]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkselection-quartz.c
Change FSF Address
[~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, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "config.h"
22
23 #include "gdkselection.h"
24 #include "gdkproperty.h"
25
26 gboolean
27 _gdk_quartz_display_set_selection_owner (GdkDisplay *display,
28                                          GdkWindow  *owner,
29                                          GdkAtom     selection,
30                                          guint32     time,
31                                          gint        send_event)
32 {
33   /* FIXME: Implement */
34   return TRUE;
35 }
36
37 GdkWindow*
38 _gdk_quartz_display_get_selection_owner (GdkDisplay *display,
39                                          GdkAtom     selection)
40 {
41   /* FIXME: Implement */
42   return NULL;
43 }
44
45 void
46 _gdk_quartz_display_convert_selection (GdkDisplay *display,
47                                        GdkWindow  *requestor,
48                                        GdkAtom     selection,
49                                        GdkAtom     target,
50                                        guint32     time)
51 {
52   /* FIXME: Implement */
53 }
54
55 gint
56 _gdk_quartz_display_get_selection_property (GdkDisplay *display,
57                                             GdkWindow  *requestor,
58                                             guchar    **data,
59                                             GdkAtom    *ret_type,
60                                             gint       *ret_format)
61 {
62   /* FIXME: Implement */
63   return 0;
64 }
65
66 gchar *
67 _gdk_quartz_display_utf8_to_string_target (GdkDisplay  *display,
68                                            const gchar *str)
69 {
70   /* FIXME: Implement */
71   return NULL;
72 }
73
74 static gint
75 make_list (const gchar  *text,
76            gint          length,
77            gboolean      latin1,
78            gchar      ***list)
79 {
80   GSList *strings = NULL;
81   gint n_strings = 0;
82   gint i;
83   const gchar *p = text;
84   const gchar *q;
85   GSList *tmp_list;
86   GError *error = NULL;
87
88   while (p < text + length)
89     {
90       gchar *str;
91       
92       q = p;
93       while (*q && q < text + length)
94         q++;
95
96       if (latin1)
97         {
98           str = g_convert (p, q - p,
99                            "UTF-8", "ISO-8859-1",
100                            NULL, NULL, &error);
101
102           if (!str)
103             {
104               g_warning ("Error converting selection from STRING: %s",
105                          error->message);
106               g_error_free (error);
107             }
108         }
109       else
110         str = g_strndup (p, q - p);
111
112       if (str)
113         {
114           strings = g_slist_prepend (strings, str);
115           n_strings++;
116         }
117
118       p = q + 1;
119     }
120
121   if (list)
122     *list = g_new0 (gchar *, n_strings + 1);
123
124   i = n_strings;
125   tmp_list = strings;
126   while (tmp_list)
127     {
128       if (list)
129         (*list)[--i] = tmp_list->data;
130       else
131         g_free (tmp_list->data);
132
133       tmp_list = tmp_list->next;
134     }
135
136   g_slist_free (strings);
137
138   return n_strings;
139 }
140
141 gint
142 _gdk_quartz_display_text_property_to_utf8_list (GdkDisplay    *display,
143                                                 GdkAtom        encoding,
144                                                 gint           format,
145                                                 const guchar  *text,
146                                                 gint           length,
147                                                 gchar       ***list)
148 {
149   g_return_val_if_fail (text != NULL, 0);
150   g_return_val_if_fail (length >= 0, 0);
151
152   if (encoding == GDK_TARGET_STRING)
153     {
154       return make_list ((gchar *)text, length, TRUE, list);
155     }
156   else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING"))
157     {
158       return make_list ((gchar *)text, length, FALSE, list);
159     }
160   else
161     {
162       gchar *enc_name = gdk_atom_name (encoding);
163
164       g_warning ("gdk_text_property_to_utf8_list_for_display: encoding %s not handled\n", enc_name);
165       g_free (enc_name);
166
167       if (list)
168         *list = NULL;
169
170       return 0;
171     }
172 }
173