From 741064fa584d5f209a4b74bb4302c7d2fc1ea9dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 28 Nov 2003 15:08:38 +0000 Subject: [PATCH] move the LyXText member git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8148 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 33 ++++++++++++++++++--------------- src/BufferView.h | 7 +------ src/BufferView_pimpl.C | 21 ++++++++++++++------- src/ChangeLog | 7 +++++++ src/buffer.C | 13 ++++++++++++- src/buffer.h | 4 ++++ 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 08ae677e23..97def2dfae 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -59,14 +59,11 @@ BufferView::BufferView(LyXView * owner, int xpos, int ypos, int width, int height) : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height)), x_target_(0) -{ - text_ = 0; -} +{} BufferView::~BufferView() { - delete text_; delete pimpl_; } @@ -256,10 +253,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 +287,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 +306,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 +324,7 @@ void BufferView::undo() return; owner()->message(_("Undo")); - text_->clearSelection(); + text()->clearSelection(); if (!textUndo(this)) owner()->message(_("No further undo information")); update(); @@ -341,7 +338,7 @@ void BufferView::redo() return; owner()->message(_("Redo")); - text_->clearSelection(); + text()->clearSelection(); if (!textRedo(this)) owner()->message(_("No further redo information")); update(); @@ -461,3 +458,9 @@ void BufferView::updateParagraphDialog() { pimpl_->updateParagraphDialog(); } + + +LyXText * BufferView::text() const +{ + return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0; +} diff --git a/src/BufferView.h b/src/BufferView.h index 7a6cbba9e2..4115e92f0a 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -189,9 +189,7 @@ public: /// UpdatableInset * innerInset() const; /// - LyXText * text() const { return text_; } - /// - void setText(LyXText * t) { text_ = t; } + LyXText * text() const; private: /// @@ -201,9 +199,6 @@ private: /// 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 906aa684c4..a73622b7e0 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -287,12 +287,15 @@ void BufferView::Pimpl::buffer(Buffer * b) << b << ')' << endl; if (buffer_) { disconnectBuffer(); - delete bv_->text(); - bv_->setText(0); + //delete bv_->text(); + //bv_->setText(0); } // set current buffer buffer_ = b; + buffer_->text().init(bv_); + buffer_->text().textwidth_ = workarea().workWidth(); + buffer_->text().fullRebreak(); top_y_ = 0; @@ -380,7 +383,11 @@ void BufferView::Pimpl::resizeCurrentBuffer() owner_->message(_("Formatting document...")); - if (bv_->text()) { + lyxerr << "### resizeCurrentBuffer: text" << bv_->text() << endl; + if (!bv_->text()) + return; + + //if (bv_->text()) { par = bv_->text()->cursor.par(); pos = bv_->text()->cursor.pos(); selstartpar = bv_->text()->selection.start.par(); @@ -391,10 +398,10 @@ void BufferView::Pimpl::resizeCurrentBuffer() mark_set = bv_->text()->selection.mark(); bv_->text()->fullRebreak(); update(); - } else { - bv_->setText(new LyXText(bv_, 0, false, bv_->buffer()->paragraphs())); - bv_->text()->init(bv_); - } + //} else { + // bv_->setText(new LyXText(bv_, 0, false, bv_->buffer()->paragraphs())); + // bv_->text()->init(bv_); + //} if (par != -1) { bv_->text()->selection.set(true); diff --git a/src/ChangeLog b/src/ChangeLog index 7868791b91..08f1da8bec 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,13 @@ * factory.C: Syntax change for CharStyles +2003-11-28 André Pönitz + + * BufferView.[Ch]: + * BufferView.[Ch]: + * buffer.[Ch]: + * buffer.[Ch]: move LyXText member + 2003-11-28 André Pönitz * BufferView.[Ch]: make LyXText * text a private member diff --git a/src/buffer.C b/src/buffer.C index 528249af2f..0485be21db 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -31,6 +31,7 @@ #include "LaTeXFeatures.h" #include "LyXAction.h" #include "lyxlex.h" +#include "lyxtext.h" #include "lyxrc.h" #include "lyxvc.h" #include "messages.h" @@ -179,13 +180,17 @@ struct Buffer::Impl * and by the citation inset. */ bool file_fully_loaded; + + /// our Text + LyXText text; }; Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_) : nicefile(true), lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), - filename(file), filepath(OnlyPath(file)), file_fully_loaded(false) + filename(file), filepath(OnlyPath(file)), file_fully_loaded(false), + text(0, 0, 0, paragraphs) { lyxvc.buffer(&parent); if (readonly_ || lyxrc.use_tempdir) @@ -220,6 +225,12 @@ Buffer::~Buffer() } +LyXText & Buffer::text() const +{ + return const_cast(pimpl_->text); +} + + limited_stack & Buffer::undostack() { return pimpl_->undostack; diff --git a/src/buffer.h b/src/buffer.h index 27c9dd29f8..044fabd53e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -34,6 +34,7 @@ class FuncRequest; class LyXFont; class LyXLex; class LyXRC; +class LyXText; class LyXVC; class LaTeXFeatures; class OutputParams; @@ -367,6 +368,9 @@ public: /// Set by buffer_funcs' newFile. void fully_loaded(bool); + /// + LyXText & text() const; + private: /** Inserts a file into a document \param par if != 0 insert the file. -- 2.39.2