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)
702 return inset_y + the_locking_inset->insetInInsetY();
706 UpdatableInset * InsetTabular::getLockingInset() const
708 return the_locking_inset ? the_locking_inset->getLockingInset() :
709 const_cast<InsetTabular *>(this);
713 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
717 if (the_locking_inset)
718 return the_locking_inset->getFirstLockingInsetOfType(c);
723 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
725 if (the_locking_inset)
726 return the_locking_inset->insertInset(bv, inset);
731 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
733 if (hasSelection() && (button == 3))
736 if (hasSelection()) {
738 updateLocal(bv, SELECTION, false);
741 int const ocell = actcell;
742 int const orow = actrow;
747 updateLocal(bv, NONE, false);
751 if ((ocell != actcell) && the_locking_inset) {
752 the_locking_inset->insetUnlock(bv);
753 the_locking_inset = 0;
760 bool const inset_hit = insetHit(bv, x, y);
762 if ((ocell == actcell) && the_locking_inset && inset_hit) {
764 the_locking_inset->insetButtonPress(bv,
765 x - inset_x, y - inset_y,
768 } else if (the_locking_inset) {
769 the_locking_inset->insetUnlock(bv);
771 the_locking_inset = 0;
773 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
776 if (inset_hit && bv->theLockingInset()) {
777 if (activateCellInsetAbs(bv, x, y, button))
778 the_locking_inset->insetButtonPress(bv,
788 bool InsetTabular::insetButtonRelease(BufferView * bv,
789 int x, int y, int button)
792 if (the_locking_inset)
793 ret = the_locking_inset->insetButtonRelease(bv, x, y, button);
794 if (button == 3 && !ret) {
795 bv->owner()->getDialogs()->showTabular(this);
802 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
804 if (the_locking_inset) {
805 the_locking_inset->insetMotionNotify(bv,
813 // int const old_cell = actcell;
816 if (!hasSelection()) {
817 setSelection(actcell, actcell);
819 setSelection(sel_cell_start, actcell);
821 updateLocal(bv, SELECTION, false);
826 void InsetTabular::insetKeyPress(XKeyEvent * xke)
828 if (the_locking_inset) {
829 the_locking_inset->insetKeyPress(xke);
835 UpdatableInset::RESULT
836 InsetTabular::localDispatch(BufferView * bv, kb_action action,
839 // We need to save the value of the_locking_inset as the call to
840 // the_locking_inset->LocalDispatch might unlock it.
841 old_locking_inset = the_locking_inset;
842 UpdatableInset::RESULT result =
843 UpdatableInset::localDispatch(bv, action, arg);
844 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
849 if ((action < 0) && arg.empty())
852 bool hs = hasSelection();
855 // this one have priority over the locked InsetText, if we're not already
856 // inside another tabular then that one get's priority!
857 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
862 unlockInsetInInset(bv, the_locking_inset);
863 if (action == LFUN_TAB)
864 moveNextCell(bv, old_locking_inset != 0);
866 movePrevCell(bv, old_locking_inset != 0);
869 updateLocal(bv, SELECTION, false);
870 if (!the_locking_inset) {
872 return DISPATCHED_NOUPDATE;
875 // this to avoid compiler warnings.
881 if (the_locking_inset) {
882 result = the_locking_inset->localDispatch(bv, action, arg);
883 if (result == DISPATCHED_NOUPDATE) {
886 if (sc != scroll()) { // inset has been scrolled
887 the_locking_inset->toggleInsetCursor(bv);
888 updateLocal(bv, FULL, false);
889 the_locking_inset->toggleInsetCursor(bv);
892 } else if (result == DISPATCHED) {
893 the_locking_inset->toggleInsetCursor(bv);
894 updateLocal(bv, CELL, false);
895 the_locking_inset->toggleInsetCursor(bv);
897 } else if (result == FINISHED_UP) {
899 } else if (result == FINISHED_DOWN) {
901 } else if (result == FINISHED_RIGHT) {
909 // --- Cursor Movements ----------------------------------
910 case LFUN_RIGHTSEL: {
911 int const start = hasSelection() ? sel_cell_start : actcell;
912 if (tabular->IsLastCellInRow(actcell)) {
913 setSelection(start, actcell);
918 // if we are starting a selection, only select
919 // the current cell at the beginning
920 if (hasSelection()) {
921 moveRight(bv, false);
924 setSelection(start, end);
925 updateLocal(bv, SELECTION, false);
929 result = moveRight(bv);
932 updateLocal(bv, SELECTION, false);
935 int const start = hasSelection() ? sel_cell_start : actcell;
936 if (tabular->IsFirstCellInRow(actcell)) {
937 setSelection(start, actcell);
942 // if we are starting a selection, only select
943 // the current cell at the beginning
944 if (hasSelection()) {
948 setSelection(start, end);
949 updateLocal(bv, SELECTION, false);
953 result = moveLeft(bv);
956 updateLocal(bv, SELECTION, false);
959 int const start = hasSelection() ? sel_cell_start : actcell;
960 int const ocell = actcell;
961 // if we are starting a selection, only select
962 // the current cell at the beginning
963 if (hasSelection()) {
965 if ((ocell == sel_cell_end) ||
966 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
967 setSelection(start, tabular->GetCellBelow(sel_cell_end));
969 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
971 setSelection(start, start);
973 updateLocal(bv, SELECTION, false);
977 result = moveDown(bv, old_locking_inset != 0);
980 updateLocal(bv, SELECTION, false);
984 int const start = hasSelection() ? sel_cell_start : actcell;
985 int const ocell = actcell;
986 // if we are starting a selection, only select
987 // the current cell at the beginning
988 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));
996 setSelection(start, start);
998 updateLocal(bv, SELECTION, false);
1002 result = moveUp(bv, old_locking_inset != 0);
1005 updateLocal(bv, SELECTION, false);
1008 int column = actcol;
1009 unlockInsetInInset(bv, the_locking_inset);
1010 if (bv->text->first + bv->painter().paperHeight() <
1011 (top_baseline + tabular->GetHeightOfTabular()))
1013 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1014 updateLocal(bv, FULL, false);
1015 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1017 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1020 updateLocal(bv, CURSOR, false);
1024 int column = actcol;
1025 unlockInsetInInset(bv, the_locking_inset);
1026 if (top_baseline < 0) {
1027 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1028 updateLocal(bv, FULL, false);
1029 if (top_baseline > 0)
1032 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1037 updateLocal(bv, CURSOR, false);
1040 // none of these make sense for insettabular,
1041 // but we must catch them to prevent any
1042 // selection from being confused
1046 case LFUN_WORDLEFTSEL:
1047 case LFUN_WORDRIGHT:
1048 case LFUN_WORDRIGHTSEL:
1049 case LFUN_DOWN_PARAGRAPH:
1050 case LFUN_DOWN_PARAGRAPHSEL:
1051 case LFUN_UP_PARAGRAPH:
1052 case LFUN_UP_PARAGRAPHSEL:
1053 case LFUN_BACKSPACE:
1060 case LFUN_LAYOUT_TABULAR:
1061 bv->owner()->getDialogs()->showTabular(this);
1063 case LFUN_TABULAR_FEATURE:
1064 if (!tabularFeatures(bv, arg))
1065 result = UNDISPATCHED;
1068 if (!copySelection(bv))
1070 setUndo(bv, Undo::DELETE,
1071 bv->text->cursor.par(),
1072 bv->text->cursor.par()->next());
1074 updateLocal(bv, INIT, true);
1077 if (!hasSelection())
1082 case LFUN_PASTESELECTION:
1084 string const clip(bv->getClipboard());
1088 if (clip.find('\t') != string::npos) {
1092 string::size_type len = clip.length();
1093 string::size_type p = 0;
1096 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1104 maxCols = max(cols, maxCols);
1110 maxCols = max(cols, maxCols);
1111 delete paste_tabular;
1112 paste_tabular = new LyXTabular(this, rows, maxCols);
1113 string::size_type op = 0;
1115 int cells = paste_tabular->GetNumberOfCells();
1117 while ((cell < cells) && (p < len) &&
1118 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1123 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1128 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1129 while (cols++ < maxCols)
1137 // check for the last cell if there is no trailing '\n'
1138 if ((cell < cells) && (op < len))
1139 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1141 // so that the clipboard is used and it goes on
1143 // and executes LFUN_PASTESELECTION in insettext!
1144 delete paste_tabular;
1149 if (hasPasteBuffer()) {
1150 setUndo(bv, Undo::INSERT,
1151 bv->text->cursor.par(),
1152 bv->text->cursor.par()->next());
1154 updateLocal(bv, INIT, true);
1157 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1159 // we try to activate the actual inset and put this event down to
1160 // the insets dispatch function.
1161 result = UNDISPATCHED;
1162 if (the_locking_inset)
1165 if (activateCellInset(bv)) {
1166 // reset need_update setted in above function!
1168 result = the_locking_inset->localDispatch(bv, action, arg);
1169 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1170 unlockInsetInInset(bv, the_locking_inset);
1172 // we need to update if this was requested before
1173 updateLocal(bv, NONE, false);
1174 return UNDISPATCHED;
1179 updateLocal(bv, CELL, false);
1184 if (result < FINISHED) {
1185 if (!the_locking_inset) {
1186 showInsetCursor(bv);
1189 bv->unlockInset(this);
1194 int InsetTabular::latex(Buffer const * buf, ostream & os,
1195 bool fragile, bool fp) const
1197 return tabular->latex(buf, os, fragile, fp);
1201 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1204 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1206 return tabular->ascii(buf, os, 0, false,0);
1210 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1212 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1216 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1221 // if the table is inside a float it doesn't need the informaltable
1222 // wrapper. Search for it.
1223 for(master = owner();
1224 master && master->lyxCode() != Inset::FLOAT_CODE;
1225 master = master->owner());
1228 os << "<informaltable>\n";
1231 ret+= tabular->docBook(buf,os);
1233 os << "</informaltable>\n";
1240 void InsetTabular::validate(LaTeXFeatures & features) const
1242 tabular->Validate(features);
1246 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1247 LyXFont const & font,
1254 bool changed = false;
1256 // if we have a locking_inset we should have to check only this cell for
1257 // change so I'll try this to have a boost, but who knows ;)
1258 if ((need_update != INIT) &&
1259 (the_locking_inset == tabular->GetCellInset(actcell))) {
1260 for(int i = 0; i < tabular->columns(); ++i) {
1261 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1263 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1266 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1267 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1268 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1271 for (int i = 0; i < tabular->rows(); ++i) {
1274 for (int j = 0; j < tabular->columns(); ++j) {
1275 if (tabular->IsPartOfMultiColumn(i,j))
1278 inset = tabular->GetCellInset(cell);
1279 if (!reinit && !tabular->GetPWidth(cell).zero())
1280 inset->update(bv, font, false);
1281 maxAsc = max(maxAsc, inset->ascent(bv, font));
1282 maxDesc = max(maxDesc, inset->descent(bv, font));
1283 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1285 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1286 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1294 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1296 if (the_locking_inset) {
1297 the_locking_inset->getCursorPos(bv, x, y);
1300 x = cursor_.x() - top_x;
1305 void InsetTabular::toggleInsetCursor(BufferView * bv)
1308 if (isCursorVisible())
1309 bv->hideLockedInsetCursor();
1312 if (the_locking_inset) {
1313 the_locking_inset->toggleInsetCursor(bv);
1317 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1319 int const asc = lyxfont::maxAscent(font);
1320 int const desc = lyxfont::maxDescent(font);
1322 if (isCursorVisible())
1323 bv->hideLockedInsetCursor();
1325 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1326 toggleCursorVisible();
1330 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1334 if (!isCursorVisible()) {
1335 LyXFont font; // = GetFont(par, cursor.pos);
1337 int const asc = lyxfont::maxAscent(font);
1338 int const desc = lyxfont::maxDescent(font);
1339 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1341 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1342 setCursorVisible(true);
1347 void InsetTabular::hideInsetCursor(BufferView * bv)
1349 if (isCursorVisible()) {
1350 bv->hideLockedInsetCursor();
1351 setCursorVisible(false);
1356 void InsetTabular::fitInsetCursor(BufferView * bv) const
1358 if (the_locking_inset) {
1359 the_locking_inset->fitInsetCursor(bv);
1364 int const asc = lyxfont::maxAscent(font);
1365 int const desc = lyxfont::maxDescent(font);
1366 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1370 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1374 actcell = actrow = actcol = 0;
1375 int ly = tabular->GetDescentOfRow(actrow);
1377 // first search the right row
1378 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1379 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1380 tabular->GetAscentOfRow(actrow + 1) +
1381 tabular->GetAdditionalHeight(actrow + 1));
1383 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1385 actcell = tabular->GetCellNumber(actrow, actcol);
1387 // now search the right column
1388 int lx = tabular->GetWidthOfColumn(actcell) -
1389 tabular->GetAdditionalWidth(actcell);
1390 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1391 lx += tabular->GetWidthOfColumn(actcell + 1)
1392 + tabular->GetAdditionalWidth(actcell);
1394 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1399 int InsetTabular::getCellXPos(int cell) const
1403 for (; !tabular->IsFirstCellInRow(c); --c)
1405 int lx = tabular->GetWidthOfColumn(cell);
1406 for (; c < cell; ++c) {
1407 lx += tabular->GetWidthOfColumn(c);
1409 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1413 void InsetTabular::resetPos(BufferView * bv) const
1415 #warning This should be fixed in the right manner (20011128 Jug)
1416 // fast hack to fix infinite repaintings!
1421 actcol = tabular->column_of_cell(actcell);
1424 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1425 if (tabular->IsLastCellInRow(cell)) {
1426 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1427 tabular->GetAscentOfRow(actrow + 1) +
1428 tabular->GetAdditionalHeight(actrow + 1));
1432 if (!locked || nodraw()) {
1433 if (the_locking_inset)
1434 inset_y = cursor_.y();
1437 // we need this only from here on!!!
1438 in_reset_pos = true;
1439 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1440 int new_x = getCellXPos(actcell);
1441 int old_x = cursor_.x();
1444 // cursor.x(getCellXPos(actcell) + offset);
1445 if ((actcol < tabular->columns()-1) && scroll(false) &&
1446 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1449 updateLocal(bv, FULL, false);
1450 } else if (the_locking_inset &&
1451 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1453 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1454 if (xx > (bv->workWidth()-20)) {
1455 scroll(bv, -(xx - bv->workWidth() + 60));
1456 updateLocal(bv, FULL, false);
1457 } else if (xx < 20) {
1463 updateLocal(bv, FULL, false);
1465 } else if ((cursor_.x() - offset) > 20 &&
1466 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1467 > (bv->workWidth() - 20)) {
1468 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1469 updateLocal(bv, FULL, false);
1470 } else if ((cursor_.x() - offset) < 20) {
1471 scroll(bv, 20 - cursor_.x() + offset);
1472 updateLocal(bv, FULL, false);
1473 } else if (scroll(false) && top_x > 20 &&
1474 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1475 scroll(bv, old_x - cursor_.x());
1476 updateLocal(bv, FULL, false);
1478 if (the_locking_inset) {
1479 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1480 inset_y = cursor_.y();
1482 if ((!the_locking_inset ||
1483 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1484 actcell != oldcell) {
1485 InsetTabular * inset = const_cast<InsetTabular *>(this);
1486 bv->owner()->getDialogs()->updateTabular(inset);
1489 in_reset_pos = false;
1493 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1495 if (lock && !old_locking_inset) {
1496 if (activateCellInset(bv))
1499 bool moved = isRightToLeft(bv)
1500 ? movePrevCell(bv) : moveNextCell(bv);
1502 return FINISHED_RIGHT;
1503 if (lock && activateCellInset(bv))
1507 return DISPATCHED_NOUPDATE;
1511 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1513 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1516 if (lock) { // behind the inset
1517 if (activateCellInset(bv, 0, 0, 0, true))
1521 return DISPATCHED_NOUPDATE;
1525 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1527 int const ocell = actcell;
1528 actcell = tabular->GetCellAbove(actcell);
1529 if (actcell == ocell) // we moved out of the inset
1535 if (old_locking_inset) {
1536 old_locking_inset->getCursorPos(bv, x, y);
1537 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1539 if (activateCellInset(bv, x, 0))
1542 return DISPATCHED_NOUPDATE;
1546 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1548 int const ocell = actcell;
1549 actcell = tabular->GetCellBelow(actcell);
1550 if (actcell == ocell) // we moved out of the inset
1551 return FINISHED_DOWN;
1556 if (old_locking_inset) {
1557 old_locking_inset->getCursorPos(bv, x, y);
1558 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1560 if (activateCellInset(bv, x, 0))
1563 return DISPATCHED_NOUPDATE;
1567 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1569 if (isRightToLeft(bv)) {
1570 if (tabular->IsFirstCellInRow(actcell)) {
1571 int row = tabular->row_of_cell(actcell);
1572 if (row == tabular->rows() - 1)
1574 actcell = tabular->GetLastCellInRow(row);
1575 actcell = tabular->GetCellBelow(actcell);
1582 if (tabular->IsLastCell(actcell))
1587 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1588 isRightToLeftPar(bv->buffer()->params);
1589 activateCellInset(bv, 0, 0, 0, !rtl);
1596 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1598 if (isRightToLeft(bv)) {
1599 if (tabular->IsLastCellInRow(actcell)) {
1600 int row = tabular->row_of_cell(actcell);
1603 actcell = tabular->GetFirstCellInRow(row);
1604 actcell = tabular->GetCellAbove(actcell);
1606 if (tabular->IsLastCell(actcell))
1611 if (!actcell) // first cell
1616 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1617 isRightToLeftPar(bv->buffer()->params);
1618 activateCellInset(bv, 0, 0, 0, !rtl);
1625 bool InsetTabular::deletable() const
1631 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1635 setSelection(0, tabular->GetNumberOfCells() - 1);
1637 if (hasSelection()) {
1638 setUndo(bv, Undo::EDIT,
1639 bv->text->cursor.par(),
1640 bv->text->cursor.par()->next());
1641 bool frozen = undo_frozen;
1644 // apply the fontchange on the whole selection
1649 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1650 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1651 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1652 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1657 updateLocal(bv, INIT, true);
1659 if (the_locking_inset)
1660 the_locking_inset->setFont(bv, font, tall);
1664 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1666 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1669 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1670 string const tmp = tabularFeature[i].feature;
1672 if (tmp == what.substr(0, tmp.length())) {
1673 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1674 //tabularFeatures[i].feature.length())) {
1675 action = tabularFeature[i].action;
1679 if (action == LyXTabular::LAST_ACTION)
1683 frontStrip(what.substr(tabularFeature[i].feature.length()));
1684 tabularFeatures(bv, action, val);
1688 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1689 string const & special, bool & flag)
1691 if (special == "dl_above") {
1694 } else if (special == "dl_below") {
1695 ltt.bottomDL = flag;
1697 } else if (special == "empty") {
1707 void InsetTabular::tabularFeatures(BufferView * bv,
1708 LyXTabular::Feature feature,
1709 string const & value)
1715 bool setLines = false;
1716 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1717 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1720 case LyXTabular::M_ALIGN_LEFT:
1721 case LyXTabular::ALIGN_LEFT:
1722 setAlign = LYX_ALIGN_LEFT;
1724 case LyXTabular::M_ALIGN_RIGHT:
1725 case LyXTabular::ALIGN_RIGHT:
1726 setAlign = LYX_ALIGN_RIGHT;
1728 case LyXTabular::M_ALIGN_CENTER:
1729 case LyXTabular::ALIGN_CENTER:
1730 setAlign = LYX_ALIGN_CENTER;
1732 case LyXTabular::M_VALIGN_TOP:
1733 case LyXTabular::VALIGN_TOP:
1734 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1736 case LyXTabular::M_VALIGN_BOTTOM:
1737 case LyXTabular::VALIGN_BOTTOM:
1738 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1740 case LyXTabular::M_VALIGN_CENTER:
1741 case LyXTabular::VALIGN_CENTER:
1742 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1747 if (hasSelection()) {
1748 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1750 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1751 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1753 setUndo(bv, Undo::FINISH,
1754 bv->text->cursor.par(),
1755 bv->text->cursor.par()->next());
1757 int row = tabular->row_of_cell(actcell);
1758 int column = tabular->column_of_cell(actcell);
1760 LyXTabular::ltType ltt;
1763 case LyXTabular::SET_PWIDTH:
1765 LyXLength const vallen(value);
1766 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1768 bool const update = (tmplen != vallen);
1769 tabular->SetColumnPWidth(actcell, vallen);
1772 for (int i = 0; i < tabular->rows(); ++i) {
1773 cell = tabular->GetCellNumber(i,column);
1774 tabular->GetCellInset(cell)->resizeLyXText(bv);
1776 updateLocal(bv, INIT, true);
1780 case LyXTabular::SET_MPWIDTH:
1782 LyXLength const vallen(value);
1783 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1785 bool const update = (tmplen != vallen);
1786 tabular->SetMColumnPWidth(actcell, vallen);
1788 for (int i = 0; i < tabular->rows(); ++i) {
1789 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1792 updateLocal(bv, INIT, true);
1796 case LyXTabular::SET_SPECIAL_COLUMN:
1797 case LyXTabular::SET_SPECIAL_MULTI:
1798 tabular->SetAlignSpecial(actcell,value,feature);
1799 updateLocal(bv, FULL, true);
1801 case LyXTabular::APPEND_ROW:
1802 // append the row into the tabular
1803 unlockInsetInInset(bv, the_locking_inset);
1804 tabular->AppendRow(actcell);
1805 updateLocal(bv, INIT, true);
1807 case LyXTabular::APPEND_COLUMN:
1808 // append the column into the tabular
1809 unlockInsetInInset(bv, the_locking_inset);
1810 tabular->AppendColumn(actcell);
1811 actcell = tabular->GetCellNumber(row, column);
1812 updateLocal(bv, INIT, true);
1814 case LyXTabular::DELETE_ROW:
1815 unlockInsetInInset(bv, the_locking_inset);
1816 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1817 tabular->DeleteRow(sel_row_start);
1819 if (sel_row_start >= tabular->rows())
1821 actcell = tabular->GetCellNumber(sel_row_start, column);
1823 updateLocal(bv, INIT, true);
1825 case LyXTabular::DELETE_COLUMN:
1826 unlockInsetInInset(bv, the_locking_inset);
1827 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1828 tabular->DeleteColumn(sel_col_start);
1830 if (sel_col_start >= tabular->columns())
1832 actcell = tabular->GetCellNumber(row, sel_col_start);
1834 updateLocal(bv, INIT, true);
1836 case LyXTabular::M_TOGGLE_LINE_TOP:
1838 case LyXTabular::TOGGLE_LINE_TOP:
1840 bool lineSet = !tabular->TopLine(actcell, flag);
1841 for (int i = sel_row_start; i <= sel_row_end; ++i)
1842 for (int j = sel_col_start; j <= sel_col_end; ++j)
1843 tabular->SetTopLine(
1844 tabular->GetCellNumber(i, j),
1846 updateLocal(bv, INIT, true);
1850 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1852 case LyXTabular::TOGGLE_LINE_BOTTOM:
1854 bool lineSet = !tabular->BottomLine(actcell, flag);
1855 for (int i = sel_row_start; i <= sel_row_end; ++i)
1856 for (int j = sel_col_start; j <= sel_col_end; ++j)
1857 tabular->SetBottomLine(
1858 tabular->GetCellNumber(i, j),
1861 updateLocal(bv, INIT, true);
1865 case LyXTabular::M_TOGGLE_LINE_LEFT:
1867 case LyXTabular::TOGGLE_LINE_LEFT:
1869 bool lineSet = !tabular->LeftLine(actcell, flag);
1870 for (int i = sel_row_start; i <= sel_row_end; ++i)
1871 for (int j = sel_col_start; j <= sel_col_end; ++j)
1872 tabular->SetLeftLine(
1873 tabular->GetCellNumber(i,j),
1876 updateLocal(bv, INIT, true);
1880 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1882 case LyXTabular::TOGGLE_LINE_RIGHT:
1884 bool lineSet = !tabular->RightLine(actcell, flag);
1885 for (int i = sel_row_start; i <= sel_row_end; ++i)
1886 for (int j = sel_col_start; j <= sel_col_end; ++j)
1887 tabular->SetRightLine(
1888 tabular->GetCellNumber(i,j),
1891 updateLocal(bv, INIT, true);
1895 case LyXTabular::M_ALIGN_LEFT:
1896 case LyXTabular::M_ALIGN_RIGHT:
1897 case LyXTabular::M_ALIGN_CENTER:
1899 case LyXTabular::ALIGN_LEFT:
1900 case LyXTabular::ALIGN_RIGHT:
1901 case LyXTabular::ALIGN_CENTER:
1902 for (int i = sel_row_start; i <= sel_row_end; ++i)
1903 for (int j = sel_col_start; j <= sel_col_end; ++j)
1904 tabular->SetAlignment(
1905 tabular->GetCellNumber(i, j),
1908 updateLocal(bv, INIT, true);
1910 case LyXTabular::M_VALIGN_TOP:
1911 case LyXTabular::M_VALIGN_BOTTOM:
1912 case LyXTabular::M_VALIGN_CENTER:
1914 case LyXTabular::VALIGN_TOP:
1915 case LyXTabular::VALIGN_BOTTOM:
1916 case LyXTabular::VALIGN_CENTER:
1917 for (int i = sel_row_start; i <= sel_row_end; ++i)
1918 for (int j = sel_col_start; j <= sel_col_end; ++j)
1919 tabular->SetVAlignment(
1920 tabular->GetCellNumber(i, j),
1922 updateLocal(bv, INIT, true);
1924 case LyXTabular::MULTICOLUMN:
1926 if (sel_row_start != sel_row_end) {
1927 Alert::alert(_("Impossible Operation!"),
1928 _("Multicolumns can only be horizontally."),
1932 // just multicol for one Single Cell
1933 if (!hasSelection()) {
1934 // check wether we are completly in a multicol
1935 if (tabular->IsMultiColumn(actcell)) {
1936 tabular->UnsetMultiColumn(actcell);
1937 updateLocal(bv, INIT, true);
1939 tabular->SetMultiColumn(actcell, 1);
1940 updateLocal(bv, CELL, true);
1944 // we have a selection so this means we just add all this
1945 // cells to form a multicolumn cell
1949 if (sel_cell_start > sel_cell_end) {
1950 s_start = sel_cell_end;
1951 s_end = sel_cell_start;
1953 s_start = sel_cell_start;
1954 s_end = sel_cell_end;
1956 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1959 updateLocal(bv, INIT, true);
1962 case LyXTabular::SET_ALL_LINES:
1964 case LyXTabular::UNSET_ALL_LINES:
1965 for (int i = sel_row_start; i <= sel_row_end; ++i)
1966 for (int j = sel_col_start; j <= sel_col_end; ++j)
1967 tabular->SetAllLines(
1968 tabular->GetCellNumber(i,j), setLines);
1969 updateLocal(bv, INIT, true);
1971 case LyXTabular::SET_LONGTABULAR:
1972 tabular->SetLongTabular(true);
1973 updateLocal(bv, INIT, true); // because this toggles displayed
1975 case LyXTabular::UNSET_LONGTABULAR:
1976 tabular->SetLongTabular(false);
1977 updateLocal(bv, INIT, true); // because this toggles displayed
1979 case LyXTabular::SET_ROTATE_TABULAR:
1980 tabular->SetRotateTabular(true);
1982 case LyXTabular::UNSET_ROTATE_TABULAR:
1983 tabular->SetRotateTabular(false);
1985 case LyXTabular::SET_ROTATE_CELL:
1986 for (int i = sel_row_start; i <= sel_row_end; ++i)
1987 for (int j = sel_col_start; j<=sel_col_end; ++j)
1988 tabular->SetRotateCell(
1989 tabular->GetCellNumber(i, j),
1992 case LyXTabular::UNSET_ROTATE_CELL:
1993 for (int i = sel_row_start; i <= sel_row_end; ++i)
1994 for (int j = sel_col_start; j <= sel_col_end; ++j)
1995 tabular->SetRotateCell(
1996 tabular->GetCellNumber(i, j), false);
1998 case LyXTabular::SET_USEBOX:
2000 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2001 if (val == tabular->GetUsebox(actcell))
2002 val = LyXTabular::BOX_NONE;
2003 for (int i = sel_row_start; i <= sel_row_end; ++i)
2004 for (int j = sel_col_start; j <= sel_col_end; ++j)
2006 tabular->GetCellNumber(i, j), val);
2009 case LyXTabular::UNSET_LTFIRSTHEAD:
2011 case LyXTabular::SET_LTFIRSTHEAD:
2012 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2013 checkLongtableSpecial(ltt, value, flag);
2014 tabular->SetLTHead(row, flag, ltt, true);
2016 case LyXTabular::UNSET_LTHEAD:
2018 case LyXTabular::SET_LTHEAD:
2019 (void)tabular->GetRowOfLTHead(row, ltt);
2020 checkLongtableSpecial(ltt, value, flag);
2021 tabular->SetLTHead(row, flag, ltt, false);
2023 case LyXTabular::UNSET_LTFOOT:
2025 case LyXTabular::SET_LTFOOT:
2026 (void)tabular->GetRowOfLTFoot(row, ltt);
2027 checkLongtableSpecial(ltt, value, flag);
2028 tabular->SetLTFoot(row, flag, ltt, false);
2030 case LyXTabular::UNSET_LTLASTFOOT:
2032 case LyXTabular::SET_LTLASTFOOT:
2033 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2034 checkLongtableSpecial(ltt, value, flag);
2035 tabular->SetLTFoot(row, flag, ltt, true);
2037 case LyXTabular::SET_LTNEWPAGE:
2039 bool what = !tabular->GetLTNewPage(row);
2040 tabular->SetLTNewPage(row, what);
2043 // dummy stuff just to avoid warnings
2044 case LyXTabular::LAST_ACTION:
2050 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2053 UpdatableInset * inset =
2054 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2055 LyXFont font(LyXFont::ALL_SANE);
2057 x = inset->x() + inset->width(bv, font);
2058 y = inset->descent(bv, font);
2060 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2061 //inset_y = cursor.y();
2062 inset->edit(bv, x, y, button);
2063 if (!the_locking_inset)
2065 updateLocal(bv, CELL, false);
2066 return (the_locking_inset != 0);
2070 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2073 inset_x = cursor_.x()
2074 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2075 inset_y = cursor_.y();
2076 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2080 bool InsetTabular::insetHit(BufferView *, int x, int) const
2083 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2087 // This returns paperWidth() if the cell-width is unlimited or the width
2088 // in pixels if we have a pwidth for this cell.
2089 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2091 LyXLength const len = tabular->GetPWidth(cell);
2095 #ifdef WITH_WARNINGS
2096 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2098 return VSpace(len).inPixels(bv);
2102 int InsetTabular::getMaxWidth(BufferView * bv,
2103 UpdatableInset const * inset) const
2105 int cell = tabular->cur_cell;
2106 if (tabular->GetCellInset(cell) != inset) {
2108 if (tabular->GetCellInset(cell) != inset) {
2110 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2115 int const n = tabular->GetNumberOfCells();
2118 for (cell = 0; cell < n; ++cell) {
2119 if (tabular->GetCellInset(cell) == inset)
2125 lyxerr << "Own inset not found, shouldn't really happen!\n";
2129 int w = getMaxWidthOfCell(bv, cell);
2131 // because the inset then subtracts it's top_x and owner->x()
2132 w += (inset->x() - top_x);
2139 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2141 resizeLyXText(bv, recursive);
2145 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2148 for(int i = 0; i < tabular->rows(); ++i) {
2149 for(int j = 0; j < tabular->columns(); ++j) {
2150 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2158 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2159 bool const recursive) const
2161 if (the_locking_inset)
2162 return the_locking_inset->getLyXText(bv, recursive);
2164 // if we're locked lock the actual insettext and return it's LyXText!!!
2166 UpdatableInset * inset =
2167 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2168 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2169 return the_locking_inset->getLyXText(bv, recursive);
2172 return Inset::getLyXText(bv, recursive);
2176 bool InsetTabular::showInsetDialog(BufferView * bv) const
2178 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2179 bv->owner()->getDialogs()
2180 ->showTabular(const_cast<InsetTabular *>(this));
2185 void InsetTabular::openLayoutDialog(BufferView * bv) const
2187 if (the_locking_inset) {
2188 InsetTabular * i = static_cast<InsetTabular *>
2189 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2191 i->openLayoutDialog(bv);
2195 bv->owner()->getDialogs()->showTabular(
2196 const_cast<InsetTabular *>(this));
2201 // functions returns:
2205 // 3 ... toggled off
2207 func_status::value_type InsetTabular::getStatus(string const & what) const
2209 int action = LyXTabular::LAST_ACTION;
2210 func_status::value_type status = func_status::OK;
2213 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2214 string const tmp = tabularFeature[i].feature;
2215 if (tmp == what.substr(0, tmp.length())) {
2216 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2217 // tabularFeatures[i].feature.length())) {
2218 action = tabularFeature[i].action;
2222 if (action == LyXTabular::LAST_ACTION)
2223 return func_status::Unknown;
2225 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2230 LyXTabular::ltType dummyltt;
2233 if (hasSelection()) {
2234 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2236 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2240 case LyXTabular::SET_PWIDTH:
2241 case LyXTabular::SET_MPWIDTH:
2242 case LyXTabular::SET_SPECIAL_COLUMN:
2243 case LyXTabular::SET_SPECIAL_MULTI:
2244 status |= func_status::Disabled;
2247 case LyXTabular::APPEND_ROW:
2248 case LyXTabular::APPEND_COLUMN:
2249 case LyXTabular::DELETE_ROW:
2250 case LyXTabular::DELETE_COLUMN:
2251 case LyXTabular::SET_ALL_LINES:
2252 case LyXTabular::UNSET_ALL_LINES:
2253 status |= func_status::OK;
2256 case LyXTabular::MULTICOLUMN:
2257 if (tabular->IsMultiColumn(actcell))
2258 status |= func_status::ToggleOn;
2260 status |= func_status::ToggleOff;
2262 case LyXTabular::M_TOGGLE_LINE_TOP:
2264 case LyXTabular::TOGGLE_LINE_TOP:
2265 if (tabular->TopLine(actcell, flag))
2266 status |= func_status::ToggleOn;
2268 status |= func_status::ToggleOff;
2270 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2272 case LyXTabular::TOGGLE_LINE_BOTTOM:
2273 if (tabular->BottomLine(actcell, flag))
2274 status |= func_status::ToggleOn;
2276 status |= func_status::ToggleOff;
2278 case LyXTabular::M_TOGGLE_LINE_LEFT:
2280 case LyXTabular::TOGGLE_LINE_LEFT:
2281 if (tabular->LeftLine(actcell, flag))
2282 status |= func_status::ToggleOn;
2284 status |= func_status::ToggleOff;
2286 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2288 case LyXTabular::TOGGLE_LINE_RIGHT:
2289 if (tabular->RightLine(actcell, flag))
2290 status |= func_status::ToggleOn;
2292 status |= func_status::ToggleOff;
2294 case LyXTabular::M_ALIGN_LEFT:
2296 case LyXTabular::ALIGN_LEFT:
2297 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2298 status |= func_status::ToggleOn;
2300 status |= func_status::ToggleOff;
2302 case LyXTabular::M_ALIGN_RIGHT:
2304 case LyXTabular::ALIGN_RIGHT:
2305 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2306 status |= func_status::ToggleOn;
2308 status |= func_status::ToggleOff;
2310 case LyXTabular::M_ALIGN_CENTER:
2312 case LyXTabular::ALIGN_CENTER:
2313 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2314 status |= func_status::ToggleOn;
2316 status |= func_status::ToggleOff;
2318 case LyXTabular::M_VALIGN_TOP:
2320 case LyXTabular::VALIGN_TOP:
2321 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2322 status |= func_status::ToggleOn;
2324 status |= func_status::ToggleOff;
2326 case LyXTabular::M_VALIGN_BOTTOM:
2328 case LyXTabular::VALIGN_BOTTOM:
2329 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2330 status |= func_status::ToggleOn;
2332 status |= func_status::ToggleOff;
2334 case LyXTabular::M_VALIGN_CENTER:
2336 case LyXTabular::VALIGN_CENTER:
2337 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2338 status |= func_status::ToggleOn;
2340 status |= func_status::ToggleOff;
2342 case LyXTabular::SET_LONGTABULAR:
2343 if (tabular->IsLongTabular())
2344 status |= func_status::ToggleOn;
2346 status |= func_status::ToggleOff;
2348 case LyXTabular::UNSET_LONGTABULAR:
2349 if (!tabular->IsLongTabular())
2350 status |= func_status::ToggleOn;
2352 status |= func_status::ToggleOff;
2354 case LyXTabular::SET_ROTATE_TABULAR:
2355 if (tabular->GetRotateTabular())
2356 status |= func_status::ToggleOn;
2358 status |= func_status::ToggleOff;
2360 case LyXTabular::UNSET_ROTATE_TABULAR:
2361 if (!tabular->GetRotateTabular())
2362 status |= func_status::ToggleOn;
2364 status |= func_status::ToggleOff;
2366 case LyXTabular::SET_ROTATE_CELL:
2367 if (tabular->GetRotateCell(actcell))
2368 status |= func_status::ToggleOn;
2370 status |= func_status::ToggleOff;
2372 case LyXTabular::UNSET_ROTATE_CELL:
2373 if (!tabular->GetRotateCell(actcell))
2374 status |= func_status::ToggleOn;
2376 status |= func_status::ToggleOff;
2378 case LyXTabular::SET_USEBOX:
2379 if (strToInt(argument) == tabular->GetUsebox(actcell))
2380 status |= func_status::ToggleOn;
2382 status |= func_status::ToggleOff;
2384 case LyXTabular::SET_LTFIRSTHEAD:
2385 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2386 status |= func_status::ToggleOn;
2388 status |= func_status::ToggleOff;
2390 case LyXTabular::SET_LTHEAD:
2391 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2392 status |= func_status::ToggleOn;
2394 status |= func_status::ToggleOff;
2396 case LyXTabular::SET_LTFOOT:
2397 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2398 status |= func_status::ToggleOn;
2400 status |= func_status::ToggleOff;
2402 case LyXTabular::SET_LTLASTFOOT:
2403 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2404 status |= func_status::ToggleOn;
2406 status |= func_status::ToggleOff;
2408 case LyXTabular::SET_LTNEWPAGE:
2409 if (tabular->GetLTNewPage(sel_row_start))
2410 status |= func_status::ToggleOn;
2412 status |= func_status::ToggleOff;
2415 status = func_status::Disabled;
2422 std::vector<string> const InsetTabular::getLabelList() const
2424 return tabular->getLabelList();
2428 bool InsetTabular::copySelection(BufferView * bv)
2430 if (!hasSelection())
2433 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2434 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2435 if (sel_col_start > sel_col_end) {
2436 sel_col_start = sel_col_end;
2437 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2439 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2441 int const columns = sel_col_end - sel_col_start + 1;
2443 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2444 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2445 if (sel_row_start > sel_row_end) {
2446 swap(sel_row_start, sel_row_end);
2448 int const rows = sel_row_end - sel_row_start + 1;
2450 delete paste_tabular;
2451 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2452 for (int i = 0; i < sel_row_start; ++i)
2453 paste_tabular->DeleteRow(0);
2454 while (paste_tabular->rows() > rows)
2455 paste_tabular->DeleteRow(rows);
2456 paste_tabular->SetTopLine(0, true, true);
2457 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2459 for (int i = 0; i < sel_col_start; ++i)
2460 paste_tabular->DeleteColumn(0);
2461 while (paste_tabular->columns() > columns)
2462 paste_tabular->DeleteColumn(columns);
2463 paste_tabular->SetLeftLine(0, true, true);
2464 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2468 paste_tabular->ascii(bv->buffer(), sstr,
2469 (int)parOwner()->params().depth(), true, '\t');
2470 bv->stuffClipboard(sstr.str().c_str());
2475 bool InsetTabular::pasteSelection(BufferView * bv)
2480 for (int r1 = 0, r2 = actrow;
2481 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2483 for(int c1 = 0, c2 = actcol;
2484 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2486 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2487 tabular->IsPartOfMultiColumn(r2,c2))
2489 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2493 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2497 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2498 int const n2 = tabular->GetCellNumber(r2, c2);
2499 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2500 tabular->GetCellInset(n2)->setOwner(this);
2501 tabular->GetCellInset(n2)->deleteLyXText(bv);
2508 bool InsetTabular::cutSelection()
2510 if (!hasSelection())
2513 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2514 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2515 if (sel_col_start > sel_col_end) {
2516 sel_col_start = sel_col_end;
2517 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2519 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2521 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2522 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2523 if (sel_row_start > sel_row_end) {
2524 swap(sel_row_start, sel_row_end);
2526 if (sel_cell_start > sel_cell_end) {
2527 swap(sel_cell_start, sel_cell_end);
2529 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2530 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2531 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2538 bool InsetTabular::isRightToLeft(BufferView *bv )
2540 return bv->getParentLanguage(this)->RightToLeft();
2544 bool InsetTabular::nodraw() const
2546 if (!UpdatableInset::nodraw() && the_locking_inset)
2547 return the_locking_inset->nodraw();
2548 return UpdatableInset::nodraw();
2552 int InsetTabular::scroll(bool recursive) const
2554 int sx = UpdatableInset::scroll(false);
2556 if (recursive && the_locking_inset)
2557 sx += the_locking_inset->scroll(recursive);
2563 bool InsetTabular::doClearArea() const
2565 return !locked || (need_update & (FULL|INIT));
2569 void InsetTabular::getSelection(int & srow, int & erow,
2570 int & scol, int & ecol) const
2572 int const start = hasSelection() ? sel_cell_start : actcell;
2573 int const end = hasSelection() ? sel_cell_end : actcell;
2575 srow = tabular->row_of_cell(start);
2576 erow = tabular->row_of_cell(end);
2581 scol = tabular->column_of_cell(start);
2582 ecol = tabular->column_of_cell(end);
2586 ecol = tabular->right_column_of_cell(end);
2591 Paragraph * InsetTabular::getParFromID(int id) const
2594 for(int i = 0; i < tabular->rows(); ++i) {
2595 for(int j = 0; j < tabular->columns(); ++j) {
2596 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2604 Paragraph * InsetTabular::firstParagraph() const
2606 if (the_locking_inset)
2607 return the_locking_inset->firstParagraph();
2612 Paragraph * InsetTabular::getFirstParagraph(int i) const
2614 return (i < tabular->GetNumberOfCells())
2615 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2620 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2622 if (the_locking_inset)
2623 return the_locking_inset->cursor(bv);
2624 return Inset::cursor(bv);
2628 Inset * InsetTabular::getInsetFromID(int id_arg) const
2631 return const_cast<InsetTabular *>(this);
2634 for(int i = 0; i < tabular->rows(); ++i) {
2635 for(int j = 0; j < tabular->columns(); ++j) {
2636 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2645 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2648 if (the_locking_inset) {
2649 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2654 if (tabular->IsLastCell(actcell)) {
2655 bv->unlockInset(const_cast<InsetTabular *>(this));
2661 // otherwise we have to lock the next inset and ask for it's selecttion
2662 UpdatableInset * inset =
2663 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2664 inset->edit(bv, 0, 0, 0);
2665 string const str(selectNextWordInt(bv, value));
2673 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2675 // when entering this function the inset should be ALWAYS locked!
2676 lyx::Assert(the_locking_inset);
2678 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2682 if (tabular->IsLastCell(actcell)) {
2683 bv->unlockInset(const_cast<InsetTabular *>(this));
2687 // otherwise we have to lock the next inset and ask for it's selecttion
2688 UpdatableInset * inset =
2689 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2691 return selectNextWordInt(bv, value);
2695 void InsetTabular::selectSelectedWord(BufferView * bv)
2697 if (the_locking_inset) {
2698 the_locking_inset->selectSelectedWord(bv);
2705 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2707 if (the_locking_inset) {
2708 the_locking_inset->toggleSelection(bv, kill_selection);
2713 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2714 bool const & cs, bool const & mw)
2717 if (the_locking_inset) {
2718 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2720 updateLocal(bv, CELL, false);
2723 if (tabular->IsLastCell(actcell)) {
2725 bv->unlockInset(const_cast<InsetTabular *>(this));
2730 // otherwise we have to lock the next inset and search there
2731 UpdatableInset * inset =
2732 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2734 bool const ret = searchForward(bv, str, cs, mw);
2736 updateLocal(bv, CELL, false);
2741 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2742 bool const & cs, bool const & mw)
2745 if (the_locking_inset) {
2746 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2748 updateLocal(bv, CELL, false);
2751 if (!actcell) { // we are already in the first cell
2753 bv->unlockInset(const_cast<InsetTabular *>(this));
2758 // otherwise we have to lock the next inset and search there
2759 UpdatableInset * inset =
2760 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2761 inset->edit(bv, false);
2762 bool const ret = searchBackward(bv, str, cs, mw);
2764 updateLocal(bv, CELL, false);
2769 bool InsetTabular::insetAllowed(Inset::Code code) const
2771 if (the_locking_inset)
2772 return the_locking_inset->insetAllowed(code);