Draws an individual RibbonGroup.
Inheritance: ComponentFactory.Krypton.Toolkit.ViewComposite, IRibbonViewGroupSize
示例#1
0
        /// <summary>
        /// Perform mouse leave processing.
        /// </summary>
        /// <param name="e">An EventArgs that contains the event data.</param>
        public override void MouseLeave(EventArgs e)
        {
            Debug.Assert(e != null);

            // Validate incoming reference
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (!_ribbon.InDesignMode)
            {
                // Only interested if the application window we are inside is active or a docking floating window is active
                if (_active || (CommonHelper.ActiveFloatingWindow != null))
                {
                    // If there is an active element
                    if (_activeGroup != null)
                    {
                        _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                        _activeGroup.Tracking = false;
                        _activeGroup          = null;
                    }
                }
            }

            // Remember to call base class for standard mouse processing
            base.MouseLeave(e);
        }
        /// <summary>
        /// Show the group popup relative to the parent group instance.
        /// </summary>
        /// <param name="parentGroup">Parent group instance.</param>
        /// <param name="parentScreenRect">Screen rectangle of the parent.</param>
        public void ShowCalculatingSize(ViewDrawRibbonGroup parentGroup,
                                        Rectangle parentScreenRect)
        {
            Size popupSize;

            // Prevent ribbon from laying out the same group as we are
            // about to get the preferred size from. This reentrancy can
            // happen if the group has a custom control that is then moved
            // to be reparented to the popup group and so therefore cause
            // a layout of the main ribbon.
            _ribbon.SuspendLayout();
            SuspendLayout();

            try
            {
                // Find the size the group requests to be
                using (ViewLayoutContext context = new ViewLayoutContext(this, Renderer))
                    popupSize = _viewGroup.GetPreferredSize(context);

                // Override the height to enforce the correct group height
                popupSize.Height = _ribbon.CalculatedValues.GroupHeight;

                // Mark the group as showing as a popup
                _ribbonGroup.ShowingAsPopup = true;

                // Request we be shown below the parent screen rect
                Show(CalculateBelowPopupRect(parentScreenRect, popupSize));
            }
            finally
            {
                // Reverse the suspend call
                _ribbon.ResumeLayout();
                ResumeLayout();
            }
        }
示例#3
0
        /// <summary>
        /// Gets the previous focus item based on the current item as provided.
        /// </summary>
        /// <param name="current">The view that is currently focused.</param>
        /// <returns>ViewBase of item; otherwise false.</returns>
        public ViewBase GetPreviousFocusItem(ViewBase current)
        {
            ViewBase view    = null;
            bool     matched = false;

            ViewDrawRibbonGroup[] groups = new ViewDrawRibbonGroup[_groupToView.Count];
            _groupToView.Values.CopyTo(groups, 0);

            // Search each group until one of them returns a focus item
            for (int i = groups.Length - 1; i >= 0; i--)
            {
                // Already matched means we need the next item we come across,
                // otherwise we continue with the attempt to find previous
                if (matched)
                {
                    view = groups[i].GetLastFocusItem();
                }
                else
                {
                    view = groups[i].GetPreviousFocusItem(current, ref matched);
                }

                if (view != null)
                {
                    break;
                }
            }

            return(view);
        }
