]> git.lyx.org Git - features.git/blob - src/Color.h
* InsetMathNest.cpp: Cosmetics.
[features.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 "ColorCode.h"
23
24 #include "support/strfwd.h"
25
26 #include <map>
27 #include <string>
28
29 namespace lyx {
30
31 /**
32  * \class Color
33  *
34  * A class holding a definition of a certain color.
35  *
36  * A color can be one of the following kinds:
37  *
38  * - a single color, then mergeColor = Color_ignore
39  * - a merged color, i.e. the average of the base and merge colors.
40  */
41
42 class Color
43 {
44 public:
45         ///
46         Color(ColorCode base_color = Color_none);
47         
48         /// comparison operators.
49         //@{
50         bool operator==(Color const & color) const;
51         bool operator!=(Color const & color) const;
52         bool operator<(Color const & color) const;
53         bool operator<=(Color const & color) const;
54         //@}
55
56         /// the base color
57         ColorCode baseColor;
58         /// The color that is merged with the base color. Set
59         /// mergeColor to Color_ignore if no merging is wanted.
60         ColorCode mergeColor;
61 };
62
63 std::ostream & operator<<(std::ostream & os, Color color);
64
65
66 /**
67  * \class ColorSet
68  *
69  * A class holding color definitions and associated names for
70  * LaTeX, X11, the GUI, and LyX internally.
71  *
72  * A color can be one of the following kinds:
73  *
74  * - A real, predefined color, such as black, white, red or green.
75  * - A logical color, such as no color, inherit, math
76  */
77
78
79 // made copyable for same reasons as LyXRC was made copyable. See there for
80 // explanation.
81
82 class ColorSet
83 {
84 public:
85         ///
86         ColorSet();
87
88         /** set the given LyX color to the color defined by the X11 name given
89          *  \returns true if successful.
90          */
91         bool setColor(ColorCode col, std::string const & x11name);
92
93         /** set the given LyX color to the color defined by the X11
94          *  name given \returns true if successful. A new color entry
95          *  is created if the color is unknown
96          */
97         bool setColor(std::string const & lyxname, std::string const & x11name);
98
99         /// Get the GUI name of \c color.
100         docstring const getGUIName(ColorCode c) const;
101
102         /// Get the X11 name of \c color.
103         std::string const getX11Name(ColorCode c) const;
104
105         /// Get the LaTeX name of \c color.
106         std::string const getLaTeXName(ColorCode c) const;
107
108         /// Get the LyX name of \c color.
109         std::string const getLyXName(ColorCode c) const;
110
111         /// \returns the ColorCode associated with the LyX name.
112         ColorCode getFromLyXName(std::string const & lyxname) const;
113         /// \returns the ColorCode associated with the LaTeX name.
114         ColorCode getFromLaTeXName(std::string const & latexname) const;
115
116 private:
117         ///
118         void addColor(ColorCode c, std::string const & lyxname); 
119         ///
120         class Information {
121         public:
122                 /// the name as it appears in the GUI
123                 std::string guiname;
124                 /// the name used in LaTeX
125                 std::string latexname;
126                 /// the name for X11
127                 std::string x11name;
128                 /// the name for LyX
129                 std::string lyxname;
130         };
131
132         /// initialise a color entry
133         struct ColorEntry;
134         void fill(ColorEntry const & entry);
135
136         ///
137         typedef std::map<ColorCode, Information> InfoTab;
138         /// the table of color Information
139         InfoTab infotab;
140
141         typedef std::map<std::string, ColorCode> Transform;
142         /// the transform between LyX color name string and integer code.
143         Transform lyxcolors;
144         /// the transform between LaTeX color name string and integer code.
145         Transform latexcolors;
146 };
147
148
149 /// the current color definitions
150 extern ColorSet lcolor;
151 /// the system color definitions
152 extern ColorSet system_lcolor;
153
154 std::string const X11hexname(RGBColor const & col);
155 RGBColor rgbFromHexName(std::string const & x11hexname);
156
157 } // namespace lyx
158
159 #endif