/*
- * This file is part of hildon-libs
+ * This file is a part of hildon
*
* Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
*
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
*
* This library 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; version 2.1 of
- * the License.
+ * the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
/**
* SECTION:hildon-find-toolbar
- * @short_description: A special toolbar to be used with HildonAppView
- * @see_also: #HildonAppView
+ * @short_description: A toolbar with a search field.
+ * @see_also: #HildonWindow
*
- * HildonFindToolbar is a predefined toolbar for text searching purpose.
- * It contains a GtkListStore which has the text items that the user has
- * searched. But once the application is terminated, or HildonFindToolbar
- * is trashed. Programmer is responsible for getting the GtkListStore through
- * property "list", if he/she wants to use the information in the future.
- * And through the same property, programmer is able to set the GtkListStore.
- * Note, once the search button is pressed, string in the GtkComboxEntry is
- * automatically added to the existing model, unless it is empty.
- */
+ * HildonFindToolbar is a toolbar that contains a search entry and a dropdown
+ * list with previously searched strings. The list is represented using a
+ * #GtkListStore and can be accesed using a property 'list'. Entries are added
+ * automatically to the list when the search button is pressed.
+ *
+ */
+#ifdef HAVE_CONFIG_H
#include <config.h>
-#include "hildon-find-toolbar.h"
-#include "hildon-defines.h"
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkbutton.h>
-#include <gtk/gtktoolbutton.h>
-#include <gtk/gtktoolitem.h>
-#include <gtk/gtkcomboboxentry.h>
-#include <gtk/gtkseparatortoolitem.h>
+#endif
+
#include <string.h>
#include <libintl.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "hildon-find-toolbar.h"
+#include "hildon-defines.h"
#include "hildon-find-toolbar-private.h"
+#include "hildon-marshalers.h"
#define _(String) \
- dgettext(PACKAGE, String)
+ dgettext("hildon-libs", String)
-/*same define as gtkentry.c as entry will further handle this*/
+/* Same define as gtkentry.c as entry will further handle this */
#define MAX_SIZE G_MAXUSHORT
hildon_find_toolbar_emit_close (GtkButton *button,
gpointer self);
+#ifdef MAEMO_GTK
static void
hildon_find_toolbar_emit_invalid_input (GtkEntry *entry,
GtkInvalidInputType type,
gpointer self);
+#endif
static void
hildon_find_toolbar_entry_activate (GtkWidget *widget,
static guint HildonFindToolbar_signal [LAST_SIGNAL] = {0};
+/**
+ * hildon_find_toolbar_get_type:
+ *
+ * Initializes and returns the type of a hildon fond toolbar.
+ *
+ * Returns: GType of #HildonFindToolbar
+ */
GType G_GNUC_CONST
hildon_find_toolbar_get_type (void)
{
g_free (string);
- return TRUE;
+ return FALSE;
}
static void
hildon_find_toolbar_emit_close (GtkButton *button,
gpointer self)
{
+#ifdef MAEMO_GTK
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
{
hildon_gtk_im_context_hide (GTK_ENTRY (entry)->im_context);
}
+#endif
/* Clicked close button */
g_signal_emit_by_name (self, "close", NULL);
}
+#ifdef MAEMO_GTK
static void
hildon_find_toolbar_emit_invalid_input (GtkEntry *entry,
GtkInvalidInputType type,
if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
g_signal_emit_by_name (self, "invalid_input", NULL);
}
+#endif
static void
hildon_find_toolbar_entry_activate (GtkWidget *widget,
{
GObjectClass *object_class;
- g_type_class_add_private (klass, sizeof(HildonFindToolbarPrivate));
+ g_type_class_add_private (klass, sizeof (HildonFindToolbarPrivate));
object_class = G_OBJECT_CLASS(klass);
klass->history_append = (gpointer) hildon_find_toolbar_history_append;
- g_object_class_install_property(object_class, PROP_LABEL,
- g_param_spec_string("label",
+ /**
+ * HildonFindToolbar:label:
+ *
+ * The label to display before the search box.
+ *
+ */
+ g_object_class_install_property (object_class, PROP_LABEL,
+ g_param_spec_string ("label",
"Label", "Displayed name for"
" find-toolbar",
_("ecdg_ti_find_toolbar_label"),
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
- g_object_class_install_property(object_class, PROP_PREFIX,
- g_param_spec_string("prefix",
+ /**
+ * HildonFindToolbar:label:
+ *
+ * The label to display before the search box.
+ *
+ */
+ g_object_class_install_property (object_class, PROP_PREFIX,
+ g_param_spec_string ("prefix",
"Prefix", "Search string", NULL,
G_PARAM_READWRITE));
- g_object_class_install_property(object_class, PROP_LIST,
- g_param_spec_object("list",
+ /**
+ * HildonFindToolbar:list:
+ *
+ * A #GtkListStore where the search history is kept.
+ *
+ */
+ g_object_class_install_property (object_class, PROP_LIST,
+ g_param_spec_object ("list",
"List"," GtkListStore model where "
"history list is kept",
GTK_TYPE_LIST_STORE,
G_PARAM_READWRITE));
+ /**
+ * HildonFindToolbar:column:
+ *
+ * The column number in GtkListStore where strings of
+ * search history are kept.
+ *
+ */
g_object_class_install_property(object_class, PROP_COLUMN,
- g_param_spec_int("column",
+ g_param_spec_int ("column",
"Column", "Column number in GtkListStore "
"where history list strings are kept",
0, G_MAXINT,
0, G_PARAM_READWRITE));
- g_object_class_install_property(object_class, PROP_MAX,
- g_param_spec_int("max_characters",
+ /**
+ * HildonFindToolbar:label:
+ *
+ * The label to display before the search box.
+ *
+ */
+ g_object_class_install_property (object_class, PROP_MAX,
+ g_param_spec_int ("max_characters",
"Maximum number of characters",
"Maximum number of characters "
"in search string",
0, G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
- g_object_class_install_property(object_class, PROP_HISTORY_LIMIT,
- g_param_spec_int("history_limit",
+ /**
+ * HildonFindToolbar:history-limit:
+ *
+ * Maximum number of history items in the combobox.
+ *
+ */
+ g_object_class_install_property (object_class, PROP_HISTORY_LIMIT,
+ g_param_spec_int ("history-limit",
"Maximum number of history items",
"Maximum number of history items "
"in search combobox",
"search", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, search),
- NULL, NULL, gtk_marshal_VOID__VOID,
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
"close", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, close),
- NULL, NULL, gtk_marshal_VOID__VOID,
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
*
* Gets emitted when the maximum search prefix length is reached and
* user tries to type more.
- */
+ */
HildonFindToolbar_signal[INVALID_INPUT] =
g_signal_new(
"invalid_input", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, invalid_input),
- NULL, NULL, gtk_marshal_VOID__VOID,
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, history_append),
g_signal_accumulator_true_handled, NULL,
- gtk_marshal_BOOLEAN__VOID,
+ _hildon_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
}
{
GtkToolItem *label_container;
GtkToolItem *entry_combo_box_container;
+ GtkAlignment *alignment;
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
/* ComboBoxEntry for search prefix string / history list */
priv->entry_combo_box = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new ());
+
+#ifdef MAEMO_GTK
g_signal_connect (hildon_find_toolbar_get_entry(priv),
"invalid_input",
G_CALLBACK(hildon_find_toolbar_emit_invalid_input), self);
+#endif
entry_combo_box_container = gtk_tool_item_new ();
+ alignment = GTK_ALIGNMENT (gtk_alignment_new (0, 0.5, 1, 0));
gtk_tool_item_set_expand (entry_combo_box_container, TRUE);
- gtk_container_add (GTK_CONTAINER (entry_combo_box_container),
+ gtk_container_add (GTK_CONTAINER (alignment),
GTK_WIDGET (priv->entry_combo_box));
+ gtk_container_add (GTK_CONTAINER (entry_combo_box_container),
+ GTK_WIDGET (alignment));
gtk_widget_show_all(GTK_WIDGET (entry_combo_box_container));
gtk_toolbar_insert (GTK_TOOLBAR (self), entry_combo_box_container, -1);
g_signal_connect (hildon_find_toolbar_get_entry (priv),
G_CALLBACK(hildon_find_toolbar_emit_search), self);
gtk_widget_show_all( GTK_WIDGET(priv->find_button));
gtk_toolbar_insert ( GTK_TOOLBAR(self), priv->find_button, -1);
+ gtk_widget_set_size_request (GTK_WIDGET (priv->find_button), 72, -1);
if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->find_button)->child) )
GTK_WIDGET_UNSET_FLAGS(
GTK_BIN(priv->find_button)->child, GTK_CAN_FOCUS);
gtk_image_new_from_icon_name ("qgn_toolb_gene_close",
HILDON_ICON_SIZE_TOOLBAR),
"Close");
+ gtk_widget_set_size_request (GTK_WIDGET (priv->close_button), 72, -1);
g_signal_connect(priv->close_button, "clicked",
G_CALLBACK(hildon_find_toolbar_emit_close), self);
gtk_widget_show_all(GTK_WIDGET(priv->close_button));
* @label: label for the find_toolbar, NULL to set the label to
* default "Find"
*
- * Returns a new HildonFindToolbar.
+ * Creates a new HildonFindToolbar.
*
* Returns: a new HildonFindToolbar
*/
-
GtkWidget*
hildon_find_toolbar_new (const gchar *label)
{
}
/**
- * hildon_find_toolbar_new_with_model
+ * hildon_find_toolbar_new_with_model:
* @label: label for the find_toolbar, NULL to set the label to
* default "Find"
* @model: a @GtkListStore
* @column: indicating which column the search histry list will
* retreive string from
*
- * Returns a new HildonFindToolbar, with a model.
+ * Creates a new HildonFindToolbar with a model.
*
* Returns: a new #HildonFindToolbar
*/
}
/**
- * hildon_find_toolbar_highlight_entry
+ * hildon_find_toolbar_highlight_entry:
* @ftb: find Toolbar whose entry is to be highlighted
* @get_focus: if user passes TRUE to this value, then the text in
* the entry will not only get highlighted, but also get focused.
+ *
+ * Highlights the current entry in the find toolbar.
*
*/
void
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
- if(get_focus)
+ if (get_focus)
gtk_widget_grab_focus (GTK_WIDGET (entry));
}
+/**
+ * hildon_find_toolbar_set_active:
+ * @toolbar: A find toolbar to operate on
+ * @index: An index in the model passed during construction, or -1 to have no active item
+ *
+ * Sets the active item on the toolbar's combo-box. Simply calls gtk_combo_box_set_active on
+ * the HildonFindToolbar's combo.
+ *
+ */
+void
+hildon_find_toolbar_set_active (HildonFindToolbar *toolbar,
+ gint index)
+{
+ HildonFindToolbarPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_FIND_TOOLBAR (toolbar));
+ priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (toolbar);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (priv->entry_combo_box), index);
+}
+
+/**
+ * hildon_find_toolbar_get_active:
+ * @toolbar: A find toolbar to query
+ *
+ * Gets the index of the currently active item, or -1 if there's no active item. Simply
+ * calls gtk_combo_box_get_active on the HildonFindToolbar's combo.
+ *
+ * Returns: An integer which is the index of the currently active item, or -1 if there's no active item.
+ *
+ */
+gint
+hildon_find_toolbar_get_active (HildonFindToolbar *toolbar)
+{
+ HildonFindToolbarPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_FIND_TOOLBAR (toolbar), -1);
+ priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (toolbar);
+
+ return gtk_combo_box_get_active (GTK_COMBO_BOX (priv->entry_combo_box));
+}
+
+/**
+ * hildon_find_toolbar_set_active_iter:
+ * @toolbar: A find toolbar to operate on
+ * @iter: An iter to make active
+ *
+ * Sets the current active item to be the one referenced by iter. Simply calls
+ * gtk_combo_box_set_active_iter on the HildonFindToolbar's combo.
+ *
+ */
+void
+hildon_find_toolbar_set_active_iter (HildonFindToolbar *toolbar,
+ GtkTreeIter *iter)
+{
+ HildonFindToolbarPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_FIND_TOOLBAR (toolbar));
+ priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (toolbar);
+
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->entry_combo_box), iter);
+}
+
+/**
+ * hildon_find_toolbar_get_active_iter:
+ * @toolbar: A find toolbar to query
+ * @iter: The uninitialized GtkTreeIter
+ *
+ * Sets iter to point to the current active item, if it exists. Simply calls
+ * gtk_combo_box_get_active_iter on the HildonFindToolbar's combo.
+ *
+ * Returns: TRUE, if iter was set
+ *
+ */
+gboolean
+hildon_find_toolbar_get_active_iter (HildonFindToolbar *toolbar,
+ GtkTreeIter *iter)
+{
+ HildonFindToolbarPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_FIND_TOOLBAR (toolbar), FALSE);
+ priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (toolbar);
+
+ return gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->entry_combo_box), iter);
+}
+
+/**
+ * hildon_find_toolbar_get_last_index
+ * @toolbar: A find toolbar to query
+ *
+ * Returns the index of the last (most recently added) item in the toolbar.
+ * Can be used to set this item active in the history-append signal.
+ *
+ *
+ * Returns: Index of the last entry
+ *
+ */
+gint32
+hildon_find_toolbar_get_last_index (HildonFindToolbar *toolbar)
+{
+ HildonFindToolbarPrivate *priv;
+ GtkTreeModel *filter_model;
+
+ g_return_val_if_fail (HILDON_IS_FIND_TOOLBAR (toolbar), FALSE);
+ priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (toolbar);
+
+ filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->entry_combo_box));
+
+ if (filter_model == NULL)
+ return 0;
+
+ gint i = 0;
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter_first (filter_model, &iter);
+
+ while (gtk_tree_model_iter_next (filter_model, &iter))
+ i++;
+
+ return i;
+}
+