Rename this testgtk to gtk-demo to avoid confusion, and install it so

2000-11-12  Havoc Pennington  <hp@pobox.com>

        Rename this testgtk to gtk-demo to avoid confusion, and
	install it so people can use it as a supplement to
	the documentation.

	        * demos/gtk-demo: Moved from demos/testgtk

		* demos/testgtk: Removed

		* configure.in: make Makefile in gtk-demo

		* demos/gtk-demo/Makefile.am: Install sample source to
		datadir/gtk-demo (maybe there's a better place?), and
		rename the binary to gtk-demo

		* demos/gtk-demo/main.c (load_file): Load installed sample
		source if source isn't found in pwd.
This commit is contained in:
Havoc Pennington 2000-11-13 04:36:38 +00:00 committed by Havoc Pennington
parent d8a06dbadc
commit 213680a436
19 changed files with 157 additions and 1116 deletions

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1,3 +1,22 @@
2000-11-12 Havoc Pennington <hp@pobox.com>
Rename this testgtk to gtk-demo to avoid confusion, and
install it so people can use it as a supplement to
the documentation.
* demos/gtk-demo: Moved from demos/testgtk
* demos/testgtk: Removed
* configure.in: make Makefile in gtk-demo
* demos/gtk-demo/Makefile.am: Install sample source to
datadir/gtk-demo (maybe there's a better place?), and
rename the binary to gtk-demo
* demos/gtk-demo/main.c (load_file): Load installed sample
source if source isn't found in pwd.
2000-11-09 Havoc Pennington <hp@pobox.com> 2000-11-09 Havoc Pennington <hp@pobox.com>
* gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char" * gtk/gtkentry.c (gtk_entry_class_init): Add an "invisible_char"

View File

@ -1020,7 +1020,7 @@ po/Makefile.in
build/Makefile build/Makefile
build/win32/Makefile build/win32/Makefile
demos/Makefile demos/Makefile
demos/testgtk/Makefile demos/gtk-demo/Makefile
docs/Makefile docs/Makefile
docs/reference/Makefile docs/reference/Makefile
docs/reference/gdk-pixbuf/Makefile docs/reference/gdk-pixbuf/Makefile

View File

@ -1,6 +1,6 @@
## Makefile.am for gtk+/demos ## Makefile.am for gtk+/demos
SUBDIRS = testgtk SUBDIRS = gtk-demo
INCLUDES = @STRIP_BEGIN@ \ INCLUDES = @STRIP_BEGIN@ \
-I$(top_srcdir) \ -I$(top_srcdir) \

View File

@ -1,5 +1,7 @@
## Makefile.am for gtk+/demos ## Makefile.am for gtk+/demos
democodedir=$(datadir)/gtk-demo
demos = @STRIP_BEGIN@ \ demos = @STRIP_BEGIN@ \
button_box.c \ button_box.c \
item_factory.c \ item_factory.c \
@ -8,6 +10,7 @@ demos = @STRIP_BEGIN@ \
@STRIP_END@ @STRIP_END@
INCLUDES = @STRIP_BEGIN@ \ INCLUDES = @STRIP_BEGIN@ \
-DDEMOCODEDIR="\"$(democodedir)\"" \
-I$(top_srcdir) \ -I$(top_srcdir) \
-I$(top_builddir)/gdk \ -I$(top_builddir)/gdk \
-DGTK_DISABLE_COMPAT_H \ -DGTK_DISABLE_COMPAT_H \
@ -37,7 +40,7 @@ LDADDS = @STRIP_BEGIN@ \
-lm \ -lm \
@STRIP_END@ @STRIP_END@
noinst_PROGRAMS = testgtk bin_PROGRAMS = gtk-demo
BUILT_SOURCES = demos.h BUILT_SOURCES = demos.h
@ -47,10 +50,12 @@ EXTRA_DIST = \
demos.h: $(demos) geninclude.pl demos.h: $(demos) geninclude.pl
(cd $(srcdir) && ./geninclude.pl $(demos) > demos.h) (cd $(srcdir) && ./geninclude.pl $(demos) > demos.h)
testgtk_SOURCES = \ gtk_demo_SOURCES = \
$(demos) \ $(demos) \
main.c \ main.c \
demos.h demos.h
testgtk_DEPENDENCIES = $(DEPS) gtk_demo_DEPENDENCIES = $(DEPS)
testgtk_LDADD = $(LDADDS) gtk_demo_LDADD = $(LDADDS)
democode_DATA = $(demos)

View File

@ -88,6 +88,19 @@ load_file (const gchar *filename)
gtk_text_buffer_delete (source_buffer, &start, &end); gtk_text_buffer_delete (source_buffer, &start, &end);
file = fopen (filename, "r"); file = fopen (filename, "r");
if (!file)
{
char *installed = g_strconcat (DEMOCODEDIR,
G_DIR_SEPARATOR_S,
filename,
NULL);
file = fopen (installed, "r");
g_free (installed);
}
if (!file) if (!file)
{ {
g_warning ("Cannot open %s: %s\n", filename, g_strerror (errno)); g_warning ("Cannot open %s: %s\n", filename, g_strerror (errno));

View File

@ -1,7 +0,0 @@
Makefile
Makefile.in
.libs
.deps
testgtk
demos.h

View File

@ -1,56 +0,0 @@
## 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)

View File

@ -1,122 +0,0 @@
/* 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);
}

View File

@ -1,40 +0,0 @@
#!/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";

View File

@ -1,118 +0,0 @@
/* 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);
}

View File

@ -1,392 +0,0 @@
#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 gchar *current_file = NULL;
enum {
TITLE_COLUMN,
FILENAME_COLUMN,
FUNC_COLUMN,
ITALIC_COLUMN,
NUM_COLUMNS
};
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 (const gchar *filename)
{
FILE *file;
GtkTextIter start, end;
GString *buffer = g_string_new (NULL);
int state = 0;
gboolean in_para = 0;
if (current_file && !strcmp (current_file, filename))
return;
g_free (current_file);
current_file = g_strdup (filename);
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 (filename, "r");
if (!file)
{
g_warning ("Cannot open %s: %s\n", 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 (GtkTreeView *tree_view,
GdkEventButton *event,
GtkTreeModel *model)
{
if (event->type == GDK_2BUTTON_PRESS)
{
GtkTreePath *path = NULL;
gtk_tree_view_get_path_at_pos (tree_view,
event->window,
event->x,
event->y,
&path,
NULL);
if (path)
{
GtkTreeIter iter;
gboolean italic;
GVoidFunc func;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_store_get (GTK_TREE_STORE (model),
&iter,
FUNC_COLUMN, &func,
ITALIC_COLUMN, &italic,
-1);
(func) ();
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
ITALIC_COLUMN, !italic,
-1);
gtk_tree_path_free (path);
}
gtk_signal_emit_stop_by_name (GTK_OBJECT (tree_view),
"button_press_event");
return TRUE;
}
return FALSE;
}
static void
selection_cb (GtkTreeSelection *selection,
GtkTreeModel *model)
{
GtkTreeIter iter;
GValue value = {0, };
if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_tree_model_get_value (model, &iter,
FILENAME_COLUMN,
&value);
load_file (g_value_get_string (&value));
g_value_unset (&value);
}
static 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;
}
/* Technically a list, but if we do go to 80 demos, we may want to move to a tree */
static GtkWidget *
create_tree (void)
{
GtkTreeSelection *selection;
GtkCellRenderer *cell;
GtkWidget *tree_view;
GtkObject *column;
GtkObject *model;
GtkTreeIter iter;
gint i;
model = gtk_tree_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection),
GTK_TREE_SELECTION_SINGLE);
gtk_widget_set_usize (tree_view, 200, -1);
for (i=0; i < G_N_ELEMENTS (testgtk_demos); i++)
{
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
TITLE_COLUMN, testgtk_demos[i].title,
FILENAME_COLUMN, testgtk_demos[i].filename,
FUNC_COLUMN, testgtk_demos[i].func,
ITALIC_COLUMN, FALSE,
-1);
}
cell = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Widget",
cell,
"text", TITLE_COLUMN,
"italic", ITALIC_COLUMN,
NULL);
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 (tree_view), "button_press_event", GTK_SIGNAL_FUNC (button_press_event_cb), model);
return tree_view;
}
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *hbox;
GtkWidget *tree;
GtkTextTag *tag;
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);
tree = create_tree ();
gtk_box_pack_start (GTK_BOX (hbox), tree, 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);
load_file (testgtk_demos[0].filename);
gtk_main ();
return 0;
}

View File

@ -1,187 +0,0 @@
/* 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_shell_append (GTK_MENU_SHELL (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_shell_append (GTK_MENU_SHELL (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_shell_append (GTK_MENU_SHELL (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_shell_append (GTK_MENU_SHELL (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_shell_append (GTK_MENU_SHELL (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);
}

View File

@ -1,188 +0,0 @@
/* 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);
}