1 #ifndef DALI_INTERNAL_KEY_EVENT_H
2 #define DALI_INTERNAL_KEY_EVENT_H
5 * Copyright (c) 2020 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>
32 typedef IntrusivePtr< KeyEvent > KeyEventPtr;
35 * @copydoc Dali::KeyEvent
37 class KeyEvent : public BaseObject
42 * @brief Default constructor.
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
61 KeyEvent( const std::string& keyName,
62 const std::string& logicalKey,
63 const std::string& keyString,
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 );
74 * Create a new KeyEvent.
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.
89 static KeyEventPtr New( const std::string& keyName,
90 const std::string& logicalKey,
91 const std::string& keyString,
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 );
102 * @copydoc Dali::KeyEvent::IsShiftModifier()
104 bool IsShiftModifier() const;
107 * @copydoc Dali::KeyEvent::IsCtrlModifier()
109 bool IsCtrlModifier() const;
112 * @copydoc Dali::KeyEvent::IsAltModifier()
114 bool IsAltModifier() const;
117 * @copydoc Dali::KeyEvent::GetCompose()
119 const std::string& GetCompose() const;
122 * @copydoc Dali::KeyEvent::GetDeviceName()
124 const std::string& GetDeviceName() const;
127 * @copydoc Dali::KeyEvent::GetDeviceClass()
129 Device::Class::Type GetDeviceClass() const;
132 * @copydoc Dali::KeyEvent::GetDeviceSubclass()
134 Device::Subclass::Type GetDeviceSubclass() const;
137 * @copydoc Dali::KeyEvent::GetKeyName()
139 const std::string& GetKeyName() const;
142 * @copydoc Dali::KeyEvent::GetKeyString()
144 const std::string& GetKeyString() const;
147 * @copydoc Dali::KeyEvent::GetLogicalKey()
149 const std::string& GetLogicalKey() const;
152 * @copydoc Dali::KeyEvent::GetKeyCode()
154 int32_t GetKeyCode() const;
157 * @copydoc Dali::KeyEvent::GetKeyModifier()
159 int32_t GetKeyModifier() const;
162 * @copydoc Dali::KeyEvent::GetTime()
164 unsigned long GetTime() const;
167 * @copydoc Dali::KeyEvent::GetState()
169 Dali::KeyEvent::State GetState() const;
172 * @brief Set the name given to the key pressed
174 * @param[in] keyName The name given to the key pressed.
176 void SetKeyName( const std::string& keyName );
179 * @brief Set the actual string of input characters that should be used for input editors.
181 * @param[in] The actual string of input characters
183 void SetKeyString( const std::string& keyString );
186 * @brief Set the unique key code for the key pressed.
188 * @param[in] keyCode The unique key code for the key pressed
190 void SetKeyCode( int32_t keyCode );
193 * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
195 * @param[in] keyModifier The key modifier
197 void SetKeyModifier( int32_t keyModifier );
200 * @brief Set the time (in ms) that the key event occurred.
202 * @param[in] time The time (in ms)
204 void SetTime( unsigned long time );
207 * @brief Set the state of the key event.
209 * @param[in] state The state of the key event
211 void SetState( const Dali::KeyEvent::State& state );
218 * A reference counted object may only be deleted by calling Unreference()
220 ~KeyEvent() override = default;
222 // Not copyable or movable
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
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
244 } // namespace Internal
246 // Helpers for public-api forwarding methods
248 inline Internal::KeyEvent& GetImplementation( Dali::KeyEvent& keyEvent )
250 DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
252 BaseObject& object = keyEvent.GetBaseObject();
254 return static_cast< Internal::KeyEvent& >( object );
257 inline const Internal::KeyEvent& GetImplementation( const Dali::KeyEvent& keyEvent )
259 DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
261 const BaseObject& object = keyEvent.GetBaseObject();
263 return static_cast< const Internal::KeyEvent& >( object );
268 #endif // DALI_INTERNAL_KEY_EVENT_H