]> git.lyx.org Git - features.git/commitdiff
remove cursor::drawSelection() plus some math reorganization (move the
authorAndré Pönitz <poenitz@gmx.net>
Mon, 2 Feb 2004 17:32:56 +0000 (17:32 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 2 Feb 2004 17:32:56 +0000 (17:32 +0000)
'width' cache from MathAtom)

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

22 files changed:
src/BufferView_pimpl.C
src/cursor.C
src/cursor.h
src/frontends/screen.C
src/insets/inset.C
src/insets/insetbase.C
src/insets/insetbase.h
src/mathed/formulamacro.C
src/mathed/math_atom.h
src/mathed/math_charinset.C
src/mathed/math_charinset.h
src/mathed/math_data.C
src/mathed/math_diminset.C
src/mathed/math_diminset.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_textinset.C
src/mathed/math_textinset.h
src/rowpainter.C
src/undo.C

index 8b8b00989645cdc241dfaef419a36e9c76ed4c6b..af33f7c5930c03e41991cdc78a57329ada76cadc 100644 (file)
@@ -905,7 +905,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
                        res = bv_->text()->dispatch(cur, cmd);
                }
 
-               if (bv_->fitCursor() || res.update()) {
+               if (fitCursor() || res.update()) {
                        bv_->update();
                        cur.updatePos();
                }
@@ -947,7 +947,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
                // if it wishes to do so.
                DispatchResult res = cur.dispatch(cmd);
 
-               if (bv_->fitCursor() || res.update())
+               if (fitCursor() || res.update())
                        bv_->update();
 
                // see workAreaKeyPress
index 955d3084242cac94ae577e926f897e931de49198..5c74ebebb675e9ea0167709b22001fa966283691 100644 (file)
@@ -1179,16 +1179,6 @@ string LCursor::macroName()
 }
 
 
