2 * \file ControlCharacter.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@.ac.uk
12 #pragma implementation
18 #include "ButtonControllerBase.h"
19 #include "ControlCharacter.h"
24 #include "bufferview_funcs.h" // ToggleAndShow
27 #include "BufferView.h"
29 using Liason::setMinibuffer;
33 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
34 : ControlDialog<ControlConnectBD>(lv, d),
35 font_(0), toggleall_(false)
37 d_.showCharacter.connect(slot(this, &ControlCharacter::show));
38 d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
42 void ControlCharacter::setParams()
44 // Do this the first time only. Used as a flag for whether or not the
45 // view has been built
47 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
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)
61 void ControlCharacter::apply()
63 // Nothing to apply. (Can be called from the Toolbar.)
67 // Apply from the view if it's visible. Otherwise, use the stored values
68 if (lv_.view()->available())
71 ToggleAndShow(lv_.view(), *(font_.get()), toggleall_);
72 lv_.view()->setState();
73 lv_.buffer()->markDirty();
74 setMinibuffer(&lv_, _("Character set"));
78 LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
81 return font_->family();
82 return LyXFont::IGNORE_FAMILY;
85 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
87 font_->setFamily(val);
90 LyXFont::FONT_SERIES ControlCharacter::getSeries() const
93 return font_->series();
94 return LyXFont::IGNORE_SERIES;
97 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
99 font_->setSeries(val);
102 LyXFont::FONT_SHAPE ControlCharacter::getShape() const
105 return font_->shape();
106 return LyXFont::IGNORE_SHAPE;
109 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
111 font_->setShape(val);
114 LyXFont::FONT_SIZE ControlCharacter::getSize() const
117 return font_->size();
118 return LyXFont::IGNORE_SIZE;
121 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
126 character::FONT_STATE ControlCharacter::getBar() const
129 if (font_->emph() != LyXFont::IGNORE)
130 return character::EMPH_TOGGLE;
132 else if (font_->underbar() != LyXFont::IGNORE)
133 return character::UNDERBAR_TOGGLE;
135 else if (font_->noun() != LyXFont::IGNORE)
136 return character::NOUN_TOGGLE;
138 else if (font_->latex() != LyXFont::IGNORE)
139 return character::LATEX_TOGGLE;
141 return character::IGNORE;
144 void ControlCharacter::setBar(character::FONT_STATE 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);
154 case character::EMPH_TOGGLE:
155 font_->setEmph(LyXFont::TOGGLE);
158 case character::UNDERBAR_TOGGLE:
159 font_->setUnderbar(LyXFont::TOGGLE);
162 case character::NOUN_TOGGLE:
163 font_->setNoun(LyXFont::TOGGLE);
166 case character::LATEX_TOGGLE:
167 font_->setLatex(LyXFont::TOGGLE);
170 case character::INHERIT:
171 font_->setEmph(LyXFont::INHERIT);
172 font_->setUnderbar(LyXFont::INHERIT);
173 font_->setNoun(LyXFont::INHERIT);
174 font_->setLatex(LyXFont::INHERIT);
179 LColor::color ControlCharacter::getColor() const
181 LColor::color col = LColor::ignore;
184 switch (font_->color()) {
193 case LColor::magenta:
195 case LColor::inherit:
198 col = font_->color();
206 void ControlCharacter::setColor(LColor::color val)
217 case LColor::magenta:
219 case LColor::inherit:
220 font_->setColor(val);
228 string ControlCharacter::getLanguage() const
230 if (font_.get() && font_->language())
231 return font_->language()->lang();
232 return _("No change");
236 void ControlCharacter::setLanguage(string const & val)
238 if (val == _("No change"))
239 font_->setLanguage(ignore_language);
241 else if ( val == _("Reset"))
242 font_->setLanguage(lv_.buffer()->params.language);
245 font_->setLanguage(languages.getLanguage(val));
249 bool ControlCharacter::getToggleAll() const
254 void ControlCharacter::setToggleAll(bool t)