Control.cs 181 KB

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