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;
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;
155 actrow = actcell = 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;
299 if (hasSelection()) {
300 drawCellSelection(pain, nx, baseline, i, j, cell);
303 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
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 lyx::Assert(hasSelection());
452 int cs = tabular->column_of_cell(sel_cell_start);
453 int ce = tabular->column_of_cell(sel_cell_end);
456 cs = tabular->column_of_cell(sel_cell_end);
458 ce = tabular->right_column_of_cell(sel_cell_end);
461 int rs = tabular->row_of_cell(sel_cell_start);
462 int re = tabular->row_of_cell(sel_cell_end);
463 if (rs > re) swap(rs, re);
465 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
466 int w = tabular->GetWidthOfColumn(cell);
467 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
468 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
469 w, h, LColor::selection);
474 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
480 owner()->update(bv, font, true);
487 if (calculate_dimensions_of_cells(bv, font, true))
490 owner()->update(bv, font, true);
494 if (the_locking_inset)
495 the_locking_inset->update(bv, font, reinit);
496 if (need_update < FULL &&
497 bv->text->status() == LyXText::NEED_MORE_REFRESH)
502 switch (need_update) {
506 if (calculate_dimensions_of_cells(bv, font, false))
519 string const InsetTabular::editMessage() const
521 return _("Opened Tabular Inset");
525 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
527 UpdatableInset::edit(bv, x, y, button);
529 if (!bv->lockInset(this)) {
530 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
534 the_locking_inset = 0;
540 if (insetHit(bv, x, y) && (button != 3)) {
541 activateCellInsetAbs(bv, x, y, button);
546 void InsetTabular::edit(BufferView * bv, bool front)
548 UpdatableInset::edit(bv, front);
550 if (!bv->lockInset(this)) {
551 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
555 the_locking_inset = 0;
561 actcell = tabular->GetNumberOfCells() - 1;
568 void InsetTabular::insetUnlock(BufferView * bv)
570 if (the_locking_inset) {
571 the_locking_inset->insetUnlock(bv);
572 the_locking_inset = 0;
577 if (scroll(false) || hasSelection()) {
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()) {
600 if (need_update != NONE) {
601 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
602 if (locked) // && (what != NONE))
608 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
610 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
615 if (inset == tabular->GetCellInset(actcell)) {
616 lyxerr[Debug::INSETTEXT] << "OK" << endl;
617 the_locking_inset = tabular->GetCellInset(actcell);
620 } else if (!the_locking_inset) {
621 int const n = tabular->GetNumberOfCells();
622 int const id = inset->id();
623 for (int i = 0; i < n; ++i) {
624 InsetText * in = tabular->GetCellInset(i);
627 the_locking_inset = in;
632 if (in->getInsetFromID(id)) {
634 the_locking_inset = in;
637 return the_locking_inset->lockInsetInInset(bv, inset);
640 } else if (the_locking_inset && (the_locking_inset == inset)) {
641 lyxerr[Debug::INSETTEXT] << "OK" << endl;
643 } else if (the_locking_inset) {
644 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
645 return the_locking_inset->lockInsetInInset(bv, inset);
647 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
652 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
655 if (!the_locking_inset)
657 if (the_locking_inset == inset) {
658 the_locking_inset->insetUnlock(bv);
659 the_locking_inset = 0;
661 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
667 updateLocal(bv, CELL, false);
668 showInsetCursor(bv, false);
671 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
672 if (inset->lyxCode() == TABULAR_CODE &&
673 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
674 bv->owner()->getDialogs()->updateTabular(this);
683 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
685 if (!the_locking_inset)
687 if (the_locking_inset != inset) {
688 if (!the_locking_inset->updateInsetInInset(bv, inset))
691 updateLocal(bv, CELL, false);
696 unsigned int InsetTabular::insetInInsetY()
698 if (!the_locking_inset)
701 return inset_y + the_locking_inset->insetInInsetY();
705 UpdatableInset * InsetTabular::getLockingInset() const
707 return the_locking_inset ? the_locking_inset->getLockingInset() :
708 const_cast<InsetTabular *>(this);
712 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
716 if (the_locking_inset)
717 return the_locking_inset->getFirstLockingInsetOfType(c);
722 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
724 if (the_locking_inset)
725 return the_locking_inset->insertInset(bv, inset);
730 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
732 if (hasSelection() && (button == 3))
735 if (hasSelection()) {
737 updateLocal(bv, SELECTION, false);
740 int const ocell = actcell;
741 int const orow = actrow;
746 updateLocal(bv, NONE, false);
749 if ((ocell != actcell) && the_locking_inset) {
750 the_locking_inset->insetUnlock(bv);
751 the_locking_inset = 0;
757 bool const inset_hit = insetHit(bv, x, y);
759 if ((ocell == actcell) && the_locking_inset && inset_hit) {
761 the_locking_inset->insetButtonPress(bv,
762 x - inset_x, y - inset_y,
765 } else if (the_locking_inset) {
766 the_locking_inset->insetUnlock(bv);
768 the_locking_inset = 0;
770 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
773 if (inset_hit && bv->theLockingInset()) {
774 if (activateCellInsetAbs(bv, x, y, button))
775 the_locking_inset->insetButtonPress(bv,
785 void InsetTabular::insetButtonRelease(BufferView * bv,
786 int x, int y, int button)
789 if (the_locking_inset) {
791 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
792 i->insetButtonRelease(bv, x, y, button);
796 bv->owner()->getDialogs()->showTabular(this);
799 if (the_locking_inset) {
800 the_locking_inset->insetButtonRelease(bv,
801 x - inset_x, y - inset_y,
808 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
810 if (the_locking_inset) {
811 the_locking_inset->insetMotionNotify(bv,
819 // int const old_cell = actcell;
822 if (!hasSelection()) {
823 setSelection(actcell, actcell);
825 setSelection(sel_cell_start, actcell);
827 updateLocal(bv, SELECTION, false);
832 void InsetTabular::insetKeyPress(XKeyEvent * xke)
834 if (the_locking_inset) {
835 the_locking_inset->insetKeyPress(xke);
841 UpdatableInset::RESULT
842 InsetTabular::localDispatch(BufferView * bv, kb_action action,
845 // We need to save the value of the_locking_inset as the call to
846 // the_locking_inset->LocalDispatch might unlock it.
847 old_locking_inset = the_locking_inset;
848 UpdatableInset::RESULT result =
849 UpdatableInset::localDispatch(bv, action, arg);
850 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
855 if ((action < 0) && arg.empty())
858 bool hs = hasSelection();
861 // this one have priority over the locked InsetText, if we're not already
862 // inside another tabular then that one get's priority!
863 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
868 unlockInsetInInset(bv, the_locking_inset);
869 if (action == LFUN_TAB)
870 moveNextCell(bv, old_locking_inset != 0);
872 movePrevCell(bv, old_locking_inset != 0);
875 updateLocal(bv, SELECTION, false);
876 if (!the_locking_inset) {
878 return DISPATCHED_NOUPDATE;
881 // this to avoid compiler warnings.
887 if (the_locking_inset) {
888 result = the_locking_inset->localDispatch(bv, action, arg);
889 if (result == DISPATCHED_NOUPDATE) {
892 if (sc != scroll()) { // inset has been scrolled
893 the_locking_inset->toggleInsetCursor(bv);
894 updateLocal(bv, FULL, false);
895 the_locking_inset->toggleInsetCursor(bv);
898 } else if (result == DISPATCHED) {
899 the_locking_inset->toggleInsetCursor(bv);
900 updateLocal(bv, CELL, false);
901 the_locking_inset->toggleInsetCursor(bv);
903 } else if (result == FINISHED_UP) {
905 } else if (result == FINISHED_DOWN) {
907 } else if (result == FINISHED_RIGHT) {
915 // --- Cursor Movements ----------------------------------
916 case LFUN_RIGHTSEL: {
917 int const start = hasSelection() ? sel_cell_start : actcell;
918 if (tabular->IsLastCellInRow(actcell)) {
919 setSelection(start, actcell);
924 // if we are starting a selection, only select
925 // the current cell at the beginning
926 if (hasSelection()) {
927 moveRight(bv, false);
930 setSelection(start, end);
931 updateLocal(bv, SELECTION, false);
935 result = moveRight(bv);
938 updateLocal(bv, SELECTION, false);
941 int const start = hasSelection() ? sel_cell_start : actcell;
942 if (tabular->IsFirstCellInRow(actcell)) {
943 setSelection(start, actcell);
948 // if we are starting a selection, only select
949 // the current cell at the beginning
950 if (hasSelection()) {
954 setSelection(start, end);
955 updateLocal(bv, SELECTION, false);
959 result = moveLeft(bv);
962 updateLocal(bv, SELECTION, false);
965 int const start = hasSelection() ? sel_cell_start : actcell;
966 int const ocell = actcell;
967 // if we are starting a selection, only select
968 // the current cell at the beginning
969 if (hasSelection()) {
972 if ((ocell == sel_cell_end) ||
973 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
974 setSelection(start, tabular->GetCellBelow(sel_cell_end));
976 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
977 updateLocal(bv, SELECTION, false);
981 result = moveDown(bv, old_locking_inset != 0);
984 updateLocal(bv, SELECTION, false);
988 int const start = hasSelection() ? sel_cell_start : actcell;
989 int const ocell = actcell;
990 // if we are starting a selection, only select
991 // the current cell at the beginning
992 if (hasSelection()) {
995 if ((ocell == sel_cell_end) ||
996 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
997 setSelection(start, tabular->GetCellAbove(sel_cell_end));
999 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1000 updateLocal(bv, SELECTION, false);
1004 result = moveUp(bv, old_locking_inset != 0);
1007 updateLocal(bv, SELECTION, false);
1010 int column = actcol;
1011 unlockInsetInInset(bv, the_locking_inset);
1012 if (bv->text->first + bv->painter().paperHeight() <
1013 (top_baseline + tabular->GetHeightOfTabular()))
1015 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1016 updateLocal(bv, FULL, false);
1017 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1019 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1022 updateLocal(bv, CURSOR, false);
1026 int column = actcol;
1027 unlockInsetInInset(bv, the_locking_inset);
1028 if (top_baseline < 0) {
1029 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1030 updateLocal(bv, FULL, false);
1031 if (top_baseline > 0)
1034 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1039 updateLocal(bv, CURSOR, false);
1042 // none of these make sense for insettabular,
1043 // but we must catch them to prevent any
1044 // selection from being confused
1048 case LFUN_WORDLEFTSEL:
1049 case LFUN_WORDRIGHT:
1050 case LFUN_WORDRIGHTSEL:
1051 case LFUN_DOWN_PARAGRAPH:
1052 case LFUN_DOWN_PARAGRAPHSEL:
1053 case LFUN_UP_PARAGRAPH:
1054 case LFUN_UP_PARAGRAPHSEL:
1055 case LFUN_BACKSPACE:
1062 case LFUN_LAYOUT_TABULAR:
1064 bv->owner()->getDialogs()->showTabular(this);
1067 case LFUN_TABULAR_FEATURE:
1068 if (!tabularFeatures(bv, arg))
1069 result = UNDISPATCHED;
1072 if (!copySelection(bv))
1074 setUndo(bv, Undo::DELETE,
1075 bv->text->cursor.par(),
1076 bv->text->cursor.par()->next());
1078 updateLocal(bv, INIT, true);
1081 if (!hasSelection())
1086 case LFUN_PASTESELECTION:
1088 string const clip(bv->getClipboard());
1092 if (clip.find('\t') != string::npos) {
1096 string::size_type len = clip.length();
1097 string::size_type p = 0;
1100 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1108 maxCols = max(cols, maxCols);
1114 maxCols = max(cols, maxCols);
1115 delete paste_tabular;
1116 paste_tabular = new LyXTabular(this, rows, maxCols);
1117 string::size_type op = 0;
1119 int cells = paste_tabular->GetNumberOfCells();
1121 while ((cell < cells) && (p < len) &&
1122 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1127 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1132 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1133 while (cols++ < maxCols)
1141 // check for the last cell if there is no trailing '\n'
1142 if ((cell < cells) && (op < len))
1143 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1145 // so that the clipboard is used and it goes on
1147 // and executes LFUN_PASTESELECTION in insettext!
1148 delete paste_tabular;
1153 if (hasPasteBuffer()) {
1154 setUndo(bv, Undo::INSERT,
1155 bv->text->cursor.par(),
1156 bv->text->cursor.par()->next());
1158 updateLocal(bv, INIT, true);
1161 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1163 // we try to activate the actual inset and put this event down to
1164 // the insets dispatch function.
1165 result = UNDISPATCHED;
1166 if (the_locking_inset)
1169 if (activateCellInset(bv)) {
1170 // reset need_update setted in above function!
1172 result = the_locking_inset->localDispatch(bv, action, arg);
1173 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1174 unlockInsetInInset(bv, the_locking_inset);
1176 // we need to update if this was requested before
1177 updateLocal(bv, NONE, false);
1178 return UNDISPATCHED;
1183 updateLocal(bv, CELL, false);
1188 if (result < FINISHED) {
1189 if (!the_locking_inset) {
1190 showInsetCursor(bv);
1193 bv->unlockInset(this);
1198 int InsetTabular::latex(Buffer const * buf, ostream & os,
1199 bool fragile, bool fp) const
1201 return tabular->Latex(buf, os, fragile, fp);
1205 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1207 // This should be changed to a real ascii export
1208 return tabular->Ascii(buf, os);
1212 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1214 return tabular->Ascii(buf,os);
1218 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1223 // if the table is inside a float it doesn't need the informaltable
1224 // wrapper. Search for it.
1225 for(master = owner();
1226 master && master->lyxCode() != Inset::FLOAT_CODE;
1227 master = master->owner());
1230 os << "<informaltable>\n";
1233 ret+= tabular->DocBook(buf,os);
1235 os << "</informaltable>\n";
1242 void InsetTabular::validate(LaTeXFeatures & features) const
1244 tabular->Validate(features);
1248 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1249 LyXFont const & font,
1256 bool changed = false;
1258 // if we have a locking_inset we should have to check only this cell for
1259 // change so I'll try this to have a boost, but who knows ;)
1260 if ((need_update != INIT) &&
1261 (the_locking_inset == tabular->GetCellInset(actcell))) {
1262 for(int i = 0; i < tabular->columns(); ++i) {
1263 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1265 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1268 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1269 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1270 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1273 for (int i = 0; i < tabular->rows(); ++i) {
1276 for (int j = 0; j < tabular->columns(); ++j) {
1277 if (tabular->IsPartOfMultiColumn(i,j))
1280 inset = tabular->GetCellInset(cell);
1281 if (!reinit && !tabular->GetPWidth(cell).zero())
1282 inset->update(bv, font, false);
1283 maxAsc = max(maxAsc, inset->ascent(bv, font));
1284 maxDesc = max(maxDesc, inset->descent(bv, font));
1285 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1287 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1288 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1296 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1298 if (the_locking_inset) {
1299 the_locking_inset->getCursorPos(bv, x, y);
1302 x = cursor_.x() - top_x;
1307 void InsetTabular::toggleInsetCursor(BufferView * bv)
1309 if (the_locking_inset) {
1310 the_locking_inset->toggleInsetCursor(bv);
1314 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1316 int const asc = lyxfont::maxAscent(font);
1317 int const desc = lyxfont::maxDescent(font);
1319 if (isCursorVisible())
1320 bv->hideLockedInsetCursor();
1322 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1323 toggleCursorVisible();
1327 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1329 if (!isCursorVisible()) {
1330 LyXFont font; // = GetFont(par, cursor.pos);
1332 int const asc = lyxfont::maxAscent(font);
1333 int const desc = lyxfont::maxDescent(font);
1334 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1336 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1337 setCursorVisible(true);
1342 void InsetTabular::hideInsetCursor(BufferView * bv)
1344 if (isCursorVisible()) {
1345 bv->hideLockedInsetCursor();
1346 setCursorVisible(false);
1351 void InsetTabular::fitInsetCursor(BufferView * bv) const
1353 if (the_locking_inset) {
1354 the_locking_inset->fitInsetCursor(bv);
1359 int const asc = lyxfont::maxAscent(font);
1360 int const desc = lyxfont::maxDescent(font);
1361 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1365 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1369 actcell = actrow = actcol = 0;
1370 int ly = tabular->GetDescentOfRow(actrow);
1372 // first search the right row
1373 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1374 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1375 tabular->GetAscentOfRow(actrow + 1) +
1376 tabular->GetAdditionalHeight(actrow + 1));
1378 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1380 actcell = tabular->GetCellNumber(actrow, actcol);
1382 // now search the right column
1383 int lx = tabular->GetWidthOfColumn(actcell) -
1384 tabular->GetAdditionalWidth(actcell);
1385 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1386 lx += tabular->GetWidthOfColumn(actcell + 1)
1387 + tabular->GetAdditionalWidth(actcell);
1389 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1394 int InsetTabular::getCellXPos(int cell) const
1398 for (; !tabular->IsFirstCellInRow(c); --c)
1400 int lx = tabular->GetWidthOfColumn(cell);
1401 for (; c < cell; ++c) {
1402 lx += tabular->GetWidthOfColumn(c);
1404 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1408 void InsetTabular::resetPos(BufferView * bv) const
1410 if (!locked || nodraw())
1412 #warning This should be fixed in the right manner (20011128 Jug)
1413 // fast hack to fix infinite repaintings!
1416 in_reset_pos = true;
1418 actcol = tabular->column_of_cell(actcell);
1423 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1424 if (tabular->IsLastCellInRow(cell)) {
1425 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1426 tabular->GetAscentOfRow(actrow + 1) +
1427 tabular->GetAdditionalHeight(actrow + 1));
1431 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1432 int new_x = getCellXPos(actcell);
1433 int old_x = cursor_.x();
1436 // cursor.x(getCellXPos(actcell) + offset);
1437 if ((actcol < tabular->columns()-1) && scroll(false) &&
1438 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1441 updateLocal(bv, FULL, false);
1442 } else if (the_locking_inset &&
1443 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1445 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1446 if (xx > (bv->workWidth()-20)) {
1447 scroll(bv, -(xx - bv->workWidth() + 60));
1448 updateLocal(bv, FULL, false);
1449 } else if (xx < 20) {
1455 updateLocal(bv, FULL, false);
1457 } else if ((cursor_.x() - offset) > 20 &&
1458 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1459 > (bv->workWidth() - 20)) {
1460 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1461 updateLocal(bv, FULL, false);
1462 } else if ((cursor_.x() - offset) < 20) {
1463 scroll(bv, 20 - cursor_.x() + offset);
1464 updateLocal(bv, FULL, false);
1465 } else if (scroll(false) && top_x > 20 &&
1466 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1467 scroll(bv, old_x - cursor_.x());
1468 updateLocal(bv, FULL, false);
1470 if (the_locking_inset) {
1471 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1472 inset_y = cursor_.y();
1474 if ((!the_locking_inset ||
1475 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1476 actcell != oldcell) {
1477 InsetTabular * inset = const_cast<InsetTabular *>(this);
1478 bv->owner()->getDialogs()->updateTabular(inset);
1481 in_reset_pos = false;
1485 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1487 if (lock && !old_locking_inset) {
1488 if (activateCellInset(bv))
1491 bool moved = isRightToLeft(bv)
1492 ? movePrevCell(bv) : moveNextCell(bv);
1494 return FINISHED_RIGHT;
1495 if (lock && activateCellInset(bv))
1499 return DISPATCHED_NOUPDATE;
1503 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1505 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1508 if (lock) { // behind the inset
1509 if (activateCellInset(bv, 0, 0, 0, true))
1513 return DISPATCHED_NOUPDATE;
1517 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1519 int const ocell = actcell;
1520 actcell = tabular->GetCellAbove(actcell);
1521 if (actcell == ocell) // we moved out of the inset
1527 if (old_locking_inset) {
1528 old_locking_inset->getCursorPos(bv, x, y);
1529 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1531 if (activateCellInset(bv, x, 0))
1534 return DISPATCHED_NOUPDATE;
1538 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1540 int const ocell = actcell;
1541 actcell = tabular->GetCellBelow(actcell);
1542 if (actcell == ocell) // we moved out of the inset
1543 return FINISHED_DOWN;
1548 if (old_locking_inset) {
1549 old_locking_inset->getCursorPos(bv, x, y);
1550 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1552 if (activateCellInset(bv, x, 0))
1555 return DISPATCHED_NOUPDATE;
1559 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1561 if (isRightToLeft(bv)) {
1562 if (tabular->IsFirstCellInRow(actcell)) {
1563 int row = tabular->row_of_cell(actcell);
1564 if (row == tabular->rows() - 1)
1566 actcell = tabular->GetLastCellInRow(row);
1567 actcell = tabular->GetCellBelow(actcell);
1574 if (tabular->IsLastCell(actcell))
1579 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1580 isRightToLeftPar(bv->buffer()->params);
1581 activateCellInset(bv, 0, 0, 0, !rtl);
1588 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1590 if (isRightToLeft(bv)) {
1591 if (tabular->IsLastCellInRow(actcell)) {
1592 int row = tabular->row_of_cell(actcell);
1595 actcell = tabular->GetFirstCellInRow(row);
1596 actcell = tabular->GetCellAbove(actcell);
1598 if (tabular->IsLastCell(actcell))
1603 if (!actcell) // first cell
1608 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1609 isRightToLeftPar(bv->buffer()->params);
1610 activateCellInset(bv, 0, 0, 0, !rtl);
1617 bool InsetTabular::deletable() const
1623 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1627 setSelection(0, tabular->GetNumberOfCells() - 1);
1629 if (hasSelection()) {
1630 setUndo(bv, Undo::EDIT,
1631 bv->text->cursor.par(),
1632 bv->text->cursor.par()->next());
1633 bool frozen = undo_frozen;
1636 // apply the fontchange on the whole selection
1641 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1642 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1643 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1644 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1649 updateLocal(bv, INIT, true);
1651 if (the_locking_inset)
1652 the_locking_inset->setFont(bv, font, tall);
1656 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1658 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1661 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1662 string const tmp = tabularFeature[i].feature;
1664 if (tmp == what.substr(0, tmp.length())) {
1665 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1666 //tabularFeatures[i].feature.length())) {
1667 action = tabularFeature[i].action;
1671 if (action == LyXTabular::LAST_ACTION)
1675 frontStrip(what.substr(tabularFeature[i].feature.length()));
1676 tabularFeatures(bv, action, val);
1681 void InsetTabular::tabularFeatures(BufferView * bv,
1682 LyXTabular::Feature feature,
1683 string const & value)
1689 bool setLines = false;
1690 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1691 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1694 case LyXTabular::M_ALIGN_LEFT:
1695 case LyXTabular::ALIGN_LEFT:
1696 setAlign = LYX_ALIGN_LEFT;
1698 case LyXTabular::M_ALIGN_RIGHT:
1699 case LyXTabular::ALIGN_RIGHT:
1700 setAlign = LYX_ALIGN_RIGHT;
1702 case LyXTabular::M_ALIGN_CENTER:
1703 case LyXTabular::ALIGN_CENTER:
1704 setAlign = LYX_ALIGN_CENTER;
1706 case LyXTabular::M_VALIGN_TOP:
1707 case LyXTabular::VALIGN_TOP:
1708 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1710 case LyXTabular::M_VALIGN_BOTTOM:
1711 case LyXTabular::VALIGN_BOTTOM:
1712 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1714 case LyXTabular::M_VALIGN_CENTER:
1715 case LyXTabular::VALIGN_CENTER:
1716 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1721 if (hasSelection()) {
1722 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1724 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1725 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1727 setUndo(bv, Undo::FINISH,
1728 bv->text->cursor.par(),
1729 bv->text->cursor.par()->next());
1731 LyXTabular::ltType ltt;
1732 int row = ltt.row = tabular->row_of_cell(actcell);
1733 int column = tabular->column_of_cell(actcell);
1737 case LyXTabular::SET_PWIDTH:
1739 LyXLength const vallen = LyXLength(value);
1740 bool const update = (tabular->GetColumnPWidth(actcell) != vallen);
1741 tabular->SetColumnPWidth(actcell,vallen);
1743 for (int i = 0; i < tabular->rows(); ++i) {
1744 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1747 updateLocal(bv, INIT, true);
1751 case LyXTabular::SET_MPWIDTH:
1753 LyXLength const vallen = LyXLength(value);
1754 bool const update = (tabular->GetPWidth(actcell) != vallen);
1755 tabular->SetMColumnPWidth(actcell,vallen);
1757 for (int i = 0; i < tabular->rows(); ++i) {
1758 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1761 updateLocal(bv, INIT, true);
1765 case LyXTabular::SET_SPECIAL_COLUMN:
1766 case LyXTabular::SET_SPECIAL_MULTI:
1767 tabular->SetAlignSpecial(actcell,value,feature);
1768 updateLocal(bv, FULL, true);
1770 case LyXTabular::APPEND_ROW:
1771 // append the row into the tabular
1772 unlockInsetInInset(bv, the_locking_inset);
1773 tabular->AppendRow(actcell);
1774 updateLocal(bv, INIT, true);
1776 case LyXTabular::APPEND_COLUMN:
1777 // append the column into the tabular
1778 unlockInsetInInset(bv, the_locking_inset);
1779 tabular->AppendColumn(actcell);
1780 actcell = tabular->GetCellNumber(row, column);
1781 updateLocal(bv, INIT, true);
1783 case LyXTabular::DELETE_ROW:
1784 unlockInsetInInset(bv, the_locking_inset);
1785 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1786 tabular->DeleteRow(sel_row_start);
1788 if (sel_row_start >= tabular->rows())
1790 actcell = tabular->GetCellNumber(sel_row_start, column);
1792 updateLocal(bv, INIT, true);
1794 case LyXTabular::DELETE_COLUMN:
1795 unlockInsetInInset(bv, the_locking_inset);
1796 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1797 tabular->DeleteColumn(sel_col_start);
1799 if (sel_col_start >= tabular->columns())
1801 actcell = tabular->GetCellNumber(row, sel_col_start);
1803 updateLocal(bv, INIT, true);
1805 case LyXTabular::M_TOGGLE_LINE_TOP:
1807 case LyXTabular::TOGGLE_LINE_TOP:
1809 bool lineSet = !tabular->TopLine(actcell, flag);
1810 for (int i = sel_row_start; i <= sel_row_end; ++i)
1811 for (int j = sel_col_start; j <= sel_col_end; ++j)
1812 tabular->SetTopLine(
1813 tabular->GetCellNumber(i, j),
1815 updateLocal(bv, INIT, true);
1819 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1821 case LyXTabular::TOGGLE_LINE_BOTTOM:
1823 bool lineSet = !tabular->BottomLine(actcell, flag);
1824 for (int i = sel_row_start; i <= sel_row_end; ++i)
1825 for (int j = sel_col_start; j <= sel_col_end; ++j)
1826 tabular->SetBottomLine(
1827 tabular->GetCellNumber(i, j),
1830 updateLocal(bv, INIT, true);
1834 case LyXTabular::M_TOGGLE_LINE_LEFT:
1836 case LyXTabular::TOGGLE_LINE_LEFT:
1838 bool lineSet = !tabular->LeftLine(actcell, flag);
1839 for (int i = sel_row_start; i <= sel_row_end; ++i)
1840 for (int j = sel_col_start; j <= sel_col_end; ++j)
1841 tabular->SetLeftLine(
1842 tabular->GetCellNumber(i,j),
1845 updateLocal(bv, INIT, true);
1849 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1851 case LyXTabular::TOGGLE_LINE_RIGHT:
1853 bool lineSet = !tabular->RightLine(actcell, flag);
1854 for (int i = sel_row_start; i <= sel_row_end; ++i)
1855 for (int j = sel_col_start; j <= sel_col_end; ++j)
1856 tabular->SetRightLine(
1857 tabular->GetCellNumber(i,j),
1860 updateLocal(bv, INIT, true);
1864 case LyXTabular::M_ALIGN_LEFT:
1865 case LyXTabular::M_ALIGN_RIGHT:
1866 case LyXTabular::M_ALIGN_CENTER:
1868 case LyXTabular::ALIGN_LEFT:
1869 case LyXTabular::ALIGN_RIGHT:
1870 case LyXTabular::ALIGN_CENTER:
1871 for (int i = sel_row_start; i <= sel_row_end; ++i)
1872 for (int j = sel_col_start; j <= sel_col_end; ++j)
1873 tabular->SetAlignment(
1874 tabular->GetCellNumber(i, j),
1877 updateLocal(bv, INIT, true);
1879 case LyXTabular::M_VALIGN_TOP:
1880 case LyXTabular::M_VALIGN_BOTTOM:
1881 case LyXTabular::M_VALIGN_CENTER:
1883 case LyXTabular::VALIGN_TOP:
1884 case LyXTabular::VALIGN_BOTTOM:
1885 case LyXTabular::VALIGN_CENTER:
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->SetVAlignment(
1889 tabular->GetCellNumber(i, j),
1891 updateLocal(bv, INIT, true);
1893 case LyXTabular::MULTICOLUMN:
1895 if (sel_row_start != sel_row_end) {
1896 Alert::alert(_("Impossible Operation!"),
1897 _("Multicolumns can only be horizontally."),
1901 // just multicol for one Single Cell
1902 if (!hasSelection()) {
1903 // check wether we are completly in a multicol
1904 if (tabular->IsMultiColumn(actcell)) {
1905 tabular->UnsetMultiColumn(actcell);
1906 updateLocal(bv, INIT, true);
1908 tabular->SetMultiColumn(actcell, 1);
1909 updateLocal(bv, CELL, true);
1913 // we have a selection so this means we just add all this
1914 // cells to form a multicolumn cell
1918 if (sel_cell_start > sel_cell_end) {
1919 s_start = sel_cell_end;
1920 s_end = sel_cell_start;
1922 s_start = sel_cell_start;
1923 s_end = sel_cell_end;
1925 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1928 updateLocal(bv, INIT, true);
1931 case LyXTabular::SET_ALL_LINES:
1933 case LyXTabular::UNSET_ALL_LINES:
1934 for (int i = sel_row_start; i <= sel_row_end; ++i)
1935 for (int j = sel_col_start; j <= sel_col_end; ++j)
1936 tabular->SetAllLines(
1937 tabular->GetCellNumber(i,j), setLines);
1938 updateLocal(bv, INIT, true);
1940 case LyXTabular::SET_LONGTABULAR:
1941 tabular->SetLongTabular(true);
1942 updateLocal(bv, INIT, true); // because this toggles displayed
1944 case LyXTabular::UNSET_LONGTABULAR:
1945 tabular->SetLongTabular(false);
1946 updateLocal(bv, INIT, true); // because this toggles displayed
1948 case LyXTabular::SET_ROTATE_TABULAR:
1949 tabular->SetRotateTabular(true);
1951 case LyXTabular::UNSET_ROTATE_TABULAR:
1952 tabular->SetRotateTabular(false);
1954 case LyXTabular::SET_ROTATE_CELL:
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j<=sel_col_end; ++j)
1957 tabular->SetRotateCell(
1958 tabular->GetCellNumber(i, j),
1961 case LyXTabular::UNSET_ROTATE_CELL:
1962 for (int i = sel_row_start; i <= sel_row_end; ++i)
1963 for (int j = sel_col_start; j <= sel_col_end; ++j)
1964 tabular->SetRotateCell(
1965 tabular->GetCellNumber(i, j), false);
1967 case LyXTabular::SET_USEBOX:
1969 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1970 if (val == tabular->GetUsebox(actcell))
1971 val = LyXTabular::BOX_NONE;
1972 for (int i = sel_row_start; i <= sel_row_end; ++i)
1973 for (int j = sel_col_start; j <= sel_col_end; ++j)
1975 tabular->GetCellNumber(i, j), val);
1978 case LyXTabular::UNSET_LTFIRSTHEAD:
1980 case LyXTabular::SET_LTFIRSTHEAD:
1981 tabular->SetLTHead(ltt, true);
1983 case LyXTabular::UNSET_LTHEAD:
1985 case LyXTabular::SET_LTHEAD:
1986 tabular->SetLTHead(ltt, false);
1988 case LyXTabular::UNSET_LTFOOT:
1990 case LyXTabular::SET_LTFOOT:
1991 tabular->SetLTFoot(ltt, false);
1993 case LyXTabular::UNSET_LTLASTFOOT:
1995 case LyXTabular::SET_LTLASTFOOT:
1996 tabular->SetLTFoot(ltt, true);
1998 case LyXTabular::SET_LTNEWPAGE:
2000 bool what = !tabular->GetLTNewPage(actcell);
2001 tabular->SetLTNewPage(actcell, what);
2004 // dummy stuff just to avoid warnings
2005 case LyXTabular::LAST_ACTION:
2011 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2014 UpdatableInset * inset =
2015 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2016 LyXFont font(LyXFont::ALL_SANE);
2018 x = inset->x() + inset->width(bv, font);
2019 y = inset->descent(bv, font);
2021 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2022 //inset_y = cursor.y();
2023 inset->edit(bv, x, y, button);
2024 if (!the_locking_inset)
2026 updateLocal(bv, CELL, false);
2027 return (the_locking_inset != 0);
2031 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2034 inset_x = cursor_.x()
2035 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2036 inset_y = cursor_.y();
2037 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2041 bool InsetTabular::insetHit(BufferView *, int x, int) const
2044 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2048 // This returns paperWidth() if the cell-width is unlimited or the width
2049 // in pixels if we have a pwidth for this cell.
2050 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2052 LyXLength const len = tabular->GetPWidth(cell);
2056 #ifdef WITH_WARNINGS
2057 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2059 return VSpace(len).inPixels(bv);
2063 int InsetTabular::getMaxWidth(BufferView * bv,
2064 UpdatableInset const * inset) const
2066 int cell = tabular->cur_cell;
2067 if (tabular->GetCellInset(cell) != inset) {
2069 if (tabular->GetCellInset(cell) != inset) {
2071 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2076 int const n = tabular->GetNumberOfCells();
2079 for (cell = 0; cell < n; ++cell) {
2080 if (tabular->GetCellInset(cell) == inset)
2086 lyxerr << "Own inset not found, shouldn't really happen!\n";
2090 int w = getMaxWidthOfCell(bv, cell);
2092 // because the inset then subtracts it's top_x and owner->x()
2093 w += (inset->x() - top_x);
2100 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2102 resizeLyXText(bv, recursive);
2106 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2109 for(int i = 0; i < tabular->rows(); ++i) {
2110 for(int j = 0; j < tabular->columns(); ++j) {
2111 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2119 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2120 bool const recursive) const
2122 if (the_locking_inset)
2123 return the_locking_inset->getLyXText(bv, recursive);
2125 // if we're locked lock the actual insettext and return it's LyXText!!!
2127 UpdatableInset * inset =
2128 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2129 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2130 return the_locking_inset->getLyXText(bv, recursive);
2133 return Inset::getLyXText(bv, recursive);
2137 bool InsetTabular::showInsetDialog(BufferView * bv) const
2139 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2140 bv->owner()->getDialogs()
2141 ->showTabular(const_cast<InsetTabular *>(this));
2146 void InsetTabular::openLayoutDialog(BufferView * bv) const
2148 if (the_locking_inset) {
2149 InsetTabular * i = static_cast<InsetTabular *>
2150 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2152 i->openLayoutDialog(bv);
2156 bv->owner()->getDialogs()->showTabular(
2157 const_cast<InsetTabular *>(this));
2162 // functions returns:
2166 // 3 ... toggled off
2168 func_status::value_type InsetTabular::getStatus(string const & what) const
2170 int action = LyXTabular::LAST_ACTION;
2171 func_status::value_type status = func_status::OK;
2174 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2175 string const tmp = tabularFeature[i].feature;
2176 if (tmp == what.substr(0, tmp.length())) {
2177 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2178 // tabularFeatures[i].feature.length())) {
2179 action = tabularFeature[i].action;
2183 if (action == LyXTabular::LAST_ACTION)
2184 return func_status::Unknown;
2186 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2191 LyXTabular::ltType dummyltt;
2194 if (hasSelection()) {
2195 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2197 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2201 case LyXTabular::SET_PWIDTH:
2202 case LyXTabular::SET_MPWIDTH:
2203 case LyXTabular::SET_SPECIAL_COLUMN:
2204 case LyXTabular::SET_SPECIAL_MULTI:
2205 status |= func_status::Disabled;
2208 case LyXTabular::APPEND_ROW:
2209 case LyXTabular::APPEND_COLUMN:
2210 case LyXTabular::DELETE_ROW:
2211 case LyXTabular::DELETE_COLUMN:
2212 case LyXTabular::SET_ALL_LINES:
2213 case LyXTabular::UNSET_ALL_LINES:
2214 status |= func_status::OK;
2217 case LyXTabular::MULTICOLUMN:
2218 if (tabular->IsMultiColumn(actcell))
2219 status |= func_status::ToggleOn;
2221 status |= func_status::ToggleOff;
2223 case LyXTabular::M_TOGGLE_LINE_TOP:
2225 case LyXTabular::TOGGLE_LINE_TOP:
2226 if (tabular->TopLine(actcell, flag))
2227 status |= func_status::ToggleOn;
2229 status |= func_status::ToggleOff;
2231 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2233 case LyXTabular::TOGGLE_LINE_BOTTOM:
2234 if (tabular->BottomLine(actcell, flag))
2235 status |= func_status::ToggleOn;
2237 status |= func_status::ToggleOff;
2239 case LyXTabular::M_TOGGLE_LINE_LEFT:
2241 case LyXTabular::TOGGLE_LINE_LEFT:
2242 if (tabular->LeftLine(actcell, flag))
2243 status |= func_status::ToggleOn;
2245 status |= func_status::ToggleOff;
2247 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2249 case LyXTabular::TOGGLE_LINE_RIGHT:
2250 if (tabular->RightLine(actcell, flag))
2251 status |= func_status::ToggleOn;
2253 status |= func_status::ToggleOff;
2255 case LyXTabular::M_ALIGN_LEFT:
2257 case LyXTabular::ALIGN_LEFT:
2258 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2259 status |= func_status::ToggleOn;
2261 status |= func_status::ToggleOff;
2263 case LyXTabular::M_ALIGN_RIGHT:
2265 case LyXTabular::ALIGN_RIGHT:
2266 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2267 status |= func_status::ToggleOn;
2269 status |= func_status::ToggleOff;
2271 case LyXTabular::M_ALIGN_CENTER:
2273 case LyXTabular::ALIGN_CENTER:
2274 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2275 status |= func_status::ToggleOn;
2277 status |= func_status::ToggleOff;
2279 case LyXTabular::M_VALIGN_TOP:
2281 case LyXTabular::VALIGN_TOP:
2282 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2283 status |= func_status::ToggleOn;
2285 status |= func_status::ToggleOff;
2287 case LyXTabular::M_VALIGN_BOTTOM:
2289 case LyXTabular::VALIGN_BOTTOM:
2290 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2291 status |= func_status::ToggleOn;
2293 status |= func_status::ToggleOff;
2295 case LyXTabular::M_VALIGN_CENTER:
2297 case LyXTabular::VALIGN_CENTER:
2298 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2299 status |= func_status::ToggleOn;
2301 status |= func_status::ToggleOff;
2303 case LyXTabular::SET_LONGTABULAR:
2304 if (tabular->IsLongTabular())
2305 status |= func_status::ToggleOn;
2307 status |= func_status::ToggleOff;
2309 case LyXTabular::UNSET_LONGTABULAR:
2310 if (!tabular->IsLongTabular())
2311 status |= func_status::ToggleOn;
2313 status |= func_status::ToggleOff;
2315 case LyXTabular::SET_ROTATE_TABULAR:
2316 if (tabular->GetRotateTabular())
2317 status |= func_status::ToggleOn;
2319 status |= func_status::ToggleOff;
2321 case LyXTabular::UNSET_ROTATE_TABULAR:
2322 if (!tabular->GetRotateTabular())
2323 status |= func_status::ToggleOn;
2325 status |= func_status::ToggleOff;
2327 case LyXTabular::SET_ROTATE_CELL:
2328 if (tabular->GetRotateCell(actcell))
2329 status |= func_status::ToggleOn;
2331 status |= func_status::ToggleOff;
2333 case LyXTabular::UNSET_ROTATE_CELL:
2334 if (!tabular->GetRotateCell(actcell))
2335 status |= func_status::ToggleOn;
2337 status |= func_status::ToggleOff;
2339 case LyXTabular::SET_USEBOX:
2340 if (strToInt(argument) == tabular->GetUsebox(actcell))
2341 status |= func_status::ToggleOn;
2343 status |= func_status::ToggleOff;
2345 case LyXTabular::SET_LTFIRSTHEAD:
2346 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2347 status |= func_status::ToggleOn;
2349 status |= func_status::ToggleOff;
2351 case LyXTabular::SET_LTHEAD:
2352 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2353 status |= func_status::ToggleOn;
2355 status |= func_status::ToggleOff;
2357 case LyXTabular::SET_LTFOOT:
2358 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2359 status |= func_status::ToggleOn;
2361 status |= func_status::ToggleOff;
2363 case LyXTabular::SET_LTLASTFOOT:
2364 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2365 status |= func_status::ToggleOn;
2367 status |= func_status::ToggleOff;
2369 case LyXTabular::SET_LTNEWPAGE:
2370 if (tabular->GetLTNewPage(actcell))
2371 status |= func_status::ToggleOn;
2373 status |= func_status::ToggleOff;
2376 status = func_status::Disabled;
2383 std::vector<string> const InsetTabular::getLabelList() const
2385 return tabular->getLabelList();
2389 bool InsetTabular::copySelection(BufferView * bv)
2391 if (!hasSelection())
2394 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2395 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2396 if (sel_col_start > sel_col_end) {
2397 sel_col_start = sel_col_end;
2398 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2400 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2402 int const columns = sel_col_end - sel_col_start + 1;
2404 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2405 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2406 if (sel_row_start > sel_row_end) {
2407 swap(sel_row_start, sel_row_end);
2409 int const rows = sel_row_end - sel_row_start + 1;
2411 delete paste_tabular;
2412 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2413 for (int i = 0; i < sel_row_start; ++i)
2414 paste_tabular->DeleteRow(0);
2415 while (paste_tabular->rows() > rows)
2416 paste_tabular->DeleteRow(rows);
2417 paste_tabular->SetTopLine(0, true, true);
2418 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2420 for (int i = 0; i < sel_col_start; ++i)
2421 paste_tabular->DeleteColumn(0);
2422 while (paste_tabular->columns() > columns)
2423 paste_tabular->DeleteColumn(columns);
2424 paste_tabular->SetLeftLine(0, true, true);
2425 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2429 paste_tabular->Ascii(bv->buffer(), sstr);
2430 bv->stuffClipboard(sstr.str().c_str());
2435 bool InsetTabular::pasteSelection(BufferView * bv)
2440 for (int r1 = 0, r2 = actrow;
2441 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2443 for(int c1 = 0, c2 = actcol;
2444 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2446 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2447 tabular->IsPartOfMultiColumn(r2,c2))
2449 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2453 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2457 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2458 int const n2 = tabular->GetCellNumber(r2, c2);
2459 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2460 tabular->GetCellInset(n2)->setOwner(this);
2461 tabular->GetCellInset(n2)->deleteLyXText(bv);
2468 bool InsetTabular::cutSelection()
2470 if (!hasSelection())
2473 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2474 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2475 if (sel_col_start > sel_col_end) {
2476 sel_col_start = sel_col_end;
2477 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2479 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2481 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2482 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2483 if (sel_row_start > sel_row_end) {
2484 swap(sel_row_start, sel_row_end);
2486 if (sel_cell_start > sel_cell_end) {
2487 swap(sel_cell_start, sel_cell_end);
2489 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2490 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2491 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2498 bool InsetTabular::isRightToLeft(BufferView *bv )
2500 return bv->getParentLanguage(this)->RightToLeft();
2504 bool InsetTabular::nodraw() const
2506 if (!UpdatableInset::nodraw() && the_locking_inset)
2507 return the_locking_inset->nodraw();
2508 return UpdatableInset::nodraw();
2512 int InsetTabular::scroll(bool recursive) const
2514 int sx = UpdatableInset::scroll(false);
2516 if (recursive && the_locking_inset)
2517 sx += the_locking_inset->scroll(recursive);
2523 bool InsetTabular::doClearArea() const
2525 return !locked || (need_update & (FULL|INIT));
2529 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2531 int const start = hasSelection() ? sel_cell_start : actcell;
2532 int const end = hasSelection() ? sel_cell_end : actcell;
2534 srow = tabular->row_of_cell(start);
2535 erow = tabular->row_of_cell(end);
2540 scol = tabular->column_of_cell(start);
2541 ecol = tabular->column_of_cell(end);
2545 ecol = tabular->right_column_of_cell(end);
2550 Paragraph * InsetTabular::getParFromID(int id) const
2553 for(int i = 0; i < tabular->rows(); ++i) {
2554 for(int j = 0; j < tabular->columns(); ++j) {
2555 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2563 Paragraph * InsetTabular::firstParagraph() const
2565 if (the_locking_inset)
2566 return the_locking_inset->firstParagraph();
2571 Paragraph * InsetTabular::getFirstParagraph(int i) const
2573 return (i < tabular->GetNumberOfCells())
2574 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2579 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2581 if (the_locking_inset)
2582 return the_locking_inset->cursor(bv);
2583 return Inset::cursor(bv);
2587 Inset * InsetTabular::getInsetFromID(int id_arg) const
2590 return const_cast<InsetTabular *>(this);
2593 for(int i=0; i < tabular->rows(); ++i) {
2594 for(int j=0; j < tabular->columns(); ++j) {
2595 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2603 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2605 if (the_locking_inset) {
2606 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2609 if (tabular->IsLastCell(actcell)) {
2610 bv->unlockInset(const_cast<InsetTabular *>(this));
2616 // otherwise we have to lock the next inset and ask for it's selecttion
2617 UpdatableInset * inset =
2618 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2619 inset->edit(bv, 0, 0, 0);
2620 string const str(selectNextWordInt(bv, value));
2628 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2630 // when entering this function the inset should be ALWAYS locked!
2631 lyx::Assert(the_locking_inset);
2633 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2637 if (tabular->IsLastCell(actcell)) {
2638 bv->unlockInset(const_cast<InsetTabular *>(this));
2642 // otherwise we have to lock the next inset and ask for it's selecttion
2643 UpdatableInset * inset =
2644 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2646 return selectNextWordInt(bv, value);
2650 void InsetTabular::selectSelectedWord(BufferView * bv)
2652 if (the_locking_inset) {
2653 the_locking_inset->selectSelectedWord(bv);
2660 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2662 if (the_locking_inset) {
2663 the_locking_inset->toggleSelection(bv, kill_selection);
2668 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2669 bool const & cs, bool const & mw)
2671 if (the_locking_inset) {
2672 if (the_locking_inset->searchForward(bv, str, cs, mw))
2674 if (tabular->IsLastCell(actcell)) {
2675 bv->unlockInset(const_cast<InsetTabular *>(this));
2680 // otherwise we have to lock the next inset and search there
2681 UpdatableInset * inset =
2682 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2685 bool const res = searchForward(bv, str, cs, mw);
2686 updateLocal(bv, NONE, false);
2687 bv->updateInset(const_cast<InsetTabular *>(this), false);
2690 return searchForward(bv, str, cs, mw);
2695 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2696 bool const & cs, bool const & mw)
2698 if (the_locking_inset) {
2699 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2701 if (!actcell) { // we are already in the first cell
2702 bv->unlockInset(const_cast<InsetTabular *>(this));
2707 // otherwise we have to lock the next inset and search there
2708 UpdatableInset * inset =
2709 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2710 inset->edit(bv, false);
2712 bool const res = searchBackward(bv, str, cs, mw);
2713 bv->updateInset(const_cast<InsetTabular *>(this), false);
2716 return searchBackward(bv, str, cs, mw);
2721 bool InsetTabular::insetAllowed(Inset::Code code) const
2723 if (the_locking_inset)
2724 return the_locking_inset->insetAllowed(code);