2 Copyright (C) 2015 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/action.h>
21 #include <gtkmm/notebook.h>
22 #include <gtkmm/window.h>
23 #include <gtkmm/stock.h>
25 #include "pbd/stacktrace.h"
27 #include "gtkmm2ext/gtk_ui.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/visibility_tracker.h"
31 #include "widgets/tabbable.h"
37 using namespace Gtkmm2ext;
38 using namespace ArdourWidgets;
40 Tabbable::Tabbable (Widget& w, const string& name, bool tabbed_by_default)
43 , _parent_notebook (0)
44 , tab_requested_by_state (tabbed_by_default)
48 Tabbable::~Tabbable ()
57 Tabbable::add_to_notebook (Notebook& notebook, const string& tab_title)
59 _parent_notebook = ¬ebook;
61 if (tab_requested_by_state) {
67 Tabbable::use_own_window (bool and_pack_it)
69 Gtk::Window* win = get (true);
72 Gtk::Container* parent = _contents.get_parent();
75 parent->remove (_contents);
77 _own_notebook.append_page (_contents);
86 Tabbable::window_visible () const
92 return _window->is_visible();
96 Tabbable::get (bool create)
106 /* From here on, we're creating the window
109 if ((_window = new Window (WINDOW_TOPLEVEL)) == 0) {
113 _window->add (_own_notebook);
114 _own_notebook.show ();
115 _own_notebook.set_show_tabs (false);
117 _window->signal_map().connect (sigc::mem_fun (*this, &Tabbable::window_mapped));
118 _window->signal_unmap().connect (sigc::mem_fun (*this, &Tabbable::window_unmapped));
120 /* do other window-related setup */
124 /* window should be ready for derived classes to do something with it */
130 Tabbable::show_own_window (bool and_pack_it)
132 Gtk::Widget* parent = _contents.get_parent();
133 Gtk::Allocation alloc;
136 alloc = parent->get_allocation();
139 (void) use_own_window (and_pack_it);
142 _window->set_default_size (alloc.get_width(), alloc.get_height());
145 tab_requested_by_state = false;
151 Tabbable::tab_root_drop ()
153 /* This is called after a drop of a tab onto the root window. Its
154 * responsibility xois to return the notebook that this Tabbable's
155 * contents should be packed into before the drop handling is
156 * completed. It is not responsible for actually taking care of this
160 show_own_window (false);
161 return &_own_notebook;
165 Tabbable::show_window ()
169 if (_window && (current_toplevel() == _window)) {
170 if (!_visible) { /* was hidden, update status */
176 /** If this Tabbable is currently parented by a tab, ensure that the tab is the
177 * current one. If it is parented by a window, then toggle the visibility of
181 Tabbable::change_visibility ()
184 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
188 if (tab_requested_by_state) {
189 /* should be tabbed, but currently isn't parented by a notebook */
193 if (_window && (current_toplevel() == _window)) {
194 /* Use WindowProxy method which will rotate then hide */
200 Tabbable::make_visible ()
202 if (_window && (current_toplevel() == _window)) {
207 if (!tab_requested_by_state) {
208 show_own_window (true);
216 Tabbable::make_invisible ()
218 if (_window && (current_toplevel() == _window)) {
228 show_own_window (true);
234 if (!_parent_notebook) {
244 if (_window && current_toplevel() == _window) {
245 /* unpack Tabbable from parent, put it back in the main tabbed
249 save_pos_and_size ();
252 _contents.get_parent()->remove (_contents);
254 /* leave the window around */
259 _parent_notebook->append_page (_contents);
260 _parent_notebook->set_tab_detachable (_contents);
261 _parent_notebook->set_tab_reorderable (_contents);
262 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
265 /* have to force this on, which is semantically correct, since
266 * the user has effectively asked for it.
269 tab_requested_by_state = true;
274 Tabbable::delete_event_handler (GdkEventAny *ev)
282 Tabbable::tabbed () const
284 if (_window && (current_toplevel() == _window)) {
288 if (_parent_notebook && (_parent_notebook->page_num (_contents) >= 0)) {
296 Tabbable::hide_tab ()
300 _parent_notebook->remove_page (_contents);
306 Tabbable::show_tab ()
308 if (!window_visible() && _parent_notebook) {
309 if (_contents.get_parent() == 0) {
310 tab_requested_by_state = true;
311 add_to_notebook (*_parent_notebook, _tab_title);
313 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
315 current_toplevel()->present ();
320 Tabbable::current_toplevel () const
322 return dynamic_cast<Gtk::Window*> (contents().get_toplevel());
326 Tabbable::xml_node_name()
328 return WindowProxy::xml_node_name();
332 Tabbable::tabbed_by_default() const
334 return tab_requested_by_state;
338 Tabbable::get_state()
340 XMLNode& node (WindowProxy::get_state());
342 node.set_property (X_("tabbed"), tabbed());
348 Tabbable::set_state (const XMLNode& node, int version)
352 if ((ret = WindowProxy::set_state (node, version)) != 0) {
357 show_own_window (true);
360 XMLNodeList children = node.children ();
361 XMLNode* window_node = node.child ("Window");
364 window_node->get_property (X_("tabbed"), tab_requested_by_state);
368 if (tab_requested_by_state) {
371 /* this does nothing if not tabbed */
380 Tabbable::window_mapped ()
386 Tabbable::window_unmapped ()