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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* e-search-bar.c
*
* Copyright (C) 2000, 2001 Ximian, Inc.
*
* Authors:
* Chris Lahey <clahey@ximian.com>
* Ettore Perazzoli <ettore@ximian.com>
* Jon Trowbridge <trow@ximian.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkeventbox.h>
#include <gtk/gtkmenuitem.h>
#include <gtk/gtkoptionmenu.h>
#include <gtk/gtkmain.h>
#include <gal/widgets/e-unicode.h>
#include <gal/widgets/e-gui-utils.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include "e-search-bar.h"
#include "e-dropdown-button.h"
enum {
QUERY_CHANGED,
MENU_ACTIVATED,
LAST_SIGNAL
};
static gint esb_signals [LAST_SIGNAL] = { 0, };
static GtkHBoxClass *parent_class = NULL;
/* The arguments we take */
enum {
ARG_0,
ARG_OPTION_CHOICE,
ARG_SUBOPTION_CHOICE,
ARG_TEXT,
};
/* Signals. */
static void
emit_query_changed (ESearchBar *esb)
{
if (esb->pending_change) {
gtk_idle_remove (esb->pending_change);
esb->pending_change = 0;
}
gtk_signal_emit (GTK_OBJECT (esb),
esb_signals [QUERY_CHANGED]);
}
static void
emit_menu_activated (ESearchBar *esb, int item)
{
gtk_signal_emit (GTK_OBJECT (esb),
esb_signals [MENU_ACTIVATED],
item);
}
/* Callbacks. */
static void
menubar_activated_cb (GtkWidget *widget, ESearchBar *esb)
{
int id;
id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), "EsbMenuId"));
emit_menu_activated (esb, id);
}
static void
entry_activated_cb (GtkWidget *widget,
ESearchBar *esb)
{
emit_query_changed (esb);
}
static void
subitem_activated_cb (GtkWidget *widget, ESearchBar *esb)
{
gint id, subid;
id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), "EsbItemId"));
subid = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), "EsbSubitemId"));
esb->option_choice = id;
esb->suboption_choice = subid;
emit_query_changed (esb);
}
static void
activate_by_subitems (ESearchBar *esb, gint item_id, ESearchBarSubitem *subitems)
{
if (subitems == NULL) {
/* This item uses the entry. */
if (esb->entry == NULL) {
esb->entry = gtk_entry_new();
gtk_object_ref (GTK_OBJECT (esb->entry));
gtk_signal_connect (GTK_OBJECT (esb->entry), "activate",
GTK_SIGNAL_FUNC (entry_activated_cb), esb);
gtk_widget_show(esb->entry);
esb->suboption_choice = 0;
}
if (esb->suboption_choice >= 0) {
if (esb->suboption != NULL) {
gtk_container_remove (GTK_CONTAINER (esb->entry_box), esb->suboption);
}
gtk_container_add (GTK_CONTAINER (esb->entry_box), esb->entry);
}
gtk_entry_set_text (GTK_ENTRY (esb->entry), "");
esb->suboption_choice = -1;
} else {
GtkWidget *menu;
GtkWidget *menu_item;
gint i;
if (esb->suboption == NULL) {
esb->suboption = gtk_option_menu_new ();
gtk_object_ref (GTK_OBJECT (esb->suboption));
gtk_widget_show (esb->suboption);
}
esb->suboption_menu = menu = gtk_menu_new ();
for (i = 0; subitems[i].id != -1; ++i) {
menu_item = gtk_menu_item_new_with_label (_(subitems[i].text));
gtk_object_set_data (GTK_OBJECT (menu_item), "EsbItemId", GINT_TO_POINTER (item_id));
gtk_object_set_data (GTK_OBJECT (menu_item), "EsbSubitemId", GINT_TO_POINTER (subitems[i].id));
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (subitem_activated_cb),
esb);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (menu), menu_item);
}
gtk_option_menu_remove_menu (GTK_OPTION_MENU (esb->suboption));
gtk_option_menu_set_menu (GTK_OPTION_MENU (esb->suboption), menu);
if (esb->entry != NULL) {
gtk_container_remove (GTK_CONTAINER (esb->entry_box), esb->entry);
}
gtk_container_add (GTK_CONTAINER (esb->entry_box), esb->suboption);
esb->suboption_choice = 0;
}
if (esb->activate_button) {
gtk_widget_set_sensitive (esb->activate_button, subitems == NULL);
}
}
static void
option_activated_cb (GtkWidget *widget,
ESearchBar *esb)
{
int id;
id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), "EsbChoiceId"));
activate_by_subitems (esb, id, gtk_object_get_data (GTK_OBJECT (widget), "EsbChoiceSubitems"));
esb->option_choice = id;
emit_query_changed (esb);
}
static void
activate_button_clicked_cb (GtkWidget *widget, ESearchBar *esb)
{
emit_query_changed (esb);
}
/* Widgetry creation. */
/* This function exists to fix the irreparable GtkOptionMenu stupidity. In
fact, this lame-ass widget adds a 1-pixel-wide empty border around the
button for no reason. So we have add a 1-pixel-wide border around the the
buttons we have in the search bar to make things look right. This is done
through an event box. */
static GtkWidget *
put_in_spacer_widget (GtkWidget *widget)
{
GtkWidget *holder;
holder = gtk_event_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (holder), 1);
gtk_container_add (GTK_CONTAINER (holder), widget);
return holder;
}
static ESearchBarSubitem *
copy_subitems (ESearchBarSubitem *subitems)
{
gint i, N;
ESearchBarSubitem *copy;
if (subitems == NULL)
return NULL;
for (N=0; subitems[N].id != -1; ++N);
copy = g_new (ESearchBarSubitem, N+1);
for (i=0; i<N; ++i) {
copy[i].text = g_strdup (subitems[i].text);
copy[i].id = subitems[i].id;
}
copy[N].text = NULL;
copy[N].id = -1;
return copy;
}
static void
free_subitems (ESearchBarSubitem *subitems)
{
gint i;
if (subitems != NULL) {
for (i=0; subitems[i].id != -1; ++i) {
g_free (subitems[i].text);
}
g_free (subitems);
}
}
static void
add_dropdown (ESearchBar *esb, ESearchBarItem *items)
{
GtkWidget *menu = esb->dropdown_menu;
GtkWidget *item;
if (items->text) {
char *str;
str = _(items->text);
if (str == items->text) {
/* It may be english string, or utf8 rule name */
item = e_utf8_gtk_menu_item_new_with_label (GTK_MENU (menu), str);
} else
item = gtk_menu_item_new_with_label (str);
}
else
item = gtk_menu_item_new();
gtk_widget_show (item);
gtk_menu_append (GTK_MENU (menu), item);
gtk_object_set_data (GTK_OBJECT (item), "EsbMenuId", GINT_TO_POINTER (items->id));
gtk_signal_connect (GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (menubar_activated_cb),
esb);
}
static void
set_dropdown (ESearchBar *esb,
ESearchBarItem *items)
{
GtkWidget *menu;
GtkWidget *dropdown;
int i;
menu = esb->dropdown_menu = gtk_menu_new ();
for (i = 0; items[i].id != -1; i++)
add_dropdown (esb, items + i);
gtk_widget_show_all (menu);
dropdown = e_dropdown_button_new (_("Sear_ch"), GTK_MENU (menu));
gtk_widget_show (dropdown);
if (esb->dropdown_holder == NULL) {
/* See the comment in `put_in_spacer_widget()' to understand
why we have to do this. */
esb->dropdown_holder = put_in_spacer_widget (dropdown);
esb->dropdown = dropdown;
gtk_widget_show (esb->dropdown_holder);
gtk_box_pack_start (GTK_BOX (esb), esb->dropdown_holder, FALSE, FALSE, 0);
} else {
gtk_widget_destroy (esb->dropdown);
esb->dropdown = dropdown;
gtk_container_add (GTK_CONTAINER (esb->dropdown_holder), esb->dropdown);
}
}
static void
set_option (ESearchBar *esb, ESearchBarItem *items)
{
GtkWidget *menu;
GtkRequisition dropdown_requisition;
GtkRequisition option_requisition;
int i;
if (esb->option) {
gtk_widget_destroy (esb->option_menu);
} else {
esb->option = gtk_option_menu_new ();
gtk_widget_show (esb->option);
gtk_box_pack_start (GTK_BOX (esb), esb->option, FALSE, FALSE, 0);
}
esb->option_menu = menu = gtk_menu_new ();
for (i = 0; items[i].id != -1; i++) {
GtkWidget *item;
ESearchBarSubitem *subitems = NULL;
if (items[i].text) {
char *str;
str = _(items[i].text);
if (str == items[i].text) {
/* It may be english string, or utf8 rule name */
item = e_utf8_gtk_menu_item_new_with_label (GTK_MENU (menu), str);
} else
item = gtk_menu_item_new_with_label (str);
}
else
item = gtk_menu_item_new ();
gtk_menu_append (GTK_MENU (menu), item);
gtk_object_set_data (GTK_OBJECT (item), "EsbChoiceId", GINT_TO_POINTER(items[i].id));
if (items[i].subitems != NULL) {
subitems = copy_subitems (items[i].subitems);
esb->subitem_garbage = g_list_prepend (esb->subitem_garbage, subitems);
}
gtk_object_set_data (GTK_OBJECT (item), "EsbChoiceSubitems", subitems);
if (i == 0) {
activate_by_subitems (esb, items[i].id, subitems);
}
gtk_signal_connect (GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (option_activated_cb),
esb);
}
gtk_widget_show_all (menu);
gtk_option_menu_set_menu (GTK_OPTION_MENU (esb->option), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (esb->option), 0);
gtk_widget_set_sensitive (esb->option, TRUE);
/* Set the minimum height of this widget to that of the dropdown
button, for a better look. */
g_assert (esb->dropdown != NULL);
gtk_widget_size_request (esb->dropdown, &dropdown_requisition);
gtk_widget_size_request (esb->option, &option_requisition);
gtk_container_set_border_width (GTK_CONTAINER (esb->dropdown), GTK_CONTAINER (esb->option)->border_width);
}
static void
add_activate_button (ESearchBar *esb)
{
GtkWidget *label;
GtkWidget *holder;
label = gtk_label_new (_("Find Now"));
gtk_widget_show (label);
/* See the comment in `put_in_spacer_widget()' to understand
why we have to do this. */
esb->activate_button = gtk_button_new ();
gtk_widget_show (esb->activate_button);
gtk_container_add (GTK_CONTAINER (esb->activate_button), label);
holder = put_in_spacer_widget (esb->activate_button);
gtk_widget_show (holder);
gtk_signal_connect (GTK_OBJECT (esb->activate_button), "clicked",
GTK_SIGNAL_FUNC (activate_button_clicked_cb), esb);
gtk_box_pack_start (GTK_BOX (esb), holder, FALSE, FALSE, 0);
}
static int
find_id (GtkWidget *menu, int idin, const char *type, GtkWidget **widget)
{
GList *l = GTK_MENU_SHELL (menu)->children;
int row = -1, i = 0, id;
if (widget)
*widget = NULL;
while (l) {
id = GPOINTER_TO_INT (gtk_object_get_data (l->data, type));
if (id == idin) {
row = i;
if (widget)
*widget = l->data;
break;
}
i++;
l = l->next;
}
return row;
}
/* GtkObject methods. */
static void
impl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESearchBar *esb = E_SEARCH_BAR (object);
switch (arg_id) {
case ARG_OPTION_CHOICE:
GTK_VALUE_ENUM (*arg) = e_search_bar_get_option_choice (esb);
break;
case ARG_SUBOPTION_CHOICE:
GTK_VALUE_ENUM (*arg) = e_search_bar_get_suboption_choice (esb);
break;
case ARG_TEXT:
GTK_VALUE_STRING (*arg) = e_search_bar_get_text (esb);
break;
default:
arg->type = GTK_TYPE_INVALID;
break;
}
}
static void
impl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESearchBar *esb = E_SEARCH_BAR(object);
int row;
switch (arg_id) {
case ARG_OPTION_CHOICE:
esb->option_choice = GTK_VALUE_ENUM(*arg);
row = find_id (esb->option_menu, esb->option_choice, "EsbChoiceId", NULL);
if (row == -1)
row = 0;
gtk_option_menu_set_history (GTK_OPTION_MENU (esb->option), row);
emit_query_changed (esb);
break;
case ARG_SUBOPTION_CHOICE:
esb->suboption_choice = GTK_VALUE_ENUM (*arg);
row = find_id (esb->suboption_menu, esb->suboption_choice, "EsbSubitemId", NULL);
if (row == -1)
row = 0;
gtk_option_menu_set_history (GTK_OPTION_MENU (esb->suboption), row);
emit_query_changed (esb);
break;
case ARG_TEXT:
e_utf8_gtk_editable_set_text (GTK_EDITABLE (esb->entry), GTK_VALUE_STRING (*arg));
emit_query_changed (esb);
break;
default:
break;
}
}
static void
impl_destroy (GtkObject *object)
{
ESearchBar *esb = E_SEARCH_BAR (object);
g_return_if_fail (object != NULL);
g_return_if_fail (E_IS_SEARCH_BAR (object));
/* These two we do need to unref, because we explicitly hold
references to them. */
if (esb->entry)
gtk_object_unref (GTK_OBJECT (esb->entry));
if (esb->suboption)
gtk_object_unref (GTK_OBJECT (esb->suboption));
g_list_foreach (esb->subitem_garbage, (GFunc) free_subitems, NULL);
g_list_free (esb->subitem_garbage);
if (esb->pending_change) {
gtk_idle_remove (esb->pending_change);
esb->pending_change = 0;
}
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
class_init (ESearchBarClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
parent_class = gtk_type_class (gtk_hbox_get_type ());
object_class->set_arg = impl_set_arg;
object_class->get_arg = impl_get_arg;
object_class->destroy = impl_destroy;
klass->set_menu = set_dropdown;
klass->set_option = set_option;
gtk_object_add_arg_type ("ESearchBar::option_choice", GTK_TYPE_ENUM,
GTK_ARG_READWRITE, ARG_OPTION_CHOICE);
gtk_object_add_arg_type ("ESearchBar::suboption_choice", GTK_TYPE_ENUM,
GTK_ARG_READWRITE, ARG_SUBOPTION_CHOICE);
gtk_object_add_arg_type ("ESearchBar::text", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_TEXT);
esb_signals [QUERY_CHANGED] =
gtk_signal_new ("query_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ESearchBarClass, query_changed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
esb_signals [MENU_ACTIVATED] =
gtk_signal_new ("menu_activated",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ESearchBarClass, menu_activated),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, esb_signals, LAST_SIGNAL);
}
static void
init (ESearchBar *esb)
{
esb->dropdown = NULL;
esb->option = NULL;
esb->entry = NULL;
esb->option_choice = 0;
esb->suboption_choice = 0;
}
/* Object construction. */
static gint
idle_change_hack (gpointer ptr)
{
ESearchBar *esb = E_SEARCH_BAR (ptr);
esb->pending_change = 0;
emit_query_changed (esb);
return FALSE;
}
void
e_search_bar_construct (ESearchBar *search_bar,
ESearchBarItem *menu_items,
ESearchBarItem *option_items)
{
g_return_if_fail (search_bar != NULL);
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (menu_items != NULL);
g_return_if_fail (option_items != NULL);
gtk_box_set_spacing (GTK_BOX (search_bar), 1);
e_search_bar_set_menu (search_bar, menu_items);
search_bar->entry_box = gtk_hbox_new (0, FALSE);
e_search_bar_set_option (search_bar, option_items);
gtk_widget_show (search_bar->entry_box);
gtk_box_pack_start (GTK_BOX(search_bar), search_bar->entry_box, TRUE, TRUE, 0);
add_activate_button (search_bar);
/*
* If the default choice for the option menu has subitems, then we need to
* activate the search immediately. However, the developer won't have
* connected to the changed signal until after the object is constructed,
* so we can't emit here. Thus we launch a one-shot idle function that will
* emit the changed signal, so that the proper callback will get invoked.
*/
if (search_bar->suboption_choice >= 0) {
gtk_widget_set_sensitive (search_bar->activate_button, FALSE);
search_bar->pending_change = gtk_idle_add (idle_change_hack, search_bar);
}
}
void
e_search_bar_set_menu (ESearchBar *search_bar, ESearchBarItem *menu_items)
{
g_return_if_fail (search_bar != NULL);
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (menu_items != NULL);
((ESearchBarClass *)((GtkObject *)search_bar)->klass)->set_menu (search_bar, menu_items);
}
void
e_search_bar_add_menu (ESearchBar *search_bar, ESearchBarItem *menu_item)
{
g_return_if_fail (search_bar != NULL);
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (menu_item != NULL);
add_dropdown (search_bar, menu_item);
}
void
e_search_bar_set_option (ESearchBar *search_bar, ESearchBarItem *option_items)
{
g_return_if_fail (search_bar != NULL);
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (option_items != NULL);
((ESearchBarClass *)((GtkObject *)search_bar)->klass)->set_option (search_bar, option_items);
}
GtkWidget *
e_search_bar_new (ESearchBarItem *menu_items,
ESearchBarItem *option_items)
{
GtkWidget *widget;
g_return_val_if_fail (menu_items != NULL, NULL);
g_return_val_if_fail (option_items != NULL, NULL);
widget = GTK_WIDGET (gtk_type_new (e_search_bar_get_type ()));
e_search_bar_construct (E_SEARCH_BAR (widget), menu_items, option_items);
return widget;
}
void
e_search_bar_set_menu_sensitive (ESearchBar *esb, int id, gboolean state)
{
int row;
GtkWidget *widget;
row = find_id (esb->dropdown_menu, id, "EsbMenuId", &widget);
if (row != -1)
gtk_widget_set_sensitive (widget, state);
}
GtkType
e_search_bar_get_type (void)
{
static GtkType type = 0;
if (!type) {
static const GtkTypeInfo info = {
"ESearchBar",
sizeof (ESearchBar),
sizeof (ESearchBarClass),
(GtkClassInitFunc) class_init,
(GtkObjectInitFunc) init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
type = gtk_type_unique (gtk_hbox_get_type (), &info);
}
return type;
}
/**
* e_search_bar_get_option_choice:
* @search_bar: A search bar.
*
* Queries the currently selected item in the options menu of a search bar.
*
* Return value: Identifier of the selected item in the options menu.
**/
int
e_search_bar_get_option_choice (ESearchBar *search_bar)
{
g_return_val_if_fail (search_bar != NULL, -1);
g_return_val_if_fail (E_IS_SEARCH_BAR (search_bar), -1);
return search_bar->option_choice;
}
/**
* e_search_bar_get_suboption_choice:
* @search_bar: A search bar.
*
* Queries the currently selected item in the suboptions menu of a search bar.
*
* Return value: Identifier of the selected item in the suboptions menu.
* If the search bar currently contains an entry rather than a a suboption menu,
* a value less than zero is returned.
**/
int
e_search_bar_get_suboption_choice (ESearchBar *search_bar)
{
g_return_val_if_fail (search_bar != NULL, -1);
g_return_val_if_fail (E_IS_SEARCH_BAR (search_bar), -1);
return search_bar->suboption_choice;
}
/**
* e_search_bar_get_text:
* @search_bar: A search bar.
*
* Queries the text of the entry line in a search bar.
*
* Return value: The text string that is in the entry line of the search bar.
* This must be freed using g_free(). If a suboption menu is active instead
* of an entry, NULL is returned.
**/
char *
e_search_bar_get_text (ESearchBar *search_bar)
{
g_return_val_if_fail (search_bar != NULL, NULL);
g_return_val_if_fail (E_IS_SEARCH_BAR (search_bar), NULL);
return search_bar->suboption_choice < 0 ? e_utf8_gtk_editable_get_text (GTK_EDITABLE (search_bar->entry)) : NULL;
}
|