2 // System.Windows.Forms.Form
5 // Miguel de Icaza (miguel@ximian.com)
6 // Rachel Hestilow (hestilow@ximian.com)
8 // (C) 2002 Ximian, Inc
15 using System.ComponentModel;
16 using System.Collections;
18 namespace System.Windows.Forms {
19 public class Control : Component {
20 internal Widget widget;
23 int left, top, width, height;
24 ControlCollection controls = CreateControlsInstance ();
25 Point location = new Point (0, 0);
26 Gtk.Layout layout = null;
27 AnchorStyles anchor = AnchorStyles.Top|AnchorStyles.Left;
31 public class ControlCollection : IList, ICollection, IEnumerable, ICloneable
33 ArrayList list = new ArrayList ();
36 public ControlCollection (Control owner)
41 private ControlCollection ()
46 public virtual void Add (Control value) {
48 owner.OnControlAdded (new ControlEventArgs (value));
50 public virtual void AddRange (Control[] controls) {
51 list.AddRange (controls);
52 foreach (Control c in controls)
53 owner.OnControlAdded (new ControlEventArgs (c));
56 public bool Contains (Control value) { return list.Contains (value); }
57 public int IndexOf (Control value) { return list.IndexOf (value); }
58 public virtual void Remove (Control value) {
60 owner.OnControlAdded (new ControlEventArgs (value));
62 public virtual Control this[int index] { get { return (Control) list[index]; } }
63 public int GetChildIndex (Control child) {
64 return GetChildIndex (child, true);
66 public int GetChildIndex (Control child, bool throwException) {
67 if (throwException && !Contains (child))
68 throw new Exception ();
69 return list.IndexOf (child);
71 public int IndexOf (Control value) { return list.IndexOf (value); }
72 public void SetChildIndex (Control child, int newIndex) {
73 int oldIndex = GetChildIndex (child);
74 if (oldIndex == newIndex)
76 // is this correct behavior?
77 Control other = (Control) list[newIndex];
78 list[oldIndex] = other;
79 list[newIndex] = child;
83 public bool IsFixedSize { get { return list.IsFixedSize; } }
84 public bool IsReadOnly { get { return list.IsReadOnly; } }
85 public object this[int index]
87 get { return list[index]; }
88 set { list[index] = value; }
90 int IList.Add (object value) { return list.Add (value); }
91 public void Clear () { list.Clear (); }
92 bool IList.Contains (object value) { return list.Contains (value); }
93 int IList.IndexOf (object value) { return list.IndexOf (value); }
94 void IList.Insert (int index, object value) { list.Insert (index, value); }
95 void IList.Remove (object value) { list.Remove (value); }
96 public void RemoveAt (int index) { list.RemoveAt (index); }
99 public int Count { get { return list.Count; } }
100 public bool IsSynchronized { get { return list.IsSynchronized; } }
101 public object SyncRoot { get { return list.SyncRoot; } }
102 public void CopyTo (Array array, int index) { list.CopyTo (array, index); }
105 public IEnumerator GetEnumerator () { return list.GetEnumerator (); }
108 public object Clone () {
109 ControlCollection c = new ControlCollection ();
110 c.list = (ArrayList) list.Clone ();
121 public Control () : this ("")
125 public Control (string text) : this (null, text)
129 public Control (Control parent, string text)
131 this.parent = parent;
135 public Control (string text, int left, int top, int width, int height)
139 public Control (Control parent, string text, int left, int top, int width, int height)
143 internal Widget Widget {
146 widget = CreateWidget ();
151 internal virtual Widget CreateWidget ()
153 layout = new Gtk.Layout (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
158 public virtual string Text {
165 OnTextChanged (EventArgs.Empty);
169 public event EventHandler TextChanged;
171 protected virtual void OnTextChanged (EventArgs e) {
172 if (TextChanged != null)
173 TextChanged (this, e);
186 public bool Visible {
188 return Widget.Visible;
192 Widget.Visible = value;
196 public ControlCollection Controls {
197 get { return controls;}
200 protected virtual ControlCollection CreateControlsInstance() {
201 controls = new ControlCollection (this);
205 public event ControlEventHandler ControlAdded;
206 public event ControlEventHandler ControlRemoved;
208 internal void ControlLocationChanged (object o, EventArgs e)
210 Control c = (Control) o;
211 Point l = c.Location;
212 if (layout == null) {
216 layout.Move (c.Widget, l.X, l.Y);
219 protected virtual void OnControlAdded(ControlEventArgs e) {
220 e.Control.Visible = true;
222 if (ControlAdded != null)
223 ControlAdded (this, e);
225 Point l = e.Control.Location;
226 if (layout == null) {
229 layout.Put (e.Control.Widget, l.X, l.Y);
230 e.Control.LocationChanged += new EventHandler (ControlLocationChanged);
233 protected virtual void OnControlRemoved(ControlEventArgs e) {
234 if (ControlRemoved != null)
235 ControlRemoved (this, e);
238 public Point Location {
239 get { return location; }
242 OnLocationChanged (EventArgs.Empty);
246 public event EventHandler LocationChanged;
248 public virtual void OnLocationChanged (EventArgs e) {
250 if (LocationChanged != null)
251 LocationChanged (this, e);
254 public event EventHandler Click;
256 protected virtual void OnClick (EventArgs e) {
261 public virtual AnchorStyles Anchor {
262 get { return anchor; }
263 set { anchor=value; }