2005-07-13 05:44:22 +00:00
|
|
|
/* testdnd.c
|
|
|
|
* Copyright (C) 1998 Red Hat, Inc.
|
|
|
|
* Author: Owen Taylor
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
1998-10-18 23:28:36 +00:00
|
|
|
#include "gtk/gtk.h"
|
|
|
|
|
|
|
|
/* Target side drag signals */
|
|
|
|
|
|
|
|
/* XPM */
|
2010-08-06 18:33:57 +00:00
|
|
|
static const char * drag_icon_xpm[] = {
|
1998-10-18 23:28:36 +00:00
|
|
|
"36 48 9 1",
|
|
|
|
" c None",
|
|
|
|
". c #020204",
|
|
|
|
"+ c #8F8F90",
|
|
|
|
"@ c #D3D3D2",
|
|
|
|
"# c #AEAEAC",
|
|
|
|
"$ c #ECECEC",
|
|
|
|
"% c #A2A2A4",
|
|
|
|
"& c #FEFEFC",
|
|
|
|
"* c #BEBEBC",
|
|
|
|
" .....................",
|
|
|
|
" ..&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ...&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&.&&&@&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&.*$%$+$&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
" ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
"................&$@&&&@&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.",
|
|
|
|
".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.",
|
|
|
|
".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&@%&%$&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&+&$+&$&@&$@&&$@&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&+&&#@%#+@#@*$%&+$&&&&&&&&.",
|
|
|
|
".&&&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&.",
|
|
|
|
".&&&&&&&&@#@@$&*@&@#@#$#*#$&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&.",
|
|
|
|
".&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&&&&&.",
|
|
|
|
".&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&.",
|
|
|
|
".&&&&&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&.",
|
|
|
|
".&&&&&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
|
|
|
|
"...................................."};
|
|
|
|
|
|
|
|
/* XPM */
|
2010-08-06 18:33:57 +00:00
|
|
|
static const char * trashcan_closed_xpm[] = {
|
1998-10-18 23:28:36 +00:00
|
|
|
"64 80 17 1",
|
|
|
|
" c None",
|
|
|
|
". c #030304",
|
|
|
|
"+ c #5A5A5C",
|
|
|
|
"@ c #323231",
|
|
|
|
"# c #888888",
|
|
|
|
"$ c #1E1E1F",
|
|
|
|
"% c #767677",
|
|
|
|
"& c #494949",
|
|
|
|
"* c #9E9E9C",
|
|
|
|
"= c #111111",
|
|
|
|
"- c #3C3C3D",
|
|
|
|
"; c #6B6B6B",
|
|
|
|
"> c #949494",
|
|
|
|
", c #282828",
|
|
|
|
"' c #808080",
|
|
|
|
") c #545454",
|
|
|
|
"! c #AEAEAC",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ==......=$$...=== ",
|
|
|
|
" ..$------)+++++++++++++@$$... ",
|
|
|
|
" ..=@@-------&+++++++++++++++++++-.... ",
|
|
|
|
" =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$ ",
|
|
|
|
" .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&.. ",
|
|
|
|
" $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@ ",
|
|
|
|
" .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$ ",
|
|
|
|
" +------++++++++++++++++++++++++++++++;;%%%;;##*!. ",
|
|
|
|
" =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>). ",
|
|
|
|
" .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@. ",
|
|
|
|
" =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%== ",
|
|
|
|
" .&....=-+++++%;;####''''''''''##'%%%)..#. ",
|
|
|
|
" .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!. ",
|
|
|
|
" .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
|
|
|
|
" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
|
|
|
|
" =.++++++++++++++!++++!++++!+++!++.= ",
|
|
|
|
" $..+++++++++++++++!++++++...$ ",
|
|
|
|
" $$=.............=$$ ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" "};
|
|
|
|
|
|
|
|
/* XPM */
|
2010-08-06 18:33:57 +00:00
|
|
|
static const char * trashcan_open_xpm[] = {
|
1998-10-18 23:28:36 +00:00
|
|
|
"64 80 17 1",
|
|
|
|
" c None",
|
|
|
|
". c #030304",
|
|
|
|
"+ c #5A5A5C",
|
|
|
|
"@ c #323231",
|
|
|
|
"# c #888888",
|
|
|
|
"$ c #1E1E1F",
|
|
|
|
"% c #767677",
|
|
|
|
"& c #494949",
|
|
|
|
"* c #9E9E9C",
|
|
|
|
"= c #111111",
|
|
|
|
"- c #3C3C3D",
|
|
|
|
"; c #6B6B6B",
|
|
|
|
"> c #949494",
|
|
|
|
", c #282828",
|
|
|
|
"' c #808080",
|
|
|
|
") c #545454",
|
|
|
|
"! c #AEAEAC",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" .=.==.,@ ",
|
|
|
|
" ==.,@-&&&)-= ",
|
|
|
|
" .$@,&++;;;%>*- ",
|
|
|
|
" $,-+)+++%%;;'#+. ",
|
|
|
|
" =---+++++;%%%;%##@. ",
|
|
|
|
" @)++++++++;%%%%'#%$ ",
|
|
|
|
" $&++++++++++;%%;%##@= ",
|
|
|
|
" ,-++++)+++++++;;;'#%) ",
|
|
|
|
" @+++&&--&)++++;;%'#'-. ",
|
|
|
|
" ,&++-@@,,,,-)++;;;'>'+, ",
|
|
|
|
" =-++&@$@&&&&-&+;;;%##%+@ ",
|
|
|
|
" =,)+)-,@@&+++++;;;;%##%&@ ",
|
|
|
|
" @--&&,,@&)++++++;;;;'#)@ ",
|
|
|
|
" ---&)-,@)+++++++;;;%''+, ",
|
|
|
|
" $--&)+&$-+++++++;;;%%'';- ",
|
|
|
|
" .,-&+++-$&++++++;;;%''%&= ",
|
|
|
|
" $,-&)++)-@++++++;;%''%), ",
|
|
|
|
" =,@&)++++&&+++++;%'''+$@&++++++ ",
|
|
|
|
" .$@-++++++++++++;'#';,........=$@&++++ ",
|
|
|
|
" =$@@&)+++++++++++'##-.................=&++ ",
|
|
|
|
" .$$@-&)+++++++++;%#+$.....................=)+ ",
|
|
|
|
" $$,@-)+++++++++;%;@=........................,+ ",
|
|
|
|
" .$$@@-++++++++)-)@=............................ ",
|
|
|
|
" $,@---)++++&)@===............................,. ",
|
|
|
|
" $-@---&)))-$$=..............................=)!. ",
|
|
|
|
" --&-&&,,$=,==...........................=&+++!. ",
|
|
|
|
" =,=$..=$+)+++++&@$=.............=$@&+++++!++!. ",
|
|
|
|
" .)-++-+++++++++++++++++++++++++++!++!++!. ",
|
|
|
|
" .+-++-+++++++++++++++++++++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!+++!!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" .+-++-+++-+++++++++!++++!++++!+++!++!++!. ",
|
|
|
|
" =+-++-+++-+++++++++!++++!++++!+++!++!+++= ",
|
|
|
|
" $.++-+++-+++++++++!++++!++++!+++!++!+.$ ",
|
|
|
|
" =.++++++++++++++!++++!++++!+++!++.= ",
|
|
|
|
" $..+++++++++++++++!++++++...$ ",
|
|
|
|
" $$==...........==$$ ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" ",
|
|
|
|
" "};
|
|
|
|
|
2010-08-06 18:33:57 +00:00
|
|
|
GdkPixbuf *trashcan_open;
|
|
|
|
GdkPixbuf *trashcan_closed;
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
gboolean have_drag;
|
|
|
|
|
2017-11-16 23:28:53 +00:00
|
|
|
static const char *target_table[] = {
|
|
|
|
"STRING",
|
|
|
|
"text/plain",
|
|
|
|
"application/x-rootwindow-drop"
|
1998-10-18 23:28:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
|
|
|
|
|
|
|
|
void
|
2020-01-02 06:46:26 +00:00
|
|
|
target_drag_leave (GtkDropTarget *dest,
|
|
|
|
GtkWidget *widget)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
g_print("leave\n");
|
|
|
|
have_drag = FALSE;
|
2010-08-06 18:33:57 +00:00
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
|
1998-10-18 23:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-01-02 06:46:26 +00:00
|
|
|
target_drag_motion (GtkDropTarget *dest,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GtkWidget *widget)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
2017-11-18 04:53:25 +00:00
|
|
|
char *s;
|
1998-11-27 17:16:36 +00:00
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
if (!have_drag)
|
|
|
|
{
|
|
|
|
have_drag = TRUE;
|
2010-08-06 18:33:57 +00:00
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open);
|
1998-10-18 23:28:36 +00:00
|
|
|
}
|
1998-11-27 17:16:36 +00:00
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
s = gdk_content_formats_to_string (gdk_drop_get_formats (drop));
|
2017-11-18 04:53:25 +00:00
|
|
|
g_print ("%s\n", s);
|
2001-03-15 23:21:39 +00:00
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
gdk_drop_status (drop, GDK_ACTION_ALL);
|
2010-12-14 00:09:11 +00:00
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-02 06:46:26 +00:00
|
|
|
static void
|
|
|
|
got_text_in_target (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = gdk_drop_read_text_finish (GDK_DROP (object), result, NULL);
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
g_print ("Received \"%s\" in target\n", str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
gboolean
|
2020-01-02 06:46:26 +00:00
|
|
|
target_drag_drop (GtkDropTarget *dest,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GtkWidget *widget)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
2017-11-18 04:53:25 +00:00
|
|
|
GdkContentFormats *formats;
|
2017-11-24 10:34:19 +00:00
|
|
|
const char *format;
|
2017-11-18 04:53:25 +00:00
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
g_print("drop\n");
|
|
|
|
have_drag = FALSE;
|
|
|
|
|
2010-08-06 18:33:57 +00:00
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
formats = gdk_drop_get_formats (drop);
|
2017-11-24 10:34:19 +00:00
|
|
|
format = gdk_content_formats_match_mime_type (formats, formats);
|
2017-11-18 04:53:25 +00:00
|
|
|
if (format)
|
1999-01-23 20:32:20 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
gdk_drop_read_text_async (drop, NULL, got_text_in_target, widget);
|
1999-01-23 20:32:20 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
static GdkDragAction
|
|
|
|
action_make_unique (GdkDragAction action)
|
|
|
|
{
|
|
|
|
if (gdk_drag_action_is_unique (action))
|
|
|
|
return action;
|
|
|
|
|
|
|
|
if (action & GDK_ACTION_COPY)
|
|
|
|
return GDK_ACTION_COPY;
|
|
|
|
|
|
|
|
if (action & GDK_ACTION_MOVE)
|
|
|
|
return GDK_ACTION_MOVE;
|
|
|
|
|
|
|
|
if (action & GDK_ACTION_LINK)
|
|
|
|
return GDK_ACTION_LINK;
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-02 06:46:26 +00:00
|
|
|
static void
|
|
|
|
got_text (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = gdk_drop_read_text_finish (GDK_DROP (object), result, NULL);
|
|
|
|
if (str)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
g_print ("Received \"%s\" in label\n", str);
|
|
|
|
g_free (str);
|
1998-10-18 23:28:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-02 06:46:26 +00:00
|
|
|
|
1999-01-12 23:27:30 +00:00
|
|
|
void
|
2020-01-02 06:46:26 +00:00
|
|
|
label_drag_drop (GtkDropTarget *dest,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GtkWidget *widget)
|
1999-01-12 23:27:30 +00:00
|
|
|
{
|
2020-01-02 06:46:26 +00:00
|
|
|
GdkDrop *drop = gtk_drop_target_get_drop (dest);
|
|
|
|
|
|
|
|
gdk_drop_read_text_async (drop, NULL, got_text, widget);
|
|
|
|
GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop));
|
|
|
|
gdk_drop_finish (drop, action);
|
1999-01-12 23:27:30 +00:00
|
|
|
}
|
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
/* The following is a rather elaborate example demonstrating/testing
|
2008-12-13 05:20:10 +00:00
|
|
|
* changing of the window hierarchy during a drag - in this case,
|
1998-10-18 23:28:36 +00:00
|
|
|
* via a "spring-loaded" popup window.
|
|
|
|
*/
|
|
|
|
static GtkWidget *popup_window = NULL;
|
|
|
|
|
|
|
|
static gboolean popped_up = FALSE;
|
|
|
|
static gboolean in_popup = FALSE;
|
|
|
|
static guint popdown_timer = 0;
|
|
|
|
static guint popup_timer = 0;
|
|
|
|
|
|
|
|
gint
|
|
|
|
popdown_cb (gpointer data)
|
|
|
|
{
|
|
|
|
popdown_timer = 0;
|
|
|
|
|
|
|
|
gtk_widget_hide (popup_window);
|
|
|
|
popped_up = FALSE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-01-02 06:46:26 +00:00
|
|
|
popup_motion (GtkDropTarget *dest,
|
|
|
|
int x,
|
|
|
|
int y)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
if (!in_popup)
|
|
|
|
{
|
|
|
|
in_popup = TRUE;
|
|
|
|
if (popdown_timer)
|
|
|
|
{
|
|
|
|
g_print ("removed popdown\n");
|
2003-02-19 19:42:04 +00:00
|
|
|
g_source_remove (popdown_timer);
|
1998-10-18 23:28:36 +00:00
|
|
|
popdown_timer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-01-02 06:46:26 +00:00
|
|
|
popup_leave (GtkDropTarget *dest)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
if (in_popup)
|
|
|
|
{
|
|
|
|
in_popup = FALSE;
|
|
|
|
if (!popdown_timer)
|
|
|
|
{
|
|
|
|
g_print ("added popdown\n");
|
2018-02-02 14:51:47 +00:00
|
|
|
popdown_timer = g_timeout_add (500, popdown_cb, NULL);
|
1998-10-18 23:28:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-22 19:10:43 +00:00
|
|
|
gboolean
|
1998-10-18 23:28:36 +00:00
|
|
|
popup_cb (gpointer data)
|
|
|
|
{
|
|
|
|
if (!popped_up)
|
|
|
|
{
|
|
|
|
if (!popup_window)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2011-09-27 20:23:26 +00:00
|
|
|
GtkWidget *grid;
|
1998-10-18 23:28:36 +00:00
|
|
|
int i, j;
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *targets;
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
grid = gtk_grid_new ();
|
2017-11-18 01:19:53 +00:00
|
|
|
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
for (i=0; i<3; i++)
|
|
|
|
for (j=0; j<3; j++)
|
|
|
|
{
|
|
|
|
char buffer[128];
|
2020-01-02 06:46:26 +00:00
|
|
|
GtkDropTarget *dest;
|
|
|
|
|
1998-12-10 06:18:32 +00:00
|
|
|
g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
|
1998-10-18 23:28:36 +00:00
|
|
|
button = gtk_button_new_with_label (buffer);
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_widget_set_hexpand (button, TRUE);
|
|
|
|
gtk_widget_set_vexpand (button, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2020-01-05 22:23:50 +00:00
|
|
|
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2020-01-02 06:46:26 +00:00
|
|
|
g_signal_connect (dest, "drag-motion", G_CALLBACK (popup_motion), NULL);
|
|
|
|
g_signal_connect (dest, "drag-leave", G_CALLBACK (popup_leave), NULL);
|
|
|
|
gtk_drop_target_attach (dest, button);
|
1998-10-18 23:28:36 +00:00
|
|
|
}
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (popup_window), grid);
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (targets);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
gtk_widget_show (popup_window);
|
|
|
|
popped_up = TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-02 14:51:47 +00:00
|
|
|
popdown_timer = g_timeout_add (500, popdown_cb, NULL);
|
1998-10-18 23:28:36 +00:00
|
|
|
g_print ("added popdown\n");
|
|
|
|
|
|
|
|
popup_timer = FALSE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-01-02 06:46:26 +00:00
|
|
|
popsite_motion (GtkDropTarget *dest,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GtkWidget *widget)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
if (!popup_timer)
|
2018-02-02 14:51:47 +00:00
|
|
|
popup_timer = g_timeout_add (500, popup_cb, NULL);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-01-02 06:46:26 +00:00
|
|
|
popsite_leave (GtkDropTarget *dest)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
if (popup_timer)
|
|
|
|
{
|
2003-02-19 19:42:04 +00:00
|
|
|
g_source_remove (popup_timer);
|
1998-10-18 23:28:36 +00:00
|
|
|
popup_timer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-01-02 06:46:26 +00:00
|
|
|
source_drag_data_delete (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-10-18 23:28:36 +00:00
|
|
|
{
|
|
|
|
g_print ("Delete the data!\n");
|
|
|
|
}
|
|
|
|
|
2001-04-25 16:17:46 +00:00
|
|
|
void
|
2004-10-28 15:00:05 +00:00
|
|
|
test_init (void)
|
2001-04-25 16:17:46 +00:00
|
|
|
{
|
2011-03-29 13:26:03 +00:00
|
|
|
if (g_file_test ("../modules/input/immodules.cache", G_FILE_TEST_EXISTS))
|
|
|
|
g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/immodules.cache", TRUE);
|
2001-04-25 16:17:46 +00:00
|
|
|
}
|
|
|
|
|
1998-10-18 23:28:36 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
2011-09-27 20:23:26 +00:00
|
|
|
GtkWidget *grid;
|
1998-10-18 23:28:36 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *pixmap;
|
|
|
|
GtkWidget *button;
|
2010-08-06 18:33:57 +00:00
|
|
|
GdkPixbuf *drag_icon;
|
2018-03-15 01:53:17 +00:00
|
|
|
GdkTexture *texture;
|
2020-01-01 02:10:15 +00:00
|
|
|
GdkContentProvider *content;
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
GtkDragSource *source;
|
2017-11-18 01:19:53 +00:00
|
|
|
GdkContentFormats *targets;
|
2020-01-02 06:46:26 +00:00
|
|
|
GtkDropTarget *dest;
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2001-04-25 16:17:46 +00:00
|
|
|
test_init ();
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), grid);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2010-08-06 18:33:57 +00:00
|
|
|
drag_icon = gdk_pixbuf_new_from_xpm_data (drag_icon_xpm);
|
2018-03-15 01:53:17 +00:00
|
|
|
texture = gdk_texture_new_for_pixbuf (drag_icon);
|
2017-11-30 01:02:01 +00:00
|
|
|
g_object_unref (drag_icon);
|
2010-08-06 18:33:57 +00:00
|
|
|
trashcan_open = gdk_pixbuf_new_from_xpm_data (trashcan_open_xpm);
|
|
|
|
trashcan_closed = gdk_pixbuf_new_from_xpm_data (trashcan_closed_xpm);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Drop Here\n");
|
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */
|
2020-01-05 22:23:50 +00:00
|
|
|
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2020-01-02 06:46:26 +00:00
|
|
|
g_signal_connect (dest, "drag-drop", G_CALLBACK (label_drag_drop), NULL);
|
|
|
|
gtk_drop_target_attach (dest, label);
|
1999-01-12 23:27:30 +00:00
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Popup\n");
|
|
|
|
|
2020-01-05 22:23:50 +00:00
|
|
|
dest = gtk_drop_target_new (targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2020-01-02 06:46:26 +00:00
|
|
|
g_signal_connect (dest, "drag-motion", G_CALLBACK (popsite_motion), NULL);
|
|
|
|
g_signal_connect (dest, "drag-leave", G_CALLBACK (popsite_leave), NULL);
|
|
|
|
gtk_drop_target_attach (dest, label);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2017-11-18 01:19:53 +00:00
|
|
|
gdk_content_formats_unref (targets);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2010-08-06 18:33:57 +00:00
|
|
|
pixmap = gtk_image_new_from_pixbuf (trashcan_closed);
|
2020-01-02 06:46:26 +00:00
|
|
|
targets = gdk_content_formats_new (NULL, 0);
|
2020-01-05 22:23:50 +00:00
|
|
|
dest = gtk_drop_target_new (targets, 0);
|
2020-01-02 06:46:26 +00:00
|
|
|
g_signal_connect (dest, "drag-leave", G_CALLBACK (target_drag_leave), pixmap);
|
|
|
|
g_signal_connect (dest, "drag-motion", G_CALLBACK (target_drag_motion), pixmap);
|
|
|
|
g_signal_connect (dest, "drag-drop", G_CALLBACK (target_drag_drop), pixmap);
|
|
|
|
gtk_drop_target_attach (dest, pixmap);
|
|
|
|
gdk_content_formats_unref (targets);
|
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_widget_set_hexpand (pixmap, TRUE);
|
|
|
|
gtk_widget_set_vexpand (pixmap, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), pixmap, 1, 0, 1, 1);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Drag site */
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Drag Here\n");
|
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&value, "I'm data!");
|
|
|
|
content = gdk_content_provider_new_for_value (&value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
source = gtk_drag_source_new (content, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
gtk_drag_source_attach (source, button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK);
|
|
|
|
gtk_drag_source_set_icon (source, GDK_PAINTABLE (texture), 0, 0);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2018-03-15 01:53:17 +00:00
|
|
|
g_object_unref (texture);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2011-09-27 20:23:26 +00:00
|
|
|
gtk_widget_set_hexpand (button, TRUE);
|
|
|
|
gtk_widget_set_vexpand (button, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
g_signal_connect (source, "drag-data-delete",
|
2002-10-13 23:22:33 +00:00
|
|
|
G_CALLBACK (source_drag_data_delete), NULL);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
1998-10-18 23:28:36 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|