1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gdkselection.h"
29 #include "gdkproperty.h"
30 #include "gdkprivate.h"
31 #include "gdkprivate-broadway.h"
32 #include "gdkdisplay-broadway.h"
37 typedef struct _OwnerInfo OwnerInfo;
46 static GSList *owner_list;
48 /* When a window is destroyed we check if it is the owner
49 * of any selections. This is somewhat inefficient, but
50 * owner_list is typically short, and it is a low memory,
54 _gdk_broadway_selection_window_destroyed (GdkWindow *window)
56 GSList *tmp_list = owner_list;
59 OwnerInfo *info = tmp_list->data;
60 tmp_list = tmp_list->next;
62 if (info->owner == window)
64 owner_list = g_slist_remove (owner_list, info);
71 _gdk_broadway_display_set_selection_owner (GdkDisplay *display,
80 if (gdk_display_is_closed (display))
83 tmp_list = owner_list;
86 info = tmp_list->data;
87 if (info->selection == selection)
89 owner_list = g_slist_remove (owner_list, info);
93 tmp_list = tmp_list->next;
98 info = g_new (OwnerInfo, 1);
100 info->serial = _gdk_display_get_next_serial (display);
102 info->selection = selection;
104 owner_list = g_slist_prepend (owner_list, info);
111 _gdk_broadway_display_get_selection_owner (GdkDisplay *display,
117 if (gdk_display_is_closed (display))
120 tmp_list = owner_list;
123 info = tmp_list->data;
124 if (info->selection == selection)
126 tmp_list = tmp_list->next;
133 _gdk_broadway_display_convert_selection (GdkDisplay *display,
134 GdkWindow *requestor,
139 g_warning ("convert_selection not implemented\n");
143 _gdk_broadway_display_get_selection_property (GdkDisplay *display,
144 GdkWindow *requestor,
150 *ret_type = GDK_NONE;
156 g_warning ("get_selection_property not implemented\n");
162 _gdk_broadway_display_send_selection_notify (GdkDisplay *display,
163 GdkWindow *requestor,
169 g_return_if_fail (GDK_IS_DISPLAY (display));
171 g_warning ("send_selection_notify not implemented\n");
176 make_list (const gchar *text,
181 GSList *strings = NULL;
184 const gchar *p = text;
187 GError *error = NULL;
189 while (p < text + length)
194 while (*q && q < text + length)
199 str = g_convert (p, q - p,
200 "UTF-8", "ISO-8859-1",
205 g_warning ("Error converting selection from STRING: %s",
207 g_error_free (error);
212 str = g_strndup (p, q - p);
213 if (!g_utf8_validate (str, -1, NULL))
215 g_warning ("Error converting selection from UTF8_STRING");
223 strings = g_slist_prepend (strings, str);
232 *list = g_new (gchar *, n_strings + 1);
233 (*list)[n_strings] = NULL;
241 (*list)[--i] = tmp_list->data;
243 g_free (tmp_list->data);
245 tmp_list = tmp_list->next;
248 g_slist_free (strings);
254 _gdk_broadway_display_text_property_to_utf8_list (GdkDisplay *display,
261 g_return_val_if_fail (text != NULL, 0);
262 g_return_val_if_fail (length >= 0, 0);
263 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
265 if (encoding == GDK_TARGET_STRING)
267 return make_list ((gchar *)text, length, TRUE, list);
269 else if (encoding == gdk_atom_intern_static_string ("UTF8_STRING"))
271 return make_list ((gchar *)text, length, FALSE, list);
280 _gdk_broadway_display_utf8_to_string_target (GdkDisplay *display,
283 return g_strdup (str);