]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
The markDirty() and fitCursor() changes
[lyx.git] / src / insets / insettabular.C
index edfdcfad6ef0cfadff852b0ae71dbe62232aca8a..c48a62b75f5a12c308ef24102b077e2fb447177d 100644 (file)
@@ -261,20 +261,12 @@ int InsetTabular::width(BufferView *, LyXFont const &) const
 
 
 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
-                       float & x, bool cleared) const
+                       float & x) const
 {
        if (nodraw()) {
-               if (cleared)
-                       need_update = FULL;
-               return;
-       }
-#if 0
-       if (need_update == INIT) {
-               if (calculate_dimensions_of_cells(bv, font, true))
-                       bv->text->status = LyXText::CHANGED_IN_DRAW;
                need_update = FULL;
+               return;
        }
-#endif
 
        Painter & pain = bv->painter();
        int i;
@@ -282,173 +274,53 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
        int nx;
 
 #if 0
-       UpdatableInset::draw(bv, font, baseline, x, cleared);
+       UpdatableInset::draw(bv, font, baseline, x);
 #else
        if (!owner())
                x += static_cast<float>(scroll());
 #endif
-       if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
-                        (top_x != int(x)) || (top_baseline != baseline)))
-       {
-               int h = ascent(bv, font) + descent(bv, font);
-               int const tx = display() || !owner() ? 0 : top_x;
-               int w =  tx ? width(bv, font) : pain.paperWidth();
-               int ty = baseline - ascent(bv, font);
-
-               if (ty < 0)
-                       ty = 0;
-               if ((ty + h) > pain.paperHeight())
-                       h = pain.paperHeight();
-               if ((top_x + w) > pain.paperWidth())
-                       w = pain.paperWidth();
-               pain.fillRectangle(tx, ty, w, h, backgroundColor());
-               need_update = FULL;
-               cleared = true;
-       }
+
        top_x = int(x);
        topx_set = true;
        top_baseline = baseline;
        x += ADD_TO_TABULAR_WIDTH;
