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"
28 char const * latexname;
36 struct LColor::Pimpl {
39 /// the name as it appears in the GUI
41 /// the name used in LaTeX
49 /// initialise a color entry
50 void fill(ColorEntry const & entry)
52 information & in = infotab[entry.lcolor];
53 in.guiname = entry.guiname;
54 in.latexname = entry.latexname;
55 in.x11name = entry.x11name;
56 in.lyxname = entry.lyxname;
60 typedef std::map<LColor::color, information> InfoTab;
61 /// the table of color information
69 // LColor::color, gui, latex, x11, lyx
70 static ColorEntry const items[] = {
71 { none, N_("none"), "none", "black", "none" },
72 { black, N_("black"), "black", "black", "black" },
73 { white, N_("white"), "white", "white", "white" },
74 { red, N_("red"), "red", "red", "red" },
75 { green, N_("green"), "green", "green", "green" },
76 { blue, N_("blue"), "blue", "blue", "blue" },
77 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
78 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
79 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
80 { cursor, N_("cursor"), "cursor", "black", "cursor" },
81 { background, N_("background"), "background", "linen", "background" },
82 { foreground, N_("text"), "foreground", "black", "foreground" },
83 { selection, N_("selection"), "selection", "LightBlue", "selection" },
84 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
85 { preview, N_("previewed snippet"), "preview", "black", "preview" },
86 { note, N_("note"), "note", "yellow", "note" },
87 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
88 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
89 { language, N_("language"), "language", "Blue", "language" },
90 { command, N_("command inset"), "command", "black", "command" },
91 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
92 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
93 { special, N_("special character"), "special", "RoyalBlue", "special" },
94 { math, N_("math"), "math", "DarkBlue", "math" },
95 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
96 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
97 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
98 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
99 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
100 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
101 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
102 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
103 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
104 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
105 { error, N_("LaTeX error"), "error", "Red", "error" },
106 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
107 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
108 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
109 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
110 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
111 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
112 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
113 { tabularline, N_("table line"), "tabularline", "black",
115 { tabularonoffline, N_("table on/off line"), "tabularonoffline",
116 "LightSteelBlue", "tabularonoffline" },
117 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
118 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
119 { top, N_("top of button"), "top", "grey90", "top" },
120 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
121 { left, N_("left of button"), "left", "grey90", "left" },
122 { right, N_("right of button"), "right", "grey60", "right" },
123 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
124 { inherit, N_("inherit"), "inherit", "black", "inherit" },
125 { ignore, N_("ignore"), "ignore", "black", "ignore" },
126 { ignore, 0, 0, 0, 0 }
129 for (int i = 0; items[i].guiname; ++i)
130 pimpl_->fill(items[i]);
134 LColor::LColor(LColor const & c)
135 : pimpl_(new Pimpl(*c.pimpl_))
145 void LColor::operator=(LColor const & c)
148 std::swap(pimpl_, tmp.pimpl_);
153 string const LColor::getGUIName(LColor::color c) const
155 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
156 if (ici != pimpl_->infotab.end())
157 return _(ici->second.guiname);
162 string const LColor::getX11Name(LColor::color c) const
164 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
165 if (ici != pimpl_->infotab.end())
166 return ici->second.x11name;
168 lyxerr << "LyX internal error: Missing color"
169 " entry in LColor.C for " << int(c) << '\n';
170 lyxerr << "Using black.\n";
175 string const LColor::getLaTeXName(LColor::color c) const
177 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
178 if (ici != pimpl_->infotab.end())
179 return ici->second.latexname;
184 string const LColor::getLyXName(LColor::color c) const
186 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
187 if (ici != pimpl_->infotab.end())
188 return ici->second.lyxname;
193 void LColor::setColor(LColor::color col, string const & x11name)
195 Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
196 if (iti != pimpl_->infotab.end()) {
197 iti->second.x11name = x11name;
200 lyxerr << "LyX internal error: color and such.\n";
205 bool LColor::setColor(string const & lyxname, string const & x11name)
207 color col = getFromLyXName(lyxname);
209 // "inherit" is returned for colors not in the database
210 // (and anyway should not be redefined)
211 if (col == inherit || col == ignore) {
212 lyxerr << "Color " << lyxname << " is undefined or may not be"
213 " redefined" << endl;
216 setColor (col, x11name);
221 LColor::color LColor::getFromGUIName(string const & guiname) const
223 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
224 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
225 for (; ici != end; ++ici) {
226 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
229 return LColor::inherit;
233 LColor::color LColor::getFromLyXName(string const & lyxname) const
235 Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
236 Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
237 for (; ici != end; ++ici) {
238 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
241 return LColor::inherit;
245 // The evil global LColor instance
247 // An equally evil global system LColor instance
248 LColor system_lcolor;