Control.cs 183 KB

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