summaryrefslogtreecommitdiff
path: root/tests/testgtk.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>1998-08-25 00:06:38 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-08-25 00:06:38 +0000
commitcaf8ebc6f141697ae7a8a89ddce6afc295c69588 (patch)
tree7a5490219e90c7d42bda5f5f8c965e85fb5b98d3 /tests/testgtk.c
parentb93d68929025fd54f10c9dcdfaa95b023406d057 (diff)
downloadgtk+-caf8ebc6f141697ae7a8a89ddce6afc295c69588.tar.gz
Reference count the fonts used in the text widget.
Mon Aug 24 18:37:15 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtktext.c: Reference count the fonts used in the text widget. * gdk/gdk.h gdk/gdkcolor.c: Rename the color allocation freeing functions to be more consistent, and more convenient; leave the old names in for backwards compatibility. * gdk/gdkcolor.c gdk/gdkprivate.h: Reference count the allocations in pseudo-color colormaps to greatly reduce calls to XAllocColor. Keep a per-colormap hashtable to speed up finding if there is an already-allocated matching color. * gdk/gdkcolor.c: Don't just match read the system colormap when the colormap is created, but synchronize our copy with the system colormap periodically. * gdk/gdk.c gdk/gdktypes.h gtk/gtkentry.c gtk/gtktext.c: Change XIM constants names to match GDK conventions * gtk/testinput.c: Allow the drawing area to get the focus. * gtk/testgtk.c: Change around the Text test to demonstrates multiple fonts, use more colors. * gtk/gtkwidget.c: Improve gtk_widget_get_colormap()/visual() so they work after a widget is unrealized. * gtk/gtktext.[ch]: Remove the requirement that the text widget be realized before adding text (!) Allocate colors ourself, instead of requiring the caller allocate them. Allow changing styles to work properly by keeping track of the values for a certain property are default or set explicitely. * gtk/gtkmenu.h: Added some comments. * gtk/gtkentry.c: Changes to match XIM constants. * gtk/gdk.h gdk/gdkwindow.c: Add gdk_drawable_set_data(), for adding keyed data to drawables. (Uses g_dataset internally) * gdk/gdkpixmap.c: Keep track of the colors we allocate, when creating an XPM - store them as user data for the GdkPixmap, so we don't leak colors when we create pixmaps from XPM's. Allocate memory for color information in large blocks instead of as many little pieces.
Diffstat (limited to 'tests/testgtk.c')
-rw-r--r--tests/testgtk.c69
1 files changed, 61 insertions, 8 deletions
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 22cb8990cf..f101c15a7a 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -1759,6 +1759,8 @@ create_pixmap (void)
&style->bg[GTK_STATE_NORMAL],
"test.xpm");
pixmapwid = gtk_pixmap_new (pixmap, mask);
+ gdk_pixmap_unref (pixmap);
+ gdk_pixmap_unref (mask);
label = gtk_label_new ("Pixmap\ntest");
box3 = gtk_hbox_new (FALSE, 0);
@@ -5186,13 +5188,43 @@ text_toggle_word_wrap (GtkWidget *checkbutton,
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
+struct {
+ GdkColor color;
+ gchar *name;
+} text_colors[] = {
+ { { 0, 0x0000, 0x0000, 0x0000 }, "black" },
+ { { 0, 0xFFFF, 0xFFFF, 0xFFFF }, "white" },
+ { { 0, 0xFFFF, 0x0000, 0x0000 }, "red" },
+ { { 0, 0x0000, 0xFFFF, 0x0000 }, "green" },
+ { { 0, 0x0000, 0x0000, 0xFFFF }, "blue" },
+ { { 0, 0x0000, 0xFFFF, 0xFFFF }, "cyan" },
+ { { 0, 0xFFFF, 0x0000, 0xFFFF }, "magenta" },
+ { { 0, 0xFFFF, 0xFFFF, 0x0000 }, "yellow" }
+};
+
+int ntext_colors = sizeof(text_colors) / sizeof(text_colors[0]);
+
/*
* GtkText
*/
+void
+text_insert_random (GtkWidget *w, GtkText *text)
+{
+ int i;
+ char c;
+ for (i=0; i<10; i++)
+ {
+ c = 'A' + rand() % ('Z' - 'A');
+ gtk_text_set_point (text, rand() % gtk_text_get_length (text));
+ gtk_text_insert (text, NULL, NULL, NULL, &c, 1);
+ }
+}
void
create_text (void)
{
+ int i, j;
+
static GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
@@ -5204,6 +5236,7 @@ create_text (void)
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkWidget *text;
+ GdkFont *font;
FILE *infile;
@@ -5259,7 +5292,27 @@ create_text (void)
gtk_text_freeze (GTK_TEXT (text));
- gtk_widget_realize (text);
+ font = gdk_font_load ("-adobe-courier-medium-r-normal--*-120-*-*-*-*-*-*");
+
+ for (i=0; i<ntext_colors; i++)
+ {
+ gtk_text_insert (GTK_TEXT (text), font, NULL, NULL,
+ text_colors[i].name, -1);
+ gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, "\t", -1);
+
+ for (j=0; j<ntext_colors; j++)
+ {
+ gtk_text_insert (GTK_TEXT (text), font,
+ &text_colors[j].color, &text_colors[i].color,
+ "XYZ", -1);
+ }
+ gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, "\n", -1);
+ }
+
+ /* The Text widget will reference count the font, so we
+ * unreference it here
+ */
+ gdk_font_unref (font);
infile = fopen("testgtk.c", "r");
@@ -5281,13 +5334,6 @@ create_text (void)
fclose (infile);
}
- gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
- "And even ", -1);
- gtk_text_insert (GTK_TEXT (text), NULL, &text->style->bg[GTK_STATE_NORMAL], NULL,
- "colored", -1);
- gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL,
- "text", -1);
-
gtk_text_thaw (GTK_TEXT (text));
hbox = gtk_hbutton_box_new ();
@@ -5319,6 +5365,13 @@ create_text (void)
gtk_widget_show (box2);
+ button = gtk_button_new_with_label ("insert random");
+ gtk_signal_connect (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC(text_insert_random),
+ GTK_TEXT (text));
+ gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
+ gtk_widget_show (button);
+
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),