2010-04-11 21:03:25 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2011-01-23 23:29:07 +00:00
|
|
|
|
2010-09-24 20:05:20 +00:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2010-11-12 20:43:13 +00:00
|
|
|
#include <cairo-gobject.h>
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-01-26 16:17:34 +00:00
|
|
|
#include "gtkcssproviderprivate.h"
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
#include "gtkcssparserprivate.h"
|
2011-06-17 00:02:24 +00:00
|
|
|
#include "gtkcsssectionprivate.h"
|
2011-05-14 11:27:31 +00:00
|
|
|
#include "gtkcssselectorprivate.h"
|
2011-04-08 14:08:28 +00:00
|
|
|
#include "gtksymboliccolor.h"
|
2011-01-23 23:29:07 +00:00
|
|
|
#include "gtkstyleprovider.h"
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2011-05-16 21:37:29 +00:00
|
|
|
#include "gtkstylepropertiesprivate.h"
|
2011-05-21 01:30:36 +00:00
|
|
|
#include "gtkstylepropertyprivate.h"
|
2011-01-28 00:52:03 +00:00
|
|
|
#include "gtkbindings.h"
|
2011-04-07 15:26:47 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2011-01-02 11:11:34 +00:00
|
|
|
#include "gtkprivate.h"
|
2011-04-07 15:26:47 +00:00
|
|
|
#include "gtkintl.h"
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkcssprovider
|
|
|
|
* @Short_description: CSS-like styling for widgets
|
|
|
|
* @Title: GtkCssProvider
|
|
|
|
* @See_also: #GtkStyleContext, #GtkStyleProvider
|
|
|
|
*
|
2010-11-26 01:39:53 +00:00
|
|
|
* GtkCssProvider is an object implementing the #GtkStyleProvider interface.
|
|
|
|
* It is able to parse <ulink url="http://www.w3.org/TR/CSS2">CSS</ulink>-like
|
|
|
|
* input in order to style widgets.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-11-20 05:22:29 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-files">
|
|
|
|
* <title>Default files</title>
|
|
|
|
* <para>
|
|
|
|
* An application can cause GTK+ to parse a specific CSS style sheet by
|
|
|
|
* calling gtk_css_provider_load_from_file() and adding the provider with
|
|
|
|
* gtk_style_context_add_provider() or gtk_style_context_add_provider_for_screen().
|
|
|
|
* In addition, certain files will be read when GTK+ is initialized. First,
|
2010-12-20 15:19:55 +00:00
|
|
|
* the file <filename><envar>$XDG_CONFIG_HOME</envar>/gtk-3.0/gtk.css</filename>
|
2010-11-20 05:22:29 +00:00
|
|
|
* is loaded if it exists. Then, GTK+ tries to load
|
2010-12-20 15:19:55 +00:00
|
|
|
* <filename><envar>$HOME</envar>/.themes/<replaceable>theme-name</replaceable>/gtk-3.0/gtk.css</filename>,
|
2010-11-20 05:22:29 +00:00
|
|
|
* falling back to
|
2010-12-20 15:19:55 +00:00
|
|
|
* <filename><replaceable>datadir</replaceable>/share/themes/<replaceable>theme-name</replaceable>/gtk-3.0/gtk.css</filename>,
|
2010-11-20 05:22:29 +00:00
|
|
|
* where <replaceable>theme-name</replaceable> is the name of the current theme
|
2010-12-21 23:15:43 +00:00
|
|
|
* (see the #GtkSettings:gtk-theme-name setting) and <replaceable>datadir</replaceable>
|
2010-11-20 05:22:29 +00:00
|
|
|
* is the prefix configured when GTK+ was compiled, unless overridden by the
|
|
|
|
* <envar>GTK_DATA_PREFIX</envar> environment variable.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
* <refsect2 id="gtkcssprovider-stylesheets">
|
|
|
|
* <title>Style sheets</title>
|
|
|
|
* <para>
|
|
|
|
* The basic structure of the style sheets understood by this provider is
|
|
|
|
* a series of statements, which are either rule sets or '@-rules', separated
|
|
|
|
* by whitespace.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* A rule set consists of a selector and a declaration block, which is
|
|
|
|
* a series of declarations enclosed in curly braces ({ and }). The
|
|
|
|
* declarations are separated by semicolons (;). Multiple selectors can
|
|
|
|
* share the same declaration block, by putting all the separators in
|
|
|
|
* front of the block, separated by commas.
|
|
|
|
* </para>
|
|
|
|
* <example><title>A rule set with two selectors</title>
|
|
|
|
* <programlisting language="text">
|
|
|
|
* GtkButton, GtkEntry {
|
|
|
|
* color: #ff00ea;
|
|
|
|
* font: Comic Sans 12
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* </refsect2>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-selectors">
|
2010-11-20 05:22:29 +00:00
|
|
|
* <title>Selectors</title>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* Selectors work very similar to the way they do in CSS, with widget class
|
|
|
|
* names taking the role of element names, and widget names taking the role
|
|
|
|
* of IDs. When used in a selector, widget names must be prefixed with a
|
|
|
|
* '#' character. The '*' character represents the so-called universal
|
|
|
|
* selector, which matches any widget.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* To express more complicated situations, selectors can be combined in
|
|
|
|
* various ways:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><para>To require that a widget satisfies several conditions,
|
|
|
|
* combine several selectors into one by concatenating them. E.g.
|
|
|
|
* <literal>GtkButton#button1</literal> matches a GtkButton widget
|
|
|
|
* with the name button1.</para></listitem>
|
|
|
|
* <listitem><para>To only match a widget when it occurs inside some other
|
|
|
|
* widget, write the two selectors after each other, separated by whitespace.
|
|
|
|
* E.g. <literal>GtkToolBar GtkButton</literal> matches GtkButton widgets
|
|
|
|
* that occur inside a GtkToolBar.</para></listitem>
|
|
|
|
* <listitem><para>In the previous example, the GtkButton is matched even
|
|
|
|
* if it occurs deeply nested inside the toolbar. To restrict the match
|
|
|
|
* to direct children of the parent widget, insert a '>' character between
|
|
|
|
* the two selectors. E.g. <literal>GtkNotebook > GtkLabel</literal> matches
|
|
|
|
* GtkLabel widgets that are direct children of a GtkNotebook.</para></listitem>
|
|
|
|
* </itemizedlist>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <title>Widget classes and names in selectors</title>
|
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* /* Theme labels that are descendants of a window */
|
|
|
|
* GtkWindow GtkLabel {
|
2010-11-18 23:36:08 +00:00
|
|
|
* background-color: #898989
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme notebooks, and anything that's within these */
|
|
|
|
* GtkNotebook {
|
2010-11-18 23:36:08 +00:00
|
|
|
* background-color: #a939f0
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme combo boxes, and entries that
|
|
|
|
* are direct children of a notebook */
|
|
|
|
* GtkComboBox,
|
|
|
|
* GtkNotebook > GtkEntry {
|
2010-11-18 23:36:08 +00:00
|
|
|
* color: @fg_color;
|
|
|
|
* background-color: #1209a2
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme any widget within a GtkBin */
|
|
|
|
* GtkBin * {
|
2011-06-01 23:55:45 +00:00
|
|
|
* font: Sans 20
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
2010-11-20 05:22:29 +00:00
|
|
|
*
|
2010-10-19 08:59:46 +00:00
|
|
|
* /* Theme a label named title-label */
|
|
|
|
* GtkLabel#title-label {
|
2011-06-01 23:55:45 +00:00
|
|
|
* font: Sans 15
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme any widget named main-entry */
|
|
|
|
* #main-entry {
|
2010-11-18 23:36:08 +00:00
|
|
|
* background-color: #f0a810
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* Widgets may also define style classes, which can be used for matching.
|
|
|
|
* When used in a selector, style classes must be prefixed with a '.'
|
|
|
|
* character.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Refer to the documentation of individual widgets to learn which
|
2010-11-26 04:46:15 +00:00
|
|
|
* style classes they define and see <xref linkend="gtkstylecontext-classes"/>
|
|
|
|
* for a list of all style classes used by GTK+ widgets.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
2011-01-19 17:55:48 +00:00
|
|
|
* <para>
|
|
|
|
* Note that there is some ambiguity in the selector syntax when it comes
|
|
|
|
* to differentiation widget class names from regions. GTK+ currently treats
|
|
|
|
* a string as a widget class name if it contains any uppercase characters
|
|
|
|
* (which should work for more widgets with names like GtkLabel).
|
|
|
|
* </para>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <example>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <title>Style classes in selectors</title>
|
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* /* Theme all widgets defining the class entry */
|
|
|
|
* .entry {
|
2010-10-29 03:33:38 +00:00
|
|
|
* color: #39f1f9;
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme spinbuttons' entry */
|
|
|
|
* GtkSpinButton.entry {
|
2010-11-18 23:36:08 +00:00
|
|
|
* color: #900185
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* In complicated widgets like e.g. a GtkNotebook, it may be desirable
|
|
|
|
* to style different parts of the widget differently. To make this
|
|
|
|
* possible, container widgets may define regions, whose names
|
|
|
|
* may be used for matching in selectors.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Some containers allow to further differentiate between regions by
|
|
|
|
* applying so-called pseudo-classes to the region. For example, the
|
|
|
|
* tab region in GtkNotebook allows to single out the first or last
|
|
|
|
* tab by using the :first-child or :last-child pseudo-class.
|
|
|
|
* When used in selectors, pseudo-classes must be prefixed with a
|
|
|
|
* ':' character.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Refer to the documentation of individual widgets to learn which
|
2010-11-26 04:49:07 +00:00
|
|
|
* regions and pseudo-classes they define and see
|
|
|
|
* <xref linkend="gtkstylecontext-classes"/> for a list of all regions
|
|
|
|
* used by GTK+ widgets.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <title>Regions in selectors</title>
|
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* /* Theme any label within a notebook */
|
|
|
|
* GtkNotebook GtkLabel {
|
2010-10-29 03:33:38 +00:00
|
|
|
* color: #f90192;
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme labels within notebook tabs */
|
2010-11-20 05:22:29 +00:00
|
|
|
* GtkNotebook tab GtkLabel {
|
2010-10-29 03:33:38 +00:00
|
|
|
* color: #703910;
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme labels in the any first notebook
|
|
|
|
* tab, both selectors are equivalent */
|
|
|
|
* GtkNotebook tab:nth-child(first) GtkLabel,
|
|
|
|
* GtkNotebook tab:first-child GtkLabel {
|
2010-10-29 03:33:38 +00:00
|
|
|
* color: #89d012;
|
2010-10-19 08:59:46 +00:00
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* Another use of pseudo-classes is to match widgets depending on their
|
|
|
|
* state. This is conceptually similar to the :hover, :active or :focus
|
|
|
|
* pseudo-classes in CSS. The available pseudo-classes for widget states
|
|
|
|
* are :active, :prelight (or :hover), :insensitive, :selected, :focused
|
|
|
|
* and :inconsistent.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Styling specific widget states</title>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* /* Theme active (pressed) buttons */
|
|
|
|
* GtkButton:active {
|
|
|
|
* background-color: #0274d9;
|
|
|
|
* }
|
|
|
|
*
|
2010-11-20 05:22:29 +00:00
|
|
|
* /* Theme buttons with the mouse pointer on it,
|
|
|
|
* both are equivalent */
|
2010-10-19 08:59:46 +00:00
|
|
|
* GtkButton:hover,
|
|
|
|
* GtkButton:prelight {
|
|
|
|
* background-color: #3085a9;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme insensitive widgets, both are equivalent */
|
|
|
|
* :insensitive,
|
|
|
|
* *:insensitive {
|
|
|
|
* background-color: #320a91;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme selection colors in entries */
|
|
|
|
* GtkEntry:selected {
|
|
|
|
* background-color: #56f9a0;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme focused labels */
|
|
|
|
* GtkLabel:focused {
|
|
|
|
* background-color: #b4940f;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* /* Theme inconsistent checkbuttons */
|
|
|
|
* GtkCheckButton:inconsistent {
|
|
|
|
* background-color: #20395a;
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* Widget state pseudoclasses may only apply to the last element
|
|
|
|
* in a selector.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* To determine the effective style for a widget, all the matching rule
|
|
|
|
* sets are merged. As in CSS, rules apply by specificity, so the rules
|
|
|
|
* whose selectors more closely match a widget path will take precedence
|
2010-10-19 08:59:46 +00:00
|
|
|
* over the others.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
* <refsect2 id="gtkcssprovider-rules">
|
2010-11-20 05:22:29 +00:00
|
|
|
* <title>@ Rules</title>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* GTK+'s CSS supports the @import rule, in order to load another
|
|
|
|
* CSS style sheet in addition to the currently parsed one.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Using the @import rule</title>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <programlisting language="text">
|
2010-11-18 23:36:08 +00:00
|
|
|
* @import url ("path/to/common.css");
|
2010-10-19 08:59:46 +00:00
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2011-01-31 12:37:36 +00:00
|
|
|
* <para id="css-binding-set">
|
2011-01-28 09:25:17 +00:00
|
|
|
* In order to extend key bindings affecting different widgets, GTK+
|
|
|
|
* supports the @binding-set rule to parse a set of bind/unbind
|
2011-01-31 04:34:52 +00:00
|
|
|
* directives, see #GtkBindingSet for the supported syntax. Note that
|
|
|
|
* the binding sets defined in this way must be associated with rule sets
|
|
|
|
* by setting the gtk-key-bindings style property.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* Customized key bindings are typically defined in a separate
|
|
|
|
* <filename>gtk-keys.css</filename> CSS file and GTK+ loads this file
|
|
|
|
* according to the current key theme, which is defined by the
|
|
|
|
* #GtkSettings:gtk-key-theme-name setting.
|
2011-01-28 09:25:17 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Using the @binding rule</title>
|
|
|
|
* <programlisting language="text">
|
|
|
|
* @binding-set binding-set1 {
|
|
|
|
* bind "<alt>Left" { "move-cursor" (visual-positions, -3, 0) };
|
|
|
|
* unbind "End";
|
|
|
|
* };
|
|
|
|
*
|
2011-01-28 23:08:57 +00:00
|
|
|
* @binding-set binding-set2 {
|
2011-01-28 09:25:17 +00:00
|
|
|
* bind "<alt>Right" { "move-cursor" (visual-positions, 3, 0) };
|
2011-01-28 23:08:57 +00:00
|
|
|
* bind "<alt>KP_space" { "delete-from-cursor" (whitespace, 1)
|
2011-01-31 04:34:52 +00:00
|
|
|
* "insert-at-cursor" (" ") };
|
2011-01-28 09:25:17 +00:00
|
|
|
* };
|
|
|
|
*
|
|
|
|
* GtkEntry {
|
2011-01-28 23:08:57 +00:00
|
|
|
* gtk-key-bindings: binding-set1, binding-set2;
|
2011-01-28 09:25:17 +00:00
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* GTK+ also supports an additional @define-color rule, in order
|
|
|
|
* to define a color name which may be used instead of color numeric
|
|
|
|
* representations. Also see the #GtkSettings:gtk-color-scheme setting
|
|
|
|
* for a way to override the values of these named colors.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Defining colors</title>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* @define-color bg_color #f9a039;
|
|
|
|
*
|
|
|
|
* * {
|
|
|
|
* background-color: @bg_color;
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
* </refsect2>
|
|
|
|
* <refsect2 id="gtkcssprovider-symbolic-colors">
|
|
|
|
* <title>Symbolic colors</title>
|
|
|
|
* <para>
|
2010-11-20 05:22:29 +00:00
|
|
|
* Besides being able to define color names, the CSS parser is also able
|
|
|
|
* to read different color expressions, which can also be nested, providing
|
|
|
|
* a rich language to define colors which are derived from a set of base
|
|
|
|
* colors.
|
2010-10-19 08:59:46 +00:00
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Using symbolic colors</title>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <programlisting language="text">
|
2010-10-19 08:59:46 +00:00
|
|
|
* @define-color entry-color shade (@bg_color, 0.7);
|
|
|
|
*
|
|
|
|
* GtkEntry {
|
|
|
|
* background-color: @entry-color;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* GtkEntry:focused {
|
|
|
|
* background-color: mix (@entry-color,
|
|
|
|
* shade (#fff, 0.5),
|
|
|
|
* 0.8);
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <para>
|
|
|
|
* The various ways to express colors in GTK+ CSS are:
|
|
|
|
* </para>
|
|
|
|
* <informaltable>
|
|
|
|
* <tgroup cols="3">
|
|
|
|
* <thead>
|
|
|
|
* <row>
|
|
|
|
* <entry>Syntax</entry>
|
|
|
|
* <entry>Explanation</entry>
|
|
|
|
* <entry>Examples</entry>
|
|
|
|
* </row>
|
|
|
|
* </thead>
|
|
|
|
* <tbody>
|
|
|
|
* <row>
|
|
|
|
* <entry>rgb(@r, @g, @b)</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>An opaque color; @r, @g, @b can be either integers between
|
|
|
|
* 0 and 255 or percentages</entry>
|
|
|
|
* <entry><literallayout>rgb(128, 10, 54)
|
|
|
|
* rgb(20%, 30%, 0%)</literallayout></entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>rgba(@r, @g, @b, @a)</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>A translucent color; @r, @g, @b are as in the previous row,
|
|
|
|
* @a is a floating point number between 0 and 1</entry>
|
|
|
|
* <entry><literallayout>rgba(255, 255, 0, 0.5)</literallayout></entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>#@xxyyzz</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>An opaque color; @xx, @yy, @zz are hexadecimal numbers
|
|
|
|
* specifying @r, @g, @b variants with between 1 and 4
|
|
|
|
* hexadecimal digits per component are allowed</entry>
|
|
|
|
* <entry><literallayout>#ff12ab
|
|
|
|
* #f0c</literallayout></entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>@name</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>Reference to a color that has been defined with
|
|
|
|
* @define-color
|
|
|
|
* </entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <entry>@bg_color</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>mix(@color1, @color2, @f)</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>A linear combination of @color1 and @color2. @f is a
|
|
|
|
* floating point number between 0 and 1.</entry>
|
|
|
|
* <entry><literallayout>mix(#ff1e0a, @bg_color, 0.8)</literallayout></entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>shade(@color, @f)</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>A lighter or darker variant of @color. @f is a
|
|
|
|
* floating point number.
|
|
|
|
* </entry>
|
2010-11-20 05:22:29 +00:00
|
|
|
* <entry>shade(@fg_color, 0.5)</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>lighter(@color)</entry>
|
|
|
|
* <entry>A lighter variant of @color</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>darker(@color)</entry>
|
|
|
|
* <entry>A darker variant of @color</entry>
|
|
|
|
* </row>
|
|
|
|
* </tbody>
|
|
|
|
* </tgroup>
|
|
|
|
* </informaltable>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </refsect2>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-gradients">
|
|
|
|
* <title>Gradients</title>
|
|
|
|
* <para>
|
|
|
|
* Linear or radial Gradients can be used as background images.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
2010-11-23 06:05:11 +00:00
|
|
|
* A linear gradient along the line from (@start_x, @start_y) to
|
|
|
|
* (@end_x, @end_y) is specified using the syntax
|
2010-11-22 06:41:45 +00:00
|
|
|
* <literallayout>-gtk-gradient (linear,
|
2010-11-23 06:05:11 +00:00
|
|
|
* @start_x @start_y, @end_x @end_y,
|
2010-11-22 06:41:45 +00:00
|
|
|
* color-stop (@position, @color),
|
|
|
|
* ...)</literallayout>
|
2010-11-23 06:05:11 +00:00
|
|
|
* where @start_x and @end_x can be either a floating point number between
|
|
|
|
* 0 and 1 or one of the special values 'left', 'right' or 'center', @start_y
|
|
|
|
* and @end_y can be either a floating point number between 0 and 1 or one
|
2010-11-22 06:41:45 +00:00
|
|
|
* of the special values 'top', 'bottom' or 'center', @position is a floating
|
|
|
|
* point number between 0 and 1 and @color is a color expression (see above).
|
|
|
|
* The color-stop can be repeated multiple times to add more than one color
|
|
|
|
* stop. 'from (@color)' and 'to (@color)' can be used as abbreviations for
|
|
|
|
* color stops with position 0 and 1, respectively.
|
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>A linear gradient</title>
|
|
|
|
* <inlinegraphic fileref="gradient1.png" format="PNG"/>
|
|
|
|
* <para>This gradient was specified with
|
|
|
|
* <literallayout>-gtk-gradient (linear,
|
|
|
|
* left top, right bottom,
|
|
|
|
* from(@yellow), to(@blue))</literallayout></para>
|
|
|
|
* </example>
|
|
|
|
* <example>
|
|
|
|
* <title>Another linear gradient</title>
|
|
|
|
* <inlinegraphic fileref="gradient2.png" format="PNG"/>
|
|
|
|
* <para>This gradient was specified with
|
|
|
|
* <literallayout>-gtk-gradient (linear,
|
|
|
|
* 0 0, 0 1,
|
|
|
|
* color-stop(0, @yellow),
|
|
|
|
* color-stop(0.2, @blue),
|
|
|
|
* color-stop(1, #0f0))</literallayout></para>
|
|
|
|
* </example>
|
|
|
|
* <para>
|
2010-11-23 06:05:11 +00:00
|
|
|
* A radial gradient along the two circles defined by (@start_x, @start_y,
|
|
|
|
* @start_radius) and (@end_x, @end_y, @end_radius) is specified using the
|
2010-11-22 06:41:45 +00:00
|
|
|
* syntax
|
|
|
|
* <literallayout>-gtk-gradient (radial,
|
2010-11-23 06:05:11 +00:00
|
|
|
* @start_x @start_y, @start_radius,
|
|
|
|
* @end_x @end_y, @end_radius,
|
2010-11-22 06:41:45 +00:00
|
|
|
* color-stop (@position, @color),
|
|
|
|
* ...)</literallayout>
|
2010-11-23 06:05:11 +00:00
|
|
|
* where @start_radius and @end_radius are floating point numbers and
|
2010-11-22 06:41:45 +00:00
|
|
|
* the other parameters are as before.
|
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>A radial gradient</title>
|
|
|
|
* <inlinegraphic fileref="gradient3.png" format="PNG"/>
|
|
|
|
* <para>This gradient was specified with
|
|
|
|
* <literallayout>-gtk-gradient (radial,
|
|
|
|
* center center, 0,
|
|
|
|
* center center, 1,
|
|
|
|
* from(@yellow), to(@green))</literallayout></para>
|
|
|
|
* </example>
|
|
|
|
* <example>
|
|
|
|
* <title>Another radial gradient</title>
|
|
|
|
* <inlinegraphic fileref="gradient4.png" format="PNG"/>
|
|
|
|
* <para>This gradient was specified with
|
2010-11-22 16:15:47 +00:00
|
|
|
* <literallayout>-gtk-gradient (radial,
|
2010-11-22 06:41:45 +00:00
|
|
|
* 0.4 0.4, 0.1,
|
|
|
|
* 0.6 0.6, 0.7,
|
|
|
|
* color-stop (0, #f00),
|
|
|
|
* color-stop (0.1, #a0f),
|
|
|
|
* color-stop (0.2, @yellow),
|
|
|
|
* color-stop (1, @green))</literallayout></para>
|
|
|
|
* </example>
|
|
|
|
* </refsect2>
|
2011-05-20 20:11:08 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-shadows">
|
|
|
|
* <title>Text shadow</title>
|
|
|
|
* <para>
|
|
|
|
* A shadow list can be applied to text or symbolic icons, using the CSS3
|
|
|
|
* text-shadow syntax, as defined in
|
|
|
|
* <ulink url="http://www.w3.org/TR/css3-text/#text-shadow">the CSS3 specification</ulink>.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* A text shadow is specified using the syntax
|
|
|
|
* <literallayout>text-shadow: @horizontal_offset @vertical_offset [ @blur_radius ] @color</literallayout>
|
|
|
|
* The offset of the shadow is specified with the @horizontal_offset and @vertical_offset
|
|
|
|
* parameters. The optional blur radius is parsed, but it is currently not rendered by
|
|
|
|
* the GTK+ theming engine.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* To set multiple shadows on an element, you can specify a comma-separated list
|
|
|
|
* of shadow elements in the text-shadow property. Shadows are always rendered
|
|
|
|
* front-back, i.e. the first shadow specified is on top of the others. Shadows
|
|
|
|
* can thus overlay each other, but they can never overlay the text itself,
|
|
|
|
* which is always rendered on top of the shadow layer.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
2011-06-07 16:57:08 +00:00
|
|
|
* <refsect2>
|
|
|
|
* <title>Box shadow</title>
|
|
|
|
* <para>
|
|
|
|
* Themes can apply shadows on framed elements using the CSS3 box-shadow syntax,
|
|
|
|
* as defined in
|
|
|
|
* <ulink url="http://www.w3.org/TR/css3-background/#the-box-shadow">the CSS3 specification</ulink>.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* A box shadow is specified using the syntax
|
|
|
|
* <literallayout>box-shadow: [ @inset ] @horizontal_offset @vertical_offset [ @blur_radius ] [ @spread ] @color</literallayout>
|
|
|
|
* A positive offset will draw a shadow that is offset to the right (down) of the box,
|
|
|
|
* a negative offset to the left (top). The optional spread parameter defines an additional
|
|
|
|
* distance to expand the shadow shape in all directions, by the specified radius.
|
|
|
|
* The optional blur radius parameter is parsed, but it is currently not rendered by
|
|
|
|
* the GTK+ theming engine.
|
|
|
|
* The inset parameter defines whether the drop shadow should be rendered inside or outside
|
|
|
|
* the box canvas. Only inset box-shadows are currently supported by the GTK+ theming engine,
|
|
|
|
* non-inset elements are currently ignored.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* To set multiple box-shadows on an element, you can specify a comma-separated list
|
|
|
|
* of shadow elements in the box-shadow property. Shadows are always rendered
|
|
|
|
* front-back, i.e. the first shadow specified is on top of the others, so they may
|
|
|
|
* overlap other boxes or other shadows.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
2011-05-31 13:32:00 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-border-image">
|
2010-11-22 16:18:27 +00:00
|
|
|
* <title>Border images</title>
|
2010-11-22 16:15:47 +00:00
|
|
|
* <para>
|
2011-05-31 13:32:00 +00:00
|
|
|
* Images and gradients can also be used in slices for the purpose of creating
|
|
|
|
* scalable borders.
|
|
|
|
* For more information, see the CSS3 documentation for the border-image property,
|
|
|
|
* which can be found <ulink url="http://www.w3.org/TR/css3-background/#border-images">here</ulink>.
|
2010-11-22 16:15:47 +00:00
|
|
|
* </para>
|
|
|
|
* <inlinegraphic fileref="slices.png" format="PNG"/>
|
|
|
|
* <para>
|
2011-05-31 13:32:00 +00:00
|
|
|
* The parameters of the slicing process are controlled by
|
2011-06-09 23:59:14 +00:00
|
|
|
* four separate properties. Note that you can use the
|
2011-05-31 13:32:00 +00:00
|
|
|
* <literallayout>border-image</literallayout> shorthand property
|
|
|
|
* to set values for the three properties at the same time.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* <literallayout>border-image-source: url(@path)
|
|
|
|
* (or border-image-source: -gtk-gradient(...))</literallayout>:
|
|
|
|
* Specifies the source of the border image, and it can either
|
|
|
|
* be an URL or a gradient (see above).
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* <literallayout>border-image-slice: @top @right @bottom @left</literallayout>
|
|
|
|
* The sizes specified by the @top, @right, @bottom and @left parameters
|
|
|
|
* are the offsets, in pixels, from the relevant edge where the image
|
|
|
|
* should be "cut off" to build the slices used for the rendering
|
|
|
|
* of the border.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
2011-06-09 23:59:14 +00:00
|
|
|
* <literallayout>border-image-width: @top @right @bottom @left</literallayout>
|
|
|
|
* The sizes specified by the @top, @right, @bottom and @left parameters
|
|
|
|
* are inward distances from the border box edge, used to specify the
|
|
|
|
* rendered size of each slice determined by border-image-slice.
|
|
|
|
* If this property is not specified, the values of border-width will
|
|
|
|
* be used as a fallback.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
2011-05-31 13:32:00 +00:00
|
|
|
* <literallayout>border-image-repeat: [stretch|repeat|round|space] ?
|
|
|
|
* [stretch|repeat|round|space]</literallayout>
|
|
|
|
* Specifies how the image slices should be rendered in the area
|
|
|
|
* outlined by border-width.
|
|
|
|
* The default (stretch) is to resize the slice to fill in the whole
|
|
|
|
* allocated area.
|
|
|
|
* If the value of this property is 'repeat', the image slice
|
|
|
|
* will be tiled to fill the area.
|
|
|
|
* If the value of this property is 'round', the image slice will
|
|
|
|
* be tiled to fill the area, and scaled to fit it exactly
|
|
|
|
* a whole number of times.
|
|
|
|
* If the value of this property is 'space', the image slice will
|
|
|
|
* be tiled to fill the area, and if it doesn't fit it exactly a whole
|
|
|
|
* number of times, the extra space is distributed as padding around
|
|
|
|
* the slices.
|
|
|
|
* If two options are specified, the first one affects
|
2010-11-22 16:15:47 +00:00
|
|
|
* the horizontal behaviour and the second one the vertical behaviour.
|
|
|
|
* If only one option is specified, it affects both.
|
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>A border image</title>
|
|
|
|
* <inlinegraphic fileref="border1.png" format="PNG"/>
|
2010-11-23 06:05:11 +00:00
|
|
|
* <para>This border image was specified with
|
|
|
|
* <literallayout>url("gradient1.png") 10 10 10 10</literallayout>
|
|
|
|
* </para>
|
2010-11-22 16:15:47 +00:00
|
|
|
* </example>
|
|
|
|
* <example>
|
|
|
|
* <title>A repeating border image</title>
|
|
|
|
* <inlinegraphic fileref="border2.png" format="PNG"/>
|
2010-11-23 06:05:11 +00:00
|
|
|
* <para>This border image was specified with
|
|
|
|
* <literallayout>url("gradient1.png") 10 10 10 10 repeat</literallayout>
|
|
|
|
* </para>
|
2010-11-22 16:15:47 +00:00
|
|
|
* </example>
|
|
|
|
* <example>
|
|
|
|
* <title>A stretched border image</title>
|
|
|
|
* <inlinegraphic fileref="border3.png" format="PNG"/>
|
2010-11-23 06:05:11 +00:00
|
|
|
* <para>This border image was specified with
|
|
|
|
* <literallayout>url("gradient1.png") 10 10 10 10 stretch</literallayout>
|
|
|
|
* </para>
|
2010-11-22 16:15:47 +00:00
|
|
|
* </example>
|
|
|
|
* </refsect2>
|
2010-11-22 20:12:42 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-transitions">
|
|
|
|
* <para>Styles can specify transitions that will be used to create a gradual
|
|
|
|
* change in the appearance when a widget state changes. The following
|
|
|
|
* syntax is used to specify transitions:
|
|
|
|
* <literallayout>@duration [s|ms] [linear|ease|ease-in|ease-out|ease-in-out] [loop]?</literallayout>
|
|
|
|
* The @duration is the amount of time that the animation will take for
|
|
|
|
* a complete cycle from start to end. If the loop option is given, the
|
|
|
|
* animation will be repated until the state changes again.
|
|
|
|
* The option after the duration determines the transition function from a
|
|
|
|
* small set of predefined functions.
|
|
|
|
* <figure><title>Linear transition</title>
|
|
|
|
* <graphic fileref="linear.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
* <figure><title>Ease transition</title>
|
|
|
|
* <graphic fileref="ease.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
* <figure><title>Ease-in-out transition</title>
|
|
|
|
* <graphic fileref="ease-in-out.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
* <figure><title>Ease-in transition</title>
|
|
|
|
* <graphic fileref="ease-in.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
* <figure><title>Ease-out transition</title>
|
|
|
|
* <graphic fileref="ease-out.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <refsect2 id="gtkcssprovider-properties">
|
|
|
|
* <title>Supported properties</title>
|
|
|
|
* <para>
|
|
|
|
* Properties are the part that differ the most to common CSS,
|
|
|
|
* not all properties are supported (some are planned to be
|
|
|
|
* supported eventually, some others are meaningless or don't
|
|
|
|
* map intuitively in a widget based environment).
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* The currently supported properties are:
|
|
|
|
* </para>
|
|
|
|
* <informaltable>
|
|
|
|
* <tgroup cols="4">
|
|
|
|
* <thead>
|
|
|
|
* <row>
|
|
|
|
* <entry>Property name</entry>
|
|
|
|
* <entry>Syntax</entry>
|
|
|
|
* <entry>Maps to</entry>
|
|
|
|
* <entry>Examples</entry>
|
|
|
|
* </row>
|
|
|
|
* </thead>
|
|
|
|
* <tbody>
|
|
|
|
* <row>
|
|
|
|
* <entry>engine</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>engine-name</entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>#GtkThemingEngine</entry>
|
2011-01-04 16:25:40 +00:00
|
|
|
* <entry>engine: clearlooks;
|
|
|
|
* engine: none; /* use the default (i.e. builtin) engine) */ </entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>background-color</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry morerows="2">color (see above)</entry>
|
2011-06-13 01:45:18 +00:00
|
|
|
* <entry morerows="7">#GdkRGBA</entry>
|
|
|
|
* <entry morerows="7"><literallayout>background-color: #fff;
|
2010-11-23 06:05:11 +00:00
|
|
|
* color: &color1;
|
|
|
|
* background-color: shade (&color1, 0.5);
|
|
|
|
* color: mix (&color1, #f0f, 0.8);</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-10-29 03:33:38 +00:00
|
|
|
* <entry>color</entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
2011-06-13 01:45:18 +00:00
|
|
|
* <entry>border-top-color</entry>
|
|
|
|
* <entry morerows="4">transparent|color (see above)</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-right-color</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-bottom-color</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-left-color</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>border-color</entry>
|
2011-06-13 01:45:18 +00:00
|
|
|
* <entry>[transparent|color]{1,4}</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
2011-05-29 05:03:59 +00:00
|
|
|
* <entry>font-family</entry>
|
|
|
|
* <entry>@family [, @family]*</entry>
|
|
|
|
* <entry>#gchararray</entry>
|
|
|
|
* <entry>font-family: Sans, Arial;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>font-style</entry>
|
|
|
|
* <entry>[normal|oblique|italic]</entry>
|
|
|
|
* <entry>#PANGO_TYPE_STYLE</entry>
|
|
|
|
* <entry>font-style: italic;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>font-variant</entry>
|
|
|
|
* <entry>[normal|small-caps]</entry>
|
|
|
|
* <entry>#PANGO_TYPE_VARIANT</entry>
|
|
|
|
* <entry>font-variant: normal;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>font-weight</entry>
|
|
|
|
* <entry>[normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900]</entry>
|
|
|
|
* <entry>#PANGO_TYPE_WEIGHT</entry>
|
|
|
|
* <entry>font-weight: bold;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>font-size</entry>
|
|
|
|
* <entry>Font size in point</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>font-size: 13;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>font</entry>
|
2010-11-22 16:15:47 +00:00
|
|
|
* <entry>@family [@style] [@size]</entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>#PangoFontDescription</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>font: Sans 15;</entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
2011-05-22 03:55:12 +00:00
|
|
|
* <entry>margin-top</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>margin-top: 0;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>margin-left</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>margin-left: 1;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>margin-bottom</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>margin-bottom: 2;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>margin-right</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>margin-right: 4;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>margin</entry>
|
2010-11-22 16:15:47 +00:00
|
|
|
* <entry morerows="1"><literallayout>@width
|
2010-11-23 06:05:11 +00:00
|
|
|
* @vertical_width @horizontal_width
|
|
|
|
* @top_width @horizontal_width @bottom_width
|
|
|
|
* @top_width @right_width @bottom_width @left_width</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* <entry morerows="1">#GtkBorder</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry morerows="1"><literallayout>margin: 5;
|
2010-10-19 08:59:46 +00:00
|
|
|
* margin: 5 10;
|
|
|
|
* margin: 5 10 3;
|
2010-11-22 06:41:45 +00:00
|
|
|
* margin: 5 10 3 5;</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2011-05-22 03:42:17 +00:00
|
|
|
* <entry>padding-top</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>padding-top: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>padding-left</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>padding-left: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>padding-bottom</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>padding-bottom: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>padding-right</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>padding-right: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>padding</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>background-image</entry>
|
2010-11-26 05:43:16 +00:00
|
|
|
* <entry><literallayout>gradient (see above) or
|
|
|
|
* url(@path)</literallayout></entry>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>#cairo_pattern_t</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry><literallayout>-gtk-gradient (linear,
|
2010-11-13 12:27:37 +00:00
|
|
|
* left top, right top,
|
2010-10-19 08:59:46 +00:00
|
|
|
* from (#fff), to (#000));
|
|
|
|
* -gtk-gradient (linear, 0.0 0.5, 0.5 1.0,
|
|
|
|
* from (#fff),
|
|
|
|
* color-stop (0.5, #f00),
|
|
|
|
* to (#000));
|
|
|
|
* -gtk-gradient (radial,
|
|
|
|
* center center, 0.2,
|
|
|
|
* center center, 0.8,
|
|
|
|
* color-stop (0.0, #fff),
|
2010-11-26 05:43:16 +00:00
|
|
|
* color-stop (1.0, #000));
|
|
|
|
* url ('background.png');</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2011-05-21 22:10:43 +00:00
|
|
|
* <entry>border-top-width</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>border-top-width: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-left-width</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>border-left-width: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-bottom-width</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
2011-05-21 22:10:43 +00:00
|
|
|
* <entry>border-bottom-width: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-right-width</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>border-right-width: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-width</entry>
|
|
|
|
* <entry morerows="1">#GtkBorder</entry>
|
|
|
|
* <entry morerows="1"><literallayout>border-width: 1;
|
|
|
|
* border-width: 1 2;
|
|
|
|
* border-width: 1 2 3;
|
|
|
|
* border-width: 1 2 3 5;</literallayout>
|
|
|
|
* </entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-radius</entry>
|
|
|
|
* <entry>integer</entry>
|
|
|
|
* <entry>#gint</entry>
|
|
|
|
* <entry>border-radius: 5;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>border-style</entry>
|
|
|
|
* <entry>[none|solid|inset|outset]</entry>
|
|
|
|
* <entry>#GtkBorderStyle</entry>
|
|
|
|
* <entry>border-style: solid;</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <entry>border-image</entry>
|
2010-11-22 16:15:47 +00:00
|
|
|
* <entry><literallayout>border image (see above)</literallayout></entry>
|
2010-11-23 13:24:49 +00:00
|
|
|
* <entry>internal use only</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry><literallayout>border-image: url("/path/to/image.png") 3 4 3 4 stretch;
|
|
|
|
* border-image: url("/path/to/image.png") 3 4 4 3 repeat stretch;</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
2011-05-21 01:41:52 +00:00
|
|
|
* <row>
|
2011-05-20 20:11:08 +00:00
|
|
|
* <entry>text-shadow</entry>
|
|
|
|
* <entry>shadow list (see above)</entry>
|
|
|
|
* <entry>#GtkTextShadow</entry>
|
|
|
|
* <entry><literallayout>text-shadow: 1 1 0 blue, -4 -4 red;</literallayout></entry>
|
|
|
|
* </row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* <row>
|
|
|
|
* <entry>transition</entry>
|
2010-11-22 20:12:42 +00:00
|
|
|
* <entry>transition (see above)</entry>
|
2010-11-23 13:24:49 +00:00
|
|
|
* <entry>internal use only</entry>
|
2010-11-22 06:41:45 +00:00
|
|
|
* <entry><literallayout>transition: 150ms ease-in-out;
|
|
|
|
* transition: 1s linear loop;</literallayout>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
2011-01-28 09:25:17 +00:00
|
|
|
* <row>
|
|
|
|
* <entry>gtk-key-bindings</entry>
|
|
|
|
* <entry>binding set name list</entry>
|
|
|
|
* <entry>internal use only</entry>
|
|
|
|
* <entry><literallayout>gtk-bindings: binding1, binding2, ...;</literallayout>
|
|
|
|
* </entry>
|
|
|
|
* </row>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </tbody>
|
|
|
|
* </tgroup>
|
|
|
|
* </informaltable>
|
2010-11-23 06:05:11 +00:00
|
|
|
* <para>
|
|
|
|
* GtkThemingEngines can register their own, engine-specific style properties
|
|
|
|
* with the function gtk_theming_engine_register_property(). These properties
|
|
|
|
* can be set in CSS like other properties, using a name of the form
|
|
|
|
* <literallayout>-<replaceable>namespace</replaceable>-<replaceable>name</replaceable></literallayout>, where <replaceable>namespace</replaceable> is typically
|
|
|
|
* the name of the theming engine, and <replaceable>name</replaceable> is the
|
|
|
|
* name of the property. Style properties that have been registered by widgets
|
|
|
|
* using gtk_widget_class_install_style_property() can also be set in this
|
|
|
|
* way, using the widget class name for <replaceable>namespace</replaceable>.
|
|
|
|
* </para>
|
|
|
|
* <example>
|
|
|
|
* <title>Using engine-specific style properties</title>
|
|
|
|
* <programlisting>
|
|
|
|
* * {
|
|
|
|
* engine: clearlooks;
|
|
|
|
* border-radius: 4;
|
|
|
|
* -GtkPaned-handle-size: 6;
|
|
|
|
* -clearlooks-colorize-scrollbar: false;
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2010-10-19 08:59:46 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
typedef struct GtkCssRuleset GtkCssRuleset;
|
2011-04-14 02:47:18 +00:00
|
|
|
typedef struct _GtkCssScanner GtkCssScanner;
|
2010-04-11 21:03:25 +00:00
|
|
|
typedef enum ParserScope ParserScope;
|
2010-04-20 23:46:52 +00:00
|
|
|
typedef enum ParserSymbol ParserSymbol;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
struct GtkCssRuleset
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
GtkCssSelector *selector;
|
2011-05-18 02:36:43 +00:00
|
|
|
GHashTable *widget_style;
|
2010-04-11 21:03:25 +00:00
|
|
|
GHashTable *style;
|
2011-05-18 03:47:18 +00:00
|
|
|
|
|
|
|
guint has_inherit :1;
|
2010-04-11 21:03:25 +00:00
|
|
|
};
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
struct _GtkCssScanner
|
2011-04-10 01:39:52 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssProvider *provider;
|
|
|
|
GtkCssParser *parser;
|
2011-06-17 02:52:43 +00:00
|
|
|
GtkCssSection *section;
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *parent;
|
2011-04-11 14:48:00 +00:00
|
|
|
GFile *file;
|
2011-04-11 15:30:01 +00:00
|
|
|
GFile *base;
|
2011-04-10 01:51:43 +00:00
|
|
|
GSList *state;
|
2011-04-10 01:39:52 +00:00
|
|
|
};
|
|
|
|
|
2011-04-06 14:10:25 +00:00
|
|
|
struct _GtkCssProviderPrivate
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
|
|
|
GScanner *scanner;
|
2010-12-03 20:56:39 +00:00
|
|
|
|
2010-06-25 18:27:15 +00:00
|
|
|
GHashTable *symbolic_colors;
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
GArray *rulesets;
|
2010-04-11 21:03:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ParserScope {
|
|
|
|
SCOPE_SELECTOR,
|
2010-04-14 21:36:48 +00:00
|
|
|
SCOPE_PSEUDO_CLASS,
|
2010-04-20 23:46:52 +00:00
|
|
|
SCOPE_NTH_CHILD,
|
2010-04-11 21:03:25 +00:00
|
|
|
SCOPE_DECLARATION,
|
2011-01-29 00:36:24 +00:00
|
|
|
SCOPE_VALUE,
|
|
|
|
SCOPE_BINDING_SET
|
2010-04-11 21:03:25 +00:00
|
|
|
};
|
|
|
|
|
2010-04-20 23:46:52 +00:00
|
|
|
/* Extend GtkStateType, since these
|
|
|
|
* values are also used as symbols
|
|
|
|
*/
|
|
|
|
enum ParserSymbol {
|
|
|
|
/* Scope: pseudo-class */
|
2010-11-12 20:44:48 +00:00
|
|
|
SYMBOL_NTH_CHILD = GTK_STATE_FOCUSED + 1,
|
2010-04-20 23:46:52 +00:00
|
|
|
SYMBOL_FIRST_CHILD,
|
|
|
|
SYMBOL_LAST_CHILD,
|
2010-10-19 11:00:07 +00:00
|
|
|
SYMBOL_SORTED_CHILD,
|
2010-04-20 23:46:52 +00:00
|
|
|
|
|
|
|
/* Scope: nth-child */
|
|
|
|
SYMBOL_NTH_CHILD_EVEN,
|
|
|
|
SYMBOL_NTH_CHILD_ODD,
|
|
|
|
SYMBOL_NTH_CHILD_FIRST,
|
|
|
|
SYMBOL_NTH_CHILD_LAST
|
|
|
|
};
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
enum {
|
|
|
|
PARSING_ERROR,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint css_provider_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void gtk_css_provider_finalize (GObject *object);
|
|
|
|
static void gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface);
|
|
|
|
|
2011-04-11 23:10:13 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_provider_load_internal (GtkCssProvider *css_provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-11 23:10:13 +00:00
|
|
|
GFile *file,
|
|
|
|
const char *data,
|
|
|
|
GError **error);
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2010-11-18 03:29:39 +00:00
|
|
|
GQuark
|
|
|
|
gtk_css_provider_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gtk-css-provider-error-quark");
|
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
G_DEFINE_TYPE_EXTENDED (GtkCssProvider, gtk_css_provider, G_TYPE_OBJECT, 0,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
|
|
|
gtk_css_style_provider_iface_init));
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_parsing_error (GtkCssProvider *provider,
|
2011-06-17 05:39:11 +00:00
|
|
|
GtkCssSection *section,
|
|
|
|
const GError *error)
|
2011-04-07 15:26:47 +00:00
|
|
|
{
|
2011-04-10 23:51:49 +00:00
|
|
|
/* Only emit a warning when we have no error handlers. This is our
|
|
|
|
* default handlers. And in this case erroneous CSS files are a bug
|
|
|
|
* and should be fixed.
|
|
|
|
* Note that these warnings can also be triggered by a broken theme
|
|
|
|
* that people installed from some weird location on the internets.
|
|
|
|
*/
|
|
|
|
if (!g_signal_has_handler_pending (provider,
|
|
|
|
css_provider_signals[PARSING_ERROR],
|
|
|
|
0,
|
|
|
|
TRUE))
|
|
|
|
{
|
2011-06-17 05:39:11 +00:00
|
|
|
GFileInfo *info;
|
|
|
|
GFile *file;
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
file = gtk_css_section_get_file (section);
|
|
|
|
if (file)
|
|
|
|
{
|
2011-09-09 13:32:54 +00:00
|
|
|
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
|
2011-06-17 05:39:11 +00:00
|
|
|
|
|
|
|
if (info)
|
|
|
|
path = g_file_info_get_display_name (info);
|
|
|
|
else
|
|
|
|
path = "<broken file>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = NULL;
|
|
|
|
path = "<data>";
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Theme parsing error: %s:%u:%u: %s",
|
|
|
|
path,
|
|
|
|
gtk_css_section_get_end_line (section) + 1,
|
|
|
|
gtk_css_section_get_end_position (section),
|
|
|
|
error->message);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
2011-04-10 23:51:49 +00:00
|
|
|
}
|
2011-04-07 15:26:47 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_class_init (GtkCssProviderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
/**
|
|
|
|
* GtkCssProvider::parsing-error:
|
|
|
|
* @provider: the provider that had a parsing error
|
2011-06-17 05:39:11 +00:00
|
|
|
* @section: section the error happened in
|
2011-04-07 15:26:47 +00:00
|
|
|
* @error: The parsing error
|
|
|
|
*
|
|
|
|
* Signals that a parsing error occured. the @path, @line and @position
|
|
|
|
* describe the actual location of the error as accurately as possible.
|
|
|
|
*
|
|
|
|
* Parsing errors are never fatal, so the parsing will resume after
|
|
|
|
* the error. Errors may however cause parts of the given
|
|
|
|
* data or even all of it to not be parsed at all. So it is a useful idea
|
|
|
|
* to check that the parsing succeeds by connecting to this signal.
|
|
|
|
*
|
|
|
|
* Note that this signal may be emitted at any time as the css provider
|
|
|
|
* may opt to defer parsing parts or all of the input to a later time
|
|
|
|
* than when a loading function was called.
|
|
|
|
*/
|
|
|
|
css_provider_signals[PARSING_ERROR] =
|
|
|
|
g_signal_new (I_("parsing-error"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkCssProviderClass, parsing_error),
|
|
|
|
NULL, NULL,
|
2011-06-17 05:39:11 +00:00
|
|
|
_gtk_marshal_VOID__BOXED_BOXED,
|
|
|
|
G_TYPE_NONE, 2, GTK_TYPE_CSS_SECTION, G_TYPE_ERROR);
|
2011-04-07 15:26:47 +00:00
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
object_class->finalize = gtk_css_provider_finalize;
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
klass->parsing_error = gtk_css_provider_parsing_error;
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
g_type_class_add_private (object_class, sizeof (GtkCssProviderPrivate));
|
|
|
|
}
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
static void
|
|
|
|
gtk_css_ruleset_init_copy (GtkCssRuleset *new,
|
|
|
|
const GtkCssRuleset *ruleset,
|
|
|
|
GtkCssSelector *selector)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
memcpy (new, ruleset, sizeof (GtkCssRuleset));
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
new->selector = selector;
|
2011-05-18 02:36:43 +00:00
|
|
|
if (new->widget_style)
|
|
|
|
g_hash_table_ref (new->widget_style);
|
2011-05-18 02:20:05 +00:00
|
|
|
if (new->style)
|
|
|
|
g_hash_table_ref (new->style);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_clear (GtkCssRuleset *ruleset)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-17 20:04:40 +00:00
|
|
|
if (ruleset->style)
|
|
|
|
g_hash_table_unref (ruleset->style);
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->widget_style)
|
|
|
|
g_hash_table_unref (ruleset->widget_style);
|
2011-05-17 20:04:40 +00:00
|
|
|
if (ruleset->selector)
|
|
|
|
_gtk_css_selector_free (ruleset->selector);
|
2011-01-16 11:52:43 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
memset (ruleset, 0, sizeof (GtkCssRuleset));
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
typedef struct _PropertyValue PropertyValue;
|
|
|
|
struct _PropertyValue {
|
|
|
|
GtkCssSection *section;
|
|
|
|
GValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PropertyValue *
|
|
|
|
property_value_new (GtkCssSection *section)
|
|
|
|
{
|
|
|
|
PropertyValue *value;
|
|
|
|
|
|
|
|
value = g_slice_new0 (PropertyValue);
|
|
|
|
|
|
|
|
value->section = gtk_css_section_ref (section);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void
|
2011-06-17 03:58:04 +00:00
|
|
|
property_value_free (PropertyValue *value)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-06-17 03:58:04 +00:00
|
|
|
if (G_IS_VALUE (&value->value))
|
|
|
|
g_value_unset (&value->value);
|
|
|
|
|
|
|
|
gtk_css_section_unref (value->section);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
g_slice_free (PropertyValue, value);
|
2011-05-18 02:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_ruleset_add_style (GtkCssRuleset *ruleset,
|
|
|
|
char *name,
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *value)
|
2011-05-18 02:20:05 +00:00
|
|
|
{
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->widget_style == NULL)
|
|
|
|
ruleset->widget_style = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
|
|
|
(GDestroyNotify) property_value_free);
|
2011-05-18 02:20:05 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
g_hash_table_insert (ruleset->widget_style, name, value);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 02:30:51 +00:00
|
|
|
static void
|
2011-05-21 19:17:08 +00:00
|
|
|
gtk_css_ruleset_add (GtkCssRuleset *ruleset,
|
|
|
|
const GtkStyleProperty *prop,
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *value)
|
2011-05-18 02:30:51 +00:00
|
|
|
{
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->style == NULL)
|
|
|
|
ruleset->style = g_hash_table_new_full (g_direct_hash,
|
|
|
|
g_direct_equal,
|
|
|
|
NULL,
|
|
|
|
(GDestroyNotify) property_value_free);
|
|
|
|
|
2011-05-21 21:47:19 +00:00
|
|
|
if (_gtk_style_property_is_shorthand (prop))
|
|
|
|
{
|
|
|
|
GParameter *parameters;
|
|
|
|
guint i, n_parameters;
|
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
parameters = _gtk_style_property_unpack (prop, &value->value, &n_parameters);
|
2011-05-21 21:47:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_parameters; i++)
|
|
|
|
{
|
|
|
|
const GtkStyleProperty *child;
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *val;
|
2011-05-30 17:04:22 +00:00
|
|
|
|
2011-05-21 21:47:19 +00:00
|
|
|
child = _gtk_style_property_lookup (parameters[i].name);
|
2011-06-17 03:58:04 +00:00
|
|
|
val = property_value_new (value->section);
|
|
|
|
memcpy (&val->value, ¶meters[i].value, sizeof (GValue));
|
|
|
|
gtk_css_ruleset_add (ruleset, child, val);
|
2011-05-21 21:47:19 +00:00
|
|
|
}
|
|
|
|
g_free (parameters);
|
2011-05-30 17:29:22 +00:00
|
|
|
property_value_free (value);
|
2011-05-21 21:47:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-31 10:05:43 +00:00
|
|
|
ruleset->has_inherit |= _gtk_style_property_is_inherit (prop);
|
2011-05-21 19:17:08 +00:00
|
|
|
g_hash_table_insert (ruleset->style, (gpointer) prop, value);
|
2011-05-18 02:30:51 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 20:11:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_ruleset_matches (GtkCssRuleset *ruleset,
|
|
|
|
GtkWidgetPath *path,
|
|
|
|
guint length)
|
|
|
|
{
|
|
|
|
return _gtk_css_selector_matches (ruleset->selector, path, length);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
gtk_css_scanner_destroy (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
g_object_unref (scanner->provider);
|
|
|
|
if (scanner->file)
|
|
|
|
g_object_unref (scanner->file);
|
|
|
|
g_object_unref (scanner->base);
|
|
|
|
_gtk_css_parser_free (scanner->parser);
|
|
|
|
|
|
|
|
g_slice_free (GtkCssScanner, scanner);
|
2011-04-10 01:51:43 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 05:39:11 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_emit_error (GtkCssProvider *provider,
|
|
|
|
GtkCssScanner *scanner,
|
|
|
|
const GError *error)
|
|
|
|
{
|
|
|
|
g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0,
|
|
|
|
scanner->section, error);
|
|
|
|
}
|
|
|
|
|
2011-04-10 01:35:19 +00:00
|
|
|
static void
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_scanner_parser_error (GtkCssParser *parser,
|
|
|
|
const GError *error,
|
|
|
|
gpointer user_data)
|
2011-04-10 01:35:19 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner = user_data;
|
2011-04-10 23:28:00 +00:00
|
|
|
|
2011-06-17 05:39:11 +00:00
|
|
|
gtk_css_provider_emit_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
error);
|
2011-04-10 01:35:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static GtkCssScanner *
|
|
|
|
gtk_css_scanner_new (GtkCssProvider *provider,
|
|
|
|
GtkCssScanner *parent,
|
2011-06-17 02:52:43 +00:00
|
|
|
GtkCssSection *section,
|
2011-04-14 02:47:18 +00:00
|
|
|
GFile *file,
|
2011-06-17 03:15:48 +00:00
|
|
|
const gchar *text)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner = g_slice_new0 (GtkCssScanner);
|
2011-04-10 01:39:52 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
g_object_ref (provider);
|
|
|
|
scanner->provider = provider;
|
|
|
|
scanner->parent = parent;
|
2011-06-17 02:52:43 +00:00
|
|
|
if (section)
|
|
|
|
scanner->section = gtk_css_section_ref (section);
|
2011-04-12 00:06:08 +00:00
|
|
|
|
2011-04-11 14:48:00 +00:00
|
|
|
if (file)
|
2011-04-11 15:30:01 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner->file = g_object_ref (file);
|
|
|
|
scanner->base = g_file_get_parent (file);
|
2011-04-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *dir = g_get_current_dir ();
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner->base = g_file_new_for_path (dir);
|
2011-04-11 15:30:01 +00:00
|
|
|
g_free (dir);
|
|
|
|
}
|
2011-04-11 14:48:00 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
scanner->parser = _gtk_css_parser_new (text,
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_scanner_parser_error,
|
|
|
|
scanner);
|
2011-04-11 14:48:00 +00:00
|
|
|
|
2010-10-08 16:36:46 +00:00
|
|
|
return scanner;
|
|
|
|
}
|
|
|
|
|
2011-04-11 15:30:01 +00:00
|
|
|
static GFile *
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_scanner_get_base_url (GtkCssScanner *scanner)
|
2011-04-11 15:30:01 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
return scanner->base;
|
2011-04-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 00:50:25 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_scanner_would_recurse (GtkCssScanner *scanner,
|
|
|
|
GFile *file)
|
2011-04-12 00:50:25 +00:00
|
|
|
{
|
|
|
|
while (scanner)
|
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
if (scanner->file && g_file_equal (scanner->file, file))
|
2011-04-12 00:50:25 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
scanner = scanner->parent;
|
2011-04-12 00:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static void
|
|
|
|
gtk_css_scanner_push_section (GtkCssScanner *scanner,
|
|
|
|
GtkCssSectionType section_type)
|
|
|
|
{
|
2011-06-17 02:52:43 +00:00
|
|
|
GtkCssSection *section;
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2011-06-17 02:52:43 +00:00
|
|
|
section = _gtk_css_section_new (scanner->section,
|
2011-06-17 00:02:24 +00:00
|
|
|
section_type,
|
|
|
|
scanner->parser,
|
|
|
|
scanner->file);
|
2011-06-17 02:52:43 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
if (scanner->section)
|
|
|
|
gtk_css_section_unref (scanner->section);
|
2011-06-17 02:52:43 +00:00
|
|
|
scanner->section = section;
|
2011-06-17 00:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_scanner_pop_section (GtkCssScanner *scanner,
|
|
|
|
GtkCssSectionType check_type)
|
|
|
|
{
|
2011-06-17 02:52:43 +00:00
|
|
|
GtkCssSection *parent;
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2011-06-17 02:52:43 +00:00
|
|
|
g_assert (gtk_css_section_get_section_type (scanner->section) == check_type);
|
|
|
|
|
|
|
|
parent = gtk_css_section_get_parent (scanner->section);
|
|
|
|
if (parent)
|
|
|
|
gtk_css_section_ref (parent);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2011-06-17 02:52:43 +00:00
|
|
|
_gtk_css_section_end (scanner->section);
|
|
|
|
gtk_css_section_unref (scanner->section);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2011-06-17 02:52:43 +00:00
|
|
|
scanner->section = parent;
|
2011-06-17 00:02:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 16:36:46 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_init (GtkCssProvider *css_provider)
|
|
|
|
{
|
|
|
|
GtkCssProviderPrivate *priv;
|
|
|
|
|
|
|
|
priv = css_provider->priv = G_TYPE_INSTANCE_GET_PRIVATE (css_provider,
|
|
|
|
GTK_TYPE_CSS_PROVIDER,
|
|
|
|
GtkCssProviderPrivate);
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
priv->rulesets = g_array_new (FALSE, FALSE, sizeof (GtkCssRuleset));
|
2010-06-25 18:27:15 +00:00
|
|
|
|
|
|
|
priv->symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
|
|
|
(GDestroyNotify) gtk_symbolic_color_unref);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 18:27:15 +00:00
|
|
|
static void
|
2010-10-29 04:47:32 +00:00
|
|
|
css_provider_dump_symbolic_colors (GtkCssProvider *css_provider,
|
|
|
|
GtkStyleProperties *props)
|
2010-06-25 18:27:15 +00:00
|
|
|
{
|
|
|
|
GtkCssProviderPrivate *priv;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
2010-07-03 00:19:27 +00:00
|
|
|
priv = css_provider->priv;
|
2010-06-25 18:27:15 +00:00
|
|
|
g_hash_table_iter_init (&iter, priv->symbolic_colors);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
GtkSymbolicColor *color;
|
|
|
|
|
|
|
|
name = key;
|
|
|
|
color = value;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_map_color (props, name, color);
|
2010-06-25 18:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
static GtkStyleProperties *
|
2010-06-18 14:52:34 +00:00
|
|
|
gtk_css_provider_get_style (GtkStyleProvider *provider,
|
|
|
|
GtkWidgetPath *path)
|
|
|
|
{
|
2010-07-03 00:19:27 +00:00
|
|
|
GtkCssProvider *css_provider;
|
2011-05-16 17:54:57 +00:00
|
|
|
GtkCssProviderPrivate *priv;
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStyleProperties *props;
|
2011-05-17 13:01:59 +00:00
|
|
|
guint i, l, length;
|
2010-06-18 14:52:34 +00:00
|
|
|
|
2010-07-03 00:19:27 +00:00
|
|
|
css_provider = GTK_CSS_PROVIDER (provider);
|
2011-05-16 17:54:57 +00:00
|
|
|
priv = css_provider->priv;
|
2011-05-17 13:01:59 +00:00
|
|
|
length = gtk_widget_path_length (path);
|
2010-10-29 04:47:32 +00:00
|
|
|
props = gtk_style_properties_new ();
|
2010-06-18 14:52:34 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
css_provider_dump_symbolic_colors (css_provider, props);
|
2010-06-18 14:52:34 +00:00
|
|
|
|
2011-05-17 13:01:59 +00:00
|
|
|
for (l = 1; l <= length; l++)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-17 20:04:40 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
2011-05-17 13:01:59 +00:00
|
|
|
{
|
2011-05-17 20:04:40 +00:00
|
|
|
GtkCssRuleset *ruleset;
|
2011-05-17 13:01:59 +00:00
|
|
|
GHashTableIter iter;
|
2011-06-17 03:58:04 +00:00
|
|
|
gpointer key, val;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
|
2011-05-16 17:54:57 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->style == NULL)
|
|
|
|
continue;
|
|
|
|
|
2011-05-18 03:47:18 +00:00
|
|
|
if (l < length && (!ruleset->has_inherit || _gtk_css_selector_get_state_flags (ruleset->selector)))
|
2011-05-17 13:01:59 +00:00
|
|
|
continue;
|
2011-05-16 17:54:57 +00:00
|
|
|
|
2011-05-17 20:11:50 +00:00
|
|
|
if (!gtk_css_ruleset_matches (ruleset, path, l))
|
2011-05-17 13:01:59 +00:00
|
|
|
continue;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
g_hash_table_iter_init (&iter, ruleset->style);
|
2011-05-16 21:37:29 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, &key, &val))
|
2011-05-17 13:01:59 +00:00
|
|
|
{
|
2011-05-21 19:17:08 +00:00
|
|
|
GtkStyleProperty *prop = key;
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *value = val;
|
2011-05-17 13:01:59 +00:00
|
|
|
|
2011-05-31 10:05:43 +00:00
|
|
|
if (l != length && !_gtk_style_property_is_inherit (prop))
|
2011-05-17 13:01:59 +00:00
|
|
|
continue;
|
2010-08-04 15:51:19 +00:00
|
|
|
|
2011-05-21 19:17:08 +00:00
|
|
|
_gtk_style_properties_set_property_by_property (props,
|
|
|
|
prop,
|
|
|
|
_gtk_css_selector_get_state_flags (ruleset->selector),
|
2011-06-17 03:58:04 +00:00
|
|
|
&value->value);
|
2011-05-17 13:01:59 +00:00
|
|
|
}
|
2010-05-04 17:58:07 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
return props;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-18 15:04:03 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_provider_get_style_property (GtkStyleProvider *provider,
|
|
|
|
GtkWidgetPath *path,
|
2010-11-30 01:14:00 +00:00
|
|
|
GtkStateFlags state,
|
2010-11-17 01:42:27 +00:00
|
|
|
GParamSpec *pspec,
|
2010-06-18 15:04:03 +00:00
|
|
|
GValue *value)
|
|
|
|
{
|
2011-05-16 15:55:50 +00:00
|
|
|
GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider);
|
|
|
|
GtkCssProviderPrivate *priv = css_provider->priv;
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *val;
|
2010-06-18 15:04:03 +00:00
|
|
|
gboolean found = FALSE;
|
|
|
|
gchar *prop_name;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
prop_name = g_strdup_printf ("-%s-%s",
|
2010-11-17 01:42:27 +00:00
|
|
|
g_type_name (pspec->owner_type),
|
|
|
|
pspec->name);
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
for (i = priv->rulesets->len - 1; i >= 0; i--)
|
2010-06-18 15:04:03 +00:00
|
|
|
{
|
2011-05-17 20:04:40 +00:00
|
|
|
GtkCssRuleset *ruleset;
|
2011-05-16 15:55:50 +00:00
|
|
|
GtkStateFlags selector_state;
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
|
2011-05-16 15:55:50 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->widget_style == NULL)
|
|
|
|
continue;
|
|
|
|
|
2011-05-17 20:11:50 +00:00
|
|
|
if (!gtk_css_ruleset_matches (ruleset, path, gtk_widget_path_length (path)))
|
2011-05-16 15:55:50 +00:00
|
|
|
continue;
|
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
selector_state = _gtk_css_selector_get_state_flags (ruleset->selector);
|
2011-05-18 02:36:43 +00:00
|
|
|
val = g_hash_table_lookup (ruleset->widget_style, prop_name);
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2010-11-30 01:14:00 +00:00
|
|
|
if (val &&
|
2011-05-16 15:55:50 +00:00
|
|
|
(selector_state == 0 ||
|
|
|
|
selector_state == state ||
|
|
|
|
((selector_state & state) != 0 &&
|
|
|
|
(selector_state & ~(state)) == 0)))
|
2010-06-18 15:04:03 +00:00
|
|
|
{
|
2011-06-17 03:58:04 +00:00
|
|
|
GtkCssScanner *scanner;
|
2011-05-18 16:32:22 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
scanner = gtk_css_scanner_new (css_provider,
|
|
|
|
NULL,
|
|
|
|
val->section,
|
|
|
|
gtk_css_section_get_file (val->section),
|
|
|
|
g_value_get_string (&val->value));
|
2011-05-18 16:32:22 +00:00
|
|
|
|
2011-05-25 23:01:44 +00:00
|
|
|
found = _gtk_style_property_parse_value (NULL,
|
|
|
|
value,
|
2011-06-17 03:58:04 +00:00
|
|
|
scanner->parser,
|
2011-05-25 23:01:44 +00:00
|
|
|
NULL);
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_destroy (scanner);
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-04-08 14:08:28 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
2010-06-18 15:04:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (prop_name);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
static void
|
|
|
|
gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface)
|
|
|
|
{
|
2010-06-18 15:04:03 +00:00
|
|
|
iface->get_style = gtk_css_provider_get_style;
|
|
|
|
iface->get_style_property = gtk_css_provider_get_style_property;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_provider_finalize (GObject *object)
|
|
|
|
{
|
2010-07-03 00:19:27 +00:00
|
|
|
GtkCssProvider *css_provider;
|
2010-04-11 21:03:25 +00:00
|
|
|
GtkCssProviderPrivate *priv;
|
2011-05-30 17:26:28 +00:00
|
|
|
guint i;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2010-07-03 00:19:27 +00:00
|
|
|
css_provider = GTK_CSS_PROVIDER (object);
|
|
|
|
priv = css_provider->priv;
|
2010-06-19 14:04:30 +00:00
|
|
|
|
2011-05-30 17:26:28 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_array_free (priv->rulesets, TRUE);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2010-11-18 03:29:39 +00:00
|
|
|
if (priv->symbolic_colors)
|
|
|
|
g_hash_table_destroy (priv->symbolic_colors);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_new:
|
|
|
|
*
|
|
|
|
* Returns a newly created #GtkCssProvider.
|
|
|
|
*
|
|
|
|
* Returns: A new #GtkCssProvider
|
|
|
|
**/
|
2010-04-11 21:03:25 +00:00
|
|
|
GtkCssProvider *
|
|
|
|
gtk_css_provider_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_CSS_PROVIDER, NULL);
|
|
|
|
}
|
|
|
|
|
2011-04-07 15:26:47 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_take_error (GtkCssProvider *provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-07 15:26:47 +00:00
|
|
|
GError *error)
|
|
|
|
{
|
2011-06-17 05:39:11 +00:00
|
|
|
gtk_css_provider_emit_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
error);
|
|
|
|
|
|
|
|
g_error_free (error);
|
2011-04-07 15:26:47 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:18:02 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_error_literal (GtkCssProvider *provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-09 16:18:02 +00:00
|
|
|
GQuark domain,
|
|
|
|
gint code,
|
|
|
|
const char *message)
|
|
|
|
{
|
|
|
|
gtk_css_provider_take_error (provider,
|
2011-04-10 13:22:07 +00:00
|
|
|
scanner,
|
2011-04-09 16:18:02 +00:00
|
|
|
g_error_new_literal (domain, code, message));
|
|
|
|
}
|
|
|
|
|
2011-04-07 11:37:03 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_error (GtkCssProvider *provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-07 11:37:03 +00:00
|
|
|
GQuark domain,
|
|
|
|
gint code,
|
|
|
|
const char *format,
|
2011-04-10 13:22:07 +00:00
|
|
|
...) G_GNUC_PRINTF (5, 6);
|
2011-04-07 11:37:03 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_error (GtkCssProvider *provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-07 11:37:03 +00:00
|
|
|
GQuark domain,
|
|
|
|
gint code,
|
|
|
|
const char *format,
|
|
|
|
...)
|
|
|
|
{
|
2011-04-07 15:26:47 +00:00
|
|
|
GError *error;
|
2011-04-07 11:37:03 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, format);
|
2011-04-07 15:26:47 +00:00
|
|
|
error = g_error_new_valist (domain, code, format, args);
|
2011-04-07 11:37:03 +00:00
|
|
|
va_end (args);
|
|
|
|
|
2011-04-10 13:22:07 +00:00
|
|
|
gtk_css_provider_take_error (provider, scanner, error);
|
2011-04-07 12:03:08 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 13:38:06 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_invalid_token (GtkCssProvider *provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner,
|
2011-04-06 13:38:06 +00:00
|
|
|
const char *expected)
|
|
|
|
{
|
2011-04-07 11:37:03 +00:00
|
|
|
gtk_css_provider_error (provider,
|
2011-04-10 13:22:07 +00:00
|
|
|
scanner,
|
2011-04-07 11:37:03 +00:00
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
2011-04-07 22:18:38 +00:00
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
2011-04-07 11:37:03 +00:00
|
|
|
"expected a valid %s", expected);
|
2011-04-06 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
2011-04-10 23:28:00 +00:00
|
|
|
css_provider_commit (GtkCssProvider *css_provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GSList *selectors,
|
2011-05-18 02:20:05 +00:00
|
|
|
GtkCssRuleset *ruleset)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
|
|
|
GtkCssProviderPrivate *priv;
|
|
|
|
GSList *l;
|
|
|
|
|
2010-07-03 00:19:27 +00:00
|
|
|
priv = css_provider->priv;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->style == NULL && ruleset->widget_style == NULL)
|
2011-05-14 11:27:31 +00:00
|
|
|
{
|
|
|
|
g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-07 00:15:02 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
for (l = selectors; l; l = l->next)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
GtkCssRuleset new;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_init_copy (&new, ruleset, l->data);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_array_append_val (priv->rulesets, new);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
2011-05-14 11:27:31 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_slist_free (selectors);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_reset (GtkCssProvider *css_provider)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssProviderPrivate *priv;
|
2011-05-18 02:20:05 +00:00
|
|
|
guint i;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
priv = css_provider->priv;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-05-27 23:01:42 +00:00
|
|
|
g_hash_table_remove_all (priv->symbolic_colors);
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
|
|
|
gtk_css_ruleset_clear (&g_array_index (priv->rulesets, GtkCssRuleset, i));
|
|
|
|
g_array_set_size (priv->rulesets, 0);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
gtk_css_provider_propagate_error (GtkCssProvider *provider,
|
2011-08-31 22:24:53 +00:00
|
|
|
GtkCssSection *section,
|
2011-04-14 02:47:18 +00:00
|
|
|
const GError *error,
|
|
|
|
GError **propagate_to)
|
|
|
|
{
|
2011-08-31 22:24:53 +00:00
|
|
|
|
|
|
|
GFileInfo *info;
|
|
|
|
GFile *file;
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
file = gtk_css_section_get_file (section);
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
info = g_file_query_info (file,G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
path = g_file_info_get_display_name (info);
|
|
|
|
else
|
|
|
|
path = "<broken file>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = NULL;
|
|
|
|
path = "<unknown>";
|
|
|
|
}
|
|
|
|
|
2011-05-18 16:35:37 +00:00
|
|
|
/* don't fail for deprecations */
|
|
|
|
if (g_error_matches (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_DEPRECATED))
|
|
|
|
{
|
2011-08-31 22:24:53 +00:00
|
|
|
g_warning ("Theme parsing error: %s:%u:%u: %s", path,
|
|
|
|
gtk_css_section_get_end_line (section) + 1,
|
|
|
|
gtk_css_section_get_end_position (section), error->message);
|
2011-05-18 16:35:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
/* we already set an error. And we'd like to keep the first one */
|
|
|
|
if (*propagate_to)
|
|
|
|
return;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
*propagate_to = g_error_copy (error);
|
2011-08-31 22:24:53 +00:00
|
|
|
g_prefix_error (propagate_to, "%s:%u:%u: ", path,
|
|
|
|
gtk_css_section_get_end_line (section) + 1,
|
|
|
|
gtk_css_section_get_end_position (section));
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_import (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
char *uri;
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_IMPORT);
|
|
|
|
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "@import", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_IMPORT);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-19 23:19:59 +00:00
|
|
|
if (_gtk_css_parser_is_string (scanner->parser))
|
|
|
|
uri = _gtk_css_parser_read_string (scanner->parser);
|
|
|
|
else
|
|
|
|
uri = _gtk_css_parser_read_uri (scanner->parser);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (uri == NULL)
|
|
|
|
{
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_IMPORT);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
file = g_file_resolve_relative_path (gtk_css_scanner_get_base_url (scanner), uri);
|
|
|
|
g_free (uri);
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (gtk_css_scanner_would_recurse (scanner, file))
|
|
|
|
{
|
|
|
|
char *path = g_file_get_path (file);
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_IMPORT,
|
|
|
|
"Loading '%s' would recurse",
|
|
|
|
path);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_provider_load_internal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
file,
|
2011-06-17 03:15:48 +00:00
|
|
|
NULL,
|
2011-04-14 02:47:18 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_invalid_token (scanner->provider, scanner, "semicolon");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
g_object_unref (file);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_IMPORT);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-10-08 16:19:34 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_color_definition (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
char *name;
|
2010-10-08 16:19:34 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "@define-color", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
name = _gtk_css_parser_try_name (scanner->parser, TRUE);
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Not a valid color name");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
symbolic = _gtk_css_parser_read_symbolic_color (scanner->parser);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
|
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
gtk_symbolic_color_unref (symbolic);
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Missing semicolon at end of color definition");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-11-18 06:59:27 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
g_hash_table_insert (scanner->provider->priv->symbolic_colors, name, symbolic);
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_COLOR_DEFINITION);
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-04-08 14:08:28 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
static gboolean
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_binding_set (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
GtkBindingSet *binding_set;
|
|
|
|
char *name;
|
2011-04-08 14:08:28 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_BINDING_SET);
|
|
|
|
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "@binding-set", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_BINDING_SET);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Expected name for binding set");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
|
|
|
goto skip_semicolon;
|
|
|
|
}
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
binding_set = gtk_binding_set_find (name);
|
|
|
|
if (!binding_set)
|
|
|
|
{
|
|
|
|
binding_set = gtk_binding_set_new (name);
|
|
|
|
binding_set->parsed = TRUE;
|
|
|
|
}
|
|
|
|
g_free (name);
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "{", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
2011-04-12 00:50:25 +00:00
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
2011-04-14 02:47:18 +00:00
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Expected '{' for binding set");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
|
|
|
goto skip_semicolon;
|
|
|
|
}
|
2010-10-08 16:36:46 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
while (!_gtk_css_parser_is_eof (scanner->parser) &&
|
|
|
|
!_gtk_css_parser_begins_with (scanner->parser, '}'))
|
|
|
|
{
|
|
|
|
name = _gtk_css_parser_read_value (scanner->parser);
|
|
|
|
if (name == NULL)
|
2011-01-28 00:52:03 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-07-20 00:11:51 +00:00
|
|
|
if (gtk_binding_entry_add_signal_from_string (binding_set, name) != G_TOKEN_NONE)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Failed to parse binding set.");
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
g_free (name);
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
|
|
|
|
{
|
|
|
|
if (!_gtk_css_parser_begins_with (scanner->parser, '}') &&
|
|
|
|
!_gtk_css_parser_is_eof (scanner->parser))
|
2011-01-28 00:52:03 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Expected semicolon");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
2011-01-28 00:52:03 +00:00
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "}", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"expected '}' after declarations");
|
|
|
|
if (!_gtk_css_parser_is_eof (scanner->parser))
|
|
|
|
_gtk_css_parser_resync (scanner->parser, FALSE, 0);
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
skip_semicolon:
|
2011-07-20 00:01:34 +00:00
|
|
|
if (_gtk_css_parser_begins_with (scanner->parser, ';'))
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_DEPRECATED,
|
|
|
|
"Nonstandard semicolon at end of binding set");
|
|
|
|
_gtk_css_parser_try (scanner->parser, ";", TRUE);
|
|
|
|
}
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_BINDING_SET);
|
|
|
|
|
|
|
|
return TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
|
|
|
parse_at_keyword (GtkCssScanner *scanner)
|
|
|
|
{
|
2011-06-17 00:02:24 +00:00
|
|
|
if (parse_import (scanner))
|
|
|
|
return;
|
|
|
|
if (parse_color_definition (scanner))
|
|
|
|
return;
|
|
|
|
if (parse_binding_set (scanner))
|
|
|
|
return;
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"unknown @ rule");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, 0);
|
|
|
|
}
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static gboolean
|
2011-05-14 11:27:31 +00:00
|
|
|
parse_selector_class (GtkCssScanner *scanner, GArray *classes)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
GQuark qname;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = _gtk_css_parser_try_name (scanner->parser, FALSE);
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
2011-05-14 11:27:31 +00:00
|
|
|
"Expected a valid name for class");
|
2011-04-14 02:47:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-29 00:36:24 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
qname = g_quark_from_string (name);
|
|
|
|
g_array_append_val (classes, qname);
|
|
|
|
g_free (name);
|
2011-04-14 02:47:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static gboolean
|
2011-05-14 11:27:31 +00:00
|
|
|
parse_selector_name (GtkCssScanner *scanner, GArray *names)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
GQuark qname;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = _gtk_css_parser_try_name (scanner->parser, FALSE);
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
2011-05-14 11:27:31 +00:00
|
|
|
"Expected a valid name for id");
|
2011-04-14 02:47:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
qname = g_quark_from_string (name);
|
|
|
|
g_array_append_val (names, qname);
|
|
|
|
g_free (name);
|
2011-04-14 02:47:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-01-28 00:52:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static gboolean
|
2011-05-14 21:54:37 +00:00
|
|
|
parse_selector_pseudo_class (GtkCssScanner *scanner,
|
|
|
|
GtkRegionFlags *region_to_modify,
|
|
|
|
GtkStateFlags *state_to_modify)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
const char *name;
|
2011-05-14 21:54:37 +00:00
|
|
|
GtkRegionFlags region_flag;
|
|
|
|
GtkStateFlags state_flag;
|
|
|
|
} pseudo_classes[] = {
|
2011-07-20 09:59:15 +00:00
|
|
|
{ "first-child", GTK_REGION_FIRST, 0 },
|
|
|
|
{ "last-child", GTK_REGION_LAST, 0 },
|
2011-05-14 21:54:37 +00:00
|
|
|
{ "sorted", GTK_REGION_SORTED, 0 },
|
|
|
|
{ "active", 0, GTK_STATE_FLAG_ACTIVE },
|
|
|
|
{ "prelight", 0, GTK_STATE_FLAG_PRELIGHT },
|
|
|
|
{ "hover", 0, GTK_STATE_FLAG_PRELIGHT },
|
|
|
|
{ "selected", 0, GTK_STATE_FLAG_SELECTED },
|
|
|
|
{ "insensitive", 0, GTK_STATE_FLAG_INSENSITIVE },
|
|
|
|
{ "inconsistent", 0, GTK_STATE_FLAG_INCONSISTENT },
|
|
|
|
{ "focused", 0, GTK_STATE_FLAG_FOCUSED },
|
|
|
|
{ "focus", 0, GTK_STATE_FLAG_FOCUSED },
|
|
|
|
{ NULL, }
|
|
|
|
}, nth_child_classes[] = {
|
|
|
|
{ "first", GTK_REGION_FIRST, 0 },
|
|
|
|
{ "last", GTK_REGION_LAST, 0 },
|
|
|
|
{ "even", GTK_REGION_EVEN, 0 },
|
|
|
|
{ "odd", GTK_REGION_ODD, 0 },
|
|
|
|
{ NULL, }
|
|
|
|
}, *classes;
|
2011-04-14 02:47:18 +00:00
|
|
|
guint i;
|
2011-05-14 21:54:37 +00:00
|
|
|
char *name;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2011-05-14 21:54:37 +00:00
|
|
|
name = _gtk_css_parser_try_ident (scanner->parser, FALSE);
|
|
|
|
if (name == NULL)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-14 21:54:37 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Missing name of pseudo-class");
|
|
|
|
return FALSE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 21:54:37 +00:00
|
|
|
if (_gtk_css_parser_try (scanner->parser, "(", TRUE))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-14 21:54:37 +00:00
|
|
|
char *function = name;
|
|
|
|
|
|
|
|
name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ")", FALSE))
|
2010-12-03 20:56:39 +00:00
|
|
|
{
|
2011-05-14 21:54:37 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Missing closing bracket for pseudo-class");
|
|
|
|
return FALSE;
|
2010-12-03 20:56:39 +00:00
|
|
|
}
|
2010-06-25 18:27:15 +00:00
|
|
|
|
2011-05-14 21:54:37 +00:00
|
|
|
if (g_ascii_strcasecmp (function, "nth-child") != 0)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
|
|
|
|
"Unknown pseudo-class '%s(%s)'", function, name ? name : "");
|
|
|
|
g_free (function);
|
|
|
|
g_free (name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (function);
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
|
|
|
|
"nth-child() requires an argument");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
classes = nth_child_classes;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-05-14 21:54:37 +00:00
|
|
|
else
|
|
|
|
classes = pseudo_classes;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-14 21:54:37 +00:00
|
|
|
for (i = 0; classes[i].name != NULL; i++)
|
2010-04-20 23:51:46 +00:00
|
|
|
{
|
2011-05-14 21:54:37 +00:00
|
|
|
if (g_ascii_strcasecmp (name, classes[i].name) == 0)
|
|
|
|
{
|
|
|
|
if ((*region_to_modify & classes[i].region_flag) ||
|
|
|
|
(*state_to_modify & classes[i].state_flag))
|
|
|
|
{
|
|
|
|
if (classes == nth_child_classes)
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Duplicate pseudo-class 'nth-child(%s)'", name);
|
|
|
|
else
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Duplicate pseudo-class '%s'", name);
|
|
|
|
}
|
|
|
|
*region_to_modify |= classes[i].region_flag;
|
|
|
|
*state_to_modify |= classes[i].state_flag;
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-04-20 23:51:46 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-14 21:54:37 +00:00
|
|
|
if (classes == nth_child_classes)
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
|
|
|
|
"Unknown pseudo-class 'nth-child(%s)'", name);
|
|
|
|
else
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_UNKNOWN_VALUE,
|
|
|
|
"Unknown pseudo-class '%s'", name);
|
|
|
|
g_free (name);
|
|
|
|
return FALSE;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static gboolean
|
2011-05-14 11:27:31 +00:00
|
|
|
parse_simple_selector (GtkCssScanner *scanner,
|
|
|
|
char **name,
|
|
|
|
GArray *ids,
|
|
|
|
GArray *classes,
|
|
|
|
GtkRegionFlags *pseudo_classes,
|
|
|
|
GtkStateFlags *state)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
gboolean parsed_something;
|
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
*name = _gtk_css_parser_try_ident (scanner->parser, FALSE);
|
|
|
|
if (*name)
|
2011-05-14 21:54:37 +00:00
|
|
|
parsed_something = TRUE;
|
2011-04-14 02:47:18 +00:00
|
|
|
else
|
2011-05-14 21:54:37 +00:00
|
|
|
parsed_something = _gtk_css_parser_try (scanner->parser, "*", FALSE);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
do {
|
|
|
|
if (_gtk_css_parser_try (scanner->parser, "#", FALSE))
|
2011-04-09 16:18:02 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
if (!parse_selector_name (scanner, ids))
|
2011-04-14 02:47:18 +00:00
|
|
|
return FALSE;
|
2011-04-09 16:18:02 +00:00
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
else if (_gtk_css_parser_try (scanner->parser, ".", FALSE))
|
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
if (!parse_selector_class (scanner, classes))
|
2011-04-14 02:47:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (_gtk_css_parser_try (scanner->parser, ":", FALSE))
|
|
|
|
{
|
2011-05-14 21:54:37 +00:00
|
|
|
if (!parse_selector_pseudo_class (scanner, pseudo_classes, state))
|
2011-04-14 02:47:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (!parsed_something)
|
2011-04-09 16:18:02 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
2011-04-10 13:22:07 +00:00
|
|
|
scanner,
|
2011-04-09 16:18:02 +00:00
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
2011-04-14 02:47:18 +00:00
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Expected a valid selector");
|
|
|
|
return FALSE;
|
2011-04-09 16:18:02 +00:00
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
else
|
|
|
|
break;
|
2011-04-09 16:18:02 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
parsed_something = TRUE;
|
|
|
|
}
|
|
|
|
while (!_gtk_css_parser_is_eof (scanner->parser));
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
_gtk_css_parser_skip_whitespace (scanner->parser);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
static GtkCssSelector *
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_selector (GtkCssScanner *scanner)
|
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
GtkCssSelector *selector = NULL;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
|
|
|
do {
|
2011-05-14 11:27:31 +00:00
|
|
|
char *name = NULL;
|
|
|
|
GArray *ids = g_array_new (TRUE, FALSE, sizeof (GQuark));
|
|
|
|
GArray *classes = g_array_new (TRUE, FALSE, sizeof (GQuark));
|
|
|
|
GtkRegionFlags pseudo_classes = 0;
|
|
|
|
GtkStateFlags state = 0;
|
|
|
|
GtkCssCombinator combine = GTK_CSS_COMBINE_DESCANDANT;
|
|
|
|
|
|
|
|
if (selector)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
if (_gtk_css_parser_try (scanner->parser, ">", TRUE))
|
|
|
|
combine = GTK_CSS_COMBINE_CHILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_simple_selector (scanner, &name, ids, classes, &pseudo_classes, &state))
|
|
|
|
{
|
|
|
|
g_array_free (ids, TRUE);
|
|
|
|
g_array_free (classes, TRUE);
|
|
|
|
if (selector)
|
|
|
|
_gtk_css_selector_free (selector);
|
2011-04-14 02:47:18 +00:00
|
|
|
return NULL;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
selector = _gtk_css_selector_new (selector,
|
|
|
|
combine,
|
|
|
|
name,
|
|
|
|
(GQuark *) g_array_free (ids, ids->len == 0),
|
|
|
|
(GQuark *) g_array_free (classes, classes->len == 0),
|
|
|
|
pseudo_classes,
|
|
|
|
state);
|
|
|
|
g_free (name);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2011-05-14 11:27:31 +00:00
|
|
|
while (!_gtk_css_parser_is_eof (scanner->parser) &&
|
2011-04-14 02:47:18 +00:00
|
|
|
!_gtk_css_parser_begins_with (scanner->parser, ',') &&
|
|
|
|
!_gtk_css_parser_begins_with (scanner->parser, '{'));
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
return selector;
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static GSList *
|
|
|
|
parse_selector_list (GtkCssScanner *scanner)
|
|
|
|
{
|
|
|
|
GSList *selectors = NULL;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_SELECTOR);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
do {
|
2011-05-14 11:27:31 +00:00
|
|
|
GtkCssSelector *select = parse_selector (scanner);
|
2011-04-09 23:48:55 +00:00
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
if (select == NULL)
|
2011-04-09 23:48:55 +00:00
|
|
|
{
|
2011-05-14 11:27:31 +00:00
|
|
|
g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
|
2011-04-14 02:47:18 +00:00
|
|
|
_gtk_css_parser_resync (scanner->parser, FALSE, 0);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_SELECTOR);
|
2011-04-14 02:47:18 +00:00
|
|
|
return NULL;
|
2011-04-09 23:48:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
selectors = g_slist_prepend (selectors, select);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
while (_gtk_css_parser_try (scanner->parser, ",", TRUE));
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_SELECTOR);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
return selectors;
|
|
|
|
}
|
2010-06-18 15:04:03 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
static void
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declaration (GtkCssScanner *scanner,
|
|
|
|
GtkCssRuleset *ruleset)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-19 12:04:51 +00:00
|
|
|
const GtkStyleProperty *property;
|
2011-05-18 16:32:22 +00:00
|
|
|
char *name;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
name = _gtk_css_parser_try_ident (scanner->parser, TRUE);
|
|
|
|
if (name == NULL)
|
|
|
|
goto check_for_semicolon;
|
|
|
|
|
2011-05-19 12:04:51 +00:00
|
|
|
property = _gtk_style_property_lookup (name);
|
|
|
|
if (property == NULL && name[0] != '-')
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
gtk_css_provider_error (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_NAME,
|
|
|
|
"'%s' is not a valid property name",
|
|
|
|
name);
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
|
|
|
g_free (name);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
2011-04-14 02:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ":", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_invalid_token (scanner->provider, scanner, "':'");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
|
|
|
g_free (name);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
2011-04-14 02:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-19 12:04:51 +00:00
|
|
|
if (property)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *val;
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2011-05-18 02:30:51 +00:00
|
|
|
g_free (name);
|
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE);
|
|
|
|
|
|
|
|
val = property_value_new (scanner->section);
|
|
|
|
g_value_init (&val->value, property->pspec->value_type);
|
2011-04-14 02:47:18 +00:00
|
|
|
|
2011-05-25 23:25:00 +00:00
|
|
|
if (_gtk_style_property_parse_value (property,
|
2011-06-17 03:58:04 +00:00
|
|
|
&val->value,
|
2011-05-25 23:25:00 +00:00
|
|
|
scanner->parser,
|
|
|
|
gtk_css_scanner_get_base_url (scanner)))
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
2011-05-25 23:25:00 +00:00
|
|
|
if (_gtk_css_parser_begins_with (scanner->parser, ';') ||
|
|
|
|
_gtk_css_parser_begins_with (scanner->parser, '}') ||
|
|
|
|
_gtk_css_parser_is_eof (scanner->parser))
|
2011-05-25 22:09:26 +00:00
|
|
|
{
|
|
|
|
gtk_css_ruleset_add (ruleset, property, val);
|
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
else
|
2011-05-30 17:26:28 +00:00
|
|
|
{
|
2011-05-25 23:25:00 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Junk at end of value");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
2011-06-17 03:58:04 +00:00
|
|
|
property_value_free (val);
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_VALUE);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
2011-05-25 23:25:00 +00:00
|
|
|
return;
|
2011-05-30 17:26:28 +00:00
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-17 03:58:04 +00:00
|
|
|
property_value_free (val);
|
2011-05-25 23:25:00 +00:00
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_VALUE);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
2011-05-25 23:25:00 +00:00
|
|
|
return;
|
2010-06-18 15:04:03 +00:00
|
|
|
}
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_VALUE);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
else if (name[0] == '-')
|
|
|
|
{
|
2011-05-18 16:32:22 +00:00
|
|
|
char *value_str;
|
2010-08-04 15:51:19 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE);
|
|
|
|
|
2011-05-18 16:32:22 +00:00
|
|
|
value_str = _gtk_css_parser_read_value (scanner->parser);
|
|
|
|
if (value_str)
|
|
|
|
{
|
2011-06-17 03:58:04 +00:00
|
|
|
PropertyValue *val;
|
2011-05-18 16:32:22 +00:00
|
|
|
|
2011-06-17 03:58:04 +00:00
|
|
|
val = property_value_new (scanner->section);
|
|
|
|
g_value_init (&val->value, G_TYPE_STRING);
|
|
|
|
g_value_take_string (&val->value, value_str);
|
2010-08-04 15:51:19 +00:00
|
|
|
|
2011-05-18 16:32:22 +00:00
|
|
|
gtk_css_ruleset_add_style (ruleset, name, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
2011-06-17 03:58:04 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_VALUE);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
2011-05-18 16:32:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-17 03:58:04 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_VALUE);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_free (name);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
check_for_semicolon:
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DECLARATION);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
|
|
|
|
{
|
|
|
|
if (!_gtk_css_parser_begins_with (scanner->parser, '}') &&
|
|
|
|
!_gtk_css_parser_is_eof (scanner->parser))
|
2011-04-07 22:08:10 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"Expected semicolon");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, TRUE, '}');
|
2011-04-07 22:08:10 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
static void
|
|
|
|
parse_declarations (GtkCssScanner *scanner,
|
|
|
|
GtkCssRuleset *ruleset)
|
2011-04-14 02:47:18 +00:00
|
|
|
{
|
|
|
|
while (!_gtk_css_parser_is_eof (scanner->parser) &&
|
|
|
|
!_gtk_css_parser_begins_with (scanner->parser, '}'))
|
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declaration (scanner, ruleset);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
static void
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_ruleset (GtkCssScanner *scanner)
|
2011-04-07 22:08:10 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GSList *selectors;
|
2011-05-18 02:20:05 +00:00
|
|
|
GtkCssRuleset ruleset = { 0, };
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_RULESET);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
selectors = parse_selector_list (scanner);
|
|
|
|
if (selectors == NULL)
|
2011-06-17 00:02:24 +00:00
|
|
|
{
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_RULESET);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-07 22:08:10 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "{", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"expected '{' after selectors");
|
|
|
|
_gtk_css_parser_resync (scanner->parser, FALSE, 0);
|
2011-05-14 11:27:31 +00:00
|
|
|
g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_RULESET);
|
2011-04-14 02:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
parse_declarations (scanner, &ruleset);
|
2011-04-14 02:47:18 +00:00
|
|
|
|
|
|
|
if (!_gtk_css_parser_try (scanner->parser, "}", TRUE))
|
|
|
|
{
|
|
|
|
gtk_css_provider_error_literal (scanner->provider,
|
|
|
|
scanner,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_SYNTAX,
|
|
|
|
"expected '}' after declarations");
|
|
|
|
if (!_gtk_css_parser_is_eof (scanner->parser))
|
|
|
|
{
|
|
|
|
_gtk_css_parser_resync (scanner->parser, FALSE, 0);
|
2011-05-14 11:27:31 +00:00
|
|
|
g_slist_free_full (selectors, (GDestroyNotify) _gtk_css_selector_free);
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_clear (&ruleset);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_RULESET);
|
2011-04-14 02:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
css_provider_commit (scanner->provider, selectors, &ruleset);
|
|
|
|
gtk_css_ruleset_clear (&ruleset);
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_RULESET);
|
2011-04-07 22:08:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 00:32:26 +00:00
|
|
|
static void
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_statement (GtkCssScanner *scanner)
|
2011-04-11 00:32:26 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
if (_gtk_css_parser_begins_with (scanner->parser, '@'))
|
|
|
|
parse_at_keyword (scanner);
|
|
|
|
else
|
|
|
|
parse_ruleset (scanner);
|
2011-04-11 00:32:26 +00:00
|
|
|
}
|
2011-04-08 00:57:33 +00:00
|
|
|
|
2011-04-11 17:57:42 +00:00
|
|
|
static void
|
2011-05-14 11:27:31 +00:00
|
|
|
parse_stylesheet (GtkCssScanner *scanner)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-06-17 00:02:24 +00:00
|
|
|
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_DOCUMENT);
|
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
_gtk_css_parser_skip_whitespace (scanner->parser);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
while (!_gtk_css_parser_is_eof (scanner->parser))
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
if (_gtk_css_parser_try (scanner->parser, "<!--", TRUE) ||
|
|
|
|
_gtk_css_parser_try (scanner->parser, "-->", TRUE))
|
|
|
|
continue;
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_statement (scanner);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
2011-06-17 00:02:24 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_DOCUMENT);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 11:27:31 +00:00
|
|
|
static int
|
|
|
|
gtk_css_provider_compare_rule (gconstpointer a_,
|
|
|
|
gconstpointer b_)
|
|
|
|
{
|
2011-05-18 02:20:05 +00:00
|
|
|
const GtkCssRuleset *a = (const GtkCssRuleset *) a_;
|
|
|
|
const GtkCssRuleset *b = (const GtkCssRuleset *) b_;
|
2011-05-14 11:27:31 +00:00
|
|
|
int compare;
|
|
|
|
|
|
|
|
compare = _gtk_css_selector_compare (a->selector, b->selector);
|
|
|
|
if (compare != 0)
|
|
|
|
return compare;
|
|
|
|
|
|
|
|
/* compare pointers in array to ensure a stable sort */
|
|
|
|
if (a_ < b_)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (a_ > b_)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_provider_postprocess (GtkCssProvider *css_provider)
|
|
|
|
{
|
|
|
|
GtkCssProviderPrivate *priv = css_provider->priv;
|
|
|
|
|
2011-05-18 02:20:05 +00:00
|
|
|
g_array_sort (priv->rulesets, gtk_css_provider_compare_rule);
|
2011-05-14 11:27:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 17:55:34 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_provider_load_internal (GtkCssProvider *css_provider,
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *parent,
|
2011-04-11 17:55:34 +00:00
|
|
|
GFile *file,
|
2011-06-17 03:15:48 +00:00
|
|
|
const char *text,
|
2011-04-11 17:55:34 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2011-04-14 02:47:18 +00:00
|
|
|
GtkCssScanner *scanner;
|
2011-04-11 17:57:42 +00:00
|
|
|
gulong error_handler;
|
2011-05-30 17:26:28 +00:00
|
|
|
char *free_data = NULL;
|
2011-04-11 17:57:42 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
error_handler = g_signal_connect (css_provider,
|
|
|
|
"parsing-error",
|
|
|
|
G_CALLBACK (gtk_css_provider_propagate_error),
|
|
|
|
error);
|
|
|
|
else
|
|
|
|
error_handler = 0; /* silence gcc */
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
if (text == NULL)
|
2011-04-11 18:08:57 +00:00
|
|
|
{
|
|
|
|
GError *load_error = NULL;
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2011-04-11 18:08:57 +00:00
|
|
|
if (g_file_load_contents (file, NULL,
|
2011-06-17 03:15:48 +00:00
|
|
|
&free_data, NULL,
|
2011-04-11 18:08:57 +00:00
|
|
|
NULL, &load_error))
|
|
|
|
{
|
2011-06-17 03:15:48 +00:00
|
|
|
text = free_data;
|
2011-04-11 18:08:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-17 05:39:11 +00:00
|
|
|
GtkCssSection *section;
|
|
|
|
|
2011-04-12 00:06:08 +00:00
|
|
|
if (parent)
|
2011-06-17 05:39:11 +00:00
|
|
|
section = gtk_css_section_ref (parent->section);
|
2011-04-12 00:06:08 +00:00
|
|
|
else
|
2011-06-17 05:39:11 +00:00
|
|
|
section = _gtk_css_section_new_for_file (GTK_CSS_SECTION_DOCUMENT, file);
|
|
|
|
|
|
|
|
gtk_css_provider_error (css_provider,
|
|
|
|
parent,
|
|
|
|
GTK_CSS_PROVIDER_ERROR,
|
|
|
|
GTK_CSS_PROVIDER_ERROR_IMPORT,
|
|
|
|
"Failed to import: %s",
|
|
|
|
load_error->message);
|
|
|
|
|
|
|
|
gtk_css_section_unref (section);
|
2011-04-11 18:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
if (text)
|
2011-04-11 18:08:57 +00:00
|
|
|
{
|
2011-06-17 02:52:43 +00:00
|
|
|
scanner = gtk_css_scanner_new (css_provider,
|
|
|
|
parent,
|
|
|
|
parent ? parent->section : NULL,
|
|
|
|
file,
|
2011-06-17 03:15:48 +00:00
|
|
|
text);
|
2011-04-11 18:08:57 +00:00
|
|
|
|
2011-04-14 02:47:18 +00:00
|
|
|
parse_stylesheet (scanner);
|
2011-04-11 18:08:57 +00:00
|
|
|
|
|
|
|
gtk_css_scanner_destroy (scanner);
|
2011-05-14 11:27:31 +00:00
|
|
|
|
|
|
|
if (parent == NULL)
|
|
|
|
gtk_css_provider_postprocess (css_provider);
|
2011-04-11 18:08:57 +00:00
|
|
|
}
|
2011-04-11 17:55:34 +00:00
|
|
|
|
2011-05-30 17:26:28 +00:00
|
|
|
g_free (free_data);
|
|
|
|
|
2011-04-11 17:57:42 +00:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (css_provider, error_handler);
|
2011-05-30 17:26:28 +00:00
|
|
|
|
2011-04-11 17:57:42 +00:00
|
|
|
if (*error)
|
|
|
|
{
|
|
|
|
/* We clear all contents from the provider for backwards compat reasons */
|
|
|
|
gtk_css_provider_reset (css_provider);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2011-04-11 17:55:34 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_data:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
2011-06-01 00:37:43 +00:00
|
|
|
* @data: (array length=length) (element-type guint8): CSS data loaded in memory
|
2011-06-17 03:15:48 +00:00
|
|
|
* @length: the length of @data in bytes, or -1 for NUL terminated strings. If
|
|
|
|
* @length is not -1, the code will assume it is not NUL terminated and will
|
|
|
|
* potentially do a copy.
|
2010-10-19 08:59:46 +00:00
|
|
|
* @error: (out) (allow-none): return location for a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Loads @data into @css_provider, making it clear any previously loaded
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the data could be loaded.
|
|
|
|
**/
|
2010-04-11 21:03:25 +00:00
|
|
|
gboolean
|
2010-11-18 01:24:18 +00:00
|
|
|
gtk_css_provider_load_from_data (GtkCssProvider *css_provider,
|
|
|
|
const gchar *data,
|
|
|
|
gssize length,
|
|
|
|
GError **error)
|
2010-04-11 21:03:25 +00:00
|
|
|
{
|
2011-06-17 03:15:48 +00:00
|
|
|
char *free_data;
|
|
|
|
gboolean ret;
|
|
|
|
|
2010-04-11 21:03:25 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
|
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
|
|
|
|
|
|
|
if (length < 0)
|
2011-06-17 03:15:48 +00:00
|
|
|
{
|
|
|
|
length = strlen (data);
|
|
|
|
free_data = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free_data = g_strndup (data, length);
|
|
|
|
data = free_data;
|
|
|
|
}
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
gtk_css_provider_reset (css_provider);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
ret = gtk_css_provider_load_internal (css_provider, NULL, NULL, data, error);
|
|
|
|
|
|
|
|
g_free (free_data);
|
|
|
|
|
|
|
|
return ret;
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_file:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
|
|
|
* @file: #GFile pointing to a file to load
|
|
|
|
* @error: (out) (allow-none): return location for a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Loads the data contained in @file into @css_provider, making it
|
|
|
|
* clear any previously loaded information.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the data could be loaded.
|
|
|
|
**/
|
2010-04-11 21:03:25 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_provider_load_from_file (GtkCssProvider *css_provider,
|
|
|
|
GFile *file,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
2011-04-07 22:08:10 +00:00
|
|
|
gtk_css_provider_reset (css_provider);
|
2010-04-11 21:03:25 +00:00
|
|
|
|
2011-06-17 03:15:48 +00:00
|
|
|
return gtk_css_provider_load_internal (css_provider, NULL, file, NULL, error);
|
2010-04-11 21:03:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_load_from_path:
|
|
|
|
* @css_provider: a #GtkCssProvider
|
|
|
|
* @path: the path of a filename to load, in the GLib filename encoding
|
|
|
|
* @error: (out) (allow-none): return location for a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Loads the data contained in @path into @css_provider, making it clear
|
|
|
|
* any previously loaded information.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the data could be loaded.
|
|
|
|
**/
|
2010-10-08 16:36:46 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_provider_load_from_path (GtkCssProvider *css_provider,
|
|
|
|
const gchar *path,
|
|
|
|
GError **error)
|
|
|
|
{
|
2011-04-11 23:22:16 +00:00
|
|
|
GFile *file;
|
|
|
|
gboolean result;
|
|
|
|
|
2010-10-08 16:36:46 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
|
|
|
|
g_return_val_if_fail (path != NULL, FALSE);
|
|
|
|
|
2011-04-11 23:22:16 +00:00
|
|
|
file = g_file_new_for_path (path);
|
|
|
|
|
|
|
|
result = gtk_css_provider_load_from_file (css_provider, file, error);
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
return result;
|
2010-10-08 16:36:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_get_default:
|
|
|
|
*
|
|
|
|
* Returns the provider containing the style settings used as a
|
|
|
|
* fallback for all widgets.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The provider used for fallback styling.
|
|
|
|
* This memory is owned by GTK+, and you must not free it.
|
|
|
|
**/
|
2010-08-02 14:16:03 +00:00
|
|
|
GtkCssProvider *
|
|
|
|
gtk_css_provider_get_default (void)
|
|
|
|
{
|
|
|
|
static GtkCssProvider *provider;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!provider))
|
|
|
|
{
|
|
|
|
const gchar *str =
|
2010-10-08 16:19:34 +00:00
|
|
|
"@define-color fg_color #000; \n"
|
|
|
|
"@define-color bg_color #dcdad5; \n"
|
|
|
|
"@define-color text_color #000; \n"
|
|
|
|
"@define-color base_color #fff; \n"
|
|
|
|
"@define-color selected_bg_color #4b6983; \n"
|
|
|
|
"@define-color selected_fg_color #fff; \n"
|
|
|
|
"@define-color tooltip_bg_color #eee1b3; \n"
|
|
|
|
"@define-color tooltip_fg_color #000; \n"
|
2011-02-24 12:29:10 +00:00
|
|
|
"@define-color placeholder_text_color #808080; \n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"\n"
|
2010-12-14 01:29:57 +00:00
|
|
|
"@define-color info_fg_color rgb (181, 171, 156);\n"
|
|
|
|
"@define-color info_bg_color rgb (252, 252, 189);\n"
|
|
|
|
"@define-color warning_fg_color rgb (173, 120, 41);\n"
|
|
|
|
"@define-color warning_bg_color rgb (250, 173, 61);\n"
|
|
|
|
"@define-color question_fg_color rgb (97, 122, 214);\n"
|
|
|
|
"@define-color question_bg_color rgb (138, 173, 212);\n"
|
|
|
|
"@define-color error_fg_color rgb (166, 38, 38);\n"
|
|
|
|
"@define-color error_bg_color rgb (237, 54, 54);\n"
|
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
"* {\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
" background-color: @bg_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @fg_color;\n"
|
2010-11-22 01:39:11 +00:00
|
|
|
" border-color: shade (@bg_color, 0.6);\n"
|
2010-11-30 23:55:14 +00:00
|
|
|
" padding: 2;\n"
|
|
|
|
" border-width: 0;\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"*:prelight {\n"
|
2010-11-19 21:45:35 +00:00
|
|
|
" background-color: shade (@bg_color, 1.05);\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: shade (@fg_color, 1.3);\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"*:selected {\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" background-color: @selected_bg_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @selected_fg_color;\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".expander, GtkTreeView.view.expander {\n"
|
2010-12-13 19:04:40 +00:00
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-04-03 10:21:57 +00:00
|
|
|
".expander:prelight,\n"
|
|
|
|
"GtkTreeView.view.expander:selected:prelight {\n"
|
2010-12-13 19:04:40 +00:00
|
|
|
" color: @text_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".expander:active {\n"
|
2011-01-31 15:51:09 +00:00
|
|
|
" transition: 200ms linear;\n"
|
2010-11-22 23:56:10 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"*:insensitive {\n"
|
2010-11-24 00:10:38 +00:00
|
|
|
" border-color: shade (@bg_color, 0.7);\n"
|
2010-11-19 21:46:07 +00:00
|
|
|
" background-color: shade (@bg_color, 0.9);\n"
|
|
|
|
" color: shade (@bg_color, 0.7);\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-01-07 10:34:35 +00:00
|
|
|
".view {\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
" border-width: 0;\n"
|
|
|
|
" border-radius: 0;\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" background-color: @base_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @text_color;\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
"}\n"
|
2011-01-09 22:10:47 +00:00
|
|
|
".view:selected {\n"
|
|
|
|
" background-color: shade (@bg_color, 0.9);\n"
|
|
|
|
" color: @fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view:selected:focused {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".view column:sorted row,\n"
|
|
|
|
".view column:sorted row:prelight {\n"
|
|
|
|
" background-color: shade (@bg_color, 0.85);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view column:sorted row:nth-child(odd),\n"
|
|
|
|
".view column:sorted row:nth-child(odd):prelight {\n"
|
|
|
|
" background-color: shade (@bg_color, 0.8);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view row,\n"
|
|
|
|
".view row:prelight {\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" background-color: @base_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @text_color;\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".view row:nth-child(odd),\n"
|
|
|
|
".view row:nth-child(odd):prelight {\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" background-color: shade (@base_color, 0.93); \n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".view row:selected:focused {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view row:selected {\n"
|
|
|
|
" background-color: darker (@bg_color);\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view.cell.trough,\n"
|
|
|
|
".view.cell.trough:hover,\n"
|
|
|
|
".view.cell.trough:selected,\n"
|
|
|
|
".view.cell.trough:selected:focused {\n"
|
|
|
|
" background-color: @bg_color;\n"
|
|
|
|
" color: @fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".view.cell.progressbar,\n"
|
|
|
|
".view.cell.progressbar:hover,\n"
|
|
|
|
".view.cell.progressbar:selected,\n"
|
|
|
|
".view.cell.progressbar:selected:focused {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".rubberband {\n"
|
|
|
|
" background-color: alpha (@fg_color, 0.25);\n"
|
|
|
|
" border-color: @fg_color;\n"
|
|
|
|
" border-style: solid;\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-06-12 21:26:53 +00:00
|
|
|
".tooltip,\n"
|
|
|
|
".tooltip * {\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
" background-color: @tooltip_bg_color; \n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @tooltip_fg_color; \n"
|
2011-01-04 01:18:51 +00:00
|
|
|
" border-color: @tooltip_fg_color; \n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
" border-style: solid;\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
".button,\n"
|
|
|
|
".slider {\n"
|
|
|
|
" border-style: outset; \n"
|
|
|
|
" border-width: 2; \n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-08-16 17:09:34 +00:00
|
|
|
".button:active {\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" background-color: shade (@bg_color, 0.7);\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
" border-style: inset; \n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
".button:prelight,\n"
|
|
|
|
".slider:prelight {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @selected_fg_color;\n"
|
2010-10-25 11:55:56 +00:00
|
|
|
" border-color: shade (@selected_bg_color, 0.7);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
".trough {\n"
|
2011-02-06 12:48:42 +00:00
|
|
|
" background-color: darker (@bg_color);\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
" border-style: inset;\n"
|
|
|
|
" border-width: 1;\n"
|
2011-01-14 00:09:40 +00:00
|
|
|
" padding: 0;\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".entry {\n"
|
|
|
|
" border-style: inset;\n"
|
|
|
|
" border-width: 2;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" background-color: @base_color;\n"
|
|
|
|
" color: @text_color;\n"
|
|
|
|
"}\n"
|
2010-11-09 17:26:39 +00:00
|
|
|
"\n"
|
2010-11-19 21:46:07 +00:00
|
|
|
".entry:insensitive {\n"
|
|
|
|
" background-color: shade (@base_color, 0.9);\n"
|
|
|
|
" color: shade (@base_color, 0.7);\n"
|
|
|
|
"}\n"
|
2010-11-23 01:55:02 +00:00
|
|
|
".entry:active {\n"
|
|
|
|
" background-color: #c4c2bd;\n"
|
|
|
|
" color: #000;\n"
|
|
|
|
"}\n"
|
2010-11-19 21:46:07 +00:00
|
|
|
"\n"
|
2010-12-28 16:42:27 +00:00
|
|
|
".progressbar,\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".entry.progressbar, \n"
|
|
|
|
".cell.progressbar {\n"
|
2010-11-09 17:26:39 +00:00
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" border-color: shade (@selected_bg_color, 0.7);\n"
|
2010-11-22 01:39:41 +00:00
|
|
|
" color: @selected_fg_color;\n"
|
2011-01-14 00:09:40 +00:00
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 1;\n"
|
2010-11-09 17:26:39 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
"GtkCheckButton:hover,\n"
|
|
|
|
"GtkCheckButton:selected,\n"
|
|
|
|
"GtkRadioButton:hover,\n"
|
|
|
|
"GtkRadioButton:selected {\n"
|
2010-11-19 21:45:35 +00:00
|
|
|
" background-color: shade (@bg_color, 1.05);\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
".check, .radio,"
|
|
|
|
".cell.check, .cell.radio,\n"
|
|
|
|
".cell.check:hover, .cell.radio:hover {\n"
|
2011-01-12 19:35:04 +00:00
|
|
|
" border-style: solid;\n"
|
|
|
|
" border-width: 1;\n"
|
2011-01-18 19:02:51 +00:00
|
|
|
" background-color: @base_color;\n"
|
2011-01-23 19:01:22 +00:00
|
|
|
" border-color: @fg_color;\n"
|
2011-01-12 19:35:04 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
".check:active, .radio:active,\n"
|
|
|
|
".check:hover, .radio:hover {\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" background-color: @base_color;\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
" border-color: @fg_color;\n"
|
2010-12-06 05:44:58 +00:00
|
|
|
" color: @text_color;\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".check:selected, .radio:selected {\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
" background-color: darker (@bg_color);\n"
|
2010-11-19 18:20:12 +00:00
|
|
|
" color: @selected_fg_color;\n"
|
2011-01-12 20:18:07 +00:00
|
|
|
" border-color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".check:selected:focused, .radio:selected:focused {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2011-06-12 21:35:39 +00:00
|
|
|
".menuitem.check, .menuitem.radio {\n"
|
2010-10-29 03:33:38 +00:00
|
|
|
" color: @fg_color;\n"
|
|
|
|
" border-style: none;\n"
|
2011-01-12 19:35:04 +00:00
|
|
|
" border-width: 0;\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-11-17 06:39:03 +00:00
|
|
|
".popup {\n"
|
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-10-23 16:32:15 +00:00
|
|
|
".viewport {\n"
|
|
|
|
" border-style: inset;\n"
|
|
|
|
" border-width: 2;\n"
|
2010-08-16 17:09:34 +00:00
|
|
|
"}\n"
|
2010-11-15 22:28:53 +00:00
|
|
|
"\n"
|
|
|
|
".notebook {\n"
|
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
2010-11-17 06:39:03 +00:00
|
|
|
"\n"
|
2010-11-17 04:02:59 +00:00
|
|
|
".frame {\n"
|
|
|
|
" border-style: inset;\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
2010-11-22 20:42:30 +00:00
|
|
|
"\n"
|
2011-01-10 19:19:58 +00:00
|
|
|
"GtkScrolledWindow.frame {\n"
|
|
|
|
" padding: 0;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-11-22 20:42:30 +00:00
|
|
|
".menu,\n"
|
|
|
|
".menubar,\n"
|
|
|
|
".toolbar {\n"
|
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
2010-11-22 20:43:44 +00:00
|
|
|
"\n"
|
|
|
|
".menu:hover,\n"
|
2011-01-12 19:35:04 +00:00
|
|
|
".menubar:hover,\n"
|
2011-06-12 21:28:43 +00:00
|
|
|
".menuitem:hover,\n"
|
|
|
|
".menuitem.check:hover,\n"
|
|
|
|
".menuitem.radio:hover {\n"
|
2010-11-22 20:43:44 +00:00
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
2010-11-22 20:44:36 +00:00
|
|
|
"\n"
|
2010-11-22 20:45:15 +00:00
|
|
|
"GtkSpinButton.button {\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
"}\n"
|
2010-11-22 20:46:12 +00:00
|
|
|
"\n"
|
|
|
|
".scale.slider:hover,\n"
|
|
|
|
"GtkSpinButton.button:hover {\n"
|
|
|
|
" background-color: shade (@bg_color, 1.05);\n"
|
|
|
|
" border-color: shade (@bg_color, 0.8);\n"
|
|
|
|
"}\n"
|
2010-11-22 20:47:11 +00:00
|
|
|
"\n"
|
2010-12-29 03:09:14 +00:00
|
|
|
"GtkSwitch.trough:active {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
2010-11-22 20:47:11 +00:00
|
|
|
"GtkToggleButton.button:inconsistent {\n"
|
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 1px;\n"
|
|
|
|
" background-color: shade (@bg_color, 0.9);\n"
|
|
|
|
" border-color: shade (@bg_color, 0.7);\n"
|
|
|
|
"}\n"
|
2010-11-24 00:25:58 +00:00
|
|
|
"\n"
|
|
|
|
"GtkLabel:selected {\n"
|
|
|
|
" background-color: shade (@bg_color, 0.9);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkLabel:selected:focused {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
"}\n"
|
2010-11-24 22:25:14 +00:00
|
|
|
"\n"
|
|
|
|
".spinner:active {\n"
|
|
|
|
" transition: 750ms linear loop;\n"
|
|
|
|
"}\n"
|
2010-12-14 01:29:57 +00:00
|
|
|
"\n"
|
|
|
|
".info {\n"
|
|
|
|
" background-color: @info_bg_color;\n"
|
|
|
|
" color: @info_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".warning {\n"
|
|
|
|
" background-color: @warning_bg_color;\n"
|
|
|
|
" color: @warning_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".question {\n"
|
|
|
|
" background-color: @question_bg_color;\n"
|
|
|
|
" color: @question_fg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".error {\n"
|
|
|
|
" background-color: @error_bg_color;\n"
|
|
|
|
" color: @error_fg_color;\n"
|
|
|
|
"}\n"
|
2011-01-04 00:57:50 +00:00
|
|
|
"\n"
|
|
|
|
".highlight {\n"
|
|
|
|
" background-color: @selected_bg_color;\n"
|
|
|
|
" color: @selected_fg_color;\n"
|
|
|
|
"}\n"
|
2011-01-10 01:37:26 +00:00
|
|
|
"\n"
|
|
|
|
".light-area-focus {\n"
|
|
|
|
" color: #000;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
".dark-area-focus {\n"
|
|
|
|
" color: #fff;\n"
|
|
|
|
"}\n"
|
2011-01-10 19:40:37 +00:00
|
|
|
"GtkCalendar.view {\n"
|
|
|
|
" border-width: 1;\n"
|
|
|
|
" border-style: inset;\n"
|
|
|
|
" padding: 1;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkCalendar.view:inconsistent {\n"
|
|
|
|
" color: darker (@bg_color);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkCalendar.header {\n"
|
|
|
|
" background-color: @bg_color;\n"
|
|
|
|
" border-style: outset;\n"
|
|
|
|
" border-width: 2;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkCalendar.highlight {\n"
|
|
|
|
" border-width: 0;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkCalendar.button {\n"
|
|
|
|
" background-color: @bg_color;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"GtkCalendar.button:hover {\n"
|
|
|
|
" background-color: lighter (@bg_color);\n"
|
|
|
|
" color: @fg_color;\n"
|
|
|
|
"}\n"
|
2011-01-12 19:35:04 +00:00
|
|
|
"\n"
|
|
|
|
".menu * {\n"
|
|
|
|
" border-width: 0;\n"
|
|
|
|
" padding: 2;\n"
|
|
|
|
"}\n"
|
2010-08-02 14:16:03 +00:00
|
|
|
"\n";
|
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
2010-12-15 13:25:19 +00:00
|
|
|
if (!gtk_css_provider_load_from_data (provider, str, -1, NULL))
|
|
|
|
{
|
|
|
|
g_error ("Failed to load the internal default CSS.");
|
|
|
|
}
|
2010-08-02 14:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
|
2011-01-26 16:17:34 +00:00
|
|
|
gchar *
|
|
|
|
_gtk_css_provider_get_theme_dir (void)
|
2010-09-22 21:39:15 +00:00
|
|
|
{
|
|
|
|
const gchar *var;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
var = g_getenv ("GTK_DATA_PREFIX");
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
path = g_build_filename (var, "share", "themes", NULL);
|
|
|
|
else
|
|
|
|
path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_css_provider_get_named:
|
|
|
|
* @name: A theme name
|
2011-01-31 00:30:00 +00:00
|
|
|
* @variant: (allow-none): variant to load, for example, "dark", or
|
|
|
|
* %NULL for the default
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-11-13 21:57:49 +00:00
|
|
|
* Loads a theme from the usual theme paths
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-11-13 21:57:49 +00:00
|
|
|
* Returns: (transfer none): a #GtkCssProvider with the theme loaded.
|
2011-01-31 00:30:00 +00:00
|
|
|
* This memory is owned by GTK+, and you must not free it.
|
|
|
|
*/
|
2010-08-20 09:50:39 +00:00
|
|
|
GtkCssProvider *
|
2010-09-22 21:39:15 +00:00
|
|
|
gtk_css_provider_get_named (const gchar *name,
|
|
|
|
const gchar *variant)
|
2010-08-20 09:50:39 +00:00
|
|
|
{
|
|
|
|
static GHashTable *themes = NULL;
|
|
|
|
GtkCssProvider *provider;
|
2011-01-31 00:30:00 +00:00
|
|
|
gchar *key;
|
2010-08-20 09:50:39 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!themes))
|
|
|
|
themes = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
2011-01-31 00:30:00 +00:00
|
|
|
if (variant == NULL)
|
|
|
|
key = (gchar *)name;
|
|
|
|
else
|
|
|
|
key = g_strconcat (name, "-", variant, NULL);
|
|
|
|
|
|
|
|
provider = g_hash_table_lookup (themes, key);
|
2010-08-20 09:50:39 +00:00
|
|
|
|
|
|
|
if (!provider)
|
|
|
|
{
|
2010-09-22 21:39:15 +00:00
|
|
|
const gchar *home_dir;
|
|
|
|
gchar *subpath, *path = NULL;
|
2010-08-20 09:50:39 +00:00
|
|
|
|
2010-09-22 21:39:15 +00:00
|
|
|
if (variant)
|
2010-11-13 21:33:34 +00:00
|
|
|
subpath = g_strdup_printf ("gtk-3.0" G_DIR_SEPARATOR_S "gtk-%s.css", variant);
|
2010-09-22 21:39:15 +00:00
|
|
|
else
|
2010-11-13 21:33:34 +00:00
|
|
|
subpath = g_strdup ("gtk-3.0" G_DIR_SEPARATOR_S "gtk.css");
|
2010-09-22 21:39:15 +00:00
|
|
|
|
|
|
|
/* First look in the users home directory
|
|
|
|
*/
|
|
|
|
home_dir = g_get_home_dir ();
|
|
|
|
if (home_dir)
|
|
|
|
{
|
|
|
|
path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
|
|
|
|
|
|
|
|
if (!g_file_test (path, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
g_free (path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
{
|
2011-01-31 00:30:00 +00:00
|
|
|
gchar *theme_dir;
|
|
|
|
|
|
|
|
theme_dir = _gtk_css_provider_get_theme_dir ();
|
2010-09-22 21:39:15 +00:00
|
|
|
path = g_build_filename (theme_dir, name, subpath, NULL);
|
|
|
|
g_free (theme_dir);
|
|
|
|
|
|
|
|
if (!g_file_test (path, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
g_free (path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 14:13:21 +00:00
|
|
|
g_free (subpath);
|
|
|
|
|
2010-09-22 21:39:15 +00:00
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
|
2011-05-18 16:37:23 +00:00
|
|
|
if (!gtk_css_provider_load_from_path (provider, path, NULL))
|
|
|
|
{
|
2010-09-22 21:39:15 +00:00
|
|
|
g_object_unref (provider);
|
|
|
|
provider = NULL;
|
|
|
|
}
|
|
|
|
else
|
2011-01-31 00:30:00 +00:00
|
|
|
g_hash_table_insert (themes, g_strdup (key), provider);
|
2011-02-05 02:13:56 +00:00
|
|
|
|
|
|
|
g_free (path);
|
2010-09-22 21:39:15 +00:00
|
|
|
}
|
2010-08-20 09:50:39 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 00:30:00 +00:00
|
|
|
if (key != name)
|
|
|
|
g_free (key);
|
|
|
|
|
2010-08-20 09:50:39 +00:00
|
|
|
return provider;
|
|
|
|
}
|
2011-04-06 20:03:35 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
static int
|
2011-05-21 19:17:08 +00:00
|
|
|
compare_properties (gconstpointer a, gconstpointer b)
|
2011-05-18 02:36:43 +00:00
|
|
|
{
|
2011-05-21 19:17:08 +00:00
|
|
|
return strcmp (((const GtkStyleProperty *) a)->pspec->name,
|
|
|
|
((const GtkStyleProperty *) b)->pspec->name);
|
2011-05-18 02:36:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 20:03:35 +00:00
|
|
|
static void
|
2011-05-17 20:04:40 +00:00
|
|
|
gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
|
|
|
|
GString *str)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
|
|
|
GList *keys, *walk;
|
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
_gtk_css_selector_print (ruleset->selector, str);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
|
|
|
g_string_append (str, " {\n");
|
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->style)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
2011-05-18 02:36:43 +00:00
|
|
|
keys = g_hash_table_get_keys (ruleset->style);
|
|
|
|
/* so the output is identical for identical selector styles */
|
2011-05-21 19:17:08 +00:00
|
|
|
keys = g_list_sort (keys, compare_properties);
|
2011-04-06 20:03:35 +00:00
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
for (walk = keys; walk; walk = walk->next)
|
|
|
|
{
|
2011-05-21 19:17:08 +00:00
|
|
|
GtkStyleProperty *prop = walk->data;
|
2011-06-17 03:58:04 +00:00
|
|
|
const PropertyValue *value = g_hash_table_lookup (ruleset->style, prop);
|
2011-05-18 02:36:43 +00:00
|
|
|
|
|
|
|
g_string_append (str, " ");
|
2011-05-21 19:17:08 +00:00
|
|
|
g_string_append (str, prop->pspec->name);
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, ": ");
|
2011-06-17 03:58:04 +00:00
|
|
|
_gtk_style_property_print_value (prop, &value->value, str);
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, ";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (keys);
|
2011-04-06 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 02:36:43 +00:00
|
|
|
if (ruleset->widget_style)
|
|
|
|
{
|
|
|
|
keys = g_hash_table_get_keys (ruleset->widget_style);
|
|
|
|
/* so the output is identical for identical selector styles */
|
|
|
|
keys = g_list_sort (keys, (GCompareFunc) strcmp);
|
|
|
|
|
|
|
|
for (walk = keys; walk; walk = walk->next)
|
|
|
|
{
|
|
|
|
const char *name = walk->data;
|
2011-06-17 03:58:04 +00:00
|
|
|
const PropertyValue *value = g_hash_table_lookup (ruleset->widget_style, (gpointer) name);
|
2011-05-18 02:36:43 +00:00
|
|
|
|
|
|
|
g_string_append (str, " ");
|
|
|
|
g_string_append (str, name);
|
|
|
|
g_string_append (str, ": ");
|
2011-06-17 03:58:04 +00:00
|
|
|
g_string_append (str, g_value_get_string (&value->value));
|
2011-05-18 02:36:43 +00:00
|
|
|
g_string_append (str, ";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (keys);
|
|
|
|
}
|
2011-04-06 20:03:35 +00:00
|
|
|
|
|
|
|
g_string_append (str, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_provider_print_colors (GHashTable *colors,
|
|
|
|
GString *str)
|
|
|
|
{
|
|
|
|
GList *keys, *walk;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
keys = g_hash_table_get_keys (colors);
|
|
|
|
/* so the output is identical for identical styles */
|
|
|
|
keys = g_list_sort (keys, (GCompareFunc) strcmp);
|
|
|
|
|
|
|
|
for (walk = keys; walk; walk = walk->next)
|
|
|
|
{
|
|
|
|
const char *name = walk->data;
|
|
|
|
GtkSymbolicColor *symbolic = g_hash_table_lookup (colors, (gpointer) name);
|
|
|
|
|
|
|
|
g_string_append (str, "@define-color ");
|
|
|
|
g_string_append (str, name);
|
|
|
|
g_string_append (str, " ");
|
|
|
|
s = gtk_symbolic_color_to_string (symbolic);
|
|
|
|
g_string_append (str, s);
|
|
|
|
g_free (s);
|
|
|
|
g_string_append (str, ";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_css_provider_to_string:
|
|
|
|
* @provider: the provider to write to a string
|
|
|
|
*
|
|
|
|
* Convertes the @provider into a string representation in CSS
|
|
|
|
* format.
|
|
|
|
*
|
|
|
|
* Using gtk_css_provider_load_from_data() with the return value
|
|
|
|
* from this function on a new provider created with
|
|
|
|
* gtk_css_provider_new() will basicallu create a duplicate of
|
|
|
|
* this @provider.
|
|
|
|
*
|
|
|
|
* Returns: a new string representing the @provider.
|
|
|
|
**/
|
|
|
|
char *
|
|
|
|
gtk_css_provider_to_string (GtkCssProvider *provider)
|
|
|
|
{
|
|
|
|
GtkCssProviderPrivate *priv;
|
|
|
|
GString *str;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CSS_PROVIDER (provider), NULL);
|
|
|
|
|
|
|
|
priv = provider->priv;
|
|
|
|
|
|
|
|
str = g_string_new ("");
|
|
|
|
|
|
|
|
gtk_css_provider_print_colors (priv->symbolic_colors, str);
|
|
|
|
|
2011-05-17 20:04:40 +00:00
|
|
|
for (i = 0; i < priv->rulesets->len; i++)
|
2011-04-06 20:03:35 +00:00
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
g_string_append (str, "\n");
|
2011-05-18 02:20:05 +00:00
|
|
|
gtk_css_ruleset_print (&g_array_index (priv->rulesets, GtkCssRuleset, i), str);
|
2011-04-06 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|