protected override string GetNameCore()
        {
            string name = base.GetNameCore();

            if (String.IsNullOrEmpty(name))
            {
                RibbonContextualTabGroup tabGroup = Owner as RibbonContextualTabGroup;
                if (tabGroup != null && tabGroup.Header != null)
                {
                    UIElement headerElement = tabGroup.Header as UIElement;
                    if (headerElement != null)
                    {
                        AutomationPeer peer = CreatePeerForElement(headerElement);
                        if (peer != null)
                        {
                            name = peer.GetName();
                        }
                    }

                    if (String.IsNullOrEmpty(name))
                    {
                        name = tabGroup.Header.ToString();
                    }
                }
            }

            return(name);
        }
        /// <summary>
        /// Called whenever RibbonTabHeaders are measured
        /// Sums up DesiredSize.Width of each RibbonTabHeader belonging to a ContextualTabGroup and stores it as ContextualTabGroup.TabsDesiredWidth.
        /// </summary>
        private void NotifyDesiredWidthChanged()
        {
            // Invalidate ContextualTabHeadersPanel
            RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;

            if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null)
            {
                foreach (RibbonContextualTabGroup tabGroup in groupHeaderItemsControl.InternalItemsHost.Children)
                {
                    tabGroup.TabsDesiredWidth          = 0.0;
                    tabGroup.DesiredExtraPaddingPerTab = 0.0;
                }
            }

            foreach (UIElement element in InternalChildren)
            {
                RibbonTabHeader tabHeader = element as RibbonTabHeader;
                if (tabHeader != null && tabHeader.IsVisible && tabHeader.IsContextualTab)
                {
                    RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup;
                    if (tabGroup != null)
                    {
                        double previousTabCount = 0;
                        if (!DoubleUtil.IsZero(tabGroup.DesiredExtraPaddingPerTab))
                        {
                            previousTabCount = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / tabGroup.DesiredExtraPaddingPerTab;
                        }
                        tabGroup.TabsDesiredWidth += tabHeader.DesiredSize.Width;
                        // compute new average
                        tabGroup.DesiredExtraPaddingPerTab = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / (previousTabCount + 1);
                    }
                }
            }
        }
Пример #3
0
        public void RenderContextualTabs(string label, Brush color, object parameter)
        {
            FluentRibbon.ContextualGroups.Clear();
            for (var index = FluentRibbon.Tabs.Count - 1; index >= 0; index--)
            {
                var ribbonTabItem = FluentRibbon.Tabs[index];
                if (ribbonTabItem.Tag as string == "Contextual")
                {
                    FluentRibbon.Tabs.Remove(ribbonTabItem);
                }
            }

            var group = new RibbonContextualTabGroup();

            FluentRibbon.ContextualGroups.Add(group);

            group.Tag        = label;
            group.Background = color;
            group.Visibility = Visibility.Visible;

            Func <ToolbarElement, bool> canRender = element =>
            {
                var command = element.Element as System.Windows.Input.ICommand;
                return(command != null && command.CanExecute(parameter));
            };

            RenderTabs(parameter, true, delegate(RibbonTabItem tab)
            {
                tab.Background = Brushes.Green;
                tab.Tag        = "Contextual";
                FluentRibbon.Tabs.Add(tab);
            }, canRender, () => parameter);
        }
Пример #4
0
        /// <summary>
        /// Método responsável em adicionar nova tab de acordo com objeto respectivo.
        /// </summary>
        /// <param name="form">Form que será referenciado para exibição do contexto.</param>
        /// <param name="value">Valor que será transportado para form</param>
        /// <param name="sender">Objeto que chamou o comando</param>
        /// <returns>Retorno a tab para objeto da chamado poder encerrar o mesmo.</returns>
        public RibbonTab AddTab(FBase form, object sender)
        {
            // Pego o caminho temporário do usuário no sistema.
            var path = Path.GetTempPath();
            // Savo a imagem temporária.
            var guid = Guid.NewGuid().ToString();

            form.ImageSource?.Save(path + $"\\{guid}.bmp");

            var context = new[]
            {
                form,
                sender
            };

            // Crio o botão da ribon, passando nome do form, e a imagem.
            var ribbonButton = new RibbonButton
            {
                Label            = form.Text ?? form.Name,
                LargeImageSource = new BitmapImage(new Uri(path + $"\\{guid}.bmp")),
                Tag = context
            };

            ribbonButton.Click += RibbonButtonOnClick;

            // Cria um grupo opções, onde conterá o botão.
            var ribbonGroup = new RibbonGroup
            {
                Header = "Opções",
                Items  = { ribbonButton }
            };

            var nameModule = form.Module;

            // Finalmente gera a tab que representará o objeto passado no contexto.
            var tab = new RibbonTab
            {
                Header = ribbonButton.Label,
                Items  = { ribbonGroup },
                ContextualTabGroupHeader = nameModule
            };

            var tabGroup = new RibbonContextualTabGroup
            {
                Header     = nameModule,
                Background = new SolidColorBrush(Color.FromRgb(254, 92, 1)),
                Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
                Visibility = Visibility.Visible,
                Margin     = new Thickness(0, -25, 0, 0),
                Width      = 150
            };

            Ribbon.ContextualTabGroups.Add(tabGroup);

            // Adiciona a tab no menu atual.
            Ribbon.Items.Add(tab);

            return(tab);
        }
Пример #5
0
        /// <summary>
        /// This algorithm calculates the extra Padding that can be assigned to a contextual tab.
        /// </summary>
        /// <param name="spaceAvailable"></param>
        /// <returns></returns>
        private double CalculateMaxPadding(double spaceAvailable)
        {
            UIElementCollection children = InternalChildren;
            int childCount = children.Count;

            // Sort DesiredPaddings
            List <double> desiredPaddings     = new List <double>();
            double        totalDesiredPadding = 0.0;

            foreach (UIElement element in children)
            {
                if (!element.IsVisible)
                {
                    continue;
                }
                RibbonTabHeader tabHeader = element as RibbonTabHeader;
                if (tabHeader != null && tabHeader.IsContextualTab)
                {
                    RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup;
                    if (tabGroup != null && DoubleUtil.GreaterThan(tabGroup.DesiredExtraPaddingPerTab, 0.0))
                    {
                        // ContextualTabGroup requires this much more width to reach its ideal DesiredSize.
                        double desiredPaddingPerTabHeader = tabGroup.DesiredExtraPaddingPerTab;
                        desiredPaddings.Add(desiredPaddingPerTabHeader);
                        totalDesiredPadding += desiredPaddingPerTabHeader;
                    }
                }
            }
            int sizeCount = desiredPaddings.Count;

            if (sizeCount == 0)
            {
                return(0.0);
            }
            desiredPaddings.Sort();

            double delta = totalDesiredPadding - spaceAvailable;

            if (DoubleUtil.LessThanOrClose(delta, 0.0))
            {
                return(desiredPaddings[sizeCount - 1]);
            }

            // Clip the TabHeader requesting most extra Padding
            double maxDesiredPadding = desiredPaddings[sizeCount - 1] - delta;

            for (int i = 1; i < sizeCount; i++)
            {
                double currentDesiredPadding = desiredPaddings[sizeCount - 1 - i];
                if (DoubleUtil.GreaterThanOrClose(maxDesiredPadding, currentDesiredPadding))
                {
                    break;
                }
                // Include next element and calculate new average
                maxDesiredPadding = ((maxDesiredPadding * i) + currentDesiredPadding) / (i + 1);
            }
            return(maxDesiredPadding);
        }
