Control.cs 110 KB

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