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