7 #include "Ecore_Win32.h"
8 #include "ecore_win32_private.h"
10 /*============================================================================*
12 *============================================================================*/
19 static int _ecore_win32_dnd_init_count = 0;
21 static HANDLE DataToHandle(const char *data, int size)
24 ptr = (char *)GlobalAlloc(GMEM_FIXED, size);
25 memcpy(ptr, data, size);
34 /*============================================================================*
36 *============================================================================*/
39 /*============================================================================*
41 *============================================================================*/
44 * @addtogroup Ecore_Win32_Group Ecore_Win32 library
50 * @brief Initialize the Ecore_Win32 Drag and Drop module.
52 * @return 1 or greater on success, 0 on error.
54 * This function initialize the Drag and Drop module. It returns 0 on
55 * failure, otherwise it returns the number of times it has already
58 * When the Drag and Drop module is not used anymore, call
59 * ecore_win32_dnd_shutdown() to shut down the module.
62 ecore_win32_dnd_init()
64 if (_ecore_win32_dnd_init_count > 0)
66 _ecore_win32_dnd_init_count++;
67 return _ecore_win32_dnd_init_count;
70 if (OleInitialize(NULL) != S_OK)
73 _ecore_win32_dnd_init_count++;
75 return _ecore_win32_dnd_init_count;
79 * @brief Shut down the Ecore_Win32 Drag and Drop module.
81 * @return 0 when the module is completely shut down, 1 or
84 * This function shuts down the Drag and Drop module. It returns 0 when it has
85 * been called the same number of times than ecore_win32_dnd_init(). In that case
86 * it shut down the module.
89 ecore_win32_dnd_shutdown()
91 _ecore_win32_dnd_init_count--;
92 if (_ecore_win32_dnd_init_count > 0) return _ecore_win32_dnd_init_count;
96 if (_ecore_win32_dnd_init_count < 0) _ecore_win32_dnd_init_count = 0;
98 return _ecore_win32_dnd_init_count;
102 * @brief Begin a DnD operation.
104 * @param data The name pf the Drag operation.
105 * @param size The size of the name.
106 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
108 * This function start a Drag operation with the name @p data. If
109 * @p data is @c NULL, @c EINA_FALSE is returned. if @p size is less than
110 * @c 0, it is set to the length (as strlen()) of @p data. On success the
111 * function returns @c EINA_TRUE, otherwise it returns @c EINA_FALSE.
114 ecore_win32_dnd_begin(const char *data,
117 IDataObject *pDataObject = NULL;
118 IDropSource *pDropSource = NULL;
119 FORMATETC fmtetc = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
120 STGMEDIUM stgmed = { TYMED_HGLOBAL, { 0 }, 0 };
121 Eina_Bool res = EINA_FALSE;
127 size = strlen(data) + 1;
129 stgmed.hGlobal = DataToHandle(data, size);
131 // create the data object
132 pDataObject = (IDataObject *)_ecore_win32_dnd_data_object_new((void *)&fmtetc,
135 pDropSource = (IDropSource *)_ecore_win32_dnd_drop_source_new();
137 if (pDataObject && pDropSource)
140 DWORD dwEffect = DROPEFFECT_COPY;
143 dwResult = DoDragDrop(pDataObject, pDropSource, DROPEFFECT_COPY, &dwEffect);
145 // finished. Check the return values to see if we need to do anything else
146 if (dwResult == DRAGDROP_S_DROP)
148 //printf(">>> \"%s\" Dropped <<<\n", str);
149 if(dwEffect == DROPEFFECT_MOVE)
151 // remove the data we just dropped from active document
154 //else if (dwResult == DRAGDROP_S_CANCEL)
155 // printf("DND cancelled\n");
157 // printf("DND error\n");
162 _ecore_win32_dnd_data_object_free(pDataObject);
163 _ecore_win32_dnd_drop_source_free(pDropSource);
166 ReleaseStgMedium(&stgmed);
172 * @brief Register a Drop operation.
174 * @param window The destination of the Drop operation.
175 * @param callback The callback called when the Drop operation
177 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
179 * This function register a Drop operation on @p window. Once the Drop
180 * operation finishes, @p callback is called. If @p window is @c NULL,
181 * the function returns @c EINA_FALSE. On success, it returns @c EINA_TRUE,
182 * otherwise it returns @c EINA_FALSE.
185 ecore_win32_dnd_register_drop_target(Ecore_Win32_Window *window,
186 Ecore_Win32_Dnd_DropTarget_Callback callback)
188 Ecore_Win32_Window *wnd = (Ecore_Win32_Window *)window;
193 wnd->dnd_drop_target = _ecore_win32_dnd_register_drop_window(wnd->window,
196 return wnd->dnd_drop_target ? EINA_TRUE : EINA_FALSE;
200 * @brief Unregister a Drop operation.
202 * @param window The destination of the Drop operation.
204 * This function unregister a Drop operation on @p window. If
205 * @p window is @c NULL, the function does nothing.
208 ecore_win32_dnd_unregister_drop_target(Ecore_Win32_Window *window)
210 Ecore_Win32_Window *wnd = (Ecore_Win32_Window *)window;
215 if (wnd->dnd_drop_target)
216 _ecore_win32_dnd_unregister_drop_window(wnd->window, wnd->dnd_drop_target);