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 "gtkmm2ext/tabbable.h"
26 #include "gtkmm2ext/gtk_ui.h"
27 #include "gtkmm2ext/utils.h"
28 #include "gtkmm2ext/visibility_tracker.h"
32 using namespace Gtkmm2ext;
36 Tabbable::Tabbable (Widget& w, const string& name)
39 , tab_close_image (ArdourIcon::CloseCross, 0xffffffff)
41 /* make the image about the same size as an actual X */
42 set_size_request_to_display_given_text (tab_close_image, "X", 0, 0);
44 _tab_box.set_spacing (2);
45 _tab_box.pack_start (_tab_label, true, true);
46 _tab_box.pack_start (_tab_close_button, false, false);
47 _tab_close_button.add (tab_close_image);
49 _tab_close_button.signal_clicked().connect (sigc::mem_fun (*this, &Tabbable::tab_close_clicked));
52 Tabbable::~Tabbable ()
61 Tabbable::set_allow_hide (bool yn)
64 tab_close_image.show ();
66 tab_close_image.hide ();
71 Tabbable::tab_close_clicked ()
77 Tabbable::add_to_notebook (Notebook& notebook, const string& tab_title)
79 _tab_label.set_text (tab_title);
82 notebook.append_page (_contents, _tab_box);
84 Gtkmm2ext::UI::instance()->set_tip (_tab_label,
85 string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
86 "To put the window back, click on its \"close\" button"), tab_title));
88 notebook.set_tab_detachable (_contents);
89 notebook.set_tab_reorderable (_contents);
91 _parent_notebook = ¬ebook;
92 _tab_title = tab_title;
96 Tabbable::use_own_window (bool and_pack_it)
98 Gtk::Window* win = get (true);
101 Gtk::Container* parent = _contents.get_parent();
103 parent->remove (_contents);
105 _own_notebook.append_page (_contents, _tab_box);
113 Tabbable::window_visible ()
123 Tabbable::get (bool create)
133 /* From here on, we're creating the window
136 if ((_window = new Window (WINDOW_TOPLEVEL)) == 0) {
140 _window->add (_own_notebook);
141 _own_notebook.show ();
142 _own_notebook.set_show_tabs (false);
144 /* do other window-related setup */
148 /* window should be ready for derived classes to do something with it */
154 Tabbable::show_own_window (bool and_pack_it)
156 Gtk::Widget* parent = _contents.get_parent();
157 Gtk::Allocation alloc;
160 alloc = parent->get_allocation();
163 (void) use_own_window (and_pack_it);
166 _window->set_default_size (alloc.get_width(), alloc.get_height());
169 _window->show_all ();
174 Tabbable::tab_root_drop ()
176 /* This is called after a drop of a tab onto the root window. Its
177 * responsibility xois to return the notebook that this Tabbable's
178 * contents should be packed into before the drop handling is
179 * completed. It is not responsible for actually taking care of this
183 show_own_window (false);
184 return &_own_notebook;
188 Tabbable::show_window ()
192 if (_window && (current_toplevel() == _window)) {
193 if (!_visible) { /* was hidden, update status */
200 Tabbable::make_visible ()
202 if (_window && (current_toplevel() == _window)) {
210 Tabbable::make_invisible ()
212 if (_window && (current_toplevel() == _window)) {
222 show_own_window (true);
228 if (!_parent_notebook) {
232 if (_parent_notebook->page_num (_contents) >= 0) {
238 if (_window && current_toplevel() == _window) {
239 /* unpack Tabbable from parent, put it back in the main tabbed
243 save_pos_and_size ();
245 _contents.get_parent()->remove (_contents);
247 /* leave the window around */
252 _parent_notebook->append_page (_contents, _tab_box);
253 _parent_notebook->set_tab_detachable (_contents);
254 _parent_notebook->set_tab_reorderable (_contents);
255 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
259 Tabbable::delete_event_handler (GdkEventAny *ev)
267 Tabbable::is_tabbed () const
269 Window* toplevel = (Window*) _contents.get_toplevel();
271 if (_window && (toplevel == _window)) {
275 if (_parent_notebook && _contents.get_parent()) {
283 Tabbable::hide_tab ()
285 if (_parent_notebook) {
286 _parent_notebook->remove_page (_contents);
291 Tabbable::show_tab ()
293 if (!window_visible() && _parent_notebook) {
294 if (_contents.get_parent() == 0) {
295 add_to_notebook (*_parent_notebook, _tab_title);
297 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
302 Tabbable::current_toplevel () const
304 return dynamic_cast<Gtk::Window*> (contents().get_toplevel());
308 Tabbable::xml_node_name()
310 return WindowProxy::xml_node_name();
314 Tabbable::get_state()
316 XMLNode& node (WindowProxy::get_state());
322 Tabbable::set_state (const XMLNode& node, int version)
326 if ((ret = WindowProxy::set_state (node, version)) == 0) {
328 if (use_own_window (true) == 0) {