+2009-08-04 Alberto Garcia <agarcia@igalia.com>
+
+ * 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 <alex@igalia.com>
* hildon/hildon-pannable-area.c,
/*
* 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
#include <gtk/gtk.h>
#include <hildon/hildon.h>
-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);
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);
/*
* 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
#include <hildon/hildon.h>
-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
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 */
/*
* 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 <michael.kostrzewa@nokia.com>
*
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;
}
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);
/*
* 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
* 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.
*
* <example>
* <title>Creating a HildonEntry with a placeholder</title>
* 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;
* }
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,
}
}
-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
*
* 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);
}
/**
*
* 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));
}
* 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);
}
/**
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,
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;
}
/*
* 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 <rodrigo.novo@nokia.com>
*
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;
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;
/*
* 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 <rodrigo.novo@nokia.com>
*
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:
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));
}
/**
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));
}
/**
/*
* 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
}
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)));
}
}
}
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);
/*
* 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 <rodrigo.novo@nokia.com>
*
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:
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:
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));
/* 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));
} 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));
/* 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));
/*
* 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
* 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.
*
* <example>
* <title>Creating a HildonTextView with a placeholder</title>
* 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;
* }
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
* 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);
}
/**
* 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));
}
/**
* 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);
}
/**
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)
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,
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));
}
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);
}
/*
* 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
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)) {
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;
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);
}