Пример #6
0
        /// <summary>
        ///     Arranges contextual tab headers
        /// </summary>
        private void ArrangeContextualTabHeaders(Size arrangeSize,
                                                 Ribbon ribbon,
                                                 Dictionary <object, List <RibbonTabHeaderAndIndex> > contextualTabHeaders,
                                                 ref int displayIndex,
                                                 ref double childX)
        {
            if (ribbon != null)
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = ribbon.ContextualTabGroupItemsControl;
                if (groupHeaderItemsControl != null)
                {
                    if (groupHeaderItemsControl.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                    {
                        int groupHeaderCount = groupHeaderItemsControl.Items.Count;
                        for (int i = 0; i < groupHeaderCount; i++)
                        {
                            RibbonContextualTabGroup groupHeader = groupHeaderItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as RibbonContextualTabGroup;
                            if (groupHeader != null)
                            {
                                object contextualTabGroupHeader = groupHeader.Header;
                                if (contextualTabGroupHeader != null && contextualTabHeaders.ContainsKey(contextualTabGroupHeader))
                                {
                                    foreach (RibbonTabHeaderAndIndex headerAndIndex in contextualTabHeaders[contextualTabGroupHeader])
                                    {
                                        RibbonTabHeader child = headerAndIndex.RibbonTabHeader;
                                        Debug.Assert(child != null);
                                        child.InvalidateVisual();
                                        child.Arrange(new Rect(childX - HorizontalOffset, arrangeSize.Height - child.DesiredSize.Height, child.DesiredSize.Width, child.DesiredSize.Height));
                                        childX += child.DesiredSize.Width;

                                        ribbon.TabDisplayIndexToIndexMap[displayIndex]         = headerAndIndex.Index;
                                        ribbon.TabIndexToDisplayIndexMap[headerAndIndex.Index] = displayIndex;
                                        displayIndex++;
                                    }

                                    contextualTabHeaders.Remove(contextualTabGroupHeader);
                                }
                            }
                        }

                        RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel;
                        if (contextualTabGroupsPanel != null)
                        {
                            contextualTabGroupsPanel.WaitingForMeasure = false;
                        }
                    }
                    else
                    {
                        // Tell the ContextualTabGroupsPanel that we are waiting on its Measure.
                        RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel;
                        if (contextualTabGroupsPanel != null)
                        {
                            contextualTabGroupsPanel.WaitingForMeasure = true;
                        }
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Selects the first tab in the ContextualTabGroup
        /// </summary>
        void IInvokeProvider.Invoke()
        {
            RibbonContextualTabGroup group = GetWrapper() as RibbonContextualTabGroup;

            // Select the first Tab
            if (group != null && group.Ribbon != null)
            {
                group.Ribbon.NotifyMouseClickedOnContextualTabGroup(group);
            }
        }
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            RibbonContextualTabGroup tabGroupHeader = element as RibbonContextualTabGroup;

            if (tabGroupHeader != null)
            {
                tabGroupHeader.PrepareTabGroupHeader(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat);
            }
        }
        protected override void ClearContainerForItemOverride(DependencyObject element, object item)
        {
            base.ClearContainerForItemOverride(element, item);
            RibbonContextualTabGroup tabGroupHeader = element as RibbonContextualTabGroup;

            if (tabGroupHeader != null)
            {
                tabGroupHeader.ClearTabGroupHeader();
            }
        }
Пример #10
0
 public IRibbonService AddRibbonContextualTabGroup(RibbonContextualTabGroup ribbonContextualTabGroup)
 {
     if (!ribbonContextualTabGroup.Dispatcher.CheckAccess())
     {
         ribbonContextualTabGroup.Dispatcher.Invoke(DispatcherPriority.Normal,
                                                    new Func <RibbonContextualTabGroup, IRibbonService>(AddRibbonContextualTabGroup), ribbonContextualTabGroup);
         return(this);
     }
     Ribbon.ContextualGroups.Add(ribbonContextualTabGroup);
     return(this);
 }
        private RibbonContextualTabGroupAutomationPeer GetWrapperPeer()
        {
            RibbonContextualTabGroupAutomationPeer wrapperPeer = null;
            RibbonContextualTabGroup wrapper = GetWrapper();

            if (wrapper != null)
            {
                wrapperPeer = UIElementAutomationPeer.CreatePeerForElement(wrapper) as RibbonContextualTabGroupAutomationPeer;
            }
            return(wrapperPeer);
        }
Пример #12
0
        protected void AddToRibbon(RibbonContextualTabGroup group)
        {
            this.Group = group;
            var shellService = ServiceLocator.Default.ResolveType <IShellService>();

            if (string.IsNullOrEmpty(this.Name))
            {
                this.Name = this.GetType().Name;
            }
            shellService.Ribbon.AddRibbonTab(this);
        }
Пример #13
0
        private double CalculateContextualTabGroupEndX(RibbonContextualTabGroup groupHeader)
        {
            double endX = CalculateContextualTabGroupStartX(groupHeader);

            foreach (RibbonTab tab in groupHeader.Tabs)
            {
                if (tab.Visibility == Visibility.Visible && tab.RibbonTabHeader != null)
                {
                    endX += tab.RibbonTabHeader.DesiredSize.Width;
                }
            }
            return(endX);
        }
        internal RibbonContextualTabGroup FindHeader(object content)
        {
            int count = this.Items.Count;

            for (int i = 0; i < count; i++)
            {
                RibbonContextualTabGroup tabGroup = this.ItemContainerGenerator.ContainerFromIndex(i) as RibbonContextualTabGroup;
                if (tabGroup != null && Object.Equals(tabGroup.Header, content))
                {
                    return(tabGroup);
                }
            }
            return(null);
        }
Пример #15
0
 private void ShowRibbonContextualTabGroup(
     RibbonContextualTabGroup rctg)
 {
     foreach (RibbonContextualTabGroup tg in crMain.ContextualTabGroups)
     {
         if (tg != rctgC1FlexGrid && tg != rctgC1Schedule && tg != rctgC1TrueDBGrid)
         {
             continue;
         }
         if (tg != rctg)
         {
             tg.Visible = false;
         }
     }
     rctg.Visible = true;
 }
Пример #16
0
        /// <summary>
        /// Ensures that a contextual tab item group with the specified header exists.
        /// </summary>
        /// <param name="ribbon">The ribbon.</param>
        /// <param name="header">The header.</param>
        /// <returns>The existing or newly created <see cref="RibbonTabItem"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref header="ribbon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref header="header"/> is <c>null</c> or whitespace.</exception>
        public static RibbonContextualTabGroup EnsureContextualTabGroup(this Ribbon ribbon, string header)
        {
            Argument.IsNotNull("ribbon", ribbon);
            Argument.IsNotNullOrWhitespace("header", header);

            var tabGroup = (from tab in ribbon.ContextualGroups
                            where string.Equals(tab.Header, header)
                            select tab).FirstOrDefault();

            if (tabGroup == null)
            {
                tabGroup        = new RibbonContextualTabGroup();
                tabGroup.Header = header;

                ribbon.ContextualGroups.Add(tabGroup);
            }

            return(tabGroup);
        }
        private bool HasTabs(FrameworkElement container)
        {
            RibbonContextualTabGroup tabGroupHeader = container as RibbonContextualTabGroup;

            if (tabGroupHeader == null ||
                !tabGroupHeader.IsVisible)
            {
                return(false);
            }
            foreach (RibbonTab tab in tabGroupHeader.Tabs)
            {
                // DDVSO: 170997 - ContextualTabGroupHeader isn't shown when the WPF Ribbon is hidden.
                // RibbonTab.Visibility shall be used to determine its visibility instead of RibbonTab.IsVisible.
                // When a RibbonTab is collapsed, its IsVisible is false to hide the content of the tab, while its Visibility is still Visible to show the header.
                if (tab != null && tab.Visibility == Visibility.Visible)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
        /// <summary>
        ///   Calculates the x-position at which the given ContextualTabGroup should be placed on the title panel.
        /// </summary>
        /// <param name="group">The RibbonContextualTabGroup to position.</param>
        /// <returns>The x-offset at which the ContextualTabGroup should be positioned.</returns>
        private double CalculateContextualTabGroupStartX(RibbonContextualTabGroup groupHeader)
        {
            double result = 0.0;

            // A visible CTG can have some of its tabs Collapsed.
            // We should start from the first visible Tab in this CTG.
            RibbonTab firstTab = groupHeader.FirstVisibleTab;

            if (firstTab != null && firstTab.RibbonTabHeader != null && Ribbon != null)
            {
                RibbonTabHeader  tabHeader = firstTab.RibbonTabHeader;
                GeneralTransform transformRibbonTabToRibbon        = tabHeader.TransformToAncestor(Ribbon);
                GeneralTransform transformRibbonToRibbonTitlePanel = Ribbon.TransformToDescendant(this);
                Point            point = new Point();
                point  = transformRibbonTabToRibbon.Transform(point);
                point  = transformRibbonToRibbonTitlePanel.Transform(point);
                result = point.X - tabHeader.Margin.Left;                 // Reduce RibbonTab Margin
            }

            return(result);
        }
Пример #19
0
        /// <summary>
        ///   Arranges the children of the RibbonTitlePanel.
        /// </summary>
        /// <param name="arrangeSize">The arranged size of the TitlePanel.</param>
        /// <returns>The size at which the TitlePanel was arranged.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            double x = 0.0;
            double width;
            double height;

            double startContextualTabX = 0;
            double endContextualTabX   = 0;

            // Arrange ContextualTabHeaders
            RibbonContextualTabGroupItemsControl tabGroups = Ribbon.ContextualTabGroupItemsControl;

            if (tabGroups != null && tabGroups.Visibility == Visibility.Visible)
            {
                RibbonContextualTabGroup firstContextualTab = tabGroups.FirstContextualTabHeader;
                if (firstContextualTab != null)
                {
                    startContextualTabX = Math.Min(CalculateContextualTabGroupStartX(firstContextualTab), finalSize.Width);
                }

                endContextualTabX = Math.Min(startContextualTabX + tabGroups.DesiredSize.Width, finalSize.Width);
                tabGroups.Arrange(new Rect(startContextualTabX, finalSize.Height - tabGroups.DesiredSize.Height, tabGroups.DesiredSize.Width, tabGroups.DesiredSize.Height));
            }

            // Arrange QuickAccessToolbar
            double    qatDesiredWidth = 0.0;
            UIElement qat             = Ribbon.QatTopHost;

            if (qat != null)
            {
                qatDesiredWidth = qat.DesiredSize.Width;
                qat.Arrange(new Rect(0, 0.0, qatDesiredWidth, qat.DesiredSize.Height));
            }

            endContextualTabX = Math.Max(endContextualTabX, qatDesiredWidth);

            // Arrange the title
            UIElement titleHost = Ribbon.TitleHost;

            if (titleHost != null)
            {
                x      = 0.0;
                width  = titleHost.DesiredSize.Width;
                height = titleHost.DesiredSize.Height;
                double leftSpace = startContextualTabX - qatDesiredWidth;

                // If title can fit entirely to the left, then arrange on the left
                // i.e. between QAT and CTGHeaders
                if (DoubleUtil.LessThanOrClose(width, leftSpace))
                {
                    x = qatDesiredWidth;
                }
                else
                {
                    // Arrange to the right of CTGHeaders.
                    x = endContextualTabX;
                }

                titleHost.Arrange(new Rect(x, 0.0, width, height));
            }

            return(finalSize);
        }
Пример #20
0
 public TabsEnumerable(RibbonContextualTabGroup tabGroup)
 {
     ContextualTabGroup = tabGroup;
 }
 public RibbonContextualTabGroupAutomationPeer(RibbonContextualTabGroup owner)
     : base(owner)
 {
 }
Пример #22
0
        /// <summary>
        ///     Called when HeaderProperty is invalidated on "d."
        /// </summary>
        private static void OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonContextualTabGroup ctrl = (RibbonContextualTabGroup)d;

            ctrl.OnHeaderChanged(e.OldValue, e.NewValue);
        }
Пример #23
0
            /// <summary>
            /// Creates the ribbon menu bar for the html editor.
            /// </summary>
            /// <param name="ribbonMenu">Main ribbon menu.</param>
            public override void CreateRibbonMenuBar(Fluent.Ribbon ribbonMenu)
            {
                foreach (RibbonContextualTabGroup t in ribbonMenu.ContextualGroups)
                {
                    if (t.Name == "tabGroupHtml")
                    {
                        return;
                    }
                }

                // add contextual items for the html editor
                RibbonContextualTabGroup contextualTG = new RibbonContextualTabGroup();

                contextualTG.Name        = "tabGroupHtml";
                contextualTG.BorderBrush = new SolidColorBrush(Colors.Orange);
                contextualTG.Background  = new SolidColorBrush(Colors.OrangeRed);
                contextualTG.Header      = "Html-Editor";

                Binding visibilityBinding = new Binding("ActiveViewModel.SelectedEditorViewModel.IsHtmlEditorViewModelVisible");

                visibilityBinding.Converter = new BooleanToVisibilityConverter();
                visibilityBinding.Mode      = BindingMode.OneWay;
                contextualTG.SetBinding(RibbonContextualTabGroup.VisibilityProperty, visibilityBinding);

                // add the html editor tab item
                RibbonTabItem tab = new RibbonTabItem();

                tab.Group  = contextualTG;
                tab.Header = "Design";

                // font group box
                RibbonGroupBox fontGP = new RibbonGroupBox();

                fontGP.Header = "Font";
                tab.Groups.Add(fontGP);

                #region Button Bold
                Fluent.ToggleButton btnBold = new Fluent.ToggleButton();
                btnBold.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnBold.SizeDefinition = "Large";
                btnBold.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-text-bold-32.png"));
                btnBold.Text = "Bold";

                Binding btnBoldCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlToggleBoldCommand");
                btnBoldCmdn.Mode = BindingMode.OneWay;
                btnBold.SetBinding(Fluent.ToggleButton.CommandProperty, btnBoldCmdn);

                Binding btnBoldIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionTextBold");
                btnBoldIsChecked.Mode = BindingMode.TwoWay;
                btnBold.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnBoldIsChecked);

                fontGP.Items.Add(btnBold);
                #endregion

                #region Button Italic
                Fluent.ToggleButton btnItalic = new Fluent.ToggleButton();
                btnItalic.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnItalic.SizeDefinition = "Large";
                btnItalic.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-text-italic-32.png"));
                btnItalic.Text = "Italic";

                Binding btnItalicCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlToggleItalicCommand");
                btnItalicCmdn.Mode = BindingMode.OneWay;
                btnItalic.SetBinding(Fluent.ToggleButton.CommandProperty, btnItalicCmdn);

                Binding btnItalicIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionTextItalic");
                btnItalicIsChecked.Mode = BindingMode.TwoWay;
                btnItalic.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnItalicIsChecked);

                fontGP.Items.Add(btnItalic);
                #endregion

                #region Button Underline
                Fluent.ToggleButton btnUnderline = new Fluent.ToggleButton();
                btnUnderline.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnUnderline.SizeDefinition = "Large";
                btnUnderline.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-text-underline-32.png"));
                btnUnderline.Text = "Underline";

                Binding btnUnderlineCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlToggleUnderlineCommand");
                btnUnderlineCmdn.Mode = BindingMode.OneWay;
                btnUnderline.SetBinding(Fluent.ToggleButton.CommandProperty, btnUnderlineCmdn);

                Binding btnUnderlineIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionTextUnderlined");
                btnUnderlineIsChecked.Mode = BindingMode.TwoWay;
                btnUnderline.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnUnderlineIsChecked);

                fontGP.Items.Add(btnUnderline);
                #endregion

                // format group box
                RibbonGroupBox formatGP = new RibbonGroupBox();
                formatGP.Header = "Format";
                tab.Groups.Add(formatGP);

                #region Button Decrease Indent
                Fluent.Button btnDecIndent = new Fluent.Button();
                btnDecIndent.SizeDefinition = "Large";
                btnDecIndent.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-indent-less-32.png"));
                btnDecIndent.Text = "Decrease Indent";

                Binding btnDecIndentCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlIndentLessCommand");
                btnDecIndentCmdn.Mode = BindingMode.OneWay;
                btnDecIndent.SetBinding(Fluent.Button.CommandProperty, btnDecIndentCmdn);

                formatGP.Items.Add(btnDecIndent);
                #endregion

                #region Button Increase Indent
                Fluent.Button btnIncIndent = new Fluent.Button();
                btnIncIndent.SizeDefinition = "Large";
                btnIncIndent.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-indent-more-32.png"));
                btnIncIndent.Text = "Increase Indent";

                Binding btnIncIndentCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlIndentMoreCommand");
                btnIncIndentCmdn.Mode = BindingMode.OneWay;
                btnIncIndent.SetBinding(Fluent.Button.CommandProperty, btnIncIndentCmdn);

                formatGP.Items.Add(btnIncIndent);
                #endregion

                // alignment group box
                RibbonGroupBox alignGP = new RibbonGroupBox();
                alignGP.Header = "Alignment";
                tab.Groups.Add(alignGP);

                #region Button Align Left
                Fluent.ToggleButton btnLeft = new Fluent.ToggleButton();
                btnLeft.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnLeft.SizeDefinition = "Large";
                btnLeft.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-justify-left-32.png"));
                btnLeft.Text = "Left";

                Binding btnLeftCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlAlignLeftCommand");
                btnLeftCmdn.Mode = BindingMode.OneWay;
                btnLeft.SetBinding(Fluent.ToggleButton.CommandProperty, btnLeftCmdn);

                Binding btnLeftIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionAlignedLeft");
                btnLeftIsChecked.Mode = BindingMode.TwoWay;
                btnLeft.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnLeftIsChecked);

                alignGP.Items.Add(btnLeft);
                #endregion

                #region Button Align Center
                Fluent.ToggleButton btnCenter = new Fluent.ToggleButton();
                btnCenter.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnCenter.SizeDefinition = "Large";
                btnCenter.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-justify-center-32.png"));
                btnCenter.Text = "Center";

                Binding btnCenterCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlAlignCenterCommand");
                btnCenterCmdn.Mode = BindingMode.OneWay;
                btnCenter.SetBinding(Fluent.ToggleButton.CommandProperty, btnCenterCmdn);

                Binding btnCenterIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionAlignedCenter");
                btnCenterIsChecked.Mode = BindingMode.TwoWay;
                btnCenter.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnCenterIsChecked);

                alignGP.Items.Add(btnCenter);
                #endregion

                #region Button Align Right
                Fluent.ToggleButton btnRight = new Fluent.ToggleButton();
                btnRight.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnRight.SizeDefinition = "Large";
                btnRight.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-justify-right-32.png"));
                btnRight.Text = "Right";

                Binding btnRightCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlAlignRightCommand");
                btnRightCmdn.Mode = BindingMode.OneWay;
                btnRight.SetBinding(Fluent.ToggleButton.CommandProperty, btnRightCmdn);

                Binding btnRightIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionAlignedRight");
                btnRightIsChecked.Mode = BindingMode.TwoWay;
                btnRight.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnRightIsChecked);

                alignGP.Items.Add(btnRight);
                #endregion

                #region Button Align Justify
                Fluent.ToggleButton btnJustify = new Fluent.ToggleButton();
                btnJustify.Margin         = new System.Windows.Thickness(2, 0, 0, 0);
                btnJustify.SizeDefinition = "Large";
                btnJustify.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/format-justify-fill-32.png"));
                btnJustify.Text = "Justify";

                Binding btnJustifyCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlAlignJustifyCommand");
                btnJustifyCmdn.Mode = BindingMode.OneWay;
                btnJustify.SetBinding(Fluent.ToggleButton.CommandProperty, btnJustifyCmdn);

                Binding btnJustifyIsChecked = new Binding("ActiveViewModel.SelectedEditorViewModel.IsSelectionAlignedJustified");
                btnJustifyIsChecked.Mode = BindingMode.TwoWay;
                btnJustify.SetBinding(Fluent.ToggleButton.IsCheckedProperty, btnJustifyIsChecked);

                alignGP.Items.Add(btnJustify);
                #endregion

                // insert group box
                RibbonGroupBox insertGP = new RibbonGroupBox();
                insertGP.Header = "Insert";
                tab.Groups.Add(insertGP);

                #region Button Hyperlink
                Fluent.Button btnHyperlink = new Fluent.Button();
                btnHyperlink.SizeDefinition = "Large";
                btnHyperlink.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/Hyperlink.ico"));
                btnHyperlink.Text = "Hyperlink";

                Binding btnHyperlinkCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlInsertHyperlinkCommand");
                btnHyperlinkCmdn.Mode = BindingMode.OneWay;
                btnHyperlink.SetBinding(Fluent.Button.CommandProperty, btnHyperlinkCmdn);

                insertGP.Items.Add(btnHyperlink);
                #endregion

                #region Button Image
                Fluent.Button btnImage = new Fluent.Button();
                btnImage.SizeDefinition = "Large";
                btnImage.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/insert-image-32.png"));
                btnImage.Text = "Image";

                Binding btnImageCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlInsertImageCommand");
                btnImageCmdn.Mode = BindingMode.OneWay;
                btnImage.SetBinding(Fluent.Button.CommandProperty, btnImageCmdn);

                insertGP.Items.Add(btnImage);
                #endregion

                #region Button List
                Fluent.SplitButton btnList = new SplitButton();
                btnList.SizeDefinition = "Large";
                btnList.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/list-32.png"));
                btnList.Text = "List";
                insertGP.Items.Add(btnList);

                Fluent.Button btnBulletedList = new Fluent.Button();
                btnBulletedList.SizeDefinition = "Middle";
                btnBulletedList.Icon           = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/List_BulletsHS.png"));
                btnBulletedList.Text = "Bulleted List";

                Binding btnBulletedListCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlInsertBulletListCommand");
                btnBulletedListCmdn.Mode = BindingMode.OneWay;
                btnBulletedList.SetBinding(Fluent.Button.CommandProperty, btnBulletedListCmdn);

                btnList.Items.Add(btnBulletedList);

                Fluent.Button btnNumberedList = new Fluent.Button();
                btnNumberedList.SizeDefinition = "Middle";
                btnNumberedList.Icon           = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/List_NumberedHS.png"));
                btnNumberedList.Text = "Numbered List";

                Binding btnNumberedListCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlInsertNumberListCommand");
                btnNumberedListCmdn.Mode = BindingMode.OneWay;
                btnNumberedList.SetBinding(Fluent.Button.CommandProperty, btnNumberedListCmdn);

                btnList.Items.Add(btnNumberedList);
                #endregion

                #region Button Table
                Fluent.Button btnTable = new Fluent.Button();
                btnTable.SizeDefinition = "Large";
                btnTable.LargeIcon      = new System.Windows.Media.Imaging.BitmapImage(
                    new Uri("pack://application:,,,/Tum.PDE.ToolFramework.Modeling.Visualization.VMXExtensions;component/Resources/Images/HtmlEditor/table-32.png"));
                btnTable.Text = "Table";

                Binding btnTableCmdn = new Binding("ActiveViewModel.SelectedEditorViewModel.HtmlInsertTableCommand");
                btnTableCmdn.Mode = BindingMode.OneWay;
                btnTable.SetBinding(Fluent.Button.CommandProperty, btnTableCmdn);

                insertGP.Items.Add(btnTable);
                #endregion

                ribbonMenu.ContextualGroups.Add(contextualTG);
                ribbonMenu.Tabs.Add(tab);

                /*
                 * <fluent:RibbonGroupBox Header="Font">
                 *      <fluent:ToggleButton Text="Bold" Command="{Binding Path=HtmlToggleBoldCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-text-bold-32.png" IsChecked="{Binding Path=IsSelectionTextBold, Mode=TwoWay}" SizeDefinition="Large"/>
                 *      <fluent:ToggleButton Text="Italic" Command="{Binding Path=HtmlToggleItalicCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-text-italic-32.png" IsChecked="{Binding Path=IsSelectionTextItalic, Mode=TwoWay}" SizeDefinition="Large"/>
                 *      <fluent:ToggleButton Text="Underline" Command="{Binding Path=HtmlToggleUnderlineCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-text-underline-32.png" IsChecked="{Binding Path=IsSelectionTextUnderlined, Mode=TwoWay}" SizeDefinition="Large"/>
                 *  </fluent:RibbonGroupBox>
                 *
                 *  <fluent:RibbonGroupBox Header="Format">
                 *      <fluent:Button Text="Decrease Indent" Command="{Binding Path=HtmlIndentLessCommand}" LargeIcon="/Resources/Images/HtmlEditor/format-indent-less-32.png"  SizeDefinition="Large"/>
                 *      <fluent:Button Text="Increase Indent" Command="{Binding Path=HtmlIndentMoreCommand}" LargeIcon="/Resources/Images/HtmlEditor/format-indent-more-32.png" SizeDefinition="Large"/>
                 *  </fluent:RibbonGroupBox>
                 *
                 *  <fluent:RibbonGroupBox Header="Font">
                 *      <fluent:ToggleButton Text="Left" Command="{Binding Path=HtmlAlignLeftCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-justify-left-32.png" IsChecked="{Binding Path=IsSelectionAlignedLeft, Mode=TwoWay}" SizeDefinition="Large"/>
                 *      <fluent:ToggleButton Text="Center" Command="{Binding Path=HtmlAlignCenterCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-justify-center-32.png" IsChecked="{Binding Path=IsSelectionAlignedCenter, Mode=TwoWay}" SizeDefinition="Large"/>
                 *      <fluent:ToggleButton Text="Right" Command="{Binding Path=HtmlAlignRightCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-justify-right-32.png" IsChecked="{Binding Path=IsSelectionAlignedRight, Mode=TwoWay}" SizeDefinition="Large"/>
                 *      <fluent:ToggleButton Text="Justify" Command="{Binding Path=HtmlAlignJustifyCommand}" Margin="2,0,0,0" LargeIcon="/Resources/Images/HtmlEditor/format-justify-fill-32.png" IsChecked="{Binding Path=IsSelectionAlignedJustified, Mode=TwoWay}" SizeDefinition="Large"/>
                 *  </fluent:RibbonGroupBox>
                 *
                 *  <fluent:RibbonGroupBox Header="Insert">
                 *      <fluent:Button Text="Hyperlink" Command="{Binding Path=HtmlInsertHyperlinkCommand}" LargeIcon="/Resources/Images/Ico/Hyperlink.ico"  SizeDefinition="Large"/>
                 *      <fluent:Button Text="Image" Command="{Binding Path=HtmlInsertImageCommand}" LargeIcon="/Resources/Images/HtmlEditor/insert-image-32.png" SizeDefinition="Large"/>
                 *      <fluent:SplitButton Text="List" LargeIcon="/Resources/Images/HtmlEditor/list-32.png" SizeDefinition="Large">
                 *          <fluent:Button Text="Bulleted List" Command="{Binding Path=HtmlInsertBulletListCommand}" Icon="/Resources/Images/HtmlEditor/List_BulletsHS.png" SizeDefinition="Middle"/>
                 *          <fluent:Button Text="Numbered List" Command="{Binding Path=HtmlInsertNumberListCommand}" Icon="/Resources/Images/HtmlEditor/List_NumberedHS.png" SizeDefinition="Middle"/>
                 *      </fluent:SplitButton>
                 *      <fluent:Button Text="Table" Command="{Binding Path=HtmlInsertTableCommand}" LargeIcon="/Resources/Images/HtmlEditor/table-32.png" SizeDefinition="Large"/>
                 *  </fluent:RibbonGroupBox>
                 */
            }
