]> git.lyx.org Git - lyx.git/blob - src/LColor.C
patch from Angus and from Levon
[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         { cursor, N_("cursor"), "cursor", "black", "cursor" },
62         { background, N_("background"), "background", "linen", "background" },
63         { foreground, N_("text"), "foreground", "black", "foreground" },
64         { selection, N_("selection"), "selection", "LightBlue", "selection" },
65         { latex, N_("latex"), "latex", "DarkRed", "latex" },
66         { floats, N_("floats"), "floats", "red", "floats" },
67         { note, N_("note"), "note", "black", "note" },
68         { notebg, N_("note background"), "notebg", "yellow", "notebg" },
69         { noteframe, N_("note frame"), "noteframe", "black", "noteframe" },
70         { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
71         { language, N_("language"), "language", "Blue", "language" },
72         { command, N_("command-inset"), "command", "black", "command" },
73         { commandbg, N_("command-inset background"), "commandbg", "grey80", "commandbg" },
74         { commandframe, N_("command-inset frame"), "commandframe", "black", "commandframe" },
75         { accent, N_("accent"), "accent", "black", "accent" },
76         { accentbg, N_("accent background"), "accentbg", "linen", "accentbg" },
77         { accentframe, N_("accent frame"), "accentframe", "linen", "accentframe" },
78         { minipageline, N_("minipage line"), "minipageline", "violet", "minipageline" },
79         { special, N_("special char"), "special", "RoyalBlue", "special" },
80         { math, N_("math"), "math", "DarkBlue", "math" },
81         { mathbg, N_("math background"), "mathbg", "AntiqueWhite", "mathbg" },
82         { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
83         { mathcursor, N_("math cursor"), "mathcursor", "black", "mathcursor" },
84         { mathline, N_("math line"), "mathline", "Blue", "mathline" },
85         { footnote, N_("footnote"), "footnote", "DarkRed", "footnote" },
86         { footnotebg, N_("footnote background"), "footnotebg", "grey60", "footnotebg" },
87         { footnoteframe, N_("footnote frame"), "footnoteframe", "IndianRed", "footnoteframe" },
88         { ert, N_("latex text"), "ert", "DarkRed", "ert" },
89         { inset, N_("inset"), "inset", "black", "inset" },
90         { insetbg, N_("inset background"), "insetbg", "grey60", "insetbg" },
91         { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
92         { error, N_("error"), "error", "Red", "error" },
93         { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
94         { appendixline, N_("appendix line"), "appendixline", "Brown", "appendixline" },
95         { vfillline, N_("vfill line"), "vfillline", "Brown", "vfillline" },
96         { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
97         { tableline, N_("table line"), "tableline", "black", "tableline" },
98         { tabularline, N_("tabular line"), "tabularline", "black",
99              "tabularline" },
100         { tabularonoffline, N_("tabularonoff line"), "tabularonoffline",
101              "LightSteelBlue", "tabularonoffline" },
102         { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
103         { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
104         { top, N_("top of button"), "top", "grey80", "top" },
105         { bottom, N_("bottom of button"), "bottom", "grey40", "bottom" },
106         { left, N_("left of button"), "left", "grey80", "left" },
107         { right, N_("right of button"), "right", "grey40", "right" },
108         { buttonbg, N_("button background"), "buttonbg", "grey60", "buttonbg" },
109         { inherit, N_("inherit"), "inherit", "black", "inherit" },
110         { ignore, N_("ignore"), "ignore", "black", "ignore" },
111         { ignore, 0, 0, 0, 0 }
112         };
113
114         int i = 0;
115         while (items[i].guiname) {
116                 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
117                      items[i].x11name, items[i].lyxname);
118                 ++i;
119         }
120 }
121
122
123 string const LColor::getGUIName(LColor::color c) const
124 {
125         InfoTab::const_iterator ici = infotab.find(c);
126         if (ici != infotab.end())
127                 return _((*ici).second.guiname);
128
129         return "none";
130 }
131
132
133 string const LColor::getX11Name(LColor::color c) const
134 {
135         InfoTab::const_iterator ici = infotab.find(c);
136         if (ici != infotab.end()) 
137                 return (*ici).second.x11name;
138
139         lyxerr << "LyX internal error: Missing color"
140                 " entry in LColor.C for " << int(c) << '\n';
141         lyxerr << "Using black.\n";
142         return "black";
143 }
144
145
146 string const LColor::getLaTeXName(LColor::color c) const
147 {
148         InfoTab::const_iterator ici = infotab.find(c);
149         if (ici != infotab.end())
150                 return (*ici).second.latexname;
151         return "black";
152 }
153
154
155 string const LColor::getLyXName(LColor::color c) const
156 {
157         InfoTab::const_iterator ici = infotab.find(c);
158         if (ici != infotab.end())
159                 return (*ici).second.lyxname;
160         return "black";
161 }
162
163
164 void LColor::setColor(LColor::color col, string const & x11name)
165 {
166         InfoTab::iterator iti = infotab.find(col);
167         if (iti != infotab.end()) {
168                 (*iti).second.x11name = x11name;
169                 return;
170         }
171         lyxerr << "LyX internal error: color and such.\n";
172         Assert(false);
173 }
174
175
176 bool LColor::setColor(string const & lyxname, string const & x11name)
177 {
178         color col = getFromLyXName (lyxname);
179
180         // "inherit" is returned for colors not in the database
181         // (and anyway should not be redefined)
182         if (col == inherit || col == ignore) {
183                 lyxerr << "Color " << lyxname << " is undefined or may not be"
184                         " redefined" << endl;
185                 return false;
186         }
187         setColor (col, x11name);
188         return true;
189 }
190
191
192 LColor::color LColor::getFromGUIName(string const & guiname) const
193 {
194         InfoTab::const_iterator ici = infotab.begin();
195         InfoTab::const_iterator end = infotab.end();
196         for (; ici != end; ++ici) {
197                 if (!compare_no_case(_((*ici).second.guiname), guiname))
198                         return (*ici).first;
199         }
200         return LColor::inherit;
201 }
202
203
204 LColor::color LColor::getFromLyXName(string const & lyxname) const
205 {
206         
207         InfoTab::const_iterator ici = infotab.begin();
208         InfoTab::const_iterator end = infotab.end();
209         for (; ici != end; ++ici) {
210                 if (!compare_no_case((*ici).second.lyxname, lyxname))
211                         return (*ici).first;
212         }
213         return LColor::inherit;
214 }
215
216 // The evil global LColor instance
217 LColor lcolor;
218 // An equally evil global system LColor instance
219 LColor system_lcolor;