示例#4
0
        /// <summary>
        /// Perform mouse leave processing.
        /// </summary>
        /// <param name="e">An EventArgs that contains the event data.</param>
        public override void MouseLeave(EventArgs e)
        {
            Debug.Assert(e != null);

            // Validate incoming reference
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // Only interested if the application window we are inside is active
            if (_active)
            {
                // If there is an active element
                if (_activeGroup != null)
                {
                    _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                    _activeGroup.Tracking = false;
                    _activeGroup          = null;
                }
            }

            // Remember to call base class for standard mouse processing
            base.MouseLeave(e);
        }
        /// <summary>
        /// Initialize a new instance of the VisualPopupGroup class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon control.</param>
        /// <param name="ribbonGroup">Reference to ribbon group for display.</param>
        /// <param name="renderer">Drawing renderer.</param>
        public VisualPopupGroup(KryptonRibbon ribbon,
                                KryptonRibbonGroup ribbonGroup,
                                IRenderer renderer)
            : base(renderer, true)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonGroup != null);

            // Remember references needed later
            _ribbon = ribbon;
            _ribbonGroup = ribbonGroup;

            // Create a view element for drawing the group
            _viewGroup = new ViewDrawRibbonGroup(ribbon, ribbonGroup, NeedPaintDelegate);
            _viewGroup.Collapsed = false;

            // Create the background that will contain the actual group instance
            _viewBackground = new ViewDrawRibbonGroupsBorder(ribbon, true, NeedPaintDelegate);
            _viewBackground.Add(_viewGroup);

            // Attach the root to the view manager instance
            ViewManager = new ViewRibbonPopupGroupManager(this, ribbon, _viewBackground, _viewGroup, NeedPaintDelegate);

            // Create and add a hidden button to act as the focus target
            _hiddenFocusTarget = new Button();
            _hiddenFocusTarget.TabStop = false;
            _hiddenFocusTarget.Location = new Point(-_hiddenFocusTarget.Width, -_hiddenFocusTarget.Height);
            CommonHelper.AddControlToParent(this, _hiddenFocusTarget);
        }
示例#6
0
        /// <summary>
        /// Gets the view element group that the provided point is inside.
        /// </summary>
        /// <param name="pt">Mouse point.</param>
        /// <returns>Reference if inside a group; otherwise null.</returns>
        public ViewDrawRibbonGroup ViewGroupFromPoint(Point pt)
        {
            // Parent element should be a view layout
            ViewLayoutControl layoutControl = (ViewLayoutControl)Parent;

            // Get the location of the child control it contains
            Point layoutLocation = layoutControl.ChildControl.Location;

            // Adjust the incoming point for the location of the child control
            pt.X -= layoutLocation.X;
            pt.Y -= layoutLocation.Y;

            // Search the child collection for matching group elements
            foreach (ViewBase child in this)
            {
                // Ignore hidden elements
                if (child.Visible)
                {
                    ViewDrawRibbonGroup group = child as ViewDrawRibbonGroup;

                    // Only interested in group instances (not separators or others)
                    if (group != null)
                    {
                        // Does this group match?
                        if (group.ClientRectangle.Contains(pt))
                        {
                            return(group);
                        }
                    }
                }
            }

            return(null);
        }
        private void OnMouseEnterControl(object sender, EventArgs e)
        {
            // Reset the active group setting
            _activeGroup = null;

            // Find the parent group instance
            ViewBase parent = Parent;

            // Keep going till we get to the top or find a group
            while (parent != null)
            {
                if (parent is ViewDrawRibbonGroup)
                {
                    _activeGroup = (ViewDrawRibbonGroup)parent;
                    break;
                }

                // Move up a level
                parent = parent.Parent;
            }

            // If we found a group we are inside
            if (_activeGroup != null)
            {
                _activeGroup.Tracking = true;
                _needPaint(this, new NeedLayoutEventArgs(false, _activeGroup.ClientRectangle));
            }
        }
示例#8
0
        /// <summary>
        /// Initialize a new instance of the VisualPopupGroup class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon control.</param>
        /// <param name="ribbonGroup">Reference to ribbon group for display.</param>
        /// <param name="renderer">Drawing renderer.</param>
        public VisualPopupGroup(KryptonRibbon ribbon,
                                KryptonRibbonGroup ribbonGroup,
                                IRenderer renderer)
            : base(renderer, true)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonGroup != null);

            // Remember references needed later
            _ribbon      = ribbon;
            _ribbonGroup = ribbonGroup;

            // Create a view element for drawing the group
            ViewGroup = new ViewDrawRibbonGroup(ribbon, ribbonGroup, NeedPaintDelegate)
            {
                Collapsed = false
            };

            // Create the background that will contain the actual group instance
            _viewBackground = new ViewDrawRibbonGroupsBorder(ribbon, true, NeedPaintDelegate)
            {
                ViewGroup
            };

            // Attach the root to the view manager instance
            ViewManager = new ViewRibbonPopupGroupManager(this, ribbon, _viewBackground, ViewGroup, NeedPaintDelegate);

            // Create and add a hidden button to act as the focus target
            _hiddenFocusTarget = new Button
            {
                TabStop = false
            };
            _hiddenFocusTarget.Location = new Point(-_hiddenFocusTarget.Width, -_hiddenFocusTarget.Height);
            CommonHelper.AddControlToParent(this, _hiddenFocusTarget);
        }
