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
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <X11/Xatom.h>
23 #include "gdkprivate.h"
28 gdk_selection_owner_set (GdkWindow *owner,
38 GdkWindowPrivate *private;
40 private = (GdkWindowPrivate*) owner;
41 if (private->destroyed)
44 xdisplay = private->xdisplay;
45 xwindow = private->xwindow;
49 xdisplay = gdk_display;
53 XSetSelectionOwner (xdisplay, selection, xwindow, time);
55 return (XGetSelectionOwner (xdisplay, selection) == xwindow);
59 gdk_selection_owner_get (GdkAtom selection)
63 xwindow = XGetSelectionOwner (gdk_display, selection);
67 return gdk_window_lookup (xwindow);
71 gdk_selection_convert (GdkWindow *requestor,
76 GdkWindowPrivate *private;
78 g_return_if_fail (requestor != NULL);
80 private = (GdkWindowPrivate*) requestor;
81 if (private->destroyed)
84 XConvertSelection (private->xdisplay, selection, target,
85 gdk_selection_property, private->xwindow, time);
89 gdk_selection_property_get (GdkWindow *requestor,
94 GdkWindowPrivate *private;
102 g_return_val_if_fail (requestor != NULL, 0);
104 /* If retrieved chunks are typically small, (and the ICCM says the
105 should be) it would be a win to try first with a buffer of
106 moderate length, to avoid two round trips to the server */
108 private = (GdkWindowPrivate*) requestor;
109 if (private->destroyed)
113 XGetWindowProperty (private->xdisplay, private->xwindow,
114 gdk_selection_property, 0, 0, False,
115 AnyPropertyType, &prop_type, &prop_format,
116 &nitems, &nbytes, &t);
119 *ret_type = prop_type;
121 *ret_format = prop_format;
123 if (prop_type == None)
135 /* Add on an extra byte to handle null termination. X guarantees
136 that t will be 1 longer than nbytes and null terminated */
139 /* We can't delete the selection here, because it might be the INCR
140 protocol, in which case the client has to make sure they'll be
141 notified of PropertyChange events _before_ the property is deleted.
142 Otherwise there's no guarantee we'll win the race ... */
143 XGetWindowProperty (private->xdisplay, private->xwindow,
144 gdk_selection_property, 0, (nbytes + 3) / 4, False,
145 AnyPropertyType, &prop_type, &prop_format,
146 &nitems, &nbytes, &t);
148 if (prop_type != None)
150 *data = g_new (guchar, length);
151 memcpy (*data, t, length);
165 gdk_selection_send_notify (guint32 requestor,
171 XSelectionEvent xevent;
173 xevent.type = SelectionNotify;
175 xevent.send_event = True;
176 xevent.display = gdk_display;
177 xevent.requestor = requestor;
178 xevent.selection = selection;
179 xevent.target = target;
180 xevent.property = property;
183 XSendEvent (gdk_display, requestor, False, NoEventMask, (XEvent*) &xevent);
187 gdk_text_property_to_text_list (GdkAtom encoding, gint format,
188 guchar *text, gint length,
191 XTextProperty property;
198 property.value = text;
199 property.encoding = encoding;
200 property.format = format;
201 property.nitems = length;
202 res = XmbTextPropertyToTextList (GDK_DISPLAY(), &property, list, &count);
204 if (res == XNoMemory || res == XLocaleNotSupported ||
205 res == XConverterNotFound)
212 gdk_free_text_list (gchar **list)
214 g_return_if_fail (list != NULL);
216 XFreeStringList (list);
220 gdk_string_to_compound_text (gchar *str,
221 GdkAtom *encoding, gint *format,
222 guchar **ctext, gint *length)
225 XTextProperty property;
227 res = XmbTextListToTextProperty (GDK_DISPLAY(),
228 &str, 1, XCompoundTextStyle,
232 property.encoding = None;
233 property.format = None;
234 property.value = NULL;
239 *encoding = property.encoding;
241 *format = property.format;
243 *ctext = property.value;
245 *length = property.nitems;
250 void gdk_free_compound_text (guchar *ctext)