]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
64 bit compile fixes.
[lyx.git] / src / paragraph.C
index 1dec5968edb708a13aa3997c57942645e511ab28..365600571cd6c1d89b9101511e986a53e3f97c26 100644 (file)
@@ -55,6 +55,7 @@ using lyx::pos_type;
 using lyx::support::contains;
 using lyx::support::subst;
 
+using std::distance;
 using std::endl;
 using std::list;
 using std::stack;
@@ -73,16 +74,13 @@ 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;
+       //lyxerr << "Paragraph::Paragraph(Paragraph const&)" << endl;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it)
@@ -90,30 +88,30 @@ Paragraph::Paragraph(Paragraph const & par)
 }
 
 
-void Paragraph::operator=(Paragraph const & par)
+Paragraph & Paragraph::operator=(Paragraph const & par)
 {
        // needed as we will destroy the pimpl_ before copying it
-       if (&par != this)
-               return;
-
-       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();
+       if (&par != this) {
+               itemdepth = par.itemdepth;
+
+               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);
+       }
+       return *this;
 }
 
 
@@ -327,7 +325,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();
@@ -518,7 +519,7 @@ void Paragraph::setFont(pos_type pos, LyXFont const & font)
                if (it->pos() >= pos)
                        break;
        }
-       unsigned int i = std::distance(beg, it);
+       unsigned int i = distance(beg, it);
        bool notfound = (it == endit);
 
        if (!notfound && pimpl_->fontlist[i].font() == font)
@@ -644,7 +645,7 @@ void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
 }
 
 
-int Paragraph::beginOfBody() const
+pos_type Paragraph::beginOfBody() const
 {
        return begin_of_body_;
 }
@@ -712,7 +713,7 @@ InsetBibitem * Paragraph::bibitem() const
 namespace {
 
 // paragraphs inside floats need different alignment tags to avoid
-// unwanted space 
+// unwanted space
 
 bool noTrivlistCentering(UpdatableInset const * inset)
 {
@@ -1338,7 +1339,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        int char_line_count = depth;
        bool label_closed = true;
        bool para_closed = true;
-       
+
        if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
                string ls = "";
                Counters & counters = buf.params().getLyXTextClass().counters();
@@ -1351,11 +1352,11 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                        if (!defaultstyle->latexparam().empty()) {
                                counters.step("para");
                                ls = tostr(counters.value("para"));
-                               ls = " id=\"" 
+                               ls = " id=\""
                                        + subst(defaultstyle->latexparam(), "#", ls) + '"';
                        }
-                       os << "<" << style->itemtag() << ">\n" 
-                          << string(depth, ' ') << "<" 
+                       os << "<" << style->itemtag() << ">\n"
+                          << string(depth, ' ') << "<"
                           << defaultstyle->latexname() << ls << ">\n";
                        para_closed = false;
                }
@@ -1384,7 +1385,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)
@@ -1408,8 +1408,8 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                        os << str;
                        } else if (!style->labeltag().empty() && !label_closed) {
                                ++char_line_count;
-                               os << "\n</" << style->labeltag() << "><" 
-                                  << style->itemtag() << "><" 
+                               os << "\n</" << style->labeltag() << "><"
+                                  << style->itemtag() << "><"
                                   << defaultstyle->latexname() << ">";
                                label_closed = true;
                                para_closed = false;
@@ -1431,12 +1431,12 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        // resets description flag correctly
        if (!label_closed) {
                // <term> not closed...
-               os << "</" << style->labeltag() << ">\n<" 
-                  << style->itemtag() << "><" 
+               os << "</" << style->labeltag() << ">\n<"
+                  << style->itemtag() << "><"
                   << defaultstyle->latexname() << ">&nbsp;";
        }
        if (!para_closed) {
-               os << "\n" << string(depth, ' ') << "</" 
+               os << "\n" << string(depth, ' ') << "</"
                   << defaultstyle->latexname() << ">\n";
        }
        if (style->free_spacing)
@@ -1553,7 +1553,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();
@@ -1702,7 +1702,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);
-
 }
 
 
@@ -1737,7 +1736,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];
@@ -1832,6 +1830,30 @@ 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();
+       RowList::const_iterator const begin = rows.begin();
+
+       for (--rit; rit != begin && rit->pos() > pos; --rit)
+               ;
+
+       return rit - begin;
+}
+
+
 unsigned char Paragraph::transformChar(unsigned char c, pos_type pos) const
 {
        if (!Encodings::is_arabic(c))