On Mon, Jul 21, 2003 at 07:54:30PM +0100, John Levon wrote:

> The actual red frame drawing itself is a bit tougher. I'm looking into
> it.

Another patch, taking inspiration from where Andre was heading I
believe. Compiling it now, probably won't work, but the idea is clear -
dump the horrendous workWidth() crap for a simple maxwidth value that is
inherited from the parent. There's not much hope unless we do
/something/ like this.

We have to be careful to keep full row insets expanded even when the
text is narrower. Hence the testing of needFullRow, which *should* do
the right thing for ERT

Comments ?

regards
john


Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.193
diff -u -p -r1.193 lyxtext.h
--- lyxtext.h   18 Jul 2003 07:47:03 -0000      1.193
+++ lyxtext.h   21 Jul 2003 19:05:32 -0000
@@ -52,7 +52,7 @@ public:
        void init(BufferView *);
        ///
        int height;
-       ///
+       /// current width of text
        unsigned int width;
        /// the current font settings
        LyXFont current_font;
@@ -194,6 +194,9 @@ private:
        // do we need a refresh?
        bool need_refresh_;
 
+       /// maximum width of text
+       unsigned int maxwidth;
+
 public:
        /// only the top-level LyXText has this non-zero
        BufferView * bv_owner;
@@ -398,10 +401,12 @@ public:
        bool updateInset(Inset *);
        ///
        void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos);
-       ///
+       /// this should go in favour of maxWidth()
        int workWidth() const;
        /// returns width of row containing inset
        int workWidth(Inset const * inset) const;
+       /// return the maximum width for this text
+       unsigned int maxWidth() const;
 
        ///
        void computeBidiTables(Buffer const *, RowList::iterator row) const;
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.383
diff -u -p -r1.383 text.C
--- text.C      18 Jul 2003 12:05:48 -0000      1.383
+++ text.C      21 Jul 2003 19:05:36 -0000
@@ -142,6 +142,14 @@ void LyXText::anchor_row(RowList::iterat
 }
 
 
+unsigned int LyXText::maxWidth() const
+{
+       if (inset_owner)
+               return maxwidth;
+       return bv()->workWidth();
+}
+
+
 int LyXText::workWidth() const
 {
        return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
@@ -311,19 +319,8 @@ int LyXText::singleWidth(ParagraphList::
                                // Because of the representation as vertical lines
                                return 3;
                        }
-#if 1
-#warning inset->update FIXME
-                       // this IS needed otherwise on initialitation we don't get the 
fill
-                       // of the row right (ONLY on initialization if we read a file!)
-                       // should be changed! (Jug 20011204)
-                       //tmpinset->update(bv());
-                       Dimension dim;
-                       MetricsInfo mi(bv(), font, workWidth());
-                       tmpinset->metrics(mi, dim);
-                       return dim.wid;
-#else 
+
                        return tmpinset->width();
-#endif
                }
                return 0;
        }
