예제 #1
0
        private void SyncChildrenToRibbonGroupItems()
        {
            // Remove all child elements
            Clear();

            ItemToView regenerate = new ItemToView();

            // Add a view element for each group item
            foreach (IRibbonGroupItem item in _ribbonTriple.Items)
            {
                ViewBase itemView;

                // Do we already have a view for this item definition
                if (_itemToView.ContainsKey(item))
                {
                    itemView = _itemToView[item];

                    // Remove from lookup as we do not want to delete this view
                    _itemToView.Remove(item);
                }
                else
                {
                    // Ask the item definition to return an appropriate view
                    itemView = item.CreateView(_ribbon, _needPaint);
                }

                // Update the visible state of the item
                itemView.Visible = _ribbon.InDesignHelperMode || item.Visible;

                // We need to keep this association
                regenerate.Add(item, itemView);

                Add(itemView);
            }

            // When in design time help mode and there is room for another item
            if (_ribbon.InDesignHelperMode && (Count < 3))
            {
                // Create the design time 'Add Tab' first time it is needed
                if (_viewAddItem == null)
                {
                    _viewAddItem = new ViewDrawRibbonDesignGroupTriple(_ribbon,
                                                                       _ribbonTriple,
                                                                       _currentSize,
                                                                       _needPaint);
                }

                // Always add at end of the list of items
                Add(_viewAddItem);
            }

            // Dispose of all the items no longer needed
            foreach (ViewBase view in _itemToView.Values)
            {
                view.Dispose();
            }

            // Use the latest hashtable
            _itemToView = regenerate;
        }
예제 #2
0
        private void SyncChildrenToRibbonGroupItems()
        {
            // Grab the shape of the ribbon
            _lastShape = _ribbon.RibbonShape;

            bool itemEdgeVisible          = (_lastShape != PaletteRibbonShape.Office2010);
            bool itemEdgeIgnoreNormal     = (_lastShape == PaletteRibbonShape.Office2010);
            bool itemConstantBorder       = (_lastShape != PaletteRibbonShape.Office2010);
            bool itemDrawNonTrackingAreas = (_lastShape != PaletteRibbonShape.Office2010);

            // Remove all child elements
            Clear();

            // Always add the start separator as the first view element
            Add(_startSep);

            // Create new lookups which are up to date
            ItemToView regenView = new ItemToView();
            ViewToEdge regenEdge = new ViewToEdge();

            // Cache the first and last visible children
            ViewBase viewFirst = null;
            ViewBase viewLast  = null;

            // Add a view element for each group item
            foreach (IRibbonGroupItem item in _ribbonCluster.Items)
            {
                ViewBase itemView;
                ViewDrawRibbonGroupClusterEdge itemEdge;

                // Do we already have a view for this item definition
                if (_itemToView.ContainsKey(item))
                {
                    itemView = _itemToView[item];
                    itemEdge = _viewToEdge[itemView];

                    // Remove from lookups
                    _itemToView.Remove(item);
                    _viewToEdge.Remove(itemView);
                }
                else
                {
                    // Ask the item definition to return an appropriate view
                    itemView = item.CreateView(_ribbon, _needPaint);

                    // Create a border edge to go with the item view
                    itemEdge = new ViewDrawRibbonGroupClusterEdge(_ribbon, _paletteBorderEdge);
                }

                // Update the visible state
                itemView.Visible = _ribbon.InDesignHelperMode || item.Visible;
                itemEdge.Visible = itemEdgeVisible && (_ribbon.InDesignHelperMode || item.Visible);

                // We need to remember associations
                regenView.Add(item, itemView);
                regenEdge.Add(itemView, itemEdge);

                Add(itemView);
                Add(itemEdge);

                // Update the cached first/last items
                if (itemView.Visible && (viewFirst == null))
                {
                    viewFirst = itemView;
                }

                if (itemView.Visible)
                {
                    viewLast = itemView;
                }
            }

            // Update the display borders for the visible items
            foreach (ViewBase item in regenView.Values)
            {
                // Only interested in visible items
                if (item.Visible)
                {
                    if ((item is ViewDrawRibbonGroupClusterButton) ||
                        (item is ViewDrawRibbonGroupClusterColorButton))
                    {
                        // By default each button shows only the top and bottom
                        PaletteDrawBorders maxBorders = PaletteDrawBorders.TopBottom;

                        switch (_lastShape)
                        {
                        default:
                        case PaletteRibbonShape.Office2007:
                            maxBorders = PaletteDrawBorders.TopBottom;

                            // First and last items have extra borders
                            if (item == viewFirst)
                            {
                                // If first and last, it needs all borders
                                if (item == viewLast)
                                {
                                    maxBorders = PaletteDrawBorders.All;
                                }
                                else
                                {
                                    maxBorders = PaletteDrawBorders.TopBottomLeft;
                                }
                            }
                            else if (item == viewLast)
                            {
                                maxBorders = PaletteDrawBorders.TopBottomRight;
                            }
                            break;

                        case PaletteRibbonShape.Office2010:
                            maxBorders = PaletteDrawBorders.All;
                            break;
                        }

                        // Remove the border edge after the last button
                        if (item == viewLast)
                        {
                            Remove(regenEdge[item]);
                        }

                        // Cast to correct type
                        ViewDrawRibbonGroupClusterButton      clusterButton      = item as ViewDrawRibbonGroupClusterButton;
                        ViewDrawRibbonGroupClusterColorButton clusterColorButton = item as ViewDrawRibbonGroupClusterColorButton;

                        if (clusterButton != null)
                        {
                            clusterButton.MaxBorderEdges       = maxBorders;
                            clusterButton.BorderIgnoreNormal   = itemEdgeIgnoreNormal;
                            clusterButton.ConstantBorder       = itemConstantBorder;
                            clusterButton.DrawNonTrackingAreas = itemDrawNonTrackingAreas;
                        }

                        if (clusterColorButton != null)
                        {
                            clusterColorButton.MaxBorderEdges       = maxBorders;
                            clusterColorButton.BorderIgnoreNormal   = itemEdgeIgnoreNormal;
                            clusterColorButton.ConstantBorder       = itemConstantBorder;
                            clusterColorButton.DrawNonTrackingAreas = itemDrawNonTrackingAreas;
                        }
                    }
                }
            }

            // Dispose of all the items no longer needed
            foreach (ViewBase view in _itemToView.Values)
            {
                view.Dispose();
            }

            foreach (ViewBase view in _viewToEdge.Values)
            {
                view.Dispose();
            }

            // Always add the end separator as the last view element (excluding any desing time additions)
            Add(_endSep);

            // Define visible state of the separators
            _startSep.Visible = (_lastShape == PaletteRibbonShape.Office2010);
            _endSep.Visible   = (_lastShape == PaletteRibbonShape.Office2010);

            // When in design time help mode
            if (_ribbon.InDesignHelperMode)
            {
                // Create the design time 'Item' first time it is needed
                if (_viewAddItem == null)
                {
                    _viewAddItem = new ViewDrawRibbonDesignCluster(_ribbon,
                                                                   _ribbonCluster,
                                                                   _needPaint);
                }

                // Always add at end of the list of items
                Add(_viewAddItem);
            }

            // Use the latest tables
            _itemToView = regenView;
            _viewToEdge = regenEdge;
        }
