#include "gettext.h"
#include "language.h"
#include "BufferView.h"
+#include "undo_funcs.h"
+#include "support/LAssert.h"
+#include "support/lstrings.h"
using std::ostream;
using std::ifstream;
rows = 1;
if (columns <= 0)
columns = 1;
- tabular.reset(new LyXTabular(this, rows,columns));
+ tabular.reset(new LyXTabular(this, rows, columns));
// for now make it always display as display() inset
// just for test!!!
the_locking_inset = 0;
}
-InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
- : buffer(&buf)
+InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
+ bool same_id)
+ : UpdatableInset(tab, same_id), buffer(&buf)
{
tabular.reset(new LyXTabular(this, *(tab.tabular)));
the_locking_inset = 0;
}
-Inset * InsetTabular::clone(Buffer const & buf) const
+Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
{
- InsetTabular * t = new InsetTabular(*this, buf);
- t->tabular.reset(tabular->clone(t));
- return t;
+ return new InsetTabular(*this, buf, same_id);
}
h = pain.paperHeight();
if ((top_x + w) > pain.paperWidth())
w = pain.paperWidth();
- pain.fillRectangle(tx, ty, w, h);
+ pain.fillRectangle(tx, ty, w, h, backgroundColor());
need_update = FULL;
cleared = true;
}
if (the_locking_inset &&
tabular->GetCellInset(actcell) != the_locking_inset)
{
-#warning Jürgen, why is this?
Inset * inset = tabular->GetCellInset(cell);
for (i = 0;
inset != the_locking_inset && i < tabular->rows();
}
}
} else {
- // copute baseline for actual row
+ // compute baseline for actual row
for (i = 0; i < actrow; ++i) {
baseline += tabular->GetDescentOfRow(i) +
tabular->GetAscentOfRow(i + 1) +
baseline - tabular->GetAscentOfRow(i) + 1,
int(cx - nx - 1),
tabular->GetAscentOfRow(i) +
- tabular->GetDescentOfRow(i) - 1);
+ tabular->GetDescentOfRow(i) - 1,
+ backgroundColor());
// clear behind the inset
pain.fillRectangle(
int(cx + the_locking_inset->width(bv,font) + 1),
the_locking_inset->width(bv,font) -
tabular->GetAdditionalWidth(cell) - 1,
tabular->GetAscentOfRow(i) +
- tabular->GetDescentOfRow(i) - 1);
+ tabular->GetDescentOfRow(i) - 1,
+ backgroundColor());
}
}
x -= ADD_TO_TABULAR_WIDTH;
x += width(bv, font);
- if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
+ if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
int i = 0;
for(Inset * inset=owner(); inset; ++i)
inset = inset->owner();
}
if (the_locking_inset)
the_locking_inset->update(bv, font, reinit);
+ if (need_update < FULL &&
+ bv->text->status() == LyXText::NEED_MORE_REFRESH)
+ {
+ need_update = FULL;
+ }
switch (need_update) {
case INIT:
inset_y = 0;
setPos(bv, x, y);
sel_cell_start = sel_cell_end = actcell;
- bv->text->finishUndo();
+ finishUndo();
if (insetHit(bv, x, y) && (button != 3)) {
activateCellInsetAbs(bv, x, y, button);
}
-// UpdateLocal(bv, NONE, false);
-// bv->getOwner()->getPopups().updateFormTabular();
+}
+
+
+void InsetTabular::edit(BufferView * bv, bool front)
+{
+ UpdatableInset::edit(bv, front);
+
+ if (!bv->lockInset(this)) {
+ lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
+ return;
+ }
+ locked = true;
+ the_locking_inset = 0;
+ inset_x = 0;
+ inset_y = 0;
+ if (front)
+ actcell = 0;
+ else
+ actcell = tabular->GetNumberOfCells() - 1;
+ sel_cell_start = sel_cell_end = actcell;
+ resetPos(bv);
+ finishUndo();
}
lyxerr[Debug::INSETS] << "OK" << endl;
the_locking_inset = tabular->GetCellInset(actcell);
resetPos(bv);
- inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+ inset_y = cursor_.y();
return true;
} else if (the_locking_inset && (the_locking_inset == inset)) {
lyxerr[Debug::INSETS] << "OK" << endl;
resetPos(bv);
- inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+ inset_y = cursor_.y();
} else if (the_locking_inset) {
lyxerr[Debug::INSETS] << "MAYBE" << endl;
return the_locking_inset->lockInsetInInset(bv, inset);
}
-UpdatableInset * InsetTabular::getLockingInset()
+UpdatableInset * InsetTabular::getLockingInset() const
{
- return the_locking_inset ? the_locking_inset->getLockingInset() : this;
+ return the_locking_inset ? the_locking_inset->getLockingInset() :
+ const_cast<InsetTabular *>(this);
}
case LFUN_CUT:
if (!copySelection(bv))
break;
- bv->text->setUndo(bv->buffer(), Undo::DELETE,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::DELETE,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
cutSelection();
updateLocal(bv, INIT, true);
break;
case LFUN_COPY:
if (!hasSelection())
break;
- bv->text->finishUndo();
+ finishUndo();
copySelection(bv);
break;
case LFUN_PASTESELECTION:
}
case LFUN_PASTE:
if (hasPasteBuffer()) {
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::INSERT,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
pasteSelection(bv);
updateLocal(bv, INIT, true);
break;
}
-void InsetTabular::getCursorPos(BufferView *,
- int & x, int & y) const
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
{
- x = cursor.x() - top_x;
- y = cursor.y();
+ if (the_locking_inset) {
+ the_locking_inset->getCursorPos(bv, x, y);
+ return;
+ }
+ x = cursor_.x() - top_x;
+ y = cursor_.y();
}
if (isCursorVisible())
bv->hideLockedInsetCursor();
else
- bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
toggleCursorVisible();
}
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
- bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
if (show)
- bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
setCursorVisible(true);
}
}
void InsetTabular::setPos(BufferView * bv, int x, int y) const
{
- cursor.y(0);
+ cursor_.y(0);
actcell = actrow = actcol = 0;
int ly = tabular->GetDescentOfRow(actrow);
// first search the right row
while((ly < y) && (actrow < tabular->rows())) {
- cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+ cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
tabular->GetAscentOfRow(actrow + 1) +
tabular->GetAdditionalHeight(actrow + 1));
++actrow;
- ly = cursor.y() + tabular->GetDescentOfRow(actrow);
+ ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
}
actcell = tabular->GetCellNumber(actrow, actcol);
tabular->GetAdditionalWidth(actcell - 1));
#else
// Jürgen, you should check that this is correct. (Lgb)
+#warning Jürgen, please check. (Lgb)
for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
lx += tabular->GetWidthOfColumn(actcell + 1)
+ tabular->GetAdditionalWidth(actcell);
}
#endif
- cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
+ cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
resetPos(bv);
}
int cell = 0;
actrow = 0;
- cursor.y(0);
+ cursor_.y(0);
for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
if (tabular->IsLastCellInRow(cell)) {
- cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+ cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
tabular->GetAscentOfRow(actrow + 1) +
tabular->GetAdditionalHeight(actrow + 1));
++actrow;
}
static int const offset = ADD_TO_TABULAR_WIDTH + 2;
int new_x = getCellXPos(actcell);
- int old_x = cursor.x();
+ int old_x = cursor_.x();
new_x += offset;
- cursor.x(new_x);
+ cursor_.x(new_x);
// cursor.x(getCellXPos(actcell) + offset);
if ((actcol < tabular->columns()-1) && scroll(false) &&
(tabular->GetWidthOfTabular() < bv->workWidth()-20))
} else if (the_locking_inset &&
(tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
{
- int xx = cursor.x() - offset + bv->text->getRealCursorX(bv);
+ int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
if (xx > (bv->workWidth()-20)) {
scroll(bv, -(xx - bv->workWidth() + 60));
updateLocal(bv, FULL, false);
scroll(bv, xx);
updateLocal(bv, FULL, false);
}
- } else if ((cursor.x() - offset) > 20 &&
- (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
+ } else if ((cursor_.x() - offset) > 20 &&
+ (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
> (bv->workWidth() - 20)) {
scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
updateLocal(bv, FULL, false);
- } else if ((cursor.x() - offset) < 20) {
- scroll(bv, 20 - cursor.x() + offset);
+ } else if ((cursor_.x() - offset) < 20) {
+ scroll(bv, 20 - cursor_.x() + offset);
updateLocal(bv, FULL, false);
} else if (scroll(false) && top_x > 20 &&
(top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
- scroll(bv, old_x - cursor.x());
+ scroll(bv, old_x - cursor_.x());
updateLocal(bv, FULL, false);
}
if ((!the_locking_inset ||
int y = 0;
if (old_locking_inset) {
old_locking_inset->getCursorPos(bv, x, y);
- x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+ x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
}
if (activateCellInset(bv, x, 0))
return DISPATCHED;
int y = 0;
if (old_locking_inset) {
old_locking_inset->getCursorPos(bv, x, y);
- x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+ x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
}
if (activateCellInset(bv, x, 0))
return DISPATCHED;
++actcell;
}
if (lock) {
- bool rtl = tabular->GetCellInset(actcell)->par->
+ bool rtl = tabular->GetCellInset(actcell)->paragraph()->
isRightToLeftPar(bv->buffer()->params);
activateCellInset(bv, 0, 0, 0, !rtl);
}
--actcell;
}
if (lock) {
- bool rtl = tabular->GetCellInset(actcell)->par->
+ bool rtl = tabular->GetCellInset(actcell)->paragraph()->
isRightToLeftPar(bv->buffer()->params);
activateCellInset(bv, 0, 0, 0, !rtl);
}
}
-bool InsetTabular::Delete()
+bool InsetTabular::deletable()
{
-#warning Is this func correctly named? Or should it be "deletable"?
return true;
}
sel_cell_end = tabular->GetNumberOfCells() - 1;
}
if (hasSelection()) {
- bool frozen;
- bv->text->setUndo(bv->buffer(), Undo::EDIT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
- frozen = bv->text->undo_frozen;
+ setUndo(bv, Undo::EDIT,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
+ bool frozen = undo_frozen;
if (!frozen)
- bv->text->freezeUndo();
+ freezeUndo();
// apply the fontchange on the whole selection
int sel_row_start;
int sel_row_end;
}
}
if (!frozen)
- bv->text->unFreezeUndo();
+ unFreezeUndo();
updateLocal(bv, INIT, true);
}
if (the_locking_inset)
sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
}
- bv->text->setUndo(bv->buffer(), Undo::FINISH,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::FINISH,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
int row = tabular->row_of_cell(actcell);
int column = tabular->column_of_cell(actcell);
bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
int button)
{
- inset_x = cursor.x()
+ inset_x = cursor_.x()
- top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_y = cursor_.y();
return activateCellInset(bv, x - inset_x, y - inset_y, button);
}
bool InsetTabular::insetHit(BufferView *, int x, int) const
{
return (x + top_x)
- > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
+ > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
}
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 << "Actcell not equal to actual cell!" << std::endl;
- //raise(SIGSTOP);
- cell = -1;
- }
+ cell = actcell;
+ if (tabular->GetCellInset(cell) != inset) {
+
+ lyxerr << "Actcell not equal to actual cell!\n";
+ cell = -1;
+ }
}
int const n = tabular->GetNumberOfCells();
if (cell == -1) {
- cell = 0;
- for (; cell < n; ++cell) {
+ for (cell = 0; cell < n; ++cell) {
if (tabular->GetCellInset(cell) == inset)
break;
}
}
if (cell >= n) {
- return -1;
+ lyxerr << "Own inset not found, shouldn't really happen!\n";
+ return -1;
}
int w = getMaxWidthOfCell(bv, cell);
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);
+#if 0
+ // if we're locked lock the actual insettext and return it's LyXText!!!
+ if (locked) {
+ UpdatableInset * inset =
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+ inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
+ return the_locking_inset->getLyXText(bv, recursive);
+ }
+#endif
return Inset::getLyXText(bv, recursive);
}
const_cast<InsetTabular *>(this));
}
+
//
// functions returns:
// 0 ... disabled
if (!hasSelection())
return false;
- //int sel_col_start;
- //int sel_col_end;
- //int sel_row_start;
- //int sel_row_end;
-
int sel_col_start = tabular->column_of_cell(sel_cell_start);
int sel_col_end = tabular->column_of_cell(sel_cell_end);
if (sel_col_start > sel_col_end) {
int sel_row_start = tabular->row_of_cell(sel_cell_start);
int sel_row_end = tabular->row_of_cell(sel_cell_end);
if (sel_row_start > sel_row_end) {
- //int tmp = sel_row_start;
- //sel_row_start = sel_row_end;
- //sel_row_end = tmp;
swap(sel_row_start, sel_row_end);
}
if (sel_cell_start > sel_cell_end) {
- //int tmp = sel_cell_start;
- //sel_cell_start = sel_cell_end;
- //sel_cell_end = tmp;
swap(sel_cell_start, sel_cell_end);
}
for (int i = sel_row_start; i <= sel_row_end; ++i) {
ecol = tabular->right_column_of_cell(sel_cell_end);
}
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+
+Paragraph * InsetTabular::getParFromID(int id) const
+{
+ Paragraph * result;
+ for(int i = 0; i < tabular->rows(); ++i) {
+ for(int j = 0; j < tabular->columns(); ++j) {
+ if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
+ return result;
+ }
+ }
+ return 0;
+}
+
+
+Paragraph * InsetTabular::firstParagraph() const
+{
+ if (the_locking_inset)
+ return the_locking_inset->firstParagraph();
+ return 0;
+}
+
+
+LyXCursor const & InsetTabular::cursor(BufferView * bv) const
+{
+ if (the_locking_inset)
+ return the_locking_inset->cursor(bv);
+ return Inset::cursor(bv);
+}
+
+
+Inset * InsetTabular::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetTabular *>(this);
+
+ Inset * result;
+ for(int i=0; i < tabular->rows(); ++i) {
+ for(int j=0; j < tabular->columns(); ++j) {
+ if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
+ return result;
+ }
+ }
+ return 0;
+}
+
+
+string const InsetTabular::selectNextWord(BufferView * bv, float & value) const
+{
+ if (the_locking_inset) {
+ string const str(the_locking_inset->selectNextWord(bv, value));
+ if (!str.empty())
+ return str;
+ if (tabular->IsLastCell(actcell)) {
+ bv->unlockInset(const_cast<InsetTabular *>(this));
+ return string();
+ }
+ ++actcell;
+ }
+
+ // otherwise we have to lock the next inset and ask for it's selecttion
+ UpdatableInset * inset =
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+ inset->edit(bv, 0, 0, 0);
+ string const str(selectNextWordInt(bv, value));
+ if (!str.empty())
+ resetPos(bv);
+ return str;
+}
+
+
+string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
+{
+ // when entering this function the inset should be ALWAYS locked!
+ lyx::Assert(the_locking_inset);
+
+ string const str(the_locking_inset->selectNextWord(bv, value));
+ if (!str.empty())
+ return str;
+
+ if (tabular->IsLastCell(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));
+ inset->edit(bv, 0, 0, 0);
+ return selectNextWordInt(bv, value);
+}
+
+
+void InsetTabular::selectSelectedWord(BufferView * bv)
+{
+ if (the_locking_inset) {
+ the_locking_inset->selectSelectedWord(bv);
+ return;
+ }
+ return;
+}
+
+
+void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
+{
+ if (the_locking_inset) {
+ the_locking_inset->toggleSelection(bv, kill_selection);
+ }
+}
+
+
+bool InsetTabular::searchForward(BufferView * bv, string const & str,
+ bool const & cs, bool const & mw)
+{
+ if (the_locking_inset) {
+ if (the_locking_inset->searchForward(bv, str, cs, mw))
+ return true;
+ if (tabular->IsLastCell(actcell)) {
+ bv->unlockInset(const_cast<InsetTabular *>(this));
+ return false;
+ }
+ ++actcell;
+ }
+ nodraw(true);
+ // otherwise we have to lock the next inset and search there
+ UpdatableInset * inset =
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+ inset->edit(bv);
+ bool const res = searchForward(bv, str, cs, mw);
+ updateLocal(bv, NONE, false);
+ nodraw(false);
+ bv->updateInset(const_cast<InsetTabular *>(this), false);
+ return res;
+}
+
+
+bool InsetTabular::searchBackward(BufferView * bv, string const & str,
+ bool const & cs, bool const & mw)
+{
+ if (the_locking_inset) {
+ if (the_locking_inset->searchBackward(bv, str, cs, mw))
+ return true;
+ if (!actcell) { // we are already in the first cell
+ bv->unlockInset(const_cast<InsetTabular *>(this));
+ return false;
+ }
+ --actcell;
+ }
+ nodraw(true);
+ // otherwise we have to lock the next inset and search there
+ UpdatableInset * inset =
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+ inset->edit(bv, false);
+ bool const res = searchBackward(bv, str, cs, mw);
+ nodraw(false);
+ bv->updateInset(const_cast<InsetTabular *>(this), false);
+ return res;
+}