]> git.lyx.org Git - features.git/commitdiff
several small fixes for mathed
authorAndré Pönitz <poenitz@gmx.net>
Tue, 6 Apr 2004 19:25:39 +0000 (19:25 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 6 Apr 2004 19:25:39 +0000 (19:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8614 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/mathed/formulamacro.C
src/mathed/math_amsarrayinset.C
src/mathed/math_arrayinset.C
src/mathed/math_commentinset.C
src/mathed/math_data.C
src/mathed/math_data.h
src/mathed/math_factory.C
src/mathed/math_factory.h
src/mathed/math_gridinset.C
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_macrotemplate.C
src/mathed/math_nestinset.C
src/mathed/math_substackinset.C

index adbd153a8984e8c27e1cef524e38c1cf6d221bc8..9d72784403c8fc73e1f80c2abf2024dadd2d50d9 100644 (file)
@@ -77,7 +77,7 @@ void InsetFormulaMacro::write(Buffer const &, ostream & os) const
 int InsetFormulaMacro::latex(Buffer const &, ostream & os,
                             OutputParams const & runparams) const
 {
-       lyxerr << "InsetFormulaMacro::latex" << endl;
+       //lyxerr << "InsetFormulaMacro::latex" << endl;
        WriteStream wi(os, runparams.moving_arg, true);
        tmpl()->write(wi);
        return 2;
@@ -129,6 +129,7 @@ string InsetFormulaMacro::prefix() const
 
 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       //lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl;
        tmpl()->metrics(mi, dim);
        dim.asc += 5;
        dim.des += 5;
index 1287d99a3f533e42ade65a6270fea7ae9e0c3bfc..561faa224871b1071f0dd979af68d64d9a6fdfdf 100644 (file)
@@ -73,9 +73,9 @@ void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
        MetricsInfo m = mi;
        if (m.base.style == LM_ST_DISPLAY)
                m.base.style = LM_ST_TEXT;
-       MathGridInset::metrics(m);
-       dim_.wid += 12;
-       dim = dim_;
+       MathGridInset::metrics(m, dim);
+       dim.wid += 12;
+       dim_ = dim;
 }
 
 
index 5794ee791354f4dce9325385e3fb74559ceb0054..1520ec5385fcb97d2905962345dba18aff5121ba 100644 (file)
@@ -78,9 +78,7 @@ auto_ptr<InsetBase> MathArrayInset::clone() const
 void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        ArrayChanger dummy(mi.base);
-       MathGridInset::metrics(mi);
-       metricsMarkers2(dim_);
-       dim = dim_;
+       MathGridInset::metrics(mi, dim);
 }
 
 
@@ -88,7 +86,6 @@ void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
 {
        ArrayChanger dummy(pi.base);
        MathGridInset::draw(pi, x + 1, y);
-       drawMarkers2(pi, x, y);
 }
 
 
index 232710c83ccd67d2b5ed7b2ce1a8921368df02e2..0d82240115b5cfaf26b62020e601fc85c537d308 100644 (file)
@@ -40,9 +40,9 @@ auto_ptr<InsetBase> MathCommentInset::clone() const
 
 void MathCommentInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       cell(0).metrics(mi);
-       metricsMarkers(dim_);
-       dim = dim_;
+       cell(0).metrics(mi, dim);
+       metricsMarkers(dim);
+       dim_ = dim;
 }
 
 
index 7617621047e771cd031f7eaa09e28b1375f5cda7..e684db565015d079d2beae584ad219d86fb2ad3d 100644 (file)
@@ -264,6 +264,7 @@ void MathArray::draw(PainterInfo & pi, int x, int y) const
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
                //pi.width = it->width_;
+               (*it)->drawSelection(pi, x, y);
                (*it)->draw(pi, x, y);
                x += (*it)->width();
        }
@@ -406,33 +407,3 @@ void MathArray::setXY(int x, int y) const
        xo_ = x;
        yo_ = y;
 }
