Revert "[Tizen] Not execute the remove callback"
[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) 2021 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 KeyEvent.
72    *
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.
85    */
86   static KeyEventPtr New(const std::string&           keyName,
87                          const std::string&           logicalKey,
88                          const std::string&           keyString,
89                          int                          keyCode,
90                          int                          keyModifier,
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);
97
98   /**
99    * @copydoc Dali::KeyEvent::IsShiftModifier()
100    */
101   bool IsShiftModifier() const;
102
103   /**
104    * @copydoc Dali::KeyEvent::IsCtrlModifier()
105    */
106   bool IsCtrlModifier() const;
107
108   /**
109    * @copydoc Dali::KeyEvent::IsAltModifier()
110    */
111   bool IsAltModifier() const;
112
113   /**
114    * @copydoc Dali::KeyEvent::GetCompose()
115    */
116   const std::string& GetCompose() const;
117
118   /**
119    * @copydoc Dali::KeyEvent::GetDeviceName()
120    */
121   const std::string& GetDeviceName() const;
122
123   /**
124    * @copydoc Dali::KeyEvent::GetDeviceClass()
125    */
126   Device::Class::Type GetDeviceClass() const;
127
128   /**
129    * @copydoc Dali::KeyEvent::GetDeviceSubclass()
130    */
131   Device::Subclass::Type GetDeviceSubclass() const;
132
133   /**
134    * @copydoc Dali::KeyEvent::GetKeyName()
135    */
136   const std::string& GetKeyName() const;
137
138   /**
139    * @copydoc Dali::KeyEvent::GetKeyString()
140    */
141   const std::string& GetKeyString() const;
142
143   /**
144    * @copydoc Dali::KeyEvent::GetLogicalKey()
145    */
146   const std::string& GetLogicalKey() const;
147
148   /**
149    * @copydoc Dali::KeyEvent::GetKeyCode()
150    */
151   int32_t GetKeyCode() const;
152
153   /**
154    * @copydoc Dali::KeyEvent::GetKeyModifier()
155    */
156   int32_t GetKeyModifier() const;
157
158   /**
159    * @copydoc Dali::KeyEvent::GetTime()
160    */
161   unsigned long GetTime() const;
162
163   /**
164    * @copydoc Dali::KeyEvent::GetState()
165    */
166   Dali::KeyEvent::State GetState() const;
167
168   /**
169    * @brief Set the name given to the key pressed
170    *
171    * @param[in] keyName The name given to the key pressed.
172    */
173   void SetKeyName(const std::string& keyName);
174
175   /**
176    * @brief Set the actual string of input characters that should be used for input editors.
177    *
178    * @param[in] The actual string of input characters
179    */
180   void SetKeyString(const std::string& keyString);
181
182   /**
183    * @brief Set the unique key code for the key pressed.
184    *
185    * @param[in] keyCode The unique key code for the key pressed
186    */
187   void SetKeyCode(int32_t keyCode);
188
189   /**
190    * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
191    *
192    * @param[in] keyModifier The key modifier
193    */
194   void SetKeyModifier(int32_t keyModifier);
195
196   /**
197    * @brief Set the time (in ms) that the key event occurred.
198    *
199    * @param[in] time The time (in ms)
200    */
201   void SetTime(unsigned long time);
202
203   /**
204    * @brief Set the state of the key event.
205    *
206    * @param[in] state The state of the key event
207    */
208   void SetState(const Dali::KeyEvent::State& state);
209
210 private:
211   /**
212    * @brief Destructor.
213    *
214    * A reference counted object may only be deleted by calling Unreference()
215    */
216   ~KeyEvent() override = default;
217
218   // Not copyable or movable
219
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
224
225 private:
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
237 };
238
239 } // namespace Internal
240
241 // Helpers for public-api forwarding methods
242
243 inline Internal::KeyEvent& GetImplementation(Dali::KeyEvent& keyEvent)
244 {
245   DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
246
247   BaseObject& object = keyEvent.GetBaseObject();
248
249   return static_cast<Internal::KeyEvent&>(object);
250 }
251
252 inline const Internal::KeyEvent& GetImplementation(const Dali::KeyEvent& keyEvent)
253 {
254   DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
255
256   const BaseObject& object = keyEvent.GetBaseObject();
257
258   return static_cast<const Internal::KeyEvent&>(object);
259 }
260
261 } // namespace Dali
262
263 #endif // DALI_INTERNAL_KEY_EVENT_H