Control.cs 109 KB

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