Commit 74209088 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

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.
parent 92bbfd05
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
......
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
......
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
......
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
......
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
......
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
......
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
......
......@@ -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
......
## Makefile.am for gtk+/demos
SUBDIRS = testgtk
INCLUDES = @STRIP_BEGIN@ \
-I$(top_srcdir) \
-I$(top_builddir)/gdk \
......
Makefile
Makefile.in
.libs
.deps
testgtk
demos.h
## 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)
/* 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);
}
#!/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";
#!/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";
/* 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);
}
#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,