1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Buildable;
use crate::IconSize;
use crate::ImageType;
use crate::Misc;
use crate::Widget;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib::wrapper! {
    /// The [`Image`][crate::Image] widget displays an image. Various kinds of object
    /// can be displayed as an image; most typically, you would load a
    /// [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] ("pixel buffer") from a file, and then display that.
    /// There’s a convenience function to do this, [`from_file()`][Self::from_file()],
    /// used as follows:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///   GtkWidget *image;
    ///   image = gtk_image_new_from_file ("myfile.png");
    /// ```
    /// If the file isn’t loaded successfully, the image will contain a
    /// “broken image” icon similar to that used in many web browsers.
    /// If you want to handle errors in loading the file yourself,
    /// for example by displaying an error message, then load the image with
    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()], then create the [`Image`][crate::Image] with
    /// [`from_pixbuf()`][Self::from_pixbuf()].
    ///
    /// The image file may contain an animation, if so the [`Image`][crate::Image] will
    /// display an animation ([`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation]) instead of a static image.
    ///
    /// [`Image`][crate::Image] is a subclass of [`Misc`][crate::Misc], which implies that you can
    /// align it (center, left, right) and add padding to it, using
    /// [`Misc`][crate::Misc] methods.
    ///
    /// [`Image`][crate::Image] is a “no window” widget (has no [`gdk::Window`][crate::gdk::Window] of its own),
    /// so by default does not receive events. If you want to receive events
    /// on the image, such as button clicks, place the image inside a
    /// [`EventBox`][crate::EventBox], then connect to the event signals on the event box.
    ///
    /// ## Handling button press events on a [`Image`][crate::Image].
    ///
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///   static gboolean
    ///   button_press_callback (GtkWidget      *event_box,
    ///                          GdkEventButton *event,
    ///                          gpointer        data)
    ///   {
    ///     g_print ("Event box clicked at coordinates %f,%f\n",
    ///              event->x, event->y);
    ///
    ///     // Returning TRUE means we handled the event, so the signal
    ///     // emission should be stopped (don’t call any further callbacks
    ///     // that may be connected). Return FALSE to continue invoking callbacks.
    ///     return TRUE;
    ///   }
    ///
    ///   static GtkWidget*
    ///   create_image (void)
    ///   {
    ///     GtkWidget *image;
    ///     GtkWidget *event_box;
    ///
    ///     image = gtk_image_new_from_file ("myfile.png");
    ///
    ///     event_box = gtk_event_box_new ();
    ///
    ///     gtk_container_add (GTK_CONTAINER (event_box), image);
    ///
    ///     g_signal_connect (G_OBJECT (event_box),
    ///                       "button_press_event",
    ///                       G_CALLBACK (button_press_callback),
    ///                       image);
    ///
    ///     return image;
    ///   }
    /// ```
    ///
    /// When handling events on the event box, keep in mind that coordinates
    /// in the image may be different from event box coordinates due to
    /// the alignment and padding settings on the image (see [`Misc`][crate::Misc]).
    /// The simplest way to solve this is to set the alignment to 0.0
    /// (left/top), and set the padding to zero. Then the origin of
    /// the image will be the same as the origin of the event box.
    ///
    /// Sometimes an application will want to avoid depending on external data
    /// files, such as image files. GTK+ comes with a program to avoid this,
    /// called “gdk-pixbuf-csource”. This library
    /// allows you to convert an image into a C variable declaration, which
    /// can then be loaded into a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] using
    /// `gdk_pixbuf_new_from_inline()`.
    ///
    /// # CSS nodes
    ///
    /// GtkImage has a single CSS node with the name image. The style classes
    /// may appear on image CSS nodes: .icon-dropshadow, .lowres-icon.
    ///
    /// # Implements
    ///
    /// [`ImageExt`][trait@crate::prelude::ImageExt], [`MiscExt`][trait@crate::prelude::MiscExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ImageExtManual`][trait@crate::prelude::ImageExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
    #[doc(alias = "GtkImage")]
    pub struct Image(Object<ffi::GtkImage, ffi::GtkImageClass>) @extends Misc, Widget, @implements Buildable;

    match fn {
        type_ => || ffi::gtk_image_get_type(),
    }
}