Пример #24
0
        private double CalculateContextualTabGroupEndX(RibbonContextualTabGroup groupHeader)
        {
            double endX = CalculateContextualTabGroupStartX(groupHeader);

            foreach (RibbonTab tab in groupHeader.Tabs)
            {
                if (tab.Visibility == Visibility.Visible && tab.RibbonTabHeader != null)
                {
                    endX += tab.RibbonTabHeader.DesiredSize.Width;
                }
            }
            return endX;
        }
        /// <summary>
        /// Create ribbon menus.
        /// </summary>
        /// <param name="ribbonMenu"></param>
        public override void CreateRibbonMenu(Ribbon ribbonMenu)
        {
            base.CreateRibbonMenu(ribbonMenu);

            // in case the tab group is used for multiple vms, prevent multiple tabs beeing created
            foreach (Fluent.RibbonContextualTabGroup t in ribbonMenu.ContextualGroups)
            {
                if (t.Name == "tabGroupExamplePlugin")
                {
                    exampleTabGroup = t;
                    return;
                }
            }

            // contextual tab, which should only be visible when the example diagram surface is active
            exampleTabGroup             = new RibbonContextualTabGroup();
            exampleTabGroup.Header      = "Example Tab Group";
            exampleTabGroup.BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.LightBlue);
            exampleTabGroup.Background  = new SolidColorBrush(System.Windows.Media.Colors.LightBlue);
            exampleTabGroup.Name        = "tabGroupExamplePlugin";

            // create ribbon bar and associate it with the contextual group
            RibbonTabItem exampleTab = new RibbonTabItem();

            exampleTab.Header = "Example View Operations";
            exampleTab.Group  = exampleTabGroup;

            // Analyze group
            RibbonGroupBox analyzeGroup = new RibbonGroupBox();

            analyzeGroup.Header = "Analyze";
            exampleTab.Groups.Add(analyzeGroup);

            Fluent.Button buttonAnalyze = new Fluent.Button();
            buttonAnalyze.Text      = "Analyze";
            buttonAnalyze.Command   = this.command;
            buttonAnalyze.Size      = RibbonControlSize.Large;
            buttonAnalyze.LargeIcon = GetImage("prepare_32.png");
            analyzeGroup.Items.Add(buttonAnalyze);

            // View group
            RibbonGroupBox viewGroup = new RibbonGroupBox();

            viewGroup.Header = "View";
            exampleTab.Groups.Add(viewGroup);

            Fluent.ToggleButton buttonTree = new Fluent.ToggleButton();
            buttonTree.Text      = "Tree";
            buttonTree.LargeIcon = GetImage("tree-32.png");
            viewGroup.Items.Add(buttonTree);

            Fluent.ToggleButton buttonTable = new Fluent.ToggleButton();
            buttonTable.Text      = "Table";
            buttonTable.LargeIcon = GetImage("table-32.png");
            viewGroup.Items.Add(buttonTable);

            // Export group
            RibbonGroupBox exportGroup = new RibbonGroupBox();

            exportGroup.Header = "Export";
            exampleTab.Groups.Add(exportGroup);

            Fluent.Button buttonExportCSV = new Fluent.Button();
            buttonExportCSV.Text      = "Export as CSV-File";
            buttonExportCSV.Size      = RibbonControlSize.Large;
            buttonExportCSV.LargeIcon = GetImage("csv_32x32.png");
            buttonExportCSV.Command   = this.command;
            exportGroup.Items.Add(buttonExportCSV);

            Fluent.Button buttonExportHTML = new Fluent.Button();
            buttonExportHTML.Text      = "Export as HTML Website";
            buttonExportHTML.Size      = RibbonControlSize.Large;
            buttonExportHTML.LargeIcon = GetImage("html_32x32.png");
            buttonExportHTML.Command   = this.command;
            exportGroup.Items.Add(buttonExportHTML);

            Fluent.Button buttonExportPDF = new Fluent.Button();
            buttonExportPDF.Text      = "Export as PDF Document";
            buttonExportPDF.Size      = RibbonControlSize.Large;
            buttonExportPDF.LargeIcon = GetImage("pdf_32x32.png");
            buttonExportPDF.Command   = this.command;
            exportGroup.Items.Add(buttonExportPDF);

            ribbonMenu.ContextualGroups.Add(exampleTabGroup);
            ribbonMenu.Tabs.Add(exampleTab);
        }
