-/* This file is part of
- * ======================================================
+/**
+ * \file insettext.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
*
- * Copyright 1998-2001 The LyX Team.
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "insettext.h"
#include "undo_funcs.h"
#include "WordLangTuple.h"
#include "paragraph_funcs.h"
+#include "sgml.h"
+#include "rowpainter.h"
#include "frontends/Alert.h"
#include "frontends/Dialogs.h"
}
}
+
void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
{
if (sstate.lpar) {
{
paragraphs.set(new Paragraph);
paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
+ if (bp.tracking_changes)
+ paragraphs.begin()->trackChanges();
init();
}
}
-void InsetText::clear()
+void InsetText::clear(bool just_mark_erased)
{
+ if (just_mark_erased) {
+ ParagraphList::iterator it = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ for (; it != end; ++it) {
+ it->markErased();
+ }
+ need_update = FULL;
+ return;
+ }
+
// This is a gross hack...
LyXLayout_ptr old_layout = paragraphs.begin()->layout();
{
ParagraphList::iterator it = paragraphs.begin();
ParagraphList::iterator end = paragraphs.end();
+ Paragraph::depth_type dth = 0;
for (; it != end; ++it) {
- it->write(buf, os, buf->params, 0);
+ it->write(buf, os, buf->params, dth);
}
}
Paragraph::depth_type depth = 0;
LyXFont font(LyXFont::ALL_INHERIT);
- clear();
+ clear(false);
+
+ if (buf->params.tracking_changes)
+ paragraphs.begin()->trackChanges();
while (lex.isOK()) {
lex.nextToken();
int yf = y_offset + first;
y = 0;
while ((row != 0) && (yf < ph)) {
- lt->getVisibleRow(bv, y + y_offset + first, int(x),
- row, y + lt->first_y, cleared);
+ Row * prev = row->previous();
+ RowPainter rp(*bv, *lt, *row);
+ if (rp.paint(y + y_offset + first, int(x), y + lt->first_y, cleared))
+ lt->markChangeInDraw(bv, row, prev);
if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
lt->need_break_row = row;
lt->fullRebreak(bv);
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
hideInsetCursor(bv);
if (the_locking_inset) {
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
bool ret = false;
if (inset) {
if (isHighlyEditableInset(inset))
inset_y = ciy(bv) + drawTextYOffset;
cmd1.x = cmd.x - inset_x;
cmd1.y = cmd.x - inset_y;
- ret = inset->localDispatch(cmd1);
+// note that we should do ret = inset->localDispatch(cmd1)
+// and fix this instead (Alfredo);
+ ret = true;
inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
}
updateLocal(bv, CURSOR_PAR, false);
Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
{
BufferView * bv = ev.view();
+ switch (ev.action) {
+ case LFUN_MOUSE_PRESS:
+ lfunMousePress(ev);
+ return DISPATCHED;
+ case LFUN_MOUSE_MOTION:
+ lfunMouseMotion(ev);
+ return DISPATCHED;
+ case LFUN_MOUSE_RELEASE:
+ return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
+ default:
+ break;
+ }
+
bool was_empty = (paragraphs.begin()->empty() && !paragraphs.begin()->next());
no_selection = false;
RESULT result = UpdatableInset::localDispatch(ev);
}
break;
case FINISHED_DOWN:
- {
- LyXText *lt = getLyXText(bv);
- if (lt->cursor.irow()->next()) {
- lt->setCursorFromCoordinates(
- bv, lt->cursor.ix() + inset_x,
- lt->cursor.iy() -
- lt->cursor.irow()->baseline() +
- lt->cursor.irow()->height() + 1);
- lt->cursor.x_fix(lt->cursor.x());
+ if ((result = moveDown(bv)) >= FINISHED) {
updateLocal(bv, CURSOR, false);
- } else {
bv->unlockInset(this);
}
- }
break;
default:
result = DISPATCHED;
int updflag = false;
switch (ev.action) {
- case LFUN_MOUSE_PRESS:
- lfunMousePress(ev);
- return DISPATCHED;
-
- case LFUN_MOUSE_MOTION:
- lfunMouseMotion(ev);
- return DISPATCHED;
-
- case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
-
// Normal chars
case LFUN_SELFINSERT:
if (bv->buffer()->isReadonly()) {
* typed in now. Depends on lyxrc settings
* "auto_region_delete", which defaults to
* true (on). */
-
+#if 0
+ // This should not be needed here and is also WRONG!
setUndo(bv, Undo::INSERT,
lt->cursor.par(), lt->cursor.par()->next());
+#endif
bv->switchKeyMap();
if (lyxrc.auto_region_delete) {
if (lt->selection.set()) {
lt->cursorEnd(bv);
updwhat = CURSOR;
break;
+ case LFUN_PRIOR:
+ if (!crow(bv)->previous())
+ result = FINISHED_UP;
+ else {
+ lt->cursorPrevious(bv);
+ result = DISPATCHED_NOUPDATE;
+ }
+ updwhat = CURSOR;
+ break;
+ case LFUN_NEXT:
+ if (!crow(bv)->next())
+ result = FINISHED_DOWN;
+ else {
+ lt->cursorNext(bv);
+ result = DISPATCHED_NOUPDATE;
+ }
+ updwhat = CURSOR;
+ break;
case LFUN_BACKSPACE: {
- setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
if (lt->selection.set())
lt->cutSelection(bv, true, false);
else
break;
case LFUN_DELETE: {
- setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
if (lt->selection.set()) {
lt->cutSelection(bv, true, false);
} else {
break;
case LFUN_CUT: {
- setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
lt->cutSelection(bv);
updwhat = CURSOR_PAR;
updflag = true;
if (!autoBreakRows) {
if (CutAndPaste::nrOfParagraphs() > 1) {
- Alert::alert(_("Impossible operation"),
+ Alert::alert(_("Impossible operation!"),
_("Cannot include more than one paragraph!"),
_("Sorry."));
break;
}
}
+#if 0
+ // This should not be needed here and is also WRONG!
setUndo(bv, Undo::INSERT,
lt->cursor.par(), lt->cursor.par()->next());
+#endif
lt->pasteSelection(bv);
// bug 393
lt->clearSelection();
result = DISPATCHED;
break;
}
+#if 0
+ // This should not be needed here and is also WRONG!
setUndo(bv, Undo::INSERT,
lt->cursor.par(), lt->cursor.par()->next());
+#endif
lt->insertChar(bv, Paragraph::META_NEWLINE);
updwhat = CURSOR | CURSOR_PAR;
updflag = true;
bool moving_arg, bool) const
{
TexRow texrow;
- buf->latexParagraphs(os, &*(paragraphs.begin()), 0,
+ buf->latexParagraphs(os, paragraphs.begin(), paragraphs.end(),
texrow, moving_arg);
return texrow.rows();
}
for (; depth > p->params().depth(); --depth) {
if (environment_inner[depth] != "!-- --") {
item_name = "listitem";
- lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+ lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
if (environment_inner[depth] == "varlistentry")
- lines += buf->sgmlCloseTag(os, depth+command_depth, mixcont, environment_inner[depth]);
+ lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
}
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
environment_stack[depth].erase();
environment_inner[depth].erase();
}
&& !environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
- lines += buf->sgmlCloseTag(os, command_depth+depth, mixcont, item_name);
+ lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
if (environment_inner[depth] == "varlistentry")
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
}
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
environment_stack[depth].erase();
environment_inner[depth].erase();
// Write opening SGML tags.
switch (style->latextype) {
case LATEX_PARAGRAPH:
- lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexname());
+ lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
break;
case LATEX_COMMAND:
- buf->sgmlError(p, 0, _("Error : LatexType Command not allowed here.\n"));
+ buf->sgmlError(p, 0, _("Error: LatexType Command not allowed here.\n"));
return -1;
break;
}
environment_stack[depth] = style->latexname();
environment_inner[depth] = "!-- --";
- lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+ lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
} else {
if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
- lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+ lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
if (environment_inner[depth] == "varlistentry")
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
}
}
if (style->latexparam() == "CDATA")
os << "<![CDATA[";
else
- lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexparam());
+ lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
}
break;
}
desc_on = (style->labeltype == LABEL_MANUAL);
- environment_inner[depth] = desc_on?"varlistentry":"listitem";
- lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
+ environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
+ lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
- item_name = desc_on?"term":"para";
- lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, item_name);
+ item_name = desc_on ? "term" : "para";
+ lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
break;
default:
- lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexname());
+ lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
break;
}
if (style->latexparam() == "CDATA")
os << "]]>";
else
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexparam());
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
}
break;
case LATEX_ITEM_ENVIRONMENT:
if (desc_on == 1) break;
end_tag= "para";
- lines += buf->sgmlCloseTag(os, depth + 1 + command_depth, mixcont, end_tag);
+ lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
break;
case LATEX_PARAGRAPH:
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexname());
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
break;
default:
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexname());
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
break;
}
}
if (!environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
item_name = "listitem";
- lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+ lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
if (environment_inner[depth] == "varlistentry")
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
}
- lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+ lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
}
}
}
-int InsetText::beginningOfMainBody(Paragraph * p) const
-{
- if (p->layout()->labeltype != LABEL_MANUAL)
- return 0;
- else
- return p->beginningOfMainBody();
-}
-
-
void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
{
if (the_locking_inset) {
}
-Inset::RESULT
-InsetText::moveUp(BufferView * bv)
+Inset::RESULT InsetText::moveUp(BufferView * bv)
{
if (!crow(bv)->previous())
return FINISHED_UP;
}
-Inset::RESULT
-InsetText::moveDown(BufferView * bv)
+Inset::RESULT InsetText::moveDown(BufferView * bv)
{
if (!crow(bv)->next())
return FINISHED_DOWN;
x -= drawTextXOffset;
int dummyx = x;
int dummyy = y + insetAscent;
- Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
+ Inset * inset = getLyXText(bv)->checkInsetHit(bv, dummyx, dummyy);
// we only do the edit() call if the inset was hit by the mouse
// or if it is a highly editable inset. So we should call this
// function from our own edit with button < 0.
}
+void InsetText::markNew(bool track_changes)
+{
+ ParagraphList::iterator pit = paragraphs.begin();
+ ParagraphList::iterator pend = paragraphs.end();
+ for (; pit != pend; ++pit) {
+ if (track_changes) {
+ pit->trackChanges();
+ } else {
+ // no-op when not tracking
+ pit->cleanChanges();
+ }
+ }
+}
+
+
void InsetText::setText(string const & data, LyXFont const & font)
{
- clear();
+ clear(false);
for (unsigned int i = 0; i < data.length(); ++i)
paragraphs.begin()->insertChar(i, data[i], font);
reinitLyXText();
}
-Paragraph * InsetText::getParFromID(int id) const
-{
- ParagraphList::iterator it = paragraphs.begin();
- ParagraphList::iterator end = paragraphs.end();
- for (; it != end; ++it) {
- if (it->id() == id) {
- return &*(it);
- }
- Paragraph * tmp2 = it->getParFromID(id);
- if (tmp2 != 0) {
- return tmp2;
- }
- }
- return 0;
-}
-
-
Paragraph * InsetText::firstParagraph() const
{
Paragraph * result;
LyXCursor const & InsetText::cursor(BufferView * bv) const
{
- if (the_locking_inset)
- return the_locking_inset->cursor(bv);
- return getLyXText(bv)->cursor;
+ if (the_locking_inset)
+ return the_locking_inset->cursor(bv);
+ return getLyXText(bv)->cursor;
}
}
+bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
+{
+ bool clear = false;
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+ if (the_locking_inset) {
+ if (the_locking_inset->nextChange(bv, length))
+ return true;
+ lt->cursorRight(bv, true);
+ }
+ lyxfind::SearchResult result =
+ lyxfind::findNextChange(bv, lt, length);
+
+ if (result == lyxfind::SR_FOUND) {
+ LyXCursor cur = lt->cursor;
+ bv->unlockInset(bv->theLockingInset());
+ if (bv->lockInset(this))
+ locked = true;
+ lt->cursor = cur;
+ lt->setSelectionRange(bv, length);
+ updateLocal(bv, SELECTION, false);
+ }
+ if (clear)
+ lt = 0;
+ return result != lyxfind::SR_NOT_FOUND;
+}
+
+
bool InsetText::searchForward(BufferView * bv, string const & str,
bool cs, bool mw)
{
if (bv->lockInset(this))
locked = true;
lt->cursor = cur;
- lt->setSelectionOverString(bv, str);
+ lt->setSelectionRange(bv, str.length());
updateLocal(bv, SELECTION, false);
}
if (clear)
if (bv->lockInset(this))
locked = true;
lt->cursor = cur;
- lt->setSelectionOverString(bv, str);
+ lt->setSelectionRange(bv, str.length());
updateLocal(bv, SELECTION, false);
}
if (clear)
void InsetText::collapseParagraphs(BufferView * bv) const
{
- BufferParams const & bparams = bv->buffer()->params;
LyXText * llt = getLyXText(bv);
while (paragraphs.begin()->next()) {
llt->selection.end.pos() + paragraphs.begin()->size());
}
}
- pasteParagraph(bparams, &*paragraphs.begin());
+ mergeParagraph(bv->buffer(), paragraphs.begin());
}
reinitLyXText();
}
}
-void InsetText::appendParagraphs(BufferParams const & bparams,
+void InsetText::appendParagraphs(Buffer * buffer,
Paragraph * newpar)
{
+ BufferParams const & bparams = buffer->params;
Paragraph * buf;
Paragraph * tmpbuf = newpar;
Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
+ if (bparams.tracking_changes)
+ buf->cleanChanges();
while (tmpbuf->next()) {
tmpbuf = tmpbuf->next();
lastbuffer->next(new Paragraph(*tmpbuf, false));
lastbuffer->next()->previous(lastbuffer);
lastbuffer = lastbuffer->next();
+ if (bparams.tracking_changes)
+ lastbuffer->cleanChanges();
}
lastbuffer = &*(paragraphs.begin());
while (lastbuffer->next())
// paste it!
lastbuffer->next(buf);
buf->previous(lastbuffer);
- pasteParagraph(bparams, lastbuffer);
+ mergeParagraph(buffer, lastbuffer);
reinitLyXText();
}