示例#9
0
 private void OnMouseLeaveControl(object sender, EventArgs e)
 {
     // If we have a cached group we made active
     if (_activeGroup != null)
     {
         _activeGroup.Tracking = false;
         _needPaint(this, new NeedLayoutEventArgs(false, _activeGroup.ClientRectangle));
         _activeGroup = null;
     }
 }
        /// <summary>
        /// Initialize a new instance of the ViewDrawRibbonGroupImage class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon control.</param>
        /// <param name="ribbonGroup">Reference to ribbon group definition.</param>
        /// <param name="viewGroup">Reference to top level group element.</param>
        public ViewDrawRibbonGroupImage(KryptonRibbon ribbon,
                                        KryptonRibbonGroup ribbonGroup,
                                        ViewDrawRibbonGroup viewGroup)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonGroup != null);
            Debug.Assert(viewGroup != null);

            _ribbon = ribbon;
            _ribbonGroup = ribbonGroup;
            _viewGroup = viewGroup;
        }
示例#11
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawRibbonGroupImage class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon control.</param>
        /// <param name="ribbonGroup">Reference to ribbon group definition.</param>
        /// <param name="viewGroup">Reference to top level group element.</param>
        public ViewDrawRibbonGroupImage(KryptonRibbon ribbon,
                                        KryptonRibbonGroup ribbonGroup,
                                        ViewDrawRibbonGroup viewGroup)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonGroup != null);
            Debug.Assert(viewGroup != null);

            _ribbon      = ribbon;
            _ribbonGroup = ribbonGroup;
            _viewGroup   = viewGroup;
        }
示例#12
0
        /// <summary>
        /// Initialize a new instance of the ViewRibbonPopupGroupManager class.
        /// </summary>
        /// <param name="control">Owning control.</param>
        /// <param name="ribbon">Owning ribbon control instance.</param>
        /// <param name="root">View for group we are tracking.</param>
        /// <param name="viewGroup">Group to track.</param>
        /// <param name="needPaintDelegate">Delegate for performing painting.</param>
        public ViewRibbonPopupGroupManager(Control control,
                                           KryptonRibbon ribbon,
                                           ViewBase root,
                                           ViewDrawRibbonGroup viewGroup,
                                           NeedPaintHandler needPaintDelegate)
            : base(control, root)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(viewGroup != null);
            Debug.Assert(needPaintDelegate != null);

            _ribbon            = ribbon;
            _viewGroup         = viewGroup;
            _needPaintDelegate = needPaintDelegate;
        }
        /// <summary>
        /// Initialize a new instance of the ViewRibbonPopupGroupManager class.
        /// </summary>
        /// <param name="control">Owning control.</param>
        /// <param name="ribbon">Owning ribbon control instance.</param>
        /// <param name="root">View for group we are tracking.</param>
        /// <param name="viewGroup">Group to track.</param>
        /// <param name="needPaintDelegate">Delegate for performing painting.</param>
        public ViewRibbonPopupGroupManager(Control control,
                                           KryptonRibbon ribbon,
                                           ViewBase root,
                                           ViewDrawRibbonGroup viewGroup,
                                           NeedPaintHandler needPaintDelegate)
            : base(control, root)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(viewGroup != null);
            Debug.Assert(needPaintDelegate != null);

            _ribbon = ribbon;
            _viewGroup = viewGroup;
            _needPaintDelegate = needPaintDelegate;
        }
示例#14
0
        /// <summary>
        /// Perform mouse movement handling.
        /// </summary>
        /// <param name="e">A MouseEventArgs that contains the event data.</param>
        /// <param name="rawPt">The actual point provided from the windows message.</param>
        public override void MouseMove(MouseEventArgs e, Point rawPt)
        {
            Debug.Assert(e != null);

            // Validate incoming reference
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            if (!_ribbon.InDesignMode)
            {
                // Only interested if the application window we are inside is active or a docking floating window is active
                if (_active || (CommonHelper.ActiveFloatingWindow != null))
                {
                    // Only hot track groups if in the correct mode
                    if (_minimizedMode == _ribbon.RealMinimizedMode)
                    {
                        // Get the view group instance that matches this point
                        ViewDrawRibbonGroup viewGroup = _viewGroups.ViewGroupFromPoint(new Point(e.X, e.Y));

                        // Is there a change in active group?
                        if (viewGroup != _activeGroup)
                        {
                            if (_activeGroup != null)
                            {
                                _activeGroup.Tracking = false;
                                _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                            }

                            _activeGroup = viewGroup;

                            if (_activeGroup != null)
                            {
                                _activeGroup.Tracking = true;
                                _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                            }
                        }
                    }
                }
            }

            // Remember to call base class for standard mouse processing
            base.MouseMove(e, rawPt);
        }
