Control.cs 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  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.60 $
  33. // $Modtime: $
  34. // $Log: Control.cs,v $
  35. // Revision 1.60 2004/09/10 22:54:52 pbartok
  36. // - Implemented remaining missing public instance properties
  37. // - Alphabetized some out of order properties
  38. //
  39. // Revision 1.59 2004/09/06 12:55:07 jordi
  40. // Caches ClientRectangle rectangle value
  41. //
  42. // Revision 1.58 2004/09/02 22:24:50 pbartok
  43. // - Added sanity check to creation of double buffer bitmap
  44. //
  45. // Revision 1.57 2004/09/02 20:26:21 pbartok
  46. // - Added missing Control.ControlAccessibleObject class
  47. // - Started to implement Select()ion mechanisms, still very incomplete
  48. //
  49. // Revision 1.56 2004/09/01 13:19:19 jordi
  50. // Init string variables with an empty object
  51. //
  52. // Revision 1.55 2004/09/01 10:20:57 jordi
  53. // fires OnFontChanged event
  54. //
  55. // Revision 1.54 2004/09/01 01:41:31 pbartok
  56. // - Added firing of BackColorChanged event
  57. // - Added TopLevelControl property
  58. // - Fixed handling of WM_ERASEBKGRND message
  59. //
  60. // Revision 1.53 2004/08/27 20:17:25 pbartok
  61. // - Removed unneeded stack vars
  62. // - First attempt to fix sizing issues when layout is suspended
  63. //
  64. // Revision 1.52 2004/08/25 19:20:47 pbartok
  65. // - Control now properly passes the ambient background color to child
  66. // controls
  67. //
  68. // Revision 1.51 2004/08/25 18:32:15 pbartok
  69. // - Fixed generation of MouseUp message
  70. //
  71. // Revision 1.50 2004/08/24 18:24:25 jordi
  72. // fire OnEnabledChanged event
  73. //
  74. // Revision 1.49 2004/08/23 21:22:53 pbartok
  75. // - Added InitLayout() method
  76. // - Added code to properly perform layout when Anchor or Dock property is
  77. // changed
  78. // - Changed 'interpretation' of ResumeLayout. MS seems to have a LAMESPEC,
  79. // tried to do it in a way that makes sense
  80. //
  81. // Revision 1.48 2004/08/23 19:55:08 pbartok
  82. // - Properly fixed Jordi's last fix
  83. // - Now uses Cursor's Position property instead of calling XplatUI directly
  84. //
  85. // Revision 1.47 2004/08/23 19:16:23 jordi
  86. // avoids null exception
  87. //
  88. // Revision 1.46 2004/08/22 21:10:30 pbartok
  89. // - Removed OverlappedWindow style from Control, instead it's default
  90. // now is child
  91. // - Made form windows OverlappedWindow by default
  92. //
  93. // Revision 1.45 2004/08/21 22:19:30 pbartok
  94. // - Signature fixes
  95. //
  96. // Revision 1.44 2004/08/21 20:53:13 pbartok
  97. // - Updated to match new GrabWindow signature
  98. //
  99. // Revision 1.43 2004/08/21 19:32:15 pbartok
  100. // - Implemented Created property
  101. //
  102. // Revision 1.42 2004/08/21 19:28:22 pbartok
  103. // - Implemented ContainsFocus
  104. //
  105. // Revision 1.41 2004/08/21 19:26:24 pbartok
  106. // - Implemented CausesValidation
  107. //
  108. // Revision 1.40 2004/08/21 19:21:50 pbartok
  109. // - Implemented CanFocus
  110. // - Implemented CanSelect
  111. // - Implemented Capture
  112. //
  113. // Revision 1.39 2004/08/21 16:54:11 jackson
  114. // Implement EndInvoke
  115. //
  116. // Revision 1.38 2004/08/20 23:38:54 ravindra
  117. // Made RightToLeft property virtual and removed a Console.WriteLine.
  118. //
  119. // Revision 1.37 2004/08/20 20:09:24 pbartok
  120. // - Added call to set window background color
  121. //
  122. // Revision 1.36 2004/08/20 19:18:30 jackson
  123. // Implement Begininvoke
  124. //
  125. // Revision 1.35 2004/08/20 01:17:24 pbartok
  126. // - Added handling of WM_MOUSEHOVER
  127. // - Worked around 'bug' in Win32 WM_MOUSE_ENTER/WM_MOUSE_LEAVE driver code
  128. //
  129. // Revision 1.34 2004/08/19 23:09:22 pbartok
  130. // - Added Right property
  131. // - Added RightToLeft property
  132. //
  133. // Revision 1.33 2004/08/19 22:25:31 jordi
  134. // theme enhancaments
  135. //
  136. // Revision 1.32 2004/08/17 21:25:12 pbartok
  137. // - Drawing improvement; don't call UpdateBounds if we are not visible (or
  138. // have been minimized)
  139. //
  140. // Revision 1.31 2004/08/17 20:25:28 pbartok
  141. // - Fixed broken handling of default window sizes
  142. //
  143. // Revision 1.30 2004/08/16 21:47:11 pbartok
  144. // - Added handling of WM_MOUSE_ENTER & WM_MOUSE_LEAVE to
  145. // support OnMouseEnter/Leave()
  146. // - Added WS_CLIPSIBLINGS and WS_CLIPCHILDREN window styles to improve
  147. // exposure handling
  148. //
  149. // Revision 1.29 2004/08/13 22:15:46 pbartok
  150. // - Fixed Anchor default
  151. //
  152. // Revision 1.28 2004/08/13 21:43:39 pbartok
  153. // - Changed GetCursorPos signature
  154. //
  155. // Revision 1.27 2004/08/13 19:00:15 jordi
  156. // implements PointToClient (ScreenToClient)
  157. //
  158. // Revision 1.26 2004/08/13 18:52:07 pbartok
  159. // - Added Dispose() and destructor
  160. // - Fixed resizing and bounds calculation
  161. // - Fixed Layout
  162. // - Added memory savings for invisible windows
  163. //
  164. // Revision 1.25 2004/08/12 19:31:19 pbartok
  165. // - Fixed Anchoring bugs
  166. //
  167. // Revision 1.24 2004/08/12 16:10:42 jackson
  168. // Add missing properties
  169. //
  170. // Revision 1.23 2004/08/11 22:20:59 pbartok
  171. // - Signature fixes
  172. //
  173. // Revision 1.22 2004/08/11 19:19:44 pbartok
  174. // - We had SetWindowPos and MoveWindow to set window positions and size,
  175. // removed MoveWindow. We have GetWindowPos, so it made sense to keep
  176. // SetWindowPos as matching counterpart
  177. // - Added some X11 sanity checking
  178. //
  179. // Revision 1.21 2004/08/11 18:59:45 pbartok
  180. // - Major cleanup of my SetBounds/SetBoundsCore/UpdateBounds mess
  181. // (It seems that SetBounds is just a front for SetBoundsCore and
  182. // SetBoundsCore updates the underlying window system and UpdateBounds is
  183. // responsible for updating the variables associated with the Control and
  184. // sending the events)
  185. // - Major cleanup of Size handling; we now have two sizes, client_size and
  186. // bounds. Bounds defines the window with decorations, client_size without
  187. // them.
  188. //
  189. // Revision 1.20 2004/08/11 15:13:32 pbartok
  190. // - Now properly reparents windows
  191. //
  192. // Revision 1.19 2004/08/11 14:37:11 pbartok
  193. // - Duh!
  194. //
  195. // Revision 1.18 2004/08/11 13:47:22 pbartok
  196. // - Rewrote the collection stuff. Might not be as fast now, not keeping
  197. // the number of children around and accessible directly, but it's more
  198. // straightforward
  199. //
  200. // Revision 1.17 2004/08/10 18:32:10 jordi
  201. // throw ontextchange event
  202. //
  203. // Revision 1.16 2004/08/10 17:43:04 pbartok
  204. // - Added more to the still unfinished Dock/Anchor layout code
  205. //
  206. // Revision 1.15 2004/08/10 15:08:05 jackson
  207. // Control will now handle the buffering code, so each control does not have to implement this.
  208. //
  209. // Revision 1.14 2004/08/09 22:11:25 pbartok
  210. // - Added incomplete dock layout code
  211. // - Added support for mouse wheel
  212. //
  213. // Revision 1.13 2004/08/09 17:25:56 jackson
  214. // Use new color names
  215. //
  216. // Revision 1.12 2004/08/09 15:54:51 jackson
  217. // Get default properties from the theme.
  218. //
  219. // Revision 1.11 2004/08/06 21:30:56 pbartok
  220. // - Fixed recursive loop when resizing
  221. // - Improved/fixed redrawing on expose messages
  222. //
  223. // Revision 1.10 2004/08/06 15:53:39 jordi
  224. // X11 keyboard navigation
  225. //
  226. // Revision 1.9 2004/08/04 21:14:26 pbartok
  227. // - Fixed Invalidation bug (calculated wrong client area)
  228. // - Added ClientSize setter
  229. //
  230. // Revision 1.8 2004/08/04 20:11:24 pbartok
  231. // - Added Invalidate handling
  232. //
  233. // Revision 1.7 2004/07/27 10:38:17 jordi
  234. // changes to be able to run winforms samples
  235. //
  236. // Revision 1.6 2004/07/19 19:09:42 jordi
  237. // label control re-written: added missing functionlity, events, and properties
  238. //
  239. // Revision 1.5 2004/07/19 16:49:23 jordi
  240. // fixes SetBounds logic
  241. //
  242. // Revision 1.4 2004/07/19 07:29:35 jordi
  243. // Call RefreshWindow only if the window has created
  244. //
  245. // Revision 1.3 2004/07/15 17:03:35 jordi
  246. // added basic mouse handeling events
  247. //
  248. // Revision 1.2 2004/07/13 15:31:45 jordi
  249. // commit: new properties and fixes form size problems
  250. //
  251. // Revision 1.1 2004/07/09 05:21:25 pbartok
  252. // - Initial check-in
  253. //
  254. //
  255. // NOT COMPLETE
  256. using System;
  257. using System.Drawing;
  258. using System.ComponentModel;
  259. using System.Collections;
  260. using System.Diagnostics;
  261. using System.Threading;
  262. using System.Runtime.InteropServices;
  263. namespace System.Windows.Forms
  264. {
  265. public class Control : Component, ISynchronizeInvoke, IWin32Window
  266. {
  267. #region Local Variables
  268. // Basic
  269. internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
  270. internal object creator_thread; // thread that created the control
  271. internal ControlNativeWindow window; // object for native window handle
  272. internal string name; // for object naming
  273. // State
  274. internal bool has_focus; // true if control has focus
  275. internal bool is_visible; // true if control is visible
  276. internal bool is_entered; // is the mouse inside the control?
  277. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  278. internal bool is_selected; // true if control is selected
  279. internal bool is_accessible; // true if the control is visible to accessibility applications
  280. internal bool is_captured; // tracks if the control has captured the mouse
  281. internal bool is_recreating; // tracks if the handle for the control is being recreated
  282. internal bool causes_validation; // tracks if validation is executed on changes
  283. internal int tab_index; // position in tab order of siblings
  284. internal bool tab_stop = true; // is the control a tab stop?
  285. internal bool is_disposed; // has the window already been disposed?
  286. internal Size client_size; // size of the client area (window excluding decorations)
  287. internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  288. internal ControlStyles control_style; // rather win32-specific, style bits for control
  289. internal ImeMode ime_mode = ImeMode.Inherit;
  290. internal bool layout_pending; // true if our parent needs to re-layout us
  291. internal object control_tag; // object that contains data about our control
  292. // Visuals
  293. internal Color foreground_color; // foreground color for control
  294. internal Color background_color; // background color for control
  295. internal Image background_image; // background image for control
  296. internal Font font; // font for control
  297. internal string text; // window/title text for control
  298. // Layout
  299. internal AnchorStyles anchor_style; // anchoring requirements for our control
  300. internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
  301. internal int prev_width; // previous width of the control; required for anchoring
  302. internal int prev_height; // previous height of our control; required for anchoring
  303. internal Size prev_size;
  304. // to be categorized...
  305. static internal Hashtable controls; // All of the applications controls, in a flat list
  306. internal ControlCollection child_controls; // our children
  307. internal Control parent; // our parent control
  308. internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
  309. internal BindingContext binding_context; // TODO
  310. internal RightToLeft right_to_left; // drawing direction for control
  311. internal int layout_suspended;
  312. internal bool double_buffering;
  313. private Graphics dc_mem; // Graphics context for double buffering
  314. private Bitmap bmp_mem; // Bitmap for double buffering control
  315. #endregion // Local Variables
  316. #region Private Classes
  317. // This helper class allows us to dispatch messages to Control.WndProc
  318. internal class ControlNativeWindow : NativeWindow {
  319. private Control control;
  320. public ControlNativeWindow(Control control) : base() {
  321. this.control=control;
  322. }
  323. protected override void WndProc(ref Message m) {
  324. control.WndProc(ref m);
  325. }
  326. }
  327. #endregion
  328. #region Public Classes
  329. public class ControlAccessibleObject : AccessibleObject {
  330. #region ControlAccessibleObject Local Variables
  331. private Control owner;
  332. #endregion // ControlAccessibleObject Local Variables
  333. #region ControlAccessibleObject Constructors
  334. public ControlAccessibleObject(Control ownerControl) {
  335. this.owner = ownerControl;
  336. }
  337. #endregion // ControlAccessibleObject Constructors
  338. #region ControlAccessibleObject Public Instance Properties
  339. public override string DefaultAction {
  340. get {
  341. return base.DefaultAction;
  342. }
  343. }
  344. public override string Description {
  345. get {
  346. return base.Description;
  347. }
  348. }
  349. public IntPtr Handle {
  350. get {
  351. return owner.Handle;
  352. }
  353. set {
  354. // We don't want to let them set it
  355. }
  356. }
  357. public override string Help {
  358. get {
  359. return base.Help;
  360. }
  361. }
  362. public override string KeyboardShortcut {
  363. get {
  364. return base.KeyboardShortcut;
  365. }
  366. }
  367. public override string Name {
  368. get {
  369. return base.Name;
  370. }
  371. set {
  372. base.Name = value;
  373. }
  374. }
  375. public Control Owner {
  376. get {
  377. return owner;
  378. }
  379. }
  380. public override AccessibleRole Role {
  381. get {
  382. return base.Role;
  383. }
  384. }
  385. #endregion // ControlAccessibleObject Public Instance Properties
  386. #region ControlAccessibleObject Public Instance Methods
  387. public override int GetHelpTopic(out string FileName) {
  388. return base.GetHelpTopic (out FileName);
  389. }
  390. #endregion // ControlAccessibleObject Public Instance Methods
  391. }
  392. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  393. #region ControlCollection Local Variables
  394. private ArrayList list;
  395. private Control owner;
  396. #endregion // ControlCollection Local Variables
  397. #region ControlCollection Public Constructor
  398. public ControlCollection(Control owner) {
  399. this.owner=owner;
  400. this.list=new ArrayList();
  401. }
  402. #endregion
  403. #region ControlCollection Public Instance Properties
  404. public int Count {
  405. get {
  406. return list.Count;
  407. }
  408. }
  409. public bool IsReadOnly {
  410. get {
  411. return list.IsReadOnly;
  412. }
  413. }
  414. public virtual Control this[int index] {
  415. get {
  416. if (index < 0 || index >= list.Count) {
  417. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  418. }
  419. return (Control)list[index];
  420. }
  421. }
  422. #endregion // ControlCollection Public Instance Properties
  423. #region ControlCollection Private Instance Methods
  424. public virtual void Add(Control value) {
  425. for (int i=0; i<list.Count; i++) {
  426. if (list[i]==value) {
  427. // Do we need to do anything here?
  428. return;
  429. }
  430. }
  431. list.Add(value);
  432. value.Parent=owner;
  433. }
  434. public virtual void AddRange(Control[] controls) {
  435. for (int i=0; i<controls.Length; i++) {
  436. Add(controls[i]);
  437. }
  438. }
  439. public virtual void Clear() {
  440. owner.SuspendLayout();
  441. list.Clear();
  442. owner.ResumeLayout();
  443. }
  444. public virtual bool Contains(Control value) {
  445. return list.Contains(value);
  446. }
  447. public void CopyTo(Array array, int index) {
  448. list.CopyTo(array, index);
  449. }
  450. public override bool Equals(object other) {
  451. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  452. return(true);
  453. } else {
  454. return(false);
  455. }
  456. }
  457. public int GetChildIndex(Control child) {
  458. return GetChildIndex(child, false);
  459. }
  460. public int GetChildIndex(Control child, bool throwException) {
  461. int index;
  462. index=list.IndexOf(child);
  463. if (index==-1 && throwException) {
  464. throw new ArgumentException("Not a child control", "child");
  465. }
  466. return index;
  467. }
  468. public IEnumerator GetEnumerator() {
  469. return list.GetEnumerator();
  470. }
  471. public override int GetHashCode() {
  472. return base.GetHashCode();
  473. }
  474. public int IndexOf(Control control) {
  475. return list.IndexOf(control);
  476. }
  477. public virtual void Remove(Control value) {
  478. list.Remove(value);
  479. }
  480. public void RemoveAt(int index) {
  481. if (index<0 || index>=list.Count) {
  482. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  483. }
  484. list.RemoveAt(index);
  485. }
  486. public void SetChildIndex(Control child, int newIndex) {
  487. int old_index;
  488. old_index=list.IndexOf(child);
  489. if (old_index==-1) {
  490. throw new ArgumentException("Not a child control", "child");
  491. }
  492. if (old_index==newIndex) {
  493. return;
  494. }
  495. RemoveAt(old_index);
  496. if (newIndex>list.Count) {
  497. list.Add(child);
  498. } else {
  499. list.Insert(newIndex, child);
  500. }
  501. }
  502. #endregion // ControlCollection Private Instance Methods
  503. #region ControlCollection Interface Properties
  504. object IList.this[int index] {
  505. get {
  506. if (index<0 || index>=list.Count) {
  507. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  508. }
  509. return this[index];
  510. }
  511. set {
  512. if (!(value is Control)) {
  513. throw new ArgumentException("Object of type Control required", "value");
  514. }
  515. list[index]=(Control)value;
  516. }
  517. }
  518. bool IList.IsFixedSize {
  519. get {
  520. return false;
  521. }
  522. }
  523. bool IList.IsReadOnly {
  524. get {
  525. return list.IsReadOnly;
  526. }
  527. }
  528. bool ICollection.IsSynchronized {
  529. get {
  530. return list.IsSynchronized;
  531. }
  532. }
  533. object ICollection.SyncRoot {
  534. get {
  535. return list.SyncRoot;
  536. }
  537. }
  538. #endregion // ControlCollection Interface Properties
  539. #region ControlCollection Interface Methods
  540. int IList.Add(object value) {
  541. if (value == null) {
  542. throw new ArgumentNullException("value", "Cannot add null controls");
  543. }
  544. if (!(value is Control)) {
  545. throw new ArgumentException("Object of type Control required", "value");
  546. }
  547. return list.Add(value);
  548. }
  549. bool IList.Contains(object value) {
  550. if (!(value is Control)) {
  551. throw new ArgumentException("Object of type Control required", "value");
  552. }
  553. return this.Contains((Control) value);
  554. }
  555. int IList.IndexOf(object value) {
  556. if (!(value is Control)) {
  557. throw new ArgumentException("Object of type Control required", "value");
  558. }
  559. return this.IndexOf((Control) value);
  560. }
  561. void IList.Insert(int index, object value) {
  562. if (!(value is Control)) {
  563. throw new ArgumentException("Object of type Control required", "value");
  564. }
  565. list.Insert(index, value);
  566. }
  567. void IList.Remove(object value) {
  568. if (!(value is Control)) {
  569. throw new ArgumentException("Object of type Control required", "value");
  570. }
  571. list.Remove(value);
  572. }
  573. void ICollection.CopyTo(Array array, int index) {
  574. if (list.Count>0) {
  575. list.CopyTo(array, index);
  576. }
  577. }
  578. Object ICloneable.Clone() {
  579. ControlCollection clone = new ControlCollection(this.owner);
  580. clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
  581. return clone;
  582. }
  583. #endregion // ControlCollection Interface Methods
  584. }
  585. #endregion // ControlCollection Class
  586. #region Public Constructors
  587. public Control() {
  588. creator_thread = Thread.CurrentThread;
  589. controls = new Hashtable();
  590. child_controls = CreateControlsInstance();
  591. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  592. client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  593. XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, false, out bounds);
  594. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
  595. bounds.X=-1;
  596. bounds.Y=-1;
  597. }
  598. prev_size = Size.Empty;
  599. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  600. is_visible = true;
  601. is_captured = false;
  602. is_disposed = false;
  603. is_enabled = true;
  604. is_entered = false;
  605. layout_pending = false;
  606. causes_validation = true;
  607. has_focus = false;
  608. layout_suspended = 0;
  609. double_buffering = true;
  610. parent = null;
  611. background_image = null;
  612. text = string.Empty;
  613. name = string.Empty;
  614. }
  615. public Control(Control parent, string text) : this() {
  616. Text=text;
  617. Parent=parent;
  618. }
  619. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  620. Parent=parent;
  621. bounds.X=left;
  622. bounds.Y=top;
  623. bounds.Width=width;
  624. bounds.Height=height;
  625. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  626. Text=text;
  627. }
  628. public Control(string text) : this() {
  629. Text=text;
  630. }
  631. public Control(string text, int left, int top, int width, int height) : this() {
  632. bounds.X=left;
  633. bounds.Y=top;
  634. bounds.Width=width;
  635. bounds.Height=height;
  636. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  637. Text=text;
  638. }
  639. protected override void Dispose(bool disposing) {
  640. is_disposed = true;
  641. if (dc_mem!=null) {
  642. dc_mem.Dispose();
  643. dc_mem=null;
  644. }
  645. if (bmp_mem!=null) {
  646. bmp_mem.Dispose();
  647. bmp_mem=null;
  648. }
  649. DestroyHandle();
  650. }
  651. #endregion // Public Constructors
  652. #region Internal Properties
  653. #endregion // Internal Properties
  654. #region Private & Internal Methods
  655. internal static void SetChildColor(Control parent) {
  656. Control child;
  657. for (int i=0; i < parent.child_controls.Count; i++) {
  658. child=parent.child_controls[i];
  659. if (child.IsHandleCreated) {
  660. XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
  661. }
  662. if (child.child_controls.Count>0) {
  663. SetChildColor(child);
  664. }
  665. }
  666. }
  667. private bool Select(Control control) {
  668. Control parent;
  669. if (control == null) {
  670. return false;
  671. }
  672. parent = control.parent;
  673. if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
  674. while (parent != null) {
  675. if (!parent.is_visible || !parent.is_enabled) {
  676. return false;
  677. }
  678. }
  679. }
  680. control.is_selected = true;
  681. return true;
  682. }
  683. private Control FindTabStop(Control control, bool forward) {
  684. if (control == null) {
  685. return null;
  686. }
  687. return null;
  688. }
  689. #endregion // Private & Internal Methods
  690. #region Public Static Properties
  691. public static Color DefaultBackColor {
  692. get {
  693. return ThemeEngine.Current.DefaultControlBackColor;
  694. }
  695. }
  696. public static Font DefaultFont {
  697. get {
  698. return ThemeEngine.Current.DefaultFont;
  699. }
  700. }
  701. public static Color DefaultForeColor {
  702. get {
  703. return ThemeEngine.Current.DefaultControlForeColor;
  704. }
  705. }
  706. public static Keys ModifierKeys {
  707. get {
  708. return XplatUI.State.ModifierKeys;
  709. }
  710. }
  711. public static MouseButtons MouseButtons {
  712. get {
  713. return XplatUI.State.MouseButtons;
  714. }
  715. }
  716. public static Point MousePosition {
  717. get {
  718. return Cursor.Position;
  719. }
  720. }
  721. #endregion // Public Static Properties
  722. #region Public Instance Properties
  723. public AccessibleObject AccessibilityObject {
  724. get {
  725. if (accessibility_object==null) {
  726. accessibility_object=CreateAccessibilityInstance();
  727. }
  728. return accessibility_object;
  729. }
  730. }
  731. public string AccessibleDefaultActionDescription {
  732. get {
  733. return AccessibilityObject.default_action;
  734. }
  735. set {
  736. AccessibilityObject.default_action=value;
  737. }
  738. }
  739. public string AccessibleDescription {
  740. get {
  741. return AccessibilityObject.description;
  742. }
  743. set {
  744. AccessibilityObject.description=value;
  745. }
  746. }
  747. public string AccessibleName {
  748. get {
  749. return AccessibilityObject.Name;
  750. }
  751. set {
  752. AccessibilityObject.Name=value;
  753. }
  754. }
  755. public AccessibleRole AccessibleRole {
  756. get {
  757. return AccessibilityObject.role;
  758. }
  759. set {
  760. AccessibilityObject.role=value;
  761. }
  762. }
  763. public virtual bool AllowDrop {
  764. get {
  765. return XplatUI.State.DropTarget;
  766. }
  767. set {
  768. XplatUI.State.DropTarget=value;
  769. }
  770. }
  771. public virtual AnchorStyles Anchor {
  772. get {
  773. return anchor_style;
  774. }
  775. set {
  776. anchor_style=value;
  777. if (parent != null) {
  778. parent.PerformLayout(this, "Parent");
  779. }
  780. }
  781. }
  782. public virtual Color BackColor {
  783. get {
  784. if (background_color.IsEmpty) {
  785. if (parent!=null) {
  786. return parent.BackColor;
  787. }
  788. return DefaultBackColor;
  789. }
  790. return background_color;
  791. }
  792. set {
  793. background_color=value;
  794. if (this.IsHandleCreated) {
  795. XplatUI.SetWindowBackground(this.window.Handle, value);
  796. }
  797. SetChildColor(this);
  798. OnBackColorChanged(EventArgs.Empty);
  799. Refresh();
  800. }
  801. }
  802. public virtual Image BackgroundImage {
  803. get {
  804. return background_image;
  805. }
  806. set {
  807. if (background_image!=value) {
  808. background_image=value;
  809. OnBackgroundImageChanged(EventArgs.Empty);
  810. }
  811. }
  812. }
  813. public virtual BindingContext BindingContext {
  814. get {
  815. throw new NotImplementedException();
  816. }
  817. set {
  818. throw new NotImplementedException();
  819. }
  820. }
  821. public int Bottom {
  822. get {
  823. return bounds.Y+bounds.Height;
  824. }
  825. }
  826. public Rectangle Bounds {
  827. get {
  828. return this.bounds;
  829. }
  830. set {
  831. SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  832. }
  833. }
  834. public bool CanFocus {
  835. get {
  836. if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
  837. return true;
  838. }
  839. return false;
  840. }
  841. }
  842. public bool CanSelect {
  843. get {
  844. Control parent;
  845. if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
  846. return false;
  847. }
  848. parent = this.parent;
  849. while (parent != null) {
  850. if (!parent.is_visible || !parent.is_enabled) {
  851. return false;
  852. }
  853. parent = parent.parent;
  854. }
  855. return true;
  856. }
  857. }
  858. public bool Capture {
  859. get {
  860. return this.is_captured;
  861. }
  862. set {
  863. if (this.IsHandleCreated) {
  864. if (value && !is_captured) {
  865. is_captured = true;
  866. XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
  867. } else if (!value && is_captured) {
  868. XplatUI.ReleaseWindow(this.window.Handle);
  869. is_captured = false;
  870. }
  871. }
  872. }
  873. }
  874. public bool CausesValidation {
  875. get {
  876. return this.causes_validation;
  877. }
  878. set {
  879. if (this.causes_validation != value) {
  880. causes_validation = value;
  881. OnCausesValidationChanged(EventArgs.Empty);
  882. }
  883. }
  884. }
  885. public Rectangle ClientRectangle {
  886. get {
  887. client_rect.Width = client_size.Width;
  888. client_rect.Height = client_size.Height;
  889. return client_rect;
  890. }
  891. }
  892. public Size ClientSize {
  893. get {
  894. return client_size;
  895. }
  896. set {
  897. this.SetClientSizeCore(value.Width, value.Height);
  898. }
  899. }
  900. public String CompanyName {
  901. get {
  902. return "Mono Project, Novell, Inc.";
  903. }
  904. }
  905. public bool ContainsFocus {
  906. get {
  907. if (this.Focused) {
  908. return true;
  909. }
  910. for (int i=0; i < child_controls.Count; i++) {
  911. if (child_controls[i].Focused) {
  912. return true;
  913. }
  914. }
  915. return false;
  916. }
  917. }
  918. #if notdef
  919. public virtual ContextMenu ContextMenu {
  920. get {
  921. throw new NotImplementedException();
  922. }
  923. set {
  924. throw new NotImplementedException();
  925. }
  926. }
  927. #endif
  928. public ControlCollection Controls {
  929. get {
  930. return this.child_controls;
  931. }
  932. }
  933. public bool Created {
  934. get {
  935. if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
  936. return true;
  937. }
  938. return false;
  939. }
  940. }
  941. #if notdef
  942. public virtual Cursor Cursor {
  943. get {
  944. throw new NotImplementedException();
  945. }
  946. set {
  947. throw new NotImplementedException();
  948. }
  949. }
  950. public ControlBidingsCollection DataBindings {
  951. get {
  952. throw new NotImplementedException();
  953. }
  954. }
  955. #endif
  956. public virtual Rectangle DisplayRectangle {
  957. get {
  958. return ClientRectangle;
  959. }
  960. }
  961. public bool Disposing {
  962. get {
  963. return is_disposed;
  964. }
  965. }
  966. public virtual DockStyle Dock {
  967. get {
  968. return dock_style;
  969. }
  970. set {
  971. if (dock_style == value) {
  972. return;
  973. }
  974. dock_style = value;
  975. if (parent != null) {
  976. parent.PerformLayout(this, "Parent");
  977. }
  978. OnDockChanged(EventArgs.Empty);
  979. }
  980. }
  981. public bool Enabled {
  982. get {
  983. return is_enabled;
  984. }
  985. set {
  986. if (is_enabled == value) {
  987. return;
  988. }
  989. is_enabled = value;
  990. Refresh();
  991. OnEnabledChanged (EventArgs.Empty);
  992. }
  993. }
  994. public virtual bool Focused {
  995. get {
  996. return this.has_focus;
  997. }
  998. }
  999. public virtual Font Font {
  1000. get {
  1001. if (font != null) {
  1002. return font;
  1003. }
  1004. if (Parent != null && Parent.Font != null) {
  1005. return Parent.Font;
  1006. }
  1007. return DefaultFont;
  1008. }
  1009. set {
  1010. if (font == value) {
  1011. return;
  1012. }
  1013. font = value;
  1014. Refresh();
  1015. OnFontChanged (EventArgs.Empty);
  1016. }
  1017. }
  1018. public virtual Color ForeColor {
  1019. get {
  1020. if (foreground_color.IsEmpty) {
  1021. if (parent!=null) {
  1022. return parent.ForeColor;
  1023. }
  1024. return DefaultForeColor;
  1025. }
  1026. return foreground_color;
  1027. }
  1028. set {
  1029. foreground_color=value;
  1030. Refresh();
  1031. }
  1032. }
  1033. public IntPtr Handle { // IWin32Window
  1034. get {
  1035. if (!IsHandleCreated) {
  1036. CreateHandle();
  1037. }
  1038. return window.Handle;
  1039. }
  1040. }
  1041. public bool HasChildren {
  1042. get {
  1043. if (this.child_controls.Count>0) {
  1044. return true;
  1045. }
  1046. return false;
  1047. }
  1048. }
  1049. public int Height {
  1050. get {
  1051. return this.bounds.Height;
  1052. }
  1053. set {
  1054. SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  1055. }
  1056. }
  1057. public ImeMode ImeMode {
  1058. get {
  1059. return ime_mode;
  1060. }
  1061. set {
  1062. ime_mode = value;
  1063. }
  1064. }
  1065. public bool InvokeRequired { // ISynchronizeInvoke
  1066. get {
  1067. if (creator_thread!=Thread.CurrentThread) {
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. }
  1073. public bool IsAccessible {
  1074. get {
  1075. return is_accessible;
  1076. }
  1077. set {
  1078. is_accessible = value;
  1079. }
  1080. }
  1081. public bool IsDisposed {
  1082. get {
  1083. return this.is_disposed;
  1084. }
  1085. }
  1086. public bool IsHandleCreated {
  1087. get {
  1088. if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
  1089. return true;
  1090. }
  1091. return false;
  1092. }
  1093. }
  1094. public int Left {
  1095. get {
  1096. return this.bounds.X;
  1097. }
  1098. set {
  1099. SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  1100. }
  1101. }
  1102. public Point Location {
  1103. get {
  1104. return new Point(bounds.X, bounds.Y);
  1105. }
  1106. set {
  1107. SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  1108. }
  1109. }
  1110. public string Name {
  1111. get {
  1112. return this.name;
  1113. }
  1114. set {
  1115. this.name=value;
  1116. }
  1117. }
  1118. public Control Parent {
  1119. get {
  1120. return this.parent;
  1121. }
  1122. set {
  1123. if (parent!=value) {
  1124. if (parent!=null) {
  1125. parent.Controls.Remove(this);
  1126. }
  1127. parent=value;
  1128. if (!parent.Controls.Contains(this)) {
  1129. parent.Controls.Add(this);
  1130. }
  1131. XplatUI.SetParent(Handle, value.Handle);
  1132. InitLayout();
  1133. }
  1134. }
  1135. }
  1136. public string ProductName {
  1137. get {
  1138. return "Novell Mono .NET Framework";
  1139. }
  1140. }
  1141. public string ProductVersion {
  1142. get {
  1143. return "1.1.4322.573";
  1144. }
  1145. }
  1146. public bool RecreatingHandle {
  1147. get {
  1148. return is_recreating;
  1149. }
  1150. }
  1151. public Region Region {
  1152. get {
  1153. return new Region(this.bounds);
  1154. }
  1155. set {
  1156. Graphics g;
  1157. RectangleF r;
  1158. g = Graphics.FromHwnd(this.window.Handle);
  1159. r = value.GetBounds(g);
  1160. SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
  1161. g.Dispose();
  1162. }
  1163. }
  1164. public int Right {
  1165. get {
  1166. return this.bounds.X+this.bounds.Width;
  1167. }
  1168. }
  1169. public virtual RightToLeft RightToLeft {
  1170. get {
  1171. return right_to_left;
  1172. }
  1173. set {
  1174. if (value != right_to_left) {
  1175. right_to_left = value;
  1176. OnRightToLeftChanged(EventArgs.Empty);
  1177. }
  1178. }
  1179. }
  1180. public override ISite Site {
  1181. get {
  1182. return base.Site;
  1183. }
  1184. set {
  1185. base.Site = value;
  1186. }
  1187. }
  1188. public Size Size {
  1189. get {
  1190. return new Size(Width, Height);
  1191. }
  1192. set {
  1193. SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  1194. }
  1195. }
  1196. public int TabIndex {
  1197. get {
  1198. return tab_index;
  1199. }
  1200. set {
  1201. tab_index = value;
  1202. }
  1203. }
  1204. public bool TabStop {
  1205. get {
  1206. return tab_stop;
  1207. }
  1208. set {
  1209. tab_stop = value;
  1210. }
  1211. }
  1212. public object Tag {
  1213. get {
  1214. return control_tag;
  1215. }
  1216. set {
  1217. control_tag = value;
  1218. }
  1219. }
  1220. public virtual string Text {
  1221. get {
  1222. return this.text;
  1223. }
  1224. set {
  1225. if (text!=value) {
  1226. text=value;
  1227. XplatUI.Text(Handle, text);
  1228. // FIXME: Do we need a Refresh() here?
  1229. OnTextChanged (EventArgs.Empty);
  1230. }
  1231. }
  1232. }
  1233. public int Top {
  1234. get {
  1235. return this.bounds.Y;
  1236. }
  1237. set {
  1238. SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  1239. }
  1240. }
  1241. public Control TopLevelControl {
  1242. get {
  1243. Control p = this;
  1244. while (p.parent != null) {
  1245. p = p.parent;
  1246. }
  1247. return p;
  1248. }
  1249. }
  1250. public bool Visible {
  1251. get {
  1252. return this.is_visible;
  1253. }
  1254. set {
  1255. if (value!=is_visible) {
  1256. is_visible=value;
  1257. XplatUI.SetVisible(Handle, value);
  1258. }
  1259. }
  1260. }
  1261. public int Width {
  1262. get {
  1263. return this.bounds.Width;
  1264. }
  1265. set {
  1266. SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  1267. }
  1268. }
  1269. public IWindowTarget WindowTarget {
  1270. get {
  1271. return null;
  1272. }
  1273. set {
  1274. ;
  1275. }
  1276. }
  1277. #endregion // Public Instance Properties
  1278. internal Graphics DeviceContext {
  1279. get {
  1280. if (dc_mem==null) {
  1281. CreateBuffers(this.Width, this.Height);
  1282. }
  1283. return dc_mem;
  1284. }
  1285. }
  1286. internal Bitmap ImageBuffer {
  1287. get {
  1288. if (bmp_mem==null) {
  1289. CreateBuffers(this.Width, this.Height);
  1290. }
  1291. return bmp_mem;
  1292. }
  1293. }
  1294. internal void CreateBuffers (int width, int height)
  1295. {
  1296. if (double_buffering == false)
  1297. return;
  1298. if (dc_mem != null)
  1299. dc_mem.Dispose ();
  1300. if (bmp_mem != null)
  1301. bmp_mem.Dispose ();
  1302. if (width < 1) {
  1303. width = 1;
  1304. }
  1305. if (height < 1) {
  1306. height = 1;
  1307. }
  1308. bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1309. dc_mem = Graphics.FromImage (bmp_mem);
  1310. }
  1311. #region Protected Instance Properties
  1312. protected virtual CreateParams CreateParams {
  1313. get {
  1314. CreateParams create_params = new CreateParams();
  1315. create_params.Caption = Text;
  1316. create_params.X = Left;
  1317. create_params.Y = Top;
  1318. create_params.Width = Width;
  1319. create_params.Height = Height;
  1320. create_params.ClassName = XplatUI.DefaultClassName;
  1321. create_params.ClassStyle = 0;
  1322. create_params.ExStyle = 0;
  1323. create_params.Param = 0;
  1324. if (parent!=null) {
  1325. create_params.Parent = parent.Handle;
  1326. }
  1327. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  1328. if (is_visible) {
  1329. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  1330. }
  1331. return create_params;
  1332. }
  1333. }
  1334. protected virtual ImeMode DefaultImeMode {
  1335. get {
  1336. return ImeMode.Inherit;
  1337. }
  1338. }
  1339. protected virtual Size DefaultSize {
  1340. get {
  1341. return new Size(100, 23);
  1342. }
  1343. }
  1344. #endregion // Protected Instance Properties
  1345. #region Public Instance Methods
  1346. public bool Contains(Control ctl) {
  1347. Control current;
  1348. current=ctl;
  1349. while (current!=null) {
  1350. if (current==ctl) {
  1351. return true;
  1352. }
  1353. current=current.parent;
  1354. }
  1355. return false;
  1356. }
  1357. public void CreateControl() {
  1358. Control child;
  1359. CreateHandle();
  1360. for (int i=0; i<child_controls.Count; i++) {
  1361. child_controls[i].CreateControl();
  1362. }
  1363. OnCreateControl();
  1364. }
  1365. public virtual void Refresh() {
  1366. if (IsHandleCreated == true) {
  1367. XplatUI.RefreshWindow(window.Handle);
  1368. }
  1369. }
  1370. public void Select() {
  1371. Select(false, false);
  1372. }
  1373. [MonoTODO("Finish")]
  1374. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  1375. return false;
  1376. }
  1377. public void SetBounds(int x, int y, int width, int height) {
  1378. SetBoundsCore(x, y, width, height, BoundsSpecified.All);
  1379. }
  1380. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  1381. SetBoundsCore(x, y, width, height, specified);
  1382. }
  1383. public void Show() {
  1384. if (!IsHandleCreated) {
  1385. this.CreateHandle();
  1386. }
  1387. this.Visible=true;
  1388. }
  1389. public object Invoke (Delegate method) {
  1390. return Invoke(method, null);
  1391. }
  1392. public object Invoke (Delegate method, object[] args) {
  1393. IAsyncResult result = BeginInvoke (method, args);
  1394. return EndInvoke(result);
  1395. }
  1396. public IAsyncResult BeginInvoke(Delegate method) {
  1397. return BeginInvoke(method, null);
  1398. }
  1399. protected virtual AccessibleObject CreateAccessibilityInstance() {
  1400. return new AccessibleObject(this);
  1401. }
  1402. protected virtual ControlCollection CreateControlsInstance() {
  1403. return new ControlCollection(this);
  1404. }
  1405. protected void UpdateBounds() {
  1406. int x;
  1407. int y;
  1408. int width;
  1409. int height;
  1410. int client_width;
  1411. int client_height;
  1412. if (!IsHandleCreated) {
  1413. CreateHandle();
  1414. }
  1415. XplatUI.GetWindowPos(this.Handle, out x, out y, out width, out height, out client_width, out client_height);
  1416. UpdateBounds(x, y, width, height, client_width, client_height);
  1417. }
  1418. protected void UpdateBounds(int x, int y, int width, int height) {
  1419. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  1420. bool moved = false;
  1421. bool resized = false;
  1422. int client_x_diff = this.bounds.Width-this.client_size.Width;
  1423. int client_y_diff = this.bounds.Height-this.client_size.Height;
  1424. // Needed to generate required notifications
  1425. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  1426. moved=true;
  1427. }
  1428. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  1429. resized=true;
  1430. }
  1431. bounds.X=x;
  1432. bounds.Y=y;
  1433. bounds.Width=width;
  1434. bounds.Height=height;
  1435. // Update client rectangle as well
  1436. if (this.layout_suspended==0) {
  1437. prev_size.Width=client_size.Width;
  1438. prev_size.Height=client_size.Height;
  1439. }
  1440. client_size.Width=width-client_x_diff;
  1441. client_size.Height=height-client_y_diff;
  1442. if (moved) {
  1443. OnLocationChanged(EventArgs.Empty);
  1444. }
  1445. if (resized) {
  1446. OnSizeChanged(EventArgs.Empty);
  1447. }
  1448. }
  1449. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  1450. UpdateBounds(x, y, width, height);
  1451. this.client_size.Width=clientWidth;
  1452. this.client_size.Height=clientHeight;
  1453. }
  1454. public void Invalidate() {
  1455. Invalidate(ClientRectangle, false);
  1456. }
  1457. public void Invalidate(bool invalidateChildren) {
  1458. Invalidate(ClientRectangle, invalidateChildren);
  1459. }
  1460. public void Invalidate(System.Drawing.Rectangle rc) {
  1461. Invalidate(rc, false);
  1462. }
  1463. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  1464. if (!IsHandleCreated || !is_visible) {
  1465. return;
  1466. }
  1467. XplatUI.Invalidate(Handle, rc, false);
  1468. if (invalidateChildren) {
  1469. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  1470. }
  1471. }
  1472. public void Invalidate(System.Drawing.Region region) {
  1473. Invalidate(region, false);
  1474. }
  1475. [MonoTODO]
  1476. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  1477. throw new NotImplementedException();
  1478. // FIXME - should use the GetRegionScans function of the region to invalidate each area
  1479. if (invalidateChildren) {
  1480. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  1481. }
  1482. }
  1483. public IAsyncResult BeginInvoke (Delegate method, object[] args)
  1484. {
  1485. return BeginInvokeInternal (method, args);
  1486. }
  1487. internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args)
  1488. {
  1489. AsyncMethodResult result = new AsyncMethodResult ();
  1490. AsyncMethodData data = new AsyncMethodData ();
  1491. data.Method = method;
  1492. data.Args = args;
  1493. data.Result = new WeakReference (result);
  1494. XplatUI.SendAsyncMethod (data);
  1495. return result;
  1496. }
  1497. public object EndInvoke (IAsyncResult async_result) {
  1498. AsyncMethodResult result = (AsyncMethodResult) async_result;
  1499. return result.EndInvoke ();
  1500. }
  1501. public void PerformLayout() {
  1502. PerformLayout(null, null);
  1503. }
  1504. public void PerformLayout(Control affectedControl, string affectedProperty) {
  1505. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  1506. if (layout_suspended>0) {
  1507. layout_pending = true;
  1508. return;
  1509. }
  1510. layout_pending = false;
  1511. // Prevent us from getting messed up
  1512. layout_suspended++;
  1513. // Perform all Dock and Anchor calculations
  1514. try {
  1515. Control child;
  1516. AnchorStyles anchor;
  1517. Rectangle space;
  1518. int diff_width;
  1519. int diff_height;
  1520. space=this.DisplayRectangle;
  1521. if (prev_size != Size.Empty) {
  1522. diff_width = space.Width - prev_size.Width;
  1523. diff_height = space.Height - prev_size.Height;
  1524. } else {
  1525. diff_width = 0;
  1526. diff_height = 0;
  1527. }
  1528. // Deal with docking
  1529. for (int i=0; i < child_controls.Count; i++) {
  1530. child=child_controls[i];
  1531. switch (child.Dock) {
  1532. case DockStyle.None: {
  1533. // Do nothing
  1534. break;
  1535. }
  1536. case DockStyle.Left: {
  1537. child.SetBounds(space.Left, space.Y, child.Width, space.Height);
  1538. space.X+=child.Width;
  1539. space.Width-=child.Width;
  1540. break;
  1541. }
  1542. case DockStyle.Top: {
  1543. child.SetBounds(space.Left, space.Y, space.Width, child.Height);
  1544. space.Y+=child.Height;
  1545. space.Height-=child.Height;
  1546. break;
  1547. }
  1548. case DockStyle.Right: {
  1549. child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
  1550. space.Width-=child.Width;
  1551. break;
  1552. }
  1553. case DockStyle.Bottom: {
  1554. child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
  1555. space.Height-=child.Height;
  1556. break;
  1557. }
  1558. case DockStyle.Fill: {
  1559. child.SetBounds(space.Left, space.Top, space.Width, space.Height);
  1560. space.Width=0;
  1561. space.Height=0;
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. space=this.DisplayRectangle;
  1567. // Deal with anchoring
  1568. for (int i=0; i < child_controls.Count; i++) {
  1569. int left;
  1570. int top;
  1571. int width;
  1572. int height;
  1573. child=child_controls[i];
  1574. anchor=child.Anchor;
  1575. left=child.Left;
  1576. top=child.Top;
  1577. width=child.Width;
  1578. height=child.Height;
  1579. // If the control is docked we don't need to do anything
  1580. if (child.Dock != DockStyle.None) {
  1581. continue;
  1582. }
  1583. if ((anchor & AnchorStyles.Left) !=0 ) {
  1584. if ((anchor & AnchorStyles.Right) != 0) {
  1585. // Anchoring to left and right
  1586. width=width+diff_width;
  1587. } else {
  1588. ; // nothing to do
  1589. }
  1590. } else if ((anchor & AnchorStyles.Right) != 0) {
  1591. left+=diff_width;
  1592. } else {
  1593. left+=diff_width/2;
  1594. }
  1595. if ((anchor & AnchorStyles.Top) !=0 ) {
  1596. if ((anchor & AnchorStyles.Bottom) != 0) {
  1597. height+=diff_height;
  1598. } else {
  1599. ; // nothing to do
  1600. }
  1601. } else if ((anchor & AnchorStyles.Bottom) != 0) {
  1602. top+=diff_height;
  1603. } else {
  1604. top+=diff_height/2;
  1605. }
  1606. // Sanity
  1607. if (width < 0) {
  1608. width=0;
  1609. }
  1610. if (height < 0) {
  1611. height=0;
  1612. }
  1613. child.SetBounds(left, top, width, height);
  1614. }
  1615. // Let everyone know
  1616. OnLayout(levent);
  1617. }
  1618. // Need to make sure we decremend layout_suspended
  1619. finally {
  1620. layout_suspended--;
  1621. }
  1622. }
  1623. public void ResumeLayout()
  1624. {
  1625. ResumeLayout (true);
  1626. }
  1627. public void ResumeLayout(bool performLayout)
  1628. {
  1629. layout_suspended--;
  1630. if (layout_suspended > 0) {
  1631. return;
  1632. }
  1633. if (performLayout || layout_pending) {
  1634. PerformLayout();
  1635. }
  1636. }
  1637. public void SuspendLayout()
  1638. {
  1639. layout_suspended++;
  1640. }
  1641. public Point PointToClient (Point p)
  1642. {
  1643. int x = p.X;
  1644. int y = p.Y;
  1645. XplatUI.ScreenToClient (Handle, ref x, ref y);
  1646. return new Point (x, y);
  1647. }
  1648. [MonoTODO]
  1649. protected virtual void WndProc(ref Message m) {
  1650. EventArgs e = new EventArgs();
  1651. #if debug
  1652. Console.WriteLine("Received message {0}", m);
  1653. #endif
  1654. switch((Msg)m.Msg) {
  1655. #if notyet
  1656. // Mouse handling
  1657. case Msg.WM_LBUTTONDBLCLK: throw new NotImplementedException(); break;
  1658. case Msg.WM_RBUTTONDOWN: throw new NotImplementedException(); break;
  1659. case Msg.WM_RBUTTONUP: throw new NotImplementedException(); break;
  1660. case Msg.WM_RBUTTONDBLCLK: throw new NotImplementedException(); break;
  1661. case Msg.WM_MOUSEHOVER: throw new NotImplementedException(); break;
  1662. case Msg.WM_MOUSELEAVE: throw new NotImplementedException(); break;
  1663. // Keyboard handling
  1664. case Msg.WM_CHAR: throw new NotImplementedException(); break;
  1665. case Msg.WM_KEYDOWN: throw new NotImplementedException(); break;
  1666. case Msg.WM_KEYUP: throw new NotImplementedException(); break;
  1667. #endif
  1668. // Window management
  1669. case Msg.WM_WINDOWPOSCHANGED: {
  1670. if (XplatUI.IsVisible(m.HWnd)) {
  1671. UpdateBounds();
  1672. }
  1673. DefWndProc(ref m);
  1674. break;
  1675. }
  1676. case Msg.WM_PAINT: {
  1677. Rectangle rect;
  1678. PaintEventArgs paint_event;
  1679. paint_event = XplatUI.PaintEventStart(Handle);
  1680. OnPaint(paint_event);
  1681. XplatUI.PaintEventEnd(Handle);
  1682. DefWndProc(ref m);
  1683. break;
  1684. }
  1685. case Msg.WM_ERASEBKGND:{
  1686. if (GetStyle (ControlStyles.UserPaint)){
  1687. if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
  1688. PaintEventArgs eraseEventArgs = new PaintEventArgs (Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
  1689. OnPaintBackground (eraseEventArgs);
  1690. }
  1691. m.Result = (IntPtr)1;
  1692. }
  1693. else {
  1694. #if notdef
  1695. SolidBrush sb = new SolidBrush(this.BackColor);
  1696. this.DeviceContext.FillRectangle(sb, this.ClientRectangle);
  1697. sb.Dispose();
  1698. #endif
  1699. m.Result = IntPtr.Zero;
  1700. DefWndProc (ref m);
  1701. }
  1702. break;
  1703. }
  1704. case Msg.WM_LBUTTONUP: {
  1705. int clicks = 1;
  1706. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  1707. clicks,
  1708. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1709. 0));
  1710. break;
  1711. }
  1712. case Msg.WM_LBUTTONDOWN: {
  1713. int clicks = 1;
  1714. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1715. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1716. 0));
  1717. break;
  1718. }
  1719. case Msg.WM_MOUSEWHEEL: {
  1720. int clicks = 1;
  1721. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1722. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1723. HighOrder(m.WParam.ToInt32())));
  1724. break;
  1725. }
  1726. case Msg.WM_MOUSEMOVE: {
  1727. int clicks = 1;
  1728. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1729. clicks,
  1730. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  1731. 0));
  1732. break;
  1733. }
  1734. case Msg.WM_MOUSE_ENTER: {
  1735. if (is_entered) {
  1736. return;
  1737. }
  1738. is_entered = true;
  1739. OnMouseEnter(EventArgs.Empty);
  1740. break;
  1741. }
  1742. case Msg.WM_MOUSE_LEAVE: {
  1743. is_entered=false;
  1744. OnMouseLeave(EventArgs.Empty);
  1745. break;
  1746. }
  1747. case Msg.WM_MOUSEHOVER: {
  1748. OnMouseHover(EventArgs.Empty);
  1749. break;
  1750. }
  1751. case Msg.WM_SIZE: {
  1752. if (GetStyle(ControlStyles.ResizeRedraw)) {
  1753. Invalidate();
  1754. }
  1755. DefWndProc(ref m);
  1756. break;
  1757. }
  1758. case Msg.WM_KEYDOWN: {
  1759. if (!ProcessKeyEventArgs (ref m))
  1760. DefWndProc (ref m);
  1761. break;
  1762. }
  1763. case Msg.WM_KEYUP: {
  1764. if (!ProcessKeyEventArgs (ref m))
  1765. DefWndProc (ref m);
  1766. break;
  1767. }
  1768. #if notyet
  1769. case Msg.WM_WINDOWPOSCHANGED: throw new NotImplementedException(); break;
  1770. case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
  1771. #endif
  1772. default:
  1773. DefWndProc(ref m);
  1774. break;
  1775. }
  1776. }
  1777. #endregion // Public Instance Methods
  1778. #region // Protected Instance Methods
  1779. protected virtual void CreateHandle() {
  1780. if (IsDisposed) {
  1781. throw new ObjectDisposedException(Name);
  1782. }
  1783. if (IsHandleCreated) {
  1784. return;
  1785. }
  1786. if (window==null) {
  1787. window = new ControlNativeWindow(this);
  1788. window.CreateHandle(CreateParams);
  1789. }
  1790. if (window.Handle!=IntPtr.Zero) {
  1791. if (!controls.Contains(window.Handle)) {
  1792. controls.Add(window.Handle, this);
  1793. }
  1794. creator_thread = Thread.CurrentThread;
  1795. XplatUI.SetWindowBackground(window.Handle, this.BackColor);
  1796. OnHandleCreated(EventArgs.Empty);
  1797. }
  1798. }
  1799. protected virtual void DefWndProc(ref Message m) {
  1800. window.DefWndProc(ref m);
  1801. }
  1802. protected virtual void DestroyHandle() {
  1803. if (IsHandleCreated) {
  1804. if (Handle != IntPtr.Zero) {
  1805. controls.Remove(Handle);
  1806. }
  1807. if (window != null) {
  1808. window.DestroyHandle();
  1809. }
  1810. }
  1811. }
  1812. protected virtual void InitLayout() {
  1813. if (parent != null) {
  1814. parent.PerformLayout(this, "parent");
  1815. }
  1816. }
  1817. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  1818. {
  1819. KeyEventArgs key_event;
  1820. switch (msg.Msg) {
  1821. case (int)Msg.WM_KEYDOWN: {
  1822. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1823. OnKeyDown (key_event);
  1824. return key_event.Handled;
  1825. }
  1826. case (int)Msg.WM_KEYUP: {
  1827. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1828. OnKeyUp (key_event);
  1829. return key_event.Handled;
  1830. }
  1831. default:
  1832. break;
  1833. }
  1834. return false;
  1835. }
  1836. protected virtual bool IsInputKey (Keys keyData)
  1837. {
  1838. return false;
  1839. }
  1840. protected virtual bool ProcessDialogKey (Keys keyData)
  1841. {
  1842. if (parent != null)
  1843. return Parent.ProcessDialogKey (keyData);
  1844. return false;
  1845. }
  1846. protected bool GetStyle(ControlStyles flag) {
  1847. return (control_style & flag) != 0;
  1848. }
  1849. protected virtual bool ProcessDialogChar(char charCode) {
  1850. throw new NotImplementedException();
  1851. }
  1852. protected virtual bool ProcessMnemonic(char charCode) {
  1853. throw new NotImplementedException();
  1854. }
  1855. protected void RecreateHandle() {
  1856. IEnumerator child = child_controls.GetEnumerator();
  1857. is_recreating=true;
  1858. if (IsHandleCreated) {
  1859. DestroyHandle();
  1860. CreateHandle();
  1861. // FIXME ZOrder?
  1862. while (child.MoveNext()) {
  1863. ((Control)child.Current).RecreateHandle();
  1864. }
  1865. } else {
  1866. CreateHandle();
  1867. }
  1868. is_recreating = false;
  1869. }
  1870. protected virtual void ScaleCore(float dx, float dy) {
  1871. throw new NotImplementedException();
  1872. }
  1873. protected virtual void Select(bool directed, bool forward) {
  1874. int index;
  1875. bool result;
  1876. if (!directed) {
  1877. // Select this control
  1878. Select(this);
  1879. }
  1880. if (parent == null) {
  1881. return;
  1882. }
  1883. index = parent.child_controls.IndexOf(this);
  1884. result = false;
  1885. do {
  1886. if (forward) {
  1887. if ((index+1) < parent.child_controls.Count) {
  1888. index++;
  1889. } else {
  1890. index = 0;
  1891. }
  1892. } else {
  1893. if (index>0) {
  1894. index++;
  1895. } else {
  1896. index = parent.child_controls.Count-1;
  1897. }
  1898. }
  1899. result = Select(parent.child_controls[index]);
  1900. } while (!result && parent.child_controls[index] != this);
  1901. }
  1902. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  1903. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  1904. if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
  1905. x = Left;
  1906. }
  1907. if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  1908. y = Top;
  1909. }
  1910. if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
  1911. width = Width;
  1912. }
  1913. if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  1914. height = Height;
  1915. }
  1916. if (IsHandleCreated) {
  1917. XplatUI.SetWindowPos(Handle, x, y, width, height);
  1918. }
  1919. UpdateBounds(x, y, width, height);
  1920. }
  1921. protected virtual void SetClientSizeCore(int x, int y) {
  1922. // Calculate the actual window size from the client size (it usually stays the same or grows)
  1923. Rectangle ClientRect;
  1924. Rectangle WindowRect;
  1925. CreateParams cp;
  1926. ClientRect = new Rectangle(0, 0, x, y);
  1927. cp = this.CreateParams;
  1928. if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, false, out WindowRect)==false) {
  1929. return;
  1930. }
  1931. this.client_size = new Size(x, y);
  1932. SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  1933. }
  1934. protected void SetStyle(ControlStyles flag, bool value) {
  1935. if (value) {
  1936. control_style |= flag;
  1937. } else {
  1938. control_style &= ~flag;
  1939. }
  1940. }
  1941. #endregion // Public Instance Methods
  1942. #region Private Instance Methods
  1943. #endregion // Private Instance Methods
  1944. #region Private Instance Methods
  1945. internal virtual void DoDefaultAction() {
  1946. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1947. }
  1948. #endregion // Private Instance Methods
  1949. #region OnXXX methods
  1950. protected virtual void OnBackColorChanged(EventArgs e) {
  1951. if (BackColorChanged!=null) BackColorChanged(this, e);
  1952. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  1953. }
  1954. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  1955. if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
  1956. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  1957. }
  1958. protected virtual void OnBindingContextChanged(EventArgs e) {
  1959. if (BindingContextChanged!=null) BindingContextChanged(this, e);
  1960. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  1961. }
  1962. protected virtual void OnCausesValidationChanged(EventArgs e) {
  1963. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1964. }
  1965. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  1966. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1967. }
  1968. protected virtual void OnClick(EventArgs e) {
  1969. if (Click!=null) Click(this, e);
  1970. }
  1971. protected virtual void OnContextMenuChanged(EventArgs e) {
  1972. if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
  1973. }
  1974. protected virtual void OnControlAdded(ControlEventArgs e) {
  1975. if (ControlAdded!=null) ControlAdded(this, e);
  1976. }
  1977. protected virtual void OnControlRemoved(ControlEventArgs e) {
  1978. if (ControlRemoved!=null) ControlRemoved(this, e);
  1979. }
  1980. protected virtual void OnCreateControl() {
  1981. // Override me!
  1982. }
  1983. protected virtual void OnCursorChanged(EventArgs e) {
  1984. if (CursorChanged!=null) CursorChanged(this, e);
  1985. }
  1986. protected virtual void OnDockChanged(EventArgs e) {
  1987. if (DockChanged!=null) DockChanged(this, e);
  1988. }
  1989. protected virtual void OnDoubleClick(EventArgs e) {
  1990. if (DoubleClick!=null) DoubleClick(this, e);
  1991. }
  1992. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  1993. if (DragDrop!=null) DragDrop(this, drgevent);
  1994. }
  1995. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  1996. if (DragEnter!=null) DragEnter(this, drgevent);
  1997. }
  1998. protected virtual void OnDragLeave(EventArgs e) {
  1999. if (DragLeave!=null) DragLeave(this, e);
  2000. }
  2001. protected virtual void OnDragOver(DragEventArgs drgevent) {
  2002. if (DragOver!=null) DragOver(this, drgevent);
  2003. }
  2004. protected virtual void OnEnabledChanged(EventArgs e) {
  2005. if (EnabledChanged!=null) EnabledChanged(this, e);
  2006. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
  2007. }
  2008. protected virtual void OnEnter(EventArgs e) {
  2009. if (Enter!=null) Enter(this, e);
  2010. }
  2011. protected virtual void OnFontChanged(EventArgs e) {
  2012. if (FontChanged!=null) FontChanged(this, e);
  2013. }
  2014. protected virtual void OnForeColorChanged(EventArgs e) {
  2015. if (ForeColorChanged!=null) ForeColorChanged(this, e);
  2016. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  2017. }
  2018. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  2019. if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
  2020. }
  2021. protected virtual void OnGotFocus(EventArgs e) {
  2022. if (GotFocus!=null) GotFocus(this, e);
  2023. }
  2024. protected virtual void OnHandleCreated(EventArgs e) {
  2025. if (HandleCreated!=null) HandleCreated(this, e);
  2026. }
  2027. protected virtual void OnHandleDestroyed(EventArgs e) {
  2028. if (HandleDestroyed!=null) HandleDestroyed(this, e);
  2029. }
  2030. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  2031. if (HelpRequested!=null) HelpRequested(this, hevent);
  2032. }
  2033. protected virtual void OnImeModeChanged(EventArgs e) {
  2034. if (ImeModeChanged!=null) ImeModeChanged(this, e);
  2035. }
  2036. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  2037. if (Invalidated!=null) Invalidated(this, e);
  2038. }
  2039. protected virtual void OnKeyDown(KeyEventArgs e) {
  2040. if (KeyDown!=null) KeyDown(this, e);
  2041. }
  2042. protected virtual void OnKeyUp(KeyEventArgs e) {
  2043. if (KeyUp!=null) KeyUp(this, e);
  2044. }
  2045. protected virtual void OnLayout(LayoutEventArgs levent) {
  2046. if (Layout!=null) Layout(this, levent);
  2047. }
  2048. protected virtual void OnLeave(EventArgs e) {
  2049. if (Leave!=null) Leave(this, e);
  2050. }
  2051. protected virtual void OnLocationChanged(EventArgs e) {
  2052. if (LocationChanged!=null) LocationChanged(this, e);
  2053. }
  2054. protected virtual void OnLostFocus(EventArgs e) {
  2055. if (LostFocus!=null) LostFocus(this, e);
  2056. }
  2057. protected virtual void OnMouseDown(MouseEventArgs e) {
  2058. if (MouseDown!=null) MouseDown(this, e);
  2059. }
  2060. protected virtual void OnMouseEnter(EventArgs e) {
  2061. if (MouseEnter!=null) MouseEnter(this, e);
  2062. }
  2063. protected virtual void OnMouseHover(EventArgs e) {
  2064. if (MouseHover!=null) MouseHover(this, e);
  2065. }
  2066. protected virtual void OnMouseLeave(EventArgs e) {
  2067. if (MouseLeave!=null) MouseLeave(this, e);
  2068. }
  2069. protected virtual void OnMouseMove(MouseEventArgs e) {
  2070. if (MouseMove!=null) MouseMove(this, e);
  2071. }
  2072. protected virtual void OnMouseUp(MouseEventArgs e) {
  2073. if (MouseUp!=null) MouseUp(this, e);
  2074. }
  2075. protected virtual void OnMouseWheel(MouseEventArgs e) {
  2076. if (MouseWheel!=null) MouseWheel(this, e);
  2077. }
  2078. protected virtual void OnMove(EventArgs e) {
  2079. if (Move!=null) Move(this, e);
  2080. }
  2081. protected virtual void OnNotifyMessage(Message m) {
  2082. // Override me!
  2083. }
  2084. protected virtual void OnPaint(PaintEventArgs e) {
  2085. if (Paint!=null) Paint(this, e);
  2086. }
  2087. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  2088. // Override me!
  2089. }
  2090. protected virtual void OnParentBackColorChanged(EventArgs e) {
  2091. if (background_color.IsEmpty && background_image==null) {
  2092. Invalidate();
  2093. OnBackColorChanged(e);
  2094. }
  2095. }
  2096. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  2097. if (background_color.IsEmpty && background_image==null) {
  2098. Invalidate();
  2099. OnBackgroundImageChanged(e);
  2100. }
  2101. }
  2102. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  2103. if (binding_context==null) {
  2104. binding_context=Parent.binding_context;
  2105. OnBindingContextChanged(e);
  2106. }
  2107. }
  2108. protected virtual void OnParentChanged(EventArgs e) {
  2109. if (ParentChanged!=null) ParentChanged(this, e);
  2110. }
  2111. protected virtual void OnParentEnabledChanged(EventArgs e) {
  2112. if ((is_enabled && !Parent.is_enabled) || (!is_enabled && Parent.is_enabled)) {
  2113. is_enabled=false;
  2114. Invalidate();
  2115. EnabledChanged(this, e);
  2116. }
  2117. }
  2118. protected virtual void OnParentFontChanged(EventArgs e) {
  2119. if (font==null) {
  2120. Invalidate();
  2121. OnFontChanged(e);
  2122. }
  2123. }
  2124. protected virtual void OnParentForeColorChanged(EventArgs e) {
  2125. if (foreground_color.IsEmpty) {
  2126. Invalidate();
  2127. OnForeColorChanged(e);
  2128. }
  2129. }
  2130. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  2131. if (right_to_left==RightToLeft.Inherit) {
  2132. Invalidate();
  2133. OnRightToLeftChanged(e);
  2134. }
  2135. }
  2136. protected virtual void OnParentVisibleChanged(EventArgs e) {
  2137. if (is_visible!=Parent.is_visible) {
  2138. is_visible=false;
  2139. Invalidate();
  2140. OnVisibleChanged(e);
  2141. }
  2142. }
  2143. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  2144. if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
  2145. }
  2146. protected virtual void OnResize(EventArgs e) {
  2147. if (Resize!=null) Resize(this, e);
  2148. PerformLayout(this, "bounds");
  2149. if (parent != null) {
  2150. parent.PerformLayout();
  2151. }
  2152. }
  2153. protected virtual void OnRightToLeftChanged(EventArgs e) {
  2154. if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
  2155. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  2156. }
  2157. protected virtual void OnSizeChanged(EventArgs e) {
  2158. OnResize(e);
  2159. if (SizeChanged!=null) SizeChanged(this, e);
  2160. }
  2161. protected virtual void OnStyleChanged(EventArgs e) {
  2162. if (StyleChanged!=null) StyleChanged(this, e);
  2163. }
  2164. protected virtual void OnSystemColorsChanged(EventArgs e) {
  2165. if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
  2166. }
  2167. protected virtual void OnTabIndexChanged(EventArgs e) {
  2168. if (TabIndexChanged!=null) TabIndexChanged(this, e);
  2169. }
  2170. protected virtual void OnTabStopChanged(EventArgs e) {
  2171. if (TabStopChanged!=null) TabStopChanged(this, e);
  2172. }
  2173. protected virtual void OnTextChanged(EventArgs e) {
  2174. if (TextChanged!=null) TextChanged(this, e);
  2175. }
  2176. protected virtual void OnValidated(EventArgs e) {
  2177. if (Validated!=null) Validated(this, e);
  2178. }
  2179. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  2180. if (Validating!=null) Validating(this, e);
  2181. }
  2182. protected virtual void OnVisibleChanged(EventArgs e) {
  2183. if (!is_visible) {
  2184. if (dc_mem!=null) {
  2185. dc_mem.Dispose ();
  2186. bmp_mem=null;
  2187. }
  2188. if (bmp_mem!=null) {
  2189. bmp_mem.Dispose();
  2190. bmp_mem=null;
  2191. }
  2192. } else {
  2193. if (!is_disposed) {
  2194. if (!this.IsHandleCreated) {
  2195. this.CreateHandle();
  2196. }
  2197. PerformLayout();
  2198. }
  2199. }
  2200. if (VisibleChanged!=null) VisibleChanged(this, e);
  2201. // We need to tell our kids
  2202. for (int i=0; i<child_controls.Count; i++) {
  2203. child_controls[i].OnParentVisibleChanged(e);
  2204. }
  2205. }
  2206. #endregion // OnXXX methods
  2207. #region Events
  2208. public event EventHandler BackColorChanged;
  2209. public event EventHandler BackgroundImageChanged;
  2210. public event EventHandler BindingContextChanged;
  2211. public event EventHandler CausesValidationChanged;
  2212. public event UICuesEventHandler ChangeUICues;
  2213. public event EventHandler Click;
  2214. public event EventHandler ContextMenuChanged;
  2215. public event ControlEventHandler ControlAdded;
  2216. public event ControlEventHandler ControlRemoved;
  2217. public event EventHandler CursorChanged;
  2218. public event EventHandler DockChanged;
  2219. public event EventHandler DoubleClick;
  2220. public event DragEventHandler DragDrop;
  2221. public event DragEventHandler DragEnter;
  2222. public event EventHandler DragLeave;
  2223. public event DragEventHandler DragOver;
  2224. public event EventHandler EnabledChanged;
  2225. public event EventHandler Enter;
  2226. public event EventHandler FontChanged;
  2227. public event EventHandler ForeColorChanged;
  2228. public event GiveFeedbackEventHandler GiveFeedback;
  2229. public event EventHandler GotFocus;
  2230. public event EventHandler HandleCreated;
  2231. public event EventHandler HandleDestroyed;
  2232. public event HelpEventHandler HelpRequested;
  2233. public event EventHandler ImeModeChanged;
  2234. public event InvalidateEventHandler Invalidated;
  2235. public event KeyEventHandler KeyDown;
  2236. public event KeyPressEventHandler KeyPress;
  2237. public event KeyEventHandler KeyUp;
  2238. public event LayoutEventHandler Layout;
  2239. public event EventHandler Leave;
  2240. public event EventHandler LocationChanged;
  2241. public event EventHandler LostFocus;
  2242. public event MouseEventHandler MouseDown;
  2243. public event EventHandler MouseEnter;
  2244. public event EventHandler MouseHover;
  2245. public event EventHandler MouseLeave;
  2246. public event MouseEventHandler MouseMove;
  2247. public event MouseEventHandler MouseUp;
  2248. public event MouseEventHandler MouseWheel;
  2249. public event EventHandler Move;
  2250. public event PaintEventHandler Paint;
  2251. public event EventHandler ParentChanged;
  2252. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
  2253. public event QueryContinueDragEventHandler QueryContinueDrag;
  2254. public event EventHandler Resize;
  2255. public event EventHandler RightToLeftChanged;
  2256. public event EventHandler SizeChanged;
  2257. public event EventHandler StyleChanged;
  2258. public event EventHandler SystemColorsChanged;
  2259. public event EventHandler TabIndexChanged;
  2260. public event EventHandler TabStopChanged;
  2261. public event EventHandler TextChanged;
  2262. public event EventHandler Validated;
  2263. public event CancelEventHandler Validating;
  2264. public event EventHandler VisibleChanged;
  2265. #endregion // Events
  2266. #region Private Methods
  2267. internal static int LowOrder (int param)
  2268. {
  2269. return (param & 0xffff);
  2270. }
  2271. internal static int HighOrder (int param)
  2272. {
  2273. return (param >> 16);
  2274. }
  2275. internal static MouseButtons FromParamToMouseButtons (int param)
  2276. {
  2277. MouseButtons buttons = MouseButtons.None;
  2278. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  2279. buttons |= MouseButtons.Left;
  2280. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  2281. buttons |= MouseButtons.Middle;
  2282. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  2283. buttons |= MouseButtons.Right;
  2284. return buttons;
  2285. }
  2286. #endregion
  2287. }
  2288. }