diff --git a/gdk4/Gir.toml b/gdk4/Gir.toml index 4458bcc44569..4b16554a7ddf 100644 --- a/gdk4/Gir.toml +++ b/gdk4/Gir.toml @@ -250,6 +250,9 @@ generate_builder = false name = "read_async" manual = true # mime_types are cloned instead of converting them to a Vec [[object.function]] + name = "read_value_async" + manual = true # To add a with_type variant + [[object.function]] name = "set_content" [object.function.return] bool_return_is_error = "Can't set new clipboard content" @@ -282,9 +285,11 @@ status = "generate" [[object.function]] name = "new_for_gtype" rename = "for_type" + manual = true # To add a with_type variant [[object.function]] name = "contain_gtype" rename = "contains_type" + manual = true # To add a with_type variant [[object.function]] name = "match_gtype" rename = "match_type" @@ -448,6 +453,9 @@ status = "generate" [[object.function]] name = "read_async" manual = true # mime_types are cloned instead of converting them to a Vec + [[object.function]] + name = "read_value_async" + manual = true # To add a with_type variant [[object]] name = "Gdk.EventType" diff --git a/gdk4/src/auto/clipboard.rs b/gdk4/src/auto/clipboard.rs index 3a12bd44354b..479dfdbdf622 100644 --- a/gdk4/src/auto/clipboard.rs +++ b/gdk4/src/auto/clipboard.rs @@ -166,72 +166,6 @@ impl Clipboard { })) } - #[doc(alias = "gdk_clipboard_read_value_async")] - pub fn read_value_async) + 'static>( - &self, - type_: glib::types::Type, - io_priority: glib::Priority, - cancellable: Option<&impl IsA>, - callback: P, - ) { - let main_context = glib::MainContext::ref_thread_default(); - let is_main_context_owner = main_context.is_owner(); - let has_acquired_main_context = (!is_main_context_owner) - .then(|| main_context.acquire().ok()) - .flatten(); - assert!( - is_main_context_owner || has_acquired_main_context.is_some(), - "Async operations only allowed if the thread is owning the MainContext" - ); - - let user_data: Box_> = - Box_::new(glib::thread_guard::ThreadGuard::new(callback)); - unsafe extern "C" fn read_value_async_trampoline< - P: FnOnce(Result) + 'static, - >( - _source_object: *mut glib::gobject_ffi::GObject, - res: *mut gio::ffi::GAsyncResult, - user_data: glib::ffi::gpointer, - ) { - let mut error = ptr::null_mut(); - let ret = - ffi::gdk_clipboard_read_value_finish(_source_object as *mut _, res, &mut error); - let result = if error.is_null() { - Ok(from_glib_none(ret)) - } else { - Err(from_glib_full(error)) - }; - let callback: Box_> = - Box_::from_raw(user_data as *mut _); - let callback: P = callback.into_inner(); - callback(result); - } - let callback = read_value_async_trampoline::

