2 // System.Windows.Forms.Form
5 // Miguel de Icaza (miguel@ximian.com)
6 // Rachel Hestilow (hestilow@ximian.com)
7 // Joel Basson (jstrike@mweb.co.za)
8 // Philip Van Hoof (me@freax.org)
9 // (C) 2002 Ximian, Inc
16 using System.ComponentModel;
17 using System.Collections;
19 namespace System.Windows.Forms {
20 public class Control : Component {
21 internal Widget widget;
25 int left, top, width, height, tabindex, index;
26 ControlCollection controls;
27 Point location = new System.Drawing.Point (0, 0);
28 Gtk.Layout layout = null;
29 AnchorStyles anchor = AnchorStyles.Top|AnchorStyles.Left;
32 RightToLeft rightToLeft;
34 public class ControlCollection : IList, ICollection, IEnumerable, ICloneable
36 ArrayList list = new ArrayList ();
39 public ControlCollection (Control owner)
44 private ControlCollection ()
49 public virtual void Add (Control value, bool doevent) {
50 if (doevent == true) {
56 public virtual void Add (Control value) {
58 owner.OnControlAdded (new ControlEventArgs (value));
60 public virtual void AddRange (Control[] controls) {
61 list.AddRange (controls);
62 foreach (Control c in controls)
63 owner.OnControlAdded (new ControlEventArgs (c));
66 public bool Contains (Control value) { return list.Contains (value); }
67 public virtual void Remove (Control value) {
69 owner.OnControlAdded (new ControlEventArgs (value));
71 public virtual Control this[int index] { get { return (Control) list[index]; } }
72 public int GetChildIndex (Control child) {
73 return GetChildIndex (child, true);
75 public int GetChildIndex (Control child, bool throwException) {
76 if (throwException && !Contains (child))
77 throw new Exception ();
78 return list.IndexOf (child);
80 public int IndexOf (Control value) { return list.IndexOf (value); }
81 public void SetChildIndex (Control child, int newIndex) {
82 int oldIndex = GetChildIndex (child);
83 if (oldIndex == newIndex)
85 // is this correct behavior?
86 Control other = (Control) list[newIndex];
87 list[oldIndex] = other;
88 list[newIndex] = child;
92 public bool IsFixedSize { get { return list.IsFixedSize; } }
93 public bool IsReadOnly { get { return list.IsReadOnly; } }
94 int IList.Add (object value) { return list.Add (value); }
95 public void Clear () { list.Clear (); }
96 bool IList.Contains (object value) { return list.Contains (value); }
97 int IList.IndexOf (object value) { return list.IndexOf (value); }
98 void IList.Insert (int index, object value) { list.Insert (index, value); }
99 void IList.Remove (object value) { list.Remove (value); }
100 public void RemoveAt (int index) { list.RemoveAt (index); }
103 public int Count { get { return list.Count; } }
104 public bool IsSynchronized { get { return list.IsSynchronized; } }
105 public object SyncRoot { get { return list.SyncRoot; } }
106 public void CopyTo (Array array, int index) { list.CopyTo (array, index); }
109 public IEnumerator GetEnumerator () { return list.GetEnumerator (); }
112 public object Clone () {
113 ControlCollection c = new ControlCollection ();
114 c.list = (ArrayList) list.Clone ();
119 object IList.this[int index]
121 get { return list[index]; }
122 set { list[index] = value; }
129 Gtk.Application.Init ();
133 public Control () : this ("")
138 public Control (string text) : this (null, text)
142 public Control (Control parent, string text)
144 this.parent = parent;
149 public Control (string text, int left, int top, int width, int height)
153 public Control (Control parent, string text, int left, int top, int width, int height)
158 internal Widget Widget {
161 widget = CreateWidget ();
166 internal virtual Widget CreateWidget ()
168 layout = new Gtk.Layout (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
173 public virtual string Text {
180 OnTextChanged (EventArgs.Empty);
184 public event EventHandler TextChanged;
186 protected virtual void OnTextChanged (EventArgs e) {
187 if (TextChanged != null)
188 TextChanged (this, e);
192 public virtual string Name {
203 public bool Enabled {
205 return Widget.Sensitive;
208 Widget.Sensitive = value;
218 Widget.SetSizeRequest (value.Width,value.Height);
222 public int TabIndex {
250 public bool Visible {
252 return Widget.Visible;
256 Widget.Visible = value;
261 public ControlCollection Controls {
262 get { if (controls == null) controls = new ControlCollection (this); return controls;}
265 public event ControlEventHandler ControlAdded;
266 public event ControlEventHandler ControlRemoved;
268 internal void ControlLocationChanged (object o, EventArgs e)
270 Control c = (Control) o;
271 Point l = c.Location;
272 if (layout == null) {
276 layout.Move (c.Widget, l.X, l.Y);
279 protected virtual void OnControlAdded(ControlEventArgs e) {
280 e.Control.Visible = true;
282 if (ControlAdded != null)
283 ControlAdded (this, e);
285 Point l = e.Control.Location;
286 if (layout == null) {
289 layout.Put (e.Control.Widget, l.X, l.Y);
290 e.Control.LocationChanged += new EventHandler (ControlLocationChanged);
293 protected virtual void OnControlRemoved(ControlEventArgs e) {
294 if (ControlRemoved != null)
295 ControlRemoved (this, e);
299 public Point Location {
300 get { return location; }
303 OnLocationChanged (EventArgs.Empty);
307 public event EventHandler LocationChanged;
309 public virtual void OnLocationChanged (EventArgs e) {
311 if (LocationChanged != null)
312 LocationChanged (this, e);
315 public event EventHandler Click;
317 protected virtual void OnClick (EventArgs e) {
322 public virtual AnchorStyles Anchor {
323 get { return anchor; }
324 set { anchor=value; }
328 protected virtual void OnEnabledChanged(EventArgs e)
330 throw new NotImplementedException();
334 protected virtual void OnHandleCreated(EventArgs e)
336 throw new NotImplementedException();
340 public virtual Color ForeColor {
342 throw new NotImplementedException();
345 this.widget.ModifyFg (Gtk.StateType.Normal, new Gdk.Color (value));
350 public virtual System.Drawing.Image BackgroundImage {
352 throw new NotImplementedException();
355 throw new NotImplementedException();
360 public virtual Color BackColor {
362 throw new NotImplementedException();
365 this.widget.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (value));
369 public bool TabStop {
379 public virtual RightToLeft RightToLeft {
389 protected virtual void OnLayout(LayoutEventArgs e)
395 protected virtual void OnMouseDown(MouseEventArgs e)
400 protected virtual void OnResize(EventArgs e)
405 protected virtual void OnHandleDestroyed(EventArgs e)
410 public virtual Font Font {
412 get { throw new NotImplementedException(); }
413 set { throw new NotImplementedException(); }
416 protected virtual Size DefaultSize {
417 get { return new Size ( 100, 100 ); }