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

This object stores styling information affecting a widget defined by WidgetPath. More...

#include <gtkmm/stylecontext.h>

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

Public Member Functions

 StyleContext (StyleContext&& src) noexcept
 
StyleContextoperator= (StyleContext&& src) noexcept
 
 ~StyleContext () noexcept override
 
GtkStyleContext* gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkStyleContext* gobj () const
 Provides access to the underlying C GObject. More...
 
GtkStyleContext* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void add_provider (const Glib::RefPtr< StyleProvider >& provider, guint priority)
 Adds a style provider to context, to be used in style construction. More...
 
void remove_provider (const Glib::RefPtr< StyleProvider >& provider)
 Removes provider from the style providers list in context. More...
 
void context_save ()
 Saves the context state, so temporary modifications done through add_class(), remove_class(), set_state(), etc. More...
 
void context_restore ()
 Restores context state to a previous stage. More...
 
void set_state (StateFlags flags)
 Sets the state to be used for style matching. More...
 
StateFlags get_state () const
 Returns the state used for style matching. More...
 
void set_scale (int scale)
 Sets the scale to use when getting image assets for the style. More...
 
int get_scale () const
 Returns the scale used for assets. More...
 
void set_path (const WidgetPath& path)
 Sets the Gtk::WidgetPath used for style matching. More...
 
WidgetPath get_path () const
 Returns the widget path used for style matching. More...
 
void set_parent (const Glib::RefPtr< StyleContext >& parent)
 Sets the parent style context for context. More...
 
void unset_parent ()
 
Glib::RefPtr< StyleContextget_parent ()
 Gets the parent context set via set_parent(). More...
 
Glib::RefPtr< const StyleContextget_parent () const
 Gets the parent context set via set_parent(). More...
 
std::vector< Glib::ustringlist_classes () const
 Returns the list of classes currently defined in context. More...
 
void add_class (const Glib::ustring& class_name)
 Adds a style class to context, so posterior calls to get() or any of the gtk_render_*() functions will make use of this new class for styling. More...
 
void remove_class (const Glib::ustring& class_name)
 Removes class_name from context. More...
 
bool has_class (const Glib::ustring& class_name)
 Returns true if context currently has defined the given class name. More...
 
void set_display (const Glib::RefPtr< Gdk::Display >& display)
 Attaches context to the given display. More...
 
Glib::RefPtr< Gdk::Displayget_display ()
 Returns the Gdk::Display to which context is attached. More...
 
Glib::RefPtr< const Gdk::Displayget_display () const
 Returns the Gdk::Display to which context is attached. More...
 
void set_frame_clock (const Glib::RefPtr< Gdk::FrameClock >& frame_clock)
 Attaches context to the given frame clock. More...
 
Glib::RefPtr< Gdk::FrameClockget_frame_clock ()
 Returns the Gdk::FrameClock to which context is attached. More...
 
Glib::RefPtr< const Gdk::FrameClockget_frame_clock () const
 Returns the Gdk::FrameClock to which context is attached. More...
 
bool lookup_color (const Glib::ustring& color_name, Gdk::RGBA& color)
 Looks up and resolves a color name in the context color map. More...
 
Gdk::RGBA get_color () const
 Gets the foreground color for a given state. More...
 
Pango::FontDescription get_font () const
 Returns the font description for a given state. More...
 
Border get_border () const
 
Border get_padding () const
 
Border get_margin () const
 
