[5.0] Add GetLogicalKey API in DevelKeyEvent
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index e04d8c8..8f0c84f
 #include <dali/internal/event/events/key-event-impl.h>
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/common/map-wrapper.h>
+#include <dali/public-api/common/dali-vector.h>
 
 namespace Dali
 {
 
 namespace
 {
-
-typedef std::map< const KeyEvent*, Internal::KeyEventImpl*> KeyEventMap;
-typedef KeyEventMap::iterator KeyEventMapIter;
-
-KeyEventMap keyEventImplMap;
+/**
+ * This container stores a mapping between public key event and impl as we cannot add data members in public one.
+ * In practice this keeps the impl "alive" in between KeyEvent constructor and destructor calls so that getter
+ * methods can be called to access the new data members. There is a 1:1 mapping between KeyEvent and KeyEventImpl.
+ */
+struct KeyImplMapping
+{
+  KeyEvent* keyEvent;
+  Internal::KeyEventImpl* impl;
+};
+Vector< KeyImplMapping > gKeyEventToImplMapping;
 
 }
 
@@ -38,20 +44,23 @@ namespace Internal
 {
 
 KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
-: mDeviceName( "" ),
-  mDeviceClass( DevelKeyEvent::DeviceClass::NONE )
+: mLogicalKey( "" ),
+  mCompose( "" ),
+  mDeviceName( "" ),
+  mDeviceClass( Device::Class::NONE ),
+  mDeviceSubclass( Device::Subclass::NONE )
 {
-  keyEventImplMap[keyEvent] = this;
+  gKeyEventToImplMapping.PushBack( { keyEvent, this } );
 }
 
 KeyEventImpl::~KeyEventImpl()
 {
-  for( KeyEventMapIter iter = keyEventImplMap.begin(); iter != keyEventImplMap.end(); ++iter )
+  for( auto&& iter : gKeyEventToImplMapping )
   {
-    if( this == iter->second )
+    if( this == iter.impl )
     {
-      keyEventImplMap.erase( iter );
-      break;
+      gKeyEventToImplMapping.Erase( &iter ); // iter is reference to KeyImplMapping, take address of it for Erase
+      return;
     }
   }
 }
@@ -60,13 +69,36 @@ KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
 {
   if( this != &rhs )
   {
+    mLogicalKey = rhs.mLogicalKey;
+    mCompose = rhs.mCompose;
     mDeviceName = rhs.mDeviceName;
     mDeviceClass = rhs.mDeviceClass;
+    mDeviceSubclass = rhs.mDeviceSubclass;
   }
 
   return *this;
 }
 
+std::string KeyEventImpl::GetLogicalKey() const
+{
+  return mLogicalKey;
+}
+
+void KeyEventImpl::SetLogicalKey( const std::string& logicalKey )
+{
+  mLogicalKey = logicalKey;
+}
+
+std::string KeyEventImpl::GetCompose() const
+{
+  return mCompose;
+}
+
+void KeyEventImpl::SetCompose( const std::string& compose )
+{
+  mCompose = compose;
+}
+
 std::string KeyEventImpl::GetDeviceName() const
 {
   return mDeviceName;
@@ -77,26 +109,52 @@ void KeyEventImpl::SetDeviceName( const std::string& deviceName )
   mDeviceName = deviceName;
 }
 
-DevelKeyEvent::DeviceClass::Type KeyEventImpl::GetDeviceClass() const
+Device::Class::Type KeyEventImpl::GetDeviceClass() const
 {
   return mDeviceClass;
 }
 
-void KeyEventImpl::SetDeviceClass( const DevelKeyEvent::DeviceClass::Type& deviceClass )
+void KeyEventImpl::SetDeviceClass( Device::Class::Type deviceClass )
 {
   mDeviceClass = deviceClass;
 }
 
+Device::Subclass::Type KeyEventImpl::GetDeviceSubclass() const
+{
+  return mDeviceSubclass;
+}
+
+void KeyEventImpl::SetDeviceSubclass( Device::Subclass::Type deviceSubclass )
+{
+  mDeviceSubclass = deviceSubclass;
+}
+
 } // namsespace Internal
 
 Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
 {
-  return keyEventImplMap[keyEvent];
+  Internal::KeyEventImpl* impl( NULL );
+  for( auto&& iter : gKeyEventToImplMapping )
+  {
+    if( iter.keyEvent == keyEvent )
+    {
+      impl = iter.impl;
+    }
+  }
+  return impl;
 }
 
 const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
 {
-  return keyEventImplMap[keyEvent];
+  Internal::KeyEventImpl* impl( NULL );
+  for( auto&& iter : gKeyEventToImplMapping )
+  {
+    if( iter.keyEvent == keyEvent )
+    {
+      impl = iter.impl;
+    }
+  }
+  return impl;
 }
 
 } // namespace Dali