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