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;
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 | Writeable
158    ///
159    ///
160    /// #### `overflow`
161    ///  Whether the rendering will be clipped to the bounds.
162    ///
163    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
190    ///
191    ///
192    /// #### `stylesheet`
193    ///  A CSS stylesheet to apply to the SVG.
194    ///
195    /// Readable | Writeable
196    ///
197    ///
198    /// #### `weight`
199    ///  If not set to -1, this value overrides the weight used
200    /// when rendering the paintable.
201    ///
202    /// Readable | Writeable
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 the state of the paintable.
509    ///
510    /// If the paintable is currently playing, the state change
511    /// will apply transitions that are defined in the SVG. If
512    /// the paintable is not playing, the state change will take
513    /// effect instantaneously.
514    /// ## `state`
515    /// the state to set, as a value between 0 and 63
516    #[doc(alias = "gtk_svg_set_state")]
517    #[doc(alias = "state")]
518    pub fn set_state(&self, state: u32) {
519        unsafe {
520            ffi::gtk_svg_set_state(self.to_glib_none().0, state);
521        }
522    }
523
524    /// Sets a CSS user stylesheet to use.
525    ///
526    /// Note that styles are applied at load time,
527    /// so this function must be called before
528    /// loading SVG.
529    /// ## `bytes`
530    /// CSS data
531    #[cfg(feature = "v4_24")]
532    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
533    #[doc(alias = "gtk_svg_set_stylesheet")]
534    #[doc(alias = "stylesheet")]
535    pub fn set_stylesheet(&self, bytes: Option<&glib::Bytes>) {
536        unsafe {
537            ffi::gtk_svg_set_stylesheet(self.to_glib_none().0, bytes.to_glib_none().0);
538        }
539    }
540
541    /// Sets the weight that is used when rendering.
542    ///
543    /// The weight affects the effective linewidth when stroking
544    /// paths.
545    ///
546    /// The default value of -1 means to use the font weight
547    /// from CSS.
548    /// ## `weight`
549    /// the font weight, as a value between -1 and 1000
550    #[doc(alias = "gtk_svg_set_weight")]
551    #[doc(alias = "weight")]
552    pub fn set_weight(&self, weight: f64) {
553        unsafe {
554            ffi::gtk_svg_set_weight(self.to_glib_none().0, weight);
555        }
556    }
557
558    /// Serializes the paintable, and saves the result to a file.
559    /// ## `filename`
560    /// the file to save to
561    ///
562    /// # Returns
563    ///
564    /// true, unless an error occurred
565    #[doc(alias = "gtk_svg_write_to_file")]
566    pub fn write_to_file(&self, filename: &str) -> Result<(), glib::Error> {
567        unsafe {
568            let mut error = std::ptr::null_mut();
569            let is_ok = ffi::gtk_svg_write_to_file(
570                self.to_glib_none().0,
571                filename.to_glib_none().0,
572                &mut error,
573            );
574            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
575            if error.is_null() {
576                Ok(())
577            } else {
578                Err(from_glib_full(error))
579            }
580        }
581    }
582
583    /// Whether the paintable is currently animating its content.
584    ///
585    /// To set this property, use the [`play()`][Self::play()] and
586    /// [`pause()`][Self::pause()] functions.
587    #[cfg(feature = "v4_22")]
588    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
589    pub fn is_playing(&self) -> bool {
590        ObjectExt::property(self, "playing")
591    }
592
593    /// Whether the paintable is currently animating its content.
594    ///
595    /// To set this property, use the [`play()`][Self::play()] and
596    /// [`pause()`][Self::pause()] functions.
597    #[cfg(feature = "v4_22")]
598    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
599    pub fn set_playing(&self, playing: bool) {
600        ObjectExt::set_property(self, "playing", playing)
601    }
602
603    /// Resource to load SVG data from.
604    ///
605    /// This property is meant to create a paintable
606    /// from a resource in ui files.
607    #[cfg(feature = "v4_22")]
608    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
609    pub fn resource(&self) -> Option<glib::GString> {
610        ObjectExt::property(self, "resource")
611    }
612
613    /// Resource to load SVG data from.
614    ///
615    /// This property is meant to create a paintable
616    /// from a resource in ui files.
617    #[cfg(feature = "v4_22")]
618    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
619    pub fn set_resource(&self, resource: Option<&str>) {
620        ObjectExt::set_property(self, "resource", resource)
621    }
622
623    /// Signals that an error occurred.
624    ///
625    /// Errors can occur both during parsing and during rendering.
626    ///
627    /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
628    /// context information about the location of parsing errors can
629    /// be obtained with the various `gtk_svg_error` functions.
630    ///
631    /// Parsing errors are never fatal, so the parsing will resume after
632    /// the error. Errors may however cause parts of the given data or
633    /// even all of it to not be parsed at all. So it is a useful idea
634    /// to check that the parsing succeeds by connecting to this signal.
635    ///
636    /// ::: note
637    ///     This signal is emitted in the middle of parsing or rendering,
638    ///     and if you handle it, you must be careful. Logging the errors
639    ///     you receive is fine, but modifying the widget hierarchy or
640    ///     changing the paintable state definitively isn't.
641    ///
642    ///     If in doubt, defer to an idle.
643    /// ## `error`
644    /// the error
645    #[cfg(feature = "v4_22")]
646    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
647    #[doc(alias = "error")]
648    pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
649        unsafe extern "C" fn error_trampoline<F: Fn(&Svg, &glib::Error) + 'static>(
650            this: *mut ffi::GtkSvg,
651            error: *mut glib::ffi::GError,
652            f: glib::ffi::gpointer,
653        ) {
654            unsafe {
655                let f: &F = &*(f as *const F);
656                f(&from_glib_borrow(this), &from_glib_borrow(error))
657            }
658        }
659        unsafe {
660            let f: Box_<F> = Box_::new(f);
661            connect_raw(
662                self.as_ptr() as *mut _,
663                c"error".as_ptr(),
664                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
665                    error_trampoline::<F> as *const (),
666                )),
667                Box_::into_raw(f),
668            )
669        }
670    }
671
672    #[cfg(feature = "v4_22")]
673    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
674    #[doc(alias = "features")]
675    pub fn connect_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
676        unsafe extern "C" fn notify_features_trampoline<F: Fn(&Svg) + 'static>(
677            this: *mut ffi::GtkSvg,
678            _param_spec: glib::ffi::gpointer,
679            f: glib::ffi::gpointer,
680        ) {
681            unsafe {
682                let f: &F = &*(f as *const F);
683                f(&from_glib_borrow(this))
684            }
685        }
686        unsafe {
687            let f: Box_<F> = Box_::new(f);
688            connect_raw(
689                self.as_ptr() as *mut _,
690                c"notify::features".as_ptr(),
691                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
692                    notify_features_trampoline::<F> as *const (),
693                )),
694                Box_::into_raw(f),
695            )
696        }
697    }
698
699    #[cfg(feature = "v4_24")]
700    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
701    #[doc(alias = "overflow")]
702    pub fn connect_overflow_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
703        unsafe extern "C" fn notify_overflow_trampoline<F: Fn(&Svg) + 'static>(
704            this: *mut ffi::GtkSvg,
705            _param_spec: glib::ffi::gpointer,
706            f: glib::ffi::gpointer,
707        ) {
708            unsafe {
709                let f: &F = &*(f as *const F);
710                f(&from_glib_borrow(this))
711            }
712        }
713        unsafe {
714            let f: Box_<F> = Box_::new(f);
715            connect_raw(
716                self.as_ptr() as *mut _,
717                c"notify::overflow".as_ptr(),
718                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
719                    notify_overflow_trampoline::<F> as *const (),
720                )),
721                Box_::into_raw(f),
722            )
723        }
724    }
725
726    #[cfg(feature = "v4_22")]
727    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
728    #[doc(alias = "playing")]
729    pub fn connect_playing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
730        unsafe extern "C" fn notify_playing_trampoline<F: Fn(&Svg) + 'static>(
731            this: *mut ffi::GtkSvg,
732            _param_spec: glib::ffi::gpointer,
733            f: glib::ffi::gpointer,
734        ) {
735            unsafe {
736                let f: &F = &*(f as *const F);
737                f(&from_glib_borrow(this))
738            }
739        }
740        unsafe {
741            let f: Box_<F> = Box_::new(f);
742            connect_raw(
743                self.as_ptr() as *mut _,
744                c"notify::playing".as_ptr(),
745                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
746                    notify_playing_trampoline::<F> as *const (),
747                )),
748                Box_::into_raw(f),
749            )
750        }
751    }
752
753    #[cfg(feature = "v4_22")]
754    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
755    #[doc(alias = "resource")]
756    pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
757        unsafe extern "C" fn notify_resource_trampoline<F: Fn(&Svg) + 'static>(
758            this: *mut ffi::GtkSvg,
759            _param_spec: glib::ffi::gpointer,
760            f: glib::ffi::gpointer,
761        ) {
762            unsafe {
763                let f: &F = &*(f as *const F);
764                f(&from_glib_borrow(this))
765            }
766        }
767        unsafe {
768            let f: Box_<F> = Box_::new(f);
769            connect_raw(
770                self.as_ptr() as *mut _,
771                c"notify::resource".as_ptr(),
772                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
773                    notify_resource_trampoline::<F> as *const (),
774                )),
775                Box_::into_raw(f),
776            )
777        }
778    }
779
780    #[cfg(feature = "v4_22")]
781    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
782    #[doc(alias = "state")]
783    pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
784        unsafe extern "C" fn notify_state_trampoline<F: Fn(&Svg) + 'static>(
785            this: *mut ffi::GtkSvg,
786            _param_spec: glib::ffi::gpointer,
787            f: glib::ffi::gpointer,
788        ) {
789            unsafe {
790                let f: &F = &*(f as *const F);
791                f(&from_glib_borrow(this))
792            }
793        }
794        unsafe {
795            let f: Box_<F> = Box_::new(f);
796            connect_raw(
797                self.as_ptr() as *mut _,
798                c"notify::state".as_ptr(),
799                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
800                    notify_state_trampoline::<F> as *const (),
801                )),
802                Box_::into_raw(f),
803            )
804        }
805    }
806
807    #[cfg(feature = "v4_24")]
808    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
809    #[doc(alias = "stylesheet")]
810    pub fn connect_stylesheet_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
811        unsafe extern "C" fn notify_stylesheet_trampoline<F: Fn(&Svg) + 'static>(
812            this: *mut ffi::GtkSvg,
813            _param_spec: glib::ffi::gpointer,
814            f: glib::ffi::gpointer,
815        ) {
816            unsafe {
817                let f: &F = &*(f as *const F);
818                f(&from_glib_borrow(this))
819            }
820        }
821        unsafe {
822            let f: Box_<F> = Box_::new(f);
823            connect_raw(
824                self.as_ptr() as *mut _,
825                c"notify::stylesheet".as_ptr(),
826                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
827                    notify_stylesheet_trampoline::<F> as *const (),
828                )),
829                Box_::into_raw(f),
830            )
831        }
832    }
833
834    #[cfg(feature = "v4_22")]
835    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
836    #[doc(alias = "weight")]
837    pub fn connect_weight_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
838        unsafe extern "C" fn notify_weight_trampoline<F: Fn(&Svg) + 'static>(
839            this: *mut ffi::GtkSvg,
840            _param_spec: glib::ffi::gpointer,
841            f: glib::ffi::gpointer,
842        ) {
843            unsafe {
844                let f: &F = &*(f as *const F);
845                f(&from_glib_borrow(this))
846            }
847        }
848        unsafe {
849            let f: Box_<F> = Box_::new(f);
850            connect_raw(
851                self.as_ptr() as *mut _,
852                c"notify::weight".as_ptr(),
853                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
854                    notify_weight_trampoline::<F> as *const (),
855                )),
856                Box_::into_raw(f),
857            )
858        }
859    }
860}
861
862#[cfg(feature = "v4_22")]
863#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
864impl Default for Svg {
865    fn default() -> Self {
866        Self::new()
867    }
868}