YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
menu.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2011 - 2013.
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 "textlist.h"
32 #include "yuicont.h" // for UI::ZOrderType;
33 
35 
37 
38 class MenuHost;
39 
40 const ZOrderType DefaultMenuZOrder(224);
41 
42 
47 class YF_API Menu : public TextList
48 {
49  friend class MenuHost;
50 
51 public:
52  typedef size_t ID;
53  typedef map<IndexType, Menu*> SubMap;
54  typedef SubMap::value_type ValueType;
55 
56 private:
57  ID id;
58 
59 protected:
60  MenuHost* pHost;
62  SubMap mSubMenus;
63  mutable vector<bool> vDisabled;
64 
65 public:
70  explicit
71  Menu(const Rect& = {}, const shared_ptr<ListType>& = {}, ID = 0);
77  DefDelMoveCtor(Menu)
78 
79 
83  PDefHOp(Menu&, [], size_t idx)
84  ImplRet(*mSubMenus.at(idx))
85 
90  void
91  operator+=(const ValueType&);
92 
97  bool
98  operator-=(IndexType);
99 
105  bool
106  IsItemEnabled(ListType::size_type) const;
107 
108  DefGetter(const ynothrow, ID, ID, id)
109  DefGetter(const ynothrow, Menu*, ParentPtr, pParent)
110 
117  void
118  SetItemEnabled(ListType::size_type idx, bool = true);
119 
120 protected:
125  void
126  AdjustSize() const;
127 
128 public:
133  bool
134  CheckConfirmed(ListType::size_type) const override;
135 
141  bool
142  Show(ZOrderType = DefaultMenuZOrder);
143 
149  Menu*
150  ShowSub(IndexType, ZOrderType = DefaultMenuZOrder);
151 
156  bool
157  Hide();
158 
159 protected:
164  void
165  DrawItem(const Graphics&, const Rect& mask, const Rect&,
166  ListType::size_type) override;
167 };
168 
169 
173 YF_API void
174 LocateMenu(Menu&, const Menu&, Menu::IndexType);
175 
176 
181 class YF_API MenuHost : private noncopyable, private OwnershipTag<Menu>
182 {
183 public:
184  typedef Menu* ItemType;
185  typedef map<Menu::ID, ItemType> MenuMap;
186  typedef MenuMap::value_type ValueType;
187 
189 
190 protected:
191  MenuMap mMenus;
192 
193 public:
200  map<IWidget*, Menu::ID> Roots;
201 
202  MenuHost(Window&);
207  virtual
208  ~MenuHost();
209 
214  void
215  operator+=(const ValueType&);
220  void
221  operator+=(Menu&);
222 
227  bool
228  operator-=(Menu::ID);
229 
234  PDefHOp(Menu&, [], Menu::ID id)
235  ImplRet(*mMenus.at(id))
236 
240  bool
241  IsShowing(Menu::ID);
242 
247  ImplRet(mMenus.find(id) != mMenus.end())
251  bool
252  Contains(Menu&);
253 
258  void
259  Clear();
260 
264  void
265  Show(Menu::ID, ZOrderType = DefaultMenuZOrder);
270  void
271  Show(Menu& mnu, ZOrderType z = DefaultMenuZOrder)
272  {
273  YAssert(Contains(mnu), "Menu is not contained.");
274 
275  ShowRaw(mnu, z);
276  }
277 
281  void
282  ShowAll(ZOrderType = DefaultMenuZOrder);
283 
284 private:
288  void
289  ShowRaw(Menu& mnu, ZOrderType = DefaultMenuZOrder);
290 
291 public:
295  void
296  Hide(Menu::ID);
301  void
302  Hide(Menu& mnu)
303  {
304  YAssert(Contains(mnu), "Menu is not contained.");
305 
306  HideRaw(mnu);
307  }
308 
312  void
313  HideAll();
314 
315 private:
319  void
320  HideRaw(Menu& mnu);
321 
322 public:
329  void
330  HideUnrelated(Menu& mnu, Menu& mnuParent);
331 };
332 
334 
335 YSL_END
336 
337 #endif
338