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>
24 #include "gtkmm2ext/tabbable.h"
25 #include "gtkmm2ext/visibility_tracker.h"
29 using namespace Gtkmm2ext;
33 Tabbable::Tabbable (Widget& w, const string& name)
39 Tabbable::~Tabbable ()
48 Tabbable::add_to_notebook (Notebook& notebook, const string& tab_title, int position)
50 notebook.insert_page (_contents, tab_title, position, false);
51 notebook.set_tab_detachable (_contents);
52 notebook.set_tab_reorderable (_contents);
54 _parent_notebook = ¬ebook;
55 _tab_title = tab_title;
56 _notebook_position = position;
60 Tabbable::use_own_window (bool and_pack_it)
62 Gtk::Window* win = get (true);
65 Gtk::Container* parent = _contents.get_parent();
67 parent->remove (_contents);
69 _own_notebook.append_page (_contents, _tab_title);
77 Tabbable::window_visible ()
87 Tabbable::get (bool create)
97 /* From here on, we're creating the window
100 if ((_window = new Window (WINDOW_TOPLEVEL)) == 0) {
104 _window->add (_own_notebook);
105 _own_notebook.show ();
106 _own_notebook.set_show_tabs (false);
108 /* do other window-related setup */
112 /* window should be ready for derived classes to do something with it */
118 Tabbable::tab_root_drop ()
120 Gtk::Allocation alloc;
122 alloc = _contents.get_parent()->get_allocation();
124 (void) use_own_window (false);
126 /* This is called after a drop of a tab onto the root window. Its
127 * responsibility is to return the notebook that this Tabbable's
128 * contents should be packed into before the drop handling is
129 * completed. It is not responsible for actually taking care of this
133 _window->set_default_size (alloc.get_width(), alloc.get_height());
134 _window->show_all ();
137 return &_own_notebook;
141 Tabbable::show_window ()
143 Window* toplevel = dynamic_cast<Window*> (_contents.get_toplevel());
145 if (toplevel == _window) {
149 if (!_visible) { /* was hidden, update status */
153 if (toplevel != _window) {
154 /* not in its own window, just switch parent notebook to show
157 if (_parent_notebook) {
158 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
164 Tabbable::delete_event_handler (GdkEventAny *ev)
166 Window* toplevel = dynamic_cast<Window*> (_contents.get_toplevel());
168 if (_window == toplevel) {
170 /* unpack Tabbable from parent, put it back in the main tabbed
174 save_pos_and_size ();
176 _contents.get_parent()->remove (_contents);
178 /* leave the window around */
182 if (_parent_notebook) {
184 _parent_notebook->insert_page (_contents, _tab_title, _notebook_position);
185 _parent_notebook->set_tab_detachable (_contents);
186 _parent_notebook->set_tab_reorderable (_contents);
187 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
190 /* don't let anything else handle this */
200 Tabbable::is_tabbed () const
202 Window* toplevel = (Window*) _contents.get_toplevel();
204 if (_window && (toplevel == _window)) {
208 if (_parent_notebook) {
216 Tabbable::show_tab ()
218 if (!window_visible() && _parent_notebook) {
219 _parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
224 Tabbable::current_toplevel () const
226 return dynamic_cast<Gtk::Window*> (contents().get_toplevel());
230 Tabbable::xml_node_name()
232 return WindowProxy::xml_node_name();
236 Tabbable::get_state()
238 XMLNode& node (WindowProxy::get_state());
244 Tabbable::set_state (const XMLNode& node, int version)
248 if ((ret = WindowProxy::set_state (node, version)) == 0) {
250 if (use_own_window (true) == 0) {