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
| /* travail sur les gtkdialog */
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <stdlib.h>
#include <stdio.h>
GtkWidget *pWindow=NULL;
char format_sortie[500]; /* chaine qui sert de tempon */
int main(int argc, char **argv)
{
gboolean test_fermeture(GtkWidget *widget, GdkEvent *event, gpointer user_data); /* fonction call back si tentative de fermeture */
void OnDestroy(GtkWidget *pWidget, gpointer pData); /* fonction call back destroy */
/* Initialisation de GTK+ */
gtk_init(&argc, &argv);
/* création de la fenetre */
pWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* définition des paramètres de la fenetre */
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(pWindow), 750, 210);
gtk_window_set_title(GTK_WINDOW(pWindow), "Testing Gtk_Dialog..");
/* Connexion des signaux */
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(OnDestroy), NULL);
g_signal_connect(G_OBJECT(pWindow), "delete-event", G_CALLBACK (test_fermeture), NULL);
/*affichage de la fenetre */
gtk_widget_show_all(pWindow);
/* Demarrage de la boucle evenementielle */
gtk_main();
return EXIT_SUCCESS;
}
void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
/* Arret de la boucle evenementielle */
gtk_main_quit();
}
gboolean test_fermeture(GtkWidget *pWindow, GdkEvent *event, gpointer user_data)
{
/* call back si tentative de fermeture de la fenetre */
GtkWidget *pQuestion=NULL; /* boite de dialogue pour poser la question */
GtkWidget *message_info=NULL; /* message de la boite de dialogue pour poser la question */
gchar* sUtf8_question=NULL; /* pour formatter des chaines de charactères */
int sortie;
/* création du label */
message_info=gtk_label_new(NULL);
(void)sprintf(format_sortie, "\n<span font_desc=\"12\" foreground=\"#000000\"><b> Etes-vous sûr de quitter ? </b></span>\n");
sUtf8_question=g_locale_to_utf8(format_sortie, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(message_info), sUtf8_question);
g_free(sUtf8_question);
/* création de la boite d'info */
pQuestion=gtk_dialog_new();
gtk_dialog_add_buttons(GTK_DIALOG(pQuestion), "Non", 0,"Oui", 1, NULL);
gtk_dialog_set_has_separator(GTK_DIALOG(pQuestion), TRUE);
/* ajout du label */
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pQuestion)->vbox), message_info, TRUE, FALSE, 0);
/* Affichage de la boite d'info */
gtk_widget_show_all(GTK_DIALOG(pQuestion)->vbox);
sortie=(int)gtk_dialog_run(GTK_DIALOG(pQuestion));
/* Destruction de la boite de message */
gtk_widget_destroy(GTK_WIDGET(pQuestion));
if (sortie==1) /* oui on quitte */
return FALSE;
else /* Non on reste */
return TRUE;
return TRUE;
} |
Partager