Debian Codegraph @

gdk/quartz/gdkselection-quartz.c

raw
1 /* gdkselection-quartz.c
2 *
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Copyright (C) 1998-2002 Tor Lillqvist
5 * Copyright (C) 2005 Imendio AB
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 #include "config.h"
24
25 #include "gdkselection.h"
26 #include "gdkproperty.h"
27 #include "gdkquartz.h"
28
29 gboolean
30 gdk_selection_owner_set_for_display (GdkDisplay *display,
31 GdkWindow *owner,
32 GdkAtom selection,
33 guint32 time,
34 gint send_event)
35 {
36 /* FIXME: Implement */
37 return TRUE;
38 }
39
40 GdkWindow*
41 gdk_selection_owner_get_for_display (GdkDisplay *display,
42 GdkAtom selection)
43 {
44 /* FIXME: Implement */
45 return NULL;
46 }
47
48 void
49 gdk_selection_convert (GdkWindow *requestor,
50 GdkAtom selection,
51 GdkAtom target,
52 guint32 time)
53 {
54 /* FIXME: Implement */
55 }
56
57 gint
58 gdk_selection_property_get (GdkWindow *requestor,
59 guchar **data,
60 GdkAtom *ret_type,
61 gint *ret_format)
62 {
63 /* FIXME: Implement */
64 return 0;
65 }
66
67 void
68 gdk_selection_send_notify_for_display (GdkDisplay *display,
69 GdkNativeWindow requestor,
70 GdkAtom selection,
71 GdkAtom target,
72 GdkAtom property,
73 guint32 time)
74 {
75 /* FIXME: Implement */
76 }
77
78 gint
79 gdk_text_property_to_text_list_for_display (GdkDisplay *display,
80 GdkAtom encoding,
81 gint format,
82 const guchar *text,
83 gint length,
84 gchar ***list)
85 {
86 /* FIXME: Implement */
87 return 0;
88 }
89
90 gint
91 gdk_string_to_compound_text_for_display (GdkDisplay *display,
92 const gchar *str,
93 GdkAtom *encoding,
94 gint *format,
95 guchar **ctext,
96 gint *length)
97 {
98 /* FIXME: Implement */
99 return 0;
100 }
101
102 void gdk_free_compound_text (guchar *ctext)
103 {
104 /* FIXME: Implement */
105 }
106
107 gchar *
108 gdk_utf8_to_string_target (const gchar *str)
109 {
110 /* FIXME: Implement */
111 return NULL;
112 }
113
114 gboolean
115 gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
116 const gchar *str,
117 GdkAtom *encoding,
118 gint *format,
119 guchar **ctext,
120 gint *length)
121 {
122 /* FIXME: Implement */
123 return 0;
124 }
125
126 void
127 gdk_free_text_list (gchar **list)
128 {
129 g_return_if_fail (list != NULL);
130
131 g_free (*list);
132 g_free (list);
133 }
134
135 static gint
136 make_list (const gchar *text,
137 gint length,
138 gboolean latin1,
139 gchar ***list)
140 {
141 GSList *strings = NULL;
142 gint n_strings = 0;
143 gint i;
144 const gchar *p = text;
145 const gchar *q;
146 GSList *tmp_list;
147 GError *error = NULL;
148
149 while (p < text + length)
150 {
151 gchar *str;
152
153 q = p;
154 while (*q && q < text + length)
155 q++;
156
157 if (latin1)
158 {
159 str = g_convert (p, q - p,
160 "UTF-8", "ISO-8859-1",
161 NULL, NULL, &error);
162
163 if (!str)
164 {
165 g_warning ("Error converting selection from STRING: %s",
166 error->message);
167 g_error_free (error);
168 }
169 }
170 else
171 str = g_strndup (p, q - p);
172
173 if (str)
174 {
175 strings = g_slist_prepend (strings, str);
176 n_strings++;
177 }
178
179 p = q + 1;
180 }
181
182 if (list)
183 *list = g_new0 (gchar *, n_strings + 1);
184
185 i = n_strings;
186 tmp_list = strings;
187 while (tmp_list)
188 {
189 if (list)
190 (*list)[--i] = tmp_list->data;
191 else
192 g_free (tmp_list->data);
193
194 tmp_list = tmp_list->next;
195 }
196
197 g_slist_free (strings);
198
199 return n_strings;
200 }
201
202 gint
203 gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
204 GdkAtom encoding,
205 gint format,
206 const guchar *text,
207 gint length,
208 gchar ***list)
209 {
210 g_return_val_if_fail (text != NULL, 0);
211 g_return_val_if_fail (length >= 0, 0);
212
213 if (encoding == GDK_TARGET_STRING)
214 {
215 return make_list ((gchar *)text, length, TRUE, list);
216 }
217 else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING"))
218 {
219 return make_list ((gchar *)text, length, FALSE, list);
220 }
221 else
222 {
223 gchar *enc_name = gdk_atom_name (encoding);
224
225 g_warning ("gdk_text_property_to_utf8_list_for_display: encoding %s not handled\n", enc_name);
226 g_free (enc_name);
227
228 if (list)
229 *list = NULL;
230
231 return 0;
232 }
233 }
234
235 GdkAtom
236 gdk_quartz_pasteboard_type_to_atom_libgtk_only (NSString *type)
237 {
238 if ([type isEqualToString:NSStringPboardType])
239 return gdk_atom_intern_static_string ("UTF8_STRING");
240 else if ([type isEqualToString:NSTIFFPboardType])
241 return gdk_atom_intern_static_string ("image/tiff");
242 else if ([type isEqualToString:NSColorPboardType])
243 return gdk_atom_intern_static_string ("application/x-color");
244 else if ([type isEqualToString:NSURLPboardType])
245 return gdk_atom_intern_static_string ("text/uri-list");
246 else
247 return gdk_atom_intern ([type UTF8String], FALSE);
248 }
249
250 NSString *
251 gdk_quartz_target_to_pasteboard_type_libgtk_only (const char *target)
252 {
253 if (strcmp (target, "UTF8_STRING") == 0)
254 return NSStringPboardType;
255 else if (strcmp (target, "image/tiff") == 0)
256 return NSTIFFPboardType;
257 else if (strcmp (target, "application/x-color") == 0)
258 return NSColorPboardType;
259 else if (strcmp (target, "text/uri-list") == 0)
260 return NSURLPboardType;
261 else
262 return [NSString stringWithUTF8String:target];
263 }
264
265 NSString *
266 gdk_quartz_atom_to_pasteboard_type_libgtk_only (GdkAtom atom)
267 {
268 gchar *target = gdk_atom_name (atom);
269 NSString *ret = gdk_quartz_target_to_pasteboard_type_libgtk_only (target);
270 g_free (target);
271
272 return ret;
273 }