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