diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-10-05 03:10:14 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-10-05 03:10:14 +0200 |
commit | a15c39546054d8ee608ec1c12e9e14be43dda783 (patch) | |
tree | 020f29b9ffaa343e7300962aa71da228ca087d8d /src/libui_sdl | |
parent | 084d9254e368d189a21a262d5bb630bfed88413d (diff) |
GTK: file drop support. adsfgdgfdg
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/libui/unix/window.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/libui_sdl/libui/unix/window.c b/src/libui_sdl/libui/unix/window.c index a16076f..a3dde76 100644 --- a/src/libui_sdl/libui/unix/window.c +++ b/src/libui_sdl/libui/unix/window.c @@ -286,9 +286,57 @@ void uiWindowSetMargined(uiWindow *w, int margined) setMargined(w->childHolderContainer, w->margined); } +static void onDragDataReceived(GtkWidget* widget, GdkDragContext* ctx, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer userdata) +{ + uiWindow* w = (uiWindow*)userdata; + + if (gtk_selection_data_get_length(data) > 0 && gtk_selection_data_get_format(data) == 8) + { + gchar** files = gtk_selection_data_get_uris(data); + if (files != NULL && files[0] != NULL) + { + // TODO: multi file support? + + gboolean success = FALSE; + + gchar* file = g_filename_from_uri(files[0], NULL, NULL); + if (file) + { + if (w->onDropFile) + w->onDropFile(w, file, w->onDropFileData); + + success = TRUE; + g_free(file); + } + + + g_strfreev(files); + gtk_drag_finish(ctx, success, FALSE, time); + return; + } + + if (files != NULL) g_strfreev(files); + gtk_drag_finish(ctx, FALSE, FALSE, time); + } +} + void uiWindowSetDropTarget(uiWindow* w, int drop) { - printf("DRAG DROP TODO!!!!!\n"); + if (!drop) + { + gtk_drag_dest_unset(w->widget); + return; + } + + GtkTargetEntry entry; + entry.target = "text/uri-list"; + entry.flags = GTK_TARGET_OTHER_APP; + entry.info = 1; + + // CHECKME: action copy? + gtk_drag_dest_set(w->widget, GTK_DEST_DEFAULT_ALL, &entry, 1, GDK_ACTION_COPY|GDK_ACTION_MOVE); + + g_signal_connect(w->widget, "drag-data-received", G_CALLBACK(onDragDataReceived), w); } uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable) |