diff options
author | Owen Taylor <otaylor@redhat.com> | 2001-05-18 18:30:59 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2001-05-18 18:30:59 +0000 |
commit | 50512ddcd2b2cb156d4a4e13a9f6ac21aae30ddf (patch) | |
tree | 1e34849888cd77ec1cb4c71c4ecacd48d4fcb1b4 /demos | |
parent | 02d5f41c9ea5116977c68fef42a984c180c04d84 (diff) | |
download | gdk-pixbuf-50512ddcd2b2cb156d4a4e13a9f6ac21aae30ddf.tar.gz |
Remove reallocate-redraws property. This is something that only a widget
Fri May 18 14:25:20 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcontainer.c: Remove reallocate-redraws property.
This is something that only a widget writer would ever want
to change.
* gtk/gtksignal.c: Handle G_SIGNAL_TYPE_STATIC_SCOPE for
gtk_signal_emit_by_name().
* gtk/gtkviewport.c: Fix some warnings.
* gtk/gtkwidget.c gtk/gtksizegroup.c: Add "size group" facility
allowing the requisitions of multiple widgets to be grouped
together.
* tests/testgtk.c: Add GtkSizeGroup test
* demos/gtk-demo/sizegroup.c: Add GtkSizeGroup demo.
* demos/gtk-demo/main.c demos/gtk-demo/pixbufs.c: Fix some
warnings.
* configure.in: Switch to using AM_GLIB_GNU_GETTEXT.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/Makefile.am | 1 | ||||
-rw-r--r-- | demos/gtk-demo/main.c | 7 | ||||
-rw-r--r-- | demos/gtk-demo/pixbufs.c | 2 | ||||
-rw-r--r-- | demos/gtk-demo/sizegroup.c | 172 |
4 files changed, 178 insertions, 4 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index 7d199e09c..228296aec 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -14,6 +14,7 @@ demos = @STRIP_BEGIN@ \ menus.c \ panes.c \ pixbufs.c \ + sizegroup.c \ textview.c \ @STRIP_END@ diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c index 1eed34976..69710e3ad 100644 --- a/demos/gtk-demo/main.c +++ b/demos/gtk-demo/main.c @@ -1,5 +1,6 @@ #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <ctype.h> @@ -546,7 +547,7 @@ button_press_event_cb (GtkTreeView *tree_view, gtk_signal_connect (GTK_OBJECT (window), "destroy", - window_closed_cb, + GTK_SIGNAL_FUNC (window_closed_cb), cbdata); } else @@ -598,7 +599,7 @@ row_activated_cb (GtkTreeView *tree_view, gtk_signal_connect (GTK_OBJECT (window), "destroy", - window_closed_cb, + GTK_SIGNAL_FUNC (window_closed_cb), cbdata); } } @@ -714,7 +715,7 @@ create_tree (void) gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column)); - gtk_signal_connect (GTK_OBJECT (selection), "selection_changed", selection_cb, model); + gtk_signal_connect (GTK_OBJECT (selection), "selection_changed", GTK_SIGNAL_FUNC (selection_cb), model); gtk_signal_connect (GTK_OBJECT (tree_view), "row_activated", GTK_SIGNAL_FUNC (row_activated_cb), model); return tree_view; diff --git a/demos/gtk-demo/pixbufs.c b/demos/gtk-demo/pixbufs.c index 6af7ea676..5ad2774d6 100644 --- a/demos/gtk-demo/pixbufs.c +++ b/demos/gtk-demo/pixbufs.c @@ -47,7 +47,7 @@ static const char *installed_image_names[] = { #define N_IMAGES G_N_ELEMENTS (relative_image_names) /* demo window */ -static GtkWindow *window = NULL; +static GtkWidget *window = NULL; /* Current frame */ static GdkPixbuf *frame; diff --git a/demos/gtk-demo/sizegroup.c b/demos/gtk-demo/sizegroup.c new file mode 100644 index 000000000..362ffcbc0 --- /dev/null +++ b/demos/gtk-demo/sizegroup.c @@ -0,0 +1,172 @@ +/* Size Groups + * + * GtkSizeGroup provides a mechanism for grouping a number of + * widgets together so they all request the same amount of space. + * This is typically useful when you want a column of widgets to + * have the same size, but you can't use a GtkTable widget. + * + * Note that size groups only affect the amount of space requested, + * not the size that the widgets finally receive. If you want the + * widgets in a GtkSizeGroup to actually be the same size, you need + * to pack them in such a way that they get the size they request + * and not more. For example, if you are packing your widgets + * into a table, you would not include the GTK_FILL flag. + */ + +#include <gtk/gtk.h> + +static GtkWidget *window = NULL; + +/* Convenience function to create an option menu holding a number of strings + */ +GtkWidget * +create_option_menu (const char **strings) +{ + GtkWidget *menu; + GtkWidget *option_menu; + const char **str; + + menu = gtk_menu_new (); + + for (str = strings; *str; str++) + { + GtkWidget *menu_item = gtk_menu_item_new_with_label (*str); + gtk_widget_show (menu_item); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + } + + option_menu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); + + return option_menu; +} + +static void +add_row (GtkTable *table, + int row, + GtkSizeGroup *size_group, + const char *label_text, + const char **options) +{ + GtkWidget *option_menu; + GtkWidget *label; + + label = gtk_label_new (label_text); + gtk_misc_set_alignment (GTK_MISC (label), 0, 1); + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, row, row + 1, + GTK_EXPAND | GTK_FILL, 0, + 0, 0); + + option_menu = create_option_menu (options); + gtk_size_group_add_widget (size_group, option_menu); + gtk_table_attach (GTK_TABLE (table), option_menu, + 1, 2, row, row + 1, + 0, 0, + 0, 0); +} + +static void +toggle_grouping (GtkToggleButton *check_button, + GtkSizeGroup *size_group) +{ + GtkSizeGroupMode new_mode; + + /* GTK_SIZE_GROUP_NONE is not generally useful, but is useful + * here to show the effect of GTK_SIZE_GROUP_HORIZONTAL by + * contrast. + */ + if (gtk_toggle_button_get_active (check_button)) + new_mode = GTK_SIZE_GROUP_HORIZONTAL; + else + new_mode = GTK_SIZE_GROUP_NONE; + + gtk_size_group_set_mode (size_group, new_mode); +} + +GtkWidget * +do_sizegroup (void) +{ + GtkWidget *table; + GtkWidget *frame; + GtkWidget *vbox; + GtkWidget *check_button; + GtkSizeGroup *size_group; + + static const char *color_options[] = { + "Red", "Green", "Blue", NULL + }; + + static const char *dash_options[] = { + "Solid", "Dashed", "Dotted", NULL + }; + + static const char *end_options[] = { + "Square", "Round", "Arrow", NULL + }; + + if (!window) + { + window = gtk_dialog_new_with_buttons ("GtkSizeGroup", + NULL, 0, + GTK_STOCK_BUTTON_CLOSE, + GTK_RESPONSE_NONE, + NULL); + gtk_window_set_resizeable (GTK_WINDOW (window), FALSE); + + gtk_signal_connect (GTK_OBJECT (window), "response", + GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window); + + vbox = gtk_vbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); + + size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + /* Create one frame holding color options + */ + frame = gtk_frame_new ("Color Options"); + gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); + + table = gtk_table_new (2, 2, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 5); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 10); + gtk_container_add (GTK_CONTAINER (frame), table); + + add_row (GTK_TABLE (table), 0, size_group, "Foreground", color_options); + add_row (GTK_TABLE (table), 1, size_group, "Background", color_options); + + /* And another frame holding line style options + */ + frame = gtk_frame_new ("Line Options"); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); + + table = gtk_table_new (2, 2, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 5); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 10); + gtk_container_add (GTK_CONTAINER (frame), table); + + add_row (GTK_TABLE (table), 0, size_group, "Dashing", dash_options); + add_row (GTK_TABLE (table), 1, size_group, "Line ends", end_options); + + /* And a check button to turn grouping on and off */ + check_button = gtk_check_button_new_with_label ("Enable grouping"); + gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_grouping), size_group); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + gtk_widget_destroy (window); + + return window; +} |