Commit 2f29e8d9 authored by Richard Hult's avatar Richard Hult Committed by Richard Hult

Patch from Christian Dywan to clean up selection data setting.

2008-06-26  Richard Hult  <richard@imendio.com>

	* gtk/gtkclipboard-quartz.c: (gtk_clipboard_wait_for_contents):
	* gtk/gtkquartz.c:
	(_gtk_quartz_get_selection_data_from_pasteboard),
	(_gtk_quartz_set_selection_data_for_pasteboard): Patch from
	Christian Dywan to clean up selection data setting.

svn path=/trunk/; revision=20690
parent 2e6f82b9
2008-06-26 Richard Hult <richard@imendio.com>
* gtk/gtkclipboard-quartz.c: (gtk_clipboard_wait_for_contents):
* gtk/gtkquartz.c:
(_gtk_quartz_get_selection_data_from_pasteboard),
(_gtk_quartz_set_selection_data_for_pasteboard): Patch from
Christian Dywan to clean up selection data setting.
2008-06-26 Richard Hult <richard@imendio.com> 2008-06-26 Richard Hult <richard@imendio.com>
* gtk/gtkdnd-quartz.c (gtk_drag_begin_internal): Don't use * gtk/gtkdnd-quartz.c (gtk_drag_begin_internal): Don't use
......
...@@ -872,31 +872,29 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard, ...@@ -872,31 +872,29 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
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, count; int i, length;
GList *atom_list, *l; GList *atom_list, *l;
GdkAtom *atoms; GdkAtom *atoms;
count = [types count]; length = [types count] * sizeof (GdkAtom);
atom_list = _gtk_quartz_pasteboard_types_to_atom_list (types);
selection_data = g_slice_new (GtkSelectionData); selection_data = g_slice_new (GtkSelectionData);
selection_data->selection = clipboard->selection; selection_data->selection = clipboard->selection;
selection_data->target = target; selection_data->target = target;
selection_data->type = GDK_SELECTION_TYPE_ATOM;
selection_data->format = 32;
selection_data->length = count * sizeof (GdkAtom);
atoms = g_malloc (selection_data->length + 1); atoms = g_malloc (length);
atom_list = _gtk_quartz_pasteboard_types_to_atom_list (types);
for (l = atom_list, i = 0; l ; l = l->next, i++) for (l = atom_list, i = 0; l ; l = l->next, i++)
atoms[i] = GDK_POINTER_TO_ATOM (l->data); atoms[i] = GDK_POINTER_TO_ATOM (l->data);
g_list_free (atom_list);
selection_data->data = (guchar *)atoms; gtk_selection_data_set (selection_data,
selection_data->data[selection_data->length] = '\0'; GDK_SELECTION_TYPE_ATOM, 32,
(guchar *)atoms, length);
[pool release]; [pool release];
g_list_free (atom_list);
return selection_data; return selection_data;
} }
...@@ -905,6 +903,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard, ...@@ -905,6 +903,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
clipboard->selection); clipboard->selection);
[pool release]; [pool release];
return selection_data; return selection_data;
} }
......
...@@ -168,10 +168,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard, ...@@ -168,10 +168,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
{ {
const char *utf8_string = [s UTF8String]; const char *utf8_string = [s UTF8String];
selection_data->type = target; gtk_selection_data_set (selection_data,
selection_data->format = 8; target, 8,
selection_data->length = strlen (utf8_string); (guchar *)utf8_string, strlen (utf8_string));
selection_data->data = (guchar*) g_strdup (utf8_string);
} }
} }
else if (target == gdk_atom_intern_static_string ("application/x-color")) else if (target == gdk_atom_intern_static_string ("application/x-color"))
...@@ -243,12 +242,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard, ...@@ -243,12 +242,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
if (data) if (data)
{ {
selection_data->type = target; gtk_selection_data_set (selection_data,
selection_data->format = 8; target, 8,
selection_data->length = [data length]; [data bytes], [data length]);
selection_data->data = g_malloc (selection_data->length + 1);
selection_data->data[selection_data->length] = '\0';
memcpy(selection_data->data, [data bytes], selection_data->length);
} }
} }
...@@ -260,17 +256,26 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, ...@@ -260,17 +256,26 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
GtkSelectionData *selection_data) GtkSelectionData *selection_data)
{ {
NSString *type; NSString *type;
gchar *target = gdk_atom_name (selection_data->target); gchar *target;
GdkDisplay *display;
gint format;
const guchar *data;
guint length;
target = gdk_atom_name (gtk_selection_data_get_target (selection_data));
display = gtk_selection_data_get_display (selection_data);
format = gtk_selection_data_get_format (selection_data);
data = gtk_selection_data_get_data (selection_data, &length);
type = target_to_pasteboard_type (target); type = target_to_pasteboard_type (target);
g_free (target); g_free (target);
if ([type isEqualTo:NSStringPboardType]) if ([type isEqualTo:NSStringPboardType])
[pasteboard setString:[NSString stringWithUTF8String:(const char *)selection_data->data] [pasteboard setString:[NSString stringWithUTF8String:(const char *)data]
forType:type]; forType:type];
else if ([type isEqualTo:NSColorPboardType]) else if ([type isEqualTo:NSColorPboardType])
{ {
guint16 *color = (guint16 *)selection_data->data; guint16 *color = (guint16 *)data;
float red, green, blue, alpha; float red, green, blue, alpha;
NSColor *nscolor; NSColor *nscolor;
...@@ -287,11 +292,11 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, ...@@ -287,11 +292,11 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
gchar **list = NULL; gchar **list = NULL;
int count; int count;
count = gdk_text_property_to_utf8_list_for_display (selection_data->display, count = gdk_text_property_to_utf8_list_for_display (display,
gdk_atom_intern_static_string ("UTF8_STRING"), gdk_atom_intern_static_string ("UTF8_STRING"),
selection_data->format, format,
selection_data->data, data,
selection_data->length, length,
&list); &list);
if (count > 0) if (count > 0)
...@@ -310,8 +315,8 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, ...@@ -310,8 +315,8 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
g_strfreev (list); g_strfreev (list);
} }
else else
[pasteboard setData:[NSData dataWithBytesNoCopy:selection_data->data [pasteboard setData:[NSData dataWithBytesNoCopy:data
length:selection_data->length length:length
freeWhenDone:NO] freeWhenDone:NO]
forType:type]; forType:type];
} }
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