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"
|
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"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
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-07-24 10:13:19 +00:00
|
|
|
InsetERT::InsetERT() : InsetCollapsable()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
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-07-24 15:07:09 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
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();
|
|
|
|
Paragraph::size_type pos = 0;
|
|
|
|
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-07-24 22:08:49 +00:00
|
|
|
void InsetERT::read(Buffer const * buf, LyXLex & lex)
|
|
|
|
{
|
|
|
|
InsetCollapsable::read(buf, lex);
|
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-04-02 14:02:58 +00:00
|
|
|
os << getInsetName() << "\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetCollapsable::write(buf, os);
|
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)
|
|
|
|
WriteAlert(_("Impossible Operation!"),
|
|
|
|
_("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-06-28 10:25:20 +00:00
|
|
|
void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
|
2000-03-24 13:24:58 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetCollapsable::edit(bv, x, y, button);
|
2001-07-25 19:45:21 +00:00
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
2001-07-25 19:45:21 +00:00
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
inset.setFont(bv, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetERT::edit(BufferView * bv, bool)
|
|
|
|
{
|
|
|
|
edit(bv, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
void InsetERT::insetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, int button)
|
|
|
|
{
|
|
|
|
if ((x >= 0) && (x < button_length) &&
|
|
|
|
(y >= button_top_y) && (y <= button_bottom_y)) {
|
|
|
|
if (collapsed_) {
|
|
|
|
setLabel(_("666"));
|
|
|
|
} else {
|
|
|
|
setLabel(get_new_label());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InsetCollapsable::insetButtonRelease(bv, x, y, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
while (par) {
|
|
|
|
Paragraph::size_type siz = inset.paragraph()->size();
|
|
|
|
for (Paragraph::size_type i = 0; i != siz; ++i) {
|
|
|
|
char c = inset.paragraph()->getChar(i);
|
|
|
|
switch (c) {
|
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
os << '\n';
|
|
|
|
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-06-27 14:10:35 +00:00
|
|
|
}
|
2001-07-16 15:42:57 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-28 10:25:20 +00:00
|
|
|
int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetERT::docBook(Buffer const *, std::ostream &) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
|
|
|
return 0;
|
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;
|
|
|
|
|
|
|
|
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-07-24 15:07:09 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
|
|
|
inset.setFont(bv, font);
|
|
|
|
}
|
2001-07-24 22:08:49 +00:00
|
|
|
break;
|
|
|
|
|
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;
|
|
|
|
Paragraph::size_type const max_length = 15;
|
|
|
|
|
2001-07-25 19:45:21 +00:00
|
|
|
int const p_siz = inset.paragraph()->size();
|
|
|
|
int 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-24 22:08:49 +00:00
|
|
|
la = _("666");
|
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
|
|
|
|
|
|
|
|
|
|
|
void InsetERT::setButtonLabel()
|
|
|
|
{
|
|
|
|
if (collapsed_) {
|
|
|
|
setLabel(get_new_label());
|
|
|
|
} else {
|
|
|
|
setLabel(_("666"));
|
|
|
|
}
|
|
|
|
}
|