]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Show corners of mathed with mouse hover, details see bug 3825
[lyx.git] / src / insets / InsetTabular.cpp
index 5617b9984ed3d01ac1325e998ec0da5377a81ae0..5d14a54eafae45de495623b54347475c597718ca 100644 (file)
@@ -151,8 +151,10 @@ TabularFeature tabularFeature[] =
        { Tabular::SET_MPWIDTH, "set-mpwidth" },
        { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
        { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
+       { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular" },
        { Tabular::SET_ROTATE_CELL, "set-rotate-cell" },
        { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
+       { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell" },
        { Tabular::SET_USEBOX, "set-usebox" },
        { Tabular::SET_LTHEAD, "set-lthead" },
        { Tabular::UNSET_LTHEAD, "unset-lthead" },
@@ -1532,11 +1534,11 @@ void Tabular::read(Buffer const & buf, Lexer & lex)
                getTokenValue(line, "topline", row_info[i].top_line);
                getTokenValue(line, "bottomline", row_info[i].bottom_line);
                getTokenValue(line, "topspace", row_info[i].top_space,
-                             row_info[i].top_space_default);
+                             row_info[i].top_space_default);
                getTokenValue(line, "bottomspace", row_info[i].bottom_space,
-                             row_info[i].bottom_space_default);
+                             row_info[i].bottom_space_default);
                getTokenValue(line, "interlinespace", row_info[i].interline_space,
-                             row_info[i].interline_space_default);
+                             row_info[i].interline_space_default);
                getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
                getTokenValue(line, "endhead", row_info[i].endhead);
                getTokenValue(line, "endfoot", row_info[i].endfoot);
@@ -2268,7 +2270,7 @@ int Tabular::TeXRow(odocstream & os, row_type i, Buffer const & buf,
                }
                ++ret;
        }
-       
+
        for (col_type j = 0; j < columns_; ++j) {
                if (isPartOfMultiColumn(i, j))
                        continue;
@@ -2280,8 +2282,13 @@ int Tabular::TeXRow(odocstream & os, row_type i, Buffer const & buf,
                        && !par.empty()
                        && getPWidth(cell).zero();
 
-               if (rtl)
-                       os << "\\R{";
+               if (rtl) {
+                       if (par.getParLanguage(buf.params())->lang() ==
+                       "farsi")
+                               os << "\\textFR{";
+                       else
+                               os << "\\R{";
+               }
                ret += inset->latex(buf, os, runparams);
                if (rtl)
                        os << '}';
@@ -2575,7 +2582,7 @@ int Tabular::docbook(Buffer const & buf, odocstream & os,
 
 
 bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
-                                   vector<unsigned int> const & clen) const
+                                  vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
        idx_type const n = numberOfCellsInRow(fcell) + fcell;
@@ -2623,7 +2630,7 @@ bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
 
 
 bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
-                                      vector<unsigned int> const & clen) const
+                                     vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
        idx_type const n = numberOfCellsInRow(fcell) + fcell;
@@ -2722,8 +2729,8 @@ void Tabular::plaintextPrintCell(Buffer const & buf, odocstream & os,
 
 
 void Tabular::plaintext(Buffer const & buf, odocstream & os,
-                           OutputParams const & runparams, int const depth,
-                           bool onlydata, unsigned char delim) const
+                          OutputParams const & runparams, int const depth,
+                          bool onlydata, unsigned char delim) const
 {
        // first calculate the width of the single columns
        vector<unsigned int> clen(columns_);
@@ -2769,7 +2776,7 @@ void Tabular::plaintext(Buffer const & buf, odocstream & os,
                        if (onlydata && j > 0)
                                os << delim;
                        plaintextPrintCell(buf, os, runparams,
-                                          cell, i, j, clen, onlydata);
+                                          cell, i, j, clen, onlydata);
                        ++cell;
                }
                os << endl;
@@ -3103,8 +3110,8 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
        Color::color onoffcol = Color::tabularonoffline;
 
        if (erased) {
-               col = Color::strikeout;
-               onoffcol = Color::strikeout;
+               col = Color::deletedtext;
+               onoffcol = Color::deletedtext;
        }
 
        if (!tabular.topAlreadyDrawn(cell)) {
@@ -3181,8 +3188,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_PRESS:
                //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
 
-               if (cmd.button() == mouse_button::button1 
-                   || (cmd.button() == mouse_button::button3 
+               if (cmd.button() == mouse_button::button1
+                   || (cmd.button() == mouse_button::button3
                        && (&bvcur.selBegin().inset() != this || !tablemode(bvcur)))) {
                        if (!bvcur.selection() && !cur.bv().mouseSetCursor(cur))
                                cur.noUpdate();
@@ -3194,7 +3201,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 
                if (cmd.button() == mouse_button::button2) {
                        if (cap::selection()) {
-                               // See comment in LyXText::dispatch why we
+                               // See comment in Text::dispatch why we
                                // do this
                                // FIXME This does not use paste_tabular,
                                // another reason why paste_tabular should go.
@@ -3202,9 +3209,11 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cmd = FuncRequest(LFUN_PASTE, "0");
                        } else {
                                cmd = FuncRequest(LFUN_PRIMARY_SELECTION_PASTE,
-                                                 "paragraph");
+                                                 "paragraph");
                        }
                        doDispatch(cur, cmd);
+                       cur.bv().buffer()->markDirty();
+                       cur.bv().mouseSetCursor(cur);
                }
                break;
 
@@ -3284,7 +3293,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                cell(cur.idx())->dispatch(cur, cmd);
                cur.dispatched(); // override the cell's decision
                if (sl == cur.top())
-                       // if our LyXText didn't do anything to the cursor
+                       // if our Text didn't do anything to the cursor
                        // then we try to put the cursor into the cell below
                        // setting also the right targetX.
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
@@ -3314,13 +3323,13 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                cell(cur.idx())->dispatch(cur, cmd);
                cur.dispatched(); // override the cell's decision
                if (sl == cur.top())
-                       // if our LyXText didn't do anything to the cursor
+                       // if our Text didn't do anything to the cursor
                        // then we try to put the cursor into the cell above
                        // setting also the right targetX.
                        if (tabular.row_of_cell(cur.idx()) != 0) {
                                cur.idx() = tabular.getCellAbove(cur.idx());
                                cur.pit() = cur.lastpit();
-                               LyXText const * text = cell(cur.idx())->getText(0);
+                               Text const * text = cell(cur.idx())->getText(0);
                                TextMetrics const & tm = cur.bv().textMetrics(text);
                                ParagraphMetrics const & pm =
                                        tm.parMetrics(cur.lastpit());
@@ -3334,7 +3343,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                                }
                        }
                if (sl == cur.top()) {
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
+                       cmd = FuncRequest(LFUN_UP);
                        cur.undispatched();
                }
                break;
@@ -3542,11 +3551,12 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
 
                row_type sel_row_start = 0;
                row_type sel_row_end = 0;
-               col_type dummy;
+               col_type sel_col_start = 0;
+               col_type sel_col_end = 0;
                Tabular::ltType dummyltt;
                bool flag = true;
 
-               getSelection(cur, sel_row_start, sel_row_end, dummy, dummy);
+               getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
 
                switch (action) {
                case Tabular::SET_PWIDTH:
@@ -3647,6 +3657,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setOnOff(!tabular.isLongTabular());
                        break;
 
+               case Tabular::TOGGLE_ROTATE_TABULAR:
                case Tabular::SET_ROTATE_TABULAR:
                        status.setOnOff(tabular.getRotateTabular());
                        break;
@@ -3655,12 +3666,15 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setOnOff(!tabular.getRotateTabular());
                        break;
 
+               case Tabular::TOGGLE_ROTATE_CELL:
                case Tabular::SET_ROTATE_CELL:
-                       status.setOnOff(tabular.getRotateCell(cur.idx()));
+                       status.setOnOff(!oneCellHasRotationState(false,
+                               sel_row_start, sel_row_end, sel_col_start, sel_col_end));
                        break;
 
                case Tabular::UNSET_ROTATE_CELL:
-                       status.setOnOff(!tabular.getRotateCell(cur.idx()));
+                       status.setOnOff(!oneCellHasRotationState(true,
+                               sel_row_start, sel_row_end, sel_col_start, sel_col_end));
                        break;
 
                case Tabular::SET_USEBOX:
@@ -3784,14 +3798,14 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 
 int InsetTabular::latex(Buffer const & buf, odocstream & os,
-                        OutputParams const & runparams) const
+                       OutputParams const & runparams) const
 {
        return tabular.latex(buf, os, runparams);
 }
 
 
 int InsetTabular::plaintext(Buffer const & buf, odocstream & os,
-                            OutputParams const & runparams) const
+                           OutputParams const & runparams) const
 {
        os << '\n'; // output table on a new line
        int const dp = runparams.linelen > 0 ? runparams.depth : 0;
@@ -3801,7 +3815,7 @@ int InsetTabular::plaintext(Buffer const & buf, odocstream & os,
 
 
 int InsetTabular::docbook(Buffer const & buf, odocstream & os,
-                          OutputParams const & runparams) const
+                         OutputParams const & runparams) const
 {
        int ret = 0;
        Inset * master = 0;
@@ -4046,7 +4060,7 @@ bool InsetTabular::tabularFeatures(Cursor & cur, string const & what)
 
                if (tmp == what.substr(0, tmp.length())) {
                        //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
-                       //tabularFeatures[i].feature.length())) 
+                       //tabularFeatures[i].feature.length()))
                        action = tabularFeature[i].action;
                        break;
                }
@@ -4079,6 +4093,20 @@ static void checkLongtableSpecial(Tabular::ltType & ltt,
        }
 }
 
+bool InsetTabular::oneCellHasRotationState(bool rotated,
+               row_type row_start, row_type row_end,
+               col_type col_start, col_type col_end) const {
+
+       for (row_type i = row_start; i <= row_end; ++i) {
+               for (col_type j = col_start; j <= col_end; ++j) {
+                       if (tabular.getRotateCell(tabular.getCellNumber(i, j))
+                               == rotated) {
+                               return true;
+                       }
+               }
+       }
+       return false;
+}
 
 void InsetTabular::tabularFeatures(Cursor & cur,
        Tabular::Feature feature, string const & value)
@@ -4339,6 +4367,10 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                tabular.setRotateTabular(false);
                break;
 
+       case Tabular::TOGGLE_ROTATE_TABULAR:
+               tabular.setRotateTabular(!tabular.getRotateTabular());
+               break;
+
        case Tabular::SET_ROTATE_CELL:
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
                        for (col_type j = sel_col_start; j <= sel_col_end; ++j)
@@ -4353,6 +4385,18 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                                        tabular.getCellNumber(i, j), false);
                break;
 
+       case Tabular::TOGGLE_ROTATE_CELL:
+               {
+               bool oneNotRotated = oneCellHasRotationState(false,
+                       sel_row_start, sel_row_end, sel_col_start, sel_col_end);
+
+               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.setRotateCell(tabular.getCellNumber(i, j),
+                                                                         oneNotRotated);
+               }
+               break;
+
        case Tabular::SET_USEBOX: {
                Tabular::BoxType val = Tabular::BoxType(convert<int>(value));
                if (val == tabular.getUsebox(cur.idx()))
@@ -4558,7 +4602,7 @@ bool InsetTabular::pasteClipboard(Cursor & cur)
                        tabular.setCellInset(r2, c2, inset);
                        // FIXME: change tracking (MG)
                        inset->setChange(Change(cur.buffer().params().trackChanges ?
-                                               Change::INSERTED : Change::UNCHANGED));
+                                               Change::INSERTED : Change::UNCHANGED));
                        cur.pos() = 0;
                }
        }
@@ -4627,7 +4671,7 @@ void InsetTabular::getSelection(Cursor & cur,
 }
 
 
-LyXText * InsetTabular::getText(int idx) const
+Text * InsetTabular::getText(int idx) const
 {
        return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
 }
@@ -4727,7 +4771,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
                                Paragraph & par = inset->text_.getPar(0);
                                Font const font = inset->text_.getFont(buffer, par, 0);
                                inset->setText(buf.substr(op, p - op), font,
-                                              buffer.params().trackChanges);
+                                              buffer.params().trackChanges);
                                ++cols;
                                ++cell;
                        }
@@ -4739,7 +4783,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
                                Paragraph & par = inset->text_.getPar(0);
                                Font const font = inset->text_.getFont(buffer, par, 0);
                                inset->setText(buf.substr(op, p - op), font,
-                                              buffer.params().trackChanges);
+                                              buffer.params().trackChanges);
                        }
                        cols = ocol;
                        ++row;