2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/events/key-event.h>
22 #include <dali/devel-api/events/key-event-devel.h>
23 #include <dali/devel-api/common/map-wrapper.h>
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;
39 deviceClass( DevelKeyEvent::DeviceClass::NONE )
43 KeyEventImpl& operator=( const KeyEventImpl& rhs )
47 deviceName = rhs.deviceName;
48 deviceClass = rhs.deviceClass;
54 KeyEventImpl( const KeyEventImpl& rhs )
56 deviceName = rhs.deviceName;
57 deviceClass = rhs.deviceClass;
60 std::string deviceName;
61 DevelKeyEvent::DeviceClass::Type deviceClass;
64 typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
65 typedef KeyEventMap::const_iterator KeyEventMapIter;
68 KeyEventMap keyEventImplMap;
75 keyCode(KEY_INVALID_CODE),
80 KeyEventImpl* impl = new KeyEventImpl;
81 keyEventImplMap[this] = impl;
84 KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier,unsigned long timeStamp, const State& keyState)
85 : keyPressedName(keyName),
86 keyPressed(keyString),
88 keyModifier(keyModifier),
92 keyEventImplMap[this] = new KeyEventImpl;
95 KeyEvent::KeyEvent( const KeyEvent& rhs )
96 : keyPressedName( rhs.keyPressedName ),
97 keyPressed( rhs.keyPressed ),
98 keyCode( rhs.keyCode ),
99 keyModifier( rhs.keyModifier ),
103 keyEventImplMap[this] = new KeyEventImpl( *keyEventImplMap[ &rhs ] );
106 KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
110 keyPressedName = rhs.keyPressedName;
111 keyPressed = rhs.keyPressed;
112 keyCode = rhs.keyCode;
113 keyModifier = rhs.keyModifier;
117 *keyEventImplMap[ this ] = *keyEventImplMap[ &rhs ];
123 KeyEvent::~KeyEvent()
125 delete keyEventImplMap[this];
126 keyEventImplMap.erase( this );
129 bool KeyEvent::IsShiftModifier() const
131 if ((MODIFIER_SHIFT & keyModifier) == MODIFIER_SHIFT)
139 bool KeyEvent::IsCtrlModifier() const
141 if ((MODIFIER_CTRL & keyModifier) == MODIFIER_CTRL)
149 bool KeyEvent::IsAltModifier() const
151 if ((MODIFIER_ALT & keyModifier) == MODIFIER_ALT)
159 std::string DevelKeyEvent::GetDeviceName( const KeyEvent& keyEvent )
161 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
163 if( search != keyEventImplMap.end())
165 return search->second->deviceName;
168 return std::string("");
171 void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName )
173 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
175 if( search != keyEventImplMap.end())
177 search->second->deviceName = deviceName;
181 DevelKeyEvent::DeviceClass::Type DevelKeyEvent::GetDeviceClass( const KeyEvent& keyEvent )
183 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
185 DevelKeyEvent::DeviceClass::Type result = DevelKeyEvent::DeviceClass::NONE;
187 if( search != keyEventImplMap.end() )
189 result = search->second->deviceClass;
195 void DevelKeyEvent::SetDeviceClass( KeyEvent& keyEvent, const DeviceClass::Type& deviceClass )
197 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
199 if( search != keyEventImplMap.end() )
201 search->second->deviceClass = deviceClass;