UIManager.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #ifndef __UIMANAGER_H__
  2. #define __UIMANAGER_H__
  3. #pragma once
  4. // 本头文件原本不含任何 include(符号由 StdAfx.h/UIlib.h 提供),
  5. // 但触屏相关的成员与状态里直接使用了 std::int64_t 与 std::vector,
  6. // 显式补齐以保证在 DuiLib 库工程(_WIN32_WINNT 兜底为 XP)里也能独立通过编译。
  7. #include <cstdint>
  8. #include <vector>
  9. namespace DuiLib {
  10. /////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. class CControlUI;
  13. class CRichEditUI;
  14. class CIDropTarget;
  15. /////////////////////////////////////////////////////////////////////////////////////
  16. //
  17. enum UILIB_RESTYPE
  18. {
  19. UILIB_FILE=1, // 来自磁盘文件
  20. UILIB_ZIP, // 来自磁盘zip压缩包
  21. UILIB_RESOURCE, // 来自资源
  22. UILIB_ZIPRESOURCE, // 来自资源的zip压缩包
  23. };
  24. /////////////////////////////////////////////////////////////////////////////////////
  25. //
  26. typedef enum EVENTTYPE_UI
  27. {
  28. UIEVENT__FIRST = 1,
  29. UIEVENT__KEYBEGIN,
  30. UIEVENT_KEYDOWN,
  31. UIEVENT_KEYUP,
  32. UIEVENT_CHAR,
  33. UIEVENT_SYSKEY,
  34. UIEVENT__KEYEND,
  35. UIEVENT__MOUSEBEGIN,
  36. UIEVENT_MOUSEMOVE,
  37. UIEVENT_MOUSELEAVE,
  38. UIEVENT_MOUSEENTER,
  39. UIEVENT_MOUSEHOVER,
  40. UIEVENT_BUTTONDOWN,
  41. UIEVENT_BUTTONUP,
  42. UIEVENT_RBUTTONDOWN,
  43. UIEVENT_RBUTTONUP,
  44. UIEVENT_MBUTTONDOWN,
  45. UIEVENT_MBUTTONUP,
  46. UIEVENT_DBLCLICK,
  47. UIEVENT_CONTEXTMENU,
  48. UIEVENT_SCROLLWHEEL,
  49. UIEVENT__MOUSEEND,
  50. // 触摸事件(NIM Duilib 模型)。必须排在 __MOUSEEND 之后:
  51. // CContainerUI::DoEvent 开头对 UIEVENT__MOUSEBEGIN~__MOUSEEND 区间做了 IsMouseEnabled 早退分支,
  52. // 排在区间之外才能保证触摸事件始终走正常派发与冒泡。
  53. UIEVENT__TOUCHBEGIN,
  54. UIEVENT_TOUCHDOWN,
  55. UIEVENT_TOUCHMOVE,
  56. UIEVENT_TOUCHUP,
  57. UIEVENT__TOUCHEND,
  58. UIEVENT_KILLFOCUS,
  59. UIEVENT_SETFOCUS,
  60. UIEVENT_WINDOWSIZE,
  61. UIEVENT_SETCURSOR,
  62. UIEVENT_TIMER,
  63. UIEVENT__LAST,
  64. };
  65. /////////////////////////////////////////////////////////////////////////////////////
  66. //
  67. // 内部保留的消息
  68. typedef enum MSGTYPE_UI
  69. {
  70. UIMSG_TRAYICON = WM_USER + 1,// 托盘消息
  71. UIMSG_SET_DPI, // DPI
  72. WM_MENUCLICK, // 菜单消息
  73. UIMSG_USER = WM_USER + 100, // 程序自定义消息
  74. };
  75. /////////////////////////////////////////////////////////////////////////////////////
  76. //
  77. // Flags for CControlUI::GetControlFlags()
  78. #define UIFLAG_TABSTOP 0x00000001
  79. #define UIFLAG_SETCURSOR 0x00000002
  80. #define UIFLAG_WANTRETURN 0x00000004
  81. // Flags for FindControl()
  82. #define UIFIND_ALL 0x00000000
  83. #define UIFIND_VISIBLE 0x00000001
  84. #define UIFIND_ENABLED 0x00000002
  85. #define UIFIND_HITTEST 0x00000004
  86. #define UIFIND_UPDATETEST 0x00000008
  87. #define UIFIND_TOP_FIRST 0x00000010
  88. #define UIFIND_ME_FIRST 0x80000000
  89. // Flags used for controlling the paint
  90. #define UISTATE_FOCUSED 0x00000001
  91. #define UISTATE_SELECTED 0x00000002
  92. #define UISTATE_DISABLED 0x00000004
  93. #define UISTATE_HOT 0x00000008
  94. #define UISTATE_PUSHED 0x00000010
  95. #define UISTATE_READONLY 0x00000020
  96. #define UISTATE_CAPTURED 0x00000040
  97. /////////////////////////////////////////////////////////////////////////////////////
  98. //
  99. typedef struct UILIB_API tagTFontInfo
  100. {
  101. HFONT hFont;
  102. CDuiString sFontName;
  103. int iSize;
  104. bool bBold;
  105. bool bUnderline;
  106. bool bItalic;
  107. bool bStrikeout;
  108. TEXTMETRIC tm;
  109. } TFontInfo;
  110. typedef struct UILIB_API tagTImageInfo
  111. {
  112. tagTImageInfo();
  113. Gdiplus::Image* pImage;
  114. HBITMAP hBitmap;
  115. LPBYTE pBits;
  116. LPBYTE pSrcBits;
  117. int nX;
  118. int nY;
  119. bool bAlpha;
  120. bool bUseHSL;
  121. CDuiString sResType;
  122. DWORD dwMask;
  123. } TImageInfo;
  124. typedef struct UILIB_API tagTDrawInfo
  125. {
  126. tagTDrawInfo();
  127. void Parse(LPCTSTR pStrImage, LPCTSTR pStrModify, CPaintManagerUI *pManager);
  128. void Clear();
  129. CDuiString sDrawString;
  130. CDuiString sDrawModify;
  131. CDuiString sImageName;
  132. CDuiString sResType;
  133. RECT rcDest;
  134. RECT rcSource;
  135. RECT rcCorner;
  136. DWORD dwMask;
  137. UINT uFade;
  138. UINT uRotate;
  139. bool bHole;
  140. bool bTiledX;
  141. bool bTiledY;
  142. bool bHSL;
  143. bool bGdiplus;
  144. CDuiSize szImage;
  145. RECT rcPadding;
  146. CDuiString sAlign;
  147. } TDrawInfo;
  148. typedef struct UILIB_API tagTPercentInfo
  149. {
  150. double left;
  151. double top;
  152. double right;
  153. double bottom;
  154. } TPercentInfo;
  155. typedef struct UILIB_API tagTResInfo
  156. {
  157. DWORD m_dwDefaultDisabledColor;
  158. DWORD m_dwDefaultFontColor;
  159. DWORD m_dwDefaultLinkFontColor;
  160. DWORD m_dwDefaultLinkHoverFontColor;
  161. DWORD m_dwDefaultSelectedBkColor;
  162. TFontInfo m_DefaultFontInfo;
  163. CStdStringPtrMap m_CustomFonts;
  164. CStdStringPtrMap m_ImageHash;
  165. CStdStringPtrMap m_AttrHash;
  166. CStdStringPtrMap m_StyleHash;
  167. CStdStringPtrMap m_DrawInfoHash;
  168. } TResInfo;
  169. // Structure for notifications from the system
  170. // to the control implementation.
  171. typedef struct UILIB_API tagTEventUI
  172. {
  173. int Type;
  174. CControlUI* pSender;
  175. DWORD dwTimestamp;
  176. POINT ptMouse;
  177. TCHAR chKey;
  178. WORD wKeyState;
  179. WPARAM wParam;
  180. LPARAM lParam;
  181. } TEventUI;
  182. // Drag&Drop control
  183. const TCHAR* const CF_MOVECONTROL = _T("CF_MOVECONTROL");
  184. typedef struct UILIB_API tagTCFMoveUI
  185. {
  186. CControlUI* pControl;
  187. } TCFMoveUI;
  188. // Listener interface
  189. class INotifyUI
  190. {
  191. public:
  192. virtual void Notify(TNotifyUI& msg) = 0;
  193. };
  194. // MessageFilter interface
  195. class IMessageFilterUI
  196. {
  197. public:
  198. virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) = 0;
  199. };
  200. class ITranslateAccelerator
  201. {
  202. public:
  203. virtual LRESULT TranslateAccelerator(MSG *pMsg) = 0;
  204. };
  205. class IDragDropUI
  206. {
  207. public:
  208. virtual bool OnDragDrop(CControlUI* pControl) { return false; }
  209. };
  210. /////////////////////////////////////////////////////////////////////////////////////
  211. //
  212. typedef CControlUI* (*LPCREATECONTROL)(LPCTSTR pstrType);
  213. class UILIB_API CPaintManagerUI : public CIDropTarget
  214. {
  215. public:
  216. CPaintManagerUI();
  217. ~CPaintManagerUI();
  218. public:
  219. void Init(HWND hWnd, LPCTSTR pstrName = NULL);
  220. bool IsUpdateNeeded() const;
  221. void NeedUpdate();
  222. void Invalidate();
  223. void Invalidate(RECT& rcItem);
  224. LPCTSTR GetName() const;
  225. HDC GetPaintDC() const;
  226. HWND GetPaintWindow() const;
  227. HWND GetTooltipWindow() const;
  228. int GetHoverTime() const;
  229. void SetHoverTime(int iTime);
  230. POINT GetMousePos() const;
  231. SIZE GetClientSize() const;
  232. SIZE GetInitSize();
  233. void SetInitSize(int cx, int cy);
  234. RECT GetSizeBox();
  235. void SetSizeBox(RECT& rcSizeBox);
  236. RECT GetCaptionRect();
  237. void SetCaptionRect(RECT& rcCaption);
  238. SIZE GetRoundCorner();
  239. void SetRoundCorner(int cx, int cy);
  240. SIZE GetMinInfo();
  241. void SetMinInfo(int cx, int cy);
  242. SIZE GetMaxInfo();
  243. void SetMaxInfo(int cx, int cy);
  244. bool IsShowUpdateRect();
  245. void SetShowUpdateRect(bool show);
  246. bool IsNoActivate();
  247. void SetNoActivate(bool bNoActivate);
  248. BYTE GetOpacity() const;
  249. void SetOpacity(BYTE nOpacity);
  250. bool IsLayered();
  251. void SetLayered(bool bLayered);
  252. RECT& GetLayeredInset();
  253. void SetLayeredInset(RECT& rcLayeredInset);
  254. BYTE GetLayeredOpacity();
  255. void SetLayeredOpacity(BYTE nOpacity);
  256. LPCTSTR GetLayeredImage();
  257. void SetLayeredImage(LPCTSTR pstrImage);
  258. CShadowUI* GetShadow();
  259. void SetUseGdiplusText(bool bUse);
  260. bool IsUseGdiplusText() const;
  261. void SetGdiplusTextRenderingHint(int trh);
  262. int GetGdiplusTextRenderingHint() const;
  263. static HINSTANCE GetInstance();
  264. static CDuiString GetInstancePath();
  265. static CDuiString GetCurrentPath();
  266. static HINSTANCE GetResourceDll();
  267. static const CDuiString& GetResourcePath();
  268. static const CDuiString& GetResourceZip();
  269. static const CDuiString& GetResourceZipPwd();
  270. static bool IsCachedResourceZip();
  271. static HANDLE GetResourceZipHandle();
  272. static void SetInstance(HINSTANCE hInst);
  273. static void SetCurrentPath(LPCTSTR pStrPath);
  274. static void SetResourceDll(HINSTANCE hInst);
  275. static void SetResourcePath(LPCTSTR pStrPath);
  276. static void SetResourceZip(LPVOID pVoid, unsigned int len, LPCTSTR password = NULL);
  277. static void SetResourceZip(LPCTSTR pstrZip, bool bCachedResourceZip = false, LPCTSTR password = NULL);
  278. static void SetResourceType(int nType);
  279. static int GetResourceType();
  280. static bool GetHSL(short* H, short* S, short* L);
  281. static void SetHSL(bool bUseHSL, short H, short S, short L); // H:0~360, S:0~200, L:0~200
  282. static void ReloadSkin();
  283. static CPaintManagerUI* GetPaintManager(LPCTSTR pstrName);
  284. static CStdPtrArray* GetPaintManagers();
  285. static bool LoadPlugin(LPCTSTR pstrModuleName);
  286. static CStdPtrArray* GetPlugins();
  287. bool IsForceUseSharedRes() const;
  288. void SetForceUseSharedRes(bool bForce);
  289. // 注意:只支持简单类型指针,因为只释放内存,不会调用类对象的析构函数
  290. void DeletePtr(void* ptr);
  291. DWORD GetDefaultDisabledColor() const;
  292. void SetDefaultDisabledColor(DWORD dwColor, bool bShared = false);
  293. DWORD GetDefaultFontColor() const;
  294. void SetDefaultFontColor(DWORD dwColor, bool bShared = false);
  295. DWORD GetDefaultLinkFontColor() const;
  296. void SetDefaultLinkFontColor(DWORD dwColor, bool bShared = false);
  297. DWORD GetDefaultLinkHoverFontColor() const;
  298. void SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared = false);
  299. DWORD GetDefaultSelectedBkColor() const;
  300. void SetDefaultSelectedBkColor(DWORD dwColor, bool bShared = false);
  301. TFontInfo* GetDefaultFontInfo();
  302. void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared = false);
  303. DWORD GetCustomFontCount(bool bShared = false) const;
  304. void AddFontArray(LPCTSTR pstrPath);
  305. HFONT AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared = false);
  306. HFONT GetFont(int id);
  307. HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout);
  308. int GetFontIndex(HFONT hFont, bool bShared = false);
  309. int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared = false);
  310. void RemoveFont(HFONT hFont, bool bShared = false);
  311. void RemoveFont(int id, bool bShared = false);
  312. void RemoveAllFonts(bool bShared = false);
  313. TFontInfo* GetFontInfo(int id);
  314. TFontInfo* GetFontInfo(HFONT hFont);
  315. const TImageInfo* GetImage(LPCTSTR bitmap);
  316. const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bGdiplus = false, HINSTANCE instance = NULL);
  317. const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bGdiplus = false, bool bShared = false, HINSTANCE instance = NULL);
  318. const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false);
  319. void RemoveImage(LPCTSTR bitmap, bool bShared = false);
  320. void RemoveAllImages(bool bShared = false);
  321. static void ReloadSharedImages();
  322. void ReloadImages();
  323. const TDrawInfo* GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
  324. void RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
  325. void RemoveAllDrawInfos();
  326. void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared = false);
  327. LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
  328. bool RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared = false);
  329. void RemoveAllDefaultAttributeList(bool bShared = false);
  330. void AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr);
  331. LPCTSTR GetWindowCustomAttribute(LPCTSTR pstrName) const;
  332. bool RemoveWindowCustomAttribute(LPCTSTR pstrName);
  333. void RemoveAllWindowCustomAttribute();
  334. // 样式管理
  335. void AddStyle(LPCTSTR pName, LPCTSTR pStyle, bool bShared = false);
  336. LPCTSTR GetStyle(LPCTSTR pName) const;
  337. BOOL RemoveStyle(LPCTSTR pName, bool bShared = false);
  338. const CStdStringPtrMap& GetStyles(bool bShared = false) const;
  339. void RemoveAllStyle(bool bShared = false);
  340. const TImageInfo* GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify = NULL);
  341. // 初始化拖拽
  342. bool EnableDragDrop(bool bEnable);
  343. void SetDragDrop(IDragDropUI* pDragDrop);
  344. virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium,DWORD *pdwEffect);
  345. bool IsValid();
  346. bool AttachDialog(CControlUI* pControl);
  347. bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
  348. void ReapObjects(CControlUI* pControl);
  349. bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  350. CStdPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
  351. void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
  352. void RemoveAllOptionGroups();
  353. CControlUI* GetFocus() const;
  354. void SetFocus(CControlUI* pControl);
  355. void SetFocusNeeded(CControlUI* pControl);
  356. bool SetNextTabControl(bool bForward = true);
  357. bool SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse);
  358. bool KillTimer(CControlUI* pControl, UINT nTimerID);
  359. void KillTimer(CControlUI* pControl);
  360. void RemoveAllTimers();
  361. void SetCapture();
  362. void ReleaseCapture();
  363. bool IsCaptured();
  364. bool IsPainting();
  365. void SetPainting(bool bIsPainting);
  366. bool AddNotifier(INotifyUI* pControl);
  367. bool RemoveNotifier(INotifyUI* pControl);
  368. void SendNotify(TNotifyUI& Msg, bool bAsync = false);
  369. void SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false);
  370. bool AddPreMessageFilter(IMessageFilterUI* pFilter);
  371. bool RemovePreMessageFilter(IMessageFilterUI* pFilter);
  372. bool AddMessageFilter(IMessageFilterUI* pFilter);
  373. bool RemoveMessageFilter(IMessageFilterUI* pFilter);
  374. int GetPostPaintCount() const;
  375. bool IsPostPaint(CControlUI* pControl);
  376. bool AddPostPaint(CControlUI* pControl);
  377. bool RemovePostPaint(CControlUI* pControl);
  378. bool SetPostPaintIndex(CControlUI* pControl, int iIndex);
  379. int GetNativeWindowCount() const;
  380. RECT GetNativeWindowRect(HWND hChildWnd);
  381. bool AddNativeWindow(CControlUI* pControl, HWND hChildWnd);
  382. bool RemoveNativeWindow(HWND hChildWnd);
  383. void AddDelayedCleanup(CControlUI* pControl);
  384. void AddMouseLeaveNeeded(CControlUI* pControl);
  385. bool RemoveMouseLeaveNeeded(CControlUI* pControl);
  386. bool AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  387. bool RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
  388. bool TranslateAccelerator(LPMSG pMsg);
  389. CControlUI* GetRoot() const;
  390. CControlUI* FindControl(POINT pt) const;
  391. CControlUI* FindControl(LPCTSTR pstrName) const;
  392. CControlUI* FindSubControlByPoint(CControlUI* pParent, POINT pt) const;
  393. CControlUI* FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const;
  394. CControlUI* FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex = 0);
  395. CStdPtrArray* FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass);
  396. static void MessageLoop();
  397. static bool TranslateMessage(const LPMSG pMsg);
  398. static void Term();
  399. CDPI* GetDPIObj();
  400. void ResetDPIAssets();
  401. void RebuildFont(TFontInfo* pFontInfo);
  402. void SetDPI(int iDPI);
  403. static void SetAllDPI(int iDPI);
  404. bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  405. bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
  406. void UsedVirtualWnd(bool bUsed);
  407. // 触屏支持(参考 NIM Duilib 模型,库级统一接管:主窗口 + 所有弹框通用)。
  408. // WM_TOUCH 在 MessageHandler 里解析为原生 DuiLib 触摸事件,直接派发给命中的控件:
  409. // DOWN → UIEVENT_TOUCHDOWN 滚动条据此抓滑块;容器据此记手势起点(其余控件忽略)
  410. // MOVE → UIEVENT_TOUCHMOVE CScrollBarUI 消费则拖滑块;否则冒泡给 CContainerUI 做 1:1 跟手平移
  411. // UP → UIEVENT_TOUCHUP 滚动条据此松开滑块;容器收尾(其余控件忽略)
  412. // 按钮“点击”【不】在此合成:它来自 Windows 为触摸自动提升(promote)的 WM_LBUTTONDOWN/UP,
  413. // 走 MessageHandler 原生鼠标路径 → CButtonUI 等据此 Activate() 触发 click。
  414. // 不做任何“触摸→鼠标”归一化,也不做 NIM 那种 m_pEventTouch!=NULL 通用守卫(旧版 DuiLib 的
  415. // 点击状态机强依赖原生 WM_LBUTTONDOWN/UP,照搬守卫会让点击全灭,已实测);仅用
  416. // m_bTouchMoved 标记“本次手势是否发生位移”,位移则松开时不触发点击(避免滚动又误点)。
  417. // 注册在 Init 中完成,无需逐窗口样板。
  418. void InitTouchSupport();
  419. void OnTouchInput(WPARAM wParam, LPARAM lParam);
  420. private:
  421. CStdPtrArray* GetFoundControls();
  422. static CControlUI* CALLBACK __FindControlFromNameHash(CControlUI* pThis, LPVOID pData);
  423. static CControlUI* CALLBACK __FindControlFromCount(CControlUI* pThis, LPVOID pData);
  424. static CControlUI* CALLBACK __FindControlFromPoint(CControlUI* pThis, LPVOID pData);
  425. static CControlUI* CALLBACK __FindControlFromTab(CControlUI* pThis, LPVOID pData);
  426. static CControlUI* CALLBACK __FindControlFromShortcut(CControlUI* pThis, LPVOID pData);
  427. static CControlUI* CALLBACK __FindControlFromName(CControlUI* pThis, LPVOID pData);
  428. static CControlUI* CALLBACK __FindControlFromClass(CControlUI* pThis, LPVOID pData);
  429. static CControlUI* CALLBACK __FindControlsFromClass(CControlUI* pThis, LPVOID pData);
  430. static CControlUI* CALLBACK __FindControlsFromUpdate(CControlUI* pThis, LPVOID pData);
  431. static void AdjustSharedImagesHSL();
  432. void AdjustImagesHSL();
  433. void PostAsyncNotify();
  434. private:
  435. CDuiString m_sName;
  436. HWND m_hWndPaint; //所附加的窗体的句柄
  437. HDC m_hDcPaint;
  438. HDC m_hDcOffscreen;
  439. HDC m_hDcBackground;
  440. HBITMAP m_hbmpOffscreen;
  441. BYTE* m_pOffscreenBits;
  442. HBITMAP m_hbmpBackground;
  443. COLORREF* m_pBackgroundBits;
  444. // 提示信息
  445. HWND m_hwndTooltip;
  446. TOOLINFO m_ToolTip;
  447. int m_iHoverTime;
  448. bool m_bNoActivate;
  449. bool m_bShowUpdateRect;
  450. // 触屏状态(库级统一接管后,每个窗口的 CPaintManagerUI 各持一份)
  451. // 旧 DuiLib 点击状态机依赖:WM_LBUTTONDOWN 设置 m_pEventClick,WM_LBUTTONUP 据此触发点击
  452. // (CButtonUI::Activate)。因此【绝不能】在鼠标分支里用 m_pEventTouch 守卫吞掉 Windows 为触摸
  453. // 模拟的 WM_LBUTTONDOWN/UP——否则 m_pEventClick 永不被设置,触摸与鼠标点击全失效。
  454. // 正确做法:放开模拟鼠标(FROMTOUCH 不过滤),点击自然走原生路径;仅用 m_bTouchMoved 标记
  455. // “本次手势是否发生位移”,若位移则松开时不触发点击(避免拖拽=滚动 又 误点按钮)。
  456. CControlUI* m_pEventTouch = NULL; // 本次触摸命中的控件(用于派发 UIEVENT_TOUCHMOVE 做跟手滚动)
  457. POINT m_ptLastTouchPos = { 0, 0 }; // 上一包触点:用于去重 + 计算跟手滚动的位移增量
  458. POINT m_ptTouchStart = { 0, 0 }; // 本次手势起点:用于判断是否发生位移(拖拽 vs 轻点)
  459. bool m_bTouchMoved = false; // 本次触摸是否发生位移(>阈值视为拖拽),松开时抑制点击
  460. // 手指抬起后,Windows 仍会补发合成的 WM_MOUSEMOVE;且真实 WM_MOUSELEAVE 在
  461. // m_bMouseTracking 为真时会【自己给自己重发 WM_MOUSEMOVE】(UIManager.cpp WM_MOUSELEAVE 分支),
  462. // 导致刚清掉的悬浮态立刻被重新点亮 → “悬浮态不消失 / 多个控件同时悬浮”。
  463. // 抬起后置 true,丢弃随后这批“非真实”的 MOUSEMOVE 悬浮逻辑;一旦收到用户真实移动鼠标
  464. // (这里用“距上次触摸位置明显移动”判定)即解除。
  465. // 注:这是【第二道】保险。第一道(根治)在 WM_MOUSEMOVE 里:凡带 MOUSEEVENTF_FROMTOUCH
  466. // 标记的“触摸提升出来的鼠标消息”一律不参与悬浮 enter/leave —— 触摸没有“光标停留”语义,
  467. // 让这类消息参与必然出现“点过的控件一直高亮 / 多点几个后多个同时高亮”。
  468. bool m_bSuppressHoverAfterTouch = false;
  469. //
  470. CControlUI* m_pRoot;
  471. CControlUI* m_pFocus;
  472. CControlUI* m_pEventHover;
  473. CControlUI* m_pEventClick;
  474. CControlUI* m_pEventRClick;
  475. CControlUI* m_pEventKey;
  476. CControlUI* m_pLastToolTip;
  477. //
  478. POINT m_ptLastMousePos;
  479. SIZE m_szMinWindow;
  480. SIZE m_szMaxWindow;
  481. SIZE m_szInitWindowSize;
  482. RECT m_rcSizeBox;
  483. SIZE m_szRoundCorner;
  484. RECT m_rcCaption;
  485. UINT m_uTimerID;
  486. bool m_bFirstLayout;
  487. bool m_bUpdateNeeded;
  488. bool m_bFocusNeeded;
  489. bool m_bOffscreenPaint;
  490. BYTE m_nOpacity;
  491. bool m_bLayered;
  492. RECT m_rcLayeredInset;
  493. bool m_bLayeredChanged;
  494. RECT m_rcLayeredUpdate;
  495. TDrawInfo m_diLayered;
  496. bool m_bMouseTracking;
  497. bool m_bMouseCapture;
  498. bool m_bIsPainting;
  499. bool m_bUsedVirtualWnd;
  500. bool m_bAsyncNotifyPosted;
  501. //
  502. CStdPtrArray m_aNotifiers;
  503. CStdPtrArray m_aTimers;
  504. CStdPtrArray m_aTranslateAccelerator;
  505. CStdPtrArray m_aPreMessageFilters;
  506. CStdPtrArray m_aMessageFilters;
  507. CStdPtrArray m_aPostPaintControls;
  508. CStdPtrArray m_aNativeWindow;
  509. CStdPtrArray m_aNativeWindowControl;
  510. CStdPtrArray m_aDelayedCleanup;
  511. CStdPtrArray m_aAsyncNotify;
  512. CStdPtrArray m_aFoundControls;
  513. CStdPtrArray m_aFonts;
  514. CStdPtrArray m_aNeedMouseLeaveNeeded;
  515. CStdStringPtrMap m_mNameHash;
  516. CStdStringPtrMap m_mWindowCustomAttrHash;
  517. CStdStringPtrMap m_mOptionGroup;
  518. bool m_bForceUseSharedRes;
  519. TResInfo m_ResInfo;
  520. // 窗口阴影
  521. CShadowUI m_shadow;
  522. // DPI管理器
  523. CDPI* m_pDPI;
  524. // 是否开启Gdiplus
  525. bool m_bUseGdiplusText;
  526. int m_trh;
  527. ULONG_PTR m_gdiplusToken;
  528. Gdiplus::GdiplusStartupInput *m_pGdiplusStartupInput;
  529. // 拖拽
  530. bool m_bDragDrop;
  531. bool m_bDragMode;
  532. HBITMAP m_hDragBitmap;
  533. IDragDropUI *m_pDragDrop;
  534. //
  535. static HINSTANCE m_hInstance;
  536. static HINSTANCE m_hResourceInstance;
  537. static CDuiString m_pStrResourcePath;
  538. static CDuiString m_pStrResourceZip;
  539. static CDuiString m_pStrResourceZipPwd;
  540. static HANDLE m_hResourceZip;
  541. static BYTE* m_cbZipBuf;
  542. static bool m_bCachedResourceZip;
  543. static int m_nResType;
  544. static TResInfo m_SharedResInfo;
  545. static bool m_bUseHSL;
  546. static short m_H;
  547. static short m_S;
  548. static short m_L;
  549. static CStdPtrArray m_aPreMessages;
  550. static CStdPtrArray m_aPlugins;
  551. };
  552. } // namespace DuiLib
  553. #endif // __UIMANAGER_H__