cropper

view support.c @ 11:c18ba4ea1514

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