void render_check (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders a checkmark (as in a Gtk::CheckButton). More...
 
void render_option (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders an option mark (as in a Gtk::RadioButton), the Gtk::StateFlags::CHECKED state will determine whether the option is on or off, and Gtk::StateFlags::INCONSISTENT whether it should be marked as undefined. More...
 
void render_arrow (const Cairo::RefPtr< Cairo::Context >& cr, double angle, double x, double y, double size)
 Renders an arrow pointing to angle. More...
 
void render_background (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders the background of an element. More...
 
void render_frame (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders a frame around the rectangle defined by x, y, width, height. More...
 
void render_expander (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders an expander (as used in Gtk::TreeView and Gtk::Expander) in the area defined by x, y, width, height. More...
 
void render_focus (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders a focus indicator on the rectangle determined by x, y, width, height. More...
 
void render_layout (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, const Glib::RefPtr< Pango::Layout >& layout)
 Renders layout on the coordinates x, y. More...
 
void render_line (const Cairo::RefPtr< Cairo::Context >& cr, double x0, double y0, double x1, double y1)
 Renders a line from (x0, y0) to (x1, y1). More...
 
void render_slider (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height, Orientation orientation)
 Renders a slider (as in Gtk::Scale) in the rectangle defined by x, y, width, height. More...
 
void render_frame_gap (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height, PositionType gap_side, double xy0_gap, double xy1_gap)
 Renders a frame around the rectangle defined by ( x, y, width, height), leaving a gap on one side. More...
 
void render_handle (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders a handle (as in Gtk::HandleBox, Gtk::Paned and Gtk::Window’s resize grip), in the rectangle determined by x, y, width, height. More...
 
void render_activity (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, double width, double height)
 Renders an activity indicator (such as in Gtk::Spinner). More...
 
void render_icon (const Cairo::RefPtr< Cairo::Context >& cr, const Glib::RefPtr< Gdk::Texture >& texture, double x, double y)
 Renders the icon in texture at the specified x and y coordinates. More...
 
void render_insertion_cursor (const Cairo::RefPtr< Cairo::Context >& cr, double x, double y, const Glib::RefPtr< Pango::Layout >& layout, int index, Pango::Direction direction)
 Draws a text caret on cr at the specified index of layout. More...
 
Glib::SignalProxy< void()> signal_changed ()
 
Glib::PropertyProxy< Glib::RefPtr< Gdk::Display > > property_display ()
 The associated GdkDisplay. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Display > > property_display () const
 The associated GdkDisplay. More...
 
Glib::PropertyProxy< Glib::RefPtr< Gdk::FrameClock > > property_paint_clock ()
 The associated GdkFrameClock. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::FrameClock > > property_paint_clock () const
 The associated GdkFrameClock. More...
 
Glib::PropertyProxy< Glib::RefPtr< StyleContext > > property_parent ()
 Sets or gets the style context’s parent. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< StyleContext > > property_parent () const
 Sets or gets the style context’s parent. More...
 
- 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 (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 sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src)
 
 ~trackable ()
 
void add_destroy_notify_callback (void *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src)
 
void remove_destroy_notify_callback (void *data) const
 

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< StyleContextcreate ()
 
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. More...
 
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. More...
 

Protected Member Functions

 StyleContext ()
 
virtual void on_changed ()
 This is a default handler for the signal signal_changed(). More...
 
- 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)
 

Related Functions

(Note that these are not member functions.)

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

Additional Inherited Members

- Public Types inherited from Glib::Object
typedef void(*)(gpointer data DestroyNotify)
 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 

Detailed Description

This object stores styling information affecting a widget defined by WidgetPath.

In order to construct the final style information, StyleContext queries information from all attached StyleProviders. Style providers can be either attached explicitly to the context through add_provider(), or to the display through add_provider_for_display(). The resulting style is a combination of all providers' information in priority order.

For GTK+ widgets, any StyleContext returned by Widget::get_style_context() will already have a WidgetPath, a Gdk::Display and RTL/LTR information set, The style context will be also updated automatically if any of these settings change on the widget.

If you are using the theming layer standalone, you will need to set a widget path and a display yourself to the created style context through set_path() and set_display(), as well as updating the context yourself using invalidate() whenever any of the conditions change, such as a change in the Settings::property_gtk_theme_name() setting or a hierarchy change in the rendered widget.

Transition animations

StyleContext has built-in support for state change transitions. Note that these animations respect the Settings::property_gtk_enable_animations() setting.

For simple widgets where state changes affect the whole widget area, calling notify_state_change() with a no region is sufficient to trigger the transition animation. And GTK+ already does that when Widget::set_state() or Widget::set_state_flags() are called.

If a widget needs to declare several animatable regions (i.e. not affecting the whole widget area), its Widget::signal_draw() signal handler needs to wrap the render operations for the different regions with calls to push_animatable_region() and pop_animatable_region(). These methods take an identifier for the region which must be unique within the style context. For simple widgets with a fixed set of animatable regions, using an enumeration works well.

For complex widgets with an arbitrary number of animatable regions, it is up to the implementation to come up with a way to uniquely identify each animatable region. Using pointers to internal objects is one way to achieve this.

The widget also needs to notify the style context about a state change for a given animatable region so the animation is triggered. notify_state_change() can take no region IDs, meaning that the whole widget area will be updated by the animation.

Since gtkmm 3.0:

Constructor & Destructor Documentation

◆ StyleContext() [1/2]

Gtk::StyleContext::StyleContext ( StyleContext&&  src)
noexcept

◆ ~StyleContext()

Gtk::StyleContext::~StyleContext ( )
overridenoexcept

◆ StyleContext() [2/2]

Gtk::StyleContext::StyleContext ( )
protected

Member Function Documentation

◆ add_class()

void Gtk::StyleContext::add_class ( const Glib::ustring class_name)

Adds a style class to context, so posterior calls to get() or any of the gtk_render_*() functions will make use of this new class for styling.

In the CSS file format, a Gtk::Entry defining a “search” class, would be matched by:

[C example ellipted]

While any widget defining a “search” class would be matched by:

[C example ellipted]

Parameters
class_nameClass name to use in styling.

◆ add_provider()

void Gtk::StyleContext::add_provider ( const Glib::RefPtr< StyleProvider >&  provider,
guint  priority 
)

Adds a style provider to context, to be used in style construction.

Note that a style provider added by this function only affects the style of the widget to which context belongs. If you want to affect the style of all widgets, use add_provider_for_display().

Note
If both priorities are the same, a Gtk::StyleProvider added through this function takes precedence over another added through add_provider_for_display().
Parameters
providerA Gtk::StyleProvider.
priorityThe priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and GTK_STYLE_PROVIDER_PRIORITY_USER.

◆ add_provider_for_display()

static void Gtk::StyleContext::add_provider_for_display ( const Glib::RefPtr< Gdk::Display >&  display,
const Glib::RefPtr< StyleProvider >&  provider,
guint  priority 
)
static

Adds a global style provider to display, which will be used in style construction for all Gtk::StyleContexts under display.

GTK+ uses this to make styling information from Gtk::Settings available.

Note
If both priorities are the same, A Gtk::StyleProvider added through add_provider() takes precedence over another added through this function.
Parameters
displayA Gdk::Display.
providerA Gtk::StyleProvider.
priorityThe priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and GTK_STYLE_PROVIDER_PRIORITY_USER.

◆ context_restore()

void Gtk::StyleContext::context_restore ( )

Restores context state to a previous stage.

See save().

◆ context_save()

void Gtk::StyleContext::context_save ( )

Saves the context state, so temporary modifications done through add_class(), remove_class(), set_state(), etc.

can quickly be reverted in one go through restore().

The matching call to restore() must be done before GTK returns to the main loop.

◆ create()

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

◆ get_border()

Border Gtk::StyleContext::get_border ( ) const

◆ get_color()

Gdk::RGBA Gtk::StyleContext::get_color ( ) const

Gets the foreground color for a given state.

Since gtkmm 3.0:
Returns
The foreground color for the given state.

◆ get_display() [1/2]

Glib::RefPtr<Gdk::Display> Gtk::StyleContext::get_display ( )

Returns the Gdk::Display to which context is attached.

Returns
A Gdk::Display.

◆ get_display() [2/2]

Glib::RefPtr<const Gdk::Display> Gtk::StyleContext::get_display ( ) const

Returns the Gdk::Display to which context is attached.

Returns
A Gdk::Display.

◆ get_font()

Pango::FontDescription Gtk::StyleContext::get_font ( ) const

Returns the font description for a given state.

Since gtkmm 3.0:
Returns
The Pango::FontDescription for the given state.

◆ get_frame_clock() [1/2]

Glib::RefPtr<Gdk::FrameClock> Gtk::StyleContext::get_frame_clock ( )

Returns the Gdk::FrameClock to which context is attached.

Since gtkmm 3.94:
Returns
A Gdk::FrameClock, or nullptr if context does not have an attached frame clock.

◆ get_frame_clock() [2/2]

Glib::RefPtr<const Gdk::FrameClock> Gtk::StyleContext::get_frame_clock ( ) const

Returns the Gdk::FrameClock to which context is attached.

Since gtkmm 3.94:
Returns
A Gdk::FrameClock, or nullptr if context does not have an attached frame clock.

◆ get_margin()

Border Gtk::StyleContext::get_margin ( ) const

◆ get_padding()

Border Gtk::StyleContext::get_padding ( ) const

◆ get_parent() [1/2]

Glib::RefPtr<StyleContext> Gtk::StyleContext::get_parent ( )

Gets the parent context set via set_parent().

See that function for details.

Returns
The parent context or nullptr.

◆ get_parent() [2/2]

Glib::RefPtr<const StyleContext> Gtk::StyleContext::get_parent ( ) const

Gets the parent context set via set_parent().

See that function for details.

Returns
The parent context or nullptr.

◆ get_path()

WidgetPath Gtk::StyleContext::get_path ( ) const

Returns the widget path used for style matching.

Returns
A Gtk::WidgetPath.

◆ get_scale()

int Gtk::StyleContext::get_scale ( ) const

Returns the scale used for assets.

Returns
The scale.

◆ get_state()

StateFlags Gtk::StyleContext::get_state ( ) const

Returns the state used for style matching.

This method should only be used to retrieve the Gtk::StateFlags to pass to Gtk::StyleContext methods, like get_padding(). If you need to retrieve the current state of a Gtk::Widget, use Gtk::Widget::get_state_flags().

Returns
The state flags.

◆ get_type()

static GType Gtk::StyleContext::get_type ( )
static

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

◆ gobj() [1/2]

GtkStyleContext* Gtk::StyleContext::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkStyleContext* Gtk::StyleContext::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkStyleContext* Gtk::StyleContext::gobj_copy ( )

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

◆ has_class()

bool Gtk::StyleContext::has_class ( const Glib::ustring class_name)

Returns true if context currently has defined the given class name.

Parameters
class_nameA class name.
Returns
true if context has class_name defined.

◆ list_classes()

std::vector<Glib::ustring> Gtk::StyleContext::list_classes ( ) const

Returns the list of classes currently defined in context.

Returns
A List of strings with the currently defined classes.

◆ lookup_color()

bool Gtk::StyleContext::lookup_color ( const Glib::ustring color_name,
Gdk::RGBA color 
)

Looks up and resolves a color name in the context color map.

Parameters
color_nameColor name to lookup.
colorReturn location for the looked up color.
Returns
true if color_name was found and resolved, false otherwise.

◆ on_changed()

virtual void Gtk::StyleContext::on_changed ( )
protectedvirtual

This is a default handler for the signal signal_changed().

◆ operator=()

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

◆ property_display() [1/2]

Glib::PropertyProxy< Glib::RefPtr<Gdk::Display> > Gtk::StyleContext::property_display ( )

The associated GdkDisplay.

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_display() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gdk::Display> > Gtk::StyleContext::property_display ( ) const

The associated GdkDisplay.

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_paint_clock() [1/2]

Glib::PropertyProxy< Glib::RefPtr<Gdk::FrameClock> > Gtk::StyleContext::property_paint_clock ( )

The associated GdkFrameClock.

Since gtkmm 3.94:
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_paint_clock() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gdk::FrameClock> > Gtk::StyleContext::property_paint_clock ( ) const

The associated GdkFrameClock.

Since gtkmm 3.94:
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_parent() [1/2]

Glib::PropertyProxy< Glib::RefPtr<StyleContext> > Gtk::StyleContext::property_parent ( )

Sets or gets the style context’s parent.

See Gtk::StyleContext::set_parent() for details.

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_parent() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<StyleContext> > Gtk::StyleContext::property_parent ( ) const

Sets or gets the style context’s parent.

See Gtk::StyleContext::set_parent() for details.

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

◆ remove_class()

void Gtk::StyleContext::remove_class ( const Glib::ustring class_name)

Removes class_name from context.

Parameters
class_nameClass name to remove.

◆ remove_provider()

void Gtk::StyleContext::remove_provider ( const Glib::RefPtr< StyleProvider >&  provider)

Removes provider from the style providers list in context.

Parameters
providerA Gtk::StyleProvider.

◆ remove_provider_for_display()

static void Gtk::StyleContext::remove_provider_for_display ( const Glib::RefPtr< Gdk::Display >&  display,
const Glib::RefPtr< StyleProvider >&  provider 
)
static

Removes provider from the global style providers list in display.

Parameters
displayA Gdk::Display.
providerA Gtk::StyleProvider.

◆ render_activity()

void Gtk::StyleContext::render_activity ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders an activity indicator (such as in Gtk::Spinner).

The state Gtk::StateFlags::CHECKED determines whether there is activity going on.

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_arrow()

void Gtk::StyleContext::render_arrow ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  angle,
double  x,
double  y,
double  size 
)

Renders an arrow pointing to angle.

Typical arrow rendering at 0, 1⁄2 π;, π; and 3⁄2 π:

Parameters
crA #cairo_t.
angleArrow angle from 0 to 2 * G_PI, being 0 the arrow pointing to the north.
xX origin of the render area.
yY origin of the render area.
sizeSquare side for render area.

◆ render_background()

void Gtk::StyleContext::render_background ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders the background of an element.

Typical background rendering, showing the effect of background-image, border-width and border-radius:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_check()

void Gtk::StyleContext::render_check ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders a checkmark (as in a Gtk::CheckButton).

The Gtk::StateFlags::CHECKED state determines whether the check is on or off, and Gtk::StateFlags::INCONSISTENT determines whether it should be marked as undefined.

Typical checkmark rendering:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_expander()

void Gtk::StyleContext::render_expander ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders an expander (as used in Gtk::TreeView and Gtk::Expander) in the area defined by x, y, width, height.

The state Gtk::StateFlags::CHECKED determines whether the expander is collapsed or expanded.

Typical expander rendering:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_focus()

void Gtk::StyleContext::render_focus ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders a focus indicator on the rectangle determined by x, y, width, height.

Typical focus rendering:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_frame()

void Gtk::StyleContext::render_frame ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders a frame around the rectangle defined by x, y, width, height.

Examples of frame rendering, showing the effect of border-image, border-color, border-width, border-radius and junctions:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_frame_gap()

void Gtk::StyleContext::render_frame_gap ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height,
PositionType  gap_side,
double  xy0_gap,
double  xy1_gap 
)

Renders a frame around the rectangle defined by ( x, y, width, height), leaving a gap on one side.

xy0_gap and xy1_gap will mean X coordinates for Gtk::PositionType::TOP and Gtk::PositionType::BOTTOM gap sides, and Y coordinates for Gtk::PositionType::LEFT and Gtk::PositionType::RIGHT.

Typical rendering of a frame with a gap:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.
gap_sideSide where the gap is.
xy0_gapInitial coordinate (X or Y depending on gap_side) for the gap.
xy1_gapEnd coordinate (X or Y depending on gap_side) for the gap.

◆ render_handle()

void Gtk::StyleContext::render_handle ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders a handle (as in Gtk::HandleBox, Gtk::Paned and Gtk::Window’s resize grip), in the rectangle determined by x, y, width, height.

Handles rendered for the paned and grip classes:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_icon()

void Gtk::StyleContext::render_icon ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Glib::RefPtr< Gdk::Texture >&  texture,
double  x,
double  y 
)

Renders the icon in texture at the specified x and y coordinates.

This function will render the icon in texture at exactly its size, regardless of scaling factors, which may not be appropriate when drawing on displays with high pixel densities.

You probably want to use gtk_render_icon_surface() instead, if you already have a Cairo surface.

Parameters
crA #cairo_t.
textureA Gdk::Texture containing the icon to draw.
xX position for the texture.
yY position for the texture.

◆ render_insertion_cursor()

void Gtk::StyleContext::render_insertion_cursor ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
const Glib::RefPtr< Pango::Layout > &  layout,
int  index,
Pango::Direction  direction 
)

Draws a text caret on cr at the specified index of layout.

Parameters
crA #cairo_t.
xX origin.
yY origin.
layoutThe Pango::Layout of the text.
indexThe index in the Pango::Layout.
directionThe Pango::Direction of the text.

◆ render_layout()

void Gtk::StyleContext::render_layout ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
const Glib::RefPtr< Pango::Layout > &  layout 
)

Renders layout on the coordinates x, y.

Parameters
crA #cairo_t.
xX origin.
yY origin.
layoutThe Pango::Layout to render.

◆ render_line()

void Gtk::StyleContext::render_line ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x0,
double  y0,
double  x1,
double  y1 
)

