]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
move some selection related stuff over to textcursor.C
[lyx.git] / src / paragraph.C
index 4d87ad7ba815a04b408ac114148589f5819f0718..fbedfeedc9ebcf65a828d1212cc7926d429e9d2a 100644 (file)
@@ -67,37 +67,20 @@ Inset * minibuffer_inset;
 } // namespace anon
 
 
-extern BufferView * current_view;
-
-
 Paragraph::Paragraph()
        : pimpl_(new Paragraph::Pimpl(this))
 {
-#ifndef NO_NEXT
-       next_ = 0;
-       previous_ = 0;
-#else
-       next_par_ = 0;
-       prev_par_ = 0;
-#endif
        enumdepth = 0;
        itemdepth = 0;
        params().clear();
 }
 
 
-Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
-       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
+Paragraph::Paragraph(Paragraph const & lp)
+       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
 {
        enumdepth = 0;
        itemdepth = 0;
-#ifndef NO_NEXT
-       next_     = 0;
-       previous_ = 0;
-#else
-       next_par_ = 0;
-       prev_par_ = 0;
-#endif
        // this is because of the dummy layout of the paragraphs that
        // follow footnotes
        layout_ = lp.layout();
@@ -107,24 +90,43 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it) {
-               it.setInset(it.getInset()->clone(*current_view->buffer(),
-                                                same_ids));
+               // currently we hold Inset*, not InsetBase*
+               it->inset = static_cast<Inset*>(it->inset->clone());
                // tell the new inset who is the boss now
-               it.getInset()->parOwner(this);
+               it->inset->parOwner(this);
        }
 }
 
 
