2003-11-12 14:38:26 +00:00
|
|
|
|
/**
|
2007-09-05 15:29:04 +00:00
|
|
|
|
* \file InsetFlex.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-09-05 15:29:04 +00:00
|
|
|
|
#include "InsetFlex.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"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2008-01-07 16:59:10 +00:00
|
|
|
|
#include "LaTeXFeatures.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
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
InsetFlex::InsetFlex(BufferParams const & bp,
|
2008-02-05 10:34:01 +00:00
|
|
|
|
TextClassPtr tc, string const & layoutName)
|
|
|
|
|
: InsetCollapsable(bp, Collapsed, tc),
|
|
|
|
|
name_(layoutName)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2008-02-05 10:34:01 +00:00
|
|
|
|
setLayout(tc); // again, because now the name is initialized
|
|
|
|
|
packages_ = getLayout().requires;
|
|
|
|
|
preamble_ = getLayout().preamble;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
InsetFlex::InsetFlex(InsetFlex const & in)
|
2007-11-05 10:14:19 +00:00
|
|
|
|
: InsetCollapsable(in), name_(in.name_)
|
2007-11-03 00:56:48 +00:00
|
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
Inset * InsetFlex::clone() const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-09-05 15:29:04 +00:00
|
|
|
|
return new InsetFlex(*this);
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
bool InsetFlex::undefined() const
|
2005-05-04 11:21:14 +00:00
|
|
|
|
{
|
2008-02-05 10:34:01 +00:00
|
|
|
|
return getLayout().labelstring == from_utf8("UNDEFINED");
|
2005-05-04 11:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
docstring const InsetFlex::editMessage() const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-09-08 13:01:29 +00:00
|
|
|
|
return _("Opened Flex Inset");
|
2003-11-12 14:38:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
void InsetFlex::write(Buffer const & buf, ostream & os) const
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2008-02-14 03:42:54 +00:00
|
|
|
|
os << "Flex " <<
|
|
|
|
|
name_.empty() ? "undefined" : name_ << "\n";
|
2003-11-12 14:38:26 +00:00
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
void InsetFlex::read(Buffer const & buf, Lexer & lex)
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{
|
2007-11-05 10:14:19 +00:00
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (token == "Flex") {
|
|
|
|
|
lex.next();
|
|
|
|
|
name_ = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is handled in Collapsable
|
|
|
|
|
else if (token == "status") {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
int InsetFlex::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
|
int InsetFlex::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())
|
2008-02-05 10:34:01 +00:00
|
|
|
|
sgml::openTag(os, getLayout().latexname,
|
|
|
|
|
par->getID(buf, runparams) + getLayout().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,
|
2007-12-12 19:28:07 +00:00
|
|
|
|
outerFont(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())
|
2008-02-05 10:34:01 +00:00
|
|
|
|
sgml::closeTag(os, getLayout().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-09-05 15:29:04 +00:00
|
|
|
|
void InsetFlex::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
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 16:59:10 +00:00
|
|
|
|
|
|
|
|
|
void InsetFlex::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
if (!preamble_.empty())
|
|
|
|
|
features.addPreambleSnippet(preamble_);
|
2008-02-01 15:12:04 +00:00
|
|
|
|
features.require(packages_);
|
2008-01-07 16:59:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|