]> git.lyx.org Git - features.git/commitdiff
Now Inset::dimension is only an access to cache
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 6 Dec 2016 08:48:49 +0000 (09:48 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 6 Dec 2016 08:52:17 +0000 (09:52 +0100)
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
src/insets/Inset.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCommand.h
src/insets/InsetIPAMacro.cpp
src/insets/InsetLine.cpp
src/insets/InsetLine.h
src/insets/InsetPhantom.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h

index 463d0f24b8bd0864be6241217b6e0077c157059c..d017db0cae115dfcad8ff041461c2607e582a59c 100644 (file)
@@ -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;
index 3398a9df3125990f124203cde931b94ba480d606..e0418dc439195a7e4fff3400e5bc1f6b8acff93f 100644 (file)
@@ -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;
@@ -569,8 +572,6 @@ public:
        /// reject the changes within the inset
        virtual void rejectChanges() {}
 
-       ///
-       virtual Dimension const dimension(BufferView const &) const;
        ///
        virtual ColorCode backgroundColor(PainterInfo const &) const;
        ///
index 38c744efd184c0382a161b9d1b0ec78e457e62c3..7a4c99952ddb38d3ce705fcea4d1f2ab36ac94b5 100644 (file)
@@ -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:
index 8260ab3ed6aca08c25166807712b13c2b5ad168f..ba7a945339497ff849e6d87a9cb3e29c8a400948 100644 (file)
@@ -99,9 +99,6 @@ protected:
        std::string contextMenuName() const;
        ///
        bool showInsetDialog(BufferView * bv) const;
-       ///
-       Dimension const dimension(BufferView const &) const 
-               { return button_.dimension(); }
        //@}
 
 protected:
index 0d7a41b0fb1f325aeb479a77435fccde5933f1e0..bf3cab5c3b20cfb41cd829930644c36d2d9e405e 100644 (file)
@@ -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);
index 73ce5401698bf377a1399ca80074dc18644aee00..46e017f99bc0d8134a7f2eb938c34dbbcd19ee02 100644 (file)
@@ -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);
index 8285045ec56ac77a8bece1a9053e10f6e3bc46dc..f518297445dd1b70d0145246c1a215fe1dc15b24 100644 (file)
@@ -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;
index 8fb9d949c74cb5ac08216b211f50bbf6f048d6d8..78bc55ed82ab993d6b2557f80b8860ad7143f390 100644 (file)
@@ -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) {
index 1c3689f627d81c1be78248329b45aad95c721913..3c1bb23f20da669448944bc8fa1b35dbe77d1447 100644 (file)
@@ -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();
index be4767f159e96a5eb9c9b4fc598b81a03a0f7613..5bc7c523eb0fe9c11a355d760862a5788f90eba1 100644 (file)
@@ -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();