summaryrefslogtreecommitdiffstats
path: root/panels/color/cc-color-cell-renderer-text.c
blob: 5803ac548d048fa6ec03fd6cf126f336ad3f4806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 *
 * Copyright (C) 2012 Richard Hughes <richard@hughsie.com>
 *
 * Licensed under the GNU General Public License Version 2
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <gtk/gtk.h>

#include "cc-color-cell-renderer-text.h"

enum {
  PROP_0,
  PROP_IS_DIM_LABEL,
  PROP_LAST
};

struct _CcColorCellRendererText
{
  GtkCellRendererText  parent_instance;

  gboolean             is_dim_label;
};

G_DEFINE_TYPE (CcColorCellRendererText, cc_color_cell_renderer_text, GTK_TYPE_CELL_RENDERER_TEXT)

static gpointer parent_class = NULL;

static void
cc_color_cell_renderer_text_get_property (GObject *object, guint param_id,
                                          GValue *value, GParamSpec *pspec)
{
  CcColorCellRendererText *renderer = CC_COLOR_CELL_RENDERER_TEXT (object);

  switch (param_id)
    {
      case PROP_IS_DIM_LABEL:
        g_value_set_boolean (value, renderer->is_dim_label);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }
}

static void
cc_color_cell_renderer_text_set_property (GObject *object, guint param_id,
                                          const GValue *value, GParamSpec *pspec)
{
  CcColorCellRendererText *renderer = CC_COLOR_CELL_RENDERER_TEXT (object);

  switch (param_id)
    {
      case PROP_IS_DIM_LABEL:
        renderer->is_dim_label = g_value_get_boolean (value);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }
}

static void
cc_color_cell_renderer_snapshot (GtkCellRenderer      *cell,
                                 GtkSnapshot          *snapshot,
                                 GtkWidget            *widget,
                                 const GdkRectangle   *background_area,
                                 const GdkRectangle   *cell_area,
                                 GtkCellRendererState  flags)
{
  CcColorCellRendererText *renderer;
  GtkStyleContext *context;

  renderer = CC_COLOR_CELL_RENDERER_TEXT (cell);
  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save (context);
  if (renderer->is_dim_label)
    gtk_style_context_add_class (context, "dim-label");
  else
    gtk_style_context_remove_class (context, "dim-label");
  GTK_CELL_RENDERER_CLASS (parent_class)->snapshot (cell, snapshot, widget,
                                                    background_area,
                                                    cell_area, flags);
  gtk_style_context_restore (context);
}

static void
cc_color_cell_renderer_text_class_init (CcColorCellRendererTextClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GtkCellRendererClass *object_class_gcr = GTK_CELL_RENDERER_CLASS (class);
  object_class_gcr->snapshot = cc_color_cell_renderer_snapshot;

  parent_class = g_type_class_peek_parent (class);

  object_class->get_property = cc_color_cell_renderer_text_get_property;
  object_class->set_property = cc_color_cell_renderer_text_set_property;

  g_object_class_install_property (object_class, PROP_IS_DIM_LABEL,
                                   g_param_spec_boolean ("is-dim-label",
                                                         NULL, NULL,
                                                         FALSE,
                                                         G_PARAM_READWRITE));
}

static void
cc_color_cell_renderer_text_init (CcColorCellRendererText *renderer)
{
  renderer->is_dim_label = FALSE;
}

GtkCellRenderer *
cc_color_cell_renderer_text_new (void)
{
  return g_object_new (CC_COLOR_TYPE_CELL_RENDERER_TEXT, NULL);
}