X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon-date-editor.c;h=8bd4732bf57bba96e5f4ef3fbb9c7fb6866c1f92;hb=f60ca25dba6c9f1cd98e80c4b0747a22907d8bf4;hp=e1ed643d7caee1d7b06b0912bc38e97a7a0ac339;hpb=798cd026f278276dcc0b02a6e271aaf85e1762a3;p=hildon diff --git a/src/hildon-date-editor.c b/src/hildon-date-editor.c index e1ed643..8bd4732 100644 --- a/src/hildon-date-editor.c +++ b/src/hildon-date-editor.c @@ -1,5 +1,6 @@ -/* - * This file is part of hildon-libs +/* vim:set sw=4 expandtab cino=(0: + * + * This file is a part of hildon * * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. * @@ -8,7 +9,7 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; version 2.1 of - * the License. + * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,38 +26,61 @@ /** * SECTION:hildon-date-editor * @short_description: A widget which queries a date from user or opens - * a HildonCalendarPopup + * a HildonCalendarPopup. * @see_also: #HildonCalendarPopup, #HildonTimeEditor * * HildonDateEditor is a widget with three entry fields (day, month, * year) and an icon (button): clicking on the icon opens up a * HildonCalendarPopup. + * + * + * + * guint y, m, d; + * GtkDialog *dialog; + * GtkWidget *date_editor; + * + * dialog = GTK_DIALOG (gtk_dialog_new ()); + * date_editor = hildon_date_editor_new (); + * + * gtk_box_pack_start (GTK_BOX (dialog->vbox), gtk_label_new ("Choose a date"), FALSE, FALSE, 10); + * gtk_box_pack_start (GTK_BOX (dialog->vbox), date_editor, FALSE, FALSE, 10); + * gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CANCEL); + * + * gtk_widget_show_all (GTK_WIDGET (dialog)); + * gtk_dialog_run (dialog); + * + * hildon_date_editor_get_date (HILDON_DATE_EDITOR (date_editor), &y, &m, &d); + * g_debug ("Date: %u-%u-%u", y, m, d); + * + * + * + * */ #ifdef HAVE_CONFIG_H #include #endif -#include "hildon-date-editor.h" -#include -#include -#include #include #include #include #include +#include +#include + +#include "hildon-date-editor.h" #include "hildon-calendar-popup.h" #include "hildon-defines.h" -#include "hildon-input-mode-hint.h" -#include "hildon-composite-widget.h" #include "hildon-marshalers.h" #include "hildon-enum-types.h" #include "hildon-time-editor.h" #include "hildon-banner.h" -#include #include "hildon-date-editor-private.h" +#include "hildon-private.h" -#define _(string) dgettext(PACKAGE, string) +#define _(string) dgettext("hildon-libs", string) + +#define c_(string) dgettext("hildon-common-strings", string) #define ENTRY_BORDERS 11 @@ -116,7 +140,7 @@ hildon_date_editor_entry_focus_out (GtkWidget *widget, static gboolean hildon_date_editor_date_error (HildonDateEditor *editor, - HildonDateTimeEditorError type); + HildonDateTimeError type); static gboolean hildon_date_editor_entry_focus_in (GtkWidget *widget, @@ -150,7 +174,9 @@ hildon_date_editor_size_allocate (GtkWidget *widget, static void hildon_date_editor_size_request (GtkWidget *widget, GtkRequisition *requisition); - +static gboolean +hildon_date_editor_focus (GtkWidget *widget, + GtkDirectionType direction); static gboolean hildon_date_editor_entry_select_all (GtkWidget *widget); @@ -173,6 +199,13 @@ enum static guint date_editor_signals[LAST_SIGNAL] = { 0 }; +/** + * hildon_date_editor_get_type: + * + * Initializes and returns the type of a hildon date editor. + * + * @Returns: GType of #HildonDateEditor + */ GType G_GNUC_CONST hildon_date_editor_get_type (void) { @@ -213,7 +246,7 @@ hildon_date_editor_class_init (HildonDateEditorClass *editor_c gobject_class->get_property = hildon_date_editor_get_property; widget_class->size_request = hildon_date_editor_size_request; widget_class->size_allocate = hildon_date_editor_size_allocate; - widget_class->focus = hildon_composite_widget_focus; + widget_class->focus = hildon_date_editor_focus; container_class->forall = hildon_child_forall; GTK_OBJECT_CLASS(editor_class)->destroy = hildon_date_editor_destroy; @@ -227,7 +260,7 @@ hildon_date_editor_class_init (HildonDateEditorClass *editor_c G_STRUCT_OFFSET (HildonDateEditorClass, date_error), g_signal_accumulator_true_handled, NULL, _hildon_marshal_BOOLEAN__ENUM, - G_TYPE_BOOLEAN, 1, HILDON_TYPE_DATE_TIME_EDITOR_ERROR); + G_TYPE_BOOLEAN, 1, HILDON_TYPE_DATE_TIME_ERROR); /** * HildonDateEditor:year: @@ -238,8 +271,8 @@ hildon_date_editor_class_init (HildonDateEditorClass *editor_c g_param_spec_uint ("year", "Current year", "Current year", - 1, 2100, - 2005, + 1, 10000, + 2007, G_PARAM_READABLE | G_PARAM_WRITABLE)); /** @@ -277,7 +310,7 @@ hildon_date_editor_class_init (HildonDateEditorClass *editor_c g_param_spec_uint ("min-year", "Minimum valid year", "Minimum valid year", - 1, 2100, + 1, 10000, DEFAULT_MIN_YEAR, G_PARAM_READWRITE)); @@ -290,7 +323,7 @@ hildon_date_editor_class_init (HildonDateEditorClass *editor_c g_param_spec_uint ("max-year", "Maximum valid year", "Maximum valid year", - 1, 2100, + 1, 10000, DEFAULT_MAX_YEAR, G_PARAM_READWRITE)); } @@ -304,7 +337,7 @@ real_set_calendar_icon_state (HildonDateEditorPrivate *priv, g_assert (priv); gtk_image_set_from_icon_name (GTK_IMAGE (priv->calendar_icon), - pressed ? "qgn_widg_datedit_pr" : "qgn_widg_datedit", HILDON_ICON_SIZE_WIDG); + pressed ? "qgn_widg_datedit_pr" : "qgn_widg_datedit", HILDON_ICON_SIZE_SMALL); priv->calendar_icon_pressed = pressed; } @@ -428,12 +461,14 @@ hildon_date_editor_init (HildonDateEditor *editor) priv->m_entry = gtk_entry_new (); priv->y_entry = gtk_entry_new (); - g_object_set (G_OBJECT(priv->d_entry), "input-mode", - HILDON_INPUT_MODE_HINT_NUMERIC, NULL); - g_object_set (G_OBJECT(priv->m_entry), "input-mode", - HILDON_INPUT_MODE_HINT_NUMERIC, NULL); - g_object_set (G_OBJECT(priv->y_entry), "input-mode", - HILDON_INPUT_MODE_HINT_NUMERIC, NULL); +#ifdef MAEMO_GTK + g_object_set (G_OBJECT(priv->d_entry), "hildon-input-mode", + HILDON_GTK_INPUT_MODE_NUMERIC, NULL); + g_object_set (G_OBJECT(priv->m_entry), "hildon-input-mode", + HILDON_GTK_INPUT_MODE_NUMERIC, NULL); + g_object_set (G_OBJECT(priv->y_entry), "hildon-input-mode", + HILDON_GTK_INPUT_MODE_NUMERIC, NULL); +#endif /* set entry look */ gtk_entry_set_width_chars (GTK_ENTRY (priv->d_entry), DAY_ENTRY_WIDTH); @@ -560,7 +595,6 @@ hildon_date_editor_set_property (GObject *object, case PROP_MIN_YEAR: val = g_value_get_uint (value); - g_return_if_fail (val > priv->max_year); priv->min_year = val; /* Clamp current year */ if (hildon_date_editor_get_year (editor) < priv->min_year) @@ -569,7 +603,6 @@ hildon_date_editor_set_property (GObject *object, case PROP_MAX_YEAR: val = g_value_get_uint (value); - g_return_if_fail (val < priv->min_year); priv->max_year = val; /* Clamp current year */ if (hildon_date_editor_get_year (editor) > priv->max_year) @@ -619,7 +652,8 @@ hildon_date_editor_get_property (GObject *object, } } -static void hildon_child_forall (GtkContainer *container, +static void +hildon_child_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) @@ -757,9 +791,10 @@ hildon_date_editor_set_date (HildonDateEditor *editor, * @month: month * @day: day * - * Returns: the year, month, and day currently on the - * date editor. You can pass NULL to any of the pointers if + * Gets the date represented by the date editor. + * You can pass NULL to any of the pointers if * you're not interested in obtaining it. + * */ void hildon_date_editor_get_date (HildonDateEditor *date, @@ -1029,6 +1064,19 @@ hildon_date_editor_entry_validate (GtkWidget *widget, return error_code; } +/* Idle callback */ +static gboolean +hildon_date_editor_entry_select_all (GtkWidget *widget) +{ + GDK_THREADS_ENTER (); + + gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); + + GDK_THREADS_LEAVE (); + + return FALSE; +} + /* When entry becomes full, we move the focus to the next field. If we are on the last field, the whole contents are validated. */ static void @@ -1037,10 +1085,13 @@ hildon_date_editor_entry_changed (GtkEditable *ed, { GtkEntry *entry; gint error_code; + HildonDateEditorPrivate *priv; + priv = HILDON_DATE_EDITOR_GET_PRIVATE (HILDON_DATE_EDITOR (data)); g_assert (GTK_IS_ENTRY (ed)); g_assert (HILDON_IS_DATE_EDITOR (data)); + g_assert (priv); entry = GTK_ENTRY (ed); @@ -1050,11 +1101,11 @@ hildon_date_editor_entry_changed (GtkEditable *ed, error_code = hildon_date_editor_entry_validate (GTK_WIDGET (entry), data); if (error_code == HILDON_DATE_TIME_ERROR_NO_ERROR) { - priv = HILDON_DATE_EDITOR_GET_PRIVATE (HILDON_DATE_EDITOR (data)); - g_assert (priv); priv->skip_validation = TRUE; gtk_widget_child_focus (GTK_WIDGET (data), GTK_DIR_RIGHT); } + } else { + priv->skip_validation = FALSE; } } @@ -1094,46 +1145,21 @@ hildon_date_editor_keypress (GtkWidget *widget, { HildonDateEditor *ed; HildonDateEditorPrivate *priv; - gint pos; - gboolean r; g_assert (HILDON_IS_DATE_EDITOR (data)); g_assert (GTK_IS_ENTRY (widget)); ed = HILDON_DATE_EDITOR (data); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - pos = gtk_editable_get_position (GTK_EDITABLE (widget)); - g_assert (priv); - - /* Show error message in case the key pressed is not allowed - (only digits and control characters are allowed )*/ - if (!g_unichar_isdigit (event->keyval) && ! (event->keyval & 0xF000)) { - g_signal_emit (ed, date_editor_signals[DATE_ERROR], 0, HILDON_DATE_TIME_ERROR_INVALID_CHAR, &r); - return TRUE; - } switch (event->keyval) { - case GDK_Left: - if (pos == 0) { - (void) gtk_widget_child_focus (GTK_WIDGET (data), GTK_DIR_LEFT); - return TRUE; - } - break; - - case GDK_Right: - if (pos >= g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (widget)), -1)) { - (void) gtk_widget_child_focus (GTK_WIDGET (data), GTK_DIR_RIGHT); - return TRUE; - } - break; case GDK_Return: case GDK_ISO_Enter: /* Ignore return value, since we want to handle event at all times. otherwise vkb would popup when the keyrepeat starts. */ - (void) hildon_date_editor_set_calendar_icon_state (ed, TRUE); + hildon_date_editor_set_calendar_icon_state (ed, TRUE); return TRUE; - case GDK_Escape: + priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); priv->skip_validation = TRUE; break; default: @@ -1165,7 +1191,7 @@ hildon_date_editor_entry_focus_out (GtkWidget *widget, static gboolean hildon_date_editor_date_error (HildonDateEditor *editor, - HildonDateTimeEditorError type) + HildonDateTimeError type) { HildonDateEditorPrivate *priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); g_assert (priv); @@ -1207,7 +1233,7 @@ hildon_date_editor_date_error (HildonDateEditor *editor, break; case HILDON_DATE_TIME_ERROR_INVALID_CHAR: - hildon_banner_show_information (GTK_WIDGET (editor), NULL, _("ckct_ib_illegal_character")); + hildon_banner_show_information (GTK_WIDGET (editor), NULL, c_("ckct_ib_illegal_character")); break; case HILDON_DATE_TIME_ERROR_INVALID_DATE: @@ -1261,6 +1287,7 @@ hildon_date_editor_size_allocate (GtkWidget *widget, GtkRequisition req; GtkRequisition max_req; GList *iter; + gboolean rtl; g_assert (GTK_IS_WIDGET (widget)); g_assert (allocation != NULL); @@ -1268,6 +1295,7 @@ hildon_date_editor_size_allocate (GtkWidget *widget, ed = HILDON_DATE_EDITOR (widget); priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); + rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); widget->allocation = *allocation; gtk_widget_get_child_requisition (widget, &max_req); @@ -1280,24 +1308,35 @@ hildon_date_editor_size_allocate (GtkWidget *widget, f_alloc.x = img_alloc.x = allocation->x + MAX (allocation->width - max_req.width, 0) / 2; - /* allocate frame */ - if (GTK_WIDGET_VISIBLE (priv->frame)) { + /* calculate allocations */ + if (GTK_WIDGET_VISIBLE (widget)) { + /* allocate frame */ gtk_widget_get_child_requisition (priv->frame, &req); f_alloc.width = req.width; f_alloc.height = max_req.height; - gtk_widget_size_allocate (priv->frame, &f_alloc); - } - /* allocate icon */ - if (GTK_WIDGET_VISIBLE (priv->d_button_image)) { + /* allocate icon */ gtk_widget_get_child_requisition (priv->d_button_image, &req); img_alloc.x += f_alloc.width + HILDON_MARGIN_DEFAULT; img_alloc.width = req.width; img_alloc.height = max_req.height; - gtk_widget_size_allocate (priv->d_button_image, &img_alloc); + + if (rtl) + { + img_alloc.x = f_alloc.x; + f_alloc.x += img_alloc.width + HILDON_MARGIN_DEFAULT; + } + + if (GTK_WIDGET_VISIBLE (priv->d_button_image)) { + gtk_widget_size_allocate (priv->d_button_image, &img_alloc); + } + + if (GTK_WIDGET_VISIBLE (priv->frame)) { + gtk_widget_size_allocate (priv->frame, &f_alloc); + } } /* FIXME: We really should not alloc delimeters by hand (since they @@ -1318,6 +1357,23 @@ hildon_date_editor_size_allocate (GtkWidget *widget, } } +static gboolean +hildon_date_editor_focus (GtkWidget *widget, + GtkDirectionType direction) +{ + gboolean retval; + GtkDirectionType effective_direction; + + g_assert (HILDON_IS_DATE_EDITOR (widget)); + + retval = hildon_private_composite_focus (widget, direction, &effective_direction); + + if (retval == TRUE) + return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); + else + return FALSE; +} + /** * hildon_date_editor_set_year: * @editor: the @HildonDateEditor widget @@ -1325,7 +1381,7 @@ hildon_date_editor_size_allocate (GtkWidget *widget, * * Sets the year shown in the editor. * - * Returns: TRUE if the year is valid + * Returns: TRUE if the year is valid and has been set. */ gboolean hildon_date_editor_set_year (HildonDateEditor *editor, @@ -1366,7 +1422,7 @@ hildon_date_editor_set_year (HildonDateEditor *editor, * * Sets the month shown in the editor. * - * Returns: TRUE if the month is valid + * Returns: TRUE if the month is valid and has been set. */ gboolean hildon_date_editor_set_month (HildonDateEditor *editor, @@ -1407,7 +1463,7 @@ hildon_date_editor_set_month (HildonDateEditor *editor, * * Sets the day shown in the editor. * - * Returns: TRUE if the day is valid + * Returns: TRUE if the day is valid and has been set. */ gboolean hildon_date_editor_set_day (HildonDateEditor *editor, @@ -1500,15 +1556,3 @@ hildon_date_editor_get_day (HildonDateEditor *editor) return (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->d_entry))); } -/* Idle callback */ -static gboolean -hildon_date_editor_entry_select_all (GtkWidget *widget) -{ - GDK_THREADS_ENTER (); - - gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); - - GDK_THREADS_LEAVE (); - - return FALSE; -}