00001
00002
00003
00004
00005 #ifdef HAVE_CONFIG_H
00006 # include <config.h>
00007 #endif
00008
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <unistd.h>
00012 #include <string.h>
00013 #include <stdio.h>
00014
00015 #include <gtk/gtk.h>
00016
00017 #include "support.h"
00018
00019 GtkWidget*
00020 lookup_widget (GtkWidget *widget,
00021 const gchar *widget_name)
00022 {
00023 GtkWidget *parent, *found_widget;
00024
00025 for (;;)
00026 {
00027 if (GTK_IS_MENU (widget))
00028 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00029 else
00030 parent = widget->parent;
00031 if (!parent)
00032 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
00033 if (parent == NULL)
00034 break;
00035 widget = parent;
00036 }
00037
00038 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
00039 widget_name);
00040 if (!found_widget)
00041 g_warning ("Widget not found: %s", widget_name);
00042 return found_widget;
00043 }
00044
00045 static GList *pixmaps_directories = NULL;
00046
00047
00048 void
00049 add_pixmap_directory (const gchar *directory)
00050 {
00051 pixmaps_directories = g_list_prepend (pixmaps_directories,
00052 g_strdup (directory));
00053 }
00054
00055
00056 static gchar*
00057 find_pixmap_file (const gchar *filename)
00058 {
00059 GList *elem;
00060
00061
00062 elem = pixmaps_directories;
00063 while (elem)
00064 {
00065 gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
00066 G_DIR_SEPARATOR_S, filename);
00067 if (g_file_test (pathname, G_FILE_TEST_EXISTS))
00068 return pathname;
00069 g_free (pathname);
00070 elem = elem->next;
00071 }
00072 return NULL;
00073 }
00074
00075
00076 GtkWidget*
00077 create_pixmap (GtkWidget *widget,
00078 const gchar *filename)
00079 {
00080 gchar *pathname = NULL;
00081 GtkWidget *pixmap;
00082
00083 if (!filename || !filename[0])
00084 return gtk_image_new ();
00085
00086 pathname = find_pixmap_file (filename);
00087
00088 if (!pathname)
00089 {
00090 g_warning (_("Couldn't find pixmap file: %s"), filename);
00091 return gtk_image_new ();
00092 }
00093
00094 pixmap = gtk_image_new_from_file (pathname);
00095 g_free (pathname);
00096 return pixmap;
00097 }
00098
00099
00100 GdkPixbuf*
00101 create_pixbuf (const gchar *filename)
00102 {
00103 gchar *pathname = NULL;
00104 GdkPixbuf *pixbuf;
00105 GError *error = NULL;
00106
00107 if (!filename || !filename[0])
00108 return NULL;
00109
00110 pathname = find_pixmap_file (filename);
00111
00112 if (!pathname)
00113 {
00114 g_warning (_("Couldn't find pixmap file: %s"), filename);
00115 return NULL;
00116 }
00117
00118 pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
00119 if (!pixbuf)
00120 {
00121 fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
00122 pathname, error->message);
00123 g_error_free (error);
00124 }
00125 g_free (pathname);
00126 return pixbuf;
00127 }
00128
00129
00130 void
00131 glade_set_atk_action_description (AtkAction *action,
00132 const gchar *action_name,
00133 const gchar *description)
00134 {
00135 gint n_actions, i;
00136
00137 n_actions = atk_action_get_n_actions (action);
00138 for (i = 0; i < n_actions; i++)
00139 {
00140 if (!strcmp (atk_action_get_name (action, i), action_name))
00141 atk_action_set_description (action, i, description);
00142 }
00143 }
00144