2 Copyright (C) 2003 Paul Barton-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.
22 #include <gtkmm2ext/tearoff.h>
23 #include <gtkmm2ext/utils.h>
25 using namespace Gtkmm2ext;
31 TearOff::TearOff (Widget& c, bool allow_resize)
33 own_window (Gtk::WINDOW_TOPLEVEL),
34 tearoff_arrow (ARROW_DOWN, SHADOW_OUT),
35 close_arrow (ARROW_UP, SHADOW_OUT)
40 tearoff_event_box.add (tearoff_arrow);
41 tearoff_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
42 tearoff_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::tearoff_click));
44 close_event_box.add (close_arrow);
45 close_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
46 close_event_box.signal_button_release_event().connect (mem_fun (*this, &TearOff::close_click));
48 own_window.add_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|POINTER_MOTION_MASK|POINTER_MOTION_HINT_MASK);
49 own_window.set_resizable (allow_resize);
50 own_window.set_type_hint (WINDOW_TYPE_HINT_TOOLBAR);
53 box1 = manage (new VBox);
54 box1->pack_start (close_event_box, false, false, 2);
56 window_box.pack_end (*box1, false, false, 2);
57 own_window.add (window_box);
59 own_window.signal_button_press_event().connect (mem_fun (*this, &TearOff::window_button_press));
60 own_window.signal_button_release_event().connect (mem_fun (*this, &TearOff::window_button_release));
61 own_window.signal_motion_notify_event().connect (mem_fun (*this, &TearOff::window_motion));
62 own_window.signal_delete_event().connect (mem_fun (*this, &TearOff::window_delete_event));
63 own_window.signal_realize().connect (bind (sigc::ptr_fun (Gtkmm2ext::set_decoration), &own_window, WMDecoration (DECOR_BORDER|DECOR_RESIZEH)));
65 tearoff_arrow.set_name ("TearOffArrow");
66 close_arrow.set_name ("TearOffArrow");
69 box2 = manage (new VBox);
70 box2->pack_start (tearoff_event_box, false, false, 2);
72 pack_start (contents);
73 pack_start (*box2, false, false, 2);
82 TearOff::set_visible (bool yn)
84 /* don't change visibility if torn off */
86 if (own_window.is_visible()) {
103 TearOff::tearoff_click (GdkEventButton* ev)
106 window_box.pack_start (contents);
107 own_window.set_name (get_name());
108 close_event_box.set_name (get_name());
109 own_window.show_all ();
116 TearOff::close_click (GdkEventButton* ev)
118 window_box.remove (contents);
119 pack_start (contents);
120 reorder_child (contents, 0);
128 TearOff::window_button_press (GdkEventButton* ev)
134 own_window.add_modal_grab();
140 TearOff::window_button_release (GdkEventButton* ev)
143 own_window.remove_modal_grab();
148 TearOff::window_delete_event (GdkEventAny* ev)
150 return close_click(0);
154 TearOff::window_motion (GdkEventMotion* ev)
161 RefPtr<Gdk::Window> win (own_window.get_window());
163 own_window.get_pointer (mx, my);
169 x_delta = ev->x_root - drag_x;
170 y_delta = ev->y_root - drag_y;
172 win->get_root_origin (x, y);
173 win->move ((gint) floor (x + x_delta), (gint) floor (y + y_delta));
182 TearOff::torn_off() const
184 return own_window.is_visible();