1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
8 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 = "GtkStatusbar")]
20 pub struct Statusbar(Object<ffi::GtkStatusbar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
21
22 match fn {
23 type_ => || ffi::gtk_statusbar_get_type(),
24 }
25}
26
27impl Statusbar {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_statusbar_new")]
31 pub fn new() -> Statusbar {
32 assert_initialized_main_thread!();
33 unsafe { Widget::from_glib_none(ffi::gtk_statusbar_new()).unsafe_cast() }
34 }
35
36 pub fn builder() -> StatusbarBuilder {
41 StatusbarBuilder::new()
42 }
43
44 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
45 #[allow(deprecated)]
46 #[doc(alias = "gtk_statusbar_get_context_id")]
47 #[doc(alias = "get_context_id")]
48 pub fn context_id(&self, context_description: &str) -> u32 {
49 unsafe {
50 ffi::gtk_statusbar_get_context_id(
51 self.to_glib_none().0,
52 context_description.to_glib_none().0,
53 )
54 }
55 }
56
57 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
58 #[allow(deprecated)]
59 #[doc(alias = "gtk_statusbar_pop")]
60 pub fn pop(&self, context_id: u32) {
61 unsafe {
62 ffi::gtk_statusbar_pop(self.to_glib_none().0, context_id);
63 }
64 }
65
66 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
67 #[allow(deprecated)]
68 #[doc(alias = "gtk_statusbar_push")]
69 pub fn push(&self, context_id: u32, text: &str) -> u32 {
70 unsafe { ffi::gtk_statusbar_push(self.to_glib_none().0, context_id, text.to_glib_none().0) }
71 }
72
73 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
74 #[allow(deprecated)]
75 #[doc(alias = "gtk_statusbar_remove")]
76 pub fn remove(&self, context_id: u32, message_id: u32) {
77 unsafe {
78 ffi::gtk_statusbar_remove(self.to_glib_none().0, context_id, message_id);
79 }
80 }
81
82 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
83 #[allow(deprecated)]
84 #[doc(alias = "gtk_statusbar_remove_all")]
85 pub fn remove_all(&self, context_id: u32) {
86 unsafe {
87 ffi::gtk_statusbar_remove_all(self.to_glib_none().0, context_id);
88 }
89 }
90
91 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
92 #[doc(alias = "text-popped")]
93 pub fn connect_text_popped<F: Fn(&Self, u32, &str) + 'static>(&self, f: F) -> SignalHandlerId {
94 unsafe extern "C" fn text_popped_trampoline<F: Fn(&Statusbar, u32, &str) + 'static>(
95 this: *mut ffi::GtkStatusbar,
96 context_id: std::ffi::c_uint,
97 text: *mut std::ffi::c_char,
98 f: glib::ffi::gpointer,
99 ) {
100 let f: &F = &*(f as *const F);
101 f(
102 &from_glib_borrow(this),
103 context_id,
104 &glib::GString::from_glib_borrow(text),
105 )
106 }
107 unsafe {
108 let f: Box_<F> = Box_::new(f);
109 connect_raw(
110 self.as_ptr() as *mut _,
111 c"text-popped".as_ptr() as *const _,
112 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
113 text_popped_trampoline::<F> as *const (),
114 )),
115 Box_::into_raw(f),
116 )
117 }
118 }
119
120 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
121 #[doc(alias = "text-pushed")]
122 pub fn connect_text_pushed<F: Fn(&Self, u32, &str) + 'static>(&self, f: F) -> SignalHandlerId {
123 unsafe extern "C" fn text_pushed_trampoline<F: Fn(&Statusbar, u32, &str) + 'static>(
124 this: *mut ffi::GtkStatusbar,
125 context_id: std::ffi::c_uint,
126 text: *mut std::ffi::c_char,
127 f: glib::ffi::gpointer,
128 ) {
129 let f: &F = &*(f as *const F);
130 f(
131 &from_glib_borrow(this),
132 context_id,
133 &glib::GString::from_glib_borrow(text),
134 )
135 }
136 unsafe {
137 let f: Box_<F> = Box_::new(f);
138 connect_raw(
139 self.as_ptr() as *mut _,
140 c"text-pushed".as_ptr() as *const _,
141 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142 text_pushed_trampoline::<F> as *const (),
143 )),
144 Box_::into_raw(f),
145 )
146 }
147 }
148}
149
150impl Default for Statusbar {
151 fn default() -> Self {
152 Self::new()
153 }
154}
155
156#[must_use = "The builder must be built to be used"]
161pub struct StatusbarBuilder {
162 builder: glib::object::ObjectBuilder<'static, Statusbar>,
163}
164
165impl StatusbarBuilder {
166 fn new() -> Self {
167 Self {
168 builder: glib::object::Object::builder(),
169 }
170 }
171
172 pub fn can_focus(self, can_focus: bool) -> Self {
173 Self {
174 builder: self.builder.property("can-focus", can_focus),
175 }
176 }
177
178 pub fn can_target(self, can_target: bool) -> Self {
179 Self {
180 builder: self.builder.property("can-target", can_target),
181 }
182 }
183
184 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
185 Self {
186 builder: self.builder.property("css-classes", css_classes.into()),
187 }
188 }
189
190 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
191 Self {
192 builder: self.builder.property("css-name", css_name.into()),
193 }
194 }
195
196 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
197 Self {
198 builder: self.builder.property("cursor", cursor.clone()),
199 }
200 }
201
202 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
203 Self {
204 builder: self.builder.property("focus-on-click", focus_on_click),
205 }
206 }
207
208 pub fn focusable(self, focusable: bool) -> Self {
209 Self {
210 builder: self.builder.property("focusable", focusable),
211 }
212 }
213
214 pub fn halign(self, halign: Align) -> Self {
215 Self {
216 builder: self.builder.property("halign", halign),
217 }
218 }
219
220 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
221 Self {
222 builder: self.builder.property("has-tooltip", has_tooltip),
223 }
224 }
225
226 pub fn height_request(self, height_request: i32) -> Self {
227 Self {
228 builder: self.builder.property("height-request", height_request),
229 }
230 }
231
232 pub fn hexpand(self, hexpand: bool) -> Self {
233 Self {
234 builder: self.builder.property("hexpand", hexpand),
235 }
236 }
237
238 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
239 Self {
240 builder: self.builder.property("hexpand-set", hexpand_set),
241 }
242 }
243
244 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
245 Self {
246 builder: self
247 .builder
248 .property("layout-manager", layout_manager.clone().upcast()),
249 }
250 }
251
252 #[cfg(feature = "v4_18")]
253 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
254 pub fn limit_events(self, limit_events: bool) -> Self {
255 Self {
256 builder: self.builder.property("limit-events", limit_events),
257 }
258 }
259
260 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
261 Self {
262 builder: self.builder.property("margin-bottom", margin_bottom),
263 }
264 }
265
266 pub fn margin_end(self, margin_end: i32) -> Self {
267 Self {
268 builder: self.builder.property("margin-end", margin_end),
269 }
270 }
271
272 pub fn margin_start(self, margin_start: i32) -> Self {
273 Self {
274 builder: self.builder.property("margin-start", margin_start),
275 }
276 }
277
278 pub fn margin_top(self, margin_top: i32) -> Self {
279 Self {
280 builder: self.builder.property("margin-top", margin_top),
281 }
282 }
283
284 pub fn name(self, name: impl Into<glib::GString>) -> Self {
285 Self {
286 builder: self.builder.property("name", name.into()),
287 }
288 }
289
290 pub fn opacity(self, opacity: f64) -> Self {
291 Self {
292 builder: self.builder.property("opacity", opacity),
293 }
294 }
295
296 pub fn overflow(self, overflow: Overflow) -> Self {
297 Self {
298 builder: self.builder.property("overflow", overflow),
299 }
300 }
301
302 pub fn receives_default(self, receives_default: bool) -> Self {
303 Self {
304 builder: self.builder.property("receives-default", receives_default),
305 }
306 }
307
308 pub fn sensitive(self, sensitive: bool) -> Self {
309 Self {
310 builder: self.builder.property("sensitive", sensitive),
311 }
312 }
313
314 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
315 Self {
316 builder: self
317 .builder
318 .property("tooltip-markup", tooltip_markup.into()),
319 }
320 }
321
322 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
323 Self {
324 builder: self.builder.property("tooltip-text", tooltip_text.into()),
325 }
326 }
327
328 pub fn valign(self, valign: Align) -> Self {
329 Self {
330 builder: self.builder.property("valign", valign),
331 }
332 }
333
334 pub fn vexpand(self, vexpand: bool) -> Self {
335 Self {
336 builder: self.builder.property("vexpand", vexpand),
337 }
338 }
339
340 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
341 Self {
342 builder: self.builder.property("vexpand-set", vexpand_set),
343 }
344 }
345
346 pub fn visible(self, visible: bool) -> Self {
347 Self {
348 builder: self.builder.property("visible", visible),
349 }
350 }
351
352 pub fn width_request(self, width_request: i32) -> Self {
353 Self {
354 builder: self.builder.property("width-request", width_request),
355 }
356 }
357
358 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
359 Self {
360 builder: self.builder.property("accessible-role", accessible_role),
361 }
362 }
363
364 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
367 pub fn build(self) -> Statusbar {
368 assert_initialized_main_thread!();
369 self.builder.build()
370 }
371}