2001-03-21 13:27:03 +00:00
|
|
|
/**
|
|
|
|
* \file ControlCharacter.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming, a.leeming@.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2001-03-21 19:14:09 +00:00
|
|
|
#ifdef __GNUG__
|
2001-03-21 13:27:03 +00:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-21 13:27:03 +00:00
|
|
|
#include "ControlCharacter.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "buffer.h"
|
2001-03-21 13:27:03 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "LyXView.h"
|
2001-03-28 12:59:29 +00:00
|
|
|
#include "bufferview_funcs.h" // ToggleAndShow
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "language.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
using Liason::setMinibuffer;
|
|
|
|
using SigC::slot;
|
|
|
|
using std::vector;
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
|
2001-03-22 11:24:36 +00:00
|
|
|
: ControlDialog<ControlConnectBD>(lv, d),
|
|
|
|
font_(0), toggleall_(false)
|
2001-03-21 13:27:03 +00:00
|
|
|
{
|
2001-06-15 16:18:43 +00:00
|
|
|
d_.showCharacter.connect(slot(this, &ControlCharacter::show));
|
2001-03-27 10:44:14 +00:00
|
|
|
d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
|
2001-03-21 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-22 11:24:36 +00:00
|
|
|
void ControlCharacter::setParams()
|
2001-03-21 13:27:03 +00:00
|
|
|
{
|
2001-06-13 13:44:23 +00:00
|
|
|
// 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));
|
2001-03-21 13:27:03 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
// 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();
|
2001-03-21 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlCharacter::apply()
|
|
|
|
{
|
2001-06-13 13:44:23 +00:00
|
|
|
// Nothing to apply. (Can be called from the Toolbar.)
|
|
|
|
if (!font_.get())
|
2001-03-21 13:27:03 +00:00
|
|
|
return;
|
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
// Apply from the view if it's visible. Otherwise, use the stored values
|
|
|
|
if (lv_.view()->available())
|
|
|
|
view().apply();
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(lv_.view(), *(font_.get()), toggleall_);
|
2001-03-21 13:27:03 +00:00
|
|
|
lv_.view()->setState();
|
|
|
|
lv_.buffer()->markDirty();
|
|
|
|
setMinibuffer(&lv_, _("Character set"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
|
|
|
|
{
|
|
|
|
if (font_.get())
|
|
|
|
return font_->family();
|
|
|
|
return LyXFont::IGNORE_FAMILY;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
|
|
|
|
{
|
|
|
|
font_->setFamily(val);
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
LyXFont::FONT_SERIES ControlCharacter::getSeries() const
|
|
|
|
{
|
|
|
|
if (font_.get())
|
|
|
|
return font_->series();
|
|
|
|
return LyXFont::IGNORE_SERIES;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
|
|
|
|
{
|
|
|
|
font_->setSeries(val);
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
LyXFont::FONT_SHAPE ControlCharacter::getShape() const
|
|
|
|
{
|
|
|
|
if (font_.get())
|
|
|
|
return font_->shape();
|
|
|
|
return LyXFont::IGNORE_SHAPE;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
|
|
|
|
{
|
|
|
|
font_->setShape(val);
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
LyXFont::FONT_SIZE ControlCharacter::getSize() const
|
|
|
|
{
|
|
|
|
if (font_.get())
|
|
|
|
return font_->size();
|
|
|
|
return LyXFont::IGNORE_SIZE;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
|
|
|
|
{
|
|
|
|
font_->setSize(val);
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
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;
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-06-13 13:44:23 +00:00
|
|
|
else if (font_->latex() != LyXFont::IGNORE)
|
|
|
|
return character::LATEX_TOGGLE;
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
2001-06-13 13:44:23 +00:00
|
|
|
}
|
|
|
|
return character::IGNORE;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
void ControlCharacter::setBar(character::FONT_STATE val)
|
2001-03-21 13:27:03 +00:00
|
|
|
{
|
|
|
|
switch (val) {
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::IGNORE:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setEmph(LyXFont::IGNORE);
|
|
|
|
font_->setUnderbar(LyXFont::IGNORE);
|
|
|
|
font_->setNoun(LyXFont::IGNORE);
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setLatex(LyXFont::IGNORE);
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
2001-03-21 13:27:03 +00:00
|
|
|
break;
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::EMPH_TOGGLE:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setEmph(LyXFont::TOGGLE);
|
|
|
|
break;
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::UNDERBAR_TOGGLE:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setUnderbar(LyXFont::TOGGLE);
|
|
|
|
break;
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::NOUN_TOGGLE:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setNoun(LyXFont::TOGGLE);
|
|
|
|
break;
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::LATEX_TOGGLE:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setLatex(LyXFont::TOGGLE);
|
|
|
|
break;
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-28 12:59:29 +00:00
|
|
|
case character::INHERIT:
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setEmph(LyXFont::INHERIT);
|
|
|
|
font_->setUnderbar(LyXFont::INHERIT);
|
|
|
|
font_->setNoun(LyXFont::INHERIT);
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-03-21 13:27:03 +00:00
|
|
|
font_->setLatex(LyXFont::INHERIT);
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
2001-03-21 13:27:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
|
|
|
|
string ControlCharacter::getLanguage() const
|
|
|
|
{
|
|
|
|
if (font_.get() && font_->language())
|
|
|
|
return font_->language()->lang();
|
|
|
|
return _("No change");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
|
|
|
|
bool ControlCharacter::getToggleAll() const
|
|
|
|
{
|
|
|
|
return toggleall_;
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
void ControlCharacter::setToggleAll(bool t)
|
|
|
|
{
|
|
|
|
toggleall_ = t;
|
|
|
|
}
|