示例#15
0
        /// <summary>
        /// Gets the last focus item from the groups.
        /// </summary>
        /// <returns>ViewBase of item; otherwise false.</returns>
        public ViewBase GetLastFocusItem()
        {
            ViewBase view = null;

            ViewDrawRibbonGroup[] groups = new ViewDrawRibbonGroup[_groupToView.Count];
            _groupToView.Values.CopyTo(groups, 0);

            // Search each group until one of them returns a focus item
            for (int i = groups.Length - 1; i >= 0; i--)
            {
                view = groups[i].GetLastFocusItem();
                if (view != null)
                {
                    break;
                }
            }

            return(view);
        }
 private void OnMouseLeaveControl(object sender, EventArgs e)
 {
     // If we have a cached group we made active
     if (_activeGroup != null)
     {
         _activeGroup.Tracking = false;
         _needPaint(this, new NeedLayoutEventArgs(false, _activeGroup.ClientRectangle));
         _activeGroup = null;
     }
 }
        private void OnMouseEnterControl(object sender, EventArgs e)
        {
            // Reset the active group setting
            _activeGroup = null;

            // Find the parent group instance
            ViewBase parent = Parent;

            // Keep going till we get to the top or find a group
            while (parent != null)
            {
                if (parent is ViewDrawRibbonGroup)
                {
                    _activeGroup = (ViewDrawRibbonGroup)parent;
                    break;
                }

                // Move up a level
                parent = parent.Parent;
            }

            // If we found a group we are inside
            if (_activeGroup != null)
            {
                _activeGroup.Tracking = true;
                _needPaint(this, new NeedLayoutEventArgs(false, _activeGroup.ClientRectangle));
            }
        }
        /// <summary>
        /// Perform mouse movement handling.
        /// </summary>
        /// <param name="e">A MouseEventArgs that contains the event data.</param>
        /// <param name="rawPt">The actual point provided from the windows message.</param>
        public override void MouseMove(MouseEventArgs e, Point rawPt)
        {
            Debug.Assert(e != null);

            // Validate incoming reference
            if (e == null) throw new ArgumentNullException("e");

            // Only interested if the application window we are inside is active
            if (_active)
            {
                // Only hot track groups if in the correct mode
                if (_minimizedMode == _ribbon.RealMinimizedMode)
                {
                    // Get the view group instance that matches this point
                    ViewDrawRibbonGroup viewGroup = _viewGroups.ViewGroupFromPoint(new Point(e.X, e.Y));

                    // Is there a change in active group?
                    if (viewGroup != _activeGroup)
                    {
                        if (_activeGroup != null)
                        {
                            _activeGroup.Tracking = false;
                            _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                        }

                        _activeGroup = viewGroup;

                        if (_activeGroup != null)
                        {
                            _activeGroup.Tracking = true;
                            _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                        }
                    }
                }
            }

            // Remember to call base class for standard mouse processing
            base.MouseMove(e, rawPt);
        }
