-/* This file is part of
- * ======================================================
+/**
+ * \file insetert.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Processor
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
*
- * Copyright 1998 The LyX Team.
- *
- *======================================================*/
-
+ * Full author contact details are available in file CREDITS
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "insetert.h"
-#include "gettext.h"
-#include "lyxfont.h"
-#include "language.h"
+#include "insettext.h"
+
#include "buffer.h"
#include "BufferView.h"
-#include "frontends/LyXView.h"
-#include "lyxtext.h"
#include "debug.h"
-#include "lyxtextclasslist.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "language.h"
+#include "lyxfont.h"
+#include "lyxlex.h"
#include "lyxrow.h"
+#include "lyxtext.h"
+#include "WordLangTuple.h"
-#include "insets/insettext.h"
-
-#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
+#include "frontends/LyXView.h"
#include "support/LOstream.h"
+#include "support/LAssert.h"
+#include "support/lstrings.h"
using std::ostream;
InsetERT::~InsetERT()
{
- hideDialog();
+ InsetERTMailer mailer(*this);
+ mailer.hideDialog();
}
inset.read(buf, lex);
#ifdef SET_HARD_FONT
-#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();
<< "status "<< st << "\n";
//inset.writeParagraphData(buf, os);
- string const layout(textclasslist[buf->params.textclass].defaultLayoutName());
+ string const layout(buf->params.getLyXTextClass().defaultLayoutName());
Paragraph * par = inset.paragraph();
while (par) {
os << "\n\\layout " << layout << "\n";
Paragraph::value_type c = par->getChar(i);
switch (c) {
case Paragraph::META_INSET:
- case Paragraph::META_HFILL:
- lyxerr << "Element is not allowed in insertERT"
- << endl;
- case Paragraph::META_NEWLINE:
- os << "\n\\newline \n";
+ if (par->getInset(i)->lyxCode() != Inset::NEWLINE_CODE) {
+ lyxerr << "Element is not allowed in insertERT"
+ << endl;
+ } else {
+ par->getInset(i)->write(buf, os);
+ }
break;
+
case '\\':
os << "\n\\backslash \n";
break;
// if selectall is activated then the fontchange was an outside general
// fontchange and this messages is not needed
if (!selectall)
- Alert::alert(_("Impossible Operation!"),
+ Alert::alert(_("Impossible operation!"),
_("Not permitted to change font-types inside ERT-insets!"),
_("Sorry."));
}
}
}
-
-void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
+void InsetERT::edit(BufferView * bv, int x, int y, mouse_button::state button)
{
- if (button == 3)
+ if (button == mouse_button::button3)
return;
if (status_ == Inlined) {
}
-
-
-void InsetERT::insetButtonPress(BufferView * bv,
- int x, int y, int button)
+void InsetERT::lfunMousePress(FuncRequest const & cmd)
{
- if (status_ == Inlined) {
- inset.insetButtonPress(bv, x, y, button);
- } else {
- InsetCollapsable::insetButtonPress(bv, x, y, button);
- }
+ if (status_ == Inlined)
+ inset.localDispatch(cmd);
+ else
+ InsetCollapsable::localDispatch(cmd);
}
-bool InsetERT::insetButtonRelease(BufferView * bv, int x, int y, int button)
+bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
{
- if (button == 3) {
+ BufferView * bv = cmd.view();
+
+ if (cmd.button() == mouse_button::button3) {
showInsetDialog(bv);
return true;
}
- if (status_ != Inlined && (x >= 0) && (x < button_length) &&
- (y >= button_top_y) && (y <= button_bottom_y)) {
+ if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) &&
+ (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
updateStatus(bv, true);
} else {
LyXFont font(LyXFont::ALL_SANE);
- int yy = ascent(bv, font) + y - inset.ascent(bv, font);
+ FuncRequest cmd1 = cmd;
+ cmd1.y = ascent(bv, font) + cmd.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);
+ if (status_ == Inlined)
+ inset.localDispatch(cmd1);
+ else if (!collapsed_ && (cmd.y > button_bottom_y)) {
+ cmd1.y -= ascent_collapsed() + descent_collapsed();
+ inset.localDispatch(cmd1);
}
}
return false;
}
-void InsetERT::insetMotionNotify(BufferView * bv,
- int x, int y, int state)
+void InsetERT::lfunMouseMotion(FuncRequest const & cmd)
{
- if (status_ == Inlined) {
- inset.insetMotionNotify(bv, x, y, state);
- } else {
- InsetCollapsable::insetMotionNotify(bv, x, y, state);
- }
+ if (status_ == Inlined)
+ inset.localDispatch(cmd);
+ else
+ InsetCollapsable::localDispatch(cmd);
}
while (par) {
pos_type siz = par->size();
for (pos_type i = 0; i < siz; ++i) {
- Paragraph::value_type c = par->getChar(i);
- switch (c) {
- case Paragraph::META_NEWLINE:
+ // ignore all struck out text
+ if (isDeletedText(*par, i))
+ continue;
+
+ if (par->isNewline(i)) {
os << '\n';
++lines;
- break;
- default:
- os << c;
- break;
+ } else {
+ os << par->getChar(i);
}
}
par = par->next();
}
-int InsetERT::ascii(Buffer const *,
- ostream &, int /*linelen*/) const
+int InsetERT::ascii(Buffer const *, ostream &, int /*linelen*/) const
{
return 0;
}
while (par) {
pos_type siz = par->size();
for (pos_type i = 0; i < siz; ++i) {
- Paragraph::value_type c = par->getChar(i);
- switch (c) {
- case Paragraph::META_NEWLINE:
+ if (par->isNewline(i)) {
os << '\n';
++lines;
- break;
- default:
- os << c;
- break;
+ } else {
+ os << par->getChar(i);
}
}
par = par->next();
}
-int InsetERT::docbook(Buffer const *, ostream & os) const
+int InsetERT::docbook(Buffer const *, ostream & os, bool) const
{
Paragraph * par = inset.paragraph();
int lines = 0;
while (par) {
pos_type siz = par->size();
for (pos_type i = 0; i < siz; ++i) {
- Paragraph::value_type c = par->getChar(i);
- switch (c) {
- case Paragraph::META_NEWLINE:
+ if (par->isNewline(i)) {
os << '\n';
++lines;
- break;
- default:
- os << c;
- break;
+ } else {
+ os << par->getChar(i);
}
}
par = par->next();
}
-UpdatableInset::RESULT
-InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
+Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
{
- UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
+ Inset::RESULT result = UNDISPATCHED;
+ BufferView * bv = cmd.view();
- if (!inset.paragraph()->size()) {
+ if (inset.paragraph()->empty()) {
set_latex_font(bv);
}
- switch (action) {
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetERT::ERTStatus status_;
+ InsetERTMailer::string2params(cmd.argument, status_);
+
+ status(bv, status_);
+ bv->updateInset(this);
+ result = DISPATCHED;
+ }
+ break;
+
+ case LFUN_MOUSE_PRESS:
+ lfunMousePress(cmd);
+ result = DISPATCHED;
+ break;
+
+ case LFUN_MOUSE_MOTION:
+ lfunMouseMotion(cmd);
+ result = DISPATCHED;
+ break;
+
+ case LFUN_MOUSE_RELEASE:
+ lfunMouseRelease(cmd);
+ result = DISPATCHED;
+ break;
+
case LFUN_LAYOUT:
- bv->owner()->setLayout(inset.paragraph()->layout());
+ bv->owner()->setLayout(inset.paragraph()->layout()->name());
+ result = DISPATCHED_NOUPDATE;
break;
+
default:
- result = InsetCollapsable::localDispatch(bv, action, arg);
+ result = InsetCollapsable::localDispatch(cmd);
}
- switch (action) {
+
+ switch (cmd.action) {
case LFUN_BREAKPARAGRAPH:
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
case LFUN_BACKSPACE:
pos_type const max_length = 15;
pos_type const p_siz = inset.paragraph()->size();
pos_type const n = min(max_length, p_siz);
- int i = 0;
- int j = 0;
+ pos_type i = 0;
+ pos_type j = 0;
for(; i < n && j < p_siz; ++j) {
if (inset.paragraph()->isInset(j))
continue;
la += inset.paragraph()->getChar(j);
++i;
}
- if (i > 0 && j < p_siz) {
+ if (inset.paragraph()->next() || (i > 0 && j < p_siz)) {
la += "...";
}
if (la.empty()) {
bool InsetERT::checkInsertChar(LyXFont & /* font */)
{
#ifdef SET_HARD_FONT
-#ifndef INHERIT_LANG
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
-#else
- LyXFont f(LyXFont::ALL_INHERIT);
-#endif
font = f;
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
void InsetERT::draw(BufferView * bv, LyXFont const & f,
- int baseline, float & x, bool cleared) const
+ int baseline, float & x) const
{
+ lyx::Assert(bv);
+ cache(bv);
+
Painter & pain = bv->painter();
button_length = width_collapsed();
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);
topx_set = true;
top_baseline = baseline;
int const bl = baseline - ascent(bv, f) + ascent_collapsed();
if (inlined()) {
- inset.draw(bv, f, baseline, x, cleared);
+ inset.draw(bv, f, baseline, x);
} else {
draw_collapsed(pain, bl, old_x);
- inset.draw(bv, f,
- bl + descent_collapsed() + inset.ascent(bv, f),
- x, cleared);
+ inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
}
need_update = NONE;
}
void InsetERT::set_latex_font(BufferView * /* bv */)
{
#ifdef SET_HARD_FONT
-#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);
bv->unlockInset(const_cast<InsetERT *>(this));
break;
}
- if (bv)
- bv->updateInset(const_cast<InsetERT *>(this), false);
+ if (bv) {
+ bv->updateInset(const_cast<InsetERT *>(this));
+ bv->buffer()->markDirty();
+ }
}
}
bool InsetERT::showInsetDialog(BufferView * bv) const
{
- bv->owner()->getDialogs()->showERT(const_cast<InsetERT *>(this));
+ InsetERTMailer mailer(const_cast<InsetERT &>(*this));
+ mailer.showDialog(bv);
return true;
}
}
-string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,
- float &) const
+WordLangTuple const
+InsetERT::selectNextWordToSpellcheck(BufferView * bv, float &) const
{
bv->unlockInset(const_cast<InsetERT *>(this));
- return string();
+ return WordLangTuple();
}
void InsetERT::getDrawFont(LyXFont & font) const
{
-#ifndef INHERIT_LANG
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
-#else
- LyXFont f(LyXFont::ALL_INHERIT);
-#endif
font = f;
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
return -1;
return w;
}
+
+
+void InsetERT::update(BufferView * bv, LyXFont const & font,
+ bool reinit)
+{
+ if (inset.need_update & InsetText::INIT ||
+ inset.need_update & InsetText::FULL)
+ {
+ setButtonLabel();
+ }
+ InsetCollapsable::update(bv, font, reinit);
+}
+
+
+string const InsetERTMailer::name_("ert");
+
+InsetERTMailer::InsetERTMailer(InsetERT & inset)
+ : inset_(inset)
+{}
+
+
+string const InsetERTMailer::inset2string() const
+{
+ return params2string(inset_.status());
+}
+
+
+void InsetERTMailer::string2params(string const & in,
+ InsetERT::ERTStatus & status)
+{
+ status = InsetERT::Collapsed;
+
+ string name;
+ string body = split(in, name, ' ');
+
+ if (body.empty())
+ return;
+
+ status = static_cast<InsetERT::ERTStatus>(strToInt(body));
+}
+
+
+string const
+InsetERTMailer::params2string(InsetERT::ERTStatus status)
+{
+ return name_ + ' ' + tostr(status);
+}