It's the worlds ugliest highlighting code!!!! The result is okay so long

Thu May 17 16:20:04 2001  Jonathan Blandford  <jrb@redhat.com>

	* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
	highlighting code!!!!  The result is okay so long as you don't try
	to stress it.  It also highlights a bug in the TextView so it's in
	an unproportional font right now until it's fixed.

	*demos/gtk-demo/*.c: Clean up code a bit to make it
	ugly-parser(TM) friendly. (-:
This commit is contained in:
Jonathan Blandford
2001-05-18 16:28:30 +00:00
committed by Jonathan Blandford
parent 288ff7e058
commit 009212ad28
18 changed files with 858 additions and 502 deletions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -1,3 +1,13 @@
Thu May 17 16:20:04 2001 Jonathan Blandford <jrb@redhat.com>
* demos/gtk-demo/main.c (fontify): It's the worlds ugliest
highlighting code!!!! The result is okay so long as you don't try
to stress it. It also highlights a bug in the TextView so it's in
an unproportional font right now until it's fixed.
*demos/gtk-demo/*.c: Clean up code a bit to make it
ugly-parser(TM) friendly. (-:
2001-05-17 Joe Shaw <joe@ximian.com> 2001-05-17 Joe Shaw <joe@ximian.com>
* gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions * gtk/gtktextdisplay.c (gtk_text_layout_draw): Remove the assertions

View File

@ -7,7 +7,7 @@
static GtkWidget * static GtkWidget *
create_bbox (gint horizontal, create_bbox (gint horizontal,
char* title, char *title,
gint spacing, gint spacing,
gint layout) gint layout)
{ {
@ -43,7 +43,7 @@ create_bbox (gint horizontal,
GtkWidget * GtkWidget *
do_button_box (void) do_button_box (void)
{ {
static GtkWidget* window = NULL; static GtkWidget *window = NULL;
GtkWidget *main_vbox; GtkWidget *main_vbox;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *hbox; GtkWidget *hbox;
@ -72,19 +72,19 @@ do_button_box (void)
gtk_container_add (GTK_CONTAINER (frame_horz), vbox); gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
gtk_box_pack_start (GTK_BOX (vbox), gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD), create_bbox (TRUE, "Spread", 40, GTK_BUTTONBOX_SPREAD),
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE), create_bbox (TRUE, "Edge", 40, GTK_BUTTONBOX_EDGE),
TRUE, TRUE, 5); TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START), create_bbox (TRUE, "Start", 40, GTK_BUTTONBOX_START),
TRUE, TRUE, 5); TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (vbox), gtk_box_pack_start (GTK_BOX (vbox),
create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END), create_bbox (TRUE, "End", 40, GTK_BUTTONBOX_END),
TRUE, TRUE, 5); TRUE, TRUE, 5);
frame_vert = gtk_frame_new ("Vertical Button Boxes"); frame_vert = gtk_frame_new ("Vertical Button Boxes");
@ -95,19 +95,19 @@ do_button_box (void)
gtk_container_add (GTK_CONTAINER (frame_vert), hbox); gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Spread", 30, GTK_BUTTONBOX_SPREAD), create_bbox (FALSE, "Spread", 30, GTK_BUTTONBOX_SPREAD),
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Edge", 30, GTK_BUTTONBOX_EDGE), create_bbox (FALSE, "Edge", 30, GTK_BUTTONBOX_EDGE),
TRUE, TRUE, 5); TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "Start", 30, GTK_BUTTONBOX_START), create_bbox (FALSE, "Start", 30, GTK_BUTTONBOX_START),
TRUE, TRUE, 5); TRUE, TRUE, 5);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
create_bbox (FALSE, "End", 30, GTK_BUTTONBOX_END), create_bbox (FALSE, "End", 30, GTK_BUTTONBOX_END),
TRUE, TRUE, 5); TRUE, TRUE, 5);
} }
@ -116,11 +116,10 @@ do_button_box (void)
gtk_widget_show_all (window); gtk_widget_show_all (window);
} }
else else
{ {
gtk_widget_destroy (window); gtk_widget_destroy (window);
window = NULL; window = NULL;
} }
return window; return window;
} }

View File

@ -14,7 +14,7 @@ static GtkWidget *frame;
static void static void
change_color_callback (GtkWidget *button, change_color_callback (GtkWidget *button,
gpointer data) gpointer data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkColorSelection *colorsel; GtkColorSelection *colorsel;
@ -35,7 +35,7 @@ change_color_callback (GtkWidget *button,
if (response == GTK_RESPONSE_OK) if (response == GTK_RESPONSE_OK)
{ {
gtk_color_selection_get_current_color (colorsel, gtk_color_selection_get_current_color (colorsel,
&color); &color);
gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color); gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
} }
@ -92,8 +92,8 @@ do_colorsel (void)
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked", gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (change_color_callback), GTK_SIGNAL_FUNC (change_color_callback),
NULL); NULL);
} }
if (!GTK_WIDGET_VISIBLE (window)) if (!GTK_WIDGET_VISIBLE (window))

View File

@ -10,7 +10,8 @@ static GtkWidget *entry1 = NULL;
static GtkWidget *entry2 = NULL; static GtkWidget *entry2 = NULL;
static void static void
message_dialog_clicked (GtkButton *button, gpointer user_data) message_dialog_clicked (GtkButton *button,
gpointer user_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
static gint i = 1; static gint i = 1;
@ -28,7 +29,8 @@ message_dialog_clicked (GtkButton *button, gpointer user_data)
} }
static void static void
interactive_dialog_clicked (GtkButton *button, gpointer user_data) interactive_dialog_clicked (GtkButton *button,
gpointer user_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *hbox; GtkWidget *hbox;
@ -59,7 +61,7 @@ interactive_dialog_clicked (GtkButton *button, gpointer user_data)
gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
label = gtk_label_new_with_mnemonic ("_Entry 1"); label = gtk_label_new_with_mnemonic ("_Entry 1");
gtk_table_attach_defaults (GTK_TABLE (table), gtk_table_attach_defaults (GTK_TABLE (table),
label, label,
0, 1, 0, 1); 0, 1, 0, 1);
local_entry1 = gtk_entry_new (); local_entry1 = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (local_entry1), gtk_entry_get_text (GTK_ENTRY (entry1))); gtk_entry_set_text (GTK_ENTRY (local_entry1), gtk_entry_get_text (GTK_ENTRY (entry1)));
@ -68,7 +70,7 @@ interactive_dialog_clicked (GtkButton *button, gpointer user_data)
label = gtk_label_new_with_mnemonic ("E_ntry 2"); label = gtk_label_new_with_mnemonic ("E_ntry 2");
gtk_table_attach_defaults (GTK_TABLE (table), gtk_table_attach_defaults (GTK_TABLE (table),
label, label,
0, 1, 1, 2); 0, 1, 1, 2);
local_entry2 = gtk_entry_new (); local_entry2 = gtk_entry_new ();
@ -142,8 +144,8 @@ do_dialog (void)
label = gtk_label_new_with_mnemonic ("_Entry 1"); label = gtk_label_new_with_mnemonic ("_Entry 1");
gtk_table_attach_defaults (GTK_TABLE (table), gtk_table_attach_defaults (GTK_TABLE (table),
label, label,
0, 1, 0, 1); 0, 1, 0, 1);
entry1 = gtk_entry_new (); entry1 = gtk_entry_new ();
gtk_table_attach_defaults (GTK_TABLE (table), entry1, 1, 2, 0, 1); gtk_table_attach_defaults (GTK_TABLE (table), entry1, 1, 2, 0, 1);
@ -152,8 +154,8 @@ do_dialog (void)
label = gtk_label_new_with_mnemonic ("E_ntry 2"); label = gtk_label_new_with_mnemonic ("E_ntry 2");
gtk_table_attach_defaults (GTK_TABLE (table), gtk_table_attach_defaults (GTK_TABLE (table),
label, label,
0, 1, 1, 2); 0, 1, 1, 2);
entry2 = gtk_entry_new (); entry2 = gtk_entry_new ();
gtk_table_attach_defaults (GTK_TABLE (table), entry2, 1, 2, 1, 2); gtk_table_attach_defaults (GTK_TABLE (table), entry2, 1, 2, 1, 2);
@ -165,7 +167,7 @@ do_dialog (void)
gtk_widget_show_all (window); gtk_widget_show_all (window);
} }
else else
{ {
gtk_widget_destroy (window); gtk_widget_destroy (window);
window = NULL; window = NULL;
} }

View File

@ -21,17 +21,17 @@ static GdkPixmap *pixmap = NULL;
/* Create a new pixmap of the appropriate size to store our scribbles */ /* Create a new pixmap of the appropriate size to store our scribbles */
static gboolean static gboolean
scribble_configure_event (GtkWidget *widget, scribble_configure_event (GtkWidget *widget,
GdkEventConfigure *event, GdkEventConfigure *event,
gpointer data) gpointer data)
{ {
if (pixmap) if (pixmap)
g_object_unref (G_OBJECT (pixmap)); g_object_unref (G_OBJECT (pixmap));
pixmap = gdk_pixmap_new (widget->window, pixmap = gdk_pixmap_new (widget->window,
widget->allocation.width, widget->allocation.width,
widget->allocation.height, widget->allocation.height,
-1); -1);
/* Initialize the pixmap to white */ /* Initialize the pixmap to white */
gdk_draw_rectangle (pixmap, gdk_draw_rectangle (pixmap,
@ -48,8 +48,8 @@ scribble_configure_event (GtkWidget *widget,
/* Redraw the screen from the pixmap */ /* Redraw the screen from the pixmap */
static gboolean static gboolean
scribble_expose_event (GtkWidget *widget, scribble_expose_event (GtkWidget *widget,
GdkEventExpose *event, GdkEventExpose *event,
gpointer data) gpointer data)
{ {
/* We use the "foreground GC" for the widget since it already exists, /* We use the "foreground GC" for the widget since it already exists,
* but honestly any GC would work. The only thing to worry about * but honestly any GC would work. The only thing to worry about
@ -57,12 +57,12 @@ scribble_expose_event (GtkWidget *widget,
*/ */
gdk_draw_drawable (widget->window, gdk_draw_drawable (widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
pixmap, pixmap,
/* Only copy the area that was exposed. */ /* Only copy the area that was exposed. */
event->area.x, event->area.y, event->area.x, event->area.y,
event->area.x, event->area.y, event->area.x, event->area.y,
event->area.width, event->area.height); event->area.width, event->area.height);
return FALSE; return FALSE;
} }
@ -70,8 +70,8 @@ scribble_expose_event (GtkWidget *widget,
/* Draw a rectangle on the screen */ /* Draw a rectangle on the screen */
static void static void
draw_brush (GtkWidget *widget, draw_brush (GtkWidget *widget,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
GdkRectangle update_rect; GdkRectangle update_rect;
@ -89,14 +89,14 @@ draw_brush (GtkWidget *widget,
/* Now invalidate the affected region of the drawing area. */ /* Now invalidate the affected region of the drawing area. */
gdk_window_invalidate_rect (widget->window, gdk_window_invalidate_rect (widget->window,
&update_rect, &update_rect,
FALSE); FALSE);
} }
static gboolean static gboolean
scribble_button_press_event (GtkWidget *widget, scribble_button_press_event (GtkWidget *widget,
GdkEventButton *event, GdkEventButton *event,
gpointer data) gpointer data)
{ {
if (pixmap == NULL) if (pixmap == NULL)
return FALSE; /* paranoia check, in case we haven't gotten a configure event */ return FALSE; /* paranoia check, in case we haven't gotten a configure event */
@ -109,9 +109,9 @@ scribble_button_press_event (GtkWidget *widget,
} }
static gboolean static gboolean
scribble_motion_notify_event (GtkWidget *widget, scribble_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event, GdkEventMotion *event,
gpointer data) gpointer data)
{ {
int x, y; int x, y;
GdkModifierType state; GdkModifierType state;
@ -141,9 +141,9 @@ scribble_motion_notify_event (GtkWidget *widget,
static gboolean static gboolean
checkerboard_expose (GtkWidget *da, checkerboard_expose (GtkWidget *da,
GdkEventExpose *event, GdkEventExpose *event,
gpointer data) gpointer data)
{ {
gint i, j, xcount, ycount; gint i, j, xcount, ycount;
GdkGC *gc1, *gc2; GdkGC *gc1, *gc2;
@ -182,28 +182,28 @@ checkerboard_expose (GtkWidget *da,
j = SPACING; j = SPACING;
ycount = xcount % 2; /* start with even/odd depending on row */ ycount = xcount % 2; /* start with even/odd depending on row */
while (j < da->allocation.height) while (j < da->allocation.height)
{ {
GdkGC *gc; GdkGC *gc;
if (ycount % 2) if (ycount % 2)
gc = gc1; gc = gc1;
else else
gc = gc2; gc = gc2;
/* If we're outside event->area, this will do nothing. /* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled * It might be mildly more efficient if we handled
* the clipping ourselves, but again we're feeling lazy. * the clipping ourselves, but again we're feeling lazy.
*/ */
gdk_draw_rectangle (da->window, gdk_draw_rectangle (da->window,
gc, gc,
TRUE, TRUE,
i, j, i, j,
CHECK_SIZE, CHECK_SIZE,
CHECK_SIZE); CHECK_SIZE);
j += CHECK_SIZE + SPACING; j += CHECK_SIZE + SPACING;
++ycount; ++ycount;
} }
i += CHECK_SIZE + SPACING; i += CHECK_SIZE + SPACING;
++xcount; ++xcount;
@ -245,7 +245,7 @@ do_drawingarea (void)
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), gtk_label_set_markup (GTK_LABEL (label),
"<u>Checkerboard pattern</u>"); "<u>Checkerboard pattern</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
@ -259,9 +259,9 @@ do_drawingarea (void)
gtk_container_add (GTK_CONTAINER (frame), da); gtk_container_add (GTK_CONTAINER (frame), da);
gtk_signal_connect (GTK_OBJECT (da), gtk_signal_connect (GTK_OBJECT (da),
"expose_event", "expose_event",
GTK_SIGNAL_FUNC (checkerboard_expose), GTK_SIGNAL_FUNC (checkerboard_expose),
NULL); NULL);
/* /*
* Create the scribble area * Create the scribble area
@ -269,7 +269,7 @@ do_drawingarea (void)
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), gtk_label_set_markup (GTK_LABEL (label),
"<u>Scribble area</u>"); "<u>Scribble area</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
@ -285,26 +285,26 @@ do_drawingarea (void)
/* Signals used to handle backing pixmap */ /* Signals used to handle backing pixmap */
gtk_signal_connect (GTK_OBJECT (da), "expose_event", gtk_signal_connect (GTK_OBJECT (da), "expose_event",
GTK_SIGNAL_FUNC (scribble_expose_event), NULL); GTK_SIGNAL_FUNC (scribble_expose_event), NULL);
gtk_signal_connect (GTK_OBJECT (da),"configure_event", gtk_signal_connect (GTK_OBJECT (da),"configure_event",
GTK_SIGNAL_FUNC (scribble_configure_event), NULL); GTK_SIGNAL_FUNC (scribble_configure_event), NULL);
/* Event signals */ /* Event signals */
gtk_signal_connect (GTK_OBJECT (da), "motion_notify_event", gtk_signal_connect (GTK_OBJECT (da), "motion_notify_event",
GTK_SIGNAL_FUNC (scribble_motion_notify_event), NULL); GTK_SIGNAL_FUNC (scribble_motion_notify_event), NULL);
gtk_signal_connect (GTK_OBJECT (da), "button_press_event", gtk_signal_connect (GTK_OBJECT (da), "button_press_event",
GTK_SIGNAL_FUNC (scribble_button_press_event), NULL); GTK_SIGNAL_FUNC (scribble_button_press_event), NULL);
/* Ask to receive events the drawing area doesn't normally /* Ask to receive events the drawing area doesn't normally
* subscribe to * subscribe to
*/ */
gtk_widget_set_events (da, gtk_widget_get_events (da) gtk_widget_set_events (da, gtk_widget_get_events (da)
| GDK_LEAVE_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_PRESS_MASK
| GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK); | GDK_POINTER_MOTION_HINT_MASK);
} }

View File

@ -22,10 +22,11 @@ static guint load_timeout = 0;
static FILE* image_stream = NULL; static FILE* image_stream = NULL;
static void static void
progressive_prepared_callback (GdkPixbufLoader* loader, gpointer data) progressive_prepared_callback (GdkPixbufLoader *loader,
gpointer data)
{ {
GdkPixbuf* pixbuf; GdkPixbuf *pixbuf;
GtkWidget* image; GtkWidget *image;
image = GTK_WIDGET (data); image = GTK_WIDGET (data);
@ -39,12 +40,14 @@ progressive_prepared_callback (GdkPixbufLoader* loader, gpointer data)
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
} }
static void static void progressive_updated_callback (GdkPixbufLoader *loader,
progressive_updated_callback (GdkPixbufLoader* loader, gint x,
gint x, gint y, gint width, gint height, gint y,
gpointer data) gint width,
gint height,
gpointer data)
{ {
GtkWidget* image; GtkWidget *image;
image = GTK_WIDGET (data); image = GTK_WIDGET (data);
@ -80,158 +83,158 @@ progressive_timeout (gpointer data)
bytes_read = fread (buf, 1, 256, image_stream); bytes_read = fread (buf, 1, 256, image_stream);
if (ferror (image_stream)) if (ferror (image_stream))
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Failure reading image file 'alphatest.png': %s", "Failure reading image file 'alphatest.png': %s",
g_strerror (errno)); g_strerror (errno));
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
fclose (image_stream); fclose (image_stream);
image_stream = NULL; image_stream = NULL;
gtk_widget_show (dialog); gtk_widget_show (dialog);
load_timeout = 0; load_timeout = 0;
return FALSE; /* uninstall the timeout */ return FALSE; /* uninstall the timeout */
} }
if (!gdk_pixbuf_loader_write (pixbuf_loader, if (!gdk_pixbuf_loader_write (pixbuf_loader,
buf, bytes_read, buf, bytes_read,
&error)) &error))
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Failed to load image: %s", "Failed to load image: %s",
error->message); error->message);
g_error_free (error); g_error_free (error);
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
fclose (image_stream); fclose (image_stream);
image_stream = NULL; image_stream = NULL;
gtk_widget_show (dialog); gtk_widget_show (dialog);
load_timeout = 0; load_timeout = 0;
return FALSE; /* uninstall the timeout */ return FALSE; /* uninstall the timeout */
} }
if (feof (image_stream)) if (feof (image_stream))
{ {
fclose (image_stream); fclose (image_stream);
image_stream = NULL; image_stream = NULL;
/* Errors can happen on close, e.g. if the image /* Errors can happen on close, e.g. if the image
* file was truncated we'll know on close that * file was truncated we'll know on close that
* it was incomplete. * it was incomplete.
*/ */
error = NULL; error = NULL;
if (!gdk_pixbuf_loader_close (pixbuf_loader, if (!gdk_pixbuf_loader_close (pixbuf_loader,
&error)) &error))
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Failed to load image: %s", "Failed to load image: %s",
error->message); error->message);
g_error_free (error); g_error_free (error);
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
gtk_widget_show (dialog); gtk_widget_show (dialog);
g_object_unref (G_OBJECT (pixbuf_loader)); g_object_unref (G_OBJECT (pixbuf_loader));
pixbuf_loader = NULL; pixbuf_loader = NULL;
load_timeout = 0; load_timeout = 0;
return FALSE; /* uninstall the timeout */ return FALSE; /* uninstall the timeout */
} }
g_object_unref (G_OBJECT (pixbuf_loader)); g_object_unref (G_OBJECT (pixbuf_loader));
pixbuf_loader = NULL; pixbuf_loader = NULL;
} }
} }
else else
{ {
const gchar *filename; const gchar *filename;
if (g_file_test ("./alphatest.png", G_FILE_TEST_EXISTS)) if (g_file_test ("./alphatest.png", G_FILE_TEST_EXISTS))
filename = "./alphatest.png"; filename = "./alphatest.png";
else else
filename = DEMOCODEDIR"/alphatest.png"; filename = DEMOCODEDIR"/alphatest.png";
image_stream = fopen (filename, "r"); image_stream = fopen (filename, "r");
if (image_stream == NULL) if (image_stream == NULL)
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Unable to open image file 'alphatest.png': %s", "Unable to open image file 'alphatest.png': %s",
g_strerror (errno)); g_strerror (errno));
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
gtk_widget_show (dialog); gtk_widget_show (dialog);
load_timeout = 0; load_timeout = 0;
return FALSE; /* uninstall the timeout */ return FALSE; /* uninstall the timeout */
} }
if (pixbuf_loader) if (pixbuf_loader)
{ {
gdk_pixbuf_loader_close (pixbuf_loader, NULL); gdk_pixbuf_loader_close (pixbuf_loader, NULL);
g_object_unref (G_OBJECT (pixbuf_loader)); g_object_unref (G_OBJECT (pixbuf_loader));
pixbuf_loader = NULL; pixbuf_loader = NULL;
} }
pixbuf_loader = gdk_pixbuf_loader_new (); pixbuf_loader = gdk_pixbuf_loader_new ();
g_signal_connect_data (G_OBJECT (pixbuf_loader), g_signal_connect_data (G_OBJECT (pixbuf_loader),
"area_prepared", "area_prepared",
G_CALLBACK (progressive_prepared_callback), G_CALLBACK (progressive_prepared_callback),
image, image,
NULL, FALSE, FALSE); NULL, FALSE, FALSE);
g_signal_connect_data (G_OBJECT (pixbuf_loader), g_signal_connect_data (G_OBJECT (pixbuf_loader),
"area_updated", "area_updated",
G_CALLBACK (progressive_updated_callback), G_CALLBACK (progressive_updated_callback),
image, image,
NULL, FALSE, FALSE); NULL, FALSE, FALSE);
} }
/* leave timeout installed */ /* leave timeout installed */
@ -249,13 +252,13 @@ start_progressive_loading (GtkWidget *image)
* pauses in the reading process. * pauses in the reading process.
*/ */
load_timeout = g_timeout_add (150, load_timeout = g_timeout_add (150,
progressive_timeout, progressive_timeout,
image); image);
} }
static void static void
cleanup_callback (GtkObject *object, cleanup_callback (GtkObject *object,
gpointer data) gpointer data)
{ {
if (load_timeout) if (load_timeout)
{ {
@ -300,7 +303,7 @@ do_images (void)
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), gtk_label_set_markup (GTK_LABEL (label),
"<u>Image loaded from a file</u>"); "<u>Image loaded from a file</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
@ -316,48 +319,48 @@ do_images (void)
* so you can run gtk-demo without installing GTK * so you can run gtk-demo without installing GTK
*/ */
if (g_file_test ("./gtk-logo-rgb.gif", G_FILE_TEST_EXISTS)) if (g_file_test ("./gtk-logo-rgb.gif", G_FILE_TEST_EXISTS))
{ {
/* This code shows off error handling. You can just use /* This code shows off error handling. You can just use
* gtk_image_new_from_file() instead if you don't want to report * gtk_image_new_from_file() instead if you don't want to report
* errors to the user. If the file doesn't load when using * errors to the user. If the file doesn't load when using
* gtk_image_new_from_file(), a "missing image" icon will * gtk_image_new_from_file(), a "missing image" icon will
* be displayed instead. * be displayed instead.
*/ */
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error = NULL; GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_file ("./gtk-logo-rgb.gif", pixbuf = gdk_pixbuf_new_from_file ("./gtk-logo-rgb.gif",
&error); &error);
if (error) if (error)
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Unable to open image file 'gtk-logo-rgb.gif': %s", "Unable to open image file 'gtk-logo-rgb.gif': %s",
error->message); error->message);
g_error_free (error); g_error_free (error);
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
image = gtk_image_new_from_pixbuf (pixbuf); image = gtk_image_new_from_pixbuf (pixbuf);
} }
else else
{ {
/* This is the simpler code, with no error handling. /* This is the simpler code, with no error handling.
* Here we're loading the installed gtk-logo-rgb.gif instead * Here we're loading the installed gtk-logo-rgb.gif instead
* of the one in the current directory. * of the one in the current directory.
*/ */
image = gtk_image_new_from_file (DEMOCODEDIR"/gtk-logo-rgb.gif"); image = gtk_image_new_from_file (DEMOCODEDIR"/gtk-logo-rgb.gif");
} }
gtk_container_add (GTK_CONTAINER (frame), image); gtk_container_add (GTK_CONTAINER (frame), image);
@ -366,7 +369,7 @@ do_images (void)
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), gtk_label_set_markup (GTK_LABEL (label),
"<u>Animation loaded from a file</u>"); "<u>Animation loaded from a file</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
@ -382,9 +385,9 @@ do_images (void)
* so you can run gtk-demo without installing GTK * so you can run gtk-demo without installing GTK
*/ */
if (g_file_test ("./floppybuddy.gif", G_FILE_TEST_EXISTS)) if (g_file_test ("./floppybuddy.gif", G_FILE_TEST_EXISTS))
image = gtk_image_new_from_file ("./floppybuddy.gif"); image = gtk_image_new_from_file ("./floppybuddy.gif");
else else
image = gtk_image_new_from_file (DEMOCODEDIR"/floppybuddy.gif"); image = gtk_image_new_from_file (DEMOCODEDIR"/floppybuddy.gif");
gtk_container_add (GTK_CONTAINER (frame), image); gtk_container_add (GTK_CONTAINER (frame), image);
@ -394,7 +397,7 @@ do_images (void)
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), gtk_label_set_markup (GTK_LABEL (label),
"<u>Progressive image loading</u>"); "<u>Progressive image loading</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);

