Skip to content

Commit ae3748f

Browse files
gtk: Add IMContext.invalid_composition vfunc support
It uses &str instead of GStr or so, as that is what we use everywhere else in this type so far. Can be updated in a separate PR.
1 parent baa224c commit ae3748f

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

gtk4/src/subclass/im_context.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ pub trait IMContextImpl: ObjectImpl + ObjectSubclass<Type: IsA<IMContext>> {
7272
fn activate_osk_with_event(&self, event: Option<&gdk::Event>) -> bool {
7373
self.parent_activate_osk_with_event(event)
7474
}
75+
#[cfg(feature = "v4_22")]
76+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
77+
fn invalid_composition(&self, string: &str) -> bool {
78+
self.parent_invalid_composition(string)
79+
}
7580
}
7681

7782
#[allow(clippy::upper_case_acronyms)]
@@ -327,6 +332,23 @@ pub trait IMContextImplExt: IMContextImpl {
327332
}
328333
}
329334
}
335+
336+
#[cfg(feature = "v4_22")]
337+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
338+
fn parent_invalid_composition(&self, string: &str) -> bool {
339+
unsafe {
340+
let data = Self::type_data();
341+
let parent_class = data.as_ref().parent_class() as *mut ffi::GtkIMContextClass;
342+
if let Some(f) = (*parent_class).invalid_composition {
343+
from_glib(f(
344+
self.obj().unsafe_cast_ref::<IMContext>().to_glib_none().0,
345+
string.to_glib_none().0,
346+
))
347+
} else {
348+
false
349+
}
350+
}
351+
}
330352
}
331353

332354
impl<T: IMContextImpl> IMContextImplExt for T {}
@@ -364,6 +386,11 @@ unsafe impl<T: IMContextImpl> IsSubclassable<T> for IMContext {
364386
{
365387
klass.activate_osk_with_event = Some(im_context_activate_osk_with_event::<T>);
366388
};
389+
#[cfg(feature = "v4_22")]
390+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
391+
{
392+
klass.invalid_composition = Some(im_context_invalid_composition::<T>);
393+
};
367394
}
368395
}
369396

@@ -538,7 +565,6 @@ unsafe extern "C" fn im_context_set_use_preedit<T: IMContextImpl>(
538565
}
539566

540567
#[cfg(feature = "v4_10")]
541-
#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
542568
unsafe extern "C" fn im_context_activate_osk<T: IMContextImpl>(ptr: *mut ffi::GtkIMContext) {
543569
let instance = &*(ptr as *mut T::Instance);
544570
let imp = instance.imp();
@@ -547,7 +573,6 @@ unsafe extern "C" fn im_context_activate_osk<T: IMContextImpl>(ptr: *mut ffi::Gt
547573
}
548574

549575
#[cfg(feature = "v4_14")]
550-
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
551576
unsafe extern "C" fn im_context_activate_osk_with_event<T: IMContextImpl>(
552577
ptr: *mut ffi::GtkIMContext,
553578
eventptr: *mut gdk::ffi::GdkEvent,
@@ -560,3 +585,15 @@ unsafe extern "C" fn im_context_activate_osk_with_event<T: IMContextImpl>(
560585
imp.activate_osk_with_event(event.as_ref().as_ref())
561586
.into_glib()
562587
}
588+
589+
#[cfg(feature = "v4_22")]
590+
unsafe extern "C" fn im_context_invalid_composition<T: IMContextImpl>(
591+
ptr: *mut ffi::GtkIMContext,
592+
stringptr: *const libc::c_char,
593+
) -> glib::ffi::gboolean {
594+
let instance = &*(ptr as *mut T::Instance);
595+
let imp = instance.imp();
596+
let text: Borrowed<GString> = from_glib_borrow(stringptr);
597+
598+
imp.invalid_composition(&text).into_glib()
599+
}

0 commit comments

Comments
 (0)