]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Fixed/Disabled code inserting InsetError in the wrong way (fix #129)
[lyx.git] / src / paragraph.C
index fd27bfb8460ec1e22c41b28a554b2c3b36f053fd..b2d361acd794dcb420fe75a2b734dbf2a0f3360c 100644 (file)
@@ -24,7 +24,6 @@
 #include "bufferparams.h"
 #include "debug.h"
 #include "LaTeXFeatures.h"
-#include "lyx_gui_misc.h"
 #include "texrow.h"
 #include "BufferView.h"
 #include "encoding.h"
@@ -56,7 +55,6 @@ using std::upper_bound;
 using std::reverse;
 
 using lyx::pos_type;
-using lyx::layout_type;
 
 int tex_code_break_column = 72;  // needs non-zero initialization. set later.
 // this is a bad idea, but how can Paragraph find its buffer to get
@@ -79,7 +77,7 @@ extern BufferView * current_view;
 
 
 Paragraph::Paragraph()
-       : layout(0), pimpl_(new Paragraph::Pimpl(this))
+       : pimpl_(new Paragraph::Pimpl(this))
 {
        for (int i = 0; i < 10; ++i)
                setCounter(i, 0);
@@ -88,13 +86,13 @@ Paragraph::Paragraph()
        enumdepth = 0;
        itemdepth = 0;
        bibkey = 0; // ale970302
-       clear();
+       params().clear();
 }
 
 
 // This constructor inserts the new paragraph in a list.
 Paragraph::Paragraph(Paragraph * par)
-       : layout(0), pimpl_(new Paragraph::Pimpl(this))
+       : pimpl_(new Paragraph::Pimpl(this))
 {
        for (int i = 0; i < 10; ++i)
                setCounter(i, 0);
@@ -109,14 +107,13 @@ Paragraph::Paragraph(Paragraph * par)
        previous_->next_ = this;
        // end
 
-       bibkey = 0; // ale970302        
-
-       clear();
+       bibkey = 0; // ale970302
+       params().clear();
 }
 
 
 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
-       : layout(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
+       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
 {
        for (int i = 0; i < 10; ++i)
                setCounter(i, 0);
@@ -127,7 +124,7 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
 
        // this is because of the dummy layout of the paragraphs that
        // follow footnotes
-       layout = lp.layout;
+       layout_ = lp.layout();
 
        // ale970302
        if (lp.bibkey) {
@@ -192,9 +189,12 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
        }
        
        // First write the layout
-       os << "\n\\layout "
-          << textclasslist.NameOfLayout(bparams.textclass, layout)
-          << "\n";
+       string lay = layout();
+       if (lay.empty()) {
+               lay = textclasslist[bparams.textclass].defaultLayoutName();
+       }
+       
+       os << "\n\\layout " << layout() << "\n";
        
        // Maybe some vertical spaces.
        if (params().spaceTop().kind() != VSpace::NONE)
@@ -342,23 +342,24 @@ void Paragraph::validate(LaTeXFeatures & features) const
                features.require("setspace");
        
        // then the layouts
-       features.useLayout(getLayout());
+       features.useLayout(layout());
 
        // then the fonts
        Language const * doc_language = bparams.language;
-       
-       for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
-            cit != pimpl_->fontlist.end(); ++cit) {
-               if (cit->font().noun() == LyXFont::ON) {
+
+       Pimpl::FontList::const_iterator fcit = pimpl_->fontlist.begin();
+       Pimpl::FontList::const_iterator fend = pimpl_->fontlist.end();
+       for (; fcit != fend; ++fcit) {
+               if (fcit->font().noun() == LyXFont::ON) {
                        lyxerr[Debug::LATEX] << "font.noun: "
-                                            << cit->font().noun()
+                                            << fcit->font().noun()
                                             << endl;
                        features.require("noun");
                        lyxerr[Debug::LATEX] << "Noun enabled. Font: "
-                                            << cit->font().stateText(0)
+                                            << fcit->font().stateText(0)
                                             << endl;
                }
-               switch (cit->font().color()) {
+               switch (fcit->font().color()) {
                case LColor::none:
                case LColor::inherit:
                case LColor::ignore:
@@ -370,11 +371,11 @@ void Paragraph::validate(LaTeXFeatures & features) const
                default:
                        features.require("color");
                        lyxerr[Debug::LATEX] << "Color enabled. Font: "
-                                            << cit->font().stateText(0)
+                                            << fcit->font().stateText(0)
                                             << endl;
                }
 
-               Language const * language = cit->font().language();
+               Language const * language = fcit->font().language();
                if (language->babel() != doc_language->babel() &&
                    language != ignore_language &&
 #ifdef INHERIT_LANGUAGE
@@ -389,15 +390,15 @@ void Paragraph::validate(LaTeXFeatures & features) const
        }
 
        // then the insets
-       LyXLayout const & layout =
-             textclasslist.Style(bparams.textclass, getLayout());
-
-       for (InsetList::const_iterator cit = insetlist.begin();
-            cit != insetlist.end(); ++cit) {
-               if (cit->inset) {
-                       cit->inset->validate(features);
-                       if (layout.needprotect &&
-                           cit->inset->lyxCode() == Inset::FOOT_CODE)
+       LyXLayout const & lout = textclasslist[bparams.textclass][layout()];
+
+       InsetList::const_iterator icit = insetlist.begin();
+       InsetList::const_iterator iend = insetlist.end();
+       for (; icit != iend; ++icit) {
+               if (icit->inset) {
+                       icit->inset->validate(features);
+                       if (lout.needprotect &&
+                           icit->inset->lyxCode() == Inset::FOOT_CODE)
                                features.require("NeedLyXFootnoteCode");
                }
        }
@@ -436,12 +437,14 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
                        // the inset, not just a clone. Otherwise
                        // the inset would be deleted when calling Erase(pos)
                        // find the entry
-                       InsetTable search_elem(pos, 0);
-                       InsetList::iterator it =
-                               lower_bound(insetlist.begin(),
-                                           insetlist.end(),
-                                           search_elem, Pimpl::matchIT());
-                       if (it != insetlist.end() && it->pos == pos)
+                       InsetList::iterator it = insetlist.begin();
+                       InsetList::iterator end = insetlist.end();
+                       for (; it != end; ++it) {
+                               if (it->pos == pos)
+                                       break;
+                       }
+
+                       if (it != end && it->pos == pos)
                                it->inset = 0;
                        // the inset is not in a paragraph anymore
                        minibuffer_inset->parOwner(0);
@@ -477,16 +480,6 @@ bool Paragraph::insertFromMinibuffer(pos_type pos)
 // end of minibuffer
 
 
-
-void Paragraph::clear()
-{
-       params().clear();
-       
-       layout = 0;
-       bibkey = 0;
-}
-
-
 void Paragraph::erase(pos_type pos)
 {
        pimpl_->erase(pos);
@@ -543,15 +536,18 @@ Inset * Paragraph::getInset(pos_type pos)
        lyx::Assert(pos < size());
 
        // Find the inset.
-       InsetTable search_inset(pos, 0);
-       InsetList::iterator it = lower_bound(insetlist.begin(),
-                                            insetlist.end(),
-                                            search_inset, Pimpl::matchIT());
-       if (it != insetlist.end() && it->pos == pos)
+       InsetList::iterator it = insetlist.begin();
+       InsetList::iterator end = insetlist.end();
+       for (; it != end; ++it) {
+               if (it->pos == pos)
+                       break;
+       }
+
+       if (it != end && it->pos == pos)
                return it->inset;
 
        lyxerr << "ERROR (Paragraph::getInset): "
-               "Inset does not exist: " << pos << endl;
+              << "Inset does not exist: " << pos << endl;
        //::raise(SIGSTOP);
        
        // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
@@ -568,15 +564,18 @@ Inset const * Paragraph::getInset(pos_type pos) const
        lyx::Assert(pos < size());
 
        // Find the inset.
-       InsetTable search_inset(pos, 0);
-       InsetList::const_iterator cit = lower_bound(insetlist.begin(),
-                                                   insetlist.end(),
-                                                   search_inset, Pimpl::matchIT());
-       if (cit != insetlist.end() && cit->pos == pos)
+       InsetList::const_iterator cit = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
+       for (; cit != end; ++cit) {
+               if (cit->pos == pos)
+                       break;
+       }
+
+       if (cit != end && cit->pos == pos)
                return cit->inset;
 
-       lyxerr << "ERROR (Paragraph::GetInset): "
-               "Inset does not exist: " << pos << endl;
+       lyxerr << "ERROR (Paragraph::getInset): "
+              << "Inset does not exist: " << pos << endl;
        //::raise(SIGSTOP);
        //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
        // Did this commenting out introduce a bug? So far I have not
@@ -592,13 +591,16 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
                                          pos_type pos) const
 {
        lyx::Assert(pos <= size());
-       
-       Pimpl::FontTable search_font(pos, LyXFont());
-       Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(),
-                                                  pimpl_->fontlist.end(),
-                                                  search_font, Pimpl::matchFT());
+
+       Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
+       Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+       for (; cit != end; ++cit) {
+               if (cit->pos() >= pos)
+                       break;
+       }
+
        LyXFont retfont;
-       if (cit != pimpl_->fontlist.end()) {
+       if (cit != end) {
                retfont = cit->font();
        } else if (pos == size() && size()) {
                retfont = getFontSettings(bparams, pos - 1);
@@ -635,18 +637,17 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
 {
        lyx::Assert(pos >= 0);
        
-       LyXLayout const & layout =
-               textclasslist.Style(bparams.textclass, 
-                                   getLayout());
+       LyXLayout const & lout =
+               textclasslist[bparams.textclass][layout()];
        pos_type main_body = 0;
-       if (layout.labeltype == LABEL_MANUAL)
+       if (lout.labeltype == LABEL_MANUAL)
                main_body = beginningOfMainBody();
 
        LyXFont layoutfont;
        if (pos < main_body)
-               layoutfont = layout.labelfont;
+               layoutfont = lout.labelfont;
        else
-               layoutfont = layout.font;
+               layoutfont = lout.font;
        
        LyXFont tmpfont = getFontSettings(bparams, pos);
 #ifndef INHERIT_LANGUAGE
@@ -661,10 +662,10 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
 
 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
 {
-       LyXLayout const & layout =
-               textclasslist.Style(bparams.textclass, getLayout());
+       LyXLayout const & lout =
+               textclasslist[bparams.textclass][layout()];
        
-       LyXFont tmpfont = layout.labelfont;
+       LyXFont tmpfont = lout.labelfont;
        tmpfont.setLanguage(getParLanguage(bparams));
 
        return pimpl_->realizeFont(tmpfont, bparams);
@@ -673,11 +674,10 @@ LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
 
 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
 {
-       LyXLayout const & layout =
-               textclasslist.Style(bparams.textclass, 
-                                   getLayout());
+       LyXLayout const & lout =
+               textclasslist[bparams.textclass][layout()];
 
-       LyXFont tmpfont = layout.font;
+       LyXFont tmpfont = lout.font;
        tmpfont.setLanguage(getParLanguage(bparams));
 
        return pimpl_->realizeFont(tmpfont, bparams);
@@ -692,21 +692,23 @@ Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
        if (pimpl_->fontlist.empty())
                return def_size;
 
-       LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
-       Pimpl::FontTable end_search(endpos, LyXFont());
-       Pimpl::FontList::const_iterator end_it =
-               lower_bound(pimpl_->fontlist.begin(),
-                           pimpl_->fontlist.end(),
-                           end_search, Pimpl::matchFT());
-       if (end_it != pimpl_->fontlist.end())
+       Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
+       Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+       for (; end_it != end; ++end_it) {
+               if (end_it->pos() >= endpos)
+                       break;
+       }
+
+       if (end_it != end)
                ++end_it;
 
-       Pimpl::FontTable start_search(startpos, LyXFont());
-       Pimpl::FontList::const_iterator cit =
-               lower_bound(pimpl_->fontlist.begin(),
-                           pimpl_->fontlist.end(),
-                           start_search, Pimpl::matchFT());
-       
+       Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
+       for (; cit != end; ++cit) {
+               if (cit->pos() >= startpos)
+                       break;
+       }
+
+       LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
        for (; cit != end_it; ++cit) {
                LyXFont::FONT_SIZE size = cit->font().size();
                if (size == LyXFont::INHERIT_SIZE)
@@ -770,18 +772,21 @@ void Paragraph::setFont(pos_type pos, LyXFont const & font)
        // in a new kernel. (Asger)
        // Next search font table
 
-       Pimpl::FontTable search_font(pos, LyXFont());
-       Pimpl::FontList::iterator it = lower_bound(pimpl_->fontlist.begin(),
-                                           pimpl_->fontlist.end(),
-                                           search_font, Pimpl::matchFT());
-       unsigned int i = it - pimpl_->fontlist.begin();
-       bool notfound = it == pimpl_->fontlist.end();
+       Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
+       Pimpl::FontList::iterator it = beg;
+       Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
+       for (; it != endit; ++it) {
+               if (it->pos() >= pos)
+                       break;
+       }
+       unsigned int i = std::distance(beg, it);
+       bool notfound = (it == endit);
 
        if (!notfound && pimpl_->fontlist[i].font() == font)
                return;
 
        bool begin = pos == 0 || notfound ||
-               (i > 0 && pimpl_->fontlist[i-1].pos() == pos - 1);
+               (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
        // Is position pos is a beginning of a font block?
        bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
        // Is position pos is the end of a font block?
@@ -865,6 +870,8 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
 {
        // create a new paragraph
        Paragraph * tmp = new Paragraph(this);
+       tmp->layout(textclasslist[bparams.textclass].defaultLayoutName());
+       
        // remember to set the inset_owner
        tmp->setInsetOwner(inInset());
        
@@ -873,12 +880,12 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
        
        // layout stays the same with latex-environments
        if (flag) {
-               tmp->setOnlyLayout(layout);
+               tmp->layout(layout());
                tmp->setLabelWidthString(params().labelWidthString());
        }
        
        if (size() > pos || !size() || flag == 2) {
-               tmp->setOnlyLayout(layout);
+               tmp->layout(layout());
                tmp->params().align(params().align());
                tmp->setLabelWidthString(params().labelWidthString());
                
@@ -913,10 +920,14 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
                tmp->params().pagebreakTop(params().pagebreakTop());
                tmp->params().spaceTop(params().spaceTop());
                tmp->bibkey = bibkey;
-               clear();
+
+               bibkey = 0;
+               params().clear();
+               layout(textclasslist[bparams.textclass].defaultLayoutName());
+               
                // layout stays the same with latex-environments
                if (flag) {
-                       setOnlyLayout(tmp->layout);
+                       layout(tmp->layout());
                        setLabelWidthString(tmp->params().labelWidthString());
                        params().depth(tmp->params().depth());
                }
@@ -926,7 +937,7 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
 
 void Paragraph::makeSameLayout(Paragraph const * par)
 {
-       layout = par->layout;
+       layout(par->layout());
        // move to pimpl?
        params() = par->params();
 }
@@ -934,9 +945,8 @@ void Paragraph::makeSameLayout(Paragraph const * par)
 
 int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass) 
 {
-       if (textclasslist.Style(tclass, getLayout()).free_spacing ||
-               isFreeSpacing())
-       {
+       if (textclasslist[tclass][layout()].free_spacing ||
+           isFreeSpacing()) {
                return 0;
        }
        
@@ -953,7 +963,7 @@ int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass)
 bool Paragraph::hasSameLayout(Paragraph const * par) const
 {
        return 
-               par->layout == layout &&
+               par->layout() == layout() &&
                params().sameLayout(par->params());
 }
 
@@ -1023,10 +1033,9 @@ int Paragraph::getEndLabel(BufferParams const & bparams) const
        Paragraph const * par = this;
        depth_type par_depth = getDepth();
        while (par) {
-               layout_type layout = par->getLayout();
+               string const & layout = par->layout();
                int const endlabeltype =
-                       textclasslist.Style(bparams.textclass,
-                                           layout).endlabeltype;
+                       textclasslist[bparams.textclass][layout].endlabeltype;
                if (endlabeltype != END_LABEL_NO_LABEL) {
                        if (!next_)
                                return endlabeltype;
@@ -1034,7 +1043,7 @@ int Paragraph::getEndLabel(BufferParams const & bparams) const
                        depth_type const next_depth = next_->getDepth();
                        if (par_depth > next_depth ||
                            (par_depth == next_depth
-                            && layout != next_->getLayout()))
+                            && layout != next_->layout()))
                                return endlabeltype;
                        break;
                }
@@ -1054,6 +1063,17 @@ Paragraph::depth_type Paragraph::getDepth() const
 }
 
 
+Paragraph::depth_type Paragraph::getMaxDepthAfter(Buffer const * buffer) const
+{
+       bool const isenv = textclasslist[buffer->params.textclass][layout()].isEnvironment();
+
+       if (isenv)
+               return params().depth() + 1;
+       else
+               return params().depth();
+
+}
+
 char Paragraph::getAlign() const
 {
        return params().align();
@@ -1088,15 +1108,9 @@ void Paragraph::setLabelWidthString(string const & s)
 }
 
 
-void Paragraph::setOnlyLayout(layout_type new_layout)
-{
-       layout = new_layout;
-}
-
-
-void Paragraph::setLayout(layout_type new_layout)
+void Paragraph::applyLayout(string const & new_layout)
 {
-       layout = new_layout;
+       layout(new_layout);
        params().labelWidthString(string());
        params().align(LYX_ALIGN_LAYOUT);
        params().spaceTop(VSpace(VSpace::NONE));
@@ -1195,10 +1209,13 @@ Paragraph const * Paragraph::outerHook() const
 Paragraph::inset_iterator
 Paragraph::InsetIterator(pos_type pos)
 {
-       InsetTable search_inset(pos, 0);
-       InsetList::iterator it = lower_bound(insetlist.begin(),
-                                            insetlist.end(),
-                                            search_inset, Pimpl::matchIT());
+       InsetList::iterator it = insetlist.begin();
+       InsetList::iterator end = insetlist.end();
+       for (; it != end; ++it) {
+               if (it->pos == pos)
+                       break;
+       }
+
        return inset_iterator(it);
 }
 
@@ -1207,8 +1224,9 @@ Paragraph::InsetIterator(pos_type pos)
 int Paragraph::getPositionOfInset(Inset const * inset) const
 {
        // Find the entry.
-       for (InsetList::const_iterator cit = insetlist.begin();
-            cit != insetlist.end(); ++cit) {
+       InsetList::const_iterator cit = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
+       for (; cit != end; ++cit) {
                if (cit->inset == inset) {
                        return cit->pos;
                }
@@ -1235,7 +1253,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        // any special options in the paragraph and also we don't allow
        // any environment other then "Standard" to be valid!
        if ((in == 0) || !in->forceDefaultParagraphs(in)) {
-               style = textclasslist.Style(bparams.textclass, layout);
+               style = textclasslist[bparams.textclass][layout()];
 
                if (params().startOfAppendix()) {
                        os << "\\appendix\n";
@@ -1273,7 +1291,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                        texrow.newline();
                }
        } else {
-               style = textclasslist.Style(bparams.textclass, 0);
+               style = textclasslist[bparams.textclass].defaultLayout();
        }
 
        Language const * language = getParLanguage(bparams);
@@ -1284,7 +1302,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        if (language->babel() != previous_language->babel()
            // check if we already put language command in TeXEnvironment()
            && !(style.isEnvironment()
-                && (!previous() || previous()->layout != layout ||
+                && (!previous() || previous()->layout() != layout() ||
                         previous()->params().depth() != params().depth())))
        {
                if (!lyxrc.language_command_end.empty() &&
@@ -1371,7 +1389,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                // if its the last paragraph of the current environment
                // skip it otherwise fall through
                if (next_
-                   && (next_->layout != layout
+                   && (next_->layout() != layout()
                        || next_->params().depth() != params().depth()))
                        break;
                // fall through possible
@@ -1543,9 +1561,9 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
                (inInset() && inInset()->forceDefaultParagraphs(inInset()));
 
        if (asdefault) {
-               style = textclasslist.Style(bparams.textclass, 0);
+               style = textclasslist[bparams.textclass].defaultLayout();
        } else {
-               style = textclasslist.Style(bparams.textclass, layout);
+               style = textclasslist[bparams.textclass][layout()];
        }
        
        LyXFont basefont;
@@ -1615,13 +1633,13 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
                // Fully instantiated font
                LyXFont font = getFont(bparams, i);
 
-               LyXFont const last_font = running_font;
+               LyXFont const last_font = running_font;
 
                // Spaces at end of font change are simulated to be
                // outside font change, i.e. we write "\textXX{text} "
                // rather than "\textXX{text }". (Asger)
                if (open_font && c == ' ' && i <= size() - 2) {
-                       LyXFont const next_font = getFont(bparams, i + 1);
+                       LyXFont const next_font = getFont(bparams, i + 1);
                        if (next_font != running_font
                            && next_font != font) {
                                font = next_font;
@@ -1794,8 +1812,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
        lyxerr[Debug::LATEX] << "TeXEnvironment...     " << this << endl;
 
        LyXLayout const & style =
-               textclasslist.Style(bparams.textclass,
-                                   layout);
+               textclasslist[bparams.textclass][layout()];
 
        Language const * language = getParLanguage(bparams);
        Language const * doc_language = bparams.language;
@@ -1842,8 +1859,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
                par = par->TeXOnePar(buf, bparams, os, texrow, false);
 
                if (par && par->params().depth() > params().depth()) {
-                       if (textclasslist.Style(bparams.textclass,
-                                               par->layout).isParagraph()
+                       if (textclasslist[bparams.textclass][par->layout()].isParagraph()
                            // Thinko!
                            // How to handle this? (Lgb)
                            //&& !suffixIs(os, "\n\n")
@@ -1864,7 +1880,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
                        par = par->pimpl_->TeXDeeper(buf, bparams, os, texrow);
                }
        } while (par
-                && par->layout == layout
+                && par->layout() == layout()
                 && par->params().depth() == params().depth());
  
        if (style.isEnvironment()) {
@@ -1905,7 +1921,8 @@ bool Paragraph::isLineSeparator(pos_type pos) const
 {
        value_type const c = getChar(pos);
        return IsLineSeparatorChar(c)
-               || (IsInsetChar(c) && getInset(pos)->isLineSeparator());
+               || (IsInsetChar(c) && getInset(pos) &&
+               getInset(pos)->isLineSeparator());
 }
 
 
@@ -1943,7 +1960,9 @@ Paragraph::getParLanguage(BufferParams const & bparams) const
                return getFirstFontSettings().language();
 #else
                Language const * lang = getFirstFontSettings().language();
+#ifdef WITH_WARNINGS
 #warning We should make this somewhat better, any ideas? (Jug)
+#endif
                if (lang == inherit_language || lang == ignore_language)
                        lang = bparams.language;
                return lang;
@@ -1978,8 +1997,10 @@ void Paragraph::changeLanguage(BufferParams const & bparams,
 bool Paragraph::isMultiLingual(BufferParams const & bparams)
 {
        Language const * doc_language = bparams.language;
-       for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
-            cit != pimpl_->fontlist.end(); ++cit)
+       Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
+       Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+       
+       for (; cit != end; ++cit)
                if (cit->font().language() != ignore_language &&
                    cit->font().language() != latex_language &&
 #ifdef INHERIT_LANGUAGE
@@ -2048,8 +2069,9 @@ string const Paragraph::asString(Buffer const * buffer,
 void Paragraph::setInsetOwner(Inset * i)
 {
        pimpl_->inset_owner = i;
-       for (InsetList::const_iterator cit = insetlist.begin();
-            cit != insetlist.end(); ++cit) {
+       InsetList::const_iterator cit = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
+       for (; cit != end; ++cit) {
                if (cit->inset)
                        cit->inset->setOwner(i);
        }
@@ -2059,13 +2081,12 @@ void Paragraph::setInsetOwner(Inset * i)
 void Paragraph::deleteInsetsLyXText(BufferView * bv)
 {
        // then the insets
-       for (InsetList::const_iterator cit = insetlist.begin();
-            cit != insetlist.end(); ++cit) {
-               if (cit->inset) {
-                       if (cit->inset->isTextInset()) {
-                               static_cast<UpdatableInset *>
-                                       (cit->inset)->deleteLyXText(bv, true);
-                       }
+       InsetList::const_iterator cit = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
+       for (; cit != end; ++cit) {
+               if (cit->inset && cit->inset->isTextInset()) {
+                       static_cast<UpdatableInset *>
+                               (cit->inset)->deleteLyXText(bv, true);
                }
        }
 }
@@ -2074,9 +2095,9 @@ void Paragraph::deleteInsetsLyXText(BufferView * bv)
 void Paragraph::resizeInsetsLyXText(BufferView * bv)
 {
        // then the insets
-       for (InsetList::const_iterator cit = insetlist.begin();
-            cit != insetlist.end(); ++cit)
-       {
+       InsetList::const_iterator cit = insetlist.begin();
+       InsetList::const_iterator end = insetlist.end();
+       for (; cit != end; ++cit) {
                if (cit->inset) {
                        if (cit->inset->isTextInset()) {
                                static_cast<UpdatableInset *>
@@ -2117,9 +2138,17 @@ void  Paragraph::id(int id_arg)
 }
 
 
-layout_type Paragraph::getLayout() const
+string const & Paragraph::layout() const
 {
-       return layout;
+       return layout_;
+}
+
+
+void Paragraph::layout(string const & new_layout)
+{
+       lyx::Assert(!new_layout.empty());
+       
+       layout_ = new_layout;
 }
 
 
@@ -2127,7 +2156,7 @@ bool Paragraph::isFirstInSequence() const
 {
        Paragraph const * dhook = depthHook(getDepth());
        return (dhook == this
-               || dhook->getLayout() != getLayout()
+               || dhook->layout() != layout()
                || dhook->getDepth() != getDepth());
 }