Add test for Glib::Mutex::trylock
[ardour.git] / libs / gtkmm2ext / tearoff.cc
index 32f440f37978ca3903b2661fd3aba53909183dfb..f0bacb593b5e79ea09ad28b9140ffe497300f88d 100644 (file)
@@ -35,14 +35,16 @@ using namespace Glib;
 using namespace std;
 
 TearOff::TearOff (Widget& c, bool allow_resize)
-       : contents (c),
-         own_window (Gtk::WINDOW_TOPLEVEL),
-         tearoff_arrow (ARROW_DOWN, SHADOW_OUT),
-         close_arrow (ARROW_UP, SHADOW_OUT)
+       : 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)
+         
 {
-       dragging = false;
-       _visible = true;
-       _can_be_torn_off = true;
         own_window_width = 0;
         own_window_height = 0;
         own_window_xpos = 0;
@@ -52,10 +54,13 @@ TearOff::TearOff (Widget& c, bool allow_resize)
        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));
 
+       tearoff_event_box.set_tooltip_text (_("Click to tear this into its own window"));
+        
        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));
-       
+
+        close_event_box.set_tooltip_text (_("Click to put this back in the main window"));
 
        VBox* box1;
        box1 = manage (new VBox);
@@ -81,10 +86,10 @@ TearOff::TearOff (Widget& c, bool allow_resize)
 
        VBox* box2;
        box2 = manage (new VBox);
-       box2->pack_start (tearoff_event_box, false, false, 2);
+       box2->pack_start (tearoff_event_box, false, false);
 
        pack_start (contents);
-       pack_start (*box2, false, false, 2);
+       pack_start (*box2, false, false);
 }
 
 TearOff::~TearOff ()
@@ -107,15 +112,15 @@ TearOff::set_can_be_torn_off (bool yn)
 }
 
 void
-TearOff::set_visible (bool yn)
+TearOff::set_visible (bool yn, bool force)
 {
        /* don't change visibility if torn off */
 
-       if (own_window.is_visible()) {
+       if (_torn) {
                return;
        }
 
-       if (_visible != yn) {
+       if (_visible != yn || force) {
                _visible = yn;
                if (yn) {
                        show_all();
@@ -149,9 +154,15 @@ TearOff::tear_it_off ()
         window_box.pack_start (contents);
         own_window.set_name (get_name());
         close_event_box.set_name (get_name());
+        if (own_window_width == 0) {
+                own_window.set_position (WIN_POS_MOUSE);
+        }
         own_window.show_all ();
         own_window.present ();
         hide ();
+
+        _torn = true;
+
         Detach ();
 }        
 
@@ -174,6 +185,9 @@ TearOff::put_it_back ()
        reorder_child (contents, 0);
        own_window.hide ();
        show_all ();
+
+        _torn = false;
+
        Attach ();
 }
 
@@ -246,13 +260,13 @@ TearOff::window_motion (GdkEventMotion* ev)
 bool
 TearOff::torn_off() const
 {
-       return own_window.is_visible();
+       return _torn;
 }
 
 void
 TearOff::add_state (XMLNode& node) const
 {
-        node.add_property ("tornoff", (own_window.is_visible() ? "yes" : "no"));
+        node.add_property ("tornoff", (_torn ? "yes" : "no"));
 
         if (own_window_width > 0) {
                 char buf[32];
@@ -279,10 +293,8 @@ TearOff::set_state (const XMLNode& node)
         }
 
         if (prop->value() == "yes") {
-                cerr << "Tearing off " << node.name() << endl;
                 tear_it_off ();
         } else {
-                cerr << "Putting back " << node.name() << endl;
                 put_it_back ();
         }
 
@@ -309,8 +321,6 @@ TearOff::set_state (const XMLNode& node)
 void
 TearOff::own_window_realized ()
 {
-        cerr << "tearoff realized\n";
-
        own_window.get_window()->set_decorations (WMDecoration (DECOR_BORDER|DECOR_RESIZEH));
 
         if (own_window_width > 0) {