[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/key-event-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 namespace Dali
25 {
26 namespace
27 {
28 const uint32_t MODIFIER_SHIFT        = 0x1;
29 const uint32_t MODIFIER_CTRL         = 0x2;
30 const uint32_t MODIFIER_ALT          = 0x4;
31 const uint32_t MODIFIER_NO_INTERCEPT = (1U << 31);
32 const int32_t  KEY_INVALID_CODE      = -1;
33 } // namespace
34
35 namespace Internal
36 {
37 KeyEvent::KeyEvent()
38 : mKeyName(""),
39   mLogicalKey(""),
40   mKeyString(""),
41   mKeyCode(KEY_INVALID_CODE),
42   mKeyModifier(0),
43   mTime(0),
44   mState(Dali::KeyEvent::DOWN),
45   mCompose(""),
46   mDeviceName(""),
47   mDeviceClass(Device::Class::NONE),
48   mDeviceSubclass(Device::Subclass::NONE),
49   mIsRepeat(false),
50   mWindowId(0)
51 {
52 }
53
54 KeyEvent::KeyEvent(const std::string&           keyName,
55                    const std::string&           logicalKey,
56                    const std::string&           keyString,
57                    int                          keyCode,
58                    int                          keyModifier,
59                    unsigned long                timeStamp,
60                    const Dali::KeyEvent::State& keyState,
61                    const std::string&           compose,
62                    const std::string&           deviceName,
63                    const Device::Class::Type    deviceClass,
64                    const Device::Subclass::Type deviceSubclass)
65 : mKeyName(keyName),
66   mLogicalKey(logicalKey),
67   mKeyString(keyString),
68   mKeyCode(keyCode),
69   mKeyModifier(keyModifier),
70   mTime(timeStamp),
71   mState(keyState),
72   mCompose(compose),
73   mDeviceName(deviceName),
74   mDeviceClass(deviceClass),
75   mDeviceSubclass(deviceSubclass),
76   mIsRepeat(false),
77   mWindowId(0)
78 {
79 }
80
81 KeyEventPtr KeyEvent::New()
82 {
83   KeyEventPtr keyEvent = new KeyEvent();
84   return keyEvent;
85 }
86
87 KeyEventPtr KeyEvent::New(const std::string&           keyName,
88                           const std::string&           logicalKey,
89                           const std::string&           keyString,
90                           int                          keyCode,
91                           int                          keyModifier,
92                           unsigned long                timeStamp,
93                           const Dali::KeyEvent::State& keyState,
94                           const std::string&           compose,
95                           const std::string&           deviceName,
96                           const Device::Class::Type    deviceClass,
97                           const Device::Subclass::Type deviceSubclass)
98 {
99   KeyEventPtr keyEvent = new KeyEvent(keyName, logicalKey, keyString, keyCode, keyModifier, timeStamp, keyState, compose, deviceName, deviceClass, deviceSubclass);
100   return keyEvent;
101 }
102
103 bool KeyEvent::IsShiftModifier() const
104 {
105   return ((MODIFIER_SHIFT & mKeyModifier) == MODIFIER_SHIFT);
106 }
107
108 bool KeyEvent::IsCtrlModifier() const
109 {
110   return ((MODIFIER_CTRL & mKeyModifier) == MODIFIER_CTRL);
111 }
112
113 bool KeyEvent::IsAltModifier() const
114 {
115   return ((MODIFIER_ALT & mKeyModifier) == MODIFIER_ALT);
116 }
117
118 bool KeyEvent::IsNoInterceptModifier() const
119 {
120   return ((MODIFIER_NO_INTERCEPT & mKeyModifier) == MODIFIER_NO_INTERCEPT);
121 }
122
123 const std::string& KeyEvent::GetCompose() const
124 {
125   return mCompose;
126 }
127
128 const std::string& KeyEvent::GetDeviceName() const
129 {
130   return mDeviceName;
131 }
132
133 Device::Class::Type KeyEvent::GetDeviceClass() const
134 {
135   return mDeviceClass;
136 }
137
138 Device::Subclass::Type KeyEvent::GetDeviceSubclass() const
139 {
140   return mDeviceSubclass;
141 }
142
143 const std::string& KeyEvent::GetKeyName() const
144 {
145   return mKeyName;
146 }
147
148 const std::string& KeyEvent::GetKeyString() const
149 {
150   return mKeyString;
151 }
152
153 const std::string& KeyEvent::GetLogicalKey() const
154 {
155   return mLogicalKey;
156 }
157
158 int32_t KeyEvent::GetKeyCode() const
159 {
160   return mKeyCode;
161 }
162
163 int32_t KeyEvent::GetKeyModifier() const
164 {
165   return mKeyModifier;
166 }
167
168 unsigned long KeyEvent::GetTime() const
169 {
170   return mTime;
171 }
172
173 Dali::KeyEvent::State KeyEvent::GetState() const
174 {
175   return mState;
176 }
177
178 bool KeyEvent::IsRepeat() const
179 {
180   return mIsRepeat;
181 }
182
183 uint32_t KeyEvent::GetWindowId() const
184 {
185   return mWindowId;
186 }
187
188 void KeyEvent::SetKeyName(const std::string& keyName)
189 {
190   mKeyName = keyName;
191 }
192
193 void KeyEvent::SetKeyString(const std::string& keyString)
194 {
195   mKeyString = keyString;
196 }
197
198 void KeyEvent::SetKeyCode(int32_t keyCode)
199 {
200   mKeyCode = keyCode;
201 }
202
203 void KeyEvent::SetKeyModifier(int32_t keyModifier)
204 {
205   mKeyModifier = keyModifier;
206 }
207
208 void KeyEvent::SetNoInterceptModifier(bool noIntercept)
209 {
210   if(noIntercept)
211   {
212     mKeyModifier |= MODIFIER_NO_INTERCEPT;
213   }
214   else
215   {
216     mKeyModifier &= ~MODIFIER_NO_INTERCEPT;
217   }
218 }
219
220 void KeyEvent::SetTime(unsigned long time)
221 {
222   mTime = time;
223 }
224
225 void KeyEvent::SetState(const Dali::KeyEvent::State& state)
226 {
227   mState = state;
228 }
229
230 void KeyEvent::SetRepeat(const bool repeat)
231 {
232   mIsRepeat = repeat;
233 }
234
235 void KeyEvent::SetWindowId(uint32_t windowId)
236 {
237   mWindowId = windowId;
238 }
239
240 } // namespace Internal
241
242 } // namespace Dali