1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
17 #include "insettabular.h"
20 #include "commandtags.h"
23 #include "LaTeXFeatures.h"
27 #include "lyx_gui_misc.h"
29 #include "insets/insettext.h"
34 #include "BufferView.h"
35 #include "undo_funcs.h"
36 #include "lyxlength.h"
37 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/Alert.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::VALIGN_TOP, "valign-top" },
87 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
88 { LyXTabular::VALIGN_CENTER, "valign-center" },
89 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
90 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
91 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
92 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
93 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
94 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
95 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
96 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
97 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
98 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
99 { LyXTabular::MULTICOLUMN, "multicolumn" },
100 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
101 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
102 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
103 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
104 { LyXTabular::SET_PWIDTH, "set-pwidth" },
105 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
106 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
107 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
108 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
109 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
110 { LyXTabular::SET_USEBOX, "set-usebox" },
111 { LyXTabular::SET_LTHEAD, "set-lthead" },
112 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
113 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
114 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
115 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
116 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
117 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
118 { LyXTabular::LAST_ACTION, "" }
124 bool InsetTabular::hasPasteBuffer() const
126 return (paste_tabular != 0);
130 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
137 tabular.reset(new LyXTabular(this, rows, columns));
138 // for now make it always display as display() inset
140 the_locking_inset = 0;
143 actrow = actcell = 0;
147 in_reset_pos = false;
151 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
153 : UpdatableInset(tab, same_id), buffer(&buf)
155 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
156 the_locking_inset = 0;
159 actrow = actcell = 0;
163 in_reset_pos = false;
167 InsetTabular::~InsetTabular()
173 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
175 return new InsetTabular(*this, buf, same_id);
179 void InsetTabular::write(Buffer const * buf, ostream & os) const
181 os << " Tabular" << endl;
182 tabular->Write(buf, os);
186 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
188 bool const old_format = (lex.getString() == "\\LyXTable");
190 tabular.reset(new LyXTabular(buf, this, lex));
198 string token = lex.getString();
199 while (lex.isOK() && (token != "\\end_inset")) {
201 token = lex.getString();
203 if (token != "\\end_inset") {
204 lex.printError("Missing \\end_inset at this point. "
210 int InsetTabular::ascent(BufferView *, LyXFont const &) const
212 return tabular->GetAscentOfRow(0);
216 int InsetTabular::descent(BufferView *, LyXFont const &) const
218 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
222 int InsetTabular::width(BufferView *, LyXFont const &) const
224 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
228 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
229 float & x, bool cleared) const
237 if (need_update == INIT) {
238 if (calculate_dimensions_of_cells(bv, font, true))
239 bv->text->status = LyXText::CHANGED_IN_DRAW;
244 Painter & pain = bv->painter();
250 UpdatableInset::draw(bv, font, baseline, x, cleared);
253 x += static_cast<float>(scroll());
255 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
256 (top_x != int(x)) || (top_baseline != baseline)))
258 int h = ascent(bv, font) + descent(bv, font);
259 int const tx = display() || !owner() ? 0 : top_x;
260 int w = tx ? width(bv, font) : pain.paperWidth();
261 int ty = baseline - ascent(bv, font);
265 if ((ty + h) > pain.paperHeight())
266 h = pain.paperHeight();
267 if ((top_x + w) > pain.paperWidth())
268 w = pain.paperWidth();
269 pain.fillRectangle(tx, ty, w, h, backgroundColor());
275 top_baseline = baseline;
276 x += ADD_TO_TABULAR_WIDTH;
280 first_visible_cell = -1;
281 for (i = 0; i < tabular->rows(); ++i) {
283 cell = tabular->GetCellNumber(i, 0);
284 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
285 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
287 baseline += tabular->GetDescentOfRow(i) +
288 tabular->GetAscentOfRow(i + 1) +
289 tabular->GetAdditionalHeight(i + 1);
292 for (j = 0; j < tabular->columns(); ++j) {
293 if (nx > bv->workWidth())
295 if (tabular->IsPartOfMultiColumn(i, j))
297 cx = nx + tabular->GetBeginningOfTextInCell(cell);
298 if (first_visible_cell < 0)
299 first_visible_cell = cell;
300 if (hasSelection()) {
301 drawCellSelection(pain, nx, baseline, i, j, cell);
304 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
305 drawCellLines(pain, nx, baseline, i, cell);
306 nx += tabular->GetWidthOfColumn(cell);
309 baseline += tabular->GetDescentOfRow(i) +
310 tabular->GetAscentOfRow(i + 1) +
311 tabular->GetAdditionalHeight(i + 1);
313 } else if (need_update == CELL) {
316 if (the_locking_inset &&
317 tabular->GetCellInset(actcell) != the_locking_inset)
319 Inset * inset = tabular->GetCellInset(cell);
321 inset != the_locking_inset && i < tabular->rows();
325 inset != the_locking_inset && j < tabular->columns();
328 if (tabular->IsPartOfMultiColumn(i, j))
330 nx += tabular->GetWidthOfColumn(cell);
332 inset = tabular->GetCellInset(cell);
334 if (tabular->row_of_cell(cell) > i) {
336 baseline += tabular->GetDescentOfRow(i) +
337 tabular->GetAscentOfRow(i + 1) +
338 tabular->GetAdditionalHeight(i + 1);
342 // compute baseline for actual row
343 for (i = 0; i < actrow; ++i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
348 // now compute the right x position
349 cell = tabular->GetCellNumber(actrow, 0);
350 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
351 if (tabular->IsPartOfMultiColumn(actrow, j))
353 nx += tabular->GetWidthOfColumn(cell);
357 i = tabular->row_of_cell(cell);
358 if (the_locking_inset != tabular->GetCellInset(cell)) {
359 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
362 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
364 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
365 // clear only if we didn't have a change
366 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
367 // clear before the inset
370 baseline - tabular->GetAscentOfRow(i) + 1,
372 tabular->GetAscentOfRow(i) +
373 tabular->GetDescentOfRow(i) - 1,
375 // clear behind the inset
377 int(cx + the_locking_inset->width(bv,font) + 1),
378 baseline - tabular->GetAscentOfRow(i) + 1,
379 tabular->GetWidthOfColumn(cell) -
380 tabular->GetBeginningOfTextInCell(cell) -
381 the_locking_inset->width(bv,font) -
382 tabular->GetAdditionalWidth(cell) - 1,
383 tabular->GetAscentOfRow(i) +
384 tabular->GetDescentOfRow(i) - 1,
386 // clear below the inset
389 baseline + the_locking_inset->descent(bv, font) + 1,
390 tabular->GetWidthOfColumn(cell) -
391 tabular->GetAdditionalWidth(cell) - 1,
392 tabular->GetAscentOfRow(i) +
393 tabular->GetDescentOfRow(i) -
394 the_locking_inset->ascent(bv, font) -
395 the_locking_inset->descent(bv, font) -
396 TEXT_TO_INSET_OFFSET - 1,
400 x -= ADD_TO_TABULAR_WIDTH;
401 x += width(bv, font);
402 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
404 for(Inset * inset = owner(); inset; ++i)
405 inset = inset->owner();
406 if (calculate_dimensions_of_cells(bv, font, false))
414 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
415 int row, int cell) const
417 int x2 = x + tabular->GetWidthOfColumn(cell);
420 if (!tabular->TopAlreadyDrawed(cell)) {
421 on_off = !tabular->TopLine(cell);
422 pain.line(x, baseline - tabular->GetAscentOfRow(row),
423 x2, baseline - tabular->GetAscentOfRow(row),
424 on_off ? LColor::tabularonoffline : LColor::tabularline,
425 on_off ? Painter::line_onoffdash : Painter::line_solid);
427 on_off = !tabular->BottomLine(cell);
428 pain.line(x,baseline + tabular->GetDescentOfRow(row),
429 x2, baseline + tabular->GetDescentOfRow(row),
430 on_off ? LColor::tabularonoffline : LColor::tabularline,
431 on_off ? Painter::line_onoffdash : Painter::line_solid);
432 if (!tabular->LeftAlreadyDrawed(cell)) {
433 on_off = !tabular->LeftLine(cell);
434 pain.line(x, baseline - tabular->GetAscentOfRow(row),
435 x, baseline + tabular->GetDescentOfRow(row),
436 on_off ? LColor::tabularonoffline : LColor::tabularline,
437 on_off ? Painter::line_onoffdash : Painter::line_solid);
439 on_off = !tabular->RightLine(cell);
440 pain.line(x2 - tabular->GetAdditionalWidth(cell),
441 baseline - tabular->GetAscentOfRow(row),
442 x2 - tabular->GetAdditionalWidth(cell),
443 baseline + tabular->GetDescentOfRow(row),
444 on_off ? LColor::tabularonoffline : LColor::tabularline,
445 on_off ? Painter::line_onoffdash : Painter::line_solid);
449 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
450 int row, int column, int cell) const
452 lyx::Assert(hasSelection());
453 int cs = tabular->column_of_cell(sel_cell_start);
454 int ce = tabular->column_of_cell(sel_cell_end);
457 cs = tabular->column_of_cell(sel_cell_end);
459 ce = tabular->right_column_of_cell(sel_cell_end);
462 int rs = tabular->row_of_cell(sel_cell_start);
463 int re = tabular->row_of_cell(sel_cell_end);
467 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
468 int w = tabular->GetWidthOfColumn(cell);
469 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
470 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
471 w, h, LColor::selection);
476 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
482 owner()->update(bv, font, true);
489 if (calculate_dimensions_of_cells(bv, font, true))
492 owner()->update(bv, font, true);
496 if (the_locking_inset)
497 the_locking_inset->update(bv, font, reinit);
498 if (need_update < FULL &&
499 bv->text->status() == LyXText::NEED_MORE_REFRESH)
504 switch (need_update) {
508 if (calculate_dimensions_of_cells(bv, font, false))
521 string const InsetTabular::editMessage() const
523 return _("Opened Tabular Inset");
527 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
529 UpdatableInset::edit(bv, x, y, button);
531 if (!bv->lockInset(this)) {
532 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
536 the_locking_inset = 0;
542 if (insetHit(bv, x, y) && (button != 3)) {
543 activateCellInsetAbs(bv, x, y, button);
548 void InsetTabular::edit(BufferView * bv, bool front)
550 UpdatableInset::edit(bv, front);
552 if (!bv->lockInset(this)) {
553 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
557 the_locking_inset = 0;
563 actcell = tabular->GetNumberOfCells() - 1;
570 void InsetTabular::insetUnlock(BufferView * bv)
572 if (the_locking_inset) {
573 the_locking_inset->insetUnlock(bv);
574 the_locking_inset = 0;
579 if (scroll(false) || hasSelection()) {
584 updateLocal(bv, FULL, false);
589 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
590 bool mark_dirty) const
594 calculate_dimensions_of_cells(bv, font, true);
596 if (need_update < what) // only set this if it has greater update
598 if ((what == INIT) && hasSelection()) {
602 if (need_update != NONE) {
603 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
604 if (locked) // && (what != NONE))
610 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
612 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
617 if (inset == tabular->GetCellInset(actcell)) {
618 lyxerr[Debug::INSETTEXT] << "OK" << endl;
619 the_locking_inset = tabular->GetCellInset(actcell);
622 } else if (!the_locking_inset) {
623 int const n = tabular->GetNumberOfCells();
624 int const id = inset->id();
625 for (int i = 0; i < n; ++i) {
626 InsetText * in = tabular->GetCellInset(i);
629 the_locking_inset = in;
634 if (in->getInsetFromID(id)) {
636 the_locking_inset = in;
639 return the_locking_inset->lockInsetInInset(bv, inset);
642 } else if (the_locking_inset && (the_locking_inset == inset)) {
643 lyxerr[Debug::INSETTEXT] << "OK" << endl;
645 } else if (the_locking_inset) {
646 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
647 return the_locking_inset->lockInsetInInset(bv, inset);
649 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
654 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
657 if (!the_locking_inset)
659 if (the_locking_inset == inset) {
660 the_locking_inset->insetUnlock(bv);
661 the_locking_inset = 0;
663 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
669 updateLocal(bv, CELL, false);
670 showInsetCursor(bv, false);
673 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
674 if (inset->lyxCode() == TABULAR_CODE &&
675 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
676 bv->owner()->getDialogs()->updateTabular(this);
685 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
687 if (!the_locking_inset)
689 if (the_locking_inset != inset) {
690 if (!the_locking_inset->updateInsetInInset(bv, inset))
693 updateLocal(bv, CELL, false);
698 unsigned int InsetTabular::insetInInsetY()
700 if (!the_locking_inset)
703 return inset_y + the_locking_inset->insetInInsetY();
707 UpdatableInset * InsetTabular::getLockingInset() const
709 return the_locking_inset ? the_locking_inset->getLockingInset() :
710 const_cast<InsetTabular *>(this);
714 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
718 if (the_locking_inset)
719 return the_locking_inset->getFirstLockingInsetOfType(c);
724 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
726 if (the_locking_inset)
727 return the_locking_inset->insertInset(bv, inset);
732 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
734 if (hasSelection() && (button == 3))
737 if (hasSelection()) {
739 updateLocal(bv, SELECTION, false);
742 int const ocell = actcell;
743 int const orow = actrow;
748 updateLocal(bv, NONE, false);
752 if ((ocell != actcell) && the_locking_inset) {
753 the_locking_inset->insetUnlock(bv);
754 the_locking_inset = 0;
761 bool const inset_hit = insetHit(bv, x, y);
763 if ((ocell == actcell) && the_locking_inset && inset_hit) {
765 the_locking_inset->insetButtonPress(bv,
766 x - inset_x, y - inset_y,
769 } else if (the_locking_inset) {
770 the_locking_inset->insetUnlock(bv);
772 the_locking_inset = 0;
774 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
777 if (inset_hit && bv->theLockingInset()) {
778 if (activateCellInsetAbs(bv, x, y, button))
779 the_locking_inset->insetButtonPress(bv,
789 bool InsetTabular::insetButtonRelease(BufferView * bv,
790 int x, int y, int button)
793 if (the_locking_inset)
794 ret = the_locking_inset->insetButtonRelease(bv, x, y, button);
795 if (button == 3 && !ret) {
796 bv->owner()->getDialogs()->showTabular(this);
803 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
805 if (the_locking_inset) {
806 the_locking_inset->insetMotionNotify(bv,
814 // int const old_cell = actcell;
817 if (!hasSelection()) {
818 setSelection(actcell, actcell);
820 setSelection(sel_cell_start, actcell);
822 updateLocal(bv, SELECTION, false);
827 void InsetTabular::insetKeyPress(XKeyEvent * xke)
829 if (the_locking_inset) {
830 the_locking_inset->insetKeyPress(xke);
836 UpdatableInset::RESULT
837 InsetTabular::localDispatch(BufferView * bv, kb_action action,
840 // We need to save the value of the_locking_inset as the call to
841 // the_locking_inset->LocalDispatch might unlock it.
842 old_locking_inset = the_locking_inset;
843 UpdatableInset::RESULT result =
844 UpdatableInset::localDispatch(bv, action, arg);
845 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
850 if ((action < 0) && arg.empty())
853 bool hs = hasSelection();
856 // this one have priority over the locked InsetText, if we're not already
857 // inside another tabular then that one get's priority!
858 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
863 unlockInsetInInset(bv, the_locking_inset);
864 if (action == LFUN_TAB)
865 moveNextCell(bv, old_locking_inset != 0);
867 movePrevCell(bv, old_locking_inset != 0);
870 updateLocal(bv, SELECTION, false);
871 if (!the_locking_inset) {
873 return DISPATCHED_NOUPDATE;
876 // this to avoid compiler warnings.
882 if (the_locking_inset) {
883 result = the_locking_inset->localDispatch(bv, action, arg);
884 if (result == DISPATCHED_NOUPDATE) {
887 if (sc != scroll()) { // inset has been scrolled
888 the_locking_inset->toggleInsetCursor(bv);
889 updateLocal(bv, FULL, false);
890 the_locking_inset->toggleInsetCursor(bv);
893 } else if (result == DISPATCHED) {
894 the_locking_inset->toggleInsetCursor(bv);
895 updateLocal(bv, CELL, false);
896 the_locking_inset->toggleInsetCursor(bv);
898 } else if (result == FINISHED_UP) {
900 } else if (result == FINISHED_DOWN) {
902 } else if (result == FINISHED_RIGHT) {
910 // --- Cursor Movements ----------------------------------
911 case LFUN_RIGHTSEL: {
912 int const start = hasSelection() ? sel_cell_start : actcell;
913 if (tabular->IsLastCellInRow(actcell)) {
914 setSelection(start, actcell);
919 // if we are starting a selection, only select
920 // the current cell at the beginning
921 if (hasSelection()) {
922 moveRight(bv, false);
925 setSelection(start, end);
926 updateLocal(bv, SELECTION, false);
930 result = moveRight(bv);
933 updateLocal(bv, SELECTION, false);
936 int const start = hasSelection() ? sel_cell_start : actcell;
937 if (tabular->IsFirstCellInRow(actcell)) {
938 setSelection(start, actcell);
943 // if we are starting a selection, only select
944 // the current cell at the beginning
945 if (hasSelection()) {
949 setSelection(start, end);
950 updateLocal(bv, SELECTION, false);
954 result = moveLeft(bv);
957 updateLocal(bv, SELECTION, false);
960 int const start = hasSelection() ? sel_cell_start : actcell;
961 int const ocell = actcell;
962 // if we are starting a selection, only select
963 // the current cell at the beginning
964 if (hasSelection()) {
966 if ((ocell == sel_cell_end) ||
967 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
968 setSelection(start, tabular->GetCellBelow(sel_cell_end));
970 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
972 setSelection(start, start);
974 updateLocal(bv, SELECTION, false);
978 result = moveDown(bv, old_locking_inset != 0);
981 updateLocal(bv, SELECTION, false);
985 int const start = hasSelection() ? sel_cell_start : actcell;
986 int const ocell = actcell;
987 // if we are starting a selection, only select
988 // the current cell at the beginning
989 if (hasSelection()) {
991 if ((ocell == sel_cell_end) ||
992 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
993 setSelection(start, tabular->GetCellAbove(sel_cell_end));
995 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
997 setSelection(start, start);
999 updateLocal(bv, SELECTION, false);
1003 result = moveUp(bv, old_locking_inset != 0);
1006 updateLocal(bv, SELECTION, false);
1009 int column = actcol;
1010 unlockInsetInInset(bv, the_locking_inset);
1011 if (bv->text->first + bv->painter().paperHeight() <
1012 (top_baseline + tabular->GetHeightOfTabular()))
1014 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1015 updateLocal(bv, FULL, false);
1016 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1018 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1021 updateLocal(bv, CURSOR, false);
1025 int column = actcol;
1026 unlockInsetInInset(bv, the_locking_inset);
1027 if (top_baseline < 0) {
1028 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1029 updateLocal(bv, FULL, false);
1030 if (top_baseline > 0)
1033 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1038 updateLocal(bv, CURSOR, false);
1041 // none of these make sense for insettabular,
1042 // but we must catch them to prevent any
1043 // selection from being confused
1047 case LFUN_WORDLEFTSEL:
1048 case LFUN_WORDRIGHT:
1049 case LFUN_WORDRIGHTSEL:
1050 case LFUN_DOWN_PARAGRAPH:
1051 case LFUN_DOWN_PARAGRAPHSEL:
1052 case LFUN_UP_PARAGRAPH:
1053 case LFUN_UP_PARAGRAPHSEL:
1054 case LFUN_BACKSPACE:
1061 case LFUN_LAYOUT_TABULAR:
1062 bv->owner()->getDialogs()->showTabular(this);
1064 case LFUN_TABULAR_FEATURE:
1065 if (!tabularFeatures(bv, arg))
1066 result = UNDISPATCHED;
1069 if (!copySelection(bv))
1071 setUndo(bv, Undo::DELETE,
1072 bv->text->cursor.par(),
1073 bv->text->cursor.par()->next());
1075 updateLocal(bv, INIT, true);
1078 if (!hasSelection())
1083 case LFUN_PASTESELECTION:
1085 string const clip(bv->getClipboard());
1089 if (clip.find('\t') != string::npos) {
1093 string::size_type len = clip.length();
1094 string::size_type p = 0;
1097 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1105 maxCols = max(cols, maxCols);
1111 maxCols = max(cols, maxCols);
1112 delete paste_tabular;
1113 paste_tabular = new LyXTabular(this, rows, maxCols);
1114 string::size_type op = 0;
1116 int cells = paste_tabular->GetNumberOfCells();
1118 while ((cell < cells) && (p < len) &&
1119 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1124 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1129 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1130 while (cols++ < maxCols)
1138 // check for the last cell if there is no trailing '\n'
1139 if ((cell < cells) && (op < len))
1140 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1142 // so that the clipboard is used and it goes on
1144 // and executes LFUN_PASTESELECTION in insettext!
1145 delete paste_tabular;
1150 if (hasPasteBuffer()) {
1151 setUndo(bv, Undo::INSERT,
1152 bv->text->cursor.par(),
1153 bv->text->cursor.par()->next());
1155 updateLocal(bv, INIT, true);
1158 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1160 // we try to activate the actual inset and put this event down to
1161 // the insets dispatch function.
1162 result = UNDISPATCHED;
1163 if (the_locking_inset)
1166 if (activateCellInset(bv)) {
1167 // reset need_update setted in above function!
1169 result = the_locking_inset->localDispatch(bv, action, arg);
1170 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1171 unlockInsetInInset(bv, the_locking_inset);
1173 // we need to update if this was requested before
1174 updateLocal(bv, NONE, false);
1175 return UNDISPATCHED;
1180 updateLocal(bv, CELL, false);
1185 if (result < FINISHED) {
1186 if (!the_locking_inset) {
1187 showInsetCursor(bv);
1190 bv->unlockInset(this);
1195 int InsetTabular::latex(Buffer const * buf, ostream & os,
1196 bool fragile, bool fp) const
1198 return tabular->latex(buf, os, fragile, fp);
1202 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1205 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1207 return tabular->ascii(buf, os, 0, false,0);
1211 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1213 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1217 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1222 // if the table is inside a float it doesn't need the informaltable
1223 // wrapper. Search for it.
1224 for(master = owner();
1225 master && master->lyxCode() != Inset::FLOAT_CODE;
1226 master = master->owner());
1229 os << "<informaltable>\n";
1232 ret+= tabular->docBook(buf,os);
1234 os << "</informaltable>\n";
1241 void InsetTabular::validate(LaTeXFeatures & features) const
1243 tabular->Validate(features);
1247 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1248 LyXFont const & font,
1255 bool changed = false;
1257 // if we have a locking_inset we should have to check only this cell for
1258 // change so I'll try this to have a boost, but who knows ;)
1259 if ((need_update != INIT) &&
1260 (the_locking_inset == tabular->GetCellInset(actcell))) {
1261 for(int i = 0; i < tabular->columns(); ++i) {
1262 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1264 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1267 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1268 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1269 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1272 for (int i = 0; i < tabular->rows(); ++i) {
1275 for (int j = 0; j < tabular->columns(); ++j) {
1276 if (tabular->IsPartOfMultiColumn(i,j))
1279 inset = tabular->GetCellInset(cell);
1280 if (!reinit && !tabular->GetPWidth(cell).zero())
1281 inset->update(bv, font, false);
1282 maxAsc = max(maxAsc, inset->ascent(bv, font));
1283 maxDesc = max(maxDesc, inset->descent(bv, font));
1284 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1286 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1287 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1295 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1297 if (the_locking_inset) {
1298 the_locking_inset->getCursorPos(bv, x, y);
1301 x = cursor_.x() - top_x;
1306 void InsetTabular::toggleInsetCursor(BufferView * bv)
1308 if (the_locking_inset) {
1309 the_locking_inset->toggleInsetCursor(bv);
1313 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1315 int const asc = lyxfont::maxAscent(font);
1316 int const desc = lyxfont::maxDescent(font);
1318 if (isCursorVisible())
1319 bv->hideLockedInsetCursor();
1321 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1322 toggleCursorVisible();
1326 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1328 if (!isCursorVisible()) {
1329 LyXFont font; // = GetFont(par, cursor.pos);
1331 int const asc = lyxfont::maxAscent(font);
1332 int const desc = lyxfont::maxDescent(font);
1333 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1335 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1336 setCursorVisible(true);
1341 void InsetTabular::hideInsetCursor(BufferView * bv)
1343 if (isCursorVisible()) {
1344 bv->hideLockedInsetCursor();
1345 setCursorVisible(false);
1350 void InsetTabular::fitInsetCursor(BufferView * bv) const
1352 if (the_locking_inset) {
1353 the_locking_inset->fitInsetCursor(bv);
1358 int const asc = lyxfont::maxAscent(font);
1359 int const desc = lyxfont::maxDescent(font);
1360 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1364 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1368 actcell = actrow = actcol = 0;
1369 int ly = tabular->GetDescentOfRow(actrow);
1371 // first search the right row
1372 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1373 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1374 tabular->GetAscentOfRow(actrow + 1) +
1375 tabular->GetAdditionalHeight(actrow + 1));
1377 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1379 actcell = tabular->GetCellNumber(actrow, actcol);
1381 // now search the right column
1382 int lx = tabular->GetWidthOfColumn(actcell) -
1383 tabular->GetAdditionalWidth(actcell);
1384 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1385 lx += tabular->GetWidthOfColumn(actcell + 1)
1386 + tabular->GetAdditionalWidth(actcell);
1388 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1393 int InsetTabular::getCellXPos(int cell) const
1397 for (; !tabular->IsFirstCellInRow(c); --c)
1399 int lx = tabular->GetWidthOfColumn(cell);
1400 for (; c < cell; ++c) {
1401 lx += tabular->GetWidthOfColumn(c);
1403 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1407 void InsetTabular::resetPos(BufferView * bv) const
1409 if (!locked || nodraw())
1411 #warning This should be fixed in the right manner (20011128 Jug)
1412 // fast hack to fix infinite repaintings!
1415 in_reset_pos = true;
1417 actcol = tabular->column_of_cell(actcell);
1422 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1423 if (tabular->IsLastCellInRow(cell)) {
1424 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1425 tabular->GetAscentOfRow(actrow + 1) +
1426 tabular->GetAdditionalHeight(actrow + 1));
1430 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1431 int new_x = getCellXPos(actcell);
1432 int old_x = cursor_.x();
1435 // cursor.x(getCellXPos(actcell) + offset);
1436 if ((actcol < tabular->columns()-1) && scroll(false) &&
1437 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1440 updateLocal(bv, FULL, false);
1441 } else if (the_locking_inset &&
1442 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1444 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1445 if (xx > (bv->workWidth()-20)) {
1446 scroll(bv, -(xx - bv->workWidth() + 60));
1447 updateLocal(bv, FULL, false);
1448 } else if (xx < 20) {
1454 updateLocal(bv, FULL, false);
1456 } else if ((cursor_.x() - offset) > 20 &&
1457 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1458 > (bv->workWidth() - 20)) {
1459 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1460 updateLocal(bv, FULL, false);
1461 } else if ((cursor_.x() - offset) < 20) {
1462 scroll(bv, 20 - cursor_.x() + offset);
1463 updateLocal(bv, FULL, false);
1464 } else if (scroll(false) && top_x > 20 &&
1465 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1466 scroll(bv, old_x - cursor_.x());
1467 updateLocal(bv, FULL, false);
1469 if (the_locking_inset) {
1470 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1471 inset_y = cursor_.y();
1473 if ((!the_locking_inset ||
1474 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1475 actcell != oldcell) {
1476 InsetTabular * inset = const_cast<InsetTabular *>(this);
1477 bv->owner()->getDialogs()->updateTabular(inset);
1480 in_reset_pos = false;
1484 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1486 if (lock && !old_locking_inset) {
1487 if (activateCellInset(bv))
1490 bool moved = isRightToLeft(bv)
1491 ? movePrevCell(bv) : moveNextCell(bv);
1493 return FINISHED_RIGHT;
1494 if (lock && activateCellInset(bv))
1498 return DISPATCHED_NOUPDATE;
1502 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1504 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1507 if (lock) { // behind the inset
1508 if (activateCellInset(bv, 0, 0, 0, true))
1512 return DISPATCHED_NOUPDATE;
1516 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1518 int const ocell = actcell;
1519 actcell = tabular->GetCellAbove(actcell);
1520 if (actcell == ocell) // we moved out of the inset
1526 if (old_locking_inset) {
1527 old_locking_inset->getCursorPos(bv, x, y);
1528 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1530 if (activateCellInset(bv, x, 0))
1533 return DISPATCHED_NOUPDATE;
1537 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1539 int const ocell = actcell;
1540 actcell = tabular->GetCellBelow(actcell);
1541 if (actcell == ocell) // we moved out of the inset
1542 return FINISHED_DOWN;
1547 if (old_locking_inset) {
1548 old_locking_inset->getCursorPos(bv, x, y);
1549 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1551 if (activateCellInset(bv, x, 0))
1554 return DISPATCHED_NOUPDATE;
1558 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1560 if (isRightToLeft(bv)) {
1561 if (tabular->IsFirstCellInRow(actcell)) {
1562 int row = tabular->row_of_cell(actcell);
1563 if (row == tabular->rows() - 1)
1565 actcell = tabular->GetLastCellInRow(row);
1566 actcell = tabular->GetCellBelow(actcell);
1573 if (tabular->IsLastCell(actcell))
1578 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1579 isRightToLeftPar(bv->buffer()->params);
1580 activateCellInset(bv, 0, 0, 0, !rtl);
1587 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1589 if (isRightToLeft(bv)) {
1590 if (tabular->IsLastCellInRow(actcell)) {
1591 int row = tabular->row_of_cell(actcell);
1594 actcell = tabular->GetFirstCellInRow(row);
1595 actcell = tabular->GetCellAbove(actcell);
1597 if (tabular->IsLastCell(actcell))
1602 if (!actcell) // first cell
1607 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1608 isRightToLeftPar(bv->buffer()->params);
1609 activateCellInset(bv, 0, 0, 0, !rtl);
1616 bool InsetTabular::deletable() const
1622 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1626 setSelection(0, tabular->GetNumberOfCells() - 1);
1628 if (hasSelection()) {
1629 setUndo(bv, Undo::EDIT,
1630 bv->text->cursor.par(),
1631 bv->text->cursor.par()->next());
1632 bool frozen = undo_frozen;
1635 // apply the fontchange on the whole selection
1640 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1641 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1642 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1643 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1648 updateLocal(bv, INIT, true);
1650 if (the_locking_inset)
1651 the_locking_inset->setFont(bv, font, tall);
1655 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1657 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1660 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1661 string const tmp = tabularFeature[i].feature;
1663 if (tmp == what.substr(0, tmp.length())) {
1664 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1665 //tabularFeatures[i].feature.length())) {
1666 action = tabularFeature[i].action;
1670 if (action == LyXTabular::LAST_ACTION)
1674 frontStrip(what.substr(tabularFeature[i].feature.length()));
1675 tabularFeatures(bv, action, val);
1679 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1680 string const & special, bool & flag)
1682 if (special == "dl_above") {
1685 } else if (special == "dl_below") {
1686 ltt.bottomDL = flag;
1688 } else if (special == "empty") {
1698 void InsetTabular::tabularFeatures(BufferView * bv,
1699 LyXTabular::Feature feature,
1700 string const & value)
1706 bool setLines = false;
1707 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1708 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1711 case LyXTabular::M_ALIGN_LEFT:
1712 case LyXTabular::ALIGN_LEFT:
1713 setAlign = LYX_ALIGN_LEFT;
1715 case LyXTabular::M_ALIGN_RIGHT:
1716 case LyXTabular::ALIGN_RIGHT:
1717 setAlign = LYX_ALIGN_RIGHT;
1719 case LyXTabular::M_ALIGN_CENTER:
1720 case LyXTabular::ALIGN_CENTER:
1721 setAlign = LYX_ALIGN_CENTER;
1723 case LyXTabular::M_VALIGN_TOP:
1724 case LyXTabular::VALIGN_TOP:
1725 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1727 case LyXTabular::M_VALIGN_BOTTOM:
1728 case LyXTabular::VALIGN_BOTTOM:
1729 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1731 case LyXTabular::M_VALIGN_CENTER:
1732 case LyXTabular::VALIGN_CENTER:
1733 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1738 if (hasSelection()) {
1739 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1741 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1742 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1744 setUndo(bv, Undo::FINISH,
1745 bv->text->cursor.par(),
1746 bv->text->cursor.par()->next());
1748 int row = tabular->row_of_cell(actcell);
1749 int column = tabular->column_of_cell(actcell);
1751 LyXTabular::ltType ltt;
1754 case LyXTabular::SET_PWIDTH:
1756 LyXLength const vallen(value);
1757 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1759 bool const update = (tmplen != vallen);
1760 tabular->SetColumnPWidth(actcell, vallen);
1763 for (int i = 0; i < tabular->rows(); ++i) {
1764 cell = tabular->GetCellNumber(i,column);
1765 tabular->GetCellInset(cell)->resizeLyXText(bv);
1767 updateLocal(bv, INIT, true);
1771 case LyXTabular::SET_MPWIDTH:
1773 LyXLength const vallen(value);
1774 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1776 bool const update = (tmplen != vallen);
1777 tabular->SetMColumnPWidth(actcell, vallen);
1779 for (int i = 0; i < tabular->rows(); ++i) {
1780 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1783 updateLocal(bv, INIT, true);
1787 case LyXTabular::SET_SPECIAL_COLUMN:
1788 case LyXTabular::SET_SPECIAL_MULTI:
1789 tabular->SetAlignSpecial(actcell,value,feature);
1790 updateLocal(bv, FULL, true);
1792 case LyXTabular::APPEND_ROW:
1793 // append the row into the tabular
1794 unlockInsetInInset(bv, the_locking_inset);
1795 tabular->AppendRow(actcell);
1796 updateLocal(bv, INIT, true);
1798 case LyXTabular::APPEND_COLUMN:
1799 // append the column into the tabular
1800 unlockInsetInInset(bv, the_locking_inset);
1801 tabular->AppendColumn(actcell);
1802 actcell = tabular->GetCellNumber(row, column);
1803 updateLocal(bv, INIT, true);
1805 case LyXTabular::DELETE_ROW:
1806 unlockInsetInInset(bv, the_locking_inset);
1807 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1808 tabular->DeleteRow(sel_row_start);
1810 if (sel_row_start >= tabular->rows())
1812 actcell = tabular->GetCellNumber(sel_row_start, column);
1814 updateLocal(bv, INIT, true);
1816 case LyXTabular::DELETE_COLUMN:
1817 unlockInsetInInset(bv, the_locking_inset);
1818 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1819 tabular->DeleteColumn(sel_col_start);
1821 if (sel_col_start >= tabular->columns())
1823 actcell = tabular->GetCellNumber(row, sel_col_start);
1825 updateLocal(bv, INIT, true);
1827 case LyXTabular::M_TOGGLE_LINE_TOP:
1829 case LyXTabular::TOGGLE_LINE_TOP:
1831 bool lineSet = !tabular->TopLine(actcell, flag);
1832 for (int i = sel_row_start; i <= sel_row_end; ++i)
1833 for (int j = sel_col_start; j <= sel_col_end; ++j)
1834 tabular->SetTopLine(
1835 tabular->GetCellNumber(i, j),
1837 updateLocal(bv, INIT, true);
1841 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1843 case LyXTabular::TOGGLE_LINE_BOTTOM:
1845 bool lineSet = !tabular->BottomLine(actcell, flag);
1846 for (int i = sel_row_start; i <= sel_row_end; ++i)
1847 for (int j = sel_col_start; j <= sel_col_end; ++j)
1848 tabular->SetBottomLine(
1849 tabular->GetCellNumber(i, j),
1852 updateLocal(bv, INIT, true);
1856 case LyXTabular::M_TOGGLE_LINE_LEFT:
1858 case LyXTabular::TOGGLE_LINE_LEFT:
1860 bool lineSet = !tabular->LeftLine(actcell, flag);
1861 for (int i = sel_row_start; i <= sel_row_end; ++i)
1862 for (int j = sel_col_start; j <= sel_col_end; ++j)
1863 tabular->SetLeftLine(
1864 tabular->GetCellNumber(i,j),
1867 updateLocal(bv, INIT, true);
1871 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1873 case LyXTabular::TOGGLE_LINE_RIGHT:
1875 bool lineSet = !tabular->RightLine(actcell, flag);
1876 for (int i = sel_row_start; i <= sel_row_end; ++i)
1877 for (int j = sel_col_start; j <= sel_col_end; ++j)
1878 tabular->SetRightLine(
1879 tabular->GetCellNumber(i,j),
1882 updateLocal(bv, INIT, true);
1886 case LyXTabular::M_ALIGN_LEFT:
1887 case LyXTabular::M_ALIGN_RIGHT:
1888 case LyXTabular::M_ALIGN_CENTER:
1890 case LyXTabular::ALIGN_LEFT:
1891 case LyXTabular::ALIGN_RIGHT:
1892 case LyXTabular::ALIGN_CENTER:
1893 for (int i = sel_row_start; i <= sel_row_end; ++i)
1894 for (int j = sel_col_start; j <= sel_col_end; ++j)
1895 tabular->SetAlignment(
1896 tabular->GetCellNumber(i, j),
1899 updateLocal(bv, INIT, true);
1901 case LyXTabular::M_VALIGN_TOP:
1902 case LyXTabular::M_VALIGN_BOTTOM:
1903 case LyXTabular::M_VALIGN_CENTER:
1905 case LyXTabular::VALIGN_TOP:
1906 case LyXTabular::VALIGN_BOTTOM:
1907 case LyXTabular::VALIGN_CENTER:
1908 for (int i = sel_row_start; i <= sel_row_end; ++i)
1909 for (int j = sel_col_start; j <= sel_col_end; ++j)
1910 tabular->SetVAlignment(
1911 tabular->GetCellNumber(i, j),
1913 updateLocal(bv, INIT, true);
1915 case LyXTabular::MULTICOLUMN:
1917 if (sel_row_start != sel_row_end) {
1918 Alert::alert(_("Impossible Operation!"),
1919 _("Multicolumns can only be horizontally."),
1923 // just multicol for one Single Cell
1924 if (!hasSelection()) {
1925 // check wether we are completly in a multicol
1926 if (tabular->IsMultiColumn(actcell)) {
1927 tabular->UnsetMultiColumn(actcell);
1928 updateLocal(bv, INIT, true);
1930 tabular->SetMultiColumn(actcell, 1);
1931 updateLocal(bv, CELL, true);
1935 // we have a selection so this means we just add all this
1936 // cells to form a multicolumn cell
1940 if (sel_cell_start > sel_cell_end) {
1941 s_start = sel_cell_end;
1942 s_end = sel_cell_start;
1944 s_start = sel_cell_start;
1945 s_end = sel_cell_end;
1947 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1950 updateLocal(bv, INIT, true);
1953 case LyXTabular::SET_ALL_LINES:
1955 case LyXTabular::UNSET_ALL_LINES:
1956 for (int i = sel_row_start; i <= sel_row_end; ++i)
1957 for (int j = sel_col_start; j <= sel_col_end; ++j)
1958 tabular->SetAllLines(
1959 tabular->GetCellNumber(i,j), setLines);
1960 updateLocal(bv, INIT, true);
1962 case LyXTabular::SET_LONGTABULAR:
1963 tabular->SetLongTabular(true);
1964 updateLocal(bv, INIT, true); // because this toggles displayed
1966 case LyXTabular::UNSET_LONGTABULAR:
1967 tabular->SetLongTabular(false);
1968 updateLocal(bv, INIT, true); // because this toggles displayed
1970 case LyXTabular::SET_ROTATE_TABULAR:
1971 tabular->SetRotateTabular(true);
1973 case LyXTabular::UNSET_ROTATE_TABULAR:
1974 tabular->SetRotateTabular(false);
1976 case LyXTabular::SET_ROTATE_CELL:
1977 for (int i = sel_row_start; i <= sel_row_end; ++i)
1978 for (int j = sel_col_start; j<=sel_col_end; ++j)
1979 tabular->SetRotateCell(
1980 tabular->GetCellNumber(i, j),
1983 case LyXTabular::UNSET_ROTATE_CELL:
1984 for (int i = sel_row_start; i <= sel_row_end; ++i)
1985 for (int j = sel_col_start; j <= sel_col_end; ++j)
1986 tabular->SetRotateCell(
1987 tabular->GetCellNumber(i, j), false);
1989 case LyXTabular::SET_USEBOX:
1991 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1992 if (val == tabular->GetUsebox(actcell))
1993 val = LyXTabular::BOX_NONE;
1994 for (int i = sel_row_start; i <= sel_row_end; ++i)
1995 for (int j = sel_col_start; j <= sel_col_end; ++j)
1997 tabular->GetCellNumber(i, j), val);
2000 case LyXTabular::UNSET_LTFIRSTHEAD:
2002 case LyXTabular::SET_LTFIRSTHEAD:
2003 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2004 checkLongtableSpecial(ltt, value, flag);
2005 tabular->SetLTHead(row, flag, ltt, true);
2007 case LyXTabular::UNSET_LTHEAD:
2009 case LyXTabular::SET_LTHEAD:
2010 (void)tabular->GetRowOfLTHead(row, ltt);
2011 checkLongtableSpecial(ltt, value, flag);
2012 tabular->SetLTHead(row, flag, ltt, false);
2014 case LyXTabular::UNSET_LTFOOT:
2016 case LyXTabular::SET_LTFOOT:
2017 (void)tabular->GetRowOfLTFoot(row, ltt);
2018 checkLongtableSpecial(ltt, value, flag);
2019 tabular->SetLTFoot(row, flag, ltt, false);
2021 case LyXTabular::UNSET_LTLASTFOOT:
2023 case LyXTabular::SET_LTLASTFOOT:
2024 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2025 checkLongtableSpecial(ltt, value, flag);
2026 tabular->SetLTFoot(row, flag, ltt, true);
2028 case LyXTabular::SET_LTNEWPAGE:
2030 bool what = !tabular->GetLTNewPage(row);
2031 tabular->SetLTNewPage(row, what);
2034 // dummy stuff just to avoid warnings
2035 case LyXTabular::LAST_ACTION:
2041 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2044 UpdatableInset * inset =
2045 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2046 LyXFont font(LyXFont::ALL_SANE);
2048 x = inset->x() + inset->width(bv, font);
2049 y = inset->descent(bv, font);
2051 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2052 //inset_y = cursor.y();
2053 inset->edit(bv, x, y, button);
2054 if (!the_locking_inset)
2056 updateLocal(bv, CELL, false);
2057 return (the_locking_inset != 0);
2061 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2064 inset_x = cursor_.x()
2065 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2066 inset_y = cursor_.y();
2067 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2071 bool InsetTabular::insetHit(BufferView *, int x, int) const
2074 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2078 // This returns paperWidth() if the cell-width is unlimited or the width
2079 // in pixels if we have a pwidth for this cell.
2080 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2082 LyXLength const len = tabular->GetPWidth(cell);
2086 #ifdef WITH_WARNINGS
2087 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2089 return VSpace(len).inPixels(bv);
2093 int InsetTabular::getMaxWidth(BufferView * bv,
2094 UpdatableInset const * inset) const
2096 int cell = tabular->cur_cell;
2097 if (tabular->GetCellInset(cell) != inset) {
2099 if (tabular->GetCellInset(cell) != inset) {
2101 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2106 int const n = tabular->GetNumberOfCells();
2109 for (cell = 0; cell < n; ++cell) {
2110 if (tabular->GetCellInset(cell) == inset)
2116 lyxerr << "Own inset not found, shouldn't really happen!\n";
2120 int w = getMaxWidthOfCell(bv, cell);
2122 // because the inset then subtracts it's top_x and owner->x()
2123 w += (inset->x() - top_x);
2130 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2132 resizeLyXText(bv, recursive);
2136 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2139 for(int i = 0; i < tabular->rows(); ++i) {
2140 for(int j = 0; j < tabular->columns(); ++j) {
2141 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2149 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2150 bool const recursive) const
2152 if (the_locking_inset)
2153 return the_locking_inset->getLyXText(bv, recursive);
2155 // if we're locked lock the actual insettext and return it's LyXText!!!
2157 UpdatableInset * inset =
2158 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2159 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2160 return the_locking_inset->getLyXText(bv, recursive);
2163 return Inset::getLyXText(bv, recursive);
2167 bool InsetTabular::showInsetDialog(BufferView * bv) const
2169 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2170 bv->owner()->getDialogs()
2171 ->showTabular(const_cast<InsetTabular *>(this));
2176 void InsetTabular::openLayoutDialog(BufferView * bv) const
2178 if (the_locking_inset) {
2179 InsetTabular * i = static_cast<InsetTabular *>
2180 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2182 i->openLayoutDialog(bv);
2186 bv->owner()->getDialogs()->showTabular(
2187 const_cast<InsetTabular *>(this));
2192 // functions returns:
2196 // 3 ... toggled off
2198 func_status::value_type InsetTabular::getStatus(string const & what) const
2200 int action = LyXTabular::LAST_ACTION;
2201 func_status::value_type status = func_status::OK;
2204 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2205 string const tmp = tabularFeature[i].feature;
2206 if (tmp == what.substr(0, tmp.length())) {
2207 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2208 // tabularFeatures[i].feature.length())) {
2209 action = tabularFeature[i].action;
2213 if (action == LyXTabular::LAST_ACTION)
2214 return func_status::Unknown;
2216 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2221 LyXTabular::ltType dummyltt;
2224 if (hasSelection()) {
2225 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2227 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2231 case LyXTabular::SET_PWIDTH:
2232 case LyXTabular::SET_MPWIDTH:
2233 case LyXTabular::SET_SPECIAL_COLUMN:
2234 case LyXTabular::SET_SPECIAL_MULTI:
2235 status |= func_status::Disabled;
2238 case LyXTabular::APPEND_ROW:
2239 case LyXTabular::APPEND_COLUMN:
2240 case LyXTabular::DELETE_ROW:
2241 case LyXTabular::DELETE_COLUMN:
2242 case LyXTabular::SET_ALL_LINES:
2243 case LyXTabular::UNSET_ALL_LINES:
2244 status |= func_status::OK;
2247 case LyXTabular::MULTICOLUMN:
2248 if (tabular->IsMultiColumn(actcell))
2249 status |= func_status::ToggleOn;
2251 status |= func_status::ToggleOff;
2253 case LyXTabular::M_TOGGLE_LINE_TOP:
2255 case LyXTabular::TOGGLE_LINE_TOP:
2256 if (tabular->TopLine(actcell, flag))
2257 status |= func_status::ToggleOn;
2259 status |= func_status::ToggleOff;
2261 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2263 case LyXTabular::TOGGLE_LINE_BOTTOM:
2264 if (tabular->BottomLine(actcell, flag))
2265 status |= func_status::ToggleOn;
2267 status |= func_status::ToggleOff;
2269 case LyXTabular::M_TOGGLE_LINE_LEFT:
2271 case LyXTabular::TOGGLE_LINE_LEFT:
2272 if (tabular->LeftLine(actcell, flag))
2273 status |= func_status::ToggleOn;
2275 status |= func_status::ToggleOff;
2277 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2279 case LyXTabular::TOGGLE_LINE_RIGHT:
2280 if (tabular->RightLine(actcell, flag))
2281 status |= func_status::ToggleOn;
2283 status |= func_status::ToggleOff;
2285 case LyXTabular::M_ALIGN_LEFT:
2287 case LyXTabular::ALIGN_LEFT:
2288 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2289 status |= func_status::ToggleOn;
2291 status |= func_status::ToggleOff;
2293 case LyXTabular::M_ALIGN_RIGHT:
2295 case LyXTabular::ALIGN_RIGHT:
2296 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2297 status |= func_status::ToggleOn;
2299 status |= func_status::ToggleOff;
2301 case LyXTabular::M_ALIGN_CENTER:
2303 case LyXTabular::ALIGN_CENTER:
2304 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2305 status |= func_status::ToggleOn;
2307 status |= func_status::ToggleOff;
2309 case LyXTabular::M_VALIGN_TOP:
2311 case LyXTabular::VALIGN_TOP:
2312 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2313 status |= func_status::ToggleOn;
2315 status |= func_status::ToggleOff;
2317 case LyXTabular::M_VALIGN_BOTTOM:
2319 case LyXTabular::VALIGN_BOTTOM:
2320 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2321 status |= func_status::ToggleOn;
2323 status |= func_status::ToggleOff;
2325 case LyXTabular::M_VALIGN_CENTER:
2327 case LyXTabular::VALIGN_CENTER:
2328 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2329 status |= func_status::ToggleOn;
2331 status |= func_status::ToggleOff;
2333 case LyXTabular::SET_LONGTABULAR:
2334 if (tabular->IsLongTabular())
2335 status |= func_status::ToggleOn;
2337 status |= func_status::ToggleOff;
2339 case LyXTabular::UNSET_LONGTABULAR:
2340 if (!tabular->IsLongTabular())
2341 status |= func_status::ToggleOn;
2343 status |= func_status::ToggleOff;
2345 case LyXTabular::SET_ROTATE_TABULAR:
2346 if (tabular->GetRotateTabular())
2347 status |= func_status::ToggleOn;
2349 status |= func_status::ToggleOff;
2351 case LyXTabular::UNSET_ROTATE_TABULAR:
2352 if (!tabular->GetRotateTabular())
2353 status |= func_status::ToggleOn;
2355 status |= func_status::ToggleOff;
2357 case LyXTabular::SET_ROTATE_CELL:
2358 if (tabular->GetRotateCell(actcell))
2359 status |= func_status::ToggleOn;
2361 status |= func_status::ToggleOff;
2363 case LyXTabular::UNSET_ROTATE_CELL:
2364 if (!tabular->GetRotateCell(actcell))
2365 status |= func_status::ToggleOn;
2367 status |= func_status::ToggleOff;
2369 case LyXTabular::SET_USEBOX:
2370 if (strToInt(argument) == tabular->GetUsebox(actcell))
2371 status |= func_status::ToggleOn;
2373 status |= func_status::ToggleOff;
2375 case LyXTabular::SET_LTFIRSTHEAD:
2376 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2377 status |= func_status::ToggleOn;
2379 status |= func_status::ToggleOff;
2381 case LyXTabular::SET_LTHEAD:
2382 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2383 status |= func_status::ToggleOn;
2385 status |= func_status::ToggleOff;
2387 case LyXTabular::SET_LTFOOT:
2388 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2389 status |= func_status::ToggleOn;
2391 status |= func_status::ToggleOff;
2393 case LyXTabular::SET_LTLASTFOOT:
2394 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2395 status |= func_status::ToggleOn;
2397 status |= func_status::ToggleOff;
2399 case LyXTabular::SET_LTNEWPAGE:
2400 if (tabular->GetLTNewPage(sel_row_start))
2401 status |= func_status::ToggleOn;
2403 status |= func_status::ToggleOff;
2406 status = func_status::Disabled;
2413 std::vector<string> const InsetTabular::getLabelList() const
2415 return tabular->getLabelList();
2419 bool InsetTabular::copySelection(BufferView * bv)
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 const columns = sel_col_end - sel_col_start + 1;
2434 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2435 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2436 if (sel_row_start > sel_row_end) {
2437 swap(sel_row_start, sel_row_end);
2439 int const rows = sel_row_end - sel_row_start + 1;
2441 delete paste_tabular;
2442 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2443 for (int i = 0; i < sel_row_start; ++i)
2444 paste_tabular->DeleteRow(0);
2445 while (paste_tabular->rows() > rows)
2446 paste_tabular->DeleteRow(rows);
2447 paste_tabular->SetTopLine(0, true, true);
2448 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2450 for (int i = 0; i < sel_col_start; ++i)
2451 paste_tabular->DeleteColumn(0);
2452 while (paste_tabular->columns() > columns)
2453 paste_tabular->DeleteColumn(columns);
2454 paste_tabular->SetLeftLine(0, true, true);
2455 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2459 paste_tabular->ascii(bv->buffer(), sstr,
2460 (int)parOwner()->params().depth(), true, '\t');
2461 bv->stuffClipboard(sstr.str().c_str());
2466 bool InsetTabular::pasteSelection(BufferView * bv)
2471 for (int r1 = 0, r2 = actrow;
2472 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2474 for(int c1 = 0, c2 = actcol;
2475 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2477 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2478 tabular->IsPartOfMultiColumn(r2,c2))
2480 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2484 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2488 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2489 int const n2 = tabular->GetCellNumber(r2, c2);
2490 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2491 tabular->GetCellInset(n2)->setOwner(this);
2492 tabular->GetCellInset(n2)->deleteLyXText(bv);
2499 bool InsetTabular::cutSelection()
2501 if (!hasSelection())
2504 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2505 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2506 if (sel_col_start > sel_col_end) {
2507 sel_col_start = sel_col_end;
2508 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2510 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2512 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2513 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2514 if (sel_row_start > sel_row_end) {
2515 swap(sel_row_start, sel_row_end);
2517 if (sel_cell_start > sel_cell_end) {
2518 swap(sel_cell_start, sel_cell_end);
2520 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2521 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2522 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2529 bool InsetTabular::isRightToLeft(BufferView *bv )
2531 return bv->getParentLanguage(this)->RightToLeft();
2535 bool InsetTabular::nodraw() const
2537 if (!UpdatableInset::nodraw() && the_locking_inset)
2538 return the_locking_inset->nodraw();
2539 return UpdatableInset::nodraw();
2543 int InsetTabular::scroll(bool recursive) const
2545 int sx = UpdatableInset::scroll(false);
2547 if (recursive && the_locking_inset)
2548 sx += the_locking_inset->scroll(recursive);
2554 bool InsetTabular::doClearArea() const
2556 return !locked || (need_update & (FULL|INIT));
2560 void InsetTabular::getSelection(int & srow, int & erow,
2561 int & scol, int & ecol) const
2563 int const start = hasSelection() ? sel_cell_start : actcell;
2564 int const end = hasSelection() ? sel_cell_end : actcell;
2566 srow = tabular->row_of_cell(start);
2567 erow = tabular->row_of_cell(end);
2572 scol = tabular->column_of_cell(start);
2573 ecol = tabular->column_of_cell(end);
2577 ecol = tabular->right_column_of_cell(end);
2582 Paragraph * InsetTabular::getParFromID(int id) const
2585 for(int i = 0; i < tabular->rows(); ++i) {
2586 for(int j = 0; j < tabular->columns(); ++j) {
2587 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2595 Paragraph * InsetTabular::firstParagraph() const
2597 if (the_locking_inset)
2598 return the_locking_inset->firstParagraph();
2603 Paragraph * InsetTabular::getFirstParagraph(int i) const
2605 return (i < tabular->GetNumberOfCells())
2606 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2611 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2613 if (the_locking_inset)
2614 return the_locking_inset->cursor(bv);
2615 return Inset::cursor(bv);
2619 Inset * InsetTabular::getInsetFromID(int id_arg) const
2622 return const_cast<InsetTabular *>(this);
2625 for(int i = 0; i < tabular->rows(); ++i) {
2626 for(int j = 0; j < tabular->columns(); ++j) {
2627 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2636 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2638 if (the_locking_inset) {
2639 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2642 if (tabular->IsLastCell(actcell)) {
2643 bv->unlockInset(const_cast<InsetTabular *>(this));
2649 // otherwise we have to lock the next inset and ask for it's selecttion
2650 UpdatableInset * inset =
2651 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2652 inset->edit(bv, 0, 0, 0);
2653 string const str(selectNextWordInt(bv, value));
2661 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2663 // when entering this function the inset should be ALWAYS locked!
2664 lyx::Assert(the_locking_inset);
2666 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2670 if (tabular->IsLastCell(actcell)) {
2671 bv->unlockInset(const_cast<InsetTabular *>(this));
2675 // otherwise we have to lock the next inset and ask for it's selecttion
2676 UpdatableInset * inset =
2677 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2679 return selectNextWordInt(bv, value);
2683 void InsetTabular::selectSelectedWord(BufferView * bv)
2685 if (the_locking_inset) {
2686 the_locking_inset->selectSelectedWord(bv);
2693 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2695 if (the_locking_inset) {
2696 the_locking_inset->toggleSelection(bv, kill_selection);
2701 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2702 bool const & cs, bool const & mw)
2704 if (the_locking_inset) {
2705 if (the_locking_inset->searchForward(bv, str, cs, mw))
2707 if (tabular->IsLastCell(actcell)) {
2708 bv->unlockInset(const_cast<InsetTabular *>(this));
2713 // otherwise we have to lock the next inset and search there
2714 UpdatableInset * inset =
2715 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2718 bool const res = searchForward(bv, str, cs, mw);
2719 updateLocal(bv, NONE, false);
2720 bv->updateInset(const_cast<InsetTabular *>(this), false);
2723 return searchForward(bv, str, cs, mw);
2728 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2729 bool const & cs, bool const & mw)
2731 if (the_locking_inset) {
2732 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2734 if (!actcell) { // we are already in the first cell
2735 bv->unlockInset(const_cast<InsetTabular *>(this));
2740 // otherwise we have to lock the next inset and search there
2741 UpdatableInset * inset =
2742 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2743 inset->edit(bv, false);
2745 bool const res = searchBackward(bv, str, cs, mw);
2746 bv->updateInset(const_cast<InsetTabular *>(this), false);
2749 return searchBackward(bv, str, cs, mw);
2754 bool InsetTabular::insetAllowed(Inset::Code code) const
2756 if (the_locking_inset)
2757 return the_locking_inset->insetAllowed(code);