diff options
-rw-r--r-- | shell/e-shell-content.c | 1 | ||||
-rw-r--r-- | shell/e-shell-searchbar.c | 32 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 2 | ||||
-rw-r--r-- | widgets/misc/e-hinted-entry.c | 293 | ||||
-rw-r--r-- | widgets/misc/e-hinted-entry.h | 73 |
5 files changed, 18 insertions, 383 deletions
diff --git a/shell/e-shell-content.c b/shell/e-shell-content.c index c7a41510f2..069e0bfa83 100644 --- a/shell/e-shell-content.c +++ b/shell/e-shell-content.c @@ -40,7 +40,6 @@ #include "filter/e-rule-editor.h" #include "widgets/misc/e-action-combo-box.h" #include "widgets/misc/e-alert-bar.h" -#include "widgets/misc/e-hinted-entry.h" #include "e-shell-backend.h" #include "e-shell-searchbar.h" diff --git a/shell/e-shell-searchbar.c b/shell/e-shell-searchbar.c index 13b0b49349..370d6b4f5e 100644 --- a/shell/e-shell-searchbar.c +++ b/shell/e-shell-searchbar.c @@ -36,7 +36,6 @@ #include "e-util/e-util.h" #include "widgets/misc/e-action-combo-box.h" -#include "widgets/misc/e-hinted-entry.h" #include "e-shell-window-actions.h" @@ -979,7 +978,7 @@ e_shell_searchbar_init (EShellSearchbar *searchbar) label = GTK_LABEL (widget); - widget = e_hinted_entry_new (); + widget = gtk_entry_new (); gtk_label_set_mnemonic_widget (label, widget); gtk_box_pack_start (box, widget, TRUE, TRUE, 0); searchbar->priv->search_entry = widget; @@ -1168,26 +1167,26 @@ e_shell_searchbar_set_filter_visible (EShellSearchbar *searchbar, const gchar * e_shell_searchbar_get_search_hint (EShellSearchbar *searchbar) { - EHintedEntry *entry; + GtkEntry *entry; g_return_val_if_fail (E_IS_SHELL_SEARCHBAR (searchbar), NULL); - entry = E_HINTED_ENTRY (searchbar->priv->search_entry); + entry = GTK_ENTRY (searchbar->priv->search_entry); - return e_hinted_entry_get_hint (entry); + return gtk_entry_get_placeholder_text (entry); } void e_shell_searchbar_set_search_hint (EShellSearchbar *searchbar, const gchar *search_hint) { - EHintedEntry *entry; + GtkEntry *entry; g_return_if_fail (E_IS_SHELL_SEARCHBAR (searchbar)); - entry = E_HINTED_ENTRY (searchbar->priv->search_entry); + entry = GTK_ENTRY (searchbar->priv->search_entry); - e_hinted_entry_set_hint (entry, search_hint); + gtk_entry_set_placeholder_text (entry, search_hint); g_object_notify (G_OBJECT (searchbar), "search-hint"); } @@ -1233,26 +1232,31 @@ e_shell_searchbar_set_search_option (EShellSearchbar *searchbar, const gchar * e_shell_searchbar_get_search_text (EShellSearchbar *searchbar) { - EHintedEntry *entry; + GtkEntry *entry; g_return_val_if_fail (E_IS_SHELL_SEARCHBAR (searchbar), NULL); - entry = E_HINTED_ENTRY (searchbar->priv->search_entry); + entry = GTK_ENTRY (searchbar->priv->search_entry); - return e_hinted_entry_get_text (entry); + return gtk_entry_get_text (entry); } void e_shell_searchbar_set_search_text (EShellSearchbar *searchbar, const gchar *search_text) { - EHintedEntry *entry; + GtkEntry *entry; g_return_if_fail (E_IS_SHELL_SEARCHBAR (searchbar)); - entry = E_HINTED_ENTRY (searchbar->priv->search_entry); + entry = GTK_ENTRY (searchbar->priv->search_entry); - e_hinted_entry_set_text (entry, search_text); + /* XXX Really wish gtk_entry_set_text() + * would just learn to accept NULL. */ + if (search_text == NULL) + search_text = ""; + + gtk_entry_set_text (entry, search_text); shell_searchbar_update_search_widgets (searchbar); diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index cd5cada041..79bc14bcbe 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -38,7 +38,6 @@ widgetsinclude_HEADERS = \ e-contact-marker.h \ e-dateedit.h \ e-focus-tracker.h \ - e-hinted-entry.h \ e-image-chooser.h \ e-import-assistant.h \ e-map.h \ @@ -123,7 +122,6 @@ libemiscwidgets_la_SOURCES = \ e-contact-marker.c \ e-dateedit.c \ e-focus-tracker.c \ - e-hinted-entry.c \ e-image-chooser.c \ e-import-assistant.c \ e-map.c \ diff --git a/widgets/misc/e-hinted-entry.c b/widgets/misc/e-hinted-entry.c deleted file mode 100644 index 21a4fff58e..0000000000 --- a/widgets/misc/e-hinted-entry.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-hinted-entry.c - * - * This program 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; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-hinted-entry.h" - -struct _EHintedEntryPrivate { - gchar *hint; - guint hint_shown : 1; -}; - -enum { - PROP_0, - PROP_HINT, - PROP_HINT_SHOWN -}; - -G_DEFINE_TYPE ( - EHintedEntry, - e_hinted_entry, - GTK_TYPE_ENTRY) - -static void -hinted_entry_show_hint (EHintedEntry *entry) -{ - GtkStyle *style; - const GdkColor *color; - const gchar *hint; - - entry->priv->hint_shown = TRUE; - - hint = e_hinted_entry_get_hint (entry); - gtk_entry_set_text (GTK_ENTRY (entry), hint); - - style = gtk_widget_get_style (GTK_WIDGET (entry)); - color = &style->text[GTK_STATE_INSENSITIVE]; - gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, color); - - g_object_notify (G_OBJECT (entry), "hint-shown"); -} - -static void -hinted_entry_show_text (EHintedEntry *entry, - const gchar *text) -{ - entry->priv->hint_shown = FALSE; - - gtk_entry_set_text (GTK_ENTRY (entry), text); - - gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL); - - g_object_notify (G_OBJECT (entry), "hint-shown"); -} - -static void -hinted_entry_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_HINT: - e_hinted_entry_set_hint ( - E_HINTED_ENTRY (object), - g_value_get_string (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -hinted_entry_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_HINT: - g_value_set_string ( - value, e_hinted_entry_get_hint ( - E_HINTED_ENTRY (object))); - return; - - case PROP_HINT_SHOWN: - g_value_set_boolean ( - value, e_hinted_entry_get_hint_shown ( - E_HINTED_ENTRY (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -hinted_entry_finalize (GObject *object) -{ - EHintedEntryPrivate *priv; - - priv = E_HINTED_ENTRY (object)->priv; - - g_free (priv->hint); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_hinted_entry_parent_class)->finalize (object); -} - -static void -hinted_entry_grab_focus (GtkWidget *widget) -{ - GtkWidgetClass *chain_class; - - /* We don't want hints to be selected so we chain to - * the GtkEntry parent if we have a hint set */ - chain_class = e_hinted_entry_parent_class; - if (e_hinted_entry_get_hint_shown (E_HINTED_ENTRY (widget))) - chain_class = g_type_class_peek_parent (chain_class); - - /* Chain up to parent's grab_focus() method. */ - GTK_WIDGET_CLASS (chain_class)->grab_focus (widget); -} - -static gboolean -hinted_entry_focus_in_event (GtkWidget *widget, - GdkEventFocus *event) -{ - EHintedEntry *entry = E_HINTED_ENTRY (widget); - - if (e_hinted_entry_get_hint_shown (entry)) - hinted_entry_show_text (entry, ""); - - /* Chain up to parent's focus_in_event() method. */ - return GTK_WIDGET_CLASS (e_hinted_entry_parent_class)-> - focus_in_event (widget, event); -} - -static gboolean -hinted_entry_focus_out_event (GtkWidget *widget, - GdkEventFocus *event) -{ - EHintedEntry *entry = E_HINTED_ENTRY (widget); - const gchar *text; - - text = e_hinted_entry_get_text (entry); - - if (text == NULL || *text == '\0') - hinted_entry_show_hint (E_HINTED_ENTRY (widget)); - - /* Chain up to parent's focus_out_event() method. */ - return GTK_WIDGET_CLASS (e_hinted_entry_parent_class)-> - focus_out_event (widget, event); -} - -static void -e_hinted_entry_class_init (EHintedEntryClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - g_type_class_add_private (class, sizeof (EHintedEntryPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = hinted_entry_set_property; - object_class->get_property = hinted_entry_get_property; - object_class->finalize = hinted_entry_finalize; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->grab_focus = hinted_entry_grab_focus; - widget_class->focus_in_event = hinted_entry_focus_in_event; - widget_class->focus_out_event = hinted_entry_focus_out_event; - - g_object_class_install_property ( - object_class, - PROP_HINT, - g_param_spec_string ( - "hint", - "Hint", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HINT_SHOWN, - g_param_spec_boolean ( - "hint-shown", - "Hint Shown", - NULL, - FALSE, - G_PARAM_READABLE)); -} - -static void -e_hinted_entry_init (EHintedEntry *entry) -{ - entry->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - entry, E_TYPE_HINTED_ENTRY, EHintedEntryPrivate); - entry->priv->hint = g_strdup (""); /* hint must never be NULL */ - hinted_entry_show_hint (entry); -} - -GtkWidget * -e_hinted_entry_new (void) -{ - return g_object_new (E_TYPE_HINTED_ENTRY, NULL); -} - -const gchar * -e_hinted_entry_get_hint (EHintedEntry *entry) -{ - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), NULL); - - return entry->priv->hint; -} - -void -e_hinted_entry_set_hint (EHintedEntry *entry, - const gchar *hint) -{ - g_return_if_fail (E_IS_HINTED_ENTRY (entry)); - - if (hint == NULL) - hint = ""; - - g_free (entry->priv->hint); - entry->priv->hint = g_strdup (hint); - - if (e_hinted_entry_get_hint_shown (entry)) - gtk_entry_set_text (GTK_ENTRY (entry), hint); - - g_object_notify (G_OBJECT (entry), "hint"); -} - -gboolean -e_hinted_entry_get_hint_shown (EHintedEntry *entry) -{ - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), FALSE); - - return entry->priv->hint_shown; -} - -const gchar * -e_hinted_entry_get_text (EHintedEntry *entry) -{ - const gchar *text = ""; - - /* XXX This clumsily overrides gtk_entry_get_text(). */ - - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), NULL); - - if (!e_hinted_entry_get_hint_shown (entry)) - text = gtk_entry_get_text (GTK_ENTRY (entry)); - - return text; -} - -void -e_hinted_entry_set_text (EHintedEntry *entry, - const gchar *text) -{ - /* XXX This clumsily overrides gtk_entry_set_text(). */ - - g_return_if_fail (E_IS_HINTED_ENTRY (entry)); - - if (text == NULL) - text = ""; - - if (*text == '\0' && !gtk_widget_has_focus (GTK_WIDGET (entry))) - hinted_entry_show_hint (entry); - else - hinted_entry_show_text (entry, text); -} diff --git a/widgets/misc/e-hinted-entry.h b/widgets/misc/e-hinted-entry.h deleted file mode 100644 index 02379d4ad7..0000000000 --- a/widgets/misc/e-hinted-entry.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * e-hinted-entry.h - * - * This program 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; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_HINTED_ENTRY_H -#define E_HINTED_ENTRY_H - -#include <gtk/gtk.h> - -/* Standard GObject macros */ -#define E_TYPE_HINTED_ENTRY \ - (e_hinted_entry_get_type ()) -#define E_HINTED_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_HINTED_ENTRY, EHintedEntry)) -#define E_HINTED_ENTRY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_HINTED_ENTRY, EHintedEntryClass)) -#define E_IS_HINTED_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_HINTED_ENTRY)) -#define E_IS_HINTED_ENTRY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_HINTED_ENTRY)) -#define E_HINTED_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_HINTED_ENTRY, EHintedEntryClass)) - -G_BEGIN_DECLS - -typedef struct _EHintedEntry EHintedEntry; -typedef struct _EHintedEntryClass EHintedEntryClass; -typedef struct _EHintedEntryPrivate EHintedEntryPrivate; - -struct _EHintedEntry { - GtkEntry parent; - EHintedEntryPrivate *priv; -}; - -struct _EHintedEntryClass { - GtkEntryClass parent_class; -}; - -GType e_hinted_entry_get_type (void); -GtkWidget * e_hinted_entry_new (void); -const gchar * e_hinted_entry_get_hint (EHintedEntry *entry); -void e_hinted_entry_set_hint (EHintedEntry *entry, - const gchar *hint); -gboolean e_hinted_entry_get_hint_shown (EHintedEntry *entry); -const gchar * e_hinted_entry_get_text (EHintedEntry *entry); -void e_hinted_entry_set_text (EHintedEntry *entry, - const gchar *text); - -G_END_DECLS - -#endif /* E_HINTED_ENTRY_H */ |