LIBURANIA
GUI library (a wrapper of Win32 API) in C++
読み取り中…
検索中…
一致する文字列を見つけられません
menu.h
[詳解]
1/*
2 * Copyright 2002-2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
43#ifndef INCLUDE_GUARD_URANIA_MENU_H
44#define INCLUDE_GUARD_URANIA_MENU_H
45
46// windows.hのmin/maxマクロの抑止
47#ifndef NOMINMAX
48#define NOMINMAX
49#endif
50
51#include <vector>
52#include <string>
53#include <memory>
54#include <windows.h>
55#include <eunomia/noncopyable.h>
56#include "decl.h"
57
58
61{
62 friend class urania::Menu;
63
64public:
65 class Node_
66 {
67 friend class MenuDesc;
68
69 public:
70 enum
71 {
73 MN_SEPARATOR = -1
74 };
75
76 private:
77 std::vector<Node_> ary_;
78 std::wstring name_;
79 int id_;
80
81 Node_() noexcept : id_(MN_SEPARATOR) {}
82 Node_(const std::wstring& s) noexcept : name_(s), id_(MN_BRANCH) {}
83 Node_(const std::wstring& s, int i) noexcept : name_(s), id_(i) {}
84
85 public:
86 ~Node_() = default;
87
89 bool addSeparator();
90
92 bool addPopup(const std::wstring& s);
93
97 bool addPopup(const std::wstring& s, int i);
98
99 Node_& operator[](int i) { return ary_[i]; }
100 const Node_& operator[](int i) const { return ary_[i]; }
101 };
102
103private:
104 std::vector<Node_> node_;
105
106public:
107 MenuDesc() = default;
108 ~MenuDesc() = default;
109
111 bool addPopup(const std::wstring& s);
112
116 bool addPopup(const std::wstring& s, int i);
117
118 Node_& operator[](int i) { return node_[i]; }
119 const Node_& operator[](int i) const { return node_[i]; }
120
121private:
123 HMENU createHandle_() const;
124
128 static void addPopupMenu_(HMENU pm, const Node_& item);
129};
130
131
133class urania::Menu : eunomia::Noncopyable<urania::Menu>
134{
135 friend class urania::Window;
136
137private:
138 HMENU hmenu_;
139 bool dst_;
140
141 Menu() : hmenu_(NULL), dst_(false) {}
142
147 void link_(HMENU h)
148 {
149 attach_(h);
150 if (hmenu_)
151 dst_ = true;
152 }
153
158 void kill_()
159 {
160 if (dst_ && hmenu_)
161 ::DestroyMenu(hmenu_);
162 detach_();
163 }
164
169 void attach_(HMENU h)
170 {
171 kill_();
172 hmenu_ = h;
173 }
174
178 void detach_()
179 {
180 hmenu_ = NULL;
181 dst_ = false;
182 }
183
188 HMENU giveHM_()
189 {
190 dst_ = false;
191 return hmenu_;
192 }
193
194
195public:
196 ~Menu() { kill_(); }
197
201 static std::shared_ptr<urania::Menu> create(const urania::MenuDesc& desc);
202
206 static std::shared_ptr<urania::Menu> create(int rc);
207
209 std::shared_ptr<urania::Menu> getSub(unsigned id);
210
211
213 void checkItem(unsigned cmdid);
214
216 void uncheckItem(unsigned cmdid);
217
219 bool getItemCheck(unsigned cmdid);
220
221
223 void enableItem(unsigned cmdid);
224
226 void disableItem(unsigned cmdid);
227
229 void grayItem(unsigned cmdid);
230};
231
232
233
234
235#endif // INCLUDE_GUARD_URANIA_MENU_H
Definition menu.h:66
@ MN_BRANCH
Definition menu.h:72
@ MN_SEPARATOR
Definition menu.h:73
const Node_ & operator[](int i) const
Definition menu.h:100
Node_ & operator[](int i)
Definition menu.h:99
bool addPopup(const std::wstring &s)
ポップアップ項目(メニューツリーの枝部分)の追加
Definition menudesc.cpp:104
bool addSeparator()
區切り線の追加
Definition menudesc.cpp:95
メニュー記述用クラス
Definition menu.h:61
Node_ & operator[](int i)
Definition menu.h:118
const Node_ & operator[](int i) const
Definition menu.h:119
MenuDesc()=default
~MenuDesc()=default
bool addPopup(const std::wstring &s)
ポップアップ項目(メニューツリーの枝部分)の追加
Definition menudesc.cpp:38
メニューハンドル(HMENU)のラッパー
Definition menu.h:134
void grayItem(unsigned cmdid)
項目の淡色表示(選擇不可能)化
Definition menu.cpp:110
static std::shared_ptr< urania::Menu > create(const urania::MenuDesc &desc)
生成
Definition menudesc.cpp:128
void disableItem(unsigned cmdid)
項目の選擇不可能化
Definition menu.cpp:99
std::shared_ptr< urania::Menu > getSub(unsigned id)
サブメニューの取得
Definition menu.cpp:47
void checkItem(unsigned cmdid)
指定項目のチェックの設定
Definition menu.cpp:62
bool getItemCheck(unsigned cmdid)
指定項目のチェックの有無の取得
Definition menu.cpp:76
void enableItem(unsigned cmdid)
項目の選擇可能化
Definition menu.cpp:92
~Menu()
Definition menu.h:196
void uncheckItem(unsigned cmdid)
指定項目のチェックの解除
Definition menu.cpp:69
ウィンドウ
Definition window.h:260
各種宣言