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