UIButton.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef __UIBUTTON_H__
  2. #define __UIBUTTON_H__
  3. #pragma once
  4. namespace DuiLib
  5. {
  6. class UILIB_API CButtonUI : public CLabelUI
  7. {
  8. DECLARE_DUICONTROL(CButtonUI)
  9. public:
  10. CButtonUI();
  11. LPCTSTR GetClass() const;
  12. LPVOID GetInterface(LPCTSTR pstrName);
  13. UINT GetControlFlags() const;
  14. bool Activate();
  15. void SetEnabled(bool bEnable = true);
  16. void DoEvent(TEventUI& event);
  17. // ------------------------------------------------------------------
  18. // [触屏] 清除"按下/按下高亮"相关位:PUSHED | CAPTURED | HOT。
  19. //
  20. // 存在的理由(Win10 真机 bug):属性弹框弹出时,被点的商品按钮
  21. // (「古古怪怪」)的 PUSHED 态残留不消失。
  22. // 成因是 CButtonUI::DoEvent 的 UIEVENT_BUTTONUP 分支带 CAPTURED 守卫 ——
  23. // 弹框把 manager 搬走时 CAPTURED 被清掉,导致弹框关闭后那条补发的
  24. // BUTTONUP 进不了分支,PUSHED 就永远留着。
  25. //
  26. // CControlUI 基类里现在有了 `virtual void ClearPushedState()`(默认空实现),
  27. // 本类把它 override 成"清 PUSHED|CAPTURED|HOT 三个显示位"。
  28. // 于是 CPaintManagerUI::ClearPushedStateAt 只需按基类指针调用,
  29. // 就能同时覆盖 CButtonUI 与业务自绘控件(如 CDiandanFoodItemUI)。
  30. //
  31. // ⚠️ 只用于"搬家"与"触摸滑动起手"这种确定性时点。
  32. // **不要**拿它去给触摸抬手打补丁 —— 触摸路径的按下态残留是
  33. // **消息顺序**问题(状态收尾被夹在业务回调之前),已在
  34. // EndTouchSlideGesture / TouchUp 里按顺序修正,不靠事后补清。
  35. // ------------------------------------------------------------------
  36. virtual void ClearPushedState();
  37. virtual LPCTSTR GetNormalImage();
  38. virtual void SetNormalImage(LPCTSTR pStrImage);
  39. virtual LPCTSTR GetHotImage();
  40. virtual void SetHotImage(LPCTSTR pStrImage);
  41. virtual LPCTSTR GetPushedImage();
  42. virtual void SetPushedImage(LPCTSTR pStrImage);
  43. virtual LPCTSTR GetFocusedImage();
  44. virtual void SetFocusedImage(LPCTSTR pStrImage);
  45. virtual LPCTSTR GetDisabledImage();
  46. virtual void SetDisabledImage(LPCTSTR pStrImage);
  47. virtual LPCTSTR GetHotForeImage();
  48. virtual void SetHotForeImage(LPCTSTR pStrImage);
  49. virtual LPCTSTR GetPushedForeImage();
  50. virtual void SetPushedForeImage(LPCTSTR pStrImage);
  51. void SetStateCount(int nCount);
  52. int GetStateCount() const;
  53. virtual LPCTSTR GetStateImage();
  54. virtual void SetStateImage(LPCTSTR pStrImage);
  55. void BindTabIndex(int _BindTabIndex);
  56. void BindTabLayoutName(LPCTSTR _TabLayoutName);
  57. void BindTriggerTabSel(int _SetSelectIndex = -1);
  58. void RemoveBindTabIndex();
  59. int GetBindTabLayoutIndex();
  60. LPCTSTR GetBindTabLayoutName();
  61. void SetHotFont(int index);
  62. int GetHotFont() const;
  63. void SetPushedFont(int index);
  64. int GetPushedFont() const;
  65. void SetFocusedFont(int index);
  66. int GetFocusedFont() const;
  67. void SetHotBkColor(DWORD dwColor);
  68. DWORD GetHotBkColor() const;
  69. void SetPushedBkColor(DWORD dwColor);
  70. DWORD GetPushedBkColor() const;
  71. void SetDisabledBkColor(DWORD dwColor);
  72. DWORD GetDisabledBkColor() const;
  73. void SetHotTextColor(DWORD dwColor);
  74. DWORD GetHotTextColor() const;
  75. void SetPushedTextColor(DWORD dwColor);
  76. DWORD GetPushedTextColor() const;
  77. void SetFocusedTextColor(DWORD dwColor);
  78. DWORD GetFocusedTextColor() const;
  79. void SetHotBorderColor(DWORD dwColor);
  80. DWORD GetHotBorderColor() const;
  81. void SetPushedBorderColor(DWORD dwColor);
  82. DWORD GetPushedBorderColor() const;
  83. void SetDisabledBorderColor(DWORD dwColor);
  84. DWORD GetDisabledBorderColor() const;
  85. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  86. void PaintText(HDC hDC);
  87. void PaintBkColor(HDC hDC);
  88. void PaintStatusImage(HDC hDC);
  89. void PaintBorder(HDC hDC);
  90. void PaintForeImage(HDC hDC);
  91. void DrawBorder(HDC hDC, const RECT& rcItem, const DWORD& dwBorderColor, const int& nBorderSize, const RECT& rcBorderSize, const SIZE& cxyBorderRound, const int& nBorderStyle);
  92. protected:
  93. UINT m_uButtonState;
  94. int m_iHotFont;
  95. int m_iPushedFont;
  96. int m_iFocusedFont;
  97. DWORD m_dwHotBkColor;
  98. DWORD m_dwPushedBkColor;
  99. DWORD m_dwDisabledBkColor;
  100. DWORD m_dwHotTextColor;
  101. DWORD m_dwPushedTextColor;
  102. DWORD m_dwFocusedTextColor;
  103. DWORD m_dwHotBorderColor;
  104. DWORD m_dwPushedBorderColor;
  105. DWORD m_dwDisabledBorderColor;
  106. CDuiString m_sNormalImage;
  107. CDuiString m_sHotImage;
  108. CDuiString m_sHotForeImage;
  109. CDuiString m_sPushedImage;
  110. CDuiString m_sPushedForeImage;
  111. CDuiString m_sFocusedImage;
  112. CDuiString m_sDisabledImage;
  113. int m_nStateCount;
  114. CDuiString m_sStateImage;
  115. int m_iBindTabIndex;
  116. CDuiString m_sBindTabLayoutName;
  117. };
  118. } // namespace DuiLib
  119. #endif // __UIBUTTON_H__