X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkclipboard-quartz.c;h=482f6aa13518de0977cab81706e0423b2cd309c9;hb=bb3c56abe2e7916126bd4f8234dee080b5381941;hp=046fe71ccfa98b359eb1ed75af613c4a1977e41d;hpb=9d31a04d129d7bc10f5b5e1922ee919c0063212c;p=~andy%2Fgtk diff --git a/gtk/gtkclipboard-quartz.c b/gtk/gtkclipboard-quartz.c index 046fe71cc..482f6aa13 100644 --- a/gtk/gtkclipboard-quartz.c +++ b/gtk/gtkclipboard-quartz.c @@ -31,7 +31,7 @@ #include "gtktextbuffer.h" #include "gtkselectionprivate.h" #include "gtkquartz.h" - +#include "../gdk/quartz/gdkquartz.h" enum { OWNER_CHANGE, @@ -40,6 +40,7 @@ enum { @interface GtkClipboardOwner : NSObject { GtkClipboard *clipboard; + @public gboolean setting_same_owner; } @@ -47,7 +48,7 @@ enum { typedef struct _GtkClipboardClass GtkClipboardClass; -struct _GtkClipboard +struct _GtkClipboard { GObject parent_instance; @@ -1038,11 +1039,74 @@ gtk_clipboard_set_can_store (GtkClipboard *clipboard, void gtk_clipboard_store (GtkClipboard *clipboard) { - /* FIXME: Implement */ + int i; + int n_targets = 0; + GtkTargetEntry *targets; + + g_return_if_fail (GTK_IS_CLIPBOARD (clipboard)); + + if (!clipboard->target_list || !clipboard->get_func) + return; + + /* We simply store all targets into the OS X clipboard. We should be + * using the functions gdk_display_supports_clipboard_persistence() and + * gdk_display_store_clipboard(), but since for OS X the clipboard support + * was implemented in GTK+ and not through GdkSelections, we do it this + * way. Doing this properly could be worthwhile to implement in the future. + */ + + targets = gtk_target_table_new_from_list (clipboard->target_list, + &n_targets); + for (i = 0; i < n_targets; i++) + { + GtkSelectionData selection_data; + + /* in each loop iteration, check if the content is still + * there, because calling get_func() can do anything to + * the clipboard + */ + if (!clipboard->target_list || !clipboard->get_func) + break; + + memset (&selection_data, 0, sizeof (GtkSelectionData)); + + selection_data.selection = clipboard->selection; + selection_data.target = gdk_atom_intern_static_string (targets[i].target); + selection_data.display = gdk_display_get_default (); + selection_data.length = -1; + + clipboard->get_func (clipboard, &selection_data, + targets[i].info, clipboard->user_data); + + if (selection_data.length >= 0) + _gtk_quartz_set_selection_data_for_pasteboard (clipboard->pasteboard, + &selection_data); + + g_free (selection_data.data); + } + + if (targets) + gtk_target_table_free (targets, n_targets); } void _gtk_clipboard_store_all (void) { - /* FIXME: Implement */ + GtkClipboard *clipboard; + GSList *displays, *list; + + displays = gdk_display_manager_list_displays (gdk_display_manager_get ()); + + list = displays; + while (list) + { + GdkDisplay *display = list->data; + + clipboard = clipboard_peek (display, GDK_SELECTION_CLIPBOARD, TRUE); + + if (clipboard) + gtk_clipboard_store (clipboard); + + list = list->next; + } }