Control.cs 167 KB

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