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); }
private void HandleRow(Row row, JSObject data, DeclarativeTemplateBuildContext bc) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); for (int i = 0; i < children.Length; i++) { string name = DataNodeWrapper.GetNodeName(children[i]); Component comp = null; if (name == DataNodeWrapper.CONTROL) { comp = CreateControlComponentFromData(children[i], bc); } else if (name == DataNodeWrapper.OVERFLOWAREA) { HandleOverflow(children[i], bc, row, i); } else { comp = CreateStripFromData(children[i], bc, row, i); } if (!CUIUtility.IsNullOrUndefined(comp)) { row.AddChild(comp); } } }
private MenuSection BuildMenuSection(JSObject data, BuildContext bc) { string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); if (CUIUtility.IsNullOrUndefined(displayMode)) { displayMode = "Menu"; } string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); bool scrollable = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.SCROLLABLE)); string maxheight = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.MAXHEIGHT); MenuSection ms = Root.CreateMenuSection(id, title, description, scrollable, maxheight, displayMode); JSObject[] menuSectionChildren = DataNodeWrapper.GetNodeChildren(data); JSObject msChild = menuSectionChildren[0]; string msChildName = DataNodeWrapper.GetNodeName(msChild); if (msChildName == DataNodeWrapper.CONTROLS) { // Get the <MenuSection><Controls> node's children JSObject[] individualControls = DataNodeWrapper.GetNodeChildren(msChild); int l = individualControls.Length; JSObject child = null; for (int i = 0; i < l; i++) { child = individualControls[i]; if (IsNodeTrimmed(child)) { continue; } Control control = BuildControl(child, bc); ms.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } else if (msChildName == DataNodeWrapper.GALLERY) { Gallery gallery = BuildGallery(msChild, bc, true); ms.AddChild(gallery); } return(ms); }
/// <summary> /// The toolbar doesn't require scaling code -- it just builds with a static set of display modes, /// since it only supports one display mode per control type. /// </summary> private Component BuildToolbarControlComponent(object data, ToolbarBuildContext buildContext) { Control control = null; string name = DataNodeWrapper.GetNodeName(data); string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); switch (name) { case DataNodeWrapper.Button: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.CheckBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.ComboBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode("Medium")); case DataNodeWrapper.FlyoutAnchor: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Medium" : displayMode)); case DataNodeWrapper.Label: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); case DataNodeWrapper.Separator: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode("Small")); case DataNodeWrapper.TextBox: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Medium" : displayMode)); case DataNodeWrapper.ToggleButton: control = BuildControl(data, buildContext); return(control.CreateComponentForDisplayMode( string.IsNullOrEmpty(displayMode) ? "Small" : displayMode)); default: throw new InvalidOperationException("Invalid control type."); } }
public static JSObject GetFirstChildNodeWithName(object data, string name) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int l = children.Length; for (int i = 0; i < l; i++) { JSObject child = children[i]; string nm = DataNodeWrapper.GetNodeName(child); if (nm == name) { return(child); } } return(null); }
private Gallery BuildGallery(object data, BuildContext bc, bool isInMenu) { JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); GalleryProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <GalleryProperties>(); Gallery gallery = Root.CreateGallery(properties.Id, DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.TITLE), DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.DESCRIPTION), properties); string displayMode = isInMenu ? "Menu" : "Default"; JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int l = children.Length; for (int i = 0; i < l; i++) { JSObject child = children[i]; if (IsNodeTrimmed(child)) { continue; } // NOTE: currently, galleries can only host GalleryButton controls. // In the future, the gallery could support other control types, so those should be added here. Control control; switch (DataNodeWrapper.GetNodeName(child)) { case DataNodeWrapper.GalleryButton: control = BuildGalleryButton(child, bc, properties.ElementDimensions); break; default: control = BuildControl(child, bc); break; } gallery.AddChild(control.CreateComponentForDisplayMode(displayMode)); } return(gallery); }
internal void FillLayout(object data, Layout layout, DeclarativeTemplateBuildContext bc) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int sectionCounter = 0; for (int i = 0; i < children.Length; i++) { string name = DataNodeWrapper.GetNodeName(children[i]); if (name == DataNodeWrapper.SECTION) { Section section = CreateSectionFromData(children[i], bc, layout, sectionCounter++); layout.AddChild(section); } else { // This must be an <OverflowSection> sectionCounter = HandleOverflow(children[i], bc, layout, sectionCounter); } } }
private void FillMenu(Menu menu, JSObject data, BuildContext bc) { JSObject[] children = DataNodeWrapper.GetNodeChildren(data); int l = children.Length; for (int i = 0; i < l; i++) { JSObject child = children[i]; string name = DataNodeWrapper.GetNodeName(child); if (name != DataNodeWrapper.MENUSECTION) { throw new InvalidOperationException("Tags with the name: " + name + " cannot be children of Menu tags."); } // Skip over menu sections that have been trimmed if (IsNodeTrimmed(child)) { continue; } MenuSection ms = BuildMenuSection(child, bc); menu.AddChild(ms); } }
private Group BuildGroup(object data, RibbonBuildContext rbc) { string templateName = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATE); Template template = TemplateManager.Instance.GetTemplate(templateName); if (CUIUtility.IsNullOrUndefined(template)) { throw new ArgumentOutOfRangeException("A template with name: " + templateName + " could not be loaded."); } JSObject controlsData = null; JSObject[] dataChildren = DataNodeWrapper.GetNodeChildren(data); for (int i = 0; i < dataChildren.Length; i++) { if (DataNodeWrapper.GetNodeName(dataChildren[i]) == DataNodeWrapper.CONTROLS) { controlsData = dataChildren[i]; break; } } if (CUIUtility.IsNullOrUndefined(controlsData)) { throw new InvalidOperationException("No Controls node found in this Group tag."); } JSObject[] children = DataNodeWrapper.GetNodeChildren(controlsData); bool groupIsEmpty = true; Dictionary <string, List <Control> > controls = new Dictionary <string, List <Control> >(); int len = children.Length; for (int i = 0; i < len; i++) { // Don't build controls that have been trimmed if (IsNodeTrimmed(children[i])) { continue; } // The group has one or more controls in it groupIsEmpty = false; Control control = BuildControl(children[i], rbc); if (!controls.ContainsKey(control.TemplateAlias) || CUIUtility.IsNullOrUndefined(controls[control.TemplateAlias])) { controls[control.TemplateAlias] = new List <Control>(); } controls[control.TemplateAlias].Add(control); } if (RibbonBuildOptions.TrimEmptyGroups && groupIsEmpty) { return(null); } string id = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID); string title = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE); string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION); string command = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND); Group group = template.CreateGroup(Ribbon, id, DataNodeWrapper.GetNodeAttributes(data).To <GroupProperties>(), title, description, command, controls, null); return(group); }
private void FillTab(Tab tab, object data, RibbonBuildContext rbc) { JSObject groupsNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.GROUPS); JSObject[] groupChildren = DataNodeWrapper.GetNodeChildren(groupsNode); Dictionary <string, string> emptyTrimmedGroupIds = new Dictionary <string, string>(); for (int i = 0; i < groupChildren.Length; i++) { if (IsNodeTrimmed(groupChildren[i])) { continue; } Group group = BuildGroup(groupChildren[i], rbc); // If the build option TrimEmptyGroups is null, and the Group is empty // then null is returned by BuildGroup() if (!CUIUtility.IsNullOrUndefined(group)) { tab.AddChild(group); } else { // If the group has an Id, then we store it so that we can ignore any scaling // information that relates it it. If it does not have an id, then any scaling info // will not work anyways and it is an invalid node. Groups must have ids. string id = DataNodeWrapper.GetAttribute(groupChildren[i], DataNodeWrapper.ID); if (!string.IsNullOrEmpty(id)) { emptyTrimmedGroupIds[id] = id; } } } JSObject scaling = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.SCALING); JSObject[] children = DataNodeWrapper.GetNodeChildren(scaling); string _scaleWarningMessage = ""; bool _scaleWarning = false; for (int i = 0; i < children.Length; i++) { string name = DataNodeWrapper.GetNodeName(children[i]); string groupId = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.GROUPID); if (name == DataNodeWrapper.MAXSIZE) { // Don't include the scale step if the group that it refers to has been trimmed if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) && !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId]))) { continue; } tab.Scaling.SetGroupMaxSize(groupId, DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE)); } else if (name == DataNodeWrapper.SCALE) { // Don't include the scale step if the group that it refers to has been trimmed if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) && !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId]))) { continue; } tab.Scaling.AddScalingStep(new ScalingStep(groupId, DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE), DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.POPUPSIZE), _scaleWarningMessage, _scaleWarning)); _scaleWarningMessage = ""; _scaleWarning = false; } else if (name == DataNodeWrapper.LOWSCALEWARNING) { _scaleWarningMessage = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.MESSAGE); _scaleWarning = true; } else { throw new InvalidOperationException("Was expecting a node with name MaxSize or Scale."); } } // Start at the largest scale tab.ScaleMax(); }
private int HandleOverflow(object data, DeclarativeTemplateBuildContext bc, Component parent, int sectionCounter) { string alias = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATEALIAS); string name = DataNodeWrapper.GetNodeName(data); List <Control> rec = bc.Controls.ContainsKey(alias) ? bc.Controls[alias] : null; // No Controls need to be added to this overflowarea so we return without doing anything if (CUIUtility.IsNullOrUndefined(rec)) { return(sectionCounter); } bool dividerBefore = false; bool dividerAfter = false; SectionType sectionType = SectionType.OneRow; if (name == DataNodeWrapper.OVERFLOWSECTION) { dividerBefore = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DIVIDERBEFORE)); dividerAfter = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DIVIDERAFTER)); if (dividerBefore) { Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.Divider, SectionAlignment.Top); parent.AddChild(section); } string secType = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TYPE); switch (secType) { case DataNodeWrapper.ONEROW: sectionType = SectionType.OneRow; break; case DataNodeWrapper.TWOROW: sectionType = SectionType.TwoRow; break; case DataNodeWrapper.THREEROW: sectionType = SectionType.ThreeRow; break; default: throw new ArgumentOutOfRangeException("Invalid Section attribute \"Type\" found in XML: " + secType); } } string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE); if (rec.Count > 1) { Section currentSection = null; for (int i = 0; i < rec.Count; i++) { Control control = rec[i]; if (name == DataNodeWrapper.OVERFLOWSECTION) { if (sectionType == SectionType.OneRow) { if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.OneRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else if (sectionType == SectionType.ThreeRow) { // ThreeRow Sections if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.ThreeRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow((i % 3) + 1).AddChild(control.CreateComponentForDisplayMode(displayMode)); // If we have just filled the third row of a section with a ControlComponent, then // we need to signal that we need to start a new section the next time through the loop if (i % 3 == 2) { currentSection = null; } } else { // Two Row Sections if (CUIUtility.IsNullOrUndefined(currentSection)) { currentSection = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.TwoRow, SectionAlignment.Top); parent.AddChild(currentSection); } currentSection.GetRow((i % 2) + 1).AddChild(control.CreateComponentForDisplayMode(displayMode)); // If we have just filled the third row of a section with a ControlComponent, then // we need to signal that we need to start a new section the next time through the loop if (i % 2 == 1) { currentSection = null; } } } else { // <OverflowArea> tag parent.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } } else { Control control = rec[0]; if (name == DataNodeWrapper.OVERFLOWSECTION) { Section section; if (sectionType == SectionType.OneRow) { section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.OneRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else if (sectionType == SectionType.ThreeRow) { // Three Row Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.ThreeRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } else { // Two Row Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.TwoRow, SectionAlignment.Top); section.GetRow(1).AddChild(control.CreateComponentForDisplayMode(displayMode)); } parent.AddChild(section); } else { // <OverflowArea> tag parent.AddChild(control.CreateComponentForDisplayMode(displayMode)); } } if (dividerAfter) { Section section = bc.Ribbon.CreateSection(parent.Id + "-" + sectionCounter++, SectionType.Divider, SectionAlignment.Top); parent.AddChild(section); } return(sectionCounter); }
internal Control BuildControl(object data, BuildContext bc) { Control control = null; string name = DataNodeWrapper.GetNodeName(data); switch (name) { case DataNodeWrapper.ToggleButton: control = BuildToggleButton(data, bc); break; case DataNodeWrapper.ComboBox: control = BuildComboBox(data, bc); break; case DataNodeWrapper.DropDown: control = BuildDropDown(data, bc); break; case DataNodeWrapper.Button: control = BuildButton(data, bc); break; case DataNodeWrapper.SplitButton: control = BuildSplitButton(data, bc); break; case DataNodeWrapper.FlyoutAnchor: control = BuildFlyoutAnchor(data, bc); break; case DataNodeWrapper.GalleryButton: control = BuildGalleryButton(data, bc, null); break; case DataNodeWrapper.InsertTable: control = BuildInsertTable(data, bc); break; case DataNodeWrapper.Label: control = BuildLabel(data, bc); break; case DataNodeWrapper.MRUSplitButton: control = BuildMRUSplitButton(data, bc); break; case DataNodeWrapper.Spinner: control = BuildSpinner(data, bc); break; case DataNodeWrapper.TextBox: control = BuildTextBox(data, bc); break; case DataNodeWrapper.ColorPicker: control = BuildColorPicker(data, bc); break; case DataNodeWrapper.CheckBox: control = BuildCheckBox(data, bc); break; case DataNodeWrapper.Separator: control = BuildSeparator(data, bc); break; default: JSObject attrs = DataNodeWrapper.GetNodeAttributes(data); string className = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.CLASSNAME); if (CUIUtility.IsNullOrUndefined(className)) { throw new InvalidOperationException("Unable to create Control with tagname: " + name); } break; } return(control); }