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
// 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 cairo;
use gdk_pixbuf;
use gdk_sys;
use glib::translate::*;
use std::fmt;
use std::mem;
use CursorType;
use Display;

glib_wrapper! {
    /// A `Cursor` represents a cursor. Its contents are private.
    pub struct Cursor(Object<gdk_sys::GdkCursor, CursorClass>);

    match fn {
        get_type => || gdk_sys::gdk_cursor_get_type(),
    }
}

impl Cursor {
    /// Creates a new cursor from the set of builtin cursors for the default display.
    /// See `Cursor::new_for_display`.
    ///
    /// To make the cursor invisible, use `CursorType::BlankCursor`.
    ///
    /// # Deprecated since 3.16
    ///
    /// Use `Cursor::new_for_display` instead.
    /// ## `cursor_type`
    /// cursor to create
    ///
    /// # Returns
    ///
    /// a new `Cursor`
    #[cfg_attr(feature = "v3_16", deprecated)]
    pub fn new(cursor_type: CursorType) -> Cursor {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(gdk_sys::gdk_cursor_new(cursor_type.to_glib())) }
    }

    /// Creates a new cursor from the set of builtin cursors.
    /// ## `display`
    /// the `Display` for which the cursor will be created
    /// ## `cursor_type`
    /// cursor to create
    ///
    /// # Returns
    ///
    /// a new `Cursor`
    pub fn new_for_display(display: &Display, cursor_type: CursorType) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(gdk_sys::gdk_cursor_new_for_display(
                display.to_glib_none().0,
                cursor_type.to_glib(),
            ))
        }
    }

    pub fn from_name(display: &Display, name: &str) -> Option<Cursor> {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(gdk_sys::gdk_cursor_new_from_name(
                display.to_glib_none().0,
                name.to_glib_none().0,
            ))
        }
    }

    pub fn from_pixbuf(display: &Display, pixbuf: &gdk_pixbuf::Pixbuf, x: i32, y: i32) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(gdk_sys::gdk_cursor_new_from_pixbuf(
                display.to_glib_none().0,
                pixbuf.to_glib_none().0,
                x,
                y,
            ))
        }
    }

    pub fn from_surface(display: &Display, surface: &cairo::Surface, x: f64, y: f64) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(gdk_sys::gdk_cursor_new_from_surface(
                display.to_glib_none().0,
                mut_override(surface.to_glib_none().0),
                x,
                y,
            ))
        }
    }

    /// Returns the cursor type for this cursor.
    ///
    /// # Returns
    ///
    /// a `CursorType`
    pub fn get_cursor_type(&self) -> CursorType {
        unsafe { from_glib(gdk_sys::gdk_cursor_get_cursor_type(self.to_glib_none().0)) }
    }

    /// Returns the display on which the `Cursor` is defined.
    ///
    /// # Returns
    ///
    /// the `Display` associated to `self`
    pub fn get_display(&self) -> Display {
        unsafe { from_glib_none(gdk_sys::gdk_cursor_get_display(self.to_glib_none().0)) }
    }

    /// Returns a `gdk_pixbuf::Pixbuf` with the image used to display the cursor.
    ///
    /// Note that depending on the capabilities of the windowing system and
    /// on the cursor, GDK may not be able to obtain the image data. In this
    /// case, `None` is returned.
    ///
    /// # Returns
    ///
    /// a `gdk_pixbuf::Pixbuf` representing
    ///  `self`, or `None`
    pub fn get_image(&self) -> Option<gdk_pixbuf::Pixbuf> {
        unsafe { from_glib_full(gdk_sys::gdk_cursor_get_image(self.to_glib_none().0)) }
    }

    /// Returns a cairo image surface with the image used to display the cursor.
    ///
    /// Note that depending on the capabilities of the windowing system and
    /// on the cursor, GDK may not be able to obtain the image data. In this
    /// case, `None` is returned.
    /// ## `x_hot`
    /// Location to store the hotspot x position,
    ///  or `None`
    /// ## `y_hot`
    /// Location to store the hotspot y position,
    ///  or `None`
    ///
    /// # Returns
    ///
    /// a `cairo::Surface`
    ///  representing `self`, or `None`
    pub fn get_surface(&self) -> (Option<cairo::Surface>, f64, f64) {
        unsafe {
            let mut x_hot = mem::MaybeUninit::uninit();
            let mut y_hot = mem::MaybeUninit::uninit();
            let ret = from_glib_full(gdk_sys::gdk_cursor_get_surface(
                self.to_glib_none().0,
                x_hot.as_mut_ptr(),
                y_hot.as_mut_ptr(),
            ));
            let x_hot = x_hot.assume_init();
            let y_hot = y_hot.assume_init();
            (ret, x_hot, y_hot)
        }
    }
}

impl fmt::Display for Cursor {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Cursor")
    }
}