]> git.lyx.org Git - features.git/commitdiff
(temporarily) add a Buffer * Inset::buffer_ membert
authorAndré Pönitz <poenitz@gmx.net>
Sat, 23 Feb 2008 22:32:33 +0000 (22:32 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 23 Feb 2008 22:32:33 +0000 (22:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23170 a592a061-630c-0410-9148-cb99ea01b6c8

src/CutAndPaste.cpp
src/factory.cpp
src/insets/Inset.h
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h

index 019783f5e63ae437ad231f0b4a3bc8386394ab0b..eed8123521bbd66d3a0e10b25c5d18cb64c3dfb8 100644 (file)
@@ -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<InsetTabular*>(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 *>(&buffer));
        }
        insertion.swap(in.paragraphs());
 
index edc01f2c017c053f0b185f9b5f9878ca85f16e15..39a6b15c8fc284e37ffe387fc3c6d8564f329684 100644 (file)
@@ -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)
 {
index e9c6b3e9e4cb52e12901c7271e38273f13e56750..349220bcccad7b95f41792a7b1a281df7b892d15 100644 (file)
@@ -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
index 35ca668d1947f5a59be04c7b38cd42f20dd5ceda..683dfc6cf0557c558469b72974eba2256889c504 100644 (file)
@@ -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<Buffer *>(&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<Buffer *>(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();
 }
index 79bc8cea23f7fc994408a2315a94f13580c88f00..a07cae58e704e1592bba3a16b040f88f48715b02 100644 (file)
@@ -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_;