Control.cs 49 KB

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