view_action.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include <memory>
32 
33 namespace clan
34 {
35  class EventUI;
36  class PointerEvent;
37  class ActivationChangeEvent;
38  class FocusChangeEvent;
39  class KeyEvent;
40  class View;
41  class ViewActionImpl;
42 
44  class ViewAction : public std::enable_shared_from_this<ViewAction>
45  {
46  public:
47  ViewAction();
48  virtual ~ViewAction();
49 
51  View *view() const;
52 
53  template<typename T>
54  T *view() const { return dynamic_cast<T*>(view<View>()); }
55 
57  void remove_from_view();
58 
60  void begin_action();
61 
63  void end_action();
64 
66  bool action_active() const;
67 
69  virtual void any_event(EventUI *e) { }
70 
72  virtual void pointer_press(PointerEvent &e) { }
73 
75  virtual void pointer_double_click(PointerEvent &e) { }
76 
78  virtual void pointer_release(PointerEvent &e) { }
79 
81  virtual void pointer_move(PointerEvent &e) { }
82 
84  virtual void pointer_enter(PointerEvent &e) { }
85 
87  virtual void pointer_leave(PointerEvent &e) { }
88 
91 
93  virtual void activated(ActivationChangeEvent &e) { }
94 
96  virtual void deactivated(ActivationChangeEvent &e) { }
97 
99  virtual void focus_gained(FocusChangeEvent &e) { }
100 
102  virtual void focus_lost(FocusChangeEvent &e) { }
103 
105  virtual void key_press(KeyEvent &e) { }
106 
108  virtual void key_release(KeyEvent &e) { }
109 
110  private:
111  ViewAction(const ViewAction &) = delete;
112  ViewAction &operator=(const ViewAction &) = delete;
113 
114  std::unique_ptr<ViewActionImpl> impl;
115 
116  friend class ViewTree;
117  friend class View;
118  friend class ViewActionImpl;
119  };
120 }
void begin_action()
Captures events until end is called.
Definition: clanapp.h:35
View for an area of the user interface.
Definition: view.h:65
virtual void key_release(KeyEvent &e)
Handler for key release events.
Definition: view_action.h:108
virtual void pointer_enter(PointerEvent &e)
Handler for pointer enter events.
Definition: view_action.h:84
Pointer event.
Definition: pointer_event.h:67
View focus changed event.
Definition: focus_change_event.h:43
virtual void pointer_proximity_change(PointerEvent &e)
Handler for pointer proximity change events.
Definition: view_action.h:90
virtual void pointer_release(PointerEvent &e)
Handler for pointer release events.
Definition: view_action.h:78
virtual void activated(ActivationChangeEvent &e)
Handler for when the application is activated.
Definition: view_action.h:93
Base class for events being dispatched through the view hiarchy.
Definition: UI/Events/event.h:47
virtual void pointer_leave(PointerEvent &e)
Handler for pointer leave events.
Definition: view_action.h:87
virtual void pointer_move(PointerEvent &e)
Handler for pointer movement events.
Definition: view_action.h:81
T * view() const
Definition: view_action.h:54
View * view() const
Returns the view the action is attached to.
virtual void any_event(EventUI *e)
Handler for any UI event.
Definition: view_action.h:69
Recognizes actions in a view and captures input for the duration of the action.
Definition: view_action.h:44
virtual ~ViewAction()
virtual void focus_gained(FocusChangeEvent &e)
Handler for focus gained events.
Definition: view_action.h:99
void remove_from_view()
Removes recognizer from the view it is attached to.
friend class ViewActionImpl
Definition: view_action.h:118
virtual void deactivated(ActivationChangeEvent &e)
Handler for when the application is deactivated.
Definition: view_action.h:96
Base class for managing a tree of views.
Definition: view_tree.h:41
virtual void key_press(KeyEvent &e)
Handler for key press events.
Definition: view_action.h:105
Keyboard key event.
Definition: key_event.h:47
Window was activated or deactivated event.
Definition: activation_change_event.h:43
virtual void pointer_double_click(PointerEvent &e)
Handler for pointer double click events.
Definition: view_action.h:75
bool action_active() const
Returns true if the action is capturing events.
void end_action()
Releases capture of events.
virtual void focus_lost(FocusChangeEvent &e)
Handler for focus lost events.
Definition: view_action.h:102
virtual void pointer_press(PointerEvent &e)
Handler for pointer press events.
Definition: view_action.h:72