]> git.lyx.org Git - lyx.git/commitdiff
cosmetics
authorAndré Pönitz <poenitz@gmx.net>
Sat, 29 Sep 2007 09:22:17 +0000 (09:22 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 29 Sep 2007 09:22:17 +0000 (09:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20578 a592a061-630c-0410-9148-cb99ea01b6c8

src/Biblio_typedefs.h [deleted file]
src/BufferView.cpp
src/BufferView.h
src/Cursor.cpp
src/TextMetrics.cpp
src/bufferview_funcs.cpp
src/bufferview_funcs.h

diff --git a/src/Biblio_typedefs.h b/src/Biblio_typedefs.h
deleted file mode 100644 (file)
index e69de29..0000000
index 9793597cde779def9e924d4d4c651c53e22fe7c0..695950fe82eb3fb9c9a552840f037a5c180977f2 100644 (file)
@@ -257,7 +257,7 @@ bool BufferView::fitCursor()
                        theFontMetrics(cursor_.getFont());
                int const asc = fm.maxAscent();
                int const des = fm.maxDescent();
-               Point const p = bv_funcs::getPos(*this, cursor_, cursor_.boundary());
+               Point const p = getPos(cursor_, cursor_.boundary());
                if (p.y_ - asc >= 0 && p.y_ + des < height_)
                        return false;
        }
@@ -462,7 +462,7 @@ void BufferView::setCursorFromScrollbar()
                cur.clearSelection();
                break;
        case CUR_INSIDE:
-               int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_;
+               int const y = getPos(cur, cur.boundary()).y_;
                int const newy = min(last, max(y, first));
                if (y != newy) {
                        cur.reset(buffer_.inset());
@@ -486,7 +486,7 @@ Change const BufferView::getCurrentChange() const
 // FIXME: This does not work within mathed!
 CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
 {
-       Point const p = bv_funcs::getPos(*this, dit, dit.boundary());
+       Point const p = getPos(dit, dit.boundary());
        if (p.y_ < 0)
                return CUR_ABOVE;
        if (p.y_ > workHeight())
@@ -608,8 +608,8 @@ void BufferView::updateOffsetRef()
        CursorSlice & bot = cursor_.bottom();
        TextMetrics & tm = text_metrics_[bot.text()];
        ParagraphMetrics const & pm = tm.parMetrics(bot.pit());
-       Point p = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary());
-       offset_ref_ = p.y_ + pm.ascent() - height_ / 2;
+       int y = coordOffset(cursor_, cursor_.boundary()).y_;
+       offset_ref_ = y + pm.ascent() - height_ / 2;
 
        need_centering_ = false;
 }
@@ -1055,7 +1055,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_DOWN: {
-               Point p = bv_funcs::getPos(*this, cur, cur.boundary());
+               Point p = getPos(cur, cur.boundary());
                if (p.y_ < 0 || p.y_ > height_) {
                        // The cursor is off-screen so recenter before proceeding.
                        center();
@@ -1063,7 +1063,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                        //FIXME: updateMetrics() does not update paragraph position
                        // This is done at draw() time. So we need a redraw!
                        buffer_.changed();
-                       p = bv_funcs::getPos(*this, cur, cur.boundary());
+                       p = getPos(cur, cur.boundary());
                }
                scroll(cmd.action == LFUN_SCREEN_UP? - height_ : height_);
                cur.reset(buffer_.inset());
@@ -1079,7 +1079,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
        case LFUN_SCREEN_DOWN_SELECT: {
                cur.selHandle(true);
                size_t initial_depth = cur.depth();
-               Point const p = bv_funcs::getPos(*this, cur, cur.boundary());
+               Point const p = getPos(cur, cur.boundary());
                scroll(cmd.action == LFUN_SCREEN_UP_SELECT? - height_ : height_);
                // FIXME: We need to verify if the cursor stayed within an inset...
                //cur.reset(buffer_.inset());
@@ -1702,6 +1702,109 @@ void BufferView::menuInsertLyXFile(string const & filenm)
 }
 
 
+Point BufferView::coordOffset(DocIterator const & dit, bool boundary) const
+{
+       int x = 0;
+       int y = 0;
+       int lastw = 0;
+
+       // Addup contribution of nested insets, from inside to outside,
+       // keeping the outer paragraph for a special handling below
+       for (size_t i = dit.depth() - 1; i >= 1; --i) {
+               CursorSlice const & sl = dit[i];
+               int xx = 0;
+               int yy = 0;
+               
+               // get relative position inside sl.inset()
+               sl.inset().cursorPos(*this, sl, boundary && (i + 1 == dit.depth()), xx, yy);
+               
+               // Make relative position inside of the edited inset relative to sl.inset()
+               x += xx;
+               y += yy;
+               
+               // In case of an RTL inset, the edited inset will be positioned to the left
+               // of xx:yy
+               if (sl.text()) {
+                       bool boundary_i = boundary && i + 1 == dit.depth();
+                       bool rtl = textMetrics(sl.text()).isRTL(sl, boundary_i);
+                       if (rtl)
+                               x -= lastw;
+               }
+
+               // 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 = parMetrics(dit[i - 1].text(),
+                               dit[i - 1].pit()).insetDimension(&sl.inset());
+                       lastw = dim.wid;
+               } else {
+                       Dimension const dim = sl.inset().dimension(*this);
+                       lastw = dim.wid;
+               }
+               
+               //lyxerr << "Cursor::getPos, i: "
+               // << i << " x: " << xx << " y: " << y << endl;
+       }
+
+       // Add contribution of initial rows of outermost paragraph
+       CursorSlice const & sl = dit[0];
+       TextMetrics const & tm = textMetrics(sl.text());
+       ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
+       BOOST_ASSERT(!pm.rows().empty());
+       y -= pm.rows()[0].ascent();
+#if 1
+       // FIXME: document this mess
+       size_t rend;
+       if (sl.pos() > 0 && dit.depth() == 1) {
+               int pos = sl.pos();
+               if (pos && boundary)
+                       --pos;
+//             lyxerr << "coordOffset: boundary:" << boundary << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << std::endl;
+               rend = pm.pos2row(pos);
+       } else
+               rend = pm.pos2row(sl.pos());
+#else
+       size_t rend = pm.pos2row(sl.pos());
+#endif
+       for (size_t rit = 0; rit != rend; ++rit)
+               y += pm.rows()[rit].height();
+       y += pm.rows()[rend].ascent();
+       
+       TextMetrics const & bottom_tm = textMetrics(dit.bottom().text());
+       
+       // Make relative position from the nested inset now bufferview absolute.
+       int xx = bottom_tm.cursorX(dit.bottom(), boundary && dit.depth() == 1);
+       x += xx;
+       
+       // In the RTL case place the nested inset at the left of the cursor in 
+       // the outer paragraph
+       bool boundary_1 = boundary && 1 == dit.depth();
+       bool rtl = bottom_tm.isRTL(dit.bottom(), boundary_1);
+       if (rtl)
+               x -= lastw;
+       
+       return Point(x, y);
+}
+
+
+Point BufferView::getPos(DocIterator const & dit, bool boundary) const
+{
+       CursorSlice const & bot = dit.bottom();
+       TextMetrics const & tm = textMetrics(bot.text());
+       if (!tm.has(bot.pit()))
+               return Point(-1, -1);
+
+       Point p = coordOffset(dit, boundary); // offset from outer paragraph
+       p.y_ += tm.parMetrics(bot.pit()).position();
+       return p;
+}
+
+
 void BufferView::draw(frontend::Painter & pain)
 {
        PainterInfo pi(this, pain);
index 234d86a8169461b16c4143eb9653c963d409dc1c..af7cbf8f80e19b924644273b24d95974f207ee86 100644 (file)
@@ -222,6 +222,10 @@ public:
        ///
        CoordCache const & coordCache() const { return coord_cache_; }
 
+       ///
+       Point getPos(DocIterator const & dit, bool boundary) const;
+
+
        ///
        void draw(frontend::Painter & pain);
 
@@ -253,6 +257,8 @@ public:
        boost::signal<void(docstring layout)> layoutChanged;
 
 private:
+       // the position relative to (0, baseline) of outermost paragraph
+       Point coordOffset(DocIterator const & dit, bool boundary) const;
        /// Update current paragraph metrics.
        /// \return true if no further update is needed.
        bool singleParUpdate();
index b5712f8816edd6c81bfcefd01f379ce440cb7744..1f1ed772667cd8f4e32dc355836c5225a507f34f 100644 (file)
@@ -162,7 +162,7 @@ namespace {
                for ( ; it != et; it.forwardPos(true)) {
                        // avoid invalid nesting when selecting
                        if (!cursor.selection() || positionable(it, cursor.anchor_)) {
-                               Point p = bv_funcs::getPos(bv, it, false);
+                               Point p = bv.getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
                                if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -220,7 +220,7 @@ namespace {
                        // avoid invalid nesting when selecting
                        if (bv.cursorStatus(it) == CUR_INSIDE
                            && (!cur.selection() || positionable(it, cur.anchor_))) {
-                               Point p = bv_funcs::getPos(bv, it, false);
+                               Point p = bv.getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
                                if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -419,7 +419,7 @@ int Cursor::currentMode()
 
 void Cursor::getPos(int & x, int & y) const
 {
-       Point p = bv_funcs::getPos(bv(), *this, boundary());
+       Point p = bv().getPos(*this, boundary());
        x = p.x_;
        y = p.y_;
 }
@@ -1235,7 +1235,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 
        // with and without selection are handled differently
        if (!selection()) {
-               int yo = bv_funcs::getPos(bv(), *this, boundary()).y_;
+               int yo = bv().getPos(*this, boundary()).y_;
                Cursor old = *this;
                // To next/previous row
                if (up)
index a5f9cdba16fb6c0fc9f31321d3a99af8682b12c6..24038913929ec2cd756831201450857aab5619d3 100644 (file)
@@ -1999,7 +1999,7 @@ void TextMetrics::drawSelection(PainterInfo & pi,
        if (clipAbove)
                middleTop = 0;
        else
-               middleTop = bv_funcs::getPos(*bv_, beg, beg.boundary()).y_ + row1.descent();
+               middleTop = bv_->getPos(beg, beg.boundary()).y_ + row1.descent();
        
        // clip below
        int middleBottom;
@@ -2007,7 +2007,7 @@ void TextMetrics::drawSelection(PainterInfo & pi,
        if (clipBelow)
                middleBottom = bv_->workHeight();
        else
-               middleBottom = bv_funcs::getPos(*bv_, end, end.boundary()).y_ - row2.ascent();
+               middleBottom = bv_->getPos(end, end.boundary()).y_ - row2.ascent();
 
        // start and end in the same line?
        if (!clipAbove && !clipBelow && &row1 == &row2)
@@ -2051,7 +2051,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
        DocIterator cur = beg;
        int x1 = cursorX(beg.top(), beg.boundary());
        int x2 = cursorX(end.top(), end.boundary());
-       int y1 = bv_funcs::getPos(*bv_, cur, cur.boundary()).y_ - row.ascent();
+       int y1 = bv_->getPos(cur, cur.boundary()).y_ - row.ascent();
        int y2 = y1 + row.height();
        
        // draw the margins
index ed8dbd90194dd462dc1d1c7f225f7650492671f0..3a3a45c8aabdb032d8bfb6b3a872022a61d6e42b 100644 (file)
@@ -147,112 +147,6 @@ bool string2font(string const & data, Font & font, bool & toggle)
 }
 
 
-// the next two should probably go elsewhere
-// this give the position relative to (0, baseline) of outermost
-// paragraph
-Point coordOffset(BufferView const & bv, DocIterator const & dit,
-               bool boundary)
-{
-       int x = 0;
-       int y = 0;
-       int lastw = 0;
-
-       // Addup contribution of nested insets, from inside to outside,
-       // keeping the outer paragraph for a special handling below
-       for (size_t i = dit.depth() - 1; i >= 1; --i) {
-               CursorSlice const & sl = dit[i];
-               int xx = 0;
-               int yy = 0;
-               
-               // get relative position inside sl.inset()
-               sl.inset().cursorPos(bv, sl, boundary && ((i+1) == dit.depth()), xx, yy);
-               
-               // Make relative position inside of the edited inset relative to sl.inset()
-               x += xx;
-               y += yy;
-               
-               // In case of an RTL inset, the edited inset will be positioned to the left
-               // of xx:yy
-               if (sl.text()) {
-                       bool boundary_i = boundary && i + 1 == dit.depth();
-                       bool rtl = bv.textMetrics(sl.text()).isRTL(sl, boundary_i);
-                       if (rtl)
-                               x -= lastw;
-               }
-
-               // 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 = bv.parMetrics(dit[i - 1].text(),
-                               dit[i - 1].pit()).insetDimension(&sl.inset());
-                       lastw = dim.wid;
-               } else {
-                       Dimension const dim = sl.inset().dimension(bv);
-                       lastw = dim.wid;
-               }
-               
-               //lyxerr << "Cursor::getPos, i: "
-               // << i << " x: " << xx << " y: " << y << endl;
-       }
-
-       // Add contribution of initial rows of outermost paragraph
-       CursorSlice const & sl = dit[0];
-       TextMetrics const & tm = bv.textMetrics(sl.text());
-       ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
-       BOOST_ASSERT(!pm.rows().empty());
-       y -= pm.rows()[0].ascent();
-#if 1
-       // FIXME: document this mess
-       size_t rend;
-       if (sl.pos() > 0 && dit.depth() == 1) {
-               int pos = sl.pos();
-               if (pos && boundary)
-                       --pos;
-//             lyxerr << "coordOffset: boundary:" << boundary << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << std::endl;
-               rend = pm.pos2row(pos);
-       } else
-               rend = pm.pos2row(sl.pos());
-#else
-       size_t rend = pm.pos2row(sl.pos());
-#endif
-       for (size_t rit = 0; rit != rend; ++rit)
-               y += pm.rows()[rit].height();
-       y += pm.rows()[rend].ascent();
-       
-       TextMetrics const & bottom_tm = bv.textMetrics(dit.bottom().text());
-       
-       // Make relative position from the nested inset now bufferview absolute.
-       int xx = bottom_tm.cursorX(dit.bottom(), boundary && dit.depth() == 1);
-       x += xx;
-       
-       // In the RTL case place the nested inset at the left of the cursor in 
-       // the outer paragraph
-       bool boundary_1 = boundary && 1 == dit.depth();
-       bool rtl = bottom_tm.isRTL(dit.bottom(), boundary_1);
-       if (rtl)
-               x -= lastw;
-       
-       return Point(x, y);
-}
-
-
-Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary)
-{
-       CursorSlice const & bot = dit.bottom();
-       TextMetrics const & tm = bv.textMetrics(bot.text());
-       if (!tm.has(bot.pit()))
-               return Point(-1, -1);
-
-       Point p = coordOffset(bv, dit, boundary); // offset from outer paragraph
-       p.y_ += tm.parMetrics(bot.pit()).position();
-       return p;
-}
-
 } // namespace bv_funcs
 
 
index 05dce330b3ebd03cb244b7dc4246265115f825aa..0f45b766cc443c07ccdbdeb17e39e6754e1fb480 100644 (file)
 
 namespace lyx {
 
-class Point;
-class BufferView;
-class DocIterator;
-class Inset_code;
 class Font;
 
 namespace bv_funcs {
@@ -37,10 +33,6 @@ bool string2font(std::string const & data, Font & font, bool & toggle);
  */
 std::string const freefont2string();
 
-Point getPos(BufferView const & bv, DocIterator const & dit, bool boundary);
-
-Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary);
-
 } // namespace bv_funcs