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 LColor::Pimpl {
47 /// the name as it appears in the GUI
49 /// the name used in LaTeX
57 /// initialise a color entry
58 void fill(ColorEntry const & entry)
61 in.lyxname = string(entry.lyxname);
62 in.latexname = string(entry.latexname);
63 in.x11name = string(entry.x11name);
64 in.guiname = string(entry.guiname);
65 infotab[entry.lcolor] = in;
66 transform[string(entry.lyxname)] = int(entry.lcolor);
70 typedef std::map<int, information> InfoTab;
71 /// the table of color information
74 typedef std::map<string, int> Transform;
75 /// the transform between colour name string and integer code.
84 // LColor::color, gui, latex, x11, lyx
85 static ColorEntry const items[] = {
86 { none, N_("none"), "none", "black", "none" },
87 { black, N_("black"), "black", "black", "black" },
88 { white, N_("white"), "white", "white", "white" },
89 { red, N_("red"), "red", "red", "red" },
90 { green, N_("green"), "green", "green", "green" },
91 { blue, N_("blue"), "blue", "blue", "blue" },
92 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
93 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
94 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
95 { cursor, N_("cursor"), "cursor", "black", "cursor" },
96 { background, N_("background"), "background", "linen", "background" },
97 { foreground, N_("text"), "foreground", "black", "foreground" },
98 { selection, N_("selection"), "selection", "LightBlue", "selection" },
99 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
100 { preview, N_("previewed snippet"), "preview", "black", "preview" },
101 { note, N_("note"), "note", "yellow", "note" },
102 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
103 { comment, N_("comment"), "comment", "magenta", "comment" },
104 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
105 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
106 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
107 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
108 { language, N_("language"), "language", "Blue", "language" },
109 { command, N_("command inset"), "command", "black", "command" },
110 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
111 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
112 { special, N_("special character"), "special", "RoyalBlue", "special" },
113 { math, N_("math"), "math", "DarkBlue", "math" },
114 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
115 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
116 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
117 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
118 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
119 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
120 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
121 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
122 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
123 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
124 { error, N_("LaTeX error"), "error", "Red", "error" },
125 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
126 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
127 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
128 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
129 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
130 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
131 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
132 { tabularline, N_("table line"), "tabularline", "black",
134 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
135 "LightSteelBlue", "tabularonoffline" },
136 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
137 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
138 { top, N_("top of button"), "top", "grey90", "top" },
139 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
140 { left, N_("left of button"), "left", "grey90", "left" },
141 { right, N_("right of button"), "right", "grey60", "right" },
142 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
143 { inherit, N_("inherit"), "inherit", "black", "inherit" },
144 { ignore, N_("ignore"), "ignore", "black", "ignore" },
145 { ignore, 0, 0, 0, 0 }
148 for (int i = 0; items[i].guiname; ++i)
149 pimpl_->fill(items[i]);
153 LColor::LColor(LColor const & c)
154 : pimpl_(new Pimpl(*c.pimpl_))
162 void LColor::operator=(LColor const & c)
165 boost::swap(pimpl_, tmp.pimpl_);
169 string const LColor::getGUIName(LColor::color c) const
171 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
172 if (it != pimpl_->infotab.end())
173 return _(it->second.guiname);
178 string const LColor::getX11Name(LColor::color c) const
180 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
181 if (it != pimpl_->infotab.end())
182 return it->second.x11name;
184 lyxerr << "LyX internal error: Missing color"
185 " entry in LColor.C for " << int(c) << '\n'
186 << "Using black." << endl;
191 string const LColor::getLaTeXName(LColor::color c) const
193 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
194 if (it != pimpl_->infotab.end())
195 return it->second.latexname;
200 string const LColor::getLyXName(LColor::color c) const
202 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
203 if (it != pimpl_->infotab.end())
204 return it->second.lyxname;
209 bool LColor::setColor(LColor::color col, string const & x11name)
211 Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col);
212 if (it == pimpl_->infotab.end()) {
213 lyxerr << "Color " << col << " not found in database."
218 // "inherit" is returned for colors not in the database
219 // (and anyway should not be redefined)
220 if (col == none || col == inherit || col == ignore) {
221 lyxerr << "Color " << getLyXName(col)
222 << " may not be redefined" << endl;
226 it->second.x11name = x11name;
231 LColor::color LColor::getFromGUIName(string const & guiname) const
233 Pimpl::InfoTab::const_iterator it = pimpl_->infotab.begin();
234 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
235 for (; it != end; ++it) {
236 if (!compare_ascii_no_case(_(it->second.guiname), guiname))
237 return static_cast<LColor::color>(it->first);
239 return LColor::inherit;
243 void LColor::addColor(LColor::color c, string const & lyxname) const
245 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
250 LColor::color LColor::getFromLyXName(string const & lyxname) const
252 if (pimpl_->transform.find(lyxname) == pimpl_->transform.end())
253 addColor(static_cast<color>(pimpl_->infotab.size()), lyxname);
255 return static_cast<LColor::color>(pimpl_->transform[lyxname]);
259 // The evil global LColor instance
261 // An equally evil global system LColor instance
262 LColor system_lcolor;