use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.h
1 #ifndef DALI_INTERNAL_KEY_EVENT_H
2 #define DALI_INTERNAL_KEY_EVENT_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/key-event.h>
23 #include <dali/public-api/object/base-object.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class KeyEvent;
32 typedef IntrusivePtr< KeyEvent > KeyEventPtr;
33
34 /**
35  * @copydoc Dali::KeyEvent
36  */
37 class KeyEvent : public BaseObject
38 {
39 public:
40
41   /**
42    * @brief Default constructor.
43    */
44   KeyEvent();
45
46   /**
47    * @brief Constructor.
48    *
49    * @param[in]  keyName         The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
50    * @param[in]  logicalKey      The logical key symbol (eg. shift + 1 == "exclamation")
51    * @param[in]  keyString       The string of input characters or key pressed
52    * @param[in]  keyCode         The unique key code for the key pressed.
53    * @param[in]  keyModifier     The key modifier for special keys like shift and alt
54    * @param[in]  timeStamp       The time (in ms) that the key event occurred.
55    * @param[in]  keyState        The state of the key event.
56    * @param[in]  compose         The key compose
57    * @param[in]  deviceName      The name of device the key event originated from
58    * @param[in]  deviceClass     The class of device the key event originated from
59    * @param[in]  deviceSubclass  The subclass of device the key event originated from
60    */
61   KeyEvent( const std::string& keyName,
62             const std::string& logicalKey,
63             const std::string& keyString,
64             int keyCode,
65             int keyModifier,
66             unsigned long timeStamp,
67             const Dali::KeyEvent::State& keyState,
68             const std::string& compose,
69             const std::string& deviceName,
70             const Device::Class::Type deviceClass,
71             const Device::Subclass::Type deviceSubclass );
72
73   /**
74    * Create a new KeyEvent.
75    *
76    * @param[in]  keyName         The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
77    * @param[in]  logicalKey      The logical key symbol (eg. shift + 1 == "exclamation")
78    * @param[in]  keyString       The string of input characters or key pressed
79    * @param[in]  keyCode         The unique key code for the key pressed.
80    * @param[in]  keyModifier     The key modifier for special keys like shift and alt
81    * @param[in]  timeStamp       The time (in ms) that the key event occurred.
82    * @param[in]  keyState        The state of the key event.
83    * @param[in]  compose         The key compose
84    * @param[in]  deviceName      The name of device the key event originated from
85    * @param[in]  deviceClass     The class of device the key event originated from
86    * @param[in]  deviceSubclass  The subclass of device the key event originated from
87    * @return A smart-pointer to the newly allocated KeyEvent.
88    */
89   static KeyEventPtr New( const std::string& keyName,
90                           const std::string& logicalKey,
91                           const std::string& keyString,
92                           int keyCode,
93                           int keyModifier,
94                           unsigned long timeStamp,
95                           const Dali::KeyEvent::State& keyState,
96                           const std::string& compose,
97                           const std::string& deviceName,
98                           const Device::Class::Type deviceClass,
99                           const Device::Subclass::Type deviceSubclass );
100
101   /**
102    * @copydoc Dali::KeyEvent::IsShiftModifier()
103    */
104   bool IsShiftModifier() const;
105
106   /**
107    * @copydoc Dali::KeyEvent::IsCtrlModifier()
108    */
109   bool IsCtrlModifier() const;
110
111   /**
112    * @copydoc Dali::KeyEvent::IsAltModifier()
113    */
114   bool IsAltModifier() const;
115
116   /**
117    * @copydoc Dali::KeyEvent::GetCompose()
118    */
119   const std::string& GetCompose() const;
120
121   /**
122    * @copydoc Dali::KeyEvent::GetDeviceName()
123    */
124   const std::string& GetDeviceName() const;
125
126   /**
127    * @copydoc Dali::KeyEvent::GetDeviceClass()
128    */
129   Device::Class::Type GetDeviceClass() const;
130
131   /**
132    * @copydoc Dali::KeyEvent::GetDeviceSubclass()
133    */
134   Device::Subclass::Type GetDeviceSubclass() const;
135
136   /**
137    * @copydoc Dali::KeyEvent::GetKeyName()
138    */
139   const std::string& GetKeyName() const;
140
141   /**
142    * @copydoc Dali::KeyEvent::GetKeyString()
143    */
144   const std::string& GetKeyString() const;
145
146   /**
147    * @copydoc Dali::KeyEvent::GetLogicalKey()
148    */
149   const std::string& GetLogicalKey() const;
150
151   /**
152    * @copydoc Dali::KeyEvent::GetKeyCode()
153    */
154   int32_t GetKeyCode() const;
155
156   /**
157    * @copydoc Dali::KeyEvent::GetKeyModifier()
158    */
159   int32_t GetKeyModifier() const;
160
161   /**
162    * @copydoc Dali::KeyEvent::GetTime()
163    */
164   unsigned long GetTime() const;
165
166   /**
167    * @copydoc Dali::KeyEvent::GetState()
168    */
169   Dali::KeyEvent::State GetState() const;
170
171   /**
172    * @brief Set the name given to the key pressed
173    *
174    * @param[in] keyName The name given to the key pressed.
175    */
176   void SetKeyName( const std::string& keyName );
177
178   /**
179    * @brief Set the actual string of input characters that should be used for input editors.
180    *
181    * @param[in] The actual string of input characters
182    */
183   void SetKeyString( const std::string& keyString );
184
185   /**
186    * @brief Set the unique key code for the key pressed.
187    *
188    * @param[in] keyCode The unique key code for the key pressed
189    */
190   void SetKeyCode( int32_t keyCode );
191
192   /**
193    * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
194    *
195    * @param[in] keyModifier The key modifier
196    */
197   void SetKeyModifier( int32_t keyModifier );
198
199   /**
200    * @brief Set the time (in ms) that the key event occurred.
201    *
202    * @param[in] time The time (in ms)
203    */
204   void SetTime( unsigned long time );
205
206   /**
207    * @brief Set the state of the key event.
208    *
209    * @param[in] state The state of the key event
210    */
211   void SetState( const Dali::KeyEvent::State& state );
212
213 private:
214
215   /**
216    * @brief Destructor.
217    *
218    * A reference counted object may only be deleted by calling Unreference()
219    */
220   ~KeyEvent() override = default;
221
222   // Not copyable or movable
223
224   KeyEvent( const KeyEvent& rhs ) = delete;             ///< Deleted copy constructor
225   KeyEvent( KeyEvent&& rhs ) = delete;                  ///< Deleted move constructor
226   KeyEvent& operator=( const KeyEvent& rhs ) = delete;  ///< Deleted copy assignment operator
227   KeyEvent& operator=( KeyEvent&& rhs ) = delete;       ///< Deleted move assignment operator
228
229 private:
230
231   std::string mKeyName;                      ///< The name of the key pressed
232   std::string mLogicalKey;                   ///< The logical key symbol
233   std::string mKeyString;                    ///< The string of input characters
234   int  mKeyCode;                             ///< TThe unique key code
235   int  mKeyModifier;                         ///< The key modifier
236   unsigned long mTime;                       ///< The time that the key event occurred.
237   Dali::KeyEvent::State mState;              ///< The state of the key event.
238   std::string mCompose;                      ///< The key compose
239   std::string mDeviceName;                   ///< The name of device the key event originated from
240   Device::Class::Type mDeviceClass;          ///< The class of device the key event originated from
241   Device::Subclass::Type mDeviceSubclass;    ///< The subclass of device the key event originated from
242 };
243
244 } // namespace Internal
245
246 // Helpers for public-api forwarding methods
247
248 inline Internal::KeyEvent& GetImplementation( Dali::KeyEvent& keyEvent )
249 {
250   DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
251
252   BaseObject& object = keyEvent.GetBaseObject();
253
254   return static_cast< Internal::KeyEvent& >( object );
255 }
256
257 inline const Internal::KeyEvent& GetImplementation( const Dali::KeyEvent& keyEvent )
258 {
259   DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
260
261   const BaseObject& object = keyEvent.GetBaseObject();
262
263   return static_cast< const Internal::KeyEvent& >( object );
264 }
265
266 } // namespace Dali
267
268 #endif // DALI_INTERNAL_KEY_EVENT_H