/// <summary>
        /// Initialize a new instance of the ContextTabSet class.
        /// </summary>
        /// <param name="tab">Reference to first tab of the set.</param>
        /// <param name="context">Reference to owning context details.</param>
        public ContextTabSet(ViewDrawRibbonTab tab,
                             KryptonRibbonContext context)
        {
            Debug.Assert(tab != null);
            Debug.Assert(context != null);

            FirstTab = tab;
            _lastTab = tab;
            Context  = context;
        }
        /// <summary>
        /// Initialize a new instance of the RibbonTabController class.
        /// </summary>
        /// <param name="ribbon">Reference to owning control.</param>
        /// <param name="target">Target for state changes.</param>
        /// <param name="needPaint">Delegate for notifying paint requests.</param>
        public RibbonTabController(KryptonRibbon ribbon,
                                   ViewDrawRibbonTab target,
                                   NeedPaintHandler needPaint)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(target != null);

            // Remember incoming references
            _target = target;
            _ribbon = ribbon;

            // Store the provided paint notification delegate
            NeedPaint = needPaint;
        }
 /// <summary>
 /// Update the last tab in the set with new refernece.
 /// </summary>
 /// <param name="tab">Reference to new last tab.</param>
 public void UpdateLastTab(ViewDrawRibbonTab tab)
 {
     Debug.Assert(tab != null);
     _lastTab = tab;
 }
 /// <summary>
 /// Gets a value indicating if the tab is the first or last in set.
 /// </summary>
 /// <param name="tab">Tab to test.</param>
 /// <returns>True if first or last; otherwise false.</returns>
 public bool IsFirstOrLastTab(ViewDrawRibbonTab tab)
 {
     return((tab == FirstTab) || (tab == _lastTab));
 }
 /// <summary>
 /// Gets a value indicating if the tab is the last in set.
 /// </summary>
 /// <param name="tab">Tab to test.</param>
 /// <returns>True if last; otherwise false.</returns>
 public bool IsLastTab(ViewDrawRibbonTab tab)
 {
     return(tab == _lastTab);
 }
 /// <summary>
 /// Gets a value indicating if the tab is the first in set.
 /// </summary>
 /// <param name="tab">Tab to test.</param>
 /// <returns>True if first; otherwise false.</returns>
 public bool IsFirstTab(ViewDrawRibbonTab tab)
 {
     return(tab == FirstTab);
 }
Пример #7
0
        private Rectangle CalculatePopupRect(ViewLayoutRibbonTabsArea tabsArea,
                                             ViewDrawPanel drawMinimizedPanel)
        {
            Size popupSize;

            // Get the preferred size of the groups area, we only really want the height
            using (ViewLayoutContext context = new ViewLayoutContext(_ribbon, Renderer))
            {
                popupSize = drawMinimizedPanel.GetPreferredSize(context);
            }

            // The width should default to being the same width as the ribbon control
            popupSize.Width = _ribbon.Width;

            // Get the screen rectangles for the ribbon and the tabs area of the ribbon
            Rectangle parentRibbonRect = _ribbon.RectangleToScreen(_ribbon.ClientRectangle);
            Rectangle parentTabsRect   = _ribbon.RectangleToScreen(tabsArea.ClientRectangle);

            // Default popup is placed below the ribbon
            Rectangle popupRect = new Rectangle(parentRibbonRect.X, parentTabsRect.Bottom - 1, popupSize.Width, popupSize.Height);

            // Get the view element for the currently selected tab
            ViewDrawRibbonTab viewTab = tabsArea.LayoutTabs.GetViewForRibbonTab(_ribbon.SelectedTab);

            // Convert the view tab client area to screen coordinates
            Rectangle viewTabRect = _ribbon.RectangleToScreen(viewTab.ClientRectangle);

            // Get the screen that the tab is mostly within
            Screen    screen      = Screen.FromRectangle(viewTabRect);
            Rectangle workingArea = screen.WorkingArea;

            workingArea.Width  -= BOTTOMRIGHT_GAP;
            workingArea.Height -= BOTTOMRIGHT_GAP;

            // Is the right side of the popup extending over the right edge of the screen...
            if (popupRect.Right > workingArea.Right)
            {
                // Reduce width to bring it back onto the screen
                popupRect.Width -= (popupRect.Right - workingArea.Right);

                // Enforce a minimum useful width for the popup
                if (popupRect.Width < MINIMUM_WIDTH)
                {
                    popupRect.X    -= (MINIMUM_WIDTH - popupRect.Width);
                    popupRect.Width = MINIMUM_WIDTH;
                }
            }
            else
            {
                // Is the left side of the popup extending over left edge of screen...
                if (popupRect.Left < workingArea.Left)
                {
                    // Reduce left side of popup to start at screen left edge
                    int reduce = (workingArea.Left - popupRect.Left);
                    popupRect.Width -= reduce;
                    popupRect.X     += reduce;

                    // Enforce a minimum useful width for the popup
                    if (popupRect.Width < MINIMUM_WIDTH)
                    {
                        popupRect.Width = MINIMUM_WIDTH;
                    }
                }
            }

            // If there is not enough room to place the popup below the tabs area
            if (popupRect.Bottom > workingArea.Bottom)
            {
                // Is there enough room above the parent for the entire popup height?
                if ((parentTabsRect.Top - popupRect.Height) >= workingArea.Top)
                {
                    // Place the popup above the parent
                    popupRect.Y = parentTabsRect.Top - popupSize.Height;
                }
                else
                {
                    // Cannot show entire popup above or below, find which has most space
                    int spareAbove = parentTabsRect.Top - workingArea.Top;
                    int spareBelow = workingArea.Bottom - parentTabsRect.Bottom;

                    // Place it in the area with the most space
                    popupRect.Y = spareAbove > spareBelow ? workingArea.Top : parentTabsRect.Bottom;
                }
            }

            return(popupRect);
        }