// Iterate recursively through the subtree of child components until either // a match is found or the end of the subtree is reached private ISelectableControl GetItemByIdInternal(Component comp, string id) { ISelectableControl tmp; if (comp is ControlComponent) { ControlComponent concomp = (ControlComponent)comp; if (concomp.Control is ISelectableControl) { ISelectableControl isc = (ISelectableControl)concomp.Control; if (isc.GetMenuItemId() == id) { return(isc); } } } List <Component> children = comp.Children; if (!CUIUtility.IsNullOrUndefined(children)) { foreach (Component c in children) { tmp = GetItemByIdInternal(c, id); if (tmp != null) { return(tmp); } } } return(null); }
public override void Dispose() { base.Dispose(); if (!CUIUtility.IsNullOrUndefined(_menu)) { _menu.Dispose(); } if (!CUIUtility.IsNullOrUndefined(_cachedMenuVersions)) { // This may have gotten called before if this is the current menu that we are // holding but it won't hurt to call it twice. foreach (string key in _cachedMenuVersions.Keys) { _cachedMenuVersions[key].Dispose(); } _cachedMenuVersions.Clear(); _cachedMenuVersions = null; } _selectedControl = null; _menu = null; _elmBackFrame = null; }
internal override bool OnPreBubbleCommand(CommandEventArgs command) { // A command has been issued from a component somewhere under this // DropDown. We want to determine if it is a option select command. // This would let us know that we need to do some processing so that // the anchor has the appropriate value in it etc. if (command.Type == CommandType.OptionSelection) { MenuItem item = (MenuItem)command.Source; if (!(item.Control is ISelectableControl)) { return(base.OnPreBubbleCommand(command)); } ISelectableControl isc = (ISelectableControl)item.Control; // If an item is currently selected, deselect it first if (!CUIUtility.IsNullOrUndefined(_selectedControl)) { _selectedControl.Deselect(); } SelectMenuItem(isc); } if (command.Type == CommandType.OptionSelection || command.Type == CommandType.OptionPreview || command.Type == CommandType.OptionPreviewRevert) { string myCommand; switch (command.Type) { case CommandType.OptionSelection: myCommand = Properties.Command; break; case CommandType.OptionPreview: myCommand = Properties.CommandPreview; break; case CommandType.OptionPreviewRevert: myCommand = Properties.CommandRevert; break; default: // This case should not be hit, but it allows compilation myCommand = Properties.Command; break; } // Stop the command here and send our own DisplayedComponent.RaiseCommandEvent(myCommand, command.Type, command.Parameters); base.OnPreBubbleCommand(command); return(false); } // if any other command type return(base.OnPreBubbleCommand(command)); }
void Initialize(ISelectableControl <object> parent) { Parent = parent; Parent.SelectedItemsChanged += HandleSelectionChanged; Change = () => new SelectionPreserverHelper { Collection = this, Preserver = Parent.SelectionPreserver }; }
protected override void OnDynamicMenuPopulated() { // If we are dynamically populating the menu, we should build the lookup // table for autocomplete now ControlComponent cc = null; Control c = null; ISelectableControl isc = null; IMenuItem imi = null; string menuitemid = ""; string labeltext = ""; if (CUIUtility.IsNullOrUndefined(Menu)) { return; } foreach (MenuSection ms in Menu.Children) { foreach (Component comp in ms.Children) { // Only check if this is a MenuItem // Ignore Galleries and GroupPopouts if (comp is MenuItem) { cc = (ControlComponent)comp; c = cc.Control; // Get MenuItemId if (c is ISelectableControl) { isc = (ISelectableControl)c; menuitemid = isc.GetMenuItemId(); } // Get Label Text if (c is IMenuItem) { imi = (IMenuItem)c; labeltext = imi.GetTextValue(); } // If we have both MenuItemId and Label Text, add the item to the table if (!(string.IsNullOrEmpty(menuitemid) || string.IsNullOrEmpty(labeltext))) { MenuItems[labeltext] = menuitemid; labeltext = ""; menuitemid = ""; } } } } }
protected override void SelectMenuItem(ISelectableControl isc) { if (_selectedControl == isc) { return; } _selectedControl = isc; StateProperties[ComboBoxCommandProperties.SelectedItemId] = isc.GetMenuItemId(); IMenuItem imi = (IMenuItem)(Control)isc; _elmMediumInput.Value = imi.GetTextValue(); }
internal override bool FocusOnItemById(string menuItemId) { if (Control is ISelectableControl) { ISelectableControl isc = (ISelectableControl)Control; if (isc.GetMenuItemId() == menuItemId) { if (Visible && Enabled) { ReceiveFocus(); Focused = true; return(true); } } } return(false); }
protected virtual void SelectMenuItem(ISelectableControl isc) { if (_selectedControl == isc) // same menu item selected { return; } _selectedControl = isc; StateProperties[DropDownCommandProperties.SelectedItemId] = isc.GetMenuItemId(); // If SelectedItemDisplayMode is not set, Medium to "Text" string selectedItemDisplayMode; if (string.IsNullOrEmpty(Properties.SelectedItemDisplayMode)) { selectedItemDisplayMode = "Text"; } else { selectedItemDisplayMode = Properties.SelectedItemDisplayMode; } Anchor selectedItem; if (selectedItemDisplayMode == "Text") { string text = isc.GetTextValue(); selectedItem = new Anchor(); UIUtility.SetInnerText(selectedItem, text); } else { selectedItem = (Anchor)_selectedControl.GetDropDownDOMElementForDisplayMode(selectedItemDisplayMode); } if (_elmMediumSelectedItem.HasChildNodes()) { Anchor oldSelectedItem = (Anchor)_elmMediumSelectedItem.FirstChild; _elmMediumSelectedItem.ReplaceChild(selectedItem, oldSelectedItem); } else { _elmMediumSelectedItem.AppendChild(selectedItem); } }
internal bool SelectMenuItemById(string menuItemId) { // We must have a MenuItemId and a Menu in order to select an item // The Menu can be null if this control's menu gets populated dynamically if (string.IsNullOrEmpty(menuItemId) || CUIUtility.IsNullOrUndefined(Menu)) { return(false); } ISelectableControl isc = Menu.GetItemById(menuItemId); if (CUIUtility.IsNullOrUndefined(isc)) { return(false); } SelectMenuItem(isc); _itemEverSelected = true; return(true); }
public void DeselectAllControlsExcept(ISelectableControl control) { foreach (var c in Controls) { if (c != control) { var dropableControl = c as DropableControl; if (dropableControl != null) { dropableControl.DeselectControl(); } var line = c as Line; if (line != null && line.ContainedByConnector != control) { line.Deselect(); } } } }
private void FocusOnAppropriateMenuItem(HtmlEvent evt) { if (CUIUtility.IsNullOrUndefined(_menu.SelectedMenuItem) && !CUIUtility.IsNullOrUndefined(_selectedControl)) { Control ctl = (Control)_selectedControl; ControlComponent dispComp = ctl.DisplayedComponent; if (dispComp is MenuItem) { _menu.SelectedMenuItem = (MenuItem)dispComp; } } // Let focus remain on triggering element if using jaws // LaunchedByKeyboard true for onkeydown, not jaws onclick if (LaunchedByKeyboard) { _menu.FocusOnFirstItem(evt); } else { // If nothing has been selected before then we auto-select the first item in some cases MenuItem selectedItem = _menu.SelectedMenuItem; if (!CUIUtility.IsNullOrUndefined(selectedItem)) { // This auto selection only happens for ToggleButtons in DropDowns where one of the // menu items represents the "currently selected item" in the DropDown. // Currently selected font in a font dropdown for example. Control selectedItemControl = selectedItem.Control; if (selectedItemControl is ToggleButton && selectedItemControl is ISelectableControl) { ISelectableControl isc = (ISelectableControl)selectedItemControl; if (!_menu.FocusOnItemById(isc.GetMenuItemId())) { _menu.FocusOnFirstItem(evt); } } } } }
public void DeselectAllControlsExcept(ISelectableControl control) { foreach (var c in Controls) { if (c != control) { var dropableControl = c as DropableControl; if (dropableControl != null) { dropableControl.DeselectControl(); } } } foreach (var c in Connectors) { if (c != control) { c.DeselectControl(); } } }
public override void OnBeginFocus() { string dictKey = DropDownCommandProperties.Value; string selectedItemTitle = StateProperties.ContainsKey(dictKey) ? StateProperties[dictKey] : ""; if (string.IsNullOrEmpty(selectedItemTitle)) { // get currently selected item ID string itemKey = DropDownCommandProperties.SelectedItemId; string currentSelectedItemId = StateProperties.ContainsKey(itemKey) ? StateProperties[itemKey] : ""; // If we currently don't have an item set, then we set it here to let the application know // since this is what we'll fall back to unless they set something else. if (string.IsNullOrEmpty(currentSelectedItemId)) { currentSelectedItemId = Properties.InitialItem; } // get the title of the selected item // The Menu can be null if this control's menu gets populated dynamically if ((!string.IsNullOrEmpty(currentSelectedItemId)) && (!CUIUtility.IsNullOrUndefined(Menu))) { ISelectableControl isc = Menu.GetItemById(currentSelectedItemId); if (!CUIUtility.IsNullOrUndefined(isc)) { selectedItemTitle = isc.GetTextValue(); } } } if (!string.IsNullOrEmpty(selectedItemTitle)) { Properties.ToolTipSelectedItemTitle = selectedItemTitle; } base.OnBeginFocus(); }
protected virtual void SelectMenuItem(ISelectableControl isc) { if (_selectedControl == isc) // same menu item selected return; _selectedControl = isc; StateProperties[DropDownCommandProperties.SelectedItemId] = isc.GetMenuItemId(); // If SelectedItemDisplayMode is not set, Medium to "Text" string selectedItemDisplayMode; if (string.IsNullOrEmpty(Properties.SelectedItemDisplayMode)) selectedItemDisplayMode = "Text"; else selectedItemDisplayMode = Properties.SelectedItemDisplayMode; Anchor selectedItem; if (selectedItemDisplayMode == "Text") { string text = isc.GetTextValue(); selectedItem = new Anchor(); UIUtility.SetInnerText(selectedItem, text); } else selectedItem = (Anchor)_selectedControl.GetDropDownDOMElementForDisplayMode(selectedItemDisplayMode); if (_elmMediumSelectedItem.HasChildNodes()) { Anchor oldSelectedItem = (Anchor)_elmMediumSelectedItem.FirstChild; _elmMediumSelectedItem.ReplaceChild(selectedItem, oldSelectedItem); } else _elmMediumSelectedItem.AppendChild(selectedItem); }
internal override bool OnPreBubbleCommand(CommandEventArgs command) { // If we have already processed the command and issued our own instead, // then we do not want to infinitely recurse by issueing another one. if (_processingCommand) return true; if (command.Type == CommandType.OptionSelection) { MenuItem item = (MenuItem)command.Source; if (!(item.Control is ISelectableControl)) return base.OnPreBubbleCommand(command); ISelectableControl isc = (ISelectableControl)item.Control; // If an item is currently selected, deselect it first if (!CUIUtility.IsNullOrUndefined(_selectedItem)) _selectedItem.Deselect(); _selectedItem = isc; } if (command.Type == CommandType.OptionSelection || command.Type == CommandType.OptionPreview || command.Type == CommandType.OptionPreviewRevert) { string myCommand; switch (command.Type) { case CommandType.OptionSelection: myCommand = Properties.Command; break; case CommandType.OptionPreview: myCommand = Properties.CommandPreview; break; case CommandType.OptionPreviewRevert: myCommand = Properties.CommandRevert; break; default: // This case should not be hit, but it allows compilation myCommand = Properties.Command; break; } // Keep track of the fact that we have already processed the command // so that we will not infinitely recurse. _processingCommand = true; // Stop the command here and send our own RaiseCommandEvent(myCommand, command.Type, command.Parameters); _processingCommand = false; base.OnPreBubbleCommand(command); return false; } return base.OnPreBubbleCommand(command); }
protected override void SelectMenuItem(ISelectableControl isc) { // Same item selected and we are not in the middle of building a DOM element // In this case we need to construct the selected item DOM element for this new display mode. if (_selectedControl == isc && !_buildingDOMElement) { return; } // We either get the current display mode of this control through what is presently // shown in the ribbon. If not, then we are creating it and just setting the initially shown // item. In this case, we want to set the menu item to the one that we are currently creating. string displayMode = !CUIUtility.IsNullOrUndefined(DisplayedComponent) ? DisplayedComponent.Title : CurrentlyCreatedDisplayMode; Span itemContainer; switch (displayMode) { case "Large": itemContainer = _elmLargeSelectedItem; break; case "Medium": itemContainer = _elmMediumSelectedItem; break; case "Small": itemContainer = _elmSmallSelectedItem; break; default: throw new ArgumentOutOfRangeException("Invalid display mode on split button while selecting a menu item"); } _selectedControl = isc; StateProperties[DropDownCommandProperties.SelectedItemId] = isc.GetMenuItemId(); Control iscControl = (Control)isc; if (iscControl.DisplayedComponent is MenuItem) { Menu.SelectedMenuItem = (MenuItem)iscControl.DisplayedComponent; } Span selectedItem = (Span)_selectedControl.GetDropDownDOMElementForDisplayMode(displayMode); // The drop down element should not have a <BR> in it because it is // used in an MRUSplitButton and there is only room for one line of text. if (selectedItem.ChildNodes.Length > 1) { HtmlElement elm = (HtmlElement)selectedItem.ChildNodes[1]; if (elm.ChildNodes.Length > 1) { if (((HtmlElement)elm.ChildNodes[1]).TagName.ToLower() == "br") { Span elmText = new Span(); UIUtility.SetInnerText(elmText, " "); elm.ReplaceChild(elmText, elm.ChildNodes[1]); } } } // Set the ID to null since this DOM element is now hosted in this MRUSplitButton. selectedItem.Id = Id + "-SelectedItem"; if (itemContainer.HasChildNodes()) { HtmlElement oldSelectedItem = (HtmlElement)itemContainer.FirstChild; itemContainer.ReplaceChild(selectedItem, oldSelectedItem); } else { itemContainer.AppendChild(selectedItem); } selectedItem.Click += OnSelectedItemClick; selectedItem.DblClick += OnDblClick; }
public override void Dispose() { base.Dispose(); if (!CUIUtility.IsNullOrUndefined(_menu)) _menu.Dispose(); if (!CUIUtility.IsNullOrUndefined(_cachedMenuVersions)) { // This may have gotten called before if this is the current menu that we are // holding but it won't hurt to call it twice. foreach (string key in _cachedMenuVersions.Keys) _cachedMenuVersions[key].Dispose(); _cachedMenuVersions.Clear(); _cachedMenuVersions = null; } _selectedControl = null; _menu = null; _elmBackFrame = null; }
protected override void SelectMenuItem(ISelectableControl isc) { // Same item selected and we are not in the middle of building a DOM element // In this case we need to construct the selected item DOM element for this new display mode. if (_selectedControl == isc && !_buildingDOMElement) return; // We either get the current display mode of this control through what is presently // shown in the ribbon. If not, then we are creating it and just setting the initially shown // item. In this case, we want to set the menu item to the one that we are currently creating. string displayMode = !CUIUtility.IsNullOrUndefined(DisplayedComponent) ? DisplayedComponent.Title : CurrentlyCreatedDisplayMode; Span itemContainer; switch (displayMode) { case "Large": itemContainer = _elmLargeSelectedItem; break; case "Medium": itemContainer = _elmMediumSelectedItem; break; case "Small": itemContainer = _elmSmallSelectedItem; break; default: throw new ArgumentOutOfRangeException("Invalid display mode on split button while selecting a menu item"); } _selectedControl = isc; StateProperties[DropDownCommandProperties.SelectedItemId] = isc.GetMenuItemId(); Control iscControl = (Control)isc; if (iscControl.DisplayedComponent is MenuItem) Menu.SelectedMenuItem = (MenuItem)iscControl.DisplayedComponent; Span selectedItem = (Span)_selectedControl.GetDropDownDOMElementForDisplayMode(displayMode); // The drop down element should not have a <BR> in it because it is // used in an MRUSplitButton and there is only room for one line of text. if (selectedItem.ChildNodes.Length > 1) { HtmlElement elm = (HtmlElement)selectedItem.ChildNodes[1]; if (elm.ChildNodes.Length > 1) { if (((HtmlElement)elm.ChildNodes[1]).TagName.ToLower() == "br") { Span elmText = new Span(); UIUtility.SetInnerText(elmText, " "); elm.ReplaceChild(elmText, elm.ChildNodes[1]); } } } // Set the ID to null since this DOM element is now hosted in this MRUSplitButton. selectedItem.Id = Id + "-SelectedItem"; if (itemContainer.HasChildNodes()) { HtmlElement oldSelectedItem = (HtmlElement)itemContainer.FirstChild; itemContainer.ReplaceChild(selectedItem, oldSelectedItem); } else itemContainer.AppendChild(selectedItem); selectedItem.Click += OnSelectedItemClick; selectedItem.DblClick += OnDblClick; }
protected override void SelectMenuItem(ISelectableControl isc) { if (_selectedControl == isc) return; _selectedControl = isc; StateProperties[ComboBoxCommandProperties.SelectedItemId] = isc.GetMenuItemId(); IMenuItem imi = (IMenuItem)(Control)isc; _elmMediumInput.Value = imi.GetTextValue(); }
internal override bool OnPreBubbleCommand(CommandEventArgs command) { // If we have already processed the command and issued our own instead, // then we do not want to infinitely recurse by issueing another one. if (_processingCommand) { return(true); } if (command.Type == CommandType.OptionSelection) { MenuItem item = (MenuItem)command.Source; if (!(item.Control is ISelectableControl)) { return(base.OnPreBubbleCommand(command)); } ISelectableControl isc = (ISelectableControl)item.Control; // If an item is currently selected, deselect it first if (!CUIUtility.IsNullOrUndefined(_selectedItem)) { _selectedItem.Deselect(); } _selectedItem = isc; } if (command.Type == CommandType.OptionSelection || command.Type == CommandType.OptionPreview || command.Type == CommandType.OptionPreviewRevert) { string myCommand; switch (command.Type) { case CommandType.OptionSelection: myCommand = Properties.Command; break; case CommandType.OptionPreview: myCommand = Properties.CommandPreview; break; case CommandType.OptionPreviewRevert: myCommand = Properties.CommandRevert; break; default: // This case should not be hit, but it allows compilation myCommand = Properties.Command; break; } // Keep track of the fact that we have already processed the command // so that we will not infinitely recurse. _processingCommand = true; // Stop the command here and send our own RaiseCommandEvent(myCommand, command.Type, command.Parameters); _processingCommand = false; base.OnPreBubbleCommand(command); return(false); } return(base.OnPreBubbleCommand(command)); }
/// <summary> /// Initializes a new instance of the <see cref="Eto.Forms.SelectableFilterCollection{T}"/> class. /// </summary> /// <param name="parent">Parent to attach this instance to.</param> /// <param name="collection">Collection for the source of this collection.</param> public SelectableFilterCollection(ISelectableControl <object> parent, IEnumerable <T> collection) : base(collection) { Initialize(parent); }
/// <summary> /// Initializes a new instance of the <see cref="Eto.Forms.SelectableFilterCollection{T}"/> class. /// </summary> /// <param name="parent">Parent to attach this instance to.</param> public SelectableFilterCollection(ISelectableControl <object> parent) { Initialize(parent); }