r2978 - in trunk/src/target/OM-2007.2/libraries/libmokoui2: . libmokoui
thomas at sita.openmoko.org
thomas at sita.openmoko.org
Mon Sep 17 13:21:16 CEST 2007
Author: thomas
Date: 2007-09-17 13:21:14 +0200 (Mon, 17 Sep 2007)
New Revision: 2978
Added:
trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.c
trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.h
Modified:
trunk/src/target/OM-2007.2/libraries/libmokoui2/ChangeLog
trunk/src/target/OM-2007.2/libraries/libmokoui2/configure.ac
trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/Makefile.am
Log:
* configure.ac:
* libmokoui/Makefile.am:
* libmokoui/moko-hint-entry.c:
* libmokoui/moko-hint-entry.h:
Add MokoHintEntry based on KotoHintEntry
Modified: trunk/src/target/OM-2007.2/libraries/libmokoui2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/libraries/libmokoui2/ChangeLog 2007-09-16 22:50:18 UTC (rev 2977)
+++ trunk/src/target/OM-2007.2/libraries/libmokoui2/ChangeLog 2007-09-17 11:21:14 UTC (rev 2978)
@@ -1,3 +1,12 @@
+2007-09-17 Thomas Wood <thomas at openedhand.com>
+
+ * configure.ac:
+ * libmokoui/Makefile.am:
+ * libmokoui/moko-hint-entry.c:
+ * libmokoui/moko-hint-entry.h:
+
+ Add MokoHintEntry based on KotoHintEntry
+
2007-08-31 Chris Lord,,, <chris at openedhand.com>
* libmokoui/moko-finger-scroll.c:
Modified: trunk/src/target/OM-2007.2/libraries/libmokoui2/configure.ac
===================================================================
--- trunk/src/target/OM-2007.2/libraries/libmokoui2/configure.ac 2007-09-16 22:50:18 UTC (rev 2977)
+++ trunk/src/target/OM-2007.2/libraries/libmokoui2/configure.ac 2007-09-17 11:21:14 UTC (rev 2978)
@@ -1,5 +1,5 @@
AC_PREREQ(2.53)
-AC_INIT(libmokoui2, 0.2.0, http://www.openmoko.org/)
+AC_INIT(libmokoui2, 0.3, http://www.openmoko.org/)
AM_INIT_AUTOMAKE()
AC_CONFIG_SRCDIR(libmokoui/moko-stock.c)
AM_CONFIG_HEADER(config.h)
Modified: trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/Makefile.am 2007-09-16 22:50:18 UTC (rev 2977)
+++ trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/Makefile.am 2007-09-17 11:21:14 UTC (rev 2978)
@@ -1,12 +1,14 @@
source_h = \
moko-stock.h \
moko-finger-scroll.h \
- moko-search-bar.h
+ moko-search-bar.h \
+ moko-hint-entry.h
source_c = \
moko-stock.c \
moko-finger-scroll.c \
- moko-search-bar.c
+ moko-search-bar.c \
+ moko-hint-entry.c
DATADIR=$(datadir)
Added: trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.c
===================================================================
--- trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.c 2007-09-16 22:50:18 UTC (rev 2977)
+++ trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.c 2007-09-17 11:21:14 UTC (rev 2978)
@@ -0,0 +1,228 @@
+/*
+ * moko-hint-history.c - taken from koto-hint-history.c
+ * <http://svn.o-hand.com/repos/tasks/trunk/libkoto/koto-hint-entry.c>
+ *
+ * Copyright (C) 2007 OpenedHand Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include "moko-hint-entry.h"
+
+G_DEFINE_TYPE (MokoHintEntry, moko_hint_entry, GTK_TYPE_ENTRY);
+
+#define GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOKO_TYPE_HINT_ENTRY, MokoHintEntryPrivate))
+
+typedef enum {
+ STATE_HINTING,
+ STATE_ENTRY,
+} EntryState;
+
+typedef struct {
+ EntryState state;
+ char *hint;
+} MokoHintEntryPrivate;
+
+/*
+ * Private methods.
+ */
+
+static void
+update (MokoHintEntry *entry)
+{
+ MokoHintEntryPrivate *priv;
+ GtkWidget *widget;
+ const char *text;
+
+ g_assert (MOKO_IS_HINT_ENTRY (entry));
+
+ priv = GET_PRIVATE (entry);
+ widget = GTK_WIDGET (entry);
+
+ text = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ if (GTK_WIDGET_HAS_FOCUS (entry)) {
+ priv->state = STATE_ENTRY;
+ gtk_widget_modify_text (widget, GTK_STATE_NORMAL, NULL);
+ if (strcmp (text, priv->hint) == 0) {
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+ }
+ } else {
+ if (text == NULL || text[0] == '\0') {
+ priv->state = STATE_HINTING;
+ gtk_entry_set_text (GTK_ENTRY (entry), priv->hint);
+ gtk_widget_modify_text (widget, GTK_STATE_NORMAL,
+ >k_widget_get_style (widget)->text[GTK_STATE_INSENSITIVE]);
+ } else {
+ priv->state = STATE_ENTRY;
+ }
+ }
+}
+
+/*
+ * Object methods.
+ */
+
+enum {
+ PROP_0,
+ PROP_HINT,
+};
+
+static gboolean
+focus_in_event (GtkWidget *widget, GdkEventFocus *event)
+{
+ update (MOKO_HINT_ENTRY (widget));
+
+ GTK_WIDGET_CLASS (moko_hint_entry_parent_class)->focus_in_event (widget, event);
+
+ return FALSE;
+}
+
+static gboolean
+focus_out_event (GtkWidget *widget, GdkEventFocus *event)
+{
+ update (MOKO_HINT_ENTRY (widget));
+
+ GTK_WIDGET_CLASS (moko_hint_entry_parent_class)->focus_out_event (widget, event);
+
+ return FALSE;
+}
+
+static void
+moko_hint_entry_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ MokoHintEntryPrivate *priv = GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_HINT:
+ g_value_set_string (value, priv->hint);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+moko_hint_entry_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ MokoHintEntryPrivate *priv = GET_PRIVATE (object);
+
+ switch (property_id) {
+ case PROP_HINT:
+ if (priv->hint) {
+ g_free (priv->hint);
+ }
+ priv->hint = g_value_dup_string (value);
+ update (MOKO_HINT_ENTRY (object));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+moko_hint_entry_finalize (GObject *object)
+{
+ MokoHintEntryPrivate *priv = GET_PRIVATE (object);
+
+ g_free (priv->hint);
+
+ if (G_OBJECT_CLASS (moko_hint_entry_parent_class)->finalize)
+ G_OBJECT_CLASS (moko_hint_entry_parent_class)->finalize (object);
+}
+
+
+static void
+moko_hint_entry_class_init (MokoHintEntryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (MokoHintEntryPrivate));
+
+ object_class->set_property = moko_hint_entry_set_property;
+ object_class->get_property = moko_hint_entry_get_property;
+ object_class->finalize = moko_hint_entry_finalize;
+
+ widget_class->focus_in_event = focus_in_event;
+ widget_class->focus_out_event = focus_out_event;
+
+ g_object_class_install_property (object_class, PROP_HINT, g_param_spec_string
+ ("hint", "hint", NULL, "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+}
+
+static void
+moko_hint_entry_init (MokoHintEntry *self)
+{
+}
+
+
+/*
+ * Public methods.
+ */
+
+/**
+ * moko_hint_entry_new:
+ * @hint: The hint to display when the widget is not focused
+ *
+ * Create a new #MokoHintEntry widget with the specified hint.
+ */
+GtkWidget *
+moko_hint_entry_new (const char *hint)
+{
+ return g_object_new (MOKO_TYPE_HINT_ENTRY,
+ "hint", hint,
+ NULL);
+}
+
+/*
+ * moko_hint_entry_clear:
+ * @entry: a @MokoHintEntry
+ *
+ * Clear the text in the entry and if the widget is not focused, display the
+ * hint text.
+ */
+void
+moko_hint_entry_clear (MokoHintEntry *entry)
+{
+ g_return_if_fail (MOKO_IS_HINT_ENTRY (entry));
+
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+
+ update (entry);
+}
+
+gboolean
+moko_hint_entry_is_empty (MokoHintEntry *entry)
+{
+ MokoHintEntryPrivate *priv;
+
+ g_return_val_if_fail (MOKO_IS_HINT_ENTRY (entry), TRUE);
+
+ priv = GET_PRIVATE (entry);
+
+ if (priv->state == STATE_HINTING)
+ return TRUE;
+
+ return strlen (gtk_entry_get_text (GTK_ENTRY (entry))) == 0;
+}
Added: trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.h
===================================================================
--- trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.h 2007-09-16 22:50:18 UTC (rev 2977)
+++ trunk/src/target/OM-2007.2/libraries/libmokoui2/libmokoui/moko-hint-entry.h 2007-09-17 11:21:14 UTC (rev 2978)
@@ -0,0 +1,70 @@
+/*
+ *
+ * moko-hint-history.c - taken from koto-hint-history.h
+ * <http://svn.o-hand.com/repos/tasks/trunk/libkoto/koto-hint-entry.h>
+ *
+ * Copyright (C) 2007 OpenedHand Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _MOKO_HINT_ENTRY
+#define _MOKO_HINT_ENTRY
+
+#include <gtk/gtkentry.h>
+
+G_BEGIN_DECLS
+
+#define MOKO_TYPE_HINT_ENTRY moko_hint_entry_get_type()
+
+#define MOKO_HINT_ENTRY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ MOKO_TYPE_HINT_ENTRY, MokoHintEntry))
+
+#define MOKO_HINT_ENTRY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MOKO_TYPE_HINT_ENTRY, MokoHintEntryClass))
+
+#define MOKO_IS_HINT_ENTRY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ MOKO_TYPE_HINT_ENTRY))
+
+#define MOKO_IS_HINT_ENTRY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MOKO_TYPE_HINT_ENTRY))
+
+#define MOKO_HINT_ENTRY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MOKO_TYPE_HINT_ENTRY, MokoGroupComboClass))
+
+typedef struct {
+ GtkEntry parent;
+} MokoHintEntry;
+
+typedef struct {
+ GtkEntryClass parent_class;
+} MokoHintEntryClass;
+
+GType moko_hint_entry_get_type (void);
+
+GtkWidget* moko_hint_entry_new (const char *hint);
+
+void moko_hint_entry_clear (MokoHintEntry *entry);
+
+gboolean moko_hint_entry_is_empty (MokoHintEntry *entry);
+
+G_END_DECLS
+
+#endif /* _MOKO_HINT_ENTRY */
More information about the commitlog
mailing list