Ejemplo n.º 1
0
 private void buttonExpandRetract_Click(YamuiButtonImage sender, EventArgs e)
 {
     if (_isExpanded)
     {
         YamuiList.ForceAllToCollapse();
     }
     else
     {
         YamuiList.ForceAllToExpand();
     }
     _isExpanded = !_isExpanded;
     FilterBox.ExtraButtonsList[0].BackGrndImage = _isExpanded ? Resources.Resources.Collapse : Resources.Resources.Expand;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Redirect mouse wheel to the list
 /// </summary>
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     YamuiList.DoScroll(e.Delta);
     base.OnMouseWheel(e);
 }
Ejemplo n.º 3
0
        private void DrawContent()
        {
            // init menu form
            ShowInTaskbar = false;
            StartPosition = FormStartPosition.Manual;

            Controls.Clear();

            // evaluates the width needed to draw the control
            var maxWidth = MenuList.Select(item => item.Level * 8 + TextRenderer.MeasureText(item.SubText ?? "", FontManager.GetFont(FontFunction.Small)).Width + TextRenderer.MeasureText(item.DisplayText ?? "", FontManager.GetStandardFont()).Width).Concat(new[] { 0 }).Max();

            maxWidth += MenuList.Exists(item => item.SubText != null) ? 10 : 0;
            maxWidth += (MenuList.Exists(item => item.ItemImage != null) ? 35 : 8) + 30;
            if (FormMaxSize.Width > 0)
            {
                maxWidth = maxWidth.ClampMax(FormMaxSize.Width);
            }
            if (FormMinSize.Width > 0)
            {
                maxWidth = maxWidth.ClampMin(FormMinSize.Width);
            }
            Width = maxWidth;

            int yPos = BorderWidth;

            // title
            HtmlLabel title = null;

            if (HtmlTitle != null)
            {
                title = new HtmlLabel {
                    Anchor             = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                    Location           = new Point(BorderWidth, yPos),
                    AutoSizeHeightOnly = true,
                    Width                = Width - BorderWidth * 2,
                    BackColor            = Color.Transparent,
                    Text                 = HtmlTitle,
                    IsSelectionEnabled   = false,
                    IsContextMenuEnabled = false,
                    Enabled              = false
                };
                yPos += title.Height;
            }

            // display filter box?
            if (DisplayFilterBox)
            {
                FilterBox.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                FilterBox.Location = new Point(BorderWidth, yPos + 5);
                FilterBox.Size     = new Size(Width - BorderWidth * 2, 20);
                FilterBox.Padding  = new Padding(5, 0, 5, 0);
                if (MenuList.Exists(item => item.CanExpand))
                {
                    _isExpanded            = MenuList.Exists(item => item.IsExpanded);
                    FilterBox.ExtraButtons = new List <YamuiFilterBox.YamuiFilterBoxButton> {
                        new YamuiFilterBox.YamuiFilterBoxButton {
                            Image   = _isExpanded ? Resources.Resources.Collapse : Resources.Resources.Expand,
                            OnClic  = buttonExpandRetract_Click,
                            ToolTip = "Toggle <b>Expand/Collapse</b>"
                        }
                    };
                }
                yPos += 30;
            }

            // list
            Padding = new Padding(BorderWidth, yPos, BorderWidth, BorderWidth);
            YamuiList.NoCanExpandItem = !MenuList.Exists(item => item.CanExpand);
            YamuiList.Dock            = DockStyle.Fill;
            if (!DisplayNbItems)
            {
                YamuiList.BottomHeight = 0;
            }
            YamuiList.SetItems(MenuList.Cast <ListItem>().ToList());
            YamuiList.MouseDown    += YamuiListOnMouseDown;
            YamuiList.EnterPressed += YamuiListOnEnterPressed;
            YamuiList.RowClicked   += YamuiListOnRowClicked;
            yPos += YamuiList.Items.Count.ClampMin(1) * YamuiList.RowHeight;

            if (YamuiList.Items.Count > 0)
            {
                var selectedIdx = YamuiList.Items.Cast <YamuiMenuItem>().ToList().FindIndex(item => item.IsSelectedByDefault);
                if (selectedIdx > 0)
                {
                    YamuiList.SelectedItemIndex = selectedIdx;
                }
            }

            // add controls
            if (title != null)
            {
                Controls.Add(title);
            }
            if (DisplayFilterBox)
            {
                FilterBox.Initialize(YamuiList);
                Controls.Add(FilterBox);
            }
            Controls.Add(YamuiList);

            // Size the form
            var height = yPos + BorderWidth + (DisplayNbItems ? YamuiList.BottomHeight : 0);

            if (FormMaxSize.Height > 0)
            {
                height = height.ClampMax(FormMaxSize.Height);
            }
            if (FormMinSize.Height > 0)
            {
                height = height.ClampMin(FormMinSize.Height);
            }
            Size = new Size(maxWidth, height);

            // position / size
            Location = ParentWindowRectangle.Width > 0 ? GetBestCenteredPosition(ParentWindowRectangle) : (AutocompletionLineHeight != 0 ? GetBestAutocompPosition(SpawnLocation, AutocompletionLineHeight) : GetBestMenuPosition(SpawnLocation));
            ResizeFormToFitScreen();
            MinimumSize = Size;

            // default focus
            if (DisplayFilterBox)
            {
                FilterBox.ClearAndFocusFilter();
            }
            else
            {
                ActiveControl = YamuiList;
            }

            // Filter?
            if (!string.IsNullOrEmpty(InitialFilterString) && DisplayFilterBox)
            {
                FilterBox.Text = InitialFilterString;
            }

            // So that the OnKeyDown event of this form is executed before the HandleKeyDown event of the control focused
            KeyPreview = true;
        }