X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=tests%2Ftestdnd.c;h=2011578f6dafb79fa78df5ed3724e9475945d253;hb=HEAD;hp=88ff0345ed9679d99139dff6ca8409a211ba0207;hpb=0df78ed774d18bb9ee9676cfb79a00eccbee741c;p=~andy%2Fgtk diff --git a/tests/testdnd.c b/tests/testdnd.c index 88ff0345e..2011578f6 100644 --- a/tests/testdnd.c +++ b/tests/testdnd.c @@ -1,9 +1,28 @@ +/* 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 + * License along with this library. If not, see . + */ + +#include "config.h" #include "gtk/gtk.h" /* Target side drag signals */ /* XPM */ -static char * drag_icon_xpm[] = { +static const char * drag_icon_xpm[] = { "36 48 9 1", " c None", ". c #020204", @@ -64,7 +83,7 @@ static char * drag_icon_xpm[] = { "...................................."}; /* XPM */ -static char * trashcan_closed_xpm[] = { +static const char * trashcan_closed_xpm[] = { "64 80 17 1", " c None", ". c #030304", @@ -165,7 +184,7 @@ static char * trashcan_closed_xpm[] = { " "}; /* XPM */ -static char * trashcan_open_xpm[] = { +static const char * trashcan_open_xpm[] = { "64 80 17 1", " c None", ". c #030304", @@ -265,10 +284,8 @@ static char * trashcan_open_xpm[] = { " ", " "}; -GdkPixmap *trashcan_open; -GdkPixmap *trashcan_open_mask; -GdkPixmap *trashcan_closed; -GdkPixmap *trashcan_closed_mask; +GdkPixbuf *trashcan_open; +GdkPixbuf *trashcan_closed; gboolean have_drag; @@ -292,8 +309,7 @@ target_drag_leave (GtkWidget *widget, { g_print("leave\n"); have_drag = FALSE; - gtk_image_set_from_pixmap (GTK_IMAGE (widget), - trashcan_closed, trashcan_closed_mask); + gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed); } gboolean @@ -309,16 +325,15 @@ target_drag_motion (GtkWidget *widget, if (!have_drag) { have_drag = TRUE; - gtk_image_set_from_pixmap (GTK_IMAGE (widget), - trashcan_open, trashcan_open_mask); + gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open); } source_widget = gtk_drag_get_source_widget (context); g_print ("motion, source %s\n", source_widget ? - GTK_OBJECT_TYPE_NAME (source_widget) : + G_OBJECT_TYPE_NAME (source_widget) : "NULL"); - tmp_list = context->targets; + tmp_list = gdk_drag_context_list_targets (context); while (tmp_list) { char *name = gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)); @@ -328,7 +343,8 @@ target_drag_motion (GtkWidget *widget, tmp_list = tmp_list->next; } - gdk_drag_status (context, context->suggested_action, time); + gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time); + return TRUE; } @@ -342,13 +358,12 @@ target_drag_drop (GtkWidget *widget, g_print("drop\n"); have_drag = FALSE; - gtk_image_set_from_pixmap (GTK_IMAGE (widget), - trashcan_closed, trashcan_closed_mask); + gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed); - if (context->targets) + if (gdk_drag_context_list_targets (context)) { - gtk_drag_get_data (widget, context, - GDK_POINTER_TO_ATOM (context->targets->data), + gtk_drag_get_data (widget, context, + GDK_POINTER_TO_ATOM (gdk_drag_context_list_targets (context)->data), time); return TRUE; } @@ -361,13 +376,14 @@ target_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *data, + GtkSelectionData *selection_data, guint info, guint time) { - if ((data->length >= 0) && (data->format == 8)) + if (gtk_selection_data_get_length (selection_data) >= 0 && + gtk_selection_data_get_format (selection_data) == 8) { - g_print ("Received \"%s\" in trashcan\n", (gchar *)data->data); + g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data)); gtk_drag_finish (context, TRUE, FALSE, time); return; } @@ -380,13 +396,14 @@ label_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *data, + GtkSelectionData *selection_data, guint info, guint time) { - if ((data->length >= 0) && (data->format == 8)) + if (gtk_selection_data_get_length (selection_data) >= 0 && + gtk_selection_data_get_format (selection_data) == 8) { - g_print ("Received \"%s\" in label\n", (gchar *)data->data); + g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data)); gtk_drag_finish (context, TRUE, FALSE, time); return; } @@ -406,12 +423,12 @@ source_drag_data_get (GtkWidget *widget, g_print ("I was dropped on the rootwin\n"); else gtk_selection_data_set (selection_data, - selection_data->target, - 8, "I'm Data!", 9); + gtk_selection_data_get_target (selection_data), + 8, (guchar *) "I'm Data!", 9); } /* The following is a rather elaborate example demonstrating/testing - * changing of the window heirarchy during a drag - in this case, + * changing of the window hierarchy during a drag - in this case, * via a "spring-loaded" popup window. */ static GtkWidget *popup_window = NULL; @@ -464,12 +481,12 @@ popup_leave (GtkWidget *widget, if (!popdown_timer) { g_print ("added popdown\n"); - popdown_timer = g_timeout_add (500, popdown_cb, NULL); + popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL); } } } -gint +gboolean popup_cb (gpointer data) { if (!popped_up) @@ -477,13 +494,13 @@ popup_cb (gpointer data) if (!popup_window) { GtkWidget *button; - GtkWidget *table; + GtkWidget *grid; int i, j; popup_window = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE); - table = gtk_table_new (3,3, FALSE); + grid = gtk_grid_new (); for (i=0; i<3; i++) for (j=0; j<3; j++) @@ -491,9 +508,9 @@ popup_cb (gpointer data) char buffer[128]; g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j); button = gtk_button_new_with_label (buffer); - gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, - 0, 0); + gtk_widget_set_hexpand (button, TRUE); + gtk_widget_set_vexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1); gtk_drag_dest_set (button, GTK_DEST_DEFAULT_ALL, @@ -505,15 +522,15 @@ popup_cb (gpointer data) G_CALLBACK (popup_leave), NULL); } - gtk_widget_show_all (table); - gtk_container_add (GTK_CONTAINER (popup_window), table); + gtk_widget_show_all (grid); + gtk_container_add (GTK_CONTAINER (popup_window), grid); } gtk_widget_show (popup_window); popped_up = TRUE; } - popdown_timer = g_timeout_add (500, popdown_cb, NULL); + popdown_timer = gdk_threads_add_timeout (500, popdown_cb, NULL); g_print ("added popdown\n"); popup_timer = FALSE; @@ -529,7 +546,7 @@ popsite_motion (GtkWidget *widget, guint time) { if (!popup_timer) - popup_timer = g_timeout_add (500, popup_cb, NULL); + popup_timer = gdk_threads_add_timeout (500, popup_cb, NULL); return TRUE; } @@ -555,26 +572,21 @@ source_drag_data_delete (GtkWidget *widget, } void -test_init () +test_init (void) { - if (g_file_test ("../gdk-pixbuf/libpixbufloader-pnm.la", - G_FILE_TEST_EXISTS)) - { - g_setenv ("GDK_PIXBUF_MODULE_FILE", "../gdk-pixbuf/gdk-pixbuf.loaders", TRUE); - g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/gtk.immodules", TRUE); - } + if (g_file_test ("../modules/input/immodules.cache", G_FILE_TEST_EXISTS)) + g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/immodules.cache", TRUE); } int main (int argc, char **argv) { GtkWidget *window; - GtkWidget *table; + GtkWidget *grid; GtkWidget *label; GtkWidget *pixmap; GtkWidget *button; - GdkPixmap *drag_icon; - GdkPixmap *drag_mask; + GdkPixbuf *drag_icon; test_init (); @@ -585,22 +597,12 @@ main (int argc, char **argv) G_CALLBACK (gtk_main_quit), NULL); - table = gtk_table_new (2, 2, FALSE); - gtk_container_add (GTK_CONTAINER (window), table); - - drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_colormap (window), - &drag_mask, - NULL, drag_icon_xpm); - - trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_colormap (window), - &trashcan_open_mask, - NULL, trashcan_open_xpm); - trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_colormap (window), - &trashcan_closed_mask, - NULL, trashcan_closed_xpm); + grid = gtk_grid_new (); + gtk_container_add (GTK_CONTAINER (window), grid); + + drag_icon = gdk_pixbuf_new_from_xpm_data (drag_icon_xpm); + trashcan_open = gdk_pixbuf_new_from_xpm_data (trashcan_open_xpm); + trashcan_closed = gdk_pixbuf_new_from_xpm_data (trashcan_closed_xpm); label = gtk_label_new ("Drop Here\n"); @@ -612,9 +614,9 @@ main (int argc, char **argv) g_signal_connect (label, "drag_data_received", G_CALLBACK( label_drag_data_received), NULL); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, - 0, 0); + gtk_widget_set_hexpand (label, TRUE); + gtk_widget_set_vexpand (label, TRUE); + gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); label = gtk_label_new ("Popup\n"); @@ -623,20 +625,20 @@ main (int argc, char **argv) target_table, n_targets - 1, /* no rootwin */ GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, - 0, 0); + gtk_widget_set_hexpand (label, TRUE); + gtk_widget_set_vexpand (label, TRUE); + gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1); g_signal_connect (label, "drag_motion", G_CALLBACK (popsite_motion), NULL); g_signal_connect (label, "drag_leave", G_CALLBACK (popsite_leave), NULL); - pixmap = gtk_image_new_from_pixmap (trashcan_closed, trashcan_closed_mask); + pixmap = gtk_image_new_from_pixbuf (trashcan_closed); gtk_drag_dest_set (pixmap, 0, NULL, 0, 0); - gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, - 0, 0); + gtk_widget_set_hexpand (pixmap, TRUE); + gtk_widget_set_vexpand (pixmap, TRUE); + gtk_grid_attach (GTK_GRID (grid), pixmap, 1, 0, 1, 1); g_signal_connect (pixmap, "drag_leave", G_CALLBACK (target_drag_leave), NULL); @@ -657,16 +659,13 @@ main (int argc, char **argv) gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, target_table, n_targets, GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_source_set_icon (button, - gtk_widget_get_colormap (window), - drag_icon, drag_mask); + gtk_drag_source_set_icon_pixbuf (button, drag_icon); g_object_unref (drag_icon); - g_object_unref (drag_mask); - gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, - 0, 0); + gtk_widget_set_hexpand (button, TRUE); + gtk_widget_set_vexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1); g_signal_connect (button, "drag_data_get", G_CALLBACK (source_drag_data_get), NULL);