UIManager.cpp 139 KB

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