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
|
|
|
|
*/
|
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
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (collapsed)
|
|
|
|
|
status_ = Collapsed;
|
|
|
|
|
else
|
|
|
|
|
status_ = 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)
|
|
|
|
|
: InsetCollapsable(in), status_(in.status_)
|
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
|
|
|
|
{
|
2001-08-13 09:57:47 +00:00
|
|
|
|
if (collapsed)
|
|
|
|
|
status_ = Collapsed;
|
|
|
|
|
else
|
|
|
|
|
status_ = 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-04-02 17:11:38 +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") {
|
2001-08-07 08:05:31 +00:00
|
|
|
|
status(0, Inlined);
|
2001-08-06 19:13:25 +00:00
|
|
|
|
} else if (tmp_token == "Collapsed") {
|
2001-08-07 08:05:31 +00:00
|
|
|
|
status(0, Collapsed);
|
2001-08-06 19:13:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
// leave this as default!
|
2001-08-07 08:05:31 +00:00
|
|
|
|
status(0, 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-12-17 13:33:22 +00:00
|
|
|
|
#if 0
|
2001-08-07 08:05:31 +00:00
|
|
|
|
#warning this should be really short lived only for compatibility to
|
|
|
|
|
#warning files written 07/08/2001 so this has to go before 1.2.0! (Jug)
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token == "collapsed") {
|
|
|
|
|
lex.next();
|
2003-09-16 15:39:33 +00:00
|
|
|
|
setCollapsed(lex.getBool());
|
2001-08-07 08:05:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
|
#endif
|
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
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pit = inset.paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = inset.paragraphs.end();
|
|
|
|
|
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())
|
2001-08-07 08:05:31 +00:00
|
|
|
|
status(0, Open);
|
2003-09-16 15:39:33 +00:00
|
|
|
|
else
|
|
|
|
|
status(0, 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs.end();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-03-29 10:55:48 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning FIXME. More UI stupidity...
|
|
|
|
|
#endif
|
2001-05-28 15:11:24 +00:00
|
|
|
|
// if selectall is activated then the fontchange was an outside general
|
|
|
|
|
// fontchange and this messages is not needed
|
|
|
|
|
if (!selectall)
|
2003-03-29 10:55:48 +00:00
|
|
|
|
Alert::error(_("Cannot change font"),
|
|
|
|
|
_("You cannot change font settings inside TeX code."));
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
2000-03-24 13:24:58 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2001-10-31 15:19:49 +00:00
|
|
|
|
void InsetERT::updateStatus(BufferView * bv, 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())
|
2001-10-31 15:19:49 +00:00
|
|
|
|
status(bv, swap ? Collapsed : Open);
|
2003-09-16 15:39:33 +00:00
|
|
|
|
else
|
|
|
|
|
status(bv, 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
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::EDITABLE InsetERT::editable() const
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (status_ == Collapsed)
|
|
|
|
|
return IS_EDITABLE;
|
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)) {
|
2001-10-31 15:19:49 +00:00
|
|
|
|
updateStatus(bv, true);
|
|
|
|
|
} 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-09-16 15:39:33 +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-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs.end();
|
|
|
|
|
|
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-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs.end();
|
|
|
|
|
|
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-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator par = inset.paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = inset.paragraphs.end();
|
|
|
|
|
|
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) {
|
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
|
return;
|
|
|
|
|
inset.edit(bv, left);
|
|
|
|
|
} else {
|
|
|
|
|
InsetCollapsable::edit(bv, left);
|
|
|
|
|
}
|
|
|
|
|
set_latex_font(bv);
|
|
|
|
|
updateStatus(bv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2003-10-17 18:01:15 +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-11-04 12:36:59 +00:00
|
|
|
|
if (inset.paragraphs.begin()->empty())
|
2001-07-31 09:53:40 +00:00
|
|
|
|
set_latex_font(bv);
|
|
|
|
|
|
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
|
|
|
|
InsetERT::ERTStatus status_;
|
|
|
|
|
InsetERTMailer::string2params(cmd.argument, status_);
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
2003-02-26 19:28:38 +00:00
|
|
|
|
status(bv, status_);
|
2003-03-22 17:26:03 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: I refuse to believe we have to live
|
|
|
|
|
* with ugliness like this ! Note that this
|
|
|
|
|
* rebreak *is* needed. Consider a change from
|
|
|
|
|
* Open (needfullrow) to Inlined (only the space
|
|
|
|
|
* taken by the text).
|
|
|
|
|
*/
|
2003-06-27 09:44:26 +00:00
|
|
|
|
inset.getLyXText(cmd.view())->fullRebreak();
|
2003-08-27 13:51:18 +00:00
|
|
|
|
bv->updateInset(this);
|
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-04-02 17:11:38 +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:
|
2001-07-31 09:53:40 +00:00
|
|
|
|
set_latex_font(bv);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
return DispatchResult(false);
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetERT::get_new_label() const
|
|
|
|
|
{
|
|
|
|
|
string la;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
pos_type const max_length = 15;
|
2003-04-02 17:11:38 +00:00
|
|
|
|
pos_type const p_siz = inset.paragraphs.begin()->size();
|
2002-02-16 15:59:55 +00:00
|
|
|
|
pos_type const n = min(max_length, p_siz);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
pos_type i = 0;
|
|
|
|
|
pos_type j = 0;
|
2001-07-25 19:45:21 +00:00
|
|
|
|
for(; i < n && j < p_siz; ++j) {
|
2003-04-02 17:11:38 +00:00
|
|
|
|
if (inset.paragraphs.begin()->isInset(j))
|
2001-07-24 22:08:49 +00:00
|
|
|
|
continue;
|
2003-04-02 17:11:38 +00:00
|
|
|
|
la += inset.paragraphs.begin()->getChar(j);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
++i;
|
|
|
|
|
}
|
2003-08-03 21:42:44 +00:00
|
|
|
|
if (inset.paragraphs.size() > 1 || (i > 0 && j < p_siz)) {
|
2001-07-24 22:08:49 +00:00
|
|
|
|
la += "...";
|
2001-07-25 19:45:21 +00:00
|
|
|
|
}
|
|
|
|
|
if (la.empty()) {
|
2001-07-30 22:14:45 +00:00
|
|
|
|
la = _("ERT");
|
2001-07-25 19:45:21 +00:00
|
|
|
|
}
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return la;
|
|
|
|
|
}
|
2001-07-25 19:45:21 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetERT::setButtonLabel() const
|
2001-07-25 19:45:21 +00:00
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (status_ == Collapsed) {
|
2001-07-25 19:45:21 +00:00
|
|
|
|
setLabel(get_new_label());
|
|
|
|
|
} else {
|
2001-07-30 22:14:45 +00:00
|
|
|
|
setLabel(_("ERT"));
|
2001-07-25 19:45:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-27 12:03:36 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-20 14:55:17 +00:00
|
|
|
|
bool InsetERT::checkInsertChar(LyXFont & /* font */)
|
2001-07-27 12:03:36 +00:00
|
|
|
|
{
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#ifdef SET_HARD_FONT
|
2001-08-11 18:31:14 +00:00
|
|
|
|
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
font = f;
|
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
font.setColor(LColor::latex);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#endif
|
2001-07-27 12:03:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
|
|
|
|
|
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-07-17 07:32:01 +00:00
|
|
|
|
setButtonLabel();
|
2003-05-21 21:20:50 +00:00
|
|
|
|
if (inlined())
|
2003-06-02 10:03:27 +00:00
|
|
|
|
inset.metrics(mi, dim);
|
2003-05-19 17:03:12 +00:00
|
|
|
|
else
|
2003-06-02 10:03:27 +00:00
|
|
|
|
InsetCollapsable::metrics(mi, dim);
|
2003-08-26 10:33:59 +00:00
|
|
|
|
// Make it stand out on its own as it is code, not part of running
|
|
|
|
|
// text:
|
|
|
|
|
if (isOpen() && !inlined())
|
|
|
|
|
dim.wid = mi.base.textwidth;
|
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-05-30 06:48:24 +00:00
|
|
|
|
InsetCollapsable::draw(pi, x, y, inlined());
|
2001-07-31 09:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-20 14:55:17 +00:00
|
|
|
|
void InsetERT::set_latex_font(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);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
inset.getLyXText(bv)->setFont(bv, font, false);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
#endif
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-06 10:17:29 +00:00
|
|
|
|
// attention this function can be called with bv == 0
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetERT::status(BufferView * bv, ERTStatus const st) const
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (st != status_) {
|
|
|
|
|
status_ = st;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
switch (st) {
|
2001-08-06 14:55:02 +00:00
|
|
|
|
case Inlined:
|
|
|
|
|
break;
|
|
|
|
|
case Open:
|
2003-09-16 15:39:33 +00:00
|
|
|
|
setCollapsed(false);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
setButtonLabel();
|
|
|
|
|
break;
|
|
|
|
|
case Collapsed:
|
2003-09-16 15:39:33 +00:00
|
|
|
|
setCollapsed(true);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
setButtonLabel();
|
2001-08-07 08:05:31 +00:00
|
|
|
|
if (bv)
|
2001-08-07 15:07:36 +00:00
|
|
|
|
bv->unlockInset(const_cast<InsetERT *>(this));
|
2001-08-06 14:55:02 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-19 14:45:22 +00:00
|
|
|
|
if (bv) {
|
2003-08-27 13:51:18 +00:00
|
|
|
|
bv->updateInset(this);
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->buffer()->markDirty();
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::open(BufferView * bv)
|
|
|
|
|
{
|
2003-09-16 15:39:33 +00:00
|
|
|
|
if (isOpen())
|
2001-08-06 14:55:02 +00:00
|
|
|
|
return;
|
|
|
|
|
status(bv, Open);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
|
void InsetERT::close(BufferView * bv) const
|
2001-08-06 14:55:02 +00:00
|
|
|
|
{
|
2002-03-26 09:51:12 +00:00
|
|
|
|
if (status_ == Collapsed || status_ == Inlined)
|
2001-08-06 14:55:02 +00:00
|
|
|
|
return;
|
2002-03-26 09:51:12 +00:00
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
status(bv, Collapsed);
|
2001-07-31 09:53:40 +00:00
|
|
|
|
}
|
2001-09-24 14:29:27 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-20 14:55:17 +00:00
|
|
|
|
void InsetERT::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
|
|
|
|
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
|
font = f;
|
|
|
|
|
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,
|
|
|
|
|
InsetERT::ERTStatus & status)
|
|
|
|
|
{
|
|
|
|
|
status = InsetERT::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-02-27 13:26:07 +00:00
|
|
|
|
status = static_cast<InsetERT::ERTStatus>(strToInt(body));
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
2003-03-07 14:08:10 +00:00
|
|
|
|
InsetERTMailer::params2string(InsetERT::ERTStatus 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
|
|
|
|
}
|