gtkmm 4.19.1
Gtk::CssProvider Class Reference

CSS-like styling for widgets, implementing the StyleProvider base class. More...

#include <gtkmm/cssprovider.h>

Inheritance diagram for Gtk::CssProvider:

Public Member Functions

 CssProvider (CssProvider && src) noexcept
CssProvideroperator= (CssProvider && src) noexcept
 ~CssProvider () noexcept override
GtkCssProvider * gobj ()
 Provides access to the underlying C GObject.
const GtkCssProvider * gobj () const
 Provides access to the underlying C GObject.
GtkCssProvider * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Glib::ustring to_string () const
 Converts the provider into a string representation in CSS format.
void load_from_data (const std::string & data)
 Loads data into this css provider, making it clear any previously loaded information.
void load_from_string (const std::string & string)
 Loads string into css_provider.
void load_from_bytes (const Glib::RefPtr< const Glib::Bytes > & data)
 Loads data into css_provider.
void load_from_file (const Glib::RefPtr< const Gio::File > & file)
 Loads the data contained in file into css_provider.
void load_from_path (const std::string & path)
 Loads the data contained in path into css_provider.
void load_from_resource (const std::string & resource_path)
 Loads the data contained in the resource at resource_path into the css_provider.
void load_named (const Glib::ustring & name, const Glib::ustring & variant)
 Loads a theme from the usual theme paths.
Glib::SignalProxy< void(const Glib::RefPtr< const CssSection > &, const Glib::Error &)> signal_parsing_error ()
Glib::PropertyProxy< InterfaceColorSchemeproperty_prefers_color_scheme ()
 Define the color scheme used for rendering the user interface.
Glib::PropertyProxy_ReadOnly< InterfaceColorSchemeproperty_prefers_color_scheme () const
 Define the color scheme used for rendering the user interface.
Glib::PropertyProxy< InterfaceContrastproperty_prefers_contrast ()
 Define the contrast mode to use for the user interface.
Glib::PropertyProxy_ReadOnly< InterfaceContrastproperty_prefers_contrast () const
 Define the contrast mode to use for the user interface.
Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
Objectoperator= (const Object &)=delete
 Object (Object &&src) noexcept
Objectoperator= (Object &&src) noexcept
void * get_data (const QueryQuark &key)
void set_data (const Quark &key, void *data)
void set_data_with_c_callback (const Quark &key, void *data, GDestroyNotify notify)
void set_data (const Quark &key, void *data, DestroyNotify notify)
void remove_data (const QueryQuark &quark)
void * steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Objectwrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
ObjectBaseoperator= (const ObjectBase &)=delete
void set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void set_property (const Glib::ustring &property_name, const PropertyType &value)
void get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType get_property (const Glib::ustring &property_name) const
sigc::connection connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void freeze_notify ()
void thaw_notify ()
virtual void reference () const
virtual void unreference () const
GObject * gobj ()
const GObject * gobj () const
GObject * gobj_copy () const
Public Member Functions inherited from Gtk::StyleProvider
 StyleProvider (StyleProvider && src) noexcept
StyleProvideroperator= (StyleProvider && src) noexcept
 ~StyleProvider () noexcept override
GtkStyleProvider * gobj ()
 Provides access to the underlying C GObject.
const GtkStyleProvider * gobj () const
 Provides access to the underlying C GObject.
Public Member Functions inherited from Glib::Interface
 Interface ()
 Interface (Interface &&src) noexcept
Interfaceoperator= (Interface &&src) noexcept
 Interface (const Glib::Interface_Class &interface_class)
 Interface (GObject *castitem)
 ~Interface () noexcept override
 Interface (const Interface &)=delete
Interfaceoperator= (const Interface &)=delete
GObject * gobj ()
const GObject * gobj () const

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< CssProvidercreate ()
Static Public Member Functions inherited from Gtk::StyleProvider
static void add_interface (GType gtype_implementer)
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system.
static void add_provider_for_display (const Glib::RefPtr< Gdk::Display > & display, const Glib::RefPtr< StyleProvider > & provider, guint priority)
 Adds a global style provider to display, which will be used in style construction for all Gtk::StyleContexts under display.
