2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Paul Barton-Davis
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
2009-07-28 16:51:28 -04:00
|
|
|
#include <iostream>
|
2010-03-18 22:49:01 -04:00
|
|
|
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/tearoff.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gdk;
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
TearOff::TearOff (Widget& c, bool allow_resize)
|
2010-03-31 22:29:13 -04:00
|
|
|
: contents (c)
|
|
|
|
, own_window (Gtk::WINDOW_TOPLEVEL)
|
|
|
|
, tearoff_arrow (ARROW_DOWN, SHADOW_OUT)
|
|
|
|
, close_arrow (ARROW_UP, SHADOW_OUT)
|
|
|
|
, dragging (false)
|
|
|
|
, _visible (true)
|
|
|
|
, _torn (false)
|
|
|
|
, _can_be_torn_off (true)
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-03-18 22:49:01 -04:00
|
|
|
own_window_width = 0;
|
|
|
|
own_window_height = 0;
|
|
|
|
own_window_xpos = 0;
|
|
|
|
own_window_ypos = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
tearoff_event_box.add (tearoff_arrow);
|
|
|
|
tearoff_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
|
|
|
|
tearoff_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::tearoff_click));
|
|
|
|
|
2011-05-30 20:19:29 -04:00
|
|
|
tearoff_event_box.set_tooltip_text (_("Click to tear this into its own window"));
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
close_event_box.add (close_arrow);
|
|
|
|
close_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
|
|
|
|
close_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::close_click));
|
2010-07-23 09:15:59 -04:00
|
|
|
|
|
|
|
close_event_box.set_tooltip_text (_("Click to put this back in the main window"));
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
VBox* box1;
|
|
|
|
box1 = manage (new VBox);
|
|
|
|
box1->pack_start (close_event_box, false, false, 2);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
window_box.pack_end (*box1, false, false, 2);
|
2010-03-19 16:53:22 -04:00
|
|
|
|
|
|
|
own_window.add_events (KEY_PRESS_MASK|KEY_RELEASE_MASK|BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|POINTER_MOTION_MASK|POINTER_MOTION_HINT_MASK);
|
|
|
|
own_window.set_resizable (allow_resize);
|
2015-03-09 12:58:00 -04:00
|
|
|
own_window.set_type_hint (WINDOW_TYPE_HINT_UTILITY);
|
2010-03-19 16:53:22 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
own_window.add (window_box);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
own_window.signal_button_press_event().connect (mem_fun (*this, &TearOff::window_button_press));
|
|
|
|
own_window.signal_button_release_event().connect (mem_fun (*this, &TearOff::window_button_release));
|
|
|
|
own_window.signal_motion_notify_event().connect (mem_fun (*this, &TearOff::window_motion));
|
|
|
|
own_window.signal_delete_event().connect (mem_fun (*this, &TearOff::window_delete_event));
|
2010-03-19 16:53:22 -04:00
|
|
|
own_window.signal_realize().connect (sigc::mem_fun (*this, &TearOff::own_window_realized));
|
|
|
|
own_window.signal_configure_event().connect (sigc::mem_fun (*this, &TearOff::own_window_configured), false);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
tearoff_arrow.set_name ("TearOffArrow");
|
|
|
|
close_arrow.set_name ("TearOffArrow");
|
|
|
|
|
|
|
|
VBox* box2;
|
|
|
|
box2 = manage (new VBox);
|
2011-11-02 10:57:16 -04:00
|
|
|
box2->pack_start (tearoff_event_box, false, false);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
pack_start (contents);
|
2011-11-02 10:57:16 -04:00
|
|
|
pack_start (*box2, false, false);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TearOff::~TearOff ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
void
|
|
|
|
TearOff::set_can_be_torn_off (bool yn)
|
|
|
|
{
|
|
|
|
if (yn != _can_be_torn_off) {
|
|
|
|
if (yn) {
|
|
|
|
tearoff_arrow.set_no_show_all (false);
|
|
|
|
tearoff_arrow.show ();
|
|
|
|
} else {
|
|
|
|
tearoff_arrow.set_no_show_all (true);
|
|
|
|
tearoff_arrow.hide ();
|
|
|
|
}
|
|
|
|
_can_be_torn_off = yn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2011-01-02 22:11:31 -05:00
|
|
|
TearOff::set_visible (bool yn, bool force)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
/* don't change visibility if torn off */
|
|
|
|
|
2010-03-31 22:29:13 -04:00
|
|
|
if (_torn) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-02 22:11:31 -05:00
|
|
|
if (_visible != yn || force) {
|
2008-06-02 17:41:35 -04:00
|
|
|
_visible = yn;
|
|
|
|
if (yn) {
|
|
|
|
show_all();
|
|
|
|
Visible ();
|
|
|
|
} else {
|
|
|
|
hide ();
|
|
|
|
Hidden ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2009-07-21 11:55:17 -04:00
|
|
|
TearOff::tearoff_click (GdkEventButton* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-03-18 22:49:01 -04:00
|
|
|
tear_it_off ();
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-18 22:49:01 -04:00
|
|
|
void
|
|
|
|
TearOff::tear_it_off ()
|
|
|
|
{
|
|
|
|
if (!_can_be_torn_off) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2010-03-18 22:49:01 -04:00
|
|
|
if (torn_off()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove (contents);
|
|
|
|
window_box.pack_start (contents);
|
|
|
|
own_window.set_name (get_name());
|
|
|
|
close_event_box.set_name (get_name());
|
2010-07-23 09:15:59 -04:00
|
|
|
if (own_window_width == 0) {
|
|
|
|
own_window.set_position (WIN_POS_MOUSE);
|
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
own_window.show_all ();
|
|
|
|
own_window.present ();
|
|
|
|
hide ();
|
2010-03-31 22:29:13 -04:00
|
|
|
|
|
|
|
_torn = true;
|
|
|
|
|
2010-03-18 22:49:01 -04:00
|
|
|
Detach ();
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
gint
|
2009-07-21 11:55:17 -04:00
|
|
|
TearOff::close_click (GdkEventButton* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-03-18 22:49:01 -04:00
|
|
|
put_it_back ();
|
|
|
|
return true;
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
TearOff::put_it_back ()
|
|
|
|
{
|
|
|
|
if (!torn_off()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
window_box.remove (contents);
|
|
|
|
pack_start (contents);
|
|
|
|
reorder_child (contents, 0);
|
|
|
|
own_window.hide ();
|
|
|
|
show_all ();
|
2010-03-31 22:29:13 -04:00
|
|
|
|
|
|
|
_torn = false;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
Attach ();
|
2010-03-18 22:49:01 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_button_press (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
if (dragging || ev->button != 1) {
|
|
|
|
dragging = false;
|
|
|
|
own_window.remove_modal_grab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dragging = true;
|
|
|
|
drag_x = ev->x_root;
|
|
|
|
drag_y = ev->y_root;
|
|
|
|
|
|
|
|
own_window.add_modal_grab();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2009-07-21 11:55:17 -04:00
|
|
|
TearOff::window_button_release (GdkEventButton* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
dragging = false;
|
|
|
|
own_window.remove_modal_grab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2009-07-21 11:55:17 -04:00
|
|
|
TearOff::window_delete_event (GdkEventAny* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
return close_click(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_motion (GdkEventMotion* ev)
|
|
|
|
{
|
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
gint mx, my;
|
|
|
|
double x_delta;
|
|
|
|
double y_delta;
|
|
|
|
RefPtr<Gdk::Window> win (own_window.get_window());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
own_window.get_pointer (mx, my);
|
|
|
|
|
|
|
|
if (!dragging) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ev->state & GDK_BUTTON1_MASK)) {
|
|
|
|
dragging = false;
|
|
|
|
own_window.remove_modal_grab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
x_delta = ev->x_root - drag_x;
|
|
|
|
y_delta = ev->y_root - drag_y;
|
|
|
|
|
|
|
|
win->get_root_origin (x, y);
|
|
|
|
win->move ((gint) floor (x + x_delta), (gint) floor (y + y_delta));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
drag_x = ev->x_root;
|
|
|
|
drag_y = ev->y_root;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TearOff::torn_off() const
|
|
|
|
{
|
2010-03-31 22:29:13 -04:00
|
|
|
return _torn;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
|
|
|
void
|
2010-03-19 16:53:22 -04:00
|
|
|
TearOff::add_state (XMLNode& node) const
|
2010-03-18 22:49:01 -04:00
|
|
|
{
|
2016-08-28 09:43:02 -04:00
|
|
|
node.set_property ("tornoff", _torn);
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2016-08-28 09:43:02 -04:00
|
|
|
if (own_window_width > 0) {
|
|
|
|
node.set_property ("width", own_window_width);
|
|
|
|
node.set_property ("height", own_window_height);
|
|
|
|
node.set_property ("xpos", own_window_xpos);
|
|
|
|
node.set_property ("ypos", own_window_ypos);
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
|
|
|
void
|
2010-03-19 16:53:22 -04:00
|
|
|
TearOff::set_state (const XMLNode& node)
|
2010-03-18 22:49:01 -04:00
|
|
|
{
|
2016-08-28 09:43:02 -04:00
|
|
|
Glib::RefPtr<Gdk::Window> win;
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2016-08-28 09:43:02 -04:00
|
|
|
bool tornoff;
|
|
|
|
if (!node.get_property (X_("tornoff"), tornoff)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2016-08-28 09:43:02 -04:00
|
|
|
if (tornoff) {
|
|
|
|
tear_it_off ();
|
|
|
|
} else {
|
|
|
|
put_it_back ();
|
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2016-08-28 09:43:02 -04:00
|
|
|
node.get_property (X_("width"), own_window_width);
|
|
|
|
node.get_property (X_("height"), own_window_height);
|
|
|
|
node.get_property (X_("xpos"), own_window_xpos);
|
|
|
|
node.get_property (X_("ypos"), own_window_ypos);
|
2010-03-18 22:49:01 -04:00
|
|
|
|
2016-08-28 09:43:02 -04:00
|
|
|
if (own_window.is_realized ()) {
|
|
|
|
own_window.set_default_size (own_window_width, own_window_height);
|
|
|
|
own_window.move (own_window_xpos, own_window_ypos);
|
|
|
|
}
|
|
|
|
/* otherwise do it once the window is realized, see below */
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2010-03-18 22:49:01 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
TearOff::own_window_realized ()
|
|
|
|
{
|
2010-03-19 16:53:22 -04:00
|
|
|
own_window.get_window()->set_decorations (WMDecoration (DECOR_BORDER|DECOR_RESIZEH));
|
|
|
|
|
2010-03-18 22:49:01 -04:00
|
|
|
if (own_window_width > 0) {
|
|
|
|
own_window.set_default_size (own_window_width, own_window_height);
|
|
|
|
own_window.move (own_window_xpos, own_window_ypos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TearOff::own_window_configured (GdkEventConfigure*)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<const Gdk::Window> win;
|
|
|
|
|
|
|
|
win = own_window.get_window ();
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2010-03-18 22:49:01 -04:00
|
|
|
if (win) {
|
|
|
|
win->get_size (own_window_width, own_window_height);
|
|
|
|
win->get_position (own_window_xpos, own_window_ypos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-19 16:53:22 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
TearOff::hide_visible ()
|
|
|
|
{
|
|
|
|
if (torn_off()) {
|
|
|
|
own_window.hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|