From eb651c3d6100eac2d3ec6d176234a0f9512671b9 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 30 Oct 2006 12:45:33 +0000 Subject: [PATCH] Move BufferView cached pointer out of LyXText: * LyXText - bv(), bv_owner, : deleted. - These methods now need a (Buffer const &) argument: getFont(), applyOuterFont(), getLayoutFont(), getLabelFont(), setCharFont(), setLayout(), singleWidth(), leftMargin(), rightMargin(), computeRowMetrics(), isMainText(), spacing(), isRTL(), cursorX(), rowBreakPoint(), setRowWidth(), labelFill(), labelEnd(). - These methods now need a (BufferView const &) argument and are propably candidates for future removal when 1.6 is opened for development: redoParagraph(), x2pos(), getRowNearY(), getColumnNearX(), checkInsetHit(), setHeightOfRow(). - recUndo(): now need a LCursor argument. * CoordCache::get(LyXText const *, pit_type): - now const. - use const_iterator instead of iterator. * FontIterator: - add (Buffer const &) argument to ctor - buffer_: new const reference to applicable BufferView. * InsetBase - xo(), yo(), covers() and neverIndent() are now const. * InsetText::setViewCache(): deleted All other changes are due to the LyXText and InsetBase API changes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15618 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 10 +- src/FontIterator.C | 11 +- src/FontIterator.h | 6 +- src/buffer_funcs.C | 2 +- src/bufferview_funcs.C | 2 +- src/coordcache.C | 6 +- src/coordcache.h | 4 +- src/cursor.C | 2 +- src/insets/insetbase.C | 6 +- src/insets/insetbase.h | 8 +- src/insets/insetbox.h | 2 +- src/insets/insetcaption.h | 2 +- src/insets/insetcharstyle.h | 2 +- src/insets/insetert.h | 2 +- src/insets/insetoptarg.h | 2 +- src/insets/insettabular.C | 22 +-- src/insets/insettext.C | 25 +-- src/insets/insettext.h | 6 +- src/lyxfunc.C | 4 +- src/lyxtext.h | 77 ++++----- src/mathed/MathData.C | 6 +- src/mathed/MathData.h | 10 +- src/rowpainter.C | 40 ++--- src/tabular.C | 5 +- src/text.C | 305 ++++++++++++++++++++---------------- src/text2.C | 140 +++++++++-------- src/text3.C | 26 +-- src/trans_mgr.C | 24 +-- src/trans_mgr.h | 9 +- 29 files changed, 400 insertions(+), 366 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 93fe6d698b..3f7ccd1c2f 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -467,7 +467,7 @@ void BufferView::scrollDocView(int value) anchor_ref_ = int(bar * t.paragraphs().size()); if (anchor_ref_ > int(t.paragraphs().size()) - 1) anchor_ref_ = int(t.paragraphs().size()) - 1; - t.redoParagraph(anchor_ref_); + t.redoParagraph(*this, anchor_ref_); int const h = t.getPar(anchor_ref_).height(); offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h); } @@ -607,7 +607,7 @@ void BufferView::center() { CursorSlice & bot = cursor_.bottom(); pit_type const pit = bot.pit(); - bot.text()->redoParagraph(pit); + bot.text()->redoParagraph(*this, pit); Paragraph const & par = bot.text()->paragraphs()[pit]; anchor_ref_ = pit; offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_ @@ -1290,7 +1290,7 @@ void BufferView::updateMetrics(bool singlepar) // (if this paragraph contains insets etc., rebreaking will // recursively descend) if (!singlepar || pit == cursor_.bottom().pit()) - buftext.redoParagraph(pit); + buftext.redoParagraph(*this, pit); int y0 = buftext.getPar(pit).ascent() - offset_ref_; // Redo paragraphs above anchor if necessary; again, in Single Par @@ -1300,7 +1300,7 @@ void BufferView::updateMetrics(bool singlepar) y1 -= buftext.getPar(pit1).ascent(); --pit1; if (!singlepar || pit1 == cursor_.bottom().pit()) - buftext.redoParagraph(pit1); + buftext.redoParagraph(*this, pit1); y1 -= buftext.getPar(pit1).descent(); } @@ -1326,7 +1326,7 @@ void BufferView::updateMetrics(bool singlepar) y2 += buftext.getPar(pit2).descent(); ++pit2; if (!singlepar || pit2 == cursor_.bottom().pit()) - buftext.redoParagraph(pit2); + buftext.redoParagraph(*this, pit2); y2 += buftext.getPar(pit2).ascent(); } diff --git a/src/FontIterator.C b/src/FontIterator.C index 38c12672e7..ab97a6f384 100644 --- a/src/FontIterator.C +++ b/src/FontIterator.C @@ -14,6 +14,7 @@ #include "FontIterator.h" +#include "buffer.h" #include "lyxtext.h" #include "paragraph.h" @@ -21,10 +22,10 @@ namespace lyx { -FontIterator::FontIterator(LyXText const & text, Paragraph const & par, - pos_type pos) - : text_(text), par_(par), pos_(pos), - font_(text.getFont(par, pos)), +FontIterator::FontIterator(Buffer const & buffer, LyXText const & text, + Paragraph const & par, pos_type pos) + : buffer_(buffer), text_(text), par_(par), pos_(pos), + font_(text.getFont(buffer, par, pos)), endspan_(par.fontSpan(pos).last), bodypos_(par.beginOfBody()) {} @@ -46,7 +47,7 @@ FontIterator & FontIterator::operator++() { ++pos_; if (pos_ > endspan_ || pos_ == bodypos_) { - font_ = text_.getFont(par_, pos_); + font_ = text_.getFont(buffer_, par_, pos_); endspan_ = par_.fontSpan(pos_).last; } return *this; diff --git a/src/FontIterator.h b/src/FontIterator.h index 497915cea4..87686bdee1 100644 --- a/src/FontIterator.h +++ b/src/FontIterator.h @@ -27,6 +27,7 @@ namespace lyx { +class Buffer; class LyXText; class Paragraph; @@ -35,7 +36,8 @@ class FontIterator : std::iterator { public: /// - FontIterator(LyXText const & text, Paragraph const & par, pos_type pos); + FontIterator(Buffer const & buffer, LyXText const & text, + Paragraph const & par, pos_type pos); /// LyXFont const & operator*() const; /// @@ -44,6 +46,8 @@ public: LyXFont * operator->(); private: + /// + Buffer const & buffer_; /// LyXText const & text_; /// diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index aea3e0b20c..b6944bf746 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -516,7 +516,7 @@ bool updateCurrentLabel(Buffer const & buf, if (it == par_iterator_end(buf.inset())) return false; -// if (it.lastpit == 0 && LyXText::isMainText()) +// if (it.lastpit == 0 && LyXText::isMainText(buf)) // return false; switch (it->layout()->labeltype) { diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 474f4301a2..52ccfb6c8a 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -194,7 +194,7 @@ Point coordOffset(BufferView const & bv, DocIterator const & dit, for (size_t rit = 0; rit != rend; ++rit) y += par.rows()[rit].height(); y += par.rows()[rend].ascent(); - x += dit.bottom().text()->cursorX(dit.bottom(), boundary && dit.depth() == 1); + x += dit.bottom().text()->cursorX(*bv.buffer(), dit.bottom(), boundary && dit.depth() == 1); // FIXME: The following correction should not be there at all. // The cursor looks much better with the +1, though. ++x; diff --git a/src/coordcache.C b/src/coordcache.C index a970393368..b55b296ef1 100644 --- a/src/coordcache.C +++ b/src/coordcache.C @@ -49,11 +49,11 @@ void CoordCache::clear() } -Point CoordCache::get(LyXText const * text, pit_type pit) +Point CoordCache::get(LyXText const * text, pit_type pit) const { - ParPosCache::iterator const it = pars_.find(text); + ParPosCache::const_iterator const it = pars_.find(text); BOOST_ASSERT(it != pars_.end()); - InnerParPosCache::iterator const posit = it->second.find(pit); + InnerParPosCache::const_iterator const posit = it->second.find(pit); BOOST_ASSERT(posit != it->second.end()); return posit->second; } diff --git a/src/coordcache.h b/src/coordcache.h index a14751f6f0..dba9b89fd4 100644 --- a/src/coordcache.h +++ b/src/coordcache.h @@ -107,13 +107,13 @@ public: * updates. (x,y) == (0,0) is the upper left screen corner, x increases * to the right, y increases downwords. * The cache is built in BufferView::updateMetrics which is called - * from BufferView::Pimpl::update. The individual points are added + * from BufferView::update. The individual points are added * while we paint them. See for instance paintPar in RowPainter.C. */ class CoordCache { public: void clear(); - Point get(LyXText const *, pit_type); + Point get(LyXText const *, pit_type) const; /// A map from paragraph index number to screen point typedef std::map InnerParPosCache; diff --git a/src/cursor.C b/src/cursor.C index e63050cf7d..1d6e67442a 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -902,7 +902,7 @@ void LCursor::setTargetX() { // For now this is good enough. A better solution would be to // avoid this rebreak by setting cursorX only after drawing - bottom().text()->redoParagraph(bottom().pit()); + bottom().text()->redoParagraph(bv(), bottom().pit()); int x; int y; getPos(x, y); diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 249d6ddf3e..c7c53d090c 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -314,19 +314,19 @@ bool InsetBase::editing(BufferView * bv) const } -int InsetBase::xo(BufferView & bv) const +int InsetBase::xo(BufferView const & bv) const { return bv.coordCache().getInsets().x(this); } -int InsetBase::yo(BufferView & bv) const +int InsetBase::yo(BufferView const & bv) const { return bv.coordCache().getInsets().y(this); } -bool InsetBase::covers(BufferView & bv, int x, int y) const +bool InsetBase::covers(BufferView const & bv, int x, int y) const { //lyxerr << "InsetBase::covers, x: " << x << " y: " << y // << " xo: " << xo(bv) << " yo: " << yo() diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 55524e17c7..7ee3d24f17 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -120,13 +120,13 @@ public: /// add space for markers void metricsMarkers2(Dimension & dim, int framesize = 1) const; /// last drawn position for 'important' insets - int xo(BufferView & bv) const; + int xo(BufferView const & bv) const; /// last drawn position for 'important' insets - int yo(BufferView & bv) const; + int yo(BufferView const & bv) const; /// set x/y drawing position cache if available virtual void setPosCache(PainterInfo const &, int, int) const {} /// do we cover screen position x/y? - virtual bool covers(BufferView & bv, int x, int y) const; + virtual bool covers(BufferView const & bv, int x, int y) const; /// get the screen positions of the cursor (see note in cursor.C) virtual void cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const; @@ -352,7 +352,7 @@ public: /// should we break lines after this inset? virtual bool isLineSeparator() const { return false; } /// should paragraph indendation be ommitted in any case? - virtual bool neverIndent() const { return false; } + virtual bool neverIndent(Buffer const &) const { return false; } /// dumps content to lyxerr virtual void dump() const; /// write inset in .lyx format diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index 448feb4ce2..00a69ca455 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -80,7 +80,7 @@ public: /// bool forceDefaultParagraphs(idx_type) const; /// - bool neverIndent() const { return true; } + bool neverIndent(Buffer const &) const { return true; } /// bool noFontChange() const { return true; } /// diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 7b4fb92c1d..723b9cf6b0 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -32,7 +32,7 @@ public: /// virtual bool display() const; /// - virtual bool neverIndent() const { return true; } + virtual bool neverIndent(Buffer const &) const { return true; } /// virtual InsetBase::Code lyxCode() const; /// diff --git a/src/insets/insetcharstyle.h b/src/insets/insetcharstyle.h index 8b518e7d8d..404e44ad40 100644 --- a/src/insets/insetcharstyle.h +++ b/src/insets/insetcharstyle.h @@ -94,7 +94,7 @@ public: InsetCharStyleParams const & params() const { return params_; } /// should paragraph indendation be ommitted in any case? - bool neverIndent() const { return true; } + bool neverIndent(Buffer const &) const { return true; } protected: InsetCharStyle(InsetCharStyle const &); diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 0fcff10f08..cf573a1195 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -73,7 +73,7 @@ public: /// bool forceDefaultParagraphs(idx_type) const { return true; } /// should paragraph indendation be ommitted in any case? - bool neverIndent() const { return true; } + bool neverIndent(Buffer const &) const { return true; } protected: InsetERT(InsetERT const &); /// diff --git a/src/insets/insetoptarg.h b/src/insets/insetoptarg.h index 032fe2dae1..c10f18cdb7 100644 --- a/src/insets/insetoptarg.h +++ b/src/insets/insetoptarg.h @@ -50,7 +50,7 @@ public: void write(Buffer const & buf, std::ostream & os) const; /// should paragraph indendation be ommitted in any case? - virtual bool neverIndent() const { return true; } + virtual bool neverIndent(Buffer const &) const { return true; } protected: InsetOptArg(InsetOptArg const &); private: diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 58a5b5c979..bc7888fe3e 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -573,7 +573,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) cur.idx() = tabular.getCellBelow(cur.idx()); cur.pit() = 0; cur.pos() = cell(cur.idx())->getText(0)->x2pos( - cur.pit(), 0, cur.targetX()); + cur.bv(), cur.pit(), 0, cur.targetX()); } if (sl == cur.top()) { // we trick it to go to the RIGHT after leaving the @@ -596,6 +596,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) cur.pit() = cur.lastpit(); LyXText const * text = cell(cur.idx())->getText(0); cur.pos() = text->x2pos( + cur.bv(), cur.pit(), text->paragraphs().back().rows().size()-1, cur.targetX()); @@ -1938,6 +1939,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf, if (buf.length() <= 0) return true; + Buffer const & buffer = *bv.buffer(); + col_type cols = 1; row_type rows = 1; col_type maxCols = 1; @@ -1966,7 +1969,7 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf, row_type row = 0; if (usePaste) { paste_tabular.reset( - new LyXTabular(bv.buffer()->params(), rows, maxCols)); + new LyXTabular(buffer.params(), rows, maxCols)); loctab = paste_tabular.get(); cols = 0; dirtyTabularStack(true); @@ -1994,11 +1997,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf, // we can only set this if we are not too far right if (cols < columns) { shared_ptr inset = loctab->getCellInset(cell); - inset->setViewCache(&bv); Paragraph & par = inset->text_.getPar(0); - LyXFont const font = inset->text_.getFont(par, 0); + LyXFont const font = inset->text_.getFont(buffer, par, 0); inset->setText(buf.substr(op, p - op), font, - bv.buffer()->params().trackChanges); + buffer.params().trackChanges); ++cols; ++cell; } @@ -2007,11 +2009,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf, // we can only set this if we are not too far right if (cols < columns) { shared_ptr inset = tabular.getCellInset(cell); - inset->setViewCache(&bv); Paragraph & par = inset->text_.getPar(0); - LyXFont const font = inset->text_.getFont(par, 0); + LyXFont const font = inset->text_.getFont(buffer, par, 0); inset->setText(buf.substr(op, p - op), font, - bv.buffer()->params().trackChanges); + buffer.params().trackChanges); } cols = ocol; ++row; @@ -2025,11 +2026,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf, // check for the last cell if there is no trailing '\n' if (cell < cells && op < len) { shared_ptr inset = loctab->getCellInset(cell); - inset->setViewCache(&bv); Paragraph & par = inset->text_.getPar(0); - LyXFont const font = inset->text_.getFont(par, 0); + LyXFont const font = inset->text_.getFont(buffer, par, 0); inset->setText(buf.substr(op, len - op), font, - bv.buffer()->params().trackChanges); + buffer.params().trackChanges); } return true; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 96c7dcdf8e..d8c7718f0b 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -88,7 +88,7 @@ InsetText::InsetText(BufferParams const & bp) InsetText::InsetText(InsetText const & in) - : InsetOld(in), text_(in.text_.bv_owner) + : InsetOld(in), text_() { text_.autoBreakRows_ = in.text_.autoBreakRows_; drawFrame_ = in.drawFrame_; @@ -167,7 +167,6 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const { //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl; - setViewCache(mi.base.bv); mi.base.textwidth -= 2 * border_; font_ = mi.base.font; // Hand font through to contained lyxtext: @@ -211,7 +210,7 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const } -bool InsetText::covers(BufferView & bv, int x, int y) const +bool InsetText::covers(BufferView const & bv, int x, int y) const { return bv.coordCache().getInsets().has(this) && x >= xo(bv) @@ -230,7 +229,6 @@ docstring const InsetText::editMessage() const void InsetText::edit(LCursor & cur, bool left) { //lyxerr << "InsetText: edit left/right" << endl; - setViewCache(&cur.bv()); int const pit = left ? 0 : paragraphs().size() - 1; int const pos = left ? 0 : paragraphs().back().size(); text_.setCursor(cur.top(), pit, pos); @@ -250,7 +248,6 @@ void InsetText::doDispatch(LCursor & cur, FuncRequest & cmd) lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION << " [ cmd.action = " << cmd.action << ']' << endl; - setViewCache(&cur.bv()); text_.dispatch(cur, cmd); } @@ -338,10 +335,10 @@ void InsetText::validate(LaTeXFeatures & features) const } -void InsetText::cursorPos(BufferView const & /*bv*/, +void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = text_.cursorX(sl, boundary) + border_; + x = text_.cursorX(*bv.buffer(), sl, boundary) + border_; y = text_.cursorY(sl, boundary); } @@ -400,16 +397,6 @@ void InsetText::setFrameColor(LColor_color col) } -void InsetText::setViewCache(BufferView const * bv) const -{ - if (bv && bv != text_.bv_owner) { - //lyxerr << "setting view cache from " - // << text_.bv_owner << " to " << bv << "\n"; - text_.bv_owner = const_cast(bv); - } -} - - void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist) { // There is little we can do here to keep track of changes. @@ -446,10 +433,10 @@ void InsetText::addPreview(PreviewLoader & loader) const //FIXME: instead of this hack, which only works by chance, // cells should have their own insetcell type, which returns CELL_CODE! -bool InsetText::neverIndent() const +bool InsetText::neverIndent(Buffer const & buffer) const { // this is only true for tabular cells - return !text_.isMainText() && lyxCode() == TEXT_CODE; + return !text_.isMainText(buffer) && lyxCode() == TEXT_CODE; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 0b33eb23eb..1baf6fc9fb 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -56,7 +56,7 @@ public: /// draw inset selection void drawSelection(PainterInfo & pi, int x, int y) const; /// are we inside the area covered by the inset? - virtual bool covers(BufferView & bv, int x, int y) const; + virtual bool covers(BufferView const & bv, int x, int y) const; /// virtual docstring const editMessage() const; /// @@ -92,8 +92,6 @@ public: /// void setFrameColor(LColor_color); /// - void setViewCache(BufferView const * bv) const; - /// bool showInsetDialog(BufferView *) const; /// LyXText * getText(int i) const { @@ -131,7 +129,7 @@ public: /// bool allowSpellCheck() const { return true; } /// should paragraph indendation be ommitted in any case? - bool neverIndent() const; + bool neverIndent(Buffer const &) const; /// InsetText(InsetText const &); /// diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3d249d36ca..3c1a0f8a6a 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -229,8 +229,8 @@ void LyXFunc::handleKeyFunc(kb_action action) if (keyseq->length()) c = 0; - lyx_view_->view()->getIntl().getTransManager() - .deadkey(c, get_accent(action).accent, view()->getLyXText()); + lyx_view_->view()->getIntl().getTransManager().deadkey( + c, get_accent(action).accent, view()->getLyXText(), view()->cursor()); // Need to clear, in case the minibuffer calls these // actions keyseq->clear(); diff --git a/src/lyxtext.h b/src/lyxtext.h index 0ec15272d3..3fba327362 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -52,29 +52,32 @@ class Spacing; class LyXText { public: /// constructor - explicit LyXText(BufferView *); + explicit LyXText(BufferView * bv = 0); /// void init(BufferView *); /// - LyXFont getFont(Paragraph const & par, pos_type pos) const; + LyXFont getFont(Buffer const & buffer, Paragraph const & par, + pos_type pos) const; /// - void applyOuterFont(LyXFont &) const; + void applyOuterFont(Buffer const & buffer, LyXFont &) const; /// - LyXFont getLayoutFont(pit_type pit) const; + LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const; /// - LyXFont getLabelFont(Paragraph const & par) const; + LyXFont getLabelFont(Buffer const & buffer, + Paragraph const & par) const; /// - void setCharFont(pit_type pit, pos_type pos, LyXFont const & font); + void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos, + LyXFont const & font); /// - void setCharFont(pit_type pit, pos_type pos, LyXFont const & font, - bool toggleall); + void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos, + LyXFont const & font, bool toggleall); /// what you expect when pressing at cursor position void breakParagraph(LCursor & cur, bool keep_layout = false); /// set layout over selection - void setLayout(pit_type start, pit_type end, + void setLayout(Buffer const & buffer, pit_type start, pit_type end, std::string const & layout); /// void setLayout(LCursor & cur, std::string const & layout); @@ -94,10 +97,10 @@ public: void setFont(LCursor & cur, LyXFont const &, bool toggleall = false); /// rebreaks the given par - bool redoParagraph(pit_type pit); + bool redoParagraph(BufferView &, pit_type pit); /// returns pos in given par at given x coord - pos_type x2pos(pit_type pit, int row, int x) const; + pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const; int pos2x(pit_type pit, pos_type pos) const; /// @@ -124,9 +127,6 @@ public: bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status) const; - /// access to out BufferView. This should go... - BufferView * bv() const; - /// read-only access to individual paragraph Paragraph const & getPar(pit_type pit) const { return pars_[pit]; } /// read-write access to individual paragraph @@ -137,13 +137,14 @@ public: /** returns row near the specified * y-coordinate in given paragraph (relative to the screen). */ - Row const & getRowNearY(int y, pit_type pit) const; - pit_type getPitNearY(int y) const; + Row const & getRowNearY(BufferView const & bv, int y, + pit_type pit) const; + pit_type getPitNearY(BufferView const & bv, int y) const; /** returns the column near the specified x-coordinate of the row x is set to the real beginning of this column */ - pos_type getColumnNearX(pit_type pit, + pos_type getColumnNearX(BufferView const & bv, pit_type pit, Row const & row, int & x, bool & boundary) const; /** Find the word under \c from in the relative location @@ -172,9 +173,9 @@ public: void setCurrentFont(LCursor & cur); /// - void recUndo(pit_type first, pit_type last) const; + void recUndo(LCursor & cur, pit_type first, pit_type last) const; /// - void recUndo(pit_type first) const; + void recUndo(LCursor & cur, pit_type first) const; /// returns true if par was empty and was removed bool setCursorFromCoordinates(LCursor & cur, int x, int y); /// @@ -269,12 +270,13 @@ public: int height() const; /// Returns an inset if inset was hit, or 0 if not. - InsetBase * checkInsetHit(int x, int y) const; + InsetBase * checkInsetHit(BufferView const &, int x, int y) const; /// - int singleWidth(Paragraph const & par, pos_type pos) const; + int singleWidth(Buffer const &, Paragraph const & par, + pos_type pos) const; /// - int singleWidth(Paragraph const & par, + int singleWidth(Buffer const &, Paragraph const & par, pos_type pos, char_type c, LyXFont const & Font) const; /// return the color of the canvas @@ -286,20 +288,21 @@ public: * in LaTeX the beginning of the text fits in some cases * (for example sections) exactly the label-width. */ - int leftMargin(pit_type pit, pos_type pos) const; - int leftMargin(pit_type pit) const; + int leftMargin(Buffer const &, pit_type pit, pos_type pos) const; + int leftMargin(Buffer const &, pit_type pit) const; /// - int rightMargin(Paragraph const & par) const; + int rightMargin(Buffer const &, Paragraph const & par) const; /** this calculates the specified parameters. needed when setting * the cursor and when creating a visible row */ - RowMetrics computeRowMetrics(pit_type pit, Row const & row) const; + RowMetrics computeRowMetrics(Buffer const &, pit_type pit, + Row const & row) const; /// access to our paragraphs ParagraphList const & paragraphs() const { return pars_; } ParagraphList & paragraphs() { return pars_; } /// return true if this is the main text - bool isMainText() const; + bool isMainText(Buffer const &) const; /// return first row of text Row const & firstRow() const; @@ -310,11 +313,11 @@ public: bool isFirstRow(pit_type pit, Row const & row) const; /// - double spacing(Paragraph const & par) const; + double spacing(Buffer const & buffer, Paragraph const & par) const; /// make a suggestion for a label std::string getPossibleLabel(LCursor & cur) const; /// is this paragraph right-to-left? - bool isRTL(Paragraph const & par) const; + bool isRTL(Buffer const &, Paragraph const & par) const; /// bool checkAndActivateInset(LCursor & cur, bool front); @@ -328,7 +331,8 @@ public: /// int descent() const; /// - int cursorX(CursorSlice const & cursor, bool boundary) const; + int cursorX(Buffer const &, CursorSlice const & cursor, + bool boundary) const; /// int cursorY(CursorSlice const & cursor, bool boundary) const; @@ -347,9 +351,6 @@ public: /// int background_color_; - /// only the top-level LyXText has this non-zero - BufferView * bv_owner; - /// mutable Bidi bidi; /// @@ -367,7 +368,7 @@ private: pit_type undoSpan(pit_type pit); /// Calculate and set the height of the row - void setHeightOfRow(pit_type, Row & row); + void setHeightOfRow(BufferView const &, pit_type, Row & row); // fix the cursor `cur' after a characters has been deleted at `where' // position. Called by deleteEmptyParagraphMechanism @@ -382,13 +383,13 @@ private: /// sets row.end to the pos value *after* which a row should break. /// for example, the pos after which isNewLine(pos) == true - void rowBreakPoint(pit_type pit, Row & row) const; + void rowBreakPoint(Buffer const &, pit_type pit, Row & row) const; /// sets row.width to the minimum space a row needs on the screen in pixel - void setRowWidth(pit_type pit, Row & row) const; + void setRowWidth(Buffer const &, pit_type pit, Row & row) const; /// the minimum space a manual label needs on the screen in pixels - int labelFill(Paragraph const & par, Row const & row) const; + int labelFill(Buffer const &, Paragraph const & par, Row const & row) const; /// FIXME - int labelEnd(pit_type pit) const; + int labelEnd(Buffer const &, pit_type pit) const; /// void charInserted(); diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index a8b31f9b6e..731a7753d2 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -407,7 +407,7 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const } -int MathArray::dist(BufferView & bv, int x, int y) const +int MathArray::dist(BufferView const & bv, int x, int y) const { int xx = 0; int yy = 0; @@ -436,13 +436,13 @@ void MathArray::setXY(BufferView & bv, int x, int y) const } -int MathArray::xo(BufferView & bv) const +int MathArray::xo(BufferView const & bv) const { return bv.coordCache().getArrays().x(this); } -int MathArray::yo(BufferView & bv) const +int MathArray::yo(BufferView const & bv) const { return bv.coordCache().getArrays().y(this); } diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index b808dba579..678e9976d5 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -117,13 +117,13 @@ public: void touch() const; /// access to cached x coordinate of last drawing - int xo(BufferView & bv) const; + int xo(BufferView const & bv) const; /// access to cached y coordinate of last drawing - int yo(BufferView & bv) const; + int yo(BufferView const & bv) const; /// access to cached x coordinate of mid point of last drawing - int xm(BufferView & bv) const { return xo(bv) + dim_.wid / 2; } + int xm(BufferView const & bv) const { return xo(bv) + dim_.wid / 2; } /// access to cached y coordinate of mid point of last drawing - int ym(BufferView & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; } + int ym(BufferView const & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; } /// write access to coordinate; void setXY(BufferView & bv, int x, int y) const; /// returns x coordinate of given position in the array @@ -136,7 +136,7 @@ public: size_type x2pos(int targetx, int glue) const; /// returns distance of this cell to the point given by x and y // assumes valid position and size cache - int dist(BufferView & bv, int x, int y) const; + int dist(BufferView const & bv, int x, int y) const; /// ascent of this cell above the baseline int ascent() const { return dim_.asc; } diff --git a/src/rowpainter.C b/src/rowpainter.C index d69bbf3267..f29b51e1d5 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -129,7 +129,7 @@ RowPainter::RowPainter(PainterInfo & pi, erased_(pi.erased_), xo_(x), yo_(y), width_(text_.width()) { - RowMetrics m = text_.computeRowMetrics(pit, row_); + RowMetrics m = text_.computeRowMetrics(*bv_.buffer(), pit, row_); x_ = m.x + xo_; //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl; @@ -146,13 +146,13 @@ RowPainter::RowPainter(PainterInfo & pi, LyXFont const RowPainter::getLabelFont() const { - return text_.getLabelFont(par_); + return text_.getLabelFont(*bv_.buffer(), par_); } int RowPainter::leftMargin() const { - return text_.leftMargin(pit_, row_.pos()); + return text_.leftMargin(*bv_.buffer(), pit_, row_.pos()); } @@ -203,7 +203,8 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font) if (!Encodings::isComposeChar_hebrew(c)) { if (isPrintableNonspace(c)) { int const width2 = - text_.singleWidth(par_, i, c, text_.getFont(par_, i)); + text_.singleWidth(*bv_.buffer(), par_, i, c, + text_.getFont(*bv_.buffer(), par_, i)); // FIXME UNICODE // This does not work anymore, and non-ascii // characters in source files are forbidden @@ -242,7 +243,8 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font) if (!Encodings::isComposeChar_arabic(c)) { if (isPrintableNonspace(c)) { int const width2 = - text_.singleWidth(par_, i, c, text_.getFont(par_, i)); + text_.singleWidth(*bv_.buffer(), par_, i, c, + text_.getFont(*bv_.buffer(), par_, i)); dx = (width2 - width) / 2; } break; @@ -328,7 +330,7 @@ void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc) void RowPainter::paintFromPos(pos_type & vpos) { pos_type const pos = text_.bidi.vis2log(vpos); - LyXFont orig_font = text_.getFont(par_, pos); + LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos); double const orig_x = x_; @@ -423,7 +425,7 @@ void RowPainter::paintDepthBar() int const w = nestMargin() / 5; int x = int(xo_) + w * i; // only consider the changebar space if we're drawing outermost text - if (text_.isMainText()) + if (text_.isMainText(*bv_.buffer())) x += changebarMargin(); int const starty = yo_ - row_.ascent(); @@ -494,7 +496,7 @@ void RowPainter::paintFirst() } } - bool const is_rtl = text_.isRTL(par_); + bool const is_rtl = text_.isRTL(buffer, par_); bool const is_seq = isFirstInSequence(pit_, text_.paragraphs()); //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl; @@ -576,7 +578,7 @@ void RowPainter::paintFirst() if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) { if (is_rtl) x = leftMargin(); - x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2; + x += (width_ - text_.rightMargin(buffer, par_) - leftMargin()) / 2; x -= fm.width(str) / 2; } else if (is_rtl) { x = width_ - leftMargin() - fm.width(str); @@ -589,7 +591,7 @@ void RowPainter::paintFirst() void RowPainter::paintLast() { - bool const is_rtl = text_.isRTL(par_); + bool const is_rtl = text_.isRTL(*bv_.buffer(), par_); int const endlabel = getEndLabel(pit_, text_.paragraphs()); // draw an endlabel @@ -618,7 +620,7 @@ void RowPainter::paintLast() docstring const & str = par_.layout()->endlabelstring(); double const x = is_rtl ? x_ - fm.width(str) - : - text_.rightMargin(par_) - row_.width(); + : - text_.rightMargin(*bv_.buffer(), par_) - row_.width(); pain_.text(int(x), yo_, str, font); break; } @@ -647,6 +649,7 @@ void RowPainter::paintText() // Use font span to speed things up, see below FontSpan font_span; LyXFont font; + Buffer const & buffer = *bv_.buffer(); for (pos_type vpos = row_.pos(); vpos < end; ) { if (x_ > bv_.workWidth()) @@ -662,11 +665,11 @@ void RowPainter::paintText() // Use font span to speed things up, see above if (vpos < font_span.first || vpos > font_span.last) { font_span = par_.fontSpan(vpos); - font = text_.getFont(par_, vpos); + font = text_.getFont(buffer, par_, vpos); } - const int width_pos = - text_.singleWidth(par_, pos, par_.getChar(pos), font); + const int width_pos = text_.singleWidth(buffer, par_, pos, + par_.getChar(pos), font); if (x_ + width_pos < 0) { x_ += width_pos; @@ -872,7 +875,7 @@ void paintPar // Instrumentation for testing row cache (see also // 12 lines lower): - if (text.isMainText()) + if (text.isMainText(*pi.base.bv->buffer())) lyxerr[Debug::PAINTING] << "#"; else lyxerr[Debug::PAINTING] << "[" << @@ -904,7 +907,8 @@ void paintText(BufferView & bv, Painter & pain) { BOOST_ASSERT(bv.buffer()); - LyXText & text = bv.buffer()->text(); + Buffer const & buffer = *bv.buffer(); + LyXText & text = buffer.text(); bool const select = bv.cursor().selection(); ViewMetricsInfo const & vi = bv.viewMetricsInfo(); @@ -936,13 +940,13 @@ void paintText(BufferView & bv, // Try viewing the User Guide Mobius figure if (vi.p1 > 0) { - text.redoParagraph(vi.p1 - 1); + text.redoParagraph(bv, vi.p1 - 1); bv.coordCache().parPos()[&text][vi.p1 - 1] = Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent()); } if (vi.p2 < pit_type(text.paragraphs().size()) - 1) { - text.redoParagraph(vi.p2 + 1); + text.redoParagraph(bv, vi.p2 + 1); bv.coordCache().parPos()[&text][vi.p2 + 1] = Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent()); } diff --git a/src/tabular.C b/src/tabular.C index bb185489b9..259f93bcf3 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -956,15 +956,14 @@ void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth) return; // merge all paragraphs to one - BufferParams const & bp = - inset->getText(0)->bv_owner->buffer()->params(); + BufferParams const & bp = cur.bv().buffer()->params(); while (inset->paragraphs().size() > 1) mergeParagraph(bp, inset->paragraphs(), 0); // reset layout cur.push(*inset); // undo information has already been recorded - inset->getText(0)->setLayout(0, cur.lastpit() + 1, + inset->getText(0)->setLayout(*cur.bv().buffer(), 0, cur.lastpit() + 1, bp.getLyXTextClass().defaultLayoutName()); cur.pop(); } diff --git a/src/text.C b/src/text.C index 9b806455a2..6a8ae7f620 100644 --- a/src/text.C +++ b/src/text.C @@ -403,17 +403,11 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, -BufferView * LyXText::bv() const -{ - BOOST_ASSERT(bv_owner != 0); - return bv_owner; -} - - -double LyXText::spacing(Paragraph const & par) const +double LyXText::spacing(Buffer const & buffer, + Paragraph const & par) const { if (par.params().spacing().isDefault()) - return bv()->buffer()->params().spacing().getValue(); + return buffer.params().spacing().getValue(); return par.params().spacing().getValue(); } @@ -430,13 +424,15 @@ int LyXText::height() const } -int LyXText::singleWidth(Paragraph const & par, pos_type pos) const +int LyXText::singleWidth(Buffer const & buffer, Paragraph const & par, + pos_type pos) const { - return singleWidth(par, pos, par.getChar(pos), getFont(par, pos)); + return singleWidth(buffer, par, pos, par.getChar(pos), + getFont(buffer, par, pos)); } -int LyXText::singleWidth(Paragraph const & par, +int LyXText::singleWidth(Buffer const & buffer, Paragraph const & par, pos_type pos, char_type c, LyXFont const & font) const { // The most common case is handled first (Asger) @@ -463,15 +459,16 @@ int LyXText::singleWidth(Paragraph const & par, } -int LyXText::leftMargin(pit_type pit) const +int LyXText::leftMargin(Buffer const & buffer, pit_type pit) const { BOOST_ASSERT(pit >= 0); BOOST_ASSERT(pit < int(pars_.size())); - return leftMargin(pit, pars_[pit].size()); + return leftMargin(buffer, pit, pars_[pit].size()); } -int LyXText::leftMargin(pit_type const pit, pos_type const pos) const +int LyXText::leftMargin(Buffer const & buffer, + pit_type const pit, pos_type const pos) const { BOOST_ASSERT(pit >= 0); BOOST_ASSERT(pit < int(pars_.size())); @@ -479,27 +476,26 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const BOOST_ASSERT(pos >= 0); BOOST_ASSERT(pos <= par.size()); //lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl; - BufferParams const & params = bv()->buffer()->params(); - LyXTextClass const & tclass = params.getLyXTextClass(); + LyXTextClass const & tclass = buffer.params().getLyXTextClass(); LyXLayout_ptr const & layout = par.layout(); string parindent = layout->parindent; int l_margin = 0; - if (isMainText()) + if (isMainText(buffer)) l_margin += changebarMargin(); // FIXME UNICODE docstring leftm = from_utf8(tclass.leftmargin()); - l_margin += theFontMetrics(params.getFont()).signedWidth(leftm); + l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm); if (par.getDepth() != 0) { // find the next level paragraph pit_type newpar = outerHook(pit, pars_); if (newpar != pit_type(pars_.size())) { if (pars_[newpar].layout()->isEnvironment()) { - l_margin = leftMargin(newpar); + l_margin = leftMargin(buffer, newpar); } if (par.layout() == tclass.defaultLayout()) { if (pars_[newpar].params().noindent()) @@ -517,7 +513,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const && pit > 0 && pars_[pit - 1].layout()->nextnoindent) parindent.erase(); - LyXFont const labelfont = getLabelFont(par); + LyXFont const labelfont = getLabelFont(buffer, par); FontMetrics const & labelfont_metrics = theFontMetrics(labelfont); switch (layout->margintype) { @@ -525,7 +521,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const if (!layout->leftmargin.empty()) { // FIXME UNICODE docstring leftm = from_utf8(layout->leftmargin); - l_margin += theFontMetrics(params.getFont()).signedWidth(leftm); + l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm); } if (!par.getLabelstring().empty()) { // FIXME UNICODE @@ -557,7 +553,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const case MARGIN_STATIC: { // FIXME UNICODE docstring leftm = from_utf8(layout->leftmargin); - l_margin += theFontMetrics(params.getFont()).signedWidth(leftm) + l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm) * 4 / (par.getDepth() + 4); break; } @@ -634,33 +630,33 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const && align == LYX_ALIGN_BLOCK && !par.params().noindent() // in some insets, paragraphs are never indented - && !(par.inInset() && par.inInset()->neverIndent()) + && !(par.inInset() && par.inInset()->neverIndent(buffer)) // display style insets are always centered, omit indentation && !(!par.empty() && par.isInset(pos) && par.getInset(pos)->display()) && (par.layout() != tclass.defaultLayout() - || bv()->buffer()->params().paragraph_separation == + || buffer.params().paragraph_separation == BufferParams::PARSEP_INDENT)) { docstring din = from_utf8(parindent); - l_margin += theFontMetrics(params.getFont()).signedWidth(din); + l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(din); } return l_margin; } -int LyXText::rightMargin(Paragraph const & par) const +int LyXText::rightMargin(Buffer const & buffer, Paragraph const & par) const { // FIXME: the correct way is to only call rightMargin() only // within the main LyXText. The following test is thus bogus. - LyXText const & text = bv()->buffer()->text(); + LyXText const & text = buffer.text(); // We do not want rightmargins on inner texts. if (&text != this) return 0; - BufferParams const & params = bv()->buffer()->params(); + BufferParams const & params = buffer.params(); LyXTextClass const & tclass = params.getLyXTextClass(); docstring trmarg = from_utf8(tclass.rightmargin()); docstring lrmarg = from_utf8(par.layout()->rightmargin); @@ -675,13 +671,13 @@ int LyXText::rightMargin(Paragraph const & par) const } -int LyXText::labelEnd(pit_type const pit) const +int LyXText::labelEnd(Buffer const & buffer, pit_type const pit) const { // labelEnd is only needed if the layout fills a flushleft label. if (pars_[pit].layout()->margintype != MARGIN_MANUAL) return 0; // return the beginning of the body - return leftMargin(pit); + return leftMargin(buffer, pit); } @@ -702,7 +698,8 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par) }; -void LyXText::rowBreakPoint(pit_type const pit, Row & row) const +void LyXText::rowBreakPoint(Buffer const & buffer, pit_type const pit, + Row & row) const { Paragraph const & par = pars_[pit]; pos_type const end = par.size(); @@ -713,7 +710,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const } // maximum pixel width of a row - int width = maxwidth_ - rightMargin(par); // - leftMargin(pit, row); + int width = maxwidth_ - rightMargin(buffer, par); // - leftMargin(buffer, pit, row); if (width < 0) { row.endpos(end); return; @@ -733,28 +730,28 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const // or the end of the par, then choose the possible break // nearest that. - int const left = leftMargin(pit, pos); + int const left = leftMargin(buffer, pit, pos); int x = left; // pixel width since last breakpoint int chunkwidth = 0; - FontIterator fi = FontIterator(*this, par, pos); + FontIterator fi = FontIterator(buffer, *this, par, pos); pos_type point = end; pos_type i = pos; - FontMetrics const & fm = theFontMetrics(getLabelFont(par)); + FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par)); for ( ; i < end; ++i, ++fi) { char_type const c = par.getChar(i); - int thiswidth = singleWidth(par, i, c, *fi); + int thiswidth = singleWidth(buffer, par, i, c, *fi); // add the auto-hfill from label end to the body if (body_pos && i == body_pos) { docstring lsep = from_utf8(layout->labelsep); int add = fm.width(lsep); if (par.isLineSeparator(i - 1)) - add -= singleWidth(par, i - 1); + add -= singleWidth(buffer, par, i - 1); - add = std::max(add, labelEnd(pit) - x); + add = std::max(add, labelEnd(buffer, pit) - x); thiswidth += add; } @@ -817,47 +814,48 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const } -void LyXText::setRowWidth(pit_type const pit, Row & row) const +void LyXText::setRowWidth(Buffer const & buffer, pit_type const pit, Row & row) const { // get the pure distance pos_type const end = row.endpos(); Paragraph const & par = pars_[pit]; docstring const labelsep = from_utf8(par.layout()->labelsep); - int w = leftMargin(pit, row.pos()); + int w = leftMargin(buffer, pit, row.pos()); pos_type const body_pos = par.beginOfBody(); pos_type i = row.pos(); - FontMetrics const & fm = theFontMetrics(getLabelFont(par)); + FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par)); if (i < end) { - FontIterator fi = FontIterator(*this, par, i); + FontIterator fi = FontIterator(buffer, *this, par, i); for ( ; i < end; ++i, ++fi) { if (body_pos > 0 && i == body_pos) { w += fm.width(labelsep); if (par.isLineSeparator(i - 1)) - w -= singleWidth(par, i - 1); - w = max(w, labelEnd(pit)); + w -= singleWidth(buffer, par, i - 1); + w = max(w, labelEnd(buffer, pit)); } char_type const c = par.getChar(i); - w += singleWidth(par, i, c, *fi); + w += singleWidth(buffer, par, i, c, *fi); } } if (body_pos > 0 && body_pos >= end) { w += fm.width(labelsep); if (end > 0 && par.isLineSeparator(end - 1)) - w -= singleWidth(par, end - 1); - w = max(w, labelEnd(pit)); + w -= singleWidth(buffer, par, end - 1); + w = max(w, labelEnd(buffer, pit)); } - row.width(w + rightMargin(par)); + row.width(w + rightMargin(buffer, par)); } // returns the minimum space a manual label needs on the screen in pixel -int LyXText::labelFill(Paragraph const & par, Row const & row) const +int LyXText::labelFill(Buffer const & buffer, Paragraph const & par, + Row const & row) const { pos_type last = par.beginOfBody(); @@ -872,13 +870,13 @@ int LyXText::labelFill(Paragraph const & par, Row const & row) const int w = 0; for (pos_type i = row.pos(); i <= last; ++i) - w += singleWidth(par, i); + w += singleWidth(buffer, par, i); docstring const & label = par.params().labelWidthString(); if (label.empty()) return 0; - FontMetrics const & fm = theFontMetrics(getLabelFont(par)); + FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par)); return max(0, fm.width(label) - w); } @@ -890,7 +888,8 @@ LColor_color LyXText::backgroundColor() const } -void LyXText::setHeightOfRow(pit_type const pit, Row & row) +void LyXText::setHeightOfRow(BufferView const & bv, pit_type const pit, + Row & row) { Paragraph const & par = pars_[pit]; // get the maximum ascent and the maximum descent @@ -907,19 +906,21 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) // increase but not decrease the height. Just some point to // start with so we don't have to do the assignment below too // often. - LyXFont font = getFont(par, row.pos()); + Buffer const & buffer = *bv.buffer(); + LyXFont font = getFont(buffer, par, row.pos()); LyXFont::FONT_SIZE const tmpsize = font.size(); - font = getLayoutFont(pit); + font = getLayoutFont(buffer, pit); LyXFont::FONT_SIZE const size = font.size(); font.setSize(tmpsize); - LyXFont labelfont = getLabelFont(par); + LyXFont labelfont = getLabelFont(buffer, par); FontMetrics const & labelfont_metrics = theFontMetrics(labelfont); FontMetrics const & fontmetrics = theFontMetrics(font); // these are minimum values - double const spacing_val = layout->spacing.getValue() * spacing(par); + double const spacing_val = layout->spacing.getValue() + * spacing(*bv.buffer(), par); //lyxerr << "spacing_val = " << spacing_val << endl; int maxasc = int(fontmetrics.maxAscent() * spacing_val); int maxdesc = int(fontmetrics.maxDescent() * spacing_val); @@ -956,16 +957,17 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) // is it a top line? if (row.pos() == 0) { - BufferParams const & bufparams = bv()->buffer()->params(); + Buffer const & buffer = *bv.buffer(); + BufferParams const & bufparams = buffer.params(); // some parksips VERY EASY IMPLEMENTATION - if (bv()->buffer()->params().paragraph_separation + if (bufparams.paragraph_separation == BufferParams::PARSEP_SKIP && pit != 0 && ((layout->isParagraph() && par.getDepth() == 0) || (pars_[pit - 1].layout()->isParagraph() && pars_[pit - 1].getDepth() == 0))) { - maxasc += bufparams.getDefSkip().inPixels(*bv()); + maxasc += bufparams.getDefSkip().inPixels(bv); } if (par.params().startOfAppendix()) @@ -977,7 +979,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) && !par.params().labelString().empty()) { labeladdon = int(labelfont_metrics.maxHeight() * layout->spacing.getValue() - * spacing(par)); + * spacing(buffer, par)); } // special code for the top label @@ -990,7 +992,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) labeladdon = int( labelfont_metrics.maxHeight() * layout->spacing.getValue() - * spacing(par) + * spacing(*bv.buffer(), par) + (layout->topsep + layout->labelbottomsep) * dh); } @@ -1056,7 +1058,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) // FIXME: the correct way is to do the following is to move the // following code in another method specially tailored for the // main LyXText. The following test is thus bogus. - LyXText const & text = bv_owner->buffer()->text(); + LyXText const & text = buffer.text(); // Top and bottom margin of the document (only at top-level) if (&text == this) { if (pit == 0 && row.pos() == 0) @@ -1092,7 +1094,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) return; // a layout change may affect also the following paragraph - recUndo(cur.pit(), undoSpan(cur.pit()) - 1); + recUndo(cur, cur.pit(), undoSpan(cur.pit()) - 1); // Always break behind a space // It is better to erase the space (Dekel) @@ -1168,6 +1170,7 @@ void LyXText::insertChar(LCursor & cur, char_type c) recordUndo(cur, Undo::INSERT); + Buffer const & buffer = cur.buffer(); Paragraph & par = cur.paragraph(); // try to remove this pit_type const pit = cur.pit(); @@ -1185,8 +1188,8 @@ void LyXText::insertChar(LCursor & cur, char_type c) !(contains(number_seperators, c) && cur.pos() != 0 && cur.pos() != cur.lastpos() && - getFont(par, cur.pos()).number() == LyXFont::ON && - getFont(par, cur.pos() - 1).number() == LyXFont::ON) + getFont(buffer, par, cur.pos()).number() == LyXFont::ON && + getFont(buffer, par, cur.pos() - 1).number() == LyXFont::ON) ) number(cur); // Set current_font.number to OFF } else if (isDigit(c) && @@ -1200,11 +1203,11 @@ void LyXText::insertChar(LCursor & cur, char_type c) || par.isSeparator(cur.pos() - 2) || par.isNewline(cur.pos() - 2)) ) { - setCharFont(pit, cur.pos() - 1, current_font); + setCharFont(buffer, pit, cur.pos() - 1, current_font); } else if (contains(number_seperators, c) && cur.pos() >= 2 - && getFont(par, cur.pos() - 2).number() == LyXFont::ON) { - setCharFont(pit, cur.pos() - 1, current_font); + && getFont(buffer, par, cur.pos() - 2).number() == LyXFont::ON) { + setCharFont(buffer, pit, cur.pos() - 1, current_font); } } } @@ -1261,19 +1264,19 @@ void LyXText::charInserted() } -RowMetrics -LyXText::computeRowMetrics(pit_type const pit, Row const & row) const +RowMetrics LyXText::computeRowMetrics(Buffer const & buffer, + pit_type const pit, Row const & row) const { RowMetrics result; Paragraph const & par = pars_[pit]; double w = dim_.wid - row.width(); - bool const is_rtl = isRTL(par); + bool const is_rtl = isRTL(buffer, par); if (is_rtl) - result.x = rightMargin(par); + result.x = rightMargin(buffer, par); else - result.x = leftMargin(pit, row.pos()); + result.x = leftMargin(buffer, pit, row.pos()); // is there a manual margin with a manual label LyXLayout_ptr const & layout = par.layout(); @@ -1292,7 +1295,7 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const ++nlh; if (nlh && !par.getLabelWidthString().empty()) - result.label_hfill = labelFill(par, row) / double(nlh); + result.label_hfill = labelFill(buffer, par, row) / double(nlh); } // are there any hfills in the row? @@ -1356,7 +1359,7 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const } } - bidi.computeTables(par, *bv()->buffer(), row); + bidi.computeTables(par, buffer, row); if (is_rtl) { pos_type body_pos = par.beginOfBody(); pos_type end = row.endpos(); @@ -1365,7 +1368,7 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const && (body_pos > end || !par.isLineSeparator(body_pos - 1))) { docstring const lsep = from_utf8(layout->labelsep); - result.x += theFontMetrics(getLabelFont(par)).width(lsep); + result.x += theFontMetrics(getLabelFont(buffer, par)).width(lsep); if (body_pos <= end) result.x += result.label_hfill; } @@ -1794,7 +1797,7 @@ bool LyXText::backspace(LCursor & cur) bool LyXText::dissolveInset(LCursor & cur) { BOOST_ASSERT(this == cur.text()); - if (isMainText() || cur.inset().nargs() != 1) + if (isMainText(*cur.bv().buffer()) || cur.inset().nargs() != 1) return false; recordUndoInset(cur); @@ -1832,7 +1835,7 @@ Row const & LyXText::firstRow() const } -bool LyXText::redoParagraph(pit_type const pit) +bool LyXText::redoParagraph(BufferView & bv, pit_type const pit) { // remove rows of paragraph, keep track of height changes Paragraph & par = pars_[pit]; @@ -1852,23 +1855,25 @@ bool LyXText::redoParagraph(pit_type const pit) InsetBibitem(InsetCommandParams("bibitem"))); // FIXME: change tracking (MG) par.insertInset(0, static_cast(inset), Change(Change::INSERTED)); - bv()->cursor().posRight(); + bv.cursor().posRight(); } } // redo insets // FIXME: We should always use getFont(), see documentation of // noFontChange() in insetbase.h. - LyXFont const bufferfont = bv()->buffer()->params().getFont(); + Buffer const & buffer = *bv.buffer(); + LyXFont const bufferfont = buffer.params().getFont(); InsetList::iterator ii = par.insetlist.begin(); InsetList::iterator iend = par.insetlist.end(); for (; ii != iend; ++ii) { Dimension dim; - int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par); + int const w = maxwidth_ - leftMargin(buffer, pit, ii->pos) + - rightMargin(buffer, par); LyXFont const & font = ii->inset->noFontChange() ? bufferfont : - getFont(par, ii->pos); - MetricsInfo mi(bv(), font, w); + getFont(buffer, par, ii->pos); + MetricsInfo mi(&bv, font, w); ii->inset->metrics(mi, dim); } @@ -1880,9 +1885,9 @@ bool LyXText::redoParagraph(pit_type const pit) pos_type z = 0; do { Row row(z); - rowBreakPoint(pit, row); - setRowWidth(pit, row); - setHeightOfRow(pit, row); + rowBreakPoint(buffer, pit, row); + setRowWidth(buffer, pit, row); + setHeightOfRow(bv, pit, row); par.rows().push_back(row); dim.wid = std::max(dim.wid, row.width()); dim.des += row.height(); @@ -1897,8 +1902,8 @@ bool LyXText::redoParagraph(pit_type const pit) if (z > 0 && par.isNewline(z - 1)) { Row row(z - 1); row.endpos(z - 1); - setRowWidth(pit, row); - setHeightOfRow(pit, row); + setRowWidth(buffer, pit, row); + setHeightOfRow(bv, pit, row); par.rows().push_back(row); dim.des += row.height(); } @@ -1928,7 +1933,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) unsigned int h = 0; unsigned int w = 0; for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) { - redoParagraph(pit); + redoParagraph(*mi.base.bv, pit); Paragraph & par = paragraphs()[pit]; h += par.height(); if (w < par.width()) @@ -1965,9 +1970,12 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const DocIterator beg = cur.selectionBegin(); DocIterator end = cur.selectionEnd(); + BufferView & bv = pi.base.bv; + Buffer const & buffer = *bv.buffer(); + // the selection doesn't touch the visible screen - if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW - || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE) + if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_BELOW + || bv_funcs::status(&bv, end) == bv_funcs::CUR_ABOVE) return; Paragraph const & par1 = pars_[beg.pit()]; @@ -1977,27 +1985,39 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const Row const & row2 = par2.getRow(end.pos(), end.boundary()); int y1,x1,x2; - if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_ABOVE) { + if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_ABOVE) { y1 = 0; x1 = 0; x2 = 0; } else { y1 = bv_funcs::getPos(beg).y_ - row1.ascent(); - int const startx = cursorX(beg.top(), begin.boundary()); - x1 = isRTL(par1) ? startx : 0; - x2 = isRTL(par1) ? 0 + dim_.wid : startx; + int const startx = cursorX(buffer, beg.top(), begin.boundary()); + if (isRTL(buffer, par1)) { + x1 = startx; + x2 = 0 + dim_.wid; + } + else { + x1 = 0; + x2 = startx; + } } int y2,X1,X2; - if (bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_BELOW) { - y2 = pi.base.bv->workHeight(); + if (bv_funcs::status(&bv, end) == bv_funcs::CUR_BELOW) { + y2 = bv.workHeight(); X1 = 0; X2 = 0; } else { y2 = bv_funcs::getPos(end).y_ + row2.descent(); - int const endx = cursorX(end.top(), end.boundary()); - X1 = isRTL(par2) ? 0 : endx; - X2 = isRTL(par2) ? endx : 0 + dim_.wid; + int const endx = cursorX(buffer, end.top(), end.boundary()); + if (isRTL(buffer, par2)) { + X1 = 0; + X2 = endx; + } + else { + X1 = endx; + X2 = 0 + dim_.wid; + } } lyxerr << " y1: " << y1 << " y2: " << y2 @@ -2034,19 +2054,20 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const DocIterator beg = cur.selectionBegin(); DocIterator end = cur.selectionEnd(); - BufferView * bv = pi.base.bv; + BufferView & bv = *pi.base.bv; + Buffer const & buffer = *bv.buffer(); // the selection doesn't touch the visible screen - if (bv_funcs::status(bv, beg) == bv_funcs::CUR_BELOW - || bv_funcs::status(bv, end) == bv_funcs::CUR_ABOVE) + if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_BELOW + || bv_funcs::status(&bv, end) == bv_funcs::CUR_ABOVE) return; Paragraph const & par1 = pars_[beg.pit()]; Paragraph const & par2 = pars_[end.pit()]; - bool const above = (bv_funcs::status(bv, beg) + bool const above = (bv_funcs::status(&bv, beg) == bv_funcs::CUR_ABOVE); - bool const below = (bv_funcs::status(bv, end) + bool const below = (bv_funcs::status(&bv, end) == bv_funcs::CUR_BELOW); int y1,y2,x1,x2; if (above) { @@ -2056,34 +2077,46 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const x2 = dim_.wid; } else { Row const & row1 = par1.getRow(beg.pos(), beg.boundary()); - y1 = bv_funcs::getPos(*bv, beg, beg.boundary()).y_ - row1.ascent(); + y1 = bv_funcs::getPos(bv, beg, beg.boundary()).y_ - row1.ascent(); y2 = y1 + row1.height(); - int const startx = cursorX(beg.top(), beg.boundary()); - x1 = !isRTL(par1) ? startx : 0; - x2 = !isRTL(par1) ? 0 + dim_.wid : startx; + int const startx = cursorX(buffer, beg.top(), beg.boundary()); + if (!isRTL(buffer, par1)) { + x1 = startx; + x2 = 0 + dim_.wid; + } + else { + x1 = 0; + x2 = startx; + } } int Y1,Y2,X1,X2; if (below) { - Y1 = bv->workHeight(); - Y2 = bv->workHeight(); + Y1 = bv.workHeight(); + Y2 = bv.workHeight(); X1 = 0; X2 = dim_.wid; } else { Row const & row2 = par2.getRow(end.pos(), end.boundary()); - Y1 = bv_funcs::getPos(*bv, end, end.boundary()).y_ - row2.ascent(); + Y1 = bv_funcs::getPos(bv, end, end.boundary()).y_ - row2.ascent(); Y2 = Y1 + row2.height(); - int const endx = cursorX(end.top(), end.boundary()); - X1 = !isRTL(par2) ? 0 : endx; - X2 = !isRTL(par2) ? endx : 0 + dim_.wid; + int const endx = cursorX(buffer, end.top(), end.boundary()); + if (!isRTL(buffer, par2)) { + X1 = 0; + X2 = endx; + } + else { + X1 = endx; + X2 = 0 + dim_.wid; + } } if (!above && !below && &par1.getRow(beg.pos(), beg.boundary()) == &par2.getRow(end.pos(), end.boundary())) { // paint only one rectangle - int const b( !isRTL(par1) ? x + x1 : x + X1 ); - int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 ); + int const b( !isRTL(*bv.buffer(), par1) ? x + x1 : x + X1 ); + int const w( !isRTL(*bv.buffer(), par1) ? X2 - x1 : x2 - X1 ); pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection); return; } @@ -2231,7 +2264,8 @@ int LyXText::descent() const } -int LyXText::cursorX(CursorSlice const & sl, bool boundary) const +int LyXText::cursorX(Buffer const & buffer, CursorSlice const & sl, + bool boundary) const { pit_type const pit = sl.pit(); Paragraph const & par = pars_[pit]; @@ -2248,7 +2282,7 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const pos_type cursor_vpos = 0; - RowMetrics const m = computeRowMetrics(pit, row); + RowMetrics const m = computeRowMetrics(buffer, pit, row); double x = m.x; pos_type const row_pos = row.pos(); @@ -2257,7 +2291,7 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const if (end <= row_pos) cursor_vpos = row_pos; else if (ppos >= end) - cursor_vpos = isRTL(par) ? row_pos : end; + cursor_vpos = isRTL(buffer, par) ? row_pos : end; else if (ppos > row_pos && ppos >= end) // Place cursor after char at (logical) position pos - 1 cursor_vpos = (bidi.level(ppos - 1) % 2 == 0) @@ -2275,7 +2309,8 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const // Use font span to speed things up, see below FontSpan font_span; LyXFont font; - FontMetrics const & labelfm = theFontMetrics(getLabelFont(par)); + FontMetrics const & labelfm = theFontMetrics( + getLabelFont(buffer, par)); for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) { pos_type pos = bidi.vis2log(vpos); @@ -2284,16 +2319,16 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const docstring const lsep = from_utf8(par.layout()->labelsep); x += m.label_hfill + labelfm.width(lsep); if (par.isLineSeparator(body_pos - 1)) - x -= singleWidth(par, body_pos - 1); + x -= singleWidth(buffer, par, body_pos - 1); } // Use font span to speed things up, see above if (pos < font_span.first || pos > font_span.last) { font_span = par.fontSpan(pos); - font = getFont(par, pos); + font = getFont(buffer, par, pos); } - x += singleWidth(par, pos, par.getChar(pos), font); + x += singleWidth(buffer, par, pos, par.getChar(pos), font); if (par.hfillExpansion(row, pos)) x += (pos >= body_pos) ? m.hfill : m.label_hfill; @@ -2303,15 +2338,15 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const // see correction above if (boundary_correction) - if (getFont(par, ppos).isVisibleRightToLeft()) - x -= singleWidth(par, ppos); + if (getFont(buffer, par, ppos).isVisibleRightToLeft()) + x -= singleWidth(buffer, par, ppos); else - x += singleWidth(par, ppos); + x += singleWidth(buffer, par, ppos); // Make sure inside an inset we always count from the left // edge (bidi!) -- MV if (sl.pos() < par.size()) { - font = getFont(par, sl.pos()); + font = getFont(buffer, par, sl.pos()); if (!boundary && font.isVisibleRightToLeft() && par.isInset(sl.pos())) x -= par.getInset(sl.pos())->width(); @@ -2481,7 +2516,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const // int pos = r.pos(); // for (; currx < x && pos < r.endpos(); ++pos) { // lastx = currx; -// currx += singleWidth(par, pos); +// currx += singleWidth(buffer, par, pos); // } // if (abs(lastx - x) < abs(currx - x) && pos != r.pos()) // --pos; @@ -2489,12 +2524,13 @@ string LyXText::getPossibleLabel(LCursor & cur) const //} -pos_type LyXText::x2pos(pit_type pit, int row, int x) const +pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row, + int x) const { BOOST_ASSERT(row < int(pars_[pit].rows().size())); bool bound = false; Row const & r = pars_[pit].rows()[row]; - return r.pos() + getColumnNearX(pit, r, x, bound); + return r.pos() + getColumnNearX(bv, pit, r, x, bound); } @@ -2512,7 +2548,7 @@ pos_type LyXText::x2pos(pit_type pit, int row, int x) const bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y) { BOOST_ASSERT(this == cur.text()); - pit_type pit = getPitNearY(y); + pit_type pit = getPitNearY(cur.bv(), y); int yy = cur.bv().coordCache().get(this, pit).y_ - pars_[pit].ascent(); lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION @@ -2541,7 +2577,8 @@ bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y) bool bound = false; int xx = x; - pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); + pos_type const pos = row.pos() + getColumnNearX(cur.bv(), pit, row, + xx, bound); lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION diff --git a/src/text2.C b/src/text2.C index 96023861b0..b5883f3ba6 100644 --- a/src/text2.C +++ b/src/text2.C @@ -75,7 +75,6 @@ LyXText::LyXText(BufferView * bv) : maxwidth_(bv ? bv->workWidth() : 100), current_font(LyXFont::ALL_INHERIT), background_color_(LColor::background), - bv_owner(bv), autoBreakRows_(false) {} @@ -83,7 +82,6 @@ LyXText::LyXText(BufferView * bv) void LyXText::init(BufferView * bv) { BOOST_ASSERT(bv); - bv_owner = bv; maxwidth_ = bv->workWidth(); dim_.wid = maxwidth_; dim_.asc = 10; @@ -97,16 +95,16 @@ void LyXText::init(BufferView * bv) } -bool LyXText::isMainText() const +bool LyXText::isMainText(Buffer const & buffer) const { - return &bv()->buffer()->text() == this; + return &buffer.text() == this; } //takes screen x,y coordinates -InsetBase * LyXText::checkInsetHit(int x, int y) const +InsetBase * LyXText::checkInsetHit(BufferView const & bv, int x, int y) const { - pit_type pit = getPitNearY(y); + pit_type pit = getPitNearY(bv, y); BOOST_ASSERT(pit != -1); Paragraph const & par = pars_[pit]; @@ -126,21 +124,21 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const << BOOST_CURRENT_FUNCTION << ": examining inset " << inset << endl; - if (bv()->coordCache().getInsets().has(inset)) + if (bv.coordCache().getInsets().has(inset)) lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION - << ": xo: " << inset->xo(*bv()) << "..." - << inset->xo(*bv()) + inset->width() - << " yo: " << inset->yo(*bv()) - inset->ascent() + << ": xo: " << inset->xo(bv) << "..." + << inset->xo(bv) + inset->width() + << " yo: " << inset->yo(bv) - inset->ascent() << "..." - << inset->yo(*bv()) + inset->descent() + << inset->yo(bv) + inset->descent() << endl; else lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": inset has no cached position" << endl; #endif - if (inset->covers(*bv(), x, y)) { + if (inset->covers(bv, x, y)) { lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": Hit inset: " << inset << endl; @@ -160,7 +158,8 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const // The difference is that this one is used for displaying, and thus we // are allowed to make cosmetic improvements. For instance make footnotes // smaller. (Asger) -LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const +LyXFont LyXText::getFont(Buffer const & buffer, Paragraph const & par, + pos_type const pos) const { BOOST_ASSERT(pos >= 0); @@ -168,14 +167,14 @@ LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const #ifdef WITH_WARNINGS #warning broken? #endif - BufferParams const & params = bv()->buffer()->params(); + BufferParams const & params = buffer.params(); pos_type const body_pos = par.beginOfBody(); // We specialize the 95% common case: if (!par.getDepth()) { LyXFont f = par.getFontSettings(params, pos); - if (!isMainText()) - applyOuterFont(f); + if (!isMainText(buffer)) + applyOuterFont(buffer, f); LyXFont lf; LyXFont rlf; if (layout->labeltype == LABEL_MANUAL && pos < body_pos) { @@ -201,8 +200,8 @@ LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const LyXFont font = par.getFontSettings(params, pos); font.realize(layoutfont); - if (!isMainText()) - applyOuterFont(font); + if (!isMainText(buffer)) + applyOuterFont(buffer, font); // Find the pit value belonging to paragraph. This will not break // even if pars_ would not be a vector anymore. @@ -233,16 +232,16 @@ LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const // the pi/mi parameters, and stored locally in a lyxtext in font_. // This is where the two are integrated in the final fully realized // font. -void LyXText::applyOuterFont(LyXFont & font) const { +void LyXText::applyOuterFont(Buffer const & buffer, LyXFont & font) const { LyXFont lf(font_); - lf.reduce(bv()->buffer()->params().getFont()); + lf.reduce(buffer.params().getFont()); lf.realize(font); lf.setLanguage(font.language()); font = lf; } -LyXFont LyXText::getLayoutFont(pit_type const pit) const +LyXFont LyXText::getLayoutFont(Buffer const & buffer, pit_type const pit) const { LyXLayout_ptr const & layout = pars_[pit].layout(); @@ -250,20 +249,20 @@ LyXFont LyXText::getLayoutFont(pit_type const pit) const LyXFont lf = layout->resfont; // In case the default family has been customized if (layout->font.family() == LyXFont::INHERIT_FAMILY) - lf.setFamily(bv()->buffer()->params().getFont().family()); + lf.setFamily(buffer.params().getFont().family()); return lf; } LyXFont font = layout->font; // Realize with the fonts of lesser depth. //font.realize(outerFont(pit, paragraphs())); - font.realize(bv()->buffer()->params().getFont()); + font.realize(buffer.params().getFont()); return font; } -LyXFont LyXText::getLabelFont(Paragraph const & par) const +LyXFont LyXText::getLabelFont(Buffer const & buffer, Paragraph const & par) const { LyXLayout_ptr const & layout = par.layout(); @@ -271,19 +270,20 @@ LyXFont LyXText::getLabelFont(Paragraph const & par) const LyXFont lf = layout->reslabelfont; // In case the default family has been customized if (layout->labelfont.family() == LyXFont::INHERIT_FAMILY) - lf.setFamily(bv()->buffer()->params().getFont().family()); + lf.setFamily(buffer.params().getFont().family()); return lf; } LyXFont font = layout->labelfont; // Realize with the fonts of lesser depth. - font.realize(bv()->buffer()->params().getFont()); + font.realize(buffer.params().getFont()); return font; } -void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt) +void LyXText::setCharFont(Buffer const & buffer, pit_type pit, + pos_type pos, LyXFont const & fnt) { LyXFont font = fnt; LyXLayout_ptr const & layout = pars_[pit].layout(); @@ -310,10 +310,10 @@ void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt) // Inside inset, apply the inset's font attributes if any // (charstyle!) - if (!isMainText()) + if (!isMainText(buffer)) layoutfont.realize(font_); - layoutfont.realize(bv()->buffer()->params().getFont()); + layoutfont.realize(buffer.params().getFont()); // Now, reduce font against full layout font font.reduce(layoutfont); @@ -341,11 +341,12 @@ pit_type LyXText::undoSpan(pit_type pit) } -void LyXText::setLayout(pit_type start, pit_type end, string const & layout) +void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end, + string const & layout) { BOOST_ASSERT(start != end); - BufferParams const & bufparams = bv()->buffer()->params(); + BufferParams const & bufparams = buffer.params(); LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout]; for (pit_type pit = start; pit != end; ++pit) { @@ -380,8 +381,8 @@ void LyXText::setLayout(LCursor & cur, string const & layout) pit_type start = cur.selBegin().pit(); pit_type end = cur.selEnd().pit() + 1; pit_type undopit = undoSpan(end - 1); - recUndo(start, undopit - 1); - setLayout(start, end, layout); + recUndo(cur, start, undopit - 1); + setLayout(cur.buffer(), start, end, layout); updateLabels(cur.buffer()); } @@ -455,9 +456,9 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) LyXFont layoutfont; pit_type pit = cur.pit(); if (cur.pos() < pars_[pit].beginOfBody()) - layoutfont = getLabelFont(pars_[pit]); + layoutfont = getLabelFont(cur.buffer(), pars_[pit]); else - layoutfont = getLayoutFont(pit); + layoutfont = getLayoutFont(cur.buffer(), pit); // Update current font real_current_font.update(font, @@ -487,9 +488,9 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) // nested insets. for (; dit != ditend; dit.forwardPosNoDescend()) { if (dit.pos() != dit.lastpos()) { - LyXFont f = getFont(dit.paragraph(), dit.pos()); + LyXFont f = getFont(cur.buffer(), dit.paragraph(), dit.pos()); f.update(font, params.language, toggleall); - setCharFont(dit.pit(), dit.pos(), f); + setCharFont(cur.buffer(), dit.pit(), dit.pos(), f); } } } @@ -608,7 +609,7 @@ void LyXText::setParagraph(LCursor & cur, BOOST_ASSERT(cur.text()); // make sure that the depth behind the selection are restored, too pit_type undopit = undoSpan(cur.selEnd().pit()); - recUndo(cur.selBegin().pit(), undopit - 1); + recUndo(cur, cur.selBegin().pit(), undopit - 1); for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit(); pit <= end; ++pit) { @@ -750,7 +751,7 @@ void LyXText::setCurrentFont(LCursor & cur) BufferParams const & bufparams = cur.buffer().params(); current_font = par.getFontSettings(bufparams, pos); - real_current_font = getFont(par, pos); + real_current_font = getFont(cur.buffer(), par, pos); if (cur.pos() == cur.lastpos() && bidi.isBoundary(cur.buffer(), par, cur.pos()) @@ -767,12 +768,13 @@ void LyXText::setCurrentFont(LCursor & cur) // x is an absolute screen coord // returns the column near the specified x-coordinate of the row // x is set to the real beginning of this column -pos_type LyXText::getColumnNearX(pit_type const pit, +pos_type LyXText::getColumnNearX(BufferView const & bv, pit_type const pit, Row const & row, int & x, bool & boundary) const { - int const xo = bv()->coordCache().get(this, pit).x_; + Buffer const & buffer = *bv.buffer(); + int const xo = bv.coordCache().get(this, pit).x_; x -= xo; - RowMetrics const r = computeRowMetrics(pit, row); + RowMetrics const r = computeRowMetrics(buffer, pit, row); Paragraph const & par = pars_[pit]; pos_type vc = row.pos(); @@ -798,7 +800,7 @@ pos_type LyXText::getColumnNearX(pit_type const pit, } frontend::FontMetrics const & fm - = theFontMetrics(getLabelFont(par)); + = theFontMetrics(getLabelFont(buffer, par)); while (vc < end && tmpx <= x) { c = bidi.vis2log(vc); @@ -808,21 +810,21 @@ pos_type LyXText::getColumnNearX(pit_type const pit, docstring const lsep = from_utf8(layout->labelsep); tmpx += r.label_hfill + fm.width(lsep); if (par.isLineSeparator(body_pos - 1)) - tmpx -= singleWidth(par, body_pos - 1); + tmpx -= singleWidth(buffer, par, body_pos - 1); } if (par.hfillExpansion(row, c)) { - tmpx += singleWidth(par, c); + tmpx += singleWidth(buffer, par, c); if (c >= body_pos) tmpx += r.hfill; else tmpx += r.label_hfill; } else if (par.isSeparator(c)) { - tmpx += singleWidth(par, c); + tmpx += singleWidth(buffer, par, c); if (c >= body_pos) tmpx += r.separator; } else { - tmpx += singleWidth(par, c); + tmpx += singleWidth(buffer, par, c); } ++vc; } @@ -841,7 +843,7 @@ pos_type LyXText::getColumnNearX(pit_type const pit, // If lastrow is false, we don't need to compute // the value of rtl. - bool const rtl = lastrow ? isRTL(par) : false; + bool const rtl = lastrow ? isRTL(buffer, par) : false; if (lastrow && ((rtl && left_side && vc == row.pos() && x < tmpx - 5) || (!rtl && !left_side && vc == end && x > tmpx + 5))) @@ -855,7 +857,7 @@ pos_type LyXText::getColumnNearX(pit_type const pit, bool const rtl = (bidi.level(c) % 2 == 1); if (left_side == rtl) { ++c; - boundary = bidi.isBoundary(*bv()->buffer(), par, c); + boundary = bidi.isBoundary(buffer, par, c); } } @@ -869,9 +871,9 @@ pos_type LyXText::getColumnNearX(pit_type const pit, // Newline inset, air gap below: if (row.pos() < end && c >= end && par.isNewline(end - 1)) { if (bidi.level(end -1) % 2 == 0) - tmpx -= singleWidth(par, end - 1); + tmpx -= singleWidth(buffer, par, end - 1); else - tmpx += singleWidth(par, end - 1); + tmpx += singleWidth(buffer, par, end - 1); c = end - 1; } @@ -903,11 +905,11 @@ pos_type LyXText::getColumnNearX(pit_type const pit, // y is screen coordinate -pit_type LyXText::getPitNearY(int y) const +pit_type LyXText::getPitNearY(BufferView const & bv, int y) const { BOOST_ASSERT(!paragraphs().empty()); - BOOST_ASSERT(bv()->coordCache().getParPos().find(this) != bv()->coordCache().getParPos().end()); - CoordCache::InnerParPosCache const & cc = bv()->coordCache().getParPos().find(this)->second; + BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end()); + CoordCache::InnerParPosCache const & cc = bv.coordCache().getParPos().find(this)->second; lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": y: " << y << " cache size: " << cc.size() @@ -940,10 +942,10 @@ pit_type LyXText::getPitNearY(int y) const } -Row const & LyXText::getRowNearY(int y, pit_type pit) const +Row const & LyXText::getRowNearY(BufferView const & bv, int y, pit_type pit) const { Paragraph const & par = pars_[pit]; - int yy = bv()->coordCache().get(this, pit).y_ - par.ascent(); + int yy = bv.coordCache().get(this, pit).y_ - par.ascent(); BOOST_ASSERT(!par.rows().empty()); RowList::const_iterator rit = par.rows().begin(); RowList::const_iterator const rlast = boost::prior(par.rows().end()); @@ -960,22 +962,22 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y) { if (lyxerr.debugging(Debug::WORKAREA)) { lyxerr << "LyXText::editXY(cur, " << x << ", " << y << ")" << std::endl; - bv()->coordCache().dump(); + cur.bv().coordCache().dump(); } - pit_type pit = getPitNearY(y); + pit_type pit = getPitNearY(cur.bv(), y); BOOST_ASSERT(pit != -1); - Row const & row = getRowNearY(y, pit); + Row const & row = getRowNearY(cur.bv(), y, pit); bool bound = false; int xx = x; // is modified by getColumnNearX - pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); + pos_type const pos = row.pos() + getColumnNearX(cur.bv(), pit, row, xx, bound); cur.pit() = pit; cur.pos() = pos; cur.boundary(bound); cur.x_target() = x; // try to descend into nested insets - InsetBase * inset = checkInsetHit(x, y); + InsetBase * inset = checkInsetHit(cur.bv(), x, y); //lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl; if (!inset) { // Either we deconst editXY or better we move current_font @@ -1108,12 +1110,12 @@ bool LyXText::cursorUp(LCursor & cur) if (row > 0) { updateNeeded |= setCursor(cur, cur.pit(), - x2pos(cur.pit(), row - 1, x)); + x2pos(cur.bv(), cur.pit(), row - 1, x)); } else if (cur.pit() > 0) { --cur.pit(); //cannot use 'par' now updateNeeded |= setCursor(cur, cur.pit(), - x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x)); + x2pos(cur.bv(), cur.pit(), cur.paragraph().rows().size() - 1, x)); } cur.x_target() = x; @@ -1162,11 +1164,11 @@ bool LyXText::cursorDown(LCursor & cur) if (row + 1 < int(par.rows().size())) { updateNeeded |= setCursor(cur, cur.pit(), - x2pos(cur.pit(), row + 1, x)); + x2pos(cur.bv(), cur.pit(), row + 1, x)); } else if (cur.pit() + 1 < int(paragraphs().size())) { ++cur.pit(); updateNeeded |= setCursor(cur, cur.pit(), - x2pos(cur.pit(), 0, x)); + x2pos(cur.bv(), cur.pit(), 0, x)); } cur.x_target() = x; @@ -1327,15 +1329,15 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old) } -void LyXText::recUndo(pit_type first, pit_type last) const +void LyXText::recUndo(LCursor & cur, pit_type first, pit_type last) const { - recordUndo(bv()->cursor(), Undo::ATOMIC, first, last); + recordUndo(cur, Undo::ATOMIC, first, last); } -void LyXText::recUndo(pit_type par) const +void LyXText::recUndo(LCursor & cur, pit_type par) const { - recordUndo(bv()->cursor(), Undo::ATOMIC, par, par); + recordUndo(cur, Undo::ATOMIC, par, par); } diff --git a/src/text3.C b/src/text3.C index 015a83f03f..6210304ad6 100644 --- a/src/text3.C +++ b/src/text3.C @@ -295,9 +295,9 @@ void LyXText::number(LCursor & cur) } -bool LyXText::isRTL(Paragraph const & par) const +bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const { - return par.isRightToLeftPar(bv()->buffer()->params()); + return par.isRightToLeftPar(buffer.params()); } @@ -324,7 +324,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_PARAGRAPH_MOVE_DOWN: { pit_type const pit = cur.pit(); - recUndo(pit, pit + 1); + recUndo(cur, pit, pit + 1); finishUndo(); std::swap(pars_[pit], pars_[pit + 1]); @@ -339,7 +339,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_PARAGRAPH_MOVE_UP: { pit_type const pit = cur.pit(); - recUndo(pit - 1, pit); + recUndo(cur, pit - 1, pit); finishUndo(); std::swap(pars_[pit], pars_[pit - 1]); @@ -363,7 +363,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) // ensure that we have only one start_of_appendix in this document for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) { if (pars_[tmp].params().startOfAppendix()) { - recUndo(tmp); + recUndo(cur, tmp); pars_[tmp].params().startOfAppendix(false); break; } @@ -420,7 +420,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) //lyxerr << BOOST_CURRENT_FUNCTION // << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl; needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT); - if (isRTL(cur.paragraph())) + if (isRTL(*cur.bv().buffer(), cur.paragraph())) needsUpdate |= cursorLeft(cur); else needsUpdate |= cursorRight(cur); @@ -436,7 +436,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_CHAR_BACKWARD_SELECT: //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl; needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT); - if (isRTL(cur.paragraph())) + if (isRTL(*cur.bv().buffer(), cur.paragraph())) needsUpdate |= cursorRight(cur); else needsUpdate |= cursorLeft(cur); @@ -526,7 +526,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_WORD_FORWARD: case LFUN_WORD_FORWARD_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT); - if (isRTL(cur.paragraph())) + if (isRTL(*cur.bv().buffer(), cur.paragraph())) needsUpdate |= cursorLeftOneWord(cur); else needsUpdate |= cursorRightOneWord(cur); @@ -535,7 +535,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_WORD_BACKWARD: case LFUN_WORD_BACKWARD_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT); - if (isRTL(cur.paragraph())) + if (isRTL(*cur.bv().buffer(), cur.paragraph())) needsUpdate |= cursorRightOneWord(cur); else needsUpdate |= cursorLeftOneWord(cur); @@ -778,8 +778,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_SERVER_GET_XY: cur.message(from_utf8( - convert(cursorX(cur.top(), cur.boundary())) + ' ' - + convert(cursorY(cur.top(), cur.boundary())))); + convert(cursorX(cur.buffer(), cur.top(), cur.boundary())) + + ' ' + convert(cursorY(cur.top(), cur.boundary())))); break; case LFUN_SERVER_SET_XY: { @@ -1388,7 +1388,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) if (!cmd.argument().empty()) // FIXME: Are all these characters encoded in one byte in utf8? bv->getIntl().getTransManager() - .translateAndInsert(cmd.argument()[0], this); + .translateAndInsert(cmd.argument()[0], this, cur); break; case LFUN_FLOAT_LIST: { @@ -1707,7 +1707,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, break; case LFUN_INSET_DISSOLVE: - enable = !isMainText() && cur.inset().nargs() == 1; + enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1; break; case LFUN_CHANGE_ACCEPT: diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 88867632e4..b02a9eba4f 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -13,6 +13,7 @@ #include "trans_mgr.h" +#include "buffer.h" #include "BufferView.h" #include "CutAndPaste.h" #include "cursor.h" @@ -253,7 +254,7 @@ void TransManager::disableKeymap() } -void TransManager::translateAndInsert(char c, LyXText * text) +void TransManager::translateAndInsert(char c, LyXText * text, LCursor & cur) { string res = active_->process(c, *this); @@ -262,19 +263,19 @@ void TransManager::translateAndInsert(char c, LyXText * text) while (res.length() > 0) { res = split(res, temp, TransState::TOKEN_SEP); - insert(temp, text); + insert(temp, text, cur); } } -void TransManager::insertVerbatim(string const & str, LyXText * text) +void TransManager::insertVerbatim(string const & str, LyXText * text, LCursor & cur) { for (string::size_type i = 0, n = str.size(); i < n; ++i) - text->insertChar(text->bv()->cursor(), str[i]); + text->insertChar(cur, str[i]); } -void TransManager::insert(string const & str, LyXText * text) +void TransManager::insert(string const & str, LyXText * text, LCursor & cur) { // Go through the character encoding only if the current // encoding (chset_->name()) matches the current font_norm @@ -288,21 +289,20 @@ void TransManager::insert(string const & str, LyXText * text) // Could not find an encoding InsetLatexAccent ins(str); if (ins.canDisplay()) { - LCursor & cur = text->bv()->cursor(); cap::replaceSelection(cur); cur.insert(new InsetLatexAccent(ins)); cur.posRight(); } else { - insertVerbatim(str, text); + insertVerbatim(str, text, cur); } return; } string const tmp(1, static_cast(enc.second)); - insertVerbatim(tmp, text); + insertVerbatim(tmp, text, cur); } -void TransManager::deadkey(char c, tex_accent accent, LyXText * t) +void TransManager::deadkey(char c, tex_accent accent, LyXText * t, LCursor & cur) { if (c == 0 && active_ != &default_) { // A deadkey was pressed that cannot be printed @@ -311,7 +311,7 @@ void TransManager::deadkey(char c, tex_accent accent, LyXText * t) if (active_->isAccentDefined(accent, i) == true) { string const res = trans_fsm_ .currentState->deadkey(c, i); - insert(res, t); + insert(res, t, cur); return; } } @@ -321,10 +321,10 @@ void TransManager::deadkey(char c, tex_accent accent, LyXText * t) i.accent = accent; i.data.erase(); string res = trans_fsm_.currentState->deadkey(c, i); - insert(res, t); + insert(res, t, cur); } else { // Go through the translation - translateAndInsert(c, t); + translateAndInsert(c, t, cur); } } diff --git a/src/trans_mgr.h b/src/trans_mgr.h index 74fdf1d8b9..06e98991eb 100644 --- a/src/trans_mgr.h +++ b/src/trans_mgr.h @@ -22,6 +22,7 @@ namespace lyx { +class LCursor; class LyXText; class Trans; @@ -150,9 +151,9 @@ private: /// CharacterSet chset_; /// - void insert(std::string const &, LyXText *); + void insert(std::string const &, LyXText *, LCursor & cur); /// - void insertVerbatim(std::string const &, LyXText *); + void insertVerbatim(std::string const &, LyXText *, LCursor & cur); public: /// TransManager(); @@ -175,13 +176,13 @@ public: return trans_fsm_.currentState->backspace(); } /// - void translateAndInsert(char, LyXText *); + void translateAndInsert(char, LyXText *, LCursor &); /// std::string const deadkey(char, KmodInfo); /// std::string const normalkey(char); /// - void deadkey(char, tex_accent, LyXText *); + void deadkey(char, tex_accent, LyXText *, LCursor &); }; -- 2.39.5