UIManager.cpp 127 KB

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