*** 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
This commit is contained in:
parent
c4b771b8e5
commit
5496e6afc5
@ -30,9 +30,9 @@ static void print_selected(gpointer callback_data,
|
|||||||
/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
|
/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
|
||||||
static GtkItemFactoryEntry menu_items[] = {
|
static GtkItemFactoryEntry menu_items[] = {
|
||||||
{ "/_File", NULL, NULL, 0, "<Branch>" },
|
{ "/_File", NULL, NULL, 0, "<Branch>" },
|
||||||
{ "/File/_New", "<control>N", print_hello, 0, "<Item>" },
|
{ "/File/_New", "<control>N", print_hello, 0, "<StockItem>", GTK_STOCK_NEW },
|
||||||
{ "/File/_Open", "<control>O", print_hello, 0, "<Item>" },
|
{ "/File/_Open", "<control>O", print_hello, 0, "<StockItem>", GTK_STOCK_OPEN },
|
||||||
{ "/File/_Save", "<control>S", print_hello, 0, "<Item>" },
|
{ "/File/_Save", "<control>S", print_hello, 0, "<StockItem>", GTK_STOCK_SAVE },
|
||||||
{ "/File/Save _As", NULL, NULL, 0, "<Item>" },
|
{ "/File/Save _As", NULL, NULL, 0, "<Item>" },
|
||||||
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
|
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
|
||||||
{ "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT },
|
{ "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT },
|
||||||
|
@ -39,6 +39,7 @@ void cb_page_size( GtkAdjustment *get,
|
|||||||
gtk_adjustment_set_value (set, CLAMP (set->value,
|
gtk_adjustment_set_value (set, CLAMP (set->value,
|
||||||
set->lower,
|
set->lower,
|
||||||
(set->upper - set->page_size)));
|
(set->upper - set->page_size)));
|
||||||
|
g_signal_emit_by_name(G_OBJECT(set), "changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cb_draw_value( GtkToggleButton *button )
|
void cb_draw_value( GtkToggleButton *button )
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#include "gtk/gtksignal.h"
|
#include <gtk/gtksignal.h>
|
||||||
#include "gtk/gtktable.h"
|
#include <gtk/gtktable.h>
|
||||||
#include "gtk/gtktogglebutton.h"
|
#include <gtk/gtktogglebutton.h>
|
||||||
#include "tictactoe.h"
|
#include "tictactoe.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -34,7 +34,7 @@ static void tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt);
|
|||||||
static gint tictactoe_signals[LAST_SIGNAL] = { 0 };
|
static gint tictactoe_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
GType
|
GType
|
||||||
tictactoe_get_type ()
|
tictactoe_get_type (void)
|
||||||
{
|
{
|
||||||
static GType ttt_type = 0;
|
static GType ttt_type = 0;
|
||||||
|
|
||||||
@ -43,57 +43,50 @@ tictactoe_get_type ()
|
|||||||
static const GTypeInfo ttt_info =
|
static const GTypeInfo ttt_info =
|
||||||
{
|
{
|
||||||
sizeof (TictactoeClass),
|
sizeof (TictactoeClass),
|
||||||
NULL,
|
NULL, /* base_init */
|
||||||
NULL,
|
NULL, /* base_finalize */
|
||||||
(GClassInitFunc) tictactoe_class_init,
|
(GClassInitFunc) tictactoe_class_init,
|
||||||
NULL,
|
NULL, /* class_finalize */
|
||||||
NULL,
|
NULL, /* class_data */
|
||||||
sizeof (Tictactoe),
|
sizeof (Tictactoe),
|
||||||
0,
|
0,
|
||||||
(GInstanceInitFunc) tictactoe_init,
|
(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;
|
return ttt_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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",
|
tictactoe_signals[TICTACTOE_SIGNAL] = g_signal_new ("tictactoe",
|
||||||
G_TYPE_FROM_CLASS (object_class),
|
G_TYPE_FROM_CLASS (klass),
|
||||||
G_SIGNAL_RUN_FIRST,
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||||
0,
|
G_STRUCT_OFFSET (TictactoeClass, tictactoe),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
g_cclosure_marshal_VOID__VOID,
|
g_cclosure_marshal_VOID__VOID,
|
||||||
G_TYPE_NONE, 0, NULL);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
|
||||||
class->tictactoe = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tictactoe_init (Tictactoe *ttt)
|
tictactoe_init (Tictactoe *ttt)
|
||||||
{
|
{
|
||||||
GtkWidget *table;
|
|
||||||
gint i,j;
|
gint i,j;
|
||||||
|
|
||||||
table = gtk_table_new (3, 3, TRUE);
|
gtk_table_resize (GTK_TABLE (ttt), 3, 3);
|
||||||
gtk_container_add (GTK_CONTAINER (ttt), table);
|
gtk_table_set_homogeneous (GTK_TABLE (ttt), TRUE);
|
||||||
gtk_widget_show (table);
|
|
||||||
|
|
||||||
for (i=0;i<3; i++)
|
for (i=0;i<3; i++)
|
||||||
for (j = 0; j < 3; j++)
|
for (j=0;j<3; j++) {
|
||||||
{
|
|
||||||
ttt->buttons[i][j] = gtk_toggle_button_new ();
|
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);
|
i, i+1, j, j+1);
|
||||||
g_signal_connect (G_OBJECT (ttt->buttons[i][j]), "toggled",
|
g_signal_connect (G_OBJECT (ttt->buttons[i][j]), "toggled",
|
||||||
G_CALLBACK (tictactoe_toggle), (gpointer) ttt);
|
G_CALLBACK (tictactoe_toggle), (gpointer) ttt);
|
||||||
@ -116,12 +109,14 @@ tictactoe_clear (Tictactoe *ttt)
|
|||||||
for (i = 0; i<3; i++)
|
for (i = 0; i<3; i++)
|
||||||
for (j = 0; j<3; j++)
|
for (j = 0; j<3; j++)
|
||||||
{
|
{
|
||||||
g_signal_handlers_block_by_func (G_OBJECT (ttt->buttons[i][j]),
|
g_signal_handlers_block_matched (G_OBJECT (ttt->buttons[i][j]),
|
||||||
NULL, ttt);
|
G_SIGNAL_MATCH_DATA,
|
||||||
|
0, 0, NULL, NULL, ttt);
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ttt->buttons[i][j]),
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ttt->buttons[i][j]),
|
||||||
FALSE);
|
FALSE);
|
||||||
g_signal_handlers_unblock_by_func (G_OBJECT (ttt->buttons[i][j]),
|
g_signal_handlers_unblock_matched (G_OBJECT (ttt->buttons[i][j]),
|
||||||
NULL, ttt);
|
G_SIGNAL_MATCH_DATA,
|
||||||
|
0, 0, NULL, NULL, ttt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* GTK - The GIMP Toolkit
|
/* GTK - The GIMP Toolkit
|
||||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
*
|
*
|
||||||
@ -21,17 +20,18 @@
|
|||||||
#define __TICTACTOE_H__
|
#define __TICTACTOE_H__
|
||||||
|
|
||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <glib.h>
|
||||||
#include <gtk/gtkvbox.h>
|
#include <glib-object.h>
|
||||||
|
#include <gtk/gtktable.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
G_BEGIN_DECLS
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#define TICTACTOE(obj) GTK_CHECK_CAST (obj, tictactoe_get_type (), Tictactoe)
|
#define TICTACTOE_TYPE (tictactoe_get_type ())
|
||||||
#define TICTACTOE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, tictactoe_get_type (), TictactoeClass)
|
#define TICTACTOE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TICTACTOE_TYPE, Tictactoe))
|
||||||
#define IS_TICTACTOE(obj) GTK_CHECK_TYPE (obj, tictactoe_get_type ())
|
#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;
|
typedef struct _Tictactoe Tictactoe;
|
||||||
@ -39,25 +39,23 @@ typedef struct _TictactoeClass TictactoeClass;
|
|||||||
|
|
||||||
struct _Tictactoe
|
struct _Tictactoe
|
||||||
{
|
{
|
||||||
GtkVBox vbox;
|
GtkTable table;
|
||||||
|
|
||||||
GtkWidget *buttons[3][3];
|
GtkWidget *buttons[3][3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _TictactoeClass
|
struct _TictactoeClass
|
||||||
{
|
{
|
||||||
GtkVBoxClass parent_class;
|
GtkTableClass parent_class;
|
||||||
|
|
||||||
void (* tictactoe) (Tictactoe *ttt);
|
void (* tictactoe) (Tictactoe *ttt);
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkType tictactoe_get_type (void);
|
GType tictactoe_get_type (void);
|
||||||
GtkWidget* tictactoe_new (void);
|
GtkWidget* tictactoe_new (void);
|
||||||
void tictactoe_clear (Tictactoe *ttt);
|
void tictactoe_clear (Tictactoe *ttt);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
G_END_DECLS
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* __TICTACTOE_H__ */
|
#endif /* __TICTACTOE_H__ */
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ int main( int argc,
|
|||||||
gtk_container_add (GTK_CONTAINER (window), ttt);
|
gtk_container_add (GTK_CONTAINER (window), ttt);
|
||||||
gtk_widget_show (ttt);
|
gtk_widget_show (ttt);
|
||||||
|
|
||||||
|
/* And attach to its "tictactoe" signal */
|
||||||
g_signal_connect (G_OBJECT (ttt), "tictactoe",
|
g_signal_connect (G_OBJECT (ttt), "tictactoe",
|
||||||
G_CALLBACK (win), NULL);
|
G_CALLBACK (win), NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user