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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
void OnUser(GtkWidget* pWidget,gpointer data)
{
GtkWidget* pBoite=NULL;
GtkTextBuffer *pTextBuffer= NULL;
GtkWidget* pEntry=NULL;
GtkWidget* pTreeStore = data;
FILE* fichier;
GtkTextIter iStart, iEnd;
GtkWidget *pFrame;
GtkWidget *pVBoxFrame;
GtkWidget *pLabel;
const gchar *sNom;
const gchar *sPrenom;
const gchar *sCode;
const gchar *sVille;
/* Creation de la boite de dialogue */
/* 1 bouton Valider */
/* 1 bouton Annuler */
pBoite = gtk_dialog_new_with_buttons("Information",
NULL,
GTK_DIALOG_MODAL,
GTK_STOCK_OK,GTK_RESPONSE_OK,
GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
NULL);
gtk_window_set_position(GTK_WINDOW (pBoite), GTK_WIN_POS_CENTER);
gtk_dialog_set_default_response (GTK_DIALOG(pBoite),GTK_RESPONSE_OK);
gtk_dialog_set_response_sensitive(GTK_DIALOG(pBoite),GTK_RESPONSE_OK,TRUE);
/* Creation de la 1ere GtkFrame */
pFrame = gtk_frame_new("Informations");
gtk_box_pack_start(GTK_DIALOG(pBoite)->vbox, pFrame, TRUE, FALSE, 0);
/* Creation et insertion d une boite pour le deuxieme GtkFrame */
pVBoxFrame = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(pFrame), pVBoxFrame);
/* Creation et insertion des elements contenus dans le deuxieme GtkFrame */
pLabel = gtk_label_new("Nom :");
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
pEntry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(pEntry),50);
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
sNom = gtk_entry_get_text(GTK_ENTRY(pEntry));
pLabel = gtk_label_new("Prenom :");
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
pEntry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(pEntry),50);
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
sPrenom= gtk_entry_get_text(GTK_ENTRY(pEntry));
pLabel = gtk_label_new("Code postal :");
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
pEntry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(pEntry),50);
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
sCode = gtk_entry_get_text(GTK_ENTRY(pEntry));
pLabel = gtk_label_new("Ville :");
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
pEntry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(pEntry),50);
gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
sVille = gtk_entry_get_text(GTK_ENTRY(pEntry));
/* Affichage des elements de la boite de dialogue */
gtk_widget_show_all(GTK_DIALOG(pBoite)->vbox);
/* On lance la boite de dialogue et on recupere la reponse */
switch (gtk_dialog_run(GTK_DIALOG(pBoite)))
{
/* L utilisateur valide */
case GTK_RESPONSE_OK:
fichier = fopen("user.txt","a");
fprintf(fichier,"%s\n%s\n%s\n%s\n",sNom,sPrenom,sCode,sVille);
//fprintf(fichier,"%d",nb_ligne);
fclose(fichier);
GtkTreeIter pIter;
GtkTreeIter pIter2;
gint j;
enum {
FROM_COLUMN,
OBJECT_COLUMN,
};
/* Creation de la nouvelle ligne */
gtk_tree_store_append(pTreeStore, &pIter, NULL);
/* Mise a jour des donnees */
gtk_tree_store_set(pTreeStore, &pIter,
FROM_COLUMN,sNom,
-1);
break;
/* L utilisateur annule */
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_NONE:
default:
break;
}
/* Destruction de la boite de dialogue */
gtk_widget_destroy(pBoite);
} |
Partager