@@ -826,26 +823,38 @@ pos_type LyXText::rowBreakPoint(Row cons
 
                char const c = pit->getChar(i);
 
-               int thiswidth;
+               int labeladdwidth = 0;
 
                // add the auto-hfill from label end to the body
                if (body_pos && i == body_pos) {
-                       thiswidth = font_metrics::width(layout->labelsep,
+                       labeladdwidth = font_metrics::width(layout->labelsep,
                                getLabelFont(bv()->buffer(), pit));
                        if (pit->isLineSeparator(i - 1))
-                               thiswidth -= singleWidth(pit, i - 1);
+                               labeladdwidth -= singleWidth(pit, i - 1);
                        int left_margin = labelEnd(row);
-                       if (thiswidth + x < left_margin)
-                               thiswidth = left_margin - x;
-                       thiswidth += singleWidth(pit, i, c);
+                       if (labeladdwidth + x < left_margin)
+                               labeladdwidth = left_margin - x;
+               }
+
+               int thiswidth;
+
+               Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
+               /* update the metrics */
+               if (in) {
+                       LyXFont const font = getFont(bv()->buffer(), pit, pos);
+                       Dimension dim;
+                       MetricsInfo mi(bv(), font, maxWidth() - (x + labeladdwidth));
+                       in->metrics(mi, dim);
+                       thiswidth = dim.wid;
                } else {
                        thiswidth = singleWidth(pit, i, c);
                }
 
+               thiswidth += labeladdwidth;
+
                x += thiswidth;
                chunkwidth += thiswidth;
 
-               Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
                fullrow = (in && (in->display() || in->needFullRow()));
 
                // break before a character that will fall off
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.393
diff -u -p -r1.393 text2.C
--- text2.C     21 Jul 2003 11:01:28 -0000      1.393
+++ text2.C     21 Jul 2003 19:05:38 -0000
@@ -58,22 +58,20 @@ using lyx::pos_type;
 
 
 LyXText::LyXText(BufferView * bv)
-       : height(0), width(0), anchor_row_offset_(0),
-         inset_owner(0), the_locking_inset(0), bv_owner(bv)
+       : height(0), width(0), anchor_row_offset_(0), inset_owner(0),
+       the_locking_inset(0), need_refresh_(true), maxwidth(0), bv_owner(bv)
 {
        anchor_row_ = rows().end();
        need_break_row = rows().end();
-       need_refresh_ = true;
 }
 
 
 LyXText::LyXText(BufferView * bv, InsetText * inset)
-       : height(0), width(0), anchor_row_offset_(0),
-         inset_owner(inset), the_locking_inset(0), bv_owner(bv)
+       : height(0), width(0), anchor_row_offset_(0), inset_owner(inset),
+       the_locking_inset(0), need_refresh_(true), maxwidth(0), bv_owner(bv)
 {
        anchor_row_ = rows().end();
        need_break_row = rows().end();
-       need_refresh_ = true;
 }
 
 
@@ -692,8 +690,10 @@ void LyXText::fullRebreak()
 }
 
 
-void LyXText::rebuild(int maxwidth)
+void LyXText::rebuild(int max)
 {
+       maxwidth = max;
+
        rowlist_.clear();
        need_break_row = rows().end();
        width = height = 0;
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.155
diff -u -p -r1.155 insetcollapsable.C
--- insets/insetcollapsable.C   18 Jul 2003 16:13:33 -0000      1.155
+++ insets/insetcollapsable.C   21 Jul 2003 19:05:41 -0000
@@ -136,6 +136,8 @@ void InsetCollapsable::metrics(MetricsIn
                inset.metrics(mi, insetdim);
                dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
                dim.wid = max(dim.wid, insetdim.wid);
+               lyxerr << "collapse wid" << dim.wid << endl;
+               lyxerr << "insetdim wid" << insetdim.wid << endl;
        }
        dim_ = dim;
 }
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.442
diff -u -p -r1.442 insettext.C
--- insets/insettext.C  21 Jul 2003 11:01:29 -0000      1.442
+++ insets/insettext.C  21 Jul 2003 19:05:43 -0000
@@ -282,10 +282,15 @@ void InsetText::metrics(MetricsInfo & mi
        BufferView * bv = mi.base.bv;
        setViewCache(bv);
        text_.rebuild(mi.base.textwidth);
+       lyxerr << "text wid" << text_.width;
+       lyxerr << "basemaxwidth" << mi.base.textwidth;
        dim.asc = text_.rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
        dim.des = text_.height - dim.asc + TEXT_TO_INSET_OFFSET;
-       dim.wid = max(textwidth_, int(text_.width)) + 2 * TEXT_TO_INSET_OFFSET;
+       dim.wid = int(text_.width) + 2 * TEXT_TO_INSET_OFFSET;
+       if (dim.wid > textwidth_ || needFullRow())
+               dim.wid = textwidth_;
        dim.wid = max(dim.wid, 10);
+       lyxerr << "insettext width is now " << dim.wid;
        dim_ = dim;
 }
 

Reply via email to