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 = gdk_drag_context_list_targets (context);
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, gdk_drag_context_get_suggested_action (context), time);
354 target_drag_drop (GtkWidget *widget,
355 GdkDragContext *context,
363 gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
365 if (gdk_drag_context_list_targets (context))
367 gtk_drag_get_data (widget, context,
368 GDK_POINTER_TO_ATOM (gdk_drag_context_list_targets (context)->data),
377 target_drag_data_received (GtkWidget *widget,
378 GdkDragContext *context,
381 GtkSelectionData *selection_data,
385 if (gtk_selection_data_get_length (selection_data) >= 0 &&
386 gtk_selection_data_get_format (selection_data) == 8)
388 g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data));
389 gtk_drag_finish (context, TRUE, FALSE, time);
393 gtk_drag_finish (context, FALSE, FALSE, time);
397 label_drag_data_received (GtkWidget *widget,
398 GdkDragContext *context,
401 GtkSelectionData *selection_data,
405 if (gtk_selection_data_get_length (selection_data) >= 0 &&
406 gtk_selection_data_get_format (selection_data) == 8)
408 g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data));
409 gtk_drag_finish (context, TRUE, FALSE, time);
413 gtk_drag_finish (context, FALSE, FALSE, time);
417 source_drag_data_get (GtkWidget *widget,
418 GdkDragContext *context,
419 GtkSelectionData *selection_data,
424 if (info == TARGET_ROOTWIN)
425 g_print ("I was dropped on the rootwin\n");
427 gtk_selection_data_set (selection_data,
428 gtk_selection_data_get_target (selection_data),
429 8, (guchar *) "I'm Data!", 9);
432 /* The following is a rather elaborate example demonstrating/testing
433 * changing of the window hierarchy during a drag - in this case,
434 * via a "spring-loaded" popup window.
436 static GtkWidget *popup_window = NULL;
438 static gboolean popped_up = FALSE;
439 static gboolean in_popup = FALSE;
440 static guint popdown_timer = 0;
441 static guint popup_timer = 0;
444 popdown_cb (gpointer data)
448 gtk_widget_hide (popup_window);
455 popup_motion (GtkWidget *widget,
456 GdkDragContext *context,
466 g_print ("removed popdown\n");
467 g_source_remove (popdown_timer);
476 popup_leave (GtkWidget *widget,
477 GdkDragContext *context,
485 g_print ("added popdown\n");
486 popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL);
492 popup_cb (gpointer data)
502 popup_window = gtk_window_new (GTK_WINDOW_POPUP);
503 gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
505 table = gtk_table_new (3,3, FALSE);
511 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
512 button = gtk_button_new_with_label (buffer);
513 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
514 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
517 gtk_drag_dest_set (button,
518 GTK_DEST_DEFAULT_ALL,
519 target_table, n_targets - 1, /* no rootwin */
520 GDK_ACTION_COPY | GDK_ACTION_MOVE);
521 g_signal_connect (button, "drag_motion",
522 G_CALLBACK (popup_motion), NULL);
523 g_signal_connect (button, "drag_leave",
524 G_CALLBACK (popup_leave), NULL);
527 gtk_widget_show_all (table);
528 gtk_container_add (GTK_CONTAINER (popup_window), table);
531 gtk_widget_show (popup_window);
535 popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL);
536 g_print ("added popdown\n");
544 popsite_motion (GtkWidget *widget,
545 GdkDragContext *context,
551 popup_timer = gdk_threads_add_timeout (500, popup_cb, NULL);
557 popsite_leave (GtkWidget *widget,
558 GdkDragContext *context,
563 g_source_remove (popup_timer);
569 source_drag_data_delete (GtkWidget *widget,
570 GdkDragContext *context,
573 g_print ("Delete the data!\n");
579 if (g_file_test ("../modules/input/immodules.cache", G_FILE_TEST_EXISTS))
580 g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/immodules.cache", TRUE);
584 main (int argc, char **argv)
591 GdkPixbuf *drag_icon;
595 gtk_init (&argc, &argv);
597 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
598 g_signal_connect (window, "destroy",
599 G_CALLBACK (gtk_main_quit), NULL);
602 table = gtk_table_new (2, 2, FALSE);
603 gtk_container_add (GTK_CONTAINER (window), table);
605 drag_icon = gdk_pixbuf_new_from_xpm_data (drag_icon_xpm);
606 trashcan_open = gdk_pixbuf_new_from_xpm_data (trashcan_open_xpm);
607 trashcan_closed = gdk_pixbuf_new_from_xpm_data (trashcan_closed_xpm);
609 label = gtk_label_new ("Drop Here\n");
611 gtk_drag_dest_set (label,
612 GTK_DEST_DEFAULT_ALL,
613 target_table, n_targets - 1, /* no rootwin */
614 GDK_ACTION_COPY | GDK_ACTION_MOVE);
616 g_signal_connect (label, "drag_data_received",
617 G_CALLBACK( label_drag_data_received), NULL);
619 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
620 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
623 label = gtk_label_new ("Popup\n");
625 gtk_drag_dest_set (label,
626 GTK_DEST_DEFAULT_ALL,
627 target_table, n_targets - 1, /* no rootwin */
628 GDK_ACTION_COPY | GDK_ACTION_MOVE);
630 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
631 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
634 g_signal_connect (label, "drag_motion",
635 G_CALLBACK (popsite_motion), NULL);
636 g_signal_connect (label, "drag_leave",
637 G_CALLBACK (popsite_leave), NULL);
639 pixmap = gtk_image_new_from_pixbuf (trashcan_closed);
640 gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
641 gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
642 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
645 g_signal_connect (pixmap, "drag_leave",
646 G_CALLBACK (target_drag_leave), NULL);
648 g_signal_connect (pixmap, "drag_motion",
649 G_CALLBACK (target_drag_motion), NULL);
651 g_signal_connect (pixmap, "drag_drop",
652 G_CALLBACK (target_drag_drop), NULL);
654 g_signal_connect (pixmap, "drag_data_received",
655 G_CALLBACK (target_drag_data_received), NULL);
659 button = gtk_button_new_with_label ("Drag Here\n");
661 gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
662 target_table, n_targets,
663 GDK_ACTION_COPY | GDK_ACTION_MOVE);
664 gtk_drag_source_set_icon_pixbuf (button, drag_icon);
666 g_object_unref (drag_icon);
668 gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
669 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
672 g_signal_connect (button, "drag_data_get",
673 G_CALLBACK (source_drag_data_get), NULL);
674 g_signal_connect (button, "drag_data_delete",
675 G_CALLBACK (source_drag_data_delete), NULL);
677 gtk_widget_show_all (window);