UIManager.cpp 287 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416
  1. #include "StdAfx.h"
  2. #include <zmouse.h>
  3. // [触屏诊断] 显式引入,避免依赖 tchar.h 的传递包含
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <tchar.h>
  7. #pragma warning(push)
  8. #pragma warning(disable:4838 4244)
  9. namespace DuiLib
  10. {
  11. /////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. //
  14. // 触屏参数(NIM Duilib 模型)
  15. // TOUCHINPUT 的坐标以 1/100 像素为单位,必须先换算成像素
  16. #ifndef TOUCH_COORD_TO_PIXEL
  17. #define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
  18. #endif
  19. // [触屏模型] 触摸只做两件事,不做任何“触摸→鼠标”的归一化:
  20. // ①点击:由 TOUCHUP 在确认未拖动后派发 BUTTONDOWN/UP,
  21. // 由 CButtonUI 等控件原生 Activate();
  22. // ②滚动:WM_TOUCH 直接派发 UIEVENT_TOUCHDOWN/MOVE/UP(见 OnTouchInput),
  23. // 容器据此 1:1 跟手平移、滚动条据此拖滑块。
  24. // “轻点 vs 拖拽”使用 m_bTouchMoved 区分,拖动不会激活控件。
  25. // WM_TOUCH 消息 ID 同样受 `#if _WIN32_WINNT >= 0x0601` 保护,DuiLib 工程未定义
  26. // _WIN32_WINNT(StdAfx.h 兜底为 XP)→ 必须自行声明,否则 switch 里引用该消息 ID
  27. // 会报 C2065(未声明的标识符)与 C2051(case 表达式不是常量)。实测固定值 0x0240。
  28. // 注:Win7+ 段受保护的不仅有结构体与函数,**消息 ID 与辅助宏同样在内**,
  29. // TOUCH_COORD_TO_PIXEL 也在上面用 #ifndef 兜底,原因相同。
  30. #ifndef WM_TOUCH
  31. #define WM_TOUCH 0x0240
  32. #endif
  33. // ======================================================================
  34. // ★★【悬浮态残留 · 跨 manager】这套"触摸抬手后抑制悬浮复活"的状态必须是
  35. // **线程级(文件级静态)**的,绝不能用 CPaintManagerUI 的成员。★★
  36. //
  37. // 反面教材(本项目真机日志实证):属性弹框 CDiandanNatureWnd **自带独立的
  38. // CPaintManagerUI m_pm**,与主窗口的 manager 不是同一个对象
  39. // (真机日志:弹框的 `MANAGER-MSG hwnd=000E04BA manager=0A29F5F8`,
  40. // 主窗口的 `MANAGER-MSG hwnd=001304D0 manager=07DA8C58`)。
  41. //
  42. // 用户点弹框里的「选好了」关掉弹框时:
  43. // · 那次触摸由**弹框的 manager** 处理 ⇒ 抑制位与参考点写在弹框那一份上;
  44. // · 弹框一销毁,系统立刻给**主窗口**补投一条 extra=0 / fromtouch=0 的
  45. // WM_MOUSEMOVE(语义"指针真的停在这")⇒ 落在**主窗口的 manager** 上。
  46. // 主窗口那份状态压根不知道刚刚发生过触摸:抑制位要么是假,要么参考点还停在
  47. // 更早那次主窗口触摸的位置 ⇒ ±8px 判据必然失败 ⇒ 解除抑制 + FindControl(pt)
  48. // 命中背后商品卡 ⇒ **悬浮态点亮且此后永不熄灭**。
  49. // (真机日志:`MODAL-DLG exit` → `HOVER-ENTER diandan_fooditem pt=778,630`,
  50. // 而主窗口那份参考点还停在 1225,446 —— 相距 447 像素。)
  51. //
  52. // 这是**线程消息队列**现象,
  53. // 与 manager 归属无关 ⇒ 状态必须线程级。
  54. // (本项目 UI 单线程;若将来多线程,把这两个 static 换成 TLS 即可。)
  55. //
  56. // 参考点存**屏幕坐标**:WM_MOUSEMOVE 的 lParam 是"接收窗口的客户区坐标",
  57. // 而触摸可能发生在另一个窗口里 —— 客户区坐标一换窗口就不可比。
  58. // ======================================================================
  59. static bool s_bSuppressHoverAfterTouch = false;
  60. static POINT s_ptLastTouchScreen = { 0, 0 };
  61. // ---------------------------------------------------------------------------
  62. // ★【Win10 Combo 下拉框"再点一下收不起来"· 根治的判据源】
  63. //
  64. // 语义只有一件事:**最近一次"点击类输入"是触摸产生的,还是鼠标产生的**。
  65. // 置真:BeginTouchSlideGesture(WM_TOUCH / WM_POINTER* 两条通道的公共入口)。
  66. // 置假:MessageHandler 收到**真正的**鼠标按键消息(非触摸提升的那一族)。
  67. // 读取点:CPaintManagerUI::GetLastInputScreenPoint —— 只服务
  68. // CComboWnd::DecideAfterFocusLoss 的"这一下是不是点在 owner Combo 上"。
  69. //
  70. // 【为什么必须有它(而不是直接用 GetCursorPos)】
  71. // 下拉框判"焦点丢失是不是用户正在点我这个 Combo"用的坐标,原来是
  72. // `::GetCursorPos()`。它在**鼠标**下是对的(鼠标就是光标),在**触摸**下却是
  73. // 错的 —— 见 BeginTouchSlideGesture 里那段的实证:系统只在"把触摸提升成鼠标"
  74. // 时才把光标挪到触点,而推动本项目 Combo 打开/关闭的**合成点击**发生在提升
  75. // **之前** ⇒ 判定读到的光标永远是**上一手**的位置。
  76. // Win7 恰好因为"提升副本会挪光标"而蒙对,Win10(WM_POINTER*,主窗口的触摸
  77. // 一条提升副本都不产生)则 100% 蒙错 —— 这就是"Win7 好、Win10 坏"的分界线。
  78. //
  79. // 【为什么不共用一个变量】`s_ptLastTouchScreen` 另有消费点(抬起后合成 MOVE 的
  80. // ±8px 悬浮抑制)。若让鼠标也去写它,鼠标点击之后紧跟的 MOVE 会被误抑制 ⇒
  81. // 悬浮态失效。故只新增一个布尔,鼠标侧一个字节都不动。
  82. //
  83. // 【自限】初始为假 ⇒ 纯鼠标机器上 GetLastInputScreenPoint() **逐字等价于**原来的
  84. // `::GetCursorPos()` ⇒ 鼠标路径行为零变化(已验收的行为一个字节不改)。
  85. // ---------------------------------------------------------------------------
  86. static bool s_bLastInputWasTouch = false;
  87. // ---------------------------------------------------------------------------
  88. // WM_POINTER* 消息 ID(Win8+)。参考 nim_duilib NativeWindow_Windows::OnPointerMsgs。
  89. //
  90. // 为什么必须自行定义:这些宏在 winuser.h 里受 `#if _WIN32_WINNT >= 0x0602` 保护,
  91. // 而本工程编译目标是 0x0601(Win7),编译期不可见。用字面量绕过(数值固定)。
  92. //
  93. // 为什么必须处理:Win10 在 Pointer 栈可用时会优先投递 WM_POINTER*,而**不是** legacy
  94. // 的 WM_TOUCH。我们此前完全不处理这条通道 —— 一旦系统走了 Pointer 路径,窗口就
  95. // 既没有 WM_TOUCH 状态机、又没有触发鼠标提升,表现就是"什么都点不动"。
  96. // nim_duilib 的注释还明确指出:WM_POINTERCAPTURECHANGED 若不设置 bHandled,
  97. // 系统会把它转换成 WM_BUTTON 类消息 —— 说明系统确实在这两条通道间做隐式转换。
  98. // ---------------------------------------------------------------------------
  99. namespace PointerMsg
  100. {
  101. const UINT DUI_WM_POINTERUPDATE = 0x0245;
  102. const UINT DUI_WM_POINTERDOWN = 0x0246;
  103. const UINT DUI_WM_POINTERUP = 0x0247;
  104. const UINT DUI_WM_POINTERENTER = 0x0249;
  105. const UINT DUI_WM_POINTERLEAVE = 0x024A;
  106. const UINT DUI_WM_POINTERACTIVATE = 0x024B;
  107. const UINT DUI_WM_POINTERCAPTURECHANGED= 0x024C;
  108. const UINT DUI_WM_POINTERWHEEL = 0x024E;
  109. const UINT DUI_WM_POINTERHWHEEL = 0x024F;
  110. // POINTER_INFO 里我们只关心主指针判定:
  111. // IS_POINTER_PRIMARY_WPARAM 的等价判断 —— 低位 bit0 = isPrimary。
  112. //
  113. // ⚠️⚠️【这台收银机上这个位域完全不可信,三个消息各不相同】⚠️⚠️
  114. //
  115. // 真机日志实测(同一次触摸的三个阶段):
  116. // msg=0x0246 WM_POINTERDOWN w=0x60170CC7 HIWORD=0x6017 bit0=1 ✓
  117. // msg=0x0245 WM_POINTERUPDATE w=0x60160CC7 HIWORD=0x6016 bit0=0 ✗
  118. // msg=0x0247 WM_POINTERUP w=0x60000CC7 HIWORD=0x6000 bit0=0 ✗
  119. //
  120. // 也就是说 **HIWORD 根本不是 MSDN 描述的 POINTER_INFO 位域**(0x6016/0x6017/0x6000
  121. // 这三个值里只有 bit0 在 0x6016→0x6017 之间来回抖,看不出 primary 语义)。
  122. // 后果极其隐蔽:
  123. // · DOWN 恰好读到 bit0=1 ⇒ 蒙对了,手势能建立;
  124. // · UPDATE 读到 bit0=0 ⇒ 被当成"非主指针"**全部丢掉**,实测 486/486 条全丢
  125. // ⇒ 手势建立成功、抬手也能派发点击(UP 早已豁免),
  126. // 但**整个过程没有任何位移信息** ⇒ 表现为"能点击,但怎么划都滑不动"。
  127. // · UP 读到 bit0=0 ⇒ 当初就踩过,已单独豁免。
  128. //
  129. // 结论(照搬 nim_duilib 的做法):**不要再依赖这个位域做过滤**。
  130. // nim_duilib 的 OnPointerMsgs 虽然也写了 IS_POINTER_PRIMARY_WPARAM,
  131. // 但它只处理单指场景、且按 pointerId 取坐标,对错位不敏感。
  132. // 本项目改为:DOWN/UPDATE/UP 一律不做 primary 过滤,
  133. // 统一用 m_dwActivePointerId 精确配对(是不是"发起本次手势的那根手指")——
  134. // 这个判据来自 pointerId(LOWORD,即日志里的 0x0CC7=3271),是可靠的。
  135. //
  136. // 本函数保留但恒返回 true,仅作为"位域不可信的显式记录点",勿再改回位域判断。
  137. inline bool IsPrimaryPointer(WPARAM wParam)
  138. {
  139. (void)wParam;
  140. return true;
  141. }
  142. }
  143. static void GetChildWndRect(HWND hWnd, HWND hChildWnd, RECT& rcChildWnd)
  144. {
  145. ::GetWindowRect(hChildWnd, &rcChildWnd);
  146. POINT pt;
  147. pt.x = rcChildWnd.left;
  148. pt.y = rcChildWnd.top;
  149. ::ScreenToClient(hWnd, &pt);
  150. rcChildWnd.left = pt.x;
  151. rcChildWnd.top = pt.y;
  152. pt.x = rcChildWnd.right;
  153. pt.y = rcChildWnd.bottom;
  154. ::ScreenToClient(hWnd, &pt);
  155. rcChildWnd.right = pt.x;
  156. rcChildWnd.bottom = pt.y;
  157. }
  158. static UINT MapKeyState()
  159. {
  160. UINT uState = 0;
  161. if (::GetKeyState(VK_CONTROL) < 0) uState |= MK_CONTROL;
  162. if (::GetKeyState(VK_LBUTTON) < 0) uState |= MK_LBUTTON;
  163. if (::GetKeyState(VK_RBUTTON) < 0) uState |= MK_RBUTTON;
  164. if (::GetKeyState(VK_SHIFT) < 0) uState |= MK_SHIFT;
  165. if (::GetKeyState(VK_MENU) < 0) uState |= MK_ALT;
  166. return uState;
  167. }
  168. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  169. ///
  170. typedef struct tagFINDTABINFO
  171. {
  172. CControlUI* pFocus;
  173. CControlUI* pLast;
  174. bool bForward;
  175. bool bNextIsIt;
  176. } FINDTABINFO;
  177. typedef struct tagFINDSHORTCUT
  178. {
  179. TCHAR ch;
  180. bool bPickNext;
  181. } FINDSHORTCUT;
  182. typedef struct tagTIMERINFO
  183. {
  184. CControlUI* pSender;
  185. UINT nLocalID;
  186. HWND hWnd;
  187. UINT uWinTimer;
  188. bool bKilled;
  189. } TIMERINFO;
  190. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. ///
  192. tagTImageInfo::tagTImageInfo()
  193. {
  194. pImage = NULL;
  195. hBitmap = NULL;
  196. }
  197. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  198. ///
  199. tagTDrawInfo::tagTDrawInfo()
  200. {
  201. Clear();
  202. }
  203. void tagTDrawInfo::Parse(LPCTSTR pStrImage, LPCTSTR pStrModify, CPaintManagerUI* pManager)
  204. {
  205. // 1、aaa.jpg
  206. // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
  207. // mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false'
  208. sDrawString = pStrImage;
  209. sDrawModify = pStrModify;
  210. sImageName = pStrImage;
  211. CDuiString sItem;
  212. CDuiString sValue;
  213. LPTSTR pstr = NULL;
  214. for (int i = 0; i < 2; ++i)
  215. {
  216. if (i == 1) pStrImage = pStrModify;
  217. if (!pStrImage) continue;
  218. while (*pStrImage != _T('\0'))
  219. {
  220. sItem.Empty();
  221. sValue.Empty();
  222. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  223. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  224. {
  225. LPTSTR pstrTemp = ::CharNext(pStrImage);
  226. while (pStrImage < pstrTemp)
  227. {
  228. sItem += *pStrImage++;
  229. }
  230. }
  231. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  232. if (*pStrImage++ != _T('=')) break;
  233. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  234. if (*pStrImage++ != _T('\'')) break;
  235. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  236. {
  237. LPTSTR pstrTemp = ::CharNext(pStrImage);
  238. while (pStrImage < pstrTemp)
  239. {
  240. sValue += *pStrImage++;
  241. }
  242. }
  243. if (*pStrImage++ != _T('\'')) break;
  244. if (!sValue.IsEmpty())
  245. {
  246. if (sItem == _T("file") || sItem == _T("res"))
  247. {
  248. sImageName = sValue;
  249. }
  250. else if (sItem == _T("restype"))
  251. {
  252. sResType = sValue;
  253. }
  254. else if (sItem == _T("dest"))
  255. {
  256. rcDest.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  257. rcDest.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  258. rcDest.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  259. rcDest.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  260. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcDest);
  261. }
  262. else if (sItem == _T("source"))
  263. {
  264. rcSource.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  265. rcSource.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  266. rcSource.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  267. rcSource.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  268. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcSource);
  269. }
  270. else if (sItem == _T("corner"))
  271. {
  272. rcCorner.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  273. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  274. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  275. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  276. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcCorner);
  277. }
  278. else if (sItem == _T("mask"))
  279. {
  280. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  281. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  282. }
  283. else if (sItem == _T("fade"))
  284. {
  285. uFade = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  286. }
  287. else if (sItem == _T("rotate"))
  288. {
  289. uRotate = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  290. bGdiplus = true;
  291. }
  292. else if (sItem == _T("gdiplus"))
  293. {
  294. bGdiplus = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  295. }
  296. else if (sItem == _T("hole"))
  297. {
  298. bHole = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  299. }
  300. else if (sItem == _T("xtiled"))
  301. {
  302. bTiledX = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  303. }
  304. else if (sItem == _T("ytiled"))
  305. {
  306. bTiledY = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  307. }
  308. else if (sItem == _T("hsl"))
  309. {
  310. bHSL = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  311. }
  312. else if (sItem == _T("size"))
  313. {
  314. szImage.cx = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  315. szImage.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  316. }
  317. else if (sItem == _T("align"))
  318. {
  319. sAlign = sValue;
  320. }
  321. else if (sItem == _T("padding"))
  322. {
  323. rcPadding.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  324. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  325. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  326. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  327. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcPadding);
  328. }
  329. }
  330. if (*pStrImage++ != _T(' ')) break;
  331. }
  332. }
  333. // 调整DPI资源
  334. if (pManager != NULL && pManager->GetDPIObj()->GetScale() != 100)
  335. {
  336. CDuiString sScale;
  337. sScale.Format(_T("@%d."), pManager->GetDPIObj()->GetScale());
  338. sImageName.Replace(_T("."), sScale);
  339. }
  340. }
  341. void tagTDrawInfo::Clear()
  342. {
  343. sDrawString.Empty();
  344. sDrawModify.Empty();
  345. sImageName.Empty();
  346. memset(&rcDest, 0, sizeof(RECT));
  347. memset(&rcSource, 0, sizeof(RECT));
  348. memset(&rcCorner, 0, sizeof(RECT));
  349. dwMask = 0;
  350. uFade = 255;
  351. uRotate = 0;
  352. bHole = false;
  353. bTiledX = false;
  354. bTiledY = false;
  355. bHSL = false;
  356. bGdiplus = false;
  357. szImage.cx = szImage.cy = 0;
  358. sAlign.Empty();
  359. memset(&rcPadding, 0, sizeof(RECT));
  360. }
  361. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  362. ///
  363. typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  364. PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL;
  365. HPEN m_hUpdateRectPen = NULL;
  366. HINSTANCE CPaintManagerUI::m_hResourceInstance = NULL;
  367. CDuiString CPaintManagerUI::m_pStrResourcePath;
  368. CDuiString CPaintManagerUI::m_pStrResourceZip;
  369. CDuiString CPaintManagerUI::m_pStrResourceZipPwd; //Garfield 20160325 带密码zip包解密
  370. HANDLE CPaintManagerUI::m_hResourceZip = NULL;
  371. bool CPaintManagerUI::m_bCachedResourceZip = true;
  372. BYTE* CPaintManagerUI::m_cbZipBuf = nullptr;
  373. int CPaintManagerUI::m_nResType = UILIB_FILE;
  374. TResInfo CPaintManagerUI::m_SharedResInfo;
  375. HINSTANCE CPaintManagerUI::m_hInstance = NULL;
  376. bool CPaintManagerUI::m_bUseHSL = false;
  377. short CPaintManagerUI::m_H = 180;
  378. short CPaintManagerUI::m_S = 100;
  379. short CPaintManagerUI::m_L = 100;
  380. CStdPtrArray CPaintManagerUI::m_aPreMessages;
  381. CStdPtrArray CPaintManagerUI::m_aPlugins;
  382. CPaintManagerUI::CPaintManagerUI() :
  383. m_hWndPaint(NULL),
  384. m_hDcPaint(NULL),
  385. m_hDcOffscreen(NULL),
  386. m_hDcBackground(NULL),
  387. m_bOffscreenPaint(true),
  388. m_hbmpOffscreen(NULL),
  389. m_pOffscreenBits(NULL),
  390. m_hbmpBackground(NULL),
  391. m_pBackgroundBits(NULL),
  392. m_hwndTooltip(NULL),
  393. m_uTimerID(0x1000),
  394. m_pRoot(NULL),
  395. m_pFocus(NULL),
  396. m_pEventHover(NULL),
  397. m_pEventClick(NULL),
  398. m_pEventRClick(NULL),
  399. m_pEventKey(NULL),
  400. m_bFirstLayout(true),
  401. m_bFocusNeeded(false),
  402. m_bUpdateNeeded(false),
  403. m_bMouseTracking(false),
  404. m_bMouseCapture(false),
  405. m_bAsyncNotifyPosted(false),
  406. m_bUsedVirtualWnd(false),
  407. m_bForceUseSharedRes(false),
  408. m_nOpacity(0xFF),
  409. m_bLayered(false),
  410. m_bLayeredChanged(false),
  411. m_bShowUpdateRect(false),
  412. m_bUseGdiplusText(false),
  413. m_trh(0),
  414. m_bDragDrop(false),
  415. m_bDragMode(false),
  416. m_hDragBitmap(NULL),
  417. m_pDPI(NULL),
  418. m_iHoverTime(400UL),
  419. // [FIX] m_bNoActivate 原本未初始化:Debug 堆新块填充 0xCD -> 读到 true;
  420. // Release 下则是随机垃圾值,属偶发性隐患。
  421. // 后果:本文件中 3 处 "if (!m_bNoActivate) ::SetFocus(m_hWndPaint);"
  422. // (WM_LBUTTONDOWN 1738 / CPaintManagerUI::SetFocus 2442 / SetFocusNeeded 2475) 全部被跳过,
  423. // 系统焦点无法回到主窗口 -> 原生 EDIT 子窗 CEditWnd 收不到 WM_KILLFOCUS ->
  424. // 其唯一的销毁途径 PostMessage(WM_CLOSE) 永不触发 -> 光标常闪、点空白不丢焦点。
  425. // XML 侧仅在显式书写 noactivate 属性时才赋值(UIDlgBuilder.cpp),故此处必须先给确定初值。
  426. m_bNoActivate(false),
  427. // 以下两个成员同样是漏网之鱼(全库无赋值点),一并清零以防后患。
  428. m_bIsPainting(false),
  429. m_pLastToolTip(NULL),
  430. // [指针通道] 默认【开启】。原因见成员声明处的长注释:
  431. // 之前"默认关闭、收到 WM_TOUCH 即永久关闭"的策略害死了真模态弹框 ——
  432. // 这台受测试的收银机上,WM_TOUCH 的"贪婪归属权"卡在主窗口,
  433. // 弹框永远收不到 WM_TOUCH,只收得到按命中投递的 WM_POINTER*;
  434. // 指针通道又被关掉 ⇒ 弹框彻底没有输入源,怎么点都没反应。
  435. // 现在改为【始终开启 + 手势级让路】:只要某一侧先开始驱动本次手势,
  436. // 另一侧就整段手势安静,绝不出现两套 WM_LBUTTONDOWN/UP。
  437. m_bPointerNormalizeEnabled(true),
  438. m_bPointerGestureActive(false),
  439. m_dwActivePointerId(0),
  440. m_dwPointerDownTick(0),
  441. // 顺序必须与 UIManager.h 里的声明顺序一致,否则 MSVC 报 -Wreorder(C5038)。
  442. m_pfnDefProcRelay(NULL),
  443. m_hWndDefProcRelay(NULL),
  444. m_bRelayDefProcForTouchMove(false)
  445. {
  446. // [WM_TOUCH 归属权] 补调 DefWindowProc 的开关读取(无需重新编译即可切换)。
  447. // 设 DUI_RELAY_DEFPROC=1 开启;只在进程启动时读一次。
  448. {
  449. TCHAR szBuf[16] = { 0 };
  450. const DWORD dwLen = ::GetEnvironmentVariable(_T("DUI_RELAY_DEFPROC"), szBuf, _countof(szBuf));
  451. if (dwLen > 0 && dwLen < _countof(szBuf) && szBuf[0] == _T('1'))
  452. {
  453. m_bRelayDefProcForTouchMove = true;
  454. }
  455. }
  456. if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  457. {
  458. m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA;
  459. m_SharedResInfo.m_dwDefaultFontColor = 0xFF000000;
  460. m_SharedResInfo.m_dwDefaultLinkFontColor = 0xFF0000FF;
  461. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = 0xFFD3215F;
  462. m_SharedResInfo.m_dwDefaultSelectedBkColor = 0xFFBAE4FF;
  463. LOGFONT lf = { 0 };
  464. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  465. lf.lfCharSet = DEFAULT_CHARSET;
  466. HFONT hDefaultFont = ::CreateFontIndirect(&lf);
  467. m_SharedResInfo.m_DefaultFontInfo.hFont = hDefaultFont;
  468. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  469. m_SharedResInfo.m_DefaultFontInfo.iSize = -lf.lfHeight;
  470. m_SharedResInfo.m_DefaultFontInfo.bBold = (lf.lfWeight >= FW_BOLD);
  471. m_SharedResInfo.m_DefaultFontInfo.bUnderline = (lf.lfUnderline == TRUE);
  472. m_SharedResInfo.m_DefaultFontInfo.bItalic = (lf.lfItalic == TRUE);
  473. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  474. }
  475. m_ResInfo.m_dwDefaultDisabledColor = m_SharedResInfo.m_dwDefaultDisabledColor;
  476. m_ResInfo.m_dwDefaultFontColor = m_SharedResInfo.m_dwDefaultFontColor;
  477. m_ResInfo.m_dwDefaultLinkFontColor = m_SharedResInfo.m_dwDefaultLinkFontColor;
  478. m_ResInfo.m_dwDefaultLinkHoverFontColor = m_SharedResInfo.m_dwDefaultLinkHoverFontColor;
  479. m_ResInfo.m_dwDefaultSelectedBkColor = m_SharedResInfo.m_dwDefaultSelectedBkColor;
  480. if (m_hUpdateRectPen == NULL)
  481. {
  482. m_hUpdateRectPen = ::CreatePen(PS_SOLID, 1, RGB(220, 0, 0));
  483. // Boot Windows Common Controls (for the ToolTip control)
  484. ::InitCommonControls();
  485. ::LoadLibrary(_T("msimg32.dll"));
  486. }
  487. m_szMinWindow.cx = 0;
  488. m_szMinWindow.cy = 0;
  489. m_szMaxWindow.cx = 0;
  490. m_szMaxWindow.cy = 0;
  491. m_szInitWindowSize.cx = 0;
  492. m_szInitWindowSize.cy = 0;
  493. m_szRoundCorner.cx = m_szRoundCorner.cy = 0;
  494. ::ZeroMemory(&m_rcSizeBox, sizeof(m_rcSizeBox));
  495. ::ZeroMemory(&m_rcCaption, sizeof(m_rcCaption));
  496. ::ZeroMemory(&m_rcLayeredInset, sizeof(m_rcLayeredInset));
  497. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  498. m_ptLastMousePos.x = m_ptLastMousePos.y = -1;
  499. m_pGdiplusStartupInput = new Gdiplus::GdiplusStartupInput;
  500. Gdiplus::GdiplusStartup(&m_gdiplusToken, m_pGdiplusStartupInput, NULL); // 加载GDI接口
  501. CShadowUI::Initialize(m_hInstance);
  502. m_pDragDrop = NULL;
  503. }
  504. CPaintManagerUI::~CPaintManagerUI()
  505. {
  506. // Delete the control-tree structures
  507. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++) delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  508. m_aDelayedCleanup.Resize(0);
  509. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  510. m_aAsyncNotify.Resize(0);
  511. m_mNameHash.Resize(0);
  512. if (m_pRoot != NULL) delete m_pRoot;
  513. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  514. RemoveAllFonts();
  515. RemoveAllImages();
  516. RemoveAllStyle();
  517. RemoveAllDefaultAttributeList();
  518. RemoveAllWindowCustomAttribute();
  519. RemoveAllOptionGroups();
  520. RemoveAllTimers();
  521. RemoveAllDrawInfos();
  522. if (m_hwndTooltip != NULL)
  523. {
  524. ::DestroyWindow(m_hwndTooltip);
  525. m_hwndTooltip = NULL;
  526. }
  527. if (!m_aFonts.IsEmpty())
  528. {
  529. for (int i = 0; i < m_aFonts.GetSize(); ++i)
  530. {
  531. HANDLE handle = static_cast<HANDLE>(m_aFonts.GetAt(i));
  532. ::RemoveFontMemResourceEx(handle);
  533. }
  534. }
  535. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  536. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  537. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  538. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  539. if (m_hDcPaint != NULL) ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  540. m_aPreMessages.Remove(m_aPreMessages.Find(this));
  541. // 销毁拖拽图片
  542. if (m_hDragBitmap != NULL) ::DeleteObject(m_hDragBitmap);
  543. //卸载GDIPlus
  544. Gdiplus::GdiplusShutdown(m_gdiplusToken);
  545. delete m_pGdiplusStartupInput;
  546. // DPI管理对象
  547. if (m_pDPI != NULL)
  548. {
  549. delete m_pDPI;
  550. m_pDPI = NULL;
  551. }
  552. }
  553. void CPaintManagerUI::Init(HWND hWnd, LPCTSTR pstrName)
  554. {
  555. ASSERT(::IsWindow(hWnd));
  556. m_mNameHash.Resize();
  557. RemoveAllFonts();
  558. RemoveAllImages();
  559. RemoveAllStyle();
  560. RemoveAllDefaultAttributeList();
  561. RemoveAllWindowCustomAttribute();
  562. RemoveAllOptionGroups();
  563. RemoveAllTimers();
  564. m_sName.Empty();
  565. if (pstrName != NULL) m_sName = pstrName;
  566. if (m_hWndPaint != hWnd)
  567. {
  568. m_hWndPaint = hWnd;
  569. m_hDcPaint = ::GetDC(hWnd);
  570. m_aPreMessages.Add(this);
  571. // 触屏兼容:每个窗口(主窗口 + 所有弹框)统一注册 WM_TOUCH,由本类库级接管,
  572. // 无需 CTouchWindowBase 外挂,也无需逐窗口样板。注册是幂等的,重复调用无害。
  573. InitTouchSupport();
  574. }
  575. }
  576. // ---------------------------------------------------------------------------
  577. // 真模态(DialogBox)支持:manager 的 paint window 迁移。
  578. // 详见 UIManager.h 里的说明。这两个方法**不**触碰任何资源状态,只换窗口绑定。
  579. // ---------------------------------------------------------------------------
  580. void CPaintManagerUI::DetachPaintWindow()
  581. {
  582. if (m_hDcPaint != NULL)
  583. {
  584. ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  585. m_hDcPaint = NULL;
  586. }
  587. const int nIndex = m_aPreMessages.Find(this);
  588. if (nIndex >= 0) m_aPreMessages.Remove(nIndex);
  589. // 注意:m_hWndPaint 暂不置空 —— AttachPaintWindow 会覆盖它。
  590. // 也不要清空控件树 / 字体 / 图片:那些是"内容",迁移后要继续用。
  591. }
  592. void CPaintManagerUI::AttachPaintWindow(HWND hWnd)
  593. {
  594. ASSERT(::IsWindow(hWnd));
  595. if (hWnd == NULL || !::IsWindow(hWnd)) return;
  596. // ------------------------------------------------------------------
  597. // ⚠️⚠️ 【必须在这里清掉跨窗口残留的输入状态】—— 真机 bug 根治点 ⚠️⚠️
  598. //
  599. // 背景:真模态把**同一个** manager 从旧窗口 Detach、再 Attach 到弹框
  600. // (见 UIBase.cpp 的 ShowModal / __DialogProc)。
  601. // 而 AttachDialog()(非模态路径)在挂控件树前会显式清掉一组输入状态:
  602. // SetFocus(NULL); m_pEventKey=NULL; m_pEventHover=NULL;
  603. // m_pEventClick=NULL; m_pEventRClick=NULL;
  604. // 这两个函数职责相同(都是"把 manager 挂到一个窗口/控件树上"),
  605. // **但本函数当初漏了同一组清理**。迁移时这些指针和标记就原样"住进"了弹框。
  606. //
  607. // 由此产生两个真机现象:
  608. // ① 「商品控件的悬浮态要等弹框关闭才消失」——
  609. // m_pEventHover 仍指着主窗口那个商品控件(控件树是同一棵,没有被换掉),
  610. // 而弹框期间触摸消息都发往弹框,主窗口那条 HOT 就再也没人去清。
  611. // ② 「弹框刚出来就被同一次手势自动点掉 / 咚一声」——
  612. // m_pEventClick、m_bMouseCapture 等属于"上一次手势"的中间态被带进弹框,
  613. // 弹框的第一条输入消息就撞上一个"正在进行中的手势",状态机接续错误。
  614. //
  615. // 修法:迁移时把**属于旧窗口的输入状态**全部归零,让弹框从干净状态起步。
  616. // ⚠️ 只清"输入态",绝不动控件树 / 字体 / 图片 —— 那些是"内容",要继续用
  617. // (与 DetachPaintWindow 的注释保持同一原则)。
  618. // ⚠️ 这里不清 m_bSuppressPromotedTouchMouse / m_dwSuppressTick ——
  619. // 它们正是用来"吞掉本次手势残留的提升鼠标消息"的,清了反而会让
  620. // Win7 的咚声与自动点弹框回来(见 MessageHandler 的拦截块)。
  621. // ------------------------------------------------------------------
  622. // 先把悬浮态正式收掉(发 MOUSELEAVE 给旧控件,让 HOT 立即熄灭),
  623. // 而不是只把指针置空 —— 只置空的话控件的 UISTATE_HOT 会留在被点亮的颜色上。
  624. {
  625. POINT ptDummy = { -1, -1 };
  626. ClearTouchHoverState(ptDummy);
  627. }
  628. // [顺序修复] 这里**不再**遍历全树清"按下态"。
  629. //
  630. // 为什么不在这里清:
  631. // 模态搬家(DetachPaintWindow → DestroyWindow(旧窗口) → AttachPaintWindow)
  632. // 发生在**业务回调内部**(ShowModal)。而用户报的"点击的商品按压态不消失"
  633. // 必须在**业务回调之前**就收掉 —— 一旦进到这里,弹框已经建好了,
  634. // 卡片还顶着 "pressed" 的那一帧已经画出去了。
  635. // ⇒ 正确的时点是触摸链放行业务回调之前(CPaintManagerUI::TouchUp)。
  636. //
  637. // 保持现状的代价:搬家时旧窗口的输入态不再被兜底清掉。这是**有意的**——
  638. // 触摸链、鼠标路径各自都会在"抬起"时把自己的状态收干净;搬家再清一遍
  639. // 属于事后补救,而事后补救正是前面几轮"清得太晚"的病根(见 TouchUp 的注释)。
  640. m_pEventKey = NULL;
  641. m_pEventClick = NULL;
  642. m_pEventRClick = NULL;
  643. // 旧窗口上若还留着鼠标捕获 / 拖拽模式,这里一并释放:
  644. // 捕获属于旧 HWND,跟着 manager 搬到新窗口毫无意义,只会让新窗口误判"正在捕获"。
  645. if (m_bMouseCapture || m_bDragMode)
  646. ReleaseCapture();
  647. m_bMouseTracking = false;
  648. s_bSuppressHoverAfterTouch = true;
  649. m_hWndPaint = hWnd;
  650. m_hDcPaint = ::GetDC(hWnd);
  651. // 重新加入全局表(Detach 时摘除过)。若之前没摘(异常路径),避免重复添加。
  652. if (m_aPreMessages.Find(this) < 0) m_aPreMessages.Add(this);
  653. // 新窗口必须注册触摸,否则收不到 WM_TOUCH。
  654. InitTouchSupport();
  655. }
  656. // ---------------------------------------------------------------------------
  657. // 触摸 API 懒加载包装(对标 NIM Duilib 的 RegisterTouchWindowWrapper 系列)。
  658. //
  659. // 为什么不能直接调用这些 API:DuiLib 工程自身没有定义 _WIN32_WINNT,
  660. // StdAfx.h 会把它兜底设成 XP(0x0501);而 TOUCHINPUT / GetTouchInputInfo /
  661. // RegisterTouchWindow 在 winuser.h 里受 `#if _WIN32_WINNT >= 0x0601` 保护,
  662. // 直接引用会编译报错(C2065/C3861)。(主工程定义了 0x0601,所以
  663. // CTouchWindowBase 里能直接用,那里不受影响。)
  664. //
  665. // 因此这里完全自给自足:自行声明与 SDK 完全一致的 TOUCHINPUT 布局和事件标志,
  666. // 再用 GetProcAddress 取函数地址。这样:
  667. // * 无论 DuiLib 的 target 版本如何都能编译通过;
  668. // * 在没有触摸 API 的系统上自动降级为空操作,不会崩溃。
  669. // ---------------------------------------------------------------------------
  670. namespace TouchApi
  671. {
  672. // 与 winuser.h 的 tagTOUCHINPUT 布局逐字段一致
  673. typedef struct tagTouchInput
  674. {
  675. LONG x;
  676. LONG y;
  677. HANDLE hSource;
  678. DWORD dwID;
  679. DWORD dwFlags;
  680. DWORD dwMask;
  681. DWORD dwTime;
  682. ULONG_PTR dwExtraInfo;
  683. DWORD cxContact;
  684. DWORD cyContact;
  685. } TOUCHINPUT, *PTOUCHINPUT;
  686. // 事件标志,数值与 winuser.h 的触摸事件标志一致。
  687. // 名字必须避开 SDK 的同名宏:部分 SDK 把它们定义成【宏】,且不受 _WIN32_WINNT 版本段保护,
  688. // 同名会被预处理器展开——声明变成 `const DWORD 0x0002 = 0x0002;`(C2059),
  689. // 限定使用变成 `TouchApi::0x0004`(C2589)。故改用 TOUCHEVTFLAG 前缀。
  690. const DWORD TOUCHEVTFLAG_MOVE = 0x0001;
  691. const DWORD TOUCHEVTFLAG_DOWN = 0x0002;
  692. const DWORD TOUCHEVTFLAG_UP = 0x0004;
  693. typedef BOOL (WINAPI *PFN_RegisterTouchWindow)(HWND, ULONG);
  694. typedef BOOL (WINAPI *PFN_GetTouchInputInfo)(HANDLE, UINT, PTOUCHINPUT, int);
  695. typedef BOOL (WINAPI *PFN_CloseTouchInputHandle)(HANDLE);
  696. inline HMODULE GetUser32()
  697. {
  698. static HMODULE s_hMod = NULL;
  699. static bool s_bInited = false;
  700. if (!s_bInited)
  701. {
  702. s_bInited = true;
  703. s_hMod = ::GetModuleHandle(_T("user32.dll"));
  704. }
  705. return s_hMod;
  706. }
  707. inline PFN_RegisterTouchWindow GetRegisterTouchWindow()
  708. {
  709. static PFN_RegisterTouchWindow s_pfn = NULL;
  710. static bool s_bInited = false;
  711. if (!s_bInited)
  712. {
  713. s_bInited = true;
  714. HMODULE hMod = GetUser32();
  715. if (hMod != NULL) s_pfn = (PFN_RegisterTouchWindow)::GetProcAddress(hMod, "RegisterTouchWindow");
  716. }
  717. return s_pfn;
  718. }
  719. inline PFN_GetTouchInputInfo GetGetTouchInputInfo()
  720. {
  721. static PFN_GetTouchInputInfo s_pfn = NULL;
  722. static bool s_bInited = false;
  723. if (!s_bInited)
  724. {
  725. s_bInited = true;
  726. HMODULE hMod = GetUser32();
  727. if (hMod != NULL) s_pfn = (PFN_GetTouchInputInfo)::GetProcAddress(hMod, "GetTouchInputInfo");
  728. }
  729. return s_pfn;
  730. }
  731. inline PFN_CloseTouchInputHandle GetCloseTouchInputHandle()
  732. {
  733. static PFN_CloseTouchInputHandle s_pfn = NULL;
  734. static bool s_bInited = false;
  735. if (!s_bInited)
  736. {
  737. s_bInited = true;
  738. HMODULE hMod = GetUser32();
  739. if (hMod != NULL) s_pfn = (PFN_CloseTouchInputHandle)::GetProcAddress(hMod, "CloseTouchInputHandle");
  740. }
  741. return s_pfn;
  742. }
  743. }
  744. // ---------------------------------------------------------------------------
  745. // [触屏] 手指容差(滚动条专治)
  746. // 滚动条默认仅 16px 宽(CScrollBarUI::DEFAULT_SCROLLBAR_SIZE),指尖按偏 5~10px 就落到
  747. // 右侧内容上:内容会跟手滚动,但“滑块拖不动”——用户感知就是“滚动条没法在触屏上滑动”。
  748. // 两个措施:①把触点横向收进滚动条 rect,再交给滚动条自己判滑块;②若直接命中的不是
  749. // 滚动条,但触点容差范围内正好压在某个滚动条的滑块上,则改判为命中该滚动条。
  750. // ---------------------------------------------------------------------------
  751. // ======================================================================
  752. // ★★【第二次合成点击 · 根治】"触摸通道处理过的这次手势,其提升鼠标副本一律作废" ★★
  753. // ======================================================================
  754. //
  755. // 【背景:一次手势会被处理两遍】
  756. // 手指点一下,DuiLib 会经历两遍:
  757. // ① 触摸通道(WM_TOUCH / WM_POINTER*)合成 BUTTONDOWN/BUTTONUP —— 业务的
  758. // 点击回调在这里跑,`ShowModal()` 的嵌套模态循环也在这里开;
  759. // ② Windows 随后把**同一次触摸**提升成鼠标消息(MOVE + LBUTTONDOWN +
  760. // LBUTTONUP,extra 带 MOUSEEVENTF_FROMTOUCH)。它是纯重复,必须作废。
  761. //
  762. // 【为什么 ② 一定还会来,但 ② 投给谁却会变】
  763. // ② 投给谁取决于**投递那一刻**的窗口状态,与 ① 时刻可能完全不同:
  764. // · 该点此刻已被弹框覆盖 ⇒ 投给**弹框**(前台且启用)⇒ 窗口过程收得到,能拦;
  765. // · 该点此刻仍在 owner 上 ⇒ 投给**被禁用的 owner** ⇒ 系统直接
  766. // MessageBeep(0) + 丢弃 ⇒ **窗口过程根本收不到**(真机日志实证:该坐标
  767. // 附近 0 条提升消息)⇒ 这就是 Win7 上"弹框一出来就咚一声"的全部成因。
  768. //
  769. // 【为什么"按代数水位去重"那类旧判据不行】(Win7 真机实测)
  770. // · 水位在**任意一条**提升消息到达时就追平 ⇒ "关闭弹框那一次手势"的副本到达时
  771. // 已无脏可判 ⇒ 放行 ⇒ 透传。25 次手势里漏 6 次,全是这一种。
  772. // · extra 指纹:Win7 上 extra **恒定**(59/59 条相同)⇒ 指纹去重彻底失效。
  773. // (Win10 的 extra 低字节每次手势都变,同一套方案在 Win10 上"看起来是对的"。)
  774. //
  775. // 【新判据:只依赖一件事实 —— 触摸通道收到了这次手势】
  776. // 收到了 ⇒ 提升副本必是重复 ⇒ 作废。与模态边界、代数、extra 全都无关,
  777. // 因此对"关闭弹框的那一次手势"同样有效(那正是旧判据唯一漏掉的一类)。
  778. //
  779. // ⚠️ 标志**只由触摸通道**置位(BeginTouchSlideGesture —— 两条通道共用的
  780. // "新手势开始"入口)。若某台机器两条通道都收不到(只会收到提升鼠标),
  781. // 标志恒假 ⇒ 提升鼠标照常放行 ⇒ **不会把整机点不动**。
  782. // 这条自限边界是本方案敢用的前提,务必保留。
  783. //
  784. // 【为什么还要比坐标】
  785. // 若某次手势的提升副本被系统吃掉(上面那种"咚"的情况),标志会一直挂着。
  786. // 此时若出现"触摸通道收不到、只能靠提升鼠标"的窗口(例如弹框的触摸注册
  787. // 被样式变更隐式注销),不加坐标判据就会把它的真实点击一起吞掉 ⇒ 点不动。
  788. // 加上 ±16px(与滑动阈值同一量级)判据后,陈旧标志不会误伤无关位置的点击。
  789. // 坐标一律换算到**屏幕坐标**再比 —— ② 可能落在**另一个窗口的客户区**里
  790. // (弹框会拦截同一物理点的消息,lParam 是弹框的客户区坐标)。
  791. // ======================================================================
  792. static bool s_bPromotedMouseDuplicate = false; // 有"待作废的提升副本"
  793. static POINT s_ptPromotedMouseDuplicate = { 0, 0 }; // 那次手势的**屏幕**坐标
  794. static const int kPromotedDuplicateSlop = 16; // 手指抖动容差(像素)
  795. // 【Combo 下拉框"点了不出来"】"刚刚真的投递过一条**提升鼠标点击**"的一次性受理位。
  796. // 置位点:MessageHandler 里确认为提升鼠标消息(DOWN/UP/DBLCLK)的那一支。
  797. // 读取点:UICombo.cpp 的 CComboWnd::DecideAfterFocusLoss(读完即清,见该函数注释)。
  798. // 目的:让下拉框能区分"这次焦点丢失是打开我那一出手势的回声"(系统行为,要忍)
  799. // 和"用户真的点了别处"(要关框)。
  800. // 【自限】不产生提升副本的平台(Win10 走 WM_POINTER*,提升鼠标点击 0 条)
  801. // 本标志恒为假 ⇒ 调用方行为与改动前**逐字一致**。
  802. static bool s_bPromotedMouseClickJustSeen = false;
  803. // 三者都只在本文件内使用 ⇒ 一律 static(内部链接),避免与别的 TU 里的
  804. // 同名符号在 DuiLib 命名空间里撞车(C2668 的典型成因)。
  805. static void ArmPromotedMouseDuplicate(const POINT& ptScreen)
  806. {
  807. s_bPromotedMouseDuplicate = true;
  808. s_ptPromotedMouseDuplicate = ptScreen;
  809. }
  810. static void DisarmPromotedMouseDuplicate()
  811. {
  812. s_bPromotedMouseDuplicate = false;
  813. }
  814. // 本条提升鼠标消息是否属于"待作废的那次手势副本"。
  815. // 参数 ptClient 是消息 lParam 里的**接收窗口客户区**坐标。
  816. static bool IsPromotedMouseDuplicate(HWND hWndPaint, const POINT& ptClient)
  817. {
  818. if (!s_bPromotedMouseDuplicate) return false;
  819. POINT ptScreen = ptClient;
  820. if (hWndPaint != NULL && ::IsWindow(hWndPaint))
  821. ::ClientToScreen(hWndPaint, &ptScreen);
  822. const LONG dx = ptScreen.x - s_ptPromotedMouseDuplicate.x;
  823. const LONG dy = ptScreen.y - s_ptPromotedMouseDuplicate.y;
  824. return (dx <= kPromotedDuplicateSlop && dx >= -kPromotedDuplicateSlop
  825. && dy <= kPromotedDuplicateSlop && dy >= -kPromotedDuplicateSlop);
  826. }
  827. // ======================================================================
  828. // ★★【Win7"咚"声 · 根治】进模态循环之前,把"在途的提升鼠标副本"从消息队列里摘掉 ★★
  829. //
  830. // 【现象】
  831. // Win7 上"点主窗口商品卡 → 弹出弹框"时会听到一声"咚"。它是**系统**发出的
  832. // `MessageBeep(0)`:属于**弹框出现之前**那一次手势的提升鼠标副本,在弹框已经把
  833. // owner `EnableWindow(FALSE)` 禁用之后才被投递 ⇒ 撞上"点击禁用窗口"的默认处理。
  834. //
  835. // 【已经逐条排除的方向(都有真机日志支撑,不要再回头走)】
  836. // · 写在窗口过程里的闸门:
  837. // 消息**根本没进窗口过程**,判据再准也无从生效。
  838. // · WH_MOUSE_LL 低级鼠标钩子:钩子过程运行在**安装它的线程**(正是消息接收线程)
  839. // 上,队列里的鼠标消息先于钩子被抽出 ⇒ 真机日志里提升副本照旧投递,一条没少。
  840. // · 让 owner 在"副本在途"期间保持启用(能消音,但不可接受):owner 的鼠标消息
  841. // 会因此落到 manager 上,而真模态期间 manager 已经搬到弹框
  842. // (DetachPaintWindow → AttachPaintWindow)⇒ 此时 `m_hWndPaint` 指向**弹框**,
  843. // owner 的客户区坐标会被拿去**弹框的控件树**里 FindControl,可能凭空命中
  844. // 弹框上的某个控件。
  845. //
  846. // 【根治点:让它根本不存在】
  847. // 既然拦不住"投递阶段"的系统行为,就在**投递之前**把它从队列里摘掉。
  848. // 调用点在 `CWindowWnd::ShowModal` 进模态循环之前(见那里的长注释)。
  849. // 为什么那个时刻一定赶得上:这条副本是在**同一次触摸**的输入处理里被排进队列的,
  850. // 而调用方的触摸 UP 此刻**已经被处理完**(业务回调就是正在执行的这段代码)
  851. // ⇒ 副本必然已经在队列里(真机日志亦实证:它被卡在队列里,直到弹框关闭、
  852. // owner 重新启用之后才被投递)。而"摘除"与"创建弹框"之间没有任何消息泵
  853. // ⇒ 摘除对投递而言是**原子**的。
  854. //
  855. // 【为什么不会误伤】
  856. // · 判据只有一件事:触摸通道确实收到了这次手势
  857. // (IsPromotedMouseDuplicatePending —— 与 PROMOTED-DUP 同源、同一处置位),
  858. // 与模态边界 / 代数水位 / extra 指纹全都无关。
  859. // · 摘除范围只限"**owner 窗口**的鼠标类消息",且只在这一个瞬间摘一次。
  860. // · 被摘掉的本来就是**重复**的:这次点击已经由触摸通道的 tap 判定处理完毕
  861. // (否则根本不会走到 ShowModal 这里)。
  862. //
  863. // 【用户的两条边界同时守住】
  864. // · 场景①【从主窗口控件点出弹框 ⇒ 咚 必须消除】:触摸通道收到了手势 ⇒ 副本在
  865. // 队列里 ⇒ 摘掉 ⇒ **无声**。
  866. // · 场景②【弹框已打开后,点弹框外空白区 ⇒ 咚 属正常,用户明确要求不改】:
  867. // 那一处属于被禁用的 owner,它的 WM_TOUCH 在**输入阶段**就被系统丢弃
  868. // ⇒ BeginTouchSlideGesture 不会被调用 ⇒ 标志为假 ⇒ 不摘 ⇒ 那一声"咚"照旧。
  869. //
  870. // 【自限】
  871. // 若某台机器压根不产生提升副本(本项目 Win10 走 WM_POINTER*,fromtouch 消息 0 条),
  872. // 标志恒假 ⇒ 本机制**从不启用** ⇒ 零影响。
  873. // ======================================================================
  874. // 【同源访问器】把"提升副本在途"这一事实暴露给 UIBase.cpp(摘除的时机在那边)。
  875. bool CPaintManagerUI::IsPromotedMouseDuplicatePending()
  876. {
  877. return s_bPromotedMouseDuplicate;
  878. }
  879. // 【Combo 下拉框"点了不出来"】"自上次判定以来,有没有真的投递过一条提升鼠标点击"。
  880. // 一次性读取(读完即清):调用方(CComboWnd::DecideAfterFocusLoss)在"焦点丢失之后
  881. // 延迟一帧"的判定里用它,等价于问"刚才那一下焦点丢失,是不是这次手势的提升副本干的"。
  882. // 为什么必须延迟一帧才问:系统的窗口激活发生在**进入窗口过程之前**,
  883. // 而 KILLFOCUS 正是激活的产物 —— 在 KILLFOCUS 里当场问,副本还没露过面,必然为假。
  884. bool CPaintManagerUI::ConsumePromotedMouseMsgJustSeen()
  885. {
  886. const bool bSeen = s_bPromotedMouseClickJustSeen;
  887. s_bPromotedMouseClickJustSeen = false;
  888. return bSeen;
  889. }
  890. // ======================================================================
  891. // ★【同源访问器】"最近一次点击类输入发生在屏幕上的哪个点"。
  892. //
  893. // 【谁在用、为什么】CComboWnd::DecideAfterFocusLoss 要回答"这一下焦点丢失是不是
  894. // 用户正在点我这个 Combo"。原来它用 `::GetCursorPos()`:
  895. // · 鼠标下正确(鼠标就是光标);
  896. // · 触摸下**错误** —— 系统的触摸提升才会挪光标,而本项目的 Combo 打开/关闭
  897. // 是触摸链**合成**的点击,发生在提升之前 ⇒ 读到的光标是**上一手**的位置。
  898. // 真机日志实证(Win10,60 秒 / 58 次开框):
  899. // `COMBO-INIT begin ... cursor=768,251`,而这一手的触点是 (789,153);
  900. // 768,251 正是**上一次**点在下拉列表里的位置。
  901. // ⇒ 判定按上一手的位置结算 ⇒
  902. // · 想收起下拉框时(点 Combo 自己)判成"不在 Combo 上" ⇒ 不放行 ⇒ 先被
  903. // 失焦关掉、再被同一手的合成点击重新打开(用户看到"点了收不起来");
  904. // · 想选 item 时(点在列表里)反而可能命中上一手的 Combo 位置 ⇒ 误判成
  905. // "打开我那一手的回声" ⇒ 框不收(用户看到"点一下没反应,要点 2 下")。
  906. //
  907. // 【判据一律是状态,无时间戳】
  908. // s_bLastInputWasTouch 由触摸链的公共入口 BeginTouchSlideGesture 置真、
  909. // 由 MessageHandler 收到真鼠标按键消息时置假 ⇒ 是"最近一次输入是谁",不是"多久之前"。
  910. //
  911. // 【自限】从未有过触摸(纯鼠标机器)⇒ 恒走 ::GetCursorPos() ⇒ 与改动前逐字一致。
  912. // ======================================================================
  913. POINT CPaintManagerUI::GetLastInputScreenPoint()
  914. {
  915. if (s_bLastInputWasTouch)
  916. {
  917. // 触摸:用触摸链记录的**真实触点**(屏幕坐标,见 s_ptLastTouchScreen)。
  918. return s_ptLastTouchScreen;
  919. }
  920. POINT pt = { 0 };
  921. ::GetCursorPos(&pt);
  922. return pt;
  923. }
  924. // ★把"本次手势在途的提升鼠标副本"从本线程消息队列里就地摘掉,返回摘掉的条数。
  925. // 调用点:CWindowWnd::ShowModal 进模态循环之前(那里的长注释解释了为什么必须摘)。
  926. //
  927. // ⚠️ 这里**故意不销账**(不调 DisarmPromotedMouseDuplicate):
  928. // 标志继续挂着,PROMOTED-DUP 那道闸门对"稍后才到的提升副本"仍然有效 ——
  929. // 摘除动作只是把"已经排在队列里的那些"提前清掉,不该顺带削弱仍在生效的保护。
  930. // 陈旧标志本身不会误伤:IsPromotedMouseDuplicate() 还要比屏幕坐标(±16px)。
  931. int CPaintManagerUI::DropQueuedPromotedMouseMessages(HWND hWndTarget)
  932. {
  933. if (hWndTarget == NULL || !::IsWindow(hWndTarget)) return 0;
  934. int nDropped = 0;
  935. MSG msg;
  936. // 范围 WM_MOUSEFIRST..WM_MOUSELAST 覆盖 MOVE / 左中右键 DOWN-UP-DBLCLK /
  937. // WHEEL / XBUTTON 全族 —— 提升副本只在其中。
  938. // 只摘"投给该窗口"的(弹框出现之前那次手势的副本,其归属窗口必然是这个 owner:
  939. // 消息的归属在**投递那一刻**才按"光标下的窗口"结算,而那时弹框还不存在)。
  940. while (::PeekMessage(&msg, hWndTarget, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  941. ++nDropped;
  942. return nDropped;
  943. }
  944. // 【悬浮态残留 · 跨窗口参考点】把"本窗口客户区点"记成**屏幕**坐标后,写进
  945. // **线程级**参考点 `s_ptLastTouchScreen`(见文件头那一大段说明:这套状态不能是
  946. // manager 成员,因为补投的 MOVE 会落在另一个 manager 上)。
  947. // 用屏幕坐标的原因:抑制"抬起后悬浮态复活"的 ±8px 判据必须用与窗口无关的坐标系,
  948. // 否则窗口一换(尤其弹框销毁、消息改投主窗口)判据就会失准。
  949. // 调用约定:凡写 `m_ptLastTouchPos` 的**触摸**路径,都应同步调一次本函数。
  950. void CPaintManagerUI::SetLastTouchScreenPoint(POINT ptClient)
  951. {
  952. POINT ptScreen = ptClient;
  953. if (m_hWndPaint != NULL && ::IsWindow(m_hWndPaint))
  954. ::ClientToScreen(m_hWndPaint, &ptScreen);
  955. s_ptLastTouchScreen = ptScreen;
  956. }
  957. namespace
  958. {
  959. const int kScrollBarTouchSlop = 12; // 手指离滚动条 rect 的最大容差(像素)
  960. // Windows 会把"触摸提升(promoted)出来的合成鼠标消息"打上 MOUSEEVENTF_FROMTOUCH
  961. // 标记(位于 GetMessageExtraInfo() 的高位)。
  962. //
  963. // ⚠️ 判定掩码有个坑,别再用文档示例里的 `(extra & 0xFFFFFF80) == 0xFF515700`:
  964. // 真机每一条提升消息的 extra 都是 0xFF515782~0xFF515785,
  965. // 与 0xFFFFFF80 相与得 0xFF515780 ≠ 0xFF515700 ⇒ 那个判定**恒为假**,
  966. // 所有依赖它的逻辑全成哑弹。
  967. // 低 7 位(& 0x7F)是**触摸标识位/光标 ID**,每次手势都变,必须屏蔽掉;
  968. // 高 24 位才是稳定的 MOUSEEVENTF_FROMTOUCH 家族值。
  969. inline bool IsPromotedTouchMouseMessage()
  970. {
  971. return (DWORD)((DWORD_PTR)::GetMessageExtraInfo() & 0xFFFFFF00) == 0xFF515700;
  972. }
  973. // -------------------------------------------------------------------
  974. // [触摸透传 · 根治] 判定 hWnd 是否是"模态弹框背后的背景窗口"。
  975. //
  976. // 与"模态输入链"(弹框 / 弹框 owner)互为反面:那里是"承接模态输入的窗口",
  977. // 这里是"弹框还开着时不该被碰的背景窗口"。
  978. //
  979. // 为什么必须补这道闸(用户实测 bug:点弹框的「选好了」会透传到主窗口):
  980. //
  981. // 本文件顶部(见 s_hModalWindow 那段注释)**早就写明**了要这么做 ——
  982. // 「只要当前有模态弹框,任何【非该弹框】的窗口收到 WM_TOUCH 一律忽略,
  983. // 避免"弹框还开着,手指却把主窗口点动了"的穿透。」
  984. // 但那段注释描述的闸门**从未被实现**(grep s_hModalWindow 只有 set/get,
  985. // 没有任何一处用它做过滤)。这就是透传能发生的原因。
  986. //
  987. // 缺了它之后的真实链路(Win10 触屏):
  988. // 1) 手指点「选好了」→ 系统把 WM_POINTER\* 投给**主窗口**(本机实测:
  989. // 真模态下 owner 被禁用,部分系统会把触摸手势转投给 owner);
  990. // 2) 主窗口的 manager 于是照常走 BeginTouchSlideGesture → TouchUp;
  991. // 3) `TouchUp` 里的"窗口归属 + 命中点"复核**挡不住**它 ——
  992. // 因为主窗口是**另一个 manager**,它的 m_pEventClick 是这次手势新记的
  993. // (记的就是主窗口自己的命中控件),`GetManager() == this` 恒成立;
  994. // 而 `FindControl(pt)` 找的是主窗口自己的控件树,根本不知道
  995. // 屏幕上还盖着一层弹框 ⇒ 复核全过 ⇒ 点击被派发 ⇒ 透传。
  996. // ⇒ 结论:**必须在入口就按"模态会话"过滤,事后的命中点复核无济于事。**
  997. //
  998. // 判定(四条件,全部为"状态"判据、无时间戳):
  999. // (a) 当前确实有活着的模态弹框;
  1000. // (b) 本窗口**不是**那个弹框本身;
  1001. // (c) 本窗口也不是**该弹框的 owner**(owner 同样是背景,被系统禁用,
  1002. // 点它只会咚一声 + 透传,必须一起拦);
  1003. // (d) 本窗口**不是那个弹框正在使用的 manager 窗口**(等价于弹框自己,
  1004. // 必须放行 —— 否则把弹框自己也拦死,弹框彻底点不动)。
  1005. //
  1006. // ⚠️ 为什么 (c) 也要拦:真模态下 owner 被 `EnableWindow(FALSE)` 禁用,
  1007. // 系统会把手势"转投"给它(这正是本机 Win10 的现象)。owner 上的 manager
  1008. // 与主窗口是同一个对象,拦掉它 == 拦掉主窗口,语义正确。
  1009. //
  1010. // ⚠️⚠️ 为什么必须有 (d)(**这是"点选好了仍然透传"的直接原因**)⚠️⚠️
  1011. // 真模态把**同一个 manager**从旧窗口搬到了弹框上(DetachPaintWindow →
  1012. // AttachPaintWindow)。于是既有可能出现"manager->m_hWndPaint == hModal"
  1013. // (正常),也有可能在某些时序下"弹框那个 HWND 收到了消息、但消息里带的
  1014. // 窗口句柄不是 hModal"(例如 `::GetWindow(hModal, GW_OWNER)` 在弹框
  1015. // 正在创建/销毁的瞬间返回了一个**陈旧或意外**的值)。
  1016. // 一旦 (c) 被这种意外情况命中,就会把**弹框自己**判成背景窗口 ⇒
  1017. // 弹框里的点击(比如"选好了")被入口闸吞掉 ⇒ 用户看到"点了没反应",
  1018. // 随后的手势/提升消息又被主窗口接走 ⇒ 表现为**透传到背后的商品卡**。
  1019. // 所以这里必须再补一道"manager 归属"判据做兜底:只要"当前收到消息的
  1020. // 这个 manager"就是弹框自己的 manager,本窗口就绝不是背景窗口。
  1021. //
  1022. // 注意判据的取法:用 `FindManagerByPaintWindow(hWnd)` 这类**按句柄查
  1023. // manager** 的方式,而不是依赖 m_hWndPaint —— 因为闸门可能被非本 manager
  1024. // 的调用路径复用。若查不到对应 manager(hWnd 不是任何被管理的绘制窗口),
  1025. // 则退回 (b)(c) 的字面判定。
  1026. // -------------------------------------------------------------------
  1027. inline bool IsModalBackdropWindow(HWND hWnd)
  1028. {
  1029. if (hWnd == NULL || !::IsWindow(hWnd)) return false;
  1030. HWND hModal = CPaintManagerUI::GetModalWindow();
  1031. if (hModal == NULL || !::IsWindow(hModal)) return false; // (a) 无模态 ⇒ 不是背景
  1032. if (hWnd == hModal) return false; // (b) 它就是弹框 ⇒ 不是背景
  1033. // (d) 本句柄是不是"弹框正在使用的那个 manager 窗口"?
  1034. // 真模态下弹框自己也是被 manager 管理的绘制窗口,因此
  1035. // `FindManagerByPaintWindow(hModal) == FindManagerByPaintWindow(hWnd)`
  1036. // 时二者同属一个 manager ⇒ hWnd 就是弹框窗口(或其别名),
  1037. // 绝不能判成背景 —— 否则连弹框自己的点击都会被这道闸吞掉。
  1038. CPaintManagerUI* pModalMgr = FindManagerByPaintWindow(hModal);
  1039. if (pModalMgr != NULL && FindManagerByPaintWindow(hWnd) == pModalMgr)
  1040. return false;
  1041. if (::GetWindow(hModal, GW_OWNER) == hWnd) return true; // (c) 它是弹框 owner ⇒ 是背景
  1042. return false;
  1043. }
  1044. // 把触点收进滚动条自身 rect:垂直滚动条主要收敛 x(y 原样保留,纵向拖拽量完好)。
  1045. inline POINT Touch_SnapIntoScrollBar(const CControlUI* pBar, POINT pt)
  1046. {
  1047. if (pBar == NULL) return pt;
  1048. RECT rc = pBar->GetPos();
  1049. if (pt.x < rc.left) pt.x = rc.left;
  1050. if (pt.x > rc.right) pt.x = rc.right;
  1051. if (pt.y < rc.top) pt.y = rc.top;
  1052. if (pt.y > rc.bottom) pt.y = rc.bottom;
  1053. return pt;
  1054. }
  1055. // 沿“命中控件 → 祖先链”找最近的、满足容差条件的滚动条滑块;找不到返回 NULL。
  1056. inline CControlUI* Touch_ResolveScrollBarThumb(CControlUI* pStart, POINT pt)
  1057. {
  1058. for (CControlUI* p = pStart; p != NULL; p = p->GetParent())
  1059. {
  1060. if (p->GetInterface(DUI_CTR_SCROLLBAR) != NULL) return NULL; // 本身已是滚动条,无需改判
  1061. CContainerUI* pCont = static_cast<CContainerUI*>(p->GetInterface(DUI_CTR_CONTAINER));
  1062. if (pCont == NULL) continue;
  1063. CScrollBarUI* pBars[2] = { pCont->GetVerticalScrollBar(), pCont->GetHorizontalScrollBar() };
  1064. for (int i = 0; i < 2; ++i)
  1065. {
  1066. if (pBars[i] != NULL && pBars[i]->IsThumbHit(pt, kScrollBarTouchSlop))
  1067. return pBars[i];
  1068. }
  1069. }
  1070. return NULL;
  1071. }
  1072. inline CScrollBarUI* Touch_FindScrollBar(CControlUI* pStart, POINT pt)
  1073. {
  1074. for (CControlUI* p = pStart; p != NULL; p = p->GetParent())
  1075. {
  1076. CContainerUI* pContainer = static_cast<CContainerUI*>(p->GetInterface(DUI_CTR_CONTAINER));
  1077. if (pContainer == NULL) continue;
  1078. CScrollBarUI* bars[2] = {
  1079. pContainer->GetVerticalScrollBar(),
  1080. pContainer->GetHorizontalScrollBar()
  1081. };
  1082. for (int i = 0; i < 2; ++i)
  1083. {
  1084. if (bars[i] == NULL || !bars[i]->IsVisible() || !bars[i]->IsEnabled())
  1085. continue;
  1086. RECT rc = bars[i]->GetPos();
  1087. ::InflateRect(&rc, kScrollBarTouchSlop, kScrollBarTouchSlop);
  1088. if (::PtInRect(&rc, pt)) return bars[i];
  1089. }
  1090. }
  1091. return NULL;
  1092. }
  1093. inline CContainerUI* Touch_FindScrollContainer(CControlUI* pStart)
  1094. {
  1095. for (CControlUI* p = pStart; p != NULL; p = p->GetParent())
  1096. {
  1097. CContainerUI* pContainer = static_cast<CContainerUI*>(p->GetInterface(DUI_CTR_CONTAINER));
  1098. if (pContainer == NULL) continue;
  1099. CScrollBarUI* pVertical = pContainer->GetVerticalScrollBar();
  1100. CScrollBarUI* pHorizontal = pContainer->GetHorizontalScrollBar();
  1101. if ((pVertical != NULL && pVertical->IsVisible() && pVertical->IsEnabled())
  1102. || (pHorizontal != NULL && pHorizontal->IsVisible() && pHorizontal->IsEnabled()))
  1103. return pContainer;
  1104. }
  1105. return NULL;
  1106. }
  1107. }
  1108. // ---------------------------------------------------------------------------
  1109. // 当前模态弹框句柄(由 CWindowWnd::ShowModal 进入/退出时设置)。
  1110. // Win8/10 指针栈下,触摸消息(WM_TOUCH / WM_POINTER)并不总是投递给"视觉上在最前面的弹框":
  1111. // 当弹框的 owner 被 EnableWindow(FALSE) 禁用时,部分系统会把手势转投给 owner。
  1112. // 这里做一道保险:只要当前有模态弹框,任何【非该弹框】的窗口收到 WM_TOUCH 一律忽略,
  1113. // 避免"弹框还开着,手指却把主窗口点动了"的穿透。
  1114. // ---------------------------------------------------------------------------
  1115. static HWND s_hModalWindow = NULL;
  1116. void CPaintManagerUI::SetModalWindow(HWND hWnd)
  1117. {
  1118. s_hModalWindow = hWnd;
  1119. }
  1120. HWND CPaintManagerUI::GetModalWindow()
  1121. {
  1122. return s_hModalWindow;
  1123. }
  1124. void CPaintManagerUI::InitTouchSupport()
  1125. {
  1126. if (m_hWndPaint == NULL || !::IsWindow(m_hWndPaint)) return;
  1127. TouchApi::PFN_RegisterTouchWindow pfnRegister = TouchApi::GetRegisterTouchWindow();
  1128. BOOL bRegistered = FALSE;
  1129. if (pfnRegister != NULL)
  1130. bRegistered = pfnRegister(m_hWndPaint, 0);
  1131. }
  1132. // ===========================================================================
  1133. // [通道无关的滑动状态机] Begin / Update / End
  1134. //
  1135. // 背景(这是本文件里最容易踩坑的一块,先把结论写在前面):
  1136. // "滑动"这件事在本库里的实现只有一份 —— 派发 UIEVENT_TOUCHMOVE,由
  1137. // · CScrollBarUI 消费 → 拖滑块;
  1138. // · 否则冒泡到 CContainerUI → 1:1 跟手平移;
  1139. // · 谁都不认时 → 合成 UIEVENT_SCROLLWHEEL(Δy 累加满 120 一次)。
  1140. // 过去这三个函数体是**内联写在 OnTouchInput(WM_TOUCH 通道)里的**。
  1141. //
  1142. // 问题:Win10 上同一次触摸会在两条互相独立的通道上都产生消息
  1143. // (WM_TOUCH 与 WM_POINTER*),而"谁驱动本次手势"是运行时决定的:
  1144. // · 主窗口常常是 WM_TOUCH 先到 → 老代码能滑;
  1145. // · 弹框 / 被指针抢走的手势 ⇒ 只有 WM_POINTER* →
  1146. // **整段滑动逻辑一条都没执行** ⇒ 「滑不动」;
  1147. // 同时 UP 走指针 → 归一化成 WM_LBUTTONUP → 原生点击路径,
  1148. // 而 tap/drag 判定所需的 m_bTouchMoved 从未被置真 ⇒「滑动反触发点击」。
  1149. //
  1150. // 修法:把滑动逻辑抽成不关心通道的这三个函数,两条通道都调用同一套。
  1151. // 于是"谁驱动手势"不再影响"能不能滑",只影响消息从哪儿来。
  1152. //
  1153. // 状态机的三个相位:
  1154. // Begin : 命中控件 + 找可滚容器 + 记起点/上一包点 + 复位位移标志
  1155. // Update : Δ=(pt - 上一包点) 去重 → 置 m_bTouchMoved → 派发 TOUCHMOVE → 可能合成滚轮
  1156. // End : 派发 TOUCHUP → 返回"是否算轻点"(未越过拖拽阈值)
  1157. //
  1158. // ⚠️ 三条不变量:
  1159. // 1) Begin 必须把 m_bTouchSlideActive 置真;End 必须置假 + 清释放态。
  1160. // 2) Update/End 在 !m_bTouchSlideActive 时必须安全空转(另一条通道可能没走 Begin)。
  1161. // 3) 坐标一律是**客户区坐标**(调用方负责把屏幕坐标转好)。
  1162. // ===========================================================================
  1163. void CPaintManagerUI::BeginTouchSlideGesture(POINT pt)
  1164. {
  1165. m_ptLastTouchPos = pt;
  1166. // 触摸没有"悬浮"语义。新手势开始前先清掉上一次鼠标路径遗留的 HOT 状态,
  1167. // 防止首个触摸 DOWN 恰好发生在合成 WM_MOUSEMOVE 之前。
  1168. ClearTouchHoverState(pt);
  1169. // 先把手势状态复位:即使这一按没命中任何控件,也不能让上一轮的 m_pEventTouch 残留
  1170. // 下去(否则后续 TOUCHMOVE 会发给一个早已松开的手指所对应的控件)。
  1171. m_pEventTouch = NULL;
  1172. m_pTouchScrollContainer = NULL;
  1173. m_bTouchMoved = false;
  1174. m_ptTouchStart = pt;
  1175. m_dwTouchDownTick = ::GetTickCount(); // 供 MessageHandler 做"TOUCHUP 丢失"超时自愈
  1176. // 滑动累加器:nim_duilib 把 TOUCHEVENTF_MOVE 的 Δy 攒够一个 WHEEL_DELTA(120) 就合成
  1177. // WM_MOUSEWHEEL。这里同样复位,避免上一轮手势的余量污染新手势。
  1178. m_nTouchWheelAccum = 0;
  1179. // 本标志是"滑动状态机活着"的唯一判据(End 之前一直为真)。
  1180. m_bTouchSlideActive = true;
  1181. // ★【第二次合成点击 · 根治】触摸通道接手了这次手势 ⇒ 它的提升鼠标副本要作废。
  1182. //
  1183. // 只在这一处置位(连同 EndTouchSlideGesture 里的销账),理由:
  1184. // · WM_TOUCH 与 WM_POINTER* 两条通道**都经由本函数**开始手势 ⇒ 一处即全覆盖;
  1185. // · 由"触摸通道确实收到了手势"来驱动,而不是由"模态边界/代数"来猜 ⇒
  1186. // 对"关闭弹框的那一次手势"同样生效(旧判据唯一漏掉的一类)。
  1187. // · pt 是**本窗口客户区**坐标,提升副本可能落在别的窗口客户区里,
  1188. // 所以这里换算成屏幕坐标存起来,供 MessageHandler 侧比对。
  1189. // 详见文件上方 ArmPromotedMouseDuplicate 那段注释。
  1190. {
  1191. POINT ptScreen = pt;
  1192. ::ClientToScreen(m_hWndPaint, &ptScreen);
  1193. ArmPromotedMouseDuplicate(ptScreen);
  1194. // 同一个触点的**屏幕坐标**副本:抑制"抬起后悬浮态复活"的 ±8px 判据必须用它
  1195. // (客户区坐标一换窗口就不可比,见 s_ptLastTouchScreen 的注释)。
  1196. s_ptLastTouchScreen = ptScreen;
  1197. // 【Combo 下拉框的判据源】两通道的公共入口,一处即全覆盖:
  1198. // 这次输入是触摸 ⇒ 之后 GetLastInputScreenPoint() 一律返回**触摸链的真实触点**,
  1199. // 而不是那个"慢一手"的 GetCursorPos()。见 s_bLastInputWasTouch 的长注释。
  1200. s_bLastInputWasTouch = true;
  1201. }
  1202. CControlUI* pControl = FindControl(pt);
  1203. if (pControl == NULL)
  1204. {
  1205. // 没命中控件也要保持 active:随后的 Update 仍需被安全吸收掉,
  1206. // 由 End 统一收尾(否则 Update 会跑到空指针上)。
  1207. return;
  1208. }
  1209. if (pControl->GetManager() != this)
  1210. {
  1211. return;
  1212. }
  1213. // [触屏] 手指容差改判:直接命中的不是滚动条时,看看是不是"手指离滚动条滑块很近"。
  1214. // 典型场景:列表右侧竖直滚动条仅 16px 宽,用户想拖滑块却按到了旁边的列表项上。
  1215. if (pControl->GetInterface(DUI_CTR_SCROLLBAR) == NULL)
  1216. {
  1217. CControlUI* pBar = Touch_FindScrollBar(pControl, pt);
  1218. if (pBar == NULL)
  1219. pBar = Touch_ResolveScrollBarThumb(pControl, pt);
  1220. if (pBar != NULL)
  1221. {
  1222. pControl = pBar;
  1223. }
  1224. }
  1225. const bool bTouchIsScrollBar = (pControl->GetInterface(DUI_CTR_SCROLLBAR) != NULL);
  1226. // 命中滚动条时把触点收进滚动条 rect(横向按偏也能拖滑块);事件点用收敛后的,
  1227. // 但 m_ptLastTouchPos / m_ptTouchStart 仍记真实坐标(去重与位移判定按真实手指轨迹走)。
  1228. const POINT ptEvent = bTouchIsScrollBar ? Touch_SnapIntoScrollBar(pControl, pt) : pt;
  1229. m_pEventTouch = pControl;
  1230. m_pTouchScrollContainer = bTouchIsScrollBar ? NULL : Touch_FindScrollContainer(pControl);
  1231. if (!bTouchIsScrollBar)
  1232. m_pEventClick = pControl;
  1233. // 触摸没有悬浮语义;整个手势期间以及抬起后的合成鼠标移动都不应重建 HOT。
  1234. s_bSuppressHoverAfterTouch = true;
  1235. {
  1236. // 【诊断 · 新建商品弹框「输入文字消失」】记下"这一手把谁选成焦点目标"。
  1237. // 特别注意 isScrollBar=1 的情形:命中滚动条时**不会**设置 m_pEventClick
  1238. // (见上面那行 if),抬手时的合成点击就没有候选目标 ⇒ 点击被静默丢弃,
  1239. // 输入框永远拿不到焦点。
  1240. CDuiString sName = pControl->GetName();
  1241. DuiLibDiag::Log(_T("TOUCH-DOWN focusTarget=%s/%s isScrollBar=%d pt=%d,%d nFocusBefore=%p"),
  1242. sName.GetData(), pControl->GetClass(), (int)(bTouchIsScrollBar ? 1 : 0),
  1243. pt.x, pt.y, (void*)::GetFocus());
  1244. }
  1245. pControl->SetFocus();
  1246. SetCapture(); // mgr 级:m_bMouseCapture=true + ::SetCapture
  1247. // 滚动条:主动发一次 TOUCHDOWN 让它抓滑块。
  1248. // (TouchDOWN 与鼠标 BUTTONDOWN 在 CScrollBarUI::DoEvent 里等价处理。)
  1249. //
  1250. // ⚠️⚠️ 【这一发 TOUCHDOWN 是"触摸能点击"的必要条件,绝不能删】⚠️⚠️
  1251. //
  1252. // 早先的注释写的是"触摸按下只建立候选点击,不立即发送任何按下事件"——那个策略
  1253. // 在**旧架构**下能活,因为旧架构依赖 Windows 为触摸提升出来的
  1254. // WM_LBUTTONDOWN/UP 去驱动点击(原生路径会自己发 UIEVENT_BUTTONDOWN)。
  1255. //
  1256. // 但现在(通道无关改造之后)触摸链已经把原生鼠标路径**有意让开**:
  1257. // · MessageHandler 的 WM_LBUTTONDOWN 在 m_pEventTouch != NULL 时直接 break;
  1258. // · OnPointerInput 的 DOWN 也不再调 MessageHandler(WM_LBUTTONDOWN)。
  1259. // ⇒ 唯一能告诉控件"用户按下了"的通道就是这一发 TOUCHDOWN。
  1260. //
  1261. // 而控件侧的点击状态机是**按下/抬起配对**的,例如 CButtonUI::DoEvent:
  1262. // UIEVENT_TOUCHDOWN → m_uButtonState |= UISTATE_PUSHED | UISTATE_CAPTURED
  1263. // UIEVENT_TOUCHUP → 清 PUSHED|CAPTURED
  1264. // UIEVENT_BUTTONUP → if ((m_uButtonState & UISTATE_CAPTURED) != 0) { ...; Activate(); }
  1265. // 如果 DOWN 阶段完全不派发,按钮的 CAPTURED 就永远不会置位 ⇒ 抬手时进不了
  1266. // BUTTONUP 分支(或进了也因守卫失败而跳过)⇒ **Activate 根本不被调用**
  1267. // ⇒ 表现为"主窗口触摸点击全灭"。
  1268. //
  1269. // 另外:本函数**只发 TOUCHDOWN,不发 BUTTONDOWN** —— 这是有意为之。
  1270. // 因为整个手势可能演变成拖动(滚动列表),此时不能让控件提前进入"已按下"的业务态;
  1271. // 真正的点击由 UP 阶段依据 tap 判定(EndTouchSlideGesture 的返回值)成对合成
  1272. // BUTTONDOWN/BUTTONUP 来派发。
  1273. // 换句话说:TOUCHDOWN/TOUCHUP 只负责**控件内部视觉与状态记账**,
  1274. // BUTTONDOWN/BUTTONUP 才负责**业务点击**。两者分工明确,不要合并。
  1275. TEventUI event = { 0 };
  1276. event.Type = UIEVENT_TOUCHDOWN;
  1277. event.pSender = pControl;
  1278. event.ptMouse = ptEvent;
  1279. event.dwTimestamp = ::GetTickCount();
  1280. event.wKeyState = MapKeyState();
  1281. pControl->Event(event);
  1282. // ------------------------------------------------------------------
  1283. // ★★【触摸按压态 · 主动冲刷一次绘制】★★
  1284. //
  1285. // 现象(Win7 真机实测):点商品卡时"很多商品没有按压态显示"。
  1286. // 成因**不是**控件没置状态,而是**没机会把它画出来**:
  1287. // · WM_PAINT 是**低优先级**消息 —— 只有消息队列空下来,GetMessage 才会合成它;
  1288. // · 真机上这次手势的 DOWN→UP 只差 0~16ms(同一个时钟滴答)。TOUCHDOWN 这一发
  1289. // 把 pressed 置上并 Invalidate 之后,队列里紧接着就排着 UP,WM_PAINT 一直
  1290. // 轮不上;等 UP 处理完,状态早被复位成 normal 了 ⇒ 画出来的是普通帧。
  1291. // · 反过来,**滑动时按压态反而看得见** —— 因为手指按住不放,队列有空隙,
  1292. // WM_PAINT 合成得出来。这与用户此前"滑动起手就显示按压态"的反馈完全吻合,
  1293. // 也反过来证明"置/复位是配对的、只是没机会绘制"这一判断成立。
  1294. //
  1295. // 修法:TOUCHDOWN 派发完,立刻用 ::UpdateWindow 把已经堆起来的脏区**同步**刷一次。
  1296. // · 与库内既有写法一致:CContainerUI::EndDown / EndRight 就是这么刷的;
  1297. // · ::UpdateWindow 只在"本窗口已有脏区"时才发 WM_PAINT,不制造多余重绘;
  1298. // · 不碰任何状态、不派发任何事件,纯显示层。
  1299. //
  1300. // ⚠️ 副作用(已知并接受):滑动起手那一帧的按压态也会**真的画出来**。
  1301. // 这不是本行引入的新语义 —— 清扫时机是"抬手时才清扫",用户已明确选择过。
  1302. // 若将来要让它不显示,改的是清扫时机,不是这里。
  1303. // ------------------------------------------------------------------
  1304. if (m_hWndPaint != NULL && ::IsWindow(m_hWndPaint))
  1305. {
  1306. ::UpdateWindow(m_hWndPaint);
  1307. }
  1308. }
  1309. void CPaintManagerUI::UpdateTouchSlideGesture(POINT pt)
  1310. {
  1311. // 另一条通道可能没走 Begin(例如 WM_TOUCH 被让路、手势实际由指针驱动);
  1312. // 此时 Update 必须安全空转,绝不能访问 m_pEventTouch。
  1313. if (!m_bTouchSlideActive) return;
  1314. // 与上一包完全相同的点 -> 去重,避免无谓派发(NIM 同款守卫)
  1315. if (m_ptLastTouchPos.x == pt.x && m_ptLastTouchPos.y == pt.y) return;
  1316. // 本次位移增量(相对上一包),随事件下发,滚动容器据此做 1:1 跟手平移
  1317. const LONG dx = pt.x - m_ptLastTouchPos.x;
  1318. const LONG dy = pt.y - m_ptLastTouchPos.y;
  1319. m_ptLastTouchPos = pt;
  1320. // 相对手势起点的累计位移超过阈值 -> 判定为"手指在滑动"(用于松开时抑制点击)。
  1321. const LONG ox = pt.x - m_ptTouchStart.x;
  1322. const LONG oy = pt.y - m_ptTouchStart.y;
  1323. // ------------------------------------------------------------------
  1324. // 滑动判定阈值(单位:像素,按**累计位移**对起点计算)。
  1325. //
  1326. // 这是"轻点 vs 滑动"的**唯一**判据,需求是:
  1327. // 「不管有没有真的滑动任何显示区域,只要手指是在滑动就不要触发点击动作」
  1328. // 即判定只看手指,不看内容有没有动、更不看有没有滚动条。
  1329. //
  1330. // 阈值取 16px 的理由:
  1331. // · 太小(如 8px)会把"用户想点击、但指尖按下去时轻微滚动"误判成滑动
  1332. // ⇒ 该次抬起的点击被抑制 ⇒ 表现为"按钮点不动"。触摸屏上这种抖动很常见。
  1333. // · 太大(如 32px)则"手指明显划了一下却没被判成滑动"⇒ 抬手时误触发点击
  1334. // ⇒ 正是用户报的"滑动却点了按钮"。
  1335. // 16px 在两者之间:正常点击抖动(通常 <10px)不误判,而有意滑动
  1336. // (手指划过屏幕的位移通常数十至数百像素)必然超过。
  1337. //
  1338. // ⚠️ 若要调整,只改这一个常量 —— 两条通道共用本函数,改一处即全局生效。
  1339. //
  1340. // ⚠️⚠️【不要擅自再加"单包位移"判据 —— 已评估后主动放弃】⚠️⚠️
  1341. // 动机看似合理:真机日志里"快速划动"时前两包累计才 11px、
  1342. // 第三包单包突然 55px,若按单包判能提前 ~60ms 判定为滑动。
  1343. // 但必须意识到:`m_bTouchMoved` **不只是**"清扫按压态的时机",
  1344. // 它同时是**"这次手势算不算点击"的唯一判据**(见 EndTouchSlideGesture
  1345. // 的 `bTapLike = !m_bTouchMoved`)。
  1346. // ⇒ 放宽它 = 放宽"点击被误判为滑动"的口径 = 有概率让**正常点击点不动**。
  1347. // 而当前真机日志里 13 次手势中**只有 1 次真实点击**(其余全是有意滑动),
  1348. // **样本不足以评估点击侧风险**。
  1349. // ⇒ 在没有"点击被误判"的直接证据前,绝不动这个判据。
  1350. // (历史教训同源:曾为"理论风险"收窄判据,结果真机主路径直接失效。)
  1351. // 清扫时机已经由"抬手"提前到"越过阈值那一帧"(157ms → ~78ms),
  1352. // 这已解决用户可感知的问题;剩余 ~78ms 是"区分点/滑"的**固有代价**,
  1353. // 不可能再压缩 —— DOWN 那一刻本来就不可能知道用户要干什么。
  1354. static const LONG kTouchDragThresholdPx = 16;
  1355. if (ox > kTouchDragThresholdPx || ox < -kTouchDragThresholdPx
  1356. || oy > kTouchDragThresholdPx || oy < -kTouchDragThresholdPx)
  1357. m_bTouchMoved = true;
  1358. if (m_pEventTouch == NULL) return;
  1359. TEventUI event = { 0 };
  1360. event.Type = UIEVENT_TOUCHMOVE;
  1361. CControlUI* pTouchTarget = m_pTouchScrollContainer != NULL
  1362. ? static_cast<CControlUI*>(m_pTouchScrollContainer) : m_pEventTouch;
  1363. event.pSender = pTouchTarget;
  1364. // 滚动条:触点同样收进滚动条 rect(与 Begin 保持一致,避免首帧跳变)。
  1365. event.ptMouse = (m_pEventTouch->GetInterface(DUI_CTR_SCROLLBAR) != NULL)
  1366. ? Touch_SnapIntoScrollBar(m_pEventTouch, pt) : pt;
  1367. event.dwTimestamp = ::GetTickCount();
  1368. event.wKeyState = MapKeyState();
  1369. event.wParam = (WPARAM)(int)dx;
  1370. event.lParam = (LPARAM)(int)dy;
  1371. pTouchTarget->Event(event);
  1372. // ------------------------------------------------------------------
  1373. // [对标 nim_duilib] 竖向滑动 → 合成 WM_MOUSEWHEEL。
  1374. //
  1375. // 为什么需要它:真实鼠标"滚动"靠 WM_MOUSEWHEEL 驱动,而触摸只有位移增量。
  1376. // 只处理 TOUCHMOVE 的容器虽然能 1:1 跟手平移,但那些只认滚轮的控件
  1377. // (如挂在窗口上的通用滚动、以及部分不认 TOUCHMOVE 的自定义控件)
  1378. // 在触摸下永远滚不动 —— Win7 之所以"感觉正常",是因为它走的是"把触摸提升成
  1379. // 鼠标"的老栈,系统会自己补 WM_MOUSEWHEEL;Win10 走指针/触摸栈就不会补了。
  1380. //
  1381. // 因此这里补齐:把 Δy 累加,每满一个 WHEEL_DELTA(120) 就投一次 SCROLLWHEEL。
  1382. // 符号按 Windows 惯例取反:手指下滑(Δy>0,内容下移)→ 负增量。
  1383. //
  1384. // 只在没有 1:1 跟手平移(即没有可滚容器接管)时才合成,避免"内容被平移一次、
  1385. // 又被滚轮滚一次"的双倍滚动。命中滚动条时不合成(滑块本身有自己的拖拽语义)。
  1386. // ------------------------------------------------------------------
  1387. if (m_pTouchScrollContainer == NULL
  1388. && m_pEventTouch->GetInterface(DUI_CTR_SCROLLBAR) == NULL)
  1389. {
  1390. if (dy != 0) m_nTouchWheelAccum -= dy;
  1391. while (m_nTouchWheelAccum >= 120 || m_nTouchWheelAccum <= -120)
  1392. {
  1393. const int nNotches = m_nTouchWheelAccum / 120;
  1394. m_nTouchWheelAccum -= nNotches * 120;
  1395. const int zDelta = nNotches * 120;
  1396. CControlUI* pWheel = (m_pEventTouch != NULL) ? m_pEventTouch : FindControl(pt);
  1397. if (pWheel == NULL) break;
  1398. TEventUI evWheel = { 0 };
  1399. evWheel.Type = UIEVENT_SCROLLWHEEL;
  1400. evWheel.pSender = pWheel;
  1401. evWheel.wParam = MAKEWPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, zDelta);
  1402. evWheel.lParam = 0;
  1403. evWheel.ptMouse = pt;
  1404. evWheel.wKeyState = MapKeyState();
  1405. evWheel.dwTimestamp = ::GetTickCount();
  1406. pWheel->Event(evWheel);
  1407. }
  1408. }
  1409. }
  1410. bool CPaintManagerUI::EndTouchSlideGesture(POINT pt)
  1411. {
  1412. if (!m_bTouchSlideActive) return false;
  1413. m_bTouchSlideActive = false;
  1414. // ⚠️⚠️ 【m_pEventTouch 为空时必须直接判"不算轻点",且必须在这里就返回】⚠️⚠️
  1415. //
  1416. // 这里曾经是"先打完 SLIDE-END 日志、再在下面才 return false",看起来等价,
  1417. // 实际上踩过一个真实死锁:只要 m_pEventTouch 被别处(曾经的"状态交叉"纠偏)
  1418. // 提前清成 NULL,本函数就会带着 m_bTouchSlideActive 已置假、但对外仍报
  1419. // "这是一次滑动"的结论返回 —— 调用方于是走 `!bTapLike` 的"consumed as slide"
  1420. // 分支,把点击**静默吞掉**,同时也不会把手势交还给原生鼠标路径。
  1421. // 结果:点击完全失灵(真机日志:`SLIDE-END touch=null moved=0` 紧跟
  1422. // `POINTER-MSG UP consumed as slide (no click)`,每一个按钮都点不动)。
  1423. //
  1424. // 因此把这条早退路提到最前面:没有命中控件 ⇒ 语义上"没点到东西",
  1425. // 既不是滑动也不是点击,直接给出明确结论,绝不拖到后面再决策。
  1426. if (m_pEventTouch == NULL)
  1427. {
  1428. m_ptLastTouchPos = pt;
  1429. SetLastTouchScreenPoint(pt);
  1430. m_pTouchScrollContainer = NULL;
  1431. m_bTouchMoved = false;
  1432. m_nTouchWheelAccum = 0;
  1433. s_bSuppressHoverAfterTouch = true;
  1434. m_bMouseTracking = false;
  1435. // [NIM 风格] 这里不需要"解除让路"——让路已改由 m_pEventTouch 这个**标记**表达。
  1436. // ⚠️ 可变参数必须在 _T 宏的括号**之外**:_T 是单参数宏,
  1437. // 若把格式化参数一起写进它的括号里,会触发 C4002「类函数宏的调用参数过多」。
  1438. return false;
  1439. }
  1440. m_ptLastTouchPos = pt;
  1441. SetLastTouchScreenPoint(pt);
  1442. // 注:`m_pEventTouch == NULL` 的早退路已提到本函数最开头(见上),
  1443. // 到这里 m_pEventTouch 必然非空,可以安全解引用。
  1444. ClearTouchHoverState(pt);
  1445. // ⚠️⚠️ 【顺序是死线:先派发 TOUCHUP,再 ReleaseCapture】⚠️⚠️
  1446. //
  1447. // CPaintManagerUI::ReleaseCapture() 不只是调 Win32 那句 ::ReleaseCapture(),
  1448. // 它同时把 m_bMouseCapture 置假、并把 m_bDragMode 置假(见本函数定义处)。
  1449. // 而 CControlUI::Activate()(CButtonUI::Activate 的第一步就是调它)里有捕获保护:
  1450. // if (!m_pManager->IsCaptured() && !(m_uButtonState & UISTATE_CAPTURED)) return false;
  1451. // (IsCaptured() 返回的就是 m_bMouseCapture)
  1452. //
  1453. // 于是原来的「先 ReleaseCapture 再 TOUCHUP」会出现这样的连锁:
  1454. // · Begin 时只发了 UIEVENT_TOUCHDOWN,没给按钮发 BUTTONDOWN
  1455. // ⇒ 按钮的 m_uButtonState 里从来没有 UISTATE_CAPTURED;
  1456. // · End 时先 ReleaseCapture ⇒ m_bMouseCapture 已假 ⇒ 随后调用方合成
  1457. // UIEVENT_BUTTONUP、按钮的 `if ((m_uButtonState & UISTATE_CAPTURED) != 0)`
  1458. // 分支因没有 CAPTURED 而不进 ⇒ Activate() 根本不会被调用;
  1459. // · 即便被调用,CControlUI::Activate 的捕获保护也会因为两个条件都为假而 return false。
  1460. // ⇒ **按钮的 click 通知永远发不出来**(按下有高亮、抬手没反应)。
  1461. //
  1462. // 把 ReleaseCapture 挪到 TOUCHUP 之后:按钮在收到 TOUCHUP 时仍处于"管理器认为有捕获"
  1463. // 的状态;等控件侧处理完再由这里收尾释放,语义上也更正确(手势真正结束了)。
  1464. //
  1465. // 注意:这里移的是 **TOUCHUP 与 ReleaseCapture 的相对顺序**,
  1466. // 不能把 ReleaseCapture 整个删掉(否则 m_bMouseCapture 与 Win32 捕获都会泄漏)。
  1467. TEventUI event = { 0 };
  1468. event.Type = UIEVENT_TOUCHUP;
  1469. event.pSender = m_pEventTouch;
  1470. // 与 Begin/Update 一致:滚动条用收敛点,保证 ptMouse 轨迹连续、位移计算不失真。
  1471. event.ptMouse = (m_pEventTouch->GetInterface(DUI_CTR_SCROLLBAR) != NULL)
  1472. ? Touch_SnapIntoScrollBar(m_pEventTouch, pt) : pt;
  1473. event.dwTimestamp = ::GetTickCount();
  1474. event.wKeyState = MapKeyState();
  1475. m_pEventTouch->Event(event);
  1476. // TOUCHUP 已派发完毕 ⇒ 现在才释放捕获(手势真正结束)。
  1477. ReleaseCapture();
  1478. // [NIM 风格] 让路无需任何"时间戳清理" —— 它现在由 m_pEventTouch 这个标记表达,
  1479. // 下面的 `m_pEventTouch = NULL` 就是"本次 WM_TOUCH 手势结束"的全部收尾动作。
  1480. //
  1481. // 历史教训(保留备查,勿再引入同类写法):
  1482. // 曾经用一个"让路时间戳"同时表示"让路中"和"指针手势计时",
  1483. // 导致 (GetTickCount() - 该值) < 3000 恒成立 ⇒ 指针通道自己驱动的手势被自己判定成
  1484. // "让路中" ⇒ UP 走进"只清状态、不合成点击"的早退路 ⇒ 两条点击路径同时断掉。
  1485. // 改用标记后,判据是"m_pEventTouch 是否非空",与"WM_TOUCH 是否真的接管了手势"
  1486. // 严格一致,不存在跨手势残留,也不需要 3 秒超时兜底。
  1487. // 关键:手指抬起后禁止"悬浮态复活"。
  1488. // Windows 会为触摸补发合成的 WM_MOUSEMOVE;且真实 WM_MOUSELEAVE 在 m_bMouseTracking
  1489. // 为真时会自己给自己重发 WM_MOUSEMOVE(见 WM_MOUSELEAVE 分支)→ 刚清掉的悬浮态立刻
  1490. // 被重新点亮。这里置抑制位 + 主动撤下鼠标跟踪,直到用户真的移动鼠标才恢复。
  1491. s_bSuppressHoverAfterTouch = true;
  1492. m_bMouseTracking = false;
  1493. // ------------------------------------------------------------------
  1494. // ★【滑动起手的按压态】手指"划着走"时,按下瞬间命中的那个控件不能留按压态。
  1495. //
  1496. // 现象(用户实测):手指触屏滑动,起手碰到的控件虽然不会触发点击,
  1497. // 但会留下按压态背景(滑完才被别的东西擦掉,或一直留着)。
  1498. //
  1499. // 成因:BeginTouchSlideGesture 在 DOWN 时**无条件**派发 UIEVENT_TOUCHDOWN,
  1500. // 控件(如 CButtonUI::DoEvent)据此置 UISTATE_PUSHED|UISTATE_CAPTURED 并
  1501. // Invalidate ⇒ 手指还没滑出控件之前,按压态已经画出来了。
  1502. // 而 UP 时这里派发的 UIEVENT_TOUCHUP 只清"抬手点所在控件"的状态:
  1503. // · CButtonUI 的 TOUCHUP 分支虽然清 PUSHED|CAPTURED,但它**不判 PtInRect**,
  1504. // 看似能清掉 —— 问题在于它只发给 m_pEventTouch(起手命中的控件),
  1505. // 而滚动场景下 UpdateTouchSlideGesture 把 TOUCHMOVE 改发给了
  1506. // m_pTouchScrollContainer,TOUCHUP 与 TOUCHMOVE 的收件人不一致,
  1507. // 一旦两个标记不指向同一对象,起手控件就**收不到 TOUCHUP**
  1508. // ⇒ PUSHED|CAPTURED 永久残留 ⇒ 按压态背景不消失。
  1509. //
  1510. // 修法:判定为滑动时,把起手控件(以及滚动容器)的按压视觉清扫掉,
  1511. // 走 ClearPushedStateAt 的窄路径(只清视觉、不发通知)。
  1512. //
  1513. // ⚠️ 顺序是死线:必须在 TOUCHUP 派发**之前**清。
  1514. // `ClearPushedStateAt` 会清 CButtonUI 的 UISTATE_CAPTURED,而那正是
  1515. // `UIEVENT_BUTTONUP` 分支的守卫(`if ((m_uButtonState & UISTATE_CAPTURED) != 0)`)。
  1516. // 放在 TOUCHUP 之后清,会连带把"轻点合成点击"必需的 CAPTURED 一起清掉
  1517. // ⇒ 按钮 Activate 不触发。但本分支只在 m_bTouchMoved(已判为滑动、不会合成点击)
  1518. // 时才进入,所以是安全的。
  1519. //
  1520. // ⚠️ 必须在下面 `m_pEventTouch = NULL` **之前**调用 —— 要用到起手控件。
  1521. // ------------------------------------------------------------------
  1522. if (m_bTouchMoved)
  1523. {
  1524. CControlUI* pSlideOrigin = m_pEventTouch;
  1525. CControlUI* pSlideScroll = m_pTouchScrollContainer;
  1526. ClearPushedStateAt(pSlideOrigin, pt);
  1527. if (pSlideScroll != NULL && pSlideScroll != pSlideOrigin)
  1528. ClearPushedStateAt(pSlideScroll, pt);
  1529. }
  1530. // ⚠️⚠️ 【必须在返回之前清掉 m_pEventTouch】—— 这是"主窗口触摸点击全灭"的元凶之一。⚠️⚠️
  1531. //
  1532. // 死锁链条(每一步都真实存在):
  1533. // 1) 本函数被调用时 m_pEventTouch 已经不再需要 —— TOUCHUP 已派发、捕获已释放、
  1534. // 悬浮态已清。它的语义是"本次触摸进行中命中的控件",手势结束就该失效。
  1535. // 2) 但 `WM_LBUTTONUP` 的原生分支开头是:
  1536. // if (m_pEventTouch != NULL || m_bSuppressPromotedTouchMouse) { ...; break; }
  1537. // 这个 break **把 ReleaseCapture() 一起跳过了**。
  1538. // 3) 于是只要 m_pEventTouch 残留非 NULL,系统随后提升出来的那条 WM_LBUTTONUP
  1539. // 就会"只清抑制位、不释放捕获"地溜过去 ⇒ 窗口持有 capture 不放。
  1540. // 4) 持有 capture 期间,鼠标/指针消息被强制路由到本窗口,**别处一律点不动**;
  1541. // 且 m_bSuppressPromotedTouchMouse 被反复清成 0,WM_LBUTTONDOWN 的守卫
  1542. // `if (m_pEventTouch != NULL ...) break;` 又继续拦 → 本窗口也点不动。
  1543. // ⇒ 整个应用触摸点击全灭,且不会自愈(capture 没有超时机制)。
  1544. //
  1545. // 注意这与"轻点分支里也清了 m_pEventTouch"不冲突:那条路走的是"已合成点击",
  1546. // 这里是手势收尾的公共清理。**两条路径都必须清**,缺一条就留下上面那个死锁。
  1547. //
  1548. // 清理顺序要求:必须在下面读 m_pEventClick 的 tap 判定**之前**完成 ——
  1549. // Begin 里给滚动条命中的分支会特意不设 m_pEventClick(滚动条不做点击),
  1550. // 所以 bTapLike 的计算只依赖 m_pEventTouch 的 rect 语义已落地(TOUCHUP 已派发),
  1551. // 与本指针无关;但为便于阅读,统一挪到 tap 判定之前一次清干净。
  1552. m_pEventTouch = NULL;
  1553. // 是否按"点击"处理。默认要求本次手势没有位移,但触摸屏上手指按下时的轻微抖动
  1554. // 超过 8px 阈值非常常见(弹框里的小按钮尤其如此)——一旦判成拖拽,这里不合成点击,
  1555. // 而提升的 WM_LBUTTONDOWN 早已在 DOWN 阶段被拦掉,于是两条点击路径同时断掉,
  1556. // 表现为"弹框里怎么点都没反应"。
  1557. // 因此补一条与鼠标语义一致的判定:位移虽大,但抬起时手指仍落在【按下时命中的同一个
  1558. // 控件】上,且该控件不在可滚动容器内(即这次位移不可能是"滚动"),同样按点击处理。
  1559. //
  1560. // ⚠️ 这里的 pt **必须**与 Begin 用同一个收敛规则,否则命中判定会失真:
  1561. // 命中滚动条时 Begin 把事件点收进滚动条 rect(Touch_SnapIntoScrollBar)。
  1562. // 如果本函数拿原始 pt 去 FindControl,一根在滚动条上但横向偏出几像素的手指
  1563. // ------------------------------------------------------------------
  1564. // tap / drag 判定:【唯一判据是"手指有没有真的滑动"】
  1565. //
  1566. // 需求原文:「不管有没有真的滑动任何显示区域,只要手指是在滑动就不要触发点击动作」。
  1567. // 即:判定只看向**手指本身**,不看向"内容有没有动"。
  1568. // · 手指位移越过 8px 阈值 ⇒ 一律算滑动 ⇒ 绝不触发点击
  1569. // · 位移在阈值内 ⇒ 算轻点 ⇒ 触发点击
  1570. // 这个语义与"有没有可滚动的对象"完全无关 —— 哪怕按在没有任何滚动条的空白区、
  1571. // 内容纹丝不动,只要手指划出去了,就不该在抬手时变成一次点击。
  1572. //
  1573. // ⚠️⚠️ 历史教训:这里曾经有一条"同控件豁免" ——
  1574. // if (!bTapLike && m_pTouchScrollContainer == NULL && ... ) {
  1575. // if (FindControl(ptTap) == m_pEventClick) bTapLike = true; // 误判!
  1576. // }
  1577. // 它的本意是"抬手指时还落在同一个控件上、且该控件不可滚,那这次位移不可能
  1578. // 是滚动,用户只是按得抖了一点,就当点击处理",用来救"按钮点不动"。
  1579. // 但它**恰好违背了上面的需求**:在无可滚区域里滑动时,手指从按下到抬起往往
  1580. // 仍落在同一控件内 ⇒ 被判成轻点 ⇒ 滑动过程中触发了点击(用户实测到的问题)。
  1581. // 而当初真正要救的"按钮点不动",根因另有其物(释放捕获时序 + 状态被误清),
  1582. // 已在本文件其它位置修复,不需要靠牺牲滑动语义来兜底。
  1583. // 因此本条豁免**整段删除**,判定回归单一的 m_bTouchMoved。
  1584. //
  1585. // 说明:ptTap 仍保留用于日志/后续扩展;此处不再参与 tap 判定。
  1586. const POINT ptTap = (m_pEventTouch != NULL
  1587. && m_pEventTouch->GetInterface(DUI_CTR_SCROLLBAR) != NULL)
  1588. ? Touch_SnapIntoScrollBar(m_pEventTouch, pt) : pt;
  1589. (void)ptTap;
  1590. const bool bTapLike = !m_bTouchMoved;
  1591. // 清空滚轮累加余量,避免串到下一次手势造成"一按就滚"。
  1592. m_nTouchWheelAccum = 0;
  1593. // 返回值 = "本次手势算轻点"。调用方据此决定是否派发点击。
  1594. return (m_pEventClick != NULL && bTapLike
  1595. && m_pEventClick->GetInterface(DUI_CTR_SCROLLBAR) == NULL);
  1596. }
  1597. void CPaintManagerUI::OnTouchInput(WPARAM wParam, LPARAM lParam)
  1598. {
  1599. // 触屏模型(参考 NIM Duilib 的 Window::HandleMessage case WM_TOUCH,但**不可**照搬它的鼠标守卫,
  1600. // 旧版 DuiLib 的点击状态机强依赖原生 WM_LBUTTONDOWN/UP,照搬会让点击全灭——已实测踩过):
  1601. // 1) 独立的 m_pEventTouch 追踪"本次触摸命中控件",DOWN 设定、UP 清空;绝不复用 m_pEventClick。
  1602. // 2) 只向控件派发“原生触摸事件” UIEVENT_TOUCHDOWN / UIEVENT_TOUCHMOVE / UIEVENT_TOUCHUP:
  1603. // · CContainerUI 认 TOUCHMOVE → 内容 1:1 跟手平移(对标 NIM ScrollableBox);
  1604. // · CScrollBarUI 认 TOUCHDOWN/MOVE/UP → 拖滑块 / 点轨道翻页(不依赖合成鼠标移动);
  1605. // · 其余控件忽略触摸事件(未认领的会沿 DoEvent 冒泡给父容器)。
  1606. // 3) 按钮"点击"由本通道的 TOUCHUP 分支依据 EndTouchSlideGesture 的 tap 判定合成
  1607. // (位移未越阈值才算轻点)—— 见下方 for 循环里的 UP 分支。
  1608. // ⚠️ 历史注记:更早的版本依赖"Windows 为触摸自动提升的 WM_LBUTTONDOWN/UP"
  1609. // 去驱动点击,但那条路会把**拖动**也当成点击,且指针通道抢走手势时完全失效。
  1610. // 现已统一由 tap 判定派发,两条通道行为一致。
  1611. // 4) 不做任何"触摸→鼠标"归一化、不做 NIM 那种 m_pEventTouch!=NULL 通用守卫
  1612. // (旧版 DuiLib 的点击状态机强依赖原生 WM_LBUTTONDOWN/UP,照搬守卫曾让点击全灭);
  1613. // "轻点 vs 拖拽"只用 m_bTouchMoved 在 UP 处抑制误点。
  1614. // 5) 触摸**不参与悬浮态**:WM_MOUSEMOVE 里用 MOUSEEVENTF_FROMTOUCH 标记把"提升出来的鼠标消息"
  1615. // 挡在悬浮 enter/leave 之外(触摸没有"光标停留"语义)——这是"点过的控件一直高亮 /
  1616. // 多个控件同时高亮"的根治手段;此处再叠加 s_bSuppressHoverAfterTouch 抑制抬起后的复活。
  1617. TouchApi::PFN_GetTouchInputInfo pfnGetInfo = TouchApi::GetGetTouchInputInfo();
  1618. // 【已移除】"把 WM_TOUCH 同步转发给模态弹框"的兜底块。
  1619. //
  1620. // 历史背景:假模态时期,系统会把 WM_TOUCH 投给 owner(被禁用的主窗口)而非弹框,
  1621. // 于是这里加了一段"发现弹框存在就 SendMessage 转发过去"的补救。
  1622. //
  1623. // 为什么现在必须删掉:
  1624. // 1. ShowModal 已改为真模态(DialogBoxIndirectParam,参考 nim_duilib)。系统对话框管理器
  1625. // 自己就是触摸目标窗口,弹框直接收到 WM_TOUCH,不需要任何转发 —— 这段代码永远不会
  1626. // 再被触发(owner 已被系统禁用,收不到消息)。
  1627. // 2. 就算被触发也是错的:MSDN 明确 WM_TOUCH 的 lParam(HTOUCHINPUT) 经 SendMessage
  1628. // 转发后立即失效,两边只能有一方解析并 CloseTouchInputHandle,极易造成句柄泄漏或
  1629. // 双重关闭;且真模态期间 m_hWndPaint 属于 owner 的情况下,转发会把 owner 的触摸
  1630. // 塞给弹框,坐标语义错位。
  1631. // 3. 它依赖 s_hModalWindow 这个假模态时代的全局状态,与新架构的 CPaintManagerUI
  1632. // 迁移方案(DetachPaintWindow/AttachPaintWindow)职责重叠、互相干扰。
  1633. //
  1634. // 因此整段删除:触摸一律由"收到消息的那个窗口自己的 manager"处理,链路单一清晰。
  1635. if (pfnGetInfo == NULL) return;
  1636. // 本次手势确认系统走的是 WM_TOUCH 通道 ⇒ 【本次手势内】让指针通道让路。
  1637. // ⚠️ 注意这里是"手势级让路",不是"永久关闭指针通道"。
  1638. // 永久关闭会害死真模态弹框:本台收银机 WM_TOUCH 的贪婪归属权卡在主窗口,
  1639. // 弹框永远收不到 WM_TOUCH;一旦指针通道被永久关掉,弹框就彻底没有输入源。
  1640. // 所以让路只标记"直到本次手势结束"(由 UP / 3 秒超时自动解禁)。
  1641. //
  1642. // 另外,若本窗口的本次手势**已经**由指针通道驱动(m_bPointerGestureActive),
  1643. // 说明这是同一次触摸的另一条通道送来的一份重复消息 —— 整条忽略,绝不能双份驱动。
  1644. if (m_bPointerGestureActive)
  1645. {
  1646. return;
  1647. }
  1648. // ------------------------------------------------------------------
  1649. // ★★【模态背闸】弹框还开着时,背景窗口的 WM_TOUCH 一律忽略。
  1650. //
  1651. // 这正是本文件 s_hModalWindow 那段注释所承诺、却一直没实现的闸门:
  1652. // 「只要当前有模态弹框,任何【非该弹框】的窗口收到 WM_TOUCH 一律忽略,
  1653. // 避免"弹框还开着,手指却把主窗口点动了"的穿透。」
  1654. //
  1655. // 为什么 WM_TOUCH 通道尤其需要它:本台收银机 WM_TOUCH 的**贪婪归属权**
  1656. // 卡在主窗口(MSDN:收到第一条触摸消息后,所有触摸消息都发给该窗口,
  1657. // 直到另一个窗口获得焦点)。弹框是被程序 SetFocus 出来的、而非触摸点出来的,
  1658. // 所以主窗口可能**持续**收到本该属于弹框的 WM_TOUCH —— 不在这里拦,
  1659. // 主窗口就会替弹框把点击"代劳"掉(用户看到的透传)。
  1660. //
  1661. // 注意 WM_TOUCH 没有"必须放行的 UP"问题:它的手势状态由 m_pEventTouch /
  1662. // m_bTouchSlideActive 表达,且上面的 `m_bPointerGestureActive` 检查
  1663. // 与本闸互不干扰;整条 return 是安全的(不会有标记悬空)。
  1664. // 唯一要注意的是把可能残留的滑动状态收干净。
  1665. // ------------------------------------------------------------------
  1666. if (IsModalBackdropWindow(m_hWndPaint))
  1667. {
  1668. // 顺手清掉可能残留的滑动/候选点击(上一次手势若被异常中断)。
  1669. // 不派发 TOUCHUP、不派发点击 —— 背景窗口此刻不该有任何交互反应。
  1670. m_bTouchSlideActive = false;
  1671. m_pTouchScrollContainer = NULL;
  1672. m_bTouchMoved = false;
  1673. m_pEventClick = NULL;
  1674. return;
  1675. }
  1676. // 注意:让路时间戳**不在这里**打 —— 必须等确认这是一条有效的手势消息之后再打。
  1677. // 曾经在函数入口就打,结果 `cInputs == 0` / GetTouchInputInfo 失败这类"空消息"
  1678. // 也会把指针通道压住 3 秒(没有任何手势在进行,却拒绝了指针)—— 白白制造"顿一下"。
  1679. // 标记触摸输入句柄是否已在“点击候选”分支里提前关闭(避免函数末尾重复关闭)。
  1680. bool bTouchInputClosed = false;
  1681. UINT cInputs = LOWORD(wParam);
  1682. if (cInputs == 0)
  1683. {
  1684. return;
  1685. }
  1686. std::vector<TouchApi::TOUCHINPUT> inputs(cInputs);
  1687. if (!pfnGetInfo((HANDLE)lParam, cInputs, inputs.data(), (int)sizeof(TouchApi::TOUCHINPUT)))
  1688. {
  1689. return;
  1690. }
  1691. // 到这里确认:这是一条**有效**的 WM_TOUCH(能取到触摸点)⇒ 正式开始本次手势。
  1692. //
  1693. // [NIM 风格] 这里**不再**写任何"让路时间戳"。
  1694. // 让路由下面的 DOWN 分支里 m_pEventTouch != NULL 这个**标记**表达:
  1695. // BeginTouchSlideGesture 会置 m_pEventTouch,指针通道看到它非空就退让。
  1696. // 标记的生命周期与"WM_TOUCH 是否真的接管了本次手势"严格一致 ——
  1697. // 这比时间戳可靠(时间戳会因为"指针通道自己也写它"而恒真,已踩过)。
  1698. for (UINT i = 0; i < cInputs; ++i)
  1699. {
  1700. TouchApi::TOUCHINPUT& ti = inputs[i];
  1701. POINT pt;
  1702. pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
  1703. pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
  1704. ::ScreenToClient(m_hWndPaint, &pt);
  1705. if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_DOWN)
  1706. {
  1707. // 这里【不再】用 `if (m_pEventClick != NULL) break;` 做通用守卫:Windows 会在 WM_TOUCH
  1708. // 前后补发合成的 WM_LBUTTONDOWN(同样设置 m_pEventClick),通用守卫会让 m_pEventTouch
  1709. // 永不设置 → 容器收不到 TOUCHMOVE,列表滚不动。
  1710. //
  1711. // 滚动条也不再“交回原生鼠标”:实测部分触摸收银机在手指拖拽期间【不补发合成的
  1712. // WM_MOUSEMOVE】,导致滑块拖不动。现在改为由 WM_TOUCH 直接驱动——CScrollBarUI 已把
  1713. // TOUCHDOWN/MOVE/UP 与鼠标事件等价处理,这里让滚动条走常规接管流程,
  1714. // 后续 TOUCHMOVE 由它消费(不会冒泡到容器把内容滚走)。
  1715. ::SetFocus(m_hWndPaint);
  1716. // [通道无关] 滑动状态机的建立逻辑已抽到 BeginTouchSlideGesture,
  1717. // 指针通道(OnPointerInput)也调用同一个函数,保证两条通道滑动行为一致。
  1718. BeginTouchSlideGesture(pt);
  1719. }
  1720. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_MOVE)
  1721. {
  1722. // 【不要】在这里对滚动条让路。滚动条现在完全由触摸事件驱动:Begin 已把 m_pEventTouch
  1723. // 设为"滚动条自身"(不再交回原生鼠标),CScrollBarUI 也已把 TOUCHDOWN/MOVE/UP 与鼠标
  1724. // 事件等价处理。若此处仍 `m_pEventClick->GetInterface("ScrollBar") != NULL` 就 break,
  1725. // TOUCHMOVE 永远到不了滚动条 → 滑块拖不动(历史症状)。滚动条收到 TOUCHMOVE 会自行消费
  1726. // (CScrollBarUI::DoEvent 命中已捕获分支后 return true),不会冒泡到容器把内容滚走。
  1727. //
  1728. // [通道无关] 去重 / Δ 计算 / 派发 TOUCHMOVE / 合成滚轮 已全部抽到
  1729. // UpdateTouchSlideGesture,指针通道也调用同一个函数。
  1730. UpdateTouchSlideGesture(pt);
  1731. }
  1732. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_UP)
  1733. {
  1734. // [通道无关] 收尾逻辑(派发 TOUCHUP、清悬浮态、让路解禁、tap 判定)已抽到
  1735. // EndTouchSlideGesture;指针通道也调用同一个函数。
  1736. //
  1737. // 返回值 = "本次手势算一次轻点"(未越过拖拽阈值,或抬起时仍落在同一控件上)。
  1738. const bool bTapLike = EndTouchSlideGesture(pt);
  1739. // [语义] 点击与否**只由手指是否滑动决定**(见 EndTouchSlideGesture 的说明)。
  1740. // 这里不再有"无可滑动对象就强行当点击"的兜底 —— 那条兜底会让
  1741. // "在没有滚动条的区域滑动"错误地触发点击。
  1742. const bool bTapLikeFinal = bTapLike;
  1743. // ------------------------------------------------------------------
  1744. // [顺序修复] 这里**不再合成** UIEVENT_BUTTONDOWN / UIEVENT_BUTTONUP。
  1745. //
  1746. // 交给 TouchUp() 做两件事:
  1747. // 1) 轻点时先把"本次按下的视觉态"收干净(按压态不该被带进业务回调);
  1748. // 2) 放行**配对的那条原生 WM_LBUTTONDOWN / WM_LBUTTONUP**,让触摸与
  1749. // 鼠标走同一条代码路径、同一个顺序。
  1750. //
  1751. // 旧写法的问题:合成的 BUTTONDOWN 与 BUTTONUP 之间夹着业务回调
  1752. // (SendNotify(CLICK) → ShowModal()),于是弹框弹出时控件还顶着按下态。
  1753. // 完整因果见 UIManager.h 里 TouchUp 的注释。
  1754. // ------------------------------------------------------------------
  1755. TouchUp(pt, bTapLikeFinal);
  1756. }
  1757. }
  1758. // 收尾:若上面“点击候选”分支已经把句柄消费掉了(bTouchInputClosed),这里不能再关一次。
  1759. TouchApi::PFN_CloseTouchInputHandle pfnClose = TouchApi::GetCloseTouchInputHandle();
  1760. if (!bTouchInputClosed && pfnClose != NULL)
  1761. pfnClose((HANDLE)lParam);
  1762. }
  1763. // ---------------------------------------------------------------------------
  1764. // WM_POINTER* 处理 —— Win8+ 的另一条触摸/笔输入通道。
  1765. //
  1766. // 参考 nim_duilib NativeWindow_Windows::OnPointerMsgs()。
  1767. //
  1768. // 策略与 nim_duilib 一致:**归一化成鼠标消息**,直接喂给现有的鼠标处理链,
  1769. // 从而不必维护"原生鼠标 / 触摸提升鼠标 / 指针"三套并行的点击状态机。
  1770. // 具体:
  1771. // WM_POINTERDOWN → WM_LBUTTONDOWN
  1772. // WM_POINTERUPDATE → WM_MOUSEMOVE
  1773. // WM_POINTERUP → WM_LBUTTONUP
  1774. // WM_POINTERWHEEL → 滚轮
  1775. //
  1776. // 只处理主指针(IS_POINTER_PRIMARY_WPARAM):多指时其余手指一律忽略,
  1777. // 避免多点同时驱动同一个点击状态机导致互相打断。
  1778. //
  1779. // ⚠️ 但 **UP 例外**:实测本台收银机上 WM_POINTERUP 的 wParam 高位不是真正的
  1780. // POINTER_INFO 位域(HIWORD=0x6000,primary 位读到 0),照字面判定会把抬起丢掉,
  1781. // 结果"按下有反应、永远不触发点击",同时让路状态也解不开。
  1782. // 所以 UP 不做 primary 过滤,改用 m_dwActivePointerId 精确配对。
  1783. //
  1784. // 返回值语义:true = 已处理(调用方应 return true 阻止默认处理)。
  1785. //
  1786. // 【不变量】任何路径都**不得**让 m_bPointerGestureActive 悬空为 true:
  1787. // · 它是"本次手势归指针管"的独占标记,为真期间 OnTouchInput 会忽略 WM_TOUCH;
  1788. // · 只有 UP / CAPTURECHANGED / 3 秒超时能把它清掉;
  1789. // · 所以 UP 在这条链路上必须走完全程(可以"只清状态不派发点击",但不能被 return true 截住)。
  1790. // ---------------------------------------------------------------------------
  1791. bool CPaintManagerUI::OnPointerInput(UINT uMsg, WPARAM wParam, LPARAM lParam)
  1792. {
  1793. using namespace PointerMsg;
  1794. const DWORD dwPointerId = (DWORD)LOWORD(wParam);
  1795. // ==================================================================
  1796. // ★★【模态背闸 · 入口第一道】弹框还开着时,背景窗口收不到"驱动点击"的指针消息。
  1797. //
  1798. // 这是用户实测 bug「点弹框的『选好了』会透传到主窗口商品卡」的**根治点**。
  1799. // 完整成因与"为什么事后的命中点复核挡不住"见 IsModalBackdropWindow 的注释。
  1800. //
  1801. // ⚠️ 只压住**驱动点击/滑动**的两个消息(DOWN / UPDATE):
  1802. // 它们在背景窗口上没有任何正当用途(背景已被系统禁用),
  1803. // 直接吃掉最干净 —— 连 BeginTouchSlideGesture 都不该进,
  1804. // 否则 m_pEventClick / m_pEventTouch 会被建立起来,
  1805. // 给后续的"抬手派发"留下可供透传的种子。
  1806. //
  1807. // ⚠️⚠️ UP 必须【放行到下面的 switch】⚠️⚠️
  1808. // 与上面"通道互斥"的注释同理:UP 是**唯一**能清 m_bPointerGestureActive 的
  1809. // 消息。在这里 return true 会让本次手势的标记永久悬空,
  1810. // 之后该窗口的所有 DOWN 都被当成"重复按下"挡掉 ⇒ 彻底聋掉(已踩过)。
  1811. // 放行后由 UP 分支自己判 `IsModalBackdropWindow` 并走"只清状态、不派发点击"。
  1812. // ==================================================================
  1813. if (uMsg != DUI_WM_POINTERUP && IsModalBackdropWindow(m_hWndPaint))
  1814. {
  1815. // 不 return true 之外的任何动作:不建状态、不派发。
  1816. // 同时顺手把可能残留的滑动标记收掉(上一次手势若被异常中断)。
  1817. return true;
  1818. }
  1819. // ---- [NIM 风格] 通道互斥:本次手势已被 WM_TOUCH 接管,指针整段安静 ----
  1820. //
  1821. // 照搬 nim_duilib Window.cpp 的判据(**不看时间戳,只看归属标记**):
  1822. //
  1823. // WM_TOUCH DOWN: if (m_pEventClick != NULL || m_pEventPointer != NULL) break;
  1824. // WM_POINTER DOWN: if (m_pEventClick != NULL || m_pEventTouch != NULL) { handled=true; break; }
  1825. //
  1826. // 即"谁先建立了占用标记,另一条通道就退让",由手势状态天然驱动、无需计时器。
  1827. // 本项目的对应标记:
  1828. // · m_pEventTouch ← 触摸链的占用标记(BeginTouchSlideGesture 里置)
  1829. // · m_bPointerGestureActive ← 指针链的占用标记(下面 DOWN 分支里置)
  1830. //
  1831. // ⚠️⚠️ 【UP 必须放行,绝不能在这里 return true】⚠️⚠️
  1832. // 这是实测踩过的坑,后果极严重(主窗口触摸点击全灭):
  1833. // WM_POINTERUP 是**唯一**能把 m_bPointerGestureActive 归零的消息。
  1834. // 早期版本把 DOWN/UPDATE/UP 不加区分地一起吞掉,于是:
  1835. // 1) 用户第一次点击:WM_TOUCH 先到 ⇒ 这里把 UP 吃掉
  1836. // ⇒ m_bPointerGestureActive 永久停在 true(上一次手势的残留值);
  1837. // 2) 之后每次触摸的 WM_POINTERDOWN 都被当成"重复按下"挡掉
  1838. // ⇒ 再也不产生 POINTER-MSG DOWN ⇒ 该窗口彻底聋掉。
  1839. // 正确做法:让路只压住"驱动点击"的两个消息(DOWN/UPDATE),UP 一律放行 ——
  1840. // 放行后**只做状态清理、不派发 WM_LBUTTONUP**(本次点击本来就不归指针管)。
  1841. //
  1842. // ⚠️ 与上一版的关键差异:这里用 `m_pEventTouch != NULL` 而非时间戳。
  1843. // m_pEventTouch 的语义是"WM_TOUCH 手势进行中命中的控件",
  1844. // 它在 BeginTouchSlideGesture 里置、在 EndTouchSlideGesture 里清,
  1845. // 生命周期与"WM_TOUCH 是否真的接管了本次手势"严格一致 —— 这正是我们想要的。
  1846. // 用时间戳的旧写法会因"指针通道自己也写它"而恒真,导致点击全灭(已踩过)。
  1847. //
  1848. // ⚠️⚠️ 【两条标记同时为真是**正常**路径,绝不能"清洗"它】⚠️⚠️
  1849. //
  1850. // 曾经在这里写过一段"状态交叉"纠偏:发现 m_pEventTouch != NULL 且
  1851. // m_bPointerGestureActive 为真,就认定异常,把 m_pEventTouch 置回 NULL。
  1852. // 那是个**严重的误判**,直接造成"整个应用什么都点不动"(真机日志可复现):
  1853. //
  1854. // 指针通道的 DOWN 分支会调 BeginTouchSlideGesture,而该函数**本来就会**
  1855. // 把 m_pEventTouch 置成命中控件 —— 也就是说"指针手势进行中 + m_pEventTouch 非空"
  1856. // 是每一次指针手势的**标准状态**,不是异常。
  1857. // 于是那段"纠偏"在第一条 UPDATE 上就把 m_pEventTouch 抹成 NULL:
  1858. // · UpdateTouchSlideGesture 里 `if (m_pEventTouch == NULL) return;`
  1859. // ⇒ 位移信息全丢,永远不产生 TOUCHMOVE ⇒ 滑不动;
  1860. // · EndTouchSlideGesture 里 `if (m_pEventTouch == NULL)` 走早退路
  1861. // ⇒ 返回 false = "不算轻点" ⇒ 点击被静默吞掉 ⇒ 什么都点不动。
  1862. //
  1863. // [NIM] 对照:NIM 的两条通道标记(m_pEventTouch / m_pEventPointer)是**并列**的,
  1864. // 互斥只表达在"谁先占、另一方就退让"那一步,NIM 从不事后清洗标记。
  1865. // 本项目的互斥同理:靠下面 bYieldToTouchChannel 的**入口快照**表达即可,
  1866. // 不需要、也不能有任何"把另一个标记清掉"的动作。
  1867. const bool bYieldToTouchChannel = (m_pEventTouch != NULL) && (!m_bPointerGestureActive);
  1868. if (bYieldToTouchChannel
  1869. && (uMsg == DUI_WM_POINTERDOWN || uMsg == DUI_WM_POINTERUPDATE))
  1870. {
  1871. return true; // 吃掉,不驱动点击;也不 return false,免得被系统再转成鼠标消息
  1872. }
  1873. if (bYieldToTouchChannel && uMsg == DUI_WM_POINTERUP)
  1874. {
  1875. // 让路期间的 UP:放行到下面的 switch,由 DUI_WM_POINTERUP 分支只清状态、不派发点击。
  1876. }
  1877. // 下面各分支统一用这个名字(保持旧代码可读性)
  1878. const bool bPointerYieldedThisGesture = bYieldToTouchChannel;
  1879. // ---- [NIM 风格] pointerId 配对:只让"发起本次手势的那根手指"驱动状态机 ----
  1880. //
  1881. // nim_duilib 的 OnPointerMsgs 里对应的写法是:
  1882. // if (!IS_POINTER_PRIMARY_WPARAM(wParam)) { handled = true; break; }
  1883. // 本项目**不能照抄**这一句 —— 真机实测该位域在这台机器上错位(见 PointerMsg::
  1884. // IsPrimaryPointer 处的大段注释),UPDATE 会被全部误杀,症状是"能点不能滑"。
  1885. //
  1886. // 因此改用**唯一可靠的判据:pointerId**(wParam 低 16 位,日志里形如 0x0CC7=3271)。
  1887. // 语义:"只有当初(或在让路解禁后补建时)记下的那根手指,才有资格驱动 UPDATE/UP。"
  1888. //
  1889. // ⚠️ 豁免条件(否则会踩真实死锁):
  1890. // (a) UP 必须无条件放行 —— 它是**唯一**能清 m_bPointerGestureActive 的消息,
  1891. // 丢了它手势状态会永久悬空(3 秒超时只是兜底,体验上是"点一下卡三秒")。
  1892. // (b) UPDATE 在"没有活跃指针手势"时必须放行 —— 此时没有 id 可比对,
  1893. // 而且它正是"DOWN 被系统丢了、只有 UPDATE 能救回来"的那条自愈路径;
  1894. // 下面的 UPDATE 分支本身有 `if (m_bTouchSlideActive)` 守卫,空转是安全的。
  1895. if (m_bPointerGestureActive && dwPointerId != m_dwActivePointerId
  1896. && uMsg != DUI_WM_POINTERUP)
  1897. {
  1898. return true;
  1899. }
  1900. // 非坐标类指针消息(没有 pointerId 语义),直接交回系统,绝不吞。
  1901. if (uMsg == DUI_WM_POINTERCAPTURECHANGED || uMsg == DUI_WM_POINTERLEAVE)
  1902. return true;
  1903. // 坐标:WM_POINTER* 的 lParam 是**屏幕坐标**(与 WM_TOUCH 一致),需转客户区。
  1904. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1905. ::ScreenToClient(m_hWndPaint, &pt);
  1906. switch (uMsg)
  1907. {
  1908. case DUI_WM_POINTERDOWN:
  1909. {
  1910. // 记下"本次手势由指针通道驱动":随后同一次触摸的 WM_TOUCH 会被 OnTouchInput 忽略。
  1911. m_bPointerGestureActive = true;
  1912. m_dwActivePointerId = dwPointerId;
  1913. // 计时基准(**仅**供 3 秒超时自愈用,不参与任何归属判定)。
  1914. m_dwPointerDownTick = ::GetTickCount();
  1915. // ⚠️⚠️ 【这里绝对不能写"让路时间戳"这类全局归属字段】⚠️⚠️
  1916. //
  1917. // 早先这里写的是"同时刷新让路时间戳,作为指针手势进行中的计时基准" ——
  1918. // 那是个语义污染,直接造成"主窗口触摸点击全灭"(真机日志可复现):
  1919. // 指针通道自己 DOWN 时把时间戳写成当前时刻 ⇒ 之后同一手势内
  1920. // `(GetTickCount() - 该值) < 3000` 恒成立 ⇒ 让路判定恒真
  1921. // ⇒ UP 走"只清状态、绝不合成点击"的早退路 ⇒ 点击两条路全断。
  1922. // (日志特征:yield=1 active=1 slide=1 moved=0 + 没有 click-candidate)
  1923. //
  1924. // [NIM 风格] 现在归属完全由 m_bPointerGestureActive 这个布尔标记表达,
  1925. // 超时自愈由专门的 m_dwPointerDownTick 计时,两者职责分离、互不干扰。
  1926. // 与 WM_LBUTTONDOWN 分支一致:先把焦点给本窗口,否则输入法/键盘焦点
  1927. // 可能仍停在别的窗口上(真模态下更要注意别把焦点让给 owner)。
  1928. //
  1929. // ⚠️【诊断 · 新建商品弹框「输入文字消失」】这一行会把键盘焦点从当前
  1930. // 输入框的 CEditWnd 上**抢到主窗口**,而 CEditWnd 一旦失焦就会
  1931. // PostMessage(WM_CLOSE) 自毁。紧接着 BeginTouchSlideGesture 里会
  1932. // pControl->SetFocus();若目标恰好是"已经持有 DuiLib 焦点"的那个
  1933. // 控件(m_pFocus 没变),CPaintManagerUI::SetFocus 会**早退**、
  1934. // 不重发 UIEVENT_SETFOCUS ⇒ 编辑窗口不会被重建 ⇒ 输入永久失效。
  1935. // 这正是"切到另一个框后就再也输不进去"最可能的断点,必须留痕。
  1936. {
  1937. TCHAR szBefore[128] = { 0 };
  1938. HWND hBefore = ::GetFocus();
  1939. if (hBefore != NULL && ::IsWindow(hBefore)) ::GetClassName(hBefore, szBefore, _countof(szBefore));
  1940. DuiLibDiag::Log(_T("PTR-DOWN stealFocus mgrHwnd=%p nFocusBefore=%p clsBefore=%s -> 即将 SetFocus(本窗口)"),
  1941. (void*)m_hWndPaint, (void*)hBefore, szBefore);
  1942. }
  1943. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1944. // ---- [通道无关滑动] 指针通道也要建立滑动状态机 ----
  1945. // 这是"滑不动"的根治点。原先滑动逻辑只写在 WM_TOUCH 通道里,指针通道一旦
  1946. // 抢到手势就完全没有滑动能力,只会在 UP 时把整个手势当一次点击。
  1947. // 现在两条通道共用 BeginTouchSlideGesture:命中控件、找可滚容器、抓滚动条滑块
  1948. // 全部照做,后续 UPDATE 才有 m_pTouchScrollContainer 可用。
  1949. //
  1950. // 该函数内部已完成原 DOWN 分支需要的一切:FindControl、SetFocus、SetCapture、
  1951. // 建立候选点击 m_pEventClick、以及给滚动条派发 UIEVENT_TOUCHDOWN。
  1952. // 所以**不再**调用 MessageHandler(WM_LBUTTONDOWN) ——
  1953. // 那条原生路径会在抬手时直接 Activate 控件("滑动也触发点击"的元凶),
  1954. // 而点击已改由 UP 分支经 tap 判定统一派发。
  1955. BeginTouchSlideGesture(pt);
  1956. return true;
  1957. }
  1958. case DUI_WM_POINTERUPDATE:
  1959. {
  1960. // [通道无关滑动] 指针的位移同样走共享滑动逻辑:
  1961. // 去重 / 置 m_bTouchMoved / 派发 UIEVENT_TOUCHMOVE 给容器或滚动条 / 合成滚轮。
  1962. // 这样指针通道下的滑动行为与 WM_TOUCH 通道**完全一致**。
  1963. //
  1964. // ⚠️ 这里**不再**额外喂 WM_MOUSEMOVE 给原生鼠标路径。
  1965. // 原因:本次手势已由触摸语义接管(m_bTouchSlideActive 为真),原生鼠标路径
  1966. // 只会带来副作用而没有任何收益 ——
  1967. // · 它会走 m_bDragMode / 拖放、并重建 HOT 悬浮态(触摸没有悬浮语义);
  1968. // · 它还会让"提升出来的鼠标移动"参与 m_bTouchMoved 的二次判定,与
  1969. // UpdateTouchSlideGesture 的判定重复。
  1970. // 而控件真正需要的移动语义,已被 UIEVENT_TOUCHMOVE(容器/滚动条)覆盖;
  1971. // 其余控件对"拖动中移动"本来就不关心(只认按下与抬起)。
  1972. // 需要鼠标侧更新的场景(真实鼠标)不经这条分支,所以不受影响。
  1973. if (m_bTouchSlideActive)
  1974. {
  1975. UpdateTouchSlideGesture(pt);
  1976. // 手势进行中:这条指针消息由我们完全接管,不再回落。
  1977. return true;
  1978. }
  1979. // 没有活跃的触摸滑动状态(例如 Begin 因 FindControl 落空而空转):
  1980. // 退化为纯粹的鼠标移动语义,交给原生路径。
  1981. LRESULT lRes = 0;
  1982. if (MessageHandler(WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(pt.x, pt.y), lRes))
  1983. return true;
  1984. return false;
  1985. }
  1986. case DUI_WM_POINTERUP:
  1987. {
  1988. // 手势结束:立刻解除"指针驱动中",让下一个手势可以重新选择通道。
  1989. m_bPointerGestureActive = false;
  1990. m_dwActivePointerId = 0;
  1991. m_dwPointerDownTick = 0;
  1992. // ------------------------------------------------------------------
  1993. // ★★【模态背闸 · UP 分支】背景窗口的 UP:只清状态,**绝不派发点击**。
  1994. //
  1995. // 为什么 UP 不能像 DOWN/UPDATE 那样在入口直接 return true:
  1996. // 上面已经把 m_bPointerGestureActive 归零了,所以"解死锁"的职责已完成;
  1997. // 但**不能**走下面正常的收尾链(EndTouchSlideGesture → TouchUp → 派发点击),
  1998. // 否则背景窗口会在弹框还开着的时候把点击派发出去 —— 这正是透传。
  1999. //
  2000. // 要清的状态(都是"上一次手势的痕迹",不清会污染下一次):
  2001. // · 滑动状态机:若本窗口竟有活跃的滑动(DOWN 是在弹框出现前建立、
  2002. // 或者两通道交叉),必须收掉,否则 m_bTouchSlideActive 残留到下次手势。
  2003. // · 但**不派发** TOUCHUP 给控件 —— 背景控件此刻不该有任何交互反应。
  2004. //
  2005. // 与 DOWN/UPDATE 的差别(为什么不用同一个入口闸):
  2006. // 入口处若连 UP 一起吞,m_bPointerGestureActive 就永远清不掉 ⇒
  2007. // 该窗口彻底聋掉(历史踩过的坑,见本函数开头注释)。
  2008. // ------------------------------------------------------------------
  2009. if (IsModalBackdropWindow(m_hWndPaint))
  2010. {
  2011. // 清滑动状态机(不发 TOUCHUP、不动控件树)。
  2012. m_bTouchSlideActive = false;
  2013. m_pTouchScrollContainer = NULL;
  2014. m_bTouchMoved = false;
  2015. // 关键:**不派发任何点击**。候选点击就地作废。
  2016. m_pEventClick = NULL;
  2017. // 释放可能残留的捕获(捕获属于背景 HWND,留着会害下一次手势)。
  2018. if (m_bMouseCapture) ReleaseCapture();
  2019. return true;
  2020. }
  2021. // 让路期间的 UP 只用来"解死锁":本次点击归 WM_TOUCH 管,指针侧绝不能
  2022. // 再补一个 WM_LBUTTONUP —— 否则会把 WM_TOUCH 路径建立的 m_pEventClick 提前
  2023. // 清掉(产生"按下有反应、点击不触发"),甚至给同一次触摸补出第二个 BUTTONUP。
  2024. if (bPointerYieldedThisGesture)
  2025. {
  2026. // 让路中不应有活跃的滑动状态;万一有(两通道交叉),也要收掉,
  2027. // 否则 m_bTouchSlideActive 会残留到下一次手势,导致 Update 算错 Δ。
  2028. if (m_bTouchSlideActive) EndTouchSlideGesture(pt);
  2029. return false;
  2030. }
  2031. // [通道无关滑动] 先走共享收尾:派发 TOUCHUP 给滚动条/容器、清悬浮态、让路解禁、
  2032. // 以及最重要的 tap 判定。返回值 = "本次手势算一次轻点"。
  2033. //
  2034. // ⚠️ 为什么这里必须走 TouchUp() 放行原生消息、而不能只交给 MessageHandler:
  2035. // DOWN 分支调 BeginTouchSlideGesture 后 m_pEventTouch 已被置成命中控件,
  2036. // 这会让原生的 WM_LBUTTONDOWN 在**当时**提前 break、不建立 m_pEventClick。
  2037. // 但 EndTouchSlideGesture(下面第一步)已经把 m_pEventTouch 释放了 ——
  2038. // ⇒ 这里放行的那条配对 DOWN 会正常建立 m_pEventClick、UP 也会正常点出来。
  2039. // (这与 WM_TOUCH 通道完全同构,见 TouchUp 的说明。)
  2040. //
  2041. // [语义] 与 WM_TOUCH 通道同构:点击与否**只由手指是否滑动决定**。
  2042. // ⚠️ 这里曾经有一条"没有任何可滑动对象时,仍按点击处理"的兜底,
  2043. // 那会让"在无滚动条区域滑动"错误地触发点击(用户实测到的问题)。
  2044. // 已删除 —— 判定回归 EndTouchSlideGesture 里单一的 m_bTouchMoved。
  2045. const bool bTapLike = EndTouchSlideGesture(pt);
  2046. TouchUp(pt, bTapLike);
  2047. // 已消费:不再回落 MessageHandler,避免同一条 UP 被处理第二次。
  2048. return true;
  2049. }
  2050. case DUI_WM_POINTERWHEEL:
  2051. {
  2052. // wParam 高位是滚轮增量(与 WM_MOUSEWHEEL 一致)
  2053. const short zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
  2054. LRESULT lRes = 0;
  2055. if (MessageHandler(WM_MOUSEWHEEL, MAKEWPARAM(0, zDelta), MAKELPARAM(pt.x, pt.y), lRes))
  2056. return true;
  2057. return false;
  2058. }
  2059. case DUI_WM_POINTERLEAVE:
  2060. // 指针离开窗口:清悬浮态(触摸本无悬浮语义,这里只做兜底清理)
  2061. ClearTouchHoverState(pt);
  2062. return true;
  2063. case DUI_WM_POINTERCAPTURECHANGED:
  2064. // 捕获被系统夺走(典型:手势被中断、窗口失活)。
  2065. // nim_duilib 注释:若不设置 bHandled,系统会把它转成 WM_BUTTON 类消息 ——
  2066. // 我们这里明确吃掉并复位状态,避免状态残留导致后续点击全被吞。
  2067. m_bPointerGestureActive = false;
  2068. m_dwActivePointerId = 0;
  2069. m_dwPointerDownTick = 0;
  2070. m_pEventTouch = NULL;
  2071. m_pTouchScrollContainer = NULL;
  2072. m_bTouchMoved = false;
  2073. m_bSuppressPromotedTouchMouse = false;
  2074. m_dwTouchDownTick = 0;
  2075. m_dwSuppressTick = 0;
  2076. m_nTouchWheelAccum = 0;
  2077. // [通道无关滑动] 滑动状态机也必须一起收掉 —— 否则 m_bTouchSlideActive 残留为真,
  2078. // 下一次手势若走 WM_TOUCH,Update 会误用上一次的 m_ptLastTouchPos 算出巨大 Δ,
  2079. // 表现为"一按下内容就猛地跳一段"。
  2080. m_bTouchSlideActive = false;
  2081. return true;
  2082. default:
  2083. break;
  2084. }
  2085. // POINTERENTER / POINTERACTIVATE / POINTERHWHEEL 等:交回默认处理。
  2086. return false;
  2087. }
  2088. // ---------------------------------------------------------------------------
  2089. // [WM_TOUCH 归属权] "补调 DefWindowProc" 钩子。
  2090. //
  2091. // 背景(详见 UIManager.h 里的长注释):WM_TOUCH 不是被系统直接投递的,
  2092. // 而是由 DefWindowProc 在收到一条"特殊标记的 WM_MOUSEMOVE / WM_INPUT"时
  2093. // 才"翻译"并派发出来。所以只要有一层吞掉了那条标记消息且不回落到
  2094. // DefWindowProc,该窗口后续就再也收不到 WM_TOUCH。
  2095. //
  2096. // 本库的 MessageHandler 为了不让"触摸提升出来的鼠标移动"污染拖拽/悬浮状态机,
  2097. // 会在两个地方吞掉它(均 return true)—— 这正是要补调的原因。
  2098. // 补调只做"副作用",我们仍然吃掉消息,DuiLib 的状态机不受影响。
  2099. // ---------------------------------------------------------------------------
  2100. void CPaintManagerUI::SetDefProcRelay(PFN_RELAY_DEFPROC pfnRelay, HWND hWndTarget)
  2101. {
  2102. m_pfnDefProcRelay = pfnRelay;
  2103. m_hWndDefProcRelay = hWndTarget;
  2104. }
  2105. void CPaintManagerUI::ClearDefProcRelay(HWND hWndTarget)
  2106. {
  2107. // 只在"绑定的窗口确实是这个"时清,避免嵌套弹框里把新弹框的钩子误清掉。
  2108. if (hWndTarget == NULL || m_hWndDefProcRelay == hWndTarget)
  2109. {
  2110. m_pfnDefProcRelay = NULL;
  2111. m_hWndDefProcRelay = NULL;
  2112. }
  2113. }
  2114. void CPaintManagerUI::RelayDefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam, LPCTSTR pszWhy)
  2115. {
  2116. if (!m_bRelayDefProcForTouchMove) return;
  2117. if (m_pfnDefProcRelay == NULL || m_hWndPaint == NULL) return;
  2118. // 绑定窗口已变(如真模态换 HWND):钩子失效,别再调用悬垂的函数指针。
  2119. if (m_hWndDefProcRelay != NULL && m_hWndDefProcRelay != m_hWndPaint)
  2120. {
  2121. return;
  2122. }
  2123. // 只关心副作用(让系统的 WM_TOUCH 翻译链继续跑),返回值丢弃。
  2124. (void)m_pfnDefProcRelay(m_hWndPaint, uMsg, wParam, lParam);
  2125. }
  2126. void CPaintManagerUI::ClearPushedStateAt(CControlUI* pControl, POINT pt)
  2127. {
  2128. // 清"这个控件"的按下/悬浮视觉,**不触发任何业务**。
  2129. //
  2130. // ------------------------------------------------------------------
  2131. // [为什么是这个签名] 参照 NIM_Duilib 的 Control::ButtonUp(关键对照)
  2132. //
  2133. // NIM 的点击收尾是这样的(duilib/Core/Control.cpp:910-939):
  2134. // bool Control::ButtonUp(EventArgs& msg) {
  2135. // if (IsMouseFocused()) {
  2136. // SetMouseFocused(false); ... Invalidate();
  2137. // if (IsPointInWithScrollOffset(msg.ptMouse)) {
  2138. // if (msg.Type == kEventPointUp) { m_uButtonState = kControlStateNormal; m_nHotAlpha = 0; }
  2139. // else { m_uButtonState = kControlStateHot; m_nHotAlpha = 255; }
  2140. // Activate(); // ★ 发 CLICK,**在复位状态之后**
  2141. // return true;
  2142. // }
  2143. // m_uButtonState = kControlStateNormal; m_nHotAlpha = 0;
  2144. // }
  2145. // return false;
  2146. // }
  2147. //
  2148. // ⇒ NIM 把 `Activate()`(触发业务、可能弹模态框)放在**状态复位之后**。
  2149. // 这就是"顺序"的字面答案:复位必须早于业务回调。
  2150. //
  2151. // 本项目的问题在**控件侧**:CDiandanFoodItemUI::DoEvent 写成了
  2152. // if (UIEVENT_BUTTONUP) { SendNotify(CLICK); SetCardState("normal"); }
  2153. // —— 先回调、后复位,而 SendNotify 会同步 `ShowModal()` 开嵌套模态循环,
  2154. // 于是复位被推迟到弹框关闭(用户看到的"按压态不消失")。
  2155. // 根治点在 CDiandanFoodItemUI::DoEvent(已改为先复位再 SendNotify)。
  2156. //
  2157. // 本函数是**兜底**:触摸链在收尾时(尤其"没有候选点击目标"或"滑动不算点击"
  2158. // 两种路径)把命中控件的视觉收干净,避免任何控件遗漏。
  2159. // ------------------------------------------------------------------
  2160. //
  2161. // ⚠️ 只处理传入的那一个控件,**不上溯祖先链**:
  2162. // 会挂按下态的只有被点击的控件本身(BUTTONDOWN 不冒泡),祖先从未被置位。
  2163. //
  2164. // ⚠️ 不碰 PUSHED 以外的状态语义:只清显示位,不发通知、不 Activate。
  2165. //
  2166. // pControl 为 NULL 时按 pt 命中查找(兼容只给坐标的调用方)。
  2167. if (m_pRoot == NULL) return;
  2168. if (pControl == NULL)
  2169. {
  2170. pControl = FindControl(pt);
  2171. if (pControl == NULL) return;
  2172. }
  2173. if (pControl->GetManager() != this) return;
  2174. // --------------------------------------------------------------
  2175. // ◆【滑动起手误按压】优先走"控件自己实现的清接口"。
  2176. //
  2177. // 原先这里只有下面那条 `DUI_CTR_BUTTON` 专用路径 —— 它依赖
  2178. // `GetInterface(DUI_CTR_BUTTON)`,也就是说**只有 CButtonUI 系**能被清到。
  2179. // 而业务侧大量自绘控件(如本项目的 CDiandanFoodItemUI : CVerticalLayoutUI)
  2180. // 的按下态是"换整卡背景图"实现的,压根没有 m_uButtonState,
  2181. // 也就拿不到 DUI_CTR_BUTTON 接口 ⇒ 被那条早退路静默跳过
  2182. // ⇒ 触摸滑动起手时留下按压态背景(用户实测 bug)。
  2183. //
  2184. // 现在改为:先用基类虚函数 `CControlUI::ClearPushedState()`。
  2185. // · CButtonUI 已把它 override 成"清 PUSHED|CAPTURED|HOT",
  2186. // 所以按钮的行为与改前**完全一致**;
  2187. // · 业务自绘控件 override 成"复位自己的卡片样式";
  2188. // · 其余控件走基类默认空实现 = 安全 no-op。
  2189. // pControl 本身就是 CControlUI* 或其派生,基类指针即可完成虚分派。
  2190. // --------------------------------------------------------------
  2191. pControl->ClearPushedState();
  2192. }
  2193. bool CPaintManagerUI::TouchUp(const POINT& pt, bool bTapLike)
  2194. {
  2195. // 【诊断 · Combo 卡顿/要点好几下】触摸链的一次抬手进入本函数。
  2196. // 判读:某一下"点了没反应"时 ——
  2197. // · 日志里**连这一行都没有** ⇒ 问题在触摸链之前(消息没到 / 被别处吞掉);
  2198. // · 有这一行、但紧随其后没有 `COMBO-ACT enter` ⇒ 点击目标不是 Combo,或被下面的闸拦了。
  2199. DuiLibDiag::Log(_T("TOUCH-UP enter tapLike=%d pt=%d,%d eventClick=%p"),
  2200. (int)(bTapLike ? 1 : 0), pt.x, pt.y, (void*)m_pEventClick);
  2201. // 契约(调用方:OnTouchInput / OnPointerInput 两条通道的 UP 分支):
  2202. // 进入时 —— 触摸链自己的手势状态(m_pEventTouch / m_pTouchScrollContainer /
  2203. // 捕获)**已经收干净**(见 EndTouchSlideGesture,它已 ReleaseCapture)。
  2204. // 返回 true —— "这次触摸的 UP 已由本函数处理完",调用方应吞掉当前消息。
  2205. //
  2206. // ==================================================================
  2207. // ★★【模态背闸 · 最后一道】本窗口是"弹框背后的背景窗口"时,只清状态、绝不派发点击。
  2208. //
  2209. // 这是用户实测 bug「点弹框的『选好了』会透传到主窗口」的**兜底防线**。
  2210. //
  2211. // 主防线在三个入口(OnPointerInput / OnTouchInput / MessageHandler),
  2212. // 它们保证"背景窗口从一开始就不产生候选点击"。但那三道闸都依赖
  2213. // `GetModalWindow()` 在**消息到达那一刻**已经登记了弹框 —— 存在两个缝隙:
  2214. //
  2215. // 缝隙 1:DOWN 到达时模态**还没开始**(手势比弹框早)。
  2216. // 这是"点商品卡 → 回调里 ShowModal()"的正常时序:
  2217. // 该次手势的 DOWN 发生在弹框出现之前,候选点击(m_pEventClick)
  2218. // 是那时建立的;等 UP 到达时弹框已经在上面了。
  2219. // 此时入口闸看到的是"UP 时模态为真",本来也该拦 ——
  2220. // 但 UP 必须放行(否则 m_bPointerGestureActive 悬空),
  2221. // 所以背景窗口的 UP 会一路走到这里。
  2222. // 缝隙 2:嵌套弹框(A 弹框里开 B 弹框)时 GetModalWindow() 会被覆盖成 B,
  2223. // 而 A 的 UP 可能仍在路上。
  2224. //
  2225. // 语义上这里也必须是零容忍的:
  2226. // **业务回调已经由"弹框自己的按钮"触发了,背景窗口不该再触发第二次。**
  2227. // 所以本函数在最开头就做这道判定,且**只收视觉、不派发任何通知**。
  2228. //
  2229. // ⚠️ 注意本闸的位置必须在 `if (!bTapLike)` **之前**:
  2230. // 否则"滑动路径"与"轻点路径"会走两套不同的清理代码,
  2231. // 而背景窗口两条路都只需要"清干净、别动控件"。
  2232. // ==================================================================
  2233. if (IsModalBackdropWindow(m_hWndPaint))
  2234. {
  2235. DuiLibDiag::Log(_T("TOUCH-UP swallow: 本窗口是模态背景窗口 ⇒ 只清状态、不派发点击 pt=%d,%d"), pt.x, pt.y);
  2236. // 清掉本次手势的痕迹(不发任何通知、不给控件派发 TOUCHUP/BUTTON*)。
  2237. m_pEventClick = NULL;
  2238. m_pTouchScrollContainer = NULL;
  2239. m_bTouchMoved = false;
  2240. m_bTouchSlideActive = false;
  2241. m_bPointerGestureActive = false;
  2242. m_dwActivePointerId = 0;
  2243. m_bSuppressPromotedTouchMouse = false;
  2244. m_dwSuppressTick = 0;
  2245. // 悬浮态也收掉(背景控件不该保持 HOT)。
  2246. {
  2247. POINT ptDummy = { -1, -1 };
  2248. ClearTouchHoverState(ptDummy);
  2249. }
  2250. return true;
  2251. }
  2252. // ------------------------------------------------------------------
  2253. // ⚠️⚠️ 为什么必须**自己派发**点击事件(别再改成"放行原生鼠标消息")⚠️⚠️
  2254. //
  2255. // 真机日志实测结论:
  2256. // 本机 Win10 上触摸**只产生 WM_POINTER\***,
  2257. // `fromtouch=1` 的 `WM_LBUTTONDOWN` / `WM_LBUTTONUP` 数量是 **0** ——
  2258. // 系统**不会**为触摸提升出鼠标点击消息(老 Win7 触摸栈才会)。
  2259. //
  2260. // ⇒ 曾经有一版实现改成"把配对的原生 DOWN/UP 放行,让鼠标路径去点",
  2261. // 结果**整机点不动**:那条消息根本不存在,放行等于把整个手势丢掉。
  2262. // 教训已写入 UIManager.h 的 TouchUp 注释,勿再重犯。
  2263. //
  2264. // ------------------------------------------------------------------
  2265. // [本函数要修的真正问题]:**业务回调被夹在两条合成事件中间**
  2266. //
  2267. // 旧的合成顺序:
  2268. // Event(BUTTONDOWN) → 控件置 PUSHED(商品卡置 "pressed")
  2269. // Event(BUTTONUP) → 控件 DoEvent 里 `SendNotify(CLICK)`
  2270. // → 业务层 `ShowModal()` 开**嵌套模态循环**
  2271. // → 控件自己的 `SetCardState("normal")` 在 CLICK 之后才跑
  2272. //
  2273. // 关键:`CControlUI::Event → DoEvent` 是**同步调用**(UIControl.cpp:841),
  2274. // 所以业务回调会阻塞在中间,"清按下态"被推迟到**弹框关闭之后** ——
  2275. // 弹框存活的整段时间里卡片都顶着 "pressed"(用户看到的"按压态不消失"),
  2276. // 而且回调返回时前台已经变了 ⇒ 复位动作打在错的对象/时机上。
  2277. //
  2278. // 鼠标路径为什么没这问题:它的清理动作全部在业务回调**之前**:
  2279. // ClearTouchHoverState / ClearPushedStateAt / s_bSuppressHoverAfterTouch
  2280. // → 才轮到 `pClick->Event(BUTTONUP)` → `SendNotify(CLICK)` → `ShowModal()`
  2281. //
  2282. // 但**触摸链不能照搬"事前 ClearPushedStateAt"**!
  2283. // 鼠标的 DOWN/UP 是两条独立消息,中间有重绘;触摸链的
  2284. // BUTTONDOWN/BUTTONUP 是同一次调用里背靠背合成的,中间没有重绘机会
  2285. // ⇒ 事前清一次等于"先擦、再置 pressed、再复位 normal"三段连跑,
  2286. // pressed 帧一帧都画不出来(用户实测:所有商品按压态都不显示)。
  2287. // ⇒ 本函数的做法是:**只收 hover,不碰按下态**,把按下态的置/复
  2288. // 完全交给控件自己的 DoEvent(TOUCHDOWN 置、BUTTONUP 先复位后回调)。
  2289. // ------------------------------------------------------------------
  2290. if (!bTapLike)
  2291. {
  2292. // 手指滑动过 ⇒ 绝不能触发点击。
  2293. // 注意:这里也**不能**靠"放行原生 UP"来清按下态(没有那条消息),
  2294. // 所以自己把命中点的按下态收掉 —— 等价于鼠标路径里
  2295. // `WM_LBUTTONUP` 那句 `ClearPushedStateAt` + `bTouchDragged` 的
  2296. // "ptMouse 置 (-1,-1) 只清位不 Activate"效果。
  2297. ClearPushedStateAt(NULL, pt);
  2298. m_pEventClick = NULL;
  2299. m_bSuppressPromotedTouchMouse = false;
  2300. m_dwSuppressTick = 0;
  2301. m_bTouchMoved = false;
  2302. return true;
  2303. }
  2304. if (m_pEventClick == NULL)
  2305. {
  2306. // 轻点,但没有候选点击目标(Begin 时 FindControl 落空)。
  2307. // 仍然要把按下视觉收干净(可能与其它路径交叉),然后吞掉。
  2308. ClearPushedStateAt(NULL, pt);
  2309. m_bSuppressPromotedTouchMouse = false;
  2310. m_dwSuppressTick = 0;
  2311. m_bTouchMoved = false;
  2312. return true;
  2313. }
  2314. CControlUI* pClick = m_pEventClick;
  2315. // 本次触摸已消费:清掉候选点击,避免它残留到下一次手势。
  2316. m_pEventClick = NULL;
  2317. m_pTouchScrollContainer = NULL;
  2318. // 本机触摸不会被提升成鼠标消息,所以这个抑制位在触摸链里意义不大;
  2319. // 保留置假以免历史行污染(真机上没有需要吞的 LBUTTON 消息)。
  2320. m_bSuppressPromotedTouchMouse = false;
  2321. m_dwSuppressTick = 0;
  2322. m_bTouchMoved = false;
  2323. // ==================================================================
  2324. // ★【防透传 · 死线检查】抬起时必须重新校验"抬手那一刻模态是否已经打开"。
  2325. //
  2326. // 这是本函数最贴近透传现场的判据,来自用户实测的**真实时序**:
  2327. // 用户点的"选好了"(`diandan_nature_save`)走的是 `Close(IDOK)`,
  2328. // 弹框由此开始销毁 —— 但 `DialogBoxIndirectParam` 的返回、
  2329. // 以及 `SetModalWindow(hPrevModal)` 的还原,都在**嵌套消息循环退出之后**。
  2330. //
  2331. // ⇒ 于是存在一个窗口期:**弹框已经在销毁、但 GetModalWindow() 还指向它**。
  2332. // 在这期间到达的输入消息,如果走的是主窗口(背景窗口),
  2333. // `IsModalBackdropWindow` 会因为 (a) 仍为真、(c) 也成立而把它拦下 ——
  2334. // 这是对的;但另一个方向:**主窗口自己那条手势的 UP 到达时**,
  2335. // 入口闸要等到 UP 分支才判,而 UP 又必须放行(否则 m_bPointerGestureActive
  2336. // 悬空、窗口彻底聋掉)—— 所以必须在这里、在**派发点击之前**再判一次。
  2337. //
  2338. // 判据是**纯状态**的(不看时间戳):
  2339. // (a) 该控件仍属于当前 manager;
  2340. // (b) 抬手点 `FindControl(pt)` 仍命中它(弹框覆盖时命中的会是弹框里的控件);
  2341. // (c) **此刻没有"别的"窗口处于模态背闸状态** —— 即本窗口自己
  2342. // 此刻是不是背景窗口。是 ⇒ 说明模态会话仍在新窗口里进行,
  2343. // 这次点击不该由背景窗口派发。
  2344. // 任一不满足 ⇒ 只收尾、绝不 SendNotify。
  2345. //
  2346. // 鼠标路径为什么没这问题:真模态独占鼠标捕获与消息投递,
  2347. // 背后窗口根本收不到那条 WM_LBUTTONUP。触摸链是我们自己按
  2348. // `m_pEventClick` 派发的,绕过了窗口边界 ⇒ 必须自己补这道复核。
  2349. // ==================================================================
  2350. if (IsModalBackdropWindow(m_hWndPaint))
  2351. {
  2352. // 只收掉按下视觉,**绝不 SendNotify**。
  2353. ClearPushedStateAt(pClick, pt);
  2354. m_bSuppressPromotedTouchMouse = false;
  2355. m_dwSuppressTick = 0;
  2356. return true;
  2357. }
  2358. const bool bStillOwned = (pClick->GetManager() == this);
  2359. if (!bStillOwned)
  2360. {
  2361. return true;
  2362. }
  2363. CControlUI* pHitNow = FindControl(pt);
  2364. // 命中判定要穿透到"同一张卡":FindControl 可能返回卡内的子控件
  2365. // (图片/文字),而 m_pEventClick 记的是整张卡。用祖先链做等价判定。
  2366. bool bSameTarget = false;
  2367. for (CControlUI* pWalk = pHitNow; pWalk != NULL; pWalk = pWalk->GetParent())
  2368. {
  2369. if (pWalk == pClick)
  2370. {
  2371. bSameTarget = true;
  2372. break;
  2373. }
  2374. }
  2375. if (!bSameTarget)
  2376. {
  2377. // 只收掉"按下视觉",绝不 SendNotify —— 这次点击已经不属于它了。
  2378. ClearPushedStateAt(pClick, pt);
  2379. return true;
  2380. }
  2381. // ==================================================================
  2382. // ★【悬浮态收尾】把 hover 登记收干净 —— 必须在派发点击**之前**。
  2383. //
  2384. // 这段解决的是上一轮的 bug:「弹框里点『选好了』后,屏幕同位置的背后商品
  2385. // 变成悬浮态(hot)」。
  2386. //
  2387. // 为什么不能"像鼠标那样用抬手点重建 hover":
  2388. // 鼠标路径点完不留悬浮,是因为它的 `WM_LBUTTONUP` 里 `ClearTouchHoverState`
  2389. // 把 `m_pEventHover` 置空了,之后系统补发的 `WM_MOUSEMOVE` 才重新立 hover。
  2390. // 触摸链抬手后**没有** `WM_MOUSEMOVE`(手指已离开),
  2391. // 若照鼠标"重新命中并 ENTER",`FindControl(pt)` 会返回**刚点的那张卡自己**
  2392. // (`CContainerUI::FindControl` 末尾 `Proc(this,pData)` 返回容器自身)
  2393. // ⇒ 卡片刚复位完 pressed 立刻被打成 hot。
  2394. // 语义上也对:**hover = 光标停留,而抬手 ≠ 停留**。
  2395. // (NIM 的 `HandleMouseEnterLeave` 由移动消息驱动,抬手时不会调用。)
  2396. //
  2397. // ⚠️ 只碰 hover,**不碰按下态** —— 按下态归下面派发链里控件自己的
  2398. // `BUTTONUP` 分支复位(见 CDiandanFoodItemUI::DoEvent)。
  2399. // 这两件事必须分开,否则又会变成"先擦后置、pressed 帧永远看不到"。
  2400. // ==================================================================
  2401. if (m_pEventHover != NULL)
  2402. {
  2403. TEventUI hoverEvent = { 0 };
  2404. hoverEvent.Type = UIEVENT_MOUSELEAVE;
  2405. hoverEvent.pSender = m_pEventHover;
  2406. hoverEvent.ptMouse = pt;
  2407. hoverEvent.wKeyState = MapKeyState();
  2408. hoverEvent.dwTimestamp = ::GetTickCount();
  2409. m_pEventHover->Event(hoverEvent);
  2410. m_pEventHover = NULL;
  2411. // 连带收掉"需要 MOUSELEAVE 的登记表"(与鼠标路径 ClearTouchHoverState 同构)。
  2412. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); ++i)
  2413. {
  2414. CControlUI* pNeed = static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]);
  2415. if (pNeed != NULL && pNeed != hoverEvent.pSender)
  2416. {
  2417. hoverEvent.pSender = pNeed;
  2418. pNeed->Event(hoverEvent);
  2419. }
  2420. }
  2421. m_aNeedMouseLeaveNeeded.Empty();
  2422. }
  2423. // ==================================================================
  2424. // ★【顺序】派发点击。**刻意不在事前清按下态**。
  2425. //
  2426. // ——— 为什么绝对不能"先清 pressed、再派发"———
  2427. // 用户实测 bug:(我上一版在派发前加了 `ClearPushedStateAt(pClick, pt)`,
  2428. // 结果) **所有商品控件的按压态都不显示了**。
  2429. //
  2430. // 因果链:
  2431. // 1) 触摸链在 DOWN 时只发 `UIEVENT_TOUCHDOWN`,`UIEVENT_BUTTONDOWN`
  2432. // 要等到**抬手时**才由下面这几行成对合成;
  2433. // 2) 商品卡的 pressed 视觉来自 `TOUCHDOWN` / `BUTTONDOWN` 分支;
  2434. // 3) 若在派发前先 `ClearPushedStateAt`,等于"先擦、再置",
  2435. // 紧接着 `BUTTONUP` 又复位成 normal ——
  2436. // 这几个动作**全在同一次调用里背靠背完成,中间没有任何重绘机会**
  2437. // ⇒ 用户从头到尾看不到 pressed 帧。
  2438. // 鼠标路径能看见 pressed,是因为它的 DOWN/UP 是**两条独立消息**,
  2439. // 中间隔着一次消息循环 + 重绘。
  2440. //
  2441. // ——— 那"弹框弹出时控件还顶着 pressed"怎么办?———
  2442. // 已由**控件侧**按 NIM `Control::ButtonUp` 的正确顺序解决:
  2443. // `CDiandanFoodItemUI::DoEvent` 的 `UIEVENT_BUTTONUP` 分支现在是
  2444. // SetCardState("normal"); // 先复位
  2445. // m_pManager->SendNotify(this, DUI_MSGTYPE_CLICK); // 后回调(此处才 ShowModal)
  2446. // 而 `EndTouchSlideGesture` 在**调用本函数之前**就已经派发过 `UIEVENT_TOUCHUP`,
  2447. // 卡片在那一刻也已经复位过一次(见卡片 DoEvent 的 TOUCHUP 分支)。
  2448. // ⇒ "业务回调时控件已是普通态"这个目标由控件自己达成,
  2449. // 不需要(也不应该)由管理端在事前粗暴擦除。
  2450. // ==================================================================
  2451. TEventUI clickEvent = { 0 };
  2452. clickEvent.Type = UIEVENT_BUTTONDOWN;
  2453. clickEvent.pSender = pClick;
  2454. clickEvent.ptMouse = pt;
  2455. clickEvent.dwTimestamp = ::GetTickCount();
  2456. clickEvent.wKeyState = MapKeyState();
  2457. // 【诊断 · Combo 卡顿/要点好几下】这一次抬手最终点了谁。
  2458. DuiLibDiag::Log(_T("TOUCH-UP dispatch target=%p name=%s class=%s pt=%d,%d"),
  2459. (void*)pClick, pClick->GetName().GetData(), pClick->GetClass(), pt.x, pt.y);
  2460. pClick->Event(clickEvent);
  2461. clickEvent.Type = UIEVENT_BUTTONUP;
  2462. clickEvent.ptMouse = pt;
  2463. clickEvent.dwTimestamp = ::GetTickCount();
  2464. pClick->Event(clickEvent);
  2465. // 兜底:只针对"库内按钮"(DUI_CTR_BUTTON)这一窄类。
  2466. // 商品卡那类自定义控件不受影响 —— 它们不吃 UISTATE_*,
  2467. // 复位由自己的 DoEvent(见上)负责。
  2468. ClearPushedStateAt(NULL, pt);
  2469. return true;
  2470. }
  2471. void CPaintManagerUI::ClearTouchHoverState(POINT pt)
  2472. {
  2473. TEventUI event = { 0 };
  2474. event.Type = UIEVENT_MOUSELEAVE;
  2475. event.ptMouse = pt;
  2476. event.wKeyState = MapKeyState();
  2477. event.dwTimestamp = ::GetTickCount();
  2478. CStdPtrArray controls(m_aNeedMouseLeaveNeeded.GetSize());
  2479. controls.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  2480. ::CopyMemory(controls.GetData(), m_aNeedMouseLeaveNeeded.GetData(),
  2481. m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  2482. for (int i = 0; i < controls.GetSize(); ++i)
  2483. {
  2484. CControlUI* pControl = static_cast<CControlUI*>(controls[i]);
  2485. if (pControl != NULL)
  2486. {
  2487. event.pSender = pControl;
  2488. pControl->Event(event);
  2489. }
  2490. }
  2491. if (m_pEventHover != NULL)
  2492. {
  2493. event.pSender = m_pEventHover;
  2494. m_pEventHover->Event(event);
  2495. m_pEventHover = NULL;
  2496. }
  2497. m_aNeedMouseLeaveNeeded.Empty();
  2498. if (m_hwndTooltip != NULL)
  2499. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  2500. }
  2501. void CPaintManagerUI::DeletePtr(void* ptr)
  2502. {
  2503. if (ptr)
  2504. {
  2505. delete ptr; ptr = NULL;
  2506. }
  2507. }
  2508. HINSTANCE CPaintManagerUI::GetInstance()
  2509. {
  2510. return m_hInstance;
  2511. }
  2512. CDuiString CPaintManagerUI::GetInstancePath()
  2513. {
  2514. if (m_hInstance == NULL) return _T('\0');
  2515. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  2516. ::GetModuleFileName(m_hInstance, tszModule, MAX_PATH);
  2517. CDuiString sInstancePath = tszModule;
  2518. int pos = sInstancePath.ReverseFind(_T('\\'));
  2519. if (pos >= 0) sInstancePath = sInstancePath.Left(pos + 1);
  2520. return sInstancePath;
  2521. }
  2522. CDuiString CPaintManagerUI::GetCurrentPath()
  2523. {
  2524. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  2525. ::GetCurrentDirectory(MAX_PATH, tszModule);
  2526. return tszModule;
  2527. }
  2528. HINSTANCE CPaintManagerUI::GetResourceDll()
  2529. {
  2530. if (m_hResourceInstance == NULL) return m_hInstance;
  2531. return m_hResourceInstance;
  2532. }
  2533. const CDuiString& CPaintManagerUI::GetResourcePath()
  2534. {
  2535. return m_pStrResourcePath;
  2536. }
  2537. const CDuiString& CPaintManagerUI::GetResourceZip()
  2538. {
  2539. return m_pStrResourceZip;
  2540. }
  2541. const CDuiString& CPaintManagerUI::GetResourceZipPwd()
  2542. {
  2543. return m_pStrResourceZipPwd;
  2544. }
  2545. bool CPaintManagerUI::IsCachedResourceZip()
  2546. {
  2547. return m_bCachedResourceZip;
  2548. }
  2549. HANDLE CPaintManagerUI::GetResourceZipHandle()
  2550. {
  2551. return m_hResourceZip;
  2552. }
  2553. void CPaintManagerUI::SetInstance(HINSTANCE hInst)
  2554. {
  2555. m_hInstance = hInst;
  2556. }
  2557. void CPaintManagerUI::SetCurrentPath(LPCTSTR pStrPath)
  2558. {
  2559. ::SetCurrentDirectory(pStrPath);
  2560. }
  2561. void CPaintManagerUI::SetResourceDll(HINSTANCE hInst)
  2562. {
  2563. m_hResourceInstance = hInst;
  2564. }
  2565. void CPaintManagerUI::SetResourcePath(LPCTSTR pStrPath)
  2566. {
  2567. m_pStrResourcePath = pStrPath;
  2568. if (m_pStrResourcePath.IsEmpty()) return;
  2569. TCHAR cEnd = m_pStrResourcePath.GetAt(m_pStrResourcePath.GetLength() - 1);
  2570. if (cEnd != _T('\\') && cEnd != _T('/')) m_pStrResourcePath += _T('\\');
  2571. }
  2572. void CPaintManagerUI::SetResourceZip(LPVOID pVoid, unsigned int len, LPCTSTR password)
  2573. {
  2574. if (m_pStrResourceZip == _T("membuffer")) return;
  2575. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  2576. {
  2577. CloseZip((HZIP)m_hResourceZip);
  2578. m_hResourceZip = NULL;
  2579. }
  2580. m_pStrResourceZip = _T("membuffer");
  2581. if (m_cbZipBuf)
  2582. {
  2583. delete[] m_cbZipBuf;
  2584. m_cbZipBuf = nullptr;
  2585. }
  2586. if (!m_cbZipBuf)
  2587. {
  2588. m_cbZipBuf = new BYTE[len];
  2589. memcpy(m_cbZipBuf, pVoid, len);
  2590. }
  2591. m_bCachedResourceZip = true;
  2592. m_pStrResourceZipPwd = password; //Garfield 20160325 带密码zip包解密
  2593. if (m_bCachedResourceZip)
  2594. {
  2595. #ifdef UNICODE
  2596. char* pwd = w2a((wchar_t*)password);
  2597. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, pwd);
  2598. if (pwd)
  2599. {
  2600. delete[] pwd;
  2601. pwd = NULL;
  2602. }
  2603. #else
  2604. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, password);
  2605. #endif
  2606. }
  2607. }
  2608. void CPaintManagerUI::SetResourceZip(LPCTSTR pStrPath, bool bCachedResourceZip, LPCTSTR password)
  2609. {
  2610. if (m_pStrResourceZip == pStrPath && m_bCachedResourceZip == bCachedResourceZip) return;
  2611. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  2612. {
  2613. CloseZip((HZIP)m_hResourceZip);
  2614. m_hResourceZip = NULL;
  2615. }
  2616. m_pStrResourceZip = pStrPath;
  2617. m_bCachedResourceZip = bCachedResourceZip;
  2618. m_pStrResourceZipPwd = password;
  2619. if (m_bCachedResourceZip)
  2620. {
  2621. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  2622. sFile += CPaintManagerUI::GetResourceZip();
  2623. #ifdef UNICODE
  2624. char* pwd = w2a((wchar_t*)password);
  2625. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), pwd);
  2626. if (pwd)
  2627. {
  2628. delete[] pwd;
  2629. pwd = NULL;
  2630. }
  2631. #else
  2632. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), password);
  2633. #endif
  2634. }
  2635. }
  2636. void CPaintManagerUI::SetResourceType(int nType)
  2637. {
  2638. m_nResType = nType;
  2639. }
  2640. int CPaintManagerUI::GetResourceType()
  2641. {
  2642. return m_nResType;
  2643. }
  2644. bool CPaintManagerUI::GetHSL(short* H, short* S, short* L)
  2645. {
  2646. *H = m_H;
  2647. *S = m_S;
  2648. *L = m_L;
  2649. return m_bUseHSL;
  2650. }
  2651. void CPaintManagerUI::SetHSL(bool bUseHSL, short H, short S, short L)
  2652. {
  2653. if (m_bUseHSL || m_bUseHSL != bUseHSL)
  2654. {
  2655. m_bUseHSL = bUseHSL;
  2656. if (H == m_H && S == m_S && L == m_L) return;
  2657. m_H = CLAMP(H, 0, 360);
  2658. m_S = CLAMP(S, 0, 200);
  2659. m_L = CLAMP(L, 0, 200);
  2660. AdjustSharedImagesHSL();
  2661. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2662. {
  2663. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2664. if (pManager != NULL) pManager->AdjustImagesHSL();
  2665. }
  2666. }
  2667. }
  2668. void CPaintManagerUI::ReloadSkin()
  2669. {
  2670. ReloadSharedImages();
  2671. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2672. {
  2673. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2674. pManager->ReloadImages();
  2675. }
  2676. }
  2677. CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName)
  2678. {
  2679. if (pstrName == NULL) return NULL;
  2680. CDuiString sName = pstrName;
  2681. if (sName.IsEmpty()) return NULL;
  2682. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2683. {
  2684. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2685. if (pManager != NULL && sName == pManager->GetName()) return pManager;
  2686. }
  2687. return NULL;
  2688. }
  2689. CStdPtrArray* CPaintManagerUI::GetPaintManagers()
  2690. {
  2691. return &m_aPreMessages;
  2692. }
  2693. bool CPaintManagerUI::LoadPlugin(LPCTSTR pstrModuleName)
  2694. {
  2695. ASSERT(!::IsBadStringPtr(pstrModuleName, -1) || pstrModuleName == NULL);
  2696. if (pstrModuleName == NULL) return false;
  2697. HMODULE hModule = ::LoadLibrary(pstrModuleName);
  2698. if (hModule != NULL)
  2699. {
  2700. LPCREATECONTROL lpCreateControl = (LPCREATECONTROL)::GetProcAddress(hModule, "CreateControl");
  2701. if (lpCreateControl != NULL)
  2702. {
  2703. if (m_aPlugins.Find(lpCreateControl) >= 0) return true;
  2704. m_aPlugins.Add(lpCreateControl);
  2705. return true;
  2706. }
  2707. }
  2708. return false;
  2709. }
  2710. CStdPtrArray* CPaintManagerUI::GetPlugins()
  2711. {
  2712. return &m_aPlugins;
  2713. }
  2714. HWND CPaintManagerUI::GetPaintWindow() const
  2715. {
  2716. return m_hWndPaint;
  2717. }
  2718. HWND CPaintManagerUI::GetTooltipWindow() const
  2719. {
  2720. return m_hwndTooltip;
  2721. }
  2722. int CPaintManagerUI::GetHoverTime() const
  2723. {
  2724. return m_iHoverTime;
  2725. }
  2726. void CPaintManagerUI::SetHoverTime(int iTime)
  2727. {
  2728. m_iHoverTime = iTime;
  2729. }
  2730. LPCTSTR CPaintManagerUI::GetName() const
  2731. {
  2732. return m_sName;
  2733. }
  2734. HDC CPaintManagerUI::GetPaintDC() const
  2735. {
  2736. return m_hDcPaint;
  2737. }
  2738. POINT CPaintManagerUI::GetMousePos() const
  2739. {
  2740. return m_ptLastMousePos;
  2741. }
  2742. SIZE CPaintManagerUI::GetClientSize() const
  2743. {
  2744. RECT rcClient = { 0 };
  2745. ::GetClientRect(m_hWndPaint, &rcClient);
  2746. return CDuiSize(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  2747. }
  2748. SIZE CPaintManagerUI::GetInitSize()
  2749. {
  2750. return m_szInitWindowSize;
  2751. }
  2752. void CPaintManagerUI::SetInitSize(int cx, int cy)
  2753. {
  2754. m_szInitWindowSize.cx = cx;
  2755. m_szInitWindowSize.cy = cy;
  2756. if (m_pRoot == NULL && m_hWndPaint != NULL)
  2757. {
  2758. ::SetWindowPos(m_hWndPaint, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  2759. }
  2760. }
  2761. RECT CPaintManagerUI::GetSizeBox()
  2762. {
  2763. return GetDPIObj()->Scale(m_rcSizeBox);
  2764. }
  2765. void CPaintManagerUI::SetSizeBox(RECT& rcSizeBox)
  2766. {
  2767. m_rcSizeBox = rcSizeBox;
  2768. }
  2769. RECT CPaintManagerUI::GetCaptionRect()
  2770. {
  2771. return GetDPIObj()->Scale(m_rcCaption);
  2772. }
  2773. void CPaintManagerUI::SetCaptionRect(RECT& rcCaption)
  2774. {
  2775. m_rcCaption = rcCaption;
  2776. }
  2777. SIZE CPaintManagerUI::GetRoundCorner()
  2778. {
  2779. return GetDPIObj()->Scale(m_szRoundCorner);
  2780. }
  2781. void CPaintManagerUI::SetRoundCorner(int cx, int cy)
  2782. {
  2783. m_szRoundCorner.cx = cx;
  2784. m_szRoundCorner.cy = cy;
  2785. }
  2786. SIZE CPaintManagerUI::GetMinInfo()
  2787. {
  2788. return GetDPIObj()->Scale(m_szMinWindow);
  2789. }
  2790. void CPaintManagerUI::SetMinInfo(int cx, int cy)
  2791. {
  2792. ASSERT(cx >= 0 && cy >= 0);
  2793. m_szMinWindow.cx = cx;
  2794. m_szMinWindow.cy = cy;
  2795. }
  2796. SIZE CPaintManagerUI::GetMaxInfo()
  2797. {
  2798. return GetDPIObj()->Scale(m_szMaxWindow);
  2799. }
  2800. void CPaintManagerUI::SetMaxInfo(int cx, int cy)
  2801. {
  2802. ASSERT(cx >= 0 && cy >= 0);
  2803. m_szMaxWindow.cx = cx;
  2804. m_szMaxWindow.cy = cy;
  2805. }
  2806. bool CPaintManagerUI::IsShowUpdateRect()
  2807. {
  2808. return m_bShowUpdateRect;
  2809. }
  2810. void CPaintManagerUI::SetShowUpdateRect(bool show)
  2811. {
  2812. m_bShowUpdateRect = show;
  2813. }
  2814. bool CPaintManagerUI::IsNoActivate()
  2815. {
  2816. return m_bNoActivate;
  2817. }
  2818. void CPaintManagerUI::SetNoActivate(bool bNoActivate)
  2819. {
  2820. m_bNoActivate = bNoActivate;
  2821. }
  2822. BYTE CPaintManagerUI::GetOpacity() const
  2823. {
  2824. return m_nOpacity;
  2825. }
  2826. void CPaintManagerUI::SetOpacity(BYTE nOpacity)
  2827. {
  2828. m_nOpacity = nOpacity;
  2829. if (m_hWndPaint != NULL)
  2830. {
  2831. typedef BOOL(__stdcall* PFUNCSETLAYEREDWINDOWATTR)(HWND, COLORREF, BYTE, DWORD);
  2832. PFUNCSETLAYEREDWINDOWATTR fSetLayeredWindowAttributes = NULL;
  2833. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  2834. if (hUser32)
  2835. {
  2836. fSetLayeredWindowAttributes =
  2837. (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
  2838. if (fSetLayeredWindowAttributes == NULL) return;
  2839. }
  2840. DWORD dwStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  2841. DWORD dwNewStyle = dwStyle;
  2842. if (nOpacity >= 0 && nOpacity < 256) dwNewStyle |= WS_EX_LAYERED;
  2843. else dwNewStyle &= ~WS_EX_LAYERED;
  2844. if (dwStyle != dwNewStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewStyle);
  2845. fSetLayeredWindowAttributes(m_hWndPaint, 0, nOpacity, LWA_ALPHA);
  2846. }
  2847. }
  2848. bool CPaintManagerUI::IsLayered()
  2849. {
  2850. return m_bLayered;
  2851. }
  2852. void CPaintManagerUI::SetLayered(bool bLayered)
  2853. {
  2854. if (m_hWndPaint != NULL && bLayered != m_bLayered)
  2855. {
  2856. UINT uStyle = GetWindowStyle(m_hWndPaint);
  2857. if ((uStyle & WS_CHILD) != 0) return;
  2858. if (g_fUpdateLayeredWindow == NULL)
  2859. {
  2860. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  2861. if (hUser32)
  2862. {
  2863. g_fUpdateLayeredWindow =
  2864. (PFUNCUPDATELAYEREDWINDOW)::GetProcAddress(hUser32, "UpdateLayeredWindow");
  2865. if (g_fUpdateLayeredWindow == NULL) return;
  2866. }
  2867. }
  2868. m_bLayered = bLayered;
  2869. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  2870. Invalidate();
  2871. }
  2872. }
  2873. RECT& CPaintManagerUI::GetLayeredInset()
  2874. {
  2875. return m_rcLayeredInset;
  2876. }
  2877. void CPaintManagerUI::SetLayeredInset(RECT& rcLayeredInset)
  2878. {
  2879. m_rcLayeredInset = rcLayeredInset;
  2880. m_bLayeredChanged = true;
  2881. Invalidate();
  2882. }
  2883. BYTE CPaintManagerUI::GetLayeredOpacity()
  2884. {
  2885. return m_nOpacity;
  2886. }
  2887. void CPaintManagerUI::SetLayeredOpacity(BYTE nOpacity)
  2888. {
  2889. m_nOpacity = nOpacity;
  2890. m_bLayeredChanged = true;
  2891. Invalidate();
  2892. }
  2893. LPCTSTR CPaintManagerUI::GetLayeredImage()
  2894. {
  2895. return m_diLayered.sDrawString;
  2896. }
  2897. void CPaintManagerUI::SetLayeredImage(LPCTSTR pstrImage)
  2898. {
  2899. m_diLayered.sDrawString = pstrImage;
  2900. RECT rcNull = { 0 };
  2901. CRenderEngine::DrawImageInfo(NULL, this, rcNull, rcNull, &m_diLayered);
  2902. m_bLayeredChanged = true;
  2903. Invalidate();
  2904. }
  2905. CShadowUI* CPaintManagerUI::GetShadow()
  2906. {
  2907. return &m_shadow;
  2908. }
  2909. void CPaintManagerUI::SetUseGdiplusText(bool bUse)
  2910. {
  2911. m_bUseGdiplusText = bUse;
  2912. }
  2913. bool CPaintManagerUI::IsUseGdiplusText() const
  2914. {
  2915. return m_bUseGdiplusText;
  2916. }
  2917. void CPaintManagerUI::SetGdiplusTextRenderingHint(int trh)
  2918. {
  2919. m_trh = trh;
  2920. }
  2921. int CPaintManagerUI::GetGdiplusTextRenderingHint() const
  2922. {
  2923. return m_trh;
  2924. }
  2925. bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  2926. {
  2927. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  2928. {
  2929. bool bHandled = false;
  2930. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  2931. if (bHandled)
  2932. {
  2933. lRes = lResult;
  2934. return true;
  2935. }
  2936. }
  2937. switch (uMsg)
  2938. {
  2939. case WM_KEYDOWN:
  2940. {
  2941. // Tabbing between controls
  2942. if (wParam == VK_TAB)
  2943. {
  2944. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("RichEditUI")) != NULL)
  2945. {
  2946. if (static_cast<CRichEditUI*>(m_pFocus)->IsWantTab()) return false;
  2947. }
  2948. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("WkeWebkitUI")) != NULL)
  2949. {
  2950. return false;
  2951. }
  2952. SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
  2953. return false;
  2954. }
  2955. }
  2956. break;
  2957. case WM_SYSCHAR:
  2958. {
  2959. // Handle ALT-shortcut key-combinations
  2960. FINDSHORTCUT fs = { 0 };
  2961. fs.ch = toupper((int)wParam);
  2962. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST);
  2963. if (pControl != NULL)
  2964. {
  2965. pControl->SetFocus();
  2966. pControl->Activate();
  2967. return true;
  2968. }
  2969. }
  2970. break;
  2971. case WM_SYSKEYDOWN:
  2972. {
  2973. if (m_pFocus != NULL)
  2974. {
  2975. TEventUI event = { 0 };
  2976. event.Type = UIEVENT_SYSKEY;
  2977. event.chKey = (TCHAR)wParam;
  2978. event.ptMouse = m_ptLastMousePos;
  2979. event.wKeyState = MapKeyState();
  2980. event.dwTimestamp = ::GetTickCount();
  2981. m_pFocus->Event(event);
  2982. }
  2983. }
  2984. break;
  2985. }
  2986. return false;
  2987. }
  2988. bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  2989. {
  2990. if (m_hWndPaint == NULL) return false;
  2991. // ------------------------------------------------------------------
  2992. // ------------------------------------------------------------------
  2993. // 触摸状态超时自愈(防“窗口突然完全点不动”):
  2994. // TOUCHDOWN 会置起 m_pEventTouch,合成点击后会置起 m_bSuppressPromotedTouchMouse;
  2995. // 若对应的 TOUCHUP / 提升的 WM_LBUTTONUP 因故丢失(手势被系统中断、激活或前台被抢、
  2996. // 窗口被遮挡、消息被别处吞掉等),这两个状态会永久残留 → 之后所有提升的鼠标消息都被
  2997. // 当成“触摸重复”吞掉,表现为“点着点着就完全没反应了”。这里粗粒度复位保证能自愈。
  2998. //
  2999. // ⚠️ 计时基准的优先级:m_dwTouchDownTick(本次手势的"按下"时刻)优先,
  3000. // 退化到 m_dwSuppressTick(抑制位被置的时刻)。这是**有意**的设计:
  3001. // 手势一开始 m_pEventTouch 就被置起,用"按下时刻"计时才能真的在 3 秒内自愈;
  3002. // 若只按 m_dwSuppressTick(合成点击后才置),TOUCHUP 丢失时它可能一直是 0,
  3003. // 条件永远不成立 ⇒ 状态永久残留 ⇒【所有窗口点击彻底失效】。这是实测踩过的坑。
  3004. //
  3005. // ⚠️⚠️⚠️【真机 bug 根治点:模态期间绝不自愈】⚠️⚠️⚠️
  3006. //
  3007. // 现象(Win10):点商品控件弹属性框;3 秒内点"选好了"正常;
  3008. // 超过 3 秒再点"选好了",弹框关掉的同时会**透点**到背后那个商品控件。
  3009. // Win7 上对应的现象是"弹框刚出来就被自动点掉 / 咚一声"。
  3010. //
  3011. // 成因:这段超时**只看时间**,不看"当前是不是模态开着"。
  3012. // · 点商品控件的那个手势在 tap-commit 时置起 m_bSuppressPromotedTouchMouse
  3013. // (用途:吞掉这次手势随后被系统"提升"出来的重复鼠标消息);
  3014. // · 紧接着回调里 ShowModal() 开了**嵌套模态循环**,本次手势的残留提升消息
  3015. // 只能等弹框关闭后才被投递出来;
  3016. // · 若用户在弹框里停留超过 3 秒,这段超时就会先把抑制位**清掉**;
  3017. // · 等弹框一关,那条残留的提升消息终于投出来时,抑制位已经没了 ⇒ **放行**
  3018. // ⇒ 它就是"第二次点击",于是自动点了弹框里的按钮 / 咚 / 透点到背后控件。
  3019. //
  3020. // 也就是说:模态开启期间,这些状态**本来就是"故意冻结"的**(在等模态循环返回),
  3021. // 不是"卡住了"。用超时去清它,等于亲手拆掉唯一的防线 —— 这正是前两轮没改好的地方。
  3022. //
  3023. // 修法:模态存续期间**跳过**本超时(保留状态),等模态结束后再让超时正常兜底。
  3024. // 判据用 GetModalWindow():真模态在 __DialogProc 里登记、__DialogWndProc 的
  3025. // WM_NCDESTROY 里清除,生命周期与"嵌套循环是否还在跑"严格一致。
  3026. // 本窗口自己就是当前模态弹框时同样跳过(它也在等自己的循环结束)。
  3027. //
  3028. // 配套:tap-commit 分支**不应**再清 m_dwTouchDownTick(本函数已不再在模态期间
  3029. // 依赖它),去掉那两处会让基准语义更直白:抑制位从置位起算 3 秒,
  3030. // 而模态期间计时整体暂停。
  3031. // ==================================================================
  3032. // ⚠️⚠️⚠️【已彻底删除:TOUCH-STATE 3000ms 超时自愈】⚠️⚠️⚠️
  3033. //
  3034. // 用户明确要求:「这里为什么要加个3秒的逻辑?能不能删除这个逻辑?
  3035. // 不要时间戳,完全根据状态来判断。」
  3036. //
  3037. // 这里原本有一段:若 (Now - 基准) > 3000ms,就把 m_pEventTouch /
  3038. // m_bSuppressPromotedTouchMouse / m_dwTouchDownTick / m_bTouchSlideActive
  3039. // 全部强制清掉,目的是"防 TOUCHUP 丢失导致状态永久悬空"。
  3040. //
  3041. // **它是纯有害的,已整段删除。** 理由(三条,任何一条都足以判它死刑):
  3042. //
  3043. // ① 它本身就是"3 秒透点"的成因。
  3044. // 点商品控件 → 手势在 tap-commit 置起 m_bSuppressPromotedTouchMouse
  3045. // (用途:吞掉这次手势随后被系统"提升"出来的重复鼠标消息)→
  3046. // 紧接着回调里 ShowModal() 开**嵌套模态循环**,残留的提升消息只能等
  3047. // 弹框关闭后才被投递出来。若用户在弹框里停留超过 3 秒,这段超时就会
  3048. // 先把抑制位**清掉** ⇒ 弹框一关,那条残留消息终于投出来时抑制位已经没了
  3049. // ⇒ **放行** ⇒ 它就是"第二次点击" ⇒ **透点到背后的商品控件**。
  3050. // 这精确解释了用户看到的「3 秒内正常、超过 3 秒就透点」。
  3051. //
  3052. // ② 它"自愈"的那些状态**根本不需要自愈 —— 泄漏是不可能的**。
  3053. // 逐条核对(这就是"完全根据状态判断"的可行性证明):
  3054. // · m_bSuppressPromotedTouchMouse:置真只发生在**已合成点击**的分支
  3055. // (OnTouchInput / OnPointerInput 的 UP)。合成点击是一次真实的
  3056. // BUTTONDOWN + BUTTONUP **配对**派发,系统必然随后投递配对的
  3057. // WM_LBUTTONDOWN/UP;MessageHandler 的拦截块收到 UP 时就会把它清掉
  3058. // (见 PROMOTED-MOUSE swallowed 那段:`if (uMsg == WM_LBUTTONUP) ... = false;`)。
  3059. // 即便那对提升消息真的丢了,下次手势正常点击时也必然被重置。
  3060. // · m_pEventTouch:由 UP / CAPTURECHANGED 清,且下次 DOWN 时
  3061. // BeginTouchSlideGesture 无条件置 NULL 后重建 ⇒ 不可能跨手势残留。
  3062. // · m_dwTouchDownTick / m_dwSuppressTick:纯时间戳,无功能语义
  3063. // (唯一的消费者就是这段被删掉的超时)。
  3064. // · m_bTouchSlideActive:由 EndTouchSlideGesture 置假,且下次 Begin 重建。
  3065. // ⇒ 当年加它,是因为**真正的泄漏源在别处**(释放捕获时序、
  3066. // AttachPaintWindow 漏清输入态等,均已单独修复)。
  3067. // 那两处修好之后,这个超时就成了纯粹的"定时炸弹"。
  3068. //
  3069. // ③ 它是"周期性"触发的 —— 判断块在 MessageHandler 开头,每条窗口消息都会跑。
  3070. // 所以"偶发"其实一点都不偶发:任何一条消息到达且距基准 >3 秒,状态就被清。
  3071. // 这也解释了为什么这个 bug 如此容易复现。
  3072. //
  3073. // 【删除后的依据(全部是状态,没有时间)】
  3074. // · 手势进行中 → m_pEventTouch != NULL / m_bTouchSlideActive
  3075. // · 刚合成过点击 → m_bSuppressPromotedTouchMouse(由配对的提升 UP 销账)
  3076. // · 模态是否存续 → GetModalWindow()(在 __DialogProc 登记、WM_NCDESTROY 清除)
  3077. // · 抬起/取消/捕获被夺 → TOUCHUP / POINTERUP / CAPTURECHANGED 各自清干净
  3078. // 没有任何一条依赖"过了多久"。
  3079. // ==================================================================
  3080. // 当前是否处于"模态存续中"。保留这个查询仅为下方**指针通道**的手势自愈
  3081. // 提供同样的"模态期间冻结"语义(见下),不再用于清触摸抑制位。
  3082. const HWND hModalNow = CPaintManagerUI::GetModalWindow();
  3083. const bool bModalAlive = (hModalNow != NULL && ::IsWindow(hModalNow));
  3084. // ==================================================================
  3085. // ⚠️⚠️⚠️【已彻底删除:POINTER-GESTURE 3000ms 超时自愈】⚠️⚠️⚠️
  3086. //
  3087. // 与上面被删的 TOUCH-STATE 超时是**同一类错误**,一并删除。
  3088. // 原文:若 (Now - m_dwPointerDownTick) > 3000ms,强制把
  3089. // m_bPointerGestureActive / m_dwActivePointerId / m_bTouchSlideActive /
  3090. // m_pEventTouch 全部清掉。
  3091. //
  3092. // 为什么它同样是纯有害的:
  3093. //
  3094. // ① 【致命】模态存续期间它会把 m_pEventTouch 清成 NULL ——
  3095. // 而 m_pEventTouch 正是"刚合成过点击、必须吞掉随后那条提升鼠标消息"
  3096. // 这个**授权标记**。弹框停留 >3 秒 ⇒ 标记被清 ⇒ 弹框关闭瞬间那条残留的
  3097. // 提升鼠标消息漏网 ⇒ 透点到背后的商品控件(Win10 那个 bug 的另一半成因)。
  3098. //
  3099. // ② 它自愈的状态同样**不会泄漏**(和上面一样,逐条可查):
  3100. // · m_bPointerGestureActive:UP / CAPTURECHANGED 清,且下次 DOWN 时
  3101. // `if (m_bPointerGestureActive && id 相同) return true;` 只挡**同一 id**
  3102. // 的重复 DOWN,换了 id 会正常重建 ⇒ 不会永久卡死。
  3103. // · m_dwActivePointerId / m_dwPointerDownTick:纯记账字段,无功能语义。
  3104. // · m_bTouchSlideActive / m_pEventTouch:由 EndTouchSlideGesture 与
  3105. // 下次 BeginTouchSlideGesture 负责,不依赖时间。
  3106. //
  3107. // ③ 当年加它的理由是"WM_POINTERUP 可能丢失导致永久点不动"。
  3108. // 那个症状的**真因**已单独修复(见 WM_POINTERUP 让路把 UP 一起吞掉
  3109. // 导致状态永久为真 —— 现在的规则是"UP/UPDATE 一律送到 OnPointerInput,
  3110. // 绝不吞 UP")。真因修好后,这个超时就成了定时炸弹。
  3111. //
  3112. // 【删除后的依据(全部是状态)】
  3113. // · 本次指针手势的归属 → m_bPointerGestureActive + m_dwActivePointerId
  3114. // · 手势是否已结束 → DUI_WM_POINTERUP(无条件走完全程)
  3115. // · 捕获是否被夺 → DUI_WM_POINTERCAPTURECHANGED(无条件清)
  3116. // · 是否处于模态 → bModalAlive(模态期间本来就不该有任何手势状态变化)
  3117. // ==================================================================
  3118. // 说明:bModalAlive 保留在作用域内,便于以后需要时按"状态"而不是"时间"做判断。
  3119. (void)bModalAlive;
  3120. if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK)
  3121. {
  3122. // ⚠️ 不要写成 ::IsPromotedTouchMouseMessage() —— 它定义在本文件的
  3123. // 匿名 namespace 内,加全局限定符会报 C2039(不是 global namespace 成员)。
  3124. const bool bPromotedNow = IsPromotedTouchMouseMessage();
  3125. if (bPromotedNow)
  3126. {
  3127. // 【诊断 · Combo 卡顿/要点好几下】每一条"提升出来的鼠标点击消息"都登记:
  3128. // 它的点位、以及能不能被"作废表决"命中(dupHit=1 才会被吞)。
  3129. // 判读:如果某一下点击之后出现 `dupHit=0` 的 DOWN,说明这条副本**没被吞**,
  3130. // 它会把主窗口重新激活(鼠标激活发生在进入窗口过程之前,任何 WndProc 闸门都拦不住)
  3131. // ⇒ 刚弹出的 Combo 下拉框收到 WM_KILLFOCUS ⇒ 立刻被关掉。
  3132. {
  3133. POINT ptDiag = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3134. POINT ptDiagScreen = ptDiag;
  3135. if (m_hWndPaint != NULL && ::IsWindow(m_hWndPaint))
  3136. ::ClientToScreen(m_hWndPaint, &ptDiagScreen);
  3137. DuiLibDiag::Log(_T("PROMOTED-MSG msg=0x%04X ptCli=%d,%d ptScreen=%d,%d dupPending=%d dupHit=%d"),
  3138. (unsigned)uMsg, ptDiag.x, ptDiag.y, ptDiagScreen.x, ptDiagScreen.y,
  3139. (int)(s_bPromotedMouseDuplicate ? 1 : 0),
  3140. (int)(IsPromotedMouseDuplicate(m_hWndPaint, ptDiag) ? 1 : 0));
  3141. }
  3142. // 【Combo 下拉框"点了不出来"】登记这一事实:**刚刚真的投递了一条提升鼠标点击**。
  3143. // 这一支只对 DOWN/UP/DBLCLK 进入(外层的 uMsg 判定),正是"触摸抬手之后
  3144. // 系统为同一次手势补投的那几条"。
  3145. // 消费点:CComboWnd::DecideAfterFocusLoss —— 下拉框用它来区分
  3146. // "焦点是被这次手势的回声抢走的(要忍)" 还是 "用户点了别处(要关框)"。
  3147. // 【自限】Win10 不产生提升鼠标消息 ⇒ 这一行永不执行 ⇒ 那边行为零变化。
  3148. s_bPromotedMouseClickJustSeen = true;
  3149. const bool bClickLike = (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP
  3150. || uMsg == WM_LBUTTONDBLCLK);
  3151. const bool bUpLike = (uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK);
  3152. // ==============================================================
  3153. // ★★【第二次合成点击 · 根治】第一道,也是唯一必需的一道闸 ★★
  3154. //
  3155. // 判据:本条提升消息,是不是"触摸通道刚刚处理过的那次手势"的副本。
  3156. // · 依据只有"触摸通道收到了这次手势"这一个事实 + 屏幕坐标吻合,
  3157. // **与模态边界 / 代数水位 / extra 指纹全都无关** ⇒ 对"关闭弹框
  3158. // 的那一次手势"同样有效(旧判据在 Win7 上唯一漏掉的就是它)。
  3159. // · 命中的处理:点击类一律吞(并且不建立候选点击);抬手类到达即销账。
  3160. // 移动类放行(不产生点击;仍需维持重绘/光标,悬浮态由"提升移动
  3161. // 不参与 hover"的总闸挡掉)。
  3162. //
  3163. // ⚠️ 必须放在下面"代数水位"那套**之前**:那套是按模态边界近似出来的
  3164. // 版本,在 Win7 上(extra 恒定 ⇒ 指纹失效;水位一次手势就追平)
  3165. // 必然漏掉"关闭弹框那一次"。本闸门是它的严格超集。
  3166. // 先不删旧的,等这两台机器都验过再决定去留。
  3167. // ==============================================================
  3168. {
  3169. POINT ptMsg = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3170. if (IsPromotedMouseDuplicate(m_hWndPaint, ptMsg) && bClickLike)
  3171. {
  3172. // 从根上不产生候选点击(抬手自然也不会派发)。
  3173. if (uMsg == WM_LBUTTONDOWN)
  3174. m_pEventClick = NULL;
  3175. if (m_bMouseCapture)
  3176. ReleaseCapture();
  3177. // 【悬浮态残留】把"抑制参考点"钉在本条坐标上:残留序列之后
  3178. // 系统还会补投一条 extra=0 的普通 MOVE,参考点不挪的话那条
  3179. // MOVE 会解除抑制并重建 hover。
  3180. s_bSuppressHoverAfterTouch = true;
  3181. m_bMouseTracking = false;
  3182. m_ptLastTouchPos = ptMsg;
  3183. SetLastTouchScreenPoint(ptMsg);
  3184. // 抬手类到达 ⇒ 这次手势的提升副本已配完 ⇒ 销账。
  3185. if (bUpLike)
  3186. DisarmPromotedMouseDuplicate();
  3187. return true;
  3188. }
  3189. }
  3190. }
  3191. else
  3192. {
  3193. // 【Combo 下拉框的判据源】这是一条**真正的鼠标**按键消息(extra 不带
  3194. // MOUSEEVENTF_FROMTOUCH 标记)⇒ 最近一次点击类输入不是触摸。
  3195. // 之后 GetLastInputScreenPoint() 会回到 `::GetCursorPos()` ——
  3196. // 鼠标下光标就是真值,与改动前逐字一致。
  3197. //
  3198. // 只在这里置假,不在 WM_MOUSEMOVE 里置:移动不构成"点击类输入",
  3199. // 而读取点(Combo 的焦点丢失判定)只会被"点击引发的激活"触发。
  3200. s_bLastInputWasTouch = false;
  3201. }
  3202. }
  3203. // ==================================================================
  3204. // ★★【模态背闸】弹框还开着时,背景窗口不处理任何"点击类"输入。
  3205. //
  3206. // 这是"点弹框的『选好了』→ 透传到主窗口商品卡"的**入口根治**,
  3207. // 覆盖鼠标通道(触摸通道的对应闸门见 OnPointerInput / OnTouchInput)。
  3208. //
  3209. // 为什么必须放在"选中点击目标"之前(即这里):
  3210. // 一旦放行到下面的原生鼠标分支,`m_pEventClick = FindControl(pt)` 就被建立了。
  3211. // 此后无论如何复核,那个候选点击都已经存在,抬手时就有被派发的机会。
  3212. // 在入口吃掉,等于**从根上不产生候选点击**。
  3213. //
  3214. // ⚠️ 只拦"点击类"(DOWN/UP/DBLCLK),**不拦** WM_MOUSEMOVE:
  3215. // 背景窗口仍需要 MOVE 来维持正常的重绘/光标逻辑,拦 MOVE 会带来其它回归、
  3216. // 收益为零。
  3217. //
  3218. // ==================================================================
  3219. if ((uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK)
  3220. && IsModalBackdropWindow(m_hWndPaint))
  3221. {
  3222. // 顺手作废可能残留的候选点击/捕获,避免抬手时被派发。
  3223. m_pEventClick = NULL;
  3224. if (m_bMouseCapture) ReleaseCapture();
  3225. return true;
  3226. }
  3227. // 触摸点击优先由 WM_TOUCH 状态机驱动 BUTTONDOWN/BUTTONUP。
  3228. // 只有当前 manager 已经收到本次 WM_TOUCH,或刚刚完成了触摸点击,
  3229. // 才拦截随后提升的鼠标消息。不能仅凭 FROMTOUCH 标记无条件拦截,
  3230. // 因为部分模态窗口只收到 Windows 提升的鼠标消息而没有收到 WM_TOUCH,
  3231. // 无条件拦截会导致模态窗口完全无法触摸点击。
  3232. //
  3233. // ⚠️ 注意这里的 return true 会【吞掉】消息、不让它进控件树。
  3234. // 只有当"确实有一次触摸手势在进行中/刚结束"时才该吞:
  3235. // · m_pEventTouch != NULL —— 本次手势已由 WM_TOUCH 接管
  3236. // · m_bSuppressPromotedTouchMouse —— 刚合成过点击,丢弃重复的提升鼠标
  3237. // 两个条件任一为假,都必须放行 —— 否则真实鼠标点击也会被吞("主窗口点不动")。
  3238. if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK)
  3239. {
  3240. if (m_pEventTouch != NULL || m_bSuppressPromotedTouchMouse)
  3241. {
  3242. // ⚠️ 这就是抑制位的**唯一的正常解除点**("配对销账"语义):
  3243. // 抬起类消息到手 ⇒ 本次手势那一对残留提升消息已经配完 ⇒ 授权作废。
  3244. // 从此不再有任何"超时自动清"的路径(那段 3000ms 自愈已整段删除)。
  3245. // 之所以能这么干,是因为"抬起"本身就是确定性的状态信号,
  3246. // 不必用时间去猜它还会不会来。
  3247. if (uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK)
  3248. {
  3249. m_bSuppressPromotedTouchMouse = false;
  3250. m_dwSuppressTick = 0;
  3251. }
  3252. return true;
  3253. }
  3254. }
  3255. // [触屏兼容] 不再过滤 Windows 为触摸模拟的鼠标消息(MOUSEEVENTF_FROMTOUCH)。
  3256. // 触摸的“点击”正来自这些模拟的 WM_LBUTTONDOWN/UP,由原生鼠标路径交给 CButtonUI 等控件
  3257. // Activate() 触发——而 DuiLib 的点击状态机依赖 WM_LBUTTONDOWN 设置 m_pEventClick,故绝不能
  3258. // 在鼠标分支吞掉这些模拟消息(之前那样做会导致触摸与鼠标点击全失效)。
  3259. // 为避免“拖拽=滚动”又“误点按钮”,改用 m_bTouchMoved:若本次手势发生位移,在 WM_LBUTTONUP 抑制点击。
  3260. // ------------------------------------------------------------------
  3261. // [对标 nim_duilib] WM_POINTER*(Win8+ 指针栈)归一化成鼠标消息。
  3262. //
  3263. // ⚠️ 这里的核心是【手势级让路】,不是"通道二选一"。改回二选一会立刻坏掉真模态弹框:
  3264. // 本台收银机上 WM_TOUCH 的贪婪归属权卡在主窗口(MSDN:收到第一条触摸消息后
  3265. // 所有触摸消息都发给该窗口,直到另一个窗口获得焦点),弹框被程序 SetFocus
  3266. // 而非触摸点出焦点 ⇒ 弹框永远收不到 WM_TOUCH,只能收到按命中投递的 WM_POINTER*。
  3267. // 所以指针通道必须始终开着,弹框才有输入源。
  3268. //
  3269. // 那怎么避免"两条通道产生两套 WM_LBUTTONDOWN/UP 把点击状态机打乱"(曾经导致
  3270. // 所有窗口点击全失效)?答案是:**同一时刻只让一条通道驱动**。
  3271. // · 指针先 DOWN ⇒ m_bPointerGestureActive=true,本次手势内 OnTouchInput 直接忽略 WM_TOUCH;
  3272. // · WM_TOUCH 先 DOWN ⇒ m_pEventTouch 置位,本次手势内这里拒绝指针;
  3273. // · 手势一结束(UP / 超时 / 捕获被夺)立刻解禁,下一个手势可以换通道。
  3274. // 让路只加在 UP 的"驱动点击"上:同一手势里两条通道的**按下**才是一对重复;
  3275. // UP/MOVE 一侧不加让路,避免某一侧的 UP 被误丢导致状态永久悬空。
  3276. // ⚠️ 【血的教训】曾经让路连 WM_POINTERUP 一起吞 —— UP 是唯一能解除
  3277. // m_bPointerGestureActive 的消息,吞掉它会让指针手势状态永久为真,
  3278. // 随后的 WM_POINTERDOWN 全被当成"重复按下"挡掉 ⇒ 整个窗口触摸点击全灭。
  3279. // 现在 UP/UPDATE 一律送到 OnPointerInput,由那里自行决定"只清状态"还是"派发点击"。
  3280. //
  3281. // 另外,只处理 DOWN/UP/UPDATE 三个真正驱动点击的消息;
  3282. // ENTER/LEAVE/ACTIVATE/HWHEEL/CAPTURECHANGED 交回系统(返回 false),绝不吞掉。
  3283. //
  3284. // 注意:本项目 _WIN32_WINNT=0x0601,WM_POINTER* 宏在编译期不可见,
  3285. // 只能用字面量常量区间判断(见文件头 PointerMsg 命名空间)。
  3286. // ------------------------------------------------------------------
  3287. if (m_bPointerNormalizeEnabled
  3288. && (uMsg == PointerMsg::DUI_WM_POINTERDOWN
  3289. || uMsg == PointerMsg::DUI_WM_POINTERUP
  3290. || uMsg == PointerMsg::DUI_WM_POINTERUPDATE))
  3291. {
  3292. // [NIM 风格] 这里**不再**做让路判定 —— 让路完全下沉到 OnPointerInput,
  3293. // 由 m_pEventTouch(WM_TOUCH 的占用标记)与 m_bPointerGestureActive 互斥决定。
  3294. // 原先在这里用时间戳预判让路,会导致"UP 被漏放/被多放"两类边界问题,
  3295. // 而 OnPointerInput 内部本就有完整的 UP 放行规则(它才是权威)。
  3296. //
  3297. // 三个消息一律委托,由 OnPointerInput 决定"吃掉"还是"放行":
  3298. // · DOWN/UPDATE 且 WM_TOUCH 已占用 ⇒ 返回 true(吃掉)
  3299. // · UP 永远返回 false(放行给系统收尾),但内部已清干净状态
  3300. if (OnPointerInput(uMsg, wParam, lParam))
  3301. {
  3302. lRes = 0;
  3303. return true;
  3304. }
  3305. }
  3306. // Cycle through listeners
  3307. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  3308. {
  3309. bool bHandled = false;
  3310. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  3311. if (bHandled)
  3312. {
  3313. lRes = lResult;
  3314. switch (uMsg)
  3315. {
  3316. case WM_MOUSEMOVE:
  3317. case WM_LBUTTONDOWN:
  3318. case WM_LBUTTONDBLCLK:
  3319. case WM_LBUTTONUP:
  3320. {
  3321. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3322. m_ptLastMousePos = pt;
  3323. }
  3324. break;
  3325. case WM_CONTEXTMENU:
  3326. case WM_MOUSEWHEEL:
  3327. {
  3328. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3329. ::ScreenToClient(m_hWndPaint, &pt);
  3330. m_ptLastMousePos = pt;
  3331. }
  3332. break;
  3333. }
  3334. return true;
  3335. }
  3336. }
  3337. if (m_bLayered)
  3338. {
  3339. switch (uMsg)
  3340. {
  3341. case WM_NCACTIVATE:
  3342. if (!::IsIconic(m_hWndPaint))
  3343. {
  3344. lRes = (wParam == 0) ? TRUE : FALSE;
  3345. return true;
  3346. }
  3347. break;
  3348. case WM_NCCALCSIZE:
  3349. case WM_NCPAINT:
  3350. lRes = 0;
  3351. return true;
  3352. }
  3353. }
  3354. // Custom handling of events
  3355. switch (uMsg)
  3356. {
  3357. case WM_APP + 1:
  3358. {
  3359. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++)
  3360. delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  3361. m_aDelayedCleanup.Empty();
  3362. m_bAsyncNotifyPosted = false;
  3363. TNotifyUI* pMsg = NULL;
  3364. while (pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify.GetAt(0)))
  3365. {
  3366. m_aAsyncNotify.Remove(0);
  3367. if (pMsg->pSender != NULL)
  3368. {
  3369. if (pMsg->pSender->OnNotify) pMsg->pSender->OnNotify(pMsg);
  3370. }
  3371. for (int j = 0; j < m_aNotifiers.GetSize(); j++)
  3372. {
  3373. static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);
  3374. }
  3375. delete pMsg;
  3376. }
  3377. }
  3378. break;
  3379. case WM_CLOSE:
  3380. {
  3381. // Make sure all matching "closing" events are sent
  3382. TEventUI event = { 0 };
  3383. event.ptMouse = m_ptLastMousePos;
  3384. event.wKeyState = MapKeyState();
  3385. event.dwTimestamp = ::GetTickCount();
  3386. if (m_pEventHover != NULL)
  3387. {
  3388. event.Type = UIEVENT_MOUSELEAVE;
  3389. event.pSender = m_pEventHover;
  3390. m_pEventHover->Event(event);
  3391. }
  3392. if (m_pEventClick != NULL)
  3393. {
  3394. event.Type = UIEVENT_BUTTONUP;
  3395. event.pSender = m_pEventClick;
  3396. m_pEventClick->Event(event);
  3397. }
  3398. if (m_pEventRClick != NULL)
  3399. {
  3400. event.Type = UIEVENT_RBUTTONUP;
  3401. event.pSender = m_pEventClick;
  3402. m_pEventRClick->Event(event);
  3403. }
  3404. SetFocus(NULL);
  3405. if (::GetActiveWindow() == m_hWndPaint)
  3406. {
  3407. HWND hwndParent = GetWindowOwner(m_hWndPaint);
  3408. if (hwndParent != NULL) ::SetFocus(hwndParent);
  3409. }
  3410. if (m_hwndTooltip != NULL)
  3411. {
  3412. ::DestroyWindow(m_hwndTooltip);
  3413. m_hwndTooltip = NULL;
  3414. }
  3415. }
  3416. break;
  3417. case WM_ERASEBKGND:
  3418. {
  3419. // We'll do the painting here...
  3420. lRes = 1;
  3421. }
  3422. return true;
  3423. case WM_PAINT:
  3424. {
  3425. if (m_pRoot == NULL)
  3426. {
  3427. PAINTSTRUCT ps = { 0 };
  3428. ::BeginPaint(m_hWndPaint, &ps);
  3429. CRenderEngine::DrawColor(m_hDcPaint, ps.rcPaint, 0xFF000000);
  3430. ::EndPaint(m_hWndPaint, &ps);
  3431. return true;
  3432. }
  3433. RECT rcClient = { 0 };
  3434. ::GetClientRect(m_hWndPaint, &rcClient);
  3435. RECT rcPaint = { 0 };
  3436. if (!::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE)) return true;
  3437. //if( m_bLayered ) {
  3438. // m_bOffscreenPaint = true;
  3439. // rcPaint = m_rcLayeredUpdate;
  3440. // if( ::IsRectEmpty(&m_rcLayeredUpdate) ) {
  3441. // PAINTSTRUCT ps = { 0 };
  3442. // ::BeginPaint(m_hWndPaint, &ps);
  3443. // ::EndPaint(m_hWndPaint, &ps);
  3444. // return true;
  3445. // }
  3446. // if( rcPaint.right > rcClient.right ) rcPaint.right = rcClient.right;
  3447. // if( rcPaint.bottom > rcClient.bottom ) rcPaint.bottom = rcClient.bottom;
  3448. // ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  3449. //}
  3450. //else {
  3451. // if( !::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE) ) return true;
  3452. //}
  3453. // Set focus to first control?
  3454. if (m_bFocusNeeded)
  3455. {
  3456. //修复新窗口自动切换焦点的问题
  3457. //SetNextTabControl();
  3458. m_bFocusNeeded = false;
  3459. }
  3460. SetPainting(true);
  3461. bool bNeedSizeMsg = false;
  3462. DWORD dwWidth = rcClient.right - rcClient.left;
  3463. DWORD dwHeight = rcClient.bottom - rcClient.top;
  3464. SetPainting(true);
  3465. if (m_bUpdateNeeded)
  3466. {
  3467. m_bUpdateNeeded = false;
  3468. if (!::IsRectEmpty(&rcClient) && !::IsIconic(m_hWndPaint))
  3469. {
  3470. if (m_pRoot->IsUpdateNeeded())
  3471. {
  3472. RECT rcRoot = rcClient;
  3473. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  3474. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  3475. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  3476. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  3477. m_hDcOffscreen = NULL;
  3478. m_hDcBackground = NULL;
  3479. m_hbmpOffscreen = NULL;
  3480. m_hbmpBackground = NULL;
  3481. if (m_bLayered)
  3482. {
  3483. rcRoot.left += m_rcLayeredInset.left;
  3484. rcRoot.top += m_rcLayeredInset.top;
  3485. rcRoot.right -= m_rcLayeredInset.right;
  3486. rcRoot.bottom -= m_rcLayeredInset.bottom;
  3487. }
  3488. m_pRoot->SetPos(rcRoot, true);
  3489. bNeedSizeMsg = true;
  3490. }
  3491. else
  3492. {
  3493. CControlUI* pControl = NULL;
  3494. m_aFoundControls.Empty();
  3495. m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST);
  3496. for (int it = 0; it < m_aFoundControls.GetSize(); it++)
  3497. {
  3498. pControl = static_cast<CControlUI*>(m_aFoundControls[it]);
  3499. pControl->SetPos(pControl->GetPos(), true);
  3500. }
  3501. bNeedSizeMsg = true;
  3502. }
  3503. // We'll want to notify the window when it is first initialized
  3504. // with the correct layout. The window form would take the time
  3505. // to submit swipes/animations.
  3506. if (m_bFirstLayout)
  3507. {
  3508. m_bFirstLayout = false;
  3509. SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWINIT, 0, 0, false);
  3510. if (m_bLayered && m_bLayeredChanged)
  3511. {
  3512. Invalidate();
  3513. SetPainting(false);
  3514. return true;
  3515. }
  3516. // 更新阴影窗口显示
  3517. m_shadow.Update(m_hWndPaint);
  3518. }
  3519. }
  3520. }
  3521. else if (m_bLayered && m_bLayeredChanged)
  3522. {
  3523. RECT rcRoot = rcClient;
  3524. if (m_pOffscreenBits) ::ZeroMemory(m_pOffscreenBits, (rcRoot.right - rcRoot.left)
  3525. * (rcRoot.bottom - rcRoot.top) * 4);
  3526. rcRoot.left += m_rcLayeredInset.left;
  3527. rcRoot.top += m_rcLayeredInset.top;
  3528. rcRoot.right -= m_rcLayeredInset.right;
  3529. rcRoot.bottom -= m_rcLayeredInset.bottom;
  3530. m_pRoot->SetPos(rcRoot, true);
  3531. }
  3532. if (m_bLayered)
  3533. {
  3534. DWORD dwExStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  3535. DWORD dwNewExStyle = dwExStyle | WS_EX_LAYERED;
  3536. if (dwExStyle != dwNewExStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewExStyle);
  3537. m_bOffscreenPaint = true;
  3538. UnionRect(&rcPaint, &rcPaint, &m_rcLayeredUpdate);
  3539. if (rcPaint.right > rcClient.right) rcPaint.right = rcClient.right;
  3540. if (rcPaint.bottom > rcClient.bottom) rcPaint.bottom = rcClient.bottom;
  3541. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  3542. }
  3543. //
  3544. // Render screen
  3545. //
  3546. // Prepare offscreen bitmap
  3547. if (m_bOffscreenPaint && m_hbmpOffscreen == NULL)
  3548. {
  3549. m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
  3550. m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (LPBYTE*)&m_pOffscreenBits);
  3551. ASSERT(m_hDcOffscreen);
  3552. ASSERT(m_hbmpOffscreen);
  3553. }
  3554. // Begin Windows paint
  3555. PAINTSTRUCT ps = { 0 };
  3556. ::BeginPaint(m_hWndPaint, &ps);
  3557. if (m_bOffscreenPaint)
  3558. {
  3559. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(m_hDcOffscreen, m_hbmpOffscreen);
  3560. int iSaveDC = ::SaveDC(m_hDcOffscreen);
  3561. if (m_bLayered)
  3562. {
  3563. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  3564. {
  3565. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  3566. {
  3567. int i = (y * dwWidth + x) * 4;
  3568. *(DWORD*)(&m_pOffscreenBits[i]) = 0;
  3569. }
  3570. }
  3571. }
  3572. m_pRoot->Paint(m_hDcOffscreen, rcPaint, NULL);
  3573. if (m_bLayered)
  3574. {
  3575. for (int i = 0; i < m_aNativeWindow.GetSize(); )
  3576. {
  3577. HWND hChildWnd = static_cast<HWND>(m_aNativeWindow[i]);
  3578. if (!::IsWindow(hChildWnd))
  3579. {
  3580. m_aNativeWindow.Remove(i);
  3581. m_aNativeWindowControl.Remove(i);
  3582. continue;
  3583. }
  3584. ++i;
  3585. if (!::IsWindowVisible(hChildWnd)) continue;
  3586. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  3587. RECT rcTemp = { 0 };
  3588. if (!::IntersectRect(&rcTemp, &rcPaint, &rcChildWnd)) continue;
  3589. COLORREF* pChildBitmapBits = NULL;
  3590. HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen);
  3591. HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap(hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, (BYTE**)&pChildBitmapBits);
  3592. ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4);
  3593. HBITMAP hOldChildBitmap = (HBITMAP) ::SelectObject(hChildMemDC, hChildBitmap);
  3594. ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED));
  3595. COLORREF* pChildBitmapBit;
  3596. for (LONG y = 0; y < rcChildWnd.bottom - rcChildWnd.top; y++)
  3597. {
  3598. for (LONG x = 0; x < rcChildWnd.right - rcChildWnd.left; x++)
  3599. {
  3600. pChildBitmapBit = pChildBitmapBits + y * (rcChildWnd.right - rcChildWnd.left) + x;
  3601. if (*pChildBitmapBit != 0x00000000) *pChildBitmapBit |= 0xff000000;
  3602. }
  3603. }
  3604. ::BitBlt(m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left,
  3605. rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY);
  3606. ::SelectObject(hChildMemDC, hOldChildBitmap);
  3607. ::DeleteObject(hChildBitmap);
  3608. ::DeleteDC(hChildMemDC);
  3609. }
  3610. }
  3611. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  3612. {
  3613. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  3614. pPostPaintControl->DoPostPaint(m_hDcOffscreen, rcPaint);
  3615. }
  3616. ::RestoreDC(m_hDcOffscreen, iSaveDC);
  3617. if (m_bLayered)
  3618. {
  3619. RECT rcWnd = { 0 };
  3620. ::GetWindowRect(m_hWndPaint, &rcWnd);
  3621. if (!m_diLayered.sDrawString.IsEmpty())
  3622. {
  3623. DWORD dwWidth = rcClient.right - rcClient.left;
  3624. DWORD dwHeight = rcClient.bottom - rcClient.top;
  3625. RECT rcLayeredClient = rcClient;
  3626. rcLayeredClient.left += m_rcLayeredInset.left;
  3627. rcLayeredClient.top += m_rcLayeredInset.top;
  3628. rcLayeredClient.right -= m_rcLayeredInset.right;
  3629. rcLayeredClient.bottom -= m_rcLayeredInset.bottom;
  3630. COLORREF* pOffscreenBits = (COLORREF*)m_pOffscreenBits;
  3631. COLORREF* pBackgroundBits = m_pBackgroundBits;
  3632. BYTE A = 0;
  3633. BYTE R = 0;
  3634. BYTE G = 0;
  3635. BYTE B = 0;
  3636. if (!m_diLayered.sDrawString.IsEmpty())
  3637. {
  3638. if (m_hbmpBackground == NULL)
  3639. {
  3640. m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint);
  3641. m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (BYTE**)&m_pBackgroundBits);
  3642. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  3643. ::SelectObject(m_hDcBackground, m_hbmpBackground);
  3644. CRenderClip clip;
  3645. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  3646. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  3647. }
  3648. else if (m_bLayeredChanged)
  3649. {
  3650. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  3651. CRenderClip clip;
  3652. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  3653. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  3654. }
  3655. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  3656. {
  3657. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  3658. {
  3659. pOffscreenBits = (COLORREF*)(m_pOffscreenBits + y * dwWidth + x);
  3660. pBackgroundBits = m_pBackgroundBits + y * dwWidth + x;
  3661. A = (BYTE)((*pBackgroundBits) >> 24);
  3662. R = (BYTE)((*pOffscreenBits) >> 16) * A / 255;
  3663. G = (BYTE)((*pOffscreenBits) >> 8) * A / 255;
  3664. B = (BYTE)(*pOffscreenBits) * A / 255;
  3665. *pOffscreenBits = RGB(B, G, R) + ((DWORD)A << 24);
  3666. }
  3667. }
  3668. }
  3669. }
  3670. else
  3671. {
  3672. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  3673. {
  3674. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  3675. {
  3676. int i = (y * dwWidth + x) * 4;
  3677. if ((m_pOffscreenBits[i + 3] == 0) && (m_pOffscreenBits[i + 0] != 0 || m_pOffscreenBits[i + 1] != 0 || m_pOffscreenBits[i + 2] != 0))
  3678. m_pOffscreenBits[i + 3] = 255;
  3679. }
  3680. }
  3681. }
  3682. BLENDFUNCTION bf = { AC_SRC_OVER, 0, m_nOpacity, AC_SRC_ALPHA };
  3683. POINT ptPos = { rcWnd.left, rcWnd.top };
  3684. SIZE sizeWnd = { dwWidth, dwHeight };
  3685. POINT ptSrc = { 0, 0 };
  3686. g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
  3687. }
  3688. else
  3689. {
  3690. ::BitBlt(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY);
  3691. }
  3692. ::SelectObject(m_hDcOffscreen, hOldBitmap);
  3693. if (m_bShowUpdateRect && !m_bLayered)
  3694. {
  3695. HPEN hOldPen = (HPEN)::SelectObject(m_hDcPaint, m_hUpdateRectPen);
  3696. ::SelectObject(m_hDcPaint, ::GetStockObject(HOLLOW_BRUSH));
  3697. ::Rectangle(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
  3698. ::SelectObject(m_hDcPaint, hOldPen);
  3699. }
  3700. }
  3701. else
  3702. {
  3703. // A standard paint job
  3704. int iSaveDC = ::SaveDC(m_hDcPaint);
  3705. m_pRoot->Paint(m_hDcPaint, rcPaint, NULL);
  3706. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  3707. {
  3708. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  3709. pPostPaintControl->DoPostPaint(m_hDcPaint, rcPaint);
  3710. }
  3711. ::RestoreDC(m_hDcPaint, iSaveDC);
  3712. }
  3713. // All Done!
  3714. ::EndPaint(m_hWndPaint, &ps);
  3715. // 绘制结束
  3716. SetPainting(false);
  3717. m_bLayeredChanged = false;
  3718. if (m_bUpdateNeeded) Invalidate();
  3719. // 发送窗口大小改变消息
  3720. if (bNeedSizeMsg)
  3721. {
  3722. this->SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWSIZE, 0, 0, true);
  3723. }
  3724. return true;
  3725. }
  3726. case WM_PRINTCLIENT:
  3727. {
  3728. if (m_pRoot == NULL) break;
  3729. RECT rcClient;
  3730. ::GetClientRect(m_hWndPaint, &rcClient);
  3731. HDC hDC = (HDC)wParam;
  3732. int save = ::SaveDC(hDC);
  3733. m_pRoot->Paint(hDC, rcClient, NULL);
  3734. if ((lParam & PRF_CHILDREN) != 0)
  3735. {
  3736. HWND hWndChild = ::GetWindow(m_hWndPaint, GW_CHILD);
  3737. while (hWndChild != NULL)
  3738. {
  3739. RECT rcPos = { 0 };
  3740. ::GetWindowRect(hWndChild, &rcPos);
  3741. ::MapWindowPoints(HWND_DESKTOP, m_hWndPaint, reinterpret_cast<LPPOINT>(&rcPos), 2);
  3742. ::SetWindowOrgEx(hDC, -rcPos.left, -rcPos.top, NULL);
  3743. ::SendMessage(hWndChild, WM_PRINT, wParam, lParam | PRF_NONCLIENT);
  3744. hWndChild = ::GetWindow(hWndChild, GW_HWNDNEXT);
  3745. }
  3746. }
  3747. ::RestoreDC(hDC, save);
  3748. }
  3749. break;
  3750. case WM_GETMINMAXINFO:
  3751. {
  3752. MONITORINFO Monitor = {};
  3753. Monitor.cbSize = sizeof(Monitor);
  3754. ::GetMonitorInfo(::MonitorFromWindow(m_hWndPaint, MONITOR_DEFAULTTOPRIMARY), &Monitor);
  3755. RECT rcWork = Monitor.rcWork;
  3756. if (Monitor.dwFlags != MONITORINFOF_PRIMARY)
  3757. {
  3758. ::OffsetRect(&rcWork, -rcWork.left, -rcWork.top);
  3759. }
  3760. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  3761. if (m_szMinWindow.cx > 0) lpMMI->ptMinTrackSize.x = m_szMinWindow.cx;
  3762. if (m_szMinWindow.cy > 0) lpMMI->ptMinTrackSize.y = m_szMinWindow.cy;
  3763. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxTrackSize.x = m_szMaxWindow.cx;
  3764. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxTrackSize.y = m_szMaxWindow.cy;
  3765. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxSize.x = m_szMaxWindow.cx;
  3766. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxSize.y = m_szMaxWindow.cy;
  3767. }
  3768. break;
  3769. case WM_SIZE:
  3770. {
  3771. if (m_pFocus != NULL)
  3772. {
  3773. TEventUI event = { 0 };
  3774. event.Type = UIEVENT_WINDOWSIZE;
  3775. event.pSender = m_pFocus;
  3776. event.dwTimestamp = ::GetTickCount();
  3777. m_pFocus->Event(event);
  3778. }
  3779. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  3780. }
  3781. return true;
  3782. case WM_TIMER:
  3783. {
  3784. for (int i = 0; i < m_aTimers.GetSize(); i++)
  3785. {
  3786. const TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  3787. if (pTimer->hWnd == m_hWndPaint &&
  3788. pTimer->uWinTimer == LOWORD(wParam) &&
  3789. pTimer->bKilled == false)
  3790. {
  3791. TEventUI event = { 0 };
  3792. event.Type = UIEVENT_TIMER;
  3793. event.pSender = pTimer->pSender;
  3794. event.dwTimestamp = ::GetTickCount();
  3795. event.ptMouse = m_ptLastMousePos;
  3796. event.wKeyState = MapKeyState();
  3797. event.wParam = pTimer->nLocalID;
  3798. event.lParam = lParam;
  3799. pTimer->pSender->Event(event);
  3800. break;
  3801. }
  3802. }
  3803. }
  3804. break;
  3805. case WM_MOUSEHOVER:
  3806. {
  3807. if (s_bSuppressHoverAfterTouch) return true;
  3808. m_bMouseTracking = false;
  3809. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3810. CControlUI* pHover = FindControl(pt);
  3811. if (pHover == NULL) break;
  3812. // Generate mouse hover event
  3813. if (m_pEventHover != NULL)
  3814. {
  3815. TEventUI event = { 0 };
  3816. event.Type = UIEVENT_MOUSEHOVER;
  3817. event.pSender = m_pEventHover;
  3818. event.wParam = wParam;
  3819. event.lParam = lParam;
  3820. event.dwTimestamp = ::GetTickCount();
  3821. event.ptMouse = pt;
  3822. event.wKeyState = MapKeyState();
  3823. m_pEventHover->Event(event);
  3824. }
  3825. // Create tooltip information
  3826. CDuiString sToolTip = pHover->GetToolTip();
  3827. if (sToolTip.IsEmpty()) return true;
  3828. ::ZeroMemory(&m_ToolTip, sizeof(TOOLINFO));
  3829. m_ToolTip.cbSize = sizeof(TOOLINFO);
  3830. m_ToolTip.uFlags = TTF_IDISHWND;
  3831. m_ToolTip.hwnd = m_hWndPaint;
  3832. m_ToolTip.uId = (UINT_PTR)m_hWndPaint;
  3833. m_ToolTip.hinst = m_hInstance;
  3834. m_ToolTip.lpszText = const_cast<LPTSTR>((LPCTSTR)sToolTip);
  3835. m_ToolTip.rect = pHover->GetPos();
  3836. if (m_hwndTooltip == NULL)
  3837. {
  3838. m_hwndTooltip = ::CreateWindowEx(0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hWndPaint, NULL, m_hInstance, NULL);
  3839. ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip);
  3840. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  3841. }
  3842. if (!::IsWindowVisible(m_hwndTooltip))
  3843. {
  3844. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  3845. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  3846. }
  3847. }
  3848. return true;
  3849. case WM_MOUSELEAVE:
  3850. {
  3851. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  3852. // 触屏抬起刚清过悬浮态时,不要执行下面这段“自回发 WM_MOUSEMOVE”:
  3853. // 光标通常仍在窗口内 → 会立刻重建悬浮态,导致“悬浮态不消失/多控件同时悬浮”。
  3854. if (!s_bSuppressHoverAfterTouch && m_bMouseTracking)
  3855. {
  3856. POINT pt = { 0 };
  3857. RECT rcWnd = { 0 };
  3858. ::GetCursorPos(&pt);
  3859. ::GetWindowRect(m_hWndPaint, &rcWnd);
  3860. if (!::IsIconic(m_hWndPaint) && ::GetActiveWindow() == m_hWndPaint && ::PtInRect(&rcWnd, pt))
  3861. {
  3862. if (::SendMessage(m_hWndPaint, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)) == HTCLIENT)
  3863. {
  3864. ::ScreenToClient(m_hWndPaint, &pt);
  3865. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
  3866. }
  3867. else
  3868. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  3869. }
  3870. else
  3871. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  3872. }
  3873. m_bMouseTracking = false;
  3874. }
  3875. break;
  3876. case WM_MOUSEMOVE:
  3877. {
  3878. const bool bPromotedTouchMove = IsPromotedTouchMouseMessage();
  3879. if (bPromotedTouchMove && m_pEventTouch != NULL)
  3880. {
  3881. POINT ptTouch = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3882. const int kTouchSlop = 8;
  3883. const int dxTouch = ptTouch.x - m_ptTouchStart.x;
  3884. const int dyTouch = ptTouch.y - m_ptTouchStart.y;
  3885. if (dxTouch > kTouchSlop || dxTouch < -kTouchSlop
  3886. || dyTouch > kTouchSlop || dyTouch < -kTouchSlop)
  3887. m_bTouchMoved = true;
  3888. m_ptLastMousePos = ptTouch;
  3889. // [WM_TOUCH 归属权] 这条被吞掉的"触摸提升鼠标移动"其实是系统
  3890. // 用来触发 WM_TOUCH 翻译的信号(见 UIManager.h 的长注释)。
  3891. // 吞掉它没问题,但必须补一次原窗口过程的副作用,
  3892. // 否则本窗口(尤其 #32770 真模态弹框)后续再也收不到 WM_TOUCH。
  3893. RelayDefWindowProc(uMsg, wParam, lParam, _T("promoted-touch-move/tracking"));
  3894. return true;
  3895. }
  3896. if (s_bSuppressHoverAfterTouch)
  3897. {
  3898. // [第十一轮修正] 这里曾经无条件丢弃消息(return true)。
  3899. // 后果:弹框弹出时 AttachPaintWindow 会置起本抑制位(为了让新弹框
  3900. // 上不残留旧窗口的悬浮态),但**新弹框自己的 WM_MOUSEMOVE 也被
  3901. // 一起丢掉了** —— 它的 m_ptLastMousePos 再也得不到更新
  3902. // ⇒ 用户停手 >1 秒后第一次移动时累积位移巨大
  3903. // ⇒ bNeedDrag 为真、且 m_bDragMode 为真时触发意外的 DoDragDrop。
  3904. // 现在改为"只在真的还在同一个触摸点上时丢弃",其余情况放行 ——
  3905. // 悬浮态保护由下方 3561 行那套 ±8px 判据继续负责(它本来就是
  3906. // 为这个目的写的),这里只是提前把 m_ptLastMousePos 跟住。
  3907. POINT ptSup = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3908. POINT ptLast = m_ptLastMousePos;
  3909. m_ptLastMousePos = ptSup;
  3910. const int dxSup = ptSup.x - ptLast.x;
  3911. const int dySup = ptSup.y - ptLast.y;
  3912. if (dxSup <= 8 && dxSup >= -8 && dySup <= 8 && dySup >= -8)
  3913. {
  3914. // [WM_TOUCH 归属权] 同上:抬手后抑制悬浮复活时丢弃的合成移动,
  3915. // 也必须补调一次,否则 WM_TOUCH 翻译链会在这段时间里断掉。
  3916. RelayDefWindowProc(uMsg, wParam, lParam, _T("suppress-hover-after-touch"));
  3917. return true;
  3918. }
  3919. // 明显移动 ⇒ 抑制期结束,落到下面走正常的鼠标移动流程。
  3920. }
  3921. if ((INT_PTR)lParam == -1)
  3922. break;
  3923. POINT ptCheck = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3924. if (s_bSuppressHoverAfterTouch)
  3925. {
  3926. // 合成消息通常仍停在触摸结束点;只有明显离开该点的鼠标移动
  3927. // 才能重新建立鼠标悬浮语义。
  3928. //
  3929. // ⚠️⚠️ 这里有两个**必须同时成立**的前提,缺一个就会让"点『选好了』
  3930. // 关掉弹框后,背后商品卡保持悬浮态不消失"复现。真机日志两次实证:
  3931. //
  3932. // ① 参考点必须换算到**屏幕坐标**再比 —— lParam 是"**接收窗口**的
  3933. // 客户区坐标",而触摸可能发生在**另一个窗口**里。
  3934. // 用户点弹框里的「选好了」时,同一物理点在
  3935. // · 弹框的客户区里是 (496,547)
  3936. // · 主窗口的客户区里是 (778,630)
  3937. // 若按客户区比较,等于拿两个不同原点的数相减 ⇒ 判据必然失准。
  3938. //
  3939. // ② 抑制位与参考点必须是**线程级**的(见文件头 `s_bSuppressHoverAfterTouch`
  3940. // 那段说明)—— 因为属性弹框**自带独立的 CPaintManagerUI m_pm**,
  3941. // 与主窗口的 manager 不是同一个对象(真机日志:弹框 0A29F5F8 /
  3942. // 主窗口 07DA8C58)。那次触摸记在**弹框**那份状态上;而弹框一销毁,
  3943. // 系统把补投的 `extra=0` WM_MOUSEMOVE 发给**主窗口** ⇒ 落到主窗口的
  3944. // manager 上。若状态是成员,主窗口那份要么抑制位为假、要么参考点
  3945. // 还停在更早那次触摸(真机日志里是 1225,446,与本次点相距 447px)
  3946. // ⇒ 判据失败 ⇒ 解除抑制 + FindControl(pt) 命中背后商品卡 ⇒ 悬浮态
  3947. // 点亮且此后永不熄灭(`MODAL-DLG exit` → `HOVER-ENTER diandan_fooditem`)。
  3948. // 所以这两个状态已提升为文件级静态变量,与 manager 无关。
  3949. //
  3950. // 注意那条补投 MOVE 的 extra=0x00000000,它绕不过"提升移动不参与 hover"
  3951. // 的总闸,只能靠**提前把状态改好**来防(此处判据 + 各触摸路径的写入)。
  3952. POINT ptCheckScreen = ptCheck;
  3953. if (m_hWndPaint != NULL && ::IsWindow(m_hWndPaint))
  3954. ::ClientToScreen(m_hWndPaint, &ptCheckScreen);
  3955. const int dx = ptCheckScreen.x - s_ptLastTouchScreen.x;
  3956. const int dy = ptCheckScreen.y - s_ptLastTouchScreen.y;
  3957. if (dx <= 8 && dx >= -8 && dy <= 8 && dy >= -8)
  3958. break;
  3959. s_bSuppressHoverAfterTouch = false;
  3960. }
  3961. // Start tracking this entire window again...
  3962. if (!m_bMouseTracking)
  3963. {
  3964. TRACKMOUSEEVENT tme = { 0 };
  3965. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  3966. tme.dwFlags = TME_HOVER | TME_LEAVE;
  3967. tme.hwndTrack = m_hWndPaint;
  3968. tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
  3969. _TrackMouseEvent(&tme);
  3970. m_bMouseTracking = true;
  3971. }
  3972. // Generate the appropriate mouse messages
  3973. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3974. // 是否移动
  3975. bool bNeedDrag = true;
  3976. if (m_ptLastMousePos.x == pt.x && m_ptLastMousePos.y == pt.y)
  3977. {
  3978. bNeedDrag = false;
  3979. }
  3980. // 记录鼠标位置
  3981. m_ptLastMousePos = pt;
  3982. CControlUI* pNewHover = FindControl(pt);
  3983. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  3984. // 拖拽事件
  3985. if (bNeedDrag && m_bDragMode && wParam == MK_LBUTTON)
  3986. {
  3987. // 释放Capture
  3988. ::ReleaseCapture();
  3989. // 接口
  3990. if (m_pDragDrop != NULL && m_pDragDrop->OnDragDrop(m_pEventClick))
  3991. {
  3992. m_bDragMode = false;
  3993. break;
  3994. }
  3995. CIDropSource* pdsrc = new CIDropSource;
  3996. if (pdsrc == NULL) return 0;
  3997. pdsrc->AddRef();
  3998. CIDataObject* pdobj = new CIDataObject(pdsrc);
  3999. if (pdobj == NULL) return 0;
  4000. pdobj->AddRef();
  4001. FORMATETC fmtetc = { 0 };
  4002. STGMEDIUM medium = { 0 };
  4003. fmtetc.dwAspect = DVASPECT_CONTENT;
  4004. fmtetc.lindex = -1;
  4005. fmtetc.cfFormat = CF_BITMAP;
  4006. fmtetc.tymed = TYMED_GDI;
  4007. //////////////////////////////////////
  4008. HBITMAP hBitmap = (HBITMAP)OleDuplicateData(m_hDragBitmap, fmtetc.cfFormat, NULL);
  4009. medium.hBitmap = hBitmap;
  4010. pdobj->SetData(&fmtetc, &medium, FALSE);
  4011. //////////////////////////////////////
  4012. BITMAP bmap;
  4013. GetObject(hBitmap, sizeof(BITMAP), &bmap);
  4014. RECT rc = { 0, 0, bmap.bmWidth, bmap.bmHeight };
  4015. fmtetc.cfFormat = CF_ENHMETAFILE;
  4016. fmtetc.tymed = TYMED_ENHMF;
  4017. HDC hMetaDC = CreateEnhMetaFile(m_hDcPaint, NULL, NULL, NULL);
  4018. HDC hdcMem = CreateCompatibleDC(m_hDcPaint);
  4019. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBitmap);
  4020. ::BitBlt(hMetaDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
  4021. ::SelectObject(hdcMem, hOldBmp);
  4022. medium.hEnhMetaFile = CloseEnhMetaFile(hMetaDC);
  4023. DeleteDC(hdcMem);
  4024. medium.tymed = TYMED_ENHMF;
  4025. pdobj->SetData(&fmtetc, &medium, TRUE);
  4026. //////////////////////////////////////
  4027. CDragSourceHelper dragSrcHelper;
  4028. POINT ptDrag = { 0 };
  4029. ptDrag.x = bmap.bmWidth / 2;
  4030. ptDrag.y = bmap.bmHeight / 2;
  4031. dragSrcHelper.InitializeFromBitmap(hBitmap, ptDrag, rc, pdobj); //will own the bmp
  4032. DWORD dwEffect;
  4033. HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
  4034. if (dwEffect) pdsrc->Release();
  4035. else delete pdsrc;
  4036. pdobj->Release();
  4037. m_bDragMode = false;
  4038. break;
  4039. }
  4040. TEventUI event = { 0 };
  4041. event.ptMouse = pt;
  4042. event.wParam = wParam;
  4043. event.lParam = lParam;
  4044. event.dwTimestamp = ::GetTickCount();
  4045. event.wKeyState = MapKeyState();
  4046. // 悬浮态总闸:触摸提升出来的合成鼠标消息(MOUSEEVENTF_FROMTOUCH)不参与
  4047. // 悬浮 enter/leave。触摸没有“光标停留”语义,一旦让它参与,就会出现
  4048. // “点过的控件一直高亮 / 连点几个控件后多个同时高亮、怎么点都清不掉”的顽疾
  4049. // (按钮的 UISTATE_HOT、列表项的 UISTATE_HOT 全靠 MOUSEENTER/MOUSELEAVE 维护)。
  4050. // 该判断只影响悬浮段,消息依旧往下走 → 点击/拖拽状态机不受影响。
  4051. //
  4052. // [第十一轮诊断] 悬浮态不消失时,这里能看出是被哪一道闸门挡住的。
  4053. if (!IsCaptured() && !bPromotedTouchMove)
  4054. {
  4055. pNewHover = FindControl(pt);
  4056. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  4057. if (pNewHover != m_pEventHover && m_pEventHover != NULL)
  4058. {
  4059. event.Type = UIEVENT_MOUSELEAVE;
  4060. event.pSender = m_pEventHover;
  4061. CStdPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  4062. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  4063. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  4064. for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++)
  4065. {
  4066. static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i])->Event(event);
  4067. }
  4068. m_pEventHover->Event(event);
  4069. m_pEventHover = NULL;
  4070. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  4071. }
  4072. if (pNewHover != m_pEventHover && pNewHover != NULL)
  4073. {
  4074. event.Type = UIEVENT_MOUSEENTER;
  4075. event.pSender = pNewHover;
  4076. pNewHover->Event(event);
  4077. m_pEventHover = pNewHover;
  4078. }
  4079. }
  4080. if (m_pEventClick != NULL)
  4081. {
  4082. event.Type = UIEVENT_MOUSEMOVE;
  4083. event.pSender = m_pEventClick;
  4084. m_pEventClick->Event(event);
  4085. }
  4086. else if (pNewHover != NULL)
  4087. {
  4088. event.Type = UIEVENT_MOUSEMOVE;
  4089. event.pSender = pNewHover;
  4090. pNewHover->Event(event);
  4091. }
  4092. }
  4093. break;
  4094. case WM_LBUTTONDOWN:
  4095. {
  4096. // WM_TOUCH 后 Windows 可能补发 WM_LBUTTONDOWN。触摸点击由 TOUCHUP
  4097. // 的 tap 判定统一处理,不能让这条合成消息提前建立鼠标点击状态。
  4098. if (m_pEventTouch != NULL || m_bSuppressPromotedTouchMouse)
  4099. break;
  4100. // We alway set focus back to our app (this helps
  4101. // when Win32 child windows are placed on the dialog
  4102. // and we need to remove them on focus change).
  4103. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  4104. if (m_pRoot == NULL) break;
  4105. // 查找控件
  4106. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4107. m_ptLastMousePos = pt;
  4108. CControlUI* pControl = FindControl(pt);
  4109. if (pControl == NULL)
  4110. {
  4111. break;
  4112. }
  4113. if (pControl->GetManager() != this)
  4114. {
  4115. break;
  4116. }
  4117. // 准备拖拽
  4118. if (m_bDragDrop && pControl->IsDragEnabled())
  4119. {
  4120. m_bDragMode = true;
  4121. if (m_hDragBitmap != NULL)
  4122. {
  4123. ::DeleteObject(m_hDragBitmap);
  4124. m_hDragBitmap = NULL;
  4125. }
  4126. m_hDragBitmap = CRenderEngine::GenerateBitmap(this, pControl, pControl->GetPos());
  4127. }
  4128. // 开启捕获
  4129. SetCapture();
  4130. // 事件处理
  4131. m_pEventClick = pControl;
  4132. pControl->SetFocus();
  4133. TEventUI event = { 0 };
  4134. event.Type = UIEVENT_BUTTONDOWN;
  4135. event.pSender = pControl;
  4136. event.wParam = wParam;
  4137. event.lParam = lParam;
  4138. event.ptMouse = pt;
  4139. event.wKeyState = (WORD)wParam;
  4140. event.dwTimestamp = ::GetTickCount();
  4141. pControl->Event(event);
  4142. }
  4143. break;
  4144. case WM_LBUTTONDBLCLK:
  4145. {
  4146. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  4147. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4148. m_ptLastMousePos = pt;
  4149. CControlUI* pControl = FindControl(pt);
  4150. if (pControl == NULL) break;
  4151. if (pControl->GetManager() != this) break;
  4152. //SetCapture();
  4153. TEventUI event = { 0 };
  4154. event.Type = UIEVENT_DBLCLICK;
  4155. event.pSender = pControl;
  4156. event.ptMouse = pt;
  4157. event.wParam = wParam;
  4158. event.lParam = lParam;
  4159. event.wKeyState = (WORD)wParam;
  4160. event.dwTimestamp = ::GetTickCount();
  4161. pControl->Event(event);
  4162. m_pEventClick = pControl;
  4163. }
  4164. break;
  4165. case WM_LBUTTONUP:
  4166. {
  4167. const bool bPromotedTouchUp = IsPromotedTouchMouseMessage();
  4168. // 触摸手势进行中 / 刚由触摸链合成过点击 ⇒ 这条提升出来的鼠标抬起
  4169. // 一律不参与点击判定,直接丢掉(tap/drag 判定只在触摸链里做一次)。
  4170. //
  4171. // ⚠️ 副作用,别忽视:这条 break 也【丢掉了 ReleaseCapture()】。
  4172. // 所以捕获必须由触摸链自己释放 —— BeginTouchSlideGesture 里 SetCapture(),
  4173. // 对应的 ReleaseCapture() 在 EndTouchSlideGesture(命中控件那条路径)里。
  4174. // 若哪天把 End 里的 ReleaseCapture 挪走,这里就会漏捕获(表现为
  4175. // 后续所有鼠标消息都跑到本窗口、点别处不响应)。
  4176. // ==============================================================
  4177. // [触摸抬起的视觉收尾 · 位置是死线]
  4178. //
  4179. // ⚠️⚠️ 必须在下面那条早退路 break **之前**执行。⚠️⚠️
  4180. //
  4181. // 触摸轻点放行的那条配对 WM_LBUTTONUP,正好会走下面
  4182. // `if (m_pEventTouch != NULL || m_bSuppressPromotedTouchMouse)` 的早退路
  4183. // (正常情况下 m_pEventTouch 已释放、m_bSuppressPromotedTouchMouse 为假,
  4184. // 于是**不会**早退,会走到最末 pClick->Event(BUTTONUP))。
  4185. // 但凡早退,这里的收尾就必须已经做完了 —— 写在这条 break 之后
  4186. // 等于"触摸抬起时永远不执行"(历史踩过的坑)。
  4187. //
  4188. // 现象(用户真机,Win10)本块针对的两个:
  4189. // ① 点商品「古古怪怪」→ 属性弹框弹出 → 「古古怪怪」的**按下态**不消失;
  4190. // ② 之后在弹框里点「选好了」(弹框内该按钮与背后商品「属性测试」
  4191. // 屏幕位置重合)→ 弹框消失,但「属性测试」成了**悬浮态**。
  4192. //
  4193. // 成因与修法见 UIManager.h 里 TouchUp 的注释(顺序修复):
  4194. // · ① 由 TouchUp 在**业务回调之前**清按下态解决;
  4195. // · ② 由本块 ClearTouchHoverState 收走"没配对的悬浮态"解决 ——
  4196. // 抬起点下方的控件可能从没收到过 MOUSEENTER(触摸无悬浮语义),
  4197. // 却因为光标停在它上面而保留 HOT;这里显式收掉。
  4198. // ==============================================================
  4199. const POINT ptButtonUp = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4200. if (bPromotedTouchUp)
  4201. {
  4202. // (a) 收悬浮态:给登记表内控件 + m_pEventHover 补发 MOUSELEAVE,
  4203. // 并清掉"抬起点下那个控件"残留的 HOT(触摸从没给它发过 ENTER)。
  4204. ClearTouchHoverState(ptButtonUp);
  4205. // (b) 收输入态:抬起点命中的那个控件。
  4206. // ⚠️ 这里**不做**"向上遍历祖先链"的通用复位 —— 触摸链合成的
  4207. // BUTTONDOWN 只发给命中控件本身,祖先从未被置位;真正会顶
  4208. // 按下的自定义控件(如商品卡)是在 TouchUp() 里由控件自己的
  4209. // DoEvent(BUTTONUP) 复位的。
  4210. ClearPushedStateAt(NULL, ptButtonUp);
  4211. // (c) 抬起后禁止"悬浮态复活"(系统会补发合成的 WM_MOUSEMOVE)。
  4212. s_bSuppressHoverAfterTouch = true;
  4213. m_bMouseTracking = false;
  4214. }
  4215. if (m_pEventTouch != NULL || m_bSuppressPromotedTouchMouse)
  4216. {
  4217. m_bSuppressPromotedTouchMouse = false;
  4218. m_dwSuppressTick = 0;
  4219. break;
  4220. }
  4221. if (!bPromotedTouchUp)
  4222. {
  4223. // 普通鼠标点击也不会天然产生 MOUSELEAVE。
  4224. // 点击后光标仍停留在控件上时,必须主动清除 HOT 状态,
  4225. // 否则直到移动到下一个控件前都会保持悬浮态。
  4226. ClearTouchHoverState(ptButtonUp);
  4227. }
  4228. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4229. m_ptLastMousePos = pt;
  4230. CControlUI* pClick = m_pEventClick;
  4231. const bool bTouchDragged = m_bTouchMoved;
  4232. m_pEventClick = NULL;
  4233. m_bTouchMoved = false; // 用完即清,绝不影响后续真实鼠标点击
  4234. if (pClick == NULL)
  4235. {
  4236. ReleaseCapture();
  4237. break;
  4238. }
  4239. ReleaseCapture();
  4240. TEventUI event = { 0 };
  4241. event.Type = UIEVENT_BUTTONUP;
  4242. event.pSender = pClick;
  4243. event.wParam = wParam;
  4244. event.lParam = lParam;
  4245. event.ptMouse = pt;
  4246. if (bTouchDragged && pClick->GetInterface(DUI_CTR_SCROLLBAR) == NULL)
  4247. {
  4248. // 清除按钮的 PUSHED/CAPTURED 状态,但让 CButtonUI 的命中测试失败,
  4249. // 从而不会在滑动结束时调用 Activate。
  4250. event.ptMouse.x = -1;
  4251. event.ptMouse.y = -1;
  4252. }
  4253. event.wKeyState = (WORD)wParam;
  4254. event.dwTimestamp = ::GetTickCount();
  4255. pClick->Event(event);
  4256. }
  4257. break;
  4258. case WM_RBUTTONDOWN:
  4259. {
  4260. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  4261. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4262. m_ptLastMousePos = pt;
  4263. CControlUI* pControl = FindControl(pt);
  4264. if (pControl == NULL) break;
  4265. if (pControl->GetManager() != this) break;
  4266. pControl->SetFocus();
  4267. SetCapture();
  4268. TEventUI event = { 0 };
  4269. event.Type = UIEVENT_RBUTTONDOWN;
  4270. event.pSender = pControl;
  4271. event.wParam = wParam;
  4272. event.lParam = lParam;
  4273. event.ptMouse = pt;
  4274. event.wKeyState = (WORD)wParam;
  4275. event.dwTimestamp = ::GetTickCount();
  4276. pControl->Event(event);
  4277. m_pEventRClick = pControl;
  4278. }
  4279. break;
  4280. case WM_RBUTTONUP:
  4281. {
  4282. if (m_bMouseCapture) ReleaseCapture();
  4283. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4284. m_ptLastMousePos = pt;
  4285. m_pEventRClick = FindControl(pt);
  4286. if (m_pEventRClick == NULL) break;
  4287. TEventUI event = { 0 };
  4288. event.Type = UIEVENT_RBUTTONUP;
  4289. event.pSender = m_pEventRClick;
  4290. event.wParam = wParam;
  4291. event.lParam = lParam;
  4292. event.ptMouse = pt;
  4293. event.wKeyState = (WORD)wParam;
  4294. event.dwTimestamp = ::GetTickCount();
  4295. m_pEventRClick->Event(event);
  4296. }
  4297. break;
  4298. case WM_MBUTTONDOWN:
  4299. {
  4300. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  4301. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4302. m_ptLastMousePos = pt;
  4303. CControlUI* pControl = FindControl(pt);
  4304. if (pControl == NULL) break;
  4305. if (pControl->GetManager() != this) break;
  4306. pControl->SetFocus();
  4307. SetCapture();
  4308. TEventUI event = { 0 };
  4309. event.Type = UIEVENT_MBUTTONDOWN;
  4310. event.pSender = pControl;
  4311. event.wParam = wParam;
  4312. event.lParam = lParam;
  4313. event.ptMouse = pt;
  4314. event.wKeyState = (WORD)wParam;
  4315. event.dwTimestamp = ::GetTickCount();
  4316. pControl->Event(event);
  4317. m_pEventClick = pControl;
  4318. }
  4319. break;
  4320. case WM_MBUTTONUP:
  4321. {
  4322. if (m_bMouseCapture) ReleaseCapture();
  4323. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4324. m_ptLastMousePos = pt;
  4325. m_pEventClick = FindControl(pt);
  4326. if (m_pEventClick == NULL) break;
  4327. TEventUI event = { 0 };
  4328. event.Type = UIEVENT_MBUTTONUP;
  4329. event.pSender = m_pEventClick;
  4330. event.wParam = wParam;
  4331. event.lParam = lParam;
  4332. event.ptMouse = pt;
  4333. event.wKeyState = (WORD)wParam;
  4334. event.dwTimestamp = ::GetTickCount();
  4335. m_pEventClick->Event(event);
  4336. }
  4337. break;
  4338. case WM_CONTEXTMENU:
  4339. {
  4340. if (m_pRoot == NULL) break;
  4341. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4342. ::ScreenToClient(m_hWndPaint, &pt);
  4343. m_ptLastMousePos = pt;
  4344. if (m_pEventRClick == NULL) break;
  4345. ReleaseCapture();
  4346. TEventUI event = { 0 };
  4347. event.Type = UIEVENT_CONTEXTMENU;
  4348. event.pSender = m_pEventRClick;
  4349. event.wParam = wParam;
  4350. event.lParam = lParam;
  4351. event.ptMouse = pt;
  4352. event.wKeyState = (WORD)wParam;
  4353. event.lParam = (LPARAM)m_pEventRClick;
  4354. event.dwTimestamp = ::GetTickCount();
  4355. m_pEventRClick->Event(event);
  4356. m_pEventRClick = NULL;
  4357. }
  4358. break;
  4359. case WM_TOUCH:
  4360. {
  4361. OnTouchInput(wParam, lParam);
  4362. lRes = 0;
  4363. return true;
  4364. }
  4365. case WM_MOUSEWHEEL:
  4366. {
  4367. if (m_pRoot == NULL) break;
  4368. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  4369. ::ScreenToClient(m_hWndPaint, &pt);
  4370. m_ptLastMousePos = pt;
  4371. CControlUI* pControl = FindControl(pt);
  4372. if (pControl == NULL) break;
  4373. if (pControl->GetManager() != this) break;
  4374. int zDelta = (int)(short)HIWORD(wParam);
  4375. TEventUI event = { 0 };
  4376. event.Type = UIEVENT_SCROLLWHEEL;
  4377. event.pSender = pControl;
  4378. event.wParam = MAKEWPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, zDelta);
  4379. event.lParam = lParam;
  4380. event.ptMouse = pt;
  4381. event.wKeyState = MapKeyState();
  4382. event.dwTimestamp = ::GetTickCount();
  4383. pControl->Event(event);
  4384. // Let's make sure that the scroll item below the cursor is the same as before...
  4385. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)MAKELPARAM(m_ptLastMousePos.x, m_ptLastMousePos.y));
  4386. }
  4387. break;
  4388. case WM_CHAR:
  4389. {
  4390. if (m_pRoot == NULL) break;
  4391. if (m_pFocus == NULL) break;
  4392. TEventUI event = { 0 };
  4393. event.Type = UIEVENT_CHAR;
  4394. event.pSender = m_pFocus;
  4395. event.wParam = wParam;
  4396. event.lParam = lParam;
  4397. event.chKey = (TCHAR)wParam;
  4398. event.ptMouse = m_ptLastMousePos;
  4399. event.wKeyState = MapKeyState();
  4400. event.dwTimestamp = ::GetTickCount();
  4401. m_pFocus->Event(event);
  4402. }
  4403. break;
  4404. case WM_KEYDOWN:
  4405. {
  4406. if (m_pRoot == NULL) break;
  4407. if (m_pFocus == NULL) break;
  4408. TEventUI event = { 0 };
  4409. event.Type = UIEVENT_KEYDOWN;
  4410. event.pSender = m_pFocus;
  4411. event.wParam = wParam;
  4412. event.lParam = lParam;
  4413. event.chKey = (TCHAR)wParam;
  4414. event.ptMouse = m_ptLastMousePos;
  4415. event.wKeyState = MapKeyState();
  4416. event.dwTimestamp = ::GetTickCount();
  4417. m_pFocus->Event(event);
  4418. m_pEventKey = m_pFocus;
  4419. }
  4420. break;
  4421. case WM_KEYUP:
  4422. {
  4423. if (m_pRoot == NULL) break;
  4424. if (m_pEventKey == NULL) break;
  4425. TEventUI event = { 0 };
  4426. event.Type = UIEVENT_KEYUP;
  4427. event.pSender = m_pEventKey;
  4428. event.wParam = wParam;
  4429. event.lParam = lParam;
  4430. event.chKey = (TCHAR)wParam;
  4431. event.ptMouse = m_ptLastMousePos;
  4432. event.wKeyState = MapKeyState();
  4433. event.dwTimestamp = ::GetTickCount();
  4434. m_pEventKey->Event(event);
  4435. m_pEventKey = NULL;
  4436. }
  4437. break;
  4438. case WM_SETCURSOR:
  4439. {
  4440. if (m_pRoot == NULL) break;
  4441. if (LOWORD(lParam) != HTCLIENT) break;
  4442. if (m_bMouseCapture) return true;
  4443. POINT pt = { 0 };
  4444. ::GetCursorPos(&pt);
  4445. ::ScreenToClient(m_hWndPaint, &pt);
  4446. CControlUI* pControl = FindControl(pt);
  4447. if (pControl == NULL) break;
  4448. if ((pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0) break;
  4449. TEventUI event = { 0 };
  4450. event.Type = UIEVENT_SETCURSOR;
  4451. event.pSender = pControl;
  4452. event.wParam = wParam;
  4453. event.lParam = lParam;
  4454. event.ptMouse = pt;
  4455. event.wKeyState = MapKeyState();
  4456. event.dwTimestamp = ::GetTickCount();
  4457. pControl->Event(event);
  4458. }
  4459. return true;
  4460. case WM_SETFOCUS:
  4461. {
  4462. DuiLibDiag::Log(_T("WND-SETFOCUS mgrHwnd=%p nFocus=%p owner=%p"),
  4463. (void*)m_hWndPaint, (void*)::GetFocus(), (void*)::GetWindow(m_hWndPaint, GW_OWNER));
  4464. if (m_pFocus != NULL)
  4465. {
  4466. TEventUI event = { 0 };
  4467. event.Type = UIEVENT_SETFOCUS;
  4468. event.wParam = wParam;
  4469. event.lParam = lParam;
  4470. event.pSender = m_pFocus;
  4471. event.dwTimestamp = ::GetTickCount();
  4472. m_pFocus->Event(event);
  4473. }
  4474. break;
  4475. }
  4476. case WM_KILLFOCUS:
  4477. {
  4478. DuiLibDiag::Log(_T("WND-KILLFOCUS mgrHwnd=%p nFocus=%p owner=%p -> 本窗口失去键盘焦点"),
  4479. (void*)m_hWndPaint, (void*)::GetFocus(), (void*)::GetWindow(m_hWndPaint, GW_OWNER));
  4480. if (IsCaptured()) ReleaseCapture();
  4481. break;
  4482. }
  4483. case WM_ACTIVATE:
  4484. {
  4485. // 【诊断】记录"谁被激活 / 谁抢走了前台"。
  4486. //
  4487. // WA_INACTIVE(=0) 一出现,就说明"有别的窗口被激活了"。这正是
  4488. // "手指点触摸键盘"与"鼠标点触摸键盘"最可能分道扬镳的地方:
  4489. // 触摸键盘是**另一个进程**的窗口,一旦它夺走前台,本窗口的键盘焦点
  4490. // 就会被系统判为失效 —— 而 CEditWnd 一失焦就自毁(见 UIEdit.cpp),
  4491. // 于是之后所有按键(含退格)都无处可去。
  4492. TCHAR szFgCls[128] = { 0 };
  4493. HWND hFg = ::GetForegroundWindow();
  4494. if (hFg != NULL && ::IsWindow(hFg)) ::GetClassName(hFg, szFgCls, _countof(szFgCls));
  4495. DuiLibDiag::Log(_T("WND-ACTIVATE mgrHwnd=%p wParam=%u(0=INACTIVE) nFocus=%p selfTid=%u fg=%p fgClass=%s fgTid=%u"),
  4496. (void*)m_hWndPaint, (unsigned)LOWORD(wParam), (void*)::GetFocus(),
  4497. (unsigned)::GetCurrentThreadId(), (void*)hFg, szFgCls,
  4498. (unsigned)(hFg != NULL ? ::GetWindowThreadProcessId(hFg, NULL) : 0));
  4499. // ★ 修复(2026-09-22):重新获得激活时,把焦点"还回"给 DuiLib 当前
  4500. // 聚焦的控件 —— 与上面 WM_SETFOCUS 分支完全同构。
  4501. //
  4502. // 为什么必须补这一步(真机日志实证):
  4503. // 1) 手指点触摸键盘会让**另一个进程**(TabTip / TextInputHost)夺走前台
  4504. // ⇒ 本窗口收到 WA_INACTIVE,本线程的键盘焦点被系统置空;
  4505. // 2) 那一刻 CEditWnd 收到 WM_KILLFOCUS,按设计 PostMessage(WM_CLOSE)
  4506. // **把原生 EDIT 子窗口销毁**(EDIT-KILLFOCUS newFocus=00000000
  4507. // newTid=0 sameProc=0 ⇒ 焦点离开了本线程);
  4508. // 3) 等我们重新被激活时,那个子窗口**已经不存在了**;而
  4509. // CPaintManagerUI::SetFocus 有 `pControl == m_pFocus` 早退,
  4510. // 不会重发 UIEVENT_SETFOCUS ⇒ **没有任何路径重建它**
  4511. // ⇒ 用户体感"切一次输入框之后就再也输不进去、连退格都无效"。
  4512. // 4) CEditUI::DoEvent 收到 UIEVENT_SETFOCUS 后会自己补建/补焦点
  4513. // (m_pWindow == NULL ⇒ new CEditWnd;否则 Show+SetFocus)。
  4514. // ⇒ 只要在这里重发一次,输入能力就自动恢复,且**全程无时间戳**。
  4515. if (LOWORD(wParam) != WA_INACTIVE && m_pFocus != NULL)
  4516. {
  4517. TEventUI event = { 0 };
  4518. event.Type = UIEVENT_SETFOCUS;
  4519. event.wParam = wParam;
  4520. event.lParam = lParam;
  4521. event.pSender = m_pFocus;
  4522. event.dwTimestamp = ::GetTickCount();
  4523. m_pFocus->Event(event);
  4524. }
  4525. break;
  4526. }
  4527. case WM_NOTIFY:
  4528. {
  4529. if (lParam == 0) break;
  4530. LPNMHDR lpNMHDR = (LPNMHDR)lParam;
  4531. if (lpNMHDR != NULL) lRes = ::SendMessage(lpNMHDR->hwndFrom, OCM__BASE + uMsg, wParam, lParam);
  4532. return true;
  4533. }
  4534. break;
  4535. case WM_COMMAND:
  4536. {
  4537. if (lParam == 0) break;
  4538. HWND hWndChild = (HWND)lParam;
  4539. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  4540. if (lRes != 0) return true;
  4541. }
  4542. break;
  4543. case WM_CTLCOLOREDIT:
  4544. case WM_CTLCOLORSTATIC:
  4545. {
  4546. // Refer To: http://msdn.microsoft.com/en-us/library/bb761691(v=vs.85).aspx
  4547. // Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message.
  4548. if (lParam == 0) break;
  4549. HWND hWndChild = (HWND)lParam;
  4550. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  4551. if (lRes != 0) return true;
  4552. }
  4553. break;
  4554. default:
  4555. break;
  4556. }
  4557. return false;
  4558. }
  4559. bool CPaintManagerUI::IsUpdateNeeded() const
  4560. {
  4561. return m_bUpdateNeeded;
  4562. }
  4563. void CPaintManagerUI::NeedUpdate()
  4564. {
  4565. m_bUpdateNeeded = true;
  4566. }
  4567. void CPaintManagerUI::Invalidate()
  4568. {
  4569. RECT rcClient = { 0 };
  4570. ::GetClientRect(m_hWndPaint, &rcClient);
  4571. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcClient);
  4572. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  4573. }
  4574. void CPaintManagerUI::Invalidate(RECT& rcItem)
  4575. {
  4576. if (rcItem.left < 0) rcItem.left = 0;
  4577. if (rcItem.top < 0) rcItem.top = 0;
  4578. if (rcItem.right < rcItem.left) rcItem.right = rcItem.left;
  4579. if (rcItem.bottom < rcItem.top) rcItem.bottom = rcItem.top;
  4580. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcItem);
  4581. ::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
  4582. }
  4583. bool CPaintManagerUI::IsValid()
  4584. {
  4585. return m_hWndPaint != NULL && m_pRoot != NULL;
  4586. }
  4587. bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
  4588. {
  4589. ASSERT(::IsWindow(m_hWndPaint));
  4590. // 创建阴影窗口
  4591. m_shadow.Create(this);
  4592. // Reset any previous attachment
  4593. SetFocus(NULL);
  4594. m_pEventKey = NULL;
  4595. m_pEventHover = NULL;
  4596. m_pEventClick = NULL;
  4597. m_pEventRClick = NULL;
  4598. // Remove the existing control-tree. We might have gotten inside this function as
  4599. // a result of an event fired or similar, so we cannot just delete the objects and
  4600. // pull the internal memory of the calling code. We'll delay the cleanup.
  4601. if (m_pRoot != NULL)
  4602. {
  4603. m_aPostPaintControls.Empty();
  4604. AddDelayedCleanup(m_pRoot);
  4605. }
  4606. // Set the dialog root element
  4607. m_pRoot = pControl;
  4608. // Go ahead...
  4609. m_bUpdateNeeded = true;
  4610. m_bFirstLayout = true;
  4611. m_bFocusNeeded = true;
  4612. // Initiate all control
  4613. return InitControls(pControl);
  4614. }
  4615. bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
  4616. {
  4617. ASSERT(pControl);
  4618. if (pControl == NULL) return false;
  4619. pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
  4620. pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);
  4621. return true;
  4622. }
  4623. void CPaintManagerUI::ReapObjects(CControlUI* pControl)
  4624. {
  4625. if (pControl == m_pEventKey) m_pEventKey = NULL;
  4626. if (pControl == m_pEventHover) m_pEventHover = NULL;
  4627. if (pControl == m_pEventClick) m_pEventClick = NULL;
  4628. if (pControl == m_pEventRClick) m_pEventRClick = NULL;
  4629. if (pControl == m_pFocus) m_pFocus = NULL;
  4630. KillTimer(pControl);
  4631. const CDuiString& sName = pControl->GetName();
  4632. if (!sName.IsEmpty())
  4633. {
  4634. if (pControl == FindControl(sName)) m_mNameHash.Remove(sName);
  4635. }
  4636. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++)
  4637. {
  4638. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  4639. if (pMsg->pSender == pControl) pMsg->pSender = NULL;
  4640. }
  4641. }
  4642. bool CPaintManagerUI::AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  4643. {
  4644. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  4645. if (lp)
  4646. {
  4647. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  4648. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  4649. {
  4650. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  4651. {
  4652. return false;
  4653. }
  4654. }
  4655. aOptionGroup->Add(pControl);
  4656. }
  4657. else
  4658. {
  4659. CStdPtrArray* aOptionGroup = new CStdPtrArray(6);
  4660. aOptionGroup->Add(pControl);
  4661. m_mOptionGroup.Insert(pStrGroupName, aOptionGroup);
  4662. }
  4663. return true;
  4664. }
  4665. CStdPtrArray* CPaintManagerUI::GetOptionGroup(LPCTSTR pStrGroupName)
  4666. {
  4667. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  4668. if (lp) return static_cast<CStdPtrArray*>(lp);
  4669. return NULL;
  4670. }
  4671. void CPaintManagerUI::RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  4672. {
  4673. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  4674. if (lp)
  4675. {
  4676. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  4677. if (aOptionGroup == NULL) return;
  4678. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  4679. {
  4680. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  4681. {
  4682. aOptionGroup->Remove(i);
  4683. break;
  4684. }
  4685. }
  4686. if (aOptionGroup->IsEmpty())
  4687. {
  4688. delete aOptionGroup;
  4689. m_mOptionGroup.Remove(pStrGroupName);
  4690. }
  4691. }
  4692. }
  4693. void CPaintManagerUI::RemoveAllOptionGroups()
  4694. {
  4695. CStdPtrArray* aOptionGroup;
  4696. for (int i = 0; i < m_mOptionGroup.GetSize(); i++)
  4697. {
  4698. if (LPCTSTR key = m_mOptionGroup.GetAt(i))
  4699. {
  4700. aOptionGroup = static_cast<CStdPtrArray*>(m_mOptionGroup.Find(key));
  4701. delete aOptionGroup;
  4702. }
  4703. }
  4704. m_mOptionGroup.RemoveAll();
  4705. }
  4706. void CPaintManagerUI::MessageLoop()
  4707. {
  4708. MSG msg = { 0 };
  4709. while (::GetMessage(&msg, NULL, 0, 0))
  4710. {
  4711. if (!CPaintManagerUI::TranslateMessage(&msg))
  4712. {
  4713. ::TranslateMessage(&msg);
  4714. try
  4715. {
  4716. ::DispatchMessage(&msg);
  4717. }
  4718. catch (...)
  4719. {
  4720. DUITRACE(_T("EXCEPTION: %s(%d)\n"), __FILET__, __LINE__);
  4721. #ifdef _DEBUG
  4722. throw "CPaintManagerUI::MessageLoop";
  4723. #endif
  4724. }
  4725. }
  4726. }
  4727. }
  4728. void CPaintManagerUI::Term()
  4729. {
  4730. // 销毁资源管理器
  4731. CResourceManager::GetInstance()->Release();
  4732. CControlFactory::GetInstance()->Release();
  4733. // 清理共享资源
  4734. // 图片
  4735. TImageInfo* data;
  4736. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  4737. {
  4738. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  4739. {
  4740. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  4741. if (data)
  4742. {
  4743. CRenderEngine::FreeImage(data);
  4744. data = NULL;
  4745. }
  4746. }
  4747. }
  4748. m_SharedResInfo.m_ImageHash.RemoveAll();
  4749. // 字体
  4750. TFontInfo* pFontInfo;
  4751. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  4752. {
  4753. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  4754. {
  4755. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  4756. if (pFontInfo)
  4757. {
  4758. ::DeleteObject(pFontInfo->hFont);
  4759. delete pFontInfo;
  4760. pFontInfo = NULL;
  4761. }
  4762. }
  4763. }
  4764. m_SharedResInfo.m_CustomFonts.RemoveAll();
  4765. // 默认字体
  4766. if (m_SharedResInfo.m_DefaultFontInfo.hFont != NULL)
  4767. {
  4768. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  4769. }
  4770. // 样式
  4771. CDuiString* pStyle;
  4772. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  4773. {
  4774. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  4775. {
  4776. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key, false));
  4777. if (pStyle)
  4778. {
  4779. delete pStyle;
  4780. pStyle = NULL;
  4781. }
  4782. }
  4783. }
  4784. m_SharedResInfo.m_StyleHash.RemoveAll();
  4785. // 样式
  4786. CDuiString* pAttr;
  4787. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  4788. {
  4789. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  4790. {
  4791. pAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key, false));
  4792. if (pAttr)
  4793. {
  4794. delete pAttr;
  4795. pAttr = NULL;
  4796. }
  4797. }
  4798. }
  4799. m_SharedResInfo.m_AttrHash.RemoveAll();
  4800. // 关闭ZIP
  4801. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  4802. {
  4803. CloseZip((HZIP)m_hResourceZip);
  4804. m_hResourceZip = NULL;
  4805. }
  4806. if (m_cbZipBuf)
  4807. {
  4808. delete[] m_cbZipBuf;
  4809. m_cbZipBuf = nullptr;
  4810. }
  4811. }
  4812. CDPI* DuiLib::CPaintManagerUI::GetDPIObj()
  4813. {
  4814. if (m_pDPI == NULL)
  4815. {
  4816. m_pDPI = new CDPI;
  4817. }
  4818. return m_pDPI;
  4819. }
  4820. void DuiLib::CPaintManagerUI::SetDPI(int iDPI)
  4821. {
  4822. int scale1 = GetDPIObj()->GetScale();
  4823. GetDPIObj()->SetScale(iDPI);
  4824. int scale2 = GetDPIObj()->GetScale();
  4825. ResetDPIAssets();
  4826. RECT rcWnd = { 0 };
  4827. ::GetWindowRect(GetPaintWindow(), &rcWnd);
  4828. RECT* prcNewWindow = &rcWnd;
  4829. if (!::IsZoomed(GetPaintWindow()))
  4830. {
  4831. RECT rc = rcWnd;
  4832. rc.right = rcWnd.left + (rcWnd.right - rcWnd.left) * scale2 / scale1;
  4833. rc.bottom = rcWnd.top + (rcWnd.bottom - rcWnd.top) * scale2 / scale1;
  4834. prcNewWindow = &rc;
  4835. }
  4836. SetWindowPos(GetPaintWindow(), NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
  4837. if (GetRoot() != NULL) GetRoot()->NeedUpdate();
  4838. ::PostMessage(GetPaintWindow(), UIMSG_SET_DPI, 0, 0);
  4839. }
  4840. void DuiLib::CPaintManagerUI::SetAllDPI(int iDPI)
  4841. {
  4842. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  4843. {
  4844. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  4845. pManager->SetDPI(iDPI);
  4846. }
  4847. }
  4848. void DuiLib::CPaintManagerUI::ResetDPIAssets()
  4849. {
  4850. RemoveAllDrawInfos();
  4851. RemoveAllImages();;
  4852. for (int it = 0; it < m_ResInfo.m_CustomFonts.GetSize(); it++)
  4853. {
  4854. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(m_ResInfo.m_CustomFonts[it]));
  4855. RebuildFont(pFontInfo);
  4856. }
  4857. RebuildFont(&m_ResInfo.m_DefaultFontInfo);
  4858. for (int it = 0; it < m_SharedResInfo.m_CustomFonts.GetSize(); it++)
  4859. {
  4860. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(m_SharedResInfo.m_CustomFonts[it]));
  4861. RebuildFont(pFontInfo);
  4862. }
  4863. RebuildFont(&m_SharedResInfo.m_DefaultFontInfo);
  4864. CStdPtrArray* richEditList = FindSubControlsByClass(GetRoot(), _T("RichEditUI"));
  4865. for (int i = 0; i < richEditList->GetSize(); i++)
  4866. {
  4867. CRichEditUI* pT = static_cast<CRichEditUI*>((*richEditList)[i]);
  4868. pT->SetFont(pT->GetFont());
  4869. }
  4870. }
  4871. void DuiLib::CPaintManagerUI::RebuildFont(TFontInfo* pFontInfo)
  4872. {
  4873. ::DeleteObject(pFontInfo->hFont);
  4874. LOGFONT lf = { 0 };
  4875. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  4876. _tcsncpy(lf.lfFaceName, pFontInfo->sFontName, LF_FACESIZE);
  4877. lf.lfCharSet = DEFAULT_CHARSET;
  4878. lf.lfHeight = -GetDPIObj()->Scale(pFontInfo->iSize);
  4879. lf.lfQuality = CLEARTYPE_QUALITY;
  4880. if (pFontInfo->bBold) lf.lfWeight += FW_BOLD;
  4881. if (pFontInfo->bUnderline) lf.lfUnderline = TRUE;
  4882. if (pFontInfo->bItalic) lf.lfItalic = TRUE;
  4883. HFONT hFont = ::CreateFontIndirect(&lf);
  4884. pFontInfo->hFont = hFont;
  4885. ::ZeroMemory(&(pFontInfo->tm), sizeof(pFontInfo->tm));
  4886. if (m_hDcPaint)
  4887. {
  4888. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  4889. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  4890. ::SelectObject(m_hDcPaint, hOldFont);
  4891. }
  4892. }
  4893. CControlUI* CPaintManagerUI::GetFocus() const
  4894. {
  4895. return m_pFocus;
  4896. }
  4897. void CPaintManagerUI::SetFocus(CControlUI* pControl)
  4898. {
  4899. // 【诊断 · 新建商品弹框「输入文字消失」】焦点流向必须可见 ——
  4900. // 本函数是"究竟哪个控件拿到了 DuiLib 侧焦点"的唯一权威入口。
  4901. // 重点看 `pControl == m_pFocus` 的那条早退:它**不会**重新派发
  4902. // UIEVENT_SETFOCUS,因此也**不会**重建已被销毁的原生编辑窗口
  4903. // (CEditWnd 失焦即自毁,见 UIEdit.cpp 的 EDIT-KILLFOCUS)。
  4904. {
  4905. CDuiString sTarget = (pControl != NULL) ? pControl->GetName() : CDuiString(_T("NULL"));
  4906. CDuiString sCur = (m_pFocus != NULL) ? m_pFocus->GetName() : CDuiString(_T("NULL"));
  4907. DuiLibDiag::Log(_T("MGR-SETFOCUS enter target=%s/%s cur=%s/%s nFocus=%p mgrHwnd=%p"),
  4908. sTarget.GetData(), (pControl != NULL) ? pControl->GetClass() : _T("-"),
  4909. sCur.GetData(), (m_pFocus != NULL) ? m_pFocus->GetClass() : _T("-"),
  4910. (void*)::GetFocus(), (void*)m_hWndPaint);
  4911. }
  4912. // Paint manager window has focus?
  4913. HWND hFocusWnd = ::GetFocus();
  4914. if (!m_bNoActivate && hFocusWnd != m_hWndPaint && pControl != m_pFocus) ::SetFocus(m_hWndPaint);
  4915. // Already has focus?
  4916. if (pControl == m_pFocus)
  4917. {
  4918. DuiLibDiag::Log(_T("MGR-SETFOCUS 早退(目标已持有焦点) -> 不重发 UIEVENT_SETFOCUS"));
  4919. return;
  4920. }
  4921. // Remove focus from old control
  4922. if (m_pFocus != NULL)
  4923. {
  4924. TEventUI event = { 0 };
  4925. event.Type = UIEVENT_KILLFOCUS;
  4926. event.pSender = pControl;
  4927. event.dwTimestamp = ::GetTickCount();
  4928. m_pFocus->Event(event);
  4929. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  4930. m_pFocus = NULL;
  4931. }
  4932. if (pControl == NULL) return;
  4933. // Set focus to new control
  4934. if (pControl != NULL
  4935. && pControl->GetManager() == this
  4936. && pControl->IsVisible()
  4937. && pControl->IsEnabled())
  4938. {
  4939. m_pFocus = pControl;
  4940. TEventUI event = { 0 };
  4941. event.Type = UIEVENT_SETFOCUS;
  4942. event.pSender = pControl;
  4943. event.dwTimestamp = ::GetTickCount();
  4944. m_pFocus->Event(event);
  4945. SendNotify(m_pFocus, DUI_MSGTYPE_SETFOCUS);
  4946. }
  4947. }
  4948. void CPaintManagerUI::SetFocusNeeded(CControlUI* pControl)
  4949. {
  4950. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  4951. if (pControl == NULL) return;
  4952. if (m_pFocus != NULL)
  4953. {
  4954. TEventUI event = { 0 };
  4955. event.Type = UIEVENT_KILLFOCUS;
  4956. event.pSender = pControl;
  4957. event.dwTimestamp = ::GetTickCount();
  4958. m_pFocus->Event(event);
  4959. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  4960. m_pFocus = NULL;
  4961. }
  4962. FINDTABINFO info = { 0 };
  4963. info.pFocus = pControl;
  4964. info.bForward = false;
  4965. m_pFocus = m_pRoot->FindControl(__FindControlFromTab, &info, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  4966. m_bFocusNeeded = true;
  4967. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  4968. }
  4969. bool CPaintManagerUI::SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse)
  4970. {
  4971. ASSERT(pControl != NULL);
  4972. ASSERT(uElapse > 0);
  4973. for (int i = 0; i < m_aTimers.GetSize(); i++)
  4974. {
  4975. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  4976. if (pTimer->pSender == pControl
  4977. && pTimer->hWnd == m_hWndPaint
  4978. && pTimer->nLocalID == nTimerID)
  4979. {
  4980. if (pTimer->bKilled == true)
  4981. {
  4982. if (::SetTimer(m_hWndPaint, pTimer->uWinTimer, uElapse, NULL))
  4983. {
  4984. pTimer->bKilled = false;
  4985. return true;
  4986. }
  4987. return false;
  4988. }
  4989. return false;
  4990. }
  4991. }
  4992. m_uTimerID = (++m_uTimerID) % 0xF0; //0xf1-0xfe特殊用途
  4993. if (!::SetTimer(m_hWndPaint, m_uTimerID, uElapse, NULL)) return FALSE;
  4994. TIMERINFO* pTimer = new TIMERINFO;
  4995. if (pTimer == NULL) return FALSE;
  4996. pTimer->hWnd = m_hWndPaint;
  4997. pTimer->pSender = pControl;
  4998. pTimer->nLocalID = nTimerID;
  4999. pTimer->uWinTimer = m_uTimerID;
  5000. pTimer->bKilled = false;
  5001. return m_aTimers.Add(pTimer);
  5002. }
  5003. bool CPaintManagerUI::KillTimer(CControlUI* pControl, UINT nTimerID)
  5004. {
  5005. ASSERT(pControl != NULL);
  5006. for (int i = 0; i < m_aTimers.GetSize(); i++)
  5007. {
  5008. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  5009. if (pTimer->pSender == pControl
  5010. && pTimer->hWnd == m_hWndPaint
  5011. && pTimer->nLocalID == nTimerID)
  5012. {
  5013. if (pTimer->bKilled == false)
  5014. {
  5015. if (::IsWindow(m_hWndPaint)) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  5016. pTimer->bKilled = true;
  5017. return true;
  5018. }
  5019. }
  5020. }
  5021. return false;
  5022. }
  5023. void CPaintManagerUI::KillTimer(CControlUI* pControl)
  5024. {
  5025. ASSERT(pControl != NULL);
  5026. int count = m_aTimers.GetSize();
  5027. for (int i = 0, j = 0; i < count; i++)
  5028. {
  5029. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i - j]);
  5030. if (pTimer->pSender == pControl && pTimer->hWnd == m_hWndPaint)
  5031. {
  5032. if (pTimer->bKilled == false) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  5033. delete pTimer;
  5034. m_aTimers.Remove(i - j);
  5035. j++;
  5036. }
  5037. }
  5038. }
  5039. void CPaintManagerUI::RemoveAllTimers()
  5040. {
  5041. for (int i = 0; i < m_aTimers.GetSize(); i++)
  5042. {
  5043. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  5044. if (pTimer->hWnd == m_hWndPaint)
  5045. {
  5046. if (pTimer->bKilled == false)
  5047. {
  5048. if (::IsWindow(m_hWndPaint)) ::KillTimer(m_hWndPaint, pTimer->uWinTimer);
  5049. }
  5050. delete pTimer;
  5051. }
  5052. }
  5053. m_aTimers.Empty();
  5054. }
  5055. void CPaintManagerUI::SetCapture()
  5056. {
  5057. ::SetCapture(m_hWndPaint);
  5058. m_bMouseCapture = true;
  5059. }
  5060. void CPaintManagerUI::ReleaseCapture()
  5061. {
  5062. ::ReleaseCapture();
  5063. m_bMouseCapture = false;
  5064. m_bDragMode = false;
  5065. }
  5066. bool CPaintManagerUI::IsCaptured()
  5067. {
  5068. return m_bMouseCapture;
  5069. }
  5070. bool CPaintManagerUI::IsPainting()
  5071. {
  5072. return m_bIsPainting;
  5073. }
  5074. void CPaintManagerUI::SetPainting(bool bIsPainting)
  5075. {
  5076. m_bIsPainting = bIsPainting;
  5077. }
  5078. bool CPaintManagerUI::SetNextTabControl(bool bForward)
  5079. {
  5080. // If we're in the process of restructuring the layout we can delay the
  5081. // focus calulation until the next repaint.
  5082. if (m_bUpdateNeeded && bForward)
  5083. {
  5084. m_bFocusNeeded = true;
  5085. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  5086. return true;
  5087. }
  5088. // Find next/previous tabbable control
  5089. FINDTABINFO info1 = { 0 };
  5090. info1.pFocus = m_pFocus;
  5091. info1.bForward = bForward;
  5092. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  5093. if (pControl == NULL)
  5094. {
  5095. if (bForward)
  5096. {
  5097. // Wrap around
  5098. FINDTABINFO info2 = { 0 };
  5099. info2.pFocus = bForward ? NULL : info1.pLast;
  5100. info2.bForward = bForward;
  5101. pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  5102. }
  5103. else
  5104. {
  5105. pControl = info1.pLast;
  5106. }
  5107. }
  5108. if (pControl != NULL) SetFocus(pControl);
  5109. m_bFocusNeeded = false;
  5110. return true;
  5111. }
  5112. bool CPaintManagerUI::AddNotifier(INotifyUI* pNotifier)
  5113. {
  5114. ASSERT(m_aNotifiers.Find(pNotifier) < 0);
  5115. return m_aNotifiers.Add(pNotifier);
  5116. }
  5117. bool CPaintManagerUI::RemoveNotifier(INotifyUI* pNotifier)
  5118. {
  5119. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  5120. {
  5121. if (static_cast<INotifyUI*>(m_aNotifiers[i]) == pNotifier)
  5122. {
  5123. return m_aNotifiers.Remove(i);
  5124. }
  5125. }
  5126. return false;
  5127. }
  5128. bool CPaintManagerUI::AddPreMessageFilter(IMessageFilterUI* pFilter)
  5129. {
  5130. ASSERT(m_aPreMessageFilters.Find(pFilter) < 0);
  5131. return m_aPreMessageFilters.Add(pFilter);
  5132. }
  5133. bool CPaintManagerUI::RemovePreMessageFilter(IMessageFilterUI* pFilter)
  5134. {
  5135. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  5136. {
  5137. if (static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i]) == pFilter)
  5138. {
  5139. return m_aPreMessageFilters.Remove(i);
  5140. }
  5141. }
  5142. return false;
  5143. }
  5144. bool CPaintManagerUI::AddMessageFilter(IMessageFilterUI* pFilter)
  5145. {
  5146. ASSERT(m_aMessageFilters.Find(pFilter) < 0);
  5147. return m_aMessageFilters.Add(pFilter);
  5148. }
  5149. bool CPaintManagerUI::RemoveMessageFilter(IMessageFilterUI* pFilter)
  5150. {
  5151. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  5152. {
  5153. if (static_cast<IMessageFilterUI*>(m_aMessageFilters[i]) == pFilter)
  5154. {
  5155. return m_aMessageFilters.Remove(i);
  5156. }
  5157. }
  5158. return false;
  5159. }
  5160. int CPaintManagerUI::GetPostPaintCount() const
  5161. {
  5162. return m_aPostPaintControls.GetSize();
  5163. }
  5164. bool CPaintManagerUI::IsPostPaint(CControlUI* pControl)
  5165. {
  5166. return m_aPostPaintControls.Find(pControl) >= 0;
  5167. }
  5168. bool CPaintManagerUI::AddPostPaint(CControlUI* pControl)
  5169. {
  5170. ASSERT(m_aPostPaintControls.Find(pControl) < 0);
  5171. return m_aPostPaintControls.Add(pControl);
  5172. }
  5173. bool CPaintManagerUI::RemovePostPaint(CControlUI* pControl)
  5174. {
  5175. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  5176. {
  5177. if (static_cast<CControlUI*>(m_aPostPaintControls[i]) == pControl)
  5178. {
  5179. return m_aPostPaintControls.Remove(i);
  5180. }
  5181. }
  5182. return false;
  5183. }
  5184. bool CPaintManagerUI::SetPostPaintIndex(CControlUI* pControl, int iIndex)
  5185. {
  5186. RemovePostPaint(pControl);
  5187. return m_aPostPaintControls.InsertAt(iIndex, pControl);
  5188. }
  5189. int CPaintManagerUI::GetNativeWindowCount() const
  5190. {
  5191. return m_aNativeWindow.GetSize();
  5192. }
  5193. bool CPaintManagerUI::AddNativeWindow(CControlUI* pControl, HWND hChildWnd)
  5194. {
  5195. if (pControl == NULL || hChildWnd == NULL) return false;
  5196. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  5197. Invalidate(rcChildWnd);
  5198. if (m_aNativeWindow.Find(hChildWnd) >= 0) return false;
  5199. if (m_aNativeWindow.Add(hChildWnd))
  5200. {
  5201. m_aNativeWindowControl.Add(pControl);
  5202. return true;
  5203. }
  5204. return false;
  5205. }
  5206. bool CPaintManagerUI::RemoveNativeWindow(HWND hChildWnd)
  5207. {
  5208. for (int i = 0; i < m_aNativeWindow.GetSize(); i++)
  5209. {
  5210. if (static_cast<HWND>(m_aNativeWindow[i]) == hChildWnd)
  5211. {
  5212. if (m_aNativeWindow.Remove(i))
  5213. {
  5214. m_aNativeWindowControl.Remove(i);
  5215. return true;
  5216. }
  5217. return false;
  5218. }
  5219. }
  5220. return false;
  5221. }
  5222. RECT CPaintManagerUI::GetNativeWindowRect(HWND hChildWnd)
  5223. {
  5224. RECT rcChildWnd;
  5225. ::GetWindowRect(hChildWnd, &rcChildWnd);
  5226. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd));
  5227. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd) + 1);
  5228. return rcChildWnd;
  5229. }
  5230. void CPaintManagerUI::AddDelayedCleanup(CControlUI* pControl)
  5231. {
  5232. if (pControl == NULL) return;
  5233. pControl->SetManager(this, NULL, false);
  5234. m_aDelayedCleanup.Add(pControl);
  5235. PostAsyncNotify();
  5236. }
  5237. void CPaintManagerUI::AddMouseLeaveNeeded(CControlUI* pControl)
  5238. {
  5239. if (pControl == NULL) return;
  5240. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  5241. {
  5242. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  5243. {
  5244. return;
  5245. }
  5246. }
  5247. m_aNeedMouseLeaveNeeded.Add(pControl);
  5248. }
  5249. bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl)
  5250. {
  5251. if (pControl == NULL) return false;
  5252. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  5253. {
  5254. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  5255. {
  5256. return m_aNeedMouseLeaveNeeded.Remove(i);
  5257. }
  5258. }
  5259. return false;
  5260. }
  5261. void CPaintManagerUI::SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/)
  5262. {
  5263. TNotifyUI Msg;
  5264. Msg.pSender = pControl;
  5265. Msg.sType = pstrMessage;
  5266. Msg.wParam = wParam;
  5267. Msg.lParam = lParam;
  5268. SendNotify(Msg, bAsync);
  5269. }
  5270. void CPaintManagerUI::SendNotify(TNotifyUI& Msg, bool bAsync /*= false*/)
  5271. {
  5272. Msg.ptMouse = m_ptLastMousePos;
  5273. Msg.dwTimestamp = ::GetTickCount();
  5274. if (m_bUsedVirtualWnd)
  5275. {
  5276. Msg.sVirtualWnd = Msg.pSender->GetVirtualWnd();
  5277. }
  5278. if (!bAsync)
  5279. {
  5280. // Send to all listeners
  5281. if (Msg.pSender != NULL)
  5282. {
  5283. if (Msg.pSender->OnNotify) Msg.pSender->OnNotify(&Msg);
  5284. }
  5285. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  5286. {
  5287. static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg);
  5288. }
  5289. }
  5290. else
  5291. {
  5292. TNotifyUI* pMsg = new TNotifyUI;
  5293. pMsg->sVirtualWnd = Msg.sVirtualWnd;
  5294. pMsg->pSender = Msg.pSender;
  5295. pMsg->sType = Msg.sType;
  5296. pMsg->wParam = Msg.wParam;
  5297. pMsg->lParam = Msg.lParam;
  5298. pMsg->ptMouse = Msg.ptMouse;
  5299. pMsg->dwTimestamp = Msg.dwTimestamp;
  5300. m_aAsyncNotify.Add(pMsg);
  5301. PostAsyncNotify();
  5302. }
  5303. }
  5304. bool CPaintManagerUI::IsForceUseSharedRes() const
  5305. {
  5306. return m_bForceUseSharedRes;
  5307. }
  5308. void CPaintManagerUI::SetForceUseSharedRes(bool bForce)
  5309. {
  5310. m_bForceUseSharedRes = bForce;
  5311. }
  5312. DWORD CPaintManagerUI::GetDefaultDisabledColor() const
  5313. {
  5314. return m_ResInfo.m_dwDefaultDisabledColor;
  5315. }
  5316. void CPaintManagerUI::SetDefaultDisabledColor(DWORD dwColor, bool bShared)
  5317. {
  5318. if (bShared)
  5319. {
  5320. if (m_ResInfo.m_dwDefaultDisabledColor == m_SharedResInfo.m_dwDefaultDisabledColor)
  5321. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  5322. m_SharedResInfo.m_dwDefaultDisabledColor = dwColor;
  5323. }
  5324. else
  5325. {
  5326. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  5327. }
  5328. }
  5329. DWORD CPaintManagerUI::GetDefaultFontColor() const
  5330. {
  5331. return m_ResInfo.m_dwDefaultFontColor;
  5332. }
  5333. void CPaintManagerUI::SetDefaultFontColor(DWORD dwColor, bool bShared)
  5334. {
  5335. if (bShared)
  5336. {
  5337. if (m_ResInfo.m_dwDefaultFontColor == m_SharedResInfo.m_dwDefaultFontColor)
  5338. m_ResInfo.m_dwDefaultFontColor = dwColor;
  5339. m_SharedResInfo.m_dwDefaultFontColor = dwColor;
  5340. }
  5341. else
  5342. {
  5343. m_ResInfo.m_dwDefaultFontColor = dwColor;
  5344. }
  5345. }
  5346. DWORD CPaintManagerUI::GetDefaultLinkFontColor() const
  5347. {
  5348. return m_ResInfo.m_dwDefaultLinkFontColor;
  5349. }
  5350. void CPaintManagerUI::SetDefaultLinkFontColor(DWORD dwColor, bool bShared)
  5351. {
  5352. if (bShared)
  5353. {
  5354. if (m_ResInfo.m_dwDefaultLinkFontColor == m_SharedResInfo.m_dwDefaultLinkFontColor)
  5355. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  5356. m_SharedResInfo.m_dwDefaultLinkFontColor = dwColor;
  5357. }
  5358. else
  5359. {
  5360. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  5361. }
  5362. }
  5363. DWORD CPaintManagerUI::GetDefaultLinkHoverFontColor() const
  5364. {
  5365. return m_ResInfo.m_dwDefaultLinkHoverFontColor;
  5366. }
  5367. void CPaintManagerUI::SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared)
  5368. {
  5369. if (bShared)
  5370. {
  5371. if (m_ResInfo.m_dwDefaultLinkHoverFontColor == m_SharedResInfo.m_dwDefaultLinkHoverFontColor)
  5372. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  5373. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  5374. }
  5375. else
  5376. {
  5377. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  5378. }
  5379. }
  5380. DWORD CPaintManagerUI::GetDefaultSelectedBkColor() const
  5381. {
  5382. return m_ResInfo.m_dwDefaultSelectedBkColor;
  5383. }
  5384. void CPaintManagerUI::SetDefaultSelectedBkColor(DWORD dwColor, bool bShared)
  5385. {
  5386. if (bShared)
  5387. {
  5388. if (m_ResInfo.m_dwDefaultSelectedBkColor == m_SharedResInfo.m_dwDefaultSelectedBkColor)
  5389. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  5390. m_SharedResInfo.m_dwDefaultSelectedBkColor = dwColor;
  5391. }
  5392. else
  5393. {
  5394. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  5395. }
  5396. }
  5397. TFontInfo* CPaintManagerUI::GetDefaultFontInfo()
  5398. {
  5399. if (m_ResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  5400. {
  5401. if (m_SharedResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  5402. {
  5403. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_SharedResInfo.m_DefaultFontInfo.hFont);
  5404. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  5405. ::SelectObject(m_hDcPaint, hOldFont);
  5406. }
  5407. return &m_SharedResInfo.m_DefaultFontInfo;
  5408. }
  5409. else
  5410. {
  5411. if (m_ResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  5412. {
  5413. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_ResInfo.m_DefaultFontInfo.hFont);
  5414. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  5415. ::SelectObject(m_hDcPaint, hOldFont);
  5416. }
  5417. return &m_ResInfo.m_DefaultFontInfo;
  5418. }
  5419. }
  5420. void CPaintManagerUI::SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  5421. {
  5422. LOGFONT lf = { 0 };
  5423. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  5424. if (lstrlen(pStrFontName) > 0)
  5425. {
  5426. TCHAR szFaceName[32] = { 0 };//_T("@");
  5427. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  5428. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  5429. }
  5430. lf.lfCharSet = DEFAULT_CHARSET;
  5431. lf.lfHeight = -GetDPIObj()->Scale(nSize);;
  5432. if (bBold) lf.lfWeight += FW_BOLD;
  5433. if (bUnderline) lf.lfUnderline = TRUE;
  5434. if (bItalic) lf.lfItalic = TRUE;
  5435. if (bStrikeout) lf.lfStrikeOut = TRUE;
  5436. HFONT hFont = ::CreateFontIndirect(&lf);
  5437. if (hFont == NULL) return;
  5438. if (bShared)
  5439. {
  5440. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  5441. m_SharedResInfo.m_DefaultFontInfo.hFont = hFont;
  5442. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  5443. m_SharedResInfo.m_DefaultFontInfo.iSize = nSize;
  5444. m_SharedResInfo.m_DefaultFontInfo.bBold = bBold;
  5445. m_SharedResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  5446. m_SharedResInfo.m_DefaultFontInfo.bItalic = bItalic;
  5447. m_SharedResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  5448. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  5449. if (m_hDcPaint)
  5450. {
  5451. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  5452. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  5453. ::SelectObject(m_hDcPaint, hOldFont);
  5454. }
  5455. }
  5456. else
  5457. {
  5458. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  5459. m_ResInfo.m_DefaultFontInfo.hFont = hFont;
  5460. m_ResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  5461. m_ResInfo.m_DefaultFontInfo.iSize = nSize;
  5462. m_ResInfo.m_DefaultFontInfo.bBold = bBold;
  5463. m_ResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  5464. m_ResInfo.m_DefaultFontInfo.bItalic = bItalic;
  5465. m_ResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  5466. ::ZeroMemory(&m_ResInfo.m_DefaultFontInfo.tm, sizeof(m_ResInfo.m_DefaultFontInfo.tm));
  5467. if (m_hDcPaint)
  5468. {
  5469. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  5470. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  5471. ::SelectObject(m_hDcPaint, hOldFont);
  5472. }
  5473. }
  5474. }
  5475. DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const
  5476. {
  5477. if (bShared)
  5478. return m_SharedResInfo.m_CustomFonts.GetSize();
  5479. else
  5480. return m_ResInfo.m_CustomFonts.GetSize();
  5481. }
  5482. HFONT CPaintManagerUI::AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  5483. {
  5484. LOGFONT lf = { 0 };
  5485. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  5486. if (lstrlen(pStrFontName) > 0)
  5487. {
  5488. TCHAR szFaceName[32] = { 0 };//_T("@");
  5489. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  5490. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  5491. }
  5492. lf.lfCharSet = DEFAULT_CHARSET;
  5493. lf.lfHeight = -GetDPIObj()->Scale(nSize);
  5494. if (bBold) lf.lfWeight = FW_BOLD;
  5495. if (bUnderline) lf.lfUnderline = TRUE;
  5496. if (bItalic) lf.lfItalic = TRUE;
  5497. if (bStrikeout) lf.lfStrikeOut = TRUE;
  5498. HFONT hFont = ::CreateFontIndirect(&lf);
  5499. if (hFont == NULL) return NULL;
  5500. TFontInfo* pFontInfo = new TFontInfo;
  5501. if (!pFontInfo) return false;
  5502. ::ZeroMemory(pFontInfo, sizeof(TFontInfo));
  5503. pFontInfo->hFont = hFont;
  5504. pFontInfo->sFontName = lf.lfFaceName;
  5505. pFontInfo->iSize = nSize;
  5506. pFontInfo->bBold = bBold;
  5507. pFontInfo->bUnderline = bUnderline;
  5508. pFontInfo->bItalic = bItalic;
  5509. pFontInfo->bStrikeout = bStrikeout;
  5510. if (m_hDcPaint)
  5511. {
  5512. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  5513. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  5514. ::SelectObject(m_hDcPaint, hOldFont);
  5515. }
  5516. TCHAR idBuffer[16];
  5517. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  5518. _itot(id, idBuffer, 10);
  5519. if (bShared || m_bForceUseSharedRes)
  5520. {
  5521. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  5522. if (pOldFontInfo)
  5523. {
  5524. ::DeleteObject(pOldFontInfo->hFont);
  5525. delete pOldFontInfo;
  5526. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  5527. }
  5528. if (!m_SharedResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  5529. {
  5530. ::DeleteObject(hFont);
  5531. delete pFontInfo;
  5532. return NULL;
  5533. }
  5534. }
  5535. else
  5536. {
  5537. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  5538. if (pOldFontInfo)
  5539. {
  5540. ::DeleteObject(pOldFontInfo->hFont);
  5541. delete pOldFontInfo;
  5542. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  5543. }
  5544. if (!m_ResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  5545. {
  5546. ::DeleteObject(hFont);
  5547. delete pFontInfo;
  5548. return NULL;
  5549. }
  5550. }
  5551. return hFont;
  5552. }
  5553. void CPaintManagerUI::AddFontArray(LPCTSTR pstrPath)
  5554. {
  5555. LPBYTE pData = NULL;
  5556. DWORD dwSize = 0;
  5557. do
  5558. {
  5559. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  5560. if (CPaintManagerUI::GetResourceZip().IsEmpty())
  5561. {
  5562. sFile += pstrPath;
  5563. HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  5564. FILE_ATTRIBUTE_NORMAL, NULL);
  5565. if (hFile == INVALID_HANDLE_VALUE) break;
  5566. dwSize = ::GetFileSize(hFile, NULL);
  5567. if (dwSize == 0) break;
  5568. DWORD dwRead = 0;
  5569. pData = new BYTE[dwSize];
  5570. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  5571. ::CloseHandle(hFile);
  5572. if (dwRead != dwSize)
  5573. {
  5574. delete[] pData;
  5575. pData = NULL;
  5576. break;
  5577. }
  5578. }
  5579. else
  5580. {
  5581. sFile += CPaintManagerUI::GetResourceZip();
  5582. HZIP hz = NULL;
  5583. if (CPaintManagerUI::IsCachedResourceZip()) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
  5584. else
  5585. {
  5586. CDuiString sFilePwd = CPaintManagerUI::GetResourceZipPwd();
  5587. #ifdef UNICODE
  5588. char* pwd = w2a((wchar_t*)sFilePwd.GetData());
  5589. hz = OpenZip(sFile.GetData(), pwd);
  5590. if (pwd) delete[] pwd;
  5591. #else
  5592. hz = OpenZip(sFile.GetData(), sFilePwd.GetData());
  5593. #endif
  5594. }
  5595. if (hz == NULL) break;
  5596. ZIPENTRY ze;
  5597. int i = 0;
  5598. CDuiString key = pstrPath;
  5599. key.Replace(_T("\\"), _T("/"));
  5600. if (FindZipItem(hz, key, true, &i, &ze) != 0) break;
  5601. dwSize = ze.unc_size;
  5602. if (dwSize == 0) break;
  5603. pData = new BYTE[dwSize];
  5604. int res = UnzipItem(hz, i, pData, dwSize);
  5605. if (res != 0x00000000 && res != 0x00000600)
  5606. {
  5607. delete[] pData;
  5608. pData = NULL;
  5609. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  5610. break;
  5611. }
  5612. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  5613. }
  5614. } while (0);
  5615. while (!pData)
  5616. {
  5617. //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
  5618. HANDLE hFile = ::CreateFile(pstrPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  5619. if (hFile == INVALID_HANDLE_VALUE) break;
  5620. dwSize = ::GetFileSize(hFile, NULL);
  5621. if (dwSize == 0) break;
  5622. DWORD dwRead = 0;
  5623. pData = new BYTE[dwSize];
  5624. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  5625. ::CloseHandle(hFile);
  5626. if (dwRead != dwSize)
  5627. {
  5628. delete[] pData;
  5629. pData = NULL;
  5630. }
  5631. break;
  5632. }
  5633. DWORD nFonts;
  5634. HANDLE hFont = ::AddFontMemResourceEx(pData, dwSize, NULL, &nFonts);
  5635. delete[] pData;
  5636. pData = NULL;
  5637. m_aFonts.Add(hFont);
  5638. }
  5639. HFONT CPaintManagerUI::GetFont(int id)
  5640. {
  5641. if (id < 0) return GetDefaultFontInfo()->hFont;
  5642. TCHAR idBuffer[16];
  5643. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  5644. _itot(id, idBuffer, 10);
  5645. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  5646. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  5647. if (!pFontInfo) return GetDefaultFontInfo()->hFont;
  5648. return pFontInfo->hFont;
  5649. }
  5650. HFONT CPaintManagerUI::GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout)
  5651. {
  5652. TFontInfo* pFontInfo = NULL;
  5653. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5654. {
  5655. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5656. {
  5657. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  5658. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  5659. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  5660. && pFontInfo->bStrikeout == bStrikeout)
  5661. return pFontInfo->hFont;
  5662. }
  5663. }
  5664. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5665. {
  5666. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5667. {
  5668. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  5669. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  5670. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  5671. && pFontInfo->bStrikeout == bStrikeout)
  5672. return pFontInfo->hFont;
  5673. }
  5674. }
  5675. return NULL;
  5676. }
  5677. int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared)
  5678. {
  5679. TFontInfo* pFontInfo = NULL;
  5680. if (bShared)
  5681. {
  5682. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5683. {
  5684. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5685. {
  5686. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  5687. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  5688. }
  5689. }
  5690. }
  5691. else
  5692. {
  5693. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5694. {
  5695. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5696. {
  5697. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  5698. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  5699. }
  5700. }
  5701. }
  5702. return -1;
  5703. }
  5704. int CPaintManagerUI::GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  5705. {
  5706. TFontInfo* pFontInfo = NULL;
  5707. if (bShared)
  5708. {
  5709. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5710. {
  5711. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5712. {
  5713. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  5714. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  5715. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  5716. && pFontInfo->bStrikeout == bStrikeout)
  5717. return _ttoi(key);
  5718. }
  5719. }
  5720. }
  5721. else
  5722. {
  5723. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5724. {
  5725. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5726. {
  5727. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  5728. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  5729. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  5730. && pFontInfo->bStrikeout == bStrikeout)
  5731. return _ttoi(key);
  5732. }
  5733. }
  5734. }
  5735. return -1;
  5736. }
  5737. void CPaintManagerUI::RemoveFont(HFONT hFont, bool bShared)
  5738. {
  5739. TFontInfo* pFontInfo = NULL;
  5740. if (bShared)
  5741. {
  5742. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5743. {
  5744. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5745. {
  5746. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  5747. if (pFontInfo && pFontInfo->hFont == hFont)
  5748. {
  5749. ::DeleteObject(pFontInfo->hFont);
  5750. delete pFontInfo;
  5751. m_SharedResInfo.m_CustomFonts.Remove(key);
  5752. return;
  5753. }
  5754. }
  5755. }
  5756. }
  5757. else
  5758. {
  5759. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5760. {
  5761. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5762. {
  5763. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  5764. if (pFontInfo && pFontInfo->hFont == hFont)
  5765. {
  5766. ::DeleteObject(pFontInfo->hFont);
  5767. delete pFontInfo;
  5768. m_ResInfo.m_CustomFonts.Remove(key);
  5769. return;
  5770. }
  5771. }
  5772. }
  5773. }
  5774. }
  5775. void CPaintManagerUI::RemoveFont(int id, bool bShared)
  5776. {
  5777. TCHAR idBuffer[16];
  5778. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  5779. _itot(id, idBuffer, 10);
  5780. TFontInfo* pFontInfo = NULL;
  5781. if (bShared)
  5782. {
  5783. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  5784. if (pFontInfo)
  5785. {
  5786. ::DeleteObject(pFontInfo->hFont);
  5787. delete pFontInfo;
  5788. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  5789. }
  5790. }
  5791. else
  5792. {
  5793. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  5794. if (pFontInfo)
  5795. {
  5796. ::DeleteObject(pFontInfo->hFont);
  5797. delete pFontInfo;
  5798. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  5799. }
  5800. }
  5801. }
  5802. void CPaintManagerUI::RemoveAllFonts(bool bShared)
  5803. {
  5804. TFontInfo* pFontInfo;
  5805. if (bShared)
  5806. {
  5807. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5808. {
  5809. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5810. {
  5811. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  5812. if (pFontInfo)
  5813. {
  5814. ::DeleteObject(pFontInfo->hFont);
  5815. delete pFontInfo;
  5816. }
  5817. }
  5818. }
  5819. m_SharedResInfo.m_CustomFonts.RemoveAll();
  5820. }
  5821. else
  5822. {
  5823. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5824. {
  5825. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5826. {
  5827. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key, false));
  5828. if (pFontInfo)
  5829. {
  5830. ::DeleteObject(pFontInfo->hFont);
  5831. delete pFontInfo;
  5832. }
  5833. }
  5834. }
  5835. m_ResInfo.m_CustomFonts.RemoveAll();
  5836. }
  5837. }
  5838. TFontInfo* CPaintManagerUI::GetFontInfo(int id)
  5839. {
  5840. if (id < 0) return GetDefaultFontInfo();
  5841. TCHAR idBuffer[16];
  5842. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  5843. _itot(id, idBuffer, 10);
  5844. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  5845. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  5846. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  5847. if (pFontInfo->tm.tmHeight == 0)
  5848. {
  5849. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  5850. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  5851. ::SelectObject(m_hDcPaint, hOldFont);
  5852. }
  5853. return pFontInfo;
  5854. }
  5855. TFontInfo* CPaintManagerUI::GetFontInfo(HFONT hFont)
  5856. {
  5857. TFontInfo* pFontInfo = NULL;
  5858. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  5859. {
  5860. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  5861. {
  5862. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  5863. if (pFontInfo && pFontInfo->hFont == hFont) break;
  5864. }
  5865. }
  5866. if (!pFontInfo)
  5867. {
  5868. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  5869. {
  5870. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  5871. {
  5872. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  5873. if (pFontInfo && pFontInfo->hFont == hFont) break;
  5874. }
  5875. }
  5876. }
  5877. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  5878. if (pFontInfo->tm.tmHeight == 0)
  5879. {
  5880. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  5881. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  5882. ::SelectObject(m_hDcPaint, hOldFont);
  5883. }
  5884. return pFontInfo;
  5885. }
  5886. const TImageInfo* CPaintManagerUI::GetImage(LPCTSTR bitmap)
  5887. {
  5888. TImageInfo* data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  5889. if (!data) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  5890. return data;
  5891. }
  5892. const TImageInfo* CPaintManagerUI::GetImageEx(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, HINSTANCE instance)
  5893. {
  5894. const TImageInfo* data = GetImage(bitmap);
  5895. if (!data)
  5896. {
  5897. if (AddImage(bitmap, type, mask, bUseHSL, bGdiplus, false, instance))
  5898. {
  5899. if (m_bForceUseSharedRes) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  5900. else data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  5901. }
  5902. }
  5903. return data;
  5904. }
  5905. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, bool bShared, HINSTANCE instance)
  5906. {
  5907. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  5908. TImageInfo* data = NULL;
  5909. if (type != NULL && lstrlen(type) > 0)
  5910. {
  5911. if (isdigit(*bitmap))
  5912. {
  5913. LPTSTR pstr = NULL;
  5914. int iIndex = _tcstol(bitmap, &pstr, 10);
  5915. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(iIndex, type, mask, instance) : CRenderEngine::LoadImage(iIndex, type, mask, instance);
  5916. }
  5917. }
  5918. else
  5919. {
  5920. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(bitmap, NULL, mask, instance) : CRenderEngine::LoadImage(bitmap, NULL, mask, instance);
  5921. if (!data)
  5922. {
  5923. CDuiString sImageName = bitmap;
  5924. int iAtIdx = sImageName.ReverseFind(_T('@'));
  5925. int iDotIdx = sImageName.ReverseFind(_T('.'));
  5926. if (iAtIdx != -1 && iDotIdx != -1)
  5927. {
  5928. CDuiString sExe = sImageName.Mid(iDotIdx);
  5929. sImageName = sImageName.Left(iAtIdx) + sExe;
  5930. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(sImageName.GetData(), NULL, mask, instance) : CRenderEngine::LoadImage(sImageName.GetData(), NULL, mask, instance);
  5931. }
  5932. }
  5933. }
  5934. if (data == NULL)
  5935. {
  5936. return NULL;
  5937. }
  5938. data->bUseHSL = bUseHSL;
  5939. if (type != NULL) data->sResType = type;
  5940. data->dwMask = mask;
  5941. if (data->bUseHSL)
  5942. {
  5943. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  5944. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  5945. }
  5946. else data->pSrcBits = NULL;
  5947. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  5948. if (data)
  5949. {
  5950. if (bShared || m_bForceUseSharedRes)
  5951. {
  5952. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  5953. if (pOldImageInfo)
  5954. {
  5955. CRenderEngine::FreeImage(pOldImageInfo);
  5956. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  5957. }
  5958. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  5959. {
  5960. CRenderEngine::FreeImage(data);
  5961. data = NULL;
  5962. }
  5963. }
  5964. else
  5965. {
  5966. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  5967. if (pOldImageInfo)
  5968. {
  5969. CRenderEngine::FreeImage(pOldImageInfo);
  5970. m_ResInfo.m_ImageHash.Remove(bitmap);
  5971. }
  5972. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  5973. {
  5974. CRenderEngine::FreeImage(data);
  5975. data = NULL;
  5976. }
  5977. }
  5978. }
  5979. return data;
  5980. }
  5981. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared)
  5982. {
  5983. // 因无法确定外部HBITMAP格式,不能使用hsl调整
  5984. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  5985. if (hBitmap == NULL || iWidth <= 0 || iHeight <= 0) return NULL;
  5986. TImageInfo* data = new TImageInfo;
  5987. data->pBits = NULL;
  5988. data->pSrcBits = NULL;
  5989. data->hBitmap = hBitmap;
  5990. data->pBits = NULL;
  5991. data->nX = iWidth;
  5992. data->nY = iHeight;
  5993. data->bAlpha = bAlpha;
  5994. data->bUseHSL = false;
  5995. data->pSrcBits = NULL;
  5996. data->dwMask = 0;
  5997. if (bShared || m_bForceUseSharedRes)
  5998. {
  5999. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  6000. {
  6001. CRenderEngine::FreeImage(data);
  6002. data = NULL;
  6003. }
  6004. }
  6005. else
  6006. {
  6007. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  6008. {
  6009. CRenderEngine::FreeImage(data);
  6010. data = NULL;
  6011. }
  6012. }
  6013. return data;
  6014. }
  6015. void CPaintManagerUI::RemoveImage(LPCTSTR bitmap, bool bShared)
  6016. {
  6017. TImageInfo* data = NULL;
  6018. if (bShared)
  6019. {
  6020. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  6021. if (data)
  6022. {
  6023. CRenderEngine::FreeImage(data);
  6024. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  6025. }
  6026. }
  6027. else
  6028. {
  6029. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  6030. if (data)
  6031. {
  6032. CRenderEngine::FreeImage(data);
  6033. m_ResInfo.m_ImageHash.Remove(bitmap);
  6034. }
  6035. }
  6036. }
  6037. void CPaintManagerUI::RemoveAllImages(bool bShared)
  6038. {
  6039. if (bShared)
  6040. {
  6041. TImageInfo* data;
  6042. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  6043. {
  6044. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  6045. {
  6046. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  6047. if (data)
  6048. {
  6049. CRenderEngine::FreeImage(data);
  6050. }
  6051. }
  6052. }
  6053. m_SharedResInfo.m_ImageHash.RemoveAll();
  6054. }
  6055. else
  6056. {
  6057. TImageInfo* data;
  6058. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  6059. {
  6060. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  6061. {
  6062. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key, false));
  6063. if (data)
  6064. {
  6065. CRenderEngine::FreeImage(data);
  6066. }
  6067. }
  6068. }
  6069. m_ResInfo.m_ImageHash.RemoveAll();
  6070. }
  6071. }
  6072. void CPaintManagerUI::AdjustSharedImagesHSL()
  6073. {
  6074. TImageInfo* data;
  6075. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  6076. {
  6077. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  6078. {
  6079. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key));
  6080. if (data && data->bUseHSL)
  6081. {
  6082. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  6083. }
  6084. }
  6085. }
  6086. }
  6087. void CPaintManagerUI::AdjustImagesHSL()
  6088. {
  6089. TImageInfo* data;
  6090. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  6091. {
  6092. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  6093. {
  6094. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key));
  6095. if (data && data->bUseHSL)
  6096. {
  6097. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  6098. }
  6099. }
  6100. }
  6101. Invalidate();
  6102. }
  6103. void CPaintManagerUI::PostAsyncNotify()
  6104. {
  6105. if (!m_bAsyncNotifyPosted)
  6106. {
  6107. ::PostMessage(m_hWndPaint, WM_APP + 1, 0, 0L);
  6108. m_bAsyncNotifyPosted = true;
  6109. }
  6110. }
  6111. void CPaintManagerUI::ReloadSharedImages()
  6112. {
  6113. TImageInfo* data = NULL;
  6114. TImageInfo* pNewData = NULL;
  6115. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  6116. {
  6117. if (LPCTSTR bitmap = m_SharedResInfo.m_ImageHash.GetAt(i))
  6118. {
  6119. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  6120. if (data != NULL)
  6121. {
  6122. if (!data->sResType.IsEmpty())
  6123. {
  6124. if (isdigit(*bitmap))
  6125. {
  6126. LPTSTR pstr = NULL;
  6127. int iIndex = _tcstol(bitmap, &pstr, 10);
  6128. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  6129. }
  6130. }
  6131. else
  6132. {
  6133. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  6134. }
  6135. if (pNewData == NULL) continue;
  6136. CRenderEngine::FreeImage(data, false);
  6137. data->hBitmap = pNewData->hBitmap;
  6138. data->pImage = pNewData->pImage;
  6139. data->pBits = pNewData->pBits;
  6140. data->nX = pNewData->nX;
  6141. data->nY = pNewData->nY;
  6142. data->bAlpha = pNewData->bAlpha;
  6143. data->pSrcBits = NULL;
  6144. if (data->bUseHSL)
  6145. {
  6146. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  6147. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  6148. }
  6149. else data->pSrcBits = NULL;
  6150. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  6151. delete pNewData;
  6152. }
  6153. }
  6154. }
  6155. }
  6156. void CPaintManagerUI::ReloadImages()
  6157. {
  6158. RemoveAllDrawInfos();
  6159. TImageInfo* data = NULL;
  6160. TImageInfo* pNewData = NULL;
  6161. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  6162. {
  6163. if (LPCTSTR bitmap = m_ResInfo.m_ImageHash.GetAt(i))
  6164. {
  6165. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  6166. if (data != NULL)
  6167. {
  6168. if (!data->sResType.IsEmpty())
  6169. {
  6170. if (isdigit(*bitmap))
  6171. {
  6172. LPTSTR pstr = NULL;
  6173. int iIndex = _tcstol(bitmap, &pstr, 10);
  6174. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  6175. }
  6176. }
  6177. else
  6178. {
  6179. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  6180. }
  6181. CRenderEngine::FreeImage(data, false);
  6182. if (pNewData == NULL)
  6183. {
  6184. m_ResInfo.m_ImageHash.Remove(bitmap);
  6185. continue;
  6186. }
  6187. data->hBitmap = pNewData->hBitmap;
  6188. data->pBits = pNewData->pBits;
  6189. data->nX = pNewData->nX;
  6190. data->nY = pNewData->nY;
  6191. data->bAlpha = pNewData->bAlpha;
  6192. data->pSrcBits = NULL;
  6193. if (data->bUseHSL)
  6194. {
  6195. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  6196. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  6197. }
  6198. else data->pSrcBits = NULL;
  6199. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  6200. delete pNewData;
  6201. }
  6202. }
  6203. }
  6204. if (m_pRoot) m_pRoot->Invalidate();
  6205. }
  6206. const TDrawInfo* CPaintManagerUI::GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  6207. {
  6208. CDuiString sKey;
  6209. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  6210. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  6211. if (pDrawInfo == NULL && !sKey.IsEmpty())
  6212. {
  6213. pDrawInfo = new TDrawInfo();
  6214. pDrawInfo->Parse(pStrImage, pStrModify, this);
  6215. m_ResInfo.m_DrawInfoHash.Insert(sKey, pDrawInfo);
  6216. }
  6217. return pDrawInfo;
  6218. }
  6219. void CPaintManagerUI::RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  6220. {
  6221. CDuiString sKey;
  6222. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  6223. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  6224. if (pDrawInfo != NULL)
  6225. {
  6226. m_ResInfo.m_DrawInfoHash.Remove(sKey);
  6227. delete pDrawInfo;
  6228. pDrawInfo = NULL;
  6229. }
  6230. }
  6231. void CPaintManagerUI::RemoveAllDrawInfos()
  6232. {
  6233. TDrawInfo* pDrawInfo = NULL;
  6234. for (int i = 0; i < m_ResInfo.m_DrawInfoHash.GetSize(); i++)
  6235. {
  6236. LPCTSTR key = m_ResInfo.m_DrawInfoHash.GetAt(i);
  6237. if (key != NULL)
  6238. {
  6239. pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(key, false));
  6240. if (pDrawInfo)
  6241. {
  6242. delete pDrawInfo;
  6243. pDrawInfo = NULL;
  6244. }
  6245. }
  6246. }
  6247. m_ResInfo.m_DrawInfoHash.RemoveAll();
  6248. }
  6249. void CPaintManagerUI::AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared)
  6250. {
  6251. if (bShared || m_bForceUseSharedRes)
  6252. {
  6253. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  6254. if (pDefaultAttr != NULL)
  6255. {
  6256. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  6257. if (pOldDefaultAttr) delete pOldDefaultAttr;
  6258. }
  6259. }
  6260. else
  6261. {
  6262. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  6263. if (pDefaultAttr != NULL)
  6264. {
  6265. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  6266. if (pOldDefaultAttr) delete pOldDefaultAttr;
  6267. }
  6268. }
  6269. }
  6270. LPCTSTR CPaintManagerUI::GetDefaultAttributeList(LPCTSTR pStrControlName) const
  6271. {
  6272. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  6273. if (!pDefaultAttr) pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  6274. if (pDefaultAttr) return pDefaultAttr->GetData();
  6275. return NULL;
  6276. }
  6277. bool CPaintManagerUI::RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared)
  6278. {
  6279. if (bShared)
  6280. {
  6281. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  6282. if (!pDefaultAttr) return false;
  6283. delete pDefaultAttr;
  6284. return m_SharedResInfo.m_AttrHash.Remove(pStrControlName);
  6285. }
  6286. else
  6287. {
  6288. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  6289. if (!pDefaultAttr) return false;
  6290. delete pDefaultAttr;
  6291. return m_ResInfo.m_AttrHash.Remove(pStrControlName);
  6292. }
  6293. }
  6294. void CPaintManagerUI::RemoveAllDefaultAttributeList(bool bShared)
  6295. {
  6296. if (bShared)
  6297. {
  6298. CDuiString* pDefaultAttr;
  6299. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  6300. {
  6301. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  6302. {
  6303. pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key));
  6304. if (pDefaultAttr) delete pDefaultAttr;
  6305. }
  6306. }
  6307. m_SharedResInfo.m_AttrHash.RemoveAll();
  6308. }
  6309. else
  6310. {
  6311. CDuiString* pDefaultAttr;
  6312. for (int i = 0; i < m_ResInfo.m_AttrHash.GetSize(); i++)
  6313. {
  6314. if (LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i))
  6315. {
  6316. pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key));
  6317. if (pDefaultAttr) delete pDefaultAttr;
  6318. }
  6319. }
  6320. m_ResInfo.m_AttrHash.RemoveAll();
  6321. }
  6322. }
  6323. void CPaintManagerUI::AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  6324. {
  6325. if (pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0')) return;
  6326. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  6327. if (pCostomAttr != NULL)
  6328. {
  6329. if (m_mWindowCustomAttrHash.Find(pstrName) == NULL)
  6330. m_mWindowCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  6331. else
  6332. delete pCostomAttr;
  6333. }
  6334. }
  6335. LPCTSTR CPaintManagerUI::GetWindowCustomAttribute(LPCTSTR pstrName) const
  6336. {
  6337. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  6338. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  6339. if (pCostomAttr) return pCostomAttr->GetData();
  6340. return NULL;
  6341. }
  6342. bool CPaintManagerUI::RemoveWindowCustomAttribute(LPCTSTR pstrName)
  6343. {
  6344. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  6345. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  6346. if (!pCostomAttr) return false;
  6347. delete pCostomAttr;
  6348. return m_mWindowCustomAttrHash.Remove(pstrName);
  6349. }
  6350. void CPaintManagerUI::RemoveAllWindowCustomAttribute()
  6351. {
  6352. CDuiString* pCostomAttr;
  6353. for (int i = 0; i < m_mWindowCustomAttrHash.GetSize(); i++)
  6354. {
  6355. if (LPCTSTR key = m_mWindowCustomAttrHash.GetAt(i))
  6356. {
  6357. pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(key));
  6358. delete pCostomAttr;
  6359. }
  6360. }
  6361. m_mWindowCustomAttrHash.Resize();
  6362. }
  6363. CControlUI* CPaintManagerUI::GetRoot() const
  6364. {
  6365. ASSERT(m_pRoot);
  6366. return m_pRoot;
  6367. }
  6368. CControlUI* CPaintManagerUI::FindControl(POINT pt) const
  6369. {
  6370. ASSERT(m_pRoot);
  6371. return m_pRoot->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  6372. }
  6373. CControlUI* CPaintManagerUI::FindControl(LPCTSTR pstrName) const
  6374. {
  6375. ASSERT(m_pRoot);
  6376. return static_cast<CControlUI*>(m_mNameHash.Find(pstrName));
  6377. }
  6378. CControlUI* CPaintManagerUI::FindSubControlByPoint(CControlUI* pParent, POINT pt) const
  6379. {
  6380. if (pParent == NULL) pParent = GetRoot();
  6381. ASSERT(pParent);
  6382. return pParent->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  6383. }
  6384. CControlUI* CPaintManagerUI::FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const
  6385. {
  6386. if (pParent == NULL) pParent = GetRoot();
  6387. ASSERT(pParent);
  6388. return pParent->FindControl(__FindControlFromName, (LPVOID)pstrName, UIFIND_ALL);
  6389. }
  6390. CControlUI* CPaintManagerUI::FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex)
  6391. {
  6392. if (pParent == NULL) pParent = GetRoot();
  6393. ASSERT(pParent);
  6394. m_aFoundControls.Resize(iIndex + 1);
  6395. return pParent->FindControl(__FindControlFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  6396. }
  6397. CStdPtrArray* CPaintManagerUI::FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass)
  6398. {
  6399. if (pParent == NULL) pParent = GetRoot();
  6400. ASSERT(pParent);
  6401. m_aFoundControls.Empty();
  6402. pParent->FindControl(__FindControlsFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  6403. return &m_aFoundControls;
  6404. }
  6405. CStdPtrArray* CPaintManagerUI::GetFoundControls()
  6406. {
  6407. return &m_aFoundControls;
  6408. }
  6409. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
  6410. {
  6411. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
  6412. const CDuiString& sName = pThis->GetName();
  6413. if (sName.IsEmpty()) return NULL;
  6414. // Add this control to the hash list
  6415. pManager->m_mNameHash.Set(sName, pThis);
  6416. return NULL; // Attempt to add all controls
  6417. }
  6418. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromCount(CControlUI* /*pThis*/, LPVOID pData)
  6419. {
  6420. int* pnCount = static_cast<int*>(pData);
  6421. (*pnCount)++;
  6422. return NULL; // Count all controls
  6423. }
  6424. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromPoint(CControlUI* pThis, LPVOID pData)
  6425. {
  6426. LPPOINT pPoint = static_cast<LPPOINT>(pData);
  6427. return ::PtInRect(&pThis->GetPos(), *pPoint) ? pThis : NULL;
  6428. }
  6429. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromTab(CControlUI* pThis, LPVOID pData)
  6430. {
  6431. FINDTABINFO* pInfo = static_cast<FINDTABINFO*>(pData);
  6432. if (pInfo->pFocus == pThis)
  6433. {
  6434. if (pInfo->bForward) pInfo->bNextIsIt = true;
  6435. return pInfo->bForward ? NULL : pInfo->pLast;
  6436. }
  6437. if ((pThis->GetControlFlags() & UIFLAG_TABSTOP) == 0) return NULL;
  6438. pInfo->pLast = pThis;
  6439. if (pInfo->bNextIsIt) return pThis;
  6440. if (pInfo->pFocus == NULL) return pThis;
  6441. return NULL; // Examine all controls
  6442. }
  6443. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromShortcut(CControlUI* pThis, LPVOID pData)
  6444. {
  6445. if (!pThis->IsVisible()) return NULL;
  6446. FINDSHORTCUT* pFS = static_cast<FINDSHORTCUT*>(pData);
  6447. if (pFS->ch == toupper(pThis->GetShortcut())) pFS->bPickNext = true;
  6448. if (_tcsstr(pThis->GetClass(), _T("LabelUI")) != NULL) return NULL; // Labels never get focus!
  6449. return pFS->bPickNext ? pThis : NULL;
  6450. }
  6451. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromName(CControlUI* pThis, LPVOID pData)
  6452. {
  6453. LPCTSTR pstrName = static_cast<LPCTSTR>(pData);
  6454. const CDuiString& sName = pThis->GetName();
  6455. if (sName.IsEmpty()) return NULL;
  6456. return (_tcsicmp(sName, pstrName) == 0) ? pThis : NULL;
  6457. }
  6458. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromClass(CControlUI* pThis, LPVOID pData)
  6459. {
  6460. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  6461. LPCTSTR pType = pThis->GetClass();
  6462. CStdPtrArray* pFoundControls = pThis->GetManager()->GetFoundControls();
  6463. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  6464. {
  6465. int iIndex = -1;
  6466. while (pFoundControls->GetAt(++iIndex) != NULL);
  6467. if (iIndex < pFoundControls->GetSize()) pFoundControls->SetAt(iIndex, pThis);
  6468. }
  6469. if (pFoundControls->GetAt(pFoundControls->GetSize() - 1) != NULL) return pThis;
  6470. return NULL;
  6471. }
  6472. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromClass(CControlUI* pThis, LPVOID pData)
  6473. {
  6474. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  6475. LPCTSTR pType = pThis->GetClass();
  6476. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  6477. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  6478. return NULL;
  6479. }
  6480. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromUpdate(CControlUI* pThis, LPVOID pData)
  6481. {
  6482. if (pThis->IsUpdateNeeded())
  6483. {
  6484. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  6485. return pThis;
  6486. }
  6487. return NULL;
  6488. }
  6489. bool CPaintManagerUI::TranslateAccelerator(LPMSG pMsg)
  6490. {
  6491. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  6492. {
  6493. LRESULT lResult = static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i])->TranslateAccelerator(pMsg);
  6494. if (lResult == S_OK) return true;
  6495. }
  6496. return false;
  6497. }
  6498. bool CPaintManagerUI::TranslateMessage(const LPMSG pMsg)
  6499. {
  6500. // Pretranslate Message takes care of system-wide messages, such as
  6501. // tabbing and shortcut key-combos. We'll look for all messages for
  6502. // each window and any child control attached.
  6503. UINT uStyle = GetWindowStyle(pMsg->hwnd);
  6504. UINT uChildRes = uStyle & WS_CHILD;
  6505. LRESULT lRes = 0;
  6506. if (uChildRes != 0)
  6507. {
  6508. HWND hWndParent = ::GetParent(pMsg->hwnd);
  6509. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  6510. {
  6511. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  6512. HWND hTempParent = hWndParent;
  6513. while (hTempParent)
  6514. {
  6515. if (pMsg->hwnd == pT->GetPaintWindow() || hTempParent == pT->GetPaintWindow())
  6516. {
  6517. if (pT->TranslateAccelerator(pMsg))
  6518. return true;
  6519. pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes);
  6520. }
  6521. hTempParent = GetParent(hTempParent);
  6522. }
  6523. }
  6524. }
  6525. else
  6526. {
  6527. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  6528. {
  6529. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  6530. if (pMsg->hwnd == pT->GetPaintWindow())
  6531. {
  6532. if (pT->TranslateAccelerator(pMsg))
  6533. return true;
  6534. if (pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes))
  6535. return true;
  6536. return false;
  6537. }
  6538. }
  6539. }
  6540. return false;
  6541. }
  6542. bool CPaintManagerUI::AddTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  6543. {
  6544. ASSERT(m_aTranslateAccelerator.Find(pTranslateAccelerator) < 0);
  6545. return m_aTranslateAccelerator.Add(pTranslateAccelerator);
  6546. }
  6547. bool CPaintManagerUI::RemoveTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  6548. {
  6549. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  6550. {
  6551. if (static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i]) == pTranslateAccelerator)
  6552. {
  6553. return m_aTranslateAccelerator.Remove(i);
  6554. }
  6555. }
  6556. return false;
  6557. }
  6558. void CPaintManagerUI::UsedVirtualWnd(bool bUsed)
  6559. {
  6560. m_bUsedVirtualWnd = bUsed;
  6561. }
  6562. // 样式管理
  6563. void CPaintManagerUI::AddStyle(LPCTSTR pName, LPCTSTR pDeclarationList, bool bShared)
  6564. {
  6565. CDuiString* pStyle = new CDuiString(pDeclarationList);
  6566. if (bShared || m_bForceUseSharedRes)
  6567. {
  6568. if (!m_SharedResInfo.m_StyleHash.Insert(pName, pStyle))
  6569. {
  6570. delete pStyle;
  6571. }
  6572. }
  6573. else
  6574. {
  6575. if (!m_ResInfo.m_StyleHash.Insert(pName, pStyle))
  6576. {
  6577. delete pStyle;
  6578. }
  6579. }
  6580. }
  6581. LPCTSTR CPaintManagerUI::GetStyle(LPCTSTR pName) const
  6582. {
  6583. CDuiString* pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  6584. if (!pStyle) pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  6585. if (pStyle) return pStyle->GetData();
  6586. else return NULL;
  6587. }
  6588. BOOL CPaintManagerUI::RemoveStyle(LPCTSTR pName, bool bShared)
  6589. {
  6590. CDuiString* pStyle = NULL;
  6591. if (bShared)
  6592. {
  6593. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  6594. if (pStyle)
  6595. {
  6596. delete pStyle;
  6597. m_SharedResInfo.m_StyleHash.Remove(pName);
  6598. }
  6599. }
  6600. else
  6601. {
  6602. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  6603. if (pStyle)
  6604. {
  6605. delete pStyle;
  6606. m_ResInfo.m_StyleHash.Remove(pName);
  6607. }
  6608. }
  6609. return true;
  6610. }
  6611. const CStdStringPtrMap& CPaintManagerUI::GetStyles(bool bShared) const
  6612. {
  6613. if (bShared) return m_SharedResInfo.m_StyleHash;
  6614. else return m_ResInfo.m_StyleHash;
  6615. }
  6616. void CPaintManagerUI::RemoveAllStyle(bool bShared)
  6617. {
  6618. if (bShared)
  6619. {
  6620. CDuiString* pStyle;
  6621. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  6622. {
  6623. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  6624. {
  6625. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key));
  6626. delete pStyle;
  6627. }
  6628. }
  6629. m_SharedResInfo.m_StyleHash.RemoveAll();
  6630. }
  6631. else
  6632. {
  6633. CDuiString* pStyle;
  6634. for (int i = 0; i < m_ResInfo.m_StyleHash.GetSize(); i++)
  6635. {
  6636. if (LPCTSTR key = m_ResInfo.m_StyleHash.GetAt(i))
  6637. {
  6638. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(key));
  6639. delete pStyle;
  6640. }
  6641. }
  6642. m_ResInfo.m_StyleHash.RemoveAll();
  6643. }
  6644. }
  6645. const TImageInfo* CPaintManagerUI::GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify)
  6646. {
  6647. CDuiString sImageName = pStrImage;
  6648. CDuiString sImageResType = _T("");
  6649. DWORD dwMask = 0;
  6650. CDuiString sItem;
  6651. CDuiString sValue;
  6652. LPTSTR pstr = NULL;
  6653. for (int i = 0; i < 2; ++i)
  6654. {
  6655. if (i == 1)
  6656. pStrImage = pStrModify;
  6657. if (!pStrImage) continue;
  6658. while (*pStrImage != _T('\0'))
  6659. {
  6660. sItem.Empty();
  6661. sValue.Empty();
  6662. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  6663. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  6664. {
  6665. LPTSTR pstrTemp = ::CharNext(pStrImage);
  6666. while (pStrImage < pstrTemp)
  6667. {
  6668. sItem += *pStrImage++;
  6669. }
  6670. }
  6671. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  6672. if (*pStrImage++ != _T('=')) break;
  6673. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  6674. if (*pStrImage++ != _T('\'')) break;
  6675. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  6676. {
  6677. LPTSTR pstrTemp = ::CharNext(pStrImage);
  6678. while (pStrImage < pstrTemp)
  6679. {
  6680. sValue += *pStrImage++;
  6681. }
  6682. }
  6683. if (*pStrImage++ != _T('\'')) break;
  6684. if (!sValue.IsEmpty())
  6685. {
  6686. if (sItem == _T("file") || sItem == _T("res"))
  6687. {
  6688. sImageName = sValue;
  6689. }
  6690. else if (sItem == _T("restype"))
  6691. {
  6692. sImageResType = sValue;
  6693. }
  6694. else if (sItem == _T("mask"))
  6695. {
  6696. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  6697. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  6698. }
  6699. }
  6700. if (*pStrImage++ != _T(' ')) break;
  6701. }
  6702. }
  6703. return GetImageEx(sImageName, sImageResType, dwMask);
  6704. }
  6705. bool CPaintManagerUI::EnableDragDrop(bool bEnable)
  6706. {
  6707. if (m_bDragDrop == bEnable) return false;
  6708. m_bDragDrop = bEnable;
  6709. if (bEnable)
  6710. {
  6711. AddRef();
  6712. if (FAILED(RegisterDragDrop(m_hWndPaint, this)))
  6713. {
  6714. return false;
  6715. }
  6716. SetTargetWnd(m_hWndPaint);
  6717. FORMATETC ftetc = { 0 };
  6718. ftetc.cfFormat = CF_BITMAP;
  6719. ftetc.dwAspect = DVASPECT_CONTENT;
  6720. ftetc.lindex = -1;
  6721. ftetc.tymed = TYMED_GDI;
  6722. AddSuportedFormat(ftetc);
  6723. ftetc.cfFormat = CF_DIB;
  6724. ftetc.tymed = TYMED_HGLOBAL;
  6725. AddSuportedFormat(ftetc);
  6726. ftetc.cfFormat = CF_HDROP;
  6727. ftetc.tymed = TYMED_HGLOBAL;
  6728. AddSuportedFormat(ftetc);
  6729. ftetc.cfFormat = CF_ENHMETAFILE;
  6730. ftetc.tymed = TYMED_ENHMF;
  6731. AddSuportedFormat(ftetc);
  6732. }
  6733. else
  6734. {
  6735. Release();
  6736. if (FAILED(RevokeDragDrop(m_hWndPaint)))
  6737. {
  6738. return false;
  6739. }
  6740. }
  6741. return true;
  6742. }
  6743. void CPaintManagerUI::SetDragDrop(IDragDropUI* pDragDrop)
  6744. {
  6745. m_pDragDrop = pDragDrop;
  6746. }
  6747. static WORD DIBNumColors(void* pv)
  6748. {
  6749. int bits;
  6750. LPBITMAPINFOHEADER lpbi;
  6751. LPBITMAPCOREHEADER lpbc;
  6752. lpbi = ((LPBITMAPINFOHEADER)pv);
  6753. lpbc = ((LPBITMAPCOREHEADER)pv);
  6754. /* With the BITMAPINFO format headers, the size of the palette
  6755. * is in biClrUsed, whereas in the BITMAPCORE - style headers, it
  6756. * is dependent on the bits per pixel ( = 2 raised to the power of
  6757. * bits/pixel).
  6758. */
  6759. if (lpbi->biSize != sizeof(BITMAPCOREHEADER))
  6760. {
  6761. if (lpbi->biClrUsed != 0)
  6762. return (WORD)lpbi->biClrUsed;
  6763. bits = lpbi->biBitCount;
  6764. }
  6765. else
  6766. bits = lpbc->bcBitCount;
  6767. switch (bits)
  6768. {
  6769. case 1:
  6770. return 2;
  6771. case 4:
  6772. return 16;
  6773. case 8:
  6774. return 256;
  6775. default:
  6776. /* A 24 bitcount DIB has no color table */
  6777. return 0;
  6778. }
  6779. }
  6780. //code taken from SEEDIB MSDN sample
  6781. static WORD ColorTableSize(LPVOID lpv)
  6782. {
  6783. LPBITMAPINFOHEADER lpbih = (LPBITMAPINFOHEADER)lpv;
  6784. if (lpbih->biSize != sizeof(BITMAPCOREHEADER))
  6785. {
  6786. if (((LPBITMAPINFOHEADER)(lpbih))->biCompression == BI_BITFIELDS)
  6787. /* Remember that 16/32bpp dibs can still have a color table */
  6788. return (sizeof(DWORD) * 3) + (DIBNumColors(lpbih) * sizeof(RGBQUAD));
  6789. else
  6790. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBQUAD));
  6791. }
  6792. else
  6793. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBTRIPLE));
  6794. }
  6795. bool CPaintManagerUI::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect)
  6796. {
  6797. POINT ptMouse = { 0 };
  6798. GetCursorPos(&ptMouse);
  6799. ::SendMessage(m_hTargetWnd, WM_LBUTTONUP, NULL, MAKELPARAM(ptMouse.x, ptMouse.y));
  6800. if (pFmtEtc->cfFormat == CF_DIB && medium.tymed == TYMED_HGLOBAL)
  6801. {
  6802. if (medium.hGlobal != NULL)
  6803. {
  6804. LPBITMAPINFOHEADER lpbi = (BITMAPINFOHEADER*)GlobalLock(medium.hGlobal);
  6805. if (lpbi != NULL)
  6806. {
  6807. HBITMAP hbm = NULL;
  6808. HDC hdc = GetDC(NULL);
  6809. if (hdc != NULL)
  6810. {
  6811. int i = ((BITMAPFILEHEADER*)lpbi)->bfOffBits;
  6812. hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi,
  6813. (LONG)CBM_INIT,
  6814. (LPSTR)lpbi + lpbi->biSize + ColorTableSize(lpbi),
  6815. (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
  6816. ::ReleaseDC(NULL, hdc);
  6817. }
  6818. GlobalUnlock(medium.hGlobal);
  6819. if (hbm != NULL)
  6820. hbm = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
  6821. if (hbm != NULL)
  6822. DeleteObject(hbm);
  6823. return true; //release the medium
  6824. }
  6825. }
  6826. }
  6827. if (pFmtEtc->cfFormat == CF_BITMAP && medium.tymed == TYMED_GDI)
  6828. {
  6829. if (medium.hBitmap != NULL)
  6830. {
  6831. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)medium.hBitmap);
  6832. if (hBmp != NULL)
  6833. DeleteObject(hBmp);
  6834. return false; //don't free the bitmap
  6835. }
  6836. }
  6837. if (pFmtEtc->cfFormat == CF_ENHMETAFILE && medium.tymed == TYMED_ENHMF)
  6838. {
  6839. ENHMETAHEADER emh;
  6840. GetEnhMetaFileHeader(medium.hEnhMetaFile, sizeof(ENHMETAHEADER), &emh);
  6841. RECT rc;//={0,0,EnhMetaHdr.rclBounds.right-EnhMetaHdr.rclBounds.left, EnhMetaHdr.rclBounds.bottom-EnhMetaHdr.rclBounds.top};
  6842. HDC hDC = GetDC(m_hTargetWnd);
  6843. //start code: taken from ENHMETA.EXE MSDN Sample
  6844. //*ALSO NEED to GET the pallete (select and RealizePalette it, but i was too lazy*
  6845. // Get the characteristics of the output device
  6846. float PixelsX = (float)GetDeviceCaps(hDC, HORZRES);
  6847. float PixelsY = (float)GetDeviceCaps(hDC, VERTRES);
  6848. float MMX = (float)GetDeviceCaps(hDC, HORZSIZE);
  6849. float MMY = (float)GetDeviceCaps(hDC, VERTSIZE);
  6850. // Calculate the rect in which to draw the metafile based on the
  6851. // intended size and the current output device resolution
  6852. // Remember that the intended size is given in 0.01mm units, so
  6853. // convert those to device units on the target device
  6854. rc.top = (int)((float)(emh.rclFrame.top) * PixelsY / (MMY * 100.0f));
  6855. rc.left = (int)((float)(emh.rclFrame.left) * PixelsX / (MMX * 100.0f));
  6856. rc.right = (int)((float)(emh.rclFrame.right) * PixelsX / (MMX * 100.0f));
  6857. rc.bottom = (int)((float)(emh.rclFrame.bottom) * PixelsY / (MMY * 100.0f));
  6858. //end code: taken from ENHMETA.EXE MSDN Sample
  6859. HDC hdcMem = CreateCompatibleDC(hDC);
  6860. HGDIOBJ hBmpMem = CreateCompatibleBitmap(hDC, emh.rclBounds.right, emh.rclBounds.bottom);
  6861. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBmpMem);
  6862. PlayEnhMetaFile(hdcMem, medium.hEnhMetaFile, &rc);
  6863. HBITMAP hBmp = (HBITMAP)::SelectObject(hdcMem, hOldBmp);
  6864. DeleteDC(hdcMem);
  6865. ReleaseDC(m_hTargetWnd, hDC);
  6866. hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
  6867. if (hBmp != NULL)
  6868. DeleteObject(hBmp);
  6869. return true;
  6870. }
  6871. if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
  6872. {
  6873. HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
  6874. if (hDrop != NULL)
  6875. {
  6876. TCHAR szFileName[MAX_PATH];
  6877. UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
  6878. if (cFiles > 0)
  6879. {
  6880. DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName));
  6881. HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
  6882. if (hBitmap)
  6883. {
  6884. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
  6885. if (hBmp != NULL)
  6886. DeleteObject(hBmp);
  6887. }
  6888. }
  6889. }
  6890. GlobalUnlock(medium.hGlobal);
  6891. }
  6892. return true; //let base free the medium
  6893. }
  6894. } // namespace DuiLib
  6895. #pragma warning(pop)