diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-03-19 02:49:01 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-03-19 02:49:01 +0000 |
commit | f0748535a5023d132eff03999a705a3e56c516db (patch) | |
tree | 34924d873426319d77cb52ac3239acb7aec916a1 /libs | |
parent | 295eb9a395d2ad36654a1d71019a571400adaee8 (diff) |
save tearoff state; restore monitor section state reasonably well; fixup access control to parts of editor.h (needs more work); extend CrossThread just a little
git-svn-id: svn://localhost/ardour2/branches/3.0@6774 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/tearoff.h | 14 | ||||
-rw-r--r-- | libs/gtkmm2ext/tearoff.cc | 142 | ||||
-rw-r--r-- | libs/pbd/crossthread.cc | 12 | ||||
-rw-r--r-- | libs/pbd/pbd/crossthread.h | 3 |
4 files changed, 153 insertions, 18 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/tearoff.h b/libs/gtkmm2ext/gtkmm2ext/tearoff.h index 737a6ddd03..db01684e2f 100644 --- a/libs/gtkmm2ext/gtkmm2ext/tearoff.h +++ b/libs/gtkmm2ext/gtkmm2ext/tearoff.h @@ -25,6 +25,8 @@ #include <gtkmm/box.h> #include <gtkmm/eventbox.h> +class XMLNode; + namespace Gtkmm2ext { class TearOff : public Gtk::HBox @@ -44,6 +46,11 @@ class TearOff : public Gtk::HBox Gtk::Window& tearoff_window() { return own_window; } bool torn_off() const; + void tear_it_off (); + void put_it_back (); + + void set_tornoff_state (const XMLNode&); + void add_tornoff_state (XMLNode&) const; private: Gtk::Widget& contents; @@ -58,6 +65,10 @@ class TearOff : public Gtk::HBox bool dragging; bool _visible; bool _can_be_torn_off; + int own_window_width; + int own_window_height; + int own_window_xpos; + int own_window_ypos; gint tearoff_click (GdkEventButton*); gint close_click (GdkEventButton*); @@ -66,6 +77,9 @@ class TearOff : public Gtk::HBox gint window_button_press (GdkEventButton*); gint window_button_release (GdkEventButton*); gint window_delete_event (GdkEventAny*); + + void own_window_realized (); + bool own_window_configured (GdkEventConfigure*); }; } /* namespace */ diff --git a/libs/gtkmm2ext/tearoff.cc b/libs/gtkmm2ext/tearoff.cc index c33663e8f7..28fb5ba4ef 100644 --- a/libs/gtkmm2ext/tearoff.cc +++ b/libs/gtkmm2ext/tearoff.cc @@ -20,8 +20,13 @@ #include <cmath> #include <iostream> -#include <gtkmm2ext/tearoff.h> -#include <gtkmm2ext/utils.h> + +#include "pbd/xml++.h" + +#include "gtkmm2ext/tearoff.h" +#include "gtkmm2ext/utils.h" + +#include "i18n.h" using namespace Gtkmm2ext; using namespace Gtk; @@ -38,6 +43,10 @@ TearOff::TearOff (Widget& c, bool allow_resize) dragging = false; _visible = true; _can_be_torn_off = true; + own_window_width = 0; + own_window_height = 0; + own_window_xpos = 0; + own_window_ypos = 0; tearoff_event_box.add (tearoff_arrow); tearoff_event_box.set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK); @@ -50,7 +59,9 @@ TearOff::TearOff (Widget& c, bool allow_resize) 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); own_window.set_type_hint (WINDOW_TYPE_HINT_TOOLBAR); - + 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); + VBox* box1; box1 = manage (new VBox); box1->pack_start (close_event_box, false, false, 2); @@ -73,7 +84,6 @@ TearOff::TearOff (Widget& c, bool allow_resize) pack_start (contents); pack_start (*box2, false, false, 2); - } TearOff::~TearOff () @@ -119,32 +129,52 @@ TearOff::set_visible (bool yn) gint TearOff::tearoff_click (GdkEventButton* /*ev*/) { - if (_can_be_torn_off) { - remove (contents); - window_box.pack_start (contents); - own_window.set_name (get_name()); - close_event_box.set_name (get_name()); - own_window.show_all (); - own_window.present (); - std::cerr << "own window should be visible\n"; - hide (); - Detach (); - } - + tear_it_off (); return true; } +void +TearOff::tear_it_off () +{ + if (!_can_be_torn_off) { + return; + } + + if (torn_off()) { + return; + } + + remove (contents); + window_box.pack_start (contents); + own_window.set_name (get_name()); + close_event_box.set_name (get_name()); + own_window.show_all (); + own_window.present (); + hide (); + Detach (); +} + gint TearOff::close_click (GdkEventButton* /*ev*/) { + put_it_back (); + return true; +} + +void +TearOff::put_it_back () +{ + if (!torn_off()) { + return; + } + window_box.remove (contents); pack_start (contents); reorder_child (contents, 0); own_window.hide (); show_all (); Attach (); - return true; -} +} gint TearOff::window_button_press (GdkEventButton* ev) @@ -217,3 +247,79 @@ TearOff::torn_off() const { return own_window.is_visible(); } + +void +TearOff::add_tornoff_state (XMLNode& node) const +{ + node.add_property ("tornoff", (own_window.is_visible() ? "yes" : "no")); + + if (own_window_width > 0) { + char buf[32]; + + snprintf (buf, sizeof (buf), "%d", own_window_width); + node.add_property ("width", buf); + snprintf (buf, sizeof (buf), "%d", own_window_height); + node.add_property ("height", buf); + snprintf (buf, sizeof (buf), "%d", own_window_xpos); + node.add_property ("xpos", buf); + snprintf (buf, sizeof (buf), "%d", own_window_ypos); + node.add_property ("ypos", buf); + } +} + +void +TearOff::set_tornoff_state (const XMLNode& node) +{ + Glib::RefPtr<Gdk::Window> win; + const XMLProperty* prop; + + if ((prop = node.property (X_("tornoff"))) == 0) { + return; + } + + if (prop->value() == "yes") { + tear_it_off (); + } else { + put_it_back (); + } + + if ((prop = node.property (X_("width"))) != 0) { + sscanf (prop->value().c_str(), "%d", &own_window_width); + } + if ((prop = node.property (X_("height"))) != 0) { + sscanf (prop->value().c_str(), "%d", &own_window_height); + } + if ((prop = node.property (X_("xpos"))) != 0) { + sscanf (prop->value().c_str(), "%d", &own_window_xpos); + } + if ((prop = node.property (X_("ypos"))) != 0) { + sscanf (prop->value().c_str(), "%d", &own_window_ypos); + } + + own_window.set_default_size (own_window_width, own_window_height); + own_window.move (own_window_xpos, own_window_ypos); +} + +void +TearOff::own_window_realized () +{ + 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 (); + + if (win) { + win->get_size (own_window_width, own_window_height); + win->get_position (own_window_xpos, own_window_ypos); + } + + return false; +} diff --git a/libs/pbd/crossthread.cc b/libs/pbd/crossthread.cc index 2bcb444b36..7ccf741380 100644 --- a/libs/pbd/crossthread.cc +++ b/libs/pbd/crossthread.cc @@ -104,3 +104,15 @@ CrossThreadChannel::drain (int fd) char buf[64]; while (::read (fd, buf, sizeof (buf)) > 0); } + +int +CrossThreadChannel::deliver (char msg) +{ + return ::write (fds[1], &msg, 1); +} + +int +CrossThreadChannel::receive (char& msg) +{ + return ::read (fds[0], &msg, 1); +} diff --git a/libs/pbd/pbd/crossthread.h b/libs/pbd/pbd/crossthread.h index 7a323e198f..f9845eedf0 100644 --- a/libs/pbd/pbd/crossthread.h +++ b/libs/pbd/pbd/crossthread.h @@ -30,6 +30,9 @@ class CrossThreadChannel { void wakeup(); int selectable() const { return fds[0]; } + int deliver (char msg); + int receive (char& msg); + void drain (); static void drain (int fd); |