Renders a line from (x0, y0) to (x1, y1).

Parameters
crA #cairo_t.
x0X coordinate for the origin of the line.
y0Y coordinate for the origin of the line.
x1X coordinate for the end of the line.
y1Y coordinate for the end of the line.

◆ render_option()

void Gtk::StyleContext::render_option ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height 
)

Renders an option mark (as in a Gtk::RadioButton), the Gtk::StateFlags::CHECKED state will determine whether the option is on or off, and Gtk::StateFlags::INCONSISTENT whether it should be marked as undefined.

Typical option mark rendering:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.

◆ render_slider()

void Gtk::StyleContext::render_slider ( const Cairo::RefPtr< Cairo::Context > &  cr,
double  x,
double  y,
double  width,
double  height,
Orientation  orientation 
)

Renders a slider (as in Gtk::Scale) in the rectangle defined by x, y, width, height.

orientation defines whether the slider is vertical or horizontal.

Typical slider rendering:

Parameters
crA #cairo_t.
xX origin of the rectangle.
yY origin of the rectangle.
widthRectangle width.
heightRectangle height.
orientationOrientation of the slider.

◆ set_display()

void Gtk::StyleContext::set_display ( const Glib::RefPtr< Gdk::Display >&  display)

Attaches context to the given display.

The display is used to add style information from “global” style providers, such as the display's Gtk::Settings instance.