-void LCursor::drawSelection(PainterInfo & pi)
-{
-       if (!selection())
-               return;
-       CursorSlice i1 = selBegin();
-       CursorSlice i2 = selEnd();
-       i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
-}
-
-
 void LCursor::handleNest(MathAtom const & a, int c)
 {
        MathAtom t = a;
@@ -1510,6 +1500,7 @@ bool LCursor::idxRight()
 bool LCursor::script(bool up)
 {
        // Hack to get \\^ and \\_ working
+       lyxerr << "handling script: up: " << up << endl;
        if (inMacroMode() && macroName() == "\\") {
                if (up)
                        niceInsert(createMathInset("mathcircumflex"));
@@ -1533,8 +1524,7 @@ bool LCursor::script(bool up)
                pos() = lastpos();
        } else if (pos() != 0) {
                --pos();
-               cell()[pos()]
-                       = MathAtom(new MathScriptInset(nextAtom(), up));
+               cell()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
                push(inset());
                idx() = up;
                pos() = 0;
@@ -1553,7 +1543,7 @@ bool LCursor::script(bool up)
 
 bool LCursor::interpret(char c)
 {
-       //lyxerr << "interpret 2: '" << c << "'" << endl;
+       lyxerr << "interpret 2: '" << c << "'" << endl;
        clearTargetX();
        if (inMacroArgMode()) {
                posLeft();
index 68c257c793479496c2291ff2c8b9ec7b351a58f0..e4d1ebc2a1d27df87eb17d19d1740efaa483a424 100644 (file)
@@ -354,8 +354,6 @@ public:
        /// are we currently typing '#1' or '#2' or...?
        bool inMacroArgMode() const;
 
-       /// draws light-blue selection background
-       void drawSelection(PainterInfo & pi);
        /// replace selected stuff with at, placing the former
        // selection in given cell of atom
        void handleNest(MathAtom const & at, int cell = 0);
index 525b3912e1b9cc1918bce57711978f4a44358f3f..c921218cbb0dde5755708d6f9b405dbb45e54b12 100644 (file)
@@ -212,8 +212,8 @@ bool LyXScreen::fitCursor(BufferView * bv)
        int x, y, asc, desc;
 
        bv->cursor().getPos(x, y);
-       //lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
-       //      << "  top_y: " << top_y << endl;
+       lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
+               << "  top_y: " << top_y << endl;
        bv->cursor().getDim(asc, desc);
        
        bool const big_row = h / 4 < asc + desc && asc + desc < h;
index b61eafd076dc3dc6a31d6c55680f4a28ee57237d..b533f4de9279e3b9ef95252eecb91381eec08237 100644 (file)
@@ -89,6 +89,7 @@ int InsetOld::scroll(bool recursive) const
 
 void InsetOld::setPosCache(PainterInfo const &, int x, int y) const
 {
+       lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
        xo_ = x;
        yo_ = y;
 }
index 1bd6b65e37acdc4084f9d8a66f776faf1b60fc79..4a03ba732791c551156ad09e9c37c2fc9534edf6 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "insetbase.h"
 
+#include "buffer.h"
 #include "BufferView.h"
 #include "LColor.h"
 #include "cursor.h"
@@ -225,6 +226,13 @@ bool InsetBase::covers(int x, int y) const
 }
 
 
+void InsetBase::dump() const
+{
+       Buffer buf("foo", 1);
+       write(buf, lyxerr);
+}
+
+
 /////////////////////////////////////////
 
 bool isEditableInset(InsetBase const * inset)
index 23d390db455fd3c1b63c2aaf26e773817521b046..a8d458fa346c94a8ec99bcdead58bb176d372cab 100644 (file)
@@ -79,6 +79,8 @@ public:
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
        /// draw inset and update (xo, yo)-cache
        virtual void draw(PainterInfo & pi, int x, int y) const = 0;
+       /// draw inset selection if necessary
+       virtual void drawSelection(PainterInfo &, int, int) const {}
        ///
        virtual bool editing(BufferView * bv) const;
        /// draw four angular markers
@@ -322,6 +324,8 @@ public:
        virtual bool display() const { return false; }
        // should we break lines after this inset?
        virtual bool isLineSeparator() const { return false; }
+       /// dumps content to lyxerr
+       virtual void dump() const;
        ///
        virtual void write(Buffer const &, std::ostream &) const {}
        ///
index 99f32293789a0beeb6215ce1c3f600f22793e188..348454b6385179263219241f53c9b7c9908f3409 100644 (file)
@@ -170,9 +170,12 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
        pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
        pi.pain.rectangle(x, a, w, h, LColor::mathframe);
 
+#warning FIXME
+#if 0
        LCursor & cur = p.base.bv->cursor();
        if (cur.isInside(this))
                cur.drawSelection(pi);
+#endif
 
        pi.pain.text(x + 2, y, prefix(), font);
 
index 751735e4a2c4bfa58cc0cb5430c3ba9d6cc9576a..37553df1edd0540fd253794f9f31536f9baeb17a 100644 (file)
@@ -63,7 +63,7 @@ public:
        MathInset const * operator->() const { return nucleus_; }
 
        /// width cache. Not nice...
-       mutable int width_;
+       //mutable int width_;
 
 private:
        ///
index 1b32d447862de68a92fda60e6c1e8a4ea9c6352b..d6c2331cb338975b2bb04435c137150afb285cfb 100644 (file)
@@ -84,6 +84,7 @@ void MathCharInset::metrics(MetricsInfo & mi, Dimension & dim) const
                width_ += 2 * font_metrics::width(' ', font_);
        lyxerr << "MathCharInset::metrics: " << dim << endl;
 #endif
+       dim_ = dim;
 }
 
 
index 067affac0bd7b82ac2b300b777c5002de2c1e909..1cad4cf94fa515c653a22ceb946cdc38e17eccee 100644 (file)
 #ifndef MATH_CHARINSET_H
 #define MATH_CHARINSET_H
 
-#include "math_inset.h"
+#include "math_diminset.h"
 
+#warning this should not derive from the fat MathDimInset
 
 /// The base character inset.
-class MathCharInset : public MathInset {
+class MathCharInset : public MathDimInset {
 public:
        ///
        explicit MathCharInset(char c);
@@ -30,6 +31,7 @@ public:
        void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
        ///
        void drawT(TextPainter &, int x, int y) const;
+
        ///
        void write(WriteStream & os) const;
        ///
index 0270d5d87c627eed0005cc28338e8f12c9a4c3de..d8a1f31902a37edc45d846b8eeaa8ff922483a83 100644 (file)
@@ -232,7 +232,7 @@ void MathArray::metrics(MetricsInfo & mi) const
                for (const_iterator it = begin(), et = end(); it != et; ++it) {
                        (*it)->metrics(mi, d);
                        dim_ += d;
-                       it->width_ = d.wid;
+                       //it->width_ = d.wid;
                }
        }
 }
@@ -263,9 +263,9 @@ void MathArray::draw(PainterInfo & pi, int x, int y) const
        }
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
-               pi.width = it->width_;
+               //pi.width = it->width_;
                (*it)->draw(pi, x, y);
-               x += it->width_;
+               x += (*it)->width();
        }
 }
 
