public void GetEnumeratorTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort);

            Assert.That(efi, Is.EquivalentTo(new[] { GenericUriParserOptions.Idn, GenericUriParserOptions.NoPort }));
            efi |= (GenericUriParserOptions)4096;
            Assert.That(efi, Is.EquivalentTo(new[] { GenericUriParserOptions.Idn, GenericUriParserOptions.NoPort, (GenericUriParserOptions)4096 }));
        }
        public void ToStringTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            Assert.That(efi.ToString(), Is.EqualTo("Idn"));
            efi |= GenericUriParserOptions.NoPort;
            Assert.That(efi.ToString(), Is.EqualTo("NoPort, Idn"));
        }
        public void AndOrTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            Assert.That(efi | GenericUriParserOptions.NoPort, Is.EqualTo(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort));
            efi |= GenericUriParserOptions.NoPort;
            Assert.That(efi & GenericUriParserOptions.NoPort, Is.EqualTo(GenericUriParserOptions.NoPort));
        }
        public void ClearTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            Assert.That((GenericUriParserOptions)efi, Is.EqualTo(GenericUriParserOptions.Idn));
            efi.Clear();
            Assert.That((GenericUriParserOptions)efi, Is.EqualTo(GenericUriParserOptions.Default));
        }
        public void EnumFlagIndexerTest()
        {
            Assert.That(() => { EnumFlagIndexer <ConsoleColor> e = ConsoleColor.Black; }, Throws.ArgumentException);
            var efi = new EnumFlagIndexer <GenericUriParserOptions>();

            Assert.That((GenericUriParserOptions)efi, Is.EqualTo(GenericUriParserOptions.Default));
            efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);
            Assert.That((GenericUriParserOptions)efi, Is.EqualTo(GenericUriParserOptions.Idn));
        }
        public void UnionTest1()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            efi.Union(new[] { GenericUriParserOptions.IriParsing, GenericUriParserOptions.NoPort });
            Assert.That(efi.Equals(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort | GenericUriParserOptions.IriParsing), Is.True);
            efi.Union(new[] { GenericUriParserOptions.Idn, GenericUriParserOptions.NoPort });
            Assert.That(efi.Equals(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort | GenericUriParserOptions.IriParsing), Is.True);
        }
        public void UnionTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            efi.Union(GenericUriParserOptions.NoPort);
            Assert.That(efi.Equals(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort), Is.True);
            efi.Union(GenericUriParserOptions.NoPort);
            Assert.That(efi.Equals(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort), Is.True);
        }
