Control.cs 132 KB

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