]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
More header file include dependency work
[lyx.git] / src / insets / insettabular.C
index e74786dcf9dd8a38464beb299981ee7e66bdde23..b15d80e5e43ae4fe8c53a4dcb5d67ddc1509048b 100644 (file)
@@ -39,6 +39,9 @@
 #include "gettext.h"
 #include "language.h"
 #include "BufferView.h"
+#include "undo_funcs.h"
+#include "support/LAssert.h"
+#include "support/lstrings.h"
 
 using std::ostream;
 using std::ifstream;
@@ -126,7 +129,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
                rows = 1;
        if (columns <= 0)
                columns = 1;
-       tabular.reset(new LyXTabular(this, rows,columns));
+       tabular.reset(new LyXTabular(this, rows, columns));
        // for now make it always display as display() inset
        // just for test!!!
        the_locking_inset = 0;
@@ -138,8 +141,9 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
 }
 
 
-InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
-       : buffer(&buf)
+InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
+                                                  bool same_id)
+       : UpdatableInset(tab, same_id), buffer(&buf)
 {
        tabular.reset(new LyXTabular(this, *(tab.tabular)));
        the_locking_inset = 0;
@@ -157,11 +161,9 @@ InsetTabular::~InsetTabular()
 }
 
 
-Inset * InsetTabular::clone(Buffer const & buf) const
+Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
 {
-       InsetTabular * t = new InsetTabular(*this, buf);
-       t->tabular.reset(tabular->clone(t));
-       return t;
+       return new InsetTabular(*this, buf, same_id);
 }
 
 
@@ -257,7 +259,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                        h = pain.paperHeight();
                if ((top_x + w) > pain.paperWidth())
                        w = pain.paperWidth();
-               pain.fillRectangle(tx, ty, w, h);
+               pain.fillRectangle(tx, ty, w, h, backgroundColor());
                need_update = FULL;
                cleared = true;
        }
@@ -306,7 +308,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                if (the_locking_inset &&
                        tabular->GetCellInset(actcell) != the_locking_inset)
                {
-#warning Jürgen, why is this?
                        Inset * inset = tabular->GetCellInset(cell);
                        for (i = 0;
                             inset != the_locking_inset && i < tabular->rows();
@@ -329,7 +330,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                }
                        }
                } else {
-                       // copute baseline for actual row
+                       // compute baseline for actual row
                        for (i = 0; i < actrow; ++i) {
                                baseline += tabular->GetDescentOfRow(i) +
                                        tabular->GetAscentOfRow(i + 1) +
@@ -365,7 +366,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                baseline - tabular->GetAscentOfRow(i) + 1,
                                int(cx - nx - 1),
                                tabular->GetAscentOfRow(i) +
-                               tabular->GetDescentOfRow(i) - 1);
+                               tabular->GetDescentOfRow(i) - 1,
+                               backgroundColor());
                        // clear behind the inset
                        pain.fillRectangle(
                                int(cx + the_locking_inset->width(bv,font) + 1),
@@ -375,12 +377,13 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                the_locking_inset->width(bv,font) -
                                tabular->GetAdditionalWidth(cell) - 1,
                                tabular->GetAscentOfRow(i) +
-                               tabular->GetDescentOfRow(i) - 1);
+                               tabular->GetDescentOfRow(i) - 1,
+                               backgroundColor());
                }
        }
        x -= ADD_TO_TABULAR_WIDTH;
        x += width(bv, font);
-       if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
+       if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
                int i = 0;
                for(Inset * inset=owner(); inset; ++i)
                        inset = inset->owner();
@@ -463,6 +466,11 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
        }
        if (the_locking_inset)
                the_locking_inset->update(bv, font, reinit);
+       if (need_update < FULL &&
+               bv->text->status() == LyXText::NEED_MORE_REFRESH)
+       {
+               need_update = FULL;
+       }
 
        switch (need_update) {
        case INIT:
@@ -500,12 +508,32 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
        inset_y = 0;
        setPos(bv, x, y);
        sel_cell_start = sel_cell_end = actcell;
-       bv->text->finishUndo();
+       finishUndo();
        if (insetHit(bv, x, y) && (button != 3)) {
                activateCellInsetAbs(bv, x, y, button);
        }
-//    UpdateLocal(bv, NONE, false);
-//    bv->getOwner()->getPopups().updateFormTabular();
+}
+
+
+void InsetTabular::edit(BufferView * bv, bool front)
+{
+       UpdatableInset::edit(bv, front);
+       
+       if (!bv->lockInset(this)) {
+               lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
+               return;
+       }
+       locked = true;
+       the_locking_inset = 0;
+       inset_x = 0;
+       inset_y = 0;
+       if (front)
+               actcell = 0;
+       else
+               actcell = tabular->GetNumberOfCells() - 1;
+       sel_cell_start = sel_cell_end = actcell;
+       resetPos(bv);
+       finishUndo();
 }
 
 
