From 7c67a37f5301a8238ea631de86053ce85b198561 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Wed, 5 Oct 2005 21:19:32 +0000 Subject: [PATCH] fix bug 2060 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10525 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 8 ++++++++ src/mathed/math_macro.C | 26 ++++++++++++++++++++++++++ src/mathed/math_macro.h | 8 +++++++- src/mathed/math_nestinset.C | 5 ++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 6159a539d1..37ef546e50 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,11 @@ +2005-10-04 Georg Baum + + * 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 * math_nestinset.C (doDispatch): do not leave the inset after diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 096acf8a58..12682fad5e 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -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(); diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 2a3637578f..6afbab1b3f 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -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_; }; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 7605b0cfd9..d9313471af 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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); -- 2.39.2