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.
22 #include "support/lstrings.h"
29 using support::compare_ascii_no_case;
30 using support::ascii_lowercase;
41 char const * latexname;
53 /// the name as it appears in the GUI
55 /// the name used in LaTeX
63 /// initialise a color entry
64 void fill(ColorEntry const & entry)
67 in.lyxname = entry.lyxname;
68 in.latexname = entry.latexname;
69 in.x11name = entry.x11name;
70 in.guiname = entry.guiname;
71 infotab[entry.lcolor] = in;
72 lyxcolors[entry.lyxname] = entry.lcolor;
73 latexcolors[entry.latexname] = entry.lcolor;
77 typedef std::map<LColor::color, information> InfoTab;
78 /// the table of color information
81 typedef std::map<string, LColor::color> Transform;
82 /// the transform between LyX color name string and integer code.
84 /// the transform between LaTeX color name string and integer code.
85 Transform latexcolors;
93 // LColor::color, gui, latex, x11, lyx
94 static ColorEntry const items[] = {
95 { none, N_("none"), "none", "black", "none" },
96 { black, N_("black"), "black", "black", "black" },
97 { white, N_("white"), "white", "white", "white" },
98 { red, N_("red"), "red", "red", "red" },
99 { green, N_("green"), "green", "green", "green" },
100 { blue, N_("blue"), "blue", "blue", "blue" },
101 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
102 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
103 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
104 { cursor, N_("cursor"), "cursor", "black", "cursor" },
105 { background, N_("background"), "background", "linen", "background" },
106 { foreground, N_("text"), "foreground", "black", "foreground" },
107 { selection, N_("selection"), "selection", "LightBlue", "selection" },
108 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
109 { preview, N_("previewed snippet"), "preview", "black", "preview" },
110 { note, N_("note"), "note", "blue", "note" },
111 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
112 { comment, N_("comment"), "comment", "magenta", "comment" },
113 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
114 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
115 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
116 { shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
117 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
118 { language, N_("language"), "language", "Blue", "language" },
119 { command, N_("command inset"), "command", "black", "command" },
120 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
121 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
122 { special, N_("special character"), "special", "RoyalBlue", "special" },
123 { math, N_("math"), "math", "DarkBlue", "math" },
124 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
125 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
126 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
127 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
128 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
129 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
130 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
131 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
132 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
133 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
134 { error, N_("LaTeX error"), "error", "Red", "error" },
135 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
136 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
137 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
138 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
139 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
140 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
141 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
142 { tabularline, N_("table line"), "tabularline", "black",
144 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
145 "LightSteelBlue", "tabularonoffline" },
146 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
147 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
148 { buttonframe, N_("frame of button"), "buttonframe", "#A9ABB5", "buttonframe" },
149 { buttonbg, N_("button background"), "buttonbg", "linen", "buttonbg" },
150 { buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
151 { inherit, N_("inherit"), "inherit", "black", "inherit" },
152 { ignore, N_("ignore"), "ignore", "black", "ignore" },
153 { ignore, 0, 0, 0, 0 }
156 for (int i = 0; items[i].guiname; ++i)
157 pimpl_->fill(items[i]);
161 LColor::LColor(LColor const & c)
162 : pimpl_(new Pimpl(*c.pimpl_))
170 LColor & LColor::operator=(LColor tmp)
172 boost::swap(pimpl_, tmp.pimpl_);
177 string const LColor::getGUIName(LColor::color c) const
179 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
180 if (it != pimpl_->infotab.end())
181 return to_utf8(_(it->second.guiname));
186 string const LColor::getX11Name(LColor::color c) const
188 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
189 if (it != pimpl_->infotab.end())
190 return it->second.x11name;
192 lyxerr << "LyX internal error: Missing color"
193 " entry in LColor.C for " << c << '\n'
194 << "Using black." << endl;
199 string const LColor::getLaTeXName(LColor::color c) const
201 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
202 if (it != pimpl_->infotab.end())
203 return it->second.latexname;
208 string const LColor::getLyXName(LColor::color c) const
210 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
211 if (it != pimpl_->infotab.end())
212 return it->second.lyxname;
217 bool LColor::setColor(LColor::color col, string const & x11name)
219 Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col);
220 if (it == pimpl_->infotab.end()) {
221 lyxerr << "Color " << col << " not found in database."
226 // "inherit" is returned for colors not in the database
227 // (and anyway should not be redefined)
228 if (col == none || col == inherit || col == ignore) {
229 lyxerr << "Color " << getLyXName(col)
230 << " may not be redefined" << endl;
234 it->second.x11name = x11name;
239 bool LColor::setColor(string const & lyxname, string const &x11name)
241 string const lcname = ascii_lowercase(lyxname);
242 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
244 << "LColor::setColor: Unknown color \""
245 << lyxname << '"' << endl;
246 addColor(static_cast<color>(pimpl_->infotab.size()), lcname);
249 return setColor(pimpl_->lyxcolors[lcname], x11name);
253 LColor::color LColor::getFromGUIName(string const & guiname) const
255 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.begin();
256 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
257 for (; it != end; ++it) {
258 if (!compare_ascii_no_case(to_utf8(_(it->second.guiname)), guiname))
261 return LColor::inherit;
265 void LColor::addColor(LColor::color c, string const & lyxname) const
267 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
272 LColor::color LColor::getFromLyXName(string const & lyxname) const
274 string const lcname = ascii_lowercase(lyxname);
275 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
276 lyxerr << "LColor::getFromLyXName: Unknown color \""
277 << lyxname << '"' << endl;
281 return pimpl_->lyxcolors[lcname];
285 LColor::color LColor::getFromLaTeXName(string const & latexname) const
287 if (pimpl_->latexcolors.find(latexname) == pimpl_->latexcolors.end()) {
288 lyxerr << "LColor::getFromLaTeXName: Unknown color \""
289 << latexname << '"' << endl;
293 return pimpl_->latexcolors[latexname];
297 // The evil global LColor instance
299 // An equally evil global system LColor instance
300 LColor system_lcolor;