/// <summary> /// Add the spacing views into the indexed docker. /// </summary> /// <param name="i">Index of docker.</param> /// <param name="spacerL">Spacer for the left side.</param> /// <param name="spacerR">Spacer for the right side.</param> protected override void AddSpacersToDocker(int i, ViewLayoutMetricSpacer spacerL, ViewLayoutMetricSpacer spacerR) { // Get the indexed instance ViewLayoutDocker viewDocker = _viewDockers[i]; // Add them into the view docker instance viewDocker.Add(spacerL, ViewDockStyle.Left); viewDocker.Add(spacerR, ViewDockStyle.Right); }
/// <summary> /// Initialize a new instance of the ViewLayoutMenuItemsPile class. /// </summary> /// <param name="provider">Provider of context menu values.</param> /// <param name="items">Reference to the owning collection.</param> /// <param name="standardStyle">Draw items with standard or alternate style.</param> /// <param name="imageColumn">Draw an image background for the item images.</param> public ViewLayoutMenuItemsPile(IContextMenuProvider provider, KryptonContextMenuItems items, bool standardStyle, bool imageColumn) { // Cache access to the highlight item palette _paletteItemHighlight = provider.ProviderStateCommon.ItemHighlight; // Create and place an image column inside a docker so it appears on the left side _imageColumn = new ViewDrawMenuImageColumn(items, provider.ProviderStateCommon.ItemImageColumn); ViewLayoutDocker imageDocker = new ViewLayoutDocker { { _imageColumn, ViewDockStyle.Left } }; // Only show the image column when in a standard collection of items imageDocker.Visible = imageColumn; // Create a vertical stack that contains each individual menu item ItemStack = new ViewLayoutStack(false) { FillLastChild = false }; // Use a docker with the item stack as the fill ViewLayoutDocker stackDocker = new ViewLayoutDocker { { ItemStack, ViewDockStyle.Fill } }; // Grab the padding for around the item stack Padding itemsPadding = _paletteItemHighlight.GetMetricPadding(PaletteState.Normal, PaletteMetricPadding.ContextMenuItemsCollection); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Left), ViewDockStyle.Left); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Right), ViewDockStyle.Right); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Top), ViewDockStyle.Top); stackDocker.Add(new ViewLayoutSeparator(itemsPadding.Bottom), ViewDockStyle.Bottom); // The background of the pile is the image column Add(imageDocker); // The foreground of the pile is the stack of menu items Add(stackDocker); }
/// <summary> /// Returns a view appropriate for this item based on the object it is inside. /// </summary> /// <param name="provider">Provider of context menu information.</param> /// <param name="parent">Owning object reference.</param> /// <param name="columns">Containing columns.</param> /// <param name="standardStyle">Draw items with standard or alternate style.</param> /// <param name="imageColumn">Draw an image background for the item images.</param> /// <returns>ViewBase that is the root of the view hierachy being added.</returns> public override ViewBase GenerateView(IContextMenuProvider provider, object parent, ViewLayoutStack columns, bool standardStyle, bool imageColumn) { if (Horizontal && (parent is KryptonContextMenuItemCollection)) { // Create a stack of horizontal items inside the item ViewLayoutDocker docker = new ViewLayoutDocker(); // Take up same space as the image column, so separator starts close to actual text ViewDrawContent imageContent = new ViewDrawContent(provider.ProviderStateCommon.ItemImage.Content, new FixedContentValue(null, null, null, Color.Empty), VisualOrientation.Top); ViewDrawMenuImageCanvas imageCanvas = new ViewDrawMenuImageCanvas(provider.ProviderStateCommon.ItemImage.Back, provider.ProviderStateCommon.ItemImage.Border, 0, true) { imageContent }; docker.Add(new ViewLayoutCenter(imageCanvas), ViewDockStyle.Left); docker.Add(new ViewLayoutSeparator(1, 0), ViewDockStyle.Left); // Gap that matches left padding of text/extra text docker.Add(new ViewLayoutMenuSepGap(provider.ProviderStateCommon, standardStyle), ViewDockStyle.Left); // Separator Display ViewLayoutStack separatorStack = new ViewLayoutStack(false) { new ViewLayoutSeparator(1, 1), new ViewDrawMenuSeparator(this, provider.ProviderStateCommon.Separator), new ViewLayoutSeparator(1, 1) }; docker.Add(separatorStack, ViewDockStyle.Fill); return(docker); } else { return(new ViewDrawMenuSeparator(this, provider.ProviderStateCommon.Separator)); } }
/// <summary> /// Initialize a new instance of the ViewDrawMenuItem class. /// </summary> /// <param name="provider">Provider of context menu information.</param> /// <param name="menuItem">Menu item definition.</param> /// <param name="columns">Containing columns.</param> /// <param name="standardStyle">Draw items with standard or alternate style.</param> /// <param name="imageColumn">Draw an image background for the item images.</param> public ViewDrawMenuItem(IContextMenuProvider provider, KryptonContextMenuItem menuItem, ViewLayoutStack columns, bool standardStyle, bool imageColumn) : base(menuItem.StateNormal.ItemHighlight.Back, menuItem.StateNormal.ItemHighlight.Border, menuItem.StateNormal.ItemHighlight, PaletteMetricPadding.ContextMenuItemHighlight, VisualOrientation.Top) { // Remember values _provider = provider; KryptonContextMenuItem = menuItem; _imageColumn = imageColumn; _standardStyle = standardStyle; // Give the item object the redirector to use when inheriting values KryptonContextMenuItem.SetPaletteRedirect(provider); // Create a stack of horizontal items inside the item ViewLayoutDocker docker = new ViewLayoutDocker(); // Decide on the enabled state of the display ItemEnabled = provider.ProviderEnabled && ResolveEnabled; PaletteContextMenuItemState menuItemState = (ItemEnabled ? KryptonContextMenuItem.StateNormal : KryptonContextMenuItem.StateDisabled); // Calculate the image to show inside in the image column Image itemColumnImage = ResolveImage; Color itemImageTransparent = ResolveImageTransparentColor; // If no image found then... if (itemColumnImage != null) { // Ensure we have a fixed size if we are showing an image column if (_imageColumn) { itemColumnImage = _empty16x16; itemImageTransparent = Color.Magenta; } switch (ResolveCheckState) { case CheckState.Checked: itemColumnImage = provider.ProviderImages.GetContextMenuCheckedImage(); itemImageTransparent = Color.Empty; break; case CheckState.Indeterminate: itemColumnImage = provider.ProviderImages.GetContextMenuIndeterminateImage(); itemImageTransparent = Color.Empty; break; } } // Column Image PaletteTripleJustImage justImage = (ResolveChecked ? KryptonContextMenuItem.StateChecked.ItemImage : menuItemState.ItemImage); _fixedImage = new FixedContentValue(null, null, itemColumnImage, itemImageTransparent); _imageContent = new ViewDrawContent(justImage.Content, _fixedImage, VisualOrientation.Top); _imageCanvas = new ViewDrawMenuImageCanvas(justImage.Back, justImage.Border, 0, false) { _imageContent }; docker.Add(new ViewLayoutCenter(_imageCanvas), ViewDockStyle.Left); _imageContent.Enabled = ItemEnabled; // Text/Extra Text PaletteContentJustText menuItemStyle = (standardStyle ? menuItemState.ItemTextStandard : menuItemState.ItemTextAlternate); _fixedTextExtraText = new FixedContentValue(ResolveText, ResolveExtraText, null, Color.Empty); _textContent = new ViewDrawMenuItemContent(menuItemStyle, _fixedTextExtraText, 1); docker.Add(_textContent, ViewDockStyle.Fill); _textContent.Enabled = ItemEnabled; // Shortcut if (KryptonContextMenuItem.ShowShortcutKeys) { string shortcutString = KryptonContextMenuItem.ShortcutKeyDisplayString; if (string.IsNullOrEmpty(shortcutString)) { shortcutString = (KryptonContextMenuItem.ShortcutKeys != Keys.None) ? new KeysConverter().ConvertToString(KryptonContextMenuItem.ShortcutKeys) : string.Empty; } if (shortcutString.Length > 0) { _shortcutContent = new ViewDrawMenuItemContent(menuItemState.ItemShortcutText, new FixedContentValue(shortcutString, null, null, Color.Empty), 2); docker.Add(_shortcutContent, ViewDockStyle.Right); _shortcutContent.Enabled = ItemEnabled; } } // Add split item separator SplitSeparator = new ViewDrawMenuSeparator(menuItemState.ItemSplit); docker.Add(SplitSeparator, ViewDockStyle.Right); SplitSeparator.Enabled = ItemEnabled; SplitSeparator.Draw = (KryptonContextMenuItem.Items.Count > 0) && KryptonContextMenuItem.SplitSubMenu; // SubMenu Indicator HasSubMenu = (KryptonContextMenuItem.Items.Count > 0); _subMenuContent = new ViewDrawMenuItemContent(menuItemState.ItemImage.Content, new FixedContentValue(null, null, (!HasSubMenu ? _empty16x16 : provider.ProviderImages.GetContextMenuSubMenuImage()), (KryptonContextMenuItem.Items.Count == 0 ? Color.Magenta : Color.Empty)), 3); docker.Add(new ViewLayoutCenter(_subMenuContent), ViewDockStyle.Right); _subMenuContent.Enabled = ItemEnabled; Add(docker); // Add a controller for handing mouse and keyboard events MenuItemController mic = new MenuItemController(provider.ProviderViewManager, this, provider.ProviderNeedPaintDelegate); MouseController = mic; KeyController = mic; // Want to know when a property changes whilst displayed KryptonContextMenuItem.PropertyChanged += OnPropertyChanged; // We need to know if a property of the command changes if (KryptonContextMenuItem.KryptonCommand != null) { _cachedCommand = KryptonContextMenuItem.KryptonCommand; KryptonContextMenuItem.KryptonCommand.PropertyChanged += OnCommandPropertyChanged; } }