/* This file is part of
* ======================================================
- *
+ *
* LyX, The Document Processor
- *
+ *
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation "lyxtext.h"
-#endif
-
#include "lyxtext.h"
#include "LString.h"
#include "paragraph.h"
-#include "lyxtextclasslist.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "undo_funcs.h"
#include "buffer.h"
#include "bufferparams.h"
#include "gettext.h"
#include "BufferView.h"
-#include "LyXView.h"
#include "CutAndPaste.h"
-#include "Painter.h"
-#include "font.h"
+#include "frontends/Painter.h"
+#include "frontends/font_metrics.h"
#include "debug.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "FloatList.h"
#include "language.h"
#include "ParagraphParameters.h"
+#include "counters.h"
#include "insets/inseterror.h"
-#include "insets/insetbib.h"
+#include "insets/insetbibitem.h"
#include "insets/insetspecialchar.h"
#include "insets/insettext.h"
#include "insets/insetfloat.h"
+#include "insets/insetwrap.h"
#include "support/LAssert.h"
#include "support/textutils.h"
#include "support/lstrings.h"
+#include "BoostFormat.h"
+
using std::vector;
using std::copy;
-using std::find;
using std::endl;
using std::find;
using std::pair;
LyXText::LyXText(BufferView * bv)
- : number_of_rows(0), height(0), width(0), first_y(0),
- bv_owner(bv), inset_owner(0), the_locking_inset(0),
- need_break_row(0), refresh_y(0), refresh_row(0),
- status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
-{}
+ : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
+ inset_owner(0), the_locking_inset(0), need_break_row(0),
+ bv_owner(bv)
+{
+ refresh_row = 0;
+ clearPaint();
+}
-LyXText::LyXText(InsetText * inset)
- : number_of_rows(0), height(0), width(0), first_y(0),
- bv_owner(0), inset_owner(inset), the_locking_inset(0),
- need_break_row(0), refresh_y(0), refresh_row(0),
- status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
-{}
+LyXText::LyXText(BufferView * bv, InsetText * inset)
+ : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
+ inset_owner(inset), the_locking_inset(0), need_break_row(0),
+ bv_owner(bv)
+{
+ refresh_row = 0;
+ clearPaint();
+}
void LyXText::init(BufferView * bview, bool reinit)
{
if (reinit) {
- // Delete all rows, this does not touch the paragraphs!
- Row * tmprow = firstrow;
- while (firstrow) {
- tmprow = firstrow->next();
- delete firstrow;
- firstrow = tmprow;
- }
-
- lastrow = 0;
- refresh_row = 0;
+ rowlist_.clear();
need_break_row = 0;
width = height = 0;
copylayouttype.erase();
- number_of_rows = first_y = refresh_y = 0;
- status_ = LyXText::UNCHANGED;
- } else if (firstrow)
+ top_y(0);
+ clearPaint();
+ } else if (firstRow())
return;
Paragraph * par = ownerParagraph();
current_font = getFont(bview->buffer(), par, 0);
-
+
while (par) {
- insertParagraph(bview, par, lastrow);
+ if (rowlist_.empty())
+ insertParagraph(par, 0);
+ else
+ insertParagraph(par, lastRow());
par = par->next();
}
- setCursorIntern(bview, firstrow->par(), 0);
+ setCursorIntern(firstRow()->par(), 0);
selection.cursor = cursor;
-}
-
-LyXText::~LyXText()
-{
- // Delete all rows, this does not touch the paragraphs!
- Row * tmprow = firstrow;
- while (firstrow) {
- tmprow = firstrow->next();
- delete firstrow;
- firstrow = tmprow;
- }
+ updateCounters();
}
Buffer const * buf,
Paragraph * par)
{
+ LyXTextClass const & tclass = buf->params.getLyXTextClass();
LyXFont tmpfont(font);
Paragraph::depth_type par_depth = par->getDepth();
-
+
// Resolve against environment font information
while (par && par_depth && !tmpfont.resolved()) {
par = par->outerHook();
if (par) {
-#ifndef INHERIT_LANGUAGE
- tmpfont.realize(textclasslist[buf->params.textclass][
- par->layout()].font);
-#else
- tmpfont.realize(textclasslist.
- Style(buf->params.textclass,
- par->layout()).font,
- buf->params.language);
-#endif
+ tmpfont.realize(par->layout()->font);
par_depth = par->getDepth();
}
}
-#ifndef INHERIT_LANGUAGE
- tmpfont.realize(textclasslist[buf->params.textclass].defaultfont());
-#else
- tmpfont.realize(textclasslist[buf->params.textclass].defaultfont(),
- buf->params.language);
-#endif
+ tmpfont.realize(tclass.defaultfont());
return tmpfont;
}
// If position is -1, we get the layout font of the paragraph.
// If position is -2, we get the font of the manual label of the paragraph.
LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
- pos_type pos) const
+ pos_type pos) const
{
lyx::Assert(pos >= 0);
-
- LyXLayout const & layout =
- textclasslist[buf->params.textclass][par->layout()];
-
- Paragraph::depth_type par_depth = par->getDepth();
+
+ LyXLayout_ptr const & layout = par->layout();
+
// We specialize the 95% common case:
- if (!par_depth) {
- if (layout.labeltype == LABEL_MANUAL
- && pos < beginningOfMainBody(buf, par)) {
+ if (!par->getDepth()) {
+ if (layout->labeltype == LABEL_MANUAL
+ && pos < par->beginningOfBody()) {
// 1% goes here
LyXFont f = par->getFontSettings(buf->params, pos);
if (par->inInset())
par->inInset()->getDrawFont(f);
-#ifndef INHERIT_LANGUAGE
- return f.realize(layout.reslabelfont);
-#else
- return f.realize(layout.reslabelfont, buf->params.language);
-#endif
+ return f.realize(layout->reslabelfont);
} else {
LyXFont f = par->getFontSettings(buf->params, pos);
if (par->inInset())
par->inInset()->getDrawFont(f);
-#ifndef INHERIT_LANGUAGE
- return f.realize(layout.resfont);
-#else
- return f.realize(layout.resfont, buf->params.language);
-#endif
+ return f.realize(layout->resfont);
}
}
-
+
// The uncommon case need not be optimized as much
-
+
LyXFont layoutfont;
-
- if (pos < beginningOfMainBody(buf, par)) {
+
+ if (pos < par->beginningOfBody()) {
// 1% goes here
- layoutfont = layout.labelfont;
+ layoutfont = layout->labelfont;
} else {
// 99% goes here
- layoutfont = layout.font;
+ layoutfont = layout->font;
}
LyXFont tmpfont = par->getFontSettings(buf->params, pos);
-#ifndef INHERIT_LANGUAGE
tmpfont.realize(layoutfont);
-#else
- tmpfont.realize(layoutfont, buf->params.language);
-#endif
+
if (par->inInset())
par->inInset()->getDrawFont(tmpfont);
-
+
return realizeFont(tmpfont, buf, par);
}
LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const
{
- LyXLayout const & layout =
- textclasslist[buf->params.textclass][par->layout()];
+ LyXLayout_ptr const & layout = par->layout();
- Paragraph::depth_type par_depth = par->getDepth();
-
- if (!par_depth) {
- return layout.resfont;
+ if (!par->getDepth()) {
+ return layout->resfont;
}
- return realizeFont(layout.font, buf, par);
+ return realizeFont(layout->font, buf, par);
}
LyXFont const LyXText::getLabelFont(Buffer const * buf, Paragraph * par) const
{
- LyXLayout const & layout =
- textclasslist[buf->params.textclass][par->layout()];
-
- Paragraph::depth_type par_depth = par->getDepth();
+ LyXLayout_ptr const & layout = par->layout();
- if (!par_depth) {
- return layout.reslabelfont;
+ if (!par->getDepth()) {
+ return layout->reslabelfont;
}
- return realizeFont(layout.labelfont, buf, par);
+ return realizeFont(layout->labelfont, buf, par);
}
-void LyXText::setCharFont(BufferView * bv, Paragraph * par,
- pos_type pos, LyXFont const & fnt,
- bool toggleall)
+void LyXText::setCharFont(Paragraph * par,
+ pos_type pos, LyXFont const & fnt,
+ bool toggleall)
{
- Buffer const * buf = bv->buffer();
+ Buffer const * buf = bv()->buffer();
LyXFont font = getFont(buf, par, pos);
font.update(fnt, buf->params.language, toggleall);
// Let the insets convert their font
if (isEditableInset(inset)) {
UpdatableInset * uinset =
static_cast<UpdatableInset *>(inset);
- uinset->setFont(bv, fnt, toggleall, true);
+ uinset->setFont(bv(), fnt, toggleall, true);
}
}
void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
- pos_type pos, LyXFont const & fnt)
+ pos_type pos, LyXFont const & fnt)
{
LyXFont font(fnt);
- LyXTextClass const & tclass = textclasslist[buf->params.textclass];
- LyXLayout const & layout = tclass[par->layout()];
+ LyXTextClass const & tclass = buf->params.getLyXTextClass();
+ LyXLayout_ptr const & layout = par->layout();
// Get concrete layout font to reduce against
LyXFont layoutfont;
- if (pos < beginningOfMainBody(buf, par))
- layoutfont = layout.labelfont;
+ if (pos < par->beginningOfBody())
+ layoutfont = layout->labelfont;
else
- layoutfont = layout.font;
+ layoutfont = layout->font;
// Realize against environment font information
if (par->getDepth()) {
while (!layoutfont.resolved() && tp && tp->getDepth()) {
tp = tp->outerHook();
if (tp)
-#ifndef INHERIT_LANGUAGE
- layoutfont.realize(tclass[tp->layout()].font);
-#else
- layoutfont.realize(textclasslist.
- Style(buf->params.textclass,
- tp->layout()).font,
- buf->params.language);
-#endif
+ layoutfont.realize(tp->layout()->font);
}
}
-#ifndef INHERIT_LANGUAGE
layoutfont.realize(tclass.defaultfont());
-#else
- layoutfont.realize(tclass.defaultfont(), buf->params.language);
-#endif
// Now, reduce font against full layout font
font.reduce(layoutfont);
}
-// inserts a new row behind the specified row, increments
+// inserts a new row before the specified row, increments
// the touched counters
void LyXText::insertRow(Row * row, Paragraph * par,
- pos_type pos) const
+ pos_type pos)
{
Row * tmprow = new Row;
- if (!row) {
- tmprow->previous(0);
- tmprow->next(firstrow);
- firstrow = tmprow;
- } else {
- tmprow->previous(row);
- tmprow->next(row->next());
- row->next(tmprow);
- }
-
- if (tmprow->next())
- tmprow->next()->previous(tmprow);
-
- if (tmprow->previous())
- tmprow->previous()->next(tmprow);
-
-
tmprow->par(par);
tmprow->pos(pos);
- if (row == lastrow)
- lastrow = tmprow;
- ++number_of_rows;
+ if (!row) {
+ rowlist_.insert(rowlist_.begin(), tmprow);
+ } else {
+ rowlist_.insert(row->next(), tmprow);
+ }
}
// removes the row and reset the touched counters
-void LyXText::removeRow(Row * row) const
+void LyXText::removeRow(Row * row)
{
+ lyx::Assert(row);
+
Row * row_prev = row->previous();
- if (row->next())
- row->next()->previous(row_prev);
- if (!row_prev) {
- firstrow = row->next();
-// lyx::Assert(firstrow);
- } else {
- row_prev->next(row->next());
- }
- if (row == lastrow) {
- lyx::Assert(!row->next());
- lastrow = row_prev;
- }
+ Row * row_next = row->next();
+ int const row_height = row->height();
+
+ /* FIXME: when we cache the bview, this should just
+ * become a postPaint(), I think */
if (refresh_row == row) {
- refresh_row = row_prev ? row_prev : row->next();
- // what about refresh_y, refresh_height
+ refresh_row = row_prev ? row_prev : row_next;
+ // what about refresh_y
}
- height -= row->height(); // the text becomes smaller
-
- delete row;
- --number_of_rows; // one row less
+ if (anchor_row_ == row) {
+ if (row_prev) {
+ anchor_row_ = row_prev;
+ anchor_row_offset_ += row_prev->height();
+ } else {
+ anchor_row_ = row_next;
+ anchor_row_offset_ -= row_height;
+ }
+ }
+
+ // the text becomes smaller
+ height -= row_height;
+
+ rowlist_.erase(row);
}
// remove all following rows of the paragraph of the specified row.
-void LyXText::removeParagraph(Row * row) const
+void LyXText::removeParagraph(Row * row)
{
Paragraph * tmppar = row->par();
row = row->next();
-
+
Row * tmprow;
while (row && row->par() == tmppar) {
tmprow = row->next();
row = tmprow;
}
}
-
-// insert the specified paragraph behind the specified row
-void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
- Row * row) const
+
+void LyXText::insertParagraph(Paragraph * par, Row * row)
{
- insertRow(row, par, 0); /* insert a new row, starting
- * at postition 0 */
+ // insert a new row, starting at position 0
+ insertRow(row, par, 0);
- setCounter(bview->buffer(), par); // set the counters
-
- // and now append the whole paragraph behind the new row
+ // and now append the whole paragraph before the new row
if (!row) {
- firstrow->height(0);
- appendParagraph(bview, firstrow);
+ appendParagraph(firstRow());
} else {
- row->next()->height(0);
- appendParagraph(bview, row->next());
+ appendParagraph(row->next());
}
}
Inset * LyXText::getInset() const
{
- Inset * inset = 0;
- if (cursor.pos() == 0 && cursor.par()->bibkey) {
- inset = cursor.par()->bibkey;
- } else if (cursor.pos() < cursor.par()->size()
+ if (cursor.pos() < cursor.par()->size()
&& cursor.par()->isInset(cursor.pos())) {
- inset = cursor.par()->getInset(cursor.pos());
+ return cursor.par()->getInset(cursor.pos());
}
- return inset;
+ return 0;
}
-void LyXText::toggleInset(BufferView * bview)
+void LyXText::toggleInset()
{
Inset * inset = getInset();
// is there an editable inset at cursor position?
// No, try to see if we are inside a collapsable inset
if (inset_owner && inset_owner->owner()
&& inset_owner->owner()->isOpen()) {
- bview->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
- inset_owner->owner()->close(bview);
+ bv()->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
+ inset_owner->owner()->close(bv());
+ bv()->getLyXText()->cursorRight(bv());
}
return;
}
- //bview->owner()->message(inset->editMessage());
+ //bv()->owner()->message(inset->editMessage());
// do we want to keep this?? (JMarc)
if (!isHighlyEditableInset(inset))
- setCursorParUndo(bview);
+ setCursorParUndo(bv());
if (inset->isOpen()) {
- inset->close(bview);
+ inset->close(bv());
} else {
- inset->open(bview);
+ inset->open(bv());
}
-#if 0
- inset->open(bview, !inset->isOpen());
-#endif
+
+ bv()->updateInset(inset);
}
/* used in setlayout */
// Asger is not sure we want to do this...
-void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf,
- Paragraph * par)
+void LyXText::makeFontEntriesLayoutSpecific(Buffer const & buf,
+ Paragraph & par)
{
- LyXLayout const & layout =
- textclasslist[buf->params.textclass][par->layout()];
+ LyXLayout_ptr const & layout = par.layout();
LyXFont layoutfont;
- for (pos_type pos = 0; pos < par->size(); ++pos) {
- if (pos < beginningOfMainBody(buf, par))
- layoutfont = layout.labelfont;
+ for (pos_type pos = 0; pos < par.size(); ++pos) {
+ if (pos < par.beginningOfBody())
+ layoutfont = layout->labelfont;
else
- layoutfont = layout.font;
-
- LyXFont tmpfont = par->getFontSettings(buf->params, pos);
+ layoutfont = layout->font;
+
+ LyXFont tmpfont = par.getFontSettings(buf.params, pos);
tmpfont.reduce(layoutfont);
- par->setFont(pos, tmpfont);
+ par.setFont(pos, tmpfont);
}
}
-Paragraph * LyXText::setLayout(BufferView * bview,
- LyXCursor & cur, LyXCursor & sstart_cur,
+Paragraph * LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
LyXCursor & send_cur,
string const & layout)
{
Paragraph * endpar = send_cur.par()->next();
Paragraph * undoendpar = endpar;
-
+
if (endpar && endpar->getDepth()) {
while (endpar && endpar->getDepth()) {
endpar = endpar->next();
} else if (endpar) {
endpar = endpar->next(); // because of parindents etc.
}
-
- setUndo(bview, Undo::EDIT, sstart_cur.par(), undoendpar);
-
+
+ setUndo(bv(), Undo::EDIT, sstart_cur.par(), undoendpar);
+
// ok we have a selection. This is always between sstart_cur
// and sel_end cursor
cur = sstart_cur;
+ Paragraph * par = sstart_cur.par();
+ Paragraph * epar = send_cur.par()->next();
+
+ LyXLayout_ptr const & lyxlayout =
+ bv()->buffer()->params.getLyXTextClass()[layout];
- LyXLayout const & lyxlayout =
- textclasslist[bview->buffer()->params.textclass][layout];
-
do {
- cur.par()->applyLayout(layout);
- makeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
- Paragraph * fppar = cur.par();
- fppar->params().spaceTop(lyxlayout.fill_top ?
+ par->applyLayout(lyxlayout);
+ makeFontEntriesLayoutSpecific(*bv()->buffer(), *par);
+ Paragraph * fppar = par;
+ fppar->params().spaceTop(lyxlayout->fill_top ?
VSpace(VSpace::VFILL)
: VSpace(VSpace::NONE));
- fppar->params().spaceBottom(lyxlayout.fill_bottom ?
+ fppar->params().spaceBottom(lyxlayout->fill_bottom ?
VSpace(VSpace::VFILL)
: VSpace(VSpace::NONE));
- if (lyxlayout.margintype == MARGIN_MANUAL)
- cur.par()->setLabelWidthString(lyxlayout.labelstring());
- if (lyxlayout.labeltype != LABEL_BIBLIO
- && fppar->bibkey) {
- delete fppar->bibkey;
- fppar->bibkey = 0;
- }
- if (cur.par() != send_cur.par())
- cur.par(cur.par()->next());
- } while (cur.par() != send_cur.par());
-
+ if (lyxlayout->margintype == MARGIN_MANUAL)
+ par->setLabelWidthString(lyxlayout->labelstring());
+ cur.par(par);
+ par = par->next();
+ } while (par != epar);
+
return endpar;
}
// set layout over selection and make a total rebreak of those paragraphs
-void LyXText::setLayout(BufferView * bview, string const & layout)
+void LyXText::setLayout(string const & layout)
{
LyXCursor tmpcursor = cursor; /* store the current cursor */
selection.start = cursor; // dummy selection
selection.end = cursor;
}
- Paragraph * endpar = setLayout(bview, cursor, selection.start,
+ Paragraph * endpar = setLayout(cursor, selection.start,
selection.end, layout);
- redoParagraphs(bview, selection.start, endpar);
-
+ redoParagraphs(selection.start, endpar);
+
// we have to reset the selection, because the
// geometry could have changed
- setCursor(bview, selection.start.par(),
+ setCursor(selection.start.par(),
selection.start.pos(), false);
selection.cursor = cursor;
- setCursor(bview, selection.end.par(), selection.end.pos(), false);
- updateCounters(bview, cursor.row());
+ setCursor(selection.end.par(), selection.end.pos(), false);
+ updateCounters();
clearSelection();
- setSelection(bview);
- setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
+ setSelection();
+ setCursor(tmpcursor.par(), tmpcursor.pos(), true);
}
// increment depth over selection and
// make a total rebreak of those paragraphs
-void LyXText::incDepth(BufferView * bview)
+void LyXText::incDepth()
{
// If there is no selection, just use the current paragraph
if (!selection.set()) {
} else if (endpar) {
endpar = endpar->next(); // because of parindents etc.
}
-
- setUndo(bview, Undo::EDIT,
+
+ setUndo(bv(), Undo::EDIT,
selection.start.par(), undoendpar);
LyXCursor tmpcursor = cursor; // store the current cursor
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
cursor = selection.start;
-
- bool anything_changed = false;
-
- LyXTextClass const & tclass =
- textclasslist[bview->buffer()->params.textclass];
-
+
while (true) {
// NOTE: you can't change the depth of a bibliography entry
- if (tclass[cursor.par()->layout()].labeltype != LABEL_BIBLIO) {
+ if (cursor.par()->layout()->labeltype != LABEL_BIBLIO) {
Paragraph * prev = cursor.par()->previous();
if (prev) {
if (cursor.par()->getDepth()
- < prev->getMaxDepthAfter(bview->buffer())){
+ < prev->getMaxDepthAfter()) {
cursor.par()->params().depth(cursor.par()->getDepth() + 1);
- anything_changed = true;
}
}
}
break;
cursor.par(cursor.par()->next());
}
-
- // if nothing changed set all depth to 0
- if (!anything_changed) {
- cursor = selection.start;
- while (cursor.par() != selection.end.par()) {
- cursor.par()->params().depth(0);
- cursor.par(cursor.par()->next());
- }
- cursor.par()->params().depth(0);
- }
-
- redoParagraphs(bview, selection.start, endpar);
-
+
+ redoParagraphs(selection.start, endpar);
+
// we have to reset the selection, because the
// geometry could have changed
- setCursor(bview, selection.start.par(), selection.start.pos());
+ setCursor(selection.start.par(), selection.start.pos());
selection.cursor = cursor;
- setCursor(bview, selection.end.par(), selection.end.pos());
- updateCounters(bview, cursor.row());
+ setCursor(selection.end.par(), selection.end.pos());
+ updateCounters();
clearSelection();
- setSelection(bview);
- setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+ setSelection();
+ setCursor(tmpcursor.par(), tmpcursor.pos());
}
// decrement depth over selection and
// make a total rebreak of those paragraphs
-void LyXText::decDepth(BufferView * bview)
+void LyXText::decDepth()
{
// if there is no selection just set the layout
// of the current paragraph
} else if (endpar) {
endpar = endpar->next(); // because of parindents etc.
}
-
- setUndo(bview, Undo::EDIT,
+
+ setUndo(bv(), Undo::EDIT,
selection.start.par(), undoendpar);
LyXCursor tmpcursor = cursor; // store the current cursor
cursor.par(cursor.par()->next());
}
- redoParagraphs(bview, selection.start, endpar);
-
+ redoParagraphs(selection.start, endpar);
+
// we have to reset the selection, because the
// geometry could have changed
- setCursor(bview, selection.start.par(),
+ setCursor(selection.start.par(),
selection.start.pos());
selection.cursor = cursor;
- setCursor(bview, selection.end.par(), selection.end.pos());
- updateCounters(bview, cursor.row());
+ setCursor(selection.end.par(), selection.end.pos());
+ updateCounters();
clearSelection();
- setSelection(bview);
- setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+ setSelection();
+ setCursor(tmpcursor.par(), tmpcursor.pos());
}
// set font over selection and make a total rebreak of those paragraphs
-void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
+void LyXText::setFont(LyXFont const & font, bool toggleall)
{
// if there is no selection just set the current_font
if (!selection.set()) {
// Determine basis font
LyXFont layoutfont;
- if (cursor.pos() < beginningOfMainBody(bview->buffer(),
- cursor.par())) {
- layoutfont = getLabelFont(bview->buffer(),
+ if (cursor.pos() < cursor.par()->beginningOfBody()) {
+ layoutfont = getLabelFont(bv()->buffer(),
cursor.par());
} else {
- layoutfont = getLayoutFont(bview->buffer(),
+ layoutfont = getLayoutFont(bv()->buffer(),
cursor.par());
}
// Update current font
- real_current_font.update(font,
- bview->buffer()->params.language,
+ real_current_font.update(font,
+ bv()->buffer()->params.language,
toggleall);
// Reduce to implicit settings
current_font = real_current_font;
current_font.reduce(layoutfont);
// And resolve it completely
-#ifndef INHERIT_LANGUAGE
real_current_font.realize(layoutfont);
-#else
- real_current_font.realize(layoutfont,
- bview->buffer()->params.language);
-#endif
+
return;
}
LyXCursor tmpcursor = cursor; // store the current cursor
-
+
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
-
- setUndo(bview, Undo::EDIT,
- selection.start.par(), selection.end.par()->next());
+
+ setUndo(bv(), Undo::EDIT,
+ selection.start.par(), selection.end.par()->next());
freezeUndo();
cursor = selection.start;
while (cursor.par() != selection.end.par() ||
- (cursor.pos() < selection.end.pos()))
+ cursor.pos() < selection.end.pos())
{
if (cursor.pos() < cursor.par()->size()) {
- // an open footnote should behave
- // like a closed one
- setCharFont(bview, cursor.par(), cursor.pos(),
+ // an open footnote should behave like a closed one
+ setCharFont(cursor.par(), cursor.pos(),
font, toggleall);
cursor.pos(cursor.pos() + 1);
} else {
}
}
unFreezeUndo();
-
- redoParagraphs(bview, selection.start, selection.end.par()->next());
-
+
+ redoParagraphs(selection.start, selection.end.par()->next());
+
// we have to reset the selection, because the
// geometry could have changed, but we keep
// it for user convenience
- setCursor(bview, selection.start.par(), selection.start.pos());
+ setCursor(selection.start.par(), selection.start.pos());
selection.cursor = cursor;
- setCursor(bview, selection.end.par(), selection.end.pos());
- setSelection(bview);
- setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
- tmpcursor.boundary());
+ setCursor(selection.end.par(), selection.end.pos());
+ setSelection();
+ setCursor(tmpcursor.par(), tmpcursor.pos(), true,
+ tmpcursor.boundary());
}
-void LyXText::redoHeightOfParagraph(BufferView * bview, LyXCursor const & cur)
+void LyXText::redoHeightOfParagraph()
{
- Row * tmprow = cur.row();
- int y = cur.y() - tmprow->baseline();
+ Row * tmprow = cursor.row();
+ int y = cursor.y() - tmprow->baseline();
+
+ setHeightOfRow(tmprow);
- setHeightOfRow(bview, tmprow);
-
while (tmprow->previous()
&& tmprow->previous()->par() == tmprow->par()) {
tmprow = tmprow->previous();
y -= tmprow->height();
- setHeightOfRow(bview, tmprow);
+ setHeightOfRow(tmprow);
}
-
- // we can set the refreshing parameters now
- status(bview, LyXText::NEED_MORE_REFRESH);
- refresh_y = y;
- refresh_row = tmprow;
- setCursor(bview, cur.par(), cur.pos(), false, cursor.boundary());
+
+ postPaint(y);
+
+ setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
}
-void LyXText::redoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
+void LyXText::redoDrawingOfParagraph(LyXCursor const & cur)
{
Row * tmprow = cur.row();
-
+
int y = cur.y() - tmprow->baseline();
- setHeightOfRow(bview, tmprow);
+ setHeightOfRow(tmprow);
while (tmprow->previous()
&& tmprow->previous()->par() == tmprow->par()) {
y -= tmprow->height();
}
- // we can set the refreshing parameters now
- if (status_ == LyXText::UNCHANGED || y < refresh_y) {
- refresh_y = y;
- refresh_row = tmprow;
- }
- status(bview, LyXText::NEED_MORE_REFRESH);
- setCursor(bview, cur.par(), cur.pos());
+ postPaint(y);
+ setCursor(cur.par(), cur.pos());
}
// deletes and inserts again all paragaphs between the cursor
-// and the specified par
+// and the specified par
// This function is needed after SetLayout and SetFont etc.
-void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
- Paragraph const * endpar) const
+void LyXText::redoParagraphs(LyXCursor const & cur,
+ Paragraph const * endpar)
{
- Row * tmprow2;
- Paragraph * tmppar = 0;
- Paragraph * first_phys_par = 0;
-
Row * tmprow = cur.row();
-
+
int y = cur.y() - tmprow->baseline();
+ Paragraph * first_phys_par = 0;
if (!tmprow->previous()) {
// a trick/hack for UNDO
// This is needed because in an UNDO/REDO we could have changed
// the ownerParagrah() so the paragraph inside the row is NOT
// my really first par anymore. Got it Lars ;) (Jug 20011206)
first_phys_par = ownerParagraph();
+ lyxerr << "ownerParagraph" << endl;
+
} else {
first_phys_par = tmprow->par();
+ lyxerr << "tmprow->par()" << endl;
+
+ // Find first row of this paragraph.
while (tmprow->previous()
&& tmprow->previous()->par() == first_phys_par)
{
}
}
- // we can set the refreshing parameters now
- status(bview, LyXText::NEED_MORE_REFRESH);
- refresh_y = y;
- refresh_row = tmprow->previous(); /* the real refresh row will
- be deleted, so I store
- the previous here */
- // remove it
+ Row * prevrow = tmprow->previous();
+
+ // Remove all the rows until we reach endpar
+ Paragraph * tmppar = 0;
if (tmprow->next())
tmppar = tmprow->next()->par();
- else
- tmppar = 0;
while (tmprow->next() && tmppar != endpar) {
removeRow(tmprow->next());
if (tmprow->next()) {
tmppar = 0;
}
}
-
- // remove the first one
- tmprow2 = tmprow; /* this is because tmprow->previous()
- can be 0 */
+
+ // Remove the first of the paragraphs rows.
+ // This is because tmprow->previous() can be 0
+ Row * tmprow2 = tmprow;
tmprow = tmprow->previous();
removeRow(tmprow2);
-
- tmppar = first_phys_par;
+ // Reinsert the paragraphs.
+ tmppar = first_phys_par;
do {
if (tmppar) {
- insertParagraph(bview, tmppar, tmprow);
+ insertParagraph(tmppar, tmprow);
if (!tmprow) {
- tmprow = firstrow;
+ tmprow = firstRow();
}
while (tmprow->next()
&& tmprow->next()->par() == tmppar) {
tmppar = tmppar->next();
}
} while (tmppar && tmppar != endpar);
-
+
// this is because of layout changes
- if (refresh_row) {
- refresh_y -= refresh_row->height();
- setHeightOfRow(bview, refresh_row);
+ if (prevrow) {
+ setHeightOfRow(prevrow);
+ const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
} else {
- refresh_row = firstrow;
- refresh_y = 0;
- setHeightOfRow(bview, refresh_row);
+ setHeightOfRow(firstRow());
+ const_cast<LyXText *>(this)->postPaint(0);
}
-
+
if (tmprow && tmprow->next())
- setHeightOfRow(bview, tmprow->next());
+ setHeightOfRow(tmprow->next());
+ updateCounters();
}
-bool LyXText::fullRebreak(BufferView * bview)
+void LyXText::fullRebreak()
{
- if (!firstrow) {
- init(bview);
- return true;
+ if (!firstRow()) {
+ init(bv());
+ return;
}
if (need_break_row) {
- breakAgain(bview, need_break_row);
+ breakAgain(need_break_row);
need_break_row = 0;
- return true;
+ return;
}
- return false;
}
// important for the screen
-/* the cursor set functions have a special mechanism. When they
- * realize, that you left an empty paragraph, they will delete it.
- * They also delete the corresponding row */
-
+// the cursor set functions have a special mechanism. When they
+// realize, that you left an empty paragraph, they will delete it.
+// They also delete the corresponding row
+
// need the selection cursor:
-void LyXText::setSelection(BufferView * bview)
+void LyXText::setSelection()
{
bool const lsel = selection.set();
selection.start = selection.cursor;
selection.end = selection.cursor;
}
-
+
selection.set(true);
-
+
// first the toggling area
if (cursor.y() < last_sel_cursor.y()
|| (cursor.y() == last_sel_cursor.y()
toggle_end_cursor = cursor;
toggle_cursor = last_sel_cursor;
}
-
+
last_sel_cursor = cursor;
-
+
// and now the whole selection
if (selection.cursor.par() == cursor.par())
selection.end = cursor;
selection.start = selection.cursor;
} else {
- selection.end = selection.cursor;
+ selection.end = selection.cursor;
selection.start = cursor;
}
else if (selection.cursor.y() < cursor.y() ||
selection.start = selection.cursor;
}
else {
- selection.end = selection.cursor;
+ selection.end = selection.cursor;
selection.start = cursor;
}
-
+
// a selection with no contents is not a selection
- if (selection.start.par() == selection.end.par() &&
+ if (selection.start.par() == selection.end.par() &&
selection.start.pos() == selection.end.pos())
selection.set(false);
if (inset_owner && (selection.set() || lsel))
- inset_owner->setUpdateStatus(bview, InsetText::SELECTION);
+ inset_owner->setUpdateStatus(bv(), InsetText::SELECTION);
}
string const LyXText::selectionAsString(Buffer const * buffer,
- bool label) const
+ bool label) const
{
if (!selection.set()) return string();
- string result;
-
- // Special handling if the whole selection is within one paragraph
- if (selection.start.par() == selection.end.par()) {
- result += selection.start.par()->asString(buffer,
- selection.start.pos(),
- selection.end.pos(),
- label);
- return result;
+
+ // should be const ...
+ Paragraph * startpar(selection.start.par());
+ Paragraph * endpar(selection.end.par());
+ pos_type const startpos(selection.start.pos());
+ pos_type const endpos(selection.end.pos());
+
+ if (startpar == endpar) {
+ return startpar->asString(buffer, startpos, endpos, label);
}
-
- // The selection spans more than one paragraph
+
+ string result;
// First paragraph in selection
- result += selection.start.par()->asString(buffer,
- selection.start.pos(),
- selection.start.par()->size(),
- label)
- + "\n\n";
-
+ result += startpar->asString(buffer, startpos, startpar->size(), label) + "\n\n";
+
// The paragraphs in between (if any)
LyXCursor tmpcur(selection.start);
tmpcur.par(tmpcur.par()->next());
- while (tmpcur.par() != selection.end.par()) {
+ while (tmpcur.par() != endpar) {
result += tmpcur.par()->asString(buffer, 0,
tmpcur.par()->size(),
label) + "\n\n";
}
// Last paragraph in selection
- result += selection.end.par()->asString(buffer, 0,
- selection.end.pos(), label);
-
+ result += endpar->asString(buffer, 0, endpos, label);
+
return result;
}
-void LyXText::clearSelection() const
+void LyXText::clearSelection()
{
selection.set(false);
selection.mark(false);
last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
+ // reset this in the bv_owner!
+ if (bv_owner && bv_owner->text)
+ bv_owner->text->xsel_cache.set(false);
}
-void LyXText::cursorHome(BufferView * bview) const
+void LyXText::cursorHome()
{
- setCursor(bview, cursor.par(), cursor.row()->pos());
+ setCursor(cursor.par(), cursor.row()->pos());
}
-void LyXText::cursorEnd(BufferView * bview) const
+void LyXText::cursorEnd()
{
if (!cursor.row()->next()
|| cursor.row()->next()->par() != cursor.row()->par()) {
- setCursor(bview, cursor.par(), rowLast(cursor.row()) + 1);
+ setCursor(cursor.par(), cursor.row()->lastPos() + 1);
} else {
- if (cursor.par()->size() &&
- (cursor.par()->getChar(rowLast(cursor.row())) == ' '
- || cursor.par()->isNewline(rowLast(cursor.row())))) {
- setCursor(bview, cursor.par(), rowLast(cursor.row()));
+ if (!cursor.par()->empty() &&
+ (cursor.par()->getChar(cursor.row()->lastPos()) == ' '
+ || cursor.par()->isNewline(cursor.row()->lastPos()))) {
+ setCursor(cursor.par(), cursor.row()->lastPos());
} else {
- setCursor(bview,cursor.par(),
- rowLast(cursor.row()) + 1);
+ setCursor(cursor.par(),
+ cursor.row()->lastPos() + 1);
}
}
}
-void LyXText::cursorTop(BufferView * bview) const
+void LyXText::cursorTop()
{
while (cursor.par()->previous())
cursor.par(cursor.par()->previous());
- setCursor(bview, cursor.par(), 0);
+ setCursor(cursor.par(), 0);
}
-void LyXText::cursorBottom(BufferView * bview) const
+void LyXText::cursorBottom()
{
while (cursor.par()->next())
cursor.par(cursor.par()->next());
- setCursor(bview, cursor.par(), cursor.par()->size());
+ setCursor(cursor.par(), cursor.par()->size());
}
-
-
-void LyXText::toggleFree(BufferView * bview,
- LyXFont const & font, bool toggleall)
+
+
+void LyXText::toggleFree(LyXFont const & font, bool toggleall)
{
// If the mask is completely neutral, tell user
if (font == LyXFont(LyXFont::ALL_IGNORE)) {
// Could only happen with user style
- bview->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
+ bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
return;
}
// Try implicit word selection
- // If there is a change in the language the implicit word selection
+ // If there is a change in the language the implicit word selection
// is disabled.
LyXCursor resetCursor = cursor;
bool implicitSelection = (font.language() == ignore_language
- && font.number() == LyXFont::IGNORE)
- ? selectWordWhenUnderCursor(bview, WHOLE_WORD_STRICT) : false;
+ && font.number() == LyXFont::IGNORE)
+ ? selectWordWhenUnderCursor(WHOLE_WORD_STRICT) : false;
// Set font
- setFont(bview, font, toggleall);
+ setFont(font, toggleall);
// Implicit selections are cleared afterwards
//and cursor is set to the original position.
if (implicitSelection) {
clearSelection();
cursor = resetCursor;
- setCursor(bview, cursor.par(), cursor.pos());
+ setCursor(cursor.par(), cursor.pos());
selection.cursor = cursor;
}
if (inset_owner)
- inset_owner->setUpdateStatus(bview, InsetText::CURSOR_PAR);
+ inset_owner->setUpdateStatus(bv(), InsetText::CURSOR_PAR);
}
-string LyXText::getStringToIndex(BufferView * bview)
+string LyXText::getStringToIndex()
{
- string idxstring;
-
// Try implicit word selection
- // If there is a change in the language the implicit word selection
+ // If there is a change in the language the implicit word selection
// is disabled.
- LyXCursor resetCursor = cursor;
- bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
+ LyXCursor const reset_cursor = cursor;
+ bool const implicitSelection = selectWordWhenUnderCursor(PREVIOUS_WORD);
- if (!selection.set()) {
- bview->owner()->message(_("Nothing to index!"));
- return string();
- }
- if (selection.start.par() != selection.end.par()) {
- bview->owner()->message(_("Cannot index more than one paragraph!"));
- return string();
- }
+ string idxstring;
+ if (!selection.set())
+ bv()->owner()->message(_("Nothing to index!"));
+ else if (selection.start.par() != selection.end.par())
+ bv()->owner()->message(_("Cannot index more than one paragraph!"));
+ else
+ idxstring = selectionAsString(bv()->buffer(), false);
- idxstring = selectionAsString(bview->buffer(), false);
-
- // Implicit selections are cleared afterwards
- //and cursor is set to the original position.
- if (implicitSelection) {
- clearSelection();
- cursor = resetCursor;
- setCursor(bview, cursor.par(), cursor.pos());
- selection.cursor = cursor;
- }
- return idxstring;
-}
+ // Reset cursors to their original position.
+ cursor = reset_cursor;
+ setCursor(cursor.par(), cursor.pos());
+ selection.cursor = cursor;
+ // Clear the implicit selection.
+ if (implicitSelection)
+ clearSelection();
-pos_type LyXText::beginningOfMainBody(Buffer const * buf,
- Paragraph const * par) const
-{
- if (textclasslist[buf->params.textclass][
- par->layout()].labeltype != LABEL_MANUAL)
- return 0;
- else
- return par->beginningOfMainBody();
+ return idxstring;
}
-/* the DTP switches for paragraphs. LyX will store them in the
-* first physicla paragraph. When a paragraph is broken, the top settings
-* rest, the bottom settings are given to the new one. So I can make shure,
-* they do not duplicate themself and you cannnot make dirty things with
-* them! */
+// the DTP switches for paragraphs. LyX will store them in the first
+// physicla paragraph. When a paragraph is broken, the top settings rest,
+// the bottom settings are given to the new one. So I can make shure,
+// they do not duplicate themself and you cannnot make dirty things with
+// them!
-void LyXText::setParagraph(BufferView * bview,
- bool line_top, bool line_bottom,
+void LyXText::setParagraph(bool line_top, bool line_bottom,
bool pagebreak_top, bool pagebreak_bottom,
VSpace const & space_top,
VSpace const & space_bottom,
Spacing const & spacing,
- LyXAlignment align,
- string labelwidthstring,
- bool noindent)
+ LyXAlignment align,
+ string const & labelwidthstring,
+ bool noindent)
{
LyXCursor tmpcursor = cursor;
if (!selection.set()) {
// because of parindents etc.
endpar = endpar->next();
}
-
- setUndo(bview, Undo::EDIT, selection.start.par(), undoendpar);
-
+ setUndo(bv(), Undo::EDIT, selection.start.par(), undoendpar);
+
+
Paragraph * tmppar = selection.end.par();
- LyXTextClass const & tclass =
- textclasslist[bview->buffer()->params.textclass];
-
+
while (tmppar != selection.start.par()->previous()) {
- setCursor(bview, tmppar, 0);
- status(bview, LyXText::NEED_MORE_REFRESH);
- refresh_row = cursor.row();
- refresh_y = cursor.y() - cursor.row()->baseline();
+ setCursor(tmppar, 0);
+ postPaint(cursor.y() - cursor.row()->baseline());
cursor.par()->params().lineTop(line_top);
cursor.par()->params().lineBottom(line_bottom);
cursor.par()->params().pagebreakTop(pagebreak_top);
cursor.par()->params().pagebreakBottom(pagebreak_bottom);
cursor.par()->params().spaceTop(space_top);
cursor.par()->params().spaceBottom(space_bottom);
- cursor.par()->params().spacing(spacing);
+ cursor.par()->params().spacing(spacing);
// does the layout allow the new alignment?
- LyXLayout const & layout = tclass[cursor.par()->layout()];
-
+ LyXLayout_ptr const & layout = cursor.par()->layout();
+
if (align == LYX_ALIGN_LAYOUT)
- align = layout.align;
- if (align & layout.alignpossible) {
- if (align == layout.align)
+ align = layout->align;
+ if (align & layout->alignpossible) {
+ if (align == layout->align)
cursor.par()->params().align(LYX_ALIGN_LAYOUT);
else
cursor.par()->params().align(align);
cursor.par()->params().noindent(noindent);
tmppar = cursor.par()->previous();
}
-
- redoParagraphs(bview, selection.start, endpar);
-
+
+ redoParagraphs(selection.start, endpar);
+
clearSelection();
- setCursor(bview, selection.start.par(), selection.start.pos());
+ setCursor(selection.start.par(), selection.start.pos());
selection.cursor = cursor;
- setCursor(bview, selection.end.par(), selection.end.pos());
- setSelection(bview);
- setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+ setCursor(selection.end.par(), selection.end.pos());
+ setSelection();
+ setCursor(tmpcursor.par(), tmpcursor.pos());
if (inset_owner)
- bview->updateInset(inset_owner, true);
-}
-
-
-char loweralphaCounter(int n)
-{
- if (n < 1 || n > 26)
- return '?';
- else
- return 'a' + n - 1;
-}
-
-
-namespace {
-
-inline
-char alphaCounter(int n)
-{
- if (n < 1 || n > 26)
- return '?';
- else
- return 'A' + n - 1;
+ bv()->updateInset(inset_owner);
}
-inline
-char hebrewCounter(int n)
-{
- static const char hebrew[22] = {
- 'à ', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è',
- 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö',
- '÷', 'ø', 'ù', 'ú'
- };
- if (n < 1 || n > 22)
- return '?';
- else
- return hebrew[n-1];
-}
-
-
-inline
-string const romanCounter(int n)
-{
- static char const * roman[20] = {
- "i", "ii", "iii", "iv", "v",
- "vi", "vii", "viii", "ix", "x",
- "xi", "xii", "xiii", "xiv", "xv",
- "xvi", "xvii", "xviii", "xix", "xx"
- };
- if (n < 1 || n > 20)
- return "??";
- else
- return roman[n-1];
-}
-
-} // namespace anon
-
-
// set the counter of a paragraph. This includes the labels
-void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
+void LyXText::setCounter(Buffer const * buf, Paragraph * par)
{
- LyXTextClass const & textclass = textclasslist[buf->params.textclass];
- LyXLayout const & layout = textclass[par->layout()];
-
+ LyXTextClass const & textclass = buf->params.getLyXTextClass();
+ LyXLayout_ptr const & layout = par->layout();
- // copy the prev-counters to this one,
- // unless this is the first paragraph
if (par->previous()) {
- for (int i = 0; i < 10; ++i) {
- par->setCounter(i, par->previous()->getFirstCounter(i));
- }
+
par->params().appendix(par->previous()->params().appendix());
if (!par->params().appendix() && par->params().startOfAppendix()) {
par->params().appendix(true);
- for (int i = 0; i < 10; ++i) {
- par->setCounter(i, 0);
- }
+ textclass.counters().reset();
}
par->enumdepth = par->previous()->enumdepth;
par->itemdepth = par->previous()->itemdepth;
} else {
- for (int i = 0; i < 10; ++i) {
- par->setCounter(i, 0);
- }
par->params().appendix(par->params().startOfAppendix());
par->enumdepth = 0;
par->itemdepth = 0;
*/
if (par->previous()
&& par->previous()->getDepth() < par->getDepth()
- && textclass[par->previous()->layout()].labeltype == LABEL_COUNTER_ENUMI
+ && par->previous()->layout()->labeltype == LABEL_COUNTER_ENUMI
&& par->enumdepth < 3
- && layout.labeltype != LABEL_BIBLIO) {
+ && layout->labeltype != LABEL_BIBLIO) {
par->enumdepth++;
}
// Maybe we have to decrement the enumeration depth, see note above
if (par->previous()
&& par->previous()->getDepth() > par->getDepth()
- && layout.labeltype != LABEL_BIBLIO) {
+ && layout->labeltype != LABEL_BIBLIO) {
par->enumdepth = par->depthHook(par->getDepth())->enumdepth;
- par->setCounter(6 + par->enumdepth,
- par->depthHook(par->getDepth())->getCounter(6 + par->enumdepth));
- /* reset the counters.
- * A depth change is like a breaking layout
- */
- for (int i = 6 + par->enumdepth + 1; i < 10; ++i)
- par->setCounter(i, 0);
- }
-
+ }
+
if (!par->params().labelString().empty()) {
par->params().labelString(string());
}
-
- if (layout.margintype == MARGIN_MANUAL) {
+
+ if (layout->margintype == MARGIN_MANUAL) {
if (par->params().labelWidthString().empty()) {
- par->setLabelWidthString(layout.labelstring());
+ par->setLabelWidthString(layout->labelstring());
}
} else {
par->setLabelWidthString(string());
}
-
- // is it a layout that has an automatic label?
- if (layout.labeltype >= LABEL_COUNTER_CHAPTER) {
-
- int i = layout.labeltype - LABEL_COUNTER_CHAPTER;
- if (i >= 0 && i<= buf->params.secnumdepth) {
- par->incCounter(i); // increment the counter
-
- // Is there a label? Useful for Chapter layout
- if (!par->params().appendix()) {
- if (!layout.labelstring().empty())
- par->params().labelString(layout.labelstring());
- else
- par->params().labelString(string());
- } else {
- if (!layout.labelstring_appendix().empty())
- par->params().labelString(layout.labelstring_appendix());
- else
- par->params().labelString(string());
- }
-
- ostringstream s;
- if (!par->params().appendix()) {
- switch (2 * LABEL_COUNTER_CHAPTER -
- textclass.maxcounter() + i) {
- case LABEL_COUNTER_CHAPTER:
- s << par->getCounter(i);
- break;
- case LABEL_COUNTER_SECTION:
- s << par->getCounter(i - 1) << '.'
- << par->getCounter(i);
- break;
- case LABEL_COUNTER_SUBSECTION:
- s << par->getCounter(i - 2) << '.'
- << par->getCounter(i - 1) << '.'
- << par->getCounter(i);
- break;
- case LABEL_COUNTER_SUBSUBSECTION:
- s << par->getCounter(i - 3) << '.'
- << par->getCounter(i - 2) << '.'
- << par->getCounter(i - 1) << '.'
- << par->getCounter(i);
-
- break;
- case LABEL_COUNTER_PARAGRAPH:
- s << par->getCounter(i - 4) << '.'
- << par->getCounter(i - 3) << '.'
- << par->getCounter(i - 2) << '.'
- << par->getCounter(i - 1) << '.'
- << par->getCounter(i);
- break;
- case LABEL_COUNTER_SUBPARAGRAPH:
- s << par->getCounter(i - 5) << '.'
- << par->getCounter(i - 4) << '.'
- << par->getCounter(i - 3) << '.'
- << par->getCounter(i - 2) << '.'
- << par->getCounter(i - 1) << '.'
- << par->getCounter(i);
-
- break;
- default:
- // Can this ever be reached? And in the
- // case it is, how can this be correct?
- // (Lgb)
- s << par->getCounter(i) << '.';
- break;
- }
- } else { // appendix
- switch (2 * LABEL_COUNTER_CHAPTER - textclass.maxcounter() + i) {
- case LABEL_COUNTER_CHAPTER:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i));
- else
- s << alphaCounter(par->getCounter(i));
- break;
- case LABEL_COUNTER_SECTION:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i - 1));
- else
- s << alphaCounter(par->getCounter(i - 1));
-
- s << '.'
- << par->getCounter(i);
-
- break;
- case LABEL_COUNTER_SUBSECTION:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i - 2));
- else
- s << alphaCounter(par->getCounter(i - 2));
-
- s << '.'
- << par->getCounter(i-1) << '.'
- << par->getCounter(i);
-
- break;
- case LABEL_COUNTER_SUBSUBSECTION:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i-3));
- else
- s << alphaCounter(par->getCounter(i-3));
+ // is it a layout that has an automatic label?
+ if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
+ int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
- s << '.'
- << par->getCounter(i-2) << '.'
- << par->getCounter(i-1) << '.'
- << par->getCounter(i);
+ ostringstream s;
- break;
- case LABEL_COUNTER_PARAGRAPH:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i-4));
- else
- s << alphaCounter(par->getCounter(i-4));
-
- s << '.'
- << par->getCounter(i-3) << '.'
- << par->getCounter(i-2) << '.'
- << par->getCounter(i-1) << '.'
- << par->getCounter(i);
+ if (i >= 0 && i <= buf->params.secnumdepth) {
+ string numbertype;
+ string langtype;
- break;
- case LABEL_COUNTER_SUBPARAGRAPH:
- if (par->isRightToLeftPar(buf->params))
- s << hebrewCounter(par->getCounter(i-5));
- else
- s << alphaCounter(par->getCounter(i-5));
-
- s << '.'
- << par->getCounter(i-4) << '.'
- << par->getCounter(i-3) << '.'
- << par->getCounter(i-2) << '.'
- << par->getCounter(i-1) << '.'
- << par->getCounter(i);
+ textclass.counters().step(layout->latexname());
- break;
- default:
- // Can this ever be reached? And in the
- // case it is, how can this be correct?
- // (Lgb)
- s << par->getCounter(i) << '.';
-
- break;
- }
+ // Is there a label? Useful for Chapter layout
+ if (!par->params().appendix()) {
+ s << layout->labelstring();
+ } else {
+ s << layout->labelstring_appendix();
}
- par->params().labelString(par->params().labelString() +s.str().c_str());
- // We really want to remove the c_str as soon as
- // possible...
-
- for (i++; i < 10; ++i) {
- // reset the following counters
- par->setCounter(i, 0);
- }
- } else if (layout.labeltype < LABEL_COUNTER_ENUMI) {
- for (i++; i < 10; ++i) {
- // reset the following counters
- par->setCounter(i, 0);
+ // Use of an integer is here less than elegant. For now.
+ int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
+ if (!par->params().appendix()) {
+ numbertype = "sectioning";
+ } else {
+ numbertype = "appendix";
+ if (par->isRightToLeftPar(buf->params))
+ langtype = "hebrew";
+ else
+ langtype = "latin";
}
- } else if (layout.labeltype == LABEL_COUNTER_ENUMI) {
- par->incCounter(i + par->enumdepth);
- int number = par->getCounter(i + par->enumdepth);
- ostringstream s;
+ s << textclass.counters()
+ .numberLabel(layout->latexname(),
+ numbertype, langtype, head);
+
+ par->params().labelString(STRCONV(s.str()));
+
+ // reset enum counters
+ textclass.counters().reset("enum");
+ } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
+ textclass.counters().reset("enum");
+ } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
+ // FIXME
+ // Yes I know this is a really, really! bad solution
+ // (Lgb)
+ string enumcounter("enum");
switch (par->enumdepth) {
- case 1:
- if (par->isRightToLeftPar(buf->params))
- s << '('
- << hebrewCounter(number)
- << ')';
- else
- s << '('
- << loweralphaCounter(number)
- << ')';
- break;
case 2:
- if (par->isRightToLeftPar(buf->params))
- s << '.' << romanCounter(number);
- else
- s << romanCounter(number) << '.';
+ enumcounter += 'i';
+ case 1:
+ enumcounter += 'i';
+ case 0:
+ enumcounter += 'i';
break;
case 3:
- if (par->isRightToLeftPar(buf->params))
- s << '.'
- << alphaCounter(number);
- else
- s << alphaCounter(number)
- << '.';
+ enumcounter += "iv";
break;
default:
- if (par->isRightToLeftPar(buf->params))
- s << '.' << number;
- else
- s << number << '.';
+ // not a valid enumdepth...
break;
}
- par->params().labelString(s.str().c_str());
+ textclass.counters().step(enumcounter);
- for (i += par->enumdepth + 1; i < 10; ++i) {
- // reset the following counters
- par->setCounter(i, 0);
- }
-
- }
- } else if (layout.labeltype == LABEL_BIBLIO) {// ale970302
- int i = LABEL_COUNTER_ENUMI - LABEL_COUNTER_CHAPTER + par->enumdepth;
- par->incCounter(i);
- int number = par->getCounter(i);
- if (!par->bibkey) {
- InsetCommandParams p("bibitem" );
- par->bibkey = new InsetBibKey(p);
+ s << textclass.counters()
+ .numberLabel(enumcounter, "enumeration");
+ par->params().labelString(STRCONV(s.str()));
+ }
+ } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
+ textclass.counters().step("bibitem");
+ int number = textclass.counters().value("bibitem");
+ if (par->bibitem()) {
+ par->bibitem()->setCounter(number);
+ par->params().labelString(layout->labelstring());
}
- par->bibkey->setCounter(number);
- par->params().labelString(layout.labelstring());
-
// In biblio should't be following counters but...
} else {
- string s = layout.labelstring();
-
+ string s = layout->labelstring();
+
// the caption hack:
- if (layout.labeltype == LABEL_SENSITIVE) {
- bool isOK (par->inInset() && par->inInset()->owner() &&
- (par->inInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
-
+ if (layout->labeltype == LABEL_SENSITIVE) {
+ Paragraph * tmppar = par;
+ Inset * in = 0;
+ bool isOK = false;
+ while (tmppar && tmppar->inInset()
+ // the single '=' is intended below
+ && (in = tmppar->inInset()->owner())) {
+ if (in->lyxCode() == Inset::FLOAT_CODE ||
+ in->lyxCode() == Inset::WRAP_CODE) {
+ isOK = true;
+ break;
+ } else {
+ tmppar = in->parOwner();
+ }
+ }
+
if (isOK) {
- InsetFloat * tmp = static_cast<InsetFloat*>(par->inInset()->owner());
Floating const & fl
- = floatList.getType(tmp->type());
- // We should get the correct number here too.
- s = fl.name() + " #:";
+ = textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
+
+ textclass.counters().step(fl.type());
+
+ // Doesn't work... yet.
+#warning use boost.format
+#if USE_BOOST_FORMAT
+ s = boost::io::str(boost::format(_("%1$s #:")) % fl.name());
+ // s << boost::format(_("%1$s %1$d:")
+ // % fl.name()
+ // % buf->counters().value(fl.name());
+#else
+ ostringstream o;
+ //o << fl.name() << ' ' << buf->counters().value(fl.name()) << ":";
+ o << fl.name() << " #:";
+ s = STRCONV(o.str());
+#endif
} else {
- /* par->SetLayout(0);
- s = layout->labelstring; */
- s = (par->getParLanguage(buf->params)->lang() == "hebrew")
- ? " :úåòîùî øñç" : "Senseless: ";
+ // par->SetLayout(0);
+ // s = layout->labelstring;
+ s = _("Senseless: ");
}
}
par->params().labelString(s);
-
- /* reset the enumeration counter. They are always resetted
- * when there is any other layout between */
- for (int i = 6 + par->enumdepth; i < 10; ++i)
- par->setCounter(i, 0);
+
+ // reset the enumeration counter. They are always reset
+ // when there is any other layout between
+ // Just fall-through between the cases so that all
+ // enum counters deeper than enumdepth is also reset.
+ switch (par->enumdepth) {
+ case 0:
+ textclass.counters().reset("enumi");
+ case 1:
+ textclass.counters().reset("enumii");
+ case 2:
+ textclass.counters().reset("enumiii");
+ case 3:
+ textclass.counters().reset("enumiv");
+ }
}
}
-// Updates all counters BEHIND the row. Changed paragraphs
-// with a dynamic left margin will be rebroken.
-void LyXText::updateCounters(BufferView * bview, Row * row) const
+// Updates all counters. Paragraphs with changed label string will be rebroken
+void LyXText::updateCounters()
{
- Paragraph * par;
+ Row * row = firstRow();
+ Paragraph * par = row->par();
- if (!row) {
- row = firstrow;
- par = row->par();
- } else {
- par = row->par()->next();
- }
+ // CHECK if this is really needed. (Lgb)
+ bv()->buffer()->params.getLyXTextClass().counters().reset();
while (par) {
while (row->par() != par)
row = row->next();
-
- setCounter(bview->buffer(), par);
-
- // now check for the headline layouts. remember that they
- // have a dynamic left margin
- LyXTextClass const & tclass =
- textclasslist[bview->buffer()->params.textclass];
- LyXLayout const & layout = tclass[par->layout()];
-
- if (layout.margintype == MARGIN_DYNAMIC
- || layout.labeltype == LABEL_SENSITIVE) {
- // Rebreak the paragraph
+
+ string const oldLabel = par->params().labelString();
+
+ // setCounter can potentially change the labelString.
+ setCounter(bv()->buffer(), par);
+
+ string const & newLabel = par->params().labelString();
+
+ if (oldLabel.empty() && !newLabel.empty()) {
removeParagraph(row);
- appendParagraph(bview, row);
+ appendParagraph(row);
}
+
par = par->next();
}
}
-void LyXText::insertInset(BufferView * bview, Inset * inset)
+void LyXText::insertInset(Inset * inset)
{
if (!cursor.par()->insetAllowed(inset->lyxCode()))
return;
- // I don't know if this is necessary here (Jug 20020102)
- setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
+ setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next());
+ freezeUndo();
cursor.par()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly.
// The character will not be inserted a second time
- insertChar(bview, Paragraph::META_INSET);
-#if 1
+ insertChar(Paragraph::META_INSET);
// If we enter a highly editable inset the cursor should be to before
// the inset. This couldn't happen before as Undo was not handled inside
// inset now after the Undo LyX tries to call inset->Edit(...) again
// and cannot do this as the cursor is behind the inset and GetInset
// does not return the inset!
if (isHighlyEditableInset(inset)) {
- cursorLeft(bview, true);
+ cursorLeft(true);
}
-#endif
+ unFreezeUndo();
}
void LyXText::copyEnvironmentType()
{
- copylayouttype = cursor.par()->layout();
+ copylayouttype = cursor.par()->layout()->name();
}
-void LyXText::pasteEnvironmentType(BufferView * bview)
+void LyXText::pasteEnvironmentType()
{
- setLayout(bview, copylayouttype);
+ // do nothing if there has been no previous copyEnvironmentType()
+ if (!copylayouttype.empty())
+ setLayout(copylayouttype);
}
-void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
+void LyXText::cutSelection(bool doclear, bool realcut)
{
// Stuff what we got on the clipboard. Even if there is no selection.
// finished. The solution used currently just works, to make it
// faster we need to be more clever and probably also have more
// calls to stuffClipboard. (Lgb)
- bview->stuffClipboard(selectionAsString(bview->buffer(), true));
+ bv()->stuffClipboard(selectionAsString(bv()->buffer(), true));
// This doesn't make sense, if there is no selection
if (!selection.set())
return;
-
+
// OK, we have a selection. This is always between selection.start
// and selection.end
// make sure that the depth behind the selection are restored, too
Paragraph * endpar = selection.end.par()->next();
Paragraph * undoendpar = endpar;
-
+
if (endpar && endpar->getDepth()) {
while (endpar && endpar->getDepth()) {
endpar = endpar->next();
} else if (endpar) {
endpar = endpar->next(); // because of parindents etc.
}
-
- setUndo(bview, Undo::DELETE,
+
+ setUndo(bv(), Undo::DELETE,
selection.start.par(), undoendpar);
-
+
// there are two cases: cut only within one paragraph or
// more than one paragraph
if (selection.start.par() == selection.end.par()) {
endpar = selection.end.par();
int pos = selection.end.pos();
CutAndPaste::cutSelection(selection.start.par(), &endpar,
- selection.start.pos(), pos,
- bview->buffer()->params.textclass,
+ selection.start.pos(), pos,
+ bv()->buffer()->params.textclass,
doclear, realcut);
selection.end.pos(pos);
} else {
endpar = selection.end.par();
int pos = selection.end.pos();
CutAndPaste::cutSelection(selection.start.par(), &endpar,
- selection.start.pos(), pos,
- bview->buffer()->params.textclass,
+ selection.start.pos(), pos,
+ bv()->buffer()->params.textclass,
doclear, realcut);
cursor.par(endpar);
selection.end.par(endpar);
// sometimes necessary
if (doclear)
- selection.start.par()->stripLeadingSpaces(bview->buffer()->params.textclass);
+ selection.start.par()->stripLeadingSpaces();
- redoParagraphs(bview, selection.start, endpar);
+ redoParagraphs(selection.start, endpar);
// cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb)
- cursor = selection.start;
+ // we prefer the end for when tracking changes
+ cursor = selection.end;
// need a valid cursor. (Lgb)
clearSelection();
- setCursor(bview, cursor.par(), cursor.pos());
+ setCursor(cursor.par(), cursor.pos());
selection.cursor = cursor;
- updateCounters(bview, cursor.row());
+ updateCounters();
}
-void LyXText::copySelection(BufferView * bview)
+void LyXText::copySelection()
{
// stuff the selection onto the X clipboard, from an explicit copy request
- bview->stuffClipboard(selectionAsString(bview->buffer(), true));
+ bv()->stuffClipboard(selectionAsString(bv()->buffer(), true));
// this doesnt make sense, if there is no selection
if (!selection.set())
&& selection.start.par()->isLineSeparator(selection.start.pos())
&& (selection.start.par() != selection.end.par()
|| selection.start.pos() < selection.end.pos()))
- selection.start.pos(selection.start.pos() + 1);
+ selection.start.pos(selection.start.pos() + 1);
CutAndPaste::copySelection(selection.start.par(), selection.end.par(),
- selection.start.pos(), selection.end.pos(),
- bview->buffer()->params.textclass);
+ selection.start.pos(), selection.end.pos(),
+ bv()->buffer()->params.textclass);
}
-void LyXText::pasteSelection(BufferView * bview)
+void LyXText::pasteSelection()
{
// this does not make sense, if there is nothing to paste
- if (!CutAndPaste::checkPastePossible(cursor.par()))
+ if (!CutAndPaste::checkPastePossible())
return;
- setUndo(bview, Undo::INSERT,
- cursor.par(), cursor.par()->next());
+ setUndo(bv(), Undo::INSERT,
+ cursor.par(), cursor.par()->next());
Paragraph * endpar;
Paragraph * actpar = cursor.par();
int pos = cursor.pos();
CutAndPaste::pasteSelection(&actpar, &endpar, pos,
- bview->buffer()->params.textclass);
-
- redoParagraphs(bview, cursor, endpar);
-
- setCursor(bview, cursor.par(), cursor.pos());
+ bv()->buffer()->params.textclass);
+
+ redoParagraphs(cursor, endpar);
+
+ setCursor(cursor.par(), cursor.pos());
clearSelection();
-
- setCursor(bview, actpar, pos);
- updateCounters(bview, cursor.row());
+
+ selection.cursor = cursor;
+ setCursor(actpar, pos);
+ setSelection();
+ updateCounters();
}
-// sets the selection over the number of characters of string, no check!!
-void LyXText::setSelectionOverString(BufferView * bview, string const & str)
+void LyXText::setSelectionRange(lyx::pos_type length)
{
- if (str.empty())
+ if (!length)
return;
-
+
selection.cursor = cursor;
- for (string::size_type i = 0; i < str.length(); ++i)
- cursorRight(bview);
- setSelection(bview);
+ while (length--)
+ cursorRight(bv());
+ setSelection();
}
// simple replacing. The font of the first selected character is used
-void LyXText::replaceSelectionWithString(BufferView * bview,
- string const & str)
+void LyXText::replaceSelectionWithString(string const & str)
{
- setCursorParUndo(bview);
+ setCursorParUndo(bv());
freezeUndo();
if (!selection.set()) { // create a dummy selection
// Get font setting before we cut
pos_type pos = selection.end.pos();
LyXFont const font = selection.start.par()
- ->getFontSettings(bview->buffer()->params,
+ ->getFontSettings(bv()->buffer()->params,
selection.start.pos());
// Insert the new string
selection.end.par()->insertChar(pos, (*cit), font);
++pos;
}
-
+
// Cut the selection
- cutSelection(bview, true, false);
+ cutSelection(true, false);
unFreezeUndo();
}
// needed to insert the selection
-void LyXText::insertStringAsLines(BufferView * bview, string const & str)
+void LyXText::insertStringAsLines(string const & str)
{
Paragraph * par = cursor.par();
pos_type pos = cursor.pos();
Paragraph * endpar = cursor.par()->next();
-
- setCursorParUndo(bview);
-
+
+ setCursorParUndo(bv());
+
// only to be sure, should not be neccessary
clearSelection();
-
- bview->buffer()->insertStringAsLines(par, pos, current_font, str);
- redoParagraphs(bview, cursor, endpar);
- setCursor(bview, cursor.par(), cursor.pos());
+ bv()->buffer()->insertStringAsLines(par, pos, current_font, str);
+
+ redoParagraphs(cursor, endpar);
+ setCursor(cursor.par(), cursor.pos());
selection.cursor = cursor;
- setCursor(bview, par, pos);
- setSelection(bview);
+ setCursor(par, pos);
+ setSelection();
}
// turns double-CR to single CR, others where converted into one
// blank. Then InsertStringAsLines is called
-void LyXText::insertStringAsParagraphs(BufferView * bview, string const & str)
+void LyXText::insertStringAsParagraphs(string const & str)
{
string linestr(str);
bool newline_inserted = false;
} else {
linestr[i] = ' ';
newline_inserted = true;
- }
+ }
} else if (IsPrintable(linestr[i])) {
newline_inserted = false;
}
}
- insertStringAsLines(bview, linestr);
+ insertStringAsLines(linestr);
}
-bool LyXText::gotoNextInset(BufferView * bview,
- vector<Inset::Code> const & codes,
- string const & contents) const
+void LyXText::checkParagraph(Paragraph * par,
+ pos_type pos)
{
- LyXCursor res = cursor;
- Inset * inset;
- do {
- if (res.pos() < res.par()->size() - 1) {
- res.pos(res.pos() + 1);
- } else {
- res.par(res.par()->next());
- res.pos(0);
- }
-
- } while (res.par() &&
- !(res.par()->isInset(res.pos())
- && (inset = res.par()->getInset(res.pos())) != 0
- && find(codes.begin(), codes.end(), inset->lyxCode())
- != codes.end()
- && (contents.empty() ||
- static_cast<InsetCommand *>(res.par()->getInset(res.pos()))->getContents()
- == contents)));
-
- if (res.par()) {
- setCursor(bview, res.par(), res.pos(), false);
- return true;
- }
- return false;
-}
-
-
-void LyXText::checkParagraph(BufferView * bview, Paragraph * par,
- pos_type pos)
-{
- LyXCursor tmpcursor;
+ LyXCursor tmpcursor;
int y = 0;
pos_type z;
Row * row = getRow(par, pos, y);
-
+
// is there a break one row above
if (row->previous() && row->previous()->par() == row->par()) {
- z = nextBreakPoint(bview, row->previous(), workWidth(bview));
+ z = rowBreakPoint(*row->previous());
if (z >= row->pos()) {
// set the dimensions of the row above
y -= row->previous()->height();
- refresh_y = y;
- refresh_row = row->previous();
- status(bview, LyXText::NEED_MORE_REFRESH);
-
- breakAgain(bview, row->previous());
-
+ postPaint(y);
+
+ breakAgain(row->previous());
+
// set the cursor again. Otherwise
// dangling pointers are possible
- setCursor(bview, cursor.par(), cursor.pos(),
+ setCursor(cursor.par(), cursor.pos(),
false, cursor.boundary());
selection.cursor = cursor;
return;
}
int const tmpheight = row->height();
- pos_type const tmplast = rowLast(row);
- refresh_y = y;
- refresh_row = row;
-
- breakAgain(bview, row);
- if (row->height() == tmpheight && rowLast(row) == tmplast)
- status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
- else
- status(bview, LyXText::NEED_MORE_REFRESH);
-
+ pos_type const tmplast = row->lastPos();
+
+ breakAgain(row);
+ if (row->height() == tmpheight && row->lastPos() == tmplast) {
+ postRowPaint(row, y);
+ } else {
+ postPaint(y);
+ }
+
// check the special right address boxes
- if (textclasslist[bview->buffer()->params.textclass][
- par->layout()].margintype
- == MARGIN_RIGHT_ADDRESS_BOX)
- {
+ if (par->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
tmpcursor.par(par);
tmpcursor.row(row);
tmpcursor.y(y);
tmpcursor.x(0);
tmpcursor.x_fix(0);
tmpcursor.pos(pos);
- redoDrawingOfParagraph(bview, tmpcursor);
+ redoDrawingOfParagraph(tmpcursor);
}
// set the cursor again. Otherwise dangling pointers are possible
// also set the selection
-
+
if (selection.set()) {
tmpcursor = cursor;
- setCursorIntern(bview, selection.cursor.par(), selection.cursor.pos(),
+ setCursorIntern(selection.cursor.par(), selection.cursor.pos(),
false, selection.cursor.boundary());
- selection.cursor = cursor;
- setCursorIntern(bview, selection.start.par(),
+ selection.cursor = cursor;
+ setCursorIntern(selection.start.par(),
selection.start.pos(),
false, selection.start.boundary());
- selection.start = cursor;
- setCursorIntern(bview, selection.end.par(),
+ selection.start = cursor;
+ setCursorIntern(selection.end.par(),
selection.end.pos(),
false, selection.end.boundary());
- selection.end = cursor;
- setCursorIntern(bview, last_sel_cursor.par(),
+ selection.end = cursor;
+ setCursorIntern(last_sel_cursor.par(),
last_sel_cursor.pos(),
false, last_sel_cursor.boundary());
- last_sel_cursor = cursor;
+ last_sel_cursor = cursor;
cursor = tmpcursor;
}
- setCursorIntern(bview, cursor.par(), cursor.pos(),
+ setCursorIntern(cursor.par(), cursor.pos(),
false, cursor.boundary());
}
// returns false if inset wasn't found
-bool LyXText::updateInset(BufferView * bview, Inset * inset)
+bool LyXText::updateInset(Inset * inset)
{
// first check the current paragraph
int pos = cursor.par()->getPositionOfInset(inset);
if (pos != -1) {
- checkParagraph(bview, cursor.par(), pos);
+ checkParagraph(cursor.par(), pos);
return true;
}
-
+
// check every paragraph
-
+
Paragraph * par = ownerParagraph();
do {
pos = par->getPositionOfInset(inset);
if (pos != -1) {
- checkParagraph(bview, par, pos);
+ checkParagraph(par, pos);
return true;
}
par = par->next();
} while (par);
-
+
return false;
}
-bool LyXText::setCursor(BufferView * bview, Paragraph * par,
- pos_type pos,
- bool setfont, bool boundary) const
+bool LyXText::setCursor(Paragraph * par,
+ pos_type pos,
+ bool setfont, bool boundary)
{
LyXCursor old_cursor = cursor;
- setCursorIntern(bview, par, pos, setfont, boundary);
- return deleteEmptyParagraphMechanism(bview, old_cursor);
+ setCursorIntern(par, pos, setfont, boundary);
+ return deleteEmptyParagraphMechanism(old_cursor);
}
-void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
- pos_type pos, bool boundary) const
+void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
+ pos_type pos, bool boundary)
{
lyx::Assert(par);
- lyx::Assert(bview);
cur.par(par);
cur.pos(pos);
cur.boundary(boundary);
-#if 0
- if (pos && par->getChar(pos) == Paragraph::META_INSET &&
- par->getInset(pos)) {
- Inset * ins = par->getInset(pos);
- if (ins->needFullRow() || ins->display()) {
- --pos;
- boundary = true;
- }
- }
-#endif
-
// get the cursor y position in text
int y = 0;
Row * row = getRow(par, pos, y);
+ Row * old_row = row;
+ cur.irow(row);
+ // if we are before the first char of this row and are still in the
+ // same paragraph and there is a previous row then put the cursor on
+ // the end of the previous row
+ cur.iy(y + row->baseline());
+ Inset * ins;
+ if (row->previous() && pos &&
+ row->previous()->par() == row->par() &&
+ pos < par->size() &&
+ par->getChar(pos) == Paragraph::META_INSET &&
+ (ins = par->getInset(pos)) && (ins->needFullRow() || ins->display()))
+ {
+ row = row->previous();
+ y -= row->height();
+ }
+
+ cur.row(row);
// y is now the beginning of the cursor row
y += row->baseline();
- // y is now the cursor baseline
+ // y is now the cursor baseline
cur.y(y);
- // now get the cursors x position
- float x;
- float fill_separator;
- float fill_hfill;
- float fill_label_hfill;
- prepareToPrint(bview, row, x, fill_separator, fill_hfill,
- fill_label_hfill);
- pos_type cursor_vpos = 0;
- pos_type last = rowLastPrintable(row);
+ pos_type last = old_row->lastPrintablePos();
- if (pos > last + 1) {
+ // None of these should happen, but we're scaredy-cats
+ if (pos > par->size()) {
+ lyxerr << "dont like 1 please report" << endl;
+ pos = 0;
+ cur.pos(0);
+ } else if (pos > last + 1) {
+ lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen.
pos = last + 1;
cur.pos(pos);
} else if (pos < row->pos()) {
+ lyxerr << "dont like 3 please report" << endl;
pos = row->pos();
cur.pos(pos);
}
-
+
+ // now get the cursors x position
+ float x = getCursorX(row, pos, last, boundary);
+ cur.x(int(x));
+ cur.x_fix(cur.x());
+ if (old_row != row) {
+ x = getCursorX(old_row, pos, last, boundary);
+ cur.ix(int(x));
+ } else
+ cur.ix(cur.x());
+ //if the cursor is in a visible row, anchor to it
+ int topy = top_y();
+ if (topy < y && y < topy + bv()->workHeight())
+ anchor_row(row);
+}
+
+
+float LyXText::getCursorX(Row * row,
+ pos_type pos, pos_type last, bool boundary) const
+{
+ pos_type cursor_vpos = 0;
+ float x;
+ float fill_separator;
+ float fill_hfill;
+ float fill_label_hfill;
+ // This call HAS to be here because of the BidiTables!!!
+ prepareToPrint(row, x, fill_separator, fill_hfill,
+ fill_label_hfill);
+
if (last < row->pos())
cursor_vpos = row->pos();
else if (pos > last && !boundary)
- cursor_vpos = (row->par()->isRightToLeftPar(bview->buffer()->params))
- ? row->pos() : last + 1;
+ cursor_vpos = (row->par()->isRightToLeftPar(bv()->buffer()->params))
+ ? row->pos() : last + 1;
else if (pos > row->pos() &&
- (pos > last || boundary))
+ (pos > last || boundary))
/// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
? log2vis(pos - 1) + 1 : log2vis(pos - 1);
/// Place cursor before char at (logical) position pos
cursor_vpos = (bidi_level(pos) % 2 == 0)
? log2vis(pos) : log2vis(pos) + 1;
-
- pos_type main_body =
- beginningOfMainBody(bview->buffer(), row->par());
- if ((main_body > 0) &&
- ((main_body-1 > last) ||
- !row->par()->isLineSeparator(main_body-1)))
- main_body = 0;
-
+
+ pos_type body_pos = row->par()->beginningOfBody();
+ if ((body_pos > 0) &&
+ ((body_pos-1 > last) ||
+ !row->par()->isLineSeparator(body_pos - 1)))
+ body_pos = 0;
+
for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
- pos = vis2log(vpos);
- if (main_body > 0 && pos == main_body - 1) {
+ pos_type pos = vis2log(vpos);
+ if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill +
- lyxfont::width(textclasslist[
- bview->buffer()->params.textclass][
- row->par()->layout()]
- .labelsep,
- getLabelFont(bview->buffer(), row->par()));
- if (row->par()->isLineSeparator(main_body-1))
- x -= singleWidth(bview, row->par(),main_body-1);
+ font_metrics::width(
+ row->par()->layout()->labelsep,
+ getLabelFont(bv()->buffer(),
+ row->par()));
+ if (row->par()->isLineSeparator(body_pos - 1))
+ x -= singleWidth(
+ row->par(), body_pos - 1);
}
- if (hfillExpansion(bview->buffer(), row, pos)) {
- x += singleWidth(bview, row->par(), pos);
- if (pos >= main_body)
+ if (row->hfillExpansion(pos)) {
+ x += singleWidth(row->par(), pos);
+ if (pos >= body_pos)
x += fill_hfill;
- else
+ else
x += fill_label_hfill;
} else if (row->par()->isSeparator(pos)) {
- x += singleWidth(bview, row->par(), pos);
- if (pos >= main_body)
+ x += singleWidth(row->par(), pos);
+ if (pos >= body_pos)
x += fill_separator;
} else
- x += singleWidth(bview, row->par(), pos);
+ x += singleWidth(row->par(), pos);
}
-
- cur.x(int(x));
- cur.x_fix(cur.x());
- cur.row(row);
+ return x;
}
-void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
- pos_type pos, bool setfont, bool boundary) const
+void LyXText::setCursorIntern(Paragraph * par,
+ pos_type pos, bool setfont, bool boundary)
{
InsetText * it = static_cast<InsetText *>(par->inInset());
if (it) {
if (it != inset_owner) {
- lyxerr << "InsetText is " << it << endl;
- lyxerr << "inset_owner is " << inset_owner << endl;
+ lyxerr[Debug::INSETS] << "InsetText is " << it
+ << endl
+ << "inset_owner is "
+ << inset_owner << endl;
#ifdef WITH_WARNINGS
#warning I believe this code is wrong. (Lgb)
#warning Jürgen, have a look at this. (Lgb)
// I moved the lyxerr stuff in here so we can see if
// this is actually really needed and where!
// (Jug)
- // it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont, boundary);
+ // it->getLyXText(bv())->setCursorIntern(bv(), par, pos, setfont, boundary);
return;
}
}
-
- setCursor(bview, cursor, par, pos, boundary);
+
+ setCursor(cursor, par, pos, boundary);
if (setfont)
- setCurrentFont(bview);
+ setCurrentFont();
}
-void LyXText::setCurrentFont(BufferView * bview) const
+void LyXText::setCurrentFont()
{
pos_type pos = cursor.pos();
if (cursor.boundary() && pos > 0)
else // potentional bug... BUG (Lgb)
if (cursor.par()->isSeparator(pos)) {
if (pos > cursor.row()->pos() &&
- bidi_level(pos) % 2 ==
+ bidi_level(pos) % 2 ==
bidi_level(pos - 1) % 2)
--pos;
else if (pos + 1 < cursor.par()->size())
}
current_font =
- cursor.par()->getFontSettings(bview->buffer()->params, pos);
- real_current_font = getFont(bview->buffer(), cursor.par(), pos);
+ cursor.par()->getFontSettings(bv()->buffer()->params, pos);
+ real_current_font = getFont(bv()->buffer(), cursor.par(), pos);
if (cursor.pos() == cursor.par()->size() &&
- isBoundary(bview->buffer(), cursor.par(), cursor.pos()) &&
+ isBoundary(bv()->buffer(), cursor.par(), cursor.pos()) &&
!cursor.boundary()) {
Language const * lang =
- cursor.par()->getParLanguage(bview->buffer()->params);
+ cursor.par()->getParLanguage(bv()->buffer()->params);
current_font.setLanguage(lang);
current_font.setNumber(LyXFont::OFF);
real_current_font.setLanguage(lang);
}
-void LyXText::setCursorFromCoordinates(BufferView * bview, int x, int y) const
+// returns the column near the specified x-coordinate of the row
+// x is set to the real beginning of this column
+pos_type
+LyXText::getColumnNearX(Row * row, int & x,
+ bool & boundary) const
+{
+ float tmpx = 0.0;
+ float fill_separator;
+ float fill_hfill;
+ float fill_label_hfill;
+
+ prepareToPrint(row, tmpx, fill_separator,
+ fill_hfill, fill_label_hfill);
+
+ pos_type vc = row->pos();
+ pos_type last = row->lastPrintablePos();
+ pos_type c = 0;
+
+ LyXLayout_ptr const & layout = row->par()->layout();
+
+ bool left_side = false;
+
+ pos_type body_pos = row->par()->beginningOfBody();
+ float last_tmpx = tmpx;
+
+ if (body_pos > 0 &&
+ (body_pos - 1 > last ||
+ !row->par()->isLineSeparator(body_pos - 1)))
+ body_pos = 0;
+
+ // check for empty row
+ if (!row->par()->size()) {
+ x = int(tmpx);
+ return 0;
+ }
+
+ while (vc <= last && tmpx <= x) {
+ c = vis2log(vc);
+ last_tmpx = tmpx;
+ if (body_pos > 0 && c == body_pos-1) {
+ tmpx += fill_label_hfill +
+ font_metrics::width(layout->labelsep,
+ getLabelFont(bv()->buffer(), row->par()));
+ if (row->par()->isLineSeparator(body_pos - 1))
+ tmpx -= singleWidth(row->par(), body_pos-1);
+ }
+
+ if (row->hfillExpansion(c)) {
+ tmpx += singleWidth(row->par(), c);
+ if (c >= body_pos)
+ tmpx += fill_hfill;
+ else
+ tmpx += fill_label_hfill;
+ } else if (row->par()->isSeparator(c)) {
+ tmpx += singleWidth(row->par(), c);
+ if (c >= body_pos)
+ tmpx+= fill_separator;
+ } else {
+ tmpx += singleWidth(row->par(), c);
+ }
+ ++vc;
+ }
+
+ if ((tmpx + last_tmpx) / 2 > x) {
+ tmpx = last_tmpx;
+ left_side = true;
+ }
+
+ if (vc > last + 1) // This shouldn't happen.
+ vc = last + 1;
+
+ boundary = false;
+ bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
+ // some speedup if rtl_support=false
+ && (!row->next() || row->next()->par() != row->par());
+ bool const rtl = (lastrow)
+ ? row->par()->isRightToLeftPar(bv()->buffer()->params)
+ : false; // If lastrow is false, we don't need to compute
+ // the value of rtl.
+
+ if (lastrow &&
+ ((rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
+ (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
+ c = last + 1;
+ else if (vc == row->pos()) {
+ c = vis2log(vc);
+ if (bidi_level(c) % 2 == 1)
+ ++c;
+ } else {
+ c = vis2log(vc - 1);
+ bool const rtl = (bidi_level(c) % 2 == 1);
+ if (left_side == rtl) {
+ ++c;
+ boundary = isBoundary(bv()->buffer(), row->par(), c);
+ }
+ }
+
+ if (row->pos() <= last && c > last
+ && row->par()->isNewline(last)) {
+ if (bidi_level(last) % 2 == 0)
+ tmpx -= singleWidth(row->par(), last);
+ else
+ tmpx += singleWidth(row->par(), last);
+ c = last;
+ }
+
+ c -= row->pos();
+ x = int(tmpx);
+ return c;
+}
+
+
+void LyXText::setCursorFromCoordinates(int x, int y)
{
LyXCursor old_cursor = cursor;
- setCursorFromCoordinates(bview, cursor, x, y);
- setCurrentFont(bview);
- deleteEmptyParagraphMechanism(bview, old_cursor);
+ setCursorFromCoordinates(cursor, x, y);
+ setCurrentFont();
+ deleteEmptyParagraphMechanism(old_cursor);
}
-void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
- int x, int y) const
+namespace {
+
+ /**
+ * return true if the cursor given is at the end of a row,
+ * and the next row is filled by an inset that spans an entire
+ * row.
+ */
+ bool beforeFullRowInset(Row & row, LyXCursor & cur) {
+ if (!row.next())
+ return false;
+ Row const & next = *row.next();
+
+ if (next.pos() != cur.pos() || next.par() != cur.par())
+ return false;
+ if (!cur.par()->isInset(cur.pos()))
+ return false;
+ Inset const * inset = cur.par()->getInset(cur.pos());
+ if (inset->needFullRow() || inset->display())
+ return true;
+ return false;
+ }
+}
+
+
+void LyXText::setCursorFromCoordinates(LyXCursor & cur,
+ int x, int y)
{
// Get the row first.
-
+
Row * row = getRowNearY(y);
bool bound = false;
- pos_type const column = getColumnNearX(bview, row, x, bound);
+ pos_type const column = getColumnNearX(row, x, bound);
cur.par(row->par());
cur.pos(row->pos() + column);
cur.x(x);
cur.y(y + row->baseline());
- cur.row(row);
+ cur.row(row);
+
+ if (beforeFullRowInset(*row, cur)) {
+ pos_type last = row->lastPrintablePos();
+ float x = getCursorX(row->next(), cur.pos(), last, bound);
+ cur.ix(int(x));
+ cur.iy(y + row->height() + row->next()->baseline());
+ cur.irow(row->next());
+ } else {
+ cur.iy(cur.y());
+ cur.ix(cur.x());
+ cur.irow(row);
+ }
cur.boundary(bound);
}
-void LyXText::cursorLeft(BufferView * bview, bool internal) const
+void LyXText::cursorLeft(bool internal)
{
if (cursor.pos() > 0) {
bool boundary = cursor.boundary();
- setCursor(bview, cursor.par(), cursor.pos() - 1, true, false);
+ setCursor(cursor.par(), cursor.pos() - 1, true, false);
if (!internal && !boundary &&
- isBoundary(bview->buffer(), cursor.par(), cursor.pos() + 1))
- setCursor(bview, cursor.par(), cursor.pos() + 1, true, true);
+ isBoundary(bv()->buffer(), cursor.par(), cursor.pos() + 1))
+ setCursor(cursor.par(), cursor.pos() + 1, true, true);
} else if (cursor.par()->previous()) { // steps into the above paragraph.
Paragraph * par = cursor.par()->previous();
- setCursor(bview, par, par->size());
+ setCursor(par, par->size());
}
}
-void LyXText::cursorRight(BufferView * bview, bool internal) const
+void LyXText::cursorRight(bool internal)
{
if (!internal && cursor.boundary() &&
!cursor.par()->isNewline(cursor.pos()))
- setCursor(bview, cursor.par(), cursor.pos(), true, false);
+ setCursor(cursor.par(), cursor.pos(), true, false);
else if (cursor.pos() < cursor.par()->size()) {
- setCursor(bview, cursor.par(), cursor.pos() + 1, true, false);
+ setCursor(cursor.par(), cursor.pos() + 1, true, false);
if (!internal &&
- isBoundary(bview->buffer(), cursor.par(), cursor.pos()))
- setCursor(bview, cursor.par(), cursor.pos(), true, true);
+ isBoundary(bv()->buffer(), cursor.par(), cursor.pos()))
+ setCursor(cursor.par(), cursor.pos(), true, true);
} else if (cursor.par()->next())
- setCursor(bview, cursor.par()->next(), 0);
+ setCursor(cursor.par()->next(), 0);
}
-void LyXText::cursorUp(BufferView * bview) const
+void LyXText::cursorUp(bool selecting)
{
- setCursorFromCoordinates(bview, cursor.x_fix(),
+#if 1
+ int x = cursor.x_fix();
+ int y = cursor.y() - cursor.row()->baseline() - 1;
+ setCursorFromCoordinates(x, y);
+ if (!selecting) {
+ int topy = top_y();
+ int y1 = cursor.iy() - topy;
+ int y2 = y1;
+ y -= topy;
+ Inset * inset_hit = checkInsetHit(x, y1);
+ if (inset_hit && isHighlyEditableInset(inset_hit)) {
+ inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
+ }
+ }
+#else
+ setCursorFromCoordinates(bv(), cursor.x_fix(),
cursor.y() - cursor.row()->baseline() - 1);
+#endif
}
-void LyXText::cursorDown(BufferView * bview) const
+void LyXText::cursorDown(bool selecting)
{
- setCursorFromCoordinates(bview, cursor.x_fix(),
+#if 1
+ int x = cursor.x_fix();
+ int y = cursor.y() - cursor.row()->baseline() +
+ cursor.row()->height() + 1;
+ setCursorFromCoordinates(x, y);
+ if (!selecting && cursor.row() == cursor.irow()) {
+ int topy = top_y();
+ int y1 = cursor.iy() - topy;
+ int y2 = y1;
+ y -= topy;
+ Inset * inset_hit = checkInsetHit(x, y1);
+ if (inset_hit && isHighlyEditableInset(inset_hit)) {
+ inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
+ }
+ }
+#else
+ setCursorFromCoordinates(bv(), cursor.x_fix(),
cursor.y() - cursor.row()->baseline()
+ cursor.row()->height() + 1);
+#endif
}
-void LyXText::cursorUpParagraph(BufferView * bview) const
+void LyXText::cursorUpParagraph()
{
if (cursor.pos() > 0) {
- setCursor(bview, cursor.par(), 0);
+ setCursor(cursor.par(), 0);
}
else if (cursor.par()->previous()) {
- setCursor(bview, cursor.par()->previous(), 0);
+ setCursor(cursor.par()->previous(), 0);
}
}
-void LyXText::cursorDownParagraph(BufferView * bview) const
+void LyXText::cursorDownParagraph()
{
if (cursor.par()->next()) {
- setCursor(bview, cursor.par()->next(), 0);
+ setCursor(cursor.par()->next(), 0);
} else {
- setCursor(bview, cursor.par(), cursor.par()->size());
+ setCursor(cursor.par(), cursor.par()->size());
}
}
// fix the cursor `cur' after a characters has been deleted at `where'
// position. Called by deleteEmptyParagraphMechanism
-void LyXText::fixCursorAfterDelete(BufferView * bview,
- LyXCursor & cur,
- LyXCursor const & where) const
+void LyXText::fixCursorAfterDelete(LyXCursor & cur,
+ LyXCursor const & where)
{
// if cursor is not in the paragraph where the delete occured,
// do nothing
if (cur.pos() > where.pos())
cur.pos(cur.pos()-1);
+ // check also if we don't want to set the cursor on a spot behind the
+ // pagragraph because we erased the last character.
+ if (cur.pos() > cur.par()->size())
+ cur.pos(cur.par()->size());
+
// recompute row et al. for this cursor
- setCursor(bview, cur, cur.par(), cur.pos(), cur.boundary());
+ setCursor(cur, cur.par(), cur.pos(), cur.boundary());
}
-bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
- LyXCursor const & old_cursor) const
+bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
{
// Would be wrong to delete anything if we have a selection.
if (selection.set())
return false;
// We allow all kinds of "mumbo-jumbo" when freespacing.
- if (textclasslist[bview->buffer()->params.textclass][
- old_cursor.par()->layout()].free_spacing
- || old_cursor.par()->isFreeSpacing())
- {
+ if (old_cursor.par()->layout()->free_spacing
+ || old_cursor.par()->isFreeSpacing()) {
return false;
}
-
+
/* Ok I'll put some comments here about what is missing.
I have fixed BackSpace (and thus Delete) to not delete
double-spaces automagically. I have also changed Cut,
// If the pos around the old_cursor were spaces, delete one of them.
if (old_cursor.par() != cursor.par()
- || old_cursor.pos() != cursor.pos()) {
+ || old_cursor.pos() != cursor.pos()) {
// Only if the cursor has really moved
-
+
if (old_cursor.pos() > 0
&& old_cursor.pos() < old_cursor.par()->size()
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
old_cursor.par()->erase(old_cursor.pos() - 1);
- redoParagraphs(bview, old_cursor, old_cursor.par()->next());
+ redoParagraphs(old_cursor, old_cursor.par()->next());
#ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer
// automated way in LyXCursor code. (JMarc 26/09/2001)
#endif
// correct all cursors held by the LyXText
- fixCursorAfterDelete(bview, cursor, old_cursor);
- fixCursorAfterDelete(bview, selection.cursor,
+ fixCursorAfterDelete(cursor, old_cursor);
+ fixCursorAfterDelete(selection.cursor,
old_cursor);
- fixCursorAfterDelete(bview, selection.start,
+ fixCursorAfterDelete(selection.start,
old_cursor);
- fixCursorAfterDelete(bview, selection.end, old_cursor);
- fixCursorAfterDelete(bview, last_sel_cursor,
+ fixCursorAfterDelete(selection.end, old_cursor);
+ fixCursorAfterDelete(last_sel_cursor,
old_cursor);
- fixCursorAfterDelete(bview, toggle_cursor, old_cursor);
- fixCursorAfterDelete(bview, toggle_end_cursor,
+ fixCursorAfterDelete(toggle_cursor, old_cursor);
+ fixCursorAfterDelete(toggle_end_cursor,
old_cursor);
return false;
}
// don't delete anything if this is the ONLY paragraph!
if (!old_cursor.par()->next() && !old_cursor.par()->previous())
return false;
-
+
// Do not delete empty paragraphs with keepempty set.
- if (textclasslist
- [bview->buffer()->params.textclass]
- [old_cursor.par()->layout()].keepempty)
+ if (old_cursor.par()->layout()->keepempty)
return false;
// only do our magic if we changed paragraph
- if (old_cursor.par() == cursor.par())
+ if (old_cursor.par() == cursor.par())
return false;
-
+
// record if we have deleted a paragraph
// we can't possibly have deleted a paragraph before this point
bool deleted = false;
- if ((old_cursor.par()->size() == 0
+ if ((old_cursor.par()->empty()
|| (old_cursor.par()->size() == 1
&& old_cursor.par()->isLineSeparator(0)))) {
// ok, we will delete anything
LyXCursor tmpcursor;
-
- // make sure that you do not delete any environments
- status(bview, LyXText::NEED_MORE_REFRESH);
+
deleted = true;
-
+
if (old_cursor.row()->previous()) {
- refresh_row = old_cursor.row()->previous();
- refresh_y = old_cursor.y() - old_cursor.row()->baseline() - refresh_row->height();
+ const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline()
+ - old_cursor.row()->previous()->height());
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next();
endpar = endpar->next();
}
}
- setUndo(bview, Undo::DELETE, old_cursor.par(), endpar);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(), endpar);
cursor = tmpcursor;
// delete old row
}
// delete old par
delete old_cursor.par();
-
+
/* Breakagain the next par. Needed because of
* the parindent that can occur or dissappear.
* The next row can change its height, if
* there is another layout before */
- if (refresh_row->next()) {
- breakAgain(bview, refresh_row->next());
- updateCounters(bview, refresh_row);
+ if (refresh_row) {
+ if (refresh_row->next()) {
+ breakAgain(refresh_row->next());
+ updateCounters();
+ }
+ setHeightOfRow(refresh_row);
}
- setHeightOfRow(bview, refresh_row);
} else {
- refresh_row = old_cursor.row()->next();
- refresh_y = old_cursor.y() - old_cursor.row()->baseline();
-
+ Row * nextrow = old_cursor.row()->next();
+ const_cast<LyXText *>(this)->postPaint(
+ old_cursor.y() - old_cursor.row()->baseline());
+
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next();
endpar = endpar->next();
}
}
- setUndo(bview, Undo::DELETE, old_cursor.par(), endpar);
+ setUndo(bv(), Undo::DELETE, old_cursor.par(), endpar);
cursor = tmpcursor;
// delete old row
}
delete old_cursor.par();
-
+
/* Breakagain the next par. Needed because of
the parindent that can occur or dissappear.
The next row can change its height, if
there is another layout before */
- if (refresh_row) {
- breakAgain(bview, refresh_row);
- updateCounters(bview, refresh_row->previous());
+ if (nextrow) {
+ breakAgain(nextrow);
+ updateCounters();
}
}
-
+
// correct cursor y
- setCursorIntern(bview, cursor.par(), cursor.pos());
+ setCursorIntern(cursor.par(), cursor.pos());
if (selection.cursor.par() == old_cursor.par()
&& selection.cursor.pos() == old_cursor.pos()) {
}
}
if (!deleted) {
- if (old_cursor.par()->stripLeadingSpaces(bview->buffer()->params.textclass)) {
- redoParagraphs(bview, old_cursor,
+ if (old_cursor.par()->stripLeadingSpaces()) {
+ redoParagraphs(old_cursor,
old_cursor.par()->next());
// correct cursor y
- setCursorIntern(bview, cursor.par(), cursor.pos());
+ setCursorIntern(cursor.par(), cursor.pos());
selection.cursor = cursor;
}
}
}
-void LyXText::toggleAppendix(BufferView * bview)
-{
- Paragraph * par = cursor.par();
- bool start = !par->params().startOfAppendix();
-
- // ensure that we have only one start_of_appendix in this document
- Paragraph * tmp = ownerParagraph();
- for (; tmp; tmp = tmp->next()) {
- tmp->params().startOfAppendix(false);
- }
-
- par->params().startOfAppendix(start);
-
- // we can set the refreshing parameters now
- status(bview, LyXText::NEED_MORE_REFRESH);
- refresh_y = 0;
- refresh_row = 0; // not needed for full update
- updateCounters(bview, 0);
- setCursor(bview, cursor.par(), cursor.pos());
-}
-
-
Paragraph * LyXText::ownerParagraph() const
{
if (inset_owner) {
return inset_owner->paragraph();
}
- return bv_owner->buffer()->paragraph;
+ return &*(bv_owner->buffer()->paragraphs.begin());
}
if (inset_owner) {
inset_owner->paragraph(p);
} else {
- bv_owner->buffer()->paragraph = p;
+ bv_owner->buffer()->paragraphs.set(p);
}
}
}
-LyXText::text_status LyXText::status() const
+LyXText::refresh_status LyXText::refreshStatus() const
{
- return status_;
+ return refresh_status_;
}
-void LyXText::status(BufferView * bview, LyXText::text_status st) const
+void LyXText::clearPaint()
{
- // well as much as I know && binds more then || so the above and the
- // below are identical (this for your known use of parentesis!)
- // Now some explanation:
- // We should only go up with refreshing code so this means that if
- // we have a MORE refresh we should never set it to LITTLE if we still
- // didn't handle it (and then it will be UNCHANGED. Now as long as
- // we stay inside one LyXText this may work but we need to tell the
- // outermost LyXText that it should REALLY draw us if there is some
- // change in a Inset::LyXText. So you see that when we are inside a
- // inset's LyXText we give the LITTLE to the outermost LyXText to
- // tell'em that it should redraw the actual row (where the inset
- // resides! Capito?!
+ refresh_status_ = REFRESH_NONE;
+ refresh_row = 0;
+ refresh_y = 0;
+}
- if ((status_ != NEED_MORE_REFRESH)
- || (status_ == NEED_MORE_REFRESH
- && st != NEED_VERY_LITTLE_REFRESH))
- {
- status_ = st;
- if (inset_owner && st != UNCHANGED) {
- bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
- if (!bview->text->refresh_row) {
- bview->text->refresh_row = bview->text->cursor.row();
- bview->text->refresh_y = bview->text->cursor.y() -
- bview->text->cursor.row()->baseline();
- }
- }
+
+void LyXText::postPaint(int start_y)
+{
+ refresh_status old = refresh_status_;
+
+ refresh_status_ = REFRESH_AREA;
+ refresh_row = 0;
+
+ if (old != REFRESH_NONE && refresh_y < start_y)
+ return;
+
+ refresh_y = start_y;
+
+ if (!inset_owner)
+ return;
+
+ // We are an inset's lyxtext. Tell the top-level lyxtext
+ // it needs to update the row we're in.
+ LyXText * t = bv()->text;
+ t->postRowPaint(t->cursor.row(), t->cursor.y() - t->cursor.row()->baseline());
+}
+
+
+// FIXME: we should probably remove this y parameter,
+// make refresh_y be 0, and use row->y etc.
+void LyXText::postRowPaint(Row * row, int start_y)
+{
+ if (refresh_status_ != REFRESH_NONE && refresh_y < start_y) {
+ refresh_status_ = REFRESH_AREA;
+ return;
+ } else {
+ refresh_y = start_y;
}
+
+ if (refresh_status_ == REFRESH_AREA)
+ return;
+
+ refresh_status_ = REFRESH_ROW;
+ refresh_row = row;
+
+ if (!inset_owner)
+ return;
+
+ // We are an inset's lyxtext. Tell the top-level lyxtext
+ // it needs to update the row we're in.
+ LyXText * t = bv()->text;
+ t->postRowPaint(t->cursor.row(), t->cursor.y() - t->cursor.row()->baseline());
+}
+
+
+bool LyXText::isInInset() const
+{
+ // Sub-level has non-null bv owner and
+ // non-null inset owner.
+ return inset_owner != 0 && bv_owner != 0;
+}
+
+
+int defaultRowHeight()
+{
+ LyXFont const font(LyXFont::ALL_SANE);
+ return int(font_metrics::maxAscent(font)
+ + font_metrics::maxDescent(font) * 1.5);
}