void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard) { DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); ASSERT(dataObject); if (gtk_clipboard_wait_is_text_available(clipboard)) { GOwnPtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard)); if (textData) dataObject->setText(String::fromUTF8(textData.get())); } if (gtk_clipboard_wait_is_target_available(clipboard, markupAtom)) { if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, markupAtom)) { String markup(selectionDataToUTF8String(data)); removeMarkupPrefix(markup); dataObject->setMarkup(markup); gtk_selection_data_free(data); } } if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) { if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) { dataObject->setURIList(selectionDataToUTF8String(data)); gtk_selection_data_free(data); } } }
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval) { *_retval = PR_FALSE; PRUint32 length = 0; aFlavorList->Count(&length); if (!length) return NS_OK; GtkSelectionData *selection_data = GetTargets(GetSelectionAtom(aWhichClipboard)); if (!selection_data) return NS_OK; gint n_targets = 0; GdkAtom *targets = NULL; if (!gtk_selection_data_get_targets(selection_data, &targets, &n_targets) || !n_targets) return NS_OK; // Walk through the provided types and try to match it to a // provided type. for (PRUint32 i = 0; i < length && !*_retval; i++) { nsCOMPtr<nsISupports> genericFlavor; aFlavorList->GetElementAt(i, getter_AddRefs(genericFlavor)); nsCOMPtr<nsISupportsCString> flavorWrapper; flavorWrapper = do_QueryInterface(genericFlavor); if (flavorWrapper) { nsXPIDLCString myStr; flavorWrapper->ToString(getter_Copies(myStr)); // We special case text/unicode here. if (!strcmp(myStr, kUnicodeMime) && gtk_selection_data_targets_include_text(selection_data)) { *_retval = PR_TRUE; break; } for (PRInt32 j = 0; j < n_targets; j++) { gchar *atom_name = gdk_atom_name(targets[j]); if (!strcmp(atom_name, (const char *)myStr)) *_retval = PR_TRUE; g_free(atom_name); if (*_retval) break; } } } gtk_selection_data_free(selection_data); g_free(targets); return NS_OK; }
/* \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; }
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); GtkClipboard* clipboard = m_helper->getCurrentTarget(frame); chosePlainText = false; if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, textHtml)) { ASSERT(data->data); String html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8); gtk_selection_data_free(data); if (!html.isEmpty()) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, ""); if (fragment) return fragment.release(); } } if (!allowPlainText) return 0; if (gchar* utf8 = gtk_clipboard_wait_for_text(clipboard)) { String text = String::fromUTF8(utf8); g_free(utf8); chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text); if (fragment) return fragment.release(); } return 0; }
static void drag_info_clear (NautilusDragSlotProxyInfo *drag_info) { slot_proxy_remove_switch_location_timer (drag_info); if (!drag_info->have_data) { goto out; } if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { nautilus_drag_destroy_selection_list (drag_info->data.selection_list); } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) { g_list_free (drag_info->data.uri_list); } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) { g_free (drag_info->data.netscape_url); } else if (drag_info->info == NAUTILUS_ICON_DND_TEXT || drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE || drag_info->info == NAUTILUS_ICON_DND_RAW) { if (drag_info->data.selection_data != NULL) { gtk_selection_data_free (drag_info->data.selection_data); } } out: drag_info->have_data = FALSE; drag_info->have_valid_data = FALSE; drag_info->drop_occured = FALSE; }
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(const char** aFlavorList, PRUint32 aLength, PRInt32 aWhichClipboard, PRBool *_retval) { if (!aFlavorList || !_retval) return NS_ERROR_NULL_POINTER; *_retval = PR_FALSE; GtkSelectionData *selection_data = GetTargets(GetSelectionAtom(aWhichClipboard)); if (!selection_data) return NS_OK; gint n_targets = 0; GdkAtom *targets = NULL; if (!gtk_selection_data_get_targets(selection_data, &targets, &n_targets) || !n_targets) return NS_OK; // Walk through the provided types and try to match it to a // provided type. for (PRUint32 i = 0; i < aLength && !*_retval; i++) { // We special case text/unicode here. if (!strcmp(aFlavorList[i], kUnicodeMime) && gtk_selection_data_targets_include_text(selection_data)) { *_retval = PR_TRUE; break; } for (PRInt32 j = 0; j < n_targets; j++) { gchar *atom_name = gdk_atom_name(targets[j]); if (!atom_name) continue; if (!strcmp(atom_name, aFlavorList[i])) *_retval = PR_TRUE; // X clipboard wants image/jpeg, not image/jpg if (!strcmp(aFlavorList[i], kJPEGImageMime) && !strcmp(atom_name, "image/jpeg")) *_retval = PR_TRUE; g_free(atom_name); if (*_retval) break; } } gtk_selection_data_free(selection_data); g_free(targets); return NS_OK; }
static void free_drag_data (EphyNodeView *view) { view->priv->have_drag_data = FALSE; if (view->priv->drag_data) { gtk_selection_data_free (view->priv->drag_data); view->priv->drag_data = NULL; } }
/** * gimp_clipboard_get_svg: * @gimp: pointer to #Gimp * @svg_length: returns the size of the SVG stream in bytes * * Retrieves SVG data from %GDK_SELECTION_CLIPBOARD or from the global * SVG buffer of @gimp. * * The returned data needs to be freed when it's no longer needed. * * Return value: a reference to a #GimpBuffer or %NULL if there's no * image data **/ gchar * gimp_clipboard_get_svg (Gimp *gimp, gsize *svg_length) { GimpClipboard *gimp_clip; GtkClipboard *clipboard; GdkAtom atom; gchar *svg = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (svg_length != NULL, NULL); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (clipboard && gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) && (atom = gimp_clipboard_wait_for_svg (gimp)) != GDK_NONE) { GtkSelectionData *data; gimp_set_busy (gimp); data = gtk_clipboard_wait_for_contents (clipboard, atom); if (data) { const guchar *stream; stream = gimp_selection_data_get_stream (data, svg_length); if (stream) svg = g_memdup (stream, *svg_length); gtk_selection_data_free (data); } gimp_unset_busy (gimp); } gimp_clip = gimp_clipboard_get (gimp); if (! svg && gimp_clip->svg) { svg = g_strdup (gimp_clip->svg); *svg_length = strlen (svg); } return svg; }
gboolean check_kde_curselection(GtkClipboard* clip) { /* Check application/x-kde-cutselection: * If the content of this format is string "1", that means the * file is cut in KDE (Dolphin). */ gboolean ret = FALSE; GdkAtom atom = gdk_atom_intern_static_string(targets[KDE_CUT_SEL-1].target); GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, atom); if(data) { if(data->length > 0 && data->format == 8 && data->data[0] == '1') ret = TRUE; gtk_selection_data_free(data); } return ret; }
/** * gimp_clipboard_get_buffer: * @gimp: pointer to #Gimp * * Retrieves either image data from %GDK_SELECTION_CLIPBOARD or from * the global cut buffer of @gimp. * * The returned #GimpBuffer needs to be unref'ed when it's no longer * needed. * * Return value: a reference to a #GimpBuffer or %NULL if there's no * image data **/ GimpBuffer * gimp_clipboard_get_buffer (Gimp *gimp) { GimpClipboard *gimp_clip; GtkClipboard *clipboard; GdkAtom atom; GimpBuffer *buffer = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (clipboard && gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) && (atom = gimp_clipboard_wait_for_buffer (gimp)) != GDK_NONE) { GtkSelectionData *data; gimp_set_busy (gimp); data = gtk_clipboard_wait_for_contents (clipboard, atom); if (data) { GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data); gtk_selection_data_free (data); if (pixbuf) { buffer = gimp_buffer_new_from_pixbuf (pixbuf, _("Clipboard")); g_object_unref (pixbuf); } } gimp_unset_busy (gimp); } gimp_clip = gimp_clipboard_get (gimp); if (! buffer && gimp_clip->buffer) buffer = g_object_ref (gimp_clip->buffer); return buffer; }
static GdkAtom * gimp_clipboard_wait_for_targets (Gimp *gimp, gint *n_targets) { GtkClipboard *clipboard; clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); if (clipboard) { GtkSelectionData *data; GdkAtom atom = gdk_atom_intern_static_string ("TARGETS"); data = gtk_clipboard_wait_for_contents (clipboard, atom); if (data) { GdkAtom *targets; gboolean success; success = gtk_selection_data_get_targets (data, &targets, n_targets); gtk_selection_data_free (data); if (success) { if (gimp->be_verbose) { gint i; for (i = 0; i < *n_targets; i++) g_printerr ("clipboard: offered type: %s\n", gdk_atom_name (targets[i])); g_printerr ("\n"); } return targets; } } } return NULL; }
JNIEXPORT void JNICALL Java_org_gnome_gtk_GtkSelectionData_gtk_1selection_1data_1free ( JNIEnv* env, jclass cls, jlong _self ) { GtkSelectionData* self; // convert parameter self self = (GtkSelectionData*) _self; // call function gtk_selection_data_free(self); // cleanup parameter self }
static void free_drag_data (NemoTreeViewDragDest *dest) { dest->details->have_drag_data = FALSE; if (dest->details->drag_data) { gtk_selection_data_free (dest->details->drag_data); dest->details->drag_data = NULL; } if (dest->details->drag_list) { nemo_drag_destroy_selection_list (dest->details->drag_list); dest->details->drag_list = NULL; } g_free (dest->details->direct_save_uri); dest->details->direct_save_uri = NULL; }
/* \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; GError * err = NULL; /* 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", &err); if (err) { GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("<b>Invalid schematic on clipboard.</b>\n\nAn error occurred while inserting clipboard data: %s."), err->message); gtk_window_set_title (GTK_WINDOW (dialog), _("Clipboard insertion failed")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free(err); } gtk_selection_data_free (selection_data); return object_list; }
static jobject get_data_raw(JNIEnv *env, const char* mime, gboolean string_data) { GtkSelectionData *data; const guchar *raw_data; jsize length; jbyteArray array; jobject result = NULL; data = gtk_clipboard_wait_for_contents(get_clipboard(), gdk_atom_intern(mime, FALSE)); if (data != NULL) { raw_data = glass_gtk_selection_data_get_data_with_length(data, &length); if (string_data) { result = env->NewStringUTF((const char*)raw_data); } else { array = env->NewByteArray(length); env->SetByteArrayRegion(array, 0, length, (const jbyte*)raw_data); result = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, array); } gtk_selection_data_free(data); } return result; }
// work out what format the clipboard data is in, and paste accordingly void clipboard_paste(void) { GtkSelectionData *sel_data; GtkClipboard *clipboard; GdkPixbuf *pixbuf; gchar *text; if (ui.cur_layer == NULL) return; ui.cur_item_type = ITEM_PASTE; clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); // try xournal data sel_data = gtk_clipboard_wait_for_contents( clipboard, gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE)); #ifdef WIN32 // avoid a win32 bug showing images as xournal data if (gtk_selection_data_get_data_type(sel_data)!=gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE)) { gtk_selection_data_free(sel_data); sel_data = NULL; } #endif ui.cur_item_type = ITEM_NONE; if (sel_data != NULL) { clipboard_paste_from_xournal(sel_data); return; } // try image data pixbuf = gtk_clipboard_wait_for_image(clipboard); if (pixbuf != NULL) { clipboard_paste_image(pixbuf); return; } // try text data text = gtk_clipboard_wait_for_text(clipboard); if (text != NULL) { clipboard_paste_text(text); return; } }
static void nemo_icon_container_free_drag_data (NemoIconContainer *container) { NemoIconDndInfo *dnd_info; dnd_info = container->details->dnd_info; dnd_info->drag_info.got_drop_data_type = FALSE; if (dnd_info->shadow != NULL) { eel_canvas_item_destroy (dnd_info->shadow); dnd_info->shadow = NULL; } if (dnd_info->drag_info.selection_data != NULL) { gtk_selection_data_free (dnd_info->drag_info.selection_data); dnd_info->drag_info.selection_data = NULL; } if (dnd_info->drag_info.direct_save_uri != NULL) { g_free (dnd_info->drag_info.direct_save_uri); dnd_info->drag_info.direct_save_uri = NULL; } }
static void free_drag_data (NautilusTreeViewDragDest *dest) { dest->details->have_drag_data = FALSE; if (dest->details->drag_data) { gtk_selection_data_free (dest->details->drag_data); dest->details->drag_data = NULL; } if (dest->details->drag_list) { nautilus_drag_destroy_selection_list (dest->details->drag_list); dest->details->drag_list = NULL; } g_free (dest->details->direct_save_uri); dest->details->direct_save_uri = NULL; g_free (dest->details->target_uri); dest->details->target_uri = NULL; remove_hover_timer (dest); remove_expand_timer (dest); }
void ptk_clipboard_paste_targets( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) //MOD added { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; gint missing_targets = 0; char* str; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_COPY; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_COPY; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { file_path = g_filename_from_uri( *puri, NULL, NULL ); if ( file_path ) { if ( g_file_test( file_path, G_FILE_TEST_IS_SYMLINK ) ) { str = file_path; file_path = g_file_read_link ( file_path, NULL ); g_free( str ); } if ( file_path ) { if ( g_file_test( file_path, G_FILE_TEST_EXISTS ) ) files = g_list_prepend( files, file_path ); else missing_targets++; } } ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); if ( missing_targets > 0 ) ptk_show_error( GTK_WINDOW( parent_win ), g_strdup_printf ( "Error" ), g_strdup_printf ( "%i target%s missing", missing_targets, missing_targets > 1 ? g_strdup_printf ( "s are" ) : g_strdup_printf ( " is" ) ) ); } }
void ptk_clipboard_paste_links( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) //MOD added { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_LINK; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; action = VFS_FILE_TASK_LINK; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { if ( file_path = g_filename_from_uri( *puri, NULL, NULL ) ) files = g_list_prepend( files, file_path ); ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); } }
void ptk_clipboard_paste_files( GtkWindow* parent_win, const char* dest_dir, GtkTreeView* task_view ) { GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); GdkAtom gnome_target; GdkAtom uri_list_target; gchar **uri_list, **puri; GtkSelectionData* sel_data = NULL; GList* files = NULL; gchar* file_path; PtkFileTask* task; VFSFileTaskType action; char* uri_list_str; gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target ); if ( sel_data ) { if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; if ( 0 == strncmp( ( char* ) sel_data->data, "cut", 3 ) ) action = VFS_FILE_TASK_MOVE; else action = VFS_FILE_TASK_COPY; if ( uri_list_str ) { while ( *uri_list_str && *uri_list_str != '\n' ) ++uri_list_str; } } else { uri_list_target = gdk_atom_intern( "text/uri-list", FALSE ); sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target ); if ( ! sel_data ) return ; if ( sel_data->length <= 0 || sel_data->format != 8 ) return ; uri_list_str = ( char* ) sel_data->data; if ( clipboard_action == GDK_ACTION_MOVE ) action = VFS_FILE_TASK_MOVE; else action = VFS_FILE_TASK_COPY; } if ( uri_list_str ) { puri = uri_list = g_uri_list_extract_uris( uri_list_str ); while ( *puri ) { file_path = g_filename_from_uri( *puri, NULL, NULL ); if ( file_path ) { files = g_list_prepend( files, file_path ); } ++puri; } g_strfreev( uri_list ); gtk_selection_data_free( sel_data ); //sfm if ( files ) files = g_list_reverse( files ); /* * If only one item is selected and the item is a * directory, paste the files in that directory; * otherwise, paste the file in current directory. */ task = ptk_file_task_new( action, files, dest_dir, GTK_WINDOW( parent_win ), GTK_WIDGET( task_view ) ); ptk_file_task_run( task ); } }
static void drag_data_received_callback (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *data, guint info, guint32 time, gpointer user_data) { NemoDragInfo *drag_info; char *tmp; const char *tmp_raw; int length; gboolean success; drag_info = &(NEMO_ICON_CONTAINER (widget)->details->dnd_info->drag_info); drag_info->got_drop_data_type = TRUE; drag_info->data_type = info; switch (info) { case NEMO_ICON_DND_GNOME_ICON_LIST: nemo_icon_container_dropped_icon_feedback (widget, data, x, y); break; case NEMO_ICON_DND_URI_LIST: case NEMO_ICON_DND_TEXT: case NEMO_ICON_DND_XDNDDIRECTSAVE: case NEMO_ICON_DND_RAW: /* Save the data so we can do the actual work on drop. */ if (drag_info->selection_data != NULL) { gtk_selection_data_free (drag_info->selection_data); } drag_info->selection_data = gtk_selection_data_copy (data); break; /* Netscape keeps sending us the data, even though we accept the first drag */ case NEMO_ICON_DND_NETSCAPE_URL: if (drag_info->selection_data != NULL) { gtk_selection_data_free (drag_info->selection_data); drag_info->selection_data = gtk_selection_data_copy (data); } break; case NEMO_ICON_DND_ROOTWINDOW_DROP: /* Do nothing, this won't even happen, since we don't want to call get_data twice */ break; } /* this is the second use case of this callback. * we have to do the actual work for the drop. */ if (drag_info->drop_occured) { success = FALSE; switch (info) { case NEMO_ICON_DND_GNOME_ICON_LIST: nemo_icon_container_receive_dropped_icons (NEMO_ICON_CONTAINER (widget), context, x, y); break; case NEMO_ICON_DND_NETSCAPE_URL: receive_dropped_netscape_url (NEMO_ICON_CONTAINER (widget), (char *) gtk_selection_data_get_data (data), context, x, y); success = TRUE; break; case NEMO_ICON_DND_URI_LIST: receive_dropped_uri_list (NEMO_ICON_CONTAINER (widget), (char *) gtk_selection_data_get_data (data), context, x, y); success = TRUE; break; case NEMO_ICON_DND_TEXT: tmp = gtk_selection_data_get_text (data); receive_dropped_text (NEMO_ICON_CONTAINER (widget), (char *) tmp, context, x, y); success = TRUE; g_free (tmp); break; case NEMO_ICON_DND_RAW: length = gtk_selection_data_get_length (data); tmp_raw = gtk_selection_data_get_data (data); receive_dropped_raw (NEMO_ICON_CONTAINER (widget), tmp_raw, length, drag_info->direct_save_uri, context, x, y); success = TRUE; break; case NEMO_ICON_DND_ROOTWINDOW_DROP: /* Do nothing, everything is done by the sender */ break; case NEMO_ICON_DND_XDNDDIRECTSAVE: { const guchar *selection_data; gint selection_length; gint selection_format; selection_data = gtk_selection_data_get_data (drag_info->selection_data); selection_length = gtk_selection_data_get_length (drag_info->selection_data); selection_format = gtk_selection_data_get_format (drag_info->selection_data); if (selection_format == 8 && selection_length == 1 && selection_data[0] == 'F') { gtk_drag_get_data (widget, context, gdk_atom_intern (NEMO_ICON_DND_RAW_TYPE, FALSE), time); return; } else if (selection_format == 8 && selection_length == 1 && selection_data[0] == 'F' && drag_info->direct_save_uri != NULL) { GdkPoint p; GFile *location; location = g_file_new_for_uri (drag_info->direct_save_uri); nemo_file_changes_queue_file_added (location); p.x = x; p.y = y; nemo_file_changes_queue_schedule_position_set ( location, p, gdk_screen_get_number ( gtk_widget_get_screen (widget))); g_object_unref (location); nemo_file_changes_consume_changes (TRUE); success = TRUE; } break; } /* NEMO_ICON_DND_XDNDDIRECTSAVE */ } gtk_drag_finish (context, success, FALSE, time); nemo_icon_container_free_drag_data (NEMO_ICON_CONTAINER (widget)); set_drop_target (NEMO_ICON_CONTAINER (widget), NULL); /* reinitialise it for the next dnd */ drag_info->drop_occured = FALSE; } }
static gboolean term_key_event (GtkWidget * widget, GdkEventKey * event, gpointer user_data) { terms_t *terms = (terms_t *) user_data; bind_t *cur; guint state = event->state; GtkClipboard *clipboard; gchar *text; state &= 0xED; // fprintf (stderr, "%s: keyval: %d, state: 0x%x\n", __func__, event->keyval, state); for (cur = terms->keys; cur; cur = cur->next) { if ((event->keyval >= cur->key_min) && (event->keyval <= cur->key_max)) { if (state == cur->state) { switch (cur->action) { case BIND_ACT_SWITCH: term_switch (terms, cur->base + (event->keyval - cur->key_min), cur->cmd); break; case BIND_ACT_CUT: widget = gtk_notebook_get_nth_page(terms->notebook, gtk_notebook_get_current_page(terms->notebook)); if (GTK_WIDGET_REALIZED(widget)) { clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), GDK_SELECTION_CLIPBOARD); } else { clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* wing it */ } text = temu_terminal_get_selection_text(widget); // printf("cut: '%s'\n", text); gtk_clipboard_set_text(clipboard, text, strlen(text)); break; case BIND_ACT_PASTE: widget = gtk_notebook_get_nth_page(terms->notebook, gtk_notebook_get_current_page(terms->notebook)); if (GTK_WIDGET_REALIZED(widget)) { clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), GDK_SELECTION_CLIPBOARD); } else { clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* wing it */ } text = gtk_clipboard_wait_for_text(clipboard); if (text) { //printf("paste: '%s'\n", text); temu_terminal_insert_text(widget, text); g_free(text); } else { // Oh boy, this is going to be 'Fun'. GtkSelectionData *data; data = gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern_static_string("STRING")); if (data) { //printf("paste; len: %d, '%s'\n", data->length, data->data); { char buf[data->length + 1]; memset(buf, '\0', data->length + 1); memcpy(buf, data->data, data->length); temu_terminal_insert_text(widget, buf); } gtk_selection_data_free(data); } } break; } return TRUE; } } } return FALSE; }
// paste xournal native data void clipboard_paste_from_xournal(GtkSelectionData *sel_data) { unsigned char *p; int nitems, npts, i, len; struct Item *item; double hoffset, voffset, cx, cy; double *pf; int sx, sy, wx, wy; reset_selection(); ui.selection = g_new(struct Selection, 1); p = sel_data->data + sizeof(int); g_memmove(&nitems, p, sizeof(int)); p+= sizeof(int); ui.selection->type = ITEM_SELECTRECT; ui.selection->layer = ui.cur_layer; g_memmove(&ui.selection->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox); ui.selection->items = NULL; // find by how much we translate the pasted selection gnome_canvas_get_scroll_offsets(canvas, &sx, &sy); gdk_window_get_geometry(GTK_WIDGET(canvas)->window, NULL, NULL, &wx, &wy, NULL); gnome_canvas_window_to_world(canvas, sx + wx/2, sy + wy/2, &cx, &cy); cx -= ui.cur_page->hoffset; cy -= ui.cur_page->voffset; if (cx + (ui.selection->bbox.right-ui.selection->bbox.left)/2 > ui.cur_page->width) cx = ui.cur_page->width - (ui.selection->bbox.right-ui.selection->bbox.left)/2; if (cx - (ui.selection->bbox.right-ui.selection->bbox.left)/2 < 0) cx = (ui.selection->bbox.right-ui.selection->bbox.left)/2; if (cy + (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 > ui.cur_page->height) cy = ui.cur_page->height - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2; if (cy - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 < 0) cy = (ui.selection->bbox.bottom-ui.selection->bbox.top)/2; hoffset = cx - (ui.selection->bbox.right+ui.selection->bbox.left)/2; voffset = cy - (ui.selection->bbox.top+ui.selection->bbox.bottom)/2; ui.selection->bbox.left += hoffset; ui.selection->bbox.right += hoffset; ui.selection->bbox.top += voffset; ui.selection->bbox.bottom += voffset; ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group, gnome_canvas_rect_get_type(), "width-pixels", 1, "outline-color-rgba", 0x000000ff, "fill-color-rgba", 0x80808040, "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right, "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL); make_dashed(ui.selection->canvas_item); while (nitems-- > 0) { item = g_new(struct Item, 1); ui.selection->items = g_list_append(ui.selection->items, item); ui.cur_layer->items = g_list_append(ui.cur_layer->items, item); ui.cur_layer->nitems++; g_memmove(&item->type, p, sizeof(int)); p+= sizeof(int); if (item->type == ITEM_STROKE) { g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush); g_memmove(&npts, p, sizeof(int)); p+= sizeof(int); item->path = gnome_canvas_points_new(npts); pf = (double *)p; for (i=0; i<npts; i++) { item->path->coords[2*i] = pf[2*i] + hoffset; item->path->coords[2*i+1] = pf[2*i+1] + voffset; } p+= 2*item->path->num_points*sizeof(double); if (item->brush.variable_width) { item->widths = g_memdup(p, (item->path->num_points-1)*sizeof(double)); p+= (item->path->num_points-1)*sizeof(double); } else item->widths = NULL; update_item_bbox(item); make_canvas_item_one(ui.cur_layer->group, item); } if (item->type == ITEM_TEXT) { g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush); g_memmove(&item->bbox.left, p, sizeof(double)); p+= sizeof(double); g_memmove(&item->bbox.top, p, sizeof(double)); p+= sizeof(double); item->bbox.left += hoffset; item->bbox.top += voffset; g_memmove(&len, p, sizeof(int)); p+= sizeof(int); item->text = g_malloc(len+1); g_memmove(item->text, p, len+1); p+= len+1; g_memmove(&len, p, sizeof(int)); p+= sizeof(int); item->font_name = g_malloc(len+1); g_memmove(item->font_name, p, len+1); p+= len+1; g_memmove(&item->font_size, p, sizeof(double)); p+= sizeof(double); make_canvas_item_one(ui.cur_layer->group, item); } if (item->type == ITEM_IMAGE) { item->canvas_item = NULL; item->image_png = NULL; item->image_png_len = 0; g_memmove(&item->bbox, p, sizeof(struct BBox)); p+= sizeof(struct BBox); item->bbox.left += hoffset; item->bbox.right += hoffset; item->bbox.top += voffset; item->bbox.bottom += voffset; g_memmove(&item->image_png_len, p, sizeof(gsize)); p+= sizeof(gsize); if (item->image_png_len > 0) { item->image_png = g_memdup(p, item->image_png_len); item->image = pixbuf_from_buffer(item->image_png, item->image_png_len); p+= item->image_png_len; } else { item->image = NULL; } make_canvas_item_one(ui.cur_layer->group, item); } } prepare_new_undo(); undo->type = ITEM_PASTE; undo->layer = ui.cur_layer; undo->itemlist = g_list_copy(ui.selection->items); gtk_selection_data_free(sel_data); update_copy_paste_enabled(); update_color_menu(); update_thickness_buttons(); update_color_buttons(); update_font_button(); update_cursor(); // FIXME: can't know if pointer is within selection! }
NS_IMETHODIMP nsClipboard::GetData(nsITransferable *aTransferable, PRInt32 aWhichClipboard) { if (!aTransferable) return NS_ERROR_FAILURE; GtkClipboard *clipboard; clipboard = gtk_clipboard_get(GetSelectionAtom(aWhichClipboard)); guchar *data = NULL; gint length = 0; PRBool foundData = PR_FALSE; nsCAutoString foundFlavor; // Get a list of flavors this transferable can import nsCOMPtr<nsISupportsArray> flavors; nsresult rv; rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavors)); if (!flavors || NS_FAILED(rv)) return NS_ERROR_FAILURE; PRUint32 count; flavors->Count(&count); for (PRUint32 i=0; i < count; i++) { nsCOMPtr<nsISupports> genericFlavor; flavors->GetElementAt(i, getter_AddRefs(genericFlavor)); nsCOMPtr<nsISupportsCString> currentFlavor; currentFlavor = do_QueryInterface(genericFlavor); if (currentFlavor) { nsXPIDLCString flavorStr; currentFlavor->ToString(getter_Copies(flavorStr)); // Special case text/unicode since we can convert any // string into text/unicode if (!strcmp(flavorStr, kUnicodeMime)) { gchar* new_text = wait_for_text(clipboard); if (new_text) { // Convert utf-8 into our unicode format. NS_ConvertUTF8toUTF16 ucs2string(new_text); data = (guchar *)ToNewUnicode(ucs2string); length = ucs2string.Length() * 2; g_free(new_text); foundData = PR_TRUE; foundFlavor = kUnicodeMime; break; } // If the type was text/unicode and we couldn't get // text off the clipboard, run the next loop // iteration. continue; } // For images, we must wrap the data in an nsIInputStream then return instead of break, // because that code below won't help us. if (!strcmp(flavorStr, kJPEGImageMime) || !strcmp(flavorStr, kPNGImageMime) || !strcmp(flavorStr, kGIFImageMime)) { GdkAtom atom; if (!strcmp(flavorStr, kJPEGImageMime)) // This is image/jpg, but X only understands image/jpeg atom = gdk_atom_intern("image/jpeg", FALSE); else atom = gdk_atom_intern(flavorStr, FALSE); GtkSelectionData *selectionData = wait_for_contents(clipboard, atom); if (!selectionData) continue; nsCOMPtr<nsIInputStream> byteStream; NS_NewByteInputStream(getter_AddRefs(byteStream), (const char*)selectionData->data, selectionData->length, NS_ASSIGNMENT_COPY); aTransferable->SetTransferData(flavorStr, byteStream, sizeof(nsIInputStream*)); gtk_selection_data_free(selectionData); return NS_OK; } // Get the atom for this type and try to request it off // the clipboard. GdkAtom atom = gdk_atom_intern(flavorStr, FALSE); GtkSelectionData *selectionData; selectionData = wait_for_contents(clipboard, atom); if (selectionData) { length = selectionData->length; // Special case text/html since we can convert into UCS2 if (!strcmp(flavorStr, kHTMLMime)) { PRUnichar* htmlBody= nsnull; PRInt32 htmlBodyLen = 0; // Convert text/html into our unicode format ConvertHTMLtoUCS2((guchar *)selectionData->data, length, &htmlBody, htmlBodyLen); // Try next data format? if (!htmlBodyLen) continue; data = (guchar *)htmlBody; length = htmlBodyLen * 2; } else { data = (guchar *)nsMemory::Alloc(length); if (!data) break; memcpy(data, selectionData->data, length); } foundData = PR_TRUE; foundFlavor = flavorStr; break; } } } if (foundData) { nsCOMPtr<nsISupports> wrapper; nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor.get(), data, length, getter_AddRefs(wrapper)); aTransferable->SetTransferData(foundFlavor.get(), wrapper, length); } if (data) nsMemory::Free(data); return NS_OK; }
void clipboard_paste_selection (ddb_playlist_t *plt, int ctx) { if (!plt) { return; } GdkDisplay *display = mainwin ? gtk_widget_get_display (mainwin) : gdk_display_get_default(); GtkClipboard *clip = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD); int type = 0; GdkAtom *avail_targets = NULL; int n = 0; // get all available targets currently in the clipboard. if (!gtk_clipboard_wait_for_targets (clip, &avail_targets, &n)) { return; } clipboard_check_atoms (); // we prefer DDB_URI_LIST, so first check all tragets for that for (int i = 0; i < n; i++) { if (avail_targets[i] == target_atom[DDB_URI_LIST]) { type = DDB_URI_LIST; break; } } if (type == 0) { // no DDB_URI_LIST, check for other supported targets for (int i = 0; i < n; i++) { if (avail_targets[i] == target_atom[GNOME_COPIED_FILES]) { type = GNOME_COPIED_FILES; break; } else if (avail_targets[i] == target_atom[URI_LIST]) { type = URI_LIST; break; } } } g_free (avail_targets); if (type) { GtkSelectionData *data = gtk_clipboard_wait_for_contents (clip, target_atom[type]); const gchar *pdata = (const gchar *)gtk_selection_data_get_data (data); gint data_len = gtk_selection_data_get_length (data); switch (type) { case DDB_URI_LIST: clipboard_activate_dest_playlist (pdata, plt, ctx); clipboard_received_ddb_uri_list (pdata); break; case GNOME_COPIED_FILES: clipboard_activate_dest_playlist (NULL, plt, ctx); clipboard_received_uri_list (pdata, data_len); break; case URI_LIST: clipboard_activate_dest_playlist (NULL, plt, ctx); clipboard_received_uri_list (pdata, data_len); break; default: break; } gtk_selection_data_free (data); } }
gboolean fm_clipboard_paste_files(GtkWidget* dest_widget, FmPath* dest_dir) { GdkDisplay* dpy = dest_widget ? gtk_widget_get_display(dest_widget) : gdk_display_get_default(); GtkClipboard* clip = gtk_clipboard_get_for_display(dpy, GDK_SELECTION_CLIPBOARD); FmPathList* files; char** uris, **uri; GdkAtom atom; int type = 0; GdkAtom *avail_targets; int n, i; /* get all available targets currently in the clipboard. */ if( !gtk_clipboard_wait_for_targets(clip, &avail_targets, &n) ) return FALSE; /* check gnome and xfce compatible format first */ atom = gdk_atom_intern_static_string(targets[GNOME_COPIED_FILES-1].target); for(i = 0; i < n; ++i) { if(avail_targets[i] == atom) { type = GNOME_COPIED_FILES; break; } } if( 0 == type ) /* x-special/gnome-copied-files is not found. */ { /* check uri-list */ atom = gdk_atom_intern_static_string(targets[URI_LIST-1].target); for(i = 0; i < n; ++i) { if(avail_targets[i] == atom) { type = URI_LIST; break; } } if( 0 == type ) /* text/uri-list is not found. */ { /* finally, fallback to UTF-8 string */ atom = gdk_atom_intern_static_string(targets[UTF8_STRING-1].target); for(i = 0; i < n; ++i) { if(avail_targets[i] == atom) { type = UTF8_STRING; break; } } } } g_free(avail_targets); if( type ) { GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, atom); char* pdata = (char*)data->data; /* FIXME: is it safe to assume the clipboard data is null-terminalted? * According to the source code in gtkselection.c, gtk+ seems to * includes an extra byte at the end of GtkSelectionData::data, so * this should be safe. */ pdata[data->length] = '\0'; /* make sure the data is null-terminated. */ is_cut = FALSE; switch(type) { case GNOME_COPIED_FILES: is_cut = g_str_has_prefix(pdata, "cut\n"); while(*pdata && *pdata != '\n') ++pdata; ++pdata; /* the following parts is actually a uri-list, so don't break here. */ case URI_LIST: uris = g_uri_list_extract_uris(pdata); if( type != GNOME_COPIED_FILES ) { /* if we're not handling x-special/gnome-copied-files, check * if information from KDE is available. */ is_cut = check_kde_curselection(clip); } break; case UTF8_STRING: /* FIXME: how should we treat UTF-8 strings? URIs or filenames? */ uris = g_uri_list_extract_uris(pdata); break; } gtk_selection_data_free(data); if(uris) { files = fm_path_list_new_from_uris((const char **)uris); g_strfreev(uris); if( is_cut ) fm_move_files(files, dest_dir); else fm_copy_files(files, dest_dir); fm_list_unref(files); return TRUE; } } return FALSE; }