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 if (GDK_DRAWABLE_DESTROYED (owner))
51 xdisplay = GDK_DRAWABLE_XDISPLAY (owner);
52 xwindow = GDK_DRAWABLE_XID (owner);
56 xdisplay = gdk_display;
60 XSetSelectionOwner (xdisplay, selection, xwindow, time);
62 return (XGetSelectionOwner (xdisplay, selection) == xwindow);
66 gdk_selection_owner_get (GdkAtom selection)
70 xwindow = XGetSelectionOwner (gdk_display, selection);
74 return gdk_window_lookup (xwindow);
78 gdk_selection_convert (GdkWindow *requestor,
83 if (GDK_DRAWABLE_DESTROYED (requestor))
86 XConvertSelection (GDK_DRAWABLE_XDISPLAY (requestor), selection, target,
87 gdk_selection_property, GDK_DRAWABLE_XID (requestor), time);
91 gdk_selection_property_get (GdkWindow *requestor,
103 g_return_val_if_fail (requestor != NULL, 0);
104 g_return_val_if_fail (GDK_IS_WINDOW (requestor), 0);
106 /* If retrieved chunks are typically small, (and the ICCCM says the
107 should be) it would be a win to try first with a buffer of
108 moderate length, to avoid two round trips to the server */
110 if (GDK_DRAWABLE_DESTROYED (requestor))
114 XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (requestor),
115 GDK_DRAWABLE_XID (requestor),
116 gdk_selection_property, 0, 0, False,
117 AnyPropertyType, &prop_type, &prop_format,
118 &nitems, &nbytes, &t);
121 *ret_type = prop_type;
123 *ret_format = prop_format;
125 if (prop_type == None)
137 /* Add on an extra byte to handle null termination. X guarantees
138 that t will be 1 longer than nbytes and null terminated */
141 /* We can't delete the selection here, because it might be the INCR
142 protocol, in which case the client has to make sure they'll be
143 notified of PropertyChange events _before_ the property is deleted.
144 Otherwise there's no guarantee we'll win the race ... */
145 XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (requestor),
146 GDK_DRAWABLE_XID (requestor),
147 gdk_selection_property, 0, (nbytes + 3) / 4, False,
148 AnyPropertyType, &prop_type, &prop_format,
149 &nitems, &nbytes, &t);
151 if (prop_type != None)
153 *data = g_new (guchar, length);
154 memcpy (*data, t, length);
168 gdk_selection_send_notify (guint32 requestor,
174 XSelectionEvent xevent;
176 xevent.type = SelectionNotify;
178 xevent.send_event = True;
179 xevent.display = gdk_display;
180 xevent.requestor = requestor;
181 xevent.selection = selection;
182 xevent.target = target;
183 xevent.property = property;
186 gdk_send_xevent (requestor, False, NoEventMask, (XEvent*) &xevent);
190 gdk_text_property_to_text_list (GdkAtom encoding, gint format,
191 guchar *text, gint length,
194 XTextProperty property;
201 property.value = text;
202 property.encoding = encoding;
203 property.format = format;
204 property.nitems = length;
205 res = XmbTextPropertyToTextList (GDK_DISPLAY(), &property, list, &count);
207 if (res == XNoMemory || res == XLocaleNotSupported ||
208 res == XConverterNotFound)
215 gdk_free_text_list (gchar **list)
217 g_return_if_fail (list != NULL);
219 XFreeStringList (list);
223 gdk_string_to_compound_text (gchar *str,
224 GdkAtom *encoding, gint *format,
225 guchar **ctext, gint *length)
228 XTextProperty property;
230 res = XmbTextListToTextProperty (GDK_DISPLAY(),
231 &str, 1, XCompoundTextStyle,
235 property.encoding = None;
236 property.format = None;
237 property.value = NULL;
242 *encoding = property.encoding;
244 *format = property.format;
246 *ctext = property.value;
248 *length = property.nitems;
253 void gdk_free_compound_text (guchar *ctext)