meillo@0: #include meillo@0: #include meillo@0: #include meillo@0: #include meillo@0: #include meillo@0: meillo@0: #include meillo@0: meillo@0: #include "support.h" meillo@0: meillo@0: meillo@1: GtkWidget* lookup_widget(GtkWidget* widget, const gchar* widget_name) { meillo@1: GtkWidget* parent; meillo@1: GtkWidget* found_widget; meillo@0: meillo@1: for (;;) { meillo@1: if (GTK_IS_MENU (widget)) { meillo@1: parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); meillo@1: } else { meillo@1: parent = widget->parent; meillo@1: } meillo@1: if (!parent) { meillo@1: parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey"); meillo@1: } meillo@1: if (parent == NULL) { meillo@1: break; meillo@1: } meillo@1: widget = parent; meillo@1: } meillo@1: meillo@1: found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), widget_name); meillo@1: if (!found_widget) { meillo@0: g_warning ("Widget not found: %s", widget_name); meillo@1: } meillo@0: return found_widget; meillo@0: } meillo@0: meillo@1: meillo@0: static GList *pixmaps_directories = NULL; meillo@0: meillo@0: /* Use this function to set the directory containing installed pixmaps. */ meillo@1: void add_pixmap_directory(const gchar* directory) { meillo@1: pixmaps_directories = g_list_prepend (pixmaps_directories, g_strdup (directory)); meillo@0: } meillo@0: meillo@0: /* This is an internally used function to find pixmap files. */ meillo@1: static gchar* find_pixmap_file(const gchar* filename) { meillo@1: GList* elem; meillo@0: meillo@0: /* We step through each of the pixmaps directory to find it. */ meillo@0: elem = pixmaps_directories; meillo@1: while (elem) { meillo@1: gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, G_DIR_SEPARATOR_S, filename); meillo@1: if (g_file_test (pathname, G_FILE_TEST_EXISTS)) { meillo@1: return pathname; meillo@1: } meillo@1: g_free (pathname); meillo@1: elem = elem->next; meillo@1: } meillo@0: return NULL; meillo@0: } meillo@0: meillo@1: meillo@0: /* This is an internally used function to create pixmaps. */ meillo@1: GtkWidget* create_pixmap(GtkWidget* widget, const gchar* filename) { meillo@1: gchar* pathname = NULL; meillo@1: GtkWidget* pixmap; meillo@0: meillo@1: if (!filename || !filename[0]) { meillo@1: return gtk_image_new (); meillo@1: } meillo@0: meillo@0: pathname = find_pixmap_file (filename); meillo@0: meillo@1: if (!pathname) { meillo@1: g_warning ("Couldn't find pixmap file: %s", filename); meillo@1: return gtk_image_new (); meillo@1: } meillo@0: meillo@0: pixmap = gtk_image_new_from_file (pathname); meillo@1: g_free(pathname); meillo@0: return pixmap; meillo@0: } meillo@0: meillo@1: meillo@0: /* This is an internally used function to create pixmaps. */ meillo@1: GdkPixbuf* create_pixbuf(const gchar* filename) { meillo@1: gchar* pathname = NULL; meillo@1: GdkPixbuf* pixbuf; meillo@1: GError* error = NULL; meillo@0: meillo@1: if (!filename || !filename[0]) { meillo@1: return NULL; meillo@1: } meillo@0: meillo@1: pathname = find_pixmap_file(filename); meillo@0: meillo@1: if (!pathname) { meillo@1: g_warning ("Couldn't find pixmap file: %s", filename); meillo@1: return NULL; meillo@1: } meillo@0: meillo@0: pixbuf = gdk_pixbuf_new_from_file (pathname, &error); meillo@1: if (!pixbuf) { meillo@1: fprintf(stderr, "Failed to load pixbuf file: %s: %s\n", pathname, error->message); meillo@1: g_error_free(error); meillo@1: } meillo@1: g_free(pathname); meillo@0: return pixbuf; meillo@0: } meillo@0: meillo@1: meillo@0: /* This is used to set ATK action descriptions. */ meillo@1: void glade_set_atk_action_description(AtkAction* action, const gchar* action_name, const gchar* description) { meillo@1: gint n_actions meillo@1: gint i; meillo@0: meillo@0: n_actions = atk_action_get_n_actions (action); meillo@1: for (i = 0; i < n_actions; i++) { meillo@1: if (!strcmp (atk_action_get_name (action, i), action_name)) { meillo@1: atk_action_set_description (action, i, description); meillo@1: } meillo@1: } meillo@0: } meillo@0: