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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gdkproperty.h"
31 #include "gdkselection.h"
32 #include "gdkprivate.h"
33 #include "gdkprivate-fb.h"
36 typedef struct _OwnerInfo OwnerInfo;
46 /* When a window is destroyed we check if it is the owner
47 * of any selections. This is somewhat inefficient, but
48 * owner_list is typically short, and it is a low memory,
52 _gdk_selection_window_destroyed (GdkWindow *window)
54 GSList *tmp_list = owner_list;
57 OwnerInfo *info = tmp_list->data;
58 tmp_list = tmp_list->next;
60 if (info->owner == window)
62 owner_list = g_slist_remove (owner_list, info);
69 gdk_selection_owner_set_for_display (GdkDisplay *display,
78 tmp_list = owner_list;
81 info = tmp_list->data;
82 if (info->selection == selection)
84 owner_list = g_slist_remove (owner_list, info);
88 tmp_list = tmp_list->next;
93 info = g_new (OwnerInfo, 1);
95 info->selection = selection;
97 owner_list = g_slist_prepend (owner_list, info);
104 gdk_selection_owner_get_for_display (GdkDisplay *display,
110 tmp_list = owner_list;
113 info = tmp_list->data;
114 if (info->selection == selection)
118 tmp_list = tmp_list->next;
124 gdk_selection_convert (GdkWindow *requestor,
131 GdkWindow *event_window;
133 owner = gdk_selection_owner_get (selection);
137 event_window = gdk_fb_other_event_window (owner, GDK_SELECTION_REQUEST);
140 event = gdk_event_make (event_window, GDK_SELECTION_REQUEST, TRUE);
141 event->selection.requestor = requestor;
142 event->selection.selection = selection;
143 event->selection.target = target;
144 event->selection.property = _gdk_selection_property;
149 /* If no owner for the specified selection exists, the X server
150 * generates a SelectionNotify event to the requestor with property None.
152 gdk_selection_send_notify ((guint32)requestor,
161 gdk_selection_property_get (GdkWindow *requestor,
171 g_return_val_if_fail (requestor != NULL, 0);
172 g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
174 if (!gdk_property_get (requestor,
175 _gdk_selection_property,
176 0/*AnyPropertyType?*/,
179 &prop_type, &prop_format, &prop_len,
187 *ret_type = prop_type;
189 *ret_format = prop_format;
191 if (!gdk_property_get (requestor,
192 _gdk_selection_property,
193 0/*AnyPropertyType?*/,
196 &prop_type, &prop_format, &prop_len,
210 gdk_selection_send_notify_for_display (GdkDisplay *display,
218 GdkWindow *event_window;
220 event_window = gdk_fb_other_event_window (gdk_window_lookup ((GdkNativeWindow) requestor), GDK_SELECTION_NOTIFY);
223 event = gdk_event_make (event_window, GDK_SELECTION_NOTIFY, TRUE);
224 event->selection.selection = selection;
225 event->selection.target = target;
226 event->selection.property = property;
227 event->selection.requestor = (GdkNativeWindow) requestor;
232 gdk_text_property_to_text_list_for_display (GdkDisplay *display,
239 g_warning ("gdk_text_property_to_text_list() not implemented\n");
244 gdk_free_text_list (gchar **list)
246 g_return_if_fail (list != NULL);
247 g_warning ("gdk_free_text_list() not implemented\n");
251 gdk_string_to_compound_text_for_display (GdkDisplay *display,
258 g_warning ("gdk_string_to_compound_text() not implemented\n");
262 void gdk_free_compound_text (guchar *ctext)
264 g_warning ("gdk_free_compound_text() not implemented\n");
268 gdk_utf8_to_string_target (const gchar *str)
270 g_warning ("gdk_utf8_to_string_target() not implemented\n");
275 gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
282 g_warning ("gdk_utf8_to_compound_text() not implemented\n");
287 make_list (const gchar *text,
292 GSList *strings = NULL;
295 const gchar *p = text;
298 GError *error = NULL;
300 while (p < text + length)
305 while (*q && q < text + length)
310 str = g_convert (p, q - p,
311 "UTF-8", "ISO-8859-1",
316 g_warning ("Error converting selection from STRING: %s",
318 g_error_free (error);
322 str = g_strndup (p, q - p);
326 strings = g_slist_prepend (strings, str);
334 *list = g_new (gchar *, n_strings + 1);
336 (*list)[n_strings] = NULL;
343 (*list)[--i] = tmp_list->data;
345 g_free (tmp_list->data);
347 tmp_list = tmp_list->next;
350 g_slist_free (strings);
357 gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
364 g_return_val_if_fail (text != NULL, 0);
365 g_return_val_if_fail (length >= 0, 0);
367 if (encoding == GDK_TARGET_STRING)
369 return make_list ((gchar *)text, length, TRUE, list);
371 else if (encoding == gdk_atom_intern ("UTF8_STRING", FALSE))
373 return make_list ((gchar *)text, length, FALSE, list);
380 const gchar *charset = NULL;
381 gboolean need_conversion = !g_get_charset (&charset);
383 GError *error = NULL;
385 /* Probably COMPOUND text, we fall back to Xlib routines
387 local_count = gdk_text_property_to_text_list (encoding,
393 *list = g_new (gchar *, local_count + 1);
395 for (i = 0; i < local_count; i++)
397 /* list contains stuff in our default encoding
401 gchar *utf = g_convert (local_list[i], -1,
407 (*list)[count++] = utf;
413 g_warning ("Error converting to UTF-8 from '%s': %s",
414 charset, error->message);
415 g_error_free (error);
422 (*list)[count++] = g_strdup (local_list[i]);
426 gdk_free_text_list (local_list);
427 (*list)[count] = NULL;