Commit 3bf11510 authored by John Ralls's avatar John Ralls

Fix Quartz clipboard image retrieval.

It does no good to iterate through a series of mime types to call a
function when the eventually-called function,
_gtk_quartz_get_selection_data_from_pasteboard() in this case, gives the
wrong answer and stops the iteration on all but one especially if that
one isn't first.

The one is "image/tiff" and the quartz pasteboard function will return
any image type Quartz knows about for it, so lose the iteration and use
only "image/tiff".
parent 1bd0431a
...@@ -142,7 +142,7 @@ static GtkClipboard *clipboard_peek (GdkDisplay *display, ...@@ -142,7 +142,7 @@ static GtkClipboard *clipboard_peek (GdkDisplay *display,
{ {
self = [super init]; self = [super init];
if (self) if (self)
{ {
clipboard = aClipboard; clipboard = aClipboard;
setting_same_owner = FALSE; setting_same_owner = FALSE;
...@@ -164,7 +164,7 @@ GType ...@@ -164,7 +164,7 @@ GType
gtk_clipboard_get_type (void) gtk_clipboard_get_type (void)
{ {
static GType clipboard_type = 0; static GType clipboard_type = 0;
if (!clipboard_type) if (!clipboard_type)
{ {
const GTypeInfo clipboard_info = const GTypeInfo clipboard_info =
...@@ -179,11 +179,11 @@ gtk_clipboard_get_type (void) ...@@ -179,11 +179,11 @@ gtk_clipboard_get_type (void)
0, /* n_preallocs */ 0, /* n_preallocs */
(GInstanceInitFunc) NULL, (GInstanceInitFunc) NULL,
}; };
clipboard_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkClipboard"), clipboard_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkClipboard"),
&clipboard_info, 0); &clipboard_info, 0);
} }
return clipboard_type; return clipboard_type;
} }
...@@ -193,7 +193,7 @@ gtk_clipboard_class_init (GtkClipboardClass *class) ...@@ -193,7 +193,7 @@ gtk_clipboard_class_init (GtkClipboardClass *class)
GObjectClass *gobject_class = G_OBJECT_CLASS (class); GObjectClass *gobject_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class); parent_class = g_type_class_peek_parent (class);
gobject_class->finalize = gtk_clipboard_finalize; gobject_class->finalize = gtk_clipboard_finalize;
class->owner_change = gtk_clipboard_owner_change; class->owner_change = gtk_clipboard_owner_change;
...@@ -227,7 +227,7 @@ gtk_clipboard_finalize (GObject *object) ...@@ -227,7 +227,7 @@ gtk_clipboard_finalize (GObject *object)
g_warning ("GtkClipboard prematurely finalized"); g_warning ("GtkClipboard prematurely finalized");
clipboard_unset (clipboard); clipboard_unset (clipboard);
clipboards = g_object_get_data (G_OBJECT (clipboard->display), "gtk-clipboard-list"); clipboards = g_object_get_data (G_OBJECT (clipboard->display), "gtk-clipboard-list");
clipboards = g_slist_remove (clipboards, clipboard); clipboards = g_slist_remove (clipboards, clipboard);
g_object_set_data (G_OBJECT (clipboard->display), I_("gtk-clipboard-list"), clipboards); g_object_set_data (G_OBJECT (clipboard->display), I_("gtk-clipboard-list"), clipboards);
...@@ -312,7 +312,7 @@ clipboard_owner_destroyed (gpointer data) ...@@ -312,7 +312,7 @@ clipboard_owner_destroyed (gpointer data)
tmp_list = tmp_list->next; tmp_list = tmp_list->next;
} }
g_slist_free (clipboards); g_slist_free (clipboards);
} }
...@@ -321,7 +321,7 @@ clipboard_add_owner_notify (GtkClipboard *clipboard) ...@@ -321,7 +321,7 @@ clipboard_add_owner_notify (GtkClipboard *clipboard)
{ {
if (!clipboards_owned_key_id) if (!clipboards_owned_key_id)
clipboards_owned_key_id = g_quark_from_static_string (clipboards_owned_key); clipboards_owned_key_id = g_quark_from_static_string (clipboards_owned_key);
if (clipboard->have_owner) if (clipboard->have_owner)
g_object_set_qdata_full (clipboard->user_data, clipboards_owned_key_id, g_object_set_qdata_full (clipboard->user_data, clipboards_owned_key_id,
g_slist_prepend (g_object_steal_qdata (clipboard->user_data, g_slist_prepend (g_object_steal_qdata (clipboard->user_data,
...@@ -502,12 +502,12 @@ clipboard_unset (GtkClipboard *clipboard) ...@@ -502,12 +502,12 @@ clipboard_unset (GtkClipboard *clipboard)
gpointer old_data; gpointer old_data;
gboolean old_have_owner; gboolean old_have_owner;
gint old_n_storable_targets; gint old_n_storable_targets;
old_clear_func = clipboard->clear_func; old_clear_func = clipboard->clear_func;
old_data = clipboard->user_data; old_data = clipboard->user_data;
old_have_owner = clipboard->have_owner; old_have_owner = clipboard->have_owner;
old_n_storable_targets = clipboard->n_storable_targets; old_n_storable_targets = clipboard->n_storable_targets;
if (old_have_owner) if (old_have_owner)
{ {
clipboard_remove_owner_notify (clipboard); clipboard_remove_owner_notify (clipboard);
...@@ -522,7 +522,7 @@ clipboard_unset (GtkClipboard *clipboard) ...@@ -522,7 +522,7 @@ clipboard_unset (GtkClipboard *clipboard)
clipboard->get_func = NULL; clipboard->get_func = NULL;
clipboard->clear_func = NULL; clipboard->clear_func = NULL;
clipboard->user_data = NULL; clipboard->user_data = NULL;
if (old_clear_func) if (old_clear_func)
old_clear_func (clipboard, old_data); old_clear_func (clipboard, old_data);
...@@ -548,7 +548,7 @@ gtk_clipboard_clear (GtkClipboard *clipboard) ...@@ -548,7 +548,7 @@ gtk_clipboard_clear (GtkClipboard *clipboard)
[clipboard->pasteboard declareTypes:nil owner:nil]; [clipboard->pasteboard declareTypes:nil owner:nil];
} }
static void static void
text_get_func (GtkClipboard *clipboard, text_get_func (GtkClipboard *clipboard,
GtkSelectionData *selection_data, GtkSelectionData *selection_data,
guint info, guint info,
...@@ -557,14 +557,14 @@ text_get_func (GtkClipboard *clipboard, ...@@ -557,14 +557,14 @@ text_get_func (GtkClipboard *clipboard,
gtk_selection_data_set_text (selection_data, data, -1); gtk_selection_data_set_text (selection_data, data, -1);
} }
static void static void
text_clear_func (GtkClipboard *clipboard, text_clear_func (GtkClipboard *clipboard,
gpointer data) gpointer data)
{ {
g_free (data); g_free (data);
} }
void void
gtk_clipboard_set_text (GtkClipboard *clipboard, gtk_clipboard_set_text (GtkClipboard *clipboard,
const gchar *text, const gchar *text,
gint len) gint len)
...@@ -573,11 +573,11 @@ gtk_clipboard_set_text (GtkClipboard *clipboard, ...@@ -573,11 +573,11 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
g_return_if_fail (clipboard != NULL); g_return_if_fail (clipboard != NULL);
g_return_if_fail (text != NULL); g_return_if_fail (text != NULL);
if (len < 0) if (len < 0)
len = strlen (text); len = strlen (text);
gtk_clipboard_set_with_data (clipboard, gtk_clipboard_set_with_data (clipboard,
&target, 1, &target, 1,
text_get_func, text_clear_func, text_get_func, text_clear_func,
g_strndup (text, len)); g_strndup (text, len));
...@@ -585,7 +585,7 @@ gtk_clipboard_set_text (GtkClipboard *clipboard, ...@@ -585,7 +585,7 @@ gtk_clipboard_set_text (GtkClipboard *clipboard,
} }
static void static void
pixbuf_get_func (GtkClipboard *clipboard, pixbuf_get_func (GtkClipboard *clipboard,
GtkSelectionData *selection_data, GtkSelectionData *selection_data,
guint info, guint info,
...@@ -594,7 +594,7 @@ pixbuf_get_func (GtkClipboard *clipboard, ...@@ -594,7 +594,7 @@ pixbuf_get_func (GtkClipboard *clipboard,
gtk_selection_data_set_pixbuf (selection_data, data); gtk_selection_data_set_pixbuf (selection_data, data);
} }
static void static void
pixbuf_clear_func (GtkClipboard *clipboard, pixbuf_clear_func (GtkClipboard *clipboard,
gpointer data) gpointer data)
{ {
...@@ -624,7 +624,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard, ...@@ -624,7 +624,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
targets[i].target = gdk_atom_name (pair->target); targets[i].target = gdk_atom_name (pair->target);
} }
gtk_clipboard_set_with_data (clipboard, gtk_clipboard_set_with_data (clipboard,
targets, n_targets, targets, n_targets,
pixbuf_get_func, pixbuf_clear_func, pixbuf_get_func, pixbuf_clear_func,
g_object_ref (pixbuf)); g_object_ref (pixbuf));
...@@ -643,7 +643,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard, ...@@ -643,7 +643,7 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
* @callback: (scope async): * @callback: (scope async):
* @user_data: * @user_data:
*/ */
void void
gtk_clipboard_request_contents (GtkClipboard *clipboard, gtk_clipboard_request_contents (GtkClipboard *clipboard,
GdkAtom target, GdkAtom target,
GtkClipboardReceivedFunc callback, GtkClipboardReceivedFunc callback,
...@@ -664,7 +664,7 @@ gtk_clipboard_request_contents (GtkClipboard *clipboard, ...@@ -664,7 +664,7 @@ gtk_clipboard_request_contents (GtkClipboard *clipboard,
* @callback: (scope async): * @callback: (scope async):
* @user_data: * @user_data:
*/ */
void void
gtk_clipboard_request_text (GtkClipboard *clipboard, gtk_clipboard_request_text (GtkClipboard *clipboard,
GtkClipboardTextReceivedFunc callback, GtkClipboardTextReceivedFunc callback,
gpointer user_data) gpointer user_data)
...@@ -718,7 +718,7 @@ gtk_clipboard_wait_for_rich_text (GtkClipboard *clipboard, ...@@ -718,7 +718,7 @@ gtk_clipboard_wait_for_rich_text (GtkClipboard *clipboard,
* @callback: (scope async): * @callback: (scope async):
* @user_data: * @user_data:
*/ */
void void
gtk_clipboard_request_image (GtkClipboard *clipboard, gtk_clipboard_request_image (GtkClipboard *clipboard,
GtkClipboardImageReceivedFunc callback, GtkClipboardImageReceivedFunc callback,
gpointer user_data) gpointer user_data)
...@@ -737,7 +737,7 @@ gtk_clipboard_request_image (GtkClipboard *clipboard, ...@@ -737,7 +737,7 @@ gtk_clipboard_request_image (GtkClipboard *clipboard,
* @callback: (scope async): * @callback: (scope async):
* @user_data: * @user_data:
*/ */
void void
gtk_clipboard_request_uris (GtkClipboard *clipboard, gtk_clipboard_request_uris (GtkClipboard *clipboard,
GtkClipboardURIReceivedFunc callback, GtkClipboardURIReceivedFunc callback,
gpointer user_data) gpointer user_data)
...@@ -755,7 +755,7 @@ gtk_clipboard_request_uris (GtkClipboard *clipboard, ...@@ -755,7 +755,7 @@ gtk_clipboard_request_uris (GtkClipboard *clipboard,
* @callback: (scope async): * @callback: (scope async):
* @user_data: * @user_data:
*/ */
void void
gtk_clipboard_request_targets (GtkClipboard *clipboard, gtk_clipboard_request_targets (GtkClipboard *clipboard,
GtkClipboardTargetsReceivedFunc callback, GtkClipboardTargetsReceivedFunc callback,
gpointer user_data) gpointer user_data)
...@@ -788,7 +788,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard, ...@@ -788,7 +788,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
clipboard->change_count = [clipboard->pasteboard changeCount]; clipboard->change_count = [clipboard->pasteboard changeCount];
} }
if (target == gdk_atom_intern_static_string ("TARGETS")) if (target == gdk_atom_intern_static_string ("TARGETS"))
{ {
NSArray *types = [clipboard->pasteboard types]; NSArray *types = [clipboard->pasteboard types];
int i, length; int i, length;
...@@ -841,7 +841,7 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard) ...@@ -841,7 +841,7 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
GtkSelectionData *data; GtkSelectionData *data;
gchar *result; gchar *result;
data = gtk_clipboard_wait_for_contents (clipboard, data = gtk_clipboard_wait_for_contents (clipboard,
gdk_atom_intern_static_string ("UTF8_STRING")); gdk_atom_intern_static_string ("UTF8_STRING"));
result = (gchar *)gtk_selection_data_get_text (data); result = (gchar *)gtk_selection_data_get_text (data);
...@@ -860,23 +860,18 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard) ...@@ -860,23 +860,18 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
GdkPixbuf * GdkPixbuf *
gtk_clipboard_wait_for_image (GtkClipboard *clipboard) gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
{ {
const gchar *priority[] = { "image/png", "image/tiff", "image/jpeg", "image/gif", "image/bmp" }; GdkAtom target = gdk_atom_intern_static_string("image/tiff")
int i; int i;
GtkSelectionData *data; GtkSelectionData *data;
for (i = 0; i < G_N_ELEMENTS (priority); i++) data = gtk_clipboard_wait_for_contents (clipboard, target);
{
data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string (priority[i]));
if (data)
{
GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
gtk_selection_data_free (data);
return pixbuf; if (data && data->data)
} {
} GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
gtk_selection_data_free (data);
return pixbuf;
}
return NULL; return NULL;
} }
...@@ -901,7 +896,7 @@ gtk_clipboard_wait_for_uris (GtkClipboard *clipboard) ...@@ -901,7 +896,7 @@ gtk_clipboard_wait_for_uris (GtkClipboard *clipboard)
gtk_selection_data_free (data); gtk_selection_data_free (data);
return uris; return uris;
} }
return NULL; return NULL;
} }
...@@ -962,7 +957,7 @@ gtk_clipboard_wait_is_image_available (GtkClipboard *clipboard) ...@@ -962,7 +957,7 @@ gtk_clipboard_wait_is_image_available (GtkClipboard *clipboard)
GtkSelectionData *data; GtkSelectionData *data;
gboolean result = FALSE; gboolean result = FALSE;
data = gtk_clipboard_wait_for_contents (clipboard, data = gtk_clipboard_wait_for_contents (clipboard,
gdk_atom_intern_static_string ("TARGETS")); gdk_atom_intern_static_string ("TARGETS"));
if (data) if (data)
{ {
...@@ -979,7 +974,7 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard) ...@@ -979,7 +974,7 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard)
GtkSelectionData *data; GtkSelectionData *data;
gboolean result = FALSE; gboolean result = FALSE;
data = gtk_clipboard_wait_for_contents (clipboard, data = gtk_clipboard_wait_for_contents (clipboard,
gdk_atom_intern_static_string ("TARGETS")); gdk_atom_intern_static_string ("TARGETS"));
if (data) if (data)
{ {
...@@ -997,13 +992,13 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard) ...@@ -997,13 +992,13 @@ gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard)
* @n_targets: (out): * @n_targets: (out):
*/ */
gboolean gboolean
gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, gtk_clipboard_wait_for_targets (GtkClipboard *clipboard,
GdkAtom **targets, GdkAtom **targets,
gint *n_targets) gint *n_targets)
{ {
GtkSelectionData *data; GtkSelectionData *data;
gboolean result = FALSE; gboolean result = FALSE;
g_return_val_if_fail (clipboard != NULL, FALSE); g_return_val_if_fail (clipboard != NULL, FALSE);
/* If the display supports change notification we cache targets */ /* If the display supports change notification we cache targets */
...@@ -1012,19 +1007,19 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, ...@@ -1012,19 +1007,19 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard,
{ {
if (n_targets) if (n_targets)
*n_targets = clipboard->n_cached_targets; *n_targets = clipboard->n_cached_targets;
if (targets) if (targets)
*targets = g_memdup (clipboard->cached_targets, *targets = g_memdup (clipboard->cached_targets,
clipboard->n_cached_targets * sizeof (GdkAtom)); clipboard->n_cached_targets * sizeof (GdkAtom));
return TRUE; return TRUE;
} }
if (n_targets) if (n_targets)
*n_targets = 0; *n_targets = 0;
if (targets) if (targets)
*targets = NULL; *targets = NULL;
data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string ("TARGETS")); data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string ("TARGETS"));
...@@ -1032,24 +1027,24 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, ...@@ -1032,24 +1027,24 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard,
{ {
GdkAtom *tmp_targets; GdkAtom *tmp_targets;
gint tmp_n_targets; gint tmp_n_targets;
result = gtk_selection_data_get_targets (data, &tmp_targets, &tmp_n_targets); result = gtk_selection_data_get_targets (data, &tmp_targets, &tmp_n_targets);
if (gdk_display_supports_selection_notification (gtk_clipboard_get_display (clipboard))) if (gdk_display_supports_selection_notification (gtk_clipboard_get_display (clipboard)))
{ {
clipboard->n_cached_targets = tmp_n_targets; clipboard->n_cached_targets = tmp_n_targets;
clipboard->cached_targets = g_memdup (tmp_targets, clipboard->cached_targets = g_memdup (tmp_targets,
tmp_n_targets * sizeof (GdkAtom)); tmp_n_targets * sizeof (GdkAtom));
} }
if (n_targets) if (n_targets)
*n_targets = tmp_n_targets; *n_targets = tmp_n_targets;
if (targets) if (targets)
*targets = tmp_targets; *targets = tmp_targets;
else else
g_free (tmp_targets); g_free (tmp_targets);
gtk_selection_data_free (data); gtk_selection_data_free (data);
} }
...@@ -1057,7 +1052,7 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, ...@@ -1057,7 +1052,7 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard,
} }
static GtkClipboard * static GtkClipboard *
clipboard_peek (GdkDisplay *display, clipboard_peek (GdkDisplay *display,
GdkAtom selection, GdkAtom selection,
gboolean only_if_exists) gboolean only_if_exists)
{ {
...@@ -1086,13 +1081,13 @@ clipboard_peek (GdkDisplay *display, ...@@ -1086,13 +1081,13 @@ clipboard_peek (GdkDisplay *display,
NSString *pasteboard_name; NSString *pasteboard_name;
clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL); clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
if (selection == GDK_SELECTION_CLIPBOARD) if (selection == GDK_SELECTION_CLIPBOARD)
pasteboard_name = NSGeneralPboard; pasteboard_name = NSGeneralPboard;
else else
{ {
char *atom_string = gdk_atom_name (selection); char *atom_string = gdk_atom_name (selection);
pasteboard_name = [NSString stringWithFormat:@"_GTK_%@", pasteboard_name = [NSString stringWithFormat:@"_GTK_%@",
[NSString stringWithUTF8String:atom_string]]; [NSString stringWithUTF8String:atom_string]];
g_free (atom_string); g_free (atom_string);
} }
...@@ -1111,7 +1106,7 @@ clipboard_peek (GdkDisplay *display, ...@@ -1111,7 +1106,7 @@ clipboard_peek (GdkDisplay *display,
G_CALLBACK (clipboard_display_closed), clipboard); G_CALLBACK (clipboard_display_closed), clipboard);
gdk_display_request_selection_notification (display, selection); gdk_display_request_selection_notification (display, selection);
} }
return clipboard; return clipboard;
} }
...@@ -1133,7 +1128,7 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard, ...@@ -1133,7 +1128,7 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
GdkAtom *targets; GdkAtom *targets;
gint i, n_targets; gint i, n_targets;
gboolean retval = FALSE; gboolean retval = FALSE;
if (!gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) if (!gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets))
return FALSE; return FALSE;
...@@ -1147,11 +1142,11 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard, ...@@ -1147,11 +1142,11 @@ gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
} }
g_free (targets); g_free (targets);
return retval; return retval;
} }
void void
_gtk_clipboard_handle_event (GdkEventOwnerChange *event) _gtk_clipboard_handle_event (GdkEventOwnerChange *event)
{ {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment