Control.cs 181 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074
  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. bounds.X=left;
  906. bounds.Y=top;
  907. bounds.Width=width;
  908. bounds.Height=height;
  909. SetBounds(left, top, width, height, BoundsSpecified.All);
  910. Text=text;
  911. }
  912. public Control (string text) : this()
  913. {
  914. Text=text;
  915. }
  916. public Control (string text, int left, int top, int width, int height) : this()
  917. {
  918. bounds.X=left;
  919. bounds.Y=top;
  920. bounds.Width=width;
  921. bounds.Height=height;
  922. SetBounds(left, top, width, height, BoundsSpecified.All);
  923. Text=text;
  924. }
  925. private delegate void RemoveDelegate(object c);
  926. protected override void Dispose (bool disposing)
  927. {
  928. if (!is_disposed && disposing) {
  929. is_disposing = true;
  930. Capture = false;
  931. DisposeBackBuffer ();
  932. if (this.InvokeRequired) {
  933. if (Application.MessageLoop && IsHandleCreated) {
  934. this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
  935. }
  936. } else {
  937. DestroyHandle();
  938. }
  939. if (parent != null)
  940. parent.Controls.Remove(this);
  941. Control [] children = child_controls.GetAllControls ();
  942. for (int i=0; i<children.Length; i++) {
  943. children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
  944. children[i].Dispose();
  945. }
  946. }
  947. is_disposed = true;
  948. is_disposing = false;
  949. is_visible = false;
  950. base.Dispose(disposing);
  951. }
  952. #endregion // Public Constructors
  953. #region Internal Properties
  954. private MenuTracker active_tracker;
  955. internal MenuTracker ActiveTracker {
  956. get { return active_tracker; }
  957. set {
  958. if (value == active_tracker)
  959. return;
  960. Capture = value != null;
  961. active_tracker = value;
  962. }
  963. }
  964. // Control is currently selected, like Focused, except maintains state
  965. // when Form loses focus
  966. internal bool InternalSelected {
  967. get {
  968. IContainerControl container;
  969. container = GetContainerControl();
  970. if (container != null && container.ActiveControl == this)
  971. return true;
  972. return false;
  973. }
  974. }
  975. // Looks for focus in child controls
  976. // and also in the implicit ones
  977. internal bool InternalContainsFocus {
  978. get {
  979. IntPtr focused_window;
  980. focused_window = XplatUI.GetFocus();
  981. if (IsHandleCreated) {
  982. if (focused_window == Handle)
  983. return true;
  984. foreach (Control child_control in child_controls.GetAllControls ())
  985. if (child_control.InternalContainsFocus)
  986. return true;
  987. }
  988. return false;
  989. }
  990. }
  991. // Mouse is currently within the control's bounds
  992. internal bool Entered {
  993. get { return this.is_entered; }
  994. }
  995. internal bool VisibleInternal {
  996. get { return is_visible; }
  997. }
  998. internal LayoutType ControlLayoutType {
  999. get { return layout_type; }
  1000. }
  1001. internal BorderStyle InternalBorderStyle {
  1002. get {
  1003. return border_style;
  1004. }
  1005. set {
  1006. if (!Enum.IsDefined (typeof (BorderStyle), value))
  1007. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
  1008. if (border_style != value) {
  1009. border_style = value;
  1010. if (IsHandleCreated) {
  1011. XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
  1012. RecreateHandle ();
  1013. Refresh ();
  1014. } else
  1015. client_size = ClientSizeFromSize (bounds.Size);
  1016. }
  1017. }
  1018. }
  1019. internal Size InternalClientSize { set { this.client_size = value; } }
  1020. internal virtual bool ActivateOnShow { get { return true; } }
  1021. internal Rectangle ExplicitBounds { get { return this.explicit_bounds; } set { this.explicit_bounds = value; } }
  1022. internal bool ValidationFailed {
  1023. get {
  1024. ContainerControl c = InternalGetContainerControl ();
  1025. if (c != null)
  1026. return c.validation_failed;
  1027. return false;
  1028. }
  1029. set {
  1030. ContainerControl c = InternalGetContainerControl ();
  1031. if (c != null)
  1032. c.validation_failed = value;
  1033. }
  1034. }
  1035. #endregion // Internal Properties
  1036. #region Private & Internal Methods
  1037. #if NET_2_0
  1038. void IDropTarget.OnDragDrop (DragEventArgs drgEvent)
  1039. {
  1040. OnDragDrop (drgEvent);
  1041. }
  1042. void IDropTarget.OnDragEnter (DragEventArgs drgEvent)
  1043. {
  1044. OnDragEnter (drgEvent);
  1045. }
  1046. void IDropTarget.OnDragLeave (EventArgs e)
  1047. {
  1048. OnDragLeave (e);
  1049. }
  1050. void IDropTarget.OnDragOver (DragEventArgs drgEvent)
  1051. {
  1052. OnDragOver (drgEvent);
  1053. }
  1054. #endif
  1055. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
  1056. return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
  1057. }
  1058. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
  1059. AsyncMethodResult result;
  1060. AsyncMethodData data;
  1061. result = new AsyncMethodResult ();
  1062. data = new AsyncMethodData ();
  1063. data.Handle = control.GetInvokableHandle ();
  1064. data.Method = method;
  1065. data.Args = args;
  1066. data.Result = result;
  1067. #if NET_2_0
  1068. if (!ExecutionContext.IsFlowSuppressed ()) {
  1069. data.Context = ExecutionContext.Capture ();
  1070. }
  1071. #else
  1072. #if !MWF_ON_MSRUNTIME
  1073. if (SecurityManager.SecurityEnabled) {
  1074. data.Stack = CompressedStack.GetCompressedStack ();
  1075. }
  1076. #endif
  1077. #endif
  1078. XplatUI.SendAsyncMethod (data);
  1079. return result;
  1080. }
  1081. // The CheckForIllegalCrossThreadCalls in the #if 2.0 of
  1082. // Control.Handle throws an exception when we are trying
  1083. // to get the Handle to properly invoke on. This avoids that.
  1084. private IntPtr GetInvokableHandle ()
  1085. {
  1086. if (!IsHandleCreated)
  1087. CreateHandle ();
  1088. return window.Handle;
  1089. }
  1090. internal void PointToClient (ref int x, ref int y) {
  1091. XplatUI.ScreenToClient (Handle, ref x, ref y);
  1092. }
  1093. internal void PointToScreen (ref int x, ref int y) {
  1094. XplatUI.ClientToScreen (Handle, ref x, ref y);
  1095. }
  1096. internal bool IsRecreating {
  1097. get {
  1098. return is_recreating;
  1099. }
  1100. }
  1101. internal Graphics DeviceContext {
  1102. get { return Hwnd.GraphicsContext; }
  1103. }
  1104. // An internal way to have a fixed height
  1105. // Basically for DataTimePicker 2.0
  1106. internal virtual int OverrideHeight (int height)
  1107. {
  1108. return height;
  1109. }
  1110. private void ProcessActiveTracker (ref Message m)
  1111. {
  1112. bool is_up = ((Msg) m.Msg == Msg.WM_LBUTTONUP) ||
  1113. ((Msg) m.Msg == Msg.WM_RBUTTONUP);
  1114. MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32 ());
  1115. // We add in the button that was released (not sent in WParam)
  1116. if (is_up) {
  1117. switch ((Msg)m.Msg) {
  1118. case Msg.WM_LBUTTONUP:
  1119. mb |= MouseButtons.Left;
  1120. break;
  1121. case Msg.WM_RBUTTONUP:
  1122. mb |= MouseButtons.Right;
  1123. break;
  1124. }
  1125. }
  1126. MouseEventArgs args = new MouseEventArgs (
  1127. mb,
  1128. mouse_clicks,
  1129. Control.MousePosition.X,
  1130. Control.MousePosition.Y,
  1131. 0);
  1132. if (is_up) {
  1133. active_tracker.OnMouseUp (args);
  1134. mouse_clicks = 1;
  1135. } else {
  1136. if (!active_tracker.OnMouseDown (args)) {
  1137. Control control = GetRealChildAtPoint (Cursor.Position);
  1138. if (control != null) {
  1139. Point pt = control.PointToClient (Cursor.Position);
  1140. XplatUI.SendMessage (control.Handle,
  1141. (Msg)m.Msg,
  1142. m.WParam,
  1143. MakeParam (pt.X, pt.Y));
  1144. }
  1145. }
  1146. }
  1147. }
  1148. private Control FindControlToInvokeOn ()
  1149. {
  1150. Control p = this;
  1151. do {
  1152. if (p.IsHandleCreated)
  1153. break;
  1154. p = p.parent;
  1155. } while (p != null);
  1156. if (p == null || !p.IsHandleCreated)
  1157. throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
  1158. return p;
  1159. }
  1160. private void InvalidateBackBuffer () {
  1161. if (backbuffer != null)
  1162. backbuffer.Invalidate ();
  1163. }
  1164. private DoubleBuffer GetBackBuffer () {
  1165. if (backbuffer == null)
  1166. backbuffer = new DoubleBuffer (this);
  1167. return backbuffer;
  1168. }
  1169. private void DisposeBackBuffer () {
  1170. if (backbuffer != null) {
  1171. backbuffer.Dispose ();
  1172. backbuffer = null;
  1173. }
  1174. }
  1175. internal static void SetChildColor(Control parent) {
  1176. Control child;
  1177. for (int i=0; i < parent.child_controls.Count; i++) {
  1178. child=parent.child_controls[i];
  1179. if (child.child_controls.Count>0) {
  1180. SetChildColor(child);
  1181. }
  1182. }
  1183. }
  1184. internal bool Select(Control control) {
  1185. IContainerControl container;
  1186. if (control == null) {
  1187. return false;
  1188. }
  1189. container = GetContainerControl();
  1190. if (container != null && (Control)container != control) {
  1191. container.ActiveControl = control;
  1192. }
  1193. else if (control.IsHandleCreated) {
  1194. XplatUI.SetFocus(control.window.Handle);
  1195. }
  1196. return true;
  1197. }
  1198. internal virtual void DoDefaultAction() {
  1199. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1200. }
  1201. internal static IntPtr MakeParam (int low, int high){
  1202. return new IntPtr (high << 16 | low & 0xffff);
  1203. }
  1204. internal static int LowOrder (int param) {
  1205. return ((int)(short)(param & 0xffff));
  1206. }
  1207. internal static int HighOrder (long param) {
  1208. return ((int)(short)(param >> 16));
  1209. }
  1210. // This method exists so controls overriding OnPaintBackground can have default background painting done
  1211. internal virtual void PaintControlBackground (PaintEventArgs pevent) {
  1212. bool tbstyle_flat = ((CreateParams.Style & (int) ToolBarStyles.TBSTYLE_FLAT) != 0);
  1213. // If we have transparent background
  1214. if (((BackColor.A != 0xff) && GetStyle(ControlStyles.SupportsTransparentBackColor)) || tbstyle_flat) {
  1215. if (parent != null) {
  1216. PaintEventArgs parent_pe;
  1217. GraphicsState state;
  1218. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1219. state = parent_pe.Graphics.Save();
  1220. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1221. parent.OnPaintBackground(parent_pe);
  1222. parent_pe.Graphics.Restore(state);
  1223. state = parent_pe.Graphics.Save();
  1224. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1225. parent.OnPaint(parent_pe);
  1226. parent_pe.Graphics.Restore(state);
  1227. parent_pe.SetGraphics(null);
  1228. }
  1229. }
  1230. if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
  1231. if (parent != null) {
  1232. PaintEventArgs parent_pe;
  1233. Region region;
  1234. GraphicsState state;
  1235. Hwnd hwnd;
  1236. hwnd = Hwnd.ObjectFromHandle(Handle);
  1237. if (hwnd != null) {
  1238. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1239. region = new Region ();
  1240. region.MakeEmpty();
  1241. region.Union(ClientRectangle);
  1242. foreach (Rectangle r in hwnd.ClipRectangles) {
  1243. region.Union (r);
  1244. }
  1245. state = parent_pe.Graphics.Save();
  1246. parent_pe.Graphics.Clip = region;
  1247. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1248. parent.OnPaintBackground(parent_pe);
  1249. parent_pe.Graphics.Restore(state);
  1250. state = parent_pe.Graphics.Save();
  1251. parent_pe.Graphics.Clip = region;
  1252. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1253. parent.OnPaint(parent_pe);
  1254. parent_pe.Graphics.Restore(state);
  1255. parent_pe.SetGraphics(null);
  1256. region.Intersect(clip_region);
  1257. pevent.Graphics.Clip = region;
  1258. }
  1259. }
  1260. }
  1261. if (background_image == null) {
  1262. if (!tbstyle_flat) {
  1263. Rectangle paintRect = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
  1264. Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
  1265. pevent.Graphics.FillRectangle(pen, paintRect);
  1266. }
  1267. return;
  1268. }
  1269. DrawBackgroundImage (pevent.Graphics);
  1270. }
  1271. void DrawBackgroundImage (Graphics g) {
  1272. #if NET_2_0
  1273. Rectangle drawing_rectangle = new Rectangle ();
  1274. g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  1275. switch (backgroundimage_layout)
  1276. {
  1277. case ImageLayout.Tile:
  1278. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  1279. g.FillRectangle (b, ClientRectangle);
  1280. }
  1281. return;
  1282. case ImageLayout.Center:
  1283. drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
  1284. drawing_rectangle.Size = background_image.Size;
  1285. break;
  1286. case ImageLayout.None:
  1287. drawing_rectangle.Location = Point.Empty;
  1288. drawing_rectangle.Size = background_image.Size;
  1289. break;
  1290. case ImageLayout.Stretch:
  1291. drawing_rectangle = ClientRectangle;
  1292. break;
  1293. case ImageLayout.Zoom:
  1294. drawing_rectangle = ClientRectangle;
  1295. if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
  1296. drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
  1297. drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
  1298. } else {
  1299. drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
  1300. drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
  1301. }
  1302. break;
  1303. default:
  1304. return;
  1305. }
  1306. g.DrawImage (background_image, drawing_rectangle);
  1307. #else
  1308. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  1309. g.FillRectangle (b, ClientRectangle);
  1310. }
  1311. #endif
  1312. }
  1313. internal virtual void DndEnter (DragEventArgs e) {
  1314. try {
  1315. OnDragEnter (e);
  1316. } catch { }
  1317. }
  1318. internal virtual void DndOver (DragEventArgs e) {
  1319. try {
  1320. OnDragOver (e);
  1321. } catch { }
  1322. }
  1323. internal virtual void DndDrop (DragEventArgs e) {
  1324. try {
  1325. OnDragDrop (e);
  1326. } catch (Exception exc) {
  1327. Console.Error.WriteLine ("MWF: Exception while dropping:");
  1328. Console.Error.WriteLine (exc);
  1329. }
  1330. }
  1331. internal virtual void DndLeave (EventArgs e) {
  1332. try {
  1333. OnDragLeave (e);
  1334. } catch { }
  1335. }
  1336. internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
  1337. try {
  1338. OnGiveFeedback(e);
  1339. } catch { }
  1340. }
  1341. internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
  1342. try {
  1343. OnQueryContinueDrag(e);
  1344. } catch { }
  1345. }
  1346. internal static MouseButtons FromParamToMouseButtons (long param) {
  1347. MouseButtons buttons = MouseButtons.None;
  1348. if ((param & (long) MsgButtons.MK_LBUTTON) != 0)
  1349. buttons |= MouseButtons.Left;
  1350. if ((param & (long)MsgButtons.MK_MBUTTON) != 0)
  1351. buttons |= MouseButtons.Middle;
  1352. if ((param & (long)MsgButtons.MK_RBUTTON) != 0)
  1353. buttons |= MouseButtons.Right;
  1354. return buttons;
  1355. }
  1356. internal virtual void FireEnter () {
  1357. OnEnter (EventArgs.Empty);
  1358. }
  1359. internal virtual void FireLeave () {
  1360. OnLeave (EventArgs.Empty);
  1361. }
  1362. internal virtual void FireValidating (CancelEventArgs ce) {
  1363. OnValidating (ce);
  1364. }
  1365. internal virtual void FireValidated () {
  1366. OnValidated (EventArgs.Empty);
  1367. }
  1368. internal virtual bool ProcessControlMnemonic(char charCode) {
  1369. return ProcessMnemonic(charCode);
  1370. }
  1371. private static Control FindFlatForward(Control container, Control start) {
  1372. Control found;
  1373. int index;
  1374. int end;
  1375. bool hit;
  1376. found = null;
  1377. end = container.child_controls.Count;
  1378. hit = false;
  1379. if (start != null) {
  1380. index = start.tab_index;
  1381. } else {
  1382. index = -1;
  1383. }
  1384. for (int i = 0; i < end; i++) {
  1385. if (start == container.child_controls[i]) {
  1386. hit = true;
  1387. continue;
  1388. }
  1389. if (found == null || found.tab_index > container.child_controls[i].tab_index) {
  1390. if (container.child_controls[i].tab_index > index || (hit && container.child_controls[i].tab_index == index)) {
  1391. found = container.child_controls[i];
  1392. }
  1393. }
  1394. }
  1395. return found;
  1396. }
  1397. private static Control FindControlForward(Control container, Control start) {
  1398. Control found;
  1399. found = null;
  1400. if (start == null) {
  1401. return FindFlatForward(container, start);
  1402. }
  1403. if (start.child_controls != null && start.child_controls.Count > 0 &&
  1404. (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
  1405. return FindControlForward(start, null);
  1406. }
  1407. else {
  1408. while (start != container) {
  1409. found = FindFlatForward(start.parent, start);
  1410. if (found != null) {
  1411. return found;
  1412. }
  1413. start = start.parent;
  1414. }
  1415. }
  1416. return null;
  1417. }
  1418. private static Control FindFlatBackward(Control container, Control start) {
  1419. Control found;
  1420. int index;
  1421. int end;
  1422. bool hit;
  1423. found = null;
  1424. end = container.child_controls.Count;
  1425. hit = false;
  1426. if (start != null) {
  1427. index = start.tab_index;
  1428. } else {
  1429. index = int.MaxValue;
  1430. }
  1431. for (int i = end - 1; i >= 0; i--) {
  1432. if (start == container.child_controls[i]) {
  1433. hit = true;
  1434. continue;
  1435. }
  1436. if (found == null || found.tab_index < container.child_controls[i].tab_index) {
  1437. if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
  1438. found = container.child_controls[i];
  1439. }
  1440. }
  1441. return found;
  1442. }
  1443. private static Control FindControlBackward(Control container, Control start) {
  1444. Control found = null;
  1445. if (start == null) {
  1446. found = FindFlatBackward(container, start);
  1447. }
  1448. else if (start != container) {
  1449. if (start.parent != null) {
  1450. found = FindFlatBackward(start.parent, start);
  1451. if (found == null) {
  1452. if (start.parent != container)
  1453. return start.parent;
  1454. return null;
  1455. }
  1456. }
  1457. }
  1458. if (found == null || start.parent == null)
  1459. found = start;
  1460. while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
  1461. found.child_controls != null && found.child_controls.Count > 0)) {
  1462. // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
  1463. // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
  1464. found = FindFlatBackward(found, null);
  1465. }
  1466. return found;
  1467. /*
  1468. Control found;
  1469. found = null;
  1470. if (start != null) {
  1471. found = FindFlatBackward(start.parent, start);
  1472. if (found == null) {
  1473. if (start.parent != container) {
  1474. return start.parent;
  1475. }
  1476. }
  1477. }
  1478. if (found == null) {
  1479. found = FindFlatBackward(container, start);
  1480. }
  1481. if (container != start) {
  1482. while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
  1483. found = FindControlBackward(found, null);
  1484. if (found != null) {
  1485. return found;
  1486. }
  1487. }
  1488. }
  1489. return found;
  1490. */
  1491. }
  1492. internal virtual void HandleClick(int clicks, MouseEventArgs me) {
  1493. bool standardclick = GetStyle (ControlStyles.StandardClick);
  1494. bool standardclickclick = GetStyle (ControlStyles.StandardDoubleClick);
  1495. if ((clicks > 1) && standardclick && standardclickclick) {
  1496. #if NET_2_0
  1497. OnDoubleClick (me);
  1498. OnMouseDoubleClick (me);
  1499. #else
  1500. OnDoubleClick(EventArgs.Empty);
  1501. #endif
  1502. } else if (clicks == 1 && standardclick && !ValidationFailed) {
  1503. #if NET_2_0
  1504. OnClick (me);
  1505. OnMouseClick (me);
  1506. #else
  1507. OnClick(EventArgs.Empty);
  1508. #endif
  1509. }
  1510. }
  1511. internal void CaptureWithConfine (Control ConfineWindow) {
  1512. if (this.IsHandleCreated && !is_captured) {
  1513. is_captured = true;
  1514. XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
  1515. }
  1516. }
  1517. private void CheckDataBindings () {
  1518. if (data_bindings == null)
  1519. return;
  1520. foreach (Binding binding in data_bindings) {
  1521. binding.Check ();
  1522. }
  1523. }
  1524. private void ChangeParent(Control new_parent) {
  1525. bool pre_enabled;
  1526. bool pre_visible;
  1527. Font pre_font;
  1528. Color pre_fore_color;
  1529. Color pre_back_color;
  1530. RightToLeft pre_rtl;
  1531. // These properties are inherited from our parent
  1532. // Get them pre parent-change and then send events
  1533. // if they are changed after we have our new parent
  1534. pre_enabled = Enabled;
  1535. pre_visible = Visible;
  1536. pre_font = Font;
  1537. pre_fore_color = ForeColor;
  1538. pre_back_color = BackColor;
  1539. pre_rtl = RightToLeft;
  1540. // MS doesn't seem to send a CursorChangedEvent
  1541. parent = new_parent;
  1542. Form frm = this as Form;
  1543. if (frm != null) {
  1544. frm.ChangingParent (new_parent);
  1545. } else if (IsHandleCreated) {
  1546. IntPtr parent_handle = IntPtr.Zero;
  1547. if (new_parent != null && new_parent.IsHandleCreated)
  1548. parent_handle = new_parent.Handle;
  1549. XplatUI.SetParent (Handle, parent_handle);
  1550. }
  1551. OnParentChanged(EventArgs.Empty);
  1552. if (pre_enabled != Enabled) {
  1553. OnEnabledChanged(EventArgs.Empty);
  1554. }
  1555. if (pre_visible != Visible) {
  1556. OnVisibleChanged(EventArgs.Empty);
  1557. }
  1558. if (pre_font != Font) {
  1559. OnFontChanged(EventArgs.Empty);
  1560. }
  1561. if (pre_fore_color != ForeColor) {
  1562. OnForeColorChanged(EventArgs.Empty);
  1563. }
  1564. if (pre_back_color != BackColor) {
  1565. OnBackColorChanged(EventArgs.Empty);
  1566. }
  1567. if (pre_rtl != RightToLeft) {
  1568. // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
  1569. // because when RTL changes they have to recreate the win32 control
  1570. // We don't really need that (until someone runs into compatibility issues)
  1571. OnRightToLeftChanged(EventArgs.Empty);
  1572. }
  1573. if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
  1574. CreateControl();
  1575. }
  1576. if ((binding_context == null) && Created) {
  1577. OnBindingContextChanged(EventArgs.Empty);
  1578. }
  1579. }
  1580. // Sometimes we need to do this calculation without it being virtual (constructor)
  1581. internal Size InternalSizeFromClientSize (Size clientSize)
  1582. {
  1583. Rectangle ClientRect;
  1584. Rectangle WindowRect;
  1585. CreateParams cp;
  1586. ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
  1587. cp = this.CreateParams;
  1588. if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
  1589. return new Size (WindowRect.Width, WindowRect.Height);
  1590. return Size.Empty;
  1591. }
  1592. internal Size ClientSizeFromSize (Size size)
  1593. {
  1594. // Calling this gives us the difference in Size and ClientSize.
  1595. // We just have to apply that difference to our given size.
  1596. Size client_size = this.InternalSizeFromClientSize (size);
  1597. if (client_size == Size.Empty)
  1598. return Size.Empty;
  1599. return new Size (size.Width - (client_size.Width - size.Width), size.Height - (client_size.Height - size.Height));
  1600. }
  1601. internal CreateParams GetCreateParams ()
  1602. {
  1603. return CreateParams;
  1604. }
  1605. #if NET_2_0
  1606. internal virtual Size GetPreferredSizeCore (Size proposedSize)
  1607. {
  1608. return this.explicit_bounds.Size;
  1609. }
  1610. #endif
  1611. private void UpdateDistances() {
  1612. if (parent != null) {
  1613. if (bounds.Width >= 0)
  1614. dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
  1615. if (bounds.Height >= 0)
  1616. dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
  1617. recalculate_distances = false;
  1618. }
  1619. }
  1620. private Cursor GetAvailableCursor ()
  1621. {
  1622. if (Cursor != null && Enabled) {
  1623. return Cursor;
  1624. }
  1625. if (Parent != null) {
  1626. return Parent.GetAvailableCursor ();
  1627. }
  1628. return Cursors.Default;
  1629. }
  1630. private void UpdateCursor ()
  1631. {
  1632. if (!IsHandleCreated)
  1633. return;
  1634. if (!Enabled) {
  1635. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1636. return;
  1637. }
  1638. Point pt = PointToClient (Cursor.Position);
  1639. if ((!bounds.Contains (pt) && !Capture) || (GetChildAtPoint (pt) != null))
  1640. return;
  1641. if (cursor != null || use_wait_cursor) {
  1642. XplatUI.SetCursor (window.Handle, Cursor.handle);
  1643. } else {
  1644. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1645. }
  1646. }
  1647. private bool UseDoubleBuffering {
  1648. get {
  1649. if (!ThemeEngine.Current.DoubleBufferingSupported)
  1650. return false;
  1651. #if NET_2_0
  1652. if (DoubleBuffered)
  1653. return true;
  1654. #endif
  1655. return (control_style & ControlStyles.DoubleBuffer) != 0;
  1656. }
  1657. }
  1658. #endregion // Private & Internal Methods
  1659. #region Public Static Properties
  1660. public static Color DefaultBackColor {
  1661. get {
  1662. return ThemeEngine.Current.DefaultControlBackColor;
  1663. }
  1664. }
  1665. public static Font DefaultFont {
  1666. get {
  1667. return ThemeEngine.Current.DefaultFont;
  1668. }
  1669. }
  1670. public static Color DefaultForeColor {
  1671. get {
  1672. return ThemeEngine.Current.DefaultControlForeColor;
  1673. }
  1674. }
  1675. public static Keys ModifierKeys {
  1676. get {
  1677. return XplatUI.State.ModifierKeys;
  1678. }
  1679. }
  1680. public static MouseButtons MouseButtons {
  1681. get {
  1682. return XplatUI.State.MouseButtons;
  1683. }
  1684. }
  1685. public static Point MousePosition {
  1686. get {
  1687. return Cursor.Position;
  1688. }
  1689. }
  1690. #if NET_2_0
  1691. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1692. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1693. [Browsable (false)]
  1694. [MonoTODO]
  1695. public static bool CheckForIllegalCrossThreadCalls
  1696. {
  1697. get {
  1698. return verify_thread_handle;
  1699. }
  1700. set {
  1701. verify_thread_handle = value;
  1702. }
  1703. }
  1704. #endif
  1705. #endregion // Public Static Properties
  1706. #region Public Instance Properties
  1707. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1708. [Browsable(false)]
  1709. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1710. public AccessibleObject AccessibilityObject {
  1711. get {
  1712. if (accessibility_object==null) {
  1713. accessibility_object=CreateAccessibilityInstance();
  1714. }
  1715. return accessibility_object;
  1716. }
  1717. }
  1718. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1719. [Browsable(false)]
  1720. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1721. public string AccessibleDefaultActionDescription {
  1722. get {
  1723. if (accessibility_object != null)
  1724. return accessibility_object.default_action;
  1725. else
  1726. return null;
  1727. }
  1728. set {
  1729. if (accessibility_object != null)
  1730. accessibility_object.default_action = value;
  1731. }
  1732. }
  1733. [Localizable(true)]
  1734. [DefaultValue(null)]
  1735. [MWFCategory("Accessibility")]
  1736. public string AccessibleDescription {
  1737. get {
  1738. if (accessibility_object != null)
  1739. return accessibility_object.description;
  1740. else
  1741. return null;
  1742. }
  1743. set {
  1744. if (accessibility_object != null)
  1745. accessibility_object.description = value;
  1746. }
  1747. }
  1748. [Localizable(true)]
  1749. [DefaultValue(null)]
  1750. [MWFCategory("Accessibility")]
  1751. public string AccessibleName {
  1752. get {
  1753. if (accessibility_object != null)
  1754. return accessibility_object.Name;
  1755. else
  1756. return null;
  1757. }
  1758. set {
  1759. if (accessibility_object != null)
  1760. accessibility_object.Name = value;
  1761. }
  1762. }
  1763. [DefaultValue(AccessibleRole.Default)]
  1764. [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
  1765. public AccessibleRole AccessibleRole {
  1766. get {
  1767. if (accessibility_object != null)
  1768. return accessibility_object.role;
  1769. else
  1770. return AccessibleRole.Default;
  1771. }
  1772. set {
  1773. if (accessibility_object != null)
  1774. accessibility_object.role = value;
  1775. }
  1776. }
  1777. [DefaultValue(false)]
  1778. [MWFCategory("Behavior")]
  1779. public virtual bool AllowDrop {
  1780. get {
  1781. return allow_drop;
  1782. }
  1783. set {
  1784. if (allow_drop == value)
  1785. return;
  1786. allow_drop = value;
  1787. if (IsHandleCreated) {
  1788. UpdateStyles();
  1789. XplatUI.SetAllowDrop (Handle, value);
  1790. }
  1791. }
  1792. }
  1793. [Localizable(true)]
  1794. [RefreshProperties(RefreshProperties.Repaint)]
  1795. [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
  1796. [MWFCategory("Layout")]
  1797. public virtual AnchorStyles Anchor {
  1798. get {
  1799. return anchor_style;
  1800. }
  1801. set {
  1802. layout_type = LayoutType.Anchor;
  1803. if (anchor_style == value)
  1804. return;
  1805. anchor_style=value;
  1806. dock_style = DockStyle.None;
  1807. UpdateDistances ();
  1808. if (parent != null)
  1809. parent.PerformLayout(this, "Anchor");
  1810. }
  1811. }
  1812. #if NET_2_0
  1813. [Browsable (false)]
  1814. [DefaultValue (typeof (Point), "0, 0")]
  1815. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1816. public virtual Point AutoScrollOffset {
  1817. get {
  1818. return auto_scroll_offset;
  1819. }
  1820. set {
  1821. this.auto_scroll_offset = value;
  1822. }
  1823. }
  1824. // XXX: Implement me!
  1825. bool auto_size;
  1826. [RefreshProperties (RefreshProperties.All)]
  1827. [Localizable (true)]
  1828. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1829. [Browsable (false)]
  1830. [EditorBrowsable (EditorBrowsableState.Never)]
  1831. [DefaultValue (false)]
  1832. public virtual bool AutoSize {
  1833. get { return auto_size; }
  1834. set {
  1835. if (this.auto_size != value) {
  1836. auto_size = value;
  1837. // If we're turning this off, reset our size
  1838. if (!value)
  1839. Size = explicit_bounds.Size;
  1840. OnAutoSizeChanged (EventArgs.Empty);
  1841. }
  1842. }
  1843. }
  1844. #if NET_2_0
  1845. [AmbientValue ("{Width=0, Height=0}")]
  1846. #else
  1847. [AmbientValue (typeof(Size), "0, 0")]
  1848. #endif
  1849. [MWFCategory("Layout")]
  1850. public virtual Size MaximumSize {
  1851. get {
  1852. return maximum_size;
  1853. }
  1854. set {
  1855. if (maximum_size != value) {
  1856. maximum_size = value;
  1857. Size = PreferredSize;
  1858. }
  1859. }
  1860. }
  1861. internal bool ShouldSerializeMaximumSize ()
  1862. {
  1863. return this.MaximumSize != DefaultMaximumSize;
  1864. }
  1865. [MWFCategory("Layout")]
  1866. public virtual Size MinimumSize {
  1867. get {
  1868. return minimum_size;
  1869. }
  1870. set {
  1871. if (minimum_size != value) {
  1872. minimum_size = value;
  1873. Size = PreferredSize;
  1874. }
  1875. }
  1876. }
  1877. internal bool ShouldSerializeMinimumSize ()
  1878. {
  1879. return this.MinimumSize != DefaultMinimumSize;
  1880. }
  1881. #endif // NET_2_0
  1882. [DispId(-501)]
  1883. [MWFCategory("Appearance")]
  1884. public virtual Color BackColor {
  1885. get {
  1886. if (background_color.IsEmpty) {
  1887. if (parent!=null) {
  1888. Color pcolor = parent.BackColor;
  1889. if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
  1890. return pcolor;
  1891. }
  1892. return DefaultBackColor;
  1893. }
  1894. return background_color;
  1895. }
  1896. set {
  1897. if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
  1898. throw new ArgumentException("Transparent background colors are not supported on this control");
  1899. }
  1900. if (background_color != value) {
  1901. background_color=value;
  1902. SetChildColor(this);
  1903. OnBackColorChanged(EventArgs.Empty);
  1904. Invalidate();
  1905. }
  1906. }
  1907. }
  1908. internal bool ShouldSerializeBackColor ()
  1909. {
  1910. return this.BackColor != DefaultBackColor;
  1911. }
  1912. [Localizable(true)]
  1913. [DefaultValue(null)]
  1914. [MWFCategory("Appearance")]
  1915. public virtual Image BackgroundImage {
  1916. get {
  1917. return background_image;
  1918. }
  1919. set {
  1920. if (background_image!=value) {
  1921. background_image=value;
  1922. OnBackgroundImageChanged(EventArgs.Empty);
  1923. Invalidate ();
  1924. }
  1925. }
  1926. }
  1927. #if NET_2_0
  1928. [DefaultValue (ImageLayout.Tile)]
  1929. [Localizable (true)]
  1930. [MWFCategory("Appearance")]
  1931. public virtual ImageLayout BackgroundImageLayout {
  1932. get {
  1933. return backgroundimage_layout;
  1934. }
  1935. set {
  1936. if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
  1937. throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
  1938. if (value != backgroundimage_layout) {
  1939. backgroundimage_layout = value;
  1940. Invalidate ();
  1941. OnBackgroundImageLayoutChanged (EventArgs.Empty);
  1942. }
  1943. }
  1944. }
  1945. #endif
  1946. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1947. [Browsable(false)]
  1948. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1949. public virtual BindingContext BindingContext {
  1950. get {
  1951. if (binding_context != null)
  1952. return binding_context;
  1953. if (Parent == null)
  1954. return null;
  1955. binding_context = Parent.BindingContext;
  1956. return binding_context;
  1957. }
  1958. set {
  1959. if (binding_context != value) {
  1960. binding_context = value;
  1961. OnBindingContextChanged(EventArgs.Empty);
  1962. }
  1963. }
  1964. }
  1965. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1966. [Browsable(false)]
  1967. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1968. public int Bottom {
  1969. get {
  1970. return bounds.Y+bounds.Height;
  1971. }
  1972. }
  1973. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1974. [Browsable(false)]
  1975. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1976. public Rectangle Bounds {
  1977. get {
  1978. return this.bounds;
  1979. }
  1980. set {
  1981. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  1982. }
  1983. }
  1984. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1985. [Browsable(false)]
  1986. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1987. public bool CanFocus {
  1988. get {
  1989. if (IsHandleCreated && Visible && Enabled) {
  1990. return true;
  1991. }
  1992. return false;
  1993. }
  1994. }
  1995. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1996. [Browsable(false)]
  1997. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1998. public bool CanSelect {
  1999. get {
  2000. Control parent;
  2001. if (!GetStyle(ControlStyles.Selectable)) {
  2002. return false;
  2003. }
  2004. parent = this;
  2005. while (parent != null) {
  2006. if (!parent.is_visible || !parent.is_enabled) {
  2007. return false;
  2008. }
  2009. parent = parent.parent;
  2010. }
  2011. return true;
  2012. }
  2013. }
  2014. internal virtual bool InternalCapture {
  2015. get {
  2016. return Capture;
  2017. }
  2018. set {
  2019. Capture = value;
  2020. }
  2021. }
  2022. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2023. [Browsable(false)]
  2024. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2025. public bool Capture {
  2026. get {
  2027. return this.is_captured;
  2028. }
  2029. set {
  2030. // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
  2031. if (value != is_captured) {
  2032. if (value) {
  2033. is_captured = true;
  2034. XplatUI.GrabWindow(Handle, IntPtr.Zero);
  2035. } else {
  2036. if (IsHandleCreated)
  2037. XplatUI.UngrabWindow(Handle);
  2038. is_captured = false;
  2039. }
  2040. }
  2041. }
  2042. }
  2043. [DefaultValue(true)]
  2044. [MWFCategory("Focus")]
  2045. public bool CausesValidation {
  2046. get {
  2047. return this.causes_validation;
  2048. }
  2049. set {
  2050. if (this.causes_validation != value) {
  2051. causes_validation = value;
  2052. OnCausesValidationChanged(EventArgs.Empty);
  2053. }
  2054. }
  2055. }
  2056. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2057. [Browsable(false)]
  2058. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2059. public Rectangle ClientRectangle {
  2060. get {
  2061. client_rect.Width = client_size.Width;
  2062. client_rect.Height = client_size.Height;
  2063. return client_rect;
  2064. }
  2065. }
  2066. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2067. [Browsable(false)]
  2068. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2069. public Size ClientSize {
  2070. get {
  2071. #if notneeded
  2072. if ((this is Form) && (((Form)this).form_parent_window != null)) {
  2073. return ((Form)this).form_parent_window.ClientSize;
  2074. }
  2075. #endif
  2076. return client_size;
  2077. }
  2078. set {
  2079. this.SetClientSizeCore(value.Width, value.Height);
  2080. #if NET_2_0
  2081. this.OnClientSizeChanged (EventArgs.Empty);
  2082. #endif
  2083. }
  2084. }
  2085. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2086. [Browsable(false)]
  2087. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2088. [DescriptionAttribute("ControlCompanyNameDescr")]
  2089. public String CompanyName {
  2090. get {
  2091. return "Mono Project, Novell, Inc.";
  2092. }
  2093. }
  2094. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2095. [Browsable(false)]
  2096. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2097. public bool ContainsFocus {
  2098. get {
  2099. IntPtr focused_window;
  2100. focused_window = XplatUI.GetFocus();
  2101. if (IsHandleCreated) {
  2102. if (focused_window == Handle) {
  2103. return true;
  2104. }
  2105. for (int i=0; i < child_controls.Count; i++) {
  2106. if (child_controls[i].ContainsFocus) {
  2107. return true;
  2108. }
  2109. }
  2110. }
  2111. return false;
  2112. }
  2113. }
  2114. #if NET_2_0
  2115. [Browsable (false)]
  2116. #endif
  2117. [DefaultValue(null)]
  2118. [MWFCategory("Behavior")]
  2119. public virtual ContextMenu ContextMenu {
  2120. get {
  2121. return ContextMenuInternal;
  2122. }
  2123. set {
  2124. ContextMenuInternal = value;
  2125. }
  2126. }
  2127. internal virtual ContextMenu ContextMenuInternal {
  2128. get {
  2129. return context_menu;
  2130. }
  2131. set {
  2132. if (context_menu != value) {
  2133. context_menu = value;
  2134. OnContextMenuChanged (EventArgs.Empty);
  2135. }
  2136. }
  2137. }
  2138. #if NET_2_0
  2139. [DefaultValue (null)]
  2140. [MWFCategory("Behavior")]
  2141. public virtual ContextMenuStrip ContextMenuStrip {
  2142. get { return this.context_menu_strip; }
  2143. set {
  2144. if (this.context_menu_strip != value) {
  2145. this.context_menu_strip = value;
  2146. OnContextMenuStripChanged (EventArgs.Empty);
  2147. }
  2148. }
  2149. }
  2150. #endif
  2151. [Browsable(false)]
  2152. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2153. public ControlCollection Controls {
  2154. get {
  2155. return this.child_controls;
  2156. }
  2157. }
  2158. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2159. [Browsable(false)]
  2160. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2161. public bool Created {
  2162. get {
  2163. return (!is_disposed && is_created);
  2164. }
  2165. }
  2166. [AmbientValue(null)]
  2167. [MWFCategory("Appearance")]
  2168. public virtual Cursor Cursor {
  2169. get {
  2170. #if NET_2_0
  2171. if (use_wait_cursor)
  2172. return Cursors.WaitCursor;
  2173. #endif
  2174. if (cursor != null) {
  2175. return cursor;
  2176. }
  2177. if (parent != null) {
  2178. return parent.Cursor;
  2179. }
  2180. return Cursors.Default;
  2181. }
  2182. set {
  2183. if (cursor == value) {
  2184. return;
  2185. }
  2186. cursor = value;
  2187. UpdateCursor ();
  2188. OnCursorChanged (EventArgs.Empty);
  2189. }
  2190. }
  2191. internal bool ShouldSerializeCursor ()
  2192. {
  2193. return this.Cursor != Cursors.Default;
  2194. }
  2195. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2196. [ParenthesizePropertyName(true)]
  2197. [RefreshProperties(RefreshProperties.All)]
  2198. [MWFCategory("Data")]
  2199. public ControlBindingsCollection DataBindings {
  2200. get {
  2201. if (data_bindings == null)
  2202. data_bindings = new ControlBindingsCollection (this);
  2203. return data_bindings;
  2204. }
  2205. }
  2206. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2207. [Browsable(false)]
  2208. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2209. public virtual Rectangle DisplayRectangle {
  2210. get {
  2211. return ClientRectangle;
  2212. }
  2213. }
  2214. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2215. [Browsable(false)]
  2216. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2217. public bool Disposing {
  2218. get {
  2219. return is_disposed;
  2220. }
  2221. }
  2222. [Localizable(true)]
  2223. [RefreshProperties(RefreshProperties.Repaint)]
  2224. [DefaultValue(DockStyle.None)]
  2225. [MWFCategory("Layout")]
  2226. public virtual DockStyle Dock {
  2227. get {
  2228. return dock_style;
  2229. }
  2230. set {
  2231. // If the user sets this to None, we need to still use Anchor layout
  2232. if (value != DockStyle.None)
  2233. layout_type = LayoutType.Dock;
  2234. if (dock_style == value) {
  2235. return;
  2236. }
  2237. if (!Enum.IsDefined (typeof (DockStyle), value)) {
  2238. throw new InvalidEnumArgumentException ("value", (int) value,
  2239. typeof (DockStyle));
  2240. }
  2241. dock_style = value;
  2242. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  2243. if (dock_style == DockStyle.None) {
  2244. bounds = explicit_bounds;
  2245. layout_type = LayoutType.Anchor;
  2246. }
  2247. if (parent != null)
  2248. parent.PerformLayout(this, "Dock");
  2249. else if (Controls.Count > 0)
  2250. PerformLayout ();
  2251. OnDockChanged(EventArgs.Empty);
  2252. }
  2253. }
  2254. #if NET_2_0
  2255. protected virtual bool DoubleBuffered {
  2256. get {
  2257. return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
  2258. }
  2259. set {
  2260. if (value == DoubleBuffered)
  2261. return;
  2262. if (value) {
  2263. SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
  2264. } else {
  2265. SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
  2266. }
  2267. }
  2268. }
  2269. public void DrawToBitmap (Bitmap bitmap, Rectangle targetBounds)
  2270. {
  2271. Bitmap b = new Bitmap (Width, Height);
  2272. Graphics g = Graphics.FromImage (b);
  2273. OnPaint (new PaintEventArgs (g, targetBounds));
  2274. using (Graphics g2 = Graphics.FromImage (bitmap))
  2275. g2.DrawImage (b, targetBounds);
  2276. b.Dispose ();
  2277. g.Dispose ();
  2278. }
  2279. #endif
  2280. [DispId(-514)]
  2281. [Localizable(true)]
  2282. [MWFCategory("Behavior")]
  2283. public bool Enabled {
  2284. get {
  2285. if (!is_enabled) {
  2286. return false;
  2287. }
  2288. if (parent != null) {
  2289. return parent.Enabled;
  2290. }
  2291. return true;
  2292. }
  2293. set {
  2294. if (this.is_enabled == value)
  2295. return;
  2296. bool old_value = is_enabled;
  2297. is_enabled = value;
  2298. if (!value)
  2299. UpdateCursor ();
  2300. if (old_value != value && !value && this.has_focus)
  2301. SelectNextControl(this, true, true, true, true);
  2302. OnEnabledChanged (EventArgs.Empty);
  2303. }
  2304. }
  2305. internal bool ShouldSerializeEnabled ()
  2306. {
  2307. return this.Enabled != true;
  2308. }
  2309. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2310. [Browsable(false)]
  2311. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2312. public virtual bool Focused {
  2313. get {
  2314. return this.has_focus;
  2315. }
  2316. }
  2317. [DispId(-512)]
  2318. [AmbientValue(null)]
  2319. [Localizable(true)]
  2320. [MWFCategory("Appearance")]
  2321. public virtual Font Font {
  2322. #if NET_2_0
  2323. [return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Font))]
  2324. #endif
  2325. get {
  2326. if (font != null)
  2327. return font;
  2328. if (parent != null) {
  2329. Font f = parent.Font;
  2330. if (f != null)
  2331. return f;
  2332. }
  2333. return DefaultFont;
  2334. }
  2335. [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
  2336. set {
  2337. if (font != null && font.Equals (value)) {
  2338. return;
  2339. }
  2340. font = value;
  2341. Invalidate();
  2342. OnFontChanged (EventArgs.Empty);
  2343. PerformLayout ();
  2344. }
  2345. }
  2346. internal bool ShouldSerializeFont ()
  2347. {
  2348. return !this.Font.Equals (DefaultFont);
  2349. }
  2350. [DispId(-513)]
  2351. [MWFCategory("Appearance")]
  2352. public virtual Color ForeColor {
  2353. get {
  2354. if (foreground_color.IsEmpty) {
  2355. if (parent!=null) {
  2356. return parent.ForeColor;
  2357. }
  2358. return DefaultForeColor;
  2359. }
  2360. return foreground_color;
  2361. }
  2362. set {
  2363. if (foreground_color != value) {
  2364. foreground_color=value;
  2365. Invalidate();
  2366. OnForeColorChanged(EventArgs.Empty);
  2367. }
  2368. }
  2369. }
  2370. internal bool ShouldSerializeForeColor ()
  2371. {
  2372. return this.ForeColor != DefaultForeColor;
  2373. }
  2374. [DispId(-515)]
  2375. [Browsable(false)]
  2376. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2377. public IntPtr Handle { // IWin32Window
  2378. get {
  2379. #if NET_2_0
  2380. if (verify_thread_handle) {
  2381. if (this.InvokeRequired) {
  2382. throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
  2383. }
  2384. }
  2385. #endif
  2386. if (!IsHandleCreated) {
  2387. CreateHandle();
  2388. }
  2389. return window.Handle;
  2390. }
  2391. }
  2392. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2393. [Browsable(false)]
  2394. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2395. public bool HasChildren {
  2396. get {
  2397. if (this.child_controls.Count>0) {
  2398. return true;
  2399. }
  2400. return false;
  2401. }
  2402. }
  2403. [EditorBrowsable(EditorBrowsableState.Always)]
  2404. [Browsable(false)]
  2405. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2406. public int Height {
  2407. get { return this.bounds.Height; }
  2408. set { SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height); }
  2409. }
  2410. [AmbientValue(ImeMode.Inherit)]
  2411. [Localizable(true)]
  2412. [MWFCategory("Behavior")]
  2413. public ImeMode ImeMode {
  2414. get {
  2415. if (ime_mode == ImeMode.Inherit) {
  2416. if (parent != null)
  2417. return parent.ImeMode;
  2418. else
  2419. return ImeMode.NoControl; // default value
  2420. }
  2421. return ime_mode;
  2422. }
  2423. set {
  2424. if (ime_mode != value) {
  2425. ime_mode = value;
  2426. OnImeModeChanged(EventArgs.Empty);
  2427. }
  2428. }
  2429. }
  2430. internal bool ShouldSerializeImeMode ()
  2431. {
  2432. return this.ImeMode != ImeMode.NoControl;
  2433. }
  2434. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2435. [Browsable(false)]
  2436. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2437. public bool InvokeRequired { // ISynchronizeInvoke
  2438. get {
  2439. if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
  2440. return true;
  2441. }
  2442. return false;
  2443. }
  2444. }
  2445. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2446. [Browsable(false)]
  2447. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2448. public bool IsAccessible {
  2449. get {
  2450. return is_accessible;
  2451. }
  2452. set {
  2453. is_accessible = value;
  2454. }
  2455. }
  2456. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2457. [Browsable(false)]
  2458. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2459. public bool IsDisposed {
  2460. get {
  2461. return this.is_disposed;
  2462. }
  2463. }
  2464. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2465. [Browsable(false)]
  2466. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2467. public bool IsHandleCreated {
  2468. get {
  2469. if (window == null || window.Handle == IntPtr.Zero)
  2470. return false;
  2471. Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
  2472. if (hwnd != null && hwnd.zombie)
  2473. return false;
  2474. return true;
  2475. }
  2476. }
  2477. #if NET_2_0
  2478. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2479. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2480. [Browsable(false)]
  2481. [MonoNotSupported ("RTL is not supported")]
  2482. public bool IsMirrored {
  2483. get { return false; }
  2484. }
  2485. #endif
  2486. [Browsable (false)]
  2487. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2488. #if NET_2_0
  2489. public virtual
  2490. #endif
  2491. Layout.LayoutEngine LayoutEngine {
  2492. get {
  2493. if (layout_engine == null)
  2494. layout_engine = new Layout.DefaultLayout ();
  2495. return layout_engine;
  2496. }
  2497. }
  2498. [EditorBrowsable(EditorBrowsableState.Always)]
  2499. [Browsable(false)]
  2500. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2501. public int Left {
  2502. get {
  2503. return this.bounds.X;
  2504. }
  2505. set {
  2506. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  2507. }
  2508. }
  2509. [Localizable(true)]
  2510. [MWFCategory("Layout")]
  2511. public Point Location {
  2512. get {
  2513. return new Point(bounds.X, bounds.Y);
  2514. }
  2515. set {
  2516. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  2517. }
  2518. }
  2519. internal bool ShouldSerializeLocation ()
  2520. {
  2521. return this.Location != new Point (0, 0);
  2522. }
  2523. #if NET_2_0
  2524. [Localizable (true)]
  2525. [MWFCategory("Layout")]
  2526. public Padding Margin {
  2527. get { return this.margin; }
  2528. set {
  2529. if (this.margin != value) {
  2530. this.margin = value;
  2531. OnMarginChanged (EventArgs.Empty);
  2532. }
  2533. }
  2534. }
  2535. internal bool ShouldSerializeMargin ()
  2536. {
  2537. return this.Margin != DefaultMargin;
  2538. }
  2539. #endif
  2540. [Browsable(false)]
  2541. public string Name {
  2542. get {
  2543. return name;
  2544. }
  2545. set {
  2546. name = value;
  2547. }
  2548. }
  2549. #if NET_2_0
  2550. [Localizable(true)]
  2551. [MWFCategory("Layout")]
  2552. public Padding Padding {
  2553. get {
  2554. return padding;
  2555. }
  2556. set {
  2557. if (padding != value) {
  2558. padding = value;
  2559. OnPaddingChanged (EventArgs.Empty);
  2560. // Changing padding generally requires a new size
  2561. if (this.AutoSize && this.Parent != null)
  2562. parent.PerformLayout (this, "Padding");
  2563. else
  2564. PerformLayout (this, "Padding");
  2565. }
  2566. }
  2567. }
  2568. internal bool ShouldSerializePadding ()
  2569. {
  2570. return this.Padding != DefaultPadding;
  2571. }
  2572. #endif
  2573. [Browsable(false)]
  2574. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2575. public Control Parent {
  2576. get {
  2577. return this.parent;
  2578. }
  2579. set {
  2580. if (value == this) {
  2581. throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
  2582. }
  2583. if (parent!=value) {
  2584. if (value==null) {
  2585. parent.Controls.Remove(this);
  2586. parent = null;
  2587. return;
  2588. }
  2589. value.Controls.Add(this);
  2590. }
  2591. }
  2592. }
  2593. #if NET_2_0
  2594. [Browsable (false)]
  2595. public Size PreferredSize {
  2596. get { return this.GetPreferredSize (Size.Empty); }
  2597. }
  2598. #endif
  2599. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2600. [Browsable(false)]
  2601. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2602. public string ProductName {
  2603. get {
  2604. Type t = typeof (AssemblyProductAttribute);
  2605. Assembly assembly = GetType().Module.Assembly;
  2606. object [] attrs = assembly.GetCustomAttributes (t, false);
  2607. AssemblyProductAttribute a = null;
  2608. // On MS we get a NullRefException if product attribute is not
  2609. // set.
  2610. if (attrs != null && attrs.Length > 0)
  2611. a = (AssemblyProductAttribute) attrs [0];
  2612. if (a == null) {
  2613. return GetType ().Namespace;
  2614. }
  2615. return a.Product;
  2616. }
  2617. }
  2618. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2619. [Browsable(false)]
  2620. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2621. public string ProductVersion {
  2622. get {
  2623. Type t = typeof (AssemblyVersionAttribute);
  2624. Assembly assembly = GetType().Module.Assembly;
  2625. object [] attrs = assembly.GetCustomAttributes (t, false);
  2626. if (attrs == null || attrs.Length < 1)
  2627. return "1.0.0.0";
  2628. return ((AssemblyVersionAttribute)attrs [0]).Version;
  2629. }
  2630. }
  2631. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2632. [Browsable(false)]
  2633. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2634. public bool RecreatingHandle {
  2635. get {
  2636. return is_recreating;
  2637. }
  2638. }
  2639. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2640. [Browsable(false)]
  2641. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2642. public Region Region {
  2643. get {
  2644. return clip_region;
  2645. }
  2646. set {
  2647. if (clip_region != value) {
  2648. if (IsHandleCreated)
  2649. XplatUI.SetClipRegion(Handle, value);
  2650. clip_region = value;
  2651. #if NET_2_0
  2652. OnRegionChanged (EventArgs.Empty);
  2653. #endif
  2654. }
  2655. }
  2656. }
  2657. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2658. [Browsable(false)]
  2659. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2660. public int Right {
  2661. get {
  2662. return this.bounds.X+this.bounds.Width;
  2663. }
  2664. }
  2665. [AmbientValue(RightToLeft.Inherit)]
  2666. [Localizable(true)]
  2667. [MWFCategory("Appearance")]
  2668. public virtual RightToLeft RightToLeft {
  2669. get {
  2670. if (right_to_left == RightToLeft.Inherit) {
  2671. if (parent != null)
  2672. return parent.RightToLeft;
  2673. else
  2674. return RightToLeft.No; // default value
  2675. }
  2676. return right_to_left;
  2677. }
  2678. set {
  2679. if (value != right_to_left) {
  2680. right_to_left = value;
  2681. OnRightToLeftChanged(EventArgs.Empty);
  2682. PerformLayout ();
  2683. }
  2684. }
  2685. }
  2686. internal bool ShouldSerializeRightToLeft ()
  2687. {
  2688. return this.RightToLeft != RightToLeft.No;
  2689. }
  2690. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2691. public override ISite Site {
  2692. get {
  2693. return base.Site;
  2694. }
  2695. set {
  2696. base.Site = value;
  2697. if (value != null) {
  2698. AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
  2699. if (ap != null) {
  2700. BackColor = ap.BackColor;
  2701. ForeColor = ap.ForeColor;
  2702. Cursor = ap.Cursor;
  2703. Font = ap.Font;
  2704. }
  2705. }
  2706. }
  2707. }
  2708. internal bool ShouldSerializeSite ()
  2709. {
  2710. return false;
  2711. }
  2712. [Localizable(true)]
  2713. [MWFCategory("Layout")]
  2714. public Size Size {
  2715. get {
  2716. return new Size(Width, Height);
  2717. }
  2718. set {
  2719. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  2720. }
  2721. }
  2722. internal virtual bool ShouldSerializeSize ()
  2723. {
  2724. return this.Size != DefaultSize;
  2725. }
  2726. [Localizable(true)]
  2727. [MergableProperty(false)]
  2728. [MWFCategory("Behavior")]
  2729. public int TabIndex {
  2730. get {
  2731. if (tab_index != -1) {
  2732. return tab_index;
  2733. }
  2734. return 0;
  2735. }
  2736. set {
  2737. if (tab_index != value) {
  2738. tab_index = value;
  2739. OnTabIndexChanged(EventArgs.Empty);
  2740. }
  2741. }
  2742. }
  2743. [DispId(-516)]
  2744. [DefaultValue(true)]
  2745. [MWFCategory("Behavior")]
  2746. public bool TabStop {
  2747. get {
  2748. return tab_stop;
  2749. }
  2750. set {
  2751. if (tab_stop != value) {
  2752. tab_stop = value;
  2753. OnTabStopChanged(EventArgs.Empty);
  2754. }
  2755. }
  2756. }
  2757. [Localizable(false)]
  2758. [Bindable(true)]
  2759. [TypeConverter(typeof(StringConverter))]
  2760. [DefaultValue(null)]
  2761. [MWFCategory("Data")]
  2762. public object Tag {
  2763. get {
  2764. return control_tag;
  2765. }
  2766. set {
  2767. control_tag = value;
  2768. }
  2769. }
  2770. [DispId(-517)]
  2771. [Localizable(true)]
  2772. [BindableAttribute(true)]
  2773. [MWFCategory("Appearance")]
  2774. public virtual string Text {
  2775. get {
  2776. // Our implementation ignores ControlStyles.CacheText - we always cache
  2777. return this.text;
  2778. }
  2779. set {
  2780. if (value == null) {
  2781. value = String.Empty;
  2782. }
  2783. if (text!=value) {
  2784. text=value;
  2785. UpdateWindowText ();
  2786. OnTextChanged (EventArgs.Empty);
  2787. #if NET_2_0
  2788. // Label has its own AutoSize implementation
  2789. if (AutoSize && Parent != null && (!(this is Label)))
  2790. Parent.PerformLayout (this, "Text");
  2791. #endif
  2792. }
  2793. }
  2794. }
  2795. internal virtual void UpdateWindowText ()
  2796. {
  2797. if (!IsHandleCreated) {
  2798. return;
  2799. }
  2800. XplatUI.Text (Handle, text);
  2801. }
  2802. [EditorBrowsable(EditorBrowsableState.Always)]
  2803. [Browsable(false)]
  2804. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2805. public int Top {
  2806. get {
  2807. return this.bounds.Y;
  2808. }
  2809. set {
  2810. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  2811. }
  2812. }
  2813. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2814. [Browsable(false)]
  2815. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2816. public Control TopLevelControl {
  2817. get {
  2818. Control p = this;
  2819. while (p.parent != null) {
  2820. p = p.parent;
  2821. }
  2822. return p is Form ? p : null;
  2823. }
  2824. }
  2825. #if NET_2_0
  2826. [EditorBrowsable(EditorBrowsableState.Always)]
  2827. [Browsable(true)]
  2828. [DefaultValue (false)]
  2829. [MWFCategory("Appearance")]
  2830. public bool UseWaitCursor {
  2831. get { return use_wait_cursor; }
  2832. set {
  2833. if (use_wait_cursor != value) {
  2834. use_wait_cursor = value;
  2835. UpdateCursor ();
  2836. OnCursorChanged (EventArgs.Empty);
  2837. }
  2838. }
  2839. }
  2840. #endif
  2841. [Localizable(true)]
  2842. [MWFCategory("Behavior")]
  2843. public bool Visible {
  2844. get {
  2845. if (!is_visible) {
  2846. return false;
  2847. } else if (parent != null) {
  2848. return parent.Visible;
  2849. }
  2850. return true;
  2851. }
  2852. set {
  2853. if (this.is_visible != value) {
  2854. SetVisibleCore(value);
  2855. if (parent != null)
  2856. parent.PerformLayout (this, "Visible");
  2857. }
  2858. }
  2859. }
  2860. internal bool ShouldSerializeVisible ()
  2861. {
  2862. return this.Visible != true;
  2863. }
  2864. [EditorBrowsable(EditorBrowsableState.Always)]
  2865. [Browsable(false)]
  2866. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2867. public int Width {
  2868. get {
  2869. return this.bounds.Width;
  2870. }
  2871. set {
  2872. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  2873. }
  2874. }
  2875. [EditorBrowsable(EditorBrowsableState.Never)]
  2876. [Browsable(false)]
  2877. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2878. public IWindowTarget WindowTarget {
  2879. get { return window_target; }
  2880. set { window_target = value; }
  2881. }
  2882. #endregion // Public Instance Properties
  2883. #region Protected Instance Properties
  2884. #if NET_2_0
  2885. protected virtual bool CanEnableIme {
  2886. get { return false; }
  2887. }
  2888. // Is only false in some ActiveX contexts
  2889. protected override bool CanRaiseEvents {
  2890. get { return true; }
  2891. }
  2892. #endif
  2893. protected virtual CreateParams CreateParams {
  2894. get {
  2895. CreateParams create_params = new CreateParams();
  2896. try {
  2897. create_params.Caption = Text;
  2898. }
  2899. catch {
  2900. create_params.Caption = text;
  2901. }
  2902. try {
  2903. create_params.X = Left;
  2904. }
  2905. catch {
  2906. create_params.X = this.bounds.X;
  2907. }
  2908. try {
  2909. create_params.Y = Top;
  2910. }
  2911. catch {
  2912. create_params.Y = this.bounds.Y;
  2913. }
  2914. try {
  2915. create_params.Width = Width;
  2916. }
  2917. catch {
  2918. create_params.Width = this.bounds.Width;
  2919. }
  2920. try {
  2921. create_params.Height = Height;
  2922. }
  2923. catch {
  2924. create_params.Height = this.bounds.Height;
  2925. }
  2926. create_params.ClassName = XplatUI.DefaultClassName;
  2927. create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
  2928. create_params.ExStyle = 0;
  2929. create_params.Param = 0;
  2930. if (allow_drop) {
  2931. create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
  2932. }
  2933. if ((parent!=null) && (parent.IsHandleCreated)) {
  2934. create_params.Parent = parent.Handle;
  2935. }
  2936. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  2937. if (is_visible) {
  2938. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  2939. }
  2940. if (!is_enabled) {
  2941. create_params.Style |= (int)WindowStyles.WS_DISABLED;
  2942. }
  2943. switch (border_style) {
  2944. case BorderStyle.FixedSingle:
  2945. create_params.Style |= (int) WindowStyles.WS_BORDER;
  2946. break;
  2947. case BorderStyle.Fixed3D:
  2948. create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
  2949. break;
  2950. }
  2951. create_params.control = this;
  2952. return create_params;
  2953. }
  2954. }
  2955. #if NET_2_0
  2956. protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
  2957. #endif
  2958. protected virtual ImeMode DefaultImeMode {
  2959. get {
  2960. return ImeMode.Inherit;
  2961. }
  2962. }
  2963. #if NET_2_0
  2964. protected virtual Padding DefaultMargin {
  2965. get { return new Padding (3); }
  2966. }
  2967. protected virtual Size DefaultMaximumSize { get { return new Size (); } }
  2968. protected virtual Size DefaultMinimumSize { get { return new Size (); } }
  2969. protected virtual Padding DefaultPadding { get { return new Padding (); } }
  2970. #endif
  2971. protected virtual Size DefaultSize {
  2972. get {
  2973. return new Size(0, 0);
  2974. }
  2975. }
  2976. protected int FontHeight {
  2977. get {
  2978. return Font.Height;
  2979. }
  2980. set {
  2981. ;; // Nothing to do
  2982. }
  2983. }
  2984. #if NET_2_0
  2985. [Obsolete ()]
  2986. #endif
  2987. protected bool RenderRightToLeft {
  2988. get {
  2989. return (this.right_to_left == RightToLeft.Yes);
  2990. }
  2991. }
  2992. protected bool ResizeRedraw {
  2993. get {
  2994. return GetStyle(ControlStyles.ResizeRedraw);
  2995. }
  2996. set {
  2997. SetStyle(ControlStyles.ResizeRedraw, value);
  2998. }
  2999. }
  3000. #if NET_2_0
  3001. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3002. protected virtual bool ScaleChildren {
  3003. get { return ScaleChildrenInternal; }
  3004. }
  3005. #endif
  3006. internal virtual bool ScaleChildrenInternal {
  3007. get { return true; }
  3008. }
  3009. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3010. [Browsable(false)]
  3011. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  3012. protected internal virtual bool ShowFocusCues {
  3013. get {
  3014. if (this is Form)
  3015. return show_focus_cues;
  3016. if (this.parent == null)
  3017. return false;
  3018. Form f = this.FindForm ();
  3019. if (f != null)
  3020. return f.show_focus_cues;
  3021. return false;
  3022. }
  3023. }
  3024. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3025. [Browsable(false)]
  3026. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  3027. #if NET_2_0
  3028. internal virtual
  3029. #endif
  3030. protected bool ShowKeyboardCues {
  3031. get {
  3032. return ShowKeyboardCuesInternal;
  3033. }
  3034. }
  3035. internal bool ShowKeyboardCuesInternal {
  3036. get {
  3037. if (SystemInformation.MenuAccessKeysUnderlined || DesignMode)
  3038. return true;
  3039. return show_keyboard_cues;
  3040. }
  3041. }
  3042. #endregion // Protected Instance Properties
  3043. #region Public Static Methods
  3044. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3045. public static Control FromChildHandle(IntPtr handle) {
  3046. return Control.ControlNativeWindow.ControlFromChildHandle (handle);
  3047. }
  3048. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3049. public static Control FromHandle(IntPtr handle) {
  3050. return Control.ControlNativeWindow.ControlFromHandle(handle);
  3051. }
  3052. #if NET_2_0
  3053. [MonoTODO ("Only implemented for Win32, others always return false")]
  3054. public static bool IsKeyLocked (Keys keyVal)
  3055. {
  3056. switch (keyVal) {
  3057. case Keys.CapsLock:
  3058. case Keys.NumLock:
  3059. case Keys.Scroll:
  3060. return XplatUI.IsKeyLocked ((VirtualKeys)keyVal);
  3061. default:
  3062. throw new NotSupportedException ("keyVal must be CapsLock, NumLock, or ScrollLock");
  3063. }
  3064. }
  3065. #endif
  3066. public static bool IsMnemonic(char charCode, string text) {
  3067. int amp;
  3068. amp = text.IndexOf('&');
  3069. if (amp != -1) {
  3070. if (amp + 1 < text.Length) {
  3071. if (text[amp + 1] != '&') {
  3072. if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
  3073. return true;
  3074. }
  3075. }
  3076. }
  3077. }
  3078. return false;
  3079. }
  3080. #endregion
  3081. #region Protected Static Methods
  3082. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3083. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  3084. Control c;
  3085. c = Control.FromHandle(hWnd);
  3086. if (c != null) {
  3087. c.WndProc(ref m);
  3088. return true;
  3089. }
  3090. return false;
  3091. }
  3092. #endregion
  3093. #region Public Instance Methods
  3094. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3095. public IAsyncResult BeginInvoke(Delegate method) {
  3096. object [] prms = null;
  3097. if (method is EventHandler)
  3098. prms = new object [] { this, EventArgs.Empty };
  3099. return BeginInvokeInternal(method, prms);
  3100. }
  3101. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3102. #if NET_2_0
  3103. public IAsyncResult BeginInvoke (Delegate method, params object[] args)
  3104. #else
  3105. public IAsyncResult BeginInvoke (Delegate method, object[] args)
  3106. #endif
  3107. {
  3108. return BeginInvokeInternal (method, args);
  3109. }
  3110. public void BringToFront() {
  3111. if (parent != null) {
  3112. parent.child_controls.SetChildIndex(this, 0);
  3113. }
  3114. else if (IsHandleCreated) {
  3115. XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
  3116. }
  3117. }
  3118. public bool Contains(Control ctl) {
  3119. while (ctl != null) {
  3120. ctl = ctl.parent;
  3121. if (ctl == this) {
  3122. return true;
  3123. }
  3124. }
  3125. return false;
  3126. }
  3127. public void CreateControl () {
  3128. if (is_disposed) {
  3129. throw new ObjectDisposedException(GetType().FullName);
  3130. }
  3131. if (is_created) {
  3132. return;
  3133. }
  3134. if (is_disposing) {
  3135. return;
  3136. }
  3137. if (!is_visible) {
  3138. return;
  3139. }
  3140. if (!IsHandleCreated) {
  3141. CreateHandle();
  3142. }
  3143. if (!is_created) {
  3144. is_created = true;
  3145. // Create all of our children (implicit ones as well) when we are created.
  3146. // The child should fire it's OnLoad before the parents, however
  3147. // if the child checks Parent.Created in it's OnCreateControl, the
  3148. // parent is already created.
  3149. foreach (Control c in Controls.GetAllControls ())
  3150. if (!c.Created && !c.IsDisposed)
  3151. c.CreateControl ();
  3152. #if ONLY_1_1
  3153. if (binding_context == null && parent != null) {
  3154. OnBindingContextChanged(EventArgs.Empty);
  3155. }
  3156. #endif
  3157. OnCreateControl();
  3158. }
  3159. }
  3160. public Graphics CreateGraphics() {
  3161. if (!IsHandleCreated) {
  3162. this.CreateHandle();
  3163. }
  3164. return Graphics.FromHwnd(this.window.Handle);
  3165. }
  3166. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  3167. if (IsHandleCreated)
  3168. return XplatUI.StartDrag(Handle, data, allowedEffects);
  3169. else
  3170. return DragDropEffects.None;
  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. OnSizeChanged(EventArgs.Empty);
  4285. #if NET_2_0
  4286. OnClientSizeChanged (EventArgs.Empty);
  4287. #endif
  4288. }
  4289. }
  4290. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4291. protected void UpdateStyles() {
  4292. if (!IsHandleCreated) {
  4293. return;
  4294. }
  4295. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  4296. OnStyleChanged(EventArgs.Empty);
  4297. }
  4298. private void UpdateZOrderOfChild(Control child) {
  4299. if (IsHandleCreated && child.IsHandleCreated && (child.parent == this) && Hwnd.ObjectFromHandle(child.Handle).Mapped) {
  4300. // Need to take into account all controls
  4301. Control [] all_controls = child_controls.GetAllControls ();
  4302. int index = Array.IndexOf (all_controls, child);
  4303. for (; index > 0; index--) {
  4304. if (!all_controls [index - 1].IsHandleCreated || !all_controls [index - 1].VisibleInternal || !Hwnd.ObjectFromHandle(all_controls [index - 1].Handle).Mapped)
  4305. continue;
  4306. break;
  4307. }
  4308. if (index > 0) {
  4309. XplatUI.SetZOrder(child.Handle, all_controls [index - 1].Handle, false, false);
  4310. } else {
  4311. IntPtr after = AfterTopMostControl ();
  4312. if (after != IntPtr.Zero && after != child.Handle)
  4313. XplatUI.SetZOrder (child.Handle, after, false, false);
  4314. else
  4315. XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
  4316. }
  4317. }
  4318. }
  4319. // Override this if there is a control that shall always remain on
  4320. // top of other controls (such as scrollbars). If there are several
  4321. // of these controls, the bottom-most should be returned.
  4322. internal virtual IntPtr AfterTopMostControl () {
  4323. return IntPtr.Zero;
  4324. }
  4325. // internal because we need to call it from ScrollableControl.OnVisibleChanged
  4326. internal void UpdateChildrenZOrder() {
  4327. Control [] controls;
  4328. if (!IsHandleCreated) {
  4329. return;
  4330. }
  4331. // XXX This code is severely broken. It leaks
  4332. // the "zero_sized" abstraction out of the X11
  4333. // backend and into Control.cs. It'll work on
  4334. // windows simply by virtue of windows never
  4335. // setting that field to true.
  4336. //
  4337. // basically what we need to guard against is
  4338. // calling XplatUI.SetZOrder on an hwnd that
  4339. // corresponds to an unmapped X window.
  4340. controls = child_controls.GetAllControls ();
  4341. ArrayList children_to_order = new ArrayList ();
  4342. for (int i = 0; i < controls.Length; i ++) {
  4343. if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
  4344. continue;
  4345. Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
  4346. if (hwnd.zero_sized)
  4347. continue;
  4348. children_to_order.Add (controls[i]);
  4349. }
  4350. for (int i = 1; i < children_to_order.Count; i ++) {
  4351. Control upper = (Control)children_to_order[i-1];
  4352. Control lower = (Control)children_to_order[i];
  4353. XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
  4354. }
  4355. }
  4356. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4357. protected void UpdateZOrder() {
  4358. if (parent != null) {
  4359. parent.UpdateZOrderOfChild(this);
  4360. }
  4361. }
  4362. protected virtual void WndProc(ref Message m) {
  4363. #if DebugMessages
  4364. Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
  4365. #endif
  4366. if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
  4367. OnNotifyMessage(m);
  4368. }
  4369. switch((Msg)m.Msg) {
  4370. case Msg.WM_DESTROY: {
  4371. WmDestroy(ref m);
  4372. return;
  4373. }
  4374. case Msg.WM_WINDOWPOSCHANGED: {
  4375. WmWindowPosChanged(ref m);
  4376. return;
  4377. }
  4378. // Nice description of what should happen when handling WM_PAINT
  4379. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4380. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4381. case Msg.WM_PAINT: {
  4382. WmPaint (ref m);
  4383. return;
  4384. }
  4385. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4386. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4387. // here but it just makes things more complicated...
  4388. case Msg.WM_ERASEBKGND: {
  4389. WmEraseBackground (ref m);
  4390. return;
  4391. }
  4392. case Msg.WM_LBUTTONUP: {
  4393. WmLButtonUp (ref m);
  4394. return;
  4395. }
  4396. case Msg.WM_LBUTTONDOWN: {
  4397. WmLButtonDown (ref m);
  4398. return;
  4399. }
  4400. case Msg.WM_LBUTTONDBLCLK: {
  4401. WmLButtonDblClick (ref m);
  4402. return;
  4403. }
  4404. case Msg.WM_MBUTTONUP: {
  4405. WmMButtonUp (ref m);
  4406. return;
  4407. }
  4408. case Msg.WM_MBUTTONDOWN: {
  4409. WmMButtonDown (ref m);
  4410. return;
  4411. }
  4412. case Msg.WM_MBUTTONDBLCLK: {
  4413. WmMButtonDblClick (ref m);
  4414. return;
  4415. }
  4416. case Msg.WM_RBUTTONUP: {
  4417. WmRButtonUp (ref m);
  4418. return;
  4419. }
  4420. case Msg.WM_RBUTTONDOWN: {
  4421. WmRButtonDown (ref m);
  4422. return;
  4423. }
  4424. case Msg.WM_RBUTTONDBLCLK: {
  4425. WmRButtonDblClick (ref m);
  4426. return;
  4427. }
  4428. case Msg.WM_CONTEXTMENU: {
  4429. WmContextMenu (ref m);
  4430. return;
  4431. }
  4432. case Msg.WM_MOUSEWHEEL: {
  4433. WmMouseWheel (ref m);
  4434. return;
  4435. }
  4436. case Msg.WM_MOUSEMOVE: {
  4437. WmMouseMove (ref m);
  4438. return;
  4439. }
  4440. case Msg.WM_SHOWWINDOW: {
  4441. WmShowWindow (ref m);
  4442. return;
  4443. }
  4444. case Msg.WM_CREATE: {
  4445. WmCreate (ref m);
  4446. return;
  4447. }
  4448. case Msg.WM_MOUSE_ENTER: {
  4449. WmMouseEnter (ref m);
  4450. return;
  4451. }
  4452. case Msg.WM_MOUSELEAVE: {
  4453. WmMouseLeave (ref m);
  4454. return;
  4455. }
  4456. case Msg.WM_MOUSEHOVER: {
  4457. WmMouseHover (ref m);
  4458. return;
  4459. }
  4460. case Msg.WM_SYSKEYUP: {
  4461. WmSysKeyUp (ref m);
  4462. return;
  4463. }
  4464. case Msg.WM_SYSKEYDOWN:
  4465. case Msg.WM_KEYDOWN:
  4466. case Msg.WM_KEYUP:
  4467. case Msg.WM_SYSCHAR:
  4468. case Msg.WM_CHAR: {
  4469. WmKeys (ref m);
  4470. return;
  4471. }
  4472. case Msg.WM_HELP: {
  4473. WmHelp (ref m);
  4474. return;
  4475. }
  4476. case Msg.WM_KILLFOCUS: {
  4477. WmKillFocus (ref m);
  4478. return;
  4479. }
  4480. case Msg.WM_SETFOCUS: {
  4481. WmSetFocus (ref m);
  4482. return;
  4483. }
  4484. case Msg.WM_SYSCOLORCHANGE: {
  4485. WmSysColorChange (ref m);
  4486. return;
  4487. }
  4488. case Msg.WM_SETCURSOR: {
  4489. WmSetCursor (ref m);
  4490. return;
  4491. }
  4492. case Msg.WM_CAPTURECHANGED: {
  4493. WmCaptureChanged (ref m);
  4494. return;
  4495. }
  4496. case Msg.WM_CHANGEUISTATE: {
  4497. WmChangeUIState (ref m);
  4498. return;
  4499. }
  4500. case Msg.WM_UPDATEUISTATE: {
  4501. WmUpdateUIState (ref m);
  4502. return;
  4503. }
  4504. default:
  4505. DefWndProc(ref m);
  4506. return;
  4507. }
  4508. }
  4509. #endregion // Public Instance Methods
  4510. #region WM methods
  4511. private void WmDestroy (ref Message m) {
  4512. OnHandleDestroyed(EventArgs.Empty);
  4513. #if DebugRecreate
  4514. IntPtr handle = window.Handle;
  4515. #endif
  4516. window.InvalidateHandle();
  4517. is_created = false;
  4518. if (is_recreating) {
  4519. #if DebugRecreate
  4520. Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
  4521. #endif
  4522. CreateHandle();
  4523. #if DebugRecreate
  4524. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  4525. #endif
  4526. is_recreating = false;
  4527. }
  4528. }
  4529. private void WmWindowPosChanged (ref Message m) {
  4530. if (Visible) {
  4531. Rectangle save_bounds = explicit_bounds;
  4532. UpdateBounds();
  4533. explicit_bounds = save_bounds;
  4534. if (GetStyle(ControlStyles.ResizeRedraw)) {
  4535. Invalidate();
  4536. }
  4537. }
  4538. }
  4539. // Nice description of what should happen when handling WM_PAINT
  4540. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4541. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4542. private void WmPaint (ref Message m) {
  4543. PaintEventArgs paint_event;
  4544. IntPtr handle = Handle;
  4545. paint_event = XplatUI.PaintEventStart (ref m, handle, true);
  4546. if (paint_event == null)
  4547. return;
  4548. DoubleBuffer current_buffer = null;
  4549. if (UseDoubleBuffering) {
  4550. current_buffer = GetBackBuffer ();
  4551. // This optimization doesn't work when the area is invalidated
  4552. // during a paint operation because finishing the paint operation
  4553. // clears the invalidated region and then this thing keeps the new
  4554. // invalidate from working. To re-enable this, we would need a
  4555. // mechanism to allow for nested invalidates (see bug #328681)
  4556. //if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
  4557. // // Just blit the previous image
  4558. // current_buffer.Blit (paint_event);
  4559. // XplatUI.PaintEventEnd (ref m, handle, true);
  4560. // return;
  4561. //}
  4562. current_buffer.Start (paint_event);
  4563. }
  4564. if (!GetStyle(ControlStyles.Opaque)) {
  4565. OnPaintBackground (paint_event);
  4566. }
  4567. // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
  4568. OnPaintBackgroundInternal (paint_event);
  4569. OnPaintInternal(paint_event);
  4570. if (!paint_event.Handled) {
  4571. OnPaint (paint_event);
  4572. }
  4573. if (current_buffer != null) {
  4574. current_buffer.End (paint_event);
  4575. }
  4576. XplatUI.PaintEventEnd (ref m, handle, true);
  4577. }
  4578. private void WmEraseBackground (ref Message m) {
  4579. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4580. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4581. // here but it just makes things more complicated...
  4582. m.Result = (IntPtr)1;
  4583. }
  4584. private void WmLButtonUp (ref Message m)
  4585. {
  4586. // Menu handle.
  4587. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4588. ProcessActiveTracker (ref m);
  4589. return;
  4590. }
  4591. MouseEventArgs me;
  4592. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  4593. mouse_clicks,
  4594. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4595. 0);
  4596. HandleClick(mouse_clicks, me);
  4597. OnMouseUp (me);
  4598. if (InternalCapture) {
  4599. InternalCapture = false;
  4600. }
  4601. if (mouse_clicks > 1) {
  4602. mouse_clicks = 1;
  4603. }
  4604. }
  4605. private void WmLButtonDown (ref Message m)
  4606. {
  4607. // Menu handle.
  4608. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4609. ProcessActiveTracker (ref m);
  4610. return;
  4611. }
  4612. ValidationFailed = false;
  4613. if (CanSelect) {
  4614. Select (true, true);
  4615. }
  4616. if (!ValidationFailed) {
  4617. InternalCapture = true;
  4618. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4619. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4620. 0));
  4621. }
  4622. }
  4623. private void WmLButtonDblClick (ref Message m) {
  4624. InternalCapture = true;
  4625. mouse_clicks++;
  4626. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4627. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4628. 0));
  4629. }
  4630. private void WmMButtonUp (ref Message m) {
  4631. MouseEventArgs me;
  4632. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
  4633. mouse_clicks,
  4634. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4635. 0);
  4636. HandleClick(mouse_clicks, me);
  4637. OnMouseUp (me);
  4638. if (InternalCapture) {
  4639. InternalCapture = false;
  4640. }
  4641. if (mouse_clicks > 1) {
  4642. mouse_clicks = 1;
  4643. }
  4644. }
  4645. private void WmMButtonDown (ref Message m) {
  4646. InternalCapture = true;
  4647. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4648. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4649. 0));
  4650. }
  4651. private void WmMButtonDblClick (ref Message m) {
  4652. InternalCapture = true;
  4653. mouse_clicks++;
  4654. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4655. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4656. 0));
  4657. }
  4658. private void WmRButtonUp (ref Message m)
  4659. {
  4660. // Menu handle.
  4661. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4662. ProcessActiveTracker (ref m);
  4663. return;
  4664. }
  4665. MouseEventArgs me;
  4666. Point pt;
  4667. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4668. pt = PointToScreen(pt);
  4669. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
  4670. mouse_clicks,
  4671. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4672. 0);
  4673. HandleClick(mouse_clicks, me);
  4674. XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
  4675. OnMouseUp (me);
  4676. if (InternalCapture) {
  4677. InternalCapture = false;
  4678. }
  4679. if (mouse_clicks > 1) {
  4680. mouse_clicks = 1;
  4681. }
  4682. }
  4683. private void WmRButtonDown (ref Message m)
  4684. {
  4685. // Menu handle.
  4686. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4687. ProcessActiveTracker (ref m);
  4688. return;
  4689. }
  4690. InternalCapture = true;
  4691. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4692. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4693. 0));
  4694. }
  4695. private void WmRButtonDblClick (ref Message m) {
  4696. InternalCapture = true;
  4697. mouse_clicks++;
  4698. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4699. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4700. 0));
  4701. }
  4702. private void WmContextMenu (ref Message m) {
  4703. if (context_menu != null) {
  4704. Point pt;
  4705. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4706. if (pt.X == -1 || pt.Y == -1) {
  4707. pt.X = (this.Width / 2) + this.Left;
  4708. pt.Y = (this.Height / 2) + this.Top;
  4709. pt = this.PointToScreen (pt);
  4710. }
  4711. context_menu.Show (this, PointToClient (pt));
  4712. return;
  4713. }
  4714. #if NET_2_0
  4715. // If there isn't a regular context menu, show the Strip version
  4716. if (context_menu == null && context_menu_strip != null) {
  4717. Point pt;
  4718. pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
  4719. if (pt.X == -1 || pt.Y == -1) {
  4720. pt.X = (this.Width / 2) + this.Left;
  4721. pt.Y = (this.Height /2) + this.Top;
  4722. pt = this.PointToScreen (pt);
  4723. }
  4724. context_menu_strip.Show (this, PointToClient (pt));
  4725. return;
  4726. }
  4727. #endif
  4728. DefWndProc(ref m);
  4729. }
  4730. private void WmCreate (ref Message m) {
  4731. OnHandleCreated(EventArgs.Empty);
  4732. }
  4733. private void WmMouseWheel (ref Message m) {
  4734. DefWndProc(ref m);
  4735. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((long) m.WParam),
  4736. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4737. HighOrder((long)m.WParam)));
  4738. }
  4739. private void WmMouseMove (ref Message m) {
  4740. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4741. MouseEventArgs args = new MouseEventArgs (
  4742. FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
  4743. mouse_clicks,
  4744. Control.MousePosition.X,
  4745. Control.MousePosition.Y,
  4746. 0);
  4747. active_tracker.OnMotion (args);
  4748. return;
  4749. }
  4750. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4751. mouse_clicks,
  4752. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4753. 0));
  4754. }
  4755. private void WmMouseEnter (ref Message m) {
  4756. if (is_entered) {
  4757. return;
  4758. }
  4759. is_entered = true;
  4760. OnMouseEnter(EventArgs.Empty);
  4761. }
  4762. private void WmMouseLeave (ref Message m) {
  4763. is_entered=false;
  4764. OnMouseLeave(EventArgs.Empty);
  4765. }
  4766. private void WmMouseHover (ref Message m) {
  4767. OnMouseHover(EventArgs.Empty);
  4768. }
  4769. private void WmShowWindow (ref Message m) {
  4770. if (IsDisposed)
  4771. return;
  4772. Form frm = this as Form;
  4773. if (m.WParam.ToInt32() != 0) {
  4774. if (m.LParam.ToInt32 () == 0) {
  4775. CreateControl ();
  4776. // Make sure all our children are properly parented to us
  4777. Control [] controls = child_controls.GetAllControls ();
  4778. bool parented = false;
  4779. for (int i=0; i<controls.Length; i++) {
  4780. if (controls [i].is_visible && controls[i].IsHandleCreated)
  4781. if (XplatUI.GetParent (controls[i].Handle) != window.Handle) {
  4782. XplatUI.SetParent(controls[i].Handle, window.Handle);
  4783. parented = true;
  4784. }
  4785. }
  4786. //if (parented)
  4787. UpdateChildrenZOrder ();
  4788. }
  4789. } else {
  4790. if (parent != null && Focused) {
  4791. Control container;
  4792. // Need to start at parent, GetContainerControl might return ourselves if we're a container
  4793. container = (Control)parent.GetContainerControl();
  4794. if (container != null && (frm == null || !frm.IsMdiChild)) {
  4795. container.SelectNextControl(this, true, true, true, true);
  4796. }
  4797. }
  4798. }
  4799. if (frm != null)
  4800. frm.waiting_showwindow = false;
  4801. // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
  4802. if (frm != null) {
  4803. if (!IsRecreating && (frm.IsMdiChild || frm.WindowState == FormWindowState.Normal)) /* XXX make sure this works for mdi forms */
  4804. OnVisibleChanged(EventArgs.Empty);
  4805. } else if (is_toplevel)
  4806. OnVisibleChanged(EventArgs.Empty);
  4807. }
  4808. private void WmSysKeyUp (ref Message m) {
  4809. if (ProcessKeyMessage(ref m)) {
  4810. m.Result = IntPtr.Zero;
  4811. return;
  4812. }
  4813. if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
  4814. Form form;
  4815. form = FindForm();
  4816. if (form != null && form.ActiveMenu != null) {
  4817. form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
  4818. }
  4819. #if NET_2_0
  4820. else
  4821. if (ToolStripManager.ProcessMenuKey (ref m))
  4822. return;
  4823. #endif
  4824. }
  4825. DefWndProc (ref m);
  4826. }
  4827. private void WmKeys (ref Message m)
  4828. {
  4829. if (ProcessKeyMessage(ref m)) {
  4830. m.Result = IntPtr.Zero;
  4831. return;
  4832. }
  4833. DefWndProc (ref m);
  4834. }
  4835. private void WmHelp (ref Message m) {
  4836. Point mouse_pos;
  4837. if (m.LParam != IntPtr.Zero) {
  4838. HELPINFO hi;
  4839. hi = new HELPINFO();
  4840. hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
  4841. mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
  4842. } else {
  4843. mouse_pos = Control.MousePosition;
  4844. }
  4845. OnHelpRequested(new HelpEventArgs(mouse_pos));
  4846. m.Result = (IntPtr)1;
  4847. }
  4848. private void WmKillFocus (ref Message m) {
  4849. this.has_focus = false;
  4850. OnLostFocus (EventArgs.Empty);
  4851. }
  4852. private void WmSetFocus (ref Message m) {
  4853. if (!has_focus) {
  4854. this.has_focus = true;
  4855. OnGotFocus (EventArgs.Empty);
  4856. }
  4857. }
  4858. private void WmSysColorChange (ref Message m) {
  4859. ThemeEngine.Current.ResetDefaults();
  4860. OnSystemColorsChanged(EventArgs.Empty);
  4861. }
  4862. private void WmSetCursor (ref Message m) {
  4863. if ((cursor == null && use_wait_cursor == false) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
  4864. DefWndProc(ref m);
  4865. return;
  4866. }
  4867. XplatUI.SetCursor(window.Handle, Cursor.handle);
  4868. m.Result = (IntPtr)1;
  4869. }
  4870. private void WmCaptureChanged (ref Message m) {
  4871. is_captured = false;
  4872. OnMouseCaptureChanged (EventArgs.Empty);
  4873. m.Result = (IntPtr) 0;
  4874. }
  4875. private void WmChangeUIState (ref Message m) {
  4876. foreach (Control control in Controls) {
  4877. XplatUI.SendMessage (control.Handle, Msg.WM_UPDATEUISTATE, m.WParam, m.LParam);
  4878. }
  4879. }
  4880. private void WmUpdateUIState (ref Message m) {
  4881. int action = LowOrder (m.WParam.ToInt32 ());
  4882. int element = HighOrder (m.WParam.ToInt32 ());
  4883. if (action == (int) MsgUIState.UIS_INITIALIZE)
  4884. return;
  4885. UICues cues = UICues.None;
  4886. if ((element & (int) MsgUIState.UISF_HIDEACCEL) != 0) {
  4887. if ((action == (int) MsgUIState.UIS_CLEAR) != show_keyboard_cues) {
  4888. cues |= UICues.ChangeKeyboard;
  4889. show_keyboard_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4890. }
  4891. }
  4892. if ((element & (int) MsgUIState.UISF_HIDEFOCUS) != 0) {
  4893. if ((action == (int) MsgUIState.UIS_CLEAR) != show_focus_cues) {
  4894. cues |= UICues.ChangeFocus;
  4895. show_focus_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4896. }
  4897. }
  4898. if ((cues & UICues.Changed) != UICues.None) {
  4899. OnChangeUICues (new UICuesEventArgs (cues));
  4900. Invalidate ();
  4901. }
  4902. }
  4903. #endregion
  4904. #region OnXXX methods
  4905. #if NET_2_0
  4906. protected virtual void OnAutoSizeChanged (EventArgs e)
  4907. {
  4908. EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
  4909. if (eh != null)
  4910. eh (this, e);
  4911. }
  4912. #endif
  4913. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4914. protected virtual void OnBackColorChanged(EventArgs e) {
  4915. EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
  4916. if (eh != null)
  4917. eh (this, e);
  4918. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  4919. }
  4920. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4921. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  4922. EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
  4923. if (eh != null)
  4924. eh (this, e);
  4925. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  4926. }
  4927. #if NET_2_0
  4928. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4929. protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
  4930. {
  4931. EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
  4932. if (eh != null)
  4933. eh (this, e);
  4934. }
  4935. #endif
  4936. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4937. protected virtual void OnBindingContextChanged(EventArgs e) {
  4938. CheckDataBindings ();
  4939. EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
  4940. if (eh != null)
  4941. eh (this, e);
  4942. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  4943. }
  4944. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4945. protected virtual void OnCausesValidationChanged(EventArgs e) {
  4946. EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
  4947. if (eh != null)
  4948. eh (this, e);
  4949. }
  4950. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4951. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  4952. UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
  4953. if (eh != null)
  4954. eh (this, e);
  4955. }
  4956. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4957. protected virtual void OnClick(EventArgs e) {
  4958. EventHandler eh = (EventHandler)(Events [ClickEvent]);
  4959. if (eh != null)
  4960. eh (this, e);
  4961. }
  4962. #if NET_2_0
  4963. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4964. protected virtual void OnClientSizeChanged (EventArgs e)
  4965. {
  4966. EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
  4967. if (eh != null)
  4968. eh (this, e);
  4969. }
  4970. #endif
  4971. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4972. protected virtual void OnContextMenuChanged(EventArgs e) {
  4973. EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
  4974. if (eh != null)
  4975. eh (this, e);
  4976. }
  4977. #if NET_2_0
  4978. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4979. protected virtual void OnContextMenuStripChanged (EventArgs e) {
  4980. EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
  4981. if (eh != null)
  4982. eh (this, e);
  4983. }
  4984. #endif
  4985. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4986. protected virtual void OnControlAdded(ControlEventArgs e) {
  4987. ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
  4988. if (eh != null)
  4989. eh (this, e);
  4990. }
  4991. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4992. protected virtual void OnControlRemoved(ControlEventArgs e) {
  4993. ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
  4994. if (eh != null)
  4995. eh (this, e);
  4996. }
  4997. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4998. protected virtual void OnCreateControl() {
  4999. // Override me!
  5000. }
  5001. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5002. protected virtual void OnCursorChanged(EventArgs e) {
  5003. EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
  5004. if (eh != null)
  5005. eh (this, e);
  5006. #if NET_2_0
  5007. for (int i = 0; i < child_controls.Count; i++) child_controls[i].OnParentCursorChanged (e);
  5008. #endif
  5009. }
  5010. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5011. protected virtual void OnDockChanged(EventArgs e) {
  5012. EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
  5013. if (eh != null)
  5014. eh (this, e);
  5015. }
  5016. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5017. protected virtual void OnDoubleClick(EventArgs e) {
  5018. EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
  5019. if (eh != null)
  5020. eh (this, e);
  5021. }
  5022. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5023. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  5024. DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
  5025. if (eh != null)
  5026. eh (this, drgevent);
  5027. }
  5028. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5029. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  5030. DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
  5031. if (eh != null)
  5032. eh (this, drgevent);
  5033. }
  5034. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5035. protected virtual void OnDragLeave(EventArgs e) {
  5036. EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
  5037. if (eh != null)
  5038. eh (this, e);
  5039. }
  5040. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5041. protected virtual void OnDragOver(DragEventArgs drgevent) {
  5042. DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
  5043. if (eh != null)
  5044. eh (this, drgevent);
  5045. }
  5046. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5047. protected virtual void OnEnabledChanged(EventArgs e) {
  5048. if (IsHandleCreated) {
  5049. if (this is Form) {
  5050. if (((Form)this).context == null) {
  5051. XplatUI.EnableWindow(window.Handle, Enabled);
  5052. }
  5053. } else {
  5054. XplatUI.EnableWindow(window.Handle, Enabled);
  5055. }
  5056. Refresh();
  5057. }
  5058. EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
  5059. if (eh != null)
  5060. eh (this, e);
  5061. for (int i=0; i<child_controls.Count; i++) {
  5062. child_controls[i].OnParentEnabledChanged(e);
  5063. }
  5064. }
  5065. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5066. protected virtual void OnEnter(EventArgs e) {
  5067. EventHandler eh = (EventHandler)(Events [EnterEvent]);
  5068. if (eh != null)
  5069. eh (this, e);
  5070. }
  5071. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5072. protected virtual void OnFontChanged(EventArgs e) {
  5073. EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
  5074. if (eh != null)
  5075. eh (this, e);
  5076. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
  5077. }
  5078. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5079. protected virtual void OnForeColorChanged(EventArgs e) {
  5080. EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
  5081. if (eh != null)
  5082. eh (this, e);
  5083. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  5084. }
  5085. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5086. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  5087. GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
  5088. if (eh != null)
  5089. eh (this, gfbevent);
  5090. }
  5091. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5092. protected virtual void OnGotFocus(EventArgs e) {
  5093. EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
  5094. if (eh != null)
  5095. eh (this, e);
  5096. }
  5097. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5098. protected virtual void OnHandleCreated(EventArgs e) {
  5099. EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
  5100. if (eh != null)
  5101. eh (this, e);
  5102. }
  5103. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5104. protected virtual void OnHandleDestroyed(EventArgs e) {
  5105. EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
  5106. if (eh != null)
  5107. eh (this, e);
  5108. }
  5109. internal void RaiseHelpRequested (HelpEventArgs hevent) {
  5110. OnHelpRequested (hevent);
  5111. }
  5112. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5113. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  5114. HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
  5115. if (eh != null)
  5116. eh (this, hevent);
  5117. }
  5118. protected virtual void OnImeModeChanged(EventArgs e) {
  5119. EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
  5120. if (eh != null)
  5121. eh (this, e);
  5122. }
  5123. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5124. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  5125. if (UseDoubleBuffering) {
  5126. // should this block be here? seems like it
  5127. // would be more at home in
  5128. // NotifyInvalidated..
  5129. if (e.InvalidRect == ClientRectangle) {
  5130. InvalidateBackBuffer ();
  5131. } else if (backbuffer != null){
  5132. // we need this Inflate call here so
  5133. // that the border of the rectangle is
  5134. // considered Visible (the
  5135. // invalid_region.IsVisible call) in
  5136. // the WM_PAINT handling below.
  5137. Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
  5138. backbuffer.InvalidRegion.Union (r);
  5139. }
  5140. }
  5141. InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
  5142. if (eh != null)
  5143. eh (this, e);
  5144. }
  5145. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5146. protected virtual void OnKeyDown(KeyEventArgs e) {
  5147. KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
  5148. if (eh != null)
  5149. eh (this, e);
  5150. }
  5151. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5152. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  5153. KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
  5154. if (eh != null)
  5155. eh (this, e);
  5156. }
  5157. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5158. protected virtual void OnKeyUp(KeyEventArgs e) {
  5159. KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
  5160. if (eh != null)
  5161. eh (this, e);
  5162. }
  5163. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5164. protected virtual void OnLayout(LayoutEventArgs levent) {
  5165. LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
  5166. if (eh != null)
  5167. eh (this, levent);
  5168. #if NET_2_0
  5169. Size s = Size;
  5170. // If our layout changed our PreferredSize, our parent
  5171. // needs to re-lay us out. However, it's not always possible to
  5172. // be our preferred size, so only try once so we don't loop forever.
  5173. if (Parent != null && AutoSize && !nested_layout && PreferredSize != s) {
  5174. nested_layout = true;
  5175. Parent.PerformLayout ();
  5176. nested_layout = false;
  5177. }
  5178. #endif
  5179. LayoutEngine.Layout (this, levent);
  5180. }
  5181. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5182. protected virtual void OnLeave(EventArgs e) {
  5183. EventHandler eh = (EventHandler)(Events [LeaveEvent]);
  5184. if (eh != null)
  5185. eh (this, e);
  5186. }
  5187. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5188. protected virtual void OnLocationChanged(EventArgs e) {
  5189. OnMove(e);
  5190. EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
  5191. if (eh != null)
  5192. eh (this, e);
  5193. }
  5194. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5195. protected virtual void OnLostFocus(EventArgs e) {
  5196. EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
  5197. if (eh != null)
  5198. eh (this, e);
  5199. }
  5200. #if NET_2_0
  5201. protected virtual void OnMarginChanged (EventArgs e)
  5202. {
  5203. EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
  5204. if (eh != null)
  5205. eh (this, e);
  5206. }
  5207. #endif
  5208. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5209. #if NET_2_0
  5210. protected virtual void OnMouseCaptureChanged (EventArgs e)
  5211. #else
  5212. internal virtual void OnMouseCaptureChanged (EventArgs e)
  5213. #endif
  5214. {
  5215. EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
  5216. if (eh != null)
  5217. eh (this, e);
  5218. }
  5219. #if NET_2_0
  5220. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5221. protected virtual void OnMouseClick (MouseEventArgs e)
  5222. {
  5223. MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
  5224. if (eh != null)
  5225. eh (this, e);
  5226. }
  5227. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5228. protected virtual void OnMouseDoubleClick (MouseEventArgs e)
  5229. {
  5230. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
  5231. if (eh != null)
  5232. eh (this, e);
  5233. }
  5234. #endif
  5235. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5236. protected virtual void OnMouseDown(MouseEventArgs e) {
  5237. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
  5238. if (eh != null)
  5239. eh (this, e);
  5240. }
  5241. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5242. protected virtual void OnMouseEnter(EventArgs e) {
  5243. EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
  5244. if (eh != null)
  5245. eh (this, e);
  5246. }
  5247. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5248. protected virtual void OnMouseHover(EventArgs e) {
  5249. EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
  5250. if (eh != null)
  5251. eh (this, e);
  5252. }
  5253. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5254. protected virtual void OnMouseLeave(EventArgs e) {
  5255. EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
  5256. if (eh != null)
  5257. eh (this, e);
  5258. }
  5259. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5260. protected virtual void OnMouseMove(MouseEventArgs e) {
  5261. MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
  5262. if (eh != null)
  5263. eh (this, e);
  5264. }
  5265. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5266. protected virtual void OnMouseUp(MouseEventArgs e) {
  5267. MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
  5268. if (eh != null)
  5269. eh (this, e);
  5270. }
  5271. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5272. protected virtual void OnMouseWheel(MouseEventArgs e) {
  5273. MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
  5274. if (eh != null)
  5275. eh (this, e);
  5276. }
  5277. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5278. protected virtual void OnMove(EventArgs e) {
  5279. EventHandler eh = (EventHandler)(Events [MoveEvent]);
  5280. if (eh != null)
  5281. eh (this, e);
  5282. }
  5283. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5284. protected virtual void OnNotifyMessage(Message m) {
  5285. // Override me!
  5286. }
  5287. #if NET_2_0
  5288. protected virtual void OnPaddingChanged (EventArgs e) {
  5289. EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
  5290. if (eh != null)
  5291. eh (this, e);
  5292. }
  5293. #endif
  5294. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5295. protected virtual void OnPaint(PaintEventArgs e) {
  5296. PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
  5297. if (eh != null)
  5298. eh (this, e);
  5299. }
  5300. internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
  5301. // Override me
  5302. }
  5303. internal virtual void OnPaintInternal(PaintEventArgs e) {
  5304. // Override me
  5305. }
  5306. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5307. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  5308. PaintControlBackground (pevent);
  5309. }
  5310. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5311. protected virtual void OnParentBackColorChanged(EventArgs e) {
  5312. if (background_color.IsEmpty && background_image==null) {
  5313. Invalidate();
  5314. OnBackColorChanged(e);
  5315. }
  5316. }
  5317. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5318. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  5319. Invalidate();
  5320. OnBackgroundImageChanged(e);
  5321. }
  5322. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5323. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  5324. if (binding_context==null && Parent != null) {
  5325. binding_context=Parent.binding_context;
  5326. OnBindingContextChanged(e);
  5327. }
  5328. }
  5329. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5330. protected virtual void OnParentChanged(EventArgs e) {
  5331. EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
  5332. if (eh != null)
  5333. eh (this, e);
  5334. }
  5335. #if NET_2_0
  5336. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5337. protected virtual void OnParentCursorChanged (EventArgs e)
  5338. {
  5339. }
  5340. #endif
  5341. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5342. protected virtual void OnParentEnabledChanged(EventArgs e) {
  5343. if (is_enabled) {
  5344. OnEnabledChanged(e);
  5345. }
  5346. }
  5347. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5348. protected virtual void OnParentFontChanged(EventArgs e) {
  5349. if (font==null) {
  5350. Invalidate();
  5351. OnFontChanged(e);
  5352. }
  5353. }
  5354. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5355. protected virtual void OnParentForeColorChanged(EventArgs e) {
  5356. if (foreground_color.IsEmpty) {
  5357. Invalidate();
  5358. OnForeColorChanged(e);
  5359. }
  5360. }
  5361. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5362. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  5363. if (right_to_left==RightToLeft.Inherit) {
  5364. Invalidate();
  5365. OnRightToLeftChanged(e);
  5366. }
  5367. }
  5368. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5369. protected virtual void OnParentVisibleChanged(EventArgs e) {
  5370. if (is_visible) {
  5371. OnVisibleChanged(e);
  5372. }
  5373. }
  5374. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5375. protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs qcdevent)
  5376. {
  5377. QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
  5378. if (eh != null)
  5379. eh (this, qcdevent);
  5380. }
  5381. #if NET_2_0
  5382. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5383. protected virtual void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
  5384. {
  5385. PreviewKeyDownEventHandler eh = (PreviewKeyDownEventHandler)(Events[PreviewKeyDownEvent]);
  5386. if (eh != null)
  5387. eh (this, e);
  5388. }
  5389. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5390. protected virtual void OnPrint (PaintEventArgs e)
  5391. {
  5392. PaintEventHandler eh = (PaintEventHandler)(Events[PaintEvent]);
  5393. if (eh != null)
  5394. eh (this, e);
  5395. }
  5396. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5397. protected virtual void OnRegionChanged (EventArgs e)
  5398. {
  5399. EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
  5400. if (eh != null)
  5401. eh (this, e);
  5402. }
  5403. #endif
  5404. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5405. protected virtual void OnResize(EventArgs e) {
  5406. OnResizeInternal (e);
  5407. }
  5408. internal virtual void OnResizeInternal (EventArgs e) {
  5409. PerformLayout(this, "Bounds");
  5410. EventHandler eh = (EventHandler)(Events [ResizeEvent]);
  5411. if (eh != null)
  5412. eh (this, e);
  5413. }
  5414. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5415. protected virtual void OnRightToLeftChanged(EventArgs e) {
  5416. EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
  5417. if (eh != null)
  5418. eh (this, e);
  5419. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  5420. }
  5421. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5422. protected virtual void OnSizeChanged(EventArgs e) {
  5423. DisposeBackBuffer ();
  5424. OnResize(e);
  5425. EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
  5426. if (eh != null)
  5427. eh (this, e);
  5428. }
  5429. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5430. protected virtual void OnStyleChanged(EventArgs e) {
  5431. EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
  5432. if (eh != null)
  5433. eh (this, e);
  5434. }
  5435. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5436. protected virtual void OnSystemColorsChanged(EventArgs e) {
  5437. EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
  5438. if (eh != null)
  5439. eh (this, e);
  5440. }
  5441. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5442. protected virtual void OnTabIndexChanged(EventArgs e) {
  5443. EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
  5444. if (eh != null)
  5445. eh (this, e);
  5446. }
  5447. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5448. protected virtual void OnTabStopChanged(EventArgs e) {
  5449. EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
  5450. if (eh != null)
  5451. eh (this, e);
  5452. }
  5453. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5454. protected virtual void OnTextChanged(EventArgs e) {
  5455. EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
  5456. if (eh != null)
  5457. eh (this, e);
  5458. }
  5459. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5460. protected virtual void OnValidated(EventArgs e) {
  5461. EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
  5462. if (eh != null)
  5463. eh (this, e);
  5464. }
  5465. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5466. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  5467. CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
  5468. if (eh != null)
  5469. eh (this, e);
  5470. }
  5471. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5472. protected virtual void OnVisibleChanged(EventArgs e) {
  5473. if (Visible)
  5474. CreateControl ();
  5475. EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
  5476. if (eh != null)
  5477. eh (this, e);
  5478. // We need to tell our kids (including implicit ones)
  5479. foreach (Control c in Controls.GetAllControls ())
  5480. if (c.Visible)
  5481. c.OnParentVisibleChanged (e);
  5482. }
  5483. #endregion // OnXXX methods
  5484. #region Events
  5485. #if NET_2_0
  5486. static object AutoSizeChangedEvent = new object ();
  5487. #endif
  5488. static object BackColorChangedEvent = new object ();
  5489. static object BackgroundImageChangedEvent = new object ();
  5490. #if NET_2_0
  5491. static object BackgroundImageLayoutChangedEvent = new object ();
  5492. #endif
  5493. static object BindingContextChangedEvent = new object ();
  5494. static object CausesValidationChangedEvent = new object ();
  5495. static object ChangeUICuesEvent = new object ();
  5496. static object ClickEvent = new object ();
  5497. #if NET_2_0
  5498. static object ClientSizeChangedEvent = new object ();
  5499. #endif
  5500. static object ContextMenuChangedEvent = new object ();
  5501. #if NET_2_0
  5502. static object ContextMenuStripChangedEvent = new object ();
  5503. #endif
  5504. static object ControlAddedEvent = new object ();
  5505. static object ControlRemovedEvent = new object ();
  5506. static object CursorChangedEvent = new object ();
  5507. static object DockChangedEvent = new object ();
  5508. static object DoubleClickEvent = new object ();
  5509. static object DragDropEvent = new object ();
  5510. static object DragEnterEvent = new object ();
  5511. static object DragLeaveEvent = new object ();
  5512. static object DragOverEvent = new object ();
  5513. static object EnabledChangedEvent = new object ();
  5514. static object EnterEvent = new object ();
  5515. static object FontChangedEvent = new object ();
  5516. static object ForeColorChangedEvent = new object ();
  5517. static object GiveFeedbackEvent = new object ();
  5518. static object GotFocusEvent = new object ();
  5519. static object HandleCreatedEvent = new object ();
  5520. static object HandleDestroyedEvent = new object ();
  5521. static object HelpRequestedEvent = new object ();
  5522. static object ImeModeChangedEvent = new object ();
  5523. static object InvalidatedEvent = new object ();
  5524. static object KeyDownEvent = new object ();
  5525. static object KeyPressEvent = new object ();
  5526. static object KeyUpEvent = new object ();
  5527. static object LayoutEvent = new object ();
  5528. static object LeaveEvent = new object ();
  5529. static object LocationChangedEvent = new object ();
  5530. static object LostFocusEvent = new object ();
  5531. #if NET_2_0
  5532. static object MarginChangedEvent = new object ();
  5533. #endif
  5534. static object MouseCaptureChangedEvent = new object ();
  5535. #if NET_2_0
  5536. static object MouseClickEvent = new object ();
  5537. static object MouseDoubleClickEvent = new object ();
  5538. #endif
  5539. static object MouseDownEvent = new object ();
  5540. static object MouseEnterEvent = new object ();
  5541. static object MouseHoverEvent = new object ();
  5542. static object MouseLeaveEvent = new object ();
  5543. static object MouseMoveEvent = new object ();
  5544. static object MouseUpEvent = new object ();
  5545. static object MouseWheelEvent = new object ();
  5546. static object MoveEvent = new object ();
  5547. #if NET_2_0
  5548. static object PaddingChangedEvent = new object ();
  5549. #endif
  5550. static object PaintEvent = new object ();
  5551. static object ParentChangedEvent = new object ();
  5552. #if NET_2_0
  5553. static object PreviewKeyDownEvent = new object ();
  5554. #endif
  5555. static object QueryAccessibilityHelpEvent = new object ();
  5556. static object QueryContinueDragEvent = new object ();
  5557. #if NET_2_0
  5558. static object RegionChangedEvent = new object ();
  5559. #endif
  5560. static object ResizeEvent = new object ();
  5561. static object RightToLeftChangedEvent = new object ();
  5562. static object SizeChangedEvent = new object ();
  5563. static object StyleChangedEvent = new object ();
  5564. static object SystemColorsChangedEvent = new object ();
  5565. static object TabIndexChangedEvent = new object ();
  5566. static object TabStopChangedEvent = new object ();
  5567. static object TextChangedEvent = new object ();
  5568. static object ValidatedEvent = new object ();
  5569. static object ValidatingEvent = new object ();
  5570. static object VisibleChangedEvent = new object ();
  5571. #if NET_2_0
  5572. [Browsable (false)]
  5573. [EditorBrowsable (EditorBrowsableState.Never)]
  5574. public event EventHandler AutoSizeChanged {
  5575. add { Events.AddHandler (AutoSizeChangedEvent, value);}
  5576. remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
  5577. }
  5578. #endif
  5579. public event EventHandler BackColorChanged {
  5580. add { Events.AddHandler (BackColorChangedEvent, value); }
  5581. remove { Events.RemoveHandler (BackColorChangedEvent, value); }
  5582. }
  5583. public event EventHandler BackgroundImageChanged {
  5584. add { Events.AddHandler (BackgroundImageChangedEvent, value); }
  5585. remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
  5586. }
  5587. #if NET_2_0
  5588. public event EventHandler BackgroundImageLayoutChanged {
  5589. add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
  5590. remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
  5591. }
  5592. #endif
  5593. public event EventHandler BindingContextChanged {
  5594. add { Events.AddHandler (BindingContextChangedEvent, value); }
  5595. remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
  5596. }
  5597. public event EventHandler CausesValidationChanged {
  5598. add { Events.AddHandler (CausesValidationChangedEvent, value); }
  5599. remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
  5600. }
  5601. public event UICuesEventHandler ChangeUICues {
  5602. add { Events.AddHandler (ChangeUICuesEvent, value); }
  5603. remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
  5604. }
  5605. public event EventHandler Click {
  5606. add { Events.AddHandler (ClickEvent, value); }
  5607. remove { Events.RemoveHandler (ClickEvent, value); }
  5608. }
  5609. #if NET_2_0
  5610. public event EventHandler ClientSizeChanged {
  5611. add {Events.AddHandler (ClientSizeChangedEvent, value);}
  5612. remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
  5613. }
  5614. #endif
  5615. #if NET_2_0
  5616. [Browsable (false)]
  5617. #endif
  5618. public event EventHandler ContextMenuChanged {
  5619. add { Events.AddHandler (ContextMenuChangedEvent, value); }
  5620. remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
  5621. }
  5622. #if NET_2_0
  5623. public event EventHandler ContextMenuStripChanged {
  5624. add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
  5625. remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
  5626. }
  5627. #endif
  5628. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5629. #if NET_2_0
  5630. [Browsable(true)]
  5631. #else
  5632. [Browsable(false)]
  5633. #endif
  5634. public event ControlEventHandler ControlAdded {
  5635. add { Events.AddHandler (ControlAddedEvent, value); }
  5636. remove { Events.RemoveHandler (ControlAddedEvent, value); }
  5637. }
  5638. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5639. #if NET_2_0
  5640. [Browsable(true)]
  5641. #else
  5642. [Browsable(false)]
  5643. #endif
  5644. public event ControlEventHandler ControlRemoved {
  5645. add { Events.AddHandler (ControlRemovedEvent, value); }
  5646. remove { Events.RemoveHandler (ControlRemovedEvent, value); }
  5647. }
  5648. [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
  5649. public event EventHandler CursorChanged {
  5650. add { Events.AddHandler (CursorChangedEvent, value); }
  5651. remove { Events.RemoveHandler (CursorChangedEvent, value); }
  5652. }
  5653. public event EventHandler DockChanged {
  5654. add { Events.AddHandler (DockChangedEvent, value); }
  5655. remove { Events.RemoveHandler (DockChangedEvent, value); }
  5656. }
  5657. public event EventHandler DoubleClick {
  5658. add { Events.AddHandler (DoubleClickEvent, value); }
  5659. remove { Events.RemoveHandler (DoubleClickEvent, value); }
  5660. }
  5661. public event DragEventHandler DragDrop {
  5662. add { Events.AddHandler (DragDropEvent, value); }
  5663. remove { Events.RemoveHandler (DragDropEvent, value); }
  5664. }
  5665. public event DragEventHandler DragEnter {
  5666. add { Events.AddHandler (DragEnterEvent, value); }
  5667. remove { Events.RemoveHandler (DragEnterEvent, value); }
  5668. }
  5669. public event EventHandler DragLeave {
  5670. add { Events.AddHandler (DragLeaveEvent, value); }
  5671. remove { Events.RemoveHandler (DragLeaveEvent, value); }
  5672. }
  5673. public event DragEventHandler DragOver {
  5674. add { Events.AddHandler (DragOverEvent, value); }
  5675. remove { Events.RemoveHandler (DragOverEvent, value); }
  5676. }
  5677. public event EventHandler EnabledChanged {
  5678. add { Events.AddHandler (EnabledChangedEvent, value); }
  5679. remove { Events.RemoveHandler (EnabledChangedEvent, value); }
  5680. }
  5681. public event EventHandler Enter {
  5682. add { Events.AddHandler (EnterEvent, value); }
  5683. remove { Events.RemoveHandler (EnterEvent, value); }
  5684. }
  5685. public event EventHandler FontChanged {
  5686. add { Events.AddHandler (FontChangedEvent, value); }
  5687. remove { Events.RemoveHandler (FontChangedEvent, value); }
  5688. }
  5689. public event EventHandler ForeColorChanged {
  5690. add { Events.AddHandler (ForeColorChangedEvent, value); }
  5691. remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
  5692. }
  5693. public event GiveFeedbackEventHandler GiveFeedback {
  5694. add { Events.AddHandler (GiveFeedbackEvent, value); }
  5695. remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
  5696. }
  5697. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5698. [Browsable(false)]
  5699. public event EventHandler GotFocus {
  5700. add { Events.AddHandler (GotFocusEvent, value); }
  5701. remove { Events.RemoveHandler (GotFocusEvent, value); }
  5702. }
  5703. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5704. [Browsable(false)]
  5705. public event EventHandler HandleCreated {
  5706. add { Events.AddHandler (HandleCreatedEvent, value); }
  5707. remove { Events.RemoveHandler (HandleCreatedEvent, value); }
  5708. }
  5709. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5710. [Browsable(false)]
  5711. public event EventHandler HandleDestroyed {
  5712. add { Events.AddHandler (HandleDestroyedEvent, value); }
  5713. remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
  5714. }
  5715. public event HelpEventHandler HelpRequested {
  5716. add { Events.AddHandler (HelpRequestedEvent, value); }
  5717. remove { Events.RemoveHandler (HelpRequestedEvent, value); }
  5718. }
  5719. public event EventHandler ImeModeChanged {
  5720. add { Events.AddHandler (ImeModeChangedEvent, value); }
  5721. remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
  5722. }
  5723. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5724. [Browsable(false)]
  5725. public event InvalidateEventHandler Invalidated {
  5726. add { Events.AddHandler (InvalidatedEvent, value); }
  5727. remove { Events.RemoveHandler (InvalidatedEvent, value); }
  5728. }
  5729. public event KeyEventHandler KeyDown {
  5730. add { Events.AddHandler (KeyDownEvent, value); }
  5731. remove { Events.RemoveHandler (KeyDownEvent, value); }
  5732. }
  5733. public event KeyPressEventHandler KeyPress {
  5734. add { Events.AddHandler (KeyPressEvent, value); }
  5735. remove { Events.RemoveHandler (KeyPressEvent, value); }
  5736. }
  5737. public event KeyEventHandler KeyUp {
  5738. add { Events.AddHandler (KeyUpEvent, value); }
  5739. remove { Events.RemoveHandler (KeyUpEvent, value); }
  5740. }
  5741. public event LayoutEventHandler Layout {
  5742. add { Events.AddHandler (LayoutEvent, value); }
  5743. remove { Events.RemoveHandler (LayoutEvent, value); }
  5744. }
  5745. public event EventHandler Leave {
  5746. add { Events.AddHandler (LeaveEvent, value); }
  5747. remove { Events.RemoveHandler (LeaveEvent, value); }
  5748. }
  5749. public event EventHandler LocationChanged {
  5750. add { Events.AddHandler (LocationChangedEvent, value); }
  5751. remove { Events.RemoveHandler (LocationChangedEvent, value); }
  5752. }
  5753. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5754. [Browsable(false)]
  5755. public event EventHandler LostFocus {
  5756. add { Events.AddHandler (LostFocusEvent, value); }
  5757. remove { Events.RemoveHandler (LostFocusEvent, value); }
  5758. }
  5759. #if NET_2_0
  5760. public event EventHandler MarginChanged {
  5761. add { Events.AddHandler (MarginChangedEvent, value); }
  5762. remove {Events.RemoveHandler (MarginChangedEvent, value); }
  5763. }
  5764. #endif
  5765. #if NET_2_0
  5766. public event EventHandler MouseCaptureChanged {
  5767. #else
  5768. internal event EventHandler MouseCaptureChanged {
  5769. #endif
  5770. add { Events.AddHandler (MouseCaptureChangedEvent, value); }
  5771. remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
  5772. }
  5773. #if NET_2_0
  5774. public event MouseEventHandler MouseClick
  5775. {
  5776. add { Events.AddHandler (MouseClickEvent, value); }
  5777. remove { Events.RemoveHandler (MouseClickEvent, value); }
  5778. }
  5779. public event MouseEventHandler MouseDoubleClick
  5780. {
  5781. add { Events.AddHandler (MouseDoubleClickEvent, value); }
  5782. remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
  5783. }
  5784. #endif
  5785. public event MouseEventHandler MouseDown {
  5786. add { Events.AddHandler (MouseDownEvent, value); }
  5787. remove { Events.RemoveHandler (MouseDownEvent, value); }
  5788. }
  5789. public event EventHandler MouseEnter {
  5790. add { Events.AddHandler (MouseEnterEvent, value); }
  5791. remove { Events.RemoveHandler (MouseEnterEvent, value); }
  5792. }
  5793. public event EventHandler MouseHover {
  5794. add { Events.AddHandler (MouseHoverEvent, value); }
  5795. remove { Events.RemoveHandler (MouseHoverEvent, value); }
  5796. }
  5797. public event EventHandler MouseLeave {
  5798. add { Events.AddHandler (MouseLeaveEvent, value); }
  5799. remove { Events.RemoveHandler (MouseLeaveEvent, value); }
  5800. }
  5801. public event MouseEventHandler MouseMove {
  5802. add { Events.AddHandler (MouseMoveEvent, value); }
  5803. remove { Events.RemoveHandler (MouseMoveEvent, value); }
  5804. }
  5805. public event MouseEventHandler MouseUp {
  5806. add { Events.AddHandler (MouseUpEvent, value); }
  5807. remove { Events.RemoveHandler (MouseUpEvent, value); }
  5808. }
  5809. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5810. [Browsable(false)]
  5811. public event MouseEventHandler MouseWheel {
  5812. add { Events.AddHandler (MouseWheelEvent, value); }
  5813. remove { Events.RemoveHandler (MouseWheelEvent, value); }
  5814. }
  5815. public event EventHandler Move {
  5816. add { Events.AddHandler (MoveEvent, value); }
  5817. remove { Events.RemoveHandler (MoveEvent, value); }
  5818. }
  5819. #if NET_2_0
  5820. public event EventHandler PaddingChanged
  5821. {
  5822. add { Events.AddHandler (PaddingChangedEvent, value); }
  5823. remove { Events.RemoveHandler (PaddingChangedEvent, value); }
  5824. }
  5825. #endif
  5826. public event PaintEventHandler Paint {
  5827. add { Events.AddHandler (PaintEvent, value); }
  5828. remove { Events.RemoveHandler (PaintEvent, value); }
  5829. }
  5830. public event EventHandler ParentChanged {
  5831. add { Events.AddHandler (ParentChangedEvent, value); }
  5832. remove { Events.RemoveHandler (ParentChangedEvent, value); }
  5833. }
  5834. #if NET_2_0
  5835. public event PreviewKeyDownEventHandler PreviewKeyDown {
  5836. add { Events.AddHandler (PreviewKeyDownEvent, value); }
  5837. remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
  5838. }
  5839. #endif
  5840. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
  5841. add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
  5842. remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
  5843. }
  5844. public event QueryContinueDragEventHandler QueryContinueDrag {
  5845. add { Events.AddHandler (QueryContinueDragEvent, value); }
  5846. remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
  5847. }
  5848. #if NET_2_0
  5849. public event EventHandler RegionChanged {
  5850. add { Events.AddHandler (RegionChangedEvent, value); }
  5851. remove { Events.RemoveHandler (RegionChangedEvent, value); }
  5852. }
  5853. #endif
  5854. #if NET_2_0
  5855. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5856. #endif
  5857. public event EventHandler Resize {
  5858. add { Events.AddHandler (ResizeEvent, value); }
  5859. remove { Events.RemoveHandler (ResizeEvent, value); }
  5860. }
  5861. public event EventHandler RightToLeftChanged {
  5862. add { Events.AddHandler (RightToLeftChangedEvent, value); }
  5863. remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
  5864. }
  5865. public event EventHandler SizeChanged {
  5866. add { Events.AddHandler (SizeChangedEvent, value); }
  5867. remove { Events.RemoveHandler (SizeChangedEvent, value); }
  5868. }
  5869. public event EventHandler StyleChanged {
  5870. add { Events.AddHandler (StyleChangedEvent, value); }
  5871. remove { Events.RemoveHandler (StyleChangedEvent, value); }
  5872. }
  5873. public event EventHandler SystemColorsChanged {
  5874. add { Events.AddHandler (SystemColorsChangedEvent, value); }
  5875. remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
  5876. }
  5877. public event EventHandler TabIndexChanged {
  5878. add { Events.AddHandler (TabIndexChangedEvent, value); }
  5879. remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
  5880. }
  5881. public event EventHandler TabStopChanged {
  5882. add { Events.AddHandler (TabStopChangedEvent, value); }
  5883. remove { Events.RemoveHandler (TabStopChangedEvent, value); }
  5884. }
  5885. public event EventHandler TextChanged {
  5886. add { Events.AddHandler (TextChangedEvent, value); }
  5887. remove { Events.RemoveHandler (TextChangedEvent, value); }
  5888. }
  5889. public event EventHandler Validated {
  5890. add { Events.AddHandler (ValidatedEvent, value); }
  5891. remove { Events.RemoveHandler (ValidatedEvent, value); }
  5892. }
  5893. public event CancelEventHandler Validating {
  5894. add { Events.AddHandler (ValidatingEvent, value); }
  5895. remove { Events.RemoveHandler (ValidatingEvent, value); }
  5896. }
  5897. public event EventHandler VisibleChanged {
  5898. add { Events.AddHandler (VisibleChangedEvent, value); }
  5899. remove { Events.RemoveHandler (VisibleChangedEvent, value); }
  5900. }
  5901. #endregion // Events
  5902. }
  5903. }