]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCharacter.C
Move the external dialog to the new scheme.
[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
14 #include "ControlCharacter.h"
15
16 #include "ViewBase.h"
17 #include "ButtonControllerBase.h"
18
19 #include "buffer.h"
20 #include "bufferview_funcs.h" // ToggleAndShow
21 #include "gettext.h"
22 #include "language.h"
23
24 #include "frontends/LyXView.h"
25
26
27 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
28         : ControlDialogBD(lv, d),
29           font_(0), toggleall_(false)
30 {}
31
32
33 void ControlCharacter::setParams()
34 {
35         // Do this the first time only. Used as a flag for whether or not the
36         // view has been built
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                 bc().valid();
49 }
50
51
52 void ControlCharacter::apply()
53 {
54         // Nothing to apply. (Can be called from the Toolbar.)
55         if (!font_.get())
56                 return;
57
58         // Apply from the view if it's visible. Otherwise, use the stored values
59         if (bufferIsAvailable())
60                 view().apply();
61
62         toggleAndShow(bufferview(), *(font_.get()), toggleall_);
63         lv_.view_state_changed();
64         buffer()->markDirty();
65         lv_.message(_("Character set"));
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 LColor::color ControlCharacter::getColor() const
179 {
180         if (!font_.get())
181                 return LColor::ignore;
182
183         return font_->color();
184 }
185
186
187 void ControlCharacter::setColor(LColor::color 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(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 }