Revert "[Tizen] Adding deviceClass to KeyEvent Integ"
[platform/core/uifw/dali-core.git] / dali / public-api / events / key-event.cpp
1 /*
2  * Copyright (c) 2015 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/public-api/events/key-event.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/events/key-event-devel.h>
23 #include <dali/devel-api/common/map-wrapper.h>
24
25 namespace Dali
26 {
27
28 namespace
29 {
30 const unsigned int MODIFIER_SHIFT = 0x1;
31 const unsigned int MODIFIER_CTRL  = 0x2;
32 const unsigned int MODIFIER_ALT   = 0x4;
33 const int KEY_INVALID_CODE = -1;
34
35 struct KeyEventImpl
36 {
37   KeyEventImpl()
38     :deviceName("")
39   {
40   };
41
42   KeyEventImpl& operator=( const KeyEventImpl& rhs )
43   {
44     if( this != &rhs )
45     {
46       deviceName = rhs.deviceName;
47     }
48
49     return *this;
50   }
51
52   KeyEventImpl( const KeyEventImpl& rhs )
53   {
54     deviceName =  rhs.deviceName;
55   }
56
57   std::string deviceName;
58 };
59
60 typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
61 typedef KeyEventMap::const_iterator KeyEventMapIter;
62
63
64 KeyEventMap keyEventImplMap;
65
66 }
67
68 KeyEvent::KeyEvent()
69 : keyPressedName(""),
70   keyPressed(""),
71   keyCode(KEY_INVALID_CODE),
72   keyModifier(0),
73   time(0),
74   state(KeyEvent::Down)
75 {
76   KeyEventImpl* impl = new KeyEventImpl;
77   keyEventImplMap[this] = impl;
78 }
79
80 KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier,unsigned long timeStamp, const State& keyState)
81 : keyPressedName(keyName),
82   keyPressed(keyString),
83   keyCode(keyCode),
84   keyModifier(keyModifier),
85   time(timeStamp),
86   state(keyState)
87 {
88   keyEventImplMap[this] = new KeyEventImpl;
89 }
90
91 KeyEvent::KeyEvent( const KeyEvent& rhs )
92 : keyPressedName( rhs.keyPressedName ),
93   keyPressed( rhs.keyPressed ),
94   keyCode( rhs.keyCode ),
95   keyModifier( rhs.keyModifier ),
96   time( rhs.time ),
97   state( rhs.state )
98 {
99   keyEventImplMap[this] = new KeyEventImpl( *keyEventImplMap[ &rhs ] );
100 }
101
102 KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
103 {
104   if( this != &rhs )
105   {
106     keyPressedName = rhs.keyPressedName;
107     keyPressed = rhs.keyPressed;
108     keyCode = rhs.keyCode;
109     keyModifier = rhs.keyModifier;
110     time = rhs.time;
111     state = rhs.state;
112
113     *keyEventImplMap[ this ] = *keyEventImplMap[ &rhs ];
114   }
115
116   return *this;
117 }
118
119 KeyEvent::~KeyEvent()
120 {
121   delete keyEventImplMap[this];
122   keyEventImplMap.erase( this );
123 }
124
125 bool KeyEvent::IsShiftModifier() const
126 {
127   if ((MODIFIER_SHIFT & keyModifier) == MODIFIER_SHIFT)
128   {
129     return true;
130   }
131
132   return false;
133 }
134
135 bool KeyEvent::IsCtrlModifier() const
136 {
137   if ((MODIFIER_CTRL & keyModifier) == MODIFIER_CTRL)
138   {
139     return true;
140   }
141
142   return false;
143 }
144
145 bool KeyEvent::IsAltModifier() const
146 {
147   if ((MODIFIER_ALT & keyModifier) == MODIFIER_ALT)
148   {
149     return true;
150   }
151
152   return false;
153 }
154
155 std::string DevelKeyEvent::GetDeviceName( const KeyEvent& keyEvent )
156 {
157   KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
158
159   if( search != keyEventImplMap.end())
160   {
161     return search->second->deviceName;
162   }
163
164   return std::string("");
165 }
166
167 void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName )
168 {
169   KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
170
171   if( search != keyEventImplMap.end())
172   {
173     search->second->deviceName = deviceName;
174   }
175 }
176
177
178 } // namespace Dali