Control.cs 70 KB

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