1/* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "config.h"
19
20#include "gtkcssinitialvalueprivate.h"
21
22#include "gtkcssarrayvalueprivate.h"
23#include "gtkcssnumbervalueprivate.h"
24#include "gtkcssstringvalueprivate.h"
25#include "gtkcssstylepropertyprivate.h"
26#include "gtksettingsprivate.h"
27#include "gtkstyleproviderprivate.h"
28
29struct _GtkCssValue {
30 GTK_CSS_VALUE_BASE
31};
32
33static void G_GNUC_NORETURN
34gtk_css_value_initial_free (GtkCssValue *value)
35{
36 /* Can only happen if the unique value gets unreffed too often */
37 g_assert_not_reached ();
38}
39
40static GtkCssValue *
41gtk_css_value_initial_compute (GtkCssValue *value,
42 guint property_id,
43 GtkStyleProvider *provider,
44 GtkCssStyle *style,
45 GtkCssStyle *parent_style)
46{
47 GtkSettings *settings;
48
49 switch (property_id)
50 {
51 case GTK_CSS_PROPERTY_DPI:
52 settings = gtk_style_provider_get_settings (provider);
53 if (settings)
54 {
55 int dpi_int;
56
57 g_object_get (object: settings, first_property_name: "gtk-xft-dpi", &dpi_int, NULL);
58
59 if (dpi_int > 0.0)
60 return _gtk_css_number_value_new (value: dpi_int / 1024., unit: GTK_CSS_NUMBER);
61 }
62 break;
63
64 case GTK_CSS_PROPERTY_FONT_FAMILY:
65 settings = gtk_style_provider_get_settings (provider);
66 if (settings && gtk_settings_get_font_family (settings) != NULL)
67 return _gtk_css_string_value_new (string: gtk_settings_get_font_family (settings));
68 break;
69
70 default:
71 break;
72 }
73
74 return _gtk_css_value_compute (value: _gtk_css_style_property_get_initial_value (property: _gtk_css_style_property_lookup_by_id (id: property_id)),
75 property_id,
76 provider,
77 style,
78 parent_style);
79}
80
81static gboolean
82gtk_css_value_initial_equal (const GtkCssValue *value1,
83 const GtkCssValue *value2)
84{
85 return TRUE;
86}
87
88static GtkCssValue *
89gtk_css_value_initial_transition (GtkCssValue *start,
90 GtkCssValue *end,
91 guint property_id,
92 double progress)
93{
94 return NULL;
95}
96
97static void
98gtk_css_value_initial_print (const GtkCssValue *value,
99 GString *string)
100{
101 g_string_append (string, val: "initial");
102}
103
104static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
105 "GtkCssInitialValue",
106 gtk_css_value_initial_free,
107 gtk_css_value_initial_compute,
108 gtk_css_value_initial_equal,
109 gtk_css_value_initial_transition,
110 NULL,
111 NULL,
112 gtk_css_value_initial_print
113};
114
115static GtkCssValue initial = { &GTK_CSS_VALUE_INITIAL, 1 };
116
117GtkCssValue *
118_gtk_css_initial_value_new (void)
119{
120 return _gtk_css_value_ref (value: &initial);
121}
122
123GtkCssValue *
124_gtk_css_initial_value_get (void)
125{
126 return &initial;
127}
128GtkCssValue *
129_gtk_css_initial_value_new_compute (guint property_id,
130 GtkStyleProvider *provider,
131 GtkCssStyle *style,
132 GtkCssStyle *parent_style)
133{
134 return gtk_css_value_initial_compute (NULL,
135 property_id,
136 provider,
137 style,
138 parent_style);
139}
140

source code of gtk/gtk/gtkcssinitialvalue.c