Adding deviceClass to KeyEvent Integ
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
1 /*
2  * Copyright (c) 2017 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/devel-api/common/map-wrapper.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29
30 typedef std::map< const KeyEvent*, Internal::KeyEventImpl*> KeyEventMap;
31 typedef KeyEventMap::iterator KeyEventMapIter;
32
33 KeyEventMap keyEventImplMap;
34
35 }
36
37 namespace Internal
38 {
39
40 KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
41 : mDeviceName( "" ),
42   mDeviceClass( DevelKeyEvent::DeviceClass::NONE )
43 {
44   keyEventImplMap[keyEvent] = this;
45 }
46
47 KeyEventImpl::~KeyEventImpl()
48 {
49   for( KeyEventMapIter iter = keyEventImplMap.begin(); iter != keyEventImplMap.end(); ++iter )
50   {
51     if( this == iter->second )
52     {
53       keyEventImplMap.erase( iter );
54       break;
55     }
56   }
57 }
58
59 KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
60 {
61   if( this != &rhs )
62   {
63     mDeviceName = rhs.mDeviceName;
64     mDeviceClass = rhs.mDeviceClass;
65   }
66
67   return *this;
68 }
69
70 std::string KeyEventImpl::GetDeviceName() const
71 {
72   return mDeviceName;
73 }
74
75 void KeyEventImpl::SetDeviceName( const std::string& deviceName )
76 {
77   mDeviceName = deviceName;
78 }
79
80 DevelKeyEvent::DeviceClass::Type KeyEventImpl::GetDeviceClass() const
81 {
82   return mDeviceClass;
83 }
84
85 void KeyEventImpl::SetDeviceClass( const DevelKeyEvent::DeviceClass::Type& deviceClass )
86 {
87   mDeviceClass = deviceClass;
88 }
89
90 } // namsespace Internal
91
92 Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
93 {
94   return keyEventImplMap[keyEvent];
95 }
96
97 const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
98 {
99   return keyEventImplMap[keyEvent];
100 }
101
102 } // namespace Dali