UIManager.cpp 113 KB

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