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.
21 #include "support/debug.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
25 #include "support/lassert.h"
34 using namespace lyx::support;
39 struct ColorSet::ColorEntry {
42 char const * latexname;
48 static int hexstrToInt(string const & str)
51 istringstream is(str);
52 is >> setbase(16) >> val;
57 /////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////
64 string const X11hexname(RGBColor const & col)
68 ostr << '#' << setbase(16) << setfill('0')
77 RGBColor rgbFromHexName(string const & x11hexname)
80 LASSERT(x11hexname.size() == 7 && x11hexname[0] == '#', /**/);
81 c.r = hexstrToInt(x11hexname.substr(1,2));
82 c.g = hexstrToInt(x11hexname.substr(3,2));
83 c.b = hexstrToInt(x11hexname.substr(5,2));
90 // ColorCode, gui, latex, x11, lyx
91 static ColorEntry const items[] = {
92 { Color_none, N_("none"), "none", "black", "none" },
93 { Color_black, N_("black"), "black", "black", "black" },
94 { Color_white, N_("white"), "white", "white", "white" },
95 { Color_red, N_("red"), "red", "red", "red" },
96 { Color_green, N_("green"), "green", "green", "green" },
97 { Color_blue, N_("blue"), "blue", "blue", "blue" },
98 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
99 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
100 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
101 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
102 { Color_background, N_("background"), "background", "linen", "background" },
103 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
104 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
105 { Color_selectiontext, N_("selected text"),
106 "selectiontext", "black", "selectiontext" },
107 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
108 { Color_inlinecompletion, N_("inline completion"),
109 "inlinecompletion", "grey60", "inlinecompletion" },
110 { Color_nonunique_inlinecompletion, N_("non-unique inline completion"),
111 "nonuniqueinlinecompletion", "grey80", "nonuniqueinlinecompletion" },
112 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
113 { Color_notelabel, N_("note label"), "note", "yellow", "note" },
114 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
115 { Color_commentlabel, N_("comment label"), "comment", "magenta", "comment" },
116 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
117 { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "greyedout" },
118 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
119 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
120 { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "branchlabel" },
121 { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", "footlabel" },
122 { Color_indexlabel, N_("index label"), "indexlabel", "green", "indexlabel" },
123 { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", "marginlabel" },
124 { Color_urllabel, N_("URL label"), "urllabel", "blue", "urllabel" },
125 { Color_urltext, N_("URL text"), "urltext", "blue", "urltext" },
126 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
127 { Color_language, N_("language"), "language", "Blue", "language" },
128 { Color_command, N_("command inset"), "command", "black", "command" },
129 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
130 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
131 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
132 { Color_math, N_("math"), "math", "DarkBlue", "math" },
133 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
134 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
135 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
136 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
137 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
138 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
139 { Color_mathmacrobg, N_("Math macro background"), "mathmacrobg", "#ede2d8", "mathmacrobg" },
140 { Color_mathmacrohoverbg, N_("Math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", "mathmacrohoverbg" },
141 { Color_mathmacrolabel, N_("Math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
142 { Color_mathmacroframe, N_("Math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
143 { Color_mathmacroblend, N_("Math macro blended out"), "mathmacroblend", "black", "mathmacroblend" },
144 { Color_mathmacrooldarg, N_("Math macro old parameter"), "mathmacrooldarg", "grey80", "mathmacrooldarg" },
145 { Color_mathmacronewarg, N_("Math macro new parameter"), "mathmacronewarg", "black", "mathmacronewarg" },
146 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
147 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
148 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
149 { Color_insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
150 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
151 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
152 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
153 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
154 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
155 { Color_deletedtext, N_("Deleted text"), "deletedtext", "#ff0000", "deletedtext" },
156 { Color_addedtext, N_("Added text"), "addedtext", "#0000ff", "addedtext" },
157 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
158 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
159 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
160 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
161 "LightSteelBlue", "tabularonoffline" },
162 { Color_bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
163 { Color_newpage, N_("new page"), "newpage", "Blue", "newpage" },
164 { Color_pagebreak, N_("page break / line break"), "pagebreak", "RoyalBlue", "pagebreak" },
165 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
166 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
167 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
168 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
169 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
170 { Color_ignore, 0, 0, 0, 0 }
173 for (int i = 0; items[i].guiname; ++i)
178 /// initialise a color entry
179 void ColorSet::fill(ColorEntry const & entry)
182 in.lyxname = entry.lyxname;
183 in.latexname = entry.latexname;
184 in.x11name = entry.x11name;
185 in.guiname = entry.guiname;
186 infotab[entry.lcolor] = in;
187 lyxcolors[entry.lyxname] = entry.lcolor;
188 latexcolors[entry.latexname] = entry.lcolor;
192 docstring const ColorSet::getGUIName(ColorCode c) const
194 InfoTab::const_iterator it = infotab.find(c);
195 if (it != infotab.end())
196 return _(it->second.guiname);
197 return from_ascii("none");
201 string const ColorSet::getX11Name(ColorCode c) const
203 InfoTab::const_iterator it = infotab.find(c);
204 if (it != infotab.end())
205 return it->second.x11name;
207 lyxerr << "LyX internal error: Missing color"
208 " entry in Color.cpp for " << c << '\n'
209 << "Using black." << endl;
214 string const ColorSet::getLaTeXName(ColorCode c) const
216 InfoTab::const_iterator it = infotab.find(c);
217 if (it != infotab.end())
218 return it->second.latexname;
223 string const ColorSet::getLyXName(ColorCode c) const
225 InfoTab::const_iterator it = infotab.find(c);
226 if (it != infotab.end())
227 return it->second.lyxname;
232 bool ColorSet::setColor(ColorCode col, string const & x11name)
234 InfoTab::iterator it = infotab.find(col);
235 if (it == infotab.end()) {
236 lyxerr << "Color " << col << " not found in database."
241 // "inherit" is returned for colors not in the database
242 // (and anyway should not be redefined)
243 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
244 lyxerr << "Color " << getLyXName(col)
245 << " may not be redefined" << endl;
249 it->second.x11name = x11name;
254 bool ColorSet::setColor(string const & lyxname, string const &x11name)
256 string const lcname = ascii_lowercase(lyxname);
257 if (lyxcolors.find(lcname) == lyxcolors.end()) {
258 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
260 addColor(static_cast<ColorCode>(infotab.size()), lcname);
263 return setColor(lyxcolors[lcname], x11name);
267 void ColorSet::addColor(ColorCode c, string const & lyxname)
269 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
274 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
276 string const lcname = ascii_lowercase(lyxname);
277 Transform::const_iterator it = lyxcolors.find(lcname);
278 if (it == lyxcolors.end()) {
279 lyxerr << "ColorSet::getFromLyXName: Unknown color \""
280 << lyxname << '"' << endl;
288 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
290 Transform::const_iterator it = latexcolors.find(latexname);
291 if (it == latexcolors.end()) {
292 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
293 << latexname << '"' << endl;
301 // The evil global Color instance
303 // An equally evil global system Color instance
304 ColorSet system_lcolor;