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.
24 #include "support/lstrings.h"
26 #include <boost/assert.hpp>
34 #ifndef CXX_GLOBAL_CSTD
42 using std::istringstream;
43 using std::ostringstream;
49 using support::compare_ascii_no_case;
50 using support::ascii_lowercase;
52 struct ColorSet::ColorEntry {
55 char const * latexname;
61 static int hexstrToInt(string const & str)
64 istringstream is(str);
65 is >> std::setbase(16) >> val;
70 /////////////////////////////////////////////////////////////////////
74 /////////////////////////////////////////////////////////////////////
77 string const X11hexname(RGBColor const & col)
81 ostr << '#' << std::setbase(16) << std::setfill('0')
90 RGBColor rgbFromHexName(string const & x11hexname)
93 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
94 c.r = hexstrToInt(x11hexname.substr(1,2));
95 c.g = hexstrToInt(x11hexname.substr(3,2));
96 c.b = hexstrToInt(x11hexname.substr(5,2));
103 // ColorCode, gui, latex, x11, lyx
104 static ColorEntry const items[] = {
105 { Color_none, N_("none"), "none", "black", "none" },
106 { Color_black, N_("black"), "black", "black", "black" },
107 { Color_white, N_("white"), "white", "white", "white" },
108 { Color_red, N_("red"), "red", "red", "red" },
109 { Color_green, N_("green"), "green", "green", "green" },
110 { Color_blue, N_("blue"), "blue", "blue", "blue" },
111 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
112 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
113 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
114 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
115 { Color_background, N_("background"), "background", "linen", "background" },
116 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
117 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
118 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
119 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
120 { Color_note, N_("note"), "note", "blue", "note" },
121 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
122 { Color_comment, N_("comment"), "comment", "magenta", "comment" },
123 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
124 { Color_greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
125 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
126 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
127 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
128 { Color_language, N_("language"), "language", "Blue", "language" },
129 { Color_command, N_("command inset"), "command", "black", "command" },
130 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
131 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
132 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
133 { Color_math, N_("math"), "math", "DarkBlue", "math" },
134 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
135 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
136 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
137 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
138 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
139 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
140 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "#ede2d8", "mathmacrobg" },
141 { Color_mathmacrohoverbg, N_("Math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", "mathmacrohoverbg" },
142 { Color_mathmacrolabel, N_("Math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
143 { Color_mathmacroframe, N_("Math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
144 { Color_mathmacroblend, N_("Math macro blended out"), "mathmacroblend", "#000000", "mathmacroblend" },
145 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
146 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
147 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
148 { Color_insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
149 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
150 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
151 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
152 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
153 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
154 { Color_deletedtext, N_("Deleted text"), "deletedtext", "#ff0000", "deletedtext" },
155 { Color_addedtext, N_("Added text"), "addedtext", "#0000ff", "addedtext" },
156 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
157 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
158 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
159 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
160 "LightSteelBlue", "tabularonoffline" },
161 { Color_bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
162 { Color_pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
163 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
164 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
165 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
166 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
167 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
168 { Color_ignore, 0, 0, 0, 0 }
171 for (int i = 0; items[i].guiname; ++i)
176 /// initialise a color entry
177 void ColorSet::fill(ColorEntry const & entry)
180 in.lyxname = entry.lyxname;
181 in.latexname = entry.latexname;
182 in.x11name = entry.x11name;
183 in.guiname = entry.guiname;
184 infotab[entry.lcolor] = in;
185 lyxcolors[entry.lyxname] = entry.lcolor;
186 latexcolors[entry.latexname] = entry.lcolor;
190 docstring const ColorSet::getGUIName(ColorCode c) const
192 InfoTab::const_iterator it = infotab.find(c);
193 if (it != infotab.end())
194 return _(it->second.guiname);
195 return from_ascii("none");
199 string const ColorSet::getX11Name(ColorCode c) const
201 InfoTab::const_iterator it = infotab.find(c);
202 if (it != infotab.end())
203 return it->second.x11name;
205 lyxerr << "LyX internal error: Missing color"
206 " entry in Color.cpp for " << c << '\n'
207 << "Using black." << endl;
212 string const ColorSet::getLaTeXName(ColorCode c) const
214 InfoTab::const_iterator it = infotab.find(c);
215 if (it != infotab.end())
216 return it->second.latexname;
221 string const ColorSet::getLyXName(ColorCode c) const
223 InfoTab::const_iterator it = infotab.find(c);
224 if (it != infotab.end())
225 return it->second.lyxname;
230 bool ColorSet::setColor(ColorCode col, string const & x11name)
232 InfoTab::iterator it = infotab.find(col);
233 if (it == infotab.end()) {
234 lyxerr << "Color " << col << " not found in database."
239 // "inherit" is returned for colors not in the database
240 // (and anyway should not be redefined)
241 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
242 lyxerr << "Color " << getLyXName(col)
243 << " may not be redefined" << endl;
247 it->second.x11name = x11name;
252 bool ColorSet::setColor(string const & lyxname, string const &x11name)
254 string const lcname = ascii_lowercase(lyxname);
255 if (lyxcolors.find(lcname) == lyxcolors.end()) {
257 << "ColorSet::setColor: Unknown color \""
258 << lyxname << '"' << endl;
259 addColor(static_cast<ColorCode>(infotab.size()), lcname);
262 return setColor(lyxcolors[lcname], x11name);
266 void ColorSet::addColor(ColorCode c, string const & lyxname)
268 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
273 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
275 string const lcname = ascii_lowercase(lyxname);
276 Transform::const_iterator it = lyxcolors.find(lcname);
277 if (it == lyxcolors.end()) {
278 lyxerr << "ColorSet::getFromLyXName: Unknown color \""
279 << lyxname << '"' << endl;
287 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
289 Transform::const_iterator it = latexcolors.find(latexname);
290 if (it == latexcolors.end()) {
291 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
292 << latexname << '"' << endl;
300 // The evil global Color instance
302 // An equally evil global system Color instance
303 ColorSet system_lcolor;