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;
37 char const * latexname;
44 struct TransformEntry {
50 struct LColor::Pimpl {
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 = string(entry.lyxname);
68 in.latexname = string(entry.latexname);
69 in.x11name = string(entry.x11name);
70 in.guiname = string(entry.guiname);
71 infotab[entry.lcolor] = in;
72 transform[string(entry.lyxname)] = int(entry.lcolor);
76 typedef std::map<int, information> InfoTab;
77 /// the table of color information
80 typedef std::map<string, int> Transform;
81 /// the transform between colour name string and integer code.
90 // LColor::color, gui, latex, x11, lyx
91 static ColorEntry const items[] = {
92 { none, N_("none"), "none", "black", "none" },
93 { black, N_("black"), "black", "black", "black" },
94 { white, N_("white"), "white", "white", "white" },
95 { red, N_("red"), "red", "red", "red" },
96 { green, N_("green"), "green", "green", "green" },
97 { blue, N_("blue"), "blue", "blue", "blue" },
98 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
99 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
100 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
101 { cursor, N_("cursor"), "cursor", "black", "cursor" },
102 { background, N_("background"), "background", "linen", "background" },
103 { foreground, N_("text"), "foreground", "black", "foreground" },
104 { selection, N_("selection"), "selection", "LightBlue", "selection" },
105 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
106 { preview, N_("previewed snippet"), "preview", "black", "preview" },
107 { note, N_("note"), "note", "yellow", "note" },
108 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
109 { comment, N_("comment"), "comment", "magenta", "comment" },
110 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
111 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
112 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
113 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
114 { language, N_("language"), "language", "Blue", "language" },
115 { command, N_("command inset"), "command", "black", "command" },
116 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
117 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
118 { special, N_("special character"), "special", "RoyalBlue", "special" },
119 { math, N_("math"), "math", "DarkBlue", "math" },
120 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
121 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
122 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
123 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
124 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
125 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
126 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
127 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
128 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
129 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
130 { error, N_("LaTeX error"), "error", "Red", "error" },
131 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
132 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
133 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
134 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
135 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
136 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
137 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
138 { tabularline, N_("table line"), "tabularline", "black",
140 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
141 "LightSteelBlue", "tabularonoffline" },
142 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
143 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
144 { top, N_("top of button"), "top", "grey90", "top" },
145 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
146 { left, N_("left of button"), "left", "grey90", "left" },
147 { right, N_("right of button"), "right", "grey60", "right" },
148 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
149 { inherit, N_("inherit"), "inherit", "black", "inherit" },
150 { ignore, N_("ignore"), "ignore", "black", "ignore" },
151 { ignore, 0, 0, 0, 0 }
154 for (int i = 0; items[i].guiname; ++i)
155 pimpl_->fill(items[i]);
159 LColor::LColor(LColor const & c)
160 : pimpl_(new Pimpl(*c.pimpl_))
168 void LColor::operator=(LColor const & c)
171 boost::swap(pimpl_, tmp.pimpl_);
175 void LColor::fill(LColor::color c,
176 string const & lyxname,
177 string const & x11name,
178 string const & latexname,
179 string const & guiname)
183 ce.guiname = guiname.c_str();
184 ce.latexname = latexname.c_str();
185 ce.x11name = x11name.c_str();
186 ce.lyxname = lyxname.c_str();
191 string const LColor::getGUIName(LColor::color c) const
193 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
194 if (ici != pimpl_->infotab.end())
195 return _(ici->second.guiname);
200 string const LColor::getGUIName(string const & s) const
202 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
203 if (ici != pimpl_->transform.end()) {
204 Pimpl::InfoTab::const_iterator
205 it = pimpl_->infotab.find(ici->second);
206 if (it != pimpl_->infotab.end())
207 return it->second.guiname;
213 string const LColor::getX11Name(LColor::color c) const
215 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
216 if (ici != pimpl_->infotab.end())
217 return ici->second.x11name;
219 lyxerr << "LyX internal error: Missing color"
220 " entry in LColor.C for " << int(c) << endl;
221 lyxerr << "Using black." << endl;
226 string const LColor::getX11Name(string const & s) const
228 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
229 if (ici != pimpl_->transform.end()) {
230 Pimpl::InfoTab::const_iterator
231 it = pimpl_->infotab.find(ici->second);
232 if (it != pimpl_->infotab.end())
233 return it->second.x11name;
235 lyxerr << "LyX internal error: Missing color"
236 " entry in LColor.C for " << s << endl;
237 lyxerr << "Using black." << endl;
242 string const LColor::getLaTeXName(LColor::color c) const
244 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
245 if (ici != pimpl_->infotab.end())
246 return ici->second.latexname;
251 string const LColor::getLaTeXName(string const & s) const
253 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
254 if (ici != pimpl_->transform.end()) {
255 Pimpl::InfoTab::const_iterator
256 it = pimpl_->infotab.find(ici->second);
257 if (it != pimpl_->infotab.end())
258 return it->second.latexname;
264 string const LColor::getLyXName(LColor::color c) const
266 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
267 if (ici != pimpl_->infotab.end())
268 return ici->second.lyxname;
273 size_t LColor::size() const
275 return pimpl_->infotab.size();
279 void LColor::setColor(LColor::color col, string const & x11name)
281 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
282 if (iti != pimpl_->infotab.end()) {
283 iti->second.x11name = x11name;
286 lyxerr << "LyX internal error: color and such." << endl;
291 bool LColor::setColor(string const & lyxname, string const & x11name)
293 color col = getFromLyXName(lyxname);
295 // "inherit" is returned for colors not in the database
296 // (and anyway should not be redefined)
297 if (col == inherit || col == ignore) {
298 lyxerr << "Color " << lyxname << " is undefined or may not be"
299 " redefined" << endl;
302 setColor(col, x11name);
307 LColor::color LColor::getFromGUIName(string const & guiname) const
309 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
310 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
311 for (; ici != end; ++ici) {
312 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
313 return static_cast<LColor::color>(ici->first);
315 return LColor::inherit;
319 LColor::color LColor::getFromLyXName(string const & lyxname) const
321 return static_cast<LColor::color>(pimpl_->transform[lyxname]);
325 // The evil global LColor instance
327 // An equally evil global system LColor instance
328 LColor system_lcolor;