]> git.lyx.org Git - lyx.git/blob - src/LColor.C
Minor bits 'n' bobs from Michael, J�rgen and Jean-Marc.
[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         { 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",
90              "tabularline" },
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 }
103         };
104
105         int i = 0;
106         while (items[i].guiname) {
107                 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
108                      items[i].x11name, items[i].lyxname);
109                 ++i;
110         }
111 }
112
113
114 string const LColor::getGUIName(LColor::color c) const
115 {
116         InfoTab::const_iterator ici = infotab.find(c);
117         if (ici != infotab.end())
118                 return _(ici->second.guiname);
119
120         return "none";
121 }
122
123
124 string const LColor::getX11Name(LColor::color c) const
125 {
126         InfoTab::const_iterator ici = infotab.find(c);
127         if (ici != infotab.end())
128                 return ici->second.x11name;
129
130         lyxerr << "LyX internal error: Missing color"
131                 " entry in LColor.C for " << int(c) << '\n';
132         lyxerr << "Using black.\n";
133         return "black";
134 }
135
136
137 string const LColor::getLaTeXName(LColor::color c) const
138 {
139         InfoTab::const_iterator ici = infotab.find(c);
140         if (ici != infotab.end())
141                 return ici->second.latexname;
142         return "black";
143 }
144
145
146 string const LColor::getLyXName(LColor::color c) const
147 {
148         InfoTab::const_iterator ici = infotab.find(c);
149         if (ici != infotab.end())
150                 return ici->second.lyxname;
151         return "black";
152 }
153
154
155 void LColor::setColor(LColor::color col, string const & x11name)
156 {
157         InfoTab::iterator iti = infotab.find(col);
158         if (iti != infotab.end()) {
159                 iti->second.x11name = x11name;
160                 return;
161         }
162         lyxerr << "LyX internal error: color and such.\n";
163         lyx::Assert(false);
164 }
165
166
167 bool LColor::setColor(string const & lyxname, string const & x11name)
168 {
169         color col = getFromLyXName (lyxname);
170
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;
176                 return false;
177         }
178         setColor (col, x11name);
179         return true;
180 }
181
182
183 LColor::color LColor::getFromGUIName(string const & guiname) const
184 {
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))
189                         return ici->first;
190         }
191         return LColor::inherit;
192 }
193
194
195 LColor::color LColor::getFromLyXName(string const & lyxname) const
196 {
197
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))
202                         return ici->first;
203         }
204         return LColor::inherit;
205 }
206
207 // The evil global LColor instance
208 LColor lcolor;
209 // An equally evil global system LColor instance
210 LColor system_lcolor;