From 52c6958571696c8fcce89e021669725be982bcfc Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Thu, 16 Jul 2009 23:21:01 +0530 Subject: Search bar stuff for Anjal. --- widgets/misc/e-icon-entry.c | 36 ++++++++++++++++++++++++++++++++++++ widgets/misc/e-icon-entry.h | 2 ++ widgets/misc/e-search-bar.c | 43 +++++++++++++++++++++++++++++++++++++++++++ widgets/misc/e-search-bar.h | 1 + 4 files changed, 82 insertions(+) (limited to 'widgets/misc') diff --git a/widgets/misc/e-icon-entry.c b/widgets/misc/e-icon-entry.c index 2ed50e242f..90130ccbd6 100644 --- a/widgets/misc/e-icon-entry.c +++ b/widgets/misc/e-icon-entry.c @@ -374,6 +374,42 @@ e_icon_entry_create_button (const gchar *stock) return eventbox; } +GtkWidget * +e_icon_entry_create_text (const gchar *text) +{ + GtkWidget *eventbox; + GtkWidget *image; + + eventbox = gtk_event_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (eventbox), 2); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (eventbox), FALSE); + + image = gtk_label_new (text); + gtk_container_add (GTK_CONTAINER (eventbox), image); + g_object_set_data ((GObject *)eventbox, "lbl", image); + g_signal_connect_after (eventbox, "enter-notify-event", (GCallback) set_cursor, NULL); + g_signal_connect_after (eventbox, "leave-notify-event", (GCallback) set_cursor, NULL); + + return eventbox; +} + + +GtkWidget * +e_icon_entry_create_separator () +{ + GtkWidget *eventbox; + GtkWidget *image; + + eventbox = gtk_event_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (eventbox), 0); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (eventbox), FALSE); + + image = (GtkWidget *)gtk_separator_tool_item_new (); + gtk_container_add (GTK_CONTAINER (eventbox), image); + + return eventbox; +} + GtkWidget * e_icon_entry_get_entry (EIconEntry *entry) { diff --git a/widgets/misc/e-icon-entry.h b/widgets/misc/e-icon-entry.h index f8e4740d36..cde735ba6f 100644 --- a/widgets/misc/e-icon-entry.h +++ b/widgets/misc/e-icon-entry.h @@ -79,6 +79,8 @@ void e_icon_entry_pack_widget (EIconEntry *entry, GtkWidget *e_icon_entry_get_entry (EIconEntry *entry); GtkWidget *e_icon_entry_create_button (const gchar *stock); +GtkWidget * e_icon_entry_create_text (const gchar *text); +GtkWidget * e_icon_entry_create_separator (void); G_END_DECLS diff --git a/widgets/misc/e-search-bar.c b/widgets/misc/e-search-bar.c index 1783ebf375..36e0e6dc52 100644 --- a/widgets/misc/e-search-bar.c +++ b/widgets/misc/e-search-bar.c @@ -74,6 +74,26 @@ static void emit_query_changed (ESearchBar *esb); /* Utility functions. */ +static void +esb_paint_label (GtkWidget *label, gboolean active) +{ + static char *sens = NULL; + static char *insens = NULL; + char *text; + + if (!label) + return; + + if (!sens) { + GtkStyle *default_style = gtk_widget_get_default_style (); + sens = gdk_color_to_string (&default_style->text[GTK_STATE_SELECTED]); + insens = gdk_color_to_string (&default_style->text[GTK_STATE_NORMAL]); + } + text = g_strdup_printf("%s", active ? sens : insens, _("Search")); + gtk_label_set_markup ((GtkLabel *)label, text); + g_free(text); +} + static void set_find_now_sensitive (ESearchBar *search_bar, gboolean sensitive) @@ -371,12 +391,14 @@ entry_activated_cb (GtkWidget *widget, gtk_widget_modify_base (esb->entry, GTK_STATE_NORMAL, &(style->base[GTK_STATE_SELECTED])); gtk_widget_modify_text (esb->entry, GTK_STATE_NORMAL, &(style->text[GTK_STATE_SELECTED])); gtk_widget_modify_base (esb->icon_entry, GTK_STATE_NORMAL, &(style->base[GTK_STATE_SELECTED])); + esb_paint_label (esb->label, TRUE); if (!esb->lite) gtk_widget_modify_base (esb->viewoption, GTK_STATE_NORMAL, &(style->base[GTK_STATE_SELECTED])); } else { gtk_widget_modify_base (esb->entry, GTK_STATE_NORMAL, NULL); gtk_widget_modify_text (esb->entry, GTK_STATE_NORMAL, NULL); gtk_widget_modify_base (esb->icon_entry, GTK_STATE_NORMAL, NULL); + esb_paint_label (esb->label, FALSE); if (!esb->lite) gtk_widget_set_sensitive (esb->clear_button, FALSE); } @@ -384,6 +406,13 @@ entry_activated_cb (GtkWidget *widget, emit_search_activated (esb); } +static void +search_entry_press_cb (GtkWidget *w, GdkEventButton *event, ESearchBar *esb) +{ + if (event->button == 1) + entry_activated_cb (w, esb); +} + static void entry_changed_cb (GtkWidget *widget, ESearchBar *esb) @@ -504,6 +533,7 @@ clear_button_clicked_cb (GtkWidget *widget, GdkEventButton *event, gtk_widget_modify_text (esb->entry, GTK_STATE_NORMAL, NULL); gtk_widget_modify_base (esb->icon_entry, GTK_STATE_NORMAL, NULL); gtk_widget_set_sensitive (esb->clear_button, FALSE); + esb_paint_label (esb->label, FALSE); clear_search (esb); gtk_entry_set_text (GTK_ENTRY (esb->entry), ""); @@ -955,6 +985,7 @@ idle_activate_hack (gpointer ptr) return FALSE; } + void e_search_bar_construct (ESearchBar *search_bar, ESearchBarItem *menu_items, @@ -986,6 +1017,18 @@ e_search_bar_construct (ESearchBar *search_bar, g_signal_connect (search_bar->entry, "key-press-event", G_CALLBACK (entry_key_press_cb), search_bar); + search_bar->label = NULL; + if (search_bar->lite) { + label = e_icon_entry_create_text (_("Search")); + g_signal_connect (G_OBJECT (label), "button-press-event", G_CALLBACK(search_entry_press_cb), search_bar); + e_icon_entry_pack_widget (E_ICON_ENTRY (search_bar->icon_entry), label, FALSE); + search_bar->label = g_object_get_data ((GObject *)label, "lbl"); + esb_paint_label (search_bar->label, FALSE); + + label = e_icon_entry_create_separator (); + e_icon_entry_pack_widget (E_ICON_ENTRY (search_bar->icon_entry), label, FALSE); + } + search_bar->clear_button = e_icon_entry_create_button ("gtk-clear"); g_signal_connect (G_OBJECT (search_bar->clear_button), "button-press-event", G_CALLBACK(clear_button_clicked_cb), search_bar); e_icon_entry_pack_widget (E_ICON_ENTRY (search_bar->icon_entry), search_bar->clear_button, FALSE); diff --git a/widgets/misc/e-search-bar.h b/widgets/misc/e-search-bar.h index 82bc1ba0da..5385ebf66a 100644 --- a/widgets/misc/e-search-bar.h +++ b/widgets/misc/e-search-bar.h @@ -85,6 +85,7 @@ struct _ESearchBar GtkWidget *clear_button; GtkWidget *entry_box; GtkWidget *icon_entry; + GtkWidget *label; /* show option widgets */ GtkWidget *viewoption_box; -- cgit v1.2.3