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