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