gtk4/auto/
calendar.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7    Widget,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    #[doc(alias = "GtkCalendar")]
19    pub struct Calendar(Object<ffi::GtkCalendar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
20
21    match fn {
22        type_ => || ffi::gtk_calendar_get_type(),
23    }
24}
25
26impl Calendar {
27    #[doc(alias = "gtk_calendar_new")]
28    pub fn new() -> Calendar {
29        assert_initialized_main_thread!();
30        unsafe { Widget::from_glib_none(ffi::gtk_calendar_new()).unsafe_cast() }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`Calendar`] objects.
35    ///
36    /// This method returns an instance of [`CalendarBuilder`](crate::builders::CalendarBuilder) which can be used to create [`Calendar`] objects.
37    pub fn builder() -> CalendarBuilder {
38        CalendarBuilder::new()
39    }
40
41    #[doc(alias = "gtk_calendar_clear_marks")]
42    pub fn clear_marks(&self) {
43        unsafe {
44            ffi::gtk_calendar_clear_marks(self.to_glib_none().0);
45        }
46    }
47
48    #[doc(alias = "gtk_calendar_get_date")]
49    #[doc(alias = "get_date")]
50    pub fn date(&self) -> glib::DateTime {
51        unsafe { from_glib_full(ffi::gtk_calendar_get_date(self.to_glib_none().0)) }
52    }
53
54    #[cfg(feature = "v4_14")]
55    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
56    #[doc(alias = "gtk_calendar_get_day")]
57    #[doc(alias = "get_day")]
58    pub fn day(&self) -> i32 {
59        unsafe { ffi::gtk_calendar_get_day(self.to_glib_none().0) }
60    }
61
62    #[doc(alias = "gtk_calendar_get_day_is_marked")]
63    #[doc(alias = "get_day_is_marked")]
64    pub fn day_is_marked(&self, day: u32) -> bool {
65        unsafe {
66            from_glib(ffi::gtk_calendar_get_day_is_marked(
67                self.to_glib_none().0,
68                day,
69            ))
70        }
71    }
72
73    #[cfg(feature = "v4_14")]
74    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
75    #[doc(alias = "gtk_calendar_get_month")]
76    #[doc(alias = "get_month")]
77    pub fn month(&self) -> i32 {
78        unsafe { ffi::gtk_calendar_get_month(self.to_glib_none().0) }
79    }
80
81    #[doc(alias = "gtk_calendar_get_show_day_names")]
82    #[doc(alias = "get_show_day_names")]
83    #[doc(alias = "show-day-names")]
84    pub fn shows_day_names(&self) -> bool {
85        unsafe { from_glib(ffi::gtk_calendar_get_show_day_names(self.to_glib_none().0)) }
86    }
87
88    #[doc(alias = "gtk_calendar_get_show_heading")]
89    #[doc(alias = "get_show_heading")]
90    #[doc(alias = "show-heading")]
91    pub fn shows_heading(&self) -> bool {
92        unsafe { from_glib(ffi::gtk_calendar_get_show_heading(self.to_glib_none().0)) }
93    }
94
95    #[doc(alias = "gtk_calendar_get_show_week_numbers")]
96    #[doc(alias = "get_show_week_numbers")]
97    #[doc(alias = "show-week-numbers")]
98    pub fn shows_week_numbers(&self) -> bool {
99        unsafe {
100            from_glib(ffi::gtk_calendar_get_show_week_numbers(
101                self.to_glib_none().0,
102            ))
103        }
104    }
105
106    #[cfg(feature = "v4_14")]
107    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
108    #[doc(alias = "gtk_calendar_get_year")]
109    #[doc(alias = "get_year")]
110    pub fn year(&self) -> i32 {
111        unsafe { ffi::gtk_calendar_get_year(self.to_glib_none().0) }
112    }
113
114    #[doc(alias = "gtk_calendar_mark_day")]
115    pub fn mark_day(&self, day: u32) {
116        unsafe {
117            ffi::gtk_calendar_mark_day(self.to_glib_none().0, day);
118        }
119    }
120
121    #[doc(alias = "gtk_calendar_select_day")]
122    pub fn select_day(&self, date: &glib::DateTime) {
123        unsafe {
124            ffi::gtk_calendar_select_day(self.to_glib_none().0, date.to_glib_none().0);
125        }
126    }
127
128    #[cfg(feature = "v4_14")]
129    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
130    #[doc(alias = "gtk_calendar_set_day")]
131    #[doc(alias = "day")]
132    pub fn set_day(&self, day: i32) {
133        unsafe {
134            ffi::gtk_calendar_set_day(self.to_glib_none().0, day);
135        }
136    }
137
138    #[cfg(feature = "v4_14")]
139    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
140    #[doc(alias = "gtk_calendar_set_month")]
141    #[doc(alias = "month")]
142    pub fn set_month(&self, month: i32) {
143        unsafe {
144            ffi::gtk_calendar_set_month(self.to_glib_none().0, month);
145        }
146    }
147
148    #[doc(alias = "gtk_calendar_set_show_day_names")]
149    #[doc(alias = "show-day-names")]
150    pub fn set_show_day_names(&self, value: bool) {
151        unsafe {
152            ffi::gtk_calendar_set_show_day_names(self.to_glib_none().0, value.into_glib());
153        }
154    }
155
156    #[doc(alias = "gtk_calendar_set_show_heading")]
157    #[doc(alias = "show-heading")]
158    pub fn set_show_heading(&self, value: bool) {
159        unsafe {
160            ffi::gtk_calendar_set_show_heading(self.to_glib_none().0, value.into_glib());
161        }
162    }
163
164    #[doc(alias = "gtk_calendar_set_show_week_numbers")]
165    #[doc(alias = "show-week-numbers")]
166    pub fn set_show_week_numbers(&self, value: bool) {
167        unsafe {
168            ffi::gtk_calendar_set_show_week_numbers(self.to_glib_none().0, value.into_glib());
169        }
170    }
171
172    #[cfg(feature = "v4_14")]
173    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
174    #[doc(alias = "gtk_calendar_set_year")]
175    #[doc(alias = "year")]
176    pub fn set_year(&self, year: i32) {
177        unsafe {
178            ffi::gtk_calendar_set_year(self.to_glib_none().0, year);
179        }
180    }
181
182    #[doc(alias = "gtk_calendar_unmark_day")]
183    pub fn unmark_day(&self, day: u32) {
184        unsafe {
185            ffi::gtk_calendar_unmark_day(self.to_glib_none().0, day);
186        }
187    }
188
189    #[doc(alias = "day-selected")]
190    pub fn connect_day_selected<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
191        unsafe extern "C" fn day_selected_trampoline<F: Fn(&Calendar) + 'static>(
192            this: *mut ffi::GtkCalendar,
193            f: glib::ffi::gpointer,
194        ) {
195            let f: &F = &*(f as *const F);
196            f(&from_glib_borrow(this))
197        }
198        unsafe {
199            let f: Box_<F> = Box_::new(f);
200            connect_raw(
201                self.as_ptr() as *mut _,
202                b"day-selected\0".as_ptr() as *const _,
203                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
204                    day_selected_trampoline::<F> as *const (),
205                )),
206                Box_::into_raw(f),
207            )
208        }
209    }
210
211    #[doc(alias = "next-month")]
212    pub fn connect_next_month<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
213        unsafe extern "C" fn next_month_trampoline<F: Fn(&Calendar) + 'static>(
214            this: *mut ffi::GtkCalendar,
215            f: glib::ffi::gpointer,
216        ) {
217            let f: &F = &*(f as *const F);
218            f(&from_glib_borrow(this))
219        }
220        unsafe {
221            let f: Box_<F> = Box_::new(f);
222            connect_raw(
223                self.as_ptr() as *mut _,
224                b"next-month\0".as_ptr() as *const _,
225                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
226                    next_month_trampoline::<F> as *const (),
227                )),
228                Box_::into_raw(f),
229            )
230        }
231    }
232
233    #[doc(alias = "next-year")]
234    pub fn connect_next_year<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
235        unsafe extern "C" fn next_year_trampoline<F: Fn(&Calendar) + 'static>(
236            this: *mut ffi::GtkCalendar,
237            f: glib::ffi::gpointer,
238        ) {
239            let f: &F = &*(f as *const F);
240            f(&from_glib_borrow(this))
241        }
242        unsafe {
243            let f: Box_<F> = Box_::new(f);
244            connect_raw(
245                self.as_ptr() as *mut _,
246                b"next-year\0".as_ptr() as *const _,
247                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
248                    next_year_trampoline::<F> as *const (),
249                )),
250                Box_::into_raw(f),
251            )
252        }
253    }
254
255    #[doc(alias = "prev-month")]
256    pub fn connect_prev_month<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
257        unsafe extern "C" fn prev_month_trampoline<F: Fn(&Calendar) + 'static>(
258            this: *mut ffi::GtkCalendar,
259            f: glib::ffi::gpointer,
260        ) {
261            let f: &F = &*(f as *const F);
262            f(&from_glib_borrow(this))
263        }
264        unsafe {
265            let f: Box_<F> = Box_::new(f);
266            connect_raw(
267                self.as_ptr() as *mut _,
268                b"prev-month\0".as_ptr() as *const _,
269                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270                    prev_month_trampoline::<F> as *const (),
271                )),
272                Box_::into_raw(f),
273            )
274        }
275    }
276
277    #[doc(alias = "prev-year")]
278    pub fn connect_prev_year<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
279        unsafe extern "C" fn prev_year_trampoline<F: Fn(&Calendar) + 'static>(
280            this: *mut ffi::GtkCalendar,
281            f: glib::ffi::gpointer,
282        ) {
283            let f: &F = &*(f as *const F);
284            f(&from_glib_borrow(this))
285        }
286        unsafe {
287            let f: Box_<F> = Box_::new(f);
288            connect_raw(
289                self.as_ptr() as *mut _,
290                b"prev-year\0".as_ptr() as *const _,
291                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292                    prev_year_trampoline::<F> as *const (),
293                )),
294                Box_::into_raw(f),
295            )
296        }
297    }
298
299    #[doc(alias = "day")]
300    pub fn connect_day_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
301        unsafe extern "C" fn notify_day_trampoline<F: Fn(&Calendar) + 'static>(
302            this: *mut ffi::GtkCalendar,
303            _param_spec: glib::ffi::gpointer,
304            f: glib::ffi::gpointer,
305        ) {
306            let f: &F = &*(f as *const F);
307            f(&from_glib_borrow(this))
308        }
309        unsafe {
310            let f: Box_<F> = Box_::new(f);
311            connect_raw(
312                self.as_ptr() as *mut _,
313                b"notify::day\0".as_ptr() as *const _,
314                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315                    notify_day_trampoline::<F> as *const (),
316                )),
317                Box_::into_raw(f),
318            )
319        }
320    }
321
322    #[doc(alias = "month")]
323    pub fn connect_month_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
324        unsafe extern "C" fn notify_month_trampoline<F: Fn(&Calendar) + 'static>(
325            this: *mut ffi::GtkCalendar,
326            _param_spec: glib::ffi::gpointer,
327            f: glib::ffi::gpointer,
328        ) {
329            let f: &F = &*(f as *const F);
330            f(&from_glib_borrow(this))
331        }
332        unsafe {
333            let f: Box_<F> = Box_::new(f);
334            connect_raw(
335                self.as_ptr() as *mut _,
336                b"notify::month\0".as_ptr() as *const _,
337                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
338                    notify_month_trampoline::<F> as *const (),
339                )),
340                Box_::into_raw(f),
341            )
342        }
343    }
344
345    #[doc(alias = "show-day-names")]
346    pub fn connect_show_day_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347        unsafe extern "C" fn notify_show_day_names_trampoline<F: Fn(&Calendar) + 'static>(
348            this: *mut ffi::GtkCalendar,
349            _param_spec: glib::ffi::gpointer,
350            f: glib::ffi::gpointer,
351        ) {
352            let f: &F = &*(f as *const F);
353            f(&from_glib_borrow(this))
354        }
355        unsafe {
356            let f: Box_<F> = Box_::new(f);
357            connect_raw(
358                self.as_ptr() as *mut _,
359                b"notify::show-day-names\0".as_ptr() as *const _,
360                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361                    notify_show_day_names_trampoline::<F> as *const (),
362                )),
363                Box_::into_raw(f),
364            )
365        }
366    }
367
368    #[doc(alias = "show-heading")]
369    pub fn connect_show_heading_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370        unsafe extern "C" fn notify_show_heading_trampoline<F: Fn(&Calendar) + 'static>(
371            this: *mut ffi::GtkCalendar,
372            _param_spec: glib::ffi::gpointer,
373            f: glib::ffi::gpointer,
374        ) {
375            let f: &F = &*(f as *const F);
376            f(&from_glib_borrow(this))
377        }
378        unsafe {
379            let f: Box_<F> = Box_::new(f);
380            connect_raw(
381                self.as_ptr() as *mut _,
382                b"notify::show-heading\0".as_ptr() as *const _,
383                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
384                    notify_show_heading_trampoline::<F> as *const (),
385                )),
386                Box_::into_raw(f),
387            )
388        }
389    }
390
391    #[doc(alias = "show-week-numbers")]
392    pub fn connect_show_week_numbers_notify<F: Fn(&Self) + 'static>(
393        &self,
394        f: F,
395    ) -> SignalHandlerId {
396        unsafe extern "C" fn notify_show_week_numbers_trampoline<F: Fn(&Calendar) + 'static>(
397            this: *mut ffi::GtkCalendar,
398            _param_spec: glib::ffi::gpointer,
399            f: glib::ffi::gpointer,
400        ) {
401            let f: &F = &*(f as *const F);
402            f(&from_glib_borrow(this))
403        }
404        unsafe {
405            let f: Box_<F> = Box_::new(f);
406            connect_raw(
407                self.as_ptr() as *mut _,
408                b"notify::show-week-numbers\0".as_ptr() as *const _,
409                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
410                    notify_show_week_numbers_trampoline::<F> as *const (),
411                )),
412                Box_::into_raw(f),
413            )
414        }
415    }
416
417    #[doc(alias = "year")]
418    pub fn connect_year_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
419        unsafe extern "C" fn notify_year_trampoline<F: Fn(&Calendar) + 'static>(
420            this: *mut ffi::GtkCalendar,
421            _param_spec: glib::ffi::gpointer,
422            f: glib::ffi::gpointer,
423        ) {
424            let f: &F = &*(f as *const F);
425            f(&from_glib_borrow(this))
426        }
427        unsafe {
428            let f: Box_<F> = Box_::new(f);
429            connect_raw(
430                self.as_ptr() as *mut _,
431                b"notify::year\0".as_ptr() as *const _,
432                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
433                    notify_year_trampoline::<F> as *const (),
434                )),
435                Box_::into_raw(f),
436            )
437        }
438    }
439}
440
441impl Default for Calendar {
442    fn default() -> Self {
443        Self::new()
444    }
445}
446
447// rustdoc-stripper-ignore-next
448/// A [builder-pattern] type to construct [`Calendar`] objects.
449///
450/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
451#[must_use = "The builder must be built to be used"]
452pub struct CalendarBuilder {
453    builder: glib::object::ObjectBuilder<'static, Calendar>,
454}
455
456impl CalendarBuilder {
457    fn new() -> Self {
458        Self {
459            builder: glib::object::Object::builder(),
460        }
461    }
462
463    pub fn day(self, day: i32) -> Self {
464        Self {
465            builder: self.builder.property("day", day),
466        }
467    }
468
469    pub fn month(self, month: i32) -> Self {
470        Self {
471            builder: self.builder.property("month", month),
472        }
473    }
474
475    pub fn show_day_names(self, show_day_names: bool) -> Self {
476        Self {
477            builder: self.builder.property("show-day-names", show_day_names),
478        }
479    }
480
481    pub fn show_heading(self, show_heading: bool) -> Self {
482        Self {
483            builder: self.builder.property("show-heading", show_heading),
484        }
485    }
486
487    pub fn show_week_numbers(self, show_week_numbers: bool) -> Self {
488        Self {
489            builder: self
490                .builder
491                .property("show-week-numbers", show_week_numbers),
492        }
493    }
494
495    pub fn year(self, year: i32) -> Self {
496        Self {
497            builder: self.builder.property("year", year),
498        }
499    }
500
501    pub fn can_focus(self, can_focus: bool) -> Self {
502        Self {
503            builder: self.builder.property("can-focus", can_focus),
504        }
505    }
506
507    pub fn can_target(self, can_target: bool) -> Self {
508        Self {
509            builder: self.builder.property("can-target", can_target),
510        }
511    }
512
513    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
514        Self {
515            builder: self.builder.property("css-classes", css_classes.into()),
516        }
517    }
518
519    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
520        Self {
521            builder: self.builder.property("css-name", css_name.into()),
522        }
523    }
524
525    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
526        Self {
527            builder: self.builder.property("cursor", cursor.clone()),
528        }
529    }
530
531    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
532        Self {
533            builder: self.builder.property("focus-on-click", focus_on_click),
534        }
535    }
536
537    pub fn focusable(self, focusable: bool) -> Self {
538        Self {
539            builder: self.builder.property("focusable", focusable),
540        }
541    }
542
543    pub fn halign(self, halign: Align) -> Self {
544        Self {
545            builder: self.builder.property("halign", halign),
546        }
547    }
548
549    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
550        Self {
551            builder: self.builder.property("has-tooltip", has_tooltip),
552        }
553    }
554
555    pub fn height_request(self, height_request: i32) -> Self {
556        Self {
557            builder: self.builder.property("height-request", height_request),
558        }
559    }
560
561    pub fn hexpand(self, hexpand: bool) -> Self {
562        Self {
563            builder: self.builder.property("hexpand", hexpand),
564        }
565    }
566
567    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
568        Self {
569            builder: self.builder.property("hexpand-set", hexpand_set),
570        }
571    }
572
573    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
574        Self {
575            builder: self
576                .builder
577                .property("layout-manager", layout_manager.clone().upcast()),
578        }
579    }
580
581    #[cfg(feature = "v4_18")]
582    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
583    pub fn limit_events(self, limit_events: bool) -> Self {
584        Self {
585            builder: self.builder.property("limit-events", limit_events),
586        }
587    }
588
589    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
590        Self {
591            builder: self.builder.property("margin-bottom", margin_bottom),
592        }
593    }
594
595    pub fn margin_end(self, margin_end: i32) -> Self {
596        Self {
597            builder: self.builder.property("margin-end", margin_end),
598        }
599    }
600
601    pub fn margin_start(self, margin_start: i32) -> Self {
602        Self {
603            builder: self.builder.property("margin-start", margin_start),
604        }
605    }
606
607    pub fn margin_top(self, margin_top: i32) -> Self {
608        Self {
609            builder: self.builder.property("margin-top", margin_top),
610        }
611    }
612
613    pub fn name(self, name: impl Into<glib::GString>) -> Self {
614        Self {
615            builder: self.builder.property("name", name.into()),
616        }
617    }
618
619    pub fn opacity(self, opacity: f64) -> Self {
620        Self {
621            builder: self.builder.property("opacity", opacity),
622        }
623    }
624
625    pub fn overflow(self, overflow: Overflow) -> Self {
626        Self {
627            builder: self.builder.property("overflow", overflow),
628        }
629    }
630
631    pub fn receives_default(self, receives_default: bool) -> Self {
632        Self {
633            builder: self.builder.property("receives-default", receives_default),
634        }
635    }
636
637    pub fn sensitive(self, sensitive: bool) -> Self {
638        Self {
639            builder: self.builder.property("sensitive", sensitive),
640        }
641    }
642
643    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
644        Self {
645            builder: self
646                .builder
647                .property("tooltip-markup", tooltip_markup.into()),
648        }
649    }
650
651    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
652        Self {
653            builder: self.builder.property("tooltip-text", tooltip_text.into()),
654        }
655    }
656
657    pub fn valign(self, valign: Align) -> Self {
658        Self {
659            builder: self.builder.property("valign", valign),
660        }
661    }
662
663    pub fn vexpand(self, vexpand: bool) -> Self {
664        Self {
665            builder: self.builder.property("vexpand", vexpand),
666        }
667    }
668
669    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
670        Self {
671            builder: self.builder.property("vexpand-set", vexpand_set),
672        }
673    }
674
675    pub fn visible(self, visible: bool) -> Self {
676        Self {
677            builder: self.builder.property("visible", visible),
678        }
679    }
680
681    pub fn width_request(self, width_request: i32) -> Self {
682        Self {
683            builder: self.builder.property("width-request", width_request),
684        }
685    }
686
687    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
688        Self {
689            builder: self.builder.property("accessible-role", accessible_role),
690        }
691    }
692
693    // rustdoc-stripper-ignore-next
694    /// Build the [`Calendar`].
695    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
696    pub fn build(self) -> Calendar {
697        assert_initialized_main_thread!();
698        self.builder.build()
699    }
700}