Commit 71709960 authored by Stefan Jeske's avatar Stefan Jeske
Browse files

Began cleanup, e.g. use gtk_widget_show_all instead of many

gtk_widget_show's. Completely rewrote the button box sample
(only one window now). Removed "miscellaneous" button.
parent fb430a8d
......@@ -16,6 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -28,12 +29,25 @@
#include "circles.xbm"
GtkWidget *shape_create_icon (char *xpm_file,
gint x,
gint y,
gint px,
gint py,
gint window_type);
typedef struct _OptionMenuItem
{
gchar *name;
GtkSignalFunc func;
} OptionMenuItem;
GtkWidget *
shape_create_icon (char *xpm_file,
gint x,
gint y,
gint px,
gint py,
gint window_type);
static GtkWidget *
build_option_menu (OptionMenuItem items[],
gint num_items,
gint history,
gpointer data);
/* macro, structure and variables used by tree window demos */
#define DEFAULT_NUMBER_OF_ITEM 3
......@@ -59,15 +73,53 @@ typedef struct sTreeButtons {
} sTreeButtons;
/* end of tree section */
static GtkWidget *
build_option_menu (OptionMenuItem items[],
gint num_items,
gint history,
gpointer data)
{
GtkWidget *omenu;
GtkWidget *menu;
GtkWidget *menu_item;
GSList *group;
gint i;
omenu = gtk_option_menu_new ();
menu = gtk_menu_new ();
group = NULL;
for (i = 0; i < num_items; i++)
{
menu_item = gtk_radio_menu_item_new_with_label (group, items[i].name);
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
(GtkSignalFunc) items[i].func, data);
group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item));
gtk_menu_append (GTK_MENU (menu), menu_item);
if (i == history)
gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (menu_item), TRUE);
gtk_widget_show (menu_item);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history);
return omenu;
}
static void
destroy_tooltips (GtkWidget *widget, GtkWindow **window)
{
GtkTooltips *tt = gtk_object_get_data (GTK_OBJECT (*window), "tooltips");
gtk_object_unref (GTK_OBJECT (tt));
*window = NULL;
}
/*
* GtkButton
*/
static void
button_window (GtkWidget *widget,
GtkWidget *button)
......@@ -96,21 +148,17 @@ create_buttons (void)
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&window);
gtk_window_set_title (GTK_WINDOW (window), "buttons");
gtk_window_set_title (GTK_WINDOW (window), "GtkButton");
gtk_container_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 5);
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
gtk_container_border_width (GTK_CONTAINER (table), 10);
gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
gtk_widget_show (table);
button[0] = gtk_button_new_with_label ("button1");
button[1] = gtk_button_new_with_label ("button2");
......@@ -128,7 +176,6 @@ create_buttons (void)
gtk_table_attach (GTK_TABLE (table), button[0], 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[0]);
gtk_signal_connect (GTK_OBJECT (button[1]), "clicked",
GTK_SIGNAL_FUNC(button_window),
......@@ -136,68 +183,55 @@ create_buttons (void)
gtk_table_attach (GTK_TABLE (table), button[1], 1, 2, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[1]);
gtk_signal_connect (GTK_OBJECT (button[2]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[3]);
gtk_table_attach (GTK_TABLE (table), button[2], 2, 3, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[2]);
gtk_signal_connect (GTK_OBJECT (button[3]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[4]);
gtk_table_attach (GTK_TABLE (table), button[3], 0, 1, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[3]);
gtk_signal_connect (GTK_OBJECT (button[4]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[5]);
gtk_table_attach (GTK_TABLE (table), button[4], 2, 3, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[4]);
gtk_signal_connect (GTK_OBJECT (button[5]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[6]);
gtk_table_attach (GTK_TABLE (table), button[5], 1, 2, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[5]);
gtk_signal_connect (GTK_OBJECT (button[6]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[7]);
gtk_table_attach (GTK_TABLE (table), button[6], 1, 2, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[6]);
gtk_signal_connect (GTK_OBJECT (button[7]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[8]);
gtk_table_attach (GTK_TABLE (table), button[7], 2, 3, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[7]);
gtk_signal_connect (GTK_OBJECT (button[8]), "clicked",
GTK_SIGNAL_FUNC(button_window),
button[0]);
gtk_table_attach (GTK_TABLE (table), button[8], 0, 1, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (button[8]);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
gtk_widget_show (separator);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);
button[9] = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button[9]), "clicked",
......@@ -206,15 +240,18 @@ create_buttons (void)
gtk_box_pack_start (GTK_BOX (box2), button[9], TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button[9], GTK_CAN_DEFAULT);
gtk_widget_grab_default (button[9]);
gtk_widget_show (button[9]);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/*
* GtkToggleButton
*/
static void
create_toggle_buttons (void)
{
......@@ -232,44 +269,31 @@ create_toggle_buttons (void)
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&window);
gtk_window_set_title (GTK_WINDOW (window), "toggle buttons");
gtk_window_set_title (GTK_WINDOW (window), "GtkToggleButton");
gtk_container_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_toggle_button_new_with_label ("button1");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_toggle_button_new_with_label ("button2");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_toggle_button_new_with_label ("button3");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
gtk_widget_show (separator);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
......@@ -278,15 +302,18 @@ create_toggle_buttons (void)
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/*
* GtkCheckButton
*/
static void
create_check_buttons (void)
{
......@@ -304,44 +331,31 @@ create_check_buttons (void)
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&window);
gtk_window_set_title (GTK_WINDOW (window), "check buttons");
gtk_window_set_title (GTK_WINDOW (window), "GtkCheckButton");
gtk_container_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_check_button_new_with_label ("button1");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_check_button_new_with_label ("button2");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_check_button_new_with_label ("button3");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
gtk_widget_show (separator);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
......@@ -350,15 +364,18 @@ create_check_buttons (void)
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/*
* GtkRadioButton
*/
static void
create_radio_buttons (void)
{
......@@ -379,46 +396,33 @@ create_radio_buttons (void)
gtk_window_set_title (GTK_WINDOW (window), "radio buttons");
gtk_container_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_radio_button_new_with_label (NULL, "button1");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_radio_button_new_with_label (
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
"button2");
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_radio_button_new_with_label (
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
"button3");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
gtk_widget_show (separator);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
......@@ -427,151 +431,137 @@ create_radio_buttons (void)
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
static void
bbox_widget_destroy (GtkWidget* widget, GtkWidget* todestroy)
{
}
/*
* GtkButtonBox
*/
static void
create_bbox_window (gint horizontal,
char* title,
gint pos,
gint spacing,
gint child_w,
gint child_h,
gint layout)
static GtkWidget *
create_bbox (gint horizontal,
char* title,
gint spacing,
gint child_w,
gint child_h,
gint layout)
{
GtkWidget* window;
GtkWidget* box1;
GtkWidget* bbox;
GtkWidget* button;
GtkWidget *frame;
GtkWidget *bbox;
GtkWidget *button;
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), title);
frame = gtk_frame_new (title);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(bbox_widget_destroy), window);
if (horizontal)
{
gtk_widget_set_usize (window, 550, 60);
gtk_widget_set_uposition (window, 150, pos);
box1 = gtk_vbox_new (FALSE, 0);
}
else
{
gtk_widget_set_usize (window, 150, 400);
gtk_widget_set_uposition (window, pos, 200);
box1 = gtk_vbox_new (FALSE, 0);
}
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);
if (horizontal)
bbox = gtk_hbutton_box_new();
bbox = gtk_hbutton_box_new ();
else
bbox = gtk_vbutton_box_new();
bbox = gtk_vbutton_box_new ();
gtk_container_border_width (GTK_CONTAINER (bbox), 5);
gtk_container_add (GTK_CONTAINER (frame), bbox);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), spacing);
gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);
gtk_widget_show (bbox);
gtk_container_border_width (GTK_CONTAINER(box1), 25);
gtk_box_pack_start (GTK_BOX (box1), bbox, TRUE, TRUE, 0);
button = gtk_button_new_with_label ("OK");
gtk_container_add (GTK_CONTAINER(bbox), button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(bbox_widget_destroy), window);
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER (bbox), button);
button = gtk_button_new_with_label ("Cancel");
gtk_container_add (GTK_CONTAINER(bbox), button);
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER (bbox), button);
button = gtk_button_new_with_label ("Help");
gtk_container_add (GTK_CONTAINER(bbox), button);
gtk_widget_show (button);
gtk_widget_show (window);
}
gtk_container_add (GTK_CONTAINER (bbox), button);
static void
test_hbbox (void)
{
create_bbox_window (TRUE, "Spread", 50, 40, 85, 28, GTK_BUTTONBOX_SPREAD);
create_bbox_window (TRUE, "Edge", 200, 40, 85, 25, GTK_BUTTONBOX_EDGE);
create_bbox_window (TRUE, "Start", 350, 40, 85, 25, GTK_BUTTONBOX_START);
create_bbox_window (TRUE, "End", 500, 15, 30, 25, GTK_BUTTONBOX_END);
return frame;
}
static void
test_vbbox (void)
{
create_bbox_window (FALSE, "Spread", 50, 40, 85, 25, GTK_BUTTONBOX_SPREAD);
create_bbox_window (FALSE, "Edge", 250, 40, 85, 28, GTK_BUTTONBOX_EDGE);
create_bbox_window (FALSE, "Start", 450, 40, 85, 25, GTK_BUTTONBOX_START);
create_bbox_window (FALSE, "End", 650, 15, 30, 25, GTK_BUTTONBOX_END);
}
static void
create_button_box (void)
{
static GtkWidget* window = NULL;
GtkWidget* bbox;
GtkWidget* button;
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *frame_horz;
GtkWidget *frame_vert;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window),
"Button Box Test");
gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&window);
gtk_container_border_width (GTK_CONTAINER (window), 20);
gtk_container_border_width (GTK_CONTAINER (window), 10);
main_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
/*
*these 15 lines are a nice and easy example for GtkHButtonBox
*/
bbox = gtk_hbutton_box_new ();
gtk_container_add (GTK_CONTAINER (window), bbox);
gtk_widget_show (bbox);
frame_horz = gtk_frame_new ("Horizontal Button Boxes");
gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
button = gtk_button_new_with_label ("Horizontal");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(test_hbbox), 0);
gtk_container_add (GTK_CONTAINER (bbox), button);
gtk_widget_show (button);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (vbox), 10);
gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Spread", 40, 85, 20, GTK_BUTTONBOX_SPREAD),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Edge", 40, 85, 20, GTK_BUTTONBOX_EDGE),
TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Start", 40, 85, 20, GTK_BUTTONBOX_START),
TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "End", 40, 85, 20, GTK_BUTTONBOX_END),
TRUE, TRUE, 5);
frame_vert = gtk_frame_new ("Vertical Button Boxes");
gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
button = gtk_button_new_with_label ("Vertical");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(test_vbbox), 0);
gtk_container_add (GTK_CONTAINER (bbox), button);
gtk_widget_show (button);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (hbox), 10);
gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Spread", 30, 85, 20, GTK_BUTTONBOX_SPREAD),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Edge", 30, 85, 20, GTK_BUTTONBOX_EDGE),
TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Start", 30, 85, 20, GTK_BUTTONBOX_START),
TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "End", 30, 85, 20, GTK_BUTTONBOX_END),
TRUE, TRUE, 5);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/*
* GtkToolBar
*/
static GtkWidget*
new_pixmap (char *filename,
GdkWindow *window,
......@@ -716,7 +706,7 @@ create_toolbar (void)
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
entry = gtk_entry_new ();
gtk_widget_show(entry);
gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, "This is an unusable GtkEntry ;)", "Hey don't click me!!!");
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));