~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/gtk2_support.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2004-08-29 10:53:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040829105342-qgmnry37eadfkoxx
Tags: upstream-1.1.3
ImportĀ upstreamĀ versionĀ 1.1.3

Show diffs side-by-side

added added

removed removed

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