2015-07-03 15:06:29 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtkmm/action.h>
|
|
|
|
#include <gtkmm/notebook.h>
|
|
|
|
#include <gtkmm/window.h>
|
2015-07-21 21:10:46 -04:00
|
|
|
#include <gtkmm/stock.h>
|
2015-07-03 15:06:29 -04:00
|
|
|
|
|
|
|
#include "gtkmm2ext/tabbable.h"
|
2015-07-09 13:27:39 -04:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
2015-07-21 22:37:39 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2015-07-03 15:06:29 -04:00
|
|
|
#include "gtkmm2ext/visibility_tracker.h"
|
|
|
|
|
2015-07-09 12:40:51 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
|
|
|
using std::string;
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
Tabbable::Tabbable (Widget& w, const string& name)
|
|
|
|
: WindowProxy (name)
|
|
|
|
, _contents (w)
|
2015-07-21 22:37:39 -04:00
|
|
|
, tab_close_image (ArdourIcon::CloseCross, 0xffffffff)
|
2015-07-22 17:49:03 -04:00
|
|
|
, tab_requested_by_state (true)
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-23 17:22:05 -04:00
|
|
|
/* sizes will be scaled during rendering */
|
2015-07-23 08:35:24 -04:00
|
|
|
tab_close_image.set_size_request (15,15);
|
2015-07-25 08:41:26 -04:00
|
|
|
|
|
|
|
_tab_box.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
|
2015-07-21 22:37:39 -04:00
|
|
|
_tab_box.set_spacing (2);
|
2015-07-21 21:10:46 -04:00
|
|
|
_tab_box.pack_start (_tab_label, true, true);
|
2015-07-23 17:22:05 -04:00
|
|
|
_tab_box.pack_start (tab_close_image, false, false);
|
2015-07-25 08:41:26 -04:00
|
|
|
|
2015-07-23 17:22:05 -04:00
|
|
|
tab_close_image.signal_button_release_event().connect (sigc::mem_fun (*this, &Tabbable::tab_close_clicked));
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Tabbable::~Tabbable ()
|
|
|
|
{
|
|
|
|
if (_window) {
|
|
|
|
delete _window;
|
|
|
|
_window = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 17:22:05 -04:00
|
|
|
bool
|
|
|
|
Tabbable::tab_close_clicked (GdkEventButton*)
|
2015-07-22 15:22:23 -04:00
|
|
|
{
|
|
|
|
hide_tab ();
|
2015-07-23 17:22:05 -04:00
|
|
|
return true;
|
2015-07-22 15:22:23 -04:00
|
|
|
}
|
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
void
|
2015-07-09 13:27:39 -04:00
|
|
|
Tabbable::add_to_notebook (Notebook& notebook, const string& tab_title)
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-22 17:49:03 -04:00
|
|
|
_parent_notebook = ¬ebook;
|
|
|
|
_tab_title = tab_title;
|
2015-07-21 21:10:46 -04:00
|
|
|
_tab_label.set_text (tab_title);
|
|
|
|
_tab_box.show_all ();
|
2015-07-21 22:37:39 -04:00
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
if (tab_requested_by_state) {
|
|
|
|
attach ();
|
|
|
|
}
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Window*
|
2015-07-09 12:40:51 -04:00
|
|
|
Tabbable::use_own_window (bool and_pack_it)
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-09 12:40:51 -04:00
|
|
|
Gtk::Window* win = get (true);
|
|
|
|
|
|
|
|
if (and_pack_it) {
|
|
|
|
Gtk::Container* parent = _contents.get_parent();
|
|
|
|
if (parent) {
|
|
|
|
parent->remove (_contents);
|
|
|
|
}
|
2015-07-21 21:10:46 -04:00
|
|
|
_own_notebook.append_page (_contents, _tab_box);
|
2015-07-09 12:40:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return win;
|
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-25 09:18:32 -04:00
|
|
|
Tabbable::window_visible () const
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-25 09:18:32 -04:00
|
|
|
if (!_window) {
|
2015-07-03 15:06:29 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-22 21:13:33 -04:00
|
|
|
return _window->is_visible();
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Window*
|
|
|
|
Tabbable::get (bool create)
|
|
|
|
{
|
|
|
|
if (_window) {
|
|
|
|
return _window;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!create) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-07 22:12:21 -04:00
|
|
|
|
|
|
|
/* From here on, we're creating the window
|
|
|
|
*/
|
2015-07-03 15:06:29 -04:00
|
|
|
|
|
|
|
if ((_window = new Window (WINDOW_TOPLEVEL)) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
_window->add (_own_notebook);
|
|
|
|
_own_notebook.show ();
|
|
|
|
_own_notebook.set_show_tabs (false);
|
|
|
|
|
2015-07-23 08:35:24 -04:00
|
|
|
_window->signal_map().connect (sigc::mem_fun (*this, &Tabbable::window_mapped));
|
|
|
|
_window->signal_unmap().connect (sigc::mem_fun (*this, &Tabbable::window_unmapped));
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
/* do other window-related setup */
|
|
|
|
|
|
|
|
setup ();
|
2015-07-03 15:06:29 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
/* window should be ready for derived classes to do something with it */
|
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
return _window;
|
|
|
|
}
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
void
|
|
|
|
Tabbable::show_own_window (bool and_pack_it)
|
2015-07-07 22:12:21 -04:00
|
|
|
{
|
2015-07-22 15:22:23 -04:00
|
|
|
Gtk::Widget* parent = _contents.get_parent();
|
2015-07-08 13:13:47 -04:00
|
|
|
Gtk::Allocation alloc;
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
if (parent) {
|
|
|
|
alloc = parent->get_allocation();
|
|
|
|
}
|
2015-07-08 13:13:47 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
(void) use_own_window (and_pack_it);
|
2015-07-07 22:12:21 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
if (parent) {
|
|
|
|
_window->set_default_size (alloc.get_width(), alloc.get_height());
|
|
|
|
}
|
|
|
|
|
2015-07-25 09:18:32 -04:00
|
|
|
tab_requested_by_state = false;
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
_window->show_all ();
|
|
|
|
_window->present ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::Notebook*
|
|
|
|
Tabbable::tab_root_drop ()
|
|
|
|
{
|
2015-07-07 22:12:21 -04:00
|
|
|
/* This is called after a drop of a tab onto the root window. Its
|
2015-07-22 15:22:23 -04:00
|
|
|
* responsibility xois to return the notebook that this Tabbable's
|
2015-07-07 22:12:21 -04:00
|
|
|
* contents should be packed into before the drop handling is
|
|
|
|
* completed. It is not responsible for actually taking care of this
|
|
|
|
* packing.
|
|
|
|
*/
|
2015-07-08 13:13:47 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
show_own_window (false);
|
2015-07-07 22:12:21 -04:00
|
|
|
return &_own_notebook;
|
|
|
|
}
|
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
void
|
|
|
|
Tabbable::show_window ()
|
|
|
|
{
|
2015-07-21 21:10:46 -04:00
|
|
|
make_visible ();
|
2015-07-03 15:06:29 -04:00
|
|
|
|
2015-07-21 21:10:46 -04:00
|
|
|
if (_window && (current_toplevel() == _window)) {
|
|
|
|
if (!_visible) { /* was hidden, update status */
|
|
|
|
set_pos_and_size ();
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
void
|
|
|
|
Tabbable::make_visible ()
|
|
|
|
{
|
|
|
|
if (_window && (current_toplevel() == _window)) {
|
|
|
|
_window->present ();
|
|
|
|
} else {
|
2015-07-22 17:49:03 -04:00
|
|
|
|
|
|
|
if (!tab_requested_by_state) {
|
|
|
|
show_own_window (true);
|
|
|
|
} else {
|
|
|
|
show_tab ();
|
|
|
|
}
|
2015-07-22 15:22:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Tabbable::make_invisible ()
|
|
|
|
{
|
|
|
|
if (_window && (current_toplevel() == _window)) {
|
|
|
|
_window->hide ();
|
|
|
|
} else {
|
|
|
|
hide_tab ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Tabbable::detach ()
|
|
|
|
{
|
|
|
|
show_own_window (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Tabbable::attach ()
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-22 15:22:23 -04:00
|
|
|
if (!_parent_notebook) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
if (tabbed()) {
|
2015-07-22 15:22:23 -04:00
|
|
|
/* already tabbed */
|
|
|
|
return;
|
|
|
|
}
|
2015-07-03 15:06:29 -04:00
|
|
|
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
if (_window && current_toplevel() == _window) {
|
2015-07-03 15:06:29 -04:00
|
|
|
/* unpack Tabbable from parent, put it back in the main tabbed
|
|
|
|
* notebook
|
|
|
|
*/
|
2015-07-22 15:22:23 -04:00
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
save_pos_and_size ();
|
2015-07-22 15:22:23 -04:00
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
_contents.get_parent()->remove (_contents);
|
2015-07-22 15:22:23 -04:00
|
|
|
|
2015-07-03 15:06:29 -04:00
|
|
|
/* leave the window around */
|
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
_window->hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
_parent_notebook->append_page (_contents, _tab_box);
|
2015-07-25 08:41:26 -04:00
|
|
|
_contents.set_data ("close-button", &tab_close_image);
|
2015-07-22 15:22:23 -04:00
|
|
|
_parent_notebook->set_tab_detachable (_contents);
|
|
|
|
_parent_notebook->set_tab_reorderable (_contents);
|
|
|
|
_parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
|
2015-07-22 17:49:03 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tab_requested_by_state = true;
|
2015-07-22 21:13:33 -04:00
|
|
|
StateChange (*this);
|
2015-07-22 15:22:23 -04:00
|
|
|
}
|
2015-07-03 15:06:29 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
bool
|
|
|
|
Tabbable::delete_event_handler (GdkEventAny *ev)
|
|
|
|
{
|
|
|
|
_window->hide();
|
2015-07-03 15:06:29 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
return true;
|
2015-07-03 15:06:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-25 09:18:32 -04:00
|
|
|
Tabbable::tabbed () const
|
2015-07-03 15:06:29 -04:00
|
|
|
{
|
2015-07-25 09:18:32 -04:00
|
|
|
if (_window && (current_toplevel() == _window)) {
|
2015-07-03 15:06:29 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-25 09:18:32 -04:00
|
|
|
if (_parent_notebook && (_parent_notebook->page_num (_contents) >= 0)) {
|
2015-07-03 15:06:29 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-07 22:12:21 -04:00
|
|
|
|
2015-07-22 15:22:23 -04:00
|
|
|
void
|
|
|
|
Tabbable::hide_tab ()
|
|
|
|
{
|
2015-07-22 17:49:03 -04:00
|
|
|
if (tabbed()) {
|
2015-07-22 15:22:23 -04:00
|
|
|
_parent_notebook->remove_page (_contents);
|
2015-07-22 21:13:33 -04:00
|
|
|
StateChange (*this);
|
2015-07-22 15:22:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
void
|
|
|
|
Tabbable::show_tab ()
|
|
|
|
{
|
|
|
|
if (!window_visible() && _parent_notebook) {
|
2015-07-21 21:10:46 -04:00
|
|
|
if (_contents.get_parent() == 0) {
|
2015-07-23 08:35:24 -04:00
|
|
|
tab_requested_by_state = true;
|
2015-07-21 21:10:46 -04:00
|
|
|
add_to_notebook (*_parent_notebook, _tab_title);
|
|
|
|
}
|
2015-07-07 22:12:21 -04:00
|
|
|
_parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::Window*
|
|
|
|
Tabbable::current_toplevel () const
|
|
|
|
{
|
|
|
|
return dynamic_cast<Gtk::Window*> (contents().get_toplevel());
|
|
|
|
}
|
2015-07-09 12:40:51 -04:00
|
|
|
|
|
|
|
string
|
|
|
|
Tabbable::xml_node_name()
|
|
|
|
{
|
|
|
|
return WindowProxy::xml_node_name();
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
bool
|
2015-07-25 09:18:32 -04:00
|
|
|
Tabbable::tabbed_by_default() const
|
2015-07-22 17:49:03 -04:00
|
|
|
{
|
2015-07-25 09:18:32 -04:00
|
|
|
return tab_requested_by_state;
|
2015-07-22 17:49:03 -04:00
|
|
|
}
|
|
|
|
|
2015-07-09 12:40:51 -04:00
|
|
|
XMLNode&
|
|
|
|
Tabbable::get_state()
|
|
|
|
{
|
|
|
|
XMLNode& node (WindowProxy::get_state());
|
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
node.add_property (X_("tabbed"), tabbed() ? X_("yes") : X_("no"));
|
|
|
|
|
2015-07-09 12:40:51 -04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Tabbable::set_state (const XMLNode& node, int version)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-07-23 17:22:05 -04:00
|
|
|
if ((ret = WindowProxy::set_state (node, version)) != 0) {
|
|
|
|
return ret;
|
2015-07-09 12:40:51 -04:00
|
|
|
}
|
|
|
|
|
2015-07-23 17:22:05 -04:00
|
|
|
if (_visible) {
|
|
|
|
show_own_window (true);
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
XMLNodeList children = node.children ();
|
|
|
|
XMLNode* window_node = node.child ("Window");
|
2015-07-23 17:22:05 -04:00
|
|
|
|
2015-07-22 17:49:03 -04:00
|
|
|
if (window_node) {
|
|
|
|
const XMLProperty* prop = window_node->property (X_("tabbed"));
|
|
|
|
if (prop) {
|
|
|
|
tab_requested_by_state = PBD::string_is_affirmative (prop->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 17:22:05 -04:00
|
|
|
if (!_visible) {
|
|
|
|
if (tab_requested_by_state) {
|
|
|
|
attach ();
|
|
|
|
} else {
|
|
|
|
/* this does nothing if not tabbed */
|
|
|
|
hide_tab ();
|
2015-07-23 08:35:24 -04:00
|
|
|
}
|
2015-07-22 17:49:03 -04:00
|
|
|
}
|
|
|
|
|
2015-07-09 12:40:51 -04:00
|
|
|
return ret;
|
|
|
|
}
|
2015-07-15 16:23:11 -04:00
|
|
|
|
2015-07-23 08:35:24 -04:00
|
|
|
void
|
|
|
|
Tabbable::window_mapped ()
|
|
|
|
{
|
|
|
|
StateChange (*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Tabbable::window_unmapped ()
|
|
|
|
{
|
|
|
|
StateChange (*this);
|
|
|
|
}
|
|
|
|
|