]> git.lyx.org Git - features.git/commitdiff
This commit fixes a crash when accessing a math inset. This was due to an invalid...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 17 Oct 2006 16:23:27 +0000 (16:23 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 17 Oct 2006 16:23:27 +0000 (16:23 +0000)
    CoordCache & coord_cache = sl.text()->bv()->coordCache();

As you can see, I used this indirection to access the BufferView::CoordCache(). Bad luck, the passed CursorSlice was not completely valid inside a mathed inset, hence the crash. My solution is to pass BufferView to InsetBase::cursorPos() and all its derivative.

* InsetBase::cursorPos(): pass BufferView const &

* bufferview_funcs::coordOffset(): ditto.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15356 a592a061-630c-0410-9148-cb99ea01b6c8

21 files changed:
src/BufferView.C
src/bufferview_funcs.C
src/bufferview_funcs.h
src/cursor.C
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetcaption.C
src/insets/insetcaption.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/mathed/InsetMathMBox.C
src/mathed/InsetMathMBox.h
src/mathed/InsetMathMacro.C
src/mathed/InsetMathMacro.h
src/mathed/InsetMathNest.C
src/mathed/InsetMathNest.h
src/mathed/MathSupport.h

index e5e1678da8279c1490147d8a743574b9b03e9b1f..cc2afe0f325832cb0cbbbeacb80a514623a338d9 100644 (file)
@@ -608,7 +608,7 @@ void BufferView::center()
        bot.text()->redoParagraph(pit);
        Paragraph const & par = bot.text()->paragraphs()[pit];
        anchor_ref_ = pit;
-       offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
+       offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
                + par.ascent() - height_ / 2;
 }
 
index 1f0ff23106708bf5560c824ff8dc26c49bd46056..508f40e2775816aa6db4d4707d32d38305dd8c91 100644 (file)
@@ -156,7 +156,8 @@ bool string2font(string const & data, LyXFont & font, bool & toggle)
 // the next two should probably go elsewhere
 // this give the position relative to (0, baseline) of outermost
 // paragraph
-Point coordOffset(DocIterator const & dit, bool boundary)
+Point coordOffset(BufferView const & bv, DocIterator const & dit,
+               bool boundary)
 {
        int x = 0;
        int y = 0;
@@ -166,7 +167,7 @@ Point coordOffset(DocIterator const & dit, bool boundary)
                CursorSlice const & sl = dit[i];
                int xx = 0;
                int yy = 0;
-               sl.inset().cursorPos(sl, boundary && ((i+1) == dit.depth()), xx, yy);
+               sl.inset().cursorPos(bv, sl, boundary && ((i+1) == dit.depth()), xx, yy);
                x += xx;
                y += yy;
                //lyxerr << "LCursor::getPos, i: "
@@ -215,7 +216,7 @@ Point getPos(BufferView & bv, DocIterator const & dit, bool boundary)
                //lyxerr << "cursor out of view" << std::endl;
                return Point(-1, -1);
        }
-       Point p = coordOffset(dit, boundary); // offset from outer paragraph
+       Point p = coordOffset(bv, dit, boundary); // offset from outer paragraph
        p.y_ += it->second.y_;
        return p;
 }
index 66931166c4e08ae4adbae63fcebe3892795d7dfe..e4026ce7327fddd7964d0f5a5589020c1cca3a5e 100644 (file)
@@ -52,7 +52,7 @@ enum CurStatus {
 CurStatus status(BufferView const * bv, DocIterator const & dit);
 
 
-lyx::Point coordOffset(DocIterator const & dit, bool boundary);
+lyx::Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary);
 
 /// Moves cursor to the next inset with one of the given codes.
 void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes,
