[Tizen] Adding deviceClass to KeyEvent Integ
[platform/core/uifw/dali-core.git] / dali / public-api / events / key-event.cpp
index 7c9bc0d..960174a 100644 (file)
@@ -1,22 +1,27 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/public-api/events/key-event.h>
 
+// INTERNAL INCLUDES
+#include <dali/devel-api/events/key-event-devel.h>
+#include <dali/devel-api/common/map-wrapper.h>
+
 namespace Dali
 {
 
@@ -27,6 +32,41 @@ const unsigned int MODIFIER_CTRL  = 0x2;
 const unsigned int MODIFIER_ALT   = 0x4;
 const int KEY_INVALID_CODE = -1;
 
+struct KeyEventImpl
+{
+  KeyEventImpl()
+  : deviceName( "" ),
+    deviceClass( DevelKeyEvent::DeviceClass::NONE )
+  {
+  }
+
+  KeyEventImpl& operator=( const KeyEventImpl& rhs )
+  {
+    if( this != &rhs )
+    {
+      deviceName = rhs.deviceName;
+      deviceClass = rhs.deviceClass;
+    }
+
+    return *this;
+  }
+
+  KeyEventImpl( const KeyEventImpl& rhs )
+  {
+    deviceName =  rhs.deviceName;
+    deviceClass = rhs.deviceClass;
+  }
+
+  std::string deviceName;
+  DevelKeyEvent::DeviceClass::Type deviceClass;
+};
+
+typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
+typedef KeyEventMap::const_iterator KeyEventMapIter;
+
+
+KeyEventMap keyEventImplMap;
+
 }
 
 KeyEvent::KeyEvent()
@@ -34,8 +74,11 @@ KeyEvent::KeyEvent()
   keyPressed(""),
   keyCode(KEY_INVALID_CODE),
   keyModifier(0),
+  time(0),
   state(KeyEvent::Down)
 {
+  KeyEventImpl* impl = new KeyEventImpl;
+  keyEventImplMap[this] = impl;
 }
 
 KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier,unsigned long timeStamp, const State& keyState)
@@ -46,10 +89,41 @@ KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int
   time(timeStamp),
   state(keyState)
 {
+  keyEventImplMap[this] = new KeyEventImpl;
+}
+
+KeyEvent::KeyEvent( const KeyEvent& rhs )
+: keyPressedName( rhs.keyPressedName ),
+  keyPressed( rhs.keyPressed ),
+  keyCode( rhs.keyCode ),
+  keyModifier( rhs.keyModifier ),
+  time( rhs.time ),
+  state( rhs.state )
+{
+  keyEventImplMap[this] = new KeyEventImpl( *keyEventImplMap[ &rhs ] );
+}
+
+KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
+{
+  if( this != &rhs )
+  {
+    keyPressedName = rhs.keyPressedName;
+    keyPressed = rhs.keyPressed;
+    keyCode = rhs.keyCode;
+    keyModifier = rhs.keyModifier;
+    time = rhs.time;
+    state = rhs.state;
+
+    *keyEventImplMap[ this ] = *keyEventImplMap[ &rhs ];
+  }
+
+  return *this;
 }
 
 KeyEvent::~KeyEvent()
 {
+  delete keyEventImplMap[this];
+  keyEventImplMap.erase( this );
 }
 
 bool KeyEvent::IsShiftModifier() const
@@ -82,4 +156,50 @@ bool KeyEvent::IsAltModifier() const
   return false;
 }
 
+std::string DevelKeyEvent::GetDeviceName( const KeyEvent& keyEvent )
+{
+  KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
+
+  if( search != keyEventImplMap.end())
+  {
+    return search->second->deviceName;
+  }
+
+  return std::string("");
+}
+
+void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName )
+{
+  KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
+
+  if( search != keyEventImplMap.end())
+  {
+    search->second->deviceName = deviceName;
+  }
+}
+
+DevelKeyEvent::DeviceClass::Type DevelKeyEvent::GetDeviceClass( const KeyEvent& keyEvent )
+{
+  KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
+
+  DevelKeyEvent::DeviceClass::Type result = DevelKeyEvent::DeviceClass::NONE;
+
+  if( search != keyEventImplMap.end() )
+  {
+    result = search->second->deviceClass;
+  }
+
+  return result;
+}
+
+void DevelKeyEvent::SetDeviceClass( KeyEvent& keyEvent, const DeviceClass::Type& deviceClass )
+{
+  KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
+
+  if( search != keyEventImplMap.end() )
+  {
+    search->second->deviceClass = deviceClass;
+  }
+}
+
 } // namespace Dali