Control.cs 183 KB

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