impl Image {
    pub const NONE: Option<&'static Image> = None;

    /// Creates a new empty [`Image`][crate::Image] widget.
    ///
    /// # Returns
    ///
    /// a newly created [`Image`][crate::Image] widget.
    #[doc(alias = "gtk_image_new")]
    pub fn new() -> Image {
        assert_initialized_main_thread!();
        unsafe { Widget::from_glib_none(ffi::gtk_image_new()).unsafe_cast() }
    }

    /// Creates a [`Image`][crate::Image] displaying the given animation.
    /// The [`Image`][crate::Image] does not assume a reference to the
    /// animation; you still need to unref it if you own references.
    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
    ///
    /// Note that the animation frames are shown using a timeout with
    /// `G_PRIORITY_DEFAULT`. When using animations to indicate busyness,
    /// keep in mind that the animation will only be shown if the main loop
    /// is not busy with something that has a higher priority.
    /// ## `animation`
    /// an animation
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image] widget
    #[doc(alias = "gtk_image_new_from_animation")]
    #[doc(alias = "new_from_animation")]
    pub fn from_animation(animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_animation(
                animation.as_ref().to_glib_none().0,
            ))
            .unsafe_cast()
        }
    }

    /// Creates a new [`Image`][crate::Image] displaying the file `filename`. If the file
    /// isn’t found or can’t be loaded, the resulting [`Image`][crate::Image] will
    /// display a “broken image” icon. This function never returns [`None`],
    /// it always returns a valid [`Image`][crate::Image] widget.
    ///
    /// If the file contains an animation, the image will contain an
    /// animation.
    ///
    /// If you need to detect failures to load the file, use
    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()] to load the file yourself, then create
    /// the [`Image`][crate::Image] from the pixbuf. (Or for animations, use
    /// [`gdk_pixbuf::PixbufAnimation::from_file()`][crate::gdk_pixbuf::PixbufAnimation::from_file()]).
    ///
    /// The storage type ([`ImageExt::storage_type()`][crate::prelude::ImageExt::storage_type()]) of the returned
    /// image is not defined, it will be whatever is appropriate for
    /// displaying the file.
    /// ## `filename`
    /// a filename
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image]
    #[doc(alias = "gtk_image_new_from_file")]
    #[doc(alias = "new_from_file")]
    pub fn from_file(filename: impl AsRef<std::path::Path>) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_file(
                filename.as_ref().to_glib_none().0,
            ))
            .unsafe_cast()
        }
    }

    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
    /// If the icon name isn’t known, a “broken image” icon will be
    /// displayed instead. If the current icon theme is changed, the icon
    /// will be updated appropriately.
    /// ## `icon`
    /// an icon
    /// ## `size`
    /// a stock icon size ([`IconSize`][crate::IconSize])
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image] displaying the themed icon
    #[doc(alias = "gtk_image_new_from_gicon")]
    #[doc(alias = "new_from_gicon")]
    pub fn from_gicon(icon: &impl IsA<gio::Icon>, size: IconSize) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_gicon(
                icon.as_ref().to_glib_none().0,
                size.into_glib(),
            ))
            .unsafe_cast()
        }
    }

    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
    /// If the icon name isn’t known, a “broken image” icon will be
    /// displayed instead. If the current icon theme is changed, the icon
    /// will be updated appropriately.
    /// ## `icon_name`
    /// an icon name or [`None`]
    /// ## `size`
    /// a stock icon size ([`IconSize`][crate::IconSize])
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image] displaying the themed icon
    #[doc(alias = "gtk_image_new_from_icon_name")]
    #[doc(alias = "new_from_icon_name")]
    pub fn from_icon_name(icon_name: Option<&str>, size: IconSize) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_icon_name(
                icon_name.to_glib_none().0,
                size.into_glib(),
            ))
            .unsafe_cast()
        }
    }

    /// Creates a new [`Image`][crate::Image] displaying `pixbuf`.
    /// The [`Image`][crate::Image] does not assume a reference to the
    /// pixbuf; you still need to unref it if you own references.
    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
    ///
    /// Note that this function just creates an [`Image`][crate::Image] from the pixbuf. The
    /// [`Image`][crate::Image] created will not react to state changes. Should you want that,
    /// you should use [`from_icon_name()`][Self::from_icon_name()].
    /// ## `pixbuf`
    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf], or [`None`]
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image]
    #[doc(alias = "gtk_image_new_from_pixbuf")]
    #[doc(alias = "new_from_pixbuf")]
    pub fn from_pixbuf(pixbuf: Option<&gdk_pixbuf::Pixbuf>) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_pixbuf(pixbuf.to_glib_none().0))
                .unsafe_cast()
        }
    }

    /// Creates a new [`Image`][crate::Image] displaying the resource file `resource_path`. If the file
    /// isn’t found or can’t be loaded, the resulting [`Image`][crate::Image] will
    /// display a “broken image” icon. This function never returns [`None`],
    /// it always returns a valid [`Image`][crate::Image] widget.
    ///
    /// If the file contains an animation, the image will contain an
    /// animation.
    ///
    /// If you need to detect failures to load the file, use
    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()] to load the file yourself, then create
    /// the [`Image`][crate::Image] from the pixbuf. (Or for animations, use
    /// [`gdk_pixbuf::PixbufAnimation::from_file()`][crate::gdk_pixbuf::PixbufAnimation::from_file()]).
    ///
    /// The storage type ([`ImageExt::storage_type()`][crate::prelude::ImageExt::storage_type()]) of the returned
    /// image is not defined, it will be whatever is appropriate for
    /// displaying the file.
    /// ## `resource_path`
    /// a resource path
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image]
    #[doc(alias = "gtk_image_new_from_resource")]
    #[doc(alias = "new_from_resource")]
    pub fn from_resource(resource_path: &str) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_resource(
                resource_path.to_glib_none().0,
            ))
            .unsafe_cast()
        }
    }

    /// Creates a new [`Image`][crate::Image] displaying `surface`.
    /// The [`Image`][crate::Image] does not assume a reference to the
    /// surface; you still need to unref it if you own references.
    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
    /// ## `surface`
    /// a [`cairo::Surface`][crate::cairo::Surface], or [`None`]
    ///
    /// # Returns
    ///
    /// a new [`Image`][crate::Image]
    #[doc(alias = "gtk_image_new_from_surface")]
    #[doc(alias = "new_from_surface")]
    pub fn from_surface(surface: Option<&cairo::Surface>) -> Image {
        assert_initialized_main_thread!();
        unsafe {
            Widget::from_glib_none(ffi::gtk_image_new_from_surface(mut_override(
                surface.to_glib_none().0,
            )))
            .unsafe_cast()
        }
    }
}

