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