UIManager.cpp 130 KB

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