-
-
-void MathArray::notifyCursorLeaves()
-{
-       // do not recurse!
-
-/*
-       // remove base-only "scripts"
-       for (pos_type i = 0; i + 1 < size(); ++i) {
-               MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
-               if (p && p->cell(0).empty() && p->cell(1).empty()) {
-                       MathArray ar = p->nuc();
-                       erase(i);
-                       insert(i, ar);
-                       mathcursor->adjust(i, ar.size() - 1);
-               }
-       }
-
-       // glue adjacent font insets of the same kind
-       for (pos_type i = 0; i + 1 < size(); ++i) {
-               MathFontInset * p = operator[](i).nucleus()->asFontInset();
-               MathFontInset const * q = operator[](i + 1)->asFontInset();
-               if (p && q && p->name() == q->name()) {
-                       p->cell(0).append(q->cell(0));
-                       erase(i + 1);
-                       mathcursor->adjust(i, -1);
-               }
-       }
-*/
-}
index 87ed99c495595460905eaa7ebd18614e29cbe924..89c116cce35fa48b94458f7d6d17350092c99095 100644 (file)
@@ -154,8 +154,6 @@ public:
        void center(int & x, int & y) const;
        /// adjust (x,y) to point on boundary on a straight line from the center
        void towards(int & x, int & y) const;
-       /// clean up if necessary
-       void notifyCursorLeaves();
 
 private:
        /// is this an exact match at this position?
index dbf0223d3d452a2278f6046b999b99385abc43c8..cc76614ab5e029c211a3ab5902fb989d929f50fa 100644 (file)
 
 #include "debug.h"
 #include "math_support.h"
+
 #include "support/std_sstream.h"
 #include "support/filetools.h" // LibFileSearch
 #include "support/lstrings.h"
+
 #include "frontends/lyx_gui.h"
 
 #include <fstream>
index 6ff6af41bd69b5f7a492c560d8123d56b5f6ca20..e5aac336b02166743fb7ad999419cd5a4f0852a1 100644 (file)
 #ifndef MATH_FACTORY_H
 #define MATH_FACTORY_H
 
-
 #include <string>
 
-
 class MathAtom;
 class MathArray;
 
+
 MathAtom createMathInset(std::string const &);
 
 /** Fills ar with the contents of str.
index 230c80144c1d405fe59659a55bf9525a302c3a62..e93297b9ae34af0a878be7a7d429e566dc8fa76b 100644 (file)
@@ -458,6 +458,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                cxrow->setBaseline(cxrow->getBaseline() - ascent);
        }
 */
+       metricsMarkers2(dim_);
 }
 
 
@@ -490,6 +491,7 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const
                                     xx, y + dim_.descent() - 1,
                                     LColor::foreground);
                }
+       drawMarkers2(pi, x, y);
 }
 
 
index 3cb51fbbbd47a399e594c2018c5c775589edbc9f..4be4d7497493e923b1587e81060ad611221381a6 100644 (file)
@@ -224,8 +224,6 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = max(dim.asc, asc);
        dim.des = max(dim.des, des);
 
-       // for markers
-       metricsMarkers2(dim);
        dim_ = dim;
 }
 
@@ -244,8 +242,6 @@ void MathHullInset::draw(PainterInfo & pi, int x, int y) const
                        drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
                }
        }
-
-       drawMarkers2(pi, x, y);
 }
 
 
@@ -787,7 +783,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
 
 void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
-       //lyxerr << "*** MathHullInset: request: " << cmd << endl;
+       lyxerr << "*** MathHullInset: request: " << cmd << endl;
        switch (cmd.action) {
 
        case LFUN_BREAKLINE:
@@ -796,10 +792,10 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.idx() = 1;
                        cur.pos() = 0;
                        //cur.dispatched(FINISHED);
-                       return;
+                       break;
                }
                MathGridInset::priv_dispatch(cur, cmd);
-               return;
+               break;
 
        case LFUN_MATH_NUMBER:
                //lyxerr << "toggling all numbers" << endl;
