16 |
#include "support.h" |
#include "support.h" |
17 |
|
|
18 |
/* This is an internally used function to check if a pixmap file exists. */ |
/* This is an internally used function to check if a pixmap file exists. */ |
19 |
static gchar *check_file_exists (const gchar * directory, |
static gchar* check_file_exists (const gchar *directory, |
20 |
const gchar * filename); |
const gchar *filename); |
21 |
|
|
22 |
/* This is an internally used function to create pixmaps. */ |
/* This is an internally used function to create pixmaps. */ |
23 |
static GtkWidget *create_dummy_pixmap (GtkWidget * widget); |
static GtkWidget* create_dummy_pixmap (GtkWidget *widget); |
24 |
|
|
25 |
GtkWidget * |
GtkWidget* |
26 |
lookup_widget (GtkWidget * widget, const gchar * widget_name) |
lookup_widget (GtkWidget *widget, |
27 |
|
const gchar *widget_name) |
28 |
{ |
{ |
29 |
GtkWidget *parent, *found_widget; |
GtkWidget *parent, *found_widget; |
30 |
|
|
31 |
for (;;) |
for (;;) |
32 |
{ |
{ |
33 |
if (GTK_IS_MENU (widget)) |
if (GTK_IS_MENU (widget)) |
34 |
parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); |
parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); |
35 |
else |
else |
36 |
parent = widget->parent; |
parent = widget->parent; |
37 |
if (parent == NULL) |
if (parent == NULL) |
38 |
break; |
break; |
39 |
widget = parent; |
widget = parent; |
40 |
} |
} |
41 |
|
|
42 |
found_widget = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (widget), |
found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget), |
43 |
widget_name); |
widget_name); |
44 |
if (!found_widget) |
if (!found_widget) |
45 |
g_warning ("Widget not found: %s", widget_name); |
g_warning ("Widget not found: %s", widget_name); |
46 |
return found_widget; |
return found_widget; |
49 |
/* This is a dummy pixmap we use when a pixmap can't be found. */ |
/* This is a dummy pixmap we use when a pixmap can't be found. */ |
50 |
static char *dummy_pixmap_xpm[] = { |
static char *dummy_pixmap_xpm[] = { |
51 |
/* columns rows colors chars-per-pixel */ |
/* columns rows colors chars-per-pixel */ |
52 |
"1 1 1 1", |
"1 1 1 1", |
53 |
" c None", |
" c None", |
54 |
/* pixels */ |
/* pixels */ |
55 |
" " |
" " |
56 |
}; |
}; |
57 |
|
|
58 |
/* This is an internally used function to create pixmaps. */ |
/* This is an internally used function to create pixmaps. */ |
59 |
static GtkWidget * |
static GtkWidget* |
60 |
create_dummy_pixmap (GtkWidget * widget) |
create_dummy_pixmap (GtkWidget *widget) |
61 |
{ |
{ |
62 |
GdkColormap *colormap; |
GdkColormap *colormap; |
63 |
GdkPixmap *gdkpixmap; |
GdkPixmap *gdkpixmap; |
66 |
|
|
67 |
colormap = gtk_widget_get_colormap (widget); |
colormap = gtk_widget_get_colormap (widget); |
68 |
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask, |
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask, |
69 |
NULL, dummy_pixmap_xpm); |
NULL, dummy_pixmap_xpm); |
70 |
if (gdkpixmap == NULL) |
if (gdkpixmap == NULL) |
71 |
g_error ("Couldn't create replacement pixmap."); |
g_error ("Couldn't create replacement pixmap."); |
72 |
pixmap = gtk_pixmap_new (gdkpixmap, mask); |
pixmap = gtk_pixmap_new (gdkpixmap, mask); |
79 |
|
|
80 |
/* Use this function to set the directory containing installed pixmaps. */ |
/* Use this function to set the directory containing installed pixmaps. */ |
81 |
void |
void |
82 |
add_pixmap_directory (const gchar * directory) |
add_pixmap_directory (const gchar *directory) |
83 |
{ |
{ |
84 |
pixmaps_directories = g_list_prepend (pixmaps_directories, |
pixmaps_directories = g_list_prepend (pixmaps_directories, |
85 |
g_strdup (directory)); |
g_strdup (directory)); |
86 |
} |
} |
87 |
|
|
88 |
/* This is an internally used function to create pixmaps. */ |
/* This is an internally used function to create pixmaps. */ |
89 |
GtkWidget * |
GtkWidget* |
90 |
create_pixmap (GtkWidget * widget, const gchar * filename) |
create_pixmap (GtkWidget *widget, |
91 |
|
const gchar *filename) |
92 |
{ |
{ |
93 |
gchar *found_filename = NULL; |
gchar *found_filename = NULL; |
94 |
GdkColormap *colormap; |
GdkColormap *colormap; |
98 |
GList *elem; |
GList *elem; |
99 |
|
|
100 |
if (!filename || !filename[0]) |
if (!filename || !filename[0]) |
101 |
return create_dummy_pixmap (widget); |
return create_dummy_pixmap (widget); |
102 |
|
|
103 |
/* We first try any pixmaps directories set by the application. */ |
/* We first try any pixmaps directories set by the application. */ |
104 |
elem = pixmaps_directories; |
elem = pixmaps_directories; |
105 |
while (elem) |
while (elem) |
106 |
{ |
{ |
107 |
found_filename = check_file_exists ((gchar *) elem->data, filename); |
found_filename = check_file_exists ((gchar*)elem->data, filename); |
108 |
if (found_filename) |
if (found_filename) |
109 |
break; |
break; |
110 |
elem = elem->next; |
elem = elem->next; |
111 |
} |
} |
112 |
|
|
124 |
|
|
125 |
colormap = gtk_widget_get_colormap (widget); |
colormap = gtk_widget_get_colormap (widget); |
126 |
gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask, |
gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask, |
127 |
NULL, found_filename); |
NULL, found_filename); |
128 |
if (gdkpixmap == NULL) |
if (gdkpixmap == NULL) |
129 |
{ |
{ |
130 |
g_warning (_("Error loading pixmap file: %s"), found_filename); |
g_warning (_("Error loading pixmap file: %s"), found_filename); |
139 |
} |
} |
140 |
|
|
141 |
/* This is an internally used function to check if a pixmap file exists. */ |
/* This is an internally used function to check if a pixmap file exists. */ |
142 |
static gchar * |
static gchar* |
143 |
check_file_exists (const gchar * directory, const gchar * filename) |
check_file_exists (const gchar *directory, |
144 |
|
const gchar *filename) |
145 |
{ |
{ |
146 |
gchar *full_filename; |
gchar *full_filename; |
147 |
struct stat s; |
struct stat s; |
148 |
gint status; |
gint status; |
149 |
|
|
150 |
full_filename = (gchar *) g_malloc (strlen (directory) + 1 |
full_filename = (gchar*) g_malloc (strlen (directory) + 1 |
151 |
+ strlen (filename) + 1); |
+ strlen (filename) + 1); |
152 |
strcpy (full_filename, directory); |
strcpy (full_filename, directory); |
153 |
strcat (full_filename, G_DIR_SEPARATOR_S); |
strcat (full_filename, G_DIR_SEPARATOR_S); |
154 |
strcat (full_filename, filename); |
strcat (full_filename, filename); |
159 |
g_free (full_filename); |
g_free (full_filename); |
160 |
return NULL; |
return NULL; |
161 |
} |
} |
162 |
|
|