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