Move Gtkmm2ext widgets into libwidget
[ardour.git] / libs / gtkmm2ext / tabbable.cc
index 928e501751c7be3e2b59a08743b88ded013cef48..8653a6a29d5442fb73544846f138c110eb8d2899 100644 (file)
 
 #include "pbd/stacktrace.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace Gtkmm2ext;
 using namespace Gtk;
 using std::string;
 
-Tabbable::Tabbable (Widget& w, const string& name)
+Tabbable::Tabbable (Widget& w, const string& name, bool tabbed_by_default)
        : WindowProxy (name)
        , _contents (w)
        , _parent_notebook (0)
-       , tab_requested_by_state (true)
+       , tab_requested_by_state (tabbed_by_default)
 {
 }
 
@@ -69,9 +69,11 @@ Tabbable::use_own_window (bool and_pack_it)
        if (and_pack_it) {
                Gtk::Container* parent = _contents.get_parent();
                if (parent) {
+                       _contents.hide ();
                        parent->remove (_contents);
                }
                _own_notebook.append_page (_contents);
+               _contents.show ();
        }
 
        return win;
@@ -140,7 +142,6 @@ Tabbable::show_own_window (bool and_pack_it)
 
        tab_requested_by_state = false;
 
-       _window->show_all ();
        _window->present ();
 }
 
@@ -170,10 +171,34 @@ Tabbable::show_window ()
        }
 }
 
+/** If this Tabbable is currently parented by a tab, ensure that the tab is the
+ * current one. If it is parented by a window, then toggle the visibility of
+ * that window.
+ */
+void
+Tabbable::change_visibility ()
+{
+       if (tabbed()) {
+               _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
+               return;
+       }
+
+       if (tab_requested_by_state) {
+               /* should be tabbed, but currently isn't parented by a notebook */
+               return;
+       }
+
+       if (_window && (current_toplevel() == _window)) {
+               /* Use WindowProxy method which will rotate then hide */
+               toggle();
+       }
+}
+
 void
 Tabbable::make_visible ()
 {
        if (_window && (current_toplevel() == _window)) {
+               set_pos ();
                _window->present ();
        } else {
 
@@ -221,6 +246,7 @@ Tabbable::attach ()
 
                save_pos_and_size ();
 
+               _contents.hide ();
                _contents.get_parent()->remove (_contents);
 
                /* leave the window around */
@@ -232,6 +258,7 @@ Tabbable::attach ()
        _parent_notebook->set_tab_detachable (_contents);
        _parent_notebook->set_tab_reorderable (_contents);
        _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
+       _contents.show ();
 
        /* have to force this on, which is semantically correct, since
         * the user has effectively asked for it.
@@ -267,6 +294,7 @@ void
 Tabbable::hide_tab ()
 {
        if (tabbed()) {
+               _contents.hide();
                _parent_notebook->remove_page (_contents);
                StateChange (*this);
        }
@@ -281,6 +309,8 @@ Tabbable::show_tab ()
                        add_to_notebook (*_parent_notebook, _tab_title);
                }
                _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
+               _contents.show ();
+               current_toplevel()->present ();
        }
 }
 
@@ -307,7 +337,7 @@ Tabbable::get_state()
 {
        XMLNode& node (WindowProxy::get_state());
 
-       node.add_property (X_("tabbed"),  tabbed() ? X_("yes") : X_("no"));
+       node.set_property (X_("tabbed"),  tabbed());
 
        return node;
 }
@@ -329,10 +359,7 @@ Tabbable::set_state (const XMLNode& node, int version)
        XMLNode* window_node = node.child ("Window");
 
        if (window_node) {
-               const XMLProperty* prop = window_node->property (X_("tabbed"));
-               if (prop) {
-                       tab_requested_by_state = PBD::string_is_affirmative (prop->value());
-               }
+               window_node->get_property (X_("tabbed"), tab_requested_by_state);
        }
 
        if (!_visible) {
@@ -358,4 +385,3 @@ Tabbable::window_unmapped ()
 {
        StateChange (*this);
 }
-