Control.cs 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410
  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-2006 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. // Partially 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. // COMPLETE
  33. using System;
  34. using System.ComponentModel;
  35. using System.ComponentModel.Design;
  36. using System.ComponentModel.Design.Serialization;
  37. using System.Collections;
  38. using System.Diagnostics;
  39. using System.Drawing;
  40. using System.Drawing.Drawing2D;
  41. using System.Reflection;
  42. using System.Runtime.InteropServices;
  43. using System.Security;
  44. using System.Threading;
  45. namespace System.Windows.Forms
  46. {
  47. [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  48. [DefaultProperty("Text")]
  49. [DefaultEvent("Click")]
  50. [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  51. [ToolboxItemFilter("System.Windows.Forms")]
  52. public class Control : Component, ISynchronizeInvoke, IWin32Window
  53. {
  54. #region Local Variables
  55. // Basic
  56. internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
  57. internal object creator_thread; // thread that created the control
  58. internal ControlNativeWindow window; // object for native window handle
  59. internal string name; // for object naming
  60. // State
  61. internal bool is_created; // true if OnCreateControl has been sent
  62. internal bool has_focus; // true if control has focus
  63. internal bool is_visible; // true if control is visible
  64. internal bool is_entered; // is the mouse inside the control?
  65. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  66. internal bool is_selected; // true if control is selected
  67. internal bool is_accessible; // true if the control is visible to accessibility applications
  68. internal bool is_captured; // tracks if the control has captured the mouse
  69. internal bool is_toplevel; // tracks if the control is a toplevel window
  70. internal bool is_recreating; // tracks if the handle for the control is being recreated
  71. internal bool causes_validation; // tracks if validation is executed on changes
  72. internal int tab_index; // position in tab order of siblings
  73. internal bool tab_stop = true; // is the control a tab stop?
  74. internal bool is_disposed; // has the window already been disposed?
  75. internal Size client_size; // size of the client area (window excluding decorations)
  76. internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  77. internal ControlStyles control_style; // rather win32-specific, style bits for control
  78. internal ImeMode ime_mode = ImeMode.Inherit;
  79. internal bool layout_pending; // true if our parent needs to re-layout us
  80. internal object control_tag; // object that contains data about our control
  81. internal int mouse_clicks; // Counter for mouse clicks
  82. internal Cursor cursor; // Cursor for the window
  83. internal bool allow_drop; // true if the control accepts droping objects on it
  84. // Visuals
  85. internal Color foreground_color; // foreground color for control
  86. internal Color background_color; // background color for control
  87. internal Image background_image; // background image for control
  88. internal Font font; // font for control
  89. internal string text; // window/title text for control
  90. internal BorderStyle border_style; // Border style of control
  91. // Layout
  92. internal AnchorStyles anchor_style; // anchoring requirements for our control
  93. internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
  94. internal int dist_left; // distance to the left border of the parent
  95. internal int dist_top; // distance to the top border of the parent
  96. internal int dist_right; // distance to the right border of the parent
  97. internal int dist_bottom; // distance to the bottom border of the parent
  98. // to be categorized...
  99. static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
  100. internal ControlCollection child_controls; // our children
  101. internal Control parent; // our parent control
  102. internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
  103. internal BindingContext binding_context; // TODO
  104. internal RightToLeft right_to_left; // drawing direction for control
  105. internal int layout_suspended;
  106. internal ContextMenu context_menu; // Context menu associated with the control
  107. private Graphics dc_mem; // Graphics context for double buffering
  108. private Bitmap bmp_mem; // Bitmap for double buffering control
  109. private bool needs_redraw = true;
  110. private ControlBindingsCollection data_bindings;
  111. #if NET_2_0
  112. internal bool use_compatible_text_rendering;
  113. #endif
  114. #endregion // Local Variables
  115. #region Private Classes
  116. // This helper class allows us to dispatch messages to Control.WndProc
  117. internal class ControlNativeWindow : NativeWindow {
  118. private Control owner;
  119. public ControlNativeWindow(Control control) : base() {
  120. this.owner=control;
  121. }
  122. public Control Owner {
  123. get {
  124. return owner;
  125. }
  126. }
  127. static internal Control ControlFromHandle(IntPtr hWnd) {
  128. ControlNativeWindow window;
  129. window = (ControlNativeWindow)window_collection[hWnd];
  130. if (window != null) {
  131. return window.owner;
  132. }
  133. return null;
  134. }
  135. protected override void WndProc(ref Message m) {
  136. owner.WndProc(ref m);
  137. }
  138. }
  139. #endregion
  140. #region Public Classes
  141. [ComVisible(true)]
  142. public class ControlAccessibleObject : AccessibleObject {
  143. #region ControlAccessibleObject Local Variables
  144. private Control owner;
  145. #endregion // ControlAccessibleObject Local Variables
  146. #region ControlAccessibleObject Constructors
  147. public ControlAccessibleObject(Control ownerControl) {
  148. this.owner = ownerControl;
  149. }
  150. #endregion // ControlAccessibleObject Constructors
  151. #region ControlAccessibleObject Public Instance Properties
  152. public override string DefaultAction {
  153. get {
  154. return base.DefaultAction;
  155. }
  156. }
  157. public override string Description {
  158. get {
  159. return base.Description;
  160. }
  161. }
  162. public IntPtr Handle {
  163. get {
  164. return owner.Handle;
  165. }
  166. set {
  167. // We don't want to let them set it
  168. }
  169. }
  170. public override string Help {
  171. get {
  172. return base.Help;
  173. }
  174. }
  175. public override string KeyboardShortcut {
  176. get {
  177. return base.KeyboardShortcut;
  178. }
  179. }
  180. public override string Name {
  181. get {
  182. return base.Name;
  183. }
  184. set {
  185. base.Name = value;
  186. }
  187. }
  188. public Control Owner {
  189. get {
  190. return owner;
  191. }
  192. }
  193. public override AccessibleObject Parent {
  194. get {
  195. return base.Parent;
  196. }
  197. }
  198. public override AccessibleRole Role {
  199. get {
  200. return base.Role;
  201. }
  202. }
  203. #endregion // ControlAccessibleObject Public Instance Properties
  204. #region ControlAccessibleObject Public Instance Methods
  205. public override int GetHelpTopic(out string FileName) {
  206. return base.GetHelpTopic (out FileName);
  207. }
  208. [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
  209. public void NotifyClients(AccessibleEvents accEvent) {
  210. throw new NotImplementedException();
  211. }
  212. [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
  213. public void NotifyClients(AccessibleEvents accEvent, int childID) {
  214. throw new NotImplementedException();
  215. }
  216. public override string ToString() {
  217. return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
  218. }
  219. #endregion // ControlAccessibleObject Public Instance Methods
  220. }
  221. [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  222. [ListBindable(false)]
  223. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  224. #region ControlCollection Local Variables
  225. private ArrayList list;
  226. private ArrayList impl_list;
  227. private Control [] all_controls;
  228. internal Control owner;
  229. #endregion // ControlCollection Local Variables
  230. #region ControlCollection Public Constructor
  231. public ControlCollection(Control owner) {
  232. this.owner=owner;
  233. this.list=new ArrayList();
  234. }
  235. #endregion
  236. #region ControlCollection Public Instance Properties
  237. public int Count {
  238. get {
  239. return list.Count;
  240. }
  241. }
  242. public virtual bool IsReadOnly {
  243. get {
  244. return list.IsReadOnly;
  245. }
  246. }
  247. public virtual Control this[int index] {
  248. get {
  249. if (index < 0 || index >= list.Count) {
  250. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  251. }
  252. return (Control)list[index];
  253. }
  254. }
  255. #endregion // ControlCollection Public Instance Properties
  256. #region ControlCollection Private Instance Methods
  257. public virtual void Add (Control value)
  258. {
  259. if (value == null)
  260. return;
  261. if (Contains (value)) {
  262. owner.PerformLayout();
  263. return;
  264. }
  265. if (value.tab_index == -1) {
  266. int end;
  267. int index;
  268. int use;
  269. use = 0;
  270. end = owner.child_controls.Count;
  271. for (int i = 0; i < end; i++) {
  272. index = owner.child_controls[i].tab_index;
  273. if (index >= use) {
  274. use = index + 1;
  275. }
  276. }
  277. value.tab_index = use;
  278. }
  279. if (value.parent != null) {
  280. value.parent.Controls.Remove(value);
  281. }
  282. all_controls = null;
  283. list.Add (value);
  284. value.ChangeParent(owner);
  285. value.InitLayout();
  286. owner.UpdateZOrder();
  287. owner.PerformLayout(value, "Parent");
  288. owner.OnControlAdded(new ControlEventArgs(value));
  289. }
  290. internal void AddToList (Control c)
  291. {
  292. all_controls = null;
  293. list.Add (c);
  294. }
  295. internal virtual void AddImplicit (Control control)
  296. {
  297. if (impl_list == null)
  298. impl_list = new ArrayList ();
  299. all_controls = null;
  300. impl_list.Add (control);
  301. control.ChangeParent (owner);
  302. owner.UpdateZOrder ();
  303. owner.PerformLayout (control, "Parent");
  304. owner.OnControlAdded (new ControlEventArgs (control));
  305. }
  306. public virtual void AddRange (Control[] controls)
  307. {
  308. if (controls == null)
  309. throw new ArgumentNullException ("controls");
  310. owner.SuspendLayout ();
  311. try {
  312. for (int i = 0; i < controls.Length; i++)
  313. Add (controls[i]);
  314. } finally {
  315. owner.ResumeLayout ();
  316. }
  317. }
  318. internal virtual void AddRangeImplicit (Control [] controls)
  319. {
  320. if (controls == null)
  321. throw new ArgumentNullException ("controls");
  322. owner.SuspendLayout ();
  323. try {
  324. for (int i = 0; i < controls.Length; i++)
  325. AddImplicit (controls [i]);
  326. } finally {
  327. owner.ResumeLayout ();
  328. }
  329. }
  330. public virtual void Clear ()
  331. {
  332. all_controls = null;
  333. // MS sends remove events in reverse order
  334. while (list.Count > 0) {
  335. RemoveAt(list.Count - 1);
  336. }
  337. }
  338. internal virtual void ClearImplicit ()
  339. {
  340. if (impl_list == null)
  341. return;
  342. all_controls = null;
  343. impl_list.Clear ();
  344. }
  345. public bool Contains (Control value)
  346. {
  347. for (int i = list.Count; i > 0; ) {
  348. i--;
  349. if (list [i] == value) {
  350. // Do we need to do anything here?
  351. return true;
  352. }
  353. }
  354. return false;
  355. }
  356. internal bool ImplicitContains (Control value)
  357. {
  358. if (impl_list == null)
  359. return false;
  360. for (int i = impl_list.Count; i > 0; ) {
  361. i--;
  362. if (impl_list [i] == value) {
  363. // Do we need to do anything here?
  364. return true;
  365. }
  366. }
  367. return false;
  368. }
  369. internal bool AllContains (Control value)
  370. {
  371. return Contains (value) || ImplicitContains (value);
  372. }
  373. public virtual void CopyTo (Array array, int index)
  374. {
  375. list.CopyTo(array, index);
  376. }
  377. public override bool Equals(object other) {
  378. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  379. return(true);
  380. } else {
  381. return(false);
  382. }
  383. }
  384. public int GetChildIndex(Control child) {
  385. return GetChildIndex(child, false);
  386. }
  387. public int GetChildIndex(Control child, bool throwException) {
  388. int index;
  389. index=list.IndexOf(child);
  390. if (index==-1 && throwException) {
  391. throw new ArgumentException("Not a child control", "child");
  392. }
  393. return index;
  394. }
  395. public IEnumerator GetEnumerator() {
  396. return list.GetEnumerator();
  397. }
  398. internal IEnumerator GetAllEnumerator ()
  399. {
  400. Control [] res = GetAllControls ();
  401. return res.GetEnumerator ();
  402. }
  403. internal Control [] GetAllControls ()
  404. {
  405. if (all_controls != null)
  406. return all_controls;
  407. if (impl_list == null)
  408. return (Control []) list.ToArray (typeof (Control));
  409. Control [] res = new Control [list.Count + impl_list.Count];
  410. list.CopyTo (res);
  411. impl_list.CopyTo (res, list.Count);
  412. return res;
  413. }
  414. public override int GetHashCode() {
  415. return base.GetHashCode();
  416. }
  417. public int IndexOf(Control control) {
  418. return list.IndexOf(control);
  419. }
  420. public virtual void Remove(Control value) {
  421. all_controls = null;
  422. owner.PerformLayout(value, "Parent");
  423. owner.OnControlRemoved(new ControlEventArgs(value));
  424. list.Remove(value);
  425. value.ChangeParent(null);
  426. owner.UpdateZOrder();
  427. }
  428. internal virtual void RemoveImplicit (Control control)
  429. {
  430. if (impl_list != null) {
  431. all_controls = null;
  432. owner.PerformLayout (control, "Parent");
  433. owner.OnControlRemoved (new ControlEventArgs (control));
  434. impl_list.Remove (control);
  435. }
  436. control.ChangeParent (null);
  437. owner.UpdateZOrder ();
  438. }
  439. public void RemoveAt(int index) {
  440. if (index < 0 || index >= list.Count) {
  441. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  442. }
  443. Remove ((Control)list[index]);
  444. }
  445. public void SetChildIndex(Control child, int newIndex) {
  446. int old_index;
  447. old_index=list.IndexOf(child);
  448. if (old_index==-1) {
  449. throw new ArgumentException("Not a child control", "child");
  450. }
  451. if (old_index==newIndex) {
  452. return;
  453. }
  454. RemoveAt(old_index);
  455. if (newIndex>list.Count) {
  456. list.Add(child);
  457. } else {
  458. list.Insert(newIndex, child);
  459. }
  460. child.parent = owner;
  461. owner.UpdateZOrder();
  462. }
  463. #endregion // ControlCollection Private Instance Methods
  464. #region ControlCollection Interface Properties
  465. object IList.this[int index] {
  466. get {
  467. if (index<0 || index>=list.Count) {
  468. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  469. }
  470. return this[index];
  471. }
  472. set {
  473. if (!(value is Control)) {
  474. throw new ArgumentException("Object of type Control required", "value");
  475. }
  476. list[index]=(Control)value;
  477. }
  478. }
  479. bool IList.IsFixedSize {
  480. get {
  481. return false;
  482. }
  483. }
  484. bool IList.IsReadOnly {
  485. get {
  486. return list.IsReadOnly;
  487. }
  488. }
  489. bool ICollection.IsSynchronized {
  490. get {
  491. return list.IsSynchronized;
  492. }
  493. }
  494. object ICollection.SyncRoot {
  495. get {
  496. return list.SyncRoot;
  497. }
  498. }
  499. #endregion // ControlCollection Interface Properties
  500. #region ControlCollection Interface Methods
  501. int IList.Add(object value) {
  502. if (value == null) {
  503. throw new ArgumentNullException("value", "Cannot add null controls");
  504. }
  505. if (!(value is Control)) {
  506. throw new ArgumentException("Object of type Control required", "value");
  507. }
  508. return list.Add(value);
  509. }
  510. bool IList.Contains(object value) {
  511. if (!(value is Control)) {
  512. throw new ArgumentException("Object of type Control required", "value");
  513. }
  514. return this.Contains((Control) value);
  515. }
  516. int IList.IndexOf(object value) {
  517. if (!(value is Control)) {
  518. throw new ArgumentException("Object of type Control required", "value");
  519. }
  520. return this.IndexOf((Control) value);
  521. }
  522. void IList.Insert(int index, object value) {
  523. if (!(value is Control)) {
  524. throw new ArgumentException("Object of type Control required", "value");
  525. }
  526. all_controls = null;
  527. list.Insert(index, value);
  528. }
  529. void IList.Remove(object value) {
  530. if (!(value is Control)) {
  531. throw new ArgumentException("Object of type Control required", "value");
  532. }
  533. all_controls = null;
  534. list.Remove(value);
  535. }
  536. void ICollection.CopyTo(Array array, int index) {
  537. if (list.Count>0) {
  538. list.CopyTo(array, index);
  539. }
  540. }
  541. Object ICloneable.Clone() {
  542. ControlCollection clone = new ControlCollection(this.owner);
  543. clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
  544. return clone;
  545. }
  546. #endregion // ControlCollection Interface Methods
  547. }
  548. #endregion // ControlCollection Class
  549. #region Public Constructors
  550. public Control() {
  551. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  552. is_created = false;
  553. is_visible = true;
  554. is_captured = false;
  555. is_disposed = false;
  556. is_enabled = true;
  557. is_entered = false;
  558. layout_pending = false;
  559. is_toplevel = false;
  560. causes_validation = true;
  561. has_focus = false;
  562. layout_suspended = 0;
  563. mouse_clicks = 1;
  564. tab_index = -1;
  565. cursor = null;
  566. right_to_left = RightToLeft.Inherit;
  567. border_style = BorderStyle.None;
  568. background_color = Color.Empty;
  569. dist_left = 0;
  570. dist_right = 0;
  571. dist_top = 0;
  572. dist_bottom = 0;
  573. #if NET_2_0
  574. use_compatible_text_rendering = Application.use_compatible_text_rendering;
  575. #endif
  576. control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
  577. ControlStyles.Selectable | ControlStyles.StandardClick |
  578. ControlStyles.StandardDoubleClick;
  579. parent = null;
  580. background_image = null;
  581. text = string.Empty;
  582. name = string.Empty;
  583. window = new ControlNativeWindow(this);
  584. child_controls = CreateControlsInstance();
  585. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  586. client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  587. XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
  588. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
  589. bounds.X=-1;
  590. bounds.Y=-1;
  591. }
  592. }
  593. public Control(Control parent, string text) : this() {
  594. Text=text;
  595. Parent=parent;
  596. }
  597. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  598. Parent=parent;
  599. bounds.X=left;
  600. bounds.Y=top;
  601. bounds.Width=width;
  602. bounds.Height=height;
  603. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  604. Text=text;
  605. }
  606. public Control(string text) : this() {
  607. Text=text;
  608. }
  609. public Control(string text, int left, int top, int width, int height) : this() {
  610. bounds.X=left;
  611. bounds.Y=top;
  612. bounds.Width=width;
  613. bounds.Height=height;
  614. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  615. Text=text;
  616. }
  617. private delegate void RemoveDelegate(object c);
  618. protected override void Dispose(bool disposing) {
  619. is_disposed = true;
  620. if (dc_mem!=null) {
  621. dc_mem.Dispose();
  622. dc_mem=null;
  623. }
  624. if (bmp_mem!=null) {
  625. bmp_mem.Dispose();
  626. bmp_mem=null;
  627. }
  628. if (this.InvokeRequired) {
  629. if (Application.MessageLoop) {
  630. this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
  631. this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
  632. }
  633. } else {
  634. DestroyHandle();
  635. controls.Remove(this);
  636. }
  637. }
  638. #endregion // Public Constructors
  639. #region Internal Properties
  640. internal BorderStyle InternalBorderStyle {
  641. get {
  642. return border_style;
  643. }
  644. set {
  645. if (!Enum.IsDefined (typeof (BorderStyle), value))
  646. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
  647. if (border_style != value) {
  648. border_style = value;
  649. if (IsHandleCreated) {
  650. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  651. Refresh();
  652. }
  653. }
  654. }
  655. }
  656. #endregion // Internal Properties
  657. #region Private & Internal Methods
  658. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
  659. AsyncMethodResult result;
  660. AsyncMethodData data;
  661. if (!disposing) {
  662. Control p;
  663. p = this;
  664. do {
  665. if (!p.IsHandleCreated) {
  666. throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
  667. }
  668. p = p.parent;
  669. } while (p != null);
  670. }
  671. result = new AsyncMethodResult ();
  672. data = new AsyncMethodData ();
  673. data.Method = method;
  674. data.Args = args;
  675. data.Result = result;
  676. #if NET_2_0
  677. if (!ExecutionContext.IsFlowSuppressed ()) {
  678. data.Context = ExecutionContext.Capture ();
  679. }
  680. #else
  681. #if !MWF_ON_MSRUNTIME
  682. if (SecurityManager.SecurityEnabled) {
  683. data.Stack = CompressedStack.GetCompressedStack ();
  684. }
  685. #endif
  686. #endif
  687. XplatUI.SendAsyncMethod (data);
  688. return result;
  689. }
  690. internal void PointToClient (ref int x, ref int y)
  691. {
  692. XplatUI.ScreenToClient (Handle, ref x, ref y);
  693. }
  694. internal void PointToScreen (ref int x, ref int y)
  695. {
  696. XplatUI.ClientToScreen (Handle, ref x, ref y);
  697. }
  698. internal Graphics DeviceContext {
  699. get {
  700. if (dc_mem==null) {
  701. CreateBuffers(this.Width, this.Height);
  702. }
  703. return dc_mem;
  704. }
  705. }
  706. private Bitmap ImageBuffer {
  707. get {
  708. if (bmp_mem==null) {
  709. CreateBuffers(this.Width, this.Height);
  710. }
  711. return bmp_mem;
  712. }
  713. }
  714. internal void CreateBuffers (int width, int height) {
  715. if (dc_mem != null) {
  716. dc_mem.Dispose ();
  717. }
  718. if (bmp_mem != null)
  719. bmp_mem.Dispose ();
  720. if (width < 1) {
  721. width = 1;
  722. }
  723. if (height < 1) {
  724. height = 1;
  725. }
  726. bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  727. dc_mem = Graphics.FromImage (bmp_mem);
  728. needs_redraw = true;
  729. }
  730. internal void InvalidateBuffers ()
  731. {
  732. if (dc_mem != null) {
  733. dc_mem.Dispose ();
  734. }
  735. if (bmp_mem != null)
  736. bmp_mem.Dispose ();
  737. dc_mem = null;
  738. bmp_mem = null;
  739. needs_redraw = true;
  740. }
  741. internal static void SetChildColor(Control parent) {
  742. Control child;
  743. for (int i=0; i < parent.child_controls.Count; i++) {
  744. child=parent.child_controls[i];
  745. if (child.child_controls.Count>0) {
  746. SetChildColor(child);
  747. }
  748. }
  749. }
  750. internal bool Select(Control control) {
  751. Control parent;
  752. IContainerControl container;
  753. if (control == null) {
  754. return false;
  755. }
  756. parent = control.parent;
  757. if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
  758. while (parent != null) {
  759. if (!parent.Visible || !parent.is_enabled) {
  760. return false;
  761. }
  762. parent = parent.parent;
  763. }
  764. }
  765. control.is_selected = true;
  766. container = GetContainerControl();
  767. if (container != null) {
  768. container.ActiveControl = control;
  769. }
  770. if (control.IsHandleCreated) {
  771. XplatUI.SetFocus(control.window.Handle);
  772. }
  773. return true;
  774. }
  775. internal virtual void DoDefaultAction() {
  776. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  777. }
  778. internal static int LowOrder (int param) {
  779. return ((int)(short)(param & 0xffff));
  780. }
  781. internal static int HighOrder (int param) {
  782. return ((int)(short)(param >> 16));
  783. }
  784. // This method exists so controls overriding OnPaintBackground can have default background painting done
  785. internal virtual void PaintControlBackground (PaintEventArgs pevent)
  786. {
  787. if (background_image == null) {
  788. pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), new Rectangle(pevent.ClipRectangle.X - 1, pevent.ClipRectangle.Y - 1, pevent.ClipRectangle.Width + 2, pevent.ClipRectangle.Height + 2));
  789. return;
  790. }
  791. DrawBackgroundImage (pevent.Graphics);
  792. }
  793. void DrawBackgroundImage (Graphics g)
  794. {
  795. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  796. g.FillRectangle (b, ClientRectangle);
  797. }
  798. }
  799. internal virtual void DndEnter (DragEventArgs e)
  800. {
  801. try {
  802. OnDragEnter (e);
  803. } catch { }
  804. }
  805. internal virtual void DndOver (DragEventArgs e)
  806. {
  807. try {
  808. OnDragOver (e);
  809. } catch { }
  810. }
  811. internal virtual void DndDrop (DragEventArgs e)
  812. {
  813. try {
  814. OnDragDrop (e);
  815. } catch (Exception exc) {
  816. Console.Error.WriteLine ("MWF: Exception while dropping:");
  817. Console.Error.WriteLine (exc);
  818. }
  819. }
  820. internal virtual void DndLeave (EventArgs e)
  821. {
  822. try {
  823. OnDragLeave (e);
  824. } catch { }
  825. }
  826. internal virtual void DndFeedback(GiveFeedbackEventArgs e)
  827. {
  828. try {
  829. OnGiveFeedback(e);
  830. } catch { }
  831. }
  832. internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
  833. {
  834. try {
  835. OnQueryContinueDrag(e);
  836. } catch { }
  837. }
  838. internal static MouseButtons FromParamToMouseButtons (int param) {
  839. MouseButtons buttons = MouseButtons.None;
  840. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  841. buttons |= MouseButtons.Left;
  842. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  843. buttons |= MouseButtons.Middle;
  844. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  845. buttons |= MouseButtons.Right;
  846. return buttons;
  847. }
  848. internal virtual bool ProcessControlMnemonic(char charCode) {
  849. return ProcessMnemonic(charCode);
  850. }
  851. private static Control FindFlatForward(Control container, Control start) {
  852. Control found;
  853. int index;
  854. int end;
  855. found = null;
  856. end = container.child_controls.Count;
  857. if (start != null) {
  858. index = start.tab_index;
  859. } else {
  860. index = -1;
  861. }
  862. for (int i = 0; i < end; i++) {
  863. if (found == null) {
  864. if (container.child_controls[i].tab_index > index) {
  865. found = container.child_controls[i];
  866. }
  867. } else if (found.tab_index > container.child_controls[i].tab_index) {
  868. if (container.child_controls[i].tab_index > index) {
  869. found = container.child_controls[i];
  870. }
  871. }
  872. }
  873. return found;
  874. }
  875. private static Control FindControlForward(Control container, Control start) {
  876. Control found;
  877. Control p;
  878. found = null;
  879. if (start != null) {
  880. if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
  881. found = FindControlForward(start, null);
  882. if (found != null) {
  883. return found;
  884. }
  885. }
  886. p = start.parent;
  887. while (p != container) {
  888. found = FindFlatForward(p, start);
  889. if (found != null) {
  890. return found;
  891. }
  892. start = p;
  893. p = p.parent;
  894. }
  895. }
  896. return FindFlatForward(container, start);
  897. }
  898. private static Control FindFlatBackward(Control container, Control start) {
  899. Control found;
  900. int index;
  901. int end;
  902. found = null;
  903. end = container.child_controls.Count;
  904. if (start != null) {
  905. index = start.tab_index;
  906. } else {
  907. // FIXME: Possible speed-up: Keep the highest taborder index in the container
  908. index = -1;
  909. for (int i = 0; i < end; i++) {
  910. if (container.child_controls[i].tab_index > index) {
  911. index = container.child_controls[i].tab_index;
  912. }
  913. }
  914. index++;
  915. }
  916. for (int i = 0; i < end; i++) {
  917. if (found == null) {
  918. if (container.child_controls[i].tab_index < index) {
  919. found = container.child_controls[i];
  920. }
  921. } else if (found.tab_index < container.child_controls[i].tab_index) {
  922. if (container.child_controls[i].tab_index < index) {
  923. found = container.child_controls[i];
  924. }
  925. }
  926. }
  927. return found;
  928. }
  929. private static Control FindControlBackward(Control container, Control start) {
  930. Control found;
  931. found = null;
  932. if (start != null) {
  933. found = FindFlatBackward(start.parent, start);
  934. if (found == null && start.parent != container) {
  935. return start.parent;
  936. }
  937. }
  938. if (found == null) {
  939. found = FindFlatBackward(container, start);
  940. }
  941. while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
  942. found = FindControlBackward(found, null);
  943. if (found != null) {
  944. return found;
  945. }
  946. }
  947. return found;
  948. }
  949. private void HandleClick(int clicks) {
  950. if (GetStyle(ControlStyles.StandardClick)) {
  951. if (clicks > 1) {
  952. if (GetStyle(ControlStyles.StandardDoubleClick)) {
  953. OnDoubleClick(EventArgs.Empty);
  954. } else {
  955. OnClick(EventArgs.Empty);
  956. }
  957. } else {
  958. OnClick(EventArgs.Empty);
  959. }
  960. }
  961. }
  962. private void CheckDataBindings ()
  963. {
  964. if (data_bindings == null)
  965. return;
  966. BindingContext binding_context = BindingContext;
  967. foreach (Binding binding in data_bindings) {
  968. binding.Check (binding_context);
  969. }
  970. }
  971. private void ChangeParent(Control new_parent) {
  972. bool pre_enabled;
  973. bool pre_visible;
  974. Font pre_font;
  975. Color pre_fore_color;
  976. Color pre_back_color;
  977. RightToLeft pre_rtl;
  978. // These properties are inherited from our parent
  979. // Get them pre parent-change and then send events
  980. // if they are changed after we have our new parent
  981. pre_enabled = Enabled;
  982. pre_visible = Visible;
  983. pre_font = Font;
  984. pre_fore_color = ForeColor;
  985. pre_back_color = BackColor;
  986. pre_rtl = RightToLeft;
  987. // MS doesn't seem to send a CursorChangedEvent
  988. parent = new_parent;
  989. if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
  990. XplatUI.SetParent(Handle, new_parent.Handle);
  991. }
  992. OnParentChanged(EventArgs.Empty);
  993. if (pre_enabled != Enabled) {
  994. OnEnabledChanged(EventArgs.Empty);
  995. }
  996. if (pre_visible != Visible) {
  997. OnVisibleChanged(EventArgs.Empty);
  998. }
  999. if (pre_font != Font) {
  1000. OnFontChanged(EventArgs.Empty);
  1001. }
  1002. if (pre_fore_color != ForeColor) {
  1003. OnForeColorChanged(EventArgs.Empty);
  1004. }
  1005. if (pre_back_color != BackColor) {
  1006. OnBackColorChanged(EventArgs.Empty);
  1007. }
  1008. if (pre_rtl != RightToLeft) {
  1009. // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
  1010. // because when RTL changes they have to recreate the win32 control
  1011. // We don't really need that (until someone runs into compatibility issues)
  1012. OnRightToLeftChanged(EventArgs.Empty);
  1013. }
  1014. if ((new_parent != null) && new_parent.Created && !Created) {
  1015. CreateControl();
  1016. }
  1017. if ((binding_context == null) && Created) {
  1018. OnBindingContextChanged(EventArgs.Empty);
  1019. }
  1020. }
  1021. private void UpdateDistances() {
  1022. dist_left = bounds.X;
  1023. dist_top = bounds.Y;
  1024. if ((parent != null) && (parent.layout_suspended == 0)) {
  1025. dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
  1026. dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
  1027. }
  1028. }
  1029. #endregion // Private & Internal Methods
  1030. #region Public Static Properties
  1031. public static Color DefaultBackColor {
  1032. get {
  1033. return ThemeEngine.Current.DefaultControlBackColor;
  1034. }
  1035. }
  1036. public static Font DefaultFont {
  1037. get {
  1038. return ThemeEngine.Current.DefaultFont;
  1039. }
  1040. }
  1041. public static Color DefaultForeColor {
  1042. get {
  1043. return ThemeEngine.Current.DefaultControlForeColor;
  1044. }
  1045. }
  1046. public static Keys ModifierKeys {
  1047. get {
  1048. return XplatUI.State.ModifierKeys;
  1049. }
  1050. }
  1051. public static MouseButtons MouseButtons {
  1052. get {
  1053. return XplatUI.State.MouseButtons;
  1054. }
  1055. }
  1056. public static Point MousePosition {
  1057. get {
  1058. return Cursor.Position;
  1059. }
  1060. }
  1061. #if NET_2_0
  1062. [MonoTODO]
  1063. public static bool CheckForIllegalCrossThreadCalls
  1064. {
  1065. set {
  1066. }
  1067. get {
  1068. return false;
  1069. }
  1070. }
  1071. #endif
  1072. #endregion // Public Static Properties
  1073. #region Public Instance Properties
  1074. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1075. [Browsable(false)]
  1076. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1077. public AccessibleObject AccessibilityObject {
  1078. get {
  1079. if (accessibility_object==null) {
  1080. accessibility_object=CreateAccessibilityInstance();
  1081. }
  1082. return accessibility_object;
  1083. }
  1084. }
  1085. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1086. [Browsable(false)]
  1087. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1088. public string AccessibleDefaultActionDescription {
  1089. get {
  1090. return AccessibilityObject.default_action;
  1091. }
  1092. set {
  1093. AccessibilityObject.default_action=value;
  1094. }
  1095. }
  1096. [Localizable(true)]
  1097. [DefaultValue(null)]
  1098. public string AccessibleDescription {
  1099. get {
  1100. return AccessibilityObject.description;
  1101. }
  1102. set {
  1103. AccessibilityObject.description=value;
  1104. }
  1105. }
  1106. [Localizable(true)]
  1107. [DefaultValue(null)]
  1108. public string AccessibleName {
  1109. get {
  1110. return AccessibilityObject.Name;
  1111. }
  1112. set {
  1113. AccessibilityObject.Name=value;
  1114. }
  1115. }
  1116. [DefaultValue(AccessibleRole.Default)]
  1117. [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
  1118. public AccessibleRole AccessibleRole {
  1119. get {
  1120. return AccessibilityObject.role;
  1121. }
  1122. set {
  1123. AccessibilityObject.role=value;
  1124. }
  1125. }
  1126. [DefaultValue(false)]
  1127. public virtual bool AllowDrop {
  1128. get {
  1129. return allow_drop;
  1130. }
  1131. set {
  1132. if (allow_drop == value)
  1133. return;
  1134. allow_drop = value;
  1135. UpdateStyles();
  1136. XplatUI.SetAllowDrop (Handle, value);
  1137. }
  1138. }
  1139. [Localizable(true)]
  1140. [RefreshProperties(RefreshProperties.Repaint)]
  1141. [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
  1142. public virtual AnchorStyles Anchor {
  1143. get {
  1144. return anchor_style;
  1145. }
  1146. set {
  1147. anchor_style=value;
  1148. if (parent != null) {
  1149. parent.PerformLayout(this, "Parent");
  1150. }
  1151. }
  1152. }
  1153. [DispId(-501)]
  1154. public virtual Color BackColor {
  1155. get {
  1156. if (background_color.IsEmpty) {
  1157. if (parent!=null) {
  1158. return parent.BackColor;
  1159. }
  1160. return DefaultBackColor;
  1161. }
  1162. return background_color;
  1163. }
  1164. set {
  1165. background_color=value;
  1166. SetChildColor(this);
  1167. OnBackColorChanged(EventArgs.Empty);
  1168. Invalidate();
  1169. }
  1170. }
  1171. [Localizable(true)]
  1172. [DefaultValue(null)]
  1173. public virtual Image BackgroundImage {
  1174. get {
  1175. return background_image;
  1176. }
  1177. set {
  1178. if (background_image!=value) {
  1179. background_image=value;
  1180. OnBackgroundImageChanged(EventArgs.Empty);
  1181. }
  1182. }
  1183. }
  1184. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1185. [Browsable(false)]
  1186. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1187. public virtual BindingContext BindingContext {
  1188. get {
  1189. if (binding_context != null)
  1190. return binding_context;
  1191. if (Parent == null)
  1192. return null;
  1193. binding_context = Parent.BindingContext;
  1194. return binding_context;
  1195. }
  1196. set {
  1197. if (binding_context != value) {
  1198. binding_context = value;
  1199. OnBindingContextChanged(EventArgs.Empty);
  1200. }
  1201. }
  1202. }
  1203. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1204. [Browsable(false)]
  1205. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1206. public int Bottom {
  1207. get {
  1208. return bounds.Y+bounds.Height;
  1209. }
  1210. }
  1211. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1212. [Browsable(false)]
  1213. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1214. public Rectangle Bounds {
  1215. get {
  1216. return this.bounds;
  1217. }
  1218. set {
  1219. SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  1220. }
  1221. }
  1222. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1223. [Browsable(false)]
  1224. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1225. public bool CanFocus {
  1226. get {
  1227. if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
  1228. return true;
  1229. }
  1230. return false;
  1231. }
  1232. }
  1233. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1234. [Browsable(false)]
  1235. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1236. public bool CanSelect {
  1237. get {
  1238. Control parent;
  1239. if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
  1240. return false;
  1241. }
  1242. parent = this.parent;
  1243. while (parent != null) {
  1244. if (!parent.is_visible || !parent.is_enabled) {
  1245. return false;
  1246. }
  1247. parent = parent.parent;
  1248. }
  1249. return true;
  1250. }
  1251. }
  1252. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1253. [Browsable(false)]
  1254. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1255. public bool Capture {
  1256. get {
  1257. return this.is_captured;
  1258. }
  1259. set {
  1260. if (this.IsHandleCreated) {
  1261. if (value && !is_captured) {
  1262. is_captured = true;
  1263. XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
  1264. } else if (!value && is_captured) {
  1265. XplatUI.UngrabWindow(this.window.Handle);
  1266. is_captured = false;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. [DefaultValue(true)]
  1272. public bool CausesValidation {
  1273. get {
  1274. return this.causes_validation;
  1275. }
  1276. set {
  1277. if (this.causes_validation != value) {
  1278. causes_validation = value;
  1279. OnCausesValidationChanged(EventArgs.Empty);
  1280. }
  1281. }
  1282. }
  1283. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1284. [Browsable(false)]
  1285. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1286. public Rectangle ClientRectangle {
  1287. get {
  1288. client_rect.Width = client_size.Width;
  1289. client_rect.Height = client_size.Height;
  1290. return client_rect;
  1291. }
  1292. }
  1293. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1294. [Browsable(false)]
  1295. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1296. public Size ClientSize {
  1297. get {
  1298. #if notneeded
  1299. if ((this is Form) && (((Form)this).form_parent_window != null)) {
  1300. return ((Form)this).form_parent_window.ClientSize;
  1301. }
  1302. #endif
  1303. return client_size;
  1304. }
  1305. set {
  1306. this.SetClientSizeCore(value.Width, value.Height);
  1307. }
  1308. }
  1309. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1310. [Browsable(false)]
  1311. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1312. [DescriptionAttribute("ControlCompanyNameDescr")]
  1313. public String CompanyName {
  1314. get {
  1315. return "Mono Project, Novell, Inc.";
  1316. }
  1317. }
  1318. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1319. [Browsable(false)]
  1320. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1321. public bool ContainsFocus {
  1322. get {
  1323. if (this.Focused) {
  1324. return true;
  1325. }
  1326. for (int i=0; i < child_controls.Count; i++) {
  1327. if (child_controls[i].ContainsFocus) {
  1328. return true;
  1329. }
  1330. }
  1331. return false;
  1332. }
  1333. }
  1334. [DefaultValue(null)]
  1335. public virtual ContextMenu ContextMenu {
  1336. get {
  1337. return context_menu;
  1338. }
  1339. set {
  1340. if (context_menu != value) {
  1341. context_menu = value;
  1342. OnContextMenuChanged(EventArgs.Empty);
  1343. }
  1344. }
  1345. }
  1346. [Browsable(false)]
  1347. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  1348. public ControlCollection Controls {
  1349. get {
  1350. return this.child_controls;
  1351. }
  1352. }
  1353. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1354. [Browsable(false)]
  1355. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1356. public bool Created {
  1357. get {
  1358. if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
  1359. return true;
  1360. }
  1361. return false;
  1362. }
  1363. }
  1364. [AmbientValue(null)]
  1365. public virtual Cursor Cursor {
  1366. get {
  1367. if (cursor != null) {
  1368. return cursor;
  1369. }
  1370. if (parent != null) {
  1371. return parent.Cursor;
  1372. }
  1373. return Cursors.Default;
  1374. }
  1375. set {
  1376. if (cursor != value) {
  1377. Point pt;
  1378. cursor = value;
  1379. if (IsHandleCreated) {
  1380. pt = Cursor.Position;
  1381. if (bounds.Contains(pt)) {
  1382. if (GetChildAtPoint(pt) == null) {
  1383. if (cursor != null) {
  1384. XplatUI.SetCursor(window.Handle, cursor.handle);
  1385. } else {
  1386. if (parent != null) {
  1387. XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
  1388. } else {
  1389. XplatUI.SetCursor(window.Handle, Cursors.def.handle);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. OnCursorChanged(EventArgs.Empty);
  1396. }
  1397. }
  1398. }
  1399. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  1400. [ParenthesizePropertyName(true)]
  1401. [RefreshProperties(RefreshProperties.All)]
  1402. public ControlBindingsCollection DataBindings {
  1403. get {
  1404. if (data_bindings == null)
  1405. data_bindings = new ControlBindingsCollection (this);
  1406. return data_bindings;
  1407. }
  1408. }
  1409. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1410. [Browsable(false)]
  1411. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1412. public virtual Rectangle DisplayRectangle {
  1413. get {
  1414. return ClientRectangle;
  1415. }
  1416. }
  1417. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1418. [Browsable(false)]
  1419. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1420. public bool Disposing {
  1421. get {
  1422. return is_disposed;
  1423. }
  1424. }
  1425. [Localizable(true)]
  1426. [RefreshProperties(RefreshProperties.Repaint)]
  1427. [DefaultValue(DockStyle.None)]
  1428. public virtual DockStyle Dock {
  1429. get {
  1430. return dock_style;
  1431. }
  1432. set {
  1433. if (dock_style == value) {
  1434. return;
  1435. }
  1436. dock_style = value;
  1437. if (parent != null) {
  1438. parent.PerformLayout(this, "Parent");
  1439. }
  1440. OnDockChanged(EventArgs.Empty);
  1441. }
  1442. }
  1443. [DispId(-514)]
  1444. [Localizable(true)]
  1445. public bool Enabled {
  1446. get {
  1447. if (!is_enabled) {
  1448. return false;
  1449. }
  1450. if (parent != null) {
  1451. return parent.Enabled;
  1452. }
  1453. return true;
  1454. }
  1455. set {
  1456. if (is_enabled == value) {
  1457. return;
  1458. }
  1459. if (IsHandleCreated) {
  1460. if (this is Form) {
  1461. if (((Form)this).context == null) {
  1462. XplatUI.EnableWindow(window.Handle, value);
  1463. }
  1464. } else {
  1465. XplatUI.EnableWindow(window.Handle, value);
  1466. }
  1467. }
  1468. is_enabled = value;
  1469. Refresh();
  1470. OnEnabledChanged (EventArgs.Empty);
  1471. }
  1472. }
  1473. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1474. [Browsable(false)]
  1475. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1476. public virtual bool Focused {
  1477. get {
  1478. return this.has_focus;
  1479. }
  1480. }
  1481. [DispId(-512)]
  1482. [AmbientValue(null)]
  1483. [Localizable(true)]
  1484. public virtual Font Font {
  1485. get {
  1486. if (font != null) {
  1487. return font;
  1488. }
  1489. if (Parent != null && Parent.Font != null) {
  1490. return Parent.Font;
  1491. }
  1492. return DefaultFont;
  1493. }
  1494. set {
  1495. if (font != null && font.Equals (value)) {
  1496. return;
  1497. }
  1498. font = value;
  1499. Invalidate();
  1500. OnFontChanged (EventArgs.Empty);
  1501. }
  1502. }
  1503. [DispId(-513)]
  1504. public virtual Color ForeColor {
  1505. get {
  1506. if (foreground_color.IsEmpty) {
  1507. if (parent!=null) {
  1508. return parent.ForeColor;
  1509. }
  1510. return DefaultForeColor;
  1511. }
  1512. return foreground_color;
  1513. }
  1514. set {
  1515. if (foreground_color != value) {
  1516. foreground_color=value;
  1517. Invalidate();
  1518. OnForeColorChanged(EventArgs.Empty);
  1519. }
  1520. }
  1521. }
  1522. [DispId(-515)]
  1523. [Browsable(false)]
  1524. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1525. public IntPtr Handle { // IWin32Window
  1526. get {
  1527. if (!IsHandleCreated) {
  1528. CreateHandle();
  1529. }
  1530. return window.Handle;
  1531. }
  1532. }
  1533. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1534. [Browsable(false)]
  1535. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1536. public bool HasChildren {
  1537. get {
  1538. if (this.child_controls.Count>0) {
  1539. return true;
  1540. }
  1541. return false;
  1542. }
  1543. }
  1544. [EditorBrowsable(EditorBrowsableState.Always)]
  1545. [Browsable(false)]
  1546. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1547. public int Height {
  1548. get {
  1549. return this.bounds.Height;
  1550. }
  1551. set {
  1552. SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  1553. }
  1554. }
  1555. [AmbientValue(ImeMode.Inherit)]
  1556. [Localizable(true)]
  1557. public ImeMode ImeMode {
  1558. get {
  1559. if (ime_mode == DefaultImeMode) {
  1560. if (parent != null)
  1561. return parent.ImeMode;
  1562. else
  1563. return ImeMode.NoControl; // default value
  1564. }
  1565. return ime_mode;
  1566. }
  1567. set {
  1568. if (ime_mode != value) {
  1569. ime_mode = value;
  1570. OnImeModeChanged(EventArgs.Empty);
  1571. }
  1572. }
  1573. }
  1574. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1575. [Browsable(false)]
  1576. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1577. public bool InvokeRequired { // ISynchronizeInvoke
  1578. get {
  1579. if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
  1580. return true;
  1581. }
  1582. return false;
  1583. }
  1584. }
  1585. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1586. [Browsable(false)]
  1587. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1588. public bool IsAccessible {
  1589. get {
  1590. return is_accessible;
  1591. }
  1592. set {
  1593. is_accessible = value;
  1594. }
  1595. }
  1596. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1597. [Browsable(false)]
  1598. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1599. public bool IsDisposed {
  1600. get {
  1601. return this.is_disposed;
  1602. }
  1603. }
  1604. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1605. [Browsable(false)]
  1606. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1607. public bool IsHandleCreated {
  1608. get {
  1609. if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
  1610. return true;
  1611. }
  1612. return false;
  1613. }
  1614. }
  1615. [EditorBrowsable(EditorBrowsableState.Always)]
  1616. [Browsable(false)]
  1617. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1618. public int Left {
  1619. get {
  1620. return this.bounds.X;
  1621. }
  1622. set {
  1623. SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  1624. }
  1625. }
  1626. [Localizable(true)]
  1627. public Point Location {
  1628. get {
  1629. return new Point(bounds.X, bounds.Y);
  1630. }
  1631. set {
  1632. SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  1633. }
  1634. }
  1635. [Browsable(false)]
  1636. public string Name {
  1637. get {
  1638. return this.name;
  1639. }
  1640. set {
  1641. this.name=value;
  1642. }
  1643. }
  1644. [Browsable(false)]
  1645. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1646. public Control Parent {
  1647. get {
  1648. return this.parent;
  1649. }
  1650. set {
  1651. if (value == this) {
  1652. throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
  1653. }
  1654. if (parent!=value) {
  1655. if (value==null) {
  1656. parent.Controls.Remove(this);
  1657. return;
  1658. }
  1659. value.Controls.Add(this);
  1660. }
  1661. }
  1662. }
  1663. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1664. [Browsable(false)]
  1665. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1666. public string ProductName {
  1667. get {
  1668. Type t = typeof (AssemblyProductAttribute);
  1669. Assembly assembly = GetType().Module.Assembly;
  1670. object [] attrs = assembly.GetCustomAttributes (t, false);
  1671. AssemblyProductAttribute a = null;
  1672. // On MS we get a NullRefException if product attribute is not
  1673. // set.
  1674. if (attrs != null && attrs.Length > 0)
  1675. a = (AssemblyProductAttribute) attrs [0];
  1676. return a.Product;
  1677. }
  1678. }
  1679. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1680. [Browsable(false)]
  1681. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1682. public string ProductVersion {
  1683. get {
  1684. Type t = typeof (AssemblyVersionAttribute);
  1685. Assembly assembly = GetType().Module.Assembly;
  1686. object [] attrs = assembly.GetCustomAttributes (t, false);
  1687. if (attrs == null || attrs.Length < 1)
  1688. return "1.0.0.0";
  1689. return ((AssemblyVersionAttribute)attrs [0]).Version;
  1690. }
  1691. }
  1692. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1693. [Browsable(false)]
  1694. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1695. public bool RecreatingHandle {
  1696. get {
  1697. return is_recreating;
  1698. }
  1699. }
  1700. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1701. [Browsable(false)]
  1702. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1703. public Region Region {
  1704. get {
  1705. return new Region(this.bounds);
  1706. }
  1707. set {
  1708. Graphics g;
  1709. RectangleF r;
  1710. g = this.CreateGraphics();
  1711. r = value.GetBounds(g);
  1712. SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
  1713. g.Dispose();
  1714. }
  1715. }
  1716. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1717. [Browsable(false)]
  1718. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1719. public int Right {
  1720. get {
  1721. return this.bounds.X+this.bounds.Width;
  1722. }
  1723. }
  1724. [AmbientValue(RightToLeft.Inherit)]
  1725. [Localizable(true)]
  1726. public virtual RightToLeft RightToLeft {
  1727. get {
  1728. if (right_to_left == RightToLeft.Inherit) {
  1729. if (parent != null)
  1730. return parent.RightToLeft;
  1731. else
  1732. return RightToLeft.No; // default value
  1733. }
  1734. return right_to_left;
  1735. }
  1736. set {
  1737. if (value != right_to_left) {
  1738. right_to_left = value;
  1739. OnRightToLeftChanged(EventArgs.Empty);
  1740. }
  1741. }
  1742. }
  1743. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1744. public override ISite Site {
  1745. get {
  1746. return base.Site;
  1747. }
  1748. set {
  1749. base.Site = value;
  1750. }
  1751. }
  1752. [Localizable(true)]
  1753. public Size Size {
  1754. get {
  1755. return new Size(Width, Height);
  1756. }
  1757. set {
  1758. SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  1759. }
  1760. }
  1761. [Localizable(true)]
  1762. [MergableProperty(false)]
  1763. public int TabIndex {
  1764. get {
  1765. if (tab_index != -1) {
  1766. return tab_index;
  1767. }
  1768. return 0;
  1769. }
  1770. set {
  1771. if (tab_index != value) {
  1772. tab_index = value;
  1773. OnTabIndexChanged(EventArgs.Empty);
  1774. }
  1775. }
  1776. }
  1777. [DispId(-516)]
  1778. [DefaultValue(true)]
  1779. public bool TabStop {
  1780. get {
  1781. return tab_stop;
  1782. }
  1783. set {
  1784. if (tab_stop != value) {
  1785. tab_stop = value;
  1786. OnTabStopChanged(EventArgs.Empty);
  1787. }
  1788. }
  1789. }
  1790. [Localizable(false)]
  1791. [Bindable(true)]
  1792. [TypeConverter(typeof(StringConverter))]
  1793. [DefaultValue(null)]
  1794. public object Tag {
  1795. get {
  1796. return control_tag;
  1797. }
  1798. set {
  1799. control_tag = value;
  1800. }
  1801. }
  1802. [DispId(-517)]
  1803. [Localizable(true)]
  1804. [BindableAttribute(true)]
  1805. public virtual string Text {
  1806. get {
  1807. // Our implementation ignores ControlStyles.CacheText - we always cache
  1808. return this.text;
  1809. }
  1810. set {
  1811. if (value == null) {
  1812. value = String.Empty;
  1813. }
  1814. if (text!=value) {
  1815. text=value;
  1816. if (IsHandleCreated) {
  1817. XplatUI.Text(Handle, text);
  1818. }
  1819. OnTextChanged (EventArgs.Empty);
  1820. }
  1821. }
  1822. }
  1823. [EditorBrowsable(EditorBrowsableState.Always)]
  1824. [Browsable(false)]
  1825. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1826. public int Top {
  1827. get {
  1828. return this.bounds.Y;
  1829. }
  1830. set {
  1831. SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  1832. }
  1833. }
  1834. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1835. [Browsable(false)]
  1836. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1837. public Control TopLevelControl {
  1838. get {
  1839. Control p = this;
  1840. while (p.parent != null) {
  1841. p = p.parent;
  1842. }
  1843. return p;
  1844. }
  1845. }
  1846. [Localizable(true)]
  1847. public bool Visible {
  1848. get {
  1849. if (!is_visible) {
  1850. return false;
  1851. } else if (parent != null) {
  1852. return parent.Visible;
  1853. }
  1854. return true;
  1855. }
  1856. set {
  1857. SetVisibleCore(value);
  1858. }
  1859. }
  1860. [EditorBrowsable(EditorBrowsableState.Always)]
  1861. [Browsable(false)]
  1862. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1863. public int Width {
  1864. get {
  1865. return this.bounds.Width;
  1866. }
  1867. set {
  1868. SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  1869. }
  1870. }
  1871. [EditorBrowsable(EditorBrowsableState.Never)]
  1872. [Browsable(false)]
  1873. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1874. public IWindowTarget WindowTarget {
  1875. get {
  1876. return null;
  1877. }
  1878. set {
  1879. ; // MS Internal
  1880. }
  1881. }
  1882. #endregion // Public Instance Properties
  1883. #region Protected Instance Properties
  1884. protected virtual CreateParams CreateParams {
  1885. get {
  1886. CreateParams create_params = new CreateParams();
  1887. try {
  1888. create_params.Caption = Text;
  1889. }
  1890. catch {
  1891. create_params.Caption = text;
  1892. }
  1893. try {
  1894. create_params.X = Left;
  1895. }
  1896. catch {
  1897. create_params.X = this.bounds.X;
  1898. }
  1899. try {
  1900. create_params.Y = Top;
  1901. }
  1902. catch {
  1903. create_params.Y = this.bounds.Y;
  1904. }
  1905. try {
  1906. create_params.Width = Width;
  1907. }
  1908. catch {
  1909. create_params.Width = this.bounds.Width;
  1910. }
  1911. try {
  1912. create_params.Height = Height;
  1913. }
  1914. catch {
  1915. create_params.Height = this.bounds.Height;
  1916. }
  1917. create_params.ClassName = XplatUI.DefaultClassName;
  1918. create_params.ClassStyle = 0;
  1919. create_params.ExStyle = 0;
  1920. create_params.Param = 0;
  1921. if (allow_drop) {
  1922. create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
  1923. }
  1924. if (parent!=null) {
  1925. create_params.Parent = parent.Handle;
  1926. }
  1927. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  1928. if (is_visible) {
  1929. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  1930. }
  1931. if (!is_enabled) {
  1932. create_params.Style |= (int)WindowStyles.WS_DISABLED;
  1933. }
  1934. switch (border_style) {
  1935. case BorderStyle.FixedSingle:
  1936. create_params.Style |= (int) WindowStyles.WS_BORDER;
  1937. break;
  1938. case BorderStyle.Fixed3D:
  1939. create_params.ExStyle |= (int) WindowStyles.WS_EX_CLIENTEDGE;
  1940. break;
  1941. }
  1942. return create_params;
  1943. }
  1944. }
  1945. protected virtual ImeMode DefaultImeMode {
  1946. get {
  1947. return ImeMode.Inherit;
  1948. }
  1949. }
  1950. protected virtual Size DefaultSize {
  1951. get {
  1952. return new Size(100, 23);
  1953. }
  1954. }
  1955. protected int FontHeight {
  1956. get {
  1957. return Font.Height;
  1958. }
  1959. set {
  1960. ;; // Nothing to do
  1961. }
  1962. }
  1963. protected bool RenderRightToLeft {
  1964. get {
  1965. return (this.right_to_left == RightToLeft.Yes);
  1966. }
  1967. }
  1968. protected bool ResizeRedraw {
  1969. get {
  1970. return GetStyle(ControlStyles.ResizeRedraw);
  1971. }
  1972. set {
  1973. SetStyle(ControlStyles.ResizeRedraw, value);
  1974. }
  1975. }
  1976. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1977. [Browsable(false)]
  1978. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1979. protected virtual bool ShowFocusCues {
  1980. get {
  1981. return true;
  1982. }
  1983. }
  1984. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1985. [Browsable(false)]
  1986. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1987. protected bool ShowKeyboardCues {
  1988. get {
  1989. return true;
  1990. }
  1991. }
  1992. #endregion // Protected Instance Properties
  1993. #region Public Static Methods
  1994. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1995. public static Control FromChildHandle(IntPtr handle) {
  1996. IEnumerator control = Control.controls.GetEnumerator();
  1997. while (control.MoveNext()) {
  1998. if (((Control)control.Current).window.Handle == handle) {
  1999. // Found it
  2000. if (((Control)control.Current).Parent != null) {
  2001. return ((Control)control.Current).Parent;
  2002. }
  2003. }
  2004. }
  2005. return null;
  2006. }
  2007. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2008. public static Control FromHandle(IntPtr handle) {
  2009. #if not
  2010. IEnumerator control = Control.controls.GetEnumerator();
  2011. while (control.MoveNext()) {
  2012. if (((Control)control.Current).window.Handle == handle) {
  2013. // Found it
  2014. return ((Control)control.Current);
  2015. }
  2016. }
  2017. return null;
  2018. #else
  2019. return Control.ControlNativeWindow.ControlFromHandle(handle);
  2020. #endif
  2021. }
  2022. public static bool IsMnemonic(char charCode, string text) {
  2023. int amp;
  2024. amp = text.IndexOf('&');
  2025. if (amp != -1) {
  2026. if (amp + 1 < text.Length) {
  2027. if (text[amp + 1] != '&') {
  2028. if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
  2029. return true;
  2030. }
  2031. }
  2032. }
  2033. }
  2034. return false;
  2035. }
  2036. #endregion
  2037. #region Protected Static Methods
  2038. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2039. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  2040. Control c;
  2041. c = Control.FromHandle(hWnd);
  2042. if (c != null) {
  2043. c.WndProc(ref m);
  2044. return true;
  2045. }
  2046. return false;
  2047. }
  2048. #endregion
  2049. #region Public Instance Methods
  2050. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2051. public IAsyncResult BeginInvoke(Delegate method) {
  2052. return BeginInvokeInternal(method, null, false);
  2053. }
  2054. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2055. public IAsyncResult BeginInvoke (Delegate method, object[] args) {
  2056. return BeginInvokeInternal (method, args, false);
  2057. }
  2058. public void BringToFront() {
  2059. if ((parent != null) && (parent.child_controls[0]!=this)) {
  2060. if (parent.child_controls.Contains(this)) {
  2061. parent.child_controls.SetChildIndex(this, 0);
  2062. }
  2063. }
  2064. XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
  2065. if (parent != null) {
  2066. parent.Refresh();
  2067. }
  2068. }
  2069. public bool Contains(Control ctl) {
  2070. while (ctl != null) {
  2071. ctl = ctl.parent;
  2072. if (ctl == this) {
  2073. return true;
  2074. }
  2075. }
  2076. return false;
  2077. }
  2078. public void CreateControl() {
  2079. if (is_created) {
  2080. return;
  2081. }
  2082. if (!IsHandleCreated) {
  2083. CreateHandle();
  2084. }
  2085. if (!is_created) {
  2086. is_created = true;
  2087. }
  2088. Control [] controls = child_controls.GetAllControls ();
  2089. for (int i=0; i<controls.Length; i++) {
  2090. controls [i].CreateControl ();
  2091. }
  2092. UpdateZOrder();
  2093. if (binding_context == null) { // seem to be sent whenever it's null?
  2094. OnBindingContextChanged(EventArgs.Empty);
  2095. }
  2096. OnCreateControl();
  2097. }
  2098. public Graphics CreateGraphics() {
  2099. if (!IsHandleCreated) {
  2100. this.CreateHandle();
  2101. }
  2102. return Graphics.FromHwnd(this.window.Handle);
  2103. }
  2104. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  2105. return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
  2106. }
  2107. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2108. public object EndInvoke (IAsyncResult async_result) {
  2109. AsyncMethodResult result = (AsyncMethodResult) async_result;
  2110. return result.EndInvoke ();
  2111. }
  2112. public Form FindForm() {
  2113. Control c;
  2114. c = this;
  2115. while (c != null) {
  2116. if (c is Form) {
  2117. return (Form)c;
  2118. }
  2119. c = c.Parent;
  2120. }
  2121. return null;
  2122. }
  2123. public bool Focus() {
  2124. if (IsHandleCreated && !has_focus) {
  2125. has_focus = true;
  2126. XplatUI.SetFocus(window.Handle);
  2127. }
  2128. return true;
  2129. }
  2130. public Control GetChildAtPoint(Point pt) {
  2131. // Microsoft's version of this function doesn't seem to work, so I can't check
  2132. // if we only consider children or also grandchildren, etc.
  2133. // I'm gonna say 'children only'
  2134. for (int i=0; i<child_controls.Count; i++) {
  2135. if (child_controls[i].Bounds.Contains(pt)) {
  2136. return child_controls[i];
  2137. }
  2138. }
  2139. return null;
  2140. }
  2141. public IContainerControl GetContainerControl() {
  2142. Control current = this;
  2143. while (current!=null) {
  2144. if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  2145. return (IContainerControl)current;
  2146. }
  2147. current = current.parent;
  2148. }
  2149. return null;
  2150. }
  2151. public Control GetNextControl(Control ctl, bool forward) {
  2152. // If we're not a container we don't play
  2153. if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
  2154. return null;
  2155. }
  2156. // If ctl is not contained by this, we start at the first child of this
  2157. if (!this.Contains(ctl)) {
  2158. ctl = null;
  2159. }
  2160. // Search through our controls, starting at ctl, stepping into children as we encounter them
  2161. // try to find the control with the tabindex closest to our own, or, if we're looking into
  2162. // child controls, the one with the smallest tabindex
  2163. if (forward) {
  2164. return FindControlForward(this, ctl);
  2165. }
  2166. return FindControlBackward(this, ctl);
  2167. }
  2168. public void Hide() {
  2169. this.Visible = false;
  2170. }
  2171. public void Invalidate() {
  2172. Invalidate(ClientRectangle, false);
  2173. }
  2174. public void Invalidate(bool invalidateChildren) {
  2175. Invalidate(ClientRectangle, invalidateChildren);
  2176. }
  2177. public void Invalidate(System.Drawing.Rectangle rc) {
  2178. Invalidate(rc, false);
  2179. }
  2180. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  2181. if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
  2182. return;
  2183. }
  2184. NotifyInvalidate(rc);
  2185. XplatUI.Invalidate(Handle, rc, false);
  2186. if (invalidateChildren) {
  2187. Control [] controls = child_controls.GetAllControls ();
  2188. for (int i=0; i<controls.Length; i++)
  2189. controls [i].Invalidate ();
  2190. }
  2191. OnInvalidated(new InvalidateEventArgs(rc));
  2192. }
  2193. public void Invalidate(System.Drawing.Region region) {
  2194. Invalidate(region, false);
  2195. }
  2196. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  2197. RectangleF bounds = region.GetBounds (CreateGraphics ());
  2198. Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
  2199. invalidateChildren);
  2200. }
  2201. public object Invoke (Delegate method) {
  2202. object [] prms = null;
  2203. if (method is EventHandler)
  2204. prms = new object [] { this, EventArgs.Empty };
  2205. return Invoke(method, prms);
  2206. }
  2207. public object Invoke (Delegate method, object[] args) {
  2208. if (!this.InvokeRequired) {
  2209. return method.DynamicInvoke(args);
  2210. }
  2211. IAsyncResult result = BeginInvoke (method, args);
  2212. return EndInvoke(result);
  2213. }
  2214. internal object InvokeInternal (Delegate method, bool disposing) {
  2215. return InvokeInternal(method, null, disposing);
  2216. }
  2217. internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
  2218. if (!this.InvokeRequired) {
  2219. return method.DynamicInvoke(args);
  2220. }
  2221. IAsyncResult result = BeginInvokeInternal (method, args, disposing);
  2222. return EndInvoke(result);
  2223. }
  2224. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2225. public void PerformLayout() {
  2226. PerformLayout(null, null);
  2227. }
  2228. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2229. public void PerformLayout(Control affectedControl, string affectedProperty) {
  2230. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  2231. if (layout_suspended > 0) {
  2232. layout_pending = true;
  2233. return;
  2234. }
  2235. layout_pending = false;
  2236. // Prevent us from getting messed up
  2237. layout_suspended++;
  2238. // Perform all Dock and Anchor calculations
  2239. try {
  2240. Control child;
  2241. AnchorStyles anchor;
  2242. Rectangle space;
  2243. space=this.DisplayRectangle;
  2244. // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
  2245. Control [] controls = child_controls.GetAllControls ();
  2246. for (int i = controls.Length - 1; i >= 0; i--) {
  2247. child = controls [i];
  2248. switch (child.Dock) {
  2249. case DockStyle.None: {
  2250. // Do nothing
  2251. break;
  2252. }
  2253. case DockStyle.Left: {
  2254. child.SetBounds(space.Left, space.Y, child.Width, space.Height);
  2255. space.X+=child.Width;
  2256. space.Width-=child.Width;
  2257. break;
  2258. }
  2259. case DockStyle.Top: {
  2260. child.SetBounds(space.Left, space.Y, space.Width, child.Height);
  2261. space.Y+=child.Height;
  2262. space.Height-=child.Height;
  2263. break;
  2264. }
  2265. case DockStyle.Right: {
  2266. child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
  2267. space.Width-=child.Width;
  2268. break;
  2269. }
  2270. case DockStyle.Bottom: {
  2271. child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
  2272. space.Height-=child.Height;
  2273. break;
  2274. }
  2275. }
  2276. }
  2277. for (int i = controls.Length - 1; i >= 0; i--) {
  2278. child=controls[i];
  2279. if (child.Dock == DockStyle.Fill) {
  2280. child.SetBounds(space.Left, space.Top, space.Width, space.Height);
  2281. space.Width=0;
  2282. space.Height=0;
  2283. }
  2284. }
  2285. space=this.DisplayRectangle;
  2286. for (int i=0; i < controls.Length; i++) {
  2287. int left;
  2288. int top;
  2289. int width;
  2290. int height;
  2291. child = controls[i];
  2292. anchor = child.Anchor;
  2293. left = child.Left;
  2294. top = child.Top;
  2295. width = child.Width;
  2296. height = child.Height;
  2297. // If the control is docked we don't need to do anything
  2298. if (child.Dock != DockStyle.None) {
  2299. continue;
  2300. }
  2301. if ((anchor & AnchorStyles.Left) !=0 ) {
  2302. if ((anchor & AnchorStyles.Right) != 0) {
  2303. width = client_size.Width - child.dist_right - left;
  2304. } else {
  2305. ; // Left anchored only, nothing to be done
  2306. }
  2307. } else if ((anchor & AnchorStyles.Right) != 0) {
  2308. left = client_size.Width - child.dist_right - width;
  2309. } else {
  2310. // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
  2311. // This calculates from scratch every time:
  2312. left = child.dist_left + (client_size.Width - (child.dist_left + width + child.dist_right)) / 2;
  2313. }
  2314. if ((anchor & AnchorStyles.Top) !=0 ) {
  2315. if ((anchor & AnchorStyles.Bottom) != 0) {
  2316. height = client_size.Height - child.dist_bottom - top;
  2317. } else {
  2318. ; // Top anchored only, nothing to be done
  2319. }
  2320. } else if ((anchor & AnchorStyles.Bottom) != 0) {
  2321. top = client_size.Height - child.dist_bottom - height;
  2322. } else {
  2323. // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
  2324. // This calculates from scratch every time:
  2325. top = child.dist_top + (client_size.Height - (child.dist_top + height + child.dist_bottom)) / 2;
  2326. }
  2327. // Sanity
  2328. if (width < 0) {
  2329. width=0;
  2330. }
  2331. if (height < 0) {
  2332. height=0;
  2333. }
  2334. child.SetBounds(left, top, width, height);
  2335. }
  2336. // Let everyone know
  2337. OnLayout(levent);
  2338. }
  2339. // Need to make sure we decremend layout_suspended
  2340. finally {
  2341. layout_suspended--;
  2342. }
  2343. }
  2344. public Point PointToClient (Point p) {
  2345. int x = p.X;
  2346. int y = p.Y;
  2347. XplatUI.ScreenToClient (Handle, ref x, ref y);
  2348. return new Point (x, y);
  2349. }
  2350. public Point PointToScreen(Point p) {
  2351. int x = p.X;
  2352. int y = p.Y;
  2353. XplatUI.ClientToScreen(Handle, ref x, ref y);
  2354. return new Point(x, y);
  2355. }
  2356. public virtual bool PreProcessMessage(ref Message msg) {
  2357. Keys key_data;
  2358. if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
  2359. key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
  2360. if (!ProcessCmdKey(ref msg, key_data)) {
  2361. if (IsInputKey(key_data)) {
  2362. return false;
  2363. }
  2364. return ProcessDialogKey(key_data);
  2365. }
  2366. return true;
  2367. } else if (msg.Msg == (int)Msg.WM_CHAR) {
  2368. if (IsInputChar((char)msg.WParam)) {
  2369. return false;
  2370. }
  2371. } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
  2372. if (IsInputChar((char)msg.WParam)) {
  2373. return false;
  2374. }
  2375. return ProcessDialogChar((char)msg.WParam);
  2376. }
  2377. return false;
  2378. }
  2379. public Rectangle RectangleToClient(Rectangle r) {
  2380. return new Rectangle(PointToClient(r.Location), r.Size);
  2381. }
  2382. public Rectangle RectangleToScreen(Rectangle r) {
  2383. return new Rectangle(PointToScreen(r.Location), r.Size);
  2384. }
  2385. public virtual void Refresh() {
  2386. if (IsHandleCreated == true) {
  2387. Invalidate();
  2388. XplatUI.UpdateWindow(window.Handle);
  2389. Control [] controls = child_controls.GetAllControls ();
  2390. for (int i=0; i < controls.Length; i++) {
  2391. controls[i].Refresh();
  2392. }
  2393. }
  2394. }
  2395. [EditorBrowsable(EditorBrowsableState.Never)]
  2396. public virtual void ResetBackColor() {
  2397. background_color = Color.Empty;
  2398. }
  2399. [EditorBrowsable(EditorBrowsableState.Never)]
  2400. [MonoTODO]
  2401. public void ResetBindings() {
  2402. // Do something
  2403. }
  2404. [EditorBrowsable(EditorBrowsableState.Never)]
  2405. public virtual void ResetCursor() {
  2406. Cursor = null;
  2407. }
  2408. [EditorBrowsable(EditorBrowsableState.Never)]
  2409. public virtual void ResetFont() {
  2410. font = null;
  2411. }
  2412. [EditorBrowsable(EditorBrowsableState.Never)]
  2413. public virtual void ResetForeColor() {
  2414. foreground_color = Color.Empty;
  2415. }
  2416. [EditorBrowsable(EditorBrowsableState.Never)]
  2417. public void ResetImeMode() {
  2418. ime_mode = DefaultImeMode;
  2419. }
  2420. [EditorBrowsable(EditorBrowsableState.Never)]
  2421. public virtual void ResetRightToLeft() {
  2422. right_to_left = RightToLeft.Inherit;
  2423. }
  2424. public virtual void ResetText() {
  2425. text = String.Empty;
  2426. }
  2427. public void ResumeLayout() {
  2428. ResumeLayout (true);
  2429. }
  2430. public void ResumeLayout(bool performLayout) {
  2431. layout_suspended--;
  2432. if (layout_suspended > 0) {
  2433. return;
  2434. }
  2435. Control [] controls = child_controls.GetAllControls ();
  2436. for (int i=0; i<controls.Length; i++) {
  2437. controls [i].UpdateDistances ();
  2438. }
  2439. if (performLayout || layout_pending) {
  2440. PerformLayout();
  2441. }
  2442. }
  2443. public void Scale(float ratio) {
  2444. ScaleCore(ratio, ratio);
  2445. }
  2446. public void Scale(float dx, float dy) {
  2447. ScaleCore(dx, dy);
  2448. }
  2449. public void Select() {
  2450. Select(false, false);
  2451. }
  2452. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  2453. Control c;
  2454. c = ctl;
  2455. do {
  2456. c = GetNextControl(c, forward);
  2457. if (c == null) {
  2458. if (wrap) {
  2459. wrap = false;
  2460. continue;
  2461. }
  2462. break;
  2463. }
  2464. if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
  2465. Select(c);
  2466. return true;
  2467. }
  2468. } while (c != ctl); // If we wrap back to ourselves we stop
  2469. return false;
  2470. }
  2471. public void SendToBack() {
  2472. if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
  2473. if (parent.child_controls.Contains(this)) {
  2474. parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
  2475. }
  2476. }
  2477. XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
  2478. if (parent != null) {
  2479. parent.Refresh();
  2480. }
  2481. }
  2482. public void SetBounds(int x, int y, int width, int height) {
  2483. SetBoundsCore(x, y, width, height, BoundsSpecified.All);
  2484. }
  2485. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  2486. SetBoundsCore(x, y, width, height, specified);
  2487. }
  2488. public void Show() {
  2489. if (!IsHandleCreated) {
  2490. this.CreateControl();
  2491. }
  2492. this.Visible=true;
  2493. }
  2494. public void SuspendLayout() {
  2495. layout_suspended++;
  2496. }
  2497. public void Update() {
  2498. needs_redraw = true;
  2499. if (IsHandleCreated) {
  2500. XplatUI.UpdateWindow(window.Handle);
  2501. }
  2502. }
  2503. #endregion // Public Instance Methods
  2504. #region Protected Instance Methods
  2505. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2506. [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
  2507. protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
  2508. throw new NotImplementedException();
  2509. }
  2510. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2511. protected virtual AccessibleObject CreateAccessibilityInstance() {
  2512. return new Control.ControlAccessibleObject(this);
  2513. }
  2514. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2515. protected virtual ControlCollection CreateControlsInstance() {
  2516. return new ControlCollection(this);
  2517. }
  2518. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2519. protected virtual void CreateHandle() {
  2520. if (IsDisposed) {
  2521. throw new ObjectDisposedException(Name);
  2522. }
  2523. if (IsHandleCreated) {
  2524. return;
  2525. }
  2526. window.CreateHandle(CreateParams);
  2527. if (window.Handle != IntPtr.Zero) {
  2528. if (!controls.Contains(window.Handle)) {
  2529. controls.Add(this);
  2530. }
  2531. creator_thread = Thread.CurrentThread;
  2532. XplatUI.EnableWindow(window.Handle, is_enabled);
  2533. // Set our handle with our parent
  2534. if ((parent != null) && (parent.IsHandleCreated)) {
  2535. XplatUI.SetParent(window.Handle, parent.Handle);
  2536. }
  2537. // Set our handle as parent for our children
  2538. Control [] children;
  2539. children = child_controls.GetAllControls ();
  2540. for (int i = 0; i < children.Length; i++ ) {
  2541. if (children[i].IsHandleCreated) {
  2542. XplatUI.SetParent(children[i].Handle, window.Handle);
  2543. }
  2544. }
  2545. // Find out where the window manager placed us
  2546. UpdateStyles();
  2547. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
  2548. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  2549. }
  2550. UpdateBounds();
  2551. OnHandleCreated(EventArgs.Empty);
  2552. }
  2553. }
  2554. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2555. protected virtual void DefWndProc(ref Message m) {
  2556. window.DefWndProc(ref m);
  2557. }
  2558. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2559. protected virtual void DestroyHandle() {
  2560. if (IsHandleCreated) {
  2561. if (window != null) {
  2562. window.DestroyHandle();
  2563. }
  2564. }
  2565. }
  2566. protected bool GetStyle(ControlStyles flag) {
  2567. return (control_style & flag) != 0;
  2568. }
  2569. protected bool GetTopLevel() {
  2570. return is_toplevel;
  2571. }
  2572. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2573. protected virtual void InitLayout() {
  2574. UpdateDistances();
  2575. }
  2576. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2577. protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
  2578. toInvoke.OnGotFocus(e);
  2579. }
  2580. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2581. protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
  2582. toInvoke.OnLostFocus(e);
  2583. }
  2584. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2585. protected void InvokeOnClick(Control toInvoke, EventArgs e) {
  2586. toInvoke.OnClick(e);
  2587. }
  2588. protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
  2589. toInvoke.OnPaint(e);
  2590. }
  2591. protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
  2592. toInvoke.OnPaintBackground(e);
  2593. }
  2594. protected virtual bool IsInputChar (char charCode) {
  2595. return true;
  2596. }
  2597. protected virtual bool IsInputKey (Keys keyData) {
  2598. // Doc says this one calls IsInputChar; not sure what to do with that
  2599. return false;
  2600. }
  2601. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2602. protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
  2603. // override me?
  2604. }
  2605. protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
  2606. if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
  2607. return true;
  2608. }
  2609. if (parent != null) {
  2610. return parent.ProcessCmdKey(ref msg, keyData);
  2611. }
  2612. return false;
  2613. }
  2614. protected virtual bool ProcessDialogChar(char charCode) {
  2615. if (parent != null) {
  2616. return parent.ProcessDialogChar (charCode);
  2617. }
  2618. return false;
  2619. }
  2620. protected virtual bool ProcessDialogKey (Keys keyData) {
  2621. if (parent != null) {
  2622. return parent.ProcessDialogKey (keyData);
  2623. }
  2624. return false;
  2625. }
  2626. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  2627. {
  2628. KeyEventArgs key_event;
  2629. switch (msg.Msg) {
  2630. case (int)Msg.WM_SYSKEYDOWN:
  2631. case (int)Msg.WM_KEYDOWN: {
  2632. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  2633. OnKeyDown (key_event);
  2634. return key_event.Handled;
  2635. }
  2636. case (int)Msg.WM_SYSKEYUP:
  2637. case (int)Msg.WM_KEYUP: {
  2638. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  2639. OnKeyUp (key_event);
  2640. return key_event.Handled;
  2641. }
  2642. case (int)Msg.WM_SYSCHAR:
  2643. case (int)Msg.WM_CHAR: {
  2644. KeyPressEventArgs key_press_event;
  2645. key_press_event = new KeyPressEventArgs((char)msg.WParam);
  2646. OnKeyPress(key_press_event);
  2647. return key_press_event.Handled;
  2648. }
  2649. default: {
  2650. break;
  2651. }
  2652. }
  2653. return false;
  2654. }
  2655. protected internal virtual bool ProcessKeyMessage(ref Message msg) {
  2656. if (parent != null) {
  2657. if (parent.ProcessKeyPreview(ref msg)) {
  2658. return true;
  2659. }
  2660. }
  2661. return ProcessKeyEventArgs(ref msg);
  2662. }
  2663. protected virtual bool ProcessKeyPreview(ref Message msg) {
  2664. if (parent != null) {
  2665. return parent.ProcessKeyPreview(ref msg);
  2666. }
  2667. return false;
  2668. }
  2669. protected virtual bool ProcessMnemonic(char charCode) {
  2670. // override me
  2671. return false;
  2672. }
  2673. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2674. protected void RaiseDragEvent(object key, DragEventArgs e) {
  2675. // MS Internal
  2676. }
  2677. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2678. protected void RaiseKeyEvent(object key, KeyEventArgs e) {
  2679. // MS Internal
  2680. }
  2681. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2682. protected void RaiseMouseEvent(object key, MouseEventArgs e) {
  2683. // MS Internal
  2684. }
  2685. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2686. protected void RaisePaintEvent(object key, PaintEventArgs e) {
  2687. // MS Internal
  2688. }
  2689. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2690. protected void RecreateHandle() {
  2691. IEnumerator child = child_controls.GetAllEnumerator();
  2692. is_recreating=true;
  2693. if (IsHandleCreated) {
  2694. DestroyHandle();
  2695. CreateHandle();
  2696. // FIXME ZOrder?
  2697. while (child.MoveNext()) {
  2698. ((Control)child.Current).RecreateHandle();
  2699. }
  2700. } else {
  2701. CreateControl();
  2702. }
  2703. is_recreating = false;
  2704. }
  2705. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2706. protected void ResetMouseEventArgs() {
  2707. // MS Internal
  2708. }
  2709. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2710. protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
  2711. if (right_to_left == RightToLeft.No) {
  2712. return align;
  2713. }
  2714. switch (align) {
  2715. case ContentAlignment.TopLeft: {
  2716. return ContentAlignment.TopRight;
  2717. }
  2718. case ContentAlignment.TopRight: {
  2719. return ContentAlignment.TopLeft;
  2720. }
  2721. case ContentAlignment.MiddleLeft: {
  2722. return ContentAlignment.MiddleRight;
  2723. }
  2724. case ContentAlignment.MiddleRight: {
  2725. return ContentAlignment.MiddleLeft;
  2726. }
  2727. case ContentAlignment.BottomLeft: {
  2728. return ContentAlignment.BottomRight;
  2729. }
  2730. case ContentAlignment.BottomRight: {
  2731. return ContentAlignment.BottomLeft;
  2732. }
  2733. default: {
  2734. // if it's center it doesn't change
  2735. return align;
  2736. }
  2737. }
  2738. }
  2739. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2740. protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
  2741. if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
  2742. return align;
  2743. }
  2744. if (align == HorizontalAlignment.Left) {
  2745. return HorizontalAlignment.Right;
  2746. }
  2747. // align must be HorizontalAlignment.Right
  2748. return HorizontalAlignment.Left;
  2749. }
  2750. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2751. protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
  2752. if (right_to_left == RightToLeft.No) {
  2753. return align;
  2754. }
  2755. if (align == LeftRightAlignment.Left) {
  2756. return LeftRightAlignment.Right;
  2757. }
  2758. // align must be LeftRightAlignment.Right;
  2759. return LeftRightAlignment.Left;
  2760. }
  2761. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2762. protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
  2763. return RtlTranslateAlignment(align);
  2764. }
  2765. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2766. protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
  2767. return RtlTranslateAlignment(align);
  2768. }
  2769. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2770. protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
  2771. return RtlTranslateAlignment(align);
  2772. }
  2773. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2774. protected virtual void ScaleCore(float dx, float dy) {
  2775. Point location;
  2776. Size size;
  2777. SuspendLayout();
  2778. location = new Point((int)(Left * dx), (int)(Top * dy));
  2779. size = this.ClientSize;
  2780. if (!GetStyle(ControlStyles.FixedWidth)) {
  2781. size.Width = (int)(size.Width * dx);
  2782. }
  2783. if (!GetStyle(ControlStyles.FixedHeight)) {
  2784. size.Height = (int)(size.Height * dy);
  2785. }
  2786. Location = location;
  2787. ClientSize = size;
  2788. /* Now scale our children */
  2789. Control [] controls = child_controls.GetAllControls ();
  2790. for (int i=0; i < controls.Length; i++) {
  2791. controls[i].Scale(dx, dy);
  2792. }
  2793. ResumeLayout();
  2794. }
  2795. protected virtual void Select(bool directed, bool forward) {
  2796. int index;
  2797. bool result;
  2798. if (!directed) {
  2799. // Select this control
  2800. Select(this);
  2801. return;
  2802. }
  2803. if (parent == null) {
  2804. return;
  2805. }
  2806. // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
  2807. index = parent.child_controls.IndexOf(this);
  2808. result = false;
  2809. do {
  2810. if (forward) {
  2811. if ((index+1) < parent.child_controls.Count) {
  2812. index++;
  2813. } else {
  2814. index = 0;
  2815. }
  2816. } else {
  2817. if (index>0) {
  2818. index++;
  2819. } else {
  2820. index = parent.child_controls.Count-1;
  2821. }
  2822. }
  2823. result = Select(parent.child_controls[index]);
  2824. } while (!result && parent.child_controls[index] != this);
  2825. }
  2826. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2827. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  2828. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  2829. if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
  2830. x = Left;
  2831. }
  2832. if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  2833. y = Top;
  2834. }
  2835. if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
  2836. width = Width;
  2837. }
  2838. if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  2839. height = Height;
  2840. }
  2841. if (IsHandleCreated) {
  2842. XplatUI.SetWindowPos(Handle, x, y, width, height);
  2843. }
  2844. UpdateBounds(x, y, width, height);
  2845. }
  2846. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2847. protected virtual void SetClientSizeCore(int x, int y) {
  2848. // Calculate the actual window size from the client size (it usually stays the same or grows)
  2849. Rectangle ClientRect;
  2850. Rectangle WindowRect;
  2851. CreateParams cp;
  2852. ClientRect = new Rectangle(0, 0, x, y);
  2853. cp = this.CreateParams;
  2854. if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
  2855. return;
  2856. }
  2857. SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  2858. }
  2859. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2860. protected void SetStyle(ControlStyles flag, bool value) {
  2861. if (value) {
  2862. control_style |= flag;
  2863. } else {
  2864. control_style &= ~flag;
  2865. }
  2866. OnStyleChanged(EventArgs.Empty);
  2867. }
  2868. protected void SetTopLevel(bool value) {
  2869. if ((GetTopLevel() != value) && (parent != null)) {
  2870. throw new Exception();
  2871. }
  2872. if (this is Form) {
  2873. if (value == true) {
  2874. if (!Visible) {
  2875. Visible = true;
  2876. }
  2877. } else {
  2878. if (Visible) {
  2879. Visible = false;
  2880. }
  2881. }
  2882. }
  2883. is_toplevel = value;
  2884. }
  2885. protected virtual void SetVisibleCore(bool value) {
  2886. if (value!=is_visible) {
  2887. is_visible=value;
  2888. if (IsHandleCreated) {
  2889. XplatUI.SetVisible(Handle, value);
  2890. // Explicitly move Toplevel windows to where we want them;
  2891. // apparently moving unmapped toplevel windows doesn't work
  2892. if (is_visible && (this is Form)) {
  2893. XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
  2894. }
  2895. }
  2896. if (!is_visible) {
  2897. if (dc_mem != null) {
  2898. dc_mem.Dispose();
  2899. dc_mem = null;
  2900. }
  2901. if (bmp_mem != null) {
  2902. bmp_mem.Dispose();
  2903. bmp_mem = null;
  2904. }
  2905. } else {
  2906. this.CreateBuffers(bounds.Width, bounds.Height);
  2907. CreateControl();
  2908. }
  2909. OnVisibleChanged(EventArgs.Empty);
  2910. if (value == false && parent != null) {
  2911. Control container;
  2912. // Need to start at parent, GetContainerControl might return ourselves if we're a container
  2913. container = (Control)parent.GetContainerControl();
  2914. if (container != null) {
  2915. container.SelectNextControl(this, true, true, true, true);
  2916. }
  2917. }
  2918. if (parent != null) {
  2919. parent.PerformLayout(this, "visible");
  2920. } else {
  2921. PerformLayout(this, "visible");
  2922. }
  2923. }
  2924. }
  2925. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2926. protected void UpdateBounds() {
  2927. int x;
  2928. int y;
  2929. int width;
  2930. int height;
  2931. int client_width;
  2932. int client_height;
  2933. if (!IsHandleCreated) {
  2934. CreateHandle();
  2935. }
  2936. XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
  2937. UpdateBounds(x, y, width, height, client_width, client_height);
  2938. }
  2939. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2940. protected void UpdateBounds(int x, int y, int width, int height) {
  2941. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  2942. bool moved = false;
  2943. bool resized = false;
  2944. int client_x_diff = this.bounds.Width-this.client_size.Width;
  2945. int client_y_diff = this.bounds.Height-this.client_size.Height;
  2946. // Needed to generate required notifications
  2947. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  2948. moved=true;
  2949. }
  2950. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  2951. resized=true;
  2952. }
  2953. bounds.X=x;
  2954. bounds.Y=y;
  2955. bounds.Width=width;
  2956. bounds.Height=height;
  2957. // Update client rectangle as well
  2958. client_size.Width=width-client_x_diff;
  2959. client_size.Height=height-client_y_diff;
  2960. UpdateDistances();
  2961. if (moved) {
  2962. OnLocationChanged(EventArgs.Empty);
  2963. }
  2964. if (resized) {
  2965. OnSizeChanged(EventArgs.Empty);
  2966. }
  2967. }
  2968. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2969. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  2970. UpdateBounds(x, y, width, height);
  2971. this.client_size.Width=clientWidth;
  2972. this.client_size.Height=clientHeight;
  2973. }
  2974. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2975. protected void UpdateStyles() {
  2976. if (!IsHandleCreated) {
  2977. return;
  2978. }
  2979. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  2980. }
  2981. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2982. protected void UpdateZOrder() {
  2983. Control [] controls;
  2984. if (!IsHandleCreated) {
  2985. return;
  2986. }
  2987. controls = child_controls.GetAllControls ();
  2988. for (int i = 1; i < controls.Length; i++ ) {
  2989. XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
  2990. }
  2991. }
  2992. protected virtual void WndProc(ref Message m) {
  2993. #if debug
  2994. Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
  2995. #endif
  2996. if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
  2997. OnNotifyMessage(m);
  2998. }
  2999. switch((Msg)m.Msg) {
  3000. case Msg.WM_DESTROY: {
  3001. OnHandleDestroyed(EventArgs.Empty);
  3002. window.InvalidateHandle();
  3003. return;
  3004. }
  3005. case Msg.WM_WINDOWPOSCHANGED: {
  3006. if (Visible) {
  3007. UpdateBounds();
  3008. if (GetStyle(ControlStyles.ResizeRedraw)) {
  3009. Invalidate();
  3010. }
  3011. }
  3012. return;
  3013. }
  3014. case Msg.WM_PAINT: {
  3015. PaintEventArgs paint_event;
  3016. paint_event = XplatUI.PaintEventStart(Handle, true);
  3017. if (!needs_redraw) {
  3018. // Just blit the previous image
  3019. paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
  3020. XplatUI.PaintEventEnd(Handle, true);
  3021. return;
  3022. }
  3023. Graphics dc = null;
  3024. if ((control_style & ControlStyles.DoubleBuffer) != 0) {
  3025. dc = paint_event.SetGraphics (DeviceContext);
  3026. }
  3027. OnPaintBackground(paint_event);
  3028. // Leave out for now, our controls can do Paint += ... as well
  3029. //OnPaintInternal(paint_event);
  3030. OnPaint(paint_event);
  3031. if ((control_style & ControlStyles.DoubleBuffer) != 0) {
  3032. dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
  3033. paint_event.SetGraphics (dc);
  3034. needs_redraw = false;
  3035. }
  3036. XplatUI.PaintEventEnd(Handle, true);
  3037. return;
  3038. }
  3039. case Msg.WM_ERASEBKGND: {
  3040. // The DefWndProc will never have to handle this, we always paint the background in managed code
  3041. m.Result = (IntPtr)1;
  3042. return;
  3043. }
  3044. case Msg.WM_LBUTTONUP: {
  3045. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  3046. mouse_clicks,
  3047. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3048. 0));
  3049. HandleClick(mouse_clicks);
  3050. if (mouse_clicks > 1) {
  3051. mouse_clicks = 1;
  3052. }
  3053. return;
  3054. }
  3055. case Msg.WM_LBUTTONDOWN: {
  3056. if (CanSelect && !is_selected) {
  3057. Select(this);
  3058. }
  3059. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3060. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3061. 0));
  3062. return;
  3063. }
  3064. case Msg.WM_LBUTTONDBLCLK: {
  3065. mouse_clicks++;
  3066. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3067. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3068. 0));
  3069. return;
  3070. }
  3071. case Msg.WM_MBUTTONUP: {
  3072. HandleClick(mouse_clicks);
  3073. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
  3074. mouse_clicks,
  3075. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3076. 0));
  3077. if (mouse_clicks > 1) {
  3078. mouse_clicks = 1;
  3079. }
  3080. return;
  3081. }
  3082. case Msg.WM_MBUTTONDOWN: {
  3083. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3084. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3085. 0));
  3086. return;
  3087. }
  3088. case Msg.WM_MBUTTONDBLCLK: {
  3089. mouse_clicks++;
  3090. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3091. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3092. 0));
  3093. return;
  3094. }
  3095. case Msg.WM_RBUTTONUP: {
  3096. if (context_menu != null) {
  3097. context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
  3098. }
  3099. HandleClick(mouse_clicks);
  3100. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
  3101. mouse_clicks,
  3102. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3103. 0));
  3104. if (mouse_clicks > 1) {
  3105. mouse_clicks = 1;
  3106. }
  3107. return;
  3108. }
  3109. case Msg.WM_RBUTTONDOWN: {
  3110. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3111. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3112. 0));
  3113. return;
  3114. }
  3115. case Msg.WM_RBUTTONDBLCLK: {
  3116. mouse_clicks++;
  3117. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3118. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3119. 0));
  3120. return;
  3121. }
  3122. case Msg.WM_MOUSEWHEEL: {
  3123. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3124. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3125. HighOrder(m.WParam.ToInt32())));
  3126. return;
  3127. }
  3128. case Msg.WM_MOUSEMOVE: {
  3129. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3130. mouse_clicks,
  3131. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3132. 0));
  3133. return;
  3134. }
  3135. case Msg.WM_MOUSE_ENTER: {
  3136. if (is_entered) {
  3137. return;
  3138. }
  3139. is_entered = true;
  3140. OnMouseEnter(EventArgs.Empty);
  3141. return;
  3142. }
  3143. case Msg.WM_MOUSE_LEAVE: {
  3144. is_entered=false;
  3145. OnMouseLeave(EventArgs.Empty);
  3146. return;
  3147. }
  3148. case Msg.WM_MOUSEHOVER: {
  3149. OnMouseHover(EventArgs.Empty);
  3150. return;
  3151. }
  3152. case Msg.WM_SYSKEYDOWN:
  3153. case Msg.WM_KEYDOWN:
  3154. case Msg.WM_SYSKEYUP:
  3155. case Msg.WM_KEYUP:
  3156. case Msg.WM_SYSCHAR:
  3157. case Msg.WM_CHAR: {
  3158. if (ProcessKeyMessage(ref m)) {
  3159. return;
  3160. }
  3161. if ((m.Msg == (int)Msg.WM_SYSKEYUP) && ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu)) {
  3162. Form form;
  3163. form = FindForm();
  3164. if (form != null && form.ActiveMenu != null) {
  3165. form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
  3166. }
  3167. }
  3168. DefWndProc (ref m);
  3169. return;
  3170. }
  3171. case Msg.WM_HELP: {
  3172. Point mouse_pos;
  3173. if (m.LParam != IntPtr.Zero) {
  3174. HELPINFO hi;
  3175. hi = new HELPINFO();
  3176. hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
  3177. mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
  3178. } else {
  3179. mouse_pos = Control.MousePosition;
  3180. }
  3181. OnHelpRequested(new HelpEventArgs(mouse_pos));
  3182. m.Result = (IntPtr)1;
  3183. return;
  3184. }
  3185. case Msg.WM_KILLFOCUS: {
  3186. OnLeave(EventArgs.Empty);
  3187. if (CausesValidation) {
  3188. CancelEventArgs e;
  3189. e = new CancelEventArgs(false);
  3190. OnValidating(e);
  3191. if (e.Cancel) {
  3192. Focus();
  3193. return;
  3194. }
  3195. OnValidated(EventArgs.Empty);
  3196. }
  3197. this.has_focus = false;
  3198. this.is_selected = false;
  3199. OnLostFocus(EventArgs.Empty);
  3200. return;
  3201. }
  3202. case Msg.WM_SETFOCUS: {
  3203. OnEnter(EventArgs.Empty);
  3204. this.has_focus = true;
  3205. OnGotFocus(EventArgs.Empty);
  3206. return;
  3207. }
  3208. case Msg.WM_SYSCOLORCHANGE: {
  3209. ThemeEngine.Current.ResetDefaults();
  3210. OnSystemColorsChanged(EventArgs.Empty);
  3211. return;
  3212. }
  3213. case Msg.WM_SETCURSOR: {
  3214. if (cursor == null) {
  3215. DefWndProc(ref m);
  3216. return;
  3217. }
  3218. XplatUI.SetCursor(window.Handle, cursor.handle);
  3219. m.Result = (IntPtr)1;
  3220. return;
  3221. }
  3222. default: {
  3223. DefWndProc(ref m);
  3224. return;
  3225. }
  3226. }
  3227. }
  3228. #endregion // Public Instance Methods
  3229. #region OnXXX methods
  3230. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3231. protected virtual void OnBackColorChanged(EventArgs e) {
  3232. if (BackColorChanged!=null) BackColorChanged(this, e);
  3233. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  3234. }
  3235. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3236. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  3237. if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
  3238. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  3239. }
  3240. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3241. protected virtual void OnBindingContextChanged(EventArgs e) {
  3242. CheckDataBindings ();
  3243. if (BindingContextChanged!=null) {
  3244. BindingContextChanged(this, e);
  3245. }
  3246. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  3247. }
  3248. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3249. protected virtual void OnCausesValidationChanged(EventArgs e) {
  3250. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  3251. }
  3252. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3253. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  3254. if (ChangeUICues!=null) ChangeUICues(this, e);
  3255. }
  3256. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3257. protected virtual void OnClick(EventArgs e) {
  3258. if (Click!=null) Click(this, e);
  3259. }
  3260. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3261. protected virtual void OnContextMenuChanged(EventArgs e) {
  3262. if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
  3263. }
  3264. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3265. protected virtual void OnControlAdded(ControlEventArgs e) {
  3266. if (ControlAdded!=null) ControlAdded(this, e);
  3267. }
  3268. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3269. protected virtual void OnControlRemoved(ControlEventArgs e) {
  3270. if (ControlRemoved!=null) ControlRemoved(this, e);
  3271. }
  3272. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3273. protected virtual void OnCreateControl() {
  3274. // Override me!
  3275. }
  3276. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3277. protected virtual void OnCursorChanged(EventArgs e) {
  3278. if (CursorChanged!=null) CursorChanged(this, e);
  3279. }
  3280. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3281. protected virtual void OnDockChanged(EventArgs e) {
  3282. if (DockChanged!=null) DockChanged(this, e);
  3283. }
  3284. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3285. protected virtual void OnDoubleClick(EventArgs e) {
  3286. if (DoubleClick!=null) DoubleClick(this, e);
  3287. }
  3288. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3289. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  3290. if (DragDrop!=null) DragDrop(this, drgevent);
  3291. }
  3292. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3293. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  3294. if (DragEnter!=null) DragEnter(this, drgevent);
  3295. }
  3296. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3297. protected virtual void OnDragLeave(EventArgs e) {
  3298. if (DragLeave!=null) DragLeave(this, e);
  3299. }
  3300. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3301. protected virtual void OnDragOver(DragEventArgs drgevent) {
  3302. if (DragOver!=null) DragOver(this, drgevent);
  3303. }
  3304. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3305. protected virtual void OnEnabledChanged(EventArgs e) {
  3306. if (EnabledChanged!=null) EnabledChanged(this, e);
  3307. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
  3308. }
  3309. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3310. protected virtual void OnEnter(EventArgs e) {
  3311. if (Enter!=null) Enter(this, e);
  3312. }
  3313. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3314. protected virtual void OnFontChanged(EventArgs e) {
  3315. if (FontChanged!=null) FontChanged(this, e);
  3316. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
  3317. }
  3318. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3319. protected virtual void OnForeColorChanged(EventArgs e) {
  3320. if (ForeColorChanged!=null) ForeColorChanged(this, e);
  3321. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  3322. }
  3323. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3324. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  3325. if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
  3326. }
  3327. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3328. protected virtual void OnGotFocus(EventArgs e) {
  3329. if (GotFocus!=null) GotFocus(this, e);
  3330. }
  3331. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3332. protected virtual void OnHandleCreated(EventArgs e) {
  3333. if (HandleCreated!=null) HandleCreated(this, e);
  3334. }
  3335. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3336. protected virtual void OnHandleDestroyed(EventArgs e) {
  3337. if (HandleDestroyed!=null) HandleDestroyed(this, e);
  3338. }
  3339. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3340. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  3341. if (HelpRequested!=null) HelpRequested(this, hevent);
  3342. }
  3343. protected virtual void OnImeModeChanged(EventArgs e) {
  3344. if (ImeModeChanged!=null) ImeModeChanged(this, e);
  3345. }
  3346. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3347. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  3348. needs_redraw = true;
  3349. if (Invalidated!=null) Invalidated(this, e);
  3350. }
  3351. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3352. protected virtual void OnKeyDown(KeyEventArgs e) {
  3353. if (KeyDown!=null) KeyDown(this, e);
  3354. }
  3355. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3356. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  3357. if (KeyPress!=null) KeyPress(this, e);
  3358. }
  3359. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3360. protected virtual void OnKeyUp(KeyEventArgs e) {
  3361. if (KeyUp!=null) KeyUp(this, e);
  3362. }
  3363. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3364. protected virtual void OnLayout(LayoutEventArgs levent) {
  3365. if (Layout!=null) Layout(this, levent);
  3366. }
  3367. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3368. protected virtual void OnLeave(EventArgs e) {
  3369. if (Leave!=null) Leave(this, e);
  3370. }
  3371. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3372. protected virtual void OnLocationChanged(EventArgs e) {
  3373. OnMove(e);
  3374. if (LocationChanged!=null) LocationChanged(this, e);
  3375. }
  3376. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3377. protected virtual void OnLostFocus(EventArgs e) {
  3378. if (LostFocus!=null) LostFocus(this, e);
  3379. }
  3380. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3381. protected virtual void OnMouseDown(MouseEventArgs e) {
  3382. if (MouseDown!=null) MouseDown(this, e);
  3383. }
  3384. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3385. protected virtual void OnMouseEnter(EventArgs e) {
  3386. if (MouseEnter!=null) MouseEnter(this, e);
  3387. }
  3388. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3389. protected virtual void OnMouseHover(EventArgs e) {
  3390. if (MouseHover!=null) MouseHover(this, e);
  3391. }
  3392. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3393. protected virtual void OnMouseLeave(EventArgs e) {
  3394. if (MouseLeave!=null) MouseLeave(this, e);
  3395. }
  3396. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3397. protected virtual void OnMouseMove(MouseEventArgs e) {
  3398. if (MouseMove!=null) MouseMove(this, e);
  3399. }
  3400. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3401. protected virtual void OnMouseUp(MouseEventArgs e) {
  3402. if (MouseUp!=null) MouseUp(this, e);
  3403. }
  3404. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3405. protected virtual void OnMouseWheel(MouseEventArgs e) {
  3406. if (MouseWheel!=null) MouseWheel(this, e);
  3407. }
  3408. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3409. protected virtual void OnMove(EventArgs e) {
  3410. if (Move!=null) Move(this, e);
  3411. }
  3412. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3413. protected virtual void OnNotifyMessage(Message m) {
  3414. // Override me!
  3415. }
  3416. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3417. protected virtual void OnPaint(PaintEventArgs e) {
  3418. if (Paint!=null) Paint(this, e);
  3419. }
  3420. internal virtual void OnPaintInternal(PaintEventArgs e) {
  3421. // Override me
  3422. }
  3423. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3424. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  3425. PaintControlBackground (pevent);
  3426. }
  3427. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3428. protected virtual void OnParentBackColorChanged(EventArgs e) {
  3429. if (background_color.IsEmpty && background_image==null) {
  3430. Invalidate();
  3431. OnBackColorChanged(e);
  3432. }
  3433. }
  3434. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3435. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  3436. if (background_color.IsEmpty && background_image==null) {
  3437. Invalidate();
  3438. OnBackgroundImageChanged(e);
  3439. }
  3440. }
  3441. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3442. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  3443. if (binding_context==null) {
  3444. binding_context=Parent.binding_context;
  3445. OnBindingContextChanged(e);
  3446. }
  3447. }
  3448. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3449. protected virtual void OnParentChanged(EventArgs e) {
  3450. if (ParentChanged!=null) ParentChanged(this, e);
  3451. }
  3452. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3453. protected virtual void OnParentEnabledChanged(EventArgs e) {
  3454. if (is_enabled != Parent.is_enabled) {
  3455. is_enabled=Parent.is_enabled;
  3456. Invalidate();
  3457. if (EnabledChanged != null) {
  3458. EnabledChanged(this, e);
  3459. }
  3460. }
  3461. }
  3462. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3463. protected virtual void OnParentFontChanged(EventArgs e) {
  3464. if (font==null) {
  3465. Invalidate();
  3466. OnFontChanged(e);
  3467. }
  3468. }
  3469. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3470. protected virtual void OnParentForeColorChanged(EventArgs e) {
  3471. if (foreground_color.IsEmpty) {
  3472. Invalidate();
  3473. OnForeColorChanged(e);
  3474. }
  3475. }
  3476. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3477. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  3478. if (right_to_left==RightToLeft.Inherit) {
  3479. Invalidate();
  3480. OnRightToLeftChanged(e);
  3481. }
  3482. }
  3483. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3484. protected virtual void OnParentVisibleChanged(EventArgs e) {
  3485. if (is_visible) {
  3486. OnVisibleChanged(e);
  3487. }
  3488. }
  3489. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3490. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  3491. if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
  3492. }
  3493. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3494. protected virtual void OnResize(EventArgs e) {
  3495. if (Resize!=null) Resize(this, e);
  3496. PerformLayout(this, "bounds");
  3497. if (parent != null) {
  3498. parent.PerformLayout();
  3499. }
  3500. }
  3501. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3502. protected virtual void OnRightToLeftChanged(EventArgs e) {
  3503. if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
  3504. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  3505. }
  3506. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3507. protected virtual void OnSizeChanged(EventArgs e) {
  3508. InvalidateBuffers ();
  3509. OnResize(e);
  3510. if (SizeChanged!=null) SizeChanged(this, e);
  3511. }
  3512. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3513. protected virtual void OnStyleChanged(EventArgs e) {
  3514. if (StyleChanged!=null) StyleChanged(this, e);
  3515. }
  3516. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3517. protected virtual void OnSystemColorsChanged(EventArgs e) {
  3518. if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
  3519. }
  3520. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3521. protected virtual void OnTabIndexChanged(EventArgs e) {
  3522. if (TabIndexChanged!=null) TabIndexChanged(this, e);
  3523. }
  3524. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3525. protected virtual void OnTabStopChanged(EventArgs e) {
  3526. if (TabStopChanged!=null) TabStopChanged(this, e);
  3527. }
  3528. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3529. protected virtual void OnTextChanged(EventArgs e) {
  3530. if (TextChanged!=null) TextChanged(this, e);
  3531. }
  3532. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3533. protected virtual void OnValidated(EventArgs e) {
  3534. if (Validated!=null) Validated(this, e);
  3535. }
  3536. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3537. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  3538. if (Validating!=null) Validating(this, e);
  3539. }
  3540. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3541. protected virtual void OnVisibleChanged(EventArgs e) {
  3542. if (!is_visible) {
  3543. if (dc_mem!=null) {
  3544. dc_mem.Dispose ();
  3545. dc_mem=null;
  3546. }
  3547. if (bmp_mem!=null) {
  3548. bmp_mem.Dispose();
  3549. bmp_mem=null;
  3550. }
  3551. } else {
  3552. if (!is_disposed) {
  3553. if (!this.IsHandleCreated) {
  3554. this.CreateControl();
  3555. }
  3556. PerformLayout();
  3557. }
  3558. }
  3559. if (VisibleChanged!=null) VisibleChanged(this, e);
  3560. // We need to tell our kids
  3561. for (int i=0; i<child_controls.Count; i++) {
  3562. child_controls[i].OnParentVisibleChanged(e);
  3563. }
  3564. }
  3565. #endregion // OnXXX methods
  3566. #region Events
  3567. public event EventHandler BackColorChanged;
  3568. public event EventHandler BackgroundImageChanged;
  3569. public event EventHandler BindingContextChanged;
  3570. public event EventHandler CausesValidationChanged;
  3571. public event UICuesEventHandler ChangeUICues;
  3572. public event EventHandler Click;
  3573. public event EventHandler ContextMenuChanged;
  3574. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3575. [Browsable(false)]
  3576. public event ControlEventHandler ControlAdded;
  3577. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3578. [Browsable(false)]
  3579. public event ControlEventHandler ControlRemoved;
  3580. [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
  3581. public event EventHandler CursorChanged;
  3582. public event EventHandler DockChanged;
  3583. public event EventHandler DoubleClick;
  3584. public event DragEventHandler DragDrop;
  3585. public event DragEventHandler DragEnter;
  3586. public event EventHandler DragLeave;
  3587. public event DragEventHandler DragOver;
  3588. public event EventHandler EnabledChanged;
  3589. public event EventHandler Enter;
  3590. public event EventHandler FontChanged;
  3591. public event EventHandler ForeColorChanged;
  3592. public event GiveFeedbackEventHandler GiveFeedback;
  3593. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3594. [Browsable(false)]
  3595. public event EventHandler GotFocus;
  3596. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3597. [Browsable(false)]
  3598. public event EventHandler HandleCreated;
  3599. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3600. [Browsable(false)]
  3601. public event EventHandler HandleDestroyed;
  3602. public event HelpEventHandler HelpRequested;
  3603. public event EventHandler ImeModeChanged;
  3604. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3605. [Browsable(false)]
  3606. public event InvalidateEventHandler Invalidated;
  3607. public event KeyEventHandler KeyDown;
  3608. public event KeyPressEventHandler KeyPress;
  3609. public event KeyEventHandler KeyUp;
  3610. public event LayoutEventHandler Layout;
  3611. public event EventHandler Leave;
  3612. public event EventHandler LocationChanged;
  3613. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3614. [Browsable(false)]
  3615. public event EventHandler LostFocus;
  3616. public event MouseEventHandler MouseDown;
  3617. public event EventHandler MouseEnter;
  3618. public event EventHandler MouseHover;
  3619. public event EventHandler MouseLeave;
  3620. public event MouseEventHandler MouseMove;
  3621. public event MouseEventHandler MouseUp;
  3622. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3623. [Browsable(false)]
  3624. public event MouseEventHandler MouseWheel;
  3625. public event EventHandler Move;
  3626. public event PaintEventHandler Paint;
  3627. public event EventHandler ParentChanged;
  3628. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
  3629. public event QueryContinueDragEventHandler QueryContinueDrag;
  3630. public event EventHandler Resize;
  3631. public event EventHandler RightToLeftChanged;
  3632. public event EventHandler SizeChanged;
  3633. public event EventHandler StyleChanged;
  3634. public event EventHandler SystemColorsChanged;
  3635. public event EventHandler TabIndexChanged;
  3636. public event EventHandler TabStopChanged;
  3637. public event EventHandler TextChanged;
  3638. public event EventHandler Validated;
  3639. public event CancelEventHandler Validating;
  3640. public event EventHandler VisibleChanged;
  3641. #endregion // Events
  3642. }
  3643. }