[gtk/wip/baedert/for-master: 6/19] calendar: Add accessors for display properties



commit cdd074df19fe05d69e356a3e6e746e68c312c735
Author: Timm Bäder <mail baedert org>
Date:   Tue Feb 4 12:19:08 2020 +0100

    calendar: Add accessors for display properties
    
    Instead of having a display flags enum and bitfield, just add proper
    accessors for the properties, which is what we do everywhere else.

 gtk/gtkcalendar.c    | 359 ++++++++++++++++++++++-----------------------------
 gtk/gtkcalendar.h    |  37 ++----
 tests/testcalendar.c | 114 ++++++----------
 3 files changed, 211 insertions(+), 299 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index b1d14b4e1f..92c5ef0c17 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -182,7 +182,6 @@ enum
   PROP_DAY,
   PROP_SHOW_HEADING,
   PROP_SHOW_DAY_NAMES,
-  PROP_NO_MONTH_CHANGE,
   PROP_SHOW_WEEK_NUMBERS,
 };
 
@@ -211,7 +210,9 @@ struct _GtkCalendarClass
 
 struct _GtkCalendarPrivate
 {
-  GtkCalendarDisplayOptions display_flags;
+  guint show_week_numbers: 1;
+  guint show_heading: 1;
+  guint show_day_names: 1;
 
   GtkWidget *header_box;
   GtkWidget *year_label;
@@ -463,19 +464,6 @@ gtk_calendar_class_init (GtkCalendarClass *class)
                                                          P_("If TRUE, day names are displayed"),
                                                          TRUE,
                                                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-/**
- * GtkCalendar:no-month-change:
- *
- * Determines whether the selected month can be changed.
- */
-  g_object_class_install_property (gobject_class,
-                                   PROP_NO_MONTH_CHANGE,
-                                   g_param_spec_boolean ("no-month-change",
-                                                         P_("No Month Change"),
-                                                         P_("If TRUE, the selected month cannot be changed"),
-                                                         FALSE,
-                                                         GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
 /**
  * GtkCalendar:show-week-numbers:
  *
@@ -803,8 +791,8 @@ gtk_calendar_init (GtkCalendar *calendar)
   priv->num_marked_dates = 0;
   priv->selected_day = tm->tm_mday;
 
-  priv->display_flags = (GTK_CALENDAR_SHOW_HEADING |
-                         GTK_CALENDAR_SHOW_DAY_NAMES);
+  priv->show_heading = TRUE;
+  priv->show_day_names = TRUE;
 
   priv->focus_row = -1;
   priv->focus_col = -1;
@@ -923,9 +911,6 @@ calendar_set_month_next (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
   gint month_len;
 
-  if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
-    return;
-
   if (priv->month == 11)
     {
       set_month (calendar, 0);
@@ -1118,7 +1103,7 @@ calendar_row_height (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
 
   return (priv->main_h - CALENDAR_MARGIN
-          - ((priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+          - ((priv->show_day_names)
              ? calendar_get_ysep (calendar) : CALENDAR_MARGIN)) / 6;
 }
 
@@ -1183,7 +1168,7 @@ calendar_left_x_for_column (GtkCalendar *calendar,
     }
 
   width = priv->day_width;
-  if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+  if (priv->show_week_numbers)
     x_left = week_width + calendar_xsep + (width + DAY_XSEP) * column;
   else
     x_left = week_width + CALENDAR_MARGIN + (width + DAY_XSEP) * column;
@@ -1290,9 +1275,6 @@ calendar_set_month_prev (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
   gint month_len;
 
-  if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
-    return;
-
   if (priv->month == 0)
     {
       set_month (calendar, 11);
@@ -1342,38 +1324,6 @@ gtk_calendar_destroy (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_calendar_parent_class)->destroy (widget);
 }
 
-static gboolean
-calendar_set_display_option (GtkCalendar              *calendar,
-                             GtkCalendarDisplayOptions flag,
-                             gboolean                  setting)
-{
-  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-  GtkCalendarDisplayOptions flags;
-  gboolean old_setting;
-
-  old_setting = (priv->display_flags & flag) != 0;
-  if (old_setting == setting)
-    return FALSE;
-
-  if (setting)
-    flags = priv->display_flags | flag;
-  else
-    flags = priv->display_flags & ~flag;
-
-  gtk_calendar_set_display_options (calendar, flags);
-
-  return TRUE;
-}
-
-static gboolean
-calendar_get_display_option (GtkCalendar              *calendar,
-                             GtkCalendarDisplayOptions flag)
-{
-  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
-  return (priv->display_flags & flag) != 0;
-}
-
 static void
 gtk_calendar_set_property (GObject      *object,
                            guint         prop_id,
@@ -1400,28 +1350,13 @@ gtk_calendar_set_property (GObject      *object,
                                g_value_get_int (value));
       break;
     case PROP_SHOW_HEADING:
-      if (calendar_set_display_option (calendar,
-                                       GTK_CALENDAR_SHOW_HEADING,
-                                       g_value_get_boolean (value)))
-        g_object_notify (object, "show-heading");
+      gtk_calendar_set_show_heading (calendar, g_value_get_boolean (value));
       break;
     case PROP_SHOW_DAY_NAMES:
-      if (calendar_set_display_option (calendar,
-                                       GTK_CALENDAR_SHOW_DAY_NAMES,
-                                       g_value_get_boolean (value)))
-        g_object_notify (object, "show-day-names");
-      break;
-    case PROP_NO_MONTH_CHANGE:
-      if (calendar_set_display_option (calendar,
-                                       GTK_CALENDAR_NO_MONTH_CHANGE,
-                                       g_value_get_boolean (value)))
-        g_object_notify (object, "no-month-change");
+      gtk_calendar_set_show_day_names (calendar, g_value_get_boolean (value));
       break;
     case PROP_SHOW_WEEK_NUMBERS:
-      if (calendar_set_display_option (calendar,
-                                       GTK_CALENDAR_SHOW_WEEK_NUMBERS,
-                                       g_value_get_boolean (value)))
-        g_object_notify (object, "show-week-numbers");
+      gtk_calendar_set_show_week_numbers (calendar, g_value_get_boolean (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1450,20 +1385,13 @@ gtk_calendar_get_property (GObject      *object,
       g_value_set_int (value, priv->selected_day);
       break;
     case PROP_SHOW_HEADING:
-      g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                               GTK_CALENDAR_SHOW_HEADING));
+      g_value_set_boolean (value, gtk_calendar_get_show_heading (calendar));
       break;
     case PROP_SHOW_DAY_NAMES:
-      g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                               GTK_CALENDAR_SHOW_DAY_NAMES));
-      break;
-    case PROP_NO_MONTH_CHANGE:
-      g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                               GTK_CALENDAR_NO_MONTH_CHANGE));
+      g_value_set_boolean (value, gtk_calendar_get_show_day_names (calendar));
       break;
     case PROP_SHOW_WEEK_NUMBERS:
-      g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                               GTK_CALENDAR_SHOW_WEEK_NUMBERS));
+      g_value_set_boolean (value, gtk_calendar_get_show_week_numbers (calendar));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1512,13 +1440,11 @@ gtk_calendar_size_request (GtkWidget      *widget,
   gint calendar_ysep = calendar_get_ysep (calendar);
   gint calendar_xsep = calendar_get_xsep (calendar);
 
-  gboolean show_week_numbers = (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS);
-
   layout = gtk_widget_create_pango_layout (widget, NULL);
 
   /* Header width */
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_HEADING)
+  if (priv->show_heading)
     {
       gtk_widget_measure (priv->header_box, GTK_ORIENTATION_HORIZONTAL, -1,
                           &header_width, NULL, NULL, NULL);
@@ -1555,7 +1481,7 @@ gtk_calendar_size_request (GtkWidget      *widget,
 
   priv->max_label_char_ascent = 0;
   priv->max_label_char_descent = 0;
-  if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+  if (priv->show_day_names)
     for (i = 0; i < 7; i++)
       {
         pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
@@ -1569,7 +1495,7 @@ gtk_calendar_size_request (GtkWidget      *widget,
       }
 
   priv->max_week_char_width = 0;
-  if (show_week_numbers)
+  if (priv->show_week_numbers)
     for (i = 0; i < 9; i++)
       {
         gchar buffer[32];
@@ -1583,14 +1509,14 @@ gtk_calendar_size_request (GtkWidget      *widget,
   get_component_paddings (calendar, &day_padding, &day_name_padding, &week_padding);
 
   priv->min_day_width += day_padding.left + day_padding.right;
-  if (show_week_numbers)
+  if (priv->show_week_numbers)
     priv->max_week_char_width += week_padding.left + week_padding.right;
 
   /* We add one to max_day_char_width to be able to make the marked day "bold" */
   priv->max_day_char_width = priv->min_day_width / 2 + 1;
 
   main_width = (7 * (priv->min_day_width) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
-                + (show_week_numbers
+                + (priv->show_week_numbers
                    ? priv->max_week_char_width * 2 + calendar_xsep * 2
                    : 0));
 
@@ -1600,7 +1526,7 @@ gtk_calendar_size_request (GtkWidget      *widget,
    * Calculate the requisition height for the widget.
    */
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_HEADING)
+  if (priv->show_heading)
     {
       priv->header_h = (max_header_height + calendar_ysep * 2);
     }
@@ -1609,7 +1535,7 @@ gtk_calendar_size_request (GtkWidget      *widget,
       priv->header_h = 0;
     }
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+  if (priv->show_day_names)
     {
       priv->day_name_h = (priv->max_label_char_ascent
                           + priv->max_label_char_descent
@@ -1666,7 +1592,7 @@ gtk_calendar_size_allocate (GtkWidget *widget,
   gint calendar_xsep = calendar_get_xsep (calendar);
   int header_height;
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+  if (priv->show_week_numbers)
     {
       priv->day_width = (priv->min_day_width
                          * ((width - (inner_border * 2)
@@ -1743,7 +1669,7 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
                                   cal_width - CALENDAR_MARGIN * 2,
                                   priv->day_name_h - CALENDAR_MARGIN);
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+  if (priv->show_week_numbers)
     gtk_snapshot_render_background (snapshot, context,
                                     CALENDAR_MARGIN,
                                     priv->day_name_h - calendar_ysep,
@@ -1819,7 +1745,7 @@ calendar_snapshot_week_numbers (GtkCalendar *calendar,
   gtk_style_context_set_state (context, state);
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+  if (priv->show_day_names)
     gtk_snapshot_render_background (snapshot, context,
                                     x + CALENDAR_MARGIN, y,
                                     priv->week_width - CALENDAR_MARGIN,
@@ -2013,10 +1939,10 @@ gtk_calendar_snapshot (GtkWidget   *widget,
 
   gtk_widget_snapshot_child (widget, priv->header_box, snapshot);
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+  if (priv->show_day_names)
     calendar_snapshot_day_names (calendar, snapshot);
 
-  if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+  if (priv->show_week_numbers)
     calendar_snapshot_week_numbers (calendar, snapshot);
 }
 
@@ -2551,9 +2477,8 @@ got_text (GObject      *source,
 {
   GtkDropTarget *dest = GTK_DROP_TARGET (data);
   GtkCalendar *calendar = GTK_CALENDAR (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest)));
-  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
   GdkDrop *drop = GDK_DROP (source);
-  guint day, month, year;
+  guint day;
   gchar *str;
   GDate *date;
   GdkDragAction suggested_action;
@@ -2599,16 +2524,11 @@ got_text (GObject      *source,
     }
 
   day = g_date_get_day (date);
-  month = g_date_get_month (date);
-  year = g_date_get_year (date);
   g_date_free (date);
 
   gdk_drop_finish (drop, suggested_action);
 
   g_object_freeze_notify (G_OBJECT (calendar));
-  if (!(priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
-      && (priv->display_flags & GTK_CALENDAR_SHOW_HEADING))
-    gtk_calendar_select_month (calendar, month - 1, year);
   gtk_calendar_select_day (calendar, day);
   g_object_thaw_notify (G_OBJECT (calendar));
 }
@@ -2672,105 +2592,6 @@ gtk_calendar_new (void)
   return g_object_new (GTK_TYPE_CALENDAR, NULL);
 }
 
-/**
- * gtk_calendar_get_display_options:
- * @calendar: a #GtkCalendar
- *
- * Returns the current display options of @calendar.
- *
- * Returns: the display options.
- **/
-GtkCalendarDisplayOptions
-gtk_calendar_get_display_options (GtkCalendar         *calendar)
-{
-  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
-  g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
-
-  return priv->display_flags;
-}
-
-/**
- * gtk_calendar_set_display_options:
- * @calendar: a #GtkCalendar
- * @flags: the display options to set
- *
- * Sets display options (whether to display the heading and the month
- * headings).
- **/
-void
-gtk_calendar_set_display_options (GtkCalendar          *calendar,
-                                  GtkCalendarDisplayOptions flags)
-{
-  GtkWidget *widget = GTK_WIDGET (calendar);
-  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-  gint resize = 0;
-  GtkCalendarDisplayOptions old_flags;
-
-  g_return_if_fail (GTK_IS_CALENDAR (calendar));
-
-  old_flags = priv->display_flags;
-
-  if (gtk_widget_get_realized (widget))
-    {
-      if ((flags ^ priv->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
-        {
-          resize ++;
-          if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
-              && (priv->display_flags & GTK_CALENDAR_SHOW_HEADING))
-            {
-              priv->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
-            }
-        }
-
-      if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_HEADING)
-        {
-          if (flags & GTK_CALENDAR_SHOW_HEADING)
-            {
-              priv->display_flags |= GTK_CALENDAR_SHOW_HEADING;
-              gtk_widget_show (priv->header_box);
-            }
-          else
-            {
-              gtk_widget_hide (priv->header_box);
-            }
-        }
-
-      if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
-        {
-          resize++;
-
-          if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
-            priv->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
-        }
-
-      if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
-        {
-          resize++;
-
-          if (flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
-            priv->display_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
-        }
-
-      priv->display_flags = flags;
-      if (resize)
-        gtk_widget_queue_resize (GTK_WIDGET (calendar));
-    }
-  else
-    priv->display_flags = flags;
-
-  g_object_freeze_notify (G_OBJECT (calendar));
-  if ((old_flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_HEADING)
-    g_object_notify (G_OBJECT (calendar), "show-heading");
-  if ((old_flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
-    g_object_notify (G_OBJECT (calendar), "show-day-names");
-  if ((old_flags ^ priv->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
-    g_object_notify (G_OBJECT (calendar), "no-month-change");
-  if ((old_flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
-    g_object_notify (G_OBJECT (calendar), "show-week-numbers");
-  g_object_thaw_notify (G_OBJECT (calendar));
-}
-
 /**
  * gtk_calendar_select_month:
  * @calendar: a #GtkCalendar
@@ -2975,3 +2796,131 @@ gtk_calendar_get_date (GtkCalendar *calendar,
   if (day)
     *day = priv->selected_day;
 }
+
+/**
+ * gtk_calendar_set_show_week_numbers
+ * @self: a #GtkCalendar
+ * @value: Whether to show week numbers on the left of the days
+ *
+ * Sets whether week numbers are shown in the calendar.
+ */
+void
+gtk_calendar_set_show_week_numbers (GtkCalendar *self,
+                                    gboolean     value)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_if_fail (GTK_IS_CALENDAR (self));
+
+  if (value != priv->show_week_numbers)
+    {
+      priv->show_week_numbers = value;
+
+      gtk_widget_queue_resize (GTK_WIDGET (self));
+
+      g_object_notify (G_OBJECT (self), "show-week-numbers");
+    }
+}
+
+/**
+ * gtk_calendar_get_show_week_numbers:
+ * @self: a #GtkCalendar
+ *
+ * Returns: Whether @self is showing week numbers right now,
+ *   i.e. the value of the #GtkCalendar:show-week-numbers property.
+ */
+gboolean
+gtk_calendar_get_show_week_numbers (GtkCalendar *self)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
+
+  return priv->show_week_numbers;
+}
+
+/**
+ * gtk_calendar_set_show_heading:
+ * @self: a #GtkCalendar
+ * @value: Whether to show the heading in the calendar,
+ *   containing the current year and month as well as
+ *   buttons for changing both.
+ */
+void
+gtk_calendar_set_show_heading (GtkCalendar *self,
+                               gboolean     value)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_if_fail (GTK_IS_CALENDAR (self));
+
+  if (value != priv->show_heading)
+    {
+      priv->show_heading = value;
+
+      gtk_widget_set_visible (priv->header_box, value);
+
+      gtk_widget_queue_draw (GTK_WIDGET (self));
+
+      g_object_notify (G_OBJECT (self), "show-heading");
+    }
+}
+
+/**
+ * gtk_calendar_get_show_heading:
+ * @self: a #GtkCalendar
+ *
+ * Returns: Whether @self is currently showing the heading,
+ *   i.e. the value of the #GtkCalendar:show-heading property.
+ */
+gboolean
+gtk_calendar_get_show_heading (GtkCalendar *self)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
+
+  return priv->show_heading;
+}
+
+/**
+ * gtk_calendar_set_show_day_names:
+ * @self: a #GtkCalendar
+ * @value: Whether to show week day names above the
+ *   day numbers
+ */
+void
+gtk_calendar_set_show_day_names (GtkCalendar *self,
+                                 gboolean     value)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_if_fail (GTK_IS_CALENDAR (self));
+
+  if (value != priv->show_day_names)
+    {
+      priv->show_day_names = value;
+
+      gtk_widget_queue_draw (GTK_WIDGET (self));
+
+      g_object_notify (G_OBJECT (self), "show-day-names");
+    }
+}
+
+/**
+ * gtk_calendar_get_day_names:
+ * @self: a #GtkCalendar
+ *
+ * Returns: Whether @self is currently showing the names
+ *   of the week days above the day numbers, i.e. the value
+ *   of the #GtkCalendar:show-day-names property.
+ */
+gboolean
+gtk_calendar_get_show_day_names (GtkCalendar *self)
+{
+  GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+
+  g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
+
+  return priv->show_day_names;
+}
diff --git a/gtk/gtkcalendar.h b/gtk/gtkcalendar.h
index a7bb609c48..bb4c04cd72 100644
--- a/gtk/gtkcalendar.h
+++ b/gtk/gtkcalendar.h
@@ -45,24 +45,6 @@ G_BEGIN_DECLS
 
 typedef struct _GtkCalendar           GtkCalendar;
 
-/**
- * GtkCalendarDisplayOptions:
- * @GTK_CALENDAR_SHOW_HEADING: Specifies that the month and year should be displayed.
- * @GTK_CALENDAR_SHOW_DAY_NAMES: Specifies that three letter day descriptions should be present.
- * @GTK_CALENDAR_NO_MONTH_CHANGE: Prevents the user from switching months with the calendar.
- * @GTK_CALENDAR_SHOW_WEEK_NUMBERS: Displays each week numbers of the current year, down the
- * left side of the calendar.
- *
- * These options can be used to influence the display and behaviour of a #GtkCalendar.
- */
-typedef enum
-{
-  GTK_CALENDAR_SHOW_HEADING            = 1 << 0,
-  GTK_CALENDAR_SHOW_DAY_NAMES          = 1 << 1,
-  GTK_CALENDAR_NO_MONTH_CHANGE         = 1 << 2,
-  GTK_CALENDAR_SHOW_WEEK_NUMBERS       = 1 << 3,
-} GtkCalendarDisplayOptions;
-
 GDK_AVAILABLE_IN_ALL
 GType     gtk_calendar_get_type        (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_ALL
@@ -85,13 +67,22 @@ void       gtk_calendar_unmark_day  (GtkCalendar *calendar,
 GDK_AVAILABLE_IN_ALL
 void      gtk_calendar_clear_marks     (GtkCalendar *calendar);
 
-
 GDK_AVAILABLE_IN_ALL
-void      gtk_calendar_set_display_options (GtkCalendar              *calendar,
-                                            GtkCalendarDisplayOptions flags);
+void       gtk_calendar_set_show_week_numbers       (GtkCalendar *self,
+                                                     gboolean     value);
+GDK_AVAILABLE_IN_ALL
+gboolean   gtk_calendar_get_show_week_numbers       (GtkCalendar *self);
 GDK_AVAILABLE_IN_ALL
-GtkCalendarDisplayOptions
-           gtk_calendar_get_display_options (GtkCalendar             *calendar);
+void       gtk_calendar_set_show_heading            (GtkCalendar *self,
+                                                     gboolean     value);
+GDK_AVAILABLE_IN_ALL
+gboolean   gtk_calendar_get_show_heading            (GtkCalendar *self);
+GDK_AVAILABLE_IN_ALL
+void       gtk_calendar_set_show_day_names          (GtkCalendar *self,
+                                                     gboolean     value);
+GDK_AVAILABLE_IN_ALL
+gboolean   gtk_calendar_get_show_day_names          (GtkCalendar *self);
+
 GDK_AVAILABLE_IN_ALL
 void      gtk_calendar_get_date        (GtkCalendar *calendar,
                                         guint       *year,
diff --git a/tests/testcalendar.c b/tests/testcalendar.c
index d060e8ccb2..f3bce328cd 100644
--- a/tests/testcalendar.c
+++ b/tests/testcalendar.c
@@ -29,10 +29,6 @@
 typedef struct _CalendarData
 {
   GtkWidget *calendar_widget;
-  GtkWidget *flag_checkboxes[6];
-  gboolean  settings[6];
-  GtkWidget *font_dialog;
-  GtkWidget *window;
   GtkWidget *prev2_sig;
   GtkWidget *prev_sig;
   GtkWidget *last_sig;
@@ -60,8 +56,8 @@ calendar_date_to_string (CalendarData *data,
   GDate *date;
   guint year, month, day;
 
-  gtk_calendar_get_date (GTK_CALENDAR(data->window),
-                        &year, &month, &day);
+  gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget),
+                         &year, &month, &day);
   if (g_date_valid_dmy (day, month + 1, year))
     {
       date = g_date_new_dmy (day, month + 1, year);
@@ -117,13 +113,13 @@ calendar_day_selected_double_click (GtkWidget    *widget,
 
   calendar_date_to_string (data, buffer+27, 256-27);
   calendar_set_signal_strings (buffer, data);
-  gtk_calendar_get_date (GTK_CALENDAR (data->window),
+  gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget),
                          NULL, NULL, &day);
 
-  if (gtk_calendar_get_day_is_marked (GTK_CALENDAR (data->window), day))
-    gtk_calendar_unmark_day (GTK_CALENDAR (data->window), day);
+  if (gtk_calendar_get_day_is_marked (GTK_CALENDAR (data->calendar_widget), day))
+    gtk_calendar_unmark_day (GTK_CALENDAR (data->calendar_widget), day);
   else
-    gtk_calendar_mark_day (GTK_CALENDAR (data->window), day);
+    gtk_calendar_mark_day (GTK_CALENDAR (data->calendar_widget), day);
 }
 
 static void
@@ -166,32 +162,19 @@ calendar_next_year (GtkWidget    *widget,
   calendar_set_signal_strings (buffer, data);
 }
 
-
 static void
-calendar_set_flags (CalendarData *calendar)
+flag_toggled_cb (GtkCheckButton *button,
+                 gpointer        user_data)
 {
-  gint options = 0, i;
-
-  for (i = 0; i < G_N_ELEMENTS (calendar->settings); i++)
-    if (calendar->settings[i])
-      options=options + (1 << i);
-
-  if (calendar->window)
-    gtk_calendar_set_display_options (GTK_CALENDAR (calendar->window), options);
-}
-
-static void
-calendar_toggle_flag (GtkWidget    *toggle,
-                      CalendarData *calendar)
-{
-  gint i;
-
-  for (i = 0; i < G_N_ELEMENTS (calendar->flag_checkboxes); i++)
-    if (calendar->flag_checkboxes[i] == toggle)
-      calendar->settings[i] = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle));
+  struct {
+    const char *prop_name;
+    const char *label;
+    GtkWidget *calendar;
+  } *data = user_data;
 
-  calendar_set_flags(calendar);
-  
+  g_object_set (G_OBJECT (data->calendar), data->prop_name,
+                gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)),
+                NULL);
 }
 
 static GtkWidget*
@@ -225,28 +208,19 @@ create_calendar(void)
   static CalendarData calendar_data;
 
   GtkWidget *window, *hpaned, *vbox, *rpane, *hbox;
-  GtkWidget *calendar, *toggle, *button;
+  GtkWidget *calendar = gtk_calendar_new ();
+  GtkWidget *button;
   GtkWidget *frame, *label, *bbox;
   gint i;
-
   struct {
-    gboolean init;
-    char *label;
-  } flags[] =
-    {
-      { TRUE,  "Show _Heading" },
-      { TRUE,  "Show Day _Names" },
-      { FALSE, "No Month _Change" },
-      { TRUE,  "Show _Week Numbers" },
-      { FALSE, "Week Start _Monday" },
-      { TRUE,  "Show De_tails" },
-    };
-
-  calendar_data.window = NULL;
-  calendar_data.font_dialog = NULL;
-
-  for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
-    calendar_data.settings[i] = 0;
+    const char *prop_name;
+    const char *label;
+    GtkWidget *calendar;
+  } flags[] = {
+    { "show-heading", "Show Heading", calendar },
+    { "show-day-names", "Show Day Names", calendar },
+    { "show-week-numbers", "Show Week Numbers", calendar },
+  };
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_hide_on_close (GTK_WINDOW (window), TRUE);
@@ -257,34 +231,31 @@ create_calendar(void)
 
   /* Calendar widget */
 
-  calendar = gtk_calendar_new ();
   calendar_data.calendar_widget = calendar;
   frame = create_frame ("<b>Calendar</b>", calendar, GTK_ALIGN_CENTER, GTK_ALIGN_CENTER);
   gtk_paned_pack1 (GTK_PANED (hpaned), frame, TRUE, FALSE);
 
-  calendar_data.window = calendar;
-  calendar_set_flags(&calendar_data);
   gtk_calendar_mark_day (GTK_CALENDAR (calendar), 19); 
 
-  g_signal_connect (calendar, "month_changed", 
+  g_signal_connect (calendar, "month-changed", 
                    G_CALLBACK (calendar_month_changed),
                    &calendar_data);
-  g_signal_connect (calendar, "day_selected", 
+  g_signal_connect (calendar, "day-selected", 
                    G_CALLBACK (calendar_day_selected),
                    &calendar_data);
-  g_signal_connect (calendar, "day_selected_double_click", 
+  g_signal_connect (calendar, "day-selected-double-click", 
                    G_CALLBACK (calendar_day_selected_double_click),
                    &calendar_data);
-  g_signal_connect (calendar, "prev_month", 
+  g_signal_connect (calendar, "prev-month", 
                    G_CALLBACK (calendar_prev_month),
                    &calendar_data);
-  g_signal_connect (calendar, "next_month", 
+  g_signal_connect (calendar, "next-month", 
                    G_CALLBACK (calendar_next_month),
                    &calendar_data);
-  g_signal_connect (calendar, "prev_year", 
+  g_signal_connect (calendar, "prev-year", 
                    G_CALLBACK (calendar_prev_year),
                    &calendar_data);
-  g_signal_connect (calendar, "next_year", 
+  g_signal_connect (calendar, "next-year", 
                    G_CALLBACK (calendar_next_year),
                    &calendar_data);
 
@@ -305,17 +276,17 @@ create_calendar(void)
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (rpane), vbox);
 
-  for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
+  for (i = 0; i < G_N_ELEMENTS (flags); i++)
     {
-      toggle = gtk_check_button_new_with_mnemonic(flags[i].label);
+      GtkWidget *toggle = gtk_check_button_new_with_mnemonic (flags[i].label);
+      gboolean value;
+
       gtk_container_add (GTK_CONTAINER (vbox), toggle);
-      calendar_data.flag_checkboxes[i] = toggle;
 
-      g_signal_connect (toggle, "toggled",
-                        G_CALLBACK (calendar_toggle_flag),
-                        &calendar_data);
+      g_object_get (G_OBJECT (calendar), flags[i].prop_name, &value, NULL);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), value);
 
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), flags[i].init);
+      g_signal_connect (toggle, "toggled", G_CALLBACK (flag_toggled_cb), &flags[i]);
     }
 
   /*
@@ -373,6 +344,9 @@ create_calendar(void)
   gtk_window_set_default_size (GTK_WINDOW (window), 600, 0);
   g_signal_connect (window, "close-request", G_CALLBACK (gtk_main_quit), NULL);
   gtk_widget_show (window);
+
+
+  gtk_main();
 }
 
 
@@ -386,8 +360,6 @@ int main(int   argc,
 
   create_calendar();
 
-  gtk_main();
-
   return(0);
 }
 /* example-end */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]