static gboolean gth_file_list_drag_motion (GtkWidget *file_view, GdkDragContext *context, gint x, gint y, guint time, gpointer extra_data) { GthBrowser *browser = extra_data; BrowserData *data; GthFileData *location_data; data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); data->drop_pos = -1; if ((gtk_drag_get_source_widget (context) == file_view) && ! gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) { gdk_drag_status (context, 0, time); return FALSE; } location_data = gth_browser_get_location_data (browser); if (! g_file_info_get_attribute_boolean (location_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { gdk_drag_status (context, 0, time); return FALSE; } if (gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) { GtkAllocation allocation; if (gtk_drag_get_source_widget (context) == file_view) gdk_drag_status (context, GDK_ACTION_MOVE, time); else gdk_drag_status (context, GDK_ACTION_COPY, time); gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, x, y, time, &data->drop_pos); gtk_widget_get_allocation (file_view, &allocation); if (y < 10) data->scroll_diff = - (10 - y); else if (y > allocation.height - 10) data->scroll_diff = (10 - (allocation.height - y)); else data->scroll_diff = 0; if (data->scroll_diff != 0) { if (data->scroll_event == 0) data->scroll_event = gdk_threads_add_timeout (SCROLL_TIMEOUT, drag_motion_autoscroll_cb, browser); } else if (data->scroll_event != 0) { g_source_remove (data->scroll_event); data->scroll_event = 0; } } else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK) gdk_drag_status (context, GDK_ACTION_ASK, time); else gdk_drag_status (context, GDK_ACTION_COPY, time); return TRUE; }
static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context, gint x, gint y, guint time, gpointer data) { GtkTreePath *tpath = NULL; GtkTreeViewDropPosition pos; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); if (tpath) { GtkTreeModel *model; GtkTreeIter dest_iter; model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); gtk_tree_model_get_iter(model, &dest_iter, tpath); if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE && gtk_tree_model_iter_has_child(model, &dest_iter)) pos = GTK_TREE_VIEW_DROP_BEFORE; if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER && gtk_tree_model_iter_has_child(model, &dest_iter)) pos = GTK_TREE_VIEW_DROP_AFTER; } gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), tpath, pos); gtk_tree_path_free(tpath); if (tree_view == gtk_drag_get_source_widget(context)) gdk_drag_status(context, GDK_ACTION_MOVE, time); else gdk_drag_status(context, GDK_ACTION_COPY, time); return TRUE; }
static void interactive_canvas_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint info, guint time, gpointer data) { /* find the tool button which is the source of this DnD operation */ GtkWidget *palette = gtk_drag_get_source_widget (context); GtkWidget *tool_item = NULL; while (palette && !GTK_IS_TOOL_PALETTE (palette)) palette = gtk_widget_get_parent (palette); if (palette) tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), selection); /* create a drop indicator when a tool button was found */ g_assert (NULL == drop_item); if (GTK_IS_TOOL_ITEM (tool_item)) { drop_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y); gdk_drag_status (context, GDK_ACTION_COPY, time); gtk_widget_queue_draw (widget); } }
static void display_data_received_callback (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, DDisplay *ddisp) { if (gtk_selection_data_get_format(data) == 8 && gtk_selection_data_get_length(data) == sizeof(ToolButtonData *) && gtk_drag_get_source_widget(context) != NULL) { ToolButtonData *tooldata = *(ToolButtonData **)gtk_selection_data_get_data(data); /* g_message("Tool drop %s at (%d, %d)", (gchar *)tooldata->extra_data, x, y);*/ ddisplay_drop_object(ddisp, x, y, object_get_type((gchar *)tooldata->extra_data), tooldata->user_data); gtk_drag_finish (context, TRUE, FALSE, time); } else { dia_dnd_file_drag_data_received (widget, context, x, y, data, info, time, ddisp); } /* ensure the right window has the focus for text editing */ gtk_window_present(GTK_WINDOW(ddisp->shell)); }
G_MODULE_EXPORT gboolean gw_settingswindow_dictionary_drag_drop_cb ( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { GwSettingsWindow *window; GwSettingsWindowPrivate *priv; GtkTreeView *source; gboolean success; window = GW_SETTINGSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (widget), GW_TYPE_SETTINGSWINDOW)); g_return_val_if_fail (window != NULL, FALSE); priv = window->priv; source = GTK_TREE_VIEW (gtk_drag_get_source_widget (context)); success = FALSE; if (source == priv->manage_dictionaries_treeview) gw_settingswindow_dictionary_drag_reorder (widget, context, x, y, time, user_data); gtk_drag_finish (context, success, FALSE, time); return success; }
static gboolean is_this_drop_ok (GtkWidget *widget, GdkDragContext *context) { static GdkAtom text_uri_list = GDK_NONE; GList *l; GtkWidget *source; source = gtk_drag_get_source_widget (context); if (source == widget) return FALSE; if (!(gdk_drag_context_get_actions (context) & GDK_ACTION_COPY)) return FALSE; if (!text_uri_list) text_uri_list = gdk_atom_intern_static_string ("text/uri-list"); for (l = gdk_drag_context_list_targets (context); l; l = l->next) { if (GDK_POINTER_TO_ATOM (l->data) == text_uri_list) break; } return l ? TRUE : FALSE; }
gboolean target_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GtkWidget *source_widget; GList *tmp_list; if (!have_drag) { have_drag = TRUE; gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open); } source_widget = gtk_drag_get_source_widget (context); g_print ("motion, source %s\n", source_widget ? G_OBJECT_TYPE_NAME (source_widget) : "NULL"); tmp_list = gdk_drag_context_list_targets (context); while (tmp_list) { char *name = gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)); g_print ("%s\n", name); g_free (name); tmp_list = tmp_list->next; } gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time); return TRUE; }
static void interactive_canvas_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint info, guint time, gpointer data) { /* find the tool button which is the source of this DnD operation */ GtkWidget *palette = gtk_drag_get_source_widget (context); GtkWidget *tool_item = NULL; CanvasItem *item; while (palette && !GTK_IS_TOOL_PALETTE (palette)) palette = gtk_widget_get_parent (palette); if (palette) tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), selection); /* create a canvas item when a tool button was found */ g_assert (NULL == drop_item); if (!GTK_IS_TOOL_ITEM (tool_item)) return; if (drop_item) { canvas_item_free (drop_item); drop_item = NULL; } item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y); /* Either create a new item or just create a preview item, depending on why the drag data was requested. */ if(drag_data_requested_for_drop) { canvas_items = g_list_append (canvas_items, item); drop_item = NULL; gtk_drag_finish (context, TRUE, FALSE, time); } else { drop_item = item; gdk_drag_status (context, GDK_ACTION_COPY, time); } gtk_widget_queue_draw (widget); }
gboolean receive_drag(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time, gpointer user_data) { GtkTargetList *TL = gtk_target_list_new(target_table,1); GdkAtom target = gtk_drag_dest_find_target(widget,drag_context,TL); GtkWidget *srcWidget = gtk_drag_get_source_widget(drag_context); if (target == GDK_NONE || srcWidget == NULL) return FALSE; gtk_drag_get_data(srcWidget,drag_context,target,time); gtk_widget_queue_draw(widget); return TRUE; }
static gboolean gth_file_list_drag_leave (GtkWidget *file_view, GdkDragContext *context, guint time, gpointer extra_data) { if (gtk_drag_get_source_widget (context) == file_view) gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, -1, -1, time, NULL); return TRUE; }
static gboolean display_drop_callback(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { if (gtk_drag_get_source_widget(context) != NULL) { /* we only accept drops from the same instance of the application, * as the drag data is a pointer in our address space */ return TRUE; } gtk_drag_finish (context, FALSE, FALSE, time); return FALSE; }
static void drag_data_received_handl(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *sel_data, guint info, guint time, gpointer data) { gint i; guint candid = GPOINTER_TO_UINT(data); g_print("%s to dest %d\n", (gchar *)gtk_selection_data_get_data(sel_data), candid); i=g_strcmp0((gchar *)gtk_selection_data_get_data(sel_data), "Candidate 1"); switch(i){ case -1: merged[candid] = 0; break; case 0: merged[candid] = 1; break; case 1: merged[candid] = 2; break; default: break; } GtkWidget *source_widget; GdkPixbuf *source_buf; GtkWidget *parent; GdkPixbuf *buf; GtkWidget *new_widget; parent = gtk_widget_get_parent(GTK_WIDGET(widget)); source_widget = gtk_drag_get_source_widget(context); source_widget = gtk_button_get_image(GTK_BUTTON(source_widget)); source_buf = gtk_image_get_pixbuf(GTK_IMAGE(source_widget)); buf = gdk_pixbuf_scale_simple(source_buf, hole_sizes_w[candid], hole_sizes_h[candid], GDK_INTERP_BILINEAR); new_widget = gtk_image_new_from_pixbuf(buf); g_object_unref(buf); gtk_fixed_put(GTK_FIXED(parent), new_widget, hole_x[candid], hole_y[candid]); gtk_widget_show_all(new_widget); gtk_drag_finish (context, TRUE, FALSE, time); }
void receive_timeSeries_drag(GtkWidget *src, GdkDragContext *context, int x, int y, const GtkSelectionData *data, unsigned int info, unsigned int event_time, gpointer *udata) { splotd *to = GGOBI_SPLOT(src), *from, *sp; displayd *display; display = to->displayptr; GList *l; gint k; GList *ivars = NULL; gint xvar; from = GGOBI_SPLOT(gtk_drag_get_source_widget(context)); if(from->displayptr != display) { gg_write_to_statusbar("the source and destination of the parallel coordinate plots are not from the same display.\n", display->ggobi); return; } /* Get the x variable */ sp = (splotd *) (display->splots)->data; xvar = sp->xyvars.x; /* Gather a list of indices of the vertically plotted variables */ l = display->splots; while (l) { sp = (splotd *) l->data; ivars = g_list_append(ivars, GINT_TO_POINTER(sp->xyvars.y)); l = l->next; } /* Find the index of the to element */ k = g_list_index(ivars, GINT_TO_POINTER(to->xyvars.y)); /* Remove the from element */ ivars = g_list_remove(ivars, GINT_TO_POINTER(from->xyvars.y)); /* Insert the from element in the position of the to element */ ivars = g_list_insert(ivars, GINT_TO_POINTER(from->xyvars.y), k); /* Assign them to the existing plots */ k = 0; l = display->splots; while (l) { sp = (splotd *) l->data; sp->xyvars.y = GPOINTER_TO_INT(g_list_nth_data(ivars, k)); k++; l = l->next; } g_list_free(ivars); display_tailpipe (display, FULL, display->ggobi); varpanel_refresh (display, display->ggobi); }
gboolean panel_check_drop_forbidden (PanelWidget *panel, GdkDragContext *context, guint info, guint time_) { if (!panel) return FALSE; if (panel_lockdown_get_locked_down ()) return FALSE; if (info == TARGET_APPLET_INTERNAL) { GtkWidget *source_widget; source_widget = gtk_drag_get_source_widget (context); if (BUTTON_IS_WIDGET (source_widget)) { GSList *forb; forb = g_object_get_data (G_OBJECT (source_widget), MATE_PANEL_APPLET_FORBIDDEN_PANELS); if (g_slist_find (forb, panel)) return FALSE; } } if (info == TARGET_ICON_INTERNAL || info == TARGET_APPLET_INTERNAL) { if (gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) gdk_drag_status (context, GDK_ACTION_MOVE, time_); else gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time_); } else if (gdk_drag_context_get_actions (context) & GDK_ACTION_COPY) gdk_drag_status (context, GDK_ACTION_COPY, time_); else gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time_); return TRUE; }
/** * gtk_drag_dest_find_target: (method) * @widget: drag destination widget * @context: drag context * @target_list: (allow-none): list of droppable targets, or %NULL to use * gtk_drag_dest_get_target_list (@widget). * * Looks for a match between the supported targets of @context and the * @dest_target_list, returning the first matching target, otherwise * returning %GDK_NONE. @dest_target_list should usually be the return * value from gtk_drag_dest_get_target_list(), but some widgets may * have different valid targets for different parts of the widget; in * that case, they will have to implement a drag_motion handler that * passes the correct target list to this function. * * Returns: (transfer none): first target that the source offers * and the dest can accept, or %GDK_NONE */ GdkAtom gtk_drag_dest_find_target (GtkWidget *widget, GdkDragContext *context, GtkTargetList *target_list) { GList *tmp_target; GList *tmp_source = NULL; GtkWidget *source_widget; g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE); g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE); source_widget = gtk_drag_get_source_widget (context); if (target_list == NULL) target_list = gtk_drag_dest_get_target_list (widget); if (target_list == NULL) return GDK_NONE; tmp_target = target_list->list; while (tmp_target) { GtkTargetPair *pair = tmp_target->data; tmp_source = gdk_drag_context_list_targets (context); while (tmp_source) { if (tmp_source->data == GUINT_TO_POINTER (pair->target)) { if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) && (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)) && (!(pair->flags & GTK_TARGET_OTHER_APP) || !source_widget) && (!(pair->flags & GTK_TARGET_OTHER_WIDGET) || (source_widget != widget))) return pair->target; else break; } tmp_source = tmp_source->next; } tmp_target = tmp_target->next; } return GDK_NONE; }
G_MODULE_EXPORT void gw_settingswindow_dictionary_drag_motion_cb ( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer data) { //Declarations GwSettingsWindow *window; GwSettingsWindowPrivate *priv; GtkTreeView *view; GtkTreeViewDropPosition drop_position; GtkTreePath *path; GtkTreeView *source; //Initializations window = GW_SETTINGSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (widget), GW_TYPE_SETTINGSWINDOW)); g_return_if_fail (window != NULL); priv = window->priv; view = GTK_TREE_VIEW (widget); source = GTK_TREE_VIEW (gtk_drag_get_source_widget (context)); if (source == priv->manage_dictionaries_treeview) { gtk_tree_view_get_dest_row_at_pos (view, x, y, &path, &drop_position); if (path != NULL) { if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) drop_position = GTK_TREE_VIEW_DROP_BEFORE; else if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) drop_position = GTK_TREE_VIEW_DROP_AFTER; gtk_tree_view_set_drag_dest_row (view, path, drop_position); } } if (path != NULL) gtk_tree_path_free (path); path = NULL; }
static void palette_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint info, guint time, gpointer data) { GtkAllocation allocation; GtkToolItemGroup *drop_group = NULL; GtkWidget *drag_palette = gtk_drag_get_source_widget (context); GtkWidget *drag_item = NULL; while (drag_palette && !GTK_IS_TOOL_PALETTE (drag_palette)) drag_palette = gtk_widget_get_parent (drag_palette); if (drag_palette) { drag_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (drag_palette), selection); drop_group = gtk_tool_palette_get_drop_group (GTK_TOOL_PALETTE (widget), x, y); } if (GTK_IS_TOOL_ITEM_GROUP (drag_item)) palette_drop_group (GTK_TOOL_PALETTE (drag_palette), GTK_TOOL_ITEM_GROUP (drag_item), drop_group); else if (GTK_IS_TOOL_ITEM (drag_item) && drop_group) { gtk_widget_get_allocation (GTK_WIDGET (drop_group), &allocation); palette_drop_item (GTK_TOOL_ITEM (drag_item), drop_group, x - allocation.x, y - allocation.y); } }
int clip_GTK_DRAGGETSOURCEWIDGET(ClipMachine * cm) { C_object *ccontext = _fetch_co_arg(cm); GtkWidget *wid ; C_widget *cwid ; if (!ccontext || ccontext->type != GDK_TYPE_DRAG_CONTEXT) goto err; wid = gtk_drag_get_source_widget((GdkDragContext*)ccontext->object); if (wid) { cwid = _list_get_cwidget(cm, wid); if (!cwid) cwid = _register_widget(cm, wid, NULL); if (cwid) _clip_mclone(cm, RETPTR(cm), &cwid->obj); } return 0; err: return 1; }
static void passive_canvas_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint info, guint time, gpointer data) { /* find the tool button, which is the source of this DnD operation */ GtkWidget *palette = gtk_drag_get_source_widget (context); CanvasItem *canvas_item = NULL; GtkWidget *tool_item = NULL; while (palette && !GTK_IS_TOOL_PALETTE (palette)) palette = gtk_widget_get_parent (palette); if (palette) tool_item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), selection); g_assert (NULL == drop_item); /* append a new canvas item when a tool button was found */ if (GTK_IS_TOOL_ITEM (tool_item)) canvas_item = canvas_item_new (widget, GTK_TOOL_BUTTON (tool_item), x, y); if (canvas_item) { canvas_items = g_list_append (canvas_items, canvas_item); gtk_widget_queue_draw (widget); } }
/* * DND "drag_data_received" handler. When DNDDataRequestCB() * calls gtk_selection_data_set() to send out the data, this function * receives it and is responsible for handling it. * * This is also the only DND callback function where the given * inputs may reflect those of the drop target so we need to check * if this is the same structure or not. */ static void DNDDataReceivedCB( GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, gpointer data) { gboolean same; GtkWidget *source_widget; if((widget == NULL) || (data == NULL) || (dc == NULL)) return; /* Important, check if we actually got data. Sometimes errors * occure and selection_data will be NULL. */ if(selection_data == NULL) return; if(selection_data->length < 0) return; /* Source and target widgets are the same? */ source_widget = gtk_drag_get_source_widget(dc); same = (source_widget == widget) ? TRUE : FALSE; if(same) { return; } /* Now check if the data format type is one that we support * (remember, data format type, not data type). * * We check this by testing if info matches one of the info * values that we have defined. * * Note that we can also iterate through the atoms in: * GList *glist = dc->targets; * * while(glist != NULL) * { * gchar *name = gdk_atom_name((GdkAtom)glist->data); * * strcmp the name to see if it matches * * one that we support * * * glist = glist->next; * } */ if((info == WAVE_DRAG_TAR_INFO_0) || (info == WAVE_DRAG_TAR_INFO_1) || (info == WAVE_DRAG_TAR_INFO_2)) { int impcnt = 0; ds_Tree *ft = NULL; int argc = 0; char**zs = zSplitTclList((const char *)selection_data->data, &argc); if(zs) { int i; for(i=0;i<argc;i++) { if((!strncmp("net ", zs[i], 4)) || (!strncmp("netBus ", zs[i], 7))) { char *stemp = strdup(zs[i]); char *ss = strchr(stemp, ' ') + 1; char *sl = strrchr(stemp, ' '); char *pnt = ss; if(sl) { *sl = 0; while(*pnt) { if(*pnt == ' ') { *pnt = '.'; } pnt++; } } ft = flattened_mod_list_root; while(ft) { if(!strcmp(ss, ft->fullname)) { if(!ft->dnd_to_import) { ft->dnd_to_import = 1; impcnt++; } break; } ft = ft->next_flat; } free(stemp); } } free(zs); } if(impcnt) { ds_Tree **fta = calloc(impcnt, sizeof(ds_Tree *)); int i = 0; while(ft) { if(ft->dnd_to_import) { ft->dnd_to_import = 0; fta[i++] = ft; if(i == impcnt) break; } ft = ft->next_flat; } for(i=impcnt-1;i>=0;i--) /* reverse list so it is forwards in rtlbrowse */ { bwlogbox(fta[i]->fullname, 640 + 8*8, fta[i], 0); } free(fta); } } }
void MainWindow::dragDataRecived(GtkWidget * widget, GdkDragContext * dragContext, gint x, gint y, GtkSelectionData * data, guint info, guint time, MainWindow * win) { GtkWidget * source = gtk_drag_get_source_widget(dragContext); if (source && widget == gtk_widget_get_toplevel(source)) { gtk_drag_finish(dragContext, false, false, time); return; } guchar * text = gtk_selection_data_get_text(data); if (text) { win->control->clipboardPasteText((const char *) text); g_free(text); gtk_drag_finish(dragContext, true, false, time); return; } GdkPixbuf * image = gtk_selection_data_get_pixbuf(data); if (image) { win->control->clipboardPasteImage(image); gdk_pixbuf_unref(image); gtk_drag_finish(dragContext, true, false, time); return; } // TODO LOW PRIO: use x and y for insert location! gchar ** uris = gtk_selection_data_get_uris(data); if (uris) { for (int i = 0; uris[i] != NULL && i < 3; i++) { const char * uri = uris[i]; // TODO LOW PRIO: check first if its an image // GSList * imageFormats = gdk_pixbuf_get_formats(); // for(GSList * l = imageFormats; l != NULL; l = l->next) { // GdkPixbufFormat * f = (GdkPixbufFormat *)l->data; // printf("", f); // } // // g_slist_free(imageFormats); GFile * file = g_file_new_for_uri(uri); GError * err = NULL; GCancellable * cancel = g_cancellable_new(); int cancelTimeout = g_timeout_add(3000, (GSourceFunc) cancellable_cancel, cancel); GFileInputStream * in = g_file_read(file, cancel, &err); if (g_cancellable_is_cancelled(cancel)) { continue; } g_object_unref(file); if (err == NULL) { GdkPixbuf * pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } g_input_stream_close(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } if (pixbuf) { win->control->clipboardPasteImage(pixbuf); gdk_pixbuf_unref(pixbuf); } } else { g_error_free(err); } if (!g_cancellable_is_cancelled(cancel)) { g_source_remove(cancelTimeout); } g_object_unref(cancel); //TODO LOW PRIO: handle .xoj, .pdf and Images printf("open uri: %s\n", uris[i]); } gtk_drag_finish(dragContext, true, false, time); g_strfreev(uris); } gtk_drag_finish(dragContext, false, false, time); }
static void view_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { ViewWindow *vw = data; ImageWindow *imd; if (gtk_drag_get_source_widget(context) == vw->imd->pr) return; imd = vw->imd; if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER) { CollectionData *source; GList *list; GList *info_list; if (info == TARGET_URI_LIST) { GList *work; list = uri_filelist_from_gtk_selection_data(selection_data); work = list; while (work) { FileData *fd = work->data; if (isdir(fd->path)) { GtkWidget *menu; menu = view_confirm_dir_list(vw, list); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time); return; } work = work->next; } list = filelist_filter(list, FALSE); source = NULL; info_list = NULL; } else { source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list); } if (list) { FileData *fd; fd = list->data; if (isfile(fd->path)) { view_slideshow_stop(vw); view_window_set_list(vw, NULL); if (source && info_list) { image_change_from_collection(imd, source, info_list->data, image_zoom_get_default(imd)); } else { if (list->next) { vw->list = list; list = NULL; vw->list_pointer = vw->list; } image_change_fd(imd, fd, image_zoom_get_default(imd)); } } } filelist_free(list); g_list_free(info_list); } }
static VALUE rg_m_get_source_widget(G_GNUC_UNUSED VALUE self, VALUE context) { return GOBJ2RVAL(gtk_drag_get_source_widget(RVAL2DC(context))); }
static void gth_file_list_drag_data_received (GtkWidget *file_view, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, gpointer user_data) { GthBrowser *browser = user_data; gboolean success = FALSE; char **uris; GList *selected_files; GdkDragAction action; g_signal_stop_emission_by_name (file_view, "drag-data-received"); action = gdk_drag_context_get_suggested_action (context); if (action == GDK_ACTION_COPY || action == GDK_ACTION_MOVE) { success = TRUE; } if (action == GDK_ACTION_ASK) { GdkDragAction actions = _gtk_menu_ask_drag_drop_action (file_view, gdk_drag_context_get_actions (context), time); gdk_drag_status (context, actions, time); success = gdk_drag_context_get_selected_action (context) != 0; } if (gtk_selection_data_get_data_type (selection_data) == XDND_ACTION_DIRECT_SAVE_ATOM) { const guchar *data; int format; int length; data = gtk_selection_data_get_data (selection_data); format = gtk_selection_data_get_format (selection_data); length = gtk_selection_data_get_length (selection_data); if ((format == 8) && (length == 1) && (data[0] == 'S')) { success = TRUE; } else { gdk_property_change (gdk_drag_context_get_dest_window (context), XDND_ACTION_DIRECT_SAVE_ATOM, TEXT_PLAIN_ATOM, 8, GDK_PROP_MODE_REPLACE, (const guchar *) "", 0); success = FALSE; } gtk_drag_finish (context, success, FALSE, time); return; } gtk_drag_finish (context, success, FALSE, time); if (! success) return; uris = gtk_selection_data_get_uris (selection_data); selected_files = _g_file_list_new_from_uriv (uris); if (selected_files != NULL) { if (gtk_drag_get_source_widget (context) == file_view) { GList *file_data_list; GList *visible_files; BrowserData *data; GthTask *task; file_data_list = gth_file_store_get_visibles (gth_browser_get_file_store (browser)); visible_files = gth_file_data_list_to_file_list (file_data_list); data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); task = gth_reorder_task_new (gth_browser_get_location_source (browser), gth_browser_get_location_data (browser), visible_files, selected_files, data->drop_pos); gth_browser_exec_task (browser, task, FALSE); g_object_unref (task); _g_object_list_unref (visible_files); _g_object_list_unref (file_data_list); } else { GthFileSource *file_source; gboolean cancel = FALSE; gboolean move; file_source = gth_browser_get_location_source (browser); move = gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE; if (move && ! gth_file_source_can_cut (file_source, (GFile *) selected_files->data)) { GtkWidget *dialog; int response; dialog = _gtk_message_dialog_new (GTK_WINDOW (browser), GTK_DIALOG_MODAL, GTK_STOCK_DIALOG_QUESTION, _("Could not move the files"), _("Files cannot be moved to the current location, as alternative you can choose to copy them."), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_COPY, GTK_RESPONSE_OK, NULL); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (response == GTK_RESPONSE_CANCEL) cancel = TRUE; move = FALSE; } if (! cancel) { GthFileSource *location_source; BrowserData *data; GthTask *task; location_source = gth_main_get_file_source (gth_browser_get_location (browser)); data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); task = gth_copy_task_new (location_source, gth_browser_get_location_data (browser), move, selected_files, data->drop_pos); gth_browser_exec_task (browser, task, FALSE); g_object_unref (task); g_object_unref (location_source); } } } _g_object_list_unref (selected_files); g_strfreev (uris); }
static gboolean slot_proxy_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, unsigned int time, gpointer user_data) { NemoDragSlotProxyInfo *drag_info; NemoWindowSlot *target_slot; GtkWidget *window; GdkAtom target; int action = 0; char *target_uri; if (gtk_drag_get_source_widget (context) == widget) { goto out; } drag_info = user_data; window = gtk_widget_get_toplevel (widget); g_assert (NEMO_IS_WINDOW (window)); if (!drag_info->have_data) { target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) { goto out; } gtk_drag_get_data (widget, context, target, time); } target_uri = NULL; if (drag_info->target_file != NULL) { target_uri = nemo_file_get_uri (drag_info->target_file); } else { if (drag_info->target_slot != NULL) { target_slot = drag_info->target_slot; } else { target_slot = nemo_window_get_active_slot (NEMO_WINDOW (window)); } if (target_slot != NULL) { target_uri = nemo_window_slot_get_current_uri (target_slot); } } if (drag_info->have_data && drag_info->have_valid_data) { if (drag_info->info == NEMO_ICON_DND_GNOME_ICON_LIST) { nemo_drag_default_drop_action_for_icons (context, target_uri, drag_info->data.selection_list, &action, &drag_info->desktop_dnd_source_fs, &drag_info->desktop_dnd_can_delete_source); } else if (drag_info->info == NEMO_ICON_DND_URI_LIST) { action = nemo_drag_default_drop_action_for_uri_list (context, target_uri); } else if (drag_info->info == NEMO_ICON_DND_NETSCAPE_URL) { action = nemo_drag_default_drop_action_for_netscape_url (context); } } g_free (target_uri); out: if (action != 0) { gtk_drag_highlight (widget); } else { gtk_drag_unhighlight (widget); } gdk_drag_status (context, action, time); return TRUE; }
static gboolean rb_tree_dnd_drag_motion_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GtkTreeView *tree_view; GtkTreePath *path = NULL; GtkTreeModel *model; GtkTreeViewDropPosition pos; RbTreeDndData *priv_data; GdkDragAction action; rb_debug ("drag and drop motion: (%i,%i)", x, y); tree_view = GTK_TREE_VIEW (widget); model = gtk_tree_view_get_model (tree_view); priv_data = g_object_get_data (G_OBJECT (widget), RB_TREE_DND_STRING); gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &path, &pos); if ((priv_data->previous_dest_path == NULL) || (path == NULL) || gtk_tree_path_compare(path,priv_data->previous_dest_path)) { remove_select_on_drag_timeout(tree_view); } if (path == NULL) { gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), NULL, GTK_TREE_VIEW_DROP_BEFORE); if (!(priv_data->dest_flags & RB_TREE_DEST_EMPTY_VIEW_DROP)) { /* Can't drop here. */ gdk_drag_status (context, 0, time); return TRUE; } else if (!filter_drop_position (widget, context, path, &pos)) { gdk_drag_status (context, 0, time); return TRUE; } } else { if (!filter_drop_position (widget, context, path, &pos)) { gdk_drag_status (context, 0, time); return TRUE; } if (priv_data->scroll_timeout == 0) { priv_data->scroll_timeout = g_timeout_add (150, scroll_row_timeout, tree_view); } } if (GTK_WIDGET (tree_view) == gtk_drag_get_source_widget (context) && context->actions & GDK_ACTION_MOVE) action = GDK_ACTION_MOVE; else action = context->suggested_action; if (path) { gtk_tree_view_set_drag_dest_row (tree_view, path, pos); if (priv_data->dest_flags & RB_TREE_DEST_SELECT_ON_DRAG_TIMEOUT) { if (priv_data->previous_dest_path != NULL) { gtk_tree_path_free (priv_data->previous_dest_path); } priv_data->previous_dest_path = path; if (priv_data->select_on_drag_timeout == 0) { rb_debug("Setting up a new select on drag timeout"); priv_data->select_on_drag_timeout = g_timeout_add_seconds (2, select_on_drag_timeout, tree_view); } } else { gtk_tree_path_free (path); } } gdk_drag_status (context, action, time); return TRUE; }
// This little bit is needed to prevent the default drag motion // handler from expanding rows if you hover over them while // dragging. // Also controls where valid drop locations are G_MODULE_EXPORT gboolean queue_drag_motion_cb( GtkTreeView *tv, GdkDragContext *ctx, gint x, gint y, guint time, signal_user_data_t *ud) { GtkTreePath *path = NULL; GtkTreeViewDropPosition pos; gint *indices, row, status, finished; GValue *js; GtkTreeIter iter; GtkTreeView *srctv; GtkTreeModel *model; GtkTreeSelection *select; GtkWidget *widget; widget = gtk_drag_get_source_widget(ctx); if (widget == NULL || widget != GTK_WIDGET(tv)) return TRUE; // This bit checks to see if the source is allowed to be // moved. Only pending and canceled items may be moved. srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx)); select = gtk_tree_view_get_selection (srctv); gtk_tree_selection_get_selected (select, &model, &iter); path = gtk_tree_model_get_path (model, &iter); indices = gtk_tree_path_get_indices(path); row = indices[0]; gtk_tree_path_free(path); js = ghb_array_get_nth(ud->queue, row); status = ghb_settings_get_int(js, "job_status"); if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED) { gdk_drag_status(ctx, 0, time); return TRUE; } // The reset checks that the destination is a valid position // in the list. Can not move above any finished or running items gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos); if (path == NULL) { gdk_drag_status(ctx, GDK_ACTION_MOVE, time); return TRUE; } // Don't allow *drop into* if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) pos = GTK_TREE_VIEW_DROP_BEFORE; if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) pos = GTK_TREE_VIEW_DROP_AFTER; // Don't allow droping int child items if (gtk_tree_path_get_depth(path) > 1) { gtk_tree_path_up(path); pos = GTK_TREE_VIEW_DROP_AFTER; } indices = gtk_tree_path_get_indices(path); row = indices[0]; js = ghb_array_get_nth(ud->queue, row); finished = find_last_finished(ud->queue); if (row < finished) { gtk_tree_path_free(path); gdk_drag_status(ctx, 0, time); return TRUE; } if (pos != GTK_TREE_VIEW_DROP_AFTER && row == finished) { gtk_tree_path_free(path); gdk_drag_status(ctx, 0, time); return TRUE; } gtk_tree_view_set_drag_dest_row(tv, path, pos); gtk_tree_path_free(path); gdk_drag_status(ctx, GDK_ACTION_MOVE, time); return TRUE; }
static gboolean slot_proxy_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, unsigned int time, gpointer user_data) { NautilusDragSlotProxyInfo *drag_info; NautilusWindowSlot *target_slot; GtkWidget *window; GdkAtom target; int action; char *target_uri; GFile *location; gboolean valid_text_drag; gboolean valid_xds_drag; drag_info = user_data; action = 0; valid_text_drag = FALSE; valid_xds_drag = FALSE; if (gtk_drag_get_source_widget (context) == widget) { goto out; } window = gtk_widget_get_toplevel (widget); g_assert (NAUTILUS_IS_WINDOW (window)); if (!drag_info->have_data) { target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) { goto out; } gtk_drag_get_data (widget, context, target, time); } target_uri = NULL; if (drag_info->target_file != NULL) { target_uri = nautilus_file_get_uri (drag_info->target_file); } else { if (drag_info->target_slot != NULL) { target_slot = drag_info->target_slot; } else { target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window)); } if (target_slot != NULL) { location = nautilus_window_slot_get_location (target_slot); target_uri = g_file_get_uri (location); } } if (target_uri != NULL) { NautilusFile *file; gboolean can; file = nautilus_file_get_existing_by_uri (target_uri); can = nautilus_file_can_write (file); g_object_unref (file); if (!can) { action = 0; goto out; } } if (drag_info->have_data && drag_info->have_valid_data) { if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { nautilus_drag_default_drop_action_for_icons (context, target_uri, drag_info->data.selection_list, 0, &action); } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) { action = nautilus_drag_default_drop_action_for_uri_list (context, target_uri); } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) { action = nautilus_drag_default_drop_action_for_netscape_url (context); } else if (drag_info->info == NAUTILUS_ICON_DND_TEXT) { valid_text_drag = TRUE; } else if (drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE || drag_info->info == NAUTILUS_ICON_DND_RAW) { valid_xds_drag = TRUE; } } g_free (target_uri); out: if (action != 0 || valid_text_drag || valid_xds_drag) { gtk_drag_highlight (widget); slot_proxy_check_switch_location_timer (drag_info, widget); } else { gtk_drag_unhighlight (widget); slot_proxy_remove_switch_location_timer (drag_info); } gdk_drag_status (context, action, time); return TRUE; }
static gboolean gimp_container_tree_view_drop_status (GimpContainerTreeView *tree_view, GdkDragContext *context, gint x, gint y, guint time, GtkTreePath **return_path, GdkAtom *return_atom, GimpDndType *return_src_type, GimpViewable **return_src, GimpViewable **return_dest, GtkTreeViewDropPosition *return_pos) { GimpViewable *src_viewable = NULL; GimpViewable *dest_viewable = NULL; GtkTreePath *drop_path = NULL; GtkTargetList *target_list; GdkAtom target_atom; GimpDndType src_type; GtkTreeViewDropPosition drop_pos = GTK_TREE_VIEW_DROP_BEFORE; GdkDragAction drag_action = 0; if (! gimp_container_view_get_container (GIMP_CONTAINER_VIEW (tree_view)) || ! gimp_container_view_get_reorderable (GIMP_CONTAINER_VIEW (tree_view))) goto drop_impossible; target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (tree_view->view)); target_atom = gtk_drag_dest_find_target (GTK_WIDGET (tree_view->view), context, target_list); if (! gtk_target_list_find (target_list, target_atom, &src_type)) goto drop_impossible; switch (src_type) { case GIMP_DND_TYPE_URI_LIST: case GIMP_DND_TYPE_TEXT_PLAIN: case GIMP_DND_TYPE_NETSCAPE_URL: case GIMP_DND_TYPE_COLOR: case GIMP_DND_TYPE_SVG: case GIMP_DND_TYPE_SVG_XML: case GIMP_DND_TYPE_COMPONENT: case GIMP_DND_TYPE_PIXBUF: break; default: { GtkWidget *src_widget = gtk_drag_get_source_widget (context); if (! src_widget) goto drop_impossible; src_viewable = gimp_dnd_get_drag_data (src_widget); if (! GIMP_IS_VIEWABLE (src_viewable)) goto drop_impossible; } break; } if (gtk_tree_view_get_path_at_pos (tree_view->view, x, y, &drop_path, NULL, NULL, NULL)) { GimpViewRenderer *renderer; GtkTreeIter iter; GdkRectangle cell_area; gtk_tree_model_get_iter (tree_view->model, &iter, drop_path); gtk_tree_model_get (tree_view->model, &iter, GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer, -1); dest_viewable = renderer->viewable; g_object_unref (renderer); gtk_tree_view_get_cell_area (tree_view->view, drop_path, NULL, &cell_area); if (gimp_viewable_get_children (dest_viewable)) { if (gtk_tree_view_row_expanded (tree_view->view, drop_path)) { if (y >= (cell_area.y + cell_area.height / 2)) drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; else drop_pos = GTK_TREE_VIEW_DROP_BEFORE; } else { if (y >= (cell_area.y + 2 * (cell_area.height / 3))) drop_pos = GTK_TREE_VIEW_DROP_AFTER; else if (y <= (cell_area.y + cell_area.height / 3)) drop_pos = GTK_TREE_VIEW_DROP_BEFORE; else drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; } } else { if (y >= (cell_area.y + cell_area.height / 2)) drop_pos = GTK_TREE_VIEW_DROP_AFTER; else drop_pos = GTK_TREE_VIEW_DROP_BEFORE; } } else { GtkTreeIter iter; gint n_children; n_children = gtk_tree_model_iter_n_children (tree_view->model, NULL); if (n_children > 0 && gtk_tree_model_iter_nth_child (tree_view->model, &iter, NULL, n_children - 1)) { GimpViewRenderer *renderer; gtk_tree_model_get (tree_view->model, &iter, GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer, -1); drop_path = gtk_tree_model_get_path (tree_view->model, &iter); dest_viewable = renderer->viewable; drop_pos = GTK_TREE_VIEW_DROP_AFTER; g_object_unref (renderer); } } if (dest_viewable || tree_view->priv->dnd_drop_to_empty) { if (GIMP_CONTAINER_TREE_VIEW_GET_CLASS (tree_view)->drop_possible (tree_view, src_type, src_viewable, dest_viewable, drop_path, drop_pos, &drop_pos, &drag_action)) { gdk_drag_status (context, drag_action, time); if (return_path) *return_path = drop_path; else gtk_tree_path_free (drop_path); if (return_atom) *return_atom = target_atom; if (return_src) *return_src = src_viewable; if (return_dest) *return_dest = dest_viewable; if (return_pos) *return_pos = drop_pos; return TRUE; } gtk_tree_path_free (drop_path); } drop_impossible: gdk_drag_status (context, 0, time); return FALSE; }
G_MODULE_EXPORT void queue_drag_cb( GtkTreeView *dstwidget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, signal_user_data_t *ud) { GtkTreePath *path = NULL; //GtkTreeModel *model; GtkTreeViewDropPosition pos; GtkTreeIter dstiter, srciter; gint *indices, row; GValue *js; GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget); g_debug("queue_drag_cb ()"); // This doesn't work here for some reason... // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos); gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos); // This little hack is needed because attempting to drop after // the last item gives us no path or pos. if (path == NULL) { gint n_children; n_children = gtk_tree_model_iter_n_children(dstmodel, NULL); if (n_children) { pos = GTK_TREE_VIEW_DROP_AFTER; path = gtk_tree_path_new_from_indices(n_children-1, -1); } else { pos = GTK_TREE_VIEW_DROP_BEFORE; path = gtk_tree_path_new_from_indices(0, -1); } } if (path) { if (gtk_tree_path_get_depth(path) > 1) gtk_tree_path_up(path); if (gtk_tree_model_get_iter (dstmodel, &dstiter, path)) { GtkTreeIter iter; GtkTreeView *srcwidget; GtkTreeModel *srcmodel; GtkTreeSelection *select; GtkTreePath *srcpath = NULL; GtkTreePath *dstpath = NULL; srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc)); //srcmodel = gtk_tree_view_get_model(srcwidget); select = gtk_tree_view_get_selection (srcwidget); gtk_tree_selection_get_selected (select, &srcmodel, &srciter); srcpath = gtk_tree_model_get_path (srcmodel, &srciter); indices = gtk_tree_path_get_indices(srcpath); row = indices[0]; gtk_tree_path_free(srcpath); js = ghb_array_get_nth(ud->queue, row); switch (pos) { case GTK_TREE_VIEW_DROP_BEFORE: case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel), &iter, NULL, &dstiter); break; case GTK_TREE_VIEW_DROP_AFTER: case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel), &iter, NULL, &dstiter); break; default: break; } // Reset job to pending ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING); add_to_queue_list(ud, js, &iter); dstpath = gtk_tree_model_get_path (dstmodel, &iter); indices = gtk_tree_path_get_indices(dstpath); row = indices[0]; gtk_tree_path_free(dstpath); ghb_array_insert(ud->queue, row, js); srcpath = gtk_tree_model_get_path (srcmodel, &srciter); indices = gtk_tree_path_get_indices(srcpath); row = indices[0]; gtk_tree_path_free(srcpath); ghb_array_remove(ud->queue, row); gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter); ghb_save_queue(ud->queue); } gtk_tree_path_free(path); } }