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