/// <summary> /// Adds a ToolbarItem to the collection. /// </summary> /// <param name="item">The ToolbarItem to add.</param> public void Add(ToolbarItem item) { if (!Contains(item)) { List.Add(item); } }
/// <summary> /// Adds a ToolbarItem to the collection at a specific index. /// </summary> /// <param name="index">The index at which to add the item.</param> /// <param name="item">The ToolbarItem to add.</param> public void AddAt(int index, ToolbarItem item) { if (!Contains(item)) { List.Insert(index, item); } }
/// <summary> /// Removes a ToolbarItem from the collection. /// </summary> /// <param name="item">The ToolbarItem to remove.</param> public void Remove(ToolbarItem item) { List.Remove(item); }
/// <summary> /// Sets properties of the ToolbarItem before being added. /// </summary> /// <param name="item">The ToolbarItem to be set.</param> private void SetItemProperties(ToolbarItem item) { item.SetParentToolbar(ParentToolbar); }
/// <summary> /// Determines zero-based index of a ToolbarItem within the collection. /// </summary> /// <param name="item">The ToolbarItem to locate within the collection.</param> /// <returns>The zero-based index.</returns> public int IndexOf(ToolbarItem item) { return List.IndexOf(item); }
/// <summary> /// The "flat" index of an item. /// Example: /// Toolbar: Button1 Group1[CheckBtn1, CheckBtn2] Button2 /// Flat IndexOf /// Button1 0 0 /// Group1 -1 1 /// CheckBtn1 1 -1 /// CheckBtn2 2 -1 /// Button2 3 2 /// </summary> /// <param name="item"></param> /// <returns></returns> public int FlatIndexOf(ToolbarItem item) { if (item is ToolbarCheckGroup) { return -1; } int index = 0; foreach (ToolbarItem testItem in List) { if (testItem.Equals(item)) { return index; } if (testItem is ToolbarCheckGroup) { ToolbarCheckGroup group = (ToolbarCheckGroup)testItem; int innerIndex = (item is ToolbarCheckButton) ? group.Items.IndexOf((ToolbarCheckButton)item) : -1; if (innerIndex >= 0) { return index + innerIndex; } else { index += group.Items.Count; } } else { index++; } } return -1; }
/// <summary> /// Determines if a ToolbarItem is in the collection. /// </summary> /// <param name="item">The ToolbarItem to search for.</param> /// <returns>true if the ToolbarItem exists within the collection. false otherwise.</returns> public bool Contains(ToolbarItem item) { return List.Contains(item); }
/// <summary> /// Perform the bubbling necessary in firing the ButtonClick event. /// </summary> /// <param name="item">The source ToolbarItem.</param> private void PostButtonClickEvent(ToolbarItem item) { bool bBubble = true; EventArgs eventArgs = new EventArgs(); if (item is ToolbarButton) { bBubble = ((ToolbarButton)item).OnButtonClick(eventArgs); } if (bBubble && (item is ToolbarCheckButton)) { ToolbarCheckGroup group = ((ToolbarCheckButton)item).Group; if (group != null) { bBubble = group.OnButtonClick(item, eventArgs); } } if (bBubble) { OnButtonClick(item, eventArgs); } }
/// <summary> /// Raises the DataBinding event. This notifies a control to perform any data binding logic that is associated with it. /// </summary> /// <param name="e">An EventArgs object that contains the event data.</param> protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); if (_DataSource != null) { Items.Clear(); _ClearChildViewState = true; string szCurGroup = String.Empty; ToolbarCheckGroup group = null; foreach (Object dataItem in _DataSource) { String type = null; String text = null; String imageUrl = null; String selected = null; String groupname = null; if (DataTypeField != String.Empty) { type = DataBinder.GetPropertyValue(dataItem, DataTypeField, null); } if (DataTextField != String.Empty) { text = DataBinder.GetPropertyValue(dataItem, DataTextField, null); } if (DataImageUrlField != String.Empty) { imageUrl = DataBinder.GetPropertyValue(dataItem, DataImageUrlField, null); } if (DataSelectedField != String.Empty) { selected = DataBinder.GetPropertyValue(dataItem, DataSelectedField, null); } if (DataGroupnameField != String.Empty) { groupname = DataBinder.GetPropertyValue(dataItem, DataGroupnameField, null); } ToolbarItem item = MakeToolbarItem(type); if (item == null) { continue; } bool bEndPrevGroup = (group != null); bool bMakeNewGroup = false; if (item is ToolbarCheckButton) { bEndPrevGroup = (group != null) && ((groupname == null) || (groupname != szCurGroup)); bMakeNewGroup = ((groupname != null) && (groupname != szCurGroup)); } if (bEndPrevGroup) { group = null; szCurGroup = String.Empty; } if (bMakeNewGroup) { group = new ToolbarCheckGroup(); Items.Add(group); szCurGroup = groupname; } if (group != null) { group.Items.Add((ToolbarCheckButton)item); } else { Items.Add(item); } if (item is ToolbarButton) { ToolbarButton btn = (ToolbarButton)item; if (text != null) { btn.Text = text; } if (imageUrl != null) { btn.ImageUrl = imageUrl; } } if (item is ToolbarLabel) { ToolbarLabel label = (ToolbarLabel)item; if (text != null) { label.Text = text; } if (imageUrl != null) { label.ImageUrl = imageUrl; } } if (item is ToolbarCheckButton) { ToolbarCheckButton btn = (ToolbarCheckButton)item; if (selected != null) { btn.SetSelected(selected.ToLower() == "true"); } } } } }