2000-02-25 12:06:15 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
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"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxfont.h"
|
2001-11-26 18:03:23 +00:00
|
|
|
#include "language.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
#include "buffer.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
#include "insets/insettext.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "support/LOstream.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
2001-07-24 15:07:09 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "LyXView.h"
|
2001-07-31 09:53:40 +00:00
|
|
|
#include "lyxtext.h"
|
2001-08-06 14:55:02 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2001-11-26 10:19:58 +00:00
|
|
|
#include "frontends/Alert.h"
|
2001-08-06 14:55:02 +00:00
|
|
|
#include "debug.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
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
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
InsetERT::InsetERT(bool collapsed)
|
|
|
|
: InsetCollapsable(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
InsetERT::InsetERT(string const & contents, bool collapsed)
|
|
|
|
: InsetCollapsable(collapsed)
|
2001-07-08 12:52:16 +00:00
|
|
|
{
|
2001-08-13 09:57:47 +00:00
|
|
|
if (collapsed)
|
|
|
|
status_ = Collapsed;
|
|
|
|
else
|
|
|
|
status_ = Open;
|
2001-08-11 18:31:14 +00:00
|
|
|
#ifndef INHERIT_LANG
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
#else
|
2001-07-24 15:07:09 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
2001-08-11 18:31:14 +00:00
|
|
|
#endif
|
2001-07-24 15:07:09 +00:00
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
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();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
token_found = true;
|
|
|
|
} else {
|
|
|
|
lyxerr << "InsetERT::Read: Missing 'status'-tag!"
|
2001-08-06 19:13:25 +00:00
|
|
|
<< std::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
|
|
|
|
|
|
|
#ifndef INHERIT_LANG
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
#else
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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;
|
|
|
|
|
|
|
|
switch(status_) {
|
|
|
|
case Open:
|
|
|
|
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);
|
|
|
|
string const layout =
|
|
|
|
textclasslist.NameOfLayout(buf->params.textclass, 0);
|
|
|
|
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"
|
|
|
|
<< std::endl;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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!"),
|
2001-05-28 15:11:24 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
|
|
|
|
{
|
|
|
|
if (button == 3)
|
|
|
|
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-10-31 15:19:49 +00:00
|
|
|
updateStatus(0);
|
2001-07-31 09:53:40 +00:00
|
|
|
set_latex_font(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::insetButtonPress(BufferView * bv,
|
|
|
|
int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (status_ == Inlined) {
|
|
|
|
inset.insetButtonPress(bv, x, y, button);
|
|
|
|
} else {
|
|
|
|
InsetCollapsable::insetButtonPress(bv, x, y, button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-17 13:33:22 +00:00
|
|
|
bool InsetERT::insetButtonRelease(BufferView * bv, int x, int y, int button)
|
2001-07-24 22:08:49 +00:00
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
if (button == 3) {
|
|
|
|
showInsetDialog(bv);
|
2001-12-17 13:33:22 +00:00
|
|
|
return true;
|
2001-08-06 14:55:02 +00:00
|
|
|
}
|
2001-10-31 15:19:49 +00:00
|
|
|
|
|
|
|
if (status_ != Inlined && (x >= 0) && (x < button_length) &&
|
|
|
|
(y >= button_top_y) && (y <= button_bottom_y)) {
|
|
|
|
updateStatus(bv, true);
|
|
|
|
} else {
|
2001-07-31 09:53:40 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2001-10-31 15:19:49 +00:00
|
|
|
int yy = ascent(bv, font) + y - inset.ascent(bv, font);
|
|
|
|
|
|
|
|
// inlined is special - the text appears above
|
|
|
|
// button_bottom_y
|
|
|
|
if (status_ == Inlined) {
|
|
|
|
inset.insetButtonRelease(bv, x, yy, button);
|
|
|
|
} else if (!collapsed_ && (y > button_bottom_y)) {
|
|
|
|
yy -= (ascent_collapsed() + descent_collapsed());
|
|
|
|
inset.insetButtonRelease(bv, x, yy, button);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
void InsetERT::insetMotionNotify(BufferView * bv,
|
|
|
|
int x, int y, int state)
|
|
|
|
{
|
|
|
|
if (status_ == Inlined) {
|
|
|
|
inset.insetMotionNotify(bv, x, y, state);
|
|
|
|
} else {
|
|
|
|
InsetCollapsable::insetMotionNotify(bv, x, y, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetERT::latex(Buffer const *, std::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
|
|
|
}
|
2001-07-16 15:42:57 +00:00
|
|
|
|
2001-09-28 20:23:49 +00:00
|
|
|
return lines;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetERT::ascii(Buffer const *,
|
2001-06-27 14:10:35 +00:00
|
|
|
std::ostream &, int /*linelen*/) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
int InsetERT::linuxdoc(Buffer const *, std::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 ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-15 12:21:11 +00:00
|
|
|
int InsetERT::docbook(Buffer const *, std::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 ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines;
|
2000-03-24 13:24:58 +00:00
|
|
|
}
|
2001-07-24 15:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
|
|
|
|
{
|
|
|
|
UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
|
|
if (!inset.paragraph()->size()) {
|
|
|
|
set_latex_font(bv);
|
|
|
|
}
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
switch(action) {
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
bv->owner()->setLayout(inset.paragraph()->getLayout());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = InsetCollapsable::localDispatch(bv, action, arg);
|
|
|
|
}
|
|
|
|
switch(action) {
|
|
|
|
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;
|
2001-07-24 22:08:49 +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();
|
|
|
|
pos_type const n = std::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;
|
|
|
|
}
|
2001-07-25 19:45:21 +00:00
|
|
|
if (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
|
|
|
|
|
|
|
|
|
|
|
bool InsetERT::checkInsertChar(LyXFont & font)
|
|
|
|
{
|
2001-08-11 18:31:14 +00:00
|
|
|
#ifndef INHERIT_LANG
|
|
|
|
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
#else
|
2001-07-27 12:03:36 +00:00
|
|
|
LyXFont f(LyXFont::ALL_INHERIT);
|
2001-08-11 18:31:14 +00:00
|
|
|
#endif
|
2001-07-27 12:03:36 +00:00
|
|
|
font = f;
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 09:53:40 +00:00
|
|
|
void InsetERT::draw(BufferView * bv, LyXFont const & f,
|
|
|
|
int baseline, float & x, bool cleared) const
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float old_x = x;
|
|
|
|
|
|
|
|
if (!owner())
|
|
|
|
x += static_cast<float>(scroll());
|
|
|
|
|
|
|
|
if (!cleared && (inset.need_update == InsetText::FULL ||
|
|
|
|
inset.need_update == InsetText::INIT ||
|
|
|
|
top_x != int(x) ||
|
|
|
|
top_baseline != baseline))
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
inset.draw(bv, f,
|
|
|
|
bl + descent_collapsed() + inset.ascent(bv, f),
|
|
|
|
x, cleared);
|
|
|
|
}
|
|
|
|
need_update = NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::set_latex_font(BufferView * bv)
|
|
|
|
{
|
2001-08-11 18:31:14 +00:00
|
|
|
#ifndef INHERIT_LANG
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
|
|
|
|
#else
|
2001-07-31 09:53:40 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
2001-08-11 18:31:14 +00:00
|
|
|
#endif
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
2001-08-06 14:55:02 +00:00
|
|
|
inset.getLyXText(bv)->setFont(bv, font, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
switch(st) {
|
|
|
|
case Inlined:
|
|
|
|
inset.setAutoBreakRows(false);
|
|
|
|
break;
|
|
|
|
case Open:
|
|
|
|
inset.setAutoBreakRows(true);
|
|
|
|
collapsed_ = false;
|
|
|
|
need_update = FULL;
|
|
|
|
setButtonLabel();
|
|
|
|
break;
|
|
|
|
case Collapsed:
|
|
|
|
inset.setAutoBreakRows(true);
|
|
|
|
collapsed_ = true;
|
|
|
|
need_update = FULL;
|
|
|
|
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)
|
2001-10-03 14:28:02 +00:00
|
|
|
bv->updateInset(const_cast<InsetERT *>(this), false);
|
2001-08-06 14:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetERT::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
bv->owner()->getDialogs()->showERT(const_cast<InsetERT *>(this));
|
|
|
|
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
|
|
|
{
|
|
|
|
if (collapsed_)
|
|
|
|
return;
|
|
|
|
status(bv, Collapsed);
|
2001-07-31 09:53:40 +00:00
|
|
|
}
|
2001-09-24 14:29:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,float &) const
|
|
|
|
{
|
|
|
|
bv->unlockInset(const_cast<InsetERT *>(this));
|
|
|
|
return string();
|
|
|
|
}
|