return GetImplementation(*this).StartDragAndDrop(source, shadowWindow, dragData, callback);
}
-bool DragAndDrop::AddListener(Dali::Actor target, DragAndDropFunction callback)
+bool DragAndDrop::AddListener(Dali::Actor target, char* mimeType, DragAndDropFunction callback)
{
- return GetImplementation(*this).AddListener(target, callback);
+ return GetImplementation(*this).AddListener(target, mimeType, callback);
}
bool DragAndDrop::RemoveListener(Dali::Actor target)
return GetImplementation(*this).RemoveListener(target);
}
-bool DragAndDrop::AddListener(Dali::Window target, DragAndDropFunction callback)
+bool DragAndDrop::AddListener(Dali::Window target, char* mimeType, DragAndDropFunction callback)
{
- return GetImplementation(*this).AddListener(target, callback);
+ return GetImplementation(*this).AddListener(target, mimeType, callback);
}
bool DragAndDrop::RemoveListener(Dali::Window target)
{
DragEvent()
{
- this->mimeType = nullptr;
+ this->mimeTypes = nullptr;
this->data = nullptr;
}
- DragEvent(DragType type, Dali::Vector2 position, const char* mimeType = nullptr, char* data = nullptr)
+ DragEvent(DragType type, Dali::Vector2 position, const char** mimeTypes = nullptr, int mimeTypesSize = 0, char* data = nullptr)
{
- this->type = type;
- this->position = position;
- this->mimeType = mimeType;
- this->data = data;
+ this->type = type;
+ this->position = position;
+ this->mimeTypes = mimeTypes;
+ this->mimeTypesSize = mimeTypesSize;
+ this->data = data;
}
void SetAction(DragType type)
{
return position;
}
- void SetMimeType(const char* mimeType)
+ void SetMimeTypes(const char** mimeTypes, int mimeTypeSize)
+ {
+ this->mimeTypes = mimeTypes;
+ this->mimeTypesSize = mimeTypeSize;
+ }
+ const char** GetMimeTypes()
{
- this->mimeType = mimeType;
+ return this->mimeTypes;
}
- const char* GetMimeType()
+ int GetMimeTypesSize() const
{
- return mimeType;
+ return mimeTypesSize;
}
void SetData(char* data)
{
private:
DragType type{DragType::DROP}; ///< The drag event type.
Dali::Vector2 position; ///< The position of drag object.
- const char* mimeType; ///< The mime type of drag object.
+ const char** mimeTypes{nullptr}; ///< The mime types of drag object.
char* data{nullptr}; ///< The data of drag object.
+ int mimeTypesSize{0}; ///< The size of mime types array.
};
/**
*/
struct DragData
{
- void SetMimeType(const char* mimeType)
+ void SetMimeTypes(const char** mimeTypes, int mimeTypesSize)
+ {
+ this->mimeTypes = mimeTypes;
+ this->mimeTypesSize = mimeTypesSize;
+ }
+
+ const char** GetMimeTypes() const
{
- this->mimeType = mimeType;
+ return mimeTypes;
}
- const char* GetMimeType() const
+
+ int GetMimeTypesSize() const
+ {
+ return mimeTypesSize;
+ }
+
+ void SetDataSet(const char** dataSet, int dataSetSize)
{
- return mimeType;
+ this->dataSet = dataSet;
+ this->dataSetSize = dataSetSize;
}
- void SetData(const char* data)
+
+ const char** GetDataSet() const
{
- this->data = data;
+ return dataSet;
}
- const char* GetData() const
+
+ int GetDataSetSize() const
{
- return data;
+ return dataSetSize;
}
private:
- const char* mimeType{nullptr}; ///<The mime type of drag data.
- const char* data{nullptr}; ///<The drag data.
+ const char** mimeTypes{nullptr};///< The mime types of drag object.
+ int mimeTypesSize{0}; ///< The size of mime types.
+ const char** dataSet{nullptr}; ///<The drag data set.
+ int dataSetSize{0}; ///<The size of data set.
};
using DragAndDropFunction = std::function<void(const DragEvent&)>;
* @brief Add the listener for receiving the drag and drop events.
*
* @param[in] target The drop target object.
+ * @param[in] mimeType The mime type of target object.
* @param[in] callback A drag and drop event callback.
* @return bool true if the listener is added successfully.
*/
- bool AddListener(Dali::Actor target, DragAndDropFunction callback);
+ bool AddListener(Dali::Actor target, char* mimeType, DragAndDropFunction callback);
/**
* @brief Remove the listener.
* @brief Add the listener for receiving the drag and drop events.
*
* @param[in] target The drop target object.
+ * @param[in] mimeType The mime type of target object.
* @param[in] callback A drag and drop event callback.
* @return bool true if the listener is added successfully.
*/
- bool AddListener(Dali::Window target, DragAndDropFunction callback);
+ bool AddListener(Dali::Window target, char* mimeType, DragAndDropFunction callback);
/**
* @brief Remove the listener.
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- virtual bool AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback) = 0;
+ virtual bool AddListener(Dali::Actor target, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback) = 0;
/**
* @copydoc Dali::DragAndDrop::RemoveListener()
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- virtual bool AddListener(Dali::Window window, Dali::DragAndDrop::DragAndDropFunction callback) = 0;
+ virtual bool AddListener(Dali::Window window, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback) = 0;
/**
* @copydoc Dali::DragAndDrop::RemoveListener()
return true;
}
-bool DragAndDropGeneric::AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback)
+bool DragAndDropGeneric::AddListener(Dali::Actor target, char* miemType, Dali::DragAndDrop::DragAndDropFunction callback)
{
return true;
}
return true;
}
-bool DragAndDropGeneric::AddListener(Dali::Window target, Dali::DragAndDrop::DragAndDropFunction callback)
+bool DragAndDropGeneric::AddListener(Dali::Window target, char* miemType, Dali::DragAndDrop::DragAndDropFunction callback)
{
return true;
}
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- bool AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback) override;
+ bool AddListener(Dali::Actor target, char* miemType, Dali::DragAndDrop::DragAndDropFunction callback) override;
/**
* @copydoc Dali::DragAndDrop::RemoveListener()
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- bool AddListener(Dali::Window target, Dali::DragAndDrop::DragAndDropFunction callback) override;
+ bool AddListener(Dali::Window target, char* miemType, Dali::DragAndDrop::DragAndDropFunction callback) override;
/**
* @copydoc Dali::DragAndDrop::RemoveListener()
{
static constexpr int32_t DEFAULT_POSITION = -1;
static constexpr int32_t INVALID_ECORE_WL2_WINDOW_ID = -1;
+static constexpr int32_t MAX_MIME_SIZE = 10;
} // namespace
+static const char* mimesPool [MAX_MIME_SIZE];
+
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))
// Get Parent Window
auto parent = Dali::DevelWindow::Get(source);
- // Set Drag Source Data
- mMimeType = data.GetMimeType();
- mData = data.GetData();
+ const char** dataSet = data.GetDataSet();
+ const char** mimeTypes = data.GetMimeTypes();
+
+ mDataMap.clear();
+ for(int i=0; i<data.GetDataSetSize(); ++i)
+ {
+ mDataMap[std::string(mimeTypes[i])] = std::string(dataSet[i]);
+ }
// Set Source Event
mSourceCallback = callback;
Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(nullptr);
Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
- // Set mime type for drag and drop
- const char* mimeTypes[2];
- mimeTypes[0] = mMimeType.c_str();
- mimeTypes[1] = nullptr;
+ int mimeTypesCount = data.GetMimeTypesSize();
+ const char* waylandMimeTypes[mimeTypesCount + 1];
+ for (int i = 0; i < mimeTypesCount; ++i)
+ {
+ waylandMimeTypes[i] = mimeTypes[i];
+ }
+ waylandMimeTypes[mimeTypesCount] = nullptr;
- // Set mime type
- ecore_wl2_dnd_drag_types_set(input, (const char**)mimeTypes);
+ // Set mime types
+ ecore_wl2_dnd_drag_types_set(input, (const char**)waylandMimeTypes);
// Start wayland drag and drop
mSerial = ecore_wl2_dnd_drag_start(input, parentWindow, dragWindow);
return true;
}
-bool DragAndDropEcoreWl::AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback)
+bool DragAndDropEcoreWl::AddListener(Dali::Actor target, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback)
{
std::vector<DropTarget>::iterator itr;
for(itr = mDropTargets.begin(); itr < mDropTargets.end(); itr++)
DropTarget targetData;
targetData.target = target;
+ targetData.mimeType = mimeType;
targetData.callback = callback;
targetData.inside = false;
targetData.parentWindowId = parentWindowId;
return true;
}
-bool DragAndDropEcoreWl::AddListener(Dali::Window target, Dali::DragAndDrop::DragAndDropFunction callback)
+bool DragAndDropEcoreWl::AddListener(Dali::Window target, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback)
{
std::vector<DropWindowTarget>::iterator itr;
for(itr = mDropWindowTargets.begin(); itr < mDropWindowTargets.end(); itr++)
DropWindowTarget targetData;
targetData.target = target;
+ targetData.mimeType = mimeType;
targetData.callback = callback;
targetData.inside = false;
targetData.windowId = windowId;
return;
}
- 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;
- }
+ int dataLength = strlen(mDataMap[std::string(event_->type)].c_str());
+ int bufferSize = dataLength + 1;
data->slice.mem = new char[bufferSize];
data->slice.len = bufferSize;
- memcpy(data->slice.mem, mData.c_str(), dataLength);
+ memcpy(data->slice.mem, mDataMap[std::string(event_->type)].c_str(), dataLength);
((char*)data->slice.mem)[dataLength] = '\0';
ecore_main_fd_handler_add(event_->fd, ECORE_FD_WRITE, WriteDelayedDataTofd, data, nullptr, nullptr);
if(mTargetIndex != -1)
{
- Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mPosition, event_->mimetype, event_->data);
+ mimesPool[0] = event_->mimetype;
+ mimesPool[1] = nullptr;
+ Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mPosition, mimesPool, 1, event_->data);
mDropTargets[mTargetIndex].callback(dragEvent);
mDropTargets[mTargetIndex].inside = false;
}
if(mWindowTargetIndex != -1)
{
- Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mWindowPosition, event_->mimetype, event_->data);
+ mimesPool[0] = event_->mimetype;
+ mimesPool[1] = nullptr;
+ Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mWindowPosition, mimesPool, 1, event_->data);
mDropWindowTargets[mWindowTargetIndex].callback(dragEvent);
mDropWindowTargets[mWindowTargetIndex].inside = false;
}
{
if(event_->win == static_cast<EcoreWl2EventDragAndDropWindowIdType>(mDropWindowTargets[i].windowId))
{
- Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mWindowPosition, event_->mimetype, event_->data);
+ mimesPool[0] = event_->mimetype;
+ mimesPool[1] = nullptr;
+ Dali::DragAndDrop::DragEvent dragEvent(Dali::DragAndDrop::DragType::DROP, mWindowPosition, mimesPool, 1, event_->data);
mDropWindowTargets[i].callback(dragEvent);
break;
}
Eina_Array* mimes = ecore_wl2_offer_mimes_get(event_->offer);
if(mimes == nullptr)
{
- dragEvent.SetMimeType("");
+ mimesPool[0] = "";
+ dragEvent.SetMimeTypes(mimesPool, 0);
}
else
{
- dragEvent.SetMimeType((const char*)eina_array_data_get(mimes, 0));
+ unsigned int mimeCount = (unsigned int)eina_array_count((Eina_Array*)mimes);
+ if (mimeCount > MAX_MIME_SIZE)
+ {
+ mimeCount = MAX_MIME_SIZE;
+ }
+ for (unsigned int i = 0; i < mimeCount; ++i)
+ {
+ mimesPool[i] = (char*)eina_array_data_get((Eina_Array*)mimes, i);
+ }
+ dragEvent.SetMimeTypes(mimesPool, mimeCount);
}
ProcessDragEventsForTargets(event_, dragEvent, mimes);
mPosition = position;
Dali::Window window = Dali::DevelWindow::Get(mDropTargets[i].target);
- char* mimetype = (char*)eina_array_data_get(mimes, 0);
- if(mimetype)
+ unsigned int mimeCount = (unsigned int)eina_array_count((Eina_Array*)mimes);
+ for (unsigned int j = 0; j < mimeCount; ++j)
{
- ecore_wl2_offer_receive(event->offer, mimetype);
- Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(nullptr);
- Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
- ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
+ char* availableType = (char*)eina_array_data_get((Eina_Array*)mimes, j);
+ if (!availableType)
+ {
+ return false;
+ }
+
+ if (!strcmp(mDropTargets[i].mimeType.c_str(),"*/*")
+ || !strcmp(availableType, mDropTargets[i].mimeType.c_str()))
+ {
+ ecore_wl2_offer_receive(event->offer, availableType);
+ Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(nullptr);
+ Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+ ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
+ return true;
+ }
}
- return true;
}
}
return false;
mWindowTargetIndex = i;
mWindowPosition = Dali::Vector2(position.GetX(), position.GetY());
- char* mimetype = (char*)eina_array_data_get(mimes, 0);
- if(mimetype)
+ unsigned int mimeCount = (unsigned int)eina_array_count((Eina_Array*)mimes);
+ for (unsigned int j = 0; j < mimeCount; ++j)
{
- ecore_wl2_offer_receive(event->offer, mimetype);
- Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(nullptr);
- Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
- ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
+ char* availableType = (char*)eina_array_data_get((Eina_Array*)mimes, j);
+ if (!availableType)
+ {
+ return false;
+ }
+
+ if (!strcmp(mDropTargets[i].mimeType.c_str(),"*/*")
+ || !strcmp(availableType, mDropTargets[i].mimeType.c_str()))
+ {
+ ecore_wl2_offer_receive(event->offer, availableType);
+ Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(nullptr);
+ Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+ ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
+ return true;
+ }
}
- return true;
}
}
return false;
#include <dali/internal/drag-and-drop/common/drag-and-drop-impl.h>
#include <dali/internal/system/linux/dali-ecore.h>
#include <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
+#include <map>
namespace Dali
{
struct DropTarget
{
Dali::Actor target;
+ std::string mimeType;
Dali::DragAndDrop::DragAndDropFunction callback;
bool inside;
int parentWindowId;
struct DropWindowTarget
{
Dali::Window target;
+ std::string mimeType;
Dali::DragAndDrop::DragAndDropFunction callback;
bool inside;
int windowId;
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- bool AddListener(Dali::Actor target, Dali::DragAndDrop::DragAndDropFunction callback) override;
+ bool AddListener(Dali::Actor target, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback) override;
/**
* @copydoc Dali::DragAndDrop::AddListener()
*/
- bool AddListener(Dali::Window target, Dali::DragAndDrop::DragAndDropFunction callback) override;
+ bool AddListener(Dali::Window target, char* mimeType, Dali::DragAndDrop::DragAndDropFunction callback) override;
/**
* @copydoc Dali::DragAndDrop::RemoveListener()
DragAndDropEcoreWl& operator=(DragAndDropEcoreWl&&) = delete;
private:
- Dali::Window mDragWindow;
- uint32_t mSerial{std::numeric_limits<uint32_t>::max()};
- 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};
- Ecore_Event_Handler* mLeaveHandler{nullptr};
- int mTargetIndex{-1};
- int mWindowTargetIndex{-1};
- std::string mMimeType;
- std::string mData;
- int mDataSize{0};
- Dali::Vector2 mPosition;
- Dali::Vector2 mWindowPosition;
- Dali::DragAndDrop::SourceFunction mSourceCallback{nullptr};
- std::vector<DropTarget> mDropTargets;
- std::vector<DropWindowTarget> mDropWindowTargets;
+ Dali::Window mDragWindow;
+ uint32_t mSerial{std::numeric_limits<uint32_t>::max()};
+ 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};
+ Ecore_Event_Handler* mLeaveHandler{nullptr};
+ int mTargetIndex{-1};
+ int mWindowTargetIndex{-1};
+ Dali::Vector2 mPosition;
+ Dali::Vector2 mWindowPosition;
+ Dali::DragAndDrop::SourceFunction mSourceCallback{nullptr};
+ std::vector<DropTarget> mDropTargets;
+ std::vector<DropWindowTarget> mDropWindowTargets;
+ std::map<std::string, std::string> mDataMap;
}; // class DragAndDropEcoreWl
} // namespace Adaptor