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;
27 using lyx::support::ascii_lowercase;
38 char const * latexname;
45 struct LColor::Pimpl {
48 /// the name as it appears in the GUI
50 /// the name used in LaTeX
58 /// initialise a color entry
59 void fill(ColorEntry const & entry)
62 in.lyxname = string(entry.lyxname);
63 in.latexname = string(entry.latexname);
64 in.x11name = string(entry.x11name);
65 in.guiname = string(entry.guiname);
66 infotab[entry.lcolor] = in;
67 transform[string(entry.lyxname)] = int(entry.lcolor);
71 typedef std::map<int, information> InfoTab;
72 /// the table of color information
75 typedef std::map<string, int> Transform;
76 /// the transform between colour name string and integer code.
85 // LColor::color, gui, latex, x11, lyx
86 static ColorEntry const items[] = {
87 { none, N_("none"), "none", "black", "none" },
88 { black, N_("black"), "black", "black", "black" },
89 { white, N_("white"), "white", "white", "white" },
90 { red, N_("red"), "red", "red", "red" },
91 { green, N_("green"), "green", "green", "green" },
92 { blue, N_("blue"), "blue", "blue", "blue" },
93 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
94 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
95 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
96 { cursor, N_("cursor"), "cursor", "black", "cursor" },
97 { background, N_("background"), "background", "linen", "background" },
98 { foreground, N_("text"), "foreground", "black", "foreground" },
99 { selection, N_("selection"), "selection", "LightBlue", "selection" },
100 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
101 { preview, N_("previewed snippet"), "preview", "black", "preview" },
102 { note, N_("note"), "note", "yellow", "note" },
103 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
104 { comment, N_("comment"), "comment", "magenta", "comment" },
105 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
106 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
107 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
108 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
109 { language, N_("language"), "language", "Blue", "language" },
110 { command, N_("command inset"), "command", "black", "command" },
111 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
112 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
113 { special, N_("special character"), "special", "RoyalBlue", "special" },
114 { math, N_("math"), "math", "DarkBlue", "math" },
115 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
116 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
117 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
118 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
119 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
120 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
121 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
122 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
123 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
124 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
125 { error, N_("LaTeX error"), "error", "Red", "error" },
126 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
127 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
128 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
129 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
130 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
131 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
132 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
133 { tabularline, N_("table line"), "tabularline", "black",
135 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
136 "LightSteelBlue", "tabularonoffline" },
137 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
138 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
139 { top, N_("top of button"), "top", "grey90", "top" },
140 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
141 { left, N_("left of button"), "left", "grey90", "left" },
142 { right, N_("right of button"), "right", "grey60", "right" },
143 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
144 { inherit, N_("inherit"), "inherit", "black", "inherit" },
145 { ignore, N_("ignore"), "ignore", "black", "ignore" },
146 { ignore, 0, 0, 0, 0 }
149 for (int i = 0; items[i].guiname; ++i)
150 pimpl_->fill(items[i]);
154 LColor::LColor(LColor const & c)
155 : pimpl_(new Pimpl(*c.pimpl_))
163 void LColor::operator=(LColor const & c)
166 boost::swap(pimpl_, tmp.pimpl_);
170 string const LColor::getGUIName(LColor::color c) const
172 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
173 if (it != pimpl_->infotab.end())
174 return _(it->second.guiname);
179 string const LColor::getX11Name(LColor::color c) const
181 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
182 if (it != pimpl_->infotab.end())
183 return it->second.x11name;
185 lyxerr << "LyX internal error: Missing color"
186 " entry in LColor.C for " << int(c) << '\n'
187 << "Using black." << endl;
192 string const LColor::getLaTeXName(LColor::color c) const
194 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
195 if (it != pimpl_->infotab.end())
196 return it->second.latexname;
201 string const LColor::getLyXName(LColor::color c) const
203 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
204 if (it != pimpl_->infotab.end())
205 return it->second.lyxname;
210 bool LColor::setColor(LColor::color col, string const & x11name)
212 Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col);
213 if (it == pimpl_->infotab.end()) {
214 lyxerr << "Color " << col << " not found in database."
219 // "inherit" is returned for colors not in the database
220 // (and anyway should not be redefined)
221 if (col == none || col == inherit || col == ignore) {
222 lyxerr << "Color " << getLyXName(col)
223 << " may not be redefined" << endl;
227 it->second.x11name = x11name;
232 LColor::color LColor::getFromGUIName(string const & guiname) const
234 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.begin();
235 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
236 for (; it != end; ++it) {
237 if (!compare_ascii_no_case(_(it->second.guiname), guiname))
238 return static_cast<LColor::color>(it->first);
240 return LColor::inherit;
244 void LColor::addColor(LColor::color c, string const & lyxname) const
246 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
251 LColor::color LColor::getFromLyXName(string const & lyxname) const
253 string const lcname = ascii_lowercase(lyxname);
254 if (pimpl_->transform.find(lcname) == pimpl_->transform.end()) {
255 lyxerr << "LColor::getFromLyXName: Unknown color \""
256 << lyxname << '"' << endl;
257 addColor(static_cast<color>(pimpl_->infotab.size()), lcname);
260 return static_cast<LColor::color>(pimpl_->transform[lcname]);
264 // The evil global LColor instance
266 // An equally evil global system LColor instance
267 LColor system_lcolor;