]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
use more specific smart_ptr headers
[lyx.git] / src / insets / insettabular.C
index 4c8e6014b3938b973202d6fa6eb8520bd94911ca..d7c59e82bf5ee72093e0234ab0f982a1443d606a 100644 (file)
@@ -1,6 +1,6 @@
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
  *
  *           Copyright 2001 The LyX Team.
@@ -28,7 +28,6 @@
 #include "LyXView.h"
 #include "insets/insettext.h"
 #include "debug.h"
-#include "WorkArea.h"
 #include "gettext.h"
 #include "language.h"
 #include "BufferView.h"
@@ -262,13 +261,13 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                x += static_cast<float>(scroll());
 #endif
        if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
-                        (top_x != int(x)) || (top_baseline != baseline)))
+                        (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())
@@ -309,7 +308,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                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);
@@ -377,7 +376,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                //
                //  +--------------------+
                //  |         C          |   The rectangles are A, B and C
-               //  | A |------------| B |   below, origin top left (tx, ty), 
+               //  | A |------------| B |   below, origin top left (tx, ty),
                //  |   |  inset box |   |   dimensions w(idth), h(eight).
                //  +---+------------+---+   x grows rightward, y downward
                //  |         D          |
@@ -389,10 +388,10 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
 #endif
                        // clear before the inset
                        int tx, ty, w, h;
-                       tx = nx + 1; 
+                       tx = nx + 1;
                        ty = baseline - tabular->GetAscentOfRow(i) + 1;
                        w = int(cx - nx - 1);
-                       h = tabular->GetAscentOfRow(i) + 
+                       h = tabular->GetAscentOfRow(i) +
                                tabular->GetDescentOfRow(i) - 1;
                        pain.fillRectangle(tx, ty, w, h, backgroundColor());
                        // clear behind the inset
@@ -438,11 +437,11 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
 
 
 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
