#define DALI_INTERNAL_KEY_EVENT_H
/*
- * Copyright (c) 2019 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.
// INTERNAL INCLUDES
#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/object/base-object.h>
namespace Dali
{
-
namespace Internal
{
+class KeyEvent;
+typedef IntrusivePtr<KeyEvent> KeyEventPtr;
-struct KeyEventImpl
+/**
+ * @copydoc Dali::KeyEvent
+ */
+class KeyEvent : public BaseObject
{
public:
+ /**
+ * @brief Default constructor.
+ */
+ KeyEvent();
/**
* @brief Constructor.
+ *
+ * @param[in] keyName The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
+ * @param[in] logicalKey The logical key symbol (eg. shift + 1 == "exclamation")
+ * @param[in] keyString The string of input characters or key pressed
+ * @param[in] keyCode The unique key code for the key pressed.
+ * @param[in] keyModifier The key modifier for special keys like shift and alt
+ * @param[in] timeStamp The time (in ms) that the key event occurred.
+ * @param[in] keyState The state of the key event.
+ * @param[in] compose The key compose
+ * @param[in] deviceName The name of device the key event originated from
+ * @param[in] deviceClass The class of device the key event originated from
+ * @param[in] deviceSubclass The subclass of device the key event originated from
*/
- KeyEventImpl( Dali::KeyEvent* 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);
/**
- * @brief Destructor.
+ * Create a new KeyEvent.
+ *
+ * @param[in] keyName The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.
+ * @param[in] logicalKey The logical key symbol (eg. shift + 1 == "exclamation")
+ * @param[in] keyString The string of input characters or key pressed
+ * @param[in] keyCode The unique key code for the key pressed.
+ * @param[in] keyModifier The key modifier for special keys like shift and alt
+ * @param[in] timeStamp The time (in ms) that the key event occurred.
+ * @param[in] keyState The state of the key event.
+ * @param[in] compose The key compose
+ * @param[in] deviceName The name of device the key event originated from
+ * @param[in] deviceClass The class of device the key event originated from
+ * @param[in] deviceSubclass The subclass of device the key event originated from
+ * @return A smart-pointer to the newly allocated KeyEvent.
*/
- ~KeyEventImpl();
+ static KeyEventPtr 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);
/**
- * @brief Assignment operator.
- * @param[in] rhs A reference to the copied handle
- * @return A reference to this
+ * @copydoc Dali::KeyEvent::IsShiftModifier()
*/
- KeyEventImpl& operator=( const KeyEventImpl& rhs );
+ bool IsShiftModifier() const;
/**
- * @brief Get the key symbol string.
- * @return The key symbol
+ * @copydoc Dali::KeyEvent::IsCtrlModifier()
*/
- std::string GetLogicalKey() const;
+ bool IsCtrlModifier() const;
/**
- * @brief Set the key symbol string to the KeyEvent.
- * @param[in] key The key symbol to set
+ * @copydoc Dali::KeyEvent::IsAltModifier()
*/
- void SetLogicalKey( const std::string& logicalKey );
+ bool IsAltModifier() const;
/**
- * @brief Get the compose string.
- *
- * @return The compose string.
+ * @copydoc Dali::KeyEvent::GetCompose()
*/
- std::string GetCompose() const;
+ const std::string& GetCompose() const;
/**
- * @brief Set the compose string to the KeyEvent
- * A string if this keystroke has modified a string in the middle of being composed,
- * this string replaces the previous one.
- *
- * @param[in] compose The compose string to set
+ * @copydoc Dali::KeyEvent::GetDeviceName()
+ */
+ const std::string& GetDeviceName() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetDeviceClass()
+ */
+ Device::Class::Type GetDeviceClass() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetDeviceSubclass()
+ */
+ Device::Subclass::Type GetDeviceSubclass() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetKeyName()
+ */
+ const std::string& GetKeyName() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetKeyString()
+ */
+ const std::string& GetKeyString() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetLogicalKey()
*/
- void SetCompose( const std::string& compose );
+ const std::string& GetLogicalKey() const;
/**
- * @brief Get the device name the key event originated from
+ * @copydoc Dali::KeyEvent::GetKeyCode()
+ */
+ int32_t GetKeyCode() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetKeyModifier()
+ */
+ int32_t GetKeyModifier() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetTime()
+ */
+ unsigned long GetTime() const;
+
+ /**
+ * @copydoc Dali::KeyEvent::GetState()
+ */
+ Dali::KeyEvent::State GetState() const;
+
+ /**
+ * @brief Set the name given to the key pressed
*
- * @return The device name
+ * @param[in] keyName The name given to the key pressed.
*/
- std::string GetDeviceName() const;
+ void SetKeyName(const std::string& keyName);
/**
- * @brief Set the device name to the KeyEvent
+ * @brief Set the actual string of input characters that should be used for input editors.
*
- * @param[in] deviceName Device name string to set
+ * @param[in] The actual string of input characters
*/
- void SetDeviceName( const std::string& deviceName );
+ void SetKeyString(const std::string& keyString);
/**
- * @brief Get the device class the key event originated from
+ * @brief Set the unique key code for the key pressed.
*
- * @return The device class
+ * @param[in] keyCode The unique key code for the key pressed
*/
- Device::Class::Type GetDeviceClass() const;
+ void SetKeyCode(int32_t keyCode);
/**
- * @brief Set the device class to the KeyEvent
+ * @brief Set the key modifier for special keys like Shift, Alt and Ctrl which modify the next key pressed.
*
- * @param[in] deviceClass Device class to set
+ * @param[in] keyModifier The key modifier
*/
- void SetDeviceClass( Device::Class::Type deviceClass );
+ void SetKeyModifier(int32_t keyModifier);
/**
- * @brief Get the device subclass the key event originated from
+ * @brief Set the time (in ms) that the key event occurred.
*
- * @return The device subclass
+ * @param[in] time The time (in ms)
*/
- Device::Subclass::Type GetDeviceSubclass() const;
+ void SetTime(unsigned long time);
/**
- * @brief Set the device subclass to the KeyEvent
+ * @brief Set the state of the key event.
*
- * @param[in] deviceClass Device subclass to set
+ * @param[in] state The state of the key event
*/
- void SetDeviceSubclass( Device::Subclass::Type deviceSubclass );
+ void SetState(const Dali::KeyEvent::State& state);
private:
+ /**
+ * @brief Destructor.
+ *
+ * A reference counted object may only be deleted by calling Unreference()
+ */
+ ~KeyEvent() override = default;
- // Undefined
- KeyEventImpl();
+ // Not copyable or movable
- // Undefined
- KeyEventImpl( const KeyEventImpl& rhs );
+ KeyEvent(const KeyEvent& rhs) = delete; ///< Deleted copy constructor
+ KeyEvent(KeyEvent&& rhs) = delete; ///< Deleted move constructor
+ KeyEvent& operator=(const KeyEvent& rhs) = delete; ///< Deleted copy assignment operator
+ KeyEvent& operator=(KeyEvent&& rhs) = delete; ///< Deleted move assignment operator
private:
-
- std::string mLogicalKey;
- std::string mCompose;
- std::string mDeviceName;
- Device::Class::Type mDeviceClass;
- Device::Subclass::Type mDeviceSubclass;
+ std::string mKeyName; ///< The name of the key pressed
+ std::string mLogicalKey; ///< The logical key symbol
+ std::string mKeyString; ///< The string of input characters
+ int mKeyCode; ///< TThe unique key code
+ int mKeyModifier; ///< The key modifier
+ unsigned long mTime; ///< The time that the key event occurred.
+ Dali::KeyEvent::State mState; ///< The state of the key event.
+ std::string mCompose; ///< The key compose
+ std::string mDeviceName; ///< The name of device the key event originated from
+ Device::Class::Type mDeviceClass; ///< The class of device the key event originated from
+ Device::Subclass::Type mDeviceSubclass; ///< The subclass of device the key event originated from
};
} // namespace Internal
// Helpers for public-api forwarding methods
-Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent );
+inline Internal::KeyEvent& GetImplementation(Dali::KeyEvent& keyEvent)
+{
+ DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
+
+ BaseObject& object = keyEvent.GetBaseObject();
+
+ return static_cast<Internal::KeyEvent&>(object);
+}
+
+inline const Internal::KeyEvent& GetImplementation(const Dali::KeyEvent& keyEvent)
+{
+ DALI_ASSERT_ALWAYS(keyEvent && "Key Event handle is empty");
+
+ const BaseObject& object = keyEvent.GetBaseObject();
-const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent );
+ return static_cast<const Internal::KeyEvent&>(object);
+}
} // namespace Dali