From: Richard Heck Date: Sat, 4 Apr 2009 19:34:14 +0000 (+0000) Subject: Manage the initial setting of Default or Plain Layout more simply. X-Git-Tag: 2.0.0~6940 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=920bfedf1f59084575c19b76a9fa824604e94408;p=features.git Manage the initial setting of Default or Plain Layout more simply. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29093 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 45e4ebe72f..fb599edbc5 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -40,13 +40,8 @@ using namespace std; namespace lyx { InsetBranch::InsetBranch(Buffer const & buf, InsetBranchParams const & params) - : InsetCollapsable(buf), params_(params) -{ - // override the default for InsetCollapsable, which is to - // use the plain layout. - DocumentClass const & dc = buf.params().documentClass(); - paragraphs().back().setDefaultLayout(dc); -} + : InsetCollapsable(buf, InsetText::DefaultLayout), params_(params) +{} InsetBranch::~InsetBranch() diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index e66b728d4e..a846fc9159 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -48,13 +48,11 @@ namespace lyx { InsetCaption::InsetCaption(Buffer const & buf) - : InsetText(buf) + : InsetText(buf, InsetText::PlainLayout) { setAutoBreakRows(true); setDrawFrame(true); setFrameColor(Color_captionframe); - // caption insets should use the plain layout - paragraphs().back().setPlainLayout(buf.params().documentClass()); } diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 24065cd9fc..e2fbb3600c 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -102,16 +102,14 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const } -InsetCollapsable::InsetCollapsable(Buffer const & buf) - : InsetText(buf), status_(Inset::Open), +InsetCollapsable::InsetCollapsable(Buffer const & buf, InsetText::UsePlain ltype) + : InsetText(buf, ltype), status_(Inset::Open), openinlined_(false), mouse_hover_(false) { - DocumentClass const & dc = buf.params().documentClass(); - setLayout(&dc); + setLayout(&buf.params().documentClass()); setAutoBreakRows(true); setDrawFrame(true); setFrameColor(Color_collapsableframe); - paragraphs().back().setPlainLayout(dc); } diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 22c062e69c..9b4e9b02bf 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -32,11 +32,8 @@ namespace frontend { class Painter; } */ class InsetCollapsable : public InsetText { public: - /// By default, InsetCollapsable uses the plain layout. If you - /// want to override this in a subclass, you'll need to call - /// Paragraph::setDefaultLayout() in its constructor. See - /// InsetBranch for an example. - InsetCollapsable(Buffer const &); + /// + InsetCollapsable(Buffer const &, InsetText::UsePlain = InsetText::PlainLayout); /// InsetCollapsable(InsetCollapsable const & rhs); /// diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 373cd35758..427e7020b6 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -490,7 +490,6 @@ Tabular::CellData::CellData(Buffer & buf) inset(new InsetTableCell(buf)) { inset->setBuffer(const_cast(buf)); - inset->paragraphs().back().setLayout(buf.params().documentClass().plainLayout()); } @@ -2841,7 +2840,7 @@ Tabular::BoxType Tabular::useParbox(idx_type cell) const ///////////////////////////////////////////////////////////////////// InsetTableCell::InsetTableCell(Buffer & buf) - : InsetText(buf), isFixedWidth(false), + : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false), contentAlign(LYX_ALIGN_CENTER) {} diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 1d843502ce..0232078b7e 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -71,11 +71,11 @@ using graphics::PreviewLoader; ///////////////////////////////////////////////////////////////////// -InsetText::InsetText(Buffer const & buf) +InsetText::InsetText(Buffer const & buf, UsePlain type) : drawFrame_(false), frame_color_(Color_insetframe) { setBuffer(const_cast(buf)); - initParagraphs(); + initParagraphs(type); } @@ -99,13 +99,17 @@ void InsetText::setBuffer(Buffer & buf) } -void InsetText::initParagraphs() +void InsetText::initParagraphs(UsePlain type) { LASSERT(paragraphs().empty(), /**/); paragraphs().push_back(Paragraph()); Paragraph & ourpar = paragraphs().back(); ourpar.setInsetOwner(this); - ourpar.setDefaultLayout(buffer_->params().documentClass()); + DocumentClass const & dc = buffer_->params().documentClass(); + if (type == DefaultLayout) + ourpar.setDefaultLayout(dc); + else + ourpar.setPlainLayout(dc); } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index aabe82ede7..90d246719c 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -34,8 +34,15 @@ class InsetTabular; */ class InsetText : public Inset { public: - /// - explicit InsetText(Buffer const & buffer); + enum UsePlain { + DefaultLayout, + PlainLayout + }; + /// \param buffer + /// \param useplain whether to use the plain layout + /// This is needed because we cannot call the virtual function + /// usePlainLayout() from within the constructor. + explicit InsetText(Buffer const & buffer, UsePlain type = DefaultLayout); /// InsetText(InsetText const &); /// @@ -169,7 +176,7 @@ public: void doDispatch(Cursor & cur, FuncRequest & cmd); private: /// - void initParagraphs(); + void initParagraphs(UsePlain type); /// void setParagraphOwner(); ///