]> git.lyx.org Git - lyx.git/blob - src/LColor.h
minimal effort implementation of:
[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 <boost/scoped_ptr.hpp>
23 #include <string>
24
25 /**
26  * This is a stateless class.
27  *
28  * It has one basic purposes:
29  * To serve as a color-namespace container (the Color enum).
30  */
31 /**
32  * \class LColor
33  *
34  * A class holding color definitions and associated names for
35  * LaTeX, X11, the GUI, and LyX internally.
36  *
37  * A color can be one of the following kinds:
38  *
39  * - A real, predefined color, such as black, white, red or green.
40  * - A logical color, such as no color, inherit, math
41  */
42
43 class LColor
44 // made copyable for same reasons as LyXRC was made copyable. See there for
45 // explanation.
46 {
47 public:
48         /// Names of colors, including all logical colors
49         enum color {
50                 /// No particular color---clear or default
51                 none,
52                 /// The different text colors
53                 black,
54                 ///
55                 white,
56                 ///
57                 red,
58                 ///
59                 green,
60                 ///
61                 blue,
62                 ///
63                 cyan,
64                 ///
65                 magenta,
66                 ///
67                 yellow,
68
69                 // Needed interface colors
70
71                 /// Cursor color
72                 cursor,
73                 /// Background color
74                 background,
75                 /// Foreground color
76                 foreground,
77                 /// Background color of selected text
78                 selection,
79                 /// Text color in LaTeX mode
80                 latex,
81                 /// The color used for previews
82                 preview,
83
84                 /// Text color for notes
85                 note,
86                 /// Background color of notes
87                 notebg,
88                 /// Text color for comments
89                 comment,
90                 /// Background color of comments
91                 commentbg,
92                 /// Text color for greyedout inset
93                 greyedout,
94                 /// Background color of greyedout inset
95                 greyedoutbg,
96                 /// Shaded box background
97                 shadedbg,
98
99                 /// Color for the depth bars in the margin
100                 depthbar,
101                 /// Color for marking foreign language words
102                 language,
103
104                 /// Text color for command insets
105                 command,
106                 /// Background color for command insets
107                 commandbg,
108                 /// Frame color for command insets
109                 commandframe,
110
111                 /// Special chars text color
112                 special,
113
114                 /// Graphics inset background color
115                 graphicsbg,
116                 /// Math inset text color
117                 math,
118                 /// Math inset background color
119                 mathbg,
120                 /// Macro math inset background color
121                 mathmacrobg,
122                 /// Math inset frame color
123                 mathframe,
124                 /// Math line color
125                 mathline,
126
127                 /// caption frame color
128                 captionframe,
129
130                 /// collapsable insets text
131                 collapsable,
132                 /// collapsable insets frame
133                 collapsableframe,
134
135                 /// Inset marker background color
136                 insetbg,
137                 /// Inset marker frame color
138                 insetframe,
139
140                 /// Error box text color
141                 error,
142                 /// EOL marker color
143                 eolmarker,
144                 /// Added space colour
145                 added_space,
146                 /// Appendix marker color
147                 appendix,
148                 /// changebar color
149                 changebar,
150                 /// strike-out color
151                 strikeout,
152                 /// added text color
153                 newtext,
154                 /// Top and bottom line color
155                 topline,
156                 /// Table line color
157                 tabularline,
158                 /// Table line color
159                 tabularonoffline,
160                 /// Bottom area color
161                 bottomarea,
162                 /// Page break color
163                 pagebreak,
164
165                 // FIXME: why are the next four separate ??
166                 /// Color used for top of boxes
167                 top,
168                 /// Color used for bottom of boxes
169                 bottom,
170                 /// Color used for left side of boxes
171                 left,
172                 /// Color used for right side of boxes
173                 right,
174                 /// Color used for bottom background
175                 buttonbg,
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         std::string 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 GUI name.
219         LColor::color getFromGUIName(std::string const & guiname) const;
220         /// \returns the LColor::color associated with the LyX name.
221         LColor::color getFromLyXName(std::string const & lyxname) const;
222         /// \returns the LColor::color associated with the LaTeX name.
223         LColor::color getFromLaTeXName(std::string const & latexname) const;
224 private:
225         ///
226         void addColor(LColor::color c, std::string const & lyxname) const;
227         ///
228         class Pimpl;
229         ///
230         boost::scoped_ptr<Pimpl> pimpl_;
231 };
232
233
234 /** \c LColor_color is a wrapper for LColor::color. It can be forward-declared and
235  *  passed as a function argument without having to expose LColor.h.
236  */
237 class LColor_color {
238         LColor::color val_;
239 public:
240         /** The default constructor is nasty,
241          *  but allows us to use LColor_color in STL containers.
242          */
243         LColor_color() : val_(static_cast<LColor::color>(-1)) {}
244
245         LColor_color(LColor::color val) : val_(val) {}
246         operator LColor::color() const{ return val_; }
247 };
248
249
250 /// the current color definitions
251 extern LColor lcolor;
252 /// the system color definitions
253 extern LColor system_lcolor;
254
255 #endif