bugrepair: drag and drop
[gpiv.git] / src / support.c
blobcd39970710bcb88a5266ef37ff5326fd2e762e5b
1 /*----------------------------------------------------------------------
3 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
4 libraries.
6 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
7 Gerber van der Graaf
9 This file is part of gpiv.
11 Gpiv is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
14 any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation,
23 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ----------------------------------------------------------------------*/
28 * $Log: support.c,v $
29 * Revision 1.3 2007-06-06 17:00:48 gerber
30 * Retreives images/data from URI using Gnome Virtual File System.
32 * Revision 1.2 2006/01/31 14:28:13 gerber
33 * version 0.3.0
35 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
36 * Imported gpiv
40 #ifdef HAVE_CONFIG_H
41 # include <config.h>
42 #endif
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <stdio.h>
50 #include <gnome.h>
52 #include "support.h"
53 #include "gpiv_gui.h"
55 GtkWidget*
56 lookup_widget (GtkWidget *widget,
57 const gchar *widget_name)
59 GtkWidget *parent, *found_widget;
61 for (;;)
63 if (GTK_IS_MENU (widget))
64 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
65 else
66 parent = widget->parent;
67 if (!parent)
68 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
69 if (parent == NULL)
70 break;
71 widget = parent;
74 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
75 widget_name);
76 if (!found_widget)
77 g_warning ("Widget not found: %s", widget_name);
78 return found_widget;
81 /* This is an internally used function to create pixmaps. */
82 GtkWidget*
83 create_pixmap (GtkWidget *widget,
84 const gchar *filename)
86 GtkWidget *pixmap;
87 gchar *pathname;
89 if (!filename || !filename[0])
90 return gtk_image_new ();
92 pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
93 filename, TRUE, NULL);
94 if (!pathname)
96 g_warning (_("Couldn't find pixmap file: %s"), filename);
97 return gtk_image_new ();
100 pixmap = gtk_image_new_from_file (pathname);
101 g_free (pathname);
102 return pixmap;
105 /* This is an internally used function to create pixmaps. */
106 GdkPixbuf*
107 create_pixbuf (const gchar *filename)
109 gchar *pathname = NULL;
110 GdkPixbuf *pixbuf;
111 GError *error = NULL;
113 if (!filename || !filename[0])
114 return NULL;
116 pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
117 filename, TRUE, NULL);
119 if (!pathname)
121 g_warning (_("Couldn't find pixmap file: %s"), filename);
122 return NULL;
125 pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
126 if (!pixbuf)
128 fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
129 pathname, error->message);
130 g_error_free (error);
132 g_free (pathname);
133 return pixbuf;
136 /* This is used to set ATK action descriptions. */
137 void
138 glade_set_atk_action_description (AtkAction *action,
139 const gchar *action_name,
140 const gchar *description)
142 gint n_actions, i;
144 n_actions = atk_action_get_n_actions (action);
145 for (i = 0; i < n_actions; i++)
147 if (!strcmp (atk_action_get_name (action, i), action_name))
148 atk_action_set_description (action, i, description);