From 9267648e5dd8d8db5fa39ae2a264b261d6c75dbe Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 4 May 2013 22:01:13 -0400 Subject: VisibilityTracker needs to inherit from sigc::tracker so that it can be used without combination with other sigc::trackable parents; fix partially_visible() logic --- gtk2_ardour/big_clock_window.cc | 159 +++++++++++++++++++ gtk2_ardour/big_clock_window.h | 54 +++++++ gtk2_ardour/window_manager.cc | 333 ++++++++++++++++++++++++++++++++++++++++ gtk2_ardour/window_manager.h | 197 ++++++++++++++++++++++++ gtk2_ardour/window_proxy.cc | 157 ------------------- gtk2_ardour/window_proxy.h | 143 ----------------- 6 files changed, 743 insertions(+), 300 deletions(-) create mode 100644 gtk2_ardour/big_clock_window.cc create mode 100644 gtk2_ardour/big_clock_window.h create mode 100644 gtk2_ardour/window_manager.cc create mode 100644 gtk2_ardour/window_manager.h delete mode 100755 gtk2_ardour/window_proxy.cc delete mode 100755 gtk2_ardour/window_proxy.h diff --git a/gtk2_ardour/big_clock_window.cc b/gtk2_ardour/big_clock_window.cc new file mode 100644 index 0000000000..b080167d34 --- /dev/null +++ b/gtk2_ardour/big_clock_window.cc @@ -0,0 +1,159 @@ +/* + Copyright (C) 20002-2013 Paul 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. + +*/ + +#ifdef WAF_BUILD +#include "gtk2ardour-config.h" +#endif + +#include "big_clock_window.h" +#include "audio_clock.h" + +#include "i18n.h" + + +BigClockWindow::BigClockWindow (AudioClock& c) + : ArdourWindow (_("Big Clock")) + , clock (c) + , resize_in_progress (false) +{ + ARDOUR_UI::Clock.connect (sigc::mem_fun (clock, &AudioClock::set)); + + clock.set_corner_radius (0.0); + clock.mode_changed.connect (sigc::mem_fun (*this, &BigClockWindow::reset_aspect_ratio)); + + win->set_keep_above (true); + win->set_border_width (0); + win->add (*clock); +} + +void +BigClockWindow::on_unmap () +{ + PublicEditor::instance().reset_focus (); +} + +bool +BigClockWindow::on_key_press_event (GdkEventKey* ev) +{ + return relay_key_press (ev); +} + +void +BigClockWindow::on_realize () +{ + int x, y, w, d, h; + + ArdourWindow::on_realize (); + + get_window()->set_decorations (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH); + get_window()->get_geometry (x, y, w, h, d); + + reset_aspect_ratio (); + + original_height = h; + original_width = w; + + Pango::FontDescription fd (clock.get_style()->get_font()); + original_font_size = fd.get_size (); + + if (!fd.get_size_is_absolute ()) { + original_font_size /= PANGO_SCALE; + } +} + +void +BigClockWindow::on_size_allocate (Gtk::Allocation& alloc) +{ + ArdourWindow::on_size_allocate (alloc); + + if (!big_clock_resize_in_progress) { + Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &BigClockWindow::text_resizer), 0, 0)); + resize_in_progress = true; + } +} + +void +BigClockWindow::float (Gtk::Window* parent) +{ + if (parent) { + set_transient_for (*parent); + } else { + /* Gtkmm doesn't allow a call to this for a null parent */ + gtk_window_set_transient_for (big_clock_window->gobj(), (GtkWindow*) 0); + } +} + +void +BigClockWindow::reset_aspect_ratio () +{ + Gtk::Requisition req; + + clock.size_request (req); + + float aspect = req.width/(float)req.height; + Gdk::Geometry geom; + + geom.min_aspect = aspect; + geom.max_aspect = aspect; + + set_geometry_hints (clock, geom, Gdk::HINT_ASPECT); +} + +bool +BigClockWindow::text_resizer (int, int) +{ + resize_in_progress = false; + + Glib::RefPtr win = get_window(); + Pango::FontDescription fd (clock.get_style()->get_font()); + int current_size = fd.get_size (); + int x, y, w, h, d; + + if (!fd.get_size_is_absolute ()) { + current_size /= PANGO_SCALE; + } + + win->get_geometry (x, y, w, h, d); + + double scale = min (((double) w / (double) original_width), + ((double) h / (double) original_height)); + + int size = (int) lrintf (original_font_size * scale); + + if (size != current_size) { + + string family = fd.get_family(); + char buf[family.length()+16]; + snprintf (buf, family.length()+16, "%s %d", family.c_str(), size); + + try { + Pango::FontDescription fd (buf); + Glib::RefPtr rcstyle = clock.get_modifier_style (); + rcstyle->set_font (fd); + clock.modify_style (rcstyle); + } + + catch (...) { + /* oh well, do nothing */ + } + } + + return false; +} + diff --git a/gtk2_ardour/big_clock_window.h b/gtk2_ardour/big_clock_window.h new file mode 100644 index 0000000000..790bf0f357 --- /dev/null +++ b/gtk2_ardour/big_clock_window.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2013 Paul 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. + +*/ + +#ifndef __bigclock_window_h__ +#define __bigclock_window_h__ + +#include "ardour_window.h" + +class AudioClock; + +class BigClockWindow : public Gtk::Window, public ARDOUR::SessionHandlePtr, public Gtkmm2ext::VisibilityTracker +{ + public: + BigClockWindow (AudioClock&); + + AudioClock* clock() const { return _clock; } + void set_clock (AudioClock* c) { _clock = c; } + + void float (Gtk::Window*); + + private: + AudioClock& clock; + bool resize_in_progress; + int original_height; + int original_width; + int original_font_size; + + void on_size_allocate (Gtk::Allocation&); + void on_realize (); + void on_unmap (); + bool on_key_press_event (); + + bool text_resizer (int, int); + void reset_aspect_ratio (); +}; + +#endif // __ardour_window_h__ + diff --git a/gtk2_ardour/window_manager.cc b/gtk2_ardour/window_manager.cc new file mode 100644 index 0000000000..5732e21a25 --- /dev/null +++ b/gtk2_ardour/window_manager.cc @@ -0,0 +1,333 @@ +/* + Copyright (C) 2013 Paul 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. +*/ + +#include + +#include "pbd/xml++.h" + +#include "ardour/session_handle.h" + +#include "gtkmm2ext/visibility_tracker.h" + +#include "actions.h" +#include "window_manager.h" + +#include "i18n.h" + +using std::string; + +WindowManager* WindowManager::_instance = 0; + +WindowManager& +WindowManager::instance () +{ + if (!_instance) { + _instance = new WindowManager; + } + return *_instance; +} + +WindowManager::WindowManager () +{ +} + +void +WindowManager::register_window (ProxyBase* info) +{ + _windows.push_back (info); + + if (info->rc_configured() && !info->menu_name().empty()) { + + if (!window_actions) { + window_actions = Gtk::ActionGroup::create (X_("Window")); + ActionManager::add_action_group (window_actions); + } + + info->set_action (ActionManager::register_action (window_actions, info->action_name().c_str(), info->menu_name().c_str(), + sigc::bind (sigc::mem_fun (*this, &WindowManager::toggle_window), info))); + } +} + +void +WindowManager::remove (const ProxyBase* info) +{ + for (Windows::iterator i = _windows.begin(); i != _windows.end(); ++i) { + if ((*i) == info) { + _windows.erase (i); + return; + } + } +} + +void +WindowManager::toggle_window (ProxyBase* proxy) +{ + if (proxy) { + proxy->toggle (); + } +} + +void +WindowManager::show_visible() const +{ + for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) { + if ((*i)->visible()) { + (*i)->show_all (); + (*i)->present (); + } + } +} + +void +WindowManager::add_state (XMLNode& root) const +{ + for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) { + root.add_child_nocopy ((*i)->get_state()); + } +} + +void +WindowManager::set_session (ARDOUR::Session* s) +{ + for (Windows::const_iterator i = _windows.begin(); i != _windows.end(); ++i) { + ARDOUR::SessionHandlePtr* sp = (*i)->session_handle (); + if (sp) { + sp->set_session (s); + } + } +} + +/*-----------------------*/ + +WindowManager::ProxyBase::ProxyBase (const string& name, const std::string& menu_name) + : _name (name) + , _menu_name (menu_name) + , _window (0) + , _visible (false) + , _x_off (-1) + , _y_off (-1) + , _width (-1) + , _height (-1) + , vistracker (0) +{ +} + +WindowManager::ProxyBase::ProxyBase (const string& name, const std::string& menu_name, const XMLNode& node) + : _name (name) + , _menu_name (menu_name) + , _window (0) + , _visible (false) + , _x_off (-1) + , _y_off (-1) + , _width (-1) + , _height (-1) + , vistracker (0) +{ + set_state (node); +} + +WindowManager::ProxyBase::~ProxyBase () +{ + delete vistracker; +} + +void +WindowManager::ProxyBase::set_state (const XMLNode& node) +{ + XMLNodeList children = node.children (); + + XMLNodeList::const_iterator i = children.begin (); + + while (i != children.end()) { + XMLProperty* prop = (*i)->property (X_("name")); + if ((*i)->name() == X_("Window") && prop && prop->value() == _name) { + break; + } + + ++i; + } + + if (i != children.end()) { + + XMLProperty* prop; + + if ((prop = (*i)->property (X_("visible"))) != 0) { + _visible = PBD::string_is_affirmative (prop->value ()); + } + + if ((prop = (*i)->property (X_("x-off"))) != 0) { + _x_off = atoi (prop->value().c_str()); + } + if ((prop = (*i)->property (X_("y-off"))) != 0) { + _y_off = atoi (prop->value().c_str()); + } + if ((prop = (*i)->property (X_("x-size"))) != 0) { + _width = atoi (prop->value().c_str()); + } + if ((prop = (*i)->property (X_("y-size"))) != 0) { + _height = atoi (prop->value().c_str()); + } + } + + /* if we have a window already, reset its properties */ + + if (_window) { + setup (); + } +} + +void +WindowManager::ProxyBase::set_action (Glib::RefPtr act) +{ + _action = act; +} + +std::string +WindowManager::ProxyBase::action_name() const +{ + return string_compose (X_("toggle-%1"), _name); +} + +void +WindowManager::ProxyBase::toggle() +{ + if (!_window) { + (void) get (true); + assert (_window); + /* XXX this is a hack - the window object should really + ensure its components are all visible. sigh. + */ + _window->show_all(); + /* we'd like to just call this and nothing else */ + _window->present (); + } else { + vistracker->cycle_visibility (); + } +} + +bool +WindowManager::ProxyBase::configured (GdkEventConfigure* ev) +{ + _visible = true; + _x_off = ev->x; + _y_off = ev->y; + _height = ev->height; + _width = ev->width; + + return false; +} + +XMLNode& +WindowManager::ProxyBase::get_state () const +{ + XMLNode* node = new XMLNode (X_("Window")); + node->add_property (X_("name"), _name); + node->add_property (X_("visible"), _visible ? X_("yes") : X_("no")); + + char buf[32]; + snprintf (buf, sizeof (buf), "%d", _x_off); + node->add_property (X_("x-off"), buf); + snprintf (buf, sizeof (buf), "%d", _y_off); + node->add_property (X_("y-off"), buf); + snprintf (buf, sizeof (buf), "%d", _width); + node->add_property (X_("x-size"), buf); + snprintf (buf, sizeof (buf), "%d", _height); + node->add_property (X_("y-size"), buf); + + return *node; +} + +void +WindowManager::ProxyBase::clear () +{ + if (_window) { + _window->hide (); + delete _window; + _window = 0; + configure_connection.disconnect (); + delete vistracker; + vistracker = 0; + } +} + +void +WindowManager::ProxyBase::use_window (Gtk::Window& win) +{ + clear (); + _window = &win; + setup (); +} + +void +WindowManager::ProxyBase::setup () +{ + assert (_window); + + configure_connection = _window->signal_configure_event().connect (sigc::mem_fun (*this, &ProxyBase::configured), false); + + vistracker = new Gtkmm2ext::VisibilityTracker (*_window); + + if (_width != -1 && _height != -1) { + _window->set_default_size (_width, _height); + } + + if (_x_off != -1 && _y_off != -1) { + _window->move (_x_off, _y_off); + } +} + +void +WindowManager::ProxyBase::show () +{ + Gtk::Window* win = get (true); + win->show (); +} + +void +WindowManager::ProxyBase::maybe_show () +{ + if (_visible) { + show (); + } +} + +void +WindowManager::ProxyBase::show_all () +{ + Gtk::Window* win = get (true); + win->show_all (); +} + + +void +WindowManager::ProxyBase::present () +{ + Gtk::Window* win = get (true); + win->show_all (); + win->present (); +} + +void +WindowManager::ProxyBase::hide () +{ + Gtk::Window* win = get (false); + if (win) { + win->hide (); + } +} + diff --git a/gtk2_ardour/window_manager.h b/gtk2_ardour/window_manager.h new file mode 100644 index 0000000000..d0204f20b8 --- /dev/null +++ b/gtk2_ardour/window_manager.h @@ -0,0 +1,197 @@ +/* + Copyright (C) 2013 Paul 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. + +*/ + +#ifndef __gtk2_ardour_window_manager_h__ +#define __gtk2_ardour_window_manager_h__ + +#include +#include + +#include +#include +#include + +class XMLNode; + +namespace Gtk { + class Window; + class Action; +} + +namespace Gtkmm2ext { + class VisibilityTracker; +} + +namespace ARDOUR { + class Session; + class SessionHandlePtr; +} + +class WindowManager +{ + public: + static WindowManager& instance(); + + class ProxyBase : public sigc::trackable { + public: + ProxyBase (const std::string& name, const std::string& menu_name); + ProxyBase (const std::string& name, const std::string& menu_name, const XMLNode&); + virtual ~ProxyBase(); + + void show (); + void show_all (); + void hide (); + void present (); + void maybe_show (); + + bool visible() const { return _visible; } + const std::string& name() const { return _name; } + const std::string& menu_name() const { return _menu_name; } + + std::string action_name() const; + void set_action (Glib::RefPtr); + Glib::RefPtr action() const { return _action; }; + + void clear (); + void use_window (Gtk::Window&); + + virtual Gtk::Window* get (bool create = false) = 0; + + virtual bool rc_configured() const { return true; } + virtual void toggle (); + + void set_state (const XMLNode&); + XMLNode& get_state () const; + + virtual ARDOUR::SessionHandlePtr* session_handle () = 0; + + operator bool() const { return _window != 0; } + + protected: + std::string _name; + std::string _menu_name; + Glib::RefPtr _action; + Gtk::Window* _window; + bool _visible; ///< true if the window should be visible on startup + int _x_off; ///< x position + int _y_off; ///< y position + int _width; ///< width + int _height; ///< height + Gtkmm2ext::VisibilityTracker* vistracker; + sigc::connection configure_connection; + + void setup (); + bool configured (GdkEventConfigure*); + }; + + template + class ProxyWithConstructor: public ProxyBase { + public: + ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function& c) + : ProxyBase (name, menu_name) , creator (c) {} + + ProxyWithConstructor (const std::string& name, const std::string& menu_name, const boost::function& c, const XMLNode* node) + : ProxyBase (name, menu_name, node) , creator (c) {} + + Gtk::Window* get (bool create = false) { + if (!_window) { + if (!create) { + return 0; + } + + _window = creator (); + + if (_window) { + setup (); + } + } + + return _window; + } + + T* operator->() { + return dynamic_cast (get (true)); + } + + ARDOUR::SessionHandlePtr* session_handle () { + /* may return null */ + return dynamic_cast (_window); + } + + private: + boost::function creator; + }; + + template + class Proxy : public ProxyBase { + public: + Proxy (const std::string& name, const std::string& menu_name) + : ProxyBase (name, menu_name) {} + + Proxy (const std::string& name, const std::string& menu_name, const XMLNode* node) + : ProxyBase (name, menu_name, node) {} + + Gtk::Window* get (bool create = false) { + if (!_window) { + if (!create) { + return 0; + } + + _window = new T (); + + if (_window) { + setup (); + } + } + + return _window; + } + + T* operator->() { + /* make return null */ + return dynamic_cast (_window); + } + + ARDOUR::SessionHandlePtr* session_handle () { + return dynamic_cast (get()); + } + + private: + boost::function creator; + }; + + void register_window (ProxyBase*); + void remove (const ProxyBase*); + void toggle_window (ProxyBase*); + void show_visible () const; + void set_session (ARDOUR::Session*); + void add_state (XMLNode&) const; + + private: + typedef std::list Windows; + Windows _windows; + Glib::RefPtr window_actions; + + WindowManager(); + ~WindowManager(); + + static WindowManager* _instance; +}; + +#endif /* __gtk2_ardour_window_manager_h__ */ diff --git a/gtk2_ardour/window_proxy.cc b/gtk2_ardour/window_proxy.cc deleted file mode 100755 index 99da166af0..0000000000 --- a/gtk2_ardour/window_proxy.cc +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright (C) 2010 Paul 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. - -*/ - -#include -#include "window_proxy.h" - -#include "pbd/convert.h" - -#include "i18n.h" - -using namespace std; - -/** WindowProxyBase constructor. - * @param name Unique internal name for this window. - * @param node node containing children, the appropriate one of which is used - * to set up this object. - */ -WindowProxyBase::WindowProxyBase (string const & name, XMLNode const * node) - : _name (name) - , _visible (false) - , _x_off (-1) - , _y_off (-1) - , _width (-1) - , _height (-1) -{ - if (!node) { - return; - } - - XMLNodeList children = node->children (); - - XMLNodeList::const_iterator i = children.begin (); - while (i != children.end()) { - XMLProperty* prop = (*i)->property (X_("name")); - if ((*i)->name() == X_("Window") && prop && prop->value() == _name) { - break; - } - - ++i; - } - - if (i != children.end()) { - - XMLProperty* prop; - - if ((prop = (*i)->property (X_("visible"))) != 0) { - _visible = PBD::string_is_affirmative (prop->value ()); - } - - if ((prop = (*i)->property (X_("x-off"))) != 0) { - _x_off = atoi (prop->value().c_str()); - } - if ((prop = (*i)->property (X_("y-off"))) != 0) { - _y_off = atoi (prop->value().c_str()); - } - if ((prop = (*i)->property (X_("x-size"))) != 0) { - _width = atoi (prop->value().c_str()); - } - if ((prop = (*i)->property (X_("y-size"))) != 0) { - _height = atoi (prop->value().c_str()); - } - } -} - -/** Show this window if it was configured as visible. This should - * be called at session startup only. - */ -void -WindowProxyBase::maybe_show () -{ - if (_visible) { - show (); - } -} - -/** Set up our window's position and size */ -void -WindowProxyBase::setup () -{ - Gtk::Window* window = get_gtk_window (); - if (!window) { - return; - } - - if (_width != -1 && _height != -1) { - window->set_default_size (_width, _height); - } - - if (_x_off != -1 && _y_off != -1) { - window->move (_x_off, _y_off); - } -} - -XMLNode * -WindowProxyBase::get_state () const -{ - bool v = _visible; - int x = _x_off; - int y = _y_off; - int w = _width; - int h = _height; - - /* If the window has been created, get its current state; otherwise use - the state that we started off with. - */ - - Gtk::Window* gtk_window = get_gtk_window (); - if (gtk_window) { - v = gtk_window->is_visible (); - - Glib::RefPtr gdk_window = gtk_window->get_window (); - if (gdk_window) { - gdk_window->get_position (x, y); - gdk_window->get_size (w, h); - } - - } - - return state_node (v, x, y, w, h); -} - - -XMLNode * -WindowProxyBase::state_node (bool v, int x, int y, int w, int h) const -{ - XMLNode* node = new XMLNode (X_("Window")); - node->add_property (X_("name"), _name); - node->add_property (X_("visible"), v ? X_("yes") : X_("no")); - - char buf[32]; - snprintf (buf, sizeof (buf), "%d", x); - node->add_property (X_("x-off"), buf); - snprintf (buf, sizeof (buf), "%d", y); - node->add_property (X_("y-off"), buf); - snprintf (buf, sizeof (buf), "%d", w); - node->add_property (X_("x-size"), buf); - snprintf (buf, sizeof (buf), "%d", h); - node->add_property (X_("y-size"), buf); - - return node; -} diff --git a/gtk2_ardour/window_proxy.h b/gtk2_ardour/window_proxy.h deleted file mode 100755 index 10ff25ced6..0000000000 --- a/gtk2_ardour/window_proxy.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (C) 2010 Paul 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. - -*/ - -#ifndef __ardour_window_proxy_h__ -#define __ardour_window_proxy_h__ - -#include -#include -#include "actions.h" - -class XMLNode; - -/** A class to proxy for a window that may not have been created yet. - * It allows the management of visibility, position and size state - * so that it can be saved and restored across session loads. - * - * Subclasses of WindowProxy handle windows that are created in different - * ways. - */ - -class WindowProxyBase -{ -public: - WindowProxyBase (std::string const &, XMLNode const *); - virtual ~WindowProxyBase () {} - - std::string name () const { - return _name; - } - - void maybe_show (); - XMLNode* get_state () const; - void setup (); - - /** Show this window */ - virtual void show () = 0; - - /** @return true if the configuration for this window should be - * global (ie across all sessions), otherwise false if it should - * be session-specific. - */ - virtual bool rc_configured () const = 0; - - virtual Gtk::Window* get_gtk_window () const = 0; - -private: - XMLNode* state_node (bool, int, int, int, int) const; - - std::string _name; ///< internal unique name for this window - bool _visible; ///< true if the window should be visible on startup - int _x_off; ///< x position - int _y_off; ///< y position - int _width; ///< width - int _height; ///< height -}; - -/** Templated WindowProxy which contains a pointer to the window that is proxying for */ -template -class WindowProxy : public WindowProxyBase -{ -public: - WindowProxy (std::string const & name, XMLNode const * node) - : WindowProxyBase (name, node) - , _window (0) - { - - } - - Gtk::Window* get_gtk_window () const { - return _window; - } - - T* get () const { - return _window; - } - - /** Set the window and maybe set it up. To be used after initial window creation */ - void set (T* w, bool s = true) { - _window = w; - if (s) { - setup (); - } - } - -private: - T* _window; -}; - -/** WindowProxy for windows that are created in response to a GTK Action being set active. - * Templated on the type of the window. - */ -template -class ActionWindowProxy : public WindowProxy -{ -public: - /** ActionWindowProxy constructor. - * @param name Unique internal name for this window. - * @param node node containing children, the appropriate one of which is used - * to set up this object. - * @param action Name of the ToggleAction that controls this window's visibility. - */ - ActionWindowProxy (std::string const & name, XMLNode const * node, std::string const & action) - : WindowProxy (name, node) - , _action (action) - { - - } - - void show () { - /* Set the appropriate action active so that the window gets shown */ - Glib::RefPtr act = ActionManager::get_action ("Common", _action.c_str()); - if (act) { - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); - assert (tact); - tact->set_active (true); - } - } - - bool rc_configured () const { - return true; - } - -private: - std::string _action; -}; - -#endif -- cgit v1.2.3