]> git.lyx.org Git - features.git/commitdiff
fix bug 2060
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 5 Oct 2005 21:19:32 +0000 (21:19 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 5 Oct 2005 21:19:32 +0000 (21:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10525 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_nestinset.C

index 6159a539d120b0576e3ee871f66881ee201e8b23..37ef546e50f291797d012591a8024a48b0803d37 100644 (file)
@@ -1,3 +1,11 @@
+2005-10-04  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * math_macro.C (editXY): new, fix crash (bug 2060)
+       * math_macro.C (cursorPos): new, fix potential crash
+       * math_macro.C (drawSelection): new, fix potential crash
+       * math_nestinset.C (doDispatch): fix crash when inserting math macros
+       with 0 arguments
+
 2005-09-30  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * math_nestinset.C (doDispatch): do not leave the inset after
index 096acf8a58bf34f96723158a2eb29fe499d5ddd8..12682fad5e391246de35a4a7bf118f9796953278 100644 (file)
@@ -46,6 +46,15 @@ string MathMacro::name() const
 }
 
 
+void MathMacro::cursorPos(CursorSlice const & sl, bool boundary, int & x,
+               int & y) const
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0)
+               MathNestInset::cursorPos(sl, boundary, x, y);
+}
+
+
 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        if (!MacroTable::globalMacros().has(name())) {
@@ -102,6 +111,14 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0)
+               MathNestInset::drawSelection(pi, x, y);
+}
+
+
 void MathMacro::validate(LaTeXFeatures & features) const
 {
        if (name() == "binom" || name() == "mathcircumflex")
@@ -109,6 +126,15 @@ void MathMacro::validate(LaTeXFeatures & features) const
 }
 
 
+InsetBase * MathMacro::editXY(LCursor & cur, int x, int y)
+{
+       // We may have 0 arguments, but MathNestInset requires at least one.
+       if (nargs() > 0)
+               return MathNestInset::editXY(cur, x, y);
+       return this;
+}
+
+
 void MathMacro::maple(MapleStream & os) const
 {
        updateExpansion();
index 2a3637578f4bf3f26b8b86ea8080d0de97065441..6afbab1b3f620009c3147029d671a5a12c9ebe9d 100644 (file)
@@ -28,8 +28,14 @@ public:
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        void drawExpanded(PainterInfo & pi, int x, int y) const;
+       /// draw selection background
+       void drawSelection(PainterInfo & pi, int x, int y) const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
+       /// get cursor position
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
+       ///
+       InsetBase * editXY(LCursor & cur, int x, int y);
        ///
        std::string name() const;
        ///
@@ -60,7 +66,7 @@ private:
        std::string name_;
        /// the unexpanded macro defintition
        mutable MathArray tmpl_;
-       /// the matcro substituted with our args
+       /// the macro substituted with our args
        mutable MathArray expanded_;
 };
 
index 7605b0cfd9465fa57c6cea5de95ab6cd45130c77..d9313471afa7e9c15090e123d95916cb644b8b12 100644 (file)
@@ -859,7 +859,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                int cell(0);
                if (cmd.argument == "\\root")
                        cell = 1;
-               if (ar.size() == 1 && (ar[0].nucleus()->asNestInset())) {
+               // math macros are nest insets and may have 0 cells.
+               // handleNest would crash in this case.
+               if (ar.size() == 1 && (ar[0].nucleus()->asNestInset()) &&
+                   ar[0].nucleus()->nargs() > cell) {
                        cur.handleNest(ar[0], cell);
                } else
                        cur.niceInsert(cmd.argument);