]> git.lyx.org Git - features.git/commitdiff
move 'Inline' state from InsetERT to InsetCollapsable
authorAndré Pönitz <poenitz@gmx.net>
Tue, 2 Dec 2003 07:15:42 +0000 (07:15 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 2 Dec 2003 07:15:42 +0000 (07:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8177 a592a061-630c-0410-9148-cb99ea01b6c8

src/factory.C
src/frontends/controllers/ControlERT.h
src/insets/ChangeLog
src/insets/inset.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetert.C
src/insets/insetert.h
src/text.C

index 08a831e816b57e9afb7650cd8f7e86461cc0f62d..f497598942656b6865a11deedb1d833bdee34b76 100644 (file)
@@ -231,9 +231,9 @@ InsetOld * createInset(FuncRequest const & cmd)
                        return new InsetCitation(icp);
 
                } else if (name == "ert") {
-                       InsetERT::ERTStatus s;
-                       InsetERTMailer::string2params(cmd.argument, s);
-                       return new InsetERT(params, s);
+                       InsetCollapsable::CollapseStatus st;
+                       InsetERTMailer::string2params(cmd.argument, st);
+                       return new InsetERT(params, st);
 
                } else if (name == "external") {
                        Buffer const & buffer = *cmd.view()->buffer();
index 6724c0fa1bcb55118eacde860d3aa5b5c05dcd14..44885238aa27a3175c2db274cb2e99531b1732d8 100644 (file)
@@ -23,9 +23,9 @@ public:
        ///
        ControlERT(Dialog &);
        ///
-       InsetERT::ERTStatus status() const { return status_; }
+       InsetCollapsable::CollapseStatus status() const { return status_; }
        ///
-       void setStatus(InsetERT::ERTStatus status) { status_ = status; }
+       void setStatus(InsetCollapsable::CollapseStatus status) { status_ = status; }
        ///
        virtual bool initialiseParams(std::string const & data);
        /// clean-up on hide.
@@ -36,7 +36,7 @@ public:
        virtual bool isBufferDependent() const { return true; }
 private:
        ///
-       InsetERT::ERTStatus status_;
+       InsetCollapsable::CollapseStatus status_;
 };
 
 #endif
index 5f58e4b9552bf31c000164f838794e8fe564a8fd..a420f98a926248b4f454149b29c0b3ccfec71df7 100644 (file)
@@ -1,3 +1,8 @@
+2003-12-01  André Pönitz  <poenitz@gmx.net>
+
+       * insetcollapsable.[Ch]:
+       * insetert.[Ch]: move 'inline' state to InsetCollapsable
+
 2003-12-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * insetvspace.C (read): handle 'end_inset' token.
index dd2e63cd1b26a1c862928ad958d7c65e0c554283..1ec2999999b059cba520189292ac65fc8eb32a16 100644 (file)
@@ -237,7 +237,7 @@ public:
        /// open the inset
        virtual void open() {}
        /// close the inset
-       virtual void close() const {}
+       virtual void close() {}
        // should this inset be handled like a normal charater
        virtual bool isChar() const { return false; }
        // is this equivalent to a letter?
index b0b43b0d3325aa79a235dabe474bb14a1db2a47b..285d8f4ae3e2addebee532090ab4831886502c76 100644 (file)
@@ -40,7 +40,8 @@ using std::ostream;
 
 
 InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
-       : UpdatableInset(), inset(bp), collapsed_(collapsed), label("Label")
+       : UpdatableInset(), inset(bp), status_(collapsed ? Collapsed : Open),
+         label("Label")
 #if 0
        ,autocollapse(false)
 #endif
@@ -54,7 +55,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
 
 
 InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
-       : UpdatableInset(in), inset(in.inset), collapsed_(in.collapsed_),
+       : UpdatableInset(in), inset(in.inset), status_(in.status_),
          labelfont_(in.labelfont_), label(in.label)
 #if 0
          ,autocollapse(in.autocollapse)
@@ -77,7 +78,7 @@ bool InsetCollapsable::insertInset(BufferView * bv, InsetOld * in)
 
 void InsetCollapsable::write(Buffer const & buf, ostream & os) const
 {
-       os << "collapsed " << (collapsed_ ? "true" : "false") << "\n";
+       os << "collapsed " << (status_ == Collapsed ? "true" : "false") << "\n";
        inset.writeParagraphData(buf, os);
 }
 
@@ -89,7 +90,7 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
                string const token = lex.getString();
                if (token == "collapsed") {
                        lex.next();
-                       collapsed_ = lex.getBool();
+                       status_ = lex.getBool() ? Collapsed : Open;
                } else {
                        lyxerr << "InsetCollapsable::Read: Missing collapsed!"
                               << endl;
@@ -118,12 +119,16 @@ int InsetCollapsable::height_collapsed() const
 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        //lyxerr << "InsetCollapsable::metrics:  width: " << mi.base.textwidth << endl;
-       dimension_collapsed(dim);
-       if (!collapsed_) {
-               Dimension insetdim;
-               inset.metrics(mi, insetdim);
-               dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
-               dim.wid = max(dim.wid, insetdim.wid);
+       if (status_ == Inlined) {
+               inset.metrics(mi, dim);
+       } else {
+               dimension_collapsed(dim);
+               if (status_ == Open) {
+                       Dimension insetdim;
+                       inset.metrics(mi, insetdim);
+                       dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
+                       dim.wid = max(dim.wid, insetdim.wid);
+               }
        }
        dim_ = dim;
        //lyxerr << "InsetCollapsable::metrics:  dim.wid: " << dim.wid << endl;
@@ -136,50 +141,42 @@ void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
+void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
-       Dimension dim_collapsed;
-       dimension_collapsed(dim_collapsed);
-
-       int const aa  = ascent();
-       button_dim.x1 = 0;
-       button_dim.x2 = dim_collapsed.width();
-       button_dim.y1 = -aa;
-       button_dim.y2 = -aa + dim_collapsed.height();
-
        xo_ = x;
        yo_ = y;
 
-       if (collapsed_) {
-               draw_collapsed(pi, x, y);
-               return;
-       }
-
-       int old_x = x;
-
-       if (!owner())
-               x += scroll();
-
-       if (inlined) {
+       if (status_ == Inlined) {
                inset.draw(pi, x, y);
        } else {
-               int const bl = y - aa + dim_collapsed.ascent();
-               draw_collapsed(pi, old_x, bl);
-               inset.draw(pi, x, bl + dim_collapsed.descent() + inset.ascent());
+               Dimension dimc;
+               dimension_collapsed(dimc);
+
+               int const aa  = ascent();
+               button_dim.x1 = 0;
+               button_dim.x2 = dimc.width();
+               button_dim.y1 = -aa;
+               button_dim.y2 = -aa + dimc.height();
+
+               draw_collapsed(pi, x, y);
+               if (status_ == Open) {
+                       if (!owner())
+                               x += scroll();
+                       inset.draw(pi, x, y - aa + dimc.height() + inset.ascent());
+               }
        }
 }
 
 
-void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
+InsetOld::EDITABLE InsetCollapsable::editable() const
 {
-       // by default we don't draw inline
-       draw(pi, x, y, false);
+       return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
 }
 
 
-InsetOld::EDITABLE InsetCollapsable::editable() const
+bool InsetCollapsable::descendable() const
 {
-       return collapsed_ ? IS_EDITABLE : HIGHLY_EDITABLE;
+       return status_ != Collapsed;
 }
 
 
@@ -202,22 +199,22 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
                return DispatchResult(true, true);
        }
 
-       if (collapsed_) {
+       if (status_ == Collapsed) {
                lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
-               collapsed_ = false;
+               setStatus(Open);
                edit(bv, true);
                return DispatchResult(true, true);
        }
 
        if (hitButton(cmd)) {
-               if (!collapsed_) {
-                       collapsed_ = true;
+               if (status_ == Open) {
+                       setStatus(Collapsed);
                        lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
                        return DispatchResult(false, FINISHED_RIGHT);
                }
-               collapsed_ = false;
+               setStatus(Open);
                lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
-       } else if (!collapsed_ && cmd.y > button_dim.y2) {
+       } else if (status_ == Open && cmd.y > button_dim.y2) {
                lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
                return inset.dispatch(adjustCommand(cmd));
        }
@@ -289,7 +286,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left)
 {
        lyxerr << "InsetCollapsable: edit left/right" << endl;
        inset.edit(bv, left);
-       open();
+       setStatus(Open);
        bv->cursor().push(this);
 }
 
@@ -297,8 +294,8 @@ void InsetCollapsable::edit(BufferView * bv, bool left)
 void InsetCollapsable::edit(BufferView * bv, int x, int y)
 {
        lyxerr << "InsetCollapsable: edit xy" << endl;
-       if (collapsed_) {
-               collapsed_ = false;
+       if (status_ == Collapsed) {
+               setStatus(Open);
        } else {
                if (y <= button_dim.y2)
                        y = 0;
@@ -313,35 +310,36 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y)
 DispatchResult
 InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
 {
-       lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
-               << "  button y: " << button_dim.y2 << endl;
+       //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
+       //      << "  button y: " << button_dim.y2 << endl;
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
-                       if (!collapsed_ && cmd.y > button_dim.y2)
+                       if (!status_ && cmd.y > button_dim.y2)
                                inset.dispatch(adjustCommand(cmd));
                        return DispatchResult(true, true);
 
                case LFUN_MOUSE_MOTION:
-                       if (!collapsed_)
+                       if (!status_)
                                inset.dispatch(adjustCommand(cmd));
                        return DispatchResult(true, true);
 
                case LFUN_MOUSE_RELEASE:
-                       if (!collapsed_ && cmd.y > button_dim.y2)
+                       if (!status_ && cmd.y > button_dim.y2)
                                inset.dispatch(adjustCommand(cmd));
                        else
                                return lfunMouseRelease(cmd);
                        return DispatchResult(true, true);
 
                case LFUN_INSET_TOGGLE:
-                       if (!inset.text_.toggleInset())
-                               close();
-                       return DispatchResult(true, true);
+                       if (inset.text_.toggleInset())
+                               return DispatchResult(true, true);
+                       close();
+                       return DispatchResult(false, FINISHED_RIGHT);
 
                default:
                        return inset.dispatch(adjustCommand(cmd));
        }
-       lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
+       //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
 }
 
 
@@ -354,7 +352,8 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
 void InsetCollapsable::getCursorPos(int & x, int & y) const
 {
        inset.getCursorPos(x, y);
-       y += - ascent() + height_collapsed() + inset.ascent();
+       if (status_ != Inlined)
+               y += - ascent() + height_collapsed() + inset.ascent();
 }
 
 
@@ -396,13 +395,13 @@ LyXText * InsetCollapsable::getText(int i) const
 
 void InsetCollapsable::open()
 {
-       collapsed_ = false;
+       setStatus(Open);
 }
 
 
-void InsetCollapsable::close() const
+void InsetCollapsable::close()
 {
-       collapsed_ = true;
+       setStatus(Collapsed);
 }
 
 
@@ -412,9 +411,9 @@ void InsetCollapsable::setLabel(string const & l) const
 }
 
 
-void InsetCollapsable::setCollapsed(bool c) const
+void InsetCollapsable::setStatus(CollapseStatus s)
 {
-       collapsed_ = c;
+       status_ = s;
 }
 
 
@@ -462,12 +461,6 @@ void InsetCollapsable::scroll(BufferView * bv, int offset) const
 }
 
 
-bool InsetCollapsable::isOpen() const
-{
-       return !collapsed_;
-}
-
-
 Box const & InsetCollapsable::buttonDim() const
 {
        return button_dim;
index c0eed4a19538f2f1bdb681659e88b9a51b8b3e7f..a662c6bc18a984cd639f34a41d355ae9b45dfd14 100644 (file)
@@ -34,6 +34,12 @@ public:
        static int const TEXT_TO_TOP_OFFSET = 2;
        ///
        static int const TEXT_TO_BOTTOM_OFFSET = 2;
+       ///
+       enum CollapseStatus {
+               Open,
+               Collapsed,
+               Inlined
+       };
        /// inset is initially collapsed if bool = true
        InsetCollapsable(BufferParams const &, bool collapsed = false);
        ///
@@ -46,8 +52,6 @@ public:
        void metrics(MetricsInfo &, Dimension &) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
-       /// draw, either inlined (no button) or collapsed/open
-       void draw(PainterInfo & pi, int x, int y, bool inlined) const;
        ///
        bool hitButton(FuncRequest const &) const;
        ///
@@ -55,7 +59,7 @@ public:
        ///
        EDITABLE editable() const;
        /// can we go further down on mouse click?
-       bool descendable() const { return isOpen(); }
+       bool descendable() const;
        ///
        bool insertInset(BufferView *, InsetOld * inset);
        ///
@@ -101,19 +105,23 @@ public:
        ///
        LyXText * getText(int) const;
        ///
-       bool display() const { return isOpen(); }
+       bool isOpen() const { return status_ == Open || status_ == Inlined; }
+       ///
+       bool inlined() const { return status_ == Inlined; }
        ///
-       bool isOpen() const;
+       CollapseStatus status() const { return status_; }
        ///
        void open();
        ///
-       void close() const;
+       void close();
        ///
        void markErased();
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
        ///
        void setBackgroundColor(LColor_color);
+       ///
+       virtual void setStatus(CollapseStatus st);
 
 protected:
        ///
@@ -128,8 +136,6 @@ protected:
        void draw_collapsed(PainterInfo & pi, int x, int y) const;
        ///
        int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
-       /// Should be non-const...
-       void setCollapsed(bool) const;
        ///
        Box const & buttonDim() const;
        ///
@@ -146,9 +152,9 @@ private:
 public:
        ///
        mutable InsetText inset;
-private:
+protected:
        ///
-       mutable bool collapsed_;
+       mutable CollapseStatus status_;
        ///
        LyXFont labelfont_;
        ///
index 4451a3cc06f992f7953c2311483cf56a9b9d46d9..5113d04c6825e69c44a884ed785d71da2d854b39 100644 (file)
@@ -66,7 +66,7 @@ InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
 
 
 InsetERT::InsetERT(InsetERT const & in)
-       : InsetCollapsable(in), status_(in.status_)
+       : InsetCollapsable(in)
 {
        init();
 }
@@ -119,12 +119,12 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex)
                        string const tmp_token = lex.getString();
 
                        if (tmp_token == "Inlined") {
-                               status(Inlined);
+                               status_ = Inlined;
                        } else if (tmp_token == "Collapsed") {
-                               status(Collapsed);
+                               status_ = Collapsed;
                        } else {
                                // leave this as default!
-                               status(Open);
+                               status_ = Open;
                        }
 
                        token_found = true;
@@ -154,9 +154,9 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex)
 
        if (!token_found) {
                if (isOpen())
-                       status(Open);
+                       status_ = Open;
                else
-                       status(Collapsed);
+                       status_ = Collapsed;
        }
        setButtonLabel();
 }
