@@ -58,6 +58,16 @@ pub trait IMContextImpl: IMContextImplExt + ObjectImpl {
58
58
fn set_surrounding ( & self , text : & str , cursor_index : i32 ) {
59
59
self . parent_set_surrounding ( text, cursor_index)
60
60
}
61
+ #[ cfg( feature = "v4_2" ) ]
62
+ #[ cfg_attr( docsrs, doc( cfg( feature = "v4_2" ) ) ) ]
63
+ fn set_surrounding_with_selection ( & self , text : & str , cursor_index : i32 , anchor_index : i32 ) {
64
+ self . parent_set_surrounding_with_selection ( text, cursor_index, anchor_index)
65
+ }
66
+ #[ cfg( feature = "v4_2" ) ]
67
+ #[ cfg_attr( docsrs, doc( cfg( feature = "v4_2" ) ) ) ]
68
+ fn surrounding_with_selection ( & self ) -> Option < ( glib:: GString , i32 , i32 ) > {
69
+ self . parent_surrounding_with_selection ( )
70
+ }
61
71
fn set_use_preedit ( & self , use_preedit : bool ) {
62
72
self . parent_set_use_preedit ( use_preedit)
63
73
}
@@ -279,6 +289,59 @@ pub trait IMContextImplExt: ObjectSubclass {
279
289
}
280
290
}
281
291
292
+ #[ cfg( feature = "v4_2" ) ]
293
+ #[ cfg_attr( docsrs, doc( cfg( feature = "v4_2" ) ) ) ]
294
+ fn parent_set_surrounding_with_selection (
295
+ & self ,
296
+ text : & str ,
297
+ cursor_index : i32 ,
298
+ anchor_index : i32 ,
299
+ ) {
300
+ unsafe {
301
+ let data = Self :: type_data ( ) ;
302
+ let parent_class = data. as_ref ( ) . parent_class ( ) as * mut ffi:: GtkIMContextClass ;
303
+ if let Some ( f) = ( * parent_class) . set_surrounding_with_selection {
304
+ f (
305
+ self . obj ( ) . unsafe_cast_ref :: < IMContext > ( ) . to_glib_none ( ) . 0 ,
306
+ text. to_glib_none ( ) . 0 ,
307
+ text. len ( ) as i32 ,
308
+ cursor_index,
309
+ anchor_index,
310
+ )
311
+ }
312
+ }
313
+ }
314
+ #[ cfg( feature = "v4_2" ) ]
315
+ #[ cfg_attr( docsrs, doc( cfg( feature = "v4_2" ) ) ) ]
316
+ fn parent_surrounding_with_selection ( & self ) -> Option < ( glib:: GString , i32 , i32 ) > {
317
+ unsafe {
318
+ let data = Self :: type_data ( ) ;
319
+ let parent_class = data. as_ref ( ) . parent_class ( ) as * mut ffi:: GtkIMContextClass ;
320
+ if let Some ( f) = ( * parent_class) . get_surrounding_with_selection {
321
+ let mut cursor_index = std:: mem:: MaybeUninit :: uninit ( ) ;
322
+ let mut anchor_index = std:: mem:: MaybeUninit :: uninit ( ) ;
323
+ let mut text = std:: ptr:: null_mut ( ) ;
324
+ let res = f (
325
+ self . obj ( ) . unsafe_cast_ref :: < IMContext > ( ) . to_glib_none ( ) . 0 ,
326
+ & mut text,
327
+ cursor_index. as_mut_ptr ( ) ,
328
+ anchor_index. as_mut_ptr ( ) ,
329
+ ) ;
330
+ if from_glib ( res) {
331
+ Some ( (
332
+ glib:: GString :: from_glib_none ( text) ,
333
+ cursor_index. assume_init ( ) ,
334
+ anchor_index. assume_init ( ) ,
335
+ ) )
336
+ } else {
337
+ None
338
+ }
339
+ } else {
340
+ None
341
+ }
342
+ }
343
+ }
344
+
282
345
fn parent_set_use_preedit ( & self , use_preedit : bool ) {
283
346
unsafe {
284
347
let data = Self :: type_data ( ) ;
@@ -329,6 +392,13 @@ unsafe impl<T: IMContextImpl> IsSubclassable<T> for IMContext {
329
392
klass. set_cursor_location = Some ( im_context_set_cursor_location :: < T > ) ;
330
393
klass. set_surrounding = Some ( im_context_set_surrounding :: < T > ) ;
331
394
klass. set_use_preedit = Some ( im_context_set_use_preedit :: < T > ) ;
395
+ #[ cfg( any( feature = "v4_2" , docsrs) ) ]
396
+ {
397
+ klass. set_surrounding_with_selection =
398
+ Some ( im_context_set_surrounding_with_selection :: < T > ) ;
399
+ klass. get_surrounding_with_selection =
400
+ Some ( im_context_get_surrounding_with_selection :: < T > ) ;
401
+ } ;
332
402
#[ cfg( any( feature = "v4_10" , docsrs) ) ]
333
403
{
334
404
klass. activate_osk = Some ( im_context_activate_osk :: < T > ) ;
@@ -506,6 +576,44 @@ unsafe extern "C" fn im_context_set_use_preedit<T: IMContextImpl>(
506
576
imp. set_use_preedit ( from_glib ( use_preedit) )
507
577
}
508
578
579
+ #[ cfg( any( feature = "v4_2" , docsrs) ) ]
580
+ unsafe extern "C" fn im_context_set_surrounding_with_selection < T : IMContextImpl > (
581
+ ptr : * mut ffi:: GtkIMContext ,
582
+ text : * const libc:: c_char ,
583
+ len : i32 ,
584
+ cursor_index : i32 ,
585
+ anchor_index : i32 ,
586
+ ) {
587
+ let instance = & * ( ptr as * mut T :: Instance ) ;
588
+ let imp = instance. imp ( ) ;
589
+
590
+ imp. set_surrounding_with_selection (
591
+ & glib:: GString :: from_glib_none_num ( text, len as usize ) ,
592
+ cursor_index,
593
+ anchor_index,
594
+ )
595
+ }
596
+
597
+ #[ cfg( any( feature = "v4_2" , docsrs) ) ]
598
+ unsafe extern "C" fn im_context_get_surrounding_with_selection < T : IMContextImpl > (
599
+ ptr : * mut ffi:: GtkIMContext ,
600
+ textptr : * mut * mut libc:: c_char ,
601
+ cursor_indexptr : * mut libc:: c_int ,
602
+ anchor_indexptr : * mut libc:: c_int ,
603
+ ) -> glib:: ffi:: gboolean {
604
+ let instance = & * ( ptr as * mut T :: Instance ) ;
605
+ let imp = instance. imp ( ) ;
606
+ match imp. surrounding_with_selection ( ) {
607
+ Some ( ( text, cursor_index, anchor_index) ) => {
608
+ * cursor_indexptr = cursor_index;
609
+ * anchor_indexptr = anchor_index;
610
+ * textptr = text. into_glib_ptr ( ) ;
611
+ true . into_glib ( )
612
+ }
613
+ None => false . into_glib ( ) ,
614
+ }
615
+ }
616
+
509
617
#[ cfg( any( feature = "v4_10" , docsrs) ) ]
510
618
unsafe extern "C" fn im_context_activate_osk < T : IMContextImpl > ( ptr : * mut ffi:: GtkIMContext ) {
511
619
let instance = & * ( ptr as * mut T :: Instance ) ;
0 commit comments