2 * DO NOT EDIT THIS FILE - it is generated by Glade.
3 WARNING: I did edit this file! Be careful! -jwz
10 #include <sys/types.h>
17 #include "demo-Gtk-support.h"
19 /* jwz -- dumbass Glade1 doesn't emit code that can read PNGs. this does. */
20 #ifdef HAVE_GDK_PIXBUF
22 # include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
23 # else /* !HAVE_GTK2 */
24 # include <gdk-pixbuf/gdk-pixbuf-xlib.h>
25 # endif /* !HAVE_GTK2 */
26 #endif /* HAVE_GDK_PIXBUF */
29 /* This is an internally used function to check if a pixmap file exists. */
30 static gchar* check_file_exists (const gchar *directory,
31 const gchar *filename);
33 /* This is an internally used function to create pixmaps. */
34 static GtkWidget* create_dummy_pixmap (GtkWidget *widget);
37 lookup_widget (GtkWidget *widget,
38 const gchar *widget_name)
40 GtkWidget *parent, *found_widget;
44 if (GTK_IS_MENU (widget))
45 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
47 parent = widget->parent;
53 found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
56 g_warning ("Widget not found: %s", widget_name);
60 /* This is a dummy pixmap we use when a pixmap can't be found. */
61 static char *dummy_pixmap_xpm[] = {
62 /* columns rows colors chars-per-pixel */
69 /* This is an internally used function to create pixmaps. */
71 create_dummy_pixmap (GtkWidget *widget)
73 GdkColormap *colormap;
78 colormap = gtk_widget_get_colormap (widget);
79 gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
80 NULL, dummy_pixmap_xpm);
81 if (gdkpixmap == NULL)
82 g_error ("Couldn't create replacement pixmap.");
83 pixmap = gtk_pixmap_new (gdkpixmap, mask);
84 gdk_pixmap_unref (gdkpixmap);
85 gdk_bitmap_unref (mask);
89 static GList *pixmaps_directories = NULL;
91 /* Use this function to set the directory containing installed pixmaps. */
93 add_pixmap_directory (const gchar *directory)
95 pixmaps_directories = g_list_prepend (pixmaps_directories,
96 g_strdup (directory));
99 /* This is an internally used function to create pixmaps. */
100 /* #### Warning: this version of this function hacked by jwz to
101 support PNGs. Don't let Glade1 overwrite this!
104 create_pixmap (GtkWidget *widget,
105 const gchar *filename)
107 gchar *found_filename = NULL;
108 GdkColormap *colormap = 0;
109 GdkPixmap *gdkpixmap = 0;
111 GtkWidget *pixmap = 0;
114 if (!filename || !filename[0])
115 return create_dummy_pixmap (widget);
117 /* We first try any pixmaps directories set by the application. */
118 elem = pixmaps_directories;
121 found_filename = check_file_exists ((gchar*)elem->data, filename);
127 /* If we haven't found the pixmap, try the source directory. */
130 found_filename = check_file_exists ("../utils/images", filename);
135 g_warning (_("Couldn't find pixmap file: %s"), filename);
136 return create_dummy_pixmap (widget);
139 colormap = gtk_widget_get_colormap (widget);
141 # ifndef HAVE_GDK_PIXBUF
143 gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
144 NULL, found_filename);
145 if (gdkpixmap == NULL)
147 g_warning (_("Error loading pixmap file: %s"), found_filename);
148 g_free (found_filename);
149 return create_dummy_pixmap (widget);
152 # else /* HAVE_GDK_PIXBUF */
154 /* jwz -- dumbass Glade1 doesn't emit code that can read PNGs.
157 /* #### Danger: we aren't using `colormap'... */
163 # endif /* HAVE_GTK2 */
165 pb = gdk_pixbuf_new_from_file (found_filename
168 # endif /* HAVE_GTK2 */
175 gdk_pixbuf_render_pixmap_and_mask (pb, &gdkpixmap, &mask, 128);
179 g_warning (_("Error loading pixmap file: %s"), found_filename);
181 if (gerr && gerr->message && *gerr->message)
182 g_warning (_("reason: %s\n"), gerr->message);
183 # endif /* HAVE_GTK2 */
185 return create_dummy_pixmap (widget);
188 # endif /* HAVE_GDK_PIXBUF */
190 g_free (found_filename);
191 pixmap = gtk_pixmap_new (gdkpixmap, mask);
192 gdk_pixmap_unref (gdkpixmap);
193 gdk_bitmap_unref (mask);
198 /* This is an internally used function to check if a pixmap file exists. */
200 check_file_exists (const gchar *directory,
201 const gchar *filename)
203 gchar *full_filename;
207 full_filename = (gchar*) g_malloc (strlen (directory) + 1
208 + strlen (filename) + 1);
209 strcpy (full_filename, directory);
210 strcat (full_filename, G_DIR_SEPARATOR_S);
211 strcat (full_filename, filename);
213 status = stat (full_filename, &s);
214 if (status == 0 && S_ISREG (s.st_mode))
215 return full_filename;
216 g_free (full_filename);