]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
fix compilation pb ; update eu.po
[lyx.git] / src / insets / insettabular.C
index c6a9e21e13a2c607ffee8d3ba9d60122feb00a0b..679698de1e1329bf7de6b5248e1469cf3a7deb30 100644 (file)
 #include "lyxtext.h"
 #include "lyx_gui_misc.h"
 #include "LyXView.h"
-#include "lyxfunc.h"
 #include "insets/insettext.h"
 #include "frontends/Dialogs.h"
 #include "debug.h"
-#include "lyxfunc.h"
 #include "WorkArea.h"
+#include "gettext.h"
+#include "language.h"
 
 using std::ostream;
 using std::ifstream;
@@ -124,38 +124,28 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
                rows = 1;
        if (columns <= 0)
                columns = 1;
-       //tabular = 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;
        locked = no_selection = false;
-#if 0
-       cursor_visible = false;
-#endif
        oldcell = -1;
        actrow = actcell = 0;
        clearSelection();
        need_update = INIT;
-       no_draw = false;
 }
 
 
 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
        : buffer(&buf)
 {
-       //tabular = new LyXTabular(this, *(tab.tabular));
        tabular.reset(new LyXTabular(this, *(tab.tabular)));
        the_locking_inset = 0;
        locked = no_selection = false;
-#if 0
-       cursor_visible = false;
-#endif
        oldcell = -1;
        actrow = actcell = 0;
        sel_cell_start = sel_cell_end = 0;
        need_update = INIT;
-       no_draw = false;
 }
 
 
@@ -231,15 +221,24 @@ int InsetTabular::width(BufferView *, LyXFont const &) const
 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                        float & x, bool cleared) const
 {
-       if (no_draw)
+       if (nodraw())
                return;
-       
+       if (bv->text->status == LyXText::CHANGED_IN_DRAW)
+               return;
+
+//     lyxerr << "InsetTabular::draw(" << need_update << ")\n";
+
        Painter & pain = bv->painter();
        int i;
        int j;
        int nx;
-       
+
+#if 0
        UpdatableInset::draw(bv, font, baseline, x, cleared);
+#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);
@@ -259,9 +258,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
        }
        top_x = int(x);
        top_baseline = baseline;
-       if (bv->text->status == LyXText::CHANGED_IN_DRAW)
-               return;
-       bool dodraw;
        x += ADD_TO_TABULAR_WIDTH;
        if (cleared) {
                int cell = 0;
@@ -269,32 +265,41 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                first_visible_cell = -1;
                for (i = 0; i < tabular->rows(); ++i) {
                        nx = int(x);
-                       dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
-                               (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
+                       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 (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,
-                                                                         cleared);
-                                       DrawCellLines(pain, nx, baseline, i, 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) +
                                tabular->GetAscentOfRow(i + 1) +
-                               tabular->GetAdditionalHeight(cell);
+                               tabular->GetAdditionalHeight(i + 1);
                }
        } else if (need_update == CELL) {
                int cell = 0;
                nx = int(x);
-               if (the_locking_inset) {
+               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();
@@ -313,24 +318,23 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                        nx = int(x);
                                        baseline += tabular->GetDescentOfRow(i) +
                                                tabular->GetAscentOfRow(i + 1) +
-                                               tabular->GetAdditionalHeight(cell);
+                                               tabular->GetAdditionalHeight(i + 1);
                                }
                        }
                } else {
-                       for (i = 0;
-                            cell < actcell && i < tabular->rows(); ++i) {
-                               for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
-                                       if (tabular->IsPartOfMultiColumn(i, j))
+                       // copute 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;
-                               }
-                               if (tabular->row_of_cell(cell) > i) {
-                                       nx = int(x);
-                                       baseline += tabular->GetDescentOfRow(i) +
-                                               tabular->GetAscentOfRow(i + 1) +
-                                               tabular->GetAdditionalHeight(cell);
-                               }
                        }
                }
                i = tabular->row_of_cell(cell);
@@ -443,12 +447,9 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
                        owner()->update(bv, font, true);
                return;
        }
