X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetTabular.cpp;h=f69da2b74bf8f967929aea94691a48bce380343d;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=a0c03179273ef4581a83b76fc3ff34872fee19a2;hpb=a8cd9a4b8fd325b00c75f601c66c6d618ba276db;p=lyx.git diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index a0c0317927..f69da2b74b 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -28,11 +28,9 @@ #include "Counters.h" #include "Cursor.h" #include "CutAndPaste.h" -#include "debug.h" #include "DispatchResult.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "gettext.h" #include "Language.h" #include "LaTeXFeatures.h" #include "Lexer.h" @@ -43,49 +41,37 @@ #include "Paragraph.h" #include "ParagraphParameters.h" #include "ParIterator.h" +#include "TextClass.h" #include "TextMetrics.h" -#include "support/convert.h" -#include "support/docstream.h" -#include "support/lstrings.h" - #include "frontends/alert.h" #include "frontends/Clipboard.h" #include "frontends/Painter.h" #include "frontends/Selection.h" + +#include "support/convert.h" +#include "support/debug.h" +#include "support/docstream.h" +#include "support/FileName.h" +#include "support/gettext.h" +#include "support/lstrings.h" + #include #include #include #include +#include -using std::abs; -using std::endl; -using std::getline; -using std::istream; -using std::istringstream; -using std::max; -using std::ostream; -using std::ostringstream; -using std::string; -using std::swap; -using std::vector; - -#ifndef CXX_GLOBAL_CSTD -using std::strlen; -#endif +using namespace std; +using namespace lyx::support; using boost::shared_ptr; using boost::dynamic_pointer_cast; namespace lyx { -using support::prefixIs; -using support::ltrim; -using support::rtrim; -using support::suffixIs; - using cap::dirtyTabularStack; using cap::tabularStackDirty; @@ -178,7 +164,7 @@ TabularFeature tabularFeature[] = }; -class FeatureEqual : public std::unary_function { +class FeatureEqual : public unary_function { public: FeatureEqual(Tabular::Feature feature) : feature_(feature) {} @@ -472,7 +458,7 @@ string const featureAsString(Tabular::Feature feature) { TabularFeature * end = tabularFeature + sizeof(tabularFeature) / sizeof(TabularFeature); - TabularFeature * it = std::find_if(tabularFeature, end, + TabularFeature * it = find_if(tabularFeature, end, FeatureEqual(feature)); return (it == end) ? string() : it->feature; } @@ -499,7 +485,9 @@ Tabular::cellstruct::cellstruct(BufferParams const & bp) usebox(BOX_NONE), rotate(false), inset(new InsetText(bp)) -{} +{ + inset->paragraphs().back().layout(bp.getTextClass().emptyLayout()); +} Tabular::cellstruct::cellstruct(cellstruct const & cs) @@ -1105,7 +1093,7 @@ void toggleFixedWidth(Cursor & cur, InsetText * inset, bool fixedWidth) cur.push(*inset); // undo information has already been recorded inset->getText(0)->setLayout(cur.bv().buffer(), 0, cur.lastpit() + 1, - bp.getTextClass().defaultLayoutName()); + bp.getTextClass().emptyLayoutName()); cur.pop(); } @@ -1976,7 +1964,8 @@ int Tabular::TeXTopHLine(odocstream & os, row_type row) const ++tmp; } if (use_booktabs && row == 0) { - os << "\\toprule "; + if (topLine(fcell)) + os << "\\toprule "; } else if (tmp == n - fcell) { os << (use_booktabs ? "\\midrule " : "\\hline "); } else if (tmp) { @@ -2012,7 +2001,8 @@ int Tabular::TeXBottomHLine(odocstream & os, row_type row) const ++tmp; } if (use_booktabs && row == rowCount() - 1) { - os << "\\bottomrule"; + if (bottomLine(fcell)) + os << "\\bottomrule"; } else if (tmp == n - fcell) { os << (use_booktabs ? "\\midrule" : "\\hline"); } else if (tmp) { @@ -2823,8 +2813,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; } @@ -2913,6 +2903,15 @@ void InsetTabular::buffer(Buffer const * b) } +bool InsetTabular::insetAllowed(InsetCode code) const +{ + if (code == MATHMACRO_CODE) + return false; + + return true; +} + + void InsetTabular::write(Buffer const & buf, ostream & os) const { os << "Tabular" << endl; @@ -3013,6 +3012,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) { @@ -3036,7 +3037,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_); @@ -3155,13 +3156,13 @@ docstring const InsetTabular::editMessage() const } -void InsetTabular::edit(Cursor & cur, bool left) +void InsetTabular::edit(Cursor & cur, bool front, EntryDirection) { //lyxerr << "InsetTabular::edit: " << this << endl; cur.finishUndo(); cur.selection() = false; cur.push(*this); - if (left) { + if (front) { if (isRightToLeft(cur)) cur.idx() = tabular.getLastCellInRow(0); else @@ -3204,8 +3205,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(); @@ -3405,8 +3406,18 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_FILE_INSERT_PLAINTEXT_PARA: case LFUN_FILE_INSERT_PLAINTEXT: { // FIXME UNICODE - docstring const tmpstr = cur.bv().contentsOfPlaintextFile(to_utf8(cmd.argument()), false); - if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), tmpstr, false)) + docstring const tmpstr = cur.bv().contentsOfPlaintextFile( + FileName(to_utf8(cmd.argument()))); + if (tmpstr.empty()) + break; + cur.recordUndoInset(INSERT_UNDO); + if (insertPlaintextString(cur.bv(), tmpstr, false)) { + // content has been replaced, + // so cursor might be invalid + cur.pos() = cur.lastpos(); + cur.pit() = cur.lastpit(); + bvcur.setCursor(cur); + } else cur.undispatched(); break; } @@ -3452,10 +3463,12 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) // pass to InsertPlaintextString, but // only if we have multi-cell content if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) { + cur.recordUndoInset(INSERT_UNDO); if (insertPlaintextString(cur.bv(), clip, false)) { // content has been replaced, // so cursor might be invalid cur.pos() = cur.lastpos(); + cur.pit() = cur.lastpit(); bvcur.setCursor(cur); break; } @@ -3466,7 +3479,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_PASTE: - if (tabularStackDirty() && theClipboard().isInternal()) { + if (tabularStackDirty() && theClipboard().isInternal() || + !theClipboard().hasInternal() && theClipboard().hasLyXContents()) { cur.recordUndoInset(INSERT_UNDO); pasteClipboard(cur); break; @@ -3765,7 +3779,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, } // disable in non-fixed-width cells - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: case LFUN_BREAK_PARAGRAPH: case LFUN_BREAK_PARAGRAPH_SKIP: { if (tabular.getPWidth(cur.idx()).zero()) { @@ -3942,7 +3956,7 @@ void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const { idx_type idx_min = 0; - int dist_min = std::numeric_limits::max(); + int dist_min = numeric_limits::max(); for (idx_type i = 0, n = nargs(); i != n; ++i) { if (bv.coordCache().getInsets().has(tabular.getCellInset(i).get())) { int const d = dist(bv, i, x, y); @@ -4692,7 +4706,7 @@ void InsetTabular::rejectChanges(BufferParams const & bparams) } -bool InsetTabular::forceDefaultParagraphs(idx_type cell) const +bool InsetTabular::allowParagraphCustomization(idx_type cell) const { return tabular.getPWidth(cell).zero(); }