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 crate::Align; 6 use crate::Bin; 7 use crate::Buildable; 8 use crate::Container; 9 use crate::Entry; 10 use crate::ResizeMode; 11 use crate::Widget; 12 use glib::object::Cast; 13 use glib::object::IsA; 14 use glib::signal::connect_raw; 15 use glib::signal::SignalHandlerId; 16 use glib::translate::*; 17 use glib::StaticType; 18 use glib::ToValue; 19 use std::boxed::Box as Box_; 20 use std::fmt; 21 use std::mem::transmute; 22 23 glib::wrapper! { 24 #[doc(alias = "GtkSearchBar")] 25 pub struct SearchBar(Object<ffi::GtkSearchBar, ffi::GtkSearchBarClass>) @extends Bin, Container, Widget, @implements Buildable; 26 27 match fn { 28 type_ => || ffi::gtk_search_bar_get_type(), 29 } 30 } 31 32 impl SearchBar { 33 #[doc(alias = "gtk_search_bar_new")] new() -> SearchBar34 pub fn new() -> SearchBar { 35 assert_initialized_main_thread!(); 36 unsafe { Widget::from_glib_none(ffi::gtk_search_bar_new()).unsafe_cast() } 37 } 38 39 // rustdoc-stripper-ignore-next 40 /// Creates a new builder-pattern struct instance to construct [`SearchBar`] objects. 41 /// 42 /// This method returns an instance of [`SearchBarBuilder`] which can be used to create [`SearchBar`] objects. builder() -> SearchBarBuilder43 pub fn builder() -> SearchBarBuilder { 44 SearchBarBuilder::default() 45 } 46 } 47 48 impl Default for SearchBar { default() -> Self49 fn default() -> Self { 50 Self::new() 51 } 52 } 53 54 #[derive(Clone, Default)] 55 // rustdoc-stripper-ignore-next 56 /// A [builder-pattern] type to construct [`SearchBar`] objects. 57 /// 58 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 59 pub struct SearchBarBuilder { 60 search_mode_enabled: Option<bool>, 61 show_close_button: Option<bool>, 62 border_width: Option<u32>, 63 child: Option<Widget>, 64 resize_mode: Option<ResizeMode>, 65 app_paintable: Option<bool>, 66 can_default: Option<bool>, 67 can_focus: Option<bool>, 68 events: Option<gdk::EventMask>, 69 expand: Option<bool>, 70 #[cfg(any(feature = "v3_20", feature = "dox"))] 71 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 72 focus_on_click: Option<bool>, 73 halign: Option<Align>, 74 has_default: Option<bool>, 75 has_focus: Option<bool>, 76 has_tooltip: Option<bool>, 77 height_request: Option<i32>, 78 hexpand: Option<bool>, 79 hexpand_set: Option<bool>, 80 is_focus: Option<bool>, 81 margin: Option<i32>, 82 margin_bottom: Option<i32>, 83 margin_end: Option<i32>, 84 margin_start: Option<i32>, 85 margin_top: Option<i32>, 86 name: Option<String>, 87 no_show_all: Option<bool>, 88 opacity: Option<f64>, 89 parent: Option<Container>, 90 receives_default: Option<bool>, 91 sensitive: Option<bool>, 92 tooltip_markup: Option<String>, 93 tooltip_text: Option<String>, 94 valign: Option<Align>, 95 vexpand: Option<bool>, 96 vexpand_set: Option<bool>, 97 visible: Option<bool>, 98 width_request: Option<i32>, 99 } 100 101 impl SearchBarBuilder { 102 // rustdoc-stripper-ignore-next 103 /// Create a new [`SearchBarBuilder`]. new() -> Self104 pub fn new() -> Self { 105 Self::default() 106 } 107 108 // rustdoc-stripper-ignore-next 109 /// Build the [`SearchBar`]. build(self) -> SearchBar110 pub fn build(self) -> SearchBar { 111 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 112 if let Some(ref search_mode_enabled) = self.search_mode_enabled { 113 properties.push(("search-mode-enabled", search_mode_enabled)); 114 } 115 if let Some(ref show_close_button) = self.show_close_button { 116 properties.push(("show-close-button", show_close_button)); 117 } 118 if let Some(ref border_width) = self.border_width { 119 properties.push(("border-width", border_width)); 120 } 121 if let Some(ref child) = self.child { 122 properties.push(("child", child)); 123 } 124 if let Some(ref resize_mode) = self.resize_mode { 125 properties.push(("resize-mode", resize_mode)); 126 } 127 if let Some(ref app_paintable) = self.app_paintable { 128 properties.push(("app-paintable", app_paintable)); 129 } 130 if let Some(ref can_default) = self.can_default { 131 properties.push(("can-default", can_default)); 132 } 133 if let Some(ref can_focus) = self.can_focus { 134 properties.push(("can-focus", can_focus)); 135 } 136 if let Some(ref events) = self.events { 137 properties.push(("events", events)); 138 } 139 if let Some(ref expand) = self.expand { 140 properties.push(("expand", expand)); 141 } 142 #[cfg(any(feature = "v3_20", feature = "dox"))] 143 if let Some(ref focus_on_click) = self.focus_on_click { 144 properties.push(("focus-on-click", focus_on_click)); 145 } 146 if let Some(ref halign) = self.halign { 147 properties.push(("halign", halign)); 148 } 149 if let Some(ref has_default) = self.has_default { 150 properties.push(("has-default", has_default)); 151 } 152 if let Some(ref has_focus) = self.has_focus { 153 properties.push(("has-focus", has_focus)); 154 } 155 if let Some(ref has_tooltip) = self.has_tooltip { 156 properties.push(("has-tooltip", has_tooltip)); 157 } 158 if let Some(ref height_request) = self.height_request { 159 properties.push(("height-request", height_request)); 160 } 161 if let Some(ref hexpand) = self.hexpand { 162 properties.push(("hexpand", hexpand)); 163 } 164 if let Some(ref hexpand_set) = self.hexpand_set { 165 properties.push(("hexpand-set", hexpand_set)); 166 } 167 if let Some(ref is_focus) = self.is_focus { 168 properties.push(("is-focus", is_focus)); 169 } 170 if let Some(ref margin) = self.margin { 171 properties.push(("margin", margin)); 172 } 173 if let Some(ref margin_bottom) = self.margin_bottom { 174 properties.push(("margin-bottom", margin_bottom)); 175 } 176 if let Some(ref margin_end) = self.margin_end { 177 properties.push(("margin-end", margin_end)); 178 } 179 if let Some(ref margin_start) = self.margin_start { 180 properties.push(("margin-start", margin_start)); 181 } 182 if let Some(ref margin_top) = self.margin_top { 183 properties.push(("margin-top", margin_top)); 184 } 185 if let Some(ref name) = self.name { 186 properties.push(("name", name)); 187 } 188 if let Some(ref no_show_all) = self.no_show_all { 189 properties.push(("no-show-all", no_show_all)); 190 } 191 if let Some(ref opacity) = self.opacity { 192 properties.push(("opacity", opacity)); 193 } 194 if let Some(ref parent) = self.parent { 195 properties.push(("parent", parent)); 196 } 197 if let Some(ref receives_default) = self.receives_default { 198 properties.push(("receives-default", receives_default)); 199 } 200 if let Some(ref sensitive) = self.sensitive { 201 properties.push(("sensitive", sensitive)); 202 } 203 if let Some(ref tooltip_markup) = self.tooltip_markup { 204 properties.push(("tooltip-markup", tooltip_markup)); 205 } 206 if let Some(ref tooltip_text) = self.tooltip_text { 207 properties.push(("tooltip-text", tooltip_text)); 208 } 209 if let Some(ref valign) = self.valign { 210 properties.push(("valign", valign)); 211 } 212 if let Some(ref vexpand) = self.vexpand { 213 properties.push(("vexpand", vexpand)); 214 } 215 if let Some(ref vexpand_set) = self.vexpand_set { 216 properties.push(("vexpand-set", vexpand_set)); 217 } 218 if let Some(ref visible) = self.visible { 219 properties.push(("visible", visible)); 220 } 221 if let Some(ref width_request) = self.width_request { 222 properties.push(("width-request", width_request)); 223 } 224 glib::Object::new::<SearchBar>(&properties) 225 .expect("Failed to create an instance of SearchBar") 226 } 227 search_mode_enabled(mut self, search_mode_enabled: bool) -> Self228 pub fn search_mode_enabled(mut self, search_mode_enabled: bool) -> Self { 229 self.search_mode_enabled = Some(search_mode_enabled); 230 self 231 } 232 show_close_button(mut self, show_close_button: bool) -> Self233 pub fn show_close_button(mut self, show_close_button: bool) -> Self { 234 self.show_close_button = Some(show_close_button); 235 self 236 } 237 border_width(mut self, border_width: u32) -> Self238 pub fn border_width(mut self, border_width: u32) -> Self { 239 self.border_width = Some(border_width); 240 self 241 } 242 child<P: IsA<Widget>>(mut self, child: &P) -> Self243 pub fn child<P: IsA<Widget>>(mut self, child: &P) -> Self { 244 self.child = Some(child.clone().upcast()); 245 self 246 } 247 resize_mode(mut self, resize_mode: ResizeMode) -> Self248 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self { 249 self.resize_mode = Some(resize_mode); 250 self 251 } 252 app_paintable(mut self, app_paintable: bool) -> Self253 pub fn app_paintable(mut self, app_paintable: bool) -> Self { 254 self.app_paintable = Some(app_paintable); 255 self 256 } 257 can_default(mut self, can_default: bool) -> Self258 pub fn can_default(mut self, can_default: bool) -> Self { 259 self.can_default = Some(can_default); 260 self 261 } 262 can_focus(mut self, can_focus: bool) -> Self263 pub fn can_focus(mut self, can_focus: bool) -> Self { 264 self.can_focus = Some(can_focus); 265 self 266 } 267 events(mut self, events: gdk::EventMask) -> Self268 pub fn events(mut self, events: gdk::EventMask) -> Self { 269 self.events = Some(events); 270 self 271 } 272 expand(mut self, expand: bool) -> Self273 pub fn expand(mut self, expand: bool) -> Self { 274 self.expand = Some(expand); 275 self 276 } 277 278 #[cfg(any(feature = "v3_20", feature = "dox"))] 279 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] focus_on_click(mut self, focus_on_click: bool) -> Self280 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self { 281 self.focus_on_click = Some(focus_on_click); 282 self 283 } 284 halign(mut self, halign: Align) -> Self285 pub fn halign(mut self, halign: Align) -> Self { 286 self.halign = Some(halign); 287 self 288 } 289 has_default(mut self, has_default: bool) -> Self290 pub fn has_default(mut self, has_default: bool) -> Self { 291 self.has_default = Some(has_default); 292 self 293 } 294 has_focus(mut self, has_focus: bool) -> Self295 pub fn has_focus(mut self, has_focus: bool) -> Self { 296 self.has_focus = Some(has_focus); 297 self 298 } 299 has_tooltip(mut self, has_tooltip: bool) -> Self300 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self { 301 self.has_tooltip = Some(has_tooltip); 302 self 303 } 304 height_request(mut self, height_request: i32) -> Self305 pub fn height_request(mut self, height_request: i32) -> Self { 306 self.height_request = Some(height_request); 307 self 308 } 309 hexpand(mut self, hexpand: bool) -> Self310 pub fn hexpand(mut self, hexpand: bool) -> Self { 311 self.hexpand = Some(hexpand); 312 self 313 } 314 hexpand_set(mut self, hexpand_set: bool) -> Self315 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self { 316 self.hexpand_set = Some(hexpand_set); 317 self 318 } 319 is_focus(mut self, is_focus: bool) -> Self320 pub fn is_focus(mut self, is_focus: bool) -> Self { 321 self.is_focus = Some(is_focus); 322 self 323 } 324 margin(mut self, margin: i32) -> Self325 pub fn margin(mut self, margin: i32) -> Self { 326 self.margin = Some(margin); 327 self 328 } 329 margin_bottom(mut self, margin_bottom: i32) -> Self330 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self { 331 self.margin_bottom = Some(margin_bottom); 332 self 333 } 334 margin_end(mut self, margin_end: i32) -> Self335 pub fn margin_end(mut self, margin_end: i32) -> Self { 336 self.margin_end = Some(margin_end); 337 self 338 } 339 margin_start(mut self, margin_start: i32) -> Self340 pub fn margin_start(mut self, margin_start: i32) -> Self { 341 self.margin_start = Some(margin_start); 342 self 343 } 344 margin_top(mut self, margin_top: i32) -> Self345 pub fn margin_top(mut self, margin_top: i32) -> Self { 346 self.margin_top = Some(margin_top); 347 self 348 } 349 name(mut self, name: &str) -> Self350 pub fn name(mut self, name: &str) -> Self { 351 self.name = Some(name.to_string()); 352 self 353 } 354 no_show_all(mut self, no_show_all: bool) -> Self355 pub fn no_show_all(mut self, no_show_all: bool) -> Self { 356 self.no_show_all = Some(no_show_all); 357 self 358 } 359 opacity(mut self, opacity: f64) -> Self360 pub fn opacity(mut self, opacity: f64) -> Self { 361 self.opacity = Some(opacity); 362 self 363 } 364 parent<P: IsA<Container>>(mut self, parent: &P) -> Self365 pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self { 366 self.parent = Some(parent.clone().upcast()); 367 self 368 } 369 receives_default(mut self, receives_default: bool) -> Self370 pub fn receives_default(mut self, receives_default: bool) -> Self { 371 self.receives_default = Some(receives_default); 372 self 373 } 374 sensitive(mut self, sensitive: bool) -> Self375 pub fn sensitive(mut self, sensitive: bool) -> Self { 376 self.sensitive = Some(sensitive); 377 self 378 } 379 tooltip_markup(mut self, tooltip_markup: &str) -> Self380 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self { 381 self.tooltip_markup = Some(tooltip_markup.to_string()); 382 self 383 } 384 tooltip_text(mut self, tooltip_text: &str) -> Self385 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self { 386 self.tooltip_text = Some(tooltip_text.to_string()); 387 self 388 } 389 valign(mut self, valign: Align) -> Self390 pub fn valign(mut self, valign: Align) -> Self { 391 self.valign = Some(valign); 392 self 393 } 394 vexpand(mut self, vexpand: bool) -> Self395 pub fn vexpand(mut self, vexpand: bool) -> Self { 396 self.vexpand = Some(vexpand); 397 self 398 } 399 vexpand_set(mut self, vexpand_set: bool) -> Self400 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self { 401 self.vexpand_set = Some(vexpand_set); 402 self 403 } 404 visible(mut self, visible: bool) -> Self405 pub fn visible(mut self, visible: bool) -> Self { 406 self.visible = Some(visible); 407 self 408 } 409 width_request(mut self, width_request: i32) -> Self410 pub fn width_request(mut self, width_request: i32) -> Self { 411 self.width_request = Some(width_request); 412 self 413 } 414 } 415 416 pub const NONE_SEARCH_BAR: Option<&SearchBar> = None; 417 418 pub trait SearchBarExt: 'static { 419 #[doc(alias = "gtk_search_bar_connect_entry")] connect_entry<P: IsA<Entry>>(&self, entry: &P)420 fn connect_entry<P: IsA<Entry>>(&self, entry: &P); 421 422 #[doc(alias = "gtk_search_bar_get_search_mode")] 423 #[doc(alias = "get_search_mode")] is_search_mode(&self) -> bool424 fn is_search_mode(&self) -> bool; 425 426 #[doc(alias = "gtk_search_bar_get_show_close_button")] 427 #[doc(alias = "get_show_close_button")] shows_close_button(&self) -> bool428 fn shows_close_button(&self) -> bool; 429 430 #[doc(alias = "gtk_search_bar_handle_event")] handle_event(&self, event: &gdk::Event) -> bool431 fn handle_event(&self, event: &gdk::Event) -> bool; 432 433 #[doc(alias = "gtk_search_bar_set_search_mode")] set_search_mode(&self, search_mode: bool)434 fn set_search_mode(&self, search_mode: bool); 435 436 #[doc(alias = "gtk_search_bar_set_show_close_button")] set_show_close_button(&self, visible: bool)437 fn set_show_close_button(&self, visible: bool); 438 439 #[doc(alias = "search-mode-enabled")] is_search_mode_enabled(&self) -> bool440 fn is_search_mode_enabled(&self) -> bool; 441 442 #[doc(alias = "search-mode-enabled")] set_search_mode_enabled(&self, search_mode_enabled: bool)443 fn set_search_mode_enabled(&self, search_mode_enabled: bool); 444 445 #[doc(alias = "search-mode-enabled")] connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId446 fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 447 448 #[doc(alias = "show-close-button")] connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId449 fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 450 } 451 452 impl<O: IsA<SearchBar>> SearchBarExt for O { connect_entry<P: IsA<Entry>>(&self, entry: &P)453 fn connect_entry<P: IsA<Entry>>(&self, entry: &P) { 454 unsafe { 455 ffi::gtk_search_bar_connect_entry( 456 self.as_ref().to_glib_none().0, 457 entry.as_ref().to_glib_none().0, 458 ); 459 } 460 } 461 is_search_mode(&self) -> bool462 fn is_search_mode(&self) -> bool { 463 unsafe { 464 from_glib(ffi::gtk_search_bar_get_search_mode( 465 self.as_ref().to_glib_none().0, 466 )) 467 } 468 } 469 shows_close_button(&self) -> bool470 fn shows_close_button(&self) -> bool { 471 unsafe { 472 from_glib(ffi::gtk_search_bar_get_show_close_button( 473 self.as_ref().to_glib_none().0, 474 )) 475 } 476 } 477 handle_event(&self, event: &gdk::Event) -> bool478 fn handle_event(&self, event: &gdk::Event) -> bool { 479 unsafe { 480 from_glib(ffi::gtk_search_bar_handle_event( 481 self.as_ref().to_glib_none().0, 482 mut_override(event.to_glib_none().0), 483 )) 484 } 485 } 486 set_search_mode(&self, search_mode: bool)487 fn set_search_mode(&self, search_mode: bool) { 488 unsafe { 489 ffi::gtk_search_bar_set_search_mode( 490 self.as_ref().to_glib_none().0, 491 search_mode.into_glib(), 492 ); 493 } 494 } 495 set_show_close_button(&self, visible: bool)496 fn set_show_close_button(&self, visible: bool) { 497 unsafe { 498 ffi::gtk_search_bar_set_show_close_button( 499 self.as_ref().to_glib_none().0, 500 visible.into_glib(), 501 ); 502 } 503 } 504 is_search_mode_enabled(&self) -> bool505 fn is_search_mode_enabled(&self) -> bool { 506 unsafe { 507 let mut value = glib::Value::from_type(<bool as StaticType>::static_type()); 508 glib::gobject_ffi::g_object_get_property( 509 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 510 b"search-mode-enabled\0".as_ptr() as *const _, 511 value.to_glib_none_mut().0, 512 ); 513 value 514 .get() 515 .expect("Return Value for property `search-mode-enabled` getter") 516 } 517 } 518 set_search_mode_enabled(&self, search_mode_enabled: bool)519 fn set_search_mode_enabled(&self, search_mode_enabled: bool) { 520 unsafe { 521 glib::gobject_ffi::g_object_set_property( 522 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 523 b"search-mode-enabled\0".as_ptr() as *const _, 524 search_mode_enabled.to_value().to_glib_none().0, 525 ); 526 } 527 } 528 connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId529 fn connect_search_mode_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 530 unsafe extern "C" fn notify_search_mode_enabled_trampoline< 531 P: IsA<SearchBar>, 532 F: Fn(&P) + 'static, 533 >( 534 this: *mut ffi::GtkSearchBar, 535 _param_spec: glib::ffi::gpointer, 536 f: glib::ffi::gpointer, 537 ) { 538 let f: &F = &*(f as *const F); 539 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref()) 540 } 541 unsafe { 542 let f: Box_<F> = Box_::new(f); 543 connect_raw( 544 self.as_ptr() as *mut _, 545 b"notify::search-mode-enabled\0".as_ptr() as *const _, 546 Some(transmute::<_, unsafe extern "C" fn()>( 547 notify_search_mode_enabled_trampoline::<Self, F> as *const (), 548 )), 549 Box_::into_raw(f), 550 ) 551 } 552 } 553 connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId554 fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 555 unsafe extern "C" fn notify_show_close_button_trampoline< 556 P: IsA<SearchBar>, 557 F: Fn(&P) + 'static, 558 >( 559 this: *mut ffi::GtkSearchBar, 560 _param_spec: glib::ffi::gpointer, 561 f: glib::ffi::gpointer, 562 ) { 563 let f: &F = &*(f as *const F); 564 f(SearchBar::from_glib_borrow(this).unsafe_cast_ref()) 565 } 566 unsafe { 567 let f: Box_<F> = Box_::new(f); 568 connect_raw( 569 self.as_ptr() as *mut _, 570 b"notify::show-close-button\0".as_ptr() as *const _, 571 Some(transmute::<_, unsafe extern "C" fn()>( 572 notify_show_close_button_trampoline::<Self, F> as *const (), 573 )), 574 Box_::into_raw(f), 575 ) 576 } 577 } 578 } 579 580 impl fmt::Display for SearchBar { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result581 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 582 f.write_str("SearchBar") 583 } 584 } 585