]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
more cleanup:
[lyx.git] / src / insets / insettabular.C
index 18ad8575301eee95e0b103b3a7058ff4804d45c6..849bf95079b7966784bcc9eb737913a072acdc6f 100644 (file)
@@ -40,7 +40,6 @@
 #include "frontends/Clipboard.h"
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
-#include "frontends/nullpainter.h"
 
 #include <sstream>
 #include <iostream>
@@ -247,7 +246,7 @@ void InsetTabular::read(Buffer const & buf, LyXLex & lex)
 }
 
 
-void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
        //      mi.base.textwidth << "\n";
@@ -301,7 +300,9 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = tabular.getAscentOfRow(0);
        dim.des = tabular.getHeightOfTabular() - dim.asc;
        dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
+       bool const changed = dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
@@ -312,9 +313,6 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
        //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
        BufferView * bv = pi.base.bv;
 
-       static frontend::NullPainter nop;
-       static PainterInfo nullpi(bv, nop);
-
        resetPos(bv->cursor());
 
        x += scx_;
@@ -338,8 +336,10 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
                            || nx > bv->workWidth()
                            || y + d < 0
                            || y - a > bv->workHeight()) {
-                               cell(idx)->draw(nullpi, cx, y);
-                               drawCellLines(nop, nx, y, i, idx, pi.erased_);
+                               pi.pain.setDrawingEnabled(false);
+                               cell(idx)->draw(pi, cx, y);
+                               drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
+                               pi.pain.setDrawingEnabled(true);
                        } else {
                                cell(idx)->draw(pi, cx, y);
                                drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
@@ -495,12 +495,12 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_PRESS:
                //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
 
-               if (cmd.button() == mouse_button::button1
-                   || cmd.button() == mouse_button::button3) {
+               if (cmd.button() == mouse_button::button1 
+                   || (cmd.button() == mouse_button::button3 
+                       && (&bvcur.selBegin().inset() != this || !tablemode(bvcur)))) {
                        cur.selection() = false;
                        setCursorFromCoordinates(cur, cmd.x, cmd.y);
-                       cur.resetAnchor();
-                       bvcur = cur;
+                       cur.bv().mouseSetCursor(cur);
                        break;
                }
 
@@ -575,7 +575,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                                cur.idx() = tabular.getCellBelow(cur.idx());
                                cur.pit() = 0;
                                cur.pos() = cell(cur.idx())->getText(0)->x2pos(
-                                       cur.pit(), 0, cur.targetX());
+                                       cur.bv(), cur.pit(), 0, cur.targetX());
                        }
                if (sl == cur.top()) {
                        // we trick it to go to the RIGHT after leaving the
@@ -598,6 +598,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                                cur.pit() = cur.lastpit();
                                LyXText const * text = cell(cur.idx())->getText(0);
                                cur.pos() = text->x2pos(
+                                       cur.bv(),
                                        cur.pit(),
                                        text->paragraphs().back().rows().size()-1,
                                        cur.targetX());
@@ -659,7 +660,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
        // insert file functions
        case LFUN_FILE_INSERT_ASCII_PARA:
        case LFUN_FILE_INSERT_ASCII: {
-               // FIXME: We don't know the encoding of filenames
+               // FIXME UNICODE
                string const tmpstr = getContentsOfAsciiFile(&cur.bv(), to_utf8(cmd.argument()), false);
                // FIXME: We don't know the encoding of the file
                if (!tmpstr.empty() && !insertAsciiString(cur.bv(), from_utf8(tmpstr), false))
@@ -1940,6 +1941,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
        if (buf.length() <= 0)
                return true;
 
+       Buffer const & buffer = *bv.buffer();
+
        col_type cols = 1;
        row_type rows = 1;
        col_type maxCols = 1;
@@ -1968,7 +1971,7 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
        row_type row = 0;
        if (usePaste) {
                paste_tabular.reset(
-                       new LyXTabular(bv.buffer()->params(), rows, maxCols));
+                       new LyXTabular(buffer.params(), rows, maxCols));
                loctab = paste_tabular.get();
                cols = 0;
                dirtyTabularStack(true);
@@ -1996,11 +1999,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                shared_ptr<InsetText> inset = loctab->getCellInset(cell);
-                               inset->setViewCache(&bv);
                                Paragraph & par = inset->text_.getPar(0);
-                               LyXFont const font = inset->text_.getFont(par, 0);
+                               LyXFont const font = inset->text_.getFont(buffer, par, 0);
                                inset->setText(buf.substr(op, p - op), font,
-                                              bv.buffer()->params().trackChanges);
+                                              buffer.params().trackChanges);
                                ++cols;
                                ++cell;
                        }
@@ -2009,11 +2011,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
                        // we can only set this if we are not too far right
                        if (cols < columns) {
                                shared_ptr<InsetText> inset = tabular.getCellInset(cell);
-                               inset->setViewCache(&bv);
                                Paragraph & par = inset->text_.getPar(0);
-                               LyXFont const font = inset->text_.getFont(par, 0);
+                               LyXFont const font = inset->text_.getFont(buffer, par, 0);
                                inset->setText(buf.substr(op, p - op), font,
-                                              bv.buffer()->params().trackChanges);
+                                              buffer.params().trackChanges);
                        }
                        cols = ocol;
                        ++row;
@@ -2027,11 +2028,10 @@ bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
        // check for the last cell if there is no trailing '\n'
        if (cell < cells && op < len) {
                shared_ptr<InsetText> inset = loctab->getCellInset(cell);
-               inset->setViewCache(&bv);
                Paragraph & par = inset->text_.getPar(0);
-               LyXFont const font = inset->text_.getFont(par, 0);
+               LyXFont const font = inset->text_.getFont(buffer, par, 0);
                inset->setText(buf.substr(op, len - op), font,
-                              bv.buffer()->params().trackChanges);
+                       buffer.params().trackChanges);
        }
        return true;
 }