1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/*
* This file is a part of hildon
*
* Copyright (C) 2008 Nokia Corporation, all rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation; version 2 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser Public License for more details.
*
*/
#include <libintl.h>
#include "hildon-stock.h"
#include "hildon-date-button.h"
#include "hildon-date-selector.h"
#include "hildon-touch-selector.h"
#include "hildon-picker-button-private.h"
/**
* SECTION:hildon-date-button
* @Short_Description: Button displaying and allowing selection of a date.
* @See_Also: #HildonPickerButton, #HildonTimeButton
*
* #HildonDateButton is a widget that shows a text label and a date, and allows
* the user to select a different date. Visually, it's a button that, once clicked,
* presents a #HildonPickerDialog containing a #HildonDateSelector. Once the user selects
* a different date from the selector, this will be shown in the button.
*/
G_DEFINE_TYPE (HildonDateButton, hildon_date_button, HILDON_TYPE_PICKER_BUTTON)
#if 0
#define GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_DATE_BUTTON, HildonDateButtonPrivate))
typedef struct _HildonDateButtonPrivate HildonDateButtonPrivate;
struct _HildonDateButtonPrivate
{
};
#endif
#if 0
static void
hildon_date_button_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
hildon_date_button_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec)
{
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
#endif
static GObject *
hildon_date_button_constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
object = G_OBJECT_CLASS (hildon_date_button_parent_class)->constructor (type,
n_construct_params,
construct_params);
gtk_button_set_use_stock (GTK_BUTTON (object), TRUE);
return object;
}
static void
hildon_date_button_class_init (HildonDateButtonClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = hildon_date_button_constructor;
#if 0
g_type_class_add_private (klass, sizeof (HildonDateButtonPrivate));
object_class->get_property = hildon_date_button_get_property;
object_class->set_property = hildon_date_button_set_property;
#endif
}
static void
hildon_date_button_init (HildonDateButton * self)
{
GtkWidget *date_selector;
date_selector = hildon_date_selector_new ();
hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self),
HILDON_TOUCH_SELECTOR (date_selector));
}
static GtkWidget *
hildon_date_button_new_full (HildonSizeType size,
HildonButtonArrangement arrangement,
GtkWidget *selector)
{
return g_object_new (HILDON_TYPE_DATE_BUTTON,
"title", HILDON_STOCK_DATE,
"arrangement", arrangement,
"size", size,
"touch-selector", selector,
NULL);
}
/**
* hildon_date_button_new:
* @size: One of #HildonSizeType
* @arrangement: one of #HildonButtonArrangement
*
* Creates a new #HildonDateButton. See hildon_button_new() for details on the
* parameters.
*
* Returns: a new #HildonDateButton
*
* Since: 2.2
**/
GtkWidget *
hildon_date_button_new (HildonSizeType size,
HildonButtonArrangement arrangement)
{
GtkWidget *selector = hildon_date_selector_new ();
return hildon_date_button_new_full (size, arrangement, selector);
}
/**
* hildon_date_button_new_with_year_range:
* @size: One of #HildonSizeType
* @arrangement: one of #HildonButtonArrangement
* @min_year: the minimum available year or -1 to ignore
* @max_year: the maximum available year or -1 to ignore
*
* Creates a new #HildonDateButton with a specific valid range of years.
* See hildon_date_selector_new_with_year_range() for details on the range.
*
* Returns: a new #HildonDateButton
*
* Since: 2.2
**/
GtkWidget *
hildon_date_button_new_with_year_range (HildonSizeType size,
HildonButtonArrangement arrangement,
gint min_year,
gint max_year)
{
GtkWidget *selector;
selector = hildon_date_selector_new_with_year_range (min_year, max_year);
return hildon_date_button_new_full (size, arrangement, selector);
}
/**
* hildon_date_button_get_date:
* @button: a #HildonDateButton
* @year: return location for the selected year
* @month: return location for the selected month
* @day: return location for the selected day
*
* Retrieves currently selected date from @button.
*
* Since: 2.2
**/
void
hildon_date_button_get_date (HildonDateButton * button,
guint * year, guint * month, guint * day)
{
HildonTouchSelector *selector;
g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
hildon_date_selector_get_date (HILDON_DATE_SELECTOR (selector), year, month, day);
}
/**
* hildon_date_button_set_date:
* @button: a #HildonDateButton
* @year: the year to set.
* @month: the month number to set.
* @day: the day of the month to set.
*
* Sets the date in @button. The date set will be displayed
* and will be the default selected option on the shown #HildonDateSelector.
*
* Since: 2.2
**/
void
hildon_date_button_set_date (HildonDateButton * button,
guint year, guint month, guint day)
{
HildonTouchSelector *selector;
gchar *date;
g_return_if_fail (HILDON_IS_DATE_BUTTON (button));
selector = hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (button));
g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), TRUE);
hildon_date_selector_select_current_date (HILDON_DATE_SELECTOR (selector),
year, month, day);
hildon_picker_button_disable_value_changed (HILDON_PICKER_BUTTON (button), FALSE);
date = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
hildon_button_set_value (HILDON_BUTTON (button), date);
g_free (date);
hildon_picker_button_value_changed (HILDON_PICKER_BUTTON (button));
}
|