1use gdk;
6use gio;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
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 Buildable;
21use Container;
22use MenuShell;
23use PackDirection;
24use ResizeMode;
25use Widget;
26
27glib_wrapper! {
28 pub struct MenuBar(Object<gtk_sys::GtkMenuBar, gtk_sys::GtkMenuBarClass, MenuBarClass>) @extends MenuShell, Container, Widget, @implements Buildable;
29
30 match fn {
31 get_type => || gtk_sys::gtk_menu_bar_get_type(),
32 }
33}
34
35impl MenuBar {
36 pub fn new() -> MenuBar {
37 assert_initialized_main_thread!();
38 unsafe { Widget::from_glib_none(gtk_sys::gtk_menu_bar_new()).unsafe_cast() }
39 }
40
41 pub fn new_from_model<P: IsA<gio::MenuModel>>(model: &P) -> MenuBar {
42 assert_initialized_main_thread!();
43 unsafe {
44 Widget::from_glib_none(gtk_sys::gtk_menu_bar_new_from_model(
45 model.as_ref().to_glib_none().0,
46 ))
47 .unsafe_cast()
48 }
49 }
50}
51
52impl Default for MenuBar {
53 fn default() -> Self {
54 Self::new()
55 }
56}
57
58pub struct MenuBarBuilder {
59 child_pack_direction: Option<PackDirection>,
60 pack_direction: Option<PackDirection>,
61 take_focus: Option<bool>,
62 border_width: Option<u32>,
63 child: Option<Widget>,
64 resize_mode: Option<ResizeMode>,
65 app_paintable: Option<bool>,
66 can_default: Option<bool>,
67 can_focus: Option<bool>,
68 events: Option<gdk::EventMask>,
69 expand: Option<bool>,
70 #[cfg(any(feature = "v3_20", feature = "dox"))]
71 focus_on_click: Option<bool>,
72 halign: Option<Align>,
73 has_default: Option<bool>,
74 has_focus: Option<bool>,
75 has_tooltip: Option<bool>,
76 height_request: Option<i32>,
77 hexpand: Option<bool>,
78 hexpand_set: Option<bool>,
79 is_focus: Option<bool>,
80 margin: Option<i32>,
81 margin_bottom: Option<i32>,
82 margin_end: Option<i32>,
83 margin_start: Option<i32>,
84 margin_top: Option<i32>,
85 name: Option<String>,
86 no_show_all: Option<bool>,
87 opacity: Option<f64>,
88 parent: Option<Container>,
89 receives_default: Option<bool>,
90 sensitive: Option<bool>,
91 tooltip_markup: Option<String>,
93 tooltip_text: Option<String>,
94 valign: Option<Align>,
95 vexpand: Option<bool>,
96 vexpand_set: Option<bool>,
97 visible: Option<bool>,
98 width_request: Option<i32>,
99}
100
101impl MenuBarBuilder {
102 pub fn new() -> Self {
103 Self {
104 child_pack_direction: None,
105 pack_direction: None,
106 take_focus: None,
107 border_width: None,
108 child: None,
109 resize_mode: None,
110 app_paintable: None,
111 can_default: None,
112 can_focus: None,
113 events: None,
114 expand: None,
115 #[cfg(any(feature = "v3_20", feature = "dox"))]
116 focus_on_click: None,
117 halign: None,
118 has_default: None,
119 has_focus: None,
120 has_tooltip: None,
121 height_request: None,
122 hexpand: None,
123 hexpand_set: None,
124 is_focus: None,
125 margin: None,
126 margin_bottom: None,
127 margin_end: None,
128 margin_start: None,
129 margin_top: None,
130 name: None,
131 no_show_all: None,
132 opacity: None,
133 parent: None,
134 receives_default: None,
135 sensitive: None,
136 tooltip_markup: None,
137 tooltip_text: None,
138 valign: None,
139 vexpand: None,
140 vexpand_set: None,
141 visible: None,
142 width_request: None,
143 }
144 }
145
146 pub fn build(self) -> MenuBar {
147 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
148 if let Some(ref child_pack_direction) = self.child_pack_direction {
149 properties.push(("child-pack-direction", child_pack_direction));
150 }
151 if let Some(ref pack_direction) = self.pack_direction {
152 properties.push(("pack-direction", pack_direction));
153 }
154 if let Some(ref take_focus) = self.take_focus {
155 properties.push(("take-focus", take_focus));
156 }
157 if let Some(ref border_width) = self.border_width {
158 properties.push(("border-width", border_width));
159 }
160 if let Some(ref child) = self.child {
161 properties.push(("child", child));
162 }
163 if let Some(ref resize_mode) = self.resize_mode {
164 properties.push(("resize-mode", resize_mode));
165 }
166 if let Some(ref app_paintable) = self.app_paintable {
167 properties.push(("app-paintable", app_paintable));
168 }
169 if let Some(ref can_default) = self.can_default {
170 properties.push(("can-default", can_default));
171 }
172 if let Some(ref can_focus) = self.can_focus {
173 properties.push(("can-focus", can_focus));
174 }
175 if let Some(ref events) = self.events {
176 properties.push(("events", events));
177 }
178 if let Some(ref expand) = self.expand {
179 properties.push(("expand", expand));
180 }
181 #[cfg(any(feature = "v3_20", feature = "dox"))]
182 {
183 if let Some(ref focus_on_click) = self.focus_on_click {
184 properties.push(("focus-on-click", focus_on_click));
185 }
186 }
187 if let Some(ref halign) = self.halign {
188 properties.push(("halign", halign));
189 }
190 if let Some(ref has_default) = self.has_default {
191 properties.push(("has-default", has_default));
192 }
193 if let Some(ref has_focus) = self.has_focus {
194 properties.push(("has-focus", has_focus));
195 }
196 if let Some(ref has_tooltip) = self.has_tooltip {
197 properties.push(("has-tooltip", has_tooltip));
198 }
199 if let Some(ref height_request) = self.height_request {
200 properties.push(("height-request", height_request));
201 }
202 if let Some(ref hexpand) = self.hexpand {
203 properties.push(("hexpand", hexpand));
204 }
205 if let Some(ref hexpand_set) = self.hexpand_set {
206 properties.push(("hexpand-set", hexpand_set));
207 }
208 if let Some(ref is_focus) = self.is_focus {
209 properties.push(("is-focus", is_focus));
210 }
211 if let Some(ref margin) = self.margin {
212 properties.push(("margin", margin));
213 }
214 if let Some(ref margin_bottom) = self.margin_bottom {
215 properties.push(("margin-bottom", margin_bottom));
216 }
217 if let Some(ref margin_end) = self.margin_end {
218 properties.push(("margin-end", margin_end));
219 }
220 if let Some(ref margin_start) = self.margin_start {
221 properties.push(("margin-start", margin_start));
222 }
223 if let Some(ref margin_top) = self.margin_top {
224 properties.push(("margin-top", margin_top));
225 }
226 if let Some(ref name) = self.name {
227 properties.push(("name", name));
228 }
229 if let Some(ref no_show_all) = self.no_show_all {
230 properties.push(("no-show-all", no_show_all));
231 }
232 if let Some(ref opacity) = self.opacity {
233 properties.push(("opacity", opacity));
234 }
235 if let Some(ref parent) = self.parent {
236 properties.push(("parent", parent));
237 }
238 if let Some(ref receives_default) = self.receives_default {
239 properties.push(("receives-default", receives_default));
240 }
241 if let Some(ref sensitive) = self.sensitive {
242 properties.push(("sensitive", sensitive));
243 }
244 if let Some(ref tooltip_markup) = self.tooltip_markup {
245 properties.push(("tooltip-markup", tooltip_markup));
246 }
247 if let Some(ref tooltip_text) = self.tooltip_text {
248 properties.push(("tooltip-text", tooltip_text));
249 }
250 if let Some(ref valign) = self.valign {
251 properties.push(("valign", valign));
252 }
253 if let Some(ref vexpand) = self.vexpand {
254 properties.push(("vexpand", vexpand));
255 }
256 if let Some(ref vexpand_set) = self.vexpand_set {
257 properties.push(("vexpand-set", vexpand_set));
258 }
259 if let Some(ref visible) = self.visible {
260 properties.push(("visible", visible));
261 }
262 if let Some(ref width_request) = self.width_request {
263 properties.push(("width-request", width_request));
264 }
265 glib::Object::new(MenuBar::static_type(), &properties)
266 .expect("object new")
267 .downcast()
268 .expect("downcast")
269 }
270
271 pub fn child_pack_direction(mut self, child_pack_direction: PackDirection) -> Self {
272 self.child_pack_direction = Some(child_pack_direction);
273 self
274 }
275
276 pub fn pack_direction(mut self, pack_direction: PackDirection) -> Self {
277 self.pack_direction = Some(pack_direction);
278 self
279 }
280
281 pub fn take_focus(mut self, take_focus: bool) -> Self {
282 self.take_focus = Some(take_focus);
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_MENU_BAR: Option<&MenuBar> = None;
464
465pub trait MenuBarExt: 'static {
466 fn get_child_pack_direction(&self) -> PackDirection;
467
468 fn get_pack_direction(&self) -> PackDirection;
469
470 fn set_child_pack_direction(&self, child_pack_dir: PackDirection);
471
472 fn set_pack_direction(&self, pack_dir: PackDirection);
473
474 fn connect_property_child_pack_direction_notify<F: Fn(&Self) + 'static>(
475 &self,
476 f: F,
477 ) -> SignalHandlerId;
478
479 fn connect_property_pack_direction_notify<F: Fn(&Self) + 'static>(
480 &self,
481 f: F,
482 ) -> SignalHandlerId;
483}
484
485impl<O: IsA<MenuBar>> MenuBarExt for O {
486 fn get_child_pack_direction(&self) -> PackDirection {
487 unsafe {
488 from_glib(gtk_sys::gtk_menu_bar_get_child_pack_direction(
489 self.as_ref().to_glib_none().0,
490 ))
491 }
492 }
493
494 fn get_pack_direction(&self) -> PackDirection {
495 unsafe {
496 from_glib(gtk_sys::gtk_menu_bar_get_pack_direction(
497 self.as_ref().to_glib_none().0,
498 ))
499 }
500 }
501
502 fn set_child_pack_direction(&self, child_pack_dir: PackDirection) {
503 unsafe {
504 gtk_sys::gtk_menu_bar_set_child_pack_direction(
505 self.as_ref().to_glib_none().0,
506 child_pack_dir.to_glib(),
507 );
508 }
509 }
510
511 fn set_pack_direction(&self, pack_dir: PackDirection) {
512 unsafe {
513 gtk_sys::gtk_menu_bar_set_pack_direction(
514 self.as_ref().to_glib_none().0,
515 pack_dir.to_glib(),
516 );
517 }
518 }
519
520 fn connect_property_child_pack_direction_notify<F: Fn(&Self) + 'static>(
521 &self,
522 f: F,
523 ) -> SignalHandlerId {
524 unsafe extern "C" fn notify_child_pack_direction_trampoline<P, F: Fn(&P) + 'static>(
525 this: *mut gtk_sys::GtkMenuBar,
526 _param_spec: glib_sys::gpointer,
527 f: glib_sys::gpointer,
528 ) where
529 P: IsA<MenuBar>,
530 {
531 let f: &F = &*(f as *const F);
532 f(&MenuBar::from_glib_borrow(this).unsafe_cast())
533 }
534 unsafe {
535 let f: Box_<F> = Box_::new(f);
536 connect_raw(
537 self.as_ptr() as *mut _,
538 b"notify::child-pack-direction\0".as_ptr() as *const _,
539 Some(transmute(
540 notify_child_pack_direction_trampoline::<Self, F> as usize,
541 )),
542 Box_::into_raw(f),
543 )
544 }
545 }
546
547 fn connect_property_pack_direction_notify<F: Fn(&Self) + 'static>(
548 &self,
549 f: F,
550 ) -> SignalHandlerId {
551 unsafe extern "C" fn notify_pack_direction_trampoline<P, F: Fn(&P) + 'static>(
552 this: *mut gtk_sys::GtkMenuBar,
553 _param_spec: glib_sys::gpointer,
554 f: glib_sys::gpointer,
555 ) where
556 P: IsA<MenuBar>,
557 {
558 let f: &F = &*(f as *const F);
559 f(&MenuBar::from_glib_borrow(this).unsafe_cast())
560 }
561 unsafe {
562 let f: Box_<F> = Box_::new(f);
563 connect_raw(
564 self.as_ptr() as *mut _,
565 b"notify::pack-direction\0".as_ptr() as *const _,
566 Some(transmute(
567 notify_pack_direction_trampoline::<Self, F> as usize,
568 )),
569 Box_::into_raw(f),
570 )
571 }
572 }
573}
574
575impl fmt::Display for MenuBar {
576 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
577 write!(f, "MenuBar")
578 }
579}