]> git.lyx.org Git - lyx.git/blob - src/LColor.C
Fix natbib bug spotted by JMarc.
[lyx.git] / src / LColor.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *          Copyright 1998-2001 The LyX Team
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "debug.h"
17 #include "LColor.h"
18 #include "support/LAssert.h"
19 #include "gettext.h"
20 #include "support/lstrings.h"
21
22 using std::endl;
23
24 void LColor::fill(LColor::color col, string const & gui,
25                   string const & latex, string const & x11,
26                   string const & lyx) {
27         information in;
28         in.guiname = gui;
29         in.latexname = latex;
30         in.x11name = x11;
31         in.lyxname = lyx;
32
33         infotab[col] = in;
34 }
35
36 struct ColorEntry {
37         LColor::color lcolor;
38         char const * guiname;
39         char const * latexname;
40         char const * x11name;
41         char const * lyxname;
42 };
43
44
45 LColor::LColor()
46 {
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         { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
88         { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
89         { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
90         { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
91         { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
92         { tabularline, N_("tabular line"), "tabularline", "black",
93              "tabularline" },
94         { tabularonoffline, N_("tabular on/off line"), "tabularonoffline",
95              "LightSteelBlue", "tabularonoffline" },
96         { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
97         { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
98         { top, N_("top of button"), "top", "grey90", "top" },
99         { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
100         { left, N_("left of button"), "left", "grey90", "left" },
101         { right, N_("right of button"), "right", "grey60", "right" },
102         { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
103         { inherit, N_("inherit"), "inherit", "black", "inherit" },
104         { ignore, N_("ignore"), "ignore", "black", "ignore" },
105         { ignore, 0, 0, 0, 0 }
106         };
107
108         int i = 0;
109         while (items[i].guiname) {
110                 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
111                      items[i].x11name, items[i].lyxname);
112                 ++i;
113         }
114 }
115
116
117 string const LColor::getGUIName(LColor::color c) const
118 {
119         InfoTab::const_iterator ici = infotab.find(c);
120         if (ici != infotab.end())
121                 return _(ici->second.guiname);
122
123         return "none";
124 }
125
126
127 string const LColor::getX11Name(LColor::color c) const
128 {
129         InfoTab::const_iterator ici = infotab.find(c);
130         if (ici != infotab.end())
131                 return ici->second.x11name;
132
133         lyxerr << "LyX internal error: Missing color"
134                 " entry in LColor.C for " << int(c) << '\n';
135         lyxerr << "Using black.\n";
136         return "black";
137 }
138
139
140 string const LColor::getLaTeXName(LColor::color c) const
141 {
142         InfoTab::const_iterator ici = infotab.find(c);
143         if (ici != infotab.end())
144                 return ici->second.latexname;
145         return "black";
146 }
147
148
149 string const LColor::getLyXName(LColor::color c) const
150 {
151         InfoTab::const_iterator ici = infotab.find(c);
152         if (ici != infotab.end())
153                 return ici->second.lyxname;
154         return "black";
155 }
156
157
158 void LColor::setColor(LColor::color col, string const & x11name)
159 {
160         InfoTab::iterator iti = infotab.find(col);
161         if (iti != infotab.end()) {
162                 iti->second.x11name = x11name;
163                 return;
164         }
165         lyxerr << "LyX internal error: color and such.\n";
166         lyx::Assert(false);
167 }
168
169
170 bool LColor::setColor(string const & lyxname, string const & x11name)
171 {
172         color col = getFromLyXName (lyxname);
173
174         // "inherit" is returned for colors not in the database
175         // (and anyway should not be redefined)
176         if (col == inherit || col == ignore) {
177                 lyxerr << "Color " << lyxname << " is undefined or may not be"
178                         " redefined" << endl;
179                 return false;
180         }
181         setColor (col, x11name);
182         return true;
183 }
184
185
186 LColor::color LColor::getFromGUIName(string const & guiname) const
187 {
188         InfoTab::const_iterator ici = infotab.begin();
189         InfoTab::const_iterator end = infotab.end();
190         for (; ici != end; ++ici) {
191                 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
192                         return ici->first;
193         }
194         return LColor::inherit;
195 }
196
197
198 LColor::color LColor::getFromLyXName(string const & lyxname) const
199 {
200
201         InfoTab::const_iterator ici = infotab.begin();
202         InfoTab::const_iterator end = infotab.end();
203         for (; ici != end; ++ici) {
204                 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
205                         return ici->first;
206         }
207         return LColor::inherit;
208 }
209
210 // The evil global LColor instance
211 LColor lcolor;
212 // An equally evil global system LColor instance
213 LColor system_lcolor;