]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
use more specific smart_ptr headers
[lyx.git] / src / insets / insettabular.C
index 9baa61cf251c1de553162507a416d6abcadf14e1..d7c59e82bf5ee72093e0234ab0f982a1443d606a 100644 (file)
@@ -450,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)) {
@@ -491,8 +491,8 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
 
        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);
        }
 }
@@ -530,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;
@@ -578,6 +580,7 @@ void InsetTabular::edit(BufferView * bv, bool front)
                lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
                return;
        }
+       finishUndo();
        locked = true;
        the_locking_inset = 0;
        inset_x = 0;
@@ -588,7 +591,7 @@ void InsetTabular::edit(BufferView * bv, bool front)
                actcell = tabular->GetNumberOfCells() - 1;
        clearSelection();
        resetPos(bv);
-       finishUndo();
+       bv->fitCursor();
 }
 
 
@@ -596,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);
@@ -685,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
@@ -694,6 +697,8 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                        scroll(bv, 0.0F);
 #endif
                updateLocal(bv, CELL, false);
+               // this has to be here otherwise we don't redraw the cell!
+               the_locking_inset = 0;
 //             showInsetCursor(bv, false);
                return true;
        }
@@ -728,7 +733,7 @@ bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
 }
 
 
-unsigned int InsetTabular::insetInInsetY()
+int InsetTabular::insetInInsetY() const
 {
        if (!the_locking_inset)
                return 0;
@@ -775,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);
@@ -783,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);
@@ -800,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);
@@ -1276,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);
@@ -1454,14 +1469,19 @@ 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;
 }
 
 
@@ -1754,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)
@@ -2781,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;
 }
 
 
@@ -2802,8 +2827,8 @@ bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
                                     bool usePaste)
 {
-       if (buf.find('\t') == string::npos)
-               return false;
+       if (buf.length() <= 0)
+               return true;
 
        int cols = 1;
        int rows = 1;
@@ -2859,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)
@@ -2878,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;
 }