2 * This file is a part of hildon
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-time-picker
27 * @short_description: A dialog popup widget which lets the user set the time.
28 * @see_also: #HildonTimeEditor
30 * #HildonTimePicker is a dialog popup widget which lets the user set the time,
31 * using up/down arrows on hours and minutes. There are two arrows for minutes,
32 * so that minutes can be added also in 10 min increments.This widget is mainly
33 * used as a part of #HildonTimeEditor implementation.
36 * <title>HildonTimePicker example</title>
39 * parent = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW);
40 * picker = hildon_time_picker_new (GTK_WINDOW (parent));
42 * hildon_time_editor_get_time (editor, &h, &m, &s);
43 * hildon_time_picker_set_time( HILDON_TIME_PICKER( picker ), h, m );
45 * result = gtk_dialog_run (GTK_DIALOG (picker));
48 * case GTK_RESPONSE_OK:
49 * case GTK_RESPONSE_ACCEPT:
50 * hildon_time_picker_get_time(HILDON_TIME_PICKER (picker), &h, &m );
57 * gtk_widget_destroy( picker );
63 #undef HILDON_DISABLE_DEPRECATED
76 #include <gdk/gdkkeysyms.h>
78 #include "hildon-time-picker.h"
79 #include "hildon-defines.h"
80 #include "hildon-time-picker-private.h"
81 #include "hildon-time-editor.h"
84 dgettext("hildon-libs", String)
86 #define DEFAULT_HOURS 1
88 #define DEFAULT_MINUTES 1
90 #define DEFAULT_ARROW_WIDTH 26
92 #define DEFAULT_ARROW_HEIGHT 26
94 #define MINS_IN_1H (60)
96 #define MINS_IN_24H (MINS_IN_1H * 24)
98 #define MINS_IN_12H (MINS_IN_1H * 12)
100 #define HILDON_TIME_PICKER_LABEL_X_PADDING 0
102 #define HILDON_TIME_PICKER_LABEL_Y_PADDING 1
105 hildon_time_picker_class_init (HildonTimePickerClass *klass);
108 hildon_time_picker_init (HildonTimePicker *picker);
111 hildon_time_picker_key_repeat_timeout (gpointer tpicker);
114 hildon_time_picker_change_time (HildonTimePicker *picker,
118 hildon_time_picker_ampm_release (GtkWidget *widget,
120 HildonTimePicker *picker);
123 hildon_time_picker_arrow_press (GtkWidget *widget,
125 HildonTimePicker *picker);
128 hildon_time_picker_arrow_release (GtkWidget *widget,
130 HildonTimePicker *picker);
133 hildon_time_picker_finalize (GObject *object);
136 hildon_time_picker_get_property (GObject *object,
142 hildon_time_picker_set_property (GObject *object,
148 hildon_time_picker_event_box_focus_in (GtkWidget *widget,
153 hildon_time_picker_event_box_focus_out (GtkWidget *widget,
158 hildon_time_picker_event_box_key_press (GtkWidget *widget,
160 HildonTimePicker *picker);
163 hildon_time_picker_event_box_key_release (GtkWidget *widget,
165 HildonTimePicker *picker);
168 hildon_time_picker_event_box_button_press (GtkWidget *widget,
173 hildon_time_picker_realize (GtkWidget *widget);
176 hildon_time_picker_style_set (GtkWidget *widget,
177 GtkStyle *previous_style);
180 frame_size_request (GtkWidget *widget,
181 GtkRequisition *requistion);
183 static GtkDialogClass* parent_class;
191 static const gint button_multipliers[WIDGET_GROUP_COUNT][2] =
193 { MINS_IN_1H, -MINS_IN_1H },
200 * hildon_time_picker_get_type:
202 * Returns the type of HildonTimePicker.
204 * Returns: HildonTimePicker type
207 hildon_time_picker_get_type (void)
209 static GType picker_type = 0;
213 static const GTypeInfo picker_info =
215 sizeof (HildonTimePickerClass),
216 NULL, /* base_init */
217 NULL, /* base_finalize */
218 (GClassInitFunc)hildon_time_picker_class_init,
219 NULL, /* class_finalize */
220 NULL, /* class_data */
221 sizeof (HildonTimePicker),
223 (GInstanceInitFunc)hildon_time_picker_init,
225 picker_type = g_type_register_static( GTK_TYPE_DIALOG, "HildonTimePicker",
233 hildon_time_picker_class_init (HildonTimePickerClass *klass)
235 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
236 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
237 parent_class = g_type_class_peek_parent (klass);
239 gobject_class->finalize = hildon_time_picker_finalize;
240 gobject_class->get_property = hildon_time_picker_get_property;
241 gobject_class->set_property = hildon_time_picker_set_property;
242 widget_class->realize = hildon_time_picker_realize;
243 widget_class->style_set = hildon_time_picker_style_set;
246 * HildonTimePicker:minutes:
248 * Currently selected time in minutes since midnight.
250 g_object_class_install_property (gobject_class, PROP_MINUTES,
251 g_param_spec_uint ("minutes",
253 "The selected time in minutes "
256 G_PARAM_READABLE | G_PARAM_WRITABLE) );
258 gtk_widget_class_install_style_property (widget_class,
259 g_param_spec_uint ("arrow-width",
261 "Increase/decrease arrows width.",
266 gtk_widget_class_install_style_property (widget_class,
267 g_param_spec_uint ("arrow-height",
269 "Increase/decrease arrows height.",
271 DEFAULT_ARROW_HEIGHT,
274 g_type_class_add_private (klass, sizeof (HildonTimePickerPrivate));
277 /* Okay, this is really bad. We make the requisition of the frames a bit larger
278 * so that it doesn't "change" when digits are changed (see #37489). It's a
279 * really bad solution to a problem, but the whole layout of the time picker is
280 * on crack anyways */
282 frame_size_request (GtkWidget *widget,
283 GtkRequisition *requistion)
285 int framed = requistion->width / 10;
286 requistion->width = (framed + 1) * 10;
290 hildon_time_picker_init (HildonTimePicker *picker)
292 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
293 gint widget_group_table_column_pos[WIDGET_GROUP_COUNT];
294 GtkDialog *dialog = GTK_DIALOG (picker);
295 GtkTable *table = NULL;
296 GtkWidget *maintocenter, *colon_label;
297 const struct tm *local = NULL;
303 widget_group_table_column_pos[WIDGET_GROUP_HOURS] = 1;
304 widget_group_table_column_pos[WIDGET_GROUP_10_MINUTES] = 3;
305 widget_group_table_column_pos[WIDGET_GROUP_1_MINUTES] = 4;
306 widget_group_table_column_pos[WIDGET_GROUP_AMPM] = 5;
308 /* Get AM/PM strings from locale. If they're set, the time is wanted
310 priv->am_symbol = g_strdup (nl_langinfo (AM_STR));
311 priv->pm_symbol = g_strdup (nl_langinfo (PM_STR));
313 priv->show_ampm = priv->am_symbol[0] != '\0';
316 /* Check if AM/PM should be before or after time.
317 %p is the AM/PM string, so we assume that if the format string
318 begins with %p it's in the beginning, and in any other case it's
319 in the end (although that's not necessarily the case). */
320 if (strncmp (nl_langinfo (T_FMT_AMPM), "%p", 2) == 0)
322 /* Before time. Update column position. */
323 priv->ampm_left = TRUE;
324 widget_group_table_column_pos[WIDGET_GROUP_AMPM] = 0;
328 gtk_widget_push_composite_child ();
330 /* Pack all our internal widgets into a table */
331 table = GTK_TABLE (gtk_table_new (3, 6, FALSE));
333 /* Put everything centered into window */
334 maintocenter = gtk_alignment_new (0.5, 0, 0, 0);
336 /* Create our internal widgets */
337 for (i = 0; i < WIDGET_GROUP_COUNT; i++)
339 HildonTimePickerWidgetGroup *group = &priv->widgets[i];
340 gint table_column = widget_group_table_column_pos[i];
342 /* Create frame and attach to table. With AM/PM label we're attaching
344 group->frame = gtk_frame_new (NULL);
345 if (i != WIDGET_GROUP_AMPM)
347 gtk_table_attach (table, group->frame, table_column, table_column + 1,
348 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0);
352 /* FIXME: is it needed to force it to 0 here? */
353 gtk_container_set_border_width (GTK_CONTAINER(group->frame), 0);
355 /* Create eventbox inside frame */
356 group->eventbox = gtk_event_box_new ();
357 gtk_container_add (GTK_CONTAINER (group->frame), group->eventbox);
359 g_object_set (group->eventbox, "can-focus", TRUE, NULL);
360 gtk_widget_set_events (group->eventbox,
361 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK);
363 /* Connect signals to eventbox */
364 g_signal_connect (group->eventbox, "key-release-event",
365 G_CALLBACK (hildon_time_picker_event_box_key_release),
367 g_signal_connect (group->eventbox, "key-press-event",
368 G_CALLBACK (hildon_time_picker_event_box_key_press),
370 g_signal_connect (group->eventbox, "focus-in-event",
371 G_CALLBACK (hildon_time_picker_event_box_focus_in),
373 g_signal_connect (group->eventbox, "focus-out-event",
374 G_CALLBACK (hildon_time_picker_event_box_focus_out),
376 g_signal_connect (group->eventbox, "button-press-event",
377 G_CALLBACK (hildon_time_picker_event_box_button_press),
380 /* Create label inside eventbox */
381 group->label = GTK_LABEL (gtk_label_new (NULL));
382 g_signal_connect (group->frame, "size-request",
383 G_CALLBACK (frame_size_request),
385 gtk_misc_set_alignment (GTK_MISC (group->label), 0.5, 0.5);
386 gtk_container_add (GTK_CONTAINER (group->eventbox), GTK_WIDGET (group->label));
388 if (i != WIDGET_GROUP_AMPM)
392 /* Add some padding to hour and minute labels, and make them bigger */
393 gtk_misc_set_padding(GTK_MISC (group->label),
394 HILDON_TIME_PICKER_LABEL_X_PADDING,
395 HILDON_TIME_PICKER_LABEL_Y_PADDING);
397 gtk_widget_set_name (GTK_WIDGET(group->label), "osso-LargeFont");
399 /* Create up and down buttons for hours and mins */
400 for (button = 0; button < BUTTON_COUNT; button++)
402 gint table_row = button == BUTTON_UP ? 0 : 2;
404 group->buttons[button] = gtk_button_new ();
405 gtk_table_attach (table, group->buttons[button],
406 table_column, table_column + 1,
407 table_row, table_row + 1,
408 GTK_SHRINK, GTK_SHRINK, 0, 0);
409 g_object_set (group->buttons[button], "can-focus", FALSE, NULL);
411 /* Connect signals */
412 g_signal_connect(group->buttons[button], "button-press-event",
413 G_CALLBACK (hildon_time_picker_arrow_press), picker);
414 g_signal_connect(group->buttons[button], "button-release-event",
415 G_CALLBACK (hildon_time_picker_arrow_release), picker);
418 gtk_widget_set_name (group->buttons[BUTTON_UP],
419 "hildon-time-picker-up");
420 gtk_widget_set_name (group->buttons[BUTTON_DOWN],
421 "hildon-time-picker-down");
425 /* Label between hour and minutes */
426 colon_label = gtk_label_new (NULL);
427 hildon_time_editor_get_time_separators (GTK_LABEL(colon_label), NULL);
429 gtk_table_attach (table, colon_label, 2, 3, 1, 2,
430 GTK_SHRINK, GTK_SHRINK, 6, 0); /* FIXME: magic */
431 gtk_widget_set_name (colon_label, "osso-LargeFont" );
435 priv->start_key_repeat = FALSE;
437 priv->button_press = FALSE;
439 gtk_table_set_row_spacing (table, 0, 6);
440 gtk_table_set_row_spacing (table, 1, 6);
444 gint table_column = widget_group_table_column_pos[WIDGET_GROUP_AMPM];
445 GtkWidget *ampmtotop = NULL;
447 /* Show the AM/PM label centered vertically */
448 ampmtotop = gtk_alignment_new (0, 0.5, 0, 0);
449 gtk_table_attach (table, ampmtotop, table_column, table_column + 1,
450 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
451 gtk_container_add (GTK_CONTAINER (ampmtotop),
452 priv->widgets[WIDGET_GROUP_AMPM].frame);
454 if (table_column != 0)
455 gtk_table_set_col_spacing (table, table_column - 1, 9);
457 /* Connect AM/PM signal handlers */
458 g_signal_connect (priv->widgets[WIDGET_GROUP_AMPM].eventbox,
459 "button-release-event",
460 G_CALLBACK(hildon_time_picker_ampm_release), picker);
463 gtk_widget_pop_composite_child ();
465 /* This dialog isn't modal */
466 gtk_window_set_modal (GTK_WINDOW (dialog), FALSE);
467 /* And final dialog packing */
468 gtk_dialog_set_has_separator (dialog, FALSE);
469 gtk_dialog_add_button (dialog, _("ecdg_bd_time_picker_close"),
472 gtk_container_add (GTK_CONTAINER (maintocenter), GTK_WIDGET(table));
473 gtk_box_pack_start (GTK_BOX (dialog->vbox), maintocenter, TRUE, FALSE, 0);
475 /* Set default time to current time */
477 local = localtime (&stamp);
478 hildon_time_picker_set_time (picker, local->tm_hour, local->tm_min);
480 gtk_widget_show_all (maintocenter);
484 hildon_time_picker_set_property (GObject *object,
489 HildonTimePicker *picker = HILDON_TIME_PICKER (object);
495 hildon_time_picker_change_time (picker, g_value_get_uint(value));
499 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
505 hildon_time_picker_finalize (GObject *object)
507 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (object);
511 /* Make sure the timer is stopped */
513 g_source_remove(priv->timer_id);
515 g_free(priv->am_symbol);
516 g_free(priv->pm_symbol);
518 if (G_OBJECT_CLASS(parent_class)->finalize)
519 G_OBJECT_CLASS(parent_class)->finalize(object);
523 hildon_time_picker_get_property (GObject *object,
528 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (object);
534 g_value_set_uint (value, priv->minutes);
538 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
544 hildon_time_picker_realize (GtkWidget *widget)
546 GTK_WIDGET_CLASS (parent_class)->realize(widget);
548 /* We only want the border for the dialog. */
549 gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
553 hildon_time_picker_style_set (GtkWidget *widget,
554 GtkStyle *previous_style)
558 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (widget);
561 GTK_WIDGET_CLASS (parent_class)->style_set(widget, previous_style);
563 /* Update hour/minute up/down buttons sizes from style properties */
564 gtk_widget_style_get (widget,
565 "arrow-width", &width,
566 "arrow-height", &height, NULL);
568 for (i = 0; i < WIDGET_GROUP_COUNT; i++)
570 if (priv->widgets[i].buttons[0] != NULL)
572 for (button = 0; button < BUTTON_COUNT; button++)
574 gtk_widget_set_size_request (priv->widgets[i].buttons[button], width, height);
581 * Clicked hour/minute field. Move focus to it.
584 hildon_time_picker_event_box_button_press (GtkWidget *widget,
588 gtk_widget_grab_focus (widget);
593 * Clicked AM/PM label. Move focus to it and move the time by 12 hours.
596 hildon_time_picker_ampm_release (GtkWidget *widget,
598 HildonTimePicker *picker)
600 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
603 gtk_widget_grab_focus (widget);
604 hildon_time_picker_change_time (picker, priv->minutes > MINS_IN_12H ?
605 priv->minutes - MINS_IN_12H :
606 priv->minutes + MINS_IN_12H);
612 hildon_time_picker_arrow_press (GtkWidget *widget,
614 HildonTimePicker *picker)
616 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
621 /* Make sure we don't add repeat timer twice. Normally it shouldn't
622 happen but WM can cause button release to be lost. */
623 if (priv->button_press )
626 priv->start_key_repeat = priv->button_press = TRUE;
628 /* Find the widget which was clicked */
630 for (i = 0; i < WIDGET_GROUP_COUNT; i++)
632 for (button = 0; button < BUTTON_COUNT; button++)
634 if (priv->widgets[i].buttons[button] == widget)
636 /* Update multiplier and move the focus to the clicked field */
637 priv->mul = button_multipliers[i][button];
638 gtk_widget_grab_focus (priv->widgets[i].eventbox);
643 g_assert (priv->mul != 0);
645 /* Change the time now, wrapping if needed. */
646 newval = priv->minutes + priv->mul;
648 newval += MINS_IN_24H;
650 hildon_time_picker_change_time (picker, newval);
652 /* Get button press repeater timeout from settings (in milliseconds) */
653 g_object_get (gtk_widget_get_settings (widget),
654 "gtk-timeout-repeat", &key_repeat, NULL);
658 /* Keep changing the time as long as button is being pressed.
659 The first repeat takes 3 times longer to start than the rest. */
661 priv->timer_id = g_timeout_add (key_repeat * 3,
662 hildon_time_picker_key_repeat_timeout,
669 hildon_time_picker_arrow_release (GtkWidget *widget,
671 HildonTimePicker *picker)
673 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
678 /* Stop repeat timer */
679 g_source_remove (priv->timer_id);
683 priv->button_press = FALSE;
688 hildon_time_picker_event_box_focus_in (GtkWidget *widget,
692 /* Draw the widget in selected state so focus shows clearly. */
693 gtk_widget_set_state (widget, GTK_STATE_SELECTED);
698 hildon_time_picker_event_box_focus_out (GtkWidget *widget,
702 /* Draw the widget in normal state */
703 gtk_widget_set_state( widget, GTK_STATE_NORMAL );
708 hildon_time_picker_lookup_eventbox_group (HildonTimePicker *picker,
712 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
716 for (i = 0; i < WIDGET_GROUP_COUNT; i++)
718 if (priv->widgets[i].eventbox == widget)
725 hildon_time_picker_event_box_key_press (GtkWidget *widget,
727 HildonTimePicker *picker)
729 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
730 HildonTimePickerWidgetGroup *group;
735 /* If mouse button is already being pressed, ignore this keypress */
739 group_idx = hildon_time_picker_lookup_eventbox_group (picker, widget);
740 group = group_idx < 0 ? NULL : &priv->widgets[group_idx];
742 /* Handle keypresses in hour/minute/AMPM fields */
743 switch (event->keyval)
749 gint button = event->keyval == GDK_Up ? BUTTON_UP : BUTTON_DOWN;
751 if (group->buttons[button] != NULL)
753 /* Fake a button up/down press */
754 hildon_time_picker_arrow_press (group->buttons[button], NULL, picker);
755 gtk_widget_set_state (group->buttons[button], GTK_STATE_SELECTED);
759 /* Fake a AM/PM button release */
760 g_assert (group_idx == WIDGET_GROUP_AMPM);
761 hildon_time_picker_ampm_release (group->eventbox, NULL, picker);
767 /* If we're in leftmost field, stop this keypress signal.
768 Otherwise let the default key handler move focus to field in left. */
769 if (priv->show_ampm && priv->ampm_left)
771 /* AM/PM is the leftmost field */
772 if (group_idx == WIDGET_GROUP_AMPM)
777 /* Hours is the leftmost field */
778 if (group_idx == WIDGET_GROUP_HOURS)
784 /* If we're in rightmost field, stop this keypress signal.
785 Otherwise let the default key handler move focus to field in right. */
786 if (priv->show_ampm && !priv->ampm_left)
788 /* AM/PM is the rightmost field */
789 if (group_idx == WIDGET_GROUP_AMPM)
794 /* 1-minutes is the leftmost field */
795 if (group_idx == WIDGET_GROUP_1_MINUTES)
801 gtk_dialog_response (GTK_DIALOG (picker), GTK_RESPONSE_CANCEL);
805 gtk_dialog_response (GTK_DIALOG (picker), GTK_RESPONSE_OK);
813 hildon_time_picker_event_box_key_release (GtkWidget *widget,
815 HildonTimePicker *picker)
817 HildonTimePickerWidgetGroup *group;
819 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
823 /* Fake a button release if in key-press handler we faked a button press. */
824 switch( event->keyval )
828 group_idx = hildon_time_picker_lookup_eventbox_group (picker, widget);
831 gint button = event->keyval == GDK_Up ? BUTTON_UP : BUTTON_DOWN;
833 group = &priv->widgets[group_idx];
834 if (group->buttons[button] != NULL)
836 /* Fake a button up/down press */
837 gtk_widget_set_state (group->buttons[button], GTK_STATE_NORMAL);
838 hildon_time_picker_arrow_release (group->buttons[button], NULL, picker);
846 /* Button up/down is being pressed. Update the time. */
848 hildon_time_picker_key_repeat_timeout (gpointer tpicker)
850 HildonTimePicker *picker;
851 HildonTimePickerPrivate *priv = NULL;
855 picker = HILDON_TIME_PICKER(tpicker);
856 g_assert(picker != NULL);
858 priv = HILDON_TIME_PICKER_GET_PRIVATE (tpicker);
861 GDK_THREADS_ENTER ();
863 /* Change the time, wrapping if needed */
864 newval = priv->minutes + priv->mul;
866 newval += MINS_IN_24H;
868 hildon_time_picker_change_time (picker, newval);
870 if (priv->start_key_repeat)
872 /* Get button press repeater timeout from settings (in milliseconds) */
873 g_object_get (gtk_widget_get_settings ((GtkWidget *) tpicker),
874 "gtk-timeout-repeat", &key_repeat, NULL);
878 /* This is the first repeat. Shorten the timeout to key_repeat
879 (instead of the first time's 3*key_repeat) */
880 priv->timer_id = g_timeout_add (key_repeat,
881 hildon_time_picker_key_repeat_timeout,
883 priv->start_key_repeat = FALSE;
885 GDK_THREADS_LEAVE ();
889 GDK_THREADS_LEAVE ();
894 hildon_time_picker_change_time (HildonTimePicker *picker,
897 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
901 gboolean ampm = TRUE;
905 /* If the minutes isn't in valid range, wrap them. */
906 minutes %= MINS_IN_24H;
908 if (priv->minutes == minutes)
911 /* Minutes changed. Update widgets to show the new time. */
912 priv->minutes = minutes;
916 /* am < 12:00 <= pm */
917 ampm = !((guint)(minutes / MINS_IN_12H));
918 /* 12:00 - 23:59 -> 00:00 - 11:59 */
919 minutes %= MINS_IN_12H;
920 if (minutes < MINS_IN_1H )
921 /* 00:mm is always shown as 12:mm */
922 minutes += MINS_IN_12H;
924 /* Update the AM/PM label */
925 gtk_label_set_text (priv->widgets[WIDGET_GROUP_AMPM].label,
926 ampm ? priv->am_symbol : priv->pm_symbol);
929 /* Update hour and minute fields */
930 hours = minutes / MINS_IN_1H;
931 minutes %= MINS_IN_1H;
933 snprintf(str, sizeof (str), "%02d", hours);
934 gtk_label_set_text (priv->widgets[WIDGET_GROUP_HOURS].label, str);
936 snprintf(str, sizeof (str), "%d", minutes / 10);
937 gtk_label_set_text (priv->widgets[WIDGET_GROUP_10_MINUTES].label, str);
939 snprintf(str, sizeof (str), "%d", minutes % 10);
940 gtk_label_set_text(priv->widgets[WIDGET_GROUP_1_MINUTES].label, str);
942 g_object_notify (G_OBJECT(picker), "minutes");
946 * hildon_time_picker_new:
947 * @parent: parent window
949 * #HildonTimePicker shows time picker dialog. The close button is placed
950 * in the dialog's action area and time picker is placed in dialogs vbox.
951 * The actual time picker consists of two #GtkLabel fields - one for hours
952 * and one for minutes - and an AM/PM button. A colon (:) is placed
953 * between hour and minute fields.
955 * Returns: pointer to a new #HildonTimePicker widget.
958 hildon_time_picker_new (GtkWindow *parent)
960 GtkWidget *widget = g_object_new (HILDON_TYPE_TIME_PICKER,
961 "minutes", 360, NULL );
964 gtk_window_set_transient_for (GTK_WINDOW(widget), parent);
966 return GTK_WIDGET (widget);
970 * hildon_time_picker_set_time:
971 * @picker: the #HildonTimePicker widget
975 * Sets the time of the #HildonTimePicker widget.
978 hildon_time_picker_set_time (HildonTimePicker *picker,
982 g_return_if_fail (HILDON_IS_TIME_PICKER(picker));
983 hildon_time_picker_change_time (picker, hours * MINS_IN_1H + minutes);
987 * hildon_time_picker_get_time:
988 * @picker: the #HildonTimePicker widget
992 * Gets the time of the #HildonTimePicker widget.
995 hildon_time_picker_get_time (HildonTimePicker *picker,
1000 g_return_if_fail (HILDON_IS_TIME_PICKER (picker));
1002 HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker);
1005 current = priv->minutes;
1006 *hours = current / MINS_IN_1H;
1007 *minutes = current % MINS_IN_1H;