1 #ifndef DALI_INTERNAL_KEY_EVENT_H
2 #define DALI_INTERNAL_KEY_EVENT_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/events/key-event.h>
23 #include <dali/public-api/object/base-object.h>
30 typedef IntrusivePtr<KeyEvent> KeyEventPtr;
33 * @copydoc Dali::KeyEvent
35 class KeyEvent : public BaseObject
39 * @brief Default constructor.
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
58 KeyEvent(const std::string& keyName,
59 const std::string& logicalKey,
60 const std::string& keyString,
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);
71 * Create a new default KeyEvent.
72 * @return A smart-pointer to the newly allocated KeyEvent.
74 static KeyEventPtr New();
77 * Create a new KeyEvent.
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.
92 static KeyEventPtr New(const std::string& keyName,
93 const std::string& logicalKey,
94 const std::string& keyString,
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);
105 * @copydoc Dali::KeyEvent::IsShiftModifier()
107 bool IsShiftModifier() const;
110 * @copydoc Dali::KeyEvent::IsCtrlModifier()
112 bool IsCtrlModifier() const;
115 * @copydoc Dali::KeyEvent::IsAltModifier()
117 bool IsAltModifier() const;
120 * @copydoc Dali::KeyEvent::IsNoInterceptModifier()
122 bool IsNoInterceptModifier() const;
125 * @copydoc Dali::KeyEvent::GetCompose()
127 const std::string& GetCompose() const;
130 * @copydoc Dali::KeyEvent::GetDeviceName()
132 const std::string& GetDeviceName() const;
135 * @copydoc Dali::KeyEvent::GetDeviceClass()
137 Device::Class::Type GetDeviceClass() const;
140 * @copydoc Dali::KeyEvent::GetDeviceSubclass()
142 Device::Subclass::Type GetDeviceSubclass() const;
145 * @copydoc Dali::KeyEvent::GetKeyName()
147 const std::string& GetKeyName() const;
150 * @copydoc Dali::KeyEvent::GetKeyString()
152 const std::string& GetKeyString() const;
155 * @copydoc Dali::KeyEvent::GetLogicalKey()
157 const std::string& GetLogicalKey() const;
160 * @copydoc Dali::KeyEvent::GetKeyCode()
162 int32_t GetKeyCode() const;
165 * @copydoc Dali::KeyEvent::GetKeyModifier()
167 int32_t GetKeyModifier() const;
170 * @copydoc Dali::KeyEvent::GetTime()
172 unsigned long GetTime() const;
175 * @copydoc Dali::KeyEvent::GetState()
177 Dali::KeyEvent::State GetState() const;
180 * @copydoc Dali::KeyEvent::IsRepeat()
182 bool IsRepeat() const;
185 * @copydoc Dali::KeyEvent::GetWindowId()
187 uint32_t GetWindowId() const;
190 * @brief Set the name given to the key pressed
192 * @param[in] keyName The name given to the key pressed.
194 void SetKeyName(const std::string& keyName);
197 * @brief Set the actual string of input characters that should be used for input editors.
199 * @param[in] The actual string of input characters
201 void SetKeyString(const std::string& keyString);
204 * @brief Set the unique key code for the key pressed.
206 * @param[in] keyCode The unique key code for the key pressed
208 void SetKeyCode(int32_t keyCode);
211 * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
213 * @param[in] keyModifier The key modifier
215 void SetKeyModifier(int32_t keyModifier);
218 * @brief Set the no-intercept key modifier.
220 * @param[in] noIntercept The value of the modifier
222 void SetNoInterceptModifier(bool noIntercept);
225 * @brief Set the time (in ms) that the key event occurred.
227 * @param[in] time The time (in ms)
229 void SetTime(unsigned long time);
232 * @brief Set the state of the key event.
234 * @param[in] state The state of the key event
236 void SetState(const Dali::KeyEvent::State& state);
239 * @brief Set whether to repeat key event.
241 * @param[in] repeat Whether the key event is a repeating key.
243 void SetRepeat(const bool repeat);
246 * @brief Sets window id where key event occurred.
248 * @param[in] windowId The window id where key event occurred
250 void SetWindowId(uint32_t windowId);
257 * A reference counted object may only be deleted by calling Unreference()
259 ~KeyEvent() override = default;
261 // Not copyable or movable
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
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.
284 } // namespace Internal
286 // Helpers for public-api forwarding methods
288 inline Internal::KeyEvent& GetImplementation(Dali::KeyEvent& keyEvent)
290 DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
292 BaseObject& object = keyEvent.GetBaseObject();
294 return static_cast<Internal::KeyEvent&>(object);
297 inline const Internal::KeyEvent& GetImplementation(const Dali::KeyEvent& keyEvent)
299 DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
301 const BaseObject& object = keyEvent.GetBaseObject();
303 return static_cast<const Internal::KeyEvent&>(object);
308 #endif // DALI_INTERNAL_KEY_EVENT_H