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;
42 KeyEventImpl& operator=( const KeyEventImpl& rhs )
46 deviceName = rhs.deviceName;
52 KeyEventImpl( const KeyEventImpl& rhs )
54 deviceName = rhs.deviceName;
57 std::string deviceName;
60 typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
61 typedef KeyEventMap::const_iterator KeyEventMapIter;
64 KeyEventMap keyEventImplMap;
71 keyCode(KEY_INVALID_CODE),
76 KeyEventImpl* impl = new KeyEventImpl;
77 keyEventImplMap[this] = impl;
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),
84 keyModifier(keyModifier),
88 keyEventImplMap[this] = new KeyEventImpl;
91 KeyEvent::KeyEvent( const KeyEvent& rhs )
92 : keyPressedName( rhs.keyPressedName ),
93 keyPressed( rhs.keyPressed ),
94 keyCode( rhs.keyCode ),
95 keyModifier( rhs.keyModifier ),
99 keyEventImplMap[this] = new KeyEventImpl( *keyEventImplMap[ &rhs ] );
102 KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
106 keyPressedName = rhs.keyPressedName;
107 keyPressed = rhs.keyPressed;
108 keyCode = rhs.keyCode;
109 keyModifier = rhs.keyModifier;
113 *keyEventImplMap[ this ] = *keyEventImplMap[ &rhs ];
119 KeyEvent::~KeyEvent()
121 delete keyEventImplMap[this];
122 keyEventImplMap.erase( this );
125 bool KeyEvent::IsShiftModifier() const
127 if ((MODIFIER_SHIFT & keyModifier) == MODIFIER_SHIFT)
135 bool KeyEvent::IsCtrlModifier() const
137 if ((MODIFIER_CTRL & keyModifier) == MODIFIER_CTRL)
145 bool KeyEvent::IsAltModifier() const
147 if ((MODIFIER_ALT & keyModifier) == MODIFIER_ALT)
155 std::string DevelKeyEvent::GetDeviceName( const KeyEvent& keyEvent )
157 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
159 if( search != keyEventImplMap.end())
161 return search->second->deviceName;
164 return std::string("");
167 void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName )
169 KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
171 if( search != keyEventImplMap.end())
173 search->second->deviceName = deviceName;