1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <cairo-gobject.h>
28 #include "gtkcssproviderprivate.h"
30 #include "gtkcssparserprivate.h"
31 #include "gtkcssselectorprivate.h"
32 #include "gtksymboliccolor.h"
33 #include "gtkstyleprovider.h"
34 #include "gtkstylecontextprivate.h"
35 #include "gtkstylepropertiesprivate.h"
36 #include "gtkstylepropertyprivate.h"
37 #include "gtkbindings.h"
38 #include "gtkmarshalers.h"
39 #include "gtkprivate.h"
43 * SECTION:gtkcssprovider
44 * @Short_description: CSS-like styling for widgets
45 * @Title: GtkCssProvider
46 * @See_also: #GtkStyleContext, #GtkStyleProvider
48 * GtkCssProvider is an object implementing the #GtkStyleProvider interface.
49 * It is able to parse <ulink url="http://www.w3.org/TR/CSS2">CSS</ulink>-like
50 * input in order to style widgets.
52 * <refsect2 id="gtkcssprovider-files">
53 * <title>Default files</title>
55 * An application can cause GTK+ to parse a specific CSS style sheet by
56 * calling gtk_css_provider_load_from_file() and adding the provider with
57 * gtk_style_context_add_provider() or gtk_style_context_add_provider_for_screen().
58 * In addition, certain files will be read when GTK+ is initialized. First,
59 * the file <filename><envar>$XDG_CONFIG_HOME</envar>/gtk-3.0/gtk.css</filename>
60 * is loaded if it exists. Then, GTK+ tries to load
61 * <filename><envar>$HOME</envar>/.themes/<replaceable>theme-name</replaceable>/gtk-3.0/gtk.css</filename>,
63 * <filename><replaceable>datadir</replaceable>/share/themes/<replaceable>theme-name</replaceable>/gtk-3.0/gtk.css</filename>,
64 * where <replaceable>theme-name</replaceable> is the name of the current theme
65 * (see the #GtkSettings:gtk-theme-name setting) and <replaceable>datadir</replaceable>
66 * is the prefix configured when GTK+ was compiled, unless overridden by the
67 * <envar>GTK_DATA_PREFIX</envar> environment variable.
70 * <refsect2 id="gtkcssprovider-stylesheets">
71 * <title>Style sheets</title>
73 * The basic structure of the style sheets understood by this provider is
74 * a series of statements, which are either rule sets or '@-rules', separated
78 * A rule set consists of a selector and a declaration block, which is
79 * a series of declarations enclosed in curly braces ({ and }). The
80 * declarations are separated by semicolons (;). Multiple selectors can
81 * share the same declaration block, by putting all the separators in
82 * front of the block, separated by commas.
84 * <example><title>A rule set with two selectors</title>
85 * <programlisting language="text">
86 * GtkButton, GtkEntry {
93 * <refsect2 id="gtkcssprovider-selectors">
94 * <title>Selectors</title>
96 * Selectors work very similar to the way they do in CSS, with widget class
97 * names taking the role of element names, and widget names taking the role
98 * of IDs. When used in a selector, widget names must be prefixed with a
99 * '#' character. The '*' character represents the so-called universal
100 * selector, which matches any widget.
103 * To express more complicated situations, selectors can be combined in
106 * <listitem><para>To require that a widget satisfies several conditions,
107 * combine several selectors into one by concatenating them. E.g.
108 * <literal>GtkButton#button1</literal> matches a GtkButton widget
109 * with the name button1.</para></listitem>
110 * <listitem><para>To only match a widget when it occurs inside some other
111 * widget, write the two selectors after each other, separated by whitespace.
112 * E.g. <literal>GtkToolBar GtkButton</literal> matches GtkButton widgets
113 * that occur inside a GtkToolBar.</para></listitem>
114 * <listitem><para>In the previous example, the GtkButton is matched even
115 * if it occurs deeply nested inside the toolbar. To restrict the match
116 * to direct children of the parent widget, insert a '>' character between
117 * the two selectors. E.g. <literal>GtkNotebook > GtkLabel</literal> matches
118 * GtkLabel widgets that are direct children of a GtkNotebook.</para></listitem>
122 * <title>Widget classes and names in selectors</title>
123 * <programlisting language="text">
124 * /* Theme labels that are descendants of a window */
125 * GtkWindow GtkLabel {
126 * background-color: #898989
129 * /* Theme notebooks, and anything that's within these */
131 * background-color: #a939f0
134 * /* Theme combo boxes, and entries that
135 * are direct children of a notebook */
137 * GtkNotebook > GtkEntry {
139 * background-color: #1209a2
142 * /* Theme any widget within a GtkBin */
147 * /* Theme a label named title-label */
148 * GtkLabel#title-label {
152 * /* Theme any widget named main-entry */
154 * background-color: #f0a810
159 * Widgets may also define style classes, which can be used for matching.
160 * When used in a selector, style classes must be prefixed with a '.'
164 * Refer to the documentation of individual widgets to learn which
165 * style classes they define and see <xref linkend="gtkstylecontext-classes"/>
166 * for a list of all style classes used by GTK+ widgets.
169 * Note that there is some ambiguity in the selector syntax when it comes
170 * to differentiation widget class names from regions. GTK+ currently treats
171 * a string as a widget class name if it contains any uppercase characters
172 * (which should work for more widgets with names like GtkLabel).
175 * <title>Style classes in selectors</title>
176 * <programlisting language="text">
177 * /* Theme all widgets defining the class entry */
179 * color: #39f1f9;
182 * /* Theme spinbuttons' entry */
183 * GtkSpinButton.entry {
189 * In complicated widgets like e.g. a GtkNotebook, it may be desirable
190 * to style different parts of the widget differently. To make this
191 * possible, container widgets may define regions, whose names
192 * may be used for matching in selectors.
195 * Some containers allow to further differentiate between regions by
196 * applying so-called pseudo-classes to the region. For example, the
197 * tab region in GtkNotebook allows to single out the first or last
198 * tab by using the :first-child or :last-child pseudo-class.
199 * When used in selectors, pseudo-classes must be prefixed with a
203 * Refer to the documentation of individual widgets to learn which
204 * regions and pseudo-classes they define and see
205 * <xref linkend="gtkstylecontext-classes"/> for a list of all regions
206 * used by GTK+ widgets.
209 * <title>Regions in selectors</title>
210 * <programlisting language="text">
211 * /* Theme any label within a notebook */
212 * GtkNotebook GtkLabel {
213 * color: #f90192;
216 * /* Theme labels within notebook tabs */
217 * GtkNotebook tab GtkLabel {
218 * color: #703910;
221 * /* Theme labels in the any first notebook
222 * tab, both selectors are equivalent */
223 * GtkNotebook tab:nth-child(first) GtkLabel,
224 * GtkNotebook tab:first-child GtkLabel {
225 * color: #89d012;
230 * Another use of pseudo-classes is to match widgets depending on their
231 * state. This is conceptually similar to the :hover, :active or :focus
232 * pseudo-classes in CSS. The available pseudo-classes for widget states
233 * are :active, :prelight (or :hover), :insensitive, :selected, :focused
237 * <title>Styling specific widget states</title>
238 * <programlisting language="text">
239 * /* Theme active (pressed) buttons */
241 * background-color: #0274d9;
244 * /* Theme buttons with the mouse pointer on it,
245 * both are equivalent */
247 * GtkButton:prelight {
248 * background-color: #3085a9;
251 * /* Theme insensitive widgets, both are equivalent */
254 * background-color: #320a91;
257 * /* Theme selection colors in entries */
258 * GtkEntry:selected {
259 * background-color: #56f9a0;
262 * /* Theme focused labels */
264 * background-color: #b4940f;
267 * /* Theme inconsistent checkbuttons */
268 * GtkCheckButton:inconsistent {
269 * background-color: #20395a;
274 * Widget state pseudoclasses may only apply to the last element
278 * To determine the effective style for a widget, all the matching rule
279 * sets are merged. As in CSS, rules apply by specificity, so the rules
280 * whose selectors more closely match a widget path will take precedence
284 * <refsect2 id="gtkcssprovider-rules">
285 * <title>@ Rules</title>
287 * GTK+'s CSS supports the @import rule, in order to load another
288 * CSS style sheet in addition to the currently parsed one.
291 * <title>Using the @import rule</title>
292 * <programlisting language="text">
293 * @import url ("path/to/common.css");
296 * <para id="css-binding-set">
297 * In order to extend key bindings affecting different widgets, GTK+
298 * supports the @binding-set rule to parse a set of bind/unbind
299 * directives, see #GtkBindingSet for the supported syntax. Note that
300 * the binding sets defined in this way must be associated with rule sets
301 * by setting the gtk-key-bindings style property.
304 * Customized key bindings are typically defined in a separate
305 * <filename>gtk-keys.css</filename> CSS file and GTK+ loads this file
306 * according to the current key theme, which is defined by the
307 * #GtkSettings:gtk-key-theme-name setting.
310 * <title>Using the @binding rule</title>
311 * <programlisting language="text">
312 * @binding-set binding-set1 {
313 * bind "<alt>Left" { "move-cursor" (visual-positions, -3, 0) };
317 * @binding-set binding-set2 {
318 * bind "<alt>Right" { "move-cursor" (visual-positions, 3, 0) };
319 * bind "<alt>KP_space" { "delete-from-cursor" (whitespace, 1)
320 * "insert-at-cursor" (" ") };
324 * gtk-key-bindings: binding-set1, binding-set2;
329 * GTK+ also supports an additional @define-color rule, in order
330 * to define a color name which may be used instead of color numeric
331 * representations. Also see the #GtkSettings:gtk-color-scheme setting
332 * for a way to override the values of these named colors.
335 * <title>Defining colors</title>
336 * <programlisting language="text">
337 * @define-color bg_color #f9a039;
340 * background-color: @bg_color;
345 * <refsect2 id="gtkcssprovider-symbolic-colors">
346 * <title>Symbolic colors</title>
348 * Besides being able to define color names, the CSS parser is also able
349 * to read different color expressions, which can also be nested, providing
350 * a rich language to define colors which are derived from a set of base
354 * <title>Using symbolic colors</title>
355 * <programlisting language="text">
356 * @define-color entry-color shade (@bg_color, 0.7);
359 * background-color: @entry-color;
363 * background-color: mix (@entry-color,
364 * shade (#fff, 0.5),
370 * The various ways to express colors in GTK+ CSS are:
376 * <entry>Syntax</entry>
377 * <entry>Explanation</entry>
378 * <entry>Examples</entry>
383 * <entry>rgb(@r, @g, @b)</entry>
384 * <entry>An opaque color; @r, @g, @b can be either integers between
385 * 0 and 255 or percentages</entry>
386 * <entry><literallayout>rgb(128, 10, 54)
387 * rgb(20%, 30%, 0%)</literallayout></entry>
390 * <entry>rgba(@r, @g, @b, @a)</entry>
391 * <entry>A translucent color; @r, @g, @b are as in the previous row,
392 * @a is a floating point number between 0 and 1</entry>
393 * <entry><literallayout>rgba(255, 255, 0, 0.5)</literallayout></entry>
396 * <entry>#@xxyyzz</entry>
397 * <entry>An opaque color; @xx, @yy, @zz are hexadecimal numbers
398 * specifying @r, @g, @b variants with between 1 and 4
399 * hexadecimal digits per component are allowed</entry>
400 * <entry><literallayout>#ff12ab
401 * #f0c</literallayout></entry>
404 * <entry>@name</entry>
405 * <entry>Reference to a color that has been defined with
406 * @define-color
408 * <entry>@bg_color</entry>
411 * <entry>mix(@color1, @color2, @f)</entry>
412 * <entry>A linear combination of @color1 and @color2. @f is a
413 * floating point number between 0 and 1.</entry>
414 * <entry><literallayout>mix(#ff1e0a, @bg_color, 0.8)</literallayout></entry>
417 * <entry>shade(@color, @f)</entry>
418 * <entry>A lighter or darker variant of @color. @f is a
419 * floating point number.
421 * <entry>shade(@fg_color, 0.5)</entry>
424 * <entry>lighter(@color)</entry>
425 * <entry>A lighter variant of @color</entry>
428 * <entry>darker(@color)</entry>
429 * <entry>A darker variant of @color</entry>
435 * <refsect2 id="gtkcssprovider-gradients">
436 * <title>Gradients</title>
438 * Linear or radial Gradients can be used as background images.
441 * A linear gradient along the line from (@start_x, @start_y) to
442 * (@end_x, @end_y) is specified using the syntax
443 * <literallayout>-gtk-gradient (linear,
444 * @start_x @start_y, @end_x @end_y,
445 * color-stop (@position, @color),
446 * ...)</literallayout>
447 * where @start_x and @end_x can be either a floating point number between
448 * 0 and 1 or one of the special values 'left', 'right' or 'center', @start_y
449 * and @end_y can be either a floating point number between 0 and 1 or one
450 * of the special values 'top', 'bottom' or 'center', @position is a floating
451 * point number between 0 and 1 and @color is a color expression (see above).
452 * The color-stop can be repeated multiple times to add more than one color
453 * stop. 'from (@color)' and 'to (@color)' can be used as abbreviations for
454 * color stops with position 0 and 1, respectively.
457 * <title>A linear gradient</title>
458 * <inlinegraphic fileref="gradient1.png" format="PNG"/>
459 * <para>This gradient was specified with
460 * <literallayout>-gtk-gradient (linear,
461 * left top, right bottom,
462 * from(@yellow), to(@blue))</literallayout></para>
465 * <title>Another linear gradient</title>
466 * <inlinegraphic fileref="gradient2.png" format="PNG"/>
467 * <para>This gradient was specified with
468 * <literallayout>-gtk-gradient (linear,
470 * color-stop(0, @yellow),
471 * color-stop(0.2, @blue),
472 * color-stop(1, #0f0))</literallayout></para>
475 * A radial gradient along the two circles defined by (@start_x, @start_y,
476 * @start_radius) and (@end_x, @end_y, @end_radius) is specified using the
478 * <literallayout>-gtk-gradient (radial,
479 * @start_x @start_y, @start_radius,
480 * @end_x @end_y, @end_radius,
481 * color-stop (@position, @color),
482 * ...)</literallayout>
483 * where @start_radius and @end_radius are floating point numbers and
484 * the other parameters are as before.
487 * <title>A radial gradient</title>
488 * <inlinegraphic fileref="gradient3.png" format="PNG"/>
489 * <para>This gradient was specified with
490 * <literallayout>-gtk-gradient (radial,
493 * from(@yellow), to(@green))</literallayout></para>
496 * <title>Another radial gradient</title>
497 * <inlinegraphic fileref="gradient4.png" format="PNG"/>
498 * <para>This gradient was specified with
499 * <literallayout>-gtk-gradient (radial,
502 * color-stop (0, #f00),
503 * color-stop (0.1, #a0f),
504 * color-stop (0.2, @yellow),
505 * color-stop (1, @green))</literallayout></para>
508 * <refsect2 id="gtkcssprovider-shadows">
509 * <title>Text shadow</title>
511 * A shadow list can be applied to text or symbolic icons, using the CSS3
512 * text-shadow syntax, as defined in
513 * <ulink url="http://www.w3.org/TR/css3-text/#text-shadow">the CSS3 specification</ulink>.
516 * A text shadow is specified using the syntax
517 * <literallayout>text-shadow: @horizontal_offset @vertical_offset [ @blur_radius ] @color</literallayout>
518 * The offset of the shadow is specified with the @horizontal_offset and @vertical_offset
519 * parameters. The optional blur radius is parsed, but it is currently not rendered by
520 * the GTK+ theming engine.
523 * To set multiple shadows on an element, you can specify a comma-separated list
524 * of shadow elements in the text-shadow property. Shadows are always rendered
525 * front-back, i.e. the first shadow specified is on top of the others. Shadows
526 * can thus overlay each other, but they can never overlay the text itself,
527 * which is always rendered on top of the shadow layer.
531 * <title>Box shadow</title>
533 * Themes can apply shadows on framed elements using the CSS3 box-shadow syntax,
535 * <ulink url="http://www.w3.org/TR/css3-background/#the-box-shadow">the CSS3 specification</ulink>.
538 * A box shadow is specified using the syntax
539 * <literallayout>box-shadow: [ @inset ] @horizontal_offset @vertical_offset [ @blur_radius ] [ @spread ] @color</literallayout>
540 * A positive offset will draw a shadow that is offset to the right (down) of the box,
541 * a negative offset to the left (top). The optional spread parameter defines an additional
542 * distance to expand the shadow shape in all directions, by the specified radius.
543 * The optional blur radius parameter is parsed, but it is currently not rendered by
544 * the GTK+ theming engine.
545 * The inset parameter defines whether the drop shadow should be rendered inside or outside
546 * the box canvas. Only inset box-shadows are currently supported by the GTK+ theming engine,
547 * non-inset elements are currently ignored.
550 * To set multiple box-shadows on an element, you can specify a comma-separated list
551 * of shadow elements in the box-shadow property. Shadows are always rendered
552 * front-back, i.e. the first shadow specified is on top of the others, so they may
553 * overlap other boxes or other shadows.
556 * <refsect2 id="gtkcssprovider-border-image">
557 * <title>Border images</title>
559 * Images and gradients can also be used in slices for the purpose of creating
561 * For more information, see the CSS3 documentation for the border-image property,
562 * which can be found <ulink url="http://www.w3.org/TR/css3-background/#border-images">here</ulink>.
564 * <inlinegraphic fileref="slices.png" format="PNG"/>
566 * The parameters of the slicing process are controlled by
567 * four separate properties. Note that you can use the
568 * <literallayout>border-image</literallayout> shorthand property
569 * to set values for the three properties at the same time.
572 * <literallayout>border-image-source: url(@path)
573 * (or border-image-source: -gtk-gradient(...))</literallayout>:
574 * Specifies the source of the border image, and it can either
575 * be an URL or a gradient (see above).
578 * <literallayout>border-image-slice: @top @right @bottom @left</literallayout>
579 * The sizes specified by the @top, @right, @bottom and @left parameters
580 * are the offsets, in pixels, from the relevant edge where the image
581 * should be "cut off" to build the slices used for the rendering
585 * <literallayout>border-image-width: @top @right @bottom @left</literallayout>
586 * The sizes specified by the @top, @right, @bottom and @left parameters
587 * are inward distances from the border box edge, used to specify the
588 * rendered size of each slice determined by border-image-slice.
589 * If this property is not specified, the values of border-width will
590 * be used as a fallback.
593 * <literallayout>border-image-repeat: [stretch|repeat|round|space] ?
594 * [stretch|repeat|round|space]</literallayout>
595 * Specifies how the image slices should be rendered in the area
596 * outlined by border-width.
597 * The default (stretch) is to resize the slice to fill in the whole
599 * If the value of this property is 'repeat', the image slice
600 * will be tiled to fill the area.
601 * If the value of this property is 'round', the image slice will
602 * be tiled to fill the area, and scaled to fit it exactly
603 * a whole number of times.
604 * If the value of this property is 'space', the image slice will
605 * be tiled to fill the area, and if it doesn't fit it exactly a whole
606 * number of times, the extra space is distributed as padding around
608 * If two options are specified, the first one affects
609 * the horizontal behaviour and the second one the vertical behaviour.
610 * If only one option is specified, it affects both.
613 * <title>A border image</title>
614 * <inlinegraphic fileref="border1.png" format="PNG"/>
615 * <para>This border image was specified with
616 * <literallayout>url("gradient1.png") 10 10 10 10</literallayout>
620 * <title>A repeating border image</title>
621 * <inlinegraphic fileref="border2.png" format="PNG"/>
622 * <para>This border image was specified with
623 * <literallayout>url("gradient1.png") 10 10 10 10 repeat</literallayout>
627 * <title>A stretched border image</title>
628 * <inlinegraphic fileref="border3.png" format="PNG"/>
629 * <para>This border image was specified with
630 * <literallayout>url("gradient1.png") 10 10 10 10 stretch</literallayout>
634 * <refsect2 id="gtkcssprovider-transitions">
635 * <para>Styles can specify transitions that will be used to create a gradual
636 * change in the appearance when a widget state changes. The following
637 * syntax is used to specify transitions:
638 * <literallayout>@duration [s|ms] [linear|ease|ease-in|ease-out|ease-in-out] [loop]?</literallayout>
639 * The @duration is the amount of time that the animation will take for
640 * a complete cycle from start to end. If the loop option is given, the
641 * animation will be repated until the state changes again.
642 * The option after the duration determines the transition function from a
643 * small set of predefined functions.
644 * <figure><title>Linear transition</title>
645 * <graphic fileref="linear.png" format="PNG"/>
647 * <figure><title>Ease transition</title>
648 * <graphic fileref="ease.png" format="PNG"/>
650 * <figure><title>Ease-in-out transition</title>
651 * <graphic fileref="ease-in-out.png" format="PNG"/>
653 * <figure><title>Ease-in transition</title>
654 * <graphic fileref="ease-in.png" format="PNG"/>
656 * <figure><title>Ease-out transition</title>
657 * <graphic fileref="ease-out.png" format="PNG"/>
661 * <refsect2 id="gtkcssprovider-properties">
662 * <title>Supported properties</title>
664 * Properties are the part that differ the most to common CSS,
665 * not all properties are supported (some are planned to be
666 * supported eventually, some others are meaningless or don't
667 * map intuitively in a widget based environment).
670 * There is also a difference in shorthand properties, for
671 * example in common CSS it is fine to define a font through
672 * the different @font-family, @font-style, @font-size
673 * properties, meanwhile in GTK+'s CSS only the canonical
674 * @font property is supported.
677 * The currently supported properties are:
683 * <entry>Property name</entry>
684 * <entry>Syntax</entry>
685 * <entry>Maps to</entry>
686 * <entry>Examples</entry>
691 * <entry>engine</entry>
692 * <entry>engine-name</entry>
693 * <entry>#GtkThemingEngine</entry>
694 * <entry>engine: clearlooks;
695 * engine: none; /* use the default (i.e. builtin) engine) */ </entry>
698 * <entry>background-color</entry>
699 * <entry morerows="2">color (see above)</entry>
700 * <entry morerows="2">#GdkRGBA</entry>
701 * <entry morerows="2"><literallayout>background-color: #fff;
702 * color: &color1;
703 * background-color: shade (&color1, 0.5);
704 * color: mix (&color1, #f0f, 0.8);</literallayout>
708 * <entry>color</entry>
711 * <entry>border-color</entry>
714 * <entry>font</entry>
715 * <entry>@family [@style] [@size]</entry>
716 * <entry>#PangoFontDescription</entry>
717 * <entry>font: Sans 15;</entry>
720 * <entry>margin-top</entry>
721 * <entry>integer</entry>
722 * <entry>#gint</entry>
723 * <entry>margin-top: 0;</entry>
726 * <entry>margin-left</entry>
727 * <entry>integer</entry>
728 * <entry>#gint</entry>
729 * <entry>margin-left: 1;</entry>
732 * <entry>margin-bottom</entry>
733 * <entry>integer</entry>
734 * <entry>#gint</entry>
735 * <entry>margin-bottom: 2;</entry>
738 * <entry>margin-right</entry>
739 * <entry>integer</entry>
740 * <entry>#gint</entry>
741 * <entry>margin-right: 4;</entry>
744 * <entry>margin</entry>
745 * <entry morerows="1"><literallayout>@width
746 * @vertical_width @horizontal_width
747 * @top_width @horizontal_width @bottom_width
748 * @top_width @right_width @bottom_width @left_width</literallayout>
750 * <entry morerows="1">#GtkBorder</entry>
751 * <entry morerows="1"><literallayout>margin: 5;
754 * margin: 5 10 3 5;</literallayout>
758 * <entry>padding-top</entry>
759 * <entry>integer</entry>
760 * <entry>#gint</entry>
761 * <entry>padding-top: 5;</entry>
764 * <entry>padding-left</entry>
765 * <entry>integer</entry>
766 * <entry>#gint</entry>
767 * <entry>padding-left: 5;</entry>
770 * <entry>padding-bottom</entry>
771 * <entry>integer</entry>
772 * <entry>#gint</entry>
773 * <entry>padding-bottom: 5;</entry>
776 * <entry>padding-right</entry>
777 * <entry>integer</entry>
778 * <entry>#gint</entry>
779 * <entry>padding-right: 5;</entry>
782 * <entry>padding</entry>
785 * <entry>background-image</entry>
786 * <entry><literallayout>gradient (see above) or
787 * url(@path)</literallayout></entry>
788 * <entry>#cairo_pattern_t</entry>
789 * <entry><literallayout>-gtk-gradient (linear,
790 * left top, right top,
791 * from (#fff), to (#000));
792 * -gtk-gradient (linear, 0.0 0.5, 0.5 1.0,
794 * color-stop (0.5, #f00),
796 * -gtk-gradient (radial,
797 * center center, 0.2,
798 * center center, 0.8,
799 * color-stop (0.0, #fff),
800 * color-stop (1.0, #000));
801 * url ('background.png');</literallayout>
805 * <entry>border-top-width</entry>
806 * <entry>integer</entry>
807 * <entry>#gint</entry>
808 * <entry>border-top-width: 5;</entry>
811 * <entry>border-left-width</entry>
812 * <entry>integer</entry>
813 * <entry>#gint</entry>
814 * <entry>border-left-width: 5;</entry>
817 * <entry>border-bottom-width</entry>
818 * <entry>integer</entry>
819 * <entry>#gint</entry>
820 * <entry>border-bottom-width: 5;</entry>
823 * <entry>border-right-width</entry>
824 * <entry>integer</entry>
825 * <entry>#gint</entry>
826 * <entry>border-right-width: 5;</entry>
829 * <entry>border-width</entry>
830 * <entry morerows="1">#GtkBorder</entry>
831 * <entry morerows="1"><literallayout>border-width: 1;
833 * border-width: 1 2 3;
834 * border-width: 1 2 3 5;</literallayout>
838 * <entry>border-radius</entry>
839 * <entry>integer</entry>
840 * <entry>#gint</entry>
841 * <entry>border-radius: 5;</entry>
844 * <entry>border-style</entry>
845 * <entry>[none|solid|inset|outset]</entry>
846 * <entry>#GtkBorderStyle</entry>
847 * <entry>border-style: solid;</entry>
850 * <entry>border-image</entry>
851 * <entry><literallayout>border image (see above)</literallayout></entry>
852 * <entry>internal use only</entry>
853 * <entry><literallayout>border-image: url("/path/to/image.png") 3 4 3 4 stretch;
854 * border-image: url("/path/to/image.png") 3 4 4 3 repeat stretch;</literallayout>
858 * <entry>text-shadow</entry>
859 * <entry>shadow list (see above)</entry>
860 * <entry>#GtkTextShadow</entry>
861 * <entry><literallayout>text-shadow: 1 1 0 blue, -4 -4 red;</literallayout></entry>
864 * <entry>transition</entry>
865 * <entry>transition (see above)</entry>
866 * <entry>internal use only</entry>
867 * <entry><literallayout>transition: 150ms ease-in-out;
868 * transition: 1s linear loop;</literallayout>
872 * <entry>gtk-key-bindings</entry>
873 * <entry>binding set name list</entry>
874 * <entry>internal use only</entry>
875 * <entry><literallayout>gtk-bindings: binding1, binding2, ...;</literallayout>
882 * GtkThemingEngines can register their own, engine-specific style properties
883 * with the function gtk_theming_engine_register_property(). These properties
884 * can be set in CSS like other properties, using a name of the form
885 * <literallayout>-<replaceable>namespace</replaceable>-<replaceable>name</replaceable></literallayout>, where <replaceable>namespace</replaceable> is typically
886 * the name of the theming engine, and <replaceable>name</replaceable> is the
887 * name of the property. Style properties that have been registered by widgets
888 * using gtk_widget_class_install_style_property() can also be set in this
889 * way, using the widget class name for <replaceable>namespace</replaceable>.
892 * <title>Using engine-specific style properties</title>
895 * engine: clearlooks;
897 * -GtkPaned-handle-size: 6;
898 * -clearlooks-colorize-scrollbar: false;
905 typedef struct GtkCssRuleset GtkCssRuleset;
906 typedef struct _GtkCssScanner GtkCssScanner;
907 typedef enum ParserScope ParserScope;
908 typedef enum ParserSymbol ParserSymbol;
912 GtkCssSelector *selector;
913 GHashTable *widget_style;
916 guint has_inherit :1;
919 struct _GtkCssScanner
921 GtkCssProvider *provider;
922 GtkCssParser *parser;
923 GtkCssScanner *parent;
927 GSList *cur_selectors;
928 GHashTable *cur_properties;
931 struct _GtkCssProviderPrivate
935 GHashTable *symbolic_colors;
949 /* Extend GtkStateType, since these
950 * values are also used as symbols
953 /* Scope: pseudo-class */
954 SYMBOL_NTH_CHILD = GTK_STATE_FOCUSED + 1,
959 /* Scope: nth-child */
960 SYMBOL_NTH_CHILD_EVEN,
961 SYMBOL_NTH_CHILD_ODD,
962 SYMBOL_NTH_CHILD_FIRST,
963 SYMBOL_NTH_CHILD_LAST
971 static guint css_provider_signals[LAST_SIGNAL] = { 0 };
973 static void gtk_css_provider_finalize (GObject *object);
974 static void gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface);
977 gtk_css_provider_load_internal (GtkCssProvider *css_provider,
978 GtkCssScanner *scanner,
985 gtk_css_provider_error_quark (void)
987 return g_quark_from_static_string ("gtk-css-provider-error-quark");
990 G_DEFINE_TYPE_EXTENDED (GtkCssProvider, gtk_css_provider, G_TYPE_OBJECT, 0,
991 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
992 gtk_css_style_provider_iface_init));
995 gtk_css_provider_parsing_error (GtkCssProvider *provider,
999 const GError * error)
1001 /* Only emit a warning when we have no error handlers. This is our
1002 * default handlers. And in this case erroneous CSS files are a bug
1003 * and should be fixed.
1004 * Note that these warnings can also be triggered by a broken theme
1005 * that people installed from some weird location on the internets.
1007 if (!g_signal_has_handler_pending (provider,
1008 css_provider_signals[PARSING_ERROR],
1012 g_warning ("Theme parsing error: %s:%u:%u: %s", path ? path : "<unknown>", line, position, error->message);
1017 gtk_css_provider_class_init (GtkCssProviderClass *klass)
1019 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1022 * GtkCssProvider::parsing-error:
1023 * @provider: the provider that had a parsing error
1024 * @path: path to the parsed file or %NULL if the file cannot be
1025 * identified or the data was not loaded from a file
1026 * @line: line in the file or data or 0 if unknown
1027 * @position: offset into the current line or 0 if unknown or the
1028 * whole line is affected
1029 * @error: The parsing error
1031 * Signals that a parsing error occured. the @path, @line and @position
1032 * describe the actual location of the error as accurately as possible.
1034 * Parsing errors are never fatal, so the parsing will resume after
1035 * the error. Errors may however cause parts of the given
1036 * data or even all of it to not be parsed at all. So it is a useful idea
1037 * to check that the parsing succeeds by connecting to this signal.
1039 * Note that this signal may be emitted at any time as the css provider
1040 * may opt to defer parsing parts or all of the input to a later time
1041 * than when a loading function was called.
1043 css_provider_signals[PARSING_ERROR] =
1044 g_signal_new (I_("parsing-error"),
1045 G_TYPE_FROM_CLASS (object_class),
1047 G_STRUCT_OFFSET (GtkCssProviderClass, parsing_error),
1049 _gtk_marshal_VOID__STRING_UINT_UINT_BOXED,
1051 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_ERROR);
1053 object_class->finalize = gtk_css_provider_finalize;
1055 klass->parsing_error = gtk_css_provider_parsing_error;
1057 g_type_class_add_private (object_class, sizeof (GtkCssProviderPrivate));
1061 gtk_css_provider_take_error_full (GtkCssProvider *provider,
1070 filename = g_file_get_path (file);
1074 g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0,
1075 filename, line, position, error);
1078 g_error_free (error);
1082 gtk_css_ruleset_init_copy (GtkCssRuleset *new,
1083 const GtkCssRuleset *ruleset,
1084 GtkCssSelector *selector)
1086 memcpy (new, ruleset, sizeof (GtkCssRuleset));
1088 new->selector = selector;
1089 if (new->widget_style)
1090 g_hash_table_ref (new->widget_style);
1092 g_hash_table_ref (new->style);
1096 gtk_css_ruleset_clear (GtkCssRuleset *ruleset)
1099 g_hash_table_unref (ruleset->style);
1100 if (ruleset->widget_style)
1101 g_hash_table_unref (ruleset->widget_style);
1102 if (ruleset->selector)
1103 _gtk_css_selector_free (ruleset->selector);
1105 memset (ruleset, 0, sizeof (GtkCssRuleset));
1109 property_value_free (GValue *value)
1111 if (G_IS_VALUE (value))
1112 g_value_unset (value);
1114 g_slice_free (GValue, value);
1118 gtk_css_ruleset_add_style (GtkCssRuleset *ruleset,
1122 if (ruleset->widget_style == NULL)
1123 ruleset->widget_style = g_hash_table_new_full (g_str_hash,
1125 (GDestroyNotify) g_free,
1126 (GDestroyNotify) property_value_free);
1128 g_hash_table_insert (ruleset->widget_style, name, value);
1132 gtk_css_ruleset_add (GtkCssRuleset *ruleset,
1133 const GtkStyleProperty *prop,
1136 if (ruleset->style == NULL)
1137 ruleset->style = g_hash_table_new_full (g_direct_hash,
1140 (GDestroyNotify) property_value_free);
1142 if (_gtk_style_property_is_shorthand (prop))
1144 GParameter *parameters;
1145 guint i, n_parameters;
1147 parameters = _gtk_style_property_unpack (prop, value, &n_parameters);
1149 for (i = 0; i < n_parameters; i++)
1151 const GtkStyleProperty *child;
1154 child = _gtk_style_property_lookup (parameters[i].name);
1155 value = g_slice_dup (GValue, ¶meters[i].value);
1156 gtk_css_ruleset_add (ruleset, child, value);
1158 g_free (parameters);
1159 property_value_free (value);
1163 ruleset->has_inherit |= _gtk_style_property_is_inherit (prop);
1164 g_hash_table_insert (ruleset->style, (gpointer) prop, value);
1168 gtk_css_ruleset_matches (GtkCssRuleset *ruleset,
1169 GtkWidgetPath *path,
1172 return _gtk_css_selector_matches (ruleset->selector, path, length);
1176 gtk_css_scanner_reset (GtkCssScanner *scanner)
1178 g_slist_free (scanner->state);
1179 scanner->state = NULL;
1181 g_slist_free_full (scanner->cur_selectors, (GDestroyNotify) _gtk_css_selector_free);
1182 scanner->cur_selectors = NULL;
1184 if (scanner->cur_properties)
1185 g_hash_table_unref (scanner->cur_properties);
1187 scanner ->cur_properties = g_hash_table_new_full (g_str_hash,
1189 (GDestroyNotify) g_free,
1190 (GDestroyNotify) property_value_free);
1194 gtk_css_scanner_destroy (GtkCssScanner *scanner)
1196 gtk_css_scanner_reset (scanner);
1198 g_object_unref (scanner->provider);
1200 g_object_unref (scanner->file);
1201 g_object_unref (scanner->base);
1202 g_hash_table_destroy (scanner->cur_properties);
1203 _gtk_css_parser_free (scanner->parser);
1205 g_slice_free (GtkCssScanner, scanner);
1209 gtk_css_scanner_parser_error (GtkCssParser *parser,
1210 const GError *error,
1213 GtkCssScanner *scanner = user_data;
1215 gtk_css_provider_take_error_full (scanner->provider,
1217 _gtk_css_parser_get_line (scanner->parser),
1218 _gtk_css_parser_get_position (scanner->parser),
1219 g_error_copy (error));
1222 static GtkCssScanner *
1223 gtk_css_scanner_new (GtkCssProvider *provider,
1224 GtkCssScanner *parent,
1229 GtkCssScanner *scanner;
1231 g_assert (data[length] == 0);
1233 scanner = g_slice_new0 (GtkCssScanner);
1235 g_object_ref (provider);
1236 scanner->provider = provider;
1237 scanner->parent = parent;
1241 scanner->file = g_object_ref (file);
1242 scanner->base = g_file_get_parent (file);
1246 char *dir = g_get_current_dir ();
1247 scanner->base = g_file_new_for_path (dir);
1251 scanner->cur_properties = g_hash_table_new_full (g_str_hash,
1253 (GDestroyNotify) g_free,
1254 (GDestroyNotify) property_value_free);
1256 scanner->parser = _gtk_css_parser_new (data,
1257 gtk_css_scanner_parser_error,
1264 gtk_css_scanner_get_base_url (GtkCssScanner *scanner)
1266 return scanner->base;
1270 gtk_css_scanner_would_recurse (GtkCssScanner *scanner,
1275 if (scanner->file && g_file_equal (scanner->file, file))
1278 scanner = scanner->parent;
1285 gtk_css_provider_init (GtkCssProvider *css_provider)
1287 GtkCssProviderPrivate *priv;
1289 priv = css_provider->priv = G_TYPE_INSTANCE_GET_PRIVATE (css_provider,
1290 GTK_TYPE_CSS_PROVIDER,
1291 GtkCssProviderPrivate);
1293 priv->rulesets = g_array_new (FALSE, FALSE, sizeof (GtkCssRuleset));
1295 priv->symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
1296 (GDestroyNotify) g_free,
1297 (GDestroyNotify) gtk_symbolic_color_unref);
1301 css_provider_dump_symbolic_colors (GtkCssProvider *css_provider,
1302 GtkStyleProperties *props)
1304 GtkCssProviderPrivate *priv;
1305 GHashTableIter iter;
1306 gpointer key, value;
1308 priv = css_provider->priv;
1309 g_hash_table_iter_init (&iter, priv->symbolic_colors);
1311 while (g_hash_table_iter_next (&iter, &key, &value))
1314 GtkSymbolicColor *color;
1319 gtk_style_properties_map_color (props, name, color);
1323 static GtkStyleProperties *
1324 gtk_css_provider_get_style (GtkStyleProvider *provider,
1325 GtkWidgetPath *path)
1327 GtkCssProvider *css_provider;
1328 GtkCssProviderPrivate *priv;
1329 GtkStyleProperties *props;
1332 css_provider = GTK_CSS_PROVIDER (provider);
1333 priv = css_provider->priv;
1334 length = gtk_widget_path_length (path);
1335 props = gtk_style_properties_new ();
1337 css_provider_dump_symbolic_colors (css_provider, props);
1339 for (l = 1; l <= length; l++)
1341 for (i = 0; i < priv->rulesets->len; i++)
1343 GtkCssRuleset *ruleset;
1344 GHashTableIter iter;
1345 gpointer key, value;
1347 ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
1349 if (ruleset->style == NULL)
1352 if (l < length && (!ruleset->has_inherit || _gtk_css_selector_get_state_flags (ruleset->selector)))
1355 if (!gtk_css_ruleset_matches (ruleset, path, l))
1358 g_hash_table_iter_init (&iter, ruleset->style);
1360 while (g_hash_table_iter_next (&iter, &key, &value))
1362 GtkStyleProperty *prop = key;
1364 if (l != length && !_gtk_style_property_is_inherit (prop))
1367 _gtk_style_properties_set_property_by_property (props,
1369 _gtk_css_selector_get_state_flags (ruleset->selector),
1379 gtk_css_provider_parser_error (GtkCssParser *parser,
1380 const GError *error,
1383 GtkCssProvider *provider = user_data;
1385 gtk_css_provider_take_error_full (provider,
1387 _gtk_css_parser_get_line (parser),
1388 _gtk_css_parser_get_position (parser),
1389 g_error_copy (error));
1393 gtk_css_provider_get_style_property (GtkStyleProvider *provider,
1394 GtkWidgetPath *path,
1395 GtkStateFlags state,
1399 GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider);
1400 GtkCssProviderPrivate *priv = css_provider->priv;
1402 gboolean found = FALSE;
1406 prop_name = g_strdup_printf ("-%s-%s",
1407 g_type_name (pspec->owner_type),
1410 for (i = priv->rulesets->len - 1; i >= 0; i--)
1412 GtkCssRuleset *ruleset;
1413 GtkStateFlags selector_state;
1415 ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
1417 if (ruleset->widget_style == NULL)
1420 if (!gtk_css_ruleset_matches (ruleset, path, gtk_widget_path_length (path)))
1423 selector_state = _gtk_css_selector_get_state_flags (ruleset->selector);
1424 val = g_hash_table_lookup (ruleset->widget_style, prop_name);
1427 (selector_state == 0 ||
1428 selector_state == state ||
1429 ((selector_state & state) != 0 &&
1430 (selector_state & ~(state)) == 0)))
1432 GtkCssParser *parser;
1434 parser = _gtk_css_parser_new (g_value_get_string (val),
1435 gtk_css_provider_parser_error,
1438 found = _gtk_style_property_parse_value (NULL,
1443 _gtk_css_parser_free (parser);
1456 gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface)
1458 iface->get_style = gtk_css_provider_get_style;
1459 iface->get_style_property = gtk_css_provider_get_style_property;
1463 gtk_css_provider_finalize (GObject *object)
1465 GtkCssProvider *css_provider;
1466 GtkCssProviderPrivate *priv;
1469 css_provider = GTK_CSS_PROVIDER (object);
1470 priv = css_provider->priv;
1472 for (i = 0; i < priv->rulesets->len; i++)
1473 gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
1475 g_array_free (priv->rulesets, TRUE);
1477 if (priv->symbolic_colors)
1478 g_hash_table_destroy (priv->symbolic_colors);
1480 G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
1484 * gtk_css_provider_new:
1486 * Returns a newly created #GtkCssProvider.
1488 * Returns: A new #GtkCssProvider
1491 gtk_css_provider_new (void)
1493 return g_object_new (GTK_TYPE_CSS_PROVIDER, NULL);
1497 gtk_css_provider_take_error (GtkCssProvider *provider,
1498 GtkCssScanner *scanner,
1501 gtk_css_provider_take_error_full (provider,
1503 _gtk_css_parser_get_line (scanner->parser),
1504 _gtk_css_parser_get_position (scanner->parser),
1509 gtk_css_provider_error_literal (GtkCssProvider *provider,
1510 GtkCssScanner *scanner,
1513 const char *message)
1515 gtk_css_provider_take_error (provider,
1517 g_error_new_literal (domain, code, message));
1521 gtk_css_provider_error (GtkCssProvider *provider,
1522 GtkCssScanner *scanner,
1526 ...) G_GNUC_PRINTF (5, 6);
1528 gtk_css_provider_error (GtkCssProvider *provider,
1529 GtkCssScanner *scanner,
1538 va_start (args, format);
1539 error = g_error_new_valist (domain, code, format, args);
1542 gtk_css_provider_take_error (provider, scanner, error);
1546 gtk_css_provider_invalid_token (GtkCssProvider *provider,
1547 GtkCssScanner *scanner,
1548 const char *expected)
1550 gtk_css_provider_error (provider,
1552 GTK_CSS_PROVIDER_ERROR,
1553 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1554 "expected a valid %s", expected);
1558 css_provider_commit (GtkCssProvider *css_provider,
1560 GtkCssRuleset *ruleset)
1562 GtkCssProviderPrivate *priv;
1565 priv = css_provider->priv;
1567 if (ruleset->style == NULL && ruleset->widget_style == NULL)
1569 g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
1573 for (l = selectors; l; l = l->next)
1577 gtk_css_ruleset_init_copy (&new, ruleset, l->data);
1579 g_array_append_val (priv->rulesets, new);
1582 g_slist_free (selectors);
1586 gtk_css_provider_reset (GtkCssProvider *css_provider)
1588 GtkCssProviderPrivate *priv;
1591 priv = css_provider->priv;
1593 g_hash_table_remove_all (priv->symbolic_colors);
1595 for (i = 0; i < priv->rulesets->len; i++)
1596 gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
1597 g_array_set_size (priv->rulesets, 0);
1601 gtk_css_provider_propagate_error (GtkCssProvider *provider,
1605 const GError *error,
1606 GError **propagate_to)
1608 /* don't fail for deprecations */
1609 if (g_error_matches (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_DEPRECATED))
1611 g_warning ("Theme parsing error: %s:%u:%u: %s", path ? path : "<unknown>", line, position, error->message);
1615 /* we already set an error. And we'd like to keep the first one */
1619 *propagate_to = g_error_copy (error);
1620 g_prefix_error (propagate_to, "%s:%u:%u: ", path ? path : "<unknown>", line, position);
1624 parse_import (GtkCssScanner *scanner)
1629 uri = _gtk_css_parser_read_uri (scanner->parser);
1632 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1636 file = g_file_resolve_relative_path (gtk_css_scanner_get_base_url (scanner), uri);
1639 if (gtk_css_scanner_would_recurse (scanner, file))
1641 char *path = g_file_get_path (file);
1642 gtk_css_provider_error (scanner->provider,
1644 GTK_CSS_PROVIDER_ERROR,
1645 GTK_CSS_PROVIDER_ERROR_IMPORT,
1646 "Loading '%s' would recurse",
1652 gtk_css_provider_load_internal (scanner->provider,
1659 if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
1661 g_object_unref (file);
1662 gtk_css_provider_invalid_token (scanner->provider, scanner, "semicolon");
1663 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1667 g_object_unref (file);
1671 parse_color_definition (GtkCssScanner *scanner)
1673 GtkSymbolicColor *symbolic;
1676 name = _gtk_css_parser_try_name (scanner->parser, TRUE);
1679 gtk_css_provider_error_literal (scanner->provider,
1681 GTK_CSS_PROVIDER_ERROR,
1682 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1683 "Not a valid color name");
1684 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1688 symbolic = _gtk_css_parser_read_symbolic_color (scanner->parser);
1689 if (symbolic == NULL)
1692 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1696 if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
1699 gtk_symbolic_color_unref (symbolic);
1700 gtk_css_provider_error_literal (scanner->provider,
1702 GTK_CSS_PROVIDER_ERROR,
1703 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1704 "Missing semicolon at end of color definition");
1705 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1709 g_hash_table_insert (scanner->provider->priv->symbolic_colors, name, symbolic);
1713 parse_binding_set (GtkCssScanner *scanner)
1715 GtkBindingSet *binding_set;
1718 name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
1721 gtk_css_provider_error_literal (scanner->provider,
1723 GTK_CSS_PROVIDER_ERROR,
1724 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1725 "Expected name for binding set");
1726 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1727 goto skip_semicolon;
1730 binding_set = gtk_binding_set_find (name);
1733 binding_set = gtk_binding_set_new (name);
1734 binding_set->parsed = TRUE;
1738 if (!_gtk_css_parser_try (scanner->parser, "{", TRUE))
1740 gtk_css_provider_error_literal (scanner->provider,
1742 GTK_CSS_PROVIDER_ERROR,
1743 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1744 "Expected '{' for binding set");
1745 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1746 goto skip_semicolon;
1749 while (!_gtk_css_parser_is_eof (scanner->parser) &&
1750 !_gtk_css_parser_begins_with (scanner->parser, '}'))
1752 name = _gtk_css_parser_read_value (scanner->parser);
1755 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
1759 gtk_binding_entry_add_signal_from_string (binding_set, name);
1762 if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
1764 if (!_gtk_css_parser_begins_with (scanner->parser, '}') &&
1765 !_gtk_css_parser_is_eof (scanner->parser))
1767 gtk_css_provider_error_literal (scanner->provider,
1769 GTK_CSS_PROVIDER_ERROR,
1770 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1771 "Expected semicolon");
1772 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
1777 if (!_gtk_css_parser_try (scanner->parser, "}", TRUE))
1779 gtk_css_provider_error_literal (scanner->provider,
1781 GTK_CSS_PROVIDER_ERROR,
1782 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1783 "expected '}' after declarations");
1784 if (!_gtk_css_parser_is_eof (scanner->parser))
1785 _gtk_css_parser_resync (scanner->parser, FALSE, 0);
1789 if (_gtk_css_parser_try (scanner->parser, ";", TRUE))
1790 gtk_css_provider_error_literal (scanner->provider,
1792 GTK_CSS_PROVIDER_ERROR,
1793 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
1794 "Nonstandard semicolon at end of binding set");
1798 parse_at_keyword (GtkCssScanner *scanner)
1800 if (_gtk_css_parser_try (scanner->parser, "@import", TRUE))
1801 parse_import (scanner);
1802 else if (_gtk_css_parser_try (scanner->parser, "@define-color", TRUE))
1803 parse_color_definition (scanner);
1804 else if (_gtk_css_parser_try (scanner->parser, "@binding-set", TRUE))
1805 parse_binding_set (scanner);
1808 gtk_css_provider_error_literal (scanner->provider,
1810 GTK_CSS_PROVIDER_ERROR,
1811 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1813 _gtk_css_parser_resync (scanner->parser, TRUE, 0);
1818 parse_selector_class (GtkCssScanner *scanner, GArray *classes)
1823 name = _gtk_css_parser_try_name (scanner->parser, FALSE);
1827 gtk_css_provider_error_literal (scanner->provider,
1829 GTK_CSS_PROVIDER_ERROR,
1830 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1831 "Expected a valid name for class");
1835 qname = g_quark_from_string (name);
1836 g_array_append_val (classes, qname);
1842 parse_selector_name (GtkCssScanner *scanner, GArray *names)
1847 name = _gtk_css_parser_try_name (scanner->parser, FALSE);
1851 gtk_css_provider_error_literal (scanner->provider,
1853 GTK_CSS_PROVIDER_ERROR,
1854 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1855 "Expected a valid name for id");
1859 qname = g_quark_from_string (name);
1860 g_array_append_val (names, qname);
1866 parse_selector_pseudo_class (GtkCssScanner *scanner,
1867 GtkRegionFlags *region_to_modify,
1868 GtkStateFlags *state_to_modify)
1872 GtkRegionFlags region_flag;
1873 GtkStateFlags state_flag;
1874 } pseudo_classes[] = {
1875 { "first", GTK_REGION_FIRST, 0 },
1876 { "last", GTK_REGION_LAST, 0 },
1877 { "sorted", GTK_REGION_SORTED, 0 },
1878 { "active", 0, GTK_STATE_FLAG_ACTIVE },
1879 { "prelight", 0, GTK_STATE_FLAG_PRELIGHT },
1880 { "hover", 0, GTK_STATE_FLAG_PRELIGHT },
1881 { "selected", 0, GTK_STATE_FLAG_SELECTED },
1882 { "insensitive", 0, GTK_STATE_FLAG_INSENSITIVE },
1883 { "inconsistent", 0, GTK_STATE_FLAG_INCONSISTENT },
1884 { "focused", 0, GTK_STATE_FLAG_FOCUSED },
1885 { "focus", 0, GTK_STATE_FLAG_FOCUSED },
1887 }, nth_child_classes[] = {
1888 { "first", GTK_REGION_FIRST, 0 },
1889 { "last", GTK_REGION_LAST, 0 },
1890 { "even", GTK_REGION_EVEN, 0 },
1891 { "odd", GTK_REGION_ODD, 0 },
1897 name = _gtk_css_parser_try_ident (scanner->parser, FALSE);
1900 gtk_css_provider_error_literal (scanner->provider,
1902 GTK_CSS_PROVIDER_ERROR,
1903 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1904 "Missing name of pseudo-class");
1908 if (_gtk_css_parser_try (scanner->parser, "(", TRUE))
1910 char *function = name;
1912 name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
1913 if (!_gtk_css_parser_try (scanner->parser, ")", FALSE))
1915 gtk_css_provider_error_literal (scanner->provider,
1917 GTK_CSS_PROVIDER_ERROR,
1918 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1919 "Missing closing bracket for pseudo-class");
1923 if (g_ascii_strcasecmp (function, "nth-child") != 0)
1925 gtk_css_provider_error (scanner->provider,
1927 GTK_CSS_PROVIDER_ERROR,
1928 GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
1929 "Unknown pseudo-class '%s(%s)'", function, name ? name : "");
1939 gtk_css_provider_error (scanner->provider,
1941 GTK_CSS_PROVIDER_ERROR,
1942 GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
1943 "nth-child() requires an argument");
1947 classes = nth_child_classes;
1950 classes = pseudo_classes;
1952 for (i = 0; classes[i].name != NULL; i++)
1954 if (g_ascii_strcasecmp (name, classes[i].name) == 0)
1956 if ((*region_to_modify & classes[i].region_flag) ||
1957 (*state_to_modify & classes[i].state_flag))
1959 if (classes == nth_child_classes)
1960 gtk_css_provider_error (scanner->provider,
1962 GTK_CSS_PROVIDER_ERROR,
1963 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1964 "Duplicate pseudo-class 'nth-child(%s)'", name);
1966 gtk_css_provider_error (scanner->provider,
1968 GTK_CSS_PROVIDER_ERROR,
1969 GTK_CSS_PROVIDER_ERROR_SYNTAX,
1970 "Duplicate pseudo-class '%s'", name);
1972 *region_to_modify |= classes[i].region_flag;
1973 *state_to_modify |= classes[i].state_flag;
1980 if (classes == nth_child_classes)
1981 gtk_css_provider_error (scanner->provider,
1983 GTK_CSS_PROVIDER_ERROR,
1984 GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
1985 "Unknown pseudo-class 'nth-child(%s)'", name);
1987 gtk_css_provider_error (scanner->provider,
1989 GTK_CSS_PROVIDER_ERROR,
1990 GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
1991 "Unknown pseudo-class '%s'", name);
1997 parse_simple_selector (GtkCssScanner *scanner,
2001 GtkRegionFlags *pseudo_classes,
2002 GtkStateFlags *state)
2004 gboolean parsed_something;
2006 *name = _gtk_css_parser_try_ident (scanner->parser, FALSE);
2008 parsed_something = TRUE;
2010 parsed_something = _gtk_css_parser_try (scanner->parser, "*", FALSE);
2013 if (_gtk_css_parser_try (scanner->parser, "#", FALSE))
2015 if (!parse_selector_name (scanner, ids))
2018 else if (_gtk_css_parser_try (scanner->parser, ".", FALSE))
2020 if (!parse_selector_class (scanner, classes))
2023 else if (_gtk_css_parser_try (scanner->parser, ":", FALSE))
2025 if (!parse_selector_pseudo_class (scanner, pseudo_classes, state))
2028 else if (!parsed_something)
2030 gtk_css_provider_error_literal (scanner->provider,
2032 GTK_CSS_PROVIDER_ERROR,
2033 GTK_CSS_PROVIDER_ERROR_SYNTAX,
2034 "Expected a valid selector");
2040 parsed_something = TRUE;
2042 while (!_gtk_css_parser_is_eof (scanner->parser));
2044 _gtk_css_parser_skip_whitespace (scanner->parser);
2048 static GtkCssSelector *
2049 parse_selector (GtkCssScanner *scanner)
2051 GtkCssSelector *selector = NULL;
2055 GArray *ids = g_array_new (TRUE, FALSE, sizeof (GQuark));
2056 GArray *classes = g_array_new (TRUE, FALSE, sizeof (GQuark));
2057 GtkRegionFlags pseudo_classes = 0;
2058 GtkStateFlags state = 0;
2059 GtkCssCombinator combine = GTK_CSS_COMBINE_DESCANDANT;
2063 if (_gtk_css_parser_try (scanner->parser, ">", TRUE))
2064 combine = GTK_CSS_COMBINE_CHILD;
2067 if (!parse_simple_selector (scanner, &name, ids, classes, &pseudo_classes, &state))
2069 g_array_free (ids, TRUE);
2070 g_array_free (classes, TRUE);
2072 _gtk_css_selector_free (selector);
2076 selector = _gtk_css_selector_new (selector,
2079 (GQuark *) g_array_free (ids, ids->len == 0),
2080 (GQuark *) g_array_free (classes, classes->len == 0),
2085 while (!_gtk_css_parser_is_eof (scanner->parser) &&
2086 !_gtk_css_parser_begins_with (scanner->parser, ',') &&
2087 !_gtk_css_parser_begins_with (scanner->parser, '{'));
2093 parse_selector_list (GtkCssScanner *scanner)
2095 GSList *selectors = NULL;
2098 GtkCssSelector *select = parse_selector (scanner);
2102 g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
2103 _gtk_css_parser_resync (scanner->parser, FALSE, 0);
2107 selectors = g_slist_prepend (selectors, select);
2109 while (_gtk_css_parser_try (scanner->parser, ",", TRUE));
2115 parse_declaration (GtkCssScanner *scanner,
2116 GtkCssRuleset *ruleset)
2118 const GtkStyleProperty *property;
2121 name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
2123 goto check_for_semicolon;
2125 property = _gtk_style_property_lookup (name);
2126 if (property == NULL && name[0] != '-')
2128 gtk_css_provider_error (scanner->provider,
2130 GTK_CSS_PROVIDER_ERROR,
2131 GTK_CSS_PROVIDER_ERROR_NAME,
2132 "'%s' is not a valid property name",
2134 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2139 if (!_gtk_css_parser_try (scanner->parser, ":", TRUE))
2141 gtk_css_provider_invalid_token (scanner->provider, scanner, "':'");
2142 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2153 val = g_slice_new0 (GValue);
2154 g_value_init (val, property->pspec->value_type);
2156 if (_gtk_style_property_parse_value (property,
2159 gtk_css_scanner_get_base_url (scanner)))
2161 if (_gtk_css_parser_begins_with (scanner->parser, ';') ||
2162 _gtk_css_parser_begins_with (scanner->parser, '}') ||
2163 _gtk_css_parser_is_eof (scanner->parser))
2165 gtk_css_ruleset_add (ruleset, property, val);
2169 gtk_css_provider_error_literal (scanner->provider,
2171 GTK_CSS_PROVIDER_ERROR,
2172 GTK_CSS_PROVIDER_ERROR_SYNTAX,
2173 "Junk at end of value");
2174 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2175 g_value_unset (val);
2176 g_slice_free (GValue, val);
2182 g_value_unset (val);
2183 g_slice_free (GValue, val);
2184 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2188 else if (name[0] == '-')
2192 value_str = _gtk_css_parser_read_value (scanner->parser);
2197 val = g_slice_new0 (GValue);
2198 g_value_init (val, G_TYPE_STRING);
2199 g_value_take_string (val, value_str);
2201 gtk_css_ruleset_add_style (ruleset, name, val);
2205 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2212 check_for_semicolon:
2213 if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
2215 if (!_gtk_css_parser_begins_with (scanner->parser, '}') &&
2216 !_gtk_css_parser_is_eof (scanner->parser))
2218 gtk_css_provider_error_literal (scanner->provider,
2220 GTK_CSS_PROVIDER_ERROR,
2221 GTK_CSS_PROVIDER_ERROR_SYNTAX,
2222 "Expected semicolon");
2223 _gtk_css_parser_resync (scanner->parser, TRUE, '}');
2229 parse_declarations (GtkCssScanner *scanner,
2230 GtkCssRuleset *ruleset)
2232 while (!_gtk_css_parser_is_eof (scanner->parser) &&
2233 !_gtk_css_parser_begins_with (scanner->parser, '}'))
2235 parse_declaration (scanner, ruleset);
2240 parse_ruleset (GtkCssScanner *scanner)
2243 GtkCssRuleset ruleset = { 0, };
2245 selectors = parse_selector_list (scanner);
2246 if (selectors == NULL)
2249 if (!_gtk_css_parser_try (scanner->parser, "{", TRUE))
2251 gtk_css_provider_error_literal (scanner->provider,
2253 GTK_CSS_PROVIDER_ERROR,
2254 GTK_CSS_PROVIDER_ERROR_SYNTAX,
2255 "expected '{' after selectors");
2256 _gtk_css_parser_resync (scanner->parser, FALSE, 0);
2257 g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
2261 parse_declarations (scanner, &ruleset);
2263 if (!_gtk_css_parser_try (scanner->parser, "}", TRUE))
2265 gtk_css_provider_error_literal (scanner->provider,
2267 GTK_CSS_PROVIDER_ERROR,
2268 GTK_CSS_PROVIDER_ERROR_SYNTAX,
2269 "expected '}' after declarations");
2270 if (!_gtk_css_parser_is_eof (scanner->parser))
2272 _gtk_css_parser_resync (scanner->parser, FALSE, 0);
2273 g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
2274 gtk_css_ruleset_clear (&ruleset);
2279 css_provider_commit (scanner->provider, selectors, &ruleset);
2280 gtk_css_ruleset_clear (&ruleset);
2284 parse_statement (GtkCssScanner *scanner)
2286 if (_gtk_css_parser_begins_with (scanner->parser, '@'))
2287 parse_at_keyword (scanner);
2289 parse_ruleset (scanner);
2293 parse_stylesheet (GtkCssScanner *scanner)
2295 _gtk_css_parser_skip_whitespace (scanner->parser);
2297 while (!_gtk_css_parser_is_eof (scanner->parser))
2299 if (_gtk_css_parser_try (scanner->parser, "<!--", TRUE) ||
2300 _gtk_css_parser_try (scanner->parser, "-->", TRUE))
2303 parse_statement (scanner);
2308 gtk_css_provider_compare_rule (gconstpointer a_,
2311 const GtkCssRuleset *a = (const GtkCssRuleset *) a_;
2312 const GtkCssRuleset *b = (const GtkCssRuleset *) b_;
2315 compare = _gtk_css_selector_compare (a->selector, b->selector);
2319 /* compare pointers in array to ensure a stable sort */
2330 gtk_css_provider_postprocess (GtkCssProvider *css_provider)
2332 GtkCssProviderPrivate *priv = css_provider->priv;
2334 g_array_sort (priv->rulesets, gtk_css_provider_compare_rule);
2338 gtk_css_provider_load_internal (GtkCssProvider *css_provider,
2339 GtkCssScanner *parent,
2345 GtkCssScanner *scanner;
2346 gulong error_handler;
2347 char *free_data = NULL;
2350 error_handler = g_signal_connect (css_provider,
2352 G_CALLBACK (gtk_css_provider_propagate_error),
2355 error_handler = 0; /* silence gcc */
2359 GError *load_error = NULL;
2361 if (g_file_load_contents (file, NULL,
2362 &free_data, &length,
2371 gtk_css_provider_error (css_provider,
2373 GTK_CSS_PROVIDER_ERROR,
2374 GTK_CSS_PROVIDER_ERROR_IMPORT,
2375 "Failed to import: %s",
2376 load_error->message);
2377 g_error_free (load_error);
2381 gtk_css_provider_take_error_full (css_provider,
2391 scanner = gtk_css_scanner_new (css_provider, parent, file, data, length);
2393 parse_stylesheet (scanner);
2395 gtk_css_scanner_destroy (scanner);
2398 gtk_css_provider_postprocess (css_provider);
2405 g_signal_handler_disconnect (css_provider, error_handler);
2409 /* We clear all contents from the provider for backwards compat reasons */
2410 gtk_css_provider_reset (css_provider);
2419 * gtk_css_provider_load_from_data:
2420 * @css_provider: a #GtkCssProvider
2421 * @data: (array length=length) (element-type guint8): CSS data loaded in memory
2422 * @length: the length of @data in bytes, or -1 for NUL terminated strings
2423 * @error: (out) (allow-none): return location for a #GError, or %NULL
2425 * Loads @data into @css_provider, making it clear any previously loaded
2428 * Returns: %TRUE if the data could be loaded.
2431 gtk_css_provider_load_from_data (GtkCssProvider *css_provider,
2436 g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
2437 g_return_val_if_fail (data != NULL, FALSE);
2440 length = strlen (data);
2442 gtk_css_provider_reset (css_provider);
2444 return gtk_css_provider_load_internal (css_provider, NULL, NULL, data, length, error);
2448 * gtk_css_provider_load_from_file:
2449 * @css_provider: a #GtkCssProvider
2450 * @file: #GFile pointing to a file to load
2451 * @error: (out) (allow-none): return location for a #GError, or %NULL
2453 * Loads the data contained in @file into @css_provider, making it
2454 * clear any previously loaded information.
2456 * Returns: %TRUE if the data could be loaded.
2459 gtk_css_provider_load_from_file (GtkCssProvider *css_provider,
2463 g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
2464 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2466 gtk_css_provider_reset (css_provider);
2468 return gtk_css_provider_load_internal (css_provider, NULL, file, NULL, 0, error);
2472 * gtk_css_provider_load_from_path:
2473 * @css_provider: a #GtkCssProvider
2474 * @path: the path of a filename to load, in the GLib filename encoding
2475 * @error: (out) (allow-none): return location for a #GError, or %NULL
2477 * Loads the data contained in @path into @css_provider, making it clear
2478 * any previously loaded information.
2480 * Returns: %TRUE if the data could be loaded.
2483 gtk_css_provider_load_from_path (GtkCssProvider *css_provider,
2490 g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
2491 g_return_val_if_fail (path != NULL, FALSE);
2493 file = g_file_new_for_path (path);
2495 result = gtk_css_provider_load_from_file (css_provider, file, error);
2497 g_object_unref (file);
2503 * gtk_css_provider_get_default:
2505 * Returns the provider containing the style settings used as a
2506 * fallback for all widgets.
2508 * Returns: (transfer none): The provider used for fallback styling.
2509 * This memory is owned by GTK+, and you must not free it.
2512 gtk_css_provider_get_default (void)
2514 static GtkCssProvider *provider;
2516 if (G_UNLIKELY (!provider))
2519 "@define-color fg_color #000; \n"
2520 "@define-color bg_color #dcdad5; \n"
2521 "@define-color text_color #000; \n"
2522 "@define-color base_color #fff; \n"
2523 "@define-color selected_bg_color #4b6983; \n"
2524 "@define-color selected_fg_color #fff; \n"
2525 "@define-color tooltip_bg_color #eee1b3; \n"
2526 "@define-color tooltip_fg_color #000; \n"
2527 "@define-color placeholder_text_color #808080; \n"
2529 "@define-color info_fg_color rgb (181, 171, 156);\n"
2530 "@define-color info_bg_color rgb (252, 252, 189);\n"
2531 "@define-color warning_fg_color rgb (173, 120, 41);\n"
2532 "@define-color warning_bg_color rgb (250, 173, 61);\n"
2533 "@define-color question_fg_color rgb (97, 122, 214);\n"
2534 "@define-color question_bg_color rgb (138, 173, 212);\n"
2535 "@define-color error_fg_color rgb (166, 38, 38);\n"
2536 "@define-color error_bg_color rgb (237, 54, 54);\n"
2539 " background-color: @bg_color;\n"
2540 " color: @fg_color;\n"
2541 " border-color: shade (@bg_color, 0.6);\n"
2543 " border-width: 0;\n"
2547 " background-color: shade (@bg_color, 1.05);\n"
2548 " color: shade (@fg_color, 1.3);\n"
2552 " background-color: @selected_bg_color;\n"
2553 " color: @selected_fg_color;\n"
2556 ".expander, GtkTreeView.view.expander {\n"
2560 ".expander:prelight,\n"
2561 "GtkTreeView.view.expander:selected:prelight {\n"
2562 " color: @text_color;\n"
2565 ".expander:active {\n"
2566 " transition: 200ms linear;\n"
2570 " border-color: shade (@bg_color, 0.7);\n"
2571 " background-color: shade (@bg_color, 0.9);\n"
2572 " color: shade (@bg_color, 0.7);\n"
2576 " border-width: 0;\n"
2577 " border-radius: 0;\n"
2578 " background-color: @base_color;\n"
2579 " color: @text_color;\n"
2581 ".view:selected {\n"
2582 " background-color: shade (@bg_color, 0.9);\n"
2583 " color: @fg_color;\n"
2586 ".view:selected:focused {\n"
2587 " background-color: @selected_bg_color;\n"
2588 " color: @selected_fg_color;\n"
2591 ".view column:sorted row,\n"
2592 ".view column:sorted row:prelight {\n"
2593 " background-color: shade (@bg_color, 0.85);\n"
2596 ".view column:sorted row:nth-child(odd),\n"
2597 ".view column:sorted row:nth-child(odd):prelight {\n"
2598 " background-color: shade (@bg_color, 0.8);\n"
2602 ".view row:prelight {\n"
2603 " background-color: @base_color;\n"
2604 " color: @text_color;\n"
2607 ".view row:nth-child(odd),\n"
2608 ".view row:nth-child(odd):prelight {\n"
2609 " background-color: shade (@base_color, 0.93); \n"
2612 ".view row:selected:focused {\n"
2613 " background-color: @selected_bg_color;\n"
2616 ".view row:selected {\n"
2617 " background-color: darker (@bg_color);\n"
2618 " color: @selected_fg_color;\n"
2621 ".view.cell.trough,\n"
2622 ".view.cell.trough:hover,\n"
2623 ".view.cell.trough:selected,\n"
2624 ".view.cell.trough:selected:focused {\n"
2625 " background-color: @bg_color;\n"
2626 " color: @fg_color;\n"
2629 ".view.cell.progressbar,\n"
2630 ".view.cell.progressbar:hover,\n"
2631 ".view.cell.progressbar:selected,\n"
2632 ".view.cell.progressbar:selected:focused {\n"
2633 " background-color: @selected_bg_color;\n"
2634 " color: @selected_fg_color;\n"
2638 " background-color: alpha (@fg_color, 0.25);\n"
2639 " border-color: @fg_color;\n"
2640 " border-style: solid;\n"
2641 " border-width: 1;\n"
2645 " background-color: @tooltip_bg_color; \n"
2646 " color: @tooltip_fg_color; \n"
2647 " border-color: @tooltip_fg_color; \n"
2648 " border-width: 1;\n"
2649 " border-style: solid;\n"
2654 " border-style: outset; \n"
2655 " border-width: 2; \n"
2658 ".button:active {\n"
2659 " background-color: shade (@bg_color, 0.7);\n"
2660 " border-style: inset; \n"
2663 ".button:prelight,\n"
2664 ".slider:prelight {\n"
2665 " background-color: @selected_bg_color;\n"
2666 " color: @selected_fg_color;\n"
2667 " border-color: shade (@selected_bg_color, 0.7);\n"
2671 " background-color: darker (@bg_color);\n"
2672 " border-style: inset;\n"
2673 " border-width: 1;\n"
2678 " border-style: inset;\n"
2679 " border-width: 2;\n"
2680 " background-color: @base_color;\n"
2681 " color: @text_color;\n"
2684 ".entry:insensitive {\n"
2685 " background-color: shade (@base_color, 0.9);\n"
2686 " color: shade (@base_color, 0.7);\n"
2689 " background-color: #c4c2bd;\n"
2694 ".entry.progressbar, \n"
2695 ".cell.progressbar {\n"
2696 " background-color: @selected_bg_color;\n"
2697 " border-color: shade (@selected_bg_color, 0.7);\n"
2698 " color: @selected_fg_color;\n"
2699 " border-style: outset;\n"
2700 " border-width: 1;\n"
2703 "GtkCheckButton:hover,\n"
2704 "GtkCheckButton:selected,\n"
2705 "GtkRadioButton:hover,\n"
2706 "GtkRadioButton:selected {\n"
2707 " background-color: shade (@bg_color, 1.05);\n"
2711 ".cell.check, .cell.radio,\n"
2712 ".cell.check:hover, .cell.radio:hover {\n"
2713 " border-style: solid;\n"
2714 " border-width: 1;\n"
2715 " background-color: @base_color;\n"
2716 " border-color: @fg_color;\n"
2719 ".check:active, .radio:active,\n"
2720 ".check:hover, .radio:hover {\n"
2721 " background-color: @base_color;\n"
2722 " border-color: @fg_color;\n"
2723 " color: @text_color;\n"
2726 ".check:selected, .radio:selected {\n"
2727 " background-color: darker (@bg_color);\n"
2728 " color: @selected_fg_color;\n"
2729 " border-color: @selected_fg_color;\n"
2732 ".check:selected:focused, .radio:selected:focused {\n"
2733 " background-color: @selected_bg_color;\n"
2736 ".menu.check, .menu.radio {\n"
2737 " color: @fg_color;\n"
2738 " border-style: none;\n"
2739 " border-width: 0;\n"
2743 " border-style: outset;\n"
2744 " border-width: 1;\n"
2748 " border-style: inset;\n"
2749 " border-width: 2;\n"
2753 " border-style: outset;\n"
2754 " border-width: 1;\n"
2758 " border-style: inset;\n"
2759 " border-width: 1;\n"
2762 "GtkScrolledWindow.frame {\n"
2769 " border-style: outset;\n"
2770 " border-width: 1;\n"
2775 ".menu.check:hover,\n"
2776 ".menu.radio:hover {\n"
2777 " background-color: @selected_bg_color;\n"
2778 " color: @selected_fg_color;\n"
2781 "GtkSpinButton.button {\n"
2782 " border-width: 1;\n"
2785 ".scale.slider:hover,\n"
2786 "GtkSpinButton.button:hover {\n"
2787 " background-color: shade (@bg_color, 1.05);\n"
2788 " border-color: shade (@bg_color, 0.8);\n"
2791 "GtkSwitch.trough:active {\n"
2792 " background-color: @selected_bg_color;\n"
2793 " color: @selected_fg_color;\n"
2796 "GtkToggleButton.button:inconsistent {\n"
2797 " border-style: outset;\n"
2798 " border-width: 1px;\n"
2799 " background-color: shade (@bg_color, 0.9);\n"
2800 " border-color: shade (@bg_color, 0.7);\n"
2803 "GtkLabel:selected {\n"
2804 " background-color: shade (@bg_color, 0.9);\n"
2807 "GtkLabel:selected:focused {\n"
2808 " background-color: @selected_bg_color;\n"
2811 ".spinner:active {\n"
2812 " transition: 750ms linear loop;\n"
2816 " background-color: @info_bg_color;\n"
2817 " color: @info_fg_color;\n"
2821 " background-color: @warning_bg_color;\n"
2822 " color: @warning_fg_color;\n"
2826 " background-color: @question_bg_color;\n"
2827 " color: @question_fg_color;\n"
2831 " background-color: @error_bg_color;\n"
2832 " color: @error_fg_color;\n"
2836 " background-color: @selected_bg_color;\n"
2837 " color: @selected_fg_color;\n"
2840 ".light-area-focus {\n"
2844 ".dark-area-focus {\n"
2847 "GtkCalendar.view {\n"
2848 " border-width: 1;\n"
2849 " border-style: inset;\n"
2853 "GtkCalendar.view:inconsistent {\n"
2854 " color: darker (@bg_color);\n"
2857 "GtkCalendar.header {\n"
2858 " background-color: @bg_color;\n"
2859 " border-style: outset;\n"
2860 " border-width: 2;\n"
2863 "GtkCalendar.highlight {\n"
2864 " border-width: 0;\n"
2867 "GtkCalendar.button {\n"
2868 " background-color: @bg_color;\n"
2871 "GtkCalendar.button:hover {\n"
2872 " background-color: lighter (@bg_color);\n"
2873 " color: @fg_color;\n"
2877 " border-width: 0;\n"
2882 provider = gtk_css_provider_new ();
2883 if (!gtk_css_provider_load_from_data (provider, str, -1, NULL))
2885 g_error ("Failed to load the internal default CSS.");
2893 _gtk_css_provider_get_theme_dir (void)
2898 var = g_getenv ("GTK_DATA_PREFIX");
2901 path = g_build_filename (var, "share", "themes", NULL);
2903 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
2909 * gtk_css_provider_get_named:
2910 * @name: A theme name
2911 * @variant: (allow-none): variant to load, for example, "dark", or
2912 * %NULL for the default
2914 * Loads a theme from the usual theme paths
2916 * Returns: (transfer none): a #GtkCssProvider with the theme loaded.
2917 * This memory is owned by GTK+, and you must not free it.
2920 gtk_css_provider_get_named (const gchar *name,
2921 const gchar *variant)
2923 static GHashTable *themes = NULL;
2924 GtkCssProvider *provider;
2927 if (G_UNLIKELY (!themes))
2928 themes = g_hash_table_new (g_str_hash, g_str_equal);
2930 if (variant == NULL)
2931 key = (gchar *)name;
2933 key = g_strconcat (name, "-", variant, NULL);
2935 provider = g_hash_table_lookup (themes, key);
2939 const gchar *home_dir;
2940 gchar *subpath, *path = NULL;
2943 subpath = g_strdup_printf ("gtk-3.0" G_DIR_SEPARATOR_S "gtk-%s.css", variant);
2945 subpath = g_strdup ("gtk-3.0" G_DIR_SEPARATOR_S "gtk.css");
2947 /* First look in the users home directory
2949 home_dir = g_get_home_dir ();
2952 path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
2954 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2965 theme_dir = _gtk_css_provider_get_theme_dir ();
2966 path = g_build_filename (theme_dir, name, subpath, NULL);
2969 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2980 provider = gtk_css_provider_new ();
2982 if (!gtk_css_provider_load_from_path (provider, path, NULL))
2984 g_object_unref (provider);
2988 g_hash_table_insert (themes, g_strdup (key), provider);
3001 compare_properties (gconstpointer a, gconstpointer b)
3003 return strcmp (((const GtkStyleProperty *) a)->pspec->name,
3004 ((const GtkStyleProperty *) b)->pspec->name);
3008 gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
3013 _gtk_css_selector_print (ruleset->selector, str);
3015 g_string_append (str, " {\n");
3019 keys = g_hash_table_get_keys (ruleset->style);
3020 /* so the output is identical for identical selector styles */
3021 keys = g_list_sort (keys, compare_properties);
3023 for (walk = keys; walk; walk = walk->next)
3025 GtkStyleProperty *prop = walk->data;
3026 const GValue *value = g_hash_table_lookup (ruleset->style, prop);
3028 g_string_append (str, " ");
3029 g_string_append (str, prop->pspec->name);
3030 g_string_append (str, ": ");
3031 _gtk_style_property_print_value (prop, value, str);
3032 g_string_append (str, ";\n");
3038 if (ruleset->widget_style)
3040 keys = g_hash_table_get_keys (ruleset->widget_style);
3041 /* so the output is identical for identical selector styles */
3042 keys = g_list_sort (keys, (GCompareFunc) strcmp);
3044 for (walk = keys; walk; walk = walk->next)
3046 const char *name = walk->data;
3047 const GValue *value = g_hash_table_lookup (ruleset->widget_style, (gpointer) name);
3049 g_string_append (str, " ");
3050 g_string_append (str, name);
3051 g_string_append (str, ": ");
3052 g_string_append (str, g_value_get_string (value));
3053 g_string_append (str, ";\n");
3059 g_string_append (str, "}\n");
3063 gtk_css_provider_print_colors (GHashTable *colors,
3069 keys = g_hash_table_get_keys (colors);
3070 /* so the output is identical for identical styles */
3071 keys = g_list_sort (keys, (GCompareFunc) strcmp);
3073 for (walk = keys; walk; walk = walk->next)
3075 const char *name = walk->data;
3076 GtkSymbolicColor *symbolic = g_hash_table_lookup (colors, (gpointer) name);
3078 g_string_append (str, "@define-color ");
3079 g_string_append (str, name);
3080 g_string_append (str, " ");
3081 s = gtk_symbolic_color_to_string (symbolic);
3082 g_string_append (str, s);
3084 g_string_append (str, ";\n");
3091 * gtk_css_provider_to_string:
3092 * @provider: the provider to write to a string
3094 * Convertes the @provider into a string representation in CSS
3097 * Using gtk_css_provider_load_from_data() with the return value
3098 * from this function on a new provider created with
3099 * gtk_css_provider_new() will basicallu create a duplicate of
3102 * Returns: a new string representing the @provider.
3105 gtk_css_provider_to_string (GtkCssProvider *provider)
3107 GtkCssProviderPrivate *priv;
3111 g_return_val_if_fail (GTK_IS_CSS_PROVIDER (provider), NULL);
3113 priv = provider->priv;
3115 str = g_string_new ("");
3117 gtk_css_provider_print_colors (priv->symbolic_colors, str);
3119 for (i = 0; i < priv->rulesets->len; i++)
3122 g_string_append (str, "\n");
3123 gtk_css_ruleset_print (&g_array_index (priv->rulesets, GtkCssRuleset, i), str);
3126 return g_string_free (str, FALSE);