+void Paragraph::operator=(Paragraph const & lp)
+{
+       // needed as we will destroy the pimpl_ before copying it
+       if (&lp != this)
+               return;
+       lyxerr << "Paragraph::operator=()\n";
+       delete pimpl_;
+       pimpl_ = new Pimpl(*lp.pimpl_, this);
+
+       enumdepth = lp.enumdepth;
+       itemdepth = lp.itemdepth;
+       // this is because of the dummy layout of the paragraphs that
+       // follow footnotes
+       layout_ = lp.layout();
+
+       // copy everything behind the break-position to the new paragraph
+       insetlist = lp.insetlist;
+       InsetList::iterator it = insetlist.begin();
+       InsetList::iterator end = insetlist.end();
+       for (; it != end; ++it) {
+               it->inset = static_cast<Inset*>(it->inset->clone());
+               // tell the new inset who is the boss now
+               it->inset->parOwner(this);
+       }
+}
+
 // the destructor removes the new paragraph from the list
 Paragraph::~Paragraph()
 {
-#ifndef NO_NEXT
-       if (previous_)
-               previous_->next_ = next_;
-       if (next_)
-               next_->previous_ = previous_;
-#endif
-
        delete pimpl_;
        //
        //lyxerr << "Paragraph::paragraph_id = "
@@ -255,7 +257,7 @@ void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
        minibuffer_inset = 0;
        if (minibuffer_char == Paragraph::META_INSET) {
                if (getInset(pos)) {
-                       minibuffer_inset = getInset(pos)->clone(buffer);
+                       minibuffer_inset = static_cast<Inset *>(getInset(pos)->clone());
                } else {
                        minibuffer_inset = 0;
                        minibuffer_char = ' ';
@@ -612,47 +614,6 @@ void Paragraph::setFont(pos_type pos, LyXFont const & font)
 }
 
 
-#ifndef NO_NEXT
-void Paragraph::next(Paragraph * p)
-{
-       next_ = p;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph * Paragraph::next()
-{
-       return next_;
-}
-
-
-Paragraph const * Paragraph::next() const
-{
-       return next_;
-}
-
-
-void Paragraph::previous(Paragraph * p)
-{
-       previous_ = p;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph * Paragraph::previous()
-{
-       return previous_;
-}
-
-
-// This function is able to hide closed footnotes.
-Paragraph const * Paragraph::previous() const
-{
-       return previous_;
-}
-#endif
-
-
 void Paragraph::makeSameLayout(Paragraph const & par)
 {
        layout(par.layout());
@@ -663,7 +624,7 @@ void Paragraph::makeSameLayout(Paragraph const & par)
 
 int Paragraph::stripLeadingSpaces()
 {
-       if (layout()->free_spacing || isFreeSpacing())
+       if (isFreeSpacing())
                return 0;
 
        int i = 0;
@@ -775,20 +736,20 @@ int Paragraph::beginningOfBody() const
 int Paragraph::getPositionOfInset(Inset const * inset) const
 {
        // Find the entry.
-       InsetList::iterator it = insetlist.begin();
-       InsetList::iterator end = insetlist.end();
+       InsetList::const_iterator it = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
        for (; it != end; ++it)
-               if (it.getInset() == inset)
-                       return it.getPos();
+               if (it->inset == inset)
+                       return it->pos;
        return -1;
 }
 
 
-InsetBibitem * Paragraph::bibitem()
+InsetBibitem * Paragraph::bibitem() const
 {
-       InsetList::iterator it = insetlist.begin();
-       if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
-               return static_cast<InsetBibitem *>(it.getInset());
+       InsetList::const_iterator it = insetlist.begin();
+       if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE)
+               return static_cast<InsetBibitem *>(it->inset);
        return 0;
 }
 
@@ -1231,6 +1192,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
 // Used for building the table of contents
 string const Paragraph::asString(Buffer const * buffer, bool label) const
 {
+#if 0
        string s;
        if (label && !params().labelString().empty())
                s += params().labelString() + ' ';
@@ -1248,6 +1210,11 @@ string const Paragraph::asString(Buffer const * buffer, bool label) const
        }
 
        return s;
+#else
+       // This should really be done by the caller and not here.
+       string ret(asString(buffer, 0, size(), label));
+       return subst(ret, '\n', ' ');
+#endif
 }
 
 
@@ -1271,14 +1238,14 @@ string const Paragraph::asString(Buffer const * buffer,
 }
 
 
-void Paragraph::setInsetOwner(Inset * i)
+void Paragraph::setInsetOwner(UpdatableInset * inset)
 {
-       pimpl_->inset_owner = i;
+       pimpl_->inset_owner = inset;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it)
-               if (it.getInset())
-                       it.getInset()->setOwner(i);
+               if (it->inset)
+                       it->inset->setOwner(inset);
 }
 
 
@@ -1395,11 +1362,19 @@ int Paragraph::id() const
 }
 
 
+void Paragraph::id(int i)
+{
+       pimpl_->id_ = i;
+}
+
+
 LyXLayout_ptr const & Paragraph::layout() const
 {
+/*
        Inset * inset = inInset();
        if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
                return static_cast<InsetEnvironment*>(inset)->layout();
+*/
        return layout_;
 }
 
@@ -1410,7 +1385,7 @@ void Paragraph::layout(LyXLayout_ptr const & new_layout)
 }
 
 
-Inset * Paragraph::inInset() const
+UpdatableInset * Paragraph::inInset() const
 {
        return pimpl_->inset_owner;
 }
@@ -1441,9 +1416,29 @@ ParagraphParameters const & Paragraph::params() const
 
 bool Paragraph::isFreeSpacing() const
 {
+       if (layout()->free_spacing)
+               return true;
+
        // for now we just need this, later should we need this in some
        // other way we can always add a function to Inset::() too.
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
                return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
        return false;
 }
+
+
+bool Paragraph::allowEmpty() const
+{
+       if (layout()->keepempty)
+               return true;
+       if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
+               return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
+       return false;
+}
+
+
+bool operator==(Paragraph const & lhs, Paragraph const & rhs)
+{
+#warning FIXME this implementatoin must be completely wrong...
+       return &lhs == &rhs;
+}