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/types.h"
#include "support/SignalSlot.h"
#include <set>
#include <string>
@ -494,6 +495,17 @@ private:
Impl * const d;
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.
tmpbuf->setInsetOwner(pars[pit].inInset());
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
if (Inset * inset = tmpbuf->getInset(i))
if (!pars[pit].insetAllowed(inset->lyxCode()))
tmpbuf->eraseChar(i--, false);
}

View File

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

View File

@ -279,8 +279,8 @@ void Paragraph::setChange(Change const & change)
if (change.type != Change::DELETED) {
for (pos_type pos = 0; pos < size(); ++pos) {
if (isInset(pos))
getInset(pos)->setChange(change);
if (Inset * inset = getInset(pos))
inset->setChange(change);
}
}
}
@ -292,8 +292,9 @@ void Paragraph::setChange(pos_type pos, Change const & change)
d->changes_.set(change, pos);
// see comment in setChange(Change const &) above
if (change.type != Change::DELETED && pos < size() && isInset(pos))
getInset(pos)->setChange(change);
if (change.type != Change::DELETED && pos < size())
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) {
case Change::UNCHANGED:
// accept changes in nested inset
if (pos < size() && isInset(pos))
getInset(pos)->acceptChanges(bparams);
if (Inset * inset = getInset(pos))
inset->acceptChanges(bparams);
break;
case Change::INSERTED:
d->changes_.set(Change(Change::UNCHANGED), pos);
// also accept changes in nested inset
if (pos < size() && isInset(pos)) {
getInset(pos)->acceptChanges(bparams);
}
if (Inset * inset = getInset(pos))
inset->acceptChanges(bparams);
break;
case Change::DELETED:
@ -352,9 +351,8 @@ void Paragraph::rejectChanges(BufferParams const & bparams,
switch (lookupChange(pos).type) {
case Change::UNCHANGED:
// reject changes in nested inset
if (pos < size() && isInset(pos)) {
getInset(pos)->rejectChanges(bparams);
}
if (Inset * inset = getInset(pos))
inset->rejectChanges(bparams);
break;
case Change::INSERTED:
@ -1113,9 +1111,7 @@ void Paragraph::write(Buffer const & buf, ostream & os,
char_type const c = d->text_[i];
switch (c) {
case META_INSET:
{
Inset const * inset = getInset(i);
if (inset)
if (Inset const * inset = getInset(i)) {
if (inset->directWrite()) {
// international char, let it write
// code directly so it's shorter in
@ -2075,8 +2071,7 @@ bool Paragraph::latex(Buffer const & buf,
bool Paragraph::emptyTag() const
{
for (pos_type i = 0; i < size(); ++i) {
if (isInset(i)) {
Inset const * inset = getInset(i);
if (Inset const * inset = getInset(i)) {
InsetCode lyx_code = inset->lyxCode();
if (lyx_code != TOC_CODE &&
lyx_code != INCLUDE_CODE &&
@ -2100,8 +2095,7 @@ bool Paragraph::emptyTag() const
string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const
{
for (pos_type i = 0; i < size(); ++i) {
if (isInset(i)) {
Inset const * inset = getInset(i);
if (Inset const * inset = getInset(i)) {
InsetCode lyx_code = inset->lyxCode();
if (lyx_code == LABEL_CODE) {
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 string();
}
@ -2119,8 +2112,7 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, odocstream & os, OutputPara
{
pos_type i;
for (i = 0; i < size(); ++i) {
if (isInset(i)) {
Inset const * inset = getInset(i);
if (Inset const * inset = getInset(i)) {
inset->docbook(buf, os, runparams);
} else {
char_type c = d->text_[i];
@ -2180,8 +2172,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
}
}
if (isInset(i)) {
Inset const * inset = getInset(i);
if (Inset const * inset = getInset(i)) {
inset->docbook(buf, os, runparams);
} else {
char_type c = d->text_[i];
@ -2207,30 +2198,33 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
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
{
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
{
char_type const c = d->text_[pos];
return isLineSeparatorChar(c)
|| (c == META_INSET && getInset(pos) &&
getInset(pos)->isLineSeparator());
if (isLineSeparatorChar(c))
return true;
Inset const * inset = getInset(pos);
return inset && inset->isLineSeparator();
}
/// Used by the spellchecker
bool Paragraph::isLetter(pos_type pos) const
{
if (isInset(pos))
return getInset(pos)->isLetter();
if (Inset const * inset = getInset(pos))
return inset->isLetter();
char_type const c = d->text_[pos];
return isLetterChar(c) || isDigit(c);
}
@ -2525,13 +2519,15 @@ Inset * Paragraph::releaseInset(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
{
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
{
// The most special cases are handled first.
if (par_->isInset(pos))
return insetDimension(par_->getInset(pos)).wid;
if (Inset const * inset = par_->getInset(pos))
return insetDimension(inset).wid;
char_type c = par_->getChar(pos);
@ -230,9 +230,10 @@ int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const
return 0;
c = par_->transformChar(c, pos);
} else if (language->lang() == "hebrew" &&
Encodings::isComposeChar_hebrew(c))
Encodings::isComposeChar_hebrew(c)) {
return 0;
}
}
return theFontMetrics(font).width(c);
}

View File

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

View File

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

View File

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

View File

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