comparison support.c @ 11:c18ba4ea1514

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