2006-08-30 Michael Dominic Kostrzewa <michael.kostrzewa@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.
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.
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   /* Clicked close button */
377   g_signal_emit_by_name(self, "close", NULL);
378 }
379
380 static void
381 hildon_find_toolbar_emit_invalid_input(GtkEntry *entry, 
382                                        GtkInvalidInputType type, 
383                                        gpointer self)
384 {
385   if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
386     g_signal_emit_by_name(self, "invalid_input", NULL);
387 }
388
389 static gboolean
390 hildon_find_toolbar_entry_key_press (GtkWidget *widget,
391                                     GdkEventKey *event,
392                                     gpointer user_data)
393 {
394   GtkWidget *find_toolbar = GTK_WIDGET(user_data);
395   
396   /* on enter we emit search and history_append signals and keep
397    * focus by returning true */
398   if (event->keyval == GDK_KP_Enter)
399     {
400       gboolean rb;  
401       g_signal_emit_by_name(find_toolbar, "search", NULL);
402       g_signal_emit_by_name(find_toolbar, "history_append", &rb, NULL);
403
404       return TRUE;
405     }
406
407   return FALSE;      
408 }
409
410 static void
411 hildon_find_toolbar_class_init(HildonFindToolbarClass *klass)
412 {
413   GObjectClass *object_class;
414
415   g_type_class_add_private(klass, sizeof(HildonFindToolbarPrivate));
416
417   object_class = G_OBJECT_CLASS(klass);
418
419   object_class->get_property = hildon_find_toolbar_get_property;
420   object_class->set_property = hildon_find_toolbar_set_property;
421
422   klass->history_append = hildon_find_toolbar_history_append;
423   
424   g_object_class_install_property(object_class, PROP_LABEL, 
425                                   g_param_spec_string("label", 
426                                   "Label", "Displayed name for"
427                                   " find-toolbar",
428                                   _("ecdg_ti_find_toolbar_label"),
429                                   G_PARAM_READWRITE |
430                                   G_PARAM_CONSTRUCT));
431   
432   g_object_class_install_property(object_class, PROP_PREFIX, 
433                                   g_param_spec_string("prefix", 
434                                   "Prefix", "Search string", NULL,
435                                   G_PARAM_READWRITE));
436   
437   g_object_class_install_property(object_class, PROP_LIST,
438                                   g_param_spec_object("list",
439                                   "List"," GtkListStore model where "
440                                   "history list is kept",
441                                   GTK_TYPE_LIST_STORE,
442                                   G_PARAM_READWRITE));
443
444   g_object_class_install_property(object_class, PROP_COLUMN,
445                                   g_param_spec_int("column",
446                                   "Column", "Column number in GtkListStore "
447                                   "where history list strings are kept",
448                                   0, G_MAXINT,
449                                   0, G_PARAM_READWRITE));
450
451   g_object_class_install_property(object_class, PROP_MAX,
452                                   g_param_spec_int("max_characters",
453                                   "Maximum number of characters",
454                                   "Maximum number of characters "
455                                   "in search string",
456                                   0, MAX_SIZE,
457                                   0, G_PARAM_READWRITE |
458                                   G_PARAM_CONSTRUCT));
459   
460   g_object_class_install_property(object_class, PROP_HISTORY_LIMIT,
461                                   g_param_spec_int("history_limit",
462                                   "Maximum number of history items",
463                                   "Maximum number of history items "
464                                   "in search combobox",
465                                   0, G_MAXINT,
466                                   5, G_PARAM_READWRITE |
467                                   G_PARAM_CONSTRUCT));
468
469   /**
470    * HildonFindToolbar::search:
471    * @toolbar: the toolbar which received the signal
472    * 
473    * Gets emitted when the find button is pressed.
474    */ 
475   HildonFindToolbar_signal[SEARCH] = 
476                               g_signal_new(
477                               "search", HILDON_TYPE_FIND_TOOLBAR,
478                               G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
479                               (HildonFindToolbarClass, search),
480                               NULL, NULL, gtk_marshal_VOID__VOID,
481                               G_TYPE_NONE, 0);
482   
483   /**
484    * HildonFindToolbar::close:
485    * @toolbar: the toolbar which received the signal
486    * 
487    * Gets emitted when the close button is pressed.
488    */ 
489   HildonFindToolbar_signal[CLOSE] = 
490                              g_signal_new(
491                              "close", HILDON_TYPE_FIND_TOOLBAR,
492                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
493                              (HildonFindToolbarClass, close),
494                              NULL, NULL, gtk_marshal_VOID__VOID,
495                              G_TYPE_NONE, 0);
496   
497   /**
498    * HildonFindToolbar::invalid-input:
499    * @toolbar: the toolbar which received the signal
500    * 
501    * Gets emitted when the maximum search prefix length is reached and
502    * user tries to type more.
503    */ 
504   HildonFindToolbar_signal[INVALID_INPUT] = 
505                              g_signal_new(
506                              "invalid_input", HILDON_TYPE_FIND_TOOLBAR,
507                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
508                              (HildonFindToolbarClass, invalid_input),
509                              NULL, NULL, gtk_marshal_VOID__VOID,
510                              G_TYPE_NONE, 0);
511   
512   /**
513    * HildonFindToolbar::history-append:
514    * @toolbar: the toolbar which received the signal
515    * 
516    * Gets emitted when the current search prefix should be added to history.
517    */ 
518   HildonFindToolbar_signal[HISTORY_APPEND] = 
519                              g_signal_new(
520                              "history_append", HILDON_TYPE_FIND_TOOLBAR,
521                              G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET 
522                              (HildonFindToolbarClass, history_append),
523                              g_signal_accumulator_true_handled, NULL, 
524                              gtk_marshal_BOOLEAN__VOID,
525                              G_TYPE_BOOLEAN, 0);
526 }
527
528 static void
529 hildon_find_toolbar_init(HildonFindToolbar *self)
530 {
531   GtkToolItem *label_container;
532   GtkToolItem *entry_combo_box_container;
533   
534   self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
535                                            HILDON_TYPE_FIND_TOOLBAR, 
536                                            HildonFindToolbarPrivate);
537
538   /* Create the label */
539   self->priv->label = gtk_label_new(_("ecdg_ti_find_toolbar_label"));
540   
541   gtk_misc_set_padding (GTK_MISC(self->priv->label), FIND_LABEL_XPADDING,
542                         FIND_LABEL_YPADDING);
543
544   label_container = gtk_tool_item_new();
545   gtk_container_add(GTK_CONTAINER(label_container), 
546                     self->priv->label);
547   gtk_widget_show_all(GTK_WIDGET(label_container));
548   gtk_toolbar_insert (GTK_TOOLBAR(self), label_container, -1);
549   
550   /* ComboBoxEntry for search prefix string / history list */
551   self->priv->entry_combo_box = GTK_COMBO_BOX_ENTRY(gtk_combo_box_entry_new());
552   g_signal_connect(hildon_find_toolbar_get_entry(self->priv),
553                    "invalid_input", 
554                    G_CALLBACK(hildon_find_toolbar_emit_invalid_input), self);
555   entry_combo_box_container = gtk_tool_item_new();
556   gtk_tool_item_set_expand(entry_combo_box_container, TRUE);
557   gtk_container_add(GTK_CONTAINER(entry_combo_box_container),
558                     GTK_WIDGET(self->priv->entry_combo_box));
559   gtk_widget_show_all(GTK_WIDGET(entry_combo_box_container));
560   gtk_toolbar_insert (GTK_TOOLBAR(self), entry_combo_box_container, -1);
561   g_signal_connect(hildon_find_toolbar_get_entry(self->priv),
562                     "key-press-event",
563                     G_CALLBACK(hildon_find_toolbar_entry_key_press), self);
564
565   /* Find button */
566   self->priv->find_button = gtk_tool_button_new (
567                               gtk_image_new_from_icon_name ("qgn_toolb_browser_gobutton",
568                                                             HILDON_ICON_SIZE_TOOLBAR),
569                               "Find");
570   g_signal_connect(self->priv->find_button, "clicked",
571                    G_CALLBACK(hildon_find_toolbar_emit_search), self);
572   gtk_widget_show_all(GTK_WIDGET(self->priv->find_button));
573   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->find_button, -1);
574   if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(self->priv->find_button)->child) )
575       GTK_WIDGET_UNSET_FLAGS(
576               GTK_BIN(self->priv->find_button)->child, GTK_CAN_FOCUS);
577   
578   /* Separator */
579   self->priv->separator = gtk_separator_tool_item_new();
580   gtk_widget_show(GTK_WIDGET(self->priv->separator));
581   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->separator, -1);
582   
583   /* Close button */
584   self->priv->close_button = gtk_tool_button_new (
585                                gtk_image_new_from_icon_name ("qgn_toolb_gene_close",
586                                                              HILDON_ICON_SIZE_TOOLBAR),
587                                "Close");
588   g_signal_connect(self->priv->close_button, "clicked",
589                    G_CALLBACK(hildon_find_toolbar_emit_close), self);
590   gtk_widget_show_all(GTK_WIDGET(self->priv->close_button));
591   gtk_toolbar_insert (GTK_TOOLBAR(self), self->priv->close_button, -1);
592   if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(self->priv->close_button)->child) )
593       GTK_WIDGET_UNSET_FLAGS(
594               GTK_BIN(self->priv->close_button)->child, GTK_CAN_FOCUS);
595 }
596
597 /*Public functions*/
598
599 /**
600  * hildon_find_toolbar_new:
601  * @label: label for the find_toolbar, NULL to set the label to 
602  *         default "Find"
603  * 
604  * Returns a new HildonFindToolbar.
605  *
606  * Returns: a new HildonFindToolbar
607  */
608
609 GtkWidget *
610 hildon_find_toolbar_new(const gchar *label)
611 {
612   GtkWidget *findtoolbar;
613   
614   findtoolbar = GTK_WIDGET(g_object_new(HILDON_TYPE_FIND_TOOLBAR, NULL));
615   if(label != NULL)
616     g_object_set(findtoolbar, "label", label, NULL);
617
618   return findtoolbar;
619 }
620
621 /**
622  * hildon_find_toolbar_new_with_model
623  * @label: label for the find_toolbar, NULL to set the label to 
624  *         default "Find"
625  * @model: a @GtkListStore
626  * @column: indicating which column the search histry list will 
627  *          retreive string from
628  * 
629  * Returns a new HildonFindToolbar, with a model.
630  *
631  * Returns: a new #HildonFindToolbar
632  */
633 GtkWidget *
634 hildon_find_toolbar_new_with_model(const gchar *label,
635                                    GtkListStore *model,
636                                    gint column)
637 {
638   GtkWidget *findtoolbar;
639
640   findtoolbar = hildon_find_toolbar_new(label);
641   g_object_set(findtoolbar, "list", model,
642                "column", column, NULL);
643
644   return findtoolbar;
645 }
646
647 /**
648  * hildon_find_toolbar_highlight_entry
649  * @ftb: find Toolbar whose entry is to be highlighted
650  * @get_focus: if user passes TRUE to this value, then the text in
651  * the entry will not only get highlighted, but also get focused.
652  * 
653  */
654 void
655 hildon_find_toolbar_highlight_entry(HildonFindToolbar *ftb,
656                                     gboolean get_focus)
657 {
658   GtkEntry *entry = NULL;
659   
660   g_return_if_fail(HILDON_IS_FIND_TOOLBAR(ftb));
661   
662   entry = hildon_find_toolbar_get_entry(ftb->priv);
663   
664   gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
665   
666   if(get_focus)
667     gtk_widget_grab_focus(GTK_WIDGET(entry));
668 }