]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkselection-quartz.c
Implement selection related vfuncs for quartz
[~andy/gtk] / gdk / quartz / gdkselection-quartz.c
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
28 gboolean
29 _gdk_quartz_display_set_selection_owner_set (GdkDisplay *display,
30                                              GdkWindow  *owner,
31                                              GdkAtom     selection,
32                                              guint32     time,
33                                              gint        send_event)
34 {
35   /* FIXME: Implement */
36   return TRUE;
37 }
38
39 GdkWindow*
40 _gdk_quartz_display_get_selection_owner (GdkDisplay *display,
41                                          GdkAtom     selection)
42 {
43   /* FIXME: Implement */
44   return NULL;
45 }
46
47 void
48 _gdk_quartz_display_convert_selection (GdkDisplay *display,
49                                        GdkWindow  *requestor,
50                                        GdkAtom     selection,
51                                        GdkAtom     target,
52                                        guint32     time)
53 {
54   /* FIXME: Implement */
55 }
56
57 gint
58 _gdk_quartz_display_get_selection_property (GdkDisplay *display,
59                                             GdkWindow  *requestor,
60                                             guchar    **data,
61                                             GdkAtom    *ret_type,
62                                             gint       *ret_format)
63 {
64   /* FIXME: Implement */
65   return 0;
66 }
67
68 void
69 _gdk_quartz_display_send_selection_send_notify (GdkDisplay      *display,
70                                                 GdkNativeWindow  requestor,
71                                                 GdkAtom          selection,
72                                                 GdkAtom          target,
73                                                 GdkAtom          property,
74                                                 guint32          time)
75 {
76   /* FIXME: Implement */
77 }
78
79 gint
80 gdk_text_property_to_text_list_for_display (GdkDisplay   *display,
81                                             GdkAtom       encoding,
82                                             gint          format,
83                                             const guchar *text,
84                                             gint          length,
85                                             gchar      ***list)
86 {
87   /* FIXME: Implement */
88   return 0;
89 }
90
91 gint
92 gdk_string_to_compound_text_for_display (GdkDisplay  *display,
93                                          const gchar *str,
94                                          GdkAtom     *encoding,
95                                          gint        *format,
96                                          guchar     **ctext,
97                                          gint        *length)
98 {
99   /* FIXME: Implement */
100   return 0;
101 }
102
103 void gdk_free_compound_text (guchar *ctext)
104 {
105   /* FIXME: Implement */
106 }
107
108 gchar *
109 gdk_utf8_to_string_target (const gchar *str)
110 {
111   /* FIXME: Implement */
112   return NULL;
113 }
114
115 gboolean
116 gdk_utf8_to_compound_text_for_display (GdkDisplay  *display,
117                                        const gchar *str,
118                                        GdkAtom     *encoding,
119                                        gint        *format,
120                                        guchar     **ctext,
121                                        gint        *length)
122 {
123   /* FIXME: Implement */
124   return 0;
125 }
126
127 void
128 gdk_free_text_list (gchar **list)
129 {
130   g_return_if_fail (list != NULL);
131
132   g_free (*list);
133   g_free (list);
134 }
135
136 static gint
137 make_list (const gchar  *text,
138            gint          length,
139            gboolean      latin1,
140            gchar      ***list)
141 {
142   GSList *strings = NULL;
143   gint n_strings = 0;
144   gint i;
145   const gchar *p = text;
146   const gchar *q;
147   GSList *tmp_list;
148   GError *error = NULL;
149
150   while (p < text + length)
151     {
152       gchar *str;
153       
154       q = p;
155       while (*q && q < text + length)
156         q++;
157
158       if (latin1)
159         {
160           str = g_convert (p, q - p,
161                            "UTF-8", "ISO-8859-1",
162                            NULL, NULL, &error);
163
164           if (!str)
165             {
166               g_warning ("Error converting selection from STRING: %s",
167                          error->message);
168               g_error_free (error);
169             }
170         }
171       else
172         str = g_strndup (p, q - p);
173
174       if (str)
175         {
176           strings = g_slist_prepend (strings, str);
177           n_strings++;
178         }
179
180       p = q + 1;
181     }
182
183   if (list)
184     *list = g_new (gchar *, n_strings + 1);
185
186   (*list)[n_strings] = NULL;
187   
188   i = n_strings;
189   tmp_list = strings;
190   while (tmp_list)
191     {
192       if (list)
193         (*list)[--i] = tmp_list->data;
194       else
195         g_free (tmp_list->data);
196
197       tmp_list = tmp_list->next;
198     }
199
200   g_slist_free (strings);
201
202   return n_strings;
203 }
204
205 gint 
206 gdk_text_property_to_utf8_list_for_display (GdkDisplay    *display,
207                                             GdkAtom        encoding,
208                                             gint           format,
209                                             const guchar  *text,
210                                             gint           length,
211                                             gchar       ***list)
212 {
213   g_return_val_if_fail (text != NULL, 0);
214   g_return_val_if_fail (length >= 0, 0);
215
216   if (encoding == GDK_TARGET_STRING)
217     {
218       return make_list ((gchar *)text, length, TRUE, list);
219     }
220   else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING"))
221     {
222       return make_list ((gchar *)text, length, FALSE, list);
223     }
224   else
225     {
226       gchar *enc_name = gdk_atom_name (encoding);
227
228       g_warning ("gdk_text_property_to_utf8_list_for_display: encoding %s not handled\n", enc_name);
229       g_free (enc_name);
230
231       if (list)
232         *list = NULL;
233
234       return 0;
235     }
236 }
237