static void remove_provider_for_display (const Glib::RefPtr< Gdk::Display > & display, const Glib::RefPtr< StyleProvider > & provider)
 Removes provider from the global style providers list in display.

Protected Member Functions

 CssProvider ()
Protected Member Functions inherited from Glib::Object
 Object ()
 Object (const Glib::ConstructParams &construct_params)
 Object (GObject *castitem)
 ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 ObjectBase (const char *custom_type_name)
 ObjectBase (const std::type_info &custom_type_info)
 ObjectBase (ObjectBase &&src) noexcept
ObjectBaseoperator= (ObjectBase &&src) noexcept
virtual ~ObjectBase () noexcept=0
void initialize (GObject *castitem)
void initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
Protected Member Functions inherited from Gtk::StyleProvider
 StyleProvider ()
 You should derive from this class to use it.

(Note that these are not member symbols.)

Glib::RefPtr< Gtk::CssProviderwrap (GtkCssProvider * object, bool take_copy=false)
 A Glib::wrap() method for this object.

Additional Inherited Members

Public Types inherited from Glib::Object
typedef void(*)(gpointer data DestroyNotify)

Detailed Description

CSS-like styling for widgets, implementing the StyleProvider base class.

It is able to parse CSS-like input in order to style widgets.

An application can cause GTK to parse a specific CSS style sheet by calling load_from_file() and adding the provider with StyleContext::add_provider() or StyleContext::add_provider_for_screen(). In addition, certain files will be read when GTK is initialized. See the GtkCssProvider documentation for details of these default files and details of the stylesheets.

Since gtkmm 3.0

Constructor & Destructor Documentation

◆ CssProvider() [1/2]

Gtk::CssProvider::CssProvider ( CssProvider && src)
noexcept

◆ ~CssProvider()

Gtk::CssProvider::~CssProvider ( )
overridenoexcept

◆ CssProvider() [2/2]

Gtk::CssProvider::CssProvider ( )
protected

Member Function Documentation

◆ create()

Glib::RefPtr< CssProvider > Gtk::CssProvider::create ( )
static

◆ get_type()

GType Gtk::CssProvider::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GtkCssProvider * Gtk::CssProvider::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkCssProvider * Gtk::CssProvider::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkCssProvider * Gtk::CssProvider::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ load_from_bytes()

void Gtk::CssProvider::load_from_bytes ( const Glib::RefPtr< const Glib::Bytes > & data)

Loads data into css_provider.

This clears any previously loaded information.

Since gtkmm 4.12
Parameters
dataBytes containing the data to load.

◆ load_from_data()

void Gtk::CssProvider::load_from_data ( const std::string & data)

Loads data into this css provider, making it clear any previously loaded information.

Deprecated
4.12: Use load_from_string() or load_from_bytes() instead.
Parameters
dataCSS data loaded in memory.

◆ load_from_file()

void Gtk::CssProvider::load_from_file ( const Glib::RefPtr< const Gio::File > & file)

Loads the data contained in file into css_provider.

This clears any previously loaded information.

Parameters
fileGio::File pointing to a file to load.

◆ load_from_path()

void Gtk::CssProvider::load_from_path ( const std::string & path)

Loads the data contained in path into css_provider.

This clears any previously loaded information.

Parameters
pathThe path of a filename to load, in the GLib filename encoding.

◆ load_from_resource()

void Gtk::CssProvider::load_from_resource ( const std::string & resource_path)

Loads the data contained in the resource at resource_path into the css_provider.

This clears any previously loaded information.

Parameters
resource_pathA Gio::Resource resource path.

◆ load_from_string()

void Gtk::CssProvider::load_from_string ( const std::string & string)

Loads string into css_provider.

This clears any previously loaded information.

Since gtkmm 4.12
Parameters
stringThe CSS to load.

◆ load_named()

void Gtk::CssProvider::load_named ( const Glib::ustring & name,
const Glib::ustring & variant )

Loads a theme from the usual theme paths.

The actual process of finding the theme might change between releases, but it is guaranteed that this function uses the same mechanism to load the theme that GTK uses for loading its own theme.

