Control.cs 134 KB

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