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.
26 * GTK+ DirectFB backend
27 * Copyright (C) 2001-2002 convergence integrated media GmbH
28 * Copyright (C) 2002-2004 convergence GmbH
29 * Written by Denis Oliver Kropp <dok@convergence.de> and
30 * Sven Neumann <sven@convergence.de>
37 #include "gdkdirectfb.h"
38 #include "gdkprivate-directfb.h"
40 #include "gdkproperty.h"
41 #include "gdkselection.h"
42 #include "gdkprivate.h"
45 typedef struct _OwnerInfo OwnerInfo;
53 GSList *owner_list = NULL;
55 /* When a window is destroyed we check if it is the owner
56 * of any selections. This is somewhat inefficient, but
57 * owner_list is typically short, and it is a low memory,
61 _gdk_selection_window_destroyed (GdkWindow *window)
63 GSList *tmp_list = owner_list;
67 OwnerInfo *info = tmp_list->data;
69 tmp_list = tmp_list->next;
71 if (info->owner == window)
73 owner_list = g_slist_remove (owner_list, info);
80 gdk_selection_owner_set_for_display (GdkDisplay *display,
89 tmp_list = owner_list;
92 info = tmp_list->data;
93 if (info->selection == selection)
95 owner_list = g_slist_remove (owner_list, info);
99 tmp_list = tmp_list->next;
104 info = g_new (OwnerInfo, 1);
106 info->selection = selection;
108 owner_list = g_slist_prepend (owner_list, info);
115 gdk_selection_owner_get_for_display (GdkDisplay *display,
121 tmp_list = owner_list;
124 info = tmp_list->data;
125 if (info->selection == selection)
129 tmp_list = tmp_list->next;
135 gdk_selection_convert (GdkWindow *requestor,
142 GdkWindow *event_window;
144 owner = gdk_selection_owner_get (selection);
148 event_window = gdk_directfb_other_event_window (owner,
149 GDK_SELECTION_REQUEST);
152 event = gdk_directfb_event_make (event_window,
153 GDK_SELECTION_REQUEST);
154 event->selection.requestor = GDK_WINDOW_DFB_ID (requestor);
155 event->selection.selection = selection;
156 event->selection.target = target;
157 event->selection.property = _gdk_selection_property;
162 /* If no owner for the specified selection exists, the X server
163 * generates a SelectionNotify event to the requestor with property None.
165 gdk_selection_send_notify (GDK_WINDOW_DFB_ID (requestor),
174 gdk_selection_property_get (GdkWindow *requestor,
184 g_return_val_if_fail (requestor != NULL, 0);
185 g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
187 if (!gdk_property_get (requestor,
188 _gdk_selection_property,
189 0/*AnyPropertyType?*/,
192 &prop_type, &prop_format, &prop_len,
200 *ret_type = prop_type;
202 *ret_format = prop_format;
204 if (!gdk_property_get (requestor,
205 _gdk_selection_property,
206 0/*AnyPropertyType?*/,
209 &prop_type, &prop_format, &prop_len,
223 gdk_selection_send_notify_for_display (GdkDisplay *display,
231 GdkWindow *event_window;
233 event_window = gdk_window_lookup ((GdkNativeWindow) requestor);
238 event_window = gdk_directfb_other_event_window (event_window,
239 GDK_SELECTION_NOTIFY);
243 event = gdk_directfb_event_make (event_window, GDK_SELECTION_NOTIFY);
244 event->selection.selection = selection;
245 event->selection.target = target;
246 event->selection.property = property;
247 event->selection.requestor = (GdkNativeWindow) requestor;
252 gdk_text_property_to_text_list_for_display (GdkDisplay *display,
259 g_warning ("gdk_text_property_to_text_list() not implemented\n");
264 gdk_free_text_list (gchar **list)
266 g_return_if_fail (list != NULL);
267 g_warning ("gdk_free_text_list() not implemented\n");
271 gdk_string_to_compound_text_for_display (GdkDisplay *display,
278 g_warning ("gdk_string_to_compound_text() not implemented\n");
283 gdk_free_compound_text (guchar *ctext)
285 g_warning ("gdk_free_compound_text() not implemented\n");
289 * gdk_utf8_to_string_target:
290 * @str: a UTF-8 string
292 * Convert an UTF-8 string into the best possible representation
293 * as a STRING. The representation of characters not in STRING
294 * is not specified; it may be as pseudo-escape sequences
295 * \x{ABCD}, or it may be in some other form of approximation.
297 * Return value: the newly allocated string, or %NULL if the
298 * conversion failed. (It should not fail for
299 * any properly formed UTF-8 string.)
302 gdk_utf8_to_string_target (const gchar *str)
304 g_warning ("gdk_utf8_to_string_target() not implemented\n");
309 * gdk_utf8_to_compound_text:
310 * @str: a UTF-8 string
311 * @encoding: location to store resulting encoding
312 * @format: location to store format of the result
313 * @ctext: location to store the data of the result
314 * @length: location to store the length of the data
317 * Convert from UTF-8 to compound text.
319 * Return value: %TRUE if the conversion succeeded, otherwise
323 gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
330 g_warning ("gdk_utf8_to_compound_text() not implemented\n");
335 make_list (const gchar *text,
340 GSList *strings = NULL;
343 const gchar *p = text;
346 GError *error = NULL;
348 while (p < text + length)
353 while (*q && q < text + length)
358 str = g_convert (p, q - p,
359 "UTF-8", "ISO-8859-1",
364 g_warning ("Error converting selection from STRING: %s",
366 g_error_free (error);
370 str = g_strndup (p, q - p);
374 strings = g_slist_prepend (strings, str);
382 *list = g_new (gchar *, n_strings + 1);
384 (*list)[n_strings] = NULL;
391 (*list)[--i] = tmp_list->data;
393 g_free (tmp_list->data);
395 tmp_list = tmp_list->next;
398 g_slist_free (strings);
405 * gdk_text_property_to_utf8_list:
406 * @encoding: an atom representing the encoding of the text
407 * @format: the format of the property
408 * @text: the text to convert
409 * @length: the length of @text, in bytes
410 * @list: location to store the list of strings or %NULL. The
411 * list should be freed with g_strfreev().
413 * Convert a text property in the giving encoding to
414 * a list of UTF-8 strings.
416 * Return value: the number of strings in the resulting
420 gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
427 g_return_val_if_fail (text != NULL, 0);
428 g_return_val_if_fail (length >= 0, 0);
430 if (encoding == GDK_TARGET_STRING)
432 return make_list ((gchar *)text, length, TRUE, list);
434 else if (encoding == gdk_atom_intern ("UTF8_STRING", FALSE))
436 return make_list ((gchar *)text, length, FALSE, list);
443 const gchar *charset = NULL;
444 gboolean need_conversion = !g_get_charset (&charset);
446 GError *error = NULL;
448 /* Probably COMPOUND text, we fall back to Xlib routines
450 local_count = gdk_text_property_to_text_list (encoding,
456 *list = g_new (gchar *, local_count + 1);
458 for (i = 0; i < local_count; i++)
460 /* list contains stuff in our default encoding
464 gchar *utf = g_convert (local_list[i], -1,
470 (*list)[count++] = utf;
476 g_warning ("Error converting to UTF-8 from '%s': %s",
477 charset, error->message);
478 g_error_free (error);
485 (*list)[count++] = g_strdup (local_list[i]);
489 gdk_free_text_list (local_list);
490 (*list)[count] = NULL;