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));
89 char const * grey40 = "#666666";
90 char const * grey60 = "#999999";
91 char const * grey80 = "#cccccc";
92 //char const * grey90 = "#e5e5e5";
93 // ColorCode, gui, latex, x11, lyx
94 static ColorEntry const items[] = {
95 { Color_none, N_("none"), "none", "black", "none" },
96 { Color_black, N_("black"), "black", "black", "black" },
97 { Color_white, N_("white"), "white", "white", "white" },
98 { Color_red, N_("red"), "red", "red", "red" },
99 { Color_green, N_("green"), "green", "green", "green" },
100 { Color_blue, N_("blue"), "blue", "blue", "blue" },
101 { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" },
102 { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" },
103 { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" },
104 { Color_cursor, N_("cursor"), "cursor", "black", "cursor" },
105 { Color_background, N_("background"), "background", "linen", "background" },
106 { Color_foreground, N_("text"), "foreground", "black", "foreground" },
107 { Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
108 { Color_selectiontext, N_("selected text"),
109 "selectiontext", "black", "selectiontext" },
110 { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
111 { Color_inlinecompletion, N_("inline completion"),
112 "inlinecompletion", grey60, "inlinecompletion" },
113 { Color_nonunique_inlinecompletion, N_("non-unique inline completion"),
114 "nonuniqueinlinecompletion", grey80, "nonuniqueinlinecompletion" },
115 { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
116 { Color_notelabel, N_("note label"), "note", "yellow", "note" },
117 { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
118 { Color_commentlabel, N_("comment label"), "comment", "magenta", "comment" },
119 { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
120 { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "greyedout" },
121 { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
122 { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "phantomtext" },
123 { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
124 { Color_listingsbg, N_("listings background"), "listingsbg", "white", "listingsbg" },
125 { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "branchlabel" },
126 { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", "footlabel" },
127 { Color_indexlabel, N_("index label"), "indexlabel", "green", "indexlabel" },
128 { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", "marginlabel" },
129 { Color_urllabel, N_("URL label"), "urllabel", "blue", "urllabel" },
130 { Color_urltext, N_("URL text"), "urltext", "blue", "urltext" },
131 { Color_depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
132 { Color_language, N_("language"), "language", "Blue", "language" },
133 { Color_command, N_("command inset"), "command", "black", "command" },
134 { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
135 { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
136 { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
137 { Color_math, N_("math"), "math", "DarkBlue", "math" },
138 { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
139 { Color_graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
140 { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
141 { Color_mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
142 { Color_mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
143 { Color_mathline, N_("math line"), "mathline", "Blue", "mathline" },
144 { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "#ede2d8", "mathmacrobg" },
145 { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", "mathmacrohoverbg" },
146 { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
147 { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
148 { Color_mathmacroblend, N_("math macro blended out"), "mathmacroblend", "black", "mathmacroblend" },
149 { Color_mathmacrooldarg, N_("math macro old parameter"), "mathmacrooldarg", grey80, "mathmacrooldarg" },
150 { Color_mathmacronewarg, N_("math macro new parameter"), "mathmacronewarg", "black", "mathmacronewarg" },
151 { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
152 { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
153 { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
154 { Color_insetbg, N_("inset background"), "insetbg", grey80, "insetbg" },
155 { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
156 { Color_error, N_("LaTeX error"), "error", "Red", "error" },
157 { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
158 { Color_appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
159 { Color_changebar, N_("change bar"), "changebar", "Blue", "changebar" },
160 { Color_deletedtext, N_("deleted text"), "deletedtext", "#ff0000", "deletedtext" },
161 { Color_addedtext, N_("added text"), "addedtext", "#0000ff", "addedtext" },
162 { Color_changedtextauthor1, N_("changed text 1st author"), "changedtextauthor1", "#0000ff", "changedtextauthor1" },
163 { Color_changedtextauthor2, N_("changed text 2nd author"), "changedtextauthor2", "#ff00ff", "changedtextauthor2" },
164 { Color_changedtextauthor3, N_("changed text 3rd author"), "changedtextauthor3", "#ff0000", "changedtextauthor3" },
165 { Color_changedtextauthor4, N_("changed text 4th author"), "changedtextauthor4", "#aa00ff", "changedtextauthor4" },
166 { Color_changedtextauthor5, N_("changed text 5th author"), "changedtextauthor5", "#55aa00", "changedtextauthor5" },
167 { Color_added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
168 { Color_topline, N_("top/bottom line"), "topline", "Brown", "topline" },
169 { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
170 { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
171 "LightSteelBlue", "tabularonoffline" },
172 { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, "bottomarea" },
173 { Color_newpage, N_("new page"), "newpage", "Blue", "newpage" },
174 { Color_pagebreak, N_("page break / line break"), "pagebreak", "RoyalBlue", "pagebreak" },
175 { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
176 { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
177 { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
178 { Color_inherit, N_("inherit"), "inherit", "black", "inherit" },
179 { Color_ignore, N_("ignore"), "ignore", "black", "ignore" },
180 { Color_ignore, 0, 0, 0, 0 }
183 for (int i = 0; items[i].guiname; ++i)
188 /// initialise a color entry
189 void ColorSet::fill(ColorEntry const & entry)
192 in.lyxname = entry.lyxname;
193 in.latexname = entry.latexname;
194 in.x11name = entry.x11name;
195 in.guiname = entry.guiname;
196 infotab[entry.lcolor] = in;
197 lyxcolors[entry.lyxname] = entry.lcolor;
198 latexcolors[entry.latexname] = entry.lcolor;
202 docstring const ColorSet::getGUIName(ColorCode c) const
204 InfoTab::const_iterator it = infotab.find(c);
205 if (it != infotab.end())
206 return _(it->second.guiname);
207 return from_ascii("none");
211 string const ColorSet::getX11Name(ColorCode c) const
213 InfoTab::const_iterator it = infotab.find(c);
214 if (it != infotab.end())
215 return it->second.x11name;
217 lyxerr << "LyX internal error: Missing color"
218 " entry in Color.cpp for " << c << '\n'
219 << "Using black." << endl;
224 string const ColorSet::getLaTeXName(ColorCode c) const
226 InfoTab::const_iterator it = infotab.find(c);
227 if (it != infotab.end())
228 return it->second.latexname;
233 string const ColorSet::getLyXName(ColorCode c) const
235 InfoTab::const_iterator it = infotab.find(c);
236 if (it != infotab.end())
237 return it->second.lyxname;
242 bool ColorSet::setColor(ColorCode col, string const & x11name)
244 InfoTab::iterator it = infotab.find(col);
245 if (it == infotab.end()) {
246 LYXERR0("Color " << col << " not found in database.");
250 // "inherit" is returned for colors not in the database
251 // (and anyway should not be redefined)
252 if (col == Color_none || col == Color_inherit || col == Color_ignore) {
253 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
257 it->second.x11name = x11name;
262 bool ColorSet::setColor(string const & lyxname, string const &x11name)
264 string const lcname = ascii_lowercase(lyxname);
265 if (lyxcolors.find(lcname) == lyxcolors.end()) {
266 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
268 addColor(static_cast<ColorCode>(infotab.size()), lcname);
271 return setColor(lyxcolors[lcname], x11name);
275 void ColorSet::addColor(ColorCode c, string const & lyxname)
277 ColorEntry ce = { c, "", "", "", lyxname.c_str() };
282 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
284 string const lcname = ascii_lowercase(lyxname);
285 Transform::const_iterator it = lyxcolors.find(lcname);
286 if (it == lyxcolors.end()) {
287 LYXERR0("ColorSet::getFromLyXName: Unknown color \""
296 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
298 Transform::const_iterator it = latexcolors.find(latexname);
299 if (it == latexcolors.end()) {
300 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
301 << latexname << '"' << endl;
309 // The evil global Color instance
311 // An equally evil global system Color instance
312 ColorSet system_lcolor;