1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| [luis@donald test1]$ diff -up test.c.original test.c
--- test.c.original 2010-08-27 02:29:29.000000000 +0200
+++ test.c 2010-08-27 02:39:47.000000000 +0200
@@ -3,14 +3,13 @@
#include <gtk/gtk.h>
-void mafonction(GtkWidget *widget, gpointer data);
-void deuxiemefenetre(GtkWidget *widget, gpointer data);
+void on_main_window_delete_event (GtkWidget *widget, gpointer data);
+void on_secondary_window_destroy (GtkWidget *widget, gpointer data);
int main(int argc, char **argv)
{
GtkWidget * MainWindow = NULL;
- const gchar *titre = NULL;
/* Initialisation de GTK+ */
gtk_init(&argc, &argv);
@@ -18,42 +17,35 @@ int main(int argc, char **argv)
/* Création de la fenêtre */
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow), "\tpremiere fenetre\t");
- titre = gtk_window_get_title(GTK_WINDOW(MainWindow));
- g_signal_connect(G_OBJECT(MainWindow), "delete-event", G_CALLBACK( deuxiemefenetre ), &titre);
+ g_signal_connect(G_OBJECT(MainWindow), "delete-event", G_CALLBACK(on_main_window_delete_event), NULL);
/* Affichage et boucle événementielle */
gtk_widget_show_all(MainWindow);
gtk_main();
/* Fermeture de GTK+ */
- gtk_exit(EXIT_SUCCESS);
- return EXIT_SUCCESS;
+ return 0;
}
-void deuxiemefenetre(GtkWidget *widget, gpointer data)
+void on_main_window_delete_event (GtkWidget *widget, gpointer data)
{
GtkWidget *fenetre = NULL, *label = NULL;
- const gchar *text;
-
- //text = gtk_window_get_title(GTK_WINDOW(widget));
- //gtk_widget_destroy(widget);
+ const gchar *titre;
fenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_resize(GTK_WINDOW(fenetre), 800, 200);
-
- label = gtk_label_new(data);
+ titre = gtk_window_get_title(GTK_WINDOW (widget));
+ label = gtk_label_new(titre);
gtk_container_add(GTK_CONTAINER(fenetre), label);
- g_signal_connect(G_OBJECT(fenetre), "delete-event", G_CALLBACK(mafonction), NULL);
+ g_signal_connect(G_OBJECT(fenetre), "destroy", G_CALLBACK(on_secondary_window_destroy), NULL);
gtk_widget_show_all(fenetre);
- gtk_main();
-
}
-void mafonction(GtkWidget *widget, gpointer data)
+void on_secondary_window_destroy (GtkWidget *widget, gpointer data)
{
gtk_main_quit();
- printf("\n\tc'est la fin\n");
+ printf("\n\tc'est la fin\n");
} |
Partager