2 * Copyright (c) 2017 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/internal/event/events/key-event-impl.h>
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/devel-api/common/dali-vector-devel.h>
31 * This container stores a mapping between public key event and impl as we cannot add data members in public one.
32 * In practice this keeps the impl "alive" in between KeyEvent constructor and destructor calls so that getter
33 * methods can be called to access the new data members. There is a 1:1 mapping between KeyEvent and KeyEventImpl.
38 Internal::KeyEventImpl* impl;
40 Vector< KeyImplMapping > gKeyEventToImplMapping;
47 KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
49 mDeviceClass( DevelDevice::Class::NONE ),
50 mDeviceSubclass( DevelDevice::Subclass::NONE )
52 gKeyEventToImplMapping.PushBack( { keyEvent, this } );
55 KeyEventImpl::~KeyEventImpl()
57 for( auto&& iter : gKeyEventToImplMapping )
59 if( this == iter.impl )
61 gKeyEventToImplMapping.Erase( &iter ); // iter is reference to KeyImplMapping, take address of it for Erase
67 KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
71 mDeviceName = rhs.mDeviceName;
72 mDeviceClass = rhs.mDeviceClass;
73 mDeviceSubclass = rhs.mDeviceSubclass;
79 std::string KeyEventImpl::GetDeviceName() const
84 void KeyEventImpl::SetDeviceName( const std::string& deviceName )
86 mDeviceName = deviceName;
89 DevelDevice::Class::Type KeyEventImpl::GetDeviceClass() const
94 void KeyEventImpl::SetDeviceClass( DevelDevice::Class::Type deviceClass )
96 mDeviceClass = deviceClass;
99 DevelDevice::Subclass::Type KeyEventImpl::GetDeviceSubclass() const
101 return mDeviceSubclass;
104 void KeyEventImpl::SetDeviceSubclass( DevelDevice::Subclass::Type deviceSubclass )
106 mDeviceSubclass = deviceSubclass;
109 } // namsespace Internal
111 Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
113 Internal::KeyEventImpl* impl( NULL );
114 for( auto&& iter : gKeyEventToImplMapping )
116 if( iter.keyEvent == keyEvent )
124 const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
126 Internal::KeyEventImpl* impl( NULL );
127 for( auto&& iter : gKeyEventToImplMapping )
129 if( iter.keyEvent == keyEvent )