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;
50 /// the name as it appears in the GUI
52 /// the name used in LaTeX
60 /// initialise a color entry
61 void fill(ColorEntry const & entry)
64 in.lyxname = entry.lyxname;
65 in.latexname = entry.latexname;
66 in.x11name = entry.x11name;
67 in.guiname = entry.guiname;
68 infotab[entry.lcolor] = in;
69 lyxcolors[entry.lyxname] = entry.lcolor;
70 latexcolors[entry.latexname] = entry.lcolor;
74 typedef std::map<LColor::color, information> InfoTab;
75 /// the table of color information
78 typedef std::map<string, LColor::color> Transform;
79 /// the transform between LyX color name string and integer code.
81 /// the transform between LaTeX color name string and integer code.
82 Transform latexcolors;
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 { shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
114 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
115 { language, N_("language"), "language", "Blue", "language" },
116 { command, N_("command inset"), "command", "black", "command" },
117 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
118 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
119 { special, N_("special character"), "special", "RoyalBlue", "special" },
120 { math, N_("math"), "math", "DarkBlue", "math" },
121 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
122 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
123 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
124 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
125 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
126 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
127 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
128 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
129 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
130 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
131 { error, N_("LaTeX error"), "error", "Red", "error" },
132 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
133 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
134 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
135 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
136 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
137 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
138 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
139 { tabularline, N_("table line"), "tabularline", "black",
141 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
142 "LightSteelBlue", "tabularonoffline" },
143 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
144 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
145 { top, N_("top of button"), "top", "grey90", "top" },
146 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
147 { left, N_("left of button"), "left", "grey90", "left" },
148 { right, N_("right of button"), "right", "grey60", "right" },
149 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
150 { inherit, N_("inherit"), "inherit", "black", "inherit" },
151 { ignore, N_("ignore"), "ignore", "black", "ignore" },
152 { ignore, 0, 0, 0, 0 }
155 for (int i = 0; items[i].guiname; ++i)
156 pimpl_->fill(items[i]);
160 LColor::LColor(LColor const & c)
161 : pimpl_(new Pimpl(*c.pimpl_))
169 LColor & LColor::operator=(LColor tmp)
171 boost::swap(pimpl_, tmp.pimpl_);
176 string const LColor::getGUIName(LColor::color c) const
178 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
179 if (it != pimpl_->infotab.end())
180 return lyx::to_utf8(_(it->second.guiname));
185 string const LColor::getX11Name(LColor::color c) const
187 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
188 if (it != pimpl_->infotab.end())
189 return it->second.x11name;
191 lyxerr << "LyX internal error: Missing color"
192 " entry in LColor.C for " << c << '\n'
193 << "Using black." << endl;
198 string const LColor::getLaTeXName(LColor::color c) const
200 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
201 if (it != pimpl_->infotab.end())
202 return it->second.latexname;
207 string const LColor::getLyXName(LColor::color c) const
209 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
210 if (it != pimpl_->infotab.end())
211 return it->second.lyxname;
216 bool LColor::setColor(LColor::color col, string const & x11name)
218 Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col);
219 if (it == pimpl_->infotab.end()) {
220 lyxerr << "Color " << col << " not found in database."
225 // "inherit" is returned for colors not in the database
226 // (and anyway should not be redefined)
227 if (col == none || col == inherit || col == ignore) {
228 lyxerr << "Color " << getLyXName(col)
229 << " may not be redefined" << endl;
233 it->second.x11name = x11name;
238 bool LColor::setColor(string const & lyxname, string const &x11name)
240 string const lcname = ascii_lowercase(lyxname);
241 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
243 << "LColor::setColor: Unknown color \""
244 << lyxname << '"' << endl;
245 addColor(static_cast<color>(pimpl_->infotab.size()), lcname);
248 return setColor(pimpl_->lyxcolors[lcname], x11name);
252 LColor::color LColor::getFromGUIName(string const & guiname) const
254 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.begin();
255 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
256 for (; it != end; ++it) {
257 if (!compare_ascii_no_case(lyx::to_utf8(_(it->second.guiname)), guiname))
260 return LColor::inherit;
264 void LColor::addColor(LColor::color c, string const & lyxname) const
266 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
271 LColor::color LColor::getFromLyXName(string const & lyxname) const
273 string const lcname = ascii_lowercase(lyxname);
274 if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
275 lyxerr << "LColor::getFromLyXName: Unknown color \""
276 << lyxname << '"' << endl;
280 return pimpl_->lyxcolors[lcname];
284 LColor::color LColor::getFromLaTeXName(string const & latexname) const
286 if (pimpl_->latexcolors.find(latexname) == pimpl_->latexcolors.end()) {
287 lyxerr << "LColor::getFromLaTeXName: Unknown color \""
288 << latexname << '"' << endl;
292 return pimpl_->latexcolors[latexname];
296 // The evil global LColor instance
298 // An equally evil global system LColor instance
299 LColor system_lcolor;