set Theme buttons on state reset
[ardour.git] / gtk2_ardour / theme_manager.cc
1 /*
2     Copyright (C) 2000-2007 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 <cmath>
21 #include <iostream>
22 #include <fstream>
23 #include <errno.h>
24
25 #include "fix_carbon.h"
26
27 #include <gtkmm/stock.h>
28 #include <gtkmm/settings.h>
29
30 #include "gtkmm2ext/gtk_ui.h"
31 #include "gtkmm2ext/cell_renderer_color_selector.h"
32 #include "gtkmm2ext/utils.h"
33
34 #include "pbd/file_utils.h"
35 #include "pbd/compose.h"
36
37 #include "ardour/filesystem_paths.h"
38
39 #include "canvas/container.h"
40 #include "canvas/rectangle.h"
41 #include "canvas/scroll_group.h"
42 #include "canvas/wave_view.h"
43
44 #include "ardour_button.h"
45 #include "ardour_dialog.h"
46 #include "theme_manager.h"
47 #include "rgb_macros.h"
48 #include "ardour_ui.h"
49 #include "global_signals.h"
50 #include "utils.h"
51
52 #include "i18n.h"
53
54 using namespace std;
55 using namespace Gtk;
56 using namespace PBD;
57 using namespace ARDOUR;
58 using namespace ARDOUR_UI_UTILS;
59
60 namespace ARDOUR_UI_UTILS {
61         sigc::signal<void> ColorsChanged;
62 }
63
64 ThemeManager::ThemeManager()
65         : dark_button (_("Dark Theme"))
66         , light_button (_("Light Theme"))
67         , reset_button (_("Restore Defaults"))
68         , flat_buttons (_("Draw \"flat\" buttons"))
69         , blink_rec_button (_("Blink Rec-Arm buttons"))
70         , region_color_button (_("Color regions using their track's color"))
71         , show_clipping_button (_("Show waveform clipping"))
72         , waveform_gradient_depth (0, 1.0, 0.05)
73         , waveform_gradient_depth_label (_("Waveforms color gradient depth"))
74         , timeline_item_gradient_depth (0, 1.0, 0.05)
75         , timeline_item_gradient_depth_label (_("Timeline item gradient depth"))
76         , all_dialogs (_("All floating windows are dialogs"))
77         , icon_set_label (_("Icon Set"))
78         , palette_viewport (*palette_scroller.get_hadjustment(), *palette_scroller.get_vadjustment())
79         , palette_group (0)
80         , palette_window (0)
81 {
82         /* Now the alias list */
83         
84         alias_list = TreeStore::create (alias_columns);
85         alias_display.set_model (alias_list);
86         alias_display.append_column (_("Object"), alias_columns.name);
87         
88         Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
89         TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer));
90         color_column->add_attribute (color_renderer->property_color(), alias_columns.color);
91         alias_display.append_column (*color_column);
92         
93         alias_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
94         alias_display.get_column (0)->set_expand (true);
95         alias_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
96         alias_display.get_column (1)->set_expand (false);
97         alias_display.set_reorderable (false);
98         alias_display.get_selection()->set_mode (SELECTION_NONE);
99         alias_display.set_headers_visible (true);
100
101         alias_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::alias_button_press_event), false);
102
103         alias_scroller.add (alias_display);
104
105         /* various buttons */
106         
107         RadioButton::Group group = dark_button.get_group();
108         light_button.set_group(group);
109         theme_selection_hbox.set_homogeneous(false);
110         theme_selection_hbox.pack_start (dark_button);
111         theme_selection_hbox.pack_start (light_button);
112
113         set_homogeneous (false);
114         pack_start (theme_selection_hbox, PACK_SHRINK);
115         pack_start (reset_button, PACK_SHRINK);
116 #ifndef __APPLE__
117         pack_start (all_dialogs, PACK_SHRINK);
118 #endif
119         pack_start (flat_buttons, PACK_SHRINK);
120         pack_start (blink_rec_button, PACK_SHRINK);
121         pack_start (region_color_button, PACK_SHRINK);
122         pack_start (show_clipping_button, PACK_SHRINK);
123
124         Gtk::HBox* hbox;
125
126         vector<string> icon_sets = ::get_icon_sets ();
127
128         if (icon_sets.size() > 1) {
129                 Gtkmm2ext::set_popdown_strings (icon_set_dropdown, icon_sets);
130                 icon_set_dropdown.set_active_text (ARDOUR_UI::config()->get_icon_set());
131
132                 hbox = Gtk::manage (new Gtk::HBox());
133                 hbox->set_spacing (6);
134                 hbox->pack_start (icon_set_label, false, false);
135                 hbox->pack_start (icon_set_dropdown, true, true);
136                 pack_start (*hbox, PACK_SHRINK);
137         }
138
139         
140         hbox = Gtk::manage (new Gtk::HBox());
141         hbox->set_spacing (6);
142         hbox->pack_start (waveform_gradient_depth, true, true);
143         hbox->pack_start (waveform_gradient_depth_label, false, false);
144         pack_start (*hbox, PACK_SHRINK);
145
146         hbox = Gtk::manage (new Gtk::HBox());
147         hbox->set_spacing (6);
148         hbox->pack_start (timeline_item_gradient_depth, true, true);
149         hbox->pack_start (timeline_item_gradient_depth_label, false, false);
150         pack_start (*hbox, PACK_SHRINK);
151
152         palette_group = initialize_palette_canvas (*palette_viewport.canvas());
153         palette_viewport.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), palette_group, palette_viewport.canvas(),
154                                                                      sigc::mem_fun (*this, &ThemeManager::palette_event)));
155         palette_scroller.add (palette_viewport);
156
157         modifier_scroller.add (modifier_vbox);
158         
159         notebook.append_page (alias_scroller, _("Items"));
160         notebook.append_page (palette_scroller, _("Palette"));
161         notebook.append_page (modifier_scroller, _("Transparency"));
162         
163         pack_start (notebook);
164
165         show_all ();
166
167         waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
168         timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
169         
170         color_dialog.get_colorsel()->set_has_opacity_control (true);
171         color_dialog.get_colorsel()->set_has_palette (true);
172         
173         set_ui_to_state();
174
175         color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
176         color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
177         dark_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_dark_theme_button_toggled));
178         light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled));
179         reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors));
180         flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled));
181         blink_rec_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_blink_rec_arm_toggled));
182         region_color_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_region_color_toggled));
183         show_clipping_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_show_clip_toggled));
184         waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
185         timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
186         all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
187         icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed));
188
189         Gtkmm2ext::UI::instance()->set_tip (all_dialogs, 
190                                             string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
191                                                               "This may help with some window managers. This requires a restart of %1 to take effect"),
192                                                             PROGRAM_NAME));
193
194         set_size_request (-1, 400);
195         /* no need to call setup_palette() here, it will be done when its size is allocated */
196         setup_aliases ();
197         setup_modifiers ();
198         
199         ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed));
200 }
201
202 ThemeManager::~ThemeManager()
203 {
204 }
205
206 void
207 ThemeManager::setup_modifiers ()
208 {
209         UIConfiguration* uic (ARDOUR_UI::config());
210         UIConfiguration::Modifiers& modifiers (uic->modifiers);
211         Gtk::HBox* mod_hbox;
212         Gtk::Label* mod_label;
213         Gtk::HScale* mod_scale;
214         
215         Gtkmm2ext::container_clear (modifier_vbox);
216
217         for (UIConfiguration::Modifiers::const_iterator m = modifiers.begin(); m != modifiers.end(); ++m) {
218                 mod_hbox = manage (new HBox);
219
220                 mod_scale = manage (new HScale (0.0, 1.0, 0.01));
221                 mod_scale->set_draw_value (false);
222                 mod_scale->set_value (m->second.a());
223                 mod_scale->set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
224                 mod_scale->signal_value_changed().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::modifier_edited), mod_scale, m->first));
225
226                 mod_label = manage (new Label (m->first));
227                 mod_label->set_alignment (1.0, 0.5);
228                 mod_label->set_size_request (150, -1); /* 150 pixels should be enough for anyone */
229                 
230                 mod_hbox->pack_start (*mod_label, false, true, 12);
231                 mod_hbox->pack_start (*mod_scale, true, true);
232
233                 modifier_vbox.pack_start (*mod_hbox, false, false);
234         }
235
236         modifier_vbox.show_all ();
237
238 }
239
240 void
241 ThemeManager::modifier_edited (Gtk::Range* range, string name)
242 {
243         using namespace ArdourCanvas;
244         
245         double alpha = range->get_value();
246         SVAModifier svam (SVAModifier::Assign, -1.0, -1.0, alpha);
247         ARDOUR_UI::config()->set_modifier (name, svam);
248 }
249
250 void
251 ThemeManager::colors_changed ()
252 {
253         setup_palette ();
254         setup_aliases ();       
255         setup_modifiers ();     
256 }
257
258 int
259 ThemeManager::save (string /*path*/)
260 {
261         return 0;
262 }
263
264 void
265 ThemeManager::on_flat_buttons_toggled ()
266 {
267         ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active());
268         ArdourButton::set_flat_buttons (flat_buttons.get_active());
269         /* force a redraw */
270         gtk_rc_reset_styles (gtk_settings_get_default());
271 }
272
273 void
274 ThemeManager::on_blink_rec_arm_toggled ()
275 {
276         ARDOUR_UI::config()->set_blink_rec_arm (blink_rec_button.get_active());
277         ARDOUR::Config->ParameterChanged("blink-rec-arm");
278 }
279
280 void
281 ThemeManager::on_region_color_toggled ()
282 {
283         ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active());
284 }
285
286 void
287 ThemeManager::on_show_clip_toggled ()
288 {
289         ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active());
290         // "show-waveform-clipping" was a session config key
291         ArdourCanvas::WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
292 }
293
294 void
295 ThemeManager::on_all_dialogs_toggled ()
296 {
297         ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active());
298 }
299
300 void
301 ThemeManager::on_waveform_gradient_depth_change ()
302 {
303         double v = waveform_gradient_depth.get_value();
304
305         ARDOUR_UI::config()->set_waveform_gradient_depth (v);
306         ArdourCanvas::WaveView::set_global_gradient_depth (v);
307 }
308
309 void
310 ThemeManager::on_timeline_item_gradient_depth_change ()
311 {
312         double v = timeline_item_gradient_depth.get_value();
313
314         ARDOUR_UI::config()->set_timeline_item_gradient_depth (v);
315 }
316
317 void
318 ThemeManager::on_icon_set_changed ()
319 {
320         string new_set = icon_set_dropdown.get_active_text();
321         ARDOUR_UI::config()->set_icon_set (new_set);
322 }
323
324 void
325 ThemeManager::on_dark_theme_button_toggled()
326 {
327         if (!dark_button.get_active()) return;
328
329         UIConfiguration* uic (ARDOUR_UI::config());
330         
331         uic->set_color_file("dark");
332 }
333
334 void
335 ThemeManager::on_light_theme_button_toggled()
336 {
337         if (!light_button.get_active()) return;
338
339         UIConfiguration* uic (ARDOUR_UI::config());
340         
341         uic->set_color_file("light");
342 }
343
344 void
345 ThemeManager::set_ui_to_state()
346 {
347         /* there is no way these values can change individually
348          * by themselves (w/o user-interaction)
349          * hence a common combined update function suffices
350          */
351
352         if (ARDOUR_UI::config()->get_color_file() == "light") {
353                 light_button.set_active(true);
354         } else {
355                 dark_button.set_active(true);
356         }
357
358         /* there is no need to block signal handlers, here,
359          * all elements check if the value has changed and ignore NOOPs 
360          */
361         flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
362         blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm());
363         region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color());
364         show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping());
365         waveform_gradient_depth.set_value(ARDOUR_UI::config()->get_waveform_gradient_depth());
366         timeline_item_gradient_depth.set_value(ARDOUR_UI::config()->get_timeline_item_gradient_depth());
367 }
368
369 void
370 ThemeManager::reset_canvas_colors()
371 {
372         ARDOUR_UI::config()->load_defaults();
373         ARDOUR_UI::config()->save_state ();
374         set_ui_to_state();
375 }
376
377 ArdourCanvas::Container*
378 ThemeManager::initialize_palette_canvas (ArdourCanvas::Canvas& canvas)
379 {
380         using namespace ArdourCanvas;
381
382         /* hide background */
383         canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0));
384
385         /* bi-directional scroll group */
386         
387         ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
388         canvas.add_scroller (*scroll_group);
389
390         /* new container to hold everything */
391
392         return new ArdourCanvas::Container (scroll_group);
393 }
394
395 void
396 ThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, ArdourCanvas::Canvas* canvas, sigc::slot<bool,GdkEvent*,std::string> event_handler)
397 {
398         build_palette_canvas (*canvas, *group, event_handler);
399 }
400
401 struct NamedColor {
402         string name;
403         ArdourCanvas::HSV    color;
404         NamedColor (string s, ArdourCanvas::HSV c) : name (s), color (c) {}
405 };
406
407 struct SortByHue {
408         bool operator() (NamedColor const & a, NamedColor const & b) {
409                 using namespace ArdourCanvas;
410                 const HSV black (0, 0, 0);
411                 if (a.color.is_gray() || b.color.is_gray()) {
412                         return black.distance (a.color) < black.distance (b.color);
413                 } else {
414                         return a.color.h < b.color.h;
415                         // const HSV red (rgba_to_color (1.0, 0.0, 0.0, 1.0));
416                         // return red.distance (a.color) < red.distance (b.color);
417                 }
418         }
419 };
420
421
422 void
423 ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::Container& group, sigc::slot<bool,GdkEvent*,std::string> event_handler)
424 {
425         using namespace ArdourCanvas;
426
427         /* we want the colors sorted by hue, with their name */
428
429         UIConfiguration::Colors& colors (ARDOUR_UI::config()->colors);
430         vector<NamedColor> nc;
431         for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) {
432                 nc.push_back (NamedColor (x->first, HSV (x->second)));
433         }
434         SortByHue sorter;
435         sort (nc.begin(), nc.end(), sorter);
436         
437         const uint32_t color_limit = nc.size();
438         const double box_size = 20.0;
439         const double width = canvas.width();
440         const double height = canvas.height();
441
442         uint32_t color_num = 0;
443
444         /* clear existing rects and delete them */
445         
446         group.clear (true);
447         
448         for (uint32_t y = 0; y < height - box_size && color_num < color_limit; y += box_size) {
449                 for (uint32_t x = 0; x < width - box_size && color_num < color_limit; x += box_size) {
450                         ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size));
451
452                         string name = nc[color_num++].name;
453
454                         UIConfiguration::Colors::iterator c = colors.find (name);
455
456                         if (c != colors.end()) {
457                                 Color color = c->second;
458                                 r->set_fill_color (color);
459                                 r->set_outline_color (rgba_to_color (0.0, 0.0, 0.0, 1.0));
460                                 r->set_tooltip (name);
461                                 r->Event.connect (sigc::bind (event_handler, name));
462                         }
463                 }
464         }
465 }
466
467 void
468 ThemeManager::palette_size_request (Gtk::Requisition* req)
469 {
470         uint32_t ncolors = ARDOUR_UI::config()->colors.size();
471         const int box_size = 20;
472
473         double c = sqrt ((double)ncolors);
474         req->width = (int) floor (c * box_size);
475         req->height = (int) floor (c * box_size);
476
477         /* add overflow row if necessary */
478         
479         if (fmod (ncolors, c) != 0.0) {
480                 req->height += box_size;
481         }
482 }
483
484 void
485 ThemeManager::setup_palette ()
486 {
487         build_palette_canvas (*palette_viewport.canvas(), *palette_group, sigc::mem_fun (*this, &ThemeManager::palette_event));
488 }
489
490 bool
491 ThemeManager::palette_event (GdkEvent* ev, string name)
492 {
493         switch (ev->type) {
494         case GDK_BUTTON_RELEASE:
495                 edit_palette_color (name);
496                 return true;
497         default:
498                 break;
499         }
500         return true;
501 }
502
503 void
504 ThemeManager::edit_palette_color (std::string name)
505 {
506         using namespace ArdourCanvas;
507         double r,g, b, a;
508         UIConfiguration* uic (ARDOUR_UI::config());
509         ArdourCanvas::Color c = uic->color (name);
510         Gdk::Color gdkcolor;
511
512         color_to_rgba (c, r, g, b, a);
513
514         gdkcolor.set_rgb_p (r, g, b);
515         color_dialog.get_colorsel()->set_previous_color (gdkcolor);
516         color_dialog.get_colorsel()->set_current_color (gdkcolor);
517         color_dialog.get_colorsel()->set_previous_alpha ((guint16) (a * 65535));
518         color_dialog.get_colorsel()->set_current_alpha ((guint16) (a * 65535));
519
520         color_dialog_connection.disconnect ();
521         color_dialog_connection = color_dialog.signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_color_response), name));
522         color_dialog.present();
523 }
524
525 void
526 ThemeManager::palette_color_response (int result, std::string name)
527 {
528         using namespace ArdourCanvas;
529
530         color_dialog_connection.disconnect ();
531         
532         UIConfiguration* uic (ARDOUR_UI::config());
533         Gdk::Color gdkcolor;
534         double r,g, b, a;
535
536         switch (result) {
537         case RESPONSE_ACCEPT:
538         case RESPONSE_OK:
539                 gdkcolor = color_dialog.get_colorsel()->get_current_color();
540                 a = color_dialog.get_colorsel()->get_current_alpha() / 65535.0;
541                 r = gdkcolor.get_red_p();
542                 g = gdkcolor.get_green_p();
543                 b = gdkcolor.get_blue_p();
544                 
545                 uic->set_color (name, rgba_to_color (r, g, b, a));
546                 break;
547                 
548         default:
549                 break;
550         }
551
552         color_dialog.hide ();
553 }
554
555 bool
556 ThemeManager::alias_palette_event (GdkEvent* ev, string new_alias, string target_name)
557 {
558         switch (ev->type) {
559         case GDK_BUTTON_RELEASE:
560                 ARDOUR_UI::config()->set_alias (target_name, new_alias);
561                 return true;
562                 break;
563         default:
564                 break;
565         }
566         return false;
567 }
568
569 void
570 ThemeManager::alias_palette_response (int response, std::string target_name, std::string old_alias)
571 {
572         switch (response) {
573         case GTK_RESPONSE_OK:
574         case GTK_RESPONSE_ACCEPT:
575                 /* rebuild alias list with new color: inefficient but simple */
576                 setup_aliases ();
577                 break;
578
579         case GTK_RESPONSE_REJECT:
580                 /* revert choice */
581                 ARDOUR_UI::config()->set_alias (target_name, old_alias);
582                 break;
583
584         default:
585                 /* do nothing */
586                 break;
587         }
588
589         palette_window->hide ();
590 }
591
592 void
593 ThemeManager::choose_color_from_palette (string const & name)
594 {
595         UIConfiguration* uic (ARDOUR_UI::config());
596         UIConfiguration::ColorAliases::iterator i = uic->color_aliases.find (name);
597
598         if (i == uic->color_aliases.end()) {
599                 return;
600         }
601
602         delete palette_window;
603
604         palette_window = new ArdourDialog (_("Color Palette"));
605         palette_window->add_button (Stock::CANCEL, RESPONSE_REJECT); /* using CANCEL causes confusion if dialog is closed via CloseAllDialogs */
606         palette_window->add_button (Stock::OK, RESPONSE_OK);
607         
608         ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas ();
609         ArdourCanvas::Container* group = initialize_palette_canvas (*canvas);
610         
611         canvas->signal_size_request().connect (sigc::mem_fun (*this, &ThemeManager::palette_size_request));
612         canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, canvas,
613                                                             sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_event), name)));
614         
615         palette_window->get_vbox()->pack_start (*canvas);
616         palette_window->show_all ();
617
618         palette_response_connection = palette_window->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_response), name, i->second));
619
620         palette_window->set_position (WIN_POS_MOUSE);
621         palette_window->present ();
622 }
623
624 void
625 ThemeManager::setup_aliases ()
626 {
627         using namespace ArdourCanvas;
628         
629         UIConfiguration* uic (ARDOUR_UI::config());
630         UIConfiguration::ColorAliases& aliases (uic->color_aliases);
631
632         alias_list->clear ();
633
634         for (UIConfiguration::ColorAliases::iterator i = aliases.begin(); i != aliases.end(); ++i) {
635                 TreeModel::Children rows = alias_list->children();
636                 TreeModel::Row row;
637                 string::size_type colon;
638
639                 if ((colon = i->first.find (':')) != string::npos) {
640
641                         /* this is supposed to be a child node, so find the
642                          * parent 
643                          */
644
645                         string parent = i->first.substr (0, colon);
646                         TreeModel::iterator ri;
647
648                         for (ri = rows.begin(); ri != rows.end(); ++ri) {
649                                 string s = (*ri)[alias_columns.name];
650                                 if (s == parent) {
651                                         break;
652                                 }
653                         }
654
655                         if (ri == rows.end()) {
656                                 /* not found, add the parent as new top level row */
657                                 row = *(alias_list->append());
658                                 row[alias_columns.name] = parent;
659                                 row[alias_columns.alias] = "";
660                                 
661                                 /* now add the child as a child of this one */
662
663                                 row = *(alias_list->insert (row->children().end()));
664                                 row[alias_columns.name] = i->first.substr (colon+1);
665                         } else {
666                                 row = *(alias_list->insert ((*ri)->children().end()));
667                                 row[alias_columns.name] = i->first.substr (colon+1);
668                         }
669
670                 } else {
671                         /* add as a child */
672                         row = *(alias_list->append());
673                         row[alias_columns.name] = i->first;
674                         row[alias_columns.key] = i->first;
675                 }
676
677                 row[alias_columns.key] = i->first;
678                 row[alias_columns.alias] = i->second;
679
680                 Gdk::Color col;
681                 double r, g, b, a;
682                 Color c (uic->color (i->second));
683                 color_to_rgba (c, r, g, b, a);
684                 col.set_rgb_p (r, g, b);
685
686                 row[alias_columns.color] = col;
687         }
688 }
689
690 bool
691 ThemeManager::alias_button_press_event (GdkEventButton* ev)
692 {
693         TreeIter iter;
694         TreeModel::Path path;
695         TreeViewColumn* column;
696         int cellx;
697         int celly;
698
699         if (!alias_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
700                 return false;
701         }
702
703         guint32 colnum = GPOINTER_TO_UINT (column->get_data (X_("colnum")));
704
705         switch (colnum) {
706         case 0:
707                 /* allow normal processing to occur */
708                 return false;
709
710         case 1: /* color */
711                 if ((iter = alias_list->get_iter (path))) {
712                         string target_color_alias = (*iter)[alias_columns.key];
713                         if (!target_color_alias.empty()) {
714                                 choose_color_from_palette (target_color_alias);
715                         }
716                 }
717                 break;
718         }
719
720         return true;
721 }