]> git.lyx.org Git - features.git/commitdiff
Transfer x2pos() and pos2x from LyXText to TextMetrics.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 1 Jan 2007 11:36:30 +0000 (11:36 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 1 Jan 2007 11:36:30 +0000 (11:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16458 a592a061-630c-0410-9148-cb99ea01b6c8

src/TextMetrics.C
src/TextMetrics.h
src/insets/insettabular.C
src/lyxtext.h
src/text.C
src/text2.C

index 7cc99b09050fa10834b224c6830fdf204b6f1b43..9b9876d3b79127e3483e016e4262d7e9a6eac269 100644 (file)
@@ -919,6 +919,26 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
 }
 
 
+pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
+{
+       ParagraphMetrics const & pm = parMetrics(pit);
+       BOOST_ASSERT(!pm.rows().empty());
+       BOOST_ASSERT(row < int(pm.rows().size()));
+       bool bound = false;
+       Row const & r = pm.rows()[row];
+       return r.pos() + getColumnNearX(pit, r, x, bound);
+}
+
+
+//int LyXText::pos2x(pit_type pit, pos_type pos) const
+//{
+//     ParagraphMetrics const & pm = parMetrics(pit);
+//     Row const & r = pm.rows()[row];
+//     int x = 0;
+//     pos -= r.pos();
+//}
+
+
 int defaultRowHeight()
 {
        return int(theFontMetrics(LyXFont(LyXFont::ALL_SANE)).maxHeight() *  1.2);
index 4af380ebe524df3509a4e10d9cf73bad56fc4675..77fc11a4b76a2946469e09daa72f6e5163876edf 100644 (file)
@@ -97,6 +97,13 @@ public:
        /// of this column.
        pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
                bool & boundary) const;
+
+       /// returns pos in given par at given x coord.
+       pos_type x2pos(pit_type pit, int row, int x) const;
+       
+       // FIXME: is there a need for this?
+       //int pos2x(pit_type pit, pos_type pos) const;
+
 private:
 
        /// The BufferView owner.
index a7b76c62aaa370f4904f8c2aad81734da6e8153d..04ff0940fe6a5cbaa67eb65dfee87e44883f7a54 100644 (file)
@@ -580,8 +580,9 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
                                cur.idx() = tabular.getCellBelow(cur.idx());
                                cur.pit() = 0;
-                               cur.pos() = cell(cur.idx())->getText(0)->x2pos(
-                                       cur.bv(), cur.pit(), 0, cur.targetX());
+                               TextMetrics const & tm =
+                                       cur.bv().textMetrics(cell(cur.idx())->getText(0));
+                               cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
                        }
                if (sl == cur.top()) {
                        // we trick it to go to the RIGHT after leaving the
@@ -603,13 +604,10 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                                cur.idx() = tabular.getCellAbove(cur.idx());
                                cur.pit() = cur.lastpit();
                                LyXText const * text = cell(cur.idx())->getText(0);
+                               TextMetrics const & tm = cur.bv().textMetrics(text);
                                ParagraphMetrics const & pm =
-                                       cur.bv().parMetrics(text, cur.lastpit());
-                               cur.pos() = text->x2pos(
-                                       cur.bv(),
-                                       cur.pit(),
-                                       pm.rows().size()-1,
-                                       cur.targetX());
+                                       tm.parMetrics(cur.lastpit());
+                               cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
                        }
                if (sl == cur.top()) {
                        cmd = FuncRequest(LFUN_FINISHED_UP);
index cfa42e1d94d20a3ff01e1fe5bad51860d4cdd64f..feb0b273ff1ceb2e10074984e29461e772862bf6 100644 (file)
@@ -94,11 +94,6 @@ public:
        /// FIXME: replace LCursor with DocIterator.
        void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
 
-       /// returns pos in given par at given x coord.
-       /// FIXME: move to TextMetrics.
-       pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const;
-       int pos2x(pit_type pit, pos_type pos) const;
-
        ///
        void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
 
index 2ed8a3ca8589c71b18cfe4110e9f48ae7ad7c177..73f3c27148915402427c6c3eb7b8a3dbdee4622f 100644 (file)
@@ -1661,45 +1661,6 @@ docstring LyXText::getPossibleLabel(LCursor & cur) const
 }
 
 
