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.
23 #include "support/lstrings.h"
31 #ifndef CXX_GLOBAL_CSTD
39 using std::istringstream;
40 using std::ostringstream;
46 using support::compare_ascii_no_case;
47 using support::ascii_lowercase;
54 char const * latexname;
61 int hexstrToInt(string const & str)
64 istringstream is(str);
65 is >> std::setbase(16) >> val;
72 /////////////////////////////////////////////////////////////////////
76 /////////////////////////////////////////////////////////////////////
79 string const X11hexname(RGBColor const & col)
83 ostr << '#' << std::setbase(16) << std::setfill('0')
92 RGBColor::RGBColor(string const & x11hexname)
95 BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
96 r = hexstrToInt(x11hexname.substr(1,2));
97 g = hexstrToInt(x11hexname.substr(3,2));
98 b = hexstrToInt(x11hexname.substr(5,2));
102 /////////////////////////////////////////////////////////////////////
106 /////////////////////////////////////////////////////////////////////
113 /// the name as it appears in the GUI
115 /// the name used in LaTeX
123 /// initialise a color entry
124 void fill(ColorEntry const & entry)
127 in.lyxname = entry.lyxname;
128 in.latexname = entry.latexname;
129 in.x11name = entry.x11name;
130 in.guiname = entry.guiname;
131 infotab[entry.lcolor] = in;
132 lyxcolors[entry.lyxname] = entry.lcolor;
133 latexcolors[entry.latexname] = entry.lcolor;
137 typedef std::map<ColorCode, information> InfoTab;
138 /// the table of color information
141 typedef std::map<string, ColorCode> Transform;
142 /// the transform between LyX color name string and integer code.
144 /// the transform between LaTeX color name string and integer code.
145 Transform latexcolors;
153 // ColorCode, gui, latex, x11, lyx
154 static ColorEntry const items[] = {
155 { Color_none, N_("none"), "none", "black", "none" },
156 { Color_black, N_("black"), "black", "black", "black" },
157 { Color_white, N_("white"), "white", "white", "white" },
158 { Color_red, N_("red"), "red", "red", "red" },
159 { Color_green, N_("green"), "green", "green", "green" },
160 { Color_blue, N_("blue"), "blue", "blue", "blue" },
161 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
162 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
163 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
164 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
165 { Color_background, N_("background"), "background", "linen", "background" },
166 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
167 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
168 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
169 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
170 { Color_note, N_("note"), "note", "blue", "note" },
171 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
172 { Color_comment, N_("comment"), "comment", "magenta", "comment" },
173 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
174 { Color_greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
175 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
176 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
177 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
178 { Color_language, N_("language"), "language", "Blue", "language" },
179 { Color_command, N_("command inset"), "command", "black", "command" },
180 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
181 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
182 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
183 { Color_math, N_("math"), "math", "DarkBlue", "math" },
184 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
185 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
186 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
187 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
188 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
189 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
190 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
191 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
192 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
193 { Color_insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
194 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
195 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
196 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
197 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
198 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
199 { Color_deletedtext, N_("Deleted text"), "deletedtext", "#ff0000", "deletedtext" },
200 { Color_addedtext, N_("Added text"), "addedtext", "#0000ff", "addedtext" },
201 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
202 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
203 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
204 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
205 "LightSteelBlue", "tabularonoffline" },
206 { Color_bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
207 { Color_pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
208 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
209 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
210 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
211 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
212 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
213 { Color_ignore, 0, 0, 0, 0 }
216 for (int i = 0; items[i].guiname; ++i)
217 pimpl_->fill(items[i]);
221 Color::Color(Color const & c)
222 : pimpl_(new Pimpl(*c.pimpl_))
230 Color & Color::operator=(Color tmp)
232 boost::swap(pimpl_, tmp.pimpl_);
237 docstring const Color::getGUIName(ColorCode c) const
239 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
240 if (it != pimpl_->infotab.end())
241 return _(it->second.guiname);
242 return from_ascii("none");
246 string const Color::getX11Name(ColorCode c) const
248 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
249 if (it != pimpl_->infotab.end())
250 return it->second.x11name;
252 lyxerr << "LyX internal error: Missing color"
253 " entry in Color.cpp for " << c << '\n'
254 << "Using black." << endl;
259 string const Color::getLaTeXName(ColorCode c) const
261 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
262 if (it != pimpl_->infotab.end())
263 return it->second.latexname;
268 string const Color::getLyXName(ColorCode c) const
270 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
271 if (it != pimpl_->infotab.end())
272 return it->second.lyxname;
277 bool Color::setColor(ColorCode col, string const & x11name)
279 Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col);
280 if (it == pimpl_->infotab.end()) {
281 lyxerr << "Color " << col << " not found in database."
286 // "inherit" is returned for colors not in the database
287 // (and anyway should not be redefined)
288 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
289 lyxerr << "Color " << getLyXName(col)
290 << " may not be redefined" << endl;
294 it->second.x11name = x11name;
299 bool Color::setColor(string const & lyxname, string const &x11name)
301 string const lcname = ascii_lowercase(lyxname);
302 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
304 << "Color::setColor: Unknown color \""
305 << lyxname << '"' << endl;
306 addColor(static_cast<ColorCode>(pimpl_->infotab.size()), lcname);
309 return setColor(pimpl_->lyxcolors[lcname], x11name);
313 void Color::addColor(ColorCode c, string const & lyxname) const
315 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
320 ColorCode Color::getFromLyXName(string const & lyxname) const
322 string const lcname = ascii_lowercase(lyxname);
323 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
324 lyxerr << "Color::getFromLyXName: Unknown color \""
325 << lyxname << '"' << endl;
329 return pimpl_->lyxcolors[lcname];
333 ColorCode Color::getFromLaTeXName(string const & latexname) const
335 if (pimpl_->latexcolors.find(latexname) == pimpl_->latexcolors.end()) {
336 lyxerr << "Color::getFromLaTeXName: Unknown color \""
337 << latexname << '"' << endl;
341 return pimpl_->latexcolors[latexname];
345 // The evil global Color instance
347 // An equally evil global system Color instance