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-23 12:47:25 +00:00
|
|
|
setLabel(_("666"), true);
|
2001-07-08 12:52:16 +00:00
|
|
|
labelfont = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
labelfont.decSize();
|
|
|
|
labelfont.decSize();
|
2001-07-24 10:13:19 +00:00
|
|
|
#ifndef NO_LATEX
|
|
|
|
labelfont.setLatex(LyXFont::ON);
|
|
|
|
#else
|
2001-07-08 12:52:16 +00:00
|
|
|
labelfont.setColor(LColor::latex);
|
2001-07-24 10:13:19 +00:00
|
|
|
#endif
|
2001-07-08 12:52:16 +00:00
|
|
|
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-24 15:07:09 +00:00
|
|
|
#if 0
|
|
|
|
InsetERT::InsetERT(InsetERT const & in, bool same_id)
|
|
|
|
: InsetCollapsable(in, same_id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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-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-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.setLatex (LyXFont::ON);
|
2001-07-24 15:07:09 +00:00
|
|
|
#else
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
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-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:
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT: {
|
|
|
|
#ifndef NO_LATEX
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.setLatex (LyXFont::ON);
|
|
|
|
#else
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
font.setColor(LColor::latex);
|
|
|
|
#endif
|
|
|
|
inset.setFont(bv, font);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|