-       if (the_locking_inset) {
+       if (the_locking_inset)
                the_locking_inset->update(bv, font, reinit);
-//     resetPos(bv);
-//     inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
-//     inset_y = cursor.y();
-       }
+
        switch (need_update) {
        case INIT:
        case FULL:
@@ -504,9 +505,9 @@ void InsetTabular::InsetUnlock(BufferView * bv)
        no_selection = false;
        oldcell = -1;
        locked = false;
-       if (scroll() || hasSelection()) {
+       if (scroll(false) || hasSelection()) {
                sel_cell_start = sel_cell_end = 0;
-               if (scroll()) {
+               if (scroll(false)) {
                        scroll(bv, 0.0F);
                }
                UpdateLocal(bv, FULL, false);
@@ -566,7 +567,10 @@ bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
        if (the_locking_inset == inset) {
                the_locking_inset->InsetUnlock(bv);
                the_locking_inset = 0;
-               UpdateLocal(bv, CELL, false);
+               if (scroll(false))
+                       scroll(bv, 0.0F);
+               else
+                       UpdateLocal(bv, CELL, false);
                ShowInsetCursor(bv, false);
                return true;
        }
@@ -780,7 +784,10 @@ InsetTabular::LocalDispatch(BufferView * bv,
                sel_cell_start = sel_cell_end = actcell;
                if (hs)
                        UpdateLocal(bv, SELECTION, false);
-               ShowInsetCursor(bv);
+               if (!the_locking_inset) {
+                       ShowInsetCursor(bv);
+                       return DISPATCHED_NOUPDATE;
+               }
                return result;
        }
        // this to avoid compiler warnings.
@@ -1039,19 +1046,19 @@ InsetTabular::LocalDispatch(BufferView * bv,
                result = UNDISPATCHED;
                if (the_locking_inset)
                        break;
-               no_draw = true;
+               nodraw(true);
                if (ActivateCellInset(bv)) {
                        result = the_locking_inset->LocalDispatch(bv, action, arg);
                        if ((result == UNDISPATCHED) || (result == FINISHED)) {
                                UnlockInsetInInset(bv, the_locking_inset);
-                               no_draw = false;
+                               nodraw(false);
                                the_locking_inset = 0;
                                return UNDISPATCHED;
                        }
-                       no_draw = false;
-                       the_locking_inset->ToggleInsetCursor(bv);
+                       nodraw(false);
+//                     the_locking_inset->ToggleInsetCursor(bv);
                        UpdateLocal(bv, CELL, false);
-                       the_locking_inset->ToggleInsetCursor(bv);
+//                     the_locking_inset->ToggleInsetCursor(bv);
                        return result;
                }
                break;
@@ -1181,8 +1188,7 @@ void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
                int const desc = lyxfont::maxDescent(font);
                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);
        }
 }
@@ -1208,13 +1214,9 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
 
        // first search the right row
        while((ly < y) && (actrow < tabular->rows())) {
-               cursor.y(cursor.y()
-                        + tabular->GetDescentOfRow(actrow)
-                        + tabular->GetAscentOfRow(actrow + 1)
-                        + tabular->
-                        GetAdditionalHeight(tabular->
-                                            GetCellNumber(actrow + 1,
-                                                          actcol)));
+               cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+                                tabular->GetAscentOfRow(actrow + 1) +
+                                tabular->GetAdditionalHeight(actrow + 1));
                ++actrow;
                ly = cursor.y() + tabular->GetDescentOfRow(actrow);
        }
@@ -1224,7 +1226,9 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
        int lx = tabular->GetWidthOfColumn(actcell) -
                tabular->GetAdditionalWidth(actcell);
 #if 0
+#ifdef WITH_WARNINGS
 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
+#endif
        for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
             ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
                     tabular->GetAdditionalWidth(actcell - 1));
@@ -1266,10 +1270,9 @@ void InsetTabular::resetPos(BufferView * bv) const
        cursor.y(0);
        for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
                if (tabular->IsLastCellInRow(cell)) {
-                       cursor.y(cursor.y()
-                                + tabular->GetDescentOfRow(actrow)
-                                + tabular->GetAscentOfRow(actrow + 1)
-                                + tabular->GetAdditionalHeight(cell + 1));
+                       cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+                                        tabular->GetAscentOfRow(actrow + 1) +
+                                        tabular->GetAdditionalHeight(actrow + 1));
                        ++actrow;
                }
        }
@@ -1279,9 +1282,10 @@ void InsetTabular::resetPos(BufferView * bv) const
        new_x += offset;
        cursor.x(new_x);
 //    cursor.x(getCellXPos(actcell) + offset);
-       if (scroll() && (tabular->GetWidthOfTabular() < bv->workWidth()-20))
+       if (scroll(false) && (tabular->GetWidthOfTabular() < bv->workWidth()-20)) {
                scroll(bv, 0.0F);
-       else if (the_locking_inset &&
+               UpdateLocal(bv, FULL, false);
+       } 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))
@@ -1293,6 +1297,7 @@ void InsetTabular::resetPos(BufferView * bv) const
                                xx = 60;
                        scroll(bv, xx);
                }
+               UpdateLocal(bv, FULL, false);
        } else if ((cursor.x() - offset) > 20 &&
                   (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
                   > (bv->workWidth() - 20)) {
@@ -1301,9 +1306,10 @@ void InsetTabular::resetPos(BufferView * bv) const
        } else if ((cursor.x() - offset) < 20) {
                scroll(bv, 20 - cursor.x() + offset);
                UpdateLocal(bv, FULL, false);
-       } else if (scroll() && top_x > 20 &&
+       } else if (scroll(false) && top_x > 20 &&
                   (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
                scroll(bv, old_x - cursor.x());
+               UpdateLocal(bv, FULL, false);
        }
        if ((!the_locking_inset ||
             !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
@@ -2159,6 +2165,12 @@ LyXFunc::func_status InsetTabular::getStatus(string const & what) const
 }
 
 
+std::vector<string> const InsetTabular::getLabelList() const
+{
+       return tabular->getLabelList();
+}
+
+
 bool InsetTabular::copySelection(BufferView * bv)
 {
        if (!hasSelection())
@@ -2293,3 +2305,31 @@ bool InsetTabular::isRightToLeft(BufferView *bv )
 {
        return bv->getParentLanguage(this)->RightToLeft();
 }
+
+bool InsetTabular::nodraw() const
+{
+       if (the_locking_inset)
+               return the_locking_inset->nodraw();
+       return UpdatableInset::nodraw();
+}
+
+int InsetTabular::scroll(bool recursive) const
+{
+       int sx = UpdatableInset::scroll(false);
+
+       if (recursive && the_locking_inset)
+               sx += the_locking_inset->scroll(recursive);
+
+       return sx;
+}
+
+bool InsetTabular::doClearArea() const
+{
+       return !locked || (need_update & (FULL|INIT));
+}
+/* Emacs:
+ * Local variables:
+ * tab-width: 4
+ * End:
+ * vi:set tabstop=4:
+ */