From: Alberto Garcia Date: Tue, 4 Aug 2009 16:25:55 +0000 (+0200) Subject: Remove all placeholder code in HildonEntry/TextView now that it's in GTK X-Git-Tag: 2.1.93-1~1 X-Git-Url: http://vcs.maemo.org/git/?p=hildon;a=commitdiff_plain;h=612b3ad6022252538dcdafe78f63a36a7d1b9335 Remove all placeholder code in HildonEntry/TextView now that it's in GTK * hildon/hildon-text-view.c * hildon/hildon-entry.c: Remove all placeholder code from HildonEntry and HildonTextView and use the API in GtkEntry and GtkTextView instead. * examples/hildon-entry-example.c * examples/hildon-text-view-example.c * examples/hildon-wizard-dialog-example.c * hildon/hildon-get-password-dialog.c * hildon/hildon-login-dialog.c * hildon/hildon-picker-dialog.c * hildon/hildon-set-password-dialog.c * hildon/hildon-touch-selector-entry.c: Replace all deprecated calls to HildonEntry and HildonTextView with their Gtk counterparts. Fixes: NB#122395 (hildon_entry_set_placeholder() should be in GtkEntry) --- diff --git a/ChangeLog b/ChangeLog index ea0fcbd..0cb8d72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2009-08-04 Alberto Garcia + + * hildon/hildon-text-view.c + * hildon/hildon-entry.c: + Remove all placeholder code from HildonEntry and HildonTextView + and use the API in GtkEntry and GtkTextView instead. + + * examples/hildon-entry-example.c + * examples/hildon-text-view-example.c + * examples/hildon-wizard-dialog-example.c + * hildon/hildon-get-password-dialog.c + * hildon/hildon-login-dialog.c + * hildon/hildon-picker-dialog.c + * hildon/hildon-set-password-dialog.c + * hildon/hildon-touch-selector-entry.c: + Replace all deprecated calls to HildonEntry and HildonTextView + with their Gtk counterparts. + + Fixes: NB#122395 (hildon_entry_set_placeholder() should be in + GtkEntry) + 2009-08-03 Alejandro G. Castro * hildon/hildon-pannable-area.c, diff --git a/examples/hildon-entry-example.c b/examples/hildon-entry-example.c index cdb718d..9bb6ea2 100644 --- a/examples/hildon-entry-example.c +++ b/examples/hildon-entry-example.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon examples * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -23,29 +23,28 @@ #include #include -HildonEntry *mainentry; +GtkEntry *mainentry; static void -set_text_button_clicked (GtkButton *button, - HildonEntry *entry) +set_text_button_clicked (GtkButton *button, + GtkEntry *entry) { - hildon_entry_set_text (mainentry, hildon_entry_get_text (entry)); + gtk_entry_set_text (mainentry, gtk_entry_get_text (entry)); } static void -set_placeholder_button_clicked (GtkButton *button, - HildonEntry *entry) +set_placeholder_button_clicked (GtkButton *button, + GtkEntry *entry) { - hildon_entry_set_placeholder (mainentry, hildon_entry_get_text (entry)); + hildon_gtk_entry_set_placeholder_text (mainentry, gtk_entry_get_text (entry)); } static void -text_changed (HildonEntry *entry, - GParamSpec *arg1, - GtkLabel *label) +text_changed (GtkEntry *entry, + GParamSpec *arg1, + GtkLabel *label) { - /* Do *NOT* use gtk_entry_get_text () */ - const gchar *text = hildon_entry_get_text (entry); + const gchar *text = gtk_entry_get_text (entry); if (text != NULL && *text != '\0') { gtk_label_set_text (label, text); @@ -83,8 +82,8 @@ main (int argc, placeholderhbox = gtk_hbox_new (FALSE, 10); /* Main HildonEntry - this is the one showcased in this example */ - mainentry = HILDON_ENTRY (hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); - hildon_entry_set_placeholder (mainentry, "This is a placeholder - change using the buttons above"); + mainentry = GTK_ENTRY (hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); + hildon_gtk_entry_set_placeholder_text (mainentry, "This is a placeholder - change using the buttons above"); /* This label is used to show the contents -not the placeholder- of the HildonEntry */ label = gtk_label_new (NULL); diff --git a/examples/hildon-text-view-example.c b/examples/hildon-text-view-example.c index d3d4843..4e2a16b 100644 --- a/examples/hildon-text-view-example.c +++ b/examples/hildon-text-view-example.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon examples * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -22,21 +22,21 @@ #include -HildonTextView *textview; +GtkTextView *textview; GtkTextBuffer *buffer; static void -set_text_button_clicked (GtkButton *button, - HildonEntry *entry) +set_text_button_clicked (GtkButton *button, + GtkEntry *entry) { - gtk_text_buffer_set_text (buffer, hildon_entry_get_text (entry), -1); + gtk_text_buffer_set_text (buffer, gtk_entry_get_text (entry), -1); } static void -set_placeholder_button_clicked (GtkButton *button, - HildonEntry *entry) +set_placeholder_button_clicked (GtkButton *button, + GtkEntry *entry) { - hildon_text_view_set_placeholder (textview, hildon_entry_get_text (entry)); + hildon_gtk_text_view_set_placeholder_text (textview, gtk_entry_get_text (entry)); } static void @@ -88,9 +88,9 @@ main (int argc, placeholderhbox = gtk_hbox_new (FALSE, 10); /* The text view */ - textview = HILDON_TEXT_VIEW (hildon_text_view_new ()); - buffer = hildon_text_view_get_buffer (textview); - hildon_text_view_set_placeholder (textview, "This is a placeholder - change using the buttons above"); + textview = GTK_TEXT_VIEW (hildon_text_view_new ()); + buffer = gtk_text_view_get_buffer (textview); + hildon_gtk_text_view_set_placeholder_text (textview, "This is a placeholder - change using the buttons above"); textviewframe = gtk_frame_new (NULL); /* This label is used to show the contents -not the placeholder- of the HildonTextView */ diff --git a/examples/hildon-wizard-dialog-example.c b/examples/hildon-wizard-dialog-example.c index 5e41985..e542221 100644 --- a/examples/hildon-wizard-dialog-example.c +++ b/examples/hildon-wizard-dialog-example.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon examples * - * Copyright (C) 2005, 2006, 2007 Nokia Corporation, all rights reserved. + * Copyright (C) 2005, 2006, 2007, 2009 Nokia Corporation, all rights reserved. * * Author: Michael Dominic Kostrzewa * @@ -56,13 +56,13 @@ some_page_func (GtkNotebook *nb, gint current, gpointer userdata) { - HildonEntry *entry; + GtkEntry *entry; /* Validate data only for the third page. */ switch (current) { case 2: - entry = HILDON_ENTRY (gtk_notebook_get_nth_page (nb, current)); - return (strlen (hildon_entry_get_text (entry)) != 0); + entry = GTK_ENTRY (gtk_notebook_get_nth_page (nb, current)); + return (strlen (gtk_entry_get_text (entry)) != 0); default: return TRUE; } @@ -77,7 +77,7 @@ main (int argc, char **argv) GtkWidget *label_1 = gtk_label_new ("Page 1"); GtkWidget *label_2 = gtk_label_new ("Page 2"); GtkWidget *entry_3 = hildon_entry_new (HILDON_SIZE_AUTO); - hildon_entry_set_placeholder (HILDON_ENTRY (entry_3), " Write something to continue"); + hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry_3), " Write something to continue"); GtkWidget *label_4 = gtk_label_new ("Page 4"); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_1, NULL); diff --git a/hildon/hildon-entry.c b/hildon/hildon-entry.c index 11609a2..398696f 100644 --- a/hildon/hildon-entry.c +++ b/hildon/hildon-entry.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by @@ -21,16 +21,10 @@ * 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 - * entry is empty and doesn't have the input focus, but it's otherwise - * ignored. Thus, calls to hildon_entry_get_text() will never return - * the placeholder text, not even when it's being displayed. - * - * Although #HildonEntry is derived from #GtkEntry, - * gtk_entry_get_text() and gtk_entry_set_text() must never be used to - * get/set the text in this widget. hildon_entry_get_text() and - * hildon_entry_set_text() must be used instead. + * A #HildonEntry can have a placeholder text. This text will be shown + * if the entry is empty and doesn't have the input focus, but it's + * otherwise ignored. Thus, calls to gtk_entry_get_text() will never + * return the placeholder text, not even when it's being displayed. * * * Creating a HildonEntry with a placeholder @@ -41,7 +35,7 @@ * GtkWidget *entry; * * entry = hildon_entry_new (HILDON_SIZE_AUTO); - * hildon_entry_set_placeholder (HILDON_ENTRY (entry), "First name"); + * hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "First name"); * * return entry; * } @@ -57,17 +51,6 @@ enum { PROP_SIZE = 1 }; -#define HILDON_ENTRY_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_ENTRY, HildonEntryPrivate)); - -struct _HildonEntryPrivate -{ - gchar *placeholder; - guint showing_placeholder : 1; - guint setting_style : 1; -}; - static void set_property (GObject *object, guint prop_id, @@ -91,63 +74,6 @@ 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); - - set_logical_color (entry); -} - -static void -hildon_entry_hide_placeholder (HildonEntry *entry, const gchar *text) -{ - HildonEntryPrivate *priv = HILDON_ENTRY (entry)->priv; - - priv->showing_placeholder = FALSE; - gtk_entry_set_text (GTK_ENTRY (entry), text); - - set_logical_color (entry); -} - /** * hildon_entry_set_text: * @entry: a #HildonEntry @@ -155,22 +81,16 @@ hildon_entry_hide_placeholder (HildonEntry *entry, const gchar *text) * * Sets the text in @entry to @text, replacing its current contents. * - * Note that you must never use gtk_entry_set_text() to set the text - * of a #HildonEntry. - * * Since: 2.2 + * + * Deprecated: Use gtk_entry_set_text() instead */ void hildon_entry_set_text (HildonEntry *entry, const gchar *text) { g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL); - - if (text[0] == '\0' && !GTK_WIDGET_HAS_FOCUS (entry)) { - hildon_entry_show_placeholder (entry); - } else { - hildon_entry_hide_placeholder (entry, text); - } + gtk_entry_set_text (GTK_ENTRY (entry), text); } /** @@ -179,27 +99,22 @@ hildon_entry_set_text (HildonEntry *entry, * * Gets the current text in @entry. * - * Note that you must never use gtk_entry_get_text() to get the text - * from a #HildonEntry. - * - * Also note that placeholder text (set using - * hildon_entry_set_placeholder()) is never returned. Only text set by - * hildon_entry_set_text() or typed by the user is considered. + * Note that the placeholder text (set using + * hildon_gtk_entry_set_placeholder_text()) is never returned. Only + * text set by gtk_entry_set_text() or typed by the user is + * considered. * * Returns: the text in @entry. This text must not be modified or * freed. * * Since: 2.2 + * + * Deprecated: Use gtk_entry_get_text() instead */ const gchar * hildon_entry_get_text (HildonEntry *entry) { g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL); - - if (entry->priv->showing_placeholder) { - return ""; - } - return gtk_entry_get_text (GTK_ENTRY (entry)); } @@ -211,21 +126,15 @@ hildon_entry_get_text (HildonEntry *entry) * Sets the placeholder text in @entry to @text. * * Since: 2.2 + * + * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead */ void hildon_entry_set_placeholder (HildonEntry *entry, const gchar *text) { g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL); - - g_free (entry->priv->placeholder); - entry->priv->placeholder = g_strdup (text); - - /* Show the placeholder if it needs to be updated or if should be shown now. */ - if (entry->priv->showing_placeholder || - (!GTK_WIDGET_HAS_FOCUS (entry) && gtk_entry_get_text (GTK_ENTRY (entry)) [0] == '\0')) { - hildon_entry_show_placeholder (entry); - } + hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text); } /** @@ -244,58 +153,12 @@ hildon_entry_new (HildonSizeType size) return g_object_new (HILDON_TYPE_ENTRY, "size", size, NULL); } -static gboolean -hildon_entry_focus_in_event (GtkWidget *widget, - GdkEventFocus *event) -{ - if (HILDON_ENTRY (widget)->priv->showing_placeholder) { - hildon_entry_hide_placeholder (HILDON_ENTRY (widget), ""); - } - - if (GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_in_event) { - return GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_in_event (widget, event); - } else { - return FALSE; - } -} - -static gboolean -hildon_entry_focus_out_event (GtkWidget *widget, - GdkEventFocus *event) -{ - if (gtk_entry_get_text (GTK_ENTRY (widget)) [0] == '\0') { - hildon_entry_show_placeholder (HILDON_ENTRY (widget)); - } - - if (GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_out_event) { - return GTK_WIDGET_CLASS (hildon_entry_parent_class)->focus_out_event (widget, event); - } else { - return FALSE; - } -} - -static void -hildon_entry_finalize (GObject *object) -{ - HildonEntryPrivate *priv = HILDON_ENTRY (object)->priv; - - g_free (priv->placeholder); - - if (G_OBJECT_CLASS (hildon_entry_parent_class)->finalize) - G_OBJECT_CLASS (hildon_entry_parent_class)->finalize (object); -} - static void hildon_entry_class_init (HildonEntryClass *klass) { 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, @@ -307,15 +170,10 @@ hildon_entry_class_init (HildonEntryClass *klass) 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)); } static void 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; + self->priv = NULL; } diff --git a/hildon/hildon-get-password-dialog.c b/hildon/hildon-get-password-dialog.c index c7d993f..e25c4ab 100644 --- a/hildon/hildon-get-password-dialog.c +++ b/hildon/hildon-get-password-dialog.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. + * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. * * Contact: Rodrigo Novo * @@ -168,7 +168,7 @@ hildon_get_password_set_property (GObject *object, break; case PROP_PASSWORD: - hildon_entry_set_text(HILDON_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry))), + gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry))), g_value_get_string(value)); break; @@ -228,7 +228,7 @@ hildon_get_password_get_property (GObject *object, break; case PROP_PASSWORD: - string = hildon_entry_get_text (HILDON_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry)))); + string = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry)))); g_value_set_string (value, string); break; diff --git a/hildon/hildon-login-dialog.c b/hildon/hildon-login-dialog.c index 0a76f9d..f0ab92e 100644 --- a/hildon/hildon-login-dialog.c +++ b/hildon/hildon-login-dialog.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. + * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. * * Contact: Rodrigo Novo * @@ -145,12 +145,12 @@ hildon_login_dialog_set_property (GObject *object, case PROP_USERNAME: /* Set the current username displayed in the dialog */ - hildon_entry_set_text (HILDON_ENTRY (priv->username_entry), g_value_get_string (value)); + gtk_entry_set_text (GTK_ENTRY (priv->username_entry), g_value_get_string (value)); break; case PROP_PASSWORD: /* Set the currently entered password */ - hildon_entry_set_text (HILDON_ENTRY (priv->password_entry), g_value_get_string (value)); + gtk_entry_set_text (GTK_ENTRY (priv->password_entry), g_value_get_string (value)); break; default: @@ -381,7 +381,7 @@ hildon_login_dialog_get_username (HildonLoginDialog *dialog) priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); g_assert (priv); - return hildon_entry_get_text (HILDON_ENTRY (priv->username_entry)); + return gtk_entry_get_text (GTK_ENTRY (priv->username_entry)); } /** @@ -402,7 +402,7 @@ hildon_login_dialog_get_password (HildonLoginDialog *dialog) priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); g_assert (priv); - return hildon_entry_get_text (HILDON_ENTRY (priv->password_entry)); + return gtk_entry_get_text (GTK_ENTRY (priv->password_entry)); } /** diff --git a/hildon/hildon-picker-dialog.c b/hildon/hildon-picker-dialog.c index 0647e7d..0947877 100644 --- a/hildon/hildon-picker-dialog.c +++ b/hildon/hildon-picker-dialog.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2005, 2008 Nokia Corporation. + * Copyright (C) 2005, 2008, 2009 Nokia Corporation. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -550,7 +550,7 @@ _save_current_selection (HildonPickerDialog *dialog) } if (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector)) { HildonEntry *entry = hildon_touch_selector_entry_get_entry (HILDON_TOUCH_SELECTOR_ENTRY (selector)); - dialog->priv->current_text = g_strdup (hildon_entry_get_text (entry)); + dialog->priv->current_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); } } @@ -596,7 +596,7 @@ _restore_current_selection (HildonPickerDialog *dialog) } if (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector) && dialog->priv->current_text != NULL) { HildonEntry *entry = hildon_touch_selector_entry_get_entry (HILDON_TOUCH_SELECTOR_ENTRY (selector)); - hildon_entry_set_text (entry, dialog->priv->current_text); + gtk_entry_set_text (GTK_ENTRY (entry), dialog->priv->current_text); } if (dialog->priv->signal_changed_id) g_signal_handler_unblock (selector, dialog->priv->signal_changed_id); diff --git a/hildon/hildon-set-password-dialog.c b/hildon/hildon-set-password-dialog.c index baf4bcf..e4c0ca3 100644 --- a/hildon/hildon-set-password-dialog.c +++ b/hildon/hildon-set-password-dialog.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. + * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. * * Contact: Rodrigo Novo * @@ -165,7 +165,7 @@ hildon_set_password_set_property (GObject *object, case PROP_PASSWORD: /* Update password entry to display new value */ - hildon_entry_set_text (HILDON_ENTRY (priv->pwd1st_entry), g_value_get_string (value)); + gtk_entry_set_text (GTK_ENTRY (priv->pwd1st_entry), g_value_get_string (value)); break; case PROP_HILDON_PASSWORD_DIALOG: @@ -204,7 +204,7 @@ hildon_set_password_get_property (GObject *object, case PROP_PASSWORD: g_value_set_string (value, - hildon_entry_get_text (HILDON_ENTRY (priv->pwd1st_entry))); + gtk_entry_get_text (GTK_ENTRY (priv->pwd1st_entry))); break; case PROP_HILDON_PASSWORD_DIALOG: @@ -451,8 +451,8 @@ hildon_set_password_response_change (GtkDialog *dialog, g_signal_stop_emission_by_name (G_OBJECT(dialog), "response"); - hildon_entry_set_text (HILDON_ENTRY (pwd1st_entry), ""); - hildon_entry_set_text (HILDON_ENTRY (pwd2nd_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd1st_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); @@ -470,7 +470,7 @@ hildon_set_password_response_change (GtkDialog *dialog, /* Error: Second field doesn't match the empty first field, so start over */ hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - hildon_entry_set_text (HILDON_ENTRY (pwd2nd_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); } gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry)); @@ -553,8 +553,8 @@ hildon_set_password_response_set (GtkDialog *dialog, } else { /* Error: Passwords don't match, so start over */ g_signal_stop_emission_by_name (G_OBJECT(dialog), "response"); - hildon_entry_set_text (HILDON_ENTRY (pwd1st_entry), ""); - hildon_entry_set_text (HILDON_ENTRY (pwd2nd_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd1st_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); gtk_widget_grab_focus (GTK_WIDGET (priv->pwd1st_entry)); @@ -569,7 +569,7 @@ hildon_set_password_response_set (GtkDialog *dialog, /* Error: Second field doesn't match the empty first field, so start over */ hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - hildon_entry_set_text (HILDON_ENTRY (pwd2nd_entry), ""); + gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); } gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry)); diff --git a/hildon/hildon-text-view.c b/hildon/hildon-text-view.c index c3133a2..933fdcf 100644 --- a/hildon/hildon-text-view.c +++ b/hildon/hildon-text-view.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by @@ -22,18 +22,11 @@ * view derived from the #GtkTextView widget that provides * additional commodities specific to the Hildon framework. * - * Besides all the features inherited from #GtkTextView, a - * #HildonTextView can also have a placeholder text. This text will be - * shown if the text view is empty and doesn't have the input focus, - * but it's otherwise ignored. Thus, calls to - * hildon_text_view_get_buffer() will never return the placeholder - * text, not even when it's being displayed. - * - * Although #HildonTextView is derived from #GtkTextView, - * gtk_text_view_get_buffer() and gtk_text_view_set_buffer() must - * never be used to get/set the buffer in this - * widget. hildon_text_view_get_buffer() and - * hildon_text_view_set_buffer() must be used instead. + * A #HildonTextView can also have a placeholder text. This text will + * be shown if the text view is empty and doesn't have the input + * focus, but it's otherwise ignored. Thus, calls to + * gtk_text_view_get_buffer() will never return the placeholder text, + * not even when it's being displayed. * * * Creating a HildonTextView with a placeholder @@ -44,8 +37,8 @@ * GtkWidget *text_view; * * text_view = hildon_text_view_new (); - * hildon_text_view_set_placeholder (HILDON_TEXT_VIEW (text_view), - * "Type some text here"); + * hildon_gtk_text_view_set_placeholder_text (GTK_TEXT_VIEW (text_view), + * "Type some text here"); * * return text_view; * } @@ -68,69 +61,11 @@ typedef struct _HildonTextViewPrivate HildonTex struct _HildonTextViewPrivate { - GtkTextBuffer *main_buffer; /* Used to show the "real" contents */ - GtkTextBuffer *placeholder_buffer; /* Internal, used to display the placeholder */ - gulong changed_id; /* ID of the main_buffer::changed signal handler */ gdouble x; /* tap x position */ gdouble y; /* tap y position */ - guint showing_placeholder : 1; /* Whether the placeholder is being shown */ - guint setting_style : 1; /* Whether the logical color is being set */ }; -static void -set_logical_color (GtkWidget *widget) -{ - GdkColor color; - const gchar *colorname; - HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (widget); - - 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_text_view_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (widget); - - if (GTK_WIDGET_CLASS (hildon_text_view_parent_class)->style_set) - GTK_WIDGET_CLASS (hildon_text_view_parent_class)->style_set (widget, previous_style); - - /* Prevent infinite recursion when calling set_logical_font() and - * set_logical_color() */ - if (priv->setting_style) - return; - - set_logical_color (widget); -} - -/* Function used to decide whether to show the placeholder or not */ -static void -hildon_text_view_refresh_contents (GtkWidget *text_view) -{ - HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (text_view); - gint bufsize = gtk_text_buffer_get_char_count (priv->main_buffer); - - /* Display the main buffer if it contains text or the widget is focused */ - priv->showing_placeholder = (bufsize <= 0) && !(GTK_WIDGET_HAS_FOCUS (text_view)); - - set_logical_color (text_view); - - if (priv->showing_placeholder) { - gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), priv->placeholder_buffer); - } else { - gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), priv->main_buffer); - } -} - /** * hildon_text_view_set_buffer: * @text_view: a #HildonTextView @@ -142,40 +77,17 @@ hildon_text_view_refresh_contents (GtkWidget *text_view) * before passing it to this function, you must remove that reference * yourself * - * Note that you must never use gtk_text_view_set_buffer() to set the - * buffer of a #HildonTextView. - * * Since: 2.2 + * + * Deprecated: use gtk_text_view_set_buffer() instead */ void hildon_text_view_set_buffer (HildonTextView *text_view, GtkTextBuffer *buffer) { - HildonTextViewPrivate *priv; - g_return_if_fail (HILDON_IS_TEXT_VIEW (text_view)); g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); - - priv = HILDON_TEXT_VIEW_GET_PRIVATE (text_view); - - /* If this is the same buffer, don't do anything */ - if (buffer == priv->main_buffer) - return; - - /* Disconnect the signal handler from the old buffer */ - g_signal_handler_disconnect (priv->main_buffer, priv->changed_id); - - /* Replace the old buffer with the new one */ - g_object_unref (priv->main_buffer); - priv->main_buffer = g_object_ref (buffer); - - /* Attach a callback to the new text buffer */ - priv->changed_id = - g_signal_connect_swapped (priv->main_buffer, "changed", - G_CALLBACK (hildon_text_view_refresh_contents), text_view); - - /* Refresh textview contents */ - hildon_text_view_refresh_contents (GTK_WIDGET (text_view)); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), buffer); } /** @@ -185,29 +97,21 @@ hildon_text_view_set_buffer (HildonTextView *text_view, * Returns the text buffer in @text_view. The reference count is not * incremented; the caller of this function won't own a new reference. * - * Note that you must never use gtk_text_view_get_buffer() to get the - * buffer from a #HildonTextView. - * - * Also note that placeholder text (set using - * hildon_text_view_set_placeholder()) is never contained in this - * buffer. + * Note that the placeholder text (set using + * hildon_gtk_text_view_set_placeholder_text()) is never contained in + * this buffer. * * Returns: a #GtkTextBuffer * * Since: 2.2 + * + * Deprecated: use gtk_text_view_get_buffer() instead */ GtkTextBuffer * hildon_text_view_get_buffer (HildonTextView *text_view) { - HildonTextViewPrivate *priv; - g_return_val_if_fail (HILDON_IS_TEXT_VIEW (text_view), NULL); - - priv = HILDON_TEXT_VIEW_GET_PRIVATE (text_view); - - /* Always return priv->main_buffer even if the placeholder is - * being displayed */ - return priv->main_buffer; + return gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); } /** @@ -218,18 +122,15 @@ hildon_text_view_get_buffer (HildonTextView *text_view) * Sets the placeholder text in @text_view to @text. * * Since: 2.2 + * + * Deprecated: use hildon_gtk_text_view_set_placeholder_text() instead */ void hildon_text_view_set_placeholder (HildonTextView *text_view, const gchar *text) { - HildonTextViewPrivate *priv; - g_return_if_fail (HILDON_IS_TEXT_VIEW (text_view) && text != NULL); - - priv = HILDON_TEXT_VIEW_GET_PRIVATE (text_view); - - gtk_text_buffer_set_text (priv->placeholder_buffer, text, -1); + hildon_gtk_text_view_set_placeholder_text (GTK_TEXT_VIEW (text_view), text); } /** @@ -249,32 +150,6 @@ hildon_text_view_new (void) return entry; } -static gboolean -hildon_text_view_focus_in_event (GtkWidget *widget, - GdkEventFocus *event) -{ - hildon_text_view_refresh_contents (widget); - - if (GTK_WIDGET_CLASS (hildon_text_view_parent_class)->focus_in_event) { - return GTK_WIDGET_CLASS (hildon_text_view_parent_class)->focus_in_event (widget, event); - } else { - return FALSE; - } -} - -static gboolean -hildon_text_view_focus_out_event (GtkWidget *widget, - GdkEventFocus *event) -{ - hildon_text_view_refresh_contents (widget); - - if (GTK_WIDGET_CLASS (hildon_text_view_parent_class)->focus_out_event) { - return GTK_WIDGET_CLASS (hildon_text_view_parent_class)->focus_out_event (widget, event); - } else { - return FALSE; - } -} - static gint hildon_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event) @@ -318,6 +193,7 @@ hildon_text_view_button_release_event (GtkWidget *widget, if (fabs (priv->x - event->x) < HILDON_TEXT_VIEW_DRAG_THRESHOLD && fabs (priv->y - event->y) < HILDON_TEXT_VIEW_DRAG_THRESHOLD) { GtkTextWindowType window_type; + GtkTextBuffer *buffer; window_type = gtk_text_view_get_window_type (text_view, event->window); gtk_text_view_window_to_buffer_coords (text_view, @@ -325,8 +201,9 @@ hildon_text_view_button_release_event (GtkWidget *widget, event->x, event->y, &x, &y); gtk_text_view_get_iter_at_location (text_view, &iter, x, y); - if (gtk_text_buffer_get_char_count (priv->main_buffer)) - gtk_text_buffer_place_cursor (priv->main_buffer, &iter); + buffer = gtk_text_view_get_buffer (text_view); + if (gtk_text_buffer_get_char_count (buffer)) + gtk_text_buffer_place_cursor (buffer, &iter); gtk_widget_grab_focus (GTK_WIDGET (text_view)); @@ -337,48 +214,17 @@ hildon_text_view_button_release_event (GtkWidget *widget, } static void -hildon_text_view_finalize (GObject *object) -{ - HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (object); - - g_signal_handler_disconnect (priv->main_buffer, priv->changed_id); - g_object_unref (priv->main_buffer); - g_object_unref (priv->placeholder_buffer); - - if (G_OBJECT_CLASS (hildon_text_view_parent_class)->finalize) - G_OBJECT_CLASS (hildon_text_view_parent_class)->finalize (object); -} - -static void hildon_text_view_class_init (HildonTextViewClass *klass) { - GObjectClass *gobject_class = (GObjectClass *)klass; GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; - gobject_class->finalize = hildon_text_view_finalize; - widget_class->focus_in_event = hildon_text_view_focus_in_event; - widget_class->focus_out_event = hildon_text_view_focus_out_event; widget_class->motion_notify_event = NULL; widget_class->button_press_event = hildon_text_view_button_press_event; widget_class->button_release_event = hildon_text_view_button_release_event; - widget_class->style_set = hildon_text_view_style_set; g_type_class_add_private (klass, sizeof (HildonTextViewPrivate)); } - static void hildon_text_view_init (HildonTextView *self) { - HildonTextViewPrivate *priv = HILDON_TEXT_VIEW_GET_PRIVATE (self); - - priv->main_buffer = gtk_text_buffer_new (NULL); - priv->placeholder_buffer = gtk_text_buffer_new (NULL); - priv->showing_placeholder = FALSE; - priv->setting_style = FALSE; - - hildon_text_view_refresh_contents (GTK_WIDGET (self)); - - priv->changed_id = - g_signal_connect_swapped (priv->main_buffer, "changed", - G_CALLBACK (hildon_text_view_refresh_contents), self); } diff --git a/hildon/hildon-touch-selector-entry.c b/hildon/hildon-touch-selector-entry.c index 2ff7c76..87663b7 100644 --- a/hildon/hildon-touch-selector-entry.c +++ b/hildon/hildon-touch-selector-entry.c @@ -1,7 +1,7 @@ /* * This file is a part of hildon * - * Copyright (C) 2008 Nokia Corporation. + * Copyright (C) 2008, 2009 Nokia Corporation. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -153,8 +153,8 @@ hildon_touch_selector_entry_print_func (HildonTouchSelector * selector, gpointer priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector); - if (*(hildon_entry_get_text (HILDON_ENTRY (priv->entry))) != '\0') { - text = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry))); + if (*(gtk_entry_get_text (GTK_ENTRY (priv->entry))) != '\0') { + text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))); } else { model = hildon_touch_selector_get_model (selector, 0); if (hildon_touch_selector_get_selected (selector, 0, &iter)) { @@ -385,20 +385,20 @@ entry_on_text_changed (GtkEditable * editable, HildonTouchSelectorEntryPrivate *priv; GtkTreeModel *model; GtkTreeIter iter; - HildonEntry *entry; + GtkEntry *entry; const gchar *prefix; gchar *text; gboolean found = FALSE; gint text_column = -1; - entry = HILDON_ENTRY (editable); + entry = GTK_ENTRY (editable); selector = HILDON_TOUCH_SELECTOR (userdata); priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector); text_column = hildon_touch_selector_entry_get_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector)); - prefix = hildon_entry_get_text (entry); + prefix = gtk_entry_get_text (entry); if (prefix[0] == '\0') { return; @@ -476,7 +476,7 @@ hildon_touch_selector_entry_changed (HildonTouchSelector * selector, text = hildon_touch_selector_get_text_from_model (HILDON_TOUCH_SELECTOR_ENTRY (selector)); if (text != NULL) { - hildon_entry_set_text (HILDON_ENTRY (priv->entry), text); + gtk_entry_set_text (GTK_ENTRY (priv->entry), text); gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1); g_free (text); }