cropper

annotate support.c @ 11:c18ba4ea1514

just cosmetic changes
author meillo@marmaro.de
date Thu, 04 Mar 2010 14:18:19 +0100
parents 5e282003f0c1
children
rev   line source
meillo@0 1 #include <sys/types.h>
meillo@0 2 #include <sys/stat.h>
meillo@0 3 #include <unistd.h>
meillo@0 4 #include <string.h>
meillo@0 5 #include <stdio.h>
meillo@0 6 #include <gtk/gtk.h>
meillo@0 7 #include "support.h"
meillo@0 8
meillo@11 9 static GList *pixmaps_directories = NULL;
meillo@0 10
meillo@11 11
meillo@11 12 GtkWidget*
meillo@11 13 lookup_widget(GtkWidget* widget, const gchar* widget_name)
meillo@11 14 {
meillo@10 15 GtkWidget* parent;
meillo@1 16 GtkWidget* found_widget;
meillo@0 17
meillo@10 18 for (;;) {
meillo@11 19 if (GTK_IS_MENU(widget)) {
meillo@11 20 parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
meillo@1 21 } else {
meillo@1 22 parent = widget->parent;
meillo@1 23 }
meillo@1 24 if (!parent) {
meillo@11 25 parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
meillo@1 26 }
meillo@1 27 if (parent == NULL) {
meillo@1 28 break;
meillo@1 29 }
meillo@1 30 widget = parent;
meillo@1 31 }
meillo@1 32
meillo@11 33 found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
meillo@10 34 if (!found_widget) {
meillo@11 35 g_warning("Widget not found: %s", widget_name);
meillo@1 36 }
meillo@10 37 return found_widget;
meillo@0 38 }
meillo@0 39
meillo@1 40
meillo@0 41 /* Use this function to set the directory containing installed pixmaps. */
meillo@11 42 void
meillo@11 43 add_pixmap_directory(const gchar* directory)
meillo@11 44 {
meillo@11 45 pixmaps_directories = g_list_prepend(pixmaps_directories, g_strdup(directory));
meillo@0 46 }
meillo@0 47
meillo@11 48
meillo@0 49 /* This is an internally used function to find pixmap files. */
meillo@11 50 static gchar*
meillo@11 51 find_pixmap_file(const gchar* filename)
meillo@11 52 {
meillo@10 53 GList* elem;
meillo@0 54
meillo@10 55 /* We step through each of the pixmaps directory to find it. */
meillo@10 56 elem = pixmaps_directories;
meillo@10 57 while (elem) {
meillo@11 58 gchar *pathname = g_strdup_printf("%s%s%s", (gchar*)elem->data, G_DIR_SEPARATOR_S, filename);
meillo@11 59 if (g_file_test(pathname, G_FILE_TEST_EXISTS)) {
meillo@1 60 return pathname;
meillo@1 61 }
meillo@11 62 g_free(pathname);
meillo@1 63 elem = elem->next;
meillo@1 64 }
meillo@10 65 return NULL;
meillo@0 66 }
meillo@0 67
meillo@1 68
meillo@0 69 /* This is an internally used function to create pixmaps. */
meillo@11 70 GtkWidget*
meillo@11 71 create_pixmap(GtkWidget* widget, const gchar* filename)
meillo@11 72 {
meillo@10 73 gchar* pathname = NULL;
meillo@10 74 GtkWidget* pixmap;
meillo@0 75
meillo@10 76 if (!filename || !filename[0]) {
meillo@11 77 return gtk_image_new();
meillo@1 78 }
meillo@0 79
meillo@11 80 pathname = find_pixmap_file(filename);
meillo@0 81
meillo@10 82 if (!pathname) {
meillo@11 83 g_warning("Couldn't find pixmap file: %s", filename);
meillo@11 84 return gtk_image_new();
meillo@1 85 }
meillo@0 86
meillo@11 87 pixmap = gtk_image_new_from_file(pathname);
meillo@10 88 g_free(pathname);
meillo@10 89 return pixmap;
meillo@0 90 }
meillo@0 91
meillo@1 92
meillo@0 93 /* This is an internally used function to create pixmaps. */
meillo@11 94 GdkPixbuf*
meillo@11 95 create_pixbuf(const gchar* filename)
meillo@11 96 {
meillo@10 97 gchar* pathname = NULL;
meillo@10 98 GdkPixbuf* pixbuf;
meillo@10 99 GError* error = NULL;
meillo@0 100
meillo@10 101 if (!filename || !filename[0]) {
meillo@1 102 return NULL;
meillo@1 103 }
meillo@0 104
meillo@10 105 pathname = find_pixmap_file(filename);
meillo@0 106
meillo@10 107 if (!pathname) {
meillo@11 108 g_warning("Couldn't find pixmap file: %s", filename);
meillo@1 109 return NULL;
meillo@1 110 }
meillo@0 111
meillo@11 112 pixbuf = gdk_pixbuf_new_from_file(pathname, &error);
meillo@10 113 if (!pixbuf) {
meillo@1 114 fprintf(stderr, "Failed to load pixbuf file: %s: %s\n", pathname, error->message);
meillo@1 115 g_error_free(error);
meillo@1 116 }
meillo@10 117 g_free(pathname);
meillo@10 118 return pixbuf;
meillo@0 119 }
meillo@0 120
meillo@1 121
meillo@0 122 /* This is used to set ATK action descriptions. */
meillo@11 123 void
meillo@11 124 glade_set_atk_action_description(AtkAction* action, const gchar* action_name, const gchar* description)
meillo@11 125 {
meillo@10 126 gint n_actions;
meillo@1 127 gint i;
meillo@0 128
meillo@11 129 n_actions = atk_action_get_n_actions(action);
meillo@10 130 for (i = 0; i < n_actions; i++) {
meillo@11 131 if (!strcmp(atk_action_get_name(action, i), action_name)) {
meillo@11 132 atk_action_set_description(action, i, description);
meillo@1 133 }
meillo@1 134 }
meillo@0 135 }