]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetTabular.cpp
reduce line noise
[features.git] / src / insets / InsetTabular.cpp
index 285abd2881b3edd7ef4daa464a63275664c2acb1..9bdff844687ca9b5ace65d5f38ff37139cbf959b 100644 (file)
 
 #include "InsetTabular.h"
 
-#include "Buffer.h"
 #include "buffer_funcs.h"
+#include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "CoordCache.h"
 #include "Counters.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
-#include "CoordCache.h"
 #include "debug.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "gettext.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
-#include "Color.h"
-#include "callback.h"
 #include "Lexer.h"
+#include "LyXFunc.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
-#include "Paragraph.h"
 #include "paragraph_funcs.h"
+#include "Paragraph.h"
 #include "ParagraphParameters.h"
 #include "ParIterator.h"
-#include "Undo.h"
+#include "TextClass.h"
+#include "TextMetrics.h"
 
 #include "support/convert.h"
+#include "support/docstream.h"
 #include "support/lstrings.h"
 
 #include "frontends/alert.h"
@@ -54,6 +55,8 @@
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
 
+#include <boost/scoped_ptr.hpp>
+
 #include <sstream>
 #include <iostream>
 #include <limits>
@@ -430,7 +433,7 @@ bool getTokenValue(string const & str, char const * token, bool & flag)
 
 bool getTokenValue(string const & str, char const * token, Length & len)
 {
-       // set the lenght to be zero() as default as this it should be if not
+       // set the length to be zero() as default as this it should be if not
        // in the file format.
        len = Length();
        string tmp;
@@ -577,6 +580,12 @@ Tabular::ltType::ltType()
 {}
 
 
+Tabular::Tabular()
+{
+       // unusable now!
+}
+
+
 Tabular::Tabular(BufferParams const & bp, row_type rows_arg,
                       col_type columns_arg)
 {
@@ -2723,7 +2732,7 @@ 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
+                          bool onlydata, char_type delim) const
 {
        // first calculate the width of the single columns
        vector<unsigned int> clen(columnCount());
@@ -2767,7 +2776,9 @@ void Tabular::plaintext(Buffer const & buf, odocstream & os,
                        if (isPartOfMultiColumn(i, j))
                                continue;
                        if (onlydata && j > 0)
-                               os << delim;
+                               // we don't use operator<< for single UCS4 character.
+                               // see explanation in docstream.h
+                               os.put(delim);
                        plaintextPrintCell(buf, os, runparams,
                                           cell, i, j, clen, onlydata);
                        ++cell;
@@ -2813,8 +2824,8 @@ Tabular::getCellFromInset(Inset const * inset) const
 
        for (idx_type cell = 0, n = cellCount(); cell < n; ++cell)
                if (getCellInset(cell).get() == inset) {
-                       LYXERR(Debug::INSETTEXT) << "Tabular::getCellFromInset: "
-                               << "cell=" << cell << endl;
+                       LYXERR(Debug::INSETTEXT, "Tabular::getCellFromInset: "
+                               << "cell=" << cell);
                        return cell;
                }
 
@@ -2932,7 +2943,7 @@ void InsetTabular::read(Buffer const & buf, Lexer & lex)
 }
 
 
-bool InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
        //      mi.base.textwidth << "\n";
@@ -2986,9 +2997,6 @@ bool InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = tabular.rowAscent(0);
        dim.des = tabular.height() - dim.asc;
        dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
 }
 
 
@@ -3006,6 +3014,8 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
        x += scx_;
        x += ADD_TO_TABULAR_WIDTH;
 
+       bool const original_drawing_state = pi.pain.isDrawingEnabled();
+
        idx_type idx = 0;
        first_visible_cell = Tabular::npos;
        for (row_type i = 0; i < tabular.rowCount(); ++i) {
@@ -3029,7 +3039,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
                                pi.pain.setDrawingEnabled(false);
                                cell(idx)->draw(pi, cx, y);
                                drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
-                               pi.pain.setDrawingEnabled(true);
+                               pi.pain.setDrawingEnabled(original_drawing_state);
                        } else {
                                cell(idx)->draw(pi, cx, y);
                                drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
@@ -3062,7 +3072,7 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
 
        if (!cur.selection())
                return;
-       if (!ptr_cmp(&cur.inset(), this))
+       if (&cur.inset() != this)
                return;
 
        //resetPos(cur);
@@ -3086,7 +3096,7 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
                                int const w = tabular.columnWidth(cell);
                                if (i >= cs && i <= ce && j >= rs && j <= re)
                                        pi.pain.fillRectangle(xx, y, w, h,
-                                                             Color::selection);
+                                                             Color_selection);
                                xx += w;
                        }
                        y += h;
