From 4d51fc96b416eb72f8f6e0533745188717da575e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 26 Jul 2002 17:23:44 +0000 Subject: [PATCH] move things around git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4799 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 5 ++--- src/mathed/math_cursor.C | 36 ++--------------------------------- src/mathed/math_inset.C | 7 +++++++ src/mathed/math_inset.h | 7 +++++-- src/mathed/math_nestinset.C | 24 +++++++++++++++++++++++ src/mathed/math_nestinset.h | 4 +++- src/mathed/math_parboxinset.C | 28 +++++++++++++++++++++++++++ src/mathed/math_parboxinset.h | 3 +++ 8 files changed, 74 insertions(+), 40 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index dbc150a52f..6be371e6d3 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -416,6 +416,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, switch (action) { + case LFUN_WORDRIGHTSEL: case LFUN_RIGHTSEL: sel = true; // fall through... case LFUN_RIGHT: @@ -427,6 +428,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, //bv->owner()->message(mathcursor->info()); break; + case LFUN_WORDLEFTSEL: case LFUN_LEFTSEL: sel = true; // fall through case LFUN_LEFT: @@ -543,9 +545,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, mathcursor->selCopy(); break; - case LFUN_WORDRIGHTSEL: - case LFUN_WORDLEFTSEL: - break; // Special casing for superscript in case of LyX handling // dead-keys: diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 77b4a35697..b7c66d5d37 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -660,46 +660,14 @@ void MathCursor::selGet(MathArray & ar) -void MathCursor::drawSelection(MathPainterInfo & pain) const +void MathCursor::drawSelection(MathPainterInfo & pi) const { if (!selection_) return; - MathCursorPos i1; MathCursorPos i2; getSelection(i1, i2); - - if (i1.idx_ == i2.idx_) { - MathXArray & c = i1.xcell(); - int x1 = c.xo() + c.pos2x(i1.pos_); - int y1 = c.yo() - c.ascent(); - int x2 = c.xo() + c.pos2x(i2.pos_); - int y2 = c.yo() + c.descent(); - pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); - } else { - vector indices - = i1.par_->idxBetween(i1.idx_, i2.idx_); - for (unsigned i = 0; i < indices.size(); ++i) { - MathXArray & c = i1.xcell(indices[i]); - int x1 = c.xo(); - int y1 = c.yo() - c.ascent(); - int x2 = c.xo() + c.width(); - int y2 = c.yo() + c.descent(); - pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); - } - } - -#if 0 - // draw anchor if different from selection boundary - MathCursorPos anc = Anchor_.back(); - if (anc != i1 && anc != i2) { - MathXArray & c = anc.xcell(); - int x = c.xo() + c.pos2x(anc.pos_); - int y1 = c.yo() - c.ascent(); - int y2 = c.yo() + c.descent(); - pain.line(x, y1, x, y2, LColor::math); - } -#endif + i1.par_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_); } diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 6d0e9cda0e..e1a6069046 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -224,6 +224,13 @@ void MathInset::draw(MathPainterInfo &, int, int) const } +void MathInset::drawSelection(MathPainterInfo &, + idx_type, pos_type, idx_type, pos_type) const +{ + lyxerr << "MathInset::drawSelection() called directly!\n"; +} + + void MathInset::metricsT(TextMetricsInfo const &) const { #ifdef WITH_WARNINGS diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 41894271c3..5a62a1bc82 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -110,9 +110,12 @@ public: virtual void substitute(MathMacro const & macro); /// compute the size of the object, sets ascend_, descend_ and width_ // updates the (xo,yo)-caches of all contained cells - virtual void metrics(MathMetricsInfo & st) const; + virtual void metrics(MathMetricsInfo & mi) const; /// draw the object - virtual void draw(MathPainterInfo &, int x, int y) const; + virtual void draw(MathPainterInfo & pi, int x, int y) const; + /// draw selection between two positions + virtual void drawSelection(MathPainterInfo & pi, + idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; /// the ascent of the inset above the baseline /// compute the size of the object for text based drawing virtual void metricsT(TextMetricsInfo const & st) const; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index e3d219470f..dd328b8312 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -182,6 +182,30 @@ void MathNestInset::draw(MathPainterInfo &, int, int) const } +void MathNestInset::drawSelection(MathPainterInfo & pi, + idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const +{ + if (idx1 == idx2) { + MathXArray const & c = xcell(idx1); + int x1 = c.xo() + c.pos2x(pos1); + int y1 = c.yo() - c.ascent(); + int x2 = c.xo() + c.pos2x(pos2); + int y2 = c.yo() + c.descent(); + pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); + } else { + vector indices = idxBetween(idx1, idx2); + for (unsigned i = 0; i < indices.size(); ++i) { + MathXArray const & c = xcell(indices[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); + } + } +} + + void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const { if (!editing()) diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index ba791df4d7..3f8fd3e180 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -28,7 +28,9 @@ public: void metricsMarkers2(int frame = 1) const; /// draw background if locked void draw(MathPainterInfo & pi, int x, int y) const; - /// draw two angular markers + /// draw selection background + void drawSelection(MathPainterInfo & pi, + idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; void drawMarkers(MathPainterInfo & pi, int x, int y) const; /// draw four angular markers void drawMarkers2(MathPainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_parboxinset.C b/src/mathed/math_parboxinset.C index 459949cc5f..609f9bdeb0 100644 --- a/src/mathed/math_parboxinset.C +++ b/src/mathed/math_parboxinset.C @@ -207,6 +207,34 @@ void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const } +void MathParboxInset::drawSelection(MathPainterInfo & pi, + idx_type, pos_type pos1, idx_type, pos_type pos2) const +{ + int row1 = pos2row(pos1); + int row2 = pos2row(pos2); + if (row1 == row2) { +/* + MathXArray & c = xcell(0); + int x1 = c.xo() + c.pos2x(i1.pos_); + int y1 = c.yo() - c.ascent(); + int x2 = c.xo() + c.pos2x(i2.pos_); + int y2 = c.yo() + c.descent(); + pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); + } else { + vector indices = idxBetween(idx1, idx2); + for (unsigned i = 0; i < indices.size(); ++i) { + MathXArray & c = i1.xcell(indices[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); + } +*/ + } +} + + void MathParboxInset::write(WriteStream & os) const { os << "\\parbox"; diff --git a/src/mathed/math_parboxinset.h b/src/mathed/math_parboxinset.h index 71e6ac07ce..ab129d9b66 100644 --- a/src/mathed/math_parboxinset.h +++ b/src/mathed/math_parboxinset.h @@ -19,6 +19,9 @@ public: void metrics(MathMetricsInfo & mi) const; /// void draw(MathPainterInfo &, int x, int y) const; + /// draw selection background + void drawSelection(MathPainterInfo & pi, + idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; /// void infoize(std::ostream & os) const; ///