]> spindle.queued.net Git - midori/commitdiff
Show statusbar text in overlay instead of urlbar
authorAndré Stösel <andre@stoesel.de>
Fri, 16 Mar 2012 15:52:55 +0000 (16:52 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 18 Mar 2012 08:32:32 +0000 (09:32 +0100)
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
midori/midori-view.c
midori/midori-view.h

index edf4fcc31dd3ff745cd67eb018c0c2534c485ffb..69d30ae925e0bf221f13e9a2e539cd90e253813f 100644 (file)
@@ -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));
     }
 }
 
index ab4f34761d136e38f72343a88231ffe520e0f0c3..0a957055ba29c131bef972f92e91fb37b7e580b1 100644 (file)
@@ -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
index 192a1fe89a185cd450927c62bb46edff297680b8..c6914515c0ff83b435b870758c9b9d4848dc29cb 100644 (file)
@@ -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);