-                                 int row, int cell) const
+                                int row, int cell) const
 {
        int x2 = x + tabular->GetWidthOfColumn(cell);
        bool on_off;
-       
+
        if (!tabular->TopAlreadyDrawed(cell)) {
                on_off = !tabular->TopLine(cell);
                pain.line(x, baseline - tabular->GetAscentOfRow(row),
@@ -451,8 +450,8 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->BottomLine(cell);
-       pain.line(x,baseline +  tabular->GetDescentOfRow(row),
-                 x2, baseline +  tabular->GetDescentOfRow(row),
+       pain.line(x, baseline + tabular->GetDescentOfRow(row),
+                 x2, baseline + tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
        if (!tabular->LeftAlreadyDrawed(cell)) {
@@ -484,16 +483,16 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
        } else {
                ce = tabular->right_column_of_cell(sel_cell_end);
        }
-       
+
        int rs = tabular->row_of_cell(sel_cell_start);
        int re = tabular->row_of_cell(sel_cell_end);
        if (rs > re)
                swap(rs, re);
-       
+
        if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
                int w = tabular->GetWidthOfColumn(cell);
-               int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
-               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
+               int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
+               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
                                   w, h, LColor::selection);
        }
 }
@@ -531,8 +530,10 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
        case INIT:
        case FULL:
        case CELL:
-               if (calculate_dimensions_of_cells(bv, font, false))
+               if (calculate_dimensions_of_cells(bv, font, false)) {
                        need_update = INIT;
+                       resetPos(bv);
+               }
                break;
        case SELECTION:
                need_update = FULL;
@@ -553,7 +554,7 @@ string const InsetTabular::editMessage() const
 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
 {
        UpdatableInset::edit(bv, x, y, button);
-       
+
        if (!bv->lockInset(this)) {
                lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
                return;
@@ -574,11 +575,12 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
 void InsetTabular::edit(BufferView * bv, bool front)
 {
        UpdatableInset::edit(bv, front);
-       
+
        if (!bv->lockInset(this)) {
                lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
                return;
        }
+       finishUndo();
        locked = true;
        the_locking_inset = 0;
        inset_x = 0;
@@ -589,7 +591,7 @@ void InsetTabular::edit(BufferView * bv, bool front)
                actcell = tabular->GetNumberOfCells() - 1;
        clearSelection();
        resetPos(bv);
-       finishUndo();
+       bv->fitCursor();
 }
 
 
@@ -597,6 +599,7 @@ void InsetTabular::insetUnlock(BufferView * bv)
 {
        if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
+               updateLocal(bv, CELL, false);
                the_locking_inset = 0;
        }
        hideInsetCursor(bv);
@@ -613,12 +616,14 @@ void InsetTabular::insetUnlock(BufferView * bv)
 
 
 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
-                               bool mark_dirty) const
+                              bool mark_dirty) const
 {
        if (what == INIT) {
                LyXFont font;
                calculate_dimensions_of_cells(bv, font, true);
        }
+       if (!locked && what == CELL)
+               what = FULL;
        if (need_update < what) // only set this if it has greater update
                need_update = what;
 #if 0 // maybe this should not be done!
@@ -684,7 +689,6 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                return false;
        if (the_locking_inset == inset) {
                the_locking_inset->insetUnlock(bv);
-               the_locking_inset = 0;
 #ifdef WITH_WARNINGS
 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
 #endif
@@ -693,7 +697,9 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                        scroll(bv, 0.0F);
 #endif
                updateLocal(bv, CELL, false);
-               showInsetCursor(bv, false);
+               // this has to be here otherwise we don't redraw the cell!
+               the_locking_inset = 0;
+//             showInsetCursor(bv, false);
                return true;
        }
        if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
@@ -710,10 +716,16 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
 
 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
 {
-       if (!the_locking_inset)
+       Inset * tl_inset = inset;
+       // look if this inset is really inside myself!
+       while(tl_inset->owner() && tl_inset->owner() != this)
+               tl_inset = tl_inset->owner();
+       // if we enter here it's not ower inset
+       if (!tl_inset->owner())
                return false;
-       if (the_locking_inset != inset) {
-               if (!the_locking_inset->updateInsetInInset(bv, inset))
+       // we only have to do this if this is a subinset of our cells
+       if (tl_inset != inset) {
+               if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
                        return false;
        }
        updateLocal(bv, CELL, false);
@@ -721,7 +733,7 @@ bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
 }
 
 
-unsigned int InsetTabular::insetInInsetY()
+int InsetTabular::insetInInsetY() const
 {
        if (!the_locking_inset)
                return 0;
@@ -768,6 +780,12 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
        int const orow = actrow;
 
        hideInsetCursor(bv);
+       if (!locked) {
+               locked = true;
+               the_locking_inset = 0;
+               inset_x = 0;
+               inset_y = 0;
+       }
        setPos(bv, x, y);
        if (actrow != orow)
                updateLocal(bv, NONE, false);
@@ -776,6 +794,7 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
        if (button == 3) {
                if ((ocell != actcell) && the_locking_inset) {
                        the_locking_inset->insetUnlock(bv);
+                       updateLocal(bv, CELL, false);
                        the_locking_inset = 0;
                }
                showInsetCursor(bv);
@@ -793,20 +812,20 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
                return;
        } else if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
+               updateLocal(bv, CELL, false);
+               the_locking_inset = 0;
        }
-       the_locking_inset = 0;
        if (button == 2) {
                localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
                return;
        }
        if (inset_hit && bv->theLockingInset()) {
-               // only activate the Inset so that no internal inset is hit
-               // by this call. It should be only hit by the insetButtonPress call.
-               if (activateCellInsetAbs(bv, 0, 0, 0))
-                       the_locking_inset->insetButtonPress(bv,
-                                                           x - inset_x,
-                                                           y - inset_y,
-                                                           button);
+               if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
+                       lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+                       return;
+               }
+               the_locking_inset->insetButtonPress(
+                       bv, x - inset_x, y - inset_y, button);
                return;
        }
        showInsetCursor(bv);
@@ -814,7 +833,7 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
 
 
 bool InsetTabular::insetButtonRelease(BufferView * bv,
-                                      int x, int y, int button)
+                                     int x, int y, int button)
 {
        bool ret = false;
        if (the_locking_inset)
@@ -837,10 +856,10 @@ void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
                                                     button);
                return;
        }
+
        hideInsetCursor(bv);
 //     int const old_cell = actcell;
-       
+
        setPos(bv, x, y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
@@ -863,9 +882,9 @@ void InsetTabular::insetKeyPress(XKeyEvent * xke)
 
 UpdatableInset::RESULT
 InsetTabular::localDispatch(BufferView * bv, kb_action action,
-                            string const & arg)
+                           string const & arg)
 {
-       // We need to save the value of the_locking_inset as the call to 
+       // We need to save the value of the_locking_inset as the call to
        // the_locking_inset->LocalDispatch might unlock it.
        old_locking_inset = the_locking_inset;
        UpdatableInset::RESULT result =
@@ -942,7 +961,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
                        setSelection(start, actcell);
                        break;
                }
-               
+
                int end = actcell;
                // if we are starting a selection, only select
                // the current cell at the beginning
@@ -966,11 +985,11 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
                        setSelection(start, actcell);
                        break;
                }