@@ -556,14 +584,14 @@ bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                lyxerr[Debug::INSETS] << "OK" << endl;
                the_locking_inset = tabular->GetCellInset(actcell);
                resetPos(bv);
-               inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
-               inset_y = cursor.y();
+               inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+               inset_y = cursor_.y();
                return true;
        } else if (the_locking_inset && (the_locking_inset == inset)) {
                lyxerr[Debug::INSETS] << "OK" << endl;
                resetPos(bv);
-               inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
-               inset_y = cursor.y();
+               inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+               inset_y = cursor_.y();
        } else if (the_locking_inset) {
                lyxerr[Debug::INSETS] << "MAYBE" << endl;
                return the_locking_inset->lockInsetInInset(bv, inset);
@@ -626,9 +654,10 @@ unsigned int InsetTabular::insetInInsetY()
 }
 
 
-UpdatableInset * InsetTabular::getLockingInset()
+UpdatableInset * InsetTabular::getLockingInset() const
 {
-       return the_locking_inset ? the_locking_inset->getLockingInset() : this;
+       return the_locking_inset ? the_locking_inset->getLockingInset() :
+               const_cast<InsetTabular *>(this);
 }
 
 
@@ -960,16 +989,16 @@ InsetTabular::localDispatch(BufferView * bv,
        case LFUN_CUT:
                if (!copySelection(bv))
                        break;
-               bv->text->setUndo(bv->buffer(), Undo::DELETE,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
+               setUndo(bv, Undo::DELETE,
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
                cutSelection();
                updateLocal(bv, INIT, true);
                break;
        case LFUN_COPY:
                if (!hasSelection())
                        break;
-               bv->text->finishUndo();
+               finishUndo();
                copySelection(bv);
                break;
        case LFUN_PASTESELECTION:
@@ -1040,9 +1069,9 @@ InsetTabular::localDispatch(BufferView * bv,
        }
        case LFUN_PASTE:
                if (hasPasteBuffer()) {
-                       bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                                         bv->text->cursor.par()->previous(),
-                                         bv->text->cursor.par()->next());
+                       setUndo(bv, Undo::INSERT,
+                               bv->text->cursor.par(),
+                               bv->text->cursor.par()->next());
                        pasteSelection(bv);
                        updateLocal(bv, INIT, true);
                        break;
@@ -1166,11 +1195,14 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
 }
 
 
-void InsetTabular::getCursorPos(BufferView *,
-                               int & x, int & y) const
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
 {
-       x = cursor.x() - top_x;
-       y = cursor.y();
+       if (the_locking_inset) {
+               the_locking_inset->getCursorPos(bv, x, y);
+               return;
+       }
+       x = cursor_.x() - top_x;
+       y = cursor_.y();
 }
 
 
@@ -1189,7 +1221,7 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
-               bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+               bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
        toggleCursorVisible();
 }
 
@@ -1201,9 +1233,9 @@ void InsetTabular::showInsetCursor(BufferView * bv, bool show)
        
                int const asc = lyxfont::maxAscent(font);
                int const desc = lyxfont::maxDescent(font);
-               bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+               bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
                if (show)
-                       bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+                       bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
                setCursorVisible(true);
        }
 }
@@ -1222,18 +1254,18 @@ void InsetTabular::hideInsetCursor(BufferView * bv)
 
 void InsetTabular::setPos(BufferView * bv, int x, int y) const
 {
-       cursor.y(0);
+       cursor_.y(0);
        
        actcell = actrow = actcol = 0;
        int ly = tabular->GetDescentOfRow(actrow);
 
        // first search the right row
        while((ly < y) && (actrow < tabular->rows())) {
-               cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+               cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
                                 tabular->GetAscentOfRow(actrow + 1) +
                                 tabular->GetAdditionalHeight(actrow + 1));
                ++actrow;
-               ly = cursor.y() + tabular->GetDescentOfRow(actrow);
+               ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
        }
        actcell = tabular->GetCellNumber(actrow, actcol);
 