index 69ba63b19533b118d1dd109d0311998487b4d8ba..2583ab12a8c16260bcefc5d4bee87ad06cf6eae5 100644 (file)
@@ -101,7 +101,7 @@ namespace {
                        int yo;
                        InsetBase const * inset = &it.inset();
                        Point o = c.bv().coordCache().getInsets().xy(inset);
-                       inset->cursorPos(it.top(), c.boundary(), xo, yo);
+                       inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
                        // Convert to absolute
                        xo += o.x_;
                        yo += o.y_;
index 6f5453a2836b3e243f71115b4aeb0ef0656c63ef..8fe2477d24bd7549aef552c9eb4952f99ac05311 100644 (file)
@@ -269,7 +269,8 @@ void InsetBase::markErased(bool)
 {}
 
 
-void InsetBase::cursorPos(CursorSlice const &, bool, int & x, int & y) const
+void InsetBase::cursorPos(BufferView const & bv, CursorSlice const &,
+               bool, int & x, int & y) const
 {
        lyxerr << "InsetBase::cursorPos called directly" << std::endl;
        x = 100;
index 05a797909edd44331563e4aef9fdd865e2fe2180..3f99b98e6c32b31438567ae849233b9fa629ee69 100644 (file)
@@ -124,8 +124,8 @@ public:
        /// do we cover screen position x/y?
        virtual bool covers(BufferView & bv, int x, int y) const;
        /// get the screen positions of the cursor (see note in cursor.C)
-       virtual void cursorPos(CursorSlice const & sl, bool boundary,
-               int & x, int & y) const;
+       virtual void cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const;
 
        /// is this an inset that can be moved into?
        virtual bool isActive() const { return nargs() > 0; }
index 0638430c70ef38b89a57eacf2d9bd7af34ca6cd6..bf4c5c976e252efef95b81fffe2e950c4bcd0db5 100644 (file)
@@ -81,10 +81,10 @@ docstring const InsetCaption::editMessage() const
 }
 
 
-void InsetCaption::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetCaption::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       InsetText::cursorPos(sl, boundary, x, y);
+       InsetText::cursorPos(bv, sl, boundary, x, y);
        x += labelwidth_;
 }
 
index 3b57d832c80f986b1746dbe4de34effd3842bcc8..ab6d9711556321c4841d68c61222ff726cf8cca5 100644 (file)
@@ -35,8 +35,8 @@ public:
        ///
        virtual lyx::docstring const editMessage() const;
        ///
-       virtual void cursorPos
-               (CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       virtual void cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
        bool descendable() const { return true; }
        ///
index 16b0d68f75a24c847657ab0123893762a3bb14f8..a8bf0856aa1006440682ff1859e0e2dd54ce6660 100644 (file)
@@ -211,12 +211,12 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetCollapsable::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetCollapsable::cursorPos(BufferView const & bv, 
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        BOOST_ASSERT(status() != Collapsed);
 
-       InsetText::cursorPos(sl, boundary, x, y);
+       InsetText::cursorPos(bv, sl, boundary, x, y);
 
        if (status() == Open) {
                if (openinlined_)
index 880bfeacd9d4905ee0335572bb974faa9d6d5942..41a826a51c904cbcdb3b4ad19ce6fc1607b4fbc9 100644 (file)
@@ -55,7 +55,8 @@ public:
        ///
        void drawSelection(PainterInfo & pi, int x, int y) const;
        /// return x,y of given position relative to the inset's baseline
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
        ///
        bool hitButton(FuncRequest const &) const;
        ///
index 0ac3d57731101273b4ca8e2ef921e7de2c321e3d..df79c6718efd1e11ae5949b3c80142ac52d76394 100644 (file)
@@ -1117,10 +1117,10 @@ shared_ptr<InsetText> InsetTabular::cell(idx_type idx)
 }
 
 
-void InsetTabular::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetTabular::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       cell(sl.idx())->cursorPos(sl, boundary, x, y);
+       cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
 
        // y offset     correction
        int const row = tabular.row_of_cell(sl.idx());
index 2b77adc5a9d946646208ba813ed060b397e1c6e9..2c4505e1471f68ffd33df603ebe009f5a4924c58 100644 (file)
@@ -97,7 +97,8 @@ public:
        ///
        Code lyxCode() const { return InsetBase::TABULAR_CODE; }
        /// get offset of this cursor slice relative to our upper left corner
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
        ///
        bool tabularFeatures(LCursor & cur, std::string const & what);
        ///
index 33c041ce42139c8b53bf1e5f414e65a582fe978b..a926f315385ae895e90016cd85faf7ae85ee3faa 100644 (file)
@@ -301,8 +301,8 @@ void InsetText::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetText::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetText::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        x = text_.cursorX(sl, boundary) + border_;
        y = text_.cursorY(sl, boundary);
index 23f054e93b06d555ee3092a54a1249f11823e56e..d7d93eedf8d4a8f48e959f9a9ba1c44dafb72a8d 100644 (file)
@@ -73,7 +73,8 @@ public:
        void validate(LaTeXFeatures & features) const;
 
        /// return x,y of given position relative to the inset's baseline
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
        ///
        Code lyxCode() const { return TEXT_CODE; }
        ///
index 970ffc4a0667f1600c63c3687eac1121c1f9ee97..37ed78429df07bd4c4bf398ee7d1124d2df9d87e 100644 (file)
@@ -102,8 +102,8 @@ LyXText * InsetMathMBox::getText(int) const
 }
 
 
-void InsetMathMBox::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetMathMBox::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        x = text_.cursorX(sl, boundary);
        y = text_.cursorY(sl, boundary);
index 39fa6e996a64da3f903abd645d35dd68d6201295..305d88fd186204b91f91b44abecf7755fc2d61b9 100644 (file)
@@ -41,7 +41,8 @@ public:
        ///
        LyXText * getText(int) const;
        ///
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
 protected:
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
 
index efad92485d8fc8cf583f6c4d6443ce33f6602320..1bf8dadc39d102af019ce691bcc55d089e974a5b 100644 (file)
@@ -48,12 +48,12 @@ string MathMacro::name() const
 }
 
 
