]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Fix assertion when checking if change in selection
[lyx.git] / src / insets / InsetTabular.cpp
index 99863e9332e8941283684478df5c5a454ba7bf0a..ed2824149479fe2337ff05b94a3063b0e20ffe06 100644 (file)
@@ -199,6 +199,7 @@ TabularFeature tabularFeature[] =
        { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false },
        { Tabular::SET_DECIMAL_POINT, "set-decimal-point", true },
        { Tabular::SET_TABULAR_WIDTH, "set-tabular-width", true },
+       { Tabular::SET_INNER_LINES, "set-inner-lines", false },
        { Tabular::LAST_ACTION, "", false }
 };
 
@@ -4214,12 +4215,12 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
 namespace {
 
 void tabline(PainterInfo const & pi, int x1, int y1, int x2, int y2,
-             bool drawline, int thickness = 1)
+             bool drawline, bool heavy = false)
 {
        ColorCode const col = drawline ? Color_tabularline : Color_tabularonoffline;
        pi.pain.line(x1, y1, x2, y2, pi.textColor(col),
                                 drawline ? Painter::line_solid : Painter::line_onoffdash,
-                                thickness * Painter::thin_line);
+                                (heavy ? 2 : 1) * Painter::thin_line);
 }
 
 }
@@ -4235,17 +4236,14 @@ void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
        // Top
        bool drawline = tabular.topLine(cell)
                || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
-       int thickness = 1;
-       if (drawline && tabular.use_booktabs && tabular.rowTopLine(row))
-               thickness = (row == 0) ? 3 : 2;
-       tabline(pi, x, y, x + w, y, drawline, thickness);
+       bool heavy = tabular.use_booktabs && row == 0 && tabular.rowTopLine(row);
+       tabline(pi, x, y, x + w, y, drawline, heavy);
 
        // Bottom
        drawline = tabular.bottomLine(cell);
-       thickness = 1;
-       if (drawline && tabular.use_booktabs && tabular.rowBottomLine(row))
-               thickness = (row == tabular.nrows() - 1) ? 3 : 2;
-       tabline(pi, x, y + h, x + w, y + h, drawline, thickness);
+       heavy = tabular.use_booktabs && row == tabular.nrows() - 1
+               && tabular.rowBottomLine(row);
+       tabline(pi, x, y + h, x + w, y + h, drawline, heavy);
 
        // Left
        col_type const col = tabular.cellColumn(cell);
@@ -4972,6 +4970,7 @@ bool InsetTabular::getFeatureStatus(Cursor & cur, string const & s,
 
                case Tabular::SET_ALL_LINES:
                case Tabular::UNSET_ALL_LINES:
+               case Tabular::SET_INNER_LINES:
                case Tabular::SET_BORDER_LINES:
                        status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
                        break;
@@ -5782,6 +5781,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
        row_type sel_row_start;
        row_type sel_row_end;
        bool setLines = false;
+       bool setLinesInnerOnly = false;
        LyXAlignment setAlign = LYX_ALIGN_LEFT;
        Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
 
@@ -5957,45 +5957,41 @@ void InsetTabular::tabularFeatures(Cursor & cur,
 
        case Tabular::SET_LINE_TOP:
        case Tabular::TOGGLE_LINE_TOP: {
+               bool lineSet = (feature == Tabular::SET_LINE_TOP)
+                              ? (value == "true") : !tabular.topLine(cur.idx());
                for (row_type r = sel_row_start; r <= sel_row_end; ++r)
-                       for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
-                               bool const lineSet = (feature == Tabular::SET_LINE_TOP)
-                                          ? (value == "true") : !tabular.topLine(tabular.cellIndex(r, c));
+                       for (col_type c = sel_col_start; c <= sel_col_end; ++c)
                                tabular.setTopLine(tabular.cellIndex(r, c), lineSet);
-                       }
                break;
        }
 
        case Tabular::SET_LINE_BOTTOM:
        case Tabular::TOGGLE_LINE_BOTTOM: {
+               bool lineSet = (feature == Tabular::SET_LINE_BOTTOM)
+                              ? (value == "true") : !tabular.bottomLine(cur.idx());
                for (row_type r = sel_row_start; r <= sel_row_end; ++r)
-                       for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
-                               bool const lineSet = (feature == Tabular::SET_LINE_BOTTOM)
-                                          ? (value == "true") : !tabular.bottomLine(tabular.cellIndex(r, c));
+                       for (col_type c = sel_col_start; c <= sel_col_end; ++c)
                                tabular.setBottomLine(tabular.cellIndex(r, c), lineSet);
-                       }
                break;
        }
 
        case Tabular::SET_LINE_LEFT:
        case Tabular::TOGGLE_LINE_LEFT: {
+               bool lineSet = (feature == Tabular::SET_LINE_LEFT)
+                              ? (value == "true") : !tabular.leftLine(cur.idx());
                for (row_type r = sel_row_start; r <= sel_row_end; ++r)
-                       for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
-                               bool const lineSet = (feature == Tabular::SET_LINE_LEFT)
-                                       ? (value == "true") : !tabular.leftLine(tabular.cellIndex(r, c));
+                       for (col_type c = sel_col_start; c <= sel_col_end; ++c)
                                tabular.setLeftLine(tabular.cellIndex(r, c), lineSet);
-                       }
                break;
        }
 
        case Tabular::SET_LINE_RIGHT:
        case Tabular::TOGGLE_LINE_RIGHT: {
+               bool lineSet = (feature == Tabular::SET_LINE_RIGHT)
+                              ? (value == "true") : !tabular.rightLine(cur.idx());
                for (row_type r = sel_row_start; r <= sel_row_end; ++r)
-                       for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
-                               bool const lineSet = (feature == Tabular::SET_LINE_RIGHT)
-                                          ? (value == "true") : !tabular.rightLine(tabular.cellIndex(r, c));
+                       for (col_type c = sel_col_start; c <= sel_col_end; ++c)
                                tabular.setRightLine(tabular.cellIndex(r, c), lineSet);
-                       }
                break;
        }
 
@@ -6138,6 +6134,9 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
        }
 
+       case Tabular::SET_INNER_LINES:
+               setLinesInnerOnly = true;
+               // fall through
        case Tabular::SET_ALL_LINES:
                setLines = true;
                // fall through
@@ -6145,10 +6144,16 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                for (row_type r = sel_row_start; r <= sel_row_end; ++r)
                        for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
                                idx_type const cell = tabular.cellIndex(r, c);
-                               tabular.setTopLine(cell, setLines);
-                               tabular.setBottomLine(cell, setLines);
-                               tabular.setRightLine(cell, setLines);
-                               tabular.setLeftLine(cell, setLines);
+                               if (!setLinesInnerOnly || r != sel_row_start)
+                                       tabular.setTopLine(cell, setLines);
+                               if ((!setLinesInnerOnly || r != sel_row_end)
+                                   && (!setLines || r == sel_row_end))
+                                       tabular.setBottomLine(cell, setLines);
+                               if ((!setLinesInnerOnly || c != sel_col_end)
+                                   && (!setLines || c == sel_col_end))
+                                       tabular.setRightLine(cell, setLines);
+                               if ((!setLinesInnerOnly || c != sel_col_start))
+                                       tabular.setLeftLine(cell, setLines);
                        }
                break;