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/.
34 /* We emulate the GDK_SELECTION window properties by storing
35 * it's data in a per-window hashtable.
45 static GHashTable *sel_prop_table = NULL;
48 gdk_selection_init (void)
50 if (sel_prop_table == NULL)
51 sel_prop_table = g_hash_table_new (g_int_hash, g_int_equal);
55 gdk_sel_prop_store (GdkWindow *owner,
61 GdkWindowPrivate *private = (GdkWindowPrivate *) owner;
64 prop = g_hash_table_lookup (sel_prop_table, &private->xwindow);
68 g_hash_table_remove (sel_prop_table, &private->xwindow);
70 prop = g_new (GdkSelProp, 1);
72 prop->length = length;
73 prop->format = format;
75 g_hash_table_insert (sel_prop_table, &private->xwindow, prop);
80 gdk_selection_owner_set (GdkWindow *owner,
85 GdkWindowPrivate *private;
89 private = (GdkWindowPrivate *) owner;
92 (sel_name = gdk_atom_name (selection),
93 g_print ("gdk_selection_owner_set: %#x %#x (%s)\n",
94 (private ? private->xwindow : 0),
98 if (selection != gdk_clipboard_atom)
102 xwindow = private->xwindow;
106 if (!OpenClipboard (xwindow))
108 g_warning ("gdk_selection_owner_set: OpenClipboard failed");
111 if (!EmptyClipboard ())
113 g_warning ("gdk_selection_owner_set: EmptyClipboard failed");
118 /* No delayed rendering */
120 SetClipboardData (CF_TEXT, NULL);
122 if (!CloseClipboard ())
124 g_warning ("gdk_selection_owner_set: CloseClipboard failed");
129 /* Send ourselves an ersatz selection request message so that
130 * gdk_property_change will be called to store the clipboard data.
132 SendMessage (private->xwindow, gdk_selection_request_msg,
140 gdk_selection_owner_get (GdkAtom selection)
143 GdkWindowPrivate *private;
146 if (selection != gdk_clipboard_atom)
149 window = gdk_window_lookup (GetClipboardOwner ());
151 private = (GdkWindowPrivate *) window;
154 (sel_name = gdk_atom_name (selection),
155 g_print ("gdk_selection_owner_get: %#x (%s) = %#x\n",
157 (private ? private->xwindow : 0)),
164 gdk_selection_convert (GdkWindow *requestor,
169 GdkWindowPrivate *private;
172 guchar *ptr, *data, *datap, *p;
173 guint i, length, slength;
174 gchar *sel_name, *tgt_name;
176 g_return_if_fail (requestor != NULL);
178 private = (GdkWindowPrivate*) requestor;
181 (sel_name = gdk_atom_name (selection),
182 tgt_name = gdk_atom_name (target),
183 g_print ("gdk_selection_convert: %#x %#x (%s) %#x (%s)\n",
184 private->xwindow, selection, sel_name, target, tgt_name),
188 if (selection == gdk_clipboard_atom)
190 /* Converting the CLIPBOARD selection means he wants the
191 * contents of the clipboard. Get the clipboard data,
192 * and store it for later.
194 if (!OpenClipboard (private->xwindow))
196 g_warning ("gdk_selection_convert: OpenClipboard failed");
200 if ((hdata = GetClipboardData (CF_TEXT)) != NULL)
202 if ((ptr = GlobalLock (hdata)) != NULL)
204 length = GlobalSize (hdata);
206 GDK_NOTE (SELECTION, g_print ("...got data: %d bytes: %.10s\n",
211 for (i = 0; i < length; i++)
220 data = datap = g_malloc (slength + 1);
222 for (i = 0; i < length; i++)
231 gdk_sel_prop_store (requestor, GDK_TARGET_STRING, 8,
232 data, strlen (data) + 1);
234 GlobalUnlock (hdata);
240 /* Send ourselves an ersatz selection notify message so that we actually
243 SendMessage (private->xwindow, gdk_selection_notify_msg, selection, target);
245 else if (selection == gdk_win32_dropfiles_atom)
247 /* This means he wants the names of the dropped files.
248 * gdk_dropfiles_filter already has stored the text/uri-list
249 * data, tempoarily on gdk_root_parent's selection "property".
253 prop = g_hash_table_lookup (sel_prop_table, &gdk_root_parent.xwindow);
257 g_hash_table_remove (sel_prop_table, &gdk_root_parent.xwindow);
258 gdk_sel_prop_store (requestor, prop->type, prop->format,
259 prop->data, prop->length);
261 SendMessage (private->xwindow, gdk_selection_notify_msg, selection, target);
266 g_warning ("gdk_selection_convert: General case not implemented");
271 gdk_selection_property_get (GdkWindow *requestor,
276 GdkWindowPrivate *private;
279 g_return_val_if_fail (requestor != NULL, 0);
281 private = (GdkWindowPrivate*) requestor;
282 if (private->destroyed)
285 GDK_NOTE (SELECTION, g_print ("gdk_selection_property_get: %#x\n",
288 prop = g_hash_table_lookup (sel_prop_table, &private->xwindow);
295 *data = g_malloc (prop->length);
296 if (prop->length > 0)
297 memmove (*data, prop->data, prop->length);
299 *ret_type = prop->type;
301 *ret_format = prop->format;
307 gdk_selection_property_delete (GdkWindowPrivate *private)
311 prop = g_hash_table_lookup (sel_prop_table, &private->xwindow);
315 g_hash_table_remove (sel_prop_table, &private->xwindow);
322 gdk_selection_send_notify (guint32 requestor,
328 gchar *sel_name, *tgt_name, *prop_name;
331 (sel_name = gdk_atom_name (selection),
332 tgt_name = gdk_atom_name (target),
333 prop_name = gdk_atom_name (property),
334 g_print ("gdk_selection_send_notify: %#x %#x (%s) %#x (%s) %#x (%s)\n",
338 property, prop_name),
341 g_free (prop_name)));
343 /* Send ourselves a selection clear message sot that gtk thinks we doen't
344 * have the selection, and will claim it anew when needed, and
345 * we thus get a chance to store data in the Windows clipboard.
346 * Otherwise, if a gtkeditable does a copy to clipboard several times
347 * only the first one actually gets copied to the Windows clipboard,
348 * as only he first one causes a call to gdk_property_change.
351 SendMessage ((HWND) requestor, gdk_selection_clear_msg, selection, 0);
355 gdk_text_property_to_text_list (GdkAtom encoding,
362 g_print ("gdk_text_property_to_text_list not implemented\n"));
368 gdk_free_text_list (gchar **list)
370 g_return_if_fail (list != NULL);
376 gdk_string_to_compound_text (gchar *str,
382 g_warning ("gdk_string_to_compound_text: Not implemented");
388 gdk_free_compound_text (guchar *ctext)
390 g_warning ("gdk_free_compound_text: Not implemented");