2000-02-25 12:06:15 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2000-02-25 12:06:15 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2000-02-25 13:35:38 +00:00
|
|
|
* Copyright 1998 The LyX Team.
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetert.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "insettext.h"
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
#include "buffer.h"
|
2001-07-24 15:07:09 +00:00
|
|
|
#include "BufferView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
#include "debug.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "language.h"
|
|
|
|
#include "lyxfont.h"
|
2002-07-21 21:21:06 +00:00
|
|
|
#include "lyxlex.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "lyxrow.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "WordLangTuple.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/Dialogs.h"
|
|
|
|
#include "frontends/LyXView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
#include "support/LOstream.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::min;
|
|
|
|
using std::endl;
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
using lyx::pos_type;
|
|
|
|
|
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();
|
2001-07-08 12:52:16 +00:00
|
|
|
labelfont = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
labelfont.decSize();
|
|
|
|
labelfont.decSize();
|
|
|
|
labelfont.setColor(LColor::latex);
|
|
|
|
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
|
|
|
|
2001-07-27 12:03:36 +00:00
|
|
|
InsetERT::InsetERT(InsetERT const & in, bool same_id)
|
2001-08-06 14:55:02 +00:00
|
|
|
: InsetCollapsable(in, same_id), status_(in.status_)
|
2001-07-27 12:03:36 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetERT::clone(Buffer const &, bool same_id) const
|
|
|
|
{
|
|
|
|
return new InsetERT(*const_cast<InsetERT *>(this), same_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
inset.paragraph()->insertChar(pos++, *cit, font);
|
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
void InsetERT::read(Buffer const * buf, LyXLex & lex)
|
|
|
|
{
|
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();
|
|
|
|
collapsed_ = lex.getBool();
|
|
|
|
} 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);
|
|
|
|
Paragraph * par = inset.paragraph();
|
|
|
|
while (par) {
|
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
|
|
|
par->setFont(i, font);
|
|
|
|
}
|
|
|
|
par = par->next();
|
|
|
|
}
|
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) {
|
2001-08-06 19:13:25 +00:00
|
|
|
if (collapsed_) {
|
2001-08-07 08:05:31 +00:00
|
|
|
status(0, Collapsed);
|
2001-08-06 19:13:25 +00:00
|
|
|
} else {
|
2001-08-07 08:05:31 +00:00
|
|
|
status(0, Open);
|
2001-08-06 19:13:25 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +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);
|
2002-07-21 21:21:06 +00:00
|
|
|
string const layout(buf->params.getLyXTextClass().defaultLayoutName());
|
2001-08-18 15:01:09 +00:00
|
|
|
Paragraph * par = inset.paragraph();
|
|
|
|
while (par) {
|
|
|
|
os << "\n\\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:
|
|
|
|
case Paragraph::META_HFILL:
|
|
|
|
lyxerr << "Element is not allowed in insertERT"
|
2002-02-16 15:59:55 +00:00
|
|
|
<< endl;
|
2001-08-18 15:01:09 +00:00
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
os << "\n\\newline \n";
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
os << "\n\\backslash \n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
par = par->next();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetERT::insertInset(BufferView *, Inset *)
|
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
|
|
|
{
|
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)
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::alert(_("Impossible Operation!"),
|
2002-03-21 17:09:55 +00:00
|
|
|
_("Not permitted to change font-types inside ERT-insets!"),
|
|
|
|
_("Sorry."));
|
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) {
|
|
|
|
if (collapsed_) {
|
2001-10-31 15:19:49 +00:00
|
|
|
status(bv, swap ? Open : Collapsed);
|
2001-08-14 07:37:46 +00:00
|
|
|
} else {
|
2001-10-31 15:19:49 +00:00
|
|
|
status(bv, swap ? Collapsed : Open);
|
2001-08-14 07:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-31 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
void InsetERT::edit(BufferView * bv, int x, int y, mouse_button::state button)
|
2001-10-31 15:19:49 +00:00
|
|
|
{
|
2002-05-26 17:33:14 +00:00
|
|
|
if (button == mouse_button::button3)
|
2001-10-31 15:19:49 +00:00
|
|
|
return;
|
2001-12-04 16:10:19 +00:00
|
|
|
|
|
|
|
if (status_ == Inlined) {
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
return;
|
|
|
|
inset.edit(bv, x, y, button);
|
|
|
|
} else {
|
|
|
|
InsetCollapsable::edit(bv, x, y, button);
|
|
|
|
}
|
2001-07-31 09:53:40 +00:00
|
|
|
set_latex_font(bv);
|
2001-12-18 14:36:27 +00:00
|
|
|
updateStatus(bv);
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
Inset::EDITABLE InsetERT::editable() const
|
|
|
|
{
|
|
|
|
if (status_ == Collapsed)
|
|
|
|
return IS_EDITABLE;
|
|
|
|
return HIGHLY_EDITABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 09:53:40 +00:00
|
|
|
void InsetERT::edit(BufferView * bv, bool front)
|
2001-07-20 14:18:48 +00:00
|
|
|
{
|
2001-07-31 09:53:40 +00:00
|
|
|
InsetCollapsable::edit(bv, front);
|
2001-10-31 15:19:49 +00:00
|
|
|
updateStatus(0);
|
2001-07-31 09:53:40 +00:00
|
|
|
set_latex_font(bv);
|
2001-07-20 14:18:48 +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)
|
|
|
|
inset.localDispatch(cmd);
|
|
|
|
else
|
|
|
|
InsetCollapsable::localDispatch(cmd);
|
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
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) &&
|
|
|
|
(cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
|
2001-10-31 15:19:49 +00:00
|
|
|
updateStatus(bv, true);
|
|
|
|
} else {
|
2001-07-31 09:53:40 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2002-08-19 10:11:13 +00:00
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
cmd1.y = ascent(bv, font) + cmd.y - inset.ascent(bv, font);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
|
|
// inlined is special - the text appears above
|
2001-10-31 15:19:49 +00:00
|
|
|
// button_bottom_y
|
2002-08-19 10:11:13 +00:00
|
|
|
if (status_ == Inlined)
|
|
|
|
inset.localDispatch(cmd1);
|
|
|
|
else if (!collapsed_ && (cmd.y > button_bottom_y)) {
|
|
|
|
cmd1.y -= ascent_collapsed() + descent_collapsed();
|
|
|
|
inset.localDispatch(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)
|
|
|
|
inset.localDispatch(cmd);
|
|
|
|
else
|
|
|
|
InsetCollapsable::localDispatch(cmd);
|
2001-12-04 16:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
int InsetERT::latex(Buffer const *, ostream & os, bool /*fragile*/,
|
2001-06-27 14:10:35 +00:00
|
|
|
bool /*free_spc*/) const
|
|
|
|
{
|
2001-07-16 15:42:57 +00:00
|
|
|
Paragraph * par = inset.paragraph();
|
2001-09-28 20:23:49 +00:00
|
|
|
int lines = 0;
|
2001-07-16 15:42:57 +00:00
|
|
|
while (par) {
|
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);
|
2001-07-16 15:42:57 +00:00
|
|
|
switch (c) {
|
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
os << '\n';
|
2001-09-28 20:23:49 +00:00
|
|
|
++lines;
|
2001-07-16 15:42:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << c;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-09 23:12:04 +00:00
|
|
|
}
|
2001-07-16 15:42:57 +00:00
|
|
|
par = par->next();
|
2001-09-28 20:23:49 +00:00
|
|
|
if (par) {
|
2001-08-18 15:01:09 +00:00
|
|
|
os << "\n\n";
|
2001-09-28 20:23:49 +00:00
|
|
|
lines += 2;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
int InsetERT::ascii(Buffer const *, ostream &, int /*linelen*/) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
int InsetERT::linuxdoc(Buffer const *, ostream & os) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2001-10-15 12:21:11 +00:00
|
|
|
Paragraph * par = inset.paragraph();
|
|
|
|
int lines = 0;
|
|
|
|
while (par) {
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type siz = par->size();
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2001-10-15 12:21:11 +00:00
|
|
|
Paragraph::value_type c = par->getChar(i);
|
|
|
|
switch (c) {
|
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
os << '\n';
|
|
|
|
++lines;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
par = par->next();
|
|
|
|
if (par) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
int InsetERT::docbook(Buffer const *, ostream & os, bool) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2001-10-15 12:21:11 +00:00
|
|
|
Paragraph * par = inset.paragraph();
|
|
|
|
int lines = 0;
|
|
|
|
while (par) {
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type siz = par->size();
|
|
|
|
for (pos_type i = 0; i < siz; ++i) {
|
2001-10-15 12:21:11 +00:00
|
|
|
Paragraph::value_type c = par->getChar(i);
|
|
|
|
switch (c) {
|
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
os << '\n';
|
|
|
|
++lines;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
par = par->next();
|
|
|
|
if (par) {
|
|
|
|
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
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
|
2001-07-24 15:07:09 +00:00
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
Inset::RESULT result = DISPATCHED_NOUPDATE;
|
|
|
|
BufferView * bv = cmd.view();
|
2001-07-31 09:53:40 +00:00
|
|
|
|
2002-08-10 15:21:07 +00:00
|
|
|
if (inset.paragraph()->empty()) {
|
2001-07-31 09:53:40 +00:00
|
|
|
set_latex_font(bv);
|
|
|
|
}
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
lfunMousePress(cmd);
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
lfunMouseMotion(cmd);
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
lfunMouseRelease(cmd);
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
bv->owner()->setLayout(inset.paragraph()->layout()->name());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = InsetCollapsable::localDispatch(cmd);
|
2001-07-24 15:07:09 +00:00
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
|
|
switch (cmd.action) {
|
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);
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
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;
|
|
|
|
pos_type const p_siz = inset.paragraph()->size();
|
2002-02-16 15:59:55 +00:00
|
|
|
pos_type const n = min(max_length, p_siz);
|
2001-07-24 22:08:49 +00:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
2001-07-25 19:45:21 +00:00
|
|
|
for(; i < n && j < p_siz; ++j) {
|
2001-07-24 22:08:49 +00:00
|
|
|
if (inset.paragraph()->isInset(j))
|
|
|
|
continue;
|
|
|
|
la += inset.paragraph()->getChar(j);
|
|
|
|
++i;
|
|
|
|
}
|
2002-05-31 12:17:28 +00:00
|
|
|
if (inset.paragraph()->next() || (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
|
|
|
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
int InsetERT::ascent(BufferView * bv, LyXFont const & font) const
|
2001-07-31 09:53:40 +00:00
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
if (!inlined())
|
|
|
|
return InsetCollapsable::ascent(bv, font);
|
|
|
|
|
|
|
|
return inset.ascent(bv, font);
|
2001-07-31 09:53:40 +00:00
|
|
|
}
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
|
|
|
int InsetERT::descent(BufferView * bv, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
if (!inlined())
|
|
|
|
return InsetCollapsable::descent(bv, font);
|
|
|
|
|
|
|
|
return inset.descent(bv, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetERT::width(BufferView * bv, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
if (!inlined())
|
|
|
|
return InsetCollapsable::width(bv, font);
|
|
|
|
|
|
|
|
return inset.width(bv, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
void InsetERT::draw(BufferView * bv, LyXFont const & f,
|
|
|
|
int baseline, float & x, bool cleared) const
|
2001-07-31 09:53:40 +00:00
|
|
|
{
|
|
|
|
Painter & pain = bv->painter();
|
|
|
|
|
|
|
|
button_length = width_collapsed();
|
|
|
|
button_top_y = -ascent(bv, f);
|
|
|
|
button_bottom_y = -ascent(bv, f) + ascent_collapsed() +
|
|
|
|
descent_collapsed();
|
|
|
|
|
|
|
|
if (!isOpen()) {
|
|
|
|
draw_collapsed(pain, baseline, x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float old_x = x;
|
|
|
|
|
|
|
|
if (!owner())
|
|
|
|
x += static_cast<float>(scroll());
|
|
|
|
|
|
|
|
if (!cleared && (inset.need_update == InsetText::FULL ||
|
2002-03-21 17:09:55 +00:00
|
|
|
inset.need_update == InsetText::INIT ||
|
|
|
|
top_x != int(x) ||
|
|
|
|
top_baseline != baseline))
|
2001-07-31 09:53:40 +00:00
|
|
|
{
|
|
|
|
// we don't need anymore to clear here we just have to tell
|
|
|
|
// the underlying LyXText that it should do the RowClear!
|
|
|
|
inset.setUpdateStatus(bv, InsetText::FULL);
|
|
|
|
bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
top_x = int(x);
|
2001-08-07 15:07:36 +00:00
|
|
|
topx_set = true;
|
2001-07-31 09:53:40 +00:00
|
|
|
top_baseline = baseline;
|
|
|
|
|
|
|
|
int const bl = baseline - ascent(bv, f) + ascent_collapsed();
|
|
|
|
|
|
|
|
if (inlined()) {
|
|
|
|
inset.draw(bv, f, baseline, x, cleared);
|
|
|
|
} else {
|
|
|
|
draw_collapsed(pain, bl, old_x);
|
2002-03-21 17:09:55 +00:00
|
|
|
inset.draw(bv, f,
|
2001-07-31 09:53:40 +00:00
|
|
|
bl + descent_collapsed() + inset.ascent(bv, f),
|
|
|
|
x, cleared);
|
|
|
|
}
|
|
|
|
need_update = NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-05 14:55:20 +00:00
|
|
|
need_update = FULL;
|
2002-02-16 15:59:55 +00:00
|
|
|
switch (st) {
|
2001-08-06 14:55:02 +00:00
|
|
|
case Inlined:
|
2002-03-06 10:17:29 +00:00
|
|
|
if (bv)
|
|
|
|
inset.setUpdateStatus(bv, InsetText::INIT);
|
2001-08-06 14:55:02 +00:00
|
|
|
break;
|
|
|
|
case Open:
|
|
|
|
collapsed_ = false;
|
|
|
|
setButtonLabel();
|
|
|
|
break;
|
|
|
|
case Collapsed:
|
|
|
|
collapsed_ = true;
|
|
|
|
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;
|
|
|
|
}
|
2001-08-07 08:05:31 +00:00
|
|
|
if (bv)
|
2002-02-13 10:37:28 +00:00
|
|
|
bv->updateInset(const_cast<InsetERT *>(this), false);
|
2001-08-06 14:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetERT::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2002-08-13 14:40:38 +00:00
|
|
|
bv->owner()->getDialogs().showERT(const_cast<InsetERT *>(this));
|
2001-08-06 14:55:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::open(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (!collapsed_)
|
|
|
|
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-08-13 14:40:38 +00:00
|
|
|
WordLangTuple const
|
|
|
|
InsetERT::selectNextWordToSpellcheck(BufferView * bv, float &) const
|
2001-09-24 14:29:27 +00:00
|
|
|
{
|
2002-02-20 14:55:17 +00:00
|
|
|
bv->unlockInset(const_cast<InsetERT *>(this));
|
2002-08-06 22:38:44 +00:00
|
|
|
return WordLangTuple();
|
2001-09-24 14:29:27 +00:00
|
|
|
}
|
2002-02-20 14:55:17 +00:00
|
|
|
|
2002-03-06 14:24:34 +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
|
|
|
|
|
|
|
|
|
|
|
int InsetERT::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
|
|
|
|
{
|
2002-03-06 10:17:29 +00:00
|
|
|
int w = InsetCollapsable::getMaxWidth(bv, in);
|
2002-03-05 14:55:20 +00:00
|
|
|
if (status_ != Inlined || w < 0)
|
|
|
|
return w;
|
|
|
|
LyXText * text = inset.getLyXText(bv);
|
2002-03-06 10:17:29 +00:00
|
|
|
int rw = text->firstRow()->width();
|
|
|
|
if (!rw)
|
|
|
|
rw = w;
|
|
|
|
rw += 40;
|
|
|
|
if (!text->firstRow()->next() && rw < w)
|
2002-03-05 14:55:20 +00:00
|
|
|
return -1;
|
|
|
|
return w;
|
|
|
|
}
|
2002-05-31 12:17:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::update(BufferView * bv, LyXFont const & font,
|
2002-06-24 20:28:12 +00:00
|
|
|
bool reinit)
|
2002-05-31 12:17:28 +00:00
|
|
|
{
|
|
|
|
if (inset.need_update & InsetText::INIT ||
|
|
|
|
inset.need_update & InsetText::FULL)
|
|
|
|
{
|
|
|
|
setButtonLabel();
|
|
|
|
}
|
|
|
|
InsetCollapsable::update(bv, font, reinit);
|
|
|
|
}
|