#include "support/convert.h"
#include "frontends/Alert.h"
+#include "frontends/Application.h"
#include "frontends/font_metrics.h"
-#include "frontends/Gui.h"
-#include "frontends/LyXView.h"
#include "frontends/Clipboard.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
#include <iostream>
#include <limits>
+using lyx::docstring;
+
using lyx::cap::dirtyTabularStack;
using lyx::cap::tabularStackDirty;
using lyx::support::ltrim;
using lyx::frontend::Painter;
-using lyx::frontend::Gui;
using lyx::frontend::Clipboard;
using boost::shared_ptr;
{ LyXTabular::APPEND_COLUMN, "append-column" },
{ LyXTabular::DELETE_ROW, "delete-row" },
{ LyXTabular::DELETE_COLUMN, "delete-column" },
+ { LyXTabular::COPY_ROW, "copy-row" },
+ { LyXTabular::COPY_COLUMN, "copy-column" },
{ LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
{ LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
{ LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
tabular.setWidthOfCell(cell, dim.wid);
if (p_width.zero()) {
m.base.textwidth = dim.wid + 2 * ADD_TO_TABULAR_WIDTH;
- // FIXME there must be a way to get rid of
+ // FIXME there must be a way to get rid of
// the second metrics call
tabular.getCellInset(cell)->metrics(m, dim);
}
}
-string const InsetTabular::editMessage() const
+docstring const InsetTabular::editMessage() const
{
return _("Opened table");
}
case LFUN_MOUSE_PRESS:
//lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
- if (cmd.button() == mouse_button::button1
+ if (cmd.button() == mouse_button::button1
|| cmd.button() == mouse_button::button3) {
cur.selection() = false;
setCursorFromCoordinates(cur, cmd.x, cmd.y);
break;
case LFUN_TABULAR_FEATURE:
- if (!tabularFeatures(cur, cmd.argument))
+ if (!tabularFeatures(cur, lyx::to_utf8(cmd.argument())))
cur.undispatched();
break;
// insert file functions
case LFUN_FILE_INSERT_ASCII_PARA:
case LFUN_FILE_INSERT_ASCII: {
- string const tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
- if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
+ // FIXME: We don't know the encoding of filenames
+ string const tmpstr = getContentsOfAsciiFile(&cur.bv(), lyx::to_utf8(cmd.argument()), false);
+ // FIXME: We don't know the encoding of the file
+ if (!tmpstr.empty() && !insertAsciiString(cur.bv(), lyx::from_utf8(tmpstr), false))
cur.undispatched();
break;
}
case LFUN_CLIPBOARD_PASTE:
case LFUN_PRIMARY_SELECTION_PASTE: {
- string const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ?
- cur.bv().owner()->gui().clipboard().get() :
- cur.bv().owner()->gui().selection().get();
+ docstring const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ?
+ theApp->clipboard().get() :
+ theApp->selection().get();
if (clip.empty())
break;
// pass to InsertAsciiString, but
// only if we have multi-cell content
- if (clip.find_first_of("\t\n") != string::npos) {
+ if (clip.find_first_of(lyx::from_ascii("\t\n")) != docstring::npos) {
if (insertAsciiString(cur.bv(), clip, false)) {
// content has been replaced,
// so cursor might be invalid
break;
}
cell(cur.idx())->dispatch(cur, cmd);
- // Reset pasted paragraphs:
- if (tabular.getPWidth(cur.idx()).zero())
- cell(cur.idx())->forceParagraphsToDefault(cur);
break;
case LFUN_FONT_EMPH:
row_type rs, re;
col_type cs, ce;
getSelection(cur, rs, re, cs, ce);
+ LCursor tmpcur = cur;
for (row_type i = rs; i <= re; ++i) {
for (col_type j = cs; j <= ce; ++j) {
// cursor follows cell:
- cur.idx() = tabular.getCellNumber(i, j);
+ tmpcur.idx() = tabular.getCellNumber(i, j);
// select this cell only:
- cur.pos() = 0;
- cur.resetAnchor();
- cur.pos() = cur.top().lastpos();
- cur.setCursor(cur);
- cur.setSelection();
- cell(cur.idx())->dispatch(cur, cmd);
+ tmpcur.pit() = 0;
+ tmpcur.pos() = 0;
+ tmpcur.resetAnchor();
+ tmpcur.pit() = tmpcur.lastpit();
+ tmpcur.pos() = tmpcur.top().lastpos();
+ tmpcur.setCursor(tmpcur);
+ tmpcur.setSelection();
+ cell(tmpcur.idx())->dispatch(tmpcur, cmd);
}
}
- // Restore original selection
- cur.idx() = tabular.getCellNumber(rs, cs);
- cur.pos() = 0;
- cur.resetAnchor();
- cur.idx() = tabular.getCellNumber(re, ce);
- cur.pos() = cur.top().lastpos();
- cur.setCursor(cur);
- cur.setSelection();
break;
} else {
cell(cur.idx())->dispatch(cur, cmd);
int i = 0;
for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
string const tmp = tabularFeature[i].feature;
- if (tmp == cmd.argument.substr(0, tmp.length())) {
+ if (tmp == lyx::to_utf8(cmd.argument()).substr(0, tmp.length())) {
action = tabularFeature[i].action;
break;
}
}
string const argument
- = ltrim(cmd.argument.substr(tabularFeature[i].feature.length()));
+ = ltrim(lyx::to_utf8(cmd.argument()).substr(tabularFeature[i].feature.length()));
row_type sel_row_start = 0;
row_type sel_row_end = 0;
case LyXTabular::APPEND_COLUMN:
case LyXTabular::DELETE_ROW:
case LyXTabular::DELETE_COLUMN:
+ case LyXTabular::COPY_ROW:
+ case LyXTabular::COPY_COLUMN:
case LyXTabular::SET_ALL_LINES:
case LyXTabular::UNSET_ALL_LINES:
case LyXTabular::SET_TOP_SPACE:
case LyXTabular::SET_LTNEWPAGE:
status.setOnOff(tabular.getLTNewPage(sel_row_start));
break;
-
+
case LyXTabular::SET_BOOKTABS:
status.setOnOff(tabular.useBookTabs());
break;
-
+
case LyXTabular::UNSET_BOOKTABS:
status.setOnOff(!tabular.useBookTabs());
break;
}
-int InsetTabular::linuxdoc(Buffer const & buf, ostream & os,
- OutputParams const & runparams) const
-{
- return tabular.linuxdoc(buf,os, runparams);
-}
-
-
int InsetTabular::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
int const xend = xbeg + tabular.getWidthOfColumn(cell);
row_type const row = tabular.row_of_cell(cell);
int const ybeg = o.y_ - tabular.getAscentOfRow(row) -
- tabular.getAdditionalHeight(row);
+ tabular.getAdditionalHeight(row);
int const yend = o.y_ + tabular.getDescentOfRow(row);
if (x < xbeg)
cur.selection() = false;
break;
+ case LyXTabular::COPY_ROW:
+ tabular.copyRow(bv.buffer()->params(), row);
+ break;
+
+ case LyXTabular::COPY_COLUMN:
+ tabular.copyColumn(bv.buffer()->params(), column);
+ cur.idx() = tabular.getCellNumber(row, column);
+ break;
+
case LyXTabular::M_TOGGLE_LINE_TOP:
flag = false;
case LyXTabular::TOGGLE_LINE_TOP: {
#ifdef WITH_WARNINGS
#warning Need I say it ? This is horrible.
#endif
+ // FIXME UNICODE
Alert::error(_("Error setting multicolumn"),
- _("You cannot set multicolumn vertically."));
+ _("You cannot set multicolumn vertically."));
return;
}
if (!cur.selection()) {
ostringstream os;
OutputParams const runparams;
paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
- cur.bv().owner()->gui().clipboard().put(os.str());
+ theApp->clipboard().put(lyx::from_utf8(os.str()));
// mark tabular stack dirty
// FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
// when we (hopefully) have a one-for-all paste mechanism.
}
// cursor position might be invalid now
- cur.pos() = cur.lastpos();
+ if (cur.pit() > cur.lastpit())
+ cur.pit() = cur.lastpit();
+ if (cur.pos() > cur.lastpos())
+ cur.pos() = cur.lastpos();
cur.clearSelection();
}
}
-bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
+bool InsetTabular::insertAsciiString(BufferView & bv, docstring const & buf,
bool usePaste)
{
if (buf.length() <= 0)
col_type cols = 1;
row_type rows = 1;
col_type maxCols = 1;
- string::size_type const len = buf.length();
- string::size_type p = 0;
+ docstring::size_type const len = buf.length();
+ docstring::size_type p = 0;
- while (p < len && (p = buf.find_first_of("\t\n", p)) != string::npos) {
+ while (p < len &&
+ (p = buf.find_first_of(lyx::from_ascii("\t\n"), p)) != docstring::npos) {
switch (buf[p]) {
case '\t':
++cols;
row = tabular.row_of_cell(cell);
}
- string::size_type op = 0;
+ docstring::size_type op = 0;
idx_type const cells = loctab->getNumberOfCells();
p = 0;
cols = ocol;
col_type const columns = loctab->columns();
while (cell < cells && p < len && row < rows &&
- (p = buf.find_first_of("\t\n", p)) != string::npos)
+ (p = buf.find_first_of(lyx::from_ascii("\t\n"), p)) != docstring::npos)
{
if (p >= len)
break;