* @short_description: A selector widget with one column and a text entry
* @see_also: #HildonTouchSelector, #HildonPickerButton
*
- * #HildonTouchSelectorEntry is a selector widget with a text entry, similar in behaviour
- * to #GtkComboBoxEntry, that allows user to select an item from a predefined list
- * or to enter a different one in a #GtkEntry. Items can also be searched and selected
- * by typing in the entry.
+ * #HildonTouchSelectorEntry is a selector widget with a text entry, similar in
+ * behaviour to #GtkComboBoxEntry, that allows user to select an item from a
+ * predefined list or to enter a different one in a #GtkEntry. Items can also
+ * be searched and selected by typing in the entry.
*
* The main difference between the #GtkTreeModel used by #HildonTouchSelector
- * and #HildonTouchSelectorEntry, is that the latter must always include a text column.
- * You should set it with hildon_touch_selector_entry_set_text_column().
+ * and #HildonTouchSelectorEntry, is that the latter must always include a text
+ * column. You should set it with hildon_touch_selector_entry_set_text_column().
*
* Normally, you would use #HildonTouchSelectorEntry together with a
* #HildonPickerDialog activated from a button. For the most common
gint column, GtkTreeModel *model);
static gboolean hildon_touch_selector_entry_has_multiple_selection (HildonTouchSelector * selector);
+static void
+_text_column_modified (GObject *pspec, GParamSpec *gobject, gpointer data);
+
+
struct _HildonTouchSelectorEntryPrivate {
- gint text_column;
gulong signal_id;
GtkWidget *entry;
};
object_class->get_property = hildon_touch_selector_entry_get_property;
object_class->set_property = hildon_touch_selector_entry_set_property;
+ /**
+ * HildonTouchSelectorEntry:text-column:
+ *
+ * Deprecated: now this property is in HildonTouchSelectorColumn use
+ * hildon_touch_selector_entry_set_text_column() and
+ * hildon_touch_selector_entry_get_text_column() to manage this.
+ *
+ **/
g_object_class_install_property (G_OBJECT_CLASS (klass),
PROP_TEXT_COLUMN,
g_param_spec_int ("text-column",
hildon_touch_selector_entry_print_func (HildonTouchSelector * selector)
{
HildonTouchSelectorEntryPrivate *priv;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint column;
+ gchar *text = NULL;
priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);
- return g_strdup (gtk_entry_get_text (GTK_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)) {
+ column = hildon_touch_selector_entry_get_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector));
+ gtk_tree_model_get (model, &iter, column, &text, -1);
+ }
+ }
+
+ return text;
}
static void
GtkWidget *selector;
GtkEntryCompletion *completion;
HildonTouchSelectorEntryPrivate *priv;
+ HildonTouchSelectorColumn *column = NULL;
selector = hildon_touch_selector_entry_new ();
model = gtk_list_store_new (1, G_TYPE_STRING);
completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (model));
+ column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
+ GTK_TREE_MODEL (model), FALSE);
- hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
- GTK_TREE_MODEL (model), FALSE);
+ g_signal_connect (column, "notify::text-column", G_CALLBACK (_text_column_modified),
+ selector);
hildon_touch_selector_entry_set_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector), 0);
return selector;
}
+static void
+_text_column_modified (GObject *pspec, GParamSpec *gobject, gpointer data)
+{
+ HildonTouchSelectorEntry *selector;
+ HildonTouchSelectorEntryPrivate *priv;
+ GtkEntryCompletion *completion;
+ gint text_column = -1;
+
+ g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (data));
+ selector = HILDON_TOUCH_SELECTOR_ENTRY (data);
+
+ priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (HILDON_TOUCH_SELECTOR_ENTRY(selector));
+ completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
+
+ text_column = hildon_touch_selector_entry_get_text_column (selector);
+
+ gtk_entry_completion_set_text_column (completion, text_column);
+}
+
+/**
+ * hildon_touch_selector_entry_set_text_column:
+ * @selector: A #HildonTouchSelectorEntry
+ * @text_column: A column in model to get the strings from
+ *
+ * Sets the model column which touch selector box should use to get strings
+ * from to be @text_column.
+ *
+ **/
void
hildon_touch_selector_entry_set_text_column (HildonTouchSelectorEntry *selector,
gint text_column)
{
- HildonTouchSelectorEntryPrivate *priv;
- GtkEntryCompletion *completion;
+ HildonTouchSelectorColumn *column = NULL;
g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector));
g_return_if_fail (text_column >= -1);
- priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);
- completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
+ column = hildon_touch_selector_get_column (HILDON_TOUCH_SELECTOR (selector), 0);
- gtk_entry_completion_set_text_column (completion, text_column);
- priv->text_column = text_column;
+ g_object_set (G_OBJECT (column), "text-column", text_column, NULL);
}
+/**
+ * hildon_touch_selector_entry_get_text_column:
+ * @selector: A #HildonTouchSelectorEntry
+ *
+ * Gets the text column that @selector is using as a text column.
+ *
+ * Returns: the number of the column used as a text column.
+ *
+ **/
gint
hildon_touch_selector_entry_get_text_column (HildonTouchSelectorEntry *selector)
{
- HildonTouchSelectorEntryPrivate *priv;
+ HildonTouchSelectorColumn *column = NULL;
+ gint text_column = -1;
g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector), -1);
- priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);
+ column = hildon_touch_selector_get_column (HILDON_TOUCH_SELECTOR (selector),
+ 0);
+
+ g_object_get (G_OBJECT (column), "text-column", &text_column, NULL);
- return priv->text_column;
+ return text_column;
}
static void
const gchar *prefix;
gchar *text;
gboolean found = FALSE;
+ gint text_column = -1;
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 = gtk_entry_get_text (entry);
- model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
+ model = hildon_touch_selector_get_model (selector, 0);
if (!gtk_tree_model_get_iter_first (model, &iter)) {
return;
}
do {
- gtk_tree_model_get (model, &iter, priv->text_column, &text, -1);
+ gtk_tree_model_get (model, &iter, text_column, &text, -1);
found = g_str_has_prefix (text, prefix);
g_free (text);
} while (found != TRUE && gtk_tree_model_iter_next (model, &iter));
GtkTreePath *path;
GList *selected_rows;
gchar *text;
+ gint text_column = -1;
priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);
model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
+ text_column = hildon_touch_selector_entry_get_text_column (selector);
selected_rows = hildon_touch_selector_get_selected_rows (HILDON_TOUCH_SELECTOR (selector), 0);
if (selected_rows == NULL) {
path = (GtkTreePath *)selected_rows->data;
gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, priv->text_column, &text, -1);
+ gtk_tree_model_get (model, &iter, text_column, &text, -1);
gtk_tree_path_free (path);
g_list_free (selected_rows);
{
GtkEntryCompletion *completion;
HildonTouchSelectorEntryPrivate *priv;
+ gint text_column = -1;
g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector));
g_return_if_fail (column == 0);
completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
gtk_entry_completion_set_model (completion, model);
- gtk_entry_completion_set_text_column (completion, priv->text_column);
+
+ text_column = hildon_touch_selector_entry_get_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector));
+
+ gtk_entry_completion_set_text_column (completion, text_column);
}
static gboolean