From: Jean-Marc Lasgouttes Date: Tue, 6 Dec 2016 08:48:49 +0000 (+0100) Subject: Now Inset::dimension is only an access to cache X-Git-Tag: 2.3.0alpha1~659 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8aaec85c8cc43d2317b684b0977eb47dd686af96;p=features.git 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. --- diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 463d0f24b8..d017db0cae 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 3398a9df31..e0418dc439 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; @@ -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; /// diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 38c744efd1..7a4c99952d 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 8260ab3ed6..ba7a945339 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 0d7a41b0fb..bf3cab5c3b 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 73ce540169..46e017f99b 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 8285045ec5..f518297445 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 8fb9d949c7..78bc55ed82 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 1c3689f627..3c1bb23f20 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 be4767f159..5bc7c523eb 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();