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