}
-void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
-{
- BufferView & bv = *pi.base.bv;
- // this should use the x/y values given, not the cached values
- Cursor & cur = bv.cursor();
- if (!cur.selection())
- return;
- if (&cur.inset() != this)
- return;
-
- // FIXME: hack to get position cache warm
- bool const original_drawing_state = pi.pain.isDrawingEnabled();
- pi.pain.setDrawingEnabled(false);
- draw(pi, x, y);
- pi.pain.setDrawingEnabled(original_drawing_state);
-
- CursorSlice s1 = cur.selBegin();
- CursorSlice s2 = cur.selEnd();
-
- //lyxerr << "InsetMathNest::drawing selection: "
- // << " s1: " << s1 << " s2: " << s2 << endl;
- if (s1.idx() == s2.idx()) {
- MathData const & c = cell(s1.idx());
- Geometry const & g = bv.coordCache().getArrays().geometry(&c);
- int x1 = g.pos.x_ + c.pos2x(pi.base.bv, s1.pos());
- int y1 = g.pos.y_ - g.dim.ascent();
- int x2 = g.pos.x_ + c.pos2x(pi.base.bv, s2.pos());
- int y2 = g.pos.y_ + g.dim.descent();
- pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection);
- //lyxerr << "InsetMathNest::drawing selection 3: "
- // << " x1: " << x1 << " x2: " << x2
- // << " y1: " << y1 << " y2: " << y2 << endl;
- } else {
- for (idx_type i = 0; i < nargs(); ++i) {
- if (idxBetween(i, s1.idx(), s2.idx())) {
- MathData const & c = cell(i);
- Geometry const & g = bv.coordCache().getArrays().geometry(&c);
- int x1 = g.pos.x_;
- int y1 = g.pos.y_ - g.dim.ascent();
- int x2 = g.pos.x_ + g.dim.width();
- int y2 = g.pos.y_ + g.dim.descent();
- pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection);
- }
- }
- }
-}
-
-
void InsetMathNest::validate(LaTeXFeatures & features) const
{
for (idx_type i = 0; i < nargs(); ++i)
void cellsMetrics(MetricsInfo const & mi) const;
/// draw background if locked
void draw(PainterInfo & pi, int x, int y) const;
- /// draw selection background
- void drawSelection(PainterInfo & pi, int x, int y) const;
///
void updateBuffer(ParIterator const &, UpdateType);
/// identifies NestInsets
void cursorPos(BufferView const & bv, CursorSlice const & sl,
bool boundary, int & x, int & y) const;
///
- void edit(Cursor & cur, bool front,
+ void edit(Cursor & cur, bool front,
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
///
Inset * editXY(Cursor & cur, int x, int y);
#include "mathed/InsetMathUnknown.h"
#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
#include "support/debug.h"
#include "support/docstream.h"
}
+void MathData::drawSelection(PainterInfo & pi, int const x, int const y) const
+{
+ BufferView const * bv = pi.base.bv;
+ Cursor const & cur = bv->cursor();
+ InsetMath const * inset = cur.inset().asInsetMath();
+ if (!cur.selection() || !inset || inset->nargs() == 0)
+ return;
+
+ CursorSlice const s1 = cur.selBegin();
+ CursorSlice const s2 = cur.selEnd();
+ MathData const & c1 = inset->cell(s1.idx());
+
+ if (s1.idx() == s2.idx() && &c1 == this) {
+ // selection indide cell
+ Dimension const dim = bv->coordCache().getArrays().dim(&c1);
+ int const beg = c1.pos2x(bv, s1.pos());
+ int const end = c1.pos2x(bv, s2.pos());
+ pi.pain.fillRectangle(x + beg, y - dim.ascent(),
+ end - beg, dim.height(), Color_selection);
+ } else {
+ for (idx_type i = 0; i < inset->nargs(); ++i) {
+ MathData const & c = inset->cell(i);
+ if (&c == this && inset->idxBetween(i, s1.idx(), s2.idx())) {
+ // The whole cell is selected
+ Dimension const dim = bv->coordCache().getArrays().dim(&c);
+ pi.pain.fillRectangle(x, y - dim.ascent(),
+ dim.width(), dim.height(),
+ Color_selection);
+ }
+ }
+ }
+}
+
+
void MathData::draw(PainterInfo & pi, int const x, int const y) const
{
//lyxerr << "MathData::draw: x: " << x << " y: " << y << endl;
|| x >= bv. workWidth())
return;
+ drawSelection(pi, x, y);
MathRow const & mrow = mrow_cache_[pi.base.bv];
mrow.draw(pi, x, y);
}
///
Dimension const & dimension(BufferView const &) const;
+ /// draw the selection over the cell
+ void drawSelection(PainterInfo & pi, int x, int y) const;
/// redraw cell using cache metrics information
void draw(PainterInfo & pi, int x, int y) const;
/// rebuild cached metrics information
}
-void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
-{
- // We may have 0 arguments, but InsetMathNest requires at least one.
- if (!cells_.empty())
- InsetMathNest::drawSelection(pi, x, y);
-}
-
-
void MathMacro::setDisplayMode(MathMacro::DisplayMode mode, int appetite)
{
if (d->displayMode_ != mode) {
bool editMetrics(BufferView const * bv) const;
///
void draw(PainterInfo & pi, int x, int y) const;
- /// draw selection background
- void drawSelection(PainterInfo & pi, int x, int y) const;
///
int kerning(BufferView const * bv) const;
/// get cursor position
Dimension d2 = d;
d2.wid -= e.before + e.after;
coords.insets().add(e.inset, d2);
- e.inset->drawSelection(pi, x + e.before, y);
e.inset->draw(pi, x + e.before, y);
coords.insets().add(e.inset, x, y);
coords.insets().add(e.inset, d);
break;
}
case BEGIN:
+ if (e.ar) {
+ coords.arrays().add(e.ar, x, y);
+ e.ar->drawSelection(pi, x, y);
+ }
if (e.inset) {
coords.insets().add(e.inset, x, y);
drawMarkers(pi, e, x, y);
e.inset->beforeDraw(pi);
}
x += e.before + e.after;
- if (e.ar)
- coords.arrays().add(e.ar, x, y);
break;
case END:
if (e.inset)