[Tizen] Fix svace/coverity issue (key events constructor)
[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 int32_t  KEY_INVALID_CODE = -1;
32 } // namespace
33
34 namespace Internal
35 {
36 KeyEvent::KeyEvent()
37 : mKeyName(""),
38   mLogicalKey(""),
39   mKeyString(""),
40   mKeyCode(KEY_INVALID_CODE),
41   mKeyModifier(0),
42   mTime(0),
43   mState(Dali::KeyEvent::DOWN),
44   mCompose(""),
45   mDeviceName(""),
46   mDeviceClass(Device::Class::NONE),
47   mDeviceSubclass(Device::Subclass::NONE),
48   mIsRepeat(false)
49 {
50 }
51
52 KeyEvent::KeyEvent(const std::string&           keyName,
53                    const std::string&           logicalKey,
54                    const std::string&           keyString,
55                    int                          keyCode,
56                    int                          keyModifier,
57                    unsigned long                timeStamp,
58                    const Dali::KeyEvent::State& keyState,
59                    const std::string&           compose,
60                    const std::string&           deviceName,
61                    const Device::Class::Type    deviceClass,
62                    const Device::Subclass::Type deviceSubclass)
63 : mKeyName(keyName),
64   mLogicalKey(logicalKey),
65   mKeyString(keyString),
66   mKeyCode(keyCode),
67   mKeyModifier(keyModifier),
68   mTime(timeStamp),
69   mState(keyState),
70   mCompose(compose),
71   mDeviceName(deviceName),
72   mDeviceClass(deviceClass),
73   mDeviceSubclass(deviceSubclass),
74   mIsRepeat(false)
75 {
76 }
77
78 KeyEventPtr KeyEvent::New(const std::string&           keyName,
79                           const std::string&           logicalKey,
80                           const std::string&           keyString,
81                           int                          keyCode,
82                           int                          keyModifier,
83                           unsigned long                timeStamp,
84                           const Dali::KeyEvent::State& keyState,
85                           const std::string&           compose,
86                           const std::string&           deviceName,
87                           const Device::Class::Type    deviceClass,
88                           const Device::Subclass::Type deviceSubclass)
89 {
90   KeyEventPtr keyEvent = new KeyEvent(keyName, logicalKey, keyString, keyCode, keyModifier, timeStamp, keyState, compose, deviceName, deviceClass, deviceSubclass);
91   return keyEvent;
92 }
93
94 bool KeyEvent::IsShiftModifier() const
95 {
96   return ((MODIFIER_SHIFT & mKeyModifier) == MODIFIER_SHIFT);
97 }
98
99 bool KeyEvent::IsCtrlModifier() const
100 {
101   return ((MODIFIER_CTRL & mKeyModifier) == MODIFIER_CTRL);
102 }
103
104 bool KeyEvent::IsAltModifier() const
105 {
106   return ((MODIFIER_ALT & mKeyModifier) == MODIFIER_ALT);
107 }
108
109 const std::string& KeyEvent::GetCompose() const
110 {
111   return mCompose;
112 }
113
114 const std::string& KeyEvent::GetDeviceName() const
115 {
116   return mDeviceName;
117 }
118
119 Device::Class::Type KeyEvent::GetDeviceClass() const
120 {
121   return mDeviceClass;
122 }
123
124 Device::Subclass::Type KeyEvent::GetDeviceSubclass() const
125 {
126   return mDeviceSubclass;
127 }
128
129 const std::string& KeyEvent::GetKeyName() const
130 {
131   return mKeyName;
132 }
133
134 const std::string& KeyEvent::GetKeyString() const
135 {
136   return mKeyString;
137 }
138
139 const std::string& KeyEvent::GetLogicalKey() const
140 {
141   return mLogicalKey;
142 }
143
144 int32_t KeyEvent::GetKeyCode() const
145 {
146   return mKeyCode;
147 }
148
149 int32_t KeyEvent::GetKeyModifier() const
150 {
151   return mKeyModifier;
152 }
153
154 unsigned long KeyEvent::GetTime() const
155 {
156   return mTime;
157 }
158
159 Dali::KeyEvent::State KeyEvent::GetState() const
160 {
161   return mState;
162 }
163
164 bool KeyEvent::IsRepeat() const
165 {
166   return mIsRepeat;
167 }
168
169 void KeyEvent::SetKeyName(const std::string& keyName)
170 {
171   mKeyName = keyName;
172 }
173
174 void KeyEvent::SetKeyString(const std::string& keyString)
175 {
176   mKeyString = keyString;
177 }
178
179 void KeyEvent::SetKeyCode(int32_t keyCode)
180 {
181   mKeyCode = keyCode;
182 }
183
184 void KeyEvent::SetKeyModifier(int32_t keyModifier)
185 {
186   mKeyModifier = keyModifier;
187 }
188
189 void KeyEvent::SetTime(unsigned long time)
190 {
191   mTime = time;
192 }
193
194 void KeyEvent::SetState(const Dali::KeyEvent::State& state)
195 {
196   mState = state;
197 }
198
199 void KeyEvent::SetRepeat(const bool repeat)
200 {
201   mIsRepeat = repeat;
202 }
203
204 } // namespace Internal
205
206 } // namespace Dali