@@ -3105,12 +3115,12 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
 {
        int x2 = x + tabular.columnWidth(cell);
        bool on_off = false;
-       Color::color col = Color::tabularline;
-       Color::color onoffcol = Color::tabularonoffline;
+       ColorCode col = Color_tabularline;
+       ColorCode onoffcol = Color_tabularonoffline;
 
        if (erased) {
-               col = Color::deletedtext;
-               onoffcol = Color::deletedtext;
+               col = Color_deletedtext;
+               onoffcol = Color_deletedtext;
        }
 
        if (!tabular.topAlreadyDrawn(cell)) {
@@ -3151,7 +3161,7 @@ docstring const InsetTabular::editMessage() const
 void InsetTabular::edit(Cursor & cur, bool left)
 {
        //lyxerr << "InsetTabular::edit: " << this << endl;
-       finishUndo();
+       cur.finishUndo();
        cur.selection() = false;
        cur.push(*this);
        if (left) {
@@ -3197,8 +3207,8 @@ void InsetTabular::updateLabels(Buffer const & buf, ParIterator const & it)
 
 void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       LYXERR(Debug::DEBUG) << "# InsetTabular::doDispatch: cmd: " << cmd
-                            << "\n  cur:" << cur << endl;
+       LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
+                            << "\n  cur:" << cur);
        CursorSlice sl = cur.top();
        Cursor & bvcur = cur.bv().cursor();
 
@@ -3254,9 +3264,9 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CHAR_FORWARD:
                cell(cur.idx())->dispatch(cur, cmd);
                if (!cur.result().dispatched()) {
-                       isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
+                       moveNextCell(cur);
                        if (sl == cur.top())
-                               cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+                               cmd = FuncRequest(LFUN_FINISHED_FORWARD);
                        else
                                cur.dispatched();
                }
@@ -3266,14 +3276,40 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CHAR_BACKWARD:
                cell(cur.idx())->dispatch(cur, cmd);
                if (!cur.result().dispatched()) {
-                       isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
+                       movePrevCell(cur);
                        if (sl == cur.top())
-                               cmd = FuncRequest(LFUN_FINISHED_LEFT);
+                               cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
                        else
                                cur.dispatched();
                }
                break;
 
+       case LFUN_CHAR_RIGHT_SELECT:
+       case LFUN_CHAR_RIGHT:
+               //FIXME: for visual cursor, really move right
+               if (isRightToLeft(cur))
+                       lyx::dispatch(FuncRequest(
+                               cmd.action == LFUN_CHAR_RIGHT_SELECT ?
+                                       LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
+               else
+                       lyx::dispatch(FuncRequest(
+                               cmd.action == LFUN_CHAR_RIGHT_SELECT ?
+                                       LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
+               break;
+
+       case LFUN_CHAR_LEFT_SELECT:
+       case LFUN_CHAR_LEFT:
+               //FIXME: for visual cursor, really move left
+               if (isRightToLeft(cur))
+                       lyx::dispatch(FuncRequest(
+                               cmd.action == LFUN_CHAR_LEFT_SELECT ?
+                                       LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
+               else
+                       lyx::dispatch(FuncRequest(
+                               cmd.action == LFUN_CHAR_LEFT_SELECT ?
+                                       LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
+               break;
+
        case LFUN_DOWN_SELECT:
        case LFUN_DOWN:
                cell(cur.idx())->dispatch(cur, cmd);
@@ -3290,9 +3326,9 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
                        }
                if (sl == cur.top()) {
-                       // we trick it to go to the RIGHT after leaving the
+                       // we trick it to go to forward after leaving the
                        // tabular.
-                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_FORWARD);
                        cur.undispatched();
                }
                break;
@@ -3372,7 +3408,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FILE_INSERT_PLAINTEXT_PARA:
        case LFUN_FILE_INSERT_PLAINTEXT: {
                // FIXME UNICODE
-               docstring const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
+               docstring const tmpstr = cur.bv().contentsOfPlaintextFile(to_utf8(cmd.argument()), false);
                if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), tmpstr, false))
                        cur.undispatched();
                break;
@@ -3381,7 +3417,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CUT:
                if (tablemode(cur)) {
                        if (copySelection(cur)) {
-                               recordUndoInset(cur, Undo::DELETE);
+                               cur.recordUndoInset(DELETE_UNDO);
                                cutSelection(cur);
                        }
                }
@@ -3392,7 +3428,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CHAR_DELETE_BACKWARD:
        case LFUN_CHAR_DELETE_FORWARD:
                if (tablemode(cur)) {
-                       recordUndoInset(cur, Undo::DELETE);
+                       cur.recordUndoInset(DELETE_UNDO);
                        cutSelection(cur);
                }
                else
@@ -3403,7 +3439,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (!cur.selection())
                        break;
                if (tablemode(cur)) {
-                       finishUndo();
+                       cur.finishUndo();
                        copySelection(cur);
                } else
                        cell(cur.idx())->dispatch(cur, cmd);
@@ -3434,7 +3470,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PASTE:
                if (tabularStackDirty() && theClipboard().isInternal()) {
-                       recordUndoInset(cur, Undo::INSERT);
+                       cur.recordUndoInset(INSERT_UNDO);
                        pasteClipboard(cur);
                        break;
                }
@@ -3447,7 +3483,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FONT_NOUN:
        case LFUN_FONT_ITAL:
        case LFUN_FONT_FRAK:
-       case LFUN_FONT_CODE:
+       case LFUN_FONT_TYPEWRITER:
        case LFUN_FONT_SANS:
        case LFUN_FONT_FREE_APPLY:
        case LFUN_FONT_FREE_UPDATE:
@@ -3734,7 +3770,6 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
        // disable in non-fixed-width cells
        case LFUN_BREAK_LINE:
        case LFUN_BREAK_PARAGRAPH:
-       case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
        case LFUN_BREAK_PARAGRAPH_SKIP: {
                if (tabular.getPWidth(cur.idx()).zero()) {
                        status.enabled(false);
@@ -3751,7 +3786,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        return cell(cur.idx())->getStatus(cur, cmd, status);
 
        case LFUN_INSET_MODIFY:
-               if (translate(cmd.getArg(0)) == TABULAR_CODE) {
+               if (insetCode(cmd.getArg(0)) == TABULAR_CODE) {
                        status.enabled(true);
                        return true;
                }
@@ -3792,7 +3827,7 @@ int InsetTabular::docbook(Buffer const & buf, odocstream & os,
        // if the table is inside a float it doesn't need the informaltable
        // wrapper. Search for it.
        for (master = owner(); master; master = master->owner())
-               if (master->lyxCode() == Inset::FLOAT_CODE)
+               if (master->lyxCode() == FLOAT_CODE)
                        break;
 #endif
 
@@ -4125,7 +4160,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
        }
 
-       recordUndoInset(cur, Undo::ATOMIC);
+       cur.recordUndoInset(ATOMIC_UNDO);
 
        getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
        row_type const row = tabular.cellRow(cur.idx());