Control.cs 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534
  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. #undef DebugRecreate
  34. #undef DebugFocus
  35. using System;
  36. using System.ComponentModel;
  37. using System.ComponentModel.Design;
  38. using System.ComponentModel.Design.Serialization;
  39. using System.Collections;
  40. using System.Diagnostics;
  41. using System.Drawing;
  42. using System.Drawing.Drawing2D;
  43. using System.Reflection;
  44. using System.Runtime.InteropServices;
  45. using System.Security;
  46. using System.Threading;
  47. namespace System.Windows.Forms
  48. {
  49. #if NET_2_0
  50. [ComVisible(true)]
  51. [ClassInterface (ClassInterfaceType.AutoDispatch)]
  52. #endif
  53. [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  54. [DefaultProperty("Text")]
  55. [DefaultEvent("Click")]
  56. [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  57. [ToolboxItemFilter("System.Windows.Forms")]
  58. public class Control : Component, ISynchronizeInvoke, IWin32Window
  59. #if NET_2_0
  60. , IBindableComponent, IDropTarget
  61. #endif
  62. {
  63. #region Local Variables
  64. // Basic
  65. internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
  66. Rectangle explicit_bounds; // explicitly set bounds
  67. internal object creator_thread; // thread that created the control
  68. internal ControlNativeWindow window; // object for native window handle
  69. string name; // for object naming
  70. // State
  71. bool is_created; // true if OnCreateControl has been sent
  72. internal bool has_focus; // true if control has focus
  73. internal bool is_visible; // true if control is visible
  74. internal bool is_entered; // is the mouse inside the control?
  75. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  76. bool is_accessible; // true if the control is visible to accessibility applications
  77. bool is_captured; // tracks if the control has captured the mouse
  78. internal bool is_toplevel; // tracks if the control is a toplevel window
  79. bool is_recreating; // tracks if the handle for the control is being recreated
  80. bool causes_validation; // tracks if validation is executed on changes
  81. bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
  82. bool container_selected; // true if Select() or Focus() is called on a container, to prevent child controls from raising their GotFocus event
  83. int tab_index; // position in tab order of siblings
  84. bool tab_stop; // is the control a tab stop?
  85. bool is_disposed; // has the window already been disposed?
  86. Size client_size; // size of the client area (window excluding decorations)
  87. Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  88. ControlStyles control_style; // rather win32-specific, style bits for control
  89. ImeMode ime_mode;
  90. bool layout_pending; // true if our parent needs to re-layout us
  91. object control_tag; // object that contains data about our control
  92. internal int mouse_clicks; // Counter for mouse clicks
  93. Cursor cursor; // Cursor for the window
  94. internal bool allow_drop; // true if the control accepts droping objects on it
  95. Region clip_region; // User-specified clip region for the window
  96. // Visuals
  97. internal Color foreground_color; // foreground color for control
  98. internal Color background_color; // background color for control
  99. Image background_image; // background image for control
  100. internal Font font; // font for control
  101. string text; // window/title text for control
  102. internal BorderStyle border_style; // Border style of control
  103. // Layout
  104. Layout.LayoutEngine layout_engine;
  105. int layout_suspended;
  106. internal AnchorStyles anchor_style; // anchoring requirements for our control
  107. internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
  108. // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
  109. internal int dist_right; // distance to the right border of the parent
  110. internal int dist_bottom; // distance to the bottom border of the parent
  111. // to be categorized...
  112. ControlCollection child_controls; // our children
  113. Control parent; // our parent control
  114. AccessibleObject accessibility_object; // object that contains accessibility information about our control
  115. BindingContext binding_context;
  116. RightToLeft right_to_left; // drawing direction for control
  117. ContextMenu context_menu; // Context menu associated with the control
  118. // double buffering
  119. Graphics backbuffer_dc;
  120. object backbuffer;
  121. Region invalid_region;
  122. // to implement DeviceContext without depending on double buffering
  123. Bitmap bmp;
  124. Graphics bmp_g;
  125. ControlBindingsCollection data_bindings;
  126. #if NET_2_0
  127. internal bool use_compatible_text_rendering;
  128. static bool verify_thread_handle;
  129. Padding padding;
  130. ImageLayout backgroundimage_layout;
  131. Size maximum_size;
  132. Size minimum_size;
  133. Size preferred_size;
  134. Padding margin;
  135. private ContextMenuStrip context_menu_strip;
  136. #endif
  137. #endregion // Local Variables
  138. #region Private Classes
  139. // This helper class allows us to dispatch messages to Control.WndProc
  140. internal class ControlNativeWindow : NativeWindow {
  141. private Control owner;
  142. public ControlNativeWindow(Control control) : base() {
  143. this.owner=control;
  144. }
  145. public Control Owner {
  146. get {
  147. return owner;
  148. }
  149. }
  150. static internal Control ControlFromHandle(IntPtr hWnd) {
  151. ControlNativeWindow window;
  152. window = (ControlNativeWindow)window_collection[hWnd];
  153. if (window != null) {
  154. return window.owner;
  155. }
  156. return null;
  157. }
  158. static internal Control ControlFromChildHandle (IntPtr handle) {
  159. ControlNativeWindow window;
  160. Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
  161. while (hwnd != null) {
  162. window = (ControlNativeWindow)window_collection[hwnd.Handle];
  163. if (window != null) {
  164. return window.owner;
  165. }
  166. hwnd = hwnd.Parent;
  167. }
  168. return null;
  169. }
  170. protected override void WndProc(ref Message m) {
  171. owner.WndProc(ref m);
  172. }
  173. }
  174. #endregion
  175. #region Public Classes
  176. [ComVisible(true)]
  177. public class ControlAccessibleObject : AccessibleObject {
  178. Control owner;
  179. #region ControlAccessibleObject Constructors
  180. public ControlAccessibleObject(Control ownerControl)
  181. : base (ownerControl)
  182. {
  183. this.owner = ownerControl;
  184. }
  185. #endregion // ControlAccessibleObject Constructors
  186. #region ControlAccessibleObject Public Instance Properties
  187. public override string DefaultAction {
  188. get {
  189. return base.DefaultAction;
  190. }
  191. }
  192. public override string Description {
  193. get {
  194. return base.Description;
  195. }
  196. }
  197. public IntPtr Handle {
  198. get {
  199. return owner.Handle;
  200. }
  201. set {
  202. // We don't want to let them set it
  203. }
  204. }
  205. public override string Help {
  206. get {
  207. return base.Help;
  208. }
  209. }
  210. public override string KeyboardShortcut {
  211. get {
  212. return base.KeyboardShortcut;
  213. }
  214. }
  215. public override string Name {
  216. get {
  217. return base.Name;
  218. }
  219. set {
  220. base.Name = value;
  221. }
  222. }
  223. public Control Owner {
  224. get {
  225. return owner;
  226. }
  227. }
  228. public override AccessibleObject Parent {
  229. get {
  230. return base.Parent;
  231. }
  232. }
  233. public override AccessibleRole Role {
  234. get {
  235. return base.Role;
  236. }
  237. }
  238. #endregion // ControlAccessibleObject Public Instance Properties
  239. #region ControlAccessibleObject Public Instance Methods
  240. public override int GetHelpTopic(out string FileName) {
  241. return base.GetHelpTopic (out FileName);
  242. }
  243. [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
  244. public void NotifyClients(AccessibleEvents accEvent) {
  245. throw new NotImplementedException();
  246. }
  247. [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
  248. public void NotifyClients(AccessibleEvents accEvent, int childID) {
  249. throw new NotImplementedException();
  250. }
  251. public override string ToString() {
  252. return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
  253. }
  254. #endregion // ControlAccessibleObject Public Instance Methods
  255. }
  256. #if NET_2_0
  257. [ComVisible (false)]
  258. #else
  259. [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  260. #endif
  261. [ListBindable(false)]
  262. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  263. #region ControlCollection Local Variables
  264. ArrayList list;
  265. ArrayList impl_list;
  266. Control[] all_controls;
  267. Control owner;
  268. #endregion // ControlCollection Local Variables
  269. #region ControlCollection Public Constructor
  270. public ControlCollection(Control owner) {
  271. this.owner=owner;
  272. this.list=new ArrayList();
  273. }
  274. #endregion
  275. #region ControlCollection Public Instance Properties
  276. public int Count
  277. {
  278. get {
  279. return list.Count;
  280. }
  281. }
  282. #if NET_2_0
  283. bool IList.IsReadOnly
  284. #else
  285. public bool IsReadOnly
  286. #endif
  287. {
  288. get {
  289. return list.IsReadOnly;
  290. }
  291. }
  292. public virtual Control this[int index] {
  293. get {
  294. if (index < 0 || index >= list.Count) {
  295. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  296. }
  297. return (Control)list[index];
  298. }
  299. }
  300. #endregion // ControlCollection Public Instance Properties
  301. #region ControlCollection Private Instance Methods
  302. public virtual void Add (Control value)
  303. {
  304. if (value == null)
  305. return;
  306. if (Contains (value)) {
  307. owner.PerformLayout();
  308. return;
  309. }
  310. if (value.tab_index == -1) {
  311. int end;
  312. int index;
  313. int use;
  314. use = 0;
  315. end = owner.child_controls.Count;
  316. for (int i = 0; i < end; i++) {
  317. index = owner.child_controls[i].tab_index;
  318. if (index >= use) {
  319. use = index + 1;
  320. }
  321. }
  322. value.tab_index = use;
  323. }
  324. if (value.parent != null) {
  325. value.parent.Controls.Remove(value);
  326. }
  327. all_controls = null;
  328. list.Add (value);
  329. value.ChangeParent(owner);
  330. value.InitLayout();
  331. owner.UpdateChildrenZOrder();
  332. owner.PerformLayout(value, "Parent");
  333. owner.OnControlAdded(new ControlEventArgs(value));
  334. }
  335. internal void AddToList (Control c)
  336. {
  337. all_controls = null;
  338. list.Add (c);
  339. }
  340. internal virtual void AddImplicit (Control control)
  341. {
  342. if (impl_list == null)
  343. impl_list = new ArrayList ();
  344. if (AllContains (control))
  345. return;
  346. all_controls = null;
  347. impl_list.Add (control);
  348. control.ChangeParent (owner);
  349. control.InitLayout ();
  350. owner.UpdateChildrenZOrder ();
  351. owner.PerformLayout (control, "Parent");
  352. owner.OnControlAdded (new ControlEventArgs (control));
  353. }
  354. #if NET_2_0
  355. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  356. #endif
  357. public virtual void AddRange (Control[] controls)
  358. {
  359. if (controls == null)
  360. throw new ArgumentNullException ("controls");
  361. owner.SuspendLayout ();
  362. try {
  363. for (int i = 0; i < controls.Length; i++)
  364. Add (controls[i]);
  365. } finally {
  366. owner.ResumeLayout ();
  367. }
  368. }
  369. internal virtual void AddRangeImplicit (Control [] controls)
  370. {
  371. if (controls == null)
  372. throw new ArgumentNullException ("controls");
  373. owner.SuspendLayout ();
  374. try {
  375. for (int i = 0; i < controls.Length; i++)
  376. AddImplicit (controls [i]);
  377. } finally {
  378. owner.ResumeLayout ();
  379. }
  380. }
  381. public virtual void Clear ()
  382. {
  383. all_controls = null;
  384. // MS sends remove events in reverse order
  385. while (list.Count > 0) {
  386. Remove((Control)list[list.Count - 1]);
  387. }
  388. }
  389. internal virtual void ClearImplicit ()
  390. {
  391. if (impl_list == null)
  392. return;
  393. all_controls = null;
  394. impl_list.Clear ();
  395. }
  396. public bool Contains (Control value)
  397. {
  398. for (int i = list.Count; i > 0; ) {
  399. i--;
  400. if (list [i] == value) {
  401. // Do we need to do anything here?
  402. return true;
  403. }
  404. }
  405. return false;
  406. }
  407. internal bool ImplicitContains (Control value)
  408. {
  409. if (impl_list == null)
  410. return false;
  411. for (int i = impl_list.Count; i > 0; ) {
  412. i--;
  413. if (impl_list [i] == value) {
  414. // Do we need to do anything here?
  415. return true;
  416. }
  417. }
  418. return false;
  419. }
  420. internal bool AllContains (Control value)
  421. {
  422. return Contains (value) || ImplicitContains (value);
  423. }
  424. public void CopyTo (Array array, int index)
  425. {
  426. list.CopyTo(array, index);
  427. }
  428. public override bool Equals(object other) {
  429. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  430. return(true);
  431. } else {
  432. return(false);
  433. }
  434. }
  435. public int GetChildIndex(Control child) {
  436. return GetChildIndex(child, false);
  437. }
  438. public int GetChildIndex(Control child, bool throwException) {
  439. int index;
  440. index=list.IndexOf(child);
  441. if (index==-1 && throwException) {
  442. throw new ArgumentException("Not a child control", "child");
  443. }
  444. return index;
  445. }
  446. public IEnumerator GetEnumerator() {
  447. return list.GetEnumerator();
  448. }
  449. internal IEnumerator GetAllEnumerator ()
  450. {
  451. Control [] res = GetAllControls ();
  452. return res.GetEnumerator ();
  453. }
  454. internal Control [] GetAllControls ()
  455. {
  456. if (all_controls != null)
  457. return all_controls;
  458. if (impl_list == null) {
  459. all_controls = (Control []) list.ToArray (typeof (Control));
  460. return all_controls;
  461. }
  462. all_controls = new Control [list.Count + impl_list.Count];
  463. impl_list.CopyTo (all_controls);
  464. list.CopyTo (all_controls, impl_list.Count);
  465. return all_controls;
  466. }
  467. public override int GetHashCode() {
  468. return base.GetHashCode();
  469. }
  470. public int IndexOf(Control control) {
  471. return list.IndexOf(control);
  472. }
  473. public virtual void Remove(Control value) {
  474. if (value == null)
  475. return;
  476. owner.PerformLayout(value, "Parent");
  477. owner.OnControlRemoved(new ControlEventArgs(value));
  478. all_controls = null;
  479. list.Remove(value);
  480. value.ChangeParent(null);
  481. owner.UpdateChildrenZOrder();
  482. }
  483. internal virtual void RemoveImplicit (Control control)
  484. {
  485. if (impl_list != null) {
  486. all_controls = null;
  487. owner.PerformLayout (control, "Parent");
  488. owner.OnControlRemoved (new ControlEventArgs (control));
  489. impl_list.Remove (control);
  490. }
  491. control.ChangeParent (null);
  492. owner.UpdateChildrenZOrder ();
  493. }
  494. public void RemoveAt(int index) {
  495. if (index < 0 || index >= list.Count) {
  496. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  497. }
  498. Remove ((Control)list[index]);
  499. }
  500. public void SetChildIndex(Control child, int newIndex) {
  501. if (child == null)
  502. throw new ArgumentNullException ("child");
  503. int old_index;
  504. old_index=list.IndexOf(child);
  505. if (old_index==-1) {
  506. throw new ArgumentException("Not a child control", "child");
  507. }
  508. if (old_index==newIndex) {
  509. return;
  510. }
  511. all_controls = null;
  512. list.RemoveAt(old_index);
  513. if (newIndex>list.Count) {
  514. list.Add(child);
  515. } else {
  516. list.Insert(newIndex, child);
  517. }
  518. child.UpdateZOrder();
  519. owner.PerformLayout();
  520. }
  521. #endregion // ControlCollection Private Instance Methods
  522. #region ControlCollection Interface Properties
  523. object IList.this[int index] {
  524. get {
  525. if (index<0 || index>=list.Count) {
  526. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  527. }
  528. return this[index];
  529. }
  530. set {
  531. if (!(value is Control)) {
  532. throw new ArgumentException("Object of type Control required", "value");
  533. }
  534. all_controls = null;
  535. Control ctrl = (Control) value;
  536. list[index]= ctrl;
  537. ctrl.ChangeParent(owner);
  538. ctrl.InitLayout();
  539. owner.UpdateChildrenZOrder();
  540. owner.PerformLayout(ctrl, "Parent");
  541. }
  542. }
  543. bool IList.IsFixedSize {
  544. get {
  545. return false;
  546. }
  547. }
  548. bool ICollection.IsSynchronized {
  549. get {
  550. return list.IsSynchronized;
  551. }
  552. }
  553. object ICollection.SyncRoot {
  554. get {
  555. return list.SyncRoot;
  556. }
  557. }
  558. #endregion // ControlCollection Interface Properties
  559. #region ControlCollection Interface Methods
  560. int IList.Add(object value) {
  561. if (value == null) {
  562. throw new ArgumentNullException("value", "Cannot add null controls");
  563. }
  564. if (!(value is Control)) {
  565. throw new ArgumentException("Object of type Control required", "value");
  566. }
  567. return list.Add(value);
  568. }
  569. bool IList.Contains(object value) {
  570. if (!(value is Control)) {
  571. throw new ArgumentException("Object of type Control required", "value");
  572. }
  573. return this.Contains((Control) value);
  574. }
  575. int IList.IndexOf(object value) {
  576. if (!(value is Control)) {
  577. throw new ArgumentException("Object of type Control required", "value");
  578. }
  579. return this.IndexOf((Control) value);
  580. }
  581. void IList.Insert(int index, object value) {
  582. if (!(value is Control)) {
  583. throw new ArgumentException("Object of type Control required", "value");
  584. }
  585. all_controls = null;
  586. list.Insert(index, value);
  587. }
  588. void IList.Remove(object value) {
  589. if (!(value is Control)) {
  590. throw new ArgumentException("Object of type Control required", "value");
  591. }
  592. all_controls = null;
  593. list.Remove(value);
  594. }
  595. Object ICloneable.Clone() {
  596. ControlCollection clone = new ControlCollection(this.owner);
  597. clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
  598. return clone;
  599. }
  600. #endregion // ControlCollection Interface Methods
  601. }
  602. #endregion // ControlCollection Class
  603. #region Public Constructors
  604. public Control()
  605. {
  606. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  607. is_created = false;
  608. is_visible = true;
  609. is_captured = false;
  610. is_disposed = false;
  611. is_enabled = true;
  612. is_entered = false;
  613. layout_pending = false;
  614. is_toplevel = false;
  615. causes_validation = true;
  616. has_focus = false;
  617. layout_suspended = 0;
  618. mouse_clicks = 1;
  619. tab_index = -1;
  620. cursor = null;
  621. right_to_left = RightToLeft.Inherit;
  622. border_style = BorderStyle.None;
  623. background_color = Color.Empty;
  624. dist_right = 0;
  625. dist_bottom = 0;
  626. tab_stop = true;
  627. ime_mode = ImeMode.Inherit;
  628. layout_engine = this.LayoutEngine;
  629. if (layout_engine == null)
  630. layout_engine = new Layout.DefaultLayout ();
  631. #if NET_2_0
  632. backgroundimage_layout = ImageLayout.Tile;
  633. use_compatible_text_rendering = Application.use_compatible_text_rendering;
  634. padding = new Padding(0);
  635. maximum_size = new Size();
  636. minimum_size = new Size();
  637. preferred_size = this.DefaultSize;
  638. margin = this.DefaultMargin;
  639. #endif
  640. control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
  641. ControlStyles.Selectable | ControlStyles.StandardClick |
  642. ControlStyles.StandardDoubleClick;
  643. #if NET_2_0
  644. control_style |= ControlStyles.UseTextForAccessibility;
  645. #endif
  646. parent = null;
  647. background_image = null;
  648. text = string.Empty;
  649. name = string.Empty;
  650. window = new ControlNativeWindow(this);
  651. child_controls = CreateControlsInstance();
  652. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  653. client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  654. XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
  655. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
  656. bounds.X=-1;
  657. bounds.Y=-1;
  658. }
  659. }
  660. public Control(Control parent, string text) : this() {
  661. Text=text;
  662. Parent=parent;
  663. }
  664. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  665. Parent=parent;
  666. bounds.X=left;
  667. bounds.Y=top;
  668. bounds.Width=width;
  669. bounds.Height=height;
  670. SetBounds(left, top, width, height, BoundsSpecified.All);
  671. Text=text;
  672. }
  673. public Control(string text) : this() {
  674. Text=text;
  675. }
  676. public Control(string text, int left, int top, int width, int height) : this() {
  677. bounds.X=left;
  678. bounds.Y=top;
  679. bounds.Width=width;
  680. bounds.Height=height;
  681. SetBounds(left, top, width, height, BoundsSpecified.All);
  682. Text=text;
  683. }
  684. private delegate void RemoveDelegate(object c);
  685. protected override void Dispose(bool disposing) {
  686. if (!is_disposed && disposing) {
  687. Capture = false;
  688. DisposeBackBuffer ();
  689. if (bmp != null) {
  690. bmp.Dispose ();
  691. bmp = null;
  692. }
  693. if (bmp_g != null) {
  694. bmp_g.Dispose ();
  695. bmp_g = null;
  696. }
  697. if (invalid_region!=null) {
  698. invalid_region.Dispose();
  699. invalid_region=null;
  700. }
  701. if (this.InvokeRequired) {
  702. if (Application.MessageLoop) {
  703. this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
  704. }
  705. } else {
  706. DestroyHandle();
  707. }
  708. if (parent != null) {
  709. parent.Controls.Remove(this);
  710. }
  711. Control [] children = child_controls.GetAllControls ();
  712. for (int i=0; i<children.Length; i++) {
  713. children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
  714. children[i].Dispose();
  715. }
  716. }
  717. is_disposed = true;
  718. is_visible = false;
  719. base.Dispose(disposing);
  720. }
  721. #endregion // Public Constructors
  722. #region Internal Properties
  723. internal BorderStyle InternalBorderStyle {
  724. get {
  725. return border_style;
  726. }
  727. set {
  728. if (!Enum.IsDefined (typeof (BorderStyle), value))
  729. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
  730. if (border_style != value) {
  731. border_style = value;
  732. if (IsHandleCreated) {
  733. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  734. Refresh();
  735. }
  736. }
  737. }
  738. }
  739. #endregion // Internal Properties
  740. #region Private & Internal Methods
  741. #if NET_2_0
  742. void IDropTarget.OnDragDrop (DragEventArgs e)
  743. {
  744. OnDragDrop (e);
  745. }
  746. void IDropTarget.OnDragEnter (DragEventArgs e)
  747. {
  748. OnDragEnter (e);
  749. }
  750. void IDropTarget.OnDragLeave (EventArgs e)
  751. {
  752. OnDragLeave (e);
  753. }
  754. void IDropTarget.OnDragOver (DragEventArgs e)
  755. {
  756. OnDragOver (e);
  757. }
  758. #endif
  759. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
  760. AsyncMethodResult result;
  761. AsyncMethodData data;
  762. if (!disposing) {
  763. Control p = this;
  764. do {
  765. if (!p.IsHandleCreated) {
  766. throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
  767. }
  768. p = p.parent;
  769. } while (p != null);
  770. }
  771. result = new AsyncMethodResult ();
  772. data = new AsyncMethodData ();
  773. data.Handle = window.Handle;
  774. data.Method = method;
  775. data.Args = args;
  776. data.Result = result;
  777. #if NET_2_0
  778. if (!ExecutionContext.IsFlowSuppressed ()) {
  779. data.Context = ExecutionContext.Capture ();
  780. }
  781. #else
  782. #if !MWF_ON_MSRUNTIME
  783. if (SecurityManager.SecurityEnabled) {
  784. data.Stack = CompressedStack.GetCompressedStack ();
  785. }
  786. #endif
  787. #endif
  788. XplatUI.SendAsyncMethod (data);
  789. return result;
  790. }
  791. internal void PointToClient (ref int x, ref int y)
  792. {
  793. XplatUI.ScreenToClient (Handle, ref x, ref y);
  794. }
  795. internal void PointToScreen (ref int x, ref int y)
  796. {
  797. XplatUI.ClientToScreen (Handle, ref x, ref y);
  798. }
  799. internal bool IsRecreating {
  800. get {
  801. return is_recreating;
  802. }
  803. }
  804. internal Graphics DeviceContext {
  805. get {
  806. if (bmp_g == null) {
  807. bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  808. bmp_g = Graphics.FromImage (bmp);
  809. }
  810. return bmp_g;
  811. }
  812. }
  813. private void InvalidateBackBuffer ()
  814. {
  815. if (invalid_region != null)
  816. invalid_region.Dispose();
  817. invalid_region = new Region (ClientRectangle);
  818. }
  819. private void CreateBackBuffer ()
  820. {
  821. if (backbuffer != null)
  822. return;
  823. int width = Width;
  824. int height = Height;
  825. if (width < 1) width = 1;
  826. if (height < 1) height = 1;
  827. XplatUI.CreateOffscreenDrawable (Handle, width, height, out backbuffer, out backbuffer_dc);
  828. InvalidateBackBuffer ();
  829. }
  830. private void DisposeBackBuffer ()
  831. {
  832. if (backbuffer == null)
  833. return;
  834. XplatUI.DestroyOffscreenDrawable (backbuffer, backbuffer_dc);
  835. backbuffer = null;
  836. backbuffer_dc = null;
  837. if (invalid_region != null)
  838. invalid_region.Dispose ();
  839. invalid_region = null;
  840. }
  841. internal static void SetChildColor(Control parent) {
  842. Control child;
  843. for (int i=0; i < parent.child_controls.Count; i++) {
  844. child=parent.child_controls[i];
  845. if (child.child_controls.Count>0) {
  846. SetChildColor(child);
  847. }
  848. }
  849. }
  850. internal bool Select(Control control) {
  851. IContainerControl container;
  852. if (control == null) {
  853. return false;
  854. }
  855. container = GetContainerControl();
  856. if (container != null) {
  857. container.ActiveControl = control;
  858. }
  859. if (control.IsHandleCreated) {
  860. XplatUI.SetFocus(control.window.Handle);
  861. }
  862. return true;
  863. }
  864. internal void SelectChild (Control control)
  865. {
  866. if (control.IsHandleCreated)
  867. XplatUI.SetFocus (control.window.Handle);
  868. }
  869. internal virtual void DoDefaultAction() {
  870. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  871. }
  872. internal static IntPtr MakeParam (int low, int high){
  873. return new IntPtr (high << 16 | low & 0xffff);
  874. }
  875. internal static int LowOrder (int param) {
  876. return ((int)(short)(param & 0xffff));
  877. }
  878. internal static int HighOrder (int param) {
  879. return ((int)(short)(param >> 16));
  880. }
  881. // This method exists so controls overriding OnPaintBackground can have default background painting done
  882. internal virtual void PaintControlBackground (PaintEventArgs pevent)
  883. {
  884. if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
  885. if (parent != null) {
  886. PaintEventArgs parent_pe;
  887. GraphicsState state;
  888. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  889. state = parent_pe.Graphics.Save();
  890. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  891. parent.OnPaintBackground(parent_pe);
  892. parent_pe.Graphics.Restore(state);
  893. state = parent_pe.Graphics.Save();
  894. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  895. parent.OnPaint(parent_pe);
  896. parent_pe.Graphics.Restore(state);
  897. parent_pe.SetGraphics(null);
  898. }
  899. }
  900. if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
  901. if (parent != null) {
  902. PaintEventArgs parent_pe;
  903. Region region;
  904. GraphicsState state;
  905. Hwnd hwnd;
  906. hwnd = Hwnd.ObjectFromHandle(Handle);
  907. if (hwnd != null) {
  908. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  909. region = new Region ();
  910. region.MakeEmpty();
  911. region.Union(ClientRectangle);
  912. foreach (Rectangle r in hwnd.ClipRectangles) {
  913. region.Union (r);
  914. }
  915. state = parent_pe.Graphics.Save();
  916. parent_pe.Graphics.Clip = region;
  917. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  918. parent.OnPaintBackground(parent_pe);
  919. parent_pe.Graphics.Restore(state);
  920. state = parent_pe.Graphics.Save();
  921. parent_pe.Graphics.Clip = region;
  922. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  923. parent.OnPaint(parent_pe);
  924. parent_pe.Graphics.Restore(state);
  925. parent_pe.SetGraphics(null);
  926. region.Intersect(clip_region);
  927. pevent.Graphics.Clip = region;
  928. }
  929. }
  930. }
  931. if (background_image == null) {
  932. 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));
  933. return;
  934. }
  935. DrawBackgroundImage (pevent.Graphics);
  936. }
  937. void DrawBackgroundImage (Graphics g)
  938. {
  939. #if NET_2_0
  940. Rectangle drawing_rectangle = new Rectangle ();
  941. g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  942. switch (backgroundimage_layout)
  943. {
  944. case ImageLayout.Tile:
  945. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  946. g.FillRectangle (b, ClientRectangle);
  947. }
  948. return;
  949. case ImageLayout.Center:
  950. drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
  951. drawing_rectangle.Size = background_image.Size;
  952. break;
  953. case ImageLayout.None:
  954. drawing_rectangle.Location = Point.Empty;
  955. drawing_rectangle.Size = background_image.Size;
  956. break;
  957. case ImageLayout.Stretch:
  958. drawing_rectangle = ClientRectangle;
  959. break;
  960. case ImageLayout.Zoom:
  961. drawing_rectangle = ClientRectangle;
  962. if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
  963. drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
  964. drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
  965. } else {
  966. drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
  967. drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
  968. }
  969. break;
  970. default:
  971. return;
  972. }
  973. g.DrawImage (background_image, drawing_rectangle);
  974. #else
  975. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  976. g.FillRectangle (b, ClientRectangle);
  977. }
  978. #endif
  979. }
  980. internal virtual void DndEnter (DragEventArgs e)
  981. {
  982. try {
  983. OnDragEnter (e);
  984. } catch { }
  985. }
  986. internal virtual void DndOver (DragEventArgs e)
  987. {
  988. try {
  989. OnDragOver (e);
  990. } catch { }
  991. }
  992. internal virtual void DndDrop (DragEventArgs e)
  993. {
  994. try {
  995. OnDragDrop (e);
  996. } catch (Exception exc) {
  997. Console.Error.WriteLine ("MWF: Exception while dropping:");
  998. Console.Error.WriteLine (exc);
  999. }
  1000. }
  1001. internal virtual void DndLeave (EventArgs e)
  1002. {
  1003. try {
  1004. OnDragLeave (e);
  1005. } catch { }
  1006. }
  1007. internal virtual void DndFeedback(GiveFeedbackEventArgs e)
  1008. {
  1009. try {
  1010. OnGiveFeedback(e);
  1011. } catch { }
  1012. }
  1013. internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
  1014. {
  1015. try {
  1016. OnQueryContinueDrag(e);
  1017. } catch { }
  1018. }
  1019. internal static MouseButtons FromParamToMouseButtons (int param) {
  1020. MouseButtons buttons = MouseButtons.None;
  1021. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  1022. buttons |= MouseButtons.Left;
  1023. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  1024. buttons |= MouseButtons.Middle;
  1025. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  1026. buttons |= MouseButtons.Right;
  1027. return buttons;
  1028. }
  1029. internal void FireEnter ()
  1030. {
  1031. OnEnter (EventArgs.Empty);
  1032. }
  1033. internal void FireLeave ()
  1034. {
  1035. OnLeave (EventArgs.Empty);
  1036. }
  1037. internal void FireValidating (CancelEventArgs ce)
  1038. {
  1039. OnValidating (ce);
  1040. }
  1041. internal void FireValidated ()
  1042. {
  1043. OnValidated (EventArgs.Empty);
  1044. }
  1045. internal virtual bool ProcessControlMnemonic(char charCode) {
  1046. return ProcessMnemonic(charCode);
  1047. }
  1048. private static Control FindFlatForward(Control container, Control start) {
  1049. Control found;
  1050. int index;
  1051. int end;
  1052. found = null;
  1053. end = container.child_controls.Count;
  1054. if (start != null) {
  1055. index = start.tab_index;
  1056. } else {
  1057. index = -1;
  1058. }
  1059. for (int i = 0, pos = -1; i < end; i++) {
  1060. if (start == container.child_controls[i]) {
  1061. pos = i;
  1062. continue;
  1063. }
  1064. if (found == null) {
  1065. if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
  1066. found = container.child_controls[i];
  1067. }
  1068. } else if (found.tab_index > container.child_controls[i].tab_index) {
  1069. if (container.child_controls[i].tab_index > index) {
  1070. found = container.child_controls[i];
  1071. }
  1072. }
  1073. }
  1074. return found;
  1075. }
  1076. private static Control FindControlForward(Control container, Control start) {
  1077. Control found;
  1078. found = null;
  1079. if (start == null) {
  1080. return FindFlatForward(container, start);
  1081. }
  1082. if (start.child_controls != null && start.child_controls.Count > 0 &&
  1083. (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
  1084. return FindControlForward(start, null);
  1085. }
  1086. else {
  1087. while (start != container) {
  1088. found = FindFlatForward(start.parent, start);
  1089. if (found != null) {
  1090. return found;
  1091. }
  1092. start = start.parent;
  1093. }
  1094. }
  1095. return null;
  1096. }
  1097. private static Control FindFlatBackward(Control container, Control start) {
  1098. Control found;
  1099. int index;
  1100. int end;
  1101. found = null;
  1102. end = container.child_controls.Count;
  1103. if (start != null) {
  1104. index = start.tab_index;
  1105. } else {
  1106. // FIXME: Possible speed-up: Keep the highest taborder index in the container
  1107. index = -1;
  1108. for (int i = 0; i < end; i++) {
  1109. if (container.child_controls[i].tab_index > index) {
  1110. index = container.child_controls[i].tab_index;
  1111. }
  1112. }
  1113. index++;
  1114. }
  1115. bool hit = false;
  1116. for (int i = end - 1; i >= 0; i--) {
  1117. if (start == container.child_controls[i]) {
  1118. hit = true;
  1119. continue;
  1120. }
  1121. if (found == null || found.tab_index < container.child_controls[i].tab_index) {
  1122. if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
  1123. found = container.child_controls[i];
  1124. }
  1125. }
  1126. return found;
  1127. }
  1128. private static Control FindControlBackward(Control container, Control start) {
  1129. Control found = null;
  1130. if (start == null) {
  1131. found = FindFlatBackward(container, start);
  1132. }
  1133. else if (start != container) {
  1134. if (start.parent != null) {
  1135. found = FindFlatBackward(start.parent, start);
  1136. if (found == null) {
  1137. if (start.parent != container)
  1138. return start.parent;
  1139. return null;
  1140. }
  1141. }
  1142. }
  1143. if (found == null || start.parent == null)
  1144. found = start;
  1145. while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
  1146. found.child_controls != null && found.child_controls.Count > 0)) {
  1147. // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
  1148. // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
  1149. found = FindFlatBackward(found, null);
  1150. }
  1151. return found;
  1152. /*
  1153. Control found;
  1154. found = null;
  1155. if (start != null) {
  1156. found = FindFlatBackward(start.parent, start);
  1157. if (found == null) {
  1158. if (start.parent != container) {
  1159. return start.parent;
  1160. }
  1161. }
  1162. }
  1163. if (found == null) {
  1164. found = FindFlatBackward(container, start);
  1165. }
  1166. if (container != start) {
  1167. while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
  1168. found = FindControlBackward(found, null);
  1169. if (found != null) {
  1170. return found;
  1171. }
  1172. }
  1173. }
  1174. return found;
  1175. */
  1176. }
  1177. internal virtual void HandleClick(int clicks, MouseEventArgs me) {
  1178. if (GetStyle(ControlStyles.StandardClick)) {
  1179. if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
  1180. #if !NET_2_0
  1181. OnDoubleClick(EventArgs.Empty);
  1182. } else {
  1183. OnClick(EventArgs.Empty);
  1184. #else
  1185. OnDoubleClick(me);
  1186. } else {
  1187. OnClick(me);
  1188. #endif
  1189. }
  1190. }
  1191. }
  1192. internal void CaptureWithConfine (Control ConfineWindow)
  1193. {
  1194. if (this.IsHandleCreated && !is_captured) {
  1195. is_captured = true;
  1196. XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
  1197. }
  1198. }
  1199. private void CheckDataBindings ()
  1200. {
  1201. if (data_bindings == null)
  1202. return;
  1203. BindingContext binding_context = BindingContext;
  1204. foreach (Binding binding in data_bindings) {
  1205. binding.Check (binding_context);
  1206. }
  1207. }
  1208. private void ChangeParent(Control new_parent) {
  1209. bool pre_enabled;
  1210. bool pre_visible;
  1211. Font pre_font;
  1212. Color pre_fore_color;
  1213. Color pre_back_color;
  1214. RightToLeft pre_rtl;
  1215. // These properties are inherited from our parent
  1216. // Get them pre parent-change and then send events
  1217. // if they are changed after we have our new parent
  1218. pre_enabled = Enabled;
  1219. pre_visible = Visible;
  1220. pre_font = Font;
  1221. pre_fore_color = ForeColor;
  1222. pre_back_color = BackColor;
  1223. pre_rtl = RightToLeft;
  1224. // MS doesn't seem to send a CursorChangedEvent
  1225. parent = new_parent;
  1226. if (IsHandleCreated)
  1227. XplatUI.SetParent(Handle,
  1228. (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
  1229. OnParentChanged(EventArgs.Empty);
  1230. if (pre_enabled != Enabled) {
  1231. OnEnabledChanged(EventArgs.Empty);
  1232. }
  1233. if (pre_visible != Visible) {
  1234. OnVisibleChanged(EventArgs.Empty);
  1235. }
  1236. if (pre_font != Font) {
  1237. OnFontChanged(EventArgs.Empty);
  1238. }
  1239. if (pre_fore_color != ForeColor) {
  1240. OnForeColorChanged(EventArgs.Empty);
  1241. }
  1242. if (pre_back_color != BackColor) {
  1243. OnBackColorChanged(EventArgs.Empty);
  1244. }
  1245. if (pre_rtl != RightToLeft) {
  1246. // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
  1247. // because when RTL changes they have to recreate the win32 control
  1248. // We don't really need that (until someone runs into compatibility issues)
  1249. OnRightToLeftChanged(EventArgs.Empty);
  1250. }
  1251. if ((new_parent != null) && new_parent.Created && !Created) {
  1252. CreateControl();
  1253. }
  1254. if ((binding_context == null) && Created) {
  1255. OnBindingContextChanged(EventArgs.Empty);
  1256. }
  1257. }
  1258. private void UpdateDistances() {
  1259. if (parent != null) {
  1260. dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
  1261. dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
  1262. }
  1263. }
  1264. #endregion // Private & Internal Methods
  1265. #region Public Static Properties
  1266. public static Color DefaultBackColor {
  1267. get {
  1268. return ThemeEngine.Current.DefaultControlBackColor;
  1269. }
  1270. }
  1271. public static Font DefaultFont {
  1272. get {
  1273. return ThemeEngine.Current.DefaultFont;
  1274. }
  1275. }
  1276. public static Color DefaultForeColor {
  1277. get {
  1278. return ThemeEngine.Current.DefaultControlForeColor;
  1279. }
  1280. }
  1281. public static Keys ModifierKeys {
  1282. get {
  1283. return XplatUI.State.ModifierKeys;
  1284. }
  1285. }
  1286. public static MouseButtons MouseButtons {
  1287. get {
  1288. return XplatUI.State.MouseButtons;
  1289. }
  1290. }
  1291. public static Point MousePosition {
  1292. get {
  1293. return Cursor.Position;
  1294. }
  1295. }
  1296. #if NET_2_0
  1297. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1298. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1299. [Browsable (false)]
  1300. [MonoTODO]
  1301. public static bool CheckForIllegalCrossThreadCalls
  1302. {
  1303. get {
  1304. return verify_thread_handle;
  1305. }
  1306. set {
  1307. verify_thread_handle = value;
  1308. }
  1309. }
  1310. #endif
  1311. #endregion // Public Static Properties
  1312. #region Public Instance Properties
  1313. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1314. [Browsable(false)]
  1315. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1316. public AccessibleObject AccessibilityObject {
  1317. get {
  1318. if (accessibility_object==null) {
  1319. accessibility_object=CreateAccessibilityInstance();
  1320. }
  1321. return accessibility_object;
  1322. }
  1323. }
  1324. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1325. [Browsable(false)]
  1326. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1327. public string AccessibleDefaultActionDescription {
  1328. get {
  1329. return AccessibilityObject.default_action;
  1330. }
  1331. set {
  1332. AccessibilityObject.default_action=value;
  1333. }
  1334. }
  1335. [Localizable(true)]
  1336. [DefaultValue(null)]
  1337. [MWFCategory("Accessibility")]
  1338. public string AccessibleDescription {
  1339. get {
  1340. return AccessibilityObject.description;
  1341. }
  1342. set {
  1343. AccessibilityObject.description=value;
  1344. }
  1345. }
  1346. [Localizable(true)]
  1347. [DefaultValue(null)]
  1348. [MWFCategory("Accessibility")]
  1349. public string AccessibleName {
  1350. get {
  1351. return AccessibilityObject.Name;
  1352. }
  1353. set {
  1354. AccessibilityObject.Name=value;
  1355. }
  1356. }
  1357. [DefaultValue(AccessibleRole.Default)]
  1358. [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
  1359. public AccessibleRole AccessibleRole {
  1360. get {
  1361. return AccessibilityObject.role;
  1362. }
  1363. set {
  1364. AccessibilityObject.role=value;
  1365. }
  1366. }
  1367. [DefaultValue(false)]
  1368. [MWFCategory("Behavior")]
  1369. public virtual bool AllowDrop {
  1370. get {
  1371. return allow_drop;
  1372. }
  1373. set {
  1374. if (allow_drop == value)
  1375. return;
  1376. allow_drop = value;
  1377. if (IsHandleCreated) {
  1378. UpdateStyles();
  1379. XplatUI.SetAllowDrop (Handle, value);
  1380. }
  1381. }
  1382. }
  1383. [Localizable(true)]
  1384. [RefreshProperties(RefreshProperties.Repaint)]
  1385. [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
  1386. [MWFCategory("Layout")]
  1387. public virtual AnchorStyles Anchor {
  1388. get {
  1389. return anchor_style;
  1390. }
  1391. set {
  1392. anchor_style=value;
  1393. if (parent != null) {
  1394. parent.PerformLayout(this, "Parent");
  1395. }
  1396. }
  1397. }
  1398. #if NET_2_0
  1399. // XXX: Implement me!
  1400. bool auto_size;
  1401. [RefreshProperties (RefreshProperties.All)]
  1402. [Localizable (true)]
  1403. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1404. [Browsable (false)]
  1405. [EditorBrowsable (EditorBrowsableState.Never)]
  1406. [DefaultValue (false)]
  1407. [MonoTODO("This method currently does nothing")]
  1408. public virtual bool AutoSize {
  1409. get {
  1410. //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
  1411. return auto_size;
  1412. }
  1413. set {
  1414. auto_size = value;
  1415. }
  1416. }
  1417. [AmbientValue (typeof(Size), "0, 0")]
  1418. public virtual Size MaximumSize {
  1419. get {
  1420. return maximum_size;
  1421. }
  1422. set {
  1423. maximum_size = value;
  1424. }
  1425. }
  1426. public virtual Size MinimumSize {
  1427. get {
  1428. return minimum_size;
  1429. }
  1430. set {
  1431. minimum_size = value;
  1432. }
  1433. }
  1434. #endif // NET_2_0
  1435. [DispId(-501)]
  1436. [MWFCategory("Appearance")]
  1437. public virtual Color BackColor {
  1438. get {
  1439. if (background_color.IsEmpty) {
  1440. if (parent!=null) {
  1441. Color pcolor = parent.BackColor;
  1442. if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
  1443. return pcolor;
  1444. }
  1445. return DefaultBackColor;
  1446. }
  1447. return background_color;
  1448. }
  1449. set {
  1450. if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
  1451. throw new ArgumentException("Transparent background colors are not supported on this control");
  1452. }
  1453. if (background_color != value) {
  1454. background_color=value;
  1455. SetChildColor(this);
  1456. OnBackColorChanged(EventArgs.Empty);
  1457. Invalidate();
  1458. }
  1459. }
  1460. }
  1461. [Localizable(true)]
  1462. [DefaultValue(null)]
  1463. [MWFCategory("Appearance")]
  1464. public virtual Image BackgroundImage {
  1465. get {
  1466. return background_image;
  1467. }
  1468. set {
  1469. if (background_image!=value) {
  1470. background_image=value;
  1471. OnBackgroundImageChanged(EventArgs.Empty);
  1472. Invalidate ();
  1473. }
  1474. }
  1475. }
  1476. #if NET_2_0
  1477. [DefaultValue (ImageLayout.Tile)]
  1478. [Localizable (true)]
  1479. public virtual ImageLayout BackgroundImageLayout {
  1480. get {
  1481. return backgroundimage_layout;
  1482. }
  1483. set {
  1484. if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
  1485. throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
  1486. if (value != backgroundimage_layout) {
  1487. backgroundimage_layout = value;
  1488. Invalidate ();
  1489. }
  1490. }
  1491. }
  1492. #endif
  1493. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1494. [Browsable(false)]
  1495. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1496. public virtual BindingContext BindingContext {
  1497. get {
  1498. if (binding_context != null)
  1499. return binding_context;
  1500. if (Parent == null)
  1501. return null;
  1502. binding_context = Parent.BindingContext;
  1503. return binding_context;
  1504. }
  1505. set {
  1506. if (binding_context != value) {
  1507. binding_context = value;
  1508. OnBindingContextChanged(EventArgs.Empty);
  1509. }
  1510. }
  1511. }
  1512. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1513. [Browsable(false)]
  1514. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1515. public int Bottom {
  1516. get {
  1517. return bounds.Y+bounds.Height;
  1518. }
  1519. }
  1520. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1521. [Browsable(false)]
  1522. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1523. public Rectangle Bounds {
  1524. get {
  1525. return this.bounds;
  1526. }
  1527. set {
  1528. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  1529. }
  1530. }
  1531. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1532. [Browsable(false)]
  1533. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1534. public bool CanFocus {
  1535. get {
  1536. if (IsHandleCreated && Visible && Enabled) {
  1537. return true;
  1538. }
  1539. return false;
  1540. }
  1541. }
  1542. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1543. [Browsable(false)]
  1544. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1545. public bool CanSelect {
  1546. get {
  1547. Control parent;
  1548. if (!GetStyle(ControlStyles.Selectable)) {
  1549. return false;
  1550. }
  1551. parent = this;
  1552. while (parent != null) {
  1553. if (!parent.is_visible || !parent.is_enabled) {
  1554. return false;
  1555. }
  1556. parent = parent.parent;
  1557. }
  1558. return true;
  1559. }
  1560. }
  1561. internal virtual bool InternalCapture {
  1562. get {
  1563. return Capture;
  1564. }
  1565. set {
  1566. Capture = value;
  1567. }
  1568. }
  1569. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1570. [Browsable(false)]
  1571. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1572. public bool Capture {
  1573. get {
  1574. return this.is_captured;
  1575. }
  1576. set {
  1577. if (this.IsHandleCreated && value != is_captured) {
  1578. if (value) {
  1579. is_captured = true;
  1580. XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
  1581. } else {
  1582. XplatUI.UngrabWindow(this.window.Handle);
  1583. is_captured = false;
  1584. }
  1585. }
  1586. }
  1587. }
  1588. [DefaultValue(true)]
  1589. [MWFCategory("Focus")]
  1590. public bool CausesValidation {
  1591. get {
  1592. return this.causes_validation;
  1593. }
  1594. set {
  1595. if (this.causes_validation != value) {
  1596. causes_validation = value;
  1597. OnCausesValidationChanged(EventArgs.Empty);
  1598. }
  1599. }
  1600. }
  1601. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1602. [Browsable(false)]
  1603. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1604. public Rectangle ClientRectangle {
  1605. get {
  1606. client_rect.Width = client_size.Width;
  1607. client_rect.Height = client_size.Height;
  1608. return client_rect;
  1609. }
  1610. }
  1611. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1612. [Browsable(false)]
  1613. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1614. public Size ClientSize {
  1615. get {
  1616. #if notneeded
  1617. if ((this is Form) && (((Form)this).form_parent_window != null)) {
  1618. return ((Form)this).form_parent_window.ClientSize;
  1619. }
  1620. #endif
  1621. return client_size;
  1622. }
  1623. set {
  1624. this.SetClientSizeCore(value.Width, value.Height);
  1625. }
  1626. }
  1627. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1628. [Browsable(false)]
  1629. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1630. [DescriptionAttribute("ControlCompanyNameDescr")]
  1631. public String CompanyName {
  1632. get {
  1633. return "Mono Project, Novell, Inc.";
  1634. }
  1635. }
  1636. internal bool ContainerSelected {
  1637. get { return container_selected; }
  1638. set { container_selected = value; }
  1639. }
  1640. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1641. [Browsable(false)]
  1642. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1643. public bool ContainsFocus {
  1644. get {
  1645. IntPtr focused_window;
  1646. focused_window = XplatUI.GetFocus();
  1647. if (IsHandleCreated) {
  1648. if (focused_window == Handle) {
  1649. return true;
  1650. }
  1651. for (int i=0; i < child_controls.Count; i++) {
  1652. if (child_controls[i].ContainsFocus) {
  1653. return true;
  1654. }
  1655. }
  1656. }
  1657. return false;
  1658. }
  1659. }
  1660. #if NET_2_0
  1661. [Browsable (false)]
  1662. #endif
  1663. [DefaultValue(null)]
  1664. [MWFCategory("Behavior")]
  1665. public virtual ContextMenu ContextMenu {
  1666. get {
  1667. return GetContextMenuInternal ();
  1668. }
  1669. set {
  1670. if (context_menu != value) {
  1671. context_menu = value;
  1672. OnContextMenuChanged(EventArgs.Empty);
  1673. }
  1674. }
  1675. }
  1676. internal virtual ContextMenu GetContextMenuInternal ()
  1677. {
  1678. return context_menu;
  1679. }
  1680. #if NET_2_0
  1681. public virtual ContextMenuStrip ContextMenuStrip {
  1682. get { return this.context_menu_strip; }
  1683. set {
  1684. if (this.context_menu_strip != value) {
  1685. this.context_menu_strip = value;
  1686. OnContextMenuStripChanged (EventArgs.Empty);
  1687. }
  1688. }
  1689. }
  1690. #endif
  1691. [Browsable(false)]
  1692. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  1693. public ControlCollection Controls {
  1694. get {
  1695. return this.child_controls;
  1696. }
  1697. }
  1698. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1699. [Browsable(false)]
  1700. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1701. public bool Created {
  1702. get {
  1703. return (!is_disposed && is_created);
  1704. }
  1705. }
  1706. [AmbientValue(null)]
  1707. [MWFCategory("Appearance")]
  1708. public virtual Cursor Cursor {
  1709. get {
  1710. if (cursor != null) {
  1711. return cursor;
  1712. }
  1713. if (parent != null) {
  1714. return parent.Cursor;
  1715. }
  1716. return Cursors.Default;
  1717. }
  1718. set {
  1719. if (cursor != value) {
  1720. Point pt;
  1721. cursor = value;
  1722. if (IsHandleCreated) {
  1723. pt = Cursor.Position;
  1724. if (bounds.Contains(pt) || Capture) {
  1725. if (GetChildAtPoint(pt) == null) {
  1726. if (cursor != null) {
  1727. XplatUI.SetCursor(window.Handle, cursor.handle);
  1728. } else {
  1729. if (parent != null) {
  1730. XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
  1731. } else {
  1732. XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738. OnCursorChanged(EventArgs.Empty);
  1739. }
  1740. }
  1741. }
  1742. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  1743. [ParenthesizePropertyName(true)]
  1744. [RefreshProperties(RefreshProperties.All)]
  1745. [MWFCategory("Data")]
  1746. public ControlBindingsCollection DataBindings {
  1747. get {
  1748. if (data_bindings == null)
  1749. data_bindings = new ControlBindingsCollection (this);
  1750. return data_bindings;
  1751. }
  1752. }
  1753. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1754. [Browsable(false)]
  1755. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1756. public virtual Rectangle DisplayRectangle {
  1757. get {
  1758. return ClientRectangle;
  1759. }
  1760. }
  1761. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1762. [Browsable(false)]
  1763. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1764. public bool Disposing {
  1765. get {
  1766. return is_disposed;
  1767. }
  1768. }
  1769. [Localizable(true)]
  1770. [RefreshProperties(RefreshProperties.Repaint)]
  1771. [DefaultValue(DockStyle.None)]
  1772. [MWFCategory("Layout")]
  1773. public virtual DockStyle Dock {
  1774. get {
  1775. return dock_style;
  1776. }
  1777. set {
  1778. if (dock_style == value) {
  1779. return;
  1780. }
  1781. if (!Enum.IsDefined (typeof (DockStyle), value)) {
  1782. throw new InvalidEnumArgumentException ("value", (int) value,
  1783. typeof (DockStyle));
  1784. }
  1785. dock_style = value;
  1786. if (dock_style == DockStyle.None) {
  1787. if (explicit_bounds == Rectangle.Empty)
  1788. Bounds = new Rectangle (new Point (0, 0), DefaultSize);
  1789. else
  1790. Bounds = explicit_bounds;
  1791. }
  1792. if (parent != null) {
  1793. parent.PerformLayout(this, "Parent");
  1794. }
  1795. OnDockChanged(EventArgs.Empty);
  1796. }
  1797. }
  1798. #if NET_2_0
  1799. protected virtual bool DoubleBuffered {
  1800. get {
  1801. return (control_style & ControlStyles.DoubleBuffer) != 0;
  1802. }
  1803. set {
  1804. SetStyle (ControlStyles.DoubleBuffer, value);
  1805. }
  1806. }
  1807. #endif
  1808. [DispId(-514)]
  1809. [Localizable(true)]
  1810. [MWFCategory("Behavior")]
  1811. public bool Enabled {
  1812. get {
  1813. if (!is_enabled) {
  1814. return false;
  1815. }
  1816. if (parent != null) {
  1817. return parent.Enabled;
  1818. }
  1819. return true;
  1820. }
  1821. set {
  1822. bool old_value = is_enabled;
  1823. is_enabled = value;
  1824. if (old_value != value && !value && this.has_focus)
  1825. SelectNextControl(this, true, true, true, true);
  1826. OnEnabledChanged (EventArgs.Empty);
  1827. }
  1828. }
  1829. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1830. [Browsable(false)]
  1831. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1832. public virtual bool Focused {
  1833. get {
  1834. return this.has_focus;
  1835. }
  1836. }
  1837. [DispId(-512)]
  1838. [AmbientValue(null)]
  1839. [Localizable(true)]
  1840. [MWFCategory("Appearance")]
  1841. public virtual Font Font {
  1842. get {
  1843. if (font != null) {
  1844. return font;
  1845. }
  1846. if (Parent != null && Parent.Font != null) {
  1847. return Parent.Font;
  1848. }
  1849. return DefaultFont;
  1850. }
  1851. [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
  1852. set {
  1853. if (font != null && font.Equals (value)) {
  1854. return;
  1855. }
  1856. font = value;
  1857. Invalidate();
  1858. OnFontChanged (EventArgs.Empty);
  1859. }
  1860. }
  1861. [DispId(-513)]
  1862. [MWFCategory("Appearance")]
  1863. public virtual Color ForeColor {
  1864. get {
  1865. if (foreground_color.IsEmpty) {
  1866. if (parent!=null) {
  1867. return parent.ForeColor;
  1868. }
  1869. return DefaultForeColor;
  1870. }
  1871. return foreground_color;
  1872. }
  1873. set {
  1874. if (foreground_color != value) {
  1875. foreground_color=value;
  1876. Invalidate();
  1877. OnForeColorChanged(EventArgs.Empty);
  1878. }
  1879. }
  1880. }
  1881. [DispId(-515)]
  1882. [Browsable(false)]
  1883. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1884. public IntPtr Handle { // IWin32Window
  1885. get {
  1886. #if NET_2_0
  1887. if (verify_thread_handle) {
  1888. if (this.InvokeRequired) {
  1889. throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
  1890. }
  1891. }
  1892. #endif
  1893. if (!IsHandleCreated) {
  1894. CreateHandle();
  1895. }
  1896. return window.Handle;
  1897. }
  1898. }
  1899. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1900. [Browsable(false)]
  1901. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1902. public bool HasChildren {
  1903. get {
  1904. if (this.child_controls.Count>0) {
  1905. return true;
  1906. }
  1907. return false;
  1908. }
  1909. }
  1910. [EditorBrowsable(EditorBrowsableState.Always)]
  1911. [Browsable(false)]
  1912. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1913. public int Height {
  1914. get {
  1915. return this.bounds.Height;
  1916. }
  1917. set {
  1918. SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  1919. }
  1920. }
  1921. [AmbientValue(ImeMode.Inherit)]
  1922. [Localizable(true)]
  1923. [MWFCategory("Behavior")]
  1924. public ImeMode ImeMode {
  1925. get {
  1926. if (ime_mode == ImeMode.Inherit) {
  1927. if (parent != null)
  1928. return parent.ImeMode;
  1929. else
  1930. return ImeMode.NoControl; // default value
  1931. }
  1932. return ime_mode;
  1933. }
  1934. set {
  1935. if (ime_mode != value) {
  1936. ime_mode = value;
  1937. OnImeModeChanged(EventArgs.Empty);
  1938. }
  1939. }
  1940. }
  1941. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1942. [Browsable(false)]
  1943. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1944. public bool InvokeRequired { // ISynchronizeInvoke
  1945. get {
  1946. if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
  1947. return true;
  1948. }
  1949. return false;
  1950. }
  1951. }
  1952. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1953. [Browsable(false)]
  1954. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1955. public bool IsAccessible {
  1956. get {
  1957. return is_accessible;
  1958. }
  1959. set {
  1960. is_accessible = value;
  1961. }
  1962. }
  1963. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1964. [Browsable(false)]
  1965. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1966. public bool IsDisposed {
  1967. get {
  1968. return this.is_disposed;
  1969. }
  1970. }
  1971. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1972. [Browsable(false)]
  1973. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1974. public bool IsHandleCreated {
  1975. get {
  1976. if ((window != null) && (window.Handle != IntPtr.Zero)) {
  1977. Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
  1978. if (hwnd != null && !hwnd.zombie)
  1979. return true;
  1980. }
  1981. return false;
  1982. }
  1983. }
  1984. [Browsable (false)]
  1985. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1986. #if NET_2_0
  1987. public virtual
  1988. #endif
  1989. Layout.LayoutEngine LayoutEngine {
  1990. get { return new Layout.DefaultLayout (); }
  1991. }
  1992. [EditorBrowsable(EditorBrowsableState.Always)]
  1993. [Browsable(false)]
  1994. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1995. public int Left {
  1996. get {
  1997. return this.bounds.X;
  1998. }
  1999. set {
  2000. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  2001. }
  2002. }
  2003. [Localizable(true)]
  2004. [MWFCategory("Layout")]
  2005. public Point Location {
  2006. get {
  2007. return new Point(bounds.X, bounds.Y);
  2008. }
  2009. set {
  2010. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  2011. }
  2012. }
  2013. #if NET_2_0
  2014. [Localizable (true)]
  2015. public Padding Margin {
  2016. get { return this.margin; }
  2017. set { this.margin = value; }
  2018. }
  2019. #endif
  2020. [Browsable(false)]
  2021. public string Name {
  2022. get {
  2023. return name;
  2024. }
  2025. set {
  2026. name = value;
  2027. }
  2028. }
  2029. #if NET_2_0
  2030. [Localizable(true)]
  2031. public Padding Padding {
  2032. get {
  2033. return padding;
  2034. }
  2035. set {
  2036. padding = value;
  2037. OnPaddingChanged (EventArgs.Empty);
  2038. }
  2039. }
  2040. #endif
  2041. [Browsable(false)]
  2042. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2043. public Control Parent {
  2044. get {
  2045. return this.parent;
  2046. }
  2047. set {
  2048. if (value == this) {
  2049. throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
  2050. }
  2051. if (parent!=value) {
  2052. if (value==null) {
  2053. parent.Controls.Remove(this);
  2054. parent = null;
  2055. return;
  2056. }
  2057. value.Controls.Add(this);
  2058. }
  2059. }
  2060. }
  2061. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2062. [Browsable(false)]
  2063. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2064. public string ProductName {
  2065. get {
  2066. Type t = typeof (AssemblyProductAttribute);
  2067. Assembly assembly = GetType().Module.Assembly;
  2068. object [] attrs = assembly.GetCustomAttributes (t, false);
  2069. AssemblyProductAttribute a = null;
  2070. // On MS we get a NullRefException if product attribute is not
  2071. // set.
  2072. if (attrs != null && attrs.Length > 0)
  2073. a = (AssemblyProductAttribute) attrs [0];
  2074. return a.Product;
  2075. }
  2076. }
  2077. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2078. [Browsable(false)]
  2079. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2080. public string ProductVersion {
  2081. get {
  2082. Type t = typeof (AssemblyVersionAttribute);
  2083. Assembly assembly = GetType().Module.Assembly;
  2084. object [] attrs = assembly.GetCustomAttributes (t, false);
  2085. if (attrs == null || attrs.Length < 1)
  2086. return "1.0.0.0";
  2087. return ((AssemblyVersionAttribute)attrs [0]).Version;
  2088. }
  2089. }
  2090. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2091. [Browsable(false)]
  2092. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2093. public bool RecreatingHandle {
  2094. get {
  2095. return is_recreating;
  2096. }
  2097. }
  2098. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2099. [Browsable(false)]
  2100. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2101. public Region Region {
  2102. get {
  2103. return clip_region;
  2104. }
  2105. set {
  2106. if (value != null && IsHandleCreated) {
  2107. XplatUI.SetClipRegion(Handle, value);
  2108. }
  2109. clip_region = value;
  2110. }
  2111. }
  2112. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2113. [Browsable(false)]
  2114. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2115. public int Right {
  2116. get {
  2117. return this.bounds.X+this.bounds.Width;
  2118. }
  2119. }
  2120. [AmbientValue(RightToLeft.Inherit)]
  2121. [Localizable(true)]
  2122. [MWFCategory("Appearance")]
  2123. public virtual RightToLeft RightToLeft {
  2124. get {
  2125. if (right_to_left == RightToLeft.Inherit) {
  2126. if (parent != null)
  2127. return parent.RightToLeft;
  2128. else
  2129. return RightToLeft.No; // default value
  2130. }
  2131. return right_to_left;
  2132. }
  2133. set {
  2134. if (value != right_to_left) {
  2135. right_to_left = value;
  2136. OnRightToLeftChanged(EventArgs.Empty);
  2137. }
  2138. }
  2139. }
  2140. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2141. public override ISite Site {
  2142. get {
  2143. return base.Site;
  2144. }
  2145. set {
  2146. base.Site = value;
  2147. if (value != null) {
  2148. AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
  2149. if (ap != null) {
  2150. BackColor = ap.BackColor;
  2151. ForeColor = ap.ForeColor;
  2152. Cursor = ap.Cursor;
  2153. Font = ap.Font;
  2154. }
  2155. }
  2156. }
  2157. }
  2158. [Localizable(true)]
  2159. [MWFCategory("Layout")]
  2160. public Size Size {
  2161. get {
  2162. return new Size(Width, Height);
  2163. }
  2164. set {
  2165. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  2166. }
  2167. }
  2168. [Localizable(true)]
  2169. [MergableProperty(false)]
  2170. [MWFCategory("Behavior")]
  2171. public int TabIndex {
  2172. get {
  2173. if (tab_index != -1) {
  2174. return tab_index;
  2175. }
  2176. return 0;
  2177. }
  2178. set {
  2179. if (tab_index != value) {
  2180. tab_index = value;
  2181. OnTabIndexChanged(EventArgs.Empty);
  2182. }
  2183. }
  2184. }
  2185. [DispId(-516)]
  2186. [DefaultValue(true)]
  2187. [MWFCategory("Behavior")]
  2188. public bool TabStop {
  2189. get {
  2190. return tab_stop;
  2191. }
  2192. set {
  2193. if (tab_stop != value) {
  2194. tab_stop = value;
  2195. OnTabStopChanged(EventArgs.Empty);
  2196. }
  2197. }
  2198. }
  2199. [Localizable(false)]
  2200. [Bindable(true)]
  2201. [TypeConverter(typeof(StringConverter))]
  2202. [DefaultValue(null)]
  2203. [MWFCategory("Data")]
  2204. public object Tag {
  2205. get {
  2206. return control_tag;
  2207. }
  2208. set {
  2209. control_tag = value;
  2210. }
  2211. }
  2212. [DispId(-517)]
  2213. [Localizable(true)]
  2214. [BindableAttribute(true)]
  2215. [MWFCategory("Appearance")]
  2216. public virtual string Text {
  2217. get {
  2218. // Our implementation ignores ControlStyles.CacheText - we always cache
  2219. return this.text;
  2220. }
  2221. set {
  2222. if (value == null) {
  2223. value = String.Empty;
  2224. }
  2225. if (text!=value) {
  2226. text=value;
  2227. if (IsHandleCreated) {
  2228. /* we need to call .SetWindowStyle here instead of just .Text
  2229. because the presence/absence of Text (== "" or not) can cause
  2230. other window style things to appear/disappear */
  2231. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  2232. XplatUI.Text(Handle, text);
  2233. }
  2234. OnTextChanged (EventArgs.Empty);
  2235. }
  2236. }
  2237. }
  2238. [EditorBrowsable(EditorBrowsableState.Always)]
  2239. [Browsable(false)]
  2240. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2241. public int Top {
  2242. get {
  2243. return this.bounds.Y;
  2244. }
  2245. set {
  2246. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  2247. }
  2248. }
  2249. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2250. [Browsable(false)]
  2251. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2252. public Control TopLevelControl {
  2253. get {
  2254. Control p = this;
  2255. while (p.parent != null) {
  2256. p = p.parent;
  2257. }
  2258. return p is Form ? p : null;
  2259. }
  2260. }
  2261. [Localizable(true)]
  2262. [MWFCategory("Behavior")]
  2263. public bool Visible {
  2264. get {
  2265. if (!is_visible) {
  2266. return false;
  2267. } else if (parent != null) {
  2268. return parent.Visible;
  2269. }
  2270. return true;
  2271. }
  2272. set {
  2273. SetVisibleCore(value);
  2274. }
  2275. }
  2276. [EditorBrowsable(EditorBrowsableState.Always)]
  2277. [Browsable(false)]
  2278. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2279. public int Width {
  2280. get {
  2281. return this.bounds.Width;
  2282. }
  2283. set {
  2284. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  2285. }
  2286. }
  2287. [EditorBrowsable(EditorBrowsableState.Never)]
  2288. [Browsable(false)]
  2289. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2290. public IWindowTarget WindowTarget {
  2291. get {
  2292. return null;
  2293. }
  2294. set {
  2295. ; // MS Internal
  2296. }
  2297. }
  2298. #endregion // Public Instance Properties
  2299. #region Protected Instance Properties
  2300. protected virtual CreateParams CreateParams {
  2301. get {
  2302. CreateParams create_params = new CreateParams();
  2303. try {
  2304. create_params.Caption = Text;
  2305. }
  2306. catch {
  2307. create_params.Caption = text;
  2308. }
  2309. try {
  2310. create_params.X = Left;
  2311. }
  2312. catch {
  2313. create_params.X = this.bounds.X;
  2314. }
  2315. try {
  2316. create_params.Y = Top;
  2317. }
  2318. catch {
  2319. create_params.Y = this.bounds.Y;
  2320. }
  2321. try {
  2322. create_params.Width = Width;
  2323. }
  2324. catch {
  2325. create_params.Width = this.bounds.Width;
  2326. }
  2327. try {
  2328. create_params.Height = Height;
  2329. }
  2330. catch {
  2331. create_params.Height = this.bounds.Height;
  2332. }
  2333. create_params.ClassName = XplatUI.DefaultClassName;
  2334. create_params.ClassStyle = 0;
  2335. create_params.ExStyle = 0;
  2336. create_params.Param = 0;
  2337. if (allow_drop) {
  2338. create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
  2339. }
  2340. if ((parent!=null) && (parent.IsHandleCreated)) {
  2341. create_params.Parent = parent.Handle;
  2342. }
  2343. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  2344. if (is_visible) {
  2345. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  2346. }
  2347. if (!is_enabled) {
  2348. create_params.Style |= (int)WindowStyles.WS_DISABLED;
  2349. }
  2350. switch (border_style) {
  2351. case BorderStyle.FixedSingle:
  2352. create_params.Style |= (int) WindowStyles.WS_BORDER;
  2353. break;
  2354. case BorderStyle.Fixed3D:
  2355. create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
  2356. break;
  2357. }
  2358. return create_params;
  2359. }
  2360. }
  2361. protected virtual ImeMode DefaultImeMode {
  2362. get {
  2363. return ImeMode.Inherit;
  2364. }
  2365. }
  2366. #if NET_2_0
  2367. protected virtual Padding DefaultMargin {
  2368. get { return new Padding (3); }
  2369. }
  2370. #endif
  2371. protected virtual Size DefaultSize {
  2372. get {
  2373. return new Size(0, 0);
  2374. }
  2375. }
  2376. protected int FontHeight {
  2377. get {
  2378. return Font.Height;
  2379. }
  2380. set {
  2381. ;; // Nothing to do
  2382. }
  2383. }
  2384. #if NET_2_0
  2385. [Obsolete ()]
  2386. #endif
  2387. protected bool RenderRightToLeft {
  2388. get {
  2389. return (this.right_to_left == RightToLeft.Yes);
  2390. }
  2391. }
  2392. protected bool ResizeRedraw {
  2393. get {
  2394. return GetStyle(ControlStyles.ResizeRedraw);
  2395. }
  2396. set {
  2397. SetStyle(ControlStyles.ResizeRedraw, value);
  2398. }
  2399. }
  2400. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2401. [Browsable(false)]
  2402. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2403. protected virtual bool ShowFocusCues {
  2404. get {
  2405. return true;
  2406. }
  2407. }
  2408. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2409. [Browsable(false)]
  2410. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2411. #if NET_2_0
  2412. internal virtual
  2413. #endif
  2414. protected bool ShowKeyboardCues {
  2415. get {
  2416. return true;
  2417. }
  2418. }
  2419. #endregion // Protected Instance Properties
  2420. #region Public Static Methods
  2421. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2422. public static Control FromChildHandle(IntPtr handle) {
  2423. return Control.ControlNativeWindow.ControlFromChildHandle (handle);
  2424. }
  2425. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2426. public static Control FromHandle(IntPtr handle) {
  2427. return Control.ControlNativeWindow.ControlFromHandle(handle);
  2428. }
  2429. public static bool IsMnemonic(char charCode, string text) {
  2430. int amp;
  2431. amp = text.IndexOf('&');
  2432. if (amp != -1) {
  2433. if (amp + 1 < text.Length) {
  2434. if (text[amp + 1] != '&') {
  2435. if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
  2436. return true;
  2437. }
  2438. }
  2439. }
  2440. }
  2441. return false;
  2442. }
  2443. #endregion
  2444. #region Protected Static Methods
  2445. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2446. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  2447. Control c;
  2448. c = Control.FromHandle(hWnd);
  2449. if (c != null) {
  2450. c.WndProc(ref m);
  2451. return true;
  2452. }
  2453. return false;
  2454. }
  2455. #endregion
  2456. #region Public Instance Methods
  2457. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2458. public IAsyncResult BeginInvoke(Delegate method) {
  2459. object [] prms = null;
  2460. if (method is EventHandler)
  2461. prms = new object [] { this, EventArgs.Empty };
  2462. return BeginInvokeInternal(method, prms, false);
  2463. }
  2464. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2465. public IAsyncResult BeginInvoke (Delegate method, object[] args) {
  2466. return BeginInvokeInternal (method, args, false);
  2467. }
  2468. public void BringToFront() {
  2469. if (parent != null) {
  2470. parent.child_controls.SetChildIndex(this, 0);
  2471. parent.Refresh();
  2472. } else {
  2473. XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
  2474. }
  2475. }
  2476. public bool Contains(Control ctl) {
  2477. while (ctl != null) {
  2478. ctl = ctl.parent;
  2479. if (ctl == this) {
  2480. return true;
  2481. }
  2482. }
  2483. return false;
  2484. }
  2485. public void CreateControl() {
  2486. if (is_disposed) {
  2487. throw new ObjectDisposedException(GetType().FullName.ToString());
  2488. }
  2489. if (is_created) {
  2490. return;
  2491. }
  2492. if (!IsHandleCreated) {
  2493. CreateHandle();
  2494. }
  2495. if (!is_created) {
  2496. is_created = true;
  2497. }
  2498. Control [] controls = child_controls.GetAllControls ();
  2499. for (int i=0; i<controls.Length; i++) {
  2500. controls [i].CreateControl ();
  2501. }
  2502. UpdateChildrenZOrder();
  2503. if (binding_context == null) { // seem to be sent whenever it's null?
  2504. OnBindingContextChanged(EventArgs.Empty);
  2505. }
  2506. OnCreateControl();
  2507. }
  2508. public Graphics CreateGraphics() {
  2509. if (!IsHandleCreated) {
  2510. this.CreateHandle();
  2511. }
  2512. return Graphics.FromHwnd(this.window.Handle);
  2513. }
  2514. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  2515. return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
  2516. }
  2517. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2518. public object EndInvoke (IAsyncResult async_result) {
  2519. AsyncMethodResult result = (AsyncMethodResult) async_result;
  2520. return result.EndInvoke ();
  2521. }
  2522. public Form FindForm() {
  2523. Control c;
  2524. c = this;
  2525. while (c != null) {
  2526. if (c is Form) {
  2527. return (Form)c;
  2528. }
  2529. c = c.Parent;
  2530. }
  2531. return null;
  2532. }
  2533. #if NET_2_0
  2534. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2535. #endif
  2536. public bool Focus() {
  2537. if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
  2538. is_focusing = true;
  2539. Select(this);
  2540. is_focusing = false;
  2541. }
  2542. return has_focus;
  2543. }
  2544. public Control GetChildAtPoint(Point pt) {
  2545. // Microsoft's version of this function doesn't seem to work, so I can't check
  2546. // if we only consider children or also grandchildren, etc.
  2547. // I'm gonna say 'children only'
  2548. for (int i=0; i<child_controls.Count; i++) {
  2549. if (child_controls[i].Bounds.Contains(pt)) {
  2550. return child_controls[i];
  2551. }
  2552. }
  2553. return null;
  2554. }
  2555. public IContainerControl GetContainerControl() {
  2556. Control current = this;
  2557. while (current!=null) {
  2558. if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  2559. return (IContainerControl)current;
  2560. }
  2561. current = current.parent;
  2562. }
  2563. return null;
  2564. }
  2565. public Control GetNextControl(Control ctl, bool forward) {
  2566. if (!this.Contains(ctl)) {
  2567. ctl = this;
  2568. }
  2569. if (forward) {
  2570. ctl = FindControlForward(this, ctl);
  2571. }
  2572. else {
  2573. ctl = FindControlBackward(this, ctl);
  2574. }
  2575. if (ctl != this) {
  2576. return ctl;
  2577. }
  2578. return null;
  2579. }
  2580. #if NET_2_0
  2581. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2582. public virtual Size GetPreferredSize (Size proposedSize) {
  2583. return preferred_size;
  2584. }
  2585. #endif
  2586. public void Hide() {
  2587. this.Visible = false;
  2588. }
  2589. public void Invalidate() {
  2590. Invalidate(ClientRectangle, false);
  2591. }
  2592. public void Invalidate(bool invalidateChildren) {
  2593. Invalidate(ClientRectangle, invalidateChildren);
  2594. }
  2595. public void Invalidate(System.Drawing.Rectangle rc) {
  2596. Invalidate(rc, false);
  2597. }
  2598. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  2599. if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
  2600. return;
  2601. }
  2602. NotifyInvalidate(rc);
  2603. XplatUI.Invalidate(Handle, rc, false);
  2604. if (invalidateChildren) {
  2605. Control [] controls = child_controls.GetAllControls ();
  2606. for (int i=0; i<controls.Length; i++)
  2607. controls [i].Invalidate ();
  2608. }
  2609. OnInvalidated(new InvalidateEventArgs(rc));
  2610. }
  2611. public void Invalidate(System.Drawing.Region region) {
  2612. Invalidate(region, false);
  2613. }
  2614. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  2615. RectangleF bounds = region.GetBounds (CreateGraphics ());
  2616. Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
  2617. invalidateChildren);
  2618. }
  2619. public object Invoke (Delegate method) {
  2620. object [] prms = null;
  2621. if (method is EventHandler)
  2622. prms = new object [] { this, EventArgs.Empty };
  2623. return Invoke(method, prms);
  2624. }
  2625. public object Invoke (Delegate method, object[] args) {
  2626. if (!this.InvokeRequired) {
  2627. return method.DynamicInvoke(args);
  2628. }
  2629. IAsyncResult result = BeginInvoke (method, args);
  2630. return EndInvoke(result);
  2631. }
  2632. internal object InvokeInternal (Delegate method, bool disposing) {
  2633. return InvokeInternal(method, null, disposing);
  2634. }
  2635. internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
  2636. if (!this.InvokeRequired) {
  2637. return method.DynamicInvoke(args);
  2638. }
  2639. IAsyncResult result = BeginInvokeInternal (method, args, disposing);
  2640. return EndInvoke(result);
  2641. }
  2642. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2643. public void PerformLayout() {
  2644. PerformLayout(null, null);
  2645. }
  2646. internal void SetImplicitBounds (int x, int y, int width, int height)
  2647. {
  2648. Rectangle saved_bounds = explicit_bounds;
  2649. SetBounds (x, y, width, height);
  2650. explicit_bounds = saved_bounds;
  2651. }
  2652. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2653. public void PerformLayout(Control affectedControl, string affectedProperty) {
  2654. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  2655. if (layout_suspended > 0) {
  2656. layout_pending = true;
  2657. return;
  2658. }
  2659. layout_pending = false;
  2660. // Prevent us from getting messed up
  2661. layout_suspended++;
  2662. // Perform all Dock and Anchor calculations
  2663. try {
  2664. layout_engine.Layout(this, levent);
  2665. // Let everyone know
  2666. OnLayout(levent);
  2667. }
  2668. // Need to make sure we decremend layout_suspended
  2669. finally {
  2670. layout_suspended--;
  2671. }
  2672. }
  2673. public Point PointToClient (Point p) {
  2674. int x = p.X;
  2675. int y = p.Y;
  2676. XplatUI.ScreenToClient (Handle, ref x, ref y);
  2677. return new Point (x, y);
  2678. }
  2679. public Point PointToScreen(Point p) {
  2680. int x = p.X;
  2681. int y = p.Y;
  2682. XplatUI.ClientToScreen(Handle, ref x, ref y);
  2683. return new Point(x, y);
  2684. }
  2685. public virtual bool PreProcessMessage(ref Message msg) {
  2686. return InternalPreProcessMessage (ref msg);
  2687. }
  2688. internal virtual bool InternalPreProcessMessage (ref Message msg) {
  2689. Keys key_data;
  2690. if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
  2691. key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
  2692. if (!ProcessCmdKey(ref msg, key_data)) {
  2693. if (IsInputKey(key_data)) {
  2694. return false;
  2695. }
  2696. return ProcessDialogKey(key_data);
  2697. }
  2698. return true;
  2699. } else if (msg.Msg == (int)Msg.WM_CHAR) {
  2700. if (IsInputChar((char)msg.WParam)) {
  2701. return false;
  2702. }
  2703. return ProcessDialogChar((char)msg.WParam);
  2704. } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
  2705. return ProcessDialogChar((char)msg.WParam);
  2706. }
  2707. return false;
  2708. }
  2709. public Rectangle RectangleToClient(Rectangle r) {
  2710. return new Rectangle(PointToClient(r.Location), r.Size);
  2711. }
  2712. public Rectangle RectangleToScreen(Rectangle r) {
  2713. return new Rectangle(PointToScreen(r.Location), r.Size);
  2714. }
  2715. public virtual void Refresh() {
  2716. if (IsHandleCreated == true) {
  2717. Invalidate();
  2718. XplatUI.UpdateWindow(window.Handle);
  2719. Control [] controls = child_controls.GetAllControls ();
  2720. for (int i=0; i < controls.Length; i++) {
  2721. controls[i].Refresh();
  2722. }
  2723. }
  2724. }
  2725. [EditorBrowsable(EditorBrowsableState.Never)]
  2726. public virtual void ResetBackColor() {
  2727. BackColor = Color.Empty;
  2728. }
  2729. [EditorBrowsable(EditorBrowsableState.Never)]
  2730. public void ResetBindings() {
  2731. data_bindings.Clear();
  2732. }
  2733. [EditorBrowsable(EditorBrowsableState.Never)]
  2734. public virtual void ResetCursor() {
  2735. Cursor = null;
  2736. }
  2737. [EditorBrowsable(EditorBrowsableState.Never)]
  2738. public virtual void ResetFont() {
  2739. font = null;
  2740. }
  2741. [EditorBrowsable(EditorBrowsableState.Never)]
  2742. public virtual void ResetForeColor() {
  2743. foreground_color = Color.Empty;
  2744. }
  2745. [EditorBrowsable(EditorBrowsableState.Never)]
  2746. public void ResetImeMode() {
  2747. ime_mode = DefaultImeMode;
  2748. }
  2749. [EditorBrowsable(EditorBrowsableState.Never)]
  2750. public virtual void ResetRightToLeft() {
  2751. right_to_left = RightToLeft.Inherit;
  2752. }
  2753. public virtual void ResetText() {
  2754. text = String.Empty;
  2755. }
  2756. public void ResumeLayout() {
  2757. ResumeLayout (true);
  2758. }
  2759. public void ResumeLayout(bool performLayout) {
  2760. if (layout_suspended > 0) {
  2761. layout_suspended--;
  2762. }
  2763. if (layout_suspended == 0) {
  2764. Control [] controls = child_controls.GetAllControls ();
  2765. if (performLayout && layout_pending) {
  2766. PerformLayout();
  2767. }
  2768. }
  2769. }
  2770. #if NET_2_0
  2771. [EditorBrowsable (EditorBrowsableState.Never)]
  2772. [Obsolete ()]
  2773. #endif
  2774. public void Scale(float ratio) {
  2775. ScaleCore(ratio, ratio);
  2776. }
  2777. #if NET_2_0
  2778. [EditorBrowsable (EditorBrowsableState.Never)]
  2779. [Obsolete ()]
  2780. #endif
  2781. public void Scale(float dx, float dy) {
  2782. ScaleCore(dx, dy);
  2783. }
  2784. #if NET_2_0
  2785. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2786. public void Scale(SizeF factor) {
  2787. ScaleCore(factor.Width, factor.Height);
  2788. }
  2789. #endif
  2790. public void Select() {
  2791. if (this is ContainerControl)
  2792. ContainerSelected = true;
  2793. else {
  2794. Control c = this.Parent;
  2795. while (c != null) {
  2796. c.ContainerSelected = false;
  2797. c = c.Parent;
  2798. }
  2799. }
  2800. Select(false, false);
  2801. }
  2802. #if DebugFocus
  2803. private void printTree(Control c, string t) {
  2804. foreach(Control i in c.child_controls) {
  2805. Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
  2806. printTree(i, t+"\t");
  2807. }
  2808. }
  2809. #endif
  2810. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  2811. Control c;
  2812. #if DebugFocus
  2813. Console.WriteLine("{0}", this.FindForm());
  2814. printTree(this, "\t");
  2815. #endif
  2816. if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
  2817. ctl = null;
  2818. }
  2819. c = ctl;
  2820. do {
  2821. c = GetNextControl(c, forward);
  2822. if (c == null) {
  2823. if (wrap) {
  2824. wrap = false;
  2825. continue;
  2826. }
  2827. break;
  2828. }
  2829. if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
  2830. c.Select (true, true);
  2831. return true;
  2832. }
  2833. } while (c != ctl); // If we wrap back to ourselves we stop
  2834. return false;
  2835. }
  2836. public void SendToBack() {
  2837. if (parent != null) {
  2838. parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
  2839. }
  2840. }
  2841. public void SetBounds(int x, int y, int width, int height) {
  2842. SetBounds(x, y, width, height, BoundsSpecified.All);
  2843. }
  2844. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  2845. if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
  2846. x = Left;
  2847. }
  2848. if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  2849. y = Top;
  2850. }
  2851. if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
  2852. width = Width;
  2853. }
  2854. if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  2855. height = Height;
  2856. }
  2857. SetBoundsCore(x, y, width, height, specified);
  2858. if (parent != null) {
  2859. parent.PerformLayout(this, "Bounds");
  2860. }
  2861. }
  2862. public void Show() {
  2863. if (!is_created) {
  2864. this.CreateControl();
  2865. }
  2866. this.Visible=true;
  2867. }
  2868. public void SuspendLayout() {
  2869. layout_suspended++;
  2870. }
  2871. public void Update() {
  2872. if (IsHandleCreated) {
  2873. XplatUI.UpdateWindow(window.Handle);
  2874. }
  2875. }
  2876. #endregion // Public Instance Methods
  2877. #region Protected Instance Methods
  2878. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2879. [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
  2880. protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
  2881. throw new NotImplementedException();
  2882. }
  2883. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2884. protected virtual AccessibleObject CreateAccessibilityInstance() {
  2885. return new Control.ControlAccessibleObject(this);
  2886. }
  2887. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2888. protected virtual ControlCollection CreateControlsInstance() {
  2889. return new ControlCollection(this);
  2890. }
  2891. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2892. protected virtual void CreateHandle() {
  2893. if (IsDisposed) {
  2894. throw new ObjectDisposedException(GetType().FullName.ToString());
  2895. }
  2896. if (IsHandleCreated && !is_recreating) {
  2897. return;
  2898. }
  2899. window.CreateHandle(CreateParams);
  2900. if (window.Handle != IntPtr.Zero) {
  2901. creator_thread = Thread.CurrentThread;
  2902. XplatUI.EnableWindow(window.Handle, is_enabled);
  2903. XplatUI.SetVisible(window.Handle, is_visible, true);
  2904. if (clip_region != null) {
  2905. XplatUI.SetClipRegion(Handle, clip_region);
  2906. }
  2907. // Set our handle with our parent
  2908. if ((parent != null) && (parent.IsHandleCreated)) {
  2909. XplatUI.SetParent(window.Handle, parent.Handle);
  2910. }
  2911. // Set our handle as parent for our children
  2912. Control [] children;
  2913. children = child_controls.GetAllControls ();
  2914. for (int i = 0; i < children.Length; i++ ) {
  2915. if (!children[i].RecreatingHandle)
  2916. XplatUI.SetParent(children[i].Handle, window.Handle);
  2917. }
  2918. UpdateStyles();
  2919. XplatUI.SetAllowDrop (Handle, allow_drop);
  2920. // Find out where the window manager placed us
  2921. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
  2922. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  2923. }
  2924. UpdateBounds();
  2925. OnHandleCreated(EventArgs.Empty);
  2926. }
  2927. }
  2928. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2929. protected virtual void DefWndProc(ref Message m) {
  2930. window.DefWndProc(ref m);
  2931. }
  2932. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2933. protected virtual void DestroyHandle() {
  2934. if (IsHandleCreated) {
  2935. if (window != null) {
  2936. window.DestroyHandle();
  2937. }
  2938. }
  2939. }
  2940. #if NET_2_0
  2941. protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
  2942. {
  2943. throw new NotImplementedException ();
  2944. }
  2945. #endif
  2946. protected internal bool GetStyle(ControlStyles flag) {
  2947. return (control_style & flag) != 0;
  2948. }
  2949. protected bool GetTopLevel() {
  2950. return is_toplevel;
  2951. }
  2952. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2953. protected virtual void InitLayout() {
  2954. UpdateDistances();
  2955. }
  2956. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2957. protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
  2958. toInvoke.OnGotFocus(e);
  2959. }
  2960. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2961. protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
  2962. toInvoke.OnLostFocus(e);
  2963. }
  2964. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2965. protected void InvokeOnClick(Control toInvoke, EventArgs e) {
  2966. toInvoke.OnClick(e);
  2967. }
  2968. protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
  2969. toInvoke.OnPaint(e);
  2970. }
  2971. protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
  2972. toInvoke.OnPaintBackground(e);
  2973. }
  2974. protected virtual bool IsInputChar (char charCode) {
  2975. return true;
  2976. }
  2977. protected virtual bool IsInputKey (Keys keyData) {
  2978. // Doc says this one calls IsInputChar; not sure what to do with that
  2979. return false;
  2980. }
  2981. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2982. protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
  2983. // override me?
  2984. }
  2985. protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
  2986. if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
  2987. return true;
  2988. }
  2989. if (parent != null) {
  2990. return parent.ProcessCmdKey(ref msg, keyData);
  2991. }
  2992. return false;
  2993. }
  2994. protected virtual bool ProcessDialogChar(char charCode) {
  2995. if (parent != null) {
  2996. return parent.ProcessDialogChar (charCode);
  2997. }
  2998. return false;
  2999. }
  3000. protected virtual bool ProcessDialogKey (Keys keyData) {
  3001. if (parent != null) {
  3002. return parent.ProcessDialogKey (keyData);
  3003. }
  3004. return false;
  3005. }
  3006. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  3007. {
  3008. KeyEventArgs key_event;
  3009. switch (msg.Msg) {
  3010. case (int)Msg.WM_SYSKEYDOWN:
  3011. case (int)Msg.WM_KEYDOWN: {
  3012. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  3013. OnKeyDown (key_event);
  3014. return key_event.Handled;
  3015. }
  3016. case (int)Msg.WM_SYSKEYUP:
  3017. case (int)Msg.WM_KEYUP: {
  3018. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  3019. OnKeyUp (key_event);
  3020. return key_event.Handled;
  3021. }
  3022. case (int)Msg.WM_SYSCHAR:
  3023. case (int)Msg.WM_CHAR: {
  3024. KeyPressEventArgs key_press_event;
  3025. key_press_event = new KeyPressEventArgs((char)msg.WParam);
  3026. OnKeyPress(key_press_event);
  3027. #if NET_2_0
  3028. msg.WParam = (IntPtr)key_press_event.KeyChar;
  3029. #endif
  3030. return key_press_event.Handled;
  3031. }
  3032. default: {
  3033. break;
  3034. }
  3035. }
  3036. return false;
  3037. }
  3038. protected internal virtual bool ProcessKeyMessage(ref Message msg) {
  3039. if (parent != null) {
  3040. if (parent.ProcessKeyPreview(ref msg)) {
  3041. return true;
  3042. }
  3043. }
  3044. return ProcessKeyEventArgs(ref msg);
  3045. }
  3046. protected virtual bool ProcessKeyPreview(ref Message msg) {
  3047. if (parent != null) {
  3048. return parent.ProcessKeyPreview(ref msg);
  3049. }
  3050. return false;
  3051. }
  3052. protected virtual bool ProcessMnemonic(char charCode) {
  3053. // override me
  3054. return false;
  3055. }
  3056. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3057. protected void RaiseDragEvent(object key, DragEventArgs e) {
  3058. // MS Internal
  3059. }
  3060. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3061. protected void RaiseKeyEvent(object key, KeyEventArgs e) {
  3062. // MS Internal
  3063. }
  3064. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3065. protected void RaiseMouseEvent(object key, MouseEventArgs e) {
  3066. // MS Internal
  3067. }
  3068. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3069. protected void RaisePaintEvent(object key, PaintEventArgs e) {
  3070. // MS Internal
  3071. }
  3072. private void SetIsRecreating ()
  3073. {
  3074. is_recreating=true;
  3075. foreach (Control c in Controls.GetAllControls()) {
  3076. c.SetIsRecreating ();
  3077. }
  3078. }
  3079. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3080. protected void RecreateHandle() {
  3081. #if DebugRecreate
  3082. Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
  3083. #endif
  3084. SetIsRecreating ();
  3085. if (IsHandleCreated) {
  3086. #if DebugRecreate
  3087. Console.WriteLine(" + handle is created, destroying it.");
  3088. #endif
  3089. DestroyHandle();
  3090. // WM_DESTROY will CreateHandle for us
  3091. } else {
  3092. #if DebugRecreate
  3093. Console.WriteLine(" + handle is not created, creating it.");
  3094. #endif
  3095. if (!is_created) {
  3096. CreateControl();
  3097. } else {
  3098. CreateHandle();
  3099. }
  3100. is_recreating = false;
  3101. #if DebugRecreate
  3102. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  3103. #endif
  3104. }
  3105. }
  3106. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3107. protected void ResetMouseEventArgs() {
  3108. // MS Internal
  3109. }
  3110. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3111. protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
  3112. if (right_to_left == RightToLeft.No) {
  3113. return align;
  3114. }
  3115. switch (align) {
  3116. case ContentAlignment.TopLeft: {
  3117. return ContentAlignment.TopRight;
  3118. }
  3119. case ContentAlignment.TopRight: {
  3120. return ContentAlignment.TopLeft;
  3121. }
  3122. case ContentAlignment.MiddleLeft: {
  3123. return ContentAlignment.MiddleRight;
  3124. }
  3125. case ContentAlignment.MiddleRight: {
  3126. return ContentAlignment.MiddleLeft;
  3127. }
  3128. case ContentAlignment.BottomLeft: {
  3129. return ContentAlignment.BottomRight;
  3130. }
  3131. case ContentAlignment.BottomRight: {
  3132. return ContentAlignment.BottomLeft;
  3133. }
  3134. default: {
  3135. // if it's center it doesn't change
  3136. return align;
  3137. }
  3138. }
  3139. }
  3140. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3141. protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
  3142. if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
  3143. return align;
  3144. }
  3145. if (align == HorizontalAlignment.Left) {
  3146. return HorizontalAlignment.Right;
  3147. }
  3148. // align must be HorizontalAlignment.Right
  3149. return HorizontalAlignment.Left;
  3150. }
  3151. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3152. protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
  3153. if (right_to_left == RightToLeft.No) {
  3154. return align;
  3155. }
  3156. if (align == LeftRightAlignment.Left) {
  3157. return LeftRightAlignment.Right;
  3158. }
  3159. // align must be LeftRightAlignment.Right;
  3160. return LeftRightAlignment.Left;
  3161. }
  3162. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3163. protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
  3164. return RtlTranslateAlignment(align);
  3165. }
  3166. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3167. protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
  3168. return RtlTranslateAlignment(align);
  3169. }
  3170. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3171. protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
  3172. return RtlTranslateAlignment(align);
  3173. }
  3174. #if NET_2_0
  3175. [EditorBrowsable (EditorBrowsableState.Never)]
  3176. #else
  3177. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3178. #endif
  3179. protected virtual void ScaleCore(float dx, float dy) {
  3180. Point location;
  3181. Size size;
  3182. SuspendLayout();
  3183. location = new Point((int)(Left * dx), (int)(Top * dy));
  3184. size = this.ClientSize;
  3185. if (!GetStyle(ControlStyles.FixedWidth)) {
  3186. size.Width = (int)(size.Width * dx);
  3187. }
  3188. if (!GetStyle(ControlStyles.FixedHeight)) {
  3189. size.Height = (int)(size.Height * dy);
  3190. }
  3191. SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
  3192. /* Now scale our children */
  3193. Control [] controls = child_controls.GetAllControls ();
  3194. for (int i=0; i < controls.Length; i++) {
  3195. controls[i].Scale(dx, dy);
  3196. }
  3197. ResumeLayout();
  3198. }
  3199. protected virtual void Select(bool directed, bool forward) {
  3200. IContainerControl container;
  3201. container = GetContainerControl();
  3202. if (container != null)
  3203. container.ActiveControl = this;
  3204. }
  3205. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3206. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  3207. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  3208. if (IsHandleCreated) {
  3209. XplatUI.SetWindowPos(Handle, x, y, width, height);
  3210. // Win32 automatically changes negative width/height to 0.
  3211. // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
  3212. // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
  3213. // size.
  3214. if (width < 0 || height < 0) {
  3215. int cw, ch, ix, iy;
  3216. XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
  3217. }
  3218. }
  3219. UpdateBounds(x, y, width, height);
  3220. UpdateDistances();
  3221. }
  3222. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3223. protected virtual void SetClientSizeCore(int x, int y) {
  3224. // Calculate the actual window size from the client size (it usually stays the same or grows)
  3225. Rectangle ClientRect;
  3226. Rectangle WindowRect;
  3227. CreateParams cp;
  3228. ClientRect = new Rectangle(0, 0, x, y);
  3229. cp = this.CreateParams;
  3230. if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
  3231. return;
  3232. }
  3233. SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  3234. }
  3235. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3236. protected internal void SetStyle(ControlStyles flag, bool value) {
  3237. if (value) {
  3238. control_style |= flag;
  3239. } else {
  3240. control_style &= ~flag;
  3241. }
  3242. }
  3243. protected void SetTopLevel(bool value) {
  3244. if ((GetTopLevel() != value) && (parent != null)) {
  3245. throw new Exception();
  3246. }
  3247. if (this is Form) {
  3248. if (value == true) {
  3249. if (!Visible) {
  3250. Visible = true;
  3251. }
  3252. } else {
  3253. if (Visible) {
  3254. Visible = false;
  3255. }
  3256. }
  3257. }
  3258. is_toplevel = value;
  3259. }
  3260. protected virtual void SetVisibleCore(bool value) {
  3261. if (value!=is_visible) {
  3262. if (value && (window.Handle == IntPtr.Zero) || !is_created) {
  3263. CreateControl();
  3264. }
  3265. is_visible=value;
  3266. if (IsHandleCreated) {
  3267. XplatUI.SetVisible(Handle, value, true);
  3268. // Explicitly move Toplevel windows to where we want them;
  3269. // apparently moving unmapped toplevel windows doesn't work
  3270. if (is_visible && (this is Form)) {
  3271. XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
  3272. }
  3273. }
  3274. OnVisibleChanged(EventArgs.Empty);
  3275. if (value == false && parent != null && Focused) {
  3276. Control container;
  3277. // Need to start at parent, GetContainerControl might return ourselves if we're a container
  3278. container = (Control)parent.GetContainerControl();
  3279. if (container != null) {
  3280. container.SelectNextControl(this, true, true, true, true);
  3281. }
  3282. }
  3283. if (parent != null) {
  3284. parent.PerformLayout(this, "visible");
  3285. } else {
  3286. PerformLayout(this, "visible");
  3287. }
  3288. }
  3289. }
  3290. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3291. protected void UpdateBounds() {
  3292. int x;
  3293. int y;
  3294. int width;
  3295. int height;
  3296. int client_width;
  3297. int client_height;
  3298. if (!IsHandleCreated) {
  3299. CreateHandle();
  3300. }
  3301. XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
  3302. UpdateBounds(x, y, width, height, client_width, client_height);
  3303. }
  3304. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3305. protected void UpdateBounds(int x, int y, int width, int height) {
  3306. CreateParams cp;
  3307. Rectangle rect;
  3308. // Calculate client rectangle
  3309. rect = new Rectangle(0, 0, 0, 0);
  3310. cp = CreateParams;
  3311. XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
  3312. UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
  3313. }
  3314. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3315. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  3316. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  3317. bool moved = false;
  3318. bool resized = false;
  3319. // Needed to generate required notifications
  3320. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  3321. moved=true;
  3322. }
  3323. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  3324. resized=true;
  3325. }
  3326. bounds.X=x;
  3327. bounds.Y=y;
  3328. bounds.Width=width;
  3329. bounds.Height=height;
  3330. // Assume explicit bounds set. SetImplicitBounds will restore old bounds
  3331. explicit_bounds = bounds;
  3332. client_size.Width=clientWidth;
  3333. client_size.Height=clientHeight;
  3334. if (moved) {
  3335. OnLocationChanged(EventArgs.Empty);
  3336. }
  3337. if (resized) {
  3338. OnSizeChanged(EventArgs.Empty);
  3339. }
  3340. }
  3341. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3342. protected void UpdateStyles() {
  3343. if (!IsHandleCreated) {
  3344. return;
  3345. }
  3346. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  3347. OnStyleChanged(EventArgs.Empty);
  3348. }
  3349. private void UpdateZOrderOfChild(Control child) {
  3350. if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
  3351. int index;
  3352. index = child_controls.IndexOf(child);
  3353. if (index > 0) {
  3354. XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
  3355. } else {
  3356. IntPtr after = AfterTopMostControl ();
  3357. if (after != IntPtr.Zero)
  3358. XplatUI.SetZOrder (child.Handle, after, false, false);
  3359. else
  3360. XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
  3361. }
  3362. }
  3363. }
  3364. // Override this if there is a control that shall always remain on
  3365. // top of other controls (such as scrollbars). If there are several
  3366. // of these controls, the bottom-most should be returned.
  3367. internal virtual IntPtr AfterTopMostControl ()
  3368. {
  3369. return IntPtr.Zero;
  3370. }
  3371. private void UpdateChildrenZOrder() {
  3372. Control [] controls;
  3373. if (!IsHandleCreated) {
  3374. return;
  3375. }
  3376. controls = child_controls.GetAllControls ();
  3377. for (int i = 1; i < controls.Length; i++ ) {
  3378. XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
  3379. }
  3380. }
  3381. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3382. protected void UpdateZOrder() {
  3383. if (parent != null) {
  3384. parent.UpdateZOrderOfChild(this);
  3385. }
  3386. }
  3387. protected virtual void WndProc(ref Message m) {
  3388. #if debug
  3389. Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
  3390. #endif
  3391. if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
  3392. OnNotifyMessage(m);
  3393. }
  3394. switch((Msg)m.Msg) {
  3395. case Msg.WM_DESTROY: {
  3396. OnHandleDestroyed(EventArgs.Empty);
  3397. #if DebugRecreate
  3398. IntPtr handle = window.Handle;
  3399. #endif
  3400. window.InvalidateHandle();
  3401. if (is_recreating) {
  3402. #if DebugRecreate
  3403. Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
  3404. #endif
  3405. CreateHandle();
  3406. #if DebugRecreate
  3407. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  3408. #endif
  3409. is_recreating = false;
  3410. }
  3411. return;
  3412. }
  3413. case Msg.WM_WINDOWPOSCHANGED: {
  3414. if (Visible) {
  3415. Rectangle save_bounds = explicit_bounds;
  3416. UpdateBounds();
  3417. explicit_bounds = save_bounds;
  3418. if (GetStyle(ControlStyles.ResizeRedraw)) {
  3419. Invalidate();
  3420. }
  3421. }
  3422. return;
  3423. }
  3424. // Nice description of what should happen when handling WM_PAINT
  3425. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  3426. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  3427. case Msg.WM_PAINT: {
  3428. PaintEventArgs paint_event;
  3429. paint_event = XplatUI.PaintEventStart(Handle, true);
  3430. if (paint_event == null) {
  3431. return;
  3432. }
  3433. if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
  3434. // Just blit the previous image
  3435. XplatUI.BlitFromOffscreen (Handle, paint_event.Graphics, backbuffer, backbuffer_dc, paint_event.ClipRectangle);
  3436. XplatUI.PaintEventEnd (Handle, true);
  3437. return;
  3438. }
  3439. Graphics dc = null;
  3440. Graphics back_dc = null;
  3441. object back = null;
  3442. if (ThemeEngine.Current.DoubleBufferingSupported) {
  3443. if ((control_style & ControlStyles.DoubleBuffer) != 0) {
  3444. CreateBackBuffer ();
  3445. back = backbuffer;
  3446. back_dc = backbuffer_dc;
  3447. dc = paint_event.SetGraphics (back_dc);
  3448. }
  3449. }
  3450. if (!GetStyle(ControlStyles.Opaque)) {
  3451. OnPaintBackground(paint_event);
  3452. }
  3453. // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
  3454. OnPaintBackgroundInternal(paint_event);
  3455. OnPaintInternal(paint_event);
  3456. if (!paint_event.Handled) {
  3457. OnPaint(paint_event);
  3458. }
  3459. if (ThemeEngine.Current.DoubleBufferingSupported)
  3460. if ((control_style & ControlStyles.DoubleBuffer) != 0) {
  3461. XplatUI.BlitFromOffscreen (Handle, dc, back, back_dc, paint_event.ClipRectangle);
  3462. paint_event.SetGraphics (dc);
  3463. invalid_region.Exclude (paint_event.ClipRectangle);
  3464. if (back != backbuffer)
  3465. XplatUI.DestroyOffscreenDrawable (back, back_dc);
  3466. }
  3467. XplatUI.PaintEventEnd(Handle, true);
  3468. return;
  3469. }
  3470. case Msg.WM_ERASEBKGND: {
  3471. // The DefWndProc will never have to handle this, we always paint the background in managed code
  3472. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  3473. // here but it just makes things more complicated...
  3474. m.Result = (IntPtr)1;
  3475. return;
  3476. }
  3477. case Msg.WM_LBUTTONUP: {
  3478. MouseEventArgs me;
  3479. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  3480. mouse_clicks,
  3481. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3482. 0);
  3483. HandleClick(mouse_clicks, me);
  3484. OnMouseUp (me);
  3485. if (InternalCapture) {
  3486. InternalCapture = false;
  3487. }
  3488. if (mouse_clicks > 1) {
  3489. mouse_clicks = 1;
  3490. }
  3491. return;
  3492. }
  3493. case Msg.WM_LBUTTONDOWN: {
  3494. if (CanSelect) {
  3495. Select (true, true);
  3496. }
  3497. InternalCapture = true;
  3498. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3499. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3500. 0));
  3501. return;
  3502. }
  3503. case Msg.WM_LBUTTONDBLCLK: {
  3504. InternalCapture = true;
  3505. mouse_clicks++;
  3506. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3507. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3508. 0));
  3509. return;
  3510. }
  3511. case Msg.WM_MBUTTONUP: {
  3512. MouseEventArgs me;
  3513. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
  3514. mouse_clicks,
  3515. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3516. 0);
  3517. HandleClick(mouse_clicks, me);
  3518. OnMouseUp (me);
  3519. if (InternalCapture) {
  3520. InternalCapture = false;
  3521. }
  3522. if (mouse_clicks > 1) {
  3523. mouse_clicks = 1;
  3524. }
  3525. return;
  3526. }
  3527. case Msg.WM_MBUTTONDOWN: {
  3528. InternalCapture = true;
  3529. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3530. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3531. 0));
  3532. return;
  3533. }
  3534. case Msg.WM_MBUTTONDBLCLK: {
  3535. InternalCapture = true;
  3536. mouse_clicks++;
  3537. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3538. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3539. 0));
  3540. return;
  3541. }
  3542. case Msg.WM_RBUTTONUP: {
  3543. MouseEventArgs me;
  3544. Point pt;
  3545. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  3546. pt = PointToScreen(pt);
  3547. XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
  3548. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
  3549. mouse_clicks,
  3550. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3551. 0);
  3552. HandleClick(mouse_clicks, me);
  3553. OnMouseUp (me);
  3554. if (InternalCapture) {
  3555. InternalCapture = false;
  3556. }
  3557. if (mouse_clicks > 1) {
  3558. mouse_clicks = 1;
  3559. }
  3560. return;
  3561. }
  3562. case Msg.WM_RBUTTONDOWN: {
  3563. InternalCapture = true;
  3564. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3565. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3566. 0));
  3567. return;
  3568. }
  3569. case Msg.WM_RBUTTONDBLCLK: {
  3570. InternalCapture = true;
  3571. mouse_clicks++;
  3572. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3573. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3574. 0));
  3575. return;
  3576. }
  3577. case Msg.WM_CONTEXTMENU: {
  3578. if (context_menu != null) {
  3579. Point pt;
  3580. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  3581. if (pt.X == -1 || pt.Y == -1) {
  3582. pt.X = (this.Width / 2) + this.Left;
  3583. pt.Y = (this.Height / 2) + this.Top;
  3584. pt = this.PointToScreen (pt);
  3585. }
  3586. context_menu.Show (this, PointToClient (pt));
  3587. return;
  3588. }
  3589. #if NET_2_0
  3590. // If there isn't a regular context menu, show the Strip version
  3591. if (context_menu == null && context_menu_strip != null) {
  3592. Point pt;
  3593. pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
  3594. if (pt.X == -1 || pt.Y == -1) {
  3595. pt.X = (this.Width / 2) + this.Left;
  3596. pt.Y = (this.Height /2) + this.Top;
  3597. pt = this.PointToScreen (pt);
  3598. }
  3599. context_menu_strip.Show (this, PointToClient (pt));
  3600. return;
  3601. }
  3602. #endif
  3603. DefWndProc(ref m);
  3604. return;
  3605. }
  3606. case Msg.WM_MOUSEWHEEL: {
  3607. DefWndProc(ref m);
  3608. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3609. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3610. HighOrder(m.WParam.ToInt32())));
  3611. return;
  3612. }
  3613. case Msg.WM_MOUSEMOVE: {
  3614. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  3615. mouse_clicks,
  3616. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  3617. 0));
  3618. return;
  3619. }
  3620. case Msg.WM_MOUSE_ENTER: {
  3621. if (is_entered) {
  3622. return;
  3623. }
  3624. is_entered = true;
  3625. OnMouseEnter(EventArgs.Empty);
  3626. return;
  3627. }
  3628. case Msg.WM_MOUSE_LEAVE: {
  3629. is_entered=false;
  3630. OnMouseLeave(EventArgs.Empty);
  3631. return;
  3632. }
  3633. case Msg.WM_MOUSEHOVER: {
  3634. OnMouseHover(EventArgs.Empty);
  3635. return;
  3636. }
  3637. case Msg.WM_SYSKEYUP: {
  3638. if (ProcessKeyMessage(ref m)) {
  3639. m.Result = IntPtr.Zero;
  3640. return;
  3641. }
  3642. if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
  3643. Form form;
  3644. form = FindForm();
  3645. if (form != null && form.ActiveMenu != null) {
  3646. form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
  3647. }
  3648. }
  3649. DefWndProc (ref m);
  3650. return;
  3651. }
  3652. case Msg.WM_SYSKEYDOWN:
  3653. case Msg.WM_KEYDOWN:
  3654. case Msg.WM_KEYUP:
  3655. case Msg.WM_SYSCHAR:
  3656. case Msg.WM_CHAR: {
  3657. if (ProcessKeyMessage(ref m)) {
  3658. m.Result = IntPtr.Zero;
  3659. return;
  3660. }
  3661. DefWndProc (ref m);
  3662. return;
  3663. }
  3664. case Msg.WM_HELP: {
  3665. Point mouse_pos;
  3666. if (m.LParam != IntPtr.Zero) {
  3667. HELPINFO hi;
  3668. hi = new HELPINFO();
  3669. hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
  3670. mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
  3671. } else {
  3672. mouse_pos = Control.MousePosition;
  3673. }
  3674. OnHelpRequested(new HelpEventArgs(mouse_pos));
  3675. m.Result = (IntPtr)1;
  3676. return;
  3677. }
  3678. case Msg.WM_KILLFOCUS: {
  3679. this.has_focus = false;
  3680. OnLostFocusInternal (EventArgs.Empty);
  3681. return;
  3682. }
  3683. case Msg.WM_SETFOCUS: {
  3684. if (!has_focus) {
  3685. this.has_focus = true;
  3686. if (this.Parent != null && this.Parent.ContainerSelected)
  3687. return;
  3688. OnGotFocusInternal (EventArgs.Empty);
  3689. }
  3690. return;
  3691. }
  3692. case Msg.WM_SYSCOLORCHANGE: {
  3693. ThemeEngine.Current.ResetDefaults();
  3694. OnSystemColorsChanged(EventArgs.Empty);
  3695. return;
  3696. }
  3697. case Msg.WM_SETCURSOR: {
  3698. if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
  3699. DefWndProc(ref m);
  3700. return;
  3701. }
  3702. XplatUI.SetCursor(window.Handle, cursor.handle);
  3703. m.Result = (IntPtr)1;
  3704. return;
  3705. }
  3706. default:
  3707. DefWndProc(ref m);
  3708. return;
  3709. }
  3710. }
  3711. #endregion // Public Instance Methods
  3712. #region OnXXX methods
  3713. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3714. protected virtual void OnBackColorChanged(EventArgs e) {
  3715. EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
  3716. if (eh != null)
  3717. eh (this, e);
  3718. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  3719. }
  3720. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3721. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  3722. EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
  3723. if (eh != null)
  3724. eh (this, e);
  3725. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  3726. }
  3727. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3728. protected virtual void OnBindingContextChanged(EventArgs e) {
  3729. CheckDataBindings ();
  3730. EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
  3731. if (eh != null)
  3732. eh (this, e);
  3733. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  3734. }
  3735. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3736. protected virtual void OnCausesValidationChanged(EventArgs e) {
  3737. EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
  3738. if (eh != null)
  3739. eh (this, e);
  3740. }
  3741. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3742. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  3743. UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
  3744. if (eh != null)
  3745. eh (this, e);
  3746. }
  3747. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3748. protected virtual void OnClick(EventArgs e) {
  3749. EventHandler eh = (EventHandler)(Events [ClickEvent]);
  3750. if (eh != null)
  3751. eh (this, e);
  3752. }
  3753. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3754. protected virtual void OnContextMenuChanged(EventArgs e) {
  3755. EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
  3756. if (eh != null)
  3757. eh (this, e);
  3758. }
  3759. #if NET_2_0
  3760. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3761. protected virtual void OnContextMenuStripChanged (EventArgs e) {
  3762. EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
  3763. if (eh != null)
  3764. eh (this, e);
  3765. }
  3766. #endif
  3767. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3768. protected virtual void OnControlAdded(ControlEventArgs e) {
  3769. ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
  3770. if (eh != null)
  3771. eh (this, e);
  3772. }
  3773. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3774. protected virtual void OnControlRemoved(ControlEventArgs e) {
  3775. ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
  3776. if (eh != null)
  3777. eh (this, e);
  3778. }
  3779. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3780. protected virtual void OnCreateControl() {
  3781. // Override me!
  3782. }
  3783. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3784. protected virtual void OnCursorChanged(EventArgs e) {
  3785. EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
  3786. if (eh != null)
  3787. eh (this, e);
  3788. }
  3789. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3790. protected virtual void OnDockChanged(EventArgs e) {
  3791. EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
  3792. if (eh != null)
  3793. eh (this, e);
  3794. }
  3795. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3796. protected virtual void OnDoubleClick(EventArgs e) {
  3797. EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
  3798. if (eh != null)
  3799. eh (this, e);
  3800. }
  3801. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3802. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  3803. DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
  3804. if (eh != null)
  3805. eh (this, drgevent);
  3806. }
  3807. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3808. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  3809. DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
  3810. if (eh != null)
  3811. eh (this, drgevent);
  3812. }
  3813. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3814. protected virtual void OnDragLeave(EventArgs e) {
  3815. EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
  3816. if (eh != null)
  3817. eh (this, e);
  3818. }
  3819. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3820. protected virtual void OnDragOver(DragEventArgs drgevent) {
  3821. DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
  3822. if (eh != null)
  3823. eh (this, drgevent);
  3824. }
  3825. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3826. protected virtual void OnEnabledChanged(EventArgs e) {
  3827. if (IsHandleCreated) {
  3828. if (this is Form) {
  3829. if (((Form)this).context == null) {
  3830. XplatUI.EnableWindow(window.Handle, Enabled);
  3831. }
  3832. } else {
  3833. XplatUI.EnableWindow(window.Handle, Enabled);
  3834. }
  3835. Refresh();
  3836. }
  3837. EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
  3838. if (eh != null)
  3839. eh (this, e);
  3840. for (int i=0; i<child_controls.Count; i++) {
  3841. child_controls[i].OnParentEnabledChanged(e);
  3842. }
  3843. }
  3844. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3845. protected virtual void OnEnter(EventArgs e) {
  3846. EventHandler eh = (EventHandler)(Events [EnterEvent]);
  3847. if (eh != null)
  3848. eh (this, e);
  3849. }
  3850. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3851. protected virtual void OnFontChanged(EventArgs e) {
  3852. EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
  3853. if (eh != null)
  3854. eh (this, e);
  3855. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
  3856. }
  3857. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3858. protected virtual void OnForeColorChanged(EventArgs e) {
  3859. EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
  3860. if (eh != null)
  3861. eh (this, e);
  3862. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  3863. }
  3864. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3865. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  3866. GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
  3867. if (eh != null)
  3868. eh (this, gfbevent);
  3869. }
  3870. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3871. protected virtual void OnGotFocus(EventArgs e) {
  3872. EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
  3873. if (eh != null)
  3874. eh (this, e);
  3875. }
  3876. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3877. protected virtual void OnHandleCreated(EventArgs e) {
  3878. EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
  3879. if (eh != null)
  3880. eh (this, e);
  3881. }
  3882. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3883. protected virtual void OnHandleDestroyed(EventArgs e) {
  3884. EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
  3885. if (eh != null)
  3886. eh (this, e);
  3887. }
  3888. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3889. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  3890. HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
  3891. if (eh != null)
  3892. eh (this, hevent);
  3893. }
  3894. protected virtual void OnImeModeChanged(EventArgs e) {
  3895. EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
  3896. if (eh != null)
  3897. eh (this, e);
  3898. }
  3899. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3900. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  3901. if (ThemeEngine.Current.DoubleBufferingSupported)
  3902. if ((control_style & ControlStyles.DoubleBuffer) != 0) {
  3903. // should this block be here? seems like it
  3904. // would be more at home in
  3905. // NotifyInvalidated..
  3906. if (e.InvalidRect == ClientRectangle) {
  3907. InvalidateBackBuffer ();
  3908. }
  3909. else {
  3910. // we need this Inflate call here so
  3911. // that the border of the rectangle is
  3912. // considered Visible (the
  3913. // invalid_region.IsVisible call) in
  3914. // the WM_PAINT handling below.
  3915. Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
  3916. if (invalid_region == null)
  3917. invalid_region = new Region (r);
  3918. else
  3919. invalid_region.Union (r);
  3920. }
  3921. }
  3922. InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
  3923. if (eh != null)
  3924. eh (this, e);
  3925. }
  3926. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3927. protected virtual void OnKeyDown(KeyEventArgs e) {
  3928. KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
  3929. if (eh != null)
  3930. eh (this, e);
  3931. }
  3932. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3933. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  3934. KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
  3935. if (eh != null)
  3936. eh (this, e);
  3937. }
  3938. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3939. protected virtual void OnKeyUp(KeyEventArgs e) {
  3940. KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
  3941. if (eh != null)
  3942. eh (this, e);
  3943. }
  3944. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3945. protected virtual void OnLayout(LayoutEventArgs levent) {
  3946. LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
  3947. if (eh != null)
  3948. eh (this, levent);
  3949. }
  3950. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3951. protected virtual void OnLeave(EventArgs e) {
  3952. EventHandler eh = (EventHandler)(Events [LeaveEvent]);
  3953. if (eh != null)
  3954. eh (this, e);
  3955. }
  3956. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3957. protected virtual void OnLocationChanged(EventArgs e) {
  3958. OnMove(e);
  3959. EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
  3960. if (eh != null)
  3961. eh (this, e);
  3962. }
  3963. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3964. protected virtual void OnLostFocus(EventArgs e) {
  3965. EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
  3966. if (eh != null)
  3967. eh (this, e);
  3968. }
  3969. #if NET_2_0
  3970. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3971. protected virtual void OnMouseCaptureChanged (EventArgs e)
  3972. {
  3973. EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
  3974. if (eh != null)
  3975. eh (this, e);
  3976. }
  3977. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3978. protected virtual void OnMouseClick (MouseEventArgs e)
  3979. {
  3980. MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
  3981. if (eh != null)
  3982. eh (this, e);
  3983. }
  3984. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3985. protected virtual void OnMouseDoubleClick (MouseEventArgs e)
  3986. {
  3987. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
  3988. if (eh != null)
  3989. eh (this, e);
  3990. }
  3991. #endif
  3992. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3993. protected virtual void OnMouseDown(MouseEventArgs e) {
  3994. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
  3995. if (eh != null)
  3996. eh (this, e);
  3997. }
  3998. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3999. protected virtual void OnMouseEnter(EventArgs e) {
  4000. EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
  4001. if (eh != null)
  4002. eh (this, e);
  4003. }
  4004. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4005. protected virtual void OnMouseHover(EventArgs e) {
  4006. EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
  4007. if (eh != null)
  4008. eh (this, e);
  4009. }
  4010. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4011. protected virtual void OnMouseLeave(EventArgs e) {
  4012. EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
  4013. if (eh != null)
  4014. eh (this, e);
  4015. }
  4016. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4017. protected virtual void OnMouseMove(MouseEventArgs e) {
  4018. MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
  4019. if (eh != null)
  4020. eh (this, e);
  4021. }
  4022. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4023. protected virtual void OnMouseUp(MouseEventArgs e) {
  4024. MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
  4025. if (eh != null)
  4026. eh (this, e);
  4027. }
  4028. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4029. protected virtual void OnMouseWheel(MouseEventArgs e) {
  4030. MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
  4031. if (eh != null)
  4032. eh (this, e);
  4033. }
  4034. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4035. protected virtual void OnMove(EventArgs e) {
  4036. EventHandler eh = (EventHandler)(Events [MoveEvent]);
  4037. if (eh != null)
  4038. eh (this, e);
  4039. }
  4040. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4041. protected virtual void OnNotifyMessage(Message m) {
  4042. // Override me!
  4043. }
  4044. #if NET_2_0
  4045. protected virtual void OnPaddingChanged (EventArgs e) {
  4046. EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
  4047. if (eh != null)
  4048. eh (this, e);
  4049. }
  4050. #endif
  4051. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4052. protected virtual void OnPaint(PaintEventArgs e) {
  4053. PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
  4054. if (eh != null)
  4055. eh (this, e);
  4056. }
  4057. internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
  4058. // Override me
  4059. }
  4060. internal virtual void OnPaintInternal(PaintEventArgs e) {
  4061. // Override me
  4062. }
  4063. internal virtual void OnGotFocusInternal (EventArgs e)
  4064. {
  4065. OnGotFocus (e);
  4066. }
  4067. internal virtual void OnLostFocusInternal (EventArgs e)
  4068. {
  4069. OnLostFocus (e);
  4070. }
  4071. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4072. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  4073. PaintControlBackground (pevent);
  4074. }
  4075. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4076. protected virtual void OnParentBackColorChanged(EventArgs e) {
  4077. if (background_color.IsEmpty && background_image==null) {
  4078. Invalidate();
  4079. OnBackColorChanged(e);
  4080. }
  4081. }
  4082. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4083. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  4084. if (background_color.IsEmpty && background_image==null) {
  4085. Invalidate();
  4086. OnBackgroundImageChanged(e);
  4087. }
  4088. }
  4089. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4090. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  4091. if (binding_context==null) {
  4092. binding_context=Parent.binding_context;
  4093. OnBindingContextChanged(e);
  4094. }
  4095. }
  4096. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4097. protected virtual void OnParentChanged(EventArgs e) {
  4098. EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
  4099. if (eh != null)
  4100. eh (this, e);
  4101. }
  4102. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4103. protected virtual void OnParentEnabledChanged(EventArgs e) {
  4104. if (is_enabled) {
  4105. OnEnabledChanged(e);
  4106. }
  4107. }
  4108. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4109. protected virtual void OnParentFontChanged(EventArgs e) {
  4110. if (font==null) {
  4111. Invalidate();
  4112. OnFontChanged(e);
  4113. }
  4114. }
  4115. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4116. protected virtual void OnParentForeColorChanged(EventArgs e) {
  4117. if (foreground_color.IsEmpty) {
  4118. Invalidate();
  4119. OnForeColorChanged(e);
  4120. }
  4121. }
  4122. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4123. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  4124. if (right_to_left==RightToLeft.Inherit) {
  4125. Invalidate();
  4126. OnRightToLeftChanged(e);
  4127. }
  4128. }
  4129. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4130. protected virtual void OnParentVisibleChanged(EventArgs e) {
  4131. if (is_visible) {
  4132. OnVisibleChanged(e);
  4133. }
  4134. }
  4135. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4136. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  4137. QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
  4138. if (eh != null)
  4139. eh (this, e);
  4140. }
  4141. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4142. protected virtual void OnResize(EventArgs e) {
  4143. EventHandler eh = (EventHandler)(Events [ResizeEvent]);
  4144. if (eh != null)
  4145. eh (this, e);
  4146. PerformLayout(this, "bounds");
  4147. if (parent != null) {
  4148. parent.PerformLayout();
  4149. }
  4150. }
  4151. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4152. protected virtual void OnRightToLeftChanged(EventArgs e) {
  4153. EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
  4154. if (eh != null)
  4155. eh (this, e);
  4156. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  4157. }
  4158. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4159. protected virtual void OnSizeChanged(EventArgs e) {
  4160. DisposeBackBuffer ();
  4161. OnResize(e);
  4162. EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
  4163. if (eh != null)
  4164. eh (this, e);
  4165. }
  4166. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4167. protected virtual void OnStyleChanged(EventArgs e) {
  4168. EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
  4169. if (eh != null)
  4170. eh (this, e);
  4171. }
  4172. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4173. protected virtual void OnSystemColorsChanged(EventArgs e) {
  4174. EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
  4175. if (eh != null)
  4176. eh (this, e);
  4177. }
  4178. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4179. protected virtual void OnTabIndexChanged(EventArgs e) {
  4180. EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
  4181. if (eh != null)
  4182. eh (this, e);
  4183. }
  4184. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4185. protected virtual void OnTabStopChanged(EventArgs e) {
  4186. EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
  4187. if (eh != null)
  4188. eh (this, e);
  4189. }
  4190. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4191. protected virtual void OnTextChanged(EventArgs e) {
  4192. EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
  4193. if (eh != null)
  4194. eh (this, e);
  4195. }
  4196. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4197. protected virtual void OnValidated(EventArgs e) {
  4198. EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
  4199. if (eh != null)
  4200. eh (this, e);
  4201. }
  4202. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4203. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  4204. CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
  4205. if (eh != null)
  4206. eh (this, e);
  4207. }
  4208. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4209. protected virtual void OnVisibleChanged(EventArgs e) {
  4210. if ((parent != null) && !Created && Visible) {
  4211. if (!is_disposed) {
  4212. CreateControl();
  4213. PerformLayout();
  4214. }
  4215. }
  4216. EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
  4217. if (eh != null)
  4218. eh (this, e);
  4219. // We need to tell our kids
  4220. for (int i=0; i<child_controls.Count; i++) {
  4221. if (child_controls[i].Visible) {
  4222. child_controls[i].OnParentVisibleChanged(e);
  4223. }
  4224. }
  4225. }
  4226. #endregion // OnXXX methods
  4227. #region Events
  4228. #if NET_2_0
  4229. static object AutoSizeChangedEvent = new object ();
  4230. #endif
  4231. static object BackColorChangedEvent = new object ();
  4232. static object BackgroundImageChangedEvent = new object ();
  4233. #if NET_2_0
  4234. static object BackgroundImageLayoutChangedEvent = new object ();
  4235. #endif
  4236. static object BindingContextChangedEvent = new object ();
  4237. static object CausesValidationChangedEvent = new object ();
  4238. static object ChangeUICuesEvent = new object ();
  4239. static object ClickEvent = new object ();
  4240. #if NET_2_0
  4241. static object ClientSizeChangedEvent = new object ();
  4242. #endif
  4243. static object ContextMenuChangedEvent = new object ();
  4244. #if NET_2_0
  4245. static object ContextMenuStripChangedEvent = new object ();
  4246. #endif
  4247. static object ControlAddedEvent = new object ();
  4248. static object ControlRemovedEvent = new object ();
  4249. static object CursorChangedEvent = new object ();
  4250. static object DockChangedEvent = new object ();
  4251. static object DoubleClickEvent = new object ();
  4252. static object DragDropEvent = new object ();
  4253. static object DragEnterEvent = new object ();
  4254. static object DragLeaveEvent = new object ();
  4255. static object DragOverEvent = new object ();
  4256. static object EnabledChangedEvent = new object ();
  4257. static object EnterEvent = new object ();
  4258. static object FontChangedEvent = new object ();
  4259. static object ForeColorChangedEvent = new object ();
  4260. static object GiveFeedbackEvent = new object ();
  4261. static object GotFocusEvent = new object ();
  4262. static object HandleCreatedEvent = new object ();
  4263. static object HandleDestroyedEvent = new object ();
  4264. static object HelpRequestedEvent = new object ();
  4265. static object ImeModeChangedEvent = new object ();
  4266. static object InvalidatedEvent = new object ();
  4267. static object KeyDownEvent = new object ();
  4268. static object KeyPressEvent = new object ();
  4269. static object KeyUpEvent = new object ();
  4270. static object LayoutEvent = new object ();
  4271. static object LeaveEvent = new object ();
  4272. static object LocationChangedEvent = new object ();
  4273. static object LostFocusEvent = new object ();
  4274. #if NET_2_0
  4275. static object MarginChangedEvent = new object ();
  4276. static object MouseCaptureChangedEvent = new object ();
  4277. static object MouseClickEvent = new object ();
  4278. static object MouseDoubleClickEvent = new object ();
  4279. #endif
  4280. static object MouseDownEvent = new object ();
  4281. static object MouseEnterEvent = new object ();
  4282. static object MouseHoverEvent = new object ();
  4283. static object MouseLeaveEvent = new object ();
  4284. static object MouseMoveEvent = new object ();
  4285. static object MouseUpEvent = new object ();
  4286. static object MouseWheelEvent = new object ();
  4287. static object MoveEvent = new object ();
  4288. #if NET_2_0
  4289. static object PaddingChangedEvent = new object ();
  4290. #endif
  4291. static object PaintEvent = new object ();
  4292. static object ParentChangedEvent = new object ();
  4293. #if NET_2_0
  4294. static object PreviewKeyDownEvent = new object ();
  4295. #endif
  4296. static object QueryAccessibilityHelpEvent = new object ();
  4297. static object QueryContinueDragEvent = new object ();
  4298. #if NET_2_0
  4299. static object RegionChangedEvent = new object ();
  4300. #endif
  4301. static object ResizeEvent = new object ();
  4302. static object RightToLeftChangedEvent = new object ();
  4303. static object SizeChangedEvent = new object ();
  4304. static object StyleChangedEvent = new object ();
  4305. static object SystemColorsChangedEvent = new object ();
  4306. static object TabIndexChangedEvent = new object ();
  4307. static object TabStopChangedEvent = new object ();
  4308. static object TextChangedEvent = new object ();
  4309. static object ValidatedEvent = new object ();
  4310. static object ValidatingEvent = new object ();
  4311. static object VisibleChangedEvent = new object ();
  4312. #if NET_2_0
  4313. public event EventHandler AutoSizeChanged {
  4314. add { Events.AddHandler (AutoSizeChangedEvent, value);}
  4315. remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
  4316. }
  4317. #endif
  4318. public event EventHandler BackColorChanged {
  4319. add { Events.AddHandler (BackColorChangedEvent, value); }
  4320. remove { Events.RemoveHandler (BackColorChangedEvent, value); }
  4321. }
  4322. public event EventHandler BackgroundImageChanged {
  4323. add { Events.AddHandler (BackgroundImageChangedEvent, value); }
  4324. remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
  4325. }
  4326. #if NET_2_0
  4327. public event EventHandler BackgroundImageLayoutChanged {
  4328. add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
  4329. remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
  4330. }
  4331. #endif
  4332. public event EventHandler BindingContextChanged {
  4333. add { Events.AddHandler (BindingContextChangedEvent, value); }
  4334. remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
  4335. }
  4336. public event EventHandler CausesValidationChanged {
  4337. add { Events.AddHandler (CausesValidationChangedEvent, value); }
  4338. remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
  4339. }
  4340. public event UICuesEventHandler ChangeUICues {
  4341. add { Events.AddHandler (ChangeUICuesEvent, value); }
  4342. remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
  4343. }
  4344. public event EventHandler Click {
  4345. add { Events.AddHandler (ClickEvent, value); }
  4346. remove { Events.RemoveHandler (ClickEvent, value); }
  4347. }
  4348. #if NET_2_0
  4349. public event EventHandler ClientSizeChanged {
  4350. add {Events.AddHandler (ClientSizeChangedEvent, value);}
  4351. remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
  4352. }
  4353. #endif
  4354. #if NET_2_0
  4355. [Browsable (false)]
  4356. #endif
  4357. public event EventHandler ContextMenuChanged {
  4358. add { Events.AddHandler (ContextMenuChangedEvent, value); }
  4359. remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
  4360. }
  4361. #if NET_2_0
  4362. public event EventHandler ContextMenuStripChanged {
  4363. add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
  4364. remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
  4365. }
  4366. #endif
  4367. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4368. #if NET_2_0
  4369. [Browsable(true)]
  4370. #else
  4371. [Browsable(false)]
  4372. #endif
  4373. public event ControlEventHandler ControlAdded {
  4374. add { Events.AddHandler (ControlAddedEvent, value); }
  4375. remove { Events.RemoveHandler (ControlAddedEvent, value); }
  4376. }
  4377. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4378. #if NET_2_0
  4379. [Browsable(true)]
  4380. #else
  4381. [Browsable(false)]
  4382. #endif
  4383. public event ControlEventHandler ControlRemoved {
  4384. add { Events.AddHandler (ControlRemovedEvent, value); }
  4385. remove { Events.RemoveHandler (ControlRemovedEvent, value); }
  4386. }
  4387. [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
  4388. public event EventHandler CursorChanged {
  4389. add { Events.AddHandler (CursorChangedEvent, value); }
  4390. remove { Events.RemoveHandler (CursorChangedEvent, value); }
  4391. }
  4392. public event EventHandler DockChanged {
  4393. add { Events.AddHandler (DockChangedEvent, value); }
  4394. remove { Events.RemoveHandler (DockChangedEvent, value); }
  4395. }
  4396. public event EventHandler DoubleClick {
  4397. add { Events.AddHandler (DoubleClickEvent, value); }
  4398. remove { Events.RemoveHandler (DoubleClickEvent, value); }
  4399. }
  4400. public event DragEventHandler DragDrop {
  4401. add { Events.AddHandler (DragDropEvent, value); }
  4402. remove { Events.RemoveHandler (DragDropEvent, value); }
  4403. }
  4404. public event DragEventHandler DragEnter {
  4405. add { Events.AddHandler (DragEnterEvent, value); }
  4406. remove { Events.RemoveHandler (DragEnterEvent, value); }
  4407. }
  4408. public event EventHandler DragLeave {
  4409. add { Events.AddHandler (DragLeaveEvent, value); }
  4410. remove { Events.RemoveHandler (DragLeaveEvent, value); }
  4411. }
  4412. public event DragEventHandler DragOver {
  4413. add { Events.AddHandler (DragOverEvent, value); }
  4414. remove { Events.RemoveHandler (DragOverEvent, value); }
  4415. }
  4416. public event EventHandler EnabledChanged {
  4417. add { Events.AddHandler (EnabledChangedEvent, value); }
  4418. remove { Events.RemoveHandler (EnabledChangedEvent, value); }
  4419. }
  4420. public event EventHandler Enter {
  4421. add { Events.AddHandler (EnterEvent, value); }
  4422. remove { Events.RemoveHandler (EnterEvent, value); }
  4423. }
  4424. public event EventHandler FontChanged {
  4425. add { Events.AddHandler (FontChangedEvent, value); }
  4426. remove { Events.RemoveHandler (FontChangedEvent, value); }
  4427. }
  4428. public event EventHandler ForeColorChanged {
  4429. add { Events.AddHandler (ForeColorChangedEvent, value); }
  4430. remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
  4431. }
  4432. public event GiveFeedbackEventHandler GiveFeedback {
  4433. add { Events.AddHandler (GiveFeedbackEvent, value); }
  4434. remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
  4435. }
  4436. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4437. [Browsable(false)]
  4438. public event EventHandler GotFocus {
  4439. add { Events.AddHandler (GotFocusEvent, value); }
  4440. remove { Events.RemoveHandler (GotFocusEvent, value); }
  4441. }
  4442. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4443. [Browsable(false)]
  4444. public event EventHandler HandleCreated {
  4445. add { Events.AddHandler (HandleCreatedEvent, value); }
  4446. remove { Events.RemoveHandler (HandleCreatedEvent, value); }
  4447. }
  4448. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4449. [Browsable(false)]
  4450. public event EventHandler HandleDestroyed {
  4451. add { Events.AddHandler (HandleDestroyedEvent, value); }
  4452. remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
  4453. }
  4454. public event HelpEventHandler HelpRequested {
  4455. add { Events.AddHandler (HelpRequestedEvent, value); }
  4456. remove { Events.RemoveHandler (HelpRequestedEvent, value); }
  4457. }
  4458. public event EventHandler ImeModeChanged {
  4459. add { Events.AddHandler (ImeModeChangedEvent, value); }
  4460. remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
  4461. }
  4462. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4463. [Browsable(false)]
  4464. public event InvalidateEventHandler Invalidated {
  4465. add { Events.AddHandler (InvalidatedEvent, value); }
  4466. remove { Events.RemoveHandler (InvalidatedEvent, value); }
  4467. }
  4468. public event KeyEventHandler KeyDown {
  4469. add { Events.AddHandler (KeyDownEvent, value); }
  4470. remove { Events.RemoveHandler (KeyDownEvent, value); }
  4471. }
  4472. public event KeyPressEventHandler KeyPress {
  4473. add { Events.AddHandler (KeyPressEvent, value); }
  4474. remove { Events.RemoveHandler (KeyPressEvent, value); }
  4475. }
  4476. public event KeyEventHandler KeyUp {
  4477. add { Events.AddHandler (KeyUpEvent, value); }
  4478. remove { Events.RemoveHandler (KeyUpEvent, value); }
  4479. }
  4480. public event LayoutEventHandler Layout {
  4481. add { Events.AddHandler (LayoutEvent, value); }
  4482. remove { Events.RemoveHandler (LayoutEvent, value); }
  4483. }
  4484. public event EventHandler Leave {
  4485. add { Events.AddHandler (LeaveEvent, value); }
  4486. remove { Events.RemoveHandler (LeaveEvent, value); }
  4487. }
  4488. public event EventHandler LocationChanged {
  4489. add { Events.AddHandler (LocationChangedEvent, value); }
  4490. remove { Events.RemoveHandler (LocationChangedEvent, value); }
  4491. }
  4492. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4493. [Browsable(false)]
  4494. public event EventHandler LostFocus {
  4495. add { Events.AddHandler (LostFocusEvent, value); }
  4496. remove { Events.RemoveHandler (LostFocusEvent, value); }
  4497. }
  4498. #if NET_2_0
  4499. public event EventHandler MarginChanged {
  4500. add { Events.AddHandler (MarginChangedEvent, value); }
  4501. remove {Events.RemoveHandler (MarginChangedEvent, value); }
  4502. }
  4503. public event EventHandler MouseCaptureChanged {
  4504. add { Events.AddHandler (MouseCaptureChangedEvent, value); }
  4505. remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
  4506. }
  4507. public event MouseEventHandler MouseClick
  4508. {
  4509. add { Events.AddHandler (MouseClickEvent, value); }
  4510. remove { Events.RemoveHandler (MouseClickEvent, value); }
  4511. }
  4512. public event MouseEventHandler MouseDoubleClick
  4513. {
  4514. add { Events.AddHandler (MouseDoubleClickEvent, value); }
  4515. remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
  4516. }
  4517. #endif
  4518. public event MouseEventHandler MouseDown {
  4519. add { Events.AddHandler (MouseDownEvent, value); }
  4520. remove { Events.RemoveHandler (MouseDownEvent, value); }
  4521. }
  4522. public event EventHandler MouseEnter {
  4523. add { Events.AddHandler (MouseEnterEvent, value); }
  4524. remove { Events.RemoveHandler (MouseEnterEvent, value); }
  4525. }
  4526. public event EventHandler MouseHover {
  4527. add { Events.AddHandler (MouseHoverEvent, value); }
  4528. remove { Events.RemoveHandler (MouseHoverEvent, value); }
  4529. }
  4530. public event EventHandler MouseLeave {
  4531. add { Events.AddHandler (MouseLeaveEvent, value); }
  4532. remove { Events.RemoveHandler (MouseLeaveEvent, value); }
  4533. }
  4534. public event MouseEventHandler MouseMove {
  4535. add { Events.AddHandler (MouseMoveEvent, value); }
  4536. remove { Events.RemoveHandler (MouseMoveEvent, value); }
  4537. }
  4538. public event MouseEventHandler MouseUp {
  4539. add { Events.AddHandler (MouseUpEvent, value); }
  4540. remove { Events.RemoveHandler (MouseUpEvent, value); }
  4541. }
  4542. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4543. [Browsable(false)]
  4544. public event MouseEventHandler MouseWheel {
  4545. add { Events.AddHandler (MouseWheelEvent, value); }
  4546. remove { Events.RemoveHandler (MouseWheelEvent, value); }
  4547. }
  4548. public event EventHandler Move {
  4549. add { Events.AddHandler (MoveEvent, value); }
  4550. remove { Events.RemoveHandler (MoveEvent, value); }
  4551. }
  4552. #if NET_2_0
  4553. public event EventHandler PaddingChanged
  4554. {
  4555. add { Events.AddHandler (PaddingChangedEvent, value); }
  4556. remove { Events.RemoveHandler (PaddingChangedEvent, value); }
  4557. }
  4558. #endif
  4559. public event PaintEventHandler Paint {
  4560. add { Events.AddHandler (PaintEvent, value); }
  4561. remove { Events.RemoveHandler (PaintEvent, value); }
  4562. }
  4563. public event EventHandler ParentChanged {
  4564. add { Events.AddHandler (ParentChangedEvent, value); }
  4565. remove { Events.RemoveHandler (ParentChangedEvent, value); }
  4566. }
  4567. #if NET_2_0
  4568. public event EventHandler PreviewKeyDown {
  4569. add { Events.AddHandler (PreviewKeyDownEvent, value); }
  4570. remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
  4571. }
  4572. #endif
  4573. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
  4574. add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
  4575. remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
  4576. }
  4577. public event QueryContinueDragEventHandler QueryContinueDrag {
  4578. add { Events.AddHandler (QueryContinueDragEvent, value); }
  4579. remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
  4580. }
  4581. #if NET_2_0
  4582. public event EventHandler RegionChanged {
  4583. add { Events.AddHandler (RegionChangedEvent, value); }
  4584. remove { Events.RemoveHandler (RegionChangedEvent, value); }
  4585. }
  4586. #endif
  4587. #if NET_2_0
  4588. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4589. #endif
  4590. public event EventHandler Resize {
  4591. add { Events.AddHandler (ResizeEvent, value); }
  4592. remove { Events.RemoveHandler (ResizeEvent, value); }
  4593. }
  4594. public event EventHandler RightToLeftChanged {
  4595. add { Events.AddHandler (RightToLeftChangedEvent, value); }
  4596. remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
  4597. }
  4598. public event EventHandler SizeChanged {
  4599. add { Events.AddHandler (SizeChangedEvent, value); }
  4600. remove { Events.RemoveHandler (SizeChangedEvent, value); }
  4601. }
  4602. public event EventHandler StyleChanged {
  4603. add { Events.AddHandler (StyleChangedEvent, value); }
  4604. remove { Events.RemoveHandler (StyleChangedEvent, value); }
  4605. }
  4606. public event EventHandler SystemColorsChanged {
  4607. add { Events.AddHandler (SystemColorsChangedEvent, value); }
  4608. remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
  4609. }
  4610. public event EventHandler TabIndexChanged {
  4611. add { Events.AddHandler (TabIndexChangedEvent, value); }
  4612. remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
  4613. }
  4614. public event EventHandler TabStopChanged {
  4615. add { Events.AddHandler (TabStopChangedEvent, value); }
  4616. remove { Events.RemoveHandler (TabStopChangedEvent, value); }
  4617. }
  4618. public event EventHandler TextChanged {
  4619. add { Events.AddHandler (TextChangedEvent, value); }
  4620. remove { Events.RemoveHandler (TextChangedEvent, value); }
  4621. }
  4622. public event EventHandler Validated {
  4623. add { Events.AddHandler (ValidatedEvent, value); }
  4624. remove { Events.RemoveHandler (ValidatedEvent, value); }
  4625. }
  4626. public event CancelEventHandler Validating {
  4627. add { Events.AddHandler (ValidatingEvent, value); }
  4628. remove { Events.RemoveHandler (ValidatingEvent, value); }
  4629. }
  4630. public event EventHandler VisibleChanged {
  4631. add { Events.AddHandler (VisibleChangedEvent, value); }
  4632. remove { Events.RemoveHandler (VisibleChangedEvent, value); }
  4633. }
  4634. #endregion // Events
  4635. }
  4636. }