Control.cs 166 KB

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