]> git.lyx.org Git - lyx.git/blob - src/LColor.C
Martin's changes to the Note inset.
[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 #include "debug.h"
13 #include "LColor.h"
14 #include "support/LAssert.h"
15 #include "gettext.h"
16 #include "support/lstrings.h"
17
18 #include <map>
19
20 using namespace lyx::support;
21
22 using std::endl;
23
24
25 namespace {
26
27 struct ColorEntry {
28         LColor::color lcolor;
29         char const * guiname;
30         char const * latexname;
31         char const * x11name;
32         char const * lyxname;
33 };
34
35 }
36
37
38 struct LColor::Pimpl {
39         ///
40         struct information {
41                 /// the name as it appears in the GUI
42                 string guiname;
43                 /// the name used in LaTeX
44                 string latexname;
45                 /// the name for X11
46                 string x11name;
47                 /// the name for LyX
48                 string lyxname;
49         };
50
51         /// initialise a color entry
52         void fill(ColorEntry const & entry)
53         {
54                 information & in = infotab[entry.lcolor];
55                 in.guiname   = entry.guiname;
56                 in.latexname = entry.latexname;
57                 in.x11name   = entry.x11name;
58                 in.lyxname   = entry.lyxname;
59         }
60
61         ///
62         typedef std::map<LColor::color, information> InfoTab;
63         /// the table of color information
64         InfoTab infotab;
65 };
66
67
68 LColor::LColor()
69         : pimpl_(new Pimpl)
70 {
71         //  LColor::color, gui, latex, x11, lyx
72         static ColorEntry const items[] = {
73         { none, N_("none"), "none", "black", "none" },
74         { black, N_("black"), "black", "black", "black" },
75         { white, N_("white"), "white", "white", "white" },
76         { red, N_("red"), "red", "red", "red" },
77         { green, N_("green"), "green", "green", "green" },
78         { blue, N_("blue"), "blue", "blue", "blue" },
79         { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
80         { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
81         { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
82         { cursor, N_("cursor"), "cursor", "black", "cursor" },
83         { background, N_("background"), "background", "linen", "background" },
84         { foreground, N_("text"), "foreground", "black", "foreground" },
85         { selection, N_("selection"), "selection", "LightBlue", "selection" },
86         { latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
87         { preview, N_("previewed snippet"), "preview", "black", "preview" },
88         { note, N_("note"), "note", "yellow", "note" },
89         { notebg, N_("note background"), "notebg", "yellow", "notebg" },
90         { comment, N_("comment"), "comment", "magenta", "comment" },
91         { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
92         { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
93         { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
94         { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
95         { language, N_("language"), "language", "Blue", "language" },
96         { command, N_("command inset"), "command", "black", "command" },
97         { commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
98         { commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
99         { special, N_("special character"), "special", "RoyalBlue", "special" },
100         { math, N_("math"), "math", "DarkBlue", "math" },
101         { mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
102         { graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
103         { mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
104         { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
105         { mathline, N_("math line"), "mathline", "Blue", "mathline" },
106         { captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
107         { collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
108         { collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
109         { insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
110         { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
111         { error, N_("LaTeX error"), "error", "Red", "error" },
112         { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
113         { appendix, N_("appendix marker"), "appendix", "Brown", "appendix" },
114         { changebar, N_("change bar"), "changebar", "Blue", "changebar" },
115         { strikeout, N_("Deleted text"), "strikeout", "Red", "strikeout" },
116         { newtext, N_("Added text"), "newtext", "Blue", "newtext" },
117         { added_space, N_("added space markers"), "added_space", "Brown", "added_space" },
118         { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
119         { tabularline, N_("table line"), "tabularline", "black",
120              "tabularline" },
121         { tabularonoffline, N_("table on/off line"), "tabularonoffline",
122              "LightSteelBlue", "tabularonoffline" },
123         { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
124         { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
125         { top, N_("top of button"), "top", "grey90", "top" },
126         { bottom, N_("bottom of button"), "bottom", "grey60", "bottom" },
127         { left, N_("left of button"), "left", "grey90", "left" },
128         { right, N_("right of button"), "right", "grey60", "right" },
129         { buttonbg, N_("button background"), "buttonbg", "grey80", "buttonbg" },
130         { inherit, N_("inherit"), "inherit", "black", "inherit" },
131         { ignore, N_("ignore"), "ignore", "black", "ignore" },
132         { ignore, 0, 0, 0, 0 }
133         };
134
135         for (int i = 0; items[i].guiname; ++i)
136                 pimpl_->fill(items[i]);
137 }
138
139
140 LColor::LColor(LColor const & c)
141         : pimpl_(new Pimpl(*c.pimpl_))
142 {}
143
144
145 LColor::~LColor()
146 {
147         delete pimpl_;
148 }
149
150
151 void LColor::operator=(LColor const & c)
152 {
153         LColor tmp(c);
154         std::swap(pimpl_, tmp.pimpl_);
155 }
156
157
158
159 string const LColor::getGUIName(LColor::color c) const
160 {
161         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
162         if (ici != pimpl_->infotab.end())
163                 return _(ici->second.guiname);
164         return "none";
165 }
166
167
168 string const LColor::getX11Name(LColor::color c) const
169 {
170         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
171         if (ici != pimpl_->infotab.end())
172                 return ici->second.x11name;
173
174         lyxerr << "LyX internal error: Missing color"
175                 " entry in LColor.C for " << int(c) << '\n';
176         lyxerr << "Using black.\n";
177         return "black";
178 }
179
180
181 string const LColor::getLaTeXName(LColor::color c) const
182 {
183         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
184         if (ici != pimpl_->infotab.end())
185                 return ici->second.latexname;
186         return "black";
187 }
188
189
190 string const LColor::getLyXName(LColor::color c) const
191 {
192         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
193         if (ici != pimpl_->infotab.end())
194                 return ici->second.lyxname;
195         return "black";
196 }
197
198
199 void LColor::setColor(LColor::color col, string const & x11name)
200 {
201         Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
202         if (iti != pimpl_->infotab.end()) {
203                 iti->second.x11name = x11name;
204                 return;
205         }
206         lyxerr << "LyX internal error: color and such.\n";
207         Assert(false);
208 }
209
210
211 bool LColor::setColor(string const & lyxname, string const & x11name)
212 {
213         color col = getFromLyXName(lyxname);
214
215         // "inherit" is returned for colors not in the database
216         // (and anyway should not be redefined)
217         if (col == inherit || col == ignore) {
218                 lyxerr << "Color " << lyxname << " is undefined or may not be"
219                         " redefined" << endl;
220                 return false;
221         }
222         setColor (col, x11name);
223         return true;
224 }
225
226
227 LColor::color LColor::getFromGUIName(string const & guiname) const
228 {
229         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
230         Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
231         for (; ici != end; ++ici) {
232                 if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
233                         return ici->first;
234         }
235         return LColor::inherit;
236 }
237
238
239 LColor::color LColor::getFromLyXName(string const & lyxname) const
240 {
241         Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
242         Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
243         for (; ici != end; ++ici) {
244                 if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
245                         return ici->first;
246         }
247         return LColor::inherit;
248 }
249
250
251 // The evil global LColor instance
252 LColor lcolor;
253 // An equally evil global system LColor instance
254 LColor system_lcolor;