]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
do not create invalid .lyx files when importing \i{}, \j{}, \l{} or \L{}.
[lyx.git] / src / text2.C
index b5883f3ba676609d77f95ffb282114e54ea15d69..0947c0303bfd62aa3b3458d2f19deec71822c39f 100644 (file)
@@ -102,7 +102,7 @@ bool LyXText::isMainText(Buffer const & buffer) const
 
 
 //takes screen x,y coordinates
-InsetBase * LyXText::checkInsetHit(BufferView const & bv, int x, int y) const
+InsetBase * LyXText::checkInsetHit(BufferView & bv, int x, int y)
 {
        pit_type pit = getPitNearY(bv, y);
        BOOST_ASSERT(pit != -1);
@@ -352,7 +352,7 @@ void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end,
        for (pit_type pit = start; pit != end; ++pit) {
                pars_[pit].applyLayout(lyxlayout);
                if (lyxlayout->margintype == MARGIN_MANUAL)
-                       pars_[pit].setLabelWidthString(lyxlayout->labelstring());
+                       pars_[pit].setLabelWidthString(buffer.translateLabel(lyxlayout->labelstring()));
        }
 }
 
@@ -576,7 +576,7 @@ void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
 }
 
 
-string LyXText::getStringToIndex(LCursor const & cur)
+docstring LyXText::getStringToIndex(LCursor const & cur)
 {
        BOOST_ASSERT(this == cur.text());
 
@@ -598,13 +598,13 @@ string LyXText::getStringToIndex(LCursor const & cur)
                        idxstring = tmpcur.selectionAsString(false);
        }
 
-       return to_utf8(idxstring);
+       return idxstring;
 }
 
 
 void LyXText::setParagraph(LCursor & cur,
                           Spacing const & spacing, LyXAlignment align,
-                          string const & labelwidthstring, bool noindent)
+                          docstring const & labelwidthstring, bool noindent)
 {
        BOOST_ASSERT(cur.text());
        // make sure that the depth behind the selection are restored, too
@@ -628,8 +628,7 @@ void LyXText::setParagraph(LCursor & cur,
                        else
                                params.align(align);
                }
-               // FIXME UNICODE
-               par.setLabelWidthString(from_ascii(labelwidthstring));
+               par.setLabelWidthString(labelwidthstring);
                params.noindent(noindent);
        }
 }
@@ -905,7 +904,7 @@ pos_type LyXText::getColumnNearX(BufferView const & bv, pit_type const pit,
 
 
 // y is screen coordinate
-pit_type LyXText::getPitNearY(BufferView const & bv, int y) const
+pit_type LyXText::getPitNearY(BufferView & bv, int y)
 {
        BOOST_ASSERT(!paragraphs().empty());
        BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end());
@@ -920,6 +919,40 @@ pit_type LyXText::getPitNearY(BufferView const & bv, int y) const
        int yy = -1;
        CoordCache::InnerParPosCache::const_iterator it = cc.begin();
        CoordCache::InnerParPosCache::const_iterator et = cc.end();
+       CoordCache::InnerParPosCache::const_iterator last = et; last--;
+
+       // If we are off-screen (before the visible part)
+       if (y < 0
+               // and even before the first paragraph in the cache.
+               && y < it->second.y_ - int(pars_[it->first].ascent())) {
+               //  and we are not at the first paragraph in the inset.
+               if (it->first == 0)
+                       return 0;
+               // then this is the paragraph we are looking for.
+               pit = it->first - 1;
+               // rebreak it and update the CoordCache.
+               redoParagraph(bv, pit);
+               bv.coordCache().parPos()[this][pit] =
+                       Point(0, it->second.y_ - pars_[it->first].descent());
+               return pit;
+       }
+
+       // If we are off-screen (after the visible part)
+       if (y > bv.workHeight()
+               // and even after the first paragraph in the cache.
+               && y >= last->second.y_ + int(pars_[last->first].descent())) {
+               pit = last->first + 1;
+               //  and we are not at the last paragraph in the inset.
+               if (pit == pars_.size())
+                       return last->first;
+               // then this is the paragraph we are looking for.
+               // rebreak it and update the CoordCache.
+               redoParagraph(bv, pit);
+               bv.coordCache().parPos()[this][pit] =
+                       Point(0, last->second.y_ + pars_[last->first].ascent());
+               return pit;
+       }
+
        for (; it != et; ++it) {
                lyxerr[Debug::DEBUG]
                        << BOOST_CURRENT_FUNCTION
@@ -970,7 +1003,8 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
        bool bound = false;
 
        int xx = x; // is modified by getColumnNearX
-       pos_type const pos = row.pos() + getColumnNearX(cur.bv(), pit, row, xx, bound);
+       pos_type const pos = row.pos()
+               + getColumnNearX(cur.bv(), pit, row, xx, bound);
        cur.pit() = pit;
        cur.pos() = pos;
        cur.boundary(bound);
@@ -986,18 +1020,22 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
                return 0;
        }
 
+       InsetBase * insetBefore = pos? pars_[pit].getInset(pos - 1): 0;
+       //InsetBase * insetBehind = pars_[pit].getInset(pos);
+
        // This should be just before or just behind the
        // cursor position set above.
-        InsetBase * inset2 = pars_[pit].getInset(pos - 1);
-        InsetBase * inset3 = pars_[pit].getInset(pos);
-        
-       BOOST_ASSERT((pos != 0 && inset == inset2)
-                    || inset == inset3);
+       BOOST_ASSERT((pos != 0 && inset == insetBefore)
+               || inset == pars_[pit].getInset(pos));
+
        // Make sure the cursor points to the position before
        // this inset.
-       if (inset == pars_[pit].getInset(pos - 1))
+       if (inset == insetBefore)
                --cur.pos();
+
+       // Try to descend recursively inside the inset.
        inset = inset->editXY(cur, x, y);
+
        if (cur.top().text() == this)
                setCurrentFont(cur);
        return inset;
@@ -1020,6 +1058,9 @@ bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
 
 bool LyXText::cursorLeft(LCursor & cur)
 {
+       // Tell BufferView to test for FitCursor in any case!
+       cur.updateFlags(Update::FitCursor);
+
        if (!cur.boundary() && cur.pos() > 0 &&
            cur.textRow().pos() == cur.pos() &&
            !cur.paragraph().isLineSeparator(cur.pos()-1) &&
@@ -1048,6 +1089,9 @@ bool LyXText::cursorLeft(LCursor & cur)
 
 bool LyXText::cursorRight(LCursor & cur)
 {
+       // Tell BufferView to test for FitCursor in any case!
+       cur.updateFlags(Update::FitCursor);
+
        if (cur.pos() != cur.lastpos()) {
                if (cur.boundary())
                        return setCursor(cur, cur.pit(), cur.pos(),
@@ -1077,6 +1121,9 @@ bool LyXText::cursorRight(LCursor & cur)
 
 bool LyXText::cursorUp(LCursor & cur)
 {
+       // Tell BufferView to test for FitCursor in any case!
+       cur.updateFlags(Update::FitCursor);
+
        Paragraph const & par = cur.paragraph();
        int row;
        int const x = cur.targetX();
@@ -1126,6 +1173,9 @@ bool LyXText::cursorUp(LCursor & cur)
 
 bool LyXText::cursorDown(LCursor & cur)
 {
+       // Tell BufferView to test for FitCursor in any case!
+       cur.updateFlags(Update::FitCursor);
+
        Paragraph const & par = cur.paragraph();
        int row;
        int const x = cur.targetX();