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"
20 void LColor::fill(LColor::color col, string const & gui,
21 string const & latex, string const & x11,
35 char const * latexname;
43 // LColor::color, gui, latex, x11, lyx
44 ColorEntry items[] = {
45 { none, N_("none"), "none", "black", "none" },
46 { black, N_("black"), "black", "black", "black" },
47 { white, N_("white"), "white", "white", "white" },
48 { red, N_("red"), "red", "red", "red" },
49 { green, N_("green"), "green", "green", "green" },
50 { blue, N_("blue"), "blue", "blue", "blue" },
51 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
52 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
53 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
54 { cursor, N_("cursor"), "cursor", "black", "cursor" },
55 { background, N_("background"), "background", "linen", "background" },
56 { foreground, N_("text"), "foreground", "black", "foreground" },
57 { selection, N_("selection"), "selection", "LightBlue", "selection" },
58 { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
59 { preview, N_("previewed snippet"), "preview", "black", "preview" },
60 { note, N_("note"), "note", "yellow", "note" },
61 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
62 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
63 { language, N_("language"), "language", "Blue", "language" },
64 { command, N_("command inset"), "command", "black", "command" },
65 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
66 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
67 { special, N_("special character"), "special", "RoyalBlue", "special" },
68 { math, N_("math"), "math", "DarkBlue", "math" },
69 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
70 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
71 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
72 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
73 { mathcursor, N_("math cursor"), "mathcursor", "black", "mathcursor" },
74 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
75 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
76 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
77 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
78 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
79 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
80 { error, N_("LaTeX error"), "error", "Red", "error" },
81 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
82 { appendixline, N_("appendix line"), "appendixline", "Brown", "appendixline" },
83 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
84 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
85 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
86 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
87 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
88 { tabularline, N_("tabular line"), "tabularline", "black",
90 { tabularonoffline, N_("tabular on/off line"), "tabularonoffline",
91 "LightSteelBlue", "tabularonoffline" },
92 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
93 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
94 { top, N_("top of button"), "top", "grey90", "top" },
95 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
96 { left, N_("left of button"), "left", "grey90", "left" },
97 { right, N_("right of button"), "right", "grey60", "right" },
98 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
99 { inherit, N_("inherit"), "inherit", "black", "inherit" },
100 { ignore, N_("ignore"), "ignore", "black", "ignore" },
101 { ignore, 0, 0, 0, 0 }
105 while (items[i].guiname) {
106 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
107 items[i].x11name, items[i].lyxname);
113 string const LColor::getGUIName(LColor::color c) const
115 InfoTab::const_iterator ici = infotab.find(c);
116 if (ici != infotab.end())
117 return _(ici->second.guiname);
123 string const LColor::getX11Name(LColor::color c) const
125 InfoTab::const_iterator ici = infotab.find(c);
126 if (ici != infotab.end())
127 return ici->second.x11name;
129 lyxerr << "LyX internal error: Missing color"
130 " entry in LColor.C for " << int(c) << '\n';
131 lyxerr << "Using black.\n";
136 string const LColor::getLaTeXName(LColor::color c) const
138 InfoTab::const_iterator ici = infotab.find(c);
139 if (ici != infotab.end())
140 return ici->second.latexname;
145 string const LColor::getLyXName(LColor::color c) const
147 InfoTab::const_iterator ici = infotab.find(c);
148 if (ici != infotab.end())
149 return ici->second.lyxname;
154 void LColor::setColor(LColor::color col, string const & x11name)
156 InfoTab::iterator iti = infotab.find(col);
157 if (iti != infotab.end()) {
158 iti->second.x11name = x11name;
161 lyxerr << "LyX internal error: color and such.\n";
166 bool LColor::setColor(string const & lyxname, string const & x11name)
168 color col = getFromLyXName (lyxname);
170 // "inherit" is returned for colors not in the database
171 // (and anyway should not be redefined)
172 if (col == inherit || col == ignore) {
173 lyxerr << "Color " << lyxname << " is undefined or may not be"
174 " redefined" << endl;
177 setColor (col, x11name);
182 LColor::color LColor::getFromGUIName(string const & guiname) const
184 InfoTab::const_iterator ici = infotab.begin();
185 InfoTab::const_iterator end = infotab.end();
186 for (; ici != end; ++ici) {
187 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
190 return LColor::inherit;
194 LColor::color LColor::getFromLyXName(string const & lyxname) const
197 InfoTab::const_iterator ici = infotab.begin();
198 InfoTab::const_iterator end = infotab.end();
199 for (; ici != end; ++ici) {
200 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
203 return LColor::inherit;
206 // The evil global LColor instance
208 // An equally evil global system LColor instance
209 LColor system_lcolor;