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 if (the_locking_inset) {
851 unlockInsetInInset(bv, the_locking_inset);
852 the_locking_inset = 0;
854 if (action == LFUN_TAB)
855 moveNextCell(bv, old_locking_inset != 0);
857 movePrevCell(bv, old_locking_inset != 0);
858 sel_cell_start = sel_cell_end = actcell;
860 updateLocal(bv, SELECTION, false);
861 if (!the_locking_inset) {
863 return DISPATCHED_NOUPDATE;
866 // this to avoid compiler warnings.
872 if (the_locking_inset) {
873 result = the_locking_inset->localDispatch(bv, action, arg);
874 if (result == DISPATCHED_NOUPDATE) {
877 if (sc != scroll()) { // inset has been scrolled
878 the_locking_inset->toggleInsetCursor(bv);
879 updateLocal(bv, FULL, false);
880 the_locking_inset->toggleInsetCursor(bv);
883 } else if (result == DISPATCHED) {
884 the_locking_inset->toggleInsetCursor(bv);
885 updateLocal(bv, CELL, false);
886 the_locking_inset->toggleInsetCursor(bv);
888 } else if (result == FINISHED_UP) {
890 } else if (result == FINISHED_DOWN) {
892 } else if (result == FINISHED_RIGHT) {
900 // --- Cursor Movements ----------------------------------
902 if (tabular->IsLastCellInRow(actcell))
904 moveRight(bv, false);
905 sel_cell_end = actcell;
906 updateLocal(bv, SELECTION, false);
909 result = moveRight(bv);
910 sel_cell_start = sel_cell_end = actcell;
912 updateLocal(bv, SELECTION, false);
915 if (tabular->IsFirstCellInRow(actcell))
918 sel_cell_end = actcell;
919 updateLocal(bv, SELECTION, false);
922 result = moveLeft(bv);
923 sel_cell_start = sel_cell_end = actcell;
925 updateLocal(bv, SELECTION, false);
929 int const ocell = actcell;
931 if ((ocell == sel_cell_end) ||
932 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
933 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
935 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
936 updateLocal(bv, SELECTION, false);
940 result = moveDown(bv, old_locking_inset != 0);
941 sel_cell_start = sel_cell_end = actcell;
943 updateLocal(bv, SELECTION, false);
947 int const ocell = actcell;
949 if ((ocell == sel_cell_end) ||
950 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
951 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
953 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
954 updateLocal(bv, SELECTION, false);
958 result = moveUp(bv, old_locking_inset != 0);
959 sel_cell_start = sel_cell_end = actcell;
961 updateLocal(bv, SELECTION, false);
965 if (the_locking_inset) {
966 unlockInsetInInset(bv, the_locking_inset);
967 the_locking_inset = 0;
969 if (bv->text->first + bv->painter().paperHeight() <
970 (top_baseline + tabular->GetHeightOfTabular()))
972 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
973 updateLocal(bv, FULL, false);
974 actcell = tabular->GetCellBelow(first_visible_cell) + column;
976 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
979 updateLocal(bv, CURSOR, false);
984 if (the_locking_inset) {
985 unlockInsetInInset(bv, the_locking_inset);
986 the_locking_inset = 0;
988 if (top_baseline < 0) {
989 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
990 updateLocal(bv, FULL, false);
991 if (top_baseline > 0)
994 actcell = tabular->GetCellBelow(first_visible_cell) + column;
999 updateLocal(bv, CURSOR, false);
1002 // none of these make sense for insettabular,
1003 // but we must catch them to prevent any
1004 // selection from being confused
1008 case LFUN_WORDLEFTSEL:
1009 case LFUN_WORDRIGHT:
1010 case LFUN_WORDRIGHTSEL:
1011 case LFUN_DOWN_PARAGRAPH:
1012 case LFUN_DOWN_PARAGRAPHSEL:
1013 case LFUN_UP_PARAGRAPH:
1014 case LFUN_UP_PARAGRAPHSEL:
1015 case LFUN_BACKSPACE:
1022 case LFUN_LAYOUT_TABULAR:
1024 bv->owner()->getDialogs()->showTabular(this);
1027 case LFUN_TABULAR_FEATURE:
1028 if (!tabularFeatures(bv, arg))
1029 result = UNDISPATCHED;
1032 if (!copySelection(bv))
1034 setUndo(bv, Undo::DELETE,
1035 bv->text->cursor.par(),
1036 bv->text->cursor.par()->next());
1038 updateLocal(bv, INIT, true);
1041 if (!hasSelection())
1046 case LFUN_PASTESELECTION:
1048 string const clip(bv->getClipboard());
1052 if (clip.find('\t') != string::npos) {
1056 string::size_type len = clip.length();
1057 string::size_type p = 0;
1060 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1068 maxCols = max(cols, maxCols);
1074 maxCols = max(cols, maxCols);
1075 delete paste_tabular;
1076 paste_tabular = new LyXTabular(this, rows, maxCols);
1077 string::size_type op = 0;
1079 int cells = paste_tabular->GetNumberOfCells();
1081 while((cell < cells) && (p < len) &&
1082 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1087 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1092 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1093 while(cols++ < maxCols)
1101 // check for the last cell if there is no trailing '\n'
1102 if ((cell < cells) && (op < len))
1103 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1105 // so that the clipboard is used and it goes on
1107 // and executes LFUN_PASTESELECTION in insettext!
1108 delete paste_tabular;
1113 if (hasPasteBuffer()) {
1114 setUndo(bv, Undo::INSERT,
1115 bv->text->cursor.par(),
1116 bv->text->cursor.par()->next());
1118 updateLocal(bv, INIT, true);
1121 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1123 // we try to activate the actual inset and put this event down to
1124 // the insets dispatch function.
1125 result = UNDISPATCHED;
1126 if (the_locking_inset)
1129 if (activateCellInset(bv)) {
1130 // reset need_update setted in above function!
1132 result = the_locking_inset->localDispatch(bv, action, arg);
1133 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1134 unlockInsetInInset(bv, the_locking_inset);
1136 the_locking_inset = 0;
1137 // we need to update if this was requested before
1138 updateLocal(bv, NONE, false);
1139 return UNDISPATCHED;
1144 updateLocal(bv, CELL, false);
1149 if (result < FINISHED) {
1150 if (!the_locking_inset) {
1151 showInsetCursor(bv);
1154 bv->unlockInset(this);
1159 int InsetTabular::latex(Buffer const * buf, ostream & os,
1160 bool fragile, bool fp) const
1162 return tabular->Latex(buf, os, fragile, fp);
1166 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1168 // This should be changed to a real ascii export
1169 return tabular->Ascii(buf, os);
1173 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1175 return tabular->Ascii(buf,os);
1179 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1184 // if the table is inside a float it doesn't need the informaltable
1185 // wrapper. Search for it.
1186 for(master = owner();
1187 master && master->lyxCode() != Inset::FLOAT_CODE;
1188 master = master->owner());
1191 os << "<informaltable>\n";
1194 ret+= tabular->DocBook(buf,os);
1196 os << "</informaltable>\n";
1203 void InsetTabular::validate(LaTeXFeatures & features) const
1205 tabular->Validate(features);
1209 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1210 LyXFont const & font,
1217 bool changed = false;
1219 // if we have a locking_inset we should have to check only this cell for
1220 // change so I'll try this to have a boost, but who knows ;)
1221 if ((need_update != INIT) &&
1222 (the_locking_inset == tabular->GetCellInset(actcell))) {
1223 for(int i = 0; i < tabular->columns(); ++i) {
1224 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1226 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1229 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1230 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1231 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1234 for (int i = 0; i < tabular->rows(); ++i) {
1237 for (int j = 0; j < tabular->columns(); ++j) {
1238 if (tabular->IsPartOfMultiColumn(i,j))
1241 inset = tabular->GetCellInset(cell);
1242 if (!reinit && !tabular->GetPWidth(cell).empty())
1243 inset->update(bv, font, false);
1244 maxAsc = max(maxAsc, inset->ascent(bv, font));
1245 maxDesc = max(maxDesc, inset->descent(bv, font));
1246 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1248 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1249 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1257 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1259 if (the_locking_inset) {
1260 the_locking_inset->getCursorPos(bv, x, y);
1263 x = cursor_.x() - top_x;
1268 void InsetTabular::toggleInsetCursor(BufferView * bv)
1270 if (the_locking_inset) {
1271 the_locking_inset->toggleInsetCursor(bv);
1275 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1277 int const asc = lyxfont::maxAscent(font);
1278 int const desc = lyxfont::maxDescent(font);
1280 if (isCursorVisible())
1281 bv->hideLockedInsetCursor();
1283 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1284 toggleCursorVisible();
1288 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1290 if (!isCursorVisible()) {
1291 LyXFont font; // = GetFont(par, cursor.pos);
1293 int const asc = lyxfont::maxAscent(font);
1294 int const desc = lyxfont::maxDescent(font);
1295 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1297 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1298 setCursorVisible(true);
1303 void InsetTabular::hideInsetCursor(BufferView * bv)
1305 if (isCursorVisible()) {
1306 bv->hideLockedInsetCursor();
1307 setCursorVisible(false);
1312 void InsetTabular::fitInsetCursor(BufferView * bv) const
1314 if (the_locking_inset) {
1315 the_locking_inset->fitInsetCursor(bv);
1320 int const asc = lyxfont::maxAscent(font);
1321 int const desc = lyxfont::maxDescent(font);
1322 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1326 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1330 actcell = actrow = actcol = 0;
1331 int ly = tabular->GetDescentOfRow(actrow);
1333 // first search the right row
1334 while((ly < y) && ((actrow+1) < tabular->rows())) {
1335 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1336 tabular->GetAscentOfRow(actrow + 1) +
1337 tabular->GetAdditionalHeight(actrow + 1));
1339 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1341 actcell = tabular->GetCellNumber(actrow, actcol);
1343 // now search the right column
1344 int lx = tabular->GetWidthOfColumn(actcell) -
1345 tabular->GetAdditionalWidth(actcell);
1346 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1347 lx += tabular->GetWidthOfColumn(actcell + 1)
1348 + tabular->GetAdditionalWidth(actcell);
1350 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1355 int InsetTabular::getCellXPos(int cell) const
1359 for (; !tabular->IsFirstCellInRow(c); --c)
1361 int lx = tabular->GetWidthOfColumn(cell);
1362 for (; c < cell; ++c) {
1363 lx += tabular->GetWidthOfColumn(c);
1365 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1369 void InsetTabular::resetPos(BufferView * bv) const
1371 if (!locked || nodraw())
1373 #warning This should be fixed in the right manner (20011128 Jug)
1374 // fast hack to fix infinite repaintings!
1377 in_reset_pos = true;
1379 actcol = tabular->column_of_cell(actcell);
1384 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1385 if (tabular->IsLastCellInRow(cell)) {
1386 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1387 tabular->GetAscentOfRow(actrow + 1) +
1388 tabular->GetAdditionalHeight(actrow + 1));
1392 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1393 int new_x = getCellXPos(actcell);
1394 int old_x = cursor_.x();
1397 // cursor.x(getCellXPos(actcell) + offset);
1398 if ((actcol < tabular->columns()-1) && scroll(false) &&
1399 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1402 updateLocal(bv, FULL, false);
1403 } else if (the_locking_inset &&
1404 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1406 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1407 if (xx > (bv->workWidth()-20)) {
1408 scroll(bv, -(xx - bv->workWidth() + 60));
1409 updateLocal(bv, FULL, false);
1410 } else if (xx < 20) {
1416 updateLocal(bv, FULL, false);
1418 } else if ((cursor_.x() - offset) > 20 &&
1419 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1420 > (bv->workWidth() - 20)) {
1421 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1422 updateLocal(bv, FULL, false);
1423 } else if ((cursor_.x() - offset) < 20) {
1424 scroll(bv, 20 - cursor_.x() + offset);
1425 updateLocal(bv, FULL, false);
1426 } else if (scroll(false) && top_x > 20 &&
1427 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1428 scroll(bv, old_x - cursor_.x());
1429 updateLocal(bv, FULL, false);
1431 if (the_locking_inset) {
1432 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1433 inset_y = cursor_.y();
1435 if ((!the_locking_inset ||
1436 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1437 actcell != oldcell) {
1438 InsetTabular * inset = const_cast<InsetTabular *>(this);
1439 bv->owner()->getDialogs()->updateTabular(inset);
1442 in_reset_pos = false;
1446 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1448 if (lock && !old_locking_inset) {
1449 if (activateCellInset(bv))
1452 bool moved = isRightToLeft(bv)
1453 ? movePrevCell(bv) : moveNextCell(bv);
1455 return FINISHED_RIGHT;
1456 if (lock && activateCellInset(bv))
1460 return DISPATCHED_NOUPDATE;
1464 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1466 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1469 if (lock) { // behind the inset
1470 if (activateCellInset(bv, 0, 0, 0, true))
1474 return DISPATCHED_NOUPDATE;
1478 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1480 int const ocell = actcell;
1481 actcell = tabular->GetCellAbove(actcell);
1482 if (actcell == ocell) // we moved out of the inset
1488 if (old_locking_inset) {
1489 old_locking_inset->getCursorPos(bv, x, y);
1490 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1492 if (activateCellInset(bv, x, 0))
1495 return DISPATCHED_NOUPDATE;
1499 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1501 int const ocell = actcell;
1502 actcell = tabular->GetCellBelow(actcell);
1503 if (actcell == ocell) // we moved out of the inset
1504 return FINISHED_DOWN;
1509 if (old_locking_inset) {
1510 old_locking_inset->getCursorPos(bv, x, y);
1511 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1513 if (activateCellInset(bv, x, 0))
1516 return DISPATCHED_NOUPDATE;
1520 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1522 if (isRightToLeft(bv)) {
1523 if (tabular->IsFirstCellInRow(actcell)) {
1524 int row = tabular->row_of_cell(actcell);
1525 if (row == tabular->rows() - 1)
1527 actcell = tabular->GetLastCellInRow(row);
1528 actcell = tabular->GetCellBelow(actcell);
1535 if (tabular->IsLastCell(actcell))
1540 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1541 isRightToLeftPar(bv->buffer()->params);
1542 activateCellInset(bv, 0, 0, 0, !rtl);
1549 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1551 if (isRightToLeft(bv)) {
1552 if (tabular->IsLastCellInRow(actcell)) {
1553 int row = tabular->row_of_cell(actcell);
1556 actcell = tabular->GetFirstCellInRow(row);
1557 actcell = tabular->GetCellAbove(actcell);
1559 if (tabular->IsLastCell(actcell))
1564 if (!actcell) // first cell
1569 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1570 isRightToLeftPar(bv->buffer()->params);
1571 activateCellInset(bv, 0, 0, 0, !rtl);
1578 bool InsetTabular::deletable() const
1584 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1589 sel_cell_end = tabular->GetNumberOfCells() - 1;
1591 if (hasSelection()) {
1592 setUndo(bv, Undo::EDIT,
1593 bv->text->cursor.par(),
1594 bv->text->cursor.par()->next());
1595 bool frozen = undo_frozen;
1598 // apply the fontchange on the whole selection
1603 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1604 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1605 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1606 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1611 updateLocal(bv, INIT, true);
1613 if (the_locking_inset)
1614 the_locking_inset->setFont(bv, font, tall);
1618 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1620 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1623 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1624 string const tmp = tabularFeature[i].feature;
1626 if (tmp == what.substr(0, tmp.length())) {
1627 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1628 //tabularFeatures[i].feature.length())) {
1629 action = tabularFeature[i].action;
1633 if (action == LyXTabular::LAST_ACTION)
1637 frontStrip(what.substr(tabularFeature[i].feature.length()));
1638 tabularFeatures(bv, action, val);
1643 void InsetTabular::tabularFeatures(BufferView * bv,
1644 LyXTabular::Feature feature,
1645 string const & value)
1651 bool setLines = false;
1652 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1653 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1656 case LyXTabular::M_ALIGN_LEFT:
1657 case LyXTabular::ALIGN_LEFT:
1658 setAlign=LYX_ALIGN_LEFT;
1660 case LyXTabular::M_ALIGN_RIGHT:
1661 case LyXTabular::ALIGN_RIGHT:
1662 setAlign=LYX_ALIGN_RIGHT;
1664 case LyXTabular::M_ALIGN_CENTER:
1665 case LyXTabular::ALIGN_CENTER:
1666 setAlign=LYX_ALIGN_CENTER;
1668 case LyXTabular::M_VALIGN_TOP:
1669 case LyXTabular::VALIGN_TOP:
1670 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1672 case LyXTabular::M_VALIGN_BOTTOM:
1673 case LyXTabular::VALIGN_BOTTOM:
1674 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1676 case LyXTabular::M_VALIGN_CENTER:
1677 case LyXTabular::VALIGN_CENTER:
1678 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1683 if (hasSelection()) {
1684 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1686 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1687 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1689 setUndo(bv, Undo::FINISH,
1690 bv->text->cursor.par(),
1691 bv->text->cursor.par()->next());
1693 LyXTabular::ltType ltt;
1694 int row = ltt.row = tabular->row_of_cell(actcell);
1695 int column = tabular->column_of_cell(actcell);
1699 case LyXTabular::SET_PWIDTH:
1701 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1702 tabular->SetColumnPWidth(actcell,value);
1704 for (int i = 0; i < tabular->rows(); ++i) {
1705 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1708 updateLocal(bv, INIT, true);
1712 case LyXTabular::SET_MPWIDTH:
1714 bool const update = (tabular->GetPWidth(actcell) != value);
1715 tabular->SetMColumnPWidth(actcell,value);
1717 for (int i = 0; i < tabular->rows(); ++i) {
1718 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1721 updateLocal(bv, INIT, true);
1725 case LyXTabular::SET_SPECIAL_COLUMN:
1726 case LyXTabular::SET_SPECIAL_MULTI:
1727 tabular->SetAlignSpecial(actcell,value,feature);
1728 updateLocal(bv, FULL, true);
1730 case LyXTabular::APPEND_ROW:
1731 // append the row into the tabular
1732 unlockInsetInInset(bv, the_locking_inset);
1733 tabular->AppendRow(actcell);
1734 updateLocal(bv, INIT, true);
1736 case LyXTabular::APPEND_COLUMN:
1737 // append the column into the tabular
1738 unlockInsetInInset(bv, the_locking_inset);
1739 tabular->AppendColumn(actcell);
1740 actcell = tabular->GetCellNumber(row, column);
1741 updateLocal(bv, INIT, true);
1743 case LyXTabular::DELETE_ROW:
1744 unlockInsetInInset(bv, the_locking_inset);
1745 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1746 tabular->DeleteRow(sel_row_start);
1748 if (sel_row_start >= tabular->rows())
1750 actcell = tabular->GetCellNumber(sel_row_start, column);
1752 updateLocal(bv, INIT, true);
1754 case LyXTabular::DELETE_COLUMN:
1755 unlockInsetInInset(bv, the_locking_inset);
1756 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1757 tabular->DeleteColumn(sel_col_start);
1759 if (sel_col_start >= tabular->columns())
1761 actcell = tabular->GetCellNumber(row, sel_col_start);
1763 updateLocal(bv, INIT, true);
1765 case LyXTabular::M_TOGGLE_LINE_TOP:
1767 case LyXTabular::TOGGLE_LINE_TOP:
1769 bool lineSet = !tabular->TopLine(actcell, flag);
1770 for (int i = sel_row_start; i <= sel_row_end; ++i)
1771 for (int j = sel_col_start; j <= sel_col_end; ++j)
1772 tabular->SetTopLine(
1773 tabular->GetCellNumber(i, j),
1775 updateLocal(bv, INIT, true);
1779 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1781 case LyXTabular::TOGGLE_LINE_BOTTOM:
1783 bool lineSet = !tabular->BottomLine(actcell, flag);
1784 for (int i = sel_row_start; i <= sel_row_end; ++i)
1785 for (int j = sel_col_start; j <= sel_col_end; ++j)
1786 tabular->SetBottomLine(
1787 tabular->GetCellNumber(i, j),
1790 updateLocal(bv, INIT, true);
1794 case LyXTabular::M_TOGGLE_LINE_LEFT:
1796 case LyXTabular::TOGGLE_LINE_LEFT:
1798 bool lineSet = !tabular->LeftLine(actcell, flag);
1799 for (int i = sel_row_start; i <= sel_row_end; ++i)
1800 for (int j = sel_col_start; j <= sel_col_end; ++j)
1801 tabular->SetLeftLine(
1802 tabular->GetCellNumber(i,j),
1805 updateLocal(bv, INIT, true);
1809 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1811 case LyXTabular::TOGGLE_LINE_RIGHT:
1813 bool lineSet = !tabular->RightLine(actcell, flag);
1814 for (int i = sel_row_start; i <= sel_row_end; ++i)
1815 for (int j = sel_col_start; j <= sel_col_end; ++j)
1816 tabular->SetRightLine(
1817 tabular->GetCellNumber(i,j),
1820 updateLocal(bv, INIT, true);
1824 case LyXTabular::M_ALIGN_LEFT:
1825 case LyXTabular::M_ALIGN_RIGHT:
1826 case LyXTabular::M_ALIGN_CENTER:
1828 case LyXTabular::ALIGN_LEFT:
1829 case LyXTabular::ALIGN_RIGHT:
1830 case LyXTabular::ALIGN_CENTER:
1831 for (int i = sel_row_start; i <= sel_row_end; ++i)
1832 for (int j = sel_col_start; j <= sel_col_end; ++j)
1833 tabular->SetAlignment(
1834 tabular->GetCellNumber(i, j),
1837 updateLocal(bv, INIT, true);
1839 case LyXTabular::M_VALIGN_TOP:
1840 case LyXTabular::M_VALIGN_BOTTOM:
1841 case LyXTabular::M_VALIGN_CENTER:
1843 case LyXTabular::VALIGN_TOP:
1844 case LyXTabular::VALIGN_BOTTOM:
1845 case LyXTabular::VALIGN_CENTER:
1846 for (int i = sel_row_start; i <= sel_row_end; ++i)
1847 for (int j = sel_col_start; j <= sel_col_end; ++j)
1848 tabular->SetVAlignment(
1849 tabular->GetCellNumber(i, j),
1851 updateLocal(bv, INIT, true);
1853 case LyXTabular::MULTICOLUMN:
1855 if (sel_row_start != sel_row_end) {
1856 Alert::alert(_("Impossible Operation!"),
1857 _("Multicolumns can only be horizontally."),
1861 // just multicol for one Single Cell
1862 if (!hasSelection()) {
1863 // check wether we are completly in a multicol
1864 if (tabular->IsMultiColumn(actcell)) {
1865 tabular->UnsetMultiColumn(actcell);
1866 updateLocal(bv, INIT, true);
1868 tabular->SetMultiColumn(actcell, 1);
1869 updateLocal(bv, CELL, true);
1873 // we have a selection so this means we just add all this
1874 // cells to form a multicolumn cell
1878 if (sel_cell_start > sel_cell_end) {
1879 s_start = sel_cell_end;
1880 s_end = sel_cell_start;
1882 s_start = sel_cell_start;
1883 s_end = sel_cell_end;
1885 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1887 sel_cell_end = sel_cell_start;
1888 updateLocal(bv, INIT, true);
1891 case LyXTabular::SET_ALL_LINES:
1893 case LyXTabular::UNSET_ALL_LINES:
1894 for (int i = sel_row_start; i <= sel_row_end; ++i)
1895 for (int j = sel_col_start; j <= sel_col_end; ++j)
1896 tabular->SetAllLines(
1897 tabular->GetCellNumber(i,j), setLines);
1898 updateLocal(bv, INIT, true);
1900 case LyXTabular::SET_LONGTABULAR:
1901 tabular->SetLongTabular(true);
1902 updateLocal(bv, INIT, true); // because this toggles displayed
1904 case LyXTabular::UNSET_LONGTABULAR:
1905 tabular->SetLongTabular(false);
1906 updateLocal(bv, INIT, true); // because this toggles displayed
1908 case LyXTabular::SET_ROTATE_TABULAR:
1909 tabular->SetRotateTabular(true);
1911 case LyXTabular::UNSET_ROTATE_TABULAR:
1912 tabular->SetRotateTabular(false);
1914 case LyXTabular::SET_ROTATE_CELL:
1915 for (int i = sel_row_start; i <= sel_row_end; ++i)
1916 for (int j = sel_col_start; j<=sel_col_end; ++j)
1917 tabular->SetRotateCell(
1918 tabular->GetCellNumber(i, j),
1921 case LyXTabular::UNSET_ROTATE_CELL:
1922 for (int i = sel_row_start; i <= sel_row_end; ++i)
1923 for (int j = sel_col_start; j <= sel_col_end; ++j)
1924 tabular->SetRotateCell(
1925 tabular->GetCellNumber(i, j), false);
1927 case LyXTabular::SET_USEBOX:
1929 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1930 if (val == tabular->GetUsebox(actcell))
1931 val = LyXTabular::BOX_NONE;
1932 for (int i = sel_row_start; i <= sel_row_end; ++i)
1933 for (int j = sel_col_start; j <= sel_col_end; ++j)
1935 tabular->GetCellNumber(i, j), val);
1938 case LyXTabular::UNSET_LTFIRSTHEAD:
1940 case LyXTabular::SET_LTFIRSTHEAD:
1941 tabular->SetLTHead(ltt, true);
1943 case LyXTabular::UNSET_LTHEAD:
1945 case LyXTabular::SET_LTHEAD:
1946 tabular->SetLTHead(ltt, false);
1948 case LyXTabular::UNSET_LTFOOT:
1950 case LyXTabular::SET_LTFOOT:
1951 tabular->SetLTFoot(ltt, false);
1953 case LyXTabular::UNSET_LTLASTFOOT:
1955 case LyXTabular::SET_LTLASTFOOT:
1956 tabular->SetLTFoot(ltt, true);
1958 case LyXTabular::SET_LTNEWPAGE:
1960 bool what = !tabular->GetLTNewPage(actcell);
1961 tabular->SetLTNewPage(actcell, what);
1964 // dummy stuff just to avoid warnings
1965 case LyXTabular::LAST_ACTION:
1971 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1974 UpdatableInset * inset =
1975 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1976 LyXFont font(LyXFont::ALL_SANE);
1978 x = inset->x() + inset->width(bv, font);
1979 y = inset->descent(bv, font);
1981 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1982 //inset_y = cursor.y();
1983 inset->edit(bv, x, y, button);
1984 if (!the_locking_inset)
1986 updateLocal(bv, CELL, false);
1987 return (the_locking_inset != 0);
1991 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1994 inset_x = cursor_.x()
1995 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1996 inset_y = cursor_.y();
1997 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2001 bool InsetTabular::insetHit(BufferView *, int x, int) const
2004 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2008 // This returns paperWidth() if the cell-width is unlimited or the width
2009 // in pixels if we have a pwidth for this cell.
2010 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2012 string const s = tabular->GetPWidth(cell);
2016 return VSpace(s).inPixels(bv);
2020 int InsetTabular::getMaxWidth(BufferView * bv,
2021 UpdatableInset const * inset) const
2023 int cell = tabular->cur_cell;
2024 if (tabular->GetCellInset(cell) != inset) {
2026 if (tabular->GetCellInset(cell) != inset) {
2028 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2033 int const n = tabular->GetNumberOfCells();
2036 for (cell = 0; cell < n; ++cell) {
2037 if (tabular->GetCellInset(cell) == inset)
2043 lyxerr << "Own inset not found, shouldn't really happen!\n";
2047 int w = getMaxWidthOfCell(bv, cell);
2049 // because the inset then subtracts it's top_x and owner->x()
2050 w += (inset->x() - top_x);
2057 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2059 resizeLyXText(bv, recursive);
2063 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2066 for(int i = 0; i < tabular->rows(); ++i) {
2067 for(int j = 0; j < tabular->columns(); ++j) {
2068 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2076 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2077 bool const recursive) const
2079 if (the_locking_inset)
2080 return the_locking_inset->getLyXText(bv, recursive);
2082 // if we're locked lock the actual insettext and return it's LyXText!!!
2084 UpdatableInset * inset =
2085 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2086 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2087 return the_locking_inset->getLyXText(bv, recursive);
2090 return Inset::getLyXText(bv, recursive);
2094 bool InsetTabular::showInsetDialog(BufferView * bv) const
2096 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2097 bv->owner()->getDialogs()
2098 ->showTabular(const_cast<InsetTabular *>(this));
2103 void InsetTabular::openLayoutDialog(BufferView * bv) const
2105 if (the_locking_inset) {
2106 InsetTabular * i = static_cast<InsetTabular *>
2107 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2109 i->openLayoutDialog(bv);
2113 bv->owner()->getDialogs()->showTabular(
2114 const_cast<InsetTabular *>(this));
2119 // functions returns:
2123 // 3 ... toggled off
2125 func_status::value_type InsetTabular::getStatus(string const & what) const
2127 int action = LyXTabular::LAST_ACTION;
2128 func_status::value_type status = func_status::OK;
2131 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2132 string const tmp = tabularFeature[i].feature;
2133 if (tmp == what.substr(0, tmp.length())) {
2134 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2135 // tabularFeatures[i].feature.length())) {
2136 action = tabularFeature[i].action;
2140 if (action == LyXTabular::LAST_ACTION)
2141 return func_status::Unknown;
2143 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2148 LyXTabular::ltType dummyltt;
2151 if (hasSelection()) {
2152 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2154 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2158 case LyXTabular::SET_PWIDTH:
2159 case LyXTabular::SET_MPWIDTH:
2160 case LyXTabular::SET_SPECIAL_COLUMN:
2161 case LyXTabular::SET_SPECIAL_MULTI:
2162 status |= func_status::Disabled;
2165 case LyXTabular::APPEND_ROW:
2166 case LyXTabular::APPEND_COLUMN:
2167 case LyXTabular::DELETE_ROW:
2168 case LyXTabular::DELETE_COLUMN:
2169 case LyXTabular::SET_ALL_LINES:
2170 case LyXTabular::UNSET_ALL_LINES:
2171 status |= func_status::OK;
2174 case LyXTabular::MULTICOLUMN:
2175 if (tabular->IsMultiColumn(actcell))
2176 status |= func_status::ToggleOn;
2178 status |= func_status::ToggleOff;
2180 case LyXTabular::M_TOGGLE_LINE_TOP:
2182 case LyXTabular::TOGGLE_LINE_TOP:
2183 if (tabular->TopLine(actcell, flag))
2184 status |= func_status::ToggleOn;
2186 status |= func_status::ToggleOff;
2188 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2190 case LyXTabular::TOGGLE_LINE_BOTTOM:
2191 if (tabular->BottomLine(actcell, flag))
2192 status |= func_status::ToggleOn;
2194 status |= func_status::ToggleOff;
2196 case LyXTabular::M_TOGGLE_LINE_LEFT:
2198 case LyXTabular::TOGGLE_LINE_LEFT:
2199 if (tabular->LeftLine(actcell, flag))
2200 status |= func_status::ToggleOn;
2202 status |= func_status::ToggleOff;
2204 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2206 case LyXTabular::TOGGLE_LINE_RIGHT:
2207 if (tabular->RightLine(actcell, flag))
2208 status |= func_status::ToggleOn;
2210 status |= func_status::ToggleOff;
2212 case LyXTabular::M_ALIGN_LEFT:
2214 case LyXTabular::ALIGN_LEFT:
2215 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2216 status |= func_status::ToggleOn;
2218 status |= func_status::ToggleOff;
2220 case LyXTabular::M_ALIGN_RIGHT:
2222 case LyXTabular::ALIGN_RIGHT:
2223 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2224 status |= func_status::ToggleOn;
2226 status |= func_status::ToggleOff;
2228 case LyXTabular::M_ALIGN_CENTER:
2230 case LyXTabular::ALIGN_CENTER:
2231 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2232 status |= func_status::ToggleOn;
2234 status |= func_status::ToggleOff;
2236 case LyXTabular::M_VALIGN_TOP:
2238 case LyXTabular::VALIGN_TOP:
2239 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2240 status |= func_status::ToggleOn;
2242 status |= func_status::ToggleOff;
2244 case LyXTabular::M_VALIGN_BOTTOM:
2246 case LyXTabular::VALIGN_BOTTOM:
2247 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2248 status |= func_status::ToggleOn;
2250 status |= func_status::ToggleOff;
2252 case LyXTabular::M_VALIGN_CENTER:
2254 case LyXTabular::VALIGN_CENTER:
2255 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2256 status |= func_status::ToggleOn;
2258 status |= func_status::ToggleOff;
2260 case LyXTabular::SET_LONGTABULAR:
2261 if (tabular->IsLongTabular())
2262 status |= func_status::ToggleOn;
2264 status |= func_status::ToggleOff;
2266 case LyXTabular::UNSET_LONGTABULAR:
2267 if (!tabular->IsLongTabular())
2268 status |= func_status::ToggleOn;
2270 status |= func_status::ToggleOff;
2272 case LyXTabular::SET_ROTATE_TABULAR:
2273 if (tabular->GetRotateTabular())
2274 status |= func_status::ToggleOn;
2276 status |= func_status::ToggleOff;
2278 case LyXTabular::UNSET_ROTATE_TABULAR:
2279 if (!tabular->GetRotateTabular())
2280 status |= func_status::ToggleOn;
2282 status |= func_status::ToggleOff;
2284 case LyXTabular::SET_ROTATE_CELL:
2285 if (tabular->GetRotateCell(actcell))
2286 status |= func_status::ToggleOn;
2288 status |= func_status::ToggleOff;
2290 case LyXTabular::UNSET_ROTATE_CELL:
2291 if (!tabular->GetRotateCell(actcell))
2292 status |= func_status::ToggleOn;
2294 status |= func_status::ToggleOff;
2296 case LyXTabular::SET_USEBOX:
2297 if (strToInt(argument) == tabular->GetUsebox(actcell))
2298 status |= func_status::ToggleOn;
2300 status |= func_status::ToggleOff;
2302 case LyXTabular::SET_LTFIRSTHEAD:
2303 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2304 status |= func_status::ToggleOn;
2306 status |= func_status::ToggleOff;
2308 case LyXTabular::SET_LTHEAD:
2309 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2310 status |= func_status::ToggleOn;
2312 status |= func_status::ToggleOff;
2314 case LyXTabular::SET_LTFOOT:
2315 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2316 status |= func_status::ToggleOn;
2318 status |= func_status::ToggleOff;
2320 case LyXTabular::SET_LTLASTFOOT:
2321 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2322 status |= func_status::ToggleOn;
2324 status |= func_status::ToggleOff;
2326 case LyXTabular::SET_LTNEWPAGE:
2327 if (tabular->GetLTNewPage(actcell))
2328 status |= func_status::ToggleOn;
2330 status |= func_status::ToggleOff;
2333 status = func_status::Disabled;
2340 std::vector<string> const InsetTabular::getLabelList() const
2342 return tabular->getLabelList();
2346 bool InsetTabular::copySelection(BufferView * bv)
2348 if (!hasSelection())
2351 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2352 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2353 if (sel_col_start > sel_col_end) {
2354 sel_col_start = sel_col_end;
2355 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2357 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2359 int const columns = sel_col_end - sel_col_start + 1;
2361 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2362 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2363 if (sel_row_start > sel_row_end) {
2364 swap(sel_row_start, sel_row_end);
2366 int const rows = sel_row_end - sel_row_start + 1;
2368 delete paste_tabular;
2369 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2370 for (int i = 0; i < sel_row_start; ++i)
2371 paste_tabular->DeleteRow(0);
2372 while(paste_tabular->rows() > rows)
2373 paste_tabular->DeleteRow(rows);
2374 paste_tabular->SetTopLine(0, true, true);
2375 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2377 for (int i = 0; i < sel_col_start; ++i)
2378 paste_tabular->DeleteColumn(0);
2379 while (paste_tabular->columns() > columns)
2380 paste_tabular->DeleteColumn(columns);
2381 paste_tabular->SetLeftLine(0, true, true);
2382 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2386 paste_tabular->Ascii(bv->buffer(), sstr);
2387 bv->stuffClipboard(sstr.str().c_str());
2392 bool InsetTabular::pasteSelection(BufferView * bv)
2397 for (int r1 = 0, r2 = actrow;
2398 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2400 for(int c1 = 0, c2 = actcol;
2401 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2403 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2404 tabular->IsPartOfMultiColumn(r2,c2))
2406 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2410 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2414 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2415 int const n2 = tabular->GetCellNumber(r2, c2);
2416 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2417 tabular->GetCellInset(n2)->setOwner(this);
2418 tabular->GetCellInset(n2)->deleteLyXText(bv);
2425 bool InsetTabular::cutSelection()
2427 if (!hasSelection())
2430 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2431 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2432 if (sel_col_start > sel_col_end) {
2433 sel_col_start = sel_col_end;
2434 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2436 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2438 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2439 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2440 if (sel_row_start > sel_row_end) {
2441 swap(sel_row_start, sel_row_end);
2443 if (sel_cell_start > sel_cell_end) {
2444 swap(sel_cell_start, sel_cell_end);
2446 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2447 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2448 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2455 bool InsetTabular::isRightToLeft(BufferView *bv )
2457 return bv->getParentLanguage(this)->RightToLeft();
2461 bool InsetTabular::nodraw() const
2463 if (!UpdatableInset::nodraw() && the_locking_inset)
2464 return the_locking_inset->nodraw();
2465 return UpdatableInset::nodraw();
2469 int InsetTabular::scroll(bool recursive) const
2471 int sx = UpdatableInset::scroll(false);
2473 if (recursive && the_locking_inset)
2474 sx += the_locking_inset->scroll(recursive);
2480 bool InsetTabular::doClearArea() const
2482 return !locked || (need_update & (FULL|INIT));
2486 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2488 srow = tabular->row_of_cell(sel_cell_start);
2489 erow = tabular->row_of_cell(sel_cell_end);
2493 scol = tabular->column_of_cell(sel_cell_start);
2494 ecol = tabular->column_of_cell(sel_cell_end);
2498 ecol = tabular->right_column_of_cell(sel_cell_end);
2502 Paragraph * InsetTabular::getParFromID(int id) const
2505 for(int i = 0; i < tabular->rows(); ++i) {
2506 for(int j = 0; j < tabular->columns(); ++j) {
2507 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2515 Paragraph * InsetTabular::firstParagraph() const
2517 if (the_locking_inset)
2518 return the_locking_inset->firstParagraph();
2523 Paragraph * InsetTabular::getFirstParagraph(int i) const
2525 return (i < tabular->GetNumberOfCells())
2526 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2531 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2533 if (the_locking_inset)
2534 return the_locking_inset->cursor(bv);
2535 return Inset::cursor(bv);
2539 Inset * InsetTabular::getInsetFromID(int id_arg) const
2542 return const_cast<InsetTabular *>(this);
2545 for(int i=0; i < tabular->rows(); ++i) {
2546 for(int j=0; j < tabular->columns(); ++j) {
2547 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2555 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2557 if (the_locking_inset) {
2558 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2561 if (tabular->IsLastCell(actcell)) {
2562 bv->unlockInset(const_cast<InsetTabular *>(this));
2568 // otherwise we have to lock the next inset and ask for it's selecttion
2569 UpdatableInset * inset =
2570 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2571 inset->edit(bv, 0, 0, 0);
2572 string const str(selectNextWordInt(bv, value));
2580 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2582 // when entering this function the inset should be ALWAYS locked!
2583 lyx::Assert(the_locking_inset);
2585 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2589 if (tabular->IsLastCell(actcell)) {
2590 bv->unlockInset(const_cast<InsetTabular *>(this));
2594 // otherwise we have to lock the next inset and ask for it's selecttion
2595 UpdatableInset * inset =
2596 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2598 return selectNextWordInt(bv, value);
2602 void InsetTabular::selectSelectedWord(BufferView * bv)
2604 if (the_locking_inset) {
2605 the_locking_inset->selectSelectedWord(bv);
2612 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2614 if (the_locking_inset) {
2615 the_locking_inset->toggleSelection(bv, kill_selection);
2620 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2621 bool const & cs, bool const & mw)
2623 if (the_locking_inset) {
2624 if (the_locking_inset->searchForward(bv, str, cs, mw))
2626 if (tabular->IsLastCell(actcell)) {
2627 bv->unlockInset(const_cast<InsetTabular *>(this));
2632 // otherwise we have to lock the next inset and search there
2633 UpdatableInset * inset =
2634 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2637 bool const res = searchForward(bv, str, cs, mw);
2638 updateLocal(bv, NONE, false);
2639 bv->updateInset(const_cast<InsetTabular *>(this), false);
2642 return searchForward(bv, str, cs, mw);
2647 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2648 bool const & cs, bool const & mw)
2650 if (the_locking_inset) {
2651 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2653 if (!actcell) { // we are already in the first cell
2654 bv->unlockInset(const_cast<InsetTabular *>(this));
2659 // otherwise we have to lock the next inset and search there
2660 UpdatableInset * inset =
2661 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2662 inset->edit(bv, false);
2664 bool const res = searchBackward(bv, str, cs, mw);
2665 bv->updateInset(const_cast<InsetTabular *>(this), false);
2668 return searchBackward(bv, str, cs, mw);
2673 bool InsetTabular::insetAllowed(Inset::Code code) const
2675 if (the_locking_inset)
2676 return the_locking_inset->insetAllowed(code);