@@ -1249,13 +1281,14 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
                     tabular->GetAdditionalWidth(actcell - 1));
 #else
        // Jürgen, you should check that this is correct. (Lgb)
+#warning Jürgen, please check. (Lgb)
        for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
                lx += tabular->GetWidthOfColumn(actcell + 1)
                        + tabular->GetAdditionalWidth(actcell);
        }
        
 #endif
-       cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
+       cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
        resetPos(bv);
 }
 
@@ -1282,10 +1315,10 @@ void InsetTabular::resetPos(BufferView * bv) const
 
        int cell = 0;
        actrow = 0;
-       cursor.y(0);
+       cursor_.y(0);
        for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
                if (tabular->IsLastCellInRow(cell)) {
-                       cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+                       cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
                                         tabular->GetAscentOfRow(actrow + 1) +
                                         tabular->GetAdditionalHeight(actrow + 1));
                        ++actrow;
@@ -1293,9 +1326,9 @@ void InsetTabular::resetPos(BufferView * bv) const
        }
        static int const offset = ADD_TO_TABULAR_WIDTH + 2;
        int new_x = getCellXPos(actcell);
-       int old_x = cursor.x();
+       int old_x = cursor_.x();
        new_x += offset;
-       cursor.x(new_x);
+       cursor_.x(new_x);
 //    cursor.x(getCellXPos(actcell) + offset);
        if ((actcol < tabular->columns()-1) && scroll(false) &&
                (tabular->GetWidthOfTabular() < bv->workWidth()-20))
@@ -1305,7 +1338,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(bv);
                if (xx > (bv->workWidth()-20)) {
                        scroll(bv, -(xx - bv->workWidth() + 60));
                        updateLocal(bv, FULL, false);
@@ -1317,17 +1350,17 @@ void InsetTabular::resetPos(BufferView * bv) const
                        scroll(bv, xx);
                        updateLocal(bv, FULL, false);
                }
-       } else if ((cursor.x() - offset) > 20 &&
-                  (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
+       } else if ((cursor_.x() - offset) > 20 &&
+                  (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
                   > (bv->workWidth() - 20)) {
                scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
                updateLocal(bv, FULL, false);
-       } else if ((cursor.x() - offset) < 20) {
-               scroll(bv, 20 - cursor.x() + offset);
+       } else if ((cursor_.x() - offset) < 20) {
+               scroll(bv, 20 - cursor_.x() + offset);
                updateLocal(bv, FULL, false);
        } else if (scroll(false) && top_x > 20 &&
                   (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
-               scroll(bv, old_x - cursor.x());
+               scroll(bv, old_x - cursor_.x());
                updateLocal(bv, FULL, false);
        }
        if ((!the_locking_inset ||
@@ -1384,7 +1417,7 @@ UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
                int y = 0;
                if (old_locking_inset) {
                        old_locking_inset->getCursorPos(bv, x, y);
-                       x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+                       x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
                }
                if (activateCellInset(bv, x, 0))
                        return DISPATCHED;
@@ -1405,7 +1438,7 @@ UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
                int y = 0;
                if (old_locking_inset) {
                        old_locking_inset->getCursorPos(bv, x, y);
-                       x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+                       x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
                }
                if (activateCellInset(bv, x, 0))
                        return DISPATCHED;
@@ -1434,7 +1467,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
                ++actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->par->
+               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, 0, !rtl);
        }
@@ -1463,7 +1496,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
                --actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->par->
+               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, 0, !rtl);
        }
@@ -1472,9 +1505,8 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
 }
 
 
-bool InsetTabular::Delete()
+bool InsetTabular::deletable()
 {
-#warning Is this func correctly named? Or should it be "deletable"?
        return true;
 }
 
@@ -1487,13 +1519,12 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                sel_cell_end = tabular->GetNumberOfCells() - 1;
        }
        if (hasSelection()) {
-               bool frozen;
-               bv->text->setUndo(bv->buffer(), Undo::EDIT,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
-               frozen = bv->text->undo_frozen;
+               setUndo(bv, Undo::EDIT,
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
+               bool frozen = undo_frozen;
                if (!frozen)
-                       bv->text->freezeUndo();
+                       freezeUndo();
                // apply the fontchange on the whole selection
                int sel_row_start;
                int sel_row_end;
@@ -1506,7 +1537,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                        }
                }
                if (!frozen)
-                       bv->text->unFreezeUndo();
+                       unFreezeUndo();
                updateLocal(bv, INIT, true);
        }
        if (the_locking_inset)
