e076699e |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 XangXiu Yang |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
561eba2a |
19 | /* |
20 | * DO NOT EDIT THIS FILE - it is generated by Glade. |
21 | */ |
22 | |
23 | #ifdef HAVE_CONFIG_H |
24 | # include <config.h> |
25 | #endif |
26 | |
27 | #include <sys/types.h> |
28 | #include <sys/stat.h> |
29 | #include <unistd.h> |
30 | #include <string.h> |
31 | #include <stdio.h> |
32 | |
33 | #include <gtk/gtk.h> |
34 | |
35 | #include "support.h" |
36 | |
37 | GtkWidget* |
38 | lookup_widget (GtkWidget *widget, |
39 | const gchar *widget_name) |
40 | { |
41 | GtkWidget *parent, *found_widget; |
42 | |
43 | for (;;) |
44 | { |
45 | if (GTK_IS_MENU (widget)) |
46 | parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); |
47 | else |
48 | parent = widget->parent; |
49 | if (!parent) |
50 | parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey"); |
51 | if (parent == NULL) |
52 | break; |
53 | widget = parent; |
54 | } |
55 | |
56 | found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), |
57 | widget_name); |
58 | if (!found_widget) |
59 | g_warning ("Widget not found: %s", widget_name); |
60 | return found_widget; |
61 | } |
62 | |
63 | static GList *pixmaps_directories = NULL; |
64 | |
65 | /* Use this function to set the directory containing installed pixmaps. */ |
66 | void |
67 | add_pixmap_directory (const gchar *directory) |
68 | { |
69 | pixmaps_directories = g_list_prepend (pixmaps_directories, |
70 | g_strdup (directory)); |
71 | } |
72 | |
73 | /* This is an internally used function to find pixmap files. */ |
74 | static gchar* |
75 | find_pixmap_file (const gchar *filename) |
76 | { |
77 | GList *elem; |
78 | |
79 | /* We step through each of the pixmaps directory to find it. */ |
80 | elem = pixmaps_directories; |
81 | while (elem) |
82 | { |
83 | gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, |
84 | G_DIR_SEPARATOR_S, filename); |
85 | if (g_file_test (pathname, G_FILE_TEST_EXISTS)) |
86 | return pathname; |
87 | g_free (pathname); |
88 | elem = elem->next; |
89 | } |
90 | return NULL; |
91 | } |
92 | |
93 | /* This is an internally used function to create pixmaps. */ |
94 | GtkWidget* |
95 | create_pixmap (GtkWidget *widget, |
96 | const gchar *filename) |
97 | { |
98 | gchar *pathname = NULL; |
99 | GtkWidget *pixmap; |
100 | |
101 | if (!filename || !filename[0]) |
102 | return gtk_image_new (); |
103 | |
104 | pathname = find_pixmap_file (filename); |
105 | |
106 | if (!pathname) |
107 | { |
d4ae0591 |
108 | g_warning ("Couldn't find pixmap file: %s", filename); |
561eba2a |
109 | return gtk_image_new (); |
110 | } |
111 | |
112 | pixmap = gtk_image_new_from_file (pathname); |
113 | g_free (pathname); |
114 | return pixmap; |
115 | } |
116 | |
117 | /* This is an internally used function to create pixmaps. */ |
118 | GdkPixbuf* |
119 | create_pixbuf (const gchar *filename) |
120 | { |
121 | gchar *pathname = NULL; |
122 | GdkPixbuf *pixbuf; |
123 | GError *error = NULL; |
124 | |
125 | if (!filename || !filename[0]) |
126 | return NULL; |
127 | |
128 | pathname = find_pixmap_file (filename); |
129 | |
130 | if (!pathname) |
131 | { |
d4ae0591 |
132 | g_warning ("Couldn't find pixmap file: %s", filename); |
561eba2a |
133 | return NULL; |
134 | } |
135 | |
136 | pixbuf = gdk_pixbuf_new_from_file (pathname, &error); |
137 | if (!pixbuf) |
138 | { |
139 | fprintf (stderr, "Failed to load pixbuf file: %s: %s\n", |
140 | pathname, error->message); |
141 | g_error_free (error); |
142 | } |
143 | g_free (pathname); |
144 | return pixbuf; |
145 | } |
146 | |
147 | /* This is used to set ATK action descriptions. */ |
148 | void |
149 | glade_set_atk_action_description (AtkAction *action, |
150 | const gchar *action_name, |
151 | const gchar *description) |
152 | { |
153 | gint n_actions, i; |
154 | |
155 | n_actions = atk_action_get_n_actions (action); |
156 | for (i = 0; i < n_actions; i++) |
157 | { |
158 | if (!strcmp (atk_action_get_name (action, i), action_name)) |
159 | atk_action_set_description (action, i, description); |
160 | } |
161 | } |
162 | |