comparison Plugins/Input/modplug/gui/support.cpp @ 278:37316876ef6e trunk

[svn] Use modplug instead of mikmod. Supports more formats & compressed files.
author chainsaw
date Sat, 10 Dec 2005 14:31:13 -0800
parents
children
comparison
equal deleted inserted replaced
277:0cf2cc6d0fe5 278:37316876ef6e
1 /*
2 * DO NOT EDIT THIS FILE - it is generated by Glade.
3 */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12 #include <string.h>
13
14 #include <gtk/gtk.h>
15
16 #include "support.h"
17
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);
21
22 /* This is an internally used function to create pixmaps. */
23 static GtkWidget* create_dummy_pixmap (GtkWidget *widget);
24
25 GtkWidget*
26 lookup_widget (GtkWidget *widget,
27 const gchar *widget_name)
28 {
29 GtkWidget *parent, *found_widget;
30
31 for (;;)
32 {
33 if (GTK_IS_MENU (widget))
34 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
35 else
36 parent = widget->parent;
37 if (parent == NULL)
38 break;
39 widget = parent;
40 }
41
42 found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
43 widget_name);
44 if (!found_widget)
45 g_warning ("Widget not found: %s", widget_name);
46 return found_widget;
47 }
48
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 */
52 "1 1 1 1",
53 " c None",
54 /* pixels */
55 " "
56 };
57
58 /* This is an internally used function to create pixmaps. */
59 static GtkWidget*
60 create_dummy_pixmap (GtkWidget *widget)
61 {
62 GdkColormap *colormap;
63 GdkPixmap *gdkpixmap;
64 GdkBitmap *mask;
65 GtkWidget *pixmap;
66
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);
75 return pixmap;
76 }
77
78 static GList *pixmaps_directories = NULL;
79
80 /* Use this function to set the directory containing installed pixmaps. */
81 void
82 add_pixmap_directory (const gchar *directory)
83 {
84 pixmaps_directories = g_list_prepend (pixmaps_directories,
85 g_strdup (directory));
86 }
87
88 /* This is an internally used function to create pixmaps. */
89 GtkWidget*
90 create_pixmap (GtkWidget *widget,
91 const gchar *filename)
92 {
93 gchar *found_filename = NULL;
94 GdkColormap *colormap;
95 GdkPixmap *gdkpixmap;
96 GdkBitmap *mask;
97 GtkWidget *pixmap;
98 GList *elem;
99
100 /* We first try any pixmaps directories set by the application. */
101 elem = pixmaps_directories;
102 while (elem)
103 {
104 found_filename = check_file_exists ((gchar*)elem->data, filename);
105 if (found_filename)
106 break;
107 elem = elem->next;
108 }
109
110 /* If we haven't found the pixmap, try the source directory. */
111 if (!found_filename)
112 {
113 found_filename = check_file_exists ("../pixmaps", filename);
114 }
115
116 if (!found_filename)
117 {
118 g_warning (_("Couldn't find pixmap file: %s"), filename);
119 return create_dummy_pixmap (widget);
120 }
121
122 colormap = gtk_widget_get_colormap (widget);
123 gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
124 NULL, found_filename);
125 if (gdkpixmap == NULL)
126 {
127 g_warning (_("Error loading pixmap file: %s"), found_filename);
128 g_free (found_filename);
129 return create_dummy_pixmap (widget);
130 }
131 g_free (found_filename);
132 pixmap = gtk_pixmap_new (gdkpixmap, mask);
133 gdk_pixmap_unref (gdkpixmap);
134 gdk_bitmap_unref (mask);
135 return pixmap;
136 }
137
138 /* This is an internally used function to check if a pixmap file exists. */
139 gchar*
140 check_file_exists (const gchar *directory,
141 const gchar *filename)
142 {
143 gchar *full_filename;
144 struct stat s;
145 gint status;
146
147 full_filename = (gchar*) g_malloc (strlen (directory) + 1
148 + strlen (filename) + 1);
149 strcpy (full_filename, directory);
150 strcat (full_filename, G_DIR_SEPARATOR_S);
151 strcat (full_filename, filename);
152
153 status = stat (full_filename, &s);
154 if (status == 0 && S_ISREG (s.st_mode))
155 return full_filename;
156 g_free (full_filename);
157 return NULL;
158 }
159