Skip to main content

gtk4/auto/
svg.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_24")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
7use crate::{Overflow, Settings};
8use crate::{SvgFeatures, SymbolicPaintable, ffi};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// A paintable implementation that renders SVG, with animations.
19    ///
20    /// [`Svg`][crate::Svg] objects are created by parsing a subset of SVG,
21    /// including SVG animations.
22    ///
23    /// [`Svg`][crate::Svg] fills or strokes paths with symbolic or fixed colors.
24    /// It can have multiple states, and paths can be included in a subset
25    /// of the states. States can have animations, and the transition
26    /// between different states can also be animated.
27    ///
28    /// To show a static SVG image, it is enough to load the
29    /// the SVG and use it like any other paintable.
30    ///
31    /// To play an SVG animation, use [`set_frame_clock()`][Self::set_frame_clock()]
32    /// to connect the paintable to a frame clock, and call
33    /// [`play()`][Self::play()] after loading the SVG. The animation can
34    /// be paused using [`pause()`][Self::pause()].
35    ///
36    /// To set the current state, use [`set_state()`][Self::set_state()].
37    ///
38    ///
39    /// ## Error handling
40    ///
41    /// Loading an SVG into [`Svg`][crate::Svg] will always produce a (possibly empty)
42    /// paintable. GTK will drop things that it can't handle and try to make
43    /// sense of the rest.
44    ///
45    /// To track errors during parsing or rendering, connect to the
46    /// [`error`][struct@crate::Svg#error] signal.
47    ///
48    /// For parsing errors in the `GTK_SVG_ERROR` domain, the functions
49    /// `Gtk::SvgError::get_start()`, `Gtk::SvgError::get_end()`,
50    /// [`SvgError::element()`][crate::SvgError::element()] and [`SvgError::attribute()`][crate::SvgError::attribute()]
51    /// can be used to obtain information about where the error occurred.
52    ///
53    ///
54    /// ## The supported subset of SVG
55    ///
56    /// The paintable supports much of [SVG 2](https://svgwg.org/svg2-draft/),
57    /// including [animations](https://svgwg.org/specs/animations/), with some
58    /// exceptions.
59    ///
60    /// Among the graphical elements, `<textPath>` and `<foreignObject>` are
61    /// not supported.
62    ///
63    /// In the `<filter>` element, the following primitives are not supported:
64    /// feConvolveMatrix, feDiffuseLighting, feMorphology, feSpecularLighting.
65    ///
66    /// Support for the `mask` attribute is limited to just a url referring to
67    /// the `<mask>` element by ID.
68    ///
69    /// In animation elements, the parsing of `begin` and `end` attributes is
70    /// limited, and the `min` and `max` attributes are not supported.
71    ///
72    /// The interactive aspects of SVG are supported by [`SvgWidget`][crate::SvgWidget].
73    ///
74    ///
75    /// ## SVG Extensions
76    ///
77    /// The paintable supports a number of [custom attributes](icon-format.html)
78    /// that offer a convenient way to define states, transitions and animations.
79    /// For example,
80    ///
81    ///     <circle cx='5' cy='5' r='5'
82    ///             gpa:states='0 1'
83    ///             gpa:animation-type='automatic'
84    ///             gpa:animation-direction='segment'
85    ///             gpa:animation-duration='600ms'/>
86    ///
87    /// defines the circle to be shown in states 0 and 1, and animates a segment
88    /// of the circle.
89    ///
90    ///
91    /// <image src="svg-renderer1.svg">
92    ///
93    /// Note that the generated animations are implemented using standard
94    /// SVG attributes (`visibility`, `stroke-dasharray, `stroke-dashoffset`,
95    /// `pathLength` and `filter`). Setting these attributes in your SVG
96    /// is therefore going to interfere with generated animations.
97    ///
98    /// To connect general SVG animations to the states of the paintable,
99    /// use the custom `StateChange(...)` condition in the `begin` and `end`
100    /// attributes of SVG animation elements. For example,
101    ///
102    ///     <animate href='path1'
103    ///              attributeName='fill'
104    ///              begin='StateChange(1 2 3, 0)'
105    ///              dur='300ms'
106    ///              fill='freeze'
107    ///              from='black'
108    ///              to='magenta'/>
109    ///
110    /// will make the fill color of path1 transition from black to
111    /// magenta when the renderer enters state 0 from states 1, 2, or 3.
112    ///
113    /// <image src="svg-renderer2.svg">
114    ///
115    /// The `StateChange(...)` condition triggers for upcoming state changes
116    /// as well, to support fade-out transitions. For example,
117    ///
118    ///     <animate href='path1'
119    ///              attributeName='opacity'
120    ///              begin='StateChange(0, 1 2 3) -300ms'
121    ///              dur='300ms'
122    ///              fill='freeze'
123    ///              from='1'
124    ///              to='0'/>
125    ///
126    /// will start a fade-out of path1 300ms before a transition from state
127    /// 0 to 1, 2 or 3.
128    ///
129    /// States can be specified numerically, or by name. It is also possible
130    /// to say `not STATE` instead of explictly listing all states that are
131    /// different from `STATE`.
132    ///
133    /// In addition to the `gpa:fill` and `gpa:stroke` attributes, symbolic
134    /// colors can also be specified as a custom paint server reference,
135    /// like this: `url(#gpa:warning)`. This works in `fill` and `stroke`
136    /// attributes, but also when specifying colors in SVG animation
137    /// attributes like `to` or `values`.
138    ///
139    /// Note that the SVG syntax allows for a fallback RGB color to be
140    /// specified after the url, for compatibility with other SVG consumers:
141    ///
142    ///     fill='url(#gpa:warning) orange'
143    ///
144    /// GtkSvg also allows to refer to symbolic colors like system colors
145    /// in CSS, with names like SymbolicForeground, SymbolicSuccess, etc.
146    /// These can be used whenever a color is required.
147    ///
148    /// In contrast to SVG 1.1 and 2.0, we allow the `transform` attribute
149    /// to be animated with `<animate>`.
150    ///
151    ///
152    /// ## On untrusted data
153    ///
154    /// Note that GtkSvg is an-process parser for a complex format and is
155    /// written in C. It was specifically created to support animated icons
156    /// and theme resources, not for general content. If you need to load SVG
157    /// data from untrusted sources, we recommend using frameworks that were
158    /// designed to handle such data, like [glycin](https://lib.rs/crates/glycin).
159    ///
160    /// ## Properties
161    ///
162    ///
163    /// #### `features`
164    ///  Enabled features for this paintable.
165    ///
166    /// Note that features have to be set before
167    /// loading SVG data to take effect.
168    ///
169    /// Readable | Writable
170    ///
171    ///
172    /// #### `overflow`
173    ///  Whether the rendering will be clipped to the bounds.
174    ///
175    /// Readable | Writable
176    ///
177    ///
178    /// #### `playing`
179    ///  Whether the paintable is currently animating its content.
180    ///
181    /// To set this property, use the [`Svg::play()`][crate::Svg::play()] and
182    /// [`Svg::pause()`][crate::Svg::pause()] functions.
183    ///
184    /// Readable | Writable
185    ///
186    ///
187    /// #### `resource`
188    ///  Resource to load SVG data from.
189    ///
190    /// This property is meant to create a paintable
191    /// from a resource in ui files.
192    ///
193    /// Readable | Writable
194    ///
195    ///
196    /// #### `state`
197    ///  The current state of the renderer.
198    ///
199    /// This can be a number between 0 and 63.
200    ///
201    /// Readable | Writable
202    ///
203    ///
204    /// #### `stylesheet`
205    ///  A CSS stylesheet to apply to the SVG.
206    ///
207    /// Readable | Writable
208    ///
209    ///
210    /// #### `weight`
211    ///  If not set to -1, this value overrides the weight used
212    /// when rendering the paintable.
213    ///
214    /// Readable | Writable
215    ///
216    /// ## Signals
217    ///
218    ///
219    /// #### `error`
220    ///  Signals that an error occurred.
221    ///
222    /// Errors can occur both during parsing and during rendering.
223    ///
224    /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
225    /// context information about the location of parsing errors can
226    /// be obtained with the various `gtk_svg_error` functions.
227    ///
228    /// Parsing errors are never fatal, so the parsing will resume after
229    /// the error. Errors may however cause parts of the given data or
230    /// even all of it to not be parsed at all. So it is a useful idea
231    /// to check that the parsing succeeds by connecting to this signal.
232    ///
233    /// ::: note
234    ///     This signal is emitted in the middle of parsing or rendering,
235    ///     and if you handle it, you must be careful. Logging the errors
236    ///     you receive is fine, but modifying the widget hierarchy or
237    ///     changing the paintable state definitively isn't.
238    ///
239    ///     If in doubt, defer to an idle.
240    ///
241    ///
242    /// <details><summary><h4>Paintable</h4></summary>
243    ///
244    ///
245    /// #### `invalidate-contents`
246    ///  Emitted when the contents of the @paintable change.
247    ///
248    /// Examples for such an event would be videos changing to the next frame or
249    /// the icon theme for an icon changing.
250    ///
251    ///
252    ///
253    ///
254    /// #### `invalidate-size`
255    ///  Emitted when the intrinsic size of the @paintable changes.
256    ///
257    /// This means the values reported by at least one of
258    /// [`PaintableExtManual::intrinsic_width()`][crate::gdk::prelude::PaintableExtManual::intrinsic_width()],
259    /// [`PaintableExtManual::intrinsic_height()`][crate::gdk::prelude::PaintableExtManual::intrinsic_height()] or
260    /// [`PaintableExtManual::intrinsic_aspect_ratio()`][crate::gdk::prelude::PaintableExtManual::intrinsic_aspect_ratio()]
261    /// has changed.
262    ///
263    /// Examples for such an event would be a paintable displaying
264    /// the contents of a toplevel surface being resized.
265    ///
266    ///
267    /// </details>
268    ///
269    /// # Implements
270    ///
271    /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
272    #[doc(alias = "GtkSvg")]
273    pub struct Svg(Object<ffi::GtkSvg, ffi::GtkSvgClass>) @implements gdk::Paintable, SymbolicPaintable;
274
275    match fn {
276        type_ => || ffi::gtk_svg_get_type(),
277    }
278}
279
280impl Svg {
281    /// Creates a new, empty SVG paintable.
282    ///
283    /// # Returns
284    ///
285    /// the paintable
286    #[doc(alias = "gtk_svg_new")]
287    pub fn new() -> Svg {
288        assert_initialized_main_thread!();
289        unsafe { from_glib_full(ffi::gtk_svg_new()) }
290    }
291
292    /// Parses the SVG data in @bytes and creates a paintable.
293    /// ## `bytes`
294    /// the data
295    ///
296    /// # Returns
297    ///
298    /// the paintable
299    #[doc(alias = "gtk_svg_new_from_bytes")]
300    #[doc(alias = "new_from_bytes")]
301    pub fn from_bytes(bytes: &glib::Bytes) -> Svg {
302        assert_initialized_main_thread!();
303        unsafe { from_glib_full(ffi::gtk_svg_new_from_bytes(bytes.to_glib_none().0)) }
304    }
305
306    /// Parses the SVG data in the resource and creates a paintable.
307    /// ## `path`
308    /// the resource path
309    ///
310    /// # Returns
311    ///
312    /// the paintable
313    #[doc(alias = "gtk_svg_new_from_resource")]
314    #[doc(alias = "new_from_resource")]
315    pub fn from_resource(path: &str) -> Svg {
316        assert_initialized_main_thread!();
317        unsafe { from_glib_full(ffi::gtk_svg_new_from_resource(path.to_glib_none().0)) }
318    }
319
320    /// Returns the currently enabled features.
321    ///
322    /// # Returns
323    ///
324    /// the enabled features
325    #[doc(alias = "gtk_svg_get_features")]
326    #[doc(alias = "get_features")]
327    pub fn features(&self) -> SvgFeatures {
328        unsafe { from_glib(ffi::gtk_svg_get_features(self.to_glib_none().0)) }
329    }
330
331    /// Gets the current overflow value.
332    ///
333    /// # Returns
334    ///
335    /// the current overflow value
336    #[cfg(feature = "v4_24")]
337    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
338    #[doc(alias = "gtk_svg_get_overflow")]
339    #[doc(alias = "get_overflow")]
340    pub fn overflow(&self) -> Overflow {
341        unsafe { from_glib(ffi::gtk_svg_get_overflow(self.to_glib_none().0)) }
342    }
343
344    /// Gets the current state of the paintable.
345    ///
346    /// # Returns
347    ///
348    /// the state
349    #[doc(alias = "gtk_svg_get_state")]
350    #[doc(alias = "get_state")]
351    pub fn state(&self) -> u32 {
352        unsafe { ffi::gtk_svg_get_state(self.to_glib_none().0) }
353    }
354
355    /// Returns a `NULL`-terminated array of
356    /// state names, if available.
357    ///
358    /// Note that the returned array and the strings
359    /// contained in it will only be valid until the
360    /// [`Svg`][crate::Svg] is cleared or reloaded, so if you
361    /// want to keep it around, you should make a copy.
362    ///
363    /// # Returns
364    ///
365    /// the state names
366    ///
367    /// ## `length`
368    /// return location for the number
369    ///   of strings that are returned
370    #[doc(alias = "gtk_svg_get_state_names")]
371    #[doc(alias = "get_state_names")]
372    pub fn state_names(&self) -> (Vec<glib::GString>, u32) {
373        unsafe {
374            let mut length = std::mem::MaybeUninit::uninit();
375            let ret = FromGlibPtrContainer::from_glib_none(ffi::gtk_svg_get_state_names(
376                self.to_glib_none().0,
377                length.as_mut_ptr(),
378            ));
379            (ret, length.assume_init())
380        }
381    }
382
383    /// Gets the CSS user stylesheet.
384    ///
385    /// # Returns
386    ///
387    /// a `GBytes` with the CSS data
388    #[cfg(feature = "v4_24")]
389    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
390    #[doc(alias = "gtk_svg_get_stylesheet")]
391    #[doc(alias = "get_stylesheet")]
392    pub fn stylesheet(&self) -> Option<glib::Bytes> {
393        unsafe { from_glib_full(ffi::gtk_svg_get_stylesheet(self.to_glib_none().0)) }
394    }
395
396    /// Gets the value of the weight property.
397    ///
398    /// # Returns
399    ///
400    /// the weight
401    #[doc(alias = "gtk_svg_get_weight")]
402    #[doc(alias = "get_weight")]
403    pub fn weight(&self) -> f64 {
404        unsafe { ffi::gtk_svg_get_weight(self.to_glib_none().0) }
405    }
406
407    /// Loads SVG content into an existing SVG paintable.
408    ///
409    /// To track errors while loading SVG content,
410    /// connect to the [`error`][struct@crate::Svg#error] signal.
411    ///
412    /// This clears any previously loaded content.
413    /// ## `bytes`
414    /// the data to load
415    #[doc(alias = "gtk_svg_load_from_bytes")]
416    pub fn load_from_bytes(&self, bytes: &glib::Bytes) {
417        unsafe {
418            ffi::gtk_svg_load_from_bytes(self.to_glib_none().0, bytes.to_glib_none().0);
419        }
420    }
421
422    /// Loads SVG content into an existing SVG paintable.
423    ///
424    /// To track errors while loading SVG content,
425    /// connect to the [`error`][struct@crate::Svg#error] signal.
426    ///
427    /// This clears any previously loaded content.
428    /// ## `path`
429    /// the resource path
430    #[doc(alias = "gtk_svg_load_from_resource")]
431    pub fn load_from_resource(&self, path: &str) {
432        unsafe {
433            ffi::gtk_svg_load_from_resource(self.to_glib_none().0, path.to_glib_none().0);
434        }
435    }
436
437    /// Stop any playing animations and state transitions.
438    ///
439    /// SvgAnimations can be paused and started repeatedly.
440    #[doc(alias = "gtk_svg_pause")]
441    pub fn pause(&self) {
442        unsafe {
443            ffi::gtk_svg_pause(self.to_glib_none().0);
444        }
445    }
446
447    /// Start playing animations and state transitions.
448    ///
449    /// SvgAnimations can be paused and started repeatedly.
450    #[doc(alias = "gtk_svg_play")]
451    pub fn play(&self) {
452        unsafe {
453            ffi::gtk_svg_play(self.to_glib_none().0);
454        }
455    }
456
457    /// Serializes the content of the renderer as SVG.
458    ///
459    /// The SVG will be similar to the orignally loaded one,
460    /// but is not guaranteed to be 100% identical.
461    ///
462    /// This function serializes the DOM, i.e. the results
463    /// of parsing the SVG. It does not reflect the effect
464    /// of applying animations.
465    ///
466    /// # Returns
467    ///
468    /// the serialized contents
469    #[doc(alias = "gtk_svg_serialize")]
470    pub fn serialize(&self) -> glib::Bytes {
471        unsafe { from_glib_full(ffi::gtk_svg_serialize(self.to_glib_none().0)) }
472    }
473
474    /// Enables or disables features of the SVG paintable.
475    ///
476    /// By default, all features are enabled.
477    ///
478    /// Note that this call only has an effect before the
479    /// SVG is loaded.
480    /// ## `features`
481    /// features to enable
482    #[doc(alias = "gtk_svg_set_features")]
483    #[doc(alias = "features")]
484    pub fn set_features(&self, features: SvgFeatures) {
485        unsafe {
486            ffi::gtk_svg_set_features(self.to_glib_none().0, features.into_glib());
487        }
488    }
489
490    /// Sets a frame clock.
491    ///
492    /// Without a frame clock, GtkSvg will not advance animations.
493    /// ## `clock`
494    /// the frame clock
495    #[doc(alias = "gtk_svg_set_frame_clock")]
496    pub fn set_frame_clock(&self, clock: &gdk::FrameClock) {
497        unsafe {
498            ffi::gtk_svg_set_frame_clock(self.to_glib_none().0, clock.to_glib_none().0);
499        }
500    }
501
502    /// Sets whether the rendering will be clipped
503    /// to the bounds.
504    ///
505    /// Clipping is expected for [`gdk::Paintable`][crate::gdk::Paintable]
506    /// semantics, so this property should not be
507    /// changed when using a [`Svg`][crate::Svg] as a paintable.
508    /// ## `overflow`
509    /// the new overflow value
510    #[cfg(feature = "v4_24")]
511    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
512    #[doc(alias = "gtk_svg_set_overflow")]
513    #[doc(alias = "overflow")]
514    pub fn set_overflow(&self, overflow: Overflow) {
515        unsafe {
516            ffi::gtk_svg_set_overflow(self.to_glib_none().0, overflow.into_glib());
517        }
518    }
519
520    /// Sets a settings object holding settinsg used when
521    /// rendering the SVG.
522    /// ## `settings`
523    /// the settings object
524    #[cfg(feature = "v4_24")]
525    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
526    #[doc(alias = "gtk_svg_set_settings")]
527    pub fn set_settings(&self, settings: Option<&Settings>) {
528        unsafe {
529            ffi::gtk_svg_set_settings(self.to_glib_none().0, settings.to_glib_none().0);
530        }
531    }
532
533    /// Sets the state of the paintable.
534    ///
535    /// If the paintable is currently playing, the state change
536    /// will apply transitions that are defined in the SVG. If
537    /// the paintable is not playing, the state change will take
538    /// effect instantaneously.
539    /// ## `state`
540    /// the state to set, as a value between 0 and 63
541    #[doc(alias = "gtk_svg_set_state")]
542    #[doc(alias = "state")]
543    pub fn set_state(&self, state: u32) {
544        unsafe {
545            ffi::gtk_svg_set_state(self.to_glib_none().0, state);
546        }
547    }
548
549    /// Sets a CSS user stylesheet to use.
550    ///
551    /// Note that styles are applied at load time,
552    /// so this function must be called before
553    /// loading SVG.
554    /// ## `bytes`
555    /// CSS data
556    #[cfg(feature = "v4_24")]
557    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
558    #[doc(alias = "gtk_svg_set_stylesheet")]
559    #[doc(alias = "stylesheet")]
560    pub fn set_stylesheet(&self, bytes: Option<&glib::Bytes>) {
561        unsafe {
562            ffi::gtk_svg_set_stylesheet(self.to_glib_none().0, bytes.to_glib_none().0);
563        }
564    }
565
566    /// Sets the weight that is used when rendering.
567    ///
568    /// The weight affects the effective linewidth when stroking
569    /// paths.
570    ///
571    /// The default value of -1 means to use the font weight
572    /// from CSS.
573    /// ## `weight`
574    /// the font weight, as a value between -1 and 1000
575    #[doc(alias = "gtk_svg_set_weight")]
576    #[doc(alias = "weight")]
577    pub fn set_weight(&self, weight: f64) {
578        unsafe {
579            ffi::gtk_svg_set_weight(self.to_glib_none().0, weight);
580        }
581    }
582
583    /// Serializes the paintable, and saves the result to a file.
584    /// ## `filename`
585    /// the file to save to
586    ///
587    /// # Returns
588    ///
589    /// true, unless an error occurred
590    #[doc(alias = "gtk_svg_write_to_file")]
591    pub fn write_to_file(&self, filename: &str) -> Result<(), glib::Error> {
592        unsafe {
593            let mut error = std::ptr::null_mut();
594            let is_ok = ffi::gtk_svg_write_to_file(
595                self.to_glib_none().0,
596                filename.to_glib_none().0,
597                &mut error,
598            );
599            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
600            if error.is_null() {
601                Ok(())
602            } else {
603                Err(from_glib_full(error))
604            }
605        }
606    }
607
608    /// Whether the paintable is currently animating its content.
609    ///
610    /// To set this property, use the [`play()`][Self::play()] and
611    /// [`pause()`][Self::pause()] functions.
612    #[cfg(feature = "v4_22")]
613    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
614    pub fn is_playing(&self) -> bool {
615        ObjectExt::property(self, "playing")
616    }
617
618    /// Whether the paintable is currently animating its content.
619    ///
620    /// To set this property, use the [`play()`][Self::play()] and
621    /// [`pause()`][Self::pause()] functions.
622    #[cfg(feature = "v4_22")]
623    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
624    pub fn set_playing(&self, playing: bool) {
625        ObjectExt::set_property(self, "playing", playing)
626    }
627
628    /// Resource to load SVG data from.
629    ///
630    /// This property is meant to create a paintable
631    /// from a resource in ui files.
632    #[cfg(feature = "v4_22")]
633    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
634    pub fn resource(&self) -> Option<glib::GString> {
635        ObjectExt::property(self, "resource")
636    }
637
638    /// Resource to load SVG data from.
639    ///
640    /// This property is meant to create a paintable
641    /// from a resource in ui files.
642    #[cfg(feature = "v4_22")]
643    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
644    pub fn set_resource(&self, resource: Option<&str>) {
645        ObjectExt::set_property(self, "resource", resource)
646    }
647
648    /// Signals that an error occurred.
649    ///
650    /// Errors can occur both during parsing and during rendering.
651    ///
652    /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
653    /// context information about the location of parsing errors can
654    /// be obtained with the various `gtk_svg_error` functions.
655    ///
656    /// Parsing errors are never fatal, so the parsing will resume after
657    /// the error. Errors may however cause parts of the given data or
658    /// even all of it to not be parsed at all. So it is a useful idea
659    /// to check that the parsing succeeds by connecting to this signal.
660    ///
661    /// ::: note
662    ///     This signal is emitted in the middle of parsing or rendering,
663    ///     and if you handle it, you must be careful. Logging the errors
664    ///     you receive is fine, but modifying the widget hierarchy or
665    ///     changing the paintable state definitively isn't.
666    ///
667    ///     If in doubt, defer to an idle.
668    /// ## `error`
669    /// the error
670    #[cfg(feature = "v4_22")]
671    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
672    #[doc(alias = "error")]
673    pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
674        unsafe extern "C" fn error_trampoline<F: Fn(&Svg, &glib::Error) + 'static>(
675            this: *mut ffi::GtkSvg,
676            error: *mut glib::ffi::GError,
677            f: glib::ffi::gpointer,
678        ) {
679            unsafe {
680                let f: &F = &*(f as *const F);
681                f(&from_glib_borrow(this), &from_glib_borrow(error))
682            }
683        }
684        unsafe {
685            let f: Box_<F> = Box_::new(f);
686            connect_raw(
687                self.as_ptr() as *mut _,
688                c"error".as_ptr(),
689                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
690                    error_trampoline::<F> as *const (),
691                )),
692                Box_::into_raw(f),
693            )
694        }
695    }
696
697    #[cfg(feature = "v4_22")]
698    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
699    #[doc(alias = "features")]
700    pub fn connect_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
701        unsafe extern "C" fn notify_features_trampoline<F: Fn(&Svg) + 'static>(
702            this: *mut ffi::GtkSvg,
703            _param_spec: glib::ffi::gpointer,
704            f: glib::ffi::gpointer,
705        ) {
706            unsafe {
707                let f: &F = &*(f as *const F);
708                f(&from_glib_borrow(this))
709            }
710        }
711        unsafe {
712            let f: Box_<F> = Box_::new(f);
713            connect_raw(
714                self.as_ptr() as *mut _,
715                c"notify::features".as_ptr(),
716                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
717                    notify_features_trampoline::<F> as *const (),
718                )),
719                Box_::into_raw(f),
720            )
721        }
722    }
723
724    #[cfg(feature = "v4_24")]
725    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
726    #[doc(alias = "overflow")]
727    pub fn connect_overflow_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
728        unsafe extern "C" fn notify_overflow_trampoline<F: Fn(&Svg) + 'static>(
729            this: *mut ffi::GtkSvg,
730            _param_spec: glib::ffi::gpointer,
731            f: glib::ffi::gpointer,
732        ) {
733            unsafe {
734                let f: &F = &*(f as *const F);
735                f(&from_glib_borrow(this))
736            }
737        }
738        unsafe {
739            let f: Box_<F> = Box_::new(f);
740            connect_raw(
741                self.as_ptr() as *mut _,
742                c"notify::overflow".as_ptr(),
743                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
744                    notify_overflow_trampoline::<F> as *const (),
745                )),
746                Box_::into_raw(f),
747            )
748        }
749    }
750
751    #[cfg(feature = "v4_22")]
752    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
753    #[doc(alias = "playing")]
754    pub fn connect_playing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
755        unsafe extern "C" fn notify_playing_trampoline<F: Fn(&Svg) + 'static>(
756            this: *mut ffi::GtkSvg,
757            _param_spec: glib::ffi::gpointer,
758            f: glib::ffi::gpointer,
759        ) {
760            unsafe {
761                let f: &F = &*(f as *const F);
762                f(&from_glib_borrow(this))
763            }
764        }
765        unsafe {
766            let f: Box_<F> = Box_::new(f);
767            connect_raw(
768                self.as_ptr() as *mut _,
769                c"notify::playing".as_ptr(),
770                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
771                    notify_playing_trampoline::<F> as *const (),
772                )),
773                Box_::into_raw(f),
774            )
775        }
776    }
777
778    #[cfg(feature = "v4_22")]
779    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
780    #[doc(alias = "resource")]
781    pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
782        unsafe extern "C" fn notify_resource_trampoline<F: Fn(&Svg) + 'static>(
783            this: *mut ffi::GtkSvg,
784            _param_spec: glib::ffi::gpointer,
785            f: glib::ffi::gpointer,
786        ) {
787            unsafe {
788                let f: &F = &*(f as *const F);
789                f(&from_glib_borrow(this))
790            }
791        }
792        unsafe {
793            let f: Box_<F> = Box_::new(f);
794            connect_raw(
795                self.as_ptr() as *mut _,
796                c"notify::resource".as_ptr(),
797                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
798                    notify_resource_trampoline::<F> as *const (),
799                )),
800                Box_::into_raw(f),
801            )
802        }
803    }
804
805    #[cfg(feature = "v4_22")]
806    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
807    #[doc(alias = "state")]
808    pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
809        unsafe extern "C" fn notify_state_trampoline<F: Fn(&Svg) + 'static>(
810            this: *mut ffi::GtkSvg,
811            _param_spec: glib::ffi::gpointer,
812            f: glib::ffi::gpointer,
813        ) {
814            unsafe {
815                let f: &F = &*(f as *const F);
816                f(&from_glib_borrow(this))
817            }
818        }
819        unsafe {
820            let f: Box_<F> = Box_::new(f);
821            connect_raw(
822                self.as_ptr() as *mut _,
823                c"notify::state".as_ptr(),
824                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
825                    notify_state_trampoline::<F> as *const (),
826                )),
827                Box_::into_raw(f),
828            )
829        }
830    }
831
832    #[cfg(feature = "v4_24")]
833    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
834    #[doc(alias = "stylesheet")]
835    pub fn connect_stylesheet_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
836        unsafe extern "C" fn notify_stylesheet_trampoline<F: Fn(&Svg) + 'static>(
837            this: *mut ffi::GtkSvg,
838            _param_spec: glib::ffi::gpointer,
839            f: glib::ffi::gpointer,
840        ) {
841            unsafe {
842                let f: &F = &*(f as *const F);
843                f(&from_glib_borrow(this))
844            }
845        }
846        unsafe {
847            let f: Box_<F> = Box_::new(f);
848            connect_raw(
849                self.as_ptr() as *mut _,
850                c"notify::stylesheet".as_ptr(),
851                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
852                    notify_stylesheet_trampoline::<F> as *const (),
853                )),
854                Box_::into_raw(f),
855            )
856        }
857    }
858
859    #[cfg(feature = "v4_22")]
860    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
861    #[doc(alias = "weight")]
862    pub fn connect_weight_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
863        unsafe extern "C" fn notify_weight_trampoline<F: Fn(&Svg) + 'static>(
864            this: *mut ffi::GtkSvg,
865            _param_spec: glib::ffi::gpointer,
866            f: glib::ffi::gpointer,
867        ) {
868            unsafe {
869                let f: &F = &*(f as *const F);
870                f(&from_glib_borrow(this))
871            }
872        }
873        unsafe {
874            let f: Box_<F> = Box_::new(f);
875            connect_raw(
876                self.as_ptr() as *mut _,
877                c"notify::weight".as_ptr(),
878                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
879                    notify_weight_trampoline::<F> as *const (),
880                )),
881                Box_::into_raw(f),
882            )
883        }
884    }
885}
886
887#[cfg(feature = "v4_22")]
888#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
889impl Default for Svg {
890    fn default() -> Self {
891        Self::new()
892    }
893}