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 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
74 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
75 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
76 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
77 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
78 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
79 { error, N_("LaTeX error"), "error", "Red", "error" },
80 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
81 { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
82 { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
83 { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
84 { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
85 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
86 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
87 { tabularline, N_("tabular line"), "tabularline", "black",
89 { tabularonoffline, N_("tabular on/off line"), "tabularonoffline",
90 "LightSteelBlue", "tabularonoffline" },
91 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
92 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
93 { top, N_("top of button"), "top", "grey90", "top" },
94 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
95 { left, N_("left of button"), "left", "grey90", "left" },
96 { right, N_("right of button"), "right", "grey60", "right" },
97 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
98 { inherit, N_("inherit"), "inherit", "black", "inherit" },
99 { ignore, N_("ignore"), "ignore", "black", "ignore" },
100 { ignore, 0, 0, 0, 0 }
104 while (items[i].guiname) {
105 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
106 items[i].x11name, items[i].lyxname);
112 string const LColor::getGUIName(LColor::color c) const
114 InfoTab::const_iterator ici = infotab.find(c);
115 if (ici != infotab.end())
116 return _(ici->second.guiname);
122 string const LColor::getX11Name(LColor::color c) const
124 InfoTab::const_iterator ici = infotab.find(c);
125 if (ici != infotab.end())
126 return ici->second.x11name;
128 lyxerr << "LyX internal error: Missing color"
129 " entry in LColor.C for " << int(c) << '\n';
130 lyxerr << "Using black.\n";
135 string const LColor::getLaTeXName(LColor::color c) const
137 InfoTab::const_iterator ici = infotab.find(c);
138 if (ici != infotab.end())
139 return ici->second.latexname;
144 string const LColor::getLyXName(LColor::color c) const
146 InfoTab::const_iterator ici = infotab.find(c);
147 if (ici != infotab.end())
148 return ici->second.lyxname;
153 void LColor::setColor(LColor::color col, string const & x11name)
155 InfoTab::iterator iti = infotab.find(col);
156 if (iti != infotab.end()) {
157 iti->second.x11name = x11name;
160 lyxerr << "LyX internal error: color and such.\n";
165 bool LColor::setColor(string const & lyxname, string const & x11name)
167 color col = getFromLyXName (lyxname);
169 // "inherit" is returned for colors not in the database
170 // (and anyway should not be redefined)
171 if (col == inherit || col == ignore) {
172 lyxerr << "Color " << lyxname << " is undefined or may not be"
173 " redefined" << endl;
176 setColor (col, x11name);
181 LColor::color LColor::getFromGUIName(string const & guiname) const
183 InfoTab::const_iterator ici = infotab.begin();
184 InfoTab::const_iterator end = infotab.end();
185 for (; ici != end; ++ici) {
186 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
189 return LColor::inherit;
193 LColor::color LColor::getFromLyXName(string const & lyxname) const
196 InfoTab::const_iterator ici = infotab.begin();
197 InfoTab::const_iterator end = infotab.end();
198 for (; ici != end; ++ici) {
199 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
202 return LColor::inherit;
205 // The evil global LColor instance
207 // An equally evil global system LColor instance
208 LColor system_lcolor;