예제 #3
0
        private void SyncChildrenToRibbonGroupItems()
        {
            // Remove all child elements
            Clear();

            ItemToView regenItemToView = new ItemToView();
            ViewToItem regenViewToItem = new ViewToItem();

            // Add a view element for each group item
            foreach (IRibbonGroupItem item in _ribbonLines.Items)
            {
                ViewBase itemView;

                // Do we already have a view for this item definition
                if (_itemToView.ContainsKey(item))
                {
                    itemView = _itemToView[item];

                    // Remove from lookup to prevent it being deleted
                    _itemToView.Remove(item);
                }
                else
                {
                    // Ask the item definition to return an appropriate view
                    itemView = item.CreateView(_ribbon, _needPaint);
                }

                // Update the visible state of the item
                itemView.Visible = _ribbon.InDesignHelperMode || item.Visible;

                // We need to keep this association
                regenItemToView.Add(item, itemView);
                regenViewToItem.Add(itemView, item);

                Add(itemView);
            }

            // When in design time help mode
            if (_ribbon.InDesignHelperMode)
            {
                // Create the design time 'Add Tab' first time it is needed
                if (_viewAddItem == null)
                {
                    _viewAddItem = new ViewDrawRibbonDesignGroupLines(_ribbon,
                                                                      _ribbonLines,
                                                                      _currentSize,
                                                                      _needPaint);
                }

                // Always add at end of the list of items
                Add(_viewAddItem);
            }

            // Dispose of all the items no longer needed
            foreach (ViewBase view in _itemToView.Values)
            {
                view.Dispose();
            }

            // Use the latest hashtable
            _itemToView = regenItemToView;
            _viewToItem = regenViewToItem;
        }