+
                int end = actcell;
                // if we are starting a selection, only select
                // the current cell at the beginning
-               if (hasSelection()) { 
+               if (hasSelection()) {
                        moveLeft(bv, false);
                        end = actcell;
                }
@@ -1083,7 +1102,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
        case LFUN_NEXTSEL:
        case LFUN_WORDLEFT:
        case LFUN_WORDLEFTSEL:
-       case LFUN_WORDRIGHT: 
+       case LFUN_WORDRIGHT:
        case LFUN_WORDRIGHTSEL:
        case LFUN_DOWN_PARAGRAPH:
        case LFUN_DOWN_PARAGRAPHSEL:
@@ -1096,7 +1115,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
        case LFUN_END:
        case LFUN_ENDSEL:
        case LFUN_BEGINNINGBUF:
-       case LFUN_BEGINNINGBUFSEL: 
+       case LFUN_BEGINNINGBUFSEL:
        case LFUN_ENDBUF:
        case LFUN_ENDBUFSEL:
                break;
@@ -1109,7 +1128,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
                break;
                // insert file functions
        case LFUN_FILE_INSERT_ASCII_PARA:
-       case LFUN_FILE_INSERT_ASCII: 
+       case LFUN_FILE_INSERT_ASCII:
        {
                string tmpstr = getContentsOfAsciiFile(bv, arg, false);
                if (tmpstr.empty())
@@ -1125,8 +1144,8 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
                if (!copySelection(bv))
                        break;
                setUndo(bv, Undo::DELETE,
-                       bv->text->cursor.par(),
-                       bv->text->cursor.par()->next());
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
                cutSelection();
                updateLocal(bv, INIT, true);
                break;
@@ -1210,8 +1229,8 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
        case LFUN_PASTE:
                if (hasPasteBuffer()) {
                        setUndo(bv, Undo::INSERT,
-                               bv->text->cursor.par(),
-                               bv->text->cursor.par()->next());
+                               bv->text->cursor.par(),
+                               bv->text->cursor.par()->next());
                        pasteSelection(bv);
                        updateLocal(bv, INIT, true);
                        break;
@@ -1269,7 +1288,10 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
        }
        if (result < FINISHED) {
                if (!the_locking_inset) {
-                       showInsetCursor(bv);
+                       if (bv->fitCursor())
+                               updateLocal(bv, FULL, false);
+                       if (locked)
+                               showInsetCursor(bv);
                }
        } else
                bv->unlockInset(this);
@@ -1278,7 +1300,7 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
 
 
 int InsetTabular::latex(Buffer const * buf, ostream & os,
-                        bool fragile, bool fp) const
+                       bool fragile, bool fp) const
 {
        return tabular->latex(buf, os, fragile, fp);
 }
@@ -1288,7 +1310,7 @@ int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
 {
        if (ll > 0)
                return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
-                                     false,0);
+                                     false,0);
        return tabular->ascii(buf, os, 0, false,0);
 }
 
@@ -1335,15 +1357,15 @@ void InsetTabular::validate(LaTeXFeatures & features) const
 
 
 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
