commit 8aaec85c8cc43d2317b684b0977eb47dd686af96
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Tue Dec 6 09:48:49 2016 +0100

    Now Inset::dimension is only an access to cache
    
    Up to now Inset::dimension was either a helper function to access
    CoordCache, or... something else. This created problems to properly
    use it.
    
    In particular, the definition of InsetText::dimension created problems
    for child classes. Removing this definition (actually renaming it to
    dimensionHelper) allows to streamline the code.
---
 src/BufferView.cpp              |   14 +-------------
 src/insets/Inset.h              |    7 ++++---
 src/insets/InsetCollapsable.cpp |    4 ++--
 src/insets/InsetCommand.h       |    3 ---
 src/insets/InsetIPAMacro.cpp    |    6 +++---
 src/insets/InsetLine.cpp        |    8 --------
 src/insets/InsetLine.h          |    1 -
 src/insets/InsetPhantom.cpp     |    2 +-
 src/insets/InsetText.cpp        |    2 +-
 src/insets/InsetText.h          |    2 +-
 10 files changed, 13 insertions(+), 36 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 463d0f2..d017db0 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2804,19 +2804,7 @@ Point BufferView::coordOffset(DocIterator const & dit) 
const
                }
 
                // remember width for the case that sl.inset() is positioned in 
an RTL inset
-               if (i && dit[i - 1].text()) {
-                       // If this Inset is inside a Text Inset, retrieve the 
Dimension
-                       // from the containing text instead of using 
Inset::dimension() which
-                       // might not be implemented.
-                       // FIXME (Abdel 23/09/2007): this is a bit messy 
because of the
-                       // elimination of Inset::dim_ cache. This coordOffset() 
method needs
-                       // to be rewritten in light of the new design.
-                       Dimension const & dim = 
coordCache().getInsets().dim(&sl.inset());
-                       lastw = dim.wid;
-               } else {
-                       Dimension const dim = sl.inset().dimension(*this);
-                       lastw = dim.wid;
-               }
+               lastw = sl.inset().dimension(*this).wid;
 
                //lyxerr << "Cursor::getPos, i: "
                // << i << " x: " << xx << " y: " << y << endl;
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 3398a9d..e0418dc 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -209,6 +209,9 @@ public:
        void metricsMarkers(Dimension & dim, int framesize = 1) const;
        /// add space for markers
        void metricsMarkers2(Dimension & dim, int framesize = 1) const;
+
+       /// last metrics computed for the inset
+       Dimension const dimension(BufferView const &) const;
        /// last drawn position for 'important' insets
        int xo(BufferView const & bv) const;
        /// last drawn position for 'important' insets
@@ -218,7 +221,7 @@ public:
        ///
        void setDimCache(MetricsInfo const &, Dimension const &) const;
        /// do we cover screen position x/y?
-       virtual bool covers(BufferView const & bv, int x, int y) const;
+       bool covers(BufferView const & bv, int x, int y) const;
        /// get the screen positions of the cursor (see note in Cursor.cpp)
        virtual void cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const;
@@ -570,8 +573,6 @@ public:
        virtual void rejectChanges() {}
 
        ///
-       virtual Dimension const dimension(BufferView const &) const;
-       ///
        virtual ColorCode backgroundColor(PainterInfo const &) const;
        ///
        virtual ColorCode labelColor() const;
diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp
index 38c744e..7a4c999 100644
--- a/src/insets/InsetCollapsable.cpp
+++ b/src/insets/InsetCollapsable.cpp
@@ -258,7 +258,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) 
const
                view_[&bv].button_dim_.y2 = 0;
        }
 
-       Dimension const textdim = InsetText::dimension(bv);
+       Dimension const textdim = dimensionHelper(bv);
        int const baseline = y;
        int textx, texty;
        Geometry g = geometry(bv);
@@ -366,7 +366,7 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
                status_ = Open;
 
        InsetText::cursorPos(bv, sl, boundary, x, y);
