Control.cs 147 KB

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