Exemple #8
0
        /// <summary>Shows the dialog box to let the user browse for and select a folder.</summary>
        /// <param name="parentWindowHandle">The HWND of the parent window.</param>
        /// <returns>The selected folder or <c>null</c> if no folder was selected by the user.</returns>
        protected override bool RunDialog(IntPtr parentWindowHandle)
        {
            // Setup BROWSEINFO.dwFlag value
            EnumFlagIndexer <BrowseInfoFlag> browseInfoFlag = BrowseInfoFlag.BIF_SHAREABLE;

            browseInfoFlag[BrowseInfoFlag.BIF_NEWDIALOGSTYLE]      = Application.OleRequired() == ApartmentState.STA;
            browseInfoFlag[BrowseInfoFlag.BIF_DONTGOBELOWDOMAIN]   = HideDomainFolders;
            browseInfoFlag[BrowseInfoFlag.BIF_BROWSEFILEJUNCTIONS] = ShowFileJunctions;
            browseInfoFlag[BrowseInfoFlag.BIF_RETURNONLYFSDIRS]    = LocalFileSystemOnly;
            browseInfoFlag[BrowseInfoFlag.BIF_NONEWFOLDERBUTTON]   = !ShowNewFolderButton;
            browseInfoFlag[BrowseInfoFlag.BIF_EDITBOX | BrowseInfoFlag.BIF_VALIDATE] = ShowFolderPathEditBox;
            switch (BrowseOption)
            {
            case FolderBrowserDialogOptions.Folders:
                break;

            case FolderBrowserDialogOptions.FoldersAndFiles:
                browseInfoFlag |= BrowseInfoFlag.BIF_BROWSEINCLUDEFILES;
                break;

            case FolderBrowserDialogOptions.Computers:
                browseInfoFlag |= BrowseInfoFlag.BIF_BROWSEFORCOMPUTER;
                RootFolder      = defaultComputersFolder;
                break;

            case FolderBrowserDialogOptions.Printers:
                browseInfoFlag |= BrowseInfoFlag.BIF_BROWSEFORPRINTER;
                RootFolder      = defaultPrintersFolder;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Setup the BROWSEINFO structure
            var dn = new SafeCoTaskMemString(Kernel32.MAX_PATH);
            var bi = new BROWSEINFO(parentWindowHandle, rootPidl.DangerousGetHandle(), Description, browseInfoFlag, OnBrowseEvent, dn.DangerousGetHandle());

            // Show the dialog
            pidl = SHBrowseForFolder(ref bi);
            href = default(HandleRef);
            if (pidl.IsInvalid)
            {
                return(false);
            }
            if (browseInfoFlag[BrowseInfoFlag.BIF_BROWSEFORPRINTER] || browseInfoFlag[BrowseInfoFlag.BIF_BROWSEFORCOMPUTER])
            {
                SelectedItem = bi.DisplayName;
            }
            else
            {
                SelectedItem = GetNameForPidl(pidl);
            }
            return(true);
        }
            /// <summary>Returns an enumerator that iterates through the assigned rights.</summary>
            /// <returns>A <see cref="IEnumerator{T}"/> that can be used to iterate through the assigned rights.</returns>
            public IEnumerator <AccountLogonRights> GetEnumerator()
            {
                EnumFlagIndexer <AccountLogonRights> r = ctrl.GetSystemAccess(ctrl.GetAccount(user));

                foreach (AccountLogonRights t in Enum.GetValues(typeof(AccountLogonRights)))
                {
                    if (r[t])
                    {
                        yield return(t);
                    }
                }
            }
        public void IndexerTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn | GenericUriParserOptions.NoPort);

            Assert.That(efi[GenericUriParserOptions.Idn], Is.True);
            Assert.That(efi[GenericUriParserOptions.NoPort], Is.True);
            Assert.That(efi[GenericUriParserOptions.NoFragment], Is.False);
            efi[GenericUriParserOptions.NoFragment] = true;
            Assert.That(efi[GenericUriParserOptions.NoFragment], Is.True);
            Assert.That(efi, Is.EqualTo(GenericUriParserOptions.NoPort | GenericUriParserOptions.Idn | GenericUriParserOptions.NoFragment));
            efi[GenericUriParserOptions.Idn] = false;
            Assert.That(efi, Is.EqualTo(GenericUriParserOptions.NoPort | GenericUriParserOptions.NoFragment));
            efi[GenericUriParserOptions.GenericAuthority] = false;
            Assert.That(efi, Is.EqualTo(GenericUriParserOptions.NoPort | GenericUriParserOptions.NoFragment));
        }
        public void EqualsTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            Assert.That(efi.Equals(new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn)), Is.True);
            Assert.That(efi == new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn), Is.True);
            Assert.That(efi.Equals(GenericUriParserOptions.Idn), Is.True);
            Assert.That(efi == GenericUriParserOptions.Idn, Is.True);
            Assert.That(efi != GenericUriParserOptions.IriParsing, Is.True);
            Assert.That(efi.Equals(new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.IriParsing)), Is.False);
            Assert.That(efi.Equals(new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.IriParsing)), Is.False);
            Assert.That(efi.Equals(GenericUriParserOptions.IriParsing), Is.False);
            Assert.That(efi.Equals(512), Is.False);
            Assert.That(efi.Equals("512"), Is.False);
        }
        private PushButtonState GetButtonState(ControlState cstate)
        {
            EnumFlagIndexer <ControlState> state = cstate;

            if (state[ControlState.Disabled])
            {
                return(PushButtonState.Disabled);
            }
            if (state[ControlState.Pressed])
            {
                return(PushButtonState.Pressed);
            }
            if (state[ControlState.Hot])
            {
                return(PushButtonState.Hot);
            }
            if (state[ControlState.Defaulted])
            {
                return(PushButtonState.Default);
            }
            return(PushButtonState.Normal);
        }
        public void GetHashCodeTest()
        {
            var efi = new EnumFlagIndexer <GenericUriParserOptions>(GenericUriParserOptions.Idn);

            Assert.That(efi.GetHashCode(), Is.EqualTo(GenericUriParserOptions.Idn.GetHashCode()));
        }
