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"
24 #include "support/lassert.h"
33 using namespace lyx::support;
38 struct ColorSet::ColorEntry {
41 char const * latexname;
47 static int hexstrToInt(string const & str)
50 istringstream is(str);
51 is >> setbase(16) >> val;
56 /////////////////////////////////////////////////////////////////////
60 /////////////////////////////////////////////////////////////////////
63 string const X11hexname(RGBColor const & col)
67 ostr << '#' << setbase(16) << setfill('0')
76 RGBColor rgbFromHexName(string const & x11hexname)
79 LASSERT(x11hexname.size() == 7 && x11hexname[0] == '#', /**/);
80 c.r = hexstrToInt(x11hexname.substr(1, 2));
81 c.g = hexstrToInt(x11hexname.substr(3, 2));
82 c.b = hexstrToInt(x11hexname.substr(5, 2));
87 Color::Color(ColorCode base_color) : baseColor(base_color),
88 mergeColor(Color_ignore)
92 bool Color::operator==(Color const & color) const
94 return baseColor == color.baseColor;
98 bool Color::operator!=(Color const & color) const
100 return baseColor != color.baseColor;
104 bool Color::operator<(Color const & color) const
106 return baseColor < color.baseColor;
110 bool Color::operator<=(Color const & color) const
112 return baseColor <= color.baseColor;
116 std::ostream & operator<<(std::ostream & os, Color color)
118 os << to_ascii(lcolor.getGUIName(color.baseColor));
119 if (color.mergeColor != Color_ignore)
120 os << "[merged with:"
121 << to_ascii(lcolor.getGUIName(color.mergeColor)) << "]";
128 char const * grey40 = "#666666";
129 char const * grey60 = "#999999";
130 char const * grey80 = "#cccccc";
131 //char const * grey90 = "#e5e5e5";
132 // ColorCode, gui, latex, x11, lyx
133 static ColorEntry const items[] = {
134 { Color_none, N_("none"), "none", "black", "none" },
135 { Color_black, N_("black"), "black", "black", "black" },
136 { Color_white, N_("white"), "white", "white", "white" },
137 { Color_red, N_("red"), "red", "red", "red" },
138 { Color_green, N_("green"), "green", "green", "green" },
139 { Color_blue, N_("blue"), "blue", "blue", "blue" },
140 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
141 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
142 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
143 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
144 { Color_background, N_("background"), "background", "linen", "background" },
145 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
146 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
147 { Color_selectiontext, N_("selected text"),
148 "selectiontext", "black", "selectiontext" },
149 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
150 { Color_inlinecompletion, N_("inline completion"),
151 "inlinecompletion", grey60, "inlinecompletion" },
152 { Color_nonunique_inlinecompletion, N_("non-unique inline completion"),
153 "nonuniqueinlinecompletion", grey80, "nonuniqueinlinecompletion" },
154 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
155 { Color_notelabel, N_("note label"), "note", "yellow", "note" },
156 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
157 { Color_commentlabel, N_("comment label"), "comment", "magenta", "comment" },
158 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
159 { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "greyedout" },
160 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
161 { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "phantomtext" },
162 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
163 { Color_listingsbg, N_("listings background"), "listingsbg", "white", "listingsbg" },
164 { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "branchlabel" },
165 { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", "footlabel" },
166 { Color_indexlabel, N_("index label"), "indexlabel", "green", "indexlabel" },
167 { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", "marginlabel" },
168 { Color_urllabel, N_("URL label"), "urllabel", "blue", "urllabel" },
169 { Color_urltext, N_("URL text"), "urltext", "blue", "urltext" },
170 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
171 { Color_language, N_("language"), "language", "Blue", "language" },
172 { Color_command, N_("command inset"), "command", "black", "command" },
173 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
174 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
175 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
176 { Color_math, N_("math"), "math", "DarkBlue", "math" },
177 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
178 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
179 { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
180 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
181 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
182 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
183 { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "#ede2d8", "mathmacrobg" },
184 { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", "mathmacrohoverbg" },
185 { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
186 { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
187 { Color_mathmacroblend, N_("math macro blended out"), "mathmacroblend", "black", "mathmacroblend" },
188 { Color_mathmacrooldarg, N_("math macro old parameter"), "mathmacrooldarg", grey80, "mathmacrooldarg" },
189 { Color_mathmacronewarg, N_("math macro new parameter"), "mathmacronewarg", "black", "mathmacronewarg" },
190 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
191 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
192 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
193 { Color_insetbg, N_("inset background"), "insetbg", grey80, "insetbg" },
194 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
195 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
196 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
197 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
198 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
199 { Color_deletedtext, N_("deleted text"), "deletedtext", "#ff0000", "deletedtext" },
200 { Color_addedtext, N_("added text"), "addedtext", "#0000ff", "addedtext" },
201 { Color_changedtextauthor1, N_("changed text 1st author"), "changedtextauthor1", "#0000ff", "changedtextauthor1" },
202 { Color_changedtextauthor2, N_("changed text 2nd author"), "changedtextauthor2", "#ff00ff", "changedtextauthor2" },
203 { Color_changedtextauthor3, N_("changed text 3rd author"), "changedtextauthor3", "#ff0000", "changedtextauthor3" },
204 { Color_changedtextauthor4, N_("changed text 4th author"), "changedtextauthor4", "#aa00ff", "changedtextauthor4" },
205 { Color_changedtextauthor5, N_("changed text 5th author"), "changedtextauthor5", "#55aa00", "changedtextauthor5" },
206 { Color_deletedtextmodifier, N_("deleted text modifier"), "deletedtextmodifier", "white", "deletedtextmodifier" },
207 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
208 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
209 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
210 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
211 "LightSteelBlue", "tabularonoffline" },
212 { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, "bottomarea" },
213 { Color_newpage, N_("new page"), "newpage", "Blue", "newpage" },
214 { Color_pagebreak, N_("page break / line break"), "pagebreak", "RoyalBlue", "pagebreak" },
215 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
216 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
217 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
218 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
219 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
220 { Color_ignore, 0, 0, 0, 0 }
223 for (int i = 0; items[i].guiname; ++i)
228 /// initialise a color entry
229 void ColorSet::fill(ColorEntry const & entry)
232 in.lyxname = entry.lyxname;
233 in.latexname = entry.latexname;
234 in.x11name = entry.x11name;
235 in.guiname = entry.guiname;
236 infotab[entry.lcolor] = in;
237 lyxcolors[entry.lyxname] = entry.lcolor;
238 latexcolors[entry.latexname] = entry.lcolor;
242 docstring const ColorSet::getGUIName(ColorCode c) const
244 InfoTab::const_iterator it = infotab.find(c);
245 if (it != infotab.end())
246 return _(it->second.guiname);
247 return from_ascii("none");
251 string const ColorSet::getX11Name(ColorCode c) const
253 InfoTab::const_iterator it = infotab.find(c);
254 if (it != infotab.end())
255 return it->second.x11name;
257 lyxerr << "LyX internal error: Missing color"
258 " entry in Color.cpp for " << c << '\n'
259 << "Using black." << endl;
264 string const ColorSet::getLaTeXName(ColorCode c) const
266 InfoTab::const_iterator it = infotab.find(c);
267 if (it != infotab.end())
268 return it->second.latexname;
273 string const ColorSet::getLyXName(ColorCode c) const
275 InfoTab::const_iterator it = infotab.find(c);
276 if (it != infotab.end())
277 return it->second.lyxname;
282 bool ColorSet::setColor(ColorCode col, string const & x11name)
284 InfoTab::iterator it = infotab.find(col);
285 if (it == infotab.end()) {
286 LYXERR0("Color " << col << " not found in database.");
290 // "inherit" is returned for colors not in the database
291 // (and anyway should not be redefined)
292 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
293 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
297 it->second.x11name = x11name;
302 bool ColorSet::setColor(string const & lyxname, string const &x11name)
304 string const lcname = ascii_lowercase(lyxname);
305 if (lyxcolors.find(lcname) == lyxcolors.end()) {
306 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
308 addColor(static_cast<ColorCode>(infotab.size()), lcname);
311 return setColor(lyxcolors[lcname], x11name);
315 void ColorSet::addColor(ColorCode c, string const & lyxname)
317 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
322 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
324 string const lcname = ascii_lowercase(lyxname);
325 Transform::const_iterator it = lyxcolors.find(lcname);
326 if (it == lyxcolors.end()) {
327 LYXERR0("ColorSet::getFromLyXName: Unknown color \""
336 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
338 Transform::const_iterator it = latexcolors.find(latexname);
339 if (it == latexcolors.end()) {
340 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
341 << latexname << '"' << endl;
349 // The evil global Color instance
351 // An equally evil global system Color instance
352 ColorSet system_lcolor;