@@ -1585,9 +1616,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
                sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
        }
-       bv->text->setUndo(bv->buffer(), Undo::FINISH,
-                         bv->text->cursor.par()->previous(),
-                         bv->text->cursor.par()->next());
+       setUndo(bv, Undo::FINISH,
+               bv->text->cursor.par(),
+               bv->text->cursor.par()->next());
 
        int row = tabular->row_of_cell(actcell);
        int column = tabular->column_of_cell(actcell);
@@ -1876,9 +1907,9 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
                                        int button)
 {
-       inset_x = cursor.x()
+       inset_x = cursor_.x()
                - top_x + tabular->GetBeginningOfTextInCell(actcell);
-       inset_y = cursor.y();
+       inset_y = cursor_.y();
        return activateCellInset(bv, x - inset_x, y - inset_y, button);
 }
 
@@ -1886,7 +1917,7 @@ bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
 bool InsetTabular::insetHit(BufferView *, int x, int) const
 {
        return (x + top_x)
-               > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
+               > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
 }
 
 
@@ -1903,30 +1934,30 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 
 
 int InsetTabular::getMaxWidth(BufferView * bv,
-                             UpdatableInset const * inset) const
+                              UpdatableInset const * inset) const
 {
        int cell = tabular->cur_cell;
        if (tabular->GetCellInset(cell) != inset) {
-                       cell = actcell;
-                       if (tabular->GetCellInset(cell) != inset) {
-                                       lyxerr << "Actcell not equal to actual cell!" << std::endl;
-                                       //raise(SIGSTOP);
-                                       cell = -1;
-                       }
+               cell = actcell;
+               if (tabular->GetCellInset(cell) != inset) {
+                       
+                       lyxerr << "Actcell not equal to actual cell!\n";
+                       cell = -1;
+               }
        }
        
        int const n = tabular->GetNumberOfCells();
 
        if (cell == -1) {
-               cell = 0;
-               for (; cell < n; ++cell) {
+               for (cell = 0; cell < n; ++cell) {
                        if (tabular->GetCellInset(cell) == inset)
                                break;
                }
        }
        
        if (cell >= n) {
-                       return -1;
+               lyxerr << "Own inset not found, shouldn't really happen!\n";
+               return -1;
        }
        
        int w = getMaxWidthOfCell(bv, cell);
@@ -1959,10 +1990,19 @@ void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
 
 
 LyXText * InsetTabular::getLyXText(BufferView const * bv,
-                                  bool const recursive) const
+                                   bool const recursive) const
 {
        if (the_locking_inset)
                return the_locking_inset->getLyXText(bv, recursive);
+#if 0
+       // if we're locked lock the actual insettext and return it's LyXText!!!
+       if (locked) {
+               UpdatableInset * inset =
+                       static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+               inset->edit(const_cast<BufferView *>(bv), 0,  0, 0);
+               return the_locking_inset->getLyXText(bv, recursive);
+       }
+#endif
        return Inset::getLyXText(bv, recursive);
 }
 
@@ -1990,6 +2030,7 @@ void InsetTabular::openLayoutDialog(BufferView * bv) const
                const_cast<InsetTabular *>(this));
 }
 
+
 //
 // functions returns:
 // 0 ... disabled
@@ -2301,11 +2342,6 @@ bool InsetTabular::cutSelection()
        if (!hasSelection())
                return false;
 
