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.
22 #include "support/lstrings.h"
30 #ifndef CXX_GLOBAL_CSTD
38 using std::istringstream
;
39 using std::ostringstream
;
43 using lyx::support::compare_ascii_no_case
;
44 using lyx::support::ascii_lowercase
;
50 lyx::Color::color lcolor
;
52 char const * latexname
;
59 int hexstrToInt(string
const & str
)
62 istringstream
is(str
);
63 is
>> std::setbase(16) >> val
;
74 /////////////////////////////////////////////////////////////////////
78 /////////////////////////////////////////////////////////////////////
81 string
const X11hexname(RGBColor
const & col
)
85 ostr
<< '#' << std::setbase(16) << std::setfill('0')
94 RGBColor::RGBColor(string
const & x11hexname
)
97 BOOST_ASSERT(x11hexname
.size() == 7 && x11hexname
[0] == '#');
98 r
= hexstrToInt(x11hexname
.substr(1,2));
99 g
= hexstrToInt(x11hexname
.substr(3,2));
100 b
= hexstrToInt(x11hexname
.substr(5,2));
104 /////////////////////////////////////////////////////////////////////
108 /////////////////////////////////////////////////////////////////////
115 /// the name as it appears in the GUI
117 /// the name used in LaTeX
125 /// initialise a color entry
126 void fill(ColorEntry
const & entry
)
129 in
.lyxname
= entry
.lyxname
;
130 in
.latexname
= entry
.latexname
;
131 in
.x11name
= entry
.x11name
;
132 in
.guiname
= entry
.guiname
;
133 infotab
[entry
.lcolor
] = in
;
134 lyxcolors
[entry
.lyxname
] = entry
.lcolor
;
135 latexcolors
[entry
.latexname
] = entry
.lcolor
;
139 typedef std::map
<Color::color
, information
> InfoTab
;
140 /// the table of color information
143 typedef std::map
<string
, Color::color
> Transform
;
144 /// the transform between LyX color name string and integer code.
146 /// the transform between LaTeX color name string and integer code.
147 Transform latexcolors
;
155 // Color::color, gui, latex, x11, lyx
156 static ColorEntry
const items
[] = {
157 { none
, N_("none"), "none", "black", "none" },
158 { black
, N_("black"), "black", "black", "black" },
159 { white
, N_("white"), "white", "white", "white" },
160 { red
, N_("red"), "red", "red", "red" },
161 { green
, N_("green"), "green", "green", "green" },
162 { blue
, N_("blue"), "blue", "blue", "blue" },
163 { cyan
, N_("cyan"), "cyan", "cyan", "cyan" },
164 { magenta
, N_("magenta"), "magenta", "magenta", "magenta" },
165 { yellow
, N_("yellow"), "yellow", "yellow", "yellow" },
166 { cursor
, N_("cursor"), "cursor", "black", "cursor" },
167 { background
, N_("background"), "background", "linen", "background" },
168 { foreground
, N_("text"), "foreground", "black", "foreground" },
169 { selection
, N_("selection"), "selection", "LightBlue", "selection" },
170 { latex
, N_("LaTeX text"), "latex", "DarkRed", "latex" },
171 { preview
, N_("previewed snippet"), "preview", "black", "preview" },
172 { note
, N_("note"), "note", "blue", "note" },
173 { notebg
, N_("note background"), "notebg", "yellow", "notebg" },
174 { comment
, N_("comment"), "comment", "magenta", "comment" },
175 { commentbg
, N_("comment background"), "commentbg", "linen", "commentbg" },
176 { greyedout
, N_("greyedout inset"), "greyedout", "red", "greyedout" },
177 { greyedoutbg
, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
178 { shadedbg
, N_("shaded box"), "shaded", "#ff0000", "shaded" },
179 { depthbar
, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
180 { language
, N_("language"), "language", "Blue", "language" },
181 { command
, N_("command inset"), "command", "black", "command" },
182 { commandbg
, N_("command inset background"), "commandbg", "azure", "commandbg" },
183 { commandframe
, N_("command inset frame"), "commandframe", "black", "commandframe" },
184 { special
, N_("special character"), "special", "RoyalBlue", "special" },
185 { math
, N_("math"), "math", "DarkBlue", "math" },
186 { mathbg
, N_("math background"), "mathbg", "linen", "mathbg" },
187 { graphicsbg
, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
188 { mathmacrobg
, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
189 { mathframe
, N_("math frame"), "mathframe", "Magenta", "mathframe" },
190 { mathcorners
, N_("math corners"), "mathcorners", "linen", "mathcorners" },
191 { mathline
, N_("math line"), "mathline", "Blue", "mathline" },
192 { captionframe
, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
193 { collapsable
, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
194 { collapsableframe
, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
195 { insetbg
, N_("inset background"), "insetbg", "grey80", "insetbg" },
196 { insetframe
, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
197 { error
, N_("LaTeX error"), "error", "Red", "error" },
198 { eolmarker
, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
199 { appendix
, N_("appendix marker"), "appendix", "Brown", "appendix" },
200 { changebar
, N_("change bar"), "changebar", "Blue", "changebar" },
201 { deletedtext
, N_("Deleted text"), "deletedtext", "#ff0000", "deletedtext" },
202 { addedtext
, N_("Added text"), "addedtext", "#0000ff", "addedtext" },
203 { added_space
, N_("added space markers"), "added_space", "Brown", "added_space" },
204 { topline
, N_("top/bottom line"), "topline", "Brown", "topline" },
205 { tabularline
, N_("table line"), "tabularline", "black", "tabularline" },
206 { tabularonoffline
, N_("table on/off line"), "tabularonoffline",
207 "LightSteelBlue", "tabularonoffline" },
208 { bottomarea
, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
209 { pagebreak
, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
210 { buttonframe
, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
211 { buttonbg
, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" },
212 { buttonhoverbg
, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" },
213 { inherit
, N_("inherit"), "inherit", "black", "inherit" },
214 { ignore
, N_("ignore"), "ignore", "black", "ignore" },
215 { ignore
, 0, 0, 0, 0 }
218 for (int i
= 0; items
[i
].guiname
; ++i
)
219 pimpl_
->fill(items
[i
]);
223 Color::Color(Color
const & c
)
224 : pimpl_(new Pimpl(*c
.pimpl_
))
232 Color
& Color::operator=(Color tmp
)
234 boost::swap(pimpl_
, tmp
.pimpl_
);
239 docstring
const Color::getGUIName(Color::color c
) const
241 Pimpl::InfoTab::const_iterator it
= pimpl_
->infotab
.find(c
);
242 if (it
!= pimpl_
->infotab
.end())
243 return _(it
->second
.guiname
);
244 return from_ascii("none");
248 string
const Color::getX11Name(Color::color c
) const
250 Pimpl::InfoTab::const_iterator it
= pimpl_
->infotab
.find(c
);
251 if (it
!= pimpl_
->infotab
.end())
252 return it
->second
.x11name
;
254 lyxerr
<< "LyX internal error: Missing color"
255 " entry in Color.cpp for " << c
<< '\n'
256 << "Using black." << endl
;
261 string
const Color::getLaTeXName(Color::color c
) const
263 Pimpl::InfoTab::const_iterator it
= pimpl_
->infotab
.find(c
);
264 if (it
!= pimpl_
->infotab
.end())
265 return it
->second
.latexname
;
270 string
const Color::getLyXName(Color::color c
) const
272 Pimpl::InfoTab::const_iterator it
= pimpl_
->infotab
.find(c
);
273 if (it
!= pimpl_
->infotab
.end())
274 return it
->second
.lyxname
;
279 bool Color::setColor(Color::color col
, string
const & x11name
)
281 Pimpl::InfoTab::iterator it
= pimpl_
->infotab
.find(col
);
282 if (it
== pimpl_
->infotab
.end()) {
283 lyxerr
<< "Color " << col
<< " not found in database."
288 // "inherit" is returned for colors not in the database
289 // (and anyway should not be redefined)
290 if (col
== none
|| col
== inherit
|| col
== ignore
) {
291 lyxerr
<< "Color " << getLyXName(col
)
292 << " may not be redefined" << endl
;
296 it
->second
.x11name
= x11name
;
301 bool Color::setColor(string
const & lyxname
, string
const &x11name
)
303 string
const lcname
= ascii_lowercase(lyxname
);
304 if (pimpl_
->lyxcolors
.find(lcname
) == pimpl_
->lyxcolors
.end()) {
306 << "Color::setColor: Unknown color \""
307 << lyxname
<< '"' << endl
;
308 addColor(static_cast<color
>(pimpl_
->infotab
.size()), lcname
);
311 return setColor(pimpl_
->lyxcolors
[lcname
], x11name
);
315 void Color::addColor(Color::color c
, string
const & lyxname
) const
317 ColorEntry ce
= { c
, "", "", "", lyxname
.c_str() };
322 Color::color
Color::getFromLyXName(string
const & lyxname
) const
324 string
const lcname
= ascii_lowercase(lyxname
);
325 if (pimpl_
->lyxcolors
.find(lcname
) == pimpl_
->lyxcolors
.end()) {
326 lyxerr
<< "Color::getFromLyXName: Unknown color \""
327 << lyxname
<< '"' << endl
;
331 return pimpl_
->lyxcolors
[lcname
];
335 Color::color
Color::getFromLaTeXName(string
const & latexname
) const
337 if (pimpl_
->latexcolors
.find(latexname
) == pimpl_
->latexcolors
.end()) {
338 lyxerr
<< "Color::getFromLaTeXName: Unknown color \""
339 << latexname
<< '"' << endl
;
343 return pimpl_
->latexcolors
[latexname
];
347 // The evil global Color instance
349 // An equally evil global system Color instance