mrDarker
6 天以前 829fe6c6bc33d53fda9c31fd45a37e1df87befff
SourceCode/Bond/BLControlsSDK/include/BLLabel.h
@@ -1,77 +1,101 @@
#if !defined(AFX_BLLABEL_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)
#if !defined(AFX_BLLABEL_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)
#define AFX_BLLABEL_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// Label.h : header file
//
#include <functional>
/////////////////////////////////////////////////////////////////////////////
// CBLLabel window
enum FlashType {None, Text, Background };
enum FlashType { None, Text, Background };
enum TextAlign { AlignLeft, AlignCenter, AlignRight };
class AFX_EXT_CLASS CBLLabel : public CStatic
{
// Construction
public:
   CBLLabel();
   CBLLabel& SetBkColor(COLORREF crBkgnd);
   CBLLabel& SetTextColor(COLORREF crText);
   CBLLabel& SetText(const CString& strText);
   CBLLabel& SetFontBold(BOOL bBold);
   CBLLabel& SetFontName(const CString& strFont);
   CBLLabel& SetFontUnderline(BOOL bSet);
   CBLLabel& SetFontItalic(BOOL bSet);
   CBLLabel& SetFontSize(int nSize);
   CBLLabel& SetSunken(BOOL bSet);
   CBLLabel& SetBorder(BOOL bSet);
   CBLLabel& FlashText(BOOL bActivate);
   CBLLabel& FlashBackground(BOOL bActivate);
   CBLLabel& SetLink(BOOL bLink);
   CBLLabel& SetLinkCursor(HCURSOR hCursor);
    DECLARE_DYNCREATE(CBLLabel) // 支持动态创建
// Attributes
public:
    // 构造与析构
    CBLLabel();
    virtual ~CBLLabel();
    void SetClickCallback(std::function<void()> callback); // 设置点击事件的回调函数
    // 属性设置接口
    CBLLabel& SetBkColor(COLORREF crBkgnd);                 // 设置背景颜色
    CBLLabel& SetTextColor(COLORREF crText);                // 设置文本颜色
    CBLLabel& SetText(const CString& strText);              // 设置文本内容
    CBLLabel& SetFontBold(BOOL bBold);                      // 设置字体加粗
    CBLLabel& SetFontName(const CString& strFont);          // 设置字体名称
    CBLLabel& SetFontUnderline(BOOL bSet);                  // 设置下划线
    CBLLabel& SetFontItalic(BOOL bSet);                     // 设置斜体
    CBLLabel& SetFontSize(int nSize);                       // 设置字体大小
    CBLLabel& SetAlignment(TextAlign alignment);            // 设置文本对齐方式
    CBLLabel& SetDynamicFont(BOOL bDynamic);                // 设置是否动态调整字体
    CBLLabel& FlashText(BOOL bActivate);                    // 闪烁文本
    CBLLabel& FlashBackground(BOOL bActivate);              // 闪烁背景
    CBLLabel& SetLink(BOOL bLink);                          // 设置是否启用超链接
    CBLLabel& SetLinkCursor(HCURSOR hCursor);               // 设置超链接光标
   CBLLabel& DisableBorder();                         // 禁用边框
   CBLLabel& SetBorderColor(COLORREF crBorder);            // 设置边框颜色
   CBLLabel& SetBorderWidth(int nWidth);                   // 设置边框宽度
   CBLLabel& SetBorderStyle(int nStyle);                   // 设置边框样式
   CBLLabel& SetDefaultCursor(HCURSOR hCursor);         // 设置默认光标
    CBLLabel& SetHandCursor(HCURSOR hCursor);            // 设置手型光标
    CBLLabel& SetRoundedCorners(BOOL bEnable, int nRadius); // 设置圆角及半径
    CBLLabel& SetCornerRadius(int nTopLeft, int nTopRight, int nBottomRight, int nBottomLeft); // 设置各角圆角半径
protected:
   void ReconstructFont();
   COLORREF   m_crText;
   HBRUSH      m_hBrush;
   HBRUSH      m_hwndBrush;
   LOGFONT      m_lf;
   CFont      m_font;
   CString      m_strText;
   BOOL      m_bState;
   BOOL      m_bTimer;
   BOOL      m_bLink;
   FlashType   m_Type;
   HCURSOR      m_hCursor;
         // Operations
public:
// Overrides
   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CBLLabel)
   //}}AFX_VIRTUAL
    // 工具函数
    void ReconstructFont();                                 // 重新构造字体
    void UpdateFontSize();                                  // 动态调整字体大小
   void CreateRoundedRegion(CRgn& rgn, const CRect& rect); // 创建圆角区域
    virtual void OnPaint();                                 // 自定义绘制文本
// Implementation
public:
   virtual ~CBLLabel();
    // 属性
    COLORREF  m_crText;           // 文本颜色
    COLORREF  m_crBkColor;        // 背景颜色
    HBRUSH    m_hBrush;           // 背景画刷
    LOGFONT   m_lf;               // 字体信息
    CFont     m_font;             // 字体对象
    CString   m_strText;          // 文本内容
    BOOL      m_bState;           // 状态,用于闪烁
    BOOL      m_bTimer;           // 定时器状态
    BOOL      m_bLink;            // 是否为超链接
    BOOL      m_bDynamicFont;     // 是否动态调整字体大小
    TextAlign m_alignment;        // 文本对齐方式
    FlashType m_Type;             // 闪烁类型
    HCURSOR   m_hCursor;          // 超链接光标
   // Generated message map functions
    // 边框属性
    COLORREF m_crBorderColor;     // 边框颜色
    int m_nBorderWidth;           // 边框宽度
    int m_nBorderStyle;           // 边框样式(使用 GDI 样式:PS_SOLID, PS_DASH 等)
    // 圆角相关属性
    BOOL m_bRoundedCorners;       // 是否启用圆角
    int  m_nTopLeftRadius;        // 左上角圆角半径
    int  m_nTopRightRadius;       // 右上角圆角半径
    int  m_nBottomRightRadius;    // 右下角圆角半径
    int  m_nBottomLeftRadius;     // 左下角圆角半径
   // 鼠标事件相关属性
    BOOL    m_bMouseIn;           // 鼠标是否在控件上
    HCURSOR m_hHandCursor;        // 手型光标
    HCURSOR m_hDefaultCursor;     // 默认光标
    std::function<void()> m_clickCallback; // 点击事件的回调函数
protected:
   //{{AFX_MSG(CBLLabel)
   afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
   afx_msg void OnTimer(UINT_PTR nIDEvent);
   afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
   afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
    // MFC 消息映射
    virtual HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);      // 背景和文本颜色设置
    afx_msg void OnTimer(UINT_PTR nIDEvent);                // 定时器事件
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);  // 鼠标点击事件
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);    // 鼠标移动事件
   afx_msg void OnMouseLeave();                            // 鼠标离开事件
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); // 设置光标事件
    DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BLLABEL_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)