Control.cs 140 KB

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