Control.cs 100 KB

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