use new method in MidiPatchManager to use MIDNAM data when setting a MidiTimeAxisView
[ardour.git] / gtk2_ardour / ui_config.cc
1 /*
2  * Copyright (C) 2008-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2012-2016 Tim Mayberry <mojofunk@gmail.com>
6  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG
24 #define OPTIONAL_CAIRO_IMAGE_SURFACE
25 #endif
26
27 #include <iostream>
28 #include <sstream>
29 #include <unistd.h>
30 #include <cstdlib>
31 #include <cstdio> /* for snprintf, grrr */
32
33 #include <cairo/cairo.h>
34
35 #include <pango/pangoft2.h> // for fontmap resolution control for GnomeCanvas
36 #include <pango/pangocairo.h> // for fontmap resolution control for GnomeCanvas
37
38 #include <glibmm/miscutils.h>
39
40 #include <gtkmm/settings.h>
41
42 #include "pbd/convert.h"
43 #include "pbd/error.h"
44 #include "pbd/failed_constructor.h"
45 #include "pbd/file_utils.h"
46 #include "pbd/gstdio_compat.h"
47 #include "pbd/unwind.h"
48 #include "pbd/xml++.h"
49
50 #include "ardour/filesystem_paths.h"
51 #include "ardour/search_paths.h"
52 #include "ardour/revision.h"
53 #include "ardour/utils.h"
54 #include "ardour/types_convert.h"
55
56 #include "gtkmm2ext/rgb_macros.h"
57 #include "gtkmm2ext/gtk_ui.h"
58
59 #include "ui_config.h"
60
61 #include "pbd/i18n.h"
62
63 using namespace std;
64 using namespace PBD;
65 using namespace ARDOUR;
66 using namespace Gtkmm2ext;
67
68 static const char* ui_config_file_name = "ui_config";
69 static const char* default_ui_config_file_name = "default_ui_config";
70
71 static const double hue_width = 18.0;
72 std::string UIConfiguration::color_file_suffix = X_(".colors");
73
74 UIConfiguration&
75 UIConfiguration::instance ()
76 {
77         static UIConfiguration s_instance;
78         _instance = &s_instance;
79         return s_instance;
80 }
81
82 UIConfiguration::UIConfiguration ()
83         :
84 #undef  UI_CONFIG_VARIABLE
85 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
86 #define CANVAS_FONT_VARIABLE(var,name) var (name),
87 #include "ui_config_vars.h"
88 #include "canvas_vars.h"
89 #undef  UI_CONFIG_VARIABLE
90 #undef  CANVAS_FONT_VARIABLE
91
92         _dirty (false),
93         aliases_modified (false),
94         colors_modified (false),
95         modifiers_modified (false),
96         block_save (0)
97 {
98         load_state();
99
100         ColorsChanged.connect (boost::bind (&UIConfiguration::colors_changed, this));
101
102         ParameterChanged.connect (sigc::mem_fun (*this, &UIConfiguration::parameter_changed));
103 }
104
105 UIConfiguration::~UIConfiguration ()
106 {
107 }
108
109 void
110 UIConfiguration::colors_changed ()
111 {
112         reset_gtk_theme ();
113
114         /* In theory, one of these ought to work:
115
116            gtk_rc_reparse_all_for_settings (gtk_settings_get_default(), true);
117            gtk_rc_reset_styles (gtk_settings_get_default());
118
119            but in practice, neither of them do. So just reload the current
120            GTK RC file, which causes a reset of all styles and a redraw
121         */
122
123         parameter_changed ("ui-rc-file");
124 }
125
126 void
127 UIConfiguration::parameter_changed (string param)
128 {
129         _dirty = true;
130
131         if (param == "ui-rc-file") {
132                 load_rc_file (true);
133         } else if (param == "color-file") {
134                 load_color_theme (true);
135         }
136
137         save_state ();
138 }
139
140 void
141 UIConfiguration::reset_gtk_theme ()
142 {
143         std::string color_scheme_string("gtk_color_scheme = \"");
144
145         for (ColorAliases::iterator g = color_aliases.begin(); g != color_aliases.end(); ++g) {
146
147                 if (g->first.find ("gtk_") == 0) {
148                         const string gtk_name = g->first.substr (4);
149                         Gtkmm2ext::Color a_color = color (g->second);
150
151                         color_scheme_string += gtk_name + ":#" + color_to_hex_string_no_alpha (a_color) + ';';
152                 }
153         }
154
155         color_scheme_string += '"';
156
157         /* reset GTK color scheme */
158
159         Gtk::Settings::get_default()->property_gtk_color_scheme() = color_scheme_string;
160 }
161
162 void
163 UIConfiguration::reset_dpi ()
164 {
165         long val = get_font_scale();
166
167         /* FT2 rendering - used by GnomeCanvas, sigh */
168
169 #ifndef PLATFORM_WINDOWS
170         pango_ft2_font_map_set_resolution ((PangoFT2FontMap*) pango_ft2_font_map_new(), val/1024, val/1024); // XXX pango_ft2_font_map_new leaks
171 #endif
172
173         /* Cairo rendering, in case there is any */
174
175         pango_cairo_font_map_set_resolution ((PangoCairoFontMap*) pango_cairo_font_map_get_default(), val/1024);
176
177         /* Xft rendering */
178
179         gtk_settings_set_long_property (gtk_settings_get_default(),
180                                         "gtk-xft-dpi", val, "ardour");
181         DPIReset(); //Emit Signal
182 }
183
184 float
185 UIConfiguration::get_ui_scale ()
186 {
187         return get_font_scale () / 102400.;
188 }
189
190 void
191 UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
192 {
193 #undef  UI_CONFIG_VARIABLE
194 #define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
195 #include "ui_config_vars.h"
196 #undef  UI_CONFIG_VARIABLE
197 }
198
199 int
200 UIConfiguration::pre_gui_init ()
201 {
202 #ifdef CAIRO_SUPPORTS_FORCE_BUGGY_GRADIENTS_ENVIRONMENT_VARIABLE
203         if (get_buggy_gradients()) {
204                 g_setenv ("FORCE_BUGGY_GRADIENTS", "1", 1);
205         }
206 #endif
207 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
208         if (get_cairo_image_surface()) {
209                 g_setenv ("ARDOUR_IMAGE_SURFACE", "1", 1);
210         }
211 #endif
212         return 0;
213 }
214
215 UIConfiguration*
216 UIConfiguration::post_gui_init ()
217 {
218         load_color_theme (true);
219         return this;
220 }
221
222 int
223 UIConfiguration::load_defaults ()
224 {
225         std::string rcfile;
226         int ret = -1;
227
228         if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile) ) {
229                 XMLTree tree;
230
231                 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg;
232
233                 if (!tree.read (rcfile.c_str())) {
234                         error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
235                 } else {
236                         if (set_state (*tree.root(), Stateful::loading_state_version)) {
237                                 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
238                         } else {
239                                 _dirty = false;
240                                 ret = 0;
241                         }
242                 }
243
244         } else {
245                 warning << string_compose (_("Could not find default UI configuration file %1"), default_ui_config_file_name) << endmsg;
246         }
247
248         if (ret == 0) {
249                 /* reload color theme */
250                 load_color_theme (false);
251         }
252
253         return ret;
254 }
255
256 std::string
257 UIConfiguration::color_file_name (bool use_my, bool with_version) const
258 {
259         string basename;
260
261         if (use_my) {
262                 basename += "my-";
263         }
264
265         std::string color_name = color_file.get();
266         size_t sep = color_name.find_first_of("-");
267         if (sep != string::npos) {
268                 color_name = color_name.substr (0, sep);
269         }
270
271         basename += color_name;
272         basename += "-";
273         basename += downcase(std::string(PROGRAM_NAME));
274
275         std::string rev (revision);
276         std::size_t pos = rev.find_first_of("-");
277
278         if (with_version && pos != string::npos && pos > 0) {
279                 basename += "-";
280                 basename += rev.substr (0, pos); // COLORFILE_VERSION - program major.minor
281         }
282
283         basename += color_file_suffix;
284         return basename;
285 }
286
287 int
288 UIConfiguration::load_color_file (string const & path)
289 {
290         XMLTree tree;
291
292         info << string_compose (_("Loading color file %1"), path) << endmsg;
293
294         if (!tree.read (path.c_str())) {
295                 error << string_compose(_("cannot read color file \"%1\""), path) << endmsg;
296                 return -1;
297         }
298
299         if (set_state (*tree.root(), Stateful::loading_state_version)) {
300                 error << string_compose(_("color file \"%1\" not loaded successfully."), path) << endmsg;
301                 return -1;
302         }
303
304         return 0;
305 }
306
307 int
308 UIConfiguration::load_color_theme (bool allow_own)
309 {
310         std::string cfile;
311         bool found = false;
312         /* ColorsChanged() will trigger a  parameter_changed () which
313          * in turn calls save_state()
314          */
315         PBD::Unwinder<uint32_t> uw (block_save, block_save + 1);
316
317         if (find_file (theme_search_path(), color_file_name (false, true), cfile)) {
318                 found = true;
319         }
320
321         if (!found) {
322                 if (find_file (theme_search_path(), color_file_name (false, false), cfile)) {
323                         found = true;
324                 }
325         }
326
327         if (!found) {
328                 warning << string_compose (_("Color file for %1 not found along %2"), color_file.get(), theme_search_path().to_string()) << endmsg;
329                 return -1;
330         }
331
332         (void) load_color_file (cfile);
333
334         if (allow_own) {
335
336                 found = false;
337
338                 PBD::Searchpath sp (user_config_directory());
339
340                 /* user's own color files never have the program name in them */
341
342                 if (find_file (sp, color_file_name (true, true), cfile)) {
343                         found = true;
344                 }
345
346                 if (!found) {
347                         if (find_file (sp, color_file_name (true, false), cfile)) {
348                                 found = true;
349                         }
350                 }
351
352                 if (found) {
353                         (void) load_color_file (cfile);
354                 }
355
356         }
357
358         ColorsChanged ();
359
360         return 0;
361 }
362
363 int
364 UIConfiguration::store_color_theme ()
365 {
366         XMLNode* root;
367
368         root = new XMLNode("Ardour");
369
370         XMLNode* parent = new XMLNode (X_("Colors"));
371         for (Colors::const_iterator i = colors.begin(); i != colors.end(); ++i) {
372                 XMLNode* node = new XMLNode (X_("Color"));
373                 node->set_property (X_("name"), i->first);
374                 node->set_property (X_("value"), color_to_hex_string (i->second));
375                 parent->add_child_nocopy (*node);
376         }
377         root->add_child_nocopy (*parent);
378
379         parent = new XMLNode (X_("ColorAliases"));
380         for (ColorAliases::const_iterator i = color_aliases.begin(); i != color_aliases.end(); ++i) {
381                 XMLNode* node = new XMLNode (X_("ColorAlias"));
382                 node->set_property (X_("name"), i->first);
383                 node->set_property (X_("alias"), i->second);
384                 parent->add_child_nocopy (*node);
385         }
386         root->add_child_nocopy (*parent);
387
388         parent = new XMLNode (X_("Modifiers"));
389         for (Modifiers::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i) {
390                 XMLNode* node = new XMLNode (X_("Modifier"));
391                 node->set_property (X_("name"), i->first);
392                 node->set_property (X_("modifier"), i->second.to_string());
393                 parent->add_child_nocopy (*node);
394         }
395         root->add_child_nocopy (*parent);
396
397         XMLTree tree;
398         std::string colorfile = Glib::build_filename (user_config_directory(), color_file_name (true, true));;
399
400         tree.set_root (root);
401
402         if (!tree.write (colorfile.c_str())){
403                 error << string_compose (_("Color file %1 not saved"), colorfile) << endmsg;
404                 return -1;
405         }
406
407         return 0;
408 }
409
410 int
411 UIConfiguration::load_state ()
412 {
413         bool found = false;
414
415         std::string rcfile;
416
417         if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile)) {
418                 XMLTree tree;
419                 found = true;
420
421                 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg;
422
423                 if (!tree.read (rcfile.c_str())) {
424                         error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
425                         return -1;
426                 }
427
428                 if (set_state (*tree.root(), Stateful::loading_state_version)) {
429                         error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
430                         return -1;
431                 }
432         }
433
434         if (find_file (ardour_config_search_path(), ui_config_file_name, rcfile)) {
435                 XMLTree tree;
436                 found = true;
437
438                 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
439
440                 if (!tree.read (rcfile)) {
441                         error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
442                         return -1;
443                 }
444
445                 if (set_state (*tree.root(), Stateful::loading_state_version)) {
446                         error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
447                         return -1;
448                 }
449
450                 _dirty = false;
451         }
452
453         if (!found) {
454                 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
455         }
456
457         return 0;
458 }
459
460 int
461 UIConfiguration::save_state()
462 {
463         if (block_save != 0) {
464                 return -1;
465         }
466
467         if (_dirty) {
468                 std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name);
469
470                 XMLTree tree;
471
472                 tree.set_root (&get_state());
473
474                 if (!tree.write (rcfile.c_str())){
475                         error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
476                         return -1;
477                 }
478
479                 _dirty = false;
480         }
481
482         if (aliases_modified || colors_modified || modifiers_modified) {
483
484                 if (store_color_theme ()) {
485                         error << string_compose (_("Color file %1 not saved"), color_file.get()) << endmsg;
486                         return -1;
487                 }
488
489                 aliases_modified = false;
490                 colors_modified = false;
491                 modifiers_modified = false;
492         }
493
494
495         return 0;
496 }
497
498 XMLNode&
499 UIConfiguration::get_state ()
500 {
501         XMLNode* root;
502
503         root = new XMLNode("Ardour");
504
505         root->add_child_nocopy (get_variables ("UI"));
506         root->add_child_nocopy (get_variables ("Canvas"));
507
508         if (_extra_xml) {
509                 root->add_child_copy (*_extra_xml);
510         }
511
512         return *root;
513 }
514
515 XMLNode&
516 UIConfiguration::get_variables (std::string which_node)
517 {
518         XMLNode* node;
519
520         node = new XMLNode (which_node);
521
522 #undef  UI_CONFIG_VARIABLE
523 #undef  CANVAS_FONT_VARIABLE
524 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
525 #define CANVAS_FONT_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
526 #include "ui_config_vars.h"
527 #include "canvas_vars.h"
528 #undef  UI_CONFIG_VARIABLE
529 #undef  CANVAS_FONT_VARIABLE
530
531         return *node;
532 }
533
534 int
535 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
536 {
537         /* this can load a generic UI configuration file or a colors file */
538
539         if (root.name() != "Ardour") {
540                 return -1;
541         }
542
543         Stateful::save_extra_xml (root);
544
545         XMLNodeList nlist = root.children();
546         XMLNodeConstIterator niter;
547         XMLNode *node;
548
549         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
550
551                 node = *niter;
552
553                 if (node->name() == "Canvas" ||  node->name() == "UI") {
554                         set_variables (*node);
555
556                 }
557         }
558
559         XMLNode* colors = find_named_node (root, X_("Colors"));
560
561         if (colors) {
562                 load_colors (*colors);
563         }
564
565         XMLNode* aliases = find_named_node (root, X_("ColorAliases"));
566
567         if (aliases) {
568                 load_color_aliases (*aliases);
569         }
570
571         XMLNode* modifiers = find_named_node (root, X_("Modifiers"));
572
573         if (modifiers) {
574                 load_modifiers (*modifiers);
575         }
576
577         return 0;
578 }
579
580 void
581 UIConfiguration::load_color_aliases (XMLNode const & node)
582 {
583         XMLNodeList const nlist = node.children();
584         XMLNodeConstIterator niter;
585         XMLProperty const *name;
586         XMLProperty const *alias;
587
588         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
589                 XMLNode const * child = *niter;
590                 if (child->name() != X_("ColorAlias")) {
591                         continue;
592                 }
593                 name = child->property (X_("name"));
594                 alias = child->property (X_("alias"));
595
596                 if (name && alias) {
597                         color_aliases[name->value()] = alias->value();
598                 }
599         }
600 }
601
602 void
603 UIConfiguration::load_colors (XMLNode const & node)
604 {
605         XMLNodeList const nlist = node.children();
606         XMLNodeConstIterator niter;
607         XMLProperty const *name;
608         XMLProperty const *color;
609
610         /* don't clear colors, so that we can load > 1 color file and have
611            the subsequent ones overwrite the later ones.
612         */
613
614         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
615                 XMLNode const * child = *niter;
616                 if (child->name() != X_("Color")) {
617                         continue;
618                 }
619                 name = child->property (X_("name"));
620                 color = child->property (X_("value"));
621
622                 if (name && color) {
623                         Gtkmm2ext::Color c;
624                         c = strtoul (color->value().c_str(), 0, 16);
625                         /* insert or replace color name definition */
626                         colors[name->value()] =  c;
627                 }
628         }
629 }
630
631 void
632 UIConfiguration::load_modifiers (XMLNode const & node)
633 {
634         XMLNodeList const nlist = node.children();
635         XMLNodeConstIterator niter;
636         XMLProperty const *name;
637         XMLProperty const *mod;
638
639         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
640                 XMLNode const * child = *niter;
641                 if (child->name() != X_("Modifier")) {
642                         continue;
643                 }
644
645                 name = child->property (X_("name"));
646                 mod = child->property (X_("modifier"));
647
648                 if (name && mod) {
649                         SVAModifier svam (mod->value());
650                         modifiers[name->value()] = svam;
651                 }
652         }
653 }
654
655 void
656 UIConfiguration::set_variables (const XMLNode& node)
657 {
658 #undef  UI_CONFIG_VARIABLE
659 #define UI_CONFIG_VARIABLE(Type,var,name,val) if (var.set_from_node (node)) { ParameterChanged (name); }
660 #define CANVAS_FONT_VARIABLE(var,name)        if (var.set_from_node (node)) { ParameterChanged (name); }
661 #include "ui_config_vars.h"
662 #include "canvas_vars.h"
663 #undef  UI_CONFIG_VARIABLE
664 #undef  CANVAS_FONT_VARIABLE
665 }
666
667 Gtkmm2ext::SVAModifier
668 UIConfiguration::modifier (string const & name) const
669 {
670         Modifiers::const_iterator m = modifiers.find (name);
671         if (m != modifiers.end()) {
672                 return m->second;
673         }
674         return SVAModifier ();
675 }
676
677 Gtkmm2ext::Color
678 UIConfiguration::color_mod (std::string const & colorname, std::string const & modifiername) const
679 {
680         return HSV (color (colorname)).mod (modifier (modifiername)).color ();
681 }
682
683 Gtkmm2ext::Color
684 UIConfiguration::color_mod (const Gtkmm2ext::Color& color, std::string const & modifiername) const
685 {
686         return HSV (color).mod (modifier (modifiername)).color ();
687 }
688
689 Gtkmm2ext::Color
690 UIConfiguration::color (const std::string& name, bool* failed) const
691 {
692         ColorAliases::const_iterator e = color_aliases.find (name);
693
694         if (failed) {
695                 *failed = false;
696         }
697
698         if (e != color_aliases.end ()) {
699                 Colors::const_iterator rc = colors.find (e->second);
700                 if (rc != colors.end()) {
701                         return rc->second;
702                 }
703         } else {
704                 /* not an alias, try directly */
705                 Colors::const_iterator rc = colors.find (name);
706                 if (rc != colors.end()) {
707                         return rc->second;
708                 }
709         }
710
711         if (!failed) {
712                 /* only show this message if the caller wasn't interested in
713                    the fail status.
714                 */
715                 cerr << string_compose (_("Color %1 not found"), name) << endl;
716         }
717
718         if (failed) {
719                 *failed = true;
720         }
721
722         return rgba_to_color ((g_random_int()%256)/255.0,
723                               (g_random_int()%256)/255.0,
724                               (g_random_int()%256)/255.0,
725                               0xff);
726 }
727
728 Color
729 UIConfiguration::quantized (Color c) const
730 {
731         HSV hsv (c);
732         hsv.h = hue_width * (round (hsv.h/hue_width));
733         return hsv.color ();
734 }
735
736 void
737 UIConfiguration::set_color (string const& name, Gtkmm2ext::Color color)
738 {
739         Colors::iterator i = colors.find (name);
740         if (i == colors.end()) {
741                 return;
742         }
743         i->second = color;
744         colors_modified = true;
745
746         ColorsChanged (); /* EMIT SIGNAL */
747 }
748
749 void
750 UIConfiguration::set_alias (string const & name, string const & alias)
751 {
752         ColorAliases::iterator i = color_aliases.find (name);
753         if (i == color_aliases.end()) {
754                 return;
755         }
756
757         i->second = alias;
758         aliases_modified = true;
759
760         ColorsChanged (); /* EMIT SIGNAL */
761 }
762
763 void
764 UIConfiguration::set_modifier (string const & name, SVAModifier svam)
765 {
766         Modifiers::iterator m = modifiers.find (name);
767
768         if (m == modifiers.end()) {
769                 return;
770         }
771
772         m->second = svam;
773         modifiers_modified = true;
774
775         ColorsChanged (); /* EMIT SIGNAL */
776 }
777
778 void
779 UIConfiguration::load_rc_file (bool themechange, bool allow_own)
780 {
781         string basename = ui_rc_file.get();
782         std::string rc_file_path;
783
784         if (!find_file (ardour_config_search_path(), basename, rc_file_path)) {
785                 warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"),
786                                            basename, ardour_config_search_path().to_string(), PROGRAM_NAME)
787                                 << endmsg;
788                 return;
789         }
790
791         info << string_compose (_("Loading ui configuration file %1"), rc_file_path) << endmsg;
792
793         Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path, themechange);
794 }
795
796 std::string
797 UIConfiguration::color_to_hex_string (Gtkmm2ext::Color c)
798 {
799         char buf[16];
800         int retval = g_snprintf (buf, sizeof(buf), "%08x", c);
801
802         if (retval < 0 || retval >= (int)sizeof(buf)) {
803                 assert(false);
804         }
805         return buf;
806 }
807
808 std::string
809 UIConfiguration::color_to_hex_string_no_alpha (Gtkmm2ext::Color c)
810 {
811         c >>= 8; // shift/remove alpha
812         char buf[16];
813         int retval = g_snprintf (buf, sizeof(buf), "%06x", c);
814
815         if (retval < 0 || retval >= (int)sizeof(buf)) {
816                 assert(false);
817         }
818         return buf;
819 }