Exemplo n.º 1
0
        internal void OperateSubMenu(DrawCommand dc, bool selectFirst, bool trackRemove)
        {
            if (this.IsDisposed)
                return;

            if (dc == null)
                return;

            Rectangle drawRect = dc.DrawRect;

            // Find screen positions for popup menu
            Point screenPos;

            if (_style == VisualStyle.IDE)
            {
                if (_direction == Direction.Horizontal)
                    screenPos = PointToScreen(new Point(dc.DrawRect.Left + 1, drawRect.Bottom - _lengthGap - 2));
                else
                    screenPos = PointToScreen(new Point(dc.DrawRect.Right - _breadthGap, drawRect.Top + _boxExpandSides - 1));
            }
            else
            {
                if (_direction == Direction.Horizontal)
                    screenPos = PointToScreen(new Point(dc.DrawRect.Left + 1, drawRect.Bottom));
                else
                    screenPos = PointToScreen(new Point(dc.DrawRect.Right, drawRect.Top));
            }

            Point aboveScreenPos;

            if (_style == VisualStyle.IDE)
            {
                if (_direction == Direction.Horizontal)
                    aboveScreenPos = PointToScreen(new Point(dc.DrawRect.Left + 1, drawRect.Top + _breadthGap + _lengthGap - 1));
                else
                    aboveScreenPos = PointToScreen(new Point(dc.DrawRect.Right - _breadthGap, drawRect.Bottom + _lengthGap + 1));
            }
            else
            {
                if (_direction == Direction.Horizontal)
                    aboveScreenPos = PointToScreen(new Point(dc.DrawRect.Left + 1, drawRect.Top));
                else
                    aboveScreenPos = PointToScreen(new Point(dc.DrawRect.Right, drawRect.Bottom));
            }

            int borderGap;

            // Calculate the missing gap in the PopupMenu border
            if (_direction == Direction.Horizontal)
                borderGap = dc.DrawRect.Width - _subMenuBorderAdjust;
            else
                borderGap = dc.DrawRect.Height - _subMenuBorderAdjust;

            _popupMenu = new PopupMenu();
            if (_popupMenu == null)
                return;

            // Define the correct visual style based on ours
            _popupMenu.Style = this.Style;

            // Key direction when keys cause dismissal
            int returnDir = 0;

            // Command selected by the PopupMenu
            MenuCommand returnCommand = null;

            // Should the PopupMenu tell the collection to remember expansion state
            _popupMenu.RememberExpansion = _rememberExpansion;

            // Propogate our highlight setting
            _popupMenu.HighlightInfrequent = _highlightInfrequent;

            // Might need to define custom colors
            if (!_defaultSelectedBackColor)
                _popupMenu.BackColor = _selectedBackColor;

            if (!_defaultSelectedTextColor)
                _popupMenu.TextColor = _selectedTextColor;

            if (!_defaultHighlightTextColor)
                _popupMenu.HighlightTextColor = _highlightTextColor;

            if (!_defaultHighlightBackColor)
                _popupMenu.HighlightColor = _highlightBackColor;

            if (!_defaultFont)
                _popupMenu.Font = base.Font;

            // Pass on the animation values
            _popupMenu.Animate = _animate;
            _popupMenu.AnimateStyle = _animateStyle;
            _popupMenu.AnimateTime = _animateTime;

            if (dc.Chevron)
            {
                MenuCommandCollection mcc = new MenuCommandCollection();

                bool addCommands = false;

                if (_menuCommands != null)
                {
                    // Generate a collection of menu commands for those not visible
                    foreach(MenuCommand command in _menuCommands)
                    {
                        if (!addCommands && (command == _chevronStartCommand))
                            addCommands = true;

                        if (addCommands)
                            mcc.Add(command);
                    }
                }

                // Track the popup using provided menu item collection
                returnCommand = _popupMenu.TrackPopup(screenPos,
                                                      aboveScreenPos,
                                                      _direction,
                                                      mcc,
                                                      borderGap,
                                                      selectFirst,
                                                      this,
                                                      _animateFirst,
                                                      ref returnDir);
            }
            else
            {
                // Generate event so that caller has chance to modify MenuCommand contents
                dc.MenuCommand.OnPopupStart();

                // Honour the collections request for showing infrequent items
                _popupMenu.ShowInfrequent = dc.MenuCommand.MenuCommands.ShowInfrequent;

                // Track the popup using provided menu item collection
                returnCommand = _popupMenu.TrackPopup(screenPos,
                                                      aboveScreenPos,
                                                      _direction,
                                                      dc.MenuCommand.MenuCommands,
                                                      borderGap,
                                                      selectFirst,
                                                      this,
                                                      _animateFirst,
                                                      ref returnDir);
            }

            // No more animation till simulation ends
            _animateFirst = false;

            // If we are supposed to expand all items at the same time
            if (_expandAllTogether)
            {
                // Is anything we have shown now in the expanded state
                if (AnythingExpanded(_menuCommands))
                {
                    // Set everything to expanded
                    SetAllCommandsExpansion(_menuCommands, true);
                }
            }

            // Was arrow key not used to dismiss the submenu?
            if (returnDir == 0)
            {
                // The submenu may have eaten the mouse leave event
                _mouseOver = false;

                // Only if the submenu was dismissed at the request of the submenu
                // should the selection mode be cancelled, otherwise keep selection mode
                if (!_dismissTransfer)
                {
                    // This item is no longer selected
                    Deselect();
                    _drawUpwards = false;

                    if (!this.IsDisposed)
                    {
                        // Should we stop tracking this item
                        if (trackRemove)
                        {
                            // Unselect the current item
                            _trackItem = SwitchTrackingItem(_trackItem, -1);
                        }
                        else
                        {
                            if (_trackItem != -1)
                            {
                                // Repaint the item
                                DrawCommand(_trackItem, true);
                            }
                        }
                    }
                }
                else
                {
                    // Do not change _selected status
                    _dismissTransfer = false;
                }
            }

            if (!dc.Chevron)
            {
                // Generate event so that caller has chance to modify MenuCommand contents
                dc.MenuCommand.OnPopupEnd();
            }

            // Spin the message loop so the messages dealing with destroying
            // the PopupMenu window are processed and cause it to disappear from
            // view before events are generated
            Application.DoEvents();

            // Remove unwanted object
            _popupMenu = null;

            // Was arrow key used to dismiss the submenu?
            if (returnDir != 0)
            {
                if (returnDir < 0)
                {
                    // Shift selection left one
                    ProcessMoveLeft(true);
                }
                else
                {
                    // Shift selection right one
                    ProcessMoveRight(true);
                }

                // A WM_MOUSEMOVE is generated when we open up the new submenu for
                // display, ignore this as it causes the selection to move
                _ignoreMouseMove = true;
            }
            else
            {
                // Was a MenuCommand returned?
                if (returnCommand != null)
                {
                    // Remove

                    // Are we simulating having the focus?
                    if (_manualFocus)
                    {
                        // Always return focus to original when a selection is made
                        SimulateReturnFocus();
                    }

                    // Pulse the selected event for the command
                     returnCommand.OnClick(EventArgs.Empty);
                }
            }
        }
