]> git.lyx.org Git - lyx.git/blob - src/Color.h
latex_lang should not have a babel language
[lyx.git] / src / Color.h
1 // -*- C++ -*-
2 /**
3  * \file Color.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author Matthias Ettrich
10  * \author Jean-Marc Lasgouttes
11  * \author Angus Leeming
12  * \author John Levon
13  * \author André Pönitz
14  * \author Martin Vermeer
15  *
16  * Full author contact details are available in file CREDITS.
17  */
18
19 #ifndef LCOLOR_H
20 #define LCOLOR_H
21
22 #include "support/docstring.h"
23
24 #include <boost/scoped_ptr.hpp>
25
26
27 namespace lyx {
28
29 /**
30  * This is a stateless class.
31  *
32  * It has one basic purposes:
33  * To serve as a color-namespace container (the Color enum).
34  */
35 /**
36  * \class Color
37  *
38  * A class holding color definitions and associated names for
39  * LaTeX, X11, the GUI, and LyX internally.
40  *
41  * A color can be one of the following kinds:
42  *
43  * - A real, predefined color, such as black, white, red or green.
44  * - A logical color, such as no color, inherit, math
45  */
46
47 class Color
48 // made copyable for same reasons as LyXRC was made copyable. See there for
49 // explanation.
50 {
51 public:
52         /// Names of colors, including all logical colors
53         enum color {
54                 /// No particular color---clear or default
55                 none,
56                 /// The different text colors
57                 black,
58                 ///
59                 white,
60                 ///
61                 red,
62                 ///
63                 green,
64                 ///
65                 blue,
66                 ///
67                 cyan,
68                 ///
69                 magenta,
70                 ///
71                 yellow,
72
73                 // Needed interface colors
74
75                 /// Cursor color
76                 cursor,
77                 /// Background color
78                 background,
79                 /// Foreground color
80                 foreground,
81                 /// Background color of selected text
82                 selection,
83                 /// Text color in LaTeX mode
84                 latex,
85                 /// The color used for previews
86                 preview,
87
88                 /// Text color for notes
89                 note,
90                 /// Background color of notes
91                 notebg,
92                 /// Text color for comments
93                 comment,
94                 /// Background color of comments
95                 commentbg,
96                 /// Text color for greyedout inset
97                 greyedout,
98                 /// Background color of greyedout inset
99                 greyedoutbg,
100                 /// Shaded box background
101                 shadedbg,
102
103                 /// Color for the depth bars in the margin
104                 depthbar,
105                 /// Color for marking foreign language words
106                 language,
107
108                 /// Text color for command insets
109                 command,
110                 /// Background color for command insets
111                 commandbg,
112                 /// Frame color for command insets
113                 commandframe,
114
115                 /// Special chars text color
116                 special,
117
118                 /// Graphics inset background color
119                 graphicsbg,
120                 /// Math inset text color
121                 math,
122                 /// Math inset background color
123                 mathbg,
124                 /// Macro math inset background color
125                 mathmacrobg,
126                 /// Math inset frame color under focus
127                 mathframe,
128                 /// Math inset frame color not under focus
129                 mathcorners,
130                 /// Math line color
131                 mathline,
132
133                 /// caption frame color
134                 captionframe,
135
136                 /// collapsable insets text
137                 collapsable,
138                 /// collapsable insets frame
139                 collapsableframe,
140
141                 /// Inset marker background color
142                 insetbg,
143                 /// Inset marker frame color
144                 insetframe,
145
146                 /// Error box text color
147                 error,
148                 /// EOL marker color
149                 eolmarker,
150                 /// Added space colour
151                 added_space,
152                 /// Appendix marker color
153                 appendix,
154                 /// changebar color
155                 changebar,
156                 /// deleted text color
157                 deletedtext,
158                 /// added text color
159                 addedtext,
160                 /// Top and bottom line color
161                 topline,
162                 /// Table line color
163                 tabularline,
164                 /// Table line color
165                 tabularonoffline,
166                 /// Bottom area color
167                 bottomarea,
168                 /// Page break color
169                 pagebreak,
170
171                 // FIXME: why are the next four separate ??
172                 /// Color used for button frame
173                 buttonframe,
174                 /// Color used for bottom background
175                 buttonbg,
176                 /// Color used for buttom under focus
177                 buttonhoverbg,
178
179                 // Logical attributes
180
181                 /// Color is inherited
182                 inherit,
183                 /// For ignoring updates of a color
184                 ignore
185         };
186
187
188         ///
189         Color();
190         ///
191         Color(Color const &);
192         ///
193         ~Color();
194         ///
195         Color & operator=(Color);
196
197         /** set the given LyX color to the color defined by the X11 name given
198          *  \returns true if successful.
199          */
200         bool setColor(Color::color col, std::string const & x11name);
201
202         /** set the given LyX color to the color defined by the X11
203          *  name given \returns true if successful. A new color entry
204          *  is created if the color is unknown
205          */
206         bool setColor(std::string const & lyxname, std::string const & x11name);
207
208         /// Get the GUI name of \c color.
209         docstring const getGUIName(Color::color c) const;
210
211         /// Get the X11 name of \c color.
212         std::string const getX11Name(Color::color c) const;
213
214         /// Get the LaTeX name of \c color.
215         std::string const getLaTeXName(Color::color c) const;
216
217         /// Get the LyX name of \c color.
218         std::string const getLyXName(Color::color c) const;
219
220         /// \returns the Color::color associated with the LyX name.
221         Color::color getFromLyXName(std::string const & lyxname) const;
222         /// \returns the Color::color associated with the LaTeX name.
223         Color::color getFromLaTeXName(std::string const & latexname) const;
224 private:
225         ///
226         void addColor(Color::color c, std::string const & lyxname) const;
227         ///
228         class Pimpl;
229         ///
230         boost::scoped_ptr<Pimpl> pimpl_;
231 };
232
233
234 /** \c Color_color is a wrapper for Color::color. It can be forward-declared and
235  *  passed as a function argument without having to expose Color.h.
236  */
237 class Color_color {
238         Color::color val_;
239 public:
240         /** The default constructor is nasty,
241          *  but allows us to use Color_color in STL containers.
242          */
243         Color_color() : val_(static_cast<Color::color>(-1)) {}
244
245         Color_color(Color::color val) : val_(val) {}
246         operator Color::color() const{ return val_; }
247 };
248
249
250 /// the current color definitions
251 extern Color lcolor;
252 /// the system color definitions
253 extern Color system_lcolor;
254
255
256 struct RGBColor;
257 /// returns a string of form #rrggbb, given an RGBColor struct
258 std::string const X11hexname(RGBColor const & col);
259
260 struct HSVColor {
261         double h;
262         double s;
263         double v;
264         HSVColor() : h(0.0), s(0.0), v(0.0) {}
265         HSVColor(double hue, double sat, double val)
266                 : h(hue), s(sat), v(val) {}
267         HSVColor(RGBColor const &);
268 };
269
270 struct RGBColor {
271         unsigned int r;
272         unsigned int g;
273         unsigned int b;
274         RGBColor() : r(0), g(0), b(0) {}
275         RGBColor(unsigned int red, unsigned int green, unsigned int blue)
276                 : r(red), g(green), b(blue) {}
277         RGBColor(HSVColor const &);
278         /// \param x11hexname is of the form "#ffa071"
279         RGBColor(std::string const & x11hexname);
280 };
281
282 struct NamedColor : public RGBColor {
283         std::string lyxname;
284         std::string guiname;
285         NamedColor() : RGBColor() {}
286         NamedColor(std::string const & lyx, std::string const & gui,
287                    RGBColor const & c)
288                 : RGBColor(c), lyxname(lyx), guiname(gui) {}
289         RGBColor const & color() const { return *this; }
290 };
291
292 inline
293 bool operator==(RGBColor const & c1, RGBColor const & c2)
294 {
295         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
296 }
297
298
299 inline
300 bool operator!=(RGBColor const & c1, RGBColor const & c2)
301 {
302         return !(c1 == c2);
303 }
304
305 } // namespace lyx
306
307 #endif