Control.cs 76 KB

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