2003-11-12 14:38:26 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetCharStyle.cpp
|
2003-11-12 14:38:26 +00:00
|
|
|
|
* 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>
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetCharStyle.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2006-09-26 21:11:22 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2004-11-04 19:50:04 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 17:34:20 +00:00
|
|
|
|
#include "Color.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
|
#include "Text.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#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
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2003-12-06 09:31:30 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2006-10-16 07:06:41 +00:00
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
|
2007-08-18 23:26:07 +00:00
|
|
|
|
: InsetCollapsable(bp, Collapsed)
|
2005-05-04 11:21:14 +00:00
|
|
|
|
{
|
2007-08-19 10:08:09 +00:00
|
|
|
|
params_.name = s;
|
2005-05-04 11:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
|
2007-08-25 14:43:59 +00:00
|
|
|
|
InsetLayout il)
|
2007-08-18 23:26:07 +00:00
|
|
|
|
: InsetCollapsable(bp, Collapsed)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-08-25 14:43:59 +00:00
|
|
|
|
params_.name = il.name;
|
|
|
|
|
setLayout(il);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
|
2004-10-31 12:30:26 +00:00
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
2007-08-25 14:43:59 +00:00
|
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetCharStyle::clone() const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetCharStyle(*this);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
bool InsetCharStyle::undefined() const
|
|
|
|
|
{
|
2007-08-25 14:43:59 +00:00
|
|
|
|
return layout_.labelstring == from_utf8("UNDEFINED");
|
2005-05-04 11:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-25 14:43:59 +00:00
|
|
|
|
void InsetCharStyle::setLayout(InsetLayout il)
|
2005-05-04 11:21:14 +00:00
|
|
|
|
{
|
2007-08-25 14:43:59 +00:00
|
|
|
|
layout_ = il;
|
2005-05-04 11:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
docstring const InsetCharStyle::editMessage() const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
|
return _("Opened CharStyle Inset");
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCharStyle::write(Buffer const & buf, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetCharStyle::read(Buffer const & buf, Lexer & lex)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2006-10-16 07:06:41 +00:00
|
|
|
|
params_.read(lex);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font tmpfont = mi.base.font;
|
2003-12-16 18:49:04 +00:00
|
|
|
|
getDrawFont(mi.base.font);
|
2007-04-29 18:17:15 +00:00
|
|
|
|
mi.base.font.reduce(Font(Font::ALL_SANE));
|
2005-04-10 14:07:33 +00:00
|
|
|
|
mi.base.font.realize(tmpfont);
|
2007-08-19 15:45:35 +00:00
|
|
|
|
bool changed = InsetCollapsable::metrics(mi, dim);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
mi.base.font = tmpfont;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
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
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font tmpfont = pi.base.font;
|
2003-12-16 18:49:04 +00:00
|
|
|
|
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
|
2007-08-18 23:26:07 +00:00
|
|
|
|
InsetCollapsable::draw(pi, x, y);
|
2003-12-16 18:49:04 +00:00
|
|
|
|
pi.base.font = tmpfont;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
|
void InsetCharStyle::getDrawFont(Font & font) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-08-19 10:08:09 +00:00
|
|
|
|
font = layout_.font;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-08-20 04:56:04 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-11-04 19:50:04 +00:00
|
|
|
|
FuncStatus & status) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// paragraph breaks not allowed in charstyle insets
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH_SKIP:
|
2004-11-04 19:50:04 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-17 15:28:50 +00:00
|
|
|
|
int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2007-02-17 15:28:50 +00:00
|
|
|
|
{
|
|
|
|
|
return InsetText::plaintext(buf, os, runparams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetCharStyle::docbook(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2006-03-23 20:11:06 +00:00
|
|
|
|
ParagraphList::const_iterator beg = paragraphs().begin();
|
2004-10-30 22:14:02 +00:00
|
|
|
|
ParagraphList::const_iterator par = paragraphs().begin();
|
2006-04-05 23:56:29 +00:00
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
2004-10-30 22:14:02 +00:00
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-08-19 10:08:09 +00:00
|
|
|
|
sgml::openTag(os, layout_.latexname,
|
|
|
|
|
par->getID(buf, runparams) + layout_.latexparam);
|
2004-10-30 22:14:02 +00:00
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
|
for (; par != end; ++par) {
|
2004-10-30 22:14:02 +00:00
|
|
|
|
par->simpleDocBookOnePar(buf, os, runparams,
|
2006-03-23 20:11:06 +00:00
|
|
|
|
outerFont(std::distance(beg, par),
|
2004-10-30 22:14:02 +00:00
|
|
|
|
paragraphs()));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
}
|
2004-10-30 22:14:02 +00:00
|
|
|
|
|
2005-05-04 11:21:14 +00:00
|
|
|
|
if (!undefined())
|
2007-08-19 10:08:09 +00:00
|
|
|
|
sgml::closeTag(os, layout_.latexname);
|
2005-05-04 11:21:14 +00:00
|
|
|
|
|
2004-10-30 22:14:02 +00:00
|
|
|
|
return 0;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-19 16:23:13 +00:00
|
|
|
|
void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
|
{
|
2007-01-19 16:23:13 +00:00
|
|
|
|
os << paragraphs().begin()->asString(buf, true);
|
2005-11-25 14:40:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
void InsetCharStyleParams::write(ostream & os) const
|
|
|
|
|
{
|
2007-08-19 10:08:09 +00:00
|
|
|
|
os << "CharStyle " << name << "\n";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetCharStyleParams::read(Lexer & lex)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2006-10-16 07:06:41 +00:00
|
|
|
|
while (lex.isOK()) {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
|
2006-10-16 07:06:41 +00:00
|
|
|
|
if (token == "CharStyle") {
|
|
|
|
|
lex.next();
|
2007-08-19 10:08:09 +00:00
|
|
|
|
name = lex.getString();
|
2006-10-16 07:06:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 23:26:07 +00:00
|
|
|
|
// This is handled in Collapsable
|
2006-10-16 07:06:41 +00:00
|
|
|
|
else if (token == "status") {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|