X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon-time-editor.c;h=25f459091e96ecd4cced11ce283b70dcdb81e03b;hb=7d3f0468795e7298a98578fbb054b5cb9908d523;hp=d22fbbe8dbc9c2a89a6590a323d559bd46cc0707;hpb=8660201cd21e0b1afea66a78ea6b0d8401d3f5fd;p=hildon diff --git a/src/hildon-time-editor.c b/src/hildon-time-editor.c index d22fbbe..25f4590 100644 --- a/src/hildon-time-editor.c +++ b/src/hildon-time-editor.c @@ -3,12 +3,12 @@ * * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. * - * Contact: Michael Dominic Kostrzewa + * Contact: Rodrigo Novo * * 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,7 +25,7 @@ /** * SECTION:hildon-time-editor * @short_description: A widget used to enter time or duration in hours, minutes, - * and optional seconds + * and optional seconds. * @see_also: #HildonTimePicker * * HildonTimeEditor is used to edit time or duration. Time mode is @@ -33,34 +33,55 @@ * amount of time up to 99 hours. It consists of entries for hours, * minutes and seconds, and pm/am indicator as well as a button which * popups a #HildonTimePicker dialog. + * + * + * + * #HildonTimeEditor has been deprecated since Hildon 2.2 and should not + * be used in newly written code. Use #HildonTimeSelector instead. + * + * + * + * + * HildonTimePicker example + * + * + * editor = hildon_time_editor_new (); + * hildon_time_editor_set_time (editor, h, m, s); + * + * gtk_box_pack_start (..., editor) + * + * hildon_time_editor_get_time (editor, &h, &m, &s); + * + * + * + * */ +#undef HILDON_DISABLE_DEPRECATED + #ifdef HAVE_CONFIG_H #include #endif -#include "hildon-time-editor.h" -#include -#include -#include -#include -#include -#include #include #include #include #include #include +#include + +#include "hildon-time-editor.h" #include "hildon-defines.h" #include "hildon-time-picker.h" #include "hildon-banner.h" -#include "hildon-input-mode-hint.h" #include "hildon-private.h" #include "hildon-marshalers.h" #include "hildon-enum-types.h" #include "hildon-time-editor-private.h" -#define _(String) dgettext(PACKAGE, String) +#define _(String) dgettext("hildon-libs", String) + +#define c_(String) dgettext("hildon-common-strings", String) #define TICKS(h,m,s) \ ((h) * 3600 + (m) * 60 + (s)) @@ -207,19 +228,26 @@ static void hildon_time_editor_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static gboolean -hildon_time_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data); +static gboolean +hildon_time_editor_focus (GtkWidget *widget, + GtkDirectionType direction); + +static gboolean +hildon_time_editor_entry_keypress (GtkEntry *entry, + GdkEventKey* event, + gpointer user_data); static gboolean hildon_time_editor_check_locale (HildonTimeEditor *editor); +#ifdef MAEMO_GTK static void hildon_time_editor_tap_and_hold_setup (GtkWidget *widget, GtkWidget *menu, GtkCallback func, GtkWidgetTapAndHoldFlags flags); +#endif + static void hildon_time_editor_validate (HildonTimeEditor *editor, gboolean allow_intermediate); @@ -251,6 +279,13 @@ hildon_time_editor_inserted_text (GtkEditable *editable, gint *position, gpointer user_data); +/** + * hildon_time_editor_get_type: + * + * Initializes and returns the type of a hildon time editor. + * + * Returns: GType of #HildonTimeEditor + */ GType G_GNUC_CONST hildon_time_editor_get_type (void) { @@ -335,8 +370,7 @@ hildon_time_editor_class_init (HildonTimeEditorClass *editor_c object_class->set_property = hildon_time_editor_set_property; widget_class->size_request = hildon_time_editor_size_request; widget_class->size_allocate = hildon_time_editor_size_allocate; - widget_class->tap_and_hold_setup = hildon_time_editor_tap_and_hold_setup; - widget_class->focus = hildon_private_composite_focus; + widget_class->focus = hildon_time_editor_focus; container_class->forall = hildon_time_editor_forall; GTK_OBJECT_CLASS (editor_class)->destroy = hildon_time_editor_destroy; @@ -431,6 +465,7 @@ hildon_time_editor_class_init (HildonTimeEditorClass *editor_c G_PARAM_READABLE | G_PARAM_WRITABLE) ); } +#ifdef MAEMO_GTK static void hildon_time_editor_tap_and_hold_setup (GtkWidget *widget, GtkWidget *menu, @@ -451,6 +486,7 @@ hildon_time_editor_tap_and_hold_setup (GtkWidget *widget, gtk_widget_tap_and_hold_setup (priv->iconbutton, menu, func, GTK_TAP_AND_HOLD_NONE); } +#endif static void hildon_time_editor_entry_changed (GtkWidget *widget, @@ -487,7 +523,7 @@ hildon_time_editor_init (HildonTimeEditor *editor) priv->ampm_button = gtk_button_new(); priv->skipper = FALSE; - icon = gtk_image_new_from_icon_name (ICON_NAME, HILDON_ICON_SIZE_WIDG); + icon = gtk_image_new_from_icon_name (ICON_NAME, HILDON_ICON_SIZE_SMALL); hbox = gtk_hbox_new (FALSE, 0); GTK_WIDGET_SET_FLAGS (editor, GTK_NO_WINDOW); @@ -508,8 +544,10 @@ hildon_time_editor_init (HildonTimeEditor *editor) /* No frames for entries, so that they all appear to be inside one long entry */ gtk_entry_set_has_frame (GTK_ENTRY (priv->entries[i]), FALSE); +#ifdef MAEMO_GTK /* Set the entries to accept only numeric characters */ - g_object_set (priv->entries[i], "input-mode", HILDON_INPUT_MODE_HINT_NUMERIC, NULL); + g_object_set (priv->entries[i], "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL); +#endif /* The entry fields all take exactly two characters */ gtk_entry_set_max_length (GTK_ENTRY (priv->entries[i]), 2); @@ -572,6 +610,13 @@ hildon_time_editor_init (HildonTimeEditor *editor) hildon_time_editor_set_to_current_time (editor); gtk_widget_pop_composite_child (); + +#ifdef MAEMO_GTK + g_signal_connect (editor, "tap-and-hold-setup", + G_CALLBACK (hildon_time_editor_tap_and_hold_setup), + NULL); +#endif + } static void @@ -655,7 +700,7 @@ hildon_time_editor_get_property (GObject *object, } } -/* +/** * hildon_time_editor_new: * * This function creates a new time editor. @@ -674,8 +719,11 @@ hildon_time_editor_finalize (GObject *obj_self) HildonTimeEditorPrivate *priv = HILDON_TIME_EDITOR_GET_PRIVATE (obj_self); g_assert (priv); - g_free (priv->am_symbol); - g_free (priv->pm_symbol); + if (priv->am_symbol) + g_free (priv->am_symbol); + + if (priv->pm_symbol) + g_free (priv->pm_symbol); if (priv->highlight_idle) g_source_remove (priv->highlight_idle); @@ -686,7 +734,6 @@ hildon_time_editor_finalize (GObject *obj_self) /** * hildon_time_editor_get_time_separators: - * @editor: the #HildonTimeEditor * @hm_sep_label: the label that will show the hour:minutes separator * @ms_sep_label: the label that will show the minutes:seconds separator * @@ -770,7 +817,7 @@ hildon_time_editor_set_ticks (HildonTimeEditor *editor, guint i, h, m, s; gchar str[3]; - g_assert (HILDON_IS_TIME_EDITOR (editor)); + g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); g_assert (priv); @@ -1695,9 +1742,11 @@ hildon_time_editor_size_allocate (GtkWidget *widget, HildonTimeEditorPrivate *priv = HILDON_TIME_EDITOR_GET_PRIVATE (widget); GtkAllocation alloc; GtkRequisition req, max_req; + gboolean rtl; g_assert (priv); + rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); widget->allocation = *allocation; gtk_widget_get_child_requisition (widget, &max_req); @@ -1707,19 +1756,32 @@ hildon_time_editor_size_allocate (GtkWidget *widget, alloc.y = allocation->y + MAX (allocation->height - max_req.height, 0) / 2; /* allocate frame */ - gtk_widget_get_child_requisition (priv->frame, &req); + if (rtl) + gtk_widget_get_child_requisition (priv->iconbutton, &req); + else + gtk_widget_get_child_requisition (priv->frame, &req); alloc.width = req.width; alloc.height = max_req.height; - gtk_widget_size_allocate (priv->frame, &alloc); + if (rtl) + gtk_widget_size_allocate (priv->iconbutton, &alloc); + else + gtk_widget_size_allocate (priv->frame, &alloc); /* allocate icon */ if (GTK_WIDGET_VISIBLE (priv->iconbutton)) { - gtk_widget_get_child_requisition (priv->iconbutton, &req); + if (rtl) + gtk_widget_get_child_requisition (priv->frame, &req); + else + gtk_widget_get_child_requisition (priv->iconbutton, &req); alloc.x += alloc.width + HILDON_MARGIN_DEFAULT; alloc.width = req.width; - gtk_widget_size_allocate (priv->iconbutton, &alloc); + + if (rtl) + gtk_widget_size_allocate (priv->frame, &alloc); + else + gtk_widget_size_allocate (priv->iconbutton, &alloc); } /* FIXME: ugly way to move labels up. They just don't seem move up @@ -1741,76 +1803,39 @@ hildon_time_editor_size_allocate (GtkWidget *widget, gtk_widget_size_allocate (priv->sec_label, &alloc); } -static gboolean -hildon_time_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data) +static gboolean +hildon_time_editor_focus (GtkWidget *widget, + GtkDirectionType direction) { - HildonTimeEditor *editor; - HildonTimeEditorPrivate *priv; - gint cursor_pos; - gboolean r; + gboolean retval; + GtkDirectionType effective_direction; - g_assert (GTK_IS_ENTRY (widget)); - g_assert (event != NULL); - g_assert (HILDON_IS_TIME_EDITOR (data)); - - editor = HILDON_TIME_EDITOR (data); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - cursor_pos = gtk_editable_get_position (GTK_EDITABLE (widget)); - - /* 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 (editor, time_editor_signals[TIME_ERROR], 0, HILDON_DATE_TIME_ERROR_INVALID_CHAR, &r); - hildon_banner_show_information (widget, NULL, _("ckct_ib_illegal_character")); - return TRUE; - } + g_assert (HILDON_IS_TIME_EDITOR (widget)); - switch (event->keyval) - { - case GDK_Return: - /* Return key popups up time picker dialog. Visually it looks as if - the time picker icon was clicked. Before opening the time picker - the fields are first validated and fixed. */ - - /* hildon_time_editor_validate (editor, FALSE); - hildon_gtk_button_set_depressed (GTK_BUTTON (priv->iconbutton), TRUE); - hildon_time_editor_icon_clicked (widget, data); - hildon_gtk_button_set_depressed (GTK_BUTTON (priv->iconbutton), FALSE); - - FIXME The above code used to be here before the consolidation that removed the - _set_depressed crap. However, I think this code had NO EFFECT anyways, since - there is no expose event after the _set functions. So I'm just cutting it out. - Another story would be to actually fix it... */ - - hildon_time_editor_icon_clicked (widget, data); - return TRUE; - - case GDK_Left: - /* left arrow pressed in the entry. If we are on first position, try to - move to the previous field. */ - if (cursor_pos == 0) { - (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_LEFT); - return TRUE; - } - break; + retval = hildon_private_composite_focus (widget, direction, &effective_direction); - case GDK_Right: - /* right arrow pressed in the entry. If we are on last position, try to - move to the next field. */ - if (cursor_pos >= g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (widget)), -1)) { - (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_RIGHT); - return TRUE; - } - break; + if (retval == TRUE) + return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); + else + return FALSE; +} - default: - break; - }; +static gboolean +hildon_time_editor_entry_keypress (GtkEntry *entry, + GdkEventKey *event, + gpointer data) +{ + switch (event->keyval) + { + case GDK_Return: + case GDK_ISO_Enter: + hildon_time_editor_icon_clicked (GTK_WIDGET (entry), data); + return TRUE; + default: + return FALSE; + } - return FALSE; + g_assert_not_reached (); } static void @@ -1848,7 +1873,7 @@ convert_to_24h (guint *h, /** * hildon_time_editor_set_show_hours: * @editor: The #HildonTimeEditor. - * @enable: Enable or disable showing of hours. + * @show_hours: Enable or disable showing of hours. * * This function shows or hides the hours field. * @@ -1882,7 +1907,7 @@ hildon_time_editor_set_show_hours (HildonTimeEditor *editor, /** * hildon_time_editor_get_show_hours: - * @self: the @HildonTimeEditor widget. + * @editor: the @HildonTimeEditor widget. * * This function returns a boolean indicating the visibility of * hours in the @HildonTimeEditor