gtk4/auto/svg_widget.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::{Accessible, Buildable, ConstraintTarget, Svg, Widget, 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 widget that renders SVG, with animations and event handling.
16 ///
17 /// [`SvgWidget`][crate::SvgWidget] uses [`Svg`][crate::Svg] internally, and should read
18 /// its documentation to learn about the supported SVG features and
19 /// extensions.
20 ///
21 /// On top of the [`Svg`][crate::Svg] rendering, [`SvgWidget`][crate::SvgWidget] adds event handling.
22 /// <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys can be used
23 /// to move the focus and <kbd>Enter</kbd> and clicks will activate links
24 /// by emitting the [`activate`][struct@crate::SvgWidget#activate] signal.
25 ///
26 /// The `tabindex` and `autofocus` attributes can be used to influence
27 /// what elements act as focus locations, and where focus goes initially.
28 ///
29 /// The styling of the SVG content is following input-related pseudo
30 /// classes such as `:focus`, `:active`, `:hover` or `:visited`.
31 ///
32 /// If [`has-tooltip`][struct@crate::Widget#has-tooltip] is set, then the content
33 /// of `<title>` elements will be shown as tooltips.
34 ///
35 /// SVG animations and different `<view>`s can be triggered by input
36 /// events as well. The following events are supported: focus, blur,
37 /// mouseenter, mouseleave, click.
38 /// See the [SVG animation](https://svgwg.org/specs/animations/)
39 /// specification for details.
40 ///
41 /// ## Properties
42 ///
43 ///
44 /// #### `resource`
45 /// Resource to load SVG data from.
46 ///
47 /// This property is meant for use in ui files.
48 ///
49 /// Readable | Writable
50 ///
51 ///
52 /// #### `state`
53 /// The current state of the renderer.
54 ///
55 /// This can be a number between 0 and 63.
56 ///
57 /// Readable | Writable
58 ///
59 ///
60 /// #### `stylesheet`
61 /// A CSS stylesheet to apply to the SVG.
62 ///
63 /// Readable | Writable
64 ///
65 ///
66 /// #### `svg`
67 /// The GtkSvg paintable used for rendering.
68 ///
69 /// This property is mainly useful for making details of the
70 /// SVG rendering machinery available in the GTK inspector.
71 ///
72 /// You should not modify the returned object.
73 ///
74 /// Readable
75 /// <details><summary><h4>Widget</h4></summary>
76 ///
77 ///
78 /// #### `can-focus`
79 /// Whether the widget or any of its descendents can accept
80 /// the input focus.
81 ///
82 /// This property is meant to be set by widget implementations,
83 /// typically in their instance init function.
84 ///
85 /// Readable | Writable
86 ///
87 ///
88 /// #### `can-target`
89 /// Whether the widget can receive pointer events.
90 ///
91 /// Readable | Writable
92 ///
93 ///
94 /// #### `css-classes`
95 /// A list of css classes applied to this widget.
96 ///
97 /// Readable | Writable
98 ///
99 ///
100 /// #### `css-name`
101 /// The name of this widget in the CSS tree.
102 ///
103 /// This property is meant to be set by widget implementations,
104 /// typically in their instance init function.
105 ///
106 /// Readable | Writable | Construct Only
107 ///
108 ///
109 /// #### `cursor`
110 /// The cursor used by @widget.
111 ///
112 /// Readable | Writable
113 ///
114 ///
115 /// #### `focus-on-click`
116 /// Whether the widget should grab focus when it is clicked with the mouse.
117 ///
118 /// This property is only relevant for widgets that can take focus.
119 ///
120 /// Readable | Writable
121 ///
122 ///
123 /// #### `focusable`
124 /// Whether this widget itself will accept the input focus.
125 ///
126 /// Readable | Writable
127 ///
128 ///
129 /// #### `halign`
130 /// How to distribute horizontal space if widget gets extra space.
131 ///
132 /// Readable | Writable
133 ///
134 ///
135 /// #### `has-default`
136 /// Whether the widget is the default widget.
137 ///
138 /// Readable
139 ///
140 ///
141 /// #### `has-focus`
142 /// Whether the widget has the input focus.
143 ///
144 /// Readable
145 ///
146 ///
147 /// #### `has-tooltip`
148 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
149 /// signal on @widget.
150 ///
151 /// A true value indicates that @widget can have a tooltip, in this case
152 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
153 /// determine whether it will provide a tooltip or not.
154 ///
155 /// Readable | Writable
156 ///
157 ///
158 /// #### `height-request`
159 /// Overrides for height request of the widget.
160 ///
161 /// If this is -1, the natural request will be used.
162 ///
163 /// Readable | Writable
164 ///
165 ///
166 /// #### `hexpand`
167 /// Whether to expand horizontally.
168 ///
169 /// Readable | Writable
170 ///
171 ///
172 /// #### `hexpand-set`
173 /// Whether to use the `hexpand` property.
174 ///
175 /// Readable | Writable
176 ///
177 ///
178 /// #### `layout-manager`
179 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
180 /// the preferred size of the widget, and allocate its children.
181 ///
182 /// This property is meant to be set by widget implementations,
183 /// typically in their instance init function.
184 ///
185 /// Readable | Writable
186 ///
187 ///
188 /// #### `limit-events`
189 /// Makes this widget act like a modal dialog, with respect to
190 /// event delivery.
191 ///
192 /// Global event controllers will not handle events with targets
193 /// inside the widget, unless they are set up to ignore propagation
194 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
195 ///
196 /// Readable | Writable
197 ///
198 ///
199 /// #### `margin-bottom`
200 /// Margin on bottom side of widget.
201 ///
202 /// This property adds margin outside of the widget's normal size
203 /// request, the margin will be added in addition to the size from
204 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
205 ///
206 /// Readable | Writable
207 ///
208 ///
209 /// #### `margin-end`
210 /// Margin on end of widget, horizontally.
211 ///
212 /// This property supports left-to-right and right-to-left text
213 /// directions.
214 ///
215 /// This property adds margin outside of the widget's normal size
216 /// request, the margin will be added in addition to the size from
217 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
218 ///
219 /// Readable | Writable
220 ///
221 ///
222 /// #### `margin-start`
223 /// Margin on start of widget, horizontally.
224 ///
225 /// This property supports left-to-right and right-to-left text
226 /// directions.
227 ///
228 /// This property adds margin outside of the widget's normal size
229 /// request, the margin will be added in addition to the size from
230 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
231 ///
232 /// Readable | Writable
233 ///
234 ///
235 /// #### `margin-top`
236 /// Margin on top side of widget.
237 ///
238 /// This property adds margin outside of the widget's normal size
239 /// request, the margin will be added in addition to the size from
240 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
241 ///
242 /// Readable | Writable
243 ///
244 ///
245 /// #### `name`
246 /// The name of the widget.
247 ///
248 /// Readable | Writable
249 ///
250 ///
251 /// #### `opacity`
252 /// The requested opacity of the widget.
253 ///
254 /// Readable | Writable
255 ///
256 ///
257 /// #### `overflow`
258 /// How content outside the widget's content area is treated.
259 ///
260 /// This property is meant to be set by widget implementations,
261 /// typically in their instance init function.
262 ///
263 /// Readable | Writable
264 ///
265 ///
266 /// #### `parent`
267 /// The parent widget of this widget.
268 ///
269 /// Readable
270 ///
271 ///
272 /// #### `receives-default`
273 /// Whether the widget will receive the default action when it is focused.
274 ///
275 /// Readable | Writable
276 ///
277 ///
278 /// #### `root`
279 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
280 ///
281 /// This will be `NULL` if the widget is not contained in a root widget.
282 ///
283 /// Readable
284 ///
285 ///
286 /// #### `scale-factor`
287 /// The scale factor of the widget.
288 ///
289 /// Readable
290 ///
291 ///
292 /// #### `sensitive`
293 /// Whether the widget responds to input.
294 ///
295 /// Readable | Writable
296 ///
297 ///
298 /// #### `tooltip-markup`
299 /// Sets the text of tooltip to be the given string, which is marked up
300 /// with Pango markup.
301 ///
302 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
303 ///
304 /// This is a convenience property which will take care of getting the
305 /// tooltip shown if the given string is not `NULL`:
306 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
307 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
308 /// the default signal handler.
309 ///
310 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
311 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
312 ///
313 /// Readable | Writable
314 ///
315 ///
316 /// #### `tooltip-text`
317 /// Sets the text of tooltip to be the given string.
318 ///
319 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
320 ///
321 /// This is a convenience property which will take care of getting the
322 /// tooltip shown if the given string is not `NULL`:
323 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
324 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
325 /// the default signal handler.
326 ///
327 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
328 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
329 ///
330 /// Readable | Writable
331 ///
332 ///
333 /// #### `valign`
334 /// How to distribute vertical space if widget gets extra space.
335 ///
336 /// Readable | Writable
337 ///
338 ///
339 /// #### `vexpand`
340 /// Whether to expand vertically.
341 ///
342 /// Readable | Writable
343 ///
344 ///
345 /// #### `vexpand-set`
346 /// Whether to use the `vexpand` property.
347 ///
348 /// Readable | Writable
349 ///
350 ///
351 /// #### `visible`
352 /// Whether the widget is visible.
353 ///
354 /// Readable | Writable
355 ///
356 ///
357 /// #### `width-request`
358 /// Overrides for width request of the widget.
359 ///
360 /// If this is -1, the natural request will be used.
361 ///
362 /// Readable | Writable
363 /// </details>
364 /// <details><summary><h4>Accessible</h4></summary>
365 ///
366 ///
367 /// #### `accessible-role`
368 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
369 ///
370 /// The accessible role cannot be changed once set.
371 ///
372 /// Readable | Writable
373 /// </details>
374 ///
375 /// ## Signals
376 ///
377 ///
378 /// #### `activate`
379 /// Emitted when a link or other element is activated.
380 ///
381 /// Activating elements can be achieved by clicking
382 /// or by hitting <kbd>Enter</kbd> while the element
383 /// has focus.
384 ///
385 ///
386 ///
387 ///
388 /// #### `error`
389 /// Signals that an error occurred.
390 ///
391 /// Errors can occur both during parsing and during rendering.
392 ///
393 /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
394 /// context information about the location of parsing errors can
395 /// be obtained with the various `gtk_svg_error` functions.
396 ///
397 /// Parsing errors are never fatal, so the parsing will resume after
398 /// the error. Errors may however cause parts of the given data or
399 /// even all of it to not be parsed at all. So it is a useful idea
400 /// to check that the parsing succeeds by connecting to this signal.
401 ///
402 /// ::: note
403 /// This signal is emitted in the middle of parsing or rendering,
404 /// and if you handle it, you must be careful. Logging the errors
405 /// you receive is fine, but modifying the widget hierarchy or
406 /// changing the paintable state definitively isn't.
407 ///
408 /// If in doubt, defer to an idle.
409 ///
410 ///
411 /// <details><summary><h4>Widget</h4></summary>
412 ///
413 ///
414 /// #### `destroy`
415 /// Signals that all holders of a reference to the widget should release
416 /// the reference that they hold.
417 ///
418 /// May result in finalization of the widget if all references are released.
419 ///
420 /// This signal is not suitable for saving widget state.
421 ///
422 ///
423 ///
424 ///
425 /// #### `direction-changed`
426 /// Emitted when the text direction of a widget changes.
427 ///
428 ///
429 ///
430 ///
431 /// #### `hide`
432 /// Emitted when @widget is hidden.
433 ///
434 ///
435 ///
436 ///
437 /// #### `keynav-failed`
438 /// Emitted if keyboard navigation fails.
439 ///
440 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
441 ///
442 ///
443 ///
444 ///
445 /// #### `map`
446 /// Emitted when @widget is going to be mapped.
447 ///
448 /// A widget is mapped when the widget is visible (which is controlled with
449 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
450 /// are also visible.
451 ///
452 /// The `::map` signal can be used to determine whether a widget will be drawn,
453 /// for instance it can resume an animation that was stopped during the
454 /// emission of [`unmap`][struct@crate::Widget#unmap].
455 ///
456 ///
457 ///
458 ///
459 /// #### `mnemonic-activate`
460 /// Emitted when a widget is activated via a mnemonic.
461 ///
462 /// The default handler for this signal activates @widget if @group_cycling
463 /// is false, or just makes @widget grab focus if @group_cycling is true.
464 ///
465 ///
466 ///
467 ///
468 /// #### `move-focus`
469 /// Emitted when the focus is moved.
470 ///
471 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
472 ///
473 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
474 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
475 ///
476 /// Action
477 ///
478 ///
479 /// #### `query-tooltip`
480 /// Emitted when the widget’s tooltip is about to be shown.
481 ///
482 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
483 /// is true and the hover timeout has expired with the cursor hovering
484 /// above @widget; or emitted when @widget got focus in keyboard mode.
485 ///
486 /// Using the given coordinates, the signal handler should determine
487 /// whether a tooltip should be shown for @widget. If this is the case
488 /// true should be returned, false otherwise. Note that if @keyboard_mode
489 /// is true, the values of @x and @y are undefined and should not be used.
490 ///
491 /// The signal handler is free to manipulate @tooltip with the therefore
492 /// destined function calls.
493 ///
494 ///
495 ///
496 ///
497 /// #### `realize`
498 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
499 ///
500 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
501 /// or the widget has been mapped (that is, it is going to be drawn).
502 ///
503 ///
504 ///
505 ///
506 /// #### `show`
507 /// Emitted when @widget is shown.
508 ///
509 ///
510 ///
511 ///
512 /// #### `state-flags-changed`
513 /// Emitted when the widget state changes.
514 ///
515 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
516 ///
517 ///
518 ///
519 ///
520 /// #### `unmap`
521 /// Emitted when @widget is going to be unmapped.
522 ///
523 /// A widget is unmapped when either it or any of its parents up to the
524 /// toplevel widget have been set as hidden.
525 ///
526 /// As `::unmap` indicates that a widget will not be shown any longer,
527 /// it can be used to, for example, stop an animation on the widget.
528 ///
529 ///
530 ///
531 ///
532 /// #### `unrealize`
533 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
534 ///
535 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
536 /// or the widget has been unmapped (that is, it is going to be hidden).
537 ///
538 ///
539 /// </details>
540 ///
541 /// # Implements
542 ///
543 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
544 #[doc(alias = "GtkSvgWidget")]
545 pub struct SvgWidget(Object<ffi::GtkSvgWidget, ffi::GtkSvgWidgetClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
546
547 match fn {
548 type_ => || ffi::gtk_svg_widget_get_type(),
549 }
550}
551
552impl SvgWidget {
553 /// Creates a new, empty [`SvgWidget`][crate::SvgWidget].
554 ///
555 /// # Returns
556 ///
557 /// the new widget
558 #[doc(alias = "gtk_svg_widget_new")]
559 pub fn new() -> SvgWidget {
560 assert_initialized_main_thread!();
561 unsafe { from_glib_none(ffi::gtk_svg_widget_new()) }
562 }
563
564 /// Gets the current state of the widget.
565 ///
566 /// # Returns
567 ///
568 /// the state
569 #[doc(alias = "gtk_svg_widget_get_state")]
570 #[doc(alias = "get_state")]
571 pub fn state(&self) -> u32 {
572 unsafe { ffi::gtk_svg_widget_get_state(self.to_glib_none().0) }
573 }
574
575 /// Gets the CSS user stylesheet.
576 ///
577 /// # Returns
578 ///
579 /// a `GBytes` with the CSS data
580 #[doc(alias = "gtk_svg_widget_get_stylesheet")]
581 #[doc(alias = "get_stylesheet")]
582 pub fn stylesheet(&self) -> Option<glib::Bytes> {
583 unsafe { from_glib_full(ffi::gtk_svg_widget_get_stylesheet(self.to_glib_none().0)) }
584 }
585
586 /// Loads SVG content into an existing SVG widget.
587 ///
588 /// To track errors while loading SVG content, connect
589 /// to the [`error`][struct@crate::SvgWidget#error] signal.
590 ///
591 /// This clears any previously loaded content.
592 /// ## `bytes`
593 /// the data to data
594 #[doc(alias = "gtk_svg_widget_load_from_bytes")]
595 pub fn load_from_bytes(&self, bytes: &glib::Bytes) {
596 unsafe {
597 ffi::gtk_svg_widget_load_from_bytes(self.to_glib_none().0, bytes.to_glib_none().0);
598 }
599 }
600
601 /// Sets the state of the widget.
602 ///
603 /// The state change will apply transitions that are defined
604 /// in the SVG. See [`Svg`][crate::Svg] for details about states
605 /// and transitions.
606 /// ## `state`
607 /// the state to set, as a value between 0 and 63
608 #[doc(alias = "gtk_svg_widget_set_state")]
609 #[doc(alias = "state")]
610 pub fn set_state(&self, state: u32) {
611 unsafe {
612 ffi::gtk_svg_widget_set_state(self.to_glib_none().0, state);
613 }
614 }
615
616 /// Sets a CSS user stylesheet to use.
617 ///
618 /// Note that styles are applied at load time, so this
619 /// function must be called before loading SVG.
620 /// ## `bytes`
621 /// CSS data
622 #[doc(alias = "gtk_svg_widget_set_stylesheet")]
623 #[doc(alias = "stylesheet")]
624 pub fn set_stylesheet(&self, bytes: Option<&glib::Bytes>) {
625 unsafe {
626 ffi::gtk_svg_widget_set_stylesheet(self.to_glib_none().0, bytes.to_glib_none().0);
627 }
628 }
629
630 /// Resource to load SVG data from.
631 ///
632 /// This property is meant for use in ui files.
633 #[cfg(feature = "v4_24")]
634 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
635 pub fn resource(&self) -> Option<glib::GString> {
636 ObjectExt::property(self, "resource")
637 }
638
639 /// Resource to load SVG data from.
640 ///
641 /// This property is meant for use in ui files.
642 #[cfg(feature = "v4_24")]
643 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
644 pub fn set_resource(&self, resource: Option<&str>) {
645 ObjectExt::set_property(self, "resource", resource)
646 }
647
648 /// The GtkSvg paintable used for rendering.
649 ///
650 /// This property is mainly useful for making details of the
651 /// SVG rendering machinery available in the GTK inspector.
652 ///
653 /// You should not modify the returned object.
654 #[cfg(feature = "v4_24")]
655 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
656 pub fn svg(&self) -> Option<Svg> {
657 ObjectExt::property(self, "svg")
658 }
659
660 /// Emitted when a link or other element is activated.
661 ///
662 /// Activating elements can be achieved by clicking
663 /// or by hitting <kbd>Enter</kbd> while the element
664 /// has focus.
665 /// ## `id`
666 /// the ID of the element
667 /// ## `href`
668 /// the href, if the element is a link
669 #[cfg(feature = "v4_24")]
670 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
671 #[doc(alias = "activate")]
672 pub fn connect_activate<F: Fn(&Self, Option<&str>, Option<&str>) + 'static>(
673 &self,
674 f: F,
675 ) -> SignalHandlerId {
676 unsafe extern "C" fn activate_trampoline<
677 F: Fn(&SvgWidget, Option<&str>, Option<&str>) + 'static,
678 >(
679 this: *mut ffi::GtkSvgWidget,
680 id: *mut std::ffi::c_char,
681 href: *mut std::ffi::c_char,
682 f: glib::ffi::gpointer,
683 ) {
684 unsafe {
685 let f: &F = &*(f as *const F);
686 f(
687 &from_glib_borrow(this),
688 Option::<glib::GString>::from_glib_borrow(id)
689 .as_ref()
690 .as_ref()
691 .map(|s| s.as_str()),
692 Option::<glib::GString>::from_glib_borrow(href)
693 .as_ref()
694 .as_ref()
695 .map(|s| s.as_str()),
696 )
697 }
698 }
699 unsafe {
700 let f: Box_<F> = Box_::new(f);
701 connect_raw(
702 self.as_ptr() as *mut _,
703 c"activate".as_ptr(),
704 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
705 activate_trampoline::<F> as *const (),
706 )),
707 Box_::into_raw(f),
708 )
709 }
710 }
711
712 /// Signals that an error occurred.
713 ///
714 /// Errors can occur both during parsing and during rendering.
715 ///
716 /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
717 /// context information about the location of parsing errors can
718 /// be obtained with the various `gtk_svg_error` functions.
719 ///
720 /// Parsing errors are never fatal, so the parsing will resume after
721 /// the error. Errors may however cause parts of the given data or
722 /// even all of it to not be parsed at all. So it is a useful idea
723 /// to check that the parsing succeeds by connecting to this signal.
724 ///
725 /// ::: note
726 /// This signal is emitted in the middle of parsing or rendering,
727 /// and if you handle it, you must be careful. Logging the errors
728 /// you receive is fine, but modifying the widget hierarchy or
729 /// changing the paintable state definitively isn't.
730 ///
731 /// If in doubt, defer to an idle.
732 /// ## `error`
733 /// the error
734 #[cfg(feature = "v4_24")]
735 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
736 #[doc(alias = "error")]
737 pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
738 unsafe extern "C" fn error_trampoline<F: Fn(&SvgWidget, &glib::Error) + 'static>(
739 this: *mut ffi::GtkSvgWidget,
740 error: *mut glib::ffi::GError,
741 f: glib::ffi::gpointer,
742 ) {
743 unsafe {
744 let f: &F = &*(f as *const F);
745 f(&from_glib_borrow(this), &from_glib_borrow(error))
746 }
747 }
748 unsafe {
749 let f: Box_<F> = Box_::new(f);
750 connect_raw(
751 self.as_ptr() as *mut _,
752 c"error".as_ptr(),
753 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
754 error_trampoline::<F> as *const (),
755 )),
756 Box_::into_raw(f),
757 )
758 }
759 }
760
761 #[cfg(feature = "v4_24")]
762 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
763 #[doc(alias = "resource")]
764 pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
765 unsafe extern "C" fn notify_resource_trampoline<F: Fn(&SvgWidget) + 'static>(
766 this: *mut ffi::GtkSvgWidget,
767 _param_spec: glib::ffi::gpointer,
768 f: glib::ffi::gpointer,
769 ) {
770 unsafe {
771 let f: &F = &*(f as *const F);
772 f(&from_glib_borrow(this))
773 }
774 }
775 unsafe {
776 let f: Box_<F> = Box_::new(f);
777 connect_raw(
778 self.as_ptr() as *mut _,
779 c"notify::resource".as_ptr(),
780 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
781 notify_resource_trampoline::<F> as *const (),
782 )),
783 Box_::into_raw(f),
784 )
785 }
786 }
787
788 #[cfg(feature = "v4_24")]
789 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
790 #[doc(alias = "state")]
791 pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
792 unsafe extern "C" fn notify_state_trampoline<F: Fn(&SvgWidget) + 'static>(
793 this: *mut ffi::GtkSvgWidget,
794 _param_spec: glib::ffi::gpointer,
795 f: glib::ffi::gpointer,
796 ) {
797 unsafe {
798 let f: &F = &*(f as *const F);
799 f(&from_glib_borrow(this))
800 }
801 }
802 unsafe {
803 let f: Box_<F> = Box_::new(f);
804 connect_raw(
805 self.as_ptr() as *mut _,
806 c"notify::state".as_ptr(),
807 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
808 notify_state_trampoline::<F> as *const (),
809 )),
810 Box_::into_raw(f),
811 )
812 }
813 }
814
815 #[cfg(feature = "v4_24")]
816 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
817 #[doc(alias = "stylesheet")]
818 pub fn connect_stylesheet_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
819 unsafe extern "C" fn notify_stylesheet_trampoline<F: Fn(&SvgWidget) + 'static>(
820 this: *mut ffi::GtkSvgWidget,
821 _param_spec: glib::ffi::gpointer,
822 f: glib::ffi::gpointer,
823 ) {
824 unsafe {
825 let f: &F = &*(f as *const F);
826 f(&from_glib_borrow(this))
827 }
828 }
829 unsafe {
830 let f: Box_<F> = Box_::new(f);
831 connect_raw(
832 self.as_ptr() as *mut _,
833 c"notify::stylesheet".as_ptr(),
834 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
835 notify_stylesheet_trampoline::<F> as *const (),
836 )),
837 Box_::into_raw(f),
838 )
839 }
840 }
841
842 #[cfg(feature = "v4_24")]
843 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
844 #[doc(alias = "svg")]
845 pub fn connect_svg_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
846 unsafe extern "C" fn notify_svg_trampoline<F: Fn(&SvgWidget) + 'static>(
847 this: *mut ffi::GtkSvgWidget,
848 _param_spec: glib::ffi::gpointer,
849 f: glib::ffi::gpointer,
850 ) {
851 unsafe {
852 let f: &F = &*(f as *const F);
853 f(&from_glib_borrow(this))
854 }
855 }
856 unsafe {
857 let f: Box_<F> = Box_::new(f);
858 connect_raw(
859 self.as_ptr() as *mut _,
860 c"notify::svg".as_ptr(),
861 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
862 notify_svg_trampoline::<F> as *const (),
863 )),
864 Box_::into_raw(f),
865 )
866 }
867 }
868}
869
870#[cfg(feature = "v4_24")]
871#[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
872impl Default for SvgWidget {
873 fn default() -> Self {
874 Self::new()
875 }
876}