From e8674d6141a5611aff74b1865b5d17549d101545 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 9 Aug 2009 15:05:36 +0000 Subject: [PATCH] General cleanup: Text is (or should be) nothing more than InsetText private implementation. We need access to the owner InsetText property in many cases where we instead take the Paragraph owner inset, which is the same of course. Next step is to avoid this indirection whenever possible. I also updated InsetMathMBox so that it remains compilable, even if not used. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30940 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Text.h | 9 ++++++++- src/Text2.cpp | 5 ----- src/insets/InsetText.cpp | 4 ++-- src/mathed/InsetMathMBox.cpp | 23 ++++++++++++----------- src/mathed/InsetMathMBox.h | 9 +++++---- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Text.h b/src/Text.h index df19ca7ae2..1ec93b006a 100644 --- a/src/Text.h +++ b/src/Text.h @@ -41,13 +41,17 @@ class Spacing; class Text { public: /// constructor - explicit Text(); + explicit Text(InsetText * owner) + : autoBreakRows_(false), owner_(owner) + {} /// \return true if there's no content at all. /// \warning a non standard layout on an empty paragraph doesn't // count as empty. bool empty() const; + InsetText const * inset() { return owner_; } + /// FontInfo layoutFont(Buffer const & buffer, pit_type pit) const; /// @@ -344,6 +348,9 @@ private: void pasteString(Cursor & cur, docstring const & str, bool asParagraphs); + /// Owner Inset. + InsetText * owner_; + /// position of the text in the buffer. DocIterator macrocontext_position_; }; diff --git a/src/Text2.cpp b/src/Text2.cpp index ed2f3fd0ba..98999c92b0 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -63,11 +63,6 @@ using namespace std; namespace lyx { -Text::Text() - : autoBreakRows_(false) -{} - - bool Text::isMainText(Buffer const & buffer) const { return &buffer.text() == this; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 0adddb48b7..8247d57d89 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -76,7 +76,7 @@ using graphics::PreviewLoader; ///////////////////////////////////////////////////////////////////// InsetText::InsetText(Buffer const & buf, UsePlain type) - : drawFrame_(false), frame_color_(Color_insetframe) + : drawFrame_(false), frame_color_(Color_insetframe), text_(this) { setBuffer(const_cast(buf)); initParagraphs(type); @@ -84,7 +84,7 @@ InsetText::InsetText(Buffer const & buf, UsePlain type) InsetText::InsetText(InsetText const & in) - : Inset(in), text_() + : Inset(in), text_(this) { text_.autoBreakRows_ = in.text_.autoBreakRows_; drawFrame_ = in.drawFrame_; diff --git a/src/mathed/InsetMathMBox.cpp b/src/mathed/InsetMathMBox.cpp index 26bbf183c7..f7d7d1b07c 100644 --- a/src/mathed/InsetMathMBox.cpp +++ b/src/mathed/InsetMathMBox.cpp @@ -32,14 +32,15 @@ using namespace std; namespace lyx { -InsetMathMBox::InsetMathMBox() +InsetMathMBox::InsetMathMBox(Buffer const & buffer) : text_(buffer) { text_.paragraphs().clear(); text_.paragraphs().push_back(Paragraph()); } -InsetMathMBox::InsetMathMBox(Layout const & layout) +InsetMathMBox::InsetMathMBox(Buffer const & buffer, Layout const & layout) + : text_(buffer) { text_.paragraphs().clear(); text_.paragraphs().push_back(Paragraph()); @@ -55,7 +56,7 @@ Inset * InsetMathMBox::clone() const void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const { - TextMetrics & tm = mi.base.bv->textMetrics(&text_); + TextMetrics & tm = mi.base.bv->textMetrics(&text_.text()); tm.metrics(mi, dim); metricsMarkers2(dim); } @@ -63,7 +64,7 @@ void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const { - pi.base.bv->textMetrics(&text_).draw(pi, x + 1, y); + pi.base.bv->textMetrics(&text_.text()).draw(pi, x + 1, y); drawMarkers(pi, x, y); } @@ -74,13 +75,13 @@ void InsetMathMBox::write(WriteStream & ws) const ws << "\\mbox{\n"; TexRow texrow; OutputParams runparams(&buffer().params().encoding()); - latexParagraphs(buffer(), text_, ws.os(), texrow, runparams); + latexParagraphs(buffer(), text_.text(), ws.os(), texrow, runparams); ws.addlines(texrow.rows()); ws << "}"; } else { ws << "\\mbox{\n"; ostringstream os; - text_.write(buffer(), os); + text_.text().write(buffer(), os); ws.os() << from_utf8(os.str()); ws << "}"; } @@ -91,7 +92,7 @@ int InsetMathMBox::latex(odocstream & os, OutputParams const & runparams) const { os << "\\mbox{\n"; TexRow texrow; - latexParagraphs(buffer(), text_, os, texrow, runparams); + latexParagraphs(buffer(), text_.text(), os, texrow, runparams); os << "}"; return texrow.rows(); } @@ -99,21 +100,21 @@ int InsetMathMBox::latex(odocstream & os, OutputParams const & runparams) const void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd) { - text_.dispatch(cur, cmd); + text_.text().dispatch(cur, cmd); } Text * InsetMathMBox::getText(int) const { - return &text_; + return &text_.text(); } void InsetMathMBox::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = bv.textMetrics(&text_).cursorX(sl, boundary); - y = bv.textMetrics(&text_).cursorY(sl, boundary); + x = bv.textMetrics(&text_.text()).cursorX(sl, boundary); + y = bv.textMetrics(&text_.text()).cursorY(sl, boundary); } diff --git a/src/mathed/InsetMathMBox.h b/src/mathed/InsetMathMBox.h index 3116e7d585..091de9ec79 100644 --- a/src/mathed/InsetMathMBox.h +++ b/src/mathed/InsetMathMBox.h @@ -17,7 +17,8 @@ #define MATH_MBOXINSET_H #include "InsetMath.h" -#include "Text.h" + +#include "insets/InsetText.h" namespace lyx { @@ -30,8 +31,8 @@ class BufferView; class InsetMathMBox : public InsetMath { public: /// - explicit InsetMathMBox(); - explicit InsetMathMBox(Layout const & layout); + explicit InsetMathMBox(Buffer const & buffer); + explicit InsetMathMBox(Buffer const & buffer, Layout const & layout); /// this stores metrics information in cache_ void metrics(MetricsInfo & mi, Dimension & dim) const; @@ -58,7 +59,7 @@ protected: virtual void doDispatch(Cursor & cur, FuncRequest & cmd); /// - mutable Text text_; + mutable InsetText text_; private: virtual Inset * clone() const; -- 2.39.5