2 * DO NOT EDIT THIS FILE - it is generated by Glade.
16 #include "VisSupport.h"
18 /* This is an internally used function to check if a pixmap file exists. */
19 static gchar* check_file_exists (const gchar *directory,
20 const gchar *filename);
22 /* This is an internally used function to create pixmaps. */
23 static GtkWidget* create_dummy_pixmap (GtkWidget *widget);
26 lookup_widget (GtkWidget *widget,
27 const gchar *widget_name)
29 GtkWidget *parent, *found_widget;
33 if (GTK_IS_MENU (widget))
34 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
36 parent = widget->parent;
42 found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
45 g_warning ("Widget not found: %s", widget_name);
49 /* This is a dummy pixmap we use when a pixmap can't be found. */
50 static char *dummy_pixmap_xpm[] = {
51 /* columns rows colors chars-per-pixel */
58 /* This is an internally used function to create pixmaps. */
60 create_dummy_pixmap (GtkWidget *widget)
62 GdkColormap *colormap;
67 colormap = gtk_widget_get_colormap (widget);
68 gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
69 NULL, dummy_pixmap_xpm);
70 if (gdkpixmap == NULL)
71 g_error ("Couldn't create replacement pixmap.");
72 pixmap = gtk_pixmap_new (gdkpixmap, mask);
73 gdk_pixmap_unref (gdkpixmap);
74 gdk_bitmap_unref (mask);
78 static GList *pixmaps_directories = NULL;
80 /* Use this function to set the directory containing installed pixmaps. */
82 add_pixmap_directory (const gchar *directory)
84 pixmaps_directories = g_list_prepend (pixmaps_directories,
85 g_strdup (directory));
88 /* This is an internally used function to create pixmaps. */
90 create_pixmap (GtkWidget *widget,
91 const gchar *filename)
93 gchar *found_filename = NULL;
94 GdkColormap *colormap;
100 if (!filename || !filename[0])
101 return create_dummy_pixmap (widget);
103 /* We first try any pixmaps directories set by the application. */
104 elem = pixmaps_directories;
107 found_filename = check_file_exists ((gchar*)elem->data, filename);
113 /* If we haven't found the pixmap, try the source directory. */
116 found_filename = check_file_exists ("../pixmaps", filename);
121 g_warning ("Couldn't find pixmap file: %s", filename);
122 return create_dummy_pixmap (widget);
125 colormap = gtk_widget_get_colormap (widget);
126 gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
127 NULL, found_filename);
128 if (gdkpixmap == NULL)
130 g_warning ("Error loading pixmap file: %s", found_filename);
131 g_free (found_filename);
132 return create_dummy_pixmap (widget);
134 g_free (found_filename);
135 pixmap = gtk_pixmap_new (gdkpixmap, mask);
136 gdk_pixmap_unref (gdkpixmap);
137 gdk_bitmap_unref (mask);
141 /* This is an internally used function to check if a pixmap file exists. */
143 check_file_exists (const gchar *directory,
144 const gchar *filename)
146 gchar *full_filename;
150 full_filename = (gchar*) g_malloc (strlen (directory) + 1
151 + strlen (filename) + 1);
152 strcpy (full_filename, directory);
153 strcat (full_filename, G_DIR_SEPARATOR_S);
154 strcat (full_filename, filename);
156 status = stat (full_filename, &s);
157 if (status == 0 && S_ISREG (s.st_mode))
158 return full_filename;
159 g_free (full_filename);