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()) {
967 if ((ocell == sel_cell_end) ||
968 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
969 setSelection(start, tabular->GetCellBelow(sel_cell_end));
971 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
972 updateLocal(bv, SELECTION, false);
976 result = moveDown(bv, old_locking_inset != 0);
979 updateLocal(bv, SELECTION, false);
983 int const start = hasSelection() ? sel_cell_start : actcell;
984 int const ocell = actcell;
985 // if we are starting a selection, only select
986 // the current cell at the beginning
987 if (hasSelection()) {
990 if ((ocell == sel_cell_end) ||
991 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
992 setSelection(start, tabular->GetCellAbove(sel_cell_end));
994 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
995 updateLocal(bv, SELECTION, false);
999 result = moveUp(bv, old_locking_inset != 0);
1002 updateLocal(bv, SELECTION, false);
1005 int column = actcol;
1006 unlockInsetInInset(bv, the_locking_inset);
1007 if (bv->text->first + bv->painter().paperHeight() <
1008 (top_baseline + tabular->GetHeightOfTabular()))
1010 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1011 updateLocal(bv, FULL, false);
1012 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1014 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1017 updateLocal(bv, CURSOR, false);
1021 int column = actcol;
1022 unlockInsetInInset(bv, the_locking_inset);
1023 if (top_baseline < 0) {
1024 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1025 updateLocal(bv, FULL, false);
1026 if (top_baseline > 0)
1029 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1034 updateLocal(bv, CURSOR, false);
1037 // none of these make sense for insettabular,
1038 // but we must catch them to prevent any
1039 // selection from being confused
1043 case LFUN_WORDLEFTSEL:
1044 case LFUN_WORDRIGHT:
1045 case LFUN_WORDRIGHTSEL:
1046 case LFUN_DOWN_PARAGRAPH:
1047 case LFUN_DOWN_PARAGRAPHSEL:
1048 case LFUN_UP_PARAGRAPH:
1049 case LFUN_UP_PARAGRAPHSEL:
1050 case LFUN_BACKSPACE:
1057 case LFUN_LAYOUT_TABULAR:
1058 bv->owner()->getDialogs()->showTabular(this);
1060 case LFUN_TABULAR_FEATURE:
1061 if (!tabularFeatures(bv, arg))
1062 result = UNDISPATCHED;
1065 if (!copySelection(bv))
1067 setUndo(bv, Undo::DELETE,
1068 bv->text->cursor.par(),
1069 bv->text->cursor.par()->next());
1071 updateLocal(bv, INIT, true);
1074 if (!hasSelection())
1079 case LFUN_PASTESELECTION:
1081 string const clip(bv->getClipboard());
1085 if (clip.find('\t') != string::npos) {
1089 string::size_type len = clip.length();
1090 string::size_type p = 0;
1093 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1101 maxCols = max(cols, maxCols);
1107 maxCols = max(cols, maxCols);
1108 delete paste_tabular;
1109 paste_tabular = new LyXTabular(this, rows, maxCols);
1110 string::size_type op = 0;
1112 int cells = paste_tabular->GetNumberOfCells();
1114 while ((cell < cells) && (p < len) &&
1115 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1120 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1125 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1126 while (cols++ < maxCols)
1134 // check for the last cell if there is no trailing '\n'
1135 if ((cell < cells) && (op < len))
1136 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1138 // so that the clipboard is used and it goes on
1140 // and executes LFUN_PASTESELECTION in insettext!
1141 delete paste_tabular;
1146 if (hasPasteBuffer()) {
1147 setUndo(bv, Undo::INSERT,
1148 bv->text->cursor.par(),
1149 bv->text->cursor.par()->next());
1151 updateLocal(bv, INIT, true);
1154 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1156 // we try to activate the actual inset and put this event down to
1157 // the insets dispatch function.
1158 result = UNDISPATCHED;
1159 if (the_locking_inset)
1162 if (activateCellInset(bv)) {
1163 // reset need_update setted in above function!
1165 result = the_locking_inset->localDispatch(bv, action, arg);
1166 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1167 unlockInsetInInset(bv, the_locking_inset);
1169 // we need to update if this was requested before
1170 updateLocal(bv, NONE, false);
1171 return UNDISPATCHED;
1176 updateLocal(bv, CELL, false);
1181 if (result < FINISHED) {
1182 if (!the_locking_inset) {
1183 showInsetCursor(bv);
1186 bv->unlockInset(this);
1191 int InsetTabular::latex(Buffer const * buf, ostream & os,
1192 bool fragile, bool fp) const
1194 return tabular->latex(buf, os, fragile, fp);
1198 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1201 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1203 return tabular->ascii(buf, os, 0, false,0);
1207 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1209 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1213 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1218 // if the table is inside a float it doesn't need the informaltable
1219 // wrapper. Search for it.
1220 for(master = owner();
1221 master && master->lyxCode() != Inset::FLOAT_CODE;
1222 master = master->owner());
1225 os << "<informaltable>\n";
1228 ret+= tabular->docBook(buf,os);
1230 os << "</informaltable>\n";
1237 void InsetTabular::validate(LaTeXFeatures & features) const
1239 tabular->Validate(features);
1243 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1244 LyXFont const & font,
1251 bool changed = false;
1253 // if we have a locking_inset we should have to check only this cell for
1254 // change so I'll try this to have a boost, but who knows ;)
1255 if ((need_update != INIT) &&
1256 (the_locking_inset == tabular->GetCellInset(actcell))) {
1257 for(int i = 0; i < tabular->columns(); ++i) {
1258 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1260 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1263 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1264 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1265 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1268 for (int i = 0; i < tabular->rows(); ++i) {
1271 for (int j = 0; j < tabular->columns(); ++j) {
1272 if (tabular->IsPartOfMultiColumn(i,j))
1275 inset = tabular->GetCellInset(cell);
1276 if (!reinit && !tabular->GetPWidth(cell).zero())
1277 inset->update(bv, font, false);
1278 maxAsc = max(maxAsc, inset->ascent(bv, font));
1279 maxDesc = max(maxDesc, inset->descent(bv, font));
1280 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1282 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1283 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1291 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1293 if (the_locking_inset) {
1294 the_locking_inset->getCursorPos(bv, x, y);
1297 x = cursor_.x() - top_x;
1302 void InsetTabular::toggleInsetCursor(BufferView * bv)
1304 if (the_locking_inset) {
1305 the_locking_inset->toggleInsetCursor(bv);
1309 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1311 int const asc = lyxfont::maxAscent(font);
1312 int const desc = lyxfont::maxDescent(font);
1314 if (isCursorVisible())
1315 bv->hideLockedInsetCursor();
1317 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1318 toggleCursorVisible();
1322 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1324 if (!isCursorVisible()) {
1325 LyXFont font; // = GetFont(par, cursor.pos);
1327 int const asc = lyxfont::maxAscent(font);
1328 int const desc = lyxfont::maxDescent(font);
1329 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1331 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1332 setCursorVisible(true);
1337 void InsetTabular::hideInsetCursor(BufferView * bv)
1339 if (isCursorVisible()) {
1340 bv->hideLockedInsetCursor();
1341 setCursorVisible(false);
1346 void InsetTabular::fitInsetCursor(BufferView * bv) const
1348 if (the_locking_inset) {
1349 the_locking_inset->fitInsetCursor(bv);
1354 int const asc = lyxfont::maxAscent(font);
1355 int const desc = lyxfont::maxDescent(font);
1356 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1360 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1364 actcell = actrow = actcol = 0;
1365 int ly = tabular->GetDescentOfRow(actrow);
1367 // first search the right row
1368 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1369 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1370 tabular->GetAscentOfRow(actrow + 1) +
1371 tabular->GetAdditionalHeight(actrow + 1));
1373 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1375 actcell = tabular->GetCellNumber(actrow, actcol);
1377 // now search the right column
1378 int lx = tabular->GetWidthOfColumn(actcell) -
1379 tabular->GetAdditionalWidth(actcell);
1380 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1381 lx += tabular->GetWidthOfColumn(actcell + 1)
1382 + tabular->GetAdditionalWidth(actcell);
1384 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1389 int InsetTabular::getCellXPos(int cell) const
1393 for (; !tabular->IsFirstCellInRow(c); --c)
1395 int lx = tabular->GetWidthOfColumn(cell);
1396 for (; c < cell; ++c) {
1397 lx += tabular->GetWidthOfColumn(c);
1399 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1403 void InsetTabular::resetPos(BufferView * bv) const
1405 if (!locked || nodraw())
1407 #warning This should be fixed in the right manner (20011128 Jug)
1408 // fast hack to fix infinite repaintings!
1411 in_reset_pos = true;
1413 actcol = tabular->column_of_cell(actcell);
1418 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1419 if (tabular->IsLastCellInRow(cell)) {
1420 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1421 tabular->GetAscentOfRow(actrow + 1) +
1422 tabular->GetAdditionalHeight(actrow + 1));
1426 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1427 int new_x = getCellXPos(actcell);
1428 int old_x = cursor_.x();
1431 // cursor.x(getCellXPos(actcell) + offset);
1432 if ((actcol < tabular->columns()-1) && scroll(false) &&
1433 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1436 updateLocal(bv, FULL, false);
1437 } else if (the_locking_inset &&
1438 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1440 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1441 if (xx > (bv->workWidth()-20)) {
1442 scroll(bv, -(xx - bv->workWidth() + 60));
1443 updateLocal(bv, FULL, false);
1444 } else if (xx < 20) {
1450 updateLocal(bv, FULL, false);
1452 } else if ((cursor_.x() - offset) > 20 &&
1453 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1454 > (bv->workWidth() - 20)) {
1455 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1456 updateLocal(bv, FULL, false);
1457 } else if ((cursor_.x() - offset) < 20) {
1458 scroll(bv, 20 - cursor_.x() + offset);
1459 updateLocal(bv, FULL, false);
1460 } else if (scroll(false) && top_x > 20 &&
1461 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1462 scroll(bv, old_x - cursor_.x());
1463 updateLocal(bv, FULL, false);
1465 if (the_locking_inset) {
1466 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1467 inset_y = cursor_.y();
1469 if ((!the_locking_inset ||
1470 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1471 actcell != oldcell) {
1472 InsetTabular * inset = const_cast<InsetTabular *>(this);
1473 bv->owner()->getDialogs()->updateTabular(inset);
1476 in_reset_pos = false;
1480 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1482 if (lock && !old_locking_inset) {
1483 if (activateCellInset(bv))
1486 bool moved = isRightToLeft(bv)
1487 ? movePrevCell(bv) : moveNextCell(bv);
1489 return FINISHED_RIGHT;
1490 if (lock && activateCellInset(bv))
1494 return DISPATCHED_NOUPDATE;
1498 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1500 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1503 if (lock) { // behind the inset
1504 if (activateCellInset(bv, 0, 0, 0, true))
1508 return DISPATCHED_NOUPDATE;
1512 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1514 int const ocell = actcell;
1515 actcell = tabular->GetCellAbove(actcell);
1516 if (actcell == ocell) // we moved out of the inset
1522 if (old_locking_inset) {
1523 old_locking_inset->getCursorPos(bv, x, y);
1524 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1526 if (activateCellInset(bv, x, 0))
1529 return DISPATCHED_NOUPDATE;
1533 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1535 int const ocell = actcell;
1536 actcell = tabular->GetCellBelow(actcell);
1537 if (actcell == ocell) // we moved out of the inset
1538 return FINISHED_DOWN;
1543 if (old_locking_inset) {
1544 old_locking_inset->getCursorPos(bv, x, y);
1545 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1547 if (activateCellInset(bv, x, 0))
1550 return DISPATCHED_NOUPDATE;
1554 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1556 if (isRightToLeft(bv)) {
1557 if (tabular->IsFirstCellInRow(actcell)) {
1558 int row = tabular->row_of_cell(actcell);
1559 if (row == tabular->rows() - 1)
1561 actcell = tabular->GetLastCellInRow(row);
1562 actcell = tabular->GetCellBelow(actcell);
1569 if (tabular->IsLastCell(actcell))
1574 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1575 isRightToLeftPar(bv->buffer()->params);
1576 activateCellInset(bv, 0, 0, 0, !rtl);
1583 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1585 if (isRightToLeft(bv)) {
1586 if (tabular->IsLastCellInRow(actcell)) {
1587 int row = tabular->row_of_cell(actcell);
1590 actcell = tabular->GetFirstCellInRow(row);
1591 actcell = tabular->GetCellAbove(actcell);
1593 if (tabular->IsLastCell(actcell))
1598 if (!actcell) // first cell
1603 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1604 isRightToLeftPar(bv->buffer()->params);
1605 activateCellInset(bv, 0, 0, 0, !rtl);
1612 bool InsetTabular::deletable() const
1618 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1622 setSelection(0, tabular->GetNumberOfCells() - 1);
1624 if (hasSelection()) {
1625 setUndo(bv, Undo::EDIT,
1626 bv->text->cursor.par(),
1627 bv->text->cursor.par()->next());
1628 bool frozen = undo_frozen;
1631 // apply the fontchange on the whole selection
1636 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1637 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1638 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1639 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1644 updateLocal(bv, INIT, true);
1646 if (the_locking_inset)
1647 the_locking_inset->setFont(bv, font, tall);
1651 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1653 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1656 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1657 string const tmp = tabularFeature[i].feature;
1659 if (tmp == what.substr(0, tmp.length())) {
1660 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1661 //tabularFeatures[i].feature.length())) {
1662 action = tabularFeature[i].action;
1666 if (action == LyXTabular::LAST_ACTION)
1670 frontStrip(what.substr(tabularFeature[i].feature.length()));
1671 tabularFeatures(bv, action, val);
1675 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1676 string const & special, bool & flag)
1678 if (special == "dl_above") {
1681 } else if (special == "dl_below") {
1682 ltt.bottomDL = flag;
1684 } else if (special == "empty") {
1694 void InsetTabular::tabularFeatures(BufferView * bv,
1695 LyXTabular::Feature feature,
1696 string const & value)
1702 bool setLines = false;
1703 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1704 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1707 case LyXTabular::M_ALIGN_LEFT:
1708 case LyXTabular::ALIGN_LEFT:
1709 setAlign = LYX_ALIGN_LEFT;
1711 case LyXTabular::M_ALIGN_RIGHT:
1712 case LyXTabular::ALIGN_RIGHT:
1713 setAlign = LYX_ALIGN_RIGHT;
1715 case LyXTabular::M_ALIGN_CENTER:
1716 case LyXTabular::ALIGN_CENTER:
1717 setAlign = LYX_ALIGN_CENTER;
1719 case LyXTabular::M_VALIGN_TOP:
1720 case LyXTabular::VALIGN_TOP:
1721 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1723 case LyXTabular::M_VALIGN_BOTTOM:
1724 case LyXTabular::VALIGN_BOTTOM:
1725 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1727 case LyXTabular::M_VALIGN_CENTER:
1728 case LyXTabular::VALIGN_CENTER:
1729 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1734 if (hasSelection()) {
1735 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1737 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1738 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1740 setUndo(bv, Undo::FINISH,
1741 bv->text->cursor.par(),
1742 bv->text->cursor.par()->next());
1744 int row = tabular->row_of_cell(actcell);
1745 int column = tabular->column_of_cell(actcell);
1747 LyXTabular::ltType ltt;
1750 case LyXTabular::SET_PWIDTH:
1752 LyXLength const vallen(value);
1753 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1755 bool const update = (tmplen != vallen);
1756 tabular->SetColumnPWidth(actcell, vallen);
1759 for (int i = 0; i < tabular->rows(); ++i) {
1760 cell = tabular->GetCellNumber(i,column);
1761 tabular->GetCellInset(cell)->resizeLyXText(bv);
1763 updateLocal(bv, INIT, true);
1767 case LyXTabular::SET_MPWIDTH:
1769 LyXLength const vallen(value);
1770 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1772 bool const update = (tmplen != vallen);
1773 tabular->SetMColumnPWidth(actcell, vallen);
1775 for (int i = 0; i < tabular->rows(); ++i) {
1776 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1779 updateLocal(bv, INIT, true);
1783 case LyXTabular::SET_SPECIAL_COLUMN:
1784 case LyXTabular::SET_SPECIAL_MULTI:
1785 tabular->SetAlignSpecial(actcell,value,feature);
1786 updateLocal(bv, FULL, true);
1788 case LyXTabular::APPEND_ROW:
1789 // append the row into the tabular
1790 unlockInsetInInset(bv, the_locking_inset);
1791 tabular->AppendRow(actcell);
1792 updateLocal(bv, INIT, true);
1794 case LyXTabular::APPEND_COLUMN:
1795 // append the column into the tabular
1796 unlockInsetInInset(bv, the_locking_inset);
1797 tabular->AppendColumn(actcell);
1798 actcell = tabular->GetCellNumber(row, column);
1799 updateLocal(bv, INIT, true);
1801 case LyXTabular::DELETE_ROW:
1802 unlockInsetInInset(bv, the_locking_inset);
1803 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1804 tabular->DeleteRow(sel_row_start);
1806 if (sel_row_start >= tabular->rows())
1808 actcell = tabular->GetCellNumber(sel_row_start, column);
1810 updateLocal(bv, INIT, true);
1812 case LyXTabular::DELETE_COLUMN:
1813 unlockInsetInInset(bv, the_locking_inset);
1814 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1815 tabular->DeleteColumn(sel_col_start);
1817 if (sel_col_start >= tabular->columns())
1819 actcell = tabular->GetCellNumber(row, sel_col_start);
1821 updateLocal(bv, INIT, true);
1823 case LyXTabular::M_TOGGLE_LINE_TOP:
1825 case LyXTabular::TOGGLE_LINE_TOP:
1827 bool lineSet = !tabular->TopLine(actcell, flag);
1828 for (int i = sel_row_start; i <= sel_row_end; ++i)
1829 for (int j = sel_col_start; j <= sel_col_end; ++j)
1830 tabular->SetTopLine(
1831 tabular->GetCellNumber(i, j),
1833 updateLocal(bv, INIT, true);
1837 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1839 case LyXTabular::TOGGLE_LINE_BOTTOM:
1841 bool lineSet = !tabular->BottomLine(actcell, flag);
1842 for (int i = sel_row_start; i <= sel_row_end; ++i)
1843 for (int j = sel_col_start; j <= sel_col_end; ++j)
1844 tabular->SetBottomLine(
1845 tabular->GetCellNumber(i, j),
1848 updateLocal(bv, INIT, true);
1852 case LyXTabular::M_TOGGLE_LINE_LEFT:
1854 case LyXTabular::TOGGLE_LINE_LEFT:
1856 bool lineSet = !tabular->LeftLine(actcell, flag);
1857 for (int i = sel_row_start; i <= sel_row_end; ++i)
1858 for (int j = sel_col_start; j <= sel_col_end; ++j)
1859 tabular->SetLeftLine(
1860 tabular->GetCellNumber(i,j),
1863 updateLocal(bv, INIT, true);
1867 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1869 case LyXTabular::TOGGLE_LINE_RIGHT:
1871 bool lineSet = !tabular->RightLine(actcell, flag);
1872 for (int i = sel_row_start; i <= sel_row_end; ++i)
1873 for (int j = sel_col_start; j <= sel_col_end; ++j)
1874 tabular->SetRightLine(
1875 tabular->GetCellNumber(i,j),
1878 updateLocal(bv, INIT, true);
1882 case LyXTabular::M_ALIGN_LEFT:
1883 case LyXTabular::M_ALIGN_RIGHT:
1884 case LyXTabular::M_ALIGN_CENTER:
1886 case LyXTabular::ALIGN_LEFT:
1887 case LyXTabular::ALIGN_RIGHT:
1888 case LyXTabular::ALIGN_CENTER:
1889 for (int i = sel_row_start; i <= sel_row_end; ++i)
1890 for (int j = sel_col_start; j <= sel_col_end; ++j)
1891 tabular->SetAlignment(
1892 tabular->GetCellNumber(i, j),
1895 updateLocal(bv, INIT, true);
1897 case LyXTabular::M_VALIGN_TOP:
1898 case LyXTabular::M_VALIGN_BOTTOM:
1899 case LyXTabular::M_VALIGN_CENTER:
1901 case LyXTabular::VALIGN_TOP:
1902 case LyXTabular::VALIGN_BOTTOM:
1903 case LyXTabular::VALIGN_CENTER:
1904 for (int i = sel_row_start; i <= sel_row_end; ++i)
1905 for (int j = sel_col_start; j <= sel_col_end; ++j)
1906 tabular->SetVAlignment(
1907 tabular->GetCellNumber(i, j),
1909 updateLocal(bv, INIT, true);
1911 case LyXTabular::MULTICOLUMN:
1913 if (sel_row_start != sel_row_end) {
1914 Alert::alert(_("Impossible Operation!"),
1915 _("Multicolumns can only be horizontally."),
1919 // just multicol for one Single Cell
1920 if (!hasSelection()) {
1921 // check wether we are completly in a multicol
1922 if (tabular->IsMultiColumn(actcell)) {
1923 tabular->UnsetMultiColumn(actcell);
1924 updateLocal(bv, INIT, true);
1926 tabular->SetMultiColumn(actcell, 1);
1927 updateLocal(bv, CELL, true);
1931 // we have a selection so this means we just add all this
1932 // cells to form a multicolumn cell
1936 if (sel_cell_start > sel_cell_end) {
1937 s_start = sel_cell_end;
1938 s_end = sel_cell_start;
1940 s_start = sel_cell_start;
1941 s_end = sel_cell_end;
1943 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1946 updateLocal(bv, INIT, true);
1949 case LyXTabular::SET_ALL_LINES:
1951 case LyXTabular::UNSET_ALL_LINES:
1952 for (int i = sel_row_start; i <= sel_row_end; ++i)
1953 for (int j = sel_col_start; j <= sel_col_end; ++j)
1954 tabular->SetAllLines(
1955 tabular->GetCellNumber(i,j), setLines);
1956 updateLocal(bv, INIT, true);
1958 case LyXTabular::SET_LONGTABULAR:
1959 tabular->SetLongTabular(true);
1960 updateLocal(bv, INIT, true); // because this toggles displayed
1962 case LyXTabular::UNSET_LONGTABULAR:
1963 tabular->SetLongTabular(false);
1964 updateLocal(bv, INIT, true); // because this toggles displayed
1966 case LyXTabular::SET_ROTATE_TABULAR:
1967 tabular->SetRotateTabular(true);
1969 case LyXTabular::UNSET_ROTATE_TABULAR:
1970 tabular->SetRotateTabular(false);
1972 case LyXTabular::SET_ROTATE_CELL:
1973 for (int i = sel_row_start; i <= sel_row_end; ++i)
1974 for (int j = sel_col_start; j<=sel_col_end; ++j)
1975 tabular->SetRotateCell(
1976 tabular->GetCellNumber(i, j),
1979 case LyXTabular::UNSET_ROTATE_CELL:
1980 for (int i = sel_row_start; i <= sel_row_end; ++i)
1981 for (int j = sel_col_start; j <= sel_col_end; ++j)
1982 tabular->SetRotateCell(
1983 tabular->GetCellNumber(i, j), false);
1985 case LyXTabular::SET_USEBOX:
1987 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1988 if (val == tabular->GetUsebox(actcell))
1989 val = LyXTabular::BOX_NONE;
1990 for (int i = sel_row_start; i <= sel_row_end; ++i)
1991 for (int j = sel_col_start; j <= sel_col_end; ++j)
1993 tabular->GetCellNumber(i, j), val);
1996 case LyXTabular::UNSET_LTFIRSTHEAD:
1998 case LyXTabular::SET_LTFIRSTHEAD:
1999 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2000 checkLongtableSpecial(ltt, value, flag);
2001 tabular->SetLTHead(row, flag, ltt, true);
2003 case LyXTabular::UNSET_LTHEAD:
2005 case LyXTabular::SET_LTHEAD:
2006 (void)tabular->GetRowOfLTHead(row, ltt);
2007 checkLongtableSpecial(ltt, value, flag);
2008 tabular->SetLTHead(row, flag, ltt, false);
2010 case LyXTabular::UNSET_LTFOOT:
2012 case LyXTabular::SET_LTFOOT:
2013 (void)tabular->GetRowOfLTFoot(row, ltt);
2014 checkLongtableSpecial(ltt, value, flag);
2015 tabular->SetLTFoot(row, flag, ltt, false);
2017 case LyXTabular::UNSET_LTLASTFOOT:
2019 case LyXTabular::SET_LTLASTFOOT:
2020 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2021 checkLongtableSpecial(ltt, value, flag);
2022 tabular->SetLTFoot(row, flag, ltt, true);
2024 case LyXTabular::SET_LTNEWPAGE:
2026 bool what = !tabular->GetLTNewPage(row);
2027 tabular->SetLTNewPage(row, what);
2030 // dummy stuff just to avoid warnings
2031 case LyXTabular::LAST_ACTION:
2037 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2040 UpdatableInset * inset =
2041 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2042 LyXFont font(LyXFont::ALL_SANE);
2044 x = inset->x() + inset->width(bv, font);
2045 y = inset->descent(bv, font);
2047 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2048 //inset_y = cursor.y();
2049 inset->edit(bv, x, y, button);
2050 if (!the_locking_inset)
2052 updateLocal(bv, CELL, false);
2053 return (the_locking_inset != 0);
2057 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2060 inset_x = cursor_.x()
2061 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2062 inset_y = cursor_.y();
2063 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2067 bool InsetTabular::insetHit(BufferView *, int x, int) const
2070 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2074 // This returns paperWidth() if the cell-width is unlimited or the width
2075 // in pixels if we have a pwidth for this cell.
2076 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2078 LyXLength const len = tabular->GetPWidth(cell);
2082 #ifdef WITH_WARNINGS
2083 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2085 return VSpace(len).inPixels(bv);
2089 int InsetTabular::getMaxWidth(BufferView * bv,
2090 UpdatableInset const * inset) const
2092 int cell = tabular->cur_cell;
2093 if (tabular->GetCellInset(cell) != inset) {
2095 if (tabular->GetCellInset(cell) != inset) {
2097 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2102 int const n = tabular->GetNumberOfCells();
2105 for (cell = 0; cell < n; ++cell) {
2106 if (tabular->GetCellInset(cell) == inset)
2112 lyxerr << "Own inset not found, shouldn't really happen!\n";
2116 int w = getMaxWidthOfCell(bv, cell);
2118 // because the inset then subtracts it's top_x and owner->x()
2119 w += (inset->x() - top_x);
2126 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2128 resizeLyXText(bv, recursive);
2132 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2135 for(int i = 0; i < tabular->rows(); ++i) {
2136 for(int j = 0; j < tabular->columns(); ++j) {
2137 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2145 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2146 bool const recursive) const
2148 if (the_locking_inset)
2149 return the_locking_inset->getLyXText(bv, recursive);
2151 // if we're locked lock the actual insettext and return it's LyXText!!!
2153 UpdatableInset * inset =
2154 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2155 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2156 return the_locking_inset->getLyXText(bv, recursive);
2159 return Inset::getLyXText(bv, recursive);
2163 bool InsetTabular::showInsetDialog(BufferView * bv) const
2165 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2166 bv->owner()->getDialogs()
2167 ->showTabular(const_cast<InsetTabular *>(this));
2172 void InsetTabular::openLayoutDialog(BufferView * bv) const
2174 if (the_locking_inset) {
2175 InsetTabular * i = static_cast<InsetTabular *>
2176 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2178 i->openLayoutDialog(bv);
2182 bv->owner()->getDialogs()->showTabular(
2183 const_cast<InsetTabular *>(this));
2188 // functions returns:
2192 // 3 ... toggled off
2194 func_status::value_type InsetTabular::getStatus(string const & what) const
2196 int action = LyXTabular::LAST_ACTION;
2197 func_status::value_type status = func_status::OK;
2200 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2201 string const tmp = tabularFeature[i].feature;
2202 if (tmp == what.substr(0, tmp.length())) {
2203 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2204 // tabularFeatures[i].feature.length())) {
2205 action = tabularFeature[i].action;
2209 if (action == LyXTabular::LAST_ACTION)
2210 return func_status::Unknown;
2212 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2217 LyXTabular::ltType dummyltt;
2220 if (hasSelection()) {
2221 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2223 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2227 case LyXTabular::SET_PWIDTH:
2228 case LyXTabular::SET_MPWIDTH:
2229 case LyXTabular::SET_SPECIAL_COLUMN:
2230 case LyXTabular::SET_SPECIAL_MULTI:
2231 status |= func_status::Disabled;
2234 case LyXTabular::APPEND_ROW:
2235 case LyXTabular::APPEND_COLUMN:
2236 case LyXTabular::DELETE_ROW:
2237 case LyXTabular::DELETE_COLUMN:
2238 case LyXTabular::SET_ALL_LINES:
2239 case LyXTabular::UNSET_ALL_LINES:
2240 status |= func_status::OK;
2243 case LyXTabular::MULTICOLUMN:
2244 if (tabular->IsMultiColumn(actcell))
2245 status |= func_status::ToggleOn;
2247 status |= func_status::ToggleOff;
2249 case LyXTabular::M_TOGGLE_LINE_TOP:
2251 case LyXTabular::TOGGLE_LINE_TOP:
2252 if (tabular->TopLine(actcell, flag))
2253 status |= func_status::ToggleOn;
2255 status |= func_status::ToggleOff;
2257 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2259 case LyXTabular::TOGGLE_LINE_BOTTOM:
2260 if (tabular->BottomLine(actcell, flag))
2261 status |= func_status::ToggleOn;
2263 status |= func_status::ToggleOff;
2265 case LyXTabular::M_TOGGLE_LINE_LEFT:
2267 case LyXTabular::TOGGLE_LINE_LEFT:
2268 if (tabular->LeftLine(actcell, flag))
2269 status |= func_status::ToggleOn;
2271 status |= func_status::ToggleOff;
2273 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2275 case LyXTabular::TOGGLE_LINE_RIGHT:
2276 if (tabular->RightLine(actcell, flag))
2277 status |= func_status::ToggleOn;
2279 status |= func_status::ToggleOff;
2281 case LyXTabular::M_ALIGN_LEFT:
2283 case LyXTabular::ALIGN_LEFT:
2284 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2285 status |= func_status::ToggleOn;
2287 status |= func_status::ToggleOff;
2289 case LyXTabular::M_ALIGN_RIGHT:
2291 case LyXTabular::ALIGN_RIGHT:
2292 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2293 status |= func_status::ToggleOn;
2295 status |= func_status::ToggleOff;
2297 case LyXTabular::M_ALIGN_CENTER:
2299 case LyXTabular::ALIGN_CENTER:
2300 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2301 status |= func_status::ToggleOn;
2303 status |= func_status::ToggleOff;
2305 case LyXTabular::M_VALIGN_TOP:
2307 case LyXTabular::VALIGN_TOP:
2308 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2309 status |= func_status::ToggleOn;
2311 status |= func_status::ToggleOff;
2313 case LyXTabular::M_VALIGN_BOTTOM:
2315 case LyXTabular::VALIGN_BOTTOM:
2316 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2317 status |= func_status::ToggleOn;
2319 status |= func_status::ToggleOff;
2321 case LyXTabular::M_VALIGN_CENTER:
2323 case LyXTabular::VALIGN_CENTER:
2324 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2325 status |= func_status::ToggleOn;
2327 status |= func_status::ToggleOff;
2329 case LyXTabular::SET_LONGTABULAR:
2330 if (tabular->IsLongTabular())
2331 status |= func_status::ToggleOn;
2333 status |= func_status::ToggleOff;
2335 case LyXTabular::UNSET_LONGTABULAR:
2336 if (!tabular->IsLongTabular())
2337 status |= func_status::ToggleOn;
2339 status |= func_status::ToggleOff;
2341 case LyXTabular::SET_ROTATE_TABULAR:
2342 if (tabular->GetRotateTabular())
2343 status |= func_status::ToggleOn;
2345 status |= func_status::ToggleOff;
2347 case LyXTabular::UNSET_ROTATE_TABULAR:
2348 if (!tabular->GetRotateTabular())
2349 status |= func_status::ToggleOn;
2351 status |= func_status::ToggleOff;
2353 case LyXTabular::SET_ROTATE_CELL:
2354 if (tabular->GetRotateCell(actcell))
2355 status |= func_status::ToggleOn;
2357 status |= func_status::ToggleOff;
2359 case LyXTabular::UNSET_ROTATE_CELL:
2360 if (!tabular->GetRotateCell(actcell))
2361 status |= func_status::ToggleOn;
2363 status |= func_status::ToggleOff;
2365 case LyXTabular::SET_USEBOX:
2366 if (strToInt(argument) == tabular->GetUsebox(actcell))
2367 status |= func_status::ToggleOn;
2369 status |= func_status::ToggleOff;
2371 case LyXTabular::SET_LTFIRSTHEAD:
2372 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2373 status |= func_status::ToggleOn;
2375 status |= func_status::ToggleOff;
2377 case LyXTabular::SET_LTHEAD:
2378 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2379 status |= func_status::ToggleOn;
2381 status |= func_status::ToggleOff;
2383 case LyXTabular::SET_LTFOOT:
2384 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2385 status |= func_status::ToggleOn;
2387 status |= func_status::ToggleOff;
2389 case LyXTabular::SET_LTLASTFOOT:
2390 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2391 status |= func_status::ToggleOn;
2393 status |= func_status::ToggleOff;
2395 case LyXTabular::SET_LTNEWPAGE:
2396 if (tabular->GetLTNewPage(sel_row_start))
2397 status |= func_status::ToggleOn;
2399 status |= func_status::ToggleOff;
2402 status = func_status::Disabled;
2409 std::vector<string> const InsetTabular::getLabelList() const
2411 return tabular->getLabelList();
2415 bool InsetTabular::copySelection(BufferView * bv)
2417 if (!hasSelection())
2420 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2421 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2422 if (sel_col_start > sel_col_end) {
2423 sel_col_start = sel_col_end;
2424 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2426 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2428 int const columns = sel_col_end - sel_col_start + 1;
2430 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2431 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2432 if (sel_row_start > sel_row_end) {
2433 swap(sel_row_start, sel_row_end);
2435 int const rows = sel_row_end - sel_row_start + 1;
2437 delete paste_tabular;
2438 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2439 for (int i = 0; i < sel_row_start; ++i)
2440 paste_tabular->DeleteRow(0);
2441 while (paste_tabular->rows() > rows)
2442 paste_tabular->DeleteRow(rows);
2443 paste_tabular->SetTopLine(0, true, true);
2444 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2446 for (int i = 0; i < sel_col_start; ++i)
2447 paste_tabular->DeleteColumn(0);
2448 while (paste_tabular->columns() > columns)
2449 paste_tabular->DeleteColumn(columns);
2450 paste_tabular->SetLeftLine(0, true, true);
2451 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2455 paste_tabular->ascii(bv->buffer(), sstr,
2456 (int)parOwner()->params().depth(), true, '\t');
2457 bv->stuffClipboard(sstr.str().c_str());
2462 bool InsetTabular::pasteSelection(BufferView * bv)
2467 for (int r1 = 0, r2 = actrow;
2468 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2470 for(int c1 = 0, c2 = actcol;
2471 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2473 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2474 tabular->IsPartOfMultiColumn(r2,c2))
2476 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2480 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2484 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2485 int const n2 = tabular->GetCellNumber(r2, c2);
2486 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2487 tabular->GetCellInset(n2)->setOwner(this);
2488 tabular->GetCellInset(n2)->deleteLyXText(bv);
2495 bool InsetTabular::cutSelection()
2497 if (!hasSelection())
2500 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2501 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2502 if (sel_col_start > sel_col_end) {
2503 sel_col_start = sel_col_end;
2504 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2506 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2508 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2509 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2510 if (sel_row_start > sel_row_end) {
2511 swap(sel_row_start, sel_row_end);
2513 if (sel_cell_start > sel_cell_end) {
2514 swap(sel_cell_start, sel_cell_end);
2516 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2517 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2518 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2525 bool InsetTabular::isRightToLeft(BufferView *bv )
2527 return bv->getParentLanguage(this)->RightToLeft();
2531 bool InsetTabular::nodraw() const
2533 if (!UpdatableInset::nodraw() && the_locking_inset)
2534 return the_locking_inset->nodraw();
2535 return UpdatableInset::nodraw();
2539 int InsetTabular::scroll(bool recursive) const
2541 int sx = UpdatableInset::scroll(false);
2543 if (recursive && the_locking_inset)
2544 sx += the_locking_inset->scroll(recursive);
2550 bool InsetTabular::doClearArea() const
2552 return !locked || (need_update & (FULL|INIT));
2556 void InsetTabular::getSelection(int & srow, int & erow,
2557 int & scol, int & ecol) const
2559 int const start = hasSelection() ? sel_cell_start : actcell;
2560 int const end = hasSelection() ? sel_cell_end : actcell;
2562 srow = tabular->row_of_cell(start);
2563 erow = tabular->row_of_cell(end);
2568 scol = tabular->column_of_cell(start);
2569 ecol = tabular->column_of_cell(end);
2573 ecol = tabular->right_column_of_cell(end);
2578 Paragraph * InsetTabular::getParFromID(int id) const
2581 for(int i = 0; i < tabular->rows(); ++i) {
2582 for(int j = 0; j < tabular->columns(); ++j) {
2583 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2591 Paragraph * InsetTabular::firstParagraph() const
2593 if (the_locking_inset)
2594 return the_locking_inset->firstParagraph();
2599 Paragraph * InsetTabular::getFirstParagraph(int i) const
2601 return (i < tabular->GetNumberOfCells())
2602 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2607 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2609 if (the_locking_inset)
2610 return the_locking_inset->cursor(bv);
2611 return Inset::cursor(bv);
2615 Inset * InsetTabular::getInsetFromID(int id_arg) const
2618 return const_cast<InsetTabular *>(this);
2621 for(int i = 0; i < tabular->rows(); ++i) {
2622 for(int j = 0; j < tabular->columns(); ++j) {
2623 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2632 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2634 if (the_locking_inset) {
2635 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2638 if (tabular->IsLastCell(actcell)) {
2639 bv->unlockInset(const_cast<InsetTabular *>(this));
2645 // otherwise we have to lock the next inset and ask for it's selecttion
2646 UpdatableInset * inset =
2647 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2648 inset->edit(bv, 0, 0, 0);
2649 string const str(selectNextWordInt(bv, value));
2657 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2659 // when entering this function the inset should be ALWAYS locked!
2660 lyx::Assert(the_locking_inset);
2662 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2666 if (tabular->IsLastCell(actcell)) {
2667 bv->unlockInset(const_cast<InsetTabular *>(this));
2671 // otherwise we have to lock the next inset and ask for it's selecttion
2672 UpdatableInset * inset =
2673 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2675 return selectNextWordInt(bv, value);
2679 void InsetTabular::selectSelectedWord(BufferView * bv)
2681 if (the_locking_inset) {
2682 the_locking_inset->selectSelectedWord(bv);
2689 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2691 if (the_locking_inset) {
2692 the_locking_inset->toggleSelection(bv, kill_selection);
2697 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2698 bool const & cs, bool const & mw)
2700 if (the_locking_inset) {
2701 if (the_locking_inset->searchForward(bv, str, cs, mw))
2703 if (tabular->IsLastCell(actcell)) {
2704 bv->unlockInset(const_cast<InsetTabular *>(this));
2709 // otherwise we have to lock the next inset and search there
2710 UpdatableInset * inset =
2711 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2714 bool const res = searchForward(bv, str, cs, mw);
2715 updateLocal(bv, NONE, false);
2716 bv->updateInset(const_cast<InsetTabular *>(this), false);
2719 return searchForward(bv, str, cs, mw);
2724 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2725 bool const & cs, bool const & mw)
2727 if (the_locking_inset) {
2728 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2730 if (!actcell) { // we are already in the first cell
2731 bv->unlockInset(const_cast<InsetTabular *>(this));
2736 // otherwise we have to lock the next inset and search there
2737 UpdatableInset * inset =
2738 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2739 inset->edit(bv, false);
2741 bool const res = searchBackward(bv, str, cs, mw);
2742 bv->updateInset(const_cast<InsetTabular *>(this), false);
2745 return searchBackward(bv, str, cs, mw);
2750 bool InsetTabular::insetAllowed(Inset::Code code) const
2752 if (the_locking_inset)
2753 return the_locking_inset->insetAllowed(code);