UIManager.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. #ifndef __UIMANAGER_H__
  2. #define __UIMANAGER_H__
  3. #pragma once
  4. namespace DuiLib {
  5. /////////////////////////////////////////////////////////////////////////////////////
  6. //
  7. class CControlUI;
  8. /////////////////////////////////////////////////////////////////////////////////////
  9. //
  10. 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 DUILIB_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 DUILIB_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 DUILIB_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 rcScale9;
  105. BYTE uFade;
  106. bool bHole;
  107. bool bTiledX;
  108. bool bTiledY;
  109. } TDrawInfo;
  110. typedef struct DUILIB_API tagTPercentInfo
  111. {
  112. double left;
  113. double top;
  114. double right;
  115. double bottom;
  116. } TPercentInfo;
  117. typedef struct DUILIB_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. CDuiStringPtrMap m_CustomFonts;
  126. CDuiStringPtrMap m_ImageHash;
  127. CDuiStringPtrMap m_AttrHash;
  128. CDuiStringPtrMap m_MultiLanguageHash;
  129. } TResInfo;
  130. // Structure for notifications from the system
  131. // to the control implementation.
  132. typedef struct DUILIB_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 DUILIB_API INotifyUI
  145. {
  146. public:
  147. virtual void Notify(TNotifyUI& msg) = 0;
  148. };
  149. // MessageFilter interface
  150. class DUILIB_API IMessageFilterUI
  151. {
  152. public:
  153. virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) = 0;
  154. };
  155. class DUILIB_API ITranslateAccelerator
  156. {
  157. public:
  158. virtual LRESULT TranslateAccelerator(MSG *pMsg) = 0;
  159. };
  160. /////////////////////////////////////////////////////////////////////////////////////
  161. //
  162. typedef CControlUI* (*LPCREATECONTROL)(LPCTSTR pstrType);
  163. class DUILIB_API CPaintManagerUI
  164. {
  165. public:
  166. CPaintManagerUI();
  167. ~CPaintManagerUI();
  168. public:
  169. void Init(HWND hWnd, LPCTSTR pstrName = NULL);
  170. bool IsUpdateNeeded() const;
  171. void NeedUpdate();
  172. void Invalidate();
  173. void Invalidate(RECT& rcItem);
  174. LPCTSTR GetName() const;
  175. HDC GetPaintDC() const;
  176. HBITMAP GetPaintOffscreenBitmap();
  177. HWND GetPaintWindow() const;
  178. HWND GetTooltipWindow() const;
  179. int GetTooltipWindowWidth() const;
  180. void SetTooltipWindowWidth(int iWidth);
  181. int GetHoverTime() const;
  182. void SetHoverTime(int iTime);
  183. POINT GetMousePos() const;
  184. SIZE GetClientSize() const;
  185. SIZE GetInitSize();
  186. void SetInitSize(int cx, int cy);
  187. RECT& GetSizeBox();
  188. void SetSizeBox(RECT& rcSizeBox);
  189. RECT& GetCaptionRect();
  190. void SetCaptionRect(RECT& rcCaption);
  191. SIZE GetRoundCorner() const;
  192. void SetRoundCorner(int cx, int cy);
  193. SIZE GetMinInfo() const;
  194. void SetMinInfo(int cx, int cy);
  195. SIZE GetMaxInfo() const;
  196. void SetMaxInfo(int cx, int cy);
  197. bool IsShowUpdateRect() const;
  198. void SetShowUpdateRect(bool show);
  199. bool IsNoActivate();
  200. void SetNoActivate(bool bNoActivate);
  201. BYTE GetOpacity() const;
  202. void SetOpacity(BYTE nOpacity);
  203. bool IsLayered();
  204. void SetLayered(bool bLayered);
  205. RECT& GetLayeredInset();
  206. void SetLayeredInset(RECT& rcLayeredInset);
  207. BYTE GetLayeredOpacity();
  208. void SetLayeredOpacity(BYTE nOpacity);
  209. LPCTSTR GetLayeredImage();
  210. void SetLayeredImage(LPCTSTR pstrImage);
  211. static HINSTANCE GetInstance();
  212. static CDuiString GetInstancePath();
  213. static CDuiString GetCurrentPath();
  214. static HINSTANCE GetResourceDll();
  215. static const CDuiString& GetResourcePath();
  216. static const CDuiString& GetResourceZip();
  217. static bool IsCachedResourceZip();
  218. static HANDLE GetResourceZipHandle();
  219. static void SetInstance(HINSTANCE hInst);
  220. static void SetCurrentPath(LPCTSTR pStrPath);
  221. static void SetResourceDll(HINSTANCE hInst);
  222. static void SetResourcePath(LPCTSTR pStrPath);
  223. static void SetResourceZip(LPVOID pVoid, unsigned int len);
  224. static void SetResourceZip(LPCTSTR pstrZip, bool bCachedResourceZip = false);
  225. static bool GetHSL(short* H, short* S, short* L);
  226. static void SetHSL(bool bUseHSL, short H, short S, short L); // H:0~360, S:0~200, L:0~200
  227. static void ReloadSkin();
  228. static CPaintManagerUI* GetPaintManager(LPCTSTR pstrName);
  229. static CDuiPtrArray* GetPaintManagers();
  230. static bool LoadPlugin(LPCTSTR pstrModuleName);
  231. static CDuiPtrArray* GetPlugins();
  232. bool IsForceUseSharedRes() const;
  233. void SetForceUseSharedRes(bool bForce);
  234. DWORD GetDefaultDisabledColor() const;
  235. void SetDefaultDisabledColor(DWORD dwColor, bool bShared = false);
  236. DWORD GetDefaultFontColor() const;
  237. void SetDefaultFontColor(DWORD dwColor, bool bShared = false);
  238. DWORD GetDefaultLinkFontColor() const;
  239. void SetDefaultLinkFontColor(DWORD dwColor, bool bShared = false);
  240. DWORD GetDefaultLinkHoverFontColor() const;
  241. void SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared = false);
  242. DWORD GetDefaultSelectedBkColor() const;
  243. void SetDefaultSelectedBkColor(DWORD dwColor, bool bShared = false);
  244. TFontInfo* GetDefaultFontInfo();
  245. void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  246. DWORD GetCustomFontCount(bool bShared = false) const;
  247. HFONT AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  248. HFONT GetFont(int id);
  249. HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
  250. int GetFontIndex(HFONT hFont, bool bShared = false);
  251. int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
  252. void RemoveFont(HFONT hFont, bool bShared = false);
  253. void RemoveFont(int id, bool bShared = false);
  254. void RemoveAllFonts(bool bShared = false);
  255. TFontInfo* GetFontInfo(int id);
  256. TFontInfo* GetFontInfo(HFONT hFont);
  257. const TImageInfo* GetImage(LPCTSTR bitmap);
  258. const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false);
  259. const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false);
  260. const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false);
  261. void RemoveImage(LPCTSTR bitmap, bool bShared = false);
  262. void RemoveAllImages(bool bShared = false);
  263. static void ReloadSharedImages();
  264. void ReloadImages();
  265. void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared = false);
  266. LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
  267. bool RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared = false);
  268. void RemoveAllDefaultAttributeList(bool bShared = false);
  269. void AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr);
  270. LPCTSTR GetWindowCustomAttribute(LPCTSTR pstrName) const;
  271. bool RemoveWindowCustomAttribute(LPCTSTR pstrName);
  272. void RemoveAllWindowCustomAttribute();
  273. CDuiString GetWindowAttribute(LPCTSTR pstrName);
  274. void SetWindowAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  275. CDuiString GetWindowAttributeList(bool bIgnoreDefault = true);
  276. void SetWindowAttributeList(LPCTSTR pstrList);
  277. bool RemoveWindowAttribute(LPCTSTR pstrName);
  278. CDuiString GetWindowXML();
  279. static void AddMultiLanguageString(int id, LPCTSTR pStrMultiLanguage);
  280. static LPCTSTR GetMultiLanguageString(int id);
  281. static bool RemoveMultiLanguageString(int id);
  282. static void RemoveAllMultiLanguageString();
  283. static void ProcessMultiLanguageTokens(CDuiString& pStrMultiLanguage);
  284. bool AttachDialog(CControlUI* pControl);
  285. bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
  286. bool RenameControl(CControlUI* pControl, LPCTSTR pstrName);
  287. void ReapObjects(CControlUI* pControl);
  288. bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  289. CDuiPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
  290. void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  291. void RemoveAllOptionGroups();
  292. CControlUI* GetFocus() const;
  293. void SetFocus(CControlUI* pControl, bool bFocusWnd=true);
  294. void SetFocusNeeded(CControlUI* pControl);
  295. bool SetNextTabControl(bool bForward = true);
  296. bool SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse);
  297. bool KillTimer(CControlUI* pControl, UINT nTimerID);
  298. void KillTimer(CControlUI* pControl);
  299. void RemoveAllTimers();
  300. void SetCapture();
  301. void ReleaseCapture();
  302. bool IsCaptured();
  303. bool IsPainting();
  304. void SetPainting(bool bIsPainting);
  305. bool AddNotifier(INotifyUI* pControl);
  306. bool RemoveNotifier(INotifyUI* pControl);
  307. void SendNotify(TNotifyUI& Msg, bool bAsync = false, bool bEnableRepeat = true);
  308. void SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false, bool bEnableRepeat = true);
  309. bool AddPreMessageFilter(IMessageFilterUI* pFilter);
  310. bool RemovePreMessageFilter(IMessageFilterUI* pFilter);
  311. bool AddMessageFilter(IMessageFilterUI* pFilter);
  312. bool RemoveMessageFilter(IMessageFilterUI* pFilter);
  313. int GetPostPaintCount() const;
  314. bool AddPostPaint(CControlUI* pControl);
  315. bool RemovePostPaint(CControlUI* pControl);
  316. bool SetPostPaintIndex(CControlUI* pControl, int iIndex);
  317. int GetNativeWindowCount() const;
  318. RECT GetNativeWindowRect(HWND hChildWnd);
  319. bool AddNativeWindow(CControlUI* pControl, HWND hChildWnd);
  320. bool RemoveNativeWindow(HWND hChildWnd);
  321. void AddDelayedCleanup(CControlUI* pControl);
  322. void AddMouseLeaveNeeded(CControlUI* pControl);
  323. bool RemoveMouseLeaveNeeded(CControlUI* pControl);
  324. bool AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  325. bool RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  326. bool TranslateAccelerator(LPMSG pMsg);
  327. CControlUI* GetRoot() const;
  328. CControlUI* FindControl(POINT pt) const;
  329. CControlUI* FindControl(LPCTSTR pstrName) const;
  330. CControlUI* FindSubControlByPoint(CControlUI* pParent, POINT pt) const;
  331. CControlUI* FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const;
  332. CControlUI* FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex = 0);
  333. CDuiPtrArray* FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass);
  334. static int MessageLoop();
  335. static bool TranslateMessage(const LPMSG pMsg);
  336. static void Term();
  337. bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  338. bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  339. void UsedVirtualWnd(bool bUsed);
  340. private:
  341. CDuiPtrArray* GetFoundControls();
  342. static CControlUI* CALLBACK __FindControlFromNameHash(CControlUI* pThis, LPVOID pData);
  343. static CControlUI* CALLBACK __FindControlFromCount(CControlUI* pThis, LPVOID pData);
  344. static CControlUI* CALLBACK __FindControlFromPoint(CControlUI* pThis, LPVOID pData);
  345. static CControlUI* CALLBACK __FindControlFromTab(CControlUI* pThis, LPVOID pData);
  346. static CControlUI* CALLBACK __FindControlFromShortcut(CControlUI* pThis, LPVOID pData);
  347. static CControlUI* CALLBACK __FindControlFromName(CControlUI* pThis, LPVOID pData);
  348. static CControlUI* CALLBACK __FindControlFromClass(CControlUI* pThis, LPVOID pData);
  349. static CControlUI* CALLBACK __FindControlsFromClass(CControlUI* pThis, LPVOID pData);
  350. static CControlUI* CALLBACK __FindControlsFromUpdate(CControlUI* pThis, LPVOID pData);
  351. static void AdjustSharedImagesHSL();
  352. void AdjustImagesHSL();
  353. void PostAsyncNotify();
  354. private:
  355. CDuiString m_sName;
  356. HWND m_hWndPaint;
  357. HDC m_hDcPaint;
  358. HDC m_hDcOffscreen;
  359. HDC m_hDcBackground;
  360. HBITMAP m_hbmpOffscreen;
  361. COLORREF* m_pOffscreenBits;
  362. HBITMAP m_hbmpBackground;
  363. COLORREF* m_pBackgroundBits;
  364. int m_iTooltipWidth;
  365. int m_iLastTooltipWidth;
  366. HWND m_hwndTooltip;
  367. TOOLINFO m_ToolTip;
  368. int m_iHoverTime;
  369. bool m_bNoActivate;
  370. bool m_bShowUpdateRect;
  371. //
  372. CControlUI* m_pRoot;
  373. CControlUI* m_pFocus;
  374. CControlUI* m_pEventHover;
  375. CControlUI* m_pEventClick;
  376. CControlUI* m_pEventKey;
  377. CControlUI* m_pLastToolTip;
  378. //
  379. POINT m_ptLastMousePos;
  380. SIZE m_szMinWindow;
  381. SIZE m_szMaxWindow;
  382. SIZE m_szInitWindowSize;
  383. RECT m_rcSizeBox;
  384. SIZE m_szRoundCorner;
  385. RECT m_rcCaption;
  386. UINT m_uTimerID;
  387. bool m_bFirstLayout;
  388. bool m_bUpdateNeeded;
  389. bool m_bFocusNeeded;
  390. bool m_bOffscreenPaint;
  391. BYTE m_nOpacity;
  392. bool m_bLayered;
  393. RECT m_rcLayeredInset;
  394. bool m_bLayeredChanged;
  395. RECT m_rcLayeredUpdate;
  396. TDrawInfo m_diLayered;
  397. bool m_bMouseTracking;
  398. bool m_bMouseCapture;
  399. bool m_bIsPainting;
  400. bool m_bUsedVirtualWnd;
  401. bool m_bAsyncNotifyPosted;
  402. //
  403. CDuiPtrArray m_aNotifiers;
  404. CDuiPtrArray m_aTimers;
  405. CDuiPtrArray m_aPreMessageFilters;
  406. CDuiPtrArray m_aMessageFilters;
  407. CDuiPtrArray m_aPostPaintControls;
  408. CDuiPtrArray m_aNativeWindow;
  409. CDuiPtrArray m_aNativeWindowControl;
  410. CDuiPtrArray m_aDelayedCleanup;
  411. CDuiPtrArray m_aAsyncNotify;
  412. CDuiPtrArray m_aFoundControls;
  413. CDuiPtrArray m_aNeedMouseLeaveNeeded;
  414. CDuiStringPtrMap m_mNameHash;
  415. CDuiStringPtrMap m_mWindowAttrHash;
  416. CDuiStringPtrMap m_mOptionGroup;
  417. //
  418. bool m_bForceUseSharedRes;
  419. TResInfo m_ResInfo;
  420. //
  421. static HINSTANCE m_hResourceInstance;
  422. static CDuiString m_pStrResourcePath;
  423. static CDuiString m_pStrResourceZip;
  424. static HANDLE m_hResourceZip;
  425. static bool m_bCachedResourceZip;
  426. static TResInfo m_SharedResInfo;
  427. static HINSTANCE m_hInstance;
  428. static bool m_bUseHSL;
  429. static short m_H;
  430. static short m_S;
  431. static short m_L;
  432. static CDuiPtrArray m_aPreMessages;
  433. static CDuiPtrArray m_aPlugins;
  434. public:
  435. CDuiPtrArray m_aTranslateAccelerator;
  436. };
  437. } // namespace DuiLib
  438. #endif // __UIMANAGER_H__