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