]> git.lyx.org Git - lyx.git/blob - src/LColor.h
A better fix for bug 675:
[lyx.git] / src / LColor.h
1 // -*- C++ -*-
2 /**
3  * \file LColor.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 LColor
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 LColor
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
127                 mathframe,
128                 /// Math line color
129                 mathline,
130
131                 /// caption frame color
132                 captionframe,
133
134                 /// collapsable insets text
135                 collapsable,
136                 /// collapsable insets frame
137                 collapsableframe,
138
139                 /// Inset marker background color
140                 insetbg,
141                 /// Inset marker frame color
142                 insetframe,
143
144                 /// Error box text color
145                 error,
146                 /// EOL marker color
147                 eolmarker,
148                 /// Added space colour
149                 added_space,
150                 /// Appendix marker color
151                 appendix,
152                 /// changebar color
153                 changebar,
154                 /// strike-out color
155                 strikeout,
156                 /// added text color
157                 newtext,
158                 /// Top and bottom line color
159                 topline,
160                 /// Table line color
161                 tabularline,
162                 /// Table line color
163                 tabularonoffline,
164                 /// Bottom area color
165                 bottomarea,
166                 /// Page break color
167                 pagebreak,
168
169                 // FIXME: why are the next four separate ??
170                 /// Color used for button frame
171                 buttonframe,
172                 /// Color used for bottom background
173                 buttonbg,
174                 /// Color used for buttom under focus
175                 buttonhoverbg,
176
177                 // Logical attributes
178
179                 /// Color is inherited
180                 inherit,
181                 /// For ignoring updates of a color
182                 ignore
183         };
184
185
186         ///
187         LColor();
188         ///
189         LColor(LColor const &);
190         ///
191         ~LColor();
192         ///
193         LColor & operator=(LColor);
194
195         /** set the given LyX color to the color defined by the X11 name given
196          *  \returns true if successful.
197          */
198         bool setColor(LColor::color col, std::string const & x11name);
199
200         /** set the given LyX color to the color defined by the X11
201          *  name given \returns true if successful. A new color entry
202          *  is created if the color is unknown
203          */
204         bool setColor(std::string const & lyxname, std::string const & x11name);
205
206         /// Get the GUI name of \c color.
207         docstring const getGUIName(LColor::color c) const;
208
209         /// Get the X11 name of \c color.
210         std::string const getX11Name(LColor::color c) const;
211
212         /// Get the LaTeX name of \c color.
213         std::string const getLaTeXName(LColor::color c) const;
214
215         /// Get the LyX name of \c color.
216         std::string const getLyXName(LColor::color c) const;
217
218         /// \returns the LColor::color associated with the LyX name.
219         LColor::color getFromLyXName(std::string const & lyxname) const;
220         /// \returns the LColor::color associated with the LaTeX name.
221         LColor::color getFromLaTeXName(std::string const & latexname) const;
222 private:
223         ///
224         void addColor(LColor::color c, std::string const & lyxname) const;
225         ///
226         class Pimpl;
227         ///
228         boost::scoped_ptr<Pimpl> pimpl_;
229 };
230
231
232 /** \c LColor_color is a wrapper for LColor::color. It can be forward-declared and
233  *  passed as a function argument without having to expose LColor.h.
234  */
235 class LColor_color {
236         LColor::color val_;
237 public:
238         /** The default constructor is nasty,
239          *  but allows us to use LColor_color in STL containers.
240          */
241         LColor_color() : val_(static_cast<LColor::color>(-1)) {}
242
243         LColor_color(LColor::color val) : val_(val) {}
244         operator LColor::color() const{ return val_; }
245 };
246
247
248 /// the current color definitions
249 extern LColor lcolor;
250 /// the system color definitions
251 extern LColor system_lcolor;
252
253
254 } // namespace lyx
255
256 #endif