]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
bit of clean up
[lyx.git] / src / insets / InsetTabular.cpp
index 935516d5cb78ab40356f4bba21f52236407c9981..6c628049ac4e5fd7dd0562afe2030b1435c78796 100644 (file)
@@ -113,6 +113,11 @@ TabularFeature tabularFeature[] =
        { Tabular::DELETE_COLUMN, "delete-column", false },
        { Tabular::COPY_ROW, "copy-row", false },
        { Tabular::COPY_COLUMN, "copy-column", false },
+       { Tabular::SET_LINE_TOP, "set-line-top", true },
+       { Tabular::SET_LINE_BOTTOM, "set-line-bottom", true },
+       { Tabular::SET_LINE_LEFT, "set-line-left", true },
+       { Tabular::SET_LINE_RIGHT, "set-line-right", true },
+       //FIXME: get rid of those 4 TOGGLE actions in favor of the 4 above.
        { Tabular::TOGGLE_LINE_TOP, "toggle-line-top", false },
        { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom", false },
        { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left", false },
@@ -862,32 +867,6 @@ bool Tabular::rightLine(idx_type cell) const
 }
 
 
-bool Tabular::topAlreadyDrawn(idx_type cell) const
-{
-       row_type const row = cellRow(cell);
-       if (row == 0)
-               return false;
-       
-       return !rowTopLine(row) && bottomLine(cellAbove(cell));
-}
-
-
-bool Tabular::leftAlreadyDrawn(idx_type cell) const
-{
-       col_type col = cellColumn(cell);
-       if (col == 0)
-               return false;
-       idx_type i = cellIndex(cellRow(cell), col - 1);
-       return rightLine(i) && !leftLine(cell);
-}
-
-
-bool Tabular::isLastRow(idx_type cell) const
-{
-       return cellRow(cell) == row_info.size() - 1;
-}
-
-
 int Tabular::interRowSpace(row_type row) const
 {
        if (!row || row >= row_info.size())
@@ -3455,7 +3434,10 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
                onoffcol = change.color();
        }
 
-       if (!tabular.topAlreadyDrawn(cell)) {
+       bool topalreadydrawn = row > 0 && !tabular.rowTopLine(row) 
+               && tabular.bottomLine(tabular.cellAbove(cell));
+
+       if (!topalreadydrawn) {
                on_off = !tabular.topLine(cell);
                pain.line(x, y, x + w, y,
                        on_off ? onoffcol : col,
@@ -3465,7 +3447,12 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
        pain.line(x, y + h, x + w, y + h,
                on_off ? onoffcol : col,
                on_off ? Painter::line_onoffdash : Painter::line_solid);
-       if (!tabular.leftAlreadyDrawn(cell)) {
+
+       col_type const column = tabular.cellColumn(cell);
+       bool leftalreadydrawn = column > 0  && !tabular.leftLine(cell)
+               && tabular.rightLine(tabular.cellIndex(row, column - 1));
+
+       if (!leftalreadydrawn) {
                on_off = !tabular.leftLine(cell);
                pain.line(x, y, x, y + h,
                        on_off ? onoffcol : col,
@@ -4095,6 +4082,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
                        break;
 
+               case Tabular::SET_LINE_TOP:
+               case Tabular::SET_LINE_BOTTOM:
+               case Tabular::SET_LINE_LEFT:
+               case Tabular::SET_LINE_RIGHT:
+                       status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
+                       break;
+
                case Tabular::TOGGLE_LINE_TOP:
                        status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
                        status.setOnOff(tabular.topLine(cur.idx()));
@@ -4732,14 +4726,14 @@ bool InsetTabular::tabularFeatures(Cursor & cur, string const & argument)
        // Safe guard.
        size_t safe_guard = 0;
        for (;;) {
+               if (is.eof())
+                       break;
                safe_guard++;
                if (safe_guard > 1000) {
                        LYXERR0("parameter max count reached!");
                        break;
                }
                is >> s;
-               if (is.eof())
-                       break;
                Tabular::Feature action = Tabular::LAST_ACTION;
 
                size_t i = 0;
@@ -4925,32 +4919,40 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                cur.idx() = tabular.cellIndex(row, column);
                break;
 
+       case Tabular::SET_LINE_TOP:
        case Tabular::TOGGLE_LINE_TOP: {
-               bool lineSet = !tabular.topLine(cur.idx());
+               bool lineSet = (feature == Tabular::SET_LINE_TOP)
+                              ? (value == "true") : !tabular.topLine(cur.idx());
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
                        for (col_type j = sel_col_start; j <= sel_col_end; ++j)
                                tabular.setTopLine(tabular.cellIndex(i, j), lineSet);
                break;
        }
 
+       case Tabular::SET_LINE_BOTTOM:
        case Tabular::TOGGLE_LINE_BOTTOM: {
-               bool lineSet = !tabular.bottomLine(cur.idx());
+               bool lineSet = (feature == Tabular::SET_LINE_BOTTOM)
+                              ? (value == "true") : !tabular.bottomLine(cur.idx());
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
                        for (col_type j = sel_col_start; j <= sel_col_end; ++j)
                                tabular.setBottomLine(tabular.cellIndex(i, j), lineSet);
                break;
        }
 
+       case Tabular::SET_LINE_LEFT:
        case Tabular::TOGGLE_LINE_LEFT: {
-               bool lineSet = !tabular.leftLine(cur.idx());
+               bool lineSet = (feature == Tabular::SET_LINE_LEFT)
+                              ? (value == "true") : !tabular.leftLine(cur.idx());
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
                        for (col_type j = sel_col_start; j <= sel_col_end; ++j)
                                tabular.setLeftLine(tabular.cellIndex(i, j), lineSet);
                break;
        }
 
+       case Tabular::SET_LINE_RIGHT:
        case Tabular::TOGGLE_LINE_RIGHT: {
-               bool lineSet = !tabular.rightLine(cur.idx());
+               bool lineSet = (feature == Tabular::SET_LINE_RIGHT)
+                              ? (value == "true") : !tabular.rightLine(cur.idx());
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
                        for (col_type j = sel_col_start; j <= sel_col_end; ++j)
                                tabular.setRightLine(tabular.cellIndex(i, j), lineSet);