aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-search-bar.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2001-03-01 08:55:12 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-03-01 08:55:12 +0800
commiteab717a2ec5594feb514efb487a33018b9a64fe2 (patch)
treeff97ca4ffadd570596232ebd31afda9ccac90838 /widgets/misc/e-search-bar.c
parent1b995212bd98536449d763031654c410200dbdd0 (diff)
downloadgsoc2013-evolution-eab717a2ec5594feb514efb487a33018b9a64fe2.tar.gz
gsoc2013-evolution-eab717a2ec5594feb514efb487a33018b9a64fe2.tar.zst
gsoc2013-evolution-eab717a2ec5594feb514efb487a33018b9a64fe2.zip
New type of search bar that interacts with filter contexts to save filters
2001-03-01 Not Zed <NotZed@Ximian.com> * e-filter-bar.c: New type of search bar that interacts with filter contexts to save filters etc. Still probably needs a little cleanpu. 2001-02-28 Not Zed <NotZed@Ximian.com> * e-search-bar.c (add_dropdown): Save the dropdown menu in the struct too. Sigh, this is only so we can scan its content later, ick. (e_search_bar_set_menu_sensitive): New function to se tthe sentisitivty of menyu items based on id. (find_id): New function to find the row and widget for a specific id. (add_option): Renamed to set_option. (add_dropdown): Renamed to set_dropdown. (add_dropdown): ?New function to add a single item. (set_dropdown): Call add_dropdown to add each item. (e_search_bar_add_menu): New public function to add a single item. 2001-02-27 Not Zed <NotZed@Ximian.com> * Makefile.am (libemiscwidgets_a_SOURCES): Added filter-bar.[ch]. * e-search-bar.c (class_init): Init virtual functions. (e_search_bar_set_option): (e_search_bar_set_menu): virtualise calling. (e_search_bar_construct): Call virtual functions to setup menus. * e-search-bar.h (struct _ESearchBarClass): Virtualise add_dropdown/add_option, so certain base options can be created. svn path=/trunk/; revision=8436
Diffstat (limited to 'widgets/misc/e-search-bar.c')
-rw-r--r--widgets/misc/e-search-bar.c110
1 files changed, 82 insertions, 28 deletions
diff --git a/widgets/misc/e-search-bar.c b/widgets/misc/e-search-bar.c
index c1d69161c6..30eaf0947f 100644
--- a/widgets/misc/e-search-bar.c
+++ b/widgets/misc/e-search-bar.c
@@ -105,31 +105,36 @@ entry_activated_cb (GtkWidget *widget,
/* Widgetry creation. */
+static void add_dropdown(ESearchBar *esb, ESearchBarItem *items)
+{
+ GtkWidget *menu = esb->dropdown_menu;
+ GtkWidget *item;
+
+ if (items->text)
+ item = gtk_menu_item_new_with_label (_(items->text));
+ 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
-add_dropdown (ESearchBar *esb,
+set_dropdown (ESearchBar *esb,
ESearchBarItem *items)
{
GtkWidget *menu;
GtkWidget *dropdown;
int i;
- menu = gtk_menu_new ();
- for (i = 0; items[i].id != -1; i++) {
- GtkWidget *item;
+ menu = esb->dropdown_menu = gtk_menu_new ();
+ for (i = 0; items[i].id != -1; i++)
+ add_dropdown(esb, items+i);
- if (items[i].text)
- item = gtk_menu_item_new_with_label (_(items[i].text));
- else
- item = gtk_menu_item_new();
-
- gtk_menu_append (GTK_MENU (menu), item);
-
- gtk_object_set_data (GTK_OBJECT (item), "EsbMenuId", GINT_TO_POINTER(items[i].id));
-
- gtk_signal_connect (GTK_OBJECT (item), "activate",
- GTK_SIGNAL_FUNC (menubar_activated_cb),
- esb);
- }
gtk_widget_show_all (menu);
dropdown = e_dropdown_button_new (_("Sear_ch"), GTK_MENU (menu));
@@ -150,7 +155,6 @@ add_dropdown (ESearchBar *esb,
gtk_box_pack_start(GTK_BOX(esb), esb->dropdown_holder, FALSE, FALSE, 0);
} else {
- gtk_container_remove(GTK_CONTAINER(esb->dropdown_holder), esb->dropdown);
gtk_widget_destroy(esb->dropdown);
esb->dropdown = dropdown;
gtk_container_add (GTK_CONTAINER (esb->dropdown_holder), esb->dropdown);
@@ -158,7 +162,7 @@ add_dropdown (ESearchBar *esb,
}
static void
-add_option(ESearchBar *esb, ESearchBarItem *items)
+set_option(ESearchBar *esb, ESearchBarItem *items)
{
GtkWidget *menu;
GtkRequisition dropdown_requisition;
@@ -166,15 +170,14 @@ add_option(ESearchBar *esb, ESearchBarItem *items)
int i;
if (esb->option) {
- gtk_option_menu_remove_menu((GtkOptionMenu *)esb->option);
- gtk_widget_destroy(esb->menu);
+ 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->menu = menu = gtk_menu_new ();
+ esb->option_menu = menu = gtk_menu_new ();
for (i = 0; items[i].id != -1; i++) {
GtkWidget *item;
@@ -230,6 +233,29 @@ add_spacer (ESearchBar *esb)
gtk_widget_set_usize(spacer, 19, 1);
}
+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));
+ printf("comparing id %d to query %d\n", id, idin);
+ if (id == idin) {
+ row = i;
+ if (widget)
+ *widget = l->data;
+ break;
+ }
+ i++;
+ l = l->next;
+ }
+ return row;
+}
+
/* GtkObject methods. */
@@ -257,11 +283,15 @@ 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);
- gtk_option_menu_set_history (GTK_OPTION_MENU (esb->option), esb->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;
@@ -296,6 +326,9 @@ class_init (ESearchBarClass *klass)
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::text", GTK_TYPE_STRING,
@@ -345,9 +378,9 @@ e_search_bar_construct (ESearchBar *search_bar,
gtk_box_set_spacing (GTK_BOX (search_bar), 1);
- add_dropdown (search_bar, menu_items);
+ e_search_bar_set_menu(search_bar, menu_items);
- add_option (search_bar, option_items);
+ e_search_bar_set_option(search_bar, option_items);
add_entry (search_bar);
@@ -361,7 +394,17 @@ e_search_bar_set_menu(ESearchBar *search_bar, ESearchBarItem *menu_items)
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (menu_items != NULL);
- add_dropdown (search_bar, menu_items);
+ ((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
@@ -371,7 +414,7 @@ e_search_bar_set_option(ESearchBar *search_bar, ESearchBarItem *option_items)
g_return_if_fail (E_IS_SEARCH_BAR (search_bar));
g_return_if_fail (option_items != NULL);
- add_option (search_bar, option_items);
+ ((ESearchBarClass *)((GtkObject *)search_bar)->klass)->set_option(search_bar, option_items);
}
GtkWidget *
@@ -390,6 +433,17 @@ e_search_bar_new (ESearchBarItem *menu_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)
{