/// <summary> /// do a limited update of the toolbar /// </summary> /// <remarks>when the user's cursor is hovering over a button and we do a redraw, /// this method is called. This allows us to update the enabled state of the button /// without getting flashing tool tips, /// which is what we get if we were to clear the toolbar and rebuild the buttons, /// as is normally done at idle time. /// </remarks> /// <param name="group"></param> protected void UpdateToolbar(ChoiceGroup group) { Bar toolbar = (Bar)group.ReferenceWidget; foreach (BaseItem item in toolbar.Items) { if (item.Tag == null) { continue; } ChoiceBase choice = item.Tag as ChoiceBase; if (choice != null) { UIItemDisplayProperties display = choice.GetDisplayProperties(); // If what should be displayed has changed, refill the toolbar. if (item.Visible && !display.Visible) { FillToolbar(group, toolbar); return; } item.Enabled = display.Enabled; } //update combo box ChoiceGroup comboGroup = item.Tag as ChoiceGroup; if (comboGroup != null) { //UIItemDisplayProperties display = group.GetDisplayProperties(); //item.Enabled = display.Enabled; comboGroup.PopulateNow(); // make sure list of items is up to date. FillCombo(comboGroup); //maybe too drastic } } }
protected void CreateControlWidget(MenuItem menu, ChoiceBase control) { string label = control.Label; label = label.Replace("_", "&"); MenuItem menuItem = new MenuItem(label); menuItem.Click += new System.EventHandler(control.OnClick); //note that we could handle the details of display in two different ways. //either weekend of this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) //for now, I am going to do the latter because with the sidebar code we are using //that kind of polling will not be done automatically. so we do it this way here so that //the sidebar adapter can be written parallel to this one. UIItemDisplayProperties display = control.GetDisplayProperties(); menuItem.Checked = display.Checked; menuItem.Enabled = display.Enabled; menuItem.Text = display.Text; control.ReferenceWidget = menuItem; menu.MenuItems.Add(menuItem); }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="reallyVisible">true if the item will be visible eventually /// (it never is right away, because the parent control isn't yet)</param> /// <exception cref="ConfigurationException"></exception> /// <returns>The new item.</returns> protected ToolStripItem CreateButtonItem(ChoiceBase choice, out bool reallyVisible) { UIItemDisplayProperties display = choice.GetDisplayProperties(); reallyVisible = display.Visible; string label = display.Text; if (label == null) label = AdapterStrings.ErrorGeneratingLabel; label = label.Replace("_", "&"); ToolStripButton item = new ToolStripButton(label); item.AccessibilityObject.Name = choice.Id; item.Tag = choice.Id; if(choice is CommandChoice) { item.Click += OnClick; } else { item.Click += choice.OnClick; } Image image = null; if (display.ImageLabel!= "default") image = m_smallImages.GetImage(display.ImageLabel); item.Image = image; item.Checked = display.Checked; Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) { String s = ((IContextHelper)helper).GetToolTip(choice.HelpId); if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); s += '(' + kc.ConvertToString(choice.Shortcut) + ')'; item.ToolTipText = s; } } else item.ToolTipText = item.Text.Replace("&",""); //useful for buttons. choice.ReferenceWidget = item; return item; }
protected CommandBarItem CreateMenuItem(ChoiceBase choice) { //note that we could handle the details of display in two different ways. //either we can leave this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; bool isSeparatorBar = (label == "-"); label = label.Replace("_", "&"); Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } CommandBarItem menuItem; if (choice is CommandChoice) { if (isSeparatorBar) { menuItem = new CommandBarSeparator(); } else { menuItem = new CommandBarButton(image, label, new EventHandler(OnClick)); } } else { CommandBarCheckBox cb = new CommandBarCheckBox(image, label); cb.Click += new System.EventHandler(choice.OnClick); cb.IsChecked = display.Checked; menuItem = cb; } if (!isSeparatorBar) { ((CommandBarButtonBase)menuItem).Shortcut = choice.Shortcut; } menuItem.Tag = choice; menuItem.IsEnabled = !isSeparatorBar && display.Enabled; menuItem.IsVisible = display.Visible; choice.ReferenceWidget = menuItem; return(menuItem); }
protected void MakeButton(OutlookBarBand band, ChoiceBase control) { UIItemDisplayProperties display = control.GetDisplayProperties(); display.Text = display.Text.Replace("_", ""); OutlookBarItem button; // if(m_images!=null && m_images.ImageList.Images.Count>0) // { // button = new OutlookBarItem(display.Text,0,control); // } // else //no images have been supplied to us! button = new OutlookBarItem(); button.Tag = control; control.ReferenceWidget = button; if (band.IconView == SidebarLibrary.WinControls.IconView.Large) { if (m_largeImages.ImageList.Images.Count > 0) { button.ImageIndex = m_largeImages.GetImageIndex(display.ImageLabel); } } else { if (m_smallImages.ImageList.Images.Count > 0) { button.ImageIndex = m_smallImages.GetImageIndex(display.ImageLabel); } } button.Selected = display.Checked; button.Text = display.Text; // if(display.Checked) // button.Text = button.Text + " (X)"; if (!display.Enabled) { button.Text = button.Text + " NA"; } //note that this sidebar library we are using does not provide click events on individual items. //So we cannot wire them up here. band.Items.Add(button); }
/// <summary> /// we use the idle call here to update the enabled/disabled state of the buttons /// </summary> public void OnIdle() { if (m_commandBarManager == null || m_commandBarManager.CommandBars == null) { return; //not really ready for an onIdle yet. } foreach (CommandBar bar in m_commandBarManager.CommandBars) { foreach (CommandBarItem button in bar.Items) { if (!(button is CommandBarButton)) { continue; } ChoiceBase control = (ChoiceBase)button.Tag; UpdateDisplay(control.GetDisplayProperties(), (CommandBarButton)button); } } }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="reallyVisible">true if the item will be visible eventually /// (it never is right away, because the parent control isn't yet)</param> /// <exception cref="ConfigurationException"></exception> /// <returns>The new item.</returns> protected ToolStripItem CreateButtonItem(ChoiceBase choice, out bool reallyVisible) { UIItemDisplayProperties display = choice.GetDisplayProperties(); reallyVisible = display.Visible; string label = display.Text; if (label == null) { label = AdapterStrings.ErrorGeneratingLabel; } label = label.Replace("_", "&"); ToolStripButton item = new ToolStripButton(label); item.AccessibilityObject.Name = choice.Id; item.Tag = choice.Id; if (choice is CommandChoice) { item.Click += OnClick; } else { item.Click += choice.OnClick; } Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } item.Image = image; item.Checked = display.Checked; Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; if (m_propertyTable.PropertyExists("ContextHelper")) { var helper = m_propertyTable.GetValue <IContextHelper>("ContextHelper"); String s = helper.GetToolTip(choice.HelpId); if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); s += '(' + kc.ConvertToString(choice.Shortcut) + ')'; item.ToolTipText = s; } } else { item.ToolTipText = item.Text.Replace("&", ""); //useful for buttons. } choice.ReferenceWidget = item; return(item); }
protected ToolStripItem CreateMenuItem(ChoiceBase choice, out bool reallyVisible) { if (choice is SeparatorChoice) { reallyVisible = true; return(new ToolStripSeparator()); } UIItemDisplayProperties display = choice.GetDisplayProperties(); reallyVisible = display.Visible; string label = display.Text; if (label == null) { label = AdapterStrings.ErrorGeneratingLabel; } label = label.Replace("_", "&"); ToolStripMenuItem item = new ToolStripMenuItem(label); item.AccessibilityObject.Name = choice.Id; item.Tag = choice.Id; if (choice is CommandChoice) { item.Click += OnClick; } else { item.Click += choice.OnClick; } Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } item.Image = image; item.Checked = display.Checked; if (choice.Shortcut != Keys.None) { KeysConverter sc = new KeysConverter(); try { if (IsAcceptableShortcut(choice.Shortcut)) { item.ShortcutKeys = choice.Shortcut; } // otherwise some other code must implement the shortcut, the built-in menu item code won't do it. } catch (Exception ex) { if (!(ex is InvalidEnumArgumentException)) { throw new ConfigurationException( "Software couldn't understand or doesn't support this shortcut: (" + choice.Shortcut + ") for " + choice.Label, ex); } } } Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; if (m_propertyTable.PropertyExists("ContextHelper")) { var helper = m_propertyTable.GetValue <IContextHelper>("ContextHelper"); String s = helper.GetToolTip(choice.HelpId); item.ToolTipText = s; if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); item.ToolTipText += '(' + kc.ConvertToString(choice.Shortcut) + ')'; } } else { item.ToolTipText = item.Text.Replace("&", ""); //useful for buttons. } choice.ReferenceWidget = item; return(item); }
protected ToolStripItem CreateMenuItem(ChoiceBase choice, out bool reallyVisible) { UIItemDisplayProperties display = choice.GetDisplayProperties(); reallyVisible = display.Visible; string label = display.Text; if (label == null) label = AdapterStrings.ErrorGeneratingLabel; label = label.Replace("_", "&"); ToolStripMenuItem item = new ToolStripMenuItem(label); item.AccessibilityObject.Name = choice.Id; item.Tag = choice.Id; if (choice is CommandChoice) { item.Click += OnClick; } else { item.Click += choice.OnClick; } Image image = null; if (display.ImageLabel != "default") image = m_smallImages.GetImage(display.ImageLabel); item.Image = image; item.Checked = display.Checked; if(choice.Shortcut != Keys.None) { KeysConverter sc = new KeysConverter(); try { if (IsAcceptableShortcut(choice.Shortcut)) item.ShortcutKeys = choice.Shortcut; // otherwise some other code must implement the shortcut, the built-in menu item code won't do it. } catch(Exception ex) { if (!(ex is InvalidEnumArgumentException)) throw new ConfigurationException( "Software couldn't understand or doesn't support this shortcut: (" + choice.Shortcut + ") for " + choice.Label, ex); } } Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) { String s = ((IContextHelper)helper).GetToolTip(choice.HelpId); item.ToolTipText = s; if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); item.ToolTipText += '(' + kc.ConvertToString(choice.Shortcut) + ')'; } } else item.ToolTipText = item.Text.Replace("&", ""); //useful for buttons. choice.ReferenceWidget = item; return item; }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="wantsSeparatorBefore">True, if it should have a separator before it, /// otherwise false.</param> /// <returns>The new item.</returns> protected ButtonItem CreateButtonItem(ChoiceBase choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; if (label == null) { label = AdapterStrings.ErrorGeneratingLabel; } label = label.Replace("_", "&"); ButtonItem item = new ButtonItem(choice.Id, label); // if(choice is CommandChoice) // { // Image image = null; // if (display.ImageLabel!= "default") // image = m_smallImages.GetImage(display.ImageLabel); // item.Image = image; // item.Click += new EventHandler(OnClick); // // // this is a bit odd to have checks on commands, but in at least one case // // (field visibility) the programmer expected this to work. So let's make it work. // item.Checked = display.Checked; // } // else // { // item.Click += new EventHandler(choice.OnClick); // item.Checked = display.Checked; // } if (choice is CommandChoice) { item.Click += new EventHandler(OnClick); } else { item.Click += new EventHandler(choice.OnClick); } Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } item.Image = image; item.Checked = display.Checked; if (choice.Shortcut != System.Windows.Forms.Keys.None) { try { //try just casting in the shortcut item.Shortcuts.Add((eShortcut)choice.Shortcut); } catch { throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: (" + choice.Shortcut.ToString() + ") for " + choice.Label); } // string s = choice.Shortcut.ToString().Replace("+","");//remove any + // // System.Windows.Forms.Shortcut sc = (System.Windows.Forms.Shortcut) Enum.Parse(typeof(System.Windows.Forms.Shortcut), s); // //DevComponents.DotNetBar.e // if(s.IndexOf(", Shift")> -1) // { // s= "Shift"+s.Replace(", Shift",""); // } // if(s.IndexOf(", Control")> -1) // { // s= "Ctrl"+s.Replace(", Control",""); // } // if(s.IndexOf(", Alt")> -1) // { // s= "Alt"+s.Replace(", Alt",""); // } // try // { // eShortcut e = (eShortcut) Enum.Parse(typeof(eShortcut), s); // item.Shortcuts.Add(e); // catch // { // item.Shortcuts.Add((eShortcut)choice.Shortcut); // //throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: "+s+" ("+choice.Shortcut.ToString()+") for "+choice.Label); // } // } // catch // { // item.Shortcuts.Add((eShortcut)choice.Shortcut); // //throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: "+s+" ("+choice.Shortcut.ToString()+") for "+choice.Label); // } // } } Debug.Assert(item != null); item.BeginGroup = wantsSeparatorBefore; item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) { item.Tooltip = ((IContextHelper)helper).GetToolTip(choice.HelpId); } else { item.Tooltip = item.Text.Replace("&", ""); //useful for buttons. } choice.ReferenceWidget = item; return(item); }
/// <summary> /// Create a ButtonItem for the sidebar. /// </summary> /// <param name="panelItem"></param> /// <param name="control"></param> protected void MakeButton(SideBarPanelItem panelItem, ChoiceBase control) { UIItemDisplayProperties display = control.GetDisplayProperties(); display.Text = display.Text.Replace("_", ""); ButtonItem button = new ButtonItem(control.Id, display.Text); button.Tag = control; control.ReferenceWidget = button; if(panelItem.ItemImageSize == eBarImageSize.Large) { if(m_largeImages.ImageList.Images.Count > 0) button.ImageIndex = m_largeImages.GetImageIndex(display.ImageLabel); } else { if(m_smallImages.ImageList.Images.Count > 0) button.ImageIndex = m_smallImages.GetImageIndex(display.ImageLabel); } button.Text = display.Text; button.ButtonStyle = eButtonStyle.ImageAndText; if(!display.Enabled) button.Text = button.Text + " NA"; button.Click += new EventHandler(OnClick); panelItem.SubItems.Add(button); //a button in this framework not really a Control... so I don't know how to use //(the same company's) balloon tip control on a sidebar button! // m_mediator.SendMessage("RegisterHelpTarget", button.ContainerControl); }
protected void CreateControlWidget(MenuItem menu , ChoiceBase control) { string label = control.Label; label = label.Replace("_", "&"); MenuItem menuItem = new MenuItem(label); menuItem.Click += new System.EventHandler(control.OnClick); //note that we could handle the details of display in two different ways. //either weekend of this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) //for now, I am going to do the latter because with the sidebar code we are using //that kind of polling will not be done automatically. so we do it this way here so that //the sidebar adapter can be written parallel to this one. UIItemDisplayProperties display = control.GetDisplayProperties(); menuItem.Checked = display.Checked; menuItem.Enabled= display. Enabled; menuItem.Text = display.Text; control.ReferenceWidget = menuItem; menu.MenuItems.Add(menuItem); }
/// <summary> /// build (or rebuild) the toolbar /// </summary> /// <param name="group"></param> /// <param name="toolbar"></param> private void FillToolbar(ChoiceGroup group, Bar toolbar) { bool wantsSeparatorBefore = false; string groupName = group.Label; ClearOutToolbar(toolbar); foreach (ChoiceRelatedClass item in group) { string itemName = item.Label; if (item is SeparatorChoice) { wantsSeparatorBefore = true; } else if (item is ChoiceBase) { ChoiceBase choice = (ChoiceBase)item; UIItemDisplayProperties display = choice.GetDisplayProperties(); if (!display.Visible) { continue; } ButtonItem btn = CreateButtonItem(choice, wantsSeparatorBefore); btn.Enabled = display.Enabled; btn.Category = group.Label; toolbar.Items.Add(btn); // DIDN'T WORK // if(!Manager.Items.Contains(btn.Name)) // Manager.Items.Add(btn.Copy()); wantsSeparatorBefore = false; } else if (item is ChoiceGroup) // Submenu { ChoiceGroup choiceGroup = (ChoiceGroup)item; //nb: the DNB class name, "ComboBoxItem" is very misleading. This is the box itself, //not an item in the box. ComboBoxItem combo = new ComboBoxItem(/*name*/ item.Id, /*text*/ item.Label); toolbar.Items.Add(combo); combo.Tag = item; int width = 100; // Make this configurable from the xml XmlAttribute att = item.ConfigurationNode.Attributes["width"]; if (att != null) { width = Int32.Parse(att.Value); } combo.ComboWidth = width; //combo.Stretch = true;//doesn't help item.ReferenceWidget = combo; //submenu.IsEnabled= true; //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 //submenu.Visible = submenu.SubItems.Count>0; } else { // TODO: Add support for other types of toolbar objects. } } toolbar.RecalcLayout(); toolbar.RecalcSize(); }
protected CommandBarItem CreateMenuItem(ChoiceBase choice) { //note that we could handle the details of display in two different ways. //either we can leave this up to the normal display mechanism, which will do its own polling, //or we could just build the menu in the desired state right here (enable checked etc.) UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; bool isSeparatorBar = (label == "-"); label = label.Replace("_", "&"); Image image = null; if (display.ImageLabel!= "default") image = m_smallImages.GetImage(display.ImageLabel); CommandBarItem menuItem; if(choice is CommandChoice) { if (isSeparatorBar) menuItem = new CommandBarSeparator(); else menuItem = new CommandBarButton(image, label, new EventHandler(OnClick)); } else { CommandBarCheckBox cb = new CommandBarCheckBox(image, label); cb.Click += new System.EventHandler(choice.OnClick); cb.IsChecked = display.Checked; menuItem = cb; } if (!isSeparatorBar) ((CommandBarButtonBase)menuItem).Shortcut = choice.Shortcut; menuItem.Tag = choice; menuItem.IsEnabled = !isSeparatorBar && display.Enabled; menuItem.IsVisible = display.Visible; choice.ReferenceWidget = menuItem; return menuItem; }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="wantsSeparatorBefore">True, if it should have a separator before it, /// otherwise false.</param> /// <returns>The new item.</returns> protected ToolStripMenuItem CreateButtonItem(ChoiceBase choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; if (label == null) { label = AdapterStrings.ErrorGeneratingLabel; } label = label.Replace("_", "&"); ToolStripMenuItem item = new ToolStripMenuItem(label); item.Tag = choice.Id; if (choice is CommandChoice) { item.Click += new EventHandler(OnClick); } else { item.Click += new EventHandler(choice.OnClick); } Image image = null; if (display.ImageLabel != "default") { image = m_smallImages.GetImage(display.ImageLabel); } item.Image = image; item.Checked = display.Checked; if (choice.Shortcut != System.Windows.Forms.Keys.None) { // TODO: Implement for this version of adapter. try { } catch { throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: (" + choice.Shortcut.ToString() + ") for " + choice.Label); } } Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) { String s = ((IContextHelper)helper).GetToolTip(choice.HelpId); if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); s += '(' + kc.ConvertToString(choice.Shortcut) + ')'; item.ToolTipText = s; } } else { item.ToolTipText = item.Text.Replace("&", ""); //useful for buttons. } choice.ReferenceWidget = item; return(item); }
public void CreateUIForChoiceGroup(ChoiceGroup group) { foreach (ChoiceRelatedClass item in group) { CommandBar toolbar = (CommandBar)group.ReferenceWidget; Debug.Assert(toolbar != null); if (item is SeparatorChoice) { toolbar.Items.Add(new CommandBarSeparator()); } else if (item is ChoiceBase) { ChoiceBase control = (ChoiceBase)item; //System.Windows.Forms.Keys shortcut = System.Windows.Forms.Keys. UIItemDisplayProperties display = control.GetDisplayProperties(); display.Text = display.Text.Replace("_", ""); Image image = m_smallImages.GetImage(display.ImageLabel); CommandBarButton button = new CommandBarButton(image, display.Text, new EventHandler(OnClick)); UpdateDisplay(display, button); button.Tag = control; control.ReferenceWidget = button; toolbar.Items.Add(button); button.IsEnabled = true; } //if this is a submenu /* * I started playing with being able to have been used in here, but it. Complicated fast because * we would need to be referring over to the menubar adapter to fill in the menu items. * else if(item is ChoiceGroup) * { * if(((ChoiceGroup)item).IsSubmenu) * { * string label = item.Label.Replace("_", "&"); * CommandBarMenu submenu = new CommandBarMenu(label);// menu.Items.AddMenu(label); * toolbar.Items.Add(submenu); * submenu.Tag = item; * item.ReferenceWidget = submenu; * //submenu.IsEnabled= true; * //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)item).OnDisplay(this, null); * //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)item).IsInlineChoiceList) * // { * // ((ChoiceGroup)item).PopulateNow(); * // foreach(ChoiceRelatedClass inlineItem in ((ChoiceGroup)item)) * // { * // Debug.Assert(inlineItem is ChoiceBase, "It should not be possible for a in line choice list to contain anything other than simple items!"); * // menu.Items.Add(CreateMenuItem ((ChoiceBase)inlineItem)); * // } * // } * * } */ } }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="wantsSeparatorBefore">True, if it should have a separator before it, /// otherwise false.</param> /// <returns>The new item.</returns> protected ToolStripMenuItem CreateButtonItem(ChoiceBase choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; if (label ==null) label = AdapterStrings.ErrorGeneratingLabel; label = label.Replace("_", "&"); ToolStripMenuItem item = new ToolStripMenuItem(label); item.Tag = choice.Id; if(choice is CommandChoice) { item.Click += new EventHandler(OnClick); } else { item.Click += new EventHandler(choice.OnClick); } Image image = null; if (display.ImageLabel!= "default") image = m_smallImages.GetImage(display.ImageLabel); item.Image = image; item.Checked = display.Checked; if(choice.Shortcut != System.Windows.Forms.Keys.None) { // TODO: Implement for this version of adapter. try { } catch { throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: ("+choice.Shortcut.ToString()+") for "+choice.Label); } } Debug.Assert(item != null); item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) { String s = ((IContextHelper)helper).GetToolTip(choice.HelpId); if (choice.Shortcut != Keys.None) { KeysConverter kc = new KeysConverter(); s += '(' + kc.ConvertToString(choice.Shortcut) + ')'; item.ToolTipText = s; } } else item.ToolTipText = item.Text.Replace("&",""); //useful for buttons. choice.ReferenceWidget = item; return item; }
protected void MakeButton(OutlookBarBand band , ChoiceBase control) { UIItemDisplayProperties display = control.GetDisplayProperties(); display.Text = display.Text.Replace("_", ""); OutlookBarItem button; // if(m_images!=null && m_images.ImageList.Images.Count>0) // { // button = new OutlookBarItem(display.Text,0,control); // } // else //no images have been supplied to us! button = new OutlookBarItem(); button.Tag = control; control.ReferenceWidget = button; if(band.IconView == SidebarLibrary.WinControls.IconView.Large) { if(m_largeImages.ImageList.Images.Count>0) button.ImageIndex = m_largeImages.GetImageIndex(display.ImageLabel); } else { if(m_smallImages.ImageList.Images.Count>0) button.ImageIndex = m_smallImages.GetImageIndex(display.ImageLabel); } button.Selected = display.Checked; button.Text = display.Text; // if(display.Checked) // button.Text = button.Text + " (X)"; if(!display.Enabled) button.Text = button.Text + " NA"; //note that this sidebar library we are using does not provide click events on individual items. //So we cannot wire them up here. band.Items.Add (button); }
/// <summary> /// Create a button item for use on a menu or a toolbar. /// </summary> /// <param name="choice">The details for the new item.</param> /// <param name="wantsSeparatorBefore">True, if it should have a separator before it, /// otherwise false.</param> /// <returns>The new item.</returns> protected ButtonItem CreateButtonItem(ChoiceBase choice, bool wantsSeparatorBefore) { UIItemDisplayProperties display = choice.GetDisplayProperties(); string label = display.Text; if (label ==null) label = AdapterStrings.ErrorGeneratingLabel; label = label.Replace("_", "&"); ButtonItem item = new ButtonItem(choice.Id, label); // if(choice is CommandChoice) // { // Image image = null; // if (display.ImageLabel!= "default") // image = m_smallImages.GetImage(display.ImageLabel); // item.Image = image; // item.Click += new EventHandler(OnClick); // // // this is a bit odd to have checks on commands, but in at least one case // // (field visibility) the programmer expected this to work. So let's make it work. // item.Checked = display.Checked; // } // else // { // item.Click += new EventHandler(choice.OnClick); // item.Checked = display.Checked; // } if(choice is CommandChoice) { item.Click += new EventHandler(OnClick); } else { item.Click += new EventHandler(choice.OnClick); } Image image = null; if (display.ImageLabel!= "default") image = m_smallImages.GetImage(display.ImageLabel); item.Image = image; item.Checked = display.Checked; if(choice.Shortcut != System.Windows.Forms.Keys.None) { try { //try just casting in the shortcut item.Shortcuts.Add((eShortcut) choice.Shortcut); } catch { throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: ("+choice.Shortcut.ToString()+") for "+choice.Label); } // string s = choice.Shortcut.ToString().Replace("+","");//remove any + // // System.Windows.Forms.Shortcut sc = (System.Windows.Forms.Shortcut) Enum.Parse(typeof(System.Windows.Forms.Shortcut), s); // //DevComponents.DotNetBar.e // if(s.IndexOf(", Shift")> -1) // { // s= "Shift"+s.Replace(", Shift",""); // } // if(s.IndexOf(", Control")> -1) // { // s= "Ctrl"+s.Replace(", Control",""); // } // if(s.IndexOf(", Alt")> -1) // { // s= "Alt"+s.Replace(", Alt",""); // } // try // { // eShortcut e = (eShortcut) Enum.Parse(typeof(eShortcut), s); // item.Shortcuts.Add(e); // catch // { // item.Shortcuts.Add((eShortcut)choice.Shortcut); // //throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: "+s+" ("+choice.Shortcut.ToString()+") for "+choice.Label); // } // } // catch // { // item.Shortcuts.Add((eShortcut)choice.Shortcut); // //throw new ConfigurationException("DotNetBar Adapter couldn't understand or doesn't support this shortcut: "+s+" ("+choice.Shortcut.ToString()+") for "+choice.Label); // } // } } Debug.Assert(item != null); item.BeginGroup = wantsSeparatorBefore; item.Tag = choice; item.Enabled = display.Enabled; item.Visible = display.Visible; object helper = m_mediator.PropertyTable.GetValue("ContextHelper"); if (helper != null) item.Tooltip =((IContextHelper)helper).GetToolTip(choice.HelpId); else item.Tooltip = item.Text.Replace("&",""); //useful for buttons. choice.ReferenceWidget = item; return item; }