Control.cs 8.4 KB

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