From 735cf301a4bbcc616ff07f818ab31483eaae7e8c Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Fri, 6 Jan 2023 20:18:53 -0800 Subject: [PATCH] calendar: Set marked days immediately The marked days are set only as part of gtk_calendar_select_day(). This is insufficient, especially because the day-selected signal is emitted after the marked days are set in gtk_calendar_select_day(). --- gtk/gtkcalendar.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index c671fb1185..7a619cfa85 100644 --- a/gtk/gtkcalendar.c +++ b/gtk/gtkcalendar.c @@ -1525,6 +1525,14 @@ gtk_calendar_clear_marks (GtkCalendar *calendar) g_return_if_fail (GTK_IS_CALENDAR (calendar)); + for (int y = 0; y < 6; y ++) + for (int x = 0; x < 7; x ++) + { + GtkWidget *label = calendar->day_number_labels[y][x]; + + gtk_widget_unset_state_flags (label, GTK_STATE_FLAG_CHECKED); + } + for (day = 0; day < 31; day++) { calendar->marked_date[day] = FALSE; @@ -1534,6 +1542,27 @@ gtk_calendar_clear_marks (GtkCalendar *calendar) calendar_queue_refresh (calendar); } +static void +update_mark_state (GtkCalendar *calendar, + guint day, + gboolean mark) +{ + for (int y = 0; y < 6; y ++) + for (int x = 0; x < 7; x ++) + { + GtkWidget *label = calendar->day_number_labels[y][x]; + + if (day != calendar->day[y][x]) + continue; + + if (mark && calendar->marked_date[day-1] && + calendar->day_month[y][x] == MONTH_CURRENT) + gtk_widget_set_state_flags (label, GTK_STATE_FLAG_CHECKED, FALSE); + else + gtk_widget_unset_state_flags (label, GTK_STATE_FLAG_CHECKED); + } +} + /** * gtk_calendar_mark_day: * @calendar: a `GtkCalendar` @@ -1551,6 +1580,7 @@ gtk_calendar_mark_day (GtkCalendar *calendar, { calendar->marked_date[day - 1] = TRUE; calendar->num_marked_dates++; + update_mark_state (calendar, day, TRUE); calendar_invalidate_day_num (calendar, day); } } @@ -1593,6 +1623,7 @@ gtk_calendar_unmark_day (GtkCalendar *calendar, { calendar->marked_date[day - 1] = FALSE; calendar->num_marked_dates--; + update_mark_state (calendar, day, FALSE); calendar_invalidate_day_num (calendar, day); } }