]> git.lyx.org Git - features.git/blobdiff - src/paragraph.C
Replace LString.h with support/std_string.h,
[features.git] / src / paragraph.C
index b766c4fb486e0a1908198d3c931626d059676680..0a6c8bd34d0fdf917434156efd20dbea781e4e87 100644 (file)
@@ -1,12 +1,19 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file paragraph.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
+ * \author Dekel Tsur
+ * \author Jürgen Vigna
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "paragraph_pimpl.h"
 
 #include "buffer.h"
-#include "bufferparams.h"
-#include "BufferView.h"
-#include "changes.h"
 #include "encoding.h"
 #include "debug.h"
 #include "gettext.h"
 #include "language.h"
 #include "latexrunparams.h"
-#include "layout.h"
-#include "lyxrc.h"
-#include "paragraph_funcs.h"
-#include "ParameterStruct.h"
-#include "texrow.h"
 
-#include "Lsstream.h"
+#include "support/std_sstream.h"
 
 #include "insets/insetbibitem.h"
 #include "insets/insetoptarg.h"
-#include "insets/insetenv.h"
 
-#include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/lyxmanip.h"
-#include "support/FileInfo.h"
 #include "support/LAssert.h"
 #include "support/textutils.h"
 
-#include <algorithm>
-#include <fstream>
-#include <csignal>
-#include <ctime>
 
 using namespace lyx::support;
 
@@ -58,19 +49,8 @@ using std::upper_bound;
 using lyx::pos_type;
 
 
-// this is a minibuffer
-
-namespace {
-
-char minibuffer_char;
-LyXFont minibuffer_font;
-Inset * minibuffer_inset;
-
-} // namespace anon
-
-
 Paragraph::Paragraph()
-       : pimpl_(new Paragraph::Pimpl(this))
+       : y(0), pimpl_(new Paragraph::Pimpl(this))
 {
        enumdepth = 0;
        itemdepth = 0;
@@ -79,7 +59,7 @@ Paragraph::Paragraph()
 
 
 Paragraph::Paragraph(Paragraph const & lp)
-       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
+       : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
 {
        enumdepth = 0;
        itemdepth = 0;
@@ -93,9 +73,7 @@ Paragraph::Paragraph(Paragraph const & lp)
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it) {
                // currently we hold Inset*, not InsetBase*
-               it->inset = static_cast<Inset*>(it->inset->clone());
-               // tell the new inset who is the boss now
-               it->inset->parOwner(this);
+               it->inset = static_cast<InsetOld*>(it->inset->clone().release());
        }
 }
 
@@ -105,7 +83,9 @@ void Paragraph::operator=(Paragraph const & lp)
        // needed as we will destroy the pimpl_ before copying it
        if (&lp != this)
                return;
-       lyxerr << "Paragraph::operator=()\n";
+
+       lyxerr << "Paragraph::operator=()" << endl;
+
        delete pimpl_;
        pimpl_ = new Pimpl(*lp.pimpl_, this);
 
@@ -120,9 +100,7 @@ void Paragraph::operator=(Paragraph const & lp)
        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);
+               it->inset = static_cast<InsetOld*>(it->inset->clone().release());
        }
 }
 
@@ -136,7 +114,7 @@ Paragraph::~Paragraph()
 }
 
 
