1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "PanelOmniBar")]
16 pub struct OmniBar(Object<ffi::PanelOmniBar, ffi::PanelOmniBarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::panel_omni_bar_get_type(),
20 }
21}
22
23impl OmniBar {
24 pub const NONE: Option<&'static OmniBar> = None;
25
26 #[doc(alias = "panel_omni_bar_new")]
27 pub fn new() -> OmniBar {
28 assert_initialized_main_thread!();
29 unsafe { gtk::Widget::from_glib_none(ffi::panel_omni_bar_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> OmniBarBuilder {
37 OmniBarBuilder::new()
38 }
39}
40
41impl Default for OmniBar {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47#[must_use = "The builder must be built to be used"]
52pub struct OmniBarBuilder {
53 builder: glib::object::ObjectBuilder<'static, OmniBar>,
54}
55
56impl OmniBarBuilder {
57 fn new() -> Self {
58 Self {
59 builder: glib::object::Object::builder(),
60 }
61 }
62
63 pub fn action_tooltip(self, action_tooltip: impl Into<glib::GString>) -> Self {
64 Self {
65 builder: self
66 .builder
67 .property("action-tooltip", action_tooltip.into()),
68 }
69 }
70
71 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
72 Self {
73 builder: self.builder.property("icon-name", icon_name.into()),
74 }
75 }
76
77 pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
78 Self {
79 builder: self
80 .builder
81 .property("menu-model", menu_model.clone().upcast()),
82 }
83 }
84
85 pub fn popover(self, popover: &impl IsA<gtk::Popover>) -> Self {
86 Self {
87 builder: self.builder.property("popover", popover.clone().upcast()),
88 }
89 }
90
91 pub fn progress(self, progress: f64) -> Self {
92 Self {
93 builder: self.builder.property("progress", progress),
94 }
95 }
96
97 pub fn can_focus(self, can_focus: bool) -> Self {
98 Self {
99 builder: self.builder.property("can-focus", can_focus),
100 }
101 }
102
103 pub fn can_target(self, can_target: bool) -> Self {
104 Self {
105 builder: self.builder.property("can-target", can_target),
106 }
107 }
108
109 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
110 Self {
111 builder: self.builder.property("css-classes", css_classes.into()),
112 }
113 }
114
115 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
116 Self {
117 builder: self.builder.property("css-name", css_name.into()),
118 }
119 }
120
121 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
122 Self {
123 builder: self.builder.property("cursor", cursor.clone()),
124 }
125 }
126
127 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
128 Self {
129 builder: self.builder.property("focus-on-click", focus_on_click),
130 }
131 }
132
133 pub fn focusable(self, focusable: bool) -> Self {
134 Self {
135 builder: self.builder.property("focusable", focusable),
136 }
137 }
138
139 pub fn halign(self, halign: gtk::Align) -> Self {
140 Self {
141 builder: self.builder.property("halign", halign),
142 }
143 }
144
145 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
146 Self {
147 builder: self.builder.property("has-tooltip", has_tooltip),
148 }
149 }
150
151 pub fn height_request(self, height_request: i32) -> Self {
152 Self {
153 builder: self.builder.property("height-request", height_request),
154 }
155 }
156
157 pub fn hexpand(self, hexpand: bool) -> Self {
158 Self {
159 builder: self.builder.property("hexpand", hexpand),
160 }
161 }
162
163 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
164 Self {
165 builder: self.builder.property("hexpand-set", hexpand_set),
166 }
167 }
168
169 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
170 Self {
171 builder: self
172 .builder
173 .property("layout-manager", layout_manager.clone().upcast()),
174 }
175 }
176
177 #[cfg(feature = "gtk_v4_18")]
178 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
179 pub fn limit_events(self, limit_events: bool) -> Self {
180 Self {
181 builder: self.builder.property("limit-events", limit_events),
182 }
183 }
184
185 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
186 Self {
187 builder: self.builder.property("margin-bottom", margin_bottom),
188 }
189 }
190
191 pub fn margin_end(self, margin_end: i32) -> Self {
192 Self {
193 builder: self.builder.property("margin-end", margin_end),
194 }
195 }
196
197 pub fn margin_start(self, margin_start: i32) -> Self {
198 Self {
199 builder: self.builder.property("margin-start", margin_start),
200 }
201 }
202
203 pub fn margin_top(self, margin_top: i32) -> Self {
204 Self {
205 builder: self.builder.property("margin-top", margin_top),
206 }
207 }
208
209 pub fn name(self, name: impl Into<glib::GString>) -> Self {
210 Self {
211 builder: self.builder.property("name", name.into()),
212 }
213 }
214
215 pub fn opacity(self, opacity: f64) -> Self {
216 Self {
217 builder: self.builder.property("opacity", opacity),
218 }
219 }
220
221 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
222 Self {
223 builder: self.builder.property("overflow", overflow),
224 }
225 }
226
227 pub fn receives_default(self, receives_default: bool) -> Self {
228 Self {
229 builder: self.builder.property("receives-default", receives_default),
230 }
231 }
232
233 pub fn sensitive(self, sensitive: bool) -> Self {
234 Self {
235 builder: self.builder.property("sensitive", sensitive),
236 }
237 }
238
239 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
240 Self {
241 builder: self
242 .builder
243 .property("tooltip-markup", tooltip_markup.into()),
244 }
245 }
246
247 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
248 Self {
249 builder: self.builder.property("tooltip-text", tooltip_text.into()),
250 }
251 }
252
253 pub fn valign(self, valign: gtk::Align) -> Self {
254 Self {
255 builder: self.builder.property("valign", valign),
256 }
257 }
258
259 pub fn vexpand(self, vexpand: bool) -> Self {
260 Self {
261 builder: self.builder.property("vexpand", vexpand),
262 }
263 }
264
265 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
266 Self {
267 builder: self.builder.property("vexpand-set", vexpand_set),
268 }
269 }
270
271 pub fn visible(self, visible: bool) -> Self {
272 Self {
273 builder: self.builder.property("visible", visible),
274 }
275 }
276
277 pub fn width_request(self, width_request: i32) -> Self {
278 Self {
279 builder: self.builder.property("width-request", width_request),
280 }
281 }
282
283 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
284 Self {
285 builder: self.builder.property("accessible-role", accessible_role),
286 }
287 }
288
289 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
292 pub fn build(self) -> OmniBar {
293 assert_initialized_main_thread!();
294 self.builder.build()
295 }
296}
297
298pub trait OmniBarExt: IsA<OmniBar> + 'static {
299 #[doc(alias = "panel_omni_bar_add_prefix")]
300 fn add_prefix(&self, priority: i32, widget: &impl IsA<gtk::Widget>) {
301 unsafe {
302 ffi::panel_omni_bar_add_prefix(
303 self.as_ref().to_glib_none().0,
304 priority,
305 widget.as_ref().to_glib_none().0,
306 );
307 }
308 }
309
310 #[doc(alias = "panel_omni_bar_add_suffix")]
311 fn add_suffix(&self, priority: i32, widget: &impl IsA<gtk::Widget>) {
312 unsafe {
313 ffi::panel_omni_bar_add_suffix(
314 self.as_ref().to_glib_none().0,
315 priority,
316 widget.as_ref().to_glib_none().0,
317 );
318 }
319 }
320
321 #[doc(alias = "panel_omni_bar_get_popover")]
322 #[doc(alias = "get_popover")]
323 fn popover(&self) -> Option<gtk::Popover> {
324 unsafe {
325 from_glib_none(ffi::panel_omni_bar_get_popover(
326 self.as_ref().to_glib_none().0,
327 ))
328 }
329 }
330
331 #[doc(alias = "panel_omni_bar_get_progress")]
332 #[doc(alias = "get_progress")]
333 fn progress(&self) -> f64 {
334 unsafe { ffi::panel_omni_bar_get_progress(self.as_ref().to_glib_none().0) }
335 }
336
337 #[doc(alias = "panel_omni_bar_remove")]
338 fn remove(&self, widget: &impl IsA<gtk::Widget>) {
339 unsafe {
340 ffi::panel_omni_bar_remove(
341 self.as_ref().to_glib_none().0,
342 widget.as_ref().to_glib_none().0,
343 );
344 }
345 }
346
347 #[doc(alias = "panel_omni_bar_set_popover")]
348 #[doc(alias = "popover")]
349 fn set_popover(&self, popover: Option<&impl IsA<gtk::Popover>>) {
350 unsafe {
351 ffi::panel_omni_bar_set_popover(
352 self.as_ref().to_glib_none().0,
353 popover.map(|p| p.as_ref()).to_glib_none().0,
354 );
355 }
356 }
357
358 #[doc(alias = "panel_omni_bar_set_progress")]
359 #[doc(alias = "progress")]
360 fn set_progress(&self, progress: f64) {
361 unsafe {
362 ffi::panel_omni_bar_set_progress(self.as_ref().to_glib_none().0, progress);
363 }
364 }
365
366 #[doc(alias = "panel_omni_bar_start_pulsing")]
367 fn start_pulsing(&self) {
368 unsafe {
369 ffi::panel_omni_bar_start_pulsing(self.as_ref().to_glib_none().0);
370 }
371 }
372
373 #[doc(alias = "panel_omni_bar_stop_pulsing")]
374 fn stop_pulsing(&self) {
375 unsafe {
376 ffi::panel_omni_bar_stop_pulsing(self.as_ref().to_glib_none().0);
377 }
378 }
379
380 #[doc(alias = "action-tooltip")]
381 fn action_tooltip(&self) -> Option<glib::GString> {
382 ObjectExt::property(self.as_ref(), "action-tooltip")
383 }
384
385 #[doc(alias = "action-tooltip")]
386 fn set_action_tooltip(&self, action_tooltip: Option<&str>) {
387 ObjectExt::set_property(self.as_ref(), "action-tooltip", action_tooltip)
388 }
389
390 #[doc(alias = "icon-name")]
391 fn icon_name(&self) -> Option<glib::GString> {
392 ObjectExt::property(self.as_ref(), "icon-name")
393 }
394
395 #[doc(alias = "icon-name")]
396 fn set_icon_name(&self, icon_name: Option<&str>) {
397 ObjectExt::set_property(self.as_ref(), "icon-name", icon_name)
398 }
399
400 #[doc(alias = "menu-model")]
401 fn menu_model(&self) -> Option<gio::MenuModel> {
402 ObjectExt::property(self.as_ref(), "menu-model")
403 }
404
405 #[doc(alias = "menu-model")]
406 fn set_menu_model<P: IsA<gio::MenuModel>>(&self, menu_model: Option<&P>) {
407 ObjectExt::set_property(self.as_ref(), "menu-model", menu_model)
408 }
409
410 #[doc(alias = "action-tooltip")]
411 fn connect_action_tooltip_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
412 unsafe extern "C" fn notify_action_tooltip_trampoline<
413 P: IsA<OmniBar>,
414 F: Fn(&P) + 'static,
415 >(
416 this: *mut ffi::PanelOmniBar,
417 _param_spec: glib::ffi::gpointer,
418 f: glib::ffi::gpointer,
419 ) {
420 let f: &F = &*(f as *const F);
421 f(OmniBar::from_glib_borrow(this).unsafe_cast_ref())
422 }
423 unsafe {
424 let f: Box_<F> = Box_::new(f);
425 connect_raw(
426 self.as_ptr() as *mut _,
427 c"notify::action-tooltip".as_ptr() as *const _,
428 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
429 notify_action_tooltip_trampoline::<Self, F> as *const (),
430 )),
431 Box_::into_raw(f),
432 )
433 }
434 }
435
436 #[doc(alias = "icon-name")]
437 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
438 unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<OmniBar>, F: Fn(&P) + 'static>(
439 this: *mut ffi::PanelOmniBar,
440 _param_spec: glib::ffi::gpointer,
441 f: glib::ffi::gpointer,
442 ) {
443 let f: &F = &*(f as *const F);
444 f(OmniBar::from_glib_borrow(this).unsafe_cast_ref())
445 }
446 unsafe {
447 let f: Box_<F> = Box_::new(f);
448 connect_raw(
449 self.as_ptr() as *mut _,
450 c"notify::icon-name".as_ptr() as *const _,
451 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
452 notify_icon_name_trampoline::<Self, F> as *const (),
453 )),
454 Box_::into_raw(f),
455 )
456 }
457 }
458
459 #[doc(alias = "menu-model")]
460 fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
461 unsafe extern "C" fn notify_menu_model_trampoline<P: IsA<OmniBar>, F: Fn(&P) + 'static>(
462 this: *mut ffi::PanelOmniBar,
463 _param_spec: glib::ffi::gpointer,
464 f: glib::ffi::gpointer,
465 ) {
466 let f: &F = &*(f as *const F);
467 f(OmniBar::from_glib_borrow(this).unsafe_cast_ref())
468 }
469 unsafe {
470 let f: Box_<F> = Box_::new(f);
471 connect_raw(
472 self.as_ptr() as *mut _,
473 c"notify::menu-model".as_ptr() as *const _,
474 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
475 notify_menu_model_trampoline::<Self, F> as *const (),
476 )),
477 Box_::into_raw(f),
478 )
479 }
480 }
481
482 #[doc(alias = "popover")]
483 fn connect_popover_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
484 unsafe extern "C" fn notify_popover_trampoline<P: IsA<OmniBar>, F: Fn(&P) + 'static>(
485 this: *mut ffi::PanelOmniBar,
486 _param_spec: glib::ffi::gpointer,
487 f: glib::ffi::gpointer,
488 ) {
489 let f: &F = &*(f as *const F);
490 f(OmniBar::from_glib_borrow(this).unsafe_cast_ref())
491 }
492 unsafe {
493 let f: Box_<F> = Box_::new(f);
494 connect_raw(
495 self.as_ptr() as *mut _,
496 c"notify::popover".as_ptr() as *const _,
497 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498 notify_popover_trampoline::<Self, F> as *const (),
499 )),
500 Box_::into_raw(f),
501 )
502 }
503 }
504
505 #[doc(alias = "progress")]
506 fn connect_progress_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
507 unsafe extern "C" fn notify_progress_trampoline<P: IsA<OmniBar>, F: Fn(&P) + 'static>(
508 this: *mut ffi::PanelOmniBar,
509 _param_spec: glib::ffi::gpointer,
510 f: glib::ffi::gpointer,
511 ) {
512 let f: &F = &*(f as *const F);
513 f(OmniBar::from_glib_borrow(this).unsafe_cast_ref())
514 }
515 unsafe {
516 let f: Box_<F> = Box_::new(f);
517 connect_raw(
518 self.as_ptr() as *mut _,
519 c"notify::progress".as_ptr() as *const _,
520 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
521 notify_progress_trampoline::<Self, F> as *const (),
522 )),
523 Box_::into_raw(f),
524 )
525 }
526 }
527}
528
529impl<O: IsA<OmniBar>> OmniBarExt for O {}