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