1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2001 The LyX Team
8 *======================================================*/
13 #pragma implementation
18 #include "support/LAssert.h"
20 #include "support/lstrings.h"
24 void LColor::fill(LColor::color col, string const & gui,
25 string const & latex, string const & x11,
39 char const * latexname;
47 // LColor::color, gui, latex, x11, lyx
48 ColorEntry items[] = {
49 { none, N_("none"), "none", "black", "none" },
50 { black, N_("black"), "black", "black", "black" },
51 { white, N_("white"), "white", "white", "white" },
52 { red, N_("red"), "red", "red", "red" },
53 { green, N_("green"), "green", "green", "green" },
54 { blue, N_("blue"), "blue", "blue", "blue" },
55 { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
56 { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
57 { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
58 { cursor, N_("cursor"), "cursor", "black", "cursor" },
59 { background, N_("background"), "background", "linen", "background" },
60 { foreground, N_("text"), "foreground", "black", "foreground" },
61 { selection, N_("selection"), "selection", "LightBlue", "selection" },
62 { latex, N_("latex text"), "latex", "DarkRed", "latex" },
63 { preview, N_("previewed snippet"), "preview", "black", "preview" },
64 { note, N_("note"), "note", "yellow", "note" },
65 { notebg, N_("note background"), "notebg", "yellow", "notebg" },
66 { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
67 { language, N_("language"), "language", "Blue", "language" },
68 { command, N_("command inset"), "command", "black", "command" },
69 { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
70 { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
71 { special, N_("special character"), "special", "RoyalBlue", "special" },
72 { math, N_("math"), "math", "DarkBlue", "math" },
73 { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
74 { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
75 { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
76 { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
77 { mathcursor, N_("math cursor"), "mathcursor", "black", "mathcursor" },
78 { mathline, N_("math line"), "mathline", "Blue", "mathline" },
79 { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
80 { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
81 { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
82 { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
83 { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
84 { error, N_("LaTeX error"), "error", "Red", "error" },
85 { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
86 { appendixline, N_("appendix line"), "appendixline", "Brown", "appendixline" },
87 { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
88 { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
89 { tabularline, N_("tabular line"), "tabularline", "black",
91 { tabularonoffline, N_("tabular on/off line"), "tabularonoffline",
92 "LightSteelBlue", "tabularonoffline" },
93 { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
94 { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
95 { top, N_("top of button"), "top", "grey90", "top" },
96 { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
97 { left, N_("left of button"), "left", "grey90", "left" },
98 { right, N_("right of button"), "right", "grey60", "right" },
99 { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
100 { inherit, N_("inherit"), "inherit", "black", "inherit" },
101 { ignore, N_("ignore"), "ignore", "black", "ignore" },
102 { ignore, 0, 0, 0, 0 }
106 while (items[i].guiname) {
107 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
108 items[i].x11name, items[i].lyxname);
114 string const LColor::getGUIName(LColor::color c) const
116 InfoTab::const_iterator ici = infotab.find(c);
117 if (ici != infotab.end())
118 return _(ici->second.guiname);
124 string const LColor::getX11Name(LColor::color c) const
126 InfoTab::const_iterator ici = infotab.find(c);
127 if (ici != infotab.end())
128 return ici->second.x11name;
130 lyxerr << "LyX internal error: Missing color"
131 " entry in LColor.C for " << int(c) << '\n';
132 lyxerr << "Using black.\n";
137 string const LColor::getLaTeXName(LColor::color c) const
139 InfoTab::const_iterator ici = infotab.find(c);
140 if (ici != infotab.end())
141 return ici->second.latexname;
146 string const LColor::getLyXName(LColor::color c) const
148 InfoTab::const_iterator ici = infotab.find(c);
149 if (ici != infotab.end())
150 return ici->second.lyxname;
155 void LColor::setColor(LColor::color col, string const & x11name)
157 InfoTab::iterator iti = infotab.find(col);
158 if (iti != infotab.end()) {
159 iti->second.x11name = x11name;
162 lyxerr << "LyX internal error: color and such.\n";
167 bool LColor::setColor(string const & lyxname, string const & x11name)
169 color col = getFromLyXName (lyxname);
171 // "inherit" is returned for colors not in the database
172 // (and anyway should not be redefined)
173 if (col == inherit || col == ignore) {
174 lyxerr << "Color " << lyxname << " is undefined or may not be"
175 " redefined" << endl;
178 setColor (col, x11name);
183 LColor::color LColor::getFromGUIName(string const & guiname) const
185 InfoTab::const_iterator ici = infotab.begin();
186 InfoTab::const_iterator end = infotab.end();
187 for (; ici != end; ++ici) {
188 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
191 return LColor::inherit;
195 LColor::color LColor::getFromLyXName(string const & lyxname) const
198 InfoTab::const_iterator ici = infotab.begin();
199 InfoTab::const_iterator end = infotab.end();
200 for (; ici != end; ++ici) {
201 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
204 return LColor::inherit;
207 // The evil global LColor instance
209 // An equally evil global system LColor instance
210 LColor system_lcolor;