http://www.uw-madison.lkams.kernel.org/pub/mirrors/fink/distfiles/xscreensaver-4...
[xscreensaver] / driver / demo-Gtk-support.c
index ce5ea475141512a9d05f1f318ee0f18fc72fbe00..881129c4f11ca1ebd8cd66e6771b1997dbd139dd 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * DO NOT EDIT THIS FILE - it is generated by Glade.
+   WARNING: I did edit this file!  Be careful!  -jwz
  */
 
 #ifdef HAVE_CONFIG_H
 
 #include "demo-Gtk-support.h"
 
+/* jwz -- dumbass Glade1 doesn't emit code that can read PNGs. this does. */
+#ifdef HAVE_GDK_PIXBUF
+# ifdef HAVE_GTK2
+#  include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
+# else  /* !HAVE_GTK2 */
+#  include <gdk-pixbuf/gdk-pixbuf-xlib.h>
+# endif /* !HAVE_GTK2 */
+#endif /* HAVE_GDK_PIXBUF */
+
+
 /* This is an internally used function to check if a pixmap file exists. */
 static gchar* check_file_exists        (const gchar     *directory,
                                         const gchar     *filename);
@@ -86,16 +97,19 @@ add_pixmap_directory                   (const gchar     *directory)
 }
 
 /* This is an internally used function to create pixmaps. */
+/* #### Warning: this version of this function hacked by jwz to
+   support PNGs.  Don't let Glade1 overwrite this!
+ */
 GtkWidget*
 create_pixmap                          (GtkWidget       *widget,
                                         const gchar     *filename)
 {
   gchar *found_filename = NULL;
-  GdkColormap *colormap;
-  GdkPixmap *gdkpixmap;
-  GdkBitmap *mask;
-  GtkWidget *pixmap;
-  GList *elem;
+  GdkColormap *colormap = 0;
+  GdkPixmap *gdkpixmap = 0;
+  GdkBitmap *mask = 0;
+  GtkWidget *pixmap = 0;
+  GList *elem = 0;
 
   if (!filename || !filename[0])
       return create_dummy_pixmap (widget);
@@ -123,6 +137,9 @@ create_pixmap                          (GtkWidget       *widget,
     }
 
   colormap = gtk_widget_get_colormap (widget);
+
+# ifndef HAVE_GDK_PIXBUF
+
   gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
                                                    NULL, found_filename);
   if (gdkpixmap == NULL)
@@ -131,10 +148,50 @@ create_pixmap                          (GtkWidget       *widget,
       g_free (found_filename);
       return create_dummy_pixmap (widget);
     }
+
+# else /* HAVE_GDK_PIXBUF */
+
+  /* jwz -- dumbass Glade1 doesn't emit code that can read PNGs.
+     This code does... */
+
+  /* #### Danger: we aren't using `colormap'... */
+
+  {
+    GdkPixbuf *pb;
+#  ifdef HAVE_GTK2
+    GError *gerr = 0;
+#  endif /* HAVE_GTK2 */
+
+    pb = gdk_pixbuf_new_from_file (found_filename
+#  ifdef HAVE_GTK2
+                                   , &gerr
+#  endif /* HAVE_GTK2 */
+                                   );
+
+    if (pb)
+      {
+        gdkpixmap = 0;
+        mask = 0;
+        gdk_pixbuf_render_pixmap_and_mask (pb, &gdkpixmap, &mask, 128);
+      }
+    else
+      {
+        g_warning (_("Error loading pixmap file: %s"), found_filename);
+#  ifdef HAVE_GTK2
+        if (gerr && gerr->message && *gerr->message)
+          g_warning (_("reason: %s\n"), gerr->message);
+#  endif /* HAVE_GTK2 */
+
+        return create_dummy_pixmap (widget);
+      }
+  }
+# endif /* HAVE_GDK_PIXBUF */
+
   g_free (found_filename);
   pixmap = gtk_pixmap_new (gdkpixmap, mask);
   gdk_pixmap_unref (gdkpixmap);
   gdk_bitmap_unref (mask);
+
   return pixmap;
 }