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
5use crate::{SvgFeatures, SymbolicPaintable, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A paintable implementation that renders SVG, with animations.
16    ///
17    /// [`Svg`][crate::Svg] objects are created by parsing a subset of SVG,
18    /// including SVG animations.
19    ///
20    /// [`Svg`][crate::Svg] fills or strokes paths with symbolic or fixed colors.
21    /// It can have multiple states, and paths can be included in a subset
22    /// of the states. The special 'empty' state is always available.
23    /// States can have animations, and the transition between different
24    /// states can also be animated.
25    ///
26    /// To show a static SVG image, it is enough to load the
27    /// the SVG and use it like any other paintable.
28    ///
29    /// To play an SVG animation, use [`set_frame_clock()`][Self::set_frame_clock()]
30    /// to connect the paintable to a frame clock, and call
31    /// [`play()`][Self::play()] after loading the SVG. The animation can
32    /// be paused using [`pause()`][Self::pause()].
33    ///
34    /// To find out what states a [`Svg`][crate::Svg] has, use [`n_states()`][Self::n_states()].
35    /// To set the current state, use [`set_state()`][Self::set_state()].
36    ///
37    ///
38    /// ## Error handling
39    ///
40    /// Loading an SVG into [`Svg`][crate::Svg] will always produce a (possibly empty)
41    /// paintable. GTK will drop things that it can't handle and try to make
42    /// sense of the rest.
43    ///
44    /// To track errors during parsing or rendering, connect to the
45    /// [`error`][struct@crate::Svg#error] signal.
46    ///
47    /// For parsing errors in the `GTK_SVG_ERROR` domain, the functions
48    /// `Gtk::SvgError::get_start()`, `Gtk::SvgError::get_end()`,
49    /// [`SvgError::element()`][crate::SvgError::element()] and [`SvgError::attribute()`][crate::SvgError::attribute()]
50    /// can be used to obtain information about where the error occurred.
51    ///
52    ///
53    /// ## The supported subset of SVG
54    ///
55    /// The paintable supports much of SVG 2, with some exceptions.
56    ///
57    /// Among the graphical elements, `<textPath>` and `<foreignObject>`
58    /// are not supported.
59    ///
60    /// Among the structural elements, `<a>` and `<view>` are not supported.
61    ///
62    /// In the `<filter>` element, the following primitives are not
63    /// supported: feConvolveMatrix, feDiffuseLighting,
64    /// feMorphology, feSpecularLighting and feTurbulence.
65    ///
66    /// Support for the `mask` attribute is limited to just a url
67    /// referring to the `<mask>` element by ID.
68    ///
69    /// In animation elements, the parsing of `begin` and `end` attributes
70    /// is limited, and the `min` and `max` attributes are not supported.
71    ///
72    /// Lastly, there is only minimal CSS support (the style attribute,
73    /// but not `<style>`), and no interactivity.
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    /// <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 `gpa:states(...)` condition in the `begin` and `end`
100    /// attributes of SVG animation elements. For example,
101    ///
102    ///     <animate href='path1'
103    ///              attributeName='fill'
104    ///              begin='gpa:states(0).begin'
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.
112    ///
113    /// <image src="svg-renderer2.svg">
114    ///
115    /// The `gpa:states(...)` 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='gpa:states(0).end -300ms'
121    ///              dur='300ms'
122    ///              fill='freeze'
123    ///              from='1'
124    ///              to='0'/>
125    ///
126    /// will start a fade-out of path1 300ms before state 0 ends.
127    ///
128    /// In addition to the `gpa:fill` and `gpa:stroke` attributes, symbolic
129    /// colors can also be specified as a custom paint server reference,
130    /// like this: `url(gpa:#warning)`. This works in `fill` and `stroke`
131    /// attributes, but also when specifying colors in SVG animation
132    /// attributes like `to` or `values`.
133    ///
134    /// Note that the SVG syntax allows for a fallback RGB color to be
135    /// specified after the url, for compatibility with other SVG consumers:
136    ///
137    ///     fill='url(gpa:#warning) orange'
138    ///
139    /// In contrast to SVG 1.1 and 2.0, we allow the `transform` attribute
140    /// to be animated with `<animate>`.
141    ///
142    /// ## Properties
143    ///
144    ///
145    /// #### `features`
146    ///  Enabled features for this paintable.
147    ///
148    /// Note that features have to be set before
149    /// loading SVG data to take effect.
150    ///
151    /// Readable | Writeable
152    ///
153    ///
154    /// #### `playing`
155    ///  Whether the paintable is currently animating its content.
156    ///
157    /// To set this property, use the [`Svg::play()`][crate::Svg::play()] and
158    /// [`Svg::pause()`][crate::Svg::pause()] functions.
159    ///
160    /// Readable | Writeable
161    ///
162    ///
163    /// #### `resource`
164    ///  Resource to load SVG data from.
165    ///
166    /// This property is meant to create a paintable
167    /// from a resource in ui files.
168    ///
169    /// Readable | Writeable
170    ///
171    ///
172    /// #### `state`
173    ///  The current state of the renderer.
174    ///
175    /// This can be a number between 0 and 63, or the special value
176    /// `(unsigned int) -1` to indicate the 'empty' state in which
177    /// nothing is drawn.
178    ///
179    /// Readable | Writeable
180    ///
181    ///
182    /// #### `weight`
183    ///  If not set to -1, this value overrides the weight used
184    /// when rendering the paintable.
185    ///
186    /// Readable | Writeable
187    ///
188    /// ## Signals
189    ///
190    ///
191    /// #### `error`
192    ///  Signals that an error occurred.
193    ///
194    /// Errors can occur both during parsing and during rendering.
195    ///
196    /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
197    /// context information about the location of parsing errors can
198    /// be obtained with the various `gtk_svg_error` functions.
199    ///
200    /// Parsing errors are never fatal, so the parsing will resume after
201    /// the error. Errors may however cause parts of the given data or
202    /// even all of it to not be parsed at all. So it is a useful idea
203    /// to check that the parsing succeeds by connecting to this signal.
204    ///
205    /// ::: note
206    ///     This signal is emitted in the middle of parsing or rendering,
207    ///     and if you handle it, you must be careful. Logging the errors
208    ///     you receive is fine, but modifying the widget hierarchy or
209    ///     changing the paintable state definitively isn't.
210    ///
211    ///     If in doubt, defer to an idle.
212    ///
213    ///
214    /// <details><summary><h4>Paintable</h4></summary>
215    ///
216    ///
217    /// #### `invalidate-contents`
218    ///  Emitted when the contents of the @paintable change.
219    ///
220    /// Examples for such an event would be videos changing to the next frame or
221    /// the icon theme for an icon changing.
222    ///
223    ///
224    ///
225    ///
226    /// #### `invalidate-size`
227    ///  Emitted when the intrinsic size of the @paintable changes.
228    ///
229    /// This means the values reported by at least one of
230    /// [`PaintableExtManual::intrinsic_width()`][crate::gdk::prelude::PaintableExtManual::intrinsic_width()],
231    /// [`PaintableExtManual::intrinsic_height()`][crate::gdk::prelude::PaintableExtManual::intrinsic_height()] or
232    /// [`PaintableExtManual::intrinsic_aspect_ratio()`][crate::gdk::prelude::PaintableExtManual::intrinsic_aspect_ratio()]
233    /// has changed.
234    ///
235    /// Examples for such an event would be a paintable displaying
236    /// the contents of a toplevel surface being resized.
237    ///
238    ///
239    /// </details>
240    ///
241    /// # Implements
242    ///
243    /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
244    #[doc(alias = "GtkSvg")]
245    pub struct Svg(Object<ffi::GtkSvg, ffi::GtkSvgClass>) @implements gdk::Paintable, SymbolicPaintable;
246
247    match fn {
248        type_ => || ffi::gtk_svg_get_type(),
249    }
250}
251
252impl Svg {
253    /// Creates a new, empty SVG paintable.
254    ///
255    /// # Returns
256    ///
257    /// the paintable
258    #[doc(alias = "gtk_svg_new")]
259    pub fn new() -> Svg {
260        assert_initialized_main_thread!();
261        unsafe { from_glib_full(ffi::gtk_svg_new()) }
262    }
263
264    /// Parses the SVG data in @bytes and creates a paintable.
265    /// ## `bytes`
266    /// the data
267    ///
268    /// # Returns
269    ///
270    /// the paintable
271    #[doc(alias = "gtk_svg_new_from_bytes")]
272    #[doc(alias = "new_from_bytes")]
273    pub fn from_bytes(bytes: &glib::Bytes) -> Svg {
274        assert_initialized_main_thread!();
275        unsafe { from_glib_full(ffi::gtk_svg_new_from_bytes(bytes.to_glib_none().0)) }
276    }
277
278    /// Parses the SVG data in the resource and creates a paintable.
279    /// ## `path`
280    /// the resource path
281    ///
282    /// # Returns
283    ///
284    /// the paintable
285    #[doc(alias = "gtk_svg_new_from_resource")]
286    #[doc(alias = "new_from_resource")]
287    pub fn from_resource(path: &str) -> Svg {
288        assert_initialized_main_thread!();
289        unsafe { from_glib_full(ffi::gtk_svg_new_from_resource(path.to_glib_none().0)) }
290    }
291
292    /// Returns the currently enabled features.
293    ///
294    /// # Returns
295    ///
296    /// the enabled features
297    #[doc(alias = "gtk_svg_get_features")]
298    #[doc(alias = "get_features")]
299    pub fn features(&self) -> SvgFeatures {
300        unsafe { from_glib(ffi::gtk_svg_get_features(self.to_glib_none().0)) }
301    }
302
303    /// Gets the number of states defined in the SVG.
304    ///
305    /// Note that there is always an empty state, which does
306    /// not count towards this number. If this function returns
307    /// the value N, the meaningful states of the SVG are
308    /// 0, 1, ..., N - 1 and `GTK_SVG_STATE_EMPTY`.
309    ///
310    /// # Returns
311    ///
312    /// the number of states
313    #[doc(alias = "gtk_svg_get_n_states")]
314    #[doc(alias = "get_n_states")]
315    pub fn n_states(&self) -> u32 {
316        unsafe { ffi::gtk_svg_get_n_states(self.to_glib_none().0) }
317    }
318
319    /// Gets the current state of the paintable.
320    ///
321    /// # Returns
322    ///
323    /// the state
324    #[doc(alias = "gtk_svg_get_state")]
325    #[doc(alias = "get_state")]
326    pub fn state(&self) -> u32 {
327        unsafe { ffi::gtk_svg_get_state(self.to_glib_none().0) }
328    }
329
330    /// Gets the value of the weight property.
331    ///
332    /// # Returns
333    ///
334    /// the weight
335    #[doc(alias = "gtk_svg_get_weight")]
336    #[doc(alias = "get_weight")]
337    pub fn weight(&self) -> f64 {
338        unsafe { ffi::gtk_svg_get_weight(self.to_glib_none().0) }
339    }
340
341    /// Loads SVG content into an existing SVG paintable.
342    ///
343    /// To track errors while loading SVG content,
344    /// connect to the [`error`][struct@crate::Svg#error] signal.
345    ///
346    /// This clears any previously loaded content.
347    /// ## `bytes`
348    /// the data to load
349    #[doc(alias = "gtk_svg_load_from_bytes")]
350    pub fn load_from_bytes(&self, bytes: &glib::Bytes) {
351        unsafe {
352            ffi::gtk_svg_load_from_bytes(self.to_glib_none().0, bytes.to_glib_none().0);
353        }
354    }
355
356    /// Loads SVG content into an existing SVG paintable.
357    ///
358    /// To track errors while loading SVG content,
359    /// connect to the [`error`][struct@crate::Svg#error] signal.
360    ///
361    /// This clears any previously loaded content.
362    /// ## `path`
363    /// the resource path
364    #[doc(alias = "gtk_svg_load_from_resource")]
365    pub fn load_from_resource(&self, path: &str) {
366        unsafe {
367            ffi::gtk_svg_load_from_resource(self.to_glib_none().0, path.to_glib_none().0);
368        }
369    }
370
371    /// Stop any playing animations and state transitions.
372    ///
373    /// Animations can be paused and started repeatedly.
374    #[doc(alias = "gtk_svg_pause")]
375    pub fn pause(&self) {
376        unsafe {
377            ffi::gtk_svg_pause(self.to_glib_none().0);
378        }
379    }
380
381    /// Start playing animations and state transitions.
382    ///
383    /// Animations can be paused and started repeatedly.
384    #[doc(alias = "gtk_svg_play")]
385    pub fn play(&self) {
386        unsafe {
387            ffi::gtk_svg_play(self.to_glib_none().0);
388        }
389    }
390
391    /// Serializes the content of the renderer as SVG.
392    ///
393    /// The SVG will be similar to the orignally loaded one,
394    /// but is not guaranteed to be 100% identical.
395    ///
396    /// This function serializes the DOM, i.e. the results
397    /// of parsing the SVG. It does not reflect the effect
398    /// of applying animations.
399    ///
400    /// # Returns
401    ///
402    /// the serialized contents
403    #[doc(alias = "gtk_svg_serialize")]
404    pub fn serialize(&self) -> glib::Bytes {
405        unsafe { from_glib_full(ffi::gtk_svg_serialize(self.to_glib_none().0)) }
406    }
407
408    /// Enables or disables features of the SVG paintable.
409    ///
410    /// By default, all features are enabled.
411    ///
412    /// Note that this call only has an effect before the
413    /// SVG is loaded.
414    /// ## `features`
415    /// features to enable
416    #[doc(alias = "gtk_svg_set_features")]
417    #[doc(alias = "features")]
418    pub fn set_features(&self, features: SvgFeatures) {
419        unsafe {
420            ffi::gtk_svg_set_features(self.to_glib_none().0, features.into_glib());
421        }
422    }
423
424    /// Sets a frame clock.
425    ///
426    /// Without a frame clock, GtkSvg will not advance animations.
427    /// ## `clock`
428    /// the frame clock
429    #[doc(alias = "gtk_svg_set_frame_clock")]
430    pub fn set_frame_clock(&self, clock: &gdk::FrameClock) {
431        unsafe {
432            ffi::gtk_svg_set_frame_clock(self.to_glib_none().0, clock.to_glib_none().0);
433        }
434    }
435
436    /// Sets the state of the paintable.
437    ///
438    /// Use [`n_states()`][Self::n_states()] to find out
439    /// what states @self has.
440    ///
441    /// If the paintable is currently playing, the state change
442    /// will apply transitions that are defined in the SVG. If
443    /// the paintable is not playing, the state change will take
444    /// effect instantaneously.
445    /// ## `state`
446    /// the state to set, as a value between 0 and 63,
447    ///   or `GTK_SVG_STATE_EMPTY`
448    #[doc(alias = "gtk_svg_set_state")]
449    #[doc(alias = "state")]
450    pub fn set_state(&self, state: u32) {
451        unsafe {
452            ffi::gtk_svg_set_state(self.to_glib_none().0, state);
453        }
454    }
455
456    /// Sets the weight that is used when rendering.
457    ///
458    /// The weight affects the effective linewidth when stroking
459    /// paths.
460    ///
461    /// The default value of -1 means to use the font weight
462    /// from CSS.
463    /// ## `weight`
464    /// the font weight, as a value between -1 and 1000
465    #[doc(alias = "gtk_svg_set_weight")]
466    #[doc(alias = "weight")]
467    pub fn set_weight(&self, weight: f64) {
468        unsafe {
469            ffi::gtk_svg_set_weight(self.to_glib_none().0, weight);
470        }
471    }
472
473    /// Serializes the paintable, and saves the result to a file.
474    /// ## `filename`
475    /// the file to save to
476    ///
477    /// # Returns
478    ///
479    /// true, unless an error occurred
480    #[doc(alias = "gtk_svg_write_to_file")]
481    pub fn write_to_file(&self, filename: &str) -> Result<(), glib::Error> {
482        unsafe {
483            let mut error = std::ptr::null_mut();
484            let is_ok = ffi::gtk_svg_write_to_file(
485                self.to_glib_none().0,
486                filename.to_glib_none().0,
487                &mut error,
488            );
489            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
490            if error.is_null() {
491                Ok(())
492            } else {
493                Err(from_glib_full(error))
494            }
495        }
496    }
497
498    /// Whether the paintable is currently animating its content.
499    ///
500    /// To set this property, use the [`play()`][Self::play()] and
501    /// [`pause()`][Self::pause()] functions.
502    #[cfg(feature = "v4_22")]
503    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
504    pub fn is_playing(&self) -> bool {
505        ObjectExt::property(self, "playing")
506    }
507
508    /// Whether the paintable is currently animating its content.
509    ///
510    /// To set this property, use the [`play()`][Self::play()] and
511    /// [`pause()`][Self::pause()] functions.
512    #[cfg(feature = "v4_22")]
513    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
514    pub fn set_playing(&self, playing: bool) {
515        ObjectExt::set_property(self, "playing", playing)
516    }
517
518    /// Resource to load SVG data from.
519    ///
520    /// This property is meant to create a paintable
521    /// from a resource in ui files.
522    #[cfg(feature = "v4_22")]
523    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
524    pub fn resource(&self) -> Option<glib::GString> {
525        ObjectExt::property(self, "resource")
526    }
527
528    /// Resource to load SVG data from.
529    ///
530    /// This property is meant to create a paintable
531    /// from a resource in ui files.
532    #[cfg(feature = "v4_22")]
533    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
534    pub fn set_resource(&self, resource: Option<&str>) {
535        ObjectExt::set_property(self, "resource", resource)
536    }
537
538    /// Signals that an error occurred.
539    ///
540    /// Errors can occur both during parsing and during rendering.
541    ///
542    /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
543    /// context information about the location of parsing errors can
544    /// be obtained with the various `gtk_svg_error` functions.
545    ///
546    /// Parsing errors are never fatal, so the parsing will resume after
547    /// the error. Errors may however cause parts of the given data or
548    /// even all of it to not be parsed at all. So it is a useful idea
549    /// to check that the parsing succeeds by connecting to this signal.
550    ///
551    /// ::: note
552    ///     This signal is emitted in the middle of parsing or rendering,
553    ///     and if you handle it, you must be careful. Logging the errors
554    ///     you receive is fine, but modifying the widget hierarchy or
555    ///     changing the paintable state definitively isn't.
556    ///
557    ///     If in doubt, defer to an idle.
558    /// ## `error`
559    /// the error
560    #[cfg(feature = "v4_22")]
561    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
562    #[doc(alias = "error")]
563    pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
564        unsafe extern "C" fn error_trampoline<F: Fn(&Svg, &glib::Error) + 'static>(
565            this: *mut ffi::GtkSvg,
566            error: *mut glib::ffi::GError,
567            f: glib::ffi::gpointer,
568        ) {
569            unsafe {
570                let f: &F = &*(f as *const F);
571                f(&from_glib_borrow(this), &from_glib_borrow(error))
572            }
573        }
574        unsafe {
575            let f: Box_<F> = Box_::new(f);
576            connect_raw(
577                self.as_ptr() as *mut _,
578                c"error".as_ptr(),
579                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
580                    error_trampoline::<F> as *const (),
581                )),
582                Box_::into_raw(f),
583            )
584        }
585    }
586
587    #[cfg(feature = "v4_22")]
588    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
589    #[doc(alias = "features")]
590    pub fn connect_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
591        unsafe extern "C" fn notify_features_trampoline<F: Fn(&Svg) + 'static>(
592            this: *mut ffi::GtkSvg,
593            _param_spec: glib::ffi::gpointer,
594            f: glib::ffi::gpointer,
595        ) {
596            unsafe {
597                let f: &F = &*(f as *const F);
598                f(&from_glib_borrow(this))
599            }
600        }
601        unsafe {
602            let f: Box_<F> = Box_::new(f);
603            connect_raw(
604                self.as_ptr() as *mut _,
605                c"notify::features".as_ptr(),
606                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
607                    notify_features_trampoline::<F> as *const (),
608                )),
609                Box_::into_raw(f),
610            )
611        }
612    }
613
614    #[cfg(feature = "v4_22")]
615    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
616    #[doc(alias = "playing")]
617    pub fn connect_playing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
618        unsafe extern "C" fn notify_playing_trampoline<F: Fn(&Svg) + 'static>(
619            this: *mut ffi::GtkSvg,
620            _param_spec: glib::ffi::gpointer,
621            f: glib::ffi::gpointer,
622        ) {
623            unsafe {
624                let f: &F = &*(f as *const F);
625                f(&from_glib_borrow(this))
626            }
627        }
628        unsafe {
629            let f: Box_<F> = Box_::new(f);
630            connect_raw(
631                self.as_ptr() as *mut _,
632                c"notify::playing".as_ptr(),
633                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
634                    notify_playing_trampoline::<F> as *const (),
635                )),
636                Box_::into_raw(f),
637            )
638        }
639    }
640
641    #[cfg(feature = "v4_22")]
642    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
643    #[doc(alias = "resource")]
644    pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
645        unsafe extern "C" fn notify_resource_trampoline<F: Fn(&Svg) + 'static>(
646            this: *mut ffi::GtkSvg,
647            _param_spec: glib::ffi::gpointer,
648            f: glib::ffi::gpointer,
649        ) {
650            unsafe {
651                let f: &F = &*(f as *const F);
652                f(&from_glib_borrow(this))
653            }
654        }
655        unsafe {
656            let f: Box_<F> = Box_::new(f);
657            connect_raw(
658                self.as_ptr() as *mut _,
659                c"notify::resource".as_ptr(),
660                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
661                    notify_resource_trampoline::<F> as *const (),
662                )),
663                Box_::into_raw(f),
664            )
665        }
666    }
667
668    #[cfg(feature = "v4_22")]
669    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
670    #[doc(alias = "state")]
671    pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
672        unsafe extern "C" fn notify_state_trampoline<F: Fn(&Svg) + 'static>(
673            this: *mut ffi::GtkSvg,
674            _param_spec: glib::ffi::gpointer,
675            f: glib::ffi::gpointer,
676        ) {
677            unsafe {
678                let f: &F = &*(f as *const F);
679                f(&from_glib_borrow(this))
680            }
681        }
682        unsafe {
683            let f: Box_<F> = Box_::new(f);
684            connect_raw(
685                self.as_ptr() as *mut _,
686                c"notify::state".as_ptr(),
687                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
688                    notify_state_trampoline::<F> as *const (),
689                )),
690                Box_::into_raw(f),
691            )
692        }
693    }
694
695    #[cfg(feature = "v4_22")]
696    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
697    #[doc(alias = "weight")]
698    pub fn connect_weight_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
699        unsafe extern "C" fn notify_weight_trampoline<F: Fn(&Svg) + 'static>(
700            this: *mut ffi::GtkSvg,
701            _param_spec: glib::ffi::gpointer,
702            f: glib::ffi::gpointer,
703        ) {
704            unsafe {
705                let f: &F = &*(f as *const F);
706                f(&from_glib_borrow(this))
707            }
708        }
709        unsafe {
710            let f: Box_<F> = Box_::new(f);
711            connect_raw(
712                self.as_ptr() as *mut _,
713                c"notify::weight".as_ptr(),
714                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
715                    notify_weight_trampoline::<F> as *const (),
716                )),
717                Box_::into_raw(f),
718            )
719        }
720    }
721}
722
723#[cfg(feature = "v4_22")]
724#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
725impl Default for Svg {
726    fn default() -> Self {
727        Self::new()
728    }
729}