gtkmm 3.24.7
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::CssProvider Class Reference

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

#include <gtkmm/cssprovider.h>

Inheritance diagram for Gtk::CssProvider:
Inheritance graph
[legend]

Public Member Functions

 CssProvider (CssProvider && src) noexcept
 
CssProvideroperator= (CssProvider && src) noexcept
 
 ~CssProvider () noexcept override
 
GtkCssProvider * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkCssProvider * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkCssProvider * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::ustring to_string () const
 Converts the provider into a string representation in CSS format. More...
 
bool load_from_data (const std::string &data)
 Loads data into this css provider, making it clear any previously loaded information. More...
 
bool load_from_file (const Glib::RefPtr< const Gio::File > & file)
 Loads the data contained in file into css_provider, making it clear any previously loaded information. More...
 
bool load_from_path (const std::string & path)
 Loads the data contained in path into css_provider, making it clear any previously loaded information. More...
 
void load_from_resource (const std::string & resource_path)
 Loads the data contained in the resource at resource_path into the Gtk::CssProvider, clearing any previously loaded information. More...
 
Glib::SignalProxy< void, const Glib::RefPtr< const CssSection > &, const Glib::Error & > signal_parsing_error ()
 
- 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. More...
 
const GtkStyleProvider * gobj () const
 Provides access to the underlying C GObject. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< CssProvidercreate ()
 
static Glib::RefPtr< CssProviderget_default ()
 Returns the provider containing the style settings used as a fallback for all widgets. More...
 
static Glib::RefPtr< CssProviderget_named (const Glib::ustring & name, const Glib::ustring & variant)
 Loads a theme from the usual theme paths. More...
 
- 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. More...
 

Protected Member Functions

 CssProvider ()
 
- Protected Member Functions inherited from Gtk::StyleProvider
 StyleProvider ()
 You should derive from this class to use it. More...
 

Related Functions

(Note that these are not member functions.)

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

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()

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

◆ get_default()

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

Returns the provider containing the style settings used as a fallback for all widgets.

Deprecated: 3.24: Use new() instead.

Deprecated:
Use create() instead.
Returns
The provider used for fallback styling. This memory is owned by GTK+, and you must not free it.

◆ get_named()

static Glib::RefPtr< CssProvider > Gtk::CssProvider::get_named ( const Glib::ustring &  name,
const Glib::ustring &  variant 
)
static

Loads a theme from the usual theme paths.

Parameters
nameA theme name.
variantVariant to load, for example, "dark", or nullptr for the default.
Returns
A Gtk::CssProvider with the theme loaded. This memory is owned by GTK+, and you must not free it.

◆ get_type()

static 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_data()

bool Gtk::CssProvider::load_from_data ( const std::string data)

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

Parameters
dataCSS data loaded in memory.
Returns
True if the data could be loaded, though an exception will always be thrown if this would return false.
Exceptions
CssProviderError

◆ load_from_file()

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

Loads the data contained in file into css_provider, making it clear any previously loaded information.

Parameters
fileGio::File pointing to a file to load.
Returns
true. The return value is deprecated and false will only be returned for backwards compatibility reasons if an error is not nullptr and a loading error occurred. To track errors while loading CSS, connect to the Gtk::CssProvider::signal_parsing_error() signal.
Exceptions
Glib::Error

◆ load_from_path()

bool Gtk::CssProvider::load_from_path ( const std::string path)

Loads the data contained in path into css_provider, making it clear any previously loaded information.

Parameters
pathThe path of a filename to load, in the GLib filename encoding.
Returns
true. The return value is deprecated and false will only be returned for backwards compatibility reasons if an error is not nullptr and a loading error occurred. To track errors while loading CSS, connect to the Gtk::CssProvider::signal_parsing_error() signal.
Exceptions
Glib::Error

◆ 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 Gtk::CssProvider, clearing any previously loaded information.

To track errors while loading CSS, connect to the Gtk::CssProvider::signal_parsing_error() signal.

Since gtkmm 3.16:
Parameters
resource_pathA Gio::Resource resource path.

◆ operator=()

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

◆ 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::CssProviderError.
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 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.

Parameters
sectionSection the error happened in.

◆ to_string()

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

Converts the provider into a string representation in CSS format.

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

Since gtkmm 3.2:
Returns
A new string representing the provider.

Friends And Related Function Documentation

◆ 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.