From c0901679db9a174fe3bcce963870c5998dcefdd0 Mon Sep 17 00:00:00 2001 From: ranfdev Date: Fri, 28 Apr 2023 18:08:32 +0200 Subject: [PATCH] manually add typed and with_type methods --- gdk4/src/content_provider.rs | 11 ++++++++--- gdk4/src/subclass/content_provider.rs | 10 +++++----- gtk4/Gir.toml | 3 +++ gtk4/src/widget.rs | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gdk4/src/content_provider.rs b/gdk4/src/content_provider.rs index 88d2a3225722..c64c28caff57 100644 --- a/gdk4/src/content_provider.rs +++ b/gdk4/src/content_provider.rs @@ -1,17 +1,22 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::{prelude::*, ContentProvider}; -use glib::translate::*; +use glib::{translate::*, value::FromValue}; // rustdoc-stripper-ignore-next /// Trait containing manually implemented methods of [`ContentProvider`](crate::ContentProvider). pub trait ContentProviderExtManual { #[doc(alias = "gdk_content_provider_get_value")] - fn value(&self, type_: glib::Type) -> Result; + fn value FromValue<'a> + StaticType>(&self) -> Result { + self.value_with_type(T::static_type()) + .map(|v| v.get::().unwrap()) + } + #[doc(alias = "gdk_content_provider_get_value")] + fn value_with_type(&self, type_: glib::Type) -> Result; } impl> ContentProviderExtManual for O { - fn value(&self, type_: glib::Type) -> Result { + fn value_with_type(&self, type_: glib::Type) -> Result { unsafe { let mut error = std::ptr::null_mut(); let mut value = glib::Value::from_type(type_); diff --git a/gdk4/src/subclass/content_provider.rs b/gdk4/src/subclass/content_provider.rs index 0ccc3718d3c7..86168f262751 100644 --- a/gdk4/src/subclass/content_provider.rs +++ b/gdk4/src/subclass/content_provider.rs @@ -37,8 +37,8 @@ pub trait ContentProviderImpl: ContentProviderImplExt + ObjectImpl { self.parent_write_mime_type_future(mime_type, stream, io_priority) } - fn value(&self, type_: glib::Type) -> Result { - self.parent_value(type_) + fn value_with_type(&self, type_: glib::Type) -> Result { + self.parent_value_with_type(type_) } } @@ -72,7 +72,7 @@ pub trait ContentProviderImplExt: ObjectSubclass { io_priority: glib::Priority, ) -> Pin> + 'static>>; - fn parent_value(&self, type_: glib::Type) -> Result; + fn parent_value_with_type(&self, type_: glib::Type) -> Result; } impl ContentProviderImplExt for T { @@ -258,7 +258,7 @@ impl ContentProviderImplExt for T { )) } - fn parent_value(&self, type_: glib::Type) -> Result { + fn parent_value_with_type(&self, type_: glib::Type) -> Result { unsafe { let data = T::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GdkContentProviderClass; @@ -421,7 +421,7 @@ unsafe extern "C" fn content_provider_get_value( let imp = instance.imp(); let value: Value = from_glib_none(value_ptr); - let ret = imp.value(value.type_()); + let ret = imp.value_with_type(value.type_()); match ret { Ok(v) => { glib::gobject_ffi::g_value_copy(v.to_glib_none().0, value_ptr); diff --git a/gtk4/Gir.toml b/gtk4/Gir.toml index 13a3590bd8cc..788d9b332c42 100644 --- a/gtk4/Gir.toml +++ b/gtk4/Gir.toml @@ -2633,6 +2633,9 @@ status = "generate" name = "Gtk.Widget" status = "generate" manual_traits = ["WidgetExtManual"] + [[object.function]] + name = "ancestor" + manual = true [[object.function]] name = "add_tick_callback" manual = true diff --git a/gtk4/src/widget.rs b/gtk4/src/widget.rs index 5444e1bdd6d1..030f958b4165 100644 --- a/gtk4/src/widget.rs +++ b/gtk4/src/widget.rs @@ -12,9 +12,30 @@ pub trait WidgetExtManual: 'static { &self, callback: P, ) -> TickCallbackId; + + #[doc(alias = "gtk_widget_get_ancestor")] + #[doc(alias = "get_ancestor")] + #[must_use] + fn ancestor>(&self) -> Option { + self.ancestor_with_type(T::static_type()) + .and_then(|w| w.downcast().ok()) + } + + #[doc(alias = "gtk_widget_get_ancestor")] + #[doc(alias = "get_ancestor")] + #[must_use] + fn ancestor_with_type(&self, widget_type: glib::types::Type) -> Option; } impl> WidgetExtManual for O { + fn ancestor_with_type(&self, widget_type: glib::types::Type) -> Option { + unsafe { + from_glib_none(ffi::gtk_widget_get_ancestor( + self.as_ref().to_glib_none().0, + widget_type.into_glib(), + )) + } + } fn add_tick_callback Continue + 'static>( &self, callback: P,