2 * Copyright (C) 1998 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 /* Target side drag signals */
27 static const char * drag_icon_xpm[] = {
38 " .....................",
39 " ..&&&&&&&&&&&&&&&&&&&.",
40 " ...&&&&&&&&&&&&&&&&&&&.",
41 " ..&.&&&&&&&&&&&&&&&&&&&.",
42 " ..&&.&&&&&&&&&&&&&&&&&&&.",
43 " ..&&&.&&&&&&&&&&&&&&&&&&&.",
44 " ..&&&&.&&&&&&&&&&&&&&&&&&&.",
45 " ..&&&&&.&&&@&&&&&&&&&&&&&&&.",
46 " ..&&&&&&.*$%$+$&&&&&&&&&&&&&.",
47 " ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.",
48 " ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.",
49 " ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.",
50 " ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.",
51 " ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
52 " ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
53 "................&$@&&&@&&&&&&&&&&&&.",
54 ".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.",
55 ".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.",
56 ".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.",
57 ".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.",
58 ".&&&&&&&&&&&&&&&&&&&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&&&&&&&&&&&&&&&&.",
84 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
85 "...................................."};
88 static const char * trashcan_closed_xpm[] = {
129 " ==......=$$...=== ",
130 " ..$------)+++++++++++++@$$... ",
131 " ..=@@-------&+++++++++++++++++++-.... ",
132 " =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$ ",
133 " .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&.. ",
134 " $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@ ",
135 " .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$ ",
136 " +------++++++++++++++++++++++++++++++;;%%%;;##*!. ",
137 " =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>). ",
138 " .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@. ",
139 " =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%== ",
140 " .&....=-+++++%;;####''''''''''##'%%%)..#. ",
141 " .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!. ",
142 " .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!. ",
143 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
144 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
145 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
146 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
147 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
148 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
149 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
150 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
151 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
152 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
153 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
154 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
155 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
156 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
157 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
158 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
159 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
160 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
161 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
162 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
163 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
164 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
165 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
166 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
167 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
168 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
169 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
170 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
171 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
172 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
173 " =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
174 " $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
175 " =.++++++++++++++!++++!++++!+++!++.= ",
176 " $..+++++++++++++++!++++++...$ ",
177 " $$=.............=$$ ",
189 static const char * trashcan_open_xpm[] = {
217 " $,-+)+++%%;;'#+. ",
218 " =---+++++;%%%;%##@. ",
219 " @)++++++++;%%%%'#%$ ",
220 " $&++++++++++;%%;%##@= ",
221 " ,-++++)+++++++;;;'#%) ",
222 " @+++&&--&)++++;;%'#'-. ",
223 " ,&++-@@,,,,-)++;;;'>'+, ",
224 " =-++&@$@&&&&-&+;;;%##%+@ ",
225 " =,)+)-,@@&+++++;;;;%##%&@ ",
226 " @--&&,,@&)++++++;;;;'#)@ ",
227 " ---&)-,@)+++++++;;;%''+, ",
228 " $--&)+&$-+++++++;;;%%'';- ",
229 " .,-&+++-$&++++++;;;%''%&= ",
230 " $,-&)++)-@++++++;;%''%), ",
231 " =,@&)++++&&+++++;%'''+$@&++++++ ",
232 " .$@-++++++++++++;'#';,........=$@&++++ ",
233 " =$@@&)+++++++++++'##-.................=&++ ",
234 " .$$@-&)+++++++++;%#+$.....................=)+ ",
235 " $$,@-)+++++++++;%;@=........................,+ ",
236 " .$$@@-++++++++)-)@=............................ ",
237 " $,@---)++++&)@===............................,. ",
238 " $-@---&)))-$$=..............................=)!. ",
239 " --&-&&,,$=,==...........................=&+++!. ",
240 " =,=$..=$+)+++++&@$=.............=$@&+++++!++!. ",
241 " .)-++-+++++++++++++++++++++++++++!++!++!. ",
242 " .+-++-+++++++++++++++++++++++!+++!++!++!. ",
243 " .+-++-+++-+++++++++!+++!!++++!+++!++!++!. ",
244 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
245 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
246 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
247 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
248 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
249 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
250 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
251 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
252 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
253 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
254 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
255 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
256 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
257 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
258 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
259 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
260 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
261 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
262 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
263 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
264 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
265 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
266 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
267 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
268 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
269 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
270 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
271 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
272 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
273 " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
274 " =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
275 " $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
276 " =.++++++++++++++!++++!++++!+++!++.= ",
277 " $..+++++++++++++++!++++++...$ ",
278 " $$==...........==$$ ",
289 GdkPixbuf *trashcan_open;
290 GdkPixbuf *trashcan_closed;
299 static GtkTargetEntry target_table[] = {
300 { "STRING", 0, TARGET_STRING },
301 { "text/plain", 0, TARGET_STRING },
302 { "application/x-rootwindow-drop", 0, TARGET_ROOTWIN }
305 static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
308 target_drag_leave (GtkWidget *widget,
309 GdkDragContext *context,
314 gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
318 target_drag_motion (GtkWidget *widget,
319 GdkDragContext *context,
324 GtkWidget *source_widget;
330 gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open);
333 source_widget = gtk_drag_get_source_widget (context);
334 g_print ("motion, source %s\n", source_widget ?
335 G_OBJECT_TYPE_NAME (source_widget) :
338 tmp_list = context->targets;
341 char *name = gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data));
342 g_print ("%s\n", name);
345 tmp_list = tmp_list->next;
348 gdk_drag_status (context, context->suggested_action, time);
353 target_drag_drop (GtkWidget *widget,
354 GdkDragContext *context,
362 gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
364 if (context->targets)
366 gtk_drag_get_data (widget, context,
367 GDK_POINTER_TO_ATOM (context->targets->data),
376 target_drag_data_received (GtkWidget *widget,
377 GdkDragContext *context,
380 GtkSelectionData *selection_data,
384 if (gtk_selection_data_get_length (selection_data) >= 0 &&
385 gtk_selection_data_get_format (selection_data) == 8)
387 g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data));
388 gtk_drag_finish (context, TRUE, FALSE, time);
392 gtk_drag_finish (context, FALSE, FALSE, time);
396 label_drag_data_received (GtkWidget *widget,
397 GdkDragContext *context,
400 GtkSelectionData *selection_data,
404 if (gtk_selection_data_get_length (selection_data) >= 0 &&
405 gtk_selection_data_get_format (selection_data) == 8)
407 g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data));
408 gtk_drag_finish (context, TRUE, FALSE, time);
412 gtk_drag_finish (context, FALSE, FALSE, time);
416 source_drag_data_get (GtkWidget *widget,
417 GdkDragContext *context,
418 GtkSelectionData *selection_data,
423 if (info == TARGET_ROOTWIN)
424 g_print ("I was dropped on the rootwin\n");
426 gtk_selection_data_set (selection_data,
427 gtk_selection_data_get_target (selection_data),
428 8, (guchar *) "I'm Data!", 9);
431 /* The following is a rather elaborate example demonstrating/testing
432 * changing of the window hierarchy during a drag - in this case,
433 * via a "spring-loaded" popup window.
435 static GtkWidget *popup_window = NULL;
437 static gboolean popped_up = FALSE;
438 static gboolean in_popup = FALSE;
439 static guint popdown_timer = 0;
440 static guint popup_timer = 0;
443 popdown_cb (gpointer data)
447 gtk_widget_hide (popup_window);
454 popup_motion (GtkWidget *widget,
455 GdkDragContext *context,
465 g_print ("removed popdown\n");
466 g_source_remove (popdown_timer);
475 popup_leave (GtkWidget *widget,
476 GdkDragContext *context,
484 g_print ("added popdown\n");
485 popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL);
491 popup_cb (gpointer data)
501 popup_window = gtk_window_new (GTK_WINDOW_POPUP);
502 gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
504 table = gtk_table_new (3,3, FALSE);
510 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
511 button = gtk_button_new_with_label (buffer);
512 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
513 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
516 gtk_drag_dest_set (button,
517 GTK_DEST_DEFAULT_ALL,
518 target_table, n_targets - 1, /* no rootwin */
519 GDK_ACTION_COPY | GDK_ACTION_MOVE);
520 g_signal_connect (button, "drag_motion",
521 G_CALLBACK (popup_motion), NULL);
522 g_signal_connect (button, "drag_leave",
523 G_CALLBACK (popup_leave), NULL);
526 gtk_widget_show_all (table);
527 gtk_container_add (GTK_CONTAINER (popup_window), table);
530 gtk_widget_show (popup_window);
534 popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL);
535 g_print ("added popdown\n");
543 popsite_motion (GtkWidget *widget,
544 GdkDragContext *context,
550 popup_timer = gdk_threads_add_timeout (500, popup_cb, NULL);
556 popsite_leave (GtkWidget *widget,
557 GdkDragContext *context,
562 g_source_remove (popup_timer);
568 source_drag_data_delete (GtkWidget *widget,
569 GdkDragContext *context,
572 g_print ("Delete the data!\n");
578 if (g_file_test ("../gdk-pixbuf/libpixbufloader-pnm.la",
581 g_setenv ("GDK_PIXBUF_MODULE_FILE", "../gdk-pixbuf/loaders.cache", TRUE);
582 g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/immodules.cache", TRUE);
587 main (int argc, char **argv)
594 GdkPixbuf *drag_icon;
598 gtk_init (&argc, &argv);
600 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
601 g_signal_connect (window, "destroy",
602 G_CALLBACK (gtk_main_quit), NULL);
605 table = gtk_table_new (2, 2, FALSE);
606 gtk_container_add (GTK_CONTAINER (window), table);
608 drag_icon = gdk_pixbuf_new_from_xpm_data (drag_icon_xpm);
609 trashcan_open = gdk_pixbuf_new_from_xpm_data (trashcan_open_xpm);
610 trashcan_closed = gdk_pixbuf_new_from_xpm_data (trashcan_closed_xpm);
612 label = gtk_label_new ("Drop Here\n");
614 gtk_drag_dest_set (label,
615 GTK_DEST_DEFAULT_ALL,
616 target_table, n_targets - 1, /* no rootwin */
617 GDK_ACTION_COPY | GDK_ACTION_MOVE);
619 g_signal_connect (label, "drag_data_received",
620 G_CALLBACK( label_drag_data_received), NULL);
622 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
623 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
626 label = gtk_label_new ("Popup\n");
628 gtk_drag_dest_set (label,
629 GTK_DEST_DEFAULT_ALL,
630 target_table, n_targets - 1, /* no rootwin */
631 GDK_ACTION_COPY | GDK_ACTION_MOVE);
633 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
634 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
637 g_signal_connect (label, "drag_motion",
638 G_CALLBACK (popsite_motion), NULL);
639 g_signal_connect (label, "drag_leave",
640 G_CALLBACK (popsite_leave), NULL);
642 pixmap = gtk_image_new_from_pixbuf (trashcan_closed);
643 gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
644 gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
645 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
648 g_signal_connect (pixmap, "drag_leave",
649 G_CALLBACK (target_drag_leave), NULL);
651 g_signal_connect (pixmap, "drag_motion",
652 G_CALLBACK (target_drag_motion), NULL);
654 g_signal_connect (pixmap, "drag_drop",
655 G_CALLBACK (target_drag_drop), NULL);
657 g_signal_connect (pixmap, "drag_data_received",
658 G_CALLBACK (target_drag_data_received), NULL);
662 button = gtk_button_new_with_label ("Drag Here\n");
664 gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
665 target_table, n_targets,
666 GDK_ACTION_COPY | GDK_ACTION_MOVE);
667 gtk_drag_source_set_icon_pixbuf (button, drag_icon);
669 g_object_unref (drag_icon);
671 gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
672 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
675 g_signal_connect (button, "drag_data_get",
676 G_CALLBACK (source_drag_data_get), NULL);
677 g_signal_connect (button, "drag_data_delete",
678 G_CALLBACK (source_drag_data_delete), NULL);
680 gtk_widget_show_all (window);