[gtk/wip/baedert/for-master: 16/16] calendar: Remove details
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 16/16] calendar: Remove details
- Date: Tue, 4 Feb 2020 09:08:04 +0000 (UTC)
commit 12e429e357a2c97a146540efd7938c534f507156
Author: Timm Bäder <mail baedert org>
Date: Tue Feb 4 10:01:58 2020 +0100
calendar: Remove details
This is an unused feature that's way too complicated for a default
calendar widget and complicates the implementation a lot. Since we want
to eventually replace this with actual widgets, remove the details
support now.
gtk/gtkcalendar.c | 453 +--------------------------------------------------
gtk/gtkcalendar.h | 44 +----
tests/testcalendar.c | 272 +------------------------------
3 files changed, 9 insertions(+), 760 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 86cf440ac3..5024168817 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -184,9 +184,6 @@ enum
PROP_SHOW_DAY_NAMES,
PROP_NO_MONTH_CHANGE,
PROP_SHOW_WEEK_NUMBERS,
- PROP_SHOW_DETAILS,
- PROP_DETAIL_WIDTH_CHARS,
- PROP_DETAIL_HEIGHT_ROWS
};
static guint gtk_calendar_signals[LAST_SIGNAL] = { 0 };
@@ -268,16 +265,6 @@ struct _GtkCalendarPrivate
gint drag_start_x;
gint drag_start_y;
-
- /* Optional callback, used to display extra information for each day. */
- GtkCalendarDetailFunc detail_func;
- gpointer detail_func_user_data;
- GDestroyNotify detail_func_destroy;
-
- /* Size requistion for details provided by the hook. */
- gint detail_height_rows;
- gint detail_width_chars;
- gint detail_overflow[6];
};
static void gtk_calendar_destroy (GtkWidget *widget);
@@ -334,12 +321,6 @@ static void gtk_calendar_grab_notify (GtkWidget *widget,
gboolean was_grabbed);
static void gtk_calendar_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
-static gboolean gtk_calendar_query_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip);
-
static gboolean gtk_calendar_drag_accept (GtkDropTarget *dest,
GdkDrop *drop,
GtkCalendar *calendar);
@@ -413,7 +394,6 @@ gtk_calendar_class_init (GtkCalendarClass *class)
widget_class->size_allocate = gtk_calendar_size_allocate;
widget_class->state_flags_changed = gtk_calendar_state_flags_changed;
widget_class->grab_notify = gtk_calendar_grab_notify;
- widget_class->query_tooltip = gtk_calendar_query_tooltip;
/**
* GtkCalendar:year:
@@ -509,50 +489,6 @@ gtk_calendar_class_init (GtkCalendarClass *class)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-/**
- * GtkCalendar:detail-width-chars:
- *
- * Width of a detail cell, in characters.
- * A value of 0 allows any width. See gtk_calendar_set_detail_func().
- */
- g_object_class_install_property (gobject_class,
- PROP_DETAIL_WIDTH_CHARS,
- g_param_spec_int ("detail-width-chars",
- P_("Details Width"),
- P_("Details width in characters"),
- 0, 127, 0,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
-/**
- * GtkCalendar:detail-height-rows:
- *
- * Height of a detail cell, in rows.
- * A value of 0 allows any width. See gtk_calendar_set_detail_func().
- */
- g_object_class_install_property (gobject_class,
- PROP_DETAIL_HEIGHT_ROWS,
- g_param_spec_int ("detail-height-rows",
- P_("Details Height"),
- P_("Details height in rows"),
- 0, 127, 0,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
-/**
- * GtkCalendar:show-details:
- *
- * Determines whether details are shown directly in the widget, or if they are
- * available only as tooltip. When this property is set days with details are
- * marked.
- */
- g_object_class_install_property (gobject_class,
- PROP_SHOW_DETAILS,
- g_param_spec_boolean ("show-details",
- P_("Show Details"),
- P_("If TRUE, details are shown"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
-
/**
* GtkCalendar::month-changed:
* @calendar: the object which received the signal.
@@ -868,8 +804,7 @@ gtk_calendar_init (GtkCalendar *calendar)
priv->selected_day = tm->tm_mday;
priv->display_flags = (GTK_CALENDAR_SHOW_HEADING |
- GTK_CALENDAR_SHOW_DAY_NAMES |
- GTK_CALENDAR_SHOW_DETAILS);
+ GTK_CALENDAR_SHOW_DAY_NAMES);
priv->focus_row = -1;
priv->focus_col = -1;
@@ -979,14 +914,7 @@ gtk_calendar_init (GtkCalendar *calendar)
static void
calendar_queue_refresh (GtkCalendar *calendar)
{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- if (!(priv->detail_func) ||
- !(priv->display_flags & GTK_CALENDAR_SHOW_DETAILS) ||
- (priv->detail_width_chars && priv->detail_height_rows))
- gtk_widget_queue_draw (GTK_WIDGET (calendar));
- else
- gtk_widget_queue_resize (GTK_WIDGET (calendar));
+ gtk_widget_queue_resize (GTK_WIDGET (calendar));
}
static void
@@ -1408,18 +1336,9 @@ static void
gtk_calendar_destroy (GtkWidget *widget)
{
GtkCalendar *calendar = GTK_CALENDAR (widget);
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
calendar_stop_spinning (calendar);
- /* Call the destroy function for the extra display callback: */
- if (priv->detail_func_destroy && priv->detail_func_user_data)
- {
- priv->detail_func_destroy (priv->detail_func_user_data);
- priv->detail_func_user_data = NULL;
- priv->detail_func_destroy = NULL;
- }
-
GTK_WIDGET_CLASS (gtk_calendar_parent_class)->destroy (widget);
}
@@ -1504,20 +1423,6 @@ gtk_calendar_set_property (GObject *object,
g_value_get_boolean (value)))
g_object_notify (object, "show-week-numbers");
break;
- case PROP_SHOW_DETAILS:
- if (calendar_set_display_option (calendar,
- GTK_CALENDAR_SHOW_DETAILS,
- g_value_get_boolean (value)))
- g_object_notify (object, "show-details");
- break;
- case PROP_DETAIL_WIDTH_CHARS:
- gtk_calendar_set_detail_width_chars (calendar,
- g_value_get_int (value));
- break;
- case PROP_DETAIL_HEIGHT_ROWS:
- gtk_calendar_set_detail_height_rows (calendar,
- g_value_get_int (value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1560,16 +1465,6 @@ gtk_calendar_get_property (GObject *object,
g_value_set_boolean (value, calendar_get_display_option (calendar,
GTK_CALENDAR_SHOW_WEEK_NUMBERS));
break;
- case PROP_SHOW_DETAILS:
- g_value_set_boolean (value, calendar_get_display_option (calendar,
- GTK_CALENDAR_SHOW_DETAILS));
- break;
- case PROP_DETAIL_WIDTH_CHARS:
- g_value_set_int (value, priv->detail_width_chars);
- break;
- case PROP_DETAIL_HEIGHT_ROWS:
- g_value_set_int (value, priv->detail_height_rows);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1595,77 +1490,6 @@ calendar_get_ysep (GtkCalendar *calendar)
return 4;
}
-static gchar*
-gtk_calendar_get_detail (GtkCalendar *calendar,
- gint row,
- gint column)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
- gint year, month;
-
- if (priv->detail_func == NULL)
- return NULL;
-
- year = priv->year;
- month = priv->month + priv->day_month[row][column] - MONTH_CURRENT;
-
- if (month < 0)
- {
- month += 12;
- year -= 1;
- }
- else if (month > 11)
- {
- month -= 12;
- year += 1;
- }
-
- return priv->detail_func (calendar,
- year, month,
- priv->day[row][column],
- priv->detail_func_user_data);
-}
-
-static gboolean
-gtk_calendar_query_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip)
-{
- GtkCalendar *calendar = GTK_CALENDAR (widget);
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
- gchar *detail = NULL;
- GdkRectangle day_rect;
- gint row, col;
-
- col = calendar_column_from_x (calendar, x);
- row = calendar_row_from_y (calendar, y);
-
- if (col != -1 && row != -1 &&
- (0 != (priv->detail_overflow[row] & (1 << col)) ||
- 0 == (priv->display_flags & GTK_CALENDAR_SHOW_DETAILS)))
- {
- detail = gtk_calendar_get_detail (calendar, row, col);
- calendar_day_rectangle (calendar, row, col, &day_rect);
- }
-
- if (detail)
- {
- gtk_tooltip_set_tip_area (tooltip, &day_rect);
- gtk_tooltip_set_markup (tooltip, detail);
-
- g_free (detail);
-
- return TRUE;
- }
-
- if (GTK_WIDGET_CLASS (gtk_calendar_parent_class)->query_tooltip)
- return GTK_WIDGET_CLASS (gtk_calendar_parent_class)->query_tooltip (widget, x, y, keyboard_mode,
tooltip);
-
- return FALSE;
-}
-
/****************************************
* Size Request and Allocate *
****************************************/
@@ -1680,11 +1504,10 @@ gtk_calendar_size_request (GtkWidget *widget,
PangoLayout *layout;
PangoRectangle logical_rect;
gint height;
- gint i, r, c;
+ gint i;
gint calendar_margin = CALENDAR_MARGIN;
gint header_width = 0, main_width;
gint max_header_height = 0;
- gint max_detail_height;
gint inner_border = calendar_get_inner_border (calendar);
gint calendar_ysep = calendar_get_ysep (calendar);
gint calendar_xsep = calendar_get_xsep (calendar);
@@ -1757,74 +1580,6 @@ gtk_calendar_size_request (GtkWidget *widget,
logical_rect.width / 2);
}
- /* Calculate detail extents. Do this as late as possible since
- * pango_layout_set_markup is called which alters font settings. */
- max_detail_height = 0;
-
- if (priv->detail_func && (priv->display_flags & GTK_CALENDAR_SHOW_DETAILS))
- {
- gchar *markup, *tail;
-
- if (priv->detail_width_chars || priv->detail_height_rows)
- {
- gint rows = MAX (1, priv->detail_height_rows) - 1;
- gsize len = priv->detail_width_chars + rows + 16;
-
- markup = tail = g_alloca (len);
-
- memcpy (tail, "<small>", 7);
- tail += 7;
-
- memset (tail, 'm', priv->detail_width_chars);
- tail += priv->detail_width_chars;
-
- memset (tail, '\n', rows);
- tail += rows;
-
- memcpy (tail, "</small>", 9);
- tail += 9;
-
- g_assert (len == (tail - markup));
-
- pango_layout_set_markup (layout, markup, -1);
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-
- if (priv->detail_width_chars)
- priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
- if (priv->detail_height_rows)
- max_detail_height = MAX (max_detail_height, logical_rect.height);
- }
-
- if (!priv->detail_width_chars || !priv->detail_height_rows)
- for (r = 0; r < 6; r++)
- for (c = 0; c < 7; c++)
- {
- gchar *detail = gtk_calendar_get_detail (calendar, r, c);
-
- if (detail)
- {
- markup = g_strconcat ("<small>", detail, "</small>", NULL);
- pango_layout_set_markup (layout, markup, -1);
-
- if (priv->detail_width_chars)
- {
- pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
- pango_layout_set_width (layout, PANGO_SCALE * priv->min_day_width);
- }
-
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-
- if (!priv->detail_width_chars)
- priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
- if (!priv->detail_height_rows)
- max_detail_height = MAX (max_detail_height, logical_rect.height);
-
- g_free (markup);
- g_free (detail);
- }
- }
- }
-
get_component_paddings (calendar, &day_padding, &day_name_padding, &week_padding);
priv->min_day_width += day_padding.left + day_padding.right;
@@ -1870,7 +1625,6 @@ gtk_calendar_size_request (GtkWidget *widget,
priv->main_h = (CALENDAR_MARGIN + calendar_margin
+ 6 * (priv->max_day_char_ascent
+ priv->max_day_char_descent
- + max_detail_height
+ day_padding.top + day_padding.bottom)
+ DAY_YSEP * 5);
@@ -2149,14 +1903,6 @@ calendar_invalidate_day (GtkCalendar *calendar,
gtk_widget_queue_draw (GTK_WIDGET (calendar));
}
-static gboolean
-is_color_attribute (PangoAttribute *attribute,
- gpointer data)
-{
- return (attribute->klass->type == PANGO_ATTR_FOREGROUND ||
- attribute->klass->type == PANGO_ATTR_BACKGROUND);
-}
-
static void
calendar_snapshot_day (GtkCalendar *calendar,
GtkSnapshot *snapshot,
@@ -2167,7 +1913,6 @@ calendar_snapshot_day (GtkCalendar *calendar,
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
GtkStyleContext *context;
GtkStateFlags state = 0;
- gchar *detail;
gchar buffer[32];
gint day;
gint x_loc, y_loc;
@@ -2175,8 +1920,6 @@ calendar_snapshot_day (GtkCalendar *calendar,
PangoLayout *layout;
PangoRectangle logical_rect;
- gboolean overflow = FALSE;
- gboolean show_details;
g_return_if_fail (row < 6);
g_return_if_fail (col < 7);
@@ -2185,7 +1928,6 @@ calendar_snapshot_day (GtkCalendar *calendar,
state = gtk_widget_get_state_flags (widget);
day = priv->day[row][col];
- show_details = (priv->display_flags & GTK_CALENDAR_SHOW_DETAILS);
calendar_day_rectangle (calendar, row, col, &day_rect);
@@ -2228,8 +1970,6 @@ calendar_snapshot_day (GtkCalendar *calendar,
/* Get extra information to show, if any: */
- detail = gtk_calendar_get_detail (calendar, row, col);
-
layout = gtk_widget_create_pango_layout (widget, buffer);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
@@ -2239,74 +1979,16 @@ calendar_snapshot_day (GtkCalendar *calendar,
gtk_snapshot_render_layout (snapshot, context, x_loc, y_loc, layout);
- if (priv->day_month[row][col] == MONTH_CURRENT &&
- (priv->marked_date[day-1] || (detail && !show_details)))
- gtk_snapshot_render_layout (snapshot, context, x_loc - 1, y_loc, layout);
-
y_loc += priv->max_day_char_descent;
- if (priv->detail_func && show_details)
- {
- GdkRGBA color;
-
- gtk_style_context_get_color (context, &color);
-
- gtk_snapshot_append_color (snapshot,
- &color,
- &GRAPHENE_RECT_INIT (
- day_rect.x + 2, y_loc,
- day_rect.width - 2, 1
- ));
-
- y_loc += 2;
- }
-
- if (detail && show_details)
- {
- gchar *markup = g_strconcat ("<small>", detail, "</small>", NULL);
- pango_layout_set_markup (layout, markup, -1);
- g_free (markup);
-
- if (day == priv->selected_day)
- {
- /* Stripping colors as they conflict with selection marking. */
-
- PangoAttrList *attrs = pango_layout_get_attributes (layout);
- PangoAttrList *colors = NULL;
-
- if (attrs)
- colors = pango_attr_list_filter (attrs, is_color_attribute, NULL);
- if (colors)
- pango_attr_list_unref (colors);
- }
-
- pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
- pango_layout_set_width (layout, PANGO_SCALE * day_rect.width);
-
- if (priv->detail_height_rows)
- {
- gint dy = day_rect.height - (y_loc - day_rect.y);
- pango_layout_set_height (layout, PANGO_SCALE * dy);
- pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
- }
-
- gtk_snapshot_render_layout (snapshot, context, day_rect.x, y_loc, layout);
- }
-
if (gtk_widget_has_visible_focus (widget) &&
priv->focus_row == row && priv->focus_col == col)
gtk_snapshot_render_focus (snapshot, context,
day_rect.x, day_rect.y,
day_rect.width, day_rect.height);
- if (overflow)
- priv->detail_overflow[row] |= (1 << col);
- else
- priv->detail_overflow[row] &= ~(1 << col);
-
gtk_style_context_restore (context);
g_object_unref (layout);
- g_free (detail);
}
static void
@@ -3064,9 +2746,6 @@ gtk_calendar_set_display_options (GtkCalendar *calendar,
priv->display_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
}
- if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_DETAILS)
- resize++;
-
priv->display_flags = flags;
if (resize)
gtk_widget_queue_resize (GTK_WIDGET (calendar));
@@ -3290,129 +2969,3 @@ gtk_calendar_get_date (GtkCalendar *calendar,
if (day)
*day = priv->selected_day;
}
-
-/**
- * gtk_calendar_set_detail_func:
- * @calendar: a #GtkCalendar.
- * @func: a function providing details for each day.
- * @data: data to pass to @func invokations.
- * @destroy: a function for releasing @data.
- *
- * Installs a function which provides Pango markup with detail information
- * for each day. Examples for such details are holidays or appointments. That
- * information is shown below each day when #GtkCalendar:show-details is set.
- * A tooltip containing with full detail information is provided, if the entire
- * text should not fit into the details area, or if #GtkCalendar:show-details
- * is not set.
- *
- * The size of the details area can be restricted by setting the
- * #GtkCalendar:detail-width-chars and #GtkCalendar:detail-height-rows
- * properties.
- */
-void
-gtk_calendar_set_detail_func (GtkCalendar *calendar,
- GtkCalendarDetailFunc func,
- gpointer data,
- GDestroyNotify destroy)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- g_return_if_fail (GTK_IS_CALENDAR (calendar));
-
- if (priv->detail_func_destroy)
- priv->detail_func_destroy (priv->detail_func_user_data);
-
- priv->detail_func = func;
- priv->detail_func_user_data = data;
- priv->detail_func_destroy = destroy;
-
- gtk_widget_set_has_tooltip (GTK_WIDGET (calendar),
- NULL != priv->detail_func);
- gtk_widget_queue_resize (GTK_WIDGET (calendar));
-}
-
-/**
- * gtk_calendar_set_detail_width_chars:
- * @calendar: a #GtkCalendar.
- * @chars: detail width in characters.
- *
- * Updates the width of detail cells.
- * See #GtkCalendar:detail-width-chars.
- */
-void
-gtk_calendar_set_detail_width_chars (GtkCalendar *calendar,
- gint chars)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- g_return_if_fail (GTK_IS_CALENDAR (calendar));
-
- if (chars != priv->detail_width_chars)
- {
- priv->detail_width_chars = chars;
- g_object_notify (G_OBJECT (calendar), "detail-width-chars");
- gtk_widget_queue_resize (GTK_WIDGET (calendar));
- }
-}
-
-/**
- * gtk_calendar_set_detail_height_rows:
- * @calendar: a #GtkCalendar.
- * @rows: detail height in rows.
- *
- * Updates the height of detail cells.
- * See #GtkCalendar:detail-height-rows.
- */
-void
-gtk_calendar_set_detail_height_rows (GtkCalendar *calendar,
- gint rows)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- g_return_if_fail (GTK_IS_CALENDAR (calendar));
-
- if (rows != priv->detail_height_rows)
- {
- priv->detail_height_rows = rows;
- g_object_notify (G_OBJECT (calendar), "detail-height-rows");
- gtk_widget_queue_resize (GTK_WIDGET (calendar));
- }
-}
-
-/**
- * gtk_calendar_get_detail_width_chars:
- * @calendar: a #GtkCalendar.
- *
- * Queries the width of detail cells, in characters.
- * See #GtkCalendar:detail-width-chars.
- *
- * Returns: The width of detail cells, in characters.
- */
-gint
-gtk_calendar_get_detail_width_chars (GtkCalendar *calendar)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
-
- return priv->detail_width_chars;
-}
-
-/**
- * gtk_calendar_get_detail_height_rows:
- * @calendar: a #GtkCalendar.
- *
- * Queries the height of detail cells, in rows.
- * See #GtkCalendar:detail-width-chars.
- *
- * Returns: The height of detail cells, in rows.
- */
-gint
-gtk_calendar_get_detail_height_rows (GtkCalendar *calendar)
-{
- GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
-
- g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
-
- return priv->detail_height_rows;
-}
diff --git a/gtk/gtkcalendar.h b/gtk/gtkcalendar.h
index 057d19ffed..a7bb609c48 100644
--- a/gtk/gtkcalendar.h
+++ b/gtk/gtkcalendar.h
@@ -52,8 +52,6 @@ typedef struct _GtkCalendar GtkCalendar;
* @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.
- * @GTK_CALENDAR_SHOW_DETAILS: Just show an indicator, not the full details
- * text when details are provided. See gtk_calendar_set_detail_func().
*
* These options can be used to influence the display and behaviour of a #GtkCalendar.
*/
@@ -63,30 +61,8 @@ typedef enum
GTK_CALENDAR_SHOW_DAY_NAMES = 1 << 1,
GTK_CALENDAR_NO_MONTH_CHANGE = 1 << 2,
GTK_CALENDAR_SHOW_WEEK_NUMBERS = 1 << 3,
- GTK_CALENDAR_SHOW_DETAILS = 1 << 5
} GtkCalendarDisplayOptions;
-/**
- * GtkCalendarDetailFunc:
- * @calendar: a #GtkCalendar.
- * @year: the year for which details are needed.
- * @month: the month for which details are needed.
- * @day: the day of @month for which details are needed.
- * @user_data: the data passed with gtk_calendar_set_detail_func().
- *
- * This kind of functions provide Pango markup with detail information for the
- * specified day. Examples for such details are holidays or appointments. The
- * function returns %NULL when no information is available.
- *
- * Returns: (nullable) (transfer full): Newly allocated string with Pango markup
- * with details for the specified day or %NULL.
- */
-typedef gchar* (*GtkCalendarDetailFunc) (GtkCalendar *calendar,
- guint year,
- guint month,
- guint day,
- gpointer user_data);
-
GDK_AVAILABLE_IN_ALL
GType gtk_calendar_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
@@ -117,29 +93,11 @@ GDK_AVAILABLE_IN_ALL
GtkCalendarDisplayOptions
gtk_calendar_get_display_options (GtkCalendar *calendar);
GDK_AVAILABLE_IN_ALL
-void gtk_calendar_get_date (GtkCalendar *calendar,
+void gtk_calendar_get_date (GtkCalendar *calendar,
guint *year,
guint *month,
guint *day);
-GDK_AVAILABLE_IN_ALL
-void gtk_calendar_set_detail_func (GtkCalendar *calendar,
- GtkCalendarDetailFunc func,
- gpointer data,
- GDestroyNotify destroy);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_calendar_set_detail_width_chars (GtkCalendar *calendar,
- gint chars);
-GDK_AVAILABLE_IN_ALL
-void gtk_calendar_set_detail_height_rows (GtkCalendar *calendar,
- gint rows);
-
-GDK_AVAILABLE_IN_ALL
-gint gtk_calendar_get_detail_width_chars (GtkCalendar *calendar);
-GDK_AVAILABLE_IN_ALL
-gint gtk_calendar_get_detail_height_rows (GtkCalendar *calendar);
-
GDK_AVAILABLE_IN_ALL
gboolean gtk_calendar_get_day_is_marked (GtkCalendar *calendar,
guint day);
diff --git a/tests/testcalendar.c b/tests/testcalendar.c
index 98481331a0..f36d53c955 100644
--- a/tests/testcalendar.c
+++ b/tests/testcalendar.c
@@ -22,7 +22,6 @@
#include <string.h>
#include <gtk/gtk.h>
-#define DEF_PAD 12
#define DEF_PAD_SMALL 6
#define TM_YEAR_BASE 1900
@@ -38,10 +37,6 @@ typedef struct _CalendarData
GtkWidget *prev_sig;
GtkWidget *last_sig;
GtkWidget *month;
-
- GHashTable *details_table;
- GtkTextBuffer *details_buffer;
- gulong details_changed;
} CalendarData;
enum
@@ -79,49 +74,6 @@ calendar_date_to_string (CalendarData *data,
}
}
-static void
-calendar_set_detail (CalendarData *data,
- guint year,
- guint month,
- guint day,
- gchar *detail)
-{
- gchar *key = g_strdup_printf ("%04d-%02d-%02d", year, month + 1, day);
- g_hash_table_replace (data->details_table, key, detail);
-}
-
-static gchar*
-calendar_get_detail (CalendarData *data,
- guint year,
- guint month,
- guint day)
-{
- const gchar *detail;
- gchar *key;
-
- key = g_strdup_printf ("%04d-%02d-%02d", year, month + 1, day);
- detail = g_hash_table_lookup (data->details_table, key);
- g_free (key);
-
- return (detail ? g_strdup (detail) : NULL);
-}
-
-static void
-calendar_update_details (CalendarData *data)
-{
- guint year, month, day;
- gchar *detail;
-
- gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget), &year, &month, &day);
- detail = calendar_get_detail (data, year, month, day);
-
- g_signal_handler_block (data->details_buffer, data->details_changed);
- gtk_text_buffer_set_text (data->details_buffer, detail ? detail : "", -1);
- g_signal_handler_unblock (data->details_buffer, data->details_changed);
-
- g_free (detail);
-}
-
static void
calendar_set_signal_strings (char *sig_str,
CalendarData *data)
@@ -154,8 +106,6 @@ calendar_day_selected (GtkWidget *widget,
calendar_date_to_string (data, buffer+14, 256-14);
calendar_set_signal_strings (buffer, data);
-
- calendar_update_details (data);
}
static void
@@ -267,107 +217,6 @@ void calendar_select_font (GtkWidget *button,
}
}
-static gchar*
-calendar_detail_cb (GtkCalendar *calendar,
- guint year,
- guint month,
- guint day,
- gpointer data)
-{
- return calendar_get_detail (data, year, month, day);
-}
-
-static void
-calendar_details_changed (GtkTextBuffer *buffer,
- CalendarData *data)
-{
- GtkTextIter start, end;
- guint year, month, day;
- gchar *detail;
-
- gtk_text_buffer_get_start_iter(buffer, &start);
- gtk_text_buffer_get_end_iter(buffer, &end);
-
- gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget), &year, &month, &day);
- detail = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
-
- if (!detail[0])
- {
- g_free (detail);
- detail = NULL;
- }
-
- calendar_set_detail (data, year, month, day, detail);
- gtk_widget_queue_resize (data->calendar_widget);
-}
-
-static void
-demonstrate_details (CalendarData *data)
-{
- static char *rainbow[] = { "#900", "#980", "#390", "#095", "#059", "#309", "#908" };
- GtkCalendar *calendar = GTK_CALENDAR (data->calendar_widget);
- guint year, month, day;
- gchar *detail;
-
- gtk_calendar_get_date (calendar,
- &year, &month, &day);
-
- for (day = 0; day < 29; ++day)
- {
- detail = g_strdup_printf ("<span color='%s'>yadda\n"
- "(%04d-%02d-%02d)</span>",
- rainbow[(day - 1) % 7], year, month, day);
- calendar_set_detail (data, year, month, day, detail);
- }
-
- gtk_widget_queue_resize (data->calendar_widget);
- calendar_update_details (data);
-}
-
-static void
-reset_details (CalendarData *data)
-{
- g_hash_table_remove_all (data->details_table);
- gtk_widget_queue_resize (data->calendar_widget);
- calendar_update_details (data);
-}
-
-static void
-calendar_toggle_details (GtkWidget *widget,
- CalendarData *data)
-{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
- gtk_calendar_set_detail_func (GTK_CALENDAR (data->calendar_widget),
- calendar_detail_cb, data, NULL);
- else
- gtk_calendar_set_detail_func (GTK_CALENDAR (data->calendar_widget),
- NULL, NULL, NULL);
-}
-
-static GtkWidget*
-create_expander (const char *caption,
- GtkWidget *child,
- GtkAlign halign,
- GtkAlign valign)
-{
- GtkWidget *expander = gtk_expander_new ("");
- GtkWidget *label = gtk_expander_get_label_widget (GTK_EXPANDER (expander));
-
- g_object_set (child,
- "margin-top", 6,
- "margin-bottom", 0,
- "margin-start", 18,
- "margin-end", 0,
- "halign", halign,
- "valign", valign,
- NULL);
- gtk_label_set_markup (GTK_LABEL (label), caption);
-
- gtk_container_add (GTK_CONTAINER (expander), child);
-
- return expander;
-}
-
static GtkWidget*
create_frame (const char *caption,
GtkWidget *child,
@@ -393,34 +242,16 @@ create_frame (const char *caption,
return frame;
}
-static void
-detail_width_changed (GtkSpinButton *button,
- CalendarData *data)
-{
- gint value = (gint) gtk_spin_button_get_value (button);
- gtk_calendar_set_detail_width_chars (GTK_CALENDAR (data->calendar_widget), value);
-}
-
-static void
-detail_height_changed (GtkSpinButton *button,
- CalendarData *data)
-{
- gint value = (gint) gtk_spin_button_get_value (button);
- gtk_calendar_set_detail_height_rows (GTK_CALENDAR (data->calendar_widget), value);
-}
-
static void
create_calendar(void)
{
static CalendarData calendar_data;
GtkWidget *window, *hpaned, *vbox, *rpane, *hbox;
- GtkWidget *calendar, *toggle, *scroller, *button;
- GtkWidget *frame, *label, *bbox, *details;
-
- GtkSizeGroup *size;
+ GtkWidget *calendar, *toggle, *button;
+ GtkWidget *frame, *label, *bbox;
gint i;
-
+
struct {
gboolean init;
char *label;
@@ -436,7 +267,6 @@ create_calendar(void)
calendar_data.window = NULL;
calendar_data.font_dialog = NULL;
- calendar_data.details_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
calendar_data.settings[i] = 0;
@@ -487,108 +317,16 @@ create_calendar(void)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
frame = create_frame ("<b>Options</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (rpane), frame);
- size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-
- /* Build the width entry */
-
- button = gtk_spin_button_new_with_range (0, 127, 1);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (button),
- gtk_calendar_get_detail_width_chars (GTK_CALENDAR (calendar)));
-
- g_signal_connect (button, "value-changed",
- G_CALLBACK (detail_width_changed),
- &calendar_data);
-
- label = gtk_label_new_with_mnemonic ("Details W_idth:");
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- gtk_widget_set_halign (label, GTK_ALIGN_START);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_size_group_add_widget (size, label);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
- gtk_container_add (GTK_CONTAINER (hbox), label);
- gtk_container_add (GTK_CONTAINER (hbox), button);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- /* Build the height entry */
-
- button = gtk_spin_button_new_with_range (0, 127, 1);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (button),
- gtk_calendar_get_detail_height_rows (GTK_CALENDAR (calendar)));
-
- g_signal_connect (button, "value-changed",
- G_CALLBACK (detail_height_changed),
- &calendar_data);
-
- label = gtk_label_new_with_mnemonic ("Details H_eight:");
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- gtk_widget_set_halign (label, GTK_ALIGN_START);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_size_group_add_widget (size, label);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
- gtk_container_add (GTK_CONTAINER (hbox), label);
- gtk_container_add (GTK_CONTAINER (hbox), button);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- /* Build the right details frame */
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
- frame = create_frame ("<b>Details</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (rpane), frame);
-
- details = gtk_text_view_new();
- calendar_data.details_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (details));
-
- calendar_data.details_changed = g_signal_connect (calendar_data.details_buffer, "changed",
- G_CALLBACK (calendar_details_changed),
- &calendar_data);
-
- scroller = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (scroller), details);
-
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroller),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- gtk_container_add (GTK_CONTAINER (vbox), scroller);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
gtk_widget_set_halign (hbox, GTK_ALIGN_START);
gtk_widget_set_valign (hbox, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
- button = gtk_button_new_with_mnemonic ("Demonstrate _Details");
-
- g_signal_connect_swapped (button,
- "clicked",
- G_CALLBACK (demonstrate_details),
- &calendar_data);
-
- gtk_container_add (GTK_CONTAINER (hbox), button);
-
- button = gtk_button_new_with_mnemonic ("_Reset Details");
-
- g_signal_connect_swapped (button,
- "clicked",
- G_CALLBACK (reset_details),
- &calendar_data);
-
- gtk_container_add (GTK_CONTAINER (hbox), button);
-
- toggle = gtk_check_button_new_with_mnemonic ("_Use Details");
- g_signal_connect (toggle, "toggled",
- G_CALLBACK(calendar_toggle_details),
- &calendar_data);
- gtk_container_add (GTK_CONTAINER (vbox), toggle);
-
/* Build the Right frame with the flags in */
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- frame = create_expander ("<b>Flags</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_CENTER);
- gtk_container_add (GTK_CONTAINER (rpane), frame);
+ gtk_container_add (GTK_CONTAINER (rpane), vbox);
for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
{
@@ -598,7 +336,7 @@ create_calendar(void)
g_signal_connect (toggle, "toggled",
G_CALLBACK (calendar_toggle_flag),
- &calendar_data);
+ &calendar_data);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), flags[i].init);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]