If you are using a Gtk::StyleContext returned from Gtk::Widget::get_style_context(), you do not need to call this yourself.

Parameters
displayA Gdk::Display.

◆ set_frame_clock()

void Gtk::StyleContext::set_frame_clock ( const Glib::RefPtr< Gdk::FrameClock >&  frame_clock)

Attaches context to the given frame clock.

The frame clock is used for the timing of animations.

If you are using a Gtk::StyleContext returned from Gtk::Widget::get_style_context(), you do not need to call this yourself.

Since gtkmm 3.94:
Parameters
frame_clockA Gdk::FrameClock.

◆ set_parent()

void Gtk::StyleContext::set_parent ( const Glib::RefPtr< StyleContext >&  parent)

Sets the parent style context for context.

The parent style context is used to implement inheritance of properties.

If you are using a Gtk::StyleContext returned from Gtk::Widget::get_style_context(), the parent will be set for you.

Parameters
parentThe new parent or nullptr.

◆ set_path()

void Gtk::StyleContext::set_path ( const WidgetPath path)

Sets the Gtk::WidgetPath used for style matching.

As a consequence, the style will be regenerated to match the new given path.

If you are using a Gtk::StyleContext returned from Gtk::Widget::get_style_context(), you do not need to call this yourself.

Parameters
pathA Gtk::WidgetPath.

◆ set_scale()

void Gtk::StyleContext::set_scale ( int  scale)

Sets the scale to use when getting image assets for the style.

Parameters
scaleScale.

◆ set_state()

void Gtk::StyleContext::set_state ( StateFlags  flags)

Sets the state to be used for style matching.

Parameters
flagsState to represent.

◆ signal_changed()

Glib::SignalProxy<void()> Gtk::StyleContext::signal_changed ( )
Slot Prototype:
void on_my_changed()

Flags: Run First

The signal_changed() signal is emitted when there is a change in the Gtk::StyleContext.

For a Gtk::StyleContext returned by Gtk::Widget::get_style_context(), the Gtk::Widget::signal_style_updated() signal/vfunc might be more convenient to use.

This signal is useful when using the theming layer standalone.

◆ unset_parent()

void Gtk::StyleContext::unset_parent ( )

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::StyleContext > wrap ( GtkStyleContext *  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.