+
+
+bool InsetTabular::nodraw() const
+{
+ if (!UpdatableInset::nodraw() && the_locking_inset)
+ return the_locking_inset->nodraw();
+ return UpdatableInset::nodraw();
+}
+
+
+int InsetTabular::scroll(bool recursive) const
+{
+ int sx = UpdatableInset::scroll(false);
+
+ if (recursive && the_locking_inset)
+ sx += the_locking_inset->scroll(recursive);
+
+ return sx;
+}
+
+
+bool InsetTabular::doClearArea() const
+{
+ return !locked || (need_update & (FULL|INIT));
+}
+
+
+void InsetTabular::getSelection(int & srow, int & erow,
+ int & scol, int & ecol) const
+{
+ 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) {
+ swap(srow, erow);
+ }
+
+ scol = tabular->column_of_cell(start);
+ ecol = tabular->column_of_cell(end);
+ if (scol > ecol) {
+ swap(scol, ecol);
+ } else {
+ ecol = tabular->right_column_of_cell(end);
+ }
+}
+
+
+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;
+}
+
+
+Paragraph * InsetTabular::getFirstParagraph(int i) const
+{
+ return (i < tabular->GetNumberOfCells())
+ ? tabular->GetCellInset(i)->getFirstParagraph(0)
+ : 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::selectNextWordToSpellcheck(BufferView * bv, float & value) const
+{
+ nodraw(true);
+ if (the_locking_inset) {
+ string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
+ if (!str.empty()) {
+ nodraw(false);
+ return str;
+ }
+ if (tabular->IsLastCell(actcell)) {
+ bv->unlockInset(const_cast<InsetTabular *>(this));
+ nodraw(false);
+ 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));
+ nodraw(false);
+ 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->selectNextWordToSpellcheck(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);
+ 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 cs, bool mw)
+{
+ nodraw(true);
+ if (the_locking_inset) {
+ 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;
+ }
+ ++actcell;
+ }
+ // otherwise we have to lock the next inset and search there
+ UpdatableInset * inset =
+ static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+ inset->edit(bv);
+ 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 cs, bool mw)
+{
+ nodraw(true);
+ if (the_locking_inset) {
+ 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;
+ }
+ --actcell;
+ }
+ // 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 ret = searchBackward(bv, str, cs, mw);
+ nodraw(false);
+ updateLocal(bv, CELL, false);
+ return ret;
+}
+
+
+bool InsetTabular::insetAllowed(Inset::Code code) const
+{
+ if (the_locking_inset)
+ return the_locking_inset->insetAllowed(code);
+ return false;
+}
+
+
+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;
+}