aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2001-01-27 19:24:13 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2001-01-27 19:24:13 +0800
commitb8ea4247926497b4f1126827823d38f2859d7563 (patch)
tree78bc663803ea43c3bdc8f775955be19ebc1c6f43
parentd2c859ad387d1220524145bc72f5ae0c911c9f40 (diff)
downloadgsoc2013-evolution-b8ea4247926497b4f1126827823d38f2859d7563.tar.gz
gsoc2013-evolution-b8ea4247926497b4f1126827823d38f2859d7563.tar.zst
gsoc2013-evolution-b8ea4247926497b4f1126827823d38f2859d7563.zip
Make the ESearchBar use the new EDropdownButton widget.
svn path=/trunk/; revision=7855
-rw-r--r--widgets/misc/ChangeLog31
-rw-r--r--widgets/misc/e-search-bar.c324
-rw-r--r--widgets/misc/e-search-bar.h8
3 files changed, 217 insertions, 146 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 2c39f11046..3a3cb1f9f0 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,5 +1,36 @@
2001-01-27 Ettore Perazzoli <ettore@ximian.com>
+ * e-search-bar.c (add_dropdown): Make the dropdown button
+ non-focusable.
+
+2001-01-27 Ettore Perazzoli <ettore@ximian.com>
+
+ * e-search-bar.c (e_search_bar_init): Don't create the widgets
+ here.
+ (e_search_bar_construct): New. Do it here instead.
+ (e_search_bar_new): Call it. Added preconditions.
+ (esb_pack_menubar): Removed.
+ (add_dropdown): New.
+ (add_option): New.
+ (add_entry): New.
+ (e_search_bar_construct): Use `add_dropdown()', `add_option()',
+ `add_entry()'.
+ (class_init): Renamed from `e_seearch_bar_class_init'.
+ (init): Renamed from `e_search_bar_init'.
+ (impl_destroy): Renamed from `e_search_bar_destroy'.
+ (emit_menu_activated): Renamed from `esb_menu_activated'.
+ (emit_query_changed): Renamed from `esb_query_changed'.
+ (menubar_activated_cb): Renamed from `esb_menubar_activated'.
+ (option_activated_cb): Renamed from `esb_option_activated'.
+ (esb_entry_activated): Renamed from `esb_entry_activated'.
+ (impl_set_arg): Renamed from `e_search_bar_set_arg'.
+ (impl_get_arg): Renamed from `e_search_bar_get_arg'.
+
+ * e-search-bar.h (struct _ESearchBar): Removed member `menubar';
+ replaced it with `dropdown'.
+
+2001-01-27 Ettore Perazzoli <ettore@ximian.com>
+
* e-dropdown-button.c (e_dropdown_button_construct): Removed
@ui_info and @data args. Obviously I am not very smart at this
time of the night.
diff --git a/widgets/misc/e-search-bar.c b/widgets/misc/e-search-bar.c
index 38ac0c5249..39730c7aa6 100644
--- a/widgets/misc/e-search-bar.c
+++ b/widgets/misc/e-search-bar.c
@@ -24,15 +24,12 @@
#include <gnome.h>
#include "e-search-bar.h"
+#include "e-dropdown-button.h"
+
#include <gal/widgets/e-unicode.h>
#include <gal/widgets/e-gui-utils.h>
-static void e_search_bar_init (ESearchBar *card);
-static void e_search_bar_class_init (ESearchBarClass *klass);
-static void e_search_bar_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
-static void e_search_bar_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
-static void e_search_bar_destroy (GtkObject *object);
-
+
enum {
QUERY_CHANGED,
MENU_ACTIVATED,
@@ -51,107 +48,64 @@ enum {
ARG_TEXT,
};
-GtkType
-e_search_bar_get_type (void)
-{
- static GtkType type = 0;
-
- if (!type) {
- static const GtkTypeInfo info =
- {
- "ESearchBar",
- sizeof (ESearchBar),
- sizeof (ESearchBarClass),
- (GtkClassInitFunc) e_search_bar_class_init,
- (GtkObjectInitFunc) e_search_bar_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
- };
-
- type = gtk_type_unique (gtk_hbox_get_type (), &info);
- }
-
- return type;
-}
-
-static void
-e_search_bar_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 = e_search_bar_set_arg;
- object_class->get_arg = e_search_bar_get_arg;
- object_class->destroy = e_search_bar_destroy;
-
- 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,
- 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);
-}
+
+/* Signals. */
static void
-esb_query_changed(ESearchBar *esb)
+emit_query_changed (ESearchBar *esb)
{
gtk_signal_emit(GTK_OBJECT (esb),
esb_signals [QUERY_CHANGED]);
}
static void
-esb_menu_activated(ESearchBar *esb, int item)
+emit_menu_activated (ESearchBar *esb, int item)
{
gtk_signal_emit(GTK_OBJECT (esb),
esb_signals [MENU_ACTIVATED],
item);
}
+
+/* Callbacks. */
+
static void
-esb_menubar_activated(GtkWidget *widget, ESearchBar *esb)
+menubar_activated_cb (GtkWidget *widget, ESearchBar *esb)
{
- int id = GPOINTER_TO_INT(gtk_object_get_data (GTK_OBJECT (widget), "EsbMenuId"));
+ int id;
- esb_menu_activated(esb, id);
+ id = GPOINTER_TO_INT(gtk_object_get_data (GTK_OBJECT (widget), "EsbMenuId"));
+
+ emit_menu_activated(esb, id);
}
static void
-esb_check_labels(GtkWidget *widget, gpointer data)
+option_activated_cb (GtkWidget *widget,
+ ESearchBar *esb)
{
- if (GTK_IS_LABEL(widget)) {
- char *text;
- gtk_object_get(GTK_OBJECT(widget),
- "label", &text,
- NULL);
- gtk_label_parse_uline(GTK_LABEL(widget), text);
- g_free(text);
- }
+ int id;
+
+ id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), "EsbChoiceId"));
+
+ esb->option_choice = id;
+ emit_query_changed (esb);
}
static void
-esb_pack_menubar(ESearchBar *esb, ESearchBarItem *items)
+entry_activated_cb (GtkWidget *widget,
+ ESearchBar *esb)
{
- GtkWidget *menu, *menuitem;
+ emit_query_changed (esb);
+}
+
+
+/* Widgetry creation. */
+
+static void
+add_dropdown (ESearchBar *esb,
+ ESearchBarItem *items)
+{
+ GtkWidget *menu;
int i;
menu = gtk_menu_new ();
@@ -168,42 +122,28 @@ esb_pack_menubar(ESearchBar *esb, ESearchBarItem *items)
gtk_object_set_data (GTK_OBJECT (item), "EsbMenuId", GINT_TO_POINTER(items[i].id));
gtk_signal_connect (GTK_OBJECT (item), "activate",
- GTK_SIGNAL_FUNC (esb_menubar_activated),
+ GTK_SIGNAL_FUNC (menubar_activated_cb),
esb);
}
gtk_widget_show_all (menu);
- menuitem = gnome_stock_menu_item(GNOME_STOCK_MENU_SEARCH, _("Sear_ch"));
- e_container_foreach_leaf(GTK_CONTAINER(menuitem), esb_check_labels, NULL);
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
-
- gtk_widget_show (menuitem);
-
- gtk_menu_bar_append (GTK_MENU_BAR(esb->menubar), menuitem);
- gtk_widget_set_sensitive (esb->menubar, TRUE);
-}
-
-static void
-esb_option_activated(GtkWidget *widget, ESearchBar *esb)
-{
- int id = GPOINTER_TO_INT(gtk_object_get_data (GTK_OBJECT (widget), "EsbChoiceId"));
-
- esb->option_choice = id;
- esb_query_changed(esb);
-}
+ 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);
-static void
-esb_entry_activated(GtkWidget *widget, ESearchBar *esb)
-{
- esb_query_changed(esb);
+ gtk_box_pack_start(GTK_BOX(esb), esb->dropdown, FALSE, FALSE, 0);
}
static void
-esb_pack_option_menu(ESearchBar *esb, ESearchBarItem *items)
+add_option(ESearchBar *esb, ESearchBarItem *items)
{
GtkWidget *menu;
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);
+
menu = gtk_menu_new ();
for (i = 0; items[i].id != -1; i++) {
GtkWidget *item;
@@ -218,38 +158,31 @@ esb_pack_option_menu(ESearchBar *esb, ESearchBarItem *items)
gtk_object_set_data (GTK_OBJECT (item), "EsbChoiceId", GINT_TO_POINTER(items[i].id));
gtk_signal_connect (GTK_OBJECT (item), "activate",
- GTK_SIGNAL_FUNC (esb_option_activated),
+ 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_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);
}
static void
-e_search_bar_init (ESearchBar *esb)
+add_entry (ESearchBar *esb)
{
- GtkWidget *spacer;
-
- gtk_box_set_spacing(GTK_BOX(esb), 1);
-
- esb->menubar = gtk_menu_bar_new();
- gtk_widget_show(esb->menubar);
- gtk_box_pack_start(GTK_BOX(esb), esb->menubar, FALSE, FALSE, 0);
-
- esb->option = gtk_option_menu_new();
- gtk_widget_show(esb->option);
- gtk_box_pack_start(GTK_BOX(esb), esb->option, FALSE, FALSE, 0);
-
esb->entry = gtk_entry_new();
gtk_signal_connect (GTK_OBJECT (esb->entry), "activate",
- GTK_SIGNAL_FUNC (esb_entry_activated), esb);
+ GTK_SIGNAL_FUNC (entry_activated_cb), esb);
gtk_widget_show(esb->entry);
gtk_box_pack_start(GTK_BOX(esb), esb->entry, TRUE, TRUE, 0);
- esb->option_choice = 0;
+}
+
+static void
+add_spacer (ESearchBar *esb)
+{
+ GtkWidget *spacer;
spacer = gtk_drawing_area_new();
gtk_widget_show(spacer);
@@ -257,25 +190,11 @@ e_search_bar_init (ESearchBar *esb)
gtk_widget_set_usize(spacer, 15, 1);
}
-static void
-e_search_bar_destroy (GtkObject *object)
-{
- if (GTK_OBJECT_CLASS(parent_class)->destroy)
- GTK_OBJECT_CLASS(parent_class)->destroy(object);
-}
-
-GtkWidget *
-e_search_bar_new (ESearchBarItem *menu_items,
- ESearchBarItem *option_items)
-{
- GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_search_bar_get_type ()));
- esb_pack_menubar(E_SEARCH_BAR(widget), menu_items);
- esb_pack_option_menu(E_SEARCH_BAR(widget), option_items);
- return widget;
-}
+
+/* GtkObject methods. */
static void
-e_search_bar_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+impl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESearchBar *esb = E_SEARCH_BAR(object);
@@ -295,7 +214,7 @@ e_search_bar_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
}
static void
-e_search_bar_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+impl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESearchBar *esb = E_SEARCH_BAR(object);
@@ -303,12 +222,12 @@ e_search_bar_set_arg (GtkObject *object, GtkArg *arg, guint 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_query_changed(esb);
+ emit_query_changed (esb);
break;
case ARG_TEXT:
e_utf8_gtk_editable_set_text(GTK_EDITABLE(esb->entry), GTK_VALUE_STRING (*arg));
- esb_query_changed(esb);
+ emit_query_changed (esb);
break;
default:
@@ -316,4 +235,121 @@ e_search_bar_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
}
}
+static void
+impl_destroy (GtkObject *object)
+{
+ 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;
+
+ 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,
+ 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;
+}
+
+
+/* Object construction. */
+
+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);
+
+ add_dropdown (search_bar, menu_items);
+
+ add_option (search_bar, option_items);
+
+ add_entry (search_bar);
+
+ add_spacer (search_bar);
+}
+
+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;
+}
+
+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;
+}
diff --git a/widgets/misc/e-search-bar.h b/widgets/misc/e-search-bar.h
index cf015f2ec0..402de319f7 100644
--- a/widgets/misc/e-search-bar.h
+++ b/widgets/misc/e-search-bar.h
@@ -57,7 +57,7 @@ struct _ESearchBar
GtkHBox parent;
/* item specific fields */
- GtkWidget *menubar;
+ GtkWidget *dropdown;
GtkWidget *option;
GtkWidget *entry;
int option_choice;
@@ -71,9 +71,13 @@ struct _ESearchBarClass
void (*menu_activated) (ESearchBar *search, int item);
};
+
+GtkType e_search_bar_get_type (void);
+void e_search_bar_construct (ESearchBar *search_bar,
+ ESearchBarItem *menu_items,
+ ESearchBarItem *option_items);
GtkWidget *e_search_bar_new (ESearchBarItem *menu_items,
ESearchBarItem *option_items);
-GtkType e_search_bar_get_type (void);
#ifdef __cplusplus
}