@@ -813,7 +809,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                                        numbered(row, !old);
                        cur.message(old ? _("No number") : _("Number"));
                }
-               return;
+               break;
 
        case LFUN_MATH_NONUMBER:
                if (display()) {
@@ -823,7 +819,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.message(old ? _("No number") : _("Number"));
                        numbered(r, !old);
                }
-               return;
+               break;
 
        case LFUN_INSERT_LABEL: {
                row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
@@ -842,13 +838,13 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                if (!new_label.empty())
                        numbered(r, true);
                label(r, new_label);
-               return;
+               break;
        }
 
        case LFUN_MATH_EXTERN:
                doExtern(cur, cmd);
                //cur.dispatched(FINISHED);
-               return;
+               break;
 
        case LFUN_MATH_MUTATE: {
                lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
@@ -863,7 +859,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                if (cur.pos() > cur.lastpos())
                        cur.pos() = cur.lastpos();
                //cur.dispatched(FINISHED);
-               return;
+               break;
        }
 
        case LFUN_MATH_DISPLAY: {
@@ -871,12 +867,31 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                cur.idx() = 0;
                cur.pos() = cur.lastpos();
                //cur.dispatched(FINISHED);
-               return;
+               break;
        }
 
        default:
                MathGridInset::priv_dispatch(cur, cmd);
-               return;
+               break;
+       }
+}
+
+
+bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+       case LFUN_BREAKLINE:
+       case LFUN_MATH_NUMBER:
+       case LFUN_MATH_NONUMBER:
+       case LFUN_INSERT_LABEL:
+       case LFUN_MATH_EXTERN:
+       case LFUN_MATH_MUTATE:
+       case LFUN_MATH_DISPLAY:
+               // we handle these
+               return true;
+       default:
+               return MathGridInset::getStatus(cur, cmd, flag);
        }
 }
 
@@ -960,6 +975,13 @@ void MathHullInset::handleFont2(LCursor & cur, string const & arg)
 }
 
 
+void MathHullInset::edit(LCursor & cur, bool left)
+{
+       lyxerr << "MathHullInset: edit left/right" << endl;
+       cur.push(*this);
+}
+
+
 string const MathHullInset::editMessage() const
 {
        return _("Math editor mode");
index 8981910fb524cfbe98398271a1b7f9ce48f1f098..f8ac234db34917286632114dcc6d04c0526f3e14 100644 (file)
@@ -118,6 +118,9 @@ public:
 protected:
        ///
        void priv_dispatch(LCursor & cur, FuncRequest & cmd);
+       /// do we want to handle this event?
+       bool getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & status) const;
        ///
        std::string eolString(row_type row, bool fragile) const;
 
@@ -177,6 +180,8 @@ public:
        ///
        virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
        ///
+       void edit(LCursor & cur, bool left);
+       ///
        bool display() const;
        ///
        Code lyxCode() const;
index 0d25b777168dfba54a2811d7d8a1aa580f14a6aa..a8ce515c52a308770a62787ad26b4834a296f60f 100644 (file)
@@ -51,13 +51,6 @@ void MathInset::dump() const
 }
 
 
