From 8af5298e50ed0a54ec229b8ce1ebc8a43a8d446e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BCgel?= <129184-gwastar@users.noreply.gitlab.gnome.org> Date: Sat, 4 Nov 2023 13:37:36 +0100 Subject: [PATCH] event-editor/multi-choice: Add prev/next value callbacks These callbacks will be used in the next commit to jump to the first day of the month. Related: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1103 Co-authored-by: Maximiliano Sandoval Part-of: --- src/gui/event-editor/gcal-multi-choice.c | 19 +++++++++++++++++-- src/gui/event-editor/gcal-multi-choice.h | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gui/event-editor/gcal-multi-choice.c b/src/gui/event-editor/gcal-multi-choice.c index f13c8fec..9ab22637 100644 --- a/src/gui/event-editor/gcal-multi-choice.c +++ b/src/gui/event-editor/gcal-multi-choice.c @@ -52,6 +52,8 @@ struct _GcalMultiChoice GcalMultiChoiceFormatCallback format_cb; gpointer format_data; GDestroyNotify format_destroy; + GcalMultiChoiceValueCallback prev_cb; + GcalMultiChoiceValueCallback next_cb; }; enum @@ -187,7 +189,9 @@ go_up (GcalMultiChoice *self) gboolean wrapped = FALSE; gint value; - value = self->value + 1; + value = self->next_cb ? self->next_cb (self->value) : self->value + 1; + g_assert_cmpint (value, > ,self->value); + if (value > self->max_value) { if (!self->wrap) @@ -209,7 +213,9 @@ go_down (GcalMultiChoice *self) gint value; gboolean wrapped = FALSE; - value = self->value - 1; + value = self->prev_cb ? self->prev_cb (self->value) : self->value - 1; + g_assert_cmpint (value, < , self->value); + if (value < self->min_value) { if (!self->wrap) @@ -849,6 +855,15 @@ gcal_multi_choice_set_format_callback (GcalMultiChoice *self, * * Sets the popover for @self. */ +void +gcal_multi_choice_set_value_callbacks (GcalMultiChoice *self, + GcalMultiChoiceValueCallback prev_cb, + GcalMultiChoiceValueCallback next_cb) +{ + self->prev_cb = prev_cb; + self->next_cb = next_cb; +} + void gcal_multi_choice_set_popover (GcalMultiChoice *self, GtkWidget *popover) diff --git a/src/gui/event-editor/gcal-multi-choice.h b/src/gui/event-editor/gcal-multi-choice.h index 20bd6b48..e7959fb4 100644 --- a/src/gui/event-editor/gcal-multi-choice.h +++ b/src/gui/event-editor/gcal-multi-choice.h @@ -56,6 +56,12 @@ void gcal_multi_choice_set_format_callback (GcalMultiChoic gpointer user_data, GDestroyNotify notify); +typedef gint (*GcalMultiChoiceValueCallback) (gint value); + +void gcal_multi_choice_set_value_callbacks (GcalMultiChoice *self, + GcalMultiChoiceValueCallback prev_cb, + GcalMultiChoiceValueCallback next_cb); + G_END_DECLS #endif /* GCAL_MULTI_CHOICE_H */