/* This file is part of
* ======================================================
- *
+ *
* LyX, The Document Processor
*
* Copyright 2001 The LyX Team.
#include "insettabular.h"
+#include "lyx_cb.h"
#include "buffer.h"
#include "commandtags.h"
#include "lyxfunc.h"
#include "Painter.h"
#include "font.h"
#include "lyxtext.h"
-#include "lyx_gui_misc.h"
#include "LyXView.h"
#include "insets/insettext.h"
#include "debug.h"
-#include "WorkArea.h"
#include "gettext.h"
#include "language.h"
#include "BufferView.h"
#include "undo_funcs.h"
#include "lyxlength.h"
+#include "ParagraphParameters.h"
#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
#include <map>
//#include <signal.h>
+
+using std::vector;
using std::ostream;
using std::ifstream;
using std::max;
rows = 1;
if (columns <= 0)
columns = 1;
- tabular.reset(new LyXTabular(this, rows, columns));
+ tabular.reset(new LyXTabular(buf.params, this, rows, columns));
// for now make it always display as display() inset
// just for test!!!
the_locking_inset = 0;
+ old_locking_inset = 0;
locked = false;
oldcell = -1;
actrow = actcell = 0;
need_update = INIT;
in_update = false;
in_reset_pos = false;
+ inset_x = 0;
+ inset_y = 0;
}
bool same_id)
: UpdatableInset(tab, same_id), buffer(&buf)
{
- tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
+ tabular.reset(new LyXTabular(buf.params,
+ this, *(tab.tabular), same_id));
the_locking_inset = 0;
+ old_locking_inset = 0;
locked = false;
oldcell = -1;
actrow = actcell = 0;
need_update = INIT;
in_update = false;
in_reset_pos = false;
+ inset_x = 0;
+ inset_y = 0;
}
x += static_cast<float>(scroll());
#endif
if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
- (top_x != int(x)) || (top_baseline != baseline)))
+ (top_x != int(x)) || (top_baseline != baseline)))
{
int h = ascent(bv, font) + descent(bv, font);
int const tx = display() || !owner() ? 0 : top_x;
int w = tx ? width(bv, font) : pain.paperWidth();
int ty = baseline - ascent(bv, font);
-
+
if (ty < 0)
ty = 0;
if ((ty + h) > pain.paperHeight())
if (hasSelection()) {
drawCellSelection(pain, nx, baseline, i, j, cell);
}
-
+
tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
drawCellLines(pain, nx, baseline, i, cell);
nx += tabular->GetWidthOfColumn(cell);
float dx = nx + tabular->GetBeginningOfTextInCell(cell);
float cx = dx;
tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
+ //
+ // Here we use rectangular backgroundColor patches to clean up
+ // within a cell around the cell's red inset box. As follows:
+ //
+ // +--------------------+
+ // | C | The rectangles are A, B and C
+ // | A |------------| B | below, origin top left (tx, ty),
+ // | | inset box | | dimensions w(idth), h(eight).
+ // +---+------------+---+ x grows rightward, y downward
+ // | D |
+ // +--------------------+
+ //
+#if 0
// clear only if we didn't have a change
if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
+#endif
// clear before the inset
- pain.fillRectangle(
- nx + 1,
- baseline - tabular->GetAscentOfRow(i) + 1,
- int(cx - nx - 1),
- tabular->GetAscentOfRow(i) +
- tabular->GetDescentOfRow(i) - 1,
- backgroundColor());
+ int tx, ty, w, h;
+ tx = nx + 1;
+ ty = baseline - tabular->GetAscentOfRow(i) + 1;
+ w = int(cx - nx - 1);
+ h = tabular->GetAscentOfRow(i) +
+ tabular->GetDescentOfRow(i) - 1;
+ pain.fillRectangle(tx, ty, w, h, backgroundColor());
// clear behind the inset
- pain.fillRectangle(
- int(cx + the_locking_inset->width(bv,font) + 1),
- baseline - tabular->GetAscentOfRow(i) + 1,
- tabular->GetWidthOfColumn(cell) -
+ tx = int(cx + the_locking_inset->width(bv,font) + 1);
+ ty = baseline - tabular->GetAscentOfRow(i) + 1;
+ w = tabular->GetWidthOfColumn(cell) -
tabular->GetBeginningOfTextInCell(cell) -
the_locking_inset->width(bv,font) -
- tabular->GetAdditionalWidth(cell) - 1,
- tabular->GetAscentOfRow(i) +
- tabular->GetDescentOfRow(i) - 1,
- backgroundColor());
+ tabular->GetAdditionalWidth(cell) - 1;
+ h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
+ pain.fillRectangle(tx, ty, w, h, backgroundColor());
// clear below the inset
- pain.fillRectangle(
- nx + 1,
- baseline + the_locking_inset->descent(bv, font) + 1,
- tabular->GetWidthOfColumn(cell) -
- tabular->GetAdditionalWidth(cell) - 1,
- tabular->GetAscentOfRow(i) +
- tabular->GetDescentOfRow(i) -
- the_locking_inset->ascent(bv, font) -
- the_locking_inset->descent(bv, font) -
- TEXT_TO_INSET_OFFSET - 1,
- backgroundColor());
+ tx = nx + 1;
+ ty = baseline + the_locking_inset->descent(bv, font) + 1;
+ w = tabular->GetWidthOfColumn(cell) -
+ tabular->GetAdditionalWidth(cell) - 1;
+ h = tabular->GetDescentOfRow(i) -
+ the_locking_inset->descent(bv, font) - 1;
+ pain.fillRectangle(tx, ty, w, h, backgroundColor());
+ // clear above the inset
+ tx = nx + 1;
+ ty = baseline - tabular->GetAscentOfRow(i) + 1;
+ w = tabular->GetWidthOfColumn(cell) -
+ tabular->GetAdditionalWidth(cell) - 1;
+ h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
+ pain.fillRectangle(tx, ty, w, h, backgroundColor());
+#if 0
}
+#endif
}
x -= ADD_TO_TABULAR_WIDTH;
x += width(bv, font);
void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
- int row, int cell) const
+ int row, int cell) const
{
int x2 = x + tabular->GetWidthOfColumn(cell);
bool on_off;
-
+
if (!tabular->TopAlreadyDrawed(cell)) {
on_off = !tabular->TopLine(cell);
pain.line(x, baseline - tabular->GetAscentOfRow(row),
on_off ? Painter::line_onoffdash : Painter::line_solid);
}
on_off = !tabular->BottomLine(cell);
- pain.line(x,baseline + tabular->GetDescentOfRow(row),
- x2, baseline + tabular->GetDescentOfRow(row),
+ pain.line(x, baseline + tabular->GetDescentOfRow(row),
+ x2, baseline + tabular->GetDescentOfRow(row),
on_off ? LColor::tabularonoffline : LColor::tabularline,
on_off ? Painter::line_onoffdash : Painter::line_solid);
if (!tabular->LeftAlreadyDrawed(cell)) {
} else {
ce = tabular->right_column_of_cell(sel_cell_end);
}
-
+
int rs = tabular->row_of_cell(sel_cell_start);
int re = tabular->row_of_cell(sel_cell_end);
if (rs > re)
swap(rs, re);
-
+
if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
int w = tabular->GetWidthOfColumn(cell);
- int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
- pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
+ int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
+ pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
w, h, LColor::selection);
}
}
case INIT:
case FULL:
case CELL:
- if (calculate_dimensions_of_cells(bv, font, false))
+ if (calculate_dimensions_of_cells(bv, font, false)) {
need_update = INIT;
+ resetPos(bv);
+ }
break;
case SELECTION:
- need_update = INIT;
+ need_update = FULL;
break;
default:
break;
void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
{
UpdatableInset::edit(bv, x, y, button);
-
+
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
return;
void InsetTabular::edit(BufferView * bv, bool front)
{
UpdatableInset::edit(bv, front);
-
+
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
return;
}
+ finishUndo();
locked = true;
the_locking_inset = 0;
inset_x = 0;
actcell = tabular->GetNumberOfCells() - 1;
clearSelection();
resetPos(bv);
- finishUndo();
+ bv->fitCursor();
}
{
if (the_locking_inset) {
the_locking_inset->insetUnlock(bv);
+ updateLocal(bv, CELL, false);
the_locking_inset = 0;
}
hideInsetCursor(bv);
LyXFont font;
calculate_dimensions_of_cells(bv, font, true);
}
+ if (!locked && what == CELL)
+ what = FULL;
if (need_update < what) // only set this if it has greater update
need_update = what;
+#if 0 // maybe this should not be done!
if ((what == INIT) && hasSelection()) {
clearSelection();
}
+#endif
// Dirty Cast! (Lgb)
if (need_update != NONE) {
bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
}
if (in->getInsetFromID(id)) {
actcell = i;
- the_locking_inset = in;
- locked = true;
- resetPos(bv);
+ in->edit(bv);
return the_locking_inset->lockInsetInInset(bv, inset);
}
}
return false;
if (the_locking_inset == inset) {
the_locking_inset->insetUnlock(bv);
- the_locking_inset = 0;
#ifdef WITH_WARNINGS
#warning fix scrolling when cellinset has requested a scroll (Jug)!!!
#endif
scroll(bv, 0.0F);
#endif
updateLocal(bv, CELL, false);
- showInsetCursor(bv, false);
+ // this has to be here otherwise we don't redraw the cell!
+ the_locking_inset = 0;
+// showInsetCursor(bv, false);
return true;
}
if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
{
- if (!the_locking_inset)
+ Inset * tl_inset = inset;
+ // look if this inset is really inside myself!
+ while(tl_inset->owner() && tl_inset->owner() != this)
+ tl_inset = tl_inset->owner();
+ // if we enter here it's not ower inset
+ if (!tl_inset->owner())
return false;
- if (the_locking_inset != inset) {
- if (!the_locking_inset->updateInsetInInset(bv, inset))
+ // we only have to do this if this is a subinset of our cells
+ if (tl_inset != inset) {
+ if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
return false;
}
updateLocal(bv, CELL, false);
}
-unsigned int InsetTabular::insetInInsetY()
+int InsetTabular::insetInInsetY() const
{
if (!the_locking_inset)
return 0;
-
return inset_y + the_locking_inset->insetInInsetY();
}
int const orow = actrow;
hideInsetCursor(bv);
+ if (!locked) {
+ locked = true;
+ the_locking_inset = 0;
+ inset_x = 0;
+ inset_y = 0;
+ }
setPos(bv, x, y);
if (actrow != orow)
updateLocal(bv, NONE, false);
if (button == 3) {
if ((ocell != actcell) && the_locking_inset) {
the_locking_inset->insetUnlock(bv);
+ updateLocal(bv, CELL, false);
the_locking_inset = 0;
}
showInsetCursor(bv);
return;
} else if (the_locking_inset) {
the_locking_inset->insetUnlock(bv);
+ updateLocal(bv, CELL, false);
+ the_locking_inset = 0;
}
- the_locking_inset = 0;
if (button == 2) {
localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
return;
}
if (inset_hit && bv->theLockingInset()) {
- if (activateCellInsetAbs(bv, x, y, button))
- the_locking_inset->insetButtonPress(bv,
- x - inset_x,
- y - inset_y,
- button);
+ if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
+ lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+ return;
+ }
+ the_locking_inset->insetButtonPress(
+ bv, x - inset_x, y - inset_y, button);
return;
}
showInsetCursor(bv);
bool InsetTabular::insetButtonRelease(BufferView * bv,
- int x, int y, int button)
+ int x, int y, int button)
{
bool ret = false;
if (the_locking_inset)
- ret = the_locking_inset->insetButtonRelease(bv, x, y, button);
+ ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
+ y - inset_y, button);
if (button == 3 && !ret) {
bv->owner()->getDialogs()->showTabular(this);
return true;
button);
return;
}
-
+
hideInsetCursor(bv);
// int const old_cell = actcell;
-
+
setPos(bv, x, y);
if (!hasSelection()) {
setSelection(actcell, actcell);
UpdatableInset::RESULT
InsetTabular::localDispatch(BufferView * bv, kb_action action,
- string const & arg)
+ string const & arg)
{
- // We need to save the value of the_locking_inset as the call to
+ // We need to save the value of the_locking_inset as the call to
// the_locking_inset->LocalDispatch might unlock it.
old_locking_inset = the_locking_inset;
UpdatableInset::RESULT result =
setSelection(start, actcell);
break;
}
-
+
int end = actcell;
// if we are starting a selection, only select
// the current cell at the beginning
setSelection(start, actcell);
break;
}
-
+
int end = actcell;
// if we are starting a selection, only select
// the current cell at the beginning
- if (hasSelection()) {
+ if (hasSelection()) {
moveLeft(bv, false);
end = actcell;
}
int const ocell = actcell;
// if we are starting a selection, only select
// the current cell at the beginning
- if (hasSelection()) {
+ if (hasSelection()) {
moveDown(bv, false);
+ if ((ocell == sel_cell_end) ||
+ (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
+ setSelection(start, tabular->GetCellBelow(sel_cell_end));
+ else
+ setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
+ } else {
+ setSelection(start, start);
}
- if ((ocell == sel_cell_end) ||
- (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
- setSelection(start, tabular->GetCellBelow(sel_cell_end));
- else
- setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
updateLocal(bv, SELECTION, false);
}
break;
// the current cell at the beginning
if (hasSelection()) {
moveUp(bv, false);
+ if ((ocell == sel_cell_end) ||
+ (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
+ setSelection(start, tabular->GetCellAbove(sel_cell_end));
+ else
+ setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
+ } else {
+ setSelection(start, start);
}
- if ((ocell == sel_cell_end) ||
- (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
- setSelection(start, tabular->GetCellAbove(sel_cell_end));
- else
- setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
updateLocal(bv, SELECTION, false);
}
break;
updateLocal(bv, SELECTION, false);
break;
case LFUN_NEXT: {
+ UpdateCodes code = CURSOR;
+ if (hs) {
+ clearSelection();
+ code = SELECTION;
+ }
int column = actcol;
unlockInsetInInset(bv, the_locking_inset);
- if (bv->text->first + bv->painter().paperHeight() <
+ if (bv->text->first_y + bv->painter().paperHeight() <
(top_baseline + tabular->GetHeightOfTabular()))
{
- bv->scrollCB(bv->text->first + bv->painter().paperHeight());
- updateLocal(bv, FULL, false);
+ bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
+ code = FULL;
actcell = tabular->GetCellBelow(first_visible_cell) + column;
} else {
actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
}
resetPos(bv);
- updateLocal(bv, CURSOR, false);
+ updateLocal(bv, code, false);
break;
}
case LFUN_PRIOR: {
+ UpdateCodes code = CURSOR;
+ if (hs) {
+ clearSelection();
+ code = SELECTION;
+ }
int column = actcol;
unlockInsetInInset(bv, the_locking_inset);
if (top_baseline < 0) {
- bv->scrollCB(bv->text->first - bv->painter().paperHeight());
- updateLocal(bv, FULL, false);
+ bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
+ code = FULL;
if (top_baseline > 0)
actcell = column;
else
actcell = column;
}
resetPos(bv);
- updateLocal(bv, CURSOR, false);
+ updateLocal(bv, code, false);
break;
}
// none of these make sense for insettabular,
case LFUN_NEXTSEL:
case LFUN_WORDLEFT:
case LFUN_WORDLEFTSEL:
- case LFUN_WORDRIGHT:
+ case LFUN_WORDRIGHT:
case LFUN_WORDRIGHTSEL:
case LFUN_DOWN_PARAGRAPH:
case LFUN_DOWN_PARAGRAPHSEL:
case LFUN_HOMESEL:
case LFUN_END:
case LFUN_ENDSEL:
+ case LFUN_BEGINNINGBUF:
+ case LFUN_BEGINNINGBUFSEL:
+ case LFUN_ENDBUF:
+ case LFUN_ENDBUFSEL:
break;
case LFUN_LAYOUT_TABULAR:
bv->owner()->getDialogs()->showTabular(this);
if (!tabularFeatures(bv, arg))
result = UNDISPATCHED;
break;
+ // insert file functions
+ case LFUN_FILE_INSERT_ASCII_PARA:
+ case LFUN_FILE_INSERT_ASCII:
+ {
+ string tmpstr = getContentsOfAsciiFile(bv, arg, false);
+ if (tmpstr.empty())
+ break;
+ if (insertAsciiString(bv, tmpstr, false))
+ updateLocal(bv, INIT, true);
+ else
+ result = UNDISPATCHED;
+ break;
+ }
+ // cut and paste functions
case LFUN_CUT:
if (!copySelection(bv))
break;
setUndo(bv, Undo::DELETE,
- bv->text->cursor.par(),
- bv->text->cursor.par()->next());
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
cutSelection();
updateLocal(bv, INIT, true);
break;
case LFUN_PASTESELECTION:
{
string const clip(bv->getClipboard());
-
- if (clip.empty())
+ if (clip.empty())
break;
+#if 0
if (clip.find('\t') != string::npos) {
int cols = 1;
int rows = 1;
while (p < len &&
((p = clip.find_first_of("\t\n", p)) != string::npos)) {
- switch(clip[p]) {
+ switch (clip[p]) {
case '\t':
++cols;
break;
}
maxCols = max(cols, maxCols);
delete paste_tabular;
- paste_tabular = new LyXTabular(this, rows, maxCols);
+ paste_tabular = new LyXTabular(bv->buffer()->params,
+ this, rows, maxCols);
string::size_type op = 0;
int cell = 0;
int cells = paste_tabular->GetNumberOfCells();
(p = clip.find_first_of("\t\n", p)) != string::npos) {
if (p >= len)
break;
- switch(clip[p]) {
+ switch (clip[p]) {
case '\t':
paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
++cols;
// check for the last cell if there is no trailing '\n'
if ((cell < cells) && (op < len))
paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
- } else {
+ } else
+#else
+ if (!insertAsciiString(bv, clip, true))
+#endif
+ {
// so that the clipboard is used and it goes on
// to default
// and executes LFUN_PASTESELECTION in insettext!
case LFUN_PASTE:
if (hasPasteBuffer()) {
setUndo(bv, Undo::INSERT,
- bv->text->cursor.par(),
- bv->text->cursor.par()->next());
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
pasteSelection(bv);
updateLocal(bv, INIT, true);
break;
}
// ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
default:
+ // handle font changing stuff on selection before we lock the inset
+ // in the default part!
+ result = UNDISPATCHED;
+ if (hs) {
+ switch(action) {
+ case LFUN_LANGUAGE:
+ case LFUN_EMPH:
+ case LFUN_BOLD:
+ case LFUN_NOUN:
+ case LFUN_CODE:
+ case LFUN_SANS:
+ case LFUN_ROMAN:
+ case LFUN_DEFAULT:
+ case LFUN_UNDERLINE:
+ case LFUN_FONT_SIZE:
+ if (bv->Dispatch(action, arg))
+ result = DISPATCHED;
+ break;
+ default:
+ break;
+ }
+ }
// we try to activate the actual inset and put this event down to
// the insets dispatch function.
- result = UNDISPATCHED;
- if (the_locking_inset)
+ if ((result == DISPATCHED) || the_locking_inset)
break;
nodraw(true);
if (activateCellInset(bv)) {
return UNDISPATCHED;
} else if (hs) {
clearSelection();
+ // so the below CELL is not set because this is higher
+ // priority and we get a full redraw
+ need_update = SELECTION;
}
nodraw(false);
updateLocal(bv, CELL, false);
}
if (result < FINISHED) {
if (!the_locking_inset) {
- showInsetCursor(bv);
+ if (bv->fitCursor())
+ updateLocal(bv, FULL, false);
+ if (locked)
+ showInsetCursor(bv);
}
} else
bv->unlockInset(this);
int InsetTabular::latex(Buffer const * buf, ostream & os,
bool fragile, bool fp) const
{
- return tabular->Latex(buf, os, fragile, fp);
+ return tabular->latex(buf, os, fragile, fp);
}
-int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
+int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
{
- // This should be changed to a real ascii export
- return tabular->Ascii(buf, os);
+ if (ll > 0)
+ return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
+ false,0);
+ return tabular->ascii(buf, os, 0, false,0);
}
int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
{
- return tabular->Ascii(buf,os);
+ os << "<![CDATA[";
+ int const ret = tabular->ascii(buf,os,
+ (int)parOwner()->params().depth(),
+ false, 0);
+ os << "]]>";
+ return ret;
}
os << "<informaltable>\n";
ret++;
}
- ret+= tabular->DocBook(buf,os);
+ ret+= tabular->docBook(buf,os);
if (!master) {
os << "</informaltable>\n";
ret++;
bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
- LyXFont const & font,
- bool reinit) const
+ LyXFont const & font,
+ bool reinit) const
{
int cell = -1;
int maxAsc = 0;
int maxDesc = 0;
InsetText * inset;
bool changed = false;
-
+
// if we have a locking_inset we should have to check only this cell for
// change so I'll try this to have a boost, but who knows ;)
if ((need_update != INIT) &&
void InsetTabular::toggleInsetCursor(BufferView * bv)
{
+ if (nodraw()) {
+ if (isCursorVisible())
+ bv->hideLockedInsetCursor();
+ return;
+ }
if (the_locking_inset) {
the_locking_inset->toggleInsetCursor(bv);
return;
}
-
+
LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
-
+
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
-
+
if (isCursorVisible())
bv->hideLockedInsetCursor();
else
void InsetTabular::showInsetCursor(BufferView * bv, bool show)
{
+ if (nodraw())
+ return;
if (!isCursorVisible()) {
LyXFont font; // = GetFont(par, cursor.pos);
-
+
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
void InsetTabular::fitInsetCursor(BufferView * bv) const
{
if (the_locking_inset) {
+ int old_first_y = bv->text->first_y;
the_locking_inset->fitInsetCursor(bv);
+ if (old_first_y != bv->text->first_y)
+ need_update = FULL;
return;
}
LyXFont font;
-
+
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
- bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
+ resetPos(bv);
+ if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
+ need_update = FULL;
}
void InsetTabular::setPos(BufferView * bv, int x, int y) const
{
cursor_.y(0);
-
+
actcell = actrow = actcol = 0;
int ly = tabular->GetDescentOfRow(actrow);
int InsetTabular::getCellXPos(int cell) const
{
int c = cell;
-
+
for (; !tabular->IsFirstCellInRow(c); --c)
;
int lx = tabular->GetWidthOfColumn(cell);
void InsetTabular::resetPos(BufferView * bv) const
{
- if (!locked || nodraw())
- return;
+#ifdef WITH_WARNINGS
#warning This should be fixed in the right manner (20011128 Jug)
+#endif
// fast hack to fix infinite repaintings!
if (in_reset_pos)
return;
- in_reset_pos = true;
-
- actcol = tabular->column_of_cell(actcell);
int cell = 0;
+ actcol = tabular->column_of_cell(actcell);
actrow = 0;
cursor_.y(0);
for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
++actrow;
}
}
+ if (!locked || nodraw()) {
+ if (the_locking_inset)
+ inset_y = cursor_.y();
+ return;
+ }
+ // we need this only from here on!!!
+ in_reset_pos = true;
static int const offset = ADD_TO_TABULAR_WIDTH + 2;
int new_x = getCellXPos(actcell);
int old_x = cursor_.x();
void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
- bool selectall)
+ bool selectall)
{
if (selectall) {
setSelection(0, tabular->GetNumberOfCells() - 1);
}
if (hasSelection()) {
setUndo(bv, Undo::EDIT,
- bv->text->cursor.par(),
- bv->text->cursor.par()->next());
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
bool frozen = undo_frozen;
if (!frozen)
freezeUndo();
}
if (!frozen)
unFreezeUndo();
+ if (selectall)
+ clearSelection();
updateLocal(bv, INIT, true);
}
if (the_locking_inset)
bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
{
LyXTabular::Feature action = LyXTabular::LAST_ACTION;
-
+
int i = 0;
for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
string const tmp = tabularFeature[i].feature;
-
+
if (tmp == what.substr(0, tmp.length())) {
//if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
//tabularFeatures[i].feature.length())) {
}
static void checkLongtableSpecial(LyXTabular::ltType & ltt,
- string const & special,
- int const row, bool const flag)
+ string const & special, bool & flag)
{
if (special == "dl_above") {
ltt.topDL = flag;
+ ltt.set = false;
} else if (special == "dl_below") {
ltt.bottomDL = flag;
+ ltt.set = false;
} else if (special == "empty") {
ltt.empty = flag;
- } else {
- if (flag)
- ltt.row = row;
- else
- ltt.row = 0;
+ ltt.set = false;
+ } else if (flag) {
+ ltt.empty = false;
+ ltt.set = true;
}
}
void InsetTabular::tabularFeatures(BufferView * bv,
- LyXTabular::Feature feature,
- string const & value)
+ LyXTabular::Feature feature,
+ string const & value)
{
int sel_col_start;
int sel_col_end;
sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
}
setUndo(bv, Undo::FINISH,
- bv->text->cursor.par(),
- bv->text->cursor.par()->next());
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
int row = tabular->row_of_cell(actcell);
int column = tabular->column_of_cell(actcell);
bool flag = true;
LyXTabular::ltType ltt;
-
+
switch (feature) {
case LyXTabular::SET_PWIDTH:
{
LyXLength const vallen(value);
LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
-
+
bool const update = (tmplen != vallen);
tabular->SetColumnPWidth(actcell, vallen);
if (update) {
{
LyXLength const vallen(value);
LyXLength const & tmplen = tabular->GetPWidth(actcell);
-
+
bool const update = (tmplen != vallen);
tabular->SetMColumnPWidth(actcell, vallen);
if (update) {
case LyXTabular::APPEND_ROW:
// append the row into the tabular
unlockInsetInInset(bv, the_locking_inset);
- tabular->AppendRow(actcell);
+ tabular->AppendRow(bv->buffer()->params, actcell);
updateLocal(bv, INIT, true);
break;
case LyXTabular::APPEND_COLUMN:
// append the column into the tabular
unlockInsetInInset(bv, the_locking_inset);
- tabular->AppendColumn(actcell);
+ tabular->AppendColumn(bv->buffer()->params, actcell);
actcell = tabular->GetCellNumber(row, column);
updateLocal(bv, INIT, true);
break;
updateLocal(bv, INIT, true);
break;
}
-
+
case LyXTabular::M_TOGGLE_LINE_BOTTOM:
flag = false;
case LyXTabular::TOGGLE_LINE_BOTTOM:
{
- bool lineSet = !tabular->BottomLine(actcell, flag);
+ bool lineSet = !tabular->BottomLine(actcell, flag);
for (int i = sel_row_start; i <= sel_row_end; ++i)
for (int j = sel_col_start; j <= sel_col_end; ++j)
tabular->SetBottomLine(
updateLocal(bv, INIT, true);
break;
}
-
+
case LyXTabular::M_TOGGLE_LINE_LEFT:
flag = false;
case LyXTabular::TOGGLE_LINE_LEFT:
updateLocal(bv, INIT, true);
break;
}
-
+
case LyXTabular::M_TOGGLE_LINE_RIGHT:
flag = false;
case LyXTabular::TOGGLE_LINE_RIGHT:
updateLocal(bv, INIT, true);
break;
}
-
+
case LyXTabular::M_ALIGN_LEFT:
case LyXTabular::M_ALIGN_RIGHT:
case LyXTabular::M_ALIGN_CENTER:
case LyXTabular::MULTICOLUMN:
{
if (sel_row_start != sel_row_end) {
- Alert::alert(_("Impossible Operation!"),
- _("Multicolumns can only be horizontally."),
+ Alert::alert(_("Impossible Operation!"),
+ _("Multicolumns can only be horizontally."),
_("Sorry."));
return;
}
tabular->UnsetMultiColumn(actcell);
updateLocal(bv, INIT, true);
} else {
- tabular->SetMultiColumn(actcell, 1);
+ tabular->SetMultiColumn(bv->buffer(), actcell, 1);
updateLocal(bv, CELL, true);
}
return;
s_start = sel_cell_start;
s_end = sel_cell_end;
}
- tabular->SetMultiColumn(s_start, s_end - s_start + 1);
+ tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
actcell = s_start;
clearSelection();
updateLocal(bv, INIT, true);
flag = false;
case LyXTabular::SET_LTFIRSTHEAD:
(void)tabular->GetRowOfLTFirstHead(row, ltt);
- checkLongtableSpecial(ltt, value, row + 1, flag);
- tabular->SetLTHead(ltt, true);
+ checkLongtableSpecial(ltt, value, flag);
+ tabular->SetLTHead(row, flag, ltt, true);
break;
case LyXTabular::UNSET_LTHEAD:
flag = false;
case LyXTabular::SET_LTHEAD:
(void)tabular->GetRowOfLTHead(row, ltt);
- checkLongtableSpecial(ltt, value, row + 1, flag);
- tabular->SetLTHead(ltt, false);
+ checkLongtableSpecial(ltt, value, flag);
+ tabular->SetLTHead(row, flag, ltt, false);
break;
case LyXTabular::UNSET_LTFOOT:
flag = false;
case LyXTabular::SET_LTFOOT:
(void)tabular->GetRowOfLTFoot(row, ltt);
- checkLongtableSpecial(ltt, value, row + 1, flag);
- tabular->SetLTFoot(ltt, false);
+ checkLongtableSpecial(ltt, value, flag);
+ tabular->SetLTFoot(row, flag, ltt, false);
break;
case LyXTabular::UNSET_LTLASTFOOT:
flag = false;
case LyXTabular::SET_LTLASTFOOT:
(void)tabular->GetRowOfLTLastFoot(row, ltt);
- checkLongtableSpecial(ltt, value, row + 1, flag);
- tabular->SetLTFoot(ltt, true);
+ checkLongtableSpecial(ltt, value, flag);
+ tabular->SetLTFoot(row, flag, ltt, true);
break;
case LyXTabular::SET_LTNEWPAGE:
{
int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
{
LyXLength const len = tabular->GetPWidth(cell);
-
+
if (len.zero())
return -1;
-#ifdef WITH_WARNINGS
-#warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
-#endif
- return VSpace(len).inPixels(bv);
+ return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
}
int InsetTabular::getMaxWidth(BufferView * bv,
- UpdatableInset const * inset) const
+ UpdatableInset const * inset) const
{
- int cell = tabular->cur_cell;
- if (tabular->GetCellInset(cell) != inset) {
- cell = actcell;
- if (tabular->GetCellInset(cell) != inset) {
-
- lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
- cell = -1;
- }
- }
-
- int const n = tabular->GetNumberOfCells();
+ int cell = tabular->GetCellFromInset(inset, actcell);
if (cell == -1) {
- for (cell = 0; cell < n; ++cell) {
- if (tabular->GetCellInset(cell) == inset)
- break;
- }
- }
-
- if (cell >= n) {
- lyxerr << "Own inset not found, shouldn't really happen!\n";
+ lyxerr << "Own inset not found, shouldn't really happen!"
+ << endl;
return -1;
}
-
+
int w = getMaxWidthOfCell(bv, cell);
if (w > 0) {
// because the inset then subtracts it's top_x and owner->x()
w += (inset->x() - top_x);
}
-
+
return w;
}
LyXText * InsetTabular::getLyXText(BufferView const * bv,
- bool const recursive) const
+ bool const recursive) const
{
if (the_locking_inset)
return the_locking_inset->getLyXText(bv, recursive);
//
-// functions returns:
-// 0 ... disabled
-// 1 ... enabled
-// 2 ... toggled on
-// 3 ... toggled off
+// function returns an object as defined in func_status.h:
+// states OK, Unknown, Disabled, On, Off.
//
-func_status::value_type InsetTabular::getStatus(string const & what) const
+FuncStatus InsetTabular::getStatus(string const & what) const
{
int action = LyXTabular::LAST_ACTION;
- func_status::value_type status = func_status::OK;
-
+ FuncStatus status;
+
int i = 0;
for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
string const tmp = tabularFeature[i].feature;
- if (tmp == what.substr(0, tmp.length())) {
+ if (tmp == what.substr(0, tmp.length())) {
//if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
// tabularFeatures[i].feature.length())) {
action = tabularFeature[i].action;
break;
}
}
- if (action == LyXTabular::LAST_ACTION)
- return func_status::Unknown;
+ if (action == LyXTabular::LAST_ACTION) {
+ status.clear();
+ return status.unknown(true);
+ }
string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
case LyXTabular::SET_MPWIDTH:
case LyXTabular::SET_SPECIAL_COLUMN:
case LyXTabular::SET_SPECIAL_MULTI:
- status |= func_status::Disabled;
- return status;
+ return status.disabled(true);
case LyXTabular::APPEND_ROW:
case LyXTabular::APPEND_COLUMN:
case LyXTabular::DELETE_COLUMN:
case LyXTabular::SET_ALL_LINES:
case LyXTabular::UNSET_ALL_LINES:
- status |= func_status::OK;
- return status;
+ return status.clear();
case LyXTabular::MULTICOLUMN:
- if (tabular->IsMultiColumn(actcell))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->IsMultiColumn(actcell));
break;
case LyXTabular::M_TOGGLE_LINE_TOP:
flag = false;
case LyXTabular::TOGGLE_LINE_TOP:
- if (tabular->TopLine(actcell, flag))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->TopLine(actcell, flag));
break;
case LyXTabular::M_TOGGLE_LINE_BOTTOM:
flag = false;
case LyXTabular::TOGGLE_LINE_BOTTOM:
- if (tabular->BottomLine(actcell, flag))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->BottomLine(actcell, flag));
break;
case LyXTabular::M_TOGGLE_LINE_LEFT:
flag = false;
case LyXTabular::TOGGLE_LINE_LEFT:
- if (tabular->LeftLine(actcell, flag))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->LeftLine(actcell, flag));
break;
case LyXTabular::M_TOGGLE_LINE_RIGHT:
flag = false;
case LyXTabular::TOGGLE_LINE_RIGHT:
- if (tabular->RightLine(actcell, flag))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->RightLine(actcell, flag));
break;
case LyXTabular::M_ALIGN_LEFT:
flag = false;
case LyXTabular::ALIGN_LEFT:
- if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
break;
case LyXTabular::M_ALIGN_RIGHT:
flag = false;
case LyXTabular::ALIGN_RIGHT:
- if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
break;
case LyXTabular::M_ALIGN_CENTER:
flag = false;
case LyXTabular::ALIGN_CENTER:
- if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
break;
case LyXTabular::M_VALIGN_TOP:
flag = false;
case LyXTabular::VALIGN_TOP:
- if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
break;
case LyXTabular::M_VALIGN_BOTTOM:
flag = false;
case LyXTabular::VALIGN_BOTTOM:
- if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
break;
case LyXTabular::M_VALIGN_CENTER:
flag = false;
case LyXTabular::VALIGN_CENTER:
- if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
break;
case LyXTabular::SET_LONGTABULAR:
- if (tabular->IsLongTabular())
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->IsLongTabular());
break;
case LyXTabular::UNSET_LONGTABULAR:
- if (!tabular->IsLongTabular())
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(!tabular->IsLongTabular());
break;
case LyXTabular::SET_ROTATE_TABULAR:
- if (tabular->GetRotateTabular())
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRotateTabular());
break;
case LyXTabular::UNSET_ROTATE_TABULAR:
- if (!tabular->GetRotateTabular())
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(!tabular->GetRotateTabular());
break;
case LyXTabular::SET_ROTATE_CELL:
- if (tabular->GetRotateCell(actcell))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRotateCell(actcell));
break;
case LyXTabular::UNSET_ROTATE_CELL:
- if (!tabular->GetRotateCell(actcell))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(!tabular->GetRotateCell(actcell));
break;
case LyXTabular::SET_USEBOX:
- if (strToInt(argument) == tabular->GetUsebox(actcell))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
break;
case LyXTabular::SET_LTFIRSTHEAD:
- if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
break;
case LyXTabular::SET_LTHEAD:
- if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
break;
case LyXTabular::SET_LTFOOT:
- if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
break;
case LyXTabular::SET_LTLASTFOOT:
- if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
break;
case LyXTabular::SET_LTNEWPAGE:
- if (tabular->GetLTNewPage(sel_row_start))
- status |= func_status::ToggleOn;
- else
- status |= func_status::ToggleOff;
+ status.setOnOff(tabular->GetLTNewPage(sel_row_start));
break;
default:
- status = func_status::Disabled;
+ status.clear();
+ status.disabled(true);
break;
}
return status;
}
-std::vector<string> const InsetTabular::getLabelList() const
+vector<string> const InsetTabular::getLabelList() const
{
return tabular->getLabelList();
}
int const rows = sel_row_end - sel_row_start + 1;
delete paste_tabular;
- paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
+ paste_tabular = new LyXTabular(bv->buffer()->params,
+ this, *tabular); // rows, columns);
for (int i = 0; i < sel_row_start; ++i)
paste_tabular->DeleteRow(0);
while (paste_tabular->rows() > rows)
true, true);
ostringstream sstr;
- paste_tabular->Ascii(bv->buffer(), sstr);
+ paste_tabular->ascii(bv->buffer(), sstr,
+ (int)parOwner()->params().depth(), true, '\t');
bv->stuffClipboard(sstr.str().c_str());
return true;
}
}
-bool InsetTabular::isRightToLeft(BufferView *bv )
+bool InsetTabular::isRightToLeft(BufferView * bv)
{
return bv->getParentLanguage(this)->RightToLeft();
}
{
int const start = hasSelection() ? sel_cell_start : actcell;
int const end = hasSelection() ? sel_cell_end : actcell;
-
+
srow = tabular->row_of_cell(start);
erow = tabular->row_of_cell(end);
if (srow > erow) {
string const
InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
{
+ nodraw(true);
if (the_locking_inset) {
string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
- if (!str.empty())
+ if (!str.empty()) {
+ nodraw(false);
return str;
+ }
if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this));
+ nodraw(false);
return string();
}
++actcell;
}
- nodraw(true);
// otherwise we have to lock the next inset and ask for it's selecttion
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
bv->unlockInset(const_cast<InsetTabular *>(this));
return string();
}
-
+
// otherwise we have to lock the next inset and ask for it's selecttion
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
bool InsetTabular::searchForward(BufferView * bv, string const & str,
- bool const & cs, bool const & mw)
+ bool cs, bool mw)
{
+ nodraw(true);
if (the_locking_inset) {
- if (the_locking_inset->searchForward(bv, str, cs, mw))
+ if (the_locking_inset->searchForward(bv, str, cs, mw)) {
+ nodraw(false);
+ updateLocal(bv, CELL, false);
return true;
+ }
if (tabular->IsLastCell(actcell)) {
+ nodraw(false);
bv->unlockInset(const_cast<InsetTabular *>(this));
return false;
}
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv);
-#if 0
- bool const res = searchForward(bv, str, cs, mw);
- updateLocal(bv, NONE, false);
- bv->updateInset(const_cast<InsetTabular *>(this), false);
- return res;
-#else
- return searchForward(bv, str, cs, mw);
-#endif
+ bool const ret = searchForward(bv, str, cs, mw);
+ nodraw(false);
+ updateLocal(bv, CELL, false);
+ return ret;
}
bool InsetTabular::searchBackward(BufferView * bv, string const & str,
- bool const & cs, bool const & mw)
+ bool cs, bool mw)
{
+ nodraw(true);
if (the_locking_inset) {
- if (the_locking_inset->searchBackward(bv, str, cs, mw))
+ if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
+ nodraw(false);
+ updateLocal(bv, CELL, false);
return true;
+ }
if (!actcell) { // we are already in the first cell
+ nodraw(false);
bv->unlockInset(const_cast<InsetTabular *>(this));
return false;
}
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv, false);
-#if 0
- bool const res = searchBackward(bv, str, cs, mw);
- bv->updateInset(const_cast<InsetTabular *>(this), false);
- return res;
-#else
- return searchBackward(bv, str, cs, mw);
-#endif
+ bool const ret = searchBackward(bv, str, cs, mw);
+ nodraw(false);
+ updateLocal(bv, CELL, false);
+ return ret;
}
{
if (the_locking_inset)
return the_locking_inset->insetAllowed(code);
+ // we return true here because if the inset is not locked someone
+ // wants to insert something in one of our insettexts and we generally
+ // allow to do so.
+ return true;
+}
+
+
+bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
+{
+ const int cell = tabular->GetCellFromInset(in, actcell);
+
+ if (cell != -1)
+ return tabular->GetPWidth(cell).zero();
+
+ // well we didn't obviously find it so maybe our owner knows more
+ if (owner())
+ return owner()->forceDefaultParagraphs(in);
+ // if we're here there is really something strange going on!!!
return false;
}
+
+bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
+ bool usePaste)
+{
+ if (buf.length() <= 0)
+ return true;
+
+ int cols = 1;
+ int rows = 1;
+ int maxCols = 1;
+ string::size_type len = buf.length();
+ string::size_type p = 0;
+
+ while (p < len &&
+ ((p = buf.find_first_of("\t\n", p)) != string::npos))
+ {
+ switch (buf[p]) {
+ case '\t':
+ ++cols;
+ break;
+ case '\n':
+ if ((p+1) < len)
+ ++rows;
+ maxCols = max(cols, maxCols);
+ cols = 1;
+ break;
+ }
+ ++p;
+ }
+ maxCols = max(cols, maxCols);
+ LyXTabular * loctab;
+ int cell = 0;
+ int ocol = 0;
+ int row = 0;
+ if (usePaste) {
+ delete paste_tabular;
+ paste_tabular = new LyXTabular(bv->buffer()->params,
+ this, rows, maxCols);
+ loctab = paste_tabular;
+ cols = 0;
+ } else {
+ loctab = tabular.get();
+ cell = actcell;
+ ocol = actcol;
+ row = actrow;
+ }
+ string::size_type op = 0;
+ int cells = loctab->GetNumberOfCells();
+ p = 0;
+ cols = ocol;
+ rows = loctab->rows();
+ int const columns = loctab->columns();
+ while ((cell < cells) && (p < len) && (row < rows) &&
+ (p = buf.find_first_of("\t\n", p)) != string::npos)
+ {
+ if (p >= len)
+ break;
+ switch (buf[p]) {
+ case '\t':
+ // we can only set this if we are not too far right
+ if (cols < columns) {
+ InsetText * ti = loctab->GetCellInset(cell);
+ LyXFont const font = ti->getLyXText(bv)->
+ getFont(bv->buffer(), ti->paragraph(), 0);
+ ti->setText(buf.substr(op, p-op), font);
+ ++cols;
+ ++cell;
+ }
+ break;
+ case '\n':
+ // we can only set this if we are not too far right
+ if (cols < columns) {
+ InsetText * ti = loctab->GetCellInset(cell);
+ LyXFont const font = ti->getLyXText(bv)->
+ getFont(bv->buffer(), ti->paragraph(), 0);
+ ti->setText(buf.substr(op, p-op), font);
+ }
+ cols = ocol;
+ ++row;
+ if (row < rows)
+ cell = loctab->GetCellNumber(row, cols);
+ break;
+ }
+ ++p;
+ op = p;
+ }
+ // check for the last cell if there is no trailing '\n'
+ if ((cell < cells) && (op < len)) {
+ InsetText * ti = loctab->GetCellInset(cell);
+ LyXFont const font = ti->getLyXText(bv)->
+ getFont(bv->buffer(), ti->paragraph(), 0);
+ ti->setText(buf.substr(op, len-op), font);
+ }
+
+ return true;
+}