; - unsafe { - ffi::gdk_clipboard_read_value_async( - self.to_glib_none().0, - type_.into_glib(), - io_priority.into_glib(), - cancellable.map(|p| p.as_ref()).to_glib_none().0, - Some(callback), - Box_::into_raw(user_data) as *mut _, - ); - } - } - - pub fn read_value_future( - &self, - type_: glib::types::Type, - io_priority: glib::Priority, - ) -> Pin> + 'static>> - { - Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { - obj.read_value_async(type_, io_priority, Some(cancellable), move |res| { - send.resolve(res); - }); - })) - } - #[doc(alias = "gdk_clipboard_set_content")] pub fn set_content( &self, diff --git a/gdk4/src/auto/content_formats.rs b/gdk4/src/auto/content_formats.rs index 37e351f15af7..c0f00260fe46 100644 --- a/gdk4/src/auto/content_formats.rs +++ b/gdk4/src/auto/content_formats.rs @@ -29,24 +29,6 @@ impl ContentFormats { } } - #[doc(alias = "gdk_content_formats_new_for_gtype")] - #[doc(alias = "new_for_gtype")] - pub fn for_type(type_: glib::types::Type) -> ContentFormats { - assert_initialized_main_thread!(); - unsafe { from_glib_full(ffi::gdk_content_formats_new_for_gtype(type_.into_glib())) } - } - - #[doc(alias = "gdk_content_formats_contain_gtype")] - #[doc(alias = "contain_gtype")] - pub fn contains_type(&self, type_: glib::types::Type) -> bool { - unsafe { - from_glib(ffi::gdk_content_formats_contain_gtype( - self.to_glib_none().0, - type_.into_glib(), - )) - } - } - #[doc(alias = "gdk_content_formats_contain_mime_type")] pub fn contain_mime_type(&self, mime_type: &str) -> bool { unsafe { diff --git a/gdk4/src/auto/drop.rs b/gdk4/src/auto/drop.rs index 55cb3b86f8e0..9b7a41113c61 100644 --- a/gdk4/src/auto/drop.rs +++ b/gdk4/src/auto/drop.rs @@ -8,7 +8,7 @@ use glib::{ signal::{connect_raw, SignalHandlerId}, translate::*, }; -use std::{boxed::Box as Box_, fmt, mem::transmute, pin::Pin, ptr}; +use std::{boxed::Box as Box_, fmt, mem::transmute}; glib::wrapper! { #[doc(alias = "GdkDrop")] @@ -63,71 +63,6 @@ impl Drop { unsafe { from_glib_none(ffi::gdk_drop_get_surface(self.to_glib_none().0)) } } - #[doc(alias = "gdk_drop_read_value_async")] - pub fn read_value_async) + 'static>( - &self, - type_: glib::types::Type, - io_priority: glib::Priority, - cancellable: Option<&impl IsA>, - callback: P, - ) { - let main_context = glib::MainContext::ref_thread_default(); - let is_main_context_owner = main_context.is_owner(); - let has_acquired_main_context = (!is_main_context_owner) - .then(|| main_context.acquire().ok()) - .flatten(); - assert!( - is_main_context_owner || has_acquired_main_context.is_some(), - "Async operations only allowed if the thread is owning the MainContext" - ); - - let user_data: Box_> = - Box_::new(glib::thread_guard::ThreadGuard::new(callback)); - unsafe extern "C" fn read_value_async_trampoline< - P: FnOnce(Result) + 'static, - >( - _source_object: *mut glib::gobject_ffi::GObject, - res: *mut gio::ffi::GAsyncResult, - user_data: glib::ffi::gpointer, - ) { - let mut error = ptr::null_mut(); - let ret = ffi::gdk_drop_read_value_finish(_source_object as *mut _, res, &mut error); - let result = if error.is_null() { - Ok(from_glib_none(ret)) - } else { - Err(from_glib_full(error)) - }; - let callback: Box_> = - Box_::from_raw(user_data as *mut _); - let callback: P = callback.into_inner(); - callback(result); - } - let callback = read_value_async_trampoline::

; - unsafe { - ffi::gdk_drop_read_value_async( - self.to_glib_none().0, - type_.into_glib(), - io_priority.into_glib(), - cancellable.map(|p| p.as_ref()).to_glib_none().0, - Some(callback), - Box_::into_raw(user_data) as *mut _, - ); - } - } - - pub fn read_value_future( - &self, - type_: glib::types::Type, - io_priority: glib::Priority, - ) -> Pin> + 'static>> - { - Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { - obj.read_value_async(type_, io_priority, Some(cancellable), move |res| { - send.resolve(res); - }); - })) - } - #[doc(alias = "gdk_drop_status")] pub fn status(&self, actions: DragAction, preferred: DragAction) { unsafe { diff --git a/gdk4/src/clipboard.rs b/gdk4/src/clipboard.rs index 75e8fd7e317a..12254e763c87 100644 --- a/gdk4/src/clipboard.rs +++ b/gdk4/src/clipboard.rs @@ -3,7 +3,7 @@ use crate::{prelude::*, Clipboard}; use glib::translate::*; use glib::GString; -use std::{future, pin::Pin, ptr}; +use std::{boxed::Box as Box_, future, pin::Pin, ptr}; impl Clipboard { #[doc(alias = "gdk_clipboard_read_async")] @@ -86,4 +86,91 @@ impl Clipboard { }); })) } + + #[doc(alias = "gdk_clipboard_read_value_async")] + pub fn read_value_async glib::value::FromValue<'a> + glib::StaticType>( + &self, + io_priority: glib::Priority, + cancellable: Option<&impl IsA>, + callback: impl FnOnce(Result) + 'static, + ) { + let callback2 = + |t: Result| callback(t.map(|v| v.get::().unwrap())); + self.read_value_async_with_type(T::static_type(), io_priority, cancellable, callback2) + } + + #[doc(alias = "gdk_clipboard_read_value_async")] + pub fn read_value_async_with_type) + 'static>( + &self, + type_: glib::types::Type, + io_priority: glib::Priority, + cancellable: Option<&impl IsA>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn read_value_async_trampoline< + P: FnOnce(Result) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = + ffi::gdk_clipboard_read_value_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(from_glib_none(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = read_value_async_trampoline::

; + unsafe { + ffi::gdk_clipboard_read_value_async( + self.to_glib_none().0, + type_.into_glib(), + io_priority.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub async fn read_value_future glib::value::FromValue<'a> + glib::StaticType>( + &self, + io_priority: glib::Priority, + ) -> Result { + self.read_value_future_with_type(T::static_type(), io_priority) + .await + .map(|v| v.get::().unwrap()) + } + + pub fn read_value_future_with_type( + &self, + type_: glib::types::Type, + io_priority: glib::Priority, + ) -> Pin> + 'static>> + { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.read_value_async_with_type(type_, io_priority, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } } diff --git a/gdk4/src/content_formats.rs b/gdk4/src/content_formats.rs index b26be3d3f048..bf262b7666b5 100644 --- a/gdk4/src/content_formats.rs +++ b/gdk4/src/content_formats.rs @@ -1,9 +1,40 @@ // Take a look at the license at the top of the repository in the LICENSE file. use crate::{ContentFormats, ContentFormatsBuilder}; -use glib::{translate::*, Slice}; +use glib::{translate::*, Slice, StaticType}; impl ContentFormats { + #[doc(alias = "gdk_content_formats_new_for_gtype")] + #[doc(alias = "new_for_gtype")] + pub fn for_type() -> Self { + assert_initialized_main_thread!(); + Self::for_type_with_type(T::static_type()) + } + + #[doc(alias = "gdk_content_formats_new_for_gtype")] + #[doc(alias = "new_for_gtype")] + pub fn for_type_with_type(type_: glib::Type) -> Self { + assert_initialized_main_thread!(); + unsafe { from_glib_full(ffi::gdk_content_formats_new_for_gtype(type_.into_glib())) } + } + + #[doc(alias = "gdk_content_formats_contain_gtype")] + #[doc(alias = "contain_gtype")] + pub fn contains_type(&self) -> bool { + self.contains_type_with_type(T::static_type()) + } + + #[doc(alias = "gdk_content_formats_contain_gtype")] + #[doc(alias = "contain_gtype")] + pub fn contains_type_with_type(&self, type_: glib::types::Type) -> bool { + unsafe { + from_glib(ffi::gdk_content_formats_contain_gtype( + self.to_glib_none().0, + type_.into_glib(), + )) + } + } + #[doc(alias = "gdk_content_formats_get_gtypes")] #[doc(alias = "get_gtypes")] pub fn types(&self) -> Slice { diff --git a/gdk4/src/content_formats_builder.rs b/gdk4/src/content_formats_builder.rs index 3f2fd704b26f..1db341823f29 100644 --- a/gdk4/src/content_formats_builder.rs +++ b/gdk4/src/content_formats_builder.rs @@ -19,7 +19,13 @@ impl ContentFormatsBuilder { #[doc(alias = "gdk_content_formats_builder_add_gtype")] #[must_use] - pub fn add_type(self, type_: glib::types::Type) -> Self { + pub fn add_type(self) -> Self { + self.add_with_type(T::static_type()) + } + + #[doc(alias = "gdk_content_formats_builder_add_gtype")] + #[must_use] + pub fn add_with_type(self, type_: glib::types::Type) -> Self { unsafe { ffi::gdk_content_formats_builder_add_gtype(self.to_glib_none().0, type_.into_glib()); } diff --git a/gdk4/src/content_provider.rs b/gdk4/src/content_provider.rs index 9bd12a34b5f0..e85af0faf460 100644 --- a/gdk4/src/content_provider.rs +++ b/gdk4/src/content_provider.rs @@ -11,8 +11,15 @@ mod sealed { // rustdoc-stripper-ignore-next /// Trait containing manually implemented methods of [`ContentProvider`](crate::ContentProvider). pub trait ContentProviderExtManual: sealed::Sealed + IsA { + fn value glib::value::FromValue<'a> + glib::StaticType>( + &self, + ) -> Result { + self.value_with_type(T::static_type()) + .map(|v| v.get::().unwrap()) + } + #[doc(alias = "gdk_content_provider_get_value")] - 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/drop.rs b/gdk4/src/drop.rs index a782fb1d3534..0ce044af183b 100644 --- a/gdk4/src/drop.rs +++ b/gdk4/src/drop.rs @@ -1,14 +1,96 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::Drop; -use glib::object::IsA; -use glib::translate::*; -use glib::GString; -use std::future; -use std::pin::Pin; -use std::ptr; +use crate::{prelude::*, Drop}; +use glib::{translate::*, GString}; +use std::{boxed::Box as Box_, future, pin::Pin, ptr}; impl Drop { + #[doc(alias = "gdk_drop_read_value_async")] + pub fn read_value_async glib::value::FromValue<'a> + glib::StaticType>( + &self, + io_priority: glib::Priority, + cancellable: Option<&impl IsA>, + callback: impl FnOnce(Result) + 'static, + ) { + let callback2 = + |t: Result| callback(t.map(|v| v.get::().unwrap())); + self.read_value_async_with_type(T::static_type(), io_priority, cancellable, callback2) + } + + #[doc(alias = "gdk_drop_read_value_async")] + pub fn read_value_async_with_type) + 'static>( + &self, + type_: glib::types::Type, + io_priority: glib::Priority, + cancellable: Option<&impl IsA>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + let user_data: Box_> = + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); + unsafe extern "C" fn read_value_async_trampoline< + P: FnOnce(Result) + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut gio::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = ptr::null_mut(); + let ret = ffi::gdk_drop_read_value_finish(_source_object as *mut _, res, &mut error); + let result = if error.is_null() { + Ok(from_glib_none(ret)) + } else { + Err(from_glib_full(error)) + }; + let callback: Box_> = + Box_::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + let callback = read_value_async_trampoline::

; + unsafe { + ffi::gdk_drop_read_value_async( + self.to_glib_none().0, + type_.into_glib(), + io_priority.into_glib(), + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box_::into_raw(user_data) as *mut _, + ); + } + } + + pub async fn read_value_future glib::value::FromValue<'a> + glib::StaticType>( + &self, + io_priority: glib::Priority, + ) -> Result { + self.read_value_future_with_type(T::static_type(), io_priority) + .await + .map(|v| v.get::().unwrap()) + } + + pub fn read_value_future_with_type( + &self, + type_: glib::types::Type, + io_priority: glib::Priority, + ) -> Pin> + 'static>> + { + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { + obj.read_value_async_with_type(type_, io_priority, Some(cancellable), move |res| { + send.resolve(res); + }); + })) + } + #[doc(alias = "gdk_drop_read_async")] pub fn read_async) + 'static>( &self, diff --git a/gdk4/src/functions.rs b/gdk4/src/functions.rs index 66954b4b39c0..7b1373726352 100644 --- a/gdk4/src/functions.rs +++ b/gdk4/src/functions.rs @@ -29,7 +29,30 @@ pub fn pango_layout_get_clip_region( } #[doc(alias = "gdk_content_deserialize_async")] -pub fn content_deserialize_async) + 'static>( +pub fn content_deserialize_async glib::value::FromValue<'a> + glib::StaticType>( + stream: &impl IsA, + mime_type: &str, + io_priority: glib::Priority, + cancellable: Option<&impl IsA>, + callback: impl FnOnce(Result) + 'static, +) { + assert_initialized_main_thread!(); + let callback2 = + |t: Result| callback(t.map(|e| e.get::().unwrap())); + content_deserialize_async_with_type( + stream, + mime_type, + T::static_type(), + io_priority, + cancellable, + callback2, + ); +} + +#[doc(alias = "gdk_content_deserialize_async")] +pub fn content_deserialize_async_with_type< + R: FnOnce(Result) + 'static, +>( stream: &impl IsA, mime_type: &str, type_: glib::types::Type, @@ -83,7 +106,20 @@ pub fn content_deserialize_async) + ' } } -pub fn content_deserialize_future( +pub async fn content_deserialize_future< + T: for<'a> glib::value::FromValue<'a> + glib::StaticType, +>( + stream: &(impl IsA + Clone + 'static), + mime_type: &str, + io_priority: glib::Priority, +) -> Result { + assert_initialized_main_thread!(); + content_deserialize_with_type_future(stream, mime_type, T::static_type(), io_priority) + .await + .map(|t| t.get::().unwrap()) +} + +pub fn content_deserialize_with_type_future( stream: &(impl IsA + Clone + 'static), mime_type: &str, type_: glib::types::Type, @@ -94,7 +130,7 @@ pub fn content_deserialize_future( let stream = stream.clone(); let mime_type = String::from(mime_type); Box::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| { - content_deserialize_async( + content_deserialize_async_with_type( &stream, &mime_type, type_, diff --git a/gdk4/src/subclass/content_provider.rs b/gdk4/src/subclass/content_provider.rs index c46471d3f20e..47c139263347 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_) } } @@ -230,7 +230,7 @@ pub trait ContentProviderImplExt: sealed::Sealed + ObjectSubclass { )) } - fn parent_value(&self, type_: glib::Type) -> Result { + fn parent_value_with_type(&self, type_: glib::Type) -> Result { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GdkContentProviderClass; @@ -395,7 +395,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 086b6f9e0a8b..76e0502f4cc2 100644 --- a/gtk4/Gir.toml +++ b/gtk4/Gir.toml @@ -194,7 +194,6 @@ generate = [ "Gtk.ProgressBar", "Gtk.PropagationLimit", "Gtk.PropagationPhase", - "Gtk.PropertyExpression", "Gtk.RecentInfo", "Gtk.RecentManagerError", "Gtk.Revealer", @@ -679,6 +678,9 @@ generate_builder = false [[object.function]] name = "get_current_object" manual = true # don't ref_sink the object + [[object.function]] + pattern = "(value_from_string_type|extend_with_template)" + manual = true # To add a with_type variant [[object]] name = "Gtk.BuilderListItemFactory" @@ -1025,6 +1027,9 @@ manual_traits = ["DrawingAreaExtManual"] [[object]] name = "Gtk.DropTarget" status = "generate" + [[object.function]] + name = "new" + manual = true # To add a with_type variant [[object.signal]] name = "drop" # manual: FromGlibPtrBorrow<*mut GValue>` is not implemented for `Value` @@ -1884,6 +1889,13 @@ name = "Gtk.PrintUnixDialog" status = "generate" cfg_condition = "target_os = \"linux\"" +[[object]] +name = "Gtk.PropertyExpression" +status = "generate" + [[object.function]] + name = "new" + manual = true # To add a with_type variant + [[object]] name = "Gtk.Range" status = "generate" @@ -2673,6 +2685,9 @@ manual_traits = ["WidgetExtManual"] pattern = "(init|dispose)_template" ignore = true # We manually bind this one as part of CompositeTemplatExt [[object.function]] + name = "get_ancestor" + manual = true # To add a with_type variant + [[object.function]] name = "get_template_child" ignore = true # Not useful for Rust bindings [[object.function]] diff --git a/gtk4/src/auto/builder.rs b/gtk4/src/auto/builder.rs index a0c1e8007e04..c652ad79b00a 100644 --- a/gtk4/src/auto/builder.rs +++ b/gtk4/src/auto/builder.rs @@ -194,33 +194,6 @@ impl Builder { } } - #[doc(alias = "gtk_builder_extend_with_template")] - pub fn extend_with_template( - &self, - object: &impl IsA, - template_type: glib::types::Type, - buffer: &str, - ) -> Result<(), glib::Error> { - let length = buffer.len() as _; - unsafe { - let mut error = ptr::null_mut(); - let is_ok = ffi::gtk_builder_extend_with_template( - self.to_glib_none().0, - object.as_ref().to_glib_none().0, - template_type.into_glib(), - buffer.to_glib_none().0, - length, - &mut error, - ); - debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); - if error.is_null() { - Ok(()) - } else { - Err(from_glib_full(error)) - } - } - } - #[doc(alias = "gtk_builder_get_objects")] #[doc(alias = "get_objects")] pub fn objects(&self) -> Vec { @@ -310,31 +283,6 @@ impl Builder { } } - #[doc(alias = "gtk_builder_value_from_string_type")] - pub fn value_from_string_type( - &self, - type_: glib::types::Type, - string: &str, - ) -> Result { - unsafe { - let mut value = glib::Value::uninitialized(); - let mut error = ptr::null_mut(); - let is_ok = ffi::gtk_builder_value_from_string_type( - self.to_glib_none().0, - type_.into_glib(), - string.to_glib_none().0, - value.to_glib_none_mut().0, - &mut error, - ); - debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); - if error.is_null() { - Ok(value) - } else { - Err(from_glib_full(error)) - } - } - } - #[doc(alias = "current-object")] pub fn connect_current_object_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_current_object_trampoline( diff --git a/gtk4/src/auto/drop_target.rs b/gtk4/src/auto/drop_target.rs index b56e18ac963a..2df2017dafb7 100644 --- a/gtk4/src/auto/drop_target.rs +++ b/gtk4/src/auto/drop_target.rs @@ -21,17 +21,6 @@ glib::wrapper! { } impl DropTarget { - #[doc(alias = "gtk_drop_target_new")] - pub fn new(type_: glib::types::Type, actions: gdk::DragAction) -> DropTarget { - assert_initialized_main_thread!(); - unsafe { - from_glib_full(ffi::gtk_drop_target_new( - type_.into_glib(), - actions.into_glib(), - )) - } - } - // rustdoc-stripper-ignore-next /// Creates a new builder-pattern struct instance to construct [`DropTarget`] objects. /// @@ -326,12 +315,6 @@ impl DropTarget { } } -impl Default for DropTarget { - fn default() -> Self { - glib::object::Object::new::() - } -} - // rustdoc-stripper-ignore-next /// A [builder-pattern] type to construct [`DropTarget`] objects. /// diff --git a/gtk4/src/auto/property_expression.rs b/gtk4/src/auto/property_expression.rs index b7114d564848..93cc1e331c96 100644 --- a/gtk4/src/auto/property_expression.rs +++ b/gtk4/src/auto/property_expression.rs @@ -23,24 +23,6 @@ impl glib::StaticType for PropertyExpression { } impl PropertyExpression { - #[doc(alias = "gtk_property_expression_new")] - pub fn new( - this_type: glib::types::Type, - expression: Option>, - property_name: &str, - ) -> PropertyExpression { - assert_initialized_main_thread!(); - unsafe { - from_glib_full(ffi::gtk_property_expression_new( - this_type.into_glib(), - expression - .map(|p| p.as_ref().clone().upcast()) - .into_glib_ptr(), - property_name.to_glib_none().0, - )) - } - } - #[doc(alias = "gtk_property_expression_new_for_pspec")] #[doc(alias = "new_for_pspec")] pub fn for_pspec( diff --git a/gtk4/src/auto/widget.rs b/gtk4/src/auto/widget.rs index 989408c3ef71..8d1f318c2e2a 100644 --- a/gtk4/src/auto/widget.rs +++ b/gtk4/src/auto/widget.rs @@ -312,18 +312,6 @@ pub trait WidgetExt: IsA + sealed::Sealed + 'static { } } - #[doc(alias = "gtk_widget_get_ancestor")] - #[doc(alias = "get_ancestor")] - #[must_use] - fn ancestor(&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(), - )) - } - } - #[cfg(feature = "v4_12")] #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))] #[doc(alias = "gtk_widget_get_baseline")] diff --git a/gtk4/src/builder.rs b/gtk4/src/builder.rs index a62351b14437..e25b8c8d581f 100644 --- a/gtk4/src/builder.rs +++ b/gtk4/src/builder.rs @@ -44,10 +44,80 @@ impl Builder { } } + #[doc(alias = "gtk_builder_extend_with_template")] + pub fn extend_with_template>( + &self, + object: &impl IsA, + buffer: &str, + ) -> Result<(), glib::Error> { + self.extend_with_template_and_type(object, T::static_type(), buffer) + } + + #[doc(alias = "gtk_builder_extend_with_template")] + pub fn extend_with_template_and_type( + &self, + object: &impl IsA, + template_type: glib::Type, + buffer: &str, + ) -> Result<(), glib::Error> { + let length = buffer.len() as _; + unsafe { + let mut error = std::ptr::null_mut(); + let is_ok = ffi::gtk_builder_extend_with_template( + self.to_glib_none().0, + object.as_ref().to_glib_none().0, + template_type.into_glib(), + buffer.to_glib_none().0, + length, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + #[doc(alias = "gtk_builder_value_from_string_type")] + pub fn value_from_string_type glib::value::FromValue<'a> + StaticType>( + &self, + string: &str, + ) -> Result { + self.value_from_string_type_with_type(T::static_type(), string) + .map(|v| v.get::().unwrap()) + } + + #[doc(alias = "gtk_builder_value_from_string_type")] + pub fn value_from_string_type_with_type( + &self, + type_: glib::Type, + string: &str, + ) -> Result { + unsafe { + let mut value = glib::Value::uninitialized(); + let mut error = std::ptr::null_mut(); + let is_ok = ffi::gtk_builder_value_from_string_type( + self.to_glib_none().0, + type_.into_glib(), + string.to_glib_none().0, + value.to_glib_none_mut().0, + &mut error, + ); + debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); + if error.is_null() { + Ok(value) + } else { + Err(from_glib_full(error)) + } + } + } + #[doc(alias = "gtk_builder_add_from_file")] pub fn add_from_file(&self, file_path: impl AsRef) -> Result<(), glib::Error> { unsafe { - let mut error = ::std::ptr::null_mut(); + let mut error = std::ptr::null_mut(); ffi::gtk_builder_add_from_file( self.to_glib_none().0, file_path.as_ref().to_glib_none().0, diff --git a/gtk4/src/drop_target.rs b/gtk4/src/drop_target.rs index 575ca0890418..da1cafb23f79 100644 --- a/gtk4/src/drop_target.rs +++ b/gtk4/src/drop_target.rs @@ -10,16 +10,38 @@ use glib::{ use std::{boxed::Box as Box_, mem::transmute}; impl DropTarget { + #[doc(alias = "gtk_drop_target_new")] + pub fn new(actions: gdk::DragAction) -> Self { + assert_initialized_main_thread!(); + Self::with_type(T::static_type(), actions) + } + + #[doc(alias = "gtk_drop_target_new")] + pub fn with_type(type_: glib::Type, actions: gdk::DragAction) -> Self { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gtk_drop_target_new( + type_.into_glib(), + actions.into_glib(), + )) + } + } + + #[doc(alias = "gtk_drop_target_new")] #[doc(alias = "gtk_drop_target_set_gtypes")] - pub fn set_types(&self, types: &[Type]) { + #[doc(alias = "set_types")] + pub fn with_types(types: &[Type], actions: gdk::DragAction) -> Self { + assert_initialized_main_thread!(); + let target = Self::with_type(glib::Type::INVALID, actions); let types: Vec = types.iter().map(|t| t.into_glib()).collect(); unsafe { ffi::gtk_drop_target_set_gtypes( - self.to_glib_none().0, + target.to_glib_none().0, mut_override(types.as_ptr()), types.len(), ) } + target } #[doc(alias = "gtk_drop_target_get_value")] diff --git a/gtk4/src/expression.rs b/gtk4/src/expression.rs index 1f93cda9a8f4..8916a9e88bb3 100644 --- a/gtk4/src/expression.rs +++ b/gtk4/src/expression.rs @@ -108,7 +108,7 @@ impl Expression { &self, property_name: &str, ) -> crate::PropertyExpression { - crate::PropertyExpression::new(T::static_type(), Some(self), property_name) + crate::PropertyExpression::new::(Some(self), property_name) } // rustdoc-stripper-ignore-next @@ -235,21 +235,21 @@ pub trait GObjectPropertyExpressionExt: IsA { /// Create an expression looking up an object's property. fn property_expression(&self, property_name: &str) -> crate::PropertyExpression { let obj_expr = crate::ConstantExpression::new(self); - crate::PropertyExpression::new(Self::static_type(), Some(&obj_expr), property_name) + crate::PropertyExpression::new::(Some(&obj_expr), property_name) } // rustdoc-stripper-ignore-next /// Create an expression looking up an object's property with a weak reference. fn property_expression_weak(&self, property_name: &str) -> crate::PropertyExpression { let obj_expr = crate::ObjectExpression::new(self); - crate::PropertyExpression::new(Self::static_type(), Some(&obj_expr), property_name) + crate::PropertyExpression::new::(Some(&obj_expr), property_name) } // rustdoc-stripper-ignore-next /// Create an expression looking up a property in the bound `this` object. fn this_expression(property_name: &str) -> crate::PropertyExpression { skip_assert_initialized!(); - crate::PropertyExpression::new(Self::static_type(), Expression::NONE, property_name) + crate::PropertyExpression::new::(Expression::NONE, property_name) } } diff --git a/gtk4/src/property_expression.rs b/gtk4/src/property_expression.rs index a60b9b03eaa3..7ad576e043e5 100644 --- a/gtk4/src/property_expression.rs +++ b/gtk4/src/property_expression.rs @@ -1,10 +1,39 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::PropertyExpression; -use glib::translate::*; +use crate::{prelude::*, Expression, PropertyExpression}; +use glib::{translate::*, Object}; define_expression!(PropertyExpression, ffi::GtkPropertyExpression); +impl PropertyExpression { + #[doc(alias = "gtk_property_expression_new")] + pub fn new>( + expression: Option>, + property_name: &str, + ) -> PropertyExpression { + assert_initialized_main_thread!(); + Self::with_type(T::static_type(), expression, property_name) + } + + #[doc(alias = "gtk_property_expression_new")] + pub fn with_type( + this_type: glib::Type, + expression: Option>, + property_name: &str, + ) -> Self { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gtk_property_expression_new( + this_type.into_glib(), + expression + .map(|p| p.as_ref().clone().upcast()) + .into_glib_ptr(), + property_name.to_glib_none().0, + )) + } + } +} + impl std::fmt::Debug for PropertyExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("PropertyExpression") @@ -20,15 +49,11 @@ impl std::fmt::Debug for PropertyExpression { mod tests { use super::*; use crate as gtk4; - use glib::StaticType; #[test] fn test_property_expression() { - let prop_expr = PropertyExpression::new( - crate::StringObject::static_type(), - crate::Expression::NONE, - "string", - ); + let prop_expr = + PropertyExpression::new::(crate::Expression::NONE, "string"); assert!(prop_expr.is::()); } } diff --git a/gtk4/src/widget.rs b/gtk4/src/widget.rs index 2da6f066d582..9fe1c096d8db 100644 --- a/gtk4/src/widget.rs +++ b/gtk4/src/widget.rs @@ -12,6 +12,26 @@ mod sealed { // rustdoc-stripper-ignore-next /// Trait containing manually implemented methods of [`Widget`](crate::Widget). pub trait WidgetExtManual: sealed::Sealed + IsA + 'static { + #[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::Type) -> Option { + unsafe { + from_glib_none(ffi::gtk_widget_get_ancestor( + self.as_ref().to_glib_none().0, + widget_type.into_glib(), + )) + } + } + #[doc(alias = "gtk_widget_add_tick_callback")] fn add_tick_callback ControlFlow + 'static>( &self,