Automatic focus movement for HildonTimeEditor (IMP-13)
authorLuc Pionchon <luc.pionchon@nokia.com>
Thu, 13 Apr 2006 10:11:36 +0000 (10:11 +0000)
committerLuc Pionchon <luc.pionchon@nokia.com>
Thu, 13 Apr 2006 10:11:36 +0000 (10:11 +0000)
* hildon-widgets/hildon-time-editor.c
        (hildon_time_editor_init): connect after signal "insert_text"
        (hildon_time_editor_inserted_text): new function.
        On inserted text, if entry has two digits, jumps to the next field.

ChangeLog
hildon-widgets/hildon-time-editor.c

index 9c64c92..ccad0b7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
 2006-04-13  Luc Pionchon  <luc.pionchon@nokia.com>
 
-       Pops up the color selector on 'selecte' hardkey (IMP-15)
+       Automatic focus movement for HildonTimeEditor (IMP-13)
+
+       * hildon-widgets/hildon-time-editor.c
+       (hildon_time_editor_init): connect after signal "insert_text"
+       (hildon_time_editor_inserted_text): new function.
+       On inserted text, if entry has two digits, jumps to the next field.
+
+
+2006-04-13  Luc Pionchon  <luc.pionchon@nokia.com>
+
+       Pops up the color selector on 'select' hardkey (IMP-15)
        
        * hildon-widgets/hildon-color-button.c
        (hildon_color_button_init): connect "key-release-event"
index 11423d1..882b421 100644 (file)
@@ -234,6 +234,12 @@ static void ticks_to_time (guint  ticks,
                            guint *minutes,
                            guint *seconds);
 
+static void
+hildon_time_editor_inserted_text  (GtkEditable * editable,
+                                   gchar * new_text,
+                                   gint new_text_length,
+                                   gint * position,
+                                   gpointer user_data);
 
 GType hildon_time_editor_get_type(void)
 {
@@ -493,6 +499,11 @@ static void hildon_time_editor_init(HildonTimeEditor * editor)
                        G_CALLBACK(hildon_time_editor_entry_keypress), editor);
       g_signal_connect(priv->entries[i], "changed",
                        G_CALLBACK(hildon_time_editor_entry_changed), editor);
+    
+      /* inserted signal sets time */
+      g_signal_connect_after (G_OBJECT(priv->entries[i]), "insert_text",
+                             G_CALLBACK (hildon_time_editor_inserted_text), 
+                             editor);
     }
     
     /* clicked signal for am/pm label */
@@ -1376,6 +1387,42 @@ hildon_time_editor_validate (HildonTimeEditor *editor, gboolean allow_intermedia
     g_string_free(error_message, TRUE);
 }
 
+/* on inserted text, if entry has two digits, jumps to the next field. */
+static void
+hildon_time_editor_inserted_text  (GtkEditable * editable,
+                                   gchar * new_text,
+                                   gint new_text_length,
+                                   gint * position,
+                                   gpointer user_data) 
+{
+  HildonTimeEditor *editor;
+  GtkEntry *entry;
+  gchar *value;
+  
+  entry = GTK_ENTRY(editable);
+  editor = HILDON_TIME_EDITOR(user_data);
+  
+  value = (gchar *) gtk_entry_get_text(entry);
+  
+  if (strlen(value) == 2)
+    {
+      HildonTimeEditorPrivate *priv;
+      
+      priv = HILDON_TIME_EDITOR_GET_PRIVATE(editor);
+      
+      if (GTK_WIDGET(editable) == priv->entries[ENTRY_HOURS]) 
+       {
+          gtk_widget_grab_focus(priv->entries[ENTRY_MINS]);
+          *position = -1;
+        }
+      else if (GTK_WIDGET(editable) == priv->entries[ENTRY_MINS]) 
+        {
+          gtk_widget_grab_focus(priv->entries[ENTRY_SECS]);
+         *position = -1;
+        }
+    }   
+}
+
 static gboolean hildon_time_editor_entry_focusout(GtkWidget * widget,
                                                   GdkEventFocus * event,
                                                   gpointer data)