[dali_2.3.27] Merge branch 'devel/master'
[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) 2023 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 namespace Internal
28 {
29 class KeyEvent;
30 typedef IntrusivePtr<KeyEvent> KeyEventPtr;
31
32 /**
33  * @copydoc Dali::KeyEvent
34  */
35 class KeyEvent : public BaseObject
36 {
37 public:
38   /**
39    * @brief Default constructor.
40    */
41   KeyEvent();
42
43   /**
44    * @brief Constructor.
45    *
46    * @param[in]  keyName         The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
47    * @param[in]  logicalKey      The logical key symbol (eg. shift + 1 == "exclamation")
48    * @param[in]  keyString       The string of input characters or key pressed
49    * @param[in]  keyCode         The unique key code for the key pressed.
50    * @param[in]  keyModifier     The key modifier for special keys like shift and alt
51    * @param[in]  timeStamp       The time (in ms) that the key event occurred.
52    * @param[in]  keyState        The state of the key event.
53    * @param[in]  compose         The key compose
54    * @param[in]  deviceName      The name of device the key event originated from
55    * @param[in]  deviceClass     The class of device the key event originated from
56    * @param[in]  deviceSubclass  The subclass of device the key event originated from
57    */
58   KeyEvent(const std::string&           keyName,
59            const std::string&           logicalKey,
60            const std::string&           keyString,
61            int                          keyCode,
62            int                          keyModifier,
63            unsigned long                timeStamp,
64            const Dali::KeyEvent::State& keyState,
65            const std::string&           compose,
66            const std::string&           deviceName,
67            const Device::Class::Type    deviceClass,
68            const Device::Subclass::Type deviceSubclass);
69
70   /**
71    * Create a new default KeyEvent.
72    * @return A smart-pointer to the newly allocated KeyEvent.
73    */
74   static KeyEventPtr New();
75
76   /**
77    * Create a new KeyEvent.
78    *
79    * @param[in]  keyName         The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
80    * @param[in]  logicalKey      The logical key symbol (eg. shift + 1 == "exclamation")
81    * @param[in]  keyString       The string of input characters or key pressed
82    * @param[in]  keyCode         The unique key code for the key pressed.
83    * @param[in]  keyModifier     The key modifier for special keys like shift and alt
84    * @param[in]  timeStamp       The time (in ms) that the key event occurred.
85    * @param[in]  keyState        The state of the key event.
86    * @param[in]  compose         The key compose
87    * @param[in]  deviceName      The name of device the key event originated from
88    * @param[in]  deviceClass     The class of device the key event originated from
89    * @param[in]  deviceSubclass  The subclass of device the key event originated from
90    * @return A smart-pointer to the newly allocated KeyEvent.
91    */
92   static KeyEventPtr New(const std::string&           keyName,
93                          const std::string&           logicalKey,
94                          const std::string&           keyString,
95                          int                          keyCode,
96                          int                          keyModifier,
97                          unsigned long                timeStamp,
98                          const Dali::KeyEvent::State& keyState,
99                          const std::string&           compose,
100                          const std::string&           deviceName,
101                          const Device::Class::Type    deviceClass,
102                          const Device::Subclass::Type deviceSubclass);
103
104   /**
105    * @copydoc Dali::KeyEvent::IsShiftModifier()
106    */
107   bool IsShiftModifier() const;
108
109   /**
110    * @copydoc Dali::KeyEvent::IsCtrlModifier()
111    */
112   bool IsCtrlModifier() const;
113
114   /**
115    * @copydoc Dali::KeyEvent::IsAltModifier()
116    */
117   bool IsAltModifier() const;
118
119   /**
120    * @copydoc Dali::KeyEvent::IsNoInterceptModifier()
121    */
122   bool IsNoInterceptModifier() const;
123
124   /**
125    * @copydoc Dali::KeyEvent::GetCompose()
126    */
127   const std::string& GetCompose() const;
128
129   /**
130    * @copydoc Dali::KeyEvent::GetDeviceName()
131    */
132   const std::string& GetDeviceName() const;
133
134   /**
135    * @copydoc Dali::KeyEvent::GetDeviceClass()
136    */
137   Device::Class::Type GetDeviceClass() const;
138
139   /**
140    * @copydoc Dali::KeyEvent::GetDeviceSubclass()
141    */
142   Device::Subclass::Type GetDeviceSubclass() const;
143
144   /**
145    * @copydoc Dali::KeyEvent::GetKeyName()
146    */
147   const std::string& GetKeyName() const;
148
149   /**
150    * @copydoc Dali::KeyEvent::GetKeyString()
151    */
152   const std::string& GetKeyString() const;
153
154   /**
155    * @copydoc Dali::KeyEvent::GetLogicalKey()
156    */
157   const std::string& GetLogicalKey() const;
158
159   /**
160    * @copydoc Dali::KeyEvent::GetKeyCode()
161    */
162   int32_t GetKeyCode() const;
163
164   /**
165    * @copydoc Dali::KeyEvent::GetKeyModifier()
166    */
167   int32_t GetKeyModifier() const;
168
169   /**
170    * @copydoc Dali::KeyEvent::GetTime()
171    */
172   unsigned long GetTime() const;
173
174   /**
175    * @copydoc Dali::KeyEvent::GetState()
176    */
177   Dali::KeyEvent::State GetState() const;
178
179   /**
180    * @copydoc Dali::KeyEvent::IsRepeat()
181    */
182   bool IsRepeat() const;
183
184   /**
185    * @copydoc Dali::KeyEvent::GetWindowId()
186    */
187   uint32_t GetWindowId() const;
188
189   /**
190    * @brief Set the name given to the key pressed
191    *
192    * @param[in] keyName The name given to the key pressed.
193    */
194   void SetKeyName(const std::string& keyName);
195
196   /**
197    * @brief Set the actual string of input characters that should be used for input editors.
198    *
199    * @param[in] The actual string of input characters
200    */
201   void SetKeyString(const std::string& keyString);
202
203   /**
204    * @brief Set the unique key code for the key pressed.
205    *
206    * @param[in] keyCode The unique key code for the key pressed
207    */
208   void SetKeyCode(int32_t keyCode);
209
210   /**
211    * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
212    *
213    * @param[in] keyModifier The key modifier
214    */
215   void SetKeyModifier(int32_t keyModifier);
216
217   /**
218    * @brief Set the no-intercept key modifier.
219    *
220    * @param[in] noIntercept The value of the modifier
221    */
222   void SetNoInterceptModifier(bool noIntercept);
223
224   /**
225    * @brief Set the time (in ms) that the key event occurred.
226    *
227    * @param[in] time The time (in ms)
228    */
229   void SetTime(unsigned long time);
230
231   /**
232    * @brief Set the state of the key event.
233    *
234    * @param[in] state The state of the key event
235    */
236   void SetState(const Dali::KeyEvent::State& state);
237
238   /**
239    * @brief Set whether to repeat key event.
240    *
241    * @param[in] repeat Whether the key event is a repeating key.
242    */
243   void SetRepeat(const bool repeat);
244
245   /**
246    * @brief Sets window id where key event occurred.
247    *
248    * @param[in] windowId The window id where key event occurred
249    */
250   void SetWindowId(uint32_t windowId);
251
252
253 private:
254   /**
255    * @brief Destructor.
256    *
257    * A reference counted object may only be deleted by calling Unreference()
258    */
259   ~KeyEvent() override = default;
260
261   // Not copyable or movable
262
263   KeyEvent(const KeyEvent& rhs) = delete;            ///< Deleted copy constructor
264   KeyEvent(KeyEvent&& rhs)      = delete;            ///< Deleted move constructor
265   KeyEvent& operator=(const KeyEvent& rhs) = delete; ///< Deleted copy assignment operator
266   KeyEvent& operator=(KeyEvent&& rhs) = delete;      ///< Deleted move assignment operator
267
268 private:
269   std::string            mKeyName;        ///< The name of the key pressed
270   std::string            mLogicalKey;     ///< The logical key symbol
271   std::string            mKeyString;      ///< The string of input characters
272   int                    mKeyCode;        ///< TThe unique key code
273   int                    mKeyModifier;    ///< The key modifier
274   unsigned long          mTime;           ///< The time that the key event occurred.
275   Dali::KeyEvent::State  mState;          ///< The state of the key event.
276   std::string            mCompose;        ///< The key compose
277   std::string            mDeviceName;     ///< The name of device the key event originated from
278   Device::Class::Type    mDeviceClass;    ///< The class of device the key event originated from
279   Device::Subclass::Type mDeviceSubclass; ///< The subclass of device the key event originated from
280   bool                   mIsRepeat;       ///< Whether the key referenced by the event is a repeating key.
281   uint32_t               mWindowId;       ///< The window id where key event occurred.
282 };
283
284 } // namespace Internal
285
286 // Helpers for public-api forwarding methods
287
288 inline Internal::KeyEvent& GetImplementation(Dali::KeyEvent& keyEvent)
289 {
290   DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
291
292   BaseObject& object = keyEvent.GetBaseObject();
293
294   return static_cast<Internal::KeyEvent&>(object);
295 }
296
297 inline const Internal::KeyEvent& GetImplementation(const Dali::KeyEvent& keyEvent)
298 {
299   DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
300
301   const BaseObject& object = keyEvent.GetBaseObject();
302
303   return static_cast<const Internal::KeyEvent&>(object);
304 }
305
306 } // namespace Dali
307
308 #endif // DALI_INTERNAL_KEY_EVENT_H