From 84b462dd370fc1d9c7ebe218917a02c234e676d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 28 Nov 2003 08:55:12 +0000 Subject: [PATCH] ismall stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8144 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 44 ++++++------- src/BufferView.h | 16 +++-- src/BufferView_pimpl.C | 120 +++++++++++++++++----------------- src/ChangeLog | 17 +++++ src/cursor.C | 11 ++-- src/frontends/screen.C | 4 +- src/insets/ChangeLog | 11 ++++ src/insets/insetcollapsable.C | 6 -- src/insets/insetcollapsable.h | 2 - src/insets/insetnewline.C | 2 +- src/insets/insettabular.C | 8 --- src/insets/insettabular.h | 2 - src/insets/insettext.C | 58 ++++------------ src/insets/insettext.h | 28 ++------ src/insets/updatableinset.h | 2 - src/iterators.C | 2 +- src/lyx_cb.C | 4 +- src/lyxfind.C | 8 +-- src/lyxtext.h | 6 +- src/output_plaintext.C | 98 +++++++++++++-------------- src/rowpainter.C | 10 +-- src/rowpainter.h | 4 +- src/text.C | 9 +++ src/text2.C | 4 +- src/undo.C | 4 +- 25 files changed, 221 insertions(+), 259 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 240702a1c7..08ae677e23 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -60,13 +60,13 @@ BufferView::BufferView(LyXView * owner, int xpos, int ypos, : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height)), x_target_(0) { - text = 0; + text_ = 0; } BufferView::~BufferView() { - delete text; + delete text_; delete pimpl_; } @@ -256,10 +256,10 @@ bool BufferView::insertLyXFile(string const & filen) string const fname = MakeAbsPath(filen); - text->clearSelection(); - text->breakParagraph(buffer()->paragraphs()); + text_->clearSelection(); + text_->breakParagraph(buffer()->paragraphs()); - bool res = buffer()->readFile(fname, text->cursorPar()); + bool res = buffer()->readFile(fname, text_->cursorPar()); resize(); return res; } @@ -290,9 +290,9 @@ void BufferView::setCursorFromRow(int row) buffer()->texrow().getIdFromRow(row, tmpid, tmppos); if (tmpid == -1) - text->setCursor(0, 0); + text_->setCursor(0, 0); else - text->setCursor(buffer()->getParFromID(tmpid).pit(), tmppos); + text_->setCursor(buffer()->getParFromID(tmpid).pit(), tmppos); } @@ -309,11 +309,11 @@ void BufferView::gotoLabel(string const & label) vector labels; it->getLabelList(*buffer(), labels); if (find(labels.begin(),labels.end(),label) != labels.end()) { - text->clearSelection(); - text->setCursor( - std::distance(text->ownerParagraphs().begin(), it.getPar()), + text_->clearSelection(); + text_->setCursor( + std::distance(text_->ownerParagraphs().begin(), it.getPar()), it.getPos()); - text->selection.cursor = text->cursor; + text_->selection.cursor = text_->cursor; update(); return; } @@ -327,7 +327,7 @@ void BufferView::undo() return; owner()->message(_("Undo")); - text->clearSelection(); + text_->clearSelection(); if (!textUndo(this)) owner()->message(_("No further undo information")); update(); @@ -341,7 +341,7 @@ void BufferView::redo() return; owner()->message(_("Redo")); - text->clearSelection(); + text_->clearSelection(); if (!textRedo(this)) owner()->message(_("No further redo information")); update(); @@ -354,14 +354,14 @@ void BufferView::replaceWord(string const & replacestring) if (!available()) return; - LyXText * text = getLyXText(); + LyXText * t = getLyXText(); - text->replaceSelectionWithString(replacestring); - text->setSelectionRange(replacestring.length()); + t->replaceSelectionWithString(replacestring); + t->setSelectionRange(replacestring.length()); // Go back so that replacement string is also spellchecked for (string::size_type i = 0; i < replacestring.length() + 1; ++i) - text->cursorLeft(this); + t->cursorLeft(this); // FIXME: should be done through LFUN buffer()->markDirty(); @@ -410,13 +410,13 @@ Language const * BufferView::getParentLanguage(InsetOld * inset) const Encoding const * BufferView::getEncoding() const { - LyXText * text = getLyXText(); - if (!text) + LyXText * t = getLyXText(); + if (!t) return 0; - return text->cursorPar()->getFont( + return t->cursorPar()->getFont( buffer()->params(), - text->cursor.pos(), - outerFont(text->cursorPar(), text->ownerParagraphs()) + t->cursor.pos(), + outerFont(t->cursorPar(), t->ownerParagraphs()) ).language()->encoding(); } diff --git a/src/BufferView.h b/src/BufferView.h index 2865989f9b..7a6cbba9e2 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -104,11 +104,6 @@ public: /// return the current change at the cursor Change const getCurrentChange(); - /** - * This holds the mapping between buffer paragraphs and screen rows. - * This should be private...but not yet. (Lgb) - */ - LyXText * text; /// return the lyxtext we are using LyXText * getLyXText() const; @@ -193,13 +188,22 @@ public: LCursor const & cursor() const; /// UpdatableInset * innerInset() const; + /// + LyXText * text() const { return text_; } + /// + void setText(LyXText * t) { text_ = t; } private: + /// struct Pimpl; + /// friend struct BufferView::Pimpl; - + /// Pimpl * pimpl_; + /// This holds the mapping between buffer paragraphs and screen rows. + LyXText * text_; + /** * The target x position of the cursor. This is used for when * we have text like : diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 8e4ef9eb0f..906aa684c4 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -287,8 +287,8 @@ void BufferView::Pimpl::buffer(Buffer * b) << b << ')' << endl; if (buffer_) { disconnectBuffer(); - delete bv_->text; - bv_->text = 0; + delete bv_->text(); + bv_->setText(0); } // set current buffer @@ -309,7 +309,7 @@ void BufferView::Pimpl::buffer(Buffer * b) connectBuffer(*buffer_); // If we don't have a text object for this, we make one - if (bv_->text == 0) + if (bv_->text() == 0) resizeCurrentBuffer(); // FIXME: needed when ? @@ -333,7 +333,7 @@ void BufferView::Pimpl::buffer(Buffer * b) // Don't forget to update the Layout if (buffer_) - owner_->setLayout(bv_->text->cursorPar()->layout()->name()); + owner_->setLayout(bv_->text()->cursorPar()->layout()->name()); if (lyx::graphics::Previews::activated() && buffer_) lyx::graphics::Previews::get().generateBufferPreviews(*buffer_); @@ -354,7 +354,7 @@ bool BufferView::Pimpl::fitCursor() void BufferView::Pimpl::redoCurrentBuffer() { lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl; - if (buffer_ && bv_->text) { + if (buffer_ && bv_->text()) { resizeCurrentBuffer(); updateScrollbar(); owner_->updateLayoutChoice(); @@ -380,37 +380,37 @@ void BufferView::Pimpl::resizeCurrentBuffer() owner_->message(_("Formatting document...")); - if (bv_->text) { - par = bv_->text->cursor.par(); - pos = bv_->text->cursor.pos(); - selstartpar = bv_->text->selection.start.par(); - selstartpos = bv_->text->selection.start.pos(); - selendpar = bv_->text->selection.end.par(); - selendpos = bv_->text->selection.end.pos(); - selection = bv_->text->selection.set(); - mark_set = bv_->text->selection.mark(); - bv_->text->fullRebreak(); + if (bv_->text()) { + par = bv_->text()->cursor.par(); + pos = bv_->text()->cursor.pos(); + selstartpar = bv_->text()->selection.start.par(); + selstartpos = bv_->text()->selection.start.pos(); + selendpar = bv_->text()->selection.end.par(); + selendpos = bv_->text()->selection.end.pos(); + selection = bv_->text()->selection.set(); + mark_set = bv_->text()->selection.mark(); + bv_->text()->fullRebreak(); update(); } else { - bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs()); - bv_->text->init(bv_); + bv_->setText(new LyXText(bv_, 0, false, bv_->buffer()->paragraphs())); + bv_->text()->init(bv_); } if (par != -1) { - bv_->text->selection.set(true); + bv_->text()->selection.set(true); // At this point just to avoid the Delete-Empty-Paragraph- // Mechanism when setting the cursor. - bv_->text->selection.mark(mark_set); + bv_->text()->selection.mark(mark_set); if (selection) { - bv_->text->setCursor(selstartpar, selstartpos); - bv_->text->selection.cursor = bv_->text->cursor; - bv_->text->setCursor(selendpar, selendpos); - bv_->text->setSelection(); - bv_->text->setCursor(par, pos); + bv_->text()->setCursor(selstartpar, selstartpos); + bv_->text()->selection.cursor = bv_->text()->cursor; + bv_->text()->setCursor(selendpar, selendpos); + bv_->text()->setSelection(); + bv_->text()->setCursor(par, pos); } else { - bv_->text->setCursor(par, pos); - bv_->text->selection.cursor = bv_->text->cursor; - bv_->text->selection.set(false); + bv_->text()->setCursor(par, pos); + bv_->text()->selection.cursor = bv_->text()->cursor; + bv_->text()->selection.set(false); } } @@ -428,13 +428,13 @@ void BufferView::Pimpl::resizeCurrentBuffer() void BufferView::Pimpl::updateScrollbar() { - if (!bv_->text) { + if (!bv_->text()) { lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl; workarea().setScrollbarParams(0, 0, 0); return; } - LyXText const & t = *bv_->text; + LyXText const & t = *bv_->text(); lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() " << top_y() << ", default height " << defaultRowHeight() << endl; @@ -462,7 +462,7 @@ void BufferView::Pimpl::scrollDocView(int value) int const first = top_y() + height; int const last = top_y() + workarea().workHeight() - height; - LyXText * text = bv_->text; + LyXText * text = bv_->text(); if (text->cursor.y() < first) text->setCursorFromCoordinates(0, first); else if (text->cursor.y() > last) @@ -477,7 +477,7 @@ void BufferView::Pimpl::scroll(int lines) if (!buffer_) return; - LyXText const * t = bv_->text; + LyXText const * t = bv_->text(); int const line_height = defaultRowHeight(); // The new absolute coordinate @@ -523,15 +523,15 @@ void BufferView::Pimpl::selectionRequested() LyXText * text = bv_->getLyXText(); if (text->selection.set() && - (!bv_->text->xsel_cache.set() || - text->selection.start != bv_->text->xsel_cache.start || - text->selection.end != bv_->text->xsel_cache.end)) + (!bv_->text()->xsel_cache.set() || + text->selection.start != bv_->text()->xsel_cache.start || + text->selection.end != bv_->text()->xsel_cache.end)) { - bv_->text->xsel_cache = text->selection; + bv_->text()->xsel_cache = text->selection; sel = text->selectionAsString(*bv_->buffer(), false); } else if (!text->selection.set()) { sel = string(); - bv_->text->xsel_cache.set(false); + bv_->text()->xsel_cache.set(false); } if (!sel.empty()) { workarea().putClipboard(sel); @@ -544,7 +544,7 @@ void BufferView::Pimpl::selectionLost() if (available()) { screen().hideCursor(); bv_->getLyXText()->clearSelection(); - bv_->text->xsel_cache.set(false); + bv_->text()->xsel_cache.set(false); } } @@ -590,7 +590,7 @@ void BufferView::Pimpl::update() getParsInRange(buffer_->paragraphs(), top_y(), top_y() + workarea().workHeight(), beg, end); - bv_->text->redoParagraphs(beg, end); + bv_->text()->redoParagraphs(beg, end); bv_->getLyXText()->redoCursor(); updateScrollbar(); } @@ -613,7 +613,7 @@ void BufferView::Pimpl::cursorToggle() bool BufferView::Pimpl::available() const { - return buffer_ && bv_->text; + return buffer_ && bv_->text(); } @@ -637,8 +637,8 @@ void BufferView::Pimpl::savePosition(unsigned int i) if (i >= saved_positions_num) return; saved_positions[i] = Position(buffer_->fileName(), - bv_->text->cursorPar()->id(), - bv_->text->cursor.pos()); + bv_->text()->cursorPar()->id(), + bv_->text()->cursor.pos()); if (i > 0) owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i))); } @@ -651,7 +651,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i) string const fname = saved_positions[i].filename; - bv_->text->clearSelection(); + bv_->text()->clearSelection(); if (fname != buffer_->fileName()) { Buffer * b = 0; @@ -669,7 +669,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i) if (par == buffer_->par_iterator_end()) return; - bv_->text->setCursor(par.pit(), + bv_->text()->setCursor(par.pit(), min(par->size(), saved_positions[i].par_pos)); if (i > 0) @@ -701,7 +701,7 @@ void BufferView::Pimpl::switchKeyMap() void BufferView::Pimpl::center() { - LyXText * text = bv_->text; + LyXText * text = bv_->text(); text->clearSelection(); int const half_height = workarea().workHeight() / 2; @@ -843,7 +843,7 @@ void BufferView::Pimpl::trackChanges() buf->undostack().clear(); } else { update(); - bv_->text->setCursor(0, 0); + bv_->text()->setCursor(0, 0); #warning changes FIXME bool found = lyx::find::findNextChange(bv_); if (found) { @@ -867,7 +867,7 @@ namespace { InsetOld * insetFromCoords(BufferView * bv, int x, int y) { - LyXText * text = bv->text; + LyXText * text = bv->text(); InsetOld * inset = 0; theTempCursor = LCursor(bv); while (true) { @@ -1208,7 +1208,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) break; case LFUN_ACCEPT_ALL_CHANGES: { - bv_->text->setCursor(0, 0); + bv_->text()->setCursor(0, 0); #warning FIXME changes while (lyx::find::findNextChange(bv_)) bv_->getLyXText()->acceptChange(); @@ -1217,7 +1217,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) } case LFUN_REJECT_ALL_CHANGES: { - bv_->text->setCursor(0, 0); + bv_->text()->setCursor(0, 0); #warning FIXME changes while (lyx::find::findNextChange(bv_)) bv_->getLyXText()->rejectChange(); @@ -1262,25 +1262,25 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) #endif // not quite sure if we want this... - bv_->text->recUndo(bv_->text->cursor.par()); + bv_->text()->recUndo(bv_->text()->cursor.par()); freezeUndo(); - bv_->text->clearSelection(); + bv_->text()->clearSelection(); if (!lout.empty()) { - bv_->text->breakParagraph(bv_->buffer()->paragraphs()); + bv_->text()->breakParagraph(bv_->buffer()->paragraphs()); - if (!bv_->text->cursorPar()->empty()) { - bv_->text->cursorLeft(bv_); - bv_->text->breakParagraph(bv_->buffer()->paragraphs()); + if (!bv_->text()->cursorPar()->empty()) { + bv_->text()->cursorLeft(bv_); + bv_->text()->breakParagraph(bv_->buffer()->paragraphs()); } string lres = lout; LyXTextClass const & tclass = buffer_->params().getLyXTextClass(); bool hasLayout = tclass.hasLayout(lres); - bv_->text->setLayout(hasLayout ? lres : tclass.defaultLayoutName()); + bv_->text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName()); - bv_->text->setParagraph( + bv_->text()->setParagraph( VSpace(VSpace::NONE), VSpace(VSpace::NONE), Spacing(), LYX_ALIGN_LAYOUT, @@ -1297,7 +1297,7 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code, string const & from, string const & to) { bool need_update = false; - LyXCursor cursor = bv_->text->cursor; + LyXCursor cursor = bv_->text()->cursor; LyXCursor tmpcursor = cursor; cursor.par(tmpcursor.par()); cursor.pos(tmpcursor.pos()); @@ -1324,12 +1324,12 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code, // The test it.size()==1 was needed to prevent crashes. // How to set the cursor correctly when it.size()>1 ?? if (it.size() == 1) { - bv_->text->setCursorIntern(bv_->text->parOffset(it.pit()), 0); - bv_->text->redoParagraph(bv_->text->cursorPar()); + bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0); + bv_->text()->redoParagraph(bv_->text()->cursorPar()); } } } - bv_->text->setCursorIntern(cursor.par(), cursor.pos()); + bv_->text()->setCursorIntern(cursor.par(), cursor.pos()); return need_update; } diff --git a/src/ChangeLog b/src/ChangeLog index 71da3c8e5d..31bdf90615 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,21 @@ +2003-11-28 André Pönitz + + * BufferView.[Ch]: make LyXText * text a private member + + * BufferView_pimpl.C: + * cursor.C: + * iterators.C: + * lyx_cb.C: + * lyxfind.C: + * lyxtext.h: + * rowpainter.[Ch]: + * text.C: + * text2.C: + * undo.C: adjust + + * output_plaintext.C: cleanup + 2003-11-27 Martin Vermeer * buffer.C: diff --git a/src/cursor.C b/src/cursor.C index 3a6d72f3bd..b5a35e2cf4 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -101,8 +101,8 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) break; } } - lyxerr << "trying to dispatch to main text " << bv_->text << endl; - DispatchResult res = bv_->text->dispatch(cmd); + lyxerr << "trying to dispatch to main text " << bv_->text() << endl; + DispatchResult res = bv_->text()->dispatch(cmd); lyxerr << " result: " << res.val() << endl; if (!res.dispatched()) { @@ -160,7 +160,7 @@ LyXText * LCursor::innerText() const if (data_[i].text()) return data_[i].text(); } - return bv_->text; + return bv_->text(); } @@ -187,8 +187,8 @@ void LCursor::getDim(int & asc, int & desc) const void LCursor::getPos(int & x, int & y) const { if (data_.empty()) { - x = bv_->text->cursor.x(); - y = bv_->text->cursor.y(); + x = bv_->text()->cursor.x(); + y = bv_->text()->cursor.y(); // y -= bv_->top_y(); } else { // Would be nice to clean this up to make some understandable sense... @@ -201,7 +201,6 @@ void LCursor::getPos(int & x, int & y) const // inset.top_baseline, so getCursor() returns an old value. // Ugly as you like. //inset->getCursorPos(bv_, x, y); - //y = inset->insetInInsetY() + bv_->text->cursor.y(); inset->getCursorPos(x, y); x += inset->x(); y += cached_y_; diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 7d4299eb7b..68da7ca38d 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -242,7 +242,7 @@ bool LyXScreen::fitCursor(BufferView * bv) void LyXScreen::redraw(BufferView & bv) { - greyed_out_ = !bv.text; + greyed_out_ = !bv.text(); if (greyed_out_) { greyOut(); @@ -257,7 +257,7 @@ void LyXScreen::redraw(BufferView & bv) // maybe we have to clear the screen at the bottom int const y2 = workarea().workHeight(); - if (y < y2 && !bv.text->isInInset()) { + if (y < y2 && !bv.text()->isInInset()) { workarea().getPainter().fillRectangle(0, y, workarea().workWidth(), y2 - y, LColor::bottomarea); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index e027610484..b87658fc70 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ + + +2003-11-28 André Pönitz + + * updatableinset.h: remove insetInInsetY + + * insetcollapsable.[Ch]: + * insetnewline.C: + * insettabular.[Ch]: + * insettext.[Ch]: adjust + 2003-11-27 Alfredo Braunstein * insettext.[Ch]: diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 7f0cfe151f..604f8f6cf6 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -318,12 +318,6 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) } -int InsetCollapsable::insetInInsetY() const -{ - return inset.y() - yo_ + inset.insetInInsetY(); -} - - void InsetCollapsable::validate(LaTeXFeatures & features) const { inset.validate(features); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 8fbd484168..61be4dae7a 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -61,8 +61,6 @@ public: /// bool isTextInset() const { return true; } /// - int insetInInsetY() const; - /// int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index 1ce8398eb3..eaf577966c 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -89,7 +89,7 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const // hack, and highly dubious lyx::pos_type pos = ownerPar(*pi.base.bv->buffer(), this) .getPositionOfInset(this); - bool const ltr_pos = (pi.base.bv->text->bidi.level(pos) % 2 == 0); + bool const ltr_pos = (pi.base.bv->text()->bidi.level(pos) % 2 == 0); int xp[3]; int yp[3]; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 654fbb4b5e..c0b0dc6848 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -388,14 +388,6 @@ void InsetTabular::updateLocal(BufferView * bv) const } -int InsetTabular::insetInInsetY() const -{ - if (the_locking_inset) - return cursory_ + the_locking_inset->insetInInsetY(); - return 0; -} - - bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset) { return the_locking_inset && the_locking_inset->insertInset(bv, inset); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 763cc75d67..6e77196f5a 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -80,8 +80,6 @@ public: /// void updateLocal(BufferView *) const; /// - int insetInInsetY() const; - /// bool insertInset(BufferView *, InsetOld *); /// bool insetAllowed(InsetOld::Code code) const; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 97e1582503..238c5f6862 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -78,7 +78,6 @@ InsetText::InsetText(BufferParams const & bp) frame_color_(LColor::insetframe), text_(0, this, true, paragraphs) { - textwidth_ = 0; // broken paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout()); if (bp.tracking_changes) paragraphs.begin()->trackChanges(); @@ -102,7 +101,6 @@ void InsetText::operator=(InsetText const & in) autoBreakRows_ = in.autoBreakRows_; drawFrame_ = in.drawFrame_; frame_color_ = in.frame_color_; - textwidth_ = in.textwidth_; text_ = LyXText(in.text_.bv_owner, this, true, paragraphs); init(); } @@ -218,7 +216,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; - textwidth_ = mi.base.textwidth; mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; setViewCache(mi.base.bv); text_.metrics(mi, dim); @@ -236,24 +233,21 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const xo_ = x; yo_ = y; - BufferView * bv = pi.base.bv; Painter & pain = pi.pain; // repaint the background if needed + x += TEXT_TO_INSET_OFFSET; if (backgroundColor() != LColor::background) - clearInset(bv, xo_ + TEXT_TO_INSET_OFFSET, y); + clearInset(pain, x, y); + BufferView * bv = pi.base.bv; bv->hideCursor(); if (!owner()) x += scroll(); - - x += TEXT_TO_INSET_OFFSET; y += bv->top_y() - text_.firstRow()->ascent_of_text(); - text_.xo_ = x; - text_.yo_ = y; - paintTextInset(*bv, text_, x, y); + text_.draw(pi, x, y); if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED) drawFrame(pain, xo_); @@ -271,7 +265,7 @@ void InsetText::drawFrame(Painter & pain, int x) const } -void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/) +void InsetText::updateLocal(BufferView * bv) { if (!bv) return; @@ -286,7 +280,7 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/) bv->owner()->updateMenubar(); bv->owner()->updateToolbar(); if (old_par != text_.cursor.par()) { - bv->owner()->setLayout(cpar()->layout()->name()); + bv->owner()->setLayout(text_.cursorPar()->layout()->name()); old_par = text_.cursor.par(); } } @@ -326,7 +320,7 @@ void InsetText::edit(BufferView * bv, bool left) text_.setCursor(paragraphs.size() - 1, paragraphs.back().size()); sanitizeEmptyText(bv); - updateLocal(bv, false); + updateLocal(bv); bv->updateParagraphDialog(); } @@ -341,7 +335,7 @@ void InsetText::edit(BufferView * bv, int x, int y) text_.clearSelection(); finishUndo(); - updateLocal(bv, false); + updateLocal(bv); bv->updateParagraphDialog(); } @@ -437,17 +431,12 @@ void InsetText::getCursorPos(int & x, int & y) const } -int InsetText::insetInInsetY() const -{ - return 0; -} - - bool InsetText::insertInset(BufferView * bv, InsetOld * inset) { inset->setOwner(this); text_.insertInset(inset); - updateLocal(bv, true); + updateLocal(bv); +#warning should we mark the buffer dirty? return true; } @@ -540,24 +529,6 @@ void InsetText::setFrameColor(LColor_color col) } -pos_type InsetText::cpos() const -{ - return text_.cursor.pos(); -} - - -ParagraphList::iterator InsetText::cpar() const -{ - return text_.cursorPar(); -} - - -RowList::iterator InsetText::crow() const -{ - return cpar()->getRow(cpos()); -} - - void InsetText::setViewCache(BufferView const * bv) const { if (bv && bv != text_.bv_owner) { @@ -585,15 +556,8 @@ int InsetText::scroll(bool /*recursive*/) const } -void InsetText::clearSelection(BufferView *) -{ - text_.clearSelection(); -} - - -void InsetText::clearInset(BufferView * bv, int x, int y) const +void InsetText::clearInset(Painter & pain, int x, int y) const { - Painter & pain = bv->painter(); int w = dim_.wid; int h = dim_.asc + dim_.des; int ty = y - dim_.asc; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 1f257fa378..e561188c5e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -59,11 +59,11 @@ public: /// empty inset to empty par, or just mark as erased void clear(bool just_mark_erased); /// - void read(Buffer const &, LyXLex &); + void read(Buffer const & buf, LyXLex & lex); /// - void write(Buffer const &, std::ostream &) const; + void write(Buffer const & buf, std::ostream & os) const; /// - void metrics(MetricsInfo &, Dimension &) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -89,8 +89,6 @@ public: /// FIXME, document void getCursorPos(int & x, int & y) const; /// - int insetInInsetY() const; - /// bool insertInset(BufferView *, InsetOld *); /// bool insetAllowed(InsetOld::Code) const; @@ -129,8 +127,6 @@ public: UpdatableInset::scroll(bv, offset); } /// - void clearSelection(BufferView * bv); - /// ParagraphList * getParagraphs(int) const; /// LyXText * getText(int) const; @@ -165,14 +161,12 @@ public: int numParagraphs() const { return 1; } /// mutable ParagraphList paragraphs; -protected: +private: /// DispatchResult priv_dispatch(FuncRequest const &, idx_type &, pos_type &); /// - void updateLocal(BufferView *, bool mark_dirty); - -private: + void updateLocal(BufferView *); /// void init(); // If the inset is empty set the language of the current font to the @@ -183,15 +177,9 @@ private: /// void removeNewlines(); /// - lyx::pos_type cpos() const; - /// - ParagraphList::iterator cpar() const; - /// - RowList::iterator crow() const; - /// void drawFrame(Painter &, int x) const; /// - void clearInset(BufferView *, int start_x, int baseline) const; + void clearInset(Painter &, int x, int y) const; /// void collapseParagraphs(BufferView *); @@ -205,8 +193,6 @@ private: */ int frame_color_; /// - bool no_selection; - /// mutable lyx::paroffset_type old_par; /** to remember old painted frame dimensions to clear it on @@ -216,7 +202,5 @@ private: public: /// mutable LyXText text_; - /// - mutable int textwidth_; }; #endif diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 2191ae1c36..8ea216607f 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -35,8 +35,6 @@ public: virtual void getCursorDim(int &, int &) const; /// virtual bool insertInset(BufferView *, InsetOld *) { return false; } - /// - virtual int insetInInsetY() const { return 0; } // We need this method to not clobber the real method in Inset int scroll(bool recursive = true) const { return InsetOld::scroll(recursive); } diff --git a/src/iterators.C b/src/iterators.C index 5b0c026cc9..b295e876bd 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -153,7 +153,7 @@ LyXText * ParIterator::text(BufferView * bv) const { //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl; if (pimpl_->positions.size() <= 1) - return bv->text; + return bv->text(); ParPosition const & pos = pimpl_->positions[pimpl_->positions.size() - 2]; return (*pos.it)->inset->getText(*pos.index); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 89f5f67e10..875281607d 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -353,8 +353,8 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) return; // clear the selection - if (bv->text == bv->getLyXText()) - bv->text->clearSelection(); + if (bv->text() == bv->getLyXText()) + bv->text()->clearSelection(); if (asParagraph) bv->getLyXText()->insertStringAsParagraphs(tmpstr); else diff --git a/src/lyxfind.C b/src/lyxfind.C index 0c69863dcb..70e9b64e8a 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -159,8 +159,7 @@ int replaceAll(BufferView * bv, if (!searchAllowed(bv, searchstr) || buf.isReadonly()) return 0; - recordUndo(Undo::ATOMIC, bv->text, 0, - buf.paragraphs().size() - 1); + recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1); PosIterator cur = buf.pos_iterator_begin(); PosIterator const end = buf.pos_iterator_end(); @@ -181,7 +180,7 @@ int replaceAll(BufferView * bv, } PosIterator beg = buf.pos_iterator_begin(); - bv->text->init(bv); + bv->text()->init(bv); put_selection_at(bv, beg, 0, false); if (num) buf.markDirty(); @@ -201,8 +200,7 @@ bool stringSelected(BufferView * bv, string const & str1 = searchstr; string const str2 = text->selectionAsString(*bv->buffer(), false); - if ((cs && str1 != str2) - || lowercase(str1) != lowercase(str2)) { + if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) { find(bv, searchstr, cs, mw, fw); return false; } diff --git a/src/lyxtext.h b/src/lyxtext.h index e2bd921582..b238817d48 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -128,6 +128,8 @@ public: void fullRebreak(); /// compute text metrics void metrics(MetricsInfo & mi, Dimension & dim); + /// draw text (only used for insets) + void draw(PainterInfo & pi, int x, int y) const; /// DispatchResult dispatch(FuncRequest const & cmd); @@ -418,8 +420,8 @@ public: ParagraphList * paragraphs_; /// absolute document pixel coordinates of this LyXText - int xo_; - int yo_; + mutable int xo_; + mutable int yo_; private: diff --git a/src/output_plaintext.C b/src/output_plaintext.C index 835ef66d80..79095bbe43 100644 --- a/src/output_plaintext.C +++ b/src/output_plaintext.C @@ -144,7 +144,7 @@ void asciiParagraph(Buffer const & buf, //-- // we should probably change to the paragraph language in the - // gettext here (if possible) so that strings are outputted in + // gettext here (if possible) so that strings are output in // the correct language! (20012712 Jug) //-- switch (ltype) { @@ -152,6 +152,7 @@ void asciiParagraph(Buffer const & buf, case 4: // (Sub)Paragraph case 5: // Description break; + case 6: // Abstract if (runparams.linelen > 0) { os << _("Abstract") << "\n\n"; @@ -162,6 +163,7 @@ void asciiParagraph(Buffer const & buf, currlinelen += abst.length(); } break; + case 7: // Bibliography if (!ref_printed) { if (runparams.linelen > 0) { @@ -172,17 +174,16 @@ void asciiParagraph(Buffer const & buf, os << refs; currlinelen += refs.length(); } - ref_printed = true; } break; - default: - { - string const parlab = par.params().labelString(); - os << parlab << ' '; - currlinelen += parlab.length() + 1; + + default: { + string const label = par.params().labelString(); + os << label << ' '; + currlinelen += label.length() + 1; + break; } - break; } } @@ -202,59 +203,52 @@ void asciiParagraph(Buffer const & buf, for (pos_type i = 0; i < par.size(); ++i) { char c = par.getUChar(buf.params(), i); switch (c) { - case Paragraph::META_INSET: - { + case Paragraph::META_INSET: { InsetOld const * inset = par.getInset(i); - if (inset) { - if (runparams.linelen > 0) { - os << word; - currlinelen += word.length(); - word.erase(); - } - if (inset->plaintext(buf, os, runparams)) { - // to be sure it breaks paragraph - currlinelen += runparams.linelen; - } + if (runparams.linelen > 0) { + os << word; + currlinelen += word.length(); + word.erase(); } + if (inset->plaintext(buf, os, runparams)) { + // to be sure it breaks paragraph + currlinelen += runparams.linelen; + } + break; } - break; - default: - if (c == ' ') { - if (runparams.linelen > 0 && - currlinelen + word.length() > runparams.linelen - 10) { - os << "\n"; - pair p = addDepth(depth, ltype_depth); - os << p.second; - currlinelen = p.first; - } + case ' ': + if (runparams.linelen > 0 && + currlinelen + word.length() > runparams.linelen - 10) { + os << "\n"; + pair p = addDepth(depth, ltype_depth); + os << p.second; + currlinelen = p.first; + } - os << word << ' '; - currlinelen += word.length() + 1; - word.erase(); + os << word << ' '; + currlinelen += word.length() + 1; + word.erase(); + break; - } else { - if (c != '\0') { - word += c; - } else { - lyxerr[Debug::INFO] << - "writeAsciiFile: NULL char in structure." << endl; - } - if ((runparams.linelen > 0) && - (currlinelen + word.length()) > runparams.linelen) - { - os << "\n"; - - pair p = - addDepth(depth, ltype_depth); - os << p.second; - currlinelen = p.first; - } + + case '\0': + lyxerr[Debug::INFO] << + "writeAsciiFile: NULL char in structure." << endl; + break; + + default: + word += c; + if (runparams.linelen > 0 && + currlinelen + word.length() > runparams.linelen) + { + os << "\n"; + pair p = addDepth(depth, ltype_depth); + os << p.second; + currlinelen = p.first; } break; } } os << word; } - - diff --git a/src/rowpainter.C b/src/rowpainter.C index 4b25b1a0be..147284d210 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -129,7 +129,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text, x_ += xo_; // background has already been cleared. - if (&text_ == bv_.text) + if (&text_ == bv_.text()) paintBackground(); // paint the selection background @@ -960,15 +960,15 @@ int paintPars(BufferView const & bv, LyXText const & text, } // namespace anon -int paintText(BufferView & bv) +int paintText(BufferView const & bv) { ParagraphList::iterator pit; - bv.text->getRowNearY(bv.top_y(), pit); - return paintPars(bv, *bv.text, pit, 0, 0, pit->y); + bv.text()->getRowNearY(bv.top_y(), pit); + return paintPars(bv, *bv.text(), pit, 0, 0, pit->y); } -void paintTextInset(BufferView & bv, LyXText & text, int xo, int yo) +void paintTextInset(BufferView const & bv, LyXText const & text, int xo, int yo) { paintPars(bv, text, text.ownerParagraphs().begin(), xo, yo, 0); } diff --git a/src/rowpainter.h b/src/rowpainter.h index b663ae8471..96dcb1b803 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -21,9 +21,9 @@ class VSpace; int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp); /// paint the rows of the main text, return last drawn y value -int paintText(BufferView & bv); +int paintText(BufferView const & bv); /// paint the rows of a text inset -void paintTextInset(BufferView & bv, LyXText & text, int x, int y); +void paintTextInset(BufferView const & bv, LyXText const & text, int x, int y); #endif // ROWPAINTER_H diff --git a/src/text.C b/src/text.C index 835c24a0ae..19eefc2525 100644 --- a/src/text.C +++ b/src/text.C @@ -1641,6 +1641,15 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) } +// only used for inset right now. should also be used for main text +void LyXText::draw(PainterInfo & pi, int x, int y) const +{ + xo_ = x; + yo_ = y; + paintTextInset(*bv(), *this, x, y); +} + + bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const { return row.endpos() >= pit->size() diff --git a/src/text2.C b/src/text2.C index 58f6d3ff9a..3bfed46f82 100644 --- a/src/text2.C +++ b/src/text2.C @@ -506,8 +506,8 @@ void LyXText::clearSelection() TextCursor::clearSelection(); // reset this in the bv()! - if (bv() && bv()->text) - bv()->text->xsel_cache.set(false); + if (bv() && bv()->text()) + bv()->text()->xsel_cache.set(false); } diff --git a/src/undo.C b/src/undo.C index 5dd0af2565..90ca31c65b 100644 --- a/src/undo.C +++ b/src/undo.C @@ -188,7 +188,7 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) text->updateCounters(); // rebreak the entire lyxtext - bv->text->fullRebreak(); + bv->text()->fullRebreak(); pit.lockPath(bv); @@ -292,5 +292,5 @@ void recordUndo(Undo::undo_kind kind, LyXText const * text, paroffset_type par) void recordUndo(BufferView * bv, Undo::undo_kind kind) { - recordUndo(kind, bv->text, bv->text->cursor.par()); + recordUndo(kind, bv->text(), bv->text()->cursor.par()); } -- 2.39.2