Deprecated: 4.20: Using any of the other theme loaders, combine with media queries.

Parameters
nameA theme name.
variantVariant to load, for example, "dark", or nullptr for the default.

◆ operator=()

CssProvider & Gtk::CssProvider::operator= ( CssProvider && src)
noexcept

◆ property_prefers_color_scheme() [1/2]

Glib::PropertyProxy< InterfaceColorScheme > Gtk::CssProvider::property_prefers_color_scheme ( )

Define the color scheme used for rendering the user interface.

The UI can be set to either Gtk::InterfaceColorScheme::LIGHT, or Gtk::InterfaceColorScheme::DARK mode. Other values will be interpreted the same as Gtk::InterfaceColorScheme::LIGHT.

This setting is be available for media queries in CSS:

[C example ellipted]

Changing this setting will cause a re-render of the style sheet.

Since gtkmm 4.20

Default value: Gtk::InterfaceColorScheme::DEFAULT

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_prefers_color_scheme() [2/2]

Glib::PropertyProxy_ReadOnly< InterfaceColorScheme > Gtk::CssProvider::property_prefers_color_scheme ( ) const

Define the color scheme used for rendering the user interface.

The UI can be set to either Gtk::InterfaceColorScheme::LIGHT, or Gtk::InterfaceColorScheme::DARK mode. Other values will be interpreted the same as Gtk::InterfaceColorScheme::LIGHT.

This setting is be available for media queries in CSS:

[C example ellipted]

Changing this setting will cause a re-render of the style sheet.

Since gtkmm 4.20

Default value: Gtk::InterfaceColorScheme::DEFAULT

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_prefers_contrast() [1/2]

Glib::PropertyProxy< InterfaceContrast > Gtk::CssProvider::property_prefers_contrast ( )

Define the contrast mode to use for the user interface.

When set to Gtk::InterfaceContrast::MORE or Gtk::InterfaceContrast::LESS, the UI is rendered in high or low contrast.

When set to Gtk::InterfaceContrast::NO_PREFERENCE (the default), the user interface will be rendered in default mode.

This setting is be available for media queries in CSS:

[C example ellipted]

Changing this setting will cause a re-render of the style sheet.

Since gtkmm 4.20

Default value: Gtk::InterfaceContrast::NO_PREFERENCE

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_prefers_contrast() [2/2]

Glib::PropertyProxy_ReadOnly< InterfaceContrast > Gtk::CssProvider::property_prefers_contrast ( ) const

Define the contrast mode to use for the user interface.

When set to Gtk::InterfaceContrast::MORE or Gtk::InterfaceContrast::LESS, the UI is rendered in high or low contrast.

When set to Gtk::InterfaceContrast::NO_PREFERENCE (the default), the user interface will be rendered in default mode.

This setting is be available for media queries in CSS:

[C example ellipted]

Changing this setting will cause a re-render of the style sheet.

Since gtkmm 4.20

Default value: Gtk::InterfaceContrast::NO_PREFERENCE

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ signal_parsing_error()

Glib::SignalProxy< void(const Glib::RefPtr< const CssSection > &, const Glib::Error &)> Gtk::CssProvider::signal_parsing_error ( )
Parameters
errorThe parsing error. The referenced object may belong to a subclass of Glib::Error, such as Gtk::CssParserError.
Slot Prototype:
void on_my_parsing_error(const Glib::RefPtr<const CssSection>& section, const Glib::Error& error)

Flags: Run Last

Signals that a parsing error occurred.

The expected error values are in the Gtk::CssParserError and Gtk::CssParserWarning enumerations.

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.

Errors in the Gtk::CssParserWarning enumeration should not be treated as fatal errors.

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.

Parameters
sectionSection the error happened in.
errorThe parsing error.

◆ to_string()

Glib::ustring Gtk::CssProvider::to_string ( ) const

Converts the provider into a string representation in CSS format.

Using load_from_string() with the return value from this function on a new provider created with new() will basically create a duplicate of this provider.

Returns
A new string representing the provider.

◆ wrap()

Glib::RefPtr< Gtk::CssProvider > wrap ( GtkCssProvider * object,
bool take_copy = false )
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.