lyx_mirror/src/frontends/controllers/ControlCharacter.C

278 lines
5.3 KiB
C++
Raw Normal View History

/**
* \file ControlCharacter.C
* Copyright 2001 The LyX Team.
* See the file COPYING.
*
* \author Angus Leeming, a.leeming@.ac.uk
*/
#include <vector>
#ifdef __GNUG__
#pragma implementation
#endif
#include <config.h>
#include "ViewBase.h"
#include "ButtonControllerBase.h"
#include "ControlCharacter.h"
#include "buffer.h"
#include "Dialogs.h"
#include "Liason.h"
#include "LyXView.h"
#include "bufferview_funcs.h" // ToggleAndShow
#include "gettext.h"
#include "language.h"
#include "BufferView.h"
using Liason::setMinibuffer;
using SigC::slot;
using std::vector;
ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
: ControlDialog<ControlConnectBD>(lv, d),
font_(0), toggleall_(false)
{
d_.showCharacter.connect(slot(this, &ControlCharacter::show));
d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
}
void ControlCharacter::setParams()
{
// Do this the first time only. Used as a flag for whether or not the
// view has been built
if (!font_.get())
font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
// so that the user can press Ok
if (getFamily() != LyXFont::IGNORE_FAMILY ||
getSeries() != LyXFont::IGNORE_SERIES ||
getShape() != LyXFont::IGNORE_SHAPE ||
getSize() != LyXFont::IGNORE_SIZE ||
getBar() != character::IGNORE ||
getColor() != LColor::ignore ||
font_->language() != ignore_language)
bc().valid();
}
void ControlCharacter::apply()
{
// Nothing to apply. (Can be called from the Toolbar.)
if (!font_.get())
return;
// Apply from the view if it's visible. Otherwise, use the stored values
if (lv_.view()->available())
view().apply();
toggleAndShow(lv_.view(), *(font_.get()), toggleall_);
lv_.view()->setState();
lv_.buffer()->markDirty();
setMinibuffer(&lv_, _("Character set"));
}
LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
{
if (font_.get())
return font_->family();
return LyXFont::IGNORE_FAMILY;
}
void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
{
font_->setFamily(val);
}
LyXFont::FONT_SERIES ControlCharacter::getSeries() const
{
if (font_.get())
return font_->series();
return LyXFont::IGNORE_SERIES;
}
void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
{
font_->setSeries(val);
}
LyXFont::FONT_SHAPE ControlCharacter::getShape() const
{
if (font_.get())
return font_->shape();
return LyXFont::IGNORE_SHAPE;
}
void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
{
font_->setShape(val);
}
LyXFont::FONT_SIZE ControlCharacter::getSize() const
{
if (font_.get())
return font_->size();
return LyXFont::IGNORE_SIZE;
}
void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
{
font_->setSize(val);
}
character::FONT_STATE ControlCharacter::getBar() const
{
if (font_.get()) {
if (font_->emph() != LyXFont::IGNORE)
return character::EMPH_TOGGLE;
else if (font_->underbar() != LyXFont::IGNORE)
return character::UNDERBAR_TOGGLE;
else if (font_->noun() != LyXFont::IGNORE)
return character::NOUN_TOGGLE;
#ifndef NO_LATEX
else if (font_->latex() != LyXFont::IGNORE)
return character::LATEX_TOGGLE;
#endif
}
return character::IGNORE;
}
void ControlCharacter::setBar(character::FONT_STATE val)
{
switch (val) {
case character::IGNORE:
font_->setEmph(LyXFont::IGNORE);
font_->setUnderbar(LyXFont::IGNORE);
font_->setNoun(LyXFont::IGNORE);
#ifndef NO_LATEX
font_->setLatex(LyXFont::IGNORE);
#endif
break;
case character::EMPH_TOGGLE:
font_->setEmph(LyXFont::TOGGLE);
break;
case character::UNDERBAR_TOGGLE:
font_->setUnderbar(LyXFont::TOGGLE);
break;
case character::NOUN_TOGGLE:
font_->setNoun(LyXFont::TOGGLE);
break;
#ifndef NO_LATEX
case character::LATEX_TOGGLE:
font_->setLatex(LyXFont::TOGGLE);
break;
#endif
case character::INHERIT:
font_->setEmph(LyXFont::INHERIT);
font_->setUnderbar(LyXFont::INHERIT);
font_->setNoun(LyXFont::INHERIT);
#ifndef NO_LATEX
font_->setLatex(LyXFont::INHERIT);
#endif
break;
}
}
LColor::color ControlCharacter::getColor() const
{
LColor::color col = LColor::ignore;
if (font_.get()) {
switch (font_->color()) {
case LColor::ignore:
case LColor::none:
case LColor::black:
case LColor::white:
case LColor::red:
case LColor::green:
case LColor::blue:
case LColor::cyan:
case LColor::magenta:
case LColor::yellow:
case LColor::inherit:
break;
default:
col = font_->color();
break;
}
}
return col;
}
void ControlCharacter::setColor(LColor::color val)
{
switch (val) {
case LColor::ignore:
case LColor::none:
case LColor::black:
case LColor::white:
case LColor::red:
case LColor::green:
case LColor::blue:
case LColor::cyan:
case LColor::magenta:
case LColor::yellow:
case LColor::inherit:
font_->setColor(val);
break;
default:
break;
}
}
string ControlCharacter::getLanguage() const
{
if (font_.get() && font_->language())
return font_->language()->lang();
return _("No change");
}
void ControlCharacter::setLanguage(string const & val)
{
if (val == _("No change"))
font_->setLanguage(ignore_language);
else if ( val == _("Reset"))
font_->setLanguage(lv_.buffer()->params.language);
else
font_->setLanguage(languages.getLanguage(val));
}
bool ControlCharacter::getToggleAll() const
{
return toggleall_;
}
void ControlCharacter::setToggleAll(bool t)
{
toggleall_ = t;
}