2005-05-13 16:47:18 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Paul Barton-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.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <gtkmm2ext/tearoff.h>
|
2005-11-25 19:06:46 -05:00
|
|
|
#include <gtkmm2ext/utils.h>
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
2006-01-01 12:23:34 -05:00
|
|
|
using namespace Gdk;
|
|
|
|
using namespace Glib;
|
2005-05-13 16:47:18 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2006-01-01 12:23:34 -05:00
|
|
|
TearOff::TearOff (Widget& c, bool allow_resize)
|
2005-05-13 16:47:18 -04:00
|
|
|
: contents (c),
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window (Gtk::WINDOW_TOPLEVEL),
|
|
|
|
tearoff_arrow (ARROW_DOWN, SHADOW_OUT),
|
|
|
|
close_arrow (ARROW_UP, SHADOW_OUT)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
dragging = false;
|
2006-01-19 13:05:31 -05:00
|
|
|
_visible = true;
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
tearoff_event_box.add (tearoff_arrow);
|
2006-01-01 12:23:34 -05:00
|
|
|
tearoff_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
|
2005-05-13 16:47:18 -04:00
|
|
|
tearoff_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::tearoff_click));
|
|
|
|
|
|
|
|
close_event_box.add (close_arrow);
|
2006-01-01 12:23:34 -05:00
|
|
|
close_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
|
2005-05-13 16:47:18 -04:00
|
|
|
close_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::close_click));
|
|
|
|
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.add_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|POINTER_MOTION_MASK|POINTER_MOTION_HINT_MASK);
|
|
|
|
own_window.set_resizable (allow_resize);
|
|
|
|
own_window.set_type_hint (WINDOW_TYPE_HINT_TOOLBAR);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
VBox* box1;
|
|
|
|
box1 = manage (new VBox);
|
|
|
|
box1->pack_start (close_event_box, false, false, 5);
|
|
|
|
|
|
|
|
window_box.pack_end (*box1, false, false, 2);
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.add (window_box);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-01-01 12:23:34 -05: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));
|
|
|
|
own_window.signal_realize().connect (bind (sigc::ptr_fun (Gtkmm2ext::set_decoration), &own_window, WMDecoration (DECOR_BORDER|DECOR_RESIZEH)));
|
2005-11-25 19:06:46 -05:00
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
tearoff_arrow.set_name ("TearOffArrow");
|
|
|
|
close_arrow.set_name ("TearOffArrow");
|
|
|
|
|
|
|
|
VBox* box2;
|
|
|
|
box2 = manage (new VBox);
|
|
|
|
box2->pack_start (tearoff_event_box, false, false, 5);
|
|
|
|
|
|
|
|
pack_start (contents);
|
|
|
|
pack_start (*box2, false, false, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TearOff::~TearOff ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-01-19 13:05:31 -05:00
|
|
|
void
|
|
|
|
TearOff::set_visible (bool yn)
|
|
|
|
{
|
|
|
|
/* don't change visibility if torn off */
|
|
|
|
|
|
|
|
if (own_window.is_visible()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_visible != yn) {
|
|
|
|
_visible = yn;
|
|
|
|
if (yn) {
|
|
|
|
show_all();
|
|
|
|
Visible ();
|
|
|
|
} else {
|
|
|
|
hide ();
|
|
|
|
Hidden ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
gint
|
|
|
|
TearOff::tearoff_click (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
remove (contents);
|
|
|
|
window_box.pack_start (contents);
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.set_name (get_name());
|
2005-05-13 16:47:18 -04:00
|
|
|
close_event_box.set_name (get_name());
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.show_all ();
|
2005-05-13 16:47:18 -04:00
|
|
|
hide ();
|
|
|
|
Detach ();
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::close_click (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
window_box.remove (contents);
|
|
|
|
pack_start (contents);
|
|
|
|
reorder_child (contents, 0);
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.hide ();
|
2005-05-13 16:47:18 -04:00
|
|
|
show_all ();
|
|
|
|
Attach ();
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_button_press (GdkEventButton* ev)
|
|
|
|
{
|
2006-11-17 12:51:22 -05:00
|
|
|
if (dragging) {
|
|
|
|
dragging = false;
|
|
|
|
own_window.remove_modal_grab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
dragging = true;
|
|
|
|
drag_x = ev->x_root;
|
|
|
|
drag_y = ev->y_root;
|
|
|
|
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.add_modal_grab();
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_button_release (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
dragging = false;
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.remove_modal_grab();
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_delete_event (GdkEventAny* ev)
|
|
|
|
{
|
|
|
|
return close_click(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
TearOff::window_motion (GdkEventMotion* ev)
|
|
|
|
{
|
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
gint mx, my;
|
|
|
|
double x_delta;
|
|
|
|
double y_delta;
|
2006-01-01 12:23:34 -05:00
|
|
|
RefPtr<Gdk::Window> win (own_window.get_window());
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-01-01 12:23:34 -05:00
|
|
|
own_window.get_pointer (mx, my);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (!dragging) {
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
drag_x = ev->x_root;
|
|
|
|
drag_y = ev->y_root;
|
|
|
|
|
2006-11-17 12:51:22 -05:00
|
|
|
return true;
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TearOff::torn_off() const
|
|
|
|
{
|
2006-01-01 12:23:34 -05:00
|
|
|
return own_window.is_visible();
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|