-void Paragraph::write(Buffer const * buf, ostream & os,
+void Paragraph::write(Buffer const & buf, ostream & os,
                          BufferParams const & bparams,
                          depth_type & dth) const
 {
@@ -156,7 +134,7 @@ void Paragraph::write(Buffer const * buf, ostream & os,
        }
 
        // First write the layout
-       os << "\n\\layout " << layout()->name() << '\n';
+       os << "\n\\begin_layout " << layout()->name() << '\n';
 
        params().write(os);
 
@@ -188,7 +166,7 @@ void Paragraph::write(Buffer const * buf, ostream & os,
                switch (c) {
                case META_INSET:
                {
-                       Inset const * inset = getInset(i);
+                       InsetOld const * inset = getInset(i);
                        if (inset)
                                if (inset->directWrite()) {
                                        // international char, let it write
@@ -240,6 +218,8 @@ void Paragraph::write(Buffer const * buf, ostream & os,
        }
        Changes::lyxMarkChange(os, column, curtime,
                running_change, Change(Change::UNCHANGED));
+
+       os << "\n\\end_layout\n";
 }
 
 
@@ -249,68 +229,6 @@ void Paragraph::validate(LaTeXFeatures & features) const
 }
 
 
-// First few functions needed for cut and paste and paragraph breaking.
-void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
-{
-       BufferParams bparams = buffer.params;
-
-       minibuffer_char = getChar(pos);
-       minibuffer_font = getFontSettings(bparams, pos);
-       minibuffer_inset = 0;
-       if (minibuffer_char == Paragraph::META_INSET) {
-               if (getInset(pos)) {
-                       minibuffer_inset = static_cast<Inset *>(getInset(pos)->clone());
-               } else {
-                       minibuffer_inset = 0;
-                       minibuffer_char = ' ';
-                       // This reflects what GetInset() does (ARRae)
-               }
-       }
-}
-
-
-void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
-{
-       minibuffer_char = getChar(pos);
-       minibuffer_font = getFontSettings(bparams, pos);
-       minibuffer_inset = 0;
-       if (minibuffer_char == Paragraph::META_INSET) {
-               if (getInset(pos)) {
-                       // the inset is not in a paragraph anymore
-                       minibuffer_inset = insetlist.release(pos);
-                       minibuffer_inset->parOwner(0);
-               } else {
-                       minibuffer_inset = 0;
-                       minibuffer_char = ' ';
-                       // This reflects what GetInset() does (ARRae)
-               }
-
-       }
-
-       // Erase(pos); now the caller is responsible for that.
-}
-
-
-bool Paragraph::insertFromMinibuffer(pos_type pos)
-{
-       if (minibuffer_char == Paragraph::META_INSET) {
-               if (!insetAllowed(minibuffer_inset->lyxCode())) {
-                       return false;
-               }
-               insertInset(pos, minibuffer_inset, minibuffer_font);
-       } else {
-               LyXFont f = minibuffer_font;
-               if (!checkInsertChar(f)) {
-                       return false;
-               }
-               insertChar(pos, minibuffer_char, f);
-       }
-       return true;
-}
-
-// end of minibuffer
-
-
 void Paragraph::eraseIntern(lyx::pos_type pos)
 {
        pimpl_->eraseIntern(pos);
@@ -339,8 +257,7 @@ bool Paragraph::checkInsertChar(LyXFont & font)
 
 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
 {
-       LyXFont const f(LyXFont::ALL_INHERIT);
-       insertChar(pos, c, f);
+       insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
 }
 
 
@@ -351,20 +268,20 @@ void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
 }
 
 
-void Paragraph::insertInset(pos_type pos, Inset * inset)
+void Paragraph::insertInset(pos_type pos, InsetOld * inset)
 {
-       LyXFont const f(LyXFont::ALL_INHERIT);
-       insertInset(pos, inset, f);
+       insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
 }
 
 
-void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
+void Paragraph::insertInset(pos_type pos, InsetOld * inset,
+       LyXFont const & font, Change change)
 {
        pimpl_->insertInset(pos, inset, font, change);
 }
 
 
-bool Paragraph::insetAllowed(Inset::Code code)
+bool Paragraph::insetAllowed(InsetOld::Code code)
 {
        //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
        if (pimpl_->inset_owner)
@@ -373,14 +290,14 @@ bool Paragraph::insetAllowed(Inset::Code code)
 }
 
 
-Inset * Paragraph::getInset(pos_type pos)
+InsetOld * Paragraph::getInset(pos_type pos)
 {
        Assert(pos < size());
        return insetlist.get(pos);
 }
 
 
-Inset const * Paragraph::getInset(pos_type pos) const
+InsetOld const * Paragraph::getInset(pos_type pos) const
 {
        Assert(pos < size());
        return insetlist.get(pos);
@@ -395,20 +312,34 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
 
        Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
        Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
-       for (; cit != end; ++cit) {
+       for (; cit != end; ++cit)
                if (cit->pos() >= pos)
                        break;
-       }
 
-       LyXFont retfont;
        if (cit != end)
-               retfont = cit->font();
-       else if (pos == size() && !empty())
-               retfont = getFontSettings(bparams, pos - 1);
-       else
-               retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+               return cit->font();
+
+       if (pos == size() && !empty())
+               return getFontSettings(bparams, pos - 1);
+
+       return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+}
+
+
+lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
+{
+       Assert(pos <= size());
+
+       Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
+       Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+       for (; cit != end; ++cit)
+               if (cit->pos() >= pos)
+                       return cit->pos();
 
-       return retfont;
+       // This should not happen, but if so, we take no chances.
+       //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
+       //      << endl;
+       return pos;
 }
 
 
@@ -445,34 +376,31 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
        LyXFont tmpfont = getFontSettings(bparams, pos);
        tmpfont.realize(layoutfont);
        tmpfont.realize(outerfont);
+       tmpfont.realize(bparams.getLyXTextClass().defaultfont());
 
-       return realizeFont(tmpfont, bparams);
+       return tmpfont;
 }
 
 
 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
                                      LyXFont const & outerfont) const
 {
-       LyXLayout_ptr const & lout = layout();
-
-       LyXFont tmpfont = lout->labelfont;
+       LyXFont tmpfont = layout()->labelfont;
        tmpfont.setLanguage(getParLanguage(bparams));
        tmpfont.realize(outerfont);
-
-       return realizeFont(tmpfont, bparams);
+       tmpfont.realize(bparams.getLyXTextClass().defaultfont());
+       return tmpfont;
 }
 
 
 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
                                       LyXFont const & outerfont) const
 {
-       LyXLayout_ptr const & lout = layout();
-
-       LyXFont tmpfont = lout->font;
+       LyXFont tmpfont = layout()->font;
        tmpfont.setLanguage(getParLanguage(bparams));
        tmpfont.realize(outerfont);
-
-       return realizeFont(tmpfont, bparams);
+       tmpfont.realize(bparams.getLyXTextClass().defaultfont());
+       return tmpfont;
 }
 
 
@@ -735,7 +663,7 @@ int Paragraph::beginningOfBody() const
 
 
 // returns -1 if inset not found
-int Paragraph::getPositionOfInset(Inset const * inset) const
+int Paragraph::getPositionOfInset(InsetOld const * inset) const
 {
        // Find the entry.
        InsetList::const_iterator it = insetlist.begin();
@@ -750,7 +678,7 @@ int Paragraph::getPositionOfInset(Inset const * inset) const
 InsetBibitem * Paragraph::bibitem() const
 {
        InsetList::const_iterator it = insetlist.begin();
-       if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE)
+       if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
                return static_cast<InsetBibitem *>(it->inset);
        return 0;
 }
@@ -874,7 +802,7 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
 
 
 // This one spits out the text of the paragraph
-bool Paragraph::simpleTeXOnePar(Buffer const * buf,
+bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                                BufferParams const & bparams,
                                LyXFont const & outerfont,
                                ostream & os, TexRow & texrow,
@@ -1080,7 +1008,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 bool Paragraph::isHfill(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
-              && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
+              && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
 }
 
 
@@ -1093,7 +1021,7 @@ bool Paragraph::isInset(pos_type pos) const
 bool Paragraph::isNewline(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
-              && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
+              && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
 }
 
 
@@ -1141,15 +1069,10 @@ bool Paragraph::isWord(pos_type pos) const
 Language const *
 Paragraph::getParLanguage(BufferParams const & bparams) const
 {
-       if (!empty()) {
+       if (!empty())
                return getFirstFontSettings().language();
 #warning FIXME we should check the prev par as well (Lgb)
-#if 0
-       } else if (previous_) {
-               return previous_->getParLanguage(bparams);
-#endif
-       }else
-               return bparams.language;
+       return bparams.language;
 }
 
 
@@ -1158,7 +1081,7 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
        return lyxrc.rtl_support
                && getParLanguage(bparams)->RightToLeft()
                && !(inInset() && inInset()->owner() &&
-                    inInset()->owner()->lyxCode() == Inset::ERT_CODE);
+                    inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
 }
 
 
@@ -1184,7 +1107,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
        for (; cit != end; ++cit)
                if (cit->font().language() != ignore_language &&
                    cit->font().language() != latex_language &&
-                       cit->font().language() != doc_language)
+                   cit->font().language() != doc_language)
                        return true;
        return false;
 }
