]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
updates to minipage inset
[lyx.git] / src / insets / insettabular.C
index 2c4f73e0fa9b533f74fad902f5bca85398b94c8d..e77fbe3bfeb07eb9bfaad0422326c3c8b4496898 100644 (file)
@@ -121,7 +121,6 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
     // just for test!!!
     the_locking_inset = 0;
     locked = no_selection = cursor_visible = false;
-    cursor.x_fix(-1);
     oldcell = -1;
     actrow = actcell = 0;
     clearSelection();
@@ -136,7 +135,6 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
     tabular = new LyXTabular(this, *(tab.tabular));
     the_locking_inset = 0;
     locked = no_selection = cursor_visible = false;
-    cursor.x_fix(-1);
     oldcell = -1;
     actrow = actcell = 0;
     sel_cell_start = sel_cell_end = 0;
@@ -251,6 +249,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
     if (cleared) {
        int cell = 0;
        float cx;
+       first_visible_cell = -1;
        for (i = 0; i < tabular->rows(); ++i) {
            nx = int(x);
            dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
@@ -260,6 +259,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                    continue;
                cx = nx + tabular->GetBeginningOfTextInCell(cell);
                if (dodraw) {
+                   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,
@@ -484,10 +485,9 @@ void InsetTabular::InsetUnlock(BufferView * bv)
     oldcell = -1;
     locked = false;
     if (scroll() || hasSelection()) {
+       sel_cell_start = sel_cell_end = 0;
        if (scroll()) {
            scroll(bv, 0.0F);
-       } else {
-           sel_cell_start = sel_cell_end = 0;
        }
        UpdateLocal(bv, FULL, false);
     }
@@ -714,7 +714,8 @@ void InsetTabular::InsetKeyPress(XKeyEvent * xke)
 }
 
 
-UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
+UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv,
+                                                  kb_action action,
                                                   string const & arg)
 {
     // We need to save the value of the_locking_inset as the call to 
@@ -731,14 +732,18 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
     if ((action < 0) && arg.empty())
         return FINISHED;
 
-    if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
-        (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
-        cursor.x_fix(-1);
     if (the_locking_inset) {
         result=the_locking_inset->LocalDispatch(bv, action, arg);
-       if (result == DISPATCHED_NOUPDATE)
+       if (result == DISPATCHED_NOUPDATE) {
+           int sc = scroll();
+           resetPos(bv);
+           if (sc != scroll()) { // inset has been scrolled
+               the_locking_inset->ToggleInsetCursor(bv);
+               UpdateLocal(bv, FULL, false);
+               the_locking_inset->ToggleInsetCursor(bv);
+           }
            return result;
-       else if (result == DISPATCHED) {
+       else if (result == DISPATCHED) {
            the_locking_inset->ToggleInsetCursor(bv);
            UpdateLocal(bv, CELL, false);
            the_locking_inset->ToggleInsetCursor(bv);
@@ -814,6 +819,45 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        if (hs)
            UpdateLocal(bv, SELECTION, false);
        break;
+    case LFUN_NEXT: {
+       int column = actcol;
+       if (the_locking_inset) {
+           UnlockInsetInInset(bv, the_locking_inset);
+           the_locking_inset = 0;
+       }
+       if (bv->text->first + bv->painter().paperHeight() <
+           (top_baseline + tabular->GetHeightOfTabular()))
+       {
+           bv->scrollCB(bv->text->first + bv->painter().paperHeight());
+           UpdateLocal(bv, FULL, false);
+           actcell = tabular->GetCellBelow(first_visible_cell) + column;
+       } else {
+           actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
+       }
+       resetPos(bv);
+       UpdateLocal(bv, CURSOR, false);
+       break;
+    }
+    case LFUN_PRIOR: {
+       int column = actcol;
+       if (the_locking_inset) {
+           UnlockInsetInInset(bv, the_locking_inset);
+           the_locking_inset = 0;
+       }
+       if (top_baseline < 0) {
+           bv->scrollCB(bv->text->first - bv->painter().paperHeight());
+           UpdateLocal(bv, FULL, false);
+           if (top_baseline > 0)
+               actcell = column;
+           else
+               actcell = tabular->GetCellBelow(first_visible_cell) + column;
+       } else {
+           actcell = column;
+       }
+       resetPos(bv);
+       UpdateLocal(bv, CURSOR, false);
+       break;
+    }
     case LFUN_BACKSPACE:
        break;
     case LFUN_DELETE:
@@ -852,11 +896,11 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
            break;
        bv->text->SetUndo(bv->buffer(), Undo::DELETE,
 #ifndef NEW_INSETS
-         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
-         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
+         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
+                         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
 #else
-         bv->text->cursor.par()->previous,
-         bv->text->cursor.par()->next
+         bv->text->cursor.par()->previous(),
+         bv->text->cursor.par()->next()
 #endif
                );
        cutSelection();
@@ -939,11 +983,11 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        if (hasPasteBuffer()) {
            bv->text->SetUndo(bv->buffer(), Undo::INSERT,
 #ifndef NEW_INSETS
-             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
-             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
+             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
+                             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
 #else
-             bv->text->cursor.par()->previous,
-             bv->text->cursor.par()->next
+             bv->text->cursor.par()->previous(),
+             bv->text->cursor.par()->next()
 #endif
                );
            pasteSelection(bv);
@@ -1192,9 +1236,24 @@ void InsetTabular::resetPos(BufferView * bv) const
     new_x += offset;
     cursor.x(new_x);
 //    cursor.x(getCellXPos(actcell) + offset);
-    if (((cursor.x() - offset) > 20) &&
-       ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
-        (bv->workWidth()-20)))
+    if (scroll() && (tabular->GetWidthOfTabular() < bv->workWidth()-20))
+       scroll(bv, 0.0F);
+    else if (the_locking_inset &&
+            (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
+    {
+           int xx = cursor.x() - offset + bv->text->GetRealCursorX(bv);
+           if (xx > (bv->workWidth()-20))
+               scroll(bv, -(xx - bv->workWidth() + 60));
+           else if (xx < 20) {
+               if (xx < 0)
+                   xx = -xx + 60;
+               else
+                   xx = 60;
+               scroll(bv, xx);
+           }
+    } 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);
@@ -1208,9 +1267,9 @@ void InsetTabular::resetPos(BufferView * bv) const
     if ((!the_locking_inset ||
         !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
        (actcell != oldcell)) {
-           InsetTabular * inset = const_cast<InsetTabular *>(this);
-           bv->owner()->getDialogs()->updateTabular(inset);
-           oldcell = actcell;
+       InsetTabular * inset = const_cast<InsetTabular *>(this);
+       bv->owner()->getDialogs()->updateTabular(inset);
+       oldcell = actcell;
     }
 }
 
@@ -1452,11 +1511,11 @@ void InsetTabular::TabularFeatures(BufferView * bv,
     }
     bv->text->SetUndo(bv->buffer(), Undo::FINISH,
 #ifndef NEW_INSETS
-             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
-             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
+             bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
+                     bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
 #else
-             bv->text->cursor.par()->previous,
-             bv->text->cursor.par()->next
+             bv->text->cursor.par()->previous(),
+             bv->text->cursor.par()->next()
 #endif
            );
 
@@ -1769,11 +1828,11 @@ void InsetTabular::resizeLyXText(BufferView *) const
 }
 
 
-LyXText * InsetTabular::getLyXText(BufferView const * bv) const
+LyXText * InsetTabular::getLyXText(BufferView const * bv, bool const recursive) const
 {
     if (the_locking_inset)
-       return the_locking_inset->getLyXText(bv);
-    return Inset::getLyXText(bv);
+       return the_locking_inset->getLyXText(bv, recursive);
+    return Inset::getLyXText(bv, recursive);
 }