Control.cs 183 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124
  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. #undef DebugRecreate
  33. #undef DebugFocus
  34. #undef DebugMessages
  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, IBounds
  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. private IWindowTarget window_target;
  70. string name; // for object naming
  71. // State
  72. bool is_created; // true if OnCreateControl has been sent
  73. internal bool has_focus; // true if control has focus
  74. internal bool is_visible; // true if control is visible
  75. internal bool is_entered; // is the mouse inside the control?
  76. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  77. bool is_accessible; // true if the control is visible to accessibility applications
  78. bool is_captured; // tracks if the control has captured the mouse
  79. internal bool is_toplevel; // tracks if the control is a toplevel window
  80. bool is_recreating; // tracks if the handle for the control is being recreated
  81. bool causes_validation; // tracks if validation is executed on changes
  82. bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
  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. bool is_disposing; // is the window getting disposed?
  87. Size client_size; // size of the client area (window excluding decorations)
  88. Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  89. ControlStyles control_style; // rather win32-specific, style bits for control
  90. ImeMode ime_mode;
  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. bool show_keyboard_cues; // Current keyboard cues
  104. internal bool show_focus_cues; // Current focus cues
  105. internal bool force_double_buffer; // Always doublebuffer regardless of ControlStyle
  106. // Layout
  107. internal enum LayoutType {
  108. Anchor,
  109. Dock
  110. }
  111. Layout.LayoutEngine layout_engine;
  112. internal int layout_suspended;
  113. bool layout_pending; // true if our parent needs to re-layout us
  114. internal AnchorStyles anchor_style; // anchoring requirements for our control
  115. internal DockStyle dock_style; // docking requirements for our control
  116. LayoutType layout_type;
  117. private bool recalculate_distances = true; // Delay anchor calculations
  118. // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
  119. internal int dist_right; // distance to the right border of the parent
  120. internal int dist_bottom; // distance to the bottom border of the parent
  121. // to be categorized...
  122. ControlCollection child_controls; // our children
  123. Control parent; // our parent control
  124. BindingContext binding_context;
  125. RightToLeft right_to_left; // drawing direction for control
  126. ContextMenu context_menu; // Context menu associated with the control
  127. internal bool use_compatible_text_rendering;
  128. private bool use_wait_cursor;
  129. //accessibility
  130. string accessible_name;
  131. string accessible_description;
  132. string accessible_default_action;
  133. AccessibleRole accessible_role = AccessibleRole.Default;
  134. AccessibleObject accessibility_object; // object that contains accessibility information about our control
  135. // double buffering
  136. DoubleBuffer backbuffer;
  137. ControlBindingsCollection data_bindings;
  138. #if NET_2_0
  139. static bool verify_thread_handle;
  140. Padding padding;
  141. ImageLayout backgroundimage_layout;
  142. Size maximum_size;
  143. Size minimum_size;
  144. Padding margin;
  145. private ContextMenuStrip context_menu_strip;
  146. private bool nested_layout = false;
  147. Point auto_scroll_offset;
  148. private AutoSizeMode auto_size_mode;
  149. private bool suppressing_key_press;
  150. #endif
  151. #endregion // Local Variables
  152. #region Private Classes
  153. // This helper class allows us to dispatch messages to Control.WndProc
  154. internal class ControlNativeWindow : NativeWindow {
  155. private Control owner;
  156. public ControlNativeWindow(Control control) : base() {
  157. this.owner=control;
  158. }
  159. public Control Owner {
  160. get {
  161. return owner;
  162. }
  163. }
  164. protected override void OnHandleChange()
  165. {
  166. this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
  167. }
  168. static internal Control ControlFromHandle(IntPtr hWnd) {
  169. ControlNativeWindow window;
  170. window = (ControlNativeWindow)NativeWindow.FromHandle (hWnd);
  171. if (window != null) {
  172. return window.owner;
  173. }
  174. return null;
  175. }
  176. static internal Control ControlFromChildHandle (IntPtr handle) {
  177. ControlNativeWindow window;
  178. Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
  179. while (hwnd != null) {
  180. window = (ControlNativeWindow)NativeWindow.FromHandle (handle);
  181. if (window != null) {
  182. return window.owner;
  183. }
  184. hwnd = hwnd.Parent;
  185. }
  186. return null;
  187. }
  188. protected override void WndProc(ref Message m) {
  189. owner.WindowTarget.OnMessage(ref m);
  190. }
  191. }
  192. private class ControlWindowTarget : IWindowTarget
  193. {
  194. private Control control;
  195. public ControlWindowTarget(Control control)
  196. {
  197. this.control = control;
  198. }
  199. public void OnHandleChange(IntPtr newHandle)
  200. {
  201. }
  202. public void OnMessage(ref Message m)
  203. {
  204. control.WndProc(ref m);
  205. }
  206. }
  207. #endregion
  208. #region Public Classes
  209. [ComVisible(true)]
  210. public class ControlAccessibleObject : AccessibleObject {
  211. IntPtr handle;
  212. #region ControlAccessibleObject Constructors
  213. public ControlAccessibleObject(Control ownerControl)
  214. : base (ownerControl)
  215. {
  216. if (ownerControl == null)
  217. throw new ArgumentNullException ("owner");
  218. handle = ownerControl.Handle;
  219. }
  220. #endregion // ControlAccessibleObject Constructors
  221. #region ControlAccessibleObject Public Instance Properties
  222. public override string DefaultAction {
  223. get {
  224. return base.DefaultAction;
  225. }
  226. }
  227. public override string Description {
  228. get {
  229. return base.Description;
  230. }
  231. }
  232. public IntPtr Handle {
  233. get {
  234. return handle;
  235. }
  236. set {
  237. // We don't want to let them set it
  238. }
  239. }
  240. public override string Help {
  241. get {
  242. return base.Help;
  243. }
  244. }
  245. public override string KeyboardShortcut {
  246. get {
  247. return base.KeyboardShortcut;
  248. }
  249. }
  250. public override string Name {
  251. get {
  252. return base.Name;
  253. }
  254. set {
  255. base.Name = value;
  256. }
  257. }
  258. public Control Owner {
  259. get {
  260. return base.owner;
  261. }
  262. }
  263. public override AccessibleObject Parent {
  264. get {
  265. return base.Parent;
  266. }
  267. }
  268. public override AccessibleRole Role {
  269. get {
  270. return base.Role;
  271. }
  272. }
  273. #endregion // ControlAccessibleObject Public Instance Properties
  274. #region ControlAccessibleObject Public Instance Methods
  275. public override int GetHelpTopic (out string fileName)
  276. {
  277. return base.GetHelpTopic (out fileName);
  278. }
  279. [MonoTODO ("Implement this")]
  280. public void NotifyClients(AccessibleEvents accEvent) {
  281. throw new NotImplementedException();
  282. }
  283. [MonoTODO ("Implement this")]
  284. public void NotifyClients(AccessibleEvents accEvent, int childID) {
  285. }
  286. #if NET_2_0
  287. [MonoTODO ("Implement this")]
  288. public void NotifyClients (AccessibleEvents accEvent, int objectID, int childID)
  289. {
  290. }
  291. #endif
  292. public override string ToString() {
  293. return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
  294. }
  295. #endregion // ControlAccessibleObject Public Instance Methods
  296. }
  297. private class DoubleBuffer : IDisposable
  298. {
  299. public Region InvalidRegion;
  300. private Stack real_graphics;
  301. private object back_buffer;
  302. private Control parent;
  303. private bool pending_disposal;
  304. public DoubleBuffer (Control parent) {
  305. this.parent = parent;
  306. real_graphics = new Stack ();
  307. int width = parent.Width;
  308. int height = parent.Height;
  309. if (width < 1) width = 1;
  310. if (height < 1) height = 1;
  311. XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
  312. Invalidate ();
  313. }
  314. public void Blit (PaintEventArgs pe) {
  315. Graphics buffered_graphics;
  316. buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
  317. XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
  318. buffered_graphics.Dispose ();
  319. }
  320. public void Start (PaintEventArgs pe) {
  321. // We need to get the graphics for every paint.
  322. real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
  323. }
  324. public void End (PaintEventArgs pe) {
  325. Graphics buffered_graphics;
  326. buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
  327. if (pending_disposal)
  328. Dispose ();
  329. else {
  330. XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
  331. InvalidRegion.Exclude (pe.ClipRectangle);
  332. }
  333. buffered_graphics.Dispose ();
  334. }
  335. public void Invalidate () {
  336. if (InvalidRegion != null)
  337. InvalidRegion.Dispose ();
  338. InvalidRegion = new Region (parent.ClientRectangle);
  339. }
  340. public void Dispose () {
  341. if (real_graphics.Count > 0) {
  342. pending_disposal = true;
  343. return;
  344. }
  345. XplatUI.DestroyOffscreenDrawable (back_buffer);
  346. if (InvalidRegion != null)
  347. InvalidRegion.Dispose ();
  348. InvalidRegion = null;
  349. back_buffer = null;
  350. GC.SuppressFinalize (this);
  351. }
  352. #region IDisposable Members
  353. void IDisposable.Dispose () {
  354. Dispose ();
  355. }
  356. #endregion
  357. ~DoubleBuffer () {
  358. Dispose ();
  359. }
  360. }
  361. [ListBindable (false)]
  362. #if NET_2_0
  363. [ComVisible (false)]
  364. public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
  365. #else
  366. [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  367. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  368. #endif
  369. #region ControlCollection Local Variables
  370. #if !NET_2_0
  371. ArrayList list;
  372. #endif
  373. ArrayList impl_list;
  374. Control [] all_controls;
  375. Control owner;
  376. #endregion // ControlCollection Local Variables
  377. #region ControlCollection Public Constructor
  378. public ControlCollection (Control owner)
  379. {
  380. this.owner = owner;
  381. #if !NET_2_0
  382. this.list = new ArrayList();
  383. #endif
  384. }
  385. #endregion
  386. #region ControlCollection Public Instance Properties
  387. #if !NET_2_0
  388. public int Count {
  389. get { return list.Count; }
  390. }
  391. public bool IsReadOnly {
  392. get {
  393. return list.IsReadOnly;
  394. }
  395. }
  396. #endif
  397. #if NET_2_0
  398. public Control Owner {
  399. get { return this.owner; }
  400. }
  401. public virtual Control this[string key] {
  402. get {
  403. int index = IndexOfKey (key);
  404. if (index >= 0)
  405. return this[index];
  406. return null;
  407. }
  408. }
  409. new
  410. #endif
  411. public virtual Control this[int index] {
  412. get {
  413. if (index < 0 || index >= list.Count) {
  414. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  415. }
  416. return (Control)list[index];
  417. }
  418. }
  419. #endregion // ControlCollection Public Instance Properties
  420. #region ControlCollection Instance Methods
  421. public virtual void Add (Control value)
  422. {
  423. if (value == null)
  424. return;
  425. Form form_value = value as Form;
  426. Form form_owner = owner as Form;
  427. bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
  428. bool child_is_toplevel = value.GetTopLevel();
  429. bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
  430. if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
  431. throw new ArgumentException("Cannot add a top level control to a control.", "value");
  432. if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
  433. throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
  434. }
  435. value.recalculate_distances = true;
  436. if (Contains (value)) {
  437. owner.PerformLayout();
  438. return;
  439. }
  440. if (value.tab_index == -1) {
  441. int end;
  442. int index;
  443. int use;
  444. use = 0;
  445. end = owner.child_controls.Count;
  446. for (int i = 0; i < end; i++) {
  447. index = owner.child_controls[i].tab_index;
  448. if (index >= use) {
  449. use = index + 1;
  450. }
  451. }
  452. value.tab_index = use;
  453. }
  454. if (value.parent != null) {
  455. value.parent.Controls.Remove(value);
  456. }
  457. all_controls = null;
  458. list.Add (value);
  459. value.ChangeParent(owner);
  460. value.InitLayout();
  461. if (owner.Visible)
  462. owner.UpdateChildrenZOrder();
  463. owner.PerformLayout(value, "Parent");
  464. owner.OnControlAdded(new ControlEventArgs(value));
  465. }
  466. internal void AddToList (Control c)
  467. {
  468. all_controls = null;
  469. list.Add (c);
  470. }
  471. internal virtual void AddImplicit (Control control)
  472. {
  473. if (impl_list == null)
  474. impl_list = new ArrayList ();
  475. if (AllContains (control)) {
  476. owner.PerformLayout ();
  477. return;
  478. }
  479. if (control.parent != null) {
  480. control.parent.Controls.Remove(control);
  481. }
  482. all_controls = null;
  483. impl_list.Add (control);
  484. control.ChangeParent (owner);
  485. control.InitLayout ();
  486. if (owner.Visible)
  487. owner.UpdateChildrenZOrder ();
  488. // If we are adding a new control that isn't
  489. // visible, don't trigger a layout
  490. if (control.VisibleInternal)
  491. owner.PerformLayout (control, "Parent");
  492. }
  493. #if NET_2_0
  494. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  495. #endif
  496. public virtual void AddRange (Control[] controls)
  497. {
  498. if (controls == null)
  499. throw new ArgumentNullException ("controls");
  500. owner.SuspendLayout ();
  501. try {
  502. for (int i = 0; i < controls.Length; i++)
  503. Add (controls[i]);
  504. } finally {
  505. owner.ResumeLayout ();
  506. }
  507. }
  508. internal virtual void AddRangeImplicit (Control [] controls)
  509. {
  510. if (controls == null)
  511. throw new ArgumentNullException ("controls");
  512. owner.SuspendLayout ();
  513. try {
  514. for (int i = 0; i < controls.Length; i++)
  515. AddImplicit (controls [i]);
  516. } finally {
  517. owner.ResumeLayout (false);
  518. }
  519. }
  520. #if NET_2_0
  521. new
  522. #endif
  523. public virtual void Clear ()
  524. {
  525. all_controls = null;
  526. // MS sends remove events in reverse order
  527. while (list.Count > 0) {
  528. Remove((Control)list[list.Count - 1]);
  529. }
  530. }
  531. internal virtual void ClearImplicit ()
  532. {
  533. if (impl_list == null)
  534. return;
  535. all_controls = null;
  536. impl_list.Clear ();
  537. }
  538. public bool Contains (Control control)
  539. {
  540. return list.Contains (control);
  541. }
  542. internal bool ImplicitContains (Control value) {
  543. if (impl_list == null)
  544. return false;
  545. return impl_list.Contains (value);
  546. }
  547. internal bool AllContains (Control value) {
  548. return Contains (value) || ImplicitContains (value);
  549. }
  550. #if NET_2_0
  551. public virtual bool ContainsKey (string key)
  552. {
  553. return IndexOfKey (key) >= 0;
  554. }
  555. #endif
  556. #if !NET_2_0
  557. public void CopyTo (Array dest, int index)
  558. {
  559. list.CopyTo (dest, index);
  560. }
  561. public override bool Equals (object other)
  562. {
  563. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  564. return(true);
  565. } else {
  566. return(false);
  567. }
  568. }
  569. #endif
  570. #if NET_2_0
  571. // LAMESPEC: MSDN says AE, MS implementation throws ANE
  572. public Control[] Find (string key, bool searchAllChildren)
  573. {
  574. if (string.IsNullOrEmpty (key))
  575. throw new ArgumentNullException ("key");
  576. ArrayList al = new ArrayList ();
  577. foreach (Control c in list) {
  578. if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
  579. al.Add (c);
  580. if (searchAllChildren)
  581. al.AddRange (c.Controls.Find (key, true));
  582. }
  583. return (Control[])al.ToArray (typeof (Control));
  584. }
  585. #endif
  586. public int GetChildIndex(Control child) {
  587. return GetChildIndex(child, false);
  588. }
  589. #if NET_2_0
  590. public virtual int
  591. #else
  592. public int
  593. #endif
  594. GetChildIndex(Control child, bool throwException) {
  595. int index;
  596. index=list.IndexOf(child);
  597. if (index==-1 && throwException) {
  598. throw new ArgumentException("Not a child control", "child");
  599. }
  600. return index;
  601. }
  602. #if NET_2_0
  603. public override IEnumerator
  604. #else
  605. public IEnumerator
  606. #endif
  607. GetEnumerator () {
  608. return new ControlCollectionEnumerator (list);
  609. }
  610. internal IEnumerator GetAllEnumerator () {
  611. Control [] res = GetAllControls ();
  612. return res.GetEnumerator ();
  613. }
  614. internal ArrayList ImplicitControls {
  615. get { return impl_list; }
  616. }
  617. internal Control [] GetAllControls () {
  618. if (all_controls != null)
  619. return all_controls;
  620. if (impl_list == null) {
  621. all_controls = (Control []) list.ToArray (typeof (Control));
  622. return all_controls;
  623. }
  624. all_controls = new Control [list.Count + impl_list.Count];
  625. impl_list.CopyTo (all_controls);
  626. list.CopyTo (all_controls, impl_list.Count);
  627. return all_controls;
  628. }
  629. #if !NET_2_0
  630. public override int GetHashCode ()
  631. {
  632. return base.GetHashCode ();
  633. }
  634. #endif
  635. public int IndexOf (Control control)
  636. {
  637. return list.IndexOf (control);
  638. }
  639. #if NET_2_0
  640. public virtual int IndexOfKey (string key)
  641. {
  642. if (string.IsNullOrEmpty (key))
  643. return -1;
  644. for (int i = 0; i < list.Count; i++)
  645. if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
  646. return i;
  647. return -1;
  648. }
  649. #endif
  650. public virtual void Remove (Control value)
  651. {
  652. if (value == null)
  653. return;
  654. all_controls = null;
  655. list.Remove(value);
  656. owner.PerformLayout(value, "Parent");
  657. owner.OnControlRemoved(new ControlEventArgs(value));
  658. ContainerControl container = owner.InternalGetContainerControl ();
  659. if (container != null) {
  660. // Inform any container controls about the loss of a child control
  661. // so that they can update their active control
  662. container.ChildControlRemoved (value);
  663. }
  664. value.ChangeParent(null);
  665. owner.UpdateChildrenZOrder();
  666. }
  667. internal virtual void RemoveImplicit (Control control)
  668. {
  669. if (impl_list != null) {
  670. all_controls = null;
  671. impl_list.Remove (control);
  672. owner.PerformLayout (control, "Parent");
  673. owner.OnControlRemoved (new ControlEventArgs (control));
  674. }
  675. control.ChangeParent (null);
  676. owner.UpdateChildrenZOrder ();
  677. }
  678. public void RemoveAt (int index)
  679. {
  680. if (index < 0 || index >= list.Count)
  681. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  682. Remove ((Control) list [index]);
  683. }
  684. #if NET_2_0
  685. public virtual void RemoveByKey (string key)
  686. {
  687. int index = IndexOfKey (key);
  688. if (index >= 0)
  689. RemoveAt (index);
  690. }
  691. #endif
  692. #if NET_2_0
  693. public virtual void
  694. #else
  695. public void
  696. #endif
  697. SetChildIndex(Control child, int newIndex)
  698. {
  699. if (child == null)
  700. throw new ArgumentNullException ("child");
  701. int old_index;
  702. old_index=list.IndexOf(child);
  703. if (old_index==-1) {
  704. throw new ArgumentException("Not a child control", "child");
  705. }
  706. if (old_index==newIndex) {
  707. return;
  708. }
  709. all_controls = null;
  710. list.RemoveAt(old_index);
  711. if (newIndex>list.Count) {
  712. list.Add(child);
  713. } else {
  714. list.Insert(newIndex, child);
  715. }
  716. child.UpdateZOrder();
  717. owner.PerformLayout();
  718. }
  719. #endregion // ControlCollection Private Instance Methods
  720. #region ControlCollection Interface Properties
  721. #if !NET_2_0
  722. object IList.this [int index] {
  723. get {
  724. if (index<0 || index>=list.Count) {
  725. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  726. }
  727. return this[index];
  728. }
  729. set {
  730. if (!(value is Control)) {
  731. throw new ArgumentException("Object of type Control required", "value");
  732. }
  733. all_controls = null;
  734. Control ctrl = (Control) value;
  735. list[index]= ctrl;
  736. ctrl.ChangeParent(owner);
  737. ctrl.InitLayout();
  738. owner.UpdateChildrenZOrder();
  739. owner.PerformLayout(ctrl, "Parent");
  740. }
  741. }
  742. bool IList.IsFixedSize {
  743. get {
  744. return false;
  745. }
  746. }
  747. bool ICollection.IsSynchronized {
  748. get {
  749. return list.IsSynchronized;
  750. }
  751. }
  752. object ICollection.SyncRoot {
  753. get {
  754. return list.SyncRoot;
  755. }
  756. }
  757. #endif
  758. #endregion // ControlCollection Interface Properties
  759. #region ControlCollection Interface Methods
  760. int IList.Add (object control)
  761. {
  762. if (!(control is Control))
  763. throw new ArgumentException ("Object of type Control required", "control");
  764. if (control == null)
  765. throw new ArgumentException ("control", "Cannot add null controls");
  766. bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
  767. bool child_is_toplevel = ((Control) control).GetTopLevel ();
  768. bool child_is_mdichild = (control is Form && ((Form) control).IsMdiChild);
  769. if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
  770. throw new ArgumentException ("Cannot add a top level control to a control.", "control");
  771. return list.Add (control);
  772. }
  773. #if !NET_2_0
  774. bool IList.Contains (object control)
  775. {
  776. if (!(control is Control))
  777. throw new ArgumentException ("Object of type Control required", "control");
  778. return this.Contains ((Control) control);
  779. }
  780. int IList.IndexOf (object control)
  781. {
  782. if (!(control is Control))
  783. throw new ArgumentException ("Object of type Control required", "control");
  784. return this.IndexOf ((Control) control);
  785. }
  786. void IList.Insert (int index, object value)
  787. {
  788. if (!(value is Control))
  789. throw new ArgumentException("Object of type Control required", "value");
  790. all_controls = null;
  791. list.Insert (index, value);
  792. }
  793. #endif
  794. void IList.Remove (object control)
  795. {
  796. if (!(control is Control))
  797. throw new ArgumentException ("Object of type Control required", "control");
  798. all_controls = null;
  799. list.Remove (control);
  800. }
  801. Object ICloneable.Clone ()
  802. {
  803. ControlCollection clone = new ControlCollection (this.owner);
  804. clone.list = (ArrayList)list.Clone (); // FIXME: Do we need this?
  805. return clone;
  806. }
  807. #endregion // ControlCollection Interface Methods
  808. internal class ControlCollectionEnumerator : IEnumerator
  809. {
  810. private ArrayList list;
  811. int position = -1;
  812. public ControlCollectionEnumerator (ArrayList collection)
  813. {
  814. list = collection;
  815. }
  816. #region IEnumerator Members
  817. public object Current {
  818. get {
  819. try {
  820. return list[position];
  821. } catch (IndexOutOfRangeException) {
  822. throw new InvalidOperationException ();
  823. }
  824. }
  825. }
  826. public bool MoveNext ()
  827. {
  828. position++;
  829. return (position < list.Count);
  830. }
  831. public void Reset ()
  832. {
  833. position = -1;
  834. }
  835. #endregion
  836. }
  837. }
  838. #endregion // ControlCollection Class
  839. #region Public Constructors
  840. public Control ()
  841. {
  842. #if NET_2_0
  843. if (WindowsFormsSynchronizationContext.AutoInstall)
  844. if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext))
  845. SynchronizationContext.SetSynchronizationContext (new WindowsFormsSynchronizationContext ());
  846. #endif
  847. layout_type = LayoutType.Anchor;
  848. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  849. is_created = false;
  850. is_visible = true;
  851. is_captured = false;
  852. is_disposed = false;
  853. is_enabled = true;
  854. is_entered = false;
  855. layout_pending = false;
  856. is_toplevel = false;
  857. causes_validation = true;
  858. has_focus = false;
  859. layout_suspended = 0;
  860. mouse_clicks = 1;
  861. tab_index = -1;
  862. cursor = null;
  863. right_to_left = RightToLeft.Inherit;
  864. border_style = BorderStyle.None;
  865. background_color = Color.Empty;
  866. dist_right = 0;
  867. dist_bottom = 0;
  868. tab_stop = true;
  869. ime_mode = ImeMode.Inherit;
  870. use_compatible_text_rendering = true;
  871. show_keyboard_cues = false;
  872. show_focus_cues = SystemInformation.MenuAccessKeysUnderlined;
  873. use_wait_cursor = false;
  874. #if NET_2_0
  875. backgroundimage_layout = ImageLayout.Tile;
  876. use_compatible_text_rendering = Application.use_compatible_text_rendering;
  877. padding = this.DefaultPadding;
  878. maximum_size = new Size();
  879. minimum_size = new Size();
  880. margin = this.DefaultMargin;
  881. auto_size_mode = AutoSizeMode.GrowOnly;
  882. #endif
  883. control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
  884. ControlStyles.Selectable | ControlStyles.StandardClick |
  885. ControlStyles.StandardDoubleClick;
  886. #if NET_2_0
  887. control_style |= ControlStyles.UseTextForAccessibility;
  888. #endif
  889. parent = null;
  890. background_image = null;
  891. text = string.Empty;
  892. name = string.Empty;
  893. window_target = new ControlWindowTarget(this);
  894. window = new ControlNativeWindow(this);
  895. child_controls = CreateControlsInstance();
  896. bounds.Size = DefaultSize;
  897. client_size = ClientSizeFromSize (bounds.Size);
  898. client_rect = new Rectangle (Point.Empty, client_size);
  899. explicit_bounds = bounds;
  900. }
  901. public Control (Control parent, string text) : this()
  902. {
  903. Text=text;
  904. Parent=parent;
  905. }
  906. public Control (Control parent, string text, int left, int top, int width, int height) : this()
  907. {
  908. Parent=parent;
  909. SetBounds(left, top, width, height, BoundsSpecified.All);
  910. Text=text;
  911. }
  912. public Control (string text) : this()
  913. {
  914. Text=text;
  915. }
  916. public Control (string text, int left, int top, int width, int height) : this()
  917. {
  918. SetBounds(left, top, width, height, BoundsSpecified.All);
  919. Text=text;
  920. }
  921. private delegate void RemoveDelegate(object c);
  922. protected override void Dispose (bool disposing)
  923. {
  924. if (!is_disposed && disposing) {
  925. is_disposing = true;
  926. Capture = false;
  927. DisposeBackBuffer ();
  928. if (this.InvokeRequired) {
  929. if (Application.MessageLoop && IsHandleCreated) {
  930. this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
  931. }
  932. } else {
  933. DestroyHandle();
  934. }
  935. if (parent != null)
  936. parent.Controls.Remove(this);
  937. Control [] children = child_controls.GetAllControls ();
  938. for (int i=0; i<children.Length; i++) {
  939. children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
  940. children[i].Dispose();
  941. }
  942. }
  943. is_disposed = true;
  944. base.Dispose(disposing);
  945. }
  946. #endregion // Public Constructors
  947. #region Internal Properties
  948. internal Rectangle PaddingClientRectangle
  949. {
  950. get {
  951. #if NET_2_0
  952. return new Rectangle (
  953. ClientRectangle.Left + padding.Left,
  954. ClientRectangle.Top + padding.Top,
  955. ClientRectangle.Width - padding.Horizontal,
  956. ClientRectangle.Height - padding.Vertical);
  957. #else
  958. return ClientRectangle;
  959. #endif
  960. }
  961. }
  962. private MenuTracker active_tracker;
  963. internal MenuTracker ActiveTracker {
  964. get { return active_tracker; }
  965. set {
  966. if (value == active_tracker)
  967. return;
  968. Capture = value != null;
  969. active_tracker = value;
  970. }
  971. }
  972. // Control is currently selected, like Focused, except maintains state
  973. // when Form loses focus
  974. internal bool InternalSelected {
  975. get {
  976. IContainerControl container;
  977. container = GetContainerControl();
  978. if (container != null && container.ActiveControl == this)
  979. return true;
  980. return false;
  981. }
  982. }
  983. // Looks for focus in child controls
  984. // and also in the implicit ones
  985. internal bool InternalContainsFocus {
  986. get {
  987. IntPtr focused_window;
  988. focused_window = XplatUI.GetFocus();
  989. if (IsHandleCreated) {
  990. if (focused_window == Handle)
  991. return true;
  992. foreach (Control child_control in child_controls.GetAllControls ())
  993. if (child_control.InternalContainsFocus)
  994. return true;
  995. }
  996. return false;
  997. }
  998. }
  999. // Mouse is currently within the control's bounds
  1000. internal bool Entered {
  1001. get { return this.is_entered; }
  1002. }
  1003. internal bool VisibleInternal {
  1004. get { return is_visible; }
  1005. }
  1006. internal LayoutType ControlLayoutType {
  1007. get { return layout_type; }
  1008. }
  1009. internal BorderStyle InternalBorderStyle {
  1010. get {
  1011. return border_style;
  1012. }
  1013. set {
  1014. if (!Enum.IsDefined (typeof (BorderStyle), value))
  1015. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
  1016. if (border_style != value) {
  1017. border_style = value;
  1018. if (IsHandleCreated) {
  1019. XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
  1020. RecreateHandle ();
  1021. Refresh ();
  1022. } else
  1023. client_size = ClientSizeFromSize (bounds.Size);
  1024. }
  1025. }
  1026. }
  1027. internal Size InternalClientSize { set { this.client_size = value; } }
  1028. internal virtual bool ActivateOnShow { get { return true; } }
  1029. internal Rectangle ExplicitBounds { get { return this.explicit_bounds; } set { this.explicit_bounds = value; } }
  1030. internal bool ValidationFailed {
  1031. get {
  1032. ContainerControl c = InternalGetContainerControl ();
  1033. if (c != null)
  1034. return c.validation_failed;
  1035. return false;
  1036. }
  1037. set {
  1038. ContainerControl c = InternalGetContainerControl ();
  1039. if (c != null)
  1040. c.validation_failed = value;
  1041. }
  1042. }
  1043. #endregion // Internal Properties
  1044. #region Private & Internal Methods
  1045. #if NET_2_0
  1046. void IDropTarget.OnDragDrop (DragEventArgs drgEvent)
  1047. {
  1048. OnDragDrop (drgEvent);
  1049. }
  1050. void IDropTarget.OnDragEnter (DragEventArgs drgEvent)
  1051. {
  1052. OnDragEnter (drgEvent);
  1053. }
  1054. void IDropTarget.OnDragLeave (EventArgs e)
  1055. {
  1056. OnDragLeave (e);
  1057. }
  1058. void IDropTarget.OnDragOver (DragEventArgs drgEvent)
  1059. {
  1060. OnDragOver (drgEvent);
  1061. }
  1062. #endif
  1063. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
  1064. return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
  1065. }
  1066. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
  1067. AsyncMethodResult result;
  1068. AsyncMethodData data;
  1069. result = new AsyncMethodResult ();
  1070. data = new AsyncMethodData ();
  1071. data.Handle = control.GetInvokableHandle ();
  1072. data.Method = method;
  1073. data.Args = args;
  1074. data.Result = result;
  1075. #if NET_2_0
  1076. if (!ExecutionContext.IsFlowSuppressed ()) {
  1077. data.Context = ExecutionContext.Capture ();
  1078. }
  1079. #else
  1080. #if !MWF_ON_MSRUNTIME
  1081. if (SecurityManager.SecurityEnabled) {
  1082. data.Stack = CompressedStack.GetCompressedStack ();
  1083. }
  1084. #endif
  1085. #endif
  1086. XplatUI.SendAsyncMethod (data);
  1087. return result;
  1088. }
  1089. // The CheckForIllegalCrossThreadCalls in the #if 2.0 of
  1090. // Control.Handle throws an exception when we are trying
  1091. // to get the Handle to properly invoke on. This avoids that.
  1092. private IntPtr GetInvokableHandle ()
  1093. {
  1094. if (!IsHandleCreated)
  1095. CreateHandle ();
  1096. return window.Handle;
  1097. }
  1098. internal void PointToClient (ref int x, ref int y) {
  1099. XplatUI.ScreenToClient (Handle, ref x, ref y);
  1100. }
  1101. internal void PointToScreen (ref int x, ref int y) {
  1102. XplatUI.ClientToScreen (Handle, ref x, ref y);
  1103. }
  1104. internal bool IsRecreating {
  1105. get {
  1106. return is_recreating;
  1107. }
  1108. }
  1109. internal Graphics DeviceContext {
  1110. get { return Hwnd.GraphicsContext; }
  1111. }
  1112. // An internal way to have a fixed height
  1113. // Basically for DataTimePicker 2.0
  1114. internal virtual int OverrideHeight (int height)
  1115. {
  1116. return height;
  1117. }
  1118. private void ProcessActiveTracker (ref Message m)
  1119. {
  1120. bool is_up = ((Msg) m.Msg == Msg.WM_LBUTTONUP) ||
  1121. ((Msg) m.Msg == Msg.WM_RBUTTONUP);
  1122. MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32 ());
  1123. // We add in the button that was released (not sent in WParam)
  1124. if (is_up) {
  1125. switch ((Msg)m.Msg) {
  1126. case Msg.WM_LBUTTONUP:
  1127. mb |= MouseButtons.Left;
  1128. break;
  1129. case Msg.WM_RBUTTONUP:
  1130. mb |= MouseButtons.Right;
  1131. break;
  1132. }
  1133. }
  1134. MouseEventArgs args = new MouseEventArgs (
  1135. mb,
  1136. mouse_clicks,
  1137. Control.MousePosition.X,
  1138. Control.MousePosition.Y,
  1139. 0);
  1140. if (is_up) {
  1141. active_tracker.OnMouseUp (args);
  1142. mouse_clicks = 1;
  1143. } else {
  1144. if (!active_tracker.OnMouseDown (args)) {
  1145. Control control = GetRealChildAtPoint (Cursor.Position);
  1146. if (control != null) {
  1147. Point pt = control.PointToClient (Cursor.Position);
  1148. XplatUI.SendMessage (control.Handle,
  1149. (Msg)m.Msg,
  1150. m.WParam,
  1151. MakeParam (pt.X, pt.Y));
  1152. }
  1153. }
  1154. }
  1155. }
  1156. private Control FindControlToInvokeOn ()
  1157. {
  1158. Control p = this;
  1159. do {
  1160. if (p.IsHandleCreated)
  1161. break;
  1162. p = p.parent;
  1163. } while (p != null);
  1164. if (p == null || !p.IsHandleCreated)
  1165. throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
  1166. return p;
  1167. }
  1168. private void InvalidateBackBuffer () {
  1169. if (backbuffer != null)
  1170. backbuffer.Invalidate ();
  1171. }
  1172. private DoubleBuffer GetBackBuffer () {
  1173. if (backbuffer == null)
  1174. backbuffer = new DoubleBuffer (this);
  1175. return backbuffer;
  1176. }
  1177. private void DisposeBackBuffer () {
  1178. if (backbuffer != null) {
  1179. backbuffer.Dispose ();
  1180. backbuffer = null;
  1181. }
  1182. }
  1183. internal static void SetChildColor(Control parent) {
  1184. Control child;
  1185. for (int i=0; i < parent.child_controls.Count; i++) {
  1186. child=parent.child_controls[i];
  1187. if (child.child_controls.Count>0) {
  1188. SetChildColor(child);
  1189. }
  1190. }
  1191. }
  1192. internal bool Select(Control control) {
  1193. IContainerControl container;
  1194. if (control == null) {
  1195. return false;
  1196. }
  1197. container = GetContainerControl();
  1198. if (container != null && (Control)container != control) {
  1199. container.ActiveControl = control;
  1200. if (container.ActiveControl == control && !control.has_focus && control.IsHandleCreated)
  1201. XplatUI.SetFocus(control.window.Handle);
  1202. }
  1203. else if (control.IsHandleCreated) {
  1204. XplatUI.SetFocus(control.window.Handle);
  1205. }
  1206. return true;
  1207. }
  1208. internal virtual void DoDefaultAction() {
  1209. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1210. }
  1211. internal static IntPtr MakeParam (int low, int high){
  1212. return new IntPtr (high << 16 | low & 0xffff);
  1213. }
  1214. internal static int LowOrder (int param) {
  1215. return ((int)(short)(param & 0xffff));
  1216. }
  1217. internal static int HighOrder (long param) {
  1218. return ((int)(short)(param >> 16));
  1219. }
  1220. // This method exists so controls overriding OnPaintBackground can have default background painting done
  1221. internal virtual void PaintControlBackground (PaintEventArgs pevent) {
  1222. bool tbstyle_flat = ((CreateParams.Style & (int) ToolBarStyles.TBSTYLE_FLAT) != 0);
  1223. // If we have transparent background
  1224. if (((BackColor.A != 0xff) && GetStyle(ControlStyles.SupportsTransparentBackColor)) || tbstyle_flat) {
  1225. if (parent != null) {
  1226. PaintEventArgs parent_pe;
  1227. GraphicsState state;
  1228. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1229. state = parent_pe.Graphics.Save();
  1230. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1231. parent.OnPaintBackground(parent_pe);
  1232. parent_pe.Graphics.Restore(state);
  1233. state = parent_pe.Graphics.Save();
  1234. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1235. parent.OnPaint(parent_pe);
  1236. parent_pe.Graphics.Restore(state);
  1237. parent_pe.SetGraphics(null);
  1238. }
  1239. }
  1240. if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
  1241. if (parent != null) {
  1242. PaintEventArgs parent_pe;
  1243. Region region;
  1244. GraphicsState state;
  1245. Hwnd hwnd;
  1246. hwnd = Hwnd.ObjectFromHandle(Handle);
  1247. if (hwnd != null) {
  1248. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1249. region = new Region ();
  1250. region.MakeEmpty();
  1251. region.Union(ClientRectangle);
  1252. foreach (Rectangle r in hwnd.ClipRectangles) {
  1253. region.Union (r);
  1254. }
  1255. state = parent_pe.Graphics.Save();
  1256. parent_pe.Graphics.Clip = region;
  1257. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1258. parent.OnPaintBackground(parent_pe);
  1259. parent_pe.Graphics.Restore(state);
  1260. state = parent_pe.Graphics.Save();
  1261. parent_pe.Graphics.Clip = region;
  1262. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1263. parent.OnPaint(parent_pe);
  1264. parent_pe.Graphics.Restore(state);
  1265. parent_pe.SetGraphics(null);
  1266. region.Intersect(clip_region);
  1267. pevent.Graphics.Clip = region;
  1268. }
  1269. }
  1270. }
  1271. if (background_image == null) {
  1272. if (!tbstyle_flat) {
  1273. Rectangle paintRect = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
  1274. Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
  1275. pevent.Graphics.FillRectangle(pen, paintRect);
  1276. }
  1277. return;
  1278. }
  1279. DrawBackgroundImage (pevent.Graphics);
  1280. }
  1281. void DrawBackgroundImage (Graphics g) {
  1282. #if NET_2_0
  1283. Rectangle drawing_rectangle = new Rectangle ();
  1284. g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  1285. switch (backgroundimage_layout)
  1286. {
  1287. case ImageLayout.Tile:
  1288. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  1289. g.FillRectangle (b, ClientRectangle);
  1290. }
  1291. return;
  1292. case ImageLayout.Center:
  1293. drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
  1294. drawing_rectangle.Size = background_image.Size;
  1295. break;
  1296. case ImageLayout.None:
  1297. drawing_rectangle.Location = Point.Empty;
  1298. drawing_rectangle.Size = background_image.Size;
  1299. break;
  1300. case ImageLayout.Stretch:
  1301. drawing_rectangle = ClientRectangle;
  1302. break;
  1303. case ImageLayout.Zoom:
  1304. drawing_rectangle = ClientRectangle;
  1305. if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
  1306. drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
  1307. drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
  1308. } else {
  1309. drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
  1310. drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
  1311. }
  1312. break;
  1313. default:
  1314. return;
  1315. }
  1316. g.DrawImage (background_image, drawing_rectangle);
  1317. #else
  1318. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  1319. g.FillRectangle (b, ClientRectangle);
  1320. }
  1321. #endif
  1322. }
  1323. internal virtual void DndEnter (DragEventArgs e) {
  1324. try {
  1325. OnDragEnter (e);
  1326. } catch { }
  1327. }
  1328. internal virtual void DndOver (DragEventArgs e) {
  1329. try {
  1330. OnDragOver (e);
  1331. } catch { }
  1332. }
  1333. internal virtual void DndDrop (DragEventArgs e) {
  1334. try {
  1335. OnDragDrop (e);
  1336. } catch (Exception exc) {
  1337. Console.Error.WriteLine ("MWF: Exception while dropping:");
  1338. Console.Error.WriteLine (exc);
  1339. }
  1340. }
  1341. internal virtual void DndLeave (EventArgs e) {
  1342. try {
  1343. OnDragLeave (e);
  1344. } catch { }
  1345. }
  1346. internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
  1347. try {
  1348. OnGiveFeedback(e);
  1349. } catch { }
  1350. }
  1351. internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
  1352. try {
  1353. OnQueryContinueDrag(e);
  1354. } catch { }
  1355. }
  1356. internal static MouseButtons FromParamToMouseButtons (long param) {
  1357. MouseButtons buttons = MouseButtons.None;
  1358. if ((param & (long) MsgButtons.MK_LBUTTON) != 0)
  1359. buttons |= MouseButtons.Left;
  1360. if ((param & (long)MsgButtons.MK_MBUTTON) != 0)
  1361. buttons |= MouseButtons.Middle;
  1362. if ((param & (long)MsgButtons.MK_RBUTTON) != 0)
  1363. buttons |= MouseButtons.Right;
  1364. return buttons;
  1365. }
  1366. internal virtual void FireEnter () {
  1367. OnEnter (EventArgs.Empty);
  1368. }
  1369. internal virtual void FireLeave () {
  1370. OnLeave (EventArgs.Empty);
  1371. }
  1372. internal virtual void FireValidating (CancelEventArgs ce) {
  1373. OnValidating (ce);
  1374. }
  1375. internal virtual void FireValidated () {
  1376. OnValidated (EventArgs.Empty);
  1377. }
  1378. internal virtual bool ProcessControlMnemonic(char charCode) {
  1379. return ProcessMnemonic(charCode);
  1380. }
  1381. private static Control FindFlatForward(Control container, Control start) {
  1382. Control found;
  1383. int index;
  1384. int end;
  1385. bool hit;
  1386. found = null;
  1387. end = container.child_controls.Count;
  1388. hit = false;
  1389. if (start != null) {
  1390. index = start.tab_index;
  1391. } else {
  1392. index = -1;
  1393. }
  1394. for (int i = 0; i < end; i++) {
  1395. if (start == container.child_controls[i]) {
  1396. hit = true;
  1397. continue;
  1398. }
  1399. if (found == null || found.tab_index > container.child_controls[i].tab_index) {
  1400. if (container.child_controls[i].tab_index > index || (hit && container.child_controls[i].tab_index == index)) {
  1401. found = container.child_controls[i];
  1402. }
  1403. }
  1404. }
  1405. return found;
  1406. }
  1407. private static Control FindControlForward(Control container, Control start) {
  1408. Control found;
  1409. found = null;
  1410. if (start == null) {
  1411. return FindFlatForward(container, start);
  1412. }
  1413. if (start.child_controls != null && start.child_controls.Count > 0 &&
  1414. (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
  1415. return FindControlForward(start, null);
  1416. }
  1417. else {
  1418. while (start != container) {
  1419. found = FindFlatForward(start.parent, start);
  1420. if (found != null) {
  1421. return found;
  1422. }
  1423. start = start.parent;
  1424. }
  1425. }
  1426. return null;
  1427. }
  1428. private static Control FindFlatBackward(Control container, Control start) {
  1429. Control found;
  1430. int index;
  1431. int end;
  1432. bool hit;
  1433. found = null;
  1434. end = container.child_controls.Count;
  1435. hit = false;
  1436. if (start != null) {
  1437. index = start.tab_index;
  1438. } else {
  1439. index = int.MaxValue;
  1440. }
  1441. for (int i = end - 1; i >= 0; i--) {
  1442. if (start == container.child_controls[i]) {
  1443. hit = true;
  1444. continue;
  1445. }
  1446. if (found == null || found.tab_index < container.child_controls[i].tab_index) {
  1447. if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
  1448. found = container.child_controls[i];
  1449. }
  1450. }
  1451. return found;
  1452. }
  1453. private static Control FindControlBackward(Control container, Control start) {
  1454. Control found = null;
  1455. if (start == null) {
  1456. found = FindFlatBackward(container, start);
  1457. }
  1458. else if (start != container) {
  1459. if (start.parent != null) {
  1460. found = FindFlatBackward(start.parent, start);
  1461. if (found == null) {
  1462. if (start.parent != container)
  1463. return start.parent;
  1464. return null;
  1465. }
  1466. }
  1467. }
  1468. if (found == null || start.parent == null)
  1469. found = start;
  1470. while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
  1471. found.child_controls != null && found.child_controls.Count > 0)) {
  1472. // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
  1473. // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
  1474. found = FindFlatBackward(found, null);
  1475. }
  1476. return found;
  1477. /*
  1478. Control found;
  1479. found = null;
  1480. if (start != null) {
  1481. found = FindFlatBackward(start.parent, start);
  1482. if (found == null) {
  1483. if (start.parent != container) {
  1484. return start.parent;
  1485. }
  1486. }
  1487. }
  1488. if (found == null) {
  1489. found = FindFlatBackward(container, start);
  1490. }
  1491. if (container != start) {
  1492. while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
  1493. found = FindControlBackward(found, null);
  1494. if (found != null) {
  1495. return found;
  1496. }
  1497. }
  1498. }
  1499. return found;
  1500. */
  1501. }
  1502. internal virtual void HandleClick(int clicks, MouseEventArgs me) {
  1503. bool standardclick = GetStyle (ControlStyles.StandardClick);
  1504. bool standardclickclick = GetStyle (ControlStyles.StandardDoubleClick);
  1505. if ((clicks > 1) && standardclick && standardclickclick) {
  1506. #if NET_2_0
  1507. OnDoubleClick (me);
  1508. OnMouseDoubleClick (me);
  1509. #else
  1510. OnDoubleClick(EventArgs.Empty);
  1511. #endif
  1512. } else if (clicks == 1 && standardclick && !ValidationFailed) {
  1513. #if NET_2_0
  1514. OnClick (me);
  1515. OnMouseClick (me);
  1516. #else
  1517. OnClick(EventArgs.Empty);
  1518. #endif
  1519. }
  1520. }
  1521. internal void CaptureWithConfine (Control ConfineWindow) {
  1522. if (this.IsHandleCreated && !is_captured) {
  1523. is_captured = true;
  1524. XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
  1525. }
  1526. }
  1527. private void CheckDataBindings () {
  1528. if (data_bindings == null)
  1529. return;
  1530. foreach (Binding binding in data_bindings) {
  1531. binding.Check ();
  1532. }
  1533. }
  1534. private void ChangeParent(Control new_parent) {
  1535. bool pre_enabled;
  1536. bool pre_visible;
  1537. Font pre_font;
  1538. Color pre_fore_color;
  1539. Color pre_back_color;
  1540. RightToLeft pre_rtl;
  1541. // These properties are inherited from our parent
  1542. // Get them pre parent-change and then send events
  1543. // if they are changed after we have our new parent
  1544. pre_enabled = Enabled;
  1545. pre_visible = Visible;
  1546. pre_font = Font;
  1547. pre_fore_color = ForeColor;
  1548. pre_back_color = BackColor;
  1549. pre_rtl = RightToLeft;
  1550. // MS doesn't seem to send a CursorChangedEvent
  1551. parent = new_parent;
  1552. Form frm = this as Form;
  1553. if (frm != null) {
  1554. frm.ChangingParent (new_parent);
  1555. } else if (IsHandleCreated) {
  1556. IntPtr parent_handle = IntPtr.Zero;
  1557. if (new_parent != null && new_parent.IsHandleCreated)
  1558. parent_handle = new_parent.Handle;
  1559. XplatUI.SetParent (Handle, parent_handle);
  1560. }
  1561. OnParentChanged(EventArgs.Empty);
  1562. if (pre_enabled != Enabled) {
  1563. OnEnabledChanged(EventArgs.Empty);
  1564. }
  1565. if (pre_visible != Visible) {
  1566. OnVisibleChanged(EventArgs.Empty);
  1567. }
  1568. if (pre_font != Font) {
  1569. OnFontChanged(EventArgs.Empty);
  1570. }
  1571. if (pre_fore_color != ForeColor) {
  1572. OnForeColorChanged(EventArgs.Empty);
  1573. }
  1574. if (pre_back_color != BackColor) {
  1575. OnBackColorChanged(EventArgs.Empty);
  1576. }
  1577. if (pre_rtl != RightToLeft) {
  1578. // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
  1579. // because when RTL changes they have to recreate the win32 control
  1580. // We don't really need that (until someone runs into compatibility issues)
  1581. OnRightToLeftChanged(EventArgs.Empty);
  1582. }
  1583. if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
  1584. CreateControl();
  1585. }
  1586. if ((binding_context == null) && Created) {
  1587. OnBindingContextChanged(EventArgs.Empty);
  1588. }
  1589. }
  1590. // Sometimes we need to do this calculation without it being virtual (constructor)
  1591. internal Size InternalSizeFromClientSize (Size clientSize)
  1592. {
  1593. Rectangle ClientRect;
  1594. Rectangle WindowRect;
  1595. CreateParams cp;
  1596. ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
  1597. cp = this.CreateParams;
  1598. if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
  1599. return new Size (WindowRect.Width, WindowRect.Height);
  1600. return Size.Empty;
  1601. }
  1602. internal Size ClientSizeFromSize (Size size)
  1603. {
  1604. // Calling this gives us the difference in Size and ClientSize.
  1605. // We just have to apply that difference to our given size.
  1606. Size client_size = this.InternalSizeFromClientSize (size);
  1607. if (client_size == Size.Empty)
  1608. return Size.Empty;
  1609. return new Size (size.Width - (client_size.Width - size.Width), size.Height - (client_size.Height - size.Height));
  1610. }
  1611. internal CreateParams GetCreateParams ()
  1612. {
  1613. return CreateParams;
  1614. }
  1615. #if NET_2_0
  1616. internal virtual Size GetPreferredSizeCore (Size proposedSize)
  1617. {
  1618. return this.explicit_bounds.Size;
  1619. }
  1620. #endif
  1621. private void UpdateDistances() {
  1622. if (parent != null) {
  1623. if (bounds.Width >= 0)
  1624. dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
  1625. if (bounds.Height >= 0)
  1626. dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
  1627. recalculate_distances = false;
  1628. }
  1629. }
  1630. private Cursor GetAvailableCursor ()
  1631. {
  1632. if (Cursor != null && Enabled) {
  1633. return Cursor;
  1634. }
  1635. if (Parent != null) {
  1636. return Parent.GetAvailableCursor ();
  1637. }
  1638. return Cursors.Default;
  1639. }
  1640. private void UpdateCursor ()
  1641. {
  1642. if (!IsHandleCreated)
  1643. return;
  1644. if (!Enabled) {
  1645. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1646. return;
  1647. }
  1648. Point pt = PointToClient (Cursor.Position);
  1649. if ((!bounds.Contains (pt) && !Capture) || (GetChildAtPoint (pt) != null))
  1650. return;
  1651. if (cursor != null || use_wait_cursor) {
  1652. XplatUI.SetCursor (window.Handle, Cursor.handle);
  1653. } else {
  1654. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1655. }
  1656. }
  1657. private bool UseDoubleBuffering {
  1658. get {
  1659. if (!ThemeEngine.Current.DoubleBufferingSupported)
  1660. return false;
  1661. // Since many of .Net's controls are unmanaged, they are doublebuffered
  1662. // even though their bits may not be set in managed land. This allows
  1663. // us to doublebuffer as well without affecting public style bits.
  1664. if (force_double_buffer)
  1665. return true;
  1666. #if NET_2_0
  1667. if (DoubleBuffered)
  1668. return true;
  1669. #endif
  1670. return (control_style & ControlStyles.DoubleBuffer) != 0;
  1671. }
  1672. }
  1673. internal void OnSizeInitializedOrChanged ()
  1674. {
  1675. Form form = this as Form;
  1676. if (form != null && form.WindowManager != null)
  1677. ThemeEngine.Current.ManagedWindowOnSizeInitializedOrChanged (form);
  1678. }
  1679. #endregion // Private & Internal Methods
  1680. #region Public Static Properties
  1681. public static Color DefaultBackColor {
  1682. get {
  1683. return ThemeEngine.Current.DefaultControlBackColor;
  1684. }
  1685. }
  1686. public static Font DefaultFont {
  1687. get {
  1688. return ThemeEngine.Current.DefaultFont;
  1689. }
  1690. }
  1691. public static Color DefaultForeColor {
  1692. get {
  1693. return ThemeEngine.Current.DefaultControlForeColor;
  1694. }
  1695. }
  1696. public static Keys ModifierKeys {
  1697. get {
  1698. return XplatUI.State.ModifierKeys;
  1699. }
  1700. }
  1701. public static MouseButtons MouseButtons {
  1702. get {
  1703. return XplatUI.State.MouseButtons;
  1704. }
  1705. }
  1706. public static Point MousePosition {
  1707. get {
  1708. return Cursor.Position;
  1709. }
  1710. }
  1711. #if NET_2_0
  1712. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1713. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1714. [Browsable (false)]
  1715. [MonoTODO]
  1716. public static bool CheckForIllegalCrossThreadCalls
  1717. {
  1718. get {
  1719. return verify_thread_handle;
  1720. }
  1721. set {
  1722. verify_thread_handle = value;
  1723. }
  1724. }
  1725. #endif
  1726. #endregion // Public Static Properties
  1727. #region Public Instance Properties
  1728. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1729. [Browsable(false)]
  1730. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1731. public AccessibleObject AccessibilityObject {
  1732. get {
  1733. if (accessibility_object==null) {
  1734. accessibility_object=CreateAccessibilityInstance();
  1735. }
  1736. return accessibility_object;
  1737. }
  1738. }
  1739. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1740. [Browsable(false)]
  1741. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1742. public string AccessibleDefaultActionDescription {
  1743. get {
  1744. return accessible_default_action;
  1745. }
  1746. set {
  1747. accessible_default_action = value;
  1748. }
  1749. }
  1750. [Localizable(true)]
  1751. [DefaultValue(null)]
  1752. [MWFCategory("Accessibility")]
  1753. public string AccessibleDescription {
  1754. get {
  1755. return accessible_description;
  1756. }
  1757. set {
  1758. accessible_description = value;
  1759. }
  1760. }
  1761. [Localizable(true)]
  1762. [DefaultValue(null)]
  1763. [MWFCategory("Accessibility")]
  1764. public string AccessibleName {
  1765. get {
  1766. return accessible_name;
  1767. }
  1768. set {
  1769. accessible_name = value;
  1770. }
  1771. }
  1772. [DefaultValue(AccessibleRole.Default)]
  1773. [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
  1774. public AccessibleRole AccessibleRole {
  1775. get {
  1776. return accessible_role;
  1777. }
  1778. set {
  1779. accessible_role = value;
  1780. }
  1781. }
  1782. [DefaultValue(false)]
  1783. [MWFCategory("Behavior")]
  1784. public virtual bool AllowDrop {
  1785. get {
  1786. return allow_drop;
  1787. }
  1788. set {
  1789. if (allow_drop == value)
  1790. return;
  1791. allow_drop = value;
  1792. if (IsHandleCreated) {
  1793. UpdateStyles();
  1794. XplatUI.SetAllowDrop (Handle, value);
  1795. }
  1796. }
  1797. }
  1798. [Localizable(true)]
  1799. [RefreshProperties(RefreshProperties.Repaint)]
  1800. [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
  1801. [MWFCategory("Layout")]
  1802. public virtual AnchorStyles Anchor {
  1803. get {
  1804. return anchor_style;
  1805. }
  1806. set {
  1807. layout_type = LayoutType.Anchor;
  1808. if (anchor_style == value)
  1809. return;
  1810. anchor_style=value;
  1811. dock_style = DockStyle.None;
  1812. UpdateDistances ();
  1813. if (parent != null)
  1814. parent.PerformLayout(this, "Anchor");
  1815. }
  1816. }
  1817. #if NET_2_0
  1818. [Browsable (false)]
  1819. [DefaultValue (typeof (Point), "0, 0")]
  1820. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1821. public virtual Point AutoScrollOffset {
  1822. get {
  1823. return auto_scroll_offset;
  1824. }
  1825. set {
  1826. this.auto_scroll_offset = value;
  1827. }
  1828. }
  1829. // XXX: Implement me!
  1830. bool auto_size;
  1831. [RefreshProperties (RefreshProperties.All)]
  1832. [Localizable (true)]
  1833. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1834. [Browsable (false)]
  1835. [EditorBrowsable (EditorBrowsableState.Never)]
  1836. [DefaultValue (false)]
  1837. public virtual bool AutoSize {
  1838. get { return auto_size; }
  1839. set {
  1840. if (this.auto_size != value) {
  1841. auto_size = value;
  1842. // If we're turning this off, reset our size
  1843. if (!value) {
  1844. Size = explicit_bounds.Size;
  1845. } else {
  1846. if (Parent != null)
  1847. Parent.PerformLayout (this, "AutoSize");
  1848. }
  1849. OnAutoSizeChanged (EventArgs.Empty);
  1850. }
  1851. }
  1852. }
  1853. #if NET_2_0
  1854. [AmbientValue ("{Width=0, Height=0}")]
  1855. #else
  1856. [AmbientValue (typeof(Size), "0, 0")]
  1857. #endif
  1858. [MWFCategory("Layout")]
  1859. public virtual Size MaximumSize {
  1860. get {
  1861. return maximum_size;
  1862. }
  1863. set {
  1864. if (maximum_size != value) {
  1865. maximum_size = value;
  1866. Size = PreferredSize;
  1867. }
  1868. }
  1869. }
  1870. internal bool ShouldSerializeMaximumSize ()
  1871. {
  1872. return this.MaximumSize != DefaultMaximumSize;
  1873. }
  1874. [MWFCategory("Layout")]
  1875. public virtual Size MinimumSize {
  1876. get {
  1877. return minimum_size;
  1878. }
  1879. set {
  1880. if (minimum_size != value) {
  1881. minimum_size = value;
  1882. Size = PreferredSize;
  1883. }
  1884. }
  1885. }
  1886. internal bool ShouldSerializeMinimumSize ()
  1887. {
  1888. return this.MinimumSize != DefaultMinimumSize;
  1889. }
  1890. #endif // NET_2_0
  1891. [DispId(-501)]
  1892. [MWFCategory("Appearance")]
  1893. public virtual Color BackColor {
  1894. get {
  1895. if (background_color.IsEmpty) {
  1896. if (parent!=null) {
  1897. Color pcolor = parent.BackColor;
  1898. if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
  1899. return pcolor;
  1900. }
  1901. return DefaultBackColor;
  1902. }
  1903. return background_color;
  1904. }
  1905. set {
  1906. if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
  1907. throw new ArgumentException("Transparent background colors are not supported on this control");
  1908. }
  1909. if (background_color != value) {
  1910. background_color=value;
  1911. SetChildColor(this);
  1912. OnBackColorChanged(EventArgs.Empty);
  1913. Invalidate();
  1914. }
  1915. }
  1916. }
  1917. internal bool ShouldSerializeBackColor ()
  1918. {
  1919. return this.BackColor != DefaultBackColor;
  1920. }
  1921. [Localizable(true)]
  1922. [DefaultValue(null)]
  1923. [MWFCategory("Appearance")]
  1924. public virtual Image BackgroundImage {
  1925. get {
  1926. return background_image;
  1927. }
  1928. set {
  1929. if (background_image!=value) {
  1930. background_image=value;
  1931. OnBackgroundImageChanged(EventArgs.Empty);
  1932. Invalidate ();
  1933. }
  1934. }
  1935. }
  1936. #if NET_2_0
  1937. [DefaultValue (ImageLayout.Tile)]
  1938. [Localizable (true)]
  1939. [MWFCategory("Appearance")]
  1940. public virtual ImageLayout BackgroundImageLayout {
  1941. get {
  1942. return backgroundimage_layout;
  1943. }
  1944. set {
  1945. if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
  1946. throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
  1947. if (value != backgroundimage_layout) {
  1948. backgroundimage_layout = value;
  1949. Invalidate ();
  1950. OnBackgroundImageLayoutChanged (EventArgs.Empty);
  1951. }
  1952. }
  1953. }
  1954. #endif
  1955. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1956. [Browsable(false)]
  1957. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1958. public virtual BindingContext BindingContext {
  1959. get {
  1960. if (binding_context != null)
  1961. return binding_context;
  1962. if (Parent == null)
  1963. return null;
  1964. binding_context = Parent.BindingContext;
  1965. return binding_context;
  1966. }
  1967. set {
  1968. if (binding_context != value) {
  1969. binding_context = value;
  1970. OnBindingContextChanged(EventArgs.Empty);
  1971. }
  1972. }
  1973. }
  1974. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1975. [Browsable(false)]
  1976. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1977. public int Bottom {
  1978. get {
  1979. return bounds.Y+bounds.Height;
  1980. }
  1981. }
  1982. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1983. [Browsable(false)]
  1984. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1985. public Rectangle Bounds {
  1986. get {
  1987. return this.bounds;
  1988. }
  1989. set {
  1990. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  1991. }
  1992. }
  1993. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1994. [Browsable(false)]
  1995. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1996. public bool CanFocus {
  1997. get {
  1998. if (IsHandleCreated && Visible && Enabled) {
  1999. return true;
  2000. }
  2001. return false;
  2002. }
  2003. }
  2004. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2005. [Browsable(false)]
  2006. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2007. public bool CanSelect {
  2008. get {
  2009. Control parent;
  2010. if (!GetStyle(ControlStyles.Selectable)) {
  2011. return false;
  2012. }
  2013. parent = this;
  2014. while (parent != null) {
  2015. if (!parent.is_visible || !parent.is_enabled) {
  2016. return false;
  2017. }
  2018. parent = parent.parent;
  2019. }
  2020. return true;
  2021. }
  2022. }
  2023. internal virtual bool InternalCapture {
  2024. get {
  2025. return Capture;
  2026. }
  2027. set {
  2028. Capture = value;
  2029. }
  2030. }
  2031. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2032. [Browsable(false)]
  2033. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2034. public bool Capture {
  2035. get {
  2036. return this.is_captured;
  2037. }
  2038. set {
  2039. // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
  2040. if (value != is_captured) {
  2041. if (value) {
  2042. is_captured = true;
  2043. XplatUI.GrabWindow(Handle, IntPtr.Zero);
  2044. } else {
  2045. if (IsHandleCreated)
  2046. XplatUI.UngrabWindow(Handle);
  2047. is_captured = false;
  2048. }
  2049. }
  2050. }
  2051. }
  2052. [DefaultValue(true)]
  2053. [MWFCategory("Focus")]
  2054. public bool CausesValidation {
  2055. get {
  2056. return this.causes_validation;
  2057. }
  2058. set {
  2059. if (this.causes_validation != value) {
  2060. causes_validation = value;
  2061. OnCausesValidationChanged(EventArgs.Empty);
  2062. }
  2063. }
  2064. }
  2065. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2066. [Browsable(false)]
  2067. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2068. public Rectangle ClientRectangle {
  2069. get {
  2070. client_rect.Width = client_size.Width;
  2071. client_rect.Height = client_size.Height;
  2072. return client_rect;
  2073. }
  2074. }
  2075. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2076. [Browsable(false)]
  2077. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2078. public Size ClientSize {
  2079. get {
  2080. #if notneeded
  2081. if ((this is Form) && (((Form)this).form_parent_window != null)) {
  2082. return ((Form)this).form_parent_window.ClientSize;
  2083. }
  2084. #endif
  2085. return client_size;
  2086. }
  2087. set {
  2088. this.SetClientSizeCore(value.Width, value.Height);
  2089. #if NET_2_0
  2090. this.OnClientSizeChanged (EventArgs.Empty);
  2091. #endif
  2092. }
  2093. }
  2094. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2095. [Browsable(false)]
  2096. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2097. [DescriptionAttribute("ControlCompanyNameDescr")]
  2098. public String CompanyName {
  2099. get {
  2100. return "Mono Project, Novell, Inc.";
  2101. }
  2102. }
  2103. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2104. [Browsable(false)]
  2105. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2106. public bool ContainsFocus {
  2107. get {
  2108. IntPtr focused_window;
  2109. focused_window = XplatUI.GetFocus();
  2110. if (IsHandleCreated) {
  2111. if (focused_window == Handle) {
  2112. return true;
  2113. }
  2114. for (int i=0; i < child_controls.Count; i++) {
  2115. if (child_controls[i].ContainsFocus) {
  2116. return true;
  2117. }
  2118. }
  2119. }
  2120. return false;
  2121. }
  2122. }
  2123. #if NET_2_0
  2124. [Browsable (false)]
  2125. #endif
  2126. [DefaultValue(null)]
  2127. [MWFCategory("Behavior")]
  2128. public virtual ContextMenu ContextMenu {
  2129. get {
  2130. return ContextMenuInternal;
  2131. }
  2132. set {
  2133. ContextMenuInternal = value;
  2134. }
  2135. }
  2136. internal virtual ContextMenu ContextMenuInternal {
  2137. get {
  2138. return context_menu;
  2139. }
  2140. set {
  2141. if (context_menu != value) {
  2142. context_menu = value;
  2143. OnContextMenuChanged (EventArgs.Empty);
  2144. }
  2145. }
  2146. }
  2147. #if NET_2_0
  2148. [DefaultValue (null)]
  2149. [MWFCategory("Behavior")]
  2150. public virtual ContextMenuStrip ContextMenuStrip {
  2151. get { return this.context_menu_strip; }
  2152. set {
  2153. if (this.context_menu_strip != value) {
  2154. this.context_menu_strip = value;
  2155. OnContextMenuStripChanged (EventArgs.Empty);
  2156. }
  2157. }
  2158. }
  2159. #endif
  2160. [Browsable(false)]
  2161. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2162. public ControlCollection Controls {
  2163. get {
  2164. return this.child_controls;
  2165. }
  2166. }
  2167. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2168. [Browsable(false)]
  2169. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2170. public bool Created {
  2171. get {
  2172. return (!is_disposed && is_created);
  2173. }
  2174. }
  2175. [AmbientValue(null)]
  2176. [MWFCategory("Appearance")]
  2177. public virtual Cursor Cursor {
  2178. get {
  2179. #if NET_2_0
  2180. if (use_wait_cursor)
  2181. return Cursors.WaitCursor;
  2182. #endif
  2183. if (cursor != null) {
  2184. return cursor;
  2185. }
  2186. if (parent != null) {
  2187. return parent.Cursor;
  2188. }
  2189. return Cursors.Default;
  2190. }
  2191. set {
  2192. if (cursor == value) {
  2193. return;
  2194. }
  2195. cursor = value;
  2196. UpdateCursor ();
  2197. OnCursorChanged (EventArgs.Empty);
  2198. }
  2199. }
  2200. internal bool ShouldSerializeCursor ()
  2201. {
  2202. return this.Cursor != Cursors.Default;
  2203. }
  2204. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2205. [ParenthesizePropertyName(true)]
  2206. [RefreshProperties(RefreshProperties.All)]
  2207. [MWFCategory("Data")]
  2208. public ControlBindingsCollection DataBindings {
  2209. get {
  2210. if (data_bindings == null)
  2211. data_bindings = new ControlBindingsCollection (this);
  2212. return data_bindings;
  2213. }
  2214. }
  2215. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2216. [Browsable(false)]
  2217. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2218. public virtual Rectangle DisplayRectangle {
  2219. get {
  2220. return ClientRectangle;
  2221. }
  2222. }
  2223. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2224. [Browsable(false)]
  2225. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2226. public bool Disposing {
  2227. get {
  2228. return is_disposed;
  2229. }
  2230. }
  2231. [Localizable(true)]
  2232. [RefreshProperties(RefreshProperties.Repaint)]
  2233. [DefaultValue(DockStyle.None)]
  2234. [MWFCategory("Layout")]
  2235. public virtual DockStyle Dock {
  2236. get {
  2237. return dock_style;
  2238. }
  2239. set {
  2240. // If the user sets this to None, we need to still use Anchor layout
  2241. if (value != DockStyle.None)
  2242. layout_type = LayoutType.Dock;
  2243. if (dock_style == value) {
  2244. return;
  2245. }
  2246. if (!Enum.IsDefined (typeof (DockStyle), value)) {
  2247. throw new InvalidEnumArgumentException ("value", (int) value,
  2248. typeof (DockStyle));
  2249. }
  2250. dock_style = value;
  2251. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  2252. if (dock_style == DockStyle.None) {
  2253. bounds = explicit_bounds;
  2254. layout_type = LayoutType.Anchor;
  2255. }
  2256. if (parent != null)
  2257. parent.PerformLayout(this, "Dock");
  2258. else if (Controls.Count > 0)
  2259. PerformLayout ();
  2260. OnDockChanged(EventArgs.Empty);
  2261. }
  2262. }
  2263. #if NET_2_0
  2264. protected virtual bool DoubleBuffered {
  2265. get {
  2266. return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
  2267. }
  2268. set {
  2269. if (value == DoubleBuffered)
  2270. return;
  2271. if (value) {
  2272. SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
  2273. } else {
  2274. SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
  2275. }
  2276. }
  2277. }
  2278. public void DrawToBitmap (Bitmap bitmap, Rectangle targetBounds)
  2279. {
  2280. Graphics g = Graphics.FromImage (bitmap);
  2281. // Only draw within the target bouds, and up to the size of the control
  2282. g.IntersectClip (targetBounds);
  2283. g.IntersectClip (Bounds);
  2284. // Logic copied from WmPaint
  2285. PaintEventArgs pea = new PaintEventArgs (g, targetBounds);
  2286. if (!GetStyle (ControlStyles.Opaque))
  2287. OnPaintBackground (pea);
  2288. OnPaintBackgroundInternal (pea);
  2289. OnPaintInternal (pea);
  2290. if (!pea.Handled)
  2291. OnPaint (pea);
  2292. g.Dispose ();
  2293. }
  2294. #endif
  2295. [DispId(-514)]
  2296. [Localizable(true)]
  2297. [MWFCategory("Behavior")]
  2298. public bool Enabled {
  2299. get {
  2300. if (!is_enabled) {
  2301. return false;
  2302. }
  2303. if (parent != null) {
  2304. return parent.Enabled;
  2305. }
  2306. return true;
  2307. }
  2308. set {
  2309. if (this.is_enabled == value)
  2310. return;
  2311. bool old_value = is_enabled;
  2312. is_enabled = value;
  2313. if (!value)
  2314. UpdateCursor ();
  2315. if (old_value != value && !value && this.has_focus)
  2316. SelectNextControl(this, true, true, true, true);
  2317. OnEnabledChanged (EventArgs.Empty);
  2318. }
  2319. }
  2320. internal bool ShouldSerializeEnabled ()
  2321. {
  2322. return this.Enabled != true;
  2323. }
  2324. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2325. [Browsable(false)]
  2326. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2327. public virtual bool Focused {
  2328. get {
  2329. return this.has_focus;
  2330. }
  2331. }
  2332. [DispId(-512)]
  2333. [AmbientValue(null)]
  2334. [Localizable(true)]
  2335. [MWFCategory("Appearance")]
  2336. public virtual Font Font {
  2337. #if NET_2_0
  2338. [return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Font))]
  2339. #endif
  2340. get {
  2341. if (font != null)
  2342. return font;
  2343. if (parent != null) {
  2344. Font f = parent.Font;
  2345. if (f != null)
  2346. return f;
  2347. }
  2348. return DefaultFont;
  2349. }
  2350. [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
  2351. set {
  2352. if (font != null && font == value) {
  2353. return;
  2354. }
  2355. font = value;
  2356. Invalidate();
  2357. OnFontChanged (EventArgs.Empty);
  2358. PerformLayout ();
  2359. }
  2360. }
  2361. internal bool ShouldSerializeFont ()
  2362. {
  2363. return !this.Font.Equals (DefaultFont);
  2364. }
  2365. [DispId(-513)]
  2366. [MWFCategory("Appearance")]
  2367. public virtual Color ForeColor {
  2368. get {
  2369. if (foreground_color.IsEmpty) {
  2370. if (parent!=null) {
  2371. return parent.ForeColor;
  2372. }
  2373. return DefaultForeColor;
  2374. }
  2375. return foreground_color;
  2376. }
  2377. set {
  2378. if (foreground_color != value) {
  2379. foreground_color=value;
  2380. Invalidate();
  2381. OnForeColorChanged(EventArgs.Empty);
  2382. }
  2383. }
  2384. }
  2385. internal bool ShouldSerializeForeColor ()
  2386. {
  2387. return this.ForeColor != DefaultForeColor;
  2388. }
  2389. [DispId(-515)]
  2390. [Browsable(false)]
  2391. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2392. public IntPtr Handle { // IWin32Window
  2393. get {
  2394. #if NET_2_0
  2395. if (verify_thread_handle) {
  2396. if (this.InvokeRequired) {
  2397. throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
  2398. }
  2399. }
  2400. #endif
  2401. if (!IsHandleCreated) {
  2402. CreateHandle();
  2403. }
  2404. return window.Handle;
  2405. }
  2406. }
  2407. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2408. [Browsable(false)]
  2409. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2410. public bool HasChildren {
  2411. get {
  2412. if (this.child_controls.Count>0) {
  2413. return true;
  2414. }
  2415. return false;
  2416. }
  2417. }
  2418. [EditorBrowsable(EditorBrowsableState.Always)]
  2419. [Browsable(false)]
  2420. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2421. public int Height {
  2422. get { return this.bounds.Height; }
  2423. set { SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height); }
  2424. }
  2425. [AmbientValue(ImeMode.Inherit)]
  2426. [Localizable(true)]
  2427. [MWFCategory("Behavior")]
  2428. public ImeMode ImeMode {
  2429. get {
  2430. if (ime_mode == ImeMode.Inherit) {
  2431. if (parent != null)
  2432. return parent.ImeMode;
  2433. else
  2434. return ImeMode.NoControl; // default value
  2435. }
  2436. return ime_mode;
  2437. }
  2438. set {
  2439. if (ime_mode != value) {
  2440. ime_mode = value;
  2441. OnImeModeChanged(EventArgs.Empty);
  2442. }
  2443. }
  2444. }
  2445. internal bool ShouldSerializeImeMode ()
  2446. {
  2447. return this.ImeMode != ImeMode.NoControl;
  2448. }
  2449. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2450. [Browsable(false)]
  2451. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2452. public bool InvokeRequired { // ISynchronizeInvoke
  2453. get {
  2454. if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
  2455. return true;
  2456. }
  2457. return false;
  2458. }
  2459. }
  2460. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2461. [Browsable(false)]
  2462. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2463. public bool IsAccessible {
  2464. get {
  2465. return is_accessible;
  2466. }
  2467. set {
  2468. is_accessible = value;
  2469. }
  2470. }
  2471. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2472. [Browsable(false)]
  2473. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2474. public bool IsDisposed {
  2475. get {
  2476. return this.is_disposed;
  2477. }
  2478. }
  2479. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2480. [Browsable(false)]
  2481. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2482. public bool IsHandleCreated {
  2483. get {
  2484. if (window == null || window.Handle == IntPtr.Zero)
  2485. return false;
  2486. Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
  2487. if (hwnd != null && hwnd.zombie)
  2488. return false;
  2489. return true;
  2490. }
  2491. }
  2492. #if NET_2_0
  2493. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2494. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2495. [Browsable(false)]
  2496. [MonoNotSupported ("RTL is not supported")]
  2497. public bool IsMirrored {
  2498. get { return false; }
  2499. }
  2500. #endif
  2501. [Browsable (false)]
  2502. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2503. #if NET_2_0
  2504. public virtual
  2505. #endif
  2506. Layout.LayoutEngine LayoutEngine {
  2507. get {
  2508. if (layout_engine == null)
  2509. layout_engine = new Layout.DefaultLayout ();
  2510. return layout_engine;
  2511. }
  2512. }
  2513. [EditorBrowsable(EditorBrowsableState.Always)]
  2514. [Browsable(false)]
  2515. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2516. public int Left {
  2517. get {
  2518. return this.bounds.X;
  2519. }
  2520. set {
  2521. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  2522. }
  2523. }
  2524. [Localizable(true)]
  2525. [MWFCategory("Layout")]
  2526. public Point Location {
  2527. get {
  2528. return new Point(bounds.X, bounds.Y);
  2529. }
  2530. set {
  2531. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  2532. }
  2533. }
  2534. internal bool ShouldSerializeLocation ()
  2535. {
  2536. return this.Location != new Point (0, 0);
  2537. }
  2538. #if NET_2_0
  2539. [Localizable (true)]
  2540. [MWFCategory("Layout")]
  2541. public Padding Margin {
  2542. get { return this.margin; }
  2543. set {
  2544. if (this.margin != value) {
  2545. this.margin = value;
  2546. if (Parent != null)
  2547. Parent.PerformLayout (this, "Margin");
  2548. OnMarginChanged (EventArgs.Empty);
  2549. }
  2550. }
  2551. }
  2552. internal bool ShouldSerializeMargin ()
  2553. {
  2554. return this.Margin != DefaultMargin;
  2555. }
  2556. #endif
  2557. [Browsable(false)]
  2558. public string Name {
  2559. get {
  2560. return name;
  2561. }
  2562. set {
  2563. name = value;
  2564. }
  2565. }
  2566. #if NET_2_0
  2567. [Localizable(true)]
  2568. [MWFCategory("Layout")]
  2569. public Padding Padding {
  2570. get {
  2571. return padding;
  2572. }
  2573. set {
  2574. if (padding != value) {
  2575. padding = value;
  2576. OnPaddingChanged (EventArgs.Empty);
  2577. // Changing padding generally requires a new size
  2578. if (this.AutoSize && this.Parent != null)
  2579. parent.PerformLayout (this, "Padding");
  2580. else
  2581. PerformLayout (this, "Padding");
  2582. }
  2583. }
  2584. }
  2585. internal bool ShouldSerializePadding ()
  2586. {
  2587. return this.Padding != DefaultPadding;
  2588. }
  2589. #endif
  2590. [Browsable(false)]
  2591. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2592. public Control Parent {
  2593. get {
  2594. return this.parent;
  2595. }
  2596. set {
  2597. if (value == this) {
  2598. throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
  2599. }
  2600. if (parent!=value) {
  2601. if (value==null) {
  2602. parent.Controls.Remove(this);
  2603. parent = null;
  2604. return;
  2605. }
  2606. value.Controls.Add(this);
  2607. }
  2608. }
  2609. }
  2610. #if NET_2_0
  2611. [Browsable (false)]
  2612. public Size PreferredSize {
  2613. get { return this.GetPreferredSize (Size.Empty); }
  2614. }
  2615. #endif
  2616. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2617. [Browsable(false)]
  2618. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2619. public string ProductName {
  2620. get {
  2621. Type t = typeof (AssemblyProductAttribute);
  2622. Assembly assembly = GetType().Module.Assembly;
  2623. object [] attrs = assembly.GetCustomAttributes (t, false);
  2624. AssemblyProductAttribute a = null;
  2625. // On MS we get a NullRefException if product attribute is not
  2626. // set.
  2627. if (attrs != null && attrs.Length > 0)
  2628. a = (AssemblyProductAttribute) attrs [0];
  2629. if (a == null) {
  2630. return GetType ().Namespace;
  2631. }
  2632. return a.Product;
  2633. }
  2634. }
  2635. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2636. [Browsable(false)]
  2637. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2638. public string ProductVersion {
  2639. get {
  2640. Type t = typeof (AssemblyVersionAttribute);
  2641. Assembly assembly = GetType().Module.Assembly;
  2642. object [] attrs = assembly.GetCustomAttributes (t, false);
  2643. if (attrs == null || attrs.Length < 1)
  2644. return "1.0.0.0";
  2645. return ((AssemblyVersionAttribute)attrs [0]).Version;
  2646. }
  2647. }
  2648. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2649. [Browsable(false)]
  2650. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2651. public bool RecreatingHandle {
  2652. get {
  2653. return is_recreating;
  2654. }
  2655. }
  2656. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2657. [Browsable(false)]
  2658. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2659. public Region Region {
  2660. get {
  2661. return clip_region;
  2662. }
  2663. set {
  2664. if (clip_region != value) {
  2665. if (IsHandleCreated)
  2666. XplatUI.SetClipRegion(Handle, value);
  2667. clip_region = value;
  2668. #if NET_2_0
  2669. OnRegionChanged (EventArgs.Empty);
  2670. #endif
  2671. }
  2672. }
  2673. }
  2674. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2675. [Browsable(false)]
  2676. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2677. public int Right {
  2678. get {
  2679. return this.bounds.X+this.bounds.Width;
  2680. }
  2681. }
  2682. [AmbientValue(RightToLeft.Inherit)]
  2683. [Localizable(true)]
  2684. [MWFCategory("Appearance")]
  2685. public virtual RightToLeft RightToLeft {
  2686. get {
  2687. if (right_to_left == RightToLeft.Inherit) {
  2688. if (parent != null)
  2689. return parent.RightToLeft;
  2690. else
  2691. return RightToLeft.No; // default value
  2692. }
  2693. return right_to_left;
  2694. }
  2695. set {
  2696. if (value != right_to_left) {
  2697. right_to_left = value;
  2698. OnRightToLeftChanged(EventArgs.Empty);
  2699. PerformLayout ();
  2700. }
  2701. }
  2702. }
  2703. internal bool ShouldSerializeRightToLeft ()
  2704. {
  2705. return this.RightToLeft != RightToLeft.No;
  2706. }
  2707. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2708. public override ISite Site {
  2709. get {
  2710. return base.Site;
  2711. }
  2712. set {
  2713. base.Site = value;
  2714. if (value != null) {
  2715. AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
  2716. if (ap != null) {
  2717. BackColor = ap.BackColor;
  2718. ForeColor = ap.ForeColor;
  2719. Cursor = ap.Cursor;
  2720. Font = ap.Font;
  2721. }
  2722. }
  2723. }
  2724. }
  2725. internal bool ShouldSerializeSite ()
  2726. {
  2727. return false;
  2728. }
  2729. [Localizable(true)]
  2730. [MWFCategory("Layout")]
  2731. public Size Size {
  2732. get {
  2733. return new Size(Width, Height);
  2734. }
  2735. set {
  2736. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  2737. }
  2738. }
  2739. internal virtual bool ShouldSerializeSize ()
  2740. {
  2741. return this.Size != DefaultSize;
  2742. }
  2743. [Localizable(true)]
  2744. [MergableProperty(false)]
  2745. [MWFCategory("Behavior")]
  2746. public int TabIndex {
  2747. get {
  2748. if (tab_index != -1) {
  2749. return tab_index;
  2750. }
  2751. return 0;
  2752. }
  2753. set {
  2754. if (tab_index != value) {
  2755. tab_index = value;
  2756. OnTabIndexChanged(EventArgs.Empty);
  2757. }
  2758. }
  2759. }
  2760. [DispId(-516)]
  2761. [DefaultValue(true)]
  2762. [MWFCategory("Behavior")]
  2763. public bool TabStop {
  2764. get {
  2765. return tab_stop;
  2766. }
  2767. set {
  2768. if (tab_stop != value) {
  2769. tab_stop = value;
  2770. OnTabStopChanged(EventArgs.Empty);
  2771. }
  2772. }
  2773. }
  2774. [Localizable(false)]
  2775. [Bindable(true)]
  2776. [TypeConverter(typeof(StringConverter))]
  2777. [DefaultValue(null)]
  2778. [MWFCategory("Data")]
  2779. public object Tag {
  2780. get {
  2781. return control_tag;
  2782. }
  2783. set {
  2784. control_tag = value;
  2785. }
  2786. }
  2787. [DispId(-517)]
  2788. [Localizable(true)]
  2789. [BindableAttribute(true)]
  2790. [MWFCategory("Appearance")]
  2791. public virtual string Text {
  2792. get {
  2793. // Our implementation ignores ControlStyles.CacheText - we always cache
  2794. return this.text;
  2795. }
  2796. set {
  2797. if (value == null) {
  2798. value = String.Empty;
  2799. }
  2800. if (text!=value) {
  2801. text=value;
  2802. UpdateWindowText ();
  2803. OnTextChanged (EventArgs.Empty);
  2804. #if NET_2_0
  2805. // Label has its own AutoSize implementation
  2806. if (AutoSize && Parent != null && (!(this is Label)))
  2807. Parent.PerformLayout (this, "Text");
  2808. #endif
  2809. }
  2810. }
  2811. }
  2812. internal virtual void UpdateWindowText ()
  2813. {
  2814. if (!IsHandleCreated) {
  2815. return;
  2816. }
  2817. XplatUI.Text (Handle, text);
  2818. }
  2819. [EditorBrowsable(EditorBrowsableState.Always)]
  2820. [Browsable(false)]
  2821. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2822. public int Top {
  2823. get {
  2824. return this.bounds.Y;
  2825. }
  2826. set {
  2827. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  2828. }
  2829. }
  2830. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2831. [Browsable(false)]
  2832. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2833. public Control TopLevelControl {
  2834. get {
  2835. Control p = this;
  2836. while (p.parent != null) {
  2837. p = p.parent;
  2838. }
  2839. return p is Form ? p : null;
  2840. }
  2841. }
  2842. #if NET_2_0
  2843. [EditorBrowsable(EditorBrowsableState.Always)]
  2844. [Browsable(true)]
  2845. [DefaultValue (false)]
  2846. [MWFCategory("Appearance")]
  2847. public bool UseWaitCursor {
  2848. get { return use_wait_cursor; }
  2849. set {
  2850. if (use_wait_cursor != value) {
  2851. use_wait_cursor = value;
  2852. UpdateCursor ();
  2853. OnCursorChanged (EventArgs.Empty);
  2854. }
  2855. }
  2856. }
  2857. #endif
  2858. [Localizable(true)]
  2859. [MWFCategory("Behavior")]
  2860. public bool Visible {
  2861. get {
  2862. if (!is_visible) {
  2863. return false;
  2864. } else if (parent != null) {
  2865. return parent.Visible;
  2866. }
  2867. return true;
  2868. }
  2869. set {
  2870. if (this.is_visible != value) {
  2871. SetVisibleCore(value);
  2872. if (parent != null)
  2873. parent.PerformLayout (this, "Visible");
  2874. }
  2875. }
  2876. }
  2877. internal bool ShouldSerializeVisible ()
  2878. {
  2879. return this.Visible != true;
  2880. }
  2881. [EditorBrowsable(EditorBrowsableState.Always)]
  2882. [Browsable(false)]
  2883. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2884. public int Width {
  2885. get {
  2886. return this.bounds.Width;
  2887. }
  2888. set {
  2889. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  2890. }
  2891. }
  2892. [EditorBrowsable(EditorBrowsableState.Never)]
  2893. [Browsable(false)]
  2894. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2895. public IWindowTarget WindowTarget {
  2896. get { return window_target; }
  2897. set { window_target = value; }
  2898. }
  2899. #endregion // Public Instance Properties
  2900. #region Protected Instance Properties
  2901. #if NET_2_0
  2902. protected virtual bool CanEnableIme {
  2903. get { return false; }
  2904. }
  2905. // Is only false in some ActiveX contexts
  2906. protected override bool CanRaiseEvents {
  2907. get { return true; }
  2908. }
  2909. #endif
  2910. protected virtual CreateParams CreateParams {
  2911. get {
  2912. CreateParams create_params = new CreateParams();
  2913. try {
  2914. create_params.Caption = Text;
  2915. }
  2916. catch {
  2917. create_params.Caption = text;
  2918. }
  2919. try {
  2920. create_params.X = Left;
  2921. }
  2922. catch {
  2923. create_params.X = this.bounds.X;
  2924. }
  2925. try {
  2926. create_params.Y = Top;
  2927. }
  2928. catch {
  2929. create_params.Y = this.bounds.Y;
  2930. }
  2931. try {
  2932. create_params.Width = Width;
  2933. }
  2934. catch {
  2935. create_params.Width = this.bounds.Width;
  2936. }
  2937. try {
  2938. create_params.Height = Height;
  2939. }
  2940. catch {
  2941. create_params.Height = this.bounds.Height;
  2942. }
  2943. create_params.ClassName = XplatUI.DefaultClassName;
  2944. create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
  2945. create_params.ExStyle = 0;
  2946. create_params.Param = 0;
  2947. if (allow_drop) {
  2948. create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
  2949. }
  2950. if ((parent!=null) && (parent.IsHandleCreated)) {
  2951. create_params.Parent = parent.Handle;
  2952. }
  2953. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  2954. if (is_visible) {
  2955. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  2956. }
  2957. if (!is_enabled) {
  2958. create_params.Style |= (int)WindowStyles.WS_DISABLED;
  2959. }
  2960. switch (border_style) {
  2961. case BorderStyle.FixedSingle:
  2962. create_params.Style |= (int) WindowStyles.WS_BORDER;
  2963. break;
  2964. case BorderStyle.Fixed3D:
  2965. create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
  2966. break;
  2967. }
  2968. create_params.control = this;
  2969. return create_params;
  2970. }
  2971. }
  2972. #if NET_2_0
  2973. protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
  2974. #endif
  2975. protected virtual ImeMode DefaultImeMode {
  2976. get {
  2977. return ImeMode.Inherit;
  2978. }
  2979. }
  2980. #if NET_2_0
  2981. protected virtual Padding DefaultMargin {
  2982. get { return new Padding (3); }
  2983. }
  2984. protected virtual Size DefaultMaximumSize { get { return new Size (); } }
  2985. protected virtual Size DefaultMinimumSize { get { return new Size (); } }
  2986. protected virtual Padding DefaultPadding { get { return new Padding (); } }
  2987. #endif
  2988. protected virtual Size DefaultSize {
  2989. get {
  2990. return new Size(0, 0);
  2991. }
  2992. }
  2993. protected int FontHeight {
  2994. get {
  2995. return Font.Height;
  2996. }
  2997. set {
  2998. ;; // Nothing to do
  2999. }
  3000. }
  3001. #if NET_2_0
  3002. [Obsolete ()]
  3003. #endif
  3004. protected bool RenderRightToLeft {
  3005. get {
  3006. return (this.right_to_left == RightToLeft.Yes);
  3007. }
  3008. }
  3009. protected bool ResizeRedraw {
  3010. get {
  3011. return GetStyle(ControlStyles.ResizeRedraw);
  3012. }
  3013. set {
  3014. SetStyle(ControlStyles.ResizeRedraw, value);
  3015. }
  3016. }
  3017. #if NET_2_0
  3018. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3019. protected virtual bool ScaleChildren {
  3020. get { return ScaleChildrenInternal; }
  3021. }
  3022. #endif
  3023. internal virtual bool ScaleChildrenInternal {
  3024. get { return true; }
  3025. }
  3026. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3027. [Browsable(false)]
  3028. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  3029. protected internal virtual bool ShowFocusCues {
  3030. get {
  3031. if (this is Form)
  3032. return show_focus_cues;
  3033. if (this.parent == null)
  3034. return false;
  3035. Form f = this.FindForm ();
  3036. if (f != null)
  3037. return f.show_focus_cues;
  3038. return false;
  3039. }
  3040. }
  3041. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3042. [Browsable(false)]
  3043. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  3044. #if NET_2_0
  3045. internal virtual
  3046. #endif
  3047. protected bool ShowKeyboardCues {
  3048. get {
  3049. return ShowKeyboardCuesInternal;
  3050. }
  3051. }
  3052. internal bool ShowKeyboardCuesInternal {
  3053. get {
  3054. if (SystemInformation.MenuAccessKeysUnderlined || DesignMode)
  3055. return true;
  3056. return show_keyboard_cues;
  3057. }
  3058. }
  3059. #endregion // Protected Instance Properties
  3060. #region Public Static Methods
  3061. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3062. public static Control FromChildHandle(IntPtr handle) {
  3063. return Control.ControlNativeWindow.ControlFromChildHandle (handle);
  3064. }
  3065. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3066. public static Control FromHandle(IntPtr handle) {
  3067. return Control.ControlNativeWindow.ControlFromHandle(handle);
  3068. }
  3069. #if NET_2_0
  3070. [MonoTODO ("Only implemented for Win32, others always return false")]
  3071. public static bool IsKeyLocked (Keys keyVal)
  3072. {
  3073. switch (keyVal) {
  3074. case Keys.CapsLock:
  3075. case Keys.NumLock:
  3076. case Keys.Scroll:
  3077. return XplatUI.IsKeyLocked ((VirtualKeys)keyVal);
  3078. default:
  3079. throw new NotSupportedException ("keyVal must be CapsLock, NumLock, or ScrollLock");
  3080. }
  3081. }
  3082. #endif
  3083. public static bool IsMnemonic(char charCode, string text) {
  3084. int amp;
  3085. amp = text.IndexOf('&');
  3086. if (amp != -1) {
  3087. if (amp + 1 < text.Length) {
  3088. if (text[amp + 1] != '&') {
  3089. if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
  3090. return true;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. return false;
  3096. }
  3097. #endregion
  3098. #region Protected Static Methods
  3099. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3100. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  3101. Control c;
  3102. c = Control.FromHandle(hWnd);
  3103. if (c != null) {
  3104. c.WndProc(ref m);
  3105. return true;
  3106. }
  3107. return false;
  3108. }
  3109. #endregion
  3110. #region Public Instance Methods
  3111. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3112. public IAsyncResult BeginInvoke(Delegate method) {
  3113. object [] prms = null;
  3114. if (method is EventHandler)
  3115. prms = new object [] { this, EventArgs.Empty };
  3116. return BeginInvokeInternal(method, prms);
  3117. }
  3118. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3119. #if NET_2_0
  3120. public IAsyncResult BeginInvoke (Delegate method, params object[] args)
  3121. #else
  3122. public IAsyncResult BeginInvoke (Delegate method, object[] args)
  3123. #endif
  3124. {
  3125. return BeginInvokeInternal (method, args);
  3126. }
  3127. public void BringToFront() {
  3128. if (parent != null) {
  3129. parent.child_controls.SetChildIndex(this, 0);
  3130. }
  3131. else if (IsHandleCreated) {
  3132. XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
  3133. }
  3134. }
  3135. public bool Contains(Control ctl) {
  3136. while (ctl != null) {
  3137. ctl = ctl.parent;
  3138. if (ctl == this) {
  3139. return true;
  3140. }
  3141. }
  3142. return false;
  3143. }
  3144. public void CreateControl () {
  3145. if (is_created) {
  3146. return;
  3147. }
  3148. if (is_disposing) {
  3149. return;
  3150. }
  3151. if (!is_visible) {
  3152. return;
  3153. }
  3154. if (parent != null && !parent.Created) {
  3155. return;
  3156. }
  3157. if (!IsHandleCreated) {
  3158. CreateHandle();
  3159. }
  3160. if (!is_created) {
  3161. is_created = true;
  3162. // Create all of our children (implicit ones as well) when we are created.
  3163. // The child should fire it's OnLoad before the parents, however
  3164. // if the child checks Parent.Created in it's OnCreateControl, the
  3165. // parent is already created.
  3166. foreach (Control c in Controls.GetAllControls ())
  3167. if (!c.Created && !c.IsDisposed)
  3168. c.CreateControl ();
  3169. #if ONLY_1_1
  3170. if (binding_context == null && parent != null) {
  3171. OnBindingContextChanged(EventArgs.Empty);
  3172. }
  3173. #endif
  3174. OnCreateControl();
  3175. }
  3176. }
  3177. public Graphics CreateGraphics() {
  3178. if (!IsHandleCreated) {
  3179. this.CreateHandle();
  3180. }
  3181. return Graphics.FromHwnd(this.window.Handle);
  3182. }
  3183. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  3184. DragDropEffects result = DragDropEffects.None;
  3185. if (IsHandleCreated)
  3186. result = XplatUI.StartDrag(Handle, data, allowedEffects);
  3187. OnDragDropEnd (result);
  3188. return result;
  3189. }
  3190. internal virtual void OnDragDropEnd (DragDropEffects effects)
  3191. {
  3192. }
  3193. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3194. public object EndInvoke (IAsyncResult asyncResult) {
  3195. AsyncMethodResult result = (AsyncMethodResult) asyncResult;
  3196. return result.EndInvoke ();
  3197. }
  3198. internal Control FindRootParent ()
  3199. {
  3200. Control c = this;
  3201. while (c.Parent != null)
  3202. c = c.Parent;
  3203. return c;
  3204. }
  3205. public Form FindForm() {
  3206. Control c;
  3207. c = this;
  3208. while (c != null) {
  3209. if (c is Form) {
  3210. return (Form)c;
  3211. }
  3212. c = c.Parent;
  3213. }
  3214. return null;
  3215. }
  3216. #if NET_2_0
  3217. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3218. #endif
  3219. public bool Focus() {
  3220. return FocusInternal (false);
  3221. }
  3222. internal virtual bool FocusInternal (bool skip_check) {
  3223. if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
  3224. is_focusing = true;
  3225. Select(this);
  3226. is_focusing = false;
  3227. }
  3228. return has_focus;
  3229. }
  3230. internal Control GetRealChildAtPoint (Point pt) {
  3231. if (!IsHandleCreated)
  3232. CreateHandle ();
  3233. foreach (Control control in child_controls.GetAllControls ()) {
  3234. if (control.Bounds.Contains (PointToClient (pt))) {
  3235. Control child = control.GetRealChildAtPoint (pt);
  3236. if (child == null)
  3237. return control;
  3238. else
  3239. return child;
  3240. }
  3241. }
  3242. return null;
  3243. }
  3244. public Control GetChildAtPoint(Point pt)
  3245. {
  3246. return GetChildAtPoint (pt, GetChildAtPointSkip.None);
  3247. }
  3248. #if NET_2_0
  3249. public
  3250. #endif
  3251. Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
  3252. {
  3253. // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
  3254. // we'll just call CreateHandle instead.
  3255. if (!IsHandleCreated)
  3256. CreateHandle ();
  3257. // Microsoft's version of this function doesn't seem to work, so I can't check
  3258. // if we only consider children or also grandchildren, etc.
  3259. // I'm gonna say 'children only'
  3260. foreach (Control child in Controls) {
  3261. if ((skipValue & GetChildAtPointSkip.Disabled) == GetChildAtPointSkip.Disabled && !child.Enabled)
  3262. continue;
  3263. else if ((skipValue & GetChildAtPointSkip.Invisible) == GetChildAtPointSkip.Invisible && !child.Visible)
  3264. continue;
  3265. else if ((skipValue & GetChildAtPointSkip.Transparent) == GetChildAtPointSkip.Transparent && child.BackColor.A == 0x0)
  3266. continue;
  3267. else if (child.Bounds.Contains (pt))
  3268. return child;
  3269. }
  3270. return null;
  3271. }
  3272. public IContainerControl GetContainerControl() {
  3273. Control current = this;
  3274. while (current!=null) {
  3275. if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  3276. return (IContainerControl)current;
  3277. }
  3278. current = current.parent;
  3279. }
  3280. return null;
  3281. }
  3282. internal ContainerControl InternalGetContainerControl() {
  3283. Control current = this;
  3284. while (current!=null) {
  3285. if ((current is ContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  3286. return current as ContainerControl;
  3287. }
  3288. current = current.parent;
  3289. }
  3290. return null;
  3291. }
  3292. public Control GetNextControl(Control ctl, bool forward) {
  3293. if (!this.Contains(ctl)) {
  3294. ctl = this;
  3295. }
  3296. if (forward) {
  3297. ctl = FindControlForward(this, ctl);
  3298. }
  3299. else {
  3300. ctl = FindControlBackward(this, ctl);
  3301. }
  3302. if (ctl != this) {
  3303. return ctl;
  3304. }
  3305. return null;
  3306. }
  3307. #if NET_2_0
  3308. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3309. public virtual Size GetPreferredSize (Size proposedSize) {
  3310. Size retsize = GetPreferredSizeCore (proposedSize);
  3311. // If we're bigger than the MaximumSize, fix that
  3312. if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
  3313. retsize.Width = this.maximum_size.Width;
  3314. if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
  3315. retsize.Height = this.maximum_size.Height;
  3316. // If we're smaller than the MinimumSize, fix that
  3317. if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
  3318. retsize.Width = this.minimum_size.Width;
  3319. if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
  3320. retsize.Height = this.minimum_size.Height;
  3321. return retsize;
  3322. }
  3323. #endif
  3324. public void Hide() {
  3325. this.Visible = false;
  3326. }
  3327. public void Invalidate() {
  3328. Invalidate(ClientRectangle, false);
  3329. }
  3330. public void Invalidate(bool invalidateChildren) {
  3331. Invalidate(ClientRectangle, invalidateChildren);
  3332. }
  3333. public void Invalidate(System.Drawing.Rectangle rc) {
  3334. Invalidate(rc, false);
  3335. }
  3336. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  3337. // Win32 invalidates control including when Width and Height is equal 0
  3338. // or is not visible, only Paint event must be care about this.
  3339. if (!IsHandleCreated)
  3340. return;
  3341. if (rc == Rectangle.Empty)
  3342. rc = ClientRectangle;
  3343. if (rc.Width > 0 && rc.Height > 0) {
  3344. NotifyInvalidate(rc);
  3345. XplatUI.Invalidate(Handle, rc, false);
  3346. if (invalidateChildren) {
  3347. Control [] controls = child_controls.GetAllControls ();
  3348. for (int i=0; i<controls.Length; i++)
  3349. controls [i].Invalidate ();
  3350. } else {
  3351. // If any of our children are transparent, we
  3352. // have to invalidate them anyways
  3353. foreach (Control c in Controls)
  3354. if (c.BackColor.A != 255)
  3355. c.Invalidate ();
  3356. }
  3357. }
  3358. OnInvalidated(new InvalidateEventArgs(rc));
  3359. }
  3360. public void Invalidate(System.Drawing.Region region) {
  3361. Invalidate(region, false);
  3362. }
  3363. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  3364. RectangleF bounds = region.GetBounds (CreateGraphics ());
  3365. Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
  3366. invalidateChildren);
  3367. }
  3368. public object Invoke (Delegate method) {
  3369. object [] prms = null;
  3370. if (method is EventHandler)
  3371. prms = new object [] { this, EventArgs.Empty };
  3372. return Invoke(method, prms);
  3373. }
  3374. #if NET_2_0
  3375. public object Invoke (Delegate method, params object [] args) {
  3376. #else
  3377. public object Invoke (Delegate method, object[] args) {
  3378. #endif
  3379. Control control = FindControlToInvokeOn ();
  3380. if (!this.InvokeRequired) {
  3381. return method.DynamicInvoke(args);
  3382. }
  3383. IAsyncResult result = BeginInvokeInternal (method, args, control);
  3384. return EndInvoke(result);
  3385. }
  3386. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3387. public void PerformLayout() {
  3388. PerformLayout(null, null);
  3389. }
  3390. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3391. public void PerformLayout(Control affectedControl, string affectedProperty) {
  3392. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  3393. foreach (Control c in Controls.GetAllControls ())
  3394. if (c.recalculate_distances)
  3395. c.UpdateDistances ();
  3396. if (layout_suspended > 0) {
  3397. layout_pending = true;
  3398. return;
  3399. }
  3400. layout_pending = false;
  3401. // Prevent us from getting messed up
  3402. layout_suspended++;
  3403. // Perform all Dock and Anchor calculations
  3404. try {
  3405. OnLayout(levent);
  3406. }
  3407. // Need to make sure we decremend layout_suspended
  3408. finally {
  3409. layout_suspended--;
  3410. }
  3411. }
  3412. public Point PointToClient (Point p) {
  3413. int x = p.X;
  3414. int y = p.Y;
  3415. XplatUI.ScreenToClient (Handle, ref x, ref y);
  3416. return new Point (x, y);
  3417. }
  3418. public Point PointToScreen(Point p) {
  3419. int x = p.X;
  3420. int y = p.Y;
  3421. XplatUI.ClientToScreen(Handle, ref x, ref y);
  3422. return new Point(x, y);
  3423. }
  3424. #if NET_2_0
  3425. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3426. public PreProcessControlState PreProcessControlMessage (ref Message msg)
  3427. {
  3428. return PreProcessControlMessageInternal (ref msg);
  3429. }
  3430. #endif
  3431. internal PreProcessControlState PreProcessControlMessageInternal (ref Message msg)
  3432. {
  3433. switch ((Msg)msg.Msg) {
  3434. case Msg.WM_KEYDOWN:
  3435. case Msg.WM_SYSKEYDOWN:
  3436. #if NET_2_0
  3437. PreviewKeyDownEventArgs e = new PreviewKeyDownEventArgs ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys);
  3438. OnPreviewKeyDown (e);
  3439. if (e.IsInputKey)
  3440. return PreProcessControlState.MessageNeeded;
  3441. #endif
  3442. if (PreProcessMessage (ref msg))
  3443. return PreProcessControlState.MessageProcessed;
  3444. if (IsInputKey ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys))
  3445. return PreProcessControlState.MessageNeeded;
  3446. break;
  3447. case Msg.WM_CHAR:
  3448. case Msg.WM_SYSCHAR:
  3449. if (PreProcessMessage (ref msg))
  3450. return PreProcessControlState.MessageProcessed;
  3451. if (IsInputChar ((char)msg.WParam))
  3452. return PreProcessControlState.MessageNeeded;
  3453. break;
  3454. default:
  3455. break;
  3456. }
  3457. return PreProcessControlState.MessageNotNeeded;
  3458. }
  3459. public virtual bool PreProcessMessage (ref Message msg)
  3460. {
  3461. return InternalPreProcessMessage (ref msg);
  3462. }
  3463. internal virtual bool InternalPreProcessMessage (ref Message msg) {
  3464. Keys key_data;
  3465. if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
  3466. key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
  3467. if (!ProcessCmdKey(ref msg, key_data)) {
  3468. if (IsInputKey(key_data)) {
  3469. return false;
  3470. }
  3471. return ProcessDialogKey(key_data);
  3472. }
  3473. return true;
  3474. } else if (msg.Msg == (int)Msg.WM_CHAR) {
  3475. if (IsInputChar((char)msg.WParam)) {
  3476. return false;
  3477. }
  3478. return ProcessDialogChar((char)msg.WParam);
  3479. } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
  3480. if (ProcessDialogChar((char)msg.WParam))
  3481. return true;
  3482. else
  3483. #if NET_2_0
  3484. return ToolStripManager.ProcessMenuKey (ref msg);
  3485. #else
  3486. return false;
  3487. #endif
  3488. }
  3489. return false;
  3490. }
  3491. public Rectangle RectangleToClient(Rectangle r) {
  3492. return new Rectangle(PointToClient(r.Location), r.Size);
  3493. }
  3494. public Rectangle RectangleToScreen(Rectangle r) {
  3495. return new Rectangle(PointToScreen(r.Location), r.Size);
  3496. }
  3497. public virtual void Refresh() {
  3498. if (IsHandleCreated && Visible) {
  3499. Invalidate();
  3500. XplatUI.UpdateWindow(window.Handle);
  3501. Control [] controls = child_controls.GetAllControls ();
  3502. for (int i=0; i < controls.Length; i++) {
  3503. controls[i].Refresh();
  3504. }
  3505. }
  3506. }
  3507. [EditorBrowsable(EditorBrowsableState.Never)]
  3508. public virtual void ResetBackColor() {
  3509. BackColor = Color.Empty;
  3510. }
  3511. [EditorBrowsable(EditorBrowsableState.Never)]
  3512. public void ResetBindings() {
  3513. if (data_bindings != null)
  3514. data_bindings.Clear();
  3515. }
  3516. [EditorBrowsable(EditorBrowsableState.Never)]
  3517. public virtual void ResetCursor() {
  3518. Cursor = null;
  3519. }
  3520. [EditorBrowsable(EditorBrowsableState.Never)]
  3521. public virtual void ResetFont() {
  3522. font = null;
  3523. }
  3524. [EditorBrowsable(EditorBrowsableState.Never)]
  3525. public virtual void ResetForeColor() {
  3526. foreground_color = Color.Empty;
  3527. }
  3528. [EditorBrowsable(EditorBrowsableState.Never)]
  3529. public void ResetImeMode() {
  3530. ime_mode = DefaultImeMode;
  3531. }
  3532. [EditorBrowsable(EditorBrowsableState.Never)]
  3533. public virtual void ResetRightToLeft() {
  3534. right_to_left = RightToLeft.Inherit;
  3535. }
  3536. public virtual void ResetText() {
  3537. text = String.Empty;
  3538. }
  3539. public void ResumeLayout() {
  3540. ResumeLayout (true);
  3541. }
  3542. public void ResumeLayout(bool performLayout) {
  3543. if (layout_suspended > 0) {
  3544. layout_suspended--;
  3545. }
  3546. if (layout_suspended == 0) {
  3547. #if NET_2_0
  3548. if (this is ContainerControl)
  3549. (this as ContainerControl).PerformDelayedAutoScale();
  3550. #endif
  3551. if (!performLayout)
  3552. foreach (Control c in Controls.GetAllControls ())
  3553. c.UpdateDistances ();
  3554. if (performLayout && layout_pending) {
  3555. PerformLayout();
  3556. }
  3557. }
  3558. }
  3559. #if NET_2_0
  3560. [EditorBrowsable (EditorBrowsableState.Never)]
  3561. [Obsolete ()]
  3562. #endif
  3563. public void Scale(float ratio) {
  3564. ScaleCore(ratio, ratio);
  3565. }
  3566. #if NET_2_0
  3567. [EditorBrowsable (EditorBrowsableState.Never)]
  3568. [Obsolete ()]
  3569. #endif
  3570. public void Scale(float dx, float dy) {
  3571. ScaleCore(dx, dy);
  3572. }
  3573. #if NET_2_0
  3574. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3575. public void Scale (SizeF factor)
  3576. {
  3577. BoundsSpecified bounds_spec = BoundsSpecified.All;
  3578. SuspendLayout ();
  3579. if (this is ContainerControl) {
  3580. if ((this as ContainerControl).IsAutoScaling)
  3581. bounds_spec = BoundsSpecified.Size;
  3582. else if (IsContainerAutoScaling (this.Parent))
  3583. bounds_spec = BoundsSpecified.Location;
  3584. }
  3585. ScaleControl (factor, bounds_spec);
  3586. // Scale children
  3587. if ((bounds_spec != BoundsSpecified.Location) && ScaleChildren) {
  3588. foreach (Control c in Controls.GetAllControls ()) {
  3589. c.Scale (factor);
  3590. if (c is ContainerControl) {
  3591. ContainerControl cc = c as ContainerControl;
  3592. if ((cc.AutoScaleMode == AutoScaleMode.Inherit) && IsContainerAutoScaling (this))
  3593. cc.PerformAutoScale (true);
  3594. }
  3595. }
  3596. }
  3597. ResumeLayout ();
  3598. }
  3599. internal ContainerControl FindContainer (Control c)
  3600. {
  3601. while ((c != null) && !(c is ContainerControl))
  3602. c = c.Parent;
  3603. return c as ContainerControl;
  3604. }
  3605. private bool IsContainerAutoScaling (Control c)
  3606. {
  3607. ContainerControl cc = FindContainer (c);
  3608. return (cc != null) && cc.IsAutoScaling;
  3609. }
  3610. #endif
  3611. public void Select() {
  3612. Select(false, false);
  3613. }
  3614. #if DebugFocus
  3615. private void printTree(Control c, string t) {
  3616. foreach(Control i in c.child_controls) {
  3617. Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
  3618. printTree (i, t+"\t");
  3619. }
  3620. }
  3621. #endif
  3622. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  3623. Control c;
  3624. #if DebugFocus
  3625. Console.WriteLine("{0}", this.FindForm());
  3626. printTree(this, "\t");
  3627. #endif
  3628. if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
  3629. ctl = null;
  3630. }
  3631. c = ctl;
  3632. do {
  3633. c = GetNextControl(c, forward);
  3634. if (c == null) {
  3635. if (wrap) {
  3636. wrap = false;
  3637. continue;
  3638. }
  3639. break;
  3640. }
  3641. #if DebugFocus
  3642. Console.WriteLine("{0} {1}", c, c.CanSelect);
  3643. #endif
  3644. if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
  3645. c.Select (true, true);
  3646. return true;
  3647. }
  3648. } while (c != ctl); // If we wrap back to ourselves we stop
  3649. return false;
  3650. }
  3651. public void SendToBack() {
  3652. if (parent != null) {
  3653. parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
  3654. }
  3655. }
  3656. public void SetBounds(int x, int y, int width, int height) {
  3657. SetBounds(x, y, width, height, BoundsSpecified.All);
  3658. }
  3659. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  3660. // Fill in the values that were not specified
  3661. if ((specified & BoundsSpecified.X) == 0)
  3662. x = Left;
  3663. if ((specified & BoundsSpecified.Y) == 0)
  3664. y = Top;
  3665. if ((specified & BoundsSpecified.Width) == 0)
  3666. width = Width;
  3667. if ((specified & BoundsSpecified.Height) == 0)
  3668. height = Height;
  3669. SetBoundsInternal (x, y, width, height, specified);
  3670. }
  3671. internal void SetBoundsInternal (int x, int y, int width, int height, BoundsSpecified specified)
  3672. {
  3673. // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
  3674. // We can avoid it if:
  3675. // - The requested dimensions are the same as our current dimensions
  3676. // AND
  3677. // - Any BoundsSpecified is the same as our current explicit_size
  3678. if (bounds.X != x || (explicit_bounds.X != x && (specified & BoundsSpecified.X) == BoundsSpecified.X))
  3679. SetBoundsCore (x, y, width, height, specified);
  3680. else if (bounds.Y != y || (explicit_bounds.Y != y && (specified & BoundsSpecified.Y) == BoundsSpecified.Y))
  3681. SetBoundsCore (x, y, width, height, specified);
  3682. else if (bounds.Width != width || (explicit_bounds.Width != width && (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
  3683. SetBoundsCore (x, y, width, height, specified);
  3684. else if (bounds.Height != height || (explicit_bounds.Height != height && (specified & BoundsSpecified.Height) == BoundsSpecified.Height))
  3685. SetBoundsCore (x, y, width, height, specified);
  3686. else
  3687. return;
  3688. // If the user explicitly moved or resized us, recalculate our anchor distances
  3689. if (specified != BoundsSpecified.None)
  3690. UpdateDistances ();
  3691. if (parent != null)
  3692. parent.PerformLayout(this, "Bounds");
  3693. }
  3694. public void Show () {
  3695. this.Visible = true;
  3696. }
  3697. public void SuspendLayout() {
  3698. layout_suspended++;
  3699. }
  3700. public void Update() {
  3701. if (IsHandleCreated) {
  3702. XplatUI.UpdateWindow(window.Handle);
  3703. }
  3704. }
  3705. #endregion // Public Instance Methods
  3706. #region Protected Instance Methods
  3707. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3708. protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
  3709. // turns out this method causes handle
  3710. // creation in 1.1. at first I thought this
  3711. // would be accomplished just by using
  3712. // get_AccessibilityObject, which would route
  3713. // through CreateAccessibilityInstance, which
  3714. // calls CreateControl. This isn't the case,
  3715. // though (as overriding
  3716. // CreateAccessibilityInstance and adding a
  3717. // CWL shows nothing. So we fudge it and put
  3718. // a CreateHandle here.
  3719. #if ONLY_1_1
  3720. CreateHandle ();
  3721. #endif
  3722. if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
  3723. ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
  3724. }
  3725. #if NET_2_0
  3726. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3727. protected void AccessibilityNotifyClients (AccessibleEvents accEvent, int objectID, int childID)
  3728. {
  3729. if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
  3730. ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, objectID, childID);
  3731. }
  3732. #endif
  3733. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3734. protected virtual AccessibleObject CreateAccessibilityInstance() {
  3735. CreateControl ();
  3736. return new Control.ControlAccessibleObject(this);
  3737. }
  3738. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3739. protected virtual ControlCollection CreateControlsInstance() {
  3740. return new ControlCollection(this);
  3741. }
  3742. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3743. protected virtual void CreateHandle() {
  3744. if (IsDisposed) {
  3745. throw new ObjectDisposedException(GetType().FullName);
  3746. }
  3747. if (IsHandleCreated && !is_recreating) {
  3748. return;
  3749. }
  3750. CreateParams create_params = CreateParams;
  3751. window.CreateHandle(create_params);
  3752. if (window.Handle != IntPtr.Zero) {
  3753. creator_thread = Thread.CurrentThread;
  3754. XplatUI.EnableWindow(window.Handle, is_enabled);
  3755. if (clip_region != null) {
  3756. XplatUI.SetClipRegion(window.Handle, clip_region);
  3757. }
  3758. // Set our handle with our parent
  3759. if ((parent != null) && (parent.IsHandleCreated)) {
  3760. XplatUI.SetParent(window.Handle, parent.Handle);
  3761. }
  3762. UpdateStyles();
  3763. XplatUI.SetAllowDrop (window.Handle, allow_drop);
  3764. // Find out where the window manager placed us
  3765. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
  3766. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  3767. }
  3768. Rectangle save_bounds = explicit_bounds;
  3769. UpdateBounds ();
  3770. explicit_bounds = save_bounds;
  3771. }
  3772. }
  3773. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3774. protected virtual void DefWndProc(ref Message m) {
  3775. window.DefWndProc(ref m);
  3776. }
  3777. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3778. protected virtual void DestroyHandle() {
  3779. if (IsHandleCreated) {
  3780. if (window != null) {
  3781. window.DestroyHandle();
  3782. }
  3783. }
  3784. }
  3785. #if NET_2_0
  3786. protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
  3787. {
  3788. // XXX need to implement this.
  3789. return null;
  3790. }
  3791. protected internal AutoSizeMode GetAutoSizeMode ()
  3792. {
  3793. return auto_size_mode;
  3794. }
  3795. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3796. protected virtual Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  3797. {
  3798. // Top level controls do not scale location
  3799. if (!is_toplevel) {
  3800. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  3801. bounds.X = (int)Math.Round (bounds.X * factor.Width);
  3802. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  3803. bounds.Y = (int)Math.Round (bounds.Y * factor.Height);
  3804. }
  3805. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
  3806. int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Width * 2) :
  3807. (this.bounds.Width - this.client_size.Width);
  3808. bounds.Width = (int)Math.Round ((bounds.Width - border) * factor.Width + border);
  3809. }
  3810. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
  3811. int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Height * 2) :
  3812. (this.bounds.Height - this.client_size.Height);
  3813. bounds.Height = (int)Math.Round ((bounds.Height - border) * factor.Height + border);
  3814. }
  3815. return bounds;
  3816. }
  3817. #endif
  3818. private Rectangle GetScaledBoundsOld (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  3819. {
  3820. RectangleF new_bounds = new RectangleF(bounds.Location, bounds.Size);
  3821. // Top level controls do not scale location
  3822. if (!is_toplevel) {
  3823. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  3824. new_bounds.X *= factor.Width;
  3825. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  3826. new_bounds.Y *= factor.Height;
  3827. }
  3828. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
  3829. int border = (this is Form) ? (this.bounds.Width - this.client_size.Width) : 0;
  3830. new_bounds.Width = ((new_bounds.Width - border) * factor.Width + border);
  3831. }
  3832. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
  3833. int border = (this is Form) ? (this.bounds.Height - this.client_size.Height) : 0;
  3834. new_bounds.Height = ((new_bounds.Height - border) * factor.Height + border);
  3835. }
  3836. bounds.X = (int)Math.Round (new_bounds.X);
  3837. bounds.Y = (int)Math.Round (new_bounds.Y);
  3838. bounds.Width = (int)Math.Round (new_bounds.Right) - bounds.X;
  3839. bounds.Height = (int)Math.Round (new_bounds.Bottom) - bounds.Y;
  3840. return bounds;
  3841. }
  3842. protected internal bool GetStyle(ControlStyles flag) {
  3843. return (control_style & flag) != 0;
  3844. }
  3845. protected bool GetTopLevel() {
  3846. return is_toplevel;
  3847. }
  3848. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3849. protected virtual void InitLayout() {
  3850. }
  3851. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3852. protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
  3853. toInvoke.OnGotFocus(e);
  3854. }
  3855. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3856. protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
  3857. toInvoke.OnLostFocus(e);
  3858. }
  3859. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3860. protected void InvokeOnClick(Control toInvoke, EventArgs e) {
  3861. toInvoke.OnClick(e);
  3862. }
  3863. protected void InvokePaint(Control c, PaintEventArgs e) {
  3864. c.OnPaint (e);
  3865. }
  3866. protected void InvokePaintBackground(Control c, PaintEventArgs e) {
  3867. c.OnPaintBackground (e);
  3868. }
  3869. protected virtual bool IsInputChar (char charCode) {
  3870. // XXX on MS.NET this method causes the handle to be created..
  3871. if (!IsHandleCreated)
  3872. CreateHandle ();
  3873. return IsInputCharInternal (charCode);
  3874. }
  3875. internal virtual bool IsInputCharInternal (char charCode) {
  3876. return false;
  3877. }
  3878. protected virtual bool IsInputKey (Keys keyData) {
  3879. // Doc says this one calls IsInputChar; not sure what to do with that
  3880. return false;
  3881. }
  3882. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3883. protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
  3884. // override me?
  3885. }
  3886. protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
  3887. if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
  3888. return true;
  3889. }
  3890. if (parent != null) {
  3891. return parent.ProcessCmdKey(ref msg, keyData);
  3892. }
  3893. return false;
  3894. }
  3895. protected virtual bool ProcessDialogChar(char charCode) {
  3896. if (parent != null) {
  3897. return parent.ProcessDialogChar (charCode);
  3898. }
  3899. return false;
  3900. }
  3901. protected virtual bool ProcessDialogKey (Keys keyData) {
  3902. if (parent != null) {
  3903. return parent.ProcessDialogKey (keyData);
  3904. }
  3905. return false;
  3906. }
  3907. protected virtual bool ProcessKeyEventArgs (ref Message m)
  3908. {
  3909. KeyEventArgs key_event;
  3910. switch (m.Msg) {
  3911. case (int)Msg.WM_SYSKEYDOWN:
  3912. case (int)Msg.WM_KEYDOWN: {
  3913. key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
  3914. OnKeyDown (key_event);
  3915. #if NET_2_0
  3916. suppressing_key_press = key_event.SuppressKeyPress;
  3917. #endif
  3918. return key_event.Handled;
  3919. }
  3920. case (int)Msg.WM_SYSKEYUP:
  3921. case (int)Msg.WM_KEYUP: {
  3922. key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
  3923. OnKeyUp (key_event);
  3924. return key_event.Handled;
  3925. }
  3926. case (int)Msg.WM_SYSCHAR:
  3927. case (int)Msg.WM_CHAR: {
  3928. #if NET_2_0
  3929. if (suppressing_key_press)
  3930. return true;
  3931. #endif
  3932. KeyPressEventArgs key_press_event;
  3933. key_press_event = new KeyPressEventArgs ((char) m.WParam);
  3934. OnKeyPress(key_press_event);
  3935. #if NET_2_0
  3936. m.WParam = (IntPtr) key_press_event.KeyChar;
  3937. #endif
  3938. return key_press_event.Handled;
  3939. }
  3940. default: {
  3941. break;
  3942. }
  3943. }
  3944. return false;
  3945. }
  3946. protected internal virtual bool ProcessKeyMessage (ref Message m)
  3947. {
  3948. if (parent != null) {
  3949. if (parent.ProcessKeyPreview (ref m))
  3950. return true;
  3951. }
  3952. return ProcessKeyEventArgs (ref m);
  3953. }
  3954. protected virtual bool ProcessKeyPreview (ref Message m) {
  3955. if (parent != null)
  3956. return parent.ProcessKeyPreview(ref m);
  3957. return false;
  3958. }
  3959. protected virtual bool ProcessMnemonic(char charCode) {
  3960. // override me
  3961. return false;
  3962. }
  3963. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3964. protected void RaiseDragEvent(object key, DragEventArgs e) {
  3965. // MS Internal
  3966. }
  3967. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3968. protected void RaiseKeyEvent(object key, KeyEventArgs e) {
  3969. // MS Internal
  3970. }
  3971. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3972. protected void RaiseMouseEvent(object key, MouseEventArgs e) {
  3973. // MS Internal
  3974. }
  3975. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3976. protected void RaisePaintEvent(object key, PaintEventArgs e) {
  3977. // MS Internal
  3978. }
  3979. private void SetIsRecreating () {
  3980. is_recreating=true;
  3981. foreach (Control c in Controls.GetAllControls()) {
  3982. c.SetIsRecreating ();
  3983. }
  3984. }
  3985. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3986. protected void RecreateHandle() {
  3987. if (!IsHandleCreated)
  3988. return;
  3989. #if DebugRecreate
  3990. Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
  3991. #endif
  3992. SetIsRecreating ();
  3993. if (IsHandleCreated) {
  3994. #if DebugRecreate
  3995. Console.WriteLine(" + handle is created, destroying it.");
  3996. #endif
  3997. DestroyHandle();
  3998. // WM_DESTROY will CreateHandle for us
  3999. } else {
  4000. #if DebugRecreate
  4001. Console.WriteLine(" + handle is not created, creating it.");
  4002. #endif
  4003. if (!is_created) {
  4004. CreateControl();
  4005. } else {
  4006. CreateHandle();
  4007. }
  4008. is_recreating = false;
  4009. #if DebugRecreate
  4010. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  4011. #endif
  4012. }
  4013. }
  4014. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4015. protected void ResetMouseEventArgs() {
  4016. // MS Internal
  4017. }
  4018. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4019. protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
  4020. if (right_to_left == RightToLeft.No) {
  4021. return align;
  4022. }
  4023. switch (align) {
  4024. case ContentAlignment.TopLeft: {
  4025. return ContentAlignment.TopRight;
  4026. }
  4027. case ContentAlignment.TopRight: {
  4028. return ContentAlignment.TopLeft;
  4029. }
  4030. case ContentAlignment.MiddleLeft: {
  4031. return ContentAlignment.MiddleRight;
  4032. }
  4033. case ContentAlignment.MiddleRight: {
  4034. return ContentAlignment.MiddleLeft;
  4035. }
  4036. case ContentAlignment.BottomLeft: {
  4037. return ContentAlignment.BottomRight;
  4038. }
  4039. case ContentAlignment.BottomRight: {
  4040. return ContentAlignment.BottomLeft;
  4041. }
  4042. default: {
  4043. // if it's center it doesn't change
  4044. return align;
  4045. }
  4046. }
  4047. }
  4048. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4049. protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
  4050. if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
  4051. return align;
  4052. }
  4053. if (align == HorizontalAlignment.Left) {
  4054. return HorizontalAlignment.Right;
  4055. }
  4056. // align must be HorizontalAlignment.Right
  4057. return HorizontalAlignment.Left;
  4058. }
  4059. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4060. protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
  4061. if (right_to_left == RightToLeft.No) {
  4062. return align;
  4063. }
  4064. if (align == LeftRightAlignment.Left) {
  4065. return LeftRightAlignment.Right;
  4066. }
  4067. // align must be LeftRightAlignment.Right;
  4068. return LeftRightAlignment.Left;
  4069. }
  4070. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4071. protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
  4072. return RtlTranslateAlignment(align);
  4073. }
  4074. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4075. protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
  4076. return RtlTranslateAlignment(align);
  4077. }
  4078. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4079. protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
  4080. return RtlTranslateAlignment(align);
  4081. }
  4082. #if NET_2_0
  4083. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4084. protected virtual void ScaleControl (SizeF factor, BoundsSpecified specified)
  4085. {
  4086. Rectangle new_bounds = GetScaledBounds (bounds, factor, specified);
  4087. SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, specified);
  4088. }
  4089. #endif
  4090. #if NET_2_0
  4091. [EditorBrowsable (EditorBrowsableState.Never)]
  4092. #else
  4093. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4094. #endif
  4095. protected virtual void ScaleCore (float dx, float dy)
  4096. {
  4097. Rectangle new_bounds = GetScaledBoundsOld (bounds, new SizeF (dx, dy), BoundsSpecified.All);
  4098. SuspendLayout ();
  4099. SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, BoundsSpecified.All);
  4100. if (ScaleChildrenInternal)
  4101. foreach (Control c in Controls.GetAllControls ())
  4102. c.Scale (dx, dy);
  4103. ResumeLayout ();
  4104. }
  4105. protected virtual void Select(bool directed, bool forward) {
  4106. IContainerControl container;
  4107. container = GetContainerControl();
  4108. if (container != null && (Control)container != this)
  4109. container.ActiveControl = this;
  4110. }
  4111. #if NET_2_0
  4112. protected void SetAutoSizeMode (AutoSizeMode mode)
  4113. {
  4114. if (auto_size_mode != mode) {
  4115. auto_size_mode = mode;
  4116. PerformLayout (this, "AutoSizeMode");
  4117. }
  4118. }
  4119. #endif
  4120. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4121. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  4122. SetBoundsCoreInternal (x, y, width, height, specified);
  4123. }
  4124. internal virtual void SetBoundsCoreInternal(int x, int y, int width, int height, BoundsSpecified specified) {
  4125. // Nasty hack for 2.0 DateTimePicker
  4126. height = OverrideHeight (height);
  4127. Rectangle old_explicit = explicit_bounds;
  4128. Rectangle new_bounds = new Rectangle (x, y, width, height);
  4129. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  4130. if (IsHandleCreated) {
  4131. XplatUI.SetWindowPos(Handle, x, y, width, height);
  4132. // Win32 automatically changes negative width/height to 0.
  4133. // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
  4134. // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
  4135. // size.
  4136. int cw, ch, ix, iy;
  4137. XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
  4138. }
  4139. // BoundsSpecified tells us which variables were programatic (user-set).
  4140. // We need to store those in the explicit bounds
  4141. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  4142. explicit_bounds.X = new_bounds.X;
  4143. else
  4144. explicit_bounds.X = old_explicit.X;
  4145. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  4146. explicit_bounds.Y = new_bounds.Y;
  4147. else
  4148. explicit_bounds.Y = old_explicit.Y;
  4149. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
  4150. explicit_bounds.Width = new_bounds.Width;
  4151. else
  4152. explicit_bounds.Width = old_explicit.Width;
  4153. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
  4154. explicit_bounds.Height = new_bounds.Height;
  4155. else
  4156. explicit_bounds.Height = old_explicit.Height;
  4157. // We need to store the explicit bounds because UpdateBounds is always going
  4158. // to change it, and we have to fix it. However, UpdateBounds also calls
  4159. // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
  4160. // override those or use those events to change the size explicitly, and we
  4161. // can't undo those changes. So if the bounds after calling UpdateBounds are
  4162. // the same as the ones we sent it, we need to fix the explicit bounds. If
  4163. // it's not the same as we sent UpdateBounds, then someone else changed it, and
  4164. // we better not mess it up. Fun stuff.
  4165. Rectangle stored_explicit_bounds = explicit_bounds;
  4166. UpdateBounds(x, y, width, height);
  4167. if (explicit_bounds.X == x)
  4168. explicit_bounds.X = stored_explicit_bounds.X;
  4169. if (explicit_bounds.Y == y)
  4170. explicit_bounds.Y = stored_explicit_bounds.Y;
  4171. if (explicit_bounds.Width == width)
  4172. explicit_bounds.Width = stored_explicit_bounds.Width;
  4173. if (explicit_bounds.Height == height)
  4174. explicit_bounds.Height = stored_explicit_bounds.Height;
  4175. }
  4176. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4177. protected virtual void SetClientSizeCore(int x, int y) {
  4178. Size NewSize = InternalSizeFromClientSize (new Size (x, y));
  4179. if (NewSize != Size.Empty)
  4180. SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
  4181. }
  4182. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4183. protected internal void SetStyle(ControlStyles flag, bool value) {
  4184. if (value) {
  4185. control_style |= flag;
  4186. } else {
  4187. control_style &= ~flag;
  4188. }
  4189. }
  4190. protected void SetTopLevel(bool value) {
  4191. if ((GetTopLevel() != value) && (parent != null)) {
  4192. throw new ArgumentException ("Cannot change toplevel style of a parented control.");
  4193. }
  4194. if (this is Form) {
  4195. if (IsHandleCreated && value != Visible) {
  4196. Visible = value;
  4197. }
  4198. } else {
  4199. // XXX MS.NET causes handle to be created here
  4200. if (!IsHandleCreated)
  4201. CreateHandle ();
  4202. }
  4203. is_toplevel = value;
  4204. }
  4205. protected virtual void SetVisibleCore(bool value) {
  4206. if (value != is_visible) {
  4207. is_visible = value;
  4208. if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
  4209. CreateControl();
  4210. if (!(this is Form))
  4211. UpdateZOrder ();
  4212. }
  4213. if (IsHandleCreated) {
  4214. XplatUI.SetVisible (Handle, is_visible, true);
  4215. if (!is_visible) {
  4216. if (parent != null && parent.IsHandleCreated) {
  4217. parent.Invalidate (bounds);
  4218. parent.Update ();
  4219. } else {
  4220. Refresh ();
  4221. }
  4222. } else if (is_visible && this is Form) {
  4223. // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
  4224. // so we need to manually create our children, and set them visible
  4225. // (This normally happens in WmShowWindow.)
  4226. if ((this as Form).WindowState != FormWindowState.Normal)
  4227. OnVisibleChanged (EventArgs.Empty);
  4228. else
  4229. // Explicitly move Toplevel windows to where we want them;
  4230. // apparently moving unmapped toplevel windows doesn't work
  4231. XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
  4232. } else {
  4233. // If we are becoming visible, z-order may have changed while
  4234. // we were invisible, so update our z-order position
  4235. if (parent != null)
  4236. parent.UpdateZOrderOfChild (this);
  4237. }
  4238. if (!(this is Form))
  4239. OnVisibleChanged (EventArgs.Empty);
  4240. }
  4241. else {
  4242. OnVisibleChanged(EventArgs.Empty);
  4243. }
  4244. }
  4245. }
  4246. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4247. #if NET_2_0
  4248. protected
  4249. #else
  4250. internal
  4251. #endif
  4252. virtual Size SizeFromClientSize (Size clientSize) {
  4253. return InternalSizeFromClientSize (clientSize);
  4254. }
  4255. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4256. protected void UpdateBounds() {
  4257. if (!IsHandleCreated)
  4258. return;
  4259. int x;
  4260. int y;
  4261. int width;
  4262. int height;
  4263. int client_width;
  4264. int client_height;
  4265. XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
  4266. UpdateBounds(x, y, width, height, client_width, client_height);
  4267. }
  4268. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4269. protected void UpdateBounds(int x, int y, int width, int height) {
  4270. CreateParams cp;
  4271. Rectangle rect;
  4272. // Calculate client rectangle
  4273. rect = new Rectangle(0, 0, 0, 0);
  4274. cp = CreateParams;
  4275. XplatUI.CalculateWindowRect(ref rect, cp, cp.menu, out rect);
  4276. UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
  4277. }
  4278. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4279. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  4280. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  4281. bool moved = false;
  4282. bool resized = false;
  4283. // Needed to generate required notifications
  4284. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  4285. moved=true;
  4286. }
  4287. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  4288. resized=true;
  4289. }
  4290. bounds.X=x;
  4291. bounds.Y=y;
  4292. bounds.Width=width;
  4293. bounds.Height=height;
  4294. // Assume explicit bounds set. SetBoundsCore will restore old bounds
  4295. // if needed.
  4296. explicit_bounds = bounds;
  4297. client_size.Width=clientWidth;
  4298. client_size.Height=clientHeight;
  4299. if (moved) {
  4300. OnLocationChanged(EventArgs.Empty);
  4301. if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
  4302. Invalidate ();
  4303. }
  4304. if (resized) {
  4305. OnSizeInitializedOrChanged ();
  4306. OnSizeChanged(EventArgs.Empty);
  4307. #if NET_2_0
  4308. OnClientSizeChanged (EventArgs.Empty);
  4309. #endif
  4310. }
  4311. }
  4312. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4313. protected void UpdateStyles() {
  4314. if (!IsHandleCreated) {
  4315. return;
  4316. }
  4317. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  4318. OnStyleChanged(EventArgs.Empty);
  4319. }
  4320. private void UpdateZOrderOfChild(Control child) {
  4321. if (IsHandleCreated && child.IsHandleCreated && (child.parent == this) && Hwnd.ObjectFromHandle(child.Handle).Mapped) {
  4322. // Need to take into account all controls
  4323. Control [] all_controls = child_controls.GetAllControls ();
  4324. int index = Array.IndexOf (all_controls, child);
  4325. for (; index > 0; index--) {
  4326. if (!all_controls [index - 1].IsHandleCreated || !all_controls [index - 1].VisibleInternal || !Hwnd.ObjectFromHandle(all_controls [index - 1].Handle).Mapped)
  4327. continue;
  4328. break;
  4329. }
  4330. if (index > 0) {
  4331. XplatUI.SetZOrder(child.Handle, all_controls [index - 1].Handle, false, false);
  4332. } else {
  4333. IntPtr after = AfterTopMostControl ();
  4334. if (after != IntPtr.Zero && after != child.Handle)
  4335. XplatUI.SetZOrder (child.Handle, after, false, false);
  4336. else
  4337. XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
  4338. }
  4339. }
  4340. }
  4341. // Override this if there is a control that shall always remain on
  4342. // top of other controls (such as scrollbars). If there are several
  4343. // of these controls, the bottom-most should be returned.
  4344. internal virtual IntPtr AfterTopMostControl () {
  4345. return IntPtr.Zero;
  4346. }
  4347. // internal because we need to call it from ScrollableControl.OnVisibleChanged
  4348. internal void UpdateChildrenZOrder() {
  4349. Control [] controls;
  4350. if (!IsHandleCreated) {
  4351. return;
  4352. }
  4353. // XXX This code is severely broken. It leaks
  4354. // the "zero_sized" abstraction out of the X11
  4355. // backend and into Control.cs. It'll work on
  4356. // windows simply by virtue of windows never
  4357. // setting that field to true.
  4358. //
  4359. // basically what we need to guard against is
  4360. // calling XplatUI.SetZOrder on an hwnd that
  4361. // corresponds to an unmapped X window.
  4362. //
  4363. // Also, explicitly send implicit controls to the back.
  4364. if (child_controls.ImplicitControls == null) {
  4365. controls = new Control [child_controls.Count];
  4366. child_controls.CopyTo (controls, 0);
  4367. } else {
  4368. controls = new Control [child_controls.Count + child_controls.ImplicitControls.Count];
  4369. child_controls.CopyTo (controls, 0);
  4370. child_controls.ImplicitControls.CopyTo (controls, child_controls.Count);
  4371. }
  4372. ArrayList children_to_order = new ArrayList ();
  4373. for (int i = 0; i < controls.Length; i ++) {
  4374. if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
  4375. continue;
  4376. Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
  4377. if (hwnd.zero_sized)
  4378. continue;
  4379. children_to_order.Add (controls[i]);
  4380. }
  4381. for (int i = 1; i < children_to_order.Count; i ++) {
  4382. Control upper = (Control)children_to_order[i-1];
  4383. Control lower = (Control)children_to_order[i];
  4384. XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
  4385. }
  4386. }
  4387. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4388. protected void UpdateZOrder() {
  4389. if (parent != null) {
  4390. parent.UpdateZOrderOfChild(this);
  4391. }
  4392. }
  4393. protected virtual void WndProc(ref Message m) {
  4394. #if DebugMessages
  4395. Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
  4396. #endif
  4397. if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
  4398. OnNotifyMessage(m);
  4399. }
  4400. switch((Msg)m.Msg) {
  4401. case Msg.WM_DESTROY: {
  4402. WmDestroy(ref m);
  4403. return;
  4404. }
  4405. case Msg.WM_WINDOWPOSCHANGED: {
  4406. WmWindowPosChanged(ref m);
  4407. return;
  4408. }
  4409. // Nice description of what should happen when handling WM_PAINT
  4410. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4411. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4412. case Msg.WM_PAINT: {
  4413. WmPaint (ref m);
  4414. return;
  4415. }
  4416. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4417. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4418. // here but it just makes things more complicated...
  4419. case Msg.WM_ERASEBKGND: {
  4420. WmEraseBackground (ref m);
  4421. return;
  4422. }
  4423. case Msg.WM_LBUTTONUP: {
  4424. WmLButtonUp (ref m);
  4425. return;
  4426. }
  4427. case Msg.WM_LBUTTONDOWN: {
  4428. WmLButtonDown (ref m);
  4429. return;
  4430. }
  4431. case Msg.WM_LBUTTONDBLCLK: {
  4432. WmLButtonDblClick (ref m);
  4433. return;
  4434. }
  4435. case Msg.WM_MBUTTONUP: {
  4436. WmMButtonUp (ref m);
  4437. return;
  4438. }
  4439. case Msg.WM_MBUTTONDOWN: {
  4440. WmMButtonDown (ref m);
  4441. return;
  4442. }
  4443. case Msg.WM_MBUTTONDBLCLK: {
  4444. WmMButtonDblClick (ref m);
  4445. return;
  4446. }
  4447. case Msg.WM_RBUTTONUP: {
  4448. WmRButtonUp (ref m);
  4449. return;
  4450. }
  4451. case Msg.WM_RBUTTONDOWN: {
  4452. WmRButtonDown (ref m);
  4453. return;
  4454. }
  4455. case Msg.WM_RBUTTONDBLCLK: {
  4456. WmRButtonDblClick (ref m);
  4457. return;
  4458. }
  4459. case Msg.WM_CONTEXTMENU: {
  4460. WmContextMenu (ref m);
  4461. return;
  4462. }
  4463. case Msg.WM_MOUSEWHEEL: {
  4464. WmMouseWheel (ref m);
  4465. return;
  4466. }
  4467. case Msg.WM_MOUSEMOVE: {
  4468. WmMouseMove (ref m);
  4469. return;
  4470. }
  4471. case Msg.WM_SHOWWINDOW: {
  4472. WmShowWindow (ref m);
  4473. return;
  4474. }
  4475. case Msg.WM_CREATE: {
  4476. WmCreate (ref m);
  4477. return;
  4478. }
  4479. case Msg.WM_MOUSE_ENTER: {
  4480. WmMouseEnter (ref m);
  4481. return;
  4482. }
  4483. case Msg.WM_MOUSELEAVE: {
  4484. WmMouseLeave (ref m);
  4485. return;
  4486. }
  4487. case Msg.WM_MOUSEHOVER: {
  4488. WmMouseHover (ref m);
  4489. return;
  4490. }
  4491. case Msg.WM_SYSKEYUP: {
  4492. WmSysKeyUp (ref m);
  4493. return;
  4494. }
  4495. case Msg.WM_SYSKEYDOWN:
  4496. case Msg.WM_KEYDOWN:
  4497. case Msg.WM_KEYUP:
  4498. case Msg.WM_SYSCHAR:
  4499. case Msg.WM_CHAR: {
  4500. WmKeys (ref m);
  4501. return;
  4502. }
  4503. case Msg.WM_HELP: {
  4504. WmHelp (ref m);
  4505. return;
  4506. }
  4507. case Msg.WM_KILLFOCUS: {
  4508. WmKillFocus (ref m);
  4509. return;
  4510. }
  4511. case Msg.WM_SETFOCUS: {
  4512. WmSetFocus (ref m);
  4513. return;
  4514. }
  4515. case Msg.WM_SYSCOLORCHANGE: {
  4516. WmSysColorChange (ref m);
  4517. return;
  4518. }
  4519. case Msg.WM_SETCURSOR: {
  4520. WmSetCursor (ref m);
  4521. return;
  4522. }
  4523. case Msg.WM_CAPTURECHANGED: {
  4524. WmCaptureChanged (ref m);
  4525. return;
  4526. }
  4527. case Msg.WM_CHANGEUISTATE: {
  4528. WmChangeUIState (ref m);
  4529. return;
  4530. }
  4531. case Msg.WM_UPDATEUISTATE: {
  4532. WmUpdateUIState (ref m);
  4533. return;
  4534. }
  4535. default:
  4536. DefWndProc(ref m);
  4537. return;
  4538. }
  4539. }
  4540. #endregion // Public Instance Methods
  4541. #region WM methods
  4542. private void WmDestroy (ref Message m) {
  4543. OnHandleDestroyed(EventArgs.Empty);
  4544. #if DebugRecreate
  4545. IntPtr handle = window.Handle;
  4546. #endif
  4547. window.InvalidateHandle();
  4548. is_created = false;
  4549. if (is_recreating) {
  4550. #if DebugRecreate
  4551. Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
  4552. #endif
  4553. CreateHandle();
  4554. #if DebugRecreate
  4555. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  4556. #endif
  4557. is_recreating = false;
  4558. }
  4559. if (is_disposing) {
  4560. is_disposing = false;
  4561. is_visible = false;
  4562. }
  4563. }
  4564. private void WmWindowPosChanged (ref Message m) {
  4565. if (Visible) {
  4566. Rectangle save_bounds = explicit_bounds;
  4567. UpdateBounds();
  4568. explicit_bounds = save_bounds;
  4569. if (GetStyle(ControlStyles.ResizeRedraw)) {
  4570. Invalidate();
  4571. }
  4572. }
  4573. }
  4574. // Nice description of what should happen when handling WM_PAINT
  4575. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4576. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4577. private void WmPaint (ref Message m) {
  4578. PaintEventArgs paint_event;
  4579. IntPtr handle = Handle;
  4580. paint_event = XplatUI.PaintEventStart (ref m, handle, true);
  4581. if (paint_event == null)
  4582. return;
  4583. DoubleBuffer current_buffer = null;
  4584. if (UseDoubleBuffering) {
  4585. current_buffer = GetBackBuffer ();
  4586. // This optimization doesn't work when the area is invalidated
  4587. // during a paint operation because finishing the paint operation
  4588. // clears the invalidated region and then this thing keeps the new
  4589. // invalidate from working. To re-enable this, we would need a
  4590. // mechanism to allow for nested invalidates (see bug #328681)
  4591. //if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
  4592. // // Just blit the previous image
  4593. // current_buffer.Blit (paint_event);
  4594. // XplatUI.PaintEventEnd (ref m, handle, true);
  4595. // return;
  4596. //}
  4597. current_buffer.Start (paint_event);
  4598. }
  4599. #if NET_2_0
  4600. // If using OptimizedDoubleBuffer, ensure the clip region gets set
  4601. if (GetStyle (ControlStyles.OptimizedDoubleBuffer))
  4602. paint_event.Graphics.SetClip (Rectangle.Intersect (paint_event.ClipRectangle, this.ClientRectangle));
  4603. #endif
  4604. if (!GetStyle(ControlStyles.Opaque)) {
  4605. OnPaintBackground (paint_event);
  4606. }
  4607. // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
  4608. OnPaintBackgroundInternal (paint_event);
  4609. OnPaintInternal(paint_event);
  4610. if (!paint_event.Handled) {
  4611. OnPaint (paint_event);
  4612. }
  4613. if (current_buffer != null) {
  4614. current_buffer.End (paint_event);
  4615. }
  4616. XplatUI.PaintEventEnd (ref m, handle, true);
  4617. }
  4618. private void WmEraseBackground (ref Message m) {
  4619. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4620. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4621. // here but it just makes things more complicated...
  4622. m.Result = (IntPtr)1;
  4623. }
  4624. private void WmLButtonUp (ref Message m)
  4625. {
  4626. // Menu handle.
  4627. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4628. ProcessActiveTracker (ref m);
  4629. return;
  4630. }
  4631. MouseEventArgs me;
  4632. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  4633. mouse_clicks,
  4634. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4635. 0);
  4636. HandleClick(mouse_clicks, me);
  4637. OnMouseUp (me);
  4638. if (InternalCapture) {
  4639. InternalCapture = false;
  4640. }
  4641. if (mouse_clicks > 1) {
  4642. mouse_clicks = 1;
  4643. }
  4644. }
  4645. private void WmLButtonDown (ref Message m)
  4646. {
  4647. // Menu handle.
  4648. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4649. ProcessActiveTracker (ref m);
  4650. return;
  4651. }
  4652. ValidationFailed = false;
  4653. if (CanSelect) {
  4654. Select (true, true);
  4655. }
  4656. if (!ValidationFailed) {
  4657. InternalCapture = true;
  4658. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4659. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4660. 0));
  4661. }
  4662. }
  4663. private void WmLButtonDblClick (ref Message m) {
  4664. InternalCapture = true;
  4665. mouse_clicks++;
  4666. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4667. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4668. 0));
  4669. }
  4670. private void WmMButtonUp (ref Message m) {
  4671. MouseEventArgs me;
  4672. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
  4673. mouse_clicks,
  4674. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4675. 0);
  4676. HandleClick(mouse_clicks, me);
  4677. OnMouseUp (me);
  4678. if (InternalCapture) {
  4679. InternalCapture = false;
  4680. }
  4681. if (mouse_clicks > 1) {
  4682. mouse_clicks = 1;
  4683. }
  4684. }
  4685. private void WmMButtonDown (ref Message m) {
  4686. InternalCapture = true;
  4687. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4688. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4689. 0));
  4690. }
  4691. private void WmMButtonDblClick (ref Message m) {
  4692. InternalCapture = true;
  4693. mouse_clicks++;
  4694. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4695. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4696. 0));
  4697. }
  4698. private void WmRButtonUp (ref Message m)
  4699. {
  4700. // Menu handle.
  4701. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4702. ProcessActiveTracker (ref m);
  4703. return;
  4704. }
  4705. MouseEventArgs me;
  4706. Point pt;
  4707. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4708. pt = PointToScreen(pt);
  4709. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
  4710. mouse_clicks,
  4711. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4712. 0);
  4713. HandleClick(mouse_clicks, me);
  4714. XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
  4715. OnMouseUp (me);
  4716. if (InternalCapture) {
  4717. InternalCapture = false;
  4718. }
  4719. if (mouse_clicks > 1) {
  4720. mouse_clicks = 1;
  4721. }
  4722. }
  4723. private void WmRButtonDown (ref Message m)
  4724. {
  4725. // Menu handle.
  4726. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4727. ProcessActiveTracker (ref m);
  4728. return;
  4729. }
  4730. InternalCapture = true;
  4731. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4732. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4733. 0));
  4734. }
  4735. private void WmRButtonDblClick (ref Message m) {
  4736. InternalCapture = true;
  4737. mouse_clicks++;
  4738. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4739. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4740. 0));
  4741. }
  4742. private void WmContextMenu (ref Message m) {
  4743. if (context_menu != null) {
  4744. Point pt;
  4745. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4746. if (pt.X == -1 || pt.Y == -1) {
  4747. pt.X = (this.Width / 2) + this.Left;
  4748. pt.Y = (this.Height / 2) + this.Top;
  4749. pt = this.PointToScreen (pt);
  4750. }
  4751. context_menu.Show (this, PointToClient (pt));
  4752. return;
  4753. }
  4754. #if NET_2_0
  4755. // If there isn't a regular context menu, show the Strip version
  4756. if (context_menu == null && context_menu_strip != null) {
  4757. Point pt;
  4758. pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
  4759. if (pt.X == -1 || pt.Y == -1) {
  4760. pt.X = (this.Width / 2) + this.Left;
  4761. pt.Y = (this.Height /2) + this.Top;
  4762. pt = this.PointToScreen (pt);
  4763. }
  4764. context_menu_strip.Show (this, PointToClient (pt));
  4765. return;
  4766. }
  4767. #endif
  4768. DefWndProc(ref m);
  4769. }
  4770. private void WmCreate (ref Message m) {
  4771. OnHandleCreated(EventArgs.Empty);
  4772. }
  4773. private void WmMouseWheel (ref Message m) {
  4774. DefWndProc(ref m);
  4775. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((long) m.WParam),
  4776. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4777. HighOrder((long)m.WParam)));
  4778. }
  4779. private void WmMouseMove (ref Message m) {
  4780. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4781. MouseEventArgs args = new MouseEventArgs (
  4782. FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
  4783. mouse_clicks,
  4784. Control.MousePosition.X,
  4785. Control.MousePosition.Y,
  4786. 0);
  4787. active_tracker.OnMotion (args);
  4788. return;
  4789. }
  4790. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4791. mouse_clicks,
  4792. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4793. 0));
  4794. }
  4795. private void WmMouseEnter (ref Message m) {
  4796. if (is_entered) {
  4797. return;
  4798. }
  4799. is_entered = true;
  4800. OnMouseEnter(EventArgs.Empty);
  4801. }
  4802. private void WmMouseLeave (ref Message m) {
  4803. is_entered=false;
  4804. OnMouseLeave(EventArgs.Empty);
  4805. }
  4806. private void WmMouseHover (ref Message m) {
  4807. OnMouseHover(EventArgs.Empty);
  4808. }
  4809. private void WmShowWindow (ref Message m) {
  4810. if (IsDisposed)
  4811. return;
  4812. Form frm = this as Form;
  4813. if (m.WParam.ToInt32() != 0) {
  4814. if (m.LParam.ToInt32 () == 0) {
  4815. CreateControl ();
  4816. // Make sure all our children are properly parented to us
  4817. Control [] controls = child_controls.GetAllControls ();
  4818. // bool parented = false;
  4819. for (int i=0; i<controls.Length; i++) {
  4820. if (controls [i].is_visible && controls[i].IsHandleCreated)
  4821. if (XplatUI.GetParent (controls[i].Handle) != window.Handle) {
  4822. XplatUI.SetParent(controls[i].Handle, window.Handle);
  4823. // parented = true;
  4824. }
  4825. }
  4826. //if (parented)
  4827. UpdateChildrenZOrder ();
  4828. }
  4829. } else {
  4830. if (parent != null && Focused) {
  4831. Control container;
  4832. // Need to start at parent, GetContainerControl might return ourselves if we're a container
  4833. container = (Control)parent.GetContainerControl();
  4834. if (container != null && (frm == null || !frm.IsMdiChild)) {
  4835. container.SelectNextControl(this, true, true, true, true);
  4836. }
  4837. }
  4838. }
  4839. if (frm != null)
  4840. frm.waiting_showwindow = false;
  4841. // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
  4842. if (frm != null) {
  4843. if (!IsRecreating && (frm.IsMdiChild || frm.WindowState == FormWindowState.Normal)) /* XXX make sure this works for mdi forms */
  4844. OnVisibleChanged(EventArgs.Empty);
  4845. } else if (is_toplevel)
  4846. OnVisibleChanged(EventArgs.Empty);
  4847. }
  4848. private void WmSysKeyUp (ref Message m) {
  4849. if (ProcessKeyMessage(ref m)) {
  4850. m.Result = IntPtr.Zero;
  4851. return;
  4852. }
  4853. if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
  4854. Form form;
  4855. form = FindForm();
  4856. if (form != null && form.ActiveMenu != null) {
  4857. form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
  4858. }
  4859. #if NET_2_0
  4860. else
  4861. if (ToolStripManager.ProcessMenuKey (ref m))
  4862. return;
  4863. #endif
  4864. }
  4865. DefWndProc (ref m);
  4866. }
  4867. private void WmKeys (ref Message m)
  4868. {
  4869. if (ProcessKeyMessage(ref m)) {
  4870. m.Result = IntPtr.Zero;
  4871. return;
  4872. }
  4873. DefWndProc (ref m);
  4874. }
  4875. private void WmHelp (ref Message m) {
  4876. Point mouse_pos;
  4877. if (m.LParam != IntPtr.Zero) {
  4878. HELPINFO hi;
  4879. hi = new HELPINFO();
  4880. hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
  4881. mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
  4882. } else {
  4883. mouse_pos = Control.MousePosition;
  4884. }
  4885. OnHelpRequested(new HelpEventArgs(mouse_pos));
  4886. m.Result = (IntPtr)1;
  4887. }
  4888. private void WmKillFocus (ref Message m) {
  4889. this.has_focus = false;
  4890. OnLostFocus (EventArgs.Empty);
  4891. }
  4892. private void WmSetFocus (ref Message m) {
  4893. if (!has_focus) {
  4894. this.has_focus = true;
  4895. OnGotFocus (EventArgs.Empty);
  4896. }
  4897. }
  4898. private void WmSysColorChange (ref Message m) {
  4899. ThemeEngine.Current.ResetDefaults();
  4900. OnSystemColorsChanged(EventArgs.Empty);
  4901. }
  4902. private void WmSetCursor (ref Message m) {
  4903. if ((cursor == null && use_wait_cursor == false) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
  4904. DefWndProc(ref m);
  4905. return;
  4906. }
  4907. XplatUI.SetCursor(window.Handle, Cursor.handle);
  4908. m.Result = (IntPtr)1;
  4909. }
  4910. private void WmCaptureChanged (ref Message m) {
  4911. is_captured = false;
  4912. OnMouseCaptureChanged (EventArgs.Empty);
  4913. m.Result = (IntPtr) 0;
  4914. }
  4915. private void WmChangeUIState (ref Message m) {
  4916. foreach (Control control in Controls) {
  4917. XplatUI.SendMessage (control.Handle, Msg.WM_UPDATEUISTATE, m.WParam, m.LParam);
  4918. }
  4919. }
  4920. private void WmUpdateUIState (ref Message m) {
  4921. int action = LowOrder (m.WParam.ToInt32 ());
  4922. int element = HighOrder (m.WParam.ToInt32 ());
  4923. if (action == (int) MsgUIState.UIS_INITIALIZE)
  4924. return;
  4925. UICues cues = UICues.None;
  4926. if ((element & (int) MsgUIState.UISF_HIDEACCEL) != 0) {
  4927. if ((action == (int) MsgUIState.UIS_CLEAR) != show_keyboard_cues) {
  4928. cues |= UICues.ChangeKeyboard;
  4929. show_keyboard_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4930. }
  4931. }
  4932. if ((element & (int) MsgUIState.UISF_HIDEFOCUS) != 0) {
  4933. if ((action == (int) MsgUIState.UIS_CLEAR) != show_focus_cues) {
  4934. cues |= UICues.ChangeFocus;
  4935. show_focus_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4936. }
  4937. }
  4938. if ((cues & UICues.Changed) != UICues.None) {
  4939. OnChangeUICues (new UICuesEventArgs (cues));
  4940. Invalidate ();
  4941. }
  4942. }
  4943. #endregion
  4944. #region OnXXX methods
  4945. #if NET_2_0
  4946. protected virtual void OnAutoSizeChanged (EventArgs e)
  4947. {
  4948. EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
  4949. if (eh != null)
  4950. eh (this, e);
  4951. }
  4952. #endif
  4953. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4954. protected virtual void OnBackColorChanged(EventArgs e) {
  4955. EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
  4956. if (eh != null)
  4957. eh (this, e);
  4958. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  4959. }
  4960. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4961. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  4962. EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
  4963. if (eh != null)
  4964. eh (this, e);
  4965. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  4966. }
  4967. #if NET_2_0
  4968. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4969. protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
  4970. {
  4971. EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
  4972. if (eh != null)
  4973. eh (this, e);
  4974. }
  4975. #endif
  4976. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4977. protected virtual void OnBindingContextChanged(EventArgs e) {
  4978. CheckDataBindings ();
  4979. EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
  4980. if (eh != null)
  4981. eh (this, e);
  4982. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  4983. }
  4984. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4985. protected virtual void OnCausesValidationChanged(EventArgs e) {
  4986. EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
  4987. if (eh != null)
  4988. eh (this, e);
  4989. }
  4990. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4991. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  4992. UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
  4993. if (eh != null)
  4994. eh (this, e);
  4995. }
  4996. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4997. protected virtual void OnClick(EventArgs e) {
  4998. EventHandler eh = (EventHandler)(Events [ClickEvent]);
  4999. if (eh != null)
  5000. eh (this, e);
  5001. }
  5002. #if NET_2_0
  5003. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5004. protected virtual void OnClientSizeChanged (EventArgs e)
  5005. {
  5006. EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
  5007. if (eh != null)
  5008. eh (this, e);
  5009. }
  5010. #endif
  5011. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5012. protected virtual void OnContextMenuChanged(EventArgs e) {
  5013. EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
  5014. if (eh != null)
  5015. eh (this, e);
  5016. }
  5017. #if NET_2_0
  5018. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5019. protected virtual void OnContextMenuStripChanged (EventArgs e) {
  5020. EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
  5021. if (eh != null)
  5022. eh (this, e);
  5023. }
  5024. #endif
  5025. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5026. protected virtual void OnControlAdded(ControlEventArgs e) {
  5027. ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
  5028. if (eh != null)
  5029. eh (this, e);
  5030. }
  5031. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5032. protected virtual void OnControlRemoved(ControlEventArgs e) {
  5033. ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
  5034. if (eh != null)
  5035. eh (this, e);
  5036. }
  5037. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5038. protected virtual void OnCreateControl() {
  5039. // Override me!
  5040. }
  5041. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5042. protected virtual void OnCursorChanged(EventArgs e) {
  5043. EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
  5044. if (eh != null)
  5045. eh (this, e);
  5046. #if NET_2_0
  5047. for (int i = 0; i < child_controls.Count; i++) child_controls[i].OnParentCursorChanged (e);
  5048. #endif
  5049. }
  5050. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5051. protected virtual void OnDockChanged(EventArgs e) {
  5052. EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
  5053. if (eh != null)
  5054. eh (this, e);
  5055. }
  5056. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5057. protected virtual void OnDoubleClick(EventArgs e) {
  5058. EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
  5059. if (eh != null)
  5060. eh (this, e);
  5061. }
  5062. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5063. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  5064. DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
  5065. if (eh != null)
  5066. eh (this, drgevent);
  5067. }
  5068. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5069. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  5070. DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
  5071. if (eh != null)
  5072. eh (this, drgevent);
  5073. }
  5074. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5075. protected virtual void OnDragLeave(EventArgs e) {
  5076. EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
  5077. if (eh != null)
  5078. eh (this, e);
  5079. }
  5080. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5081. protected virtual void OnDragOver(DragEventArgs drgevent) {
  5082. DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
  5083. if (eh != null)
  5084. eh (this, drgevent);
  5085. }
  5086. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5087. protected virtual void OnEnabledChanged(EventArgs e) {
  5088. if (IsHandleCreated) {
  5089. if (this is Form) {
  5090. if (((Form)this).context == null) {
  5091. XplatUI.EnableWindow(window.Handle, Enabled);
  5092. }
  5093. } else {
  5094. XplatUI.EnableWindow(window.Handle, Enabled);
  5095. }
  5096. Refresh();
  5097. }
  5098. EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
  5099. if (eh != null)
  5100. eh (this, e);
  5101. foreach (Control c in Controls.GetAllControls ())
  5102. c.OnParentEnabledChanged (e);
  5103. }
  5104. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5105. protected virtual void OnEnter(EventArgs e) {
  5106. EventHandler eh = (EventHandler)(Events [EnterEvent]);
  5107. if (eh != null)
  5108. eh (this, e);
  5109. }
  5110. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5111. protected virtual void OnFontChanged(EventArgs e) {
  5112. EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
  5113. if (eh != null)
  5114. eh (this, e);
  5115. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
  5116. }
  5117. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5118. protected virtual void OnForeColorChanged(EventArgs e) {
  5119. EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
  5120. if (eh != null)
  5121. eh (this, e);
  5122. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  5123. }
  5124. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5125. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  5126. GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
  5127. if (eh != null)
  5128. eh (this, gfbevent);
  5129. }
  5130. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5131. protected virtual void OnGotFocus(EventArgs e) {
  5132. EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
  5133. if (eh != null)
  5134. eh (this, e);
  5135. }
  5136. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5137. protected virtual void OnHandleCreated(EventArgs e) {
  5138. EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
  5139. if (eh != null)
  5140. eh (this, e);
  5141. }
  5142. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5143. protected virtual void OnHandleDestroyed(EventArgs e) {
  5144. EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
  5145. if (eh != null)
  5146. eh (this, e);
  5147. }
  5148. internal void RaiseHelpRequested (HelpEventArgs hevent) {
  5149. OnHelpRequested (hevent);
  5150. }
  5151. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5152. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  5153. HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
  5154. if (eh != null)
  5155. eh (this, hevent);
  5156. }
  5157. protected virtual void OnImeModeChanged(EventArgs e) {
  5158. EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
  5159. if (eh != null)
  5160. eh (this, e);
  5161. }
  5162. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5163. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  5164. if (UseDoubleBuffering) {
  5165. // should this block be here? seems like it
  5166. // would be more at home in
  5167. // NotifyInvalidated..
  5168. if (e.InvalidRect == ClientRectangle) {
  5169. InvalidateBackBuffer ();
  5170. } else if (backbuffer != null){
  5171. // we need this Inflate call here so
  5172. // that the border of the rectangle is
  5173. // considered Visible (the
  5174. // invalid_region.IsVisible call) in
  5175. // the WM_PAINT handling below.
  5176. Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
  5177. backbuffer.InvalidRegion.Union (r);
  5178. }
  5179. }
  5180. InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
  5181. if (eh != null)
  5182. eh (this, e);
  5183. }
  5184. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5185. protected virtual void OnKeyDown(KeyEventArgs e) {
  5186. KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
  5187. if (eh != null)
  5188. eh (this, e);
  5189. }
  5190. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5191. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  5192. KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
  5193. if (eh != null)
  5194. eh (this, e);
  5195. }
  5196. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5197. protected virtual void OnKeyUp(KeyEventArgs e) {
  5198. KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
  5199. if (eh != null)
  5200. eh (this, e);
  5201. }
  5202. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5203. protected virtual void OnLayout(LayoutEventArgs levent) {
  5204. LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
  5205. if (eh != null)
  5206. eh (this, levent);
  5207. #if NET_2_0
  5208. Size s = Size;
  5209. // If our layout changed our PreferredSize, our parent
  5210. // needs to re-lay us out. However, it's not always possible to
  5211. // be our preferred size, so only try once so we don't loop forever.
  5212. if (Parent != null && AutoSize && !nested_layout && PreferredSize != s) {
  5213. nested_layout = true;
  5214. Parent.PerformLayout ();
  5215. nested_layout = false;
  5216. }
  5217. #endif
  5218. LayoutEngine.Layout (this, levent);
  5219. }
  5220. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5221. protected virtual void OnLeave(EventArgs e) {
  5222. EventHandler eh = (EventHandler)(Events [LeaveEvent]);
  5223. if (eh != null)
  5224. eh (this, e);
  5225. }
  5226. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5227. protected virtual void OnLocationChanged(EventArgs e) {
  5228. OnMove(e);
  5229. EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
  5230. if (eh != null)
  5231. eh (this, e);
  5232. }
  5233. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5234. protected virtual void OnLostFocus(EventArgs e) {
  5235. EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
  5236. if (eh != null)
  5237. eh (this, e);
  5238. }
  5239. #if NET_2_0
  5240. protected virtual void OnMarginChanged (EventArgs e)
  5241. {
  5242. EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
  5243. if (eh != null)
  5244. eh (this, e);
  5245. }
  5246. #endif
  5247. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5248. #if NET_2_0
  5249. protected virtual void OnMouseCaptureChanged (EventArgs e)
  5250. #else
  5251. internal virtual void OnMouseCaptureChanged (EventArgs e)
  5252. #endif
  5253. {
  5254. EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
  5255. if (eh != null)
  5256. eh (this, e);
  5257. }
  5258. #if NET_2_0
  5259. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5260. protected virtual void OnMouseClick (MouseEventArgs e)
  5261. {
  5262. MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
  5263. if (eh != null)
  5264. eh (this, e);
  5265. }
  5266. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5267. protected virtual void OnMouseDoubleClick (MouseEventArgs e)
  5268. {
  5269. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
  5270. if (eh != null)
  5271. eh (this, e);
  5272. }
  5273. #endif
  5274. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5275. protected virtual void OnMouseDown(MouseEventArgs e) {
  5276. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
  5277. if (eh != null)
  5278. eh (this, e);
  5279. }
  5280. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5281. protected virtual void OnMouseEnter(EventArgs e) {
  5282. EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
  5283. if (eh != null)
  5284. eh (this, e);
  5285. }
  5286. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5287. protected virtual void OnMouseHover(EventArgs e) {
  5288. EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
  5289. if (eh != null)
  5290. eh (this, e);
  5291. }
  5292. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5293. protected virtual void OnMouseLeave(EventArgs e) {
  5294. EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
  5295. if (eh != null)
  5296. eh (this, e);
  5297. }
  5298. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5299. protected virtual void OnMouseMove(MouseEventArgs e) {
  5300. MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
  5301. if (eh != null)
  5302. eh (this, e);
  5303. }
  5304. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5305. protected virtual void OnMouseUp(MouseEventArgs e) {
  5306. MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
  5307. if (eh != null)
  5308. eh (this, e);
  5309. }
  5310. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5311. protected virtual void OnMouseWheel(MouseEventArgs e) {
  5312. MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
  5313. if (eh != null)
  5314. eh (this, e);
  5315. }
  5316. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5317. protected virtual void OnMove(EventArgs e) {
  5318. EventHandler eh = (EventHandler)(Events [MoveEvent]);
  5319. if (eh != null)
  5320. eh (this, e);
  5321. }
  5322. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5323. protected virtual void OnNotifyMessage(Message m) {
  5324. // Override me!
  5325. }
  5326. #if NET_2_0
  5327. protected virtual void OnPaddingChanged (EventArgs e) {
  5328. EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
  5329. if (eh != null)
  5330. eh (this, e);
  5331. }
  5332. #endif
  5333. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5334. protected virtual void OnPaint(PaintEventArgs e) {
  5335. PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
  5336. if (eh != null)
  5337. eh (this, e);
  5338. }
  5339. internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
  5340. // Override me
  5341. }
  5342. internal virtual void OnPaintInternal(PaintEventArgs e) {
  5343. // Override me
  5344. }
  5345. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5346. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  5347. PaintControlBackground (pevent);
  5348. }
  5349. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5350. protected virtual void OnParentBackColorChanged(EventArgs e) {
  5351. if (background_color.IsEmpty && background_image==null) {
  5352. Invalidate();
  5353. OnBackColorChanged(e);
  5354. }
  5355. }
  5356. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5357. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  5358. Invalidate();
  5359. OnBackgroundImageChanged(e);
  5360. }
  5361. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5362. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  5363. if (binding_context==null && Parent != null) {
  5364. binding_context=Parent.binding_context;
  5365. OnBindingContextChanged(e);
  5366. }
  5367. }
  5368. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5369. protected virtual void OnParentChanged(EventArgs e) {
  5370. EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
  5371. if (eh != null)
  5372. eh (this, e);
  5373. }
  5374. #if NET_2_0
  5375. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5376. protected virtual void OnParentCursorChanged (EventArgs e)
  5377. {
  5378. }
  5379. #endif
  5380. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5381. protected virtual void OnParentEnabledChanged(EventArgs e) {
  5382. if (is_enabled) {
  5383. OnEnabledChanged(e);
  5384. }
  5385. }
  5386. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5387. protected virtual void OnParentFontChanged(EventArgs e) {
  5388. if (font==null) {
  5389. Invalidate();
  5390. OnFontChanged(e);
  5391. }
  5392. }
  5393. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5394. protected virtual void OnParentForeColorChanged(EventArgs e) {
  5395. if (foreground_color.IsEmpty) {
  5396. Invalidate();
  5397. OnForeColorChanged(e);
  5398. }
  5399. }
  5400. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5401. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  5402. if (right_to_left==RightToLeft.Inherit) {
  5403. Invalidate();
  5404. OnRightToLeftChanged(e);
  5405. }
  5406. }
  5407. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5408. protected virtual void OnParentVisibleChanged(EventArgs e) {
  5409. if (is_visible) {
  5410. OnVisibleChanged(e);
  5411. }
  5412. }
  5413. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5414. protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs qcdevent)
  5415. {
  5416. QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
  5417. if (eh != null)
  5418. eh (this, qcdevent);
  5419. }
  5420. #if NET_2_0
  5421. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5422. protected virtual void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
  5423. {
  5424. PreviewKeyDownEventHandler eh = (PreviewKeyDownEventHandler)(Events[PreviewKeyDownEvent]);
  5425. if (eh != null)
  5426. eh (this, e);
  5427. }
  5428. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5429. protected virtual void OnPrint (PaintEventArgs e)
  5430. {
  5431. PaintEventHandler eh = (PaintEventHandler)(Events[PaintEvent]);
  5432. if (eh != null)
  5433. eh (this, e);
  5434. }
  5435. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5436. protected virtual void OnRegionChanged (EventArgs e)
  5437. {
  5438. EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
  5439. if (eh != null)
  5440. eh (this, e);
  5441. }
  5442. #endif
  5443. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5444. protected virtual void OnResize(EventArgs e) {
  5445. OnResizeInternal (e);
  5446. }
  5447. internal virtual void OnResizeInternal (EventArgs e) {
  5448. PerformLayout(this, "Bounds");
  5449. EventHandler eh = (EventHandler)(Events [ResizeEvent]);
  5450. if (eh != null)
  5451. eh (this, e);
  5452. }
  5453. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5454. protected virtual void OnRightToLeftChanged(EventArgs e) {
  5455. EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
  5456. if (eh != null)
  5457. eh (this, e);
  5458. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  5459. }
  5460. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5461. protected virtual void OnSizeChanged(EventArgs e) {
  5462. DisposeBackBuffer ();
  5463. OnResize(e);
  5464. EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
  5465. if (eh != null)
  5466. eh (this, e);
  5467. }
  5468. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5469. protected virtual void OnStyleChanged(EventArgs e) {
  5470. EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
  5471. if (eh != null)
  5472. eh (this, e);
  5473. }
  5474. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5475. protected virtual void OnSystemColorsChanged(EventArgs e) {
  5476. EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
  5477. if (eh != null)
  5478. eh (this, e);
  5479. }
  5480. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5481. protected virtual void OnTabIndexChanged(EventArgs e) {
  5482. EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
  5483. if (eh != null)
  5484. eh (this, e);
  5485. }
  5486. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5487. protected virtual void OnTabStopChanged(EventArgs e) {
  5488. EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
  5489. if (eh != null)
  5490. eh (this, e);
  5491. }
  5492. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5493. protected virtual void OnTextChanged(EventArgs e) {
  5494. EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
  5495. if (eh != null)
  5496. eh (this, e);
  5497. }
  5498. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5499. protected virtual void OnValidated(EventArgs e) {
  5500. EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
  5501. if (eh != null)
  5502. eh (this, e);
  5503. }
  5504. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5505. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  5506. CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
  5507. if (eh != null)
  5508. eh (this, e);
  5509. }
  5510. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5511. protected virtual void OnVisibleChanged(EventArgs e) {
  5512. if (Visible)
  5513. CreateControl ();
  5514. EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
  5515. if (eh != null)
  5516. eh (this, e);
  5517. // We need to tell our kids (including implicit ones)
  5518. foreach (Control c in Controls.GetAllControls ())
  5519. if (c.Visible)
  5520. c.OnParentVisibleChanged (e);
  5521. }
  5522. #endregion // OnXXX methods
  5523. #region Events
  5524. #if NET_2_0
  5525. static object AutoSizeChangedEvent = new object ();
  5526. #endif
  5527. static object BackColorChangedEvent = new object ();
  5528. static object BackgroundImageChangedEvent = new object ();
  5529. #if NET_2_0
  5530. static object BackgroundImageLayoutChangedEvent = new object ();
  5531. #endif
  5532. static object BindingContextChangedEvent = new object ();
  5533. static object CausesValidationChangedEvent = new object ();
  5534. static object ChangeUICuesEvent = new object ();
  5535. static object ClickEvent = new object ();
  5536. #if NET_2_0
  5537. static object ClientSizeChangedEvent = new object ();
  5538. #endif
  5539. static object ContextMenuChangedEvent = new object ();
  5540. #if NET_2_0
  5541. static object ContextMenuStripChangedEvent = new object ();
  5542. #endif
  5543. static object ControlAddedEvent = new object ();
  5544. static object ControlRemovedEvent = new object ();
  5545. static object CursorChangedEvent = new object ();
  5546. static object DockChangedEvent = new object ();
  5547. static object DoubleClickEvent = new object ();
  5548. static object DragDropEvent = new object ();
  5549. static object DragEnterEvent = new object ();
  5550. static object DragLeaveEvent = new object ();
  5551. static object DragOverEvent = new object ();
  5552. static object EnabledChangedEvent = new object ();
  5553. static object EnterEvent = new object ();
  5554. static object FontChangedEvent = new object ();
  5555. static object ForeColorChangedEvent = new object ();
  5556. static object GiveFeedbackEvent = new object ();
  5557. static object GotFocusEvent = new object ();
  5558. static object HandleCreatedEvent = new object ();
  5559. static object HandleDestroyedEvent = new object ();
  5560. static object HelpRequestedEvent = new object ();
  5561. static object ImeModeChangedEvent = new object ();
  5562. static object InvalidatedEvent = new object ();
  5563. static object KeyDownEvent = new object ();
  5564. static object KeyPressEvent = new object ();
  5565. static object KeyUpEvent = new object ();
  5566. static object LayoutEvent = new object ();
  5567. static object LeaveEvent = new object ();
  5568. static object LocationChangedEvent = new object ();
  5569. static object LostFocusEvent = new object ();
  5570. #if NET_2_0
  5571. static object MarginChangedEvent = new object ();
  5572. #endif
  5573. static object MouseCaptureChangedEvent = new object ();
  5574. #if NET_2_0
  5575. static object MouseClickEvent = new object ();
  5576. static object MouseDoubleClickEvent = new object ();
  5577. #endif
  5578. static object MouseDownEvent = new object ();
  5579. static object MouseEnterEvent = new object ();
  5580. static object MouseHoverEvent = new object ();
  5581. static object MouseLeaveEvent = new object ();
  5582. static object MouseMoveEvent = new object ();
  5583. static object MouseUpEvent = new object ();
  5584. static object MouseWheelEvent = new object ();
  5585. static object MoveEvent = new object ();
  5586. #if NET_2_0
  5587. static object PaddingChangedEvent = new object ();
  5588. #endif
  5589. static object PaintEvent = new object ();
  5590. static object ParentChangedEvent = new object ();
  5591. #if NET_2_0
  5592. static object PreviewKeyDownEvent = new object ();
  5593. #endif
  5594. static object QueryAccessibilityHelpEvent = new object ();
  5595. static object QueryContinueDragEvent = new object ();
  5596. #if NET_2_0
  5597. static object RegionChangedEvent = new object ();
  5598. #endif
  5599. static object ResizeEvent = new object ();
  5600. static object RightToLeftChangedEvent = new object ();
  5601. static object SizeChangedEvent = new object ();
  5602. static object StyleChangedEvent = new object ();
  5603. static object SystemColorsChangedEvent = new object ();
  5604. static object TabIndexChangedEvent = new object ();
  5605. static object TabStopChangedEvent = new object ();
  5606. static object TextChangedEvent = new object ();
  5607. static object ValidatedEvent = new object ();
  5608. static object ValidatingEvent = new object ();
  5609. static object VisibleChangedEvent = new object ();
  5610. #if NET_2_0
  5611. [Browsable (false)]
  5612. [EditorBrowsable (EditorBrowsableState.Never)]
  5613. public event EventHandler AutoSizeChanged {
  5614. add { Events.AddHandler (AutoSizeChangedEvent, value);}
  5615. remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
  5616. }
  5617. #endif
  5618. public event EventHandler BackColorChanged {
  5619. add { Events.AddHandler (BackColorChangedEvent, value); }
  5620. remove { Events.RemoveHandler (BackColorChangedEvent, value); }
  5621. }
  5622. public event EventHandler BackgroundImageChanged {
  5623. add { Events.AddHandler (BackgroundImageChangedEvent, value); }
  5624. remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
  5625. }
  5626. #if NET_2_0
  5627. public event EventHandler BackgroundImageLayoutChanged {
  5628. add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
  5629. remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
  5630. }
  5631. #endif
  5632. public event EventHandler BindingContextChanged {
  5633. add { Events.AddHandler (BindingContextChangedEvent, value); }
  5634. remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
  5635. }
  5636. public event EventHandler CausesValidationChanged {
  5637. add { Events.AddHandler (CausesValidationChangedEvent, value); }
  5638. remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
  5639. }
  5640. public event UICuesEventHandler ChangeUICues {
  5641. add { Events.AddHandler (ChangeUICuesEvent, value); }
  5642. remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
  5643. }
  5644. public event EventHandler Click {
  5645. add { Events.AddHandler (ClickEvent, value); }
  5646. remove { Events.RemoveHandler (ClickEvent, value); }
  5647. }
  5648. #if NET_2_0
  5649. public event EventHandler ClientSizeChanged {
  5650. add {Events.AddHandler (ClientSizeChangedEvent, value);}
  5651. remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
  5652. }
  5653. #endif
  5654. #if NET_2_0
  5655. [Browsable (false)]
  5656. #endif
  5657. public event EventHandler ContextMenuChanged {
  5658. add { Events.AddHandler (ContextMenuChangedEvent, value); }
  5659. remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
  5660. }
  5661. #if NET_2_0
  5662. public event EventHandler ContextMenuStripChanged {
  5663. add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
  5664. remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
  5665. }
  5666. #endif
  5667. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5668. #if NET_2_0
  5669. [Browsable(true)]
  5670. #else
  5671. [Browsable(false)]
  5672. #endif
  5673. public event ControlEventHandler ControlAdded {
  5674. add { Events.AddHandler (ControlAddedEvent, value); }
  5675. remove { Events.RemoveHandler (ControlAddedEvent, value); }
  5676. }
  5677. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5678. #if NET_2_0
  5679. [Browsable(true)]
  5680. #else
  5681. [Browsable(false)]
  5682. #endif
  5683. public event ControlEventHandler ControlRemoved {
  5684. add { Events.AddHandler (ControlRemovedEvent, value); }
  5685. remove { Events.RemoveHandler (ControlRemovedEvent, value); }
  5686. }
  5687. [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
  5688. public event EventHandler CursorChanged {
  5689. add { Events.AddHandler (CursorChangedEvent, value); }
  5690. remove { Events.RemoveHandler (CursorChangedEvent, value); }
  5691. }
  5692. public event EventHandler DockChanged {
  5693. add { Events.AddHandler (DockChangedEvent, value); }
  5694. remove { Events.RemoveHandler (DockChangedEvent, value); }
  5695. }
  5696. public event EventHandler DoubleClick {
  5697. add { Events.AddHandler (DoubleClickEvent, value); }
  5698. remove { Events.RemoveHandler (DoubleClickEvent, value); }
  5699. }
  5700. public event DragEventHandler DragDrop {
  5701. add { Events.AddHandler (DragDropEvent, value); }
  5702. remove { Events.RemoveHandler (DragDropEvent, value); }
  5703. }
  5704. public event DragEventHandler DragEnter {
  5705. add { Events.AddHandler (DragEnterEvent, value); }
  5706. remove { Events.RemoveHandler (DragEnterEvent, value); }
  5707. }
  5708. public event EventHandler DragLeave {
  5709. add { Events.AddHandler (DragLeaveEvent, value); }
  5710. remove { Events.RemoveHandler (DragLeaveEvent, value); }
  5711. }
  5712. public event DragEventHandler DragOver {
  5713. add { Events.AddHandler (DragOverEvent, value); }
  5714. remove { Events.RemoveHandler (DragOverEvent, value); }
  5715. }
  5716. public event EventHandler EnabledChanged {
  5717. add { Events.AddHandler (EnabledChangedEvent, value); }
  5718. remove { Events.RemoveHandler (EnabledChangedEvent, value); }
  5719. }
  5720. public event EventHandler Enter {
  5721. add { Events.AddHandler (EnterEvent, value); }
  5722. remove { Events.RemoveHandler (EnterEvent, value); }
  5723. }
  5724. public event EventHandler FontChanged {
  5725. add { Events.AddHandler (FontChangedEvent, value); }
  5726. remove { Events.RemoveHandler (FontChangedEvent, value); }
  5727. }
  5728. public event EventHandler ForeColorChanged {
  5729. add { Events.AddHandler (ForeColorChangedEvent, value); }
  5730. remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
  5731. }
  5732. public event GiveFeedbackEventHandler GiveFeedback {
  5733. add { Events.AddHandler (GiveFeedbackEvent, value); }
  5734. remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
  5735. }
  5736. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5737. [Browsable(false)]
  5738. public event EventHandler GotFocus {
  5739. add { Events.AddHandler (GotFocusEvent, value); }
  5740. remove { Events.RemoveHandler (GotFocusEvent, value); }
  5741. }
  5742. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5743. [Browsable(false)]
  5744. public event EventHandler HandleCreated {
  5745. add { Events.AddHandler (HandleCreatedEvent, value); }
  5746. remove { Events.RemoveHandler (HandleCreatedEvent, value); }
  5747. }
  5748. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5749. [Browsable(false)]
  5750. public event EventHandler HandleDestroyed {
  5751. add { Events.AddHandler (HandleDestroyedEvent, value); }
  5752. remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
  5753. }
  5754. public event HelpEventHandler HelpRequested {
  5755. add { Events.AddHandler (HelpRequestedEvent, value); }
  5756. remove { Events.RemoveHandler (HelpRequestedEvent, value); }
  5757. }
  5758. public event EventHandler ImeModeChanged {
  5759. add { Events.AddHandler (ImeModeChangedEvent, value); }
  5760. remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
  5761. }
  5762. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5763. [Browsable(false)]
  5764. public event InvalidateEventHandler Invalidated {
  5765. add { Events.AddHandler (InvalidatedEvent, value); }
  5766. remove { Events.RemoveHandler (InvalidatedEvent, value); }
  5767. }
  5768. public event KeyEventHandler KeyDown {
  5769. add { Events.AddHandler (KeyDownEvent, value); }
  5770. remove { Events.RemoveHandler (KeyDownEvent, value); }
  5771. }
  5772. public event KeyPressEventHandler KeyPress {
  5773. add { Events.AddHandler (KeyPressEvent, value); }
  5774. remove { Events.RemoveHandler (KeyPressEvent, value); }
  5775. }
  5776. public event KeyEventHandler KeyUp {
  5777. add { Events.AddHandler (KeyUpEvent, value); }
  5778. remove { Events.RemoveHandler (KeyUpEvent, value); }
  5779. }
  5780. public event LayoutEventHandler Layout {
  5781. add { Events.AddHandler (LayoutEvent, value); }
  5782. remove { Events.RemoveHandler (LayoutEvent, value); }
  5783. }
  5784. public event EventHandler Leave {
  5785. add { Events.AddHandler (LeaveEvent, value); }
  5786. remove { Events.RemoveHandler (LeaveEvent, value); }
  5787. }
  5788. public event EventHandler LocationChanged {
  5789. add { Events.AddHandler (LocationChangedEvent, value); }
  5790. remove { Events.RemoveHandler (LocationChangedEvent, value); }
  5791. }
  5792. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5793. [Browsable(false)]
  5794. public event EventHandler LostFocus {
  5795. add { Events.AddHandler (LostFocusEvent, value); }
  5796. remove { Events.RemoveHandler (LostFocusEvent, value); }
  5797. }
  5798. #if NET_2_0
  5799. public event EventHandler MarginChanged {
  5800. add { Events.AddHandler (MarginChangedEvent, value); }
  5801. remove {Events.RemoveHandler (MarginChangedEvent, value); }
  5802. }
  5803. #endif
  5804. #if NET_2_0
  5805. public event EventHandler MouseCaptureChanged {
  5806. #else
  5807. internal event EventHandler MouseCaptureChanged {
  5808. #endif
  5809. add { Events.AddHandler (MouseCaptureChangedEvent, value); }
  5810. remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
  5811. }
  5812. #if NET_2_0
  5813. public event MouseEventHandler MouseClick
  5814. {
  5815. add { Events.AddHandler (MouseClickEvent, value); }
  5816. remove { Events.RemoveHandler (MouseClickEvent, value); }
  5817. }
  5818. public event MouseEventHandler MouseDoubleClick
  5819. {
  5820. add { Events.AddHandler (MouseDoubleClickEvent, value); }
  5821. remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
  5822. }
  5823. #endif
  5824. public event MouseEventHandler MouseDown {
  5825. add { Events.AddHandler (MouseDownEvent, value); }
  5826. remove { Events.RemoveHandler (MouseDownEvent, value); }
  5827. }
  5828. public event EventHandler MouseEnter {
  5829. add { Events.AddHandler (MouseEnterEvent, value); }
  5830. remove { Events.RemoveHandler (MouseEnterEvent, value); }
  5831. }
  5832. public event EventHandler MouseHover {
  5833. add { Events.AddHandler (MouseHoverEvent, value); }
  5834. remove { Events.RemoveHandler (MouseHoverEvent, value); }
  5835. }
  5836. public event EventHandler MouseLeave {
  5837. add { Events.AddHandler (MouseLeaveEvent, value); }
  5838. remove { Events.RemoveHandler (MouseLeaveEvent, value); }
  5839. }
  5840. public event MouseEventHandler MouseMove {
  5841. add { Events.AddHandler (MouseMoveEvent, value); }
  5842. remove { Events.RemoveHandler (MouseMoveEvent, value); }
  5843. }
  5844. public event MouseEventHandler MouseUp {
  5845. add { Events.AddHandler (MouseUpEvent, value); }
  5846. remove { Events.RemoveHandler (MouseUpEvent, value); }
  5847. }
  5848. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5849. [Browsable(false)]
  5850. public event MouseEventHandler MouseWheel {
  5851. add { Events.AddHandler (MouseWheelEvent, value); }
  5852. remove { Events.RemoveHandler (MouseWheelEvent, value); }
  5853. }
  5854. public event EventHandler Move {
  5855. add { Events.AddHandler (MoveEvent, value); }
  5856. remove { Events.RemoveHandler (MoveEvent, value); }
  5857. }
  5858. #if NET_2_0
  5859. public event EventHandler PaddingChanged
  5860. {
  5861. add { Events.AddHandler (PaddingChangedEvent, value); }
  5862. remove { Events.RemoveHandler (PaddingChangedEvent, value); }
  5863. }
  5864. #endif
  5865. public event PaintEventHandler Paint {
  5866. add { Events.AddHandler (PaintEvent, value); }
  5867. remove { Events.RemoveHandler (PaintEvent, value); }
  5868. }
  5869. public event EventHandler ParentChanged {
  5870. add { Events.AddHandler (ParentChangedEvent, value); }
  5871. remove { Events.RemoveHandler (ParentChangedEvent, value); }
  5872. }
  5873. #if NET_2_0
  5874. public event PreviewKeyDownEventHandler PreviewKeyDown {
  5875. add { Events.AddHandler (PreviewKeyDownEvent, value); }
  5876. remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
  5877. }
  5878. #endif
  5879. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
  5880. add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
  5881. remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
  5882. }
  5883. public event QueryContinueDragEventHandler QueryContinueDrag {
  5884. add { Events.AddHandler (QueryContinueDragEvent, value); }
  5885. remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
  5886. }
  5887. #if NET_2_0
  5888. public event EventHandler RegionChanged {
  5889. add { Events.AddHandler (RegionChangedEvent, value); }
  5890. remove { Events.RemoveHandler (RegionChangedEvent, value); }
  5891. }
  5892. #endif
  5893. #if NET_2_0
  5894. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5895. #endif
  5896. public event EventHandler Resize {
  5897. add { Events.AddHandler (ResizeEvent, value); }
  5898. remove { Events.RemoveHandler (ResizeEvent, value); }
  5899. }
  5900. public event EventHandler RightToLeftChanged {
  5901. add { Events.AddHandler (RightToLeftChangedEvent, value); }
  5902. remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
  5903. }
  5904. public event EventHandler SizeChanged {
  5905. add { Events.AddHandler (SizeChangedEvent, value); }
  5906. remove { Events.RemoveHandler (SizeChangedEvent, value); }
  5907. }
  5908. public event EventHandler StyleChanged {
  5909. add { Events.AddHandler (StyleChangedEvent, value); }
  5910. remove { Events.RemoveHandler (StyleChangedEvent, value); }
  5911. }
  5912. public event EventHandler SystemColorsChanged {
  5913. add { Events.AddHandler (SystemColorsChangedEvent, value); }
  5914. remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
  5915. }
  5916. public event EventHandler TabIndexChanged {
  5917. add { Events.AddHandler (TabIndexChangedEvent, value); }
  5918. remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
  5919. }
  5920. public event EventHandler TabStopChanged {
  5921. add { Events.AddHandler (TabStopChangedEvent, value); }
  5922. remove { Events.RemoveHandler (TabStopChangedEvent, value); }
  5923. }
  5924. public event EventHandler TextChanged {
  5925. add { Events.AddHandler (TextChangedEvent, value); }
  5926. remove { Events.RemoveHandler (TextChangedEvent, value); }
  5927. }
  5928. public event EventHandler Validated {
  5929. add { Events.AddHandler (ValidatedEvent, value); }
  5930. remove { Events.RemoveHandler (ValidatedEvent, value); }
  5931. }
  5932. public event CancelEventHandler Validating {
  5933. add { Events.AddHandler (ValidatingEvent, value); }
  5934. remove { Events.RemoveHandler (ValidatingEvent, value); }
  5935. }
  5936. public event EventHandler VisibleChanged {
  5937. add { Events.AddHandler (VisibleChangedEvent, value); }
  5938. remove { Events.RemoveHandler (VisibleChangedEvent, value); }
  5939. }
  5940. #endregion // Events
  5941. }
  5942. }