Control.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. //
  2. // System.Windows.Forms.Form
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Rachel Hestilow ([email protected])
  7. // Joel Basson ([email protected])
  8. // (C) 2002 Ximian, Inc
  9. //
  10. using System;
  11. using System.Drawing;
  12. using Gtk;
  13. using GtkSharp;
  14. using System.ComponentModel;
  15. using System.Collections;
  16. namespace System.Windows.Forms {
  17. public class Control : Component {
  18. internal Widget widget;
  19. Control parent;
  20. string text, name;
  21. Size size;
  22. int left, top, width, height, tabindex, index;
  23. ControlCollection controls;
  24. Point location = new System.Drawing.Point (0, 0);
  25. Gtk.Layout layout = null;
  26. AnchorStyles anchor = AnchorStyles.Top|AnchorStyles.Left;
  27. bool tabStop=true;
  28. static int init_me;
  29. RightToLeft rightToLeft;
  30. public class ControlCollection : IList, ICollection, IEnumerable, ICloneable
  31. {
  32. ArrayList list = new ArrayList ();
  33. Control owner;
  34. public ControlCollection (Control owner)
  35. {
  36. this.owner = owner;
  37. }
  38. private ControlCollection ()
  39. {
  40. }
  41. // ControlCollection
  42. public virtual void Add (Control value, bool doevent) {
  43. if (doevent == true) {
  44. this.Add (value);
  45. return;
  46. }
  47. list.Add(value);
  48. }
  49. public virtual void Add (Control value) {
  50. list.Add (value);
  51. owner.OnControlAdded (new ControlEventArgs (value));
  52. }
  53. public virtual void AddRange (Control[] controls) {
  54. list.AddRange (controls);
  55. foreach (Control c in controls)
  56. owner.OnControlAdded (new ControlEventArgs (c));
  57. }
  58. public bool Contains (Control value) { return list.Contains (value); }
  59. public virtual void Remove (Control value) {
  60. list.Remove (value);
  61. owner.OnControlAdded (new ControlEventArgs (value));
  62. }
  63. public virtual Control this[int index] { get { return (Control) list[index]; } }
  64. public int GetChildIndex (Control child) {
  65. return GetChildIndex (child, true);
  66. }
  67. public int GetChildIndex (Control child, bool throwException) {
  68. if (throwException && !Contains (child))
  69. throw new Exception ();
  70. return list.IndexOf (child);
  71. }
  72. public int IndexOf (Control value) { return list.IndexOf (value); }
  73. public void SetChildIndex (Control child, int newIndex) {
  74. int oldIndex = GetChildIndex (child);
  75. if (oldIndex == newIndex)
  76. return;
  77. // is this correct behavior?
  78. Control other = (Control) list[newIndex];
  79. list[oldIndex] = other;
  80. list[newIndex] = child;
  81. }
  82. // IList
  83. public bool IsFixedSize { get { return list.IsFixedSize; } }
  84. public bool IsReadOnly { get { return list.IsReadOnly; } }
  85. int IList.Add (object value) { return list.Add (value); }
  86. public void Clear () { list.Clear (); }
  87. bool IList.Contains (object value) { return list.Contains (value); }
  88. int IList.IndexOf (object value) { return list.IndexOf (value); }
  89. void IList.Insert (int index, object value) { list.Insert (index, value); }
  90. void IList.Remove (object value) { list.Remove (value); }
  91. public void RemoveAt (int index) { list.RemoveAt (index); }
  92. // ICollection
  93. public int Count { get { return list.Count; } }
  94. public bool IsSynchronized { get { return list.IsSynchronized; } }
  95. public object SyncRoot { get { return list.SyncRoot; } }
  96. public void CopyTo (Array array, int index) { list.CopyTo (array, index); }
  97. // IEnumerable
  98. public IEnumerator GetEnumerator () { return list.GetEnumerator (); }
  99. // ICloneable
  100. public object Clone () {
  101. ControlCollection c = new ControlCollection ();
  102. c.list = (ArrayList) list.Clone ();
  103. c.owner = owner;
  104. return c;
  105. }
  106. object IList.this[int index]
  107. {
  108. get { return list[index]; }
  109. set { list[index] = value; }
  110. }
  111. }
  112. static Control ()
  113. {
  114. init_me = 1;
  115. }
  116. public Control () : this ("")
  117. {
  118. }
  119. public Control (string text) : this (null, text)
  120. {
  121. }
  122. public Control (Control parent, string text)
  123. {
  124. this.parent = parent;
  125. this.text = text;
  126. }
  127. public Control (string text, int left, int top, int width, int height)
  128. {
  129. }
  130. public Control (Control parent, string text, int left, int top, int width, int height)
  131. {
  132. }
  133. internal Widget Widget {
  134. get {
  135. if (widget == null)
  136. widget = CreateWidget ();
  137. return widget;
  138. }
  139. }
  140. internal virtual Widget CreateWidget ()
  141. {
  142. layout = new Gtk.Layout (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
  143. layout.Show ();
  144. return layout;
  145. }
  146. public virtual string Text {
  147. get {
  148. return text;
  149. }
  150. set {
  151. text = value;
  152. OnTextChanged (EventArgs.Empty);
  153. }
  154. }
  155. public event EventHandler TextChanged;
  156. protected virtual void OnTextChanged (EventArgs e) {
  157. if (TextChanged != null)
  158. TextChanged (this, e);
  159. }
  160. public virtual string Name {
  161. get {
  162. return name;
  163. }
  164. set {
  165. name = value;
  166. Widget.Name = value;
  167. }
  168. }
  169. public bool Enabled {
  170. get {
  171. return Widget.Sensitive;
  172. }
  173. set {
  174. Widget.Sensitive = value;
  175. }
  176. }
  177. public Size Size {
  178. get {
  179. return size;
  180. }
  181. set {
  182. size = value;
  183. Widget.SetSizeRequest (value.Width,value.Height);
  184. }
  185. }
  186. public int TabIndex {
  187. get {
  188. return tabindex;
  189. }
  190. set {
  191. tabindex = value;
  192. }
  193. }
  194. public int Index {
  195. get {
  196. return index;
  197. }
  198. set {
  199. index = value;
  200. }
  201. }
  202. public void Show ()
  203. {
  204. Widget.Show ();
  205. }
  206. public void Hide ()
  207. {
  208. Widget.Hide ();
  209. }
  210. public bool Visible {
  211. get {
  212. return Widget.Visible;
  213. }
  214. set {
  215. Widget.Visible = value;
  216. }
  217. }
  218. public ControlCollection Controls {
  219. get { if (controls == null) controls = new ControlCollection (this); return controls;}
  220. }
  221. public event ControlEventHandler ControlAdded;
  222. public event ControlEventHandler ControlRemoved;
  223. internal void ControlLocationChanged (object o, EventArgs e)
  224. {
  225. Control c = (Control) o;
  226. Point l = c.Location;
  227. if (layout == null) {
  228. Widget w = Widget;
  229. }
  230. layout.Move (c.Widget, l.X, l.Y);
  231. }
  232. protected virtual void OnControlAdded(ControlEventArgs e) {
  233. e.Control.Visible = true;
  234. if (ControlAdded != null)
  235. ControlAdded (this, e);
  236. Point l = e.Control.Location;
  237. if (layout == null) {
  238. Widget w = Widget;
  239. }
  240. layout.Put (e.Control.Widget, l.X, l.Y);
  241. e.Control.LocationChanged += new EventHandler (ControlLocationChanged);
  242. }
  243. protected virtual void OnControlRemoved(ControlEventArgs e) {
  244. if (ControlRemoved != null)
  245. ControlRemoved (this, e);
  246. }
  247. public Point Location {
  248. get { return location; }
  249. set {
  250. location = value;
  251. OnLocationChanged (EventArgs.Empty);
  252. }
  253. }
  254. public event EventHandler LocationChanged;
  255. public virtual void OnLocationChanged (EventArgs e) {
  256. if (LocationChanged != null)
  257. LocationChanged (this, e);
  258. }
  259. public event EventHandler Click;
  260. protected virtual void OnClick (EventArgs e) {
  261. if (Click != null)
  262. Click (this, e);
  263. }
  264. public virtual AnchorStyles Anchor {
  265. get { return anchor; }
  266. set { anchor=value; }
  267. }
  268. [MonoTODO]
  269. protected virtual void OnEnabledChanged(EventArgs e)
  270. {
  271. throw new NotImplementedException();
  272. }
  273. [MonoTODO]
  274. protected virtual void OnHandleCreated(EventArgs e)
  275. {
  276. throw new NotImplementedException();
  277. }
  278. [MonoTODO]
  279. public virtual Color ForeColor {
  280. get {
  281. throw new NotImplementedException();
  282. }
  283. set {
  284. throw new NotImplementedException();
  285. }
  286. }
  287. [MonoTODO]
  288. public virtual System.Drawing.Image BackgroundImage {
  289. get {
  290. throw new NotImplementedException();
  291. }
  292. set {
  293. throw new NotImplementedException();
  294. }
  295. }
  296. [MonoTODO]
  297. public virtual Color BackColor {
  298. get {
  299. throw new NotImplementedException();
  300. }
  301. set {
  302. throw new NotImplementedException();
  303. }
  304. }
  305. public bool TabStop {
  306. get {
  307. return tabStop;
  308. }
  309. set {
  310. tabStop = value;
  311. }
  312. }
  313. [MonoTODO]
  314. public virtual RightToLeft RightToLeft {
  315. get {
  316. return rightToLeft;
  317. }
  318. set {
  319. rightToLeft = value;
  320. }
  321. }
  322. }
  323. }