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
| int main (int argc, char **argv)
{
gint i = 0;
gchar *string = NULL;
GtkWidget *win = NULL;
GtkWidget *notebook = NULL;
t_pages *nouvelle = (t_pages *)malloc(6 * sizeof(t_pages));
/* Initialize GTK+ */
gtk_init (&argc, &argv);
/* Create the main window */
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win), 320, 200);
gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
notebook = gtk_notebook_new();
gtk_container_add(GTK_CONTAINER(win), notebook);
/* Create 6 pages with close button */
for(i = 0; i < 6; i++)
{
fprintf(stderr,"adresse p>>%p\n",&nouvelle[i]);
nouvelle[i].page_num = i;
string = g_strdup_printf("page %d", i);
nouvelle[i].label = gtk_label_new(string);
nouvelle[i].box = gtk_vbox_new(FALSE, 0);
nouvelle[i].onglet_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start (GTK_BOX(nouvelle[i].onglet_box), nouvelle[i].label, TRUE, TRUE, 0);
nouvelle[i].button = gtk_button_new ();
nouvelle[i].icon = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON(nouvelle[i].button), nouvelle[i].icon);
gtk_button_set_relief (GTK_BUTTON(nouvelle[i].button), GTK_RELIEF_NONE);
/* Associate button with the "num page" */
g_object_set_data (G_OBJECT(nouvelle[i].button), "str", (gpointer)i);
gtk_box_pack_start (GTK_BOX(nouvelle[i].onglet_box), nouvelle[i].button, TRUE, TRUE, 0);
/* Add the structure _pages in Glist */
list = g_list_append (list, &nouvelle[i]);
g_free(string);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nouvelle[i].box, nouvelle[i].onglet_box);
g_signal_connect (G_OBJECT(nouvelle[i].button), "clicked", G_CALLBACK(DeleteOnglet), notebook);
gtk_widget_show_all(nouvelle[i].onglet_box);
}
g_free(string);
gtk_widget_show_all (win);
gtk_main ();
free(nouvelle);
return EXIT_SUCCESS;
} |
Partager