Commit fdbf92ad authored by Mathias Hasselmann's avatar Mathias Hasselmann

Add infrastructure for GtkCalendar details. (#339540)

* gtk/gtkcalendar.c, gtk/gtkcalendar.h, gtk/gtk.symbols:
Add "detail-width-chars" and "detail-height-rows" properties,
and gtk_calendar_set_detail_func function.

svn path=/trunk/; revision=19251
parent b28fea94
2007-12-27 Mathias Hasselmann <mathias@openismus.com>
Add infrastructure for GtkCalendar details. (#339540)
* gtk/gtkcalendar.c, gtk/gtkcalendar.h, gtk/gtk.symbols:
Add "detail-width-chars" and "detail-height-rows" properties,
and gtk_calendar_set_detail_func function.
2007-12-27 Xan Lopez <xan@gnome.org>
* gtk/gtk.symbols:
......
2007-12-27 Mathias Hasselmann <mathias@openismus.com>
* reference/gtk/gtk-sections.txt: Add new GtkCalendar symbols.
2007-12-27 Xan Lopez <xan@gnome.org>
* gtk/gtk-sections.txt: Add gtk_border_new
......
......@@ -547,19 +547,34 @@ gtk_button_get_type
<FILE>gtkcalendar</FILE>
<TITLE>GtkCalendar</TITLE>
GtkCalendar
GtkCalendarDetailFunc
GtkCalendarDisplayOptions
<SUBSECTION>
gtk_calendar_new
gtk_calendar_select_month
gtk_calendar_select_day
gtk_calendar_mark_day
gtk_calendar_unmark_day
gtk_calendar_clear_marks
<SUBSECTION>
gtk_calendar_get_display_options
gtk_calendar_set_display_options
gtk_calendar_display_options
gtk_calendar_get_date
<SUBSECTION>
gtk_calendar_set_detail_func
gtk_calendar_get_detail_width_chars
gtk_calendar_set_detail_width_chars
gtk_calendar_get_detail_height_rows
gtk_calendar_set_detail_height_rows
<SUBSECTION>
gtk_calendar_display_options
gtk_calendar_freeze
gtk_calendar_thaw
<SUBSECTION Standard>
GTK_CALENDAR
GTK_IS_CALENDAR
......
......@@ -512,12 +512,17 @@ gtk_calendar_thaw
#endif
gtk_calendar_clear_marks
gtk_calendar_get_date
gtk_calendar_get_detail_height_rows
gtk_calendar_get_detail_width_chars
gtk_calendar_get_display_options
gtk_calendar_get_type G_GNUC_CONST
gtk_calendar_mark_day
gtk_calendar_new
gtk_calendar_select_day
gtk_calendar_select_month
gtk_calendar_set_detail_func
gtk_calendar_set_detail_height_rows
gtk_calendar_set_detail_width_chars
gtk_calendar_set_display_options
gtk_calendar_unmark_day
#endif
......
......@@ -232,6 +232,8 @@ enum
PROP_SHOW_DAY_NAMES,
PROP_NO_MONTH_CHANGE,
PROP_SHOW_WEEK_NUMBERS,
PROP_DETAIL_WIDTH_CHARS,
PROP_DETAIL_HEIGHT_ROWS,
PROP_LAST
};
......@@ -280,6 +282,15 @@ 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;
};
#define GTK_CALENDAR_GET_PRIVATE(widget) (GTK_CALENDAR (widget)->priv)
......@@ -492,6 +503,38 @@ gtk_calendar_class_init (GtkCalendarClass *class)
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkCalendar:detail-width-chars:
*
* Width of a detail cell, in characters.
* A value of 0 allows any width. See gtk_calendar_set_detail_func().
*
* Since: 2.16
*/
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));
/**
* GtkCalendar:detail-height-rows:
*
* Height of a detail cell, in rows.
* A value of 0 allows any width. See gtk_calendar_set_detail_func().
*
* Since: 2.16
*/
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));
gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
g_signal_new (I_("month_changed"),
G_OBJECT_CLASS_TYPE (gobject_class),
......@@ -1148,8 +1191,18 @@ gtk_calendar_finalize (GObject *object)
static void
gtk_calendar_destroy (GtkObject *object)
{
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (object);
calendar_stop_spinning (GTK_CALENDAR (object));
/* 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_OBJECT_CLASS (gtk_calendar_parent_class)->destroy (object);
}
......@@ -1220,6 +1273,14 @@ gtk_calendar_set_property (GObject *object,
GTK_CALENDAR_SHOW_WEEK_NUMBERS,
g_value_get_boolean (value));
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;
......@@ -1232,9 +1293,8 @@ gtk_calendar_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GtkCalendar *calendar;
calendar = GTK_CALENDAR (object);
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (object);
GtkCalendar *calendar = GTK_CALENDAR (object);
switch (prop_id)
{
......@@ -1263,6 +1323,12 @@ gtk_calendar_get_property (GObject *object,
g_value_set_boolean (value, calendar_get_display_option (calendar,
GTK_CALENDAR_SHOW_WEEK_NUMBERS));
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;
......@@ -3488,6 +3554,142 @@ gtk_calendar_get_date (GtkCalendar *calendar,
*day = calendar->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.
*
* Since: 2.16
*/
void
gtk_calendar_set_detail_func (GtkCalendar *calendar,
GtkCalendarDetailFunc func,
gpointer data,
GDestroyNotify destroy)
{
GtkCalendarPrivate *priv;
g_return_if_fail (GTK_IS_CALENDAR (calendar));
priv = GTK_CALENDAR_GET_PRIVATE (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.
*
* Since: 2.16
*/
void
gtk_calendar_set_detail_width_chars (GtkCalendar *calendar,
gint chars)
{
GtkCalendarPrivate *priv;
g_return_if_fail (GTK_IS_CALENDAR (calendar));
priv = GTK_CALENDAR_GET_PRIVATE (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_no_redraw (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.
*
* Since: 2.16
*/
void
gtk_calendar_set_detail_height_rows (GtkCalendar *calendar,
gint rows)
{
GtkCalendarPrivate *priv;
g_return_if_fail (GTK_IS_CALENDAR (calendar));
priv = GTK_CALENDAR_GET_PRIVATE (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_no_redraw (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.
*
* Since: 2.16
*
* Return value: The width of detail cells, in characters.
*/
gint
gtk_calendar_get_detail_width_chars (GtkCalendar *calendar)
{
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
return GTK_CALENDAR_GET_PRIVATE (calendar)->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.
*
* Since: 2.16
*
* Return value: The height of detail cells, in rows.
*/
gint
gtk_calendar_get_detail_height_rows (GtkCalendar *calendar)
{
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
return GTK_CALENDAR_GET_PRIVATE (calendar)->detail_height_rows;
}
/**
* gtk_calendar_freeze:
* @calendar: a #GtkCalendar
......
......@@ -60,6 +60,28 @@ typedef enum
GTK_CALENDAR_WEEK_START_MONDAY = 1 << 4
} 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.
*
* Since: 2.16
*
* Return value: Pango markup with details for the specified day, or %NULL.
*/
typedef G_CONST_RETURN gchar* (*GtkCalendarDetailFunc) (GtkCalendar *calendar,
guint year,
guint month,
guint day,
gpointer user_data);
struct _GtkCalendar
{
GtkWidget widget;
......@@ -143,6 +165,20 @@ void gtk_calendar_get_date (GtkCalendar *calendar,
guint *year,
guint *month,
guint *day);
void gtk_calendar_set_detail_func (GtkCalendar *calendar,
GtkCalendarDetailFunc func,
gpointer data,
GDestroyNotify destroy);
void gtk_calendar_set_detail_width_chars (GtkCalendar *calendar,
gint chars);
void gtk_calendar_set_detail_height_rows (GtkCalendar *calendar,
gint rows);
gint gtk_calendar_get_detail_width_chars (GtkCalendar *calendar);
gint gtk_calendar_get_detail_height_rows (GtkCalendar *calendar);
#ifndef GTK_DISABLE_DEPRECATED
void gtk_calendar_freeze (GtkCalendar *calendar);
void gtk_calendar_thaw (GtkCalendar *calendar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment