-//\r
-// ToolStripItemCollection.cs\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-// Copyright (c) 2006 Jonathan Pobst\r
-//\r
-// Authors:\r
-// Jonathan Pobst (monkey@jpobst.com)\r
-//\r
-#if NET_2_0\r
-\r
-using System.Drawing;\r
-using System.Collections;\r
-using System.Windows.Forms.Layout;\r
-\r
-namespace System.Windows.Forms\r
-{\r
- public class ToolStripItemCollection : ArrangedElementCollection, IList, ICollection, IEnumerable\r
- {\r
- private ToolStrip owner;\r
-\r
- #region Public Constructor\r
- public ToolStripItemCollection (ToolStrip owner, ToolStripItem[] value) : base ()\r
- {\r
- if (owner == null)\r
- throw new ArgumentNullException ("owner");\r
-\r
- this.owner = owner;\r
-\r
- if (value != null)\r
- foreach (ToolStripItem tsi in value)\r
- this.Add (tsi);\r
- }\r
- #endregion\r
-\r
- #region Public Properties\r
- public override bool IsReadOnly { get { return base.IsReadOnly; } }\r
- \r
- public virtual ToolStripItem this[int index] { get { return (ToolStripItem)base[index]; } }\r
- \r
- public virtual ToolStripItem this[string key] {\r
- get {\r
- foreach (ToolStripItem tsi in this)\r
- if (tsi.Name == key)\r
- return tsi;\r
-\r
- return null;\r
- }\r
- }\r
- #endregion\r
-\r
- #region Public Methods\r
- public ToolStripItem Add (Image image)\r
- {\r
- ToolStripButton tsb = new ToolStripButton (image);\r
- this.Add (tsb);\r
- return tsb;\r
- }\r
-\r
- public ToolStripItem Add (string text)\r
- {\r
- ToolStripButton tsb = new ToolStripButton (text);\r
- this.Add (tsb);\r
- return tsb;\r
- }\r
-\r
- public int Add (ToolStripItem value)\r
- {\r
- if (value == null)\r
- throw new ArgumentNullException ("value");\r
-\r
- value.Owner = owner;\r
- value.Parent = owner;\r
- owner.PerformLayout ();\r
- owner.OnItemAdded (new ToolStripItemEventArgs (value));\r
- return base.Add (value);\r
- }\r
-\r
- public ToolStripItem Add (string text, Image image)\r
- {\r
- ToolStripButton tsb = new ToolStripButton (text, image);\r
- this.Add (tsb);\r
- return tsb;\r
- }\r
-\r
- public ToolStripItem Add (string text, Image image, EventHandler onClick)\r
- {\r
- ToolStripButton tsb = new ToolStripButton (text, image, onClick);\r
- this.Add (tsb);\r
- return tsb;\r
- }\r
-\r
- public void AddRange (ToolStripItem[] toolStripItems)\r
- {\r
- if (toolStripItems == null)\r
- throw new ArgumentNullException ("toolStripItems");\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- this.owner.SuspendLayout ();\r
-\r
- foreach (ToolStripItem tsi in toolStripItems)\r
- this.Add (tsi);\r
-\r
- this.owner.ResumeLayout ();\r
- }\r
-\r
- public void AddRange (ToolStripItemCollection toolStripItems)\r
- {\r
- if (toolStripItems == null)\r
- throw new ArgumentNullException ("toolStripItems");\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- this.owner.SuspendLayout ();\r
-\r
- foreach (ToolStripItem tsi in toolStripItems)\r
- this.Add (tsi);\r
-\r
- this.owner.ResumeLayout ();\r
- }\r
-\r
- public virtual void Clear ()\r
- {\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- base.Clear ();\r
- owner.PerformLayout ();\r
- }\r
-\r
- public bool Contains (ToolStripItem value)\r
- {\r
- return base.Contains (value);\r
- }\r
-\r
- public virtual bool ContainsKey (string key)\r
- {\r
- return this[key] != null;\r
- }\r
-\r
- public void CopyTo (ToolStripItem[] array, int index)\r
- {\r
- base.CopyTo (array, index);\r
- }\r
-\r
- [MonoTODO ()]\r
- public ToolStripItem[] Find (string key, bool searchAllChildren)\r
- {\r
- if (key == null)\r
- throw new ArgumentNullException ("key");\r
-\r
- ArrayList al = new ArrayList ();\r
-\r
- foreach (ToolStripItem tsi in this) {\r
- if (tsi.Name == key) {\r
- al.Add (tsi);\r
-\r
- if (searchAllChildren) {\r
- // TODO: tsi does not have an items property yet..\r
- }\r
- }\r
- }\r
-\r
- return (ToolStripItem[])al.ToArray ();\r
- }\r
-\r
- public int IndexOf (ToolStripItem value)\r
- {\r
- return base.IndexOf (value);\r
- }\r
-\r
- public virtual int IndexOfKey (string key)\r
- {\r
- ToolStripItem tsi = this[key];\r
-\r
- if (tsi == null)\r
- return -1;\r
-\r
- return this.IndexOf (tsi);\r
- }\r
-\r
- public void Insert (int index, ToolStripItem value)\r
- {\r
- if (value == null)\r
- throw new ArgumentNullException ("value");\r
-\r
- base.Insert (index, value);\r
- owner.OnItemAdded (new ToolStripItemEventArgs (value));\r
- owner.PerformLayout ();\r
- }\r
-\r
- public void Remove (ToolStripItem value)\r
- {\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- base.Remove (value);\r
- owner.OnItemRemoved (new ToolStripItemEventArgs (value));\r
- owner.PerformLayout ();\r
- }\r
-\r
- public void RemoveAt (int index)\r
- {\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- ToolStripItem tsi = (ToolStripItem)base[index];\r
- base.RemoveAt (index);\r
- owner.OnItemRemoved (new ToolStripItemEventArgs (tsi));\r
- owner.PerformLayout ();\r
- }\r
-\r
- public virtual void RemoveByKey (string key)\r
- {\r
- if (this.IsReadOnly)\r
- throw new NotSupportedException ("This collection is read-only");\r
-\r
- ToolStripItem tsi = this[key];\r
-\r
- if (tsi != null)\r
- this.Remove (tsi);\r
-\r
- return;\r
- }\r
- #endregion\r
-\r
- #region IList Members\r
- int IList.Add (object value)\r
- {\r
- return this.Add ((ToolStripItem)value);\r
- }\r
-\r
- void IList.Clear ()\r
- {\r
- this.Clear ();\r
- }\r
-\r
- bool IList.Contains (object value)\r
- {\r
- return this.Contains ((ToolStripItem)value);\r
- }\r
-\r
- int IList.IndexOf (object value)\r
- {\r
- return this.IndexOf ((ToolStripItem)value);\r
- }\r
-\r
- void IList.Insert (int index, object value)\r
- {\r
- this.Insert (index, (ToolStripItem)value);\r
- }\r
-\r
- bool IList.IsFixedSize {\r
- get { return this.IsFixedSize; }\r
- }\r
-\r
- bool IList.IsReadOnly {\r
- get { return this.IsReadOnly; }\r
- }\r
-\r
- void IList.Remove (object value)\r
- {\r
- this.Remove ((ToolStripItem)value); ;\r
- }\r
-\r
- void IList.RemoveAt (int index)\r
- {\r
- this.RemoveAt (index);\r
- }\r
-\r
- object IList.this[int index] {\r
- get { return this[index]; }\r
- set { throw new NotSupportedException (); }\r
- }\r
- #endregion\r
- }\r
-}\r
-#endif
\ No newline at end of file
+//
+// ToolStripItemCollection.cs
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2006 Jonathan Pobst
+//
+// Authors:
+// Jonathan Pobst (monkey@jpobst.com)
+//
+#if NET_2_0
+
+using System.Drawing;
+using System.Collections;
+using System.Windows.Forms.Layout;
+
+namespace System.Windows.Forms
+{
+ public class ToolStripItemCollection : ArrangedElementCollection, IList, ICollection, IEnumerable
+ {
+ private ToolStrip owner;
+
+ #region Public Constructor
+ public ToolStripItemCollection (ToolStrip owner, ToolStripItem[] value) : base ()
+ {
+ if (owner == null)
+ throw new ArgumentNullException ("owner");
+
+ this.owner = owner;
+
+ if (value != null)
+ foreach (ToolStripItem tsi in value)
+ this.Add (tsi);
+ }
+ #endregion
+
+ #region Public Properties
+ public override bool IsReadOnly { get { return base.IsReadOnly; } }
+
+ public new virtual ToolStripItem this[int index] { get { return (ToolStripItem)base[index]; } }
+
+ public virtual ToolStripItem this[string key] {
+ get {
+ foreach (ToolStripItem tsi in this)
+ if (tsi.Name == key)
+ return tsi;
+
+ return null;
+ }
+ }
+ #endregion
+
+ #region Public Methods
+ public ToolStripItem Add (Image image)
+ {
+ ToolStripItem tsb = owner.CreateDefaultItem (string.Empty, image, null);
+ this.Add (tsb);
+ return tsb;
+ }
+
+ public ToolStripItem Add (string text)
+ {
+ ToolStripItem tsb = owner.CreateDefaultItem (text, null, null);
+ this.Add (tsb);
+ return tsb;
+ }
+
+ public int Add (ToolStripItem value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ value.Owner = owner;
+ value.Parent = owner;
+
+ int index = base.Add (value);
+
+ owner.PerformLayout ();
+ owner.OnItemAdded (new ToolStripItemEventArgs (value));
+ return index;
+ }
+
+ public ToolStripItem Add (string text, Image image)
+ {
+ ToolStripItem tsb = owner.CreateDefaultItem (text, image, null);
+ this.Add (tsb);
+ return tsb;
+ }
+
+ public ToolStripItem Add (string text, Image image, EventHandler onClick)
+ {
+ ToolStripItem tsb = owner.CreateDefaultItem (text, image, onClick);
+ this.Add (tsb);
+ return tsb;
+ }
+
+ public void AddRange (ToolStripItem[] toolStripItems)
+ {
+ if (toolStripItems == null)
+ throw new ArgumentNullException ("toolStripItems");
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ this.owner.SuspendLayout ();
+
+ foreach (ToolStripItem tsi in toolStripItems)
+ this.Add (tsi);
+
+ this.owner.ResumeLayout ();
+ }
+
+ public void AddRange (ToolStripItemCollection toolStripItems)
+ {
+ if (toolStripItems == null)
+ throw new ArgumentNullException ("toolStripItems");
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ this.owner.SuspendLayout ();
+
+ foreach (ToolStripItem tsi in toolStripItems)
+ this.Add (tsi);
+
+ this.owner.ResumeLayout ();
+ }
+
+ public new virtual void Clear ()
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ base.Clear ();
+ owner.PerformLayout ();
+ }
+
+ public bool Contains (ToolStripItem value)
+ {
+ return base.Contains (value);
+ }
+
+ public virtual bool ContainsKey (string key)
+ {
+ return this[key] != null;
+ }
+
+ public void CopyTo (ToolStripItem[] array, int index)
+ {
+ base.CopyTo (array, index);
+ }
+
+ [MonoTODO ()]
+ public ToolStripItem[] Find (string key, bool searchAllChildren)
+ {
+ if (key == null)
+ throw new ArgumentNullException ("key");
+
+ ArrayList al = new ArrayList ();
+
+ foreach (ToolStripItem tsi in this) {
+ if (tsi.Name == key) {
+ al.Add (tsi);
+
+ if (searchAllChildren) {
+ // TODO: tsi does not have an items property yet..
+ }
+ }
+ }
+
+ return (ToolStripItem[])al.ToArray ();
+ }
+
+ public int IndexOf (ToolStripItem value)
+ {
+ return base.IndexOf (value);
+ }
+
+ public virtual int IndexOfKey (string key)
+ {
+ ToolStripItem tsi = this[key];
+
+ if (tsi == null)
+ return -1;
+
+ return this.IndexOf (tsi);
+ }
+
+ public void Insert (int index, ToolStripItem value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ base.Insert (index, value);
+ owner.OnItemAdded (new ToolStripItemEventArgs (value));
+ owner.PerformLayout ();
+ }
+
+ public void Remove (ToolStripItem value)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ base.Remove (value);
+ owner.OnItemRemoved (new ToolStripItemEventArgs (value));
+ owner.PerformLayout ();
+ }
+
+ public new void RemoveAt (int index)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ ToolStripItem tsi = (ToolStripItem)base[index];
+ base.RemoveAt (index);
+ owner.OnItemRemoved (new ToolStripItemEventArgs (tsi));
+ owner.PerformLayout ();
+ }
+
+ public virtual void RemoveByKey (string key)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException ("This collection is read-only");
+
+ ToolStripItem tsi = this[key];
+
+ if (tsi != null)
+ this.Remove (tsi);
+
+ return;
+ }
+ #endregion
+
+ #region IList Members
+ int IList.Add (object value)
+ {
+ return this.Add ((ToolStripItem)value);
+ }
+
+ void IList.Clear ()
+ {
+ this.Clear ();
+ }
+
+ bool IList.Contains (object value)
+ {
+ return this.Contains ((ToolStripItem)value);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ return this.IndexOf ((ToolStripItem)value);
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ this.Insert (index, (ToolStripItem)value);
+ }
+
+ bool IList.IsFixedSize {
+ get { return this.IsFixedSize; }
+ }
+
+ bool IList.IsReadOnly {
+ get { return this.IsReadOnly; }
+ }
+
+ void IList.Remove (object value)
+ {
+ this.Remove ((ToolStripItem)value); ;
+ }
+
+ void IList.RemoveAt (int index)
+ {
+ this.RemoveAt (index);
+ }
+
+ object IList.this[int index] {
+ get { return this[index]; }
+ set { throw new NotSupportedException (); }
+ }
+ #endregion
+ }
+}
+#endif