remove AU GUI debugging test in which arrow keys could be used to change GUI size
[ardour.git] / gtk2_ardour / window_proxy.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <gtkmm/window.h>
21 #include "window_proxy.h"
22
23 #include "pbd/convert.h"
24
25 #include "i18n.h"
26
27 using namespace std;
28
29 /** WindowProxyBase constructor.
30  *  @param name Unique internal name for this window.
31  *  @param node <UI> node containing <Window> children, the appropriate one of which is used
32  *  to set up this object.
33  */
34 WindowProxyBase::WindowProxyBase (string const & name, XMLNode const * node)
35         : _name (name)
36         , _visible (false)
37         , _x_off (-1)
38         , _y_off (-1)
39         , _width (-1)
40         , _height (-1)
41 {
42         if (!node) {
43                 return;
44         }
45
46         XMLNodeList children = node->children ();
47
48         XMLNodeList::const_iterator i = children.begin ();
49         while (i != children.end()) {
50                 XMLProperty* prop = (*i)->property (X_("name"));
51                 if ((*i)->name() == X_("Window") && prop && prop->value() == _name) {
52                         break;
53                 }
54
55                 ++i;
56         }
57
58         if (i != children.end()) {
59
60                 XMLProperty* prop;
61
62                 if ((prop = (*i)->property (X_("visible"))) != 0) {
63                         _visible = PBD::string_is_affirmative (prop->value ());
64                 }
65
66                 if ((prop = (*i)->property (X_("x-off"))) != 0) {
67                         _x_off = atoi (prop->value().c_str());
68                 }
69                 if ((prop = (*i)->property (X_("y-off"))) != 0) {
70                         _y_off = atoi (prop->value().c_str());
71                 }
72                 if ((prop = (*i)->property (X_("x-size"))) != 0) {
73                         _width = atoi (prop->value().c_str());
74                 }
75                 if ((prop = (*i)->property (X_("y-size"))) != 0) {
76                         _height = atoi (prop->value().c_str());
77                 }
78         }
79 }
80
81 /** Show this window if it was configured as visible.  This should
82  *  be called at session startup only.
83  */
84 void
85 WindowProxyBase::maybe_show ()
86 {
87         if (_visible) {
88                 show ();
89         }
90 }
91
92 /** Set up our window's position and size */
93 void
94 WindowProxyBase::setup ()
95 {
96         Gtk::Window* window = get_gtk_window ();
97         if (!window) {
98                 return;
99         }
100
101         if (_width != -1 && _height != -1) {
102                 window->set_default_size (_width, _height);
103         }
104
105         if (_x_off != -1 && _y_off != -1) {
106                 window->move (_x_off, _y_off);
107         }
108 }
109
110 XMLNode *
111 WindowProxyBase::get_state () const
112 {
113         bool v = _visible;
114         int x = _x_off;
115         int y = _y_off;
116         int w = _width;
117         int h = _height;
118
119         /* If the window has been created, get its current state; otherwise use
120            the state that we started off with.
121         */
122
123         Gtk::Window* gtk_window = get_gtk_window ();
124         if (gtk_window) {
125                 v = gtk_window->is_visible ();
126
127                 Glib::RefPtr<Gdk::Window> gdk_window = gtk_window->get_window ();
128                 if (gdk_window) {
129                         gdk_window->get_position (x, y);
130                         gdk_window->get_size (w, h);
131                 }
132
133         }
134
135         return state_node (v, x, y, w, h);
136 }
137
138
139 XMLNode *
140 WindowProxyBase::state_node (bool v, int x, int y, int w, int h) const
141 {
142         XMLNode* node = new XMLNode (X_("Window"));
143         node->add_property (X_("name"), _name);
144         node->add_property (X_("visible"), v ? X_("yes") : X_("no"));
145
146         char buf[32];
147         snprintf (buf, sizeof (buf), "%d", x);
148         node->add_property (X_("x-off"), buf);
149         snprintf (buf, sizeof (buf), "%d", y);
150         node->add_property (X_("y-off"), buf);
151         snprintf (buf, sizeof (buf), "%d", w);
152         node->add_property (X_("x-size"), buf);
153         snprintf (buf, sizeof (buf), "%d", h);
154         node->add_property (X_("y-size"), buf);
155
156         return node;
157 }