summaryrefslogtreecommitdiff
path: root/demos/gtk-demo/images.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-11-23 21:46:44 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-11-23 21:46:44 +0000
commit2936c8e9423cc28555dbe56877a315d16b7f7d8f (patch)
tree986279438d9adf88cbd8c88b0ae067ad0bc06107 /demos/gtk-demo/images.c
parent393c47573ea197e2026133ec79eae7a02880b0d7 (diff)
downloadgtk+-2936c8e9423cc28555dbe56877a315d16b7f7d8f.tar.gz
Version 1.3.11 Require GLib-1.3.11, Pango-0.22, ATK-0.7. Restore toGTK_1_3_11
Thu Nov 22 15:01:03 2001 Owen Taylor <otaylor@redhat.com> * Version 1.3.11 * configure.in (ATK_REQUIRED_VERSION): Require GLib-1.3.11, Pango-0.22, ATK-0.7. * tests/prop-editor.c (property_widget): Restore to working as well as it did before. * gtk/gtklistitem.h: Mark deprecated since it is an integral part of GtkList. * demos/gtk-demo/demo-common.h: New header file, for a common functions not important to the meat of the demos. * demos/gtk-demo/main.c (demo_ifind_file): Add a utility function to search for a file used by the demo. * demos/*.c: Use demo_find_file.
Diffstat (limited to 'demos/gtk-demo/images.c')
-rw-r--r--demos/gtk-demo/images.c104
1 files changed, 56 insertions, 48 deletions
diff --git a/demos/gtk-demo/images.c b/demos/gtk-demo/images.c
index 154e14beda..4719f484ed 100644
--- a/demos/gtk-demo/images.c
+++ b/demos/gtk-demo/images.c
@@ -15,6 +15,7 @@
#include <gtk/gtk.h>
#include <stdio.h>
#include <errno.h>
+#include "demo-common.h"
static GtkWidget *window = NULL;
static GdkPixbufLoader *pixbuf_loader = NULL;
@@ -177,14 +178,29 @@ progressive_timeout (gpointer data)
}
else
{
- const gchar *filename;
+ gchar *filename;
+ gchar *error_message = NULL;
+ GError *error = NULL;
- if (g_file_test ("./alphatest.png", G_FILE_TEST_EXISTS))
- filename = "./alphatest.png";
+ /* demo_find_file() looks in the the current directory first,
+ * so you can run gtk-demo without installing GTK, then looks
+ * in the location where the file is installed.
+ */
+ filename = demo_find_file ("alphatest.png", &error);
+ if (error)
+ {
+ error_message = g_strdup (error->message);
+ g_error_free (error);
+ }
else
- filename = DEMOCODEDIR"/alphatest.png";
-
- image_stream = fopen (filename, "r");
+ {
+ image_stream = fopen (filename, "r");
+ g_free (filename);
+
+ if (!image_stream)
+ error_message = g_strdup_printf ("Unable to open image file 'alphatest.png': %s",
+ g_strerror (errno));
+ }
if (image_stream == NULL)
{
@@ -194,8 +210,8 @@ progressive_timeout (gpointer data)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
- "Unable to open image file 'alphatest.png': %s",
- g_strerror (errno));
+ "%s", error_message);
+ g_free (error_message);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
@@ -272,6 +288,9 @@ do_images (void)
GtkWidget *image;
GtkWidget *label;
GtkWidget *align;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ char *filename;
if (!window)
{
@@ -303,10 +322,19 @@ do_images (void)
gtk_container_add (GTK_CONTAINER (align), frame);
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
- /* We look for the image in the current directory first,
- * so you can run gtk-demo without installing GTK
+ /* demo_find_file() looks in the the current directory first,
+ * so you can run gtk-demo without installing GTK, then looks
+ * in the location where the file is installed.
*/
- if (g_file_test ("./gtk-logo-rgb.gif", G_FILE_TEST_EXISTS))
+ pixbuf = NULL;
+ filename = demo_find_file ("gtk-logo-rgb.gif", &error);
+ if (filename)
+ {
+ pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+ g_free (filename);
+ }
+
+ if (error)
{
/* This code shows off error handling. You can just use
* gtk_image_new_from_file() instead if you don't want to report
@@ -314,39 +342,23 @@ do_images (void)
* gtk_image_new_from_file(), a "missing image" icon will
* be displayed instead.
*/
- GdkPixbuf *pixbuf;
- GError *error = NULL;
+ GtkWidget *dialog;
- pixbuf = gdk_pixbuf_new_from_file ("./gtk-logo-rgb.gif",
- &error);
- if (error)
- {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "Unable to open image file 'gtk-logo-rgb.gif': %s",
- error->message);
- g_error_free (error);
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
-
- gtk_widget_show (dialog);
- }
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Unable to open image file 'gtk-logo-rgb.gif': %s",
+ error->message);
+ g_error_free (error);
- image = gtk_image_new_from_pixbuf (pixbuf);
- }
- else
- {
- /* This is the simpler code, with no error handling.
- * Here we're loading the installed gtk-logo-rgb.gif instead
- * of the one in the current directory.
- */
- image = gtk_image_new_from_file (DEMOCODEDIR"/gtk-logo-rgb.gif");
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show (dialog);
}
+
+ image = gtk_image_new_from_pixbuf (pixbuf);
gtk_container_add (GTK_CONTAINER (frame), image);
@@ -367,13 +379,9 @@ do_images (void)
gtk_container_add (GTK_CONTAINER (align), frame);
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
- /* We look for the image in the current directory first,
- * so you can run gtk-demo without installing GTK
- */
- if (g_file_test ("./floppybuddy.gif", G_FILE_TEST_EXISTS))
- image = gtk_image_new_from_file ("./floppybuddy.gif");
- else
- image = gtk_image_new_from_file (DEMOCODEDIR"/floppybuddy.gif");
+ filename = demo_find_file ("floppybuddy.gif", NULL);
+ image = gtk_image_new_from_file (filename);
+ g_free (filename);
gtk_container_add (GTK_CONTAINER (frame), image);