@@ -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,7 +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 > ) ;
332
- #[ cfg( any( feature = "v4_10" , docsrs) ) ]
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
+ } ;
333
402
{
334
403
klass. activate_osk = Some ( im_context_activate_osk :: < T > ) ;
335
404
} ;
@@ -506,6 +575,44 @@ unsafe extern "C" fn im_context_set_use_preedit<T: IMContextImpl>(
506
575
imp. set_use_preedit ( from_glib ( use_preedit) )
507
576
}
508
577
578
+ #[ cfg( any( feature = "v4_2" , docsrs) ) ]
579
+ unsafe extern "C" fn im_context_set_surrounding_with_selection < T : IMContextImpl > (
580
+ ptr : * mut ffi:: GtkIMContext ,
581
+ text : * const libc:: c_char ,
582
+ len : i32 ,
583
+ cursor_index : i32 ,
584
+ anchor_index : i32 ,
585
+ ) {
586
+ let instance = & * ( ptr as * mut T :: Instance ) ;
587
+ let imp = instance. imp ( ) ;
588
+
589
+ imp. set_surrounding_with_selection (
590
+ & glib:: GString :: from_glib_none_num ( text, len as usize ) ,
591
+ cursor_index,
592
+ anchor_index,
593
+ )
594
+ }
595
+
596
+ #[ cfg( any( feature = "v4_2" , docsrs) ) ]
597
+ unsafe extern "C" fn im_context_get_surrounding_with_selection < T : IMContextImpl > (
598
+ ptr : * mut ffi:: GtkIMContext ,
599
+ textptr : * mut * mut libc:: c_char ,
600
+ cursor_indexptr : * mut libc:: c_int ,
601
+ anchor_indexptr : * mut libc:: c_int ,
602
+ ) -> glib:: ffi:: gboolean {
603
+ let instance = & * ( ptr as * mut T :: Instance ) ;
604
+ let imp = instance. imp ( ) ;
605
+ match imp. surrounding_with_selection ( ) {
606
+ Some ( ( text, cursor_index, anchor_index) ) => {
607
+ * cursor_indexptr = cursor_index;
608
+ * anchor_indexptr = anchor_index;
609
+ * textptr = text. into_glib_ptr ( ) ;
610
+ true . into_glib ( )
611
+ }
612
+ None => false . into_glib ( ) ,
613
+ }
614
+ }
615
+
509
616
#[ cfg( any( feature = "v4_10" , docsrs) ) ]
510
617
unsafe extern "C" fn im_context_activate_osk < T : IMContextImpl > ( ptr : * mut ffi:: GtkIMContext ) {
511
618
let instance = & * ( ptr as * mut T :: Instance ) ;
0 commit comments