2006-09-21 Tommi Komulainen <tommi.komulainen@nokia.com>
[hildon] / hildon-widgets / hildon-find-toolbar.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License or any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-find-toolbar
27  * @short_description: A special toolbar to be used with HildonAppView
28  * @see_also: #HildonAppView
29  *
30  * HildonFindToolbar is a predefined toolbar for text searching purpose. 
31  * It contains a GtkListStore which has the text items that the user has 
32  * searched. But once the application is terminated, or HildonFindToolbar 
33  * is trashed. Programmer is responsible for getting the GtkListStore through 
34  * property "list", if he/she wants to use the information in the future.
35  * And through the same property, programmer is able to set the GtkListStore. 
36  * Note, once the search button is pressed, string in the GtkComboxEntry is 
37  * automatically added to the existing model, unless it is empty.
38  */    
39
40 #include "hildon-find-toolbar.h"
41 #include "hildon-defines.h"
42 #include <gdk/gdkkeysyms.h>
43
44 #include <gtk/gtklabel.h>
45 #include <gtk/gtkentry.h>
46 #include <gtk/gtkbutton.h>
47 #include <gtk/gtktoolbutton.h>
48 #include <gtk/gtktoolitem.h>
49 #include <gtk/gtkcomboboxentry.h>
50 #include <gtk/gtkseparatortoolitem.h>
51 #include <string.h>
52
53 #ifdef HAVE_CONFIG_H
54 #include <config.h>
55 #endif
56 #include <libintl.h>
57 #define _(String) dgettext(PACKAGE, String)
58
59 /*same define as gtkentry.c as entry will further handle this*/
60 #define MAX_SIZE G_MAXUSHORT
61 #define FIND_LABEL_XPADDING 6
62 #define FIND_LABEL_YPADDING 0
63
64 enum
65 {
66   SEARCH = 0,
67   CLOSE,
68   INVALID_INPUT,
69   HISTORY_APPEND,
70
71   LAST_SIGNAL
72 };
73
74 enum
75 {
76   PROP_LABEL = 1,
77   PROP_PREFIX,
78   PROP_LIST,
79   PROP_COLUMN,
80   PROP_MAX,
81   PROP_HISTORY_LIMIT
82 };
83
84 struct _HildonFindToolbarPrivate
85 {
86   GtkWidget*            label;
87   GtkComboBoxEntry*     entry_combo_box;
88   GtkToolItem*          find_button;
89   GtkToolItem*          separator;
90   GtkToolItem*          close_button;
91
92   gint                  history_limit;
93 };
94 static guint HildonFindToolbar_signal[LAST_SIGNAL] = {0};
95
96 G_DEFINE_TYPE(HildonFindToolbar, hildon_find_toolbar, GTK_TYPE_TOOLBAR)
97
98 static GtkTreeModel *
99 hildon_find_toolbar_get_list_model(HildonFindToolbarPrivate *priv)
100 {
101   GtkTreeModel *filter_model =
102     gtk_combo_box_get_model(GTK_COMBO_BOX(priv->entry_combo_box));
103
104   return filter_model == NULL ? NULL :
105     gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(filter_model));
106 }
107
108 static GtkEntry *
109 hildon_find_toolbar_get_entry(HildonFindToolbarPrivate *priv)
110 {
111   return GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->entry_combo_box)));
112 }
113
114 static gboolean
115 hildon_find_toolbar_filter(GtkTreeModel *model,
116                            GtkTreeIter *iter,
117                            gpointer self)
118 {
119   GtkTreePath *path;
120   const gint *indices;
121   gint n;
122   gint limit;
123   gint total;
124
125   total = gtk_tree_model_iter_n_children(model, NULL);
126   g_object_get(self, "history_limit", &limit, NULL);
127   path = gtk_tree_model_get_path(model, iter);
128   indices = gtk_tree_path_get_indices (path);
129
130   /* set the row's index, list store has only one level */
131   n = indices[0];
132   gtk_tree_path_free(path);
133   
134   /*if the row is among the latest "history_limit" additions of the 
135    * model, then we show it */
136   if( (total - limit <= n) && (n < total) )
137     return TRUE;
138   else
139     return FALSE;
140 }
141
142 static void
143 hildon_find_toolbar_apply_filter(HildonFindToolbar *self,  GtkTreeModel *model)
144 {
145   GtkTreeModel *filter;
146   HildonFindToolbarPrivate *priv = self->priv;
147
148   /* Create a filter for the given model. Its only purpose is to hide
149      the oldest entries so only "history_limit" entries are visible. */
150   filter = gtk_tree_model_filter_new(model, NULL);
151
152   gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter), 
153                                          hildon_find_toolbar_filter,
154                                          self, NULL);
155   gtk_combo_box_set_model(GTK_COMBO_BOX(priv->entry_combo_box), filter);
156
157   /* ComboBox keeps the only needed reference to the filter */
158   g_object_unref(filter);
159 }
160
161 static void
162 hildon_find_toolbar_get_property(GObject     *object,
163                                  guint        prop_id,
164                                  GValue      *value,
165                                  GParamSpec  *pspec)
166 {
167   HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR(object)->priv;
168   const gchar *string;
169   gint c_n, max_len;
170
171   switch (prop_id)
172     {
173     case PROP_LABEL:
174       string = gtk_label_get_text(GTK_LABEL(priv->label));
175       g_value_set_string(value, string);
176       break;
177     case PROP_PREFIX:
178       string = gtk_entry_get_text(hildon_find_toolbar_get_entry(priv));
179       g_value_set_string(value, string);
180       break;
181     case PROP_LIST:
182       g_value_set_object(value, hildon_find_toolbar_get_list_model(priv));
183       break;
184     case PROP_COLUMN:
185       c_n = gtk_combo_box_entry_get_text_column(priv->entry_combo_box);
186       g_value_set_int(value, c_n);
187       break;
188     case PROP_MAX:
189       max_len = gtk_entry_get_max_length(hildon_find_toolbar_get_entry(priv));
190       g_value_set_int(value, max_len);
191       break;
192     case PROP_HISTORY_LIMIT:
193       g_value_set_int(value, priv->history_limit);
194       break;
195     default:
196       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
197       break;
198     }
199 }
200
201 static void
202 hildon_find_toolbar_set_property(GObject      *object,
203                                  guint         prop_id,
204                                  const GValue *value,
205                                  GParamSpec   *pspec)
206 {
207   HildonFindToolbar *self = HILDON_FIND_TOOLBAR(object);
208   HildonFindToolbarPrivate *priv = self->priv;
209   GtkTreeModel *model;
210   const gchar *string;
211   
212   switch (prop_id)
213     {
214     case PROP_LABEL:
215       string = g_value_get_string(value);       
216       gtk_label_set_text(GTK_LABEL(priv->label), string);
217       break;
218     case PROP_PREFIX:
219       string = g_value_get_string(value);
220       gtk_entry_set_text(hildon_find_toolbar_get_entry(priv), string);
221       break;
222     case PROP_LIST:
223       model = GTK_TREE_MODEL(g_value_get_object(value));
224       hildon_find_toolbar_apply_filter(self, model);
225       break;
226     case PROP_COLUMN:
227       gtk_combo_box_entry_set_text_column(priv->entry_combo_box,
228                                           g_value_get_int(value));
229       break;
230     case PROP_MAX:
231       gtk_entry_set_max_length(hildon_find_toolbar_get_entry(priv),
232                                g_value_get_int(value));
233       break;
234     case PROP_HISTORY_LIMIT:
235       priv->history_limit = g_value_get_int(value);
236
237       /* Re-apply the history limit to the model. */
238       model = hildon_find_toolbar_get_list_model(priv);
239       if (model != NULL)
240         {
241           /* Note that refilter function doesn't update the status of the
242              combobox popup arrow, so we'll just recreate the filter. */
243           hildon_find_toolbar_apply_filter(self, model);
244
245           if (gtk_combo_box_entry_get_text_column(priv->entry_combo_box) == -1)
246             {
247               /* FIXME: This is only for backwards compatibility, although
248                  probably nothing actually relies on it. The behavior was only
249                  an accidental side effect of original code */
250               gtk_combo_box_entry_set_text_column(priv->entry_combo_box, 0);
251             }
252         }
253       break;
254     default:
255       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
256       break;
257     }
258 }
259
260 static gboolean
261 hildon_find_toolbar_find_string(HildonFindToolbar *self,
262                                 GtkTreeIter       *iter,
263                                 gint               column,
264                                 const gchar       *string)
265 {
266   GtkTreeModel *model = NULL;
267   gchar *old_string;
268
269   model = hildon_find_toolbar_get_list_model(self->priv);
270
271   if (gtk_tree_model_get_iter_first(model, iter))
272     {
273       do {
274         gtk_tree_model_get(model, iter, column, &old_string, -1);
275         if (old_string != NULL && strcmp(string, old_string) == 0)
276           {
277             /* Found it */
278             return TRUE;
279           }
280       } while (gtk_tree_model_iter_next(model, iter));
281     }
282
283   return FALSE;
284 }
285
286 static gboolean
287 hildon_find_toolbar_history_append(HildonFindToolbar *self,
288                                    gpointer data) 
289 {
290   HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR(self)->priv;
291   gchar *string;
292   gint column = 0;
293   GtkTreeModel *model = NULL;
294   GtkListStore *list = NULL;
295   GtkTreeIter iter;
296   gboolean self_create = FALSE;
297   
298   g_object_get(self, "prefix", &string, NULL);
299   
300   if (*string == '\0')
301     {
302       /* empty prefix, ignore */
303       g_free(string);
304       return TRUE;
305     }
306
307
308   /* If list store is set, get it */
309   model = hildon_find_toolbar_get_list_model(priv);
310   if(model != NULL)
311     {
312       list = GTK_LIST_STORE(model);
313       g_object_get(self, "column", &column, NULL);
314
315       if (column < 0)
316         {
317           /* Column number is -1 if "column" property hasn't been set but
318              "list" property is. */
319           g_free(string);
320           return TRUE;
321         }
322
323       /* Latest string is always the first one in list. If the string
324          already exists, remove it so there are no duplicates in list. */
325       if (hildon_find_toolbar_find_string(self, &iter, column, string))
326           gtk_list_store_remove(list, &iter);
327     }
328   else
329     {
330       /* No list store set. Create our own. */
331       list = gtk_list_store_new(1, G_TYPE_STRING);
332       model = GTK_TREE_MODEL(list);
333       self_create = TRUE;
334     }
335
336   /* Add the string to first in list */
337   gtk_list_store_append(list, &iter);
338   gtk_list_store_set(list, &iter, column, string, -1);
339
340   if(self_create)
341     {
342       /* Add the created list to ComboBoxEntry */
343       hildon_find_toolbar_apply_filter(self, model);
344       /* ComboBoxEntry keeps the only needed reference to this list */
345       g_object_unref(list);
346
347       /* Set the column only after ComboBoxEntry's model is set
348          in hildon_find_toolbar_apply_filter() */
349       g_object_set(self, "column", 0, NULL);
350     }
351   else
352     {
353       /* Refilter to get the oldest entry hidden from history */
354       gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(
355         gtk_combo_box_get_model(GTK_COMBO_BOX(priv->entry_combo_box))));
356     }
357
358   g_free(string);
359
360   return TRUE;
361 }
362
363 static void
364 hildon_find_toolbar_emit_search(GtkButton *button, gpointer self)
365 {
366   gboolean rb;
367
368   /* Clicked search button. Perform search and add search prefix to history */
369   g_signal_emit_by_name(self, "search", NULL);
370   g_signal_emit_by_name(self, "history_append", &rb, NULL);
371 }
372
373 static void
374 hildon_find_toolbar_emit_close(GtkButton *button, gpointer self)
375 {
376   GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (self));
377   gtk_widget_grab_focus (parent);
378   /* Clicked close button */
379   g_signal_emit_by_name(self, "close", NULL);
380 }
381
382 static void
383 hildon_find_toolbar_emit_invalid_input(GtkEntry *entry, 
384                                        GtkInvalidInputType type, 
385                                        gpointer self)
386 {
387   if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
388     g_signal_emit_by_name(self, "invalid_input", NULL);
389 }
390
391 static void
392 hildon_find_toolbar_entry_activate (GtkWidget *widget,
393                                     gpointer user_data)
394 {
395   GtkWidget *find_toolbar = GTK_WIDGET(user_data);
396   gboolean rb;  
397
398   /* NB#40936 stop focus from moving to next widget */
399   g_signal_stop_emission_by_name (widget, "activate");
400
401   g_signal_emit_by_name(find_toolbar, "search", NULL);
402   g_signal_emit_by_name(find_toolbar, "history_append", &rb, NULL);
403 }
404
405 static void
406 hildon_find_toolbar_class_init(HildonFindToolbarClass *klass)
407 {
408   GObjectClass *object_class;
409
410   g_type_class_add_private(klass, sizeof(HildonFindToolbarPrivate));
411
412   object_class = G_OBJECT_CLASS(klass);
413
414   object_class->get_property = hildon_find_toolbar_get_property;
415   object_class->set_property = hildon_find_toolbar_set_property;
416
417   klass->history_append = hildon_find_toolbar_history_append;
418   
419   g_object_class_install_property(object_class, PROP_LABEL, 
420                                   g_param_spec_string("label", 
421                                   "Label", "Displayed name for"
422                                   " find-toolbar",
423                                   _("ecdg_ti_find_toolbar_label"),
424                                   G_PARAM_READWRITE |
425                                   G_PARAM_CONSTRUCT));
426   
427   g_object_class_install_property(object_class, PROP_PREFIX, 
428                                   g_param_spec_string("prefix", 
429                                   "Prefix", "Search string", NULL,
430                                   G_PARAM_READWRITE));
431   
432   g_object_class_install_property(object_class, PROP_LIST,
433                                   g_param_spec_object("list",
434                                   "List"," GtkListStore model where "
435                                   "history list is kept",
436                                   GTK_TYPE_LIST_STORE,
437                                   G_PARAM_READWRITE));
438
439   g_object_class_install_property(object_class, PROP_COLUMN,
440                                   g_param_spec_int("column",
441                                   "Column", "Column number in GtkListStore "
442                                   "where history list strings are kept",
443                                   0, G_MAXINT,
444                                   0, G_PARAM_READWRITE));
445
446   g_object_class_install_property(object_class, PROP_MAX,
447                                   g_param_spec_int("max_characters",
448                                   "Maximum number of characters",
449                                   "Maximum number of characters "
450                                   "in search string",
451                                   0, MAX_SIZE,
452                                   0, G_PARAM_READWRITE |
453                                   G_PARAM_CONSTRUCT));
454   
455   g_object_class_install_property(object_class, PROP_HISTORY_LIMIT,
456                                   g_param_spec_int("history_limit",
457                                   "Maximum number of history items",
458                                   "Maximum number of history items "
459                                   "in search combobox",
460                                   0, G_MAXINT,
461                                   5, G_PARAM_READWRITE |
462                                   G_PARAM_CONSTRUCT));
463
464   /**
465    * HildonFindToolbar::search:
466    * @toolbar: the toolbar which received the signal
467    * 
468    * Gets emitted when the find button is pressed.
469    */ 
470   HildonFindToolbar_signal[SEARCH] = 
471                               g_signal_new(
472                               "search", HILDON_TYPE_FIND_TOOLBAR,
473                               G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
474                               (HildonFindToolbarClass, search),
475                               NULL, NULL, gtk_marshal_VOID__VOID,
476                               G_TYPE_NONE, 0);
477   
478   /**
479    * HildonFindToolbar::close:
480    * @toolbar: the toolbar which received the signal
481    * 
482    * Gets emitted when the close button is pressed.
483    */ 
484   HildonFindToolbar_signal[CLOSE] = 
485                              g_signal_new(
486                              "close", HILDON_TYPE_FIND_TOOLBAR,
487                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
488                              (HildonFindToolbarClass, close),
489                              NULL, NULL, gtk_marshal_VOID__VOID,
490                              G_TYPE_NONE, 0);
491   
492   /**
493    * HildonFindToolbar::invalid-input:
494    * @toolbar: the toolbar which received the signal
495    * 
496    * Gets emitted when the maximum search prefix length is reached and
497    * user tries to type more.
498    */ 
499   HildonFindToolbar_signal[INVALID_INPUT] = 
500                              g_signal_new(
501                              "invalid_input", HILDON_TYPE_FIND_TOOLBAR,
502                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
503                              (HildonFindToolbarClass, invalid_input),
504                              NULL, NULL, gtk_marshal_VOID__VOID,
505                              G_TYPE_NONE, 0);
506   
507   /**
508    * HildonFindToolbar::history-append:
509    * @toolbar: the toolbar which received the signal
510    * 
511    * Gets emitted when the current search prefix should be added to history.
512    */ 
513   HildonFindToolbar_signal[HISTORY_APPEND] = 
514                              g_signal_new(
515                              "history_append", HILDON_TYPE_FIND_TOOLBAR,
516                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
517                              (HildonFindToolbarClass, history_append),
518                              g_signal_accumulator_true_handled, NULL, 
519                              gtk_marshal_BOOLEAN__VOID,
520                              G_TYPE_BOOLEAN, 0);
521 }
522
523 static void
524 hildon_find_toolbar_init(HildonFindToolbar *self)
525 {
526   GtkToolItem *label_container;
527   GtkToolItem *entry_combo_box_container;
528   
529   self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
530                                            HILDON_TYPE_FIND_TOOLBAR, 
531                                            HildonFindToolbarPrivate);
532
533   /* Create the label */
534   self->priv->label = gtk_label_new(_("ecdg_ti_find_toolbar_label"));
535   
536   gtk_misc_set_padding (GTK_MISC(self->priv->label), FIND_LABEL_XPADDING,
537                         FIND_LABEL_YPADDING);
538
539   label_container = gtk_tool_item_new();
540   gtk_container_add(GTK_CONTAINER(label_container), 
541                     self->priv->label);
542   gtk_widget_show_all(GTK_WIDGET(label_container));
543   gtk_toolbar_insert (GTK_TOOLBAR(self), label_container, -1);
544   
545   /* ComboBoxEntry for search prefix string / history list */
546   self->priv->entry_combo_box = GTK_COMBO_BOX_ENTRY(gtk_combo_box_entry_new());
547   g_signal_connect(hildon_find_toolbar_get_entry(self->priv),
548                    "invalid_input", 
549                    G_CALLBACK(hildon_find_toolbar_emit_invalid_input), self);
550   entry_combo_box_container = gtk_tool_item_new();
551   gtk_tool_item_set_expand(entry_combo_box_container, TRUE);
552   gtk_container_add(GTK_CONTAINER(entry_combo_box_container),
553                     GTK_WIDGET(self->priv->entry_combo_box));
554   gtk_widget_show_all(GTK_WIDGET(entry_combo_box_container));
555   gtk_toolbar_insert (GTK_TOOLBAR(self), entry_combo_box_container, -1);
556   g_signal_connect(hildon_find_toolbar_get_entry(self->priv),
557                     "activate",
558                     G_CALLBACK(hildon_find_toolbar_entry_activate), self);
559
560   /* Find button */
561   self->priv->find_button = gtk_tool_button_new (
562                               gtk_image_new_from_icon_name ("qgn_toolb_browser_gobutton",
563                                                             HILDON_ICON_SIZE_TOOLBAR),
564                               "Find");
565   g_signal_connect(self->priv->find_button, "clicked",
566                    G_CALLBACK(hildon_find_toolbar_emit_search), self);
567   gtk_widget_show_all(GTK_WIDGET(self->priv->find_button));
568   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->find_button, -1);
569   if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(self->priv->find_button)->child) )
570       GTK_WIDGET_UNSET_FLAGS(
571               GTK_BIN(self->priv->find_button)->child, GTK_CAN_FOCUS);
572   
573   /* Separator */
574   self->priv->separator = gtk_separator_tool_item_new();
575   gtk_widget_show(GTK_WIDGET(self->priv->separator));
576   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->separator, -1);
577   
578   /* Close button */
579   self->priv->close_button = gtk_tool_button_new (
580                                gtk_image_new_from_icon_name ("qgn_toolb_gene_close",
581                                                              HILDON_ICON_SIZE_TOOLBAR),
582                                "Close");
583   g_signal_connect(self->priv->close_button, "clicked",
584                    G_CALLBACK(hildon_find_toolbar_emit_close), self);
585   gtk_widget_show_all(GTK_WIDGET(self->priv->close_button));
586   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->close_button, -1);
587   if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(self->priv->close_button)->child) )
588       GTK_WIDGET_UNSET_FLAGS(
589               GTK_BIN(self->priv->close_button)->child, GTK_CAN_FOCUS);
590 }
591
592 /*Public functions*/
593
594 /**
595  * hildon_find_toolbar_new:
596  * @label: label for the find_toolbar, NULL to set the label to 
597  *         default "Find"
598  * 
599  * Returns a new HildonFindToolbar.
600  *
601  * Returns: a new HildonFindToolbar
602  */
603
604 GtkWidget *
605 hildon_find_toolbar_new(const gchar *label)
606 {
607   GtkWidget *findtoolbar;
608   
609   findtoolbar = GTK_WIDGET(g_object_new(HILDON_TYPE_FIND_TOOLBAR, NULL));
610   if(label != NULL)
611     g_object_set(findtoolbar, "label", label, NULL);
612
613   return findtoolbar;
614 }
615
616 /**
617  * hildon_find_toolbar_new_with_model
618  * @label: label for the find_toolbar, NULL to set the label to 
619  *         default "Find"
620  * @model: a @GtkListStore
621  * @column: indicating which column the search histry list will 
622  *          retreive string from
623  * 
624  * Returns a new HildonFindToolbar, with a model.
625  *
626  * Returns: a new #HildonFindToolbar
627  */
628 GtkWidget *
629 hildon_find_toolbar_new_with_model(const gchar *label,
630                                    GtkListStore *model,
631                                    gint column)
632 {
633   GtkWidget *findtoolbar;
634
635   findtoolbar = hildon_find_toolbar_new(label);
636   g_object_set(findtoolbar, "list", model,
637                "column", column, NULL);
638
639   return findtoolbar;
640 }
641
642 /**
643  * hildon_find_toolbar_highlight_entry
644  * @ftb: find Toolbar whose entry is to be highlighted
645  * @get_focus: if user passes TRUE to this value, then the text in
646  * the entry will not only get highlighted, but also get focused.
647  * 
648  */
649 void
650 hildon_find_toolbar_highlight_entry(HildonFindToolbar *ftb,
651                                     gboolean get_focus)
652 {
653   GtkEntry *entry = NULL;
654   
655   g_return_if_fail(HILDON_IS_FIND_TOOLBAR(ftb));
656   
657   entry = hildon_find_toolbar_get_entry(ftb->priv);
658   
659   gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
660   
661   if(get_focus)
662     gtk_widget_grab_focus(GTK_WIDGET(entry));
663 }