]> git.lyx.org Git - features.git/commitdiff
never ask for one past last
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 13 Mar 2003 10:30:28 +0000 (10:30 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 13 Mar 2003 10:30:28 +0000 (10:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6479 a592a061-630c-0410-9148-cb99ea01b6c8

po/POTFILES.in
src/ChangeLog
src/lyxrow.C
src/paragraph.C
src/paragraph_pimpl.C
src/rowpainter.C
src/text.C
src/text2.C

index 4a5d31c7326c93c0880792f401a407af7c0cf7a2..701bbdf17c7675738b2be1916dcf64abab2d4f6d 100644 (file)
@@ -1,20 +1,16 @@
-src/BufferView.C
-src/BufferView_pimpl.C
-src/Chktex.C
-src/CutAndPaste.C
-src/LColor.C
-src/LaTeX.C
-src/LyXAction.C
-src/MenuBackend.C
 src/buffer.C
 src/bufferlist.C
+src/BufferView.C
 src/bufferview_funcs.C
+src/BufferView_pimpl.C
+src/Chktex.C
 src/converter.C
+src/CutAndPaste.C
 src/debug.C
 src/exporter.C
 src/format.C
-src/frontends/LyXView.C
-src/frontends/controllers/ButtonController.h
+src/frontends/controllers/biblio.C
+src/frontends/controllers/character.C
 src/frontends/controllers/ControlAboutlyx.C
 src/frontends/controllers/ControlBibtex.C
 src/frontends/controllers/ControlCharacter.C
@@ -30,14 +26,14 @@ src/frontends/controllers/ControlSearch.C
 src/frontends/controllers/ControlSpellchecker.C
 src/frontends/controllers/ControlThesaurus.C
 src/frontends/controllers/ControlVCLog.C
-src/frontends/controllers/biblio.C
-src/frontends/controllers/character.C
 src/frontends/controllers/frnt_lang.C
 src/frontends/controllers/helper_funcs.C
 src/frontends/gnome/GLog.C
+src/frontends/LyXView.C
 src/frontends/qt2/Alert_pimpl.C
 src/frontends/qt2/Dialogs3.C
 src/frontends/qt2/FileDialog.C
+src/frontends/qt2/lengthcombo.C
 src/frontends/qt2/QAbout.C
 src/frontends/qt2/QBibitem.C
 src/frontends/qt2/QBibtex.C
@@ -50,16 +46,16 @@ src/frontends/qt2/QCommandBuffer.C
 src/frontends/qt2/QDelimiterDialog.C
 src/frontends/qt2/QDocument.C
 src/frontends/qt2/QDocumentDialog.C
-src/frontends/qt2/QERT.C
 src/frontends/qt2/QError.C
+src/frontends/qt2/QERT.C
 src/frontends/qt2/QExternal.C
 src/frontends/qt2/QExternalDialog.C
 src/frontends/qt2/QFloat.C
 src/frontends/qt2/QGraphics.C
 src/frontends/qt2/QGraphicsDialog.C
 src/frontends/qt2/QInclude.C
-src/frontends/qt2/QLPrintDialog.C
 src/frontends/qt2/QLog.C
+src/frontends/qt2/QLPrintDialog.C
 src/frontends/qt2/QMathDialog.C
 src/frontends/qt2/QMathMatrixDialog.C
 src/frontends/qt2/QMinipage.C
@@ -72,18 +68,19 @@ src/frontends/qt2/QSearch.C
 src/frontends/qt2/QSendto.C
 src/frontends/qt2/QShowFile.C
 src/frontends/qt2/QSpellchecker.C
+src/frontends/qt2/Qt2BC.h
 src/frontends/qt2/QTabular.C
 src/frontends/qt2/QTabularCreate.C
 src/frontends/qt2/QTexinfo.C
 src/frontends/qt2/QThesaurus.C
 src/frontends/qt2/QToc.C
+src/frontends/qt2/QtView.C
 src/frontends/qt2/QURL.C
 src/frontends/qt2/QVCLog.C
 src/frontends/qt2/QWrap.C
-src/frontends/qt2/QtView.C
-src/frontends/qt2/lengthcombo.C
 src/frontends/xforms/Alert_pimpl.C
 src/frontends/xforms/ColorHandler.C
+src/frontends/xforms/combox.C
 src/frontends/xforms/Dialogs3.C
 src/frontends/xforms/FileDialog.C
 src/frontends/xforms/FormAboutlyx.C
@@ -95,8 +92,8 @@ src/frontends/xforms/FormCharacter.C
 src/frontends/xforms/FormCitation.C
 src/frontends/xforms/FormDialogView.C
 src/frontends/xforms/FormDocument.C
-src/frontends/xforms/FormERT.C
 src/frontends/xforms/FormError.C
+src/frontends/xforms/FormERT.C
 src/frontends/xforms/FormExternal.C
 src/frontends/xforms/FormFiledialog.C
 src/frontends/xforms/FormFloat.C
@@ -128,15 +125,15 @@ src/frontends/xforms/FormToc.C
 src/frontends/xforms/FormUrl.C
 src/frontends/xforms/FormVCLog.C
 src/frontends/xforms/FormWrap.C
-src/frontends/xforms/Menubar_pimpl.C
-src/frontends/xforms/XMiniBuffer.C
-src/frontends/xforms/combox.C
 src/frontends/xforms/input_validators.C
+src/frontends/xforms/Menubar_pimpl.C
+src/frontends/xforms/xformsBC.h
 src/frontends/xforms/xforms_helpers.C
+src/frontends/xforms/XMiniBuffer.C
 src/gettext.h
 src/importer.C
-src/insets/inset.C
 src/insets/insetbibtex.C
+src/insets/inset.C
 src/insets/insetcaption.C
 src/insets/inseterror.C
 src/insets/insetert.C
@@ -163,12 +160,15 @@ src/insets/insetwrap.C
 src/ispell.C
 src/kbsequence.C
 src/language.C
+src/LaTeX.C
+src/LColor.C
 src/lengthcommon.C
+src/LyXAction.C
 src/lyx_cb.C
-src/lyx_main.C
 src/lyxfind.C
 src/lyxfont.C
 src/lyxfunc.C
+src/lyx_main.C
 src/lyxrc.C
 src/lyxtextclasslist.C
 src/lyxvc.C
@@ -177,10 +177,12 @@ src/mathed/formulamacro.C
 src/mathed/math_hullinset.C
 src/mathed/math_parboxinset.C
 src/mathed/ref_inset.C
+src/MenuBackend.C
 src/paragraph.C
+src/paragraph_funcs.C
 src/rowpainter.C
 src/support/filetools.C
 src/tabular.C
-src/text.C
 src/text2.C
 src/text3.C
+src/text.C
index 3b5eb6a6485b229a2505c808bf942a92db4d9587..b711da17e55bbcd905a1d3c12aa706948b6847e1 100644 (file)
@@ -1,3 +1,28 @@
+2003-03-13  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * text2.C (setCursor): never ask for one past last
+       (setCursor): add some debugging messages.
+
+       * text.C (singleWidth): never ask for one past last
+       (singleWidth): ditto
+       (leftMargin): ditto
+       (rightMargin): ditto
+       (rowBreakPoint): ditto
+       (setHeightOfRow): ditto
+       (prepareToPrint): ditto
+
+       * rowpainter.C (paintBackground): never ask for one past last
+       (paintText): never ask for one past last
+
+       * paragraph_pimpl.C (getChar): make the assert stricter, never
+       allow the one past last pos to be taken
+
+       * paragraph.C (getChar): ws changes only
+
+       * lyxrow.C (nextRowIsAllInset): never ask for one past last
+       (numberOfSeparators): ditto
+       (numberOfHfills): ditto
+
 2003-03-12  John Levon  <levon@movementarian.org>
 
        * author.h:
index af4c7304fc91b8f5b18226fc44bf7da6a2f3f422..b12b17ad0f57c8c7973b57ab821333a60affec44 100644 (file)
@@ -159,6 +159,9 @@ namespace {
 
 bool nextRowIsAllInset(Row const & row, pos_type last)
 {
+       if (last + 1 >= row.par()->size())
+               return false;
+
        if (!row.par()->isInset(last + 1))
                return false;
 
@@ -192,7 +195,7 @@ int Row::numberOfSeparators() const
        pos_type p = max(pos(), par()->beginningOfBody());
 
        int n = 0;
-       for (; p <= last; ++p) {
+       for (; p < last; ++p) {
                if (par()->isSeparator(p)) {
                        ++n;
                }
@@ -208,7 +211,7 @@ int Row::numberOfHfills() const
 
        // hfill *DO* count at the beginning of paragraphs!
        if (first) {
-               while (first <= last && par()->isHfill(first)) {
+               while (first < last && par()->isHfill(first)) {
                        ++first;
                }
        }
@@ -218,7 +221,7 @@ int Row::numberOfHfills() const
        int n = 0;
 
        // last, because the end is ignored!
-       for (pos_type p = first; p <= last; ++p) {
+       for (pos_type p = first; p < last; ++p) {
                if (par()->isHfill(p))
                        ++n;
        }
index 53b9601704278fa485844b093db8853352244d2c..b83a8a77a5331fed5ce6f47a447ee440dd6795d3 100644 (file)
@@ -788,7 +788,7 @@ int Paragraph::beginningOfBody() const
                char previous_char = 0;
                char temp = 0;
                if (i < size()) {
-                       previous_char = getChar(i);
+                       previous_char = getChar(i);
                        if (!isNewline(i)) {
                                ++i;
                                while (i < size() && previous_char != ' ') {
@@ -1345,7 +1345,7 @@ string const Paragraph::asString(Buffer const * buffer,
                value_type const c = getUChar(buffer->params, i);
                if (IsPrintable(c))
                        os << c;
-               else if (c == META_INSET) 
+               else if (c == META_INSET)
                        getInset(i)->ascii(buffer, os);
        }
 
@@ -1358,7 +1358,7 @@ void Paragraph::setInsetOwner(Inset * i)
        pimpl_->inset_owner = i;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
-       for (; it != end; ++it) 
+       for (; it != end; ++it)
                if (it.getInset())
                        it.getInset()->setOwner(i);
 }
index fd47d46e8a45c5017ae98c9aaeae81b3a85d214d..63c72b8130f81da839c240eb8eddfb25b7997ec3 100644 (file)
@@ -252,12 +252,14 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
 
 Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
 {
-       // This is in the critical path for loading!
-       pos_type const siz = size();
-       lyx::Assert(pos <= siz);
+       //lyx::Assert(pos <= siz);
        // This is stronger, and I belive that this is the assertion
        // that we should really use. (Lgb)
-       //Assert(pos < size());
+       lyx::Assert(pos < size());
+
+#if 0
+       // This is in the critical path for loading!
+       pos_type const siz = size();
 
        // Then this has no meaning. (Lgb)
        if (!siz || pos == siz) {
@@ -266,7 +268,7 @@ Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
                        << "  is a bit silly !" << endl;
                return '\0';
        }
-
+#endif
        return text[pos];
 }
 
index 0f37a206d5554d468570a152756402d29530f7b4..99e4b04b249c8351c4223f11a36f34fb4146c69a 100644 (file)
@@ -312,7 +312,8 @@ bool RowPainter::paintBackground()
        Inset const * inset = 0;
 
        if (!bv_.screen().forceClear() && last == row_.pos()
-               && par_.isInset(row_.pos())) {
+           && row_.pos() < par_.size()
+           && par_.isInset(row_.pos())) {
                inset = par_.getInset(row_.pos());
                clear_area = inset->doClearArea();
        }
@@ -898,6 +899,11 @@ bool RowPainter::paintText()
                        break;
                pos_type pos = text_.vis2log(vpos);
 
+               if (pos >= par_.size()) {
+                       ++vpos;
+                       continue;
+               }
+
                if (x_ + singleWidth(pos) < 0) {
                        x_ += singleWidth(pos);
                        ++vpos;
index 8110f198af573f780d54fed419324f6acf0da9f7..9769d34b02b6e46edf0eac7733be4343015f3196 100644 (file)
@@ -62,7 +62,7 @@ int LyXText::top_y() const
 {
        if (!top_row_)
                return 0;
-       
+
        int y = 0;
        for (Row * row = firstrow; row && row != top_row_; row = row->next()) {
                y += row->height();
@@ -76,7 +76,7 @@ void LyXText::top_y(int newy)
        if (!firstrow)
                return;
        lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
-       
+
        int y = newy;
        top_row_ = getRowNearY(y);
        top_row_offset_ = newy - y;
@@ -206,6 +206,9 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
 int LyXText::singleWidth(BufferView * bview, Paragraph * par,
                         pos_type pos) const
 {
+       if (pos >= par->size())
+               return 0;
+
        char const c = par->getChar(pos);
        return singleWidth(bview, par, pos, c);
 }
@@ -214,6 +217,9 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 int LyXText::singleWidth(BufferView * bview, Paragraph * par,
                         pos_type pos, char c) const
 {
+       if (pos >= par->size())
+               return 0;
+
        LyXFont const font = getFont(bview->buffer(), par, pos);
 
        // The most common case is handled first (Asger)
@@ -422,10 +428,12 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
 int LyXText::leftMargin(BufferView * bview, Row const * row) const
 {
        Inset * ins;
-       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
-               (ins=row->par()->getInset(row->pos())) &&
-               (ins->needFullRow() || ins->display()))
-               return LEFT_MARGIN;
+
+       if (row->pos() < row->par()->size())
+               if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+                   (ins = row->par()->getInset(row->pos())) &&
+                   (ins->needFullRow() || ins->display()))
+                       return LEFT_MARGIN;
 
        LyXTextClass const & tclass =
                bview->buffer()->params.getLyXTextClass();
@@ -615,10 +623,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
 {
        Inset * ins;
-       if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
-               (ins=row.par()->getInset(row.pos())) &&
-               (ins->needFullRow() || ins->display()))
-               return PAPER_MARGIN;
+
+       if (row.pos() < row.par()->size())
+               if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
+                   (ins=row.par()->getInset(row.pos())) &&
+                   (ins->needFullRow() || ins->display()))
+                       return PAPER_MARGIN;
 
        LyXTextClass const & tclass = buf.params.getLyXTextClass();
        LyXLayout_ptr const & layout = row.par()->layout();
@@ -722,7 +732,9 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
        pos_type const body_pos = par->beginningOfBody();
        pos_type const last = par->size();
        pos_type point = last;
-       pos_type i = pos;
+
+       if (pos == last)
+               return last;
 
        // Now we iterate through until we reach the right margin
        // or the end of the par, then choose the possible break
@@ -734,7 +746,8 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
        // pixel width since last breakpoint
        int chunkwidth = 0;
 
-       for (i = pos; i < last; ++i) {
+       pos_type i = pos;
+       for (; i < last; ++i) {
 
                if (par->isNewline(i)) {
                        point = i;
@@ -795,7 +808,7 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
 
                if (!display)
                        continue;
-                       
+
                // full row insets start at a new row
                if (i == pos) {
                        if (pos < last - 1) {
@@ -976,7 +989,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
        int maxwidth = 0;
 
        // Check if any insets are larger
-       for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
+       for (pos_type pos = row->pos(); pos < pos_end; ++pos) {
                if (row->par()->isInset(pos)) {
                        tmpfont = getFont(bview->buffer(), row->par(), pos);
                        tmpinset = row->par()->getInset(pos);
@@ -1592,9 +1605,10 @@ void LyXText::insertChar(BufferView * bview, char c)
                        return;
                }
        }
-       
+
        // the display inset stuff
-       if (cursor.row()->par()->isInset(cursor.row()->pos())) {
+       if (cursor.row()->pos() < cursor.row()->par()->size()
+           && cursor.row()->par()->isInset(cursor.row()->pos())) {
                Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
                if (inset && (inset->display() || inset->needFullRow())) {
                        // force a new break
@@ -1787,7 +1801,7 @@ void LyXText::prepareToPrint(BufferView * bview,
                // is empty.
                if (!row->par()->empty())
                        ++nlh;
-                       
+
                if (nlh && !row->par()->getLabelWidthString().empty()) {
                        fill_label_hfill = labelFill(*bview, *row) / nlh;
                }
@@ -1814,8 +1828,9 @@ void LyXText::prepareToPrint(BufferView * bview,
 
                // center displayed insets
                Inset * inset;
-               if (row->par()->isInset(row->pos())
-                   && (inset=row->par()->getInset(row->pos()))
+               if (row->pos() < row->par()->size()
+                   && row->par()->isInset(row->pos())
+                   && (inset = row->par()->getInset(row->pos()))
                    && (inset->display())) // || (inset->scroll() < 0)))
                    align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
                        ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
@@ -1991,7 +2006,7 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
                // Move cursor to the beginning, when not already there.
                if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
                    && !(from.par()->isKomma(from.pos() - 1)
-                        || from.par()->isNewline(from.pos() - 1)))
+                        || from.par()->isNewline(from.pos() - 1)))
                        cursorLeftOneWord(from);
                break;
        case PREVIOUS_WORD:
index baf28126b08815f2159b4ca967de8b71628553fd..10fc7e03d723c0031b32610d8f277ce39e5e6c7b 100644 (file)
@@ -52,7 +52,7 @@ using lyx::pos_type;
 
 
 LyXText::LyXText(BufferView * bv)
-       : height(0), width(0), top_row_(0), top_row_offset_(0), 
+       : height(0), width(0), top_row_(0), top_row_offset_(0),
          inset_owner(0), the_locking_inset(0), need_break_row(0),
          refresh_y(0), refresh_row(0), bv_owner(bv),
          status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
@@ -60,7 +60,7 @@ LyXText::LyXText(BufferView * bv)
 
 
 LyXText::LyXText(InsetText * inset)
-       : height(0), width(0), top_row_(0), top_row_offset_(0), 
+       : height(0), width(0), top_row_(0), top_row_offset_(0),
          inset_owner(inset), the_locking_inset(0), need_break_row(0),
          refresh_y(0), refresh_row(0), bv_owner(0),
          status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
@@ -1769,8 +1769,9 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        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()))
+               (ins = par->getInset(pos)) && (ins->needFullRow() || ins->display()))
        {
                row = row->previous();
                y -= row->height();
@@ -1786,13 +1787,16 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
 
        // 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);
        }