Control.cs 103 KB

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