diff options
author | GMT 2003 Tony Gale <gale@gtk.org> | 2003-01-23 21:08:59 +0000 |
---|---|---|
committer | Tony Gale <gale@src.gnome.org> | 2003-01-23 21:08:59 +0000 |
commit | 5496e6afc5f18ec24df84c76d9e935a02e649ac9 (patch) | |
tree | 1f39223098efe2dea8dee8b334f5a617562bc44e /examples | |
parent | c4b771b8e5e1a7c6076f39f811b923030c7a0a19 (diff) | |
download | gtk+-5496e6afc5f18ec24df84c76d9e935a02e649ac9.tar.gz |
*** RETRY - last commit aborted half way through
Thu Jan 23 20:56:56 GMT 2003 Tony Gale <gale@gtk.org>
* Sebastian Rittau <srittau@jroger.in-berlin.de>:
docs/tutorial/gtk-tut.sgml: Adopted chapter 21.3 "Creating a
Composite widget" to modern standards. (I.e. use gobject instead of
glib, derive from GtkTable instead of GtkVBox.) Bugzilla #103869.
* docs/tutorial/gtk-tut.sgml, examples/tictactoe: Fixup tic-tac-toe
code in Appendix C to reflect above changes.
* examples/rangewidgets/rangewidgets.c: From Roger Leigh
auto resize on page size change
Diffstat (limited to 'examples')
-rw-r--r-- | examples/menu/itemfactory.c | 6 | ||||
-rw-r--r-- | examples/rangewidgets/rangewidgets.c | 1 | ||||
-rw-r--r-- | examples/tictactoe/tictactoe.c | 63 | ||||
-rw-r--r-- | examples/tictactoe/tictactoe.h | 28 | ||||
-rw-r--r-- | examples/tictactoe/ttt_test.c | 1 |
5 files changed, 47 insertions, 52 deletions
diff --git a/examples/menu/itemfactory.c b/examples/menu/itemfactory.c index 05923101b2..21082d715c 100644 --- a/examples/menu/itemfactory.c +++ b/examples/menu/itemfactory.c @@ -30,9 +30,9 @@ static void print_selected(gpointer callback_data, /* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */ static GtkItemFactoryEntry menu_items[] = { { "/_File", NULL, NULL, 0, "<Branch>" }, - { "/File/_New", "<control>N", print_hello, 0, "<Item>" }, - { "/File/_Open", "<control>O", print_hello, 0, "<Item>" }, - { "/File/_Save", "<control>S", print_hello, 0, "<Item>" }, + { "/File/_New", "<control>N", print_hello, 0, "<StockItem>", GTK_STOCK_NEW }, + { "/File/_Open", "<control>O", print_hello, 0, "<StockItem>", GTK_STOCK_OPEN }, + { "/File/_Save", "<control>S", print_hello, 0, "<StockItem>", GTK_STOCK_SAVE }, { "/File/Save _As", NULL, NULL, 0, "<Item>" }, { "/File/sep1", NULL, NULL, 0, "<Separator>" }, { "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, diff --git a/examples/rangewidgets/rangewidgets.c b/examples/rangewidgets/rangewidgets.c index 457dd6a4a3..be4b6cc092 100644 --- a/examples/rangewidgets/rangewidgets.c +++ b/examples/rangewidgets/rangewidgets.c @@ -39,6 +39,7 @@ void cb_page_size( GtkAdjustment *get, gtk_adjustment_set_value (set, CLAMP (set->value, set->lower, (set->upper - set->page_size))); + g_signal_emit_by_name(G_OBJECT(set), "changed"); } void cb_draw_value( GtkToggleButton *button ) diff --git a/examples/tictactoe/tictactoe.c b/examples/tictactoe/tictactoe.c index bb17d3f5f1..271b3678aa 100644 --- a/examples/tictactoe/tictactoe.c +++ b/examples/tictactoe/tictactoe.c @@ -17,9 +17,9 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include "gtk/gtksignal.h" -#include "gtk/gtktable.h" -#include "gtk/gtktogglebutton.h" +#include <gtk/gtksignal.h> +#include <gtk/gtktable.h> +#include <gtk/gtktogglebutton.h> #include "tictactoe.h" enum { @@ -34,7 +34,7 @@ static void tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt); static gint tictactoe_signals[LAST_SIGNAL] = { 0 }; GType -tictactoe_get_type () +tictactoe_get_type (void) { static GType ttt_type = 0; @@ -43,57 +43,50 @@ tictactoe_get_type () static const GTypeInfo ttt_info = { sizeof (TictactoeClass), - NULL, - NULL, + NULL, /* base_init */ + NULL, /* base_finalize */ (GClassInitFunc) tictactoe_class_init, - NULL, - NULL, + NULL, /* class_finalize */ + NULL, /* class_data */ sizeof (Tictactoe), 0, (GInstanceInitFunc) tictactoe_init, }; - ttt_type = g_type_register_static (GTK_TYPE_VBOX, "Tictactoe", &ttt_info, 0); + ttt_type = g_type_register_static (GTK_TYPE_TABLE, "Tictactoe", &ttt_info, 0); } return ttt_type; } static void -tictactoe_class_init (TictactoeClass *class) +tictactoe_class_init (TictactoeClass *klass) { - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) class; tictactoe_signals[TICTACTOE_SIGNAL] = g_signal_new ("tictactoe", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - 0, + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (TictactoeClass, tictactoe), NULL, NULL, g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0, NULL); + G_TYPE_NONE, 0); - class->tictactoe = NULL; } static void tictactoe_init (Tictactoe *ttt) { - GtkWidget *table; gint i,j; - table = gtk_table_new (3, 3, TRUE); - gtk_container_add (GTK_CONTAINER (ttt), table); - gtk_widget_show (table); + gtk_table_resize (GTK_TABLE (ttt), 3, 3); + gtk_table_set_homogeneous (GTK_TABLE (ttt), TRUE); - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) - { + for (i=0;i<3; i++) + for (j=0;j<3; j++) { ttt->buttons[i][j] = gtk_toggle_button_new (); - gtk_table_attach_defaults (GTK_TABLE (table), ttt->buttons[i][j], + gtk_table_attach_defaults (GTK_TABLE (ttt), ttt->buttons[i][j], i, i+1, j, j+1); g_signal_connect (G_OBJECT (ttt->buttons[i][j]), "toggled", G_CALLBACK (tictactoe_toggle), (gpointer) ttt); @@ -113,15 +106,17 @@ tictactoe_clear (Tictactoe *ttt) { int i,j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i<3; i++) + for (j = 0; j<3; j++) { - g_signal_handlers_block_by_func (G_OBJECT (ttt->buttons[i][j]), - NULL, ttt); + g_signal_handlers_block_matched (G_OBJECT (ttt->buttons[i][j]), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, ttt); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ttt->buttons[i][j]), FALSE); - g_signal_handlers_unblock_by_func (G_OBJECT (ttt->buttons[i][j]), - NULL, ttt); + g_signal_handlers_unblock_matched (G_OBJECT (ttt->buttons[i][j]), + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, ttt); } } @@ -139,12 +134,12 @@ tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt) int success, found; - for (k = 0; k < 8; k++) + for (k = 0; k<8; k++) { success = TRUE; found = FALSE; - for (i = 0; i < 3; i++) + for (i = 0; i<3; i++) { success = success && GTK_TOGGLE_BUTTON (ttt->buttons[rwins[k][i]][cwins[k][i]])->active; diff --git a/examples/tictactoe/tictactoe.h b/examples/tictactoe/tictactoe.h index f36df1913e..e48f753dd5 100644 --- a/examples/tictactoe/tictactoe.h +++ b/examples/tictactoe/tictactoe.h @@ -1,4 +1,3 @@ - /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * @@ -21,17 +20,18 @@ #define __TICTACTOE_H__ -#include <gdk/gdk.h> -#include <gtk/gtkvbox.h> +#include <glib.h> +#include <glib-object.h> +#include <gtk/gtktable.h> -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS -#define TICTACTOE(obj) GTK_CHECK_CAST (obj, tictactoe_get_type (), Tictactoe) -#define TICTACTOE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, tictactoe_get_type (), TictactoeClass) -#define IS_TICTACTOE(obj) GTK_CHECK_TYPE (obj, tictactoe_get_type ()) +#define TICTACTOE_TYPE (tictactoe_get_type ()) +#define TICTACTOE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TICTACTOE_TYPE, Tictactoe)) +#define TICTACTOE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TICTACTOE_TYPE, TictactoeClass)) +#define IS_TICTACTOE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TICTACTOE_TYPE)) +#define IS_TICTACTOE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TICTACTOE_TYPE)) typedef struct _Tictactoe Tictactoe; @@ -39,25 +39,23 @@ typedef struct _TictactoeClass TictactoeClass; struct _Tictactoe { - GtkVBox vbox; + GtkTable table; GtkWidget *buttons[3][3]; }; struct _TictactoeClass { - GtkVBoxClass parent_class; + GtkTableClass parent_class; void (* tictactoe) (Tictactoe *ttt); }; -GtkType tictactoe_get_type (void); +GType tictactoe_get_type (void); GtkWidget* tictactoe_new (void); void tictactoe_clear (Tictactoe *ttt); -#ifdef __cplusplus -} -#endif /* __cplusplus */ +G_END_DECLS #endif /* __TICTACTOE_H__ */ diff --git a/examples/tictactoe/ttt_test.c b/examples/tictactoe/ttt_test.c index 6065593e64..0f8a0f12e5 100644 --- a/examples/tictactoe/ttt_test.c +++ b/examples/tictactoe/ttt_test.c @@ -32,6 +32,7 @@ int main( int argc, gtk_container_add (GTK_CONTAINER (window), ttt); gtk_widget_show (ttt); + /* And attach to its "tictactoe" signal */ g_signal_connect (G_OBJECT (ttt), "tictactoe", G_CALLBACK (win), NULL); |