~strycore/ubuntu/vivid/gnome-weather/fix-for-1456400

« back to all changes in this revision

Viewing changes to libgd/libgd/gd-styled-text-renderer.c

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-12-20 18:32:08 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141220183208-e2895ntfyv23x1m3
Tags: 3.14.1-0ubuntu1
* New upstream release.
* Fix a typo in watch file
* Change binary to arch: all
* Update d/copyright for this 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-styled-text-renderer.h"
23
 
 
24
 
G_DEFINE_TYPE (GdStyledTextRenderer, gd_styled_text_renderer, GTK_TYPE_CELL_RENDERER_TEXT);
25
 
 
26
 
struct _GdStyledTextRendererPrivate {
27
 
  GList *style_classes;
28
 
};
29
 
 
30
 
static void
31
 
gd_styled_text_renderer_render (GtkCellRenderer      *cell,
32
 
                                cairo_t              *cr,
33
 
                                GtkWidget            *widget,
34
 
                                const GdkRectangle   *background_area,
35
 
                                const GdkRectangle   *cell_area,
36
 
                                GtkCellRendererState  flags)
37
 
{
38
 
  GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (cell);
39
 
  GtkStyleContext *context;
40
 
  const gchar *style_class;
41
 
  GList *l;
42
 
 
43
 
  context = gtk_widget_get_style_context (widget);
44
 
  gtk_style_context_save (context);
45
 
 
46
 
  for (l = self->priv->style_classes; l != NULL; l = l->next)
47
 
    {
48
 
      style_class = l->data;
49
 
      gtk_style_context_add_class (context, style_class);
50
 
    }
51
 
 
52
 
  GTK_CELL_RENDERER_CLASS (gd_styled_text_renderer_parent_class)->render 
53
 
    (cell, cr, widget,
54
 
     background_area, cell_area, flags);
55
 
 
56
 
  gtk_style_context_restore (context);
57
 
}
58
 
 
59
 
static void
60
 
gd_styled_text_renderer_finalize (GObject *obj)
61
 
{
62
 
  GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (obj);
63
 
 
64
 
  if (self->priv->style_classes != NULL)
65
 
    {
66
 
      g_list_free_full (self->priv->style_classes, g_free);
67
 
      self->priv->style_classes = NULL;
68
 
    }
69
 
 
70
 
  G_OBJECT_CLASS (gd_styled_text_renderer_parent_class)->finalize (obj);
71
 
}
72
 
 
73
 
static void
74
 
gd_styled_text_renderer_class_init (GdStyledTextRendererClass *klass)
75
 
{
76
 
  GtkCellRendererClass *crclass = GTK_CELL_RENDERER_CLASS (klass);
77
 
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
78
 
 
79
 
  oclass->finalize = gd_styled_text_renderer_finalize;
80
 
  crclass->render = gd_styled_text_renderer_render;
81
 
 
82
 
  g_type_class_add_private (klass, sizeof (GdStyledTextRendererPrivate));
83
 
}
84
 
 
85
 
static void
86
 
gd_styled_text_renderer_init (GdStyledTextRenderer *self)
87
 
{
88
 
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_STYLED_TEXT_RENDERER,
89
 
                                            GdStyledTextRendererPrivate);
90
 
}
91
 
 
92
 
GtkCellRenderer *
93
 
gd_styled_text_renderer_new (void)
94
 
{
95
 
  return g_object_new (GD_TYPE_STYLED_TEXT_RENDERER,
96
 
                       NULL);
97
 
}
98
 
 
99
 
void
100
 
gd_styled_text_renderer_add_class (GdStyledTextRenderer *self,
101
 
                                   const gchar *class)
102
 
{
103
 
  if (g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0))
104
 
    return;
105
 
 
106
 
  self->priv->style_classes = g_list_append (self->priv->style_classes, g_strdup (class));
107
 
}
108
 
 
109
 
void
110
 
gd_styled_text_renderer_remove_class (GdStyledTextRenderer *self,
111
 
                                      const gchar *class)
112
 
{
113
 
  GList *class_element;
114
 
 
115
 
  class_element = g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0);
116
 
 
117
 
  if (class_element == NULL)
118
 
    return;
119
 
 
120
 
  self->priv->style_classes = g_list_remove_link (self->priv->style_classes,
121
 
                                                  class_element);
122
 
  g_free (class_element->data);
123
 
  g_list_free_1 (class_element);
124
 
}