KeyEvent.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 #ifndef Pt_Forms_KeyEvent_h
30 #define Pt_Forms_KeyEvent_h
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/Widget.h>
34 #include <Pt/Forms/Key.h>
35 #include <Pt/Event.h>
36 #include <Pt/String.h>
37 
38 namespace Pt {
39 
40 namespace Forms {
41 
42 class PT_FORMS_API KeyEvent : public Pt::BasicEvent<KeyEvent>
43 {
44  public:
45  enum Action
46  {
47  Press,
48  Release
49  };
50 
51  public:
52  KeyEvent()
53  : _widgetId_(0)
54  , _widget(0)
55  , _action(Release)
56  {
57  }
58 
59  explicit KeyEvent(Widget& widget)
60  : _widgetId_( widget.id() )
61  , _widget(&widget)
62  , _action(Release)
63  {
64  }
65 
66  Pt::uint64_t widgetId() const
67  {
68  return _widgetId_;
69  }
70 
71  Widget* widget() const
72  {
73  return _widget;
74  }
75 
76  void setWidget(Widget* widget)
77  {
78  _widget = widget;
79  _widgetId_ = widget ? widget->id() : 0;
80  }
81 
82  const Key& key() const
83  {
84  return _key;
85  }
86 
87  const Pt::Char& unicode() const
88  {
89  return _unicode;
90  }
91 
92  bool isPress() const
93  {
94  return _action == Press;
95  }
96 
97  void setPress(const Key& key, const Pt::Char& ch)
98  {
99  _action = Press;
100  _key = key;
101  _unicode = ch;
102  }
103 
104  bool isRelease() const
105  {
106  return _action == Release;
107  }
108 
109  void setRelease(const Key& key, const Pt::Char& ch)
110  {
111  _action = Release;
112  _key = key;
113  _unicode = ch;
114  }
115 
116  private:
117  Pt::uint64_t _widgetId_;
118  Widget* _widget;
119  Action _action;
120  Key _key;
121  Pt::Char _unicode;
122 };
123 
124 } // namespace
125 
126 } // namespace
127 
128 #endif
129 
Unicode character type.
Definition: String.h:66
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54