UIManager.cpp 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902
  1. #include "StdAfx.h"
  2. #include <zmouse.h>
  3. #pragma warning(push)
  4. #pragma warning(disable:4838 4244)
  5. namespace DuiLib
  6. {
  7. /////////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //
  10. // 触屏参数(NIM Duilib 模型)
  11. // TOUCHINPUT 的坐标以 1/100 像素为单位,必须先换算成像素
  12. #ifndef TOUCH_COORD_TO_PIXEL
  13. #define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
  14. #endif
  15. // [触屏模型变更] 不再使用 tap-slop 阈值:100% 照搬 NIM Duilib,触摸“点击”交给 Windows
  16. // 为触摸模拟的 WM_LBUTTONDOWN/UP(原生鼠标路径),滚动交给原生 UIEVENT_TOUCHMOVE,
  17. // 二者由 m_pEventTouch 守卫互斥,无需自定滑动阈值。
  18. // WM_TOUCH 消息 ID 同样受 `#if _WIN32_WINNT >= 0x0601` 保护,DuiLib 工程未定义
  19. // _WIN32_WINNT(StdAfx.h 兜底为 XP)→ 必须自行声明,否则 switch 里引用该消息 ID
  20. // 会报 C2065(未声明的标识符)与 C2051(case 表达式不是常量)。实测固定值 0x0240。
  21. // 注:Win7+ 段受保护的不仅有结构体与函数,**消息 ID 与辅助宏同样在内**,
  22. // TOUCH_COORD_TO_PIXEL 也在上面用 #ifndef 兜底,原因相同。
  23. #ifndef WM_TOUCH
  24. #define WM_TOUCH 0x0240
  25. #endif
  26. static void GetChildWndRect(HWND hWnd, HWND hChildWnd, RECT& rcChildWnd)
  27. {
  28. ::GetWindowRect(hChildWnd, &rcChildWnd);
  29. POINT pt;
  30. pt.x = rcChildWnd.left;
  31. pt.y = rcChildWnd.top;
  32. ::ScreenToClient(hWnd, &pt);
  33. rcChildWnd.left = pt.x;
  34. rcChildWnd.top = pt.y;
  35. pt.x = rcChildWnd.right;
  36. pt.y = rcChildWnd.bottom;
  37. ::ScreenToClient(hWnd, &pt);
  38. rcChildWnd.right = pt.x;
  39. rcChildWnd.bottom = pt.y;
  40. }
  41. static UINT MapKeyState()
  42. {
  43. UINT uState = 0;
  44. if (::GetKeyState(VK_CONTROL) < 0) uState |= MK_CONTROL;
  45. if (::GetKeyState(VK_LBUTTON) < 0) uState |= MK_LBUTTON;
  46. if (::GetKeyState(VK_RBUTTON) < 0) uState |= MK_RBUTTON;
  47. if (::GetKeyState(VK_SHIFT) < 0) uState |= MK_SHIFT;
  48. if (::GetKeyState(VK_MENU) < 0) uState |= MK_ALT;
  49. return uState;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. ///
  53. typedef struct tagFINDTABINFO
  54. {
  55. CControlUI* pFocus;
  56. CControlUI* pLast;
  57. bool bForward;
  58. bool bNextIsIt;
  59. } FINDTABINFO;
  60. typedef struct tagFINDSHORTCUT
  61. {
  62. TCHAR ch;
  63. bool bPickNext;
  64. } FINDSHORTCUT;
  65. typedef struct tagTIMERINFO
  66. {
  67. CControlUI* pSender;
  68. UINT nLocalID;
  69. HWND hWnd;
  70. UINT uWinTimer;
  71. bool bKilled;
  72. } TIMERINFO;
  73. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. ///
  75. tagTImageInfo::tagTImageInfo()
  76. {
  77. pImage = NULL;
  78. hBitmap = NULL;
  79. }
  80. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. ///
  82. tagTDrawInfo::tagTDrawInfo()
  83. {
  84. Clear();
  85. }
  86. void tagTDrawInfo::Parse(LPCTSTR pStrImage, LPCTSTR pStrModify, CPaintManagerUI* pManager)
  87. {
  88. // 1、aaa.jpg
  89. // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
  90. // mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false'
  91. sDrawString = pStrImage;
  92. sDrawModify = pStrModify;
  93. sImageName = pStrImage;
  94. CDuiString sItem;
  95. CDuiString sValue;
  96. LPTSTR pstr = NULL;
  97. for (int i = 0; i < 2; ++i)
  98. {
  99. if (i == 1) pStrImage = pStrModify;
  100. if (!pStrImage) continue;
  101. while (*pStrImage != _T('\0'))
  102. {
  103. sItem.Empty();
  104. sValue.Empty();
  105. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  106. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  107. {
  108. LPTSTR pstrTemp = ::CharNext(pStrImage);
  109. while (pStrImage < pstrTemp)
  110. {
  111. sItem += *pStrImage++;
  112. }
  113. }
  114. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  115. if (*pStrImage++ != _T('=')) break;
  116. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  117. if (*pStrImage++ != _T('\'')) break;
  118. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  119. {
  120. LPTSTR pstrTemp = ::CharNext(pStrImage);
  121. while (pStrImage < pstrTemp)
  122. {
  123. sValue += *pStrImage++;
  124. }
  125. }
  126. if (*pStrImage++ != _T('\'')) break;
  127. if (!sValue.IsEmpty())
  128. {
  129. if (sItem == _T("file") || sItem == _T("res"))
  130. {
  131. sImageName = sValue;
  132. }
  133. else if (sItem == _T("restype"))
  134. {
  135. sResType = sValue;
  136. }
  137. else if (sItem == _T("dest"))
  138. {
  139. rcDest.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  140. rcDest.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  141. rcDest.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  142. rcDest.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  143. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcDest);
  144. }
  145. else if (sItem == _T("source"))
  146. {
  147. rcSource.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  148. rcSource.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  149. rcSource.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  150. rcSource.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  151. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcSource);
  152. }
  153. else if (sItem == _T("corner"))
  154. {
  155. rcCorner.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  156. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  157. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  158. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  159. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcCorner);
  160. }
  161. else if (sItem == _T("mask"))
  162. {
  163. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  164. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  165. }
  166. else if (sItem == _T("fade"))
  167. {
  168. uFade = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  169. }
  170. else if (sItem == _T("rotate"))
  171. {
  172. uRotate = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  173. bGdiplus = true;
  174. }
  175. else if (sItem == _T("gdiplus"))
  176. {
  177. bGdiplus = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  178. }
  179. else if (sItem == _T("hole"))
  180. {
  181. bHole = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  182. }
  183. else if (sItem == _T("xtiled"))
  184. {
  185. bTiledX = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  186. }
  187. else if (sItem == _T("ytiled"))
  188. {
  189. bTiledY = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  190. }
  191. else if (sItem == _T("hsl"))
  192. {
  193. bHSL = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  194. }
  195. else if (sItem == _T("size"))
  196. {
  197. szImage.cx = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  198. szImage.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  199. }
  200. else if (sItem == _T("align"))
  201. {
  202. sAlign = sValue;
  203. }
  204. else if (sItem == _T("padding"))
  205. {
  206. rcPadding.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  207. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  208. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  209. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  210. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcPadding);
  211. }
  212. }
  213. if (*pStrImage++ != _T(' ')) break;
  214. }
  215. }
  216. // 调整DPI资源
  217. if (pManager != NULL && pManager->GetDPIObj()->GetScale() != 100)
  218. {
  219. CDuiString sScale;
  220. sScale.Format(_T("@%d."), pManager->GetDPIObj()->GetScale());
  221. sImageName.Replace(_T("."), sScale);
  222. }
  223. }
  224. void tagTDrawInfo::Clear()
  225. {
  226. sDrawString.Empty();
  227. sDrawModify.Empty();
  228. sImageName.Empty();
  229. memset(&rcDest, 0, sizeof(RECT));
  230. memset(&rcSource, 0, sizeof(RECT));
  231. memset(&rcCorner, 0, sizeof(RECT));
  232. dwMask = 0;
  233. uFade = 255;
  234. uRotate = 0;
  235. bHole = false;
  236. bTiledX = false;
  237. bTiledY = false;
  238. bHSL = false;
  239. bGdiplus = false;
  240. szImage.cx = szImage.cy = 0;
  241. sAlign.Empty();
  242. memset(&rcPadding, 0, sizeof(RECT));
  243. }
  244. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. ///
  246. typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  247. PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL;
  248. HPEN m_hUpdateRectPen = NULL;
  249. HINSTANCE CPaintManagerUI::m_hResourceInstance = NULL;
  250. CDuiString CPaintManagerUI::m_pStrResourcePath;
  251. CDuiString CPaintManagerUI::m_pStrResourceZip;
  252. CDuiString CPaintManagerUI::m_pStrResourceZipPwd; //Garfield 20160325 带密码zip包解密
  253. HANDLE CPaintManagerUI::m_hResourceZip = NULL;
  254. bool CPaintManagerUI::m_bCachedResourceZip = true;
  255. BYTE* CPaintManagerUI::m_cbZipBuf = nullptr;
  256. int CPaintManagerUI::m_nResType = UILIB_FILE;
  257. TResInfo CPaintManagerUI::m_SharedResInfo;
  258. HINSTANCE CPaintManagerUI::m_hInstance = NULL;
  259. bool CPaintManagerUI::m_bUseHSL = false;
  260. short CPaintManagerUI::m_H = 180;
  261. short CPaintManagerUI::m_S = 100;
  262. short CPaintManagerUI::m_L = 100;
  263. CStdPtrArray CPaintManagerUI::m_aPreMessages;
  264. CStdPtrArray CPaintManagerUI::m_aPlugins;
  265. CPaintManagerUI::CPaintManagerUI() :
  266. m_hWndPaint(NULL),
  267. m_hDcPaint(NULL),
  268. m_hDcOffscreen(NULL),
  269. m_hDcBackground(NULL),
  270. m_bOffscreenPaint(true),
  271. m_hbmpOffscreen(NULL),
  272. m_pOffscreenBits(NULL),
  273. m_hbmpBackground(NULL),
  274. m_pBackgroundBits(NULL),
  275. m_hwndTooltip(NULL),
  276. m_uTimerID(0x1000),
  277. m_pRoot(NULL),
  278. m_pFocus(NULL),
  279. m_pEventHover(NULL),
  280. m_pEventClick(NULL),
  281. m_pEventRClick(NULL),
  282. m_pEventKey(NULL),
  283. m_bFirstLayout(true),
  284. m_bFocusNeeded(false),
  285. m_bUpdateNeeded(false),
  286. m_bMouseTracking(false),
  287. m_bMouseCapture(false),
  288. m_bAsyncNotifyPosted(false),
  289. m_bUsedVirtualWnd(false),
  290. m_bForceUseSharedRes(false),
  291. m_nOpacity(0xFF),
  292. m_bLayered(false),
  293. m_bLayeredChanged(false),
  294. m_bShowUpdateRect(false),
  295. m_bUseGdiplusText(false),
  296. m_trh(0),
  297. m_bDragDrop(false),
  298. m_bDragMode(false),
  299. m_hDragBitmap(NULL),
  300. m_pDPI(NULL),
  301. m_iHoverTime(400UL),
  302. // [FIX] m_bNoActivate 原本未初始化:Debug 堆新块填充 0xCD -> 读到 true;
  303. // Release 下则是随机垃圾值,属偶发性隐患。
  304. // 后果:本文件中 3 处 "if (!m_bNoActivate) ::SetFocus(m_hWndPaint);"
  305. // (WM_LBUTTONDOWN 1738 / CPaintManagerUI::SetFocus 2442 / SetFocusNeeded 2475) 全部被跳过,
  306. // 系统焦点无法回到主窗口 -> 原生 EDIT 子窗 CEditWnd 收不到 WM_KILLFOCUS ->
  307. // 其唯一的销毁途径 PostMessage(WM_CLOSE) 永不触发 -> 光标常闪、点空白不丢焦点。
  308. // XML 侧仅在显式书写 noactivate 属性时才赋值(UIDlgBuilder.cpp),故此处必须先给确定初值。
  309. m_bNoActivate(false),
  310. // 以下两个成员同样是漏网之鱼(全库无赋值点),一并清零以防后患。
  311. m_bIsPainting(false),
  312. m_pLastToolTip(NULL)
  313. {
  314. if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  315. {
  316. m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA;
  317. m_SharedResInfo.m_dwDefaultFontColor = 0xFF000000;
  318. m_SharedResInfo.m_dwDefaultLinkFontColor = 0xFF0000FF;
  319. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = 0xFFD3215F;
  320. m_SharedResInfo.m_dwDefaultSelectedBkColor = 0xFFBAE4FF;
  321. LOGFONT lf = { 0 };
  322. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  323. lf.lfCharSet = DEFAULT_CHARSET;
  324. HFONT hDefaultFont = ::CreateFontIndirect(&lf);
  325. m_SharedResInfo.m_DefaultFontInfo.hFont = hDefaultFont;
  326. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  327. m_SharedResInfo.m_DefaultFontInfo.iSize = -lf.lfHeight;
  328. m_SharedResInfo.m_DefaultFontInfo.bBold = (lf.lfWeight >= FW_BOLD);
  329. m_SharedResInfo.m_DefaultFontInfo.bUnderline = (lf.lfUnderline == TRUE);
  330. m_SharedResInfo.m_DefaultFontInfo.bItalic = (lf.lfItalic == TRUE);
  331. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  332. }
  333. m_ResInfo.m_dwDefaultDisabledColor = m_SharedResInfo.m_dwDefaultDisabledColor;
  334. m_ResInfo.m_dwDefaultFontColor = m_SharedResInfo.m_dwDefaultFontColor;
  335. m_ResInfo.m_dwDefaultLinkFontColor = m_SharedResInfo.m_dwDefaultLinkFontColor;
  336. m_ResInfo.m_dwDefaultLinkHoverFontColor = m_SharedResInfo.m_dwDefaultLinkHoverFontColor;
  337. m_ResInfo.m_dwDefaultSelectedBkColor = m_SharedResInfo.m_dwDefaultSelectedBkColor;
  338. if (m_hUpdateRectPen == NULL)
  339. {
  340. m_hUpdateRectPen = ::CreatePen(PS_SOLID, 1, RGB(220, 0, 0));
  341. // Boot Windows Common Controls (for the ToolTip control)
  342. ::InitCommonControls();
  343. ::LoadLibrary(_T("msimg32.dll"));
  344. }
  345. m_szMinWindow.cx = 0;
  346. m_szMinWindow.cy = 0;
  347. m_szMaxWindow.cx = 0;
  348. m_szMaxWindow.cy = 0;
  349. m_szInitWindowSize.cx = 0;
  350. m_szInitWindowSize.cy = 0;
  351. m_szRoundCorner.cx = m_szRoundCorner.cy = 0;
  352. ::ZeroMemory(&m_rcSizeBox, sizeof(m_rcSizeBox));
  353. ::ZeroMemory(&m_rcCaption, sizeof(m_rcCaption));
  354. ::ZeroMemory(&m_rcLayeredInset, sizeof(m_rcLayeredInset));
  355. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  356. m_ptLastMousePos.x = m_ptLastMousePos.y = -1;
  357. m_pGdiplusStartupInput = new Gdiplus::GdiplusStartupInput;
  358. Gdiplus::GdiplusStartup(&m_gdiplusToken, m_pGdiplusStartupInput, NULL); // 加载GDI接口
  359. CShadowUI::Initialize(m_hInstance);
  360. m_pDragDrop = NULL;
  361. }
  362. CPaintManagerUI::~CPaintManagerUI()
  363. {
  364. // Delete the control-tree structures
  365. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++) delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  366. m_aDelayedCleanup.Resize(0);
  367. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  368. m_aAsyncNotify.Resize(0);
  369. m_mNameHash.Resize(0);
  370. if (m_pRoot != NULL) delete m_pRoot;
  371. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  372. RemoveAllFonts();
  373. RemoveAllImages();
  374. RemoveAllStyle();
  375. RemoveAllDefaultAttributeList();
  376. RemoveAllWindowCustomAttribute();
  377. RemoveAllOptionGroups();
  378. RemoveAllTimers();
  379. RemoveAllDrawInfos();
  380. if (m_hwndTooltip != NULL)
  381. {
  382. ::DestroyWindow(m_hwndTooltip);
  383. m_hwndTooltip = NULL;
  384. }
  385. if (!m_aFonts.IsEmpty())
  386. {
  387. for (int i = 0; i < m_aFonts.GetSize(); ++i)
  388. {
  389. HANDLE handle = static_cast<HANDLE>(m_aFonts.GetAt(i));
  390. ::RemoveFontMemResourceEx(handle);
  391. }
  392. }
  393. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  394. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  395. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  396. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  397. if (m_hDcPaint != NULL) ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  398. m_aPreMessages.Remove(m_aPreMessages.Find(this));
  399. // 销毁拖拽图片
  400. if (m_hDragBitmap != NULL) ::DeleteObject(m_hDragBitmap);
  401. //卸载GDIPlus
  402. Gdiplus::GdiplusShutdown(m_gdiplusToken);
  403. delete m_pGdiplusStartupInput;
  404. // DPI管理对象
  405. if (m_pDPI != NULL)
  406. {
  407. delete m_pDPI;
  408. m_pDPI = NULL;
  409. }
  410. }
  411. void CPaintManagerUI::Init(HWND hWnd, LPCTSTR pstrName)
  412. {
  413. ASSERT(::IsWindow(hWnd));
  414. m_mNameHash.Resize();
  415. RemoveAllFonts();
  416. RemoveAllImages();
  417. RemoveAllStyle();
  418. RemoveAllDefaultAttributeList();
  419. RemoveAllWindowCustomAttribute();
  420. RemoveAllOptionGroups();
  421. RemoveAllTimers();
  422. m_sName.Empty();
  423. if (pstrName != NULL) m_sName = pstrName;
  424. if (m_hWndPaint != hWnd)
  425. {
  426. m_hWndPaint = hWnd;
  427. m_hDcPaint = ::GetDC(hWnd);
  428. m_aPreMessages.Add(this);
  429. // 触屏兼容:每个窗口(主窗口 + 所有弹框)统一注册 WM_TOUCH,由本类库级接管,
  430. // 无需 CTouchWindowBase 外挂,也无需逐窗口样板。注册是幂等的,重复调用无害。
  431. InitTouchSupport();
  432. }
  433. }
  434. // ---------------------------------------------------------------------------
  435. // 触摸 API 懒加载包装(对标 NIM Duilib 的 RegisterTouchWindowWrapper 系列)。
  436. //
  437. // 为什么不能直接调用这些 API:DuiLib 工程自身没有定义 _WIN32_WINNT,
  438. // StdAfx.h 会把它兜底设成 XP(0x0501);而 TOUCHINPUT / GetTouchInputInfo /
  439. // RegisterTouchWindow 在 winuser.h 里受 `#if _WIN32_WINNT >= 0x0601` 保护,
  440. // 直接引用会编译报错(C2065/C3861)。(主工程定义了 0x0601,所以
  441. // CTouchWindowBase 里能直接用,那里不受影响。)
  442. //
  443. // 因此这里完全自给自足:自行声明与 SDK 完全一致的 TOUCHINPUT 布局和事件标志,
  444. // 再用 GetProcAddress 取函数地址。这样:
  445. // * 无论 DuiLib 的 target 版本如何都能编译通过;
  446. // * 在没有触摸 API 的系统上自动降级为空操作,不会崩溃。
  447. // ---------------------------------------------------------------------------
  448. namespace TouchApi
  449. {
  450. // 与 winuser.h 的 tagTOUCHINPUT 布局逐字段一致
  451. typedef struct tagTouchInput
  452. {
  453. LONG x;
  454. LONG y;
  455. HANDLE hSource;
  456. DWORD dwID;
  457. DWORD dwFlags;
  458. DWORD dwMask;
  459. DWORD dwTime;
  460. ULONG_PTR dwExtraInfo;
  461. DWORD cxContact;
  462. DWORD cyContact;
  463. } TOUCHINPUT, *PTOUCHINPUT;
  464. // 事件标志,数值与 winuser.h 的触摸事件标志一致。
  465. // 名字必须避开 SDK 的同名宏:部分 SDK 把它们定义成【宏】,且不受 _WIN32_WINNT 版本段保护,
  466. // 同名会被预处理器展开——声明变成 `const DWORD 0x0002 = 0x0002;`(C2059),
  467. // 限定使用变成 `TouchApi::0x0004`(C2589)。故改用 TOUCHEVTFLAG 前缀。
  468. const DWORD TOUCHEVTFLAG_MOVE = 0x0002;
  469. const DWORD TOUCHEVTFLAG_DOWN = 0x0004;
  470. const DWORD TOUCHEVTFLAG_UP = 0x0008;
  471. typedef BOOL (WINAPI *PFN_RegisterTouchWindow)(HWND, ULONG);
  472. typedef BOOL (WINAPI *PFN_GetTouchInputInfo)(HANDLE, UINT, PTOUCHINPUT, int);
  473. typedef BOOL (WINAPI *PFN_CloseTouchInputHandle)(HANDLE);
  474. inline HMODULE GetUser32()
  475. {
  476. static HMODULE s_hMod = NULL;
  477. static bool s_bInited = false;
  478. if (!s_bInited)
  479. {
  480. s_bInited = true;
  481. s_hMod = ::GetModuleHandle(_T("user32.dll"));
  482. }
  483. return s_hMod;
  484. }
  485. inline PFN_RegisterTouchWindow GetRegisterTouchWindow()
  486. {
  487. static PFN_RegisterTouchWindow s_pfn = NULL;
  488. static bool s_bInited = false;
  489. if (!s_bInited)
  490. {
  491. s_bInited = true;
  492. HMODULE hMod = GetUser32();
  493. if (hMod != NULL) s_pfn = (PFN_RegisterTouchWindow)::GetProcAddress(hMod, "RegisterTouchWindow");
  494. }
  495. return s_pfn;
  496. }
  497. inline PFN_GetTouchInputInfo GetGetTouchInputInfo()
  498. {
  499. static PFN_GetTouchInputInfo s_pfn = NULL;
  500. static bool s_bInited = false;
  501. if (!s_bInited)
  502. {
  503. s_bInited = true;
  504. HMODULE hMod = GetUser32();
  505. if (hMod != NULL) s_pfn = (PFN_GetTouchInputInfo)::GetProcAddress(hMod, "GetTouchInputInfo");
  506. }
  507. return s_pfn;
  508. }
  509. inline PFN_CloseTouchInputHandle GetCloseTouchInputHandle()
  510. {
  511. static PFN_CloseTouchInputHandle s_pfn = NULL;
  512. static bool s_bInited = false;
  513. if (!s_bInited)
  514. {
  515. s_bInited = true;
  516. HMODULE hMod = GetUser32();
  517. if (hMod != NULL) s_pfn = (PFN_CloseTouchInputHandle)::GetProcAddress(hMod, "CloseTouchInputHandle");
  518. }
  519. return s_pfn;
  520. }
  521. }
  522. void CPaintManagerUI::InitTouchSupport()
  523. {
  524. if (m_hWndPaint == NULL || !::IsWindow(m_hWndPaint)) return;
  525. TouchApi::PFN_RegisterTouchWindow pfnRegister = TouchApi::GetRegisterTouchWindow();
  526. if (pfnRegister != NULL)
  527. pfnRegister(m_hWndPaint, 0);
  528. }
  529. void CPaintManagerUI::OnTouchInput(WPARAM wParam, LPARAM lParam)
  530. {
  531. // 100% 照搬 NIM Duilib 的 Window::HandleMessage case WM_TOUCH(Window.cpp:1139-1199)。
  532. // 设计要点(不要自创归一化 / 状态机):
  533. // 1) 独立的 m_pEventTouch 追踪“本次触摸命中控件”,DOWN 设定、UP 清空;绝不复用 m_pEventClick。
  534. // 2) 只向控件派发“原生触摸事件” UIEVENT_TOUCHDOWN / UIEVENT_TOUCHMOVE / UIEVENT_TOUCHUP,
  535. // 由 CContainerUI::DoEvent 把 TOUCHMOVE 当作 1:1 跟手滚动(对标 NIM ScrollableBox)。
  536. // 3) 按钮“点击”不在这里合成!它来自 Windows 为触摸自动模拟的 WM_LBUTTONDOWN/UP,
  537. // 走 MessageHandler 里原生的鼠标点击路径(CButtonUI 等据此 Activate())。NIM 从不过滤
  538. // 这些模拟鼠标,只在 WM_LBUTTON* 分支加了 m_pEventTouch!=NULL 守卫,保证一次手指手势
  539. // 要么滚动、要么点击,不会双触发。
  540. // 4) 守卫:DOWN 时若真实鼠标已在交互(m_pEventClick 被真实鼠标置位)则忽略触摸;MOVE 仅对“滚动条”让路
  541. // (原生鼠标独占滑块拖拽),容器照常收 TOUCHMOVE 跟手滚动。注意 m_pEventClick 也会被触摸模拟的
  542. // WM_LBUTTONDOWN 置位,故不能仅因它非空就吞掉 TOUCHMOVE,否则列表滚不动。
  543. TouchApi::PFN_GetTouchInputInfo pfnGetInfo = TouchApi::GetGetTouchInputInfo();
  544. if (pfnGetInfo == NULL) return;
  545. UINT cInputs = LOWORD(wParam);
  546. if (cInputs == 0) return;
  547. std::vector<TouchApi::TOUCHINPUT> inputs(cInputs);
  548. if (!pfnGetInfo((HANDLE)lParam, cInputs, inputs.data(), (int)sizeof(TouchApi::TOUCHINPUT)))
  549. return;
  550. for (UINT i = 0; i < cInputs; ++i)
  551. {
  552. TouchApi::TOUCHINPUT& ti = inputs[i];
  553. // 仅处理主触点(dwID==0 为保留值,NIM 同款跳过)
  554. if (ti.dwID == 0) continue;
  555. POINT pt;
  556. pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
  557. pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
  558. ::ScreenToClient(m_hWndPaint, &pt);
  559. if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_DOWN)
  560. {
  561. // 鼠标/指针交互进行中 -> 忽略触摸(NIM 同款守卫)
  562. if (m_pEventClick != NULL) break;
  563. ::SetFocus(m_hWndPaint);
  564. m_ptLastTouchPos = pt;
  565. CControlUI* pControl = FindControl(pt);
  566. if (pControl == NULL) break;
  567. if (pControl->GetManager() != this) break;
  568. // 滚动条:滑块拖拽/点击由原生鼠标路径(模拟的 WM_LBUTTONDOWN/MOVE/UP)驱动;
  569. // 若此处再派发 UIEVENT_TOUCHMOVE 会冒泡到容器把【内容】滚走,与滑块拖拽打架→滑块拖不动、点轨道误翻页。
  570. // 直接交回原生鼠标,本函数提前退出(悬浮态由 WM_TOUCH UP 统一清理)。
  571. if (pControl->GetInterface(_T("ScrollBar")) != NULL)
  572. break;
  573. m_pEventTouch = pControl;
  574. m_bTouchMoved = false;
  575. m_ptTouchStart = pt;
  576. pControl->SetFocus();
  577. SetCapture(); // mgr 级:m_bMouseCapture=true + ::SetCapture
  578. TEventUI event = { 0 };
  579. event.Type = UIEVENT_TOUCHDOWN;
  580. event.pSender = pControl;
  581. event.ptMouse = pt;
  582. event.dwTimestamp = ::GetTickCount();
  583. event.wKeyState = MapKeyState();
  584. pControl->Event(event);
  585. }
  586. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_MOVE)
  587. {
  588. // 鼠标/指针交互进行中 -> 忽略触摸。但注意:一次触摸手势本身会触发 Windows 模拟的
  589. // WM_LBUTTONDOWN,从而把 m_pEventClick 置为【当前命中控件】(容器/按钮/滚动条都会)。
  590. // 若整句 break,会把容器的 UIEVENT_TOUCHMOVE 一起吞掉→列表无法跟手滚动。
  591. // 故只对“滚动条”让路(滚动条滑块拖拽由原生鼠标驱动,见 DOWN 的 ScrollBar break),
  592. // 其余控件(容器/按钮)照常派发 TOUCHMOVE:容器据此 1:1 跟手滚动,按钮不处理 TOUCHMOVE 无害。
  593. if (m_pEventClick != NULL && m_pEventClick->GetInterface(_T("ScrollBar")) != NULL) break;
  594. // 与上一包完全相同的点 -> 去重,避免无谓派发(NIM 同款守卫)
  595. if (m_ptLastTouchPos.x == pt.x && m_ptLastTouchPos.y == pt.y) break;
  596. // 本次位移增量(相对上一包),随事件下发,滚动容器据此做 1:1 跟手平移
  597. LONG dx = pt.x - m_ptLastTouchPos.x;
  598. LONG dy = pt.y - m_ptLastTouchPos.y;
  599. m_ptLastTouchPos = pt;
  600. // 相对手势起点的累计位移超过阈值 -> 判定为拖拽(用于松开时抑制点击)
  601. LONG ox = pt.x - m_ptTouchStart.x;
  602. LONG oy = pt.y - m_ptTouchStart.y;
  603. if (ox > 5 || ox < -5 || oy > 5 || oy < -5)
  604. m_bTouchMoved = true;
  605. if (m_pEventTouch == NULL) break;
  606. TEventUI event = { 0 };
  607. event.Type = UIEVENT_TOUCHMOVE;
  608. event.pSender = m_pEventTouch;
  609. event.ptMouse = pt;
  610. event.dwTimestamp = ::GetTickCount();
  611. event.wKeyState = MapKeyState();
  612. event.wParam = (WPARAM)(int)dx;
  613. event.lParam = (LPARAM)(int)dy;
  614. m_pEventTouch->Event(event);
  615. }
  616. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_UP)
  617. {
  618. m_ptLastTouchPos = pt;
  619. // 触屏抬起模拟“鼠标离开”:清除悬浮态。触摸永远不会生成 WM_MOUSELEAVE,
  620. // 若只清 m_pEventHover,m_aNeedMouseLeaveNeeded 数组里登记过的控件
  621. // (按钮/列表项/滚动条等曾收到 MOUSEENTER 并 AddMouseLeaveNeeded 的)会一直残留
  622. // 悬浮态,表现为“多个控件同时悬浮”。必须复刻 WM_MOUSEMOVE 里的离开广播:先遍历
  623. // 整个数组逐一发 MOUSELEAVE(控件自身在 MOUSELEAVE 里把自己从数组移除),再清 m_pEventHover。
  624. if (m_aNeedMouseLeaveNeeded.GetSize() > 0 || m_pEventHover != NULL)
  625. {
  626. TEventUI event = { 0 };
  627. event.Type = UIEVENT_MOUSELEAVE;
  628. event.ptMouse = pt;
  629. event.wKeyState = MapKeyState();
  630. event.dwTimestamp = ::GetTickCount();
  631. if (m_aNeedMouseLeaveNeeded.GetSize() > 0)
  632. {
  633. CStdPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  634. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  635. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  636. for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++)
  637. {
  638. CControlUI* pHover = static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i]);
  639. event.pSender = pHover;
  640. pHover->Event(event);
  641. }
  642. }
  643. if (m_pEventHover != NULL)
  644. {
  645. event.pSender = m_pEventHover;
  646. m_pEventHover->Event(event);
  647. m_pEventHover = NULL;
  648. }
  649. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  650. }
  651. // 滚动条等场景本函数未接管(m_pEventTouch 为 NULL),捕获由原生鼠标路径负责,这里不释放。
  652. if (m_pEventTouch == NULL) break;
  653. ReleaseCapture();
  654. TEventUI event = { 0 };
  655. event.Type = UIEVENT_TOUCHUP;
  656. event.pSender = m_pEventTouch;
  657. event.ptMouse = pt;
  658. event.dwTimestamp = ::GetTickCount();
  659. event.wKeyState = MapKeyState();
  660. m_pEventTouch->Event(event);
  661. m_pEventTouch = NULL;
  662. }
  663. }
  664. TouchApi::PFN_CloseTouchInputHandle pfnClose = TouchApi::GetCloseTouchInputHandle();
  665. if (pfnClose != NULL)
  666. pfnClose((HANDLE)lParam);
  667. }
  668. void CPaintManagerUI::DeletePtr(void* ptr)
  669. {
  670. if (ptr)
  671. {
  672. delete ptr; ptr = NULL;
  673. }
  674. }
  675. HINSTANCE CPaintManagerUI::GetInstance()
  676. {
  677. return m_hInstance;
  678. }
  679. CDuiString CPaintManagerUI::GetInstancePath()
  680. {
  681. if (m_hInstance == NULL) return _T('\0');
  682. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  683. ::GetModuleFileName(m_hInstance, tszModule, MAX_PATH);
  684. CDuiString sInstancePath = tszModule;
  685. int pos = sInstancePath.ReverseFind(_T('\\'));
  686. if (pos >= 0) sInstancePath = sInstancePath.Left(pos + 1);
  687. return sInstancePath;
  688. }
  689. CDuiString CPaintManagerUI::GetCurrentPath()
  690. {
  691. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  692. ::GetCurrentDirectory(MAX_PATH, tszModule);
  693. return tszModule;
  694. }
  695. HINSTANCE CPaintManagerUI::GetResourceDll()
  696. {
  697. if (m_hResourceInstance == NULL) return m_hInstance;
  698. return m_hResourceInstance;
  699. }
  700. const CDuiString& CPaintManagerUI::GetResourcePath()
  701. {
  702. return m_pStrResourcePath;
  703. }
  704. const CDuiString& CPaintManagerUI::GetResourceZip()
  705. {
  706. return m_pStrResourceZip;
  707. }
  708. const CDuiString& CPaintManagerUI::GetResourceZipPwd()
  709. {
  710. return m_pStrResourceZipPwd;
  711. }
  712. bool CPaintManagerUI::IsCachedResourceZip()
  713. {
  714. return m_bCachedResourceZip;
  715. }
  716. HANDLE CPaintManagerUI::GetResourceZipHandle()
  717. {
  718. return m_hResourceZip;
  719. }
  720. void CPaintManagerUI::SetInstance(HINSTANCE hInst)
  721. {
  722. m_hInstance = hInst;
  723. }
  724. void CPaintManagerUI::SetCurrentPath(LPCTSTR pStrPath)
  725. {
  726. ::SetCurrentDirectory(pStrPath);
  727. }
  728. void CPaintManagerUI::SetResourceDll(HINSTANCE hInst)
  729. {
  730. m_hResourceInstance = hInst;
  731. }
  732. void CPaintManagerUI::SetResourcePath(LPCTSTR pStrPath)
  733. {
  734. m_pStrResourcePath = pStrPath;
  735. if (m_pStrResourcePath.IsEmpty()) return;
  736. TCHAR cEnd = m_pStrResourcePath.GetAt(m_pStrResourcePath.GetLength() - 1);
  737. if (cEnd != _T('\\') && cEnd != _T('/')) m_pStrResourcePath += _T('\\');
  738. }
  739. void CPaintManagerUI::SetResourceZip(LPVOID pVoid, unsigned int len, LPCTSTR password)
  740. {
  741. if (m_pStrResourceZip == _T("membuffer")) return;
  742. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  743. {
  744. CloseZip((HZIP)m_hResourceZip);
  745. m_hResourceZip = NULL;
  746. }
  747. m_pStrResourceZip = _T("membuffer");
  748. if (m_cbZipBuf)
  749. {
  750. delete[] m_cbZipBuf;
  751. m_cbZipBuf = nullptr;
  752. }
  753. if (!m_cbZipBuf)
  754. {
  755. m_cbZipBuf = new BYTE[len];
  756. memcpy(m_cbZipBuf, pVoid, len);
  757. }
  758. m_bCachedResourceZip = true;
  759. m_pStrResourceZipPwd = password; //Garfield 20160325 带密码zip包解密
  760. if (m_bCachedResourceZip)
  761. {
  762. #ifdef UNICODE
  763. char* pwd = w2a((wchar_t*)password);
  764. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, pwd);
  765. if (pwd)
  766. {
  767. delete[] pwd;
  768. pwd = NULL;
  769. }
  770. #else
  771. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, password);
  772. #endif
  773. }
  774. }
  775. void CPaintManagerUI::SetResourceZip(LPCTSTR pStrPath, bool bCachedResourceZip, LPCTSTR password)
  776. {
  777. if (m_pStrResourceZip == pStrPath && m_bCachedResourceZip == bCachedResourceZip) return;
  778. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  779. {
  780. CloseZip((HZIP)m_hResourceZip);
  781. m_hResourceZip = NULL;
  782. }
  783. m_pStrResourceZip = pStrPath;
  784. m_bCachedResourceZip = bCachedResourceZip;
  785. m_pStrResourceZipPwd = password;
  786. if (m_bCachedResourceZip)
  787. {
  788. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  789. sFile += CPaintManagerUI::GetResourceZip();
  790. #ifdef UNICODE
  791. char* pwd = w2a((wchar_t*)password);
  792. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), pwd);
  793. if (pwd)
  794. {
  795. delete[] pwd;
  796. pwd = NULL;
  797. }
  798. #else
  799. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), password);
  800. #endif
  801. }
  802. }
  803. void CPaintManagerUI::SetResourceType(int nType)
  804. {
  805. m_nResType = nType;
  806. }
  807. int CPaintManagerUI::GetResourceType()
  808. {
  809. return m_nResType;
  810. }
  811. bool CPaintManagerUI::GetHSL(short* H, short* S, short* L)
  812. {
  813. *H = m_H;
  814. *S = m_S;
  815. *L = m_L;
  816. return m_bUseHSL;
  817. }
  818. void CPaintManagerUI::SetHSL(bool bUseHSL, short H, short S, short L)
  819. {
  820. if (m_bUseHSL || m_bUseHSL != bUseHSL)
  821. {
  822. m_bUseHSL = bUseHSL;
  823. if (H == m_H && S == m_S && L == m_L) return;
  824. m_H = CLAMP(H, 0, 360);
  825. m_S = CLAMP(S, 0, 200);
  826. m_L = CLAMP(L, 0, 200);
  827. AdjustSharedImagesHSL();
  828. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  829. {
  830. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  831. if (pManager != NULL) pManager->AdjustImagesHSL();
  832. }
  833. }
  834. }
  835. void CPaintManagerUI::ReloadSkin()
  836. {
  837. ReloadSharedImages();
  838. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  839. {
  840. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  841. pManager->ReloadImages();
  842. }
  843. }
  844. CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName)
  845. {
  846. if (pstrName == NULL) return NULL;
  847. CDuiString sName = pstrName;
  848. if (sName.IsEmpty()) return NULL;
  849. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  850. {
  851. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  852. if (pManager != NULL && sName == pManager->GetName()) return pManager;
  853. }
  854. return NULL;
  855. }
  856. CStdPtrArray* CPaintManagerUI::GetPaintManagers()
  857. {
  858. return &m_aPreMessages;
  859. }
  860. bool CPaintManagerUI::LoadPlugin(LPCTSTR pstrModuleName)
  861. {
  862. ASSERT(!::IsBadStringPtr(pstrModuleName, -1) || pstrModuleName == NULL);
  863. if (pstrModuleName == NULL) return false;
  864. HMODULE hModule = ::LoadLibrary(pstrModuleName);
  865. if (hModule != NULL)
  866. {
  867. LPCREATECONTROL lpCreateControl = (LPCREATECONTROL)::GetProcAddress(hModule, "CreateControl");
  868. if (lpCreateControl != NULL)
  869. {
  870. if (m_aPlugins.Find(lpCreateControl) >= 0) return true;
  871. m_aPlugins.Add(lpCreateControl);
  872. return true;
  873. }
  874. }
  875. return false;
  876. }
  877. CStdPtrArray* CPaintManagerUI::GetPlugins()
  878. {
  879. return &m_aPlugins;
  880. }
  881. HWND CPaintManagerUI::GetPaintWindow() const
  882. {
  883. return m_hWndPaint;
  884. }
  885. HWND CPaintManagerUI::GetTooltipWindow() const
  886. {
  887. return m_hwndTooltip;
  888. }
  889. int CPaintManagerUI::GetHoverTime() const
  890. {
  891. return m_iHoverTime;
  892. }
  893. void CPaintManagerUI::SetHoverTime(int iTime)
  894. {
  895. m_iHoverTime = iTime;
  896. }
  897. LPCTSTR CPaintManagerUI::GetName() const
  898. {
  899. return m_sName;
  900. }
  901. HDC CPaintManagerUI::GetPaintDC() const
  902. {
  903. return m_hDcPaint;
  904. }
  905. POINT CPaintManagerUI::GetMousePos() const
  906. {
  907. return m_ptLastMousePos;
  908. }
  909. SIZE CPaintManagerUI::GetClientSize() const
  910. {
  911. RECT rcClient = { 0 };
  912. ::GetClientRect(m_hWndPaint, &rcClient);
  913. return CDuiSize(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  914. }
  915. SIZE CPaintManagerUI::GetInitSize()
  916. {
  917. return m_szInitWindowSize;
  918. }
  919. void CPaintManagerUI::SetInitSize(int cx, int cy)
  920. {
  921. m_szInitWindowSize.cx = cx;
  922. m_szInitWindowSize.cy = cy;
  923. if (m_pRoot == NULL && m_hWndPaint != NULL)
  924. {
  925. ::SetWindowPos(m_hWndPaint, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  926. }
  927. }
  928. RECT CPaintManagerUI::GetSizeBox()
  929. {
  930. return GetDPIObj()->Scale(m_rcSizeBox);
  931. }
  932. void CPaintManagerUI::SetSizeBox(RECT& rcSizeBox)
  933. {
  934. m_rcSizeBox = rcSizeBox;
  935. }
  936. RECT CPaintManagerUI::GetCaptionRect()
  937. {
  938. return GetDPIObj()->Scale(m_rcCaption);
  939. }
  940. void CPaintManagerUI::SetCaptionRect(RECT& rcCaption)
  941. {
  942. m_rcCaption = rcCaption;
  943. }
  944. SIZE CPaintManagerUI::GetRoundCorner()
  945. {
  946. return GetDPIObj()->Scale(m_szRoundCorner);
  947. }
  948. void CPaintManagerUI::SetRoundCorner(int cx, int cy)
  949. {
  950. m_szRoundCorner.cx = cx;
  951. m_szRoundCorner.cy = cy;
  952. }
  953. SIZE CPaintManagerUI::GetMinInfo()
  954. {
  955. return GetDPIObj()->Scale(m_szMinWindow);
  956. }
  957. void CPaintManagerUI::SetMinInfo(int cx, int cy)
  958. {
  959. ASSERT(cx >= 0 && cy >= 0);
  960. m_szMinWindow.cx = cx;
  961. m_szMinWindow.cy = cy;
  962. }
  963. SIZE CPaintManagerUI::GetMaxInfo()
  964. {
  965. return GetDPIObj()->Scale(m_szMaxWindow);
  966. }
  967. void CPaintManagerUI::SetMaxInfo(int cx, int cy)
  968. {
  969. ASSERT(cx >= 0 && cy >= 0);
  970. m_szMaxWindow.cx = cx;
  971. m_szMaxWindow.cy = cy;
  972. }
  973. bool CPaintManagerUI::IsShowUpdateRect()
  974. {
  975. return m_bShowUpdateRect;
  976. }
  977. void CPaintManagerUI::SetShowUpdateRect(bool show)
  978. {
  979. m_bShowUpdateRect = show;
  980. }
  981. bool CPaintManagerUI::IsNoActivate()
  982. {
  983. return m_bNoActivate;
  984. }
  985. void CPaintManagerUI::SetNoActivate(bool bNoActivate)
  986. {
  987. m_bNoActivate = bNoActivate;
  988. }
  989. BYTE CPaintManagerUI::GetOpacity() const
  990. {
  991. return m_nOpacity;
  992. }
  993. void CPaintManagerUI::SetOpacity(BYTE nOpacity)
  994. {
  995. m_nOpacity = nOpacity;
  996. if (m_hWndPaint != NULL)
  997. {
  998. typedef BOOL(__stdcall* PFUNCSETLAYEREDWINDOWATTR)(HWND, COLORREF, BYTE, DWORD);
  999. PFUNCSETLAYEREDWINDOWATTR fSetLayeredWindowAttributes = NULL;
  1000. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  1001. if (hUser32)
  1002. {
  1003. fSetLayeredWindowAttributes =
  1004. (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
  1005. if (fSetLayeredWindowAttributes == NULL) return;
  1006. }
  1007. DWORD dwStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  1008. DWORD dwNewStyle = dwStyle;
  1009. if (nOpacity >= 0 && nOpacity < 256) dwNewStyle |= WS_EX_LAYERED;
  1010. else dwNewStyle &= ~WS_EX_LAYERED;
  1011. if (dwStyle != dwNewStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewStyle);
  1012. fSetLayeredWindowAttributes(m_hWndPaint, 0, nOpacity, LWA_ALPHA);
  1013. }
  1014. }
  1015. bool CPaintManagerUI::IsLayered()
  1016. {
  1017. return m_bLayered;
  1018. }
  1019. void CPaintManagerUI::SetLayered(bool bLayered)
  1020. {
  1021. if (m_hWndPaint != NULL && bLayered != m_bLayered)
  1022. {
  1023. UINT uStyle = GetWindowStyle(m_hWndPaint);
  1024. if ((uStyle & WS_CHILD) != 0) return;
  1025. if (g_fUpdateLayeredWindow == NULL)
  1026. {
  1027. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  1028. if (hUser32)
  1029. {
  1030. g_fUpdateLayeredWindow =
  1031. (PFUNCUPDATELAYEREDWINDOW)::GetProcAddress(hUser32, "UpdateLayeredWindow");
  1032. if (g_fUpdateLayeredWindow == NULL) return;
  1033. }
  1034. }
  1035. m_bLayered = bLayered;
  1036. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  1037. Invalidate();
  1038. }
  1039. }
  1040. RECT& CPaintManagerUI::GetLayeredInset()
  1041. {
  1042. return m_rcLayeredInset;
  1043. }
  1044. void CPaintManagerUI::SetLayeredInset(RECT& rcLayeredInset)
  1045. {
  1046. m_rcLayeredInset = rcLayeredInset;
  1047. m_bLayeredChanged = true;
  1048. Invalidate();
  1049. }
  1050. BYTE CPaintManagerUI::GetLayeredOpacity()
  1051. {
  1052. return m_nOpacity;
  1053. }
  1054. void CPaintManagerUI::SetLayeredOpacity(BYTE nOpacity)
  1055. {
  1056. m_nOpacity = nOpacity;
  1057. m_bLayeredChanged = true;
  1058. Invalidate();
  1059. }
  1060. LPCTSTR CPaintManagerUI::GetLayeredImage()
  1061. {
  1062. return m_diLayered.sDrawString;
  1063. }
  1064. void CPaintManagerUI::SetLayeredImage(LPCTSTR pstrImage)
  1065. {
  1066. m_diLayered.sDrawString = pstrImage;
  1067. RECT rcNull = { 0 };
  1068. CRenderEngine::DrawImageInfo(NULL, this, rcNull, rcNull, &m_diLayered);
  1069. m_bLayeredChanged = true;
  1070. Invalidate();
  1071. }
  1072. CShadowUI* CPaintManagerUI::GetShadow()
  1073. {
  1074. return &m_shadow;
  1075. }
  1076. void CPaintManagerUI::SetUseGdiplusText(bool bUse)
  1077. {
  1078. m_bUseGdiplusText = bUse;
  1079. }
  1080. bool CPaintManagerUI::IsUseGdiplusText() const
  1081. {
  1082. return m_bUseGdiplusText;
  1083. }
  1084. void CPaintManagerUI::SetGdiplusTextRenderingHint(int trh)
  1085. {
  1086. m_trh = trh;
  1087. }
  1088. int CPaintManagerUI::GetGdiplusTextRenderingHint() const
  1089. {
  1090. return m_trh;
  1091. }
  1092. bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  1093. {
  1094. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  1095. {
  1096. bool bHandled = false;
  1097. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  1098. if (bHandled)
  1099. {
  1100. lRes = lResult;
  1101. return true;
  1102. }
  1103. }
  1104. switch (uMsg)
  1105. {
  1106. case WM_KEYDOWN:
  1107. {
  1108. // Tabbing between controls
  1109. if (wParam == VK_TAB)
  1110. {
  1111. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("RichEditUI")) != NULL)
  1112. {
  1113. if (static_cast<CRichEditUI*>(m_pFocus)->IsWantTab()) return false;
  1114. }
  1115. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("WkeWebkitUI")) != NULL)
  1116. {
  1117. return false;
  1118. }
  1119. SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
  1120. return false;
  1121. }
  1122. }
  1123. break;
  1124. case WM_SYSCHAR:
  1125. {
  1126. // Handle ALT-shortcut key-combinations
  1127. FINDSHORTCUT fs = { 0 };
  1128. fs.ch = toupper((int)wParam);
  1129. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST);
  1130. if (pControl != NULL)
  1131. {
  1132. pControl->SetFocus();
  1133. pControl->Activate();
  1134. return true;
  1135. }
  1136. }
  1137. break;
  1138. case WM_SYSKEYDOWN:
  1139. {
  1140. if (m_pFocus != NULL)
  1141. {
  1142. TEventUI event = { 0 };
  1143. event.Type = UIEVENT_SYSKEY;
  1144. event.chKey = (TCHAR)wParam;
  1145. event.ptMouse = m_ptLastMousePos;
  1146. event.wKeyState = MapKeyState();
  1147. event.dwTimestamp = ::GetTickCount();
  1148. m_pFocus->Event(event);
  1149. }
  1150. }
  1151. break;
  1152. }
  1153. return false;
  1154. }
  1155. bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  1156. {
  1157. if (m_hWndPaint == NULL) return false;
  1158. // [触屏兼容] 不再过滤 Windows 为触摸模拟的鼠标消息(MOUSEEVENTF_FROMTOUCH)。
  1159. // 触摸的“点击”正来自这些模拟的 WM_LBUTTONDOWN/UP,由原生鼠标路径交给 CButtonUI 等控件
  1160. // Activate() 触发——而 DuiLib 的点击状态机依赖 WM_LBUTTONDOWN 设置 m_pEventClick,故绝不能
  1161. // 在鼠标分支吞掉这些模拟消息(之前那样做会导致触摸与鼠标点击全失效)。
  1162. // 为避免“拖拽=滚动”又“误点按钮”,改用 m_bTouchMoved:若本次手势发生位移,在 WM_LBUTTONUP 抑制点击。
  1163. // Cycle through listeners
  1164. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  1165. {
  1166. bool bHandled = false;
  1167. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  1168. if (bHandled)
  1169. {
  1170. lRes = lResult;
  1171. switch (uMsg)
  1172. {
  1173. case WM_MOUSEMOVE:
  1174. case WM_LBUTTONDOWN:
  1175. case WM_LBUTTONDBLCLK:
  1176. case WM_LBUTTONUP:
  1177. {
  1178. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1179. m_ptLastMousePos = pt;
  1180. }
  1181. break;
  1182. case WM_CONTEXTMENU:
  1183. case WM_MOUSEWHEEL:
  1184. {
  1185. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1186. ::ScreenToClient(m_hWndPaint, &pt);
  1187. m_ptLastMousePos = pt;
  1188. }
  1189. break;
  1190. }
  1191. return true;
  1192. }
  1193. }
  1194. if (m_bLayered)
  1195. {
  1196. switch (uMsg)
  1197. {
  1198. case WM_NCACTIVATE:
  1199. if (!::IsIconic(m_hWndPaint))
  1200. {
  1201. lRes = (wParam == 0) ? TRUE : FALSE;
  1202. return true;
  1203. }
  1204. break;
  1205. case WM_NCCALCSIZE:
  1206. case WM_NCPAINT:
  1207. lRes = 0;
  1208. return true;
  1209. }
  1210. }
  1211. // Custom handling of events
  1212. switch (uMsg)
  1213. {
  1214. case WM_APP + 1:
  1215. {
  1216. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++)
  1217. delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  1218. m_aDelayedCleanup.Empty();
  1219. m_bAsyncNotifyPosted = false;
  1220. TNotifyUI* pMsg = NULL;
  1221. while (pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify.GetAt(0)))
  1222. {
  1223. m_aAsyncNotify.Remove(0);
  1224. if (pMsg->pSender != NULL)
  1225. {
  1226. if (pMsg->pSender->OnNotify) pMsg->pSender->OnNotify(pMsg);
  1227. }
  1228. for (int j = 0; j < m_aNotifiers.GetSize(); j++)
  1229. {
  1230. static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);
  1231. }
  1232. delete pMsg;
  1233. }
  1234. }
  1235. break;
  1236. case WM_CLOSE:
  1237. {
  1238. // Make sure all matching "closing" events are sent
  1239. TEventUI event = { 0 };
  1240. event.ptMouse = m_ptLastMousePos;
  1241. event.wKeyState = MapKeyState();
  1242. event.dwTimestamp = ::GetTickCount();
  1243. if (m_pEventHover != NULL)
  1244. {
  1245. event.Type = UIEVENT_MOUSELEAVE;
  1246. event.pSender = m_pEventHover;
  1247. m_pEventHover->Event(event);
  1248. }
  1249. if (m_pEventClick != NULL)
  1250. {
  1251. event.Type = UIEVENT_BUTTONUP;
  1252. event.pSender = m_pEventClick;
  1253. m_pEventClick->Event(event);
  1254. }
  1255. if (m_pEventRClick != NULL)
  1256. {
  1257. event.Type = UIEVENT_RBUTTONUP;
  1258. event.pSender = m_pEventClick;
  1259. m_pEventRClick->Event(event);
  1260. }
  1261. SetFocus(NULL);
  1262. if (::GetActiveWindow() == m_hWndPaint)
  1263. {
  1264. HWND hwndParent = GetWindowOwner(m_hWndPaint);
  1265. if (hwndParent != NULL) ::SetFocus(hwndParent);
  1266. }
  1267. if (m_hwndTooltip != NULL)
  1268. {
  1269. ::DestroyWindow(m_hwndTooltip);
  1270. m_hwndTooltip = NULL;
  1271. }
  1272. }
  1273. break;
  1274. case WM_ERASEBKGND:
  1275. {
  1276. // We'll do the painting here...
  1277. lRes = 1;
  1278. }
  1279. return true;
  1280. case WM_PAINT:
  1281. {
  1282. if (m_pRoot == NULL)
  1283. {
  1284. PAINTSTRUCT ps = { 0 };
  1285. ::BeginPaint(m_hWndPaint, &ps);
  1286. CRenderEngine::DrawColor(m_hDcPaint, ps.rcPaint, 0xFF000000);
  1287. ::EndPaint(m_hWndPaint, &ps);
  1288. return true;
  1289. }
  1290. RECT rcClient = { 0 };
  1291. ::GetClientRect(m_hWndPaint, &rcClient);
  1292. RECT rcPaint = { 0 };
  1293. if (!::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE)) return true;
  1294. //if( m_bLayered ) {
  1295. // m_bOffscreenPaint = true;
  1296. // rcPaint = m_rcLayeredUpdate;
  1297. // if( ::IsRectEmpty(&m_rcLayeredUpdate) ) {
  1298. // PAINTSTRUCT ps = { 0 };
  1299. // ::BeginPaint(m_hWndPaint, &ps);
  1300. // ::EndPaint(m_hWndPaint, &ps);
  1301. // return true;
  1302. // }
  1303. // if( rcPaint.right > rcClient.right ) rcPaint.right = rcClient.right;
  1304. // if( rcPaint.bottom > rcClient.bottom ) rcPaint.bottom = rcClient.bottom;
  1305. // ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1306. //}
  1307. //else {
  1308. // if( !::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE) ) return true;
  1309. //}
  1310. // Set focus to first control?
  1311. if (m_bFocusNeeded)
  1312. {
  1313. //修复新窗口自动切换焦点的问题
  1314. //SetNextTabControl();
  1315. m_bFocusNeeded = false;
  1316. }
  1317. SetPainting(true);
  1318. bool bNeedSizeMsg = false;
  1319. DWORD dwWidth = rcClient.right - rcClient.left;
  1320. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1321. SetPainting(true);
  1322. if (m_bUpdateNeeded)
  1323. {
  1324. m_bUpdateNeeded = false;
  1325. if (!::IsRectEmpty(&rcClient) && !::IsIconic(m_hWndPaint))
  1326. {
  1327. if (m_pRoot->IsUpdateNeeded())
  1328. {
  1329. RECT rcRoot = rcClient;
  1330. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  1331. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  1332. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  1333. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  1334. m_hDcOffscreen = NULL;
  1335. m_hDcBackground = NULL;
  1336. m_hbmpOffscreen = NULL;
  1337. m_hbmpBackground = NULL;
  1338. if (m_bLayered)
  1339. {
  1340. rcRoot.left += m_rcLayeredInset.left;
  1341. rcRoot.top += m_rcLayeredInset.top;
  1342. rcRoot.right -= m_rcLayeredInset.right;
  1343. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1344. }
  1345. m_pRoot->SetPos(rcRoot, true);
  1346. bNeedSizeMsg = true;
  1347. }
  1348. else
  1349. {
  1350. CControlUI* pControl = NULL;
  1351. m_aFoundControls.Empty();
  1352. m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST);
  1353. for (int it = 0; it < m_aFoundControls.GetSize(); it++)
  1354. {
  1355. pControl = static_cast<CControlUI*>(m_aFoundControls[it]);
  1356. pControl->SetPos(pControl->GetPos(), true);
  1357. }
  1358. bNeedSizeMsg = true;
  1359. }
  1360. // We'll want to notify the window when it is first initialized
  1361. // with the correct layout. The window form would take the time
  1362. // to submit swipes/animations.
  1363. if (m_bFirstLayout)
  1364. {
  1365. m_bFirstLayout = false;
  1366. SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWINIT, 0, 0, false);
  1367. if (m_bLayered && m_bLayeredChanged)
  1368. {
  1369. Invalidate();
  1370. SetPainting(false);
  1371. return true;
  1372. }
  1373. // 更新阴影窗口显示
  1374. m_shadow.Update(m_hWndPaint);
  1375. }
  1376. }
  1377. }
  1378. else if (m_bLayered && m_bLayeredChanged)
  1379. {
  1380. RECT rcRoot = rcClient;
  1381. if (m_pOffscreenBits) ::ZeroMemory(m_pOffscreenBits, (rcRoot.right - rcRoot.left)
  1382. * (rcRoot.bottom - rcRoot.top) * 4);
  1383. rcRoot.left += m_rcLayeredInset.left;
  1384. rcRoot.top += m_rcLayeredInset.top;
  1385. rcRoot.right -= m_rcLayeredInset.right;
  1386. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1387. m_pRoot->SetPos(rcRoot, true);
  1388. }
  1389. if (m_bLayered)
  1390. {
  1391. DWORD dwExStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  1392. DWORD dwNewExStyle = dwExStyle | WS_EX_LAYERED;
  1393. if (dwExStyle != dwNewExStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewExStyle);
  1394. m_bOffscreenPaint = true;
  1395. UnionRect(&rcPaint, &rcPaint, &m_rcLayeredUpdate);
  1396. if (rcPaint.right > rcClient.right) rcPaint.right = rcClient.right;
  1397. if (rcPaint.bottom > rcClient.bottom) rcPaint.bottom = rcClient.bottom;
  1398. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1399. }
  1400. //
  1401. // Render screen
  1402. //
  1403. // Prepare offscreen bitmap
  1404. if (m_bOffscreenPaint && m_hbmpOffscreen == NULL)
  1405. {
  1406. m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
  1407. m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (LPBYTE*)&m_pOffscreenBits);
  1408. ASSERT(m_hDcOffscreen);
  1409. ASSERT(m_hbmpOffscreen);
  1410. }
  1411. // Begin Windows paint
  1412. PAINTSTRUCT ps = { 0 };
  1413. ::BeginPaint(m_hWndPaint, &ps);
  1414. if (m_bOffscreenPaint)
  1415. {
  1416. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(m_hDcOffscreen, m_hbmpOffscreen);
  1417. int iSaveDC = ::SaveDC(m_hDcOffscreen);
  1418. if (m_bLayered)
  1419. {
  1420. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1421. {
  1422. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1423. {
  1424. int i = (y * dwWidth + x) * 4;
  1425. *(DWORD*)(&m_pOffscreenBits[i]) = 0;
  1426. }
  1427. }
  1428. }
  1429. m_pRoot->Paint(m_hDcOffscreen, rcPaint, NULL);
  1430. if (m_bLayered)
  1431. {
  1432. for (int i = 0; i < m_aNativeWindow.GetSize(); )
  1433. {
  1434. HWND hChildWnd = static_cast<HWND>(m_aNativeWindow[i]);
  1435. if (!::IsWindow(hChildWnd))
  1436. {
  1437. m_aNativeWindow.Remove(i);
  1438. m_aNativeWindowControl.Remove(i);
  1439. continue;
  1440. }
  1441. ++i;
  1442. if (!::IsWindowVisible(hChildWnd)) continue;
  1443. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  1444. RECT rcTemp = { 0 };
  1445. if (!::IntersectRect(&rcTemp, &rcPaint, &rcChildWnd)) continue;
  1446. COLORREF* pChildBitmapBits = NULL;
  1447. HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen);
  1448. HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap(hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, (BYTE**)&pChildBitmapBits);
  1449. ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4);
  1450. HBITMAP hOldChildBitmap = (HBITMAP) ::SelectObject(hChildMemDC, hChildBitmap);
  1451. ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED));
  1452. COLORREF* pChildBitmapBit;
  1453. for (LONG y = 0; y < rcChildWnd.bottom - rcChildWnd.top; y++)
  1454. {
  1455. for (LONG x = 0; x < rcChildWnd.right - rcChildWnd.left; x++)
  1456. {
  1457. pChildBitmapBit = pChildBitmapBits + y * (rcChildWnd.right - rcChildWnd.left) + x;
  1458. if (*pChildBitmapBit != 0x00000000) *pChildBitmapBit |= 0xff000000;
  1459. }
  1460. }
  1461. ::BitBlt(m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left,
  1462. rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY);
  1463. ::SelectObject(hChildMemDC, hOldChildBitmap);
  1464. ::DeleteObject(hChildBitmap);
  1465. ::DeleteDC(hChildMemDC);
  1466. }
  1467. }
  1468. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1469. {
  1470. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1471. pPostPaintControl->DoPostPaint(m_hDcOffscreen, rcPaint);
  1472. }
  1473. ::RestoreDC(m_hDcOffscreen, iSaveDC);
  1474. if (m_bLayered)
  1475. {
  1476. RECT rcWnd = { 0 };
  1477. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1478. if (!m_diLayered.sDrawString.IsEmpty())
  1479. {
  1480. DWORD dwWidth = rcClient.right - rcClient.left;
  1481. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1482. RECT rcLayeredClient = rcClient;
  1483. rcLayeredClient.left += m_rcLayeredInset.left;
  1484. rcLayeredClient.top += m_rcLayeredInset.top;
  1485. rcLayeredClient.right -= m_rcLayeredInset.right;
  1486. rcLayeredClient.bottom -= m_rcLayeredInset.bottom;
  1487. COLORREF* pOffscreenBits = (COLORREF*)m_pOffscreenBits;
  1488. COLORREF* pBackgroundBits = m_pBackgroundBits;
  1489. BYTE A = 0;
  1490. BYTE R = 0;
  1491. BYTE G = 0;
  1492. BYTE B = 0;
  1493. if (!m_diLayered.sDrawString.IsEmpty())
  1494. {
  1495. if (m_hbmpBackground == NULL)
  1496. {
  1497. m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint);
  1498. m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (BYTE**)&m_pBackgroundBits);
  1499. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1500. ::SelectObject(m_hDcBackground, m_hbmpBackground);
  1501. CRenderClip clip;
  1502. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1503. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1504. }
  1505. else if (m_bLayeredChanged)
  1506. {
  1507. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1508. CRenderClip clip;
  1509. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1510. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1511. }
  1512. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1513. {
  1514. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1515. {
  1516. pOffscreenBits = (COLORREF*)(m_pOffscreenBits + y * dwWidth + x);
  1517. pBackgroundBits = m_pBackgroundBits + y * dwWidth + x;
  1518. A = (BYTE)((*pBackgroundBits) >> 24);
  1519. R = (BYTE)((*pOffscreenBits) >> 16) * A / 255;
  1520. G = (BYTE)((*pOffscreenBits) >> 8) * A / 255;
  1521. B = (BYTE)(*pOffscreenBits) * A / 255;
  1522. *pOffscreenBits = RGB(B, G, R) + ((DWORD)A << 24);
  1523. }
  1524. }
  1525. }
  1526. }
  1527. else
  1528. {
  1529. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1530. {
  1531. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1532. {
  1533. int i = (y * dwWidth + x) * 4;
  1534. if ((m_pOffscreenBits[i + 3] == 0) && (m_pOffscreenBits[i + 0] != 0 || m_pOffscreenBits[i + 1] != 0 || m_pOffscreenBits[i + 2] != 0))
  1535. m_pOffscreenBits[i + 3] = 255;
  1536. }
  1537. }
  1538. }
  1539. BLENDFUNCTION bf = { AC_SRC_OVER, 0, m_nOpacity, AC_SRC_ALPHA };
  1540. POINT ptPos = { rcWnd.left, rcWnd.top };
  1541. SIZE sizeWnd = { dwWidth, dwHeight };
  1542. POINT ptSrc = { 0, 0 };
  1543. g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
  1544. }
  1545. else
  1546. {
  1547. ::BitBlt(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY);
  1548. }
  1549. ::SelectObject(m_hDcOffscreen, hOldBitmap);
  1550. if (m_bShowUpdateRect && !m_bLayered)
  1551. {
  1552. HPEN hOldPen = (HPEN)::SelectObject(m_hDcPaint, m_hUpdateRectPen);
  1553. ::SelectObject(m_hDcPaint, ::GetStockObject(HOLLOW_BRUSH));
  1554. ::Rectangle(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
  1555. ::SelectObject(m_hDcPaint, hOldPen);
  1556. }
  1557. }
  1558. else
  1559. {
  1560. // A standard paint job
  1561. int iSaveDC = ::SaveDC(m_hDcPaint);
  1562. m_pRoot->Paint(m_hDcPaint, rcPaint, NULL);
  1563. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1564. {
  1565. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1566. pPostPaintControl->DoPostPaint(m_hDcPaint, rcPaint);
  1567. }
  1568. ::RestoreDC(m_hDcPaint, iSaveDC);
  1569. }
  1570. // All Done!
  1571. ::EndPaint(m_hWndPaint, &ps);
  1572. // 绘制结束
  1573. SetPainting(false);
  1574. m_bLayeredChanged = false;
  1575. if (m_bUpdateNeeded) Invalidate();
  1576. // 发送窗口大小改变消息
  1577. if (bNeedSizeMsg)
  1578. {
  1579. this->SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWSIZE, 0, 0, true);
  1580. }
  1581. return true;
  1582. }
  1583. case WM_PRINTCLIENT:
  1584. {
  1585. if (m_pRoot == NULL) break;
  1586. RECT rcClient;
  1587. ::GetClientRect(m_hWndPaint, &rcClient);
  1588. HDC hDC = (HDC)wParam;
  1589. int save = ::SaveDC(hDC);
  1590. m_pRoot->Paint(hDC, rcClient, NULL);
  1591. if ((lParam & PRF_CHILDREN) != 0)
  1592. {
  1593. HWND hWndChild = ::GetWindow(m_hWndPaint, GW_CHILD);
  1594. while (hWndChild != NULL)
  1595. {
  1596. RECT rcPos = { 0 };
  1597. ::GetWindowRect(hWndChild, &rcPos);
  1598. ::MapWindowPoints(HWND_DESKTOP, m_hWndPaint, reinterpret_cast<LPPOINT>(&rcPos), 2);
  1599. ::SetWindowOrgEx(hDC, -rcPos.left, -rcPos.top, NULL);
  1600. ::SendMessage(hWndChild, WM_PRINT, wParam, lParam | PRF_NONCLIENT);
  1601. hWndChild = ::GetWindow(hWndChild, GW_HWNDNEXT);
  1602. }
  1603. }
  1604. ::RestoreDC(hDC, save);
  1605. }
  1606. break;
  1607. case WM_GETMINMAXINFO:
  1608. {
  1609. MONITORINFO Monitor = {};
  1610. Monitor.cbSize = sizeof(Monitor);
  1611. ::GetMonitorInfo(::MonitorFromWindow(m_hWndPaint, MONITOR_DEFAULTTOPRIMARY), &Monitor);
  1612. RECT rcWork = Monitor.rcWork;
  1613. if (Monitor.dwFlags != MONITORINFOF_PRIMARY)
  1614. {
  1615. ::OffsetRect(&rcWork, -rcWork.left, -rcWork.top);
  1616. }
  1617. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  1618. if (m_szMinWindow.cx > 0) lpMMI->ptMinTrackSize.x = m_szMinWindow.cx;
  1619. if (m_szMinWindow.cy > 0) lpMMI->ptMinTrackSize.y = m_szMinWindow.cy;
  1620. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxTrackSize.x = m_szMaxWindow.cx;
  1621. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxTrackSize.y = m_szMaxWindow.cy;
  1622. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxSize.x = m_szMaxWindow.cx;
  1623. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxSize.y = m_szMaxWindow.cy;
  1624. }
  1625. break;
  1626. case WM_SIZE:
  1627. {
  1628. if (m_pFocus != NULL)
  1629. {
  1630. TEventUI event = { 0 };
  1631. event.Type = UIEVENT_WINDOWSIZE;
  1632. event.pSender = m_pFocus;
  1633. event.dwTimestamp = ::GetTickCount();
  1634. m_pFocus->Event(event);
  1635. }
  1636. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  1637. }
  1638. return true;
  1639. case WM_TIMER:
  1640. {
  1641. for (int i = 0; i < m_aTimers.GetSize(); i++)
  1642. {
  1643. const TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1644. if (pTimer->hWnd == m_hWndPaint &&
  1645. pTimer->uWinTimer == LOWORD(wParam) &&
  1646. pTimer->bKilled == false)
  1647. {
  1648. TEventUI event = { 0 };
  1649. event.Type = UIEVENT_TIMER;
  1650. event.pSender = pTimer->pSender;
  1651. event.dwTimestamp = ::GetTickCount();
  1652. event.ptMouse = m_ptLastMousePos;
  1653. event.wKeyState = MapKeyState();
  1654. event.wParam = pTimer->nLocalID;
  1655. event.lParam = lParam;
  1656. pTimer->pSender->Event(event);
  1657. break;
  1658. }
  1659. }
  1660. }
  1661. break;
  1662. case WM_MOUSEHOVER:
  1663. {
  1664. m_bMouseTracking = false;
  1665. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1666. CControlUI* pHover = FindControl(pt);
  1667. if (pHover == NULL) break;
  1668. // Generate mouse hover event
  1669. if (m_pEventHover != NULL)
  1670. {
  1671. TEventUI event = { 0 };
  1672. event.Type = UIEVENT_MOUSEHOVER;
  1673. event.pSender = m_pEventHover;
  1674. event.wParam = wParam;
  1675. event.lParam = lParam;
  1676. event.dwTimestamp = ::GetTickCount();
  1677. event.ptMouse = pt;
  1678. event.wKeyState = MapKeyState();
  1679. m_pEventHover->Event(event);
  1680. }
  1681. // Create tooltip information
  1682. CDuiString sToolTip = pHover->GetToolTip();
  1683. if (sToolTip.IsEmpty()) return true;
  1684. ::ZeroMemory(&m_ToolTip, sizeof(TOOLINFO));
  1685. m_ToolTip.cbSize = sizeof(TOOLINFO);
  1686. m_ToolTip.uFlags = TTF_IDISHWND;
  1687. m_ToolTip.hwnd = m_hWndPaint;
  1688. m_ToolTip.uId = (UINT_PTR)m_hWndPaint;
  1689. m_ToolTip.hinst = m_hInstance;
  1690. m_ToolTip.lpszText = const_cast<LPTSTR>((LPCTSTR)sToolTip);
  1691. m_ToolTip.rect = pHover->GetPos();
  1692. if (m_hwndTooltip == NULL)
  1693. {
  1694. 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);
  1695. ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip);
  1696. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1697. }
  1698. if (!::IsWindowVisible(m_hwndTooltip))
  1699. {
  1700. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1701. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1702. }
  1703. }
  1704. return true;
  1705. case WM_MOUSELEAVE:
  1706. {
  1707. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1708. if (m_bMouseTracking)
  1709. {
  1710. POINT pt = { 0 };
  1711. RECT rcWnd = { 0 };
  1712. ::GetCursorPos(&pt);
  1713. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1714. if (!::IsIconic(m_hWndPaint) && ::GetActiveWindow() == m_hWndPaint && ::PtInRect(&rcWnd, pt))
  1715. {
  1716. if (::SendMessage(m_hWndPaint, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)) == HTCLIENT)
  1717. {
  1718. ::ScreenToClient(m_hWndPaint, &pt);
  1719. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
  1720. }
  1721. else
  1722. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1723. }
  1724. else
  1725. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1726. }
  1727. m_bMouseTracking = false;
  1728. }
  1729. break;
  1730. case WM_MOUSEMOVE:
  1731. {
  1732. // Start tracking this entire window again...
  1733. if (!m_bMouseTracking)
  1734. {
  1735. TRACKMOUSEEVENT tme = { 0 };
  1736. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  1737. tme.dwFlags = TME_HOVER | TME_LEAVE;
  1738. tme.hwndTrack = m_hWndPaint;
  1739. tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
  1740. _TrackMouseEvent(&tme);
  1741. m_bMouseTracking = true;
  1742. }
  1743. // Generate the appropriate mouse messages
  1744. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1745. // 是否移动
  1746. bool bNeedDrag = true;
  1747. if (m_ptLastMousePos.x == pt.x && m_ptLastMousePos.y == pt.y)
  1748. {
  1749. bNeedDrag = false;
  1750. }
  1751. // 记录鼠标位置
  1752. m_ptLastMousePos = pt;
  1753. CControlUI* pNewHover = FindControl(pt);
  1754. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1755. // 拖拽事件
  1756. if (bNeedDrag && m_bDragMode && wParam == MK_LBUTTON)
  1757. {
  1758. // 释放Capture
  1759. ::ReleaseCapture();
  1760. // 接口
  1761. if (m_pDragDrop != NULL && m_pDragDrop->OnDragDrop(m_pEventClick))
  1762. {
  1763. m_bDragMode = false;
  1764. break;
  1765. }
  1766. CIDropSource* pdsrc = new CIDropSource;
  1767. if (pdsrc == NULL) return 0;
  1768. pdsrc->AddRef();
  1769. CIDataObject* pdobj = new CIDataObject(pdsrc);
  1770. if (pdobj == NULL) return 0;
  1771. pdobj->AddRef();
  1772. FORMATETC fmtetc = { 0 };
  1773. STGMEDIUM medium = { 0 };
  1774. fmtetc.dwAspect = DVASPECT_CONTENT;
  1775. fmtetc.lindex = -1;
  1776. fmtetc.cfFormat = CF_BITMAP;
  1777. fmtetc.tymed = TYMED_GDI;
  1778. //////////////////////////////////////
  1779. HBITMAP hBitmap = (HBITMAP)OleDuplicateData(m_hDragBitmap, fmtetc.cfFormat, NULL);
  1780. medium.hBitmap = hBitmap;
  1781. pdobj->SetData(&fmtetc, &medium, FALSE);
  1782. //////////////////////////////////////
  1783. BITMAP bmap;
  1784. GetObject(hBitmap, sizeof(BITMAP), &bmap);
  1785. RECT rc = { 0, 0, bmap.bmWidth, bmap.bmHeight };
  1786. fmtetc.cfFormat = CF_ENHMETAFILE;
  1787. fmtetc.tymed = TYMED_ENHMF;
  1788. HDC hMetaDC = CreateEnhMetaFile(m_hDcPaint, NULL, NULL, NULL);
  1789. HDC hdcMem = CreateCompatibleDC(m_hDcPaint);
  1790. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBitmap);
  1791. ::BitBlt(hMetaDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
  1792. ::SelectObject(hdcMem, hOldBmp);
  1793. medium.hEnhMetaFile = CloseEnhMetaFile(hMetaDC);
  1794. DeleteDC(hdcMem);
  1795. medium.tymed = TYMED_ENHMF;
  1796. pdobj->SetData(&fmtetc, &medium, TRUE);
  1797. //////////////////////////////////////
  1798. CDragSourceHelper dragSrcHelper;
  1799. POINT ptDrag = { 0 };
  1800. ptDrag.x = bmap.bmWidth / 2;
  1801. ptDrag.y = bmap.bmHeight / 2;
  1802. dragSrcHelper.InitializeFromBitmap(hBitmap, ptDrag, rc, pdobj); //will own the bmp
  1803. DWORD dwEffect;
  1804. HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
  1805. if (dwEffect) pdsrc->Release();
  1806. else delete pdsrc;
  1807. pdobj->Release();
  1808. m_bDragMode = false;
  1809. break;
  1810. }
  1811. TEventUI event = { 0 };
  1812. event.ptMouse = pt;
  1813. event.wParam = wParam;
  1814. event.lParam = lParam;
  1815. event.dwTimestamp = ::GetTickCount();
  1816. event.wKeyState = MapKeyState();
  1817. if (!IsCaptured())
  1818. {
  1819. pNewHover = FindControl(pt);
  1820. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1821. if (pNewHover != m_pEventHover && m_pEventHover != NULL)
  1822. {
  1823. event.Type = UIEVENT_MOUSELEAVE;
  1824. event.pSender = m_pEventHover;
  1825. CStdPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  1826. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  1827. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  1828. for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++)
  1829. {
  1830. static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i])->Event(event);
  1831. }
  1832. m_pEventHover->Event(event);
  1833. m_pEventHover = NULL;
  1834. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1835. }
  1836. if (pNewHover != m_pEventHover && pNewHover != NULL)
  1837. {
  1838. event.Type = UIEVENT_MOUSEENTER;
  1839. event.pSender = pNewHover;
  1840. pNewHover->Event(event);
  1841. m_pEventHover = pNewHover;
  1842. }
  1843. }
  1844. if (m_pEventClick != NULL)
  1845. {
  1846. event.Type = UIEVENT_MOUSEMOVE;
  1847. event.pSender = m_pEventClick;
  1848. m_pEventClick->Event(event);
  1849. }
  1850. else if (pNewHover != NULL)
  1851. {
  1852. event.Type = UIEVENT_MOUSEMOVE;
  1853. event.pSender = pNewHover;
  1854. pNewHover->Event(event);
  1855. }
  1856. }
  1857. break;
  1858. case WM_LBUTTONDOWN:
  1859. {
  1860. // We alway set focus back to our app (this helps
  1861. // when Win32 child windows are placed on the dialog
  1862. // and we need to remove them on focus change).
  1863. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1864. if (m_pRoot == NULL) break;
  1865. // 查找控件
  1866. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1867. m_ptLastMousePos = pt;
  1868. CControlUI* pControl = FindControl(pt);
  1869. if (pControl == NULL) break;
  1870. if (pControl->GetManager() != this) break;
  1871. // 准备拖拽
  1872. if (m_bDragDrop && pControl->IsDragEnabled())
  1873. {
  1874. m_bDragMode = true;
  1875. if (m_hDragBitmap != NULL)
  1876. {
  1877. ::DeleteObject(m_hDragBitmap);
  1878. m_hDragBitmap = NULL;
  1879. }
  1880. m_hDragBitmap = CRenderEngine::GenerateBitmap(this, pControl, pControl->GetPos());
  1881. }
  1882. // 开启捕获
  1883. SetCapture();
  1884. // 事件处理
  1885. m_pEventClick = pControl;
  1886. pControl->SetFocus();
  1887. TEventUI event = { 0 };
  1888. event.Type = UIEVENT_BUTTONDOWN;
  1889. event.pSender = pControl;
  1890. event.wParam = wParam;
  1891. event.lParam = lParam;
  1892. event.ptMouse = pt;
  1893. event.wKeyState = (WORD)wParam;
  1894. event.dwTimestamp = ::GetTickCount();
  1895. pControl->Event(event);
  1896. }
  1897. break;
  1898. case WM_LBUTTONDBLCLK:
  1899. {
  1900. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1901. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1902. m_ptLastMousePos = pt;
  1903. CControlUI* pControl = FindControl(pt);
  1904. if (pControl == NULL) break;
  1905. if (pControl->GetManager() != this) break;
  1906. //SetCapture();
  1907. TEventUI event = { 0 };
  1908. event.Type = UIEVENT_DBLCLICK;
  1909. event.pSender = pControl;
  1910. event.ptMouse = pt;
  1911. event.wParam = wParam;
  1912. event.lParam = lParam;
  1913. event.wKeyState = (WORD)wParam;
  1914. event.dwTimestamp = ::GetTickCount();
  1915. pControl->Event(event);
  1916. m_pEventClick = pControl;
  1917. }
  1918. break;
  1919. case WM_LBUTTONUP:
  1920. {
  1921. // 触屏拖拽手势(已发生位移)-> 松开不触发“点击”,避免“拖拽又误点”。
  1922. // 但滚动条滑块拖拽依赖 BUTTONUP 来解除 UISTATE_CAPTURED 并停掉 50ms 定时器,
  1923. // 绝不能在此提前清空 m_pEventClick,否则滚动条卡死在捕获态。故对滚动条放行 BUTTONUP。
  1924. if (m_bTouchMoved && m_pEventClick != NULL && m_pEventClick->GetInterface(_T("ScrollBar")) == NULL)
  1925. m_pEventClick = NULL;
  1926. m_bTouchMoved = false; // 用完即清,绝不影响后续真实鼠标点击
  1927. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1928. m_ptLastMousePos = pt;
  1929. if (m_pEventClick == NULL) break;
  1930. ReleaseCapture();
  1931. TEventUI event = { 0 };
  1932. event.Type = UIEVENT_BUTTONUP;
  1933. event.pSender = m_pEventClick;
  1934. event.wParam = wParam;
  1935. event.lParam = lParam;
  1936. event.ptMouse = pt;
  1937. event.wKeyState = (WORD)wParam;
  1938. event.dwTimestamp = ::GetTickCount();
  1939. CControlUI* pClick = m_pEventClick;
  1940. m_pEventClick = NULL;
  1941. pClick->Event(event);
  1942. }
  1943. break;
  1944. case WM_RBUTTONDOWN:
  1945. {
  1946. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1947. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1948. m_ptLastMousePos = pt;
  1949. CControlUI* pControl = FindControl(pt);
  1950. if (pControl == NULL) break;
  1951. if (pControl->GetManager() != this) break;
  1952. pControl->SetFocus();
  1953. SetCapture();
  1954. TEventUI event = { 0 };
  1955. event.Type = UIEVENT_RBUTTONDOWN;
  1956. event.pSender = pControl;
  1957. event.wParam = wParam;
  1958. event.lParam = lParam;
  1959. event.ptMouse = pt;
  1960. event.wKeyState = (WORD)wParam;
  1961. event.dwTimestamp = ::GetTickCount();
  1962. pControl->Event(event);
  1963. m_pEventRClick = pControl;
  1964. }
  1965. break;
  1966. case WM_RBUTTONUP:
  1967. {
  1968. if (m_bMouseCapture) ReleaseCapture();
  1969. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1970. m_ptLastMousePos = pt;
  1971. m_pEventRClick = FindControl(pt);
  1972. if (m_pEventRClick == NULL) break;
  1973. TEventUI event = { 0 };
  1974. event.Type = UIEVENT_RBUTTONUP;
  1975. event.pSender = m_pEventRClick;
  1976. event.wParam = wParam;
  1977. event.lParam = lParam;
  1978. event.ptMouse = pt;
  1979. event.wKeyState = (WORD)wParam;
  1980. event.dwTimestamp = ::GetTickCount();
  1981. m_pEventRClick->Event(event);
  1982. }
  1983. break;
  1984. case WM_MBUTTONDOWN:
  1985. {
  1986. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1987. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1988. m_ptLastMousePos = pt;
  1989. CControlUI* pControl = FindControl(pt);
  1990. if (pControl == NULL) break;
  1991. if (pControl->GetManager() != this) break;
  1992. pControl->SetFocus();
  1993. SetCapture();
  1994. TEventUI event = { 0 };
  1995. event.Type = UIEVENT_MBUTTONDOWN;
  1996. event.pSender = pControl;
  1997. event.wParam = wParam;
  1998. event.lParam = lParam;
  1999. event.ptMouse = pt;
  2000. event.wKeyState = (WORD)wParam;
  2001. event.dwTimestamp = ::GetTickCount();
  2002. pControl->Event(event);
  2003. m_pEventClick = pControl;
  2004. }
  2005. break;
  2006. case WM_MBUTTONUP:
  2007. {
  2008. if (m_bMouseCapture) ReleaseCapture();
  2009. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  2010. m_ptLastMousePos = pt;
  2011. m_pEventClick = FindControl(pt);
  2012. if (m_pEventClick == NULL) break;
  2013. TEventUI event = { 0 };
  2014. event.Type = UIEVENT_MBUTTONUP;
  2015. event.pSender = m_pEventClick;
  2016. event.wParam = wParam;
  2017. event.lParam = lParam;
  2018. event.ptMouse = pt;
  2019. event.wKeyState = (WORD)wParam;
  2020. event.dwTimestamp = ::GetTickCount();
  2021. m_pEventClick->Event(event);
  2022. }
  2023. break;
  2024. case WM_CONTEXTMENU:
  2025. {
  2026. if (m_pRoot == NULL) break;
  2027. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  2028. ::ScreenToClient(m_hWndPaint, &pt);
  2029. m_ptLastMousePos = pt;
  2030. if (m_pEventRClick == NULL) break;
  2031. ReleaseCapture();
  2032. TEventUI event = { 0 };
  2033. event.Type = UIEVENT_CONTEXTMENU;
  2034. event.pSender = m_pEventRClick;
  2035. event.wParam = wParam;
  2036. event.lParam = lParam;
  2037. event.ptMouse = pt;
  2038. event.wKeyState = (WORD)wParam;
  2039. event.lParam = (LPARAM)m_pEventRClick;
  2040. event.dwTimestamp = ::GetTickCount();
  2041. m_pEventRClick->Event(event);
  2042. m_pEventRClick = NULL;
  2043. }
  2044. break;
  2045. case WM_TOUCH:
  2046. {
  2047. OnTouchInput(wParam, lParam);
  2048. lRes = 0;
  2049. return true;
  2050. }
  2051. case WM_MOUSEWHEEL:
  2052. {
  2053. if (m_pRoot == NULL) break;
  2054. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  2055. ::ScreenToClient(m_hWndPaint, &pt);
  2056. m_ptLastMousePos = pt;
  2057. CControlUI* pControl = FindControl(pt);
  2058. if (pControl == NULL) break;
  2059. if (pControl->GetManager() != this) break;
  2060. int zDelta = (int)(short)HIWORD(wParam);
  2061. TEventUI event = { 0 };
  2062. event.Type = UIEVENT_SCROLLWHEEL;
  2063. event.pSender = pControl;
  2064. event.wParam = MAKEWPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, zDelta);
  2065. event.lParam = lParam;
  2066. event.ptMouse = pt;
  2067. event.wKeyState = MapKeyState();
  2068. event.dwTimestamp = ::GetTickCount();
  2069. pControl->Event(event);
  2070. // Let's make sure that the scroll item below the cursor is the same as before...
  2071. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)MAKELPARAM(m_ptLastMousePos.x, m_ptLastMousePos.y));
  2072. }
  2073. break;
  2074. case WM_CHAR:
  2075. {
  2076. if (m_pRoot == NULL) break;
  2077. if (m_pFocus == NULL) break;
  2078. TEventUI event = { 0 };
  2079. event.Type = UIEVENT_CHAR;
  2080. event.pSender = m_pFocus;
  2081. event.wParam = wParam;
  2082. event.lParam = lParam;
  2083. event.chKey = (TCHAR)wParam;
  2084. event.ptMouse = m_ptLastMousePos;
  2085. event.wKeyState = MapKeyState();
  2086. event.dwTimestamp = ::GetTickCount();
  2087. m_pFocus->Event(event);
  2088. }
  2089. break;
  2090. case WM_KEYDOWN:
  2091. {
  2092. if (m_pRoot == NULL) break;
  2093. if (m_pFocus == NULL) break;
  2094. TEventUI event = { 0 };
  2095. event.Type = UIEVENT_KEYDOWN;
  2096. event.pSender = m_pFocus;
  2097. event.wParam = wParam;
  2098. event.lParam = lParam;
  2099. event.chKey = (TCHAR)wParam;
  2100. event.ptMouse = m_ptLastMousePos;
  2101. event.wKeyState = MapKeyState();
  2102. event.dwTimestamp = ::GetTickCount();
  2103. m_pFocus->Event(event);
  2104. m_pEventKey = m_pFocus;
  2105. }
  2106. break;
  2107. case WM_KEYUP:
  2108. {
  2109. if (m_pRoot == NULL) break;
  2110. if (m_pEventKey == NULL) break;
  2111. TEventUI event = { 0 };
  2112. event.Type = UIEVENT_KEYUP;
  2113. event.pSender = m_pEventKey;
  2114. event.wParam = wParam;
  2115. event.lParam = lParam;
  2116. event.chKey = (TCHAR)wParam;
  2117. event.ptMouse = m_ptLastMousePos;
  2118. event.wKeyState = MapKeyState();
  2119. event.dwTimestamp = ::GetTickCount();
  2120. m_pEventKey->Event(event);
  2121. m_pEventKey = NULL;
  2122. }
  2123. break;
  2124. case WM_SETCURSOR:
  2125. {
  2126. if (m_pRoot == NULL) break;
  2127. if (LOWORD(lParam) != HTCLIENT) break;
  2128. if (m_bMouseCapture) return true;
  2129. POINT pt = { 0 };
  2130. ::GetCursorPos(&pt);
  2131. ::ScreenToClient(m_hWndPaint, &pt);
  2132. CControlUI* pControl = FindControl(pt);
  2133. if (pControl == NULL) break;
  2134. if ((pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0) break;
  2135. TEventUI event = { 0 };
  2136. event.Type = UIEVENT_SETCURSOR;
  2137. event.pSender = pControl;
  2138. event.wParam = wParam;
  2139. event.lParam = lParam;
  2140. event.ptMouse = pt;
  2141. event.wKeyState = MapKeyState();
  2142. event.dwTimestamp = ::GetTickCount();
  2143. pControl->Event(event);
  2144. }
  2145. return true;
  2146. case WM_SETFOCUS:
  2147. {
  2148. if (m_pFocus != NULL)
  2149. {
  2150. TEventUI event = { 0 };
  2151. event.Type = UIEVENT_SETFOCUS;
  2152. event.wParam = wParam;
  2153. event.lParam = lParam;
  2154. event.pSender = m_pFocus;
  2155. event.dwTimestamp = ::GetTickCount();
  2156. m_pFocus->Event(event);
  2157. }
  2158. break;
  2159. }
  2160. case WM_KILLFOCUS:
  2161. {
  2162. if (IsCaptured()) ReleaseCapture();
  2163. break;
  2164. }
  2165. case WM_NOTIFY:
  2166. {
  2167. if (lParam == 0) break;
  2168. LPNMHDR lpNMHDR = (LPNMHDR)lParam;
  2169. if (lpNMHDR != NULL) lRes = ::SendMessage(lpNMHDR->hwndFrom, OCM__BASE + uMsg, wParam, lParam);
  2170. return true;
  2171. }
  2172. break;
  2173. case WM_COMMAND:
  2174. {
  2175. if (lParam == 0) break;
  2176. HWND hWndChild = (HWND)lParam;
  2177. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  2178. if (lRes != 0) return true;
  2179. }
  2180. break;
  2181. case WM_CTLCOLOREDIT:
  2182. case WM_CTLCOLORSTATIC:
  2183. {
  2184. // Refer To: http://msdn.microsoft.com/en-us/library/bb761691(v=vs.85).aspx
  2185. // Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message.
  2186. if (lParam == 0) break;
  2187. HWND hWndChild = (HWND)lParam;
  2188. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  2189. if (lRes != 0) return true;
  2190. }
  2191. break;
  2192. default:
  2193. break;
  2194. }
  2195. return false;
  2196. }
  2197. bool CPaintManagerUI::IsUpdateNeeded() const
  2198. {
  2199. return m_bUpdateNeeded;
  2200. }
  2201. void CPaintManagerUI::NeedUpdate()
  2202. {
  2203. m_bUpdateNeeded = true;
  2204. }
  2205. void CPaintManagerUI::Invalidate()
  2206. {
  2207. RECT rcClient = { 0 };
  2208. ::GetClientRect(m_hWndPaint, &rcClient);
  2209. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcClient);
  2210. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  2211. }
  2212. void CPaintManagerUI::Invalidate(RECT& rcItem)
  2213. {
  2214. if (rcItem.left < 0) rcItem.left = 0;
  2215. if (rcItem.top < 0) rcItem.top = 0;
  2216. if (rcItem.right < rcItem.left) rcItem.right = rcItem.left;
  2217. if (rcItem.bottom < rcItem.top) rcItem.bottom = rcItem.top;
  2218. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcItem);
  2219. ::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
  2220. }
  2221. bool CPaintManagerUI::IsValid()
  2222. {
  2223. return m_hWndPaint != NULL && m_pRoot != NULL;
  2224. }
  2225. bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
  2226. {
  2227. ASSERT(::IsWindow(m_hWndPaint));
  2228. // 创建阴影窗口
  2229. m_shadow.Create(this);
  2230. // Reset any previous attachment
  2231. SetFocus(NULL);
  2232. m_pEventKey = NULL;
  2233. m_pEventHover = NULL;
  2234. m_pEventClick = NULL;
  2235. m_pEventRClick = NULL;
  2236. // Remove the existing control-tree. We might have gotten inside this function as
  2237. // a result of an event fired or similar, so we cannot just delete the objects and
  2238. // pull the internal memory of the calling code. We'll delay the cleanup.
  2239. if (m_pRoot != NULL)
  2240. {
  2241. m_aPostPaintControls.Empty();
  2242. AddDelayedCleanup(m_pRoot);
  2243. }
  2244. // Set the dialog root element
  2245. m_pRoot = pControl;
  2246. // Go ahead...
  2247. m_bUpdateNeeded = true;
  2248. m_bFirstLayout = true;
  2249. m_bFocusNeeded = true;
  2250. // Initiate all control
  2251. return InitControls(pControl);
  2252. }
  2253. bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
  2254. {
  2255. ASSERT(pControl);
  2256. if (pControl == NULL) return false;
  2257. pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
  2258. pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);
  2259. return true;
  2260. }
  2261. void CPaintManagerUI::ReapObjects(CControlUI* pControl)
  2262. {
  2263. if (pControl == m_pEventKey) m_pEventKey = NULL;
  2264. if (pControl == m_pEventHover) m_pEventHover = NULL;
  2265. if (pControl == m_pEventClick) m_pEventClick = NULL;
  2266. if (pControl == m_pEventRClick) m_pEventRClick = NULL;
  2267. if (pControl == m_pFocus) m_pFocus = NULL;
  2268. KillTimer(pControl);
  2269. const CDuiString& sName = pControl->GetName();
  2270. if (!sName.IsEmpty())
  2271. {
  2272. if (pControl == FindControl(sName)) m_mNameHash.Remove(sName);
  2273. }
  2274. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++)
  2275. {
  2276. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  2277. if (pMsg->pSender == pControl) pMsg->pSender = NULL;
  2278. }
  2279. }
  2280. bool CPaintManagerUI::AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2281. {
  2282. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2283. if (lp)
  2284. {
  2285. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2286. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2287. {
  2288. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2289. {
  2290. return false;
  2291. }
  2292. }
  2293. aOptionGroup->Add(pControl);
  2294. }
  2295. else
  2296. {
  2297. CStdPtrArray* aOptionGroup = new CStdPtrArray(6);
  2298. aOptionGroup->Add(pControl);
  2299. m_mOptionGroup.Insert(pStrGroupName, aOptionGroup);
  2300. }
  2301. return true;
  2302. }
  2303. CStdPtrArray* CPaintManagerUI::GetOptionGroup(LPCTSTR pStrGroupName)
  2304. {
  2305. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2306. if (lp) return static_cast<CStdPtrArray*>(lp);
  2307. return NULL;
  2308. }
  2309. void CPaintManagerUI::RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2310. {
  2311. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2312. if (lp)
  2313. {
  2314. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2315. if (aOptionGroup == NULL) return;
  2316. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2317. {
  2318. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2319. {
  2320. aOptionGroup->Remove(i);
  2321. break;
  2322. }
  2323. }
  2324. if (aOptionGroup->IsEmpty())
  2325. {
  2326. delete aOptionGroup;
  2327. m_mOptionGroup.Remove(pStrGroupName);
  2328. }
  2329. }
  2330. }
  2331. void CPaintManagerUI::RemoveAllOptionGroups()
  2332. {
  2333. CStdPtrArray* aOptionGroup;
  2334. for (int i = 0; i < m_mOptionGroup.GetSize(); i++)
  2335. {
  2336. if (LPCTSTR key = m_mOptionGroup.GetAt(i))
  2337. {
  2338. aOptionGroup = static_cast<CStdPtrArray*>(m_mOptionGroup.Find(key));
  2339. delete aOptionGroup;
  2340. }
  2341. }
  2342. m_mOptionGroup.RemoveAll();
  2343. }
  2344. void CPaintManagerUI::MessageLoop()
  2345. {
  2346. MSG msg = { 0 };
  2347. while (::GetMessage(&msg, NULL, 0, 0))
  2348. {
  2349. if (!CPaintManagerUI::TranslateMessage(&msg))
  2350. {
  2351. ::TranslateMessage(&msg);
  2352. try
  2353. {
  2354. ::DispatchMessage(&msg);
  2355. }
  2356. catch (...)
  2357. {
  2358. DUITRACE(_T("EXCEPTION: %s(%d)\n"), __FILET__, __LINE__);
  2359. #ifdef _DEBUG
  2360. throw "CPaintManagerUI::MessageLoop";
  2361. #endif
  2362. }
  2363. }
  2364. }
  2365. }
  2366. void CPaintManagerUI::Term()
  2367. {
  2368. // 销毁资源管理器
  2369. CResourceManager::GetInstance()->Release();
  2370. CControlFactory::GetInstance()->Release();
  2371. // 清理共享资源
  2372. // 图片
  2373. TImageInfo* data;
  2374. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  2375. {
  2376. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  2377. {
  2378. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  2379. if (data)
  2380. {
  2381. CRenderEngine::FreeImage(data);
  2382. data = NULL;
  2383. }
  2384. }
  2385. }
  2386. m_SharedResInfo.m_ImageHash.RemoveAll();
  2387. // 字体
  2388. TFontInfo* pFontInfo;
  2389. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  2390. {
  2391. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  2392. {
  2393. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  2394. if (pFontInfo)
  2395. {
  2396. ::DeleteObject(pFontInfo->hFont);
  2397. delete pFontInfo;
  2398. pFontInfo = NULL;
  2399. }
  2400. }
  2401. }
  2402. m_SharedResInfo.m_CustomFonts.RemoveAll();
  2403. // 默认字体
  2404. if (m_SharedResInfo.m_DefaultFontInfo.hFont != NULL)
  2405. {
  2406. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  2407. }
  2408. // 样式
  2409. CDuiString* pStyle;
  2410. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  2411. {
  2412. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  2413. {
  2414. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key, false));
  2415. if (pStyle)
  2416. {
  2417. delete pStyle;
  2418. pStyle = NULL;
  2419. }
  2420. }
  2421. }
  2422. m_SharedResInfo.m_StyleHash.RemoveAll();
  2423. // 样式
  2424. CDuiString* pAttr;
  2425. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  2426. {
  2427. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  2428. {
  2429. pAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key, false));
  2430. if (pAttr)
  2431. {
  2432. delete pAttr;
  2433. pAttr = NULL;
  2434. }
  2435. }
  2436. }
  2437. m_SharedResInfo.m_AttrHash.RemoveAll();
  2438. // 关闭ZIP
  2439. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  2440. {
  2441. CloseZip((HZIP)m_hResourceZip);
  2442. m_hResourceZip = NULL;
  2443. }
  2444. if (m_cbZipBuf)
  2445. {
  2446. delete[] m_cbZipBuf;
  2447. m_cbZipBuf = nullptr;
  2448. }
  2449. }
  2450. CDPI* DuiLib::CPaintManagerUI::GetDPIObj()
  2451. {
  2452. if (m_pDPI == NULL)
  2453. {
  2454. m_pDPI = new CDPI;
  2455. }
  2456. return m_pDPI;
  2457. }
  2458. void DuiLib::CPaintManagerUI::SetDPI(int iDPI)
  2459. {
  2460. int scale1 = GetDPIObj()->GetScale();
  2461. GetDPIObj()->SetScale(iDPI);
  2462. int scale2 = GetDPIObj()->GetScale();
  2463. ResetDPIAssets();
  2464. RECT rcWnd = { 0 };
  2465. ::GetWindowRect(GetPaintWindow(), &rcWnd);
  2466. RECT* prcNewWindow = &rcWnd;
  2467. if (!::IsZoomed(GetPaintWindow()))
  2468. {
  2469. RECT rc = rcWnd;
  2470. rc.right = rcWnd.left + (rcWnd.right - rcWnd.left) * scale2 / scale1;
  2471. rc.bottom = rcWnd.top + (rcWnd.bottom - rcWnd.top) * scale2 / scale1;
  2472. prcNewWindow = &rc;
  2473. }
  2474. SetWindowPos(GetPaintWindow(), NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
  2475. if (GetRoot() != NULL) GetRoot()->NeedUpdate();
  2476. ::PostMessage(GetPaintWindow(), UIMSG_SET_DPI, 0, 0);
  2477. }
  2478. void DuiLib::CPaintManagerUI::SetAllDPI(int iDPI)
  2479. {
  2480. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2481. {
  2482. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2483. pManager->SetDPI(iDPI);
  2484. }
  2485. }
  2486. void DuiLib::CPaintManagerUI::ResetDPIAssets()
  2487. {
  2488. RemoveAllDrawInfos();
  2489. RemoveAllImages();;
  2490. for (int it = 0; it < m_ResInfo.m_CustomFonts.GetSize(); it++)
  2491. {
  2492. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(m_ResInfo.m_CustomFonts[it]));
  2493. RebuildFont(pFontInfo);
  2494. }
  2495. RebuildFont(&m_ResInfo.m_DefaultFontInfo);
  2496. for (int it = 0; it < m_SharedResInfo.m_CustomFonts.GetSize(); it++)
  2497. {
  2498. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(m_SharedResInfo.m_CustomFonts[it]));
  2499. RebuildFont(pFontInfo);
  2500. }
  2501. RebuildFont(&m_SharedResInfo.m_DefaultFontInfo);
  2502. CStdPtrArray* richEditList = FindSubControlsByClass(GetRoot(), _T("RichEditUI"));
  2503. for (int i = 0; i < richEditList->GetSize(); i++)
  2504. {
  2505. CRichEditUI* pT = static_cast<CRichEditUI*>((*richEditList)[i]);
  2506. pT->SetFont(pT->GetFont());
  2507. }
  2508. }
  2509. void DuiLib::CPaintManagerUI::RebuildFont(TFontInfo* pFontInfo)
  2510. {
  2511. ::DeleteObject(pFontInfo->hFont);
  2512. LOGFONT lf = { 0 };
  2513. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2514. _tcsncpy(lf.lfFaceName, pFontInfo->sFontName, LF_FACESIZE);
  2515. lf.lfCharSet = DEFAULT_CHARSET;
  2516. lf.lfHeight = -GetDPIObj()->Scale(pFontInfo->iSize);
  2517. lf.lfQuality = CLEARTYPE_QUALITY;
  2518. if (pFontInfo->bBold) lf.lfWeight += FW_BOLD;
  2519. if (pFontInfo->bUnderline) lf.lfUnderline = TRUE;
  2520. if (pFontInfo->bItalic) lf.lfItalic = TRUE;
  2521. HFONT hFont = ::CreateFontIndirect(&lf);
  2522. pFontInfo->hFont = hFont;
  2523. ::ZeroMemory(&(pFontInfo->tm), sizeof(pFontInfo->tm));
  2524. if (m_hDcPaint)
  2525. {
  2526. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2527. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2528. ::SelectObject(m_hDcPaint, hOldFont);
  2529. }
  2530. }
  2531. CControlUI* CPaintManagerUI::GetFocus() const
  2532. {
  2533. return m_pFocus;
  2534. }
  2535. void CPaintManagerUI::SetFocus(CControlUI* pControl)
  2536. {
  2537. // Paint manager window has focus?
  2538. HWND hFocusWnd = ::GetFocus();
  2539. if (!m_bNoActivate && hFocusWnd != m_hWndPaint && pControl != m_pFocus) ::SetFocus(m_hWndPaint);
  2540. // Already has focus?
  2541. if (pControl == m_pFocus) return;
  2542. // Remove focus from old control
  2543. if (m_pFocus != NULL)
  2544. {
  2545. TEventUI event = { 0 };
  2546. event.Type = UIEVENT_KILLFOCUS;
  2547. event.pSender = pControl;
  2548. event.dwTimestamp = ::GetTickCount();
  2549. m_pFocus->Event(event);
  2550. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2551. m_pFocus = NULL;
  2552. }
  2553. if (pControl == NULL) return;
  2554. // Set focus to new control
  2555. if (pControl != NULL
  2556. && pControl->GetManager() == this
  2557. && pControl->IsVisible()
  2558. && pControl->IsEnabled())
  2559. {
  2560. m_pFocus = pControl;
  2561. TEventUI event = { 0 };
  2562. event.Type = UIEVENT_SETFOCUS;
  2563. event.pSender = pControl;
  2564. event.dwTimestamp = ::GetTickCount();
  2565. m_pFocus->Event(event);
  2566. SendNotify(m_pFocus, DUI_MSGTYPE_SETFOCUS);
  2567. }
  2568. }
  2569. void CPaintManagerUI::SetFocusNeeded(CControlUI* pControl)
  2570. {
  2571. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  2572. if (pControl == NULL) return;
  2573. if (m_pFocus != NULL)
  2574. {
  2575. TEventUI event = { 0 };
  2576. event.Type = UIEVENT_KILLFOCUS;
  2577. event.pSender = pControl;
  2578. event.dwTimestamp = ::GetTickCount();
  2579. m_pFocus->Event(event);
  2580. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2581. m_pFocus = NULL;
  2582. }
  2583. FINDTABINFO info = { 0 };
  2584. info.pFocus = pControl;
  2585. info.bForward = false;
  2586. m_pFocus = m_pRoot->FindControl(__FindControlFromTab, &info, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2587. m_bFocusNeeded = true;
  2588. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  2589. }
  2590. bool CPaintManagerUI::SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse)
  2591. {
  2592. ASSERT(pControl != NULL);
  2593. ASSERT(uElapse > 0);
  2594. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2595. {
  2596. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2597. if (pTimer->pSender == pControl
  2598. && pTimer->hWnd == m_hWndPaint
  2599. && pTimer->nLocalID == nTimerID)
  2600. {
  2601. if (pTimer->bKilled == true)
  2602. {
  2603. if (::SetTimer(m_hWndPaint, pTimer->uWinTimer, uElapse, NULL))
  2604. {
  2605. pTimer->bKilled = false;
  2606. return true;
  2607. }
  2608. return false;
  2609. }
  2610. return false;
  2611. }
  2612. }
  2613. m_uTimerID = (++m_uTimerID) % 0xF0; //0xf1-0xfe特殊用途
  2614. if (!::SetTimer(m_hWndPaint, m_uTimerID, uElapse, NULL)) return FALSE;
  2615. TIMERINFO* pTimer = new TIMERINFO;
  2616. if (pTimer == NULL) return FALSE;
  2617. pTimer->hWnd = m_hWndPaint;
  2618. pTimer->pSender = pControl;
  2619. pTimer->nLocalID = nTimerID;
  2620. pTimer->uWinTimer = m_uTimerID;
  2621. pTimer->bKilled = false;
  2622. return m_aTimers.Add(pTimer);
  2623. }
  2624. bool CPaintManagerUI::KillTimer(CControlUI* pControl, UINT nTimerID)
  2625. {
  2626. ASSERT(pControl != NULL);
  2627. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2628. {
  2629. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2630. if (pTimer->pSender == pControl
  2631. && pTimer->hWnd == m_hWndPaint
  2632. && pTimer->nLocalID == nTimerID)
  2633. {
  2634. if (pTimer->bKilled == false)
  2635. {
  2636. if (::IsWindow(m_hWndPaint)) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2637. pTimer->bKilled = true;
  2638. return true;
  2639. }
  2640. }
  2641. }
  2642. return false;
  2643. }
  2644. void CPaintManagerUI::KillTimer(CControlUI* pControl)
  2645. {
  2646. ASSERT(pControl != NULL);
  2647. int count = m_aTimers.GetSize();
  2648. for (int i = 0, j = 0; i < count; i++)
  2649. {
  2650. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i - j]);
  2651. if (pTimer->pSender == pControl && pTimer->hWnd == m_hWndPaint)
  2652. {
  2653. if (pTimer->bKilled == false) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2654. delete pTimer;
  2655. m_aTimers.Remove(i - j);
  2656. j++;
  2657. }
  2658. }
  2659. }
  2660. void CPaintManagerUI::RemoveAllTimers()
  2661. {
  2662. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2663. {
  2664. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2665. if (pTimer->hWnd == m_hWndPaint)
  2666. {
  2667. if (pTimer->bKilled == false)
  2668. {
  2669. if (::IsWindow(m_hWndPaint)) ::KillTimer(m_hWndPaint, pTimer->uWinTimer);
  2670. }
  2671. delete pTimer;
  2672. }
  2673. }
  2674. m_aTimers.Empty();
  2675. }
  2676. void CPaintManagerUI::SetCapture()
  2677. {
  2678. ::SetCapture(m_hWndPaint);
  2679. m_bMouseCapture = true;
  2680. }
  2681. void CPaintManagerUI::ReleaseCapture()
  2682. {
  2683. ::ReleaseCapture();
  2684. m_bMouseCapture = false;
  2685. m_bDragMode = false;
  2686. }
  2687. bool CPaintManagerUI::IsCaptured()
  2688. {
  2689. return m_bMouseCapture;
  2690. }
  2691. bool CPaintManagerUI::IsPainting()
  2692. {
  2693. return m_bIsPainting;
  2694. }
  2695. void CPaintManagerUI::SetPainting(bool bIsPainting)
  2696. {
  2697. m_bIsPainting = bIsPainting;
  2698. }
  2699. bool CPaintManagerUI::SetNextTabControl(bool bForward)
  2700. {
  2701. // If we're in the process of restructuring the layout we can delay the
  2702. // focus calulation until the next repaint.
  2703. if (m_bUpdateNeeded && bForward)
  2704. {
  2705. m_bFocusNeeded = true;
  2706. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  2707. return true;
  2708. }
  2709. // Find next/previous tabbable control
  2710. FINDTABINFO info1 = { 0 };
  2711. info1.pFocus = m_pFocus;
  2712. info1.bForward = bForward;
  2713. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2714. if (pControl == NULL)
  2715. {
  2716. if (bForward)
  2717. {
  2718. // Wrap around
  2719. FINDTABINFO info2 = { 0 };
  2720. info2.pFocus = bForward ? NULL : info1.pLast;
  2721. info2.bForward = bForward;
  2722. pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2723. }
  2724. else
  2725. {
  2726. pControl = info1.pLast;
  2727. }
  2728. }
  2729. if (pControl != NULL) SetFocus(pControl);
  2730. m_bFocusNeeded = false;
  2731. return true;
  2732. }
  2733. bool CPaintManagerUI::AddNotifier(INotifyUI* pNotifier)
  2734. {
  2735. ASSERT(m_aNotifiers.Find(pNotifier) < 0);
  2736. return m_aNotifiers.Add(pNotifier);
  2737. }
  2738. bool CPaintManagerUI::RemoveNotifier(INotifyUI* pNotifier)
  2739. {
  2740. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2741. {
  2742. if (static_cast<INotifyUI*>(m_aNotifiers[i]) == pNotifier)
  2743. {
  2744. return m_aNotifiers.Remove(i);
  2745. }
  2746. }
  2747. return false;
  2748. }
  2749. bool CPaintManagerUI::AddPreMessageFilter(IMessageFilterUI* pFilter)
  2750. {
  2751. ASSERT(m_aPreMessageFilters.Find(pFilter) < 0);
  2752. return m_aPreMessageFilters.Add(pFilter);
  2753. }
  2754. bool CPaintManagerUI::RemovePreMessageFilter(IMessageFilterUI* pFilter)
  2755. {
  2756. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  2757. {
  2758. if (static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i]) == pFilter)
  2759. {
  2760. return m_aPreMessageFilters.Remove(i);
  2761. }
  2762. }
  2763. return false;
  2764. }
  2765. bool CPaintManagerUI::AddMessageFilter(IMessageFilterUI* pFilter)
  2766. {
  2767. ASSERT(m_aMessageFilters.Find(pFilter) < 0);
  2768. return m_aMessageFilters.Add(pFilter);
  2769. }
  2770. bool CPaintManagerUI::RemoveMessageFilter(IMessageFilterUI* pFilter)
  2771. {
  2772. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  2773. {
  2774. if (static_cast<IMessageFilterUI*>(m_aMessageFilters[i]) == pFilter)
  2775. {
  2776. return m_aMessageFilters.Remove(i);
  2777. }
  2778. }
  2779. return false;
  2780. }
  2781. int CPaintManagerUI::GetPostPaintCount() const
  2782. {
  2783. return m_aPostPaintControls.GetSize();
  2784. }
  2785. bool CPaintManagerUI::IsPostPaint(CControlUI* pControl)
  2786. {
  2787. return m_aPostPaintControls.Find(pControl) >= 0;
  2788. }
  2789. bool CPaintManagerUI::AddPostPaint(CControlUI* pControl)
  2790. {
  2791. ASSERT(m_aPostPaintControls.Find(pControl) < 0);
  2792. return m_aPostPaintControls.Add(pControl);
  2793. }
  2794. bool CPaintManagerUI::RemovePostPaint(CControlUI* pControl)
  2795. {
  2796. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  2797. {
  2798. if (static_cast<CControlUI*>(m_aPostPaintControls[i]) == pControl)
  2799. {
  2800. return m_aPostPaintControls.Remove(i);
  2801. }
  2802. }
  2803. return false;
  2804. }
  2805. bool CPaintManagerUI::SetPostPaintIndex(CControlUI* pControl, int iIndex)
  2806. {
  2807. RemovePostPaint(pControl);
  2808. return m_aPostPaintControls.InsertAt(iIndex, pControl);
  2809. }
  2810. int CPaintManagerUI::GetNativeWindowCount() const
  2811. {
  2812. return m_aNativeWindow.GetSize();
  2813. }
  2814. bool CPaintManagerUI::AddNativeWindow(CControlUI* pControl, HWND hChildWnd)
  2815. {
  2816. if (pControl == NULL || hChildWnd == NULL) return false;
  2817. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  2818. Invalidate(rcChildWnd);
  2819. if (m_aNativeWindow.Find(hChildWnd) >= 0) return false;
  2820. if (m_aNativeWindow.Add(hChildWnd))
  2821. {
  2822. m_aNativeWindowControl.Add(pControl);
  2823. return true;
  2824. }
  2825. return false;
  2826. }
  2827. bool CPaintManagerUI::RemoveNativeWindow(HWND hChildWnd)
  2828. {
  2829. for (int i = 0; i < m_aNativeWindow.GetSize(); i++)
  2830. {
  2831. if (static_cast<HWND>(m_aNativeWindow[i]) == hChildWnd)
  2832. {
  2833. if (m_aNativeWindow.Remove(i))
  2834. {
  2835. m_aNativeWindowControl.Remove(i);
  2836. return true;
  2837. }
  2838. return false;
  2839. }
  2840. }
  2841. return false;
  2842. }
  2843. RECT CPaintManagerUI::GetNativeWindowRect(HWND hChildWnd)
  2844. {
  2845. RECT rcChildWnd;
  2846. ::GetWindowRect(hChildWnd, &rcChildWnd);
  2847. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd));
  2848. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd) + 1);
  2849. return rcChildWnd;
  2850. }
  2851. void CPaintManagerUI::AddDelayedCleanup(CControlUI* pControl)
  2852. {
  2853. if (pControl == NULL) return;
  2854. pControl->SetManager(this, NULL, false);
  2855. m_aDelayedCleanup.Add(pControl);
  2856. PostAsyncNotify();
  2857. }
  2858. void CPaintManagerUI::AddMouseLeaveNeeded(CControlUI* pControl)
  2859. {
  2860. if (pControl == NULL) return;
  2861. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2862. {
  2863. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2864. {
  2865. return;
  2866. }
  2867. }
  2868. m_aNeedMouseLeaveNeeded.Add(pControl);
  2869. }
  2870. bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl)
  2871. {
  2872. if (pControl == NULL) return false;
  2873. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2874. {
  2875. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2876. {
  2877. return m_aNeedMouseLeaveNeeded.Remove(i);
  2878. }
  2879. }
  2880. return false;
  2881. }
  2882. void CPaintManagerUI::SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/)
  2883. {
  2884. TNotifyUI Msg;
  2885. Msg.pSender = pControl;
  2886. Msg.sType = pstrMessage;
  2887. Msg.wParam = wParam;
  2888. Msg.lParam = lParam;
  2889. SendNotify(Msg, bAsync);
  2890. }
  2891. void CPaintManagerUI::SendNotify(TNotifyUI& Msg, bool bAsync /*= false*/)
  2892. {
  2893. Msg.ptMouse = m_ptLastMousePos;
  2894. Msg.dwTimestamp = ::GetTickCount();
  2895. if (m_bUsedVirtualWnd)
  2896. {
  2897. Msg.sVirtualWnd = Msg.pSender->GetVirtualWnd();
  2898. }
  2899. if (!bAsync)
  2900. {
  2901. // Send to all listeners
  2902. if (Msg.pSender != NULL)
  2903. {
  2904. if (Msg.pSender->OnNotify) Msg.pSender->OnNotify(&Msg);
  2905. }
  2906. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2907. {
  2908. static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg);
  2909. }
  2910. }
  2911. else
  2912. {
  2913. TNotifyUI* pMsg = new TNotifyUI;
  2914. pMsg->sVirtualWnd = Msg.sVirtualWnd;
  2915. pMsg->pSender = Msg.pSender;
  2916. pMsg->sType = Msg.sType;
  2917. pMsg->wParam = Msg.wParam;
  2918. pMsg->lParam = Msg.lParam;
  2919. pMsg->ptMouse = Msg.ptMouse;
  2920. pMsg->dwTimestamp = Msg.dwTimestamp;
  2921. m_aAsyncNotify.Add(pMsg);
  2922. PostAsyncNotify();
  2923. }
  2924. }
  2925. bool CPaintManagerUI::IsForceUseSharedRes() const
  2926. {
  2927. return m_bForceUseSharedRes;
  2928. }
  2929. void CPaintManagerUI::SetForceUseSharedRes(bool bForce)
  2930. {
  2931. m_bForceUseSharedRes = bForce;
  2932. }
  2933. DWORD CPaintManagerUI::GetDefaultDisabledColor() const
  2934. {
  2935. return m_ResInfo.m_dwDefaultDisabledColor;
  2936. }
  2937. void CPaintManagerUI::SetDefaultDisabledColor(DWORD dwColor, bool bShared)
  2938. {
  2939. if (bShared)
  2940. {
  2941. if (m_ResInfo.m_dwDefaultDisabledColor == m_SharedResInfo.m_dwDefaultDisabledColor)
  2942. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2943. m_SharedResInfo.m_dwDefaultDisabledColor = dwColor;
  2944. }
  2945. else
  2946. {
  2947. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2948. }
  2949. }
  2950. DWORD CPaintManagerUI::GetDefaultFontColor() const
  2951. {
  2952. return m_ResInfo.m_dwDefaultFontColor;
  2953. }
  2954. void CPaintManagerUI::SetDefaultFontColor(DWORD dwColor, bool bShared)
  2955. {
  2956. if (bShared)
  2957. {
  2958. if (m_ResInfo.m_dwDefaultFontColor == m_SharedResInfo.m_dwDefaultFontColor)
  2959. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2960. m_SharedResInfo.m_dwDefaultFontColor = dwColor;
  2961. }
  2962. else
  2963. {
  2964. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2965. }
  2966. }
  2967. DWORD CPaintManagerUI::GetDefaultLinkFontColor() const
  2968. {
  2969. return m_ResInfo.m_dwDefaultLinkFontColor;
  2970. }
  2971. void CPaintManagerUI::SetDefaultLinkFontColor(DWORD dwColor, bool bShared)
  2972. {
  2973. if (bShared)
  2974. {
  2975. if (m_ResInfo.m_dwDefaultLinkFontColor == m_SharedResInfo.m_dwDefaultLinkFontColor)
  2976. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2977. m_SharedResInfo.m_dwDefaultLinkFontColor = dwColor;
  2978. }
  2979. else
  2980. {
  2981. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2982. }
  2983. }
  2984. DWORD CPaintManagerUI::GetDefaultLinkHoverFontColor() const
  2985. {
  2986. return m_ResInfo.m_dwDefaultLinkHoverFontColor;
  2987. }
  2988. void CPaintManagerUI::SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared)
  2989. {
  2990. if (bShared)
  2991. {
  2992. if (m_ResInfo.m_dwDefaultLinkHoverFontColor == m_SharedResInfo.m_dwDefaultLinkHoverFontColor)
  2993. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2994. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2995. }
  2996. else
  2997. {
  2998. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2999. }
  3000. }
  3001. DWORD CPaintManagerUI::GetDefaultSelectedBkColor() const
  3002. {
  3003. return m_ResInfo.m_dwDefaultSelectedBkColor;
  3004. }
  3005. void CPaintManagerUI::SetDefaultSelectedBkColor(DWORD dwColor, bool bShared)
  3006. {
  3007. if (bShared)
  3008. {
  3009. if (m_ResInfo.m_dwDefaultSelectedBkColor == m_SharedResInfo.m_dwDefaultSelectedBkColor)
  3010. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  3011. m_SharedResInfo.m_dwDefaultSelectedBkColor = dwColor;
  3012. }
  3013. else
  3014. {
  3015. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  3016. }
  3017. }
  3018. TFontInfo* CPaintManagerUI::GetDefaultFontInfo()
  3019. {
  3020. if (m_ResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  3021. {
  3022. if (m_SharedResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  3023. {
  3024. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_SharedResInfo.m_DefaultFontInfo.hFont);
  3025. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  3026. ::SelectObject(m_hDcPaint, hOldFont);
  3027. }
  3028. return &m_SharedResInfo.m_DefaultFontInfo;
  3029. }
  3030. else
  3031. {
  3032. if (m_ResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  3033. {
  3034. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_ResInfo.m_DefaultFontInfo.hFont);
  3035. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  3036. ::SelectObject(m_hDcPaint, hOldFont);
  3037. }
  3038. return &m_ResInfo.m_DefaultFontInfo;
  3039. }
  3040. }
  3041. void CPaintManagerUI::SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3042. {
  3043. LOGFONT lf = { 0 };
  3044. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  3045. if (lstrlen(pStrFontName) > 0)
  3046. {
  3047. TCHAR szFaceName[32] = { 0 };//_T("@");
  3048. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  3049. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  3050. }
  3051. lf.lfCharSet = DEFAULT_CHARSET;
  3052. lf.lfHeight = -GetDPIObj()->Scale(nSize);;
  3053. if (bBold) lf.lfWeight += FW_BOLD;
  3054. if (bUnderline) lf.lfUnderline = TRUE;
  3055. if (bItalic) lf.lfItalic = TRUE;
  3056. if (bStrikeout) lf.lfStrikeOut = TRUE;
  3057. HFONT hFont = ::CreateFontIndirect(&lf);
  3058. if (hFont == NULL) return;
  3059. if (bShared)
  3060. {
  3061. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  3062. m_SharedResInfo.m_DefaultFontInfo.hFont = hFont;
  3063. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  3064. m_SharedResInfo.m_DefaultFontInfo.iSize = nSize;
  3065. m_SharedResInfo.m_DefaultFontInfo.bBold = bBold;
  3066. m_SharedResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  3067. m_SharedResInfo.m_DefaultFontInfo.bItalic = bItalic;
  3068. m_SharedResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  3069. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  3070. if (m_hDcPaint)
  3071. {
  3072. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3073. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  3074. ::SelectObject(m_hDcPaint, hOldFont);
  3075. }
  3076. }
  3077. else
  3078. {
  3079. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  3080. m_ResInfo.m_DefaultFontInfo.hFont = hFont;
  3081. m_ResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  3082. m_ResInfo.m_DefaultFontInfo.iSize = nSize;
  3083. m_ResInfo.m_DefaultFontInfo.bBold = bBold;
  3084. m_ResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  3085. m_ResInfo.m_DefaultFontInfo.bItalic = bItalic;
  3086. m_ResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  3087. ::ZeroMemory(&m_ResInfo.m_DefaultFontInfo.tm, sizeof(m_ResInfo.m_DefaultFontInfo.tm));
  3088. if (m_hDcPaint)
  3089. {
  3090. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3091. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  3092. ::SelectObject(m_hDcPaint, hOldFont);
  3093. }
  3094. }
  3095. }
  3096. DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const
  3097. {
  3098. if (bShared)
  3099. return m_SharedResInfo.m_CustomFonts.GetSize();
  3100. else
  3101. return m_ResInfo.m_CustomFonts.GetSize();
  3102. }
  3103. HFONT CPaintManagerUI::AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3104. {
  3105. LOGFONT lf = { 0 };
  3106. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  3107. if (lstrlen(pStrFontName) > 0)
  3108. {
  3109. TCHAR szFaceName[32] = { 0 };//_T("@");
  3110. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  3111. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  3112. }
  3113. lf.lfCharSet = DEFAULT_CHARSET;
  3114. lf.lfHeight = -GetDPIObj()->Scale(nSize);
  3115. if (bBold) lf.lfWeight = FW_BOLD;
  3116. if (bUnderline) lf.lfUnderline = TRUE;
  3117. if (bItalic) lf.lfItalic = TRUE;
  3118. if (bStrikeout) lf.lfStrikeOut = TRUE;
  3119. HFONT hFont = ::CreateFontIndirect(&lf);
  3120. if (hFont == NULL) return NULL;
  3121. TFontInfo* pFontInfo = new TFontInfo;
  3122. if (!pFontInfo) return false;
  3123. ::ZeroMemory(pFontInfo, sizeof(TFontInfo));
  3124. pFontInfo->hFont = hFont;
  3125. pFontInfo->sFontName = lf.lfFaceName;
  3126. pFontInfo->iSize = nSize;
  3127. pFontInfo->bBold = bBold;
  3128. pFontInfo->bUnderline = bUnderline;
  3129. pFontInfo->bItalic = bItalic;
  3130. pFontInfo->bStrikeout = bStrikeout;
  3131. if (m_hDcPaint)
  3132. {
  3133. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3134. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3135. ::SelectObject(m_hDcPaint, hOldFont);
  3136. }
  3137. TCHAR idBuffer[16];
  3138. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3139. _itot(id, idBuffer, 10);
  3140. if (bShared || m_bForceUseSharedRes)
  3141. {
  3142. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3143. if (pOldFontInfo)
  3144. {
  3145. ::DeleteObject(pOldFontInfo->hFont);
  3146. delete pOldFontInfo;
  3147. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  3148. }
  3149. if (!m_SharedResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  3150. {
  3151. ::DeleteObject(hFont);
  3152. delete pFontInfo;
  3153. return NULL;
  3154. }
  3155. }
  3156. else
  3157. {
  3158. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3159. if (pOldFontInfo)
  3160. {
  3161. ::DeleteObject(pOldFontInfo->hFont);
  3162. delete pOldFontInfo;
  3163. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  3164. }
  3165. if (!m_ResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  3166. {
  3167. ::DeleteObject(hFont);
  3168. delete pFontInfo;
  3169. return NULL;
  3170. }
  3171. }
  3172. return hFont;
  3173. }
  3174. void CPaintManagerUI::AddFontArray(LPCTSTR pstrPath)
  3175. {
  3176. LPBYTE pData = NULL;
  3177. DWORD dwSize = 0;
  3178. do
  3179. {
  3180. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  3181. if (CPaintManagerUI::GetResourceZip().IsEmpty())
  3182. {
  3183. sFile += pstrPath;
  3184. HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  3185. FILE_ATTRIBUTE_NORMAL, NULL);
  3186. if (hFile == INVALID_HANDLE_VALUE) break;
  3187. dwSize = ::GetFileSize(hFile, NULL);
  3188. if (dwSize == 0) break;
  3189. DWORD dwRead = 0;
  3190. pData = new BYTE[dwSize];
  3191. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  3192. ::CloseHandle(hFile);
  3193. if (dwRead != dwSize)
  3194. {
  3195. delete[] pData;
  3196. pData = NULL;
  3197. break;
  3198. }
  3199. }
  3200. else
  3201. {
  3202. sFile += CPaintManagerUI::GetResourceZip();
  3203. HZIP hz = NULL;
  3204. if (CPaintManagerUI::IsCachedResourceZip()) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
  3205. else
  3206. {
  3207. CDuiString sFilePwd = CPaintManagerUI::GetResourceZipPwd();
  3208. #ifdef UNICODE
  3209. char* pwd = w2a((wchar_t*)sFilePwd.GetData());
  3210. hz = OpenZip(sFile.GetData(), pwd);
  3211. if (pwd) delete[] pwd;
  3212. #else
  3213. hz = OpenZip(sFile.GetData(), sFilePwd.GetData());
  3214. #endif
  3215. }
  3216. if (hz == NULL) break;
  3217. ZIPENTRY ze;
  3218. int i = 0;
  3219. CDuiString key = pstrPath;
  3220. key.Replace(_T("\\"), _T("/"));
  3221. if (FindZipItem(hz, key, true, &i, &ze) != 0) break;
  3222. dwSize = ze.unc_size;
  3223. if (dwSize == 0) break;
  3224. pData = new BYTE[dwSize];
  3225. int res = UnzipItem(hz, i, pData, dwSize);
  3226. if (res != 0x00000000 && res != 0x00000600)
  3227. {
  3228. delete[] pData;
  3229. pData = NULL;
  3230. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  3231. break;
  3232. }
  3233. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  3234. }
  3235. } while (0);
  3236. while (!pData)
  3237. {
  3238. //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
  3239. HANDLE hFile = ::CreateFile(pstrPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  3240. if (hFile == INVALID_HANDLE_VALUE) break;
  3241. dwSize = ::GetFileSize(hFile, NULL);
  3242. if (dwSize == 0) break;
  3243. DWORD dwRead = 0;
  3244. pData = new BYTE[dwSize];
  3245. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  3246. ::CloseHandle(hFile);
  3247. if (dwRead != dwSize)
  3248. {
  3249. delete[] pData;
  3250. pData = NULL;
  3251. }
  3252. break;
  3253. }
  3254. DWORD nFonts;
  3255. HANDLE hFont = ::AddFontMemResourceEx(pData, dwSize, NULL, &nFonts);
  3256. delete[] pData;
  3257. pData = NULL;
  3258. m_aFonts.Add(hFont);
  3259. }
  3260. HFONT CPaintManagerUI::GetFont(int id)
  3261. {
  3262. if (id < 0) return GetDefaultFontInfo()->hFont;
  3263. TCHAR idBuffer[16];
  3264. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3265. _itot(id, idBuffer, 10);
  3266. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3267. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3268. if (!pFontInfo) return GetDefaultFontInfo()->hFont;
  3269. return pFontInfo->hFont;
  3270. }
  3271. HFONT CPaintManagerUI::GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout)
  3272. {
  3273. TFontInfo* pFontInfo = NULL;
  3274. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3275. {
  3276. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3277. {
  3278. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3279. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3280. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3281. && pFontInfo->bStrikeout == bStrikeout)
  3282. return pFontInfo->hFont;
  3283. }
  3284. }
  3285. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3286. {
  3287. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3288. {
  3289. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3290. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3291. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3292. && pFontInfo->bStrikeout == bStrikeout)
  3293. return pFontInfo->hFont;
  3294. }
  3295. }
  3296. return NULL;
  3297. }
  3298. int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared)
  3299. {
  3300. TFontInfo* pFontInfo = NULL;
  3301. if (bShared)
  3302. {
  3303. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3304. {
  3305. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3306. {
  3307. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3308. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3309. }
  3310. }
  3311. }
  3312. else
  3313. {
  3314. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3315. {
  3316. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3317. {
  3318. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3319. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3320. }
  3321. }
  3322. }
  3323. return -1;
  3324. }
  3325. int CPaintManagerUI::GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3326. {
  3327. TFontInfo* pFontInfo = NULL;
  3328. if (bShared)
  3329. {
  3330. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3331. {
  3332. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3333. {
  3334. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3335. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3336. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3337. && pFontInfo->bStrikeout == bStrikeout)
  3338. return _ttoi(key);
  3339. }
  3340. }
  3341. }
  3342. else
  3343. {
  3344. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3345. {
  3346. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3347. {
  3348. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3349. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3350. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3351. && pFontInfo->bStrikeout == bStrikeout)
  3352. return _ttoi(key);
  3353. }
  3354. }
  3355. }
  3356. return -1;
  3357. }
  3358. void CPaintManagerUI::RemoveFont(HFONT hFont, bool bShared)
  3359. {
  3360. TFontInfo* pFontInfo = NULL;
  3361. if (bShared)
  3362. {
  3363. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3364. {
  3365. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3366. {
  3367. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3368. if (pFontInfo && pFontInfo->hFont == hFont)
  3369. {
  3370. ::DeleteObject(pFontInfo->hFont);
  3371. delete pFontInfo;
  3372. m_SharedResInfo.m_CustomFonts.Remove(key);
  3373. return;
  3374. }
  3375. }
  3376. }
  3377. }
  3378. else
  3379. {
  3380. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3381. {
  3382. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3383. {
  3384. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3385. if (pFontInfo && pFontInfo->hFont == hFont)
  3386. {
  3387. ::DeleteObject(pFontInfo->hFont);
  3388. delete pFontInfo;
  3389. m_ResInfo.m_CustomFonts.Remove(key);
  3390. return;
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. void CPaintManagerUI::RemoveFont(int id, bool bShared)
  3397. {
  3398. TCHAR idBuffer[16];
  3399. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3400. _itot(id, idBuffer, 10);
  3401. TFontInfo* pFontInfo = NULL;
  3402. if (bShared)
  3403. {
  3404. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3405. if (pFontInfo)
  3406. {
  3407. ::DeleteObject(pFontInfo->hFont);
  3408. delete pFontInfo;
  3409. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  3410. }
  3411. }
  3412. else
  3413. {
  3414. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3415. if (pFontInfo)
  3416. {
  3417. ::DeleteObject(pFontInfo->hFont);
  3418. delete pFontInfo;
  3419. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  3420. }
  3421. }
  3422. }
  3423. void CPaintManagerUI::RemoveAllFonts(bool bShared)
  3424. {
  3425. TFontInfo* pFontInfo;
  3426. if (bShared)
  3427. {
  3428. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3429. {
  3430. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3431. {
  3432. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  3433. if (pFontInfo)
  3434. {
  3435. ::DeleteObject(pFontInfo->hFont);
  3436. delete pFontInfo;
  3437. }
  3438. }
  3439. }
  3440. m_SharedResInfo.m_CustomFonts.RemoveAll();
  3441. }
  3442. else
  3443. {
  3444. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3445. {
  3446. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3447. {
  3448. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key, false));
  3449. if (pFontInfo)
  3450. {
  3451. ::DeleteObject(pFontInfo->hFont);
  3452. delete pFontInfo;
  3453. }
  3454. }
  3455. }
  3456. m_ResInfo.m_CustomFonts.RemoveAll();
  3457. }
  3458. }
  3459. TFontInfo* CPaintManagerUI::GetFontInfo(int id)
  3460. {
  3461. if (id < 0) return GetDefaultFontInfo();
  3462. TCHAR idBuffer[16];
  3463. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3464. _itot(id, idBuffer, 10);
  3465. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3466. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3467. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3468. if (pFontInfo->tm.tmHeight == 0)
  3469. {
  3470. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3471. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3472. ::SelectObject(m_hDcPaint, hOldFont);
  3473. }
  3474. return pFontInfo;
  3475. }
  3476. TFontInfo* CPaintManagerUI::GetFontInfo(HFONT hFont)
  3477. {
  3478. TFontInfo* pFontInfo = NULL;
  3479. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3480. {
  3481. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3482. {
  3483. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3484. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3485. }
  3486. }
  3487. if (!pFontInfo)
  3488. {
  3489. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3490. {
  3491. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3492. {
  3493. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3494. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3495. }
  3496. }
  3497. }
  3498. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3499. if (pFontInfo->tm.tmHeight == 0)
  3500. {
  3501. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3502. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3503. ::SelectObject(m_hDcPaint, hOldFont);
  3504. }
  3505. return pFontInfo;
  3506. }
  3507. const TImageInfo* CPaintManagerUI::GetImage(LPCTSTR bitmap)
  3508. {
  3509. TImageInfo* data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3510. if (!data) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3511. return data;
  3512. }
  3513. const TImageInfo* CPaintManagerUI::GetImageEx(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, HINSTANCE instance)
  3514. {
  3515. const TImageInfo* data = GetImage(bitmap);
  3516. if (!data)
  3517. {
  3518. if (AddImage(bitmap, type, mask, bUseHSL, bGdiplus, false, instance))
  3519. {
  3520. if (m_bForceUseSharedRes) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3521. else data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3522. }
  3523. }
  3524. return data;
  3525. }
  3526. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, bool bShared, HINSTANCE instance)
  3527. {
  3528. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3529. TImageInfo* data = NULL;
  3530. if (type != NULL && lstrlen(type) > 0)
  3531. {
  3532. if (isdigit(*bitmap))
  3533. {
  3534. LPTSTR pstr = NULL;
  3535. int iIndex = _tcstol(bitmap, &pstr, 10);
  3536. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(iIndex, type, mask, instance) : CRenderEngine::LoadImage(iIndex, type, mask, instance);
  3537. }
  3538. }
  3539. else
  3540. {
  3541. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(bitmap, NULL, mask, instance) : CRenderEngine::LoadImage(bitmap, NULL, mask, instance);
  3542. if (!data)
  3543. {
  3544. CDuiString sImageName = bitmap;
  3545. int iAtIdx = sImageName.ReverseFind(_T('@'));
  3546. int iDotIdx = sImageName.ReverseFind(_T('.'));
  3547. if (iAtIdx != -1 && iDotIdx != -1)
  3548. {
  3549. CDuiString sExe = sImageName.Mid(iDotIdx);
  3550. sImageName = sImageName.Left(iAtIdx) + sExe;
  3551. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(sImageName.GetData(), NULL, mask, instance) : CRenderEngine::LoadImage(sImageName.GetData(), NULL, mask, instance);
  3552. }
  3553. }
  3554. }
  3555. if (data == NULL)
  3556. {
  3557. return NULL;
  3558. }
  3559. data->bUseHSL = bUseHSL;
  3560. if (type != NULL) data->sResType = type;
  3561. data->dwMask = mask;
  3562. if (data->bUseHSL)
  3563. {
  3564. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3565. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3566. }
  3567. else data->pSrcBits = NULL;
  3568. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3569. if (data)
  3570. {
  3571. if (bShared || m_bForceUseSharedRes)
  3572. {
  3573. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3574. if (pOldImageInfo)
  3575. {
  3576. CRenderEngine::FreeImage(pOldImageInfo);
  3577. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3578. }
  3579. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3580. {
  3581. CRenderEngine::FreeImage(data);
  3582. data = NULL;
  3583. }
  3584. }
  3585. else
  3586. {
  3587. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3588. if (pOldImageInfo)
  3589. {
  3590. CRenderEngine::FreeImage(pOldImageInfo);
  3591. m_ResInfo.m_ImageHash.Remove(bitmap);
  3592. }
  3593. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3594. {
  3595. CRenderEngine::FreeImage(data);
  3596. data = NULL;
  3597. }
  3598. }
  3599. }
  3600. return data;
  3601. }
  3602. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared)
  3603. {
  3604. // 因无法确定外部HBITMAP格式,不能使用hsl调整
  3605. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3606. if (hBitmap == NULL || iWidth <= 0 || iHeight <= 0) return NULL;
  3607. TImageInfo* data = new TImageInfo;
  3608. data->pBits = NULL;
  3609. data->pSrcBits = NULL;
  3610. data->hBitmap = hBitmap;
  3611. data->pBits = NULL;
  3612. data->nX = iWidth;
  3613. data->nY = iHeight;
  3614. data->bAlpha = bAlpha;
  3615. data->bUseHSL = false;
  3616. data->pSrcBits = NULL;
  3617. data->dwMask = 0;
  3618. if (bShared || m_bForceUseSharedRes)
  3619. {
  3620. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3621. {
  3622. CRenderEngine::FreeImage(data);
  3623. data = NULL;
  3624. }
  3625. }
  3626. else
  3627. {
  3628. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3629. {
  3630. CRenderEngine::FreeImage(data);
  3631. data = NULL;
  3632. }
  3633. }
  3634. return data;
  3635. }
  3636. void CPaintManagerUI::RemoveImage(LPCTSTR bitmap, bool bShared)
  3637. {
  3638. TImageInfo* data = NULL;
  3639. if (bShared)
  3640. {
  3641. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3642. if (data)
  3643. {
  3644. CRenderEngine::FreeImage(data);
  3645. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3646. }
  3647. }
  3648. else
  3649. {
  3650. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3651. if (data)
  3652. {
  3653. CRenderEngine::FreeImage(data);
  3654. m_ResInfo.m_ImageHash.Remove(bitmap);
  3655. }
  3656. }
  3657. }
  3658. void CPaintManagerUI::RemoveAllImages(bool bShared)
  3659. {
  3660. if (bShared)
  3661. {
  3662. TImageInfo* data;
  3663. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3664. {
  3665. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3666. {
  3667. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  3668. if (data)
  3669. {
  3670. CRenderEngine::FreeImage(data);
  3671. }
  3672. }
  3673. }
  3674. m_SharedResInfo.m_ImageHash.RemoveAll();
  3675. }
  3676. else
  3677. {
  3678. TImageInfo* data;
  3679. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3680. {
  3681. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3682. {
  3683. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key, false));
  3684. if (data)
  3685. {
  3686. CRenderEngine::FreeImage(data);
  3687. }
  3688. }
  3689. }
  3690. m_ResInfo.m_ImageHash.RemoveAll();
  3691. }
  3692. }
  3693. void CPaintManagerUI::AdjustSharedImagesHSL()
  3694. {
  3695. TImageInfo* data;
  3696. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3697. {
  3698. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3699. {
  3700. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key));
  3701. if (data && data->bUseHSL)
  3702. {
  3703. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3704. }
  3705. }
  3706. }
  3707. }
  3708. void CPaintManagerUI::AdjustImagesHSL()
  3709. {
  3710. TImageInfo* data;
  3711. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3712. {
  3713. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3714. {
  3715. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key));
  3716. if (data && data->bUseHSL)
  3717. {
  3718. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3719. }
  3720. }
  3721. }
  3722. Invalidate();
  3723. }
  3724. void CPaintManagerUI::PostAsyncNotify()
  3725. {
  3726. if (!m_bAsyncNotifyPosted)
  3727. {
  3728. ::PostMessage(m_hWndPaint, WM_APP + 1, 0, 0L);
  3729. m_bAsyncNotifyPosted = true;
  3730. }
  3731. }
  3732. void CPaintManagerUI::ReloadSharedImages()
  3733. {
  3734. TImageInfo* data = NULL;
  3735. TImageInfo* pNewData = NULL;
  3736. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3737. {
  3738. if (LPCTSTR bitmap = m_SharedResInfo.m_ImageHash.GetAt(i))
  3739. {
  3740. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3741. if (data != NULL)
  3742. {
  3743. if (!data->sResType.IsEmpty())
  3744. {
  3745. if (isdigit(*bitmap))
  3746. {
  3747. LPTSTR pstr = NULL;
  3748. int iIndex = _tcstol(bitmap, &pstr, 10);
  3749. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3750. }
  3751. }
  3752. else
  3753. {
  3754. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3755. }
  3756. if (pNewData == NULL) continue;
  3757. CRenderEngine::FreeImage(data, false);
  3758. data->hBitmap = pNewData->hBitmap;
  3759. data->pImage = pNewData->pImage;
  3760. data->pBits = pNewData->pBits;
  3761. data->nX = pNewData->nX;
  3762. data->nY = pNewData->nY;
  3763. data->bAlpha = pNewData->bAlpha;
  3764. data->pSrcBits = NULL;
  3765. if (data->bUseHSL)
  3766. {
  3767. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3768. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3769. }
  3770. else data->pSrcBits = NULL;
  3771. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3772. delete pNewData;
  3773. }
  3774. }
  3775. }
  3776. }
  3777. void CPaintManagerUI::ReloadImages()
  3778. {
  3779. RemoveAllDrawInfos();
  3780. TImageInfo* data = NULL;
  3781. TImageInfo* pNewData = NULL;
  3782. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3783. {
  3784. if (LPCTSTR bitmap = m_ResInfo.m_ImageHash.GetAt(i))
  3785. {
  3786. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3787. if (data != NULL)
  3788. {
  3789. if (!data->sResType.IsEmpty())
  3790. {
  3791. if (isdigit(*bitmap))
  3792. {
  3793. LPTSTR pstr = NULL;
  3794. int iIndex = _tcstol(bitmap, &pstr, 10);
  3795. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3796. }
  3797. }
  3798. else
  3799. {
  3800. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3801. }
  3802. CRenderEngine::FreeImage(data, false);
  3803. if (pNewData == NULL)
  3804. {
  3805. m_ResInfo.m_ImageHash.Remove(bitmap);
  3806. continue;
  3807. }
  3808. data->hBitmap = pNewData->hBitmap;
  3809. data->pBits = pNewData->pBits;
  3810. data->nX = pNewData->nX;
  3811. data->nY = pNewData->nY;
  3812. data->bAlpha = pNewData->bAlpha;
  3813. data->pSrcBits = NULL;
  3814. if (data->bUseHSL)
  3815. {
  3816. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3817. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3818. }
  3819. else data->pSrcBits = NULL;
  3820. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3821. delete pNewData;
  3822. }
  3823. }
  3824. }
  3825. if (m_pRoot) m_pRoot->Invalidate();
  3826. }
  3827. const TDrawInfo* CPaintManagerUI::GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3828. {
  3829. CDuiString sKey;
  3830. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3831. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3832. if (pDrawInfo == NULL && !sKey.IsEmpty())
  3833. {
  3834. pDrawInfo = new TDrawInfo();
  3835. pDrawInfo->Parse(pStrImage, pStrModify, this);
  3836. m_ResInfo.m_DrawInfoHash.Insert(sKey, pDrawInfo);
  3837. }
  3838. return pDrawInfo;
  3839. }
  3840. void CPaintManagerUI::RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3841. {
  3842. CDuiString sKey;
  3843. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3844. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3845. if (pDrawInfo != NULL)
  3846. {
  3847. m_ResInfo.m_DrawInfoHash.Remove(sKey);
  3848. delete pDrawInfo;
  3849. pDrawInfo = NULL;
  3850. }
  3851. }
  3852. void CPaintManagerUI::RemoveAllDrawInfos()
  3853. {
  3854. TDrawInfo* pDrawInfo = NULL;
  3855. for (int i = 0; i < m_ResInfo.m_DrawInfoHash.GetSize(); i++)
  3856. {
  3857. LPCTSTR key = m_ResInfo.m_DrawInfoHash.GetAt(i);
  3858. if (key != NULL)
  3859. {
  3860. pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(key, false));
  3861. if (pDrawInfo)
  3862. {
  3863. delete pDrawInfo;
  3864. pDrawInfo = NULL;
  3865. }
  3866. }
  3867. }
  3868. m_ResInfo.m_DrawInfoHash.RemoveAll();
  3869. }
  3870. void CPaintManagerUI::AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared)
  3871. {
  3872. if (bShared || m_bForceUseSharedRes)
  3873. {
  3874. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3875. if (pDefaultAttr != NULL)
  3876. {
  3877. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3878. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3879. }
  3880. }
  3881. else
  3882. {
  3883. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3884. if (pDefaultAttr != NULL)
  3885. {
  3886. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3887. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3888. }
  3889. }
  3890. }
  3891. LPCTSTR CPaintManagerUI::GetDefaultAttributeList(LPCTSTR pStrControlName) const
  3892. {
  3893. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3894. if (!pDefaultAttr) pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3895. if (pDefaultAttr) return pDefaultAttr->GetData();
  3896. return NULL;
  3897. }
  3898. bool CPaintManagerUI::RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared)
  3899. {
  3900. if (bShared)
  3901. {
  3902. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3903. if (!pDefaultAttr) return false;
  3904. delete pDefaultAttr;
  3905. return m_SharedResInfo.m_AttrHash.Remove(pStrControlName);
  3906. }
  3907. else
  3908. {
  3909. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3910. if (!pDefaultAttr) return false;
  3911. delete pDefaultAttr;
  3912. return m_ResInfo.m_AttrHash.Remove(pStrControlName);
  3913. }
  3914. }
  3915. void CPaintManagerUI::RemoveAllDefaultAttributeList(bool bShared)
  3916. {
  3917. if (bShared)
  3918. {
  3919. CDuiString* pDefaultAttr;
  3920. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  3921. {
  3922. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  3923. {
  3924. pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key));
  3925. if (pDefaultAttr) delete pDefaultAttr;
  3926. }
  3927. }
  3928. m_SharedResInfo.m_AttrHash.RemoveAll();
  3929. }
  3930. else
  3931. {
  3932. CDuiString* pDefaultAttr;
  3933. for (int i = 0; i < m_ResInfo.m_AttrHash.GetSize(); i++)
  3934. {
  3935. if (LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i))
  3936. {
  3937. pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key));
  3938. if (pDefaultAttr) delete pDefaultAttr;
  3939. }
  3940. }
  3941. m_ResInfo.m_AttrHash.RemoveAll();
  3942. }
  3943. }
  3944. void CPaintManagerUI::AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  3945. {
  3946. if (pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0')) return;
  3947. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  3948. if (pCostomAttr != NULL)
  3949. {
  3950. if (m_mWindowCustomAttrHash.Find(pstrName) == NULL)
  3951. m_mWindowCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  3952. else
  3953. delete pCostomAttr;
  3954. }
  3955. }
  3956. LPCTSTR CPaintManagerUI::GetWindowCustomAttribute(LPCTSTR pstrName) const
  3957. {
  3958. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3959. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3960. if (pCostomAttr) return pCostomAttr->GetData();
  3961. return NULL;
  3962. }
  3963. bool CPaintManagerUI::RemoveWindowCustomAttribute(LPCTSTR pstrName)
  3964. {
  3965. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3966. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3967. if (!pCostomAttr) return false;
  3968. delete pCostomAttr;
  3969. return m_mWindowCustomAttrHash.Remove(pstrName);
  3970. }
  3971. void CPaintManagerUI::RemoveAllWindowCustomAttribute()
  3972. {
  3973. CDuiString* pCostomAttr;
  3974. for (int i = 0; i < m_mWindowCustomAttrHash.GetSize(); i++)
  3975. {
  3976. if (LPCTSTR key = m_mWindowCustomAttrHash.GetAt(i))
  3977. {
  3978. pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(key));
  3979. delete pCostomAttr;
  3980. }
  3981. }
  3982. m_mWindowCustomAttrHash.Resize();
  3983. }
  3984. CControlUI* CPaintManagerUI::GetRoot() const
  3985. {
  3986. ASSERT(m_pRoot);
  3987. return m_pRoot;
  3988. }
  3989. CControlUI* CPaintManagerUI::FindControl(POINT pt) const
  3990. {
  3991. ASSERT(m_pRoot);
  3992. return m_pRoot->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3993. }
  3994. CControlUI* CPaintManagerUI::FindControl(LPCTSTR pstrName) const
  3995. {
  3996. ASSERT(m_pRoot);
  3997. return static_cast<CControlUI*>(m_mNameHash.Find(pstrName));
  3998. }
  3999. CControlUI* CPaintManagerUI::FindSubControlByPoint(CControlUI* pParent, POINT pt) const
  4000. {
  4001. if (pParent == NULL) pParent = GetRoot();
  4002. ASSERT(pParent);
  4003. return pParent->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  4004. }
  4005. CControlUI* CPaintManagerUI::FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const
  4006. {
  4007. if (pParent == NULL) pParent = GetRoot();
  4008. ASSERT(pParent);
  4009. return pParent->FindControl(__FindControlFromName, (LPVOID)pstrName, UIFIND_ALL);
  4010. }
  4011. CControlUI* CPaintManagerUI::FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex)
  4012. {
  4013. if (pParent == NULL) pParent = GetRoot();
  4014. ASSERT(pParent);
  4015. m_aFoundControls.Resize(iIndex + 1);
  4016. return pParent->FindControl(__FindControlFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  4017. }
  4018. CStdPtrArray* CPaintManagerUI::FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass)
  4019. {
  4020. if (pParent == NULL) pParent = GetRoot();
  4021. ASSERT(pParent);
  4022. m_aFoundControls.Empty();
  4023. pParent->FindControl(__FindControlsFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  4024. return &m_aFoundControls;
  4025. }
  4026. CStdPtrArray* CPaintManagerUI::GetFoundControls()
  4027. {
  4028. return &m_aFoundControls;
  4029. }
  4030. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
  4031. {
  4032. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
  4033. const CDuiString& sName = pThis->GetName();
  4034. if (sName.IsEmpty()) return NULL;
  4035. // Add this control to the hash list
  4036. pManager->m_mNameHash.Set(sName, pThis);
  4037. return NULL; // Attempt to add all controls
  4038. }
  4039. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromCount(CControlUI* /*pThis*/, LPVOID pData)
  4040. {
  4041. int* pnCount = static_cast<int*>(pData);
  4042. (*pnCount)++;
  4043. return NULL; // Count all controls
  4044. }
  4045. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromPoint(CControlUI* pThis, LPVOID pData)
  4046. {
  4047. LPPOINT pPoint = static_cast<LPPOINT>(pData);
  4048. return ::PtInRect(&pThis->GetPos(), *pPoint) ? pThis : NULL;
  4049. }
  4050. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromTab(CControlUI* pThis, LPVOID pData)
  4051. {
  4052. FINDTABINFO* pInfo = static_cast<FINDTABINFO*>(pData);
  4053. if (pInfo->pFocus == pThis)
  4054. {
  4055. if (pInfo->bForward) pInfo->bNextIsIt = true;
  4056. return pInfo->bForward ? NULL : pInfo->pLast;
  4057. }
  4058. if ((pThis->GetControlFlags() & UIFLAG_TABSTOP) == 0) return NULL;
  4059. pInfo->pLast = pThis;
  4060. if (pInfo->bNextIsIt) return pThis;
  4061. if (pInfo->pFocus == NULL) return pThis;
  4062. return NULL; // Examine all controls
  4063. }
  4064. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromShortcut(CControlUI* pThis, LPVOID pData)
  4065. {
  4066. if (!pThis->IsVisible()) return NULL;
  4067. FINDSHORTCUT* pFS = static_cast<FINDSHORTCUT*>(pData);
  4068. if (pFS->ch == toupper(pThis->GetShortcut())) pFS->bPickNext = true;
  4069. if (_tcsstr(pThis->GetClass(), _T("LabelUI")) != NULL) return NULL; // Labels never get focus!
  4070. return pFS->bPickNext ? pThis : NULL;
  4071. }
  4072. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromName(CControlUI* pThis, LPVOID pData)
  4073. {
  4074. LPCTSTR pstrName = static_cast<LPCTSTR>(pData);
  4075. const CDuiString& sName = pThis->GetName();
  4076. if (sName.IsEmpty()) return NULL;
  4077. return (_tcsicmp(sName, pstrName) == 0) ? pThis : NULL;
  4078. }
  4079. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromClass(CControlUI* pThis, LPVOID pData)
  4080. {
  4081. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  4082. LPCTSTR pType = pThis->GetClass();
  4083. CStdPtrArray* pFoundControls = pThis->GetManager()->GetFoundControls();
  4084. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  4085. {
  4086. int iIndex = -1;
  4087. while (pFoundControls->GetAt(++iIndex) != NULL);
  4088. if (iIndex < pFoundControls->GetSize()) pFoundControls->SetAt(iIndex, pThis);
  4089. }
  4090. if (pFoundControls->GetAt(pFoundControls->GetSize() - 1) != NULL) return pThis;
  4091. return NULL;
  4092. }
  4093. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromClass(CControlUI* pThis, LPVOID pData)
  4094. {
  4095. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  4096. LPCTSTR pType = pThis->GetClass();
  4097. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  4098. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  4099. return NULL;
  4100. }
  4101. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromUpdate(CControlUI* pThis, LPVOID pData)
  4102. {
  4103. if (pThis->IsUpdateNeeded())
  4104. {
  4105. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  4106. return pThis;
  4107. }
  4108. return NULL;
  4109. }
  4110. bool CPaintManagerUI::TranslateAccelerator(LPMSG pMsg)
  4111. {
  4112. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  4113. {
  4114. LRESULT lResult = static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i])->TranslateAccelerator(pMsg);
  4115. if (lResult == S_OK) return true;
  4116. }
  4117. return false;
  4118. }
  4119. bool CPaintManagerUI::TranslateMessage(const LPMSG pMsg)
  4120. {
  4121. // Pretranslate Message takes care of system-wide messages, such as
  4122. // tabbing and shortcut key-combos. We'll look for all messages for
  4123. // each window and any child control attached.
  4124. UINT uStyle = GetWindowStyle(pMsg->hwnd);
  4125. UINT uChildRes = uStyle & WS_CHILD;
  4126. LRESULT lRes = 0;
  4127. if (uChildRes != 0)
  4128. {
  4129. HWND hWndParent = ::GetParent(pMsg->hwnd);
  4130. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  4131. {
  4132. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  4133. HWND hTempParent = hWndParent;
  4134. while (hTempParent)
  4135. {
  4136. if (pMsg->hwnd == pT->GetPaintWindow() || hTempParent == pT->GetPaintWindow())
  4137. {
  4138. if (pT->TranslateAccelerator(pMsg))
  4139. return true;
  4140. pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes);
  4141. }
  4142. hTempParent = GetParent(hTempParent);
  4143. }
  4144. }
  4145. }
  4146. else
  4147. {
  4148. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  4149. {
  4150. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  4151. if (pMsg->hwnd == pT->GetPaintWindow())
  4152. {
  4153. if (pT->TranslateAccelerator(pMsg))
  4154. return true;
  4155. if (pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes))
  4156. return true;
  4157. return false;
  4158. }
  4159. }
  4160. }
  4161. return false;
  4162. }
  4163. bool CPaintManagerUI::AddTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  4164. {
  4165. ASSERT(m_aTranslateAccelerator.Find(pTranslateAccelerator) < 0);
  4166. return m_aTranslateAccelerator.Add(pTranslateAccelerator);
  4167. }
  4168. bool CPaintManagerUI::RemoveTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  4169. {
  4170. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  4171. {
  4172. if (static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i]) == pTranslateAccelerator)
  4173. {
  4174. return m_aTranslateAccelerator.Remove(i);
  4175. }
  4176. }
  4177. return false;
  4178. }
  4179. void CPaintManagerUI::UsedVirtualWnd(bool bUsed)
  4180. {
  4181. m_bUsedVirtualWnd = bUsed;
  4182. }
  4183. // 样式管理
  4184. void CPaintManagerUI::AddStyle(LPCTSTR pName, LPCTSTR pDeclarationList, bool bShared)
  4185. {
  4186. CDuiString* pStyle = new CDuiString(pDeclarationList);
  4187. if (bShared || m_bForceUseSharedRes)
  4188. {
  4189. if (!m_SharedResInfo.m_StyleHash.Insert(pName, pStyle))
  4190. {
  4191. delete pStyle;
  4192. }
  4193. }
  4194. else
  4195. {
  4196. if (!m_ResInfo.m_StyleHash.Insert(pName, pStyle))
  4197. {
  4198. delete pStyle;
  4199. }
  4200. }
  4201. }
  4202. LPCTSTR CPaintManagerUI::GetStyle(LPCTSTR pName) const
  4203. {
  4204. CDuiString* pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  4205. if (!pStyle) pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  4206. if (pStyle) return pStyle->GetData();
  4207. else return NULL;
  4208. }
  4209. BOOL CPaintManagerUI::RemoveStyle(LPCTSTR pName, bool bShared)
  4210. {
  4211. CDuiString* pStyle = NULL;
  4212. if (bShared)
  4213. {
  4214. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  4215. if (pStyle)
  4216. {
  4217. delete pStyle;
  4218. m_SharedResInfo.m_StyleHash.Remove(pName);
  4219. }
  4220. }
  4221. else
  4222. {
  4223. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  4224. if (pStyle)
  4225. {
  4226. delete pStyle;
  4227. m_ResInfo.m_StyleHash.Remove(pName);
  4228. }
  4229. }
  4230. return true;
  4231. }
  4232. const CStdStringPtrMap& CPaintManagerUI::GetStyles(bool bShared) const
  4233. {
  4234. if (bShared) return m_SharedResInfo.m_StyleHash;
  4235. else return m_ResInfo.m_StyleHash;
  4236. }
  4237. void CPaintManagerUI::RemoveAllStyle(bool bShared)
  4238. {
  4239. if (bShared)
  4240. {
  4241. CDuiString* pStyle;
  4242. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  4243. {
  4244. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  4245. {
  4246. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key));
  4247. delete pStyle;
  4248. }
  4249. }
  4250. m_SharedResInfo.m_StyleHash.RemoveAll();
  4251. }
  4252. else
  4253. {
  4254. CDuiString* pStyle;
  4255. for (int i = 0; i < m_ResInfo.m_StyleHash.GetSize(); i++)
  4256. {
  4257. if (LPCTSTR key = m_ResInfo.m_StyleHash.GetAt(i))
  4258. {
  4259. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(key));
  4260. delete pStyle;
  4261. }
  4262. }
  4263. m_ResInfo.m_StyleHash.RemoveAll();
  4264. }
  4265. }
  4266. const TImageInfo* CPaintManagerUI::GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify)
  4267. {
  4268. CDuiString sImageName = pStrImage;
  4269. CDuiString sImageResType = _T("");
  4270. DWORD dwMask = 0;
  4271. CDuiString sItem;
  4272. CDuiString sValue;
  4273. LPTSTR pstr = NULL;
  4274. for (int i = 0; i < 2; ++i)
  4275. {
  4276. if (i == 1)
  4277. pStrImage = pStrModify;
  4278. if (!pStrImage) continue;
  4279. while (*pStrImage != _T('\0'))
  4280. {
  4281. sItem.Empty();
  4282. sValue.Empty();
  4283. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4284. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  4285. {
  4286. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4287. while (pStrImage < pstrTemp)
  4288. {
  4289. sItem += *pStrImage++;
  4290. }
  4291. }
  4292. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4293. if (*pStrImage++ != _T('=')) break;
  4294. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4295. if (*pStrImage++ != _T('\'')) break;
  4296. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  4297. {
  4298. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4299. while (pStrImage < pstrTemp)
  4300. {
  4301. sValue += *pStrImage++;
  4302. }
  4303. }
  4304. if (*pStrImage++ != _T('\'')) break;
  4305. if (!sValue.IsEmpty())
  4306. {
  4307. if (sItem == _T("file") || sItem == _T("res"))
  4308. {
  4309. sImageName = sValue;
  4310. }
  4311. else if (sItem == _T("restype"))
  4312. {
  4313. sImageResType = sValue;
  4314. }
  4315. else if (sItem == _T("mask"))
  4316. {
  4317. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  4318. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  4319. }
  4320. }
  4321. if (*pStrImage++ != _T(' ')) break;
  4322. }
  4323. }
  4324. return GetImageEx(sImageName, sImageResType, dwMask);
  4325. }
  4326. bool CPaintManagerUI::EnableDragDrop(bool bEnable)
  4327. {
  4328. if (m_bDragDrop == bEnable) return false;
  4329. m_bDragDrop = bEnable;
  4330. if (bEnable)
  4331. {
  4332. AddRef();
  4333. if (FAILED(RegisterDragDrop(m_hWndPaint, this)))
  4334. {
  4335. return false;
  4336. }
  4337. SetTargetWnd(m_hWndPaint);
  4338. FORMATETC ftetc = { 0 };
  4339. ftetc.cfFormat = CF_BITMAP;
  4340. ftetc.dwAspect = DVASPECT_CONTENT;
  4341. ftetc.lindex = -1;
  4342. ftetc.tymed = TYMED_GDI;
  4343. AddSuportedFormat(ftetc);
  4344. ftetc.cfFormat = CF_DIB;
  4345. ftetc.tymed = TYMED_HGLOBAL;
  4346. AddSuportedFormat(ftetc);
  4347. ftetc.cfFormat = CF_HDROP;
  4348. ftetc.tymed = TYMED_HGLOBAL;
  4349. AddSuportedFormat(ftetc);
  4350. ftetc.cfFormat = CF_ENHMETAFILE;
  4351. ftetc.tymed = TYMED_ENHMF;
  4352. AddSuportedFormat(ftetc);
  4353. }
  4354. else
  4355. {
  4356. Release();
  4357. if (FAILED(RevokeDragDrop(m_hWndPaint)))
  4358. {
  4359. return false;
  4360. }
  4361. }
  4362. return true;
  4363. }
  4364. void CPaintManagerUI::SetDragDrop(IDragDropUI* pDragDrop)
  4365. {
  4366. m_pDragDrop = pDragDrop;
  4367. }
  4368. static WORD DIBNumColors(void* pv)
  4369. {
  4370. int bits;
  4371. LPBITMAPINFOHEADER lpbi;
  4372. LPBITMAPCOREHEADER lpbc;
  4373. lpbi = ((LPBITMAPINFOHEADER)pv);
  4374. lpbc = ((LPBITMAPCOREHEADER)pv);
  4375. /* With the BITMAPINFO format headers, the size of the palette
  4376. * is in biClrUsed, whereas in the BITMAPCORE - style headers, it
  4377. * is dependent on the bits per pixel ( = 2 raised to the power of
  4378. * bits/pixel).
  4379. */
  4380. if (lpbi->biSize != sizeof(BITMAPCOREHEADER))
  4381. {
  4382. if (lpbi->biClrUsed != 0)
  4383. return (WORD)lpbi->biClrUsed;
  4384. bits = lpbi->biBitCount;
  4385. }
  4386. else
  4387. bits = lpbc->bcBitCount;
  4388. switch (bits)
  4389. {
  4390. case 1:
  4391. return 2;
  4392. case 4:
  4393. return 16;
  4394. case 8:
  4395. return 256;
  4396. default:
  4397. /* A 24 bitcount DIB has no color table */
  4398. return 0;
  4399. }
  4400. }
  4401. //code taken from SEEDIB MSDN sample
  4402. static WORD ColorTableSize(LPVOID lpv)
  4403. {
  4404. LPBITMAPINFOHEADER lpbih = (LPBITMAPINFOHEADER)lpv;
  4405. if (lpbih->biSize != sizeof(BITMAPCOREHEADER))
  4406. {
  4407. if (((LPBITMAPINFOHEADER)(lpbih))->biCompression == BI_BITFIELDS)
  4408. /* Remember that 16/32bpp dibs can still have a color table */
  4409. return (sizeof(DWORD) * 3) + (DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4410. else
  4411. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4412. }
  4413. else
  4414. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBTRIPLE));
  4415. }
  4416. bool CPaintManagerUI::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect)
  4417. {
  4418. POINT ptMouse = { 0 };
  4419. GetCursorPos(&ptMouse);
  4420. ::SendMessage(m_hTargetWnd, WM_LBUTTONUP, NULL, MAKELPARAM(ptMouse.x, ptMouse.y));
  4421. if (pFmtEtc->cfFormat == CF_DIB && medium.tymed == TYMED_HGLOBAL)
  4422. {
  4423. if (medium.hGlobal != NULL)
  4424. {
  4425. LPBITMAPINFOHEADER lpbi = (BITMAPINFOHEADER*)GlobalLock(medium.hGlobal);
  4426. if (lpbi != NULL)
  4427. {
  4428. HBITMAP hbm = NULL;
  4429. HDC hdc = GetDC(NULL);
  4430. if (hdc != NULL)
  4431. {
  4432. int i = ((BITMAPFILEHEADER*)lpbi)->bfOffBits;
  4433. hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi,
  4434. (LONG)CBM_INIT,
  4435. (LPSTR)lpbi + lpbi->biSize + ColorTableSize(lpbi),
  4436. (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
  4437. ::ReleaseDC(NULL, hdc);
  4438. }
  4439. GlobalUnlock(medium.hGlobal);
  4440. if (hbm != NULL)
  4441. hbm = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
  4442. if (hbm != NULL)
  4443. DeleteObject(hbm);
  4444. return true; //release the medium
  4445. }
  4446. }
  4447. }
  4448. if (pFmtEtc->cfFormat == CF_BITMAP && medium.tymed == TYMED_GDI)
  4449. {
  4450. if (medium.hBitmap != NULL)
  4451. {
  4452. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)medium.hBitmap);
  4453. if (hBmp != NULL)
  4454. DeleteObject(hBmp);
  4455. return false; //don't free the bitmap
  4456. }
  4457. }
  4458. if (pFmtEtc->cfFormat == CF_ENHMETAFILE && medium.tymed == TYMED_ENHMF)
  4459. {
  4460. ENHMETAHEADER emh;
  4461. GetEnhMetaFileHeader(medium.hEnhMetaFile, sizeof(ENHMETAHEADER), &emh);
  4462. RECT rc;//={0,0,EnhMetaHdr.rclBounds.right-EnhMetaHdr.rclBounds.left, EnhMetaHdr.rclBounds.bottom-EnhMetaHdr.rclBounds.top};
  4463. HDC hDC = GetDC(m_hTargetWnd);
  4464. //start code: taken from ENHMETA.EXE MSDN Sample
  4465. //*ALSO NEED to GET the pallete (select and RealizePalette it, but i was too lazy*
  4466. // Get the characteristics of the output device
  4467. float PixelsX = (float)GetDeviceCaps(hDC, HORZRES);
  4468. float PixelsY = (float)GetDeviceCaps(hDC, VERTRES);
  4469. float MMX = (float)GetDeviceCaps(hDC, HORZSIZE);
  4470. float MMY = (float)GetDeviceCaps(hDC, VERTSIZE);
  4471. // Calculate the rect in which to draw the metafile based on the
  4472. // intended size and the current output device resolution
  4473. // Remember that the intended size is given in 0.01mm units, so
  4474. // convert those to device units on the target device
  4475. rc.top = (int)((float)(emh.rclFrame.top) * PixelsY / (MMY * 100.0f));
  4476. rc.left = (int)((float)(emh.rclFrame.left) * PixelsX / (MMX * 100.0f));
  4477. rc.right = (int)((float)(emh.rclFrame.right) * PixelsX / (MMX * 100.0f));
  4478. rc.bottom = (int)((float)(emh.rclFrame.bottom) * PixelsY / (MMY * 100.0f));
  4479. //end code: taken from ENHMETA.EXE MSDN Sample
  4480. HDC hdcMem = CreateCompatibleDC(hDC);
  4481. HGDIOBJ hBmpMem = CreateCompatibleBitmap(hDC, emh.rclBounds.right, emh.rclBounds.bottom);
  4482. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBmpMem);
  4483. PlayEnhMetaFile(hdcMem, medium.hEnhMetaFile, &rc);
  4484. HBITMAP hBmp = (HBITMAP)::SelectObject(hdcMem, hOldBmp);
  4485. DeleteDC(hdcMem);
  4486. ReleaseDC(m_hTargetWnd, hDC);
  4487. hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
  4488. if (hBmp != NULL)
  4489. DeleteObject(hBmp);
  4490. return true;
  4491. }
  4492. if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
  4493. {
  4494. HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
  4495. if (hDrop != NULL)
  4496. {
  4497. TCHAR szFileName[MAX_PATH];
  4498. UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
  4499. if (cFiles > 0)
  4500. {
  4501. DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName));
  4502. HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
  4503. if (hBitmap)
  4504. {
  4505. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
  4506. if (hBmp != NULL)
  4507. DeleteObject(hBmp);
  4508. }
  4509. }
  4510. }
  4511. GlobalUnlock(medium.hGlobal);
  4512. }
  4513. return true; //let base free the medium
  4514. }
  4515. } // namespace DuiLib
  4516. #pragma warning(pop)