From 669c08181079cc48352959b829f578ea922351a6 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Fri, 23 Feb 2001 21:22:15 +0000 Subject: Move the event box into the esb->dropdown_holder. Changed so it can be 2001-02-24 Not Zed * e-search-bar.c (add_dropdown): Move the event box into the esb->dropdown_holder. Changed so it can be called again on the same esb, to rebuild the menu. (e_search_bar_set_menu): New function to (re)set the menu. (add_option): Setup so it can be re-called to rebuild the option list. (e_search_bar_set_option): New function to build the menu's. svn path=/trunk/; revision=8373 --- widgets/misc/ChangeLog | 10 +++++++ widgets/misc/e-search-bar.c | 67 ++++++++++++++++++++++++++++++++++----------- widgets/misc/e-search-bar.h | 7 +++++ 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 04a1273f32..207ac511e7 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,13 @@ +2001-02-24 Not Zed + + * e-search-bar.c (add_dropdown): Move the event box into the + esb->dropdown_holder. Changed so it can be called again on the + same esb, to rebuild the menu. + (e_search_bar_set_menu): New function to (re)set the menu. + (add_option): Setup so it can be re-called to rebuild the option + list. + (e_search_bar_set_option): New function to build the menu's. + 2001-02-05 Jeffrey Stedfast * .cvsignore: Ignore test-dropdown-button diff --git a/widgets/misc/e-search-bar.c b/widgets/misc/e-search-bar.c index 1e5c4f2c8e..c1d69161c6 100644 --- a/widgets/misc/e-search-bar.c +++ b/widgets/misc/e-search-bar.c @@ -110,7 +110,7 @@ add_dropdown (ESearchBar *esb, ESearchBarItem *items) { GtkWidget *menu; - GtkWidget *event_box; + GtkWidget *dropdown; int i; menu = gtk_menu_new (); @@ -132,19 +132,29 @@ add_dropdown (ESearchBar *esb, } gtk_widget_show_all (menu); - esb->dropdown = e_dropdown_button_new (_("Sear_ch"), GTK_MENU (menu)); - GTK_WIDGET_UNSET_FLAGS (esb->dropdown, GTK_CAN_FOCUS); - gtk_widget_show (esb->dropdown); + dropdown = e_dropdown_button_new (_("Sear_ch"), GTK_MENU (menu)); + GTK_WIDGET_UNSET_FLAGS (dropdown, GTK_CAN_FOCUS); + gtk_widget_show (dropdown); - /* So, GtkOptionMenu is stupid; it adds a 1-pixel-wide empty border - around the button for no reason. So we add a 1-pixel-wide border - around the button as well, by using an event box. */ - event_box = gtk_event_box_new (); - gtk_container_set_border_width (GTK_CONTAINER (event_box), 1); - gtk_container_add (GTK_CONTAINER (event_box), esb->dropdown); - gtk_widget_show (event_box); + if (esb->dropdown_holder == NULL) { - gtk_box_pack_start(GTK_BOX(esb), event_box, FALSE, FALSE, 0); + /* So, GtkOptionMenu is stupid; it adds a 1-pixel-wide empty border + around the button for no reason. So we add a 1-pixel-wide border + around the button as well, by using an event box. */ + + esb->dropdown_holder = gtk_event_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (esb->dropdown_holder), 1); + esb->dropdown = dropdown; + gtk_container_add (GTK_CONTAINER (esb->dropdown_holder), esb->dropdown); + gtk_widget_show (esb->dropdown_holder); + + 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); + } } static void @@ -155,11 +165,16 @@ add_option(ESearchBar *esb, ESearchBarItem *items) GtkRequisition option_requisition; int i; - esb->option = gtk_option_menu_new(); - gtk_widget_show(esb->option); - gtk_box_pack_start(GTK_BOX(esb), esb->option, FALSE, FALSE, 0); + if (esb->option) { + gtk_option_menu_remove_menu((GtkOptionMenu *)esb->option); + gtk_widget_destroy(esb->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); + } - menu = gtk_menu_new (); + esb->menu = menu = gtk_menu_new (); for (i = 0; items[i].id != -1; i++) { GtkWidget *item; @@ -339,6 +354,26 @@ e_search_bar_construct (ESearchBar *search_bar, add_spacer (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); + + add_dropdown (search_bar, menu_items); +} + +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); + + add_option (search_bar, option_items); +} + GtkWidget * e_search_bar_new (ESearchBarItem *menu_items, ESearchBarItem *option_items) diff --git a/widgets/misc/e-search-bar.h b/widgets/misc/e-search-bar.h index 402de319f7..222501d2fe 100644 --- a/widgets/misc/e-search-bar.h +++ b/widgets/misc/e-search-bar.h @@ -60,6 +60,11 @@ struct _ESearchBar GtkWidget *dropdown; GtkWidget *option; GtkWidget *entry; + + /* PRIVATE */ + GtkWidget *dropdown_holder; /* holds the dropdown */ + GtkWidget *menu; + int option_choice; }; @@ -73,6 +78,8 @@ struct _ESearchBarClass GtkType e_search_bar_get_type (void); +void e_search_bar_set_menu (ESearchBar *search_bar, ESearchBarItem *menu_items); +void e_search_bar_set_option (ESearchBar *search_bar, ESearchBarItem *option_items); void e_search_bar_construct (ESearchBar *search_bar, ESearchBarItem *menu_items, ESearchBarItem *option_items); -- cgit