First cut at marking days

Add a callback that can set display options for each day.
So far, you can mark a day, or set it as a weekend or holiday.
This commit is contained in:
Matthias Clasen
2015-09-04 00:47:20 -04:00
parent 817c35f39f
commit 0291f49dad
4 changed files with 85 additions and 0 deletions

View File

@@ -347,3 +347,24 @@ gtk_date_chooser_day_set_selected (GtkDateChooserDay *day,
else
gtk_widget_unset_state_flags (GTK_WIDGET (day), GTK_STATE_FLAG_SELECTED);
}
void
gtk_date_chooser_day_set_options (GtkDateChooserDay *day,
GtkDateChooserDayOptions options)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (GTK_WIDGET (day));
if (options & GTK_DATE_CHOOSER_DAY_WEEKEND)
gtk_style_context_add_class (context, "weekend");
else
gtk_style_context_remove_class (context, "weekend");
if (options & GTK_DATE_CHOOSER_DAY_HOLIDAY)
gtk_style_context_add_class (context, "holiday");
else
gtk_style_context_remove_class (context, "holiday");
if (options & GTK_DATE_CHOOSER_DAY_MARKED)
gtk_style_context_add_class (context, "marked");
else
gtk_style_context_remove_class (context, "marked");
}

View File

@@ -19,6 +19,7 @@
#define __GTK_DATE_CHOOSER_DAY_PRIVATE_H__
#include <gtk/gtkbin.h>
#include <gtk/gtkdatechooserwidget.h>
G_BEGIN_DECLS
@@ -42,6 +43,8 @@ void gtk_date_chooser_day_set_other_month (GtkDateChooserDay *day,
gboolean other_month);
void gtk_date_chooser_day_set_selected (GtkDateChooserDay *day,
gboolean selected);
void gtk_date_chooser_day_set_options (GtkDateChooserDay *day,
GtkDateChooserDayOptions options);
G_END_DECLS

View File

@@ -75,6 +75,10 @@ struct _GtkDateChooserWidget
gboolean show_day_names;
gboolean show_week_numbers;
gboolean no_month_change;
GtkDateChooserDayOptionsCallback day_options_cb;
gpointer day_options_data;
GDestroyNotify day_options_destroy;
};
struct _GtkDateChooserWidgetClass
@@ -203,6 +207,8 @@ calendar_compute_days (GtkDateChooserWidget *calendar)
gtk_label_set_label (GTK_LABEL (calendar->rows[row]), text);
g_free (text);
}
gtk_date_chooser_widget_invalidate_day_options (calendar);
}
/* 0 == sunday */
@@ -747,3 +753,40 @@ gtk_date_chooser_widget_get_date (GtkDateChooserWidget *calendar)
{
return calendar->date;
}
void
gtk_date_chooser_widget_set_day_options_callback (GtkDateChooserWidget *calendar,
GtkDateChooserDayOptionsCallback callback,
gpointer data,
GDestroyNotify destroy)
{
if (calendar->day_options_destroy)
calendar->day_options_destroy (calendar->day_options_data);
calendar->day_options_cb = callback;
calendar->day_options_data = data;
calendar->day_options_destroy = destroy;
gtk_date_chooser_widget_invalidate_day_options (calendar);
}
void
gtk_date_chooser_widget_invalidate_day_options (GtkDateChooserWidget *calendar)
{
gint row, col;
GDateTime *date;
GtkDateChooserDay *d;
GtkDateChooserDayOptions options;
for (row = 0; row < 6; row++)
for (col = 0; col < 7; col++)
{
d = GTK_DATE_CHOOSER_DAY (calendar->days[row][col]);
date = gtk_date_chooser_day_get_date (d);
if (calendar->day_options_cb)
options = calendar->day_options_cb (calendar, date, calendar->day_options_data);
else
options = GTK_DATE_CHOOSER_DAY_NONE;
gtk_date_chooser_day_set_options (d, options);
}
}

View File

@@ -52,6 +52,24 @@ void gtk_date_chooser_widget_set_date (GtkDateChooserWidget
GDK_AVAILABLE_IN_3_20
GDateTime * gtk_date_chooser_widget_get_date (GtkDateChooserWidget *chooser);
typedef enum {
GTK_DATE_CHOOSER_DAY_NONE = 0,
GTK_DATE_CHOOSER_DAY_WEEKEND = 1,
GTK_DATE_CHOOSER_DAY_HOLIDAY = 2,
GTK_DATE_CHOOSER_DAY_MARKED = 4
} GtkDateChooserDayOptions;
typedef GtkDateChooserDayOptions (* GtkDateChooserDayOptionsCallback) (GtkDateChooserWidget *chooser,
GDateTime *date,
gpointer data);
GDK_AVAILABLE_IN_3_20
void gtk_date_chooser_widget_set_day_options_callback (GtkDateChooserWidget *chooser,
GtkDateChooserDayOptionsCallback callback,
gpointer data,
GDestroyNotify destroy);
GDK_AVAILABLE_IN_3_20
void gtk_date_chooser_widget_invalidate_day_options (GtkDateChooserWidget *widget);
GDK_AVAILABLE_IN_3_20
void gtk_date_chooser_widget_set_no_month_change (GtkDateChooserWidget *chooser,
gboolean setting);