Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new instance of the ContextMenuProvider class.
        /// </summary>
        /// <param name="viewManager">View manager used to organize keyboard events.</param>
        /// <param name="menuCollection">Top level set of menu items.</param>
        /// <param name="viewColumns">Stack used for adding new columns.</param>
        /// <param name="palette">Local palette setting to use initially.</param>
        /// <param name="paletteMode">Palette mode setting to use initially.</param>
        /// <param name="redirector">Redirector used for obtaining palette values.</param>
        /// <param name="needPaintDelegate">Delegate used to when paint changes occur.</param>
        public AppButtonMenuProvider(ViewContextMenuManager viewManager,
                                     KryptonContextMenuItemCollection menuCollection,
                                     ViewLayoutStack viewColumns,
                                     IPalette palette,
                                     PaletteMode paletteMode,
                                     PaletteRedirect redirector,
                                     NeedPaintHandler needPaintDelegate)
        {
            // Store incoming state
            _viewManager       = viewManager;
            _menuCollection    = menuCollection;
            _viewColumns       = viewColumns;
            _palette           = palette;
            _paletteMode       = paletteMode;
            _redirector        = redirector;
            _needPaintDelegate = needPaintDelegate;

            // Create all other state
            _parent           = null;
            _enabled          = true;
            _canCloseMenu     = true;
            _showHorz         = KryptonContextMenuPositionH.After;
            _showVert         = KryptonContextMenuPositionV.Top;
            _stateCommon      = new PaletteContextMenuRedirect(redirector, needPaintDelegate);
            _stateNormal      = new PaletteContextMenuItemState(_stateCommon);
            _stateDisabled    = new PaletteContextMenuItemState(_stateCommon);
            _stateHighlight   = new PaletteContextMenuItemStateHighlight(_stateCommon);
            _stateChecked     = new PaletteContextMenuItemStateChecked(_stateCommon);
            _redirectorImages = new PaletteRedirectContextMenu(redirector, new ContextMenuImages(needPaintDelegate));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize a new instance of the ContextMenuProvider class.
        /// </summary>
        /// <param name="viewManager">Reference to view manager.</param>
        /// <param name="viewColumns">Columns view element.</param>
        /// <param name="palette">Local palette setting to use initially.</param>
        /// <param name="paletteMode">Palette mode setting to use initially.</param>
        /// <param name="stateCommon">State used to provide common palette values.</param>
        /// <param name="stateNormal">State used to provide normal palette values.</param>
        /// <param name="stateDisabled">State used to provide disabled palette values.</param>
        /// <param name="stateHighlight">State used to provide highlight palette values.</param>
        /// <param name="stateChecked">State used to provide checked palette values.</param>
        /// <param name="redirector">Redirector used for obtaining palette values.</param>
        /// <param name="redirectorImages">Redirector used for obtaining images.</param>
        /// <param name="needPaintDelegate">Delegate for requesting paint changes.</param>
        /// <param name="enabled">Enabled state of the context menu.</param>
        public ContextMenuProvider(ViewContextMenuManager viewManager,
                                   ViewLayoutStack viewColumns,
                                   IPalette palette,
                                   PaletteMode paletteMode,
                                   PaletteContextMenuRedirect stateCommon,
                                   PaletteContextMenuItemState stateDisabled,
                                   PaletteContextMenuItemState stateNormal,
                                   PaletteContextMenuItemStateHighlight stateHighlight,
                                   PaletteContextMenuItemStateChecked stateChecked,
                                   PaletteRedirect redirector,
                                   PaletteRedirectContextMenu redirectorImages,
                                   NeedPaintHandler needPaintDelegate,
                                   bool enabled)
        {
            _showHorz = KryptonContextMenuPositionH.Left;
            _showVert = KryptonContextMenuPositionV.Below;

            _enabled           = enabled;
            _viewManager       = viewManager;
            _viewColumns       = viewColumns;
            _stateCommon       = stateCommon;
            _stateDisabled     = stateDisabled;
            _stateNormal       = stateNormal;
            _stateHighlight    = stateHighlight;
            _stateChecked      = stateChecked;
            _redirectorImages  = redirectorImages;
            _palette           = palette;
            _paletteMode       = paletteMode;
            _redirector        = redirector;
            _needPaintDelegate = needPaintDelegate;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Show the context menu relative to the provided screen point.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="screenPt">Screen location.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become Displayed.</returns>
 public bool Show(object caller,
                  Point screenPt,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert) =>
 // When providing just a point we turn this into a rectangle that happens to
 // have a zero size. We always position relative to a screen rectangle.
 Show(caller, new Rectangle(screenPt, Size.Empty), horz, vert);
 /// <summary>
 /// Show the context menu relative to the current mouse location.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become displayed.</returns>
 public bool Show(object caller,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // Without a screen location we just place it at the same location as the mouse
     return(Show(caller, Control.MousePosition, horz, vert));
 }
 /// <summary>
 /// Show the context menu relative to the provided screen rectangle.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="screenRect">Screen rectangle.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become displayed.</returns>
 public bool Show(object caller,
                  Rectangle screenRect,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // By default we assume the context menu was not activated using the keyboard.
     return(Show(caller, screenRect, horz, vert, false, true));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initialize a new instance of the DateTimePickerDropArgs class.
 /// </summary>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public DateTimePickerDropArgs(KryptonContextMenu kcm,
                               KryptonContextMenuPositionH positionH,
                               KryptonContextMenuPositionV positionV)
 {
     KryptonContextMenu = kcm;
     PositionH          = positionH;
     PositionV          = positionV;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="crumb">Reference to related crumb.</param>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public BreadCrumbMenuArgs(KryptonBreadCrumbItem crumb,
                           KryptonContextMenu kcm,
                           KryptonContextMenuPositionH positionH,
                           KryptonContextMenuPositionV positionV)
     : base(null, kcm, positionH, positionV)
 {
     Crumb = crumb;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Show the context menu relative to the provided screen rectangle.
 /// </summary>
 /// <param name="screenRect">Screen rectangle.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 public void Show(Rectangle screenRect,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // Do not bounce, so adjust position so it fits on screen but do not alter the
     // position so that you bounce the menu from the edges as you reach them.
     Show(screenRect, horz, vert, false, true);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="crumb">Reference to related crumb.</param>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public BreadCrumbMenuArgs(KryptonBreadCrumbItem crumb,
                           KryptonContextMenu kcm,
                           KryptonContextMenuPositionH positionH,
                           KryptonContextMenuPositionV positionV)
     : base(null, kcm, positionH, positionV)
 {
     _crumb = crumb;
 }
 /// <summary>
 /// Initialize a new instance of the DateTimePickerDropArgs class.
 /// </summary>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public DateTimePickerDropArgs(KryptonContextMenu kcm,
                              KryptonContextMenuPositionH positionH,
                              KryptonContextMenuPositionV positionV)
 {
     _kcm = kcm;
     _positionH = positionH;
     _positionV = positionV;
 }
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="cms">Context menu strip that can be customized.</param>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public ContextPositionMenuArgs(ContextMenuStrip cms,
                                KryptonContextMenu kcm,
                                KryptonContextMenuPositionH positionH,
                                KryptonContextMenuPositionV positionV)
     : base(cms, kcm)
 {
     PositionH = positionH;
     PositionV = positionV;
 }
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="cms">Context menu strip that can be customized.</param>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public ContextPositionMenuArgs(ContextMenuStrip cms,
                                KryptonContextMenu kcm,
                                KryptonContextMenuPositionH positionH,
                                KryptonContextMenuPositionV positionV)
     : base(cms, kcm)
 {
     _positionH = positionH;
     _positionV = positionV;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Show the context menu at the fixed screen rectangle.
        /// </summary>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        public void ShowFixed(Rectangle screenRect,
                              KryptonContextMenuPositionH horz,
                              KryptonContextMenuPositionV vert)
        {
            // Cache the information used to create this menu
            ShowHorz = horz;
            ShowVert = vert;

            // Call base class method that performs actual sizing and display of control
            base.Show(screenRect);
        }
        /// <summary>
        /// Show the context menu relative to the provided screen rectangle.
        /// </summary>
        /// <param name="caller">Reference to object causing the context menu to be shown.</param>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        /// <param name="keyboardActivated">Was context menu initiated via a keyboard action.</param>
        /// <param name="constrain">Should size and position of menu be constrained by display size.</param>
        /// <returns>Has the context menu become displayed.</returns>
        public bool Show(object caller,
                         Rectangle screenRect,
                         KryptonContextMenuPositionH horz,
                         KryptonContextMenuPositionV vert,
                         bool keyboardActivated,
                         bool constrain)
        {
            bool displayed = false;

            // Only need to show if not already displaying it
            if (VisualContextMenu == null)
            {
                // Remember the caller for us in events
                Caller = caller;

                // Give event handler a change to cancel the open request
                CancelEventArgs cea = new CancelEventArgs();
                OnOpening(cea);

                if (!cea.Cancel)
                {
                    // Set a default reason for the menu being dismissed
                    CloseReason = ToolStripDropDownCloseReason.AppFocusChange;

                    // Create the actual control used to show the context menu
                    VisualContextMenu = CreateContextMenu(this, Palette, PaletteMode,
                                                          _redirector, _redirectorImages,
                                                          Items, Enabled, keyboardActivated);

                    // Need to know when the visual control is removed
                    VisualContextMenu.Disposed += OnContextMenuDisposed;

                    // Request the menu be shown immediately
                    VisualContextMenu.Show(screenRect, horz, vert, false, constrain);

                    // Override the horz, vert setting so that sub menus appear right and below
                    VisualContextMenu.ShowHorz = KryptonContextMenuPositionH.After;
                    VisualContextMenu.ShowVert = KryptonContextMenuPositionV.Top;

                    // Indicate the context menu is fully constructed and displayed
                    OnOpened(EventArgs.Empty);

                    // The menu has actually become displayed
                    displayed = true;
                }
            }

            return(displayed);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Initialize a new instance of the ContextMenuProvider class.
 /// </summary>
 /// <param name="provider">Original provider.</param>
 /// <param name="needPaintDelegate">Delegate for requesting paint changes.</param>
 /// <param name="viewManager">Reference to view manager.</param>
 /// <param name="viewColumns">Columns view element.</param>
 public ContextMenuProvider(IContextMenuProvider provider,
                            ViewContextMenuManager viewManager,
                            ViewLayoutStack viewColumns,
                            NeedPaintHandler needPaintDelegate)
 {
     _parent = provider;
     _enabled = provider.ProviderEnabled;
     _canCloseMenu = provider.ProviderCanCloseMenu;
     _viewManager = viewManager;
     _viewColumns = viewColumns;
     _stateCommon = provider.ProviderStateCommon;
     _stateDisabled = provider.ProviderStateDisabled;
     _stateNormal = provider.ProviderStateNormal;
     _stateHighlight = provider.ProviderStateHighlight;
     _stateChecked = provider.ProviderStateChecked;
     _redirectorImages = provider.ProviderImages;
     _palette = provider.ProviderPalette;
     _paletteMode = provider.ProviderPaletteMode;
     _redirector = provider.ProviderRedirector;
     _needPaintDelegate = needPaintDelegate;
     _showHorz = provider.ProviderShowHorz;
     _showVert = provider.ProviderShowVert;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initialize a new instance of the ContextMenuProvider class.
 /// </summary>
 /// <param name="provider">Original provider.</param>
 /// <param name="needPaintDelegate">Delegate for requesting paint changes.</param>
 /// <param name="viewManager">Reference to view manager.</param>
 /// <param name="viewColumns">Columns view element.</param>
 public ContextMenuProvider(IContextMenuProvider provider,
                            ViewContextMenuManager viewManager,
                            ViewLayoutStack viewColumns,
                            NeedPaintHandler needPaintDelegate)
 {
     _parent            = provider;
     _enabled           = provider.ProviderEnabled;
     _canCloseMenu      = provider.ProviderCanCloseMenu;
     _viewManager       = viewManager;
     _viewColumns       = viewColumns;
     _stateCommon       = provider.ProviderStateCommon;
     _stateDisabled     = provider.ProviderStateDisabled;
     _stateNormal       = provider.ProviderStateNormal;
     _stateHighlight    = provider.ProviderStateHighlight;
     _stateChecked      = provider.ProviderStateChecked;
     _redirectorImages  = provider.ProviderImages;
     _palette           = provider.ProviderPalette;
     _paletteMode       = provider.ProviderPaletteMode;
     _redirector        = provider.ProviderRedirector;
     _needPaintDelegate = needPaintDelegate;
     _showHorz          = provider.ProviderShowHorz;
     _showVert          = provider.ProviderShowVert;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initialize a new instance of the ContextMenuProvider class.
        /// </summary>
        /// <param name="contextMenu">Originating context menu instance.</param>
        /// <param name="viewManager">Reference to view manager.</param>
        /// <param name="viewColumns">Columns view element.</param>
        /// <param name="palette">Local palette setting to use initially.</param>
        /// <param name="paletteMode">Palette mode setting to use initially.</param>
        /// <param name="redirector">Redirector used for obtaining palette values.</param>
        /// <param name="redirectorImages">Redirector used for obtaining images.</param>
        /// <param name="needPaintDelegate">Delegate for requesting paint changes.</param>
        /// <param name="enabled">Enabled state of the context menu.</param>
        public ContextMenuProvider(KryptonContextMenu contextMenu,
                                   ViewContextMenuManager viewManager,
                                   ViewLayoutStack viewColumns,
                                   IPalette palette,
                                   PaletteMode paletteMode,
                                   PaletteRedirect redirector,
                                   PaletteRedirectContextMenu redirectorImages,
                                   NeedPaintHandler needPaintDelegate,
                                   bool enabled)
        {
            _showHorz = KryptonContextMenuPositionH.Left;
            _showVert = KryptonContextMenuPositionV.Below;

            _enabled = enabled;
            _viewManager = viewManager;
            _viewColumns = viewColumns;
            _stateCommon = contextMenu.StateCommon;
            _stateDisabled = contextMenu.StateDisabled;
            _stateNormal = contextMenu.StateNormal;
            _stateHighlight = contextMenu.StateHighlight;
            _stateChecked = contextMenu.StateChecked;
            _redirectorImages = redirectorImages;
            _palette = palette;
            _paletteMode = paletteMode;
            _redirector = redirector;
            _needPaintDelegate = needPaintDelegate;
            _canCloseMenu = true;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initialize a new instance of the ContextMenuProvider class.
        /// </summary>
        /// <param name="viewManager">View manager used to organize keyboard events.</param>
        /// <param name="menuCollection">Top level set of menu items.</param>
        /// <param name="viewColumns">Stack used for adding new columns.</param>
        /// <param name="palette">Local palette setting to use initially.</param>
        /// <param name="paletteMode">Palette mode setting to use initially.</param>
        /// <param name="redirector">Redirector used for obtaining palette values.</param>
        /// <param name="needPaintDelegate">Delegate used to when paint changes occur.</param>
        public AppButtonMenuProvider(ViewContextMenuManager viewManager,
                                     KryptonContextMenuItemCollection menuCollection,
                                     ViewLayoutStack viewColumns,
                                     IPalette palette,
                                     PaletteMode paletteMode,
                                     PaletteRedirect redirector,
                                     NeedPaintHandler needPaintDelegate)
        {
            // Store incoming state
            _viewManager = viewManager;
            _menuCollection = menuCollection;
            _viewColumns = viewColumns;
            _palette = palette;
            _paletteMode = paletteMode;
            _redirector = redirector;
            _needPaintDelegate = needPaintDelegate;

            // Create all other state
            _parent = null;
            _enabled = true;
            _canCloseMenu = true;
            _showHorz = KryptonContextMenuPositionH.After;
            _showVert = KryptonContextMenuPositionV.Top;
            _stateCommon = new PaletteContextMenuRedirect(redirector, needPaintDelegate);
            _stateNormal = new PaletteContextMenuItemState(_stateCommon);
            _stateDisabled = new PaletteContextMenuItemState(_stateCommon);
            _stateHighlight = new PaletteContextMenuItemStateHighlight(_stateCommon);
            _stateChecked = new PaletteContextMenuItemStateChecked(_stateCommon);
            _redirectorImages = new PaletteRedirectContextMenu(redirector, new ContextMenuImages(needPaintDelegate));
        }
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public ContextPositionMenuArgs(KryptonContextMenu kcm,
                                KryptonContextMenuPositionH positionH,
                                KryptonContextMenuPositionV positionV)
     : this(null, kcm, positionH, positionV)
 {
 }
Exemplo n.º 20
0
        internal void ShownGalleryDropDown(Rectangle screenRect,
            KryptonContextMenuPositionH hPosition,
            KryptonContextMenuPositionV vPosition,
            EventHandler finishDelegate,
            int actualLineItems)
        {
            // First time around create the context menu, otherwise just clear it down
            if (_dropMenu == null)
                _dropMenu = new KryptonContextMenu();

            // Number of line items equals the number actually used
            int lineItems = Math.Max(DropMinItemWidth, Math.Min(DropMaxItemWidth, actualLineItems));

            // If there are no ranges defined, just add a single entry showing all enties
            if (_dropButtonRanges.Count == 0)
            {
                KryptonContextMenuImageSelect imageSelect = new KryptonContextMenuImageSelect();
                imageSelect.ImageList = ImageList;
                imageSelect.ImageIndexStart = 0;
                imageSelect.ImageIndexEnd = (ImageList == null ? 0 : ImageList.Images.Count - 1);
                imageSelect.SelectedIndex = SelectedIndex;
                imageSelect.LineItems = lineItems;
                _dropMenu.Items.Add(imageSelect);
            }
            else
            {
                foreach (KryptonGalleryRange range in _dropButtonRanges)
                {
                    // If not the first item in the menu, add a separator
                    if (_dropMenu.Items.Count > 0)
                        _dropMenu.Items.Add(new KryptonContextMenuSeparator());

                    // Only add a heading if the heading text is not empty
                    if (!string.IsNullOrEmpty(range.Heading))
                    {
                        KryptonContextMenuHeading heading = new KryptonContextMenuHeading();
                        heading.Text = range.Heading;
                        _dropMenu.Items.Add(heading);
                    }

                    // Add the image select for the range
                    KryptonContextMenuImageSelect imageSelect = new KryptonContextMenuImageSelect();
                    imageSelect.ImageList = ImageList;
                    imageSelect.ImageIndexStart = Math.Max(0, range.ImageIndexStart);
                    imageSelect.ImageIndexEnd = Math.Min(range.ImageIndexEnd, (ImageList == null ? 0 : ImageList.Images.Count - 1));
                    imageSelect.SelectedIndex = SelectedIndex;
                    imageSelect.LineItems = lineItems;
                    _dropMenu.Items.Add(imageSelect);
                }
            }

            // Give event handler a change to modify the menu
            GalleryDropMenuEventArgs args = new GalleryDropMenuEventArgs(_dropMenu);
            OnGalleryDropMenu(args);

            if (!args.Cancel && CommonHelper.ValidKryptonContextMenu(args.KryptonContextMenu))
            {
                // Hook into relevant events of the image select areas
                foreach (KryptonContextMenuItemBase item in _dropMenu.Items)
                    if (item is KryptonContextMenuImageSelect)
                    {
                        KryptonContextMenuImageSelect itemSelect = (KryptonContextMenuImageSelect)item;
                        itemSelect.SelectedIndexChanged += new EventHandler(OnDropImageSelect);
                        itemSelect.TrackingImage += new EventHandler<ImageSelectEventArgs>(OnDropImageTracking);
                    }

                // Need to know when the menu is dismissed
                args.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnDropMenuClosed);

                // Remember the delegate we need to fire when the menu is dismissed
                _finishDelegate = finishDelegate;

                // Show the menu to the user
                args.KryptonContextMenu.Show(this, screenRect, hPosition, vPosition);
            }
            else
            {
                // Nothing to show, but still need to call the finished delegate?
                if (finishDelegate != null)
                    finishDelegate(this, EventArgs.Empty);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Show the context menu relative to the provided screen rectangle.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="screenRect">Screen rectangle.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become displayed.</returns>
 public bool Show(object caller,
                  Rectangle screenRect,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // By default we assume the context menu was not activated using the keyboard.
     return Show(caller, screenRect, horz, vert, false, true);
 }
Exemplo n.º 22
0
        internal void ShownGalleryDropDown(Rectangle screenRect,
                                           KryptonContextMenuPositionH hPosition,
                                           KryptonContextMenuPositionV vPosition,
                                           EventHandler finishDelegate,
                                           int actualLineItems)
        {
            // First time around create the context menu, otherwise just clear it down
            if (_dropMenu == null)
            {
                _dropMenu = new KryptonContextMenu();
            }

            // Number of line items equals the number actually used
            int lineItems = Math.Max(DropMinItemWidth, Math.Min(DropMaxItemWidth, actualLineItems));

            // If there are no ranges defined, just add a single entry showing all enties
            if (_dropButtonRanges.Count == 0)
            {
                KryptonContextMenuImageSelect imageSelect = new KryptonContextMenuImageSelect();
                imageSelect.ImageList       = ImageList;
                imageSelect.ImageIndexStart = 0;
                imageSelect.ImageIndexEnd   = (ImageList == null ? 0 : ImageList.Images.Count - 1);
                imageSelect.SelectedIndex   = SelectedIndex;
                imageSelect.LineItems       = lineItems;
                _dropMenu.Items.Add(imageSelect);
            }
            else
            {
                foreach (KryptonGalleryRange range in _dropButtonRanges)
                {
                    // If not the first item in the menu, add a separator
                    if (_dropMenu.Items.Count > 0)
                    {
                        _dropMenu.Items.Add(new KryptonContextMenuSeparator());
                    }

                    // Only add a heading if the heading text is not empty
                    if (!string.IsNullOrEmpty(range.Heading))
                    {
                        KryptonContextMenuHeading heading = new KryptonContextMenuHeading();
                        heading.Text = range.Heading;
                        _dropMenu.Items.Add(heading);
                    }

                    // Add the image select for the range
                    KryptonContextMenuImageSelect imageSelect = new KryptonContextMenuImageSelect();
                    imageSelect.ImageList       = ImageList;
                    imageSelect.ImageIndexStart = Math.Max(0, range.ImageIndexStart);
                    imageSelect.ImageIndexEnd   = Math.Min(range.ImageIndexEnd, (ImageList == null ? 0 : ImageList.Images.Count - 1));
                    imageSelect.SelectedIndex   = SelectedIndex;
                    imageSelect.LineItems       = lineItems;
                    _dropMenu.Items.Add(imageSelect);
                }
            }

            // Give event handler a change to modify the menu
            GalleryDropMenuEventArgs args = new GalleryDropMenuEventArgs(_dropMenu);

            OnGalleryDropMenu(args);

            if (!args.Cancel && CommonHelper.ValidKryptonContextMenu(args.KryptonContextMenu))
            {
                // Hook into relevant events of the image select areas
                foreach (KryptonContextMenuItemBase item in _dropMenu.Items)
                {
                    if (item is KryptonContextMenuImageSelect)
                    {
                        KryptonContextMenuImageSelect itemSelect = (KryptonContextMenuImageSelect)item;
                        itemSelect.SelectedIndexChanged += new EventHandler(OnDropImageSelect);
                        itemSelect.TrackingImage        += new EventHandler <ImageSelectEventArgs>(OnDropImageTracking);
                    }
                }

                // Need to know when the menu is dismissed
                args.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnDropMenuClosed);

                // Remember the delegate we need to fire when the menu is dismissed
                _finishDelegate = finishDelegate;

                // Show the menu to the user
                args.KryptonContextMenu.Show(this, screenRect, hPosition, vPosition);
            }
            else
            {
                // Nothing to show, but still need to call the finished delegate?
                finishDelegate?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Show the context menu relative to the provided screen rectangle.
        /// </summary>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        /// <param name="bounce">Should the menu bounce around the monitor.</param>
        /// <param name="constrain">Should size and position of menu be constrained by display size.</param>
        public void Show(Rectangle screenRect,
                         KryptonContextMenuPositionH horz,
                         KryptonContextMenuPositionV vert,
                         bool bounce,
                         bool constrain)
        {
            // Find the preferred size of the context menu if it could be any size it likes
            Size preferredSize = CalculatePreferredSize();

            // Get the working area of the monitor that most of the screen rectangle is inside
            Rectangle workingArea = Screen.GetWorkingArea(screenRect);

            if (constrain)
            {
                // Limit size of context menu to the working area
                preferredSize.Width = Math.Min(workingArea.Width, preferredSize.Width);
                preferredSize.Height = Math.Min(workingArea.Height, preferredSize.Height);
            }

            // Find the horizontal position relative to screen rectangle
            Point screenPt = Point.Empty;
            switch (horz)
            {
                case KryptonContextMenuPositionH.After:
                    screenPt.X = screenRect.Right;
                    break;
                case KryptonContextMenuPositionH.Before:
                    screenPt.X = screenRect.Left - preferredSize.Width;
                    break;
                case KryptonContextMenuPositionH.Left:
                    screenPt.X = screenRect.Left;
                    break;
                case KryptonContextMenuPositionH.Right:
                    screenPt.X = screenRect.Right - preferredSize.Width;
                    break;
            }

            // Find the vertical position relative to screen rectangle
            switch (vert)
            {
                case KryptonContextMenuPositionV.Above:
                    screenPt.Y = screenRect.Top - preferredSize.Height;
                    break;
                case KryptonContextMenuPositionV.Below:
                    screenPt.Y = screenRect.Bottom;
                    break;
                case KryptonContextMenuPositionV.Top:
                    screenPt.Y = screenRect.Top;
                    break;
                case KryptonContextMenuPositionV.Bottom:
                    screenPt.Y = screenRect.Bottom - preferredSize.Height;
                    break;
            }

            // Do we check for bouncing off working area edges?
            if (bounce)
            {
                // Are we extending past the right edge...
                if ((screenPt.X + preferredSize.Width) > workingArea.Right)
                {
                    // ...and we tried to position afterwards
                    if ((horz == KryptonContextMenuPositionH.After) ||
                        (horz == KryptonContextMenuPositionH.Left))
                    {
                        // Then switch to positioning before
                        horz = KryptonContextMenuPositionH.Before;
                        screenPt.X = screenRect.Left - preferredSize.Width;
                    }
                }

                // Are we extending past the left edge...
                if (screenPt.X < workingArea.X)
                {
                    // ...and we tried to position before
                    if ((horz == KryptonContextMenuPositionH.Before) ||
                        (horz == KryptonContextMenuPositionH.Right))
                    {
                        // Then switch to positioning after
                        horz = KryptonContextMenuPositionH.After;
                        screenPt.X = screenRect.Right;
                    }
                }

                // Are we extending past the bottom edge...
                if ((screenPt.Y + preferredSize.Height) > workingArea.Bottom)
                {
                    // ...and we tried to position downwards
                    if ((vert == KryptonContextMenuPositionV.Below) ||
                        (vert == KryptonContextMenuPositionV.Top))
                    {
                        // Then switch to positoning upwards
                        vert = KryptonContextMenuPositionV.Bottom;
                        screenPt.Y = screenRect.Bottom - preferredSize.Height;
                    }
                }

                // Are we extending past the top edge...
                if (screenPt.Y < workingArea.Y)
                {
                    // ...and we tried to position upwards
                    if ((vert == KryptonContextMenuPositionV.Above) ||
                        (vert == KryptonContextMenuPositionV.Bottom))
                    {
                        // Then switch to positoning downwards
                        vert = KryptonContextMenuPositionV.Top;
                        screenPt.Y = screenRect.Top;
                    }
                }
            }

            if (constrain)
            {
                // Limit location of context menu to the working area
                screenPt.X = Math.Max(screenPt.X, workingArea.X);
                screenPt.Y = Math.Max(screenPt.Y, workingArea.Y);

                if ((screenPt.X + preferredSize.Width) > workingArea.Right)
                    screenPt.X = workingArea.Right - preferredSize.Width;

                if ((screenPt.Y + preferredSize.Height) > workingArea.Bottom)
                    screenPt.Y = workingArea.Bottom - preferredSize.Height;
            }

            // Cache the information used to create this menu
            ShowHorz = horz;
            ShowVert = vert;

            // Call base class method that performs actual sizing and display of control
            base.Show(new Rectangle(screenPt, preferredSize));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Show the context menu at the fixed screen rectangle.
        /// </summary>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        public void ShowFixed(Rectangle screenRect,
                              KryptonContextMenuPositionH horz,
                              KryptonContextMenuPositionV vert)
        {
            // Cache the information used to create this menu
            ShowHorz = horz;
            ShowVert = vert;

            // Call base class method that performs actual sizing and display of control
            base.Show(screenRect);
        }
 /// <summary>
 /// Initialize a new instance of the ContextMenuArgs class.
 /// </summary>
 /// <param name="kcm">KryptonContextMenu that can be customized.</param>
 /// <param name="positionH">Relative horizontal position of the KryptonContextMenu.</param>
 /// <param name="positionV">Relative vertical position of the KryptonContextMenu.</param>
 public ContextPositionMenuArgs(KryptonContextMenu kcm,
                                KryptonContextMenuPositionH positionH,
                                KryptonContextMenuPositionV positionV)
     : this(null, kcm, positionH, positionV)
 {
 }
Exemplo n.º 26
0
 /// <summary>
 /// Show the context menu relative to the current mouse location.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become displayed.</returns>
 public bool Show(object caller,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // Without a screen location we just place it at the same location as the mouse
     return Show(caller, Control.MousePosition, horz, vert);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Show the context menu relative to the provided screen rectangle.
        /// </summary>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        /// <param name="bounce">Should the menu bounce around the monitor.</param>
        /// <param name="constrain">Should size and position of menu be constrained by display size.</param>
        public void Show(Rectangle screenRect,
                         KryptonContextMenuPositionH horz,
                         KryptonContextMenuPositionV vert,
                         bool bounce,
                         bool constrain)
        {
            // Find the preferred size of the context menu if it could be any size it likes
            Size preferredSize = CalculatePreferredSize();

            // Get the working area of the monitor that most of the screen rectangle is inside
            Rectangle workingArea = Screen.GetWorkingArea(screenRect);

            if (constrain)
            {
                // Limit size of context menu to the working area
                preferredSize.Width  = Math.Min(workingArea.Width, preferredSize.Width);
                preferredSize.Height = Math.Min(workingArea.Height, preferredSize.Height);
            }

            // Find the horizontal position relative to screen rectangle
            Point screenPt = Point.Empty;

            switch (horz)
            {
            case KryptonContextMenuPositionH.After:
                screenPt.X = screenRect.Right;
                break;

            case KryptonContextMenuPositionH.Before:
                screenPt.X = screenRect.Left - preferredSize.Width;
                break;

            case KryptonContextMenuPositionH.Left:
                screenPt.X = screenRect.Left;
                break;

            case KryptonContextMenuPositionH.Right:
                screenPt.X = screenRect.Right - preferredSize.Width;
                break;
            }

            // Find the vertical position relative to screen rectangle
            switch (vert)
            {
            case KryptonContextMenuPositionV.Above:
                screenPt.Y = screenRect.Top - preferredSize.Height;
                break;

            case KryptonContextMenuPositionV.Below:
                screenPt.Y = screenRect.Bottom;
                break;

            case KryptonContextMenuPositionV.Top:
                screenPt.Y = screenRect.Top;
                break;

            case KryptonContextMenuPositionV.Bottom:
                screenPt.Y = screenRect.Bottom - preferredSize.Height;
                break;
            }

            // Do we check for bouncing off working area edges?
            if (bounce)
            {
                // Are we extending past the right edge...
                if ((screenPt.X + preferredSize.Width) > workingArea.Right)
                {
                    // ...and we tried to position afterwards
                    if ((horz == KryptonContextMenuPositionH.After) ||
                        (horz == KryptonContextMenuPositionH.Left))
                    {
                        // Then switch to positioning before
                        horz       = KryptonContextMenuPositionH.Before;
                        screenPt.X = screenRect.Left - preferredSize.Width;
                    }
                }

                // Are we extending past the left edge...
                if (screenPt.X < workingArea.X)
                {
                    // ...and we tried to position before
                    if ((horz == KryptonContextMenuPositionH.Before) ||
                        (horz == KryptonContextMenuPositionH.Right))
                    {
                        // Then switch to positioning after
                        horz       = KryptonContextMenuPositionH.After;
                        screenPt.X = screenRect.Right;
                    }
                }

                // Are we extending past the bottom edge...
                if ((screenPt.Y + preferredSize.Height) > workingArea.Bottom)
                {
                    // ...and we tried to position downwards
                    if ((vert == KryptonContextMenuPositionV.Below) ||
                        (vert == KryptonContextMenuPositionV.Top))
                    {
                        // Then switch to positoning upwards
                        vert       = KryptonContextMenuPositionV.Bottom;
                        screenPt.Y = screenRect.Bottom - preferredSize.Height;
                    }
                }

                // Are we extending past the top edge...
                if (screenPt.Y < workingArea.Y)
                {
                    // ...and we tried to position upwards
                    if ((vert == KryptonContextMenuPositionV.Above) ||
                        (vert == KryptonContextMenuPositionV.Bottom))
                    {
                        // Then switch to positoning downwards
                        vert       = KryptonContextMenuPositionV.Top;
                        screenPt.Y = screenRect.Top;
                    }
                }
            }

            if (constrain)
            {
                // Limit location of context menu to the working area
                screenPt.X = Math.Max(screenPt.X, workingArea.X);
                screenPt.Y = Math.Max(screenPt.Y, workingArea.Y);

                if ((screenPt.X + preferredSize.Width) > workingArea.Right)
                {
                    screenPt.X = workingArea.Right - preferredSize.Width;
                }

                if ((screenPt.Y + preferredSize.Height) > workingArea.Bottom)
                {
                    screenPt.Y = workingArea.Bottom - preferredSize.Height;
                }
            }

            // Cache the information used to create this menu
            ShowHorz = horz;
            ShowVert = vert;

            // Call base class method that performs actual sizing and display of control
            base.Show(new Rectangle(screenPt, preferredSize));
        }
Exemplo n.º 28
0
 /// <summary>
 /// Show the context menu relative to the provided screen rectangle.
 /// </summary>
 /// <param name="screenRect">Screen rectangle.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 public void Show(Rectangle screenRect,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // Do not bounce, so adjust position so it fits on screen but do not alter the
     // position so that you bounce the menu from the edges as you reach them.
     Show(screenRect, horz, vert, false, true);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Show the context menu relative to the provided screen rectangle.
        /// </summary>
        /// <param name="caller">Reference to object causing the context menu to be shown.</param>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        /// <param name="keyboardActivated">Was context menu initiated via a keyboard action.</param>
        /// <param name="constrain">Should size and position of menu be constrained by display size.</param>
        /// <returns>Has the context menu become displayed.</returns>
        public bool Show(object caller,
                         Rectangle screenRect,
                         KryptonContextMenuPositionH horz,
                         KryptonContextMenuPositionV vert,
                         bool keyboardActivated,
                         bool constrain)
        {
            bool displayed = false;

            // Only need to show if not already displaying it
            if (_contextMenu == null)
            {
                // Remember the caller for us in events
                _caller = caller;

                // Give event handler a change to cancel the open request
                CancelEventArgs cea = new CancelEventArgs();
                OnOpening(cea);

                if (!cea.Cancel)
                {
                    // Set a default reason for the menu being dismissed
                    _closeReason = ToolStripDropDownCloseReason.AppFocusChange;

                    // Create the actual control used to show the context menu
                    _contextMenu = CreateContextMenu(this, _localPalette, _paletteMode,
                                                     _redirector, _redirectorImages,
                                                     Items, Enabled, keyboardActivated);

                    // Need to know when the visual control is removed
                    _contextMenu.Disposed += new EventHandler(OnContextMenuDisposed);

                    // Request the menu be shown immediately
                    _contextMenu.Show(screenRect, horz, vert, false, constrain);

                    // Override the horz, vert setting so that sub menus appear right and below
                    _contextMenu.ShowHorz = KryptonContextMenuPositionH.After;
                    _contextMenu.ShowVert = KryptonContextMenuPositionV.Top;

                    // Indicate the context menu is fully constructed and displayed
                    OnOpened(EventArgs.Empty);

                    // The menu has actually become displayed
                    displayed = true;
                }
            }

            return displayed;
        }
Exemplo n.º 30
0
 /// <summary>
 /// Show the context menu relative to the provided screen point.
 /// </summary>
 /// <param name="caller">Reference to object causing the context menu to be shown.</param>
 /// <param name="screenPt">Screen location.</param>
 /// <param name="horz">Horizontal location relative to screen rectangle.</param>
 /// <param name="vert">Vertical location relative to screen rectangle.</param>
 /// <returns>Has the context menu become displayed.</returns>
 public bool Show(object caller,
                  Point screenPt,
                  KryptonContextMenuPositionH horz,
                  KryptonContextMenuPositionV vert)
 {
     // When providing just a point we turn this into a rectangle that happens to
     // have a zero size. We always position relative to a screen rectangle.
     return Show(caller, new Rectangle(screenPt, Size.Empty), horz, vert);
 }