Пример #26
0
        /// <summary>
        ///   Calculates the x-position at which the given ContextualTabGroup should be placed on the title panel.
        /// </summary>
        /// <param name="group">The RibbonContextualTabGroup to position.</param>
        /// <returns>The x-offset at which the ContextualTabGroup should be positioned.</returns>
        private double CalculateContextualTabGroupStartX(RibbonContextualTabGroup groupHeader)
        {
            double result = 0.0;

            // A visible CTG can have some of its tabs Collapsed.
            // We should start from the first visible Tab in this CTG.
            RibbonTab firstTab = groupHeader.FirstVisibleTab;
            if (firstTab != null && firstTab.RibbonTabHeader != null && Ribbon != null)
            {
                RibbonTabHeader tabHeader = firstTab.RibbonTabHeader;
                GeneralTransform transformRibbonTabToRibbon = tabHeader.TransformToAncestor(Ribbon);
                GeneralTransform transformRibbonToRibbonTitlePanel = Ribbon.TransformToDescendant(this);
                Point point = new Point();
                point = transformRibbonTabToRibbon.Transform(point);
                point = transformRibbonToRibbonTitlePanel.Transform(point);
                result = point.X - tabHeader.Margin.Left; // Reduce RibbonTab Margin
            }

            return result;
        }
