YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ycontrol.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2010 - 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_ycontrol_h_
29 #define YSL_INC_UI_ycontrol_h_ 1
30 
31 #include "ywidget.h"
32 #include "ywgtevt.h"
33 
35 
37 
38 using namespace Drawing;
39 
46 {
47 protected:
49 
50 public:
51  explicit
52  Controller(bool b)
53  : AController(b), EventMap()
54  {}
56  template<typename... _tParams>
57  Controller(bool b, _tParams&&... args)
58  : AController(b), EventMap(yforward(args)...)
59  {}
60 
61  ImplI(AController) PDefH(EventMapping::ItemType&, GetItem,
62  const VisualEvent& id)
63  ImplRet(EventMap.at(id))
64  EventMapping::ItemType&
65  GetItemRef(const VisualEvent&, EventMapping::MappedType(&)()) override;
66  DefGetter(const ynothrow, EventMapping::MapType&, EventMap, EventMap) \
68 
69  ImplI(AController) DefClone(const override, Controller, Clone)
70 };
71 
72 
76 inline bool
77 IsEnabled(const IWidget& wgt)
78 {
79  try
80  {
81  return wgt.GetController().IsEnabled();
82  }
83  catch(BadEvent&)
84  {}
85  return false;
86 }
87 
91 inline void
92 SetEnabledOf(IWidget& wgt, bool b)
93 {
94  try
95  {
96  wgt.GetController().SetEnabled(b);
97  }
98  catch(BadEvent&)
99  {}
100 }
101 
107 YF_API bool
108 Enable(IWidget&, bool = true);
109 
110 
114 template<VisualEvent _vID>
117 {
118  return EventMapping::MappedType(new GEventWrapper<EventT(typename
120 }
121 
128 
135 template<VisualEvent _vID>
136 EventT(typename EventTypeMapping<_vID>::HandlerType)&
138 {
139  return dynamic_cast<EventT(typename EventTypeMapping<_vID>::HandlerType)&>(
140  GetEvent(m, _vID, NewEvent<_vID>));
141 }
152 template<VisualEvent _vID>
153 EventT(typename EventTypeMapping<_vID>::HandlerType)&
154 FetchEvent(AController& controller)
155 {
156  return dynamic_cast<EventT(typename EventTypeMapping<_vID>::HandlerType)&>(
157  controller.GetItemRef(_vID, NewEvent<_vID>));
158 }
169 template<VisualEvent _vID>
170 inline EventT(typename EventTypeMapping<_vID>::HandlerType)&
172 {
173  return FetchEvent<_vID>(wgt.GetController());
174 }
175 
181 template<VisualEvent _vID, typename _tEventArgs>
182 inline size_t
183 CallEvent(IWidget& wgt, _tEventArgs&& e)
184 {
185  static_assert(std::is_same<typename std::remove_reference<_tEventArgs>
186  ::type, typename std::remove_reference<typename
188  ::value, "Invalid event argument type found @ CallEvent;");
189 
190  try
191  {
192  return DoEvent<typename EventTypeMapping<_vID>::HandlerType>(
193  wgt.GetController(), _vID, yforward(e));
194  }
195  catch(BadEvent&)
196  {}
197  return 0;
198 }
199 
200 
201 //公共事件处理器。
202 
210 template<VisualEvent _vID, class _tEventArgs>
211 inline void
212 OnEvent_Call(_tEventArgs&& e)
213 {
214  CallEvent<_vID>(e.GetSender(), e);
215 }
216 
217 /*
218 \brief 处理事件:停止事件路由。
219 \since build 285
220 */
221 template<class _tEventArgs>
222 inline void
223 OnEvent_StopRouting(_tEventArgs&& e)
224 {
225  e.Handled = true;
226 }
227 
231 YF_API void
232 OnKeyHeld(KeyEventArgs&&);
233 
243 YF_API void
244 OnTouchDown_RequestToTopFocused(TouchEventArgs&&);
245 
251 YF_API void
252 OnTouchHeld(TouchEventArgs&&);
253 
258 YF_API void
259 OnTouchMove(TouchEventArgs&&);
260 
266 YF_API void
267 OnTouchMove_Dragging(TouchEventArgs&&);
268 
269 
270 // Control 事件处理器。
271 
278 YF_API void
279 OnKey_Bound_TouchUpAndLeave(KeyEventArgs&&);
280 
287 YF_API void
288 OnKey_Bound_EnterAndTouchDown(KeyEventArgs&&);
289 
296 YF_API void
297 OnKey_Bound_Click(KeyEventArgs&&);
298 
299 
304 class YF_API Control : public Widget
305 {
306 protected:
313 
314 public:
315  //标准控件事件见 VisualEvent 。
316 
317  //其它扩展控件事件示例。
318 // DeclEvent(H1Event, Ext1) //!< 扩展事件 1 。
319 // DeclEvent(H2Event, Ext2) //!< 扩展事件 2 。
320 
321  //事件组映射。
328  std::function<IWidget*(const KeyInput&)> BoundControlPtr;
329 
335  explicit
336  Control(const Rect& = {});
344  Control(const Rect&, NoBackgroundTag);
348  Control(const Control&);
350 
351 
354  virtual PDefH(IWidget*, GetBoundControlPtr, const KeyInput&)
355  ImplRet(nullptr)
356 
362  void
363  OnTouch_Close(TouchEventArgs&&);
364 };
365 
367 
368 YSL_END
369 
370 #endif
371