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::StaticType; 12 use glib::ToValue; 13 use glib_sys; 14 use gtk_sys; 15 use std::boxed::Box as Box_; 16 use std::fmt; 17 use std::mem::transmute; 18 use xlib; 19 use Align; 20 use Buildable; 21 use Container; 22 use ResizeMode; 23 use Widget; 24 25 glib_wrapper! { 26 pub struct Socket(Object<gtk_sys::GtkSocket, gtk_sys::GtkSocketClass, SocketClass>) @extends Container, Widget, @implements Buildable; 27 28 match fn { 29 get_type => || gtk_sys::gtk_socket_get_type(), 30 } 31 } 32 33 impl Socket { new() -> Socket34 pub fn new() -> Socket { 35 assert_initialized_main_thread!(); 36 unsafe { Widget::from_glib_none(gtk_sys::gtk_socket_new()).unsafe_cast() } 37 } 38 } 39 40 impl Default for Socket { default() -> Self41 fn default() -> Self { 42 Self::new() 43 } 44 } 45 46 #[derive(Clone, Default)] 47 pub struct SocketBuilder { 48 border_width: Option<u32>, 49 child: Option<Widget>, 50 resize_mode: Option<ResizeMode>, 51 app_paintable: Option<bool>, 52 can_default: Option<bool>, 53 can_focus: Option<bool>, 54 events: Option<gdk::EventMask>, 55 expand: Option<bool>, 56 #[cfg(any(feature = "v3_20", feature = "dox"))] 57 focus_on_click: Option<bool>, 58 halign: Option<Align>, 59 has_default: Option<bool>, 60 has_focus: Option<bool>, 61 has_tooltip: Option<bool>, 62 height_request: Option<i32>, 63 hexpand: Option<bool>, 64 hexpand_set: Option<bool>, 65 is_focus: Option<bool>, 66 margin: Option<i32>, 67 margin_bottom: Option<i32>, 68 margin_end: Option<i32>, 69 margin_start: Option<i32>, 70 margin_top: Option<i32>, 71 name: Option<String>, 72 no_show_all: Option<bool>, 73 opacity: Option<f64>, 74 parent: Option<Container>, 75 receives_default: Option<bool>, 76 sensitive: Option<bool>, 77 tooltip_markup: Option<String>, 78 tooltip_text: Option<String>, 79 valign: Option<Align>, 80 vexpand: Option<bool>, 81 vexpand_set: Option<bool>, 82 visible: Option<bool>, 83 width_request: Option<i32>, 84 } 85 86 impl SocketBuilder { new() -> Self87 pub fn new() -> Self { 88 Self::default() 89 } 90 build(self) -> Socket91 pub fn build(self) -> Socket { 92 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 93 if let Some(ref border_width) = self.border_width { 94 properties.push(("border-width", border_width)); 95 } 96 if let Some(ref child) = self.child { 97 properties.push(("child", child)); 98 } 99 if let Some(ref resize_mode) = self.resize_mode { 100 properties.push(("resize-mode", resize_mode)); 101 } 102 if let Some(ref app_paintable) = self.app_paintable { 103 properties.push(("app-paintable", app_paintable)); 104 } 105 if let Some(ref can_default) = self.can_default { 106 properties.push(("can-default", can_default)); 107 } 108 if let Some(ref can_focus) = self.can_focus { 109 properties.push(("can-focus", can_focus)); 110 } 111 if let Some(ref events) = self.events { 112 properties.push(("events", events)); 113 } 114 if let Some(ref expand) = self.expand { 115 properties.push(("expand", expand)); 116 } 117 #[cfg(any(feature = "v3_20", feature = "dox"))] 118 { 119 if let Some(ref focus_on_click) = self.focus_on_click { 120 properties.push(("focus-on-click", focus_on_click)); 121 } 122 } 123 if let Some(ref halign) = self.halign { 124 properties.push(("halign", halign)); 125 } 126 if let Some(ref has_default) = self.has_default { 127 properties.push(("has-default", has_default)); 128 } 129 if let Some(ref has_focus) = self.has_focus { 130 properties.push(("has-focus", has_focus)); 131 } 132 if let Some(ref has_tooltip) = self.has_tooltip { 133 properties.push(("has-tooltip", has_tooltip)); 134 } 135 if let Some(ref height_request) = self.height_request { 136 properties.push(("height-request", height_request)); 137 } 138 if let Some(ref hexpand) = self.hexpand { 139 properties.push(("hexpand", hexpand)); 140 } 141 if let Some(ref hexpand_set) = self.hexpand_set { 142 properties.push(("hexpand-set", hexpand_set)); 143 } 144 if let Some(ref is_focus) = self.is_focus { 145 properties.push(("is-focus", is_focus)); 146 } 147 if let Some(ref margin) = self.margin { 148 properties.push(("margin", margin)); 149 } 150 if let Some(ref margin_bottom) = self.margin_bottom { 151 properties.push(("margin-bottom", margin_bottom)); 152 } 153 if let Some(ref margin_end) = self.margin_end { 154 properties.push(("margin-end", margin_end)); 155 } 156 if let Some(ref margin_start) = self.margin_start { 157 properties.push(("margin-start", margin_start)); 158 } 159 if let Some(ref margin_top) = self.margin_top { 160 properties.push(("margin-top", margin_top)); 161 } 162 if let Some(ref name) = self.name { 163 properties.push(("name", name)); 164 } 165 if let Some(ref no_show_all) = self.no_show_all { 166 properties.push(("no-show-all", no_show_all)); 167 } 168 if let Some(ref opacity) = self.opacity { 169 properties.push(("opacity", opacity)); 170 } 171 if let Some(ref parent) = self.parent { 172 properties.push(("parent", parent)); 173 } 174 if let Some(ref receives_default) = self.receives_default { 175 properties.push(("receives-default", receives_default)); 176 } 177 if let Some(ref sensitive) = self.sensitive { 178 properties.push(("sensitive", sensitive)); 179 } 180 if let Some(ref tooltip_markup) = self.tooltip_markup { 181 properties.push(("tooltip-markup", tooltip_markup)); 182 } 183 if let Some(ref tooltip_text) = self.tooltip_text { 184 properties.push(("tooltip-text", tooltip_text)); 185 } 186 if let Some(ref valign) = self.valign { 187 properties.push(("valign", valign)); 188 } 189 if let Some(ref vexpand) = self.vexpand { 190 properties.push(("vexpand", vexpand)); 191 } 192 if let Some(ref vexpand_set) = self.vexpand_set { 193 properties.push(("vexpand-set", vexpand_set)); 194 } 195 if let Some(ref visible) = self.visible { 196 properties.push(("visible", visible)); 197 } 198 if let Some(ref width_request) = self.width_request { 199 properties.push(("width-request", width_request)); 200 } 201 glib::Object::new(Socket::static_type(), &properties) 202 .expect("object new") 203 .downcast() 204 .expect("downcast") 205 } 206 border_width(mut self, border_width: u32) -> Self207 pub fn border_width(mut self, border_width: u32) -> Self { 208 self.border_width = Some(border_width); 209 self 210 } 211 child<P: IsA<Widget>>(mut self, child: &P) -> Self212 pub fn child<P: IsA<Widget>>(mut self, child: &P) -> Self { 213 self.child = Some(child.clone().upcast()); 214 self 215 } 216 resize_mode(mut self, resize_mode: ResizeMode) -> Self217 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self { 218 self.resize_mode = Some(resize_mode); 219 self 220 } 221 app_paintable(mut self, app_paintable: bool) -> Self222 pub fn app_paintable(mut self, app_paintable: bool) -> Self { 223 self.app_paintable = Some(app_paintable); 224 self 225 } 226 can_default(mut self, can_default: bool) -> Self227 pub fn can_default(mut self, can_default: bool) -> Self { 228 self.can_default = Some(can_default); 229 self 230 } 231 can_focus(mut self, can_focus: bool) -> Self232 pub fn can_focus(mut self, can_focus: bool) -> Self { 233 self.can_focus = Some(can_focus); 234 self 235 } 236 events(mut self, events: gdk::EventMask) -> Self237 pub fn events(mut self, events: gdk::EventMask) -> Self { 238 self.events = Some(events); 239 self 240 } 241 expand(mut self, expand: bool) -> Self242 pub fn expand(mut self, expand: bool) -> Self { 243 self.expand = Some(expand); 244 self 245 } 246 247 #[cfg(any(feature = "v3_20", feature = "dox"))] focus_on_click(mut self, focus_on_click: bool) -> Self248 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self { 249 self.focus_on_click = Some(focus_on_click); 250 self 251 } 252 halign(mut self, halign: Align) -> Self253 pub fn halign(mut self, halign: Align) -> Self { 254 self.halign = Some(halign); 255 self 256 } 257 has_default(mut self, has_default: bool) -> Self258 pub fn has_default(mut self, has_default: bool) -> Self { 259 self.has_default = Some(has_default); 260 self 261 } 262 has_focus(mut self, has_focus: bool) -> Self263 pub fn has_focus(mut self, has_focus: bool) -> Self { 264 self.has_focus = Some(has_focus); 265 self 266 } 267 has_tooltip(mut self, has_tooltip: bool) -> Self268 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self { 269 self.has_tooltip = Some(has_tooltip); 270 self 271 } 272 height_request(mut self, height_request: i32) -> Self273 pub fn height_request(mut self, height_request: i32) -> Self { 274 self.height_request = Some(height_request); 275 self 276 } 277 hexpand(mut self, hexpand: bool) -> Self278 pub fn hexpand(mut self, hexpand: bool) -> Self { 279 self.hexpand = Some(hexpand); 280 self 281 } 282 hexpand_set(mut self, hexpand_set: bool) -> Self283 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self { 284 self.hexpand_set = Some(hexpand_set); 285 self 286 } 287 is_focus(mut self, is_focus: bool) -> Self288 pub fn is_focus(mut self, is_focus: bool) -> Self { 289 self.is_focus = Some(is_focus); 290 self 291 } 292 margin(mut self, margin: i32) -> Self293 pub fn margin(mut self, margin: i32) -> Self { 294 self.margin = Some(margin); 295 self 296 } 297 margin_bottom(mut self, margin_bottom: i32) -> Self298 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self { 299 self.margin_bottom = Some(margin_bottom); 300 self 301 } 302 margin_end(mut self, margin_end: i32) -> Self303 pub fn margin_end(mut self, margin_end: i32) -> Self { 304 self.margin_end = Some(margin_end); 305 self 306 } 307 margin_start(mut self, margin_start: i32) -> Self308 pub fn margin_start(mut self, margin_start: i32) -> Self { 309 self.margin_start = Some(margin_start); 310 self 311 } 312 margin_top(mut self, margin_top: i32) -> Self313 pub fn margin_top(mut self, margin_top: i32) -> Self { 314 self.margin_top = Some(margin_top); 315 self 316 } 317 name(mut self, name: &str) -> Self318 pub fn name(mut self, name: &str) -> Self { 319 self.name = Some(name.to_string()); 320 self 321 } 322 no_show_all(mut self, no_show_all: bool) -> Self323 pub fn no_show_all(mut self, no_show_all: bool) -> Self { 324 self.no_show_all = Some(no_show_all); 325 self 326 } 327 opacity(mut self, opacity: f64) -> Self328 pub fn opacity(mut self, opacity: f64) -> Self { 329 self.opacity = Some(opacity); 330 self 331 } 332 parent<P: IsA<Container>>(mut self, parent: &P) -> Self333 pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self { 334 self.parent = Some(parent.clone().upcast()); 335 self 336 } 337 receives_default(mut self, receives_default: bool) -> Self338 pub fn receives_default(mut self, receives_default: bool) -> Self { 339 self.receives_default = Some(receives_default); 340 self 341 } 342 sensitive(mut self, sensitive: bool) -> Self343 pub fn sensitive(mut self, sensitive: bool) -> Self { 344 self.sensitive = Some(sensitive); 345 self 346 } 347 tooltip_markup(mut self, tooltip_markup: &str) -> Self348 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self { 349 self.tooltip_markup = Some(tooltip_markup.to_string()); 350 self 351 } 352 tooltip_text(mut self, tooltip_text: &str) -> Self353 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self { 354 self.tooltip_text = Some(tooltip_text.to_string()); 355 self 356 } 357 valign(mut self, valign: Align) -> Self358 pub fn valign(mut self, valign: Align) -> Self { 359 self.valign = Some(valign); 360 self 361 } 362 vexpand(mut self, vexpand: bool) -> Self363 pub fn vexpand(mut self, vexpand: bool) -> Self { 364 self.vexpand = Some(vexpand); 365 self 366 } 367 vexpand_set(mut self, vexpand_set: bool) -> Self368 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self { 369 self.vexpand_set = Some(vexpand_set); 370 self 371 } 372 visible(mut self, visible: bool) -> Self373 pub fn visible(mut self, visible: bool) -> Self { 374 self.visible = Some(visible); 375 self 376 } 377 width_request(mut self, width_request: i32) -> Self378 pub fn width_request(mut self, width_request: i32) -> Self { 379 self.width_request = Some(width_request); 380 self 381 } 382 } 383 384 pub const NONE_SOCKET: Option<&Socket> = None; 385 386 pub trait GtkSocketExt: 'static { add_id(&self, window: xlib::Window)387 fn add_id(&self, window: xlib::Window); 388 get_id(&self) -> xlib::Window389 fn get_id(&self) -> xlib::Window; 390 get_plug_window(&self) -> Option<gdk::Window>391 fn get_plug_window(&self) -> Option<gdk::Window>; 392 connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId393 fn connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 394 connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId395 fn connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId; 396 } 397 398 impl<O: IsA<Socket>> GtkSocketExt for O { add_id(&self, window: xlib::Window)399 fn add_id(&self, window: xlib::Window) { 400 unsafe { 401 gtk_sys::gtk_socket_add_id(self.as_ref().to_glib_none().0, window); 402 } 403 } 404 get_id(&self) -> xlib::Window405 fn get_id(&self) -> xlib::Window { 406 unsafe { gtk_sys::gtk_socket_get_id(self.as_ref().to_glib_none().0) } 407 } 408 get_plug_window(&self) -> Option<gdk::Window>409 fn get_plug_window(&self) -> Option<gdk::Window> { 410 unsafe { 411 from_glib_none(gtk_sys::gtk_socket_get_plug_window( 412 self.as_ref().to_glib_none().0, 413 )) 414 } 415 } 416 connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId417 fn connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 418 unsafe extern "C" fn plug_added_trampoline<P, F: Fn(&P) + 'static>( 419 this: *mut gtk_sys::GtkSocket, 420 f: glib_sys::gpointer, 421 ) where 422 P: IsA<Socket>, 423 { 424 let f: &F = &*(f as *const F); 425 f(&Socket::from_glib_borrow(this).unsafe_cast()) 426 } 427 unsafe { 428 let f: Box_<F> = Box_::new(f); 429 connect_raw( 430 self.as_ptr() as *mut _, 431 b"plug-added\0".as_ptr() as *const _, 432 Some(transmute(plug_added_trampoline::<Self, F> as usize)), 433 Box_::into_raw(f), 434 ) 435 } 436 } 437 connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId438 fn connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId { 439 unsafe extern "C" fn plug_removed_trampoline<P, F: Fn(&P) -> bool + 'static>( 440 this: *mut gtk_sys::GtkSocket, 441 f: glib_sys::gpointer, 442 ) -> glib_sys::gboolean 443 where 444 P: IsA<Socket>, 445 { 446 let f: &F = &*(f as *const F); 447 f(&Socket::from_glib_borrow(this).unsafe_cast()).to_glib() 448 } 449 unsafe { 450 let f: Box_<F> = Box_::new(f); 451 connect_raw( 452 self.as_ptr() as *mut _, 453 b"plug-removed\0".as_ptr() as *const _, 454 Some(transmute(plug_removed_trampoline::<Self, F> as usize)), 455 Box_::into_raw(f), 456 ) 457 } 458 } 459 } 460 461 impl fmt::Display for Socket { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result462 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 463 write!(f, "Socket") 464 } 465 } 466