]> git.lyx.org Git - lyx.git/blob - src/Color.h
* gcc does not like missing characters in keywords
[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 <boost/scoped_ptr.hpp>
27
28
29 namespace lyx {
30
31 /**
32  * This is a stateless class.
33  *
34  * It has one basic purposes:
35  * To serve as a color-namespace container (the Color enum).
36  */
37 /**
38  * \class Color
39  *
40  * A class holding color definitions and associated names for
41  * LaTeX, X11, the GUI, and LyX internally.
42  *
43  * A color can be one of the following kinds:
44  *
45  * - A real, predefined color, such as black, white, red or green.
46  * - A logical color, such as no color, inherit, math
47  */
48
49 class Color
50 // made copyable for same reasons as LyXRC was made copyable. See there for
51 // explanation.
52 {
53 public:
54         ///
55         Color();
56         ///
57         Color(Color const &);
58         ///
59         ~Color();
60         ///
61         Color & operator=(Color);
62
63         /** set the given LyX color to the color defined by the X11 name given
64          *  \returns true if successful.
65          */
66         bool setColor(ColorCode col, std::string const & x11name);
67
68         /** set the given LyX color to the color defined by the X11
69          *  name given \returns true if successful. A new color entry
70          *  is created if the color is unknown
71          */
72         bool setColor(std::string const & lyxname, std::string const & x11name);
73
74         /// Get the GUI name of \c color.
75         docstring const getGUIName(ColorCode c) const;
76
77         /// Get the X11 name of \c color.
78         std::string const getX11Name(ColorCode c) const;
79
80         /// Get the LaTeX name of \c color.
81         std::string const getLaTeXName(ColorCode c) const;
82
83         /// Get the LyX name of \c color.
84         std::string const getLyXName(ColorCode c) const;
85
86         /// \returns the ColorCode associated with the LyX name.
87         ColorCode getFromLyXName(std::string const & lyxname) const;
88         /// \returns the ColorCode associated with the LaTeX name.
89         ColorCode getFromLaTeXName(std::string const & latexname) const;
90 private:
91         ///
92         void addColor(ColorCode c, std::string const & lyxname) const;
93         ///
94         class Pimpl;
95         ///
96         boost::scoped_ptr<Pimpl> pimpl_;
97 };
98
99
100 /// the current color definitions
101 extern Color lcolor;
102 /// the system color definitions
103 extern Color system_lcolor;
104
105
106 struct RGBColor {
107         unsigned int r;
108         unsigned int g;
109         unsigned int b;
110         RGBColor() : r(0), g(0), b(0) {}
111         RGBColor(unsigned int red, unsigned int green, unsigned int blue)
112                 : r(red), g(green), b(blue) {}
113         /// \param x11hexname is of the form "#ffa071"
114         RGBColor(std::string const & x11hexname);
115 };
116
117 inline
118 bool operator==(RGBColor const & c1, RGBColor const & c2)
119 {
120         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
121 }
122
123
124 inline
125 bool operator!=(RGBColor const & c1, RGBColor const & c2)
126 {
127         return !(c1 == c2);
128 }
129
130 /// returns a string of form #rrggbb, given an RGBColor struct
131 std::string const X11hexname(RGBColor const & col);
132
133 } // namespace lyx
134
135 #endif