/**
* 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
*/
#include "hildon-entry.h"
-#include "hildon-helper.h"
G_DEFINE_TYPE (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);
+enum {
+ PROP_SIZE = 1
+};
+
#define HILDON_ENTRY_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
HILDON_TYPE_ENTRY, HildonEntryPrivate));
struct _HildonEntryPrivate
{
gchar *placeholder;
- gboolean showing_placeholder;
+ guint showing_placeholder : 1;
+ guint setting_style : 1;
};
static void
+set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ HildonSizeType size;
+
+ switch (prop_id)
+ {
+ case PROP_SIZE:
+ 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);
+ break;
+ }
+}
+
+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
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);
}
/**
GtkWidget *
hildon_entry_new (HildonSizeType size)
{
- GtkWidget *entry = g_object_new (HILDON_TYPE_ENTRY, NULL);
-
- hildon_gtk_widget_set_theme_size (entry, size);
-
- return entry;
+ return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL);
}
static gboolean
GObjectClass *gobject_class = (GObjectClass *)klass;
GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
+ gobject_class->set_property = set_property;
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,
+ PROP_SIZE,
+ g_param_spec_flags (
+ "size",
+ "Size",
+ "Size request for the entry",
+ HILDON_TYPE_SIZE_TYPE,
+ HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+ G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
g_type_class_add_private (klass, sizeof (HildonEntryPrivate));
}
self->priv = HILDON_ENTRY_GET_PRIVATE (self);
self->priv->placeholder = g_strdup ("");
self->priv->showing_placeholder = FALSE;
+ self->priv->setting_style = FALSE;
}