Class CssProvider
- All Implemented Interfaces:
Proxy
,StyleProvider
GtkCssProvider
is an object implementing the GtkStyleProvider
interface
for CSS.
It is able to parse CSS-like input in order to style widgets.
An application can make GTK parse a specific CSS style sheet by calling
loadFromFile(org.gnome.gio.File)
or
loadFromResource(java.lang.String)
and adding the provider with StyleContext.addProvider(org.gnome.gtk.StyleProvider, int)
or
StyleContext.addProviderForDisplay(org.gnome.gdk.Display, org.gnome.gtk.StyleProvider, int)
.
In addition, certain files will be read when GTK is initialized.
First, the file $XDG_CONFIG_HOME/gtk-4.0/gtk.css
is loaded if it
exists. Then, GTK loads the first existing file among
XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css
and
DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
where THEME
is the name of the current theme (see the
Gtk.Settings:gtk-theme-name
setting), VARIANT
is the
variant to load (see the
Gtk.Settings:gtk-application-prefer-dark-theme
setting),
DATADIR
is the prefix configured when GTK was compiled (unless
overridden by the GTK_DATA_PREFIX
environment variable), and
VERSION
is the GTK version number. If no file is found for the
current version, GTK tries older versions all the way back to 4.0.
To track errors while loading CSS, connect to the
Gtk.CssProvider::parsing-error
signal.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
CssProvider.Builder<B extends CssProvider.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
static interface
Functional interface declaration of theParsingErrorCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.StyleProvider
StyleProvider.GtkPrivateChangedCallback, StyleProvider.StyleProviderImpl
-
Constructor Summary
ConstructorDescriptionReturns a newly createdGtkCssProvider
.CssProvider
(MemorySegment address) Create a CssProvider proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected CssProvider
asParent()
Returns this instance as if it were its parent type.static CssProvider.Builder
<? extends CssProvider.Builder> builder()
ACssProvider.Builder
object constructs aCssProvider
with the specified properties.void
emitParsingError
(CssSection section, GError error) Emits the "parsing-error" signal.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the CssProvider classvoid
loadFromBytes
(Bytes data) Loadsdata
into this CssProvider.void
loadFromData
(String data, long length) Deprecated.void
loadFromFile
(File file) Loads the data contained infile
into this CssProvider.void
loadFromPath
(String path) Loads the data contained inpath
into this CssProvider.void
loadFromResource
(String resourcePath) Loads the data contained in the resource atresourcePath
into the this CssProvider.void
loadFromString
(String string) Loadsstring
into this CssProvider.void
Loads a theme from the usual theme paths.Signals that a parsing error occurred.toString()
Converts the this CssProvider into a string representation in CSS format.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.gnome.gtk.StyleProvider
emitGtkPrivateChanged, onGtkPrivateChanged
-
Constructor Details
-
CssProvider
Create a CssProvider proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
CssProvider
public CssProvider()Returns a newly createdGtkCssProvider
.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
loadFromBytes
Loadsdata
into this CssProvider.This clears any previously loaded information.
- Parameters:
data
-GBytes
containing the data to load
-
loadFromData
Deprecated.Loadsdata
into this CssProvider.This clears any previously loaded information.
- Parameters:
data
- CSS data to be parsedlength
- the length ofdata
in bytes, or -1 for NUL terminated strings
-
loadFromFile
Loads the data contained infile
into this CssProvider.This clears any previously loaded information.
- Parameters:
file
-GFile
pointing to a file to load
-
loadFromPath
Loads the data contained inpath
into this CssProvider.This clears any previously loaded information.
- Parameters:
path
- the path of a filename to load, in the GLib filename encoding
-
loadFromResource
Loads the data contained in the resource atresourcePath
into the this CssProvider.This clears any previously loaded information.
- Parameters:
resourcePath
- aGResource
resource path
-
loadFromString
Loadsstring
into this CssProvider.This clears any previously loaded information.
- Parameters:
string
- the CSS to load
-
loadNamed
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.
- Parameters:
name
- A theme namevariant
- variant to load, for example, "dark", ornull
for the default
-
toString
Converts the this CssProvider into a string representation in CSS format.Using
loadFromString(java.lang.String)
with the return value from this function on a new provider created withCssProvider()
will basically create a duplicate of this this CssProvider. -
onParsingError
public SignalConnection<CssProvider.ParsingErrorCallback> onParsingError(CssProvider.ParsingErrorCallback handler) Signals that a parsing error occurred.The expected error values are in the
Gtk.CssParserError
andGtk.CssParserWarning
enumerations.The
path
,line
andposition
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:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitParsingError
Emits the "parsing-error" signal. SeeonParsingError(org.gnome.gtk.CssProvider.ParsingErrorCallback)
. -
builder
ACssProvider.Builder
object constructs aCssProvider
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCssProvider.Builder.build()
.
-
loadFromString(java.lang.String)
orloadFromBytes(org.gnome.glib.Bytes)
instead