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
This commit is contained in:
André Pönitz 2004-02-02 17:32:56 +00:00
parent a73da74db2
commit 6af06846fd
22 changed files with 92 additions and 52 deletions

View 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

View 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();

View 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);

View 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;

View 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;
}

View 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)

View 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 {}
///

View 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);

View File

@ -63,7 +63,7 @@ public:
MathInset const * operator->() const { return nucleus_; }
/// width cache. Not nice...
mutable int width_;
//mutable int width_;
private:
///

View 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;
}

View File

@ -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;
///

View 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;

View File

@ -11,8 +11,13 @@
#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;
}

View File

@ -21,6 +21,9 @@ class PainterInfo;
/// things that need the dimension cache
class MathDimInset : public MathInset {
public:
///
MathDimInset();
///
Dimension dimensions() const { return dim_; }
///

View 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;

View 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

View 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();

View 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;

View 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);
}
*/

View 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:

View 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();
}

View 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;