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 { comment, N_("comment"), "comment", "magenta", "comment" },
91 { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
92 { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
93 { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
94 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
95 { language, N_("language"), "language", "Blue", "language" },
96 { command, N_("command inset"), "command", "black", "command" },
97 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
98 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
99 { special, N_("special character"), "special", "RoyalBlue", "special" },
100 { math, N_("math"), "math", "DarkBlue", "math" },
101 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
102 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
103 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
104 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
105 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
106 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
107 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
108 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
109 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
110 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
111 { error, N_("LaTeX error"), "error", "Red", "error" },
112 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
113 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
114 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
115 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
116 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
117 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
118 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
119 { tabularline, N_("table line"), "tabularline", "black",
121 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
122 "LightSteelBlue", "tabularonoffline" },
123 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
124 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
125 { top, N_("top of button"), "top", "grey90", "top" },
126 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
127 { left, N_("left of button"), "left", "grey90", "left" },
128 { right, N_("right of button"), "right", "grey60", "right" },
129 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
130 { inherit, N_("inherit"), "inherit", "black", "inherit" },
131 { ignore, N_("ignore"), "ignore", "black", "ignore" },
132 { ignore, 0, 0, 0, 0 }
135 for (int i = 0; items[i].guiname; ++i)
136 pimpl_->fill(items[i]);
140 LColor::LColor(LColor const & c)
141 : pimpl_(new Pimpl(*c.pimpl_))
151 void LColor::operator=(LColor const & c)
154 std::swap(pimpl_, tmp.pimpl_);
159 string const LColor::getGUIName(LColor::color c) const
161 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
162 if (ici != pimpl_->infotab.end())
163 return _(ici->second.guiname);
168 string const LColor::getX11Name(LColor::color c) const
170 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
171 if (ici != pimpl_->infotab.end())
172 return ici->second.x11name;
174 lyxerr << "LyX internal error: Missing color"
175 " entry in LColor.C for " << int(c) << endl;
176 lyxerr << "Using black." << endl;
181 string const LColor::getLaTeXName(LColor::color c) const
183 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
184 if (ici != pimpl_->infotab.end())
185 return ici->second.latexname;
190 string const LColor::getLyXName(LColor::color c) const
192 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
193 if (ici != pimpl_->infotab.end())
194 return ici->second.lyxname;
199 void LColor::setColor(LColor::color col, string const & x11name)
201 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
202 if (iti != pimpl_->infotab.end()) {
203 iti->second.x11name = x11name;
206 lyxerr << "LyX internal error: color and such." << endl;
211 bool LColor::setColor(string const & lyxname, string const & x11name)
213 color col = getFromLyXName(lyxname);
215 // "inherit" is returned for colors not in the database
216 // (and anyway should not be redefined)
217 if (col == inherit || col == ignore) {
218 lyxerr << "Color " << lyxname << " is undefined or may not be"
219 " redefined" << endl;
222 setColor (col, x11name);
227 LColor::color LColor::getFromGUIName(string const & guiname) const
229 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
230 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
231 for (; ici != end; ++ici) {
232 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
235 return LColor::inherit;
239 LColor::color LColor::getFromLyXName(string const & lyxname) const
241 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
242 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
243 for (; ici != end; ++ici) {
244 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
247 return LColor::inherit;
251 // The evil global LColor instance
253 // An equally evil global system LColor instance
254 LColor system_lcolor;