-//pos_type LyXText::x2pos(pit_type pit, int row, int x) const
-//{
-//     int lastx = 0;
-//     int currx = 0;
-//     Paragraph const & par = pars_[pit];
-//     Row const & r = par.rows()[row];
-//     int pos = r.pos();
-//     for (; currx < x && pos < r.endpos(); ++pos) {
-//             lastx = currx;
-//             currx += singleWidth(buffer, par, pos);
-//     }
-//     if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
-//             --pos;
-//     return pos;
-//}
-
-
-pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row,
-               int x) const
-{
-       TextMetrics const & tm = bv.textMetrics(this);
-       ParagraphMetrics const & pm = tm.parMetrics(pit);
-       BOOST_ASSERT(!pm.rows().empty());
-       BOOST_ASSERT(row < int(pm.rows().size()));
-       bool bound = false;
-       Row const & r = pm.rows()[row];
-       return r.pos() + tm.getColumnNearX(pit, r, x, bound);
-}
-
-
-//int LyXText::pos2x(pit_type pit, pos_type pos) const
-//{
-//     Paragraph const & par = pars_[pit];
-//     Row const & r = par.rows()[row];
-//     int x = 0;
-//     pos -= r.pos();
-//}
-
-
 void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 {
        BOOST_ASSERT(this == cur.text());
index e47be66fd66377981502f4e7099b872c88927773..4f919f66383de4a71c2e90a44184124bf232867d 100644 (file)
@@ -981,7 +981,8 @@ bool LyXText::cursorUp(LCursor & cur)
        // Tell BufferView to test for FitCursor in any case!
        cur.updateFlags(Update::FitCursor);
 
-       ParagraphMetrics const & pm = cur.bv().parMetrics(this, cur.pit());
+       TextMetrics const & tm = cur.bv().textMetrics(this);
+       ParagraphMetrics const & pm = tm.parMetrics(cur.pit());
 
        int row;
        int const x = cur.targetX();
@@ -1015,13 +1016,13 @@ bool LyXText::cursorUp(LCursor & cur)
 
        if (row > 0) {
                updateNeeded |= setCursor(cur, cur.pit(),
-                       x2pos(cur.bv(), cur.pit(), row - 1, x));
+                       tm.x2pos(cur.pit(), row - 1, x));
        } else if (cur.pit() > 0) {
                --cur.pit();
                //cannot use 'par' now
                ParagraphMetrics const & pmcur = cur.bv().parMetrics(this, cur.pit());
                updateNeeded |= setCursor(cur, cur.pit(),
-                       x2pos(cur.bv(), cur.pit(), pmcur.rows().size() - 1, x));
+                       tm.x2pos(cur.pit(), pmcur.rows().size() - 1, x));
        }
 
        cur.x_target() = x;
@@ -1035,7 +1036,8 @@ bool LyXText::cursorDown(LCursor & cur)
        // Tell BufferView to test for FitCursor in any case!
        cur.updateFlags(Update::FitCursor);
 
-       ParagraphMetrics const & pm = cur.bv().parMetrics(this, cur.pit());
+       TextMetrics const & tm = cur.bv().textMetrics(this);
+       ParagraphMetrics const & pm = tm.parMetrics(cur.pit());
 
        int row;
        int const x = cur.targetX();
@@ -1074,11 +1076,11 @@ bool LyXText::cursorDown(LCursor & cur)
 
        if (row + 1 < int(pm.rows().size())) {
                updateNeeded |= setCursor(cur, cur.pit(),
-                       x2pos(cur.bv(), cur.pit(), row + 1, x));
+                       tm.x2pos(cur.pit(), row + 1, x));
        } else if (cur.pit() + 1 < int(paragraphs().size())) {
                ++cur.pit();
                updateNeeded |= setCursor(cur, cur.pit(),
-                       x2pos(cur.bv(), cur.pit(), 0, x));
+                       tm.x2pos(cur.pit(), 0, x));
        }
 
        cur.x_target() = x;