]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkselection-quartz.c
Merge branch 'win32-theme2'
[~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 (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 gchar *
69 _gdk_quartz_display_utf8_to_string_target (GdkDisplay  *display,
70                                            const gchar *str)
71 {
72   /* FIXME: Implement */
73   return NULL;
74 }
75
76 static gint
77 make_list (const gchar  *text,
78            gint          length,
79            gboolean      latin1,
80            gchar      ***list)
81 {
82   GSList *strings = NULL;
83   gint n_strings = 0;
84   gint i;
85   const gchar *p = text;
86   const gchar *q;
87   GSList *tmp_list;
88   GError *error = NULL;
89
90   while (p < text + length)
91     {
92       gchar *str;
93       
94       q = p;
95       while (*q && q < text + length)
96         q++;
97
98       if (latin1)
99         {
100           str = g_convert (p, q - p,
101                            "UTF-8", "ISO-8859-1",
102                            NULL, NULL, &error);
103
104           if (!str)
105             {
106               g_warning ("Error converting selection from STRING: %s",
107                          error->message);
108               g_error_free (error);
109             }
110         }
111       else
112         str = g_strndup (p, q - p);
113
114       if (str)
115         {
116           strings = g_slist_prepend (strings, str);
117           n_strings++;
118         }
119
120       p = q + 1;
121     }
122
123   if (list)
124     *list = g_new0 (gchar *, n_strings + 1);
125
126   i = n_strings;
127   tmp_list = strings;
128   while (tmp_list)
129     {
130       if (list)
131         (*list)[--i] = tmp_list->data;
132       else
133         g_free (tmp_list->data);
134
135       tmp_list = tmp_list->next;
136     }
137
138   g_slist_free (strings);
139
140   return n_strings;
141 }
142
143 gint
144 _gdk_quartz_display_text_property_to_utf8_list (GdkDisplay    *display,
145                                                 GdkAtom        encoding,
146                                                 gint           format,
147                                                 const guchar  *text,
148                                                 gint           length,
149                                                 gchar       ***list)
150 {
151   g_return_val_if_fail (text != NULL, 0);
152   g_return_val_if_fail (length >= 0, 0);
153
154   if (encoding == GDK_TARGET_STRING)
155     {
156       return make_list ((gchar *)text, length, TRUE, list);
157     }
158   else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING"))
159     {
160       return make_list ((gchar *)text, length, FALSE, list);
161     }
162   else
163     {
164       gchar *enc_name = gdk_atom_name (encoding);
165
166       g_warning ("gdk_text_property_to_utf8_list_for_display: encoding %s not handled\n", enc_name);
167       g_free (enc_name);
168
169       if (list)
170         *list = NULL;
171
172       return 0;
173     }
174 }
175