From 08492c2703848a3810e9719cd640731b51bb5b31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 19 Aug 2003 16:46:47 +0000 Subject: [PATCH] shift rowpainter interface a bit git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7575 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 3 ++ src/frontends/ChangeLog | 4 ++ src/frontends/screen.C | 51 ++++++++----------------- src/frontends/screen.h | 3 -- src/insets/ChangeLog | 5 +++ src/insets/insettext.C | 46 +++++------------------ src/rowpainter.C | 82 +++++++++++++++++++++++++++++------------ src/rowpainter.h | 14 +++---- src/text3.C | 3 +- 9 files changed, 102 insertions(+), 109 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1db57f3c9f..6c8ab57e01 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,9 @@ * funcrequest.C: initialize button_ member + * text3.C: + * rowpainter.[Ch]: interface consolidation + 2003-08-18 André Pönitz * BufferView.C: diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index ae67922f43..7de4f12c75 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,4 +1,8 @@ +2003-08-19 André Pönitz + + * screen.[Ch]: use new rowpainter interface + 2003-08-18 André Pönitz * screen.[Ch]: remove draw() diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 2302ee3202..2b7321198e 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -220,7 +220,7 @@ void LyXScreen::toggleCursor(BufferView & bv) } -bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text, +bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text, int /*x*/, int y, int asc, int desc) { int const vheight = workarea().workHeight(); @@ -237,7 +237,6 @@ bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text, return false; text->top_y(newtop); - //draw(); return true; } @@ -251,13 +250,7 @@ unsigned int LyXScreen::topCursorVisible(LyXText * text) RowList::iterator row = text->cursorRow(); -#warning SUPER HACK DISABLED (Lgb) -#if 0 - // Is this a hack? Yes, probably... (Lgb) - if (!row) - return max(newtop, 0); -#endif - if (cursor.y() - row->baseline() + row->height() - top_y >= vheight) { + if (int(cursor.y() - row->baseline() + row->height() - top_y) >= vheight) { if (row->height() < vheight && row->height() > vheight / 4) { newtop = cursor.y() @@ -278,9 +271,7 @@ unsigned int LyXScreen::topCursorVisible(LyXText * text) } } - newtop = max(newtop, 0); - - return newtop; + return max(newtop, 0); } @@ -290,8 +281,6 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv) int const newtop = topCursorVisible(text); bool const result = (newtop != text->top_y()); text->top_y(newtop); - //if (result) - // draw(); return result; } @@ -308,7 +297,18 @@ void LyXScreen::redraw(BufferView & bv) workarea().getPainter().start(); bv.text->updateRowPositions(); - drawFromTo(bv.text, &bv); + hideCursor(); + + int const y = paintText(bv, *bv.text); + + // maybe we have to clear the screen at the bottom + int const y2 = workarea().workHeight(); + if (y < y2 && !bv.text->isInInset()) { + workarea().getPainter().fillRectangle(0, y, + workarea().workWidth(), y2 - y, + LColor::bottomarea); + } + expose(0, 0, workarea().workWidth(), workarea().workHeight()); workarea().getPainter().end(); @@ -347,24 +347,3 @@ void LyXScreen::greyOut() expose(0, 0, workarea().workWidth(), workarea().workHeight()); workarea().getPainter().end(); } - - -void LyXScreen::drawFromTo(LyXText * text, BufferView * bv) -{ - hideCursor(); - int const topy = text->top_y(); - int y_text = topy; - ParagraphList::iterator pit; - RowList::iterator rit = text->getRowNearY(y_text, pit); - int y = y_text - topy; - - y = paintRows(*bv, *text, pit, rit, 0, y, y, 0); - - // maybe we have to clear the screen at the bottom - int const y2 = workarea().workHeight(); - if (y < y2 && !text->isInInset()) { - workarea().getPainter().fillRectangle(0, y, - workarea().workWidth(), y2 - y, - LColor::bottomarea); - } -} diff --git a/src/frontends/screen.h b/src/frontends/screen.h index 5ba7bbf222..74661739cb 100644 --- a/src/frontends/screen.h +++ b/src/frontends/screen.h @@ -108,9 +108,6 @@ protected: virtual void removeCursor() = 0; private: - /// y1 and y2 are coordinates of the screen - void drawFromTo(LyXText *, BufferView *); - /// grey out (no buffer) void greyOut(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 2dc82f11f2..9907a26789 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ + +2003-08-19 André Pönitz + + * insettext.C: use new RowPainter interface + 2003-08-18 John Levon * insetref.C: require amsmath for eqref diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 569c7e744a..ae83c6032e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -251,7 +251,7 @@ int InsetText::textWidth() const } -void InsetText::draw(PainterInfo & pi, int x, int baseline) const +void InsetText::draw(PainterInfo & pi, int x, int y) const { // update our idea of where we are. Clearly, we should // not have to know this information. @@ -264,11 +264,11 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const // repaint the background if needed if (backgroundColor() != LColor::background) - clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline); + clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, y); // no draw is necessary !!! if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) { - top_baseline = baseline; + top_baseline = y; return; } @@ -277,8 +277,8 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const if (!owner()) x += scroll(); - top_baseline = baseline; - top_y = baseline - dim_.asc; + top_baseline = y; + top_y = y - dim_.asc; if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) { inset_x = cix() - x + drawTextXOffset; @@ -287,33 +287,10 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const x += TEXT_TO_INSET_OFFSET; - RowList::iterator rit = text_.firstRow(); - RowList::iterator end = text_.endRow(); - ParagraphList::iterator pit = paragraphs.begin(); - - int y_offset = baseline - rit->ascent_of_text(); - int first = 0; - int y = y_offset; - while (rit != end && y + rit->height() <= 0) { - y += rit->height(); - first += rit->height(); - text_.nextRow(pit, rit); - } - if (y_offset < 0) { - text_.top_y(-y_offset); - first = y; - y_offset = 0; - } else { - text_.top_y(first); - first = 0; - } - - int yo = y_offset + first; - - paintRows(*bv, text_, pit, rit, x, 0, yo, yo); + paintTextInset(*bv, text_, x, y); if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked)) - drawFrame(pain, int(start_x)); + drawFrame(pain, start_x); } @@ -1629,7 +1606,7 @@ int InsetText::scroll(bool recursive) const void InsetText::clearSelection(BufferView * bv) { - getLyXText(bv)->clearSelection(); + text_.clearSelection(); } @@ -1776,12 +1753,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str, return true; } if (!locked) { - ParagraphList::iterator pit = paragraphs.begin(); - ParagraphList::iterator pend = paragraphs.end(); - - while (boost::next(pit) != pend) - ++pit; - + ParagraphList::iterator pit = boost::prior(paragraphs.end()); text_.setCursor(pit, pit->size()); } lyx::find::SearchResult result = diff --git a/src/rowpainter.C b/src/rowpainter.C index 6f7a77446e..f1adf7e0ee 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -1041,30 +1041,6 @@ void RowPainter::paint() } -} // namespace anon - - -int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp) -{ - if (vsp.kind() == VSpace::NONE) - return 0; - - int const arrow_size = 4; - int const space_size = vsp.inPixels(bv); - - LyXFont font; - font.decSize(); - int const min_size = max(3 * arrow_size, - font_metrics::maxAscent(font) - + font_metrics::maxDescent(font)); - - if (vsp.length().len().value() < 0.0) - return min_size; - else - return max(min_size, space_size); -} - - int paintRows(BufferView const & bv, LyXText const & text, ParagraphList::iterator pit, RowList::iterator rit, int xo, int y, int yf, int yo) @@ -1099,3 +1075,61 @@ int paintRows(BufferView const & bv, LyXText const & text, return y; } + +} // namespace anon + + +int paintText(BufferView & bv, LyXText & text) +{ + int const topy = text.top_y(); + int y_text = topy; + ParagraphList::iterator pit; + RowList::iterator rit = text.getRowNearY(y_text, pit); + int y = y_text - topy; + return paintRows(bv, text, pit, rit, 0, y, y, 0); +} + + +void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline) +{ + RowList::iterator rit = text.firstRow(); + RowList::iterator end = text.endRow(); + ParagraphList::iterator pit = text.ownerParagraphs().begin(); + + int y_offset = baseline - rit->ascent_of_text(); + int y = y_offset; + while (rit != end && y + rit->height() <= 0) { + y += rit->height(); + text.nextRow(pit, rit); + } + if (y_offset < 0) { + text.top_y(-y_offset); + paintRows(bv, text, pit, rit, x, 0, y, y); + } else { + text.top_y(y - y_offset); + paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset); + } +} + + +int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp) +{ + if (vsp.kind() == VSpace::NONE) + return 0; + + int const arrow_size = 4; + int const space_size = vsp.inPixels(bv); + + LyXFont font; + font.decSize(); + int const min_size = max(3 * arrow_size, + font_metrics::maxAscent(font) + + font_metrics::maxDescent(font)); + + if (vsp.length().len().value() < 0.0) + return min_size; + else + return max(min_size, space_size); +} + + diff --git a/src/rowpainter.h b/src/rowpainter.h index dbd9d75ca9..dbc17abff2 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -15,19 +15,17 @@ #include -#include "RowList.h" - class LyXText; class BufferView; class VSpace; -/// paint the rows -// return last used y -int paintRows(BufferView const & bv, LyXText const & text, - ParagraphList::iterator pit, - RowList::iterator rit, int xo, int y, int yf, int yo); - /// return the pixel height of a space marker before/after a par int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp); +/// paint the rows of the main text, return last drawn y value +int paintText(BufferView & bv, LyXText & text); + +/// paint the rows of a text inset +void paintTextInset(BufferView & bv, LyXText & text, int x, int y); + #endif // ROWPAINTER_H diff --git a/src/text3.C b/src/text3.C index 29c8d56813..09b84dd5a0 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1454,7 +1454,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) } bv->beforeChange(this); - LyXFont const old_font(real_current_font); + LyXFont const old_font = real_current_font; string::const_iterator cit = cmd.argument.begin(); string::const_iterator end = cmd.argument.end(); @@ -1469,6 +1469,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) // update the minibuffer if (old_font != real_current_font) bv->owner()->view_state_changed(); + bv->updateScrollbar(); break; } -- 2.39.2