]> git.lyx.org Git - features.git/commitdiff
Fix bug 2884 and 3437:
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 21 Apr 2007 08:43:46 +0000 (08:43 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 21 Apr 2007 08:43:46 +0000 (08:43 +0000)
* src/insets/insetbase.h:
* src/insets/insetcollapsable.h:
- make isFixedWidth (former insetcollapsable member) a member of insetbase.
src/insets/insettext.h:
- make border_ public (needed by insetcollapsable).
src/insets/insettext.C (draw, drawSelection):
- adjust drawing for fixed width insets
* src/insets/insetcollapsable.C (metrics):
- adjust dimension for fixed width insets
src/insets/insetbox.C (metrics):
- properly calculate metrics for fixed width insets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17879 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/insetbase.h
src/insets/insetbox.C
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettext.C
src/insets/insettext.h

index 8e6786b67b647e09327f0e6c4185b734fbd47425..815136072c431412f65755e57ff1ef5818843f82 100644 (file)
@@ -357,6 +357,8 @@ public:
        /// if this inset has paragraphs should they be output all as default
        /// paragraphs with the default layout of the text class?
        virtual bool forceDefaultParagraphs(idx_type) const { return false; }
+       /// Is the width forced to some value?
+       virtual bool hasFixedWidth() const { return false; }
 
        ///
        virtual docstring const & getInsetName() const;
index acc533e4b356b1f95b2455aaf585e2a262b86ed3..6e07db2cac7ef45c712d93b0eb10b0d2a07a0ffe 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "insetbox.h"
 
+#include "BufferView.h"
 #include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
@@ -25,6 +26,7 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
+#include "TextMetrics.h"
 
 #include "support/translator.h"
 
@@ -177,8 +179,13 @@ bool InsetBox::hasFixedWidth() const
 bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 {
        MetricsInfo mi = m;
+       // first round in order to know the minimum size.
+       InsetCollapsable::metrics(mi, dim);
+       TextMetrics & tm = mi.base.bv->textMetrics(&text_);
        if (hasFixedWidth())
-               mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
+               mi.base.textwidth =
+                       std::max(tm.width() + 2 * border_ + (int) (2.5 * TEXT_TO_INSET_OFFSET),
+                                params_.width.inPixels(m.base.textwidth));
        InsetCollapsable::metrics(mi, dim);
        bool const changed = dim_ != dim;
        dim_ = dim;
index 0adaaf6a77d05fbe1db5b6b472508f3ee310a78c..0c480765c7af010bc22a93af0a9ce36a13356b55 100644 (file)
@@ -173,6 +173,8 @@ bool InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
                        } else {
                                dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
                                dim.wid = max(dim.wid, textdim_.wid);
+                               if (hasFixedWidth())
+                                       dim.wid = max(dim.wid, mi.base.textwidth);
                        }
                }
        }
index af7469aed2178f4cc716af352cdef1a81423f3bf..5bc909ea621afe21d999b544ab56f2fd7bb4d5d9 100644 (file)
@@ -98,8 +98,6 @@ protected:
        InsetBase * editXY(LCursor & cur, int x, int y);
        ///
        void setInlined() { status_ = Inlined; }
-       /// Is the width forced to some value?
-       virtual bool hasFixedWidth() const { return false; }
        ///
        docstring floatName(std::string const & type, BufferParams const &) const;
 
index 676c11e07313784cb1462e2517a90223bd91d084..a782cc56f53775d01e80dda54da0ce27fc52dc2c 100644 (file)
@@ -198,8 +198,9 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
                int const w = tm.width() + 2 * border_;
                int const a = tm.ascent() + border_;
                int const h = a + tm.descent() + border_;
-               pi.pain.rectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
-                       frameColor());
+               pi.pain.rectangle(x, y - a,
+                                 ((wide() || hasFixedWidth()) ? tm.maxWidth() : w),
+                                 h, frameColor());
        }
 }
 
@@ -211,8 +212,9 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
        int const w = tm.width() + 2 * border_;
        int const a = tm.ascent() + border_;
        int const h = a + tm.descent() + border_;
-       pi.pain.fillRectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
-               backgroundColor());
+       pi.pain.fillRectangle(x, y - a,
+                             ((wide() || hasFixedWidth()) ? tm.maxWidth() : w),
+                             h, backgroundColor());
        text_.drawSelection(pi, x + border_, y);
 }
 
index 6b7d3563488ebbbef0bf8a857843b721d81e175f..3b21200f3dfecd2387e8004f227bf51ab27f265b 100644 (file)
@@ -159,14 +159,14 @@ private:
        ///
        mutable pit_type old_pit;
        ///
-       static int border_;
-       ///
        bool wide_inset_;
 public:
        ///
        mutable LyXText text_;
        ///
        mutable LyXFont font_;
+       ///
+       static int border_;
 };
 
 } // namespace lyx