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
590 if (need_update < what) // only set this if it has greater update
592 if ((what == INIT) && hasSelection())
595 if (need_update != NONE) {
596 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
597 if (locked) // && (what != NONE))
603 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
605 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
610 if (inset == tabular->GetCellInset(actcell)) {
611 lyxerr[Debug::INSETTEXT] << "OK" << endl;
612 the_locking_inset = tabular->GetCellInset(actcell);
615 } else if (the_locking_inset && (the_locking_inset == inset)) {
616 lyxerr[Debug::INSETTEXT] << "OK" << endl;
618 } else if (the_locking_inset) {
619 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
620 return the_locking_inset->lockInsetInInset(bv, inset);
622 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
627 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
630 if (!the_locking_inset)
632 if (the_locking_inset == inset) {
633 the_locking_inset->insetUnlock(bv);
634 the_locking_inset = 0;
636 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
642 updateLocal(bv, CELL, false);
643 showInsetCursor(bv, false);
646 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
647 if (inset->lyxCode() == TABULAR_CODE &&
648 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
649 bv->owner()->getDialogs()->updateTabular(this);
658 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
660 if (!the_locking_inset)
662 if (the_locking_inset != inset) {
663 if (!the_locking_inset->updateInsetInInset(bv, inset))
666 updateLocal(bv, CELL, false);
671 unsigned int InsetTabular::insetInInsetY()
673 if (!the_locking_inset)
676 return inset_y + the_locking_inset->insetInInsetY();
680 UpdatableInset * InsetTabular::getLockingInset() const
682 return the_locking_inset ? the_locking_inset->getLockingInset() :
683 const_cast<InsetTabular *>(this);
687 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
691 if (the_locking_inset)
692 return the_locking_inset->getFirstLockingInsetOfType(c);
697 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
699 if (the_locking_inset)
700 return the_locking_inset->insertInset(bv, inset);
705 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
707 if (hasSelection() && (button == 3))
710 if (hasSelection()) {
712 updateLocal(bv, SELECTION, false);
715 no_selection = false;
717 int const ocell = actcell;
718 int const orow = actrow;
723 updateLocal(bv, NONE, false);
724 sel_cell_start = sel_cell_end = actcell;
726 if ((ocell != actcell) && the_locking_inset) {
727 the_locking_inset->insetUnlock(bv);
728 the_locking_inset = 0;
734 bool const inset_hit = insetHit(bv, x, y);
736 if ((ocell == actcell) && the_locking_inset && inset_hit) {
738 the_locking_inset->insetButtonPress(bv,
739 x - inset_x, y - inset_y,
742 } else if (the_locking_inset) {
743 the_locking_inset->insetUnlock(bv);
745 the_locking_inset = 0;
747 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
750 if (inset_hit && bv->theLockingInset()) {
751 if (activateCellInsetAbs(bv, x, y, button))
752 the_locking_inset->insetButtonPress(bv,
762 void InsetTabular::insetButtonRelease(BufferView * bv,
763 int x, int y, int button)
766 if (the_locking_inset) {
768 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
769 i->insetButtonRelease(bv, x, y, button);
773 bv->owner()->getDialogs()->showTabular(this);
776 if (the_locking_inset) {
777 the_locking_inset->insetButtonRelease(bv,
778 x - inset_x, y - inset_y,
782 no_selection = false;
786 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
788 if (the_locking_inset) {
789 the_locking_inset->insetMotionNotify(bv,
797 int const old_cell = actcell;
800 sel_cell_end = actcell;
801 if (sel_cell_end != old_cell)
802 updateLocal(bv, SELECTION, false);
805 no_selection = false;
809 void InsetTabular::insetKeyPress(XKeyEvent * xke)
811 if (the_locking_inset) {
812 the_locking_inset->insetKeyPress(xke);
818 UpdatableInset::RESULT
819 InsetTabular::localDispatch(BufferView * bv, kb_action action,
822 // We need to save the value of the_locking_inset as the call to
823 // the_locking_inset->LocalDispatch might unlock it.
824 old_locking_inset = the_locking_inset;
825 no_selection = false;
826 UpdatableInset::RESULT result =
827 UpdatableInset::localDispatch(bv, action, arg);
828 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
833 if ((action < 0) && arg.empty())
836 bool hs = hasSelection();
839 // this one have priority over the locked InsetText, if we're not already
840 // inside another tabular then that one get's priority!
841 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
846 if (the_locking_inset) {
847 unlockInsetInInset(bv, the_locking_inset);
848 the_locking_inset = 0;
850 if (action == LFUN_TAB)
851 moveNextCell(bv, old_locking_inset != 0);
853 movePrevCell(bv, old_locking_inset != 0);
854 sel_cell_start = sel_cell_end = actcell;
856 updateLocal(bv, SELECTION, false);
857 if (!the_locking_inset) {
859 return DISPATCHED_NOUPDATE;
862 // this to avoid compiler warnings.
868 if (the_locking_inset) {
869 result = the_locking_inset->localDispatch(bv, action, arg);
870 if (result == DISPATCHED_NOUPDATE) {
873 if (sc != scroll()) { // inset has been scrolled
874 the_locking_inset->toggleInsetCursor(bv);
875 updateLocal(bv, FULL, false);
876 the_locking_inset->toggleInsetCursor(bv);
879 } else if (result == DISPATCHED) {
880 the_locking_inset->toggleInsetCursor(bv);
881 updateLocal(bv, CELL, false);
882 the_locking_inset->toggleInsetCursor(bv);
884 } else if (result == FINISHED_UP) {
886 } else if (result == FINISHED_DOWN) {
888 } else if (result == FINISHED_RIGHT) {
896 // --- Cursor Movements ----------------------------------
898 if (tabular->IsLastCellInRow(actcell))
900 moveRight(bv, false);
901 sel_cell_end = actcell;
902 updateLocal(bv, SELECTION, false);
905 result = moveRight(bv);
906 sel_cell_start = sel_cell_end = actcell;
908 updateLocal(bv, SELECTION, false);
911 if (tabular->IsFirstCellInRow(actcell))
914 sel_cell_end = actcell;
915 updateLocal(bv, SELECTION, false);
918 result = moveLeft(bv);
919 sel_cell_start = sel_cell_end = actcell;
921 updateLocal(bv, SELECTION, false);
925 int const ocell = actcell;
927 if ((ocell == sel_cell_end) ||
928 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
929 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
931 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
932 updateLocal(bv, SELECTION, false);
936 result = moveDown(bv, old_locking_inset != 0);
937 sel_cell_start = sel_cell_end = actcell;
939 updateLocal(bv, SELECTION, false);
943 int const ocell = actcell;
945 if ((ocell == sel_cell_end) ||
946 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
947 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
949 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
950 updateLocal(bv, SELECTION, false);
954 result = moveUp(bv, old_locking_inset != 0);
955 sel_cell_start = sel_cell_end = actcell;
957 updateLocal(bv, SELECTION, false);
961 if (the_locking_inset) {
962 unlockInsetInInset(bv, the_locking_inset);
963 the_locking_inset = 0;
965 if (bv->text->first + bv->painter().paperHeight() <
966 (top_baseline + tabular->GetHeightOfTabular()))
968 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
969 updateLocal(bv, FULL, false);
970 actcell = tabular->GetCellBelow(first_visible_cell) + column;
972 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
975 updateLocal(bv, CURSOR, false);
980 if (the_locking_inset) {
981 unlockInsetInInset(bv, the_locking_inset);
982 the_locking_inset = 0;
984 if (top_baseline < 0) {
985 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
986 updateLocal(bv, FULL, false);
987 if (top_baseline > 0)
990 actcell = tabular->GetCellBelow(first_visible_cell) + column;
995 updateLocal(bv, CURSOR, false);
998 // none of these make sense for insettabular,
999 // but we must catch them to prevent any
1000 // selection from being confused
1004 case LFUN_WORDLEFTSEL:
1005 case LFUN_WORDRIGHT:
1006 case LFUN_WORDRIGHTSEL:
1007 case LFUN_DOWN_PARAGRAPH:
1008 case LFUN_DOWN_PARAGRAPHSEL:
1009 case LFUN_UP_PARAGRAPH:
1010 case LFUN_UP_PARAGRAPHSEL:
1011 case LFUN_BACKSPACE:
1018 case LFUN_LAYOUT_TABULAR:
1020 bv->owner()->getDialogs()->showTabular(this);
1023 case LFUN_TABULAR_FEATURE:
1024 if (!tabularFeatures(bv, arg))
1025 result = UNDISPATCHED;
1028 if (!copySelection(bv))
1030 setUndo(bv, Undo::DELETE,
1031 bv->text->cursor.par(),
1032 bv->text->cursor.par()->next());
1034 updateLocal(bv, INIT, true);
1037 if (!hasSelection())
1042 case LFUN_PASTESELECTION:
1044 string const clip(bv->getClipboard());
1048 if (clip.find('\t') != string::npos) {
1052 string::size_type len = clip.length();
1053 string::size_type p = 0;
1056 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1064 maxCols = max(cols, maxCols);
1070 maxCols = max(cols, maxCols);
1071 delete paste_tabular;
1072 paste_tabular = new LyXTabular(this, rows, maxCols);
1073 string::size_type op = 0;
1075 int cells = paste_tabular->GetNumberOfCells();
1077 while((cell < cells) && (p < len) &&
1078 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1083 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1088 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1089 while(cols++ < maxCols)
1097 // check for the last cell if there is no trailing '\n'
1098 if ((cell < cells) && (op < len))
1099 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1101 // so that the clipboard is used and it goes on
1103 // and executes LFUN_PASTESELECTION in insettext!
1104 delete paste_tabular;
1109 if (hasPasteBuffer()) {
1110 setUndo(bv, Undo::INSERT,
1111 bv->text->cursor.par(),
1112 bv->text->cursor.par()->next());
1114 updateLocal(bv, INIT, true);
1117 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1119 // we try to activate the actual inset and put this event down to
1120 // the insets dispatch function.
1121 result = UNDISPATCHED;
1122 if (the_locking_inset)
1125 if (activateCellInset(bv)) {
1126 // reset need_update setted in above function!
1128 result = the_locking_inset->localDispatch(bv, action, arg);
1129 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1130 unlockInsetInInset(bv, the_locking_inset);
1132 the_locking_inset = 0;
1133 // we need to update if this was requested before
1134 updateLocal(bv, NONE, false);
1135 return UNDISPATCHED;
1140 updateLocal(bv, CELL, false);
1145 if (result < FINISHED) {
1146 if (!the_locking_inset) {
1147 showInsetCursor(bv);
1150 bv->unlockInset(this);
1155 int InsetTabular::latex(Buffer const * buf, ostream & os,
1156 bool fragile, bool fp) const
1158 return tabular->Latex(buf, os, fragile, fp);
1162 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1164 // This should be changed to a real ascii export
1165 return tabular->Ascii(buf, os);
1169 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1171 return tabular->Ascii(buf,os);
1175 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1180 // if the table is inside a float it doesn't need the informaltable
1181 // wrapper. Search for it.
1182 for(master = owner();
1183 master && master->lyxCode() != Inset::FLOAT_CODE;
1184 master = master->owner());
1187 os << "<informaltable>\n";
1190 ret+= tabular->DocBook(buf,os);
1192 os << "</informaltable>\n";
1199 void InsetTabular::validate(LaTeXFeatures & features) const
1201 tabular->Validate(features);
1205 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1206 LyXFont const & font,
1213 bool changed = false;
1215 // if we have a locking_inset we should have to check only this cell for
1216 // change so I'll try this to have a boost, but who knows ;)
1217 if ((need_update != INIT) &&
1218 (the_locking_inset == tabular->GetCellInset(actcell))) {
1219 for(int i = 0; i < tabular->columns(); ++i) {
1220 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1222 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1225 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1226 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1227 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1230 for (int i = 0; i < tabular->rows(); ++i) {
1233 for (int j = 0; j < tabular->columns(); ++j) {
1234 if (tabular->IsPartOfMultiColumn(i,j))
1237 inset = tabular->GetCellInset(cell);
1238 if (!reinit && !tabular->GetPWidth(cell).empty())
1239 inset->update(bv, font, false);
1240 maxAsc = max(maxAsc, inset->ascent(bv, font));
1241 maxDesc = max(maxDesc, inset->descent(bv, font));
1242 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1244 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1245 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1251 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1253 if (the_locking_inset) {
1254 the_locking_inset->getCursorPos(bv, x, y);
1257 x = cursor_.x() - top_x;
1262 void InsetTabular::toggleInsetCursor(BufferView * bv)
1264 if (the_locking_inset) {
1265 the_locking_inset->toggleInsetCursor(bv);
1269 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1271 int const asc = lyxfont::maxAscent(font);
1272 int const desc = lyxfont::maxDescent(font);
1274 if (isCursorVisible())
1275 bv->hideLockedInsetCursor();
1277 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1278 toggleCursorVisible();
1282 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1284 if (!isCursorVisible()) {
1285 LyXFont font; // = GetFont(par, cursor.pos);
1287 int const asc = lyxfont::maxAscent(font);
1288 int const desc = lyxfont::maxDescent(font);
1289 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1291 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1292 setCursorVisible(true);
1297 void InsetTabular::hideInsetCursor(BufferView * bv)
1299 if (isCursorVisible()) {
1300 bv->hideLockedInsetCursor();
1301 setCursorVisible(false);
1306 void InsetTabular::fitInsetCursor(BufferView * bv) const
1308 if (the_locking_inset) {
1309 the_locking_inset->fitInsetCursor(bv);
1314 int const asc = lyxfont::maxAscent(font);
1315 int const desc = lyxfont::maxDescent(font);
1316 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1320 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1324 actcell = actrow = actcol = 0;
1325 int ly = tabular->GetDescentOfRow(actrow);
1327 // first search the right row
1328 while((ly < y) && ((actrow+1) < tabular->rows())) {
1329 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1330 tabular->GetAscentOfRow(actrow + 1) +
1331 tabular->GetAdditionalHeight(actrow + 1));
1333 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1335 actcell = tabular->GetCellNumber(actrow, actcol);
1337 // now search the right column
1338 int lx = tabular->GetWidthOfColumn(actcell) -
1339 tabular->GetAdditionalWidth(actcell);
1340 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1341 lx += tabular->GetWidthOfColumn(actcell + 1)
1342 + tabular->GetAdditionalWidth(actcell);
1344 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1349 int InsetTabular::getCellXPos(int cell) const
1353 for (; !tabular->IsFirstCellInRow(c); --c)
1355 int lx = tabular->GetWidthOfColumn(cell);
1356 for (; c < cell; ++c) {
1357 lx += tabular->GetWidthOfColumn(c);
1359 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1363 void InsetTabular::resetPos(BufferView * bv) const
1365 if (!locked || nodraw())
1367 #warning This should be fixed in the right manner (20011128 Jug)
1368 // fast hack to fix infinite repaintings!
1371 in_reset_pos = true;
1373 actcol = tabular->column_of_cell(actcell);
1378 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1379 if (tabular->IsLastCellInRow(cell)) {
1380 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1381 tabular->GetAscentOfRow(actrow + 1) +
1382 tabular->GetAdditionalHeight(actrow + 1));
1386 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1387 int new_x = getCellXPos(actcell);
1388 int old_x = cursor_.x();
1391 // cursor.x(getCellXPos(actcell) + offset);
1392 if ((actcol < tabular->columns()-1) && scroll(false) &&
1393 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1396 updateLocal(bv, FULL, false);
1397 } else if (the_locking_inset &&
1398 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1400 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1401 if (xx > (bv->workWidth()-20)) {
1402 scroll(bv, -(xx - bv->workWidth() + 60));
1403 updateLocal(bv, FULL, false);
1404 } else if (xx < 20) {
1410 updateLocal(bv, FULL, false);
1412 } else if ((cursor_.x() - offset) > 20 &&
1413 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1414 > (bv->workWidth() - 20)) {
1415 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1416 updateLocal(bv, FULL, false);
1417 } else if ((cursor_.x() - offset) < 20) {
1418 scroll(bv, 20 - cursor_.x() + offset);
1419 updateLocal(bv, FULL, false);
1420 } else if (scroll(false) && top_x > 20 &&
1421 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1422 scroll(bv, old_x - cursor_.x());
1423 updateLocal(bv, FULL, false);
1425 if (the_locking_inset) {
1426 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1427 inset_y = cursor_.y();
1429 if ((!the_locking_inset ||
1430 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1431 actcell != oldcell) {
1432 InsetTabular * inset = const_cast<InsetTabular *>(this);
1433 bv->owner()->getDialogs()->updateTabular(inset);
1436 in_reset_pos = false;
1440 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1442 if (lock && !old_locking_inset) {
1443 if (activateCellInset(bv))
1446 bool moved = isRightToLeft(bv)
1447 ? movePrevCell(bv) : moveNextCell(bv);
1449 return FINISHED_RIGHT;
1450 if (lock && activateCellInset(bv))
1454 return DISPATCHED_NOUPDATE;
1458 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1460 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1463 if (lock) { // behind the inset
1464 if (activateCellInset(bv, 0, 0, 0, true))
1468 return DISPATCHED_NOUPDATE;
1472 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1474 int const ocell = actcell;
1475 actcell = tabular->GetCellAbove(actcell);
1476 if (actcell == ocell) // we moved out of the inset
1482 if (old_locking_inset) {
1483 old_locking_inset->getCursorPos(bv, x, y);
1484 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1486 if (activateCellInset(bv, x, 0))
1489 return DISPATCHED_NOUPDATE;
1493 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1495 int const ocell = actcell;
1496 actcell = tabular->GetCellBelow(actcell);
1497 if (actcell == ocell) // we moved out of the inset
1498 return FINISHED_DOWN;
1503 if (old_locking_inset) {
1504 old_locking_inset->getCursorPos(bv, x, y);
1505 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1507 if (activateCellInset(bv, x, 0))
1510 return DISPATCHED_NOUPDATE;
1514 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1516 if (isRightToLeft(bv)) {
1517 if (tabular->IsFirstCellInRow(actcell)) {
1518 int row = tabular->row_of_cell(actcell);
1519 if (row == tabular->rows() - 1)
1521 actcell = tabular->GetLastCellInRow(row);
1522 actcell = tabular->GetCellBelow(actcell);
1529 if (tabular->IsLastCell(actcell))
1534 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1535 isRightToLeftPar(bv->buffer()->params);
1536 activateCellInset(bv, 0, 0, 0, !rtl);
1543 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1545 if (isRightToLeft(bv)) {
1546 if (tabular->IsLastCellInRow(actcell)) {
1547 int row = tabular->row_of_cell(actcell);
1550 actcell = tabular->GetFirstCellInRow(row);
1551 actcell = tabular->GetCellAbove(actcell);
1553 if (tabular->IsLastCell(actcell))
1558 if (!actcell) // first cell
1563 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1564 isRightToLeftPar(bv->buffer()->params);
1565 activateCellInset(bv, 0, 0, 0, !rtl);
1572 bool InsetTabular::deletable() const
1578 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1583 sel_cell_end = tabular->GetNumberOfCells() - 1;
1585 if (hasSelection()) {
1586 setUndo(bv, Undo::EDIT,
1587 bv->text->cursor.par(),
1588 bv->text->cursor.par()->next());
1589 bool frozen = undo_frozen;
1592 // apply the fontchange on the whole selection
1597 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1598 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1599 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1600 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1605 updateLocal(bv, INIT, true);
1607 if (the_locking_inset)
1608 the_locking_inset->setFont(bv, font, tall);
1612 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1614 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1617 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1618 string const tmp = tabularFeature[i].feature;
1620 if (tmp == what.substr(0, tmp.length())) {
1621 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1622 //tabularFeatures[i].feature.length())) {
1623 action = tabularFeature[i].action;
1627 if (action == LyXTabular::LAST_ACTION)
1631 frontStrip(what.substr(tabularFeature[i].feature.length()));
1632 tabularFeatures(bv, action, val);
1637 void InsetTabular::tabularFeatures(BufferView * bv,
1638 LyXTabular::Feature feature,
1639 string const & value)
1645 bool setLines = false;
1646 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1647 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1650 case LyXTabular::M_ALIGN_LEFT:
1651 case LyXTabular::ALIGN_LEFT:
1652 setAlign=LYX_ALIGN_LEFT;
1654 case LyXTabular::M_ALIGN_RIGHT:
1655 case LyXTabular::ALIGN_RIGHT:
1656 setAlign=LYX_ALIGN_RIGHT;
1658 case LyXTabular::M_ALIGN_CENTER:
1659 case LyXTabular::ALIGN_CENTER:
1660 setAlign=LYX_ALIGN_CENTER;
1662 case LyXTabular::M_VALIGN_TOP:
1663 case LyXTabular::VALIGN_TOP:
1664 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1666 case LyXTabular::M_VALIGN_BOTTOM:
1667 case LyXTabular::VALIGN_BOTTOM:
1668 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1670 case LyXTabular::M_VALIGN_CENTER:
1671 case LyXTabular::VALIGN_CENTER:
1672 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1677 if (hasSelection()) {
1678 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1680 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1681 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1683 setUndo(bv, Undo::FINISH,
1684 bv->text->cursor.par(),
1685 bv->text->cursor.par()->next());
1687 LyXTabular::ltType ltt;
1688 int row = ltt.row = tabular->row_of_cell(actcell);
1689 int column = tabular->column_of_cell(actcell);
1693 case LyXTabular::SET_PWIDTH:
1695 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1696 tabular->SetColumnPWidth(actcell,value);
1698 for (int i = 0; i < tabular->rows(); ++i) {
1699 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1702 updateLocal(bv, INIT, true);
1706 case LyXTabular::SET_MPWIDTH:
1708 bool const update = (tabular->GetPWidth(actcell) != value);
1709 tabular->SetMColumnPWidth(actcell,value);
1711 for (int i = 0; i < tabular->rows(); ++i) {
1712 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1715 updateLocal(bv, INIT, true);
1719 case LyXTabular::SET_SPECIAL_COLUMN:
1720 case LyXTabular::SET_SPECIAL_MULTI:
1721 tabular->SetAlignSpecial(actcell,value,feature);
1722 updateLocal(bv, FULL, true);
1724 case LyXTabular::APPEND_ROW:
1725 // append the row into the tabular
1726 unlockInsetInInset(bv, the_locking_inset);
1727 tabular->AppendRow(actcell);
1728 updateLocal(bv, INIT, true);
1730 case LyXTabular::APPEND_COLUMN:
1731 // append the column into the tabular
1732 unlockInsetInInset(bv, the_locking_inset);
1733 tabular->AppendColumn(actcell);
1734 actcell = tabular->GetCellNumber(row, column);
1735 updateLocal(bv, INIT, true);
1737 case LyXTabular::DELETE_ROW:
1738 unlockInsetInInset(bv, the_locking_inset);
1739 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1740 tabular->DeleteRow(sel_row_start);
1742 if (sel_row_start >= tabular->rows())
1744 actcell = tabular->GetCellNumber(sel_row_start, column);
1746 updateLocal(bv, INIT, true);
1748 case LyXTabular::DELETE_COLUMN:
1749 unlockInsetInInset(bv, the_locking_inset);
1750 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1751 tabular->DeleteColumn(sel_col_start);
1753 if (sel_col_start >= tabular->columns())
1755 actcell = tabular->GetCellNumber(row, sel_col_start);
1757 updateLocal(bv, INIT, true);
1759 case LyXTabular::M_TOGGLE_LINE_TOP:
1761 case LyXTabular::TOGGLE_LINE_TOP:
1763 bool lineSet = !tabular->TopLine(actcell, flag);
1764 for (int i = sel_row_start; i <= sel_row_end; ++i)
1765 for (int j = sel_col_start; j <= sel_col_end; ++j)
1766 tabular->SetTopLine(
1767 tabular->GetCellNumber(i, j),
1769 updateLocal(bv, INIT, true);
1773 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1775 case LyXTabular::TOGGLE_LINE_BOTTOM:
1777 bool lineSet = !tabular->BottomLine(actcell, flag);
1778 for (int i = sel_row_start; i <= sel_row_end; ++i)
1779 for (int j = sel_col_start; j <= sel_col_end; ++j)
1780 tabular->SetBottomLine(
1781 tabular->GetCellNumber(i, j),
1784 updateLocal(bv, INIT, true);
1788 case LyXTabular::M_TOGGLE_LINE_LEFT:
1790 case LyXTabular::TOGGLE_LINE_LEFT:
1792 bool lineSet = !tabular->LeftLine(actcell, flag);
1793 for (int i = sel_row_start; i <= sel_row_end; ++i)
1794 for (int j = sel_col_start; j <= sel_col_end; ++j)
1795 tabular->SetLeftLine(
1796 tabular->GetCellNumber(i,j),
1799 updateLocal(bv, INIT, true);
1803 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1805 case LyXTabular::TOGGLE_LINE_RIGHT:
1807 bool lineSet = !tabular->RightLine(actcell, flag);
1808 for (int i = sel_row_start; i <= sel_row_end; ++i)
1809 for (int j = sel_col_start; j <= sel_col_end; ++j)
1810 tabular->SetRightLine(
1811 tabular->GetCellNumber(i,j),
1814 updateLocal(bv, INIT, true);
1818 case LyXTabular::M_ALIGN_LEFT:
1819 case LyXTabular::M_ALIGN_RIGHT:
1820 case LyXTabular::M_ALIGN_CENTER:
1822 case LyXTabular::ALIGN_LEFT:
1823 case LyXTabular::ALIGN_RIGHT:
1824 case LyXTabular::ALIGN_CENTER:
1825 for (int i = sel_row_start; i <= sel_row_end; ++i)
1826 for (int j = sel_col_start; j <= sel_col_end; ++j)
1827 tabular->SetAlignment(
1828 tabular->GetCellNumber(i, j),
1831 updateLocal(bv, INIT, true);
1833 case LyXTabular::M_VALIGN_TOP:
1834 case LyXTabular::M_VALIGN_BOTTOM:
1835 case LyXTabular::M_VALIGN_CENTER:
1837 case LyXTabular::VALIGN_TOP:
1838 case LyXTabular::VALIGN_BOTTOM:
1839 case LyXTabular::VALIGN_CENTER:
1840 for (int i = sel_row_start; i <= sel_row_end; ++i)
1841 for (int j = sel_col_start; j <= sel_col_end; ++j)
1842 tabular->SetVAlignment(
1843 tabular->GetCellNumber(i, j),
1845 updateLocal(bv, INIT, true);
1847 case LyXTabular::MULTICOLUMN:
1849 if (sel_row_start != sel_row_end) {
1850 Alert::alert(_("Impossible Operation!"),
1851 _("Multicolumns can only be horizontally."),
1855 // just multicol for one Single Cell
1856 if (!hasSelection()) {
1857 // check wether we are completly in a multicol
1858 if (tabular->IsMultiColumn(actcell)) {
1859 tabular->UnsetMultiColumn(actcell);
1860 updateLocal(bv, INIT, true);
1862 tabular->SetMultiColumn(actcell, 1);
1863 updateLocal(bv, CELL, true);
1867 // we have a selection so this means we just add all this
1868 // cells to form a multicolumn cell
1872 if (sel_cell_start > sel_cell_end) {
1873 s_start = sel_cell_end;
1874 s_end = sel_cell_start;
1876 s_start = sel_cell_start;
1877 s_end = sel_cell_end;
1879 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1881 sel_cell_end = sel_cell_start;
1882 updateLocal(bv, INIT, true);
1885 case LyXTabular::SET_ALL_LINES:
1887 case LyXTabular::UNSET_ALL_LINES:
1888 for (int i = sel_row_start; i <= sel_row_end; ++i)
1889 for (int j = sel_col_start; j <= sel_col_end; ++j)
1890 tabular->SetAllLines(
1891 tabular->GetCellNumber(i,j), setLines);
1892 updateLocal(bv, INIT, true);
1894 case LyXTabular::SET_LONGTABULAR:
1895 tabular->SetLongTabular(true);
1896 updateLocal(bv, INIT, true); // because this toggles displayed
1898 case LyXTabular::UNSET_LONGTABULAR:
1899 tabular->SetLongTabular(false);
1900 updateLocal(bv, INIT, true); // because this toggles displayed
1902 case LyXTabular::SET_ROTATE_TABULAR:
1903 tabular->SetRotateTabular(true);
1905 case LyXTabular::UNSET_ROTATE_TABULAR:
1906 tabular->SetRotateTabular(false);
1908 case LyXTabular::SET_ROTATE_CELL:
1909 for (int i = sel_row_start; i <= sel_row_end; ++i)
1910 for (int j = sel_col_start; j<=sel_col_end; ++j)
1911 tabular->SetRotateCell(
1912 tabular->GetCellNumber(i, j),
1915 case LyXTabular::UNSET_ROTATE_CELL:
1916 for (int i = sel_row_start; i <= sel_row_end; ++i)
1917 for (int j = sel_col_start; j <= sel_col_end; ++j)
1918 tabular->SetRotateCell(
1919 tabular->GetCellNumber(i, j), false);
1921 case LyXTabular::SET_USEBOX:
1923 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1924 if (val == tabular->GetUsebox(actcell))
1925 val = LyXTabular::BOX_NONE;
1926 for (int i = sel_row_start; i <= sel_row_end; ++i)
1927 for (int j = sel_col_start; j <= sel_col_end; ++j)
1929 tabular->GetCellNumber(i, j), val);
1932 case LyXTabular::UNSET_LTFIRSTHEAD:
1934 case LyXTabular::SET_LTFIRSTHEAD:
1935 tabular->SetLTHead(ltt, true);
1937 case LyXTabular::UNSET_LTHEAD:
1939 case LyXTabular::SET_LTHEAD:
1940 tabular->SetLTHead(ltt, false);
1942 case LyXTabular::UNSET_LTFOOT:
1944 case LyXTabular::SET_LTFOOT:
1945 tabular->SetLTFoot(ltt, false);
1947 case LyXTabular::UNSET_LTLASTFOOT:
1949 case LyXTabular::SET_LTLASTFOOT:
1950 tabular->SetLTFoot(ltt, true);
1952 case LyXTabular::SET_LTNEWPAGE:
1954 bool what = !tabular->GetLTNewPage(actcell);
1955 tabular->SetLTNewPage(actcell, what);
1958 // dummy stuff just to avoid warnings
1959 case LyXTabular::LAST_ACTION:
1965 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1968 UpdatableInset * inset =
1969 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1970 LyXFont font(LyXFont::ALL_SANE);
1972 x = inset->x() + inset->width(bv, font);
1973 y = inset->descent(bv, font);
1975 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1976 //inset_y = cursor.y();
1977 inset->edit(bv, x, y, button);
1978 if (!the_locking_inset)
1980 updateLocal(bv, CELL, false);
1981 return (the_locking_inset != 0);
1985 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1988 inset_x = cursor_.x()
1989 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1990 inset_y = cursor_.y();
1991 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1995 bool InsetTabular::insetHit(BufferView *, int x, int) const
1998 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2002 // This returns paperWidth() if the cell-width is unlimited or the width
2003 // in pixels if we have a pwidth for this cell.
2004 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2006 string const s = tabular->GetPWidth(cell);
2010 return VSpace(s).inPixels(bv);
2014 int InsetTabular::getMaxWidth(BufferView * bv,
2015 UpdatableInset const * inset) const
2017 int cell = tabular->cur_cell;
2018 if (tabular->GetCellInset(cell) != inset) {
2020 if (tabular->GetCellInset(cell) != inset) {
2022 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2027 int const n = tabular->GetNumberOfCells();
2030 for (cell = 0; cell < n; ++cell) {
2031 if (tabular->GetCellInset(cell) == inset)
2037 lyxerr << "Own inset not found, shouldn't really happen!\n";
2041 int w = getMaxWidthOfCell(bv, cell);
2043 // because the inset then subtracts it's top_x and owner->x()
2044 w += (inset->x() - top_x);
2051 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2053 resizeLyXText(bv, recursive);
2057 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2060 for(int i = 0; i < tabular->rows(); ++i) {
2061 for(int j = 0; j < tabular->columns(); ++j) {
2062 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2070 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2071 bool const recursive) const
2073 if (the_locking_inset)
2074 return the_locking_inset->getLyXText(bv, recursive);
2076 // if we're locked lock the actual insettext and return it's LyXText!!!
2078 UpdatableInset * inset =
2079 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2080 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2081 return the_locking_inset->getLyXText(bv, recursive);
2084 return Inset::getLyXText(bv, recursive);
2088 bool InsetTabular::showInsetDialog(BufferView * bv) const
2090 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2091 bv->owner()->getDialogs()
2092 ->showTabular(const_cast<InsetTabular *>(this));
2097 void InsetTabular::openLayoutDialog(BufferView * bv) const
2099 if (the_locking_inset) {
2100 InsetTabular * i = static_cast<InsetTabular *>
2101 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2103 i->openLayoutDialog(bv);
2107 bv->owner()->getDialogs()->showTabular(
2108 const_cast<InsetTabular *>(this));
2113 // functions returns:
2117 // 3 ... toggled off
2119 func_status::value_type InsetTabular::getStatus(string const & what) const
2121 int action = LyXTabular::LAST_ACTION;
2122 func_status::value_type status = func_status::OK;
2125 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2126 string const tmp = tabularFeature[i].feature;
2127 if (tmp == what.substr(0, tmp.length())) {
2128 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2129 // tabularFeatures[i].feature.length())) {
2130 action = tabularFeature[i].action;
2134 if (action == LyXTabular::LAST_ACTION)
2135 return func_status::Unknown;
2137 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2142 LyXTabular::ltType dummyltt;
2145 if (hasSelection()) {
2146 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2148 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2152 case LyXTabular::SET_PWIDTH:
2153 case LyXTabular::SET_MPWIDTH:
2154 case LyXTabular::SET_SPECIAL_COLUMN:
2155 case LyXTabular::SET_SPECIAL_MULTI:
2156 status |= func_status::Disabled;
2159 case LyXTabular::APPEND_ROW:
2160 case LyXTabular::APPEND_COLUMN:
2161 case LyXTabular::DELETE_ROW:
2162 case LyXTabular::DELETE_COLUMN:
2163 case LyXTabular::SET_ALL_LINES:
2164 case LyXTabular::UNSET_ALL_LINES:
2165 status |= func_status::OK;
2168 case LyXTabular::MULTICOLUMN:
2169 if (tabular->IsMultiColumn(actcell))
2170 status |= func_status::ToggleOn;
2172 status |= func_status::ToggleOff;
2174 case LyXTabular::M_TOGGLE_LINE_TOP:
2176 case LyXTabular::TOGGLE_LINE_TOP:
2177 if (tabular->TopLine(actcell, flag))
2178 status |= func_status::ToggleOn;
2180 status |= func_status::ToggleOff;
2182 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2184 case LyXTabular::TOGGLE_LINE_BOTTOM:
2185 if (tabular->BottomLine(actcell, flag))
2186 status |= func_status::ToggleOn;
2188 status |= func_status::ToggleOff;
2190 case LyXTabular::M_TOGGLE_LINE_LEFT:
2192 case LyXTabular::TOGGLE_LINE_LEFT:
2193 if (tabular->LeftLine(actcell, flag))
2194 status |= func_status::ToggleOn;
2196 status |= func_status::ToggleOff;
2198 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2200 case LyXTabular::TOGGLE_LINE_RIGHT:
2201 if (tabular->RightLine(actcell, flag))
2202 status |= func_status::ToggleOn;
2204 status |= func_status::ToggleOff;
2206 case LyXTabular::M_ALIGN_LEFT:
2208 case LyXTabular::ALIGN_LEFT:
2209 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2210 status |= func_status::ToggleOn;
2212 status |= func_status::ToggleOff;
2214 case LyXTabular::M_ALIGN_RIGHT:
2216 case LyXTabular::ALIGN_RIGHT:
2217 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2218 status |= func_status::ToggleOn;
2220 status |= func_status::ToggleOff;
2222 case LyXTabular::M_ALIGN_CENTER:
2224 case LyXTabular::ALIGN_CENTER:
2225 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2226 status |= func_status::ToggleOn;
2228 status |= func_status::ToggleOff;
2230 case LyXTabular::M_VALIGN_TOP:
2232 case LyXTabular::VALIGN_TOP:
2233 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2234 status |= func_status::ToggleOn;
2236 status |= func_status::ToggleOff;
2238 case LyXTabular::M_VALIGN_BOTTOM:
2240 case LyXTabular::VALIGN_BOTTOM:
2241 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2242 status |= func_status::ToggleOn;
2244 status |= func_status::ToggleOff;
2246 case LyXTabular::M_VALIGN_CENTER:
2248 case LyXTabular::VALIGN_CENTER:
2249 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2250 status |= func_status::ToggleOn;
2252 status |= func_status::ToggleOff;
2254 case LyXTabular::SET_LONGTABULAR:
2255 if (tabular->IsLongTabular())
2256 status |= func_status::ToggleOn;
2258 status |= func_status::ToggleOff;
2260 case LyXTabular::UNSET_LONGTABULAR:
2261 if (!tabular->IsLongTabular())
2262 status |= func_status::ToggleOn;
2264 status |= func_status::ToggleOff;
2266 case LyXTabular::SET_ROTATE_TABULAR:
2267 if (tabular->GetRotateTabular())
2268 status |= func_status::ToggleOn;
2270 status |= func_status::ToggleOff;
2272 case LyXTabular::UNSET_ROTATE_TABULAR:
2273 if (!tabular->GetRotateTabular())
2274 status |= func_status::ToggleOn;
2276 status |= func_status::ToggleOff;
2278 case LyXTabular::SET_ROTATE_CELL:
2279 if (tabular->GetRotateCell(actcell))
2280 status |= func_status::ToggleOn;
2282 status |= func_status::ToggleOff;
2284 case LyXTabular::UNSET_ROTATE_CELL:
2285 if (!tabular->GetRotateCell(actcell))
2286 status |= func_status::ToggleOn;
2288 status |= func_status::ToggleOff;
2290 case LyXTabular::SET_USEBOX:
2291 if (strToInt(argument) == tabular->GetUsebox(actcell))
2292 status |= func_status::ToggleOn;
2294 status |= func_status::ToggleOff;
2296 case LyXTabular::SET_LTFIRSTHEAD:
2297 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2298 status |= func_status::ToggleOn;
2300 status |= func_status::ToggleOff;
2302 case LyXTabular::SET_LTHEAD:
2303 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2304 status |= func_status::ToggleOn;
2306 status |= func_status::ToggleOff;
2308 case LyXTabular::SET_LTFOOT:
2309 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2310 status |= func_status::ToggleOn;
2312 status |= func_status::ToggleOff;
2314 case LyXTabular::SET_LTLASTFOOT:
2315 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2316 status |= func_status::ToggleOn;
2318 status |= func_status::ToggleOff;
2320 case LyXTabular::SET_LTNEWPAGE:
2321 if (tabular->GetLTNewPage(actcell))
2322 status |= func_status::ToggleOn;
2324 status |= func_status::ToggleOff;
2327 status = func_status::Disabled;
2334 std::vector<string> const InsetTabular::getLabelList() const
2336 return tabular->getLabelList();
2340 bool InsetTabular::copySelection(BufferView * bv)
2342 if (!hasSelection())
2345 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2346 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2347 if (sel_col_start > sel_col_end) {
2348 sel_col_start = sel_col_end;
2349 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2351 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2353 int const columns = sel_col_end - sel_col_start + 1;
2355 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2356 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2357 if (sel_row_start > sel_row_end) {
2358 swap(sel_row_start, sel_row_end);
2360 int const rows = sel_row_end - sel_row_start + 1;
2362 delete paste_tabular;
2363 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2364 for (int i = 0; i < sel_row_start; ++i)
2365 paste_tabular->DeleteRow(0);
2366 while(paste_tabular->rows() > rows)
2367 paste_tabular->DeleteRow(rows);
2368 paste_tabular->SetTopLine(0, true, true);
2369 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2371 for (int i = 0; i < sel_col_start; ++i)
2372 paste_tabular->DeleteColumn(0);
2373 while (paste_tabular->columns() > columns)
2374 paste_tabular->DeleteColumn(columns);
2375 paste_tabular->SetLeftLine(0, true, true);
2376 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2380 paste_tabular->Ascii(bv->buffer(), sstr);
2381 bv->stuffClipboard(sstr.str().c_str());
2386 bool InsetTabular::pasteSelection(BufferView * bv)
2391 for (int r1 = 0, r2 = actrow;
2392 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2394 for(int c1 = 0, c2 = actcol;
2395 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2397 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2398 tabular->IsPartOfMultiColumn(r2,c2))
2400 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2404 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2408 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2409 int const n2 = tabular->GetCellNumber(r2, c2);
2410 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2411 tabular->GetCellInset(n2)->setOwner(this);
2412 tabular->GetCellInset(n2)->deleteLyXText(bv);
2419 bool InsetTabular::cutSelection()
2421 if (!hasSelection())
2424 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2425 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2426 if (sel_col_start > sel_col_end) {
2427 sel_col_start = sel_col_end;
2428 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2430 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2432 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2433 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2434 if (sel_row_start > sel_row_end) {
2435 swap(sel_row_start, sel_row_end);
2437 if (sel_cell_start > sel_cell_end) {
2438 swap(sel_cell_start, sel_cell_end);
2440 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2441 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2442 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2449 bool InsetTabular::isRightToLeft(BufferView *bv )
2451 return bv->getParentLanguage(this)->RightToLeft();
2455 bool InsetTabular::nodraw() const
2457 if (!UpdatableInset::nodraw() && the_locking_inset)
2458 return the_locking_inset->nodraw();
2459 return UpdatableInset::nodraw();
2463 int InsetTabular::scroll(bool recursive) const
2465 int sx = UpdatableInset::scroll(false);
2467 if (recursive && the_locking_inset)
2468 sx += the_locking_inset->scroll(recursive);
2474 bool InsetTabular::doClearArea() const
2476 return !locked || (need_update & (FULL|INIT));
2480 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2482 srow = tabular->row_of_cell(sel_cell_start);
2483 erow = tabular->row_of_cell(sel_cell_end);
2487 scol = tabular->column_of_cell(sel_cell_start);
2488 ecol = tabular->column_of_cell(sel_cell_end);
2492 ecol = tabular->right_column_of_cell(sel_cell_end);
2496 Paragraph * InsetTabular::getParFromID(int id) const
2499 for(int i = 0; i < tabular->rows(); ++i) {
2500 for(int j = 0; j < tabular->columns(); ++j) {
2501 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2509 Paragraph * InsetTabular::firstParagraph() const
2511 if (the_locking_inset)
2512 return the_locking_inset->firstParagraph();
2517 Paragraph * InsetTabular::getFirstParagraph(int i) const
2519 return (i < tabular->GetNumberOfCells())
2520 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2525 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2527 if (the_locking_inset)
2528 return the_locking_inset->cursor(bv);
2529 return Inset::cursor(bv);
2533 Inset * InsetTabular::getInsetFromID(int id_arg) const
2536 return const_cast<InsetTabular *>(this);
2539 for(int i=0; i < tabular->rows(); ++i) {
2540 for(int j=0; j < tabular->columns(); ++j) {
2541 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2549 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2551 if (the_locking_inset) {
2552 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2555 if (tabular->IsLastCell(actcell)) {
2556 bv->unlockInset(const_cast<InsetTabular *>(this));
2562 // otherwise we have to lock the next inset and ask for it's selecttion
2563 UpdatableInset * inset =
2564 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2565 inset->edit(bv, 0, 0, 0);
2566 string const str(selectNextWordInt(bv, value));
2574 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2576 // when entering this function the inset should be ALWAYS locked!
2577 lyx::Assert(the_locking_inset);
2579 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2583 if (tabular->IsLastCell(actcell)) {
2584 bv->unlockInset(const_cast<InsetTabular *>(this));
2588 // otherwise we have to lock the next inset and ask for it's selecttion
2589 UpdatableInset * inset =
2590 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2592 return selectNextWordInt(bv, value);
2596 void InsetTabular::selectSelectedWord(BufferView * bv)
2598 if (the_locking_inset) {
2599 the_locking_inset->selectSelectedWord(bv);
2606 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2608 if (the_locking_inset) {
2609 the_locking_inset->toggleSelection(bv, kill_selection);
2614 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2615 bool const & cs, bool const & mw)
2617 if (the_locking_inset) {
2618 if (the_locking_inset->searchForward(bv, str, cs, mw))
2620 if (tabular->IsLastCell(actcell)) {
2621 bv->unlockInset(const_cast<InsetTabular *>(this));
2626 // otherwise we have to lock the next inset and search there
2627 UpdatableInset * inset =
2628 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2631 bool const res = searchForward(bv, str, cs, mw);
2632 updateLocal(bv, NONE, false);
2633 bv->updateInset(const_cast<InsetTabular *>(this), false);
2636 return searchForward(bv, str, cs, mw);
2641 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2642 bool const & cs, bool const & mw)
2644 if (the_locking_inset) {
2645 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2647 if (!actcell) { // we are already in the first cell
2648 bv->unlockInset(const_cast<InsetTabular *>(this));
2653 // otherwise we have to lock the next inset and search there
2654 UpdatableInset * inset =
2655 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2656 inset->edit(bv, false);
2658 bool const res = searchBackward(bv, str, cs, mw);
2659 bv->updateInset(const_cast<InsetTabular *>(this), false);
2662 return searchBackward(bv, str, cs, mw);
2667 bool InsetTabular::insetAllowed(Inset::Code code) const
2669 if (the_locking_inset)
2670 return the_locking_inset->insetAllowed(code);