@@ -1192,7 +1115,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
 
 // Convert the paragraph to a string.
 // Used for building the table of contents
-string const Paragraph::asString(Buffer const * buffer, bool label) const
+string const Paragraph::asString(Buffer const & buffer, bool label) const
 {
 #if 0
        string s;
@@ -1204,7 +1127,7 @@ string const Paragraph::asString(Buffer const * buffer, bool label) const
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET &&
-                        getInset(i)->lyxCode() == Inset::MATH_CODE) {
+                        getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
                        ostringstream ost;
                        getInset(i)->ascii(buffer, ost);
                        s += subst(STRCONV(ost.str()),'\n',' ');
@@ -1220,7 +1143,7 @@ string const Paragraph::asString(Buffer const * buffer, bool label) const
 }
 
 
-string const Paragraph::asString(Buffer const * buffer,
+string const Paragraph::asString(Buffer const & buffer,
                                 pos_type beg, pos_type end, bool label) const
 {
        ostringstream os;
@@ -1229,7 +1152,7 @@ string const Paragraph::asString(Buffer const * buffer,
                os << params().labelString() << ' ';
 
        for (pos_type i = beg; i < end; ++i) {
-               value_type const c = getUChar(buffer->params, i);
+               value_type const c = getUChar(buffer.params, i);
                if (IsPrintable(c))
                        os << c;
                else if (c == META_INSET)
@@ -1253,18 +1176,10 @@ void Paragraph::setInsetOwner(UpdatableInset * inset)
 
 void Paragraph::deleteInsetsLyXText(BufferView * bv)
 {
-       // then the insets
        insetlist.deleteInsetsLyXText(bv);
 }
 
 
-void Paragraph::resizeInsetsLyXText(BufferView * bv)
-{
-       // then the insets
-       insetlist.resizeInsetsLyXText(bv);
-}
-
-
 void Paragraph::setContentsFromPar(Paragraph const & par)
 {
        pimpl_->setContentsFromPar(par);
@@ -1373,8 +1288,8 @@ void Paragraph::id(int i)
 LyXLayout_ptr const & Paragraph::layout() const
 {
 /*
-       Inset * inset = inInset();
-       if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
+       InsetOld * inset = inInset();
+       if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
                return static_cast<InsetEnvironment*>(inset)->layout();
 */
        return layout_;
@@ -1422,9 +1337,9 @@ bool Paragraph::isFreeSpacing() const
                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.
+       // other way we can always add a function to InsetOld too.
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
-               return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
+               return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
        return false;
 }
 
@@ -1434,13 +1349,6 @@ 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 pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
        return false;
 }
-
-
-bool operator==(Paragraph const & lhs, Paragraph const & rhs)
-{
-#warning FIXME this implementatoin must be completely wrong...
-       return &lhs == &rhs;
-}