Remove all calls to hildon_helper_set_logical_* from within Hildon
[hildon] / hildon / hildon-entry.c
index 6e065bc..11609a2 100644 (file)
 
 /**
  * SECTION:hildon-entry
- * @short_description: Widget representing a text entry in the Hildon framework.
+ * @short_description: Text entry in the Hildon framework.
  *
- * The #HildonEntry is a GTK widget which represents a text entry. It
- * is derived from the #GtkEntry widget and provides additional
- * commodities specific to the Hildon framework.
+ * The #HildonEntry is text entry derived from the #GtkEntry widget providing
+ * additional commodities specific to the Hildon framework.
  *
  * Besides all the features inherited from #GtkEntry, a #HildonEntry
  * can also have a placeholder text. This text will be shown if the
@@ -51,7 +50,6 @@
  */
 
 #include                                        "hildon-entry.h"
-#include                                        "hildon-helper.h"
 
 G_DEFINE_TYPE                                   (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
 
@@ -66,7 +64,8 @@ enum {
 struct                                          _HildonEntryPrivate
 {
     gchar *placeholder;
-    gboolean showing_placeholder;
+    guint showing_placeholder : 1;
+    guint setting_style : 1;
 };
 
 static void
@@ -75,10 +74,16 @@ set_property                                    (GObject      *object,
                                                  const GValue *value,
                                                  GParamSpec   *pspec)
 {
+    HildonSizeType size;
+
     switch (prop_id)
     {
     case PROP_SIZE:
-        hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), g_value_get_flags (value));
+       size = g_value_get_flags (value);
+       /* If this is auto height, default to finger height. */
+       if (!(size & (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_THUMB_HEIGHT)))
+         size |= HILDON_SIZE_FINGER_HEIGHT;
+       hildon_gtk_widget_set_theme_size (GTK_WIDGET (object), size);
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -87,14 +92,49 @@ set_property                                    (GObject      *object,
 }
 
 static void
+set_logical_color                               (HildonEntry *entry)
+{
+    GdkColor color;
+    const gchar *colorname;
+    GtkWidget *widget = GTK_WIDGET (entry);
+    HildonEntryPrivate *priv = entry->priv;
+
+    colorname = priv->showing_placeholder ? "ReversedSecondaryTextColor" : "ReversedTextColor";
+
+    gtk_widget_ensure_style (widget);
+    if (gtk_style_lookup_color (widget->style, colorname, &color) == TRUE) {
+        priv->setting_style = TRUE;
+        gtk_widget_modify_text (widget, GTK_STATE_NORMAL, &color);
+        priv->setting_style = FALSE;
+    }
+}
+
+static void
+hildon_entry_style_set                          (GtkWidget *widget,
+                                                 GtkStyle  *previous_style)
+{
+    HildonEntry *entry = HILDON_ENTRY (widget);
+
+    if (GTK_WIDGET_CLASS (hildon_entry_parent_class)->style_set)
+        GTK_WIDGET_CLASS (hildon_entry_parent_class)->style_set (widget, previous_style);
+
+    /* Prevent infinite recursion when calling set_logical_font() and
+     * set_logical_color() */
+    if (entry->priv->setting_style)
+        return;
+
+    set_logical_color (entry);
+}
+
+static void
 hildon_entry_show_placeholder (HildonEntry *entry)
 {
     HildonEntryPrivate *priv = HILDON_ENTRY (entry)->priv;
 
     priv->showing_placeholder = TRUE;
     gtk_entry_set_text (GTK_ENTRY (entry), priv->placeholder);
-    hildon_helper_set_logical_color (GTK_WIDGET (entry),
-                                    GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedSecondaryTextColor");
+
+    set_logical_color (entry);
 }
 
 static void
@@ -104,8 +144,8 @@ hildon_entry_hide_placeholder (HildonEntry *entry, const gchar *text)
 
     priv->showing_placeholder = FALSE;
     gtk_entry_set_text (GTK_ENTRY (entry), text);
-    hildon_helper_set_logical_color (GTK_WIDGET (entry),
-                                    GTK_RC_TEXT, GTK_STATE_NORMAL, "ReversedTextColor");
+
+    set_logical_color (entry);
 }
 
 /**
@@ -255,6 +295,7 @@ hildon_entry_class_init                         (HildonEntryClass *klass)
     gobject_class->finalize = hildon_entry_finalize;
     widget_class->focus_in_event = hildon_entry_focus_in_event;
     widget_class->focus_out_event = hildon_entry_focus_out_event;
+    widget_class->style_set = hildon_entry_style_set;
 
     g_object_class_install_property (
         gobject_class,
@@ -264,8 +305,8 @@ hildon_entry_class_init                         (HildonEntryClass *klass)
             "Size",
             "Size request for the entry",
             HILDON_TYPE_SIZE_TYPE,
-            HILDON_SIZE_AUTO,
-            G_PARAM_WRITABLE));
+            HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+            G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
 
     g_type_class_add_private (klass, sizeof (HildonEntryPrivate));
 }
@@ -276,4 +317,5 @@ hildon_entry_init                               (HildonEntry *self)
     self->priv = HILDON_ENTRY_GET_PRIVATE (self);
     self->priv->placeholder = g_strdup ("");
     self->priv->showing_placeholder = FALSE;
+    self->priv->setting_style = FALSE;
 }