Control.cs 72 KB

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