~ubuntu-branches/debian/sid/terminatorx/sid

« back to all changes in this revision

Viewing changes to src/tX_ui_support.cc

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2014-03-10 11:43:09 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140310114309-9xtymsijhfr50yvh
Tags: 3.90-1
* New upstream release.
* Fix debian/watch file.
* Build-depend on gnome-doc-utils.
* Fix dh_install target.
* Remove manual copy of terminatorX-app.xpm, no longer needed.
* Drop 05_endian_h.patch, no longer applicable.
* Drop 16_loose_spelling_fix.patch, fixed upstream.
* Refresh 17_cleanup_desktop_file.patch
* Drop 20_fix_ftbfs_on_kfreebsd.patch, adopted upstream.
* Drop 23_new_zlib.patch, adopted upstream.
* Drop 24-missing_include.patch, applied upstream.
* Refresh 25-libdl_underlinkage.patch.
* Add patch to fix minor spelling mistakes.
* Various small improvements and updates on debian/copyright.
* Bump Standards.

Show diffs side-by-side

added added

removed removed

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