View File

@ -7,36 +7,37 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
static void static void
gtk_ifactory_cb (gpointer callback_data, gtk_ifactory_cb (gpointer callback_data,
guint callback_action, guint callback_action,
GtkWidget *widget) GtkWidget *widget)
{ {
g_message ("ItemFactory: activated \"%s\"", gtk_item_factory_path_from_widget (widget)); g_message ("ItemFactory: activated \"%s\"",
gtk_item_factory_path_from_widget (widget));
} }
static GtkItemFactoryEntry menu_items[] = static GtkItemFactoryEntry menu_items[] =
{ {
{ "/_File", NULL, 0, 0, "<Branch>" }, { "/_File", NULL, 0, 0, "<Branch>" },
{ "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" }, { "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" },
{ "/File/_New", "<control>N", gtk_ifactory_cb, 0 }, { "/File/_New", "<control>N", gtk_ifactory_cb, 0 },
{ "/File/_Open", "<control>O", gtk_ifactory_cb, 0 }, { "/File/_Open", "<control>O", gtk_ifactory_cb, 0 },
{ "/File/_Save", "<control>S", gtk_ifactory_cb, 0 }, { "/File/_Save", "<control>S", gtk_ifactory_cb, 0 },
{ "/File/Save _As...", NULL, gtk_ifactory_cb, 0 }, { "/File/Save _As...", NULL, gtk_ifactory_cb, 0 },
{ "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" }, { "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" },
{ "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 }, { "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 },
{ "/_Preferences", NULL, 0, 0, "<Branch>" }, { "/_Preferences", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Color", NULL, 0, 0, "<Branch>" }, { "/_Preferences/_Color", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, { "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
{ "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/Color/_Blue", 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", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, { "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
{ "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" }, { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" },
{ "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" }, { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" },
{ "/_Help", NULL, 0, 0, "<LastBranch>" }, { "/_Help", NULL, 0, 0, "<LastBranch>" },
{ "/Help/_About", NULL, gtk_ifactory_cb, 0 }, { "/Help/_About", NULL, gtk_ifactory_cb, 0 },
}; };
static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
@ -78,9 +79,10 @@ do_item_factory (void)
/* preselect /Preferences/Shape/Oval over the other radios /* 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, gtk_check_menu_item_set_active
"/Preferences/Shape/Oval")), (GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory,
TRUE); "/Preferences/Shape/Oval")),
TRUE);
box1 = gtk_vbox_new (FALSE, 0); box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1); gtk_container_add (GTK_CONTAINER (window), box1);

View File

@ -93,6 +93,271 @@ read_line (FILE *stream, GString *str)
return n_read > 0; return n_read > 0;
} }
/* Stupid syntax highlighting.
*
* No regex was used in the making of this highlighting.
* It should only work for simple cases. This is good, as
* that's all we should have in the demos.
*/
/* This code should not be used elsewhere, except perhaps as an example of how
* to iterate through a text buffer.
*/
enum {
STATE_NORMAL,
STATE_IN_COMMENT,
};
static gchar *tokens[] =
{
"/*",
"\"",
NULL
};
static gchar *types[] =
{
"static",
"const ",
"void",
"gint",
"int ",
"char ",
"gchar ",
"gfloat",
"float",
"gint8",
"gint16",
"gint32",
"guint",
"guint8",
"guint16",
"guint32",
"guchar",
"glong",
"gboolean" ,
"gshort",
"gushort",
"gulong",
"gdouble",
"gldouble",
"gpointer",
"NULL",
"GList",
"GSList",
"FALSE",
"TRUE",
"FILE ",
"GtkObject ",
"GtkColorSelection ",
"GtkWidget ",
"GtkButton ",
"GdkColor ",
"GdkRectangle ",
"GdkEventExpose ",
"GdkGC ",
"GdkPixbufLoader ",
"GdkPixbuf ",
"GError",
"size_t",
NULL
};
static gchar *control[] =
{
" if ",
" while ",
" else",
" do ",
" for ",
"?",
":",
"return ",
"goto ",
NULL
};
void
parse_chars (gchar *text,
gchar **end_ptr,
gint *state,
gchar **tag,
gboolean start)
{
gint i;
gchar *next_token;
/* Handle comments first */
if (*state == STATE_IN_COMMENT)
{
*end_ptr = strstr (text, "*/");
if (*end_ptr)
{
*end_ptr += 2;
*state = STATE_NORMAL;
*tag = "comment";
}
return;
}
*tag = NULL;
*end_ptr = NULL;
/* check for comment */
if (!strncmp (text, "/*", 2))
{
*end_ptr = strstr (text, "*/");
if (*end_ptr)
*end_ptr += 2;
else
*state = STATE_IN_COMMENT;
*tag = "comment";
return;
}
/* check for preprocessor defines */
if (*text == '#' && start)
{
*end_ptr = NULL;
*tag = "preprocessor";
return;
}
/* functions */
if (start && * text != '\t' && *text != ' ' && *text != '{' && *text != '}')
{
if (strstr (text, "("))
{
*end_ptr = strstr (text, "(");
*tag = "function";
return;
}
}
/* check for types */
for (i = 0; types[i] != NULL; i++)
if (!strncmp (text, types[i], strlen (types[i])))
{
*end_ptr = text + strlen (types[i]);
*tag = "type";
return;
}
/* check for control */
for (i = 0; control[i] != NULL; i++)
if (!strncmp (text, control[i], strlen (control[i])))
{
*end_ptr = text + strlen (control[i]);
*tag = "control";
return;
}
/* check for string */
if (text[0] == '"')
{
gint maybe_escape = FALSE;
*end_ptr = text + 1;
*tag = "string";
while (**end_ptr != '\000')
{
if (**end_ptr == '\"' && !maybe_escape)
{
*end_ptr += 1;
return;
}
if (**end_ptr == '\\')
maybe_escape = TRUE;
else
maybe_escape = FALSE;
*end_ptr += 1;
}
return;
}
/* not at the start of a tag. Find the next one. */
for (i = 0; tokens[i] != NULL; i++)
{
next_token = strstr (text, tokens[i]);
if (next_token)
{
if (*end_ptr)
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
else
*end_ptr = next_token;
}
}
for (i = 0; types[i] != NULL; i++)
{
next_token = strstr (text, types[i]);
if (next_token)
{
if (*end_ptr)
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
else
*end_ptr = next_token;
}
}
for (i = 0; control[i] != NULL; i++)
{
next_token = strstr (text, control[i]);
if (next_token)
{
if (*end_ptr)
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
else
*end_ptr = next_token;
}
}
}
/* While not as cool as c-mode, this will do as a quick attempt at highlighting */
static void
fontify ()
{
GtkTextIter start_iter, next_iter, tmp_iter;
gint state;
gchar *text;
gchar *start_ptr, *end_ptr;
gchar *tag;
state = STATE_NORMAL;
gtk_text_buffer_get_iter_at_offset (source_buffer, &start_iter, 0);
next_iter = start_iter;
while (gtk_text_iter_forward_line (&next_iter))
{
gboolean start = TRUE;
start_ptr = text = gtk_text_iter_get_text (&start_iter, &next_iter);
do
{
parse_chars (start_ptr, &end_ptr, &state, &tag, start);
start = FALSE;
if (end_ptr)
{
tmp_iter = start_iter;
gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
}
else
{
tmp_iter = next_iter;
}
if (tag)
gtk_text_buffer_apply_tag_by_name (info_buffer, tag, &start_iter, &tmp_iter);
start_iter = tmp_iter;
start_ptr = end_ptr;
}
while (end_ptr);
g_free (text);
start_iter = next_iter;
}
}
void void
load_file (const gchar *filename) load_file (const gchar *filename)
{ {
@ -230,8 +495,7 @@ load_file (const gchar *filename)
} }
} }
gtk_text_buffer_get_bounds (source_buffer, &start, &end); fontify ();
gtk_text_buffer_apply_tag_by_name (info_buffer, "source", &start, &end);
g_string_free (buffer, TRUE); g_string_free (buffer, TRUE);
} }
@ -381,7 +645,7 @@ create_text (GtkTextBuffer **buffer,
if (is_source) if (is_source)
{ {
font_desc = pango_font_description_from_string ("Courier 10"); font_desc = pango_font_description_from_string ("Courier 14");
gtk_widget_modify_font (text_view, font_desc); gtk_widget_modify_font (text_view, font_desc);
pango_font_description_free (font_desc); pango_font_description_free (font_desc);
@ -505,10 +769,26 @@ main (int argc, char **argv)
"font", "Sans 18", "font", "Sans 18",
NULL); NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "source", tag = gtk_text_buffer_create_tag (info_buffer, "comment",
"font", "Courier 10", "foreground", "blue",
"pixels_above_lines", 0, NULL);
"pixels_below_lines", 0, tag = gtk_text_buffer_create_tag (info_buffer, "type",
"foreground", "red",
NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "string",
"foreground", "SpringGreen3",
"weight", PANGO_WEIGHT_BOLD,
NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "control",
"foreground", "purple",
NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "preprocessor",
"style", PANGO_STYLE_OBLIQUE,
"foreground", "burlywood4",
NULL);
tag = gtk_text_buffer_create_tag (info_buffer, "function",
"weight", PANGO_WEIGHT_BOLD,
"foreground", "DarkGoldenrod4",
NULL); NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);

View File

@ -28,13 +28,14 @@
* *
*/ */
#include <stdio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
static GtkWidget* #include <stdio.h>
create_menu (gint depth, gboolean tearoff)
static GtkWidget *
create_menu (gint depth,
gboolean tearoff)
{ {
GtkWidget *menu; GtkWidget *menu;
GtkWidget *menuitem; GtkWidget *menuitem;
@ -215,4 +216,3 @@ do_menus (void)
return window; return window;
} }

View File

@ -14,7 +14,8 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
void void
toggle_resize (GtkWidget *widget, GtkWidget *child) toggle_resize (GtkWidget *widget,
GtkWidget *child)
{ {
GtkPaned *paned = GTK_PANED (child->parent); GtkPaned *paned = GTK_PANED (child->parent);
gboolean is_child1 = (child == paned->child1); gboolean is_child1 = (child == paned->child1);
@ -33,7 +34,8 @@ toggle_resize (GtkWidget *widget, GtkWidget *child)
} }
void void
toggle_shrink (GtkWidget *widget, GtkWidget *child) toggle_shrink (GtkWidget *widget,
GtkWidget *child)
{ {
GtkPaned *paned = GTK_PANED (child->parent); GtkPaned *paned = GTK_PANED (child->parent);
gboolean is_child1 = (child == paned->child1); gboolean is_child1 = (child == paned->child1);
@ -52,7 +54,7 @@ toggle_shrink (GtkWidget *widget, GtkWidget *child)
} }
GtkWidget * GtkWidget *
create_pane_options (GtkPaned *paned, create_pane_options (GtkPaned *paned,
const gchar *frame_label, const gchar *frame_label,
const gchar *label1, const gchar *label1,
const gchar *label2) const gchar *label2)

View File

@ -9,7 +9,7 @@
* off how to use GtkDrawingArea to do a simple animation. * off how to use GtkDrawingArea to do a simple animation.
* *
* Look at the Image demo for additional pixbuf usage examples. * Look at the Image demo for additional pixbuf usage examples.
* *
*/ */
#include <config.h> #include <config.h>
@ -17,8 +17,6 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <math.h> #include <math.h>
#define FRAME_DELAY 50 #define FRAME_DELAY 50
#define RELATIVE_BACKGROUND_NAME "background.jpg" #define RELATIVE_BACKGROUND_NAME "background.jpg"
@ -56,7 +54,7 @@ static GdkPixbuf *frame;
/* Background image */ /* Background image */
static GdkPixbuf *background; static GdkPixbuf *background;
static int back_width, back_height; static gint back_width, back_height;
/* Images */ /* Images */
static GdkPixbuf *images[N_IMAGES]; static GdkPixbuf *images[N_IMAGES];
@ -64,18 +62,16 @@ static GdkPixbuf *images[N_IMAGES];
/* Widgets */ /* Widgets */
static GtkWidget *da; static GtkWidget *da;
/* Loads the images for the demo and returns whether the operation succeeded */ /* Loads the images for the demo and returns whether the operation succeeded */
static gboolean static gboolean
load_pixbufs (GError **error) load_pixbufs (GError **error)
{ {
int i; gint i;
const char **image_names; const gchar **image_names;
if (background) if (background)
return TRUE; /* already loaded earlier */ return TRUE; /* already loaded earlier */
background = gdk_pixbuf_new_from_file (RELATIVE_BACKGROUND_NAME, NULL); background = gdk_pixbuf_new_from_file (RELATIVE_BACKGROUND_NAME, NULL);
if (!background) if (!background)
@ -83,7 +79,7 @@ load_pixbufs (GError **error)
if (!background) if (!background)
return FALSE; /* note that "error" was filled in and returned */ return FALSE; /* note that "error" was filled in and returned */
back_width = gdk_pixbuf_get_width (background); back_width = gdk_pixbuf_get_width (background);
back_height = gdk_pixbuf_get_height (background); back_height = gdk_pixbuf_get_height (background);
@ -91,12 +87,12 @@ load_pixbufs (GError **error)
image_names = relative_image_names; image_names = relative_image_names;
else else
image_names = installed_image_names; image_names = installed_image_names;
for (i = 0; i < N_IMAGES; i++) for (i = 0; i < N_IMAGES; i++)
{ {
images[i] = gdk_pixbuf_new_from_file (image_names[i], error); images[i] = gdk_pixbuf_new_from_file (image_names[i], error);
if (!images[i]) if (!images[i])
return FALSE; /* Note that "error" was filled with a GError */ return FALSE; /* Note that "error" was filled with a GError */
} }
return TRUE; return TRUE;
@ -104,7 +100,9 @@ load_pixbufs (GError **error)
/* Expose callback for the drawing area */ /* Expose callback for the drawing area */
static gint static gint
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) expose_cb (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
{ {
guchar *pixels; guchar *pixels;
int rowstride; int rowstride;
@ -112,14 +110,14 @@ expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
rowstride = gdk_pixbuf_get_rowstride (frame); rowstride = gdk_pixbuf_get_rowstride (frame);
pixels = gdk_pixbuf_get_pixels (frame) + rowstride * event->area.y + event->area.x * 3; pixels = gdk_pixbuf_get_pixels (frame) + rowstride * event->area.y + event->area.x * 3;
gdk_draw_rgb_image_dithalign (widget->window, gdk_draw_rgb_image_dithalign (widget->window,
widget->style->black_gc, widget->style->black_gc,
event->area.x, event->area.y, event->area.x, event->area.y,
event->area.width, event->area.height, event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL, GDK_RGB_DITHER_NORMAL,
pixels, rowstride, pixels, rowstride,
event->area.x, event->area.y); event->area.x, event->area.y);
return TRUE; return TRUE;
} }
@ -138,7 +136,7 @@ timeout (gpointer data)
double radius; double radius;
gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height, gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height,
frame, 0, 0); frame, 0, 0);
f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN; f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN;
@ -181,16 +179,16 @@ timeout (gpointer data)
r2.height = back_height; r2.height = back_height;
if (gdk_rectangle_intersect (&r1, &r2, &dest)) if (gdk_rectangle_intersect (&r1, &r2, &dest))
gdk_pixbuf_composite (images[i], gdk_pixbuf_composite (images[i],
frame, frame,
dest.x, dest.y, dest.x, dest.y,
dest.width, dest.height, dest.width, dest.height,
xpos, ypos, xpos, ypos,
k, k, k, k,
GDK_INTERP_NEAREST, GDK_INTERP_NEAREST,
((i & 1) ((i & 1)
? MAX (127, fabs (255 * sin (f * 2.0 * M_PI))) ? MAX (127, fabs (255 * sin (f * 2.0 * M_PI)))
: MAX (127, fabs (255 * cos (f * 2.0 * M_PI))))); : MAX (127, fabs (255 * cos (f * 2.0 * M_PI)))));
} }
gtk_widget_queue_draw (da); gtk_widget_queue_draw (da);
@ -203,7 +201,7 @@ static guint timeout_id;
static void static void
cleanup_callback (GtkObject *object, cleanup_callback (GtkObject *object,
gpointer data) gpointer data)
{ {
g_source_remove (timeout_id); g_source_remove (timeout_id);
timeout_id = 0; timeout_id = 0;
@ -216,53 +214,53 @@ do_pixbufs (void)
{ {
GError *error; GError *error;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Pixbufs"); gtk_window_set_title (GTK_WINDOW (window), "Pixbufs");
gtk_window_set_resizeable (GTK_WINDOW (window), FALSE); gtk_window_set_resizeable (GTK_WINDOW (window), FALSE);
gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window);
gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (cleanup_callback), NULL); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (cleanup_callback), NULL);
error = NULL; error = NULL;
if (!load_pixbufs (&error)) if (!load_pixbufs (&error))
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window), dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
"Failed to load an image: %s", "Failed to load an image: %s",
error->message); error->message);
g_error_free (error); g_error_free (error);
gtk_signal_connect (GTK_OBJECT (dialog), gtk_signal_connect (GTK_OBJECT (dialog),
"response", "response",
GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_SIGNAL_FUNC (gtk_widget_destroy),
NULL); NULL);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
else else
{ {
gtk_widget_set_usize (window, back_width, back_height); gtk_widget_set_usize (window, back_width, back_height);
frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height); frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height);
da = gtk_drawing_area_new (); da = gtk_drawing_area_new ();
gtk_signal_connect (GTK_OBJECT (da), "expose_event", gtk_signal_connect (GTK_OBJECT (da), "expose_event",
GTK_SIGNAL_FUNC (expose_cb), NULL); GTK_SIGNAL_FUNC (expose_cb), NULL);
gtk_container_add (GTK_CONTAINER (window), da); gtk_container_add (GTK_CONTAINER (window), da);
timeout_id = gtk_timeout_add (FRAME_DELAY, timeout, NULL); timeout_id = gtk_timeout_add (FRAME_DELAY, timeout, NULL);
} }
} }
if (!GTK_WIDGET_VISIBLE (window)) if (!GTK_WIDGET_VISIBLE (window))
{ {
gtk_widget_show_all (window); gtk_widget_show_all (window);

View File

@ -12,30 +12,30 @@
/* Don't copy this bad example; inline RGB data is always a better /* Don't copy this bad example; inline RGB data is always a better
* idea than inline XPMs. * idea than inline XPMs.
*/ */
static char *book_closed_xpm[] = { static char *book_closed_xpm[] = {
"16 16 6 1", "16 16 6 1",
" c None s None", " c None s None",
". c black", ". c black",
"X c red", "X c red",
"o c yellow", "o c yellow",
"O c #808080", "O c #808080",
"# c white", "# c white",
" ", " ",
" .. ", " .. ",
" ..XX. ", " ..XX. ",
" ..XXXXX. ", " ..XXXXX. ",
" ..XXXXXXXX. ", " ..XXXXXXXX. ",
".ooXXXXXXXXX. ", ".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ", "..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ", ".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ", ".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ", " .XX.ooXXX..#O ",
" .XX.oo..##OO. ", " .XX.oo..##OO. ",
" .XX..##OO.. ", " .XX..##OO.. ",
" .X.#OO.. ", " .X.#OO.. ",
" ..O.. ", " ..O.. ",
" .. ", " .. ",
" " " "
}; };
@ -63,111 +63,111 @@ create_tags (GtkTextBuffer *buffer)
* new copies of the same tags for every buffer. * new copies of the same tags for every buffer.
* *
* Tags are assigned default priorities in order of addition to the * Tags are assigned default priorities in order of addition to the
* tag table. That is, tags created later that affect the same text * tag table. That is, tags created later that affect the same text
* property affected by an earlier tag will override the earlier * property affected by an earlier tag will override the earlier
* tag. You can modify tag priorities with * tag. You can modify tag priorities with
* gtk_text_tag_set_priority(). * gtk_text_tag_set_priority().
*/ */
gtk_text_buffer_create_tag (buffer, "heading", gtk_text_buffer_create_tag (buffer, "heading",
"weight", PANGO_WEIGHT_BOLD, "weight", PANGO_WEIGHT_BOLD,
"size", 20 * PANGO_SCALE, "size", 20 * PANGO_SCALE,
NULL); NULL);
gtk_text_buffer_create_tag (buffer, "italic", gtk_text_buffer_create_tag (buffer, "italic",
"style", PANGO_STYLE_ITALIC, NULL); "style", PANGO_STYLE_ITALIC, NULL);
gtk_text_buffer_create_tag (buffer, "bold", gtk_text_buffer_create_tag (buffer, "bold",
"weight", PANGO_WEIGHT_BOLD, NULL); "weight", PANGO_WEIGHT_BOLD, NULL);
gtk_text_buffer_create_tag (buffer, "big", gtk_text_buffer_create_tag (buffer, "big",
/* points times the PANGO_SCALE factor */ /* points times the PANGO_SCALE factor */
"size", 30 * PANGO_SCALE, NULL); "size", 30 * PANGO_SCALE, NULL);
gtk_text_buffer_create_tag (buffer, "xx-small", gtk_text_buffer_create_tag (buffer, "xx-small",
"scale", PANGO_SCALE_XX_SMALL, NULL); "scale", PANGO_SCALE_XX_SMALL, NULL);
gtk_text_buffer_create_tag (buffer, "x-large", gtk_text_buffer_create_tag (buffer, "x-large",
"scale", PANGO_SCALE_X_LARGE, NULL); "scale", PANGO_SCALE_X_LARGE, NULL);
gtk_text_buffer_create_tag (buffer, "monospace", gtk_text_buffer_create_tag (buffer, "monospace",
"family", "monospace", NULL); "family", "monospace", NULL);
gtk_text_buffer_create_tag (buffer, "blue_foreground", gtk_text_buffer_create_tag (buffer, "blue_foreground",
"foreground", "blue", NULL); "foreground", "blue", NULL);
gtk_text_buffer_create_tag (buffer, "red_background", gtk_text_buffer_create_tag (buffer, "red_background",
"background", "red", NULL); "background", "red", NULL);
stipple = gdk_bitmap_create_from_data (NULL, stipple = gdk_bitmap_create_from_data (NULL,
gray50_bits, gray50_width, gray50_bits, gray50_width,
gray50_height); gray50_height);
gtk_text_buffer_create_tag (buffer, "background_stipple", gtk_text_buffer_create_tag (buffer, "background_stipple",
"background_stipple", stipple, NULL); "background_stipple", stipple, NULL);
gtk_text_buffer_create_tag (buffer, "foreground_stipple", gtk_text_buffer_create_tag (buffer, "foreground_stipple",
"foreground_stipple", stipple, NULL); "foreground_stipple", stipple, NULL);
g_object_unref (G_OBJECT (stipple)); g_object_unref (G_OBJECT (stipple));
gtk_text_buffer_create_tag (buffer, "big_gap_before_line", gtk_text_buffer_create_tag (buffer, "big_gap_before_line",
"pixels_above_lines", 30, NULL); "pixels_above_lines", 30, NULL);
gtk_text_buffer_create_tag (buffer, "big_gap_after_line", gtk_text_buffer_create_tag (buffer, "big_gap_after_line",
"pixels_below_lines", 30, NULL); "pixels_below_lines", 30, NULL);
gtk_text_buffer_create_tag (buffer, "double_spaced_line", gtk_text_buffer_create_tag (buffer, "double_spaced_line",
"pixels_inside_wrap", 10, NULL); "pixels_inside_wrap", 10, NULL);
gtk_text_buffer_create_tag (buffer, "not_editable", gtk_text_buffer_create_tag (buffer, "not_editable",
"editable", FALSE, NULL); "editable", FALSE, NULL);
gtk_text_buffer_create_tag (buffer, "word_wrap", gtk_text_buffer_create_tag (buffer, "word_wrap",
"wrap_mode", GTK_WRAP_WORD, NULL); "wrap_mode", GTK_WRAP_WORD, NULL);
gtk_text_buffer_create_tag (buffer, "char_wrap", gtk_text_buffer_create_tag (buffer, "char_wrap",
"wrap_mode", GTK_WRAP_CHAR, NULL); "wrap_mode", GTK_WRAP_CHAR, NULL);
gtk_text_buffer_create_tag (buffer, "no_wrap", gtk_text_buffer_create_tag (buffer, "no_wrap",
"wrap_mode", GTK_WRAP_NONE, NULL); "wrap_mode", GTK_WRAP_NONE, NULL);
gtk_text_buffer_create_tag (buffer, "center", gtk_text_buffer_create_tag (buffer, "center",
"justification", GTK_JUSTIFY_CENTER, NULL); "justification", GTK_JUSTIFY_CENTER, NULL);
gtk_text_buffer_create_tag (buffer, "right_justify", gtk_text_buffer_create_tag (buffer, "right_justify",
"justification", GTK_JUSTIFY_RIGHT, NULL); "justification", GTK_JUSTIFY_RIGHT, NULL);
gtk_text_buffer_create_tag (buffer, "wide_margins", gtk_text_buffer_create_tag (buffer, "wide_margins",
"left_margin", 50, "right_margin", 50, "left_margin", 50, "right_margin", 50,
NULL); NULL);
gtk_text_buffer_create_tag (buffer, "strikethrough", gtk_text_buffer_create_tag (buffer, "strikethrough",
"strikethrough", TRUE, NULL); "strikethrough", TRUE, NULL);
gtk_text_buffer_create_tag (buffer, "underline", gtk_text_buffer_create_tag (buffer, "underline",
"underline", PANGO_UNDERLINE_SINGLE, NULL); "underline", PANGO_UNDERLINE_SINGLE, NULL);
gtk_text_buffer_create_tag (buffer, "double_underline", gtk_text_buffer_create_tag (buffer, "double_underline",
"underline", PANGO_UNDERLINE_DOUBLE, NULL); "underline", PANGO_UNDERLINE_DOUBLE, NULL);
gtk_text_buffer_create_tag (buffer, "superscript", gtk_text_buffer_create_tag (buffer, "superscript",
"rise", 10 * PANGO_SCALE, /* 10 pixels */ "rise", 10 * PANGO_SCALE, /* 10 pixels */
"size", 8 * PANGO_SCALE, /* 8 points */ "size", 8 * PANGO_SCALE, /* 8 points */
NULL); NULL);
gtk_text_buffer_create_tag (buffer, "subscript", gtk_text_buffer_create_tag (buffer, "subscript",
"rise", -10 * PANGO_SCALE, /* 10 pixels */ "rise", -10 * PANGO_SCALE, /* 10 pixels */
"size", 8 * PANGO_SCALE, /* 8 points */ "size", 8 * PANGO_SCALE, /* 8 points */
NULL); NULL);
gtk_text_buffer_create_tag (buffer, "rtl_quote", gtk_text_buffer_create_tag (buffer, "rtl_quote",
"wrap_mode", GTK_WRAP_WORD, "wrap_mode", GTK_WRAP_WORD,
"direction", GTK_TEXT_DIR_RTL, "direction", GTK_TEXT_DIR_RTL,
"indent", 30, "indent", 30,
"left_margin", 20, "left_margin", 20,
"right_margin", 20, "right_margin", 20,
NULL); NULL);
} }
static void static void
@ -187,88 +187,88 @@ insert_text (GtkTextBuffer *buffer)
gtk_text_buffer_insert (buffer, &iter, "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Font styles. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Font styles. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, "For example, you can have ", -1); gtk_text_buffer_insert (buffer, &iter, "For example, you can have ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"italic", -1, "italic", -1,
"italic", NULL); "italic", NULL);
gtk_text_buffer_insert (buffer, &iter, ", ", -1); gtk_text_buffer_insert (buffer, &iter, ", ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"bold", -1, "bold", -1,
"bold", NULL); "bold", NULL);
gtk_text_buffer_insert (buffer, &iter, ", or ", -1); gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"monospace (typewriter)", -1, "monospace (typewriter)", -1,
"monospace", NULL); "monospace", NULL);
gtk_text_buffer_insert (buffer, &iter, ", or ", -1); gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"big", -1, "big", -1,
"big", NULL); "big", NULL);
gtk_text_buffer_insert (buffer, &iter, " text. ", -1); gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
gtk_text_buffer_insert (buffer, &iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ", -1); gtk_text_buffer_insert (buffer, &iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"xx-small", -1, "xx-small", -1,
"xx-small", NULL); "xx-small", NULL);
gtk_text_buffer_insert (buffer, &iter, " or ", -1); gtk_text_buffer_insert (buffer, &iter, " or ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"x-large", -1, "x-large", -1,
"x-large", NULL); "x-large", NULL);
gtk_text_buffer_insert (buffer, &iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1); gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"a blue foreground", -1, "a blue foreground", -1,
"blue_foreground", NULL); "blue_foreground", NULL);
gtk_text_buffer_insert (buffer, &iter, " or ", -1); gtk_text_buffer_insert (buffer, &iter, " or ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"a red background", -1, "a red background", -1,
"red_background", NULL); "red_background", NULL);
gtk_text_buffer_insert (buffer, &iter, " or even ", -1); gtk_text_buffer_insert (buffer, &iter, " or even ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"a stippled red background", -1, "a stippled red background", -1,
"red_background", "red_background",
"background_stipple", "background_stipple",
NULL); NULL);
gtk_text_buffer_insert (buffer, &iter, " or ", -1); gtk_text_buffer_insert (buffer, &iter, " or ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"a stippled blue foreground on solid red background", -1, "a stippled blue foreground on solid red background", -1,
"blue_foreground", "blue_foreground",
"red_background", "red_background",
"foreground_stipple", "foreground_stipple",
NULL); NULL);
gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Underline, strikethrough, and rise. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Underline, strikethrough, and rise. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"Strikethrough", -1, "Strikethrough", -1,
"strikethrough", NULL); "strikethrough", NULL);
gtk_text_buffer_insert (buffer, &iter, ", ", -1); gtk_text_buffer_insert (buffer, &iter, ", ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"underline", -1, "underline", -1,
"underline", NULL); "underline", NULL);
gtk_text_buffer_insert (buffer, &iter, ", ", -1); gtk_text_buffer_insert (buffer, &iter, ", ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"double underline", -1, "double underline", -1,
"double_underline", NULL); "double_underline", NULL);
gtk_text_buffer_insert (buffer, &iter, ", ", -1); gtk_text_buffer_insert (buffer, &iter, ", ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"superscript", -1, "superscript", -1,
"superscript", NULL); "superscript", NULL);
gtk_text_buffer_insert (buffer, &iter, ", and ", -1); gtk_text_buffer_insert (buffer, &iter, ", and ", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"subscript", -1, "subscript", -1,
"subscript", NULL); "subscript", NULL);
gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1); gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
@ -277,68 +277,68 @@ insert_text (GtkTextBuffer *buffer)
gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, "You can adjust the amount of space before each line.\n", -1); gtk_text_buffer_insert (buffer, &iter, "You can adjust the amount of space before each line.\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"This line has a whole lot of space before it.\n", -1, "This line has a whole lot of space before it.\n", -1,
"big_gap_before_line", "wide_margins", NULL); "big_gap_before_line", "wide_margins", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", -1, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", -1,
"big_gap_after_line", "wide_margins", NULL); "big_gap_after_line", "wide_margins", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", -1, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", -1,
"double_spaced_line", "wide_margins", NULL); "double_spaced_line", "wide_margins", NULL);
gtk_text_buffer_insert (buffer, &iter, "Also note that those lines have extra-wide margins.\n\n", -1); gtk_text_buffer_insert (buffer, &iter, "Also note that those lines have extra-wide margins.\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Editability. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Editability. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", -1, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", -1,
"not_editable", NULL); "not_editable", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Wrapping. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Wrapping. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, gtk_text_buffer_insert (buffer, &iter,
"This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1); "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1,
"char_wrap", NULL); "char_wrap", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", -1, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", -1,
"no_wrap", NULL); "no_wrap", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Justification. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Justification. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"\nThis line has center justification.\n", -1, "\nThis line has center justification.\n", -1,
"center", NULL); "center", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"This line has right justification.\n", -1, "This line has right justification.\n", -1,
"right_justify", NULL); "right_justify", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
"\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", -1, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", -1,
"wide_margins", NULL); "wide_margins", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Internationalization. ", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Internationalization. ", -1,
"heading", NULL); "heading", NULL);
gtk_text_buffer_insert (buffer, &iter, gtk_text_buffer_insert (buffer, &iter,
"You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch Süd) Grüß Gott\nGreek (Ελληνικά) Γειά σας\nHebrew שלום\nJapanese (日本語)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n", -1); "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch Süd) Grüß Gott\nGreek (Ελληνικά) Γειά σας\nHebrew שלום\nJapanese (日本語)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n", -1);
gtk_text_buffer_insert (buffer, &iter, "Here's a word-wrapped quote in a right-to-left language:\n", -1); gtk_text_buffer_insert (buffer, &iter, "Here's a word-wrapped quote in a right-to-left language:\n", -1);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "وقد بدأ ثلاث من أكثر المؤسسات تقدما في شبكة اكسيون برامجها كمنظمات لا تسعى للربح، ثم تحولت في السنوات الخمس الماضية إلى مؤسسات مالية منظمة، وباتت جزءا من النظام المالي في بلدانها، ولكنها تتخصص في خدمة قطاع المشروعات الصغيرة. وأحد أكثر هذه المؤسسات نجاحا هو »بانكوسول« في بوليفيا.\n\n", -1, gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "وقد بدأ ثلاث من أكثر المؤسسات تقدما في شبكة اكسيون برامجها كمنظمات لا تسعى للربح، ثم تحولت في السنوات الخمس الماضية إلى مؤسسات مالية منظمة، وباتت جزءا من النظام المالي في بلدانها، ولكنها تتخصص في خدمة قطاع المشروعات الصغيرة. وأحد أكثر هذه المؤسسات نجاحا هو »بانكوسول« في بوليفيا.\n\n", -1,
"rtl_quote", NULL); "rtl_quote", NULL);
gtk_text_buffer_insert (buffer, &iter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...", -1); gtk_text_buffer_insert (buffer, &iter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...", -1);
@ -364,7 +364,7 @@ do_textview (void)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), gtk_window_set_default_size (GTK_WINDOW (window),
450, 450); 450, 450);
gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(gtk_widget_destroyed), GTK_SIGNAL_FUNC(gtk_widget_destroyed),
@ -388,16 +388,16 @@ do_textview (void)
sw = gtk_scrolled_window_new (NULL, NULL); sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC); GTK_POLICY_AUTOMATIC);
gtk_paned_add1 (GTK_PANED (vpaned), sw); gtk_paned_add1 (GTK_PANED (vpaned), sw);
gtk_container_add (GTK_CONTAINER (sw), view1); gtk_container_add (GTK_CONTAINER (sw), view1);
sw = gtk_scrolled_window_new (NULL, NULL); sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC); GTK_POLICY_AUTOMATIC);
gtk_paned_add2 (GTK_PANED (vpaned), sw); gtk_paned_add2 (GTK_PANED (vpaned), sw);
gtk_container_add (GTK_CONTAINER (sw), view2); gtk_container_add (GTK_CONTAINER (sw), view2);