Control.cs 69 KB

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