Control.cs 147 KB

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