2 Copyright (C) 2001-2009 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 #include <gtkmm/box.h>
21 #include <gtkmm/alignment.h>
22 #include "ardour/configuration.h"
23 #include "option_editor.h"
24 #include "gui_thread.h"
30 using namespace ARDOUR;
33 OptionEditorComponent::add_widget_to_page (OptionEditorPage* p, Gtk::Widget* w)
35 int const n = p->table.property_n_rows();
36 p->table.resize (n + 1, 3);
37 p->table.attach (*w, 1, 3, n, n + 1, FILL | EXPAND);
41 OptionEditorComponent::add_widgets_to_page (OptionEditorPage* p, Gtk::Widget* wa, Gtk::Widget* wb)
43 int const n = p->table.property_n_rows();
44 p->table.resize (n + 1, 3);
45 p->table.attach (*wa, 1, 2, n, n + 1, FILL | EXPAND);
46 p->table.attach (*wb, 2, 3, n, n + 1, FILL | EXPAND);
49 OptionEditorHeading::OptionEditorHeading (string const & h)
52 s << "<b>" << h << "</b>";
53 _label = manage (new Label (s.str()));
54 _label->set_alignment (0, 0.5);
55 _label->set_use_markup (true);
59 OptionEditorHeading::add_to_page (OptionEditorPage* p)
61 int const n = p->table.property_n_rows();
62 p->table.resize (n + 2, 3);
64 p->table.attach (*manage (new Label ("")), 0, 3, n, n + 1, FILL | EXPAND);
65 p->table.attach (*_label, 0, 3, n + 1, n + 2, FILL | EXPAND);
69 OptionEditorBox::add_to_page (OptionEditorPage* p)
71 add_widget_to_page (p, _box);
74 BoolOption::BoolOption (string const & i, string const & n, slot<bool> g, slot<bool, bool> s)
79 _button = manage (new CheckButton (n));
80 _button->set_active (_get ());
81 _button->signal_toggled().connect (mem_fun (*this, &BoolOption::toggled));
85 BoolOption::add_to_page (OptionEditorPage* p)
87 add_widget_to_page (p, _button);
91 BoolOption::set_state_from_config ()
93 _button->set_active (_get ());
97 BoolOption::toggled ()
99 _set (_button->get_active ());
102 EntryOption::EntryOption (string const & i, string const & n, slot<string> g, slot<bool, string> s)
107 _label = manage (new Label (n + ":"));
108 _label->set_alignment (1, 0.5);
109 _entry = manage (new Entry);
110 _entry->signal_activate().connect (mem_fun (*this, &EntryOption::activated));
114 EntryOption::add_to_page (OptionEditorPage* p)
116 add_widgets_to_page (p, _label, _entry);
120 EntryOption::set_state_from_config ()
122 _entry->set_text (_get ());
126 EntryOption::activated ()
128 _set (_entry->get_text ());
131 OptionEditorPage::OptionEditorPage (Gtk::Notebook& n, std::string const & t)
134 table.set_spacings (4);
135 table.set_col_spacing (0, 32);
136 box.pack_start (table, false, false);
137 box.set_border_width (4);
138 n.append_page (box, t);
141 /** Construct an OptionEditor.
142 * @param o Configuration to edit.
143 * @param t Title for the dialog.
145 OptionEditor::OptionEditor (Configuration* c, std::string const & t)
146 : ArdourDialog (t, false), _config (c)
148 using namespace Notebook_Helpers;
150 set_default_size (300, 300);
151 set_wmclass (X_("ardour_preferences"), "Ardour");
153 set_name ("Preferences");
154 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
156 set_border_width (4);
158 get_vbox()->set_spacing (4);
159 get_vbox()->pack_start (_notebook);
161 _notebook.set_show_tabs (true);
162 _notebook.set_show_border (true);
163 _notebook.set_name ("OptionsNotebook");
167 /* Watch out for changes to parameters */
168 _config->ParameterChanged.connect (mem_fun (*this, &OptionEditor::parameter_changed));
171 OptionEditor::~OptionEditor ()
173 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
174 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
181 /** Called when a configuration parameter has been changed.
182 * @param p Parameter name.
185 OptionEditor::parameter_changed (std::string const & p)
187 ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), p));
189 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
190 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
191 (*j)->parameter_changed (p);
196 /** Add a component to a given page.
197 * @param pn Page name (will be created if it doesn't already exist)
198 * @param o Component.
201 OptionEditor::add_option (std::string const & pn, OptionEditorComponent* o)
203 if (_pages.find (pn) == _pages.end()) {
204 _pages[pn] = new OptionEditorPage (_notebook, pn);
207 OptionEditorPage* p = _pages[pn];
208 p->components.push_back (o);
211 o->set_state_from_config ();