CssProviderProtocol

public protocol CssProviderProtocol : ObjectProtocol, StyleProviderProtocol

GtkCssProvider is an object implementing the GtkStyleProvider interface. 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 gtk_css_provider_load_from_file() or gtk_css_provider_load_from_resource() 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, the file $XDG_CONFIG_HOME/gtk-3.0/gtk.css is loaded if it exists. Then, GTK+ loads the first existing file among XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk.css, $HOME/.themes/THEME/gtk-VERSION/gtk.css, $XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk.css and DATADIR/share/themes/THEME/gtk-VERSION/gtk.css, where THEME is the name of the current theme (see the GtkSettings:gtk-theme-name 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 3.0.

In the same way, GTK+ tries to load a gtk-keys.css file for the current key theme, as defined by GtkSettings:gtk-key-theme-name.

The CssProviderProtocol protocol exposes the methods and properties of an underlying GtkCssProvider instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see CssProvider. Alternatively, use CssProviderRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkCssProvider instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • css_provider_ptr Default implementation

    Typed pointer to the underlying GtkCssProvider instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkCssProvider instance.

    Declaration

    Swift

    var css_provider_ptr: UnsafeMutablePointer<GtkCssProvider>! { get }
  • Required Initialiser for types conforming to CssProviderProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)
  • styleProvider Extension method

    Return the CSS provider as a style provider

    Declaration

    Swift

    @inlinable
    var styleProvider: StyleProviderRef { get }
  • load(from:) Extension method

    Loads the data provided in the given string into the CSS Provider

    Throws

    an ErrorType if there is an issue with the CSS

    Declaration

    Swift

    @discardableResult
    @inlinable
    func load(from data: String) throws -> Bool

    Parameters

    data

    the CSS data represented as a String

    Return Value

    true iff successful

CssProvider signals

  • Connect a Swift signal handler to the given, typed CssProviderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    handler

    The Swift signal handler (function or callback) to invoke on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Connect a C signal handler to the given, typed CssProviderSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: CssProviderSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    signalHandler

    The C function to be called on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

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

    Note

    This represents the underlying parsing-error signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onParsingError(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: CssProviderRef, _ section: CssSectionRef, _ error: GLib.ErrorRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    section

    section the error happened in

    error

    The parsing error

    handler

    The signal handler to call Run the given callback whenever the parsingError signal is emitted

  • parsingErrorSignal Extension method

    Typed parsing-error signal for using the connect(signal:) methods

    Declaration

    Swift

    static var parsingErrorSignal: CssProviderSignalName { get }

CssProvider Class: CssProviderProtocol extension (methods and fields)

  • loadFrom(data:length:) Extension method

    Loads data into css_provider, and by doing so clears any previously loaded information.

    Declaration

    Swift

    @inlinable
    func loadFrom(data: UnsafePointer<gchar>!, length: gssize) throws -> Bool
  • loadFrom(file:) Extension method

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

    Declaration

    Swift

    @inlinable
    func loadFrom<FileT>(file: FileT) throws -> Bool where FileT : FileProtocol
  • loadFrom(path:) Extension method

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

    Declaration

    Swift

    @inlinable
    func loadFrom(path: UnsafePointer<gchar>!) throws -> Bool
  • loadFrom(resourcePath:) Extension method

    Loads the data contained in the resource at resource_path into the GtkCssProvider, clearing any previously loaded information.

    To track errors while loading CSS, connect to the GtkCssProvider::parsing-error signal.

    Declaration

    Swift

    @inlinable
    func loadFrom(resourcePath: UnsafePointer<gchar>!)
  • toString() Extension method

    Converts 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 basically create a duplicate of this provider.

    Declaration

    Swift

    @inlinable
    func toString() -> String!
  • parentInstance Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var parentInstance: GObject { get }