~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to libgd/libgd/gd-toggle-pixbuf-renderer.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-26 00:07:51 UTC
  • mfrom: (1.6.1) (24.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130526000751-kv8ap3x1di4qq8j2
Tags: 3.8.2-0ubuntu1
* Sync with Debian. Remaining changes: 
* debian/control.in:
  - Drop build-depends on libepc-ui-dev and libgrilo-0.2-dev (in universe)
  - Drop libxtst-dev build-depends so that the (redundant) fake key presses
    for inhibiting the screensaver are disabled (LP: #1007438)
  - Build-depend on libzeitgeist-dev
  - Suggest rather than recommend gstreamer components in universe
  - Add totem-plugins-extra
  - Add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - Refer to Firefox in totem-mozilla description instead of Iceweasel
  - Don't have totem-mozilla recommend any particular browser
  - Drop obsolete python library dependencies since iplayer is no longer
    included
* debian/totem-common.install, debian/source_totem.py:
  - Install Ubuntu apport debugging hook
* debian/totem-plugins-extra.install:
  - Universe plugins split out of totem-plugins (currently only gromit)
* debian/totem-plugins.install:    
  - Skip the plugins split to -extra and add the zeitgeist plugin
* debian/rules:
  - Build with --fail-missing, to ensure we install everything. 
    + Ignore libtotem.{,l}a since we delibrately don't install these.
  - Re-enable hardening, make sure both PIE and BINDNOW are used
    by setting hardening=+all. (LP: #1039604)
* debian/patches/91_quicklist_entries.patch:
  - Add static quicklist
* debian/patches/92_gst-plugins-good.patch:
  - Build without unnecessary gstreamer1.0-bad dependency
* debian/patches/93_grilo_optional.patch:
  - Allow building without grilo while grilo MIR is still pending
* debian/patches/correct_desktop_mimetypes.patch:
  - Don't list the mimetypes after the unity lists
* debian/patches/revert_shell_menu.patch: 
  - revert the use of a shell menu until indicator-appmenu can handle
    the mixed shell/traditional menus itself
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2011 Red Hat, Inc.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by 
 
6
 * the Free Software Foundation; either version 2 of the License, or (at your
 
7
 * option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
11
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License 
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 * Author: Cosimo Cecchi <cosimoc@redhat.com>
 
19
 *
 
20
 */
 
21
 
 
22
#include "gd-toggle-pixbuf-renderer.h"
 
23
 
 
24
G_DEFINE_TYPE (GdTogglePixbufRenderer, gd_toggle_pixbuf_renderer, GTK_TYPE_CELL_RENDERER_PIXBUF);
 
25
 
 
26
enum {
 
27
  PROP_ACTIVE = 1,
 
28
  PROP_TOGGLE_VISIBLE,
 
29
  NUM_PROPERTIES
 
30
};
 
31
 
 
32
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 
33
 
 
34
struct _GdTogglePixbufRendererPrivate {
 
35
  gboolean active;
 
36
  gboolean toggle_visible;
 
37
};
 
38
 
 
39
static void
 
40
gd_toggle_pixbuf_renderer_render (GtkCellRenderer      *cell,
 
41
                                  cairo_t              *cr,
 
42
                                  GtkWidget            *widget,
 
43
                                  const GdkRectangle   *background_area,
 
44
                                  const GdkRectangle   *cell_area,
 
45
                                  GtkCellRendererState  flags)
 
46
{
 
47
  gint icon_size = -1;
 
48
  gint check_x, check_y, x_offset, xpad, ypad;
 
49
  GtkStyleContext *context;
 
50
  GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (cell);
 
51
  GtkTextDirection direction;
 
52
 
 
53
  GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->render
 
54
    (cell, cr, widget,
 
55
     background_area, cell_area, flags);
 
56
 
 
57
  if (!self->priv->toggle_visible)
 
58
    return;
 
59
 
 
60
  gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
 
61
  direction = gtk_widget_get_direction (widget);
 
62
  gtk_widget_style_get (widget,
 
63
                        "check-icon-size", &icon_size,
 
64
                        NULL);
 
65
 
 
66
  if (icon_size == -1)
 
67
    icon_size = 40;
 
68
 
 
69
  if (direction == GTK_TEXT_DIR_RTL)
 
70
    x_offset = xpad;
 
71
  else
 
72
    x_offset = cell_area->width - icon_size - xpad;
 
73
 
 
74
  check_x = cell_area->x + x_offset;
 
75
  check_y = cell_area->y + cell_area->height - icon_size - ypad;
 
76
 
 
77
  context = gtk_widget_get_style_context (widget);
 
78
  gtk_style_context_save (context);
 
79
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
 
80
 
 
81
  if (self->priv->active)
 
82
    gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
 
83
 
 
84
  gtk_render_check (context, cr,
 
85
                    check_x, check_y,
 
86
                    icon_size, icon_size);
 
87
 
 
88
  gtk_style_context_restore (context);
 
89
}
 
90
 
 
91
static void
 
92
gd_toggle_pixbuf_renderer_get_size (GtkCellRenderer *cell,
 
93
                                    GtkWidget       *widget,
 
94
                                    const GdkRectangle *cell_area,
 
95
                                    gint *x_offset,
 
96
                                    gint *y_offset,
 
97
                                    gint *width,
 
98
                                    gint *height)
 
99
{
 
100
  gint icon_size;
 
101
 
 
102
  gtk_widget_style_get (widget,
 
103
                        "check-icon-size", &icon_size,
 
104
                        NULL);
 
105
 
 
106
  GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->get_size
 
107
    (cell, widget, cell_area,
 
108
     x_offset, y_offset, width, height);
 
109
 
 
110
  *width += icon_size / 4;
 
111
}
 
112
 
 
113
static void
 
114
gd_toggle_pixbuf_renderer_get_property (GObject    *object,
 
115
                                        guint       property_id,
 
116
                                        GValue     *value,
 
117
                                        GParamSpec *pspec)
 
118
{
 
119
  GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (object);
 
120
 
 
121
  switch (property_id)
 
122
    {
 
123
    case PROP_ACTIVE:
 
124
      g_value_set_boolean (value, self->priv->active);
 
125
      break;
 
126
    case PROP_TOGGLE_VISIBLE:
 
127
      g_value_set_boolean (value, self->priv->toggle_visible);
 
128
      break;
 
129
    default:
 
130
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
131
      break;
 
132
    }
 
133
}
 
134
 
 
135
static void
 
136
gd_toggle_pixbuf_renderer_set_property (GObject    *object,
 
137
                                        guint       property_id,
 
138
                                        const GValue *value,
 
139
                                        GParamSpec *pspec)
 
140
{
 
141
  GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (object);
 
142
 
 
143
  switch (property_id)
 
144
    {
 
145
    case PROP_ACTIVE:
 
146
      self->priv->active = g_value_get_boolean (value);
 
147
      break;
 
148
    case PROP_TOGGLE_VISIBLE:
 
149
      self->priv->toggle_visible = g_value_get_boolean (value);
 
150
      break;
 
151
    default:
 
152
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
153
      break;
 
154
    }
 
155
}
 
156
 
 
157
static void
 
158
gd_toggle_pixbuf_renderer_class_init (GdTogglePixbufRendererClass *klass)
 
159
{
 
160
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
 
161
  GtkCellRendererClass *crclass = GTK_CELL_RENDERER_CLASS (klass);
 
162
 
 
163
  crclass->render = gd_toggle_pixbuf_renderer_render;
 
164
  crclass->get_size = gd_toggle_pixbuf_renderer_get_size;
 
165
  oclass->get_property = gd_toggle_pixbuf_renderer_get_property;
 
166
  oclass->set_property = gd_toggle_pixbuf_renderer_set_property;
 
167
 
 
168
  properties[PROP_ACTIVE] = 
 
169
    g_param_spec_boolean ("active",
 
170
                          "Active",
 
171
                          "Whether the cell renderer is active",
 
172
                          FALSE,
 
173
                          G_PARAM_READWRITE |
 
174
                          G_PARAM_STATIC_STRINGS);
 
175
  properties[PROP_TOGGLE_VISIBLE] =
 
176
    g_param_spec_boolean ("toggle-visible",
 
177
                          "Toggle visible",
 
178
                          "Whether to draw the toggle indicator",
 
179
                          FALSE,
 
180
                          G_PARAM_READWRITE |
 
181
                          G_PARAM_STATIC_STRINGS);
 
182
 
 
183
  g_type_class_add_private (klass, sizeof (GdTogglePixbufRendererPrivate));
 
184
  g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 
185
}
 
186
 
 
187
static void
 
188
gd_toggle_pixbuf_renderer_init (GdTogglePixbufRenderer *self)
 
189
{
 
190
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_TOGGLE_PIXBUF_RENDERER,
 
191
                                            GdTogglePixbufRendererPrivate);
 
192
}
 
193
 
 
194
GtkCellRenderer *
 
195
gd_toggle_pixbuf_renderer_new (void)
 
196
{
 
197
  return g_object_new (GD_TYPE_TOGGLE_PIXBUF_RENDERER, NULL);
 
198
}