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