*/
// EXTERNAL INCLUDES
+#include <dali/public-api/adaptor-framework/window.h>
#include <dali/public-api/actors/actor.h>
#include <dali/public-api/math/rect.h>
#include <dali/public-api/object/base-handle.h>
{
public:
/**
+ * @brief Enumeration for the drag source event type in the source object
+ */
+ enum class SourceEventType
+ {
+ START, ///< Drag and drop is started.
+ CANCEL, ///< Drag and drop is cancelled.
+ ACCEPT, ///< Drag and drop is accepted.
+ FINISH ///< Drag and drop is finished.
+ };
+
+ /**
* @brief Enumeration for the drag event type in the target object
*/
enum class DragType
};
using DragAndDropFunction = std::function<void(const DragEvent&)>;
+ using SourceFunction = std::function<void(enum SourceEventType)>;
/**
* @brief Create an uninitialized DragAndDrop.
* @brief Start the drag operation.
*
* @param[in] source The drag source object.
- * @param[in] shadow The shadow object for drag object.
+ * @param[in] shadowWindow The shadow window for drag object.
* @param[in] dragData The data to send to target object.
+ * @param[in] callback The drag source event callback.
* @return bool true if the drag operation is started successfully.
*/
- bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const DragData& dragData);
+ bool StartDragAndDrop(Dali::Actor source, Dali::Window shadowWindow, const DragData& dragData, Dali::DragAndDrop::SourceFunction callback);
/**
* @brief Add the listener for receiving the drag and drop events.
return ECORE_CALLBACK_PASS_ON;
}
+static Eina_Bool EcoreEventDataSourceEnd(void* data, int type, void* event)
+{
+ Ecore_Wl2_Event_Data_Source_End *ev = reinterpret_cast<Ecore_Wl2_Event_Data_Source_End*>(event);
+ DragAndDropEcoreWl* dndImpl = reinterpret_cast<DragAndDropEcoreWl*>(data);
+ if(ev->cancelled)
+ {
+ dndImpl->CallSourceEvent(Dali::DragAndDrop::SourceEventType::CANCEL);
+ }
+ else
+ {
+ dndImpl->CallSourceEvent(Dali::DragAndDrop::SourceEventType::ACCEPT);
+ }
+
+ return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool EcoreEventDataSourceDrop(void* data, int type, void* event)
+{
+ DragAndDropEcoreWl* dndImpl = reinterpret_cast<DragAndDropEcoreWl*>(data);
+ dndImpl->CallSourceEvent(Dali::DragAndDrop::SourceEventType::FINISH);
+ return ECORE_CALLBACK_PASS_ON;
+}
+
static Eina_Bool EcoreEventOfferDataReady(void* data, int type, void* event)
{
DragAndDropEcoreWl* dndImpl = reinterpret_cast<DragAndDropEcoreWl*>(data);
return ECORE_CALLBACK_PASS_ON;
}
+static Eina_Bool EcoreEventDataEnter(void* data, int type, void* event)
+{
+ Ecore_Wl2_Event_Dnd_Enter* ev = reinterpret_cast<Ecore_Wl2_Event_Dnd_Enter*>(event);
+
+ // Set default offer is reject
+ ecore_wl2_offer_accept(ev->offer, NULL);
+
+ return ECORE_CALLBACK_PASS_ON;
+}
+
Dali::DragAndDrop GetDragAndDrop()
{
Dali::DragAndDrop dnd;
DragAndDropEcoreWl::DragAndDropEcoreWl()
{
- 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);
+ // Source Events
+ mSendHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this);
+ mSourceEndHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_END, EcoreEventDataSourceEnd, this);
+ mSourceDropHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_DROP, EcoreEventDataSourceDrop, this);
+
+ // Target Events
+ 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);
+ mEnterHandler = ecore_event_handler_add(ECORE_WL2_EVENT_DND_ENTER, EcoreEventDataEnter, this);
}
DragAndDropEcoreWl::~DragAndDropEcoreWl()
{
+ // Source Events
ecore_event_handler_del(mSendHandler);
+ ecore_event_handler_del(mSourceEndHandler);
+ ecore_event_handler_del(mSourceDropHandler);
+
+ // Target Events
ecore_event_handler_del(mReceiveHandler);
ecore_event_handler_del(mMotionHandler);
ecore_event_handler_del(mDropHandler);
+ ecore_event_handler_del(mEnterHandler);
}
-bool DragAndDropEcoreWl::StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const Dali::DragAndDrop::DragData& data)
+bool DragAndDropEcoreWl::StartDragAndDrop(Dali::Actor source, Dali::Window shadowWindow, const Dali::DragAndDrop::DragData& data, Dali::DragAndDrop::SourceFunction callback)
{
// Get Parent Window
auto parent = Dali::DevelWindow::Get(source);
mMimeType = data.GetMimeType();
mData = data.GetData();
- // Apply Shadow Property
- shadow.SetProperty(Dali::Actor::Property::SIZE, Vector2(150, 150));
- shadow.SetProperty(Dali::Actor::Property::OPACITY, 0.9f);
+ // Set Source Event
+ mSourceCallback = callback;
- // Create Drag Window
- mDragWindow = Dali::Window::New(Dali::PositionSize(0, 0, 150, 150), "DragWindow", "class", true);
- mDragWindow.SetTransparency(true);
- mDragWindow.SetSize(Dali::Window::WindowSize(150, 150));
- mDragWindow.SetBackgroundColor(Color::TRANSPARENT);
- mDragWindow.Add(shadow);
+ // Set Drag Window
+ mDragWindow = shadowWindow;
// Start Drag and Drop
Ecore_Wl2_Window* parentWindow = AnyCast<Ecore_Wl2_Window*>(parent.GetNativeHandle());
// Start wayland drag and drop
mSerial = ecore_wl2_dnd_drag_start(input, parentWindow, dragWindow);
+ // Call Start Event
+ CallSourceEvent(Dali::DragAndDrop::SourceEventType::START);
+
return true;
}
return true;
}
+void DragAndDropEcoreWl::CallSourceEvent(Dali::DragAndDrop::SourceEventType type)
+{
+ if(mSourceCallback)
+ {
+ mSourceCallback(type);
+ }
+}
+
void DragAndDropEcoreWl::SendData(void* event)
{
Ecore_Wl2_Event_Data_Source_Send* ev = reinterpret_cast<Ecore_Wl2_Event_Data_Source_Send*>(event);
Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mPosition, ev->mimetype, ev->data);
mDropTargets[mTargetIndex].callback(dragEvent);
mDropTargets[mTargetIndex].inside = false;
+ ecore_wl2_offer_finish(ev->offer);
}
mTargetIndex = -1;
}
dragEvent.SetAction(Dali::DragAndDrop::DragType::ENTER);
dragEvent.SetPosition(curPosition);
mDropTargets[i].callback(dragEvent);
+ // Accept Offer
+ ecore_wl2_offer_mimes_set(ev->offer, ecore_wl2_offer_mimes_get(ev->offer));
}
else if(!currentInside && mDropTargets[i].inside)
{
dragEvent.SetAction(Dali::DragAndDrop::DragType::LEAVE);
dragEvent.SetPosition(curPosition);
mDropTargets[i].callback(dragEvent);
+ // Reject Offer
+ ecore_wl2_offer_accept(ev->offer, NULL);
}
else if(currentInside && mDropTargets[i].inside)
{
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);
/**
* @copydoc Dali::DragAndDrop::StartDragAndDrop()
*/
- bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const Dali::DragAndDrop::DragData& data) override;
+ bool StartDragAndDrop(Dali::Actor source, Dali::Window shadowWindow, const Dali::DragAndDrop::DragData& data, Dali::DragAndDrop::SourceFunction callback) override;
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
bool CalculateViewRegion(void* event) override;
+ /**
+ * @brief Call drag source events.
+ */
+ void CallSourceEvent(Dali::DragAndDrop::SourceEventType type);
+
private:
DragAndDropEcoreWl(const DragAndDropEcoreWl&) = delete;
DragAndDropEcoreWl& operator=(DragAndDropEcoreWl&) = delete;
DragAndDropEcoreWl& operator=(DragAndDropEcoreWl&&) = delete;
private:
- Dali::Window mDragWindow;
- uint32_t mSerial{0u};
- Ecore_Event_Handler* mSendHandler{nullptr};
- Ecore_Event_Handler* mReceiveHandler{nullptr};
- Ecore_Event_Handler* mMotionHandler{nullptr};
- Ecore_Event_Handler* mDropHandler{nullptr};
- int mTargetIndex{0};
- std::string mMimeType;
- std::string mData;
- int mDataSize{0};
- Dali::Vector2 mPosition;
+ Dali::Window mDragWindow;
+ uint32_t mSerial{0u};
+ Ecore_Event_Handler* mSendHandler{nullptr};
+ Ecore_Event_Handler* mSourceEndHandler{nullptr};
+ Ecore_Event_Handler* mSourceDropHandler{nullptr};
+ Ecore_Event_Handler* mReceiveHandler{nullptr};
+ Ecore_Event_Handler* mMotionHandler{nullptr};
+ Ecore_Event_Handler* mDropHandler{nullptr};
+ Ecore_Event_Handler* mEnterHandler{nullptr};
+ int mTargetIndex{0};
+ std::string mMimeType;
+ std::string mData;
+ int mDataSize{0};
+ Dali::Vector2 mPosition;
+ Dali::DragAndDrop::SourceFunction mSourceCallback{nullptr};
std::vector<DropTarget> mDropTargets;
}; // class DragAndDropEcoreWl