]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Check character encodability with pass-thru in command insets
[lyx.git] / src / insets / InsetTabular.cpp
index 43795e7d40a09a7b2bff3d0bf9ee931baa5c7719..9df7d463c3832dde51d9d04e4bd87868c4b9a12a 100644 (file)
@@ -137,10 +137,10 @@ TabularFeature tabularFeature[] =
        { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom", false },
        { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left", false },
        { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right", false },
-       { Tabular::TOGGLE_LTRIM_TOP, "toggle-ltrim-top", true },
-       { Tabular::TOGGLE_LTRIM_BOTTOM, "toggle-ltrim-bottom", true },
-       { Tabular::TOGGLE_RTRIM_TOP, "toggle-rtrim-top", true },
-       { Tabular::TOGGLE_RTRIM_BOTTOM, "toggle-rtrim-bottom", true },
+       { Tabular::TOGGLE_LTRIM_TOP, "toggle-ltrim-top", false },
+       { Tabular::TOGGLE_LTRIM_BOTTOM, "toggle-ltrim-bottom", false },
+       { Tabular::TOGGLE_RTRIM_TOP, "toggle-rtrim-top", false },
+       { Tabular::TOGGLE_RTRIM_BOTTOM, "toggle-rtrim-bottom", false },
        { Tabular::ALIGN_LEFT, "align-left", false },
        { Tabular::ALIGN_RIGHT, "align-right", false },
        { Tabular::ALIGN_CENTER, "align-center", false },
@@ -2403,6 +2403,11 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, string const & lang,
                                topltrims[c] = false;
                                toprtrims[c] = false;
                        }
+               // copy trimming to multicolumn parts
+               if (isPartOfMultiColumn(row, c)) {
+                       topltrims[c] = topltrims[c-1];
+                       toprtrims[c] = toprtrims[c-1];
+               }
                if (topline.find(c) != topline.end() && topline.find(c)->second)
                        ++nset;
                if ((topltrims.find(c) != topltrims.end() && topltrims.find(c)->second)
@@ -2426,6 +2431,11 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, string const & lang,
                for (auto & c : columns) {
                        if (topline.find(c)->second) {
                                col_type offset = 0;
+                               for (col_type j = 0 ; j < c; ++j)
+                                       if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
+                                               ++offset;
+                               while (isPartOfMultiColumn(row, c))
+                                       ++c;
                                string trim;
                                if (topltrims.find(c) != topltrims.end()
                                     && topltrims.find(c)->second)
@@ -2433,9 +2443,13 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, string const & lang,
                                string const firstcol = convert<string>(c + 1 + offset);
                                col_type cstart = c;
                                for ( ; c < ncols() - 1 && topline.find(c)->second ; ++c) {
+                                       if (isMultiColumn(cellIndex(row, c))
+                                           && c < ncols() - 1 && isPartOfMultiColumn(row, c + 1))
+                                               continue;
                                        if (c > cstart && topltrims.find(c) != topltrims.end()
                                                        && topltrims.find(c)->second) {
-                                               --c;
+                                               if (!isPartOfMultiColumn(row, c))
+                                                       --c;
                                                break;
                                        } else if (toprtrims.find(c) != toprtrims.end()
                                                   && toprtrims.find(c)->second)
@@ -2504,6 +2518,14 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const & lang,
                                topltrims[c] = false;
                                toprtrims[c] = false;
                        }
+               // copy trimming in multicolumn parts
+               if (isPartOfMultiColumn(row, c)) {
+                       topltrims[c] = topltrims[c-1];
+                       toprtrims[c] = toprtrims[c-1];
+                       bottomltrims[c] = bottomltrims[c-1];
+                       bottomrtrims[c] = bottomrtrims[c-1];
+               }
+                       
                nextrowset &= topline.find(c) != topline.end() && topline.find(c)->second;
        }
 
@@ -2541,7 +2563,8 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const & lang,
                                for (col_type j = 0 ; j < c; ++j)
                                        if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
                                                ++offset;
-
+                               while (isPartOfMultiColumn(row, c))
+                                       ++c;
                                string trim;
                                if (bottomltrims.find(c) != bottomltrims.end()
                                     && bottomltrims.find(c)->second)
@@ -2549,9 +2572,14 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const & lang,
                                string const firstcol = convert<string>(c + 1 + offset);
                                col_type cstart = c;
                                for ( ; c < ncols() - 1 && bottomline.find(c)->second ; ++c) {
+                                       if (isMultiColumn(cellIndex(row, c))
+                                           && c < ncols() - 1
+                                           && isPartOfMultiColumn(row, c + 1))
+                                               continue;
                                        if (c > cstart && bottomltrims.find(c) != bottomltrims.end()
-                                                       && bottomltrims.find(c)->second) {
-                                               --c;
+                                           && bottomltrims.find(c)->second) {
+                                               if (!isPartOfMultiColumn(row, c))
+                                                       --c;
                                                break;
                                        } else if (bottomrtrims.find(c) != bottomrtrims.end()
                                                   && bottomrtrims.find(c)->second)
@@ -4954,6 +4982,18 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PASTE:
                if (!tabularStackDirty()) {
+                       // Check if we have plain text or HTML with rows/columns.
+                       // and if so, pass over to LFUN_CLIPBOARD_PASTE
+                       if (theClipboard().hasTextContents(Clipboard::AnyTextType)
+                           && !theClipboard().hasTextContents(Clipboard::LyXTextType)) {
+                               docstring const clip =
+                                       theClipboard().getAsText(Clipboard::AnyTextType);
+                               if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
+                                       FuncRequest ncmd = FuncRequest(LFUN_CLIPBOARD_PASTE, cmd.argument());
+                                       doDispatch(cur, ncmd);
+                                       break;
+                               }
+                       }
                        if (!cur.selIsMultiCell())
                                cell(cur.idx())->dispatch(cur, cmd);
                        break;
@@ -5544,6 +5584,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
        // disable these with multiple cells selected
        case LFUN_INSET_INSERT:
        case LFUN_TABULAR_INSERT:
+       case LFUN_TABULAR_STYLE_INSERT:
        case LFUN_FLEX_INSERT:
        case LFUN_FLOAT_INSERT:
        case LFUN_FLOAT_WIDE_INSERT:
@@ -6956,20 +6997,26 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
        }
 
        size_t op = 0;
-       idx_type const cells = loctab->numberofcells;
+       idx_type cells = loctab->numberofcells;
        p = 0;
        cols = ocol;
        rows = loctab->nrows();
-       col_type const columns = loctab->ncols();
+       col_type columns = loctab->ncols();
 
-       while (cell < cells && p < len && row < rows &&
+       while (p < len &&
               (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos)
        {
                if (p >= len)
                        break;
                switch (buf[p]) {
                case '\t':
-                       // we can only set this if we are not too far right
+                       // append column if necessary
+                       if (cols == columns) {
+                               loctab->appendColumn(cols - 1);
+                               columns = loctab->ncols();
+                               cells = loctab->numberofcells;
+                               ++cell;
+                       }
                        if (cols < columns) {
                                shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
                                Font const font = bv.textMetrics(&inset->text()).
@@ -6991,6 +7038,12 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
                        }
                        cols = ocol;
                        ++row;
+                       // append row if necessary
+                       if (row == rows && p < len - 1) {
+                               loctab->appendRow(row - 1);
+                               rows = loctab->nrows();
+                               cells = loctab->numberofcells;
+                       }
                        if (row < rows)
                                cell = loctab->cellIndex(row, cols);
                        break;