-       Dimension const textdim = InsetText::dimension(bv);
+       Dimension const textdim = dimensionHelper(bv);
 
        switch (geometry(bv)) {
        case LeftButton:
diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h
index 8260ab3..ba7a945 100644
--- a/src/insets/InsetCommand.h
+++ b/src/insets/InsetCommand.h
@@ -99,9 +99,6 @@ protected:
        std::string contextMenuName() const;
        ///
        bool showInsetDialog(BufferView * bv) const;
-       ///
-       Dimension const dimension(BufferView const &) const 
-               { return button_.dimension(); }
        //@}
 
 protected:
diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp
index 0d7a41b..bf3cab5 100644
--- a/src/insets/InsetIPAMacro.cpp
+++ b/src/insets/InsetIPAMacro.cpp
@@ -146,7 +146,7 @@ docstring InsetIPADeco::layoutName() const
 void InsetIPADeco::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetText::metrics(mi, dim);
-       
+
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                // consider width of the inset label
                FontInfo font(getLayout().labelfont());
@@ -187,7 +187,7 @@ void InsetIPADeco::draw(PainterInfo & pi, int x, int y) 
const
        // draw the inset marker
        drawMarkers(pi, x, y);
 
-       Dimension const dim = Inset::dimension(*pi.base.bv);
+       Dimension const dim = dimension(*pi.base.bv);
 
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                FontInfo font(getLayout().labelfont());
@@ -293,7 +293,7 @@ int InsetIPADeco::plaintext(odocstringstream & os,
        docstring result = ods.str();
        docstring const before = result.substr(0, h);
        docstring const after = result.substr(h, result.size());
-       
+
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                os << before;
                os.put(0x0361);
diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp
index 73ce540..46e017f 100644
--- a/src/insets/InsetLine.cpp
+++ b/src/insets/InsetLine.cpp
@@ -138,14 +138,6 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) 
const
 }
 
 
-Dimension const InsetLine::dimension(BufferView const & bv) const
-{
-       // We cannot use InsetCommand::dimension() as this returns the dimension
-       // of the button, which is not used here.
-       return Inset::dimension(bv);
-}
-
-
 void InsetLine::draw(PainterInfo & pi, int x, int y) const
 {
        Dimension const dim = dimension(*pi.base.bv);
diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h
index 8285045..f518297 100644
--- a/src/insets/InsetLine.h
+++ b/src/insets/InsetLine.h
@@ -41,7 +41,6 @@ private:
        /// Inset inherited methods.
        //@{
        InsetCode lyxCode() const { return LINE_CODE; }
-       Dimension const dimension(BufferView const &) const;
        int docbook(odocstream &, OutputParams const &) const;
        /// Does nothing at the moment.
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp
index 8fb9d94..78bc55e 100644
--- a/src/insets/InsetPhantom.cpp
+++ b/src/insets/InsetPhantom.cpp
@@ -157,7 +157,7 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) 
const
        ColorCode const origcol = pi.base.font.color();
        pi.base.font.setColor(Color_special);
        pi.base.font.setColor(origcol);
-       Dimension const dim = Inset::dimension(*pi.base.bv);
+       Dimension const dim = dimension(*pi.base.bv);
 
        if (params_.type == InsetPhantomParams::Phantom ||
                params_.type == InsetPhantomParams::VPhantom) {
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 1c3689f..3c1bb23 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -137,7 +137,7 @@ void InsetText::clear()
 }
 
 
-Dimension const InsetText::dimension(BufferView const & bv) const
+Dimension const InsetText::dimensionHelper(BufferView const & bv) const
 {
        TextMetrics const & tm = bv.textMetrics(&text_);
        Dimension dim = tm.dimension();
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index be4767f..5bc7c52 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -47,7 +47,7 @@ public:
        void setBuffer(Buffer &);
 
        ///
-       Dimension const dimension(BufferView const &) const;
+       Dimension const dimensionHelper(BufferView const &) const;
 
        /// empty inset to empty par
        void clear();

Reply via email to