]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
formatting
[lyx.git] / src / paragraph.C
index ee256c90af60e01abd461754079e027dbada8f81..a45454a4e9825f716685a6fda78079534152e6ca 100644 (file)
 #include "outputparams.h"
 #include "paragraph_funcs.h"
 #include "ParagraphList_fwd.h"
+
+#include "rowpainter.h"
+
 #include "sgml.h"
 #include "texrow.h"
 #include "vspace.h"
 
+#include "frontends/FontMetrics.h"
+
 #include "insets/insetbibitem.h"
 #include "insets/insetoptarg.h"
 
 #include <stack>
 #include <sstream>
 
-
-namespace lyx {
-
-using lyx::support::contains;
-using lyx::support::rsplit;
-using support::subst;
-
 using std::distance;
 using std::endl;
 using std::list;
@@ -68,88 +66,11 @@ using std::string;
 using std::ostream;
 using std::ostringstream;
 
+namespace lyx {
 
-ParagraphMetrics::ParagraphMetrics()
-{
-}
-
-
-ParagraphMetrics::ParagraphMetrics(ParagraphMetrics const & pm)
-       : dim_(pm.dim_), rows_(pm.rows_), rowSignature_(pm.rowSignature_)
-{
-}
-
-
-ParagraphMetrics & ParagraphMetrics::operator=(ParagraphMetrics const & pm)
-{
-       rows_ = pm.rows_;
-       dim_ = pm.dim_;
-       rowSignature_ = pm.rowSignature_;
-       return *this;
-}
-
-
-Row & ParagraphMetrics::getRow(pos_type pos, bool boundary)
-{
-       BOOST_ASSERT(!rows().empty());
-
-       // If boundary is set we should return the row on which
-       // the character before is inside.
-       if (pos > 0 && boundary)
-               --pos;
-
-       RowList::iterator rit = rows_.end();
-       RowList::iterator const begin = rows_.begin();
-
-       for (--rit; rit != begin && rit->pos() > pos; --rit)
-               ;
-
-       return *rit;
-}
-
-
-Row const & ParagraphMetrics::getRow(pos_type pos, bool boundary) const
-{
-       BOOST_ASSERT(!rows().empty());
-
-       // If boundary is set we should return the row on which
-       // the character before is inside.
-       if (pos > 0 && boundary)
-               --pos;
-
-       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 ParagraphMetrics::pos2row(pos_type pos) const
-{
-       BOOST_ASSERT(!rows().empty());
-
-       RowList::const_iterator rit = rows_.end();
-       RowList::const_iterator const begin = rows_.begin();
-
-       for (--rit; rit != begin && rit->pos() > pos; --rit)
-               ;
-
-       return rit - begin;
-}
-
-
-void ParagraphMetrics::dump() const
-{
-       lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
-       for (size_t i = 0; i != rows_.size(); ++i) {
-               lyxerr << "  row " << i << ":   ";
-               rows_[i].dump();
-       }
-}
-
+using support::contains;
+using support::rsplit;
+using support::subst;
 
 Paragraph::Paragraph()
        : begin_of_body_(0), pimpl_(new Paragraph::Pimpl(this))
@@ -160,8 +81,7 @@ Paragraph::Paragraph()
 
 
 Paragraph::Paragraph(Paragraph const & par)
-       : ParagraphMetrics(par),
-       itemdepth(par.itemdepth), insetlist(par.insetlist),
+       : itemdepth(par.itemdepth), insetlist(par.insetlist),
        layout_(par.layout_),
        text_(par.text_), begin_of_body_(par.begin_of_body_),
        pimpl_(new Paragraph::Pimpl(*par.pimpl_, this))
@@ -192,8 +112,6 @@ Paragraph & Paragraph::operator=(Paragraph const & par)
 
                delete pimpl_;
                pimpl_ = new Pimpl(*par.pimpl_, this);
-
-               ParagraphMetrics::operator=(par);
        }
        return *this;
 }
@@ -1686,4 +1604,25 @@ bool Paragraph::hfillExpansion(Row const & row, pos_type pos) const
 }
 
 
+bool Paragraph::checkBiblio(bool track_changes)
+{
+       // Add bibitem insets if necessary
+       if (layout()->labeltype != LABEL_BIBLIO)
+               return false;
+
+       bool hasbibitem = !insetlist.empty()
+               // Insist on it being in pos 0
+               && getChar(0) == Paragraph::META_INSET
+               && insetlist.begin()->inset->lyxCode() == InsetBase::BIBITEM_CODE;
+
+       if (hasbibitem)
+               return false;
+
+       InsetBibitem * inset(new InsetBibitem(InsetCommandParams("bibitem")));
+       insertInset(0, static_cast<InsetBase *>(inset),
+               Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
+
+       return true;
+}
+
 } // namespace lyx