Control.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. // Based on work by:
  26. // Aleksey Ryabchuk [email protected]
  27. // Alexandre Pigolkine [email protected]
  28. // Dennis Hayes [email protected]
  29. // Jaak Simm [email protected]
  30. // John Sohn [email protected]
  31. //
  32. // $Revision: 1.20 $
  33. // $Modtime: $
  34. // $Log: Control.cs,v $
  35. // Revision 1.20 2004/08/11 15:13:32 pbartok
  36. // - Now properly reparents windows
  37. //
  38. // Revision 1.19 2004/08/11 14:37:11 pbartok
  39. // - Duh!
  40. //
  41. // Revision 1.18 2004/08/11 13:47:22 pbartok
  42. // - Rewrote the collection stuff. Might not be as fast now, not keeping
  43. // the number of children around and accessible directly, but it's more
  44. // straightforward
  45. //
  46. // Revision 1.17 2004/08/10 18:32:10 jordi
  47. // throw ontextchange event
  48. //
  49. // Revision 1.16 2004/08/10 17:43:04 pbartok
  50. // - Added more to the still unfinished Dock/Anchor layout code
  51. //
  52. // Revision 1.15 2004/08/10 15:08:05 jackson
  53. // Control will now handle the buffering code, so each control does not have to implement this.
  54. //
  55. // Revision 1.14 2004/08/09 22:11:25 pbartok
  56. // - Added incomplete dock layout code
  57. // - Added support for mouse wheel
  58. //
  59. // Revision 1.13 2004/08/09 17:25:56 jackson
  60. // Use new color names
  61. //
  62. // Revision 1.12 2004/08/09 15:54:51 jackson
  63. // Get default properties from the theme.
  64. //
  65. // Revision 1.11 2004/08/06 21:30:56 pbartok
  66. // - Fixed recursive loop when resizing
  67. // - Improved/fixed redrawing on expose messages
  68. //
  69. // Revision 1.10 2004/08/06 15:53:39 jordi
  70. // X11 keyboard navigation
  71. //
  72. // Revision 1.9 2004/08/04 21:14:26 pbartok
  73. // - Fixed Invalidation bug (calculated wrong client area)
  74. // - Added ClientSize setter
  75. //
  76. // Revision 1.8 2004/08/04 20:11:24 pbartok
  77. // - Added Invalidate handling
  78. //
  79. // Revision 1.7 2004/07/27 10:38:17 jordi
  80. // changes to be able to run winforms samples
  81. //
  82. // Revision 1.6 2004/07/19 19:09:42 jordi
  83. // label control re-written: added missing functionlity, events, and properties
  84. //
  85. // Revision 1.5 2004/07/19 16:49:23 jordi
  86. // fixes SetBounds logic
  87. //
  88. // Revision 1.4 2004/07/19 07:29:35 jordi
  89. // Call RefreshWindow only if the window has created
  90. //
  91. // Revision 1.3 2004/07/15 17:03:35 jordi
  92. // added basic mouse handeling events
  93. //
  94. // Revision 1.2 2004/07/13 15:31:45 jordi
  95. // commit: new properties and fixes form size problems
  96. //
  97. // Revision 1.1 2004/07/09 05:21:25 pbartok
  98. // - Initial check-in
  99. //
  100. //
  101. // NOT COMPLETE
  102. using System;
  103. using System.Drawing;
  104. using System.ComponentModel;
  105. using System.Collections;
  106. using System.Diagnostics;
  107. using System.Threading;
  108. using System.Runtime.InteropServices;
  109. namespace System.Windows.Forms
  110. {
  111. public class Control : Component, ISynchronizeInvoke, IWin32Window
  112. {
  113. #region Local Variables
  114. // Basic
  115. internal Rectangle bounds; // bounding rectangle for control
  116. internal object creator_thread; // thread that created the control
  117. internal ControlNativeWindow window; // object for native window handle
  118. internal string name; // for object naming
  119. // State
  120. internal bool has_focus; // true if control has focus
  121. internal bool is_visible; // true if control is visible
  122. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  123. internal int tab_index; // position in tab order of siblings
  124. internal bool is_disposed; // has the window already been disposed?
  125. internal Size window_size; // size of the window (including decorations)
  126. internal Size client_size; // size of the client area (window excluding decorations)
  127. internal ControlStyles control_style; // win32-specific, style bits for control
  128. // Visuals
  129. internal Color foreground_color; // foreground color for control
  130. internal Color background_color; // background color for control
  131. internal Image background_image; // background image for control
  132. internal Font font; // font for control
  133. internal string text; // window/title text for control
  134. // Layout
  135. internal AnchorStyles anchor_style; // anchoring requirements for our control
  136. internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
  137. internal int prev_width; // previous width of the control; required for anchoring
  138. internal int prev_height; // previous height of our control; required for anchoring
  139. internal Size prev_size;
  140. // to be categorized...
  141. static internal Hashtable controls; // All of the applications controls, in a flat list
  142. internal ControlCollection child_controls; // our children
  143. internal Control parent; // our parent control
  144. internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
  145. internal BindingContext binding_context; // TODO
  146. internal RightToLeft right_to_left; // drawing direction for control
  147. internal int layout_suspended;
  148. private Graphics dc_mem;
  149. private Bitmap bmp_mem;
  150. #endregion // Local Variables
  151. #region Private Classes
  152. // This helper class allows us to dispatch messages to Control.WndProc
  153. internal class ControlNativeWindow : NativeWindow {
  154. private Control control;
  155. public ControlNativeWindow(Control control) : base() {
  156. this.control=control;
  157. }
  158. protected override void WndProc(ref Message m) {
  159. control.WndProc(ref m);
  160. }
  161. }
  162. #endregion
  163. #region Public Classes
  164. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  165. #region ControlCollection Local Variables
  166. private ArrayList list;
  167. private Control owner;
  168. #endregion // ControlCollection Local Variables
  169. #region ControlCollection Public Constructor
  170. public ControlCollection(Control owner) {
  171. this.owner=owner;
  172. this.list=new ArrayList();
  173. }
  174. #endregion
  175. #region ControlCollection Public Instance Properties
  176. public int Count {
  177. get {
  178. return list.Count;
  179. }
  180. }
  181. public bool IsReadOnly {
  182. get {
  183. return list.IsReadOnly;
  184. }
  185. }
  186. public virtual Control this[int index] {
  187. get {
  188. if (index < 0 || index >= list.Count) {
  189. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  190. }
  191. return (Control)list[index];
  192. }
  193. }
  194. #endregion // ControlCollection Public Instance Properties
  195. #region ControlCollection Private Instance Methods
  196. public virtual void Add(Control value) {
  197. for (int i=0; i<list.Count; i++) {
  198. if (list[i]==value) {
  199. // Do we need to do anything here?
  200. return;
  201. }
  202. }
  203. list.Add(value);
  204. value.Parent=owner;
  205. }
  206. public virtual void AddRange(Control[] controls) {
  207. for (int i=0; i<controls.Length; i++) {
  208. Add(controls[i]);
  209. }
  210. }
  211. public virtual void Clear() {
  212. owner.SuspendLayout();
  213. list.Clear();
  214. owner.ResumeLayout();
  215. }
  216. public virtual bool Contains(Control value) {
  217. return list.Contains(value);
  218. }
  219. public void CopyTo(Array array, int index) {
  220. list.CopyTo(array, index);
  221. }
  222. public override bool Equals(object other) {
  223. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  224. return(true);
  225. } else {
  226. return(false);
  227. }
  228. }
  229. public int GetChildIndex(Control child) {
  230. return GetChildIndex(child, false);
  231. }
  232. public int GetChildIndex(Control child, bool throwException) {
  233. int index;
  234. index=list.IndexOf(child);
  235. if (index==-1 && throwException) {
  236. throw new ArgumentException("Not a child control", "child");
  237. }
  238. return index;
  239. }
  240. public IEnumerator GetEnumerator() {
  241. return list.GetEnumerator();
  242. }
  243. public override int GetHashCode() {
  244. return base.GetHashCode();
  245. }
  246. public int IndexOf(Control control) {
  247. return list.IndexOf(control);
  248. }
  249. public virtual void Remove(Control value) {
  250. list.Remove(value);
  251. }
  252. public void RemoveAt(int index) {
  253. if (index<0 || index>=list.Count) {
  254. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  255. }
  256. list.RemoveAt(index);
  257. }
  258. public void SetChildIndex(Control child, int newIndex) {
  259. int old_index;
  260. old_index=list.IndexOf(child);
  261. if (old_index==-1) {
  262. throw new ArgumentException("Not a child control", "child");
  263. }
  264. if (old_index==newIndex) {
  265. return;
  266. }
  267. RemoveAt(old_index);
  268. if (newIndex>list.Count) {
  269. list.Add(child);
  270. } else {
  271. list.Insert(newIndex, child);
  272. }
  273. }
  274. #endregion // ControlCollection Private Instance Methods
  275. #region ControlCollection Interface Properties
  276. object IList.this[int index] {
  277. get {
  278. if (index<0 || index>=list.Count) {
  279. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  280. }
  281. return this[index];
  282. }
  283. set {
  284. if (!(value is Control)) {
  285. throw new ArgumentException("Object of type Control required", "value");
  286. }
  287. list[index]=(Control)value;
  288. }
  289. }
  290. bool IList.IsFixedSize {
  291. get {
  292. return false;
  293. }
  294. }
  295. bool IList.IsReadOnly {
  296. get {
  297. return list.IsReadOnly;
  298. }
  299. }
  300. bool ICollection.IsSynchronized {
  301. get {
  302. return list.IsSynchronized;
  303. }
  304. }
  305. object ICollection.SyncRoot {
  306. get {
  307. return list.SyncRoot;
  308. }
  309. }
  310. #endregion // ControlCollection Interface Properties
  311. #region ControlCollection Interface Methods
  312. int IList.Add(object value) {
  313. if (value == null) {
  314. throw new ArgumentNullException("value", "Cannot add null controls");
  315. }
  316. if (!(value is Control)) {
  317. throw new ArgumentException("Object of type Control required", "value");
  318. }
  319. return list.Add(value);
  320. }
  321. bool IList.Contains(object value) {
  322. if (!(value is Control)) {
  323. throw new ArgumentException("Object of type Control required", "value");
  324. }
  325. return this.Contains((Control) value);
  326. }
  327. int IList.IndexOf(object value) {
  328. if (!(value is Control)) {
  329. throw new ArgumentException("Object of type Control required", "value");
  330. }
  331. return this.IndexOf((Control) value);
  332. }
  333. void IList.Insert(int index, object value) {
  334. if (!(value is Control)) {
  335. throw new ArgumentException("Object of type Control required", "value");
  336. }
  337. list.Insert(index, value);
  338. }
  339. void IList.Remove(object value) {
  340. if (!(value is Control)) {
  341. throw new ArgumentException("Object of type Control required", "value");
  342. }
  343. list.Remove(value);
  344. }
  345. void ICollection.CopyTo(Array array, int index) {
  346. if (list.Count>0) {
  347. list.CopyTo(array, index);
  348. }
  349. }
  350. Object ICloneable.Clone() {
  351. ControlCollection clone = new ControlCollection(this.owner);
  352. clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
  353. return clone;
  354. }
  355. #endregion // ControlCollection Interface Methods
  356. }
  357. #endregion // ControlCollection Class
  358. #region Public Constructors
  359. public Control() {
  360. creator_thread = Thread.CurrentThread;
  361. controls = new Hashtable();
  362. child_controls = CreateControlsInstance();
  363. bounds = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  364. window_size = new Size(DefaultSize.Width, DefaultSize.Height);
  365. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  366. prev_size = client_size;
  367. is_visible = true;
  368. is_disposed = false;
  369. is_enabled = true;
  370. has_focus = false;
  371. layout_suspended = 0;
  372. parent = null;
  373. background_image = null;
  374. }
  375. public Control(Control parent, string text) : this() {
  376. Text=text;
  377. Parent=parent;
  378. }
  379. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  380. Parent=parent;
  381. Left=left;
  382. Top=top;
  383. Width=width;
  384. Height=height;
  385. Text=text;
  386. }
  387. public Control(string text) : this() {
  388. Text=text;
  389. }
  390. public Control(string text, int left, int top, int width, int height) : this() {
  391. Left=left;
  392. Top=top;
  393. Width=width;
  394. Height=height;
  395. Text=text;
  396. }
  397. #endregion // Public Constructors
  398. #region Public Static Properties
  399. public static Color DefaultBackColor {
  400. get {
  401. return ThemeEngine.Current.DefaultControlBackColor;
  402. }
  403. }
  404. public static Font DefaultFont {
  405. get {
  406. return ThemeEngine.Current.DefaultFont;
  407. }
  408. }
  409. public static Color DefaultForeColor {
  410. get {
  411. return ThemeEngine.Current.DefaultControlForeColor;
  412. }
  413. }
  414. public static Keys ModifierKeys {
  415. get {
  416. return XplatUI.State.ModifierKeys;
  417. }
  418. }
  419. public static MouseButtons MouseButtons {
  420. get {
  421. return XplatUI.State.MouseButtons;
  422. }
  423. }
  424. public static Point MousePosition {
  425. get {
  426. return XplatUI.State.MousePosition;
  427. }
  428. }
  429. #endregion // Public Static Properties
  430. #region Public Instance Properties
  431. public AccessibleObject AccessibilityObject {
  432. get {
  433. if (accessibility_object==null) {
  434. accessibility_object=CreateAccessibilityInstance();
  435. }
  436. return accessibility_object;
  437. }
  438. }
  439. public string AccessibleDefaultActionDescription {
  440. get {
  441. return AccessibilityObject.default_action;
  442. }
  443. set {
  444. AccessibilityObject.default_action=value;
  445. }
  446. }
  447. public string AccessibleDescription {
  448. get {
  449. return AccessibilityObject.description;
  450. }
  451. set {
  452. AccessibilityObject.description=value;
  453. }
  454. }
  455. public string AccessibleName {
  456. get {
  457. return AccessibilityObject.Name;
  458. }
  459. set {
  460. AccessibilityObject.Name=value;
  461. }
  462. }
  463. public AccessibleRole AccessibleRole {
  464. get {
  465. return AccessibilityObject.role;
  466. }
  467. set {
  468. AccessibilityObject.role=value;
  469. }
  470. }
  471. public virtual bool AllowDrop {
  472. get {
  473. return XplatUI.State.DropTarget;
  474. }
  475. set {
  476. XplatUI.State.DropTarget=value;
  477. }
  478. }
  479. public virtual AnchorStyles Anchor {
  480. get {
  481. return anchor_style;
  482. }
  483. set {
  484. anchor_style=value;
  485. }
  486. }
  487. public virtual Color BackColor {
  488. get {
  489. if (background_color.IsEmpty) {
  490. if (parent!=null) {
  491. return parent.BackColor;
  492. }
  493. return DefaultBackColor;
  494. }
  495. return background_color;
  496. }
  497. set {
  498. background_color=value;
  499. Refresh();
  500. }
  501. }
  502. public virtual Image BackgroundImage {
  503. get {
  504. return background_image;
  505. }
  506. set {
  507. if (background_image!=value) {
  508. background_image=value;
  509. OnBackgroundImageChanged(EventArgs.Empty);
  510. }
  511. }
  512. }
  513. public virtual BindingContext BindingContext {
  514. get {
  515. throw new NotImplementedException();
  516. }
  517. set {
  518. throw new NotImplementedException();
  519. }
  520. }
  521. public int Bottom {
  522. get {
  523. return bounds.Y+bounds.Height;
  524. }
  525. }
  526. public Rectangle Bounds {
  527. get {
  528. return this.bounds;
  529. }
  530. set {
  531. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  532. }
  533. }
  534. public bool CanFocus {
  535. get {
  536. throw new NotImplementedException();
  537. }
  538. }
  539. public bool CanSelect {
  540. get {
  541. throw new NotImplementedException();
  542. }
  543. }
  544. public bool Capture {
  545. get {
  546. throw new NotImplementedException();
  547. }
  548. set {
  549. throw new NotImplementedException();
  550. }
  551. }
  552. public bool CausesValidation {
  553. get {
  554. throw new NotImplementedException();
  555. }
  556. set {
  557. throw new NotImplementedException();
  558. }
  559. }
  560. public Rectangle ClientRectangle {
  561. get {
  562. return new Rectangle(0, 0, client_size.Width, client_size.Height);
  563. }
  564. }
  565. public Size ClientSize {
  566. get {
  567. return client_size;
  568. }
  569. set {
  570. this.SetClientSizeCore(value.Width, value.Height);
  571. }
  572. }
  573. public String CompanyName {
  574. get {
  575. return "Mono Project, Novell, Inc.";
  576. }
  577. }
  578. public bool ContainsFocus {
  579. get {
  580. throw new NotImplementedException();
  581. }
  582. }
  583. #if notdef
  584. public virtual ContextMenu ContextMenu {
  585. get {
  586. throw new NotImplementedException();
  587. }
  588. set {
  589. throw new NotImplementedException();
  590. }
  591. }
  592. #endif
  593. public ControlCollection Controls {
  594. get {
  595. return this.child_controls;
  596. }
  597. }
  598. public bool Created {
  599. get {
  600. throw new NotImplementedException();
  601. }
  602. }
  603. #if notdef
  604. public virtual Cursor Cursor {
  605. get {
  606. throw new NotImplementedException();
  607. }
  608. set {
  609. throw new NotImplementedException();
  610. }
  611. }
  612. public ControlBidingsCollection DataBindings {
  613. get {
  614. throw new NotImplementedException();
  615. }
  616. }
  617. #endif
  618. public virtual Rectangle DisplayRectangle {
  619. get {
  620. return ClientRectangle;
  621. }
  622. }
  623. public bool Disposing {
  624. get {
  625. throw new NotImplementedException();
  626. }
  627. }
  628. public virtual DockStyle Dock {
  629. get { return dock_style;}
  630. set {
  631. if (dock_style == value)
  632. return;
  633. dock_style = value;
  634. OnDockChanged(EventArgs.Empty);
  635. }
  636. }
  637. public bool Enabled {
  638. get {
  639. return is_enabled;
  640. }
  641. set {
  642. is_enabled = value;
  643. }
  644. }
  645. public virtual bool Focused {
  646. get {
  647. return this.has_focus;
  648. }
  649. set {
  650. throw new NotImplementedException();
  651. }
  652. }
  653. public virtual Font Font {
  654. get {
  655. if (font != null) {
  656. return font;
  657. }
  658. if (Parent != null && Parent.Font != null) {
  659. return Parent.Font;
  660. }
  661. return DefaultFont;
  662. }
  663. set {
  664. font=value;
  665. Refresh();
  666. }
  667. }
  668. public virtual Color ForeColor {
  669. get {
  670. if (foreground_color.IsEmpty) {
  671. if (parent!=null) {
  672. return parent.ForeColor;
  673. }
  674. return DefaultForeColor;
  675. }
  676. return foreground_color;
  677. }
  678. set {
  679. foreground_color=value;
  680. Refresh();
  681. }
  682. }
  683. public bool IsDisposed {
  684. get {
  685. return this.is_disposed;
  686. }
  687. }
  688. public bool IsHandleCreated {
  689. get {
  690. if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
  691. return true;
  692. }
  693. return false;
  694. }
  695. }
  696. public string Name {
  697. get {
  698. return this.name;
  699. }
  700. set {
  701. this.name=value;
  702. }
  703. }
  704. public Control Parent {
  705. get {
  706. return this.parent;
  707. }
  708. set {
  709. if (parent!=value) {
  710. if (parent!=null) {
  711. parent.Controls.Remove(this);
  712. }
  713. parent=value;
  714. if (!parent.Controls.Contains(this)) {
  715. parent.Controls.Add(this);
  716. }
  717. XplatUI.SetParent(Handle, value.Handle);
  718. }
  719. }
  720. }
  721. public IntPtr Handle { // IWin32Window
  722. get
  723. {
  724. if (!IsHandleCreated) {
  725. CreateHandle();
  726. }
  727. return window.Handle;
  728. }
  729. }
  730. public bool InvokeRequired { // ISynchronizeInvoke
  731. get {
  732. if (creator_thread!=Thread.CurrentThread) {
  733. return true;
  734. }
  735. return false;
  736. }
  737. }
  738. public bool Visible {
  739. get {
  740. return this.is_visible;
  741. }
  742. set {
  743. if (value!=is_visible) {
  744. is_visible=value;
  745. XplatUI.SetVisible(Handle, value);
  746. }
  747. }
  748. }
  749. public virtual string Text {
  750. get {
  751. return this.text;
  752. }
  753. set {
  754. if (text!=value) {
  755. text=value;
  756. XplatUI.Text(Handle, text);
  757. OnTextChanged (EventArgs.Empty);
  758. }
  759. }
  760. }
  761. public int Left {
  762. get {
  763. return this.bounds.X;
  764. }
  765. set {
  766. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  767. }
  768. }
  769. public int Top {
  770. get {
  771. return this.bounds.Y;
  772. }
  773. set {
  774. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  775. }
  776. }
  777. public int Width {
  778. get {
  779. return this.bounds.Width;
  780. }
  781. set {
  782. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  783. }
  784. }
  785. public int Height {
  786. get {
  787. return this.bounds.Height;
  788. }
  789. set {
  790. SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  791. }
  792. }
  793. public Point Location {
  794. get {
  795. return new Point(bounds.X, bounds.Y);
  796. }
  797. set {
  798. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  799. }
  800. }
  801. public Size Size {
  802. get {
  803. return new Size(Width, Height);
  804. }
  805. set {
  806. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  807. }
  808. }
  809. public int TabIndex {
  810. get {
  811. return tab_index;
  812. }
  813. set {
  814. tab_index = value;
  815. }
  816. }
  817. #endregion // Public Instance Properties
  818. internal Graphics DeviceContext {
  819. get { return dc_mem; }
  820. }
  821. internal Bitmap ImageBuffer {
  822. get { return bmp_mem; }
  823. }
  824. internal void CreateBuffers (int width, int height)
  825. {
  826. if (dc_mem != null)
  827. dc_mem.Dispose ();
  828. if (bmp_mem != null)
  829. bmp_mem.Dispose ();
  830. bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  831. dc_mem = Graphics.FromImage (bmp_mem);
  832. }
  833. #region Protected Instance Properties
  834. protected virtual CreateParams CreateParams {
  835. get {
  836. CreateParams create_params = new CreateParams();
  837. create_params.Caption = Text;
  838. create_params.X = Left;
  839. create_params.Y = Top;
  840. create_params.Width = Width;
  841. create_params.Height = Height;
  842. create_params.ClassName = XplatUI.DefaultClassName;
  843. create_params.ClassStyle = 0;
  844. create_params.ExStyle = 0;
  845. create_params.Param = 0;
  846. if (parent!=null) {
  847. create_params.Parent = parent.Handle;
  848. }
  849. create_params.Style = (int)WindowStyles.WS_OVERLAPPED;
  850. if (is_visible) {
  851. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  852. }
  853. return create_params;
  854. }
  855. }
  856. protected virtual ImeMode DefaultImeMode {
  857. get {
  858. return ImeMode.Inherit;
  859. }
  860. }
  861. protected virtual Size DefaultSize {
  862. get {
  863. return new Size(100, 23);
  864. }
  865. }
  866. #endregion // Protected Instance Properties
  867. #region Public Instance Methods
  868. public bool Contains(Control ctl) {
  869. Control current;
  870. current=ctl;
  871. while (current!=null) {
  872. if (current==ctl) {
  873. return true;
  874. }
  875. current=current.parent;
  876. }
  877. return false;
  878. }
  879. public void CreateControl() {
  880. Control child;
  881. CreateHandle();
  882. for (int i=0; i<child_controls.Count; i++) {
  883. child_controls[i].CreateControl();
  884. }
  885. OnCreateControl();
  886. }
  887. public virtual void Refresh() {
  888. if (IsHandleCreated == true)
  889. XplatUI.RefreshWindow(window.Handle);
  890. }
  891. public void SetBounds(int x, int y, int width, int height) {
  892. SetBounds(x, y, width, height, BoundsSpecified.All);
  893. }
  894. public void SetBounds(int x, int y, int width, int height, BoundsSpecified bounds_specified) {
  895. if ((bounds_specified & BoundsSpecified.X) != BoundsSpecified.X) {
  896. x = Left;
  897. }
  898. if ((bounds_specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  899. y = Top;
  900. }
  901. if ((bounds_specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
  902. width = Width;
  903. }
  904. if ((bounds_specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  905. height = Height;
  906. }
  907. if (IsHandleCreated) {
  908. XplatUI.MoveWindow(Handle, x, y, width, height);
  909. }
  910. UpdateBounds(x, y, width, height);
  911. }
  912. public void Show() {
  913. if (!IsHandleCreated) {
  914. this.CreateHandle();
  915. }
  916. this.Visible=true;
  917. }
  918. public object Invoke(Delegate method) { // ISynchronizeInvoke
  919. return Invoke(method, null);
  920. }
  921. public object Invoke(Delegate method, object[] args) { // ISynchronizeInvoke
  922. IAsyncResult result;
  923. result=BeginInvoke(method, args);
  924. return EndInvoke(result);
  925. }
  926. public IAsyncResult BeginInvoke(Delegate method) { // ISynchronizeInvoke
  927. return BeginInvoke(method, null);
  928. }
  929. protected virtual AccessibleObject CreateAccessibilityInstance() {
  930. return new AccessibleObject(this);
  931. }
  932. protected virtual ControlCollection CreateControlsInstance() {
  933. return new ControlCollection(this);
  934. }
  935. protected void UpdateBounds() {
  936. int x;
  937. int y;
  938. int width;
  939. int height;
  940. XplatUI.GetWindowPos(this.Handle, out x, out y, out width, out height);
  941. UpdateBounds(x, y, width, height);
  942. }
  943. protected void UpdateBounds(int x, int y, int width, int height) {
  944. bool moved = false;
  945. bool resized = false;
  946. // Generate required notifications
  947. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  948. moved=true;
  949. }
  950. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  951. resized=true;
  952. }
  953. bounds.X=x;
  954. bounds.Y=y;
  955. bounds.Width=width;
  956. bounds.Height=height;
  957. #if notdef
  958. if (IsHandleCreated) {
  959. XplatUI.SetWindowPos(Handle, bounds);
  960. }
  961. #endif
  962. if (moved) {
  963. OnLocationChanged(EventArgs.Empty);
  964. }
  965. if (resized) {
  966. OnSizeChanged(EventArgs.Empty);
  967. }
  968. }
  969. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  970. UpdateBounds(x, y, width, height);
  971. }
  972. public void Invalidate() {
  973. Invalidate(new Rectangle(0, 0, bounds.Width, bounds.Height), false);
  974. }
  975. public void Invalidate(bool invalidateChildren) {
  976. Invalidate(new Rectangle(0, 0, bounds.Width, bounds.Height), invalidateChildren);
  977. }
  978. public void Invalidate(System.Drawing.Rectangle rc) {
  979. Invalidate(rc, false);
  980. }
  981. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  982. if (!IsHandleCreated || !is_visible) {
  983. return;
  984. }
  985. XplatUI.Invalidate(Handle, rc, false);
  986. if (invalidateChildren) {
  987. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  988. }
  989. }
  990. public void Invalidate(System.Drawing.Region region) {
  991. Invalidate(region, false);
  992. }
  993. [MonoTODO]
  994. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  995. throw new NotImplementedException();
  996. // FIXME - should use the GetRegionScans function of the region to invalidate each area
  997. if (invalidateChildren) {
  998. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  999. }
  1000. }
  1001. [MonoTODO("BeginInvoke() : Figure out a cross-platform way to handle this")]
  1002. public IAsyncResult BeginInvoke(Delegate method, object[] args) { // ISynchronizeInvoke
  1003. IAsyncResult result = null;
  1004. return result;
  1005. }
  1006. [MonoTODO]
  1007. public object EndInvoke(IAsyncResult async_result) { // ISynchronizeInvoke
  1008. object result = null;
  1009. return result;
  1010. }
  1011. public void PerformLayout() {
  1012. PerformLayout(null, null);
  1013. }
  1014. public void PerformLayout(Control affectedControl, string affectedProperty) {
  1015. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  1016. if (layout_suspended>0) {
  1017. return;
  1018. }
  1019. // Prevent us from getting messed up
  1020. layout_suspended++;
  1021. // Perform all Dock and Anchor calculations
  1022. try {
  1023. Control child;
  1024. AnchorStyles anchor;
  1025. Rectangle space;
  1026. space=this.DisplayRectangle;
  1027. // Deal with docking
  1028. for (int i=0; i < child_controls.Count; i++) {
  1029. child=child_controls[i];
  1030. switch (child.Dock) {
  1031. case DockStyle.None: {
  1032. // Do nothing
  1033. break;
  1034. }
  1035. case DockStyle.Left: {
  1036. child.SetBounds(space.Left, space.Y, child.Width, space.Height);
  1037. space.X+=child.Width;
  1038. space.Width-=child.Width;
  1039. break;
  1040. }
  1041. case DockStyle.Top: {
  1042. child.SetBounds(space.Left, space.Y, space.Width, child.Height);
  1043. space.Y+=child.Height;
  1044. space.Height-=child.Height;
  1045. break;
  1046. }
  1047. case DockStyle.Right: {
  1048. child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
  1049. space.Width-=child.Width;
  1050. break;
  1051. }
  1052. case DockStyle.Bottom: {
  1053. child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
  1054. space.Height-=child.Height;
  1055. break;
  1056. }
  1057. case DockStyle.Fill: {
  1058. child.SetBounds(space.Left, space.Top, space.Width, space.Height);
  1059. space.Width=0;
  1060. space.Height=0;
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. space=this.DisplayRectangle;
  1066. // Deal with anchoring
  1067. for (int i=0; i < child_controls.Count; i++) {
  1068. int left;
  1069. int top;
  1070. int width;
  1071. int height;
  1072. int diff_width;
  1073. int diff_height;
  1074. child=child_controls[i];
  1075. anchor=child.Anchor;
  1076. left=child.Left-space.Left;
  1077. top=child.Top-space.Top;
  1078. width=prev_size.Width-child.Width-child.Left;
  1079. height=prev_size.Height-child.Height-child.Top;
  1080. diff_width=space.Width-prev_size.Width;
  1081. diff_height=space.Height-prev_size.Height;
  1082. prev_size.Width=space.Width;
  1083. prev_size.Height=space.Height;
  1084. // If the control is docked we don't need to do anything
  1085. if (child.Dock != DockStyle.None) {
  1086. continue;
  1087. }
  1088. if ((anchor & AnchorStyles.Left) !=0 ) {
  1089. if ((anchor & AnchorStyles.Right) != 0) {
  1090. // Anchoring to left and right
  1091. width=width+diff_width;
  1092. } else {
  1093. ; // nothing to do
  1094. }
  1095. } else if ((anchor & AnchorStyles.Right) != 0) {
  1096. left+=diff_width;
  1097. } else {
  1098. left+=diff_width/2;
  1099. }
  1100. if ((anchor & AnchorStyles.Top) !=0 ) {
  1101. if ((anchor & AnchorStyles.Bottom) != 0) {
  1102. height+=diff_height;
  1103. } else {
  1104. ; // nothing to do
  1105. }
  1106. } else if ((anchor & AnchorStyles.Bottom) != 0) {
  1107. top+=diff_height;
  1108. } else {
  1109. top+=diff_height/2;
  1110. }
  1111. // Sanity
  1112. if (width < 0) {
  1113. width=0;
  1114. }
  1115. if (height < 0) {
  1116. height=0;
  1117. }
  1118. child.SetBounds(left, top, width, height);
  1119. }
  1120. // Let everyone know
  1121. OnLayout(levent);
  1122. }
  1123. // Need to make sure we decremend layout_suspended
  1124. finally {
  1125. layout_suspended--;
  1126. }
  1127. }
  1128. public void ResumeLayout()
  1129. {
  1130. ResumeLayout (true);
  1131. }
  1132. public void ResumeLayout(bool peformLayout)
  1133. {
  1134. layout_suspended--;
  1135. if (layout_suspended > 0 || peformLayout == false)
  1136. return;
  1137. PerformLayout();
  1138. }
  1139. public void SuspendLayout()
  1140. {
  1141. layout_suspended++;
  1142. }
  1143. [MonoTODO]
  1144. protected virtual void WndProc(ref Message m) {
  1145. EventArgs e = new EventArgs();
  1146. #if debug
  1147. Console.WriteLine("Received message {0}", m);
  1148. #endif
  1149. switch((Msg)m.Msg) {
  1150. #if notyet
  1151. // Mouse handling
  1152. case Msg.WM_LBUTTONDBLCLK: throw new NotImplementedException(); break;
  1153. case Msg.WM_RBUTTONDOWN: throw new NotImplementedException(); break;
  1154. case Msg.WM_RBUTTONUP: throw new NotImplementedException(); break;
  1155. case Msg.WM_RBUTTONDBLCLK: throw new NotImplementedException(); break;
  1156. case Msg.WM_MOUSEHOVER: throw new NotImplementedException(); break;
  1157. case Msg.WM_MOUSELEAVE: throw new NotImplementedException(); break;
  1158. // Keyboard handling
  1159. case Msg.WM_CHAR: throw new NotImplementedException(); break;
  1160. case Msg.WM_KEYDOWN: throw new NotImplementedException(); break;
  1161. case Msg.WM_KEYUP: throw new NotImplementedException(); break;
  1162. #endif
  1163. // Window management
  1164. case Msg.WM_WINDOWPOSCHANGED: {
  1165. UpdateBounds();
  1166. DefWndProc(ref m);
  1167. break;
  1168. }
  1169. case Msg.WM_PAINT: {
  1170. Rectangle rect;
  1171. PaintEventArgs paint_event;
  1172. paint_event = XplatUI.PaintEventStart(Handle);
  1173. OnPaint(paint_event);
  1174. XplatUI.PaintEventEnd(Handle);
  1175. DefWndProc(ref m);
  1176. break;
  1177. }
  1178. case Msg.WM_ERASEBKGND:{
  1179. if (GetStyle (ControlStyles.UserPaint)){
  1180. PaintEventArgs eraseEventArgs = new PaintEventArgs (Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
  1181. OnPaintBackground (eraseEventArgs);
  1182. m.Result = (IntPtr)1;
  1183. }
  1184. else {
  1185. m.Result = (IntPtr)0;
  1186. DefWndProc (ref m);
  1187. }
  1188. break;
  1189. }
  1190. case Msg.WM_LBUTTONUP: {
  1191. int clicks = 1;
  1192. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1193. clicks,
  1194. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1195. 0));
  1196. break;
  1197. }
  1198. case Msg.WM_LBUTTONDOWN: {
  1199. int clicks = 1;
  1200. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1201. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1202. 0));
  1203. break;
  1204. }
  1205. case Msg.WM_MOUSEWHEEL: {
  1206. int clicks = 1;
  1207. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1208. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1209. HighOrder(m.WParam.ToInt32())));
  1210. break;
  1211. }
  1212. case Msg.WM_MOUSEMOVE: {
  1213. int clicks = 1;
  1214. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1215. clicks,
  1216. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1217. 0));
  1218. break;
  1219. }
  1220. case Msg.WM_SIZE: {
  1221. UpdateBounds (bounds.X, bounds.Y, LowOrder ((int) m.LParam.ToInt32 ()),
  1222. HighOrder ((int) m.LParam.ToInt32 ()));
  1223. DefWndProc(ref m);
  1224. break;
  1225. }
  1226. case Msg.WM_KEYDOWN: {
  1227. if (!ProcessKeyEventArgs (ref m))
  1228. DefWndProc (ref m);
  1229. break;
  1230. }
  1231. case Msg.WM_KEYUP: {
  1232. if (!ProcessKeyEventArgs (ref m))
  1233. DefWndProc (ref m);
  1234. break;
  1235. }
  1236. #if notyet
  1237. case Msg.WM_WINDOWPOSCHANGED: throw new NotImplementedException(); break;
  1238. case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
  1239. #endif
  1240. default:
  1241. DefWndProc(ref m);
  1242. break;
  1243. }
  1244. }
  1245. #endregion // Public Instance Methods
  1246. #region // Protected Instance Methods
  1247. protected virtual void CreateHandle() {
  1248. if (IsDisposed) {
  1249. throw new ObjectDisposedException(Name);
  1250. }
  1251. if (IsHandleCreated) {
  1252. return;
  1253. }
  1254. if (window==null) {
  1255. window = new ControlNativeWindow(this);
  1256. window.CreateHandle(CreateParams);
  1257. }
  1258. if (window.Handle!=IntPtr.Zero) {
  1259. if (!controls.Contains(window.Handle)) {
  1260. controls.Add(window.Handle, this);
  1261. }
  1262. creator_thread = Thread.CurrentThread;
  1263. OnHandleCreated(EventArgs.Empty);
  1264. }
  1265. }
  1266. protected virtual void DefWndProc(ref Message m) {
  1267. window.DefWndProc(ref m);
  1268. }
  1269. protected virtual void DestroyHandle() {
  1270. if (IsHandleCreated) {
  1271. if (Handle != IntPtr.Zero) {
  1272. controls.Remove(Handle);
  1273. }
  1274. if (window != null) {
  1275. window.DestroyHandle();
  1276. }
  1277. }
  1278. }
  1279. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  1280. {
  1281. KeyEventArgs key_event;
  1282. switch (msg.Msg) {
  1283. case (int)Msg.WM_KEYDOWN: {
  1284. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1285. OnKeyDown (key_event);
  1286. return key_event.Handled;
  1287. }
  1288. case (int)Msg.WM_KEYUP: {
  1289. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1290. OnKeyUp (key_event);
  1291. return key_event.Handled;
  1292. }
  1293. default:
  1294. break;
  1295. }
  1296. return false;
  1297. }
  1298. protected virtual bool IsInputKey (Keys keyData)
  1299. {
  1300. return false;
  1301. }
  1302. protected virtual bool ProcessDialogKey (Keys keyData)
  1303. {
  1304. if (parent != null)
  1305. return Parent.ProcessDialogKey (keyData);
  1306. return false;
  1307. }
  1308. protected bool GetStyle(ControlStyles flag) {
  1309. return (control_style & flag) != 0;
  1310. }
  1311. protected virtual bool ProcessDialogChar(char charCode) {
  1312. throw new NotImplementedException();
  1313. }
  1314. protected virtual bool ProcessMnemonic(char charCode) {
  1315. throw new NotImplementedException();
  1316. }
  1317. protected void RecreateHandle() {
  1318. IEnumerator child = child_controls.GetEnumerator();
  1319. if (IsHandleCreated) {
  1320. DestroyHandle();
  1321. CreateHandle();
  1322. // FIXME ZOrder?
  1323. while (child.MoveNext()) {
  1324. ((Control)child.Current).RecreateHandle();
  1325. }
  1326. }
  1327. }
  1328. protected virtual void ScaleCore(float dx, float dy) {
  1329. throw new NotImplementedException();
  1330. }
  1331. protected virtual void Select(bool directed, bool forward) {
  1332. throw new NotImplementedException();
  1333. }
  1334. protected virtual void SetClientSizeCore(int x, int y) {
  1335. bounds.Width=x;
  1336. bounds.Height=y;
  1337. XplatUI.MoveWindow(Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
  1338. }
  1339. protected void SetStyle(ControlStyles flag, bool value) {
  1340. if (value) {
  1341. control_style |= flag;
  1342. } else {
  1343. control_style &= ~flag;
  1344. }
  1345. }
  1346. #endregion // Public Instance Methods
  1347. #region Private Instance Methods
  1348. #endregion // Private Instance Methods
  1349. #region Private Instance Methods
  1350. internal virtual void DoDefaultAction() {
  1351. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1352. }
  1353. #endregion // Private Instance Methods
  1354. #region OnXXX methods
  1355. protected virtual void OnBackColorChanged(EventArgs e) {
  1356. if (BackColorChanged!=null) BackColorChanged(this, e);
  1357. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  1358. }
  1359. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  1360. if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
  1361. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  1362. }
  1363. protected virtual void OnBindingContextChanged(EventArgs e) {
  1364. if (BindingContextChanged!=null) BindingContextChanged(this, e);
  1365. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  1366. }
  1367. protected virtual void OnCausesValidationChanged(EventArgs e) {
  1368. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1369. }
  1370. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  1371. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1372. }
  1373. protected virtual void OnClick(EventArgs e) {
  1374. if (Click!=null) Click(this, e);
  1375. }
  1376. protected virtual void OnContextMenuChanged(EventArgs e) {
  1377. if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
  1378. }
  1379. protected virtual void OnControlAdded(ControlEventArgs e) {
  1380. if (ControlAdded!=null) ControlAdded(this, e);
  1381. }
  1382. protected virtual void OnControlRemoved(ControlEventArgs e) {
  1383. if (ControlRemoved!=null) ControlRemoved(this, e);
  1384. }
  1385. protected virtual void OnCreateControl() {
  1386. }
  1387. protected virtual void OnCursorChanged(EventArgs e) {
  1388. if (CursorChanged!=null) CursorChanged(this, e);
  1389. }
  1390. protected virtual void OnDockChanged(EventArgs e) {
  1391. if (DockChanged!=null) DockChanged(this, e);
  1392. }
  1393. protected virtual void OnDoubleClick(EventArgs e) {
  1394. if (DoubleClick!=null) DoubleClick(this, e);
  1395. }
  1396. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  1397. if (DragDrop!=null) DragDrop(this, drgevent);
  1398. }
  1399. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  1400. if (DragEnter!=null) DragEnter(this, drgevent);
  1401. }
  1402. protected virtual void OnDragLeave(EventArgs e) {
  1403. if (DragLeave!=null) DragLeave(this, e);
  1404. }
  1405. protected virtual void OnDragOver(DragEventArgs drgevent) {
  1406. if (DragOver!=null) DragOver(this, drgevent);
  1407. }
  1408. protected virtual void OnEnabledChanged(EventArgs e) {
  1409. if (EnabledChanged!=null) EnabledChanged(this, e);
  1410. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
  1411. }
  1412. protected virtual void OnEnter(EventArgs e) {
  1413. if (Enter!=null) Enter(this, e);
  1414. }
  1415. protected virtual void OnFontChanged(EventArgs e) {
  1416. if (FontChanged!=null) FontChanged(this, e);
  1417. }
  1418. protected virtual void OnForeColorChanged(EventArgs e) {
  1419. if (ForeColorChanged!=null) ForeColorChanged(this, e);
  1420. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  1421. }
  1422. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  1423. if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
  1424. }
  1425. protected virtual void OnGotFocus(EventArgs e) {
  1426. if (GotFocus!=null) GotFocus(this, e);
  1427. }
  1428. protected virtual void OnHandleCreated(EventArgs e) {
  1429. if (HandleCreated!=null) HandleCreated(this, e);
  1430. }
  1431. protected virtual void OnHandleDestroyed(EventArgs e) {
  1432. if (HandleDestroyed!=null) HandleDestroyed(this, e);
  1433. }
  1434. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  1435. if (HelpRequested!=null) HelpRequested(this, hevent);
  1436. }
  1437. protected virtual void OnImeModeChanged(EventArgs e) {
  1438. if (ImeModeChanged!=null) ImeModeChanged(this, e);
  1439. }
  1440. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  1441. if (Invalidated!=null) Invalidated(this, e);
  1442. }
  1443. protected virtual void OnKeyDown(KeyEventArgs e) {
  1444. if (KeyDown!=null) KeyDown(this, e);
  1445. }
  1446. protected virtual void OnKeyUp(KeyEventArgs e) {
  1447. if (KeyUp!=null) KeyUp(this, e);
  1448. }
  1449. protected virtual void OnLayout(LayoutEventArgs levent) {
  1450. if (Layout!=null) Layout(this, levent);
  1451. }
  1452. protected virtual void OnLeave(EventArgs e) {
  1453. if (Leave!=null) Leave(this, e);
  1454. }
  1455. protected virtual void OnLocationChanged(EventArgs e) {
  1456. if (LocationChanged!=null) LocationChanged(this, e);
  1457. }
  1458. protected virtual void OnLostFocus(EventArgs e) {
  1459. if (LostFocus!=null) LostFocus(this, e);
  1460. }
  1461. protected virtual void OnMouseDown(MouseEventArgs e) {
  1462. if (MouseDown!=null) MouseDown(this, e);
  1463. }
  1464. protected virtual void OnMouseEnter(EventArgs e) {
  1465. if (MouseEnter!=null) MouseEnter(this, e);
  1466. }
  1467. protected virtual void OnMouseHover(EventArgs e) {
  1468. if (MouseHover!=null) MouseHover(this, e);
  1469. }
  1470. protected virtual void OnMouseLeave(EventArgs e) {
  1471. if (MouseLeave!=null) MouseLeave(this, e);
  1472. }
  1473. protected virtual void OnMouseMove(MouseEventArgs e) {
  1474. if (MouseMove!=null) MouseMove(this, e);
  1475. }
  1476. protected virtual void OnMouseUp(MouseEventArgs e) {
  1477. if (MouseUp!=null) MouseUp(this, e);
  1478. }
  1479. protected virtual void OnMouseWheel(MouseEventArgs e) {
  1480. if (MouseWheel!=null) MouseWheel(this, e);
  1481. }
  1482. protected virtual void OnMove(EventArgs e) {
  1483. if (Move!=null) Move(this, e);
  1484. }
  1485. protected virtual void OnNotifyMessage(Message m) {
  1486. // Override me!
  1487. }
  1488. protected virtual void OnPaint(PaintEventArgs e) {
  1489. if (Paint!=null) Paint(this, e);
  1490. }
  1491. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  1492. // Override me!
  1493. }
  1494. protected virtual void OnParentBackColorChanged(EventArgs e) {
  1495. if (background_color.IsEmpty && background_image==null) {
  1496. Invalidate();
  1497. OnBackColorChanged(e);
  1498. }
  1499. }
  1500. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  1501. if (background_color.IsEmpty && background_image==null) {
  1502. Invalidate();
  1503. OnBackgroundImageChanged(e);
  1504. }
  1505. }
  1506. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  1507. if (binding_context==null) {
  1508. binding_context=Parent.binding_context;
  1509. OnBindingContextChanged(e);
  1510. }
  1511. }
  1512. protected virtual void OnParentChanged(EventArgs e) {
  1513. if (ParentChanged!=null) ParentChanged(this, e);
  1514. }
  1515. protected virtual void OnParentEnabledChanged(EventArgs e) {
  1516. if ((is_enabled && !Parent.is_enabled) || (!is_enabled && Parent.is_enabled)) {
  1517. is_enabled=false;
  1518. Invalidate();
  1519. EnabledChanged(this, e);
  1520. }
  1521. }
  1522. protected virtual void OnParentFontChanged(EventArgs e) {
  1523. if (font==null) {
  1524. Invalidate();
  1525. OnFontChanged(e);
  1526. }
  1527. }
  1528. protected virtual void OnParentForeColorChanged(EventArgs e) {
  1529. if (foreground_color.IsEmpty) {
  1530. Invalidate();
  1531. OnForeColorChanged(e);
  1532. }
  1533. }
  1534. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  1535. if (right_to_left==RightToLeft.Inherit) {
  1536. Invalidate();
  1537. OnRightToLeftChanged(e);
  1538. }
  1539. }
  1540. protected virtual void OnParentVisibleChanged(EventArgs e) {
  1541. if (is_visible!=Parent.is_visible) {
  1542. is_visible=false;
  1543. Invalidate();
  1544. OnVisibleChanged(e);
  1545. }
  1546. }
  1547. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  1548. if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
  1549. }
  1550. protected virtual void OnResize(EventArgs e) {
  1551. if (Resize!=null) Resize(this, e);
  1552. PerformLayout();
  1553. }
  1554. protected virtual void OnRightToLeftChanged(EventArgs e) {
  1555. if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
  1556. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  1557. }
  1558. protected virtual void OnSizeChanged(EventArgs e) {
  1559. OnResize(e);
  1560. if (SizeChanged!=null) SizeChanged(this, e);
  1561. }
  1562. protected virtual void OnStyleChanged(EventArgs e) {
  1563. if (StyleChanged!=null) StyleChanged(this, e);
  1564. }
  1565. protected virtual void OnSystemColorsChanged(EventArgs e) {
  1566. if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
  1567. }
  1568. protected virtual void OnTabIndexChanged(EventArgs e) {
  1569. if (TabIndexChanged!=null) TabIndexChanged(this, e);
  1570. }
  1571. protected virtual void OnTabStopChanged(EventArgs e) {
  1572. if (TabStopChanged!=null) TabStopChanged(this, e);
  1573. }
  1574. protected virtual void OnTextChanged(EventArgs e) {
  1575. if (TextChanged!=null) TextChanged(this, e);
  1576. }
  1577. protected virtual void OnValidated(EventArgs e) {
  1578. if (Validated!=null) Validated(this, e);
  1579. }
  1580. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  1581. if (Validating!=null) Validating(this, e);
  1582. }
  1583. protected virtual void OnVisibleChanged(EventArgs e) {
  1584. if (VisibleChanged!=null) VisibleChanged(this, e);
  1585. }
  1586. #endregion // OnXXX methods
  1587. #region Events
  1588. public event EventHandler BackColorChanged;
  1589. public event EventHandler BackgroundImageChanged;
  1590. public event EventHandler BindingContextChanged;
  1591. public event EventHandler CausesValidationChanged;
  1592. public event UICuesEventHandler ChangeUICues;
  1593. public event EventHandler Click;
  1594. public event EventHandler ContextMenuChanged;
  1595. public event ControlEventHandler ControlAdded;
  1596. public event ControlEventHandler ControlRemoved;
  1597. public event EventHandler CursorChanged;
  1598. public event EventHandler DockChanged;
  1599. public event EventHandler DoubleClick;
  1600. public event DragEventHandler DragDrop;
  1601. public event DragEventHandler DragEnter;
  1602. public event EventHandler DragLeave;
  1603. public event DragEventHandler DragOver;
  1604. public event EventHandler EnabledChanged;
  1605. public event EventHandler Enter;
  1606. public event EventHandler FontChanged;
  1607. public event EventHandler ForeColorChanged;
  1608. public event GiveFeedbackEventHandler GiveFeedback;
  1609. public event EventHandler GotFocus;
  1610. public event EventHandler HandleCreated;
  1611. public event EventHandler HandleDestroyed;
  1612. public event HelpEventHandler HelpRequested;
  1613. public event EventHandler ImeModeChanged;
  1614. public event InvalidateEventHandler Invalidated;
  1615. public event KeyEventHandler KeyDown;
  1616. public event KeyPressEventHandler KeyPress;
  1617. public event KeyEventHandler KeyUp;
  1618. public event LayoutEventHandler Layout;
  1619. public event EventHandler Leave;
  1620. public event EventHandler LocationChanged;
  1621. public event EventHandler LostFocus;
  1622. public event MouseEventHandler MouseDown;
  1623. public event EventHandler MouseEnter;
  1624. public event EventHandler MouseHover;
  1625. public event EventHandler MouseLeave;
  1626. public event MouseEventHandler MouseMove;
  1627. public event MouseEventHandler MouseUp;
  1628. public event MouseEventHandler MouseWheel;
  1629. public event EventHandler Move;
  1630. public event PaintEventHandler Paint;
  1631. public event EventHandler ParentChanged;
  1632. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
  1633. public event QueryContinueDragEventHandler QueryContinueDrag;
  1634. public event EventHandler Resize;
  1635. public event EventHandler RightToLeftChanged;
  1636. public event EventHandler SizeChanged;
  1637. public event EventHandler StyleChanged;
  1638. public event EventHandler SystemColorsChanged;
  1639. public event EventHandler TabIndexChanged;
  1640. public event EventHandler TabStopChanged;
  1641. public event EventHandler TextChanged;
  1642. public event EventHandler Validated;
  1643. public event CancelEventHandler Validating;
  1644. public event EventHandler VisibleChanged;
  1645. #endregion // Events
  1646. #region Private Methods
  1647. internal static int LowOrder (int param)
  1648. {
  1649. return (param & 0xffff);
  1650. }
  1651. internal static int HighOrder (int param)
  1652. {
  1653. return (param >> 16);
  1654. }
  1655. internal static MouseButtons FromParamToMouseButtons (int param)
  1656. {
  1657. MouseButtons buttons = MouseButtons.None;
  1658. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  1659. buttons |= MouseButtons.Left;
  1660. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  1661. buttons |= MouseButtons.Middle;
  1662. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  1663. buttons |= MouseButtons.Right;
  1664. return buttons;
  1665. }
  1666. #endregion
  1667. }
  1668. }