Exemplo n.º 2
0
        public virtual void OnShowContextMenu(Point screenPos)
        {
            PopupMenu context = new PopupMenu();

            // The order of Content displayed in the context menu is not the same as
            // the order of Content in the _contents collection. The latter has its
            // ordering changed to enable Restore functionality to work.
            ContentCollection temp = new ContentCollection();

            foreach(Content c in _contents)
            {
                int count = temp.Count;
                int index = 0;

                // Find best place to add into the temp collection
                for(; index<count; index++)
                {
                    if (c.Order < temp[index].Order)
                        break;
                }

                temp.Insert(index, c);
            }

            // Create a context menu entry per Content
            foreach(Content t in temp)
            {
                MenuCommand mc = new MenuCommand(t.Title, new EventHandler(OnToggleContentVisibility));
                mc.Checked = t.Visible;
                mc.Tag = t;

                context.MenuCommands.Add(mc);
            }

            // Add a separator
            context.MenuCommands.Add(new MenuCommand("-"));

            // Add fixed entries to end to effect all content objects
            context.MenuCommands.Add(new MenuCommand("Show All", new EventHandler(OnShowAll)));
            context.MenuCommands.Add(new MenuCommand("Hide All", new EventHandler(OnHideAll)));

            // Ensure menu has same style as the docking windows
            context.Style = _visualStyle;

            if (OnContextMenu(context))
            {
                // Show it!
                context.TrackPopup(screenPos, true);
            }
        }