@@ -228,19 +228,13 @@ void InsetERT::updateStatus(bool swap) const
 {
        if (status_ != Inlined) {
                if (isOpen())
-                       status(swap ? Collapsed : Open);
+                       status_ = swap ? Collapsed : Open;
                else
-                       status(swap ? Open : Collapsed);
+                       status_ = swap ? Open : Collapsed;
        }
 }
 
 
-InsetOld::EDITABLE InsetERT::editable() const
-{
-       return (status_ == Collapsed) ? IS_EDITABLE : HIGHLY_EDITABLE;
-}
-
-
 void InsetERT::lfunMousePress(FuncRequest const & cmd)
 {
        if (status_ == Inlined)
@@ -411,9 +405,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY: {
-               InsetERT::ERTStatus status_;
                InsetERTMailer::string2params(cmd.argument, status_);
-               status(status_);
                bv->update();
                return DispatchResult(true, true);
        }
@@ -457,24 +449,22 @@ void InsetERT::setButtonLabel() const
 }
 
 
+bool InsetERT::insetAllowed(InsetOld::Code code) const
+{
+       return code == InsetOld::NEWLINE_CODE;
+}
+
+
 void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       setButtonLabel();
-       if (inlined())
-               inset.metrics(mi, dim);
-       else
-               InsetCollapsable::metrics(mi, dim);
-       // Make it stand out on its own as it is code, not part of running
-       // text:
-       if (isOpen() && !inlined())
-               dim.wid = mi.base.textwidth;
+       InsetCollapsable::metrics(mi, dim);
        dim_ = dim;
 }
 
 
 void InsetERT::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCollapsable::draw(pi, x, y, inlined());
