#include "language.h"
#include "BufferView.h"
#include "undo_funcs.h"
+#include "support/LAssert.h"
+#include "support/lstrings.h"
using std::ostream;
using std::ifstream;
InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
bool same_id)
- : buffer(&buf)
+ : UpdatableInset(tab, same_id), buffer(&buf)
{
tabular.reset(new LyXTabular(this, *(tab.tabular)));
the_locking_inset = 0;
actrow = actcell = 0;
sel_cell_start = sel_cell_end = 0;
need_update = INIT;
- if (same_id)
- id_ = tab.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;
}
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;
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();
}
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);
}
-bool InsetTabular::Delete()
+bool InsetTabular::deletable()
{
-#warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
-#warning I guess this could be 'deletable'! (Jug)
return true;
}
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);
}
+
Paragraph * InsetTabular::getParFromID(int id) const
{
Paragraph * result;
return 0;
}
+
Paragraph * InsetTabular::firstParagraph() const
{
if (the_locking_inset)
return 0;
}
+
LyXCursor const & InsetTabular::cursor(BufferView * bv) const
{
if (the_locking_inset)
}
-string InsetTabular::selectNextWord(BufferView * bv, float & value) const
+string const InsetTabular::selectNextWord(BufferView * bv, float & value) const
{
if (the_locking_inset) {
- string str;
- str = the_locking_inset->selectNextWord(bv, value);
+ 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();
+ 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));
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv, 0, 0, 0);
- string str = selectNextWordInt(bv, value);
+ string const str(selectNextWordInt(bv, value));
if (!str.empty())
resetPos(bv);
return str;
}
+
string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
{
- if (the_locking_inset) {
- string str;
- str = the_locking_inset->selectNextWord(bv, value);
- if (!str.empty())
- return str;
- }
+ // 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();
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;
+}