]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetert.C
handle missing layout gracefully when reading and writing lyx files
[lyx.git] / src / insets / insetert.C
index 94b0f411159b74d41dac51f71e61f7184ca7affc..415879dbdd2204640439ccf434fc723ccfd0612c 100644 (file)
 #include "lyxfont.h"
 #include "language.h"
 #include "buffer.h"
-#include "lyx_gui_misc.h"
 #include "BufferView.h"
 #include "LyXView.h"
 #include "lyxtext.h"
 #include "debug.h"
 #include "lyxtextclasslist.h"
+#include "lyxrow.h"
 
 #include "insets/insettext.h"
 
@@ -51,8 +51,8 @@ void InsetERT::init()
 }
 
 
-InsetERT::InsetERT(bool collapsed)
-       : InsetCollapsable(collapsed)
+InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
+       : InsetCollapsable(bp, collapsed)
 {
        if (collapsed)
                status_ = Collapsed;
@@ -75,8 +75,9 @@ Inset * InsetERT::clone(Buffer const &, bool same_id) const
 }
 
 
-InsetERT::InsetERT(Language const * l, string const & contents, bool collapsed)
-       : InsetCollapsable(collapsed)
+InsetERT::InsetERT(BufferParams const & bp,
+                  Language const * l, string const & contents, bool collapsed)
+       : InsetCollapsable(bp, collapsed)
 {
        if (collapsed)
                status_ = Collapsed;
@@ -200,8 +201,7 @@ void InsetERT::write(Buffer const * buf, ostream & os) const
           << "status "<< st << "\n";
 
        //inset.writeParagraphData(buf, os);
-       string const layout =
-               textclasslist.NameOfLayout(buf->params.textclass, 0);
+       string const layout(textclasslist[buf->params.textclass].defaultLayoutName());
        Paragraph * par = inset.paragraph();
        while (par) {
                os << "\n\\layout " << layout << "\n";
@@ -454,7 +454,7 @@ InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
 
        switch (action) {
        case LFUN_LAYOUT:
-               bv->owner()->setLayout(inset.paragraph()->getLayout());
+               bv->owner()->setLayout(inset.paragraph()->layout());
                break;
        default:
                result = InsetCollapsable::localDispatch(bv, action, arg);
@@ -623,24 +623,24 @@ void InsetERT::set_latex_font(BufferView * /* bv */)
 }
 
 
+// attention this function can be called with bv == 0
 void InsetERT::status(BufferView * bv, ERTStatus const st) const
 {
        if (st != status_) {
                status_ = st;
+               need_update = FULL;
                switch (st) {
                case Inlined:
-                       inset.setAutoBreakRows(false);
+#warning Another gross hack. (Lgb)
+                       if (bv)
+                               inset.setUpdateStatus(bv, InsetText::INIT);
                        break;
                case Open:
-                       inset.setAutoBreakRows(true);
                        collapsed_ = false;
-                       need_update = FULL;
                        setButtonLabel();
                        break;
                case Collapsed:
-                       inset.setAutoBreakRows(true);
                        collapsed_ = true;
-                       need_update = FULL;
                        setButtonLabel();
                        if (bv)
                                bv->unlockInset(const_cast<InsetERT *>(this));
@@ -675,12 +675,14 @@ void InsetERT::close(BufferView * bv) const
 }
 
 
-string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,float &) const
+string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,
+                                                 float &) const
 {
        bv->unlockInset(const_cast<InsetERT *>(this));
        return string();
 }
 
+
 void InsetERT::getDrawFont(LyXFont & font) const
 {
 #ifndef INHERIT_LANG
@@ -692,3 +694,19 @@ void InsetERT::getDrawFont(LyXFont & font) const
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
 }
+
+
+int InsetERT::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
+{
+       int w = InsetCollapsable::getMaxWidth(bv, in);
+       if (status_ != Inlined || w < 0)
+               return w;
+       LyXText * text = inset.getLyXText(bv);
+       int rw = text->firstRow()->width();
+       if (!rw)
+               rw = w;
+       rw += 40;
+       if (!text->firstRow()->next() && rw < w)
+               return -1;
+       return w;
+}