-void MathInset::drawSelection(PainterInfo &,
-       idx_type, pos_type, idx_type, pos_type) const
-{
-       lyxerr << "MathInset::drawSelection() called directly!" << endl;
-}
-
-
 void MathInset::metricsT(TextMetricsInfo const &, Dimension &) const
 {
 #ifdef WITH_WARNINGS
index 36ee2b1ac672c1430aec5e6bcd349cc71ab030be..11716f1382e53d6c238c4e9c7682b6fa4346313c 100644 (file)
@@ -82,9 +82,6 @@ public:
 
        /// substitutes macro arguments if necessary
        virtual void substitute(MathMacro const & macro);
-       /// draw selection between two positions
-       virtual void drawSelection(PainterInfo & pi,
-               idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
        /// the ascent of the inset above the baseline
        /// compute the size of the object for text based drawing
        virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
index eba161e677a7545d587b2433ea7610b7553b0d2e..98b792fbc2c1a7b0f98c82e9ac595400103f692f 100644 (file)
@@ -55,8 +55,8 @@ string MathMacro::name() const
 
 bool MathMacro::defining() const
 {
-       return 0;
-       //return mathcursor && mathcursor->formula()->getInsetName() == name();
+       return false;
+       //return mathcursor->formula()->getInsetName() == name();
 }
 
 
@@ -78,7 +78,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
        } else if (editing(mi.base.bv)) {
 
                expand();
-               expanded_.metrics(mi_, dim);
+               expanded_.metrics(mi, dim);
                metricsMarkers(dim);
 
                dim.wid += mathed_string_width(font_, name()) + 10;
@@ -87,17 +87,16 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 
                for (idx_type i = 0; i < nargs(); ++i) {
                        MathArray const & c = cell(i);
-                       c.metrics(mi_);
+                       c.metrics(mi);
                        dim.wid  = max(dim.wid, c.width() + ww);
-                       dim.des += max(c.ascent(),  dim.asc) + 5;
-                       dim.des += max(c.descent(), dim.des) + 5;
+                       dim.des += c.height() + 10;
                }
 
        } else {
 
                expand();
                expanded_.substitute(*this);
-               expanded_.metrics(mi_, dim);
+               expanded_.metrics(mi, dim);
 
        }
 
index 90e0e49ac045e339d1b137d85959527a1fd38ef2..30290a466ce7adafba5b29b963e0e31758465e0f 100644 (file)
 #include "debug.h"
 #include "LColor.h"
 
-
 using std::string;
 using std::auto_ptr;
 using std::endl;
 
 
+
 MathMacroTemplate::MathMacroTemplate()
        : MathNestInset(2), numargs_(0), name_(), type_("newcommand")
 {}
@@ -81,6 +81,7 @@ string MathMacroTemplate::name() const
 
 void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       lyxerr << "drawing template " << name() << ' ' << this << std::endl;
        cell(0).metrics(mi);
        cell(1).metrics(mi);
        dim.wid = cell(0).width() + cell(1).width() + 10;
index 704685389c6b83fa8910e77bdeb83e1359a732af..0a9fd568747933be7fc54c4bb2fbc62c713eb45c 100644 (file)
@@ -194,6 +194,8 @@ void MathNestInset::draw(PainterInfo &, int, int) const
 
 void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
 {
+       //lyxerr << "MathNestInset::drawing selection: "
+       //      << " x: " << x << " y: " << y << endl;
        // this should use the x/y values given, not the cached values
        LCursor & cur = pi.base.bv->cursor();
        if (!cur.selection())
@@ -202,6 +204,8 @@ void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
                return;
        CursorSlice s1 = cur.selBegin();
        CursorSlice s2 = cur.selEnd();
+       lyxerr << "MathNestInset::drawing selection: "
+               << " s1: " << s1 << " s2: " << s2 << endl; 
        if (s1.idx() == s2.idx()) {
                MathArray const & c = cell(s1.idx());
                int x1 = c.xo() + c.pos2x(s1.pos());
index ce15a19a4887800ca0689bb1ef9d805fdf9ae6fe..696a9986e9559d52964832ff468127a53d71f6bc 100644 (file)
@@ -37,7 +37,6 @@ void MathSubstackInset::metrics(MetricsInfo & mi, Dimension & dim) const
        } else {
                MathGridInset::metrics(mi, dim);
        }
-       metricsMarkers(dim);
        dim_ = dim;
 }
 
@@ -45,7 +44,6 @@ void MathSubstackInset::metrics(MetricsInfo & mi, Dimension & dim) const
 void MathSubstackInset::draw(PainterInfo & pi, int x, int y) const
 {
        MathGridInset::draw(pi, x + 1, y);
-       drawMarkers(pi, x, y);
 }