1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
#include <stdio.h>
|
1998-03-31 23:43:49 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
/* This function rotates the position of the tabs */
|
1999-11-13 23:06:46 +00:00
|
|
|
void rotate_book( GtkButton *button,
|
|
|
|
GtkNotebook *notebook )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos + 1) % 4);
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add/Remove the page tabs and the borders */
|
1999-11-13 23:06:46 +00:00
|
|
|
void tabsborder_book( GtkButton *button,
|
|
|
|
GtkNotebook *notebook )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
|
|
|
gint tval = FALSE;
|
|
|
|
gint bval = FALSE;
|
|
|
|
if (notebook->show_tabs == 0)
|
|
|
|
tval = TRUE;
|
|
|
|
if (notebook->show_border == 0)
|
|
|
|
bval = TRUE;
|
|
|
|
|
|
|
|
gtk_notebook_set_show_tabs (notebook, tval);
|
|
|
|
gtk_notebook_set_show_border (notebook, bval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a page from the notebook */
|
1999-11-13 23:06:46 +00:00
|
|
|
void remove_book( GtkButton *button,
|
|
|
|
GtkNotebook *notebook )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
|
|
|
gint page;
|
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
page = gtk_notebook_get_current_page (notebook);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_notebook_remove_page (notebook, page);
|
|
|
|
/* Need to refresh the widget --
|
|
|
|
This forces the widget to redraw itself. */
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (notebook));
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
gint delete( GtkWidget *widget,
|
|
|
|
GtkWidget *event,
|
|
|
|
gpointer data )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_main_quit ();
|
|
|
|
return FALSE;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *notebook;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *checkbutton;
|
|
|
|
int i;
|
|
|
|
char bufferf[32];
|
|
|
|
char bufferl[32];
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (window), "delete_event",
|
|
|
|
G_CALLBACK (delete), NULL);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
|
1998-12-13 22:25:07 +00:00
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
table = gtk_table_new (3, 6, FALSE);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), table);
|
|
|
|
|
|
|
|
/* Create a new notebook, place the position of the tabs */
|
|
|
|
notebook = gtk_notebook_new ();
|
|
|
|
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 6, 0, 1);
|
|
|
|
gtk_widget_show (notebook);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* Let's append a bunch of pages to the notebook */
|
2002-02-19 01:25:26 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
sprintf(bufferf, "Append Frame %d", i + 1);
|
|
|
|
sprintf(bufferl, "Page %d", i + 1);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (bufferf);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (frame, 100, 75);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
label = gtk_label_new (bufferf);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
label = gtk_label_new (bufferl);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
|
|
|
|
}
|
1998-12-13 22:25:07 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* Now let's add a page to a specific spot */
|
1998-03-31 23:43:49 +00:00
|
|
|
checkbutton = gtk_check_button_new_with_label ("Check me please!");
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (checkbutton, 100, 75);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (checkbutton);
|
1998-12-13 22:25:07 +00:00
|
|
|
|
1998-03-31 23:43:49 +00:00
|
|
|
label = gtk_label_new ("Add page");
|
|
|
|
gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2);
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
/* Now finally let's prepend pages to the notebook */
|
2002-02-19 01:25:26 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
sprintf (bufferf, "Prepend Frame %d", i + 1);
|
|
|
|
sprintf (bufferl, "PPage %d", i + 1);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new (bufferf);
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (frame, 100, 75);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
label = gtk_label_new (bufferf);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
label = gtk_label_new (bufferl);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_notebook_prepend_page (GTK_NOTEBOOK (notebook), frame, label);
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set what page to start at (page 4) */
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 3);
|
1998-12-13 22:25:07 +00:00
|
|
|
|
|
|
|
/* Create a bunch of buttons */
|
1998-03-31 23:43:49 +00:00
|
|
|
button = gtk_button_new_with_label ("close");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (delete), NULL);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("next page");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (gtk_notebook_next_page),
|
2002-08-24 11:53:26 +00:00
|
|
|
G_OBJECT (notebook));
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("prev page");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (gtk_notebook_prev_page),
|
2002-08-24 11:53:26 +00:00
|
|
|
G_OBJECT (notebook));
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("tab position");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (rotate_book),
|
2002-08-24 11:53:26 +00:00
|
|
|
(gpointer) notebook);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 3, 4, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("tabs/border on/off");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (tabsborder_book),
|
2002-08-24 11:53:26 +00:00
|
|
|
(gpointer) notebook);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 4, 5, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("remove page");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (remove_book),
|
2002-08-24 11:53:26 +00:00
|
|
|
(gpointer) notebook);
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button, 5, 6, 1, 2);
|
|
|
|
gtk_widget_show (button);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_widget_show (table);
|
|
|
|
gtk_widget_show (window);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|