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"
|
2004-11-04 19:50:04 +00:00
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "cursor.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "metricsinfo.h"
|
|
|
|
|
#include "paragraph.h"
|
2004-10-30 22:14:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2004-10-28 15:10:10 +00:00
|
|
|
|
#include "sgml.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
using std::istringstream;
|
2005-09-06 16:27:24 +00:00
|
|
|
|
using std::max;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ostringstream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::init()
|
|
|
|
|
{
|
|
|
|
|
setInsetName("CharStyle");
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setInlined();
|
2004-10-31 12:30:26 +00:00
|
|
|
|
setDrawFrame(false);
|
|
|
|
|
has_label_ = true;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
|
|
|
|
|
: InsetCollapsable(bp)
|
|
|
|
|
{
|
|
|
|
|
params_.type = s;
|
|
|
|
|
setUndefined();
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
CharStyles::iterator cs)
|
2004-10-31 12:30:26 +00:00
|
|
|
|
: InsetCollapsable(bp)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
params_.type = cs->name;
|
2005-05-04 11:21:14 +00:00
|
|
|
|
setDefined(cs);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
|
2004-10-31 12:30:26 +00:00
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetCharStyle::doClone() const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
|
|
|
|
return auto_ptr<InsetBase>(new InsetCharStyle(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
bool InsetCharStyle::undefined() const
|
|
|
|
|
{
|
|
|
|
|
return params_.latexname.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::setUndefined()
|
|
|
|
|
{
|
|
|
|
|
params_.latextype.clear();
|
|
|
|
|
params_.latexname.clear();
|
|
|
|
|
params_.latexparam.clear();
|
|
|
|
|
params_.font = LyXFont(LyXFont::ALL_INHERIT);
|
|
|
|
|
params_.labelfont = LyXFont(LyXFont::ALL_INHERIT);
|
2005-11-02 13:54:33 +00:00
|
|
|
|
params_.labelfont.setColor(LColor::error);
|
2005-05-04 11:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::setDefined(CharStyles::iterator cs)
|
|
|
|
|
{
|
|
|
|
|
params_.latextype = cs->latextype;
|
|
|
|
|
params_.latexname = cs->latexname;
|
|
|
|
|
params_.latexparam = cs->latexparam;
|
|
|
|
|
params_.font = cs->font;
|
|
|
|
|
params_.labelfont = cs->labelfont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
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);
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setInlined();
|
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);
|
2005-04-10 14:07:33 +00:00
|
|
|
|
mi.base.font.reduce(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
|
mi.base.font.realize(tmpfont);
|
2005-02-22 13:19:11 +00:00
|
|
|
|
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
2004-10-31 12:30:26 +00:00
|
|
|
|
InsetText::metrics(mi, dim);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
mi.base.font = tmpfont;
|
2005-09-06 16:27:24 +00:00
|
|
|
|
if (has_label_) {
|
|
|
|
|
// consider width of the inset label
|
|
|
|
|
LyXFont font(params_.labelfont);
|
|
|
|
|
font.realize(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
|
|
|
|
string s(params_.type);
|
|
|
|
|
if (undefined())
|
|
|
|
|
s = _("Undef: ") + s;
|
|
|
|
|
font_metrics::rectText(s, font, w, a, d);
|
|
|
|
|
dim.wid = max(dim.wid, w);
|
|
|
|
|
}
|
2005-02-22 13:19:11 +00:00
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
|
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
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-16 18:49:04 +00:00
|
|
|
|
LyXFont tmpfont = pi.base.font;
|
|
|
|
|
getDrawFont(pi.base.font);
|
2005-04-26 11:12:20 +00:00
|
|
|
|
// I don't understand why the above .reduce and .realize aren't
|
2005-04-10 14:07:33 +00:00
|
|
|
|
//needed, or even wanted, here. It just works. -- MV 10.04.2005
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::draw(pi, x, y);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
pi.base.font = tmpfont;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
|
2004-10-31 12:30:26 +00:00
|
|
|
|
int desc = InsetText::descent();
|
|
|
|
|
if (has_label_)
|
|
|
|
|
desc -= ascent();
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-10-31 12:30:26 +00:00
|
|
|
|
pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color());
|
2005-02-22 13:19:11 +00:00
|
|
|
|
pi.pain.line(x, y + desc, x + dim_.wid - 3, y + desc,
|
2004-10-31 12:30:26 +00:00
|
|
|
|
params_.labelfont.color());
|
2005-02-22 13:19:11 +00:00
|
|
|
|
pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
|
2004-10-31 12:30:26 +00:00
|
|
|
|
params_.labelfont.color());
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-11-04 19:50:04 +00:00
|
|
|
|
// the name of the charstyle. Can be toggled.
|
2003-12-06 09:31:30 +00:00
|
|
|
|
if (has_label_) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXFont font(params_.labelfont);
|
|
|
|
|
font.realize(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
2005-05-04 11:21:14 +00:00
|
|
|
|
string s(params_.type);
|
|
|
|
|
if (undefined())
|
|
|
|
|
s = _("Undef: ") + s;
|
2005-09-06 16:27:24 +00:00
|
|
|
|
font_metrics::rectText(s, font, w, a, d);
|
2004-10-31 12:30:26 +00:00
|
|
|
|
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
|
2005-05-04 11:21:14 +00:00
|
|
|
|
s, font, LColor::none, LColor::none);
|
2003-12-06 09:31:30 +00:00
|
|
|
|
}
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-11-04 19:50:04 +00:00
|
|
|
|
// a visual clue when the cursor is inside the inset
|
|
|
|
|
LCursor & cur = pi.base.bv->cursor();
|
|
|
|
|
if (cur.isInside(this)) {
|
|
|
|
|
y -= ascent();
|
|
|
|
|
pi.pain.line(x, y + 4, x, y, params_.labelfont.color());
|
|
|
|
|
pi.pain.line(x + 4, y, x, y, params_.labelfont.color());
|
2005-02-22 13:19:11 +00:00
|
|
|
|
pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
|
2004-11-04 19:50:04 +00:00
|
|
|
|
params_.labelfont.color());
|
2005-02-22 13:19:11 +00:00
|
|
|
|
pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
|
2004-11-04 19:50:04 +00:00
|
|
|
|
params_.labelfont.color());
|
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
|
|
|
|
font = params_.font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void InsetCharStyle::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2005-05-06 20:00:31 +00:00
|
|
|
|
setInlined();
|
2003-12-06 09:31:30 +00:00
|
|
|
|
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
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-06 09:31:30 +00:00
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-12-06 09:31:30 +00:00
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-04 19:50:04 +00:00
|
|
|
|
bool InsetCharStyle::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & status) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// paragraph breaks not allowed in charstyle insets
|
|
|
|
|
case LFUN_BREAKPARAGRAPH:
|
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
|
|
|
|
case LFUN_BREAKPARAGRAPH_SKIP:
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
return true;
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-11-04 19:50:04 +00:00
|
|
|
|
default:
|
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int InsetCharStyle::latex(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined()) {
|
|
|
|
|
os << "\\" << params_.latexname;
|
|
|
|
|
if (!params_.latexparam.empty())
|
|
|
|
|
os << params_.latexparam;
|
|
|
|
|
os << "{";
|
|
|
|
|
}
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int i = InsetText::latex(buf, os, runparams);
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
|
|
|
|
os << "}";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
|
|
|
|
sgml::openTag(os, params_.latexname, params_.latexparam);
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int i = InsetText::linuxdoc(buf, os, runparams);
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
|
|
|
|
sgml::closeTag(os, params_.latexname);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2004-10-30 22:14:02 +00:00
|
|
|
|
ParagraphList::const_iterator par = paragraphs().begin();
|
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
2005-06-09 09:58:08 +00:00
|
|
|
|
sgml::openTag(os, params_.latexname,
|
2005-05-04 11:21:14 +00:00
|
|
|
|
par->getID(buf, runparams) + params_.latexparam);
|
2004-10-30 22:14:02 +00:00
|
|
|
|
|
|
|
|
|
for (; par != end; ++par) {
|
|
|
|
|
par->simpleDocBookOnePar(buf, os, runparams,
|
2005-05-04 11:21:14 +00:00
|
|
|
|
outerFont(par - paragraphs().begin(),
|
2004-10-30 22:14:02 +00:00
|
|
|
|
paragraphs()));
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
|
|
|
|
sgml::closeTag(os, params_.latexname);
|
|
|
|
|
|
2004-10-30 22:14:02 +00:00
|
|
|
|
return 0;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-30 13:27:30 +00:00
|
|
|
|
int InsetCharStyle::plaintext(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2004-10-30 13:27:30 +00:00
|
|
|
|
return InsetText::plaintext(buf, os, runparams);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2005-05-04 11:21:14 +00:00
|
|
|
|
// Force inclusion of preamble snippet in layout file
|
2003-11-12 14:38:26 +00:00
|
|
|
|
features.require(params_.type);
|
2005-04-18 11:22:02 +00:00
|
|
|
|
InsetText::validate(features);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|