From: André Pönitz Date: Mon, 2 Feb 2004 17:32:56 +0000 (+0000) Subject: remove cursor::drawSelection() plus some math reorganization (move the X-Git-Tag: 1.6.10~15545 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6af06846fd8b037e2b7e60b2f4838c64da602555;p=features.git remove cursor::drawSelection() plus some math reorganization (move the 'width' cache from MathAtom) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8383 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 8b8b009896..af33f7c593 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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 diff --git a/src/cursor.C b/src/cursor.C index 955d308424..5c74ebebb6 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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(); diff --git a/src/cursor.h b/src/cursor.h index 68c257c793..e4d1ebc2a1 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -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); diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 525b3912e1..c921218cbb 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -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; diff --git a/src/insets/inset.C b/src/insets/inset.C index b61eafd076..b533f4de92 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -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; } diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 1bd6b65e37..4a03ba7327 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -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) diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 23d390db45..a8d458fa34 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -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 {} /// diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 99f3229378..348454b638 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -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); diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 751735e4a2..37553df1ed 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -63,7 +63,7 @@ public: MathInset const * operator->() const { return nucleus_; } /// width cache. Not nice... - mutable int width_; + //mutable int width_; private: /// diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 1b32d44786..d6c2331cb3 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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; } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 067affac0b..1cad4cf94f 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -12,11 +12,12 @@ #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; /// diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 0270d5d87c..d8a1f31902 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -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; diff --git a/src/mathed/math_diminset.C b/src/mathed/math_diminset.C index ff779ad580..034ad1510e 100644 --- a/src/mathed/math_diminset.C +++ b/src/mathed/math_diminset.C @@ -11,8 +11,13 @@ #include #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; } diff --git a/src/mathed/math_diminset.h b/src/mathed/math_diminset.h index 2131e5d740..636baeeb9a 100644 --- a/src/mathed/math_diminset.h +++ b/src/mathed/math_diminset.h @@ -21,6 +21,9 @@ class PainterInfo; /// things that need the dimension cache class MathDimInset : public MathInset { public: + /// + MathDimInset(); + /// Dimension dimensions() const { return dim_; } /// diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 344d91933b..48825c1569 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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; diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 853a33aa54..77ce4d5e56 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -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 diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 52f9796298..8d46fe151f 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -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(); diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 45514a844a..2f9dd58b40 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -25,7 +25,7 @@ public: /// create inset with single script and given nucleus MathScriptInset(MathAtom const & at, bool up); /// - virtual std::auto_ptr clone() const; + std::auto_ptr 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; diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index d60928a79b..952692be28 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -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); } +*/ diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index 44ebf919f6..04826766c0 100644 --- a/src/mathed/math_textinset.h +++ b/src/mathed/math_textinset.h @@ -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: diff --git a/src/rowpainter.C b/src/rowpainter.C index 1bebde2723..d9f8001afe 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -194,10 +194,11 @@ int RowPainter::leftMargin() const void RowPainter::paintInset(pos_type const pos) { - InsetBase * inset = const_cast(pit_->getInset(pos)); + InsetBase const * inset = pit_->getInset(pos); BOOST_ASSERT(inset); PainterInfo pi(const_cast(&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(); } diff --git a/src/undo.C b/src/undo.C index 939aee4530..f517f2ab0e 100644 --- a/src/undo.C +++ b/src/undo.C @@ -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;