From 98f4d114057e8a2060775149929514c59cf345f9 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 18 Oct 2024 19:42:09 +0200 Subject: [PATCH] gtk: Manually implement TextBuffer.add_commit_notify --- gtk4/Gir.toml | 3 +++ gtk4/src/auto/text_buffer.rs | 47 ------------------------------------ gtk4/src/text_buffer.rs | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 47 deletions(-) diff --git a/gtk4/Gir.toml b/gtk4/Gir.toml index 0b14f17fcc76..3b12c59666eb 100644 --- a/gtk4/Gir.toml +++ b/gtk4/Gir.toml @@ -2195,6 +2195,9 @@ manual_traits = ["TextBufferExtManual"] [[object.function]] name = "insert_with_tags_by_name" manual = true + [[object.function]] + name = "add_commit_notify" + manual = true # Ends up using from_glib_borrow for a TextBufferNotifyFlags [[object]] name = "Gtk.TextIter" diff --git a/gtk4/src/auto/text_buffer.rs b/gtk4/src/auto/text_buffer.rs index 924658dd50e7..5a5d4510a19b 100644 --- a/gtk4/src/auto/text_buffer.rs +++ b/gtk4/src/auto/text_buffer.rs @@ -2,9 +2,6 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT -#[cfg(feature = "v4_16")] -#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] -use crate::TextBufferNotifyFlags; use crate::{ffi, TextChildAnchor, TextIter, TextMark, TextTag, TextTagTable}; use glib::{ prelude::*, @@ -89,50 +86,6 @@ impl TextBufferBuilder { } pub trait TextBufferExt: IsA + 'static { - #[cfg(feature = "v4_16")] - #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] - #[doc(alias = "gtk_text_buffer_add_commit_notify")] - fn add_commit_notify( - &self, - flags: TextBufferNotifyFlags, - commit_notify: P, - ) -> u32 { - let commit_notify_data: Box_

= Box_::new(commit_notify); - unsafe extern "C" fn commit_notify_func< - P: Fn(&TextBuffer, &TextBufferNotifyFlags, u32, u32) + 'static, - >( - buffer: *mut ffi::GtkTextBuffer, - flags: ffi::GtkTextBufferNotifyFlags, - position: std::ffi::c_uint, - length: std::ffi::c_uint, - user_data: glib::ffi::gpointer, - ) { - let buffer = from_glib_borrow(buffer); - let flags = from_glib_borrow(flags); - let callback = &*(user_data as *mut P); - (*callback)(&buffer, &flags, position, length) - } - let commit_notify = Some(commit_notify_func::

as _); - unsafe extern "C" fn destroy_func< - P: Fn(&TextBuffer, &TextBufferNotifyFlags, u32, u32) + 'static, - >( - data: glib::ffi::gpointer, - ) { - let _callback = Box_::from_raw(data as *mut P); - } - let destroy_call4 = Some(destroy_func::

as _); - let super_callback0: Box_

= commit_notify_data; - unsafe { - ffi::gtk_text_buffer_add_commit_notify( - self.as_ref().to_glib_none().0, - flags.into_glib(), - commit_notify, - Box_::into_raw(super_callback0) as *mut _, - destroy_call4, - ) - } - } - #[doc(alias = "gtk_text_buffer_add_mark")] fn add_mark(&self, mark: &impl IsA, where_: &TextIter) { unsafe { diff --git a/gtk4/src/text_buffer.rs b/gtk4/src/text_buffer.rs index b1c7f23e50bd..b06390884e0e 100644 --- a/gtk4/src/text_buffer.rs +++ b/gtk4/src/text_buffer.rs @@ -10,6 +10,9 @@ use libc::{c_char, c_int}; use crate::{ffi, prelude::*, TextBuffer, TextIter, TextTag}; +#[cfg(feature = "v4_16")] +use crate::TextBufferNotifyFlags; + // rustdoc-stripper-ignore-next /// Trait containing manually implemented methods of /// [`TextBuffer`](crate::TextBuffer). @@ -100,6 +103,50 @@ pub trait TextBufferExtManual: IsA + 'static { ) } } + + #[cfg(feature = "v4_16")] + #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))] + #[doc(alias = "gtk_text_buffer_add_commit_notify")] + fn add_commit_notify( + &self, + flags: TextBufferNotifyFlags, + commit_notify: P, + ) -> u32 { + let commit_notify_data: Box_

= Box_::new(commit_notify); + unsafe extern "C" fn commit_notify_func< + P: Fn(&TextBuffer, TextBufferNotifyFlags, u32, u32) + 'static, + >( + buffer: *mut ffi::GtkTextBuffer, + flags: ffi::GtkTextBufferNotifyFlags, + position: std::ffi::c_uint, + length: std::ffi::c_uint, + user_data: glib::ffi::gpointer, + ) { + let buffer = from_glib_borrow(buffer); + let flags = from_glib(flags); + let callback = &*(user_data as *mut P); + (*callback)(&buffer, flags, position, length) + } + let commit_notify = Some(commit_notify_func::

as _); + unsafe extern "C" fn destroy_func< + P: Fn(&TextBuffer, TextBufferNotifyFlags, u32, u32) + 'static, + >( + data: glib::ffi::gpointer, + ) { + let _callback = Box_::from_raw(data as *mut P); + } + let destroy_call4 = Some(destroy_func::

as _); + let super_callback0: Box_

= commit_notify_data; + unsafe { + ffi::gtk_text_buffer_add_commit_notify( + self.as_ref().to_glib_none().0, + flags.into_glib(), + commit_notify, + Box_::into_raw(super_callback0) as *mut _, + destroy_call4, + ) + } + } } impl> TextBufferExtManual for O {}