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"
46
typedef struct _OwnerInfo OwnerInfo;
54
GSList *owner_list = NULL;
56
/* When a window is destroyed we check if it is the owner
57
* of any selections. This is somewhat inefficient, but
58
* owner_list is typically short, and it is a low memory,
62
_gdk_selection_window_destroyed (GdkWindow *window)
64
GSList *tmp_list = owner_list;
68
OwnerInfo *info = tmp_list->data;
70
tmp_list = tmp_list->next;
72
if (info->owner == window)
74
owner_list = g_slist_remove (owner_list, info);
81
gdk_selection_owner_set_for_display (GdkDisplay *display,
90
tmp_list = owner_list;
93
info = tmp_list->data;
94
if (info->selection == selection)
96
owner_list = g_slist_remove (owner_list, info);
100
tmp_list = tmp_list->next;
105
info = g_new (OwnerInfo, 1);
107
info->selection = selection;
109
owner_list = g_slist_prepend (owner_list, info);
116
gdk_selection_owner_get_for_display (GdkDisplay *display,
122
tmp_list = owner_list;
125
info = tmp_list->data;
126
if (info->selection == selection)
130
tmp_list = tmp_list->next;
136
gdk_selection_convert (GdkWindow *requestor,
143
GdkWindow *event_window;
145
owner = gdk_selection_owner_get (selection);
149
event_window = gdk_directfb_other_event_window (owner,
150
GDK_SELECTION_REQUEST);
153
event = gdk_directfb_event_make (event_window,
154
GDK_SELECTION_REQUEST);
155
event->selection.requestor = GDK_WINDOW_DFB_ID (requestor);
156
event->selection.selection = selection;
157
event->selection.target = target;
158
event->selection.property = _gdk_selection_property;
163
/* If no owner for the specified selection exists, the X server
164
* generates a SelectionNotify event to the requestor with property None.
166
gdk_selection_send_notify (GDK_WINDOW_DFB_ID (requestor),
175
gdk_selection_property_get (GdkWindow *requestor,
185
g_return_val_if_fail (requestor != NULL, 0);
186
g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
188
if (!gdk_property_get (requestor,
189
_gdk_selection_property,
190
0/*AnyPropertyType?*/,
193
&prop_type, &prop_format, &prop_len,
201
*ret_type = prop_type;
203
*ret_format = prop_format;
205
if (!gdk_property_get (requestor,
206
_gdk_selection_property,
207
0/*AnyPropertyType?*/,
210
&prop_type, &prop_format, &prop_len,
224
gdk_selection_send_notify_for_display (GdkDisplay *display,
232
GdkWindow *event_window;
234
event_window = gdk_window_lookup ((GdkNativeWindow) requestor);
239
event_window = gdk_directfb_other_event_window (event_window,
240
GDK_SELECTION_NOTIFY);
244
event = gdk_directfb_event_make (event_window, GDK_SELECTION_NOTIFY);
245
event->selection.selection = selection;
246
event->selection.target = target;
247
event->selection.property = property;
248
event->selection.requestor = (GdkNativeWindow) requestor;
253
gdk_text_property_to_text_list_for_display (GdkDisplay *display,
260
g_warning ("gdk_text_property_to_text_list() not implemented\n");
265
gdk_free_text_list (gchar **list)
267
g_return_if_fail (list != NULL);
268
g_warning ("gdk_free_text_list() not implemented\n");
272
gdk_string_to_compound_text_for_display (GdkDisplay *display,
279
g_warning ("gdk_string_to_compound_text() not implemented\n");
284
gdk_free_compound_text (guchar *ctext)
286
g_warning ("gdk_free_compound_text() not implemented\n");
290
* gdk_utf8_to_string_target:
291
* @str: a UTF-8 string
293
* Convert an UTF-8 string into the best possible representation
294
* as a STRING. The representation of characters not in STRING
295
* is not specified; it may be as pseudo-escape sequences
296
* \x{ABCD}, or it may be in some other form of approximation.
298
* Return value: the newly allocated string, or %NULL if the
299
* conversion failed. (It should not fail for
300
* any properly formed UTF-8 string.)
303
gdk_utf8_to_string_target (const gchar *str)
305
g_warning ("gdk_utf8_to_string_target() not implemented\n");
310
* gdk_utf8_to_compound_text:
311
* @str: a UTF-8 string
312
* @encoding: location to store resulting encoding
313
* @format: location to store format of the result
314
* @ctext: location to store the data of the result
315
* @length: location to store the length of the data
318
* Convert from UTF-8 to compound text.
320
* Return value: %TRUE if the conversion succeeded, otherwise
324
gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
331
g_warning ("gdk_utf8_to_compound_text() not implemented\n");
336
make_list (const gchar *text,
341
GSList *strings = NULL;
344
const gchar *p = text;
347
GError *error = NULL;
349
while (p < text + length)
354
while (*q && q < text + length)
359
str = g_convert (p, q - p,
360
"UTF-8", "ISO-8859-1",
365
g_warning ("Error converting selection from STRING: %s",
367
g_error_free (error);
371
str = g_strndup (p, q - p);
375
strings = g_slist_prepend (strings, str);
383
*list = g_new (gchar *, n_strings + 1);
385
(*list)[n_strings] = NULL;
392
(*list)[--i] = tmp_list->data;
394
g_free (tmp_list->data);
396
tmp_list = tmp_list->next;
399
g_slist_free (strings);
406
* gdk_text_property_to_utf8_list:
407
* @encoding: an atom representing the encoding of the text
408
* @format: the format of the property
409
* @text: the text to convert
410
* @length: the length of @text, in bytes
411
* @list: location to store the list of strings or %NULL. The
412
* list should be freed with g_strfreev().
414
* Convert a text property in the giving encoding to
415
* a list of UTF-8 strings.
417
* Return value: the number of strings in the resulting
421
gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
428
g_return_val_if_fail (text != NULL, 0);
429
g_return_val_if_fail (length >= 0, 0);
431
if (encoding == GDK_TARGET_STRING)
433
return make_list ((gchar *)text, length, TRUE, list);
435
else if (encoding == gdk_atom_intern ("UTF8_STRING", FALSE))
437
return make_list ((gchar *)text, length, FALSE, list);
444
const gchar *charset = NULL;
445
gboolean need_conversion = !g_get_charset (&charset);
447
GError *error = NULL;
449
/* Probably COMPOUND text, we fall back to Xlib routines
451
local_count = gdk_text_property_to_text_list (encoding,
457
*list = g_new (gchar *, local_count + 1);
459
for (i = 0; i < local_count; i++)
461
/* list contains stuff in our default encoding
465
gchar *utf = g_convert (local_list[i], -1,
471
(*list)[count++] = utf;
477
g_warning ("Error converting to UTF-8 from '%s': %s",
478
charset, error->message);
479
g_error_free (error);
486
(*list)[count++] = g_strdup (local_list[i]);
490
gdk_free_text_list (local_list);
491
(*list)[count] = NULL;
497
#define __GDK_SELECTION_X11_C__
498
#include "gdkaliasdef.c"