/* methods to receive URLs which were dropped anywhere in the main window */ static void liferea_shell_URL_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time_received) { gchar *tmp1, *tmp2, *freeme; GtkWidget *mainwindow; GtkAllocation alloc; GtkTreeView *treeview; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; nodePtr node; gint tx, ty; g_return_if_fail (gtk_selection_data_get_data (data) != NULL); mainwindow = GTK_WIDGET (shell->priv->window); treeview = GTK_TREE_VIEW (shell->priv->feedlistView); model = gtk_tree_view_get_model (treeview); /* x and y are relative to the main window, make them relative to the treeview */ gtk_widget_translate_coordinates (mainwindow, GTK_WIDGET (treeview), x, y, &tx, &ty); /* Allow link drops only over feed list widget. This is to avoid the frequent accidental text drops in the HTML view. */ gtk_widget_get_allocation(GTK_WIDGET(treeview), &alloc); if((x > alloc.x+alloc.width) || (x < alloc.x) || (y > alloc.y+alloc.height) || (y < alloc.y)) { gtk_drag_finish (context, FALSE, FALSE, time_received); return; } if ((gtk_selection_data_get_length (data) >= 0) && (gtk_selection_data_get_format (data) == 8)) { /* extra handling to accept multiple drops */ freeme = tmp1 = g_strdup (gtk_selection_data_get_data (data)); while ((tmp2 = strsep (&tmp1, "\n\r"))) { if (strlen (tmp2)) { /* if the drop is over a node, select it so that feedlist_add_subscription() * adds it in the correct folder */ if (gtk_tree_view_get_dest_row_at_pos (treeview, tx, ty, &path, NULL)) { if (gtk_tree_model_get_iter (model, &iter, path)) { gtk_tree_model_get (model, &iter, FS_PTR, &node, -1); /* if node is NULL, feed_list_view_select() will unselect the tv */ feed_list_view_select (node); } gtk_tree_path_free (path); } feedlist_add_subscription (g_strdup (tmp2), NULL, NULL, FEED_REQ_PRIORITY_HIGH); } } g_free (freeme); gtk_drag_finish (context, TRUE, FALSE, time_received); } else { gtk_drag_finish (context, FALSE, FALSE, time_received); } }
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); }
static void bar_pane_exif_dnd_receive(GtkWidget *pane, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { PaneExifData *ped; GList *work, *list; gint pos; GtkWidget *new_entry = NULL; ped = g_object_get_data(G_OBJECT(pane), "pane_data"); if (!ped) return; switch (info) { case TARGET_APP_EXIF_ENTRY: new_entry = *(gpointer *)gtk_selection_data_get_data(selection_data); if (gtk_widget_get_parent(new_entry) && gtk_widget_get_parent(new_entry) != ped->vbox) bar_pane_exif_reparent_entry(new_entry, pane); break; default: /* FIXME: this needs a check for valid exif keys */ new_entry = bar_pane_exif_add_entry(ped, (gchar *)gtk_selection_data_get_data(selection_data), NULL, TRUE, FALSE); break; } list = gtk_container_get_children(GTK_CONTAINER(ped->vbox)); work = list; pos = 0; while (work) { gint nx, ny; GtkWidget *entry = work->data; GtkAllocation allocation; work = work->next; if (entry == new_entry) continue; gtk_widget_get_allocation(entry, &allocation); if (gtk_widget_is_drawable(entry) && gtk_widget_translate_coordinates(pane, entry, x, y, &nx, &ny) && ny < allocation.height / 2) break; pos++; } g_list_free(list); gtk_box_reorder_child(GTK_BOX(ped->vbox), new_entry, pos); }
void PluginManageDlg::drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, guint x, guint y, GtkSelectionData *sd, guint info, guint t, PluginManageDlg *oPluginManageDlg) { if (gtk_selection_data_get_target(sd) == gdk_atom_intern("STARDICT_PLUGINMANAGE", FALSE) && gtk_selection_data_get_data(sd)) { GtkTreePath *path = NULL; GtkTreeViewDropPosition position; GtkTreeIter drag_iter; memcpy(&drag_iter, gtk_selection_data_get_data(sd), sizeof(drag_iter)); if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { GtkTreeIter iter; GtkTreeModel *model = GTK_TREE_MODEL(oPluginManageDlg->plugin_tree_model); gtk_tree_model_get_iter(model, &iter, path); if (gtk_tree_model_iter_has_child(model, &iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } if (gtk_tree_model_iter_has_child(model, &drag_iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } GtkTreeIter parent_iter; if (!gtk_tree_model_iter_parent(model, &parent_iter, &iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } GtkTreeIter drag_parent_iter; if (!gtk_tree_model_iter_parent(model, &drag_parent_iter, &drag_iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } char *iter_str, *drag_iter_str; iter_str = gtk_tree_model_get_string_from_iter(model, &parent_iter); drag_iter_str = gtk_tree_model_get_string_from_iter(model, &drag_parent_iter); if (strcmp(iter_str, drag_iter_str) != 0) { g_free(iter_str); g_free(drag_iter_str); gtk_drag_finish (ctx, FALSE, FALSE, t); return; } g_free(iter_str); g_free(drag_iter_str); switch (position) { case GTK_TREE_VIEW_DROP_AFTER: case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: gtk_tree_store_move_after(GTK_TREE_STORE(model), &drag_iter, &iter); break; case GTK_TREE_VIEW_DROP_BEFORE: case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: gtk_tree_store_move_before(GTK_TREE_STORE(model), &drag_iter, &iter); break; default: { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } } oPluginManageDlg->write_order_list(); oPluginManageDlg->order_changed_ = true; gtk_drag_finish (ctx, TRUE, FALSE, t); } } }
static void fm_ditem_page_url_drag_data_received (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, GtkEntry *entry) { char **uris; gboolean exactly_one; char *path; uris = g_strsplit (gtk_selection_data_get_data (selection_data), "\r\n", 0); exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0'); if (!exactly_one) { g_strfreev (uris); return; } path = g_filename_from_uri (uris[0], NULL, NULL); if (path != NULL) { gtk_entry_set_text (entry, path); g_free (path); } else { gtk_entry_set_text (entry, uris[0]); } g_strfreev (uris); }
GList* caja_clipboard_get_uri_list_from_selection_data (GtkSelectionData *selection_data, gboolean *cut, GdkAtom copied_files_atom) { GList *items; char **lines; if (gtk_selection_data_get_data_type (selection_data) != copied_files_atom || gtk_selection_data_get_length (selection_data) <= 0) { items = NULL; } else { guchar *data; /* Not sure why it's legal to assume there's an extra byte * past the end of the selection data that it's safe to write * to. But gtk_editable_selection_received does this, so I * think it is OK. */ data = (guchar *) gtk_selection_data_get_data (selection_data); data[gtk_selection_data_get_length (selection_data)] = '\0'; lines = g_strsplit (data, "\n", 0); items = convert_lines_to_str_list (lines, cut); g_strfreev (lines); } return items; }
/* \brief Get the contents of the system clipboard. * \par Function Description * If the system clipboard contains schematic data, retrieve it. * * \param [in,out] w_current The current GSCHEM_TOPLEVEL. * * \returns Any OBJECTs retrieved from the system clipboard, or NULL * if none were available. */ GList * x_clipboard_get (GSCHEM_TOPLEVEL *w_current) { GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); TOPLEVEL *toplevel = w_current->toplevel; GdkAtom type = gdk_atom_intern (MIME_TYPE_SCHEMATIC, FALSE); GtkSelectionData *selection_data; GList *object_list = NULL; const guchar *buf; /* Try to get the contents of the clipboard */ selection_data = gtk_clipboard_wait_for_contents (cb, type); if (selection_data == NULL) return FALSE; /* Convert the data buffer to OBJECTs */ #if GTK_CHECK_VERSION(2,14,0) buf = gtk_selection_data_get_data (selection_data); #else buf = selection_data->data; #endif object_list = o_read_buffer (toplevel, object_list, (gchar *) buf, -1, "Clipboard"); gtk_selection_data_free (selection_data); return object_list; }
static void __gel_ui_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { gboolean success = FALSE; if ((selection_data == NULL) && (gtk_selection_data_get_length(selection_data) <= 0)) success = FALSE; else { switch (target_type) { case TARGET_STRING: success = TRUE; break; default: g_warning("Unknow type"); success = FALSE; break; } void (*callback) (GtkWidget *w, GType type, const guchar *data, gpointer user_data) = g_object_get_data((GObject *) widget, "gel-ui-dnd-callback"); gpointer user_data = (gpointer) g_object_get_data((GObject *) widget, "gel-ui-dnd-user-data"); if (callback) callback(widget, G_TYPE_STRING, gtk_selection_data_get_data(selection_data), user_data); } gtk_drag_finish (context, success, FALSE, time); }
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)); }
static gboolean tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, GtkSelectionData *selection_data, FavoriteSelector *tsel) { ToolsFavorites *bfav; ToolsFavoritesAttributes fav; GError *error = NULL; gint pos; memset (&fav, 0, sizeof (ToolsFavoritesAttributes)); fav.id = -1; fav.type = GDA_TOOLS_FAVORITES_TABLES; fav.name = NULL; fav.descr = NULL; fav.contents = (gchar*) gtk_selection_data_get_data (selection_data); pos = atoi (path); /*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/ bfav = browser_connection_get_favorites (tsel->priv->bcnc); if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, pos, &error)) { browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); return FALSE; } return TRUE; }
static gboolean individual_drag_received (EmpathyPersonaView *self, GdkDragContext *context, GtkSelectionData *selection) { EmpathyIndividualManager *manager = NULL; FolksIndividual *individual; const gchar *individual_id; gboolean success = FALSE; individual_id = (const gchar *) gtk_selection_data_get_data (selection); manager = empathy_individual_manager_dup_singleton (); individual = empathy_individual_manager_lookup_member (manager, individual_id); if (individual == NULL) { DEBUG ("Failed to find drag event individual with ID '%s'", individual_id); g_object_unref (manager); return FALSE; } /* Emit a signal notifying of the drag. */ g_signal_emit (self, signals[DRAG_INDIVIDUAL_RECEIVED], 0, gdk_drag_context_get_selected_action (context), individual, &success); g_object_unref (manager); return success; }
static void stations_view_drag_data_received_cb (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, RBIRadioSource *source) { GList *uri_list, *i; rb_debug ("parsing uri list"); uri_list = rb_uri_list_parse ((char *) gtk_selection_data_get_data (selection_data)); if (uri_list == NULL) return; for (i = uri_list; i != NULL; i = i->next) { char *uri = NULL; uri = i->data; if (uri != NULL) { rb_iradio_source_add_station (source, uri, NULL, NULL); } if (info == 1) { /* for _NETSCAPE_URL drags, this item is the link text */ i = i->next; } } rb_list_deep_free (uri_list); return; }
static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data) { CopyAndPasteFixture* fixture = (CopyAndPasteFixture*)data; WebKitLoadStatus status = webkit_web_view_get_load_status(webView); if (status != WEBKIT_LOAD_FINISHED) return; GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_clear(clipboard); webkit_web_view_copy_clipboard(webView); gchar* text = gtk_clipboard_wait_for_text(clipboard); g_assert(text || !fixture->info->expectedContent); g_assert(!text || !strcmp(text, fixture->info->expectedContent)); g_free(text); // Verify that the markup starts with the proper content-type meta tag prefix. GtkSelectionData* selectionData = gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern("text/html", FALSE)); if (selectionData) { static const char* markupPrefix = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"; char* markup = g_strndup((const char*) gtk_selection_data_get_data(selectionData), gtk_selection_data_get_length(selectionData)); g_assert(strlen(markupPrefix) <= strlen(markup)); g_assert(!strncmp(markupPrefix, markup, strlen(markupPrefix))); g_free(markup); } g_assert(!gtk_clipboard_wait_is_uris_available(clipboard)); g_assert(!gtk_clipboard_wait_is_image_available(clipboard)); g_main_loop_quit(fixture->loop); }
void Tag_Area_Picture_Drag_Data (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, gpointer data) { GtkTreeSelection *selection; gchar **uri_list, **uri; gtk_drag_finish(dc, TRUE, FALSE, t); if (info != TARGET_URI_LIST || !selection_data || !PictureEntryView) return; selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView)); gtk_tree_selection_unselect_all(selection); uri = uri_list = g_strsplit((gchar *)gtk_selection_data_get_data(selection_data), "\r\n", 0); while (*uri && strlen(*uri)) { GFile *file = g_file_new_for_uri (*uri); et_picture_load_file (file, NULL); g_object_unref (file); uri++; } g_strfreev(uri_list); }
static void drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer user_data){ int datalen=gtk_selection_data_get_length(selection_data); const void *data=gtk_selection_data_get_data(selection_data); LinphoneCall *call=g_object_get_data(G_OBJECT(widget),"call"); ms_message("target_type=%i, datalen=%i, data=%p",target_type,datalen,data); if (target_type==TARGET_URILIST && data){ LinphonePlayer *player=linphone_call_get_player(call); char *path=ms_strdup(data); while (datalen&&(path[datalen-1]=='\r'||path[datalen-1]=='\n')) { path[datalen-1]='\0'; datalen--; } if (player){ const char* filepath = (strstr(path,"file://")==path) ? path+strlen("file://") : path; if (linphone_player_open(player,filepath,on_end_of_play,NULL)==0){ linphone_player_start(player); }else{ GtkWidget *warn=gtk_message_dialog_new(GTK_WINDOW(widget),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, _("Cannot play %s."),filepath); g_signal_connect(warn,"response",(GCallback)gtk_widget_destroy,NULL); gtk_widget_show(warn); } } ms_free(path); } gtk_drag_finish (context, TRUE, FALSE, time); }
static void gimp_color_area_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { GimpColorArea *area = GIMP_COLOR_AREA (widget); const guint16 *vals; GimpRGB color; if (gtk_selection_data_get_length (selection_data) != 8 || gtk_selection_data_get_format (selection_data) != 16) { g_warning ("%s: received invalid color data", G_STRFUNC); return; } vals = (const guint16 *) gtk_selection_data_get_data (selection_data); gimp_rgba_set (&color, (gdouble) vals[0] / 0xffff, (gdouble) vals[1] / 0xffff, (gdouble) vals[2] / 0xffff, (gdouble) vals[3] / 0xffff); gimp_color_area_set_color (area, &color); }
static void handle_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time) { gboolean success = FALSE; if (gtk_selection_data_get_length (data) >= 0 && gtk_selection_data_get_format (data) == 8) { ObjectList_t *list = get_shapes(); Object_t *obj; x = get_real_coord(x); y = get_real_coord(y); obj = object_list_find(list, x, y); if (obj && !obj->locked) { command_list_add(edit_object_command_new(obj)); object_set_url(obj, (const gchar *) gtk_selection_data_get_data (data)); object_emit_update_signal(obj); success = TRUE; } } gtk_drag_finish(context, success, FALSE, time); }
void PasteboardHelper::fillDataObjectFromDropData(GtkSelectionData* data, guint info, DataObjectGtk* dataObject) { if (!gtk_selection_data_get_data(data)) return; GdkAtom target = gtk_selection_data_get_target(data); if (target == textPlainAtom) dataObject->setText(selectionDataToUTF8String(data)); else if (target == markupAtom) { String markup(selectionDataToUTF8String(data)); removeMarkupPrefix(markup); dataObject->setMarkup(markup); } else if (target == uriListAtom) { dataObject->setURIList(selectionDataToUTF8String(data)); } else if (target == netscapeURLAtom) { String urlWithLabel(selectionDataToUTF8String(data)); Vector<String> pieces; urlWithLabel.split("\n", pieces); // Give preference to text/uri-list here, as it can hold more // than one URI but still take the label if there is one. if (!dataObject->hasURIList()) dataObject->setURIList(pieces[0]); if (pieces.size() > 1) dataObject->setText(pieces[1]); } }
static void theme_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, AppearanceData *data) { gchar **uris; if (!(info == TARGET_URI_LIST || info == TARGET_NS_URL)) return; uris = g_uri_list_extract_uris ((gchar *) gtk_selection_data_get_data (selection_data)); if (uris != NULL && uris[0] != NULL) { GFile *f = g_file_new_for_uri (uris[0]); mate_theme_install (f, GTK_WINDOW (appearance_capplet_get_widget (data, "appearance_window"))); g_object_unref (f); } g_strfreev (uris); }
/** * gtk_tree_get_row_drag_data: * @selection_data: a #GtkSelectionData * @tree_model: (nullable) (optional) (transfer none) (out): a #GtkTreeModel * @path: (nullable) (optional) (out): row in @tree_model * * Obtains a @tree_model and @path from selection data of target type * %GTK_TREE_MODEL_ROW. Normally called from a drag_data_received handler. * This function can only be used if @selection_data originates from the same * process that’s calling this function, because a pointer to the tree model * is being passed around. If you aren’t in the same process, then you'll * get memory corruption. In the #GtkTreeDragDest drag_data_received handler, * you can assume that selection data of type %GTK_TREE_MODEL_ROW is * in from the current process. The returned path must be freed with * gtk_tree_path_free(). * * Returns: %TRUE if @selection_data had target type %GTK_TREE_MODEL_ROW and * is otherwise valid **/ gboolean gtk_tree_get_row_drag_data (GtkSelectionData *selection_data, GtkTreeModel **tree_model, GtkTreePath **path) { TreeRowData *trd; g_return_val_if_fail (selection_data != NULL, FALSE); if (tree_model) *tree_model = NULL; if (path) *path = NULL; if (gtk_selection_data_get_target (selection_data) != gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) return FALSE; if (gtk_selection_data_get_length (selection_data) < 0) return FALSE; trd = (void*) gtk_selection_data_get_data (selection_data); if (tree_model) *tree_model = trd->model; if (path) *path = gtk_tree_path_new_from_string (trd->path); return TRUE; }
static void __clipboard_contents_received_callback (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer info) { g_debug ("__clipboard_contents_received_callback: begin"); FileOpsClipboardInfo* _info = (FileOpsClipboardInfo*) info; __clear_clipboard_info (info); _info->num = 0; _info->cut = FALSE; if (selection_data == NULL) return; if (gtk_selection_data_get_data_type (selection_data) != copied_files_atom) return; int _len = gtk_selection_data_get_length (selection_data); if (_len <= 0) return; guchar *data; data = (guchar*) gtk_selection_data_get_data (selection_data); data[_len] = '\0'; char **lines; lines = g_strsplit ((const gchar*)data, "\n", 0); //fill FileOpsClipboardInfo* info if (lines[0] == NULL) return; if (strcmp (lines[0], "cut") == 0) _info->cut = TRUE; else if (strcmp (lines[0], "copy") != 0) return; int i; //get the number of files for (i = 1; lines[i] != NULL; i++) _info->num ++; //FIXME: avoid another loop _info->file_list = g_malloc (_info->num * sizeof (GFile*)); g_debug ("operation: %s; num: %d", lines[0], _info->num); for (i = 1; lines[i] != NULL; i++) { g_debug ("%d file: %s", i, lines[i]); //NOTE: i-1 _info->file_list[i-1] = g_file_new_for_uri (lines[i]); } g_strfreev (lines); g_debug ("__clipboard_contents_received_callback: end"); }
void drag_received(GtkWidget * widget, GdkDragContext * context, gint x, gint y, GtkSelectionData * select_data, guint type_type, guint time, gpointer data) { struct stat info; gchar * file = (char *) gtk_selection_data_get_data(select_data); int len; if (strncmp(file, "file:///", 8) != 0) return; gtk_drag_finish(context, TRUE, FALSE, time); file += 7 * sizeof(char); #ifndef OS_LINUX file += 1 * sizeof(char); #endif len = strlen(file) - 1; while ((file[len] == ' ') || (file[len] == '\n') || (file[len] == '\r')) { file[len] = '\0'; len--; } if (stat(file, &info) < 0) return; if(srecmpend(".dat", file) == 0) { add_buffer(); image_load_map(file); } else if(srecmpend(".bmp", file) == 0 || srecmpend(".png", file) == 0 || srecmpend(".jpg", file) == 0 || srecmpend(".jpeg", file) == 0 || srecmpend(".gif", file) == 0) { GError * err = NULL; add_buffer(); if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(FSD_checkbox))) generate_image_dithered(mdata[current_buffer], 128, 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err); else generate_image(mdata[current_buffer], 128, 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err); if(err != NULL) { information("Error while loading image file!"); printf("%s\n", err->message); g_error_free(err); } set_image(); } else if(srecmpend(".imtm", file) == 0) { add_buffer(); load_raw_map(file, mdata[current_buffer]); set_image(); } else information("File format not supported!"); gtk_drag_finish(context, TRUE, TRUE, time); }
static void tabwin_handle_drag (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer p) { const guchar *seldata = NULL; gchar *dfname; char tmp[MAXLEN]; int pos, skip = 5; if (data != NULL) { seldata = gtk_selection_data_get_data(data); } if (info != GRETL_FILENAME) { return; } /* ignore the wrong sort of data */ if (data == NULL || (dfname = (gchar *) seldata) == NULL || strlen(dfname) <= 5 || strncmp(dfname, "file:", 5)) { return; } if (strncmp(dfname, "file://", 7) == 0) skip = 7; #ifdef G_OS_WIN32 if (strncmp(dfname, "file:///", 8) == 0) skip = 8; #endif /* there may be multiple files: we ignore all but the first */ *tmp = 0; if ((pos = gretl_charpos('\r', dfname)) > 0 || (pos = gretl_charpos('\n', dfname) > 0)) { strncat(tmp, dfname + skip, pos - skip); } else { strcat(tmp, dfname + skip); } /* handle spaces and such */ unescape_url(tmp); #ifdef G_OS_WIN32 filename_to_win32(tryfile, tmp); #else strcpy(tryfile, tmp); #endif if (has_suffix(tryfile, ".inp")) { do_open_script(EDIT_SCRIPT); } }
static void tb_editor_drag_data_rcvd_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint ltime, TBEditorWidget *tbw) { GtkTreeView *tree = GTK_TREE_VIEW(widget); gboolean del = FALSE; if (gtk_selection_data_get_target (data) != GDK_NONE ) { gboolean is_sep; const guchar *text = gtk_selection_data_get_data (data); is_sep = (g_strcmp0(text, "Separator") == 0); /* If the source of the action is equal to the target, we do just re-order and ** so need to delete the separator to get it moved, not just copied. */ if (is_sep && widget == tbw->drag_source) is_sep = FALSE; if (tree != tbw->tree_available || ! is_sep) { GtkTreeIter iter, iter_before, *iter_before_ptr; GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(tree)); if (tbw->last_drag_path != NULL) { gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter_before, tbw->last_drag_path); if (gtk_list_store_iter_is_valid(store, &iter_before)) iter_before_ptr = &iter_before; else iter_before_ptr = NULL; if (tbw->last_drag_pos == GTK_TREE_VIEW_DROP_BEFORE || tbw->last_drag_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) gtk_list_store_insert_before(store, &iter, iter_before_ptr); else gtk_list_store_insert_after(store, &iter, iter_before_ptr); tb_editor_set_item_values(tbw, text, store, &iter); } else { gtk_list_store_append(store, &iter); tb_editor_set_item_values(tbw, text, store, &iter); } tb_editor_scroll_to_iter(tree, &iter); } if (tree != tbw->tree_used || ! is_sep) del = TRUE; } tbw->drag_source = NULL; /* reset the value just to be sure */ tb_editor_free_path(tbw); gtk_drag_finish(context, TRUE, del, ltime); }
static void _lib_keywords_drag_data_received_callback(GtkWidget *w, GdkDragContext *dctx, guint x, guint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_keywords_t *d = (dt_lib_keywords_t*)self->data; GtkTreePath *dpath; GtkTreeViewDropPosition dpos; GtkTreeModel *model = gtk_tree_view_get_model(d->view); if (gtk_selection_data_get_format(data) == 8) { if (gtk_tree_view_get_dest_row_at_pos(d->view, x, y, &dpath, &dpos)) { /* fetch tree iter of source and dest dnd operation */ GtkTreePath *spath = gtk_tree_path_new_from_string((char *)gtk_selection_data_get_data(data)); char dtag[1024]; char stag[1024]; _lib_keywords_string_from_path(dtag, 1024, model, dpath); _lib_keywords_string_from_path(stag, 1024, model, spath); /* reject drop onto ourself */ if (strcmp(dtag,stag) == 0) goto reject_drop; /* updated tags in database */ dt_tag_reorganize(stag,dtag); /* lets move the source iter into dest iter */ GtkTreeIter sit,dit; gtk_tree_model_get_iter(model, &sit, spath); gtk_tree_model_get_iter(model, &dit, dpath); _gtk_tree_move_iter(GTK_TREE_STORE(model), &sit, &dit); /* accept drop */ gtk_drag_finish(dctx, TRUE, FALSE, time); } } /* reject drop */ reject_drop: gtk_drag_finish (dctx, FALSE, FALSE, time); }
static void fm_ditem_page_exec_drag_data_received (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, GtkEntry *entry) { char **uris; gboolean exactly_one; CajaFile *file; GKeyFile *key_file; char *uri, *type, *exec; uris = g_strsplit (gtk_selection_data_get_data (selection_data), "\r\n", 0); exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0'); if (!exactly_one) { g_strfreev (uris); return; } file = caja_file_get_by_uri (uris[0]); g_strfreev (uris); g_return_if_fail (file != NULL); uri = caja_file_get_uri (file); if (caja_file_is_mime_type (file, "application/x-desktop")) { key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL); if (key_file != NULL) { type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL); if (type != NULL && strcmp (type, "Application") == 0) { exec = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL); if (exec != NULL) { g_free (uri); uri = exec; } } g_free (type); g_key_file_free (key_file); } } gtk_entry_set_text (entry, uri?uri:""); gtk_widget_grab_focus (GTK_WIDGET (entry)); g_free (uri); caja_file_unref (file); }
static void dnd_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { GFile *file_uri; gchar **file_list; const guchar *file_data; STlinkGUI *gui = STLINK_GUI (data); GtkListStore *store; GtkTreeIter iter; if (selection_data != NULL && gtk_selection_data_get_length (selection_data) > 0) { switch (target_type) { case TARGET_FILENAME: if (gui->filename) { g_free (gui->filename); } file_data = gtk_selection_data_get_data (selection_data); file_list = g_strsplit ((gchar *)file_data, "\r\n", 0); file_uri = g_file_new_for_uri (file_list[0]); gui->filename = g_file_get_path (file_uri); g_strfreev (file_list); g_object_unref (file_uri); store = GTK_LIST_STORE (gtk_tree_view_get_model (gui->devmem_treeview)); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { gtk_list_store_clear (store); } stlink_gui_set_sensitivity (gui, FALSE); gtk_notebook_set_current_page (gui->notebook, PAGE_FILEMEM); gtk_widget_show (GTK_WIDGET (gui->progress.bar)); gtk_progress_bar_set_text (gui->progress.bar, "Reading file"); g_thread_new ("file", (GThreadFunc) stlink_gui_populate_filemem_view, gui); break; } } gtk_drag_finish (context, TRUE, gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE, time); }
static void on_button_drag_data_received (GtkWidget *widget, GdkDrop *drop, GtkSelectionData *data, gpointer user_data) { GtkWidget **child; child = (void*) gtk_selection_data_get_data (data); g_idle_add (remove_in_idle, *child); }
/* Emitted when the data has been received from the source. It should check * the GtkSelectionData sent by the source, and do something with it. Finally * it needs to finish the operation by calling gtk_drag_finish, which will emit * the "data-delete" signal if told to. */ static void drag_data_received_handler(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { char *filename, *p, *lfn; gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; DBG(("drag_data_received_handler")); /* Deal with what we are given from source */ if(dropdata && (selection_data != NULL) && (gtk_selection_data_get_length (selection_data) >= 0)) { dropdata = 0; if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE) { delete_selection_data = TRUE; } /* FIXME; Check that we got a format we can use */ filename = (char*)gtk_selection_data_get_data(selection_data); DBG(("DnD got string: %s", filename)); dnd_success = TRUE; /* incase we got a list of files, terminate the list after the first file */ p = filename; while (*p) { if ((*p == '\n') || (*p == '\r')) { *p = 0; break; } p++; } lfn = g_filename_from_uri(filename, NULL, NULL); if (!lfn) { log_error(ui_log, "URI conversion failed: %s", filename); } DBG(("DnD using filename: '%s'", lfn)); /* finally call the drop callback set by the individual ui */ if (drop_cb) { drop_cb(lfn); } DBG(("DnD done")); if (lfn) { free(lfn); } } if (dnd_success == FALSE) { DBG(("DnD data transfer failed!")); } gtk_drag_finish (context, dnd_success, delete_selection_data, time); }
static gboolean tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, GtkSelectionData *selection_data, QueryFavoriteSelector *tsel) { TFavorites *bfav; TFavoritesAttributes fav; GError *error = NULL; gint pos; gboolean retval = TRUE; gint id; bfav = t_connection_get_favorites (tsel->priv->tcnc); id = t_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data), &fav, NULL); if (id < 0) { memset (&fav, 0, sizeof (TFavoritesAttributes)); fav.id = -1; fav.type = T_FAVORITES_QUERIES; fav.name = _("Unnamed query"); fav.descr = NULL; fav.contents = (gchar*) gtk_selection_data_get_data (selection_data); } pos = atoi (path); /*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) { ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel), _("Could not add favorite: %s"), error && error->message ? error->message : _("No detail")); if (error) g_error_free (error); retval = FALSE; } if (id >= 0) t_favorites_reset_attributes (&fav); return retval; }