cropper

view support.c @ 3:6aaba3a61563

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