Move util functions into UIConfiguration as they depend on it anyway
[ardour.git] / gtk2_ardour / ui_config.h
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 #ifndef __ardour_ui_configuration_h__
21 #define __ardour_ui_configuration_h__
22
23 #include <sstream>
24 #include <ostream>
25 #include <iostream>
26
27 #include <boost/function.hpp>
28 #include <boost/bind.hpp>
29
30 #include "pbd/stateful.h"
31 #include "pbd/xml++.h"
32 #include "pbd/configuration_variable.h"
33
34 #include "canvas/colors.h"
35
36 #include "utils.h"
37
38 class UIConfiguration : public PBD::Stateful
39 {
40     public:
41         UIConfiguration();
42         ~UIConfiguration();
43
44         static UIConfiguration* instance() { return _instance; }
45
46         void load_rc_file (bool themechange, bool allow_own = true);
47
48         int load_state ();
49         int save_state ();
50         int load_defaults ();
51         int load_color_theme (bool allow_own=true);
52
53         int set_state (const XMLNode&, int version);
54         XMLNode& get_state (void);
55         XMLNode& get_variables (std::string);
56         void set_variables (const XMLNode&);
57
58         typedef std::map<std::string,ArdourCanvas::Color> Colors;
59         typedef std::map<std::string,std::string> ColorAliases;
60         typedef std::map<std::string,ArdourCanvas::SVAModifier> Modifiers;
61
62         Colors         colors;
63         ColorAliases   color_aliases;
64         Modifiers      modifiers;
65
66         void set_alias (std::string const & name, std::string const & alias);
67         void set_color (const std::string& name, ArdourCanvas::Color);
68         void set_modifier (std::string const &, ArdourCanvas::SVAModifier svam);
69         
70         std::string color_as_alias (ArdourCanvas::Color c);
71         ArdourCanvas::Color quantized (ArdourCanvas::Color) const;
72
73         ArdourCanvas::Color color (const std::string&, bool* failed = 0) const;
74         ArdourCanvas::Color color_mod (std::string const & color, std::string const & modifier) const;
75         ArdourCanvas::Color color_mod (const ArdourCanvas::Color& color, std::string const & modifier) const;
76         ArdourCanvas::HSV  color_hsv (const std::string&) const;
77         ArdourCanvas::SVAModifier modifier (const std::string&) const;
78
79         void reset_dpi ();
80         void set_pango_fontsize ();
81                 
82         sigc::signal<void,std::string> ParameterChanged;
83         void map_parameters (boost::function<void (std::string)>&);
84
85         void parameter_changed (std::string);
86
87         /** called before initializing any part of the GUI. Sets up
88          *  any runtime environment required to make the GUI work
89          *  in specific ways.
90          */
91         int pre_gui_init ();
92
93         /** called after the GUI toolkit has been initialized. 
94          */
95         UIConfiguration* post_gui_init ();
96         
97 #undef UI_CONFIG_VARIABLE
98 #define UI_CONFIG_VARIABLE(Type,var,name,value) \
99         Type get_##var () const { return var.get(); } \
100         bool set_##var (Type val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
101 #include "ui_config_vars.h"
102 #undef  UI_CONFIG_VARIABLE
103 #define CANVAS_FONT_VARIABLE(var,name) \
104         Pango::FontDescription get_##var () const { return ARDOUR_UI_UTILS::sanitized_font (var.get()); } \
105         bool set_##var (const std::string& val) { bool ret = var.set (val); if (ret) { ParameterChanged (name); } return ret;  }
106 #include "canvas_vars.h"
107 #undef CANVAS_FONT_VARIABLE
108
109   private:
110         /* declare variables */
111
112 #undef  UI_CONFIG_VARIABLE
113 #define UI_CONFIG_VARIABLE(Type,var,name,value) PBD::ConfigVariable<Type> var;
114 #include "ui_config_vars.h"
115 #undef UI_CONFIG_VARIABLE
116
117 #define CANVAS_FONT_VARIABLE(var,name) PBD::ConfigVariable<std::string> var;
118 #include "canvas_vars.h"
119 #undef CANVAS_FONT_VARIABLE
120
121         XMLNode& state ();
122         bool _dirty;
123         bool aliases_modified;
124         bool colors_modified;
125         bool modifiers_modified;
126         
127         static UIConfiguration* _instance;
128
129         int store_color_theme ();
130         void load_color_aliases (XMLNode const &);
131         void load_colors (XMLNode const &);
132         void load_modifiers (XMLNode const &);
133         void reset_gtk_theme ();
134         void colors_changed ();
135
136         uint32_t block_save;
137 };
138
139 #endif /* __ardour_ui_configuration_h__ */
140