-                                                 LyXFont const & font,
-                                                 bool reinit) const
+                                                LyXFont const & font,
+                                                bool reinit) const
 {
        int cell = -1;
        int maxAsc = 0;
        int maxDesc = 0;
        InsetText * inset;
        bool changed = false;
-       
+
        // if we have a locking_inset we should have to check only this cell for
        // change so I'll try this to have a boost, but who knows ;)
        if ((need_update != INIT) &&
@@ -1404,12 +1426,12 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
                the_locking_inset->toggleInsetCursor(bv);
                return;
        }
-       
+
        LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
-       
+
        int const asc = lyxfont::maxAscent(font);
        int const desc = lyxfont::maxDescent(font);
-       
+
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
@@ -1424,7 +1446,7 @@ void InsetTabular::showInsetCursor(BufferView * bv, bool show)
                return;
        if (!isCursorVisible()) {
                LyXFont font; // = GetFont(par, cursor.pos);
-       
+
                int const asc = lyxfont::maxAscent(font);
                int const desc = lyxfont::maxDescent(font);
                bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
@@ -1447,21 +1469,26 @@ void InsetTabular::hideInsetCursor(BufferView * bv)
 void InsetTabular::fitInsetCursor(BufferView * bv) const
 {
        if (the_locking_inset) {
+               int old_first_y = bv->text->first_y;
                the_locking_inset->fitInsetCursor(bv);
+               if (old_first_y != bv->text->first_y)
+                       need_update = FULL;
                return;
        }
        LyXFont font;
-       
+
        int const asc = lyxfont::maxAscent(font);
        int const desc = lyxfont::maxDescent(font);
-       bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
+       resetPos(bv);
+       if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
+               need_update = FULL;
 }
 
 
 void InsetTabular::setPos(BufferView * bv, int x, int y) const
 {
        cursor_.y(0);
-       
+
        actcell = actrow = actcol = 0;
        int ly = tabular->GetDescentOfRow(actrow);
 
@@ -1490,7 +1517,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
 int InsetTabular::getCellXPos(int cell) const
 {
        int c = cell;
-       
+
        for (; !tabular->IsFirstCellInRow(c); --c)
                ;
        int lx = tabular->GetWidthOfColumn(cell);
@@ -1503,7 +1530,9 @@ int InsetTabular::getCellXPos(int cell) const
 
 void InsetTabular::resetPos(BufferView * bv) const
 {
+#ifdef WITH_WARNINGS
 #warning This should be fixed in the right manner (20011128 Jug)
+#endif
        // fast hack to fix infinite repaintings!
        if (in_reset_pos)
                return;
@@ -1720,15 +1749,15 @@ bool InsetTabular::deletable() const
 
 
 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
-                           bool selectall)
+                          bool selectall)
 {
        if (selectall) {
                setSelection(0, tabular->GetNumberOfCells() - 1);
        }
        if (hasSelection()) {
                setUndo(bv, Undo::EDIT,
-                       bv->text->cursor.par(),
-                       bv->text->cursor.par()->next());
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
                bool frozen = undo_frozen;
                if (!frozen)
                        freezeUndo();
@@ -1745,6 +1774,8 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                }
                if (!frozen)
                        unFreezeUndo();
+               if (selectall)
+                       clearSelection();
                updateLocal(bv, INIT, true);
        }
        if (the_locking_inset)
@@ -1755,11 +1786,11 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
 {
        LyXTabular::Feature action = LyXTabular::LAST_ACTION;
-       
+
        int i = 0;
        for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
                string const tmp = tabularFeature[i].feature;
-               
+
                if (tmp == what.substr(0, tmp.length())) {
                        //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
                        //tabularFeatures[i].feature.length())) {
@@ -1777,7 +1808,7 @@ bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
 }
 
 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
-                                  string const & special, bool & flag)
+                                 string const & special, bool & flag)
 {
        if (special == "dl_above") {
                ltt.topDL = flag;
@@ -1796,8 +1827,8 @@ static void checkLongtableSpecial(LyXTabular::ltType & ltt,
 
 
 void InsetTabular::tabularFeatures(BufferView * bv,
-                                   LyXTabular::Feature feature,
-                                   string const & value)
+                                  LyXTabular::Feature feature,
+                                  string const & value)
 {
        int sel_col_start;
        int sel_col_end;
@@ -1842,20 +1873,20 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
        }
        setUndo(bv, Undo::FINISH,
-               bv->text->cursor.par(),
-               bv->text->cursor.par()->next());
+               bv->text->cursor.par(),
+               bv->text->cursor.par()->next());
 
        int row =  tabular->row_of_cell(actcell);
        int column = tabular->column_of_cell(actcell);
        bool flag = true;
        LyXTabular::ltType ltt;
-       
+
        switch (feature) {
        case LyXTabular::SET_PWIDTH:
        {
                LyXLength const vallen(value);
                LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
-               
+
                bool const update = (tmplen != vallen);
                tabular->SetColumnPWidth(actcell, vallen);
                if (update) {
@@ -1872,7 +1903,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        {
                LyXLength const vallen(value);
                LyXLength const & tmplen = tabular->GetPWidth(actcell);
-               
+
                bool const update = (tmplen != vallen);
                tabular->SetMColumnPWidth(actcell, vallen);
                if (update) {
@@ -1937,12 +1968,12 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                updateLocal(bv, INIT, true);
                break;
        }
-       
+
        case LyXTabular::M_TOGGLE_LINE_BOTTOM:
                flag = false;
        case LyXTabular::TOGGLE_LINE_BOTTOM:
        {
-               bool lineSet = !tabular->BottomLine(actcell, flag); 
+               bool lineSet = !tabular->BottomLine(actcell, flag);
                for (int i = sel_row_start; i <= sel_row_end; ++i)
                        for (int j = sel_col_start; j <= sel_col_end; ++j)
                                tabular->SetBottomLine(
@@ -1952,7 +1983,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                updateLocal(bv, INIT, true);
                break;
        }
-       
+
        case LyXTabular::M_TOGGLE_LINE_LEFT:
                flag = false;
        case LyXTabular::TOGGLE_LINE_LEFT:
@@ -1967,7 +1998,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                updateLocal(bv, INIT, true);
                break;
        }
-       
+
        case LyXTabular::M_TOGGLE_LINE_RIGHT:
                flag = false;
        case LyXTabular::TOGGLE_LINE_RIGHT:
@@ -1982,7 +2013,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                updateLocal(bv, INIT, true);
                break;
        }
-       
+
        case LyXTabular::M_ALIGN_LEFT:
        case LyXTabular::M_ALIGN_RIGHT:
        case LyXTabular::M_ALIGN_CENTER:
@@ -2015,8 +2046,8 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        case LyXTabular::MULTICOLUMN:
        {
                if (sel_row_start != sel_row_end) {
-                       Alert::alert(_("Impossible Operation!"), 
-                                  _("Multicolumns can only be horizontally."), 
+                       Alert::alert(_("Impossible Operation!"),
+                                  _("Multicolumns can only be horizontally."),
                                   _("Sorry."));
                        return;
                }
@@ -2027,7 +2058,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                tabular->UnsetMultiColumn(actcell);
                                updateLocal(bv, INIT, true);
                        } else {
-                               tabular->SetMultiColumn(actcell, 1);
+                               tabular->SetMultiColumn(bv->buffer(), actcell, 1);
                                updateLocal(bv, CELL, true);
                        }
                        return;
@@ -2044,7 +2075,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        s_start = sel_cell_start;
                        s_end = sel_cell_end;
                }
-               tabular->SetMultiColumn(s_start, s_end - s_start + 1);
+               tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
                actcell = s_start;
                clearSelection();
                updateLocal(bv, INIT, true);
@@ -2180,7 +2211,7 @@ bool InsetTabular::insetHit(BufferView *, int x, int) const
 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 {
        LyXLength const len = tabular->GetPWidth(cell);
-       
+
        if (len.zero())
                return -1;
        return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
@@ -2188,7 +2219,7 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 
 
 int InsetTabular::getMaxWidth(BufferView * bv,
-                              UpdatableInset const * inset) const
+                             UpdatableInset const * inset) const
 {
        int cell = tabular->GetCellFromInset(inset, actcell);
 
@@ -2197,13 +2228,13 @@ int InsetTabular::getMaxWidth(BufferView * bv,
                       << endl;
                return -1;
        }
-       
+
        int w = getMaxWidthOfCell(bv, cell);
        if (w > 0) {
                // because the inset then subtracts it's top_x and owner->x()
                w += (inset->x() - top_x);
        }
-       
+
        return w;
 }
 
@@ -2228,7 +2259,7 @@ 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);
@@ -2277,11 +2308,11 @@ FuncStatus InsetTabular::getStatus(string const & what) const
 {
        int action = LyXTabular::LAST_ACTION;
        FuncStatus status;
-       
+
        int i = 0;
        for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
                string const tmp = tabularFeature[i].feature;
-               if (tmp == what.substr(0, tmp.length())) {                  
+               if (tmp == what.substr(0, tmp.length())) {
                        //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
                        //   tabularFeatures[i].feature.length())) {
                        action = tabularFeature[i].action;
@@ -2292,7 +2323,7 @@ FuncStatus InsetTabular::getStatus(string const & what) const
                status.clear();
                return status.unknown(true);
        }
-       
+
        string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
 
        int sel_row_start;
@@ -2468,7 +2499,7 @@ bool InsetTabular::copySelection(BufferView * bv)
 
        ostringstream sstr;
        paste_tabular->ascii(bv->buffer(), sstr,
-                            (int)parOwner()->params().depth(), true, '\t');
+                            (int)parOwner()->params().depth(), true, '\t');
        bv->stuffClipboard(sstr.str().c_str());
        return true;
 }
@@ -2573,7 +2604,7 @@ void InsetTabular::getSelection(int & srow, int & erow,
 {
        int const start = hasSelection() ? sel_cell_start : actcell;
        int const end = hasSelection() ? sel_cell_end : actcell;
+
        srow = tabular->row_of_cell(start);
        erow = tabular->row_of_cell(end);
        if (srow > erow) {
@@ -2685,7 +2716,7 @@ string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
                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));
@@ -2713,7 +2744,7 @@ void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
 
 
 bool InsetTabular::searchForward(BufferView * bv, string const & str,
-                                 bool cs, bool mw)
+                                bool cs, bool mw)
 {
        nodraw(true);
        if (the_locking_inset) {
@@ -2741,7 +2772,7 @@ bool InsetTabular::searchForward(BufferView * bv, string const & str,
 
 
 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
-                               bool cs, bool mw)
+                              bool cs, bool mw)
 {
        nodraw(true);
        if (the_locking_inset) {
@@ -2772,7 +2803,10 @@ bool InsetTabular::insetAllowed(Inset::Code code) const
 {
        if (the_locking_inset)
                return the_locking_inset->insetAllowed(code);
-       return false;
+       // we return true here because if the inset is not locked someone
+       // wants to insert something in one of our insettexts and we generally
+       // allow to do so.
+       return true;
 }
 
 
@@ -2791,11 +2825,11 @@ bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
 }
 
 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
-                                     bool usePaste)
+                                    bool usePaste)
 {
-       if (buf.find('\t') == string::npos)
-               return false;
-       
+       if (buf.length() <= 0)
+               return true;
+
        int cols = 1;
        int rows = 1;
        int maxCols = 1;
@@ -2826,7 +2860,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
        if (usePaste) {
                delete paste_tabular;
                paste_tabular = new LyXTabular(bv->buffer()->params,
-                                              this, rows, maxCols);
+                                              this, rows, maxCols);
                loctab = paste_tabular;
                cols = 0;
        } else {
@@ -2850,15 +2884,22 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
                case '\t':
                        // we can only set this if we are not too far right
                        if (cols < columns) {
-                               loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
+                               InsetText * ti = loctab->GetCellInset(cell);
+                               LyXFont const font = ti->getLyXText(bv)->
+                                       getFont(bv->buffer(), ti->paragraph(), 0);
+                               ti->setText(buf.substr(op, p-op), font);
                                ++cols;
                                ++cell;
                        }
                        break;
                case '\n':
                        // we can only set this if we are not too far right
-                       if (cols < columns)
-                               loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
+                       if (cols < columns) {
+                               InsetText * ti = loctab->GetCellInset(cell);
+                               LyXFont const font = ti->getLyXText(bv)->
+                                       getFont(bv->buffer(), ti->paragraph(), 0);
+                               ti->setText(buf.substr(op, p-op), font);
+                       }
                        cols = ocol;
                        ++row;
                        if (row < rows)
@@ -2869,8 +2910,12 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
                op = p;
        }
        // check for the last cell if there is no trailing '\n'
-       if ((cell < cells) && (op < len))
-               loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));
-       
+       if ((cell < cells) && (op < len)) {
+               InsetText * ti = loctab->GetCellInset(cell);
+               LyXFont const font = ti->getLyXText(bv)->
+                       getFont(bv->buffer(), ti->paragraph(), 0);
+               ti->setText(buf.substr(op, len-op), font);
+       }
+
        return true;
 }