X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Ftabbable.cc;h=5e4752454e6cfd6c8547b56799f59399b2307165;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=451405db63df1987095ec1d16e41624e9a756ac2;hpb=0819efe27c7091d3a96e426ed7202e0d6b0974a9;p=ardour.git diff --git a/libs/gtkmm2ext/tabbable.cc b/libs/gtkmm2ext/tabbable.cc index 451405db63..5e4752454e 100644 --- a/libs/gtkmm2ext/tabbable.cc +++ b/libs/gtkmm2ext/tabbable.cc @@ -27,7 +27,9 @@ #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; @@ -36,17 +38,9 @@ using std::string; Tabbable::Tabbable (Widget& w, const string& name) : WindowProxy (name) , _contents (w) - , tab_close_image (ArdourIcon::CloseCross, 0xffffffff) + , _parent_notebook (0) , tab_requested_by_state (true) { - tab_close_image.set_size_request (15,15); - - _tab_box.set_spacing (2); - _tab_box.pack_start (_tab_label, true, true); - _tab_box.pack_start (_tab_close_button, false, false); - _tab_close_button.add (tab_close_image); - - _tab_close_button.signal_clicked().connect (sigc::mem_fun (*this, &Tabbable::tab_close_clicked)); } Tabbable::~Tabbable () @@ -57,19 +51,10 @@ Tabbable::~Tabbable () } } -void -Tabbable::tab_close_clicked () -{ - hide_tab (); -} - 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,7 +71,7 @@ Tabbable::use_own_window (bool and_pack_it) if (parent) { parent->remove (_contents); } - _own_notebook.append_page (_contents, _tab_box); + _own_notebook.append_page (_contents); } return win; @@ -94,9 +79,9 @@ Tabbable::use_own_window (bool and_pack_it) } bool -Tabbable::window_visible () +Tabbable::window_visible () const { - if (!own_window()) { + if (!_window) { return false; } @@ -114,9 +99,9 @@ Tabbable::get (bool create) return 0; } - /* From here on, we're creating the window + /* From here on, we're creating the window */ - + if ((_window = new Window (WINDOW_TOPLEVEL)) == 0) { return 0; } @@ -127,13 +112,13 @@ Tabbable::get (bool create) _window->signal_map().connect (sigc::mem_fun (*this, &Tabbable::window_mapped)); _window->signal_unmap().connect (sigc::mem_fun (*this, &Tabbable::window_unmapped)); - + /* do other window-related setup */ setup (); /* window should be ready for derived classes to do something with it */ - + return _window; } @@ -146,14 +131,15 @@ Tabbable::show_own_window (bool and_pack_it) if (parent) { alloc = parent->get_allocation(); } - + (void) use_own_window (and_pack_it); - + if (parent) { _window->set_default_size (alloc.get_width(), alloc.get_height()); } - _window->show_all (); + tab_requested_by_state = false; + _window->present (); } @@ -183,10 +169,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 { @@ -207,7 +217,7 @@ Tabbable::make_invisible () hide_tab (); } } - + void Tabbable::detach () { @@ -220,7 +230,7 @@ Tabbable::attach () if (!_parent_notebook) { return; } - + if (tabbed()) { /* already tabbed */ return; @@ -231,26 +241,21 @@ Tabbable::attach () /* unpack Tabbable from parent, put it back in the main tabbed * notebook */ - + save_pos_and_size (); - + _contents.get_parent()->remove (_contents); - + /* leave the window around */ - + _window->hide (); } - - _parent_notebook->append_page (_contents, _tab_box); + + _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)); - - /* have to force this on, which is semantically correct, since * the user has effectively asked for it. */ @@ -268,18 +273,16 @@ Tabbable::delete_event_handler (GdkEventAny *ev) } bool -Tabbable::is_tabbed () const +Tabbable::tabbed () const { - Window* toplevel = (Window*) _contents.get_toplevel(); - - if (_window && (toplevel == _window)) { + if (_window && (current_toplevel() == _window)) { return false; } - if (_parent_notebook && _contents.get_parent()) { + if (_parent_notebook && (_parent_notebook->page_num (_contents) >= 0)) { return true; } - + return false; } @@ -301,6 +304,7 @@ Tabbable::show_tab () add_to_notebook (*_parent_notebook, _tab_title); } _parent_notebook->set_current_page (_parent_notebook->page_num (_contents)); + current_toplevel()->present (); } } @@ -317,9 +321,9 @@ Tabbable::xml_node_name() } bool -Tabbable::tabbed () const +Tabbable::tabbed_by_default() const { - return _parent_notebook && (_parent_notebook->page_num (_contents) >= 0); + return tab_requested_by_state; } XMLNode& @@ -328,7 +332,7 @@ Tabbable::get_state() XMLNode& node (WindowProxy::get_state()); node.add_property (X_("tabbed"), tabbed() ? X_("yes") : X_("no")); - + return node; } @@ -337,37 +341,33 @@ Tabbable::set_state (const XMLNode& node, int version) { int ret; - if ((ret = WindowProxy::set_state (node, version)) == 0) { - if (_visible) { - if (use_own_window (true) == 0) { - ret = -1; - } - } + if ((ret = WindowProxy::set_state (node, version)) != 0) { + return ret; + } + + if (_visible) { + show_own_window (true); } XMLNodeList children = node.children (); XMLNode* window_node = node.child ("Window"); if (window_node) { - const XMLProperty* prop = window_node->property (X_("tabbed")); + XMLProperty const * prop = window_node->property (X_("tabbed")); if (prop) { tab_requested_by_state = PBD::string_is_affirmative (prop->value()); } } - if (tab_requested_by_state) { - - std::cerr << name() << " pn " << _parent_notebook << std::endl; - if (_parent_notebook) { - std::cerr << "\t page " << _parent_notebook->page_num (_contents) << std::endl; + if (!_visible) { + if (tab_requested_by_state) { + attach (); + } else { + /* this does nothing if not tabbed */ + hide_tab (); } - - attach (); - } else { - /* this does nothing if not tabbed */ - hide_tab (); } - + return ret; } @@ -382,4 +382,3 @@ Tabbable::window_unmapped () { StateChange (*this); } -