From: André Pönitz Date: Sat, 23 Feb 2008 22:32:33 +0000 (+0000) Subject: (temporarily) add a Buffer * Inset::buffer_ membert X-Git-Tag: 1.6.10~6131 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e05e2b6b19ce30eb2b21616d00e319b300c5c586;p=features.git (temporarily) add a Buffer * Inset::buffer_ membert git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23170 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 019783f5e6..eed8123521 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -217,21 +217,10 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, ParIterator fend = par_iterator_end(in); for (; fpit != fend; ++fpit) { - InsetList::const_iterator lit = fpit->insetList().begin(); - InsetList::const_iterator eit = fpit->insetList().end(); - - for (; lit != eit; ++lit) { - switch (lit->inset->lyxCode()) { - case TABULAR_CODE: { - InsetTabular * it = static_cast(lit->inset); - it->buffer(&buffer); - break; - } - - default: - break; // nothing - } - } + InsetList::const_iterator it = fpit->insetList().begin(); + InsetList::const_iterator et = fpit->insetList().end(); + for (; it != et; ++it) + it->inset->setBuffer(const_cast(&buffer)); } insertion.swap(in.paragraphs()); diff --git a/src/factory.cpp b/src/factory.cpp index edc01f2c01..39a6b15c8f 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -75,7 +75,7 @@ namespace lyx { namespace Alert = frontend::Alert; -Inset * createInset(Buffer & buf, FuncRequest const & cmd) +Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd) { BufferParams const & params = buf.params(); @@ -372,6 +372,13 @@ Inset * createInset(Buffer & buf, FuncRequest const & cmd) return 0; } +Inset * createInset(Buffer & buf, FuncRequest const & cmd) +{ + Inset * inset = createInsetHelper(buf, cmd); + if (inset) + inset->setBuffer(&buf); + return inset; +} Inset * readInset(Lexer & lex, Buffer const & buf) { diff --git a/src/insets/Inset.h b/src/insets/Inset.h index e9c6b3e9e4..349220bccc 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -90,6 +90,13 @@ public: /// virtual base class destructor virtual ~Inset() {} + /// change associated Buffer + virtual void setBuffer(Buffer * buffer) { buffer_ = buffer; } + virtual void setBufferRecursively(Buffer *) {} + /// retrieve associated Buffer + virtual Buffer * buffer() { return buffer_; } + virtual Buffer const * buffer() const { return buffer_; } + /// identification as math inset virtual InsetMath * asInsetMath() { return 0; } /// true for 'math' math inset, but not for e.g. mbox @@ -477,7 +484,8 @@ public: enum { TEXT_TO_INSET_OFFSET = 4 }; protected: - Inset() {} + /// Constructor + explicit Inset() : buffer_(0) {} /// replicate ourselves friend class InsetList; @@ -496,6 +504,8 @@ protected: * \sa getStatus */ virtual void doDispatch(Cursor & cur, FuncRequest & cmd); + + Buffer * buffer_; }; } // namespace lyx diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 35ca668d19..683dfc6cf0 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -2869,14 +2869,17 @@ Tabular::BoxType Tabular::useParbox(idx_type cell) const InsetTabular::InsetTabular(Buffer const & buf, row_type rows, col_type columns) : tabular(buf.params(), max(rows, row_type(1)), - max(columns, col_type(1))), buffer_(&buf), scx_(0) -{} + max(columns, col_type(1))), scx_(0) +{ + setBuffer(const_cast(&buf)); // FIXME: remove later +} InsetTabular::InsetTabular(InsetTabular const & tab) - : Inset(tab), tabular(tab.tabular), - buffer_(tab.buffer_), scx_(0) -{} + : Inset(tab), tabular(tab.tabular), scx_(0) +{ + setBuffer(const_cast(tab.buffer())); // FIXME: remove later +} InsetTabular::~InsetTabular() @@ -2891,18 +2894,6 @@ Inset * InsetTabular::clone() const } -Buffer const & InsetTabular::buffer() const -{ - return *buffer_; -} - - -void InsetTabular::buffer(Buffer const * b) -{ - buffer_ = b; -} - - bool InsetTabular::insetAllowed(InsetCode code) const { if (code == MATHMACRO_CODE) @@ -4867,7 +4858,7 @@ void InsetTabularMailer::string2params(string const & in, InsetTabular & inset) return print_mailer_error("InsetTabularMailer", in, 2, "Tabular"); - Buffer const & buffer = inset.buffer(); + Buffer const & buffer = *inset.buffer(); inset.read(buffer, lex); } @@ -4876,7 +4867,7 @@ string const InsetTabularMailer::params2string(InsetTabular const & inset) { ostringstream data; data << name_ << ' '; - inset.write(inset.buffer(), data); + inset.write(*inset.buffer(), data); data << "\\end_inset\n"; return data.str(); } diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 79bc8cea23..a07cae58e7 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -740,11 +740,6 @@ public: /// void addPreview(graphics::PreviewLoader &) const; - /// - Buffer const & buffer() const; - - /// set the owning buffer - void buffer(Buffer const * buf); /// lock cell with given index void edit(Cursor & cur, bool front, EntryDirection entry_from); /// @@ -814,8 +809,6 @@ private: row_type row_start, row_type row_end, col_type col_start, col_type col_end) const; /// - Buffer const * buffer_; - /// mutable idx_type first_visible_cell; /// mutable int scx_;