2003-11-12 14:38:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcharstyle.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Martin Vermeer
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetcharstyle.h"
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "dispatchresult.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "metricsinfo.h"
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ostringstream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::init()
|
|
|
|
|
{
|
|
|
|
|
setInsetName("CharStyle");
|
2003-12-06 09:31:30 +00:00
|
|
|
|
setStatus(Inlined);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
CharStyles::iterator cs)
|
2003-12-06 09:31:30 +00:00
|
|
|
|
: InsetCollapsable(bp), has_label_(true)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
params_.type = cs->name;
|
|
|
|
|
params_.latextype = cs->latextype;
|
|
|
|
|
params_.latexname = cs->latexname;
|
2003-12-01 16:01:50 +00:00
|
|
|
|
params_.latexparam = cs->latexparam;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
params_.font = cs->font;
|
|
|
|
|
params_.labelfont = cs->labelfont;
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
|
2003-12-06 09:31:30 +00:00
|
|
|
|
: InsetCollapsable(in), params_(in.params_), has_label_(true)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto_ptr<InsetBase> InsetCharStyle::clone() const
|
|
|
|
|
{
|
|
|
|
|
return auto_ptr<InsetBase>(new InsetCharStyle(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetCharStyle::editMessage() const
|
|
|
|
|
{
|
|
|
|
|
return _("Opened CharStyle Inset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::write(Buffer const & buf, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
InsetCollapsable::read(buf, lex);
|
2003-12-06 09:31:30 +00:00
|
|
|
|
setStatus(Inlined);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2003-12-16 18:49:04 +00:00
|
|
|
|
LyXFont tmpfont = mi.base.font;
|
|
|
|
|
getDrawFont(mi.base.font);
|
2003-12-06 09:31:30 +00:00
|
|
|
|
InsetCollapsable::metrics(mi, dim);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
mi.base.font = tmpfont;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
dim_ = dim;
|
|
|
|
|
if (has_label_)
|
|
|
|
|
dim_.des += ascent();
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-12-06 09:31:30 +00:00
|
|
|
|
|
2003-12-12 14:02:14 +00:00
|
|
|
|
// FIXME: setStatus(Inlined); this is not a const operation
|
2003-12-16 18:49:04 +00:00
|
|
|
|
LyXFont tmpfont = pi.base.font;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
inset.setDrawFrame(InsetText::NEVER);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
getDrawFont(pi.base.font);
|
2003-12-06 09:31:30 +00:00
|
|
|
|
inset.draw(pi, x, y);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
pi.base.font = tmpfont;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
|
|
|
|
|
pi.pain.line(x + 2, y + inset.descent() - 4, x + 2,
|
|
|
|
|
y + inset.descent(), params_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + 2, y + inset.descent(), x + dim_.wid - 2,
|
|
|
|
|
y + inset.descent(), params_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + dim_.wid - 2, y + inset.descent(), x + dim_.wid - 2,
|
|
|
|
|
y + inset.descent() - 4, params_.labelfont.color());
|
|
|
|
|
|
|
|
|
|
if (has_label_) {
|
|
|
|
|
if (!owner())
|
|
|
|
|
x += scroll();
|
|
|
|
|
|
|
|
|
|
LyXFont font(params_.labelfont);
|
|
|
|
|
font.realize(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
|
|
|
|
font_metrics::rectText(params_.type, font, w, a, d);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
pi.pain.rectText(x + (dim_.wid - w) / 2,
|
2003-12-06 09:31:30 +00:00
|
|
|
|
y + inset.descent() + a,
|
|
|
|
|
params_.type, font, LColor::none, LColor::none);
|
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
|
|
|
|
font = params_.font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2003-12-06 09:31:30 +00:00
|
|
|
|
setStatus(Inlined);
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button3)
|
2003-12-06 09:31:30 +00:00
|
|
|
|
has_label_ = !has_label_;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
else
|
|
|
|
|
inset.dispatch(cur, cmd);
|
|
|
|
|
break;
|
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
default:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
InsetCollapsable::priv_dispatch(cur, cmd);
|
|
|
|
|
break;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
int outputVerbatim(std::ostream & os, InsetText inset)
|
|
|
|
|
{
|
|
|
|
|
int lines = 0;
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs().end();
|
2003-11-12 14:38:26 +00:00
|
|
|
|
while (par != end) {
|
|
|
|
|
lyx::pos_type siz = par->size();
|
|
|
|
|
for (lyx::pos_type i = 0; i < siz; ++i) {
|
|
|
|
|
if (par->isNewline(i)) {
|
|
|
|
|
os << '\n';
|
|
|
|
|
++lines;
|
|
|
|
|
} else {
|
|
|
|
|
os << par->getChar(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++par;
|
|
|
|
|
if (par != end) {
|
|
|
|
|
os << "\n";
|
|
|
|
|
lines ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2003-11-20 01:22:51 +00:00
|
|
|
|
int InsetCharStyle::latex(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2003-12-01 16:01:50 +00:00
|
|
|
|
os << "%\n\\" << params_.latexname;
|
|
|
|
|
if (!params_.latexparam.empty())
|
|
|
|
|
os << params_.latexparam;
|
|
|
|
|
os << "{";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
int i = outputVerbatim(os, inset);
|
|
|
|
|
os << "}%\n";
|
|
|
|
|
i += 2;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-20 01:22:51 +00:00
|
|
|
|
int InsetCharStyle::linuxdoc(Buffer const &, std::ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2003-12-01 16:01:50 +00:00
|
|
|
|
os << "<" << params_.latexname;
|
|
|
|
|
if (!params_.latexparam.empty())
|
|
|
|
|
os << " " << params_.latexparam;
|
|
|
|
|
os << ">";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
int const i = outputVerbatim(os, inset);
|
|
|
|
|
os << "</" << params_.latexname << ">";
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-20 01:22:51 +00:00
|
|
|
|
int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2003-12-01 16:01:50 +00:00
|
|
|
|
os << "<" << params_.latexname;
|
|
|
|
|
if (!params_.latexparam.empty())
|
|
|
|
|
os << " " << params_.latexparam;
|
|
|
|
|
os << ">";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
int const i = outputVerbatim(os, inset);
|
|
|
|
|
os << "</" << params_.latexname << ">";
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-20 01:22:51 +00:00
|
|
|
|
int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
|
2004-01-20 14:25:24 +00:00
|
|
|
|
OutputParams const & /*runparams*/) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
return outputVerbatim(os, inset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require(params_.type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyleParams::write(ostream & os) const
|
|
|
|
|
{
|
2003-11-28 10:12:04 +00:00
|
|
|
|
os << "CharStyle " << type << "\n";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyleParams::read(LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
type = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
}
|