Exemplo n.º 3
0
        private void _lv_HeaderMenuEvent(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            ContainerListView listView = sender as ContainerListView;

            PopupMenu pop = new PopupMenu();
            pop.Selected += new CommandHandler(pop_Selected);
            pop.Deselected += new CommandHandler(pop_Deselected);

            MenuCommand sortBy = pop.MenuCommands.Add(new MenuCommand("Sort &By"));
            pop.MenuCommands.Add(new MenuCommand("-"));
            bool isAscending = true;
            for(int idx = 0; idx < listView.Columns.Count; ++idx)
            {
                ContainerListViewColumnHeader hdr = listView.Columns[idx];
                MenuCommand sortByItem = new MenuCommand(hdr.Text);

                sortByItem.Description = string.Format("Sort By the '{1}' column from this grid", (hdr.Visible ? "Shows" : "Hides"), hdr.Text);
                sortByItem.RadioCheck = true;
                sortByItem.Checked = hdr.SortOrder != SortOrder.None;
                sortByItem.Tag = new object[] { listView, idx };
                //				sortByItem.Click += new EventHandler(sortByItem_Click);

                if(sortByItem.Checked)
                    isAscending = hdr.SortOrder == SortOrder.Ascending;

                sortBy.MenuCommands.Add(sortByItem);
            }

            sortBy.MenuCommands.Add(new MenuCommand("-"));
            MenuCommand ascending = sortBy.MenuCommands.Add(new MenuCommand("&Ascending"));
            ascending.RadioCheck = true;
            ascending.Checked = isAscending;
            ascending.Tag = new object[] { listView, SortOrder.Ascending };
            //			ascending.Click += new EventHandler(sortOrder_Click);

            MenuCommand descending = sortBy.MenuCommands.Add(new MenuCommand("&Descending"));
            descending.RadioCheck = true;
            descending.Checked = !isAscending;
            descending.Tag = new object[] { listView, SortOrder.Descending };
            //			descending.Click += new EventHandler(sortOrder_Click);

            bool allShown = true;
            for(int idx = 0; idx < listView.Columns.Count; ++idx)
            {
                ContainerListViewColumnHeader hdr = listView.Columns[idx];
                MenuCommand checkable = new MenuCommand(hdr.Text);

                checkable.Description = string.Format("{0} the '{1}' column from this grid", (hdr.Visible ? "Shows" : "Hides"), hdr.Text);
                checkable.Checked = hdr.Visible;
                checkable.Tag = hdr;

                pop.MenuCommands.Add(checkable);
                allShown &= hdr.Visible;
            }

            pop.MenuCommands.Add(new MenuCommand("-"));
            pop.MenuCommands.Add(new MenuCommand("Show &All")).Enabled = !allShown;

            MenuCommand result = pop.TrackPopup(listView.PointToScreen(new Point(e.X, e.Y)));
            if(result != null && result.Tag is ContainerListViewColumnHeader)
                (result.Tag as ContainerListViewColumnHeader).Visible = !result.Checked;
        }