-void MathMacro::cursorPos(CursorSlice const & sl, bool boundary, int & x,
-               int & y) const
+void MathMacro::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        // We may have 0 arguments, but InsetMathNest requires at least one.
        if (nargs() > 0)
-               InsetMathNest::cursorPos(sl, boundary, x, y);
+               InsetMathNest::cursorPos(bv, sl, boundary, x, y);
 }
 
 
index 3c82d9ac24d907573e39ee921671ba2f8cb09cfb..02c097bfb2669e2ccab5ccea56a9b2410fb32e25 100644 (file)
@@ -33,7 +33,8 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        /// get cursor position
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
        ///
        InsetBase * editXY(LCursor & cur, int x, int y);
        ///
index e0e3e419a2efdbb88f84621a697897e2c1cfa895..37db10add0045cf1b2e5409ef9bbae070c74a1ab 100644 (file)
@@ -98,8 +98,9 @@ MathArray const & InsetMathNest::cell(idx_type i) const
 }
 
 
-void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
-       int & x, int & y) const
+void InsetMathNest::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool /*boundary*/,
+               int & x, int & y) const
 {
 // FIXME: This is a hack. Ideally, the coord cache should not store
 // absolute positions, but relative ones. This would mean to call
@@ -110,7 +111,7 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
 // absolute again when actually drawing the cursor. What a mess.
        BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
        MathArray const & ar = sl.cell();
-       CoordCache & coord_cache = sl.text()->bv()->coordCache();
+       CoordCache const & coord_cache = bv.coordCache();
        if (!coord_cache.getArrays().has(&ar)) {
                // this can (semi-)legally happen if we just created this cell
                // and it never has been drawn before. So don't ASSERT.
index 7790be0872eb18d909425240c367faca8cb5dc36..74908c31cf730537754249499bc3c2dd62f984df 100644 (file)
@@ -37,7 +37,8 @@ public:
        /// identifies NestInsets
        InsetMathNest const * asNestInset() const { return this; }
        /// get cursor position
-       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       void cursorPos(BufferView const & bv, CursorSlice const & sl,
+               bool boundary, int & x, int & y) const;
        ///
        void edit(LCursor & cur, bool left);
        ///
index 8b026fe434d4772a0f788a163214f22bf62d48f6..a10b938351dcc97a9944eb695493fd11ceb5b92d 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "support/docstring.h"
 
+#include <string>
+
 class PainterInfo;
 class LyXFont;
 class Dimension;