]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetert.C
prevent crash when inserting minipage in table cell,
[lyx.git] / src / insets / insetert.C
index b0f96d24973d2b8d7a28cd86202eab7c0833a002..f153d61e4c40e67420477c346e46ff380a789166 100644 (file)
 
 using namespace lyx::support;
 
+using lyx::pos_type;
+
 using std::ostream;
 using std::min;
 using std::endl;
-
-using lyx::pos_type;
+using std::auto_ptr;
 
 
 void InsetERT::init()
@@ -71,9 +72,9 @@ InsetERT::InsetERT(InsetERT const & in)
 }
 
 
-InsetBase * InsetERT::clone() const
+auto_ptr<InsetBase> InsetERT::clone() const
 {
-       return new InsetERT(*this);
+       return auto_ptr<InsetBase>(new InsetERT(*this));
 }
 
 
@@ -204,13 +205,13 @@ void InsetERT::write(Buffer const * buf, ostream & os) const
        ParagraphList::iterator par = inset.paragraphs.begin();
        ParagraphList::iterator end = inset.paragraphs.end();
        for (; par != end; ++par) {
-               os << "\n\\layout " << layout << "\n";
+               os << "\n\\begin_layout " << layout << "\n";
                pos_type siz = par->size();
                for (pos_type i = 0; i < siz; ++i) {
                        Paragraph::value_type c = par->getChar(i);
                        switch (c) {
                        case Paragraph::META_INSET:
-                               if (par->getInset(i)->lyxCode() != Inset::NEWLINE_CODE) {
+                               if (par->getInset(i)->lyxCode() != InsetOld::NEWLINE_CODE) {
                                        lyxerr << "Element is not allowed in insertERT"
                                               << endl;
                                } else {
@@ -226,6 +227,7 @@ void InsetERT::write(Buffer const * buf, ostream & os) const
                                break;
                        }
                }
+               os << "\n\\end_layout\n";
        }
 }
 
@@ -236,7 +238,7 @@ string const InsetERT::editMessage() const
 }
 
 
-bool InsetERT::insertInset(BufferView *, Inset *)
+bool InsetERT::insertInset(BufferView *, InsetOld *)
 {
        return false;
 }
@@ -267,7 +269,7 @@ void InsetERT::updateStatus(BufferView * bv, bool swap) const
 }
 
 
-Inset::EDITABLE InsetERT::editable() const
+InsetOld::EDITABLE InsetERT::editable() const
 {
        if (status_ == Collapsed)
                return IS_EDITABLE;
@@ -293,19 +295,18 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
                return true;
        }
 
-       if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) &&
-           (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
+       if (status_ != Inlined && hitButton(cmd)) {
                updateStatus(bv, true);
        } else {
-               LyXFont font(LyXFont::ALL_SANE);
                FuncRequest cmd1 = cmd;
-               cmd1.y = ascent(bv, font) + cmd.y - inset.ascent(bv, font);
+#warning metrics?
+               cmd1.y = ascent() + cmd.y - inset.ascent();
 
                // inlined is special - the text appears above
-               // button_bottom_y
+               // button_dim.y2
                if (status_ == Inlined)
                        inset.localDispatch(cmd1);
-               else if (!collapsed_ && (cmd.y > button_bottom_y)) {
+               else if (!collapsed_ && (cmd.y > button_dim.y2)) {
                        cmd1.y -= height_collapsed();
                        inset.localDispatch(cmd1);
                }
@@ -415,9 +416,9 @@ int InsetERT::docbook(Buffer const *, ostream & os, bool) const
 }
 
 
-Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
+InsetOld::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
 {
-       Inset::RESULT result = UNDISPATCHED;
+       InsetOld::RESULT result = UNDISPATCHED;
        BufferView * bv = cmd.view();
 
        if (inset.paragraphs.begin()->empty()) {
@@ -453,7 +454,6 @@ Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
                 * taken by the text).
                 */
                inset.getLyXText(cmd.view())->fullRebreak();
-               inset.update(cmd.view(), true);
                bv->updateInset(this);
                result = DISPATCHED;
        }
@@ -550,10 +550,12 @@ bool InsetERT::checkInsertChar(LyXFont & /* font */)
 
 void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       setButtonLabel();
        if (inlined())
                inset.metrics(mi, dim);
        else
                InsetCollapsable::metrics(mi, dim);
+       dim_ = dim;
 }
 
 
@@ -646,33 +648,6 @@ void InsetERT::getDrawFont(LyXFont & font) const
 }
 
 
-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->rows().begin()->width();
-       if (!rw)
-               rw = w;
-       rw += 40;
-       if (text->rows().size() == 1 && rw < w)
-               return -1;
-       return w;
-}
-
-
-void InsetERT::update(BufferView * bv, bool reinit)
-{
-       if (inset.need_update & InsetText::INIT ||
-           inset.need_update & InsetText::FULL) {
-               setButtonLabel();
-       }
-
-       InsetCollapsable::update(bv, reinit);
-}
-
-
 string const InsetERTMailer::name_("ert");
 
 InsetERTMailer::InsetERTMailer(InsetERT & inset)
@@ -680,7 +655,7 @@ InsetERTMailer::InsetERTMailer(InsetERT & inset)
 {}
 
 
-string const InsetERTMailer::inset2string() const
+string const InsetERTMailer::inset2string(Buffer const &) const
 {
        return params2string(inset_.status());
 }