Пример #27
0
        /// <summary>
        ///     Measure
        /// </summary>
        protected override Size MeasureOverride(Size availableSize)
        {
            // Note: The logic below assumes that the TabHeaders belonging to inactive
            // ContextualTabGroups have their IsVisible set to false.

            //_separatorOpacity = 0.0;
            Size desiredSize = new Size();

            UIElementCollection children = InternalChildren;

            if (children.Count == 0)
            {
                return(desiredSize);
            }

            Size   childConstraint  = new Size(double.PositiveInfinity, availableSize.Height);
            int    countRegularTabs = 0;
            double totalDefaultPaddingAllTabHeaders     = 0;
            double totalDefaultPaddingRegularTabHeaders = 0;
            double totalDesiredWidthRegularTabHeaders   = 0;
            bool   showRegularTabHeaderToolTips         = false;
            bool   showContextualTabHeaderToolTips      = false;
            int    countVisibleTabs = 0;

            // Measure all TabHeaders to fit their content
            // desiredSize should hold the total size required to fit all TabHeaders
            desiredSize = InitialMeasure(childConstraint,
                                         out totalDefaultPaddingAllTabHeaders,
                                         out totalDefaultPaddingRegularTabHeaders,
                                         out totalDesiredWidthRegularTabHeaders,
                                         out countRegularTabs,
                                         out countVisibleTabs);

            int countContextualTabs = countVisibleTabs - countRegularTabs;

            SpaceAvailable = 0.0;
            double overflowWidth = desiredSize.Width - availableSize.Width;             // Total overflow width

            if (DoubleUtil.GreaterThan(overflowWidth, 0))
            {
                // Calculate max tab width if tab clipping is necessary
                double totalClipWidthRegularTabHeaders    = 0;                               // How much pixels we need to clip regular tabs
                double totalClipWidthContextualTabHeaders = 0;                               // How much pixels we need to clip contextual tabs

                if (DoubleUtil.GreaterThan(overflowWidth, totalDefaultPaddingAllTabHeaders)) // Clipping is necessary - all tabs padding will we 0
                {
                    showRegularTabHeaderToolTips    = true;
                    totalClipWidthRegularTabHeaders = overflowWidth - totalDefaultPaddingAllTabHeaders;                     // Try to use the whole totalClipAmount in the regular tabs
                }

                double maxRegularTabHeaderWidth = CalculateMaxTabHeaderWidth(totalClipWidthRegularTabHeaders, false);
                if (DoubleUtil.AreClose(maxRegularTabHeaderWidth, _tabHeaderMinWidth))                 // Regular tabs are clipped to the min size -  need to clip contextual tabs
                {
                    showContextualTabHeaderToolTips = true;
                    double totalClipAmount = overflowWidth - totalDefaultPaddingAllTabHeaders;
                    double usedClipAmount  = totalDesiredWidthRegularTabHeaders - totalDefaultPaddingRegularTabHeaders - (_tabHeaderMinWidth * countRegularTabs);
                    totalClipWidthContextualTabHeaders = totalClipAmount - usedClipAmount;                     // Remaining clipping amount
                }

                double maxContextualTabHeaderWidth      = CalculateMaxTabHeaderWidth(totalClipWidthContextualTabHeaders, true);
                double reducePaddingRegularTabHeader    = 0;
                double reducePaddingContextualTabHeader = 0;

                if (DoubleUtil.GreaterThanOrClose(totalDefaultPaddingRegularTabHeaders, overflowWidth))
                {
                    reducePaddingRegularTabHeader = (0.5 * overflowWidth) / countRegularTabs;
                    //_separatorOpacity = Math.Max(0.0, reducePaddingRegularTabHeader * 0.2);
                }
                else
                {
                    //_separatorOpacity = 1.0;
                    reducePaddingRegularTabHeader = double.PositiveInfinity;
                    // If countContextualTabs==0 then reducePaddingContextualTab will become Infinity
                    reducePaddingContextualTabHeader = (0.5 * (overflowWidth - totalDefaultPaddingRegularTabHeaders)) / (countVisibleTabs - countRegularTabs);
                }

                desiredSize = FinalMeasure(childConstraint,
                                           reducePaddingContextualTabHeader,
                                           reducePaddingRegularTabHeader,
                                           maxContextualTabHeaderWidth,
                                           maxRegularTabHeaderWidth);
            }
            else if (countContextualTabs > 0)
            {
                // After assigning DefaultPadding, we are left with extra space.
                // If contextual tabs need that extra space, assign them more padding.
                NotifyDesiredWidthChanged();
                double spaceAvailable            = availableSize.Width - desiredSize.Width;
                double availableExtraWidthPerTab = CalculateMaxPadding(spaceAvailable);

                foreach (UIElement child in InternalChildren)
                {
                    RibbonTabHeader ribbonTabHeader = child as RibbonTabHeader;
                    if (ribbonTabHeader != null && ribbonTabHeader.IsVisible && ribbonTabHeader.IsContextualTab)
                    {
                        RibbonContextualTabGroup ctg = ribbonTabHeader.ContextualTabGroup;
                        if (ctg != null && DoubleUtil.GreaterThan(ctg.DesiredExtraPaddingPerTab, 0.0))
                        {
                            double desiredExtraPaddingPerTab = ctg.DesiredExtraPaddingPerTab;
                            double availableExtraWidth       = Math.Min(desiredExtraPaddingPerTab, availableExtraWidthPerTab);

                            Thickness newPadding = ribbonTabHeader.Padding;
                            newPadding.Left        += availableExtraWidth * 0.5;
                            newPadding.Right       += availableExtraWidth * 0.5;
                            ribbonTabHeader.Padding = newPadding;

                            // Remeasure with added padding
                            desiredSize.Width -= ribbonTabHeader.DesiredSize.Width;
                            ribbonTabHeader.Measure(new Size(Double.MaxValue, childConstraint.Height));
                            desiredSize.Width += ribbonTabHeader.DesiredSize.Width;
                        }
                    }
                }
            }

            // If the difference between desiredWidth and constraintWidth is less
            // than 1e-10 then assume that both are same. This avoids unnecessary
            // inequalities in extent and viewport resulting in spontaneous
            // flickering of scroll button.
            if (Math.Abs(desiredSize.Width - availableSize.Width) < _desiredWidthEpsilon)
            {
                desiredSize.Width = availableSize.Width;
            }

            SpaceAvailable = availableSize.Width - desiredSize.Width;
            // Update ContextualTabGroup.TabsDesiredWidth
            NotifyDesiredWidthChanged();

            // Update whether tooltips should be shown.
            UpdateToolTips(showRegularTabHeaderToolTips, showContextualTabHeaderToolTips);

            VerifyScrollData(availableSize.Width, desiredSize.Width);


            // Invalidate ContextualTabHeadersPanel
            if (Ribbon != null)
            {
                RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;
                if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null)
                {
                    groupHeaderItemsControl.InternalItemsHost.InvalidateMeasure();
                }
            }

            return(desiredSize);
        }
