1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2001 The LyX Team
8 *======================================================*/
14 #include "support/LAssert.h"
16 #include "support/lstrings.h"
20 using namespace lyx::support;
30 char const * latexname;
37 struct TransformEntry {
43 struct LColor::Pimpl {
46 /// the name as it appears in the GUI
48 /// the name used in LaTeX
56 /// initialise a color entry
57 void fill(ColorEntry const & entry)
60 in.lyxname = string(entry.lyxname);
61 in.latexname = string(entry.latexname);
62 in.x11name = string(entry.x11name);
63 in.guiname = string(entry.guiname);
64 infotab[entry.lcolor] = in;
65 transform[string(entry.lyxname)] = int(entry.lcolor);
69 typedef std::map<int, information> InfoTab;
70 /// the table of color information
73 typedef std::map<string, int> Transform;
74 /// the transform between colour name string and integer code.
83 // LColor::color, gui, latex, x11, lyx
84 static ColorEntry const items[] = {
85 { none, N_("none"), "none", "black", "none" },
86 { black, N_("black"), "black", "black", "black" },
87 { white, N_("white"), "white", "white", "white" },
88 { red, N_("red"), "red", "red", "red" },
89 { green, N_("green"), "green", "green", "green" },
90 { blue, N_("blue"), "blue", "blue", "blue" },
91 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
92 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
93 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
94 { cursor, N_("cursor"), "cursor", "black", "cursor" },
95 { background, N_("background"), "background", "linen", "background" },
96 { foreground, N_("text"), "foreground", "black", "foreground" },
97 { selection, N_("selection"), "selection", "LightBlue", "selection" },
98 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
99 { preview, N_("previewed snippet"), "preview", "black", "preview" },
100 { note, N_("note"), "note", "yellow", "note" },
101 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
102 { comment, N_("comment"), "comment", "magenta", "comment" },
103 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
104 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
105 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
106 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
107 { language, N_("language"), "language", "Blue", "language" },
108 { command, N_("command inset"), "command", "black", "command" },
109 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
110 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
111 { special, N_("special character"), "special", "RoyalBlue", "special" },
112 { math, N_("math"), "math", "DarkBlue", "math" },
113 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
114 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
115 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
116 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
117 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
118 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
119 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
120 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
121 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
122 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
123 { error, N_("LaTeX error"), "error", "Red", "error" },
124 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
125 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
126 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
127 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
128 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
129 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
130 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
131 { tabularline, N_("table line"), "tabularline", "black",
133 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
134 "LightSteelBlue", "tabularonoffline" },
135 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
136 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
137 { top, N_("top of button"), "top", "grey90", "top" },
138 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
139 { left, N_("left of button"), "left", "grey90", "left" },
140 { right, N_("right of button"), "right", "grey60", "right" },
141 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
142 { inherit, N_("inherit"), "inherit", "black", "inherit" },
143 { ignore, N_("ignore"), "ignore", "black", "ignore" },
144 { ignore, 0, 0, 0, 0 }
147 for (int i = 0; items[i].guiname; ++i)
148 pimpl_->fill(items[i]);
152 LColor::LColor(LColor const & c)
153 : pimpl_(new Pimpl(*c.pimpl_))
161 void LColor::operator=(LColor const & c)
164 boost::swap(pimpl_, tmp.pimpl_);
168 void LColor::fill(LColor::color c,
169 string const & lyxname,
170 string const & x11name,
171 string const & latexname,
172 string const & guiname)
176 ce.guiname = guiname.c_str();
177 ce.latexname = latexname.c_str();
178 ce.x11name = x11name.c_str();
179 ce.lyxname = lyxname.c_str();
184 string const LColor::getGUIName(LColor::color c) const
186 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
187 if (ici != pimpl_->infotab.end())
188 return _(ici->second.guiname);
193 string const LColor::getGUIName(string const & s) const
195 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
196 if (ici != pimpl_->transform.end()) {
197 Pimpl::InfoTab::const_iterator
198 it = pimpl_->infotab.find(ici->second);
199 if (it != pimpl_->infotab.end())
200 return it->second.guiname;
206 string const LColor::getX11Name(LColor::color c) const
208 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
209 if (ici != pimpl_->infotab.end())
210 return ici->second.x11name;
212 lyxerr << "LyX internal error: Missing color"
213 " entry in LColor.C for " << int(c) << endl;
214 lyxerr << "Using black." << endl;
219 string const LColor::getX11Name(string const & s) const
221 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
222 if (ici != pimpl_->transform.end()) {
223 Pimpl::InfoTab::const_iterator
224 it = pimpl_->infotab.find(ici->second);
225 if (it != pimpl_->infotab.end())
226 return it->second.x11name;
228 lyxerr << "LyX internal error: Missing color"
229 " entry in LColor.C for " << s << endl;
230 lyxerr << "Using black." << endl;
235 string const LColor::getLaTeXName(LColor::color c) const
237 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
238 if (ici != pimpl_->infotab.end())
239 return ici->second.latexname;
244 string const LColor::getLaTeXName(string const & s) const
246 Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
247 if (ici != pimpl_->transform.end()) {
248 Pimpl::InfoTab::const_iterator
249 it = pimpl_->infotab.find(ici->second);
250 if (it != pimpl_->infotab.end())
251 return it->second.latexname;
257 string const LColor::getLyXName(LColor::color c) const
259 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
260 if (ici != pimpl_->infotab.end())
261 return ici->second.lyxname;
266 size_t LColor::size() const
268 return pimpl_->infotab.size();
272 void LColor::setColor(LColor::color col, string const & x11name)
274 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
275 if (iti != pimpl_->infotab.end()) {
276 iti->second.x11name = x11name;
279 lyxerr << "LyX internal error: color and such." << endl;
284 bool LColor::setColor(string const & lyxname, string const & x11name)
286 color col = getFromLyXName(lyxname);
288 // "inherit" is returned for colors not in the database
289 // (and anyway should not be redefined)
290 if (col == inherit || col == ignore) {
291 lyxerr << "Color " << lyxname << " is undefined or may not be"
292 " redefined" << endl;
295 setColor(col, x11name);
300 LColor::color LColor::getFromGUIName(string const & guiname) const
302 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
303 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
304 for (; ici != end; ++ici) {
305 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
306 return static_cast<LColor::color>(ici->first);
308 return LColor::inherit;
312 LColor::color LColor::getFromLyXName(string const & lyxname) const
314 return static_cast<LColor::color>(pimpl_->transform[lyxname]);
318 // The evil global LColor instance
320 // An equally evil global system LColor instance
321 LColor system_lcolor;