void EditorClient::respondToChangedSelection() { WebKitWebViewPrivate* priv = m_webView->priv; Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame(); if (!targetFrame) return; if (targetFrame->editor()->ignoreCompositionSelectionChange()) return; GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY); if (targetFrame->selection()->isRange()) { GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView); gint targetCount; GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount); gtk_clipboard_set_with_owner(clipboard, targets, targetCount, clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView)); gtk_target_table_free(targets, targetCount); } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView)) gtk_clipboard_clear(clipboard); if (!targetFrame->editor()->hasComposition()) return; unsigned start; unsigned end; if (!targetFrame->editor()->getCompositionSelection(start, end)) { // gtk_im_context_reset() clears the composition for us. gtk_im_context_reset(priv->imContext); targetFrame->editor()->confirmCompositionWithoutDisturbingSelection(); } }
static void _g_paste_clipboard_select_uris (GPasteClipboard *self, GPasteUrisItem *item) { g_return_if_fail (G_PASTE_IS_CLIPBOARD (self)); g_return_if_fail (G_PASTE_IS_URIS_ITEM (item)); GtkClipboard *real = self->priv->real; GtkTargetList *target_list = gtk_target_list_new (NULL, 0); _g_paste_clipboard_set_text (self, g_paste_item_get_value (G_PASTE_ITEM (item))); gtk_target_list_add_text_targets (target_list, 0); gtk_target_list_add_uri_targets (target_list, 0); gtk_target_list_add (target_list, g_paste_clipboard_copy_files_target, 0, 0); gint n_targets; GtkTargetEntry *targets = gtk_target_table_new_from_list (target_list, &n_targets); gtk_clipboard_set_with_owner (real, targets, n_targets, g_paste_clipboard_get_clipboard_data, g_paste_clipboard_clear_clipboard_data, g_object_ref (item)); gtk_clipboard_store (real); gtk_target_table_free (targets, n_targets); gtk_target_list_unref (target_list); }
static void take_xconsole_ownership(GtkWidget *widget, gpointer data) { char *name, hostname[255]; GdkAtom atom; GtkClipboard *clipboard; const GtkTargetEntry targets[] = { {"UTF8_STRING", 0, 0}, {"COMPOUND_TEXT", 0, 0}, {"TEXT", 0, 0}, {"STRING", 0, 0}, }; memset(hostname, '\0', sizeof(hostname)); gethostname(hostname, sizeof(hostname) - 1); name = g_strdup_printf("MIT_CONSOLE_%s", hostname); atom = gdk_atom_intern(name, FALSE); clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), atom); g_free(name); gtk_clipboard_set_with_owner(clipboard, targets, G_N_ELEMENTS(targets), clipboard_get, (GtkClipboardClearFunc)gtk_main_quit, G_OBJECT(widget)); }
static void take_xconsole_ownership(GtkWidget *widget, gpointer data) { char *name, hostname[255]; GdkAtom atom; GtkClipboard *clipboard; GtkTargetList *target_list; GtkTargetEntry *targets; int n_targets; target_list = gtk_target_list_new(NULL, 0); gtk_target_list_add_text_targets(target_list, 0); targets = gtk_target_table_new_from_list (target_list, &n_targets); gtk_target_list_unref(target_list); memset(hostname, '\0', sizeof(hostname)); gethostname(hostname, sizeof(hostname) - 1); name = g_strdup_printf("MIT_CONSOLE_%s", hostname); atom = gdk_atom_intern(name, FALSE); clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), atom); g_free(name); gtk_clipboard_set_with_owner(clipboard, targets, n_targets, clipboard_get, (GtkClipboardClearFunc)gtk_main_quit, G_OBJECT(widget)); }
static gboolean clipboard_grab(SpiceMainChannel *main, guint selection, guint32* types, guint32 ntypes, gpointer user_data) { g_return_val_if_fail(SPICE_IS_GTK_SESSION(user_data), FALSE); SpiceGtkSession *self = user_data; SpiceGtkSessionPrivate *s = self->priv; GtkTargetEntry targets[SPICE_N_ELEMENTS(atom2agent)]; gboolean target_selected[SPICE_N_ELEMENTS(atom2agent)] = { FALSE, }; gboolean found; GtkClipboard* cb; int m, n, i; cb = get_clipboard_from_selection(s, selection); g_return_val_if_fail(cb != NULL, FALSE); i = 0; for (n = 0; n < ntypes; ++n) { found = FALSE; for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) { if (atom2agent[m].vdagent == types[n] && !target_selected[m]) { found = TRUE; g_return_val_if_fail(i < SPICE_N_ELEMENTS(atom2agent), FALSE); targets[i].target = (gchar*)atom2agent[m].xatom; targets[i].flags = 0; targets[i].info = m; target_selected[m] = TRUE; i += 1; } } if (!found) { g_warning("clipboard: couldn't find a matching type for: %d", types[n]); } } g_free(s->clip_targets[selection]); s->nclip_targets[selection] = i; s->clip_targets[selection] = g_memdup(targets, sizeof(GtkTargetEntry) * i); /* Receiving a grab implies we've released our own grab */ s->clip_grabbed[selection] = FALSE; if (read_only(self) || !s->auto_clipboard_enable || s->nclip_targets[selection] == 0) goto skip_grab_clipboard; if (!gtk_clipboard_set_with_owner(cb, targets, i, clipboard_get, clipboard_clear, G_OBJECT(self))) { g_warning("clipboard grab failed"); return FALSE; } s->clipboard_by_guest[selection] = TRUE; s->clip_hasdata[selection] = FALSE; skip_grab_clipboard: return TRUE; }
//! //! @brief To be written //! G_MODULE_EXPORT gboolean gw_kanjipadwindow_candidatearea_button_press_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { //Declarations GwKanjipadWindow *window; GwKanjipadWindowPrivate *priv; GwKanjipadWindowClass *klass; int j; gint char_height; GtkClipboard *clipboard; char *string_utf; //Initializations window = GW_KANJIPADWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_KANJIPADWINDOW)); if (window == NULL) return FALSE; priv = window->priv; klass = GW_KANJIPADWINDOW_CLASS (G_OBJECT_GET_CLASS (window)); clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); static const GtkTargetEntry targets[] = { { "STRING", 0, 0 }, { "TEXT", 0, 0 }, { "COMPOUND_TEXT", 0, 0 }, { "UTF8_STRING", 0, 0 } }; _kanjipadwindow_erase_candidate_selection (window); _kanjipadwindow_get_candidate_character_size (window, NULL, &char_height); j = event->y / (char_height + 6); if (j < priv->total_candidates) { gw_kanjipadwindow_draw_candidates (window); strncpy(priv->kselected, priv->kanji_candidates[j], 2); _kanjipadwindow_draw_candidate_character (window, j, 1); if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets), _kanjipadwindow_primary_candidates_get, _kanjipadwindow_primary_candidates_clear, G_OBJECT (widget))) _kanjipadwindow_primary_candidates_clear (clipboard, widget); } else { priv->kselected[0] = 0; priv->kselected[1] = 0; if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (widget)) gtk_clipboard_clear (clipboard); } gtk_widget_queue_draw (widget); string_utf = _kanjipadwindow_utf8_for_char (priv->kselected); g_signal_emit (G_OBJECT (window), klass->signalid[GW_KANJIPADWINDOW_CLASS_SIGNALID_KANJI_SELECTED], 0, string_utf); g_free (string_utf); //Cleanup so the user can draw the next character gw_kanjipadwindow_clear_drawingarea (window); return TRUE; }
static void data_sheet_update_clipboard (PsppireSheet *sheet) { GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (sheet), GDK_SELECTION_CLIPBOARD); if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets), clipboard_get_cb, clipboard_clear_cb, G_OBJECT (sheet))) clipboard_clear_cb (clipboard, sheet); }
void remmina_rdp_cliprdr_set_clipboard_data(RemminaProtocolWidget* gp, RemminaPluginRdpUiObject* ui) { TRACE_CALL(__func__); GtkClipboard* gtkClipboard; GtkTargetEntry* targets; gint n_targets; rfContext* rfi = GET_PLUGIN_DATA(gp); targets = gtk_target_table_new_from_list(ui->clipboard.targetlist, &n_targets); gtkClipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD); if (gtkClipboard && targets) { gtk_clipboard_set_with_owner(gtkClipboard, targets, n_targets, (GtkClipboardGetFunc)remmina_rdp_cliprdr_request_data, (GtkClipboardClearFunc)remmina_rdp_cliprdr_empty_clipboard, G_OBJECT(gp)); gtk_target_table_free(targets, n_targets); } }
static void xfdesktop_clipboard_manager_transfer_files (XfdesktopClipboardManager *manager, gboolean copy, GList *files) { XfdesktopFileIcon *file; GList *lp; /* release any pending files */ for (lp = manager->files; lp != NULL; lp = lp->next) { g_object_weak_unref(G_OBJECT (lp->data), (GWeakNotify)xfdesktop_clipboard_manager_file_destroyed, manager); g_object_unref (G_OBJECT (lp->data)); } g_list_free (manager->files); /* remember the transfer operation */ manager->files_cutted = !copy; /* setup the new file list */ for (lp = files, manager->files = NULL; lp != NULL; lp = lp->next) { file = g_object_ref (G_OBJECT (lp->data)); manager->files = g_list_prepend (manager->files, file); g_object_weak_ref(G_OBJECT(file), (GWeakNotify)xfdesktop_clipboard_manager_file_destroyed, manager); } /* acquire the CLIPBOARD ownership */ gtk_clipboard_set_with_owner (manager->clipboard, clipboard_targets, G_N_ELEMENTS (clipboard_targets), xfdesktop_clipboard_manager_get_callback, xfdesktop_clipboard_manager_clear_callback, G_OBJECT (manager)); /* Need to fake a "owner-change" event here if the Xserver doesn't support clipboard notification */ if (!gdk_display_supports_selection_notification (gtk_clipboard_get_display (manager->clipboard))) { xfdesktop_clipboard_manager_owner_changed (manager->clipboard, NULL, manager); } }
static int karea_button_press_event (GtkWidget *w, GdkEventButton *event) { int j; gint char_height; GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); static const GtkTargetEntry targets[] = { { "STRING", 0, 0 }, { "TEXT", 0, 0 }, { "COMPOUND_TEXT", 0, 0 }, { "UTF8_STRING", 0, 0 } }; karea_erase_selection (w); karea_get_char_size (w, NULL, &char_height); j = event->y / (char_height + 6); if (j < num_guesses) { kselected = kanjiguess[j]; karea_draw_character (w, j, 1); if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets), karea_primary_get, karea_primary_clear, G_OBJECT (w))) karea_primary_clear (clipboard, w); } else { kselected.d[0] = 0; kselected.d[1] = 0; if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (w)) gtk_clipboard_clear (clipboard); } update_sensitivity (); gtk_widget_queue_draw (w); return TRUE; }
/** * spice_gtk_session_paste_from_guest: * @self: * * Copy guest clipboard to client-side clipboard. * * Since 0.8 **/ void spice_gtk_session_paste_from_guest(SpiceGtkSession *self) { g_return_if_fail(SPICE_IS_GTK_SESSION(self)); g_return_if_fail(read_only(self) == FALSE); SpiceGtkSessionPrivate *s = self->priv; int selection = VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD; if (s->nclip_targets[selection] == 0) { g_warning("Guest clipboard is not available."); return; } if (!gtk_clipboard_set_with_owner(s->clipboard, s->clip_targets[selection], s->nclip_targets[selection], clipboard_get, clipboard_clear, G_OBJECT(self))) { g_warning("Clipboard grab failed"); return; } s->clipboard_by_guest[selection] = TRUE; s->clip_hasdata[selection] = FALSE; }
static void gretl_clipboard_set (int fmt, int imgtype) { static GtkClipboard *clip; GtkTargetEntry *targs; gint n_targs; #ifdef OS_OSX if (fmt == GRETL_FORMAT_RTF || fmt == GRETL_FORMAT_RTF_TXT) { pasteboard_set(fmt); return; } #endif if (clip == NULL) { clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); } if (imgtype) { targs = image_targets; n_targs = n_image; } else if (fmt == GRETL_FORMAT_RTF || fmt == GRETL_FORMAT_RTF_TXT) { targs = rtf_targets; n_targs = n_rtf; } else { targs = text_targets; n_targs = n_text; } #if CLIPDEBUG fprintf(stderr, "gretl_clipboard_set: fmt = %d, imgtype = %d\n", fmt, imgtype); #endif if (!gtk_clipboard_set_with_owner(clip, targs, n_targs, gretl_clipboard_get, gretl_clipboard_clear, G_OBJECT(mdata->main))) { fprintf(stderr, "Failed to initialize clipboard\n"); } }
/** * gimp_clipboard_set_buffer: * @gimp: pointer to #Gimp * @buffer: a #GimpBuffer, or %NULL. * * Offers the buffer in %GDK_SELECTION_CLIPBOARD. **/ void gimp_clipboard_set_buffer (Gimp *gimp, GimpBuffer *buffer) { GimpClipboard *gimp_clip; GtkClipboard *clipboard; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (buffer == NULL || GIMP_IS_BUFFER (buffer)); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (! clipboard) return; gimp_clip = gimp_clipboard_get (gimp); gimp_clipboard_clear (gimp_clip); if (buffer) { gimp_clip->buffer = g_object_ref (buffer); gtk_clipboard_set_with_owner (clipboard, gimp_clip->target_entries, gimp_clip->n_target_entries, (GtkClipboardGetFunc) gimp_clipboard_send_buffer, (GtkClipboardClearFunc) NULL, G_OBJECT (gimp)); /* mark the first entry (image/png) as suitable for storing */ gtk_clipboard_set_can_store (clipboard, gimp_clip->target_entries, 1); } else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp)) { gtk_clipboard_clear (clipboard); } }
/** * gimp_clipboard_set_svg: * @gimp: pointer to #Gimp * @svg: a string containing the SVG data, or %NULL * * Offers SVG data in %GDK_SELECTION_CLIPBOARD. **/ void gimp_clipboard_set_svg (Gimp *gimp, const gchar *svg) { GimpClipboard *gimp_clip; GtkClipboard *clipboard; g_return_if_fail (GIMP_IS_GIMP (gimp)); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (! clipboard) return; gimp_clip = gimp_clipboard_get (gimp); gimp_clipboard_clear (gimp_clip); if (svg) { gimp_clip->svg = g_strdup (svg); gtk_clipboard_set_with_owner (clipboard, gimp_clip->svg_target_entries, gimp_clip->n_svg_target_entries, (GtkClipboardGetFunc) gimp_clipboard_send_svg, (GtkClipboardClearFunc) NULL, G_OBJECT (gimp)); /* mark the first entry (image/svg) as suitable for storing */ gtk_clipboard_set_can_store (clipboard, gimp_clip->svg_target_entries, 1); } else if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (gimp)) { gtk_clipboard_clear (clipboard); } }