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 );
79 * Create a new KeyEvent.
81 * @param[in] keyName The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
82 * @param[in] logicalKey The logical key symbol (eg. shift + 1 == "exclamation")
83 * @param[in] keyString The string of input characters or key pressed
84 * @param[in] keyCode The unique key code for the key pressed.
85 * @param[in] keyModifier The key modifier for special keys like shift and alt
86 * @param[in] timeStamp The time (in ms) that the key event occurred.
87 * @param[in] keyState The state of the key event.
88 * @param[in] compose The key compose
89 * @param[in] deviceName The name of device the key event originated from
90 * @param[in] deviceClass The class of device the key event originated from
91 * @param[in] deviceSubclass The subclass of device the key event originated from
92 * @return A smart-pointer to the newly allocated KeyEvent.
94 static KeyEventPtr New( const std::string& keyName,
95 const std::string& logicalKey,
96 const std::string& keyString,
99 unsigned long timeStamp,
100 const Dali::KeyEvent::State& keyState,
101 const std::string& compose,
102 const std::string& deviceName,
103 const Device::Class::Type deviceClass,
104 const Device::Subclass::Type deviceSubclass );
107 * @copydoc Dali::KeyEvent::IsShiftModifier()
109 bool IsShiftModifier() const;
112 * @copydoc Dali::KeyEvent::IsCtrlModifier()
114 bool IsCtrlModifier() const;
117 * @copydoc Dali::KeyEvent::IsAltModifier()
119 bool IsAltModifier() const;
122 * @copydoc Dali::KeyEvent::GetCompose()
124 const std::string& GetCompose() const;
127 * @copydoc Dali::KeyEvent::GetDeviceName()
129 const std::string& GetDeviceName() const;
132 * @copydoc Dali::KeyEvent::GetDeviceClass()
134 Device::Class::Type GetDeviceClass() const;
137 * @copydoc Dali::KeyEvent::GetDeviceSubclass()
139 Device::Subclass::Type GetDeviceSubclass() const;
142 * @copydoc Dali::KeyEvent::GetKeyName()
144 const std::string& GetKeyName() const;
147 * @copydoc Dali::KeyEvent::GetKeyString()
149 const std::string& GetKeyString() const;
152 * @copydoc Dali::KeyEvent::GetLogicalKey()
154 const std::string& GetLogicalKey() const;
157 * @copydoc Dali::KeyEvent::GetKeyCode()
159 int32_t GetKeyCode() const;
162 * @copydoc Dali::KeyEvent::GetKeyModifier()
164 int32_t GetKeyModifier() const;
167 * @copydoc Dali::KeyEvent::GetTime()
169 unsigned long GetTime() const;
172 * @copydoc Dali::KeyEvent::GetState()
174 Dali::KeyEvent::State GetState() const;
177 * @brief Set the name given to the key pressed
179 * @param[in] keyName The name given to the key pressed.
181 void SetKeyName( const std::string& keyName );
184 * @brief Set the actual string of input characters that should be used for input editors.
186 * @param[in] The actual string of input characters
188 void SetKeyString( const std::string& keyString );
191 * @brief Set the unique key code for the key pressed.
193 * @param[in] keyCode The unique key code for the key pressed
195 void SetKeyCode( int32_t keyCode );
198 * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
200 * @param[in] keyModifier The key modifier
202 void SetKeyModifier( int32_t keyModifier );
205 * @brief Set the time (in ms) that the key event occurred.
207 * @param[in] time The time (in ms)
209 void SetTime( unsigned long time );
212 * @brief Set the state of the key event.
214 * @param[in] state The state of the key event
216 void SetState( const Dali::KeyEvent::State& state );
220 // Not copyable or movable
222 KeyEvent( const KeyEvent& rhs ) = delete; ///< Deleted copy constructor
223 KeyEvent( KeyEvent&& rhs ) = delete; ///< Deleted move constructor
224 KeyEvent& operator=( const KeyEvent& rhs ) = delete; ///< Deleted copy assignment operator
225 KeyEvent& operator=( KeyEvent&& rhs ) = delete; ///< Deleted move assignment operator
229 std::string mKeyName; ///< The name of the key pressed
230 std::string mLogicalKey; ///< The logical key symbol
231 std::string mKeyString; ///< The string of input characters
232 int mKeyCode; ///< TThe unique key code
233 int mKeyModifier; ///< The key modifier
234 unsigned long mTime; ///< The time that the key event occurred.
235 Dali::KeyEvent::State mState; ///< The state of the key event.
236 std::string mCompose; ///< The key compose
237 std::string mDeviceName; ///< The name of device the key event originated from
238 Device::Class::Type mDeviceClass; ///< The class of device the key event originated from
239 Device::Subclass::Type mDeviceSubclass; ///< The subclass of device the key event originated from
242 } // namespace Internal
244 // Helpers for public-api forwarding methods
246 inline Internal::KeyEvent& GetImplementation( Dali::KeyEvent& keyEvent )
248 DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
250 BaseObject& object = keyEvent.GetBaseObject();
252 return static_cast< Internal::KeyEvent& >( object );
255 inline const Internal::KeyEvent& GetImplementation( const Dali::KeyEvent& keyEvent )
257 DALI_ASSERT_ALWAYS( keyEvent && "Key Event handle is empty" );
259 const BaseObject& object = keyEvent.GetBaseObject();
261 return static_cast< const Internal::KeyEvent& >( object );
266 #endif // DALI_INTERNAL_KEY_EVENT_H