xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/gtk/support.c (revision 2d5f7628c5531eb583b9313ac2fd1cf8582b4479)
1 
2 /*
3  * Licensed Materials - Property of IBM
4  *
5  * trousers - An open source TCG Software Stack
6  *
7  * (C) Copyright International Business Machines Corp. 2004
8  *
9  */
10 
11 /*
12  * DO NOT EDIT THIS FILE - it is generated by Glade.
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #  include <config.h>
17 #endif
18 
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdio.h>
24 
25 #include <gtk/gtk.h>
26 
27 #include "trousers/tss.h"
28 #include "tsplog.h"
29 
30 #include "support.h"
31 
32 GtkWidget*
lookup_widget(GtkWidget * widget,const gchar * widget_name)33 lookup_widget                          (GtkWidget       *widget,
34                                         const gchar     *widget_name)
35 {
36   GtkWidget *parent, *found_widget;
37 
38   for (;;)
39     {
40       if (GTK_IS_MENU (widget))
41         parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
42       else
43         parent = widget->parent;
44       if (!parent)
45         parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
46       if (parent == NULL)
47         break;
48       widget = parent;
49     }
50 
51   found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
52                                                  widget_name);
53   if (!found_widget)
54     g_warning ("Widget not found: %s", widget_name);
55   return found_widget;
56 }
57 
58 static GList *pixmaps_directories = NULL;
59 
60 /* Use this function to set the directory containing installed pixmaps. */
61 void
__tspi_add_pixmap_directory(const gchar * directory)62 __tspi_add_pixmap_directory                   (const gchar     *directory)
63 {
64   pixmaps_directories = g_list_prepend (pixmaps_directories,
65                                         g_strdup (directory));
66 }
67 
68 /* This is an internally used function to find pixmap files. */
69 static gchar*
find_pixmap_file(const gchar * filename)70 find_pixmap_file                       (const gchar     *filename)
71 {
72   GList *elem;
73 
74   /* We step through each of the pixmaps directory to find it. */
75   elem = pixmaps_directories;
76   while (elem)
77     {
78       gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
79                                          G_DIR_SEPARATOR_S, filename);
80       if (g_file_test (pathname, G_FILE_TEST_EXISTS))
81         return pathname;
82       g_free (pathname);
83       elem = elem->next;
84     }
85   return NULL;
86 }
87 
88 /* This is an internally used function to create pixmaps. */
89 GtkWidget*
create_pixmap(GtkWidget * widget,const gchar * filename)90 create_pixmap                          (GtkWidget       *widget,
91                                         const gchar     *filename)
92 {
93   gchar *pathname = NULL;
94   GtkWidget *pixmap;
95 
96   if (!filename || !filename[0])
97       return gtk_image_new ();
98 
99   pathname = find_pixmap_file (filename);
100 
101   if (!pathname)
102     {
103       g_warning (_("Couldn't find pixmap file: %s"), filename);
104       return gtk_image_new ();
105     }
106 
107   pixmap = gtk_image_new_from_file (pathname);
108   g_free (pathname);
109   return pixmap;
110 }
111 
112 /* This is an internally used function to create pixmaps. */
113 GdkPixbuf*
create_pixbuf(const gchar * filename)114 create_pixbuf                          (const gchar     *filename)
115 {
116   gchar *pathname = NULL;
117   GdkPixbuf *pixbuf;
118   GError *error = NULL;
119 
120   if (!filename || !filename[0])
121       return NULL;
122 
123   pathname = find_pixmap_file (filename);
124 
125   if (!pathname)
126     {
127       g_warning (_("Couldn't find pixmap file: %s"), filename);
128       return NULL;
129     }
130 
131   pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
132   if (!pixbuf)
133     {
134       LogError ("Failed to load pixbuf file: %s: %s\n",
135                pathname, error->message);
136       g_error_free (error);
137     }
138   g_free (pathname);
139   return pixbuf;
140 }
141 
142 /* This is used to set ATK action descriptions. */
143 void
glade_set_atk_action_description(AtkAction * action,const gchar * action_name,const gchar * description)144 glade_set_atk_action_description       (AtkAction       *action,
145                                         const gchar     *action_name,
146                                         const gchar     *description)
147 {
148   gint n_actions, i;
149 
150   n_actions = atk_action_get_n_actions (action);
151   for (i = 0; i < n_actions; i++)
152     {
153       if (!strcmp (atk_action_get_name (action, i), action_name))
154         atk_action_set_description (action, i, description);
155     }
156 }
157 
158