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.
21 * Modified by the GTK+ Team and others 1997-1999. 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/.
28 #include <X11/Xatom.h>
31 #include "gdkproperty.h"
32 #include "gdkselection.h"
33 #include "gdkprivate.h"
38 gdk_selection_owner_set (GdkWindow *owner,
48 GdkWindowPrivate *private;
50 private = (GdkWindowPrivate*) owner;
51 if (private->destroyed)
54 xdisplay = private->xdisplay;
55 xwindow = private->xwindow;
59 xdisplay = gdk_display;
63 XSetSelectionOwner (xdisplay, selection, xwindow, time);
65 return (XGetSelectionOwner (xdisplay, selection) == xwindow);
69 gdk_selection_owner_get (GdkAtom selection)
73 xwindow = XGetSelectionOwner (gdk_display, selection);
77 return gdk_window_lookup (xwindow);
81 gdk_selection_convert (GdkWindow *requestor,
86 GdkWindowPrivate *private;
88 g_return_if_fail (requestor != NULL);
90 private = (GdkWindowPrivate*) requestor;
91 if (private->destroyed)
94 XConvertSelection (private->xdisplay, selection, target,
95 gdk_selection_property, private->xwindow, time);
99 gdk_selection_property_get (GdkWindow *requestor,
104 GdkWindowPrivate *private;
112 g_return_val_if_fail (requestor != NULL, 0);
114 /* If retrieved chunks are typically small, (and the ICCCM says the
115 should be) it would be a win to try first with a buffer of
116 moderate length, to avoid two round trips to the server */
118 private = (GdkWindowPrivate*) requestor;
119 if (private->destroyed)
123 XGetWindowProperty (private->xdisplay, private->xwindow,
124 gdk_selection_property, 0, 0, False,
125 AnyPropertyType, &prop_type, &prop_format,
126 &nitems, &nbytes, &t);
129 *ret_type = prop_type;
131 *ret_format = prop_format;
133 if (prop_type == None)
145 /* Add on an extra byte to handle null termination. X guarantees
146 that t will be 1 longer than nbytes and null terminated */
149 /* We can't delete the selection here, because it might be the INCR
150 protocol, in which case the client has to make sure they'll be
151 notified of PropertyChange events _before_ the property is deleted.
152 Otherwise there's no guarantee we'll win the race ... */
153 XGetWindowProperty (private->xdisplay, private->xwindow,
154 gdk_selection_property, 0, (nbytes + 3) / 4, False,
155 AnyPropertyType, &prop_type, &prop_format,
156 &nitems, &nbytes, &t);
158 if (prop_type != None)
160 *data = g_new (guchar, length);
161 memcpy (*data, t, length);
175 gdk_selection_send_notify (guint32 requestor,
181 XSelectionEvent xevent;
183 xevent.type = SelectionNotify;
185 xevent.send_event = True;
186 xevent.display = gdk_display;
187 xevent.requestor = requestor;
188 xevent.selection = selection;
189 xevent.target = target;
190 xevent.property = property;
193 gdk_send_xevent (requestor, False, NoEventMask, (XEvent*) &xevent);
197 gdk_text_property_to_text_list (GdkAtom encoding, gint format,
198 guchar *text, gint length,
201 XTextProperty property;
208 property.value = text;
209 property.encoding = encoding;
210 property.format = format;
211 property.nitems = length;
212 res = XmbTextPropertyToTextList (GDK_DISPLAY(), &property, list, &count);
214 if (res == XNoMemory || res == XLocaleNotSupported ||
215 res == XConverterNotFound)
222 gdk_free_text_list (gchar **list)
224 g_return_if_fail (list != NULL);
226 XFreeStringList (list);
230 gdk_string_to_compound_text (gchar *str,
231 GdkAtom *encoding, gint *format,
232 guchar **ctext, gint *length)
235 XTextProperty property;
237 res = XmbTextListToTextProperty (GDK_DISPLAY(),
238 &str, 1, XCompoundTextStyle,
242 property.encoding = None;
243 property.format = None;
244 property.value = NULL;
249 *encoding = property.encoding;
251 *format = property.format;
253 *ctext = property.value;
255 *length = property.nitems;
260 void gdk_free_compound_text (guchar *ctext)