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