*/
// EXTERNAL INCLUDES
-#include <functional>
+#include <dali/public-api/actors/actor.h>
#include <dali/public-api/math/rect.h>
#include <dali/public-api/object/base-handle.h>
-#include <dali/public-api/actors/actor.h>
+#include <functional>
// INTERNAL INCLUDES
#include <dali/public-api/dali-adaptor-common.h>
{
ENTER, ///< The drag object has entered the target object.
LEAVE, ///< The drag object has left the target object.
- MOVE, ///< The drag object moves in the target object.
- DROP ///< The drag object dropped in the target object.
+ MOVE, ///< The drag object moves in the target object.
+ DROP ///< The drag object dropped in the target object.
};
/**
*/
struct DragEvent
{
- DragEvent() { this->data = nullptr; }
+ DragEvent()
+ {
+ this->data = nullptr;
+ }
DragEvent(DragType type, Dali::Vector2 position, char* data = nullptr)
{
+ this->type = type;
+ this->position = position;
+ this->data = data;
+ }
+
+ void SetAction(DragType type)
+ {
this->type = type;
+ }
+ DragType GetAction()
+ {
+ return type;
+ }
+ void SetPosition(Dali::Vector2 position)
+ {
this->position = position;
+ }
+ Dali::Vector2 GetPosition()
+ {
+ return position;
+ }
+ void SetData(char* data)
+ {
this->data = data;
}
-
- void SetAction(DragType type) { this->type = type; }
- DragType GetAction() { return type; }
- void SetPosition(Dali::Vector2 position) { this->position = position; }
- Dali::Vector2 GetPosition() { return position; }
- void SetData(char* data) { this->data = data; }
- char* GetData() { return data; }
+ char* GetData()
+ {
+ return data;
+ }
private:
- DragType type; ///< The drag event type.
- Dali::Vector2 position; ///< The position of drag object.
- char* data; ///< The data of drag object.
+ DragType type{DragType::DROP}; ///< The drag event type.
+ Dali::Vector2 position; ///< The position of drag object.
+ char* data{nullptr}; ///< The data of drag object.
};
- using DragAndDropFunction = std::function<void(const DragEvent&)>;
+ using DragAndDropFunction = std::function<void(const DragEvent&)>;
/**
* @brief Create an uninitialized DragAndDrop.
#include <dali/internal/drag-and-drop/tizen-wayland/drag-and-drop-impl-ecore-wl2.h>
// EXTERNAL INCLUDES
-#include <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
#include <dali/devel-api/common/singleton-service.h>
#include <dali/integration-api/debug.h>
+#include <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
#include <unistd.h>
///////////////////////////////////////////////////////////////////////////////////////////////////
{
namespace Adaptor
{
-
static bool IsIntersection(int px, int py, int tx, int ty, int tw, int th)
{
if(px > tx && py > ty && px < (tx + tw) && py < (ty + th))
return ECORE_CALLBACK_PASS_ON;
}
-
Dali::DragAndDrop GetDragAndDrop()
{
Dali::DragAndDrop dnd;
else
{
// Create a singleon instance
- DragAndDropEcoreWl *dndImpl = new DragAndDropEcoreWl();
+ DragAndDropEcoreWl* dndImpl = new DragAndDropEcoreWl();
dnd = Dali::DragAndDrop(dndImpl);
service.Register(typeid(Dali::DragAndDrop), dnd);
DragAndDropEcoreWl::DragAndDropEcoreWl()
{
- mSendHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this);
+ mSendHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this);
mReceiveHandler = ecore_event_handler_add(ECORE_WL2_EVENT_OFFER_DATA_READY, EcoreEventOfferDataReady, this);
- mMotionHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DND_MOTION, EcoreEventDataMotion, this);
- mDropHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DND_DROP, EcoreEventDataDrop, this);
+ mMotionHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DND_MOTION, EcoreEventDataMotion, this);
+ mDropHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DND_DROP, EcoreEventDataDrop, this);
}
DragAndDropEcoreWl::~DragAndDropEcoreWl()
mDragWindow.Add(shadow);
// Start Drag and Drop
- Ecore_Wl2_Window* parentWindow = AnyCast<Ecore_Wl2_Window*>(parent.GetNativeHandle());
- Ecore_Wl2_Window* dragWindow = AnyCast<Ecore_Wl2_Window*>(mDragWindow.GetNativeHandle());
- Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
- Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+ Ecore_Wl2_Window* parentWindow = AnyCast<Ecore_Wl2_Window*>(parent.GetNativeHandle());
+ Ecore_Wl2_Window* dragWindow = AnyCast<Ecore_Wl2_Window*>(mDragWindow.GetNativeHandle());
+ Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
+ Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
// TODO: Makes mime-type common
- char *mimeTypes[2] = {"text/plain"};
- mimeTypes[1] = NULL;
+ char* mimeTypes[2] = {"text/plain"};
+ mimeTypes[1] = NULL;
// Set mimetype
ecore_wl2_dnd_drag_types_set(input, (const char**)mimeTypes);
bool DragAndDropEcoreWl::AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback)
{
DropTarget targetData;
- targetData.target = target;
+ targetData.target = target;
targetData.callback = callback;
- targetData.inside = false;
+ targetData.inside = false;
mDropTargets.push_back(targetData);
return;
}
- int len = strlen(mData.c_str());
- char *buf = new char[len + 1];
+ int len = strlen(mData.c_str());
+ char* buf = new char[len + 1];
strncpy(buf, mData.c_str(), len);
buf[len] = '\0';
// Write source object data to target object
- write(ev->fd, buf, len+1);
+ write(ev->fd, buf, len + 1);
close(ev->fd);
if(mDragWindow)
if(buf)
{
- free(buf);
+ delete[] buf;
}
}
bool DragAndDropEcoreWl::CalculateDragEvent(void* event)
{
- Ecore_Wl2_Event_Dnd_Motion *ev = reinterpret_cast<Ecore_Wl2_Event_Dnd_Motion*>(event);
+ Ecore_Wl2_Event_Dnd_Motion* ev = reinterpret_cast<Ecore_Wl2_Event_Dnd_Motion*>(event);
Dali::DragAndDrop::DragEvent dragEvent;
- Dali::Vector2 curPosition(ev->x, ev->y);
+ Dali::Vector2 curPosition(ev->x, ev->y);
for(int i = 0; i < mDropTargets.size(); i++)
{
- Vector2 position = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::POSITION);
- Vector2 size = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::SIZE);
- bool currentInside = IsIntersection(ev->x, ev->y, position.x, position.y, size.width, size.height);
+ Vector2 position = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::POSITION);
+ Vector2 size = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::SIZE);
+ bool currentInside = IsIntersection(ev->x, ev->y, position.x, position.y, size.width, size.height);
// Calculate Drag Enter, Leave, Move Event
if(currentInside && !mDropTargets[i].inside)
bool DragAndDropEcoreWl::CalculateViewRegion(void* event)
{
- Ecore_Wl2_Event_Dnd_Drop *ev = reinterpret_cast<Ecore_Wl2_Event_Dnd_Drop*>(event);
+ Ecore_Wl2_Event_Dnd_Drop* ev = reinterpret_cast<Ecore_Wl2_Event_Dnd_Drop*>(event);
// Check the target object region
mTargetIndex = -1;
for(int i = 0; i < mDropTargets.size(); i++)
{
Vector2 position = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::POSITION);
- Vector2 size = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::SIZE);
+ Vector2 size = mDropTargets[i].target.GetProperty<Vector2>(Dali::Actor::Property::SIZE);
// If the drop position is in the target object region, request drop data to the source object
if(IsIntersection(ev->x, ev->y, position.x, position.y, size.width, size.height))
{
- mTargetIndex = i;
- mPosition = position;
+ mTargetIndex = i;
+ mPosition = position;
Dali::Window window = Dali::DevelWindow::Get(mDropTargets[i].target);
- char *mimetype = (char*)eina_array_data_get(ecore_wl2_offer_mimes_get(ev->offer), 0);
+ char* mimetype = (char*)eina_array_data_get(ecore_wl2_offer_mimes_get(ev->offer), 0);
if(mimetype)
{
- ecore_wl2_offer_accept(ev->offer, mimetype);
- ecore_wl2_offer_receive(ev->offer, mimetype);
- Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
- Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
- ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
+ ecore_wl2_offer_accept(ev->offer, mimetype);
+ ecore_wl2_offer_receive(ev->offer, mimetype);
+ Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
+ Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+ ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
}
return true;
}