2 Copyright (C) 2000-2007 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.
25 #include <gtkmm/stock.h>
26 #include <gtkmm2ext/gtk_ui.h>
27 #include <gtkmm/settings.h>
29 #include "pbd/file_utils.h"
31 #include "ardour/configuration.h"
32 #include "ardour/filesystem_paths.h"
33 #include "ardour/profile.h"
35 #include "theme_manager.h"
36 #include "rgb_macros.h"
37 #include "ardour_ui.h"
38 #include "global_signals.h"
45 using namespace ARDOUR;
48 sigc::signal<void> ColorsChanged;
49 sigc::signal<void,uint32_t> ColorChanged;
51 ThemeManager::ThemeManager()
52 : ArdourWindow (_("Theme Manager")),
53 dark_button (_("Dark Theme")),
54 light_button (_("Light Theme")),
55 reset_button (_("Restore Defaults"))
57 set_title (_("Theme Manager"));
59 color_list = TreeStore::create (columns);
60 color_display.set_model (color_list);
61 color_display.append_column (_("Object"), columns.name);
62 color_display.append_column (_("Color"), columns.color);
63 color_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
64 color_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
65 color_display.set_reorderable (false);
66 color_display.get_selection()->set_mode (SELECTION_NONE);
67 color_display.set_headers_visible (true);
69 CellRenderer* color_cell = color_display.get_column_cell_renderer (1);
70 TreeViewColumn* color_column = color_display.get_column (1);
71 color_column->add_attribute (color_cell->property_cell_background_gdk(), columns.gdkcolor);
73 scroller.add (color_display);
74 scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
76 RadioButton::Group group = dark_button.get_group();
77 light_button.set_group(group);
78 theme_selection_hbox.set_homogeneous(false);
79 theme_selection_hbox.pack_start (dark_button);
80 theme_selection_hbox.pack_start (light_button);
82 Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ());
83 vbox->set_homogeneous (false);
84 vbox->pack_start (theme_selection_hbox, PACK_SHRINK);
85 vbox->pack_start (reset_button, PACK_SHRINK);
86 vbox->pack_start (scroller);
89 color_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::button_press_event), false);
91 color_dialog.get_colorsel()->set_has_opacity_control (true);
92 color_dialog.get_colorsel()->set_has_palette (true);
94 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
95 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
96 dark_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_dark_theme_button_toggled));
97 light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled));
98 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors));
100 set_size_request (-1, 400);
104 ThemeManager::~ThemeManager()
109 ThemeManager::save (string /*path*/)
115 ThemeManager::button_press_event (GdkEventButton* ev)
118 TreeModel::Path path;
119 TreeViewColumn* column;
123 UIConfigVariable<uint32_t> *ccvar;
125 if (!color_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
129 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
131 /* allow normal processing to occur */
135 if ((iter = color_list->get_iter (path))) {
137 UIConfigVariable<uint32_t>* var = (*iter)[columns.pVar];
139 /* parent row, do nothing */
144 uint32_t rgba = (*iter)[columns.rgba];
147 UINT_TO_RGBA (rgba, &r, &g, &b, &a);
148 color.set_rgb_p (r / 255.0, g / 255.0, b / 255.0);
149 color_dialog.get_colorsel()->set_previous_color (color);
150 color_dialog.get_colorsel()->set_current_color (color);
151 color_dialog.get_colorsel()->set_previous_alpha (a * 256);
152 color_dialog.get_colorsel()->set_current_alpha (a * 256);
154 ResponseType result = (ResponseType) color_dialog.run();
157 case RESPONSE_CANCEL:
159 case RESPONSE_ACCEPT:
160 color = color_dialog.get_colorsel()->get_current_color();
161 a = color_dialog.get_colorsel()->get_current_alpha();
162 r = (int) floor (color.get_red_p() * 255.0);
163 g = (int) floor (color.get_green_p() * 255.0);
164 b = (int) floor (color.get_blue_p() * 255.0);
166 rgba = RGBA_TO_UINT(r,g,b,a>>8);
167 (*iter)[columns.rgba] = rgba;
168 (*iter)[columns.gdkcolor] = color;
170 ccvar = (*iter)[columns.pVar];
172 ARDOUR_UI::config()->set_dirty ();
174 ColorsChanged(); //EMIT SIGNAL
182 color_dialog.hide ();
194 load_rc_file (const string& filename, bool themechange)
196 sys::path rc_file_path;
198 SearchPath spath (ardour_search_path());
199 spath += user_config_directory();
200 spath += system_config_search_path();
202 if (!find_file_in_search_path (spath, filename, rc_file_path)) {
203 warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"),
204 filename, spath.to_string(), PROGRAM_NAME)
209 info << "Loading ui configuration file " << rc_file_path.to_string() << endmsg;
211 Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path.to_string(), themechange);
214 /* hmm, this is a problem. the profile doesn't
215 exist when the theme manager is constructed
216 and toggles buttons during "normal" GTK setup.
218 a better solution will be to make all Profile
219 methods static or something.
224 #define HACK_PROFILE_IS_SAE() (getenv("ARDOUR_SAE")!=0)
227 ThemeManager::on_dark_theme_button_toggled()
229 if (!dark_button.get_active()) return;
231 if (HACK_PROFILE_IS_SAE()){
232 ARDOUR_UI::config()->ui_rc_file.set("ardour3_ui_dark_sae.rc");
234 ARDOUR_UI::config()->ui_rc_file.set("ardour3_ui_dark.rc");
236 ARDOUR_UI::config()->set_dirty ();
238 load_rc_file (ARDOUR_UI::config()->ui_rc_file.get(), true);
242 ThemeManager::on_light_theme_button_toggled()
244 if (!light_button.get_active()) return;
246 if (HACK_PROFILE_IS_SAE()){
247 ARDOUR_UI::config()->ui_rc_file.set("ardour3_ui_light_sae.rc");
249 ARDOUR_UI::config()->ui_rc_file.set("ardour3_ui_light.rc");
252 load_rc_file (ARDOUR_UI::config()->ui_rc_file.get(), true);
256 ThemeManager::setup_theme ()
262 for (std::map<std::string,UIConfigVariable<uint32_t> *>::iterator i = ARDOUR_UI::config()->canvas_colors.begin(); i != ARDOUR_UI::config()->canvas_colors.end(); i++) {
265 UIConfigVariable<uint32_t>* var = i->second;
267 TreeModel::Children rows = color_list->children();
269 string::size_type colon;
271 if ((colon = var->name().find (':')) != string::npos) {
273 /* this is supposed to be a child node, so find the
277 string parent = var->name().substr (0, colon);
278 TreeModel::iterator ri;
280 for (ri = rows.begin(); ri != rows.end(); ++ri) {
281 string s = (*ri)[columns.name];
287 if (ri == rows.end()) {
288 /* not found, add the parent as new top level row */
289 row = *(color_list->append());
290 row[columns.name] = parent;
291 row[columns.pVar] = 0;
293 /* now add the child as a child of this one */
295 row = *(color_list->insert (row->children().end()));
296 row[columns.name] = var->name().substr (colon+1);
298 row = *(color_list->insert ((*ri)->children().end()));
299 row[columns.name] = var->name().substr (colon+1);
304 row = *(color_list->append());
305 row[columns.name] = var->name();
309 uint32_t rgba = var->get();
310 UINT_TO_RGBA (rgba, &r, &g, &b, &a);
311 //cerr << (*i)->name() << " == " << hex << rgba << ": " << hex << r << " " << hex << g << " " << hex << b << endl;
312 col.set_rgb_p (r / 255.0, g / 255.0, b / 255.0);
314 row[columns.color] = "";
315 row[columns.pVar] = var;
316 row[columns.rgba] = rgba;
317 row[columns.gdkcolor] = col;
320 ColorsChanged.emit();
322 bool env_defined = false;
323 string rcfile = Glib::getenv("ARDOUR3_UI_RC", env_defined);
326 rcfile = ARDOUR_UI::config()->ui_rc_file.get();
329 if (rcfile == "ardour3_ui_dark.rc" || rcfile == "ardour3_ui_dark_sae.rc") {
330 dark_button.set_active();
331 } else if (rcfile == "ardour3_ui_light.rc" || "ardour3_ui_light_sae.rc") {
332 light_button.set_active();
335 load_rc_file(rcfile, false);
339 ThemeManager::reset_canvas_colors()
341 ARDOUR_UI::config()->load_defaults();