示例#19
0
        private void SyncChildrenToRibbonGroups()
        {
            // Remove all child elements
            Clear();

            // Create a new lookup that reflects any changes in groups
            GroupToView regenerate = new GroupToView();

            // Make sure we have a view element to match each group
            foreach (KryptonRibbonGroup group in _ribbonTab.Groups)
            {
                ViewDrawRibbonGroup view = null;

                // Get the currently cached view for the group
                if (_groupToView.ContainsKey(group))
                {
                    view = _groupToView[group];
                }

                // If a new group, create a view for it now
                if (view == null)
                {
                    view = new ViewDrawRibbonGroup(_ribbon, group, _needPaint);
                }

                // Add to the lookup for future reference
                regenerate.Add(group, view);
            }

            if (_groupSepCache.Count < _ribbonTab.Groups.Count)
            {
                for (int i = _groupSepCache.Count; i < _ribbonTab.Groups.Count; i++)
                {
                    _groupSepCache.Add(new ViewLayoutRibbonSeparator(0, true));
                }
            }

            // Update size of all separators to match ribbon shape
            Size sepSize = SeparatorSize;

            foreach (ViewLayoutRibbonSeparator sep in _groupSepCache)
            {
                sep.SeparatorSize = sepSize;
            }

            // We ignore the first separator
            bool ignoreSep = true;

            // Add child elements appropriate for each ribbon group
            for (int i = 0; i < _ribbonTab.Groups.Count; i++)
            {
                KryptonRibbonGroup ribbonGroup = _ribbonTab.Groups[i];

                // Only make the separator visible if the group is and not the first sep
                bool groupVisible = (_ribbon.InDesignHelperMode || ribbonGroup.Visible);
                _groupSepCache[i].Visible       = groupVisible && !ignoreSep;
                regenerate[ribbonGroup].Visible = groupVisible;

                // Only add a separator for the second group onwards
                if (groupVisible && ignoreSep)
                {
                    ignoreSep = false;
                }

                Add(_groupSepCache[i]);
                Add(regenerate[ribbonGroup]);

                // Remove entries we still are using
                if (_groupToView.ContainsKey(ribbonGroup))
                {
                    _groupToView.Remove(ribbonGroup);
                }
            }

            // When in design time help mode
            if (_ribbon.InDesignHelperMode)
            {
                // Create the design time 'Add Group' first time it is needed
                if (_viewAddGroup == null)
                {
                    _viewAddGroup = new ViewDrawRibbonDesignGroup(_ribbon, _needPaint);
                }

                // Always add at end of the list of groups
                Add(_viewAddGroup);
            }

            // Dispose of views no longer required
            foreach (ViewDrawRibbonGroup group in _groupToView.Values)
            {
                group.Dispose();
            }

            // No longer need the old lookup
            _groupToView = regenerate;
        }
        /// <summary>
        /// Perform mouse leave processing.
        /// </summary>
        /// <param name="e">An EventArgs that contains the event data.</param>
        public override void MouseLeave(EventArgs e)
        {
            Debug.Assert(e != null);

            // Validate incoming reference
            if (e == null) throw new ArgumentNullException("e");

            // Only interested if the application window we are inside is active
            if (_active)
            {
                // If there is an active element
                if (_activeGroup != null)
                {
                    _activeGroup.PerformNeedPaint(false, _activeGroup.ClientRectangle);
                    _activeGroup.Tracking = false;
                    _activeGroup = null;
                }
            }

            // Remember to call base class for standard mouse processing
            base.MouseLeave(e);
        }
        /// <summary>
        /// Show the group popup relative to the parent group instance.
        /// </summary>
        /// <param name="parentGroup">Parent group instance.</param>
        /// <param name="parentScreenRect">Screen rectangle of the parent.</param>
        public void ShowCalculatingSize(ViewDrawRibbonGroup parentGroup,
                                        Rectangle parentScreenRect)
        {
            Size popupSize;

            // Prevent ribbon from laying out the same group as we are
            // about to get the preferred size from. This reentrancy can
            // happen if the group has a custom control that is then moved
            // to be reparented to the popup group and so therefore cause
            // a layout of the main ribbon.
            _ribbon.SuspendLayout();
            SuspendLayout();

            try
            {
                // Find the size the group requests to be
                using (ViewLayoutContext context = new ViewLayoutContext(this, Renderer))
                    popupSize = _viewGroup.GetPreferredSize(context);

                // Override the height to enforce the correct group height
                popupSize.Height = _ribbon.CalculatedValues.GroupHeight;

                // Mark the group as showing as a popup
                _ribbonGroup.ShowingAsPopup = true;

                // Request we be shown below the parent screen rect
                Show(CalculateBelowPopupRect(parentScreenRect, popupSize));
            }
            finally
            {
                // Reverse the suspend call
                _ribbon.ResumeLayout();
                ResumeLayout();
            }
        }