00001
00023 #ifdef HAVE_CONFIG_H
00024 # include <config.h>
00025 #endif
00026
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <unistd.h>
00030 #include <string.h>
00031 #include <stdio.h>
00032
00033 #include <gtk/gtk.h>
00034
00035 #include "support.h"
00036
00044 GtkWidget*
00045 lookup_widget
00046 (
00047 GtkWidget *widget,
00048 const gchar *widget_name)
00049 {
00050 GtkWidget *parent, *found_widget;
00051
00052 for (;;)
00053 {
00054 if (GTK_IS_MENU (widget))
00055 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00056 else
00057 parent = widget->parent;
00058 if (!parent)
00059 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
00060 if (parent == NULL)
00061 break;
00062 widget = parent;
00063 }
00064 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
00065 widget_name);
00066 if (!found_widget)
00067 g_warning ("Widget not found: %s", widget_name);
00068 return found_widget;
00069 }
00070
00071
00072 static GList *pixmaps_directories = NULL;
00073
00074
00078 void
00079 add_pixmap_directory (const gchar *directory)
00080 {
00081 pixmaps_directories = g_list_prepend (pixmaps_directories,
00082 g_strdup (directory));
00083 }
00084
00085
00089 static gchar*
00090 find_pixmap_file (const gchar *filename)
00091 {
00092 GList *elem;
00093
00094
00095 elem = pixmaps_directories;
00096 while (elem)
00097 {
00098 gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
00099 G_DIR_SEPARATOR_S, filename);
00100 if (g_file_test (pathname, G_FILE_TEST_EXISTS))
00101 return pathname;
00102 g_free (pathname);
00103 elem = elem->next;
00104 }
00105 return NULL;
00106 }
00107
00108
00112 GtkWidget*
00113 create_pixmap
00114 (
00115 GtkWidget *widget,
00116 const gchar *filename
00117 )
00118 {
00119 gchar *pathname = NULL;
00120 GtkWidget *pixmap;
00121
00122 if (!filename || !filename[0])
00123 return gtk_image_new ();
00124
00125 pathname = find_pixmap_file (filename);
00126
00127 if (!pathname)
00128 {
00129 g_warning (_("Couldn't find pixmap file: %s"), filename);
00130 return gtk_image_new ();
00131 }
00132
00133 pixmap = gtk_image_new_from_file (pathname);
00134 g_free (pathname);
00135 return pixmap;
00136 }
00137
00138
00142 GdkPixbuf*
00143 create_pixbuf (const gchar *filename)
00144 {
00145 gchar *pathname = NULL;
00146 GdkPixbuf *pixbuf;
00147 GError *error = NULL;
00148
00149 if (!filename || !filename[0])
00150 return NULL;
00151
00152 pathname = find_pixmap_file (filename);
00153
00154 if (!pathname)
00155 {
00156 g_warning (_("Couldn't find pixmap file: %s"), filename);
00157 return NULL;
00158 }
00159
00160 pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
00161 if (!pixbuf)
00162 {
00163 fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
00164 pathname, error->message);
00165 g_error_free (error);
00166 }
00167 g_free (pathname);
00168 return pixbuf;
00169 }
00170
00171
00174 void
00175 glade_set_atk_action_description
00176 (
00177 AtkAction *action,
00178 const gchar *action_name,
00179 const gchar *description
00180 )
00181 {
00182 gint n_actions, i;
00183
00184 n_actions = atk_action_get_n_actions (action);
00185 for (i = 0; i < n_actions; i++)
00186 {
00187 if (!strcmp (atk_action_get_name (action, i), action_name))
00188 atk_action_set_description (action, i, description);
00189 }
00190 }
00191
00192
00193