1 // This file was generated by gir (https://github.com/gtk-rs/gir) 2 // from gir-files (https://github.com/gtk-rs/gir-files) 3 // DO NOT EDIT 4 5 use gdk; 6 use glib::object::Cast; 7 use glib::object::IsA; 8 use glib::signal::connect_raw; 9 use glib::signal::SignalHandlerId; 10 use glib::translate::*; 11 use glib::GString; 12 use glib::StaticType; 13 use glib::Value; 14 use glib_sys; 15 use gobject_sys; 16 use gtk_sys; 17 use libc; 18 use pango; 19 use std::boxed::Box as Box_; 20 use std::fmt; 21 use std::mem; 22 use std::mem::transmute; 23 use std::ptr; 24 use InputHints; 25 use InputPurpose; 26 27 glib_wrapper! { 28 pub struct IMContext(Object<gtk_sys::GtkIMContext, gtk_sys::GtkIMContextClass, IMContextClass>); 29 30 match fn { 31 get_type => || gtk_sys::gtk_im_context_get_type(), 32 } 33 } 34 35 pub const NONE_IM_CONTEXT: Option<&IMContext> = None; 36 37 pub trait IMContextExt: 'static { delete_surrounding(&self, offset: i32, n_chars: i32) -> bool38 fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool; 39 filter_keypress(&self, event: &gdk::EventKey) -> bool40 fn filter_keypress(&self, event: &gdk::EventKey) -> bool; 41 focus_in(&self)42 fn focus_in(&self); 43 focus_out(&self)44 fn focus_out(&self); 45 get_preedit_string(&self) -> (GString, pango::AttrList, i32)46 fn get_preedit_string(&self) -> (GString, pango::AttrList, i32); 47 get_surrounding(&self) -> Option<(GString, i32)>48 fn get_surrounding(&self) -> Option<(GString, i32)>; 49 reset(&self)50 fn reset(&self); 51 set_client_window<P: IsA<gdk::Window>>(&self, window: Option<&P>)52 fn set_client_window<P: IsA<gdk::Window>>(&self, window: Option<&P>); 53 set_cursor_location(&self, area: &gdk::Rectangle)54 fn set_cursor_location(&self, area: &gdk::Rectangle); 55 set_surrounding(&self, text: &str, cursor_index: i32)56 fn set_surrounding(&self, text: &str, cursor_index: i32); 57 set_use_preedit(&self, use_preedit: bool)58 fn set_use_preedit(&self, use_preedit: bool); 59 get_property_input_hints(&self) -> InputHints60 fn get_property_input_hints(&self) -> InputHints; 61 set_property_input_hints(&self, input_hints: InputHints)62 fn set_property_input_hints(&self, input_hints: InputHints); 63 get_property_input_purpose(&self) -> InputPurpose64 fn get_property_input_purpose(&self) -> InputPurpose; 65 set_property_input_purpose(&self, input_purpose: InputPurpose)66 fn set_property_input_purpose(&self, input_purpose: InputPurpose); 67 connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId68 fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId; 69 connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId70 fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( 71 &self, 72 f: F, 73 ) -> SignalHandlerId; 74 connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId75 fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 76 connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId77 fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 78 connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId79 fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 80 connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId81 fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(&self, f: F) 82 -> SignalHandlerId; 83 connect_property_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId84 fn connect_property_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 85 connect_property_input_purpose_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId86 fn connect_property_input_purpose_notify<F: Fn(&Self) + 'static>( 87 &self, 88 f: F, 89 ) -> SignalHandlerId; 90 } 91 92 impl<O: IsA<IMContext>> IMContextExt for O { delete_surrounding(&self, offset: i32, n_chars: i32) -> bool93 fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool { 94 unsafe { 95 from_glib(gtk_sys::gtk_im_context_delete_surrounding( 96 self.as_ref().to_glib_none().0, 97 offset, 98 n_chars, 99 )) 100 } 101 } 102 filter_keypress(&self, event: &gdk::EventKey) -> bool103 fn filter_keypress(&self, event: &gdk::EventKey) -> bool { 104 unsafe { 105 from_glib(gtk_sys::gtk_im_context_filter_keypress( 106 self.as_ref().to_glib_none().0, 107 mut_override(event.to_glib_none().0), 108 )) 109 } 110 } 111 focus_in(&self)112 fn focus_in(&self) { 113 unsafe { 114 gtk_sys::gtk_im_context_focus_in(self.as_ref().to_glib_none().0); 115 } 116 } 117 focus_out(&self)118 fn focus_out(&self) { 119 unsafe { 120 gtk_sys::gtk_im_context_focus_out(self.as_ref().to_glib_none().0); 121 } 122 } 123 get_preedit_string(&self) -> (GString, pango::AttrList, i32)124 fn get_preedit_string(&self) -> (GString, pango::AttrList, i32) { 125 unsafe { 126 let mut str = ptr::null_mut(); 127 let mut attrs = ptr::null_mut(); 128 let mut cursor_pos = mem::MaybeUninit::uninit(); 129 gtk_sys::gtk_im_context_get_preedit_string( 130 self.as_ref().to_glib_none().0, 131 &mut str, 132 &mut attrs, 133 cursor_pos.as_mut_ptr(), 134 ); 135 let cursor_pos = cursor_pos.assume_init(); 136 (from_glib_full(str), from_glib_full(attrs), cursor_pos) 137 } 138 } 139 get_surrounding(&self) -> Option<(GString, i32)>140 fn get_surrounding(&self) -> Option<(GString, i32)> { 141 unsafe { 142 let mut text = ptr::null_mut(); 143 let mut cursor_index = mem::MaybeUninit::uninit(); 144 let ret = from_glib(gtk_sys::gtk_im_context_get_surrounding( 145 self.as_ref().to_glib_none().0, 146 &mut text, 147 cursor_index.as_mut_ptr(), 148 )); 149 let cursor_index = cursor_index.assume_init(); 150 if ret { 151 Some((from_glib_full(text), cursor_index)) 152 } else { 153 None 154 } 155 } 156 } 157 reset(&self)158 fn reset(&self) { 159 unsafe { 160 gtk_sys::gtk_im_context_reset(self.as_ref().to_glib_none().0); 161 } 162 } 163 set_client_window<P: IsA<gdk::Window>>(&self, window: Option<&P>)164 fn set_client_window<P: IsA<gdk::Window>>(&self, window: Option<&P>) { 165 unsafe { 166 gtk_sys::gtk_im_context_set_client_window( 167 self.as_ref().to_glib_none().0, 168 window.map(|p| p.as_ref()).to_glib_none().0, 169 ); 170 } 171 } 172 set_cursor_location(&self, area: &gdk::Rectangle)173 fn set_cursor_location(&self, area: &gdk::Rectangle) { 174 unsafe { 175 gtk_sys::gtk_im_context_set_cursor_location( 176 self.as_ref().to_glib_none().0, 177 area.to_glib_none().0, 178 ); 179 } 180 } 181 set_surrounding(&self, text: &str, cursor_index: i32)182 fn set_surrounding(&self, text: &str, cursor_index: i32) { 183 let len = text.len() as i32; 184 unsafe { 185 gtk_sys::gtk_im_context_set_surrounding( 186 self.as_ref().to_glib_none().0, 187 text.to_glib_none().0, 188 len, 189 cursor_index, 190 ); 191 } 192 } 193 set_use_preedit(&self, use_preedit: bool)194 fn set_use_preedit(&self, use_preedit: bool) { 195 unsafe { 196 gtk_sys::gtk_im_context_set_use_preedit( 197 self.as_ref().to_glib_none().0, 198 use_preedit.to_glib(), 199 ); 200 } 201 } 202 get_property_input_hints(&self) -> InputHints203 fn get_property_input_hints(&self) -> InputHints { 204 unsafe { 205 let mut value = Value::from_type(<InputHints as StaticType>::static_type()); 206 gobject_sys::g_object_get_property( 207 self.to_glib_none().0 as *mut gobject_sys::GObject, 208 b"input-hints\0".as_ptr() as *const _, 209 value.to_glib_none_mut().0, 210 ); 211 value 212 .get() 213 .expect("Return Value for property `input-hints` getter") 214 .unwrap() 215 } 216 } 217 set_property_input_hints(&self, input_hints: InputHints)218 fn set_property_input_hints(&self, input_hints: InputHints) { 219 unsafe { 220 gobject_sys::g_object_set_property( 221 self.to_glib_none().0 as *mut gobject_sys::GObject, 222 b"input-hints\0".as_ptr() as *const _, 223 Value::from(&input_hints).to_glib_none().0, 224 ); 225 } 226 } 227 get_property_input_purpose(&self) -> InputPurpose228 fn get_property_input_purpose(&self) -> InputPurpose { 229 unsafe { 230 let mut value = Value::from_type(<InputPurpose as StaticType>::static_type()); 231 gobject_sys::g_object_get_property( 232 self.to_glib_none().0 as *mut gobject_sys::GObject, 233 b"input-purpose\0".as_ptr() as *const _, 234 value.to_glib_none_mut().0, 235 ); 236 value 237 .get() 238 .expect("Return Value for property `input-purpose` getter") 239 .unwrap() 240 } 241 } 242 set_property_input_purpose(&self, input_purpose: InputPurpose)243 fn set_property_input_purpose(&self, input_purpose: InputPurpose) { 244 unsafe { 245 gobject_sys::g_object_set_property( 246 self.to_glib_none().0 as *mut gobject_sys::GObject, 247 b"input-purpose\0".as_ptr() as *const _, 248 Value::from(&input_purpose).to_glib_none().0, 249 ); 250 } 251 } 252 connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId253 fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId { 254 unsafe extern "C" fn commit_trampoline<P, F: Fn(&P, &str) + 'static>( 255 this: *mut gtk_sys::GtkIMContext, 256 str: *mut libc::c_char, 257 f: glib_sys::gpointer, 258 ) where 259 P: IsA<IMContext>, 260 { 261 let f: &F = &*(f as *const F); 262 f( 263 &IMContext::from_glib_borrow(this).unsafe_cast(), 264 &GString::from_glib_borrow(str), 265 ) 266 } 267 unsafe { 268 let f: Box_<F> = Box_::new(f); 269 connect_raw( 270 self.as_ptr() as *mut _, 271 b"commit\0".as_ptr() as *const _, 272 Some(transmute(commit_trampoline::<Self, F> as usize)), 273 Box_::into_raw(f), 274 ) 275 } 276 } 277 connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId278 fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( 279 &self, 280 f: F, 281 ) -> SignalHandlerId { 282 unsafe extern "C" fn delete_surrounding_trampoline< 283 P, 284 F: Fn(&P, i32, i32) -> bool + 'static, 285 >( 286 this: *mut gtk_sys::GtkIMContext, 287 offset: libc::c_int, 288 n_chars: libc::c_int, 289 f: glib_sys::gpointer, 290 ) -> glib_sys::gboolean 291 where 292 P: IsA<IMContext>, 293 { 294 let f: &F = &*(f as *const F); 295 f( 296 &IMContext::from_glib_borrow(this).unsafe_cast(), 297 offset, 298 n_chars, 299 ) 300 .to_glib() 301 } 302 unsafe { 303 let f: Box_<F> = Box_::new(f); 304 connect_raw( 305 self.as_ptr() as *mut _, 306 b"delete-surrounding\0".as_ptr() as *const _, 307 Some(transmute(delete_surrounding_trampoline::<Self, F> as usize)), 308 Box_::into_raw(f), 309 ) 310 } 311 } 312 connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId313 fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 314 unsafe extern "C" fn preedit_changed_trampoline<P, F: Fn(&P) + 'static>( 315 this: *mut gtk_sys::GtkIMContext, 316 f: glib_sys::gpointer, 317 ) where 318 P: IsA<IMContext>, 319 { 320 let f: &F = &*(f as *const F); 321 f(&IMContext::from_glib_borrow(this).unsafe_cast()) 322 } 323 unsafe { 324 let f: Box_<F> = Box_::new(f); 325 connect_raw( 326 self.as_ptr() as *mut _, 327 b"preedit-changed\0".as_ptr() as *const _, 328 Some(transmute(preedit_changed_trampoline::<Self, F> as usize)), 329 Box_::into_raw(f), 330 ) 331 } 332 } 333 connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId334 fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 335 unsafe extern "C" fn preedit_end_trampoline<P, F: Fn(&P) + 'static>( 336 this: *mut gtk_sys::GtkIMContext, 337 f: glib_sys::gpointer, 338 ) where 339 P: IsA<IMContext>, 340 { 341 let f: &F = &*(f as *const F); 342 f(&IMContext::from_glib_borrow(this).unsafe_cast()) 343 } 344 unsafe { 345 let f: Box_<F> = Box_::new(f); 346 connect_raw( 347 self.as_ptr() as *mut _, 348 b"preedit-end\0".as_ptr() as *const _, 349 Some(transmute(preedit_end_trampoline::<Self, F> as usize)), 350 Box_::into_raw(f), 351 ) 352 } 353 } 354 connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId355 fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 356 unsafe extern "C" fn preedit_start_trampoline<P, F: Fn(&P) + 'static>( 357 this: *mut gtk_sys::GtkIMContext, 358 f: glib_sys::gpointer, 359 ) where 360 P: IsA<IMContext>, 361 { 362 let f: &F = &*(f as *const F); 363 f(&IMContext::from_glib_borrow(this).unsafe_cast()) 364 } 365 unsafe { 366 let f: Box_<F> = Box_::new(f); 367 connect_raw( 368 self.as_ptr() as *mut _, 369 b"preedit-start\0".as_ptr() as *const _, 370 Some(transmute(preedit_start_trampoline::<Self, F> as usize)), 371 Box_::into_raw(f), 372 ) 373 } 374 } 375 connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId376 fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>( 377 &self, 378 f: F, 379 ) -> SignalHandlerId { 380 unsafe extern "C" fn retrieve_surrounding_trampoline<P, F: Fn(&P) -> bool + 'static>( 381 this: *mut gtk_sys::GtkIMContext, 382 f: glib_sys::gpointer, 383 ) -> glib_sys::gboolean 384 where 385 P: IsA<IMContext>, 386 { 387 let f: &F = &*(f as *const F); 388 f(&IMContext::from_glib_borrow(this).unsafe_cast()).to_glib() 389 } 390 unsafe { 391 let f: Box_<F> = Box_::new(f); 392 connect_raw( 393 self.as_ptr() as *mut _, 394 b"retrieve-surrounding\0".as_ptr() as *const _, 395 Some(transmute( 396 retrieve_surrounding_trampoline::<Self, F> as usize, 397 )), 398 Box_::into_raw(f), 399 ) 400 } 401 } 402 connect_property_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId403 fn connect_property_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 404 unsafe extern "C" fn notify_input_hints_trampoline<P, F: Fn(&P) + 'static>( 405 this: *mut gtk_sys::GtkIMContext, 406 _param_spec: glib_sys::gpointer, 407 f: glib_sys::gpointer, 408 ) where 409 P: IsA<IMContext>, 410 { 411 let f: &F = &*(f as *const F); 412 f(&IMContext::from_glib_borrow(this).unsafe_cast()) 413 } 414 unsafe { 415 let f: Box_<F> = Box_::new(f); 416 connect_raw( 417 self.as_ptr() as *mut _, 418 b"notify::input-hints\0".as_ptr() as *const _, 419 Some(transmute(notify_input_hints_trampoline::<Self, F> as usize)), 420 Box_::into_raw(f), 421 ) 422 } 423 } 424 connect_property_input_purpose_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId425 fn connect_property_input_purpose_notify<F: Fn(&Self) + 'static>( 426 &self, 427 f: F, 428 ) -> SignalHandlerId { 429 unsafe extern "C" fn notify_input_purpose_trampoline<P, F: Fn(&P) + 'static>( 430 this: *mut gtk_sys::GtkIMContext, 431 _param_spec: glib_sys::gpointer, 432 f: glib_sys::gpointer, 433 ) where 434 P: IsA<IMContext>, 435 { 436 let f: &F = &*(f as *const F); 437 f(&IMContext::from_glib_borrow(this).unsafe_cast()) 438 } 439 unsafe { 440 let f: Box_<F> = Box_::new(f); 441 connect_raw( 442 self.as_ptr() as *mut _, 443 b"notify::input-purpose\0".as_ptr() as *const _, 444 Some(transmute( 445 notify_input_purpose_trampoline::<Self, F> as usize, 446 )), 447 Box_::into_raw(f), 448 ) 449 } 450 } 451 } 452 453 impl fmt::Display for IMContext { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result454 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 455 write!(f, "IMContext") 456 } 457 } 458