X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=inline;f=libs%2Fgtkmm2ext%2Ftabbable.cc;h=8653a6a29d5442fb73544846f138c110eb8d2899;hb=f6e182b937efda6ed0ba50dbc02af98524beb61c;hp=c2d7b36963e3a745cf970819d424d27ab719907f;hpb=bc487bb4b02a9780938d6cf8528c888e59161aa9;p=ardour.git diff --git a/libs/gtkmm2ext/tabbable.cc b/libs/gtkmm2ext/tabbable.cc index c2d7b36963..8653a6a29d 100644 --- a/libs/gtkmm2ext/tabbable.cc +++ b/libs/gtkmm2ext/tabbable.cc @@ -27,27 +27,20 @@ #include "gtkmm2ext/utils.h" #include "gtkmm2ext/visibility_tracker.h" -#include "i18n.h" +#include "pbd/stacktrace.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) - , tab_close_image (ArdourIcon::CloseCross, 0xffffffff) - , tab_requested_by_state (true) + , _parent_notebook (0) + , tab_requested_by_state (tabbed_by_default) { - /* sizes will be scaled during rendering */ - tab_close_image.set_size_request (15,15); - - _tab_box.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK); - _tab_box.set_spacing (2); - _tab_box.pack_start (_tab_label, true, true); - _tab_box.pack_start (tab_close_image, false, false); - - tab_close_image.signal_button_release_event().connect (sigc::mem_fun (*this, &Tabbable::tab_close_clicked)); } Tabbable::~Tabbable () @@ -58,20 +51,10 @@ Tabbable::~Tabbable () } } -bool -Tabbable::tab_close_clicked (GdkEventButton*) -{ - hide_tab (); - return true; -} - void Tabbable::add_to_notebook (Notebook& notebook, const string& tab_title) { _parent_notebook = ¬ebook; - _tab_title = tab_title; - _tab_label.set_text (tab_title); - _tab_box.show_all (); if (tab_requested_by_state) { attach (); @@ -86,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, _tab_box); + _own_notebook.append_page (_contents); + _contents.show (); } return win; @@ -157,7 +142,6 @@ Tabbable::show_own_window (bool and_pack_it) tab_requested_by_state = false; - _window->show_all (); _window->present (); } @@ -187,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 { @@ -238,6 +246,7 @@ Tabbable::attach () save_pos_and_size (); + _contents.hide (); _contents.get_parent()->remove (_contents); /* leave the window around */ @@ -245,16 +254,11 @@ Tabbable::attach () _window->hide (); } - _parent_notebook->append_page (_contents, _tab_box); - _contents.set_data ("close-button", &tab_close_image); + _parent_notebook->append_page (_contents); _parent_notebook->set_tab_detachable (_contents); _parent_notebook->set_tab_reorderable (_contents); _parent_notebook->set_current_page (_parent_notebook->page_num (_contents)); - - Gtkmm2ext::UI::instance()->set_tip (_tab_label, - string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n" - "To put the window back, click on its \"close\" button"), _tab_title)); - + _contents.show (); /* have to force this on, which is semantically correct, since * the user has effectively asked for it. @@ -290,6 +294,7 @@ void Tabbable::hide_tab () { if (tabbed()) { + _contents.hide(); _parent_notebook->remove_page (_contents); StateChange (*this); } @@ -304,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 (); } } @@ -330,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; } @@ -352,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) { @@ -381,4 +385,3 @@ Tabbable::window_unmapped () { StateChange (*this); } -