Пример #28
0
        /// <summary>
        ///   Measures the children of the RibbonTitlePanel.
        /// </summary>
        /// <param name="constraint">The space available for layout.</param>
        /// <returns>Returns the RibbonTitlePanel's desired size as determined by measurement of its children.</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            Size desiredSize = new Size();
            int  count       = Children.Count;

            if (count == 0)
            {
                return(desiredSize);
            }

            double startContextualTabX = availableSize.Width;
            double endContextualTabX   = 0.0;

            RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl;

            if (groupHeaderItemsControl != null && groupHeaderItemsControl.Visibility == Visibility.Visible)
            {
                // A dummy measure to ensure containers are generated.
                // We need to know FirstContextualTabHeader and LastContextualTabHeader
                if (groupHeaderItemsControl.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                {
                    groupHeaderItemsControl.Measure(availableSize);
                }

                // Calculate start and end positions
                RibbonContextualTabGroup firstContextualTab = groupHeaderItemsControl.FirstContextualTabHeader;
                if (firstContextualTab != null)
                {
                    startContextualTabX = Math.Min(CalculateContextualTabGroupStartX(firstContextualTab), availableSize.Width);
                }

                RibbonContextualTabGroup lastContextualTab = groupHeaderItemsControl.LastContextualTabHeader;
                if (lastContextualTab != null)
                {
                    endContextualTabX = Math.Min(CalculateContextualTabGroupEndX(lastContextualTab), availableSize.Width);
                }

                groupHeaderItemsControl.Measure(new Size(Math.Max(endContextualTabX - startContextualTabX, 0), availableSize.Height));
                desiredSize.Width += groupHeaderItemsControl.DesiredSize.Width;
                desiredSize.Height = Math.Max(desiredSize.Height, groupHeaderItemsControl.DesiredSize.Height);
            }

            FrameworkElement qat       = Ribbon.QatTopHost as FrameworkElement;
            FrameworkElement titleHost = Ribbon.TitleHost as FrameworkElement;

            if (qat != null && titleHost != null)
            {
                double availableToQat = 0.0, availableToTitle;
                double leftSpace, rightSpace;

                // If ribbon is not collapsed and QAT is on top
                if (qat.Visibility == Visibility.Visible)
                {
                    rightSpace = availableSize.Width - endContextualTabX;
                    // 1) if there is no room on the right for Title
                    // 2) or when there are no contextual tabs (i.e. endContextualTabX==0), then rightSpace=entire width
                    //  want to ensure MinWidth for title if possible
                    if ((DoubleUtil.LessThan(rightSpace, titleHost.MinWidth) ||
                         DoubleUtil.GreaterThan(startContextualTabX, endContextualTabX)) &&
                        DoubleUtil.GreaterThan(startContextualTabX, titleHost.MinWidth))
                    {
                        // Leave titleHost.MinWidth at the left of ContextualTabGroupItemsControl for TitleHost
                        availableToQat = startContextualTabX - titleHost.MinWidth;
                    }
                    else
                    {
                        // Give QAT space from 0 to start of ContextualTabGroupItemsControl
                        availableToQat = startContextualTabX;
                    }
                    // The size computed could be negative because of invalid
                    // transforms due to invalid arrange. Assume that the space
                    // available is 0 in such cases and assume that validation of
                    // transforms at a later point of time will fix the situation.
                    availableToQat = Math.Max(availableToQat, 0);

                    // Measure QAT
                    qat.Measure(new Size(availableToQat, availableSize.Height));
                    availableToQat = qat.DesiredSize.Width;

                    desiredSize.Width += availableToQat;
                    desiredSize.Height = Math.Max(desiredSize.Height, qat.DesiredSize.Height);
                }

                // Measure TitleHost.
                // We try to give it titleHost.MinWidth, but it may get less than that when QAT has already reached qat.MinWidth
                endContextualTabX = Math.Max(endContextualTabX, availableToQat);
                rightSpace        = availableSize.Width - endContextualTabX;
                leftSpace         = startContextualTabX - availableToQat;

                // first measure to title's full size and see if it can fit entirely to the left
                titleHost.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                if (DoubleUtil.LessThanOrClose(titleHost.DesiredSize.Width, leftSpace))
                {
                    availableToTitle = leftSpace;
                }
                else
                {
                    // title takes best of right or left
                    availableToTitle = Math.Max(leftSpace, rightSpace);
                }
                // The size computed could be negative because of invalid
                // transforms due to invalid arrange. Assume that the space
                // available is 0 in such cases and assume that validation of
                // transforms at a later point of time will fix the situation.
                availableToTitle = Math.Max(availableToTitle, 0);

                titleHost.Measure(new Size(availableToTitle, availableSize.Height));
                desiredSize.Width += titleHost.DesiredSize.Width;
                desiredSize.Height = Math.Max(desiredSize.Height, titleHost.DesiredSize.Height);
            }

            desiredSize.Width = Math.Min(desiredSize.Width, availableSize.Width);             // Prevent clipping
            return(desiredSize);
        }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns>null: Delay add</returns>
        private RibbonGroupBox GetUiPosition(CompositeRemoteCommand command, out RibbonTabItem ribbonTab)
        {
            Argument.IsNotNull(() => command.DeserializedUIData);
            Argument.IsOfType(() => command.DeserializedUIData, typeof(RibbonUIData));
            var ribbonUiData  = (RibbonUIData)(command.DeserializedUIData);
            var ribbonTabData = ribbonUiData.UiPosition.RibbonTab;
            //find ribbon tab
            string tabName = null;

            if (ribbonTabData == null || string.IsNullOrEmpty(ribbonTabData.Name))
            {
                tabName = "RibbonTabHome";
            }
            else
            {
                tabName = ribbonTabData.Name;
            }
            ribbonTab = Ribbon.Tabs.FirstOrDefault(tab => tab.Name.Equals(tabName));
            if (ribbonTab == null)
            {
                if (ribbonTabData != null && ribbonTabData.CreatNewIfCanNotFound)
                {
                    //ToDo: creat new, consider contextual tab?
                    ribbonTab = new RibbonTabItem {
                        Name = ribbonTabData.Name
                    };
                    ribbonTab.BindToLoc(RibbonTabItem.HeaderProperty, ribbonTabData.LocalizedHeader);
                    //Consider ribbon tab group data
                    var ribbonGroupData = ribbonUiData.UiPosition.RibbonTabGroup;
                    if (!string.IsNullOrEmpty(ribbonGroupData.Name))
                    {
                        //find or create
                        var tabGroup = Ribbon.ContextualGroups.FirstOrDefault(ribbonGroup => ribbonGroup.Name.Equals(ribbonGroupData.Name));
                        if (tabGroup == null)
                        {
                            var conv = new BrushConverter();
                            tabGroup = new RibbonContextualTabGroup()
                            {
                                Visibility = Visibility.Visible, Name = ribbonGroupData.Name
                            };

                            if (!string.IsNullOrEmpty(ribbonGroupData.BorderBrush))
                            {
                                tabGroup.BorderBrush =
                                    conv.ConvertFromString(ribbonGroupData.BorderBrush) as SolidColorBrush;
                            }
                            if (!string.IsNullOrEmpty(ribbonGroupData.BackgroundBrush))
                            {
                                tabGroup.Background =
                                    conv.ConvertFromString(ribbonGroupData.BackgroundBrush) as SolidColorBrush;
                            }

                            if (string.IsNullOrEmpty(ribbonGroupData.LocalizedHeader))
                            {
                                tabGroup.Header = ribbonGroupData.Name;
                            }
                            else
                            {
                                tabGroup.BindToLoc(RibbonContextualTabGroup.HeaderProperty, ribbonGroupData.LocalizedHeader);
                            }
                            ShellService.Ribbon.AddRibbonContextualTabGroup(tabGroup);
                        }
                        if (ribbonTab.Group == null)
                        {
                            ribbonTab.Group = tabGroup;
                        }
                    }
                    ShellService.Ribbon.AddRibbonTab(ribbonTab);
                }
                else
                {
                    //delay the remote command add.
                    DelayGenerateUiList.Add(command);
                    return(null);
                }
            }

            //ribbon group box
            var groupBox = ribbonTab.Groups.FirstOrDefault(g => g.Name.Equals(ribbonUiData.UiPosition.GroupBox.Name));

            if (groupBox == null)
            {
                groupBox = new RibbonGroupBoxContextUI()
                {
                    Name = ribbonUiData.UiPosition.GroupBox.Name
                };
                if (string.IsNullOrEmpty(ribbonUiData.UiPosition.GroupBox.LocalizedHeader))
                {
                    groupBox.Header = ribbonUiData.UiPosition.GroupBox.Name;
                }
                else
                {
                    groupBox.BindToLoc(RibbonGroupBox.HeaderProperty, ribbonUiData.UiPosition.GroupBox.LocalizedHeader);
                }

                ribbonTab.Groups.Add(groupBox);
            }
            return(groupBox);
        }
 public RibbonContextualTabGroupAutomationPeer(RibbonContextualTabGroup owner)
     : base(owner)
 {
 }