aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/Menu.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/Menu.h52
1 files changed, 32 insertions, 20 deletions
diff --git a/CPP/Windows/Menu.h b/CPP/Windows/Menu.h
index aacdc7c..e1de4c4 100644
--- a/CPP/Windows/Menu.h
+++ b/CPP/Windows/Menu.h
@@ -1,14 +1,27 @@
1// Windows/Menu.h 1// Windows/Menu.h
2 2
3#ifndef __WINDOWS_MENU_H 3#ifndef ZIP7_INC_WINDOWS_MENU_H
4#define __WINDOWS_MENU_H 4#define ZIP7_INC_WINDOWS_MENU_H
5 5
6#include "../Common/MyWindows.h"
6#include "../Common/MyString.h" 7#include "../Common/MyString.h"
7 8
8#include "Defs.h" 9#include "Defs.h"
9 10
10namespace NWindows { 11namespace NWindows {
11 12
13#ifndef MIIM_STRING
14#define MIIM_STRING 0x00000040
15#endif
16/*
17#ifndef MIIM_BITMAP
18#define MIIM_BITMAP 0x00000080
19#endif
20*/
21#ifndef MIIM_FTYPE
22#define MIIM_FTYPE 0x00000100
23#endif
24
12struct CMenuItem 25struct CMenuItem
13{ 26{
14 UString StringValue; 27 UString StringValue;
@@ -23,24 +36,23 @@ struct CMenuItem
23 // LPTSTR dwTypeData; 36 // LPTSTR dwTypeData;
24 // UINT cch; 37 // UINT cch;
25 // HBITMAP hbmpItem; 38 // HBITMAP hbmpItem;
26 bool IsString() const // change it MIIM_STRING 39 bool IsString() const { return (fMask & (MIIM_TYPE | MIIM_STRING)) != 0; }
27 { return ((fMask & MIIM_TYPE) != 0 && (fType == MFT_STRING)); }
28 bool IsSeparator() const { return (fType == MFT_SEPARATOR); } 40 bool IsSeparator() const { return (fType == MFT_SEPARATOR); }
29 CMenuItem(): fMask(0), fType(0), fState(0), wID(0), hSubMenu(0), hbmpChecked(0), 41 CMenuItem(): fMask(0), fType(0), fState(0), wID(0),
30 hbmpUnchecked(0), dwItemData(0) {} 42 hSubMenu(NULL), hbmpChecked(NULL), hbmpUnchecked(NULL), dwItemData(0) {}
31}; 43};
32 44
33class CMenu 45class CMenu
34{ 46{
35 HMENU _menu; 47 HMENU _menu;
36public: 48public:
37 CMenu(): _menu(NULL) {}; 49 CMenu(): _menu(NULL) {}
38 operator HMENU() const { return _menu; } 50 operator HMENU() const { return _menu; }
39 void Attach(HMENU menu) { _menu = menu; } 51 void Attach(HMENU menu) { _menu = menu; }
40 52
41 HMENU Detach() 53 HMENU Detach()
42 { 54 {
43 HMENU menu = _menu; 55 const HMENU menu = _menu;
44 _menu = NULL; 56 _menu = NULL;
45 return menu; 57 return menu;
46 } 58 }
@@ -59,27 +71,27 @@ public:
59 71
60 bool Destroy() 72 bool Destroy()
61 { 73 {
62 if (_menu == NULL) 74 if (!_menu)
63 return false; 75 return false;
64 return BOOLToBool(::DestroyMenu(Detach())); 76 return BOOLToBool(::DestroyMenu(Detach()));
65 } 77 }
66 78
67 int GetItemCount() 79 int GetItemCount() const
68 { 80 {
69 #ifdef UNDER_CE 81 #ifdef UNDER_CE
70 for (int i = 0;; i++) 82 for (unsigned i = 0;; i++)
71 { 83 {
72 CMenuItem item; 84 CMenuItem item;
73 item.fMask = MIIM_STATE; 85 item.fMask = MIIM_STATE;
74 if (!GetItem(i, true, item)) 86 if (!GetItem(i, true, item))
75 return i; 87 return (int)i;
76 } 88 }
77 #else 89 #else
78 return GetMenuItemCount(_menu); 90 return GetMenuItemCount(_menu);
79 #endif 91 #endif
80 } 92 }
81 93
82 HMENU GetSubMenu(int pos) { return ::GetSubMenu(_menu, pos); } 94 HMENU GetSubMenu(int pos) const { return ::GetSubMenu(_menu, pos); }
83 #ifndef UNDER_CE 95 #ifndef UNDER_CE
84 /* 96 /*
85 bool GetItemString(UINT idItem, UINT flag, CSysString &result) 97 bool GetItemString(UINT idItem, UINT flag, CSysString &result)
@@ -93,11 +105,11 @@ public:
93 return (len != 0); 105 return (len != 0);
94 } 106 }
95 */ 107 */
96 UINT GetItemID(int pos) { return ::GetMenuItemID(_menu, pos); } 108 UINT GetItemID(int pos) const { return ::GetMenuItemID(_menu, pos); }
97 UINT GetItemState(UINT id, UINT flags) { return ::GetMenuState(_menu, id, flags); } 109 UINT GetItemState(UINT id, UINT flags) const { return ::GetMenuState(_menu, id, flags); }
98 #endif 110 #endif
99 111
100 bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) 112 bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) const
101 { return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } 113 { return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
102 bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) 114 bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo)
103 { return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } 115 { return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
@@ -118,7 +130,7 @@ public:
118 void RemoveAllItems() { RemoveAllItemsFrom(0); } 130 void RemoveAllItems() { RemoveAllItemsFrom(0); }
119 131
120 #ifndef _UNICODE 132 #ifndef _UNICODE
121 bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) 133 bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) const
122 { return BOOLToBool(::GetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } 134 { return BOOLToBool(::GetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
123 bool InsertItem(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) 135 bool InsertItem(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo)
124 { return BOOLToBool(::InsertMenuItemW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } 136 { return BOOLToBool(::InsertMenuItemW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
@@ -127,7 +139,7 @@ public:
127 bool AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem); 139 bool AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem);
128 #endif 140 #endif
129 141
130 bool GetItem(UINT itemIndex, bool byPosition, CMenuItem &item); 142 bool GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) const;
131 bool SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item); 143 bool SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item);
132 bool InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item); 144 bool InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item);
133 145
@@ -147,10 +159,10 @@ class CMenuDestroyer
147 CMenu *_menu; 159 CMenu *_menu;
148public: 160public:
149 CMenuDestroyer(CMenu &menu): _menu(&menu) {} 161 CMenuDestroyer(CMenu &menu): _menu(&menu) {}
150 CMenuDestroyer(): _menu(0) {} 162 CMenuDestroyer(): _menu(NULL) {}
151 ~CMenuDestroyer() { if (_menu) _menu->Destroy(); } 163 ~CMenuDestroyer() { if (_menu) _menu->Destroy(); }
152 void Attach(CMenu &menu) { _menu = &menu; } 164 void Attach(CMenu &menu) { _menu = &menu; }
153 void Disable() { _menu = 0; } 165 void Disable() { _menu = NULL; }
154}; 166};
155 167
156} 168}