UIManager.cpp 102 KB

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