]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
pimpl not needed here
[lyx.git] / src / insets / InsetTabular.cpp
index 7041004107d2ccc7221a7f7153384ecb551775e3..a0c03179273ef4581a83b76fc3ff34872fee19a2 100644 (file)
@@ -24,7 +24,6 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
-#include "Color.h"
 #include "CoordCache.h"
 #include "Counters.h"
 #include "Cursor.h"
@@ -37,6 +36,7 @@
 #include "Language.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
+#include "LyXFunc.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
 #include "paragraph_funcs.h"
@@ -44,9 +44,9 @@
 #include "ParagraphParameters.h"
 #include "ParIterator.h"
 #include "TextMetrics.h"
-#include "Undo.h"
 
 #include "support/convert.h"
+#include "support/docstream.h"
 #include "support/lstrings.h"
 
 #include "frontends/alert.h"
@@ -54,6 +54,8 @@
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
 
+#include <boost/scoped_ptr.hpp>
+
 #include <sstream>
 #include <iostream>
 #include <limits>
@@ -2729,7 +2731,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());
@@ -2773,7 +2775,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;
@@ -3065,7 +3069,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);
@@ -3089,7 +3093,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;
@@ -3108,12 +3112,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)) {
@@ -3154,7 +3158,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) {
@@ -3257,9 +3261,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();
                }
@@ -3269,14 +3273,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);
@@ -3293,9 +3323,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;
@@ -3384,7 +3414,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);
                        }
                }
@@ -3395,7 +3425,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
@@ -3406,7 +3436,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);
@@ -3437,7 +3467,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;
                }
@@ -4127,7 +4157,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());