]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Fix date inset except on windows (bug 9925)
[lyx.git] / src / insets / InsetTabular.cpp
index 24bab873acf68e738ec0176213e9f42dbcfe5789..437ac7eca75a5f7d10bec8310300d9c8abf90148 100644 (file)
@@ -151,6 +151,7 @@ TabularFeature tabularFeature[] =
        { Tabular::SET_MROFFSET, "set-mroffset", true },
        { Tabular::SET_ALL_LINES, "set-all-lines", false },
        { Tabular::UNSET_ALL_LINES, "unset-all-lines", false },
+       { Tabular::TOGGLE_LONGTABULAR, "toggle-longtabular", false },
        { Tabular::SET_LONGTABULAR, "set-longtabular", false },
        { Tabular::UNSET_LONGTABULAR, "unset-longtabular", false },
        { Tabular::SET_PWIDTH, "set-pwidth", true },
@@ -177,6 +178,7 @@ TabularFeature tabularFeature[] =
        { Tabular::UNSET_LTCAPTION, "unset-ltcaption", false },
        { Tabular::SET_SPECIAL_COLUMN, "set-special-column", true },
        { Tabular::SET_SPECIAL_MULTICOLUMN, "set-special-multicolumn", true },
+       { Tabular::TOGGLE_BOOKTABS, "toggle-booktabs", false },
        { Tabular::SET_BOOKTABS, "set-booktabs", false },
        { Tabular::UNSET_BOOKTABS, "unset-booktabs", false },
        { Tabular::SET_TOP_SPACE, "set-top-space", true },
@@ -652,7 +654,7 @@ Tabular::ColumnData::ColumnData()
 
 
 Tabular::ltType::ltType()
-       : topDL(false),
+       : set(false), topDL(false),
          bottomDL(false),
          empty(false)
 {}
@@ -2572,6 +2574,9 @@ void Tabular::TeXRow(otexstream & os, row_type row,
                shared_ptr<InsetTableCell> inset = cellInset(cell);
 
                Paragraph const & par = inset->paragraphs().front();
+
+               os.texrow().forceStart(par.id(), 0);
+
                bool rtl = par.isRTL(buffer().params())
                        && !par.empty()
                        && getPWidth(cell).zero()
@@ -2673,14 +2678,16 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 void Tabular::latex(otexstream & os, OutputParams const & runparams) const
 {
        bool const is_tabular_star = !tabular_width.zero();
+       TexRow::RowEntry pos = TexRow::textEntry(runparams.lastid,
+                                                                                        runparams.lastpos);
 
        //+---------------------------------------------------------------------
        //+                      first the opening preamble                    +
        //+---------------------------------------------------------------------
 
        os << safebreakln;
-       if (runparams.lastid != -1)
-               os.texrow().start(runparams.lastid, runparams.lastpos);
+       if (!TexRow::isNone(pos))
+               os.texrow().start(pos);
 
        if (rotate != 0)
                os << "\\begin{turn}{" << convert<string>(rotate) << "}\n";
@@ -2809,6 +2816,9 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
 
        if (rotate != 0)
                os << breakln << "\\end{turn}";
+
+       if (!TexRow::isNone(pos))
+               os.texrow().start(pos);
 }
 
 
@@ -3439,9 +3449,10 @@ docstring InsetTableCell::asString(bool intoInsets)
 }
 
 
-void InsetTableCell::addToToc(DocIterator const & di, bool output_active) const
+void InsetTableCell::addToToc(DocIterator const & di, bool output_active,
+                                                         UpdateType utype) const
 {
-       InsetText::iterateForToc(di, output_active);
+       InsetText::iterateForToc(di, output_active, utype);
 }
 
 
@@ -3463,7 +3474,7 @@ docstring InsetTableCell::xhtml(XHTMLStream & xs, OutputParams const & rp) const
 InsetTabular::InsetTabular(Buffer * buf, row_type rows,
                           col_type columns)
        : Inset(buf), tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))),
-         rowselect_(false), colselect_(false)
+         first_visible_cell_(0), offset_valign_(0), rowselect_(false), colselect_(false)
 {
 }
 
@@ -3732,7 +3743,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
        bool const original_selection_state = pi.selected;
 
        idx_type idx = 0;
-       first_visible_cell = Tabular::npos;
+       first_visible_cell_ = Tabular::npos;
 
        int yy = y + offset_valign_;
        for (row_type r = 0; r < tabular.nrows(); ++r) {
@@ -3748,8 +3759,8 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
                                continue;
                        }
 
-                       if (first_visible_cell == Tabular::npos)
-                               first_visible_cell = idx;
+                       if (first_visible_cell_ == Tabular::npos)
+                               first_visible_cell_ = idx;
 
                        pi.selected |= isCellSelected(cur, r, c);
                        int const cx = nx + tabular.textHOffset(idx);
@@ -3927,13 +3938,14 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype)
 }
 
 
