diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-10-18 15:50:13 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-10-18 15:50:13 +0000 |
commit | 7420908815651a1ff2ceb1c0fb5e92fe9b260619 (patch) | |
tree | d5f528e39a5b20ac5ba3e88ddea0e8b4f81bbad8 | |
parent | 92bbfd05a879df21bcc44fc1d48ec217bee1d8ae (diff) | |
download | gdk-pixbuf-7420908815651a1ff2ceb1c0fb5e92fe9b260619.tar.gz |
Start of work to move to new modularized testgtk.
Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com>
* configure.in demos/Makefile.am demos/testgtk/*: Start of work to
move to new modularized testgtk.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-0 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-2 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 7 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | demos/Makefile.am | 2 | ||||
-rw-r--r-- | demos/gtk-demo/.cvsignore | 7 | ||||
-rw-r--r-- | demos/gtk-demo/Makefile.am | 56 | ||||
-rw-r--r-- | demos/gtk-demo/button_box.c | 122 | ||||
-rwxr-xr-x | demos/gtk-demo/geninclude.pl | 40 | ||||
-rwxr-xr-x | demos/gtk-demo/geninclude.pl.in | 40 | ||||
-rw-r--r-- | demos/gtk-demo/item_factory.c | 118 | ||||
-rw-r--r-- | demos/gtk-demo/main.c | 324 | ||||
-rw-r--r-- | demos/gtk-demo/menus.c | 187 | ||||
-rw-r--r-- | demos/gtk-demo/panes.c | 188 | ||||
-rw-r--r-- | demos/testgtk/.cvsignore | 7 | ||||
-rw-r--r-- | demos/testgtk/Makefile.am | 56 | ||||
-rw-r--r-- | demos/testgtk/button_box.c | 122 | ||||
-rwxr-xr-x | demos/testgtk/geninclude.pl | 40 | ||||
-rw-r--r-- | demos/testgtk/item_factory.c | 118 | ||||
-rw-r--r-- | demos/testgtk/main.c | 324 | ||||
-rw-r--r-- | demos/testgtk/menus.c | 187 | ||||
-rw-r--r-- | demos/testgtk/panes.c | 188 |
26 files changed, 2169 insertions, 7 deletions
@@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 39b997a3f..6ab294324 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +Wed Oct 18 11:14:05 2000 Owen Taylor <otaylor@redhat.com> + + * configure.in demos/Makefile.am demos/testgtk/*: Start of work to + move to new modularized testgtk. + 2000-10-17 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c: Draw the arrows correctly. @@ -141,7 +146,7 @@ * gdk/gdkwindow.c (gdk_window_draw_arc): Fix obvious bug in circle drawing. -Wed Oct 4 15:52:15 2000 <otaylor@redhat.com> +Wed Oct 4 15:52:15 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (_gdk_selection_window_destroyed): Move list pointer forwards before removing item from diff --git a/configure.in b/configure.in index 452e543c1..2987f97a9 100644 --- a/configure.in +++ b/configure.in @@ -1020,6 +1020,7 @@ po/Makefile.in build/Makefile build/win32/Makefile demos/Makefile +demos/testgtk/Makefile docs/Makefile docs/reference/Makefile docs/reference/gdk-pixbuf/Makefile diff --git a/demos/Makefile.am b/demos/Makefile.am index 3aa45b422..34baf2935 100644 --- a/demos/Makefile.am +++ b/demos/Makefile.am @@ -1,5 +1,7 @@ ## Makefile.am for gtk+/demos +SUBDIRS = testgtk + INCLUDES = @STRIP_BEGIN@ \ -I$(top_srcdir) \ -I$(top_builddir)/gdk \ diff --git a/demos/gtk-demo/.cvsignore b/demos/gtk-demo/.cvsignore new file mode 100644 index 000000000..67b6fe524 --- /dev/null +++ b/demos/gtk-demo/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +.libs +.deps +testgtk +demos.h + diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am new file mode 100644 index 000000000..e2dbd160e --- /dev/null +++ b/demos/gtk-demo/Makefile.am @@ -0,0 +1,56 @@ +## Makefile.am for gtk+/demos + +demos = @STRIP_BEGIN@ \ + button_box.c \ + item_factory.c \ + menus.c \ + panes.c \ +@STRIP_END@ + +INCLUDES = @STRIP_BEGIN@ \ + -I$(top_srcdir) \ + -I$(top_builddir)/gdk \ + -DGTK_DISABLE_COMPAT_H \ + @GTK_DEBUG_FLAGS@ \ + @GTK_XIM_FLAGS@ \ + @GTK_LOCALE_FLAGS@ \ + @PANGO_CFLAGS@ \ + @GLIB_CFLAGS@ \ + @more_cflags@ \ +@STRIP_END@ + +DEPS = \ + $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-1.3.la \ + $(top_builddir)/gdk/@gdktargetlib@ \ + $(top_builddir)/gtk/@gtktargetlib@ + +LDADDS = @STRIP_BEGIN@ \ + $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-1.3.la \ + $(top_builddir)/gdk/@gdktargetlib@ \ + $(top_builddir)/gtk/@gtktargetlib@ \ + @more_ldflags@ \ + @more_libs@ \ + @GDK_WLIBS@ \ + @PANGO_LIBS@ \ + @GLIB_LIBS@ \ + @GTK_LIBS_EXTRA@ \ + -lm \ +@STRIP_END@ + +noinst_PROGRAMS = testgtk + +BUILT_SOURCES = demos.h + +EXTRA_DIST = \ + geninclude.pl + +demos.h: $(demos) geninclude.pl + (cd $(srcdir) && ./geninclude.pl $(demos) > demos.h) + +testgtk_SOURCES = \ + $(demos) \ + main.c \ + demos.h + +testgtk_DEPENDENCIES = $(DEPS) +testgtk_LDADD = $(LDADDS) diff --git a/demos/gtk-demo/button_box.c b/demos/gtk-demo/button_box.c new file mode 100644 index 000000000..432bfbbfc --- /dev/null +++ b/demos/gtk-demo/button_box.c @@ -0,0 +1,122 @@ +/* Button Boxes + * + * The Button Box widgets are used to arrange buttons with padding. + */ + +#include <gtk/gtk.h> + +static GtkWidget * +create_bbox (gint horizontal, + char* title, + gint spacing, + gint child_w, + gint child_h, + gint layout) +{ + GtkWidget *frame; + GtkWidget *bbox; + GtkWidget *button; + + frame = gtk_frame_new (title); + + if (horizontal) + bbox = gtk_hbutton_box_new (); + else + bbox = gtk_vbutton_box_new (); + + gtk_container_set_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); + + button = gtk_button_new_with_label ("OK"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + button = gtk_button_new_with_label ("Cancel"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + button = gtk_button_new_with_label ("Help"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + return frame; +} + +void +do_button_box (void) +{ + static GtkWidget* window = NULL; + 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 Boxes"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + + main_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), main_vbox); + + frame_horz = gtk_frame_new ("Horizontal Button Boxes"); + gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_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); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_set_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_all (window); + else + gtk_widget_destroy (window); +} + diff --git a/demos/gtk-demo/geninclude.pl b/demos/gtk-demo/geninclude.pl new file mode 100755 index 000000000..31036cc39 --- /dev/null +++ b/demos/gtk-demo/geninclude.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +print <<EOT; +typedef struct _Demo Demo; + +struct _Demo +{ + gchar *title; + gchar *filename; + void (*func) (void); +}; + +EOT + +$array = ""; +$first = 1; +for $file (@ARGV) { + + ($basename = $file) =~ s/\.c$//; + + if ($first) { + $first = 0; + } else { + $array .= ",\n"; + } + + open INFO_FILE, $file or die "Cannot open '$file'\n"; + $title = <INFO_FILE>; + $title =~ s@^\s*/\*\s*@@; + $title =~ s@\s*$@@; + + close INFO_FILE; + + print "void do_$basename (void);\n"; + $array .= qq( { "$title", "$file", do_$basename }); +} + +print "\nDemo testgtk_demos[] = {"; +print $array; +print "\n};\n"; diff --git a/demos/gtk-demo/geninclude.pl.in b/demos/gtk-demo/geninclude.pl.in new file mode 100755 index 000000000..31036cc39 --- /dev/null +++ b/demos/gtk-demo/geninclude.pl.in @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +print <<EOT; +typedef struct _Demo Demo; + +struct _Demo +{ + gchar *title; + gchar *filename; + void (*func) (void); +}; + +EOT + +$array = ""; +$first = 1; +for $file (@ARGV) { + + ($basename = $file) =~ s/\.c$//; + + if ($first) { + $first = 0; + } else { + $array .= ",\n"; + } + + open INFO_FILE, $file or die "Cannot open '$file'\n"; + $title = <INFO_FILE>; + $title =~ s@^\s*/\*\s*@@; + $title =~ s@\s*$@@; + + close INFO_FILE; + + print "void do_$basename (void);\n"; + $array .= qq( { "$title", "$file", do_$basename }); +} + +print "\nDemo testgtk_demos[] = {"; +print $array; +print "\n};\n"; diff --git a/demos/gtk-demo/item_factory.c b/demos/gtk-demo/item_factory.c new file mode 100644 index 000000000..4e808f9da --- /dev/null +++ b/demos/gtk-demo/item_factory.c @@ -0,0 +1,118 @@ +/* Item Factory + * + * The GtkItemFactory object allows the easy creation of menus + * from an array of descriptions of menu items. + */ + +#include <gtk/gtk.h> + +static void +gtk_ifactory_cb (gpointer callback_data, + guint callback_action, + GtkWidget *widget) +{ + g_message ("ItemFactory: activated \"%s\"", gtk_item_factory_path_from_widget (widget)); +} + +static GtkItemFactoryEntry menu_items[] = +{ + { "/_File", NULL, 0, 0, "<Branch>" }, + { "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" }, + { "/File/_New", "<control>N", gtk_ifactory_cb, 0 }, + { "/File/_Open", "<control>O", gtk_ifactory_cb, 0 }, + { "/File/_Save", "<control>S", gtk_ifactory_cb, 0 }, + { "/File/Save _As...", NULL, gtk_ifactory_cb, 0 }, + { "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" }, + { "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 }, + + { "/_Preferences", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/_Color", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, + { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, + { "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, + { "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, + { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" }, + { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" }, + + { "/_Help", NULL, 0, 0, "<LastBranch>" }, + { "/Help/_About", NULL, gtk_ifactory_cb, 0 }, +}; + +static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); + +void +do_item_factory (void) +{ + static GtkWidget *window = NULL; + + if (!window) + { + GtkWidget *box1; + GtkWidget *box2; + GtkWidget *separator; + GtkWidget *label; + GtkWidget *button; + GtkAccelGroup *accel_group; + GtkItemFactory *item_factory; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + gtk_signal_connect (GTK_OBJECT (window), "delete-event", + GTK_SIGNAL_FUNC (gtk_true), + NULL); + + accel_group = gtk_accel_group_new (); + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); + gtk_object_set_data_full (GTK_OBJECT (window), + "<main>", + item_factory, + (GtkDestroyNotify) gtk_object_unref); + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + gtk_window_set_title (GTK_WINDOW (window), "Item Factory"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); + + /* preselect /Preferences/Shape/Oval over the other radios + */ + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory, + "/Preferences/Shape/Oval")), + TRUE); + + box1 = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box1); + + gtk_box_pack_start (GTK_BOX (box1), + gtk_item_factory_get_widget (item_factory, "<main>"), + FALSE, FALSE, 0); + + label = gtk_label_new ("Type\n<alt>\nto start"); + gtk_widget_set_usize (label, 200, 200); + gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); + gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0); + + + separator = gtk_hseparator_new (); + gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); + + + box2 = gtk_vbox_new (FALSE, 10); + gtk_container_set_border_width (GTK_CONTAINER (box2), 10); + gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); + + button = gtk_button_new_with_label ("close"); + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (window)); + 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_all (window); + } + else + gtk_widget_destroy (window); +} diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c new file mode 100644 index 000000000..2e0649f7c --- /dev/null +++ b/demos/gtk-demo/main.c @@ -0,0 +1,324 @@ +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#include <gtk/gtk.h> + +#include <demos.h> + +static GtkTextBuffer *info_buffer; +static GtkTextBuffer *source_buffer; +static GtkWidget *demo_clist; + +static Demo *current_demo; + +gboolean +read_line (FILE *stream, GString *str) +{ + int n_read = 0; + + flockfile (stream); + + g_string_truncate (str, 0); + + while (1) + { + int c; + + c = getc_unlocked (stream); + + if (c == EOF) + goto done; + else + n_read++; + + switch (c) + { + case '\r': + case '\n': + { + int next_c = getc_unlocked (stream); + + if (!(next_c == EOF || + (c == '\r' && next_c == '\n') || + (c == '\n' && next_c == '\r'))) + ungetc (next_c, stream); + + goto done; + } + default: + g_string_append_c (str, c); + } + } + + done: + + funlockfile (stream); + + return n_read > 0; +} + +void +load_file (Demo *demo) +{ + FILE *file; + GtkTextIter start, end; + GString *buffer = g_string_new (NULL); + int state = 0; + gboolean in_para = 0; + + if (current_demo == demo) + return; + + current_demo = demo; + + gtk_text_buffer_get_bounds (info_buffer, &start, &end); + gtk_text_buffer_delete (info_buffer, &start, &end); + + gtk_text_buffer_get_bounds (source_buffer, &start, &end); + gtk_text_buffer_delete (source_buffer, &start, &end); + + file = fopen (demo->filename, "r"); + if (!file) + { + g_warning ("Cannot open %s: %s\n", demo->filename, g_strerror (errno)); + return; + } + + gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0); + while (read_line (file, buffer)) + { + gchar *p = buffer->str; + gchar *q; + + switch (state) + { + case 0: + /* Reading title */ + while (*p == '/' || *p == '*' || isspace (*p)) + p++; + q = p + strlen (p); + while (q > p && isspace (*(q - 1))) + q--; + + if (q > p) + { + int len_chars = g_utf8_pointer_to_offset (p, q); + + end = start; + + g_assert (strlen (p) >= q - p); + gtk_text_buffer_insert (info_buffer, &end, p, q - p); + start = end; + + gtk_text_iter_backward_chars (&start, len_chars); + gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end); + + start = end; + + state++; + } + break; + + case 1: + /* Reading body of info section */ + while (isspace (*p)) + p++; + if (*p == '*' && *(p + 1) == '/') + { + gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0); + state++; + } + else + { + int len; + + while (*p == '*' || isspace (*p)) + p++; + + len = strlen (p); + while (isspace (*(p + len - 1))) + len--; + + if (len > 0) + { + if (in_para) + gtk_text_buffer_insert (info_buffer, &start, " ", 1); + + g_assert (strlen (p) >= len); + gtk_text_buffer_insert (info_buffer, &start, p, len); + in_para = 1; + } + else + { + gtk_text_buffer_insert (info_buffer, &start, "\n", 1); + in_para = 0; + } + } + break; + + case 2: + /* Skipping blank lines */ + while (isspace (*p)) + p++; + if (*p) + { + p = buffer->str; + state++; + /* Fall through */ + } + else + break; + + case 3: + /* Reading program body */ + gtk_text_buffer_insert (source_buffer, &start, p, -1); + gtk_text_buffer_insert (info_buffer, &start, "\n", 1); + break; + } + } + + gtk_text_buffer_get_bounds (source_buffer, &start, &end); + gtk_text_buffer_apply_tag_by_name (info_buffer, "source", &start, &end); +} + +gboolean +button_press_event_cb (GtkCList *clist, + GdkEventButton *event) +{ + if (event->type == GDK_2BUTTON_PRESS && + event->window == clist->clist_window) + { + gint row, column; + + if (gtk_clist_get_selection_info (clist, + event->x, event->y, + &row, &column)) + + { + Demo *demo = gtk_clist_get_row_data (clist, row); + demo->func(); + } + + gtk_signal_emit_stop_by_name (GTK_OBJECT (clist), "button_press_event"); + return TRUE; + } + + return FALSE; +} + +void +select_row_cb (GtkCList *clist, + gint row, + gint column, + GdkEvent *event) +{ + Demo *demo = gtk_clist_get_row_data (clist, row); + load_file (demo); +} + +GtkWidget * +create_text (GtkTextBuffer **buffer, + gboolean is_source) +{ + GtkWidget *scrolled_window; + GtkWidget *text_view; + PangoFontDescription *font_desc; + + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_SHADOW_IN); + + text_view = gtk_text_view_new (); + gtk_container_add (GTK_CONTAINER (scrolled_window), text_view); + + *buffer = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), *buffer); + gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE); + + if (is_source) + { + font_desc = pango_font_description_from_string ("Courier 10"); + gtk_widget_modify_font (text_view, font_desc); + pango_font_description_free (font_desc); + } + + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), !is_source); + + return scrolled_window; +} + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *notebook; + GtkWidget *hbox; + GtkTextTag *tag; + int i; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), hbox); + + demo_clist = gtk_clist_new (1); + gtk_clist_set_selection_mode (GTK_CLIST (demo_clist), GTK_SELECTION_BROWSE); + + gtk_widget_set_usize (demo_clist, 200, -1); + gtk_box_pack_start (GTK_BOX (hbox), demo_clist, FALSE, FALSE, 0); + + notebook = gtk_notebook_new (); + gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0); + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), + create_text (&info_buffer, FALSE), + gtk_label_new ("Info")); + + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), + create_text (&source_buffer, TRUE), + gtk_label_new ("Source")); + + tag = gtk_text_buffer_create_tag (info_buffer, "title"); + gtk_object_set (GTK_OBJECT (tag), + "font", "Sans 18", + NULL); + + tag = gtk_text_buffer_create_tag (info_buffer, "source"); + gtk_object_set (GTK_OBJECT (tag), + "font", "Courier 10", + "pixels_above_lines", 0, + "pixels_below_lines", 0, + NULL); + + gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); + gtk_widget_show_all (window); + + for (i=0; i < G_N_ELEMENTS (testgtk_demos); i++) + { + gint row = gtk_clist_append (GTK_CLIST (demo_clist), &testgtk_demos[i].title); + gtk_clist_set_row_data (GTK_CLIST (demo_clist), row, &testgtk_demos[i]); + } + + load_file (&testgtk_demos[0]); + + gtk_signal_connect (GTK_OBJECT (demo_clist), "button_press_event", + GTK_SIGNAL_FUNC (button_press_event_cb), NULL); + + gtk_signal_connect (GTK_OBJECT (demo_clist), "select_row", + GTK_SIGNAL_FUNC (select_row_cb), NULL); + + gtk_main (); + + return 0; +} diff --git a/demos/gtk-demo/menus.c b/demos/gtk-demo/menus.c new file mode 100644 index 000000000..8c394cd28 --- /dev/null +++ b/demos/gtk-demo/menus.c @@ -0,0 +1,187 @@ +/* Menus + * + * GTK+ includes a number of widgets for menus of actions. + * GtkMenu is a drop-down menu, GtkMenuBar a horizontal menu bar. + * Each of these widgets can hold various types of menuitem. + * As well as the base type, GtkMenuItem, there are GtkCheckMenuItem, + * GtkRadioMenuItem and GtkTearoffMenuItem. + */ + +#include <stdio.h> + +#include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> + +static GtkWidget* +create_menu (gint depth, gboolean tearoff) +{ + GtkWidget *menu; + GtkWidget *menuitem; + GSList *group; + char buf[32]; + int i, j; + + if (depth < 1) + return NULL; + + menu = gtk_menu_new (); + group = NULL; + + if (tearoff) + { + menuitem = gtk_tearoff_menu_item_new (); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + } + + for (i = 0, j = 1; i < 5; i++, j++) + { + sprintf (buf, "item %2d - %d", depth, j); + menuitem = gtk_radio_menu_item_new_with_label (group, buf); + group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); + if (depth % 2) + gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), TRUE); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + if (i == 3) + gtk_widget_set_sensitive (menuitem, FALSE); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE)); + } + + return menu; +} + +void +do_menus (void) +{ + static GtkWidget *window = NULL; + GtkWidget *box1; + GtkWidget *box2; + GtkWidget *button; + GtkWidget *optionmenu; + GtkWidget *separator; + + if (!window) + { + GtkWidget *menubar; + GtkWidget *menu; + GtkWidget *menuitem; + GtkAccelGroup *accel_group; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + gtk_signal_connect (GTK_OBJECT (window), "delete-event", + GTK_SIGNAL_FUNC (gtk_true), + NULL); + + accel_group = gtk_accel_group_new (); + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + + gtk_window_set_title (GTK_WINDOW (window), "menus"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + + box1 = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box1); + gtk_widget_show (box1); + + menubar = gtk_menu_bar_new (); + gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0); + gtk_widget_show (menubar); + + menu = create_menu (2, TRUE); + + menuitem = gtk_menu_item_new_with_label ("test\nline2"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + menuitem = gtk_menu_item_new_with_label ("foo"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE)); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + menuitem = gtk_menu_item_new_with_label ("bar"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE)); + gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem)); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + box2 = gtk_vbox_new (FALSE, 10); + gtk_container_set_border_width (GTK_CONTAINER (box2), 10); + gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); + gtk_widget_show (box2); + + menu = create_menu (1, FALSE); + gtk_menu_set_accel_group (GTK_MENU (menu), accel_group); + + menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F1, + 0, + GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE); + menuitem = gtk_check_menu_item_new_with_label ("Accelerator Locked"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F2, + 0, + GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); + menuitem = gtk_check_menu_item_new_with_label ("Accelerators Frozen"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F2, + 0, + GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F3, + 0, + GTK_ACCEL_VISIBLE); + gtk_widget_lock_accelerators (menuitem); + + optionmenu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 3); + gtk_box_pack_start (GTK_BOX (box2), optionmenu, TRUE, TRUE, 0); + gtk_widget_show (optionmenu); + + 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_set_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", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (window)); + 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); + else + gtk_widget_destroy (window); +} + diff --git a/demos/gtk-demo/panes.c b/demos/gtk-demo/panes.c new file mode 100644 index 000000000..718f8969b --- /dev/null +++ b/demos/gtk-demo/panes.c @@ -0,0 +1,188 @@ +/* Paned Widgets + * + * The GtkHPaned and GtkVPaned Widgets divide their content + * area into two panes with a divider in between that the + * user can adjust. A separate child is placed into each + * pane. + * + * There are a number of options that can be set for each pane. + * This test contains both a horizontal (HPaned) and a vertical + * (VPaned) widget, and allows you to adjust the options for + * each side of each widget. + */ + +#include <gtk/gtk.h> + +void +toggle_resize (GtkWidget *widget, GtkWidget *child) +{ + GtkPaned *paned = GTK_PANED (child->parent); + gboolean is_child1 = (child == paned->child1); + gboolean resize, shrink; + + resize = is_child1 ? paned->child1_resize : paned->child2_resize; + shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; + + gtk_widget_ref (child); + gtk_container_remove (GTK_CONTAINER (child->parent), child); + if (is_child1) + gtk_paned_pack1 (paned, child, !resize, shrink); + else + gtk_paned_pack2 (paned, child, !resize, shrink); + gtk_widget_unref (child); +} + +void +toggle_shrink (GtkWidget *widget, GtkWidget *child) +{ + GtkPaned *paned = GTK_PANED (child->parent); + gboolean is_child1 = (child == paned->child1); + gboolean resize, shrink; + + resize = is_child1 ? paned->child1_resize : paned->child2_resize; + shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; + + gtk_widget_ref (child); + gtk_container_remove (GTK_CONTAINER (child->parent), child); + if (is_child1) + gtk_paned_pack1 (paned, child, resize, !shrink); + else + gtk_paned_pack2 (paned, child, resize, !shrink); + gtk_widget_unref (child); +} + +GtkWidget * +create_pane_options (GtkPaned *paned, + const gchar *frame_label, + const gchar *label1, + const gchar *label2) +{ + GtkWidget *frame; + GtkWidget *table; + GtkWidget *label; + GtkWidget *check_button; + + frame = gtk_frame_new (frame_label); + gtk_container_set_border_width (GTK_CONTAINER (frame), 4); + + table = gtk_table_new (3, 2, 4); + gtk_container_add (GTK_CONTAINER (frame), table); + + label = gtk_label_new (label1); + gtk_table_attach_defaults (GTK_TABLE (table), label, + 0, 1, 0, 1); + + check_button = gtk_check_button_new_with_label ("Resize"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 0, 1, 1, 2); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_resize), + paned->child1); + + check_button = gtk_check_button_new_with_label ("Shrink"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 0, 1, 2, 3); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_shrink), + paned->child1); + + label = gtk_label_new (label2); + gtk_table_attach_defaults (GTK_TABLE (table), label, + 1, 2, 0, 1); + + check_button = gtk_check_button_new_with_label ("Resize"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 1, 2, 1, 2); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_resize), + paned->child2); + + check_button = gtk_check_button_new_with_label ("Shrink"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 1, 2, 2, 3); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_shrink), + paned->child2); + + return frame; +} + +void +do_panes (void) +{ + static GtkWidget *window = NULL; + GtkWidget *frame; + GtkWidget *hpaned; + GtkWidget *vpaned; + GtkWidget *button; + GtkWidget *vbox; + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + + gtk_window_set_title (GTK_WINDOW (window), "Panes"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + vpaned = gtk_vpaned_new (); + gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER(vpaned), 5); + + hpaned = gtk_hpaned_new (); + gtk_paned_add1 (GTK_PANED (vpaned), hpaned); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 60, 60); + gtk_paned_add1 (GTK_PANED (hpaned), frame); + + button = gtk_button_new_with_label ("Hi there"); + gtk_container_add (GTK_CONTAINER(frame), button); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 80, 60); + gtk_paned_add2 (GTK_PANED (hpaned), frame); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 60, 80); + gtk_paned_add2 (GTK_PANED (vpaned), frame); + + /* Now create toggle buttons to control sizing */ + + gtk_box_pack_start (GTK_BOX (vbox), + create_pane_options (GTK_PANED (hpaned), + "Horizontal", + "Left", + "Right"), + FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (vbox), + create_pane_options (GTK_PANED (vpaned), + "Vertical", + "Top", + "Bottom"), + FALSE, FALSE, 0); + + gtk_widget_show_all (vbox); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show (window); + else + gtk_widget_destroy (window); +} diff --git a/demos/testgtk/.cvsignore b/demos/testgtk/.cvsignore new file mode 100644 index 000000000..67b6fe524 --- /dev/null +++ b/demos/testgtk/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +.libs +.deps +testgtk +demos.h + diff --git a/demos/testgtk/Makefile.am b/demos/testgtk/Makefile.am new file mode 100644 index 000000000..e2dbd160e --- /dev/null +++ b/demos/testgtk/Makefile.am @@ -0,0 +1,56 @@ +## Makefile.am for gtk+/demos + +demos = @STRIP_BEGIN@ \ + button_box.c \ + item_factory.c \ + menus.c \ + panes.c \ +@STRIP_END@ + +INCLUDES = @STRIP_BEGIN@ \ + -I$(top_srcdir) \ + -I$(top_builddir)/gdk \ + -DGTK_DISABLE_COMPAT_H \ + @GTK_DEBUG_FLAGS@ \ + @GTK_XIM_FLAGS@ \ + @GTK_LOCALE_FLAGS@ \ + @PANGO_CFLAGS@ \ + @GLIB_CFLAGS@ \ + @more_cflags@ \ +@STRIP_END@ + +DEPS = \ + $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-1.3.la \ + $(top_builddir)/gdk/@gdktargetlib@ \ + $(top_builddir)/gtk/@gtktargetlib@ + +LDADDS = @STRIP_BEGIN@ \ + $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-1.3.la \ + $(top_builddir)/gdk/@gdktargetlib@ \ + $(top_builddir)/gtk/@gtktargetlib@ \ + @more_ldflags@ \ + @more_libs@ \ + @GDK_WLIBS@ \ + @PANGO_LIBS@ \ + @GLIB_LIBS@ \ + @GTK_LIBS_EXTRA@ \ + -lm \ +@STRIP_END@ + +noinst_PROGRAMS = testgtk + +BUILT_SOURCES = demos.h + +EXTRA_DIST = \ + geninclude.pl + +demos.h: $(demos) geninclude.pl + (cd $(srcdir) && ./geninclude.pl $(demos) > demos.h) + +testgtk_SOURCES = \ + $(demos) \ + main.c \ + demos.h + +testgtk_DEPENDENCIES = $(DEPS) +testgtk_LDADD = $(LDADDS) diff --git a/demos/testgtk/button_box.c b/demos/testgtk/button_box.c new file mode 100644 index 000000000..432bfbbfc --- /dev/null +++ b/demos/testgtk/button_box.c @@ -0,0 +1,122 @@ +/* Button Boxes + * + * The Button Box widgets are used to arrange buttons with padding. + */ + +#include <gtk/gtk.h> + +static GtkWidget * +create_bbox (gint horizontal, + char* title, + gint spacing, + gint child_w, + gint child_h, + gint layout) +{ + GtkWidget *frame; + GtkWidget *bbox; + GtkWidget *button; + + frame = gtk_frame_new (title); + + if (horizontal) + bbox = gtk_hbutton_box_new (); + else + bbox = gtk_vbutton_box_new (); + + gtk_container_set_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); + + button = gtk_button_new_with_label ("OK"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + button = gtk_button_new_with_label ("Cancel"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + button = gtk_button_new_with_label ("Help"); + gtk_container_add (GTK_CONTAINER (bbox), button); + + return frame; +} + +void +do_button_box (void) +{ + static GtkWidget* window = NULL; + 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 Boxes"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + + main_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), main_vbox); + + frame_horz = gtk_frame_new ("Horizontal Button Boxes"); + gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_set_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); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_set_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_all (window); + else + gtk_widget_destroy (window); +} + diff --git a/demos/testgtk/geninclude.pl b/demos/testgtk/geninclude.pl new file mode 100755 index 000000000..31036cc39 --- /dev/null +++ b/demos/testgtk/geninclude.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +print <<EOT; +typedef struct _Demo Demo; + +struct _Demo +{ + gchar *title; + gchar *filename; + void (*func) (void); +}; + +EOT + +$array = ""; +$first = 1; +for $file (@ARGV) { + + ($basename = $file) =~ s/\.c$//; + + if ($first) { + $first = 0; + } else { + $array .= ",\n"; + } + + open INFO_FILE, $file or die "Cannot open '$file'\n"; + $title = <INFO_FILE>; + $title =~ s@^\s*/\*\s*@@; + $title =~ s@\s*$@@; + + close INFO_FILE; + + print "void do_$basename (void);\n"; + $array .= qq( { "$title", "$file", do_$basename }); +} + +print "\nDemo testgtk_demos[] = {"; +print $array; +print "\n};\n"; diff --git a/demos/testgtk/item_factory.c b/demos/testgtk/item_factory.c new file mode 100644 index 000000000..4e808f9da --- /dev/null +++ b/demos/testgtk/item_factory.c @@ -0,0 +1,118 @@ +/* Item Factory + * + * The GtkItemFactory object allows the easy creation of menus + * from an array of descriptions of menu items. + */ + +#include <gtk/gtk.h> + +static void +gtk_ifactory_cb (gpointer callback_data, + guint callback_action, + GtkWidget *widget) +{ + g_message ("ItemFactory: activated \"%s\"", gtk_item_factory_path_from_widget (widget)); +} + +static GtkItemFactoryEntry menu_items[] = +{ + { "/_File", NULL, 0, 0, "<Branch>" }, + { "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" }, + { "/File/_New", "<control>N", gtk_ifactory_cb, 0 }, + { "/File/_Open", "<control>O", gtk_ifactory_cb, 0 }, + { "/File/_Save", "<control>S", gtk_ifactory_cb, 0 }, + { "/File/Save _As...", NULL, gtk_ifactory_cb, 0 }, + { "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" }, + { "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 }, + + { "/_Preferences", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/_Color", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, + { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, + { "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, + { "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" }, + { "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, + { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" }, + { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" }, + + { "/_Help", NULL, 0, 0, "<LastBranch>" }, + { "/Help/_About", NULL, gtk_ifactory_cb, 0 }, +}; + +static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); + +void +do_item_factory (void) +{ + static GtkWidget *window = NULL; + + if (!window) + { + GtkWidget *box1; + GtkWidget *box2; + GtkWidget *separator; + GtkWidget *label; + GtkWidget *button; + GtkAccelGroup *accel_group; + GtkItemFactory *item_factory; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + gtk_signal_connect (GTK_OBJECT (window), "delete-event", + GTK_SIGNAL_FUNC (gtk_true), + NULL); + + accel_group = gtk_accel_group_new (); + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); + gtk_object_set_data_full (GTK_OBJECT (window), + "<main>", + item_factory, + (GtkDestroyNotify) gtk_object_unref); + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + gtk_window_set_title (GTK_WINDOW (window), "Item Factory"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); + + /* preselect /Preferences/Shape/Oval over the other radios + */ + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory, + "/Preferences/Shape/Oval")), + TRUE); + + box1 = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box1); + + gtk_box_pack_start (GTK_BOX (box1), + gtk_item_factory_get_widget (item_factory, "<main>"), + FALSE, FALSE, 0); + + label = gtk_label_new ("Type\n<alt>\nto start"); + gtk_widget_set_usize (label, 200, 200); + gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); + gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0); + + + separator = gtk_hseparator_new (); + gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); + + + box2 = gtk_vbox_new (FALSE, 10); + gtk_container_set_border_width (GTK_CONTAINER (box2), 10); + gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); + + button = gtk_button_new_with_label ("close"); + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (window)); + 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_all (window); + } + else + gtk_widget_destroy (window); +} diff --git a/demos/testgtk/main.c b/demos/testgtk/main.c new file mode 100644 index 000000000..2e0649f7c --- /dev/null +++ b/demos/testgtk/main.c @@ -0,0 +1,324 @@ +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#include <gtk/gtk.h> + +#include <demos.h> + +static GtkTextBuffer *info_buffer; +static GtkTextBuffer *source_buffer; +static GtkWidget *demo_clist; + +static Demo *current_demo; + +gboolean +read_line (FILE *stream, GString *str) +{ + int n_read = 0; + + flockfile (stream); + + g_string_truncate (str, 0); + + while (1) + { + int c; + + c = getc_unlocked (stream); + + if (c == EOF) + goto done; + else + n_read++; + + switch (c) + { + case '\r': + case '\n': + { + int next_c = getc_unlocked (stream); + + if (!(next_c == EOF || + (c == '\r' && next_c == '\n') || + (c == '\n' && next_c == '\r'))) + ungetc (next_c, stream); + + goto done; + } + default: + g_string_append_c (str, c); + } + } + + done: + + funlockfile (stream); + + return n_read > 0; +} + +void +load_file (Demo *demo) +{ + FILE *file; + GtkTextIter start, end; + GString *buffer = g_string_new (NULL); + int state = 0; + gboolean in_para = 0; + + if (current_demo == demo) + return; + + current_demo = demo; + + gtk_text_buffer_get_bounds (info_buffer, &start, &end); + gtk_text_buffer_delete (info_buffer, &start, &end); + + gtk_text_buffer_get_bounds (source_buffer, &start, &end); + gtk_text_buffer_delete (source_buffer, &start, &end); + + file = fopen (demo->filename, "r"); + if (!file) + { + g_warning ("Cannot open %s: %s\n", demo->filename, g_strerror (errno)); + return; + } + + gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0); + while (read_line (file, buffer)) + { + gchar *p = buffer->str; + gchar *q; + + switch (state) + { + case 0: + /* Reading title */ + while (*p == '/' || *p == '*' || isspace (*p)) + p++; + q = p + strlen (p); + while (q > p && isspace (*(q - 1))) + q--; + + if (q > p) + { + int len_chars = g_utf8_pointer_to_offset (p, q); + + end = start; + + g_assert (strlen (p) >= q - p); + gtk_text_buffer_insert (info_buffer, &end, p, q - p); + start = end; + + gtk_text_iter_backward_chars (&start, len_chars); + gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end); + + start = end; + + state++; + } + break; + + case 1: + /* Reading body of info section */ + while (isspace (*p)) + p++; + if (*p == '*' && *(p + 1) == '/') + { + gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0); + state++; + } + else + { + int len; + + while (*p == '*' || isspace (*p)) + p++; + + len = strlen (p); + while (isspace (*(p + len - 1))) + len--; + + if (len > 0) + { + if (in_para) + gtk_text_buffer_insert (info_buffer, &start, " ", 1); + + g_assert (strlen (p) >= len); + gtk_text_buffer_insert (info_buffer, &start, p, len); + in_para = 1; + } + else + { + gtk_text_buffer_insert (info_buffer, &start, "\n", 1); + in_para = 0; + } + } + break; + + case 2: + /* Skipping blank lines */ + while (isspace (*p)) + p++; + if (*p) + { + p = buffer->str; + state++; + /* Fall through */ + } + else + break; + + case 3: + /* Reading program body */ + gtk_text_buffer_insert (source_buffer, &start, p, -1); + gtk_text_buffer_insert (info_buffer, &start, "\n", 1); + break; + } + } + + gtk_text_buffer_get_bounds (source_buffer, &start, &end); + gtk_text_buffer_apply_tag_by_name (info_buffer, "source", &start, &end); +} + +gboolean +button_press_event_cb (GtkCList *clist, + GdkEventButton *event) +{ + if (event->type == GDK_2BUTTON_PRESS && + event->window == clist->clist_window) + { + gint row, column; + + if (gtk_clist_get_selection_info (clist, + event->x, event->y, + &row, &column)) + + { + Demo *demo = gtk_clist_get_row_data (clist, row); + demo->func(); + } + + gtk_signal_emit_stop_by_name (GTK_OBJECT (clist), "button_press_event"); + return TRUE; + } + + return FALSE; +} + +void +select_row_cb (GtkCList *clist, + gint row, + gint column, + GdkEvent *event) +{ + Demo *demo = gtk_clist_get_row_data (clist, row); + load_file (demo); +} + +GtkWidget * +create_text (GtkTextBuffer **buffer, + gboolean is_source) +{ + GtkWidget *scrolled_window; + GtkWidget *text_view; + PangoFontDescription *font_desc; + + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_SHADOW_IN); + + text_view = gtk_text_view_new (); + gtk_container_add (GTK_CONTAINER (scrolled_window), text_view); + + *buffer = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), *buffer); + gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE); + + if (is_source) + { + font_desc = pango_font_description_from_string ("Courier 10"); + gtk_widget_modify_font (text_view, font_desc); + pango_font_description_free (font_desc); + } + + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), !is_source); + + return scrolled_window; +} + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *notebook; + GtkWidget *hbox; + GtkTextTag *tag; + int i; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), hbox); + + demo_clist = gtk_clist_new (1); + gtk_clist_set_selection_mode (GTK_CLIST (demo_clist), GTK_SELECTION_BROWSE); + + gtk_widget_set_usize (demo_clist, 200, -1); + gtk_box_pack_start (GTK_BOX (hbox), demo_clist, FALSE, FALSE, 0); + + notebook = gtk_notebook_new (); + gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0); + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), + create_text (&info_buffer, FALSE), + gtk_label_new ("Info")); + + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), + create_text (&source_buffer, TRUE), + gtk_label_new ("Source")); + + tag = gtk_text_buffer_create_tag (info_buffer, "title"); + gtk_object_set (GTK_OBJECT (tag), + "font", "Sans 18", + NULL); + + tag = gtk_text_buffer_create_tag (info_buffer, "source"); + gtk_object_set (GTK_OBJECT (tag), + "font", "Courier 10", + "pixels_above_lines", 0, + "pixels_below_lines", 0, + NULL); + + gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); + gtk_widget_show_all (window); + + for (i=0; i < G_N_ELEMENTS (testgtk_demos); i++) + { + gint row = gtk_clist_append (GTK_CLIST (demo_clist), &testgtk_demos[i].title); + gtk_clist_set_row_data (GTK_CLIST (demo_clist), row, &testgtk_demos[i]); + } + + load_file (&testgtk_demos[0]); + + gtk_signal_connect (GTK_OBJECT (demo_clist), "button_press_event", + GTK_SIGNAL_FUNC (button_press_event_cb), NULL); + + gtk_signal_connect (GTK_OBJECT (demo_clist), "select_row", + GTK_SIGNAL_FUNC (select_row_cb), NULL); + + gtk_main (); + + return 0; +} diff --git a/demos/testgtk/menus.c b/demos/testgtk/menus.c new file mode 100644 index 000000000..8c394cd28 --- /dev/null +++ b/demos/testgtk/menus.c @@ -0,0 +1,187 @@ +/* Menus + * + * GTK+ includes a number of widgets for menus of actions. + * GtkMenu is a drop-down menu, GtkMenuBar a horizontal menu bar. + * Each of these widgets can hold various types of menuitem. + * As well as the base type, GtkMenuItem, there are GtkCheckMenuItem, + * GtkRadioMenuItem and GtkTearoffMenuItem. + */ + +#include <stdio.h> + +#include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> + +static GtkWidget* +create_menu (gint depth, gboolean tearoff) +{ + GtkWidget *menu; + GtkWidget *menuitem; + GSList *group; + char buf[32]; + int i, j; + + if (depth < 1) + return NULL; + + menu = gtk_menu_new (); + group = NULL; + + if (tearoff) + { + menuitem = gtk_tearoff_menu_item_new (); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + } + + for (i = 0, j = 1; i < 5; i++, j++) + { + sprintf (buf, "item %2d - %d", depth, j); + menuitem = gtk_radio_menu_item_new_with_label (group, buf); + group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); + if (depth % 2) + gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), TRUE); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + if (i == 3) + gtk_widget_set_sensitive (menuitem, FALSE); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE)); + } + + return menu; +} + +void +do_menus (void) +{ + static GtkWidget *window = NULL; + GtkWidget *box1; + GtkWidget *box2; + GtkWidget *button; + GtkWidget *optionmenu; + GtkWidget *separator; + + if (!window) + { + GtkWidget *menubar; + GtkWidget *menu; + GtkWidget *menuitem; + GtkAccelGroup *accel_group; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + gtk_signal_connect (GTK_OBJECT (window), "delete-event", + GTK_SIGNAL_FUNC (gtk_true), + NULL); + + accel_group = gtk_accel_group_new (); + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + + gtk_window_set_title (GTK_WINDOW (window), "menus"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + + box1 = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box1); + gtk_widget_show (box1); + + menubar = gtk_menu_bar_new (); + gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0); + gtk_widget_show (menubar); + + menu = create_menu (2, TRUE); + + menuitem = gtk_menu_item_new_with_label ("test\nline2"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + menuitem = gtk_menu_item_new_with_label ("foo"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE)); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + menuitem = gtk_menu_item_new_with_label ("bar"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE)); + gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem)); + gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); + gtk_widget_show (menuitem); + + box2 = gtk_vbox_new (FALSE, 10); + gtk_container_set_border_width (GTK_CONTAINER (box2), 10); + gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); + gtk_widget_show (box2); + + menu = create_menu (1, FALSE); + gtk_menu_set_accel_group (GTK_MENU (menu), accel_group); + + menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F1, + 0, + GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE); + menuitem = gtk_check_menu_item_new_with_label ("Accelerator Locked"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F2, + 0, + GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); + menuitem = gtk_check_menu_item_new_with_label ("Accelerators Frozen"); + gtk_menu_append (GTK_MENU (menu), menuitem); + gtk_widget_show (menuitem); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F2, + 0, + GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (menuitem, + "activate", + accel_group, + GDK_F3, + 0, + GTK_ACCEL_VISIBLE); + gtk_widget_lock_accelerators (menuitem); + + optionmenu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 3); + gtk_box_pack_start (GTK_BOX (box2), optionmenu, TRUE, TRUE, 0); + gtk_widget_show (optionmenu); + + 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_set_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", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (window)); + 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); + else + gtk_widget_destroy (window); +} + diff --git a/demos/testgtk/panes.c b/demos/testgtk/panes.c new file mode 100644 index 000000000..718f8969b --- /dev/null +++ b/demos/testgtk/panes.c @@ -0,0 +1,188 @@ +/* Paned Widgets + * + * The GtkHPaned and GtkVPaned Widgets divide their content + * area into two panes with a divider in between that the + * user can adjust. A separate child is placed into each + * pane. + * + * There are a number of options that can be set for each pane. + * This test contains both a horizontal (HPaned) and a vertical + * (VPaned) widget, and allows you to adjust the options for + * each side of each widget. + */ + +#include <gtk/gtk.h> + +void +toggle_resize (GtkWidget *widget, GtkWidget *child) +{ + GtkPaned *paned = GTK_PANED (child->parent); + gboolean is_child1 = (child == paned->child1); + gboolean resize, shrink; + + resize = is_child1 ? paned->child1_resize : paned->child2_resize; + shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; + + gtk_widget_ref (child); + gtk_container_remove (GTK_CONTAINER (child->parent), child); + if (is_child1) + gtk_paned_pack1 (paned, child, !resize, shrink); + else + gtk_paned_pack2 (paned, child, !resize, shrink); + gtk_widget_unref (child); +} + +void +toggle_shrink (GtkWidget *widget, GtkWidget *child) +{ + GtkPaned *paned = GTK_PANED (child->parent); + gboolean is_child1 = (child == paned->child1); + gboolean resize, shrink; + + resize = is_child1 ? paned->child1_resize : paned->child2_resize; + shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; + + gtk_widget_ref (child); + gtk_container_remove (GTK_CONTAINER (child->parent), child); + if (is_child1) + gtk_paned_pack1 (paned, child, resize, !shrink); + else + gtk_paned_pack2 (paned, child, resize, !shrink); + gtk_widget_unref (child); +} + +GtkWidget * +create_pane_options (GtkPaned *paned, + const gchar *frame_label, + const gchar *label1, + const gchar *label2) +{ + GtkWidget *frame; + GtkWidget *table; + GtkWidget *label; + GtkWidget *check_button; + + frame = gtk_frame_new (frame_label); + gtk_container_set_border_width (GTK_CONTAINER (frame), 4); + + table = gtk_table_new (3, 2, 4); + gtk_container_add (GTK_CONTAINER (frame), table); + + label = gtk_label_new (label1); + gtk_table_attach_defaults (GTK_TABLE (table), label, + 0, 1, 0, 1); + + check_button = gtk_check_button_new_with_label ("Resize"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 0, 1, 1, 2); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_resize), + paned->child1); + + check_button = gtk_check_button_new_with_label ("Shrink"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 0, 1, 2, 3); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_shrink), + paned->child1); + + label = gtk_label_new (label2); + gtk_table_attach_defaults (GTK_TABLE (table), label, + 1, 2, 0, 1); + + check_button = gtk_check_button_new_with_label ("Resize"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 1, 2, 1, 2); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_resize), + paned->child2); + + check_button = gtk_check_button_new_with_label ("Shrink"); + gtk_table_attach_defaults (GTK_TABLE (table), check_button, + 1, 2, 2, 3); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), + TRUE); + gtk_signal_connect (GTK_OBJECT (check_button), "toggled", + GTK_SIGNAL_FUNC (toggle_shrink), + paned->child2); + + return frame; +} + +void +do_panes (void) +{ + static GtkWidget *window = NULL; + GtkWidget *frame; + GtkWidget *hpaned; + GtkWidget *vpaned; + GtkWidget *button; + GtkWidget *vbox; + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), + &window); + + gtk_window_set_title (GTK_WINDOW (window), "Panes"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + vpaned = gtk_vpaned_new (); + gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER(vpaned), 5); + + hpaned = gtk_hpaned_new (); + gtk_paned_add1 (GTK_PANED (vpaned), hpaned); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 60, 60); + gtk_paned_add1 (GTK_PANED (hpaned), frame); + + button = gtk_button_new_with_label ("Hi there"); + gtk_container_add (GTK_CONTAINER(frame), button); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 80, 60); + gtk_paned_add2 (GTK_PANED (hpaned), frame); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_widget_set_usize (frame, 60, 80); + gtk_paned_add2 (GTK_PANED (vpaned), frame); + + /* Now create toggle buttons to control sizing */ + + gtk_box_pack_start (GTK_BOX (vbox), + create_pane_options (GTK_PANED (hpaned), + "Horizontal", + "Left", + "Right"), + FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (vbox), + create_pane_options (GTK_PANED (vpaned), + "Vertical", + "Top", + "Bottom"), + FALSE, FALSE, 0); + + gtk_widget_show_all (vbox); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show (window); + else + gtk_widget_destroy (window); +} |