@@ -294,7 +294,8 @@ void MathArray::drawT(TextPainter & pain, int x, int y) const
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
                (*it)->drawT(pain, x, y);
-               x += it->width_;
+               //x += (*it->width_;
+               x += 2;
        }
 }
 
@@ -313,7 +314,9 @@ int MathArray::pos2x(size_type pos, int glue) const
                const_iterator it = begin() + i;
                if ((*it)->getChar() == ' ')
                        x += glue;
-               x += it->width_;
+               lyxerr << "char: " << (*it)->getChar()
+                       << "width: " << (*it)->width() << std::endl;
+               x += (*it)->width();
        }
        return x;
 }
@@ -334,7 +337,7 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const
                lastx = currx;
                if ((*it)->getChar() == ' ')
                        currx += glue;
-               currx += it->width_;
+               currx += (*it)->width();
        }
        if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
                --it;
index ff779ad580f23fa63f76e3c100c884363fbdbce9..034ad1510e1b41fed49bfbf654313debcbe2250a 100644 (file)
 #include <config.h>
 
 #include "math_diminset.h"
+#include "debug.h"
 
 
+MathDimInset::MathDimInset()
+       : xo_(-3), yo_(-3)
+{}
+
 
 int MathDimInset::ascent() const
 {
@@ -34,6 +39,7 @@ int MathDimInset::width() const
 
 void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
 {
+       lyxerr << "MathDimInset:: position cache to " << x << " " << y << std::endl;
        xo_ = x;
        yo_ = y;
 }
index 2131e5d7405f635c8a753947e223691e2881d4c4..636baeeb9aa731405ddd02374d096a01d3b28b01 100644 (file)
@@ -21,6 +21,9 @@ class PainterInfo;
 /// things that need the dimension cache
 class MathDimInset : public MathInset {
 public:
+       ///
+       MathDimInset(); 
+
        ///
        Dimension dimensions() const { return dim_; }
        ///
index 344d91933bab9c9c4cfcc867350c810e1a20c75f..48825c15694279f84013f366ee9b2cf4fcaf1253 100644 (file)
@@ -72,12 +72,16 @@ MathArray const & MathNestInset::cell(idx_type i) const
 void MathNestInset::getCursorPos(CursorSlice const & cur,
        int & x, int & y) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        MathArray const & ar = cur.cell();
        x = ar.xo() + ar.pos2x(cur.pos());
        y = ar.yo();
        // move cursor visually into empty cells ("blue rectangles");
        if (cur.cell().empty())
                x += 2;
+       lyxerr << "MathNestInset::getCursorPos: cur: " << cur
+               << " x: " << x << " y: " << y << endl;
+       BOOST_ASSERT(x < 100000);
 }
 
 
@@ -98,6 +102,7 @@ void MathNestInset::metrics(MetricsInfo const & mi) const
 
 bool MathNestInset::idxNext(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.idx() + 1 >= nargs())
                return false;
        ++cur.idx();
@@ -114,6 +119,7 @@ bool MathNestInset::idxRight(LCursor & cur) const
 
 bool MathNestInset::idxPrev(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.idx() == 0)
                return false;
        --cur.idx();
@@ -130,6 +136,7 @@ bool MathNestInset::idxLeft(LCursor & cur) const
 
 bool MathNestInset::idxFirst(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (nargs() == 0)
                return false;
        cur.idx() = 0;
@@ -140,6 +147,7 @@ bool MathNestInset::idxFirst(LCursor & cur) const
 
 bool MathNestInset::idxLast(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (nargs() == 0)
                return false;
        cur.idx() = nargs() - 1;
@@ -150,6 +158,7 @@ bool MathNestInset::idxLast(LCursor & cur) const
 
 bool MathNestInset::idxHome(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.pos() == 0)
                return false;
        cur.pos() = 0;
@@ -159,6 +168,7 @@ bool MathNestInset::idxHome(LCursor & cur) const
 
 bool MathNestInset::idxEnd(LCursor & cur) const
 {
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.lastpos() == cur.lastpos())
                return false;
        cur.pos() = cur.lastpos();
@@ -189,25 +199,35 @@ void MathNestInset::draw(PainterInfo &, int, int) const
 }
 
 
-void MathNestInset::drawSelection(PainterInfo & pi,
-               idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
+void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
 {
-       if (idx1 == idx2) {
-               MathArray const & c = cell(idx1);
-               int x1 = c.xo() + c.pos2x(pos1);
+       // this should use the x/y values given, not the cached values
+       LCursor & cur = pi.base.bv->cursor();
+       if (!cur.selection())
+               return;
+       if (cur.inset() != this)
+               return;
+       CursorSlice & s1 = cur.selBegin();
+       CursorSlice & s2 = cur.selEnd();
+       if (s1.idx() == s2.idx()) {
+               MathArray const & c = s1.cell();
+               lyxerr << "###### c.xo(): " << c.xo() << " c.yo(): " << c.yo() << endl;
+               int x1 = c.xo() + c.pos2x(s1.pos());
                int y1 = c.yo() - c.ascent();
-               int x2 = c.xo() + c.pos2x(pos2);
+               int x2 = c.xo() + c.pos2x(s2.pos());
                int y2 = c.yo() + c.descent();
-               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+               //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
        } else {
                for (idx_type i = 0; i < nargs(); ++i) {
-                       if (idxBetween(i, idx1, idx2)) {
+                       if (idxBetween(i, s1.idx(), s2.idx())) {
                                MathArray const & c = cell(i);
                                int x1 = c.xo();
                                int y1 = c.yo() - c.ascent();
                                int x2 = c.xo() + c.width();
                                int y2 = c.yo() + c.descent();
-                               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+                               //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+                               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
                        }
                }
        }
@@ -779,7 +799,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 
 void MathNestInset::edit(LCursor & cur, int x, int y)
 {
-       lyxerr << "Called MathHullInset::edit with '" << x << ' ' << y << "'" << endl;
+       lyxerr << "Called MathNestInset::edit with '" << x << ' ' << y << "'" << endl;
        cur.push(this);
        int idx_min = 0;
        int dist_min = 1000000;
index 853a33aa54f7a8ca89f0b4cf0943d50987a45038..77ce4d5e56d122eb7c3974fc12988af320f4c663 100644 (file)
@@ -31,8 +31,7 @@ public:
        /// draw background if locked
        void draw(PainterInfo & pi, int x, int y) const;
        /// draw selection background
-       void drawSelection(PainterInfo & pi,
-               idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
+       void drawSelection(PainterInfo & pi, int x, int y) const;
        /// appends itself with macro arguments substituted
        void substitute(MathMacro const & macro);
        /// identifies NestInsets
index 52f97962989b6be46fb97292ab51fc11bf784e29..8d46fe151f7ef90b4cca696c3fc74c667e4a8c39 100644 (file)
@@ -444,13 +444,14 @@ void MathScriptInset::mathematica(MathematicaStream & os) const
        if (u)
                os << "^(" << up() << ')';
 
-       if (nuc().size())
+       if (nuc().size()) {
                if (d)
                        os << ',' << down() << ']';
+       }
 }
 
 
-void MathScriptInset::mathmlize( MathMLStream & os) const
+void MathScriptInset::mathmlize(MathMLStream & os) const
 {
        bool d = hasDown() && down().size();
        bool u = hasUp() && up().size();
index 45514a844a195ed6d1814a9e627e35c08a2d8b64..2f9dd58b408cc92fa55e8eb99d893896ad89c625 100644 (file)
@@ -25,7 +25,7 @@ public:
        /// create inset with single script and given nucleus
        MathScriptInset(MathAtom const & at, bool up);
        ///
-       virtual std::auto_ptr<InsetBase> clone() const;
+       std::auto_ptr<InsetBase> clone() const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -98,9 +98,7 @@ public:
        void infoize2(std::ostream & os) const;
 protected:
        ///
-       virtual
-       DispatchResult
-       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        /// returns x offset for main part
        int dxx() const;
index d60928a79bdb78716ef7006bdf0a62beafe3d0fd..952692be2896f205eee0a27939b0e5a03c5c32b4 100644 (file)
@@ -114,14 +114,14 @@ void MathTextInset::metrics(MetricsInfo & mi, Dimension & dim) const
                        safepos = i;
                        ++spaces;
                        // restart chunk with size of the space
-                       curr = cell(0)[i].width_;
+                       curr = cell(0)[i]->width();
                        continue;
                }
 
                if (c != '\n') {
                        // This is a regular char. Go on if we either don't care for
                        // the width limit or have not reached that limit.
-                       curr += cell(0)[i].width_;
+                       curr += cell(0)[i]->width();
                        if (curr + safe <= mi.base.textwidth)
                                continue;
                }
@@ -187,8 +187,10 @@ void MathTextInset::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+/*
 void MathTextInset::drawSelection(PainterInfo & pi,
                idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
 {
        cache_.drawSelection(pi, idx1, pos1, idx2, pos2);
 }
+*/
index 44ebf919f6ddeeeaf1df896b3632c90f980b2182..04826766c09bb9768239aaf97b78eb25a1f2597b 100644 (file)
@@ -30,8 +30,8 @@ public:
        /// draw according to cached metrics
        void draw(PainterInfo &, int x, int y) const;
        /// draw selection background
-       void drawSelection(PainterInfo & pi,
-               idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
+       //void drawSelection(PainterInfo & pi,
+       //      idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
        /// moves cursor up or down
        //bool idxUpDown2(LCursor & pos, bool up) const;
 protected:
index 1bebde2723f658e0977c7c2490056f00bdd0bad7..d9f8001afe9fafab5aa5e37ccfa45a5f6e74732f 100644 (file)
@@ -194,10 +194,11 @@ int RowPainter::leftMargin() const
 
 void RowPainter::paintInset(pos_type const pos)
 {
-       InsetBase * inset = const_cast<InsetBase *>(pit_->getInset(pos));
+       InsetBase const * inset = pit_->getInset(pos);
        BOOST_ASSERT(inset);
        PainterInfo pi(const_cast<BufferView *>(&bv_));
        pi.base.font = getFont(pos);
+       inset->drawSelection(pi, int(x_), yo_ + row_.baseline());
        inset->draw(pi, int(x_), yo_ + row_.baseline());
        x_ += inset->width();
 }
index 939aee4530eb36323791e07181c279d74fb5ddea..f517f2ab0e94d936f7147f8411fe69222364cc8c 100644 (file)
@@ -123,7 +123,7 @@ void recordUndo(Undo::undo_kind kind,
        ParIterator pit = text2pit(buf, text, textnum);
        stack.push(Undo(kind, textnum, pit.index(),
                first_par, end_par, text->cursor().par(), text->cursor().pos()));
-       lyxerr << "undo record: " << stack.top() << std::endl;
+       //lyxerr << "undo record: " << stack.top() << std::endl;
 
        // record the relevant paragraphs
        ParagraphList & undo_pars = stack.top().pars;