]> git.lyx.org Git - lyx.git/blob - src/ColorSet.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / ColorSet.h
1 // -*- C++ -*-
2 /**
3  * \file ColorSet.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 COLORSET_H
20 #define COLORSET_H
21
22 #include "Color.h"
23
24 #include <map>
25 #include <string>
26
27 namespace lyx {
28
29 /**
30  * \class ColorSet
31  *
32  * A class holding color definitions and associated names for
33  * LaTeX, X11, the GUI, and LyX internally.
34  *
35  * A color can be one of the following kinds:
36  *
37  * - A real, predefined color, such as black, white, red or green.
38  * - A logical color, such as no color, inherit, math
39  */
40
41
42 // made copyable for same reasons as LyXRC was made copyable. See there for
43 // explanation.
44
45 class ColorSet
46 {
47 public:
48         ///
49         ColorSet();
50
51         /** set the given LyX color to the color defined by the X11 hex name given
52          *  \returns true if successful. The optional third argument passes
53          *  a color for dark mode.
54          */
55         bool setColor(ColorCode col, std::string const & x11hexname,
56                       std::string const & x11darkhexname = std::string());
57
58         /** set the given LyX color to the color defined by the X11
59          *  hex name given \returns true if successful. A new color entry
60          *  is created if the color is unknown. The optional third argument passes
61          *  a color for dark mode.
62          */
63         bool setColor(std::string const & lyxname, std::string const & x11hexname,
64                       std::string const & x11darkhexname = std::string());
65
66         /** set the given LyX color to a latexcolor if not yet defined
67          *  \returns true if successful. A new color entry
68          *  is created if the color is unknown.
69          */
70         bool setLaTeXName(std::string const & lyxname, std::string const & latexname);
71
72         /** set the GUI name of a given LyX color to a guiname if not yet defined
73          *  \returns true if successful.
74          */
75         bool setGUIName(std::string const & lyxname, std::string const & guiname);
76
77         /// Get the GUI name of \c color.
78         docstring const getGUIName(ColorCode c) const;
79
80         /// Get the X11 hexname of \c color.
81         std::string const getX11HexName(ColorCode c, bool const darkmode = false) const;
82
83         /// Get the X11 hexname of \c color.
84         std::pair<std::string, std::string> const getAllX11HexNames(ColorCode c) const;
85
86         /// Get the LaTeX name of \c color.
87         std::string const getLaTeXName(ColorCode c) const;
88
89         /// Get the LyX name of \c color.
90         std::string const getLyXName(ColorCode c) const;
91
92         /// \returns the ColorCode associated with the LyX name.
93         ColorCode getFromLyXName(std::string const & lyxname) const;
94         /// \returns the ColorCode associated with the LaTeX name.
95         ColorCode getFromLaTeXName(std::string const & latexname) const;
96
97 private:
98         ///
99         void addColor(ColorCode c, std::string const & lyxname);
100         ///
101         class Information {
102         public:
103                 /// the name as it appears in the GUI
104                 std::string guiname;
105                 /// the name used in LaTeX
106                 std::string latexname;
107                 /// the name for X11
108                 std::string x11hexname;
109                 /// matching X11 color for dark mode
110                 std::string x11darkhexname;
111                 /// the name for LyX
112                 std::string lyxname;
113         };
114
115         /// initialise a color entry
116         struct ColorEntry;
117         void fill(ColorEntry const & entry);
118
119         ///
120         typedef std::map<ColorCode, Information> InfoTab;
121         /// the table of color Information
122         InfoTab infotab;
123
124         typedef std::map<std::string, ColorCode> Transform;
125         /// the transform between LyX color name string and integer code.
126         Transform lyxcolors;
127         /// the transform between LaTeX color name string and integer code.
128         Transform latexcolors;
129 };
130
131
132 /// the current color definitions
133 extern ColorSet lcolor;
134 /// the system color definitions
135 extern ColorSet system_lcolor;
136
137 } // namespace lyx
138
139 #endif // COLORSET_H