2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetert.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetert.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2001-07-24 15:07:09 +00:00
|
|
|
|
#include "BufferView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "language.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2002-07-21 21:21:06 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::split;
|
|
|
|
|
using lyx::support::strToInt;
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::min;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2001-07-24 10:13:19 +00:00
|
|
|
|
void InsetERT::init()
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-07-25 19:45:21 +00:00
|
|
|
|
setButtonLabel();
|
2003-09-16 15:39:33 +00:00
|
|
|
|
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.setColor(LColor::latex);
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
setInsetName("ERT");
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
|
|
|
|
|
: InsetCollapsable(bp, collapsed)
|
2001-07-24 10:13:19 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
status_ = collapsed ? Collapsed : Open;
|
2001-07-24 10:13:19 +00:00
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetERT::InsetERT(InsetERT const & in)
|
2003-12-02 07:15:42 +00:00
|
|
|
|
: InsetCollapsable(in)
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetERT::clone() const
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetERT(*this));
|
2001-07-27 12:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetERT::InsetERT(BufferParams const & bp,
|
|
|
|
|
Language const * l, string const & contents, bool collapsed)
|
|
|
|
|
: InsetCollapsable(bp, collapsed)
|
2001-07-08 12:52:16 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
status_ = collapsed ? Collapsed : Open;
|
2002-02-20 14:55:17 +00:00
|
|
|
|
|
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, l);
|
|
|
|
|
#ifdef SET_HARD_FONT
|
2001-07-24 15:07:09 +00:00
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
font.setColor(LColor::latex);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#endif
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
string::const_iterator cit = contents.begin();
|
|
|
|
|
string::const_iterator end = contents.end();
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type pos = 0;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
for (; cit != end; ++cit) {
|
2003-12-01 13:35:49 +00:00
|
|
|
|
inset.paragraphs().begin()->insertChar(pos++, *cit, font);
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
|
// the init has to be after the initialization of the paragraph
|
|
|
|
|
// because of the label settings (draw_label for ert insets).
|
|
|
|
|
init();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
InsetERT::~InsetERT()
|
|
|
|
|
{
|
2003-07-14 17:50:00 +00:00
|
|
|
|
InsetERTMailer(*this).hideDialog();
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetERT::read(Buffer const & buf, LyXLex & lex)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
|
bool token_found = false;
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-08-06 14:55:02 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (token == "status") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const tmp_token = lex.getString();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (tmp_token == "Inlined") {
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = Inlined;
|
2001-08-06 19:13:25 +00:00
|
|
|
|
} else if (tmp_token == "Collapsed") {
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = Collapsed;
|
2001-08-06 19:13:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
// leave this as default!
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = Open;
|
2001-08-06 19:13:25 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
token_found = true;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetERT::Read: Missing 'status'-tag!"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
<< endl;
|
2001-08-06 14:55:02 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-07 08:05:31 +00:00
|
|
|
|
inset.read(buf, lex);
|
2001-08-18 15:01:09 +00:00
|
|
|
|
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#ifdef SET_HARD_FONT
|
2001-08-18 15:01:09 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
font.setColor(LColor::latex);
|
2003-04-16 04:35:43 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator pit = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator pend = inset.paragraphs().end();
|
2003-04-16 04:35:43 +00:00
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
|
pos_type siz = pit->size();
|
2001-11-27 10:34:16 +00:00
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2003-04-16 04:35:43 +00:00
|
|
|
|
pit->setFont(i, font);
|
2001-08-18 15:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#endif
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (!token_found) {
|
2003-09-16 15:39:33 +00:00
|
|
|
|
if (isOpen())
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = Open;
|
2003-09-16 15:39:33 +00:00
|
|
|
|
else
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = Collapsed;
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
2001-07-25 19:45:21 +00:00
|
|
|
|
setButtonLabel();
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetERT::write(Buffer const & buf, ostream & os) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
|
string st;
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
switch (status_) {
|
2002-03-21 17:09:55 +00:00
|
|
|
|
case Open:
|
2001-08-06 14:55:02 +00:00
|
|
|
|
st = "Open";
|
|
|
|
|
break;
|
|
|
|
|
case Collapsed:
|
|
|
|
|
st = "Collapsed";
|
|
|
|
|
break;
|
|
|
|
|
case Inlined:
|
|
|
|
|
st = "Inlined";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
os << getInsetName() << "\n" << "status "<< st << "\n";
|
2001-08-07 08:05:31 +00:00
|
|
|
|
|
2001-08-18 15:01:09 +00:00
|
|
|
|
//inset.writeParagraphData(buf, os);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string const layout(buf.params().getLyXTextClass().defaultLayoutName());
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs().end();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
for (; par != end; ++par) {
|
2003-07-28 15:17:11 +00:00
|
|
|
|
os << "\n\\begin_layout " << layout << "\n";
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type siz = par->size();
|
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2001-08-18 15:01:09 +00:00
|
|
|
|
Paragraph::value_type c = par->getChar(i);
|
|
|
|
|
switch (c) {
|
|
|
|
|
case Paragraph::META_INSET:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (par->getInset(i)->lyxCode() != InsetOld::NEWLINE_CODE) {
|
2003-03-12 19:16:42 +00:00
|
|
|
|
lyxerr << "Element is not allowed in insertERT"
|
|
|
|
|
<< endl;
|
|
|
|
|
} else {
|
|
|
|
|
par->getInset(i)->write(buf, os);
|
|
|
|
|
}
|
2001-08-18 15:01:09 +00:00
|
|
|
|
break;
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
2001-08-18 15:01:09 +00:00
|
|
|
|
case '\\':
|
|
|
|
|
os << "\n\\backslash \n";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
os << c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-28 15:17:11 +00:00
|
|
|
|
os << "\n\\end_layout\n";
|
2001-08-18 15:01:09 +00:00
|
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const InsetERT::editMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return _("Opened ERT Inset");
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
bool InsetERT::insertInset(BufferView *, InsetOld *)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-21 17:26:11 +00:00
|
|
|
|
void InsetERT::updateStatus(bool swap) const
|
2000-03-24 13:24:58 +00:00
|
|
|
|
{
|
2001-08-14 07:37:46 +00:00
|
|
|
|
if (status_ != Inlined) {
|
2003-09-16 15:39:33 +00:00
|
|
|
|
if (isOpen())
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = swap ? Collapsed : Open;
|
2003-09-16 15:39:33 +00:00
|
|
|
|
else
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status_ = swap ? Open : Collapsed;
|
2001-08-14 07:37:46 +00:00
|
|
|
|
}
|
2001-10-31 15:19:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetERT::lfunMousePress(FuncRequest const & cmd)
|
2001-12-04 16:10:19 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (status_ == Inlined)
|
2003-10-17 18:01:15 +00:00
|
|
|
|
inset.dispatch(cmd);
|
|
|
|
|
else {
|
|
|
|
|
idx_type idx = 0;
|
|
|
|
|
pos_type pos = 0;
|
|
|
|
|
InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
|
|
|
|
}
|
2001-12-04 16:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
|
|
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2001-08-06 14:55:02 +00:00
|
|
|
|
showInsetDialog(bv);
|
2001-12-17 13:33:22 +00:00
|
|
|
|
return true;
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-07-30 14:43:14 +00:00
|
|
|
|
if (status_ != Inlined && hitButton(cmd)) {
|
2003-11-21 17:26:11 +00:00
|
|
|
|
updateStatus(true);
|
2001-10-31 15:19:49 +00:00
|
|
|
|
} else {
|
2002-08-19 10:11:13 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
|
|
|
|
cmd1.y = ascent() + cmd.y - inset.ascent();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
|
|
// inlined is special - the text appears above
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (status_ == Inlined)
|
2003-10-17 18:01:15 +00:00
|
|
|
|
inset.dispatch(cmd1);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
else if (isOpen() && cmd.y > buttonDim().y2) {
|
2003-05-19 17:03:12 +00:00
|
|
|
|
cmd1.y -= height_collapsed();
|
2003-10-17 18:01:15 +00:00
|
|
|
|
inset.dispatch(cmd1);
|
2001-10-31 15:19:49 +00:00
|
|
|
|
}
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
|
return false;
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetERT::lfunMouseMotion(FuncRequest const & cmd)
|
2001-12-04 16:10:19 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (status_ == Inlined)
|
2003-10-17 18:01:15 +00:00
|
|
|
|
inset.dispatch(cmd);
|
|
|
|
|
else {
|
|
|
|
|
idx_type idx = 0;
|
|
|
|
|
pos_type pos = 0;
|
|
|
|
|
InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
|
|
|
|
}
|
2001-12-04 16:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetERT::latex(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs().end();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
|
2001-09-28 20:23:49 +00:00
|
|
|
|
int lines = 0;
|
2003-04-02 17:11:38 +00:00
|
|
|
|
while (par != end) {
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type siz = par->size();
|
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// ignore all struck out text
|
2003-02-26 17:04:10 +00:00
|
|
|
|
if (isDeletedText(*par, i))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
continue;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-03-12 19:16:42 +00:00
|
|
|
|
if (par->isNewline(i)) {
|
2001-07-16 15:42:57 +00:00
|
|
|
|
os << '\n';
|
2001-09-28 20:23:49 +00:00
|
|
|
|
++lines;
|
2003-03-12 19:16:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
os << par->getChar(i);
|
2001-07-16 15:42:57 +00:00
|
|
|
|
}
|
2001-07-09 23:12:04 +00:00
|
|
|
|
}
|
2003-04-02 17:11:38 +00:00
|
|
|
|
++par;
|
|
|
|
|
if (par != end) {
|
2003-06-07 17:45:43 +00:00
|
|
|
|
os << "\n";
|
|
|
|
|
++lines;
|
2001-09-28 20:23:49 +00:00
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-09-28 20:23:49 +00:00
|
|
|
|
return lines;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetERT::plaintext(Buffer const &, ostream &,
|
|
|
|
|
OutputParams const & /*runparams*/) const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetERT::linuxdoc(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &)const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs().end();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
|
int lines = 0;
|
2003-04-02 17:11:38 +00:00
|
|
|
|
while (par != end) {
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type siz = par->size();
|
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2003-03-12 19:16:42 +00:00
|
|
|
|
if (par->isNewline(i)) {
|
2001-10-15 12:21:11 +00:00
|
|
|
|
os << '\n';
|
|
|
|
|
++lines;
|
2003-03-12 19:16:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
os << par->getChar(i);
|
2001-10-15 12:21:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-02 17:11:38 +00:00
|
|
|
|
++par;
|
|
|
|
|
if (par != end) {
|
2001-10-15 12:21:11 +00:00
|
|
|
|
os << "\n";
|
|
|
|
|
lines ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
|
return lines;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetERT::docbook(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs().end();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
|
int lines = 0;
|
2003-04-02 17:11:38 +00:00
|
|
|
|
while (par != end) {
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type siz = par->size();
|
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2003-03-12 19:16:42 +00:00
|
|
|
|
if (par->isNewline(i)) {
|
2001-10-15 12:21:11 +00:00
|
|
|
|
os << '\n';
|
|
|
|
|
++lines;
|
2003-03-12 19:16:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
os << par->getChar(i);
|
2001-10-15 12:21:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-02 17:11:38 +00:00
|
|
|
|
++par;
|
|
|
|
|
if (par != end) {
|
2001-10-15 12:21:11 +00:00
|
|
|
|
os << "\n";
|
|
|
|
|
lines ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
|
return lines;
|
2000-03-24 13:24:58 +00:00
|
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void InsetERT::edit(BufferView * bv, bool left)
|
|
|
|
|
{
|
|
|
|
|
if (status_ == Inlined) {
|
|
|
|
|
inset.edit(bv, left);
|
|
|
|
|
} else {
|
|
|
|
|
InsetCollapsable::edit(bv, left);
|
|
|
|
|
}
|
2003-11-21 17:31:46 +00:00
|
|
|
|
setLatexFont(bv);
|
2003-11-21 17:26:11 +00:00
|
|
|
|
updateStatus();
|
2003-11-04 12:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2003-11-10 09:06:48 +00:00
|
|
|
|
InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (inset.paragraphs().begin()->empty())
|
2003-11-21 17:31:46 +00:00
|
|
|
|
setLatexFont(bv);
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-03-04 14:31:04 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-02-26 19:28:38 +00:00
|
|
|
|
InsetERTMailer::string2params(cmd.argument, status_);
|
2003-11-10 13:23:14 +00:00
|
|
|
|
bv->update();
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-02-26 19:28:38 +00:00
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-02-26 19:28:38 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
lfunMousePress(cmd);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
lfunMouseMotion(cmd);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
lfunMouseRelease(cmd);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_LAYOUT:
|
2003-12-01 13:35:49 +00:00
|
|
|
|
bv->owner()->setLayout(inset.paragraphs().begin()->layout()->name());
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(true);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
|
case LFUN_BREAKPARAGRAPH:
|
2001-07-24 22:08:49 +00:00
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
2001-08-18 15:01:09 +00:00
|
|
|
|
case LFUN_BACKSPACE:
|
|
|
|
|
case LFUN_BACKSPACE_SKIP:
|
|
|
|
|
case LFUN_DELETE:
|
|
|
|
|
case LFUN_DELETE_SKIP:
|
|
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
|
|
|
|
case LFUN_CUT:
|
2003-11-21 17:31:46 +00:00
|
|
|
|
setLatexFont(bv);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
|
default:
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2001-07-24 15:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetERT::setButtonLabel() const
|
2001-07-25 19:45:21 +00:00
|
|
|
|
{
|
2003-12-01 14:51:52 +00:00
|
|
|
|
setLabel(status_ == Collapsed ? getNewLabel(_("ERT")) : _("ERT"));
|
2001-07-25 19:45:21 +00:00
|
|
|
|
}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
bool InsetERT::insetAllowed(InsetOld::Code code) const
|
|
|
|
|
{
|
|
|
|
|
return code == InsetOld::NEWLINE_CODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2003-12-02 07:15:42 +00:00
|
|
|
|
InsetCollapsable::metrics(mi, dim);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetERT::draw(PainterInfo & pi, int x, int y) const
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2003-12-02 07:15:42 +00:00
|
|
|
|
InsetCollapsable::draw(pi, x, y);
|
2001-07-31 09:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-21 17:31:46 +00:00
|
|
|
|
void InsetERT::setLatexFont(BufferView * /*bv*/)
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#ifdef SET_HARD_FONT
|
2001-08-11 18:31:14 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
|
2001-07-31 09:53:40 +00:00
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
font.setColor(LColor::latex);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
inset.text_.setFont(bv, font, false);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#endif
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
void InsetERT::setStatus(CollapseStatus st)
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
status_ = st;
|
2003-12-02 07:15:42 +00:00
|
|
|
|
setButtonLabel();
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-10 22:12:07 +00:00
|
|
|
|
bool InsetERT::showInsetDialog(BufferView * bv) const
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
2003-07-14 17:50:00 +00:00
|
|
|
|
InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-20 14:55:17 +00:00
|
|
|
|
void InsetERT::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
font.setColor(LColor::latex);
|
|
|
|
|
}
|
2002-03-05 14:55:20 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetERTMailer::name_("ert");
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetERTMailer::InsetERTMailer(InsetERT & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetERTMailer::inset2string(Buffer const &) const
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.status());
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERTMailer::string2params(string const & in,
|
2003-12-02 07:15:42 +00:00
|
|
|
|
InsetCollapsable::InsetCollapsable::CollapseStatus & status)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status = InsetCollapsable::Collapsed;
|
2003-02-27 13:26:07 +00:00
|
|
|
|
|
|
|
|
|
string name;
|
|
|
|
|
string body = split(in, name, ' ');
|
|
|
|
|
|
|
|
|
|
if (body.empty())
|
2003-02-25 14:51:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
status = static_cast<InsetCollapsable::CollapseStatus>(strToInt(body));
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-02 07:15:42 +00:00
|
|
|
|
string const
|
|
|
|
|
InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return name_ + ' ' + tostr(status);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|