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"
26 using lyx::support::compare_ascii_no_case;
36 char const * latexname;
43 struct TransformEntry {
49 struct LColor::Pimpl {
52 /// the name as it appears in the GUI
54 /// the name used in LaTeX
62 /// initialise a color entry
63 void fill(ColorEntry const & entry)
66 in.lyxname = string(entry.lyxname);
67 in.latexname = string(entry.latexname);
68 in.x11name = string(entry.x11name);
69 in.guiname = string(entry.guiname);
70 infotab[entry.lcolor] = in;
71 transform[string(entry.lyxname)] = int(entry.lcolor);
75 typedef std::map<int, information> InfoTab;
76 /// the table of color information
79 typedef std::map<string, int> Transform;
80 /// the transform between colour name string and integer code.
89 // LColor::color, gui, latex, x11, lyx
90 static ColorEntry const items[] = {
91 { none, N_("none"), "none", "black", "none" },
92 { black, N_("black"), "black", "black", "black" },
93 { white, N_("white"), "white", "white", "white" },
94 { red, N_("red"), "red", "red", "red" },
95 { green, N_("green"), "green", "green", "green" },
96 { blue, N_("blue"), "blue", "blue", "blue" },
97 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
98 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
99 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
100 { cursor, N_("cursor"), "cursor", "black", "cursor" },
101 { background, N_("background"), "background", "linen", "background" },
102 { foreground, N_("text"), "foreground", "black", "foreground" },
103 { selection, N_("selection"), "selection", "LightBlue", "selection" },
104 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
105 { preview, N_("previewed snippet"), "preview", "black", "preview" },
106 { note, N_("note"), "note", "yellow", "note" },
107 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
108 { comment, N_("comment"), "comment", "magenta", "comment" },
109 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
110 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
111 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
112 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
113 { language, N_("language"), "language", "Blue", "language" },
114 { command, N_("command inset"), "command", "black", "command" },
115 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
116 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
117 { special, N_("special character"), "special", "RoyalBlue", "special" },
118 { math, N_("math"), "math", "DarkBlue", "math" },
119 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
120 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
121 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
122 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
123 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
124 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
125 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
126 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
127 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
128 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
129 { error, N_("LaTeX error"), "error", "Red", "error" },
130 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
131 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
132 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
133 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
134 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
135 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
136 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
137 { tabularline, N_("table line"), "tabularline", "black",
139 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
140 "LightSteelBlue", "tabularonoffline" },
141 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
142 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
143 { top, N_("top of button"), "top", "grey90", "top" },
144 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
145 { left, N_("left of button"), "left", "grey90", "left" },
146 { right, N_("right of button"), "right", "grey60", "right" },
147 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
148 { inherit, N_("inherit"), "inherit", "black", "inherit" },
149 { ignore, N_("ignore"), "ignore", "black", "ignore" },
150 { ignore, 0, 0, 0, 0 }
153 for (int i = 0; items[i].guiname; ++i)
154 pimpl_->fill(items[i]);
158 LColor::LColor(LColor const & c)
159 : pimpl_(new Pimpl(*c.pimpl_))
167 void LColor::operator=(LColor const & c)
170 boost::swap(pimpl_, tmp.pimpl_);
174 void LColor::fill(LColor::color c,
175 string const & lyxname,
176 string const & x11name,
177 string const & latexname,
178 string const & guiname)
182 ce.guiname = guiname.c_str();
183 ce.latexname = latexname.c_str();
184 ce.x11name = x11name.c_str();
185 ce.lyxname = lyxname.c_str();
190 string const LColor::getGUIName(LColor::color c) const
192 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
193 if (ici != pimpl_->infotab.end())
194 return _(ici->second.guiname);
199 string const LColor::getGUIName(string const & s) const
201 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
202 if (ici != pimpl_->transform.end()) {
203 Pimpl::InfoTab::const_iterator
204 it = pimpl_->infotab.find(ici->second);
205 if (it != pimpl_->infotab.end())
206 return it->second.guiname;
212 string const LColor::getX11Name(LColor::color c) const
214 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
215 if (ici != pimpl_->infotab.end())
216 return ici->second.x11name;
218 lyxerr << "LyX internal error: Missing color"
219 " entry in LColor.C for " << int(c) << endl;
220 lyxerr << "Using black." << endl;
225 string const LColor::getX11Name(string const & s) const
227 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
228 if (ici != pimpl_->transform.end()) {
229 Pimpl::InfoTab::const_iterator
230 it = pimpl_->infotab.find(ici->second);
231 if (it != pimpl_->infotab.end())
232 return it->second.x11name;
234 lyxerr << "LyX internal error: Missing color"
235 " entry in LColor.C for " << s << endl;
236 lyxerr << "Using black." << endl;
241 string const LColor::getLaTeXName(LColor::color c) const
243 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
244 if (ici != pimpl_->infotab.end())
245 return ici->second.latexname;
250 string const LColor::getLaTeXName(string const & s) const
252 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
253 if (ici != pimpl_->transform.end()) {
254 Pimpl::InfoTab::const_iterator
255 it = pimpl_->infotab.find(ici->second);
256 if (it != pimpl_->infotab.end())
257 return it->second.latexname;
263 string const LColor::getLyXName(LColor::color c) const
265 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
266 if (ici != pimpl_->infotab.end())
267 return ici->second.lyxname;
272 size_t LColor::size() const
274 return pimpl_->infotab.size();
278 void LColor::setColor(LColor::color col, string const & x11name)
280 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
281 if (iti != pimpl_->infotab.end()) {
282 iti->second.x11name = x11name;
285 lyxerr << "LyX internal error: color and such." << endl;
290 bool LColor::setColor(string const & lyxname, string const & x11name)
292 color col = getFromLyXName(lyxname);
294 // "inherit" is returned for colors not in the database
295 // (and anyway should not be redefined)
296 if (col == inherit || col == ignore) {
297 lyxerr << "Color " << lyxname << " is undefined or may not be"
298 " redefined" << endl;
301 setColor(col, x11name);
306 LColor::color LColor::getFromGUIName(string const & guiname) const
308 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
309 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
310 for (; ici != end; ++ici) {
311 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
312 return static_cast<LColor::color>(ici->first);
314 return LColor::inherit;
318 LColor::color LColor::getFromLyXName(string const & lyxname) const
320 return static_cast<LColor::color>(pimpl_->transform[lyxname]);
324 // The evil global LColor instance
326 // An equally evil global system LColor instance
327 LColor system_lcolor;