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>
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
40 WindowProxyBase (std::string
const &, XMLNode
const *);
41 virtual ~WindowProxyBase () {}
43 std::string
name () const {
48 XMLNode
* get_state () const;
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;
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 */
75 class WindowProxy
: public WindowProxyBase
78 WindowProxy (std::string
const & name
, XMLNode
const * node
)
79 : WindowProxyBase (name
, node
)
85 Gtk::Window
* get_gtk_window () const {
93 /** Set the window and maybe set it up. To be used after initial window creation */
94 void set (T
* w
, bool s
= true) {
105 /** WindowProxy for windows that are created in response to a GTK Action being set active.
106 * Templated on the type of the window.
109 class ActionWindowProxy
: public WindowProxy
<T
>
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
)
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());
129 Glib::RefPtr
<Gtk::ToggleAction
> tact
= Glib::RefPtr
<Gtk::ToggleAction
>::cast_dynamic (act
);
131 tact
->set_active (true);
135 bool rc_configured () const {