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).zero())
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 LyXLength const vallen = LyXLength(value);
1692 bool const update = (tabular->GetColumnPWidth(actcell) != vallen);
1693 tabular->SetColumnPWidth(actcell,vallen);
1695 for (int i = 0; i < tabular->rows(); ++i) {
1696 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1699 updateLocal(bv, INIT, true);
1703 case LyXTabular::SET_MPWIDTH:
1705 LyXLength const vallen = LyXLength(value);
1706 bool const update = (tabular->GetPWidth(actcell) != vallen);
1707 tabular->SetMColumnPWidth(actcell,vallen);
1709 for (int i = 0; i < tabular->rows(); ++i) {
1710 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1713 updateLocal(bv, INIT, true);
1717 case LyXTabular::SET_SPECIAL_COLUMN:
1718 case LyXTabular::SET_SPECIAL_MULTI:
1719 tabular->SetAlignSpecial(actcell,value,feature);
1720 updateLocal(bv, FULL, true);
1722 case LyXTabular::APPEND_ROW:
1723 // append the row into the tabular
1724 unlockInsetInInset(bv, the_locking_inset);
1725 tabular->AppendRow(actcell);
1726 updateLocal(bv, INIT, true);
1728 case LyXTabular::APPEND_COLUMN:
1729 // append the column into the tabular
1730 unlockInsetInInset(bv, the_locking_inset);
1731 tabular->AppendColumn(actcell);
1732 actcell = tabular->GetCellNumber(row, column);
1733 updateLocal(bv, INIT, true);
1735 case LyXTabular::DELETE_ROW:
1736 unlockInsetInInset(bv, the_locking_inset);
1737 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1738 tabular->DeleteRow(sel_row_start);
1740 if (sel_row_start >= tabular->rows())
1742 actcell = tabular->GetCellNumber(sel_row_start, column);
1744 updateLocal(bv, INIT, true);
1746 case LyXTabular::DELETE_COLUMN:
1747 unlockInsetInInset(bv, the_locking_inset);
1748 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1749 tabular->DeleteColumn(sel_col_start);
1751 if (sel_col_start >= tabular->columns())
1753 actcell = tabular->GetCellNumber(row, sel_col_start);
1755 updateLocal(bv, INIT, true);
1757 case LyXTabular::M_TOGGLE_LINE_TOP:
1759 case LyXTabular::TOGGLE_LINE_TOP:
1761 bool lineSet = !tabular->TopLine(actcell, flag);
1762 for (int i = sel_row_start; i <= sel_row_end; ++i)
1763 for (int j = sel_col_start; j <= sel_col_end; ++j)
1764 tabular->SetTopLine(
1765 tabular->GetCellNumber(i, j),
1767 updateLocal(bv, INIT, true);
1771 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1773 case LyXTabular::TOGGLE_LINE_BOTTOM:
1775 bool lineSet = !tabular->BottomLine(actcell, flag);
1776 for (int i = sel_row_start; i <= sel_row_end; ++i)
1777 for (int j = sel_col_start; j <= sel_col_end; ++j)
1778 tabular->SetBottomLine(
1779 tabular->GetCellNumber(i, j),
1782 updateLocal(bv, INIT, true);
1786 case LyXTabular::M_TOGGLE_LINE_LEFT:
1788 case LyXTabular::TOGGLE_LINE_LEFT:
1790 bool lineSet = !tabular->LeftLine(actcell, flag);
1791 for (int i = sel_row_start; i <= sel_row_end; ++i)
1792 for (int j = sel_col_start; j <= sel_col_end; ++j)
1793 tabular->SetLeftLine(
1794 tabular->GetCellNumber(i,j),
1797 updateLocal(bv, INIT, true);
1801 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1803 case LyXTabular::TOGGLE_LINE_RIGHT:
1805 bool lineSet = !tabular->RightLine(actcell, flag);
1806 for (int i = sel_row_start; i <= sel_row_end; ++i)
1807 for (int j = sel_col_start; j <= sel_col_end; ++j)
1808 tabular->SetRightLine(
1809 tabular->GetCellNumber(i,j),
1812 updateLocal(bv, INIT, true);
1816 case LyXTabular::M_ALIGN_LEFT:
1817 case LyXTabular::M_ALIGN_RIGHT:
1818 case LyXTabular::M_ALIGN_CENTER:
1820 case LyXTabular::ALIGN_LEFT:
1821 case LyXTabular::ALIGN_RIGHT:
1822 case LyXTabular::ALIGN_CENTER:
1823 for (int i = sel_row_start; i <= sel_row_end; ++i)
1824 for (int j = sel_col_start; j <= sel_col_end; ++j)
1825 tabular->SetAlignment(
1826 tabular->GetCellNumber(i, j),
1829 updateLocal(bv, INIT, true);
1831 case LyXTabular::M_VALIGN_TOP:
1832 case LyXTabular::M_VALIGN_BOTTOM:
1833 case LyXTabular::M_VALIGN_CENTER:
1835 case LyXTabular::VALIGN_TOP:
1836 case LyXTabular::VALIGN_BOTTOM:
1837 case LyXTabular::VALIGN_CENTER:
1838 for (int i = sel_row_start; i <= sel_row_end; ++i)
1839 for (int j = sel_col_start; j <= sel_col_end; ++j)
1840 tabular->SetVAlignment(
1841 tabular->GetCellNumber(i, j),
1843 updateLocal(bv, INIT, true);
1845 case LyXTabular::MULTICOLUMN:
1847 if (sel_row_start != sel_row_end) {
1848 Alert::alert(_("Impossible Operation!"),
1849 _("Multicolumns can only be horizontally."),
1853 // just multicol for one Single Cell
1854 if (!hasSelection()) {
1855 // check wether we are completly in a multicol
1856 if (tabular->IsMultiColumn(actcell)) {
1857 tabular->UnsetMultiColumn(actcell);
1858 updateLocal(bv, INIT, true);
1860 tabular->SetMultiColumn(actcell, 1);
1861 updateLocal(bv, CELL, true);
1865 // we have a selection so this means we just add all this
1866 // cells to form a multicolumn cell
1870 if (sel_cell_start > sel_cell_end) {
1871 s_start = sel_cell_end;
1872 s_end = sel_cell_start;
1874 s_start = sel_cell_start;
1875 s_end = sel_cell_end;
1877 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1879 sel_cell_end = sel_cell_start;
1880 updateLocal(bv, INIT, true);
1883 case LyXTabular::SET_ALL_LINES:
1885 case LyXTabular::UNSET_ALL_LINES:
1886 for (int i = sel_row_start; i <= sel_row_end; ++i)
1887 for (int j = sel_col_start; j <= sel_col_end; ++j)
1888 tabular->SetAllLines(
1889 tabular->GetCellNumber(i,j), setLines);
1890 updateLocal(bv, INIT, true);
1892 case LyXTabular::SET_LONGTABULAR:
1893 tabular->SetLongTabular(true);
1894 updateLocal(bv, INIT, true); // because this toggles displayed
1896 case LyXTabular::UNSET_LONGTABULAR:
1897 tabular->SetLongTabular(false);
1898 updateLocal(bv, INIT, true); // because this toggles displayed
1900 case LyXTabular::SET_ROTATE_TABULAR:
1901 tabular->SetRotateTabular(true);
1903 case LyXTabular::UNSET_ROTATE_TABULAR:
1904 tabular->SetRotateTabular(false);
1906 case LyXTabular::SET_ROTATE_CELL:
1907 for (int i = sel_row_start; i <= sel_row_end; ++i)
1908 for (int j = sel_col_start; j<=sel_col_end; ++j)
1909 tabular->SetRotateCell(
1910 tabular->GetCellNumber(i, j),
1913 case LyXTabular::UNSET_ROTATE_CELL:
1914 for (int i = sel_row_start; i <= sel_row_end; ++i)
1915 for (int j = sel_col_start; j <= sel_col_end; ++j)
1916 tabular->SetRotateCell(
1917 tabular->GetCellNumber(i, j), false);
1919 case LyXTabular::SET_USEBOX:
1921 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1922 if (val == tabular->GetUsebox(actcell))
1923 val = LyXTabular::BOX_NONE;
1924 for (int i = sel_row_start; i <= sel_row_end; ++i)
1925 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular->GetCellNumber(i, j), val);
1930 case LyXTabular::UNSET_LTFIRSTHEAD:
1932 case LyXTabular::SET_LTFIRSTHEAD:
1933 tabular->SetLTHead(ltt, true);
1935 case LyXTabular::UNSET_LTHEAD:
1937 case LyXTabular::SET_LTHEAD:
1938 tabular->SetLTHead(ltt, false);
1940 case LyXTabular::UNSET_LTFOOT:
1942 case LyXTabular::SET_LTFOOT:
1943 tabular->SetLTFoot(ltt, false);
1945 case LyXTabular::UNSET_LTLASTFOOT:
1947 case LyXTabular::SET_LTLASTFOOT:
1948 tabular->SetLTFoot(ltt, true);
1950 case LyXTabular::SET_LTNEWPAGE:
1952 bool what = !tabular->GetLTNewPage(actcell);
1953 tabular->SetLTNewPage(actcell, what);
1956 // dummy stuff just to avoid warnings
1957 case LyXTabular::LAST_ACTION:
1963 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1966 UpdatableInset * inset =
1967 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1968 LyXFont font(LyXFont::ALL_SANE);
1970 x = inset->x() + inset->width(bv, font);
1971 y = inset->descent(bv, font);
1973 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1974 //inset_y = cursor.y();
1975 inset->edit(bv, x, y, button);
1976 if (!the_locking_inset)
1978 updateLocal(bv, CELL, false);
1979 return (the_locking_inset != 0);
1983 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1986 inset_x = cursor_.x()
1987 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1988 inset_y = cursor_.y();
1989 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1993 bool InsetTabular::insetHit(BufferView *, int x, int) const
1996 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2000 // This returns paperWidth() if the cell-width is unlimited or the width
2001 // in pixels if we have a pwidth for this cell.
2002 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2004 LyXLength const len = tabular->GetPWidth(cell);
2008 #ifdef WITH_WARNINGS
2009 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2011 return VSpace(len).inPixels(bv);
2015 int InsetTabular::getMaxWidth(BufferView * bv,
2016 UpdatableInset const * inset) const
2018 int cell = tabular->cur_cell;
2019 if (tabular->GetCellInset(cell) != inset) {
2021 if (tabular->GetCellInset(cell) != inset) {
2023 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2028 int const n = tabular->GetNumberOfCells();
2031 for (cell = 0; cell < n; ++cell) {
2032 if (tabular->GetCellInset(cell) == inset)
2038 lyxerr << "Own inset not found, shouldn't really happen!\n";
2042 int w = getMaxWidthOfCell(bv, cell);
2044 // because the inset then subtracts it's top_x and owner->x()
2045 w += (inset->x() - top_x);
2052 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2054 resizeLyXText(bv, recursive);
2058 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2061 for(int i = 0; i < tabular->rows(); ++i) {
2062 for(int j = 0; j < tabular->columns(); ++j) {
2063 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2071 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2072 bool const recursive) const
2074 if (the_locking_inset)
2075 return the_locking_inset->getLyXText(bv, recursive);
2077 // if we're locked lock the actual insettext and return it's LyXText!!!
2079 UpdatableInset * inset =
2080 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2081 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2082 return the_locking_inset->getLyXText(bv, recursive);
2085 return Inset::getLyXText(bv, recursive);
2089 bool InsetTabular::showInsetDialog(BufferView * bv) const
2091 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2092 bv->owner()->getDialogs()
2093 ->showTabular(const_cast<InsetTabular *>(this));
2098 void InsetTabular::openLayoutDialog(BufferView * bv) const
2100 if (the_locking_inset) {
2101 InsetTabular * i = static_cast<InsetTabular *>
2102 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2104 i->openLayoutDialog(bv);
2108 bv->owner()->getDialogs()->showTabular(
2109 const_cast<InsetTabular *>(this));
2114 // functions returns:
2118 // 3 ... toggled off
2120 func_status::value_type InsetTabular::getStatus(string const & what) const
2122 int action = LyXTabular::LAST_ACTION;
2123 func_status::value_type status = func_status::OK;
2126 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2127 string const tmp = tabularFeature[i].feature;
2128 if (tmp == what.substr(0, tmp.length())) {
2129 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2130 // tabularFeatures[i].feature.length())) {
2131 action = tabularFeature[i].action;
2135 if (action == LyXTabular::LAST_ACTION)
2136 return func_status::Unknown;
2138 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2143 LyXTabular::ltType dummyltt;
2146 if (hasSelection()) {
2147 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2149 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2153 case LyXTabular::SET_PWIDTH:
2154 case LyXTabular::SET_MPWIDTH:
2155 case LyXTabular::SET_SPECIAL_COLUMN:
2156 case LyXTabular::SET_SPECIAL_MULTI:
2157 status |= func_status::Disabled;
2160 case LyXTabular::APPEND_ROW:
2161 case LyXTabular::APPEND_COLUMN:
2162 case LyXTabular::DELETE_ROW:
2163 case LyXTabular::DELETE_COLUMN:
2164 case LyXTabular::SET_ALL_LINES:
2165 case LyXTabular::UNSET_ALL_LINES:
2166 status |= func_status::OK;
2169 case LyXTabular::MULTICOLUMN:
2170 if (tabular->IsMultiColumn(actcell))
2171 status |= func_status::ToggleOn;
2173 status |= func_status::ToggleOff;
2175 case LyXTabular::M_TOGGLE_LINE_TOP:
2177 case LyXTabular::TOGGLE_LINE_TOP:
2178 if (tabular->TopLine(actcell, flag))
2179 status |= func_status::ToggleOn;
2181 status |= func_status::ToggleOff;
2183 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2185 case LyXTabular::TOGGLE_LINE_BOTTOM:
2186 if (tabular->BottomLine(actcell, flag))
2187 status |= func_status::ToggleOn;
2189 status |= func_status::ToggleOff;
2191 case LyXTabular::M_TOGGLE_LINE_LEFT:
2193 case LyXTabular::TOGGLE_LINE_LEFT:
2194 if (tabular->LeftLine(actcell, flag))
2195 status |= func_status::ToggleOn;
2197 status |= func_status::ToggleOff;
2199 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2201 case LyXTabular::TOGGLE_LINE_RIGHT:
2202 if (tabular->RightLine(actcell, flag))
2203 status |= func_status::ToggleOn;
2205 status |= func_status::ToggleOff;
2207 case LyXTabular::M_ALIGN_LEFT:
2209 case LyXTabular::ALIGN_LEFT:
2210 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2211 status |= func_status::ToggleOn;
2213 status |= func_status::ToggleOff;
2215 case LyXTabular::M_ALIGN_RIGHT:
2217 case LyXTabular::ALIGN_RIGHT:
2218 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2219 status |= func_status::ToggleOn;
2221 status |= func_status::ToggleOff;
2223 case LyXTabular::M_ALIGN_CENTER:
2225 case LyXTabular::ALIGN_CENTER:
2226 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2227 status |= func_status::ToggleOn;
2229 status |= func_status::ToggleOff;
2231 case LyXTabular::M_VALIGN_TOP:
2233 case LyXTabular::VALIGN_TOP:
2234 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2235 status |= func_status::ToggleOn;
2237 status |= func_status::ToggleOff;
2239 case LyXTabular::M_VALIGN_BOTTOM:
2241 case LyXTabular::VALIGN_BOTTOM:
2242 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2243 status |= func_status::ToggleOn;
2245 status |= func_status::ToggleOff;
2247 case LyXTabular::M_VALIGN_CENTER:
2249 case LyXTabular::VALIGN_CENTER:
2250 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2251 status |= func_status::ToggleOn;
2253 status |= func_status::ToggleOff;
2255 case LyXTabular::SET_LONGTABULAR:
2256 if (tabular->IsLongTabular())
2257 status |= func_status::ToggleOn;
2259 status |= func_status::ToggleOff;
2261 case LyXTabular::UNSET_LONGTABULAR:
2262 if (!tabular->IsLongTabular())
2263 status |= func_status::ToggleOn;
2265 status |= func_status::ToggleOff;
2267 case LyXTabular::SET_ROTATE_TABULAR:
2268 if (tabular->GetRotateTabular())
2269 status |= func_status::ToggleOn;
2271 status |= func_status::ToggleOff;
2273 case LyXTabular::UNSET_ROTATE_TABULAR:
2274 if (!tabular->GetRotateTabular())
2275 status |= func_status::ToggleOn;
2277 status |= func_status::ToggleOff;
2279 case LyXTabular::SET_ROTATE_CELL:
2280 if (tabular->GetRotateCell(actcell))
2281 status |= func_status::ToggleOn;
2283 status |= func_status::ToggleOff;
2285 case LyXTabular::UNSET_ROTATE_CELL:
2286 if (!tabular->GetRotateCell(actcell))
2287 status |= func_status::ToggleOn;
2289 status |= func_status::ToggleOff;
2291 case LyXTabular::SET_USEBOX:
2292 if (strToInt(argument) == tabular->GetUsebox(actcell))
2293 status |= func_status::ToggleOn;
2295 status |= func_status::ToggleOff;
2297 case LyXTabular::SET_LTFIRSTHEAD:
2298 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2299 status |= func_status::ToggleOn;
2301 status |= func_status::ToggleOff;
2303 case LyXTabular::SET_LTHEAD:
2304 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2305 status |= func_status::ToggleOn;
2307 status |= func_status::ToggleOff;
2309 case LyXTabular::SET_LTFOOT:
2310 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2311 status |= func_status::ToggleOn;
2313 status |= func_status::ToggleOff;
2315 case LyXTabular::SET_LTLASTFOOT:
2316 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2317 status |= func_status::ToggleOn;
2319 status |= func_status::ToggleOff;
2321 case LyXTabular::SET_LTNEWPAGE:
2322 if (tabular->GetLTNewPage(actcell))
2323 status |= func_status::ToggleOn;
2325 status |= func_status::ToggleOff;
2328 status = func_status::Disabled;
2335 std::vector<string> const InsetTabular::getLabelList() const
2337 return tabular->getLabelList();
2341 bool InsetTabular::copySelection(BufferView * bv)
2343 if (!hasSelection())
2346 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2347 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2348 if (sel_col_start > sel_col_end) {
2349 sel_col_start = sel_col_end;
2350 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2352 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2354 int const columns = sel_col_end - sel_col_start + 1;
2356 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2357 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2358 if (sel_row_start > sel_row_end) {
2359 swap(sel_row_start, sel_row_end);
2361 int const rows = sel_row_end - sel_row_start + 1;
2363 delete paste_tabular;
2364 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2365 for (int i = 0; i < sel_row_start; ++i)
2366 paste_tabular->DeleteRow(0);
2367 while (paste_tabular->rows() > rows)
2368 paste_tabular->DeleteRow(rows);
2369 paste_tabular->SetTopLine(0, true, true);
2370 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2372 for (int i = 0; i < sel_col_start; ++i)
2373 paste_tabular->DeleteColumn(0);
2374 while (paste_tabular->columns() > columns)
2375 paste_tabular->DeleteColumn(columns);
2376 paste_tabular->SetLeftLine(0, true, true);
2377 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2381 paste_tabular->Ascii(bv->buffer(), sstr);
2382 bv->stuffClipboard(sstr.str().c_str());
2387 bool InsetTabular::pasteSelection(BufferView * bv)
2392 for (int r1 = 0, r2 = actrow;
2393 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2395 for(int c1 = 0, c2 = actcol;
2396 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2398 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2399 tabular->IsPartOfMultiColumn(r2,c2))
2401 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2405 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2409 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2410 int const n2 = tabular->GetCellNumber(r2, c2);
2411 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2412 tabular->GetCellInset(n2)->setOwner(this);
2413 tabular->GetCellInset(n2)->deleteLyXText(bv);
2420 bool InsetTabular::cutSelection()
2422 if (!hasSelection())
2425 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2426 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2427 if (sel_col_start > sel_col_end) {
2428 sel_col_start = sel_col_end;
2429 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2431 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2433 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2434 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2435 if (sel_row_start > sel_row_end) {
2436 swap(sel_row_start, sel_row_end);
2438 if (sel_cell_start > sel_cell_end) {
2439 swap(sel_cell_start, sel_cell_end);
2441 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2442 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2443 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2450 bool InsetTabular::isRightToLeft(BufferView *bv )
2452 return bv->getParentLanguage(this)->RightToLeft();
2456 bool InsetTabular::nodraw() const
2458 if (!UpdatableInset::nodraw() && the_locking_inset)
2459 return the_locking_inset->nodraw();
2460 return UpdatableInset::nodraw();
2464 int InsetTabular::scroll(bool recursive) const
2466 int sx = UpdatableInset::scroll(false);
2468 if (recursive && the_locking_inset)
2469 sx += the_locking_inset->scroll(recursive);
2475 bool InsetTabular::doClearArea() const
2477 return !locked || (need_update & (FULL|INIT));
2481 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2483 srow = tabular->row_of_cell(sel_cell_start);
2484 erow = tabular->row_of_cell(sel_cell_end);
2488 scol = tabular->column_of_cell(sel_cell_start);
2489 ecol = tabular->column_of_cell(sel_cell_end);
2493 ecol = tabular->right_column_of_cell(sel_cell_end);
2497 Paragraph * InsetTabular::getParFromID(int id) const
2500 for(int i = 0; i < tabular->rows(); ++i) {
2501 for(int j = 0; j < tabular->columns(); ++j) {
2502 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2510 Paragraph * InsetTabular::firstParagraph() const
2512 if (the_locking_inset)
2513 return the_locking_inset->firstParagraph();
2518 Paragraph * InsetTabular::getFirstParagraph(int i) const
2520 return (i < tabular->GetNumberOfCells())
2521 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2526 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2528 if (the_locking_inset)
2529 return the_locking_inset->cursor(bv);
2530 return Inset::cursor(bv);
2534 Inset * InsetTabular::getInsetFromID(int id_arg) const
2537 return const_cast<InsetTabular *>(this);
2540 for(int i=0; i < tabular->rows(); ++i) {
2541 for(int j=0; j < tabular->columns(); ++j) {
2542 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2550 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2552 if (the_locking_inset) {
2553 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2556 if (tabular->IsLastCell(actcell)) {
2557 bv->unlockInset(const_cast<InsetTabular *>(this));
2563 // otherwise we have to lock the next inset and ask for it's selecttion
2564 UpdatableInset * inset =
2565 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2566 inset->edit(bv, 0, 0, 0);
2567 string const str(selectNextWordInt(bv, value));
2575 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2577 // when entering this function the inset should be ALWAYS locked!
2578 lyx::Assert(the_locking_inset);
2580 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2584 if (tabular->IsLastCell(actcell)) {
2585 bv->unlockInset(const_cast<InsetTabular *>(this));
2589 // otherwise we have to lock the next inset and ask for it's selecttion
2590 UpdatableInset * inset =
2591 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2593 return selectNextWordInt(bv, value);
2597 void InsetTabular::selectSelectedWord(BufferView * bv)
2599 if (the_locking_inset) {
2600 the_locking_inset->selectSelectedWord(bv);
2607 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2609 if (the_locking_inset) {
2610 the_locking_inset->toggleSelection(bv, kill_selection);
2615 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2616 bool const & cs, bool const & mw)
2618 if (the_locking_inset) {
2619 if (the_locking_inset->searchForward(bv, str, cs, mw))
2621 if (tabular->IsLastCell(actcell)) {
2622 bv->unlockInset(const_cast<InsetTabular *>(this));
2627 // otherwise we have to lock the next inset and search there
2628 UpdatableInset * inset =
2629 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2632 bool const res = searchForward(bv, str, cs, mw);
2633 updateLocal(bv, NONE, false);
2634 bv->updateInset(const_cast<InsetTabular *>(this), false);
2637 return searchForward(bv, str, cs, mw);
2642 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2643 bool const & cs, bool const & mw)
2645 if (the_locking_inset) {
2646 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2648 if (!actcell) { // we are already in the first cell
2649 bv->unlockInset(const_cast<InsetTabular *>(this));
2654 // otherwise we have to lock the next inset and search there
2655 UpdatableInset * inset =
2656 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2657 inset->edit(bv, false);
2659 bool const res = searchBackward(bv, str, cs, mw);
2660 bv->updateInset(const_cast<InsetTabular *>(this), false);
2663 return searchBackward(bv, str, cs, mw);
2668 bool InsetTabular::insetAllowed(Inset::Code code) const
2670 if (the_locking_inset)
2671 return the_locking_inset->insetAllowed(code);