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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <X11/Xatom.h>
22 #include "gdkprivate.h"
27 gdk_selection_owner_set (GdkWindow *owner,
32 GdkWindowPrivate *private;
38 private = (GdkWindowPrivate*) owner;
39 xdisplay = private->xdisplay;
40 xwindow = private->xwindow;
44 xdisplay = gdk_display;
48 XSetSelectionOwner (xdisplay, selection, xwindow, time);
50 return (XGetSelectionOwner (xdisplay, selection) == xwindow);
54 gdk_selection_owner_get (GdkAtom selection)
58 xwindow = XGetSelectionOwner (gdk_display, selection);
62 return gdk_window_lookup (xwindow);
66 gdk_selection_convert (GdkWindow *requestor,
71 GdkWindowPrivate *private;
73 g_return_if_fail (requestor != NULL);
75 private = (GdkWindowPrivate*) requestor;
77 XConvertSelection (private->xdisplay, selection, target,
78 gdk_selection_property, private->xwindow, time);
82 gdk_selection_property_get (GdkWindow *requestor,
87 GdkWindowPrivate *private;
95 g_return_val_if_fail (requestor != NULL, 0);
97 /* If retrieved chunks are typically small, (and the ICCM says the
98 should be) it would be a win to try first with a buffer of
99 moderate length, to avoid two round trips to the server */
101 private = (GdkWindowPrivate*) requestor;
103 XGetWindowProperty (private->xdisplay, private->xwindow,
104 gdk_selection_property, 0, 0, False,
105 AnyPropertyType, &prop_type, &prop_format,
106 &nitems, &nbytes, &t);
109 *ret_type = prop_type;
111 *ret_format = prop_format;
113 if (prop_type == None)
121 /* Add on an extra byte to handle null termination. X guarantees
122 that t will be 1 longer than nbytes and null terminated */
125 /* We can't delete the selection here, because it might be the INCR
126 protocol, in which case the client has to make sure they'll be
127 notified of PropertyChange events _before_ the property is deleted.
128 Otherwise there's no guarantee we'll win the race ... */
129 XGetWindowProperty (private->xdisplay, private->xwindow,
130 gdk_selection_property, 0, (nbytes + 3) / 4, False,
131 AnyPropertyType, &prop_type, &prop_format,
132 &nitems, &nbytes, &t);
134 if (prop_type != None)
136 *data = g_new (guchar, length);
137 memcpy (*data, t, length);
150 gdk_selection_send_notify (guint32 requestor,
156 XSelectionEvent xevent;
158 xevent.type = SelectionNotify;
160 xevent.send_event = True;
161 xevent.display = gdk_display;
162 xevent.requestor = requestor;
163 xevent.selection = selection;
164 xevent.target = target;
165 xevent.property = property;
168 XSendEvent (gdk_display, requestor, False, NoEventMask, (XEvent*) &xevent);
172 gdk_text_property_to_text_list (GdkAtom encoding, gint format,
173 guchar *text, gint length,
176 XTextProperty property;
183 property.value = text;
184 property.encoding = encoding;
185 property.format = format;
186 property.nitems = length;
187 res = XmbTextPropertyToTextList (GDK_DISPLAY(), &property, list, &count);
189 if (res == XNoMemory || res == XLocaleNotSupported ||
190 res == XConverterNotFound)
197 gdk_free_text_list (gchar **list)
199 XFreeStringList (list);
203 gdk_string_to_compound_text (gchar *str,
204 GdkAtom *encoding, gint *format,
205 guchar **ctext, gint *length)
208 XTextProperty property;
210 res = XmbTextListToTextProperty (GDK_DISPLAY(),
211 &str, 1, XCompoundTextStyle,
215 property.encoding = None;
216 property.format = None;
217 property.value = NULL;
222 *encoding = property.encoding;
224 *format = property.format;
226 *ctext = property.value;
228 *length = property.nitems;
233 void gdk_free_compound_text (guchar *ctext)