-       //int sel_col_start;
-       //int sel_col_end;
-       //int sel_row_start;
-       //int sel_row_end;
-
        int sel_col_start = tabular->column_of_cell(sel_cell_start);
        int sel_col_end = tabular->column_of_cell(sel_cell_end);
        if (sel_col_start > sel_col_end) {
@@ -2317,15 +2353,9 @@ bool InsetTabular::cutSelection()
        int sel_row_start = tabular->row_of_cell(sel_cell_start);
        int sel_row_end = tabular->row_of_cell(sel_cell_end);
        if (sel_row_start > sel_row_end) {
-               //int tmp = sel_row_start;
-               //sel_row_start = sel_row_end;
-               //sel_row_end = tmp;
                swap(sel_row_start, sel_row_end);
        }
        if (sel_cell_start > sel_cell_end) {
-               //int tmp = sel_cell_start;
-               //sel_cell_start = sel_cell_end;
-               //sel_cell_end = tmp;
                swap(sel_cell_start, sel_cell_end);
        }
        for (int i = sel_row_start; i <= sel_row_end; ++i) {
@@ -2383,9 +2413,160 @@ void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol)
                        ecol = tabular->right_column_of_cell(sel_cell_end);
 }
 
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+
+Paragraph * InsetTabular::getParFromID(int id) const
+{
+       Paragraph * result;
+       for(int i = 0; i < tabular->rows(); ++i) {
+               for(int j = 0; j < tabular->columns(); ++j) {
+                       if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
+                               return result;
+               }
+       }
+       return 0;
+}
+
+
+Paragraph * InsetTabular::firstParagraph() const
+{
+       if (the_locking_inset)
+               return the_locking_inset->firstParagraph();
+       return 0;
+}
+
+
+LyXCursor const & InsetTabular::cursor(BufferView * bv) const
+{
+       if (the_locking_inset)
+               return the_locking_inset->cursor(bv);
+       return Inset::cursor(bv);
+}
+
+
+Inset * InsetTabular::getInsetFromID(int id_arg) const
+{
+       if (id_arg == id())
+               return const_cast<InsetTabular *>(this);
+
+       Inset * result;
+       for(int i=0; i < tabular->rows(); ++i) {
+               for(int j=0; j < tabular->columns(); ++j) {
+                       if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
+                               return result;
+               }
+       }
+       return 0;
+}
+
+
+string const InsetTabular::selectNextWord(BufferView * bv, float & value) const
+{
+       if (the_locking_inset) {
+               string const str(the_locking_inset->selectNextWord(bv, value));
+               if (!str.empty())
+                       return str;
+               if (tabular->IsLastCell(actcell)) {
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return string();
+               }
+               ++actcell;
+       }
+       
+       // otherwise we have to lock the next inset and ask for it's selecttion
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+       inset->edit(bv, 0,  0, 0);
+       string const str(selectNextWordInt(bv, value));
+       if (!str.empty())
+               resetPos(bv);
+       return str;
+}
+
+
+string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
+{
+       // when entering this function the inset should be ALWAYS locked!
+       lyx::Assert(the_locking_inset);
+
+       string const str(the_locking_inset->selectNextWord(bv, value));
+       if (!str.empty())
+               return str;
+
+       if (tabular->IsLastCell(actcell)) {
+               bv->unlockInset(const_cast<InsetTabular *>(this));
+               return string();
+       }
+       
+       // otherwise we have to lock the next inset and ask for it's selecttion
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
+       inset->edit(bv, 0,  0, 0);
+       return selectNextWordInt(bv, value);
+}
+
+
+void InsetTabular::selectSelectedWord(BufferView * bv)
+{
+       if (the_locking_inset) {
+               the_locking_inset->selectSelectedWord(bv);
+               return;
+       }
+       return;
+}
+
+
+void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
+{
+       if (the_locking_inset) {
+               the_locking_inset->toggleSelection(bv, kill_selection);
+       }
+}
+
+
+bool InsetTabular::searchForward(BufferView * bv, string const & str,
+                              bool const & cs, bool const & mw)
+{
+       if (the_locking_inset) {
+               if (the_locking_inset->searchForward(bv, str, cs, mw))
+                       return true;
+               if (tabular->IsLastCell(actcell)) {
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return false;
+               }
+               ++actcell;
+       }
+       nodraw(true);
+       // otherwise we have to lock the next inset and search there
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+       inset->edit(bv);
+       bool const res = searchForward(bv, str, cs, mw);
+       updateLocal(bv, NONE, false);
+       nodraw(false);
+       bv->updateInset(const_cast<InsetTabular *>(this), false);
+       return res;
+}
+
+
+bool InsetTabular::searchBackward(BufferView * bv, string const & str,
+                               bool const & cs, bool const & mw)
+{
+       if (the_locking_inset) {
+               if (the_locking_inset->searchBackward(bv, str, cs, mw))
+                       return true;
+               if (!actcell) { // we are already in the first cell
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return false;
+               }
+               --actcell;
+       }
+       nodraw(true);
+       // otherwise we have to lock the next inset and search there
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+       inset->edit(bv, false);
+       bool const res = searchBackward(bv, str, cs, mw);
+       nodraw(false);
+       bv->updateInset(const_cast<InsetTabular *>(this), false);
+       return res;
+}