]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
replace nextToken by more appropriate lex methods.
[lyx.git] / src / insets / insettabular.C
index 09c47927ecc00e97dc7922b90148de367fc21a16..fd5c283bf5ec97c75b41791d0ca0e9d53f7248d0 100644 (file)
@@ -204,10 +204,10 @@ void InsetTabular::read(Buffer const & buf, LyXLex & lex)
        if (old_format)
                return;
 
-       lex.nextToken();
+       lex.next();
        string token = lex.getString();
        while (lex.isOK() && (token != "\\end_inset")) {
-               lex.nextToken();
+               lex.next();
                token = lex.getString();
        }
        if (token != "\\end_inset") {
@@ -235,8 +235,10 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        ++cell;
                        Dimension dim;
                        MetricsInfo m = mi;
-                       m.base.textwidth =
-                               tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
+                       LyXLength p_width = tabular.column_info[j].p_width;
+                       if (!p_width.zero()) {
+                               m.base.textwidth = p_width.inPixels(mi.base.textwidth);
+                       }
                        tabular.getCellInset(cell).metrics(m, dim);
                        maxAsc  = max(maxAsc, dim.asc);
                        maxDesc = max(maxDesc, dim.des);
@@ -268,12 +270,11 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
        for (int i = 0; i < tabular.rows(); ++i) {
                int nx = x;
                idx = tabular.getCellNumber(i, 0);
-               if (y + tabular.getDescentOfRow(i) <= 0 &&
-                         y - tabular.getAscentOfRow(i) < pi.pain.paperHeight())
-               {
-                       y += tabular.getDescentOfRow(i) +
-                                       tabular.getAscentOfRow(i + 1) +
-                                       tabular.getAdditionalHeight(i + 1);
+               if (y + tabular.getDescentOfRow(i) <= 0
+                   && y - tabular.getAscentOfRow(i) < pi.pain.paperHeight()) {
+                       y += tabular.getDescentOfRow(i)
+                               + tabular.getAscentOfRow(i + 1)
+                               + tabular.getAdditionalHeight(i + 1);
                        continue;
                }
                for (int j = 0; j < tabular.columns(); ++j) {
@@ -375,6 +376,7 @@ void InsetTabular::edit(LCursor & cur, bool left)
        lyxerr << "InsetTabular::edit: " << this << endl;
        finishUndo();
        int cell;
+       cur.push(*this);
        if (left) {
                if (isRightToLeft(cur))
                        cell = tabular.getLastCellInRow(0);
@@ -390,7 +392,6 @@ void InsetTabular::edit(LCursor & cur, bool left)
        // this accesses the position cache before it is initialized
        //resetPos(cur);
        //cur.bv().fitCursor();
-       cur.push(*this);
        cur.idx() = cell;
 }
 
@@ -435,11 +436,12 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_MOUSE_MOTION:
                lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
-               if (cmd.button() != mouse_button::button1) {
+               if (cmd.button() == mouse_button::button1) {
                        // only accept motions to places not deeper nested than the real anchor
                        if (bvcur.anchor_.hasPart(cur)) {
                                setPos(cur, cmd.x, cmd.y);
                                bvcur.setCursor(cur);
+                               bvcur.selection() = true;
                        }
                }
                break;
@@ -890,7 +892,7 @@ int InsetTabular::latex(Buffer const & buf, ostream & os,
 int InsetTabular::plaintext(Buffer const & buf, ostream & os,
                        OutputParams const & runparams) const
 {
-       int dp = runparams.linelen ? ownerPar(buf, this).params().depth() : 0;
+       int dp = runparams.linelen ? runparams.depth : 0;
        return tabular.plaintext(buf, os, runparams, dp, false, 0);
 }
 
@@ -962,6 +964,7 @@ void InsetTabular::getCursorPos(LCursor const & cur, int & x, int & y) const
 
 InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
 {
+       lyxerr << "# InsetTabular::setPos()  x=" << x << " y=" << y << endl;
        int idx_min = 0;
        int dist_min = 1000000;
        for (idx_type i = 0; i < nargs(); ++i) {
@@ -1559,9 +1562,13 @@ void InsetTabular::cutSelection(LCursor & cur)
 }
 
 
-bool InsetTabular::isRightToLeft(LCursor & cur)
+bool InsetTabular::isRightToLeft(LCursor & cur) const
 {
-       return cur.bv().getParentLanguage(this)->RightToLeft();
+       BOOST_ASSERT(cur.size() > 1);
+       Paragraph const & parentpar = cur[cur.size() - 2].paragraph();
+       LCursor::pos_type const parentpos = cur[cur.size() - 2].pos();
+       return parentpar.getFontSettings(cur.bv().buffer()->params(),
+                                        parentpos).language()->RightToLeft();
 }
 
 
@@ -1690,7 +1697,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                InsetText & inset = loctab->getCellInset(cell);
-                               LyXFont const font = inset.text_.getFont(0, 0);
+                               Paragraph & par = inset.text_.getPar(0);
+                               LyXFont const font = inset.text_.getFont(par, 0);
                                inset.setText(buf.substr(op, p - op), font);
                                ++cols;
                                ++cell;
@@ -1700,7 +1708,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                InsetText & inset = tabular.getCellInset(cell);
-                               LyXFont const font = inset.text_.getFont(0, 0);
+                               Paragraph & par = inset.text_.getPar(0);
+                               LyXFont const font = inset.text_.getFont(par, 0);
                                inset.setText(buf.substr(op, p - op), font);
                        }
                        cols = ocol;
@@ -1715,7 +1724,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
        // check for the last cell if there is no trailing '\n'
        if (cell < cells && op < len) {
                InsetText & inset = loctab->getCellInset(cell);
-               LyXFont const font = inset.text_.getFont(0, 0);
+               Paragraph & par = inset.text_.getPar(0);
+               LyXFont const font = inset.text_.getFont(par, 0);
                inset.setText(buf.substr(op, len - op), font);
        }
        return true;