UIManager.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. #ifndef __UIMANAGER_H__
  2. #define __UIMANAGER_H__
  3. #pragma once
  4. namespace DuiLib {
  5. /////////////////////////////////////////////////////////////////////////////////////
  6. //
  7. class CControlUI;
  8. /////////////////////////////////////////////////////////////////////////////////////
  9. //
  10. typedef enum EVENTTYPE_UI
  11. {
  12. UIEVENT__FIRST = 1,
  13. UIEVENT__KEYBEGIN,
  14. UIEVENT_KEYDOWN,
  15. UIEVENT_KEYUP,
  16. UIEVENT_CHAR,
  17. UIEVENT_SYSKEY,
  18. UIEVENT__KEYEND,
  19. UIEVENT__MOUSEBEGIN,
  20. UIEVENT_MOUSEMOVE,
  21. UIEVENT_MOUSELEAVE,
  22. UIEVENT_MOUSEENTER,
  23. UIEVENT_MOUSEHOVER,
  24. UIEVENT_BUTTONDOWN,
  25. UIEVENT_BUTTONUP,
  26. UIEVENT_RBUTTONDOWN,
  27. UIEVENT_DBLCLICK,
  28. UIEVENT_CONTEXTMENU,
  29. UIEVENT_SCROLLWHEEL,
  30. UIEVENT__MOUSEEND,
  31. UIEVENT_KILLFOCUS,
  32. UIEVENT_SETFOCUS,
  33. UIEVENT_WINDOWSIZE,
  34. UIEVENT_SETCURSOR,
  35. UIEVENT_TIMER,
  36. UIEVENT_NOTIFY,
  37. UIEVENT_COMMAND,
  38. UIEVENT__LAST,
  39. };
  40. /////////////////////////////////////////////////////////////////////////////////////
  41. //
  42. // Flags for CControlUI::GetControlFlags()
  43. #define UIFLAG_TABSTOP 0x00000001
  44. #define UIFLAG_SETCURSOR 0x00000002
  45. #define UIFLAG_WANTRETURN 0x00000004
  46. // Flags for FindControl()
  47. #define UIFIND_ALL 0x00000000
  48. #define UIFIND_VISIBLE 0x00000001
  49. #define UIFIND_ENABLED 0x00000002
  50. #define UIFIND_HITTEST 0x00000004
  51. #define UIFIND_UPDATETEST 0x00000008
  52. #define UIFIND_TOP_FIRST 0x00000010
  53. #define UIFIND_ME_FIRST 0x80000000
  54. // Flags for the CDialogLayout stretching
  55. #define UISTRETCH_NEWGROUP 0x00000001
  56. #define UISTRETCH_NEWLINE 0x00000002
  57. #define UISTRETCH_MOVE_X 0x00000004
  58. #define UISTRETCH_MOVE_Y 0x00000008
  59. #define UISTRETCH_SIZE_X 0x00000010
  60. #define UISTRETCH_SIZE_Y 0x00000020
  61. // Flags used for controlling the paint
  62. #define UISTATE_FOCUSED 0x00000001
  63. #define UISTATE_SELECTED 0x00000002
  64. #define UISTATE_DISABLED 0x00000004
  65. #define UISTATE_HOT 0x00000008
  66. #define UISTATE_PUSHED 0x00000010
  67. #define UISTATE_READONLY 0x00000020
  68. #define UISTATE_CAPTURED 0x00000040
  69. /////////////////////////////////////////////////////////////////////////////////////
  70. //
  71. typedef struct UILIB_API tagTFontInfo
  72. {
  73. HFONT hFont;
  74. CDuiString sFontName;
  75. int iSize;
  76. bool bBold;
  77. bool bUnderline;
  78. bool bItalic;
  79. TEXTMETRIC tm;
  80. } TFontInfo;
  81. typedef struct UILIB_API tagTImageInfo
  82. {
  83. HBITMAP hBitmap;
  84. LPBYTE pBits;
  85. LPBYTE pSrcBits;
  86. int nX;
  87. int nY;
  88. bool bAlpha;
  89. bool bUseHSL;
  90. CDuiString sResType;
  91. DWORD dwMask;
  92. } TImageInfo;
  93. typedef struct UILIB_API tagTDrawInfo
  94. {
  95. tagTDrawInfo();
  96. tagTDrawInfo(LPCTSTR lpsz);
  97. void Clear();
  98. CDuiString sDrawString;
  99. CDuiString sImageName;
  100. bool bLoaded;
  101. const TImageInfo* pImageInfo;
  102. RECT rcDestOffset;
  103. RECT rcBmpPart;
  104. RECT rcCorner;
  105. BYTE uFade;
  106. bool bHole;
  107. bool bTiledX;
  108. bool bTiledY;
  109. } TDrawInfo;
  110. typedef struct UILIB_API tagTPercentInfo
  111. {
  112. double left;
  113. double top;
  114. double right;
  115. double bottom;
  116. } TPercentInfo;
  117. typedef struct UILIB_API tagTResInfo
  118. {
  119. DWORD m_dwDefaultDisabledColor;
  120. DWORD m_dwDefaultFontColor;
  121. DWORD m_dwDefaultLinkFontColor;
  122. DWORD m_dwDefaultLinkHoverFontColor;
  123. DWORD m_dwDefaultSelectedBkColor;
  124. TFontInfo m_DefaultFontInfo;
  125. CStdStringPtrMap m_CustomFonts;
  126. CStdStringPtrMap m_ImageHash;
  127. CStdStringPtrMap m_AttrHash;
  128. CStdStringPtrMap m_MultiLanguageHash;
  129. } TResInfo;
  130. // Structure for notifications from the system
  131. // to the control implementation.
  132. typedef struct UILIB_API tagTEventUI
  133. {
  134. int Type;
  135. CControlUI* pSender;
  136. DWORD dwTimestamp;
  137. POINT ptMouse;
  138. TCHAR chKey;
  139. WORD wKeyState;
  140. WPARAM wParam;
  141. LPARAM lParam;
  142. } TEventUI;
  143. // Listener interface
  144. class UILIB_API INotifyUI
  145. {
  146. public:
  147. virtual void Notify(TNotifyUI& msg) = 0;
  148. };
  149. // MessageFilter interface
  150. class UILIB_API IMessageFilterUI
  151. {
  152. public:
  153. virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) = 0;
  154. };
  155. class UILIB_API ITranslateAccelerator
  156. {
  157. public:
  158. virtual LRESULT TranslateAccelerator(MSG *pMsg) = 0;
  159. };
  160. /////////////////////////////////////////////////////////////////////////////////////
  161. //
  162. typedef CControlUI* (*LPCREATECONTROL)(LPCTSTR pstrType);
  163. class UILIB_API CPaintManagerUI
  164. {
  165. public:
  166. CPaintManagerUI();
  167. ~CPaintManagerUI();
  168. public:
  169. //add
  170. CShadowUI* GetShadow();
  171. void Init(HWND hWnd, LPCTSTR pstrName = NULL);
  172. bool IsUpdateNeeded() const;
  173. void NeedUpdate();
  174. void Invalidate();
  175. void Invalidate(RECT& rcItem);
  176. LPCTSTR GetName() const;
  177. HDC GetPaintDC() const;
  178. //add by Hong
  179. HDC GetOffscreenDC() const;
  180. HWND GetPaintWindow() const;
  181. HWND GetTooltipWindow() const;
  182. int GetTooltipWindowWidth() const;
  183. void SetTooltipWindowWidth(int iWidth);
  184. int GetHoverTime() const;
  185. void SetHoverTime(int iTime);
  186. POINT GetMousePos() const;
  187. SIZE GetClientSize() const;
  188. SIZE GetInitSize();
  189. void SetInitSize(int cx, int cy);
  190. RECT& GetSizeBox();
  191. void SetSizeBox(RECT& rcSizeBox);
  192. RECT& GetCaptionRect();
  193. void SetCaptionRect(RECT& rcCaption);
  194. SIZE GetRoundCorner() const;
  195. void SetRoundCorner(int cx, int cy);
  196. SIZE GetMinInfo() const;
  197. void SetMinInfo(int cx, int cy);
  198. SIZE GetMaxInfo() const;
  199. void SetMaxInfo(int cx, int cy);
  200. bool IsShowUpdateRect() const;
  201. void SetShowUpdateRect(bool show);
  202. BYTE GetOpacity() const;
  203. void SetOpacity(BYTE nOpacity);
  204. bool IsLayered();
  205. void SetLayered(bool bLayered);
  206. RECT& GetLayeredInset();
  207. void SetLayeredInset(RECT& rcLayeredInset);
  208. BYTE GetLayeredOpacity();
  209. void SetLayeredOpacity(BYTE nOpacity);
  210. LPCTSTR GetLayeredImage();
  211. void SetLayeredImage(LPCTSTR pstrImage);
  212. static HINSTANCE GetInstance();
  213. static CDuiString GetInstancePath();
  214. static CDuiString GetCurrentPath();
  215. static HINSTANCE GetResourceDll();
  216. static const CDuiString& GetResourcePath();
  217. static const CDuiString& GetResourceZip();
  218. static bool IsCachedResourceZip();
  219. static HANDLE GetResourceZipHandle();
  220. static void SetInstance(HINSTANCE hInst);
  221. static void SetCurrentPath(LPCTSTR pStrPath);
  222. static void SetResourceDll(HINSTANCE hInst);
  223. static void SetResourcePath(LPCTSTR pStrPath);
  224. static void SetResourceZip(LPVOID pVoid, unsigned int len);
  225. static void SetResourceZip(LPCTSTR pstrZip, bool bCachedResourceZip = false);
  226. static bool GetHSL(short* H, short* S, short* L);
  227. static void SetHSL(bool bUseHSL, short H, short S, short L); // H:0~360, S:0~200, L:0~200
  228. static void ReloadSkin();
  229. static CPaintManagerUI* GetPaintManager(LPCTSTR pstrName);
  230. static CStdPtrArray* GetPaintManagers();
  231. static bool LoadPlugin(LPCTSTR pstrModuleName);
  232. static CStdPtrArray* GetPlugins();
  233. bool IsForceUseSharedRes() const;
  234. void SetForceUseSharedRes(bool bForce);
  235. DWORD GetDefaultDisabledColor() const;
  236. void SetDefaultDisabledColor(DWORD dwColor, bool bShared = false);
  237. DWORD GetDefaultFontColor() const;
  238. void SetDefaultFontColor(DWORD dwColor, bool bShared = false);
  239. DWORD GetDefaultLinkFontColor() const;
  240. void SetDefaultLinkFontColor(DWORD dwColor, bool bShared = false);
  241. DWORD GetDefaultLinkHoverFontColor() const;
  242. void SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared = false);
  243. DWORD GetDefaultSelectedBkColor() const;
  244. void SetDefaultSelectedBkColor(DWORD dwColor, bool bShared = false);
  245. TFontInfo* GetDefaultFontInfo();
  246. void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  247. DWORD GetCustomFontCount(bool bShared = false) const;
  248. HFONT AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  249. HFONT GetFont(int id);
  250. HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
  251. int GetFontIndex(HFONT hFont, bool bShared = false);
  252. int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  253. void RemoveFont(HFONT hFont, bool bShared = false);
  254. void RemoveFont(int id, bool bShared = false);
  255. void RemoveAllFonts(bool bShared = false);
  256. TFontInfo* GetFontInfo(int id);
  257. TFontInfo* GetFontInfo(HFONT hFont);
  258. const TImageInfo* GetImage(LPCTSTR bitmap);
  259. const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false);
  260. const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false);
  261. const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false);
  262. void RemoveImage(LPCTSTR bitmap, bool bShared = false);
  263. void RemoveAllImages(bool bShared = false);
  264. static void ReloadSharedImages();
  265. void ReloadImages();
  266. void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared = false);
  267. LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
  268. bool RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared = false);
  269. void RemoveAllDefaultAttributeList(bool bShared = false);
  270. void AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr);
  271. LPCTSTR GetWindowCustomAttribute(LPCTSTR pstrName) const;
  272. bool RemoveWindowCustomAttribute(LPCTSTR pstrName);
  273. void RemoveAllWindowCustomAttribute();
  274. static void AddMultiLanguageString(int id, LPCTSTR pStrMultiLanguage);
  275. static LPCTSTR GetMultiLanguageString(int id);
  276. static bool RemoveMultiLanguageString(int id);
  277. static void RemoveAllMultiLanguageString();
  278. static void ProcessMultiLanguageTokens(CDuiString& pStrMultiLanguage);
  279. bool AttachDialog(CControlUI* pControl);
  280. bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
  281. void ReapObjects(CControlUI* pControl);
  282. bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  283. CStdPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
  284. void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  285. void RemoveAllOptionGroups();
  286. CControlUI* GetFocus() const;
  287. void SetFocus(CControlUI* pControl, bool bFocusWnd=true);
  288. void SetFocusNeeded(CControlUI* pControl);
  289. bool SetNextTabControl(bool bForward = true);
  290. bool SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse);
  291. bool KillTimer(CControlUI* pControl, UINT nTimerID);
  292. void KillTimer(CControlUI* pControl);
  293. void RemoveAllTimers();
  294. void SetCapture();
  295. void ReleaseCapture();
  296. bool IsCaptured();
  297. bool IsPainting();
  298. void SetPainting(bool bIsPainting);
  299. bool AddNotifier(INotifyUI* pControl);
  300. bool RemoveNotifier(INotifyUI* pControl);
  301. void SendNotify(TNotifyUI& Msg, bool bAsync = false, bool bEnableRepeat = true);
  302. void SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false, bool bEnableRepeat = true);
  303. bool AddPreMessageFilter(IMessageFilterUI* pFilter);
  304. bool RemovePreMessageFilter(IMessageFilterUI* pFilter);
  305. bool AddMessageFilter(IMessageFilterUI* pFilter);
  306. bool RemoveMessageFilter(IMessageFilterUI* pFilter);
  307. int GetPostPaintCount() const;
  308. bool AddPostPaint(CControlUI* pControl);
  309. bool RemovePostPaint(CControlUI* pControl);
  310. bool SetPostPaintIndex(CControlUI* pControl, int iIndex);
  311. int GetNativeWindowCount() const;
  312. bool AddNativeWindow(CControlUI* pControl, HWND hChildWnd);
  313. bool RemoveNativeWindow(HWND hChildWnd);
  314. void AddDelayedCleanup(CControlUI* pControl);
  315. bool AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  316. bool RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  317. bool TranslateAccelerator(LPMSG pMsg);
  318. CControlUI* GetRoot() const;
  319. CControlUI* FindControl(POINT pt) const;
  320. CControlUI* FindControl(LPCTSTR pstrName) const;
  321. CControlUI* FindSubControlByPoint(CControlUI* pParent, POINT pt) const;
  322. CControlUI* FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const;
  323. CControlUI* FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex = 0);
  324. CStdPtrArray* FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass);
  325. static void MessageLoop();
  326. static bool TranslateMessage(const LPMSG pMsg);
  327. static void Term();
  328. bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  329. bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  330. void UsedVirtualWnd(bool bUsed);
  331. private:
  332. CStdPtrArray* GetFoundControls();
  333. static CControlUI* CALLBACK __FindControlFromNameHash(CControlUI* pThis, LPVOID pData);
  334. static CControlUI* CALLBACK __FindControlFromCount(CControlUI* pThis, LPVOID pData);
  335. static CControlUI* CALLBACK __FindControlFromPoint(CControlUI* pThis, LPVOID pData);
  336. static CControlUI* CALLBACK __FindControlFromTab(CControlUI* pThis, LPVOID pData);
  337. static CControlUI* CALLBACK __FindControlFromShortcut(CControlUI* pThis, LPVOID pData);
  338. static CControlUI* CALLBACK __FindControlFromName(CControlUI* pThis, LPVOID pData);
  339. static CControlUI* CALLBACK __FindControlFromClass(CControlUI* pThis, LPVOID pData);
  340. static CControlUI* CALLBACK __FindControlsFromClass(CControlUI* pThis, LPVOID pData);
  341. static CControlUI* CALLBACK __FindControlsFromUpdate(CControlUI* pThis, LPVOID pData);
  342. static void AdjustSharedImagesHSL();
  343. void AdjustImagesHSL();
  344. void PostAsyncNotify();
  345. private:
  346. //add
  347. CShadowUI m_shadow;
  348. CDuiString m_sName;
  349. HWND m_hWndPaint;
  350. HDC m_hDcPaint;
  351. HDC m_hDcOffscreen;
  352. HDC m_hDcBackground;
  353. HBITMAP m_hbmpOffscreen;
  354. COLORREF* m_pOffscreenBits;
  355. HBITMAP m_hbmpBackground;
  356. COLORREF* m_pBackgroundBits;
  357. int m_iTooltipWidth;
  358. HWND m_hwndTooltip;
  359. TOOLINFO m_ToolTip;
  360. int m_iHoverTime;
  361. bool m_bShowUpdateRect;
  362. //
  363. CControlUI* m_pRoot;
  364. CControlUI* m_pFocus;
  365. CControlUI* m_pEventHover;
  366. CControlUI* m_pEventClick;
  367. CControlUI* m_pEventKey;
  368. //
  369. POINT m_ptLastMousePos;
  370. SIZE m_szMinWindow;
  371. SIZE m_szMaxWindow;
  372. SIZE m_szInitWindowSize;
  373. RECT m_rcSizeBox;
  374. SIZE m_szRoundCorner;
  375. RECT m_rcCaption;
  376. UINT m_uTimerID;
  377. bool m_bFirstLayout;
  378. bool m_bUpdateNeeded;
  379. bool m_bFocusNeeded;
  380. bool m_bOffscreenPaint;
  381. BYTE m_nOpacity;
  382. bool m_bLayered;
  383. RECT m_rcLayeredInset;
  384. bool m_bLayeredChanged;
  385. RECT m_rcLayeredUpdate;
  386. TDrawInfo m_diLayered;
  387. bool m_bMouseTracking;
  388. bool m_bMouseCapture;
  389. bool m_bIsPainting;
  390. bool m_bUsedVirtualWnd;
  391. bool m_bAsyncNotifyPosted;
  392. //
  393. CStdPtrArray m_aNotifiers;
  394. CStdPtrArray m_aTimers;
  395. CStdPtrArray m_aPreMessageFilters;
  396. CStdPtrArray m_aMessageFilters;
  397. CStdPtrArray m_aPostPaintControls;
  398. CStdPtrArray m_aNativeWindow;
  399. CStdPtrArray m_aNativeWindowControl;
  400. CStdPtrArray m_aDelayedCleanup;
  401. CStdPtrArray m_aAsyncNotify;
  402. CStdPtrArray m_aFoundControls;
  403. CStdStringPtrMap m_mNameHash;
  404. CStdStringPtrMap m_mWindowCustomAttrHash;
  405. CStdStringPtrMap m_mOptionGroup;
  406. //
  407. bool m_bForceUseSharedRes;
  408. TResInfo m_ResInfo;
  409. //
  410. static HINSTANCE m_hResourceInstance;
  411. static CDuiString m_pStrResourcePath;
  412. static CDuiString m_pStrResourceZip;
  413. static HANDLE m_hResourceZip;
  414. static bool m_bCachedResourceZip;
  415. static TResInfo m_SharedResInfo;
  416. static HINSTANCE m_hInstance;
  417. static bool m_bUseHSL;
  418. static short m_H;
  419. static short m_S;
  420. static short m_L;
  421. static CStdPtrArray m_aPreMessages;
  422. static CStdPtrArray m_aPlugins;
  423. public:
  424. CStdPtrArray m_aTranslateAccelerator;
  425. };
  426. } // namespace DuiLib
  427. #endif // __UIMANAGER_H__