1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
/*
* This file is a part of hildon
*
* Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
*
* 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, 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**
* SECTION:hildon-find-toolbar
* @short_description: A toolbar with a search field.
* @see_also: #HildonWindow
*
* 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>
#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("hildon-libs", String)
/* Same define as gtkentry.c as entry will further handle this */
#define MAX_SIZE G_MAXUSHORT
#define FIND_LABEL_XPADDING 6
#define FIND_LABEL_YPADDING 0
static GtkTreeModel*
hildon_find_toolbar_get_list_model (HildonFindToolbarPrivate *priv);
static GtkEntry*
hildon_find_toolbar_get_entry (HildonFindToolbarPrivate *priv);
static gboolean
hildon_find_toolbar_filter (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer self);
static void
hildon_find_toolbar_apply_filter (HildonFindToolbar *self,
GtkTreeModel *model);
static void
hildon_find_toolbar_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void
hildon_find_toolbar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static gboolean
hildon_find_toolbar_find_string (HildonFindToolbar *self,
GtkTreeIter *iter,
gint column,
const gchar *string);
static gboolean
hildon_find_toolbar_history_append (HildonFindToolbar *self,
gpointer data);
static void
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,
gpointer user_data);
static void
hildon_find_toolbar_class_init (HildonFindToolbarClass *klass);
static void
hildon_find_toolbar_init (HildonFindToolbar *self);
enum
{
SEARCH = 0,
CLOSE,
INVALID_INPUT,
HISTORY_APPEND,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_LABEL = 1,
PROP_PREFIX,
PROP_LIST,
PROP_COLUMN,
PROP_MAX,
PROP_HISTORY_LIMIT
};
static guint HildonFindToolbar_signal [LAST_SIGNAL] = {0};
/**
* hildon_find_toolbar_get_type:
*
* Initializes and returns the type of a #HildonFindToolbar.
*
* Returns: GType of #HildonFindToolbar
*/
GType G_GNUC_CONST
hildon_find_toolbar_get_type (void)
{
static GType find_toolbar_type = 0;
if (! find_toolbar_type) {
static const GTypeInfo find_toolbar_info = {
sizeof(HildonFindToolbarClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) hildon_find_toolbar_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(HildonFindToolbar),
0, /* n_preallocs */
(GInstanceInitFunc) hildon_find_toolbar_init,
};
find_toolbar_type = g_type_register_static (GTK_TYPE_TOOLBAR,
"HildonFindToolbar",
&find_toolbar_info, 0);
}
return find_toolbar_type;
}
static GtkTreeModel*
hildon_find_toolbar_get_list_model (HildonFindToolbarPrivate *priv)
{
GtkTreeModel *filter_model =
gtk_combo_box_get_model (GTK_COMBO_BOX (priv->entry_combo_box));
return filter_model == NULL ? NULL :
gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
}
static GtkEntry*
hildon_find_toolbar_get_entry (HildonFindToolbarPrivate *priv)
{
return GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->entry_combo_box)));
}
static gboolean
hildon_find_toolbar_filter (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer self)
{
GtkTreePath *path;
const gint *indices;
gint n;
gint limit;
gint total;
total = gtk_tree_model_iter_n_children (model, NULL);
g_object_get (self, "history_limit", &limit, NULL);
path = gtk_tree_model_get_path (model, iter);
indices = gtk_tree_path_get_indices (path);
/* set the row's index, list store has only one level */
n = indices [0];
gtk_tree_path_free (path);
/*if the row is among the latest "history_limit" additions of the
* model, then we show it */
if( (total - limit <= n) && (n < total) )
return TRUE;
else
return FALSE;
}
static void
hildon_find_toolbar_apply_filter (HildonFindToolbar *self,
GtkTreeModel *model)
{
GtkTreeModel *filter;
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
/* Create a filter for the given model. Its only purpose is to hide
the oldest entries so only "history_limit" entries are visible. */
filter = gtk_tree_model_filter_new (model, NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER(filter),
hildon_find_toolbar_filter,
self, NULL);
gtk_combo_box_set_model (GTK_COMBO_BOX (priv->entry_combo_box), filter);
/* ComboBox keeps the only needed reference to the filter */
g_object_unref (filter);
}
static void
hildon_find_toolbar_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
g_assert (priv);
const gchar *string;
gint c_n, max_len;
switch (prop_id)
{
case PROP_LABEL:
string = gtk_label_get_text (GTK_LABEL (priv->label));
g_value_set_string (value, string);
break;
case PROP_PREFIX:
string = gtk_entry_get_text (hildon_find_toolbar_get_entry(priv));
g_value_set_string (value, string);
break;
case PROP_LIST:
g_value_set_object (value, hildon_find_toolbar_get_list_model(priv));
break;
case PROP_COLUMN:
c_n = gtk_combo_box_entry_get_text_column (priv->entry_combo_box);
g_value_set_int (value, c_n);
break;
case PROP_MAX:
max_len = gtk_entry_get_max_length (hildon_find_toolbar_get_entry(priv));
g_value_set_int (value, max_len);
break;
case PROP_HISTORY_LIMIT:
g_value_set_int (value, priv->history_limit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
hildon_find_toolbar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
HildonFindToolbar *self = HILDON_FIND_TOOLBAR(object);
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (object);
g_assert (priv);
GtkTreeModel *model;
const gchar *string;
switch (prop_id)
{
case PROP_LABEL:
string = g_value_get_string (value);
gtk_label_set_text (GTK_LABEL (priv->label), string);
break;
case PROP_PREFIX:
string = g_value_get_string (value);
gtk_entry_set_text (hildon_find_toolbar_get_entry(priv), string);
break;
case PROP_LIST:
model = GTK_TREE_MODEL (g_value_get_object(value));
hildon_find_toolbar_apply_filter (self, model);
break;
case PROP_COLUMN:
gtk_combo_box_entry_set_text_column (priv->entry_combo_box,
g_value_get_int (value));
break;
case PROP_MAX:
gtk_entry_set_max_length (hildon_find_toolbar_get_entry(priv),
g_value_get_int (value));
break;
case PROP_HISTORY_LIMIT:
priv->history_limit = g_value_get_int (value);
/* Re-apply the history limit to the model. */
model = hildon_find_toolbar_get_list_model (priv);
if (model != NULL)
{
/* Note that refilter function doesn't update the status of the
combobox popup arrow, so we'll just recreate the filter. */
hildon_find_toolbar_apply_filter (self, model);
if (gtk_combo_box_entry_get_text_column (priv->entry_combo_box) == -1)
{
/* FIXME: This is only for backwards compatibility, although
probably nothing actually relies on it. The behavior was only
an accidental side effect of original code */
gtk_combo_box_entry_set_text_column (priv->entry_combo_box, 0);
}
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
hildon_find_toolbar_find_string (HildonFindToolbar *self,
GtkTreeIter *iter,
gint column,
const gchar *string)
{
GtkTreeModel *model = NULL;
gchar *old_string;
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
model = hildon_find_toolbar_get_list_model (priv);
if (gtk_tree_model_get_iter_first (model, iter))
{
do {
gtk_tree_model_get (model, iter, column, &old_string, -1);
if (old_string != NULL && strcmp (string, old_string) == 0)
{
/* Found it */
return TRUE;
}
} while (gtk_tree_model_iter_next (model, iter));
}
return FALSE;
}
static gboolean
hildon_find_toolbar_history_append (HildonFindToolbar *self,
gpointer data)
{
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
gchar *string;
gint column = 0;
GtkTreeModel *model = NULL;
GtkListStore *list = NULL;
GtkTreeIter iter;
gboolean self_create = FALSE;
g_object_get (self, "prefix", &string, NULL);
if (*string == '\0')
{
/* empty prefix, ignore */
g_free (string);
return TRUE;
}
/* If list store is set, get it */
model = hildon_find_toolbar_get_list_model(priv);
if(model != NULL)
{
list = GTK_LIST_STORE (model);
g_object_get(self, "column", &column, NULL);
if (column < 0)
{
/* Column number is -1 if "column" property hasn't been set but
"list" property is. */
g_free (string);
return TRUE;
}
/* Latest string is always the first one in list. If the string
already exists, remove it so there are no duplicates in list. */
if (hildon_find_toolbar_find_string (self, &iter, column, string))
gtk_list_store_remove (list, &iter);
}
else
{
/* No list store set. Create our own. */
list = gtk_list_store_new (1, G_TYPE_STRING);
model = GTK_TREE_MODEL (list);
self_create = TRUE;
}
/* Add the string to first in list */
gtk_list_store_append (list, &iter);
gtk_list_store_set (list, &iter, column, string, -1);
if(self_create)
{
/* Add the created list to ComboBoxEntry */
hildon_find_toolbar_apply_filter (self, model);
/* ComboBoxEntry keeps the only needed reference to this list */
g_object_unref (list);
/* Set the column only after ComboBoxEntry's model is set
in hildon_find_toolbar_apply_filter() */
g_object_set (self, "column", 0, NULL);
}
else
{
/* Refilter to get the oldest entry hidden from history */
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(
gtk_combo_box_get_model (GTK_COMBO_BOX(priv->entry_combo_box))));
}
g_free (string);
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);
GtkWidget *entry = gtk_bin_get_child (GTK_BIN (priv->entry_combo_box));
if (GTK_WIDGET_HAS_FOCUS (entry))
{
hildon_gtk_im_context_hide (GTK_ENTRY (entry)->im_context);
}
#endif
/* Clicked close button */
g_signal_emit (self, HildonFindToolbar_signal [CLOSE], 0);
}
#ifdef MAEMO_GTK
static void
hildon_find_toolbar_emit_invalid_input (GtkEntry *entry,
GtkInvalidInputType type,
gpointer self)
{
if(type == GTK_INVALID_INPUT_MAX_CHARS_REACHED)
g_signal_emit (self, HildonFindToolbar_signal [INVALID_INPUT], 0);
}
#endif
static void
hildon_find_toolbar_entry_activate (GtkWidget *widget,
gpointer user_data)
{
GtkWidget *find_toolbar = GTK_WIDGET (user_data);
gboolean rb;
/* NB#40936 stop focus from moving to next widget */
g_signal_stop_emission_by_name (widget, "activate");
g_signal_emit (find_toolbar, HildonFindToolbar_signal [SEARCH], 0);
g_signal_emit (find_toolbar, HildonFindToolbar_signal [HISTORY_APPEND], 0, &rb);
}
static void
hildon_find_toolbar_class_init (HildonFindToolbarClass *klass)
{
GObjectClass *object_class;
g_type_class_add_private (klass, sizeof (HildonFindToolbarPrivate));
object_class = G_OBJECT_CLASS(klass);
object_class->get_property = hildon_find_toolbar_get_property;
object_class->set_property = hildon_find_toolbar_set_property;
klass->history_append = (gpointer) hildon_find_toolbar_history_append;
/**
* 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));
/**
* HildonFindToolbar:prefix:
*
* The search string.
*
*/
g_object_class_install_property (object_class, PROP_PREFIX,
g_param_spec_string ("prefix",
"Prefix", "Search string", NULL,
G_PARAM_READWRITE));
/**
* 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",
"Column", "Column number in GtkListStore "
"where history list strings are kept",
0, G_MAXINT,
0, G_PARAM_READWRITE));
/**
* HildonFindToolbar:max-characters:
*
* Maximum number of characters in search string.
*
*/
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, MAX_SIZE,
0, G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
/**
* 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",
0, G_MAXINT,
5, G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
/**
* HildonFindToolbar::search:
* @toolbar: the toolbar which received the signal
*
* Gets emitted when the find button is pressed.
*/
HildonFindToolbar_signal[SEARCH] =
g_signal_new(
"search", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, search),
NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* HildonFindToolbar::close:
* @toolbar: the toolbar which received the signal
*
* Gets emitted when the close button is pressed.
*/
HildonFindToolbar_signal[CLOSE] =
g_signal_new(
"close", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, close),
NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* HildonFindToolbar::invalid-input:
* @toolbar: the toolbar which received the signal
*
* 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, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* HildonFindToolbar::history-append:
* @toolbar: the toolbar which received the signal
*
* Gets emitted when the current search prefix should be added to history.
*/
HildonFindToolbar_signal[HISTORY_APPEND] =
g_signal_new(
"history_append", HILDON_TYPE_FIND_TOOLBAR,
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET
(HildonFindToolbarClass, history_append),
g_signal_accumulator_true_handled, NULL,
_hildon_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
}
static void
hildon_find_toolbar_init (HildonFindToolbar *self)
{
GtkToolItem *label_container;
GtkToolItem *entry_combo_box_container;
GtkAlignment *alignment;
HildonFindToolbarPrivate *priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
/* Create the label */
priv->label = gtk_label_new (_("ecdg_ti_find_toolbar_label"));
gtk_misc_set_padding (GTK_MISC (priv->label), FIND_LABEL_XPADDING,
FIND_LABEL_YPADDING);
label_container = gtk_tool_item_new ();
gtk_container_add (GTK_CONTAINER (label_container),
priv->label);
gtk_widget_show_all (GTK_WIDGET (label_container));
gtk_toolbar_insert (GTK_TOOLBAR (self), label_container, -1);
/* 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 (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),
"activate",
G_CALLBACK(hildon_find_toolbar_entry_activate), self);
/* Separator */
priv->separator = gtk_separator_tool_item_new();
gtk_widget_set_size_request (GTK_WIDGET (priv->separator), 72, -1);
gtk_widget_show(GTK_WIDGET(priv->separator));
gtk_toolbar_insert (GTK_TOOLBAR(self), priv->separator, -1);
/* Close button */
priv->close_button = gtk_tool_button_new (
gtk_image_new_from_icon_name ("general_close",
HILDON_ICON_SIZE_TOOLBAR),
"Close");
g_signal_connect(priv->close_button, "clicked",
G_CALLBACK(hildon_find_toolbar_emit_close), self);
gtk_widget_show_all(GTK_WIDGET(priv->close_button));
gtk_toolbar_insert (GTK_TOOLBAR(self), priv->close_button, -1);
if ( GTK_WIDGET_CAN_FOCUS( GTK_BIN(priv->close_button)->child) )
GTK_WIDGET_UNSET_FLAGS(
GTK_BIN(priv->close_button)->child, GTK_CAN_FOCUS);
}
/**
* hildon_find_toolbar_new:
* @label: label for the #HildonFindToolbar, %NULL to set the label to
* default "Find".
*
* Creates a new #HildonFindToolbar.
*
* Returns: a new #HildonFindToolbar.
*/
GtkWidget*
hildon_find_toolbar_new (const gchar *label)
{
GtkWidget *findtoolbar;
findtoolbar = GTK_WIDGET (g_object_new (HILDON_TYPE_FIND_TOOLBAR, NULL));
if (label != NULL)
g_object_set(findtoolbar, "label", label, NULL);
return findtoolbar;
}
/**
* hildon_find_toolbar_new_with_model:
* @label: label for the #HildonFindToolbar, %NULL to set the label to
* default "Find".
* @model: a #GtkListStore.
* @column: indicates which column the search history list will
* retrieve the string from.
*
* Creates a new #HildonFindToolbar with an initial #GtkTreeModel.
*
* Returns: a new #HildonFindToolbar.
*/
GtkWidget*
hildon_find_toolbar_new_with_model (const gchar *label,
GtkListStore *model,
gint column)
{
GtkWidget *findtoolbar;
findtoolbar = hildon_find_toolbar_new (label);
g_object_set (findtoolbar, "list", model, "column", column, NULL);
return findtoolbar;
}
/**
* hildon_find_toolbar_highlight_entry:
* @ftb: #HildonFindToolbar 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 #HildonFindToolbar.
*
*/
void
hildon_find_toolbar_highlight_entry (HildonFindToolbar *self,
gboolean get_focus)
{
GtkEntry *entry = NULL;
HildonFindToolbarPrivate *priv;
g_return_if_fail (HILDON_IS_FIND_TOOLBAR (self));
priv = HILDON_FIND_TOOLBAR_GET_PRIVATE (self);
g_assert (priv);
entry = hildon_find_toolbar_get_entry (priv);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
if (get_focus)
gtk_widget_grab_focus (GTK_WIDGET (entry));
}
/**
* hildon_find_toolbar_set_active:
* @toolbar: A #HildonFindToolbar to operate on.
* @index: An index in the model, or -1 to have no active item.
*
* Sets the active item on the #HildonFindToolbar's #GtkComboBox. Simply calls
* gtk_combo_box_set_active() on the #HildonFindToolbar's #GtkComboBox.
*
*/
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 #HildonFindToolbar 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
* #GtkComboBox.
*
* Returns: the index of the currently active item, or -1 if there is 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 #HildonFindToolbar to operate on.
* @iter: A #GtkTreeIter to activate.
*
* Sets the current active item to be the one referenced by @iter. Simply calls
* gtk_combo_box_set_active_iter() on the #HildonFindToolbar's #GtkComboBox.
*
*/
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 #HildonFindToolbar 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 #GtkComboBox.
*
* 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 #HildonFindToolbar to query.
*
* Returns the index of the last (most recently added) item in the
* #HildonFindToolbar. Can be used to set this item active in the
* #HildonFindToolbar::history-append signal.
*
*
* Returns: Index of the most recent 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;
}
|