Support compose variable for key event
[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/public-api/common/dali-vector.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29 /**
30  * This container stores a mapping between public key event and impl as we cannot add data members in public one.
31  * In practice this keeps the impl "alive" in between KeyEvent constructor and destructor calls so that getter
32  * methods can be called to access the new data members. There is a 1:1 mapping between KeyEvent and KeyEventImpl.
33  */
34 struct KeyImplMapping
35 {
36   KeyEvent* keyEvent;
37   Internal::KeyEventImpl* impl;
38 };
39 Vector< KeyImplMapping > gKeyEventToImplMapping;
40
41 }
42
43 namespace Internal
44 {
45
46 KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
47 : mCompose( "" ),
48   mDeviceName( "" ),
49   mDeviceClass( Device::Class::NONE ),
50   mDeviceSubclass( Device::Subclass::NONE )
51 {
52   gKeyEventToImplMapping.PushBack( { keyEvent, this } );
53 }
54
55 KeyEventImpl::~KeyEventImpl()
56 {
57   for( auto&& iter : gKeyEventToImplMapping )
58   {
59     if( this == iter.impl )
60     {
61       gKeyEventToImplMapping.Erase( &iter ); // iter is reference to KeyImplMapping, take address of it for Erase
62       return;
63     }
64   }
65 }
66
67 KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
68 {
69   if( this != &rhs )
70   {
71     mCompose = rhs.mCompose;
72     mDeviceName = rhs.mDeviceName;
73     mDeviceClass = rhs.mDeviceClass;
74     mDeviceSubclass = rhs.mDeviceSubclass;
75   }
76
77   return *this;
78 }
79
80 std::string KeyEventImpl::GetCompose() const
81 {
82   return mCompose;
83 }
84
85 void KeyEventImpl::SetCompose( const std::string& compose )
86 {
87   mCompose = compose;
88 }
89
90 std::string KeyEventImpl::GetDeviceName() const
91 {
92   return mDeviceName;
93 }
94
95 void KeyEventImpl::SetDeviceName( const std::string& deviceName )
96 {
97   mDeviceName = deviceName;
98 }
99
100 Device::Class::Type KeyEventImpl::GetDeviceClass() const
101 {
102   return mDeviceClass;
103 }
104
105 void KeyEventImpl::SetDeviceClass( Device::Class::Type deviceClass )
106 {
107   mDeviceClass = deviceClass;
108 }
109
110 Device::Subclass::Type KeyEventImpl::GetDeviceSubclass() const
111 {
112   return mDeviceSubclass;
113 }
114
115 void KeyEventImpl::SetDeviceSubclass( Device::Subclass::Type deviceSubclass )
116 {
117   mDeviceSubclass = deviceSubclass;
118 }
119
120 } // namsespace Internal
121
122 Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
123 {
124   Internal::KeyEventImpl* impl( NULL );
125   for( auto&& iter : gKeyEventToImplMapping )
126   {
127     if( iter.keyEvent == keyEvent )
128     {
129       impl = iter.impl;
130     }
131   }
132   return impl;
133 }
134
135 const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
136 {
137   Internal::KeyEventImpl* impl( NULL );
138   for( auto&& iter : gKeyEventToImplMapping )
139   {
140     if( iter.keyEvent == keyEvent )
141     {
142       impl = iter.impl;
143     }
144   }
145   return impl;
146 }
147
148 } // namespace Dali