res = bv_->text()->dispatch(cur, cmd);
}
- if (bv_->fitCursor() || res.update()) {
+ if (fitCursor() || res.update()) {
bv_->update();
cur.updatePos();
}
// if it wishes to do so.
DispatchResult res = cur.dispatch(cmd);
- if (bv_->fitCursor() || res.update())
+ if (fitCursor() || res.update())
bv_->update();
// see workAreaKeyPress
}
-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;
bool LCursor::script(bool up)
{
// Hack to get \\^ and \\_ working
+ lyxerr << "handling script: up: " << up << endl;
if (inMacroMode() && macroName() == "\\") {
if (up)
niceInsert(createMathInset("mathcircumflex"));
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;
bool LCursor::interpret(char c)
{
- //lyxerr << "interpret 2: '" << c << "'" << endl;
+ lyxerr << "interpret 2: '" << c << "'" << endl;
clearTargetX();
if (inMacroArgMode()) {
posLeft();
/// 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);
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;
void InsetOld::setPosCache(PainterInfo const &, int x, int y) const
{
+ lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
xo_ = x;
yo_ = y;
}
#include "insetbase.h"
+#include "buffer.h"
#include "BufferView.h"
#include "LColor.h"
#include "cursor.h"
}
+void InsetBase::dump() const
+{
+ Buffer buf("foo", 1);
+ write(buf, lyxerr);
+}
+
+
/////////////////////////////////////////
bool isEditableInset(InsetBase const * inset)
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
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 {}
///
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);
MathInset const * operator->() const { return nucleus_; }
/// width cache. Not nice...
- mutable int width_;
+ //mutable int width_;
private:
///
width_ += 2 * font_metrics::width(' ', font_);
lyxerr << "MathCharInset::metrics: " << dim << endl;
#endif
+ dim_ = dim;
}
#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);
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter &, int x, int y) const;
+
///
void write(WriteStream & os) 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;
}
}
}
}
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();
}
}
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->drawT(pain, x, y);
- x += it->width_;
+ //x += (*it->width_;
+ x += 2;
}
}
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;
}
lastx = currx;
if ((*it)->getChar() == ' ')
currx += glue;
- currx += it->width_;
+ currx += (*it)->width();
}
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
--it;
#include <config.h>
#include "math_diminset.h"
+#include "debug.h"
+MathDimInset::MathDimInset()
+ : xo_(-3), yo_(-3)
+{}
+
int MathDimInset::ascent() const
{
void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
{
+ lyxerr << "MathDimInset:: position cache to " << x << " " << y << std::endl;
xo_ = x;
yo_ = y;
}
/// things that need the dimension cache
class MathDimInset : public MathInset {
public:
+ ///
+ MathDimInset();
+
///
Dimension dimensions() const { return dim_; }
///
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);
}
bool MathNestInset::idxNext(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (cur.idx() + 1 >= nargs())
return false;
++cur.idx();
bool MathNestInset::idxPrev(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (cur.idx() == 0)
return false;
--cur.idx();
bool MathNestInset::idxFirst(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (nargs() == 0)
return false;
cur.idx() = 0;
bool MathNestInset::idxLast(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (nargs() == 0)
return false;
cur.idx() = nargs() - 1;
bool MathNestInset::idxHome(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (cur.pos() == 0)
return false;
cur.pos() = 0;
bool MathNestInset::idxEnd(LCursor & cur) const
{
+ BOOST_ASSERT(cur.inset() == this);
if (cur.lastpos() == cur.lastpos())
return false;
cur.pos() = cur.lastpos();
}
-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);
}
}
}
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;
/// 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
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();
/// 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;
///
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;
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;
}
}
+/*
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);
}
+*/
/// 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:
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();
}
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;