impl Default for Image {
    fn default() -> Self {
        Self::new()
    }
}

/// Trait containing all [`struct@Image`] methods.
///
/// # Implementors
///
/// [`Image`][struct@crate::Image]
pub trait ImageExt: 'static {
    /// Resets the image to be empty.
    #[doc(alias = "gtk_image_clear")]
    fn clear(&self);

    /// Gets the [`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation] being displayed by the [`Image`][crate::Image].
    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
    /// [`ImageType::Animation`][crate::ImageType::Animation] (see [`storage_type()`][Self::storage_type()]).
    /// The caller of this function does not own a reference to the
    /// returned animation.
    ///
    /// # Returns
    ///
    /// the displayed animation, or [`None`] if
    /// the image is empty
    #[doc(alias = "gtk_image_get_animation")]
    #[doc(alias = "get_animation")]
    fn animation(&self) -> Option<gdk_pixbuf::PixbufAnimation>;

    /// Gets the [`gio::Icon`][crate::gio::Icon] and size being displayed by the [`Image`][crate::Image].
    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
    /// [`ImageType::Gicon`][crate::ImageType::Gicon] (see [`storage_type()`][Self::storage_type()]).
    /// The caller of this function does not own a reference to the
    /// returned [`gio::Icon`][crate::gio::Icon].
    ///
    /// # Returns
    ///
    ///
    /// ## `gicon`
    /// place to store a
    ///  [`gio::Icon`][crate::gio::Icon], or [`None`]
    ///
    /// ## `size`
    /// place to store an icon size
    ///  ([`IconSize`][crate::IconSize]), or [`None`]
    #[doc(alias = "gtk_image_get_gicon")]
    #[doc(alias = "get_gicon")]
    fn gicon(&self) -> (gio::Icon, IconSize);

    /// Gets the [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] being displayed by the [`Image`][crate::Image].
    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
    /// [`ImageType::Pixbuf`][crate::ImageType::Pixbuf] (see [`storage_type()`][Self::storage_type()]).
    /// The caller of this function does not own a reference to the
    /// returned pixbuf.
    ///
    /// # Returns
    ///
    /// the displayed pixbuf, or [`None`] if
    /// the image is empty
    #[doc(alias = "gtk_image_get_pixbuf")]
    #[doc(alias = "get_pixbuf")]
    fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf>;

    /// Gets the pixel size used for named icons.
    ///
    /// # Returns
    ///
    /// the pixel size used for named icons.
    #[doc(alias = "gtk_image_get_pixel_size")]
    #[doc(alias = "get_pixel_size")]
    fn pixel_size(&self) -> i32;

    /// Gets the type of representation being used by the [`Image`][crate::Image]
    /// to store image data. If the [`Image`][crate::Image] has no image data,
    /// the return value will be [`ImageType::Empty`][crate::ImageType::Empty].
    ///
    /// # Returns
    ///
    /// image representation being used
    #[doc(alias = "gtk_image_get_storage_type")]
    #[doc(alias = "get_storage_type")]
    fn storage_type(&self) -> ImageType;

    /// Causes the [`Image`][crate::Image] to display the given animation (or display
    /// nothing, if you set the animation to [`None`]).
    /// ## `animation`
    /// the [`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation]
    #[doc(alias = "gtk_image_set_from_animation")]
    fn set_from_animation(&self, animation: &impl IsA<gdk_pixbuf::PixbufAnimation>);

    /// See [`Image::from_file()`][crate::Image::from_file()] for details.
    /// ## `filename`
    /// a filename or [`None`]
    #[doc(alias = "gtk_image_set_from_file")]
    fn set_from_file(&self, filename: Option<impl AsRef<std::path::Path>>);

    /// See [`Image::from_gicon()`][crate::Image::from_gicon()] for details.
    /// ## `icon`
    /// an icon
    /// ## `size`
    /// an icon size ([`IconSize`][crate::IconSize])
    #[doc(alias = "gtk_image_set_from_gicon")]
    fn set_from_gicon(&self, icon: &impl IsA<gio::Icon>, size: IconSize);

    /// See [`Image::from_icon_name()`][crate::Image::from_icon_name()] for details.
    /// ## `icon_name`
    /// an icon name or [`None`]
    /// ## `size`
    /// an icon size ([`IconSize`][crate::IconSize])
    #[doc(alias = "gtk_image_set_from_icon_name")]
    fn set_from_icon_name(&self, icon_name: Option<&str>, size: IconSize);

    /// See [`Image::from_pixbuf()`][crate::Image::from_pixbuf()] for details.
    /// ## `pixbuf`
    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] or [`None`]
    #[doc(alias = "gtk_image_set_from_pixbuf")]
    fn set_from_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>);

    /// See [`Image::from_resource()`][crate::Image::from_resource()] for details.
    /// ## `resource_path`
    /// a resource path or [`None`]
    #[doc(alias = "gtk_image_set_from_resource")]
    fn set_from_resource(&self, resource_path: Option<&str>);

    /// See [`Image::from_surface()`][crate::Image::from_surface()] for details.
    /// ## `surface`
    /// a cairo_surface_t or [`None`]
    #[doc(alias = "gtk_image_set_from_surface")]
    fn set_from_surface(&self, surface: Option<&cairo::Surface>);

    /// Sets the pixel size to use for named icons. If the pixel size is set
    /// to a value != -1, it is used instead of the icon size set by
    /// [`set_from_icon_name()`][Self::set_from_icon_name()].
    /// ## `pixel_size`
    /// the new pixel size
    #[doc(alias = "gtk_image_set_pixel_size")]
    fn set_pixel_size(&self, pixel_size: i32);

    fn file(&self) -> Option<glib::GString>;

    fn set_file(&self, file: Option<&str>);

    /// The GIcon displayed in the GtkImage. For themed icons,
    /// If the icon theme is changed, the image will be updated
    /// automatically.
    fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>);

    /// The name of the icon in the icon theme. If the icon theme is
    /// changed, the image will be updated automatically.
    #[doc(alias = "icon-name")]
    fn icon_name(&self) -> Option<glib::GString>;

    /// The name of the icon in the icon theme. If the icon theme is
    /// changed, the image will be updated automatically.
    #[doc(alias = "icon-name")]
    fn set_icon_name(&self, icon_name: Option<&str>);

    fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>);

    #[doc(alias = "pixbuf-animation")]
    fn pixbuf_animation(&self) -> Option<gdk_pixbuf::PixbufAnimation>;

    #[doc(alias = "pixbuf-animation")]
    fn set_pixbuf_animation<P: IsA<gdk_pixbuf::PixbufAnimation>>(
        &self,
        pixbuf_animation: Option<&P>,
    );

    /// A path to a resource file to display.
    fn resource(&self) -> Option<glib::GString>;

    /// A path to a resource file to display.
    fn set_resource(&self, resource: Option<&str>);

    fn surface(&self) -> Option<cairo::Surface>;

    fn set_surface(&self, surface: Option<&cairo::Surface>);

    /// Whether the icon displayed in the GtkImage will use
    /// standard icon names fallback. The value of this property
    /// is only relevant for images of type [`ImageType::IconName`][crate::ImageType::IconName]
    /// and [`ImageType::Gicon`][crate::ImageType::Gicon].
    #[doc(alias = "use-fallback")]
    fn uses_fallback(&self) -> bool;

    /// Whether the icon displayed in the GtkImage will use
    /// standard icon names fallback. The value of this property
    /// is only relevant for images of type [`ImageType::IconName`][crate::ImageType::IconName]
    /// and [`ImageType::Gicon`][crate::ImageType::Gicon].
    #[doc(alias = "use-fallback")]
    fn set_use_fallback(&self, use_fallback: bool);

    #[doc(alias = "file")]
    fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "gicon")]
    fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "icon-name")]
    fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "pixbuf")]
    fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "pixbuf-animation")]
    fn connect_pixbuf_animation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "pixel-size")]
    fn connect_pixel_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "resource")]
    fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "storage-type")]
    fn connect_storage_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "surface")]
    fn connect_surface_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "use-fallback")]
    fn connect_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Image>> ImageExt for O {
    fn clear(&self) {
        unsafe {
            ffi::gtk_image_clear(self.as_ref().to_glib_none().0);
        }
    }

    fn animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
        unsafe { from_glib_none(ffi::gtk_image_get_animation(self.as_ref().to_glib_none().0)) }
    }

    fn gicon(&self) -> (gio::Icon, IconSize) {
        unsafe {
            let mut gicon = ptr::null_mut();
            let mut size = mem::MaybeUninit::uninit();
            ffi::gtk_image_get_gicon(
                self.as_ref().to_glib_none().0,
                &mut gicon,
                size.as_mut_ptr(),
            );
            (from_glib_none(gicon), from_glib(size.assume_init()))
        }
    }

    fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
        unsafe { from_glib_none(ffi::gtk_image_get_pixbuf(self.as_ref().to_glib_none().0)) }
    }

    fn pixel_size(&self) -> i32 {
        unsafe { ffi::gtk_image_get_pixel_size(self.as_ref().to_glib_none().0) }
    }

    fn storage_type(&self) -> ImageType {
        unsafe {
            from_glib(ffi::gtk_image_get_storage_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_from_animation(&self, animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) {
        unsafe {
            ffi::gtk_image_set_from_animation(
                self.as_ref().to_glib_none().0,
                animation.as_ref().to_glib_none().0,
            );
        }
    }

    fn set_from_file(&self, filename: Option<impl AsRef<std::path::Path>>) {
        unsafe {
            ffi::gtk_image_set_from_file(
                self.as_ref().to_glib_none().0,
                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn set_from_gicon(&self, icon: &impl IsA<gio::Icon>, size: IconSize) {
        unsafe {
            ffi::gtk_image_set_from_gicon(
                self.as_ref().to_glib_none().0,
                icon.as_ref().to_glib_none().0,
                size.into_glib(),
            );
        }
    }

    fn set_from_icon_name(&self, icon_name: Option<&str>, size: IconSize) {
        unsafe {
            ffi::gtk_image_set_from_icon_name(
                self.as_ref().to_glib_none().0,
                icon_name.to_glib_none().0,
                size.into_glib(),
            );
        }
    }

    fn set_from_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
        unsafe {
            ffi::gtk_image_set_from_pixbuf(self.as_ref().to_glib_none().0, pixbuf.to_glib_none().0);
        }
    }

    fn set_from_resource(&self, resource_path: Option<&str>) {
        unsafe {
            ffi::gtk_image_set_from_resource(
                self.as_ref().to_glib_none().0,
                resource_path.to_glib_none().0,
            );
        }
    }

    fn set_from_surface(&self, surface: Option<&cairo::Surface>) {
        unsafe {
            ffi::gtk_image_set_from_surface(
                self.as_ref().to_glib_none().0,
                mut_override(surface.to_glib_none().0),
            );
        }
    }

    fn set_pixel_size(&self, pixel_size: i32) {
        unsafe {
            ffi::gtk_image_set_pixel_size(self.as_ref().to_glib_none().0, pixel_size);
        }
    }

    fn file(&self) -> Option<glib::GString> {
        glib::ObjectExt::property(self.as_ref(), "file")
    }

    fn set_file(&self, file: Option<&str>) {
        glib::ObjectExt::set_property(self.as_ref(), "file", &file)
    }

    fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>) {
        glib::ObjectExt::set_property(self.as_ref(), "gicon", &gicon)
    }

    fn icon_name(&self) -> Option<glib::GString> {
        glib::ObjectExt::property(self.as_ref(), "icon-name")
    }

    fn set_icon_name(&self, icon_name: Option<&str>) {
        glib::ObjectExt::set_property(self.as_ref(), "icon-name", &icon_name)
    }

    fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
        glib::ObjectExt::set_property(self.as_ref(), "pixbuf", &pixbuf)
    }

    fn pixbuf_animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
        glib::ObjectExt::property(self.as_ref(), "pixbuf-animation")
    }

    fn set_pixbuf_animation<P: IsA<gdk_pixbuf::PixbufAnimation>>(
        &self,
        pixbuf_animation: Option<&P>,
    ) {
        glib::ObjectExt::set_property(self.as_ref(), "pixbuf-animation", &pixbuf_animation)
    }

    fn resource(&self) -> Option<glib::GString> {
        glib::ObjectExt::property(self.as_ref(), "resource")
    }

    fn set_resource(&self, resource: Option<&str>) {
        glib::ObjectExt::set_property(self.as_ref(), "resource", &resource)
    }

    fn surface(&self) -> Option<cairo::Surface> {
        glib::ObjectExt::property(self.as_ref(), "surface")
    }

    fn set_surface(&self, surface: Option<&cairo::Surface>) {
        glib::ObjectExt::set_property(self.as_ref(), "surface", &surface)
    }

    fn uses_fallback(&self) -> bool {
        glib::ObjectExt::property(self.as_ref(), "use-fallback")
    }

    fn set_use_fallback(&self, use_fallback: bool) {
        glib::ObjectExt::set_property(self.as_ref(), "use-fallback", &use_fallback)
    }

    fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_file_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::file\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_file_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_gicon_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::gicon\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_gicon_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::icon-name\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_icon_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_pixbuf_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::pixbuf\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_pixbuf_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_pixbuf_animation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_pixbuf_animation_trampoline<
            P: IsA<Image>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::pixbuf-animation\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_pixbuf_animation_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_pixel_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_pixel_size_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::pixel-size\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_pixel_size_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_resource_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::resource\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_resource_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_storage_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_storage_type_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::storage-type\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_storage_type_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_surface_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_surface_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::surface\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_surface_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_use_fallback_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkImage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Image::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::use-fallback\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_use_fallback_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Image {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Image")
    }
}