]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCharacter.C
Really dull and boring header shit
[lyx.git] / src / frontends / controllers / ControlCharacter.C
1 /**
2  * \file ControlCharacter.C
3  * See the file COPYING.
4  *
5  * \author Angus Leeming 
6  *
7  * Full author contact details are available in file CREDITS
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "ControlCharacter.h"
17
18 #include "ViewBase.h"
19 #include "ButtonControllerBase.h"
20
21 #include "buffer.h"
22 #include "bufferview_funcs.h" // ToggleAndShow
23 #include "gettext.h"
24 #include "language.h"
25
26 #include "frontends/Liason.h"
27 #include "frontends/LyXView.h"
28
29 using Liason::setMinibuffer;
30
31
32 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
33         : ControlDialogBD(lv, d),
34           font_(0), toggleall_(false)
35 {}
36
37
38 void ControlCharacter::setParams()
39 {
40         // Do this the first time only. Used as a flag for whether or not the
41         // view has been built
42         if (!font_.get())
43                 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
44
45         // so that the user can press Ok
46         if (getFamily()   != LyXFont::IGNORE_FAMILY ||
47             getSeries()   != LyXFont::IGNORE_SERIES ||
48             getShape()    != LyXFont::IGNORE_SHAPE  ||
49             getSize()     != LyXFont::IGNORE_SIZE ||
50             getBar()      != frnt::IGNORE ||
51             getColor()    != LColor::ignore ||
52             font_->language() != ignore_language)
53                 bc().valid();
54 }
55
56
57 void ControlCharacter::apply()
58 {
59         // Nothing to apply. (Can be called from the Toolbar.)
60         if (!font_.get())
61                 return;
62
63         // Apply from the view if it's visible. Otherwise, use the stored values
64         if (bufferIsAvailable())
65                 view().apply();
66
67         toggleAndShow(bufferview(), *(font_.get()), toggleall_);
68         lv_.view_state_changed();
69         buffer()->markDirty();
70         setMinibuffer(&lv_, _("Character set"));
71 }
72
73
74 LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
75 {
76         if (!font_.get())
77                 return LyXFont::IGNORE_FAMILY;
78         return font_->family();
79 }
80
81
82 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
83 {
84         font_->setFamily(val);
85 }
86
87
88 LyXFont::FONT_SERIES ControlCharacter::getSeries() const
89 {
90         if (!font_.get())
91                 return LyXFont::IGNORE_SERIES;
92         return font_->series();
93 }
94
95
96 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
97 {
98         font_->setSeries(val);
99 }
100
101
102 LyXFont::FONT_SHAPE ControlCharacter::getShape() const
103 {
104         if (!font_.get())
105                 return LyXFont::IGNORE_SHAPE;
106         return font_->shape();
107 }
108
109
110 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
111 {
112         font_->setShape(val);
113 }
114
115
116 LyXFont::FONT_SIZE ControlCharacter::getSize() const
117 {
118         if (!font_.get())
119                 return LyXFont::IGNORE_SIZE;
120         return font_->size();
121 }
122
123
124 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
125 {
126         font_->setSize(val);
127 }
128
129
130 frnt::FONT_STATE ControlCharacter::getBar() const
131 {
132         if (!font_.get())
133                 return frnt::IGNORE;
134
135         if (font_->emph() == LyXFont::TOGGLE)
136                 return frnt::EMPH_TOGGLE;
137
138         if (font_->underbar() == LyXFont::TOGGLE)
139                 return frnt::UNDERBAR_TOGGLE;
140
141         if (font_->noun() == LyXFont::TOGGLE)
142                 return frnt::NOUN_TOGGLE;
143
144         if (font_->emph() == LyXFont::IGNORE &&
145             font_->underbar() == LyXFont::IGNORE &&
146             font_->noun() == LyXFont::IGNORE)
147                 return frnt::IGNORE;
148
149         return frnt::INHERIT;
150 }
151
152
153 void ControlCharacter::setBar(frnt::FONT_STATE val)
154 {
155         switch (val) {
156         case frnt::IGNORE:
157                 font_->setEmph(LyXFont::IGNORE);
158                 font_->setUnderbar(LyXFont::IGNORE);
159                 font_->setNoun(LyXFont::IGNORE);
160                 break;
161
162         case frnt::EMPH_TOGGLE:
163                 font_->setEmph(LyXFont::TOGGLE);
164                 break;
165
166         case frnt::UNDERBAR_TOGGLE:
167                 font_->setUnderbar(LyXFont::TOGGLE);
168                 break;
169
170         case frnt::NOUN_TOGGLE:
171                 font_->setNoun(LyXFont::TOGGLE);
172                 break;
173
174         case frnt::INHERIT:
175                 font_->setEmph(LyXFont::INHERIT);
176                 font_->setUnderbar(LyXFont::INHERIT);
177                 font_->setNoun(LyXFont::INHERIT);
178                 break;
179         }
180 }
181
182
183 LColor::color ControlCharacter::getColor() const
184 {
185         if (!font_.get())
186                 return LColor::ignore;
187
188         return font_->color();
189 }
190
191
192 void ControlCharacter::setColor(LColor::color val)
193 {
194         switch (val) {
195         case LColor::ignore:
196         case LColor::none:
197         case LColor::black:
198         case LColor::white:
199         case LColor::red:
200         case LColor::green:
201         case LColor::blue:
202         case LColor::cyan:
203         case LColor::magenta:
204         case LColor::yellow:
205         case LColor::inherit:
206                 font_->setColor(val);
207                 break;
208         default:
209                 break;
210         }
211 }
212
213
214 string ControlCharacter::getLanguage() const
215 {
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
227         else if (val == "reset")
228                 font_->setLanguage(buffer()->params.language);
229
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 }