2 * \file ControlCharacter.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@ic.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;
34 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
35 : ControlDialogBD(lv, d),
36 font_(0), toggleall_(false)
38 d_.showCharacter.connect(slot(this, &ControlCharacter::show));
39 d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
43 void ControlCharacter::setParams()
45 // Do this the first time only. Used as a flag for whether or not the
46 // view has been built
48 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
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)
62 void ControlCharacter::apply()
64 // Nothing to apply. (Can be called from the Toolbar.)
68 // Apply from the view if it's visible. Otherwise, use the stored values
69 if (lv_.view()->available())
72 toggleAndShow(lv_.view(), *(font_.get()), toggleall_);
73 lv_.view()->setState();
74 lv_.buffer()->markDirty();
75 setMinibuffer(&lv_, _("Character set"));
79 LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
82 return LyXFont::IGNORE_FAMILY;
83 return font_->family();
87 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
89 font_->setFamily(val);
93 LyXFont::FONT_SERIES ControlCharacter::getSeries() const
96 return LyXFont::IGNORE_SERIES;
97 return font_->series();
101 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
103 font_->setSeries(val);
107 LyXFont::FONT_SHAPE ControlCharacter::getShape() const
110 return LyXFont::IGNORE_SHAPE;
111 return font_->shape();
115 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
117 font_->setShape(val);
121 LyXFont::FONT_SIZE ControlCharacter::getSize() const
124 return LyXFont::IGNORE_SIZE;
125 return font_->size();
129 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
135 character::FONT_STATE ControlCharacter::getBar() const
138 return character::IGNORE;
140 if (font_->emph() == LyXFont::TOGGLE)
141 return character::EMPH_TOGGLE;
143 if (font_->underbar() == LyXFont::TOGGLE)
144 return character::UNDERBAR_TOGGLE;
146 if (font_->noun() == LyXFont::TOGGLE)
147 return character::NOUN_TOGGLE;
149 if (font_->emph() == LyXFont::IGNORE &&
150 font_->underbar() == LyXFont::IGNORE &&
151 font_->noun() == LyXFont::IGNORE)
152 return character::IGNORE;
154 return character::INHERIT;
158 void ControlCharacter::setBar(character::FONT_STATE val)
161 case character::IGNORE:
162 font_->setEmph(LyXFont::IGNORE);
163 font_->setUnderbar(LyXFont::IGNORE);
164 font_->setNoun(LyXFont::IGNORE);
167 case character::EMPH_TOGGLE:
168 font_->setEmph(LyXFont::TOGGLE);
171 case character::UNDERBAR_TOGGLE:
172 font_->setUnderbar(LyXFont::TOGGLE);
175 case character::NOUN_TOGGLE:
176 font_->setNoun(LyXFont::TOGGLE);
179 case character::INHERIT:
180 font_->setEmph(LyXFont::INHERIT);
181 font_->setUnderbar(LyXFont::INHERIT);
182 font_->setNoun(LyXFont::INHERIT);
188 LColor::color ControlCharacter::getColor() const
191 return LColor::ignore;
193 return font_->color();
197 void ControlCharacter::setColor(LColor::color val)
208 case LColor::magenta:
210 case LColor::inherit:
211 font_->setColor(val);
219 string ControlCharacter::getLanguage() const
221 if (font_.get() && font_->language())
222 return font_->language()->lang();
223 return _("No change");
227 void ControlCharacter::setLanguage(string const & val)
229 if (val == _("No change"))
230 font_->setLanguage(ignore_language);
232 else if (val == _("Reset"))
233 font_->setLanguage(lv_.buffer()->params.language);
236 font_->setLanguage(languages.getLanguage(val));
240 bool ControlCharacter::getToggleAll() const
246 void ControlCharacter::setToggleAll(bool t)