1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
37 #include "frontends/Alert.h"
42 #include "BufferView.h"
43 #include "undo_funcs.h"
44 #include "support/LAssert.h"
45 #include "support/lstrings.h"
56 const int ADD_TO_HEIGHT = 2;
57 const int ADD_TO_TABULAR_WIDTH = 2;
59 LyXTabular * paste_tabular = 0;
62 struct TabularFeature {
63 LyXTabular::Feature action;
67 //tabular_features * tabularFeatures = 0;
69 TabularFeature tabularFeature[] =
71 { LyXTabular::APPEND_ROW, "append-row" },
72 { LyXTabular::APPEND_COLUMN, "append-column" },
73 { LyXTabular::DELETE_ROW, "delete-row" },
74 { LyXTabular::DELETE_COLUMN, "delete-column" },
75 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
76 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
77 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
78 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
79 { LyXTabular::ALIGN_LEFT, "align-left" },
80 { LyXTabular::ALIGN_RIGHT, "align-right" },
81 { LyXTabular::ALIGN_CENTER, "align-center" },
82 { LyXTabular::VALIGN_TOP, "valign-top" },
83 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
84 { LyXTabular::VALIGN_CENTER, "valign-center" },
85 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
86 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
87 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
88 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
89 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
90 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
91 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
92 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
93 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
94 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
95 { LyXTabular::MULTICOLUMN, "multicolumn" },
96 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
97 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
98 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
99 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
100 { LyXTabular::SET_PWIDTH, "set-pwidth" },
101 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
102 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
103 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
104 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
105 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
106 { LyXTabular::SET_USEBOX, "set-usebox" },
107 { LyXTabular::SET_LTHEAD, "set-lthead" },
108 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
109 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
110 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
111 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
112 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
113 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
114 { LyXTabular::LAST_ACTION, "" }
120 bool InsetTabular::hasPasteBuffer() const
122 return (paste_tabular != 0);
126 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
133 tabular.reset(new LyXTabular(this, rows, columns));
134 // for now make it always display as display() inset
136 the_locking_inset = 0;
137 locked = no_selection = false;
139 actrow = actcell = 0;
143 in_reset_pos = false;
147 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
149 : UpdatableInset(tab, same_id), buffer(&buf)
151 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
152 the_locking_inset = 0;
153 locked = no_selection = false;
155 actrow = actcell = 0;
156 sel_cell_start = sel_cell_end = 0;
159 in_reset_pos = false;
163 InsetTabular::~InsetTabular()
169 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
171 return new InsetTabular(*this, buf, same_id);
175 void InsetTabular::write(Buffer const * buf, ostream & os) const
177 os << " Tabular" << endl;
178 tabular->Write(buf, os);
182 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
184 bool const old_format = (lex.getString() == "\\LyXTable");
188 //tabular = new LyXTabular(buf, this, lex);
189 tabular.reset(new LyXTabular(buf, this, lex));
197 string token = lex.getString();
198 while (lex.isOK() && (token != "\\end_inset")) {
200 token = lex.getString();
202 if (token != "\\end_inset") {
203 lex.printError("Missing \\end_inset at this point. "
209 int InsetTabular::ascent(BufferView *, LyXFont const &) const
211 return tabular->GetAscentOfRow(0);
215 int InsetTabular::descent(BufferView *, LyXFont const &) const
217 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
221 int InsetTabular::width(BufferView *, LyXFont const &) const
223 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
227 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
228 float & x, bool cleared) const
236 if (need_update == INIT) {
237 if (calculate_dimensions_of_cells(bv, font, true))
238 bv->text->status = LyXText::CHANGED_IN_DRAW;
243 Painter & pain = bv->painter();
249 UpdatableInset::draw(bv, font, baseline, x, cleared);
252 x += static_cast<float>(scroll());
254 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
255 (top_x != int(x)) || (top_baseline != baseline)))
257 int h = ascent(bv, font) + descent(bv, font);
258 int const tx = display() || !owner() ? 0 : top_x;
259 int w = tx ? width(bv, font) : pain.paperWidth();
260 int ty = baseline - ascent(bv, font);
264 if ((ty + h) > pain.paperHeight())
265 h = pain.paperHeight();
266 if ((top_x + w) > pain.paperWidth())
267 w = pain.paperWidth();
268 pain.fillRectangle(tx, ty, w, h, backgroundColor());
274 top_baseline = baseline;
275 x += ADD_TO_TABULAR_WIDTH;
279 first_visible_cell = -1;
280 for (i = 0; i < tabular->rows(); ++i) {
282 cell = tabular->GetCellNumber(i, 0);
283 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
284 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
286 baseline += tabular->GetDescentOfRow(i) +
287 tabular->GetAscentOfRow(i + 1) +
288 tabular->GetAdditionalHeight(i + 1);
291 for (j = 0; j < tabular->columns(); ++j) {
292 if (nx > bv->workWidth())
294 if (tabular->IsPartOfMultiColumn(i, j))
296 cx = nx + tabular->GetBeginningOfTextInCell(cell);
297 if (first_visible_cell < 0)
298 first_visible_cell = cell;
300 drawCellSelection(pain, nx, baseline, i, j, cell);
302 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
304 drawCellLines(pain, nx, baseline, i, cell);
305 nx += tabular->GetWidthOfColumn(cell);
308 baseline += tabular->GetDescentOfRow(i) +
309 tabular->GetAscentOfRow(i + 1) +
310 tabular->GetAdditionalHeight(i + 1);
312 } else if (need_update == CELL) {
315 if (the_locking_inset &&
316 tabular->GetCellInset(actcell) != the_locking_inset)
318 Inset * inset = tabular->GetCellInset(cell);
320 inset != the_locking_inset && i < tabular->rows();
324 inset != the_locking_inset && j < tabular->columns();
327 if (tabular->IsPartOfMultiColumn(i, j))
329 nx += tabular->GetWidthOfColumn(cell);
331 inset = tabular->GetCellInset(cell);
333 if (tabular->row_of_cell(cell) > i) {
335 baseline += tabular->GetDescentOfRow(i) +
336 tabular->GetAscentOfRow(i + 1) +
337 tabular->GetAdditionalHeight(i + 1);
341 // compute baseline for actual row
342 for (i = 0; i < actrow; ++i) {
343 baseline += tabular->GetDescentOfRow(i) +
344 tabular->GetAscentOfRow(i + 1) +
345 tabular->GetAdditionalHeight(i + 1);
347 // now compute the right x position
348 cell = tabular->GetCellNumber(actrow, 0);
349 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
350 if (tabular->IsPartOfMultiColumn(actrow, j))
352 nx += tabular->GetWidthOfColumn(cell);
356 i = tabular->row_of_cell(cell);
357 if (the_locking_inset != tabular->GetCellInset(cell)) {
358 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
361 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
363 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
364 // clear only if we didn't have a change
365 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
366 // clear before the inset
369 baseline - tabular->GetAscentOfRow(i) + 1,
371 tabular->GetAscentOfRow(i) +
372 tabular->GetDescentOfRow(i) - 1,
374 // clear behind the inset
376 int(cx + the_locking_inset->width(bv,font) + 1),
377 baseline - tabular->GetAscentOfRow(i) + 1,
378 tabular->GetWidthOfColumn(cell) -
379 tabular->GetBeginningOfTextInCell(cell) -
380 the_locking_inset->width(bv,font) -
381 tabular->GetAdditionalWidth(cell) - 1,
382 tabular->GetAscentOfRow(i) +
383 tabular->GetDescentOfRow(i) - 1,
385 // clear below the inset
388 baseline + the_locking_inset->descent(bv, font) + 1,
389 tabular->GetWidthOfColumn(cell) -
390 tabular->GetAdditionalWidth(cell) - 1,
391 tabular->GetAscentOfRow(i) +
392 tabular->GetDescentOfRow(i) -
393 the_locking_inset->ascent(bv, font) -
394 the_locking_inset->descent(bv, font) -
395 TEXT_TO_INSET_OFFSET - 1,
399 x -= ADD_TO_TABULAR_WIDTH;
400 x += width(bv, font);
401 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
403 for(Inset * inset=owner(); inset; ++i)
404 inset = inset->owner();
405 if (calculate_dimensions_of_cells(bv, font, false))
413 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
414 int row, int cell) const
416 int x2 = x + tabular->GetWidthOfColumn(cell);
419 if (!tabular->TopAlreadyDrawed(cell)) {
420 on_off = !tabular->TopLine(cell);
421 pain.line(x, baseline - tabular->GetAscentOfRow(row),
422 x2, baseline - tabular->GetAscentOfRow(row),
423 on_off ? LColor::tabularonoffline : LColor::tabularline,
424 on_off ? Painter::line_onoffdash : Painter::line_solid);
426 on_off = !tabular->BottomLine(cell);
427 pain.line(x,baseline + tabular->GetDescentOfRow(row),
428 x2, baseline + tabular->GetDescentOfRow(row),
429 on_off ? LColor::tabularonoffline : LColor::tabularline,
430 on_off ? Painter::line_onoffdash : Painter::line_solid);
431 if (!tabular->LeftAlreadyDrawed(cell)) {
432 on_off = !tabular->LeftLine(cell);
433 pain.line(x, baseline - tabular->GetAscentOfRow(row),
434 x, baseline + tabular->GetDescentOfRow(row),
435 on_off ? LColor::tabularonoffline : LColor::tabularline,
436 on_off ? Painter::line_onoffdash : Painter::line_solid);
438 on_off = !tabular->RightLine(cell);
439 pain.line(x2 - tabular->GetAdditionalWidth(cell),
440 baseline - tabular->GetAscentOfRow(row),
441 x2 - tabular->GetAdditionalWidth(cell),
442 baseline + tabular->GetDescentOfRow(row),
443 on_off ? LColor::tabularonoffline : LColor::tabularline,
444 on_off ? Painter::line_onoffdash : Painter::line_solid);
448 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
449 int row, int column, int cell) const
451 int cs = tabular->column_of_cell(sel_cell_start);
452 int ce = tabular->column_of_cell(sel_cell_end);
455 cs = tabular->column_of_cell(sel_cell_end);
457 ce = tabular->right_column_of_cell(sel_cell_end);
460 int rs = tabular->row_of_cell(sel_cell_start);
461 int re = tabular->row_of_cell(sel_cell_end);
462 if (rs > re) swap(rs, re);
464 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
465 int w = tabular->GetWidthOfColumn(cell);
466 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
467 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
468 w, h, LColor::selection);
473 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
479 owner()->update(bv, font, true);
486 if (calculate_dimensions_of_cells(bv, font, true))
489 owner()->update(bv, font, true);
493 if (the_locking_inset)
494 the_locking_inset->update(bv, font, reinit);
495 if (need_update < FULL &&
496 bv->text->status() == LyXText::NEED_MORE_REFRESH)
501 switch (need_update) {
505 if (calculate_dimensions_of_cells(bv, font, false))
518 string const InsetTabular::editMessage() const
520 return _("Opened Tabular Inset");
524 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
526 UpdatableInset::edit(bv, x, y, button);
528 if (!bv->lockInset(this)) {
529 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
533 the_locking_inset = 0;
537 sel_cell_start = sel_cell_end = actcell;
539 if (insetHit(bv, x, y) && (button != 3)) {
540 activateCellInsetAbs(bv, x, y, button);
545 void InsetTabular::edit(BufferView * bv, bool front)
547 UpdatableInset::edit(bv, front);
549 if (!bv->lockInset(this)) {
550 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
554 the_locking_inset = 0;
560 actcell = tabular->GetNumberOfCells() - 1;
561 sel_cell_start = sel_cell_end = actcell;
567 void InsetTabular::insetUnlock(BufferView * bv)
569 if (the_locking_inset) {
570 the_locking_inset->insetUnlock(bv);
571 the_locking_inset = 0;
574 no_selection = false;
577 if (scroll(false) || hasSelection()) {
578 sel_cell_start = sel_cell_end = 0;
582 updateLocal(bv, FULL, false);
587 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
588 bool mark_dirty) const
592 calculate_dimensions_of_cells(bv, font, true);
594 if (need_update < what) // only set this if it has greater update
596 if ((what == INIT) && hasSelection())
599 if (need_update != NONE) {
600 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
601 if (locked) // && (what != NONE))
607 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
609 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
614 if (inset == tabular->GetCellInset(actcell)) {
615 lyxerr[Debug::INSETTEXT] << "OK" << endl;
616 the_locking_inset = tabular->GetCellInset(actcell);
619 } else if (the_locking_inset && (the_locking_inset == inset)) {
620 lyxerr[Debug::INSETTEXT] << "OK" << endl;
622 } else if (the_locking_inset) {
623 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
624 return the_locking_inset->lockInsetInInset(bv, inset);
626 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
631 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
634 if (!the_locking_inset)
636 if (the_locking_inset == inset) {
637 the_locking_inset->insetUnlock(bv);
638 the_locking_inset = 0;
640 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
646 updateLocal(bv, CELL, false);
647 showInsetCursor(bv, false);
650 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
651 if (inset->lyxCode() == TABULAR_CODE &&
652 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
653 bv->owner()->getDialogs()->updateTabular(this);
662 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
664 if (!the_locking_inset)
666 if (the_locking_inset != inset) {
667 if (!the_locking_inset->updateInsetInInset(bv, inset))
670 updateLocal(bv, CELL, false);
675 unsigned int InsetTabular::insetInInsetY()
677 if (!the_locking_inset)
680 return inset_y + the_locking_inset->insetInInsetY();
684 UpdatableInset * InsetTabular::getLockingInset() const
686 return the_locking_inset ? the_locking_inset->getLockingInset() :
687 const_cast<InsetTabular *>(this);
691 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
695 if (the_locking_inset)
696 return the_locking_inset->getFirstLockingInsetOfType(c);
701 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
703 if (the_locking_inset)
704 return the_locking_inset->insertInset(bv, inset);
709 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
711 if (hasSelection() && (button == 3))
714 if (hasSelection()) {
716 updateLocal(bv, SELECTION, false);
719 no_selection = false;
721 int const ocell = actcell;
722 int const orow = actrow;
727 updateLocal(bv, NONE, false);
728 sel_cell_start = sel_cell_end = actcell;
730 if ((ocell != actcell) && the_locking_inset) {
731 the_locking_inset->insetUnlock(bv);
732 the_locking_inset = 0;
738 bool const inset_hit = insetHit(bv, x, y);
740 if ((ocell == actcell) && the_locking_inset && inset_hit) {
742 the_locking_inset->insetButtonPress(bv,
743 x - inset_x, y - inset_y,
746 } else if (the_locking_inset) {
747 the_locking_inset->insetUnlock(bv);
749 the_locking_inset = 0;
751 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
754 if (inset_hit && bv->theLockingInset()) {
755 if (activateCellInsetAbs(bv, x, y, button))
756 the_locking_inset->insetButtonPress(bv,
766 void InsetTabular::insetButtonRelease(BufferView * bv,
767 int x, int y, int button)
770 if (the_locking_inset) {
772 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
773 i->insetButtonRelease(bv, x, y, button);
777 bv->owner()->getDialogs()->showTabular(this);
780 if (the_locking_inset) {
781 the_locking_inset->insetButtonRelease(bv,
782 x - inset_x, y - inset_y,
786 no_selection = false;
790 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
792 if (the_locking_inset) {
793 the_locking_inset->insetMotionNotify(bv,
801 int const old_cell = actcell;
804 sel_cell_end = actcell;
805 if (sel_cell_end != old_cell)
806 updateLocal(bv, SELECTION, false);
809 no_selection = false;
813 void InsetTabular::insetKeyPress(XKeyEvent * xke)
815 if (the_locking_inset) {
816 the_locking_inset->insetKeyPress(xke);
822 UpdatableInset::RESULT
823 InsetTabular::localDispatch(BufferView * bv, kb_action action,
826 // We need to save the value of the_locking_inset as the call to
827 // the_locking_inset->LocalDispatch might unlock it.
828 old_locking_inset = the_locking_inset;
829 no_selection = false;
830 UpdatableInset::RESULT result =
831 UpdatableInset::localDispatch(bv, action, arg);
832 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
837 if ((action < 0) && arg.empty())
840 bool hs = hasSelection();
843 // this one have priority over the locked InsetText, if we're not already
844 // inside another tabular then that one get's priority!
845 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
850 unlockInsetInInset(bv, the_locking_inset);
851 if (action == LFUN_TAB)
852 moveNextCell(bv, old_locking_inset != 0);
854 movePrevCell(bv, old_locking_inset != 0);
855 sel_cell_start = sel_cell_end = actcell;
857 updateLocal(bv, SELECTION, false);
858 if (!the_locking_inset) {
860 return DISPATCHED_NOUPDATE;
863 // this to avoid compiler warnings.
869 if (the_locking_inset) {
870 result = the_locking_inset->localDispatch(bv, action, arg);
871 if (result == DISPATCHED_NOUPDATE) {
874 if (sc != scroll()) { // inset has been scrolled
875 the_locking_inset->toggleInsetCursor(bv);
876 updateLocal(bv, FULL, false);
877 the_locking_inset->toggleInsetCursor(bv);
880 } else if (result == DISPATCHED) {
881 the_locking_inset->toggleInsetCursor(bv);
882 updateLocal(bv, CELL, false);
883 the_locking_inset->toggleInsetCursor(bv);
885 } else if (result == FINISHED_UP) {
887 } else if (result == FINISHED_DOWN) {
889 } else if (result == FINISHED_RIGHT) {
897 // --- Cursor Movements ----------------------------------
899 if (tabular->IsLastCellInRow(actcell))
901 moveRight(bv, false);
902 sel_cell_end = actcell;
903 updateLocal(bv, SELECTION, false);
906 result = moveRight(bv);
907 sel_cell_start = sel_cell_end = actcell;
909 updateLocal(bv, SELECTION, false);
912 if (tabular->IsFirstCellInRow(actcell))
915 sel_cell_end = actcell;
916 updateLocal(bv, SELECTION, false);
919 result = moveLeft(bv);
920 sel_cell_start = sel_cell_end = actcell;
922 updateLocal(bv, SELECTION, false);
926 int const ocell = actcell;
928 if ((ocell == sel_cell_end) ||
929 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
930 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
932 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
933 updateLocal(bv, SELECTION, false);
937 result = moveDown(bv, old_locking_inset != 0);
938 sel_cell_start = sel_cell_end = actcell;
940 updateLocal(bv, SELECTION, false);
944 int const ocell = actcell;
946 if ((ocell == sel_cell_end) ||
947 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
948 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
950 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
951 updateLocal(bv, SELECTION, false);
955 result = moveUp(bv, old_locking_inset != 0);
956 sel_cell_start = sel_cell_end = actcell;
958 updateLocal(bv, SELECTION, false);
962 unlockInsetInInset(bv, the_locking_inset);
963 if (bv->text->first + bv->painter().paperHeight() <
964 (top_baseline + tabular->GetHeightOfTabular()))
966 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
967 updateLocal(bv, FULL, false);
968 actcell = tabular->GetCellBelow(first_visible_cell) + column;
970 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
973 updateLocal(bv, CURSOR, false);
978 unlockInsetInInset(bv, the_locking_inset);
979 if (top_baseline < 0) {
980 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
981 updateLocal(bv, FULL, false);
982 if (top_baseline > 0)
985 actcell = tabular->GetCellBelow(first_visible_cell) + column;
990 updateLocal(bv, CURSOR, false);
993 // none of these make sense for insettabular,
994 // but we must catch them to prevent any
995 // selection from being confused
999 case LFUN_WORDLEFTSEL:
1000 case LFUN_WORDRIGHT:
1001 case LFUN_WORDRIGHTSEL:
1002 case LFUN_DOWN_PARAGRAPH:
1003 case LFUN_DOWN_PARAGRAPHSEL:
1004 case LFUN_UP_PARAGRAPH:
1005 case LFUN_UP_PARAGRAPHSEL:
1006 case LFUN_BACKSPACE:
1013 case LFUN_LAYOUT_TABULAR:
1015 bv->owner()->getDialogs()->showTabular(this);
1018 case LFUN_TABULAR_FEATURE:
1019 if (!tabularFeatures(bv, arg))
1020 result = UNDISPATCHED;
1023 if (!copySelection(bv))
1025 setUndo(bv, Undo::DELETE,
1026 bv->text->cursor.par(),
1027 bv->text->cursor.par()->next());
1029 updateLocal(bv, INIT, true);
1032 if (!hasSelection())
1037 case LFUN_PASTESELECTION:
1039 string const clip(bv->getClipboard());
1043 if (clip.find('\t') != string::npos) {
1047 string::size_type len = clip.length();
1048 string::size_type p = 0;
1051 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1059 maxCols = max(cols, maxCols);
1065 maxCols = max(cols, maxCols);
1066 delete paste_tabular;
1067 paste_tabular = new LyXTabular(this, rows, maxCols);
1068 string::size_type op = 0;
1070 int cells = paste_tabular->GetNumberOfCells();
1072 while ((cell < cells) && (p < len) &&
1073 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1078 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1083 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1084 while (cols++ < maxCols)
1092 // check for the last cell if there is no trailing '\n'
1093 if ((cell < cells) && (op < len))
1094 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1096 // so that the clipboard is used and it goes on
1098 // and executes LFUN_PASTESELECTION in insettext!
1099 delete paste_tabular;
1104 if (hasPasteBuffer()) {
1105 setUndo(bv, Undo::INSERT,
1106 bv->text->cursor.par(),
1107 bv->text->cursor.par()->next());
1109 updateLocal(bv, INIT, true);
1112 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1114 // we try to activate the actual inset and put this event down to
1115 // the insets dispatch function.
1116 result = UNDISPATCHED;
1117 if (the_locking_inset)
1120 if (activateCellInset(bv)) {
1121 // reset need_update setted in above function!
1123 result = the_locking_inset->localDispatch(bv, action, arg);
1124 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1125 unlockInsetInInset(bv, the_locking_inset);
1127 // we need to update if this was requested before
1128 updateLocal(bv, NONE, false);
1129 return UNDISPATCHED;
1134 updateLocal(bv, CELL, false);
1139 if (result < FINISHED) {
1140 if (!the_locking_inset) {
1141 showInsetCursor(bv);
1144 bv->unlockInset(this);
1149 int InsetTabular::latex(Buffer const * buf, ostream & os,
1150 bool fragile, bool fp) const
1152 return tabular->Latex(buf, os, fragile, fp);
1156 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1158 // This should be changed to a real ascii export
1159 return tabular->Ascii(buf, os);
1163 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1165 return tabular->Ascii(buf,os);
1169 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1174 // if the table is inside a float it doesn't need the informaltable
1175 // wrapper. Search for it.
1176 for(master = owner();
1177 master && master->lyxCode() != Inset::FLOAT_CODE;
1178 master = master->owner());
1181 os << "<informaltable>\n";
1184 ret+= tabular->DocBook(buf,os);
1186 os << "</informaltable>\n";
1193 void InsetTabular::validate(LaTeXFeatures & features) const
1195 tabular->Validate(features);
1199 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1200 LyXFont const & font,
1207 bool changed = false;
1209 // if we have a locking_inset we should have to check only this cell for
1210 // change so I'll try this to have a boost, but who knows ;)
1211 if ((need_update != INIT) &&
1212 (the_locking_inset == tabular->GetCellInset(actcell))) {
1213 for(int i = 0; i < tabular->columns(); ++i) {
1214 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1216 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1219 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1220 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1221 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1224 for (int i = 0; i < tabular->rows(); ++i) {
1227 for (int j = 0; j < tabular->columns(); ++j) {
1228 if (tabular->IsPartOfMultiColumn(i,j))
1231 inset = tabular->GetCellInset(cell);
1232 if (!reinit && !tabular->GetPWidth(cell).empty())
1233 inset->update(bv, font, false);
1234 maxAsc = max(maxAsc, inset->ascent(bv, font));
1235 maxDesc = max(maxDesc, inset->descent(bv, font));
1236 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1238 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1239 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1247 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1249 if (the_locking_inset) {
1250 the_locking_inset->getCursorPos(bv, x, y);
1253 x = cursor_.x() - top_x;
1258 void InsetTabular::toggleInsetCursor(BufferView * bv)
1260 if (the_locking_inset) {
1261 the_locking_inset->toggleInsetCursor(bv);
1265 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1267 int const asc = lyxfont::maxAscent(font);
1268 int const desc = lyxfont::maxDescent(font);
1270 if (isCursorVisible())
1271 bv->hideLockedInsetCursor();
1273 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1274 toggleCursorVisible();
1278 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1280 if (!isCursorVisible()) {
1281 LyXFont font; // = GetFont(par, cursor.pos);
1283 int const asc = lyxfont::maxAscent(font);
1284 int const desc = lyxfont::maxDescent(font);
1285 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1287 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1288 setCursorVisible(true);
1293 void InsetTabular::hideInsetCursor(BufferView * bv)
1295 if (isCursorVisible()) {
1296 bv->hideLockedInsetCursor();
1297 setCursorVisible(false);
1302 void InsetTabular::fitInsetCursor(BufferView * bv) const
1304 if (the_locking_inset) {
1305 the_locking_inset->fitInsetCursor(bv);
1310 int const asc = lyxfont::maxAscent(font);
1311 int const desc = lyxfont::maxDescent(font);
1312 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1316 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1320 actcell = actrow = actcol = 0;
1321 int ly = tabular->GetDescentOfRow(actrow);
1323 // first search the right row
1324 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1325 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1326 tabular->GetAscentOfRow(actrow + 1) +
1327 tabular->GetAdditionalHeight(actrow + 1));
1329 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1331 actcell = tabular->GetCellNumber(actrow, actcol);
1333 // now search the right column
1334 int lx = tabular->GetWidthOfColumn(actcell) -
1335 tabular->GetAdditionalWidth(actcell);
1336 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1337 lx += tabular->GetWidthOfColumn(actcell + 1)
1338 + tabular->GetAdditionalWidth(actcell);
1340 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1345 int InsetTabular::getCellXPos(int cell) const
1349 for (; !tabular->IsFirstCellInRow(c); --c)
1351 int lx = tabular->GetWidthOfColumn(cell);
1352 for (; c < cell; ++c) {
1353 lx += tabular->GetWidthOfColumn(c);
1355 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1359 void InsetTabular::resetPos(BufferView * bv) const
1361 if (!locked || nodraw())
1363 #warning This should be fixed in the right manner (20011128 Jug)
1364 // fast hack to fix infinite repaintings!
1367 in_reset_pos = true;
1369 actcol = tabular->column_of_cell(actcell);
1374 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1375 if (tabular->IsLastCellInRow(cell)) {
1376 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1377 tabular->GetAscentOfRow(actrow + 1) +
1378 tabular->GetAdditionalHeight(actrow + 1));
1382 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1383 int new_x = getCellXPos(actcell);
1384 int old_x = cursor_.x();
1387 // cursor.x(getCellXPos(actcell) + offset);
1388 if ((actcol < tabular->columns()-1) && scroll(false) &&
1389 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1392 updateLocal(bv, FULL, false);
1393 } else if (the_locking_inset &&
1394 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1396 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1397 if (xx > (bv->workWidth()-20)) {
1398 scroll(bv, -(xx - bv->workWidth() + 60));
1399 updateLocal(bv, FULL, false);
1400 } else if (xx < 20) {
1406 updateLocal(bv, FULL, false);
1408 } else if ((cursor_.x() - offset) > 20 &&
1409 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1410 > (bv->workWidth() - 20)) {
1411 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1412 updateLocal(bv, FULL, false);
1413 } else if ((cursor_.x() - offset) < 20) {
1414 scroll(bv, 20 - cursor_.x() + offset);
1415 updateLocal(bv, FULL, false);
1416 } else if (scroll(false) && top_x > 20 &&
1417 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1418 scroll(bv, old_x - cursor_.x());
1419 updateLocal(bv, FULL, false);
1421 if (the_locking_inset) {
1422 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1423 inset_y = cursor_.y();
1425 if ((!the_locking_inset ||
1426 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1427 actcell != oldcell) {
1428 InsetTabular * inset = const_cast<InsetTabular *>(this);
1429 bv->owner()->getDialogs()->updateTabular(inset);
1432 in_reset_pos = false;
1436 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1438 if (lock && !old_locking_inset) {
1439 if (activateCellInset(bv))
1442 bool moved = isRightToLeft(bv)
1443 ? movePrevCell(bv) : moveNextCell(bv);
1445 return FINISHED_RIGHT;
1446 if (lock && activateCellInset(bv))
1450 return DISPATCHED_NOUPDATE;
1454 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1456 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1459 if (lock) { // behind the inset
1460 if (activateCellInset(bv, 0, 0, 0, true))
1464 return DISPATCHED_NOUPDATE;
1468 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1470 int const ocell = actcell;
1471 actcell = tabular->GetCellAbove(actcell);
1472 if (actcell == ocell) // we moved out of the inset
1478 if (old_locking_inset) {
1479 old_locking_inset->getCursorPos(bv, x, y);
1480 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1482 if (activateCellInset(bv, x, 0))
1485 return DISPATCHED_NOUPDATE;
1489 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1491 int const ocell = actcell;
1492 actcell = tabular->GetCellBelow(actcell);
1493 if (actcell == ocell) // we moved out of the inset
1494 return FINISHED_DOWN;
1499 if (old_locking_inset) {
1500 old_locking_inset->getCursorPos(bv, x, y);
1501 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1503 if (activateCellInset(bv, x, 0))
1506 return DISPATCHED_NOUPDATE;
1510 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1512 if (isRightToLeft(bv)) {
1513 if (tabular->IsFirstCellInRow(actcell)) {
1514 int row = tabular->row_of_cell(actcell);
1515 if (row == tabular->rows() - 1)
1517 actcell = tabular->GetLastCellInRow(row);
1518 actcell = tabular->GetCellBelow(actcell);
1525 if (tabular->IsLastCell(actcell))
1530 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1531 isRightToLeftPar(bv->buffer()->params);
1532 activateCellInset(bv, 0, 0, 0, !rtl);
1539 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1541 if (isRightToLeft(bv)) {
1542 if (tabular->IsLastCellInRow(actcell)) {
1543 int row = tabular->row_of_cell(actcell);
1546 actcell = tabular->GetFirstCellInRow(row);
1547 actcell = tabular->GetCellAbove(actcell);
1549 if (tabular->IsLastCell(actcell))
1554 if (!actcell) // first cell
1559 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1560 isRightToLeftPar(bv->buffer()->params);
1561 activateCellInset(bv, 0, 0, 0, !rtl);
1568 bool InsetTabular::deletable() const
1574 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1579 sel_cell_end = tabular->GetNumberOfCells() - 1;
1581 if (hasSelection()) {
1582 setUndo(bv, Undo::EDIT,
1583 bv->text->cursor.par(),
1584 bv->text->cursor.par()->next());
1585 bool frozen = undo_frozen;
1588 // apply the fontchange on the whole selection
1593 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1594 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1595 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1596 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1601 updateLocal(bv, INIT, true);
1603 if (the_locking_inset)
1604 the_locking_inset->setFont(bv, font, tall);
1608 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1610 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1613 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1614 string const tmp = tabularFeature[i].feature;
1616 if (tmp == what.substr(0, tmp.length())) {
1617 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1618 //tabularFeatures[i].feature.length())) {
1619 action = tabularFeature[i].action;
1623 if (action == LyXTabular::LAST_ACTION)
1627 frontStrip(what.substr(tabularFeature[i].feature.length()));
1628 tabularFeatures(bv, action, val);
1633 void InsetTabular::tabularFeatures(BufferView * bv,
1634 LyXTabular::Feature feature,
1635 string const & value)
1641 bool setLines = false;
1642 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1643 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1646 case LyXTabular::M_ALIGN_LEFT:
1647 case LyXTabular::ALIGN_LEFT:
1648 setAlign=LYX_ALIGN_LEFT;
1650 case LyXTabular::M_ALIGN_RIGHT:
1651 case LyXTabular::ALIGN_RIGHT:
1652 setAlign=LYX_ALIGN_RIGHT;
1654 case LyXTabular::M_ALIGN_CENTER:
1655 case LyXTabular::ALIGN_CENTER:
1656 setAlign=LYX_ALIGN_CENTER;
1658 case LyXTabular::M_VALIGN_TOP:
1659 case LyXTabular::VALIGN_TOP:
1660 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1662 case LyXTabular::M_VALIGN_BOTTOM:
1663 case LyXTabular::VALIGN_BOTTOM:
1664 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1666 case LyXTabular::M_VALIGN_CENTER:
1667 case LyXTabular::VALIGN_CENTER:
1668 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1673 if (hasSelection()) {
1674 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1676 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1677 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1679 setUndo(bv, Undo::FINISH,
1680 bv->text->cursor.par(),
1681 bv->text->cursor.par()->next());
1683 LyXTabular::ltType ltt;
1684 int row = ltt.row = tabular->row_of_cell(actcell);
1685 int column = tabular->column_of_cell(actcell);
1689 case LyXTabular::SET_PWIDTH:
1691 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1692 tabular->SetColumnPWidth(actcell,value);
1694 for (int i = 0; i < tabular->rows(); ++i) {
1695 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1698 updateLocal(bv, INIT, true);
1702 case LyXTabular::SET_MPWIDTH:
1704 bool const update = (tabular->GetPWidth(actcell) != value);
1705 tabular->SetMColumnPWidth(actcell,value);
1707 for (int i = 0; i < tabular->rows(); ++i) {
1708 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1711 updateLocal(bv, INIT, true);
1715 case LyXTabular::SET_SPECIAL_COLUMN:
1716 case LyXTabular::SET_SPECIAL_MULTI:
1717 tabular->SetAlignSpecial(actcell,value,feature);
1718 updateLocal(bv, FULL, true);
1720 case LyXTabular::APPEND_ROW:
1721 // append the row into the tabular
1722 unlockInsetInInset(bv, the_locking_inset);
1723 tabular->AppendRow(actcell);
1724 updateLocal(bv, INIT, true);
1726 case LyXTabular::APPEND_COLUMN:
1727 // append the column into the tabular
1728 unlockInsetInInset(bv, the_locking_inset);
1729 tabular->AppendColumn(actcell);
1730 actcell = tabular->GetCellNumber(row, column);
1731 updateLocal(bv, INIT, true);
1733 case LyXTabular::DELETE_ROW:
1734 unlockInsetInInset(bv, the_locking_inset);
1735 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1736 tabular->DeleteRow(sel_row_start);
1738 if (sel_row_start >= tabular->rows())
1740 actcell = tabular->GetCellNumber(sel_row_start, column);
1742 updateLocal(bv, INIT, true);
1744 case LyXTabular::DELETE_COLUMN:
1745 unlockInsetInInset(bv, the_locking_inset);
1746 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1747 tabular->DeleteColumn(sel_col_start);
1749 if (sel_col_start >= tabular->columns())
1751 actcell = tabular->GetCellNumber(row, sel_col_start);
1753 updateLocal(bv, INIT, true);
1755 case LyXTabular::M_TOGGLE_LINE_TOP:
1757 case LyXTabular::TOGGLE_LINE_TOP:
1759 bool lineSet = !tabular->TopLine(actcell, flag);
1760 for (int i = sel_row_start; i <= sel_row_end; ++i)
1761 for (int j = sel_col_start; j <= sel_col_end; ++j)
1762 tabular->SetTopLine(
1763 tabular->GetCellNumber(i, j),
1765 updateLocal(bv, INIT, true);
1769 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1771 case LyXTabular::TOGGLE_LINE_BOTTOM:
1773 bool lineSet = !tabular->BottomLine(actcell, flag);
1774 for (int i = sel_row_start; i <= sel_row_end; ++i)
1775 for (int j = sel_col_start; j <= sel_col_end; ++j)
1776 tabular->SetBottomLine(
1777 tabular->GetCellNumber(i, j),
1780 updateLocal(bv, INIT, true);
1784 case LyXTabular::M_TOGGLE_LINE_LEFT:
1786 case LyXTabular::TOGGLE_LINE_LEFT:
1788 bool lineSet = !tabular->LeftLine(actcell, flag);
1789 for (int i = sel_row_start; i <= sel_row_end; ++i)
1790 for (int j = sel_col_start; j <= sel_col_end; ++j)
1791 tabular->SetLeftLine(
1792 tabular->GetCellNumber(i,j),
1795 updateLocal(bv, INIT, true);
1799 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1801 case LyXTabular::TOGGLE_LINE_RIGHT:
1803 bool lineSet = !tabular->RightLine(actcell, flag);
1804 for (int i = sel_row_start; i <= sel_row_end; ++i)
1805 for (int j = sel_col_start; j <= sel_col_end; ++j)
1806 tabular->SetRightLine(
1807 tabular->GetCellNumber(i,j),
1810 updateLocal(bv, INIT, true);
1814 case LyXTabular::M_ALIGN_LEFT:
1815 case LyXTabular::M_ALIGN_RIGHT:
1816 case LyXTabular::M_ALIGN_CENTER:
1818 case LyXTabular::ALIGN_LEFT:
1819 case LyXTabular::ALIGN_RIGHT:
1820 case LyXTabular::ALIGN_CENTER:
1821 for (int i = sel_row_start; i <= sel_row_end; ++i)
1822 for (int j = sel_col_start; j <= sel_col_end; ++j)
1823 tabular->SetAlignment(
1824 tabular->GetCellNumber(i, j),
1827 updateLocal(bv, INIT, true);
1829 case LyXTabular::M_VALIGN_TOP:
1830 case LyXTabular::M_VALIGN_BOTTOM:
1831 case LyXTabular::M_VALIGN_CENTER:
1833 case LyXTabular::VALIGN_TOP:
1834 case LyXTabular::VALIGN_BOTTOM:
1835 case LyXTabular::VALIGN_CENTER:
1836 for (int i = sel_row_start; i <= sel_row_end; ++i)
1837 for (int j = sel_col_start; j <= sel_col_end; ++j)
1838 tabular->SetVAlignment(
1839 tabular->GetCellNumber(i, j),
1841 updateLocal(bv, INIT, true);
1843 case LyXTabular::MULTICOLUMN:
1845 if (sel_row_start != sel_row_end) {
1846 Alert::alert(_("Impossible Operation!"),
1847 _("Multicolumns can only be horizontally."),
1851 // just multicol for one Single Cell
1852 if (!hasSelection()) {
1853 // check wether we are completly in a multicol
1854 if (tabular->IsMultiColumn(actcell)) {
1855 tabular->UnsetMultiColumn(actcell);
1856 updateLocal(bv, INIT, true);
1858 tabular->SetMultiColumn(actcell, 1);
1859 updateLocal(bv, CELL, true);
1863 // we have a selection so this means we just add all this
1864 // cells to form a multicolumn cell
1868 if (sel_cell_start > sel_cell_end) {
1869 s_start = sel_cell_end;
1870 s_end = sel_cell_start;
1872 s_start = sel_cell_start;
1873 s_end = sel_cell_end;
1875 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1877 sel_cell_end = sel_cell_start;
1878 updateLocal(bv, INIT, true);
1881 case LyXTabular::SET_ALL_LINES:
1883 case LyXTabular::UNSET_ALL_LINES:
1884 for (int i = sel_row_start; i <= sel_row_end; ++i)
1885 for (int j = sel_col_start; j <= sel_col_end; ++j)
1886 tabular->SetAllLines(
1887 tabular->GetCellNumber(i,j), setLines);
1888 updateLocal(bv, INIT, true);
1890 case LyXTabular::SET_LONGTABULAR:
1891 tabular->SetLongTabular(true);
1892 updateLocal(bv, INIT, true); // because this toggles displayed
1894 case LyXTabular::UNSET_LONGTABULAR:
1895 tabular->SetLongTabular(false);
1896 updateLocal(bv, INIT, true); // because this toggles displayed
1898 case LyXTabular::SET_ROTATE_TABULAR:
1899 tabular->SetRotateTabular(true);
1901 case LyXTabular::UNSET_ROTATE_TABULAR:
1902 tabular->SetRotateTabular(false);
1904 case LyXTabular::SET_ROTATE_CELL:
1905 for (int i = sel_row_start; i <= sel_row_end; ++i)
1906 for (int j = sel_col_start; j<=sel_col_end; ++j)
1907 tabular->SetRotateCell(
1908 tabular->GetCellNumber(i, j),
1911 case LyXTabular::UNSET_ROTATE_CELL:
1912 for (int i = sel_row_start; i <= sel_row_end; ++i)
1913 for (int j = sel_col_start; j <= sel_col_end; ++j)
1914 tabular->SetRotateCell(
1915 tabular->GetCellNumber(i, j), false);
1917 case LyXTabular::SET_USEBOX:
1919 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1920 if (val == tabular->GetUsebox(actcell))
1921 val = LyXTabular::BOX_NONE;
1922 for (int i = sel_row_start; i <= sel_row_end; ++i)
1923 for (int j = sel_col_start; j <= sel_col_end; ++j)
1925 tabular->GetCellNumber(i, j), val);
1928 case LyXTabular::UNSET_LTFIRSTHEAD:
1930 case LyXTabular::SET_LTFIRSTHEAD:
1931 tabular->SetLTHead(ltt, true);
1933 case LyXTabular::UNSET_LTHEAD:
1935 case LyXTabular::SET_LTHEAD:
1936 tabular->SetLTHead(ltt, false);
1938 case LyXTabular::UNSET_LTFOOT:
1940 case LyXTabular::SET_LTFOOT:
1941 tabular->SetLTFoot(ltt, false);
1943 case LyXTabular::UNSET_LTLASTFOOT:
1945 case LyXTabular::SET_LTLASTFOOT:
1946 tabular->SetLTFoot(ltt, true);
1948 case LyXTabular::SET_LTNEWPAGE:
1950 bool what = !tabular->GetLTNewPage(actcell);
1951 tabular->SetLTNewPage(actcell, what);
1954 // dummy stuff just to avoid warnings
1955 case LyXTabular::LAST_ACTION:
1961 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1964 UpdatableInset * inset =
1965 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1966 LyXFont font(LyXFont::ALL_SANE);
1968 x = inset->x() + inset->width(bv, font);
1969 y = inset->descent(bv, font);
1971 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1972 //inset_y = cursor.y();
1973 inset->edit(bv, x, y, button);
1974 if (!the_locking_inset)
1976 updateLocal(bv, CELL, false);
1977 return (the_locking_inset != 0);
1981 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1984 inset_x = cursor_.x()
1985 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1986 inset_y = cursor_.y();
1987 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1991 bool InsetTabular::insetHit(BufferView *, int x, int) const
1994 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
1998 // This returns paperWidth() if the cell-width is unlimited or the width
1999 // in pixels if we have a pwidth for this cell.
2000 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2002 string const s = tabular->GetPWidth(cell);
2006 return VSpace(s).inPixels(bv);
2010 int InsetTabular::getMaxWidth(BufferView * bv,
2011 UpdatableInset const * inset) const
2013 int cell = tabular->cur_cell;
2014 if (tabular->GetCellInset(cell) != inset) {
2016 if (tabular->GetCellInset(cell) != inset) {
2018 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2023 int const n = tabular->GetNumberOfCells();
2026 for (cell = 0; cell < n; ++cell) {
2027 if (tabular->GetCellInset(cell) == inset)
2033 lyxerr << "Own inset not found, shouldn't really happen!\n";
2037 int w = getMaxWidthOfCell(bv, cell);
2039 // because the inset then subtracts it's top_x and owner->x()
2040 w += (inset->x() - top_x);
2047 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2049 resizeLyXText(bv, recursive);
2053 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2056 for(int i = 0; i < tabular->rows(); ++i) {
2057 for(int j = 0; j < tabular->columns(); ++j) {
2058 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2066 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2067 bool const recursive) const
2069 if (the_locking_inset)
2070 return the_locking_inset->getLyXText(bv, recursive);
2072 // if we're locked lock the actual insettext and return it's LyXText!!!
2074 UpdatableInset * inset =
2075 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2076 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2077 return the_locking_inset->getLyXText(bv, recursive);
2080 return Inset::getLyXText(bv, recursive);
2084 bool InsetTabular::showInsetDialog(BufferView * bv) const
2086 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2087 bv->owner()->getDialogs()
2088 ->showTabular(const_cast<InsetTabular *>(this));
2093 void InsetTabular::openLayoutDialog(BufferView * bv) const
2095 if (the_locking_inset) {
2096 InsetTabular * i = static_cast<InsetTabular *>
2097 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2099 i->openLayoutDialog(bv);
2103 bv->owner()->getDialogs()->showTabular(
2104 const_cast<InsetTabular *>(this));
2109 // functions returns:
2113 // 3 ... toggled off
2115 func_status::value_type InsetTabular::getStatus(string const & what) const
2117 int action = LyXTabular::LAST_ACTION;
2118 func_status::value_type status = func_status::OK;
2121 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2122 string const tmp = tabularFeature[i].feature;
2123 if (tmp == what.substr(0, tmp.length())) {
2124 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2125 // tabularFeatures[i].feature.length())) {
2126 action = tabularFeature[i].action;
2130 if (action == LyXTabular::LAST_ACTION)
2131 return func_status::Unknown;
2133 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2138 LyXTabular::ltType dummyltt;
2141 if (hasSelection()) {
2142 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2144 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2148 case LyXTabular::SET_PWIDTH:
2149 case LyXTabular::SET_MPWIDTH:
2150 case LyXTabular::SET_SPECIAL_COLUMN:
2151 case LyXTabular::SET_SPECIAL_MULTI:
2152 status |= func_status::Disabled;
2155 case LyXTabular::APPEND_ROW:
2156 case LyXTabular::APPEND_COLUMN:
2157 case LyXTabular::DELETE_ROW:
2158 case LyXTabular::DELETE_COLUMN:
2159 case LyXTabular::SET_ALL_LINES:
2160 case LyXTabular::UNSET_ALL_LINES:
2161 status |= func_status::OK;
2164 case LyXTabular::MULTICOLUMN:
2165 if (tabular->IsMultiColumn(actcell))
2166 status |= func_status::ToggleOn;
2168 status |= func_status::ToggleOff;
2170 case LyXTabular::M_TOGGLE_LINE_TOP:
2172 case LyXTabular::TOGGLE_LINE_TOP:
2173 if (tabular->TopLine(actcell, flag))
2174 status |= func_status::ToggleOn;
2176 status |= func_status::ToggleOff;
2178 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2180 case LyXTabular::TOGGLE_LINE_BOTTOM:
2181 if (tabular->BottomLine(actcell, flag))
2182 status |= func_status::ToggleOn;
2184 status |= func_status::ToggleOff;
2186 case LyXTabular::M_TOGGLE_LINE_LEFT:
2188 case LyXTabular::TOGGLE_LINE_LEFT:
2189 if (tabular->LeftLine(actcell, flag))
2190 status |= func_status::ToggleOn;
2192 status |= func_status::ToggleOff;
2194 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2196 case LyXTabular::TOGGLE_LINE_RIGHT:
2197 if (tabular->RightLine(actcell, flag))
2198 status |= func_status::ToggleOn;
2200 status |= func_status::ToggleOff;
2202 case LyXTabular::M_ALIGN_LEFT:
2204 case LyXTabular::ALIGN_LEFT:
2205 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2206 status |= func_status::ToggleOn;
2208 status |= func_status::ToggleOff;
2210 case LyXTabular::M_ALIGN_RIGHT:
2212 case LyXTabular::ALIGN_RIGHT:
2213 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2214 status |= func_status::ToggleOn;
2216 status |= func_status::ToggleOff;
2218 case LyXTabular::M_ALIGN_CENTER:
2220 case LyXTabular::ALIGN_CENTER:
2221 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2222 status |= func_status::ToggleOn;
2224 status |= func_status::ToggleOff;
2226 case LyXTabular::M_VALIGN_TOP:
2228 case LyXTabular::VALIGN_TOP:
2229 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2230 status |= func_status::ToggleOn;
2232 status |= func_status::ToggleOff;
2234 case LyXTabular::M_VALIGN_BOTTOM:
2236 case LyXTabular::VALIGN_BOTTOM:
2237 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2238 status |= func_status::ToggleOn;
2240 status |= func_status::ToggleOff;
2242 case LyXTabular::M_VALIGN_CENTER:
2244 case LyXTabular::VALIGN_CENTER:
2245 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2246 status |= func_status::ToggleOn;
2248 status |= func_status::ToggleOff;
2250 case LyXTabular::SET_LONGTABULAR:
2251 if (tabular->IsLongTabular())
2252 status |= func_status::ToggleOn;
2254 status |= func_status::ToggleOff;
2256 case LyXTabular::UNSET_LONGTABULAR:
2257 if (!tabular->IsLongTabular())
2258 status |= func_status::ToggleOn;
2260 status |= func_status::ToggleOff;
2262 case LyXTabular::SET_ROTATE_TABULAR:
2263 if (tabular->GetRotateTabular())
2264 status |= func_status::ToggleOn;
2266 status |= func_status::ToggleOff;
2268 case LyXTabular::UNSET_ROTATE_TABULAR:
2269 if (!tabular->GetRotateTabular())
2270 status |= func_status::ToggleOn;
2272 status |= func_status::ToggleOff;
2274 case LyXTabular::SET_ROTATE_CELL:
2275 if (tabular->GetRotateCell(actcell))
2276 status |= func_status::ToggleOn;
2278 status |= func_status::ToggleOff;
2280 case LyXTabular::UNSET_ROTATE_CELL:
2281 if (!tabular->GetRotateCell(actcell))
2282 status |= func_status::ToggleOn;
2284 status |= func_status::ToggleOff;
2286 case LyXTabular::SET_USEBOX:
2287 if (strToInt(argument) == tabular->GetUsebox(actcell))
2288 status |= func_status::ToggleOn;
2290 status |= func_status::ToggleOff;
2292 case LyXTabular::SET_LTFIRSTHEAD:
2293 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2294 status |= func_status::ToggleOn;
2296 status |= func_status::ToggleOff;
2298 case LyXTabular::SET_LTHEAD:
2299 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2300 status |= func_status::ToggleOn;
2302 status |= func_status::ToggleOff;
2304 case LyXTabular::SET_LTFOOT:
2305 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2306 status |= func_status::ToggleOn;
2308 status |= func_status::ToggleOff;
2310 case LyXTabular::SET_LTLASTFOOT:
2311 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2312 status |= func_status::ToggleOn;
2314 status |= func_status::ToggleOff;
2316 case LyXTabular::SET_LTNEWPAGE:
2317 if (tabular->GetLTNewPage(actcell))
2318 status |= func_status::ToggleOn;
2320 status |= func_status::ToggleOff;
2323 status = func_status::Disabled;
2330 std::vector<string> const InsetTabular::getLabelList() const
2332 return tabular->getLabelList();
2336 bool InsetTabular::copySelection(BufferView * bv)
2338 if (!hasSelection())
2341 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2342 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2343 if (sel_col_start > sel_col_end) {
2344 sel_col_start = sel_col_end;
2345 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2347 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2349 int const columns = sel_col_end - sel_col_start + 1;
2351 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2352 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2353 if (sel_row_start > sel_row_end) {
2354 swap(sel_row_start, sel_row_end);
2356 int const rows = sel_row_end - sel_row_start + 1;
2358 delete paste_tabular;
2359 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2360 for (int i = 0; i < sel_row_start; ++i)
2361 paste_tabular->DeleteRow(0);
2362 while (paste_tabular->rows() > rows)
2363 paste_tabular->DeleteRow(rows);
2364 paste_tabular->SetTopLine(0, true, true);
2365 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2367 for (int i = 0; i < sel_col_start; ++i)
2368 paste_tabular->DeleteColumn(0);
2369 while (paste_tabular->columns() > columns)
2370 paste_tabular->DeleteColumn(columns);
2371 paste_tabular->SetLeftLine(0, true, true);
2372 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2376 paste_tabular->Ascii(bv->buffer(), sstr);
2377 bv->stuffClipboard(sstr.str().c_str());
2382 bool InsetTabular::pasteSelection(BufferView * bv)
2387 for (int r1 = 0, r2 = actrow;
2388 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2390 for(int c1 = 0, c2 = actcol;
2391 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2393 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2394 tabular->IsPartOfMultiColumn(r2,c2))
2396 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2400 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2404 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2405 int const n2 = tabular->GetCellNumber(r2, c2);
2406 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2407 tabular->GetCellInset(n2)->setOwner(this);
2408 tabular->GetCellInset(n2)->deleteLyXText(bv);
2415 bool InsetTabular::cutSelection()
2417 if (!hasSelection())
2420 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2421 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2422 if (sel_col_start > sel_col_end) {
2423 sel_col_start = sel_col_end;
2424 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2426 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2428 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2429 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2430 if (sel_row_start > sel_row_end) {
2431 swap(sel_row_start, sel_row_end);
2433 if (sel_cell_start > sel_cell_end) {
2434 swap(sel_cell_start, sel_cell_end);
2436 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2437 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2438 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2445 bool InsetTabular::isRightToLeft(BufferView *bv )
2447 return bv->getParentLanguage(this)->RightToLeft();
2451 bool InsetTabular::nodraw() const
2453 if (!UpdatableInset::nodraw() && the_locking_inset)
2454 return the_locking_inset->nodraw();
2455 return UpdatableInset::nodraw();
2459 int InsetTabular::scroll(bool recursive) const
2461 int sx = UpdatableInset::scroll(false);
2463 if (recursive && the_locking_inset)
2464 sx += the_locking_inset->scroll(recursive);
2470 bool InsetTabular::doClearArea() const
2472 return !locked || (need_update & (FULL|INIT));
2476 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2478 srow = tabular->row_of_cell(sel_cell_start);
2479 erow = tabular->row_of_cell(sel_cell_end);
2483 scol = tabular->column_of_cell(sel_cell_start);
2484 ecol = tabular->column_of_cell(sel_cell_end);
2488 ecol = tabular->right_column_of_cell(sel_cell_end);
2492 Paragraph * InsetTabular::getParFromID(int id) const
2495 for(int i = 0; i < tabular->rows(); ++i) {
2496 for(int j = 0; j < tabular->columns(); ++j) {
2497 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2505 Paragraph * InsetTabular::firstParagraph() const
2507 if (the_locking_inset)
2508 return the_locking_inset->firstParagraph();
2513 Paragraph * InsetTabular::getFirstParagraph(int i) const
2515 return (i < tabular->GetNumberOfCells())
2516 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2521 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2523 if (the_locking_inset)
2524 return the_locking_inset->cursor(bv);
2525 return Inset::cursor(bv);
2529 Inset * InsetTabular::getInsetFromID(int id_arg) const
2532 return const_cast<InsetTabular *>(this);
2535 for(int i=0; i < tabular->rows(); ++i) {
2536 for(int j=0; j < tabular->columns(); ++j) {
2537 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2545 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2547 if (the_locking_inset) {
2548 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2551 if (tabular->IsLastCell(actcell)) {
2552 bv->unlockInset(const_cast<InsetTabular *>(this));
2558 // otherwise we have to lock the next inset and ask for it's selecttion
2559 UpdatableInset * inset =
2560 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2561 inset->edit(bv, 0, 0, 0);
2562 string const str(selectNextWordInt(bv, value));
2570 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2572 // when entering this function the inset should be ALWAYS locked!
2573 lyx::Assert(the_locking_inset);
2575 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2579 if (tabular->IsLastCell(actcell)) {
2580 bv->unlockInset(const_cast<InsetTabular *>(this));
2584 // otherwise we have to lock the next inset and ask for it's selecttion
2585 UpdatableInset * inset =
2586 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2588 return selectNextWordInt(bv, value);
2592 void InsetTabular::selectSelectedWord(BufferView * bv)
2594 if (the_locking_inset) {
2595 the_locking_inset->selectSelectedWord(bv);
2602 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2604 if (the_locking_inset) {
2605 the_locking_inset->toggleSelection(bv, kill_selection);
2610 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2611 bool const & cs, bool const & mw)
2613 if (the_locking_inset) {
2614 if (the_locking_inset->searchForward(bv, str, cs, mw))
2616 if (tabular->IsLastCell(actcell)) {
2617 bv->unlockInset(const_cast<InsetTabular *>(this));
2622 // otherwise we have to lock the next inset and search there
2623 UpdatableInset * inset =
2624 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2627 bool const res = searchForward(bv, str, cs, mw);
2628 updateLocal(bv, NONE, false);
2629 bv->updateInset(const_cast<InsetTabular *>(this), false);
2632 return searchForward(bv, str, cs, mw);
2637 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2638 bool const & cs, bool const & mw)
2640 if (the_locking_inset) {
2641 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2643 if (!actcell) { // we are already in the first cell
2644 bv->unlockInset(const_cast<InsetTabular *>(this));
2649 // otherwise we have to lock the next inset and search there
2650 UpdatableInset * inset =
2651 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2652 inset->edit(bv, false);
2654 bool const res = searchBackward(bv, str, cs, mw);
2655 bv->updateInset(const_cast<InsetTabular *>(this), false);
2658 return searchBackward(bv, str, cs, mw);
2663 bool InsetTabular::insetAllowed(Inset::Code code) const
2665 if (the_locking_inset)
2666 return the_locking_inset->insetAllowed(code);