From fa1305ccd33e3b58b42b9a4516718ac88ce568b5 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 29 Jul 2008 12:07:08 +0000 Subject: [PATCH] InsetText: remove InsetText default ctor and make text_ member private. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25974 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 2 +- src/CutAndPaste.cpp | 3 ++- src/Text3.cpp | 2 +- src/insets/InsetBranch.cpp | 2 +- src/insets/InsetCaption.cpp | 4 ++-- src/insets/InsetCollapsable.cpp | 2 +- src/insets/InsetTabular.cpp | 10 +++++----- src/insets/InsetText.cpp | 13 +++++-------- src/insets/InsetText.h | 11 +++++------ 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 96c4c6adc6..406682b0ef 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -315,7 +315,7 @@ frontend::WorkAreaManager & Buffer::workAreaManager() const Text & Buffer::text() const { - return d->inset->text_; + return d->inset->text(); } diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index e878e30c1f..ba82e9439f 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -154,8 +154,9 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, } } + InsetText in(buffer); // Make sure there is no class difference. - InsetText in; + in.paragraphs().clear(); // This works without copying any paragraph data because we have // a specialized swap method for ParagraphList. This is important // since we store pointers to insets at some places and we don't diff --git a/src/Text3.cpp b/src/Text3.cpp index 3671170eaf..b1635e2f55 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -202,7 +202,7 @@ static bool doInsertInset(Cursor & cur, Text * text, if (edit) inset->edit(cur, true); // Now put this into inset - static_cast(inset)->text_.insertStringAsParagraphs(cur, ds); + static_cast(inset)->text().insertStringAsParagraphs(cur, ds); return true; } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 02537c05f6..3eea5ddefb 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -277,7 +277,7 @@ void InsetBranch::addToToc(DocIterator const & cpit) pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc("branch"); - docstring const str = params_.branch + ": " + text_.getPar(0).asString(); + docstring const str = params_.branch + ": " + text().getPar(0).asString(); toc.push_back(TocItem(pit, 0, str)); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit); diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index b0f4d02981..be5bc00d3f 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -61,7 +61,7 @@ InsetCaption::InsetCaption(Buffer const & buf) void InsetCaption::write(ostream & os) const { os << "Caption\n"; - text_.write(buffer(), os); + text().write(buffer(), os); } @@ -111,7 +111,7 @@ void InsetCaption::addToToc(DocIterator const & cpit) pit.push_back(CursorSlice(*this)); Toc & toc = buffer().tocBackend().toc(type_); - docstring const str = full_label_ + ". " + text_.getPar(0).asString(); + docstring const str = full_label_ + ". " + text().getPar(0).asString(); toc.push_back(TocItem(pit, 0, str)); // Proceed with the rest of the inset. diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 7cb36e2a9a..e897ee02b7 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -167,7 +167,7 @@ void InsetCollapsable::write(ostream & os) const break; } os << "\n"; - text_.write(buffer(), os); + text().write(buffer(), os); } diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index cbce92c348..7cf33c3288 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3903,14 +3903,14 @@ Inset * InsetTabular::editXY(Cursor & cur, int x, int y) cur.push(*this); cur.idx() = getNearestCell(cur.bv(), x, y); resetPos(cur); - return cur.bv().textMetrics(&cell(cur.idx())->text_).editXY(cur, x, y); + return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y); } void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const { cur.idx() = getNearestCell(cur.bv(), x, y); - cur.bv().textMetrics(&cell(cur.idx())->text_).setCursorFromCoordinates(cur, x, y); + cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y); } @@ -4755,7 +4755,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf, // we can only set this if we are not too far right if (cols < columns) { shared_ptr inset = loctab->cellInset(cell); - Font const font = bv.textMetrics(&inset->text_). + Font const font = bv.textMetrics(&inset->text()). displayFont(0, 0); inset->setText(buf.substr(op, p - op), font, buffer().params().trackChanges); @@ -4767,7 +4767,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf, // we can only set this if we are not too far right if (cols < columns) { shared_ptr inset = tabular.cellInset(cell); - Font const font = bv.textMetrics(&inset->text_). + Font const font = bv.textMetrics(&inset->text()). displayFont(0, 0); inset->setText(buf.substr(op, p - op), font, buffer().params().trackChanges); @@ -4784,7 +4784,7 @@ bool InsetTabular::insertPlaintextString(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->cellInset(cell); - Font const font = bv.textMetrics(&inset->text_).displayFont(0, 0); + Font const font = bv.textMetrics(&inset->text()).displayFont(0, 0); inset->setText(buf.substr(op, len - op), font, buffer().params().trackChanges); } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 71bc8ae80e..cf34fc9ed0 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -73,7 +73,8 @@ using graphics::PreviewLoader; InsetText::InsetText(Buffer const & buf) : drawFrame_(false), frame_color_(Color_insetframe) { - initParagraphs(buf); + initParagraphs(buf.params()); + setBuffer(const_cast(buf)); } @@ -88,10 +89,6 @@ InsetText::InsetText(InsetText const & in) } -InsetText::InsetText() -{} - - void InsetText::setBuffer(Buffer & buf) { ParagraphList::iterator end = paragraphs().end(); @@ -101,16 +98,16 @@ void InsetText::setBuffer(Buffer & buf) } -void InsetText::initParagraphs(Buffer const & buf) +void InsetText::initParagraphs(BufferParams const & bparams) { LASSERT(paragraphs().empty(), /**/); - buffer_ = const_cast(&buf); paragraphs().push_back(Paragraph()); Paragraph & ourpar = paragraphs().back(); - ourpar.setPlainOrDefaultLayout(buf.params().documentClass()); + ourpar.setPlainOrDefaultLayout(bparams.documentClass()); ourpar.setInsetOwner(this); } + void InsetText::setParagraphOwner() { for_each(paragraphs().begin(), paragraphs().end(), diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 7be51ddd01..f20fd4a0b3 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -37,12 +37,8 @@ public: /// explicit InsetText(Buffer const & buffer); /// - InsetText(); - /// InsetText(InsetText const &); /// - void initParagraphs(Buffer const & buffer); - /// void setBuffer(Buffer &); /// @@ -69,6 +65,9 @@ public: /// InsetText const * asInsetText() const { return this; } /// + Text & text() { return text_; } + Text const & text() const { return text_; } + /// int latex(odocstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; @@ -169,6 +168,8 @@ public: /// void doDispatch(Cursor & cur, FuncRequest & cmd); private: + /// + void initParagraphs(BufferParams const &); /// void setParagraphOwner(); /// @@ -177,8 +178,6 @@ private: ColorCode frame_color_; /// mutable pit_type old_pit; - -public: /// mutable Text text_; }; -- 2.39.2