CommandBarItemCollection.cs :  » Game » RealmForge » System » Windows » Forms » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » System » Windows » Forms » CommandBarItemCollection.cs
// ---------------------------------------------------------
// Windows Forms CommandBar Control
// Copyright (C) 2001-2003 Lutz Roeder. All rights reserved.
// http://www.aisto.com/roeder
// roeder@aisto.com
// ---------------------------------------------------------
namespace System.Windows.Forms{
  using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Drawing;
  using System.Globalization;
  using System.Windows.Forms;

  public class CommandBarItemCollection : ICollection
  {
    private CommandBar commandBar;
    private ArrayList items;

    internal CommandBarItemCollection()
    {
      this.commandBar = null;
      this.items = new ArrayList();
    }

    internal CommandBarItemCollection(CommandBar commandBar)
    {
      this.commandBar = commandBar;
      this.items = new ArrayList();
    }

    public IEnumerator GetEnumerator()
    {
      return this.items.GetEnumerator();    
    }

    public int Count
    {
      get { return this.items.Count; } 
    }

    public void Clear()
    {
      while (this.Count > 0)
      {
        this.RemoveAt(0);
      }
    }

    public void Add(CommandBarItem item)
    {
      this.items.Add(item);

      if (this.commandBar != null)
      {
        this.commandBar.AddItem(item);
      }
    }

    public void AddSeparator()
    {
      this.Add(new CommandBarSeparator());
    }

    public CommandBarMenu AddMenu(string text)
    {
      CommandBarMenu menu = new CommandBarMenu(text);
      this.Add(menu);
      return menu;  
    }

    public CommandBarMenu AddMenu(Image image, string text)
    {
      CommandBarMenu menu = this.AddMenu(text);
      menu.Image = image;
      return menu;
    }

    public CommandBarMenu AddMenu(string text, EventHandler dropDownHandler)
    {
      CommandBarMenu menu = this.AddMenu(text);
      menu.DropDown += dropDownHandler;
      return menu;
    }

    public CommandBarMenu AddMenu(Image image, string text, EventHandler dropDownHandler)
    {
      CommandBarMenu menu = this.AddMenu(text);
      menu.Image = image;
      menu.DropDown += dropDownHandler;
      return menu;
    }

    public CommandBarButton AddButton(string text, EventHandler clickHandler)
    {
      CommandBarButton button = new CommandBarButton(text);
      button.Click += clickHandler;
      this.Add(button);
      return button;
    }

    public CommandBarButton AddButton(string text, EventHandler clickHandler, Keys shortcut)
    {
      CommandBarButton button = this.AddButton(text, clickHandler);
      button.Shortcut = shortcut;
      return button;
    }

    public CommandBarButton AddButton(Image image, string text, EventHandler clickHandler)
    {
      CommandBarButton button = this.AddButton(text, clickHandler);
      button.Image = image;
      return button;
    }

    public CommandBarButton AddButton(Image image, string text, EventHandler clickHandler, Keys shortcut)
    {
      CommandBarButton button = this.AddButton(text, clickHandler, shortcut);
      button.Image = image;
      return button;
    }

    public CommandBarCheckBox AddCheckBox(string text)
    {
      CommandBarCheckBox checkBox = new CommandBarCheckBox(text);
      this.Add(checkBox);
      return checkBox;
    }

    public CommandBarCheckBox AddCheckBox(string text, Keys shortcut)
    {
      CommandBarCheckBox checkBox = this.AddCheckBox(text);
      checkBox.Shortcut = shortcut;
      return checkBox;
    }

    public CommandBarCheckBox AddCheckBox(Image image, string text, Keys shortcut)
    {
      CommandBarCheckBox checkBox = this.AddCheckBox(text, shortcut);
      checkBox.Image = image;
      return checkBox;
    }

    public CommandBarCheckBox AddCheckBox(Image image, string text)
    {
      CommandBarCheckBox checkBox = this.AddCheckBox(text);
      checkBox.Image = image;
      return checkBox;
    }

    public CommandBarComboBox AddComboBox(string text, ComboBox comboBox)
    {
      CommandBarComboBox item = new CommandBarComboBox(text, comboBox);
      this.Add(item);
      return item;
    }

    public void AddRange(ICollection items)
    {
      foreach (CommandBarItem item in items)
      {
        this.items.Add(item);

        if (this.commandBar != null)
        {
          this.commandBar.AddItem(item);
        }
      }
    }

    public void Insert(int index, CommandBarItem item)
    {
      items.Insert(index, item);

      if (this.commandBar != null)
      {
        this.commandBar.AddItem(item);
      }
    }

    public void RemoveAt(int index)
    {
      CommandBarItem item = (CommandBarItem) this.items[index];
      items.RemoveAt(index);

      if (this.commandBar != null)
      {
        this.commandBar.RemoveItem(item);
      }
    }

    public void Remove(CommandBarItem item)
    {
      if (this.items.Contains(item))
      {
        this.items.Remove(item);

        if (this.commandBar != null)
        {
          this.commandBar.RemoveItem(item);
        }
      }
    }

    public bool Contains(CommandBarItem item)
    {
      return this.items.Contains(item);
    }

    public int IndexOf(CommandBarItem item)
    {
      return this.items.IndexOf(item);
    }

    public CommandBarItem this[int index]
    {
      get { return (CommandBarItem)items[index]; }
    }

    public object SyncRoot
    {
      get { throw new NotSupportedException(); }  
    }

    public bool IsSynchronized
    {
      get { return false; }  
    }

    public void CopyTo(Array array, int index)
    {
      this.items.CopyTo(array, index);  
    }

    public void CopyTo(CommandBarItem[] array, int index)
    {
      this.items.CopyTo(array, index);  
    }

    // TODO 
    internal CommandBarItem[] this[Keys shortcut]
    {
      get
      {
        ArrayList list = new ArrayList();

        foreach (CommandBarItem item in items)
        {
          CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
          if (buttonBase != null)
          {
            if ((buttonBase.Shortcut == shortcut) && (buttonBase.IsEnabled) && (buttonBase.IsVisible))
            {
              list.Add(buttonBase);
            }
          }
        }

        foreach (CommandBarItem item in items)
        {
          CommandBarMenu menu = item as CommandBarMenu;
          if (menu != null)
          {
            list.AddRange(menu.Items[shortcut]);
          }
        }

        CommandBarItem[] array = new CommandBarItem[list.Count];
        list.CopyTo(array, 0);
        return array;
      }
    }

    // TODO Only used in CommandBar.PreProcessMnemonic
    internal CommandBarItem[] this[char mnemonic]
    {
      get
      {
        ArrayList list = new ArrayList();

        foreach (CommandBarItem item in items)
        {
          if ((item.IsVisible) && (item.IsEnabled))
          {
            string text = item.Text;
            for (int i = 0; i < text.Length; i++)
            {
              if ((text[i] == '&') && (i + 1 < text.Length) && (text[i + 1] != '&'))
              {
                if (mnemonic == Char.ToUpper(text[i + 1], CultureInfo.InvariantCulture))
                {
                  list.Add(item);
                }
              }
            }
          }
        }

        CommandBarItem[] array = new CommandBarItem[list.Count];
        list.CopyTo(array, 0);
        return array;
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.