xref: /MusicPlayer2/MusicPlayer2/PlayerToolBar.h (revision d0f663722daed37d7c579eeb34fb31f1424fe445)
1 #pragma once
2 #include "CommonData.h"
3 #include "IconMgr.h"
4 
5 // CPlayerToolBar
6 // 自绘的工具栏
7 
8 class CPlayerToolBar : public CStatic
9 {
10 	DECLARE_DYNAMIC(CPlayerToolBar)
11 public:
12 	CPlayerToolBar();
13 	virtual ~CPlayerToolBar();
14 
15     // 添加一个按钮,点击后执行一个命令
16     // IconMgr::IconType icon_type: 图标类型
17     // LPCTSTR strText: 图标右侧的文本
18     // LPCTSTR strToolTip: 鼠标提示的文本
19     // UINT cmdId: 点击后执行的命令ID
20     // bool showText: 是否在图标右侧显示文本
21     void AddToolButton(IconMgr::IconType icon_type, LPCTSTR strText, LPCTSTR strToolTip, UINT cmdId, bool showText = false);
22 
23     // 添加一个按钮,点击后弹出菜单
24     // IconMgr::IconType icon_type: 图标类型
25     // LPCTSTR strText: 图标右侧的文本
26     // LPCTSTR strToolTip: 鼠标提示的文本
27     // CMenu * pMenu: 点击后弹出的菜单
28     // bool showText: 是否在图标右侧显示文本
29     void AddToolButton(IconMgr::IconType icon_type, LPCTSTR strText, LPCTSTR strToolTip, CMenu* pMenu, bool showText = false);
30 
31     void ModifyToolButton(int index, IconMgr::IconType icon_type, LPCTSTR strText, LPCTSTR strToolTip, UINT cmdId, bool showText = false);
32     void ModifyToolButton(int index, IconMgr::IconType icon_type, LPCTSTR strText, LPCTSTR strToolTip, CMenu* pMenu, bool showText = false);
33 
34     void SetIconSize(int size);
35     void SetCmdReciveWindow(CWnd* pWnd);        //设置响应工具按钮命令的窗口,如果不设置,则为工具栏的父窗口
36 
37 protected:
38     struct ToolBtn
39     {
40         IconMgr::IconType icon_type;    //图标类型
41         CString text;           //显示文本
42         bool show_text = false; //是否显示文本
43         UINT cmd_id;            //点击后发送的命令ID
44         CMenu* pMenu = nullptr; //点击后弹出的菜单
45         bool is_cmd = true;     //点击后发送命令还是弹出菜单
46         CString tooltip_text;   //鼠标提示文本
47         CRect rect;				//按钮的矩形区域
48         bool hover{ false };	//鼠标是否指向按钮
49         bool pressed{ false };	//按钮是否按下
50         bool enable{ true };	//按钮是否启用
51     };
52 
53     void AddToolTips();
54     void UpdateToolTipsPosition();  //更新鼠标提示的位置
55     CWnd* GetCmdReciveWindow();
56 
57 protected:
58 	CToolTipCtrl m_tool_tip;		//文本提示类
59     std::vector<ToolBtn> m_buttons;
60     const ColorTable& m_theme_color;
61     int m_icon_size = 20;
62     int m_cur_btn_id = 100;
63     bool m_first_draw = true;
64     bool m_btn_updated = false;
65     bool m_menu_poped_up = false;
66     CWnd* m_pCmdReciveWnd = nullptr;
67 
68 	DECLARE_MESSAGE_MAP()
69 
70 	afx_msg void OnPaint();
71 	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
72 	virtual void PreSubclassWindow();
73 	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
74 public:
75 	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
76 	virtual BOOL PreTranslateMessage(MSG* pMsg);
77     afx_msg void OnMouseLeave();
78     afx_msg void OnMouseHover(UINT nFlags, CPoint point);
79 protected:
80     afx_msg LRESULT OnInitmenu(WPARAM wParam, LPARAM lParam);
81     virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
82 public:
83     afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
84 };
85