Control.cs 110 KB

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