YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ywgtevt.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_ywgtevt_h_
29 #define YSL_INC_UI_ywgtevt_h_ 1
30 
31 #include "ycomp.h"
32 #include "../Core/yevt.hpp"
33 
35 
37 
38 
47 
48 
55 {
56 private:
58 
59 public:
60  explicit
61  UIEventArgs(IWidget& wgt)
62  : pSender(&wgt)
63  {}
68  inline DefDeCopyCtor(UIEventArgs)
69 
70 
74  inline DefDeCopyAssignment(UIEventArgs)
75 
76  DefGetter(const ynothrow, IWidget&, Sender, *pSender)
77  PDefH(void, SetSender, IWidget& wgt)
78  ImplExpr(pSender = &wgt)
79 };
80 
81 
87 struct YF_API RoutedEventArgs : public UIEventArgs
88 {
89 public:
91  typedef enum
92  {
93  Bubble = 0,
94  Tunnel = 1,
95  Direct = 2
96  } RoutingStrategy;
97 
99  bool Handled;
100 
101  RoutedEventArgs(IWidget& wgt, RoutingStrategy strategy = Direct)
102  : UIEventArgs(wgt),
103  Strategy(strategy), Handled(false)
104  {}
105 };
106 
107 
114 
115 
122 {
123 public:
129 
134  InputEventArgs(IWidget&, const KeyInput& = {}, RoutingStrategy = Direct);
135 
140  DefCvt(const ynothrow, const KeyInput&, Keys)
141 
142 
146  DefGetter(const ynothrow, const KeyInput&, Keys, Keys)
147 };
148 
149 
156 {
157 public:
158  typedef KeyInput InputType;
159 
163  KeyEventArgs(IWidget&, const InputType& = {}, RoutingStrategy = Direct);
164 };
165 
166 
172 struct YF_API TouchEventArgs : public InputEventArgs,
173  public MScreenPositionEventArgs
174 {
175 public:
177 
182  TouchEventArgs(IWidget&, const KeyInput&, const InputType& = {},
183  RoutingStrategy = Direct);
184 };
185 
186 
194 template<typename _type>
195 struct GValueEventArgs : public UIEventArgs
196 {
198  typedef _type ValueType;
199 
201 
205  template<typename... _tParams>
206  yconstfn
207  GValueEventArgs(IWidget& wgt, _tParams&&... args)
208  : UIEventArgs(wgt),
209  Value(yforward(args)...)
210  {}
211  DefCvt(const ynothrow, ValueType, Value)
212 };
213 
214 
220 struct YF_API PaintEventArgs : public UIEventArgs, public PaintContext
221 {
223  PaintEventArgs(IWidget&, const PaintContext&);
224  PaintEventArgs(IWidget&, const Drawing::Graphics&, const Drawing::Point&,
225  const Drawing::Rect&);
226 };
227 
228 
229 //事件处理器类型。
230 DeclDelegate(HUIEvent, UIEventArgs&&)
231 DeclDelegate(HInputEvent, InputEventArgs&&)
235 //DefDelegate(HPointEvent, Drawing::Point&&)
236 //DefDelegate(HSizeEvent, Size&&)
237 
238 
239 #define DefEventTypeMapping(_name, _tEventHandler) \
240  template<> \
241  struct EventTypeMapping<_name> \
242  { \
243  typedef _tEventHandler HandlerType; \
244  };
245 
246 
251 typedef enum
252 {
253 // AutoSizeChanged,
254 // BackColorChanged,
255 // ForeColorChanged,
256 // LocationChanged,
257 // MarginChanged,
258 // VisibleChanged,
259 
260 // EnabledChanged,
261 
262  //视图变更事件。
265 
266  //图形用户界面输入事件。
276 
277  //图形用户界面输出事件。
279 
280  //焦点事件。
283 
284  //边界事件。
287 // TextChanged,
288 // FontChanged,
289 // FontColorChanged,
290 // FontSizeChanged,
291 } VisualEvent;
292 
293 
294 template<VisualEvent>
296 {
297  //定义 HandlerType 的默认值可能会导致运行期 dynamic_cast 失败。
298 // typedef HEvent HandlerType;
299 };
300 
303 
313 
315 
318 
321 
322 
327 YSL_BEGIN_NAMESPACE(EventMapping)
328 
329 typedef GEventPointerWrapper<UIEventArgs&&> MappedType;
330 typedef GIHEvent<UIEventArgs&&> ItemType;
331 typedef pair<VisualEvent, MappedType> PairType;
332 typedef map<VisualEvent, MappedType> MapType;
333 typedef pair<typename MapType::iterator, bool> SearchResult; \
335 
336 YSL_END_NAMESPACE(EventMapping)
337 
338 typedef EventMapping::MapType VisualEventMap;
339 
340 
343 {};
344 
345 
351 {
352 private:
353  bool enabled;
354 
355 public:
359  AController(bool b = true)
360  : enabled(b)
361  {}
367 
368  DefPred(const ynothrow, Enabled, enabled)
369 
374  DeclIEntry(EventMapping::ItemType& GetItem(const VisualEvent&))
379  virtual EventMapping::ItemType&
380  GetItemRef(const VisualEvent& id, EventMapping::MappedType(&)())
381  {
382  return GetItem(id);
383  }
384 
385  DefSetter(bool, Enabled, enabled)
386 
387  /*
388  \brief 复制实例。
389  \since build 350
390  */
391  DeclIEntry(AController* Clone() const)
392 };
393 
394 
395 template<class _tEventHandler>
396 size_t
397 DoEvent(AController& controller, const VisualEvent& id,
398  typename _tEventHandler::EventArgsType&& e)
399 {
400  try
401  {
402  return dynamic_cast<EventT(typename _tEventHandler)&>(
403  controller.GetItem(id))(std::move(e));
404  }
405  catch(std::out_of_range&)
406  {}
407  catch(std::bad_cast&)
408  {}
409  return 0;
410 }
411 template<class _tEventHandler>
412 inline size_t
413 DoEvent(AController& controller, const VisualEvent& id,
414  typename _tEventHandler::EventArgsType& e)
415 {
416  return DoEvent<_tEventHandler>(controller, id, std::move(e));
417 }
418 
419 
425 {
426 public:
429 
433  explicit
434  WidgetController(bool = false);
435 
436  ImplI(AController) EventMapping::ItemType&
437  GetItem(const VisualEvent&);
438 
439  ImplI(AController) DefClone(const override, WidgetController, Clone)
440 };
441 
443 
444 YSL_END
445 
446 #endif
447