protected ToolStripComboBox CreateComboBox(ChoiceGroup choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; choice.PopulateNow(); if (label == null) label = AdapterStrings.ErrorGeneratingLabel; if (!display.Visible) return null; label = label.Replace("_", "&"); ToolStripComboBox combo = new ToolStripComboBox(); combo.Text = label; //foreach(ChoiceBase s in choice) //{ // item.Items.Add(s.Label); //} //item.Tag = choice; choice.ReferenceWidget = combo; combo.Tag = choice; FillCombo(choice); combo.SelectedIndexChanged += new EventHandler(OnSelectedIndexChanged); combo.Enabled = display.Enabled; combo.Visible = display.Visible; return combo; }
/// <summary> /// Populate a menu. /// This is called by the OnDisplay() method of some ChoiceGroup /// </summary> /// <param name="group">The group that defines this menu item.</param> public override void CreateUIForChoiceGroup(ChoiceGroup group) { m_control.SuspendLayout(); //doesn't help ToolStripMenuItem toolStripItem = group.ReferenceWidget as ToolStripMenuItem; toolStripItem.DropDown.Items.Clear(); bool wantsSeparatorBefore = false; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { wantsSeparatorBefore = true; } else if (item is ChoiceBase) { ToolStripItem newItem = (ToolStripItem)CreateButtonItem(item as ChoiceBase, wantsSeparatorBefore); toolStripItem.DropDown.Items.Add(newItem); //toolStripItem. wantsSeparatorBefore = false; } else if (item is ChoiceGroup) // Submenu { ChoiceGroup choiceGroup = (ChoiceGroup)item; if (choiceGroup.IsSubmenu) { string label = item.Label.Replace("_", "&"); UIItemDisplayProperties display = choiceGroup.GetDisplayProperties(); var submenu = new ToolStripMenuItem() { Tag = item, Text = label }; item.ReferenceWidget = submenu; toolStripItem.DropDown.Items.Add(submenu); if (display.Visible && display.Enabled) { choiceGroup.OnDisplay(m_window, null); } } else if (choiceGroup.IsInlineChoiceList) { choiceGroup.PopulateNow(); foreach (ChoiceRelatedClass inlineItem in choiceGroup) { Debug.Assert(inlineItem is ChoiceBase, "It should not be possible for an in line choice list to contain anything other than simple items!"); toolStripItem.DropDown.Items.Add(CreateButtonItem((ChoiceBase)inlineItem, false)); } } } } m_control.ResumeLayout(); //doesn't help }
protected ToolStripComboBox CreateComboBox(ChoiceGroup choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; choice.PopulateNow(); if (label == null) { label = AdapterStrings.ErrorGeneratingLabel; } if (!display.Visible) { return(null); } label = label.Replace("_", "&"); ToolStripComboBox combo = new ToolStripComboBox(); combo.AccessibilityObject.Name = choice.Id; combo.Text = label; //foreach(ChoiceBase s in choice) //{ // item.Items.Add(s.Label); //} //item.Tag = choice; choice.ReferenceWidget = combo; combo.Tag = choice; FillCombo(choice); combo.SelectedIndexChanged += OnSelectedIndexChanged; combo.Enabled = display.Enabled; combo.Visible = display.Visible; return(combo); }
/// <summary> /// populate a combo box on the toolbar /// </summary> /// <param name="choice">The group that is the basis for this combo box.</param> private void FillCombo(ChoiceGroup choice) { UIItemDisplayProperties groupDisplay = choice.GetDisplayProperties(); ToolStripComboBox combo = choice.ReferenceWidget as ToolStripComboBox; if (combo.Focused) { return; //don't mess while we're in the combo } // Disable if needed, but still show what's current, as for unicode fields where you can't change it, but you want to see what it is set to. combo.Enabled = groupDisplay.Enabled; ArrayList newItems = new ArrayList(); bool fDifferent = false; var selectedItem = (ChoiceBase)null; foreach (ChoiceRelatedClass item in choice) { if (item is SeparatorChoice) { //TODO } else if (item is ChoiceBase) { newItems.Add(item); //if (groupDisplay.Checked) // selectedItem = (ChoiceBase) item; if (choice.SinglePropertyValue == (item as ListPropertyChoice).Value) { selectedItem = (ChoiceBase)item; } if (combo.Items.Count < newItems.Count || combo.Items[newItems.Count - 1] != item) { fDifferent = true; } } } // let it take the default // combo.AccessibleName = choice.Label; if (fDifferent || selectedItem != (combo.SelectedItem)) { //combo.Click -= new EventHandler(OnComboClick); //don't generate clicks (which end up being onpropertychanged() calls) combo.Items.Clear(); combo.Items.AddRange(newItems.ToArray()); combo.DropDownStyle = ComboBoxStyle.DropDownList; combo.SelectedItem = selectedItem; //combo.SuspendLayout = false; } ////Set the ComboWidth of the combo box so that is is wide enough to show ////the text of all items in the list. //int maxStringLength = 0; //for (int i = 0; i < combo.Items.Count; i++) //{ // if (combo.Items[i].ToString().Length > maxStringLength) // { // maxStringLength = combo.Items[i].ToString().Length; // } //} //int factor = 6; //if (maxStringLength > 0 && combo.ComboWidth < maxStringLength * factor) // combo.ComboWidth = maxStringLength * factor; //combo.Tooltip = combo.ToString(); }
/// <summary> /// Populate a menu. /// This is called by the OnDisplay() method of some ChoiceGroup /// </summary> /// <param name="group">The group that defines this menu item.</param> public override void CreateUIForChoiceGroup(ChoiceGroup group) { //m_control.SuspendLayout();//doesn't help ToolStripMenuItem toolStripItem = group.ReferenceWidget as ToolStripMenuItem; toolStripItem.DropDown.Items.Clear(); bool somethingVisibleAlready = false; bool wantsSeparatorBefore = false; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { // don't just add one, we don't want it unless another visible item gets // added, and one has already been added wantsSeparatorBefore = somethingVisibleAlready; } else if (item is ChoiceBase) { bool reallyVisible; ToolStripItem newItem = (ToolStripItem)CreateMenuItem(item as ChoiceBase, out reallyVisible); if (reallyVisible) { somethingVisibleAlready = true; if (wantsSeparatorBefore) { wantsSeparatorBefore = false; toolStripItem.DropDown.Items.Add(new ToolStripSeparator()); } } newItem.AccessibilityObject.Name = item.Id; //newItem.GetType().Name; toolStripItem.DropDown.Items.Add(newItem); //toolStripItem. } else if (item is ChoiceGroup) // Submenu { ChoiceGroup choiceGroup = (ChoiceGroup)item; if (choiceGroup.IsSubmenu) { string label = item.Label.Replace("_", "&"); UIItemDisplayProperties display = choiceGroup.GetDisplayProperties(); if (display.Visible) { somethingVisibleAlready = true; if (wantsSeparatorBefore) { wantsSeparatorBefore = false; toolStripItem.DropDown.Items.Add(new ToolStripSeparator()); } } var submenu = new ToolStripMenuItem { Tag = item, Text = label }; if (display.ImageLabel != "default") { submenu.Image = m_smallImages.GetImage(display.ImageLabel); } submenu.AccessibilityObject.Name = item.Id; // Have the submenu display characteristics behave as desired. See FWR-3104. submenu.Visible = display.Visible; submenu.Enabled = display.Enabled; //submenu.GetType().Name; item.ReferenceWidget = submenu; toolStripItem.DropDown.Items.Add(submenu); if (display.Visible && display.Enabled) { choiceGroup.OnDisplay(m_window, null); } } else if (choiceGroup.IsInlineChoiceList) { choiceGroup.PopulateNow(); foreach (ChoiceRelatedClass inlineItem in choiceGroup) { Debug.Assert(inlineItem is ChoiceBase, "It should not be possible for an in line choice list to contain anything other than simple items!"); bool reallyVisible; ToolStripItem newItem = CreateMenuItem((ChoiceBase)inlineItem, out reallyVisible); if (reallyVisible) { somethingVisibleAlready = true; if (wantsSeparatorBefore) { wantsSeparatorBefore = false; toolStripItem.DropDown.Items.Add(new ToolStripSeparator()); } } toolStripItem.DropDown.Items.Add(newItem); } } } } m_control.ResumeLayout(); //doesn't help }
/// <summary> /// populate a combo box on the toolbar /// </summary> /// <param name="choice">The group that is the basis for this combo box.</param> private void FillCombo(ChoiceGroup choice) { UIItemDisplayProperties groupDisplay = choice.GetDisplayProperties(); ToolStripComboBox combo = choice.ReferenceWidget as ToolStripComboBox; if (combo.Focused) return;//don't mess while we're in the combo // Disable if needed, but still show what's current, as for unicode fields where you can't change it, but you want to see what it is set to. combo.Enabled = groupDisplay.Enabled; ArrayList newItems = new ArrayList(); bool fDifferent = false; var selectedItem = (ChoiceBase) null; foreach (ChoiceRelatedClass item in choice) { if (item is SeparatorChoice) { //TODO } else if (item is ChoiceBase) { newItems.Add(item); //if (groupDisplay.Checked) // selectedItem = (ChoiceBase) item; if (choice.SinglePropertyValue == (item as ListPropertyChoice).Value) selectedItem = (ChoiceBase) item; if (combo.Items.Count < newItems.Count || combo.Items[newItems.Count - 1] != item) fDifferent = true; } } // let it take the default // combo.AccessibleName = choice.Label; if (fDifferent || selectedItem != (combo.SelectedItem)) { //combo.Click -= new EventHandler(OnComboClick); //don't generate clicks (which end up being onpropertychanged() calls) combo.Items.Clear(); combo.Items.AddRange(newItems.ToArray()); combo.DropDownStyle = ComboBoxStyle.DropDownList; combo.SelectedItem = selectedItem; //combo.SuspendLayout = false; } ////Set the ComboWidth of the combo box so that is is wide enough to show ////the text of all items in the list. //int maxStringLength = 0; //for (int i = 0; i < combo.Items.Count; i++) //{ // if (combo.Items[i].ToString().Length > maxStringLength) // { // maxStringLength = combo.Items[i].ToString().Length; // } //} //int factor = 6; //if (maxStringLength > 0 && combo.ComboWidth < maxStringLength * factor) // combo.ComboWidth = maxStringLength * factor; //combo.Tooltip = combo.ToString(); }
/// <summary> /// populate a combo box on the toolbar /// </summary> /// <param name="group">The group that is the basis for this combo box.</param> private void FillCombo(ChoiceGroup group) { UIItemDisplayProperties groupDisplay = group.GetDisplayProperties(); ComboBoxItem combo = group.ReferenceWidget as ComboBoxItem; if (combo.Focused) { return; //don't mess while we're in the combo } // Disable if needed, but still show what's current, as for unicode fields where you can't change it, but you want to see what it is set to. combo.Enabled = groupDisplay.Enabled; ArrayList newItems = new ArrayList(); bool fDifferent = false; ComboItem selectedItem = null; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { //TODO } else if (item is ChoiceBase) { UIItemDisplayProperties display = ((ChoiceBase)item).GetDisplayProperties(); ComboItem ci = CreateComboItem((ChoiceBase)item, display); if (ci != null) //will be null if item is supposed to be invisible now { newItems.Add(ci); if (display.Checked) { selectedItem = ci; //nb: if there should be more than one, only the last one will be selected } if (combo.Items.Count < newItems.Count || ((combo.Items[newItems.Count - 1]) as ComboItem).Tag != item) { fDifferent = true; } } } } combo.AccessibleName = group.Label; if (fDifferent || selectedItem.Tag != (combo.SelectedItem as ComboItem).Tag) { combo.SuspendLayout = true; combo.Click -= new EventHandler(OnComboClick); //don't generate clicks (which end up being onpropertychanged() calls) combo.Items.Clear(); combo.Items.AddRange(newItems.ToArray()); combo.SelectedItem = selectedItem; combo.Click += new EventHandler(OnComboClick); combo.SuspendLayout = false; } //Set the ComboWidth of the combo box so that is is wide enough to show //the text of all items in the list. int maxStringLength = 0; for (int i = 0; i < combo.Items.Count; i++) { if (combo.Items[i].ToString().Length > maxStringLength) { maxStringLength = combo.Items[i].ToString().Length; } } int factor = 6; if (maxStringLength > 0 && combo.ComboWidth < maxStringLength * factor) { combo.ComboWidth = maxStringLength * factor; } combo.Tooltip = combo.ToString(); }
/// <summary> /// populate a combo box on the toolbar /// </summary> /// <param name="group">The group that is the basis for this combo box.</param> private void FillCombo(ChoiceGroup group) { UIItemDisplayProperties groupDisplay = group.GetDisplayProperties(); ComboBoxItem combo = group.ReferenceWidget as ComboBoxItem; if(combo.Focused) return;//don't mess while we're in the combo // Disable if needed, but still show what's current, as for unicode fields where you can't change it, but you want to see what it is set to. combo.Enabled = groupDisplay.Enabled; ArrayList newItems = new ArrayList(); bool fDifferent = false; ComboItem selectedItem = null; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { //TODO } else if (item is ChoiceBase) { UIItemDisplayProperties display = ((ChoiceBase)item).GetDisplayProperties(); ComboItem ci = CreateComboItem((ChoiceBase)item, display); if (ci != null)//will be null if item is supposed to be invisible now { newItems.Add(ci); if (display.Checked) { selectedItem = ci; //nb: if there should be more than one, only the last one will be selected } if (combo.Items.Count < newItems.Count || ((combo.Items[newItems.Count - 1]) as ComboItem).Tag != item) fDifferent = true; } } } combo.AccessibleName = group.Label; if (fDifferent || selectedItem.Tag != (combo.SelectedItem as ComboItem).Tag) { combo.SuspendLayout = true; combo.Click -= new EventHandler(OnComboClick); //don't generate clicks (which end up being onpropertychanged() calls) combo.Items.Clear(); combo.Items.AddRange(newItems.ToArray()); combo.SelectedItem = selectedItem; combo.Click += new EventHandler(OnComboClick); combo.SuspendLayout = false; } //Set the ComboWidth of the combo box so that is is wide enough to show //the text of all items in the list. int maxStringLength = 0; for (int i = 0; i < combo.Items.Count; i++) { if (combo.Items[i].ToString().Length > maxStringLength) { maxStringLength = combo.Items[i].ToString().Length; } } int factor = 6; if (maxStringLength > 0 && combo.ComboWidth < maxStringLength * factor) combo.ComboWidth = maxStringLength * factor; combo.Tooltip = combo.ToString(); }
/// <summary> /// Populate a menu. /// This is called by the OnDisplay() method of some ChoiceGroup /// </summary> /// <param name="group">The group that defines this menu item.</param> public override void CreateUIForChoiceGroup(ChoiceGroup group) { m_control.SuspendLayout(); //doesn't help ButtonItem menu = (ButtonItem)group.ReferenceWidget; if (menu.SubItems.Count > 0) { Debug.WriteLine("CreateUIForChoiceGroup " + group.Label); } menu.SubItems.Clear(); bool wantsSeparatorBefore = false; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { wantsSeparatorBefore = true; } else if (item is ChoiceBase) { menu.SubItems.Add(CreateButtonItem((ChoiceBase)item, wantsSeparatorBefore)); wantsSeparatorBefore = false; } else if (item is ChoiceGroup) // Submenu { ChoiceGroup choiceGroup = (ChoiceGroup)item; if (choiceGroup.IsSubmenu) { UIItemDisplayProperties display = choiceGroup.GetDisplayProperties(); string label = item.Label.Replace("_", "&"); ButtonItem submenu = new ButtonItem(item.Id, label); submenu.BeginGroup = wantsSeparatorBefore; wantsSeparatorBefore = false; menu.SubItems.Add(submenu); submenu.Tag = item; item.ReferenceWidget = submenu; submenu.Visible = display.Visible; if (display.Visible) { // Can be visible and either enabled or disabled. submenu.Enabled = display.Enabled; if (display.Enabled) { //the drop down the event seems to be ignored by the submenusof this package. //submenu.DropDown += new System.EventHandler(((ChoiceGroup)item).OnDisplay); //therefore, we need to populate the submenu right now and not wait choiceGroup.OnDisplay(m_window, null); //hide if no sub items were added REVIEW: would it be better to just disable? //submenu.Visible = submenu.SubItems.Count > 0; } else //if we don't have *any* items, it won't look like a submenu { submenu.SubItems.Add(new DevComponents.DotNetBar.ButtonItem("dummy", "dummy")); } } else { submenu.Enabled = false; // Not visible, so no need for it to be enabled. } //this was enough to make the menu enabled, but not enough to trigger the drop down event when chosen //submenu.Items.Add(new CommandBarSeparator()); } else if (choiceGroup.IsInlineChoiceList) { choiceGroup.PopulateNow(); foreach (ChoiceRelatedClass inlineItem in choiceGroup) { Debug.Assert(inlineItem is ChoiceBase, "It should not be possible for an in line choice list to contain anything other than simple items!"); menu.SubItems.Add(CreateButtonItem((ChoiceBase)inlineItem, false)); } } else { throw new ApplicationException("Unknown kind of ChoiceGroup."); } } else { throw new ApplicationException("Unknown kind of ChoiceRelatedClass."); } } m_control.ResumeLayout(); //doesn't help }