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