]> git.lyx.org Git - lyx.git/blob - src/Color.h
0f0a0934a356c633f0c754b4e3a4f1ca3ad07ebe
[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 "ColorCode.h"
23
24 #include "support/strfwd.h"
25
26 #include <map>
27 #include <string>
28
29 namespace lyx {
30
31 /**
32  * \class ColorSet
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
44 // made copyable for same reasons as LyXRC was made copyable. See there for
45 // explanation.
46
47 class ColorSet
48 {
49 public:
50         ///
51         ColorSet();
52
53         /** set the given LyX color to the color defined by the X11 name given
54          *  \returns true if successful.
55          */
56         bool setColor(ColorCode col, std::string const & x11name);
57
58         /** set the given LyX color to the color defined by the X11
59          *  name given \returns true if successful. A new color entry
60          *  is created if the color is unknown
61          */
62         bool setColor(std::string const & lyxname, std::string const & x11name);
63
64         /// Get the GUI name of \c color.
65         docstring const getGUIName(ColorCode c) const;
66
67         /// Get the X11 name of \c color.
68         std::string const getX11Name(ColorCode c) const;
69
70         /// Get the LaTeX name of \c color.
71         std::string const getLaTeXName(ColorCode c) const;
72
73         /// Get the LyX name of \c color.
74         std::string const getLyXName(ColorCode c) const;
75
76         /// \returns the ColorCode associated with the LyX name.
77         ColorCode getFromLyXName(std::string const & lyxname) const;
78         /// \returns the ColorCode associated with the LaTeX name.
79         ColorCode getFromLaTeXName(std::string const & latexname) const;
80
81 private:
82         ///
83         void addColor(ColorCode c, std::string const & lyxname); 
84         ///
85         class Information {
86         public:
87                 /// the name as it appears in the GUI
88                 std::string guiname;
89                 /// the name used in LaTeX
90                 std::string latexname;
91                 /// the name for X11
92                 std::string x11name;
93                 /// the name for LyX
94                 std::string lyxname;
95         };
96
97         /// initialise a color entry
98         struct ColorEntry;
99         void fill(ColorEntry const & entry);
100
101         ///
102         typedef std::map<ColorCode, Information> InfoTab;
103         /// the table of color Information
104         InfoTab infotab;
105
106         typedef std::map<std::string, ColorCode> Transform;
107         /// the transform between LyX color name string and integer code.
108         Transform lyxcolors;
109         /// the transform between LaTeX color name string and integer code.
110         Transform latexcolors;
111 };
112
113
114 /// the current color definitions
115 extern ColorSet lcolor;
116 /// the system color definitions
117 extern ColorSet system_lcolor;
118
119 std::string const X11hexname(RGBColor const & col);
120 RGBColor rgbFromHexName(std::string const & x11hexname);
121
122 } // namespace lyx
123
124 #endif