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