This is a more recent version, that also fixes bug 966. We were not
checking for size(text) < size(button) in the ERT draw. This was fixed
by merging  the duplicated code.

john


? a.diff
Index: insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.129
diff -u -p -r1.129 insetcollapsable.C
--- insetcollapsable.C  19 Mar 2003 14:45:18 -0000      1.129
+++ insetcollapsable.C  19 Mar 2003 19:40:59 -0000
@@ -46,7 +46,7 @@ class LyXText;
 InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
        : UpdatableInset(), collapsed_(collapsed), inset(bp),
          button_length(0), button_top_y(0), button_bottom_y(0),
-         need_update(NONE), label("Label"),
+         label("Label"),
 #if 0
        autocollapse(false),
 #endif
@@ -64,7 +64,7 @@ InsetCollapsable::InsetCollapsable(Inset
        : UpdatableInset(in, same_id), collapsed_(in.collapsed_),
          framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
          button_length(0), button_top_y(0), button_bottom_y(0),
-         need_update(NONE), label(in.label),
+         label(in.label),
 #if 0
          autocollapse(in.autocollapse),
 #endif
@@ -167,10 +167,10 @@ int InsetCollapsable::width(BufferView *
        if (collapsed_)
                return width_collapsed();
 
-       int widthCollapsed = width_collapsed();
+       int const collapsed_width = width_collapsed();
+       int const contents_width = inset.width(bv, font);
 
-       return (inset.width(bv, font) > widthCollapsed) ?
-               inset.width(bv, font) : widthCollapsed;
+       return max(collapsed_width, contents_width);
 }
 
 
@@ -184,17 +184,11 @@ void InsetCollapsable::draw_collapsed(Pa
 
 
 void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x) const
+                            int baseline, float & x, bool inlined) const
 {
        lyx::Assert(bv);
        cache(bv);
 
-       if (need_update != NONE) {
-               const_cast<InsetText *>(&inset)->update(bv, f, true);
-               bv->text->postChangedInDraw();
-               need_update = NONE;
-               return;
-       }
        if (nodraw())
                return;
 
@@ -213,7 +207,7 @@ void InsetCollapsable::draw(BufferView *
        float old_x = x;
 
        if (!owner())
-               x += static_cast<float>(scroll());
+               x += scroll();
 
        top_x = int(x);
        topx_set = true;
@@ -221,10 +215,23 @@ void InsetCollapsable::draw(BufferView *
 
        int const bl = baseline - ascent(bv, f) + ascent_collapsed();
 
-       draw_collapsed(pain, bl, old_x);
-       inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
-       if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET))
-               x = top_x + button_length + TEXT_TO_INSET_OFFSET;
+       if (inlined) {
+               inset.draw(bv, f, baseline, x);
+       } else {
+               draw_collapsed(pain, bl, old_x);
+               inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
+               // contained inset may be shorter than the button
+               if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET))
+                       x = top_x + button_length + TEXT_TO_INSET_OFFSET;
+       }
+}
+
+
+void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
+                           int baseline, float & x) const
+{
+       // by default, we are not inlined-drawing
+       draw(bv, f, baseline, x, false);
 }
 
 
Index: insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.94
diff -u -p -r1.94 insetcollapsable.h
--- insetcollapsable.h  17 Mar 2003 01:34:34 -0000      1.94
+++ insetcollapsable.h  19 Mar 2003 19:40:59 -0000
@@ -33,11 +33,6 @@ class LyXCursor;
 class InsetCollapsable : public UpdatableInset {
 public:
        ///
-       enum UpdateCodes {
-               NONE = 0,
-               FULL
-       };
-       ///
        static int const TEXT_TO_TOP_OFFSET = 2;
        ///
        static int const TEXT_TO_BOTTOM_OFFSET = 2;
@@ -57,6 +52,9 @@ public:
        int width(BufferView *, LyXFont const &) const;
        ///
        void draw(BufferView *, const LyXFont &, int , float &) const;
+       /// draw, either inlined (no button) or collapsed/open
+       void draw(BufferView * bv, LyXFont const & f,
+                 int baseline, float & x, bool inlined) const;
        ///
        void update(BufferView *, LyXFont const &, bool =false);
        ///
@@ -226,7 +224,6 @@ protected:
        ///
        mutable int topx;
        mutable int topbaseline;
-       mutable UpdateCodes need_update;
 
 private:
        ///
Index: insetert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v
retrieving revision 1.110
diff -u -p -r1.110 insetert.C
--- insetert.C  19 Mar 2003 14:45:19 -0000      1.110
+++ insetert.C  19 Mar 2003 19:41:00 -0000
@@ -53,7 +53,7 @@ void InsetERT::init()
 
 
 InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
-       : InsetCollapsable(bp, collapsed)
+       : InsetCollapsable(bp, collapsed), need_update(false)
 {
        if (collapsed)
                status_ = Collapsed;
@@ -64,7 +64,8 @@ InsetERT::InsetERT(BufferParams const & 
 
 
 InsetERT::InsetERT(InsetERT const & in, bool same_id)
-       : InsetCollapsable(in, same_id), status_(in.status_)
+       : InsetCollapsable(in, same_id), status_(in.status_),
+       need_update(false)
 {
        init();
 }
@@ -572,36 +573,15 @@ void InsetERT::draw(BufferView * bv, LyX
        lyx::Assert(bv);
        cache(bv);
 
-       Painter & pain = bv->painter();
-
-       button_length = width_collapsed();
-       button_top_y = -ascent(bv, f);
-       button_bottom_y = -ascent(bv, f) + ascent_collapsed() +
-               descent_collapsed();
-
-       if (!isOpen()) {
-               draw_collapsed(pain, baseline, x);
+       if (need_update) {
+               InsetText * it = const_cast<InsetText *>(&inset);
+               it->update(bv, f, true);
+               bv->text->postChangedInDraw();
+               need_update = false;
                return;
        }
 
-       float old_x = x;
-
-       if (!owner())
-               x += static_cast<float>(scroll());
-
-       top_x = int(x);
-       topx_set = true;
-       top_baseline = baseline;
-
-       int const bl = baseline - ascent(bv, f) + ascent_collapsed();
-
-       if (inlined()) {
-               inset.draw(bv, f, baseline, x);
-       } else {
-               draw_collapsed(pain, bl, old_x);
-               inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
-       }
-       need_update = NONE;
+       InsetCollapsable::draw(bv, f, baseline, x, inlined());
 }
 
 
@@ -623,7 +603,7 @@ void InsetERT::status(BufferView * bv, E
 {
        if (st != status_) {
                status_ = st;
-               need_update = FULL;
+               need_update = true;
                switch (st) {
                case Inlined:
                        if (bv)
@@ -710,10 +690,10 @@ void InsetERT::update(BufferView * bv, L
                      bool reinit)
 {
        if (inset.need_update & InsetText::INIT ||
-               inset.need_update & InsetText::FULL)
-       {
+           inset.need_update & InsetText::FULL) {
                setButtonLabel();
        }
+
        InsetCollapsable::update(bv, font, reinit);
 }
 
Index: insetert.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v
retrieving revision 1.64
diff -u -p -r1.64 insetert.h
--- insetert.h  17 Mar 2003 01:34:34 -0000      1.64
+++ insetert.h  19 Mar 2003 19:41:00 -0000
@@ -149,6 +149,9 @@ private:
 
        ///
        mutable ERTStatus status_;
+
+       /// repaint needed ?
+       mutable bool need_update;
 };
 
 

Reply via email to