some refactoring.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22890 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-02-09 10:41:49 +00:00
parent fb2c00d4bc
commit 225bf49cf9
10 changed files with 86 additions and 88 deletions

View File

@ -16,6 +16,7 @@
#include "support/strfwd.h" #include "support/strfwd.h"
#include "support/types.h" #include "support/types.h"
#include "support/SignalSlot.h"
#include <set> #include <set>
#include <string> #include <string>
@ -494,6 +495,17 @@ private:
Impl * const d; Impl * const d;
frontend::GuiBufferDelegate * gui_; frontend::GuiBufferDelegate * gui_;
/// This function is called when the buffer structure is changed.
Signal structureChanged_;
/// This function is called when some parsing error shows up.
//Signal errors(std::string const &) = 0;
/// This function is called when some message shows up.
//Signal message(docstring const &) = 0;
/// This function is called when the buffer busy status change.
//Signal setBusy(bool) = 0;
/// Reset autosave timers for all users.
Signal resetAutosaveTimers_;
}; };

View File

@ -191,9 +191,9 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
// Set the inset owner of this paragraph. // Set the inset owner of this paragraph.
tmpbuf->setInsetOwner(pars[pit].inInset()); tmpbuf->setInsetOwner(pars[pit].inInset());
for (pos_type i = 0; i < tmpbuf->size(); ++i) { for (pos_type i = 0; i < tmpbuf->size(); ++i) {
if (tmpbuf->isInset(i) &&
!pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
// do not track deletion of invalid insets // do not track deletion of invalid insets
if (Inset * inset = tmpbuf->getInset(i))
if (!pars[pit].insetAllowed(inset->lyxCode()))
tmpbuf->eraseChar(i--, false); tmpbuf->eraseChar(i--, false);
} }

View File

@ -77,7 +77,7 @@ Inset * DocIterator::nextInset() const
} }
if (inMathed()) if (inMathed())
return nextAtom().nucleus(); return nextAtom().nucleus();
return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0; return paragraph().getInset(pos());
} }
@ -95,7 +95,7 @@ Inset * DocIterator::prevInset() const
else else
return prevAtom().nucleus(); return prevAtom().nucleus();
} }
return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0; return paragraph().getInset(pos() - 1);
} }
@ -268,13 +268,11 @@ void DocIterator::forwardPos()
if (tip.pos() != lastp) { if (tip.pos() != lastp) {
// this is impossible for pos() == size() // this is impossible for pos() == size()
if (inMathed()) { if (inMathed())
n = (tip.cell().begin() + tip.pos())->nucleus(); n = (tip.cell().begin() + tip.pos())->nucleus();
} else { else
if (paragraph().isInset(tip.pos()))
n = paragraph().getInset(tip.pos()); n = paragraph().getInset(tip.pos());
} }
}
if (n && n->isActive()) { if (n && n->isActive()) {
//lyxerr << "... descend" << endl; //lyxerr << "... descend" << endl;
@ -384,12 +382,10 @@ void DocIterator::backwardPos()
// move into an inset to the left if possible // move into an inset to the left if possible
Inset * n = 0; Inset * n = 0;
if (inMathed()) { if (inMathed())
n = (top().cell().begin() + top().pos())->nucleus(); n = (top().cell().begin() + top().pos())->nucleus();
} else { else
if (paragraph().isInset(top().pos()))
n = paragraph().getInset(top().pos()); n = paragraph().getInset(top().pos());
}
if (n && n->isActive()) { if (n && n->isActive()) {
push_back(CursorSlice(*n)); push_back(CursorSlice(*n));
@ -463,8 +459,8 @@ bool DocIterator::fixIfBroken()
// get inset which is supposed to be in the next slice // get inset which is supposed to be in the next slice
if (cs.inset().inMathed()) if (cs.inset().inMathed())
inset = (cs.cell().begin() + cs.pos())->nucleus(); inset = (cs.cell().begin() + cs.pos())->nucleus();
else if (cs.paragraph().isInset(cs.pos())) else if (Inset * csInset = cs.paragraph().getInset(cs.pos()))
inset = cs.paragraph().getInset(cs.pos()); inset = csInset;
else { else {
// there are slices left, so there must be another inset // there are slices left, so there must be another inset
break; break;

View File

@ -279,8 +279,8 @@ void Paragraph::setChange(Change const & change)
if (change.type != Change::DELETED) { if (change.type != Change::DELETED) {
for (pos_type pos = 0; pos < size(); ++pos) { for (pos_type pos = 0; pos < size(); ++pos) {
if (isInset(pos)) if (Inset * inset = getInset(pos))
getInset(pos)->setChange(change); inset->setChange(change);
} }
} }
} }
@ -292,8 +292,9 @@ void Paragraph::setChange(pos_type pos, Change const & change)
d->changes_.set(change, pos); d->changes_.set(change, pos);
// see comment in setChange(Change const &) above // see comment in setChange(Change const &) above
if (change.type != Change::DELETED && pos < size() && isInset(pos)) if (change.type != Change::DELETED && pos < size())
getInset(pos)->setChange(change); if (Inset * inset = getInset(pos))
inset->setChange(change);
} }
@ -314,17 +315,15 @@ void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
switch (lookupChange(pos).type) { switch (lookupChange(pos).type) {
case Change::UNCHANGED: case Change::UNCHANGED:
// accept changes in nested inset // accept changes in nested inset
if (pos < size() && isInset(pos)) if (Inset * inset = getInset(pos))
getInset(pos)->acceptChanges(bparams); inset->acceptChanges(bparams);
break; break;
case Change::INSERTED: case Change::INSERTED:
d->changes_.set(Change(Change::UNCHANGED), pos); d->changes_.set(Change(Change::UNCHANGED), pos);
// also accept changes in nested inset // also accept changes in nested inset
if (pos < size() && isInset(pos)) { if (Inset * inset = getInset(pos))
getInset(pos)->acceptChanges(bparams); inset->acceptChanges(bparams);
}
break; break;
case Change::DELETED: case Change::DELETED:
@ -352,9 +351,8 @@ void Paragraph::rejectChanges(BufferParams const & bparams,
switch (lookupChange(pos).type) { switch (lookupChange(pos).type) {
case Change::UNCHANGED: case Change::UNCHANGED:
// reject changes in nested inset // reject changes in nested inset
if (pos < size() && isInset(pos)) { if (Inset * inset = getInset(pos))
getInset(pos)->rejectChanges(bparams); inset->rejectChanges(bparams);
}
break; break;
case Change::INSERTED: case Change::INSERTED:
@ -1113,9 +1111,7 @@ void Paragraph::write(Buffer const & buf, ostream & os,
char_type const c = d->text_[i]; char_type const c = d->text_[i];
switch (c) { switch (c) {
case META_INSET: case META_INSET:
{ if (Inset const * inset = getInset(i)) {
Inset const * inset = getInset(i);
if (inset)
if (inset->directWrite()) { if (inset->directWrite()) {
// international char, let it write // international char, let it write
// code directly so it's shorter in // code directly so it's shorter in
@ -2075,8 +2071,7 @@ bool Paragraph::latex(Buffer const & buf,
bool Paragraph::emptyTag() const bool Paragraph::emptyTag() const
{ {
for (pos_type i = 0; i < size(); ++i) { for (pos_type i = 0; i < size(); ++i) {
if (isInset(i)) { if (Inset const * inset = getInset(i)) {
Inset const * inset = getInset(i);
InsetCode lyx_code = inset->lyxCode(); InsetCode lyx_code = inset->lyxCode();
if (lyx_code != TOC_CODE && if (lyx_code != TOC_CODE &&
lyx_code != INCLUDE_CODE && lyx_code != INCLUDE_CODE &&
@ -2100,8 +2095,7 @@ bool Paragraph::emptyTag() const
string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const
{ {
for (pos_type i = 0; i < size(); ++i) { for (pos_type i = 0; i < size(); ++i) {
if (isInset(i)) { if (Inset const * inset = getInset(i)) {
Inset const * inset = getInset(i);
InsetCode lyx_code = inset->lyxCode(); InsetCode lyx_code = inset->lyxCode();
if (lyx_code == LABEL_CODE) { if (lyx_code == LABEL_CODE) {
InsetLabel const * const il = static_cast<InsetLabel const *>(inset); InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
@ -2109,7 +2103,6 @@ string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) cons
return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'"; return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'";
} }
} }
} }
return string(); return string();
} }
@ -2119,8 +2112,7 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, odocstream & os, OutputPara
{ {
pos_type i; pos_type i;
for (i = 0; i < size(); ++i) { for (i = 0; i < size(); ++i) {
if (isInset(i)) { if (Inset const * inset = getInset(i)) {
Inset const * inset = getInset(i);
inset->docbook(buf, os, runparams); inset->docbook(buf, os, runparams);
} else { } else {
char_type c = d->text_[i]; char_type c = d->text_[i];
@ -2180,8 +2172,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
} }
} }
if (isInset(i)) { if (Inset const * inset = getInset(i)) {
Inset const * inset = getInset(i);
inset->docbook(buf, os, runparams); inset->docbook(buf, os, runparams);
} else { } else {
char_type c = d->text_[i]; char_type c = d->text_[i];
@ -2207,30 +2198,33 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
bool Paragraph::isHfill(pos_type pos) const bool Paragraph::isHfill(pos_type pos) const
{ {
return isInset(pos) && getInset(pos)->lyxCode() == HFILL_CODE; Inset const * inset = getInset(pos);
return inset && inset->lyxCode() == HFILL_CODE;
} }
bool Paragraph::isNewline(pos_type pos) const bool Paragraph::isNewline(pos_type pos) const
{ {
return isInset(pos) && getInset(pos)->lyxCode() == NEWLINE_CODE; Inset const * inset = getInset(pos);
return inset && inset->lyxCode() == NEWLINE_CODE;
} }
bool Paragraph::isLineSeparator(pos_type pos) const bool Paragraph::isLineSeparator(pos_type pos) const
{ {
char_type const c = d->text_[pos]; char_type const c = d->text_[pos];
return isLineSeparatorChar(c) if (isLineSeparatorChar(c))
|| (c == META_INSET && getInset(pos) && return true;
getInset(pos)->isLineSeparator()); Inset const * inset = getInset(pos);
return inset && inset->isLineSeparator();
} }
/// Used by the spellchecker /// Used by the spellchecker
bool Paragraph::isLetter(pos_type pos) const bool Paragraph::isLetter(pos_type pos) const
{ {
if (isInset(pos)) if (Inset const * inset = getInset(pos))
return getInset(pos)->isLetter(); return inset->isLetter();
char_type const c = d->text_[pos]; char_type const c = d->text_[pos];
return isLetterChar(c) || isDigit(c); return isLetterChar(c) || isDigit(c);
} }
@ -2525,13 +2519,15 @@ Inset * Paragraph::releaseInset(pos_type pos)
Inset * Paragraph::getInset(pos_type pos) Inset * Paragraph::getInset(pos_type pos)
{ {
return d->insetlist_.get(pos); return (pos < d->text_.size() && d->text_[pos] == META_INSET)
? d->insetlist_.get(pos) : 0;
} }
Inset const * Paragraph::getInset(pos_type pos) const Inset const * Paragraph::getInset(pos_type pos) const
{ {
return d->insetlist_.get(pos); return (pos < d->text_.size() && d->text_[pos] == META_INSET)
? d->insetlist_.get(pos) : 0;
} }

View File

@ -213,8 +213,8 @@ int ParagraphMetrics::rightMargin(Buffer const & buffer) const
int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const
{ {
// The most special cases are handled first. // The most special cases are handled first.
if (par_->isInset(pos)) if (Inset const * inset = par_->getInset(pos))
return insetDimension(par_->getInset(pos)).wid; return insetDimension(inset).wid;
char_type c = par_->getChar(pos); char_type c = par_->getChar(pos);
@ -230,9 +230,10 @@ int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const
return 0; return 0;
c = par_->transformChar(c, pos); c = par_->transformChar(c, pos);
} else if (language->lang() == "hebrew" && } else if (language->lang() == "hebrew" &&
Encodings::isComposeChar_hebrew(c)) Encodings::isComposeChar_hebrew(c)) {
return 0; return 0;
} }
}
return theFontMetrics(font).width(c); return theFontMetrics(font).width(c);
} }

View File

@ -42,7 +42,6 @@
#include "Paragraph.h" #include "Paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ParIterator.h"
#include "TextClass.h" #include "TextClass.h"
#include "TextMetrics.h" #include "TextMetrics.h"
#include "VSpace.h" #include "VSpace.h"
@ -160,10 +159,9 @@ void Text::setCharFont(Buffer const & buffer, pit_type pit,
void Text::setInsetFont(BufferView const & bv, pit_type pit, void Text::setInsetFont(BufferView const & bv, pit_type pit,
pos_type pos, Font const & font, bool toggleall) pos_type pos, Font const & font, bool toggleall)
{ {
BOOST_ASSERT(pars_[pit].isInset(pos) &&
pars_[pit].getInset(pos)->noFontChange());
Inset * const inset = pars_[pit].getInset(pos); Inset * const inset = pars_[pit].getInset(pos);
BOOST_ASSERT(inset && inset->noFontChange());
CursorSlice::idx_type endidx = inset->nargs(); CursorSlice::idx_type endidx = inset->nargs();
for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) { for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) {
Text * text = cs.text(); Text * text = cs.text();
@ -354,13 +352,14 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
if (dit.pos() != dit.lastpos()) { if (dit.pos() != dit.lastpos()) {
pit_type const pit = dit.pit(); pit_type const pit = dit.pit();
pos_type const pos = dit.pos(); pos_type const pos = dit.pos();
if (pars_[pit].isInset(pos) && Inset * inset = pars_[pit].getInset(pos);
pars_[pit].getInset(pos)->noFontChange()) if (inset && inset->noFontChange()) {
// We need to propagate the font change to all // We need to propagate the font change to all
// text cells of the inset (bug 1973). // text cells of the inset (bug 1973).
// FIXME: This should change, see documentation // FIXME: This should change, see documentation
// of noFontChange in Inset.h // of noFontChange in Inset.h
setInsetFont(bv, pit, pos, font, toggleall); setInsetFont(bv, pit, pos, font, toggleall);
}
TextMetrics const & tm = bv.textMetrics(this); TextMetrics const & tm = bv.textMetrics(this);
Font f = tm.getDisplayFont(pit, pos); Font f = tm.getDisplayFont(pit, pos);
f.update(font, language, toggleall); f.update(font, language, toggleall);

View File

@ -27,12 +27,10 @@
#include "BufferView.h" #include "BufferView.h"
#include "Cursor.h" #include "Cursor.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "support/debug.h"
#include "DispatchResult.h" #include "DispatchResult.h"
#include "ErrorList.h" #include "ErrorList.h"
#include "factory.h" #include "factory.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "support/gettext.h"
#include "InsetList.h" #include "InsetList.h"
#include "Intl.h" #include "Intl.h"
#include "Language.h" #include "Language.h"
@ -44,7 +42,6 @@
#include "Paragraph.h" #include "Paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ParIterator.h"
#include "TextClass.h" #include "TextClass.h"
#include "TextMetrics.h" #include "TextMetrics.h"
#include "VSpace.h" #include "VSpace.h"
@ -61,8 +58,10 @@
#include "insets/InsetText.h" #include "insets/InsetText.h"
#include "insets/InsetInfo.h" #include "insets/InsetInfo.h"
#include "support/lstrings.h"
#include "support/convert.h" #include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/lyxtime.h" #include "support/lyxtime.h"
#include "mathed/InsetMathHull.h" #include "mathed/InsetMathHull.h"

View File

@ -570,11 +570,8 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
align = par.params().align(); align = par.params().align();
// Display-style insets should always be on a centred row // Display-style insets should always be on a centred row
// The test on par.size() is to catch zero-size pars, which if (Inset const * inset = par.getInset(row.pos())) {
// would trigger the assert in Paragraph::getInset(). switch (inset->display()) {
//inset = par.size() ? par.getInset(row.pos()) : 0;
if (row.pos() < par.size() && par.isInset(row.pos())) {
switch(par.getInset(row.pos())->display()) {
case Inset::AlignLeft: case Inset::AlignLeft:
align = LYX_ALIGN_BLOCK; align = LYX_ALIGN_BLOCK;
break; break;
@ -783,20 +780,22 @@ pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
point = i + 1; point = i + 1;
break; break;
} }
Inset const * inset = 0;
// Break before... // Break before...
if (i + 1 < end) { if (i + 1 < end) {
if (par.isInset(i + 1) && par.getInset(i + 1)->display()) { if ((inset = par.getInset(i + 1)) && inset->display()) {
point = i + 1; point = i + 1;
break; break;
} }
// ...and after. // ...and after.
if (par.isInset(i) && par.getInset(i)->display()) { if ((inset = par.getInset(i)) && inset->display()) {
point = i + 1; point = i + 1;
break; break;
} }
} }
if (!par.isInset(i) || par.getInset(i)->isChar()) { inset = par.getInset(i);
if (!inset || inset->isChar()) {
// some insets are line separators too // some insets are line separators too
if (par.isLineSeparator(i)) { if (par.isLineSeparator(i)) {
// register breakpoint: // register breakpoint:

View File

@ -201,8 +201,7 @@ int countChars(DocIterator const & from, DocIterator const & to, bool with_blank
pos_type const pos = dit.pos(); pos_type const pos = dit.pos();
if (pos != dit.lastpos() && !par.isDeleted(pos)) { if (pos != dit.lastpos() && !par.isDeleted(pos)) {
if (par.isInset(pos)) { if (Inset const * ins = par.getInset(pos)) {
Inset const * ins = par.getInset(pos);
if (ins->isLetter()) if (ins->isLetter())
++chars; ++chars;
else if (with_blanks && ins->isSpace()) else if (with_blanks && ins->isSpace())

View File

@ -647,15 +647,12 @@ void RowPainter::paintOnlyInsets()
{ {
pos_type const end = row_.endpos(); pos_type const end = row_.endpos();
for (pos_type pos = row_.pos(); pos != end; ++pos) { for (pos_type pos = row_.pos(); pos != end; ++pos) {
if (!par_.isInset(pos))
continue;
// If outer row has changed, nested insets are repaint completely. // If outer row has changed, nested insets are repaint completely.
Inset const * inset = par_.getInset(pos); Inset const * inset = par_.getInset(pos);
if (!inset)
continue;
if (x_ > pi_.base.bv->workWidth()) if (x_ > pi_.base.bv->workWidth())
continue; continue;
x_ = pi_.base.bv->coordCache().getInsets().x(inset); x_ = pi_.base.bv->coordCache().getInsets().x(inset);
paintInset(inset, pos); paintInset(inset, pos);
} }
@ -730,8 +727,9 @@ void RowPainter::paintText()
last_strikeout_x = int(x_); last_strikeout_x = int(x_);
} }
bool const highly_editable_inset = par_.isInset(pos) Inset const * inset = par_.getInset(pos);
&& par_.getInset(pos)->editable() == Inset::HIGHLY_EDITABLE; bool const highly_editable_inset = inset
&& inset->editable() == Inset::HIGHLY_EDITABLE;
// If we reach the end of a struck out range, paint it. // If we reach the end of a struck out range, paint it.
// We also don't paint across things like tables // We also don't paint across things like tables
@ -761,9 +759,8 @@ void RowPainter::paintText()
paintForeignMark(orig_x, orig_font.language()); paintForeignMark(orig_x, orig_font.language());
++vpos; ++vpos;
} else if (par_.isInset(pos)) { } else if (inset) {
// If outer row has changed, nested insets are repaint completely. // If outer row has changed, nested insets are repaint completely.
Inset const * inset = par_.getInset(pos);
pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_); pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
paintInset(inset, pos); paintInset(inset, pos);
++vpos; ++vpos;