Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2012 Richard Hughes <richard@hughsie.com> |
4 |
|
|
* |
5 |
|
|
* Licensed under the GNU General Public License Version 2 |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "config.h" |
23 |
|
|
|
24 |
|
|
#include <gtk/gtk.h> |
25 |
|
|
|
26 |
|
|
#include "cc-color-cell-renderer-text.h" |
27 |
|
|
|
28 |
|
|
enum { |
29 |
|
|
PROP_0, |
30 |
|
|
PROP_IS_DIM_LABEL, |
31 |
|
|
PROP_LAST |
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
struct _CcColorCellRendererText |
35 |
|
|
{ |
36 |
|
|
GtkCellRendererText parent_instance; |
37 |
|
|
|
38 |
|
|
gboolean is_dim_label; |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
✗ |
G_DEFINE_TYPE (CcColorCellRendererText, cc_color_cell_renderer_text, GTK_TYPE_CELL_RENDERER_TEXT) |
42 |
|
|
|
43 |
|
|
static gpointer parent_class = NULL; |
44 |
|
|
|
45 |
|
|
static void |
46 |
|
✗ |
cc_color_cell_renderer_text_get_property (GObject *object, guint param_id, |
47 |
|
|
GValue *value, GParamSpec *pspec) |
48 |
|
|
{ |
49 |
|
✗ |
CcColorCellRendererText *renderer = CC_COLOR_CELL_RENDERER_TEXT (object); |
50 |
|
|
|
51 |
|
✗ |
switch (param_id) |
52 |
|
|
{ |
53 |
|
✗ |
case PROP_IS_DIM_LABEL: |
54 |
|
✗ |
g_value_set_boolean (value, renderer->is_dim_label); |
55 |
|
✗ |
break; |
56 |
|
✗ |
default: |
57 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
58 |
|
✗ |
break; |
59 |
|
|
} |
60 |
|
✗ |
} |
61 |
|
|
|
62 |
|
|
static void |
63 |
|
✗ |
cc_color_cell_renderer_text_set_property (GObject *object, guint param_id, |
64 |
|
|
const GValue *value, GParamSpec *pspec) |
65 |
|
|
{ |
66 |
|
✗ |
CcColorCellRendererText *renderer = CC_COLOR_CELL_RENDERER_TEXT (object); |
67 |
|
|
|
68 |
|
✗ |
switch (param_id) |
69 |
|
|
{ |
70 |
|
✗ |
case PROP_IS_DIM_LABEL: |
71 |
|
✗ |
renderer->is_dim_label = g_value_get_boolean (value); |
72 |
|
✗ |
break; |
73 |
|
✗ |
default: |
74 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
75 |
|
✗ |
break; |
76 |
|
|
} |
77 |
|
✗ |
} |
78 |
|
|
|
79 |
|
|
static void |
80 |
|
✗ |
cc_color_cell_renderer_snapshot (GtkCellRenderer *cell, |
81 |
|
|
GtkSnapshot *snapshot, |
82 |
|
|
GtkWidget *widget, |
83 |
|
|
const GdkRectangle *background_area, |
84 |
|
|
const GdkRectangle *cell_area, |
85 |
|
|
GtkCellRendererState flags) |
86 |
|
|
{ |
87 |
|
|
CcColorCellRendererText *renderer; |
88 |
|
|
GtkStyleContext *context; |
89 |
|
|
|
90 |
|
✗ |
renderer = CC_COLOR_CELL_RENDERER_TEXT (cell); |
91 |
|
✗ |
context = gtk_widget_get_style_context (widget); |
92 |
|
✗ |
gtk_style_context_save (context); |
93 |
|
✗ |
if (renderer->is_dim_label) |
94 |
|
✗ |
gtk_style_context_add_class (context, "dim-label"); |
95 |
|
|
else |
96 |
|
✗ |
gtk_style_context_remove_class (context, "dim-label"); |
97 |
|
✗ |
GTK_CELL_RENDERER_CLASS (parent_class)->snapshot (cell, snapshot, widget, |
98 |
|
|
background_area, |
99 |
|
|
cell_area, flags); |
100 |
|
✗ |
gtk_style_context_restore (context); |
101 |
|
✗ |
} |
102 |
|
|
|
103 |
|
|
static void |
104 |
|
✗ |
cc_color_cell_renderer_text_class_init (CcColorCellRendererTextClass *class) |
105 |
|
|
{ |
106 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (class); |
107 |
|
✗ |
GtkCellRendererClass *object_class_gcr = GTK_CELL_RENDERER_CLASS (class); |
108 |
|
✗ |
object_class_gcr->snapshot = cc_color_cell_renderer_snapshot; |
109 |
|
|
|
110 |
|
✗ |
parent_class = g_type_class_peek_parent (class); |
111 |
|
|
|
112 |
|
✗ |
object_class->get_property = cc_color_cell_renderer_text_get_property; |
113 |
|
✗ |
object_class->set_property = cc_color_cell_renderer_text_set_property; |
114 |
|
|
|
115 |
|
✗ |
g_object_class_install_property (object_class, PROP_IS_DIM_LABEL, |
116 |
|
|
g_param_spec_boolean ("is-dim-label", |
117 |
|
|
NULL, NULL, |
118 |
|
|
FALSE, |
119 |
|
|
G_PARAM_READWRITE)); |
120 |
|
✗ |
} |
121 |
|
|
|
122 |
|
|
static void |
123 |
|
✗ |
cc_color_cell_renderer_text_init (CcColorCellRendererText *renderer) |
124 |
|
|
{ |
125 |
|
✗ |
renderer->is_dim_label = FALSE; |
126 |
|
✗ |
} |
127 |
|
|
|
128 |
|
|
GtkCellRenderer * |
129 |
|
✗ |
cc_color_cell_renderer_text_new (void) |
130 |
|
|
{ |
131 |
|
✗ |
return g_object_new (CC_COLOR_TYPE_CELL_RENDERER_TEXT, NULL); |
132 |
|
|
} |
133 |
|
|
|