Control.cs 108 KB

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