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