]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssinitialvalue.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcssinitialvalue.c
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 "gtkstyleproviderprivate.h"
27
28 struct _GtkCssValue {
29   GTK_CSS_VALUE_BASE
30 };
31
32 static void
33 gtk_css_value_initial_free (GtkCssValue *value)
34 {
35   /* Can only happen if the unique value gets unreffed too often */
36   g_assert_not_reached ();
37 }
38
39 static GtkCssValue *
40 gtk_css_value_initial_compute (GtkCssValue             *value,
41                                guint                    property_id,
42                                GtkStyleProviderPrivate *provider,
43                                GtkCssComputedValues    *values,
44                                GtkCssComputedValues    *parent_values,
45                                GtkCssDependencies      *dependencies)
46 {
47   GtkSettings *settings;
48
49   switch (property_id)
50     {
51     case GTK_CSS_PROPERTY_FONT_FAMILY:
52       settings = _gtk_style_provider_private_get_settings (provider);
53       if (settings)
54         {
55           PangoFontDescription *description;
56           char *font_name;
57           GtkCssValue *value;
58
59           g_object_get (settings, "gtk-font-name", &font_name, NULL);
60           description = pango_font_description_from_string (font_name);
61           g_free (font_name);
62           if (description == NULL)
63             break;
64
65           if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY)
66             {
67               value = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description)));
68               pango_font_description_free (description);
69               return value;
70             }
71  
72           pango_font_description_free (description);
73         }
74       break;
75
76     default:
77       break;
78     }
79
80   return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
81                                  property_id,
82                                  provider,
83                                  values,
84                                  parent_values,
85                                  dependencies);
86 }
87
88 static gboolean
89 gtk_css_value_initial_equal (const GtkCssValue *value1,
90                              const GtkCssValue *value2)
91 {
92   return TRUE;
93 }
94
95 static GtkCssValue *
96 gtk_css_value_initial_transition (GtkCssValue *start,
97                                   GtkCssValue *end,
98                                   guint        property_id,
99                                   double       progress)
100 {
101   return NULL;
102 }
103
104 static void
105 gtk_css_value_initial_print (const GtkCssValue *value,
106                              GString           *string)
107 {
108   g_string_append (string, "initial");
109 }
110
111 static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
112   gtk_css_value_initial_free,
113   gtk_css_value_initial_compute,
114   gtk_css_value_initial_equal,
115   gtk_css_value_initial_transition,
116   gtk_css_value_initial_print
117 };
118
119 static GtkCssValue initial = { &GTK_CSS_VALUE_INITIAL, 1 };
120
121 GtkCssValue *
122 _gtk_css_initial_value_new (void)
123 {
124   return _gtk_css_value_ref (&initial);
125 }
126
127 GtkCssValue *
128 _gtk_css_initial_value_get (void)
129 {
130   return &initial;
131 }