gtk/auto/
search_bar.rs

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
5use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use gtk_sys;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem::transmute;
20use Align;
21use Bin;
22use Buildable;
23use Container;
24use Entry;
25use ResizeMode;
26use Widget;
27
28glib_wrapper! {
29    pub struct SearchBar(Object<gtk_sys::GtkSearchBar, gtk_sys::GtkSearchBarClass, SearchBarClass>) @extends Bin, Container, Widget, @implements Buildable;
30
31    match fn {
32        get_type => || gtk_sys::gtk_search_bar_get_type(),
33    }
34}
35
36impl SearchBar {
37    pub fn new() -> SearchBar {
38        assert_initialized_main_thread!();
39        unsafe { Widget::from_glib_none(gtk_sys::gtk_search_bar_new()).unsafe_cast() }
40    }
41}
42
43impl Default for SearchBar {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49pub struct SearchBarBuilder {
50    search_mode_enabled: Option<bool>,
51    show_close_button: Option<bool>,
52    border_width: Option<u32>,
53    child: Option<Widget>,
54    resize_mode: Option<ResizeMode>,
55    app_paintable: Option<bool>,
56    can_default: Option<bool>,
57    can_focus: Option<bool>,
58    events: Option<gdk::EventMask>,
59    expand: Option<bool>,
60    #[cfg(any(feature = "v3_20", feature = "dox"))]
61    focus_on_click: Option<bool>,
62    halign: Option<Align>,
63    has_default: Option<bool>,
64    has_focus: Option<bool>,
65    has_tooltip: Option<bool>,
66    height_request: Option<i32>,
67    hexpand: Option<bool>,
68    hexpand_set: Option<bool>,
69    is_focus: Option<bool>,
70    margin: Option<i32>,
71    margin_bottom: Option<i32>,
72    margin_end: Option<i32>,
73    margin_start: Option<i32>,
74    margin_top: Option<i32>,
75    name: Option<String>,
76    no_show_all: Option<bool>,
77    opacity: Option<f64>,
78    parent: Option<Container>,
79    receives_default: Option<bool>,
80    sensitive: Option<bool>,
81    //style: /*Unknown type*/,
82    tooltip_markup: Option<String>,
83    tooltip_text: Option<String>,
84    valign: Option<Align>,
85    vexpand: Option<bool>,
86    vexpand_set: Option<bool>,
87    visible: Option<bool>,
88    width_request: Option<i32>,
89}
90
91impl SearchBarBuilder {
92    pub fn new() -> Self {
93        Self {
94            search_mode_enabled: None,
95            show_close_button: None,
96            border_width: None,
97            child: None,
98            resize_mode: None,
99            app_paintable: None,
100            can_default: None,
101            can_focus: None,
102            events: None,
103            expand: None,
104            #[cfg(any(feature = "v3_20", feature = "dox"))]
105            focus_on_click: None,
106            halign: None,
107            has_default: None,
108            has_focus: None,
109            has_tooltip: None,
110            height_request: None,
111            hexpand: None,
112            hexpand_set: None,
113            is_focus: None,
114            margin: None,
115            margin_bottom: None,
116            margin_end: None,
117            margin_start: None,
118            margin_top: None,
119            name: None,
120            no_show_all: None,
121            opacity: None,
122            parent: None,
123            receives_default: None,
124            sensitive: None,
125            tooltip_markup: None,
126            tooltip_text: None,
127            valign: None,
128            vexpand: None,
129            vexpand_set: None,
130            visible: None,
131            width_request: None,
132        }
133    }
134
135    pub fn build(self) -> SearchBar {
136        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
137        if let Some(ref search_mode_enabled) = self.search_mode_enabled {
138            properties.push(("search-mode-enabled", search_mode_enabled));
139        }
140        if let Some(ref show_close_button) = self.show_close_button {
141            properties.push(("show-close-button", show_close_button));
142        }
143        if let Some(ref border_width) = self.border_width {
144            properties.push(("border-width", border_width));
145        }
146        if let Some(ref child) = self.child {
147            properties.push(("child", child));
148        }
149        if let Some(ref resize_mode) = self.resize_mode {
150            properties.push(("resize-mode", resize_mode));
151        }
152        if let Some(ref app_paintable) = self.app_paintable {
153            properties.push(("app-paintable", app_paintable));
154        }
155        if let Some(ref can_default) = self.can_default {
156            properties.push(("can-default", can_default));
157        }
158        if let Some(ref can_focus) = self.can_focus {
159            properties.push(("can-focus", can_focus));
160        }
161        if let Some(ref events) = self.events {
162            properties.push(("events", events));
163        }
164        if let Some(ref expand) = self.expand {
165            properties.push(("expand", expand));
166        }
167        #[cfg(any(feature = "v3_20", feature = "dox"))]
168        {
169            if let Some(ref focus_on_click) = self.focus_on_click {
170                properties.push(("focus-on-click", focus_on_click));
171            }
172        }
173        if let Some(ref halign) = self.halign {
174            properties.push(("halign", halign));
175        }
176        if let Some(ref has_default) = self.has_default {
177            properties.push(("has-default", has_default));
178        }
179        if let Some(ref has_focus) = self.has_focus {
180            properties.push(("has-focus", has_focus));
181        }
182        if let Some(ref has_tooltip) = self.has_tooltip {
183            properties.push(("has-tooltip", has_tooltip));
184        }
185        if let Some(ref height_request) = self.height_request {
186            properties.push(("height-request", height_request));
187        }
188        if let Some(ref hexpand) = self.hexpand {
189            properties.push(("hexpand", hexpand));
190        }
191        if let Some(ref hexpand_set) = self.hexpand_set {
192            properties.push(("hexpand-set", hexpand_set));
193        }
194        if let Some(ref is_focus) = self.is_focus {
195            properties.push(("is-focus", is_focus));
196        }
197        if let Some(ref margin) = self.margin {
198            properties.push(("margin", margin));
199        }
200        if let Some(ref margin_bottom) = self.margin_bottom {
201            properties.push(("margin-bottom", margin_bottom));
202        }
203        if let Some(ref margin_end) = self.margin_end {
204            properties.push(("margin-end", margin_end));
205        }
206        if let Some(ref margin_start) = self.margin_start {
207            properties.push(("margin-start", margin_start));
208        }
209        if let Some(ref margin_top) = self.margin_top {
210            properties.push(("margin-top", margin_top));
211        }
212        if let Some(ref name) = self.name {
213            properties.push(("name", name));
214        }
215        if let Some(ref no_show_all) = self.no_show_all {
216            properties.push(("no-show-all", no_show_all));
217        }
218        if let Some(ref opacity) = self.opacity {
219            properties.push(("opacity", opacity));
220        }
221        if let Some(ref parent) = self.parent {
222            properties.push(("parent", parent));
223        }
224        if let Some(ref receives_default) = self.receives_default {
225            properties.push(("receives-default", receives_default));
226        }
227        if let Some(ref sensitive) = self.sensitive {
228            properties.push(("sensitive", sensitive));
229        }
230        if let Some(ref tooltip_markup) = self.tooltip_markup {
231            properties.push(("tooltip-markup", tooltip_markup));
232        }
233        if let Some(ref tooltip_text) = self.tooltip_text {
234            properties.push(("tooltip-text", tooltip_text));
235        }
236        if let Some(ref valign) = self.valign {
237            properties.push(("valign", valign));
238        }
239        if let Some(ref vexpand) = self.vexpand {
240            properties.push(("vexpand", vexpand));
241        }
242        if let Some(ref vexpand_set) = self.vexpand_set {
243            properties.push(("vexpand-set", vexpand_set));
244        }
245        if let Some(ref visible) = self.visible {
246            properties.push(("visible", visible));
247        }
248        if let Some(ref width_request) = self.width_request {
249            properties.push(("width-request", width_request));
250        }
251        glib::Object::new(SearchBar::static_type(), &properties)
252            .expect("object new")
253            .downcast()
254            .expect("downcast")
255    }
256
257    pub fn search_mode_enabled(mut self, search_mode_enabled: bool) -> Self {
258        self.search_mode_enabled = Some(search_mode_enabled);
259        self
260    }
261
262    pub fn show_close_button(mut self, show_close_button: bool) -> Self {
263        self.show_close_button = Some(show_close_button);
264        self
265    }
266
267    pub fn border_width(mut self, border_width: u32) -> Self {
268        self.border_width = Some(border_width);
269        self
270    }
271
272    pub fn child(mut self, child: &Widget) -> Self {
273        self.child = Some(child.clone());
274        self
275    }
276
277    pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
278        self.resize_mode = Some(resize_mode);
279        self
280    }
281
282    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
283        self.app_paintable = Some(app_paintable);
284        self
285    }
286
287    pub fn can_default(mut self, can_default: bool) -> Self {
288        self.can_default = Some(can_default);
289        self
290    }
291
292    pub fn can_focus(mut self, can_focus: bool) -> Self {
293        self.can_focus = Some(can_focus);
294        self
295    }
296
297    pub fn events(mut self, events: gdk::EventMask) -> Self {
298        self.events = Some(events);
299        self
300    }
301
302    pub fn expand(mut self, expand: bool) -> Self {
303        self.expand = Some(expand);
304        self
305    }
306
307    #[cfg(any(feature = "v3_20", feature = "dox"))]
308    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
309        self.focus_on_click = Some(focus_on_click);
310        self
311    }
312
313    pub fn halign(mut self, halign: Align) -> Self {
314        self.halign = Some(halign);
315        self
316    }
317
318    pub fn has_default(mut self, has_default: bool) -> Self {
319        self.has_default = Some(has_default);
320        self
321    }
322
323    pub fn has_focus(mut self, has_focus: bool) -> Self {
324        self.has_focus = Some(has_focus);
325        self
326    }
327
328    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
329        self.has_tooltip = Some(has_tooltip);
330        self
331    }
332
333    pub fn height_request(mut self, height_request: i32) -> Self {
334        self.height_request = Some(height_request);
335        self
336    }
337
338    pub fn hexpand(mut self, hexpand: bool) -> Self {
339        self.hexpand = Some(hexpand);
340        self
341    }
342
343    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
344        self.hexpand_set = Some(hexpand_set);
345        self
346    }
347
348    pub fn is_focus(mut self, is_focus: bool) -> Self {
349        self.is_focus = Some(is_focus);
350        self
351    }
352
353    pub fn margin(mut self, margin: i32) -> Self {
354        self.margin = Some(margin);
355        self
356    }
357
358    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
359        self.margin_bottom = Some(margin_bottom);
360        self
361    }
362
363    pub fn margin_end(mut self, margin_end: i32) -> Self {
364        self.margin_end = Some(margin_end);
365        self
366    }
367
368    pub fn margin_start(mut self, margin_start: i32) -> Self {
369        self.margin_start = Some(margin_start);
370        self
371    }
372
373    pub fn margin_top(mut self, margin_top: i32) -> Self {
374        self.margin_top = Some(margin_top);
375        self
376    }
377
378    pub fn name(mut self, name: &str) -> Self {
379        self.name = Some(name.to_string());
380        self
381    }
382
383    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
384        self.no_show_all = Some(no_show_all);
385        self
386    }
387
388    pub fn opacity(mut self, opacity: f64) -> Self {
389        self.opacity = Some(opacity);
390        self
391    }
392
393    pub fn parent(mut self, parent: &Container) -> Self {
394        self.parent = Some(parent.clone());
395        self
396    }
397
398    pub fn receives_default(mut self, receives_default: bool) -> Self {
399        self.receives_default = Some(receives_default);
400        self
401    }
402
403    pub fn sensitive(mut self, sensitive: bool) -> Self {
404        self.sensitive = Some(sensitive);
405        self
406    }
407
408    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
409        self.tooltip_markup = Some(tooltip_markup.to_string());
410        self
411    }
412
413    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
414        self.tooltip_text = Some(tooltip_text.to_string());
415        self
416    }
417
418    pub fn valign(mut self, valign: Align) -> Self {
419        self.valign = Some(valign);
420        self
421    }
422
423    pub fn vexpand(mut self, vexpand: bool) -> Self {
424        self.vexpand = Some(vexpand);
425        self
426    }
427
428    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
429        self.vexpand_set = Some(vexpand_set);
430        self
431    }
432
433    pub fn visible(mut self, visible: bool) -> Self {
434        self.visible = Some(visible);
435        self
436    }
437
438    pub fn width_request(mut self, width_request: i32) -> Self {
439        self.width_request = Some(width_request);
440        self
441    }
442}
443
444pub const NONE_SEARCH_BAR: Option<&SearchBar> = None;
445
446pub trait SearchBarExt: 'static {
447    fn connect_entry<P: IsA<Entry>>(&self, entry: &P);
448
449    fn get_search_mode(&self) -> bool;
450
451    fn get_show_close_button(&self) -> bool;
452
453    fn handle_event(&self, event: &gdk::Event) -> bool;
454
455    fn set_search_mode(&self, search_mode: bool);
456
457    fn set_show_close_button(&self, visible: bool);
458
459    fn get_property_search_mode_enabled(&self) -> bool;
460
461    fn set_property_search_mode_enabled(&self, search_mode_enabled: bool);
462
463    fn connect_property_search_mode_enabled_notify<F: Fn(&Self) + 'static>(
464        &self,
465        f: F,
466    ) -> SignalHandlerId;
467
468    fn connect_property_show_close_button_notify<F: Fn(&Self) + 'static>(
469        &self,
470        f: F,
471    ) -> SignalHandlerId;
472}
473
474impl<O: IsA<SearchBar>> SearchBarExt for O {
475    fn connect_entry<P: IsA<Entry>>(&self, entry: &P) {
476        unsafe {
477            gtk_sys::gtk_search_bar_connect_entry(
478                self.as_ref().to_glib_none().0,
479                entry.as_ref().to_glib_none().0,
480            );
481        }
482    }
483
484    fn get_search_mode(&self) -> bool {
485        unsafe {
486            from_glib(gtk_sys::gtk_search_bar_get_search_mode(
487                self.as_ref().to_glib_none().0,
488            ))
489        }
490    }
491
492    fn get_show_close_button(&self) -> bool {
493        unsafe {
494            from_glib(gtk_sys::gtk_search_bar_get_show_close_button(
495                self.as_ref().to_glib_none().0,
496            ))
497        }
498    }
499
500    fn handle_event(&self, event: &gdk::Event) -> bool {
501        unsafe {
502            from_glib(gtk_sys::gtk_search_bar_handle_event(
503                self.as_ref().to_glib_none().0,
504                mut_override(event.to_glib_none().0),
505            ))
506        }
507    }
508
509    fn set_search_mode(&self, search_mode: bool) {
510        unsafe {
511            gtk_sys::gtk_search_bar_set_search_mode(
512                self.as_ref().to_glib_none().0,
513                search_mode.to_glib(),
514            );
515        }
516    }
517
518    fn set_show_close_button(&self, visible: bool) {
519        unsafe {
520            gtk_sys::gtk_search_bar_set_show_close_button(
521                self.as_ref().to_glib_none().0,
522                visible.to_glib(),
523            );
524        }
525    }
526
527    fn get_property_search_mode_enabled(&self) -> bool {
528        unsafe {
529            let mut value = Value::from_type(<bool as StaticType>::static_type());
530            gobject_sys::g_object_get_property(
531                self.to_glib_none().0 as *mut gobject_sys::GObject,
532                b"search-mode-enabled\0".as_ptr() as *const _,
533                value.to_glib_none_mut().0,
534            );
535            value.get().unwrap()
536        }
537    }
538
539    fn set_property_search_mode_enabled(&self, search_mode_enabled: bool) {
540        unsafe {
541            gobject_sys::g_object_set_property(
542                self.to_glib_none().0 as *mut gobject_sys::GObject,
543                b"search-mode-enabled\0".as_ptr() as *const _,
544                Value::from(&search_mode_enabled).to_glib_none().0,
545            );
546        }
547    }
548
549    fn connect_property_search_mode_enabled_notify<F: Fn(&Self) + 'static>(
550        &self,
551        f: F,
552    ) -> SignalHandlerId {
553        unsafe extern "C" fn notify_search_mode_enabled_trampoline<P, F: Fn(&P) + 'static>(
554            this: *mut gtk_sys::GtkSearchBar,
555            _param_spec: glib_sys::gpointer,
556            f: glib_sys::gpointer,
557        ) where
558            P: IsA<SearchBar>,
559        {
560            let f: &F = &*(f as *const F);
561            f(&SearchBar::from_glib_borrow(this).unsafe_cast())
562        }
563        unsafe {
564            let f: Box_<F> = Box_::new(f);
565            connect_raw(
566                self.as_ptr() as *mut _,
567                b"notify::search-mode-enabled\0".as_ptr() as *const _,
568                Some(transmute(
569                    notify_search_mode_enabled_trampoline::<Self, F> as usize,
570                )),
571                Box_::into_raw(f),
572            )
573        }
574    }
575
576    fn connect_property_show_close_button_notify<F: Fn(&Self) + 'static>(
577        &self,
578        f: F,
579    ) -> SignalHandlerId {
580        unsafe extern "C" fn notify_show_close_button_trampoline<P, F: Fn(&P) + 'static>(
581            this: *mut gtk_sys::GtkSearchBar,
582            _param_spec: glib_sys::gpointer,
583            f: glib_sys::gpointer,
584        ) where
585            P: IsA<SearchBar>,
586        {
587            let f: &F = &*(f as *const F);
588            f(&SearchBar::from_glib_borrow(this).unsafe_cast())
589        }
590        unsafe {
591            let f: Box_<F> = Box_::new(f);
592            connect_raw(
593                self.as_ptr() as *mut _,
594                b"notify::show-close-button\0".as_ptr() as *const _,
595                Some(transmute(
596                    notify_show_close_button_trampoline::<Self, F> as usize,
597                )),
598                Box_::into_raw(f),
599            )
600        }
601    }
602}
603
604impl fmt::Display for SearchBar {
605    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
606        write!(f, "SearchBar")
607    }
608}