]> git.lyx.org Git - lyx.git/blob - src/LColor.C
faster compile of LColor.C
[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
26 void LColor::fill(LColor::color col, string const & gui,
27                   string const & latex, string const & x11,
28                   string const & lyx) {
29         information in;
30         in.guiname = gui;
31         in.latexname = latex;
32         in.x11name = x11;
33         in.lyxname = lyx;
34
35         infotab[col] = in;
36 }
37
38 struct ColorEntry {
39         LColor::color lcolor;
40         char const * guiname;
41         char const * latexname;
42         char const * x11name;
43         char const * lyxname;
44 };
45
46
47 LColor::LColor()
48 {
49         //  LColor::color, gui, latex, x11, lyx
50         ColorEntry items[] = {
51         { none, N_("none"), "none", "black", "none" },
52         { black, N_("black"), "black", "black", "black" },
53         { white, N_("white"), "white", "white", "white" },
54         { red, N_("red"), "red", "red", "red" },
55         { green, N_("green"), "green", "green", "green" },
56         { blue, N_("blue"), "blue", "blue", "blue" },
57         { cyan, N_("cyan"), "cyan", "cyan", "cyan" },
58         { magenta, N_("magenta"), "magenta", "magenta", "magenta" },
59         { yellow, N_("yellow"), "yellow", "yellow", "yellow" },
60         { background, N_("background"), "background", "linen", "background" },
61         { foreground, N_("foreground"), "foreground", "black", "foreground" },
62         { selection, N_("selection"), "selection", "LightBlue", "selection" },
63         { latex, N_("latex"), "latex", "DarkRed", "latex" },
64         { floats, N_("floats"), "floats", "red", "floats" },
65         { note, N_("note"), "note", "black", "note" },
66         { notebg, N_("note background"), "notebg", "yellow", "notebg" },
67         { noteframe, N_("note frame"), "noteframe", "black", "noteframe" },
68         { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
69         { command, N_("command-inset"), "command", "black", "command" },
70         { commandbg, N_("command-inset background"), "commandbg", "grey80", "commandbg" },
71         { commandframe, N_("inset frame"), "commandframe", "black", "commandframe" },
72         { accent, N_("accent"), "accent", "black", "accent" },
73         { accentbg, N_("accent background"), "accentbg", "offwhite", "accentbg" },
74         { accentframe, N_("accent frame"), "accentframe", "linen", "accentframe" },
75         { minipageline, N_("minipage line"), "minipageline", "violet", "minipageline" },
76         { special, N_("special char"), "special", "RoyalBlue", "special" },
77         { math, N_("math"), "math", "DarkBlue", "math" },
78         { mathbg, N_("math background"), "mathbg", "AntiqueWhite", "mathbg" },
79         { mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
80         { mathcursor, N_("math cursor"), "mathcursor", "black", "mathcursor" },
81         { mathline, N_("math line"), "mathline", "Blue", "mathline" },
82         { footnote, N_("footnote"), "footnote", "DarkRed", "footnote" },
83         { footnotebg, N_("footnote background"), "footnotebg", "grey60", "footnotebg" },
84         { footnoteframe, N_("footnote frame"), "footnoteframe", "IndianRed", "footnoteframe" },
85         { ert, N_("ert"), "ert", "DarkRed", "ert" },
86         { inset, N_("inset"), "inset", "black", "inset" },
87         { insetbg, N_("inset background"), "insetbg", "grey60", "insetbg" },
88         { insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
89         { error, N_("error"), "error", "Red", "error" },
90         { eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
91         { appendixline, N_("appendix line"), "appendixline", "Brown", "appendixline" },
92         { vfillline, N_("vfill line"), "vfillline", "Brown", "vfillline" },
93         { topline, N_("top/bottom line"), "topline", "Brown", "topline" },
94         { tableline, N_("table line"), "tableline", "black", "tableline" },
95         { tabularline, N_("tabular line"), "tabularline", "black",
96              "tabularline" },
97         { tabularonoffline, N_("tabularonoff line"), "tabularonoffline",
98              "LightSteelBlue", "tabularonoffline" },
99         { bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
100         { pagebreak, N_("page break"), "pagebreak", "RoyalBlue", "pagebreak" },
101         { top, N_("top of button"), "top", "grey80", "top" },
102         { bottom, N_("bottom of button"), "bottom", "grey40", "bottom" },
103         { left, N_("left of button"), "left", "grey80", "left" },
104         { right, N_("right of button"), "right", "grey40", "right" },
105         { buttonbg, N_("button background"), "buttonbg", "grey60", "buttonbg" },
106         { inherit, N_("inherit"), "inherit", "black", "inherit" },
107         { ignore, N_("ignore"), "ignore", "black", "ignore" },
108         { ignore, 0, 0, 0, 0 }
109         };
110
111         int i = 0;
112         while (items[i].guiname) {
113                 fill(items[i].lcolor, items[i].guiname, items[i].latexname,
114                      items[i].x11name, items[i].lyxname);
115                 ++i;
116         }
117 }
118
119
120 string LColor::getGUIName(LColor::color c) const
121 {
122         InfoTab::const_iterator ici = infotab.find(c);
123         if (ici != infotab.end())
124                 return _((*ici).second.guiname.c_str());
125
126         return "none";
127 }
128
129
130 string LColor::getX11Name(LColor::color c) const
131 {
132         InfoTab::const_iterator ici = infotab.find(c);
133         if (ici != infotab.end()) 
134                 return (*ici).second.x11name;
135
136         lyxerr << "LyX internal error: Missing color"
137                 " entry in LColor.C for " << int(c) << '\n';
138         lyxerr << "Using black.\n";
139         return "black";
140 }
141
142
143 string LColor::getLaTeXName(LColor::color c) const
144 {
145         InfoTab::const_iterator ici = infotab.find(c);
146         if (ici != infotab.end())
147                 return (*ici).second.latexname;
148         return "black";
149 }
150
151
152 string LColor::getLyXName(LColor::color c) const
153 {
154         InfoTab::const_iterator ici = infotab.find(c);
155         if (ici != infotab.end())
156                 return (*ici).second.lyxname;
157         return "black";
158 }
159
160
161 void LColor::setColor(LColor::color col, string const & x11name)
162 {
163         InfoTab::iterator iti = infotab.find(col);
164         if (iti != infotab.end()) {
165                 (*iti).second.x11name = x11name;
166                 return;
167         }
168         lyxerr << "LyX internal error: color and such.\n";
169         Assert(false);
170 }
171
172
173 LColor::color LColor::getFromGUIName(string const & guiname) const
174 {
175         InfoTab::const_iterator ici = infotab.begin();
176         for (; ici != infotab.end(); ++ici) {
177                 if (!compare_no_case((*ici).second.guiname, guiname))
178                         return (*ici).first;
179         }
180         return LColor::ignore;
181 }
182
183
184 LColor::color LColor::getFromLyXName(string const & lyxname) const
185 {
186         
187         InfoTab::const_iterator ici = infotab.begin();
188         for (; ici != infotab.end(); ++ici) {
189                 if (!compare_no_case((*ici).second.lyxname, lyxname))
190                         return (*ici).first;
191         }
192         return LColor::inherit;
193 }
194
195 // The evil global LColor instance
196 LColor lcolor;