-       if (cleared) {
-               int cell = 0;
-               float cx;
-               first_visible_cell = -1;
-               for (i = 0; i < tabular->rows(); ++i) {
-                       nx = int(x);
-                       cell = tabular->GetCellNumber(i, 0);
-                       if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
-                               (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
-                       {
-                               baseline += tabular->GetDescentOfRow(i) +
-                                       tabular->GetAscentOfRow(i + 1) +
-                                       tabular->GetAdditionalHeight(i + 1);
-                               continue;
-                       }
-                       for (j = 0; j < tabular->columns(); ++j) {
-                               if (nx > bv->workWidth())
-                                       break;
-                               if (tabular->IsPartOfMultiColumn(i, j))
-                                       continue;
-                               cx = nx + tabular->GetBeginningOfTextInCell(cell);
-                               if (first_visible_cell < 0)
-                                       first_visible_cell = cell;
-                               if (hasSelection()) {
-                                       drawCellSelection(pain, nx, baseline, i, j, cell);
-                               }
 
-                               tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
-                               drawCellLines(pain, nx, baseline, i, cell);
-                               nx += tabular->GetWidthOfColumn(cell);
-                               ++cell;
-                       }
-                       baseline += tabular->GetDescentOfRow(i) +
+       int cell = 0;
+       float cx;
+       first_visible_cell = -1;
+       for (i = 0; i < tabular->rows(); ++i) {
+               nx = int(x);
+               cell = tabular->GetCellNumber(i, 0);
+               if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
+                       (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
+               {
+               baseline += tabular->GetDescentOfRow(i) +
                                tabular->GetAscentOfRow(i + 1) +
                                tabular->GetAdditionalHeight(i + 1);
+                       continue;
                }
-       } else if (need_update == CELL) {
-               int cell = 0;
-               nx = int(x);
-               if (the_locking_inset &&
-                       tabular->GetCellInset(actcell) != the_locking_inset)
-               {
-                       Inset * inset = tabular->GetCellInset(cell);
-                       for (i = 0;
-                            inset != the_locking_inset && i < tabular->rows();
-                            ++i)
-                       {
-                               for (j = 0;
-                                    inset != the_locking_inset && j < tabular->columns();
-                                    ++j)
-                               {
-                                       if (tabular->IsPartOfMultiColumn(i, j))
-                                               continue;
-                                       nx += tabular->GetWidthOfColumn(cell);
-                                       ++cell;
-                                       inset = tabular->GetCellInset(cell);
-                               }
-                               if (tabular->row_of_cell(cell) > i) {
-                                       nx = int(x);
-                                       baseline += tabular->GetDescentOfRow(i) +
-                                               tabular->GetAscentOfRow(i + 1) +
-                                               tabular->GetAdditionalHeight(i + 1);
-                               }
-                       }
-               } else {
-                       // compute baseline for actual row
-                       for (i = 0; i < actrow; ++i) {
-                               baseline += tabular->GetDescentOfRow(i) +
-                                       tabular->GetAscentOfRow(i + 1) +
-                                       tabular->GetAdditionalHeight(i + 1);
-                       }
-                       // now compute the right x position
-                       cell = tabular->GetCellNumber(actrow, 0);
-                       for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
-                                       if (tabular->IsPartOfMultiColumn(actrow, j))
-                                               continue;
-                                       nx += tabular->GetWidthOfColumn(cell);
-                                       ++cell;
+               for (j = 0; j < tabular->columns(); ++j) {
+                       if (nx > bv->workWidth())
+                               break;
+                       if (tabular->IsPartOfMultiColumn(i, j))
+                               continue;
+                       cx = nx + tabular->GetBeginningOfTextInCell(cell);
+                       if (first_visible_cell < 0)
+                               first_visible_cell = cell;
+                       if (hasSelection()) {
+                               drawCellSelection(pain, nx, baseline, i, j, cell);
                        }
+
+                       tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
+                       drawCellLines(pain, nx, baseline, i, cell);
+                       nx += tabular->GetWidthOfColumn(cell);
+                       ++cell;
                }
-               i = tabular->row_of_cell(cell);
-               if (the_locking_inset != tabular->GetCellInset(cell)) {
-                       lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
-                       return;
-               }
-               float dx = nx + tabular->GetBeginningOfTextInCell(cell);
-               float cx = dx;
-               tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
-               //
-               // Here we use rectangular backgroundColor patches to clean up
-               // within a cell around the cell's red inset box. As follows:
-               //
-               //  +--------------------+
-               //  |         C          |   The rectangles are A, B and C
-               //  | A |------------| B |   below, origin top left (tx, ty),
-               //  |   |  inset box |   |   dimensions w(idth), h(eight).
-               //  +---+------------+---+   x grows rightward, y downward
-               //  |         D          |
-               //  +--------------------+
-               //
-#if 0
-               // clear only if we didn't have a change
-               if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
-#endif
-                       // clear before the inset
-                       int tx, ty, w, h;
-                       tx = nx + 1;
-                       ty = baseline - tabular->GetAscentOfRow(i) + 1;
-                       w = int(cx - nx - 1);
-                       h = tabular->GetAscentOfRow(i) +
-                               tabular->GetDescentOfRow(i) - 1;
-                       pain.fillRectangle(tx, ty, w, h, backgroundColor());
-                       // clear behind the inset
-                       tx = int(cx + the_locking_inset->width(bv,font) + 1);
-                       ty = baseline - tabular->GetAscentOfRow(i) + 1;
-                       w = tabular->GetWidthOfColumn(cell) -
-                               tabular->GetBeginningOfTextInCell(cell) -
-                               the_locking_inset->width(bv,font) -
-                               tabular->GetAdditionalWidth(cell) - 1;
-                       h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
-                       pain.fillRectangle(tx, ty, w, h, backgroundColor());
-                       // clear below the inset
-                       tx = nx + 1;
-                       ty = baseline + the_locking_inset->descent(bv, font) + 1;
-                       w = tabular->GetWidthOfColumn(cell) -
-                               tabular->GetAdditionalWidth(cell) - 1;
-                       h = tabular->GetDescentOfRow(i) -
-                               the_locking_inset->descent(bv, font) - 1;
-                       pain.fillRectangle(tx, ty, w, h, backgroundColor());
-                       // clear above the inset
-                       tx = nx + 1;
-                       ty = baseline - tabular->GetAscentOfRow(i) + 1;
-                       w = tabular->GetWidthOfColumn(cell) -
-                               tabular->GetAdditionalWidth(cell) - 1;
-                       h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
-                       pain.fillRectangle(tx, ty, w, h, backgroundColor());
-#if 0
-               }
-#endif
+               baseline += tabular->GetDescentOfRow(i) +
+                       tabular->GetAscentOfRow(i + 1) +
+                       tabular->GetAdditionalHeight(i + 1);
        }
+
        x -= ADD_TO_TABULAR_WIDTH;
        x += width(bv, font);
        if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
@@ -663,7 +535,7 @@ void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
                need_update = what;
        // Dirty Cast! (Lgb)
        if (need_update != NONE) {
-               bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
+               bv->updateInset(const_cast<InsetTabular *>(this));
                if (locked)
                        resetPos(bv);
        }
@@ -736,7 +608,7 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                if (inset->lyxCode() == TABULAR_CODE &&
                    !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
                        InsetTabularMailer mailer(*this);
-                       mailer.updateDialog();
+                       mailer.updateDialog(bv);
                        oldcell = actcell;
                }
                return true;
@@ -884,7 +756,7 @@ bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
        }
        if (cmd.button() == mouse_button::button3 && !ret) {
                InsetTabularMailer mailer(*this);
-               mailer.showDialog();
+               mailer.showDialog(cmd.view());
                return true;
        }
        return ret;
@@ -1170,12 +1042,12 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                break;
        case LFUN_LAYOUT_TABULAR: {
                InsetTabularMailer mailer(*this);
-               mailer.showDialog();
+               mailer.showDialog(bv);
                break;
        }
        case LFUN_INSET_DIALOG_UPDATE: {
                InsetTabularMailer mailer(*this);
-               mailer.updateDialog();
+               mailer.updateDialog(bv);
                break;
        }
        case LFUN_TABULAR_FEATURE:
@@ -1633,7 +1505,7 @@ void InsetTabular::resetPos(BufferView * bv) const
        } else if (the_locking_inset &&
                 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
        {
-               int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
+               int xx = cursor_.x() - offset + bv->text->getRealCursorX();
                if (xx > (bv->workWidth()-20)) {
                        scroll(bv, -(xx - bv->workWidth() + 60));
                        updateLocal(bv, FULL, false);
@@ -1667,7 +1539,7 @@ void InsetTabular::resetPos(BufferView * bv) const
            actcell != oldcell) {
                InsetTabular * inset = const_cast<InsetTabular *>(this);
                InsetTabularMailer mailer(*inset);
-               mailer.updateDialog();
+               mailer.updateDialog(bv);
                oldcell = actcell;
        }
        in_reset_pos = 0;
@@ -2354,7 +2226,7 @@ bool InsetTabular::showInsetDialog(BufferView * bv) const
        if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
                InsetTabular * tmp = const_cast<InsetTabular *>(this);
                InsetTabularMailer mailer(*tmp);
-               mailer.showDialog();
+               mailer.showDialog(bv);
        }
        return true;
 }
@@ -2372,7 +2244,7 @@ void InsetTabular::openLayoutDialog(BufferView * bv) const
        }
        InsetTabular * tmp = const_cast<InsetTabular *>(this);
        InsetTabularMailer mailer(*tmp);
-       mailer.showDialog();
+       mailer.showDialog(bv);
 }
 
 
@@ -2674,12 +2546,6 @@ int InsetTabular::scroll(bool recursive) const
 }
 
 
-bool InsetTabular::doClearArea() const
-{
-       return !locked || (need_update & (FULL|INIT));
-}
-
-
 void InsetTabular::getSelection(int & srow, int & erow,
                                int & scol, int & ecol) const
 {
@@ -3070,7 +2936,7 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
        if (lex.isOK()) {
                lex.next();
                string const token = lex.getString();
-               if (token != "active_cell")
+               if (token != "\\active_cell")
                        return -1;
                lex.next();
                cell = lex.getInteger();
@@ -3085,6 +2951,9 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
                        return -1;
        }
 
+       if (!lex.isOK())
+               return -1;
+
        BufferView * const bv = inset.view();
        Buffer const * const buffer = bv ? bv->buffer() : 0;
        if (buffer)
@@ -3105,7 +2974,7 @@ InsetTabularMailer::params2string(InsetTabular const & inset)
                return string();
 
        ostringstream data;
-       data << name_ << " active_cell " << inset.getActCell() << '\n';
+       data << name_ << " \\active_cell " << inset.getActCell() << '\n';
        inset.write(buffer, data);
        data << "\\end_inset\n";