]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCharacter.C
prefs/tabular MVC work
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlCharacter.h"
18
19 #include "ViewBase.h"
20 #include "ButtonControllerBase.h"
21
22 #include "buffer.h"
23 #include "bufferview_funcs.h" // ToggleAndShow
24 #include "gettext.h"
25 #include "language.h"
26
27 #include "frontends/LyXView.h"
28
29
30 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
31         : ControlDialogBD(lv, d),
32           font_(0), toggleall_(false)
33 {}
34
35
36 void ControlCharacter::setParams()
37 {
38         // Do this the first time only. Used as a flag for whether or not the
39         // view has been built
40         if (!font_.get())
41                 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
42
43         // so that the user can press Ok
44         if (getFamily()   != LyXFont::IGNORE_FAMILY ||
45             getSeries()   != LyXFont::IGNORE_SERIES ||
46             getShape()    != LyXFont::IGNORE_SHAPE  ||
47             getSize()     != LyXFont::IGNORE_SIZE ||
48             getBar()      != frnt::IGNORE ||
49             getColor()    != LColor::ignore ||
50             font_->language() != ignore_language)
51                 bc().valid();
52 }
53
54
55 void ControlCharacter::apply()
56 {
57         // Nothing to apply. (Can be called from the Toolbar.)
58         if (!font_.get())
59                 return;
60
61         // Apply from the view if it's visible. Otherwise, use the stored values
62         if (bufferIsAvailable())
63                 view().apply();
64
65         toggleAndShow(bufferview(), *(font_.get()), toggleall_);
66         lv_.view_state_changed();
67         buffer()->markDirty();
68         lv_.message(_("Character set"));
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 frnt::FONT_STATE ControlCharacter::getBar() const
129 {
130         if (!font_.get())
131                 return frnt::IGNORE;
132
133         if (font_->emph() == LyXFont::TOGGLE)
134                 return frnt::EMPH_TOGGLE;
135
136         if (font_->underbar() == LyXFont::TOGGLE)
137                 return frnt::UNDERBAR_TOGGLE;
138
139         if (font_->noun() == LyXFont::TOGGLE)
140                 return frnt::NOUN_TOGGLE;
141
142         if (font_->emph() == LyXFont::IGNORE &&
143             font_->underbar() == LyXFont::IGNORE &&
144             font_->noun() == LyXFont::IGNORE)
145                 return frnt::IGNORE;
146
147         return frnt::INHERIT;
148 }
149
150
151 void ControlCharacter::setBar(frnt::FONT_STATE val)
152 {
153         switch (val) {
154         case frnt::IGNORE:
155                 font_->setEmph(LyXFont::IGNORE);
156                 font_->setUnderbar(LyXFont::IGNORE);
157                 font_->setNoun(LyXFont::IGNORE);
158                 break;
159
160         case frnt::EMPH_TOGGLE:
161                 font_->setEmph(LyXFont::TOGGLE);
162                 break;
163
164         case frnt::UNDERBAR_TOGGLE:
165                 font_->setUnderbar(LyXFont::TOGGLE);
166                 break;
167
168         case frnt::NOUN_TOGGLE:
169                 font_->setNoun(LyXFont::TOGGLE);
170                 break;
171
172         case frnt::INHERIT:
173                 font_->setEmph(LyXFont::INHERIT);
174                 font_->setUnderbar(LyXFont::INHERIT);
175                 font_->setNoun(LyXFont::INHERIT);
176                 break;
177         }
178 }
179
180
181 LColor::color ControlCharacter::getColor() const
182 {
183         if (!font_.get())
184                 return LColor::ignore;
185
186         return font_->color();
187 }
188
189
190 void ControlCharacter::setColor(LColor::color val)
191 {
192         switch (val) {
193         case LColor::ignore:
194         case LColor::none:
195         case LColor::black:
196         case LColor::white:
197         case LColor::red:
198         case LColor::green:
199         case LColor::blue:
200         case LColor::cyan:
201         case LColor::magenta:
202         case LColor::yellow:
203         case LColor::inherit:
204                 font_->setColor(val);
205                 break;
206         default:
207                 break;
208         }
209 }
210
211
212 string ControlCharacter::getLanguage() const
213 {
214         if (font_.get() && font_->language())
215                 return font_->language()->lang();
216         return "ignore";
217 }
218
219
220 void ControlCharacter::setLanguage(string const & val)
221 {
222         if (val == "ignore")
223                 font_->setLanguage(ignore_language);
224
225         else if (val == "reset")
226                 font_->setLanguage(buffer()->params.language);
227
228         else
229                 font_->setLanguage(languages.getLanguage(val));
230 }
231
232
233 bool ControlCharacter::getToggleAll() const
234 {
235         return toggleall_;
236 }
237
238
239 void ControlCharacter::setToggleAll(bool t)
240 {
241         toggleall_ = t;
242 }