Control.cs 134 KB

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