Skip to content

Commit eed0e28

Browse files
Merge pull request gtk-rs#621 from GuillaumeGomez/clipboard-request-img
Make Clipboard::request_image pixbuf an Option
2 parents b117741 + a6e6b52 commit eed0e28

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

gtk/Gir.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ status = "generate"
742742
name = "set_with_owner"
743743
#array with size
744744
ignore = true
745+
[[object.function]]
746+
name = "request_image"
747+
# nullable callback parameter
748+
ignore = true
745749

746750
[[object]]
747751
name = "Gtk.ColorButton"

gtk/src/auto/clipboard.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,6 @@ impl Clipboard {
7777
}
7878
}
7979

80-
#[doc(alias = "gtk_clipboard_request_image")]
81-
pub fn request_image<P: FnOnce(&Clipboard, &gdk_pixbuf::Pixbuf) + 'static>(&self, callback: P) {
82-
let callback_data: Box_<P> = Box_::new(callback);
83-
unsafe extern "C" fn callback_func<P: FnOnce(&Clipboard, &gdk_pixbuf::Pixbuf) + 'static>(
84-
clipboard: *mut ffi::GtkClipboard,
85-
pixbuf: *mut gdk_pixbuf::ffi::GdkPixbuf,
86-
data: glib::ffi::gpointer,
87-
) {
88-
let clipboard = from_glib_borrow(clipboard);
89-
let pixbuf = from_glib_borrow(pixbuf);
90-
let callback: Box_<P> = Box_::from_raw(data as *mut _);
91-
(*callback)(&clipboard, &pixbuf);
92-
}
93-
let callback = Some(callback_func::<P> as _);
94-
let super_callback0: Box_<P> = callback_data;
95-
unsafe {
96-
ffi::gtk_clipboard_request_image(
97-
self.to_glib_none().0,
98-
callback,
99-
Box_::into_raw(super_callback0) as *mut _,
100-
);
101-
}
102-
}
103-
10480
#[doc(alias = "gtk_clipboard_request_rich_text")]
10581
pub fn request_rich_text<
10682
P: IsA<TextBuffer>,

gtk/src/clipboard.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,35 @@ impl Clipboard {
9090
);
9191
}
9292
}
93+
94+
#[doc(alias = "gtk_clipboard_request_image")]
95+
pub fn request_image<P: FnOnce(&Clipboard, Option<&gdk_pixbuf::Pixbuf>) + 'static>(
96+
&self,
97+
callback: P,
98+
) {
99+
unsafe extern "C" fn callback_func<
100+
P: FnOnce(&Clipboard, Option<&gdk_pixbuf::Pixbuf>) + 'static,
101+
>(
102+
clipboard: *mut ffi::GtkClipboard,
103+
pixbuf: *mut gdk_pixbuf::ffi::GdkPixbuf,
104+
data: glib::ffi::gpointer,
105+
) {
106+
let clipboard = from_glib_borrow(clipboard);
107+
let callback: Box_<P> = Box_::from_raw(data as *mut _);
108+
(*callback)(
109+
&clipboard,
110+
Option::<gdk_pixbuf::Pixbuf>::from_glib_borrow(pixbuf)
111+
.as_ref()
112+
.as_ref(),
113+
);
114+
}
115+
let callback: Box_<P> = Box::new(callback);
116+
unsafe {
117+
ffi::gtk_clipboard_request_image(
118+
self.to_glib_none().0,
119+
Some(callback_func::<P> as _),
120+
Box_::into_raw(callback) as *mut _,
121+
);
122+
}
123+
}
93124
}

0 commit comments

Comments
 (0)