/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * 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.
// 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
{
const unsigned int MODIFIER_ALT = 0x4;
const int KEY_INVALID_CODE = -1;
+struct KeyEventImpl
+{
+ KeyEventImpl()
+ :deviceName("")
+ {
+ };
+
+ KeyEventImpl& operator=( const KeyEventImpl& rhs )
+ {
+ if( this != &rhs )
+ {
+ deviceName = rhs.deviceName;
+ }
+
+ return *this;
+ }
+
+ KeyEventImpl( const KeyEventImpl& rhs )
+ {
+ deviceName = rhs.deviceName;
+ }
+
+ std::string deviceName;
+};
+
+typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
+typedef KeyEventMap::const_iterator KeyEventMapIter;
+
+
+KeyEventMap keyEventImplMap;
+
}
KeyEvent::KeyEvent()
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)
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
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;
+ }
+}
+
+
} // namespace Dali