]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
more 'value' semantics for paragraphs
[lyx.git] / src / paragraph.C
index 9f0d646d8e6a61daf19c794b08666c6c8986fe36..2be105b73b34677e7989a48cd9562a8ee61985fd 100644 (file)
@@ -74,16 +74,12 @@ Paragraph::Paragraph()
 
 
 Paragraph::Paragraph(Paragraph const & par)
-       : y(0), height(0), text_(par.text_), begin_of_body_(par.begin_of_body_),
+       :       itemdepth(par.itemdepth), insetlist(par.insetlist),
+               rows(par.rows), y(par.y), height(par.height),
+               width(par.width), layout_(par.layout_),
+               text_(par.text_), begin_of_body_(par.begin_of_body_),
          pimpl_(new Paragraph::Pimpl(*par.pimpl_, this))
 {
-       itemdepth = 0;
-       // this is because of the dummy layout of the paragraphs that
-       // follow footnotes
-       layout_ = par.layout();
-
-       // copy everything behind the break-position to the new paragraph
-       insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it)
@@ -99,22 +95,24 @@ void Paragraph::operator=(Paragraph const & par)
 
        lyxerr << "Paragraph::operator=()" << endl;
 
-       text_ = par.text_;
-
-       delete pimpl_;
-       pimpl_ = new Pimpl(*par.pimpl_, this);
-
        itemdepth = par.itemdepth;
-       // this is because of the dummy layout of the paragraphs that
-       // follow footnotes
-       layout_ = par.layout();
 
-       // copy everything behind the break-position to the new paragraph
        insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it)
                it->inset = it->inset->clone().release();
+
+       rows = par.rows;
+       y = par.y;
+       height = par.height;
+       width = par.width;
+       layout_ = par.layout();
+       text_ = par.text_;
+       begin_of_body_ = par.begin_of_body_;
+
+       delete pimpl_;
+       pimpl_ = new Pimpl(*par.pimpl_, this);
 }
 
 
@@ -328,7 +326,10 @@ InsetBase const * Paragraph::getInset(pos_type pos) const
 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
                                         pos_type pos) const
 {
-       BOOST_ASSERT(pos <= size());
+       if (pos > size()) {
+               lyxerr << " pos: " << pos << " size: " << size() << endl;
+               BOOST_ASSERT(pos <= size());
+       }
 
        Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
        Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
@@ -1385,7 +1386,6 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                        }
                }
 
-
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
                        // don't print the inset in position 0 if desc_on == 3 (label)
@@ -1554,7 +1554,7 @@ void Paragraph::changeLanguage(BufferParams const & bparams,
 }
 
 
-bool Paragraph::isMultiLingual(BufferParams const & bparams)
+bool Paragraph::isMultiLingual(BufferParams const & bparams) const
 {
        Language const * doc_language = bparams.language;
        Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
@@ -1703,7 +1703,6 @@ bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
 {
        pimpl_->setChange(pos, type);
-
 }
 
 
@@ -1738,7 +1737,6 @@ Paragraph::value_type Paragraph::getChar(pos_type pos) const
                       << id() << " of size " << siz
                       << "  is a bit silly !" << endl;
                BOOST_ASSERT(false);
-               return '\0';
        }
 
        return text_[pos];
@@ -1833,6 +1831,18 @@ RowList::iterator Paragraph::getRow(pos_type pos)
 }
 
 
+RowList::const_iterator Paragraph::getRow(pos_type pos) const
+{
+       RowList::const_iterator rit = rows.end();
+       RowList::const_iterator const begin = rows.begin();
+
+       for (--rit; rit != begin && rit->pos() > pos; --rit)
+               ;
+
+       return rit;
+}
+
+
 size_t Paragraph::row(pos_type pos) const
 {
        RowList::const_iterator rit = rows.end();