Exemple #14
0
        /// <summary>
        /// Measures the specified item.
        /// </summary>
        /// <param name="g">A <see cref="Graphics"/> reference.</param>
        /// <param name="index">The index of the item.</param>
        /// <param name="maxSize">Maximum size of the item. Usually only constrains the width.</param>
        /// <returns>Minimum size for the item.</returns>
        protected internal override Size MeasureItem(Graphics g, int index, Size maxSize)
        {
            var chkAlign = new EnumFlagIndexer <ContentAlignment>(CheckAlign, false);           // base.RtlTranslateContent(this.CheckAlign);
            var txtAlign = new EnumFlagIndexer <ContentAlignment>(TextAlign, false);            // base.RtlTranslateContent(this.TextAlign);

            var item = BaseItems[index] as ButtonListItem <T>;

            if (item == null)
            {
                return(Size.Empty);
            }

            // Get glyph size
            if (imageSize == Size.Empty)
            {
                imageSize = GetButtonSize(g);
            }
            var glyphWithPadding = imageSize.Width + lrPadding * 2;

            // Calculate text size
            var textSize = new Size(maxSize.Width, Int32.MaxValue);

            if (!chkAlign[anyCenterAlignment])
            {
                textSize.Width -= glyphWithPadding;
            }

            var tsz = TextRenderer.MeasureText(g, item.Text, Font, textSize, TextFormatFlags);

            item.TextRect = new Rectangle(0, 0, textSize.Width, tsz.Height);
            // NEW: item.TextRect = new Rectangle(Point.Empty, tsz);
            var stsz = Size.Empty;

            item.SubtextRect = Rectangle.Empty;
            if (!string.IsNullOrEmpty(item.Subtext))
            {
                stsz             = TextRenderer.MeasureText(g, item.Subtext, SubtextFont, textSize, TextFormatFlags);
                item.SubtextRect = new Rectangle(0, tsz.Height + subtextSeparatorHeight, textSize.Width, stsz.Height);
                // NEW: item.SubtextRect = new Rectangle(0, tsz.Height + subtextSeparatorHeight, stsz.Width, stsz.Height);
            }

            // Calculate minimum item height
            var minHeight = item.TextRect.Height;

            if (!item.SubtextRect.IsEmpty)
            {
                minHeight += item.SubtextRect.Height + subtextSeparatorHeight;
            }
            var textHeight = minHeight;

            if (chkAlign[ContentAlignment.TopCenter] || chkAlign[ContentAlignment.BottomCenter])
            {
                minHeight += imageSize.Height + tPadding;
            }

            // Calculate minimum item width
            var minWidth = Math.Max(tsz.Width, stsz.Width);

            if (imageSize.Width > 0 && !chkAlign[anyCenterAlignment])
            {
                minWidth += imageSize.Width + lrPadding;
            }

            var itemSize = new Size(maxSize.Width, minHeight);

            // NEW: Size itemSize = new Size(minWidth, minHeight);

            // Set relative position of glyph
            item.GlyphPosition = Point.Empty;
            if (chkAlign[anyBottomAlignment])
            {
                item.GlyphPosition.Y = itemSize.Height - imageSize.Height;
            }
            else if (chkAlign[anyMiddleAlignment])
            {
                item.GlyphPosition.Y = (itemSize.Height - imageSize.Height) / 2;
            }
            else if (chkAlign == ContentAlignment.TopCenter)
            {
                item.OffsetText(0, imageSize.Height + tPadding);
            }
            if (chkAlign[anyRightAlignment])
            {
                item.GlyphPosition.X = itemSize.Width - imageSize.Width;
                item.OffsetText(lrPadding, 0);
            }
            else if (chkAlign[anyCenterAlignment])
            {
                item.GlyphPosition.X = (itemSize.Width - imageSize.Width) / 2;
                if (item.TextRect.Width < item.SubtextRect.Width)
                {
                    item.TextRect.Offset((item.SubtextRect.Width - item.TextRect.Width) / 2, 0);
                }
                else
                {
                    item.SubtextRect.Offset((item.TextRect.Width - item.SubtextRect.Width) / 2, 0);
                }
            }
            else
            {
                item.OffsetText(imageSize.Width + lrPadding, 0);
            }

            // Set text focus rectangle
            item.FocusRect = Rectangle.Union(item.TextRect, item.SubtextRect);

            /*item.FocusRect = new Rectangle(item.TextRect.Location, new Size(Math.Min(Math.Max(tsz.Width, stsz.Width), maxSize.Width), textHeight));
             * if ((txtAlign & anyCenterAlignment) != (ContentAlignment)0)
             *      item.FocusRect.X += (itemSize.Width - item.FocusRect.Width) / 2;
             * else if ((txtAlign & anyRightAlignment) != (ContentAlignment)0)
             *      item.FocusRect.X = itemSize.Width - item.FocusRect.Width - imageSize.Width - lrPadding;*/

            // Adjust text position for bottom or middle
            if (txtAlign[anyBottomAlignment])
            {
                item.OffsetText(0, itemSize.Height - item.TextRect.Height);
            }
            else if (txtAlign[anyMiddleAlignment])
            {
                item.OffsetText(0, (itemSize.Height - item.TextRect.Height) / 2);
            }

            return(itemSize);
        }