initialize theme > gradient sliders.
[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         flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
174         blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm());
175         region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color());
176         show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping());
177         waveform_gradient_depth.set_value(ARDOUR_UI::config()->get_waveform_gradient_depth());
178         timeline_item_gradient_depth.set_value(ARDOUR_UI::config()->get_timeline_item_gradient_depth());
179
180         color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
181         color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
182         dark_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_dark_theme_button_toggled));
183         light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled));
184         reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors));
185         flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled));
186         blink_rec_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_blink_rec_arm_toggled));
187         region_color_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_region_color_toggled));
188         show_clipping_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_show_clip_toggled));
189         waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
190         timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
191         all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
192         icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed));
193
194         Gtkmm2ext::UI::instance()->set_tip (all_dialogs, 
195                                             string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
196                                                               "This may help with some window managers. This requires a restart of %1 to take effect"),
197                                                             PROGRAM_NAME));
198
199         set_size_request (-1, 400);
200         /* no need to call setup_palette() here, it will be done when its size is allocated */
201         setup_aliases ();
202         setup_modifiers ();
203         
204         ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed));
205 }
206
207 ThemeManager::~ThemeManager()
208 {
209 }
210
211 void
212 ThemeManager::setup_modifiers ()
213 {
214         UIConfiguration* uic (ARDOUR_UI::config());
215         UIConfiguration::Modifiers& modifiers (uic->modifiers);
216         Gtk::HBox* mod_hbox;
217         Gtk::Label* mod_label;
218         Gtk::HScale* mod_scale;
219         
220         Gtkmm2ext::container_clear (modifier_vbox);
221
222         for (UIConfiguration::Modifiers::const_iterator m = modifiers.begin(); m != modifiers.end(); ++m) {
223                 mod_hbox = manage (new HBox);
224
225                 mod_scale = manage (new HScale (0.0, 1.0, 0.01));
226                 mod_scale->set_draw_value (false);
227                 mod_scale->set_value (m->second.a());
228                 mod_scale->set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
229                 mod_scale->signal_value_changed().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::modifier_edited), mod_scale, m->first));
230
231                 mod_label = manage (new Label (m->first));
232                 mod_label->set_alignment (1.0, 0.5);
233                 mod_label->set_size_request (150, -1); /* 150 pixels should be enough for anyone */
234                 
235                 mod_hbox->pack_start (*mod_label, false, true, 12);
236                 mod_hbox->pack_start (*mod_scale, true, true);
237
238                 modifier_vbox.pack_start (*mod_hbox, false, false);
239         }
240
241         modifier_vbox.show_all ();
242
243 }
244
245 void
246 ThemeManager::modifier_edited (Gtk::Range* range, string name)
247 {
248         using namespace ArdourCanvas;
249         
250         double alpha = range->get_value();
251         SVAModifier svam (SVAModifier::Assign, -1.0, -1.0, alpha);
252         ARDOUR_UI::config()->set_modifier (name, svam);
253 }
254
255 void
256 ThemeManager::colors_changed ()
257 {
258         setup_palette ();
259         setup_aliases ();       
260         setup_modifiers ();     
261 }
262
263 int
264 ThemeManager::save (string /*path*/)
265 {
266         return 0;
267 }
268
269 void
270 ThemeManager::on_flat_buttons_toggled ()
271 {
272         ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active());
273         ArdourButton::set_flat_buttons (flat_buttons.get_active());
274         /* force a redraw */
275         gtk_rc_reset_styles (gtk_settings_get_default());
276 }
277
278 void
279 ThemeManager::on_blink_rec_arm_toggled ()
280 {
281         ARDOUR_UI::config()->set_blink_rec_arm (blink_rec_button.get_active());
282         ARDOUR::Config->ParameterChanged("blink-rec-arm");
283 }
284
285 void
286 ThemeManager::on_region_color_toggled ()
287 {
288         ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active());
289 }
290
291 void
292 ThemeManager::on_show_clip_toggled ()
293 {
294         ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active());
295         // "show-waveform-clipping" was a session config key
296         ArdourCanvas::WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
297 }
298
299 void
300 ThemeManager::on_all_dialogs_toggled ()
301 {
302         ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active());
303 }
304
305 void
306 ThemeManager::on_waveform_gradient_depth_change ()
307 {
308         double v = waveform_gradient_depth.get_value();
309
310         ARDOUR_UI::config()->set_waveform_gradient_depth (v);
311         ArdourCanvas::WaveView::set_global_gradient_depth (v);
312 }
313
314 void
315 ThemeManager::on_timeline_item_gradient_depth_change ()
316 {
317         double v = timeline_item_gradient_depth.get_value();
318
319         ARDOUR_UI::config()->set_timeline_item_gradient_depth (v);
320 }
321
322 void
323 ThemeManager::on_icon_set_changed ()
324 {
325         string new_set = icon_set_dropdown.get_active_text();
326         ARDOUR_UI::config()->set_icon_set (new_set);
327 }
328
329 void
330 ThemeManager::on_dark_theme_button_toggled()
331 {
332         if (!dark_button.get_active()) return;
333
334         UIConfiguration* uic (ARDOUR_UI::config());
335         
336         uic->set_color_file("dark");
337 }
338
339 void
340 ThemeManager::on_light_theme_button_toggled()
341 {
342         if (!light_button.get_active()) return;
343
344         UIConfiguration* uic (ARDOUR_UI::config());
345         
346         uic->set_color_file("light");
347 }
348
349 void
350 ThemeManager::reset_canvas_colors()
351 {
352         ARDOUR_UI::config()->load_defaults();
353         ARDOUR_UI::config()->save_state ();
354 }
355
356 ArdourCanvas::Container*
357 ThemeManager::initialize_palette_canvas (ArdourCanvas::Canvas& canvas)
358 {
359         using namespace ArdourCanvas;
360
361         /* hide background */
362         canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0));
363
364         /* bi-directional scroll group */
365         
366         ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
367         canvas.add_scroller (*scroll_group);
368
369         /* new container to hold everything */
370
371         return new ArdourCanvas::Container (scroll_group);
372 }
373
374 void
375 ThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, ArdourCanvas::Canvas* canvas, sigc::slot<bool,GdkEvent*,std::string> event_handler)
376 {
377         build_palette_canvas (*canvas, *group, event_handler);
378 }
379
380 struct NamedColor {
381         string name;
382         ArdourCanvas::HSV    color;
383         NamedColor (string s, ArdourCanvas::HSV c) : name (s), color (c) {}
384 };
385
386 struct SortByHue {
387         bool operator() (NamedColor const & a, NamedColor const & b) {
388                 using namespace ArdourCanvas;
389                 const HSV black (0, 0, 0);
390                 if (a.color.is_gray() || b.color.is_gray()) {
391                         return black.distance (a.color) < black.distance (b.color);
392                 } else {
393                         return a.color.h < b.color.h;
394                         // const HSV red (rgba_to_color (1.0, 0.0, 0.0, 1.0));
395                         // return red.distance (a.color) < red.distance (b.color);
396                 }
397         }
398 };
399
400
401 void
402 ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::Container& group, sigc::slot<bool,GdkEvent*,std::string> event_handler)
403 {
404         using namespace ArdourCanvas;
405
406         /* we want the colors sorted by hue, with their name */
407
408         UIConfiguration::Colors& colors (ARDOUR_UI::config()->colors);
409         vector<NamedColor> nc;
410         for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) {
411                 nc.push_back (NamedColor (x->first, HSV (x->second)));
412         }
413         SortByHue sorter;
414         sort (nc.begin(), nc.end(), sorter);
415         
416         const uint32_t color_limit = nc.size();
417         const double box_size = 20.0;
418         const double width = canvas.width();
419         const double height = canvas.height();
420
421         uint32_t color_num = 0;
422
423         /* clear existing rects and delete them */
424         
425         group.clear (true);
426         
427         for (uint32_t y = 0; y < height - box_size && color_num < color_limit; y += box_size) {
428                 for (uint32_t x = 0; x < width - box_size && color_num < color_limit; x += box_size) {
429                         ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size));
430
431                         string name = nc[color_num++].name;
432
433                         UIConfiguration::Colors::iterator c = colors.find (name);
434
435                         if (c != colors.end()) {
436                                 Color color = c->second;
437                                 r->set_fill_color (color);
438                                 r->set_outline_color (rgba_to_color (0.0, 0.0, 0.0, 1.0));
439                                 r->set_tooltip (name);
440                                 r->Event.connect (sigc::bind (event_handler, name));
441                         }
442                 }
443         }
444 }
445
446 void
447 ThemeManager::palette_size_request (Gtk::Requisition* req)
448 {
449         uint32_t ncolors = ARDOUR_UI::config()->colors.size();
450         const int box_size = 20;
451
452         double c = sqrt ((double)ncolors);
453         req->width = (int) floor (c * box_size);
454         req->height = (int) floor (c * box_size);
455
456         /* add overflow row if necessary */
457         
458         if (fmod (ncolors, c) != 0.0) {
459                 req->height += box_size;
460         }
461 }
462
463 void
464 ThemeManager::setup_palette ()
465 {
466         build_palette_canvas (*palette_viewport.canvas(), *palette_group, sigc::mem_fun (*this, &ThemeManager::palette_event));
467 }
468
469 bool
470 ThemeManager::palette_event (GdkEvent* ev, string name)
471 {
472         switch (ev->type) {
473         case GDK_BUTTON_RELEASE:
474                 edit_palette_color (name);
475                 return true;
476         default:
477                 break;
478         }
479         return true;
480 }
481
482 void
483 ThemeManager::edit_palette_color (std::string name)
484 {
485         using namespace ArdourCanvas;
486         double r,g, b, a;
487         UIConfiguration* uic (ARDOUR_UI::config());
488         ArdourCanvas::Color c = uic->color (name);
489         Gdk::Color gdkcolor;
490
491         color_to_rgba (c, r, g, b, a);
492
493         gdkcolor.set_rgb_p (r, g, b);
494         color_dialog.get_colorsel()->set_previous_color (gdkcolor);
495         color_dialog.get_colorsel()->set_current_color (gdkcolor);
496         color_dialog.get_colorsel()->set_previous_alpha ((guint16) (a * 65535));
497         color_dialog.get_colorsel()->set_current_alpha ((guint16) (a * 65535));
498
499         color_dialog_connection.disconnect ();
500         color_dialog_connection = color_dialog.signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_color_response), name));
501         color_dialog.present();
502 }
503
504 void
505 ThemeManager::palette_color_response (int result, std::string name)
506 {
507         using namespace ArdourCanvas;
508
509         color_dialog_connection.disconnect ();
510         
511         UIConfiguration* uic (ARDOUR_UI::config());
512         Gdk::Color gdkcolor;
513         double r,g, b, a;
514
515         switch (result) {
516         case RESPONSE_ACCEPT:
517         case RESPONSE_OK:
518                 gdkcolor = color_dialog.get_colorsel()->get_current_color();
519                 a = color_dialog.get_colorsel()->get_current_alpha() / 65535.0;
520                 r = gdkcolor.get_red_p();
521                 g = gdkcolor.get_green_p();
522                 b = gdkcolor.get_blue_p();
523                 
524                 uic->set_color (name, rgba_to_color (r, g, b, a));
525                 break;
526                 
527         default:
528                 break;
529         }
530
531         color_dialog.hide ();
532 }
533
534 bool
535 ThemeManager::alias_palette_event (GdkEvent* ev, string new_alias, string target_name)
536 {
537         switch (ev->type) {
538         case GDK_BUTTON_RELEASE:
539                 ARDOUR_UI::config()->set_alias (target_name, new_alias);
540                 return true;
541                 break;
542         default:
543                 break;
544         }
545         return false;
546 }
547
548 void
549 ThemeManager::alias_palette_response (int response, std::string target_name, std::string old_alias)
550 {
551         switch (response) {
552         case GTK_RESPONSE_OK:
553         case GTK_RESPONSE_ACCEPT:
554                 /* rebuild alias list with new color: inefficient but simple */
555                 setup_aliases ();
556                 break;
557
558         case GTK_RESPONSE_REJECT:
559                 /* revert choice */
560                 ARDOUR_UI::config()->set_alias (target_name, old_alias);
561                 break;
562
563         default:
564                 /* do nothing */
565                 break;
566         }
567
568         palette_window->hide ();
569 }
570
571 void
572 ThemeManager::choose_color_from_palette (string const & name)
573 {
574         UIConfiguration* uic (ARDOUR_UI::config());
575         UIConfiguration::ColorAliases::iterator i = uic->color_aliases.find (name);
576
577         if (i == uic->color_aliases.end()) {
578                 return;
579         }
580
581         delete palette_window;
582
583         palette_window = new ArdourDialog (_("Color Palette"));
584         palette_window->add_button (Stock::CANCEL, RESPONSE_REJECT); /* using CANCEL causes confusion if dialog is closed via CloseAllDialogs */
585         palette_window->add_button (Stock::OK, RESPONSE_OK);
586         
587         ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas ();
588         ArdourCanvas::Container* group = initialize_palette_canvas (*canvas);
589         
590         canvas->signal_size_request().connect (sigc::mem_fun (*this, &ThemeManager::palette_size_request));
591         canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, canvas,
592                                                             sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_event), name)));
593         
594         palette_window->get_vbox()->pack_start (*canvas);
595         palette_window->show_all ();
596
597         palette_response_connection = palette_window->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_response), name, i->second));
598
599         palette_window->set_position (WIN_POS_MOUSE);
600         palette_window->present ();
601 }
602
603 void
604 ThemeManager::setup_aliases ()
605 {
606         using namespace ArdourCanvas;
607         
608         UIConfiguration* uic (ARDOUR_UI::config());
609         UIConfiguration::ColorAliases& aliases (uic->color_aliases);
610
611         alias_list->clear ();
612
613         for (UIConfiguration::ColorAliases::iterator i = aliases.begin(); i != aliases.end(); ++i) {
614                 TreeModel::Children rows = alias_list->children();
615                 TreeModel::Row row;
616                 string::size_type colon;
617
618                 if ((colon = i->first.find (':')) != string::npos) {
619
620                         /* this is supposed to be a child node, so find the
621                          * parent 
622                          */
623
624                         string parent = i->first.substr (0, colon);
625                         TreeModel::iterator ri;
626
627                         for (ri = rows.begin(); ri != rows.end(); ++ri) {
628                                 string s = (*ri)[alias_columns.name];
629                                 if (s == parent) {
630                                         break;
631                                 }
632                         }
633
634                         if (ri == rows.end()) {
635                                 /* not found, add the parent as new top level row */
636                                 row = *(alias_list->append());
637                                 row[alias_columns.name] = parent;
638                                 row[alias_columns.alias] = "";
639                                 
640                                 /* now add the child as a child of this one */
641
642                                 row = *(alias_list->insert (row->children().end()));
643                                 row[alias_columns.name] = i->first.substr (colon+1);
644                         } else {
645                                 row = *(alias_list->insert ((*ri)->children().end()));
646                                 row[alias_columns.name] = i->first.substr (colon+1);
647                         }
648
649                 } else {
650                         /* add as a child */
651                         row = *(alias_list->append());
652                         row[alias_columns.name] = i->first;
653                         row[alias_columns.key] = i->first;
654                 }
655
656                 row[alias_columns.key] = i->first;
657                 row[alias_columns.alias] = i->second;
658
659                 Gdk::Color col;
660                 double r, g, b, a;
661                 Color c (uic->color (i->second));
662                 color_to_rgba (c, r, g, b, a);
663                 col.set_rgb_p (r, g, b);
664
665                 row[alias_columns.color] = col;
666         }
667 }
668
669 bool
670 ThemeManager::alias_button_press_event (GdkEventButton* ev)
671 {
672         TreeIter iter;
673         TreeModel::Path path;
674         TreeViewColumn* column;
675         int cellx;
676         int celly;
677
678         if (!alias_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
679                 return false;
680         }
681
682         guint32 colnum = GPOINTER_TO_UINT (column->get_data (X_("colnum")));
683
684         switch (colnum) {
685         case 0:
686                 /* allow normal processing to occur */
687                 return false;
688
689         case 1: /* color */
690                 if ((iter = alias_list->get_iter (path))) {
691                         string target_color_alias = (*iter)[alias_columns.key];
692                         if (!target_color_alias.empty()) {
693                                 choose_color_from_palette (target_color_alias);
694                         }
695                 }
696                 break;
697         }
698
699         return true;
700 }