UIManager.cpp 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581
  1. #include "StdAfx.h"
  2. #include <zmouse.h>
  3. #include <stdlib.h>
  4. DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that has been opened
  5. typedef DWORD ZRESULT;
  6. #define OpenZip OpenZipU
  7. #define CloseZip(hz) CloseZipU(hz)
  8. extern HZIP OpenZipU(void *z,unsigned int len,DWORD flags);
  9. extern ZRESULT CloseZipU(HZIP hz);
  10. namespace DuiLib {
  11. /////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. //
  14. static UINT MapKeyState()
  15. {
  16. UINT uState = 0;
  17. if( ::GetKeyState(VK_CONTROL) < 0 ) uState |= MK_CONTROL;
  18. if( ::GetKeyState(VK_RBUTTON) < 0 ) uState |= MK_RBUTTON;
  19. if( ::GetKeyState(VK_LBUTTON) < 0 ) uState |= MK_LBUTTON;
  20. if( ::GetKeyState(VK_SHIFT) < 0 ) uState |= MK_SHIFT;
  21. if( ::GetKeyState(VK_MENU) < 0 ) uState |= MK_ALT;
  22. return uState;
  23. }
  24. typedef struct tagFINDTABINFO
  25. {
  26. CControlUI* pFocus;
  27. CControlUI* pLast;
  28. bool bForward;
  29. bool bNextIsIt;
  30. } FINDTABINFO;
  31. typedef struct tagFINDSHORTCUT
  32. {
  33. TCHAR ch;
  34. bool bPickNext;
  35. } FINDSHORTCUT;
  36. typedef struct tagTIMERINFO
  37. {
  38. CControlUI* pSender;
  39. UINT nLocalID;
  40. HWND hWnd;
  41. UINT uWinTimer;
  42. bool bKilled;
  43. } TIMERINFO;
  44. /////////////////////////////////////////////////////////////////////////////////////
  45. tagTDrawInfo::tagTDrawInfo()
  46. {
  47. Clear();
  48. }
  49. tagTDrawInfo::tagTDrawInfo(LPCTSTR lpsz)
  50. {
  51. Clear();
  52. sDrawString = lpsz;
  53. }
  54. void tagTDrawInfo::Clear()
  55. {
  56. sDrawString.Empty();
  57. sImageName.Empty();
  58. ::ZeroMemory(&bLoaded, sizeof(tagTDrawInfo) - offsetof(tagTDrawInfo, bLoaded));
  59. uFade = 255;
  60. }
  61. /////////////////////////////////////////////////////////////////////////////////////
  62. typedef BOOL (__stdcall *PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  63. PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL;
  64. HPEN m_hUpdateRectPen = NULL;
  65. HINSTANCE CPaintManagerUI::m_hResourceInstance = NULL;
  66. CDuiString CPaintManagerUI::m_pStrResourcePath;
  67. CDuiString CPaintManagerUI::m_pStrResourceZip;
  68. HANDLE CPaintManagerUI::m_hResourceZip = NULL;
  69. bool CPaintManagerUI::m_bCachedResourceZip = true;
  70. TResInfo CPaintManagerUI::m_SharedResInfo;
  71. HINSTANCE CPaintManagerUI::m_hInstance = NULL;
  72. bool CPaintManagerUI::m_bUseHSL = false;
  73. short CPaintManagerUI::m_H = 180;
  74. short CPaintManagerUI::m_S = 100;
  75. short CPaintManagerUI::m_L = 100;
  76. CDuiPtrArray CPaintManagerUI::m_aPreMessages;
  77. CDuiPtrArray CPaintManagerUI::m_aPlugins;
  78. CPaintManagerUI::CPaintManagerUI() :
  79. m_hWndPaint(NULL),
  80. m_hDcPaint(NULL),
  81. m_hDcOffscreen(NULL),
  82. m_hDcBackground(NULL),
  83. m_hbmpOffscreen(NULL),
  84. m_pOffscreenBits(NULL),
  85. m_hbmpBackground(NULL),
  86. m_pBackgroundBits(NULL),
  87. m_iTooltipWidth(-1),
  88. m_iLastTooltipWidth(-1),
  89. m_hwndTooltip(NULL),
  90. m_iHoverTime(1000),
  91. m_bNoActivate(false),
  92. m_bShowUpdateRect(false),
  93. m_uTimerID(0x1000),
  94. m_pRoot(NULL),
  95. m_pFocus(NULL),
  96. m_pEventHover(NULL),
  97. m_pEventClick(NULL),
  98. m_pEventKey(NULL),
  99. m_pLastToolTip(NULL),
  100. m_bFirstLayout(true),
  101. m_bFocusNeeded(false),
  102. m_bUpdateNeeded(false),
  103. m_bMouseTracking(false),
  104. m_bMouseCapture(false),
  105. m_bIsPainting(false),
  106. m_bOffscreenPaint(true),
  107. m_bUsedVirtualWnd(false),
  108. m_bAsyncNotifyPosted(false),
  109. m_bForceUseSharedRes(false),
  110. m_nOpacity(0xFF),
  111. m_bLayered(false),
  112. m_bLayeredChanged(false)
  113. {
  114. if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  115. {
  116. m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA;
  117. m_SharedResInfo.m_dwDefaultFontColor = 0xFF000000;
  118. m_SharedResInfo.m_dwDefaultLinkFontColor = 0xFF0000FF;
  119. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = 0xFFD3215F;
  120. m_SharedResInfo.m_dwDefaultSelectedBkColor = 0xFFBAE4FF;
  121. LOGFONT lf = { 0 };
  122. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  123. lf.lfCharSet = DEFAULT_CHARSET;
  124. HFONT hDefaultFont = ::CreateFontIndirect(&lf);
  125. m_SharedResInfo.m_DefaultFontInfo.hFont = hDefaultFont;
  126. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  127. m_SharedResInfo.m_DefaultFontInfo.iSize = -lf.lfHeight;
  128. m_SharedResInfo.m_DefaultFontInfo.bBold = (lf.lfWeight >= FW_BOLD);
  129. m_SharedResInfo.m_DefaultFontInfo.bUnderline = (lf.lfUnderline == TRUE);
  130. m_SharedResInfo.m_DefaultFontInfo.bItalic = (lf.lfItalic == TRUE);
  131. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  132. }
  133. m_ResInfo.m_dwDefaultDisabledColor = m_SharedResInfo.m_dwDefaultDisabledColor;
  134. m_ResInfo.m_dwDefaultFontColor = m_SharedResInfo.m_dwDefaultFontColor;
  135. m_ResInfo.m_dwDefaultLinkFontColor = m_SharedResInfo.m_dwDefaultLinkFontColor;
  136. m_ResInfo.m_dwDefaultLinkHoverFontColor = m_SharedResInfo.m_dwDefaultLinkHoverFontColor;
  137. m_ResInfo.m_dwDefaultSelectedBkColor = m_SharedResInfo.m_dwDefaultSelectedBkColor;
  138. if( m_hUpdateRectPen == NULL ) {
  139. m_hUpdateRectPen = ::CreatePen(PS_SOLID, 1, RGB(220, 0, 0));
  140. // Boot Windows Common Controls (for the ToolTip control)
  141. ::InitCommonControls();
  142. ::LoadLibrary(_T("msimg32.dll"));
  143. }
  144. m_szMinWindow.cx = 0;
  145. m_szMinWindow.cy = 0;
  146. m_szMaxWindow.cx = 0;
  147. m_szMaxWindow.cy = 0;
  148. m_szInitWindowSize.cx = 0;
  149. m_szInitWindowSize.cy = 0;
  150. m_szRoundCorner.cx = m_szRoundCorner.cy = 0;
  151. ::ZeroMemory(&m_rcSizeBox, sizeof(m_rcSizeBox));
  152. ::ZeroMemory(&m_rcCaption, sizeof(m_rcCaption));
  153. ::ZeroMemory(&m_rcLayeredInset, sizeof(m_rcLayeredInset));
  154. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  155. m_ptLastMousePos.x = m_ptLastMousePos.y = -1;
  156. }
  157. CPaintManagerUI::~CPaintManagerUI()
  158. {
  159. // Delete the control-tree structures
  160. for( int i = 0; i < m_aDelayedCleanup.GetSize(); i++ ) static_cast<CControlUI*>(m_aDelayedCleanup[i])->Delete();
  161. for( int i = 0; i < m_aAsyncNotify.GetSize(); i++ ) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  162. m_mNameHash.Resize(0);
  163. if( m_pRoot != NULL ) m_pRoot->Delete();
  164. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  165. RemoveAllFonts();
  166. RemoveAllImages();
  167. RemoveAllDefaultAttributeList();
  168. RemoveAllWindowCustomAttribute();
  169. RemoveAllOptionGroups();
  170. RemoveAllTimers();
  171. // Reset other parts...
  172. if( m_hwndTooltip != NULL )
  173. {
  174. ::DestroyWindow(m_hwndTooltip);
  175. m_hwndTooltip = NULL;
  176. }
  177. m_pLastToolTip = NULL;
  178. if( m_hDcOffscreen != NULL ) ::DeleteDC(m_hDcOffscreen);
  179. if( m_hDcBackground != NULL ) ::DeleteDC(m_hDcBackground);
  180. if( m_hbmpOffscreen != NULL ) ::DeleteObject(m_hbmpOffscreen);
  181. if( m_hbmpBackground != NULL ) ::DeleteObject(m_hbmpBackground);
  182. if( m_hDcPaint != NULL ) ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  183. m_aPreMessages.Remove(m_aPreMessages.Find(this));
  184. }
  185. void CPaintManagerUI::Init(HWND hWnd, LPCTSTR pstrName)
  186. {
  187. ASSERT(::IsWindow(hWnd));
  188. m_mNameHash.Resize();
  189. RemoveAllFonts();
  190. RemoveAllImages();
  191. RemoveAllDefaultAttributeList();
  192. RemoveAllWindowCustomAttribute();
  193. RemoveAllOptionGroups();
  194. RemoveAllTimers();
  195. m_sName.Empty();
  196. if( pstrName != NULL ) m_sName = pstrName;
  197. if( m_hWndPaint != hWnd ) {
  198. m_hWndPaint = hWnd;
  199. m_hDcPaint = ::GetDC(hWnd);
  200. m_aPreMessages.Add(this);
  201. }
  202. }
  203. HINSTANCE CPaintManagerUI::GetInstance()
  204. {
  205. return m_hInstance;
  206. }
  207. CDuiString CPaintManagerUI::GetInstancePath()
  208. {
  209. if( m_hInstance == NULL ) return _T('\0');
  210. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  211. ::GetModuleFileName(m_hInstance, tszModule, MAX_PATH);
  212. CDuiString sInstancePath = tszModule;
  213. int pos = sInstancePath.ReverseFind(_T('\\'));
  214. if( pos >= 0 ) sInstancePath = sInstancePath.Left(pos + 1);
  215. return sInstancePath;
  216. }
  217. CDuiString CPaintManagerUI::GetCurrentPath()
  218. {
  219. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  220. ::GetCurrentDirectory(MAX_PATH, tszModule);
  221. return tszModule;
  222. }
  223. HINSTANCE CPaintManagerUI::GetResourceDll()
  224. {
  225. if( m_hResourceInstance == NULL ) return m_hInstance;
  226. return m_hResourceInstance;
  227. }
  228. const CDuiString& CPaintManagerUI::GetResourcePath()
  229. {
  230. return m_pStrResourcePath;
  231. }
  232. const CDuiString& CPaintManagerUI::GetResourceZip()
  233. {
  234. return m_pStrResourceZip;
  235. }
  236. bool CPaintManagerUI::IsCachedResourceZip()
  237. {
  238. return m_bCachedResourceZip;
  239. }
  240. HANDLE CPaintManagerUI::GetResourceZipHandle()
  241. {
  242. return m_hResourceZip;
  243. }
  244. void CPaintManagerUI::SetInstance(HINSTANCE hInst)
  245. {
  246. m_hInstance = hInst;
  247. }
  248. void CPaintManagerUI::SetCurrentPath(LPCTSTR pStrPath)
  249. {
  250. ::SetCurrentDirectory(pStrPath);
  251. }
  252. void CPaintManagerUI::SetResourceDll(HINSTANCE hInst)
  253. {
  254. m_hResourceInstance = hInst;
  255. }
  256. void CPaintManagerUI::SetResourcePath(LPCTSTR pStrPath)
  257. {
  258. m_pStrResourcePath = pStrPath;
  259. if( m_pStrResourcePath.IsEmpty() ) return;
  260. TCHAR cEnd = m_pStrResourcePath.GetAt(m_pStrResourcePath.GetLength() - 1);
  261. if( cEnd != _T('\\') && cEnd != _T('/') ) m_pStrResourcePath += _T('\\');
  262. }
  263. void CPaintManagerUI::SetResourceZip(LPVOID pVoid, unsigned int len)
  264. {
  265. if( m_pStrResourceZip == _T("membuffer") ) return;
  266. if( m_bCachedResourceZip && m_hResourceZip != NULL ) {
  267. CloseZip((HZIP)m_hResourceZip);
  268. m_hResourceZip = NULL;
  269. }
  270. m_pStrResourceZip = _T("membuffer");
  271. if( m_bCachedResourceZip )
  272. m_hResourceZip = (HANDLE)OpenZip(pVoid, len, 3);
  273. }
  274. void CPaintManagerUI::SetResourceZip(LPCTSTR pStrPath, bool bCachedResourceZip)
  275. {
  276. if( m_pStrResourceZip == pStrPath && m_bCachedResourceZip == bCachedResourceZip ) return;
  277. if( m_bCachedResourceZip && m_hResourceZip != NULL ) {
  278. CloseZip((HZIP)m_hResourceZip);
  279. m_hResourceZip = NULL;
  280. }
  281. m_pStrResourceZip = pStrPath;
  282. m_bCachedResourceZip = bCachedResourceZip;
  283. if( m_bCachedResourceZip ) {
  284. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  285. sFile += CPaintManagerUI::GetResourceZip();
  286. m_hResourceZip = (HANDLE)OpenZip((void*)sFile.GetData(), 0, 2);
  287. }
  288. }
  289. bool CPaintManagerUI::GetHSL(short* H, short* S, short* L)
  290. {
  291. *H = m_H;
  292. *S = m_S;
  293. *L = m_L;
  294. return m_bUseHSL;
  295. }
  296. void CPaintManagerUI::SetHSL(bool bUseHSL, short H, short S, short L)
  297. {
  298. if( m_bUseHSL || m_bUseHSL != bUseHSL ) {
  299. m_bUseHSL = bUseHSL;
  300. if( H == m_H && S == m_S && L == m_L ) return;
  301. m_H = CLAMP(H, 0, 360);
  302. m_S = CLAMP(S, 0, 200);
  303. m_L = CLAMP(L, 0, 200);
  304. AdjustSharedImagesHSL();
  305. for( int i = 0; i < m_aPreMessages.GetSize(); i++ ) {
  306. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  307. if( pManager != NULL ) pManager->AdjustImagesHSL();
  308. }
  309. }
  310. }
  311. void CPaintManagerUI::ReloadSkin()
  312. {
  313. ReloadSharedImages();
  314. for( int i = 0; i < m_aPreMessages.GetSize(); i++ ) {
  315. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  316. pManager->ReloadImages();
  317. }
  318. }
  319. CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName)
  320. {
  321. if( pstrName == NULL ) return NULL;
  322. CDuiString sName = pstrName;
  323. if( sName.IsEmpty() ) return NULL;
  324. for( int i = 0; i < m_aPreMessages.GetSize(); i++ ) {
  325. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  326. if( pManager != NULL && sName == pManager->GetName() ) return pManager;
  327. }
  328. return NULL;
  329. }
  330. CDuiPtrArray* CPaintManagerUI::GetPaintManagers()
  331. {
  332. return &m_aPreMessages;
  333. }
  334. bool CPaintManagerUI::LoadPlugin(LPCTSTR pstrModuleName)
  335. {
  336. ASSERT( !::IsBadStringPtr(pstrModuleName,-1) || pstrModuleName == NULL );
  337. if( pstrModuleName == NULL ) return false;
  338. HMODULE hModule = ::LoadLibrary(pstrModuleName);
  339. if( hModule != NULL ) {
  340. LPCREATECONTROL lpCreateControl = (LPCREATECONTROL)::GetProcAddress(hModule, "CreateControl");
  341. if( lpCreateControl != NULL ) {
  342. if( m_aPlugins.Find(lpCreateControl) >= 0 ) return true;
  343. m_aPlugins.Add(lpCreateControl);
  344. return true;
  345. }
  346. }
  347. return false;
  348. }
  349. CDuiPtrArray* CPaintManagerUI::GetPlugins()
  350. {
  351. return &m_aPlugins;
  352. }
  353. HWND CPaintManagerUI::GetPaintWindow() const
  354. {
  355. return m_hWndPaint;
  356. }
  357. HWND CPaintManagerUI::GetTooltipWindow() const
  358. {
  359. return m_hwndTooltip;
  360. }
  361. int CPaintManagerUI::GetTooltipWindowWidth() const
  362. {
  363. return m_iTooltipWidth;
  364. }
  365. void CPaintManagerUI::SetTooltipWindowWidth(int iWidth)
  366. {
  367. if( m_iTooltipWidth != iWidth ) {
  368. m_iTooltipWidth = iWidth;
  369. if( m_hwndTooltip != NULL && m_iTooltipWidth >= 0 ) {
  370. m_iTooltipWidth = (int)::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, m_iTooltipWidth);
  371. }
  372. }
  373. }
  374. int CPaintManagerUI::GetHoverTime() const
  375. {
  376. return m_iHoverTime;
  377. }
  378. void CPaintManagerUI::SetHoverTime(int iTime)
  379. {
  380. m_iHoverTime = iTime;
  381. }
  382. LPCTSTR CPaintManagerUI::GetName() const
  383. {
  384. return m_sName;
  385. }
  386. HDC CPaintManagerUI::GetPaintDC() const
  387. {
  388. return m_hDcPaint;
  389. }
  390. HBITMAP CPaintManagerUI::GetPaintOffscreenBitmap()
  391. {
  392. return m_hbmpOffscreen;
  393. }
  394. POINT CPaintManagerUI::GetMousePos() const
  395. {
  396. return m_ptLastMousePos;
  397. }
  398. SIZE CPaintManagerUI::GetClientSize() const
  399. {
  400. RECT rcClient = { 0 };
  401. ::GetClientRect(m_hWndPaint, &rcClient);
  402. return CDuiSize(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  403. }
  404. SIZE CPaintManagerUI::GetInitSize()
  405. {
  406. return m_szInitWindowSize;
  407. }
  408. void CPaintManagerUI::SetInitSize(int cx, int cy)
  409. {
  410. m_szInitWindowSize.cx = cx;
  411. m_szInitWindowSize.cy = cy;
  412. if( m_pRoot == NULL && m_hWndPaint != NULL ) {
  413. ::SetWindowPos(m_hWndPaint, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  414. }
  415. }
  416. RECT& CPaintManagerUI::GetSizeBox()
  417. {
  418. return m_rcSizeBox;
  419. }
  420. void CPaintManagerUI::SetSizeBox(RECT& rcSizeBox)
  421. {
  422. m_rcSizeBox = rcSizeBox;
  423. }
  424. RECT& CPaintManagerUI::GetCaptionRect()
  425. {
  426. return m_rcCaption;
  427. }
  428. void CPaintManagerUI::SetCaptionRect(RECT& rcCaption)
  429. {
  430. m_rcCaption = rcCaption;
  431. }
  432. SIZE CPaintManagerUI::GetRoundCorner() const
  433. {
  434. return m_szRoundCorner;
  435. }
  436. void CPaintManagerUI::SetRoundCorner(int cx, int cy)
  437. {
  438. m_szRoundCorner.cx = cx;
  439. m_szRoundCorner.cy = cy;
  440. }
  441. SIZE CPaintManagerUI::GetMinInfo() const
  442. {
  443. return m_szMinWindow;
  444. }
  445. void CPaintManagerUI::SetMinInfo(int cx, int cy)
  446. {
  447. ASSERT(cx>=0 && cy>=0);
  448. m_szMinWindow.cx = cx;
  449. m_szMinWindow.cy = cy;
  450. }
  451. SIZE CPaintManagerUI::GetMaxInfo() const
  452. {
  453. return m_szMaxWindow;
  454. }
  455. void CPaintManagerUI::SetMaxInfo(int cx, int cy)
  456. {
  457. ASSERT(cx>=0 && cy>=0);
  458. m_szMaxWindow.cx = cx;
  459. m_szMaxWindow.cy = cy;
  460. }
  461. bool CPaintManagerUI::IsShowUpdateRect() const
  462. {
  463. return m_bShowUpdateRect;
  464. }
  465. void CPaintManagerUI::SetShowUpdateRect(bool show)
  466. {
  467. m_bShowUpdateRect = show;
  468. }
  469. bool CPaintManagerUI::IsNoActivate()
  470. {
  471. return m_bNoActivate;
  472. }
  473. void CPaintManagerUI::SetNoActivate(bool bNoActivate)
  474. {
  475. m_bNoActivate = bNoActivate;
  476. }
  477. BYTE CPaintManagerUI::GetOpacity() const
  478. {
  479. return m_nOpacity;
  480. }
  481. void CPaintManagerUI::SetOpacity(BYTE nOpacity)
  482. {
  483. m_nOpacity = nOpacity;
  484. if( m_hWndPaint != NULL ) {
  485. typedef BOOL (__stdcall *PFUNCSETLAYEREDWINDOWATTR)(HWND, COLORREF, BYTE, DWORD);
  486. PFUNCSETLAYEREDWINDOWATTR fSetLayeredWindowAttributes = NULL;
  487. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  488. if (hUser32)
  489. {
  490. fSetLayeredWindowAttributes =
  491. (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
  492. if( fSetLayeredWindowAttributes == NULL ) return;
  493. }
  494. DWORD dwStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  495. DWORD dwNewStyle = dwStyle;
  496. if( nOpacity >= 0 && nOpacity < 256 ) dwNewStyle |= WS_EX_LAYERED;
  497. else dwNewStyle &= ~WS_EX_LAYERED;
  498. if(dwStyle != dwNewStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewStyle);
  499. fSetLayeredWindowAttributes(m_hWndPaint, 0, nOpacity, LWA_ALPHA);
  500. m_bLayered = false;
  501. Invalidate();
  502. }
  503. }
  504. bool CPaintManagerUI::IsLayered()
  505. {
  506. return m_bLayered;
  507. }
  508. void CPaintManagerUI::SetLayered(bool bLayered)
  509. {
  510. if( m_hWndPaint != NULL && bLayered != m_bLayered ) {
  511. UINT uStyle = GetWindowStyle(m_hWndPaint);
  512. if( (uStyle & WS_CHILD) != 0 ) return;
  513. if( g_fUpdateLayeredWindow == NULL ) {
  514. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  515. if (hUser32) {
  516. g_fUpdateLayeredWindow =
  517. (PFUNCUPDATELAYEREDWINDOW)::GetProcAddress(hUser32, "UpdateLayeredWindow");
  518. if( g_fUpdateLayeredWindow == NULL ) return;
  519. }
  520. }
  521. DWORD dwExStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  522. DWORD dwNewExStyle = dwExStyle;
  523. if( bLayered ) {
  524. dwNewExStyle |= WS_EX_LAYERED;
  525. ::SetTimer(m_hWndPaint, LAYEREDUPDATE_TIMERID, 10L, NULL);
  526. }
  527. else {
  528. dwNewExStyle &= ~WS_EX_LAYERED;
  529. ::KillTimer(m_hWndPaint, LAYEREDUPDATE_TIMERID);
  530. }
  531. if(dwExStyle != dwNewExStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewExStyle);
  532. m_bLayered = bLayered;
  533. if( m_pRoot != NULL ) m_pRoot->NeedUpdate();
  534. Invalidate();
  535. }
  536. }
  537. RECT& CPaintManagerUI::GetLayeredInset()
  538. {
  539. return m_rcLayeredInset;
  540. }
  541. void CPaintManagerUI::SetLayeredInset(RECT& rcLayeredInset)
  542. {
  543. m_rcLayeredInset = rcLayeredInset;
  544. m_bLayeredChanged = true;
  545. Invalidate();
  546. }
  547. BYTE CPaintManagerUI::GetLayeredOpacity()
  548. {
  549. return m_nOpacity;
  550. }
  551. void CPaintManagerUI::SetLayeredOpacity(BYTE nOpacity)
  552. {
  553. m_nOpacity = nOpacity;
  554. m_bLayeredChanged = true;
  555. Invalidate();
  556. }
  557. LPCTSTR CPaintManagerUI::GetLayeredImage()
  558. {
  559. return m_diLayered.sDrawString;
  560. }
  561. void CPaintManagerUI::SetLayeredImage(LPCTSTR pstrImage)
  562. {
  563. m_diLayered.sDrawString = pstrImage;
  564. RECT rcNull = {0};
  565. CRenderEngine::DrawImage(NULL, this, rcNull, rcNull, m_diLayered);
  566. }
  567. bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& /*lRes*/)
  568. {
  569. for( int i = 0; i < m_aPreMessageFilters.GetSize(); i++ )
  570. {
  571. bool bHandled = false;
  572. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  573. if( bHandled ) {
  574. return true;
  575. }
  576. }
  577. switch( uMsg ) {
  578. case WM_KEYDOWN:
  579. {
  580. // Tabbing between controls
  581. if( wParam == VK_TAB ) {
  582. if( m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), DUI_CTR_RICHEDIT) != NULL ) {
  583. if( static_cast<CRichEditUI*>(m_pFocus)->IsWantTab() ) return false;
  584. }
  585. SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
  586. return true;
  587. }
  588. }
  589. break;
  590. case WM_SYSCHAR:
  591. {
  592. if( m_pRoot == NULL ) return false;
  593. // Handle ALT-shortcut key-combinations
  594. FINDSHORTCUT fs = { 0 };
  595. fs.ch = toupper((int)wParam);
  596. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST);
  597. if( pControl != NULL ) {
  598. pControl->SetFocus();
  599. pControl->Activate();
  600. return true;
  601. }
  602. }
  603. break;
  604. case WM_SYSKEYDOWN:
  605. {
  606. if( m_pFocus != NULL ) {
  607. TEventUI event = { 0 };
  608. event.Type = UIEVENT_SYSKEY;
  609. event.pSender = m_pFocus;
  610. event.chKey = (TCHAR)wParam;
  611. event.ptMouse = m_ptLastMousePos;
  612. event.wKeyState = MapKeyState();
  613. event.dwTimestamp = ::GetTickCount();
  614. m_pFocus->Event(event);
  615. }
  616. }
  617. break;
  618. }
  619. return false;
  620. }
  621. bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  622. {
  623. //#ifdef _DEBUG
  624. // switch( uMsg ) {
  625. // case WM_NCPAINT:
  626. // case WM_NCHITTEST:
  627. // case WM_SETCURSOR:
  628. // break;
  629. // default:
  630. // DUITRACE(_T("MSG: %-20s (%08ld)"), DUITRACEMSG(uMsg), ::GetTickCount());
  631. // }
  632. //#endif
  633. // Not ready yet?
  634. if( m_hWndPaint == NULL ) return false;
  635. // Cycle through listeners
  636. for( int i = 0; i < m_aMessageFilters.GetSize(); i++ )
  637. {
  638. bool bHandled = false;
  639. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  640. if( bHandled ) {
  641. lRes = lResult;
  642. switch( uMsg ) {
  643. case WM_MOUSEMOVE:
  644. case WM_LBUTTONDOWN:
  645. case WM_LBUTTONDBLCLK:
  646. case WM_LBUTTONUP:
  647. {
  648. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  649. m_ptLastMousePos = pt;
  650. }
  651. break;
  652. case WM_CONTEXTMENU:
  653. case WM_MOUSEWHEEL:
  654. {
  655. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  656. ::ScreenToClient(m_hWndPaint, &pt);
  657. m_ptLastMousePos = pt;
  658. }
  659. break;
  660. }
  661. return true;
  662. }
  663. }
  664. if( m_bLayered ) {
  665. switch( uMsg ) {
  666. case WM_NCACTIVATE:
  667. if( !::IsIconic(m_hWndPaint) ) {
  668. lRes = (wParam == 0) ? TRUE : FALSE;
  669. return true;
  670. }
  671. break;
  672. case WM_NCCALCSIZE:
  673. case WM_NCPAINT:
  674. lRes = 0;
  675. return true;
  676. }
  677. }
  678. // Custom handling of events
  679. switch( uMsg ) {
  680. case WM_APP + 1:
  681. {
  682. m_bAsyncNotifyPosted = false;
  683. TNotifyUI* pMsg = NULL;
  684. while( pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify.GetAt(0)) ) {
  685. m_aAsyncNotify.Remove(0);
  686. if( pMsg->pSender != NULL ) {
  687. if( pMsg->pSender->OnNotify ) pMsg->pSender->OnNotify(pMsg);
  688. }
  689. for( int j = 0; j < m_aNotifiers.GetSize(); j++ ) {
  690. static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);
  691. }
  692. delete pMsg;
  693. }
  694. for( int i = 0; i < m_aDelayedCleanup.GetSize(); i++ )
  695. static_cast<CControlUI*>(m_aDelayedCleanup[i])->Delete();
  696. m_aDelayedCleanup.Empty();
  697. }
  698. break;
  699. case WM_CLOSE:
  700. {
  701. // Make sure all matching "closing" events are sent
  702. TEventUI event = { 0 };
  703. event.ptMouse = m_ptLastMousePos;
  704. event.wKeyState = MapKeyState();
  705. event.dwTimestamp = ::GetTickCount();
  706. if( m_pEventHover != NULL ) {
  707. event.Type = UIEVENT_MOUSELEAVE;
  708. event.pSender = m_pEventHover;
  709. m_pEventHover->Event(event);
  710. }
  711. if( m_pEventClick != NULL ) {
  712. event.Type = UIEVENT_BUTTONUP;
  713. event.pSender = m_pEventClick;
  714. m_pEventClick->Event(event);
  715. }
  716. SetFocus(NULL);
  717. if( ::GetActiveWindow() == m_hWndPaint ) {
  718. HWND hwndParent = GetWindowOwner(m_hWndPaint);
  719. if ((GetWindowStyle(m_hWndPaint) & WS_CHILD) !=0 ) hwndParent = GetParent(m_hWndPaint);
  720. if( hwndParent != NULL ) ::SetFocus(hwndParent);
  721. }
  722. if (m_hwndTooltip != NULL) {
  723. ::DestroyWindow(m_hwndTooltip);
  724. m_hwndTooltip = NULL;
  725. }
  726. }
  727. break;
  728. case WM_ERASEBKGND:
  729. {
  730. // We'll do the painting here...
  731. lRes = 1;
  732. }
  733. return true;
  734. case WM_PAINT:
  735. {
  736. if( m_pRoot == NULL ) {
  737. PAINTSTRUCT ps = { 0 };
  738. ::BeginPaint(m_hWndPaint, &ps);
  739. CRenderEngine::DrawColor(m_hDcPaint, ps.rcPaint, 0xFF000000);
  740. ::EndPaint(m_hWndPaint, &ps);
  741. return true;
  742. }
  743. RECT rcClient = { 0 };
  744. ::GetClientRect(m_hWndPaint, &rcClient);
  745. RECT rcPaint = { 0 };
  746. if( m_bLayered ) {
  747. m_bOffscreenPaint = true;
  748. rcPaint = m_rcLayeredUpdate;
  749. if( ::IsRectEmpty(&m_rcLayeredUpdate) ) {
  750. PAINTSTRUCT ps = { 0 };
  751. ::BeginPaint(m_hWndPaint, &ps);
  752. ::EndPaint(m_hWndPaint, &ps);
  753. return true;
  754. }
  755. if( rcPaint.right > rcClient.right ) rcPaint.right = rcClient.right;
  756. if( rcPaint.bottom > rcClient.bottom ) rcPaint.bottom = rcClient.bottom;
  757. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  758. }
  759. else {
  760. if( !::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE) ) return true;
  761. }
  762. // Set focus to first control?
  763. if( m_bFocusNeeded ) {
  764. SetNextTabControl();
  765. }
  766. SetPainting(true);
  767. if( m_bUpdateNeeded ) {
  768. m_bUpdateNeeded = false;
  769. if( !::IsRectEmpty(&rcClient) ) {
  770. if( m_pRoot->IsUpdateNeeded() ) {
  771. RECT rcRoot = rcClient;
  772. if( m_hDcOffscreen != NULL ) ::DeleteDC(m_hDcOffscreen);
  773. if( m_hDcBackground != NULL ) ::DeleteDC(m_hDcBackground);
  774. if( m_hbmpOffscreen != NULL ) ::DeleteObject(m_hbmpOffscreen);
  775. if( m_hbmpBackground != NULL ) ::DeleteObject(m_hbmpBackground);
  776. m_hDcOffscreen = NULL;
  777. m_hDcBackground = NULL;
  778. m_hbmpOffscreen = NULL;
  779. m_hbmpBackground = NULL;
  780. if( m_bLayered ) {
  781. rcRoot.left += m_rcLayeredInset.left;
  782. rcRoot.top += m_rcLayeredInset.top;
  783. rcRoot.right -= m_rcLayeredInset.right;
  784. rcRoot.bottom -= m_rcLayeredInset.bottom;
  785. }
  786. m_pRoot->SetPos(rcRoot, true);
  787. }
  788. else {
  789. CControlUI* pControl = NULL;
  790. m_aFoundControls.Empty();
  791. m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST);
  792. for( int it = 0; it < m_aFoundControls.GetSize(); it++ ) {
  793. pControl = static_cast<CControlUI*>(m_aFoundControls[it]);
  794. if( !pControl->IsFloat() ) pControl->SetPos(pControl->GetPos(), true);
  795. else pControl->SetPos(pControl->GetRelativePos(), true);
  796. }
  797. }
  798. // We'll want to notify the window when it is first initialized
  799. // with the correct layout. The window form would take the time
  800. // to submit swipes/animations.
  801. if( m_bFirstLayout ) {
  802. m_bFirstLayout = false;
  803. SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWINIT, 0, 0, false);
  804. if( m_bLayered && m_bLayeredChanged ) {
  805. Invalidate();
  806. SetPainting(false);
  807. return true;
  808. }
  809. }
  810. }
  811. }
  812. else if( m_bLayered && m_bLayeredChanged ) {
  813. RECT rcRoot = rcClient;
  814. if( m_pOffscreenBits ) ::ZeroMemory(m_pOffscreenBits, (rcRoot.right - rcRoot.left)
  815. * (rcRoot.bottom - rcRoot.top) * 4);
  816. rcRoot.left += m_rcLayeredInset.left;
  817. rcRoot.top += m_rcLayeredInset.top;
  818. rcRoot.right -= m_rcLayeredInset.right;
  819. rcRoot.bottom -= m_rcLayeredInset.bottom;
  820. m_pRoot->SetPos(rcRoot, true);
  821. }
  822. //
  823. // Render screen
  824. //
  825. // Prepare offscreen bitmap?
  826. if( m_bOffscreenPaint && m_hbmpOffscreen == NULL )
  827. {
  828. m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
  829. if( m_bLayered ) m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, &m_pOffscreenBits);
  830. else m_hbmpOffscreen = ::CreateCompatibleBitmap(m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  831. ASSERT(m_hDcOffscreen);
  832. ASSERT(m_hbmpOffscreen);
  833. }
  834. // Begin Windows paint
  835. PAINTSTRUCT ps = { 0 };
  836. ::BeginPaint(m_hWndPaint, &ps);
  837. if( m_bOffscreenPaint )
  838. {
  839. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(m_hDcOffscreen, m_hbmpOffscreen);
  840. int iSaveDC = ::SaveDC(m_hDcOffscreen);
  841. if (m_bLayered && m_diLayered.pImageInfo == NULL) {
  842. COLORREF* pOffscreenBits = NULL;
  843. for( LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y ) {
  844. for( LONG x = rcPaint.left; x < rcPaint.right; ++x ) {
  845. pOffscreenBits = m_pOffscreenBits + y*(rcClient.right - rcClient.left) + x;
  846. *pOffscreenBits = 0;
  847. }
  848. }
  849. }
  850. m_pRoot->Paint(m_hDcOffscreen, rcPaint, NULL);
  851. if( m_bLayered ) {
  852. for( int i = 0; i < m_aNativeWindow.GetSize(); ) {
  853. HWND hChildWnd = static_cast<HWND>(m_aNativeWindow[i]);
  854. if (!::IsWindow(hChildWnd)) {
  855. m_aNativeWindow.Remove(i);
  856. m_aNativeWindowControl.Remove(i);
  857. continue;
  858. }
  859. ++i;
  860. if (!::IsWindowVisible(hChildWnd)) continue;
  861. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  862. RECT rcTemp = { 0 };
  863. if( !::IntersectRect(&rcTemp, &rcPaint, &rcChildWnd) ) continue;
  864. COLORREF* pChildBitmapBits = NULL;
  865. HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen);
  866. HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap(hChildMemDC, rcChildWnd.right-rcChildWnd.left, rcChildWnd.bottom-rcChildWnd.top, &pChildBitmapBits);
  867. ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left)*(rcChildWnd.bottom - rcChildWnd.top)*4);
  868. HBITMAP hOldChildBitmap = (HBITMAP) ::SelectObject(hChildMemDC, hChildBitmap);
  869. ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC,(LPARAM)(PRF_CHECKVISIBLE|PRF_CHILDREN|PRF_CLIENT|PRF_OWNED));
  870. COLORREF* pChildBitmapBit;
  871. for( LONG y = 0; y < rcChildWnd.bottom-rcChildWnd.top; y++ ) {
  872. for( LONG x = 0; x < rcChildWnd.right-rcChildWnd.left; x++ ) {
  873. pChildBitmapBit = pChildBitmapBits+y*(rcChildWnd.right-rcChildWnd.left) + x;
  874. if (*pChildBitmapBit != 0x00000000) *pChildBitmapBit |= 0xff000000;
  875. }
  876. }
  877. ::BitBlt(m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left,
  878. rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY);
  879. ::SelectObject(hChildMemDC, hOldChildBitmap);
  880. ::DeleteObject(hChildBitmap);
  881. ::DeleteDC(hChildMemDC);
  882. }
  883. }
  884. for( int i = 0; i < m_aPostPaintControls.GetSize(); i++ ) {
  885. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  886. pPostPaintControl->DoPostPaint(m_hDcOffscreen, rcPaint);
  887. }
  888. ::RestoreDC(m_hDcOffscreen, iSaveDC);
  889. if( m_bLayered ) {
  890. RECT rcWnd = { 0 };
  891. ::GetWindowRect(m_hWndPaint, &rcWnd);
  892. DWORD dwWidth = rcClient.right - rcClient.left;
  893. DWORD dwHeight = rcClient.bottom - rcClient.top;
  894. RECT rcLayeredClient = rcClient;
  895. rcLayeredClient.left += m_rcLayeredInset.left;
  896. rcLayeredClient.top += m_rcLayeredInset.top;
  897. rcLayeredClient.right -= m_rcLayeredInset.right;
  898. rcLayeredClient.bottom -= m_rcLayeredInset.bottom;
  899. COLORREF* pOffscreenBits = m_pOffscreenBits;
  900. COLORREF* pBackgroundBits = m_pBackgroundBits;
  901. BYTE A = 0;
  902. BYTE R = 0;
  903. BYTE G = 0;
  904. BYTE B = 0;
  905. if (m_diLayered.pImageInfo != NULL) {
  906. if( m_hbmpBackground == NULL) {
  907. m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint);
  908. m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, &m_pBackgroundBits);
  909. ASSERT(m_hDcBackground);
  910. ASSERT(m_hbmpBackground);
  911. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  912. ::SelectObject(m_hDcBackground, m_hbmpBackground);
  913. CRenderClip clip;
  914. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  915. CRenderEngine::DrawImage(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, m_diLayered);
  916. }
  917. else if( m_bLayeredChanged ) {
  918. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  919. CRenderClip clip;
  920. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  921. CRenderEngine::DrawImage(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, m_diLayered);
  922. }
  923. if( m_diLayered.pImageInfo->bAlpha ) {
  924. for( LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y ) {
  925. for( LONG x = rcPaint.left; x < rcPaint.right; ++x ) {
  926. pOffscreenBits = m_pOffscreenBits + y * dwWidth + x;
  927. pBackgroundBits = m_pBackgroundBits + y * dwWidth + x;
  928. A = (BYTE)((*pBackgroundBits) >> 24);
  929. R = (BYTE)((*pOffscreenBits) >> 16) * A / 255;
  930. G = (BYTE)((*pOffscreenBits) >> 8) * A / 255;
  931. B = (BYTE)(*pOffscreenBits) * A / 255;
  932. *pOffscreenBits = RGB(B, G, R) + ((DWORD)A << 24);
  933. }
  934. }
  935. }
  936. }
  937. BLENDFUNCTION bf = { AC_SRC_OVER, 0, m_nOpacity, AC_SRC_ALPHA };
  938. POINT ptPos = { rcWnd.left, rcWnd.top };
  939. SIZE sizeWnd = { dwWidth, dwHeight };
  940. POINT ptSrc = { 0, 0 };
  941. g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
  942. }
  943. else
  944. ::BitBlt(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left,
  945. rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY);
  946. ::SelectObject(m_hDcOffscreen, hOldBitmap);
  947. if( m_bShowUpdateRect && !m_bLayered ) {
  948. HPEN hOldPen = (HPEN)::SelectObject(m_hDcPaint, m_hUpdateRectPen);
  949. ::SelectObject(m_hDcPaint, ::GetStockObject(HOLLOW_BRUSH));
  950. ::Rectangle(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
  951. ::SelectObject(m_hDcPaint, hOldPen);
  952. }
  953. }
  954. else
  955. {
  956. // A standard paint job
  957. int iSaveDC = ::SaveDC(m_hDcPaint);
  958. m_pRoot->Paint(m_hDcPaint, rcPaint, NULL);
  959. ::RestoreDC(m_hDcPaint, iSaveDC);
  960. }
  961. // All Done!
  962. ::EndPaint(m_hWndPaint, &ps);
  963. SetPainting(false);
  964. m_bLayeredChanged = false;
  965. if( m_bUpdateNeeded ) Invalidate();
  966. }
  967. return true;
  968. case WM_PRINTCLIENT:
  969. {
  970. if( m_pRoot == NULL ) break;
  971. RECT rcClient;
  972. ::GetClientRect(m_hWndPaint, &rcClient);
  973. HDC hDC = (HDC) wParam;
  974. int save = ::SaveDC(hDC);
  975. m_pRoot->Paint(hDC, rcClient, NULL);
  976. // Check for traversing children. The crux is that WM_PRINT will assume
  977. // that the DC is positioned at frame coordinates and will paint the child
  978. // control at the wrong position. We'll simulate the entire thing instead.
  979. if( (lParam & PRF_CHILDREN) != 0 ) {
  980. HWND hWndChild = ::GetWindow(m_hWndPaint, GW_CHILD);
  981. while( hWndChild != NULL ) {
  982. RECT rcPos = { 0 };
  983. ::GetWindowRect(hWndChild, &rcPos);
  984. ::MapWindowPoints(HWND_DESKTOP, m_hWndPaint, reinterpret_cast<LPPOINT>(&rcPos), 2);
  985. ::SetWindowOrgEx(hDC, -rcPos.left, -rcPos.top, NULL);
  986. // NOTE: We use WM_PRINT here rather than the expected WM_PRINTCLIENT
  987. // since the latter will not print the nonclient correctly for
  988. // EDIT controls.
  989. ::SendMessage(hWndChild, WM_PRINT, wParam, lParam | PRF_NONCLIENT);
  990. hWndChild = ::GetWindow(hWndChild, GW_HWNDNEXT);
  991. }
  992. }
  993. ::RestoreDC(hDC, save);
  994. }
  995. break;
  996. case WM_GETMINMAXINFO:
  997. {
  998. LPMINMAXINFO lpMMI = (LPMINMAXINFO) lParam;
  999. if( m_szMinWindow.cx > 0 ) lpMMI->ptMinTrackSize.x = m_szMinWindow.cx;
  1000. if( m_szMinWindow.cy > 0 ) lpMMI->ptMinTrackSize.y = m_szMinWindow.cy;
  1001. if( m_szMaxWindow.cx > 0 ) lpMMI->ptMaxTrackSize.x = m_szMaxWindow.cx;
  1002. if( m_szMaxWindow.cy > 0 ) lpMMI->ptMaxTrackSize.y = m_szMaxWindow.cy;
  1003. }
  1004. break;
  1005. case WM_SIZE:
  1006. {
  1007. if( m_pFocus != NULL ) {
  1008. TEventUI event = { 0 };
  1009. event.Type = UIEVENT_WINDOWSIZE;
  1010. event.pSender = m_pFocus;
  1011. event.wParam = wParam;
  1012. event.lParam = lParam;
  1013. event.dwTimestamp = ::GetTickCount();
  1014. event.ptMouse = m_ptLastMousePos;
  1015. event.wKeyState = MapKeyState();
  1016. m_pFocus->Event(event);
  1017. }
  1018. if( m_pRoot != NULL ) m_pRoot->NeedUpdate();
  1019. if( m_bLayered ) Invalidate();
  1020. }
  1021. return true;
  1022. case WM_TIMER:
  1023. {
  1024. if( LOWORD(wParam) == LAYEREDUPDATE_TIMERID ) {
  1025. if( m_bLayered && !::IsRectEmpty(&m_rcLayeredUpdate) ) {
  1026. LRESULT lRes = 0;
  1027. if( !::IsIconic(m_hWndPaint) ) MessageHandler(WM_PAINT, 0, 0L, lRes);
  1028. break;
  1029. }
  1030. }
  1031. for( int i = 0; i < m_aTimers.GetSize(); i++ ) {
  1032. const TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1033. if( pTimer->hWnd == m_hWndPaint && pTimer->uWinTimer == LOWORD(wParam) && pTimer->bKilled == false) {
  1034. TEventUI event = { 0 };
  1035. event.Type = UIEVENT_TIMER;
  1036. event.pSender = pTimer->pSender;
  1037. event.dwTimestamp = ::GetTickCount();
  1038. event.ptMouse = m_ptLastMousePos;
  1039. event.wKeyState = MapKeyState();
  1040. event.wParam = pTimer->nLocalID;
  1041. event.lParam = lParam;
  1042. pTimer->pSender->Event(event);
  1043. break;
  1044. }
  1045. }
  1046. }
  1047. break;
  1048. case WM_MOUSEACTIVATE:
  1049. {
  1050. if (m_bNoActivate) {
  1051. lRes = MA_NOACTIVATE;
  1052. return true;
  1053. }
  1054. }
  1055. break;
  1056. case WM_MOUSEHOVER:
  1057. {
  1058. if (m_pRoot == NULL) break;
  1059. m_bMouseTracking = false;
  1060. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1061. CControlUI* pHover = FindControl(pt);
  1062. if (pHover == NULL) break;
  1063. // Generate mouse hover event
  1064. if (m_pEventHover != NULL) {
  1065. TEventUI event = { 0 };
  1066. event.Type = UIEVENT_MOUSEHOVER;
  1067. event.pSender = m_pEventHover;
  1068. event.wParam = wParam;
  1069. event.lParam = lParam;
  1070. event.dwTimestamp = ::GetTickCount();
  1071. event.ptMouse = pt;
  1072. event.wKeyState = MapKeyState();
  1073. m_pEventHover->Event(event);
  1074. }
  1075. // Create tooltip information
  1076. CDuiString sToolTip = pHover->GetToolTip();
  1077. if (sToolTip.IsEmpty()) return true;
  1078. ProcessMultiLanguageTokens(sToolTip);
  1079. ::ZeroMemory(&m_ToolTip, sizeof(TOOLINFO));
  1080. m_ToolTip.cbSize = sizeof(TOOLINFO);
  1081. m_ToolTip.uFlags = TTF_IDISHWND;
  1082. m_ToolTip.hwnd = m_hWndPaint;
  1083. m_ToolTip.uId = (UINT_PTR)m_hWndPaint;
  1084. m_ToolTip.hinst = m_hInstance;
  1085. m_ToolTip.lpszText = const_cast<LPTSTR>((LPCTSTR)sToolTip);
  1086. m_ToolTip.rect = pHover->GetPos();
  1087. if (m_hwndTooltip == NULL) {
  1088. 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);
  1089. ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip);
  1090. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1091. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1092. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1093. }
  1094. // by jiangdong 2016-8-6 修改tooltip 悬停时候 闪烁bug
  1095. if (m_pLastToolTip == NULL) {
  1096. m_pLastToolTip = pHover;
  1097. }
  1098. else{
  1099. if (m_pLastToolTip == pHover){
  1100. if (m_iLastTooltipWidth != pHover->GetToolTipWidth()){
  1101. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1102. m_iLastTooltipWidth = pHover->GetToolTipWidth();
  1103. }
  1104. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1105. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1106. }
  1107. else{
  1108. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1109. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1110. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1111. }
  1112. }
  1113. //修改在CListElementUI 有提示 子项无提示下无法跟随移动!(按理说不应该移动的)
  1114. ::SendMessage(m_hwndTooltip, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(pt.x, pt.y));
  1115. }
  1116. return true;
  1117. case WM_MOUSELEAVE:
  1118. {
  1119. if( m_pRoot == NULL ) break;
  1120. if( m_hwndTooltip != NULL ) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM) &m_ToolTip);
  1121. if( m_bMouseTracking ) {
  1122. POINT pt = { 0 };
  1123. RECT rcWnd = { 0 };
  1124. ::GetCursorPos(&pt);
  1125. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1126. if( !::IsIconic(m_hWndPaint) && ::GetActiveWindow() == m_hWndPaint && ::PtInRect(&rcWnd, pt) ) {
  1127. if( ::SendMessage(m_hWndPaint, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)) == HTCLIENT ) {
  1128. ::ScreenToClient(m_hWndPaint, &pt);
  1129. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
  1130. }
  1131. else
  1132. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1133. }
  1134. else
  1135. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1136. }
  1137. m_bMouseTracking = false;
  1138. }
  1139. break;
  1140. case WM_MOUSEMOVE:
  1141. {
  1142. if( m_pRoot == NULL ) break;
  1143. // Start tracking this entire window again...
  1144. if( !m_bMouseTracking ) {
  1145. TRACKMOUSEEVENT tme = { 0 };
  1146. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  1147. tme.dwFlags = TME_HOVER | TME_LEAVE;
  1148. tme.hwndTrack = m_hWndPaint;
  1149. tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
  1150. _TrackMouseEvent(&tme);
  1151. m_bMouseTracking = true;
  1152. }
  1153. // Generate the appropriate mouse messages
  1154. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1155. m_ptLastMousePos = pt;
  1156. CControlUI* pNewHover = FindControl(pt);
  1157. if( pNewHover != NULL && pNewHover->GetManager() != this ) break;
  1158. TEventUI event = { 0 };
  1159. event.ptMouse = pt;
  1160. event.wParam = wParam;
  1161. event.lParam = lParam;
  1162. event.dwTimestamp = ::GetTickCount();
  1163. event.wKeyState = MapKeyState();
  1164. if( !IsCaptured() ) {
  1165. pNewHover = FindControl(pt);
  1166. if( pNewHover != NULL && pNewHover->GetManager() != this ) break;
  1167. if( pNewHover != m_pEventHover && m_pEventHover != NULL ) {
  1168. event.Type = UIEVENT_MOUSELEAVE;
  1169. event.pSender = m_pEventHover;
  1170. CDuiPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  1171. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  1172. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  1173. for( int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++ ) {
  1174. static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i])->Event(event);
  1175. }
  1176. m_pEventHover->Event(event);
  1177. m_pEventHover = NULL;
  1178. if( m_hwndTooltip != NULL ) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM) &m_ToolTip);
  1179. }
  1180. if( pNewHover != m_pEventHover && pNewHover != NULL ) {
  1181. event.Type = UIEVENT_MOUSEENTER;
  1182. event.pSender = pNewHover;
  1183. pNewHover->Event(event);
  1184. m_pEventHover = pNewHover;
  1185. }
  1186. }
  1187. if( m_pEventClick != NULL ) {
  1188. event.Type = UIEVENT_MOUSEMOVE;
  1189. event.pSender = m_pEventClick;
  1190. m_pEventClick->Event(event);
  1191. }
  1192. else if( pNewHover != NULL ) {
  1193. event.Type = UIEVENT_MOUSEMOVE;
  1194. event.pSender = pNewHover;
  1195. pNewHover->Event(event);
  1196. }
  1197. }
  1198. break;
  1199. case WM_LBUTTONDOWN:
  1200. {
  1201. // We alway set focus back to our app (this helps
  1202. // when Win32 child windows are placed on the dialog
  1203. // and we need to remove them on focus change).
  1204. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1205. if( m_pRoot == NULL ) break;
  1206. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1207. m_ptLastMousePos = pt;
  1208. CControlUI* pControl = FindControl(pt);
  1209. if( pControl == NULL ) break;
  1210. if( pControl->GetManager() != this ) break;
  1211. m_pEventClick = pControl;
  1212. pControl->SetFocus();
  1213. SetCapture();
  1214. TEventUI event = { 0 };
  1215. event.Type = UIEVENT_BUTTONDOWN;
  1216. event.pSender = pControl;
  1217. event.wParam = wParam;
  1218. event.lParam = lParam;
  1219. event.ptMouse = pt;
  1220. event.wKeyState = (WORD)wParam;
  1221. event.dwTimestamp = ::GetTickCount();
  1222. pControl->Event(event);
  1223. }
  1224. break;
  1225. case WM_LBUTTONDBLCLK:
  1226. {
  1227. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1228. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1229. m_ptLastMousePos = pt;
  1230. CControlUI* pControl = FindControl(pt);
  1231. if( pControl == NULL ) break;
  1232. if( pControl->GetManager() != this ) break;
  1233. SetCapture();
  1234. TEventUI event = { 0 };
  1235. event.Type = UIEVENT_DBLCLICK;
  1236. event.pSender = pControl;
  1237. event.ptMouse = pt;
  1238. event.wKeyState = (WORD)wParam;
  1239. event.dwTimestamp = ::GetTickCount();
  1240. pControl->Event(event);
  1241. m_pEventClick = pControl;
  1242. }
  1243. break;
  1244. case WM_LBUTTONUP:
  1245. {
  1246. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1247. m_ptLastMousePos = pt;
  1248. if( m_pEventClick == NULL ) break;
  1249. ReleaseCapture();
  1250. TEventUI event = { 0 };
  1251. event.Type = UIEVENT_BUTTONUP;
  1252. event.pSender = m_pEventClick;
  1253. event.wParam = wParam;
  1254. event.lParam = lParam;
  1255. event.ptMouse = pt;
  1256. event.wKeyState = (WORD)wParam;
  1257. event.dwTimestamp = ::GetTickCount();
  1258. // By daviyang35 at 2015-6-5 16:10:13
  1259. // 在Click事件中弹出了模态对话框,退出阶段窗口实例可能已经删除
  1260. // this成员属性赋值将会导致heap错误
  1261. // this成员函数调用将会导致野指针异常
  1262. // 使用栈上的成员来调用响应,提前清空成员
  1263. // 当阻塞的模态窗口返回时,回栈阶段不访问任何类实例方法或属性
  1264. // 将不会触发异常
  1265. CControlUI* pClick = m_pEventClick;
  1266. m_pEventClick = NULL;
  1267. pClick->Event(event);
  1268. }
  1269. break;
  1270. case WM_RBUTTONDOWN:
  1271. {
  1272. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1273. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1274. m_ptLastMousePos = pt;
  1275. CControlUI* pControl = FindControl(pt);
  1276. if( pControl == NULL ) break;
  1277. if( pControl->GetManager() != this ) break;
  1278. pControl->SetFocus();
  1279. TEventUI event = { 0 };
  1280. event.Type = UIEVENT_RBUTTONDOWN;
  1281. event.pSender = pControl;
  1282. event.wParam = wParam;
  1283. event.lParam = lParam;
  1284. event.ptMouse = pt;
  1285. event.wKeyState = (WORD)wParam;
  1286. event.dwTimestamp = ::GetTickCount();
  1287. pControl->Event(event);
  1288. m_pEventClick = pControl;
  1289. }
  1290. break;
  1291. case WM_CONTEXTMENU:
  1292. {
  1293. if( m_pRoot == NULL ) break;
  1294. if( IsCaptured() ) break;
  1295. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1296. ::ScreenToClient(m_hWndPaint, &pt);
  1297. m_ptLastMousePos = pt;
  1298. if( m_pEventClick == NULL ) break;
  1299. TEventUI event = { 0 };
  1300. event.Type = UIEVENT_CONTEXTMENU;
  1301. event.pSender = m_pEventClick;
  1302. event.ptMouse = pt;
  1303. event.wKeyState = (WORD)wParam;
  1304. event.lParam = (LPARAM)m_pEventClick;
  1305. event.dwTimestamp = ::GetTickCount();
  1306. m_pEventClick->Event(event);
  1307. m_pEventClick = NULL;
  1308. }
  1309. break;
  1310. case WM_MOUSEWHEEL:
  1311. {
  1312. if( m_pRoot == NULL ) break;
  1313. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1314. ::ScreenToClient(m_hWndPaint, &pt);
  1315. m_ptLastMousePos = pt;
  1316. CControlUI* pControl = FindControl(pt);
  1317. if( pControl == NULL ) break;
  1318. if( pControl->GetManager() != this ) break;
  1319. int zDelta = (int) (short) HIWORD(wParam);
  1320. TEventUI event = { 0 };
  1321. event.Type = UIEVENT_SCROLLWHEEL;
  1322. event.pSender = pControl;
  1323. event.wParam = MAKELPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, 0);
  1324. event.lParam = lParam;
  1325. event.ptMouse = m_ptLastMousePos;
  1326. event.wKeyState = MapKeyState();
  1327. event.dwTimestamp = ::GetTickCount();
  1328. pControl->Event(event);
  1329. // Let's make sure that the scroll item below the cursor is the same as before...
  1330. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM) MAKELPARAM(m_ptLastMousePos.x, m_ptLastMousePos.y));
  1331. }
  1332. break;
  1333. case WM_CHAR:
  1334. {
  1335. if( m_pRoot == NULL ) break;
  1336. if( m_pFocus == NULL ) break;
  1337. TEventUI event = { 0 };
  1338. event.Type = UIEVENT_CHAR;
  1339. event.pSender = m_pFocus;
  1340. event.wParam = wParam;
  1341. event.lParam = lParam;
  1342. event.chKey = (TCHAR)wParam;
  1343. event.ptMouse = m_ptLastMousePos;
  1344. event.wKeyState = MapKeyState();
  1345. event.dwTimestamp = ::GetTickCount();
  1346. m_pFocus->Event(event);
  1347. }
  1348. break;
  1349. case WM_KEYDOWN:
  1350. {
  1351. if( m_pRoot == NULL ) break;
  1352. if( m_pFocus == NULL ) break;
  1353. TEventUI event = { 0 };
  1354. event.Type = UIEVENT_KEYDOWN;
  1355. event.pSender = m_pFocus;
  1356. event.wParam = wParam;
  1357. event.lParam = lParam;
  1358. event.chKey = (TCHAR)wParam;
  1359. event.ptMouse = m_ptLastMousePos;
  1360. event.wKeyState = MapKeyState();
  1361. event.dwTimestamp = ::GetTickCount();
  1362. m_pFocus->Event(event);
  1363. m_pEventKey = m_pFocus;
  1364. }
  1365. break;
  1366. case WM_KEYUP:
  1367. {
  1368. if( m_pRoot == NULL ) break;
  1369. if( m_pEventKey == NULL ) break;
  1370. TEventUI event = { 0 };
  1371. event.Type = UIEVENT_KEYUP;
  1372. event.pSender = m_pEventKey;
  1373. event.wParam = wParam;
  1374. event.lParam = lParam;
  1375. event.chKey = (TCHAR)wParam;
  1376. event.ptMouse = m_ptLastMousePos;
  1377. event.wKeyState = MapKeyState();
  1378. event.dwTimestamp = ::GetTickCount();
  1379. m_pEventKey->Event(event);
  1380. m_pEventKey = NULL;
  1381. }
  1382. break;
  1383. case WM_SETCURSOR:
  1384. {
  1385. if( m_pRoot == NULL ) break;
  1386. if( LOWORD(lParam) != HTCLIENT ) break;
  1387. if( m_bMouseCapture ) return true;
  1388. POINT pt = { 0 };
  1389. ::GetCursorPos(&pt);
  1390. ::ScreenToClient(m_hWndPaint, &pt);
  1391. CControlUI* pControl = FindControl(pt);
  1392. if( pControl == NULL ) break;
  1393. if( (pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0 ) break;
  1394. TEventUI event = { 0 };
  1395. event.Type = UIEVENT_SETCURSOR;
  1396. event.pSender = pControl;
  1397. event.wParam = wParam;
  1398. event.lParam = lParam;
  1399. event.ptMouse = pt;
  1400. event.wKeyState = MapKeyState();
  1401. event.dwTimestamp = ::GetTickCount();
  1402. pControl->Event(event);
  1403. }
  1404. return true;
  1405. case WM_KILLFOCUS:
  1406. {
  1407. if( wParam != NULL ) {
  1408. HWND hWnd = ::GetFocus();
  1409. HWND hParentWnd = NULL;
  1410. while( hParentWnd = ::GetParent(hWnd) ) {
  1411. if( m_hWndPaint == hParentWnd ) {
  1412. for( int i = 0; i < m_aNativeWindow.GetSize(); i++ ) {
  1413. if( static_cast<HWND>(m_aNativeWindow[i]) == hWnd ) {
  1414. if( static_cast<CControlUI*>(m_aNativeWindowControl[i]) != m_pFocus ) {
  1415. SetFocus(static_cast<CControlUI*>(m_aNativeWindowControl[i]), false);
  1416. }
  1417. break;
  1418. }
  1419. }
  1420. break;
  1421. }
  1422. hWnd = hParentWnd;
  1423. }
  1424. }
  1425. }
  1426. break;
  1427. case WM_NOTIFY:
  1428. {
  1429. LPNMHDR lpNMHDR = (LPNMHDR) lParam;
  1430. if( lpNMHDR != NULL ) lRes = ::SendMessage(lpNMHDR->hwndFrom, OCM__BASE + uMsg, wParam, lParam);
  1431. return true;
  1432. }
  1433. break;
  1434. case WM_COMMAND:
  1435. {
  1436. if( lParam == 0 ) break;
  1437. HWND hWndChild = (HWND) lParam;
  1438. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  1439. return true;
  1440. }
  1441. break;
  1442. case WM_CTLCOLOREDIT:
  1443. case WM_CTLCOLORSTATIC:
  1444. {
  1445. // Refer To: http://msdn.microsoft.com/en-us/library/bb761691(v=vs.85).aspx
  1446. // Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message.
  1447. if( lParam == 0 ) break;
  1448. HWND hWndChild = (HWND) lParam;
  1449. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  1450. return true;
  1451. }
  1452. break;
  1453. default:
  1454. break;
  1455. }
  1456. return false;
  1457. }
  1458. bool CPaintManagerUI::IsUpdateNeeded() const
  1459. {
  1460. return m_bUpdateNeeded;
  1461. }
  1462. void CPaintManagerUI::NeedUpdate()
  1463. {
  1464. m_bUpdateNeeded = true;
  1465. }
  1466. void CPaintManagerUI::Invalidate()
  1467. {
  1468. if( !m_bLayered ) ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  1469. else {
  1470. RECT rcClient = { 0 };
  1471. ::GetClientRect(m_hWndPaint, &rcClient);
  1472. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcClient);
  1473. }
  1474. }
  1475. void CPaintManagerUI::Invalidate(RECT& rcItem)
  1476. {
  1477. if( rcItem.left < 0 ) rcItem.left = 0;
  1478. if( rcItem .top < 0 ) rcItem.top = 0;
  1479. if( rcItem.right < rcItem.left ) rcItem.right = rcItem.left;
  1480. if( rcItem.bottom < rcItem.top ) rcItem.bottom = rcItem.top;
  1481. if( !m_bLayered ) ::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
  1482. else ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcItem);
  1483. }
  1484. bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
  1485. {
  1486. ASSERT(::IsWindow(m_hWndPaint));
  1487. // Reset any previous attachment
  1488. SetFocus(NULL);
  1489. m_pEventKey = NULL;
  1490. m_pEventHover = NULL;
  1491. m_pEventClick = NULL;
  1492. m_pLastToolTip = NULL;
  1493. // Remove the existing control-tree. We might have gotten inside this function as
  1494. // a result of an event fired or similar, so we cannot just delete the objects and
  1495. // pull the internal memory of the calling code. We'll delay the cleanup.
  1496. if( m_pRoot != NULL ) {
  1497. for( int i = 0; i < m_aDelayedCleanup.GetSize(); i++ ) static_cast<CControlUI*>(m_aDelayedCleanup[i])->Delete();
  1498. m_aDelayedCleanup.Empty();
  1499. for( int i = 0; i < m_aAsyncNotify.GetSize(); i++ ) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  1500. m_aAsyncNotify.Empty();
  1501. m_mNameHash.Resize(0);
  1502. m_aPostPaintControls.Empty();
  1503. m_aNativeWindow.Empty();
  1504. AddDelayedCleanup(m_pRoot);
  1505. }
  1506. // Set the dialog root element
  1507. m_pRoot = pControl;
  1508. // Go ahead...
  1509. m_bUpdateNeeded = true;
  1510. m_bFirstLayout = true;
  1511. m_bFocusNeeded = true;
  1512. // Initiate all control
  1513. return InitControls(pControl);
  1514. }
  1515. bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
  1516. {
  1517. ASSERT(pControl);
  1518. if( pControl == NULL ) return false;
  1519. pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
  1520. pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);
  1521. return true;
  1522. }
  1523. bool CPaintManagerUI::RenameControl(CControlUI* pControl, LPCTSTR pstrName)
  1524. {
  1525. ASSERT(pControl);
  1526. if( pControl == NULL || pControl->GetManager() != this || pstrName == NULL || *pstrName == _T('\0')) return false;
  1527. if (pControl->GetName() == pstrName) return true;
  1528. if (NULL != FindControl(pstrName)) return false;
  1529. m_mNameHash.Remove(pControl->GetName());
  1530. bool bResult = m_mNameHash.Insert(pstrName, pControl);
  1531. if (bResult) pControl->SetName(pstrName);
  1532. return bResult;
  1533. }
  1534. void CPaintManagerUI::ReapObjects(CControlUI* pControl)
  1535. {
  1536. if( pControl == NULL ) return;
  1537. if( pControl == m_pEventKey ) m_pEventKey = NULL;
  1538. if( pControl == m_pEventHover ) m_pEventHover = NULL;
  1539. if( pControl == m_pEventClick ) m_pEventClick = NULL;
  1540. if( pControl == m_pFocus ) m_pFocus = NULL;
  1541. KillTimer(pControl);
  1542. const CDuiString& sName = pControl->GetName();
  1543. if( !sName.IsEmpty() ) {
  1544. if( pControl == FindControl(sName) ) m_mNameHash.Remove(sName);
  1545. }
  1546. for( int i = 0; i < m_aAsyncNotify.GetSize(); i++ ) {
  1547. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  1548. if( pMsg->pSender == pControl ) pMsg->pSender = NULL;
  1549. }
  1550. }
  1551. bool CPaintManagerUI::AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  1552. {
  1553. if (pControl == NULL || pStrGroupName == NULL) return false;
  1554. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  1555. if( lp ) {
  1556. CDuiPtrArray* aOptionGroup = static_cast<CDuiPtrArray*>(lp);
  1557. for( int i = 0; i < aOptionGroup->GetSize(); i++ ) {
  1558. if( static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl ) {
  1559. return false;
  1560. }
  1561. }
  1562. aOptionGroup->Add(pControl);
  1563. }
  1564. else {
  1565. CDuiPtrArray* aOptionGroup = new CDuiPtrArray(6);
  1566. aOptionGroup->Add(pControl);
  1567. m_mOptionGroup.Insert(pStrGroupName, aOptionGroup);
  1568. }
  1569. return true;
  1570. }
  1571. CDuiPtrArray* CPaintManagerUI::GetOptionGroup(LPCTSTR pStrGroupName)
  1572. {
  1573. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  1574. if( lp ) return static_cast<CDuiPtrArray*>(lp);
  1575. return NULL;
  1576. }
  1577. void CPaintManagerUI::RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  1578. {
  1579. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  1580. if( lp ) {
  1581. CDuiPtrArray* aOptionGroup = static_cast<CDuiPtrArray*>(lp);
  1582. if( aOptionGroup == NULL ) return;
  1583. for( int i = 0; i < aOptionGroup->GetSize(); i++ ) {
  1584. if( static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl ) {
  1585. aOptionGroup->Remove(i);
  1586. break;
  1587. }
  1588. }
  1589. if( aOptionGroup->IsEmpty() ) {
  1590. delete aOptionGroup;
  1591. m_mOptionGroup.Remove(pStrGroupName);
  1592. }
  1593. }
  1594. }
  1595. void CPaintManagerUI::RemoveAllOptionGroups()
  1596. {
  1597. CDuiPtrArray* aOptionGroup;
  1598. for( int i = 0; i< m_mOptionGroup.GetSize(); i++ ) {
  1599. if(LPCTSTR key = m_mOptionGroup.GetAt(i)) {
  1600. aOptionGroup = static_cast<CDuiPtrArray*>(m_mOptionGroup.Find(key));
  1601. delete aOptionGroup;
  1602. }
  1603. }
  1604. m_mOptionGroup.RemoveAll();
  1605. }
  1606. int CPaintManagerUI::MessageLoop()
  1607. {
  1608. MSG msg = { 0 };
  1609. while( ::GetMessage(&msg, NULL, 0, 0) ) {
  1610. if( !CPaintManagerUI::TranslateMessage(&msg) ) {
  1611. ::TranslateMessage(&msg);
  1612. ::DispatchMessage(&msg);
  1613. //try{
  1614. // ::DispatchMessage(&msg);
  1615. //} catch(...) {
  1616. // DUITRACE(_T("EXCEPTION: %s(%d)\n"), __FILET__, __LINE__);
  1617. // #ifdef _DEBUG
  1618. // throw "CPaintManagerUI::MessageLoop";
  1619. // #endif
  1620. //}
  1621. }
  1622. }
  1623. return msg.wParam;
  1624. }
  1625. void CPaintManagerUI::Term()
  1626. {
  1627. if( m_bCachedResourceZip && m_hResourceZip != NULL ) {
  1628. CloseZip((HZIP)m_hResourceZip);
  1629. m_hResourceZip = NULL;
  1630. }
  1631. }
  1632. CControlUI* CPaintManagerUI::GetFocus() const
  1633. {
  1634. return m_pFocus;
  1635. }
  1636. void CPaintManagerUI::SetFocus(CControlUI* pControl, bool bFocusWnd)
  1637. {
  1638. // Paint manager window has focus?
  1639. HWND hFocusWnd = ::GetFocus();
  1640. if( bFocusWnd && hFocusWnd != m_hWndPaint && pControl != m_pFocus && !m_bNoActivate) ::SetFocus(m_hWndPaint);
  1641. // Already has focus?
  1642. if( pControl == m_pFocus ) return;
  1643. // Remove focus from old control
  1644. if( m_pFocus != NULL )
  1645. {
  1646. TEventUI event = { 0 };
  1647. event.Type = UIEVENT_KILLFOCUS;
  1648. event.pSender = pControl;
  1649. event.dwTimestamp = ::GetTickCount();
  1650. m_pFocus->Event(event);
  1651. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  1652. m_pFocus = NULL;
  1653. }
  1654. if( pControl == NULL ) return;
  1655. // Set focus to new control
  1656. if( pControl != NULL
  1657. && pControl->GetManager() == this
  1658. && pControl->IsVisible()
  1659. && pControl->IsEnabled() )
  1660. {
  1661. m_pFocus = pControl;
  1662. TEventUI event = { 0 };
  1663. event.Type = UIEVENT_SETFOCUS;
  1664. event.pSender = pControl;
  1665. event.dwTimestamp = ::GetTickCount();
  1666. m_pFocus->Event(event);
  1667. SendNotify(m_pFocus, DUI_MSGTYPE_SETFOCUS);
  1668. }
  1669. }
  1670. void CPaintManagerUI::SetFocusNeeded(CControlUI* pControl)
  1671. {
  1672. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1673. if( pControl == NULL ) return;
  1674. if( m_pFocus != NULL ) {
  1675. TEventUI event = { 0 };
  1676. event.Type = UIEVENT_KILLFOCUS;
  1677. event.pSender = pControl;
  1678. event.dwTimestamp = ::GetTickCount();
  1679. m_pFocus->Event(event);
  1680. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  1681. m_pFocus = NULL;
  1682. }
  1683. FINDTABINFO info = { 0 };
  1684. info.pFocus = pControl;
  1685. info.bForward = false;
  1686. m_pFocus = m_pRoot->FindControl(__FindControlFromTab, &info, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  1687. m_bFocusNeeded = true;
  1688. if( m_pRoot != NULL ) m_pRoot->NeedUpdate();
  1689. }
  1690. bool CPaintManagerUI::SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse)
  1691. {
  1692. ASSERT(pControl!=NULL);
  1693. ASSERT(uElapse>0);
  1694. for( int i = 0; i< m_aTimers.GetSize(); i++ ) {
  1695. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1696. if( pTimer->pSender == pControl
  1697. && pTimer->hWnd == m_hWndPaint
  1698. && pTimer->nLocalID == nTimerID ) {
  1699. if( pTimer->bKilled == true ) {
  1700. if( ::SetTimer(m_hWndPaint, pTimer->uWinTimer, uElapse, NULL) ) {
  1701. pTimer->bKilled = false;
  1702. return true;
  1703. }
  1704. return false;
  1705. }
  1706. return false;
  1707. }
  1708. }
  1709. m_uTimerID = (++m_uTimerID) % 0xFF;
  1710. if( !::SetTimer(m_hWndPaint, m_uTimerID, uElapse, NULL) ) return FALSE;
  1711. TIMERINFO* pTimer = new TIMERINFO;
  1712. if( pTimer == NULL ) return FALSE;
  1713. pTimer->hWnd = m_hWndPaint;
  1714. pTimer->pSender = pControl;
  1715. pTimer->nLocalID = nTimerID;
  1716. pTimer->uWinTimer = m_uTimerID;
  1717. pTimer->bKilled = false;
  1718. return m_aTimers.Add(pTimer);
  1719. }
  1720. bool CPaintManagerUI::KillTimer(CControlUI* pControl, UINT nTimerID)
  1721. {
  1722. ASSERT(pControl!=NULL);
  1723. for( int i = 0; i< m_aTimers.GetSize(); i++ ) {
  1724. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1725. if( pTimer->pSender == pControl
  1726. && pTimer->hWnd == m_hWndPaint
  1727. && pTimer->nLocalID == nTimerID )
  1728. {
  1729. if( pTimer->bKilled == false ) {
  1730. if( ::IsWindow(m_hWndPaint) ) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  1731. pTimer->bKilled = true;
  1732. return true;
  1733. }
  1734. }
  1735. }
  1736. return false;
  1737. }
  1738. void CPaintManagerUI::KillTimer(CControlUI* pControl)
  1739. {
  1740. ASSERT(pControl!=NULL);
  1741. int count = m_aTimers.GetSize();
  1742. for( int i = 0, j = 0; i < count; i++ ) {
  1743. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i - j]);
  1744. if( pTimer->pSender == pControl && pTimer->hWnd == m_hWndPaint ) {
  1745. if( pTimer->bKilled == false ) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  1746. delete pTimer;
  1747. m_aTimers.Remove(i - j);
  1748. j++;
  1749. }
  1750. }
  1751. }
  1752. void CPaintManagerUI::RemoveAllTimers()
  1753. {
  1754. for( int i = 0; i < m_aTimers.GetSize(); i++ ) {
  1755. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1756. if( pTimer->hWnd == m_hWndPaint ) {
  1757. if( pTimer->bKilled == false ) {
  1758. if( ::IsWindow(m_hWndPaint) ) ::KillTimer(m_hWndPaint, pTimer->uWinTimer);
  1759. }
  1760. delete pTimer;
  1761. }
  1762. }
  1763. m_aTimers.Empty();
  1764. }
  1765. void CPaintManagerUI::SetCapture()
  1766. {
  1767. ::SetCapture(m_hWndPaint);
  1768. m_bMouseCapture = true;
  1769. }
  1770. void CPaintManagerUI::ReleaseCapture()
  1771. {
  1772. ::ReleaseCapture();
  1773. m_bMouseCapture = false;
  1774. }
  1775. bool CPaintManagerUI::IsCaptured()
  1776. {
  1777. return m_bMouseCapture;
  1778. }
  1779. bool CPaintManagerUI::IsPainting()
  1780. {
  1781. return m_bIsPainting;
  1782. }
  1783. void CPaintManagerUI::SetPainting(bool bIsPainting)
  1784. {
  1785. m_bIsPainting = bIsPainting;
  1786. }
  1787. bool CPaintManagerUI::SetNextTabControl(bool bForward)
  1788. {
  1789. // If we're in the process of restructuring the layout we can delay the
  1790. // focus calulation until the next repaint.
  1791. if( m_bUpdateNeeded && bForward ) {
  1792. m_bFocusNeeded = true;
  1793. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  1794. return true;
  1795. }
  1796. // Find next/previous tabbable control
  1797. FINDTABINFO info1 = { 0 };
  1798. info1.pFocus = m_pFocus;
  1799. info1.bForward = bForward;
  1800. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  1801. if( pControl == NULL ) {
  1802. if( bForward ) {
  1803. // Wrap around
  1804. FINDTABINFO info2 = { 0 };
  1805. info2.pFocus = bForward ? NULL : info1.pLast;
  1806. info2.bForward = bForward;
  1807. pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  1808. }
  1809. else {
  1810. pControl = info1.pLast;
  1811. }
  1812. }
  1813. if( pControl != NULL ) SetFocus(pControl);
  1814. m_bFocusNeeded = false;
  1815. return true;
  1816. }
  1817. bool CPaintManagerUI::AddNotifier(INotifyUI* pNotifier)
  1818. {
  1819. if (pNotifier == NULL) return false;
  1820. ASSERT(m_aNotifiers.Find(pNotifier)<0);
  1821. return m_aNotifiers.Add(pNotifier);
  1822. }
  1823. bool CPaintManagerUI::RemoveNotifier(INotifyUI* pNotifier)
  1824. {
  1825. for( int i = 0; i < m_aNotifiers.GetSize(); i++ ) {
  1826. if( static_cast<INotifyUI*>(m_aNotifiers[i]) == pNotifier ) {
  1827. return m_aNotifiers.Remove(i);
  1828. }
  1829. }
  1830. return false;
  1831. }
  1832. bool CPaintManagerUI::AddPreMessageFilter(IMessageFilterUI* pFilter)
  1833. {
  1834. if (pFilter == NULL) return false;
  1835. ASSERT(m_aPreMessageFilters.Find(pFilter)<0);
  1836. return m_aPreMessageFilters.Add(pFilter);
  1837. }
  1838. bool CPaintManagerUI::RemovePreMessageFilter(IMessageFilterUI* pFilter)
  1839. {
  1840. for( int i = 0; i < m_aPreMessageFilters.GetSize(); i++ ) {
  1841. if( static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i]) == pFilter ) {
  1842. return m_aPreMessageFilters.Remove(i);
  1843. }
  1844. }
  1845. return false;
  1846. }
  1847. bool CPaintManagerUI::AddMessageFilter(IMessageFilterUI* pFilter)
  1848. {
  1849. if (pFilter == NULL) return false;
  1850. ASSERT(m_aMessageFilters.Find(pFilter)<0);
  1851. return m_aMessageFilters.Add(pFilter);
  1852. }
  1853. bool CPaintManagerUI::RemoveMessageFilter(IMessageFilterUI* pFilter)
  1854. {
  1855. for( int i = 0; i < m_aMessageFilters.GetSize(); i++ ) {
  1856. if( static_cast<IMessageFilterUI*>(m_aMessageFilters[i]) == pFilter ) {
  1857. return m_aMessageFilters.Remove(i);
  1858. }
  1859. }
  1860. return false;
  1861. }
  1862. int CPaintManagerUI::GetPostPaintCount() const
  1863. {
  1864. return m_aPostPaintControls.GetSize();
  1865. }
  1866. bool CPaintManagerUI::AddPostPaint(CControlUI* pControl)
  1867. {
  1868. if (pControl == NULL) return false;
  1869. ASSERT(m_aPostPaintControls.Find(pControl) < 0);
  1870. return m_aPostPaintControls.Add(pControl);
  1871. }
  1872. bool CPaintManagerUI::RemovePostPaint(CControlUI* pControl)
  1873. {
  1874. for( int i = 0; i < m_aPostPaintControls.GetSize(); i++ ) {
  1875. if( static_cast<CControlUI*>(m_aPostPaintControls[i]) == pControl ) {
  1876. return m_aPostPaintControls.Remove(i);
  1877. }
  1878. }
  1879. return false;
  1880. }
  1881. bool CPaintManagerUI::SetPostPaintIndex(CControlUI* pControl, int iIndex)
  1882. {
  1883. if (pControl == NULL) return false;
  1884. RemovePostPaint(pControl);
  1885. return m_aPostPaintControls.InsertAt(iIndex, pControl);
  1886. }
  1887. int CPaintManagerUI::GetNativeWindowCount() const
  1888. {
  1889. return m_aNativeWindow.GetSize();
  1890. }
  1891. RECT CPaintManagerUI::GetNativeWindowRect(HWND hChildWnd)
  1892. {
  1893. RECT rcChildWnd;
  1894. ::GetWindowRect(hChildWnd, &rcChildWnd);
  1895. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd));
  1896. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd)+1);
  1897. return rcChildWnd;
  1898. }
  1899. bool CPaintManagerUI::AddNativeWindow(CControlUI* pControl, HWND hChildWnd)
  1900. {
  1901. if (pControl == NULL || hChildWnd == NULL) return false;
  1902. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  1903. Invalidate(rcChildWnd);
  1904. if (m_aNativeWindow.Find(hChildWnd) >= 0) return false;
  1905. if (m_aNativeWindow.Add(hChildWnd)) {
  1906. m_aNativeWindowControl.Add(pControl);
  1907. return true;
  1908. }
  1909. return false;
  1910. }
  1911. bool CPaintManagerUI::RemoveNativeWindow(HWND hChildWnd)
  1912. {
  1913. for( int i = 0; i < m_aNativeWindow.GetSize(); i++ ) {
  1914. if( static_cast<HWND>(m_aNativeWindow[i]) == hChildWnd ) {
  1915. if( m_aNativeWindow.Remove(i) ) {
  1916. m_aNativeWindowControl.Remove(i);
  1917. return true;
  1918. }
  1919. return false;
  1920. }
  1921. }
  1922. return false;
  1923. }
  1924. void CPaintManagerUI::AddDelayedCleanup(CControlUI* pControl)
  1925. {
  1926. if (pControl == NULL) return;
  1927. pControl->SetManager(this, NULL, false);
  1928. m_aDelayedCleanup.Add(pControl);
  1929. PostAsyncNotify();
  1930. }
  1931. void CPaintManagerUI::AddMouseLeaveNeeded(CControlUI* pControl)
  1932. {
  1933. if (pControl == NULL) return;
  1934. for( int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++ ) {
  1935. if( static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl ) {
  1936. return;
  1937. }
  1938. }
  1939. m_aNeedMouseLeaveNeeded.Add(pControl);
  1940. }
  1941. bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl)
  1942. {
  1943. if (pControl == NULL) return false;
  1944. for( int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++ ) {
  1945. if( static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl ) {
  1946. return m_aNeedMouseLeaveNeeded.Remove(i);
  1947. }
  1948. }
  1949. return false;
  1950. }
  1951. void CPaintManagerUI::SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/, bool bEnableRepeat /*= true*/)
  1952. {
  1953. TNotifyUI Msg;
  1954. Msg.pSender = pControl;
  1955. Msg.sType = pstrMessage;
  1956. Msg.wParam = wParam;
  1957. Msg.lParam = lParam;
  1958. SendNotify(Msg, bAsync, bEnableRepeat);
  1959. }
  1960. void CPaintManagerUI::SendNotify(TNotifyUI& Msg, bool bAsync /*= false*/, bool bEnableRepeat /*= true*/)
  1961. {
  1962. Msg.ptMouse = m_ptLastMousePos;
  1963. Msg.dwTimestamp = ::GetTickCount();
  1964. if( m_bUsedVirtualWnd )
  1965. {
  1966. Msg.sVirtualWnd = Msg.pSender->GetVirtualWnd();
  1967. }
  1968. if( !bAsync ) {
  1969. // Send to all listeners
  1970. if( Msg.pSender != NULL ) {
  1971. if( Msg.pSender->OnNotify ) Msg.pSender->OnNotify(&Msg);
  1972. }
  1973. for( int i = 0; i < m_aNotifiers.GetSize(); i++ ) {
  1974. static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg);
  1975. }
  1976. }
  1977. else {
  1978. if( !bEnableRepeat ) {
  1979. for( int i = 0; i < m_aAsyncNotify.GetSize(); i++ ) {
  1980. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  1981. if( pMsg->pSender == Msg.pSender && pMsg->sType == Msg.sType) {
  1982. if (m_bUsedVirtualWnd) pMsg->sVirtualWnd = Msg.sVirtualWnd;
  1983. pMsg->wParam = Msg.wParam;
  1984. pMsg->lParam = Msg.lParam;
  1985. pMsg->ptMouse = Msg.ptMouse;
  1986. pMsg->dwTimestamp = Msg.dwTimestamp;
  1987. return;
  1988. }
  1989. }
  1990. }
  1991. TNotifyUI *pMsg = new TNotifyUI;
  1992. if (m_bUsedVirtualWnd) pMsg->sVirtualWnd = Msg.sVirtualWnd;
  1993. pMsg->pSender = Msg.pSender;
  1994. pMsg->sType = Msg.sType;
  1995. pMsg->wParam = Msg.wParam;
  1996. pMsg->lParam = Msg.lParam;
  1997. pMsg->ptMouse = Msg.ptMouse;
  1998. pMsg->dwTimestamp = Msg.dwTimestamp;
  1999. m_aAsyncNotify.Add(pMsg);
  2000. PostAsyncNotify();
  2001. }
  2002. }
  2003. bool CPaintManagerUI::IsForceUseSharedRes() const
  2004. {
  2005. return m_bForceUseSharedRes;
  2006. }
  2007. void CPaintManagerUI::SetForceUseSharedRes(bool bForce)
  2008. {
  2009. m_bForceUseSharedRes = bForce;
  2010. }
  2011. DWORD CPaintManagerUI::GetDefaultDisabledColor() const
  2012. {
  2013. return m_ResInfo.m_dwDefaultDisabledColor;
  2014. }
  2015. void CPaintManagerUI::SetDefaultDisabledColor(DWORD dwColor, bool bShared)
  2016. {
  2017. if (bShared)
  2018. {
  2019. if (m_ResInfo.m_dwDefaultDisabledColor == m_SharedResInfo.m_dwDefaultDisabledColor)
  2020. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2021. m_SharedResInfo.m_dwDefaultDisabledColor = dwColor;
  2022. }
  2023. else
  2024. {
  2025. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2026. }
  2027. }
  2028. DWORD CPaintManagerUI::GetDefaultFontColor() const
  2029. {
  2030. return m_ResInfo.m_dwDefaultFontColor;
  2031. }
  2032. void CPaintManagerUI::SetDefaultFontColor(DWORD dwColor, bool bShared)
  2033. {
  2034. if (bShared)
  2035. {
  2036. if (m_ResInfo.m_dwDefaultFontColor == m_SharedResInfo.m_dwDefaultFontColor)
  2037. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2038. m_SharedResInfo.m_dwDefaultFontColor = dwColor;
  2039. }
  2040. else
  2041. {
  2042. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2043. }
  2044. }
  2045. DWORD CPaintManagerUI::GetDefaultLinkFontColor() const
  2046. {
  2047. return m_ResInfo.m_dwDefaultLinkFontColor;
  2048. }
  2049. void CPaintManagerUI::SetDefaultLinkFontColor(DWORD dwColor, bool bShared)
  2050. {
  2051. if (bShared)
  2052. {
  2053. if (m_ResInfo.m_dwDefaultLinkFontColor == m_SharedResInfo.m_dwDefaultLinkFontColor)
  2054. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2055. m_SharedResInfo.m_dwDefaultLinkFontColor = dwColor;
  2056. }
  2057. else
  2058. {
  2059. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2060. }
  2061. }
  2062. DWORD CPaintManagerUI::GetDefaultLinkHoverFontColor() const
  2063. {
  2064. return m_ResInfo.m_dwDefaultLinkHoverFontColor;
  2065. }
  2066. void CPaintManagerUI::SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared)
  2067. {
  2068. if (bShared)
  2069. {
  2070. if (m_ResInfo.m_dwDefaultLinkHoverFontColor == m_SharedResInfo.m_dwDefaultLinkHoverFontColor)
  2071. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2072. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2073. }
  2074. else
  2075. {
  2076. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2077. }
  2078. }
  2079. DWORD CPaintManagerUI::GetDefaultSelectedBkColor() const
  2080. {
  2081. return m_ResInfo.m_dwDefaultSelectedBkColor;
  2082. }
  2083. void CPaintManagerUI::SetDefaultSelectedBkColor(DWORD dwColor, bool bShared)
  2084. {
  2085. if (bShared)
  2086. {
  2087. if (m_ResInfo.m_dwDefaultSelectedBkColor == m_SharedResInfo.m_dwDefaultSelectedBkColor)
  2088. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2089. m_SharedResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2090. }
  2091. else
  2092. {
  2093. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2094. }
  2095. }
  2096. TFontInfo* CPaintManagerUI::GetDefaultFontInfo()
  2097. {
  2098. if (m_ResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  2099. {
  2100. if( m_SharedResInfo.m_DefaultFontInfo.tm.tmHeight == 0 )
  2101. {
  2102. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_SharedResInfo.m_DefaultFontInfo.hFont);
  2103. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  2104. ::SelectObject(m_hDcPaint, hOldFont);
  2105. }
  2106. return &m_SharedResInfo.m_DefaultFontInfo;
  2107. }
  2108. else
  2109. {
  2110. if( m_ResInfo.m_DefaultFontInfo.tm.tmHeight == 0 )
  2111. {
  2112. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_ResInfo.m_DefaultFontInfo.hFont);
  2113. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  2114. ::SelectObject(m_hDcPaint, hOldFont);
  2115. }
  2116. return &m_ResInfo.m_DefaultFontInfo;
  2117. }
  2118. }
  2119. void CPaintManagerUI::SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared)
  2120. {
  2121. LOGFONT lf = { 0 };
  2122. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2123. _tcsncpy(lf.lfFaceName, pStrFontName, LF_FACESIZE);
  2124. lf.lfCharSet = DEFAULT_CHARSET;
  2125. lf.lfHeight = -nSize;
  2126. if( bBold ) lf.lfWeight += FW_BOLD;
  2127. if( bUnderline ) lf.lfUnderline = TRUE;
  2128. if( bItalic ) lf.lfItalic = TRUE;
  2129. HFONT hFont = ::CreateFontIndirect(&lf);
  2130. if( hFont == NULL ) return;
  2131. if (bShared)
  2132. {
  2133. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  2134. m_SharedResInfo.m_DefaultFontInfo.hFont = hFont;
  2135. m_SharedResInfo.m_DefaultFontInfo.sFontName = pStrFontName;
  2136. m_SharedResInfo.m_DefaultFontInfo.iSize = nSize;
  2137. m_SharedResInfo.m_DefaultFontInfo.bBold = bBold;
  2138. m_SharedResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  2139. m_SharedResInfo.m_DefaultFontInfo.bItalic = bItalic;
  2140. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  2141. if( m_hDcPaint ) {
  2142. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2143. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  2144. ::SelectObject(m_hDcPaint, hOldFont);
  2145. }
  2146. }
  2147. else
  2148. {
  2149. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  2150. m_ResInfo.m_DefaultFontInfo.hFont = hFont;
  2151. m_ResInfo.m_DefaultFontInfo.sFontName = pStrFontName;
  2152. m_ResInfo.m_DefaultFontInfo.iSize = nSize;
  2153. m_ResInfo.m_DefaultFontInfo.bBold = bBold;
  2154. m_ResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  2155. m_ResInfo.m_DefaultFontInfo.bItalic = bItalic;
  2156. ::ZeroMemory(&m_ResInfo.m_DefaultFontInfo.tm, sizeof(m_ResInfo.m_DefaultFontInfo.tm));
  2157. if( m_hDcPaint ) {
  2158. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2159. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  2160. ::SelectObject(m_hDcPaint, hOldFont);
  2161. }
  2162. }
  2163. }
  2164. DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const
  2165. {
  2166. if (bShared)
  2167. return m_SharedResInfo.m_CustomFonts.GetSize();
  2168. else
  2169. return m_ResInfo.m_CustomFonts.GetSize();
  2170. }
  2171. HFONT CPaintManagerUI::AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared)
  2172. {
  2173. LOGFONT lf = { 0 };
  2174. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2175. _tcsncpy(lf.lfFaceName, pStrFontName, LF_FACESIZE);
  2176. lf.lfCharSet = DEFAULT_CHARSET;
  2177. lf.lfHeight = -nSize;
  2178. if( bBold ) lf.lfWeight += FW_BOLD;
  2179. if( bUnderline ) lf.lfUnderline = TRUE;
  2180. if( bItalic ) lf.lfItalic = TRUE;
  2181. HFONT hFont = ::CreateFontIndirect(&lf);
  2182. if( hFont == NULL ) return NULL;
  2183. TFontInfo* pFontInfo = new TFontInfo;
  2184. if( !pFontInfo ) return false;
  2185. ::ZeroMemory(pFontInfo, sizeof(TFontInfo));
  2186. pFontInfo->hFont = hFont;
  2187. pFontInfo->sFontName = pStrFontName;
  2188. pFontInfo->iSize = nSize;
  2189. pFontInfo->bBold = bBold;
  2190. pFontInfo->bUnderline = bUnderline;
  2191. pFontInfo->bItalic = bItalic;
  2192. if( m_hDcPaint ) {
  2193. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2194. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2195. ::SelectObject(m_hDcPaint, hOldFont);
  2196. }
  2197. TCHAR idBuffer[16];
  2198. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  2199. _itot(id, idBuffer, 10);
  2200. if (bShared || m_bForceUseSharedRes)
  2201. {
  2202. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  2203. if (pOldFontInfo)
  2204. {
  2205. ::DeleteObject(pOldFontInfo->hFont);
  2206. delete pOldFontInfo;
  2207. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  2208. }
  2209. if( !m_SharedResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo) )
  2210. {
  2211. ::DeleteObject(hFont);
  2212. delete pFontInfo;
  2213. return NULL;
  2214. }
  2215. }
  2216. else
  2217. {
  2218. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  2219. if (pOldFontInfo)
  2220. {
  2221. ::DeleteObject(pOldFontInfo->hFont);
  2222. delete pOldFontInfo;
  2223. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  2224. }
  2225. if( !m_ResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo) )
  2226. {
  2227. ::DeleteObject(hFont);
  2228. delete pFontInfo;
  2229. return NULL;
  2230. }
  2231. }
  2232. return hFont;
  2233. }
  2234. HFONT CPaintManagerUI::GetFont(int id)
  2235. {
  2236. if (id < 0) return GetDefaultFontInfo()->hFont;
  2237. TCHAR idBuffer[16];
  2238. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  2239. _itot(id, idBuffer, 10);
  2240. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  2241. if( !pFontInfo ) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  2242. if (!pFontInfo) return GetDefaultFontInfo()->hFont;
  2243. return pFontInfo->hFont;
  2244. }
  2245. HFONT CPaintManagerUI::GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic)
  2246. {
  2247. TFontInfo* pFontInfo = NULL;
  2248. for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ ) {
  2249. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i)) {
  2250. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  2251. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  2252. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic)
  2253. return pFontInfo->hFont;
  2254. }
  2255. }
  2256. for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ ) {
  2257. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i)) {
  2258. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  2259. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  2260. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic)
  2261. return pFontInfo->hFont;
  2262. }
  2263. }
  2264. return NULL;
  2265. }
  2266. int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared)
  2267. {
  2268. TFontInfo* pFontInfo = NULL;
  2269. if (bShared)
  2270. {
  2271. for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ ) {
  2272. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i)) {
  2273. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  2274. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  2275. }
  2276. }
  2277. }
  2278. else
  2279. {
  2280. for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ ) {
  2281. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i)) {
  2282. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  2283. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  2284. }
  2285. }
  2286. }
  2287. return -1;
  2288. }
  2289. int CPaintManagerUI::GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared)
  2290. {
  2291. TFontInfo* pFontInfo = NULL;
  2292. if (bShared)
  2293. {
  2294. for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ ) {
  2295. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i)) {
  2296. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  2297. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  2298. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic)
  2299. return _ttoi(key);
  2300. }
  2301. }
  2302. }
  2303. else
  2304. {
  2305. for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ ) {
  2306. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i)) {
  2307. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  2308. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  2309. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic)
  2310. return _ttoi(key);
  2311. }
  2312. }
  2313. }
  2314. return -1;
  2315. }
  2316. void CPaintManagerUI::RemoveFont(HFONT hFont, bool bShared)
  2317. {
  2318. TFontInfo* pFontInfo = NULL;
  2319. if (bShared)
  2320. {
  2321. for( int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++ )
  2322. {
  2323. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  2324. {
  2325. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  2326. if (pFontInfo && pFontInfo->hFont == hFont)
  2327. {
  2328. ::DeleteObject(pFontInfo->hFont);
  2329. delete pFontInfo;
  2330. m_SharedResInfo.m_CustomFonts.Remove(key);
  2331. return;
  2332. }
  2333. }
  2334. }
  2335. }
  2336. else
  2337. {
  2338. for( int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++ )
  2339. {
  2340. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  2341. {
  2342. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  2343. if (pFontInfo && pFontInfo->hFont == hFont)
  2344. {
  2345. ::DeleteObject(pFontInfo->hFont);
  2346. delete pFontInfo;
  2347. m_ResInfo.m_CustomFonts.Remove(key);
  2348. return;
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. void CPaintManagerUI::RemoveFont(int id, bool bShared)
  2355. {
  2356. TCHAR idBuffer[16];
  2357. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  2358. _itot(id, idBuffer, 10);
  2359. TFontInfo* pFontInfo = NULL;
  2360. if (bShared)
  2361. {
  2362. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  2363. if (pFontInfo)
  2364. {
  2365. ::DeleteObject(pFontInfo->hFont);
  2366. delete pFontInfo;
  2367. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  2368. }
  2369. }
  2370. else
  2371. {
  2372. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  2373. if (pFontInfo)
  2374. {
  2375. ::DeleteObject(pFontInfo->hFont);
  2376. delete pFontInfo;
  2377. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  2378. }
  2379. }
  2380. }
  2381. void CPaintManagerUI::RemoveAllFonts(bool bShared)
  2382. {
  2383. TFontInfo* pFontInfo;
  2384. if (bShared)
  2385. {
  2386. for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ ) {
  2387. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i)) {
  2388. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  2389. if (pFontInfo) {
  2390. ::DeleteObject(pFontInfo->hFont);
  2391. delete pFontInfo;
  2392. }
  2393. }
  2394. }
  2395. m_SharedResInfo.m_CustomFonts.RemoveAll();
  2396. }
  2397. else
  2398. {
  2399. for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ ) {
  2400. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i)) {
  2401. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key, false));
  2402. if (pFontInfo) {
  2403. ::DeleteObject(pFontInfo->hFont);
  2404. delete pFontInfo;
  2405. }
  2406. }
  2407. }
  2408. m_ResInfo.m_CustomFonts.RemoveAll();
  2409. }
  2410. }
  2411. TFontInfo* CPaintManagerUI::GetFontInfo(int id)
  2412. {
  2413. TCHAR idBuffer[16];
  2414. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  2415. _itot(id, idBuffer, 10);
  2416. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  2417. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  2418. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  2419. if (pFontInfo->tm.tmHeight == 0)
  2420. {
  2421. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  2422. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2423. ::SelectObject(m_hDcPaint, hOldFont);
  2424. }
  2425. return pFontInfo;
  2426. }
  2427. TFontInfo* CPaintManagerUI::GetFontInfo(HFONT hFont)
  2428. {
  2429. TFontInfo* pFontInfo = NULL;
  2430. for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ )
  2431. {
  2432. if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  2433. {
  2434. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  2435. if (pFontInfo && pFontInfo->hFont == hFont) break;
  2436. }
  2437. }
  2438. if (!pFontInfo)
  2439. {
  2440. for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ )
  2441. {
  2442. if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  2443. {
  2444. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  2445. if (pFontInfo && pFontInfo->hFont == hFont) break;
  2446. }
  2447. }
  2448. }
  2449. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  2450. if( pFontInfo->tm.tmHeight == 0 ) {
  2451. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  2452. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2453. ::SelectObject(m_hDcPaint, hOldFont);
  2454. }
  2455. return pFontInfo;
  2456. }
  2457. const TImageInfo* CPaintManagerUI::GetImage(LPCTSTR bitmap)
  2458. {
  2459. TImageInfo* data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  2460. if( !data ) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  2461. return data;
  2462. }
  2463. const TImageInfo* CPaintManagerUI::GetImageEx(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL)
  2464. {
  2465. const TImageInfo* data = GetImage(bitmap);
  2466. if( !data ) {
  2467. if( AddImage(bitmap, type, mask, bUseHSL, false) ) {
  2468. if (m_bForceUseSharedRes) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  2469. else data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  2470. }
  2471. }
  2472. return data;
  2473. }
  2474. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bShared)
  2475. {
  2476. if( bitmap == NULL || bitmap[0] == _T('\0') ) return NULL;
  2477. TImageInfo* data = NULL;
  2478. if( type != NULL ) {
  2479. if( isdigit(*bitmap) ) {
  2480. LPTSTR pstr = NULL;
  2481. int iIndex = _tcstol(bitmap, &pstr, 10);
  2482. data = CRenderEngine::LoadImage(iIndex, type, mask);
  2483. }
  2484. else {
  2485. data = CRenderEngine::LoadImage(bitmap, type, mask);
  2486. }
  2487. }
  2488. else {
  2489. data = CRenderEngine::LoadImage(bitmap, NULL, mask);
  2490. }
  2491. if( data == NULL ) return NULL;
  2492. data->bUseHSL = bUseHSL;
  2493. if( type != NULL ) data->sResType = type;
  2494. data->dwMask = mask;
  2495. if( data->bUseHSL ) {
  2496. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  2497. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  2498. }
  2499. else data->pSrcBits = NULL;
  2500. if( m_bUseHSL ) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  2501. if (data)
  2502. {
  2503. if (bShared || m_bForceUseSharedRes)
  2504. {
  2505. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  2506. if (pOldImageInfo)
  2507. {
  2508. CRenderEngine::FreeImage(pOldImageInfo);
  2509. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  2510. }
  2511. if( !m_SharedResInfo.m_ImageHash.Insert(bitmap, data) ) {
  2512. CRenderEngine::FreeImage(data);
  2513. data = NULL;
  2514. }
  2515. }
  2516. else
  2517. {
  2518. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  2519. if (pOldImageInfo)
  2520. {
  2521. CRenderEngine::FreeImage(pOldImageInfo);
  2522. m_ResInfo.m_ImageHash.Remove(bitmap);
  2523. }
  2524. if( !m_ResInfo.m_ImageHash.Insert(bitmap, data) ) {
  2525. CRenderEngine::FreeImage(data);
  2526. data = NULL;
  2527. }
  2528. }
  2529. }
  2530. return data;
  2531. }
  2532. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared)
  2533. {
  2534. // 因无法确定外部HBITMAP格式,不能使用hsl调整
  2535. if( bitmap == NULL || bitmap[0] == _T('\0') ) return NULL;
  2536. if( hBitmap == NULL || iWidth <= 0 || iHeight <= 0 ) return NULL;
  2537. TImageInfo* data = new TImageInfo;
  2538. data->hBitmap = hBitmap;
  2539. data->pBits = NULL;
  2540. data->nX = iWidth;
  2541. data->nY = iHeight;
  2542. data->bAlpha = bAlpha;
  2543. data->bUseHSL = false;
  2544. data->pSrcBits = NULL;
  2545. //data->sResType = _T("");
  2546. data->dwMask = 0;
  2547. if (bShared || m_bForceUseSharedRes)
  2548. {
  2549. if( !m_SharedResInfo.m_ImageHash.Insert(bitmap, data) ) {
  2550. CRenderEngine::FreeImage(data);
  2551. data = NULL;
  2552. }
  2553. }
  2554. else
  2555. {
  2556. if( !m_SharedResInfo.m_ImageHash.Insert(bitmap, data) ) {
  2557. CRenderEngine::FreeImage(data);
  2558. data = NULL;
  2559. }
  2560. }
  2561. return data;
  2562. }
  2563. void CPaintManagerUI::RemoveImage(LPCTSTR bitmap, bool bShared)
  2564. {
  2565. TImageInfo* data = NULL;
  2566. if (bShared)
  2567. {
  2568. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  2569. if (data)
  2570. {
  2571. CRenderEngine::FreeImage(data) ;
  2572. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  2573. }
  2574. }
  2575. else
  2576. {
  2577. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  2578. if (data)
  2579. {
  2580. CRenderEngine::FreeImage(data) ;
  2581. m_ResInfo.m_ImageHash.Remove(bitmap);
  2582. }
  2583. }
  2584. }
  2585. void CPaintManagerUI::RemoveAllImages(bool bShared)
  2586. {
  2587. if (bShared)
  2588. {
  2589. TImageInfo* data;
  2590. for( int i = 0; i< m_SharedResInfo.m_ImageHash.GetSize(); i++ ) {
  2591. if(LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i)) {
  2592. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  2593. if (data) {
  2594. CRenderEngine::FreeImage(data);
  2595. }
  2596. }
  2597. }
  2598. m_SharedResInfo.m_ImageHash.RemoveAll();
  2599. }
  2600. else
  2601. {
  2602. TImageInfo* data;
  2603. for( int i = 0; i< m_ResInfo.m_ImageHash.GetSize(); i++ ) {
  2604. if(LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i)) {
  2605. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key, false));
  2606. if (data) {
  2607. CRenderEngine::FreeImage(data);
  2608. }
  2609. }
  2610. }
  2611. m_ResInfo.m_ImageHash.RemoveAll();
  2612. }
  2613. }
  2614. void CPaintManagerUI::AdjustSharedImagesHSL()
  2615. {
  2616. TImageInfo* data;
  2617. for( int i = 0; i< m_SharedResInfo.m_ImageHash.GetSize(); i++ ) {
  2618. if(LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i)) {
  2619. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key));
  2620. if( data && data->bUseHSL ) {
  2621. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  2622. }
  2623. }
  2624. }
  2625. }
  2626. void CPaintManagerUI::AdjustImagesHSL()
  2627. {
  2628. TImageInfo* data;
  2629. for( int i = 0; i< m_ResInfo.m_ImageHash.GetSize(); i++ ) {
  2630. if(LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i)) {
  2631. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key));
  2632. if( data && data->bUseHSL ) {
  2633. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  2634. }
  2635. }
  2636. }
  2637. Invalidate();
  2638. }
  2639. void CPaintManagerUI::PostAsyncNotify()
  2640. {
  2641. if (!m_bAsyncNotifyPosted) {
  2642. ::PostMessage(m_hWndPaint, WM_APP + 1, 0, 0L);
  2643. m_bAsyncNotifyPosted = true;
  2644. }
  2645. }
  2646. void CPaintManagerUI::ReloadSharedImages()
  2647. {
  2648. TImageInfo* data;
  2649. TImageInfo* pNewData;
  2650. for( int i = 0; i< m_SharedResInfo.m_ImageHash.GetSize(); i++ ) {
  2651. if(LPCTSTR bitmap = m_SharedResInfo.m_ImageHash.GetAt(i)) {
  2652. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  2653. if( data != NULL ) {
  2654. if( !data->sResType.IsEmpty() ) {
  2655. if( isdigit(*bitmap) ) {
  2656. LPTSTR pstr = NULL;
  2657. int iIndex = _tcstol(bitmap, &pstr, 10);
  2658. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  2659. }
  2660. else {
  2661. pNewData = CRenderEngine::LoadImage(bitmap, data->sResType.GetData(), data->dwMask);
  2662. }
  2663. }
  2664. else {
  2665. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  2666. }
  2667. if( pNewData == NULL ) continue;
  2668. CRenderEngine::FreeImage(data, false);
  2669. data->hBitmap = pNewData->hBitmap;
  2670. data->pBits = pNewData->pBits;
  2671. data->nX = pNewData->nX;
  2672. data->nY = pNewData->nY;
  2673. data->bAlpha = pNewData->bAlpha;
  2674. data->pSrcBits = NULL;
  2675. if( data->bUseHSL ) {
  2676. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  2677. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  2678. }
  2679. else data->pSrcBits = NULL;
  2680. if( m_bUseHSL ) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  2681. delete pNewData;
  2682. }
  2683. }
  2684. }
  2685. }
  2686. void CPaintManagerUI::ReloadImages()
  2687. {
  2688. TImageInfo* data;
  2689. TImageInfo* pNewData;
  2690. for( int i = 0; i< m_ResInfo.m_ImageHash.GetSize(); i++ ) {
  2691. if(LPCTSTR bitmap = m_ResInfo.m_ImageHash.GetAt(i)) {
  2692. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  2693. if( data != NULL ) {
  2694. if( !data->sResType.IsEmpty() ) {
  2695. if( isdigit(*bitmap) ) {
  2696. LPTSTR pstr = NULL;
  2697. int iIndex = _tcstol(bitmap, &pstr, 10);
  2698. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  2699. }
  2700. else {
  2701. pNewData = CRenderEngine::LoadImage(bitmap, data->sResType.GetData(), data->dwMask);
  2702. }
  2703. }
  2704. else {
  2705. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  2706. }
  2707. if( pNewData == NULL ) continue;
  2708. CRenderEngine::FreeImage(data, false);
  2709. data->hBitmap = pNewData->hBitmap;
  2710. data->pBits = pNewData->pBits;
  2711. data->nX = pNewData->nX;
  2712. data->nY = pNewData->nY;
  2713. data->bAlpha = pNewData->bAlpha;
  2714. data->pSrcBits = NULL;
  2715. if( data->bUseHSL ) {
  2716. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  2717. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  2718. }
  2719. else data->pSrcBits = NULL;
  2720. if( m_bUseHSL ) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  2721. delete pNewData;
  2722. }
  2723. }
  2724. }
  2725. if( m_pRoot ) m_pRoot->Invalidate();
  2726. }
  2727. void CPaintManagerUI::AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared)
  2728. {
  2729. if (bShared || m_bForceUseSharedRes)
  2730. {
  2731. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  2732. if (pDefaultAttr != NULL)
  2733. {
  2734. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  2735. if (pOldDefaultAttr) delete pOldDefaultAttr;
  2736. }
  2737. }
  2738. else
  2739. {
  2740. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  2741. if (pDefaultAttr != NULL)
  2742. {
  2743. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  2744. if (pOldDefaultAttr) delete pOldDefaultAttr;
  2745. }
  2746. }
  2747. }
  2748. LPCTSTR CPaintManagerUI::GetDefaultAttributeList(LPCTSTR pStrControlName) const
  2749. {
  2750. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  2751. if( !pDefaultAttr ) pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  2752. if (pDefaultAttr) return pDefaultAttr->GetData();
  2753. return NULL;
  2754. }
  2755. bool CPaintManagerUI::RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared)
  2756. {
  2757. if (bShared)
  2758. {
  2759. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  2760. if( !pDefaultAttr ) return false;
  2761. delete pDefaultAttr;
  2762. return m_SharedResInfo.m_AttrHash.Remove(pStrControlName);
  2763. }
  2764. else
  2765. {
  2766. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  2767. if( !pDefaultAttr ) return false;
  2768. delete pDefaultAttr;
  2769. return m_ResInfo.m_AttrHash.Remove(pStrControlName);
  2770. }
  2771. }
  2772. void CPaintManagerUI::RemoveAllDefaultAttributeList(bool bShared)
  2773. {
  2774. if (bShared)
  2775. {
  2776. CDuiString* pDefaultAttr;
  2777. for( int i = 0; i< m_SharedResInfo.m_AttrHash.GetSize(); i++ ) {
  2778. if(LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i)) {
  2779. pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key));
  2780. if (pDefaultAttr) delete pDefaultAttr;
  2781. }
  2782. }
  2783. m_SharedResInfo.m_AttrHash.RemoveAll();
  2784. }
  2785. else
  2786. {
  2787. CDuiString* pDefaultAttr;
  2788. for( int i = 0; i< m_ResInfo.m_AttrHash.GetSize(); i++ ) {
  2789. if(LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i)) {
  2790. pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key));
  2791. if (pDefaultAttr) delete pDefaultAttr;
  2792. }
  2793. }
  2794. m_ResInfo.m_AttrHash.RemoveAll();
  2795. }
  2796. }
  2797. void CPaintManagerUI::AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  2798. {
  2799. if( pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0') ) return;
  2800. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  2801. if (pCostomAttr != NULL) {
  2802. if (m_mWindowAttrHash.Find(pstrName) == NULL)
  2803. m_mWindowAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  2804. else
  2805. delete pCostomAttr;
  2806. }
  2807. }
  2808. LPCTSTR CPaintManagerUI::GetWindowCustomAttribute(LPCTSTR pstrName) const
  2809. {
  2810. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  2811. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowAttrHash.Find(pstrName));
  2812. if( pCostomAttr ) return pCostomAttr->GetData();
  2813. return NULL;
  2814. }
  2815. bool CPaintManagerUI::RemoveWindowCustomAttribute(LPCTSTR pstrName)
  2816. {
  2817. if( pstrName == NULL || pstrName[0] == _T('\0') ) return NULL;
  2818. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowAttrHash.Find(pstrName));
  2819. if( !pCostomAttr ) return false;
  2820. delete pCostomAttr;
  2821. return m_mWindowAttrHash.Remove(pstrName);
  2822. }
  2823. void CPaintManagerUI::RemoveAllWindowCustomAttribute()
  2824. {
  2825. CDuiString* pCostomAttr;
  2826. for( int i = 0; i< m_mWindowAttrHash.GetSize(); i++ ) {
  2827. if(LPCTSTR key = m_mWindowAttrHash.GetAt(i)) {
  2828. pCostomAttr = static_cast<CDuiString*>(m_mWindowAttrHash.Find(key));
  2829. delete pCostomAttr;
  2830. }
  2831. }
  2832. m_mWindowAttrHash.Resize();
  2833. }
  2834. CDuiString CPaintManagerUI::GetWindowAttribute(LPCTSTR pstrName)
  2835. {
  2836. return _T("");
  2837. }
  2838. void CPaintManagerUI::SetWindowAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  2839. {
  2840. if( _tcsicmp(pstrName, _T("size")) == 0 ) {
  2841. LPTSTR pstr = NULL;
  2842. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2843. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2844. SetInitSize(cx, cy);
  2845. }
  2846. else if( _tcsicmp(pstrName, _T("sizebox")) == 0 ) {
  2847. RECT rcSizeBox = { 0 };
  2848. LPTSTR pstr = NULL;
  2849. rcSizeBox.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2850. rcSizeBox.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2851. rcSizeBox.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2852. rcSizeBox.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2853. SetSizeBox(rcSizeBox);
  2854. }
  2855. else if( _tcsicmp(pstrName, _T("caption")) == 0 ) {
  2856. RECT rcCaption = { 0 };
  2857. LPTSTR pstr = NULL;
  2858. rcCaption.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2859. rcCaption.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2860. rcCaption.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2861. rcCaption.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2862. SetCaptionRect(rcCaption);
  2863. }
  2864. else if( _tcsicmp(pstrName, _T("roundcorner")) == 0 ) {
  2865. LPTSTR pstr = NULL;
  2866. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2867. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2868. SetRoundCorner(cx, cy);
  2869. }
  2870. else if( _tcsicmp(pstrName, _T("mininfo")) == 0 ) {
  2871. LPTSTR pstr = NULL;
  2872. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2873. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2874. SetMinInfo(cx, cy);
  2875. }
  2876. else if( _tcsicmp(pstrName, _T("maxinfo")) == 0 ) {
  2877. LPTSTR pstr = NULL;
  2878. int cx = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  2879. int cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  2880. SetMaxInfo(cx, cy);
  2881. }
  2882. else if( _tcsicmp(pstrName, _T("showdirty")) == 0 ) {
  2883. SetShowUpdateRect(_tcsicmp(pstrValue, _T("true")) == 0);
  2884. }
  2885. else if( _tcscmp(pstrName, _T("noactivate")) == 0 ) {
  2886. SetNoActivate(_tcsicmp(pstrValue, _T("true")) == 0);
  2887. }
  2888. else if( _tcsicmp(pstrName, _T("opacity")) == 0 ) {
  2889. SetOpacity(_ttoi(pstrValue));
  2890. }
  2891. else if( _tcscmp(pstrName, _T("layeredopacity")) == 0 ) {
  2892. SetLayeredOpacity(_ttoi(pstrValue));
  2893. }
  2894. else if( _tcscmp(pstrName, _T("layeredimage")) == 0 ) {
  2895. SetLayered(true);
  2896. SetLayeredImage(pstrValue);
  2897. }
  2898. else if( _tcsicmp(pstrName, _T("disabledfontcolor")) == 0 ) {
  2899. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  2900. LPTSTR pstr = NULL;
  2901. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  2902. SetDefaultDisabledColor(clrColor);
  2903. }
  2904. else if( _tcsicmp(pstrName, _T("defaultfontcolor")) == 0 ) {
  2905. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  2906. LPTSTR pstr = NULL;
  2907. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  2908. SetDefaultFontColor(clrColor);
  2909. }
  2910. else if( _tcsicmp(pstrName, _T("linkfontcolor")) == 0 ) {
  2911. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  2912. LPTSTR pstr = NULL;
  2913. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  2914. SetDefaultLinkFontColor(clrColor);
  2915. }
  2916. else if( _tcsicmp(pstrName, _T("linkhoverfontcolor")) == 0 ) {
  2917. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  2918. LPTSTR pstr = NULL;
  2919. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  2920. SetDefaultLinkHoverFontColor(clrColor);
  2921. }
  2922. else if( _tcsicmp(pstrName, _T("selectedcolor")) == 0 ) {
  2923. if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  2924. LPTSTR pstr = NULL;
  2925. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  2926. SetDefaultSelectedBkColor(clrColor);
  2927. }
  2928. else
  2929. AddWindowCustomAttribute(pstrName, pstrValue);
  2930. }
  2931. CDuiString CPaintManagerUI::GetWindowAttributeList(bool bIgnoreDefault)
  2932. {
  2933. return _T("");
  2934. }
  2935. void CPaintManagerUI::SetWindowAttributeList(LPCTSTR pstrList)
  2936. {
  2937. CDuiString sItem;
  2938. CDuiString sValue;
  2939. while( *pstrList != _T('\0') ) {
  2940. sItem.Empty();
  2941. sValue.Empty();
  2942. while( *pstrList != _T('\0') && *pstrList != _T('=') ) {
  2943. LPTSTR pstrTemp = ::CharNext(pstrList);
  2944. while( pstrList < pstrTemp) {
  2945. sItem += *pstrList++;
  2946. }
  2947. }
  2948. ASSERT( *pstrList == _T('=') );
  2949. if( *pstrList++ != _T('=') ) return;
  2950. ASSERT( *pstrList == _T('\"') );
  2951. if( *pstrList++ != _T('\"') ) return;
  2952. while( *pstrList != _T('\0') && *pstrList != _T('\"') ) {
  2953. LPTSTR pstrTemp = ::CharNext(pstrList);
  2954. while( pstrList < pstrTemp) {
  2955. sValue += *pstrList++;
  2956. }
  2957. }
  2958. ASSERT( *pstrList == _T('\"') );
  2959. if( *pstrList++ != _T('\"') ) return;
  2960. SetWindowAttribute(sItem, sValue);
  2961. if( *pstrList++ != _T(' ') ) return;
  2962. }
  2963. }
  2964. bool CPaintManagerUI::RemoveWindowAttribute(LPCTSTR pstrName)
  2965. {
  2966. return false;
  2967. }
  2968. CDuiString CPaintManagerUI::GetWindowXML()
  2969. {
  2970. CDuiString sWindowXML;
  2971. sWindowXML.Append(_T("<Window "));
  2972. // Window
  2973. // font
  2974. //TFontInfo* pFontInfo;
  2975. //for( int i = 0; i< m_SharedResInfo.m_CustomFonts.GetSize(); i++ ) {
  2976. // if(LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i)) {
  2977. // pFontInfo = static_cast<CDuiString*>(m_SharedResInfo.m_CustomFonts.Find(key))->GetData();
  2978. // sWindowXML.Append(_T("\n\t<Font shared=\"true\" id=\" "));
  2979. // sWindowXML.Append(key);
  2980. // sWindowXML.Append(_T("\" value=\" "));
  2981. // sWindowXML.Append(sDefaultAttr.GetData());
  2982. // sWindowXML.Append(_T("\" />"));
  2983. // }
  2984. //}
  2985. //for( int i = 0; i< m_ResInfo.m_CustomFonts.GetSize(); i++ ) {
  2986. // if(LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i)) {
  2987. // sDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_CustomFonts.Find(key))->GetData();
  2988. // sDefaultAttr.Replace(_T("\""), _T("&quot;"));
  2989. // sWindowXML.Append(_T("\n\t<Default name=\" "));
  2990. // sWindowXML.Append(key);
  2991. // sWindowXML.Append(_T("\" value=\" "));
  2992. // sWindowXML.Append(sDefaultAttr.GetData());
  2993. // sWindowXML.Append(_T("\" />"));
  2994. // }
  2995. //}
  2996. // image
  2997. // MultiLanguage
  2998. // Default
  2999. CDuiString sDefaultAttr;
  3000. for( int i = 0; i< m_SharedResInfo.m_AttrHash.GetSize(); i++ ) {
  3001. if(LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i)) {
  3002. sDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key))->GetData();
  3003. sDefaultAttr.Replace(_T("\""), _T("&quot;"));
  3004. sWindowXML.Append(_T("\n\t<Default shared=\"true\" name=\" "));
  3005. sWindowXML.Append(key);
  3006. sWindowXML.Append(_T("\" value=\" "));
  3007. sWindowXML.Append(sDefaultAttr.GetData());
  3008. sWindowXML.Append(_T("\" />"));
  3009. }
  3010. }
  3011. for( int i = 0; i< m_ResInfo.m_AttrHash.GetSize(); i++ ) {
  3012. if(LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i)) {
  3013. sDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key))->GetData();
  3014. sDefaultAttr.Replace(_T("\""), _T("&quot;"));
  3015. sWindowXML.Append(_T("\n\t<Default name=\" "));
  3016. sWindowXML.Append(key);
  3017. sWindowXML.Append(_T("\" value=\" "));
  3018. sWindowXML.Append(sDefaultAttr.GetData());
  3019. sWindowXML.Append(_T("\" />"));
  3020. }
  3021. }
  3022. // Controls
  3023. return _T("");
  3024. }
  3025. void CPaintManagerUI::AddMultiLanguageString(int id, LPCTSTR pStrMultiLanguage)
  3026. {
  3027. TCHAR idBuffer[16];
  3028. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3029. _itot(id, idBuffer, 10);
  3030. CDuiString* pMultiLanguage = new CDuiString(pStrMultiLanguage);
  3031. if (pMultiLanguage != NULL)
  3032. {
  3033. CDuiString* pOldMultiLanguage = static_cast<CDuiString*>(m_SharedResInfo.m_MultiLanguageHash.Set(idBuffer, (LPVOID)pMultiLanguage));
  3034. if (pOldMultiLanguage) delete pOldMultiLanguage;
  3035. }
  3036. }
  3037. LPCTSTR CPaintManagerUI::GetMultiLanguageString(int id)
  3038. {
  3039. TCHAR idBuffer[16];
  3040. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3041. _itot(id, idBuffer, 10);
  3042. CDuiString* pMultiLanguage = static_cast<CDuiString*>(m_SharedResInfo.m_MultiLanguageHash.Find(idBuffer));
  3043. if (pMultiLanguage) return pMultiLanguage->GetData();
  3044. return NULL;
  3045. }
  3046. bool CPaintManagerUI::RemoveMultiLanguageString(int id)
  3047. {
  3048. TCHAR idBuffer[16];
  3049. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3050. _itot(id, idBuffer, 10);
  3051. CDuiString* pMultiLanguage = static_cast<CDuiString*>(m_SharedResInfo.m_MultiLanguageHash.Find(idBuffer));
  3052. if( !pMultiLanguage ) return false;
  3053. delete pMultiLanguage;
  3054. return m_SharedResInfo.m_MultiLanguageHash.Remove(idBuffer);
  3055. }
  3056. void CPaintManagerUI::RemoveAllMultiLanguageString()
  3057. {
  3058. CDuiString* pMultiLanguage;
  3059. for( int i = 0; i< m_SharedResInfo.m_MultiLanguageHash.GetSize(); i++ ) {
  3060. if(LPCTSTR key = m_SharedResInfo.m_MultiLanguageHash.GetAt(i)) {
  3061. pMultiLanguage = static_cast<CDuiString*>(m_SharedResInfo.m_MultiLanguageHash.Find(key));
  3062. if (pMultiLanguage) delete pMultiLanguage;
  3063. }
  3064. }
  3065. m_SharedResInfo.m_MultiLanguageHash.RemoveAll();
  3066. }
  3067. void CPaintManagerUI::ProcessMultiLanguageTokens(CDuiString& pStrMultiLanguage)
  3068. {
  3069. // Replace string-tokens: %{nnn}, nnn=int
  3070. int iPos = pStrMultiLanguage.Find(_T('%'));
  3071. while( iPos >= 0 ) {
  3072. if( pStrMultiLanguage.GetAt(iPos + 1) == _T('{') ) {
  3073. int iEndPos = iPos + 2;
  3074. while( isdigit(pStrMultiLanguage.GetAt(iEndPos)) ) iEndPos++;
  3075. if( pStrMultiLanguage.GetAt(iEndPos) == '}' ) {
  3076. LPCTSTR pStrTemp = CPaintManagerUI::GetMultiLanguageString((UINT)_ttoi(pStrMultiLanguage.GetData() + iPos + 2));
  3077. if (pStrTemp)
  3078. pStrMultiLanguage.Replace(pStrMultiLanguage.Mid(iPos, iEndPos - iPos + 1), pStrTemp);
  3079. }
  3080. }
  3081. iPos = pStrMultiLanguage.Find(_T('%'), iPos + 1);
  3082. }
  3083. }
  3084. CControlUI* CPaintManagerUI::GetRoot() const
  3085. {
  3086. ASSERT(m_pRoot);
  3087. return m_pRoot;
  3088. }
  3089. CControlUI* CPaintManagerUI::FindControl(POINT pt) const
  3090. {
  3091. ASSERT(m_pRoot);
  3092. return m_pRoot->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3093. }
  3094. CControlUI* CPaintManagerUI::FindControl(LPCTSTR pstrName) const
  3095. {
  3096. ASSERT(m_pRoot);
  3097. return static_cast<CControlUI*>(m_mNameHash.Find(pstrName));
  3098. }
  3099. CControlUI* CPaintManagerUI::FindSubControlByPoint(CControlUI* pParent, POINT pt) const
  3100. {
  3101. if( pParent == NULL ) pParent = GetRoot();
  3102. ASSERT(pParent);
  3103. return pParent->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3104. }
  3105. CControlUI* CPaintManagerUI::FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const
  3106. {
  3107. if( pParent == NULL ) pParent = GetRoot();
  3108. ASSERT(pParent);
  3109. return pParent->FindControl(__FindControlFromName, (LPVOID)pstrName, UIFIND_ALL);
  3110. }
  3111. CControlUI* CPaintManagerUI::FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex)
  3112. {
  3113. if( pParent == NULL ) pParent = GetRoot();
  3114. ASSERT(pParent);
  3115. m_aFoundControls.Resize(iIndex + 1);
  3116. return pParent->FindControl(__FindControlFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3117. }
  3118. CDuiPtrArray* CPaintManagerUI::FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass)
  3119. {
  3120. if( pParent == NULL ) pParent = GetRoot();
  3121. ASSERT(pParent);
  3122. m_aFoundControls.Empty();
  3123. pParent->FindControl(__FindControlsFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3124. return &m_aFoundControls;
  3125. }
  3126. CDuiPtrArray* CPaintManagerUI::GetFoundControls()
  3127. {
  3128. return &m_aFoundControls;
  3129. }
  3130. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
  3131. {
  3132. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
  3133. const CDuiString& sName = pThis->GetName();
  3134. if( sName.IsEmpty() ) return NULL;
  3135. // Add this control to the hash list
  3136. pManager->m_mNameHash.Set(sName, pThis);
  3137. return NULL; // Attempt to add all controls
  3138. }
  3139. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromCount(CControlUI* /*pThis*/, LPVOID pData)
  3140. {
  3141. int* pnCount = static_cast<int*>(pData);
  3142. (*pnCount)++;
  3143. return NULL; // Count all controls
  3144. }
  3145. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromPoint(CControlUI* pThis, LPVOID pData)
  3146. {
  3147. LPPOINT pPoint = static_cast<LPPOINT>(pData);
  3148. return ::PtInRect(&pThis->GetPos(), *pPoint) ? pThis : NULL;
  3149. }
  3150. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromTab(CControlUI* pThis, LPVOID pData)
  3151. {
  3152. FINDTABINFO* pInfo = static_cast<FINDTABINFO*>(pData);
  3153. if( pInfo->pFocus == pThis ) {
  3154. if( pInfo->bForward ) pInfo->bNextIsIt = true;
  3155. return pInfo->bForward ? NULL : pInfo->pLast;
  3156. }
  3157. if( (pThis->GetControlFlags() & UIFLAG_TABSTOP) == 0 ) return NULL;
  3158. pInfo->pLast = pThis;
  3159. if( pInfo->bNextIsIt ) return pThis;
  3160. if( pInfo->pFocus == NULL ) return pThis;
  3161. return NULL; // Examine all controls
  3162. }
  3163. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromShortcut(CControlUI* pThis, LPVOID pData)
  3164. {
  3165. if( !pThis->IsVisible() ) return NULL;
  3166. FINDSHORTCUT* pFS = static_cast<FINDSHORTCUT*>(pData);
  3167. if( pFS->ch == toupper(pThis->GetShortcut()) ) pFS->bPickNext = true;
  3168. if( _tcsstr(pThis->GetClass(), DUI_CTR_LABEL) != NULL ) return NULL; // Labels never get focus!
  3169. return pFS->bPickNext ? pThis : NULL;
  3170. }
  3171. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromName(CControlUI* pThis, LPVOID pData)
  3172. {
  3173. LPCTSTR pstrName = static_cast<LPCTSTR>(pData);
  3174. const CDuiString& sName = pThis->GetName();
  3175. if( sName.IsEmpty() ) return NULL;
  3176. return (_tcsicmp(sName, pstrName) == 0) ? pThis : NULL;
  3177. }
  3178. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromClass(CControlUI* pThis, LPVOID pData)
  3179. {
  3180. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  3181. LPCTSTR pType = pThis->GetClass();
  3182. CDuiPtrArray* pFoundControls = pThis->GetManager()->GetFoundControls();
  3183. if( _tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0 ) {
  3184. int iIndex = -1;
  3185. while( pFoundControls->GetAt(++iIndex) != NULL ) ;
  3186. if( iIndex < pFoundControls->GetSize() ) pFoundControls->SetAt(iIndex, pThis);
  3187. }
  3188. if( pFoundControls->GetAt(pFoundControls->GetSize() - 1) != NULL ) return pThis;
  3189. return NULL;
  3190. }
  3191. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromClass(CControlUI* pThis, LPVOID pData)
  3192. {
  3193. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  3194. LPCTSTR pType = pThis->GetClass();
  3195. if( _tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0 )
  3196. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  3197. return NULL;
  3198. }
  3199. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromUpdate(CControlUI* pThis, LPVOID pData)
  3200. {
  3201. if( pThis->IsUpdateNeeded() ) {
  3202. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  3203. return pThis;
  3204. }
  3205. return NULL;
  3206. }
  3207. bool CPaintManagerUI::TranslateAccelerator(LPMSG pMsg)
  3208. {
  3209. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  3210. {
  3211. LRESULT lResult = static_cast<ITranslateAccelerator *>(m_aTranslateAccelerator[i])->TranslateAccelerator(pMsg);
  3212. if( lResult == S_OK ) return true;
  3213. }
  3214. return false;
  3215. }
  3216. bool CPaintManagerUI::TranslateMessage(const LPMSG pMsg)
  3217. {
  3218. // Pretranslate Message takes care of system-wide messages, such as
  3219. // tabbing and shortcut key-combos. We'll look for all messages for
  3220. // each window and any child control attached.
  3221. UINT uStyle = GetWindowStyle(pMsg->hwnd);
  3222. UINT uChildRes = uStyle & WS_CHILD;
  3223. LRESULT lRes = 0;
  3224. if (uChildRes != 0)
  3225. {
  3226. HWND hWndParent = ::GetParent(pMsg->hwnd);
  3227. //code by redrain 2014.12.3,解决edit和webbrowser按tab无法切换焦点的bug
  3228. // for( int i = 0; i < m_aPreMessages.GetSize(); i++ )
  3229. for( int i = m_aPreMessages.GetSize() - 1; i >= 0 ; --i )
  3230. {
  3231. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  3232. HWND hTempParent = hWndParent;
  3233. while(hTempParent)
  3234. {
  3235. if(pMsg->hwnd == pT->GetPaintWindow() || hTempParent == pT->GetPaintWindow())
  3236. {
  3237. if (pT->TranslateAccelerator(pMsg))
  3238. return true;
  3239. pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes);
  3240. // if( pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes) )
  3241. // return true;
  3242. //
  3243. // return false;
  3244. }
  3245. hTempParent = GetParent(hTempParent);
  3246. }
  3247. }
  3248. }
  3249. else
  3250. {
  3251. for( int i = 0; i < m_aPreMessages.GetSize(); i++ )
  3252. {
  3253. int size = m_aPreMessages.GetSize();
  3254. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  3255. if(pMsg->hwnd == pT->GetPaintWindow())
  3256. {
  3257. if (pT->TranslateAccelerator(pMsg))
  3258. return true;
  3259. if( pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes) )
  3260. return true;
  3261. return false;
  3262. }
  3263. }
  3264. }
  3265. return false;
  3266. }
  3267. bool CPaintManagerUI::AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator)
  3268. {
  3269. ASSERT(m_aTranslateAccelerator.Find(pTranslateAccelerator) < 0);
  3270. return m_aTranslateAccelerator.Add(pTranslateAccelerator);
  3271. }
  3272. bool CPaintManagerUI::RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator)
  3273. {
  3274. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  3275. {
  3276. if (static_cast<ITranslateAccelerator *>(m_aTranslateAccelerator[i]) == pTranslateAccelerator)
  3277. {
  3278. return m_aTranslateAccelerator.Remove(i);
  3279. }
  3280. }
  3281. return false;
  3282. }
  3283. void CPaintManagerUI::UsedVirtualWnd(bool bUsed)
  3284. {
  3285. m_bUsedVirtualWnd = bUsed;
  3286. }
  3287. } // namespace DuiLib