]> git.lyx.org Git - lyx.git/blob - src/LColor.C
Dekel's lyxrc.example; Angus's FormDocument; John's build-listerrors; POTFILES.in...
[lyx.git] / src / LColor.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *          Copyright 1998-2000 The LyX Team
8  *
9  *======================================================*/
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <X11/Xlib.h>
18
19 #include "debug.h"
20 #include "LColor.h"
21 #include "support/LAssert.h"
22 #include "gettext.h"
23 #include "support/lstrings.h"
24
25 using std::endl;
26
27 void LColor::fill(LColor::color col, string const & gui,
28                   string const & latex, string const & x11,
29                   string const & lyx) {
30         information in;
31         in.guiname = gui;
32         in.latexname = latex;
33         in.x11name = x11;
34         in.lyxname = lyx;
35
36         infotab[col] = in;
37 }
38
39 struct ColorEntry {
40         LColor::color lcolor;
41         char const * guiname;
42         char const * latexname;
43         char const * x11name;
44         char const * lyxname;
45 };
46
47
48 LColor::LColor()
49 {
50         //  LColor::color, gui, latex, x11, lyx
51         ColorEntry items[] = {
52         { none, N_("none"), "none", "black", "none" },
53         { black, N_("black"), "black", "black", "black" },
54         { white, N_("white"), "white", "white", "white" },
55         { red, N_("red"), "red", "red", "red" },
56         { green, N_("green"), "green", "green", "green" },
57         { blue, N_("blue"), "blue", "blue", "blue" },
58         { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
59         { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
60         { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
61         { background, N_("background"), "background", "linen", "background" },
62         { foreground, N_("foreground"), "foreground", "black", "foreground" },
63         { selection, N_("selection"), "selection", "LightBlue", "selection" },
64         { latex, N_("latex"), "latex", "DarkRed", "latex" },
65         { floats, N_("floats"), "floats", "red", "floats" },
66         { note, N_("note"), "note", "black", "note" },
67         { notebg, N_("note background"), "notebg", "yellow", "notebg" },
68         { noteframe, N_("note frame"), "noteframe", "black", "noteframe" },
69         { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
70         { language, N_("language"), "language", "Blue", "language" },
71         { command, N_("command-inset"), "command", "black", "command" },
72         { commandbg, N_("command-inset background"), "commandbg", "grey80", "commandbg" },
73         { commandframe, N_("inset frame"), "commandframe", "black", "commandframe" },
74         { accent, N_("accent"), "accent", "black", "accent" },
75         { accentbg, N_("accent background"), "accentbg", "offwhite", "accentbg" },
76         { accentframe, N_("accent frame"), "accentframe", "linen", "accentframe" },
77         { minipageline, N_("minipage line"), "minipageline", "violet", "minipageline" },
78         { special, N_("special char"), "special", "RoyalBlue", "special" },
79         { math, N_("math"), "math", "DarkBlue", "math" },
80         { mathbg, N_("math background"), "mathbg", "AntiqueWhite", "mathbg" },
81         { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
82         { mathcursor, N_("math cursor"), "mathcursor", "black", "mathcursor" },
83         { mathline, N_("math line"), "mathline", "Blue", "mathline" },
84         { footnote, N_("footnote"), "footnote", "DarkRed", "footnote" },
85         { footnotebg, N_("footnote background"), "footnotebg", "grey60", "footnotebg" },
86         { footnoteframe, N_("footnote frame"), "footnoteframe", "IndianRed", "footnoteframe" },
87         { ert, N_("ert"), "ert", "DarkRed", "ert" },
88         { inset, N_("inset"), "inset", "black", "inset" },
89         { insetbg, N_("inset background"), "insetbg", "grey60", "insetbg" },
90         { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
91         { error, N_("error"), "error", "Red", "error" },
92         { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
93         { appendixline, N_("appendix line"), "appendixline", "Brown", "appendixline" },
94         { vfillline, N_("vfill line"), "vfillline", "Brown", "vfillline" },
95         { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
96         { tableline, N_("table line"), "tableline", "black", "tableline" },
97         { tabularline, N_("tabular line"), "tabularline", "black",
98              "tabularline" },
99         { tabularonoffline, N_("tabularonoff line"), "tabularonoffline",
100              "LightSteelBlue", "tabularonoffline" },
101         { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
102         { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
103         { top, N_("top of button"), "top", "grey80", "top" },
104         { bottom, N_("bottom of button"), "bottom", "grey40", "bottom" },
105         { left, N_("left of button"), "left", "grey80", "left" },
106         { right, N_("right of button"), "right", "grey40", "right" },
107         { buttonbg, N_("button background"), "buttonbg", "grey60", "buttonbg" },
108         { inherit, N_("inherit"), "inherit", "black", "inherit" },
109         { ignore, N_("ignore"), "ignore", "black", "ignore" },
110         { ignore, 0, 0, 0, 0 }
111         };
112
113         int i = 0;
114         while (items[i].guiname) {
115                 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
116                      items[i].x11name, items[i].lyxname);
117                 ++i;
118         }
119 }
120
121
122 string const LColor::getGUIName(LColor::color c) const
123 {
124         InfoTab::const_iterator ici = infotab.find(c);
125         if (ici != infotab.end())
126                 return _((*ici).second.guiname.c_str());
127
128         return "none";
129 }
130
131
132 string const LColor::getX11Name(LColor::color c) const
133 {
134         InfoTab::const_iterator ici = infotab.find(c);
135         if (ici != infotab.end()) 
136                 return (*ici).second.x11name;
137
138         lyxerr << "LyX internal error: Missing color"
139                 " entry in LColor.C for " << int(c) << '\n';
140         lyxerr << "Using black.\n";
141         return "black";
142 }
143
144
145 string const LColor::getLaTeXName(LColor::color c) const
146 {
147         InfoTab::const_iterator ici = infotab.find(c);
148         if (ici != infotab.end())
149                 return (*ici).second.latexname;
150         return "black";
151 }
152
153
154 string const LColor::getLyXName(LColor::color c) const
155 {
156         InfoTab::const_iterator ici = infotab.find(c);
157         if (ici != infotab.end())
158                 return (*ici).second.lyxname;
159         return "black";
160 }
161
162
163 void LColor::setColor(LColor::color col, string const & x11name)
164 {
165         InfoTab::iterator iti = infotab.find(col);
166         if (iti != infotab.end()) {
167                 (*iti).second.x11name = x11name;
168                 return;
169         }
170         lyxerr << "LyX internal error: color and such.\n";
171         Assert(false);
172 }
173
174
175 bool LColor::setColor(string const & lyxname, string const & x11name)
176 {
177         color col = getFromLyXName (lyxname);
178
179         // "inherit" is returned for colors not in the database
180         // (and anyway should not be redefined)
181         if (col == inherit || col == ignore) {
182                 lyxerr << "Color " << lyxname << " is undefined or may not be"
183                         " redefined" << endl;
184                 return false;
185         }
186         setColor (col, x11name);
187         return true;
188 }
189
190
191 LColor::color LColor::getFromGUIName(string const & guiname) const
192 {
193         InfoTab::const_iterator ici = infotab.begin();
194         InfoTab::const_iterator end = infotab.end();
195         for (; ici != end; ++ici) {
196                 if (!compare_no_case((*ici).second.guiname, guiname))
197                         return (*ici).first;
198         }
199         return LColor::inherit;
200 }
201
202
203 LColor::color LColor::getFromLyXName(string const & lyxname) const
204 {
205         
206         InfoTab::const_iterator ici = infotab.begin();
207         InfoTab::const_iterator end = infotab.end();
208         for (; ici != end; ++ici) {
209                 if (!compare_no_case((*ici).second.lyxname, lyxname))
210                         return (*ici).first;
211         }
212         return LColor::inherit;
213 }
214
215 // The evil global LColor instance
216 LColor lcolor;