]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCharacter.C
The EnumLColor patch, free of macros.
[lyx.git] / src / frontends / controllers / ControlCharacter.C
1 /**
2  * \file ControlCharacter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlCharacter.h"
14 #include "ButtonController.h"
15
16 #include "buffer.h"
17 #include "bufferparams.h"
18 #include "bufferview_funcs.h"
19 #include "funcrequest.h"
20 #include "language.h"
21
22 using bv_funcs::font2string;
23
24
25 ControlCharacter::ControlCharacter(Dialog & parent)
26         : Dialog::Controller(parent),
27           font_(0), toggleall_(false)
28 {}
29
30
31 bool ControlCharacter::initialiseParams(string const &)
32 {
33         // Do this the first time only.
34         if (!font_.get())
35                 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
36
37         // so that the user can press Ok
38         if (getFamily()   != LyXFont::IGNORE_FAMILY ||
39             getSeries()   != LyXFont::IGNORE_SERIES ||
40             getShape()    != LyXFont::IGNORE_SHAPE  ||
41             getSize()     != LyXFont::IGNORE_SIZE ||
42             getBar()      != frnt::IGNORE ||
43             getColor()    != LColor::ignore ||
44             font_->language() != ignore_language)
45                 dialog().bc().valid();
46
47         return true;
48 }
49
50
51 void ControlCharacter::clearParams()
52 {}
53
54
55 void ControlCharacter::dispatchParams()
56 {
57         // Nothing to dispatch. (Can be called from the Toolbar.)
58         if (!font_.get())
59                 return;
60
61         string data;
62         if (font2string(*font_.get(), toggleall_, data)) {
63                 kernel().dispatch(FuncRequest(LFUN_FREEFONT_UPDATE, data));
64         }
65 }
66
67
68 LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
69 {
70         if (!font_.get())
71                 return LyXFont::IGNORE_FAMILY;
72         return font_->family();
73 }
74
75
76 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
77 {
78         font_->setFamily(val);
79 }
80
81
82 LyXFont::FONT_SERIES ControlCharacter::getSeries() const
83 {
84         if (!font_.get())
85                 return LyXFont::IGNORE_SERIES;
86         return font_->series();
87 }
88
89
90 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
91 {
92         font_->setSeries(val);
93 }
94
95
96 LyXFont::FONT_SHAPE ControlCharacter::getShape() const
97 {
98         if (!font_.get())
99                 return LyXFont::IGNORE_SHAPE;
100         return font_->shape();
101 }
102
103
104 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
105 {
106         font_->setShape(val);
107 }
108
109
110 LyXFont::FONT_SIZE ControlCharacter::getSize() const
111 {
112         if (!font_.get())
113                 return LyXFont::IGNORE_SIZE;
114         return font_->size();
115 }
116
117
118 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
119 {
120         font_->setSize(val);
121 }
122
123
124 frnt::FONT_STATE ControlCharacter::getBar() const
125 {
126         if (!font_.get())
127                 return frnt::IGNORE;
128
129         if (font_->emph() == LyXFont::TOGGLE)
130                 return frnt::EMPH_TOGGLE;
131
132         if (font_->underbar() == LyXFont::TOGGLE)
133                 return frnt::UNDERBAR_TOGGLE;
134
135         if (font_->noun() == LyXFont::TOGGLE)
136                 return frnt::NOUN_TOGGLE;
137
138         if (font_->emph() == LyXFont::IGNORE &&
139             font_->underbar() == LyXFont::IGNORE &&
140             font_->noun() == LyXFont::IGNORE)
141                 return frnt::IGNORE;
142
143         return frnt::INHERIT;
144 }
145
146
147 void ControlCharacter::setBar(frnt::FONT_STATE val)
148 {
149         switch (val) {
150         case frnt::IGNORE:
151                 font_->setEmph(LyXFont::IGNORE);
152                 font_->setUnderbar(LyXFont::IGNORE);
153                 font_->setNoun(LyXFont::IGNORE);
154                 break;
155
156         case frnt::EMPH_TOGGLE:
157                 font_->setEmph(LyXFont::TOGGLE);
158                 break;
159
160         case frnt::UNDERBAR_TOGGLE:
161                 font_->setUnderbar(LyXFont::TOGGLE);
162                 break;
163
164         case frnt::NOUN_TOGGLE:
165                 font_->setNoun(LyXFont::TOGGLE);
166                 break;
167
168         case frnt::INHERIT:
169                 font_->setEmph(LyXFont::INHERIT);
170                 font_->setUnderbar(LyXFont::INHERIT);
171                 font_->setNoun(LyXFont::INHERIT);
172                 break;
173         }
174 }
175
176
177 EnumLColor ControlCharacter::getColor() const
178 {
179         if (!font_.get())
180                 return LColor::ignore;
181
182         return font_->color();
183 }
184
185
186 void ControlCharacter::setColor(EnumLColor val)
187 {
188         switch (val) {
189         case LColor::ignore:
190         case LColor::none:
191         case LColor::black:
192         case LColor::white:
193         case LColor::red:
194         case LColor::green:
195         case LColor::blue:
196         case LColor::cyan:
197         case LColor::magenta:
198         case LColor::yellow:
199         case LColor::inherit:
200                 font_->setColor(val);
201                 break;
202         default:
203                 break;
204         }
205 }
206
207
208 string ControlCharacter::getLanguage() const
209 {
210         if (font_.get() && font_->language())
211                 return font_->language()->lang();
212         return "ignore";
213 }
214
215
216 void ControlCharacter::setLanguage(string const & val)
217 {
218         if (val == "ignore")
219                 font_->setLanguage(ignore_language);
220
221         else if (val == "reset")
222                 font_->setLanguage(kernel().buffer().params().language);
223
224         else
225                 font_->setLanguage(languages.getLanguage(val));
226 }
227
228
229 bool ControlCharacter::getToggleAll() const
230 {
231         return toggleall_;
232 }
233
234
235 void ControlCharacter::setToggleAll(bool t)
236 {
237         toggleall_ = t;
238 }