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;
38 struct LColor::Pimpl {
41 /// the name as it appears in the GUI
43 /// the name used in LaTeX
51 /// initialise a color entry
52 void fill(ColorEntry const & entry)
54 information & in = infotab[entry.lcolor];
55 in.guiname = entry.guiname;
56 in.latexname = entry.latexname;
57 in.x11name = entry.x11name;
58 in.lyxname = entry.lyxname;
62 typedef std::map<LColor::color, information> InfoTab;
63 /// the table of color information
71 // LColor::color, gui, latex, x11, lyx
72 static ColorEntry const items[] = {
73 { none, N_("none"), "none", "black", "none" },
74 { black, N_("black"), "black", "black", "black" },
75 { white, N_("white"), "white", "white", "white" },
76 { red, N_("red"), "red", "red", "red" },
77 { green, N_("green"), "green", "green", "green" },
78 { blue, N_("blue"), "blue", "blue", "blue" },
79 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
80 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
81 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
82 { cursor, N_("cursor"), "cursor", "black", "cursor" },
83 { background, N_("background"), "background", "linen", "background" },
84 { foreground, N_("text"), "foreground", "black", "foreground" },
85 { selection, N_("selection"), "selection", "LightBlue", "selection" },
86 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
87 { preview, N_("previewed snippet"), "preview", "black", "preview" },
88 { note, N_("note"), "note", "yellow", "note" },
89 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
90 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
91 { language, N_("language"), "language", "Blue", "language" },
92 { command, N_("command inset"), "command", "black", "command" },
93 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
94 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
95 { special, N_("special character"), "special", "RoyalBlue", "special" },
96 { math, N_("math"), "math", "DarkBlue", "math" },
97 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
98 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
99 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
100 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
101 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
102 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
103 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
104 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
105 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
106 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
107 { error, N_("LaTeX error"), "error", "Red", "error" },
108 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
109 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
110 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
111 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
112 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
113 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
114 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
115 { tabularline, N_("table line"), "tabularline", "black",
117 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
118 "LightSteelBlue", "tabularonoffline" },
119 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
120 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
121 { top, N_("top of button"), "top", "grey90", "top" },
122 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
123 { left, N_("left of button"), "left", "grey90", "left" },
124 { right, N_("right of button"), "right", "grey60", "right" },
125 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
126 { inherit, N_("inherit"), "inherit", "black", "inherit" },
127 { ignore, N_("ignore"), "ignore", "black", "ignore" },
128 { ignore, 0, 0, 0, 0 }
131 for (int i = 0; items[i].guiname; ++i)
132 pimpl_->fill(items[i]);
136 LColor::LColor(LColor const & c)
137 : pimpl_(new Pimpl(*c.pimpl_))
147 void LColor::operator=(LColor const & c)
150 std::swap(pimpl_, tmp.pimpl_);
155 string const LColor::getGUIName(LColor::color c) const
157 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
158 if (ici != pimpl_->infotab.end())
159 return _(ici->second.guiname);
164 string const LColor::getX11Name(LColor::color c) const
166 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
167 if (ici != pimpl_->infotab.end())
168 return ici->second.x11name;
170 lyxerr << "LyX internal error: Missing color"
171 " entry in LColor.C for " << int(c) << '\n';
172 lyxerr << "Using black.\n";
177 string const LColor::getLaTeXName(LColor::color c) const
179 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
180 if (ici != pimpl_->infotab.end())
181 return ici->second.latexname;
186 string const LColor::getLyXName(LColor::color c) const
188 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
189 if (ici != pimpl_->infotab.end())
190 return ici->second.lyxname;
195 void LColor::setColor(LColor::color col, string const & x11name)
197 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
198 if (iti != pimpl_->infotab.end()) {
199 iti->second.x11name = x11name;
202 lyxerr << "LyX internal error: color and such.\n";
207 bool LColor::setColor(string const & lyxname, string const & x11name)
209 color col = getFromLyXName(lyxname);
211 // "inherit" is returned for colors not in the database
212 // (and anyway should not be redefined)
213 if (col == inherit || col == ignore) {
214 lyxerr << "Color " << lyxname << " is undefined or may not be"
215 " redefined" << endl;
218 setColor (col, x11name);
223 LColor::color LColor::getFromGUIName(string const & guiname) const
225 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
226 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
227 for (; ici != end; ++ici) {
228 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
231 return LColor::inherit;
235 LColor::color LColor::getFromLyXName(string const & lyxname) const
237 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
238 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
239 for (; ici != end; ++ici) {
240 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
243 return LColor::inherit;
247 // The evil global LColor instance
249 // An equally evil global system LColor instance
250 LColor system_lcolor;