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