Skip to content

Commit

Permalink
gtk: Manually implement TextBuffer.add_commit_notify
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Oct 18, 2024
1 parent 98d001c commit 98f4d11
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 47 deletions.
3 changes: 3 additions & 0 deletions gtk4/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
47 changes: 0 additions & 47 deletions gtk4/src/auto/text_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -89,50 +86,6 @@ impl TextBufferBuilder {
}

pub trait TextBufferExt: IsA<TextBuffer> + '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<P: Fn(&TextBuffer, &TextBufferNotifyFlags, u32, u32) + 'static>(
&self,
flags: TextBufferNotifyFlags,
commit_notify: P,
) -> u32 {
let commit_notify_data: Box_<P> = 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::<P> 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::<P> as _);
let super_callback0: Box_<P> = 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<TextMark>, where_: &TextIter) {
unsafe {
Expand Down
47 changes: 47 additions & 0 deletions gtk4/src/text_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -100,6 +103,50 @@ pub trait TextBufferExtManual: IsA<TextBuffer> + '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<P: Fn(&TextBuffer, TextBufferNotifyFlags, u32, u32) + 'static>(
&self,
flags: TextBufferNotifyFlags,
commit_notify: P,
) -> u32 {
let commit_notify_data: Box_<P> = 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::<P> 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::<P> as _);
let super_callback0: Box_<P> = 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<O: IsA<TextBuffer>> TextBufferExtManual for O {}
Expand Down

0 comments on commit 98f4d11

Please sign in to comment.