-void InsetTabular::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetTabular::addToToc(DocIterator const & cpit, bool output_active,
+                                                       UpdateType utype) const
 {
        DocIterator dit = cpit;
        dit.forwardPos();
        size_t const end = dit.nargs();
        for ( ; dit.idx() < end; dit.top().forwardIdx())
-               cell(dit.idx())->addToToc(dit, output_active);
+               cell(dit.idx())->addToToc(dit, output_active, utype);
 }
 
 
@@ -4254,7 +4266,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 //             int const t =   cur.bv().top_y() + cur.bv().height();
 //             if (t < yo() + tabular.getHeightOfTabular()) {
 //                     cur.bv().scrollDocView(t, true);
-//                     cur.idx() = tabular.cellBelow(first_visible_cell) + col;
+//                     cur.idx() = tabular.cellBelow(first_visible_cell_) + col;
 //             } else {
 //                     cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
 //             }
@@ -4273,7 +4285,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 //                     if (yo() > 0)
 //                             cur.idx() = col;
 //                     else
-//                             cur.idx() = tabular.cellBelow(first_visible_cell) + col;
+//                             cur.idx() = tabular.cellBelow(first_visible_cell_) + col;
 //             } else {
 //                     cur.idx() = col;
 //             }
@@ -4612,9 +4624,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
 
                case Tabular::SET_LINE_TOP:
                case Tabular::SET_LINE_BOTTOM:
+                       status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
+                       break;
+
                case Tabular::SET_LINE_LEFT:
                case Tabular::SET_LINE_RIGHT:
-                       status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
+                       status.setEnabled(!tabular.use_booktabs
+                                         && !tabular.ltCaption(tabular.cellRow(cur.idx())));
                        break;
 
                case Tabular::TOGGLE_LINE_TOP:
@@ -4628,12 +4644,14 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
 
                case Tabular::TOGGLE_LINE_LEFT:
-                       status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
+                       status.setEnabled(!tabular.use_booktabs
+                                         && !tabular.ltCaption(tabular.cellRow(cur.idx())));
                        status.setOnOff(tabular.leftLine(cur.idx()));
                        break;
 
                case Tabular::TOGGLE_LINE_RIGHT:
-                       status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
+                       status.setEnabled(!tabular.use_booktabs
+                                         && !tabular.ltCaption(tabular.cellRow(cur.idx())));
                        status.setOnOff(tabular.rightLine(cur.idx()));
                        break;
 
@@ -4702,6 +4720,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
 
                case Tabular::SET_LONGTABULAR:
+               case Tabular::TOGGLE_LONGTABULAR:
                        // setting as longtable is not allowed when table is inside a float
                        if (cur.innerInsetOfType(FLOAT_CODE) != 0
                                || cur.innerInsetOfType(WRAP_CODE) != 0)
@@ -4850,6 +4869,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setOnOff(tabular.ltCaption(sel_row_start));
                        break;
 
+               case Tabular::TOGGLE_BOOKTABS:
                case Tabular::SET_BOOKTABS:
                        status.setOnOff(tabular.use_booktabs);
                        break;
@@ -5402,10 +5422,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
 
        case Tabular::ALIGN_DECIMAL:
-               if (tabular.column_info[tabular.cellColumn(cur.idx())].alignment == LYX_ALIGN_DECIMAL)
-                       setAlign = LYX_ALIGN_CENTER;
-               else
-                       setAlign = LYX_ALIGN_DECIMAL;
+               setAlign = LYX_ALIGN_DECIMAL;
                break;
 
        case Tabular::M_VALIGN_TOP:
@@ -5748,6 +5765,13 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                }
                break;
 
+       case Tabular::TOGGLE_LONGTABULAR:
+               if (tabular.is_long_tabular)
+                       tabularFeatures(cur, Tabular::UNSET_LONGTABULAR);
+               else
+                       tabular.is_long_tabular = true;
+               break;
+
        case Tabular::SET_LONGTABULAR:
                tabular.is_long_tabular = true;
                break;
@@ -5888,7 +5912,9 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                cur.setSelection(false);
                // If a row is set as caption, then also insert
                // a caption. Otherwise the LaTeX output is broken.
-               lyx::dispatch(FuncRequest(LFUN_INSET_SELECT_ALL));
+               // Select cell if it is non-empty
+               if (cur.lastpos() > 0 || cur.lastpit() > 0)
+                       lyx::dispatch(FuncRequest(LFUN_INSET_SELECT_ALL));
                lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
                break;
        }
@@ -5914,6 +5940,10 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
        }
 
+       case Tabular::TOGGLE_BOOKTABS:
+               tabular.use_booktabs = !tabular.use_booktabs;
+               break;
+
        case Tabular::SET_BOOKTABS:
                tabular.use_booktabs = true;
                break;
@@ -6230,7 +6260,6 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
        if (usePaste) {
                paste_tabular.reset(new Tabular(buffer_, rows, maxCols));
                loctab = paste_tabular.get();
-               cols = 0;
                dirtyTabularStack(true);
        } else {
                loctab = &tabular;