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