From 9634888bf3e820e2507f866ff03fd1760f6a310f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 27 Apr 2016 00:01:13 -0400 Subject: add the concept of a "state mask" that determines what info a WindowProxy will save --- libs/gtkmm2ext/gtkmm2ext/window_proxy.h | 9 +++++++ libs/gtkmm2ext/window_proxy.cc | 44 +++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'libs/gtkmm2ext') diff --git a/libs/gtkmm2ext/gtkmm2ext/window_proxy.h b/libs/gtkmm2ext/gtkmm2ext/window_proxy.h index c5949701d9..3bb941bccf 100644 --- a/libs/gtkmm2ext/gtkmm2ext/window_proxy.h +++ b/libs/gtkmm2ext/gtkmm2ext/window_proxy.h @@ -69,6 +69,14 @@ class LIBGTKMM2EXT_API WindowProxy : public PBD::StatefulDestructible, public vi virtual int set_state (const XMLNode&, int version); virtual XMLNode& get_state (); + enum StateMask { + Position = 0x1, + Size = 0x2 + }; + + void set_state_mask (StateMask); + StateMask state_mask () const { return _state_mask; } + operator bool() const { return _window != 0; } static std::string xml_node_name(); @@ -84,6 +92,7 @@ class LIBGTKMM2EXT_API WindowProxy : public PBD::StatefulDestructible, public vi mutable int _width; ///< width mutable int _height; ///< height Gtkmm2ext::VisibilityTracker* vistracker; + StateMask _state_mask; void save_pos_and_size (); void set_pos_and_size (); diff --git a/libs/gtkmm2ext/window_proxy.cc b/libs/gtkmm2ext/window_proxy.cc index 6ad6a4d86b..d859c730c0 100644 --- a/libs/gtkmm2ext/window_proxy.cc +++ b/libs/gtkmm2ext/window_proxy.cc @@ -42,6 +42,7 @@ WindowProxy::WindowProxy (const std::string& name) , _width (-1) , _height (-1) , vistracker (0) + , _state_mask (StateMask (Position|Size)) { } @@ -55,6 +56,7 @@ WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name) , _width (-1) , _height (-1) , vistracker (0) + , _state_mask (StateMask (Position|Size)) { } @@ -189,14 +191,32 @@ WindowProxy::get_state () _window->get_size (_width, _height); } + int x, y, w, h; + + if (_state_mask & Position) { + x = _x_off; + y = _y_off; + } else { + x = -1; + y = -1; + } + + if (_state_mask & Size) { + w = _width; + h = _height; + } else { + w = -1; + h = -1; + } + node->add_property (X_("visible"), _visible? X_("yes") : X_("no")); - snprintf (buf, sizeof (buf), "%d", _x_off); + snprintf (buf, sizeof (buf), "%d", x); node->add_property (X_("x-off"), buf); - snprintf (buf, sizeof (buf), "%d", _y_off); + snprintf (buf, sizeof (buf), "%d", y); node->add_property (X_("y-off"), buf); - snprintf (buf, sizeof (buf), "%d", _width); + snprintf (buf, sizeof (buf), "%d", w); node->add_property (X_("x-size"), buf); - snprintf (buf, sizeof (buf), "%d", _height); + snprintf (buf, sizeof (buf), "%d", h); node->add_property (X_("y-size"), buf); return *node; @@ -327,16 +347,16 @@ WindowProxy::set_pos_and_size () return; } - if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) { + if ((_state_mask & Position) && (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1)) { /* cancel any mouse-based positioning */ _window->set_position (Gtk::WIN_POS_NONE); } - if (_width != -1 && _height != -1) { + if ((_state_mask & Size) && _width != -1 && _height != -1) { _window->resize (_width, _height); } - if (_x_off != -1 && _y_off != -1) { + if ((_state_mask & Position) && _x_off != -1 && _y_off != -1) { _window->move (_x_off, _y_off); } } @@ -348,6 +368,10 @@ WindowProxy::set_pos () return; } + if (!(_state_mask & Position)) { + return; + } + if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) { /* cancel any mouse-based positioning */ _window->set_position (Gtk::WIN_POS_NONE); @@ -357,3 +381,9 @@ WindowProxy::set_pos () _window->move (_x_off, _y_off); } } + +void +WindowProxy::set_state_mask (StateMask sm) +{ + _state_mask = sm; +} -- cgit v1.2.3