void on_mainapp_selection_received (GtkWidget *widget, GtkSelectionData *selection_data, guint time, gpointer user_data) { GromitData *data = (GromitData *) user_data; if(gtk_selection_data_get_length(selection_data) < 0) { if(data->debug) g_printerr("DEBUG: mainapp got no answer back from client.\n"); } else { if(gtk_selection_data_get_target(selection_data) == GA_TOGGLEDATA ) { intptr_t dev_nr = strtoull((gchar*)gtk_selection_data_get_data(selection_data), NULL, 10); if(data->debug) g_printerr("DEBUG: mainapp got toggle id '%ld' back from client.\n", (long)dev_nr); if(dev_nr < 0) toggle_grab(data, NULL); /* toggle all */ else { /* find dev numbered dev_nr */ GHashTableIter it; gpointer value; GromitDeviceData* devdata = NULL; g_hash_table_iter_init (&it, data->devdatatable); while (g_hash_table_iter_next (&it, NULL, &value)) { devdata = value; if(devdata->index == dev_nr) break; else devdata = NULL; } if(devdata) toggle_grab(data, devdata->device); else g_printerr("ERROR: No device at index %ld.\n", (long)dev_nr); } } } gtk_main_quit (); }
void source_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { if (info == TARGET_ROOTWIN) g_print ("I was dropped on the rootwin\n"); else gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar *) "I'm Data!", 9); }
void PluginManageDlg::drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx, GtkSelectionData *data, guint info, guint time, PluginManageDlg *oPluginManageDlg) { if (gtk_selection_data_get_target(data) == gdk_atom_intern("STARDICT_PLUGINMANAGE", FALSE)) { GtkTreeRowReference *ref; GtkTreePath *source_row; ref = (GtkTreeRowReference *)g_object_get_data(G_OBJECT(ctx), "gtk-tree-view-source-row"); source_row = gtk_tree_row_reference_get_path(ref); if (source_row == NULL) return; GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(oPluginManageDlg->plugin_tree_model), &iter, source_row); gtk_selection_data_set(data, gdk_atom_intern("STARDICT_PLUGINMANAGE", FALSE), 8, (const guchar *)&iter, sizeof(iter)); gtk_tree_path_free(source_row); } }
static void matewnck_selector_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, MatewnckWindow *window) { gulong xid; xid = matewnck_window_get_xid (window); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar *)&xid, sizeof (gulong)); }
static void gtkDragDataGet(GtkWidget *widget, GdkDragContext *drag_context, GtkSelectionData *seldata, guint info, guint time, Ihandle* ih) { IFnsCi cbDragData = (IFnsCi)IupGetCallback(ih, "DRAGDATA_CB"); IFns cbDragDataSize = (IFns)IupGetCallback(ih, "DRAGDATASIZE_CB"); if(cbDragData && cbDragDataSize) { void* sourceData; char *type; int size; GdkDragAction action; #if GTK_CHECK_VERSION(2, 22, 0) action = gdk_drag_context_get_selected_action(drag_context); #else action = drag_context->action; #endif #if GTK_CHECK_VERSION(2, 14, 0) type = gdk_atom_name(gtk_selection_data_get_target(seldata)); #else type = seldata->type; #endif if (action != GDK_ACTION_MOVE && action != GDK_ACTION_COPY) return; size = cbDragDataSize(ih, type); if (size <= 0) return; sourceData = malloc(size+1); /* fill data */ cbDragData(ih, type, sourceData, size); /* Zero-terminates the stored data. */ ((guchar*)sourceData)[size] = 0; gtk_selection_data_set(seldata, gdk_atom_intern(type, 0), 8, (guchar*)sourceData, size+1); /* gtk_selection_data_set will copy the data */ free(sourceData); } (void)widget; (void)drag_context; (void)time; (void)info; }
static void drag_data_get_cb (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint32 time, EggToolbarEditor *editor) { const char *target; target = g_object_get_data (G_OBJECT (widget), "egg-item-name"); g_return_if_fail (target != NULL); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (const guchar *) target, strlen (target)); }
static void drag_data_get_cb (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, Drawer *drawer) { char *foo; foo = g_strdup_printf ("DRAWER:%d", panel_find_applet_index (widget)); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar *) foo, strlen (foo)); g_free (foo); }
void wxClipboard::GTKOnSelectionReceived(const GtkSelectionData& sel) { wxCHECK_RET( m_receivedData, wxT("should be inside GetData()") ); const wxDataFormat format(gtk_selection_data_get_target(const_cast<GtkSelectionData*>(&sel))); wxLogTrace(TRACE_CLIPBOARD, wxT("Received selection %s"), format.GetId().c_str()); if ( !m_receivedData->IsSupportedFormat(format, wxDataObject::Set) ) return; m_receivedData->SetData(format, gtk_selection_data_get_length(const_cast<GtkSelectionData*>(&sel)), gtk_selection_data_get_data(const_cast<GtkSelectionData*>(&sel))); m_formatSupported = true; }
static void cheese_thumb_view_on_drag_data_get_cb (GtkIconView *thumb_view, GdkDragContext *drag_context, GtkSelectionData *data, guint info, guint time, gpointer user_data) { GList *list, *l; GtkTreeIter iter; GtkTreeModel *model; char *str; char *uris = NULL; char *tmp_str; list = gtk_icon_view_get_selected_items (thumb_view); model = gtk_icon_view_get_model (thumb_view); for (l = list; l != NULL; l = l->next) { gtk_tree_model_get_iter (model, &iter, l->data); gtk_tree_model_get (model, &iter, 1, &str, -1); gtk_tree_path_free (l->data); /* we always store local paths in the model, but DnD * needs URIs, so we must add file:// to the path. */ /* build the "text/uri-list" string */ if (uris) { tmp_str = g_strconcat (uris, "file://", str, "\r\n", NULL); g_free (uris); } else { tmp_str = g_strconcat ("file://", str, "\r\n", NULL); } uris = tmp_str; g_free (str); } gtk_selection_data_set (data, gtk_selection_data_get_target (data), 8, (guchar *) uris, strlen (uris)); g_free (uris); g_list_free (list); }
void nautilus_get_clipboard_callback (GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer user_data) { char **uris; GList *l; int i; NautilusClipboardInfo *clipboard_info; GdkAtom target; clipboard_info = nautilus_clipboard_monitor_get_clipboard_info (nautilus_clipboard_monitor_get ()); target = gtk_selection_data_get_target (selection_data); if (gtk_targets_include_uri (&target, 1)) { uris = g_malloc ((g_list_length (clipboard_info->files) + 1) * sizeof (char *)); i = 0; for (l = clipboard_info->files; l != NULL; l = l->next) { uris[i] = nautilus_file_get_uri (l->data); i++; } uris[i] = NULL; gtk_selection_data_set_uris (selection_data, uris); g_strfreev (uris); } else if (gtk_targets_include_text (&target, 1)) { char *str; gsize len; str = convert_file_list_to_string (clipboard_info, TRUE, &len); gtk_selection_data_set_text (selection_data, str, len); g_free (str); } else if (target == copied_files_atom) { char *str; gsize len; str = convert_file_list_to_string (clipboard_info, FALSE, &len); gtk_selection_data_set (selection_data, copied_files_atom, 8, (guchar *) str, len); g_free (str); } }
static void gsm_color_button_drag_data_get (GtkWidget * widget, GdkDragContext * context, GtkSelectionData * selection_data, guint info, guint time, GSMColorButton * color_button) { guint16 dropped[4]; dropped[0] = color_button->priv->color.red; dropped[1] = color_button->priv->color.green; dropped[2] = color_button->priv->color.blue; dropped[3] = 65535; // This widget doesn't care about alpha gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 16, (guchar *) dropped, 8); }
static void caja_emblem_sidebar_drag_data_get_cb (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *data, guint info, guint time, CajaEmblemSidebar *emblem_sidebar) { char *keyword; keyword = g_object_get_data (G_OBJECT (widget), "emblem-keyword"); g_return_if_fail (keyword != NULL); gtk_selection_data_set (data, gtk_selection_data_get_target (data), 8, keyword, strlen (keyword)); }
static void mate_color_button_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, MateColorButton *color_button) { guint16 dropped[4]; dropped[0] = color_button->priv->color.red; dropped[1] = color_button->priv->color.green; dropped[2] = color_button->priv->color.blue; dropped[3] = color_button->priv->alpha; gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 16, (guchar *)dropped, 8); }
static void gstyle_color_widget_on_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *data, guint info, guint time) { GstyleColorWidget *self = (GstyleColorWidget *)widget; GdkAtom target = gtk_selection_data_get_target (data); GstyleColor *color; guint16 data_rgba[4]; GdkRGBA rgba; g_assert (GSTYLE_IS_COLOR_WIDGET (self)); g_assert (GDK_IS_DRAG_CONTEXT (context)); if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color)) color = self->filtered_color; else color = self->color; if (target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET")) gtk_selection_data_set (data, target, 8, (void*)&color, sizeof (gpointer)); else if (target == gdk_atom_intern_static_string ("application/x-color")) { gstyle_color_fill_rgba (color, &rgba); data_rgba[0] = (guint16) (rgba.red * 65535); data_rgba[1] = (guint16) (rgba.green * 65535); data_rgba[2] = (guint16) (rgba.blue * 65535); data_rgba[3] = (guint16) (rgba.alpha * 65535); gtk_selection_data_set (data, target, 16, (void*)&data_rgba, 8); } else if (gtk_targets_include_text (&target, 1)) { g_autofree gchar *name = NULL; name = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_ORIGINAL); if (name == NULL) name = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGB_HEX6); gtk_selection_data_set_text (data, name, -1); } }
static void e_minicard_view_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, EMinicardView *view) { GdkAtom target; if (!E_IS_MINICARD_VIEW (view)) return; target = gtk_selection_data_get_target (selection_data); switch (info) { case DND_TARGET_TYPE_VCARD_LIST: { gchar *value; value = eab_contact_list_to_string (view->drag_list); gtk_selection_data_set ( selection_data, target, 8, (guchar *) value, strlen (value)); g_free (value); break; } case DND_TARGET_TYPE_SOURCE_VCARD_LIST: { EBookClient *book_client = NULL; gchar *value; g_object_get (view->adapter, "client", &book_client, NULL); value = eab_book_and_contact_list_to_string (book_client, view->drag_list); gtk_selection_data_set ( selection_data, target, 8, (guchar *) value, strlen (value)); g_object_unref (book_client); g_free (value); break; } } }
static void gtkDragDataReceived(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *seldata, guint info, guint time, Ihandle *ih) { IFnsCiii cbDrop = (IFnsCiii)IupGetCallback(ih, "DROPDATA_CB"); void* targetData = NULL; char* type; int size, format, res; GdkDragAction action; #if GTK_CHECK_VERSION(2, 22, 0) action = gdk_drag_context_get_selected_action(drag_context); #else action = drag_context->action; #endif #if GTK_CHECK_VERSION(2, 14, 0) type = gdk_atom_name(gtk_selection_data_get_target(seldata)); targetData = (void*)gtk_selection_data_get_data(seldata); size = gtk_selection_data_get_length(seldata); format = gtk_selection_data_get_format(seldata); #else type = gdk_atom_name(seldata->type); targetData = (void*)seldata->data; size = seldata->length; format = seldata->format; #endif if(size <= 0 || format != 8 || (action != GDK_ACTION_MOVE && action != GDK_ACTION_COPY)) { gtk_drag_finish(drag_context, FALSE, FALSE, time); return; } if(cbDrop) res = cbDrop(ih, type, targetData, size, x, y); gtk_drag_finish(drag_context, TRUE, FALSE, time); (void)info; (void)widget; (void)time; }
/** * gtk_tree_set_row_drag_data: * @selection_data: some #GtkSelectionData * @tree_model: a #GtkTreeModel * @path: a row in @tree_model * * Sets selection data of target type %GTK_TREE_MODEL_ROW. Normally used * in a drag_data_get handler. * * Returns: %TRUE if the #GtkSelectionData had the proper target type to allow us to set a tree row **/ gboolean gtk_tree_set_row_drag_data (GtkSelectionData *selection_data, GtkTreeModel *tree_model, GtkTreePath *path) { TreeRowData *trd; gchar *path_str; gint len; gint struct_size; g_return_val_if_fail (selection_data != NULL, FALSE); g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); g_return_val_if_fail (path != NULL, FALSE); if (gtk_selection_data_get_target (selection_data) != gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) return FALSE; path_str = gtk_tree_path_to_string (path); len = strlen (path_str); /* the old allocate-end-of-struct-to-hold-string trick */ struct_size = sizeof (TreeRowData) + len + 1 - (sizeof (TreeRowData) - G_STRUCT_OFFSET (TreeRowData, path)); trd = g_malloc (struct_size); strcpy (trd->path, path_str); g_free (path_str); trd->model = tree_model; gtk_selection_data_set (selection_data, gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"), 8, /* bytes */ (void*)trd, struct_size); g_free (trd); return TRUE; }
bool wxDropTarget::GetData() { if (!m_dragData) return false; if (!m_dataObject) return false; wxDataFormat dragFormat(gtk_selection_data_get_target(m_dragData)); if (!m_dataObject->IsSupportedFormat( dragFormat )) return false; m_dataObject->SetData(dragFormat, (size_t)gtk_selection_data_get_length(m_dragData), (const void*)gtk_selection_data_get_data(m_dragData)); return true; }
static void gtk_color_button_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, GtkColorButton *button) { guint16 dropped[4]; dropped[0] = (guint16) (button->priv->rgba.red * 65535); dropped[1] = (guint16) (button->priv->rgba.green * 65535); dropped[2] = (guint16) (button->priv->rgba.blue * 65535); dropped[3] = (guint16) (button->priv->rgba.alpha * 65535); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 16, (guchar *)dropped, 8); }
static gboolean tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path, GtkSelectionData *selection_ldap, LdapFavoriteSelector *fsel) { GdaTreeNode *node; node = gda_tree_get_node (fsel->priv->tree, path, FALSE); if (node) { const GValue *cvalue; cvalue = gda_tree_node_get_node_attribute (node, "fav_contents"); if (cvalue) { const gchar *str; str = g_value_get_string (cvalue); gtk_selection_data_set (selection_ldap, gtk_selection_data_get_target (selection_ldap), 8, (guchar*) str, strlen (str)); return TRUE; } } return FALSE; }
static void panel_menu_button_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time) { char *drag_data; g_return_if_fail (PANEL_IS_MENU_BUTTON (widget)); drag_data = g_strdup_printf ("MENU:%d", panel_find_applet_index (widget)); gtk_selection_data_set ( selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar *) drag_data, strlen (drag_data)); g_free (drag_data); }
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]); } else if (target == unknownAtom) { GRefPtr<GVariant> variant = g_variant_new_parsed(reinterpret_cast<const char*>(gtk_selection_data_get_data(data))); GOwnPtr<gchar> key; GOwnPtr<gchar> value; GVariantIter iter; g_variant_iter_init(&iter, variant.get()); while (g_variant_iter_next(&iter, "{ss}", &key.outPtr(), &value.outPtr())) { dataObject->setUnknownTypeData(key.get(), value.get()); // FIXME: should GOwnPtr be smarter about this and replace the existing ptr when outPtr() is used? key.clear(); value.clear(); } } }
static void bar_pane_exif_entry_dnd_get(GtkWidget *entry, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { ExifEntry *ee = g_object_get_data(G_OBJECT(entry), "entry_data"); switch (info) { case TARGET_APP_EXIF_ENTRY: gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8, (gpointer) &entry, sizeof(entry)); break; case TARGET_TEXT_PLAIN: default: gtk_selection_data_set_text(selection_data, ee->key, -1); break; } }
static void drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, Browser *br) { DndData *data; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; gchar *part_name; schematic_view_reset_tool (br->schematic_view); data = g_new0 (DndData, 1); data->schematic_view = br->schematic_view; data->br = br; data->library_name = br->library->name; // Get the current selected row selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (br->list)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (br->list)); if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { // No selection, Action canceled return; } gtk_tree_model_get (model, &iter, 0, &part_name, -1); data->part_name = part_name; gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (gpointer) data, sizeof (DndData)); // gtk_selection_data_set copies the information so we can free it now. g_free (data); }
static void memo_shell_content_table_drag_data_get_cb (EMemoShellContent *memo_shell_content, gint row, gint col, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time) { EMemoTable *memo_table; GdkAtom target; struct { ECalModel *model; GSList *list; } foreach_data; /* Sanity check the selection target. */ target = gtk_selection_data_get_target (selection_data); if (!e_targets_include_calendar (&target, 1)) return; memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); foreach_data.model = e_memo_table_get_model (memo_table); foreach_data.list = NULL; e_table_selected_row_foreach ( E_TABLE (memo_table), memo_shell_content_table_foreach_cb, &foreach_data); if (foreach_data.list != NULL) { cal_comp_selection_set_string_list ( selection_data, foreach_data.list); g_slist_foreach (foreach_data.list, (GFunc) g_free, NULL); g_slist_free (foreach_data.list); } }
static void drag_data_get_menu_cb (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, MateMenuTreeEntry *entry) { const char *path; char *uri; char *uri_list; path = matemenu_tree_entry_get_desktop_file_path (entry); uri = g_filename_to_uri (path, NULL, NULL); uri_list = g_strconcat (uri, "\r\n", NULL); g_free (uri); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar *)uri_list, strlen (uri_list)); g_free (uri_list); }
static void pixmap_drag_data_get (GtkWidget *run_dialog, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, PanelRunDialog *dialog) { char *uri; if (dialog->use_program_list && dialog->desktop_path) uri = g_filename_to_uri (dialog->desktop_path, NULL, NULL); else uri = panel_run_dialog_create_desktop_file (dialog); if (uri) { gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (unsigned char *) uri, strlen (uri)); g_free (uri); } }
static void view_window_set_dnd_data(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { ViewWindow *vw = data; FileData *fd; fd = image_get_fd(vw->imd); if (fd) { GList *list; list = g_list_append(NULL, fd); uri_selection_data_set_uris_from_filelist(selection_data, list); g_list_free(list); } else { gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8, NULL, 0); } }
static gboolean fm_list_model_multi_drag_data_get (EggTreeMultiDragSource *drag_source, GList *path_list, GtkSelectionData *selection_data) { FMListModel *model; DragDataGetInfo context; guint target_info; model = FM_LIST_MODEL (drag_source); context.model = model; context.path_list = path_list; if (!drag_target_list) { drag_target_list = fm_list_model_get_drag_target_list (); } if (gtk_target_list_find (drag_target_list, gtk_selection_data_get_target (selection_data), &target_info)) { caja_drag_drag_data_get (NULL, NULL, selection_data, target_info, GDK_CURRENT_TIME, &context, each_path_get_data_binder); return TRUE; } else { return FALSE; } }
static gboolean drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, SeahorseKeyManagerStore *skstore) { gchar *destination; gboolean ret; g_debug ("drag_data_get %d -->", info); g_return_val_if_fail (skstore->priv->drag_objects, FALSE); /* The caller wants plain text */ if (info == DRAG_INFO_TEXT) { g_debug ("returning object text"); export_to_text (skstore, selection_data); /* The caller wants XDS */ } else if (info == DRAG_INFO_XDS) { if (xds_is_dnd_valid_context (context)) { destination = xds_get_atom_value (context); g_return_val_if_fail (destination, FALSE); skstore->priv->drag_destination = g_path_get_dirname (destination); g_free (destination); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), 8, (guchar*)"S", 1); ret = TRUE; } /* Unrecognized format */ } else { g_debug ("Unrecognized format: %d", info); } g_debug ("drag_data_get <--"); return ret; }