/// <summary> /// Creates a Component for the passed in display mode. /// </summary> /// <param name="displayMode">The display mode whose ControlComponent should be created.</param> /// <returns>The ControlComponent for the passed in display mode.</returns> public virtual ControlComponent CreateComponentForDisplayMode(string displayMode) { ControlComponent comp = CreateComponentForDisplayModeInternal(displayMode); Components.Add(comp); return(comp); }
internal override Component Clone(bool deep) { Section section = Ribbon.CreateSection("clonedSection-" + Ribbon.GetUniqueNumber(), Type, _alignment); if (!deep) { return(section); } int i = 0; foreach (Row row in Children) { foreach (object obj in row.Children) { Component clonedComp = null; if (obj is ControlComponent) { ControlComponent comp = (ControlComponent)obj; clonedComp = comp.Clone(deep); } else if (obj is Strip) { clonedComp = ((Strip)obj).Clone(deep); } section.GetRow(i + 1).AddChild(clonedComp); } i++; } return(section); }
private Strip CreateStripFromData(object data, DeclarativeTemplateBuildContext bc, Component parent, int rowComponentNumber) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); Strip strip = bc.Ribbon.CreateStrip(parent.Id + "-" + rowComponentNumber); for (int i = 0; i < children.Length; i++) { string name = DataNodeWrapper.GetNodeName(children[i]); if (name == DataNodeWrapper.CONTROL) { ControlComponent comp = CreateControlComponentFromData(children[i], bc); if (!CUIUtility.IsNullOrUndefined(comp)) { strip.AddChild(comp); } } else { HandleOverflow(children[i], bc, strip, i); } } // If there are no children in the strip then there is no reason to add it // If we ever support dynamically adding and removing components out of the ribbon // then this will need to be revisitited. if (strip.Children.Count == 0) { return(null); } return(strip); }
// 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); }
protected virtual ControlComponent CreateComponentForDisplayModeInternal(string displayMode) { ControlComponent comp = _root.CreateControlComponent( _id + "-" + displayMode + _root.GetUniqueNumber(), displayMode, this); return(comp); }
protected override void EnsureCorrectChildType(Component child) { if (!typeof(ControlComponent).IsInstanceOfType(child)) { throw new ArgumentException("Galleries can only have children controls of type GalleryButton"); } ControlComponent cc = (ControlComponent)child; if (!typeof(GalleryButton).IsInstanceOfType(cc.Control)) { throw new ArgumentException("Galleries can only have children of type GalleryButton"); } }
private ControlComponent CreateControlComponentFromData(object data, DeclarativeTemplateBuildContext bc) { string alias = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATEALIAS); string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); ControlComponent comp = null; List <Control> control = bc.Controls.ContainsKey(alias) ? bc.Controls[alias] : null; // If there is more than one control that is using the same TemplateAlias and the template // slot is a ControlRef, then the slot remains empty so that the problem can be detected and resolved. if (!CUIUtility.IsNullOrUndefined(control) && control.Count > 1) { comp = control[0].CreateComponentForDisplayMode(displayMode); } return(comp); }
private bool FocusInternal() { ControlComponent comp = this.DisplayedComponent; // We currently do not support this for non-menuitems. if (!typeof(MenuItem).IsInstanceOfType(comp)) { return(false); } // REVIEW(josefl): Consider moving knowledge about whether this is focused // or not into the Control. For now, we still get it from the MenuItem Component. if (!((MenuItem)comp).Focused) { ((IMenuItem)this).ReceiveFocus(); return(true); } return(false); }
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); } } } } }
/// <summary> /// Launch this MenuLauncher's Menu. /// </summary> /// <param name="evt">The DomEvent that triggered the launch(usually a mouse click)</param> protected bool LaunchMenu(HtmlElement elmHadFocus, Action onDelayedLoadSucceeded) { // If the menu is already launched, don't launch it twice // This happens when the menu is launched using the enter // key or the space bar since the browser sends two events: // one for the keypress and one for the associated click // when enter or space is pressed on an anchor element. if (MenuLaunched) { return(false); } _elmHadFocus = elmHadFocus; // If there is no Menu, then we check if this menu polls to get initialized. // If so, we poll for the menu XML, otherwise we exit. if (Utility.IsTrue(Properties.PopulateDynamically)) { PollForDynamicMenu(true, onDelayedLoadSucceeded); } // If there is no Menu to launch then we can't launch the Menu // This is not necessarily a bug. There is an asynchronous callback // available to create menus that are populated dynamically. This // is handled in PollForDynamicMenu() above. if (CUIUtility.IsNullOrUndefined(_menu)) { return(false); } // If we got this far and the member delayed load variable is not null, this was a delayed // load that succeeded, so we need to run the callback and clear the variable if (!CUIUtility.IsNullOrUndefined(_onDelayLoadSucceeded)) { _onDelayLoadSucceeded(); _onDelayLoadSucceeded = null; } _menu.EnsureRefreshed(); if (!_menu.HasItems()) { return(false); } ControlComponent comp = DisplayedComponent; comp.EnsureChildren(); comp.IgnoreDirtyingEvents = true; comp.AddChild(_menu); comp.IgnoreDirtyingEvents = false; _menu.PollIfRootPolledSinceLastPoll(); _menu.InvalidatePositionAndSizeData(); #if !CUI_NORIBBON // Adding the menu may cause window resize events which then immediately close the menu. // To fix this, we remove the onresize handler on Window until the menu is done launching. bool isInRibbon = Root is SPRibbon; SPRibbon ribbon = null; bool oldWindowResizedHandlerEnabled = false; if (isInRibbon) { ribbon = (SPRibbon)Root; oldWindowResizedHandlerEnabled = ribbon.WindowResizedHandlerEnabled; ribbon.WindowResizedHandlerEnabled = false; } #endif HtmlElement menuElement = _menu.ElementInternal; // Hide menu while positioning menuElement.Style.Visibility = "hidden"; menuElement.Style.Position = "absolute"; menuElement.Style.Top = "0px"; menuElement.Style.Left = "0px"; // Place menu directly on top of modal div (z-index:1000) menuElement.Style.ZIndex = 1001; // Add menu to DOM Browser.Document.Body.AppendChild(menuElement); if (BrowserUtility.InternetExplorer7 && Root.TextDirection == Direction.RTL) { int menuWidth = menuElement.OffsetWidth; // The menu items have 12px of padding, 2px of borders, and 2px of margins, // and the menu itself has 2px of borders too, so we need to remove that first menuWidth = menuWidth >= 18 ? menuWidth - 18 : 0; string strMenuWidth = menuWidth + "px"; List <Component> sections = _menu.Children; foreach (MenuSection section in sections) { List <Component> items = section.Children; foreach (Component c in items) { if (c is MenuItem) { c.ElementInternal.Style.Width = strMenuWidth; } } } } PositionMenu(menuElement, comp.ElementInternal); // For IE, we need a backframe IFrame in order for the menu to show up over // ActiveX controls if (BrowserUtility.InternetExplorer) { AddAndPositionBackFrame(); } // Show menu once it is positioned Root.BeginModal(this, _elmHadFocus); Root.AddMenuLauncherToStack(this); menuElement.Style.Visibility = "visible"; _menuLaunched = true; _menu.Launched = true; FocusOnAppropriateMenuItem(null); #if !CUI_NORIBBON if (isInRibbon) { ribbon.WindowResizedHandlerEnabled = oldWindowResizedHandlerEnabled; } #endif return(true); }
/// <summary> /// Launch this Control's ToolTip. /// </summary> /// <owner alias="HillaryM" /> protected void LaunchToolTip() { if (CUIUtility.IsNullOrUndefined(Root)) { return; } // clear the tooltip launching timer Browser.Window.ClearInterval(Root.TooltipLauncherTimer); // If the tooltip is already launched, don't launch it twice if (_toolTipLaunched) { return; } // if there is currently an open tooltip and it was not launched by this control, close it if ((!CUIUtility.IsNullOrUndefined(Root.TooltipLauncher)) && (Root.TooltipLauncher.Id != this.Id)) { Root.CloseOpenTootips(); } // If there is no ToolTip title, we don't launch the ToolTip if (string.IsNullOrEmpty(_properties.ToolTipTitle)) { return; } _toolTip = new ToolTip(Root, Id + "_ToolTip", _properties.ToolTipTitle, _properties.ToolTipDescription, _properties); if (!Enabled) { // Show message indicating that the control is disabled and give reason. DisabledCommandInfoProperties disabledInfo = new DisabledCommandInfoProperties(); disabledInfo.Icon = Root.Properties.ToolTipDisabledCommandImage16by16; disabledInfo.IconClass = Root.Properties.ToolTipDisabledCommandImage16by16Class; disabledInfo.IconTop = Root.Properties.ToolTipDisabledCommandImage16by16Top; disabledInfo.IconLeft = Root.Properties.ToolTipDisabledCommandImage16by16Left; disabledInfo.Title = Root.Properties.ToolTipDisabledCommandTitle; disabledInfo.Description = Root.Properties.ToolTipDisabledCommandDescription; disabledInfo.HelpKeyWord = Root.Properties.ToolTipDisabledCommandHelpKey; _toolTip.DisabledCommandInfo = disabledInfo; } ControlComponent comp = DisplayedComponent; if (!CUIUtility.IsNullOrUndefined(comp)) { comp.EnsureChildren(); comp.AddChild(_toolTip); _toolTip.Display(); _toolTipLaunched = true; Root.TooltipLauncher = this; OnToolTipOpenned(); } else { _toolTip = null; } }