1 #ifndef DALI_INTERNAL_KEY_EVENT_H
2 #define DALI_INTERNAL_KEY_EVENT_H
5 * Copyright (c) 2021 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 KeyEvent.
73 * @param[in] keyName The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
74 * @param[in] logicalKey The logical key symbol (eg. shift + 1 == "exclamation")
75 * @param[in] keyString The string of input characters or key pressed
76 * @param[in] keyCode The unique key code for the key pressed.
77 * @param[in] keyModifier The key modifier for special keys like shift and alt
78 * @param[in] timeStamp The time (in ms) that the key event occurred.
79 * @param[in] keyState The state of the key event.
80 * @param[in] compose The key compose
81 * @param[in] deviceName The name of device the key event originated from
82 * @param[in] deviceClass The class of device the key event originated from
83 * @param[in] deviceSubclass The subclass of device the key event originated from
84 * @return A smart-pointer to the newly allocated KeyEvent.
86 static KeyEventPtr New(const std::string& keyName,
87 const std::string& logicalKey,
88 const std::string& keyString,
91 unsigned long timeStamp,
92 const Dali::KeyEvent::State& keyState,
93 const std::string& compose,
94 const std::string& deviceName,
95 const Device::Class::Type deviceClass,
96 const Device::Subclass::Type deviceSubclass);
99 * @copydoc Dali::KeyEvent::IsShiftModifier()
101 bool IsShiftModifier() const;
104 * @copydoc Dali::KeyEvent::IsCtrlModifier()
106 bool IsCtrlModifier() const;
109 * @copydoc Dali::KeyEvent::IsAltModifier()
111 bool IsAltModifier() const;
114 * @copydoc Dali::KeyEvent::GetCompose()
116 const std::string& GetCompose() const;
119 * @copydoc Dali::KeyEvent::GetDeviceName()
121 const std::string& GetDeviceName() const;
124 * @copydoc Dali::KeyEvent::GetDeviceClass()
126 Device::Class::Type GetDeviceClass() const;
129 * @copydoc Dali::KeyEvent::GetDeviceSubclass()
131 Device::Subclass::Type GetDeviceSubclass() const;
134 * @copydoc Dali::KeyEvent::GetKeyName()
136 const std::string& GetKeyName() const;
139 * @copydoc Dali::KeyEvent::GetKeyString()
141 const std::string& GetKeyString() const;
144 * @copydoc Dali::KeyEvent::GetLogicalKey()
146 const std::string& GetLogicalKey() const;
149 * @copydoc Dali::KeyEvent::GetKeyCode()
151 int32_t GetKeyCode() const;
154 * @copydoc Dali::KeyEvent::GetKeyModifier()
156 int32_t GetKeyModifier() const;
159 * @copydoc Dali::KeyEvent::GetTime()
161 unsigned long GetTime() const;
164 * @copydoc Dali::KeyEvent::GetState()
166 Dali::KeyEvent::State GetState() const;
169 * @brief Set the name given to the key pressed
171 * @param[in] keyName The name given to the key pressed.
173 void SetKeyName(const std::string& keyName);
176 * @brief Set the actual string of input characters that should be used for input editors.
178 * @param[in] The actual string of input characters
180 void SetKeyString(const std::string& keyString);
183 * @brief Set the unique key code for the key pressed.
185 * @param[in] keyCode The unique key code for the key pressed
187 void SetKeyCode(int32_t keyCode);
190 * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
192 * @param[in] keyModifier The key modifier
194 void SetKeyModifier(int32_t keyModifier);
197 * @brief Set the time (in ms) that the key event occurred.
199 * @param[in] time The time (in ms)
201 void SetTime(unsigned long time);
204 * @brief Set the state of the key event.
206 * @param[in] state The state of the key event
208 void SetState(const Dali::KeyEvent::State& state);
214 * A reference counted object may only be deleted by calling Unreference()
216 ~KeyEvent() override = default;
218 // Not copyable or movable
220 KeyEvent(const KeyEvent& rhs) = delete; ///< Deleted copy constructor
221 KeyEvent(KeyEvent&& rhs) = delete; ///< Deleted move constructor
222 KeyEvent& operator=(const KeyEvent& rhs) = delete; ///< Deleted copy assignment operator
223 KeyEvent& operator=(KeyEvent&& rhs) = delete; ///< Deleted move assignment operator
226 std::string mKeyName; ///< The name of the key pressed
227 std::string mLogicalKey; ///< The logical key symbol
228 std::string mKeyString; ///< The string of input characters
229 int mKeyCode; ///< TThe unique key code
230 int mKeyModifier; ///< The key modifier
231 unsigned long mTime; ///< The time that the key event occurred.
232 Dali::KeyEvent::State mState; ///< The state of the key event.
233 std::string mCompose; ///< The key compose
234 std::string mDeviceName; ///< The name of device the key event originated from
235 Device::Class::Type mDeviceClass; ///< The class of device the key event originated from
236 Device::Subclass::Type mDeviceSubclass; ///< The subclass of device the key event originated from
239 } // namespace Internal
241 // Helpers for public-api forwarding methods
243 inline Internal::KeyEvent& GetImplementation(Dali::KeyEvent& keyEvent)
245 DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
247 BaseObject& object = keyEvent.GetBaseObject();
249 return static_cast<Internal::KeyEvent&>(object);
252 inline const Internal::KeyEvent& GetImplementation(const Dali::KeyEvent& keyEvent)
254 DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
256 const BaseObject& object = keyEvent.GetBaseObject();
258 return static_cast<const Internal::KeyEvent&>(object);
263 #endif // DALI_INTERNAL_KEY_EVENT_H