2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser Public License as published by
8 * the Free Software Foundation; version 2 of the license.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser Public License for more details.
17 #include "hildon-date-button.h"
18 #include "hildon-date-selector.h"
19 #include "hildon-touch-selector.h"
22 * SECTION:hildon-date-button
23 * @Short_Description: Button displaying and allowing selection of a date.
24 * @See_Also: #HildonPickerButton, #HildonTimeButton
26 * #HildonDateButton is a widget that shows a text label and a date, and allows
27 * the user to select a different date. Visually, it's a button that, once clicked,
28 * presents a #HildonPickerDialog containing a #HildonDateSelector. Once the user selects
29 * a different date from the selector, this will be shown in the button.
32 G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
35 #define GET_PRIVATE(o) \
36 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_DATE_BUTTON, HildonDateButtonPrivate))
38 typedef struct _HildonDateButtonPrivate HildonDateButtonPrivate;
40 struct _HildonDateButtonPrivate
47 hildon_date_button_get_property (GObject * object, guint property_id,
48 GValue * value, GParamSpec * pspec)
50 switch (property_id) {
52 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
57 hildon_date_button_set_property (GObject * object, guint property_id,
58 const GValue * value, GParamSpec * pspec)
60 switch (property_id) {
62 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 hildon_date_button_class_init (HildonDateButtonClass * klass)
71 GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 g_type_class_add_private (klass, sizeof (HildonDateButtonPrivate));
75 object_class->get_property = hildon_date_button_get_property;
76 object_class->set_property = hildon_date_button_set_property;
81 hildon_date_button_init (HildonDateButton * self)
83 GtkWidget *date_selector;
85 date_selector = hildon_date_selector_new ();
87 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self),
88 HILDON_TOUCH_SELECTOR (date_selector));
92 * hildon_date_button_new:
93 * @size: One of #HildonSizeType
94 * @arrangement: one of #HildonButtonArrangement
96 * Creates a new #HildonDateButton. See hildon_button_new() for details on the
99 * Returns: a new #HildonDateButton
104 hildon_date_button_new (HildonSizeType size,
105 HildonButtonArrangement arrangement)
107 return g_object_new (HILDON_TYPE_DATE_BUTTON,
109 "arrangement", arrangement,
115 * hildon_date_button_new_with_year_range:
116 * @size: One of #HildonSizeType
117 * @arrangement: one of #HildonButtonArrangement
118 * @min_year: the minimum available year or -1 to ignore
119 * @max_year: the maximum available year or -1 to ignore
121 * Creates a new #HildonDateButton with a specific valid range of years.
122 * See hildon_date_selector_new_with_year_range() for details on the range.
124 * Returns: a new #HildonDateButton
129 hildon_date_button_new_with_year_range (HildonSizeType size,
130 HildonButtonArrangement arrangement,
137 button = hildon_date_button_new (size, arrangement);
138 selector = hildon_date_selector_new_with_year_range (min_year, max_year);
139 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
140 HILDON_TOUCH_SELECTOR (selector));
146 * hildon_date_button_get_date:
147 * @button: a #HildonDateButton
148 * @year: return location for the selected year
149 * @month: return location for the selected month
150 * @day: return location for the selected day
152 * Retrieves currently selected date from @button.
157 hildon_date_button_get_date (HildonDateButton * button,
158 guint * year, guint * month, guint * day)
160 HildonTouchSelector *selector;
162 g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
164 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
166 hildon_date_selector_get_date (HILDON_DATE_SELECTOR (selector), year, month, day);
170 * hildon_date_button_set_date:
171 * @button: a #HildonDateButton
172 * @year: the year to set.
173 * @month: the month number to set.
174 * @day: the day of the month to set.
176 * Sets the date in @button. The date set will be displayed
177 * and will be the default selected option on the shown #HildonDateSelector.
182 hildon_date_button_set_date (HildonDateButton * button,
183 guint year, guint month, guint day)
185 HildonTouchSelector *selector;
188 g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
190 selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
192 hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (selector),
194 date = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
196 hildon_button_set_value (HILDON_BUTTON (button), date);