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