cropper

annotate support.c @ 1:80535e4deaa4

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