2
0

Control.cs 161 KB

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