1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, Button, ConstraintTarget, LayoutManager,
8 MessageType, Overflow, ResponseType, Widget,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "GtkInfoBar")]
20 pub struct InfoBar(Object<ffi::GtkInfoBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
21
22 match fn {
23 type_ => || ffi::gtk_info_bar_get_type(),
24 }
25}
26
27impl InfoBar {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_info_bar_new")]
31 pub fn new() -> InfoBar {
32 assert_initialized_main_thread!();
33 unsafe { Widget::from_glib_none(ffi::gtk_info_bar_new()).unsafe_cast() }
34 }
35
36 pub fn builder() -> InfoBarBuilder {
41 InfoBarBuilder::new()
42 }
43
44 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
45 #[allow(deprecated)]
46 #[doc(alias = "gtk_info_bar_add_action_widget")]
47 pub fn add_action_widget(&self, child: &impl IsA<Widget>, response_id: ResponseType) {
48 unsafe {
49 ffi::gtk_info_bar_add_action_widget(
50 self.to_glib_none().0,
51 child.as_ref().to_glib_none().0,
52 response_id.into_glib(),
53 );
54 }
55 }
56
57 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
58 #[allow(deprecated)]
59 #[doc(alias = "gtk_info_bar_add_button")]
60 pub fn add_button(&self, button_text: &str, response_id: ResponseType) -> Button {
61 unsafe {
62 from_glib_none(ffi::gtk_info_bar_add_button(
63 self.to_glib_none().0,
64 button_text.to_glib_none().0,
65 response_id.into_glib(),
66 ))
67 }
68 }
69
70 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
71 #[allow(deprecated)]
72 #[doc(alias = "gtk_info_bar_add_child")]
73 pub fn add_child(&self, widget: &impl IsA<Widget>) {
74 unsafe {
75 ffi::gtk_info_bar_add_child(self.to_glib_none().0, widget.as_ref().to_glib_none().0);
76 }
77 }
78
79 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
80 #[allow(deprecated)]
81 #[doc(alias = "gtk_info_bar_get_message_type")]
82 #[doc(alias = "get_message_type")]
83 #[doc(alias = "message-type")]
84 pub fn message_type(&self) -> MessageType {
85 unsafe { from_glib(ffi::gtk_info_bar_get_message_type(self.to_glib_none().0)) }
86 }
87
88 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
89 #[allow(deprecated)]
90 #[doc(alias = "gtk_info_bar_get_revealed")]
91 #[doc(alias = "get_revealed")]
92 #[doc(alias = "revealed")]
93 pub fn is_revealed(&self) -> bool {
94 unsafe { from_glib(ffi::gtk_info_bar_get_revealed(self.to_glib_none().0)) }
95 }
96
97 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
98 #[allow(deprecated)]
99 #[doc(alias = "gtk_info_bar_get_show_close_button")]
100 #[doc(alias = "get_show_close_button")]
101 #[doc(alias = "show-close-button")]
102 pub fn shows_close_button(&self) -> bool {
103 unsafe {
104 from_glib(ffi::gtk_info_bar_get_show_close_button(
105 self.to_glib_none().0,
106 ))
107 }
108 }
109
110 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
111 #[allow(deprecated)]
112 #[doc(alias = "gtk_info_bar_remove_action_widget")]
113 pub fn remove_action_widget(&self, widget: &impl IsA<Widget>) {
114 unsafe {
115 ffi::gtk_info_bar_remove_action_widget(
116 self.to_glib_none().0,
117 widget.as_ref().to_glib_none().0,
118 );
119 }
120 }
121
122 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
123 #[allow(deprecated)]
124 #[doc(alias = "gtk_info_bar_remove_child")]
125 pub fn remove_child(&self, widget: &impl IsA<Widget>) {
126 unsafe {
127 ffi::gtk_info_bar_remove_child(self.to_glib_none().0, widget.as_ref().to_glib_none().0);
128 }
129 }
130
131 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
132 #[allow(deprecated)]
133 #[doc(alias = "gtk_info_bar_response")]
134 pub fn response(&self, response_id: ResponseType) {
135 unsafe {
136 ffi::gtk_info_bar_response(self.to_glib_none().0, response_id.into_glib());
137 }
138 }
139
140 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
141 #[allow(deprecated)]
142 #[doc(alias = "gtk_info_bar_set_default_response")]
143 pub fn set_default_response(&self, response_id: ResponseType) {
144 unsafe {
145 ffi::gtk_info_bar_set_default_response(self.to_glib_none().0, response_id.into_glib());
146 }
147 }
148
149 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
150 #[allow(deprecated)]
151 #[doc(alias = "gtk_info_bar_set_message_type")]
152 #[doc(alias = "message-type")]
153 pub fn set_message_type(&self, message_type: MessageType) {
154 unsafe {
155 ffi::gtk_info_bar_set_message_type(self.to_glib_none().0, message_type.into_glib());
156 }
157 }
158
159 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
160 #[allow(deprecated)]
161 #[doc(alias = "gtk_info_bar_set_response_sensitive")]
162 pub fn set_response_sensitive(&self, response_id: ResponseType, setting: bool) {
163 unsafe {
164 ffi::gtk_info_bar_set_response_sensitive(
165 self.to_glib_none().0,
166 response_id.into_glib(),
167 setting.into_glib(),
168 );
169 }
170 }
171
172 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
173 #[allow(deprecated)]
174 #[doc(alias = "gtk_info_bar_set_revealed")]
175 #[doc(alias = "revealed")]
176 pub fn set_revealed(&self, revealed: bool) {
177 unsafe {
178 ffi::gtk_info_bar_set_revealed(self.to_glib_none().0, revealed.into_glib());
179 }
180 }
181
182 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
183 #[allow(deprecated)]
184 #[doc(alias = "gtk_info_bar_set_show_close_button")]
185 #[doc(alias = "show-close-button")]
186 pub fn set_show_close_button(&self, setting: bool) {
187 unsafe {
188 ffi::gtk_info_bar_set_show_close_button(self.to_glib_none().0, setting.into_glib());
189 }
190 }
191
192 #[doc(alias = "close")]
193 pub fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
194 unsafe extern "C" fn close_trampoline<F: Fn(&InfoBar) + 'static>(
195 this: *mut ffi::GtkInfoBar,
196 f: glib::ffi::gpointer,
197 ) {
198 let f: &F = &*(f as *const F);
199 f(&from_glib_borrow(this))
200 }
201 unsafe {
202 let f: Box_<F> = Box_::new(f);
203 connect_raw(
204 self.as_ptr() as *mut _,
205 c"close".as_ptr() as *const _,
206 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
207 close_trampoline::<F> as *const (),
208 )),
209 Box_::into_raw(f),
210 )
211 }
212 }
213
214 pub fn emit_close(&self) {
215 self.emit_by_name::<()>("close", &[]);
216 }
217
218 #[doc(alias = "response")]
219 pub fn connect_response<F: Fn(&Self, ResponseType) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe extern "C" fn response_trampoline<F: Fn(&InfoBar, ResponseType) + 'static>(
221 this: *mut ffi::GtkInfoBar,
222 response_id: ffi::GtkResponseType,
223 f: glib::ffi::gpointer,
224 ) {
225 let f: &F = &*(f as *const F);
226 f(&from_glib_borrow(this), from_glib(response_id))
227 }
228 unsafe {
229 let f: Box_<F> = Box_::new(f);
230 connect_raw(
231 self.as_ptr() as *mut _,
232 c"response".as_ptr() as *const _,
233 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234 response_trampoline::<F> as *const (),
235 )),
236 Box_::into_raw(f),
237 )
238 }
239 }
240
241 #[doc(alias = "message-type")]
242 pub fn connect_message_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
243 unsafe extern "C" fn notify_message_type_trampoline<F: Fn(&InfoBar) + 'static>(
244 this: *mut ffi::GtkInfoBar,
245 _param_spec: glib::ffi::gpointer,
246 f: glib::ffi::gpointer,
247 ) {
248 let f: &F = &*(f as *const F);
249 f(&from_glib_borrow(this))
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 c"notify::message-type".as_ptr() as *const _,
256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257 notify_message_type_trampoline::<F> as *const (),
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263
264 #[doc(alias = "revealed")]
265 pub fn connect_revealed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266 unsafe extern "C" fn notify_revealed_trampoline<F: Fn(&InfoBar) + 'static>(
267 this: *mut ffi::GtkInfoBar,
268 _param_spec: glib::ffi::gpointer,
269 f: glib::ffi::gpointer,
270 ) {
271 let f: &F = &*(f as *const F);
272 f(&from_glib_borrow(this))
273 }
274 unsafe {
275 let f: Box_<F> = Box_::new(f);
276 connect_raw(
277 self.as_ptr() as *mut _,
278 c"notify::revealed".as_ptr() as *const _,
279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280 notify_revealed_trampoline::<F> as *const (),
281 )),
282 Box_::into_raw(f),
283 )
284 }
285 }
286
287 #[doc(alias = "show-close-button")]
288 pub fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(
289 &self,
290 f: F,
291 ) -> SignalHandlerId {
292 unsafe extern "C" fn notify_show_close_button_trampoline<F: Fn(&InfoBar) + 'static>(
293 this: *mut ffi::GtkInfoBar,
294 _param_spec: glib::ffi::gpointer,
295 f: glib::ffi::gpointer,
296 ) {
297 let f: &F = &*(f as *const F);
298 f(&from_glib_borrow(this))
299 }
300 unsafe {
301 let f: Box_<F> = Box_::new(f);
302 connect_raw(
303 self.as_ptr() as *mut _,
304 c"notify::show-close-button".as_ptr() as *const _,
305 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
306 notify_show_close_button_trampoline::<F> as *const (),
307 )),
308 Box_::into_raw(f),
309 )
310 }
311 }
312}
313
314impl Default for InfoBar {
315 fn default() -> Self {
316 Self::new()
317 }
318}
319
320#[must_use = "The builder must be built to be used"]
325pub struct InfoBarBuilder {
326 builder: glib::object::ObjectBuilder<'static, InfoBar>,
327}
328
329impl InfoBarBuilder {
330 fn new() -> Self {
331 Self {
332 builder: glib::object::Object::builder(),
333 }
334 }
335
336 pub fn message_type(self, message_type: MessageType) -> Self {
337 Self {
338 builder: self.builder.property("message-type", message_type),
339 }
340 }
341
342 pub fn revealed(self, revealed: bool) -> Self {
343 Self {
344 builder: self.builder.property("revealed", revealed),
345 }
346 }
347
348 pub fn show_close_button(self, show_close_button: bool) -> Self {
349 Self {
350 builder: self
351 .builder
352 .property("show-close-button", show_close_button),
353 }
354 }
355
356 pub fn can_focus(self, can_focus: bool) -> Self {
357 Self {
358 builder: self.builder.property("can-focus", can_focus),
359 }
360 }
361
362 pub fn can_target(self, can_target: bool) -> Self {
363 Self {
364 builder: self.builder.property("can-target", can_target),
365 }
366 }
367
368 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
369 Self {
370 builder: self.builder.property("css-classes", css_classes.into()),
371 }
372 }
373
374 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
375 Self {
376 builder: self.builder.property("css-name", css_name.into()),
377 }
378 }
379
380 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
381 Self {
382 builder: self.builder.property("cursor", cursor.clone()),
383 }
384 }
385
386 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
387 Self {
388 builder: self.builder.property("focus-on-click", focus_on_click),
389 }
390 }
391
392 pub fn focusable(self, focusable: bool) -> Self {
393 Self {
394 builder: self.builder.property("focusable", focusable),
395 }
396 }
397
398 pub fn halign(self, halign: Align) -> Self {
399 Self {
400 builder: self.builder.property("halign", halign),
401 }
402 }
403
404 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
405 Self {
406 builder: self.builder.property("has-tooltip", has_tooltip),
407 }
408 }
409
410 pub fn height_request(self, height_request: i32) -> Self {
411 Self {
412 builder: self.builder.property("height-request", height_request),
413 }
414 }
415
416 pub fn hexpand(self, hexpand: bool) -> Self {
417 Self {
418 builder: self.builder.property("hexpand", hexpand),
419 }
420 }
421
422 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
423 Self {
424 builder: self.builder.property("hexpand-set", hexpand_set),
425 }
426 }
427
428 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
429 Self {
430 builder: self
431 .builder
432 .property("layout-manager", layout_manager.clone().upcast()),
433 }
434 }
435
436 #[cfg(feature = "v4_18")]
437 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
438 pub fn limit_events(self, limit_events: bool) -> Self {
439 Self {
440 builder: self.builder.property("limit-events", limit_events),
441 }
442 }
443
444 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
445 Self {
446 builder: self.builder.property("margin-bottom", margin_bottom),
447 }
448 }
449
450 pub fn margin_end(self, margin_end: i32) -> Self {
451 Self {
452 builder: self.builder.property("margin-end", margin_end),
453 }
454 }
455
456 pub fn margin_start(self, margin_start: i32) -> Self {
457 Self {
458 builder: self.builder.property("margin-start", margin_start),
459 }
460 }
461
462 pub fn margin_top(self, margin_top: i32) -> Self {
463 Self {
464 builder: self.builder.property("margin-top", margin_top),
465 }
466 }
467
468 pub fn name(self, name: impl Into<glib::GString>) -> Self {
469 Self {
470 builder: self.builder.property("name", name.into()),
471 }
472 }
473
474 pub fn opacity(self, opacity: f64) -> Self {
475 Self {
476 builder: self.builder.property("opacity", opacity),
477 }
478 }
479
480 pub fn overflow(self, overflow: Overflow) -> Self {
481 Self {
482 builder: self.builder.property("overflow", overflow),
483 }
484 }
485
486 pub fn receives_default(self, receives_default: bool) -> Self {
487 Self {
488 builder: self.builder.property("receives-default", receives_default),
489 }
490 }
491
492 pub fn sensitive(self, sensitive: bool) -> Self {
493 Self {
494 builder: self.builder.property("sensitive", sensitive),
495 }
496 }
497
498 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
499 Self {
500 builder: self
501 .builder
502 .property("tooltip-markup", tooltip_markup.into()),
503 }
504 }
505
506 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
507 Self {
508 builder: self.builder.property("tooltip-text", tooltip_text.into()),
509 }
510 }
511
512 pub fn valign(self, valign: Align) -> Self {
513 Self {
514 builder: self.builder.property("valign", valign),
515 }
516 }
517
518 pub fn vexpand(self, vexpand: bool) -> Self {
519 Self {
520 builder: self.builder.property("vexpand", vexpand),
521 }
522 }
523
524 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
525 Self {
526 builder: self.builder.property("vexpand-set", vexpand_set),
527 }
528 }
529
530 pub fn visible(self, visible: bool) -> Self {
531 Self {
532 builder: self.builder.property("visible", visible),
533 }
534 }
535
536 pub fn width_request(self, width_request: i32) -> Self {
537 Self {
538 builder: self.builder.property("width-request", width_request),
539 }
540 }
541
542 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
543 Self {
544 builder: self.builder.property("accessible-role", accessible_role),
545 }
546 }
547
548 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
551 pub fn build(self) -> InfoBar {
552 assert_initialized_main_thread!();
553 self.builder.build()
554 }
555}