cropper

annotate support.c @ 0:ca9155129253

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