YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
menu.h
浏览该文件的文档.
1 /*
2  © 2011-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YSL_INC_UI_menu_h_
29 #define YSL_INC_UI_menu_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_TextList
33 #include YFM_YSLib_UI_YUIContainer // for UI::ZOrderType;
34 
35 namespace YSLib
36 {
37 
38 namespace UI
39 {
40 
41 class MenuHost;
42 
43 const ZOrderType DefaultMenuZOrder(224);
44 
45 
50 class YF_API Menu : public TextList
51 {
52  friend class MenuHost;
53 
54 public:
55  using ID = size_t;
56  using SubMap = map<IndexType, Menu*>;
57  using ValueType = SubMap::value_type;
58 
59 private:
60  ID id;
61 
62 protected:
66  mutable vector<bool> vDisabled;
67 
68 public:
73  explicit
74  Menu(const Rect& = {}, const shared_ptr<ListType>& = {}, ID = 0);
81 
82 
86  PDefHOp(Menu&, [], size_t idx)
87  ImplRet(*mSubMenus.at(idx))
88 
93  void
94  operator+=(const ValueType&);
95 
100  bool
101  operator-=(IndexType);
102 
108  bool
109  IsItemEnabled(ListType::size_type) const;
110 
111  DefGetter(const ynothrow, ID, ID, id)
112  DefGetter(const ynothrow, Menu*, ParentPtr, pParent)
113 
120  void
121  SetItemEnabled(ListType::size_type idx, bool = true);
122 
123 protected:
128  void
129  AdjustSize() const;
130 
131 public:
136  bool
137  CheckConfirmed(ListType::size_type) const override;
138 
144  bool
146 
152  Menu*
153  ShowSub(IndexType, ZOrderType = DefaultMenuZOrder);
154 
159  bool
160  Hide();
161 
162 protected:
167  void
168  DrawItem(const Graphics&, const Rect& mask, const Rect&,
169  ListType::size_type) override;
170 };
171 
172 
176 YF_API void
177 LocateMenu(Menu&, const Menu&, Menu::IndexType);
178 
179 
184 class YF_API MenuHost : private noncopyable, private OwnershipTag<Menu>
185 {
186 public:
187  using ItemType = Menu*;
188  using MenuMap = map<Menu::ID, ItemType>;
189  using ValueType = MenuMap::value_type;
190 
192 
193 protected:
195 
196 public:
203  map<IWidget*, Menu::ID> Roots;
204 
205  MenuHost(Window&);
210  virtual
211  ~MenuHost();
212 
217  void
218  operator+=(const ValueType&);
223  void
224  operator+=(Menu&);
225 
230  bool
231  operator-=(Menu::ID);
232 
237  PDefHOp(Menu&, [], Menu::ID id)
238  ImplRet(*mMenus.at(id))
239 
243  bool
244  IsShowing(Menu::ID);
245 
249  PDefH(bool, Contains, Menu::ID id)
250  ImplRet(ystdex::exists(mMenus, id))
254  bool
255  Contains(Menu&);
256 
261  void
262  Clear();
263 
267  void
268  Show(Menu::ID, ZOrderType = DefaultMenuZOrder);
273  PDefH(void, Show, Menu& mnu, ZOrderType z = DefaultMenuZOrder)
274  ImplExpr(YAssert(Contains(mnu), "Menu is not contained."),
275  ShowRaw(mnu, z))
276 
280  void
281  ShowAll(ZOrderType = DefaultMenuZOrder);
282 
283 private:
287  void
288  ShowRaw(Menu& mnu, ZOrderType = DefaultMenuZOrder);
289 
290 public:
294  void
295  Hide(Menu::ID);
300  PDefH(void, Hide, Menu& mnu)
301  ImplExpr(YAssert(Contains(mnu), "Menu is not contained."), HideRaw(mnu))
302 
306  void
307  HideAll();
308 
309 private:
313  void
314  HideRaw(Menu& mnu);
315 
316 public:
323  void
324  HideUnrelated(Menu& mnu, Menu& mnuParent);
325 };
326 
327 } // namespace UI;
328 
329 } // namespace YSLib;
330 
331 #endif
332 
bool return true
Definition: DSMain.cpp:177
指定对于参数指定类型的成员具有所有权的标签。
Definition: yobject.h:47
Window & Frame
框架窗口。
Definition: menu.h:191
#define YF_API
Definition: Platform.h:64
YF_API void LocateMenu(Menu &, const Menu &, Menu::IndexType)
定位菜单:以第二个参数作为参考父菜单,按指定参考偏移索引定位菜单。
Definition: menu.cpp:228
窗口。
Definition: ywindow.h:44
YF_API void Hide(IWidget &)
隐藏部件。
Definition: ywidget.cpp:103
map< IndexType, Menu * > SubMap
子菜单映射表类型。
Definition: menu.h:56
菜单宿主。
Definition: menu.h:184
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
YF_API void Show(IWidget &)
显示部件。
Definition: ywidget.cpp:206
virtual bool CheckConfirmed(ListType::size_type) const
检查列表中的指定项是否有效。
size_t ID
菜单标识类型。
Definition: menu.h:55
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活:使用指定屏幕、有效性、前景色和默认背景色。
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
#define ImplExpr(...)
Definition: YBaseMacro.h:93
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
SubMap::value_type ValueType
子菜单映射表项目类型。
Definition: menu.h:57
map< IWidget *, Menu::ID > Roots
根菜单关联映射。
Definition: menu.h:203
表示菜单键(如 Menu 和 Win )。
Definition: Keys.h:129
Menu * pParent
父菜单指针。
Definition: menu.h:64
u8 ZOrderType
Definition: yuicont.h:146
virtual void DrawItem(const Graphics &, const Rect &mask, const Rect &, ListType::size_type)
绘制列表项。
二维图形接口上下文。
Definition: ygdibase.h:721
vector< bool > vDisabled
未启用菜单项。
Definition: menu.h:66
MenuMap mMenus
菜单组:存储非空菜单指针。
Definition: menu.h:194
Selected const shared_ptr< ListType > const pair< Color, Color > viewer Contains
Definition: textlist.h:124
文本菜单。
Definition: menu.h:50
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
MenuHost * pHost
宿主指针。
Definition: menu.h:63
map< Menu::ID, ItemType > MenuMap
菜单组类型。
Definition: menu.h:188
bool exists(const _tCon &con, const _tKey &key)
判断指定的容器中存在指定的键。
Definition: container.hpp:373
const ZOrderType DefaultMenuZOrder(224)
默认菜单 Z 顺序值。
ID id
菜单标识。
Definition: menu.h:60
SubMap mSubMenus
子菜单映射表:存储非空子菜单指针。
Definition: menu.h:65
#define YAssert(_expr, _msg)
Definition: cassert.h:73
yimpl(u32) ID
消息标识。
Definition: ymsg.h:46
#define DefDelMoveCtor(_t)
Definition: YBaseMacro.h:143