Mercurial > cropper
annotate support.c @ 3:6aaba3a61563
added ratio control code
author | meillo@marmaro.de |
---|---|
date | Wed, 05 Dec 2007 00:08:39 +0100 |
parents | e359bea4c8ac |
children | 5e282003f0c1 |
rev | line source |
---|---|
0 | 1 #include <sys/types.h> |
2 #include <sys/stat.h> | |
3 #include <unistd.h> | |
4 #include <string.h> | |
5 #include <stdio.h> | |
6 | |
7 #include <gtk/gtk.h> | |
8 | |
9 #include "support.h" | |
10 | |
1 | 11 |
12 GtkWidget* lookup_widget(GtkWidget* widget, const gchar* widget_name) { | |
13 GtkWidget* parent; | |
14 GtkWidget* found_widget; | |
0 | 15 |
1 | 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 } | |
0 | 30 |
1 | 31 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), widget_name); |
32 if (!found_widget) { | |
0 | 33 g_warning ("Widget not found: %s", widget_name); |
1 | 34 } |
0 | 35 return found_widget; |
36 } | |
37 | |
1 | 38 |
0 | 39 static GList *pixmaps_directories = NULL; |
40 | |
41 /* Use this function to set the directory containing installed pixmaps. */ | |
1 | 42 void add_pixmap_directory(const gchar* directory) { |
43 pixmaps_directories = g_list_prepend (pixmaps_directories, g_strdup (directory)); | |
0 | 44 } |
45 | |
46 /* This is an internally used function to find pixmap files. */ | |
1 | 47 static gchar* find_pixmap_file(const gchar* filename) { |
48 GList* elem; | |
0 | 49 |
50 /* We step through each of the pixmaps directory to find it. */ | |
51 elem = pixmaps_directories; | |
1 | 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 } | |
0 | 60 return NULL; |
61 } | |
62 | |
1 | 63 |
0 | 64 /* This is an internally used function to create pixmaps. */ |
1 | 65 GtkWidget* create_pixmap(GtkWidget* widget, const gchar* filename) { |
66 gchar* pathname = NULL; | |
67 GtkWidget* pixmap; | |
0 | 68 |
1 | 69 if (!filename || !filename[0]) { |
70 return gtk_image_new (); | |
71 } | |
0 | 72 |
73 pathname = find_pixmap_file (filename); | |
74 | |
1 | 75 if (!pathname) { |
76 g_warning ("Couldn't find pixmap file: %s", filename); | |
77 return gtk_image_new (); | |
78 } | |
0 | 79 |
80 pixmap = gtk_image_new_from_file (pathname); | |
1 | 81 g_free(pathname); |
0 | 82 return pixmap; |
83 } | |
84 | |
1 | 85 |
0 | 86 /* This is an internally used function to create pixmaps. */ |
1 | 87 GdkPixbuf* create_pixbuf(const gchar* filename) { |
88 gchar* pathname = NULL; | |
89 GdkPixbuf* pixbuf; | |
90 GError* error = NULL; | |
0 | 91 |
1 | 92 if (!filename || !filename[0]) { |
93 return NULL; | |
94 } | |
0 | 95 |
1 | 96 pathname = find_pixmap_file(filename); |
97 | |
98 if (!pathname) { | |
99 g_warning ("Couldn't find pixmap file: %s", filename); | |
100 return NULL; | |
101 } | |
0 | 102 |
103 pixbuf = gdk_pixbuf_new_from_file (pathname, &error); | |
1 | 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); | |
0 | 109 return pixbuf; |
110 } | |
111 | |
1 | 112 |
0 | 113 /* This is used to set ATK action descriptions. */ |
1 | 114 void glade_set_atk_action_description(AtkAction* action, const gchar* action_name, const gchar* description) { |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
115 gint n_actions; |
1 | 116 gint i; |
0 | 117 |
118 n_actions = atk_action_get_n_actions (action); | |
1 | 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 } | |
0 | 124 } |
125 |