3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
9 * \author Jean-Marc Lasgouttes
11 * \author André Pönitz
12 * \author Martin Vermeer
14 * Full author contact details are available in file CREDITS.
21 #include "support/debug.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
25 #include <boost/assert.hpp>
33 #ifndef CXX_GLOBAL_CSTD
41 using std::istringstream;
42 using std::ostringstream;
48 using support::ascii_lowercase;
50 struct ColorSet::ColorEntry {
53 char const * latexname;
59 static int hexstrToInt(string const & str)
62 istringstream is(str);
63 is >> std::setbase(16) >> val;
68 /////////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////////
75 string const X11hexname(RGBColor const & col)
79 ostr << '#' << std::setbase(16) << std::setfill('0')
88 RGBColor rgbFromHexName(string const & x11hexname)
91 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
92 c.r = hexstrToInt(x11hexname.substr(1,2));
93 c.g = hexstrToInt(x11hexname.substr(3,2));
94 c.b = hexstrToInt(x11hexname.substr(5,2));
101 // ColorCode, gui, latex, x11, lyx
102 static ColorEntry const items[] = {
103 { Color_none, N_("none"), "none", "black", "none" },
104 { Color_black, N_("black"), "black", "black", "black" },
105 { Color_white, N_("white"), "white", "white", "white" },
106 { Color_red, N_("red"), "red", "red", "red" },
107 { Color_green, N_("green"), "green", "green", "green" },
108 { Color_blue, N_("blue"), "blue", "blue", "blue" },
109 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
110 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
111 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
112 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
113 { Color_background, N_("background"), "background", "linen", "background" },
114 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
115 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
116 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
117 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
118 { Color_note, N_("note"), "note", "blue", "note" },
119 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
120 { Color_comment, N_("comment"), "comment", "magenta", "comment" },
121 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
122 { Color_greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
123 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
124 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
125 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
126 { Color_language, N_("language"), "language", "Blue", "language" },
127 { Color_command, N_("command inset"), "command", "black", "command" },
128 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
129 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
130 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
131 { Color_math, N_("math"), "math", "DarkBlue", "math" },
132 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
133 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
134 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
135 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
136 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
137 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
138 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "#ede2d8", "mathmacrobg" },
139 { Color_mathmacrohoverbg, N_("Math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", "mathmacrohoverbg" },
140 { Color_mathmacrolabel, N_("Math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
141 { Color_mathmacroframe, N_("Math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
142 { Color_mathmacroblend, N_("Math macro blended out"), "mathmacroblend", "#000000", "mathmacroblend" },
143 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
144 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
145 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
146 { Color_insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
147 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
148 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
149 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
150 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
151 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
152 { Color_deletedtext, N_("Deleted text"), "deletedtext", "#ff0000", "deletedtext" },
153 { Color_addedtext, N_("Added text"), "addedtext", "#0000ff", "addedtext" },
154 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
155 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
156 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
157 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
158 "LightSteelBlue", "tabularonoffline" },
159 { Color_bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
160 { Color_newpage, N_("new page"), "newpage", "Blue", "newpage" },
161 { Color_pagebreak, N_("page break / line break"), "pagebreak", "RoyalBlue", "pagebreak" },
162 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
163 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
164 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
165 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
166 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
167 { Color_ignore, 0, 0, 0, 0 }
170 for (int i = 0; items[i].guiname; ++i)
175 /// initialise a color entry
176 void ColorSet::fill(ColorEntry const & entry)
179 in.lyxname = entry.lyxname;
180 in.latexname = entry.latexname;
181 in.x11name = entry.x11name;
182 in.guiname = entry.guiname;
183 infotab[entry.lcolor] = in;
184 lyxcolors[entry.lyxname] = entry.lcolor;
185 latexcolors[entry.latexname] = entry.lcolor;
189 docstring const ColorSet::getGUIName(ColorCode c) const
191 InfoTab::const_iterator it = infotab.find(c);
192 if (it != infotab.end())
193 return _(it->second.guiname);
194 return from_ascii("none");
198 string const ColorSet::getX11Name(ColorCode c) const
200 InfoTab::const_iterator it = infotab.find(c);
201 if (it != infotab.end())
202 return it->second.x11name;
204 lyxerr << "LyX internal error: Missing color"
205 " entry in Color.cpp for " << c << '\n'
206 << "Using black." << endl;
211 string const ColorSet::getLaTeXName(ColorCode c) const
213 InfoTab::const_iterator it = infotab.find(c);
214 if (it != infotab.end())
215 return it->second.latexname;
220 string const ColorSet::getLyXName(ColorCode c) const
222 InfoTab::const_iterator it = infotab.find(c);
223 if (it != infotab.end())
224 return it->second.lyxname;
229 bool ColorSet::setColor(ColorCode col, string const & x11name)
231 InfoTab::iterator it = infotab.find(col);
232 if (it == infotab.end()) {
233 lyxerr << "Color " << col << " not found in database."
238 // "inherit" is returned for colors not in the database
239 // (and anyway should not be redefined)
240 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
241 lyxerr << "Color " << getLyXName(col)
242 << " may not be redefined" << endl;
246 it->second.x11name = x11name;
251 bool ColorSet::setColor(string const & lyxname, string const &x11name)
253 string const lcname = ascii_lowercase(lyxname);
254 if (lyxcolors.find(lcname) == lyxcolors.end()) {
255 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
257 addColor(static_cast<ColorCode>(infotab.size()), lcname);
260 return setColor(lyxcolors[lcname], x11name);
264 void ColorSet::addColor(ColorCode c, string const & lyxname)
266 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
271 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
273 string const lcname = ascii_lowercase(lyxname);
274 Transform::const_iterator it = lyxcolors.find(lcname);
275 if (it == lyxcolors.end()) {
276 lyxerr << "ColorSet::getFromLyXName: Unknown color \""
277 << lyxname << '"' << endl;
285 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
287 Transform::const_iterator it = latexcolors.find(latexname);
288 if (it == latexcolors.end()) {
289 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
290 << latexname << '"' << endl;
298 // The evil global Color instance
300 // An equally evil global system Color instance
301 ColorSet system_lcolor;