Remove erroneous assert which I added earlier.
[ardour2.git] / gtk2_ardour / window_proxy.h
blob10ff25ced652853f5c7b86913fe1270eeb4e5016
1 /*
2 Copyright (C) 2010 Paul 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.
20 #ifndef __ardour_window_proxy_h__
21 #define __ardour_window_proxy_h__
23 #include <gtkmm/action.h>
24 #include <gtkmm/toggleaction.h>
25 #include "actions.h"
27 class XMLNode;
29 /** A class to proxy for a window that may not have been created yet.
30 * It allows the management of visibility, position and size state
31 * so that it can be saved and restored across session loads.
33 * Subclasses of WindowProxy handle windows that are created in different
34 * ways.
37 class WindowProxyBase
39 public:
40 WindowProxyBase (std::string const &, XMLNode const *);
41 virtual ~WindowProxyBase () {}
43 std::string name () const {
44 return _name;
47 void maybe_show ();
48 XMLNode* get_state () const;
49 void setup ();
51 /** Show this window */
52 virtual void show () = 0;
54 /** @return true if the configuration for this window should be
55 * global (ie across all sessions), otherwise false if it should
56 * be session-specific.
58 virtual bool rc_configured () const = 0;
60 virtual Gtk::Window* get_gtk_window () const = 0;
62 private:
63 XMLNode* state_node (bool, int, int, int, int) const;
65 std::string _name; ///< internal unique name for this window
66 bool _visible; ///< true if the window should be visible on startup
67 int _x_off; ///< x position
68 int _y_off; ///< y position
69 int _width; ///< width
70 int _height; ///< height
73 /** Templated WindowProxy which contains a pointer to the window that is proxying for */
74 template <class T>
75 class WindowProxy : public WindowProxyBase
77 public:
78 WindowProxy (std::string const & name, XMLNode const * node)
79 : WindowProxyBase (name, node)
80 , _window (0)
85 Gtk::Window* get_gtk_window () const {
86 return _window;
89 T* get () const {
90 return _window;
93 /** Set the window and maybe set it up. To be used after initial window creation */
94 void set (T* w, bool s = true) {
95 _window = w;
96 if (s) {
97 setup ();
101 private:
102 T* _window;
105 /** WindowProxy for windows that are created in response to a GTK Action being set active.
106 * Templated on the type of the window.
108 template <class T>
109 class ActionWindowProxy : public WindowProxy<T>
111 public:
112 /** ActionWindowProxy constructor.
113 * @param name Unique internal name for this window.
114 * @param node <UI> node containing <Window> children, the appropriate one of which is used
115 * to set up this object.
116 * @param action Name of the ToggleAction that controls this window's visibility.
118 ActionWindowProxy (std::string const & name, XMLNode const * node, std::string const & action)
119 : WindowProxy<T> (name, node)
120 , _action (action)
125 void show () {
126 /* Set the appropriate action active so that the window gets shown */
127 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action ("Common", _action.c_str());
128 if (act) {
129 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic (act);
130 assert (tact);
131 tact->set_active (true);
135 bool rc_configured () const {
136 return true;
139 private:
140 std::string _action;
143 #endif