From ee8824b93be8d2acdd848abc26ffa01a98520379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20St=C3=B6sel?= Date: Fri, 16 Mar 2012 16:52:55 +0100 Subject: [PATCH] Show statusbar text in overlay instead of urlbar If the statusbar is hidden in GTK+ 3.2 or newer the text appears in an overlay on the view. midori_view_set_overlay_text sets the overlay label. --- midori/midori-browser.c | 59 ++++++++++++++++++++++++----------------- midori/midori-view.c | 45 +++++++++++++++++++++++++++++++ midori/midori-view.h | 4 +++ 3 files changed, 84 insertions(+), 24 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index edf4fcc3..69d30ae9 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -370,45 +370,56 @@ static void _midori_browser_set_statusbar_text (MidoriBrowser* browser, const gchar* text) { + GtkWidget* view = midori_browser_get_current_tab (browser); + #if GTK_CHECK_VERSION (3, 2, 0) + gboolean is_location = FALSE; + #else GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); gboolean is_location = widget && GTK_IS_ENTRY (widget) && GTK_IS_ALIGNMENT (gtk_widget_get_parent (widget)); + #endif katze_assign (browser->statusbar_text, midori_uri_format_for_display (text)); + if (view == NULL) + return; - if (!browser->show_statusbar && !is_location) + if (!gtk_widget_get_visible (browser->statusbar) && !is_location + && text && *text) { + #if GTK_CHECK_VERSION (3, 2, 0) + midori_view_set_overlay_text (MIDORI_VIEW (view), browser->statusbar_text); + #else GtkAction* action = _action_by_name (browser, "Location"); MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action); - if (text && *text) - { - midori_location_action_set_text (location_action, browser->statusbar_text); - midori_location_action_set_icon (location_action, NULL); - midori_location_action_set_secondary_icon (location_action, NULL); - } + midori_location_action_set_text (location_action, browser->statusbar_text); + midori_location_action_set_icon (location_action, NULL); + midori_location_action_set_secondary_icon (location_action, NULL); + #endif + } + else if (!gtk_widget_get_visible (browser->statusbar) && !is_location) + { + #if GTK_CHECK_VERSION (3, 2, 0) + midori_view_set_overlay_text (MIDORI_VIEW (view), NULL); + #else + GtkAction* action = _action_by_name (browser, "Location"); + MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action); + if (g_object_get_data (G_OBJECT (view), "news-feeds")) + midori_location_action_set_secondary_icon ( + location_action, STOCK_NEWS_FEED); else - { - GtkWidget* view = midori_browser_get_current_tab (browser); - if (G_LIKELY (view)) - { - if (g_object_get_data (G_OBJECT (view), "news-feeds")) - midori_location_action_set_secondary_icon ( - location_action, STOCK_NEWS_FEED); - else - midori_location_action_set_secondary_icon ( - location_action, GTK_STOCK_JUMP_TO); - midori_location_action_set_text (location_action, - midori_view_get_display_uri (MIDORI_VIEW (view))); - midori_location_action_set_icon (location_action, - midori_view_get_icon (MIDORI_VIEW (view))); - } - } + midori_location_action_set_secondary_icon ( + location_action, GTK_STOCK_JUMP_TO); + midori_location_action_set_text (location_action, + midori_view_get_display_uri (MIDORI_VIEW (view))); + midori_location_action_set_icon (location_action, + midori_view_get_icon (MIDORI_VIEW (view))); + #endif } else { gtk_statusbar_pop (GTK_STATUSBAR (browser->statusbar), 1); gtk_statusbar_push (GTK_STATUSBAR (browser->statusbar), 1, - browser->statusbar_text ? browser->statusbar_text : ""); + katze_str_non_null (browser->statusbar_text)); } } diff --git a/midori/midori-view.c b/midori/midori-view.c index ab4f3476..0a957055 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -112,6 +112,11 @@ struct _MidoriView gboolean back_forward_set; GHashTable* memory; GtkWidget* scrolled_window; + + #if GTK_CHECK_VERSION (3, 2, 0) + GtkWidget* overlay; + GtkWidget* overlay_label; + #endif }; struct _MidoriViewClass @@ -3162,7 +3167,20 @@ midori_view_init (MidoriView* view) view->scrolled_window = katze_scrolled_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->scrolled_window), GTK_SHADOW_NONE); + + #if GTK_CHECK_VERSION(3, 2, 0) + view->overlay = gtk_overlay_new (); + gtk_widget_show (view->overlay); + gtk_container_add (GTK_CONTAINER (view->overlay), view->scrolled_window); + gtk_box_pack_start (GTK_BOX (view), view->overlay, TRUE, TRUE, 0); + + view->overlay_label = gtk_label_new (NULL); + gtk_widget_set_halign (view->overlay_label, GTK_ALIGN_START); + gtk_widget_set_valign (view->overlay_label, GTK_ALIGN_END); + gtk_overlay_add_overlay (GTK_OVERLAY (view->overlay), view->overlay_label); + #else gtk_box_pack_start (GTK_BOX (view), view->scrolled_window, TRUE, TRUE, 0); + #endif g_signal_connect (view->item, "meta-data-changed", G_CALLBACK (midori_view_item_meta_data_changed), view); @@ -4217,6 +4235,33 @@ midori_view_set_uri (MidoriView* view, } } +/** + * midori_view_set_overlay_text: + * @view: a #MidoriView + * @text: a URI or text string + * + * Show a specified URI or text on top of the view. + * Has no effect with < GTK+ 3.2.0. + * + * Since: 0.4.5 + **/ +void +midori_view_set_overlay_text (MidoriView* view, + const gchar* text) +{ + g_return_if_fail (MIDORI_IS_VIEW (view)); + + #if GTK_CHECK_VERSION (3, 2, 0) + if (text == NULL) + gtk_widget_hide (view->overlay_label); + else + { + gtk_label_set_text (GTK_LABEL (view->overlay_label), text); + gtk_widget_show (view->overlay_label); + } + #endif +} + /** * midori_view_is_blank: * @view: a #MidoriView diff --git a/midori/midori-view.h b/midori/midori-view.h index 192a1fe8..c6914515 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -96,6 +96,10 @@ void midori_view_set_uri (MidoriView* view, const gchar* uri); +void +midori_view_set_overlay_text (MidoriView* view, + const gchar* text); + gboolean midori_view_is_blank (MidoriView* view);