#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()
ecore_event_handler_del(mDropHandler);
}
-void DragAndDropEcoreWl::SetData(std::string data)
-{
- // Save Data
- mData = data;
-}
-
-bool DragAndDropEcoreWl::StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const std::string& dragData)
+bool DragAndDropEcoreWl::StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const Dali::DragAndDrop::DragData& data)
{
// Get Parent Window
auto parent = Dali::DevelWindow::Get(source);
// Set Drag Source Data
- SetData(dragData);
+ mMimeType = data.GetMimeType();
+ mData = data.GetData();
// Apply Shadow Property
shadow.SetProperty(Dali::Actor::Property::SIZE, Vector2(150, 150));
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"};
+ // Disable Default Cursor
+ ecore_wl2_input_pointer_set(input, NULL, 0, 0);
+
+ // Set mime type for drag and drop
+ const char* mimeTypes[2];
+ mimeTypes[0] = mMimeType.c_str();
mimeTypes[1] = NULL;
- // Set mimetype
+ // Set mime type
ecore_wl2_dnd_drag_types_set(input, (const char**)mimeTypes);
// Start wayland drag and drop
bool DragAndDropEcoreWl::AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback)
{
+ std::vector<DropTarget>::iterator itr;
+ for(itr = mDropTargets.begin(); itr < mDropTargets.end(); itr++)
+ {
+ if((*itr).target == target)
+ {
+ return false;
+ }
+ }
+
DropTarget targetData;
- targetData.target = target;
+ targetData.target = target;
targetData.callback = callback;
- targetData.inside = false;
+ targetData.inside = false;
mDropTargets.push_back(targetData);
return true;
}
+bool DragAndDropEcoreWl::RemoveListener(Dali::Actor target)
+{
+ std::vector<DropTarget>::iterator itr;
+ for(itr = mDropTargets.begin(); itr < mDropTargets.end(); itr++)
+ {
+ if((*itr).target == target)
+ {
+ mDropTargets.erase(itr);
+ break;
+ }
+ }
+
+ return true;
+}
+
void DragAndDropEcoreWl::SendData(void* event)
{
Ecore_Wl2_Event_Data_Source_Send* ev = reinterpret_cast<Ecore_Wl2_Event_Data_Source_Send*>(event);
return;
}
- int len = strlen(mData.c_str());
- char *buf = new char[len + 1];
- strncpy(buf, mData.c_str(), len);
- buf[len] = '\0';
+ int dataLength = strlen(mData.c_str());
+ int bufferSize = dataLength;
+ if((mMimeType.find("text") != std::string::npos) ||
+ (mMimeType.find("markup") != std::string::npos) ||
+ (mMimeType.find("image") != std::string::npos))
+ {
+ bufferSize += 1;
+ }
+
+ char* buffer = new char[bufferSize];
+ if(!buffer)
+ {
+ return;
+ }
+
+ memcpy(buffer, mData.c_str(), dataLength);
+ buffer[dataLength] = '\0';
+
+ auto ret = write(ev->fd, buffer, bufferSize);
+ if(DALI_UNLIKELY(ret != bufferSize))
+ {
+ DALI_LOG_ERROR("write(ev->fd) return %d! Pleacse check it\n", static_cast<int>(ret));
+ }
- // Write source object data to target object
- write(ev->fd, buf, len+1);
close(ev->fd);
if(mDragWindow)
mDragWindow.Hide();
}
- if(buf)
- {
- free(buf);
- }
+ delete[] buffer;
}
void DragAndDropEcoreWl::ReceiveData(void* event)
if(mTargetIndex != -1)
{
- Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mPosition, ev->data);
+ Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mPosition, ev->mimetype, ev->data);
mDropTargets[mTargetIndex].callback(dragEvent);
mDropTargets[mTargetIndex].inside = false;
}
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++)
+ for(std::size_t 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++)
+ for(std::size_t 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;
}