+       InsetCollapsable::draw(pi, x, y);
 }
 
 
@@ -489,25 +479,10 @@ void InsetERT::setLatexFont(BufferView * /*bv*/)
 }
 
 
-void InsetERT::status(ERTStatus const st) const
+void InsetERT::setStatus(CollapseStatus st)
 {
-       if (st == status_)
-               return;
-
        status_ = st;
-
-       switch (st) {
-       case Inlined:
-               break;
-       case Open:
-               setCollapsed(false);
-               setButtonLabel();
-               break;
-       case Collapsed:
-               setCollapsed(true);
-               setButtonLabel();
-               break;
-       }
+       setButtonLabel();
 }
 
 
@@ -518,22 +493,6 @@ bool InsetERT::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetERT::open()
-{
-       if (!isOpen())
-               status(Open);
-}
-
-
-void InsetERT::close() const
-{
-       if (status_ == Collapsed || status_ == Inlined)
-               return;
-
-       status(Collapsed);
-}
-
-
 void InsetERT::getDrawFont(LyXFont & font) const
 {
        font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
@@ -556,9 +515,9 @@ string const InsetERTMailer::inset2string(Buffer const &) const
 
 
 void InsetERTMailer::string2params(string const & in,
-                                  InsetERT::ERTStatus & status)
+                                  InsetCollapsable::InsetCollapsable::CollapseStatus & status)
 {
-       status = InsetERT::Collapsed;
+       status = InsetCollapsable::Collapsed;
 
        string name;
        string body = split(in, name, ' ');
@@ -566,11 +525,12 @@ void InsetERTMailer::string2params(string const & in,
        if (body.empty())
                return;
 
-       status = static_cast<InsetERT::ERTStatus>(strToInt(body));
+       status = static_cast<InsetCollapsable::CollapseStatus>(strToInt(body));
 }
 
 
-string const InsetERTMailer::params2string(InsetERT::ERTStatus status)
+string const
+InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
 {
        return name_ + ' ' + tostr(status);
 }
index 98c102ba572831f98e792fb33ddce4544d7cc6a8..4c8796963827227821493972b995376ace156333 100644 (file)
@@ -29,12 +29,6 @@ class Language;
 
 class InsetERT : public InsetCollapsable {
 public:
-       ///
-       enum ERTStatus {
-               Open,
-               Collapsed,
-               Inlined
-       };
        ///
        InsetERT(BufferParams const &, bool collapsed = false);
        ///
@@ -57,11 +51,7 @@ public:
        ///
        bool insertInset(BufferView *, InsetOld *);
        ///
-       bool insetAllowed(InsetOld::Code code) const {
-               return code == InsetOld::NEWLINE_CODE;
-       }
-       ///
-       EDITABLE editable() const;
+       bool insetAllowed(InsetOld::Code code) const;
        ///
        int latex(Buffer const &, std::ostream &,
                  OutputParams const &) const;
@@ -77,29 +67,17 @@ public:
        ///
        void validate(LaTeXFeatures &) const {}
        ///
-       // these are needed here because of the label/inlined functionallity
-       ///
-       bool isOpen() const { return status_ == Open || status_ == Inlined; }
-       ///
-       bool inlined() const { return status_ == Inlined; }
-       ///
-       ERTStatus status() const { return status_; }
-       ///
-       void open();
-       ///
-       void close() const;
-       ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
-       /// set the status of the inset
-       void status(ERTStatus const st) const;
        ///
        bool showInsetDialog(BufferView *) const;
        ///
        void getDrawFont(LyXFont &) const;
        ///
        bool forceDefaultParagraphs(InsetOld const *) const { return true; }
+       ///
+       void setStatus(CollapseStatus st);
 protected:
        ///
        virtual
@@ -128,9 +106,6 @@ private:
        void edit(BufferView * bv, bool left);
        ///
        bool allowSpellCheck() const { return false; }
-
-       ///
-       mutable ERTStatus status_;
 };
 
 
@@ -147,9 +122,10 @@ public:
        ///
        virtual std::string const inset2string(Buffer const &) const;
        ///
-       static void string2params(std::string const &, InsetERT::ERTStatus &);
+       static void string2params(std::string const &,
+               InsetCollapsable::CollapseStatus &);
        ///
-       static std::string const params2string(InsetERT::ERTStatus);
+       static std::string const params2string(InsetCollapsable::CollapseStatus);
 private:
        ///
        static std::string const name_;
index 624ff48e869b6082bc2469e58a9066874867960c..7b206d8ba97ccf9826cdaa8784c77672d67e5245 100644 (file)
@@ -282,6 +282,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
                break;
 
        case MARGIN_RIGHT_ADDRESS_BOX: {
+#if 0
                // ok, a terrible hack. The left margin depends on the widest
                // row in this paragraph.
                RowList::iterator rit = pit->rows.begin();
@@ -294,6 +295,9 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
                x += font_metrics::signedWidth(layout->leftmargin,
                        tclass.defaultfont());
                x += minfill;
+#endif
+               // also wrong, but much shorter.
+               x += textwidth_ / 2;
                break;
        }
        }
@@ -1620,7 +1624,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
        // final dimension
        dim.asc = firstRow()->ascent_of_text();
        dim.des = height - dim.asc;
-       dim.wid = std::max(mi.base.textwidth, int(width));
+       dim.wid = width;
 }