forked from krkrz/menu
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowMenu.h
111 lines (85 loc) · 2.46 KB
/
WindowMenu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef __WINDOW_MENU_H__
#define __WINDOW_MENU_H__
#include <string>
#include <vector>
#include <map>
#include <windows.h>
class WindowMenuItem {
static const int MAX_CAPTION_LENGTH = 1024;
static const int MENU_ID_MIN = 0x2000;
static const int MENU_ID_MAX = 0x6FFF;
static std::vector<int> FREE_ID_LIST;
static std::map<int, WindowMenuItem*> ID_TO_ITEM;
static int CURRENT_MENU_ID;
static int GetNewMenuId( WindowMenuItem* item );
static void ReleaseMenuId( int id );
protected:
MENUITEMINFO menu_item_info_;
HMENU hMenu_;
HWND hWnd_;
private:
class tTJSNI_MenuItem* owner_;
std::string caption_;
int short_cut_key_;
int group_no_;
bool is_visible_;
WindowMenuItem* parent_;
std::vector<WindowMenuItem*> children_;
void Remove( WindowMenuItem* item, bool ignoreupdate = false );
/**
* 全ての項目を削除してから追加し直す
*/
void UpdateChildren();
void UpdateMenu( bool rebuild = true );
void CheckRadioItem( WindowMenuItem* item );
void UncheckRadioItem( int group );
/**
* 指定グループの内でcheckがついているアイテムインデックスを取得する
*/
int GetCheckRadioIndex( int group );
/**
* ラジオアイテム化する時に
*/
void RadioItemSafeCheck();
bool AddSubMenu();
bool RemoveSubMenu();
public:
WindowMenuItem( class tTJSNI_MenuItem* owner, HWND hWnd, HMENU hMenu=NULL );
~WindowMenuItem();
void Add( WindowMenuItem* item );
void Insert( int index, WindowMenuItem* item );
void Delete( int index );
void SetCaption( const TCHAR* caption );
const TCHAR* GetCaption() const;
HMENU GetHandle() { return hMenu_; }
int IndexOf( const WindowMenuItem* item );
int GetMenuIndex() const;
void SetMenuIndex( int index );
void SetChecked( bool b );
bool GetChecked() const {
return (menu_item_info_.fState & MFS_CHECKED) != 0;
}
void SetEnabled( bool b );
bool GetEnabled() const {
return (menu_item_info_.fState & MFS_DISABLED) == 0;
}
void SetGroupIndex( int index );
int GetGroupIndex() const {
return group_no_;
}
void SetRadioItem( bool b );
bool GetRadioItem() const {
return (menu_item_info_.fType & MFT_RADIOCHECK) != 0;
}
void SetShortCut( int key );
int GetShortCut() const {
return short_cut_key_;
}
void SetVisible( bool b );
bool GetVisible() const { return is_visible_; }
const WindowMenuItem* GetParent() const { return parent_; }
WindowMenuItem* GetParent() { return parent_; }
void OnClick();
static void OnClickHandler( int id );
};
#endif