Updated all code to new format
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
index f6a0a32..4cfefd1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #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
 {
+const uint32_t MODIFIER_SHIFT   = 0x1;
+const uint32_t MODIFIER_CTRL    = 0x2;
+const uint32_t MODIFIER_ALT     = 0x4;
+const int32_t  KEY_INVALID_CODE = -1;
+} // namespace
 
-typedef std::map< const KeyEvent*, Internal::KeyEventImpl*> KeyEventMap;
-typedef KeyEventMap::iterator KeyEventMapIter;
-
-KeyEventMap keyEventImplMap;
+namespace Internal
+{
+KeyEvent::KeyEvent()
+: mKeyName(""),
+  mLogicalKey(""),
+  mKeyString(""),
+  mKeyCode(KEY_INVALID_CODE),
+  mKeyModifier(0),
+  mTime(0),
+  mState(Dali::KeyEvent::DOWN),
+  mCompose(""),
+  mDeviceName(""),
+  mDeviceClass(Device::Class::NONE),
+  mDeviceSubclass(Device::Subclass::NONE)
+{
+}
 
+KeyEvent::KeyEvent(const std::string&           keyName,
+                   const std::string&           logicalKey,
+                   const std::string&           keyString,
+                   int                          keyCode,
+                   int                          keyModifier,
+                   unsigned long                timeStamp,
+                   const Dali::KeyEvent::State& keyState,
+                   const std::string&           compose,
+                   const std::string&           deviceName,
+                   const Device::Class::Type    deviceClass,
+                   const Device::Subclass::Type deviceSubclass)
+: mKeyName(keyName),
+  mLogicalKey(logicalKey),
+  mKeyString(keyString),
+  mKeyCode(keyCode),
+  mKeyModifier(keyModifier),
+  mTime(timeStamp),
+  mState(keyState),
+  mCompose(compose),
+  mDeviceName(deviceName),
+  mDeviceClass(deviceClass),
+  mDeviceSubclass(deviceSubclass)
+{
 }
 
-namespace Internal
+KeyEventPtr KeyEvent::New(const std::string&           keyName,
+                          const std::string&           logicalKey,
+                          const std::string&           keyString,
+                          int                          keyCode,
+                          int                          keyModifier,
+                          unsigned long                timeStamp,
+                          const Dali::KeyEvent::State& keyState,
+                          const std::string&           compose,
+                          const std::string&           deviceName,
+                          const Device::Class::Type    deviceClass,
+                          const Device::Subclass::Type deviceSubclass)
 {
+  KeyEventPtr keyEvent = new KeyEvent(keyName, logicalKey, keyString, keyCode, keyModifier, timeStamp, keyState, compose, deviceName, deviceClass, deviceSubclass);
+  return keyEvent;
+}
 
-KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
-: mDeviceName( "" ),
-  mDeviceClass( DevelDevice::Class::NONE ),
-  mDeviceSubclass( DevelDevice::Subclass::NONE )
+bool KeyEvent::IsShiftModifier() const
 {
-  keyEventImplMap[keyEvent] = this;
+  return ((MODIFIER_SHIFT & mKeyModifier) == MODIFIER_SHIFT);
 }
 
-KeyEventImpl::~KeyEventImpl()
+bool KeyEvent::IsCtrlModifier() const
 {
-  for( KeyEventMapIter iter = keyEventImplMap.begin(); iter != keyEventImplMap.end(); ++iter )
-  {
-    if( this == iter->second )
-    {
-      keyEventImplMap.erase( iter );
-      break;
-    }
-  }
+  return ((MODIFIER_CTRL & mKeyModifier) == MODIFIER_CTRL);
 }
 
-KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
+bool KeyEvent::IsAltModifier() const
 {
-  if( this != &rhs )
-  {
-    mDeviceName = rhs.mDeviceName;
-    mDeviceClass = rhs.mDeviceClass;
-    mDeviceSubclass = rhs.mDeviceSubclass;
-  }
+  return ((MODIFIER_ALT & mKeyModifier) == MODIFIER_ALT);
+}
 
-  return *this;
+const std::string& KeyEvent::GetCompose() const
+{
+  return mCompose;
 }
 
-std::string KeyEventImpl::GetDeviceName() const
+const std::string& KeyEvent::GetDeviceName() const
 {
   return mDeviceName;
 }
 
-void KeyEventImpl::SetDeviceName( const std::string& deviceName )
+Device::Class::Type KeyEvent::GetDeviceClass() const
 {
-  mDeviceName = deviceName;
+  return mDeviceClass;
 }
 
-DevelDevice::Class::Type KeyEventImpl::GetDeviceClass() const
+Device::Subclass::Type KeyEvent::GetDeviceSubclass() const
 {
-  return mDeviceClass;
+  return mDeviceSubclass;
 }
 
-void KeyEventImpl::SetDeviceClass( DevelDevice::Class::Type deviceClass )
+const std::string& KeyEvent::GetKeyName() const
 {
-  mDeviceClass = deviceClass;
+  return mKeyName;
 }
 
-DevelDevice::Subclass::Type KeyEventImpl::GetDeviceSubclass() const
+const std::string& KeyEvent::GetKeyString() const
 {
-  return mDeviceSubclass;
+  return mKeyString;
 }
 
-void KeyEventImpl::SetDeviceSubclass( DevelDevice::Subclass::Type deviceSubclass )
+const std::string& KeyEvent::GetLogicalKey() const
 {
-  mDeviceSubclass = deviceSubclass;
+  return mLogicalKey;
 }
 
-} // namsespace Internal
+int32_t KeyEvent::GetKeyCode() const
+{
+  return mKeyCode;
+}
+
+int32_t KeyEvent::GetKeyModifier() const
+{
+  return mKeyModifier;
+}
 
-Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
+unsigned long KeyEvent::GetTime() const
 {
-  return keyEventImplMap[keyEvent];
+  return mTime;
 }
 
-const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
+Dali::KeyEvent::State KeyEvent::GetState() const
 {
-  return keyEventImplMap[keyEvent];
+  return mState;
 }
 
+void KeyEvent::SetKeyName(const std::string& keyName)
+{
+  mKeyName = keyName;
+}
+
+void KeyEvent::SetKeyString(const std::string& keyString)
+{
+  mKeyString = keyString;
+}
+
+void KeyEvent::SetKeyCode(int32_t keyCode)
+{
+  mKeyCode = keyCode;
+}
+
+void KeyEvent::SetKeyModifier(int32_t keyModifier)
+{
+  mKeyModifier = keyModifier;
+}
+
+void KeyEvent::SetTime(unsigned long time)
+{
+  mTime = time;
+}
+
+void KeyEvent::SetState(const Dali::KeyEvent::State& state)
+{
+  mState = state;
+}
+
+} // namespace Internal
+
 } // namespace Dali