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 gio; 6 use glib; 7 use glib::object::Cast; 8 use glib::object::IsA; 9 use glib::object::ObjectExt; 10 use glib::signal::connect_raw; 11 use glib::signal::SignalHandlerId; 12 use glib::translate::*; 13 use glib_sys; 14 use gobject_sys; 15 use gtk_sys; 16 use libc; 17 use signal::Inhibit; 18 use std::boxed::Box as Box_; 19 use std::fmt; 20 use std::mem::transmute; 21 use Buildable; 22 use Container; 23 use DirectionType; 24 use MenuDirectionType; 25 use MenuItem; 26 use Widget; 27 28 glib_wrapper! { 29 pub struct MenuShell(Object<gtk_sys::GtkMenuShell, gtk_sys::GtkMenuShellClass, MenuShellClass>) @extends Container, Widget, @implements Buildable; 30 31 match fn { 32 get_type => || gtk_sys::gtk_menu_shell_get_type(), 33 } 34 } 35 36 pub const NONE_MENU_SHELL: Option<&MenuShell> = None; 37 38 pub trait MenuShellExt: 'static { activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool)39 fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool); 40 append<P: IsA<MenuItem>>(&self, child: &P)41 fn append<P: IsA<MenuItem>>(&self, child: &P); 42 bind_model<P: IsA<gio::MenuModel>>( &self, model: Option<&P>, action_namespace: Option<&str>, with_separators: bool, )43 fn bind_model<P: IsA<gio::MenuModel>>( 44 &self, 45 model: Option<&P>, 46 action_namespace: Option<&str>, 47 with_separators: bool, 48 ); 49 cancel(&self)50 fn cancel(&self); 51 deactivate(&self)52 fn deactivate(&self); 53 deselect(&self)54 fn deselect(&self); 55 get_parent_shell(&self) -> Option<Widget>56 fn get_parent_shell(&self) -> Option<Widget>; 57 get_selected_item(&self) -> Option<Widget>58 fn get_selected_item(&self) -> Option<Widget>; 59 get_take_focus(&self) -> bool60 fn get_take_focus(&self) -> bool; 61 insert<P: IsA<Widget>>(&self, child: &P, position: i32)62 fn insert<P: IsA<Widget>>(&self, child: &P, position: i32); 63 prepend<P: IsA<Widget>>(&self, child: &P)64 fn prepend<P: IsA<Widget>>(&self, child: &P); 65 select_first(&self, search_sensitive: bool)66 fn select_first(&self, search_sensitive: bool); 67 select_item<P: IsA<Widget>>(&self, menu_item: &P)68 fn select_item<P: IsA<Widget>>(&self, menu_item: &P); 69 set_take_focus(&self, take_focus: bool)70 fn set_take_focus(&self, take_focus: bool); 71 connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId72 fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId; 73 emit_activate_current(&self, force_hide: bool)74 fn emit_activate_current(&self, force_hide: bool); 75 connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId76 fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 77 emit_cancel(&self)78 fn emit_cancel(&self); 79 connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId80 fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId; 81 emit_cycle_focus(&self, direction: DirectionType)82 fn emit_cycle_focus(&self, direction: DirectionType); 83 connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId84 fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 85 connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId86 fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId; 87 connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>( &self, f: F, ) -> SignalHandlerId88 fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>( 89 &self, 90 f: F, 91 ) -> SignalHandlerId; 92 emit_move_current(&self, direction: MenuDirectionType)93 fn emit_move_current(&self, direction: MenuDirectionType); 94 connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId95 fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>( 96 &self, 97 f: F, 98 ) -> SignalHandlerId; 99 connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId100 fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 101 connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId102 fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 103 } 104 105 impl<O: IsA<MenuShell>> MenuShellExt for O { activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool)106 fn activate_item<P: IsA<Widget>>(&self, menu_item: &P, force_deactivate: bool) { 107 unsafe { 108 gtk_sys::gtk_menu_shell_activate_item( 109 self.as_ref().to_glib_none().0, 110 menu_item.as_ref().to_glib_none().0, 111 force_deactivate.to_glib(), 112 ); 113 } 114 } 115 append<P: IsA<MenuItem>>(&self, child: &P)116 fn append<P: IsA<MenuItem>>(&self, child: &P) { 117 unsafe { 118 gtk_sys::gtk_menu_shell_append( 119 self.as_ref().to_glib_none().0, 120 child.as_ref().to_glib_none().0, 121 ); 122 } 123 } 124 bind_model<P: IsA<gio::MenuModel>>( &self, model: Option<&P>, action_namespace: Option<&str>, with_separators: bool, )125 fn bind_model<P: IsA<gio::MenuModel>>( 126 &self, 127 model: Option<&P>, 128 action_namespace: Option<&str>, 129 with_separators: bool, 130 ) { 131 unsafe { 132 gtk_sys::gtk_menu_shell_bind_model( 133 self.as_ref().to_glib_none().0, 134 model.map(|p| p.as_ref()).to_glib_none().0, 135 action_namespace.to_glib_none().0, 136 with_separators.to_glib(), 137 ); 138 } 139 } 140 cancel(&self)141 fn cancel(&self) { 142 unsafe { 143 gtk_sys::gtk_menu_shell_cancel(self.as_ref().to_glib_none().0); 144 } 145 } 146 deactivate(&self)147 fn deactivate(&self) { 148 unsafe { 149 gtk_sys::gtk_menu_shell_deactivate(self.as_ref().to_glib_none().0); 150 } 151 } 152 deselect(&self)153 fn deselect(&self) { 154 unsafe { 155 gtk_sys::gtk_menu_shell_deselect(self.as_ref().to_glib_none().0); 156 } 157 } 158 get_parent_shell(&self) -> Option<Widget>159 fn get_parent_shell(&self) -> Option<Widget> { 160 unsafe { 161 from_glib_none(gtk_sys::gtk_menu_shell_get_parent_shell( 162 self.as_ref().to_glib_none().0, 163 )) 164 } 165 } 166 get_selected_item(&self) -> Option<Widget>167 fn get_selected_item(&self) -> Option<Widget> { 168 unsafe { 169 from_glib_none(gtk_sys::gtk_menu_shell_get_selected_item( 170 self.as_ref().to_glib_none().0, 171 )) 172 } 173 } 174 get_take_focus(&self) -> bool175 fn get_take_focus(&self) -> bool { 176 unsafe { 177 from_glib(gtk_sys::gtk_menu_shell_get_take_focus( 178 self.as_ref().to_glib_none().0, 179 )) 180 } 181 } 182 insert<P: IsA<Widget>>(&self, child: &P, position: i32)183 fn insert<P: IsA<Widget>>(&self, child: &P, position: i32) { 184 unsafe { 185 gtk_sys::gtk_menu_shell_insert( 186 self.as_ref().to_glib_none().0, 187 child.as_ref().to_glib_none().0, 188 position, 189 ); 190 } 191 } 192 prepend<P: IsA<Widget>>(&self, child: &P)193 fn prepend<P: IsA<Widget>>(&self, child: &P) { 194 unsafe { 195 gtk_sys::gtk_menu_shell_prepend( 196 self.as_ref().to_glib_none().0, 197 child.as_ref().to_glib_none().0, 198 ); 199 } 200 } 201 select_first(&self, search_sensitive: bool)202 fn select_first(&self, search_sensitive: bool) { 203 unsafe { 204 gtk_sys::gtk_menu_shell_select_first( 205 self.as_ref().to_glib_none().0, 206 search_sensitive.to_glib(), 207 ); 208 } 209 } 210 select_item<P: IsA<Widget>>(&self, menu_item: &P)211 fn select_item<P: IsA<Widget>>(&self, menu_item: &P) { 212 unsafe { 213 gtk_sys::gtk_menu_shell_select_item( 214 self.as_ref().to_glib_none().0, 215 menu_item.as_ref().to_glib_none().0, 216 ); 217 } 218 } 219 set_take_focus(&self, take_focus: bool)220 fn set_take_focus(&self, take_focus: bool) { 221 unsafe { 222 gtk_sys::gtk_menu_shell_set_take_focus( 223 self.as_ref().to_glib_none().0, 224 take_focus.to_glib(), 225 ); 226 } 227 } 228 connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId229 fn connect_activate_current<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId { 230 unsafe extern "C" fn activate_current_trampoline<P, F: Fn(&P, bool) + 'static>( 231 this: *mut gtk_sys::GtkMenuShell, 232 force_hide: glib_sys::gboolean, 233 f: glib_sys::gpointer, 234 ) where 235 P: IsA<MenuShell>, 236 { 237 let f: &F = &*(f as *const F); 238 f( 239 &MenuShell::from_glib_borrow(this).unsafe_cast(), 240 from_glib(force_hide), 241 ) 242 } 243 unsafe { 244 let f: Box_<F> = Box_::new(f); 245 connect_raw( 246 self.as_ptr() as *mut _, 247 b"activate-current\0".as_ptr() as *const _, 248 Some(transmute(activate_current_trampoline::<Self, F> as usize)), 249 Box_::into_raw(f), 250 ) 251 } 252 } 253 emit_activate_current(&self, force_hide: bool)254 fn emit_activate_current(&self, force_hide: bool) { 255 let _ = unsafe { 256 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject) 257 .emit("activate-current", &[&force_hide]) 258 .unwrap() 259 }; 260 } 261 connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId262 fn connect_cancel<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 263 unsafe extern "C" fn cancel_trampoline<P, F: Fn(&P) + 'static>( 264 this: *mut gtk_sys::GtkMenuShell, 265 f: glib_sys::gpointer, 266 ) where 267 P: IsA<MenuShell>, 268 { 269 let f: &F = &*(f as *const F); 270 f(&MenuShell::from_glib_borrow(this).unsafe_cast()) 271 } 272 unsafe { 273 let f: Box_<F> = Box_::new(f); 274 connect_raw( 275 self.as_ptr() as *mut _, 276 b"cancel\0".as_ptr() as *const _, 277 Some(transmute(cancel_trampoline::<Self, F> as usize)), 278 Box_::into_raw(f), 279 ) 280 } 281 } 282 emit_cancel(&self)283 fn emit_cancel(&self) { 284 let _ = unsafe { 285 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject) 286 .emit("cancel", &[]) 287 .unwrap() 288 }; 289 } 290 connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId291 fn connect_cycle_focus<F: Fn(&Self, DirectionType) + 'static>(&self, f: F) -> SignalHandlerId { 292 unsafe extern "C" fn cycle_focus_trampoline<P, F: Fn(&P, DirectionType) + 'static>( 293 this: *mut gtk_sys::GtkMenuShell, 294 direction: gtk_sys::GtkDirectionType, 295 f: glib_sys::gpointer, 296 ) where 297 P: IsA<MenuShell>, 298 { 299 let f: &F = &*(f as *const F); 300 f( 301 &MenuShell::from_glib_borrow(this).unsafe_cast(), 302 from_glib(direction), 303 ) 304 } 305 unsafe { 306 let f: Box_<F> = Box_::new(f); 307 connect_raw( 308 self.as_ptr() as *mut _, 309 b"cycle-focus\0".as_ptr() as *const _, 310 Some(transmute(cycle_focus_trampoline::<Self, F> as usize)), 311 Box_::into_raw(f), 312 ) 313 } 314 } 315 emit_cycle_focus(&self, direction: DirectionType)316 fn emit_cycle_focus(&self, direction: DirectionType) { 317 let _ = unsafe { 318 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject) 319 .emit("cycle-focus", &[&direction]) 320 .unwrap() 321 }; 322 } 323 connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId324 fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 325 unsafe extern "C" fn deactivate_trampoline<P, F: Fn(&P) + 'static>( 326 this: *mut gtk_sys::GtkMenuShell, 327 f: glib_sys::gpointer, 328 ) where 329 P: IsA<MenuShell>, 330 { 331 let f: &F = &*(f as *const F); 332 f(&MenuShell::from_glib_borrow(this).unsafe_cast()) 333 } 334 unsafe { 335 let f: Box_<F> = Box_::new(f); 336 connect_raw( 337 self.as_ptr() as *mut _, 338 b"deactivate\0".as_ptr() as *const _, 339 Some(transmute(deactivate_trampoline::<Self, F> as usize)), 340 Box_::into_raw(f), 341 ) 342 } 343 } 344 connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId345 fn connect_insert<F: Fn(&Self, &Widget, i32) + 'static>(&self, f: F) -> SignalHandlerId { 346 unsafe extern "C" fn insert_trampoline<P, F: Fn(&P, &Widget, i32) + 'static>( 347 this: *mut gtk_sys::GtkMenuShell, 348 child: *mut gtk_sys::GtkWidget, 349 position: libc::c_int, 350 f: glib_sys::gpointer, 351 ) where 352 P: IsA<MenuShell>, 353 { 354 let f: &F = &*(f as *const F); 355 f( 356 &MenuShell::from_glib_borrow(this).unsafe_cast(), 357 &from_glib_borrow(child), 358 position, 359 ) 360 } 361 unsafe { 362 let f: Box_<F> = Box_::new(f); 363 connect_raw( 364 self.as_ptr() as *mut _, 365 b"insert\0".as_ptr() as *const _, 366 Some(transmute(insert_trampoline::<Self, F> as usize)), 367 Box_::into_raw(f), 368 ) 369 } 370 } 371 connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>( &self, f: F, ) -> SignalHandlerId372 fn connect_move_current<F: Fn(&Self, MenuDirectionType) + 'static>( 373 &self, 374 f: F, 375 ) -> SignalHandlerId { 376 unsafe extern "C" fn move_current_trampoline<P, F: Fn(&P, MenuDirectionType) + 'static>( 377 this: *mut gtk_sys::GtkMenuShell, 378 direction: gtk_sys::GtkMenuDirectionType, 379 f: glib_sys::gpointer, 380 ) where 381 P: IsA<MenuShell>, 382 { 383 let f: &F = &*(f as *const F); 384 f( 385 &MenuShell::from_glib_borrow(this).unsafe_cast(), 386 from_glib(direction), 387 ) 388 } 389 unsafe { 390 let f: Box_<F> = Box_::new(f); 391 connect_raw( 392 self.as_ptr() as *mut _, 393 b"move-current\0".as_ptr() as *const _, 394 Some(transmute(move_current_trampoline::<Self, F> as usize)), 395 Box_::into_raw(f), 396 ) 397 } 398 } 399 emit_move_current(&self, direction: MenuDirectionType)400 fn emit_move_current(&self, direction: MenuDirectionType) { 401 let _ = unsafe { 402 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject) 403 .emit("move-current", &[&direction]) 404 .unwrap() 405 }; 406 } 407 connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId408 fn connect_move_selected<F: Fn(&Self, i32) -> Inhibit + 'static>( 409 &self, 410 f: F, 411 ) -> SignalHandlerId { 412 unsafe extern "C" fn move_selected_trampoline<P, F: Fn(&P, i32) -> Inhibit + 'static>( 413 this: *mut gtk_sys::GtkMenuShell, 414 distance: libc::c_int, 415 f: glib_sys::gpointer, 416 ) -> glib_sys::gboolean 417 where 418 P: IsA<MenuShell>, 419 { 420 let f: &F = &*(f as *const F); 421 f(&MenuShell::from_glib_borrow(this).unsafe_cast(), distance).to_glib() 422 } 423 unsafe { 424 let f: Box_<F> = Box_::new(f); 425 connect_raw( 426 self.as_ptr() as *mut _, 427 b"move-selected\0".as_ptr() as *const _, 428 Some(transmute(move_selected_trampoline::<Self, F> as usize)), 429 Box_::into_raw(f), 430 ) 431 } 432 } 433 connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId434 fn connect_selection_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 435 unsafe extern "C" fn selection_done_trampoline<P, F: Fn(&P) + 'static>( 436 this: *mut gtk_sys::GtkMenuShell, 437 f: glib_sys::gpointer, 438 ) where 439 P: IsA<MenuShell>, 440 { 441 let f: &F = &*(f as *const F); 442 f(&MenuShell::from_glib_borrow(this).unsafe_cast()) 443 } 444 unsafe { 445 let f: Box_<F> = Box_::new(f); 446 connect_raw( 447 self.as_ptr() as *mut _, 448 b"selection-done\0".as_ptr() as *const _, 449 Some(transmute(selection_done_trampoline::<Self, F> as usize)), 450 Box_::into_raw(f), 451 ) 452 } 453 } 454 connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId455 fn connect_property_take_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 456 unsafe extern "C" fn notify_take_focus_trampoline<P, F: Fn(&P) + 'static>( 457 this: *mut gtk_sys::GtkMenuShell, 458 _param_spec: glib_sys::gpointer, 459 f: glib_sys::gpointer, 460 ) where 461 P: IsA<MenuShell>, 462 { 463 let f: &F = &*(f as *const F); 464 f(&MenuShell::from_glib_borrow(this).unsafe_cast()) 465 } 466 unsafe { 467 let f: Box_<F> = Box_::new(f); 468 connect_raw( 469 self.as_ptr() as *mut _, 470 b"notify::take-focus\0".as_ptr() as *const _, 471 Some(transmute(notify_take_focus_trampoline::<Self, F> as usize)), 472 Box_::into_raw(f), 473 ) 474 } 475 } 476 } 477 478 impl fmt::Display for MenuShell { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result479 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 480 write!(f, "MenuShell") 481 } 482 } 483