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"
28 #include "insets/insettext.h"
33 #include "BufferView.h"
34 #include "undo_funcs.h"
35 #include "lyxlength.h"
36 #include "ParagraphParameters.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/Alert.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
61 int const ADD_TO_HEIGHT = 2;
62 int const ADD_TO_TABULAR_WIDTH = 2;
65 LyXTabular * paste_tabular = 0;
68 struct TabularFeature {
69 LyXTabular::Feature action;
74 TabularFeature tabularFeature[] =
76 { LyXTabular::APPEND_ROW, "append-row" },
77 { LyXTabular::APPEND_COLUMN, "append-column" },
78 { LyXTabular::DELETE_ROW, "delete-row" },
79 { LyXTabular::DELETE_COLUMN, "delete-column" },
80 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
81 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
82 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
83 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
84 { LyXTabular::ALIGN_LEFT, "align-left" },
85 { LyXTabular::ALIGN_RIGHT, "align-right" },
86 { LyXTabular::ALIGN_CENTER, "align-center" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
125 bool InsetTabular::hasPasteBuffer() const
127 return (paste_tabular != 0);
131 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
138 tabular.reset(new LyXTabular(this, rows, columns));
139 // for now make it always display as display() inset
141 the_locking_inset = 0;
142 old_locking_inset = 0;
145 actrow = actcell = 0;
149 in_reset_pos = false;
155 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
157 : UpdatableInset(tab, same_id), buffer(&buf)
159 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
160 the_locking_inset = 0;
161 old_locking_inset = 0;
164 actrow = actcell = 0;
168 in_reset_pos = false;
174 InsetTabular::~InsetTabular()
180 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
182 return new InsetTabular(*this, buf, same_id);
186 void InsetTabular::write(Buffer const * buf, ostream & os) const
188 os << " Tabular" << endl;
189 tabular->Write(buf, os);
193 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
195 bool const old_format = (lex.getString() == "\\LyXTable");
197 tabular.reset(new LyXTabular(buf, this, lex));
205 string token = lex.getString();
206 while (lex.isOK() && (token != "\\end_inset")) {
208 token = lex.getString();
210 if (token != "\\end_inset") {
211 lex.printError("Missing \\end_inset at this point. "
217 int InsetTabular::ascent(BufferView *, LyXFont const &) const
219 return tabular->GetAscentOfRow(0);
223 int InsetTabular::descent(BufferView *, LyXFont const &) const
225 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
229 int InsetTabular::width(BufferView *, LyXFont const &) const
231 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
235 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
236 float & x, bool cleared) const
244 if (need_update == INIT) {
245 if (calculate_dimensions_of_cells(bv, font, true))
246 bv->text->status = LyXText::CHANGED_IN_DRAW;
251 Painter & pain = bv->painter();
257 UpdatableInset::draw(bv, font, baseline, x, cleared);
260 x += static_cast<float>(scroll());
262 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
263 (top_x != int(x)) || (top_baseline != baseline)))
265 int h = ascent(bv, font) + descent(bv, font);
266 int const tx = display() || !owner() ? 0 : top_x;
267 int w = tx ? width(bv, font) : pain.paperWidth();
268 int ty = baseline - ascent(bv, font);
272 if ((ty + h) > pain.paperHeight())
273 h = pain.paperHeight();
274 if ((top_x + w) > pain.paperWidth())
275 w = pain.paperWidth();
276 pain.fillRectangle(tx, ty, w, h, backgroundColor());
282 top_baseline = baseline;
283 x += ADD_TO_TABULAR_WIDTH;
287 first_visible_cell = -1;
288 for (i = 0; i < tabular->rows(); ++i) {
290 cell = tabular->GetCellNumber(i, 0);
291 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
292 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
294 baseline += tabular->GetDescentOfRow(i) +
295 tabular->GetAscentOfRow(i + 1) +
296 tabular->GetAdditionalHeight(i + 1);
299 for (j = 0; j < tabular->columns(); ++j) {
300 if (nx > bv->workWidth())
302 if (tabular->IsPartOfMultiColumn(i, j))
304 cx = nx + tabular->GetBeginningOfTextInCell(cell);
305 if (first_visible_cell < 0)
306 first_visible_cell = cell;
307 if (hasSelection()) {
308 drawCellSelection(pain, nx, baseline, i, j, cell);
311 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
312 drawCellLines(pain, nx, baseline, i, cell);
313 nx += tabular->GetWidthOfColumn(cell);
316 baseline += tabular->GetDescentOfRow(i) +
317 tabular->GetAscentOfRow(i + 1) +
318 tabular->GetAdditionalHeight(i + 1);
320 } else if (need_update == CELL) {
323 if (the_locking_inset &&
324 tabular->GetCellInset(actcell) != the_locking_inset)
326 Inset * inset = tabular->GetCellInset(cell);
328 inset != the_locking_inset && i < tabular->rows();
332 inset != the_locking_inset && j < tabular->columns();
335 if (tabular->IsPartOfMultiColumn(i, j))
337 nx += tabular->GetWidthOfColumn(cell);
339 inset = tabular->GetCellInset(cell);
341 if (tabular->row_of_cell(cell) > i) {
343 baseline += tabular->GetDescentOfRow(i) +
344 tabular->GetAscentOfRow(i + 1) +
345 tabular->GetAdditionalHeight(i + 1);
349 // compute baseline for actual row
350 for (i = 0; i < actrow; ++i) {
351 baseline += tabular->GetDescentOfRow(i) +
352 tabular->GetAscentOfRow(i + 1) +
353 tabular->GetAdditionalHeight(i + 1);
355 // now compute the right x position
356 cell = tabular->GetCellNumber(actrow, 0);
357 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
358 if (tabular->IsPartOfMultiColumn(actrow, j))
360 nx += tabular->GetWidthOfColumn(cell);
364 i = tabular->row_of_cell(cell);
365 if (the_locking_inset != tabular->GetCellInset(cell)) {
366 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
369 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
371 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
373 // Here we use rectangular backgroundColor patches to clean up
374 // within a cell around the cell's red inset box. As follows:
376 // +--------------------+
377 // | C | The rectangles are A, B and C
378 // | A |------------| B | below, origin top left (tx, ty),
379 // | | inset box | | dimensions w(idth), h(eight).
380 // +---+------------+---+ x grows rightward, y downward
382 // +--------------------+
385 // clear only if we didn't have a change
386 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
388 // clear before the inset
391 ty = baseline - tabular->GetAscentOfRow(i) + 1;
392 w = int(cx - nx - 1);
393 h = tabular->GetAscentOfRow(i) +
394 tabular->GetDescentOfRow(i) - 1;
395 pain.fillRectangle(tx, ty, w, h, backgroundColor());
396 // clear behind the inset
397 tx = int(cx + the_locking_inset->width(bv,font) + 1);
398 ty = baseline - tabular->GetAscentOfRow(i) + 1;
399 w = tabular->GetWidthOfColumn(cell) -
400 tabular->GetBeginningOfTextInCell(cell) -
401 the_locking_inset->width(bv,font) -
402 tabular->GetAdditionalWidth(cell) - 1;
403 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
404 pain.fillRectangle(tx, ty, w, h, backgroundColor());
405 // clear below the inset
407 ty = baseline + the_locking_inset->descent(bv, font) + 1;
408 w = tabular->GetWidthOfColumn(cell) -
409 tabular->GetAdditionalWidth(cell) - 1;
410 h = tabular->GetDescentOfRow(i) -
411 the_locking_inset->descent(bv, font) - 1;
412 pain.fillRectangle(tx, ty, w, h, backgroundColor());
413 // clear above the inset
415 ty = baseline - tabular->GetAscentOfRow(i) + 1;
416 w = tabular->GetWidthOfColumn(cell) -
417 tabular->GetAdditionalWidth(cell) - 1;
418 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
419 pain.fillRectangle(tx, ty, w, h, backgroundColor());
424 x -= ADD_TO_TABULAR_WIDTH;
425 x += width(bv, font);
426 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
428 for(Inset * inset = owner(); inset; ++i)
429 inset = inset->owner();
430 if (calculate_dimensions_of_cells(bv, font, false))
438 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
439 int row, int cell) const
441 int x2 = x + tabular->GetWidthOfColumn(cell);
444 if (!tabular->TopAlreadyDrawed(cell)) {
445 on_off = !tabular->TopLine(cell);
446 pain.line(x, baseline - tabular->GetAscentOfRow(row),
447 x2, baseline - tabular->GetAscentOfRow(row),
448 on_off ? LColor::tabularonoffline : LColor::tabularline,
449 on_off ? Painter::line_onoffdash : Painter::line_solid);
451 on_off = !tabular->BottomLine(cell);
452 pain.line(x,baseline + tabular->GetDescentOfRow(row),
453 x2, baseline + tabular->GetDescentOfRow(row),
454 on_off ? LColor::tabularonoffline : LColor::tabularline,
455 on_off ? Painter::line_onoffdash : Painter::line_solid);
456 if (!tabular->LeftAlreadyDrawed(cell)) {
457 on_off = !tabular->LeftLine(cell);
458 pain.line(x, baseline - tabular->GetAscentOfRow(row),
459 x, baseline + tabular->GetDescentOfRow(row),
460 on_off ? LColor::tabularonoffline : LColor::tabularline,
461 on_off ? Painter::line_onoffdash : Painter::line_solid);
463 on_off = !tabular->RightLine(cell);
464 pain.line(x2 - tabular->GetAdditionalWidth(cell),
465 baseline - tabular->GetAscentOfRow(row),
466 x2 - tabular->GetAdditionalWidth(cell),
467 baseline + tabular->GetDescentOfRow(row),
468 on_off ? LColor::tabularonoffline : LColor::tabularline,
469 on_off ? Painter::line_onoffdash : Painter::line_solid);
473 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
474 int row, int column, int cell) const
476 lyx::Assert(hasSelection());
477 int cs = tabular->column_of_cell(sel_cell_start);
478 int ce = tabular->column_of_cell(sel_cell_end);
481 cs = tabular->column_of_cell(sel_cell_end);
483 ce = tabular->right_column_of_cell(sel_cell_end);
486 int rs = tabular->row_of_cell(sel_cell_start);
487 int re = tabular->row_of_cell(sel_cell_end);
491 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
492 int w = tabular->GetWidthOfColumn(cell);
493 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
494 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
495 w, h, LColor::selection);
500 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
506 owner()->update(bv, font, true);
513 if (calculate_dimensions_of_cells(bv, font, true))
516 owner()->update(bv, font, true);
520 if (the_locking_inset)
521 the_locking_inset->update(bv, font, reinit);
522 if (need_update < FULL &&
523 bv->text->status() == LyXText::NEED_MORE_REFRESH)
528 switch (need_update) {
532 if (calculate_dimensions_of_cells(bv, font, false))
545 string const InsetTabular::editMessage() const
547 return _("Opened Tabular Inset");
551 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
553 UpdatableInset::edit(bv, x, y, button);
555 if (!bv->lockInset(this)) {
556 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
560 the_locking_inset = 0;
566 if (insetHit(bv, x, y) && (button != 3)) {
567 activateCellInsetAbs(bv, x, y, button);
572 void InsetTabular::edit(BufferView * bv, bool front)
574 UpdatableInset::edit(bv, front);
576 if (!bv->lockInset(this)) {
577 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
581 the_locking_inset = 0;
587 actcell = tabular->GetNumberOfCells() - 1;
594 void InsetTabular::insetUnlock(BufferView * bv)
596 if (the_locking_inset) {
597 the_locking_inset->insetUnlock(bv);
598 the_locking_inset = 0;
603 if (scroll(false) || hasSelection()) {
608 updateLocal(bv, FULL, false);
613 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
614 bool mark_dirty) const
618 calculate_dimensions_of_cells(bv, font, true);
620 if (need_update < what) // only set this if it has greater update
622 #if 0 // maybe this should not be done!
623 if ((what == INIT) && hasSelection()) {
628 if (need_update != NONE) {
629 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
630 if (locked) // && (what != NONE))
636 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
638 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
643 if (inset == tabular->GetCellInset(actcell)) {
644 lyxerr[Debug::INSETTEXT] << "OK" << endl;
645 the_locking_inset = tabular->GetCellInset(actcell);
648 } else if (!the_locking_inset) {
649 int const n = tabular->GetNumberOfCells();
650 int const id = inset->id();
651 for (int i = 0; i < n; ++i) {
652 InsetText * in = tabular->GetCellInset(i);
655 the_locking_inset = in;
660 if (in->getInsetFromID(id)) {
663 return the_locking_inset->lockInsetInInset(bv, inset);
666 } else if (the_locking_inset && (the_locking_inset == inset)) {
667 lyxerr[Debug::INSETTEXT] << "OK" << endl;
669 } else if (the_locking_inset) {
670 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
671 return the_locking_inset->lockInsetInInset(bv, inset);
673 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
678 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
681 if (!the_locking_inset)
683 if (the_locking_inset == inset) {
684 the_locking_inset->insetUnlock(bv);
685 the_locking_inset = 0;
687 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
693 updateLocal(bv, CELL, false);
694 showInsetCursor(bv, false);
697 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
698 if (inset->lyxCode() == TABULAR_CODE &&
699 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
700 bv->owner()->getDialogs()->updateTabular(this);
709 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
711 if (!the_locking_inset)
713 if (the_locking_inset != inset) {
714 if (!the_locking_inset->updateInsetInInset(bv, inset))
717 updateLocal(bv, CELL, false);
722 unsigned int InsetTabular::insetInInsetY()
724 if (!the_locking_inset)
726 return inset_y + the_locking_inset->insetInInsetY();
730 UpdatableInset * InsetTabular::getLockingInset() const
732 return the_locking_inset ? the_locking_inset->getLockingInset() :
733 const_cast<InsetTabular *>(this);
737 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
741 if (the_locking_inset)
742 return the_locking_inset->getFirstLockingInsetOfType(c);
747 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
749 if (the_locking_inset)
750 return the_locking_inset->insertInset(bv, inset);
755 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
757 if (hasSelection() && (button == 3))
760 if (hasSelection()) {
762 updateLocal(bv, SELECTION, false);
765 int const ocell = actcell;
766 int const orow = actrow;
771 updateLocal(bv, NONE, false);
775 if ((ocell != actcell) && the_locking_inset) {
776 the_locking_inset->insetUnlock(bv);
777 the_locking_inset = 0;
784 bool const inset_hit = insetHit(bv, x, y);
786 if ((ocell == actcell) && the_locking_inset && inset_hit) {
788 the_locking_inset->insetButtonPress(bv,
789 x - inset_x, y - inset_y,
792 } else if (the_locking_inset) {
793 the_locking_inset->insetUnlock(bv);
795 the_locking_inset = 0;
797 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
800 if (inset_hit && bv->theLockingInset()) {
801 if (activateCellInsetAbs(bv, x, y, button))
802 the_locking_inset->insetButtonPress(bv,
812 bool InsetTabular::insetButtonRelease(BufferView * bv,
813 int x, int y, int button)
816 if (the_locking_inset)
817 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
818 y - inset_y, button);
819 if (button == 3 && !ret) {
820 bv->owner()->getDialogs()->showTabular(this);
827 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
829 if (the_locking_inset) {
830 the_locking_inset->insetMotionNotify(bv,
838 // int const old_cell = actcell;
841 if (!hasSelection()) {
842 setSelection(actcell, actcell);
844 setSelection(sel_cell_start, actcell);
846 updateLocal(bv, SELECTION, false);
851 void InsetTabular::insetKeyPress(XKeyEvent * xke)
853 if (the_locking_inset) {
854 the_locking_inset->insetKeyPress(xke);
860 UpdatableInset::RESULT
861 InsetTabular::localDispatch(BufferView * bv, kb_action action,
864 // We need to save the value of the_locking_inset as the call to
865 // the_locking_inset->LocalDispatch might unlock it.
866 old_locking_inset = the_locking_inset;
867 UpdatableInset::RESULT result =
868 UpdatableInset::localDispatch(bv, action, arg);
869 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
874 if ((action < 0) && arg.empty())
877 bool hs = hasSelection();
880 // this one have priority over the locked InsetText, if we're not already
881 // inside another tabular then that one get's priority!
882 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
887 unlockInsetInInset(bv, the_locking_inset);
888 if (action == LFUN_TAB)
889 moveNextCell(bv, old_locking_inset != 0);
891 movePrevCell(bv, old_locking_inset != 0);
894 updateLocal(bv, SELECTION, false);
895 if (!the_locking_inset) {
897 return DISPATCHED_NOUPDATE;
900 // this to avoid compiler warnings.
906 if (the_locking_inset) {
907 result = the_locking_inset->localDispatch(bv, action, arg);
908 if (result == DISPATCHED_NOUPDATE) {
911 if (sc != scroll()) { // inset has been scrolled
912 the_locking_inset->toggleInsetCursor(bv);
913 updateLocal(bv, FULL, false);
914 the_locking_inset->toggleInsetCursor(bv);
917 } else if (result == DISPATCHED) {
918 the_locking_inset->toggleInsetCursor(bv);
919 updateLocal(bv, CELL, false);
920 the_locking_inset->toggleInsetCursor(bv);
922 } else if (result == FINISHED_UP) {
924 } else if (result == FINISHED_DOWN) {
926 } else if (result == FINISHED_RIGHT) {
934 // --- Cursor Movements ----------------------------------
935 case LFUN_RIGHTSEL: {
936 int const start = hasSelection() ? sel_cell_start : actcell;
937 if (tabular->IsLastCellInRow(actcell)) {
938 setSelection(start, actcell);
943 // if we are starting a selection, only select
944 // the current cell at the beginning
945 if (hasSelection()) {
946 moveRight(bv, false);
949 setSelection(start, end);
950 updateLocal(bv, SELECTION, false);
954 result = moveRight(bv);
957 updateLocal(bv, SELECTION, false);
960 int const start = hasSelection() ? sel_cell_start : actcell;
961 if (tabular->IsFirstCellInRow(actcell)) {
962 setSelection(start, actcell);
967 // if we are starting a selection, only select
968 // the current cell at the beginning
969 if (hasSelection()) {
973 setSelection(start, end);
974 updateLocal(bv, SELECTION, false);
978 result = moveLeft(bv);
981 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->GetCellBelow(sel_cell_end));
994 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
996 setSelection(start, start);
998 updateLocal(bv, SELECTION, false);
1002 result = moveDown(bv, old_locking_inset != 0);
1005 updateLocal(bv, SELECTION, false);
1009 int const start = hasSelection() ? sel_cell_start : actcell;
1010 int const ocell = actcell;
1011 // if we are starting a selection, only select
1012 // the current cell at the beginning
1013 if (hasSelection()) {
1015 if ((ocell == sel_cell_end) ||
1016 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1017 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1019 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1021 setSelection(start, start);
1023 updateLocal(bv, SELECTION, false);
1027 result = moveUp(bv, old_locking_inset != 0);
1030 updateLocal(bv, SELECTION, false);
1033 UpdateCodes code = CURSOR;
1038 int column = actcol;
1039 unlockInsetInInset(bv, the_locking_inset);
1040 if (bv->text->first + bv->painter().paperHeight() <
1041 (top_baseline + tabular->GetHeightOfTabular()))
1043 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1045 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1047 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1050 updateLocal(bv, code, false);
1054 UpdateCodes code = CURSOR;
1059 int column = actcol;
1060 unlockInsetInInset(bv, the_locking_inset);
1061 if (top_baseline < 0) {
1062 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1064 if (top_baseline > 0)
1067 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1072 updateLocal(bv, code, false);
1075 // none of these make sense for insettabular,
1076 // but we must catch them to prevent any
1077 // selection from being confused
1081 case LFUN_WORDLEFTSEL:
1082 case LFUN_WORDRIGHT:
1083 case LFUN_WORDRIGHTSEL:
1084 case LFUN_DOWN_PARAGRAPH:
1085 case LFUN_DOWN_PARAGRAPHSEL:
1086 case LFUN_UP_PARAGRAPH:
1087 case LFUN_UP_PARAGRAPHSEL:
1088 case LFUN_BACKSPACE:
1094 case LFUN_BEGINNINGBUF:
1095 case LFUN_BEGINNINGBUFSEL:
1097 case LFUN_ENDBUFSEL:
1099 case LFUN_LAYOUT_TABULAR:
1100 bv->owner()->getDialogs()->showTabular(this);
1102 case LFUN_TABULAR_FEATURE:
1103 if (!tabularFeatures(bv, arg))
1104 result = UNDISPATCHED;
1107 if (!copySelection(bv))
1109 setUndo(bv, Undo::DELETE,
1110 bv->text->cursor.par(),
1111 bv->text->cursor.par()->next());
1113 updateLocal(bv, INIT, true);
1116 if (!hasSelection())
1121 case LFUN_PASTESELECTION:
1123 string const clip(bv->getClipboard());
1127 if (clip.find('\t') != string::npos) {
1131 string::size_type len = clip.length();
1132 string::size_type p = 0;
1135 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1143 maxCols = max(cols, maxCols);
1149 maxCols = max(cols, maxCols);
1150 delete paste_tabular;
1151 paste_tabular = new LyXTabular(this, rows, maxCols);
1152 string::size_type op = 0;
1154 int cells = paste_tabular->GetNumberOfCells();
1156 while ((cell < cells) && (p < len) &&
1157 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1162 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1167 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1168 while (cols++ < maxCols)
1176 // check for the last cell if there is no trailing '\n'
1177 if ((cell < cells) && (op < len))
1178 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1180 // so that the clipboard is used and it goes on
1182 // and executes LFUN_PASTESELECTION in insettext!
1183 delete paste_tabular;
1188 if (hasPasteBuffer()) {
1189 setUndo(bv, Undo::INSERT,
1190 bv->text->cursor.par(),
1191 bv->text->cursor.par()->next());
1193 updateLocal(bv, INIT, true);
1196 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1198 // handle font changing stuff on selection before we lock the inset
1199 // in the default part!
1200 result = UNDISPATCHED;
1211 case LFUN_UNDERLINE:
1212 case LFUN_FONT_SIZE:
1213 if (bv->Dispatch(action, arg))
1214 result = DISPATCHED;
1220 // we try to activate the actual inset and put this event down to
1221 // the insets dispatch function.
1222 if ((result == DISPATCHED) || the_locking_inset)
1225 if (activateCellInset(bv)) {
1226 // reset need_update setted in above function!
1228 result = the_locking_inset->localDispatch(bv, action, arg);
1229 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1230 unlockInsetInInset(bv, the_locking_inset);
1232 // we need to update if this was requested before
1233 updateLocal(bv, NONE, false);
1234 return UNDISPATCHED;
1237 // so the below CELL is not set because this is higher
1238 // priority and we get a full redraw
1239 need_update = SELECTION;
1242 updateLocal(bv, CELL, false);
1247 if (result < FINISHED) {
1248 if (!the_locking_inset) {
1249 showInsetCursor(bv);
1252 bv->unlockInset(this);
1257 int InsetTabular::latex(Buffer const * buf, ostream & os,
1258 bool fragile, bool fp) const
1260 return tabular->latex(buf, os, fragile, fp);
1264 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1267 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1269 return tabular->ascii(buf, os, 0, false,0);
1273 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1276 int const ret = tabular->ascii(buf,os,
1277 (int)parOwner()->params().depth(),
1284 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1289 // if the table is inside a float it doesn't need the informaltable
1290 // wrapper. Search for it.
1291 for(master = owner();
1292 master && master->lyxCode() != Inset::FLOAT_CODE;
1293 master = master->owner());
1296 os << "<informaltable>\n";
1299 ret+= tabular->docBook(buf,os);
1301 os << "</informaltable>\n";
1308 void InsetTabular::validate(LaTeXFeatures & features) const
1310 tabular->Validate(features);
1314 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1315 LyXFont const & font,
1322 bool changed = false;
1324 // if we have a locking_inset we should have to check only this cell for
1325 // change so I'll try this to have a boost, but who knows ;)
1326 if ((need_update != INIT) &&
1327 (the_locking_inset == tabular->GetCellInset(actcell))) {
1328 for(int i = 0; i < tabular->columns(); ++i) {
1329 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1331 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1334 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1335 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1336 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1339 for (int i = 0; i < tabular->rows(); ++i) {
1342 for (int j = 0; j < tabular->columns(); ++j) {
1343 if (tabular->IsPartOfMultiColumn(i,j))
1346 inset = tabular->GetCellInset(cell);
1347 if (!reinit && !tabular->GetPWidth(cell).zero())
1348 inset->update(bv, font, false);
1349 maxAsc = max(maxAsc, inset->ascent(bv, font));
1350 maxDesc = max(maxDesc, inset->descent(bv, font));
1351 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1353 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1354 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1362 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1364 if (the_locking_inset) {
1365 the_locking_inset->getCursorPos(bv, x, y);
1368 x = cursor_.x() - top_x;
1373 void InsetTabular::toggleInsetCursor(BufferView * bv)
1376 if (isCursorVisible())
1377 bv->hideLockedInsetCursor();
1380 if (the_locking_inset) {
1381 the_locking_inset->toggleInsetCursor(bv);
1385 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1387 int const asc = lyxfont::maxAscent(font);
1388 int const desc = lyxfont::maxDescent(font);
1390 if (isCursorVisible())
1391 bv->hideLockedInsetCursor();
1393 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1394 toggleCursorVisible();
1398 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1402 if (!isCursorVisible()) {
1403 LyXFont font; // = GetFont(par, cursor.pos);
1405 int const asc = lyxfont::maxAscent(font);
1406 int const desc = lyxfont::maxDescent(font);
1407 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1409 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1410 setCursorVisible(true);
1415 void InsetTabular::hideInsetCursor(BufferView * bv)
1417 if (isCursorVisible()) {
1418 bv->hideLockedInsetCursor();
1419 setCursorVisible(false);
1424 void InsetTabular::fitInsetCursor(BufferView * bv) const
1426 if (the_locking_inset) {
1427 the_locking_inset->fitInsetCursor(bv);
1432 int const asc = lyxfont::maxAscent(font);
1433 int const desc = lyxfont::maxDescent(font);
1434 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1438 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1442 actcell = actrow = actcol = 0;
1443 int ly = tabular->GetDescentOfRow(actrow);
1445 // first search the right row
1446 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1447 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1448 tabular->GetAscentOfRow(actrow + 1) +
1449 tabular->GetAdditionalHeight(actrow + 1));
1451 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1453 actcell = tabular->GetCellNumber(actrow, actcol);
1455 // now search the right column
1456 int lx = tabular->GetWidthOfColumn(actcell) -
1457 tabular->GetAdditionalWidth(actcell);
1458 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1459 lx += tabular->GetWidthOfColumn(actcell + 1)
1460 + tabular->GetAdditionalWidth(actcell);
1462 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1467 int InsetTabular::getCellXPos(int cell) const
1471 for (; !tabular->IsFirstCellInRow(c); --c)
1473 int lx = tabular->GetWidthOfColumn(cell);
1474 for (; c < cell; ++c) {
1475 lx += tabular->GetWidthOfColumn(c);
1477 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1481 void InsetTabular::resetPos(BufferView * bv) const
1483 #warning This should be fixed in the right manner (20011128 Jug)
1484 // fast hack to fix infinite repaintings!
1489 actcol = tabular->column_of_cell(actcell);
1492 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1493 if (tabular->IsLastCellInRow(cell)) {
1494 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1495 tabular->GetAscentOfRow(actrow + 1) +
1496 tabular->GetAdditionalHeight(actrow + 1));
1500 if (!locked || nodraw()) {
1501 if (the_locking_inset)
1502 inset_y = cursor_.y();
1505 // we need this only from here on!!!
1506 in_reset_pos = true;
1507 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1508 int new_x = getCellXPos(actcell);
1509 int old_x = cursor_.x();
1512 // cursor.x(getCellXPos(actcell) + offset);
1513 if ((actcol < tabular->columns()-1) && scroll(false) &&
1514 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1517 updateLocal(bv, FULL, false);
1518 } else if (the_locking_inset &&
1519 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1521 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1522 if (xx > (bv->workWidth()-20)) {
1523 scroll(bv, -(xx - bv->workWidth() + 60));
1524 updateLocal(bv, FULL, false);
1525 } else if (xx < 20) {
1531 updateLocal(bv, FULL, false);
1533 } else if ((cursor_.x() - offset) > 20 &&
1534 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1535 > (bv->workWidth() - 20)) {
1536 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1537 updateLocal(bv, FULL, false);
1538 } else if ((cursor_.x() - offset) < 20) {
1539 scroll(bv, 20 - cursor_.x() + offset);
1540 updateLocal(bv, FULL, false);
1541 } else if (scroll(false) && top_x > 20 &&
1542 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1543 scroll(bv, old_x - cursor_.x());
1544 updateLocal(bv, FULL, false);
1546 if (the_locking_inset) {
1547 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1548 inset_y = cursor_.y();
1550 if ((!the_locking_inset ||
1551 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1552 actcell != oldcell) {
1553 InsetTabular * inset = const_cast<InsetTabular *>(this);
1554 bv->owner()->getDialogs()->updateTabular(inset);
1557 in_reset_pos = false;
1561 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1563 if (lock && !old_locking_inset) {
1564 if (activateCellInset(bv))
1567 bool moved = isRightToLeft(bv)
1568 ? movePrevCell(bv) : moveNextCell(bv);
1570 return FINISHED_RIGHT;
1571 if (lock && activateCellInset(bv))
1575 return DISPATCHED_NOUPDATE;
1579 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1581 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1584 if (lock) { // behind the inset
1585 if (activateCellInset(bv, 0, 0, 0, true))
1589 return DISPATCHED_NOUPDATE;
1593 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1595 int const ocell = actcell;
1596 actcell = tabular->GetCellAbove(actcell);
1597 if (actcell == ocell) // we moved out of the inset
1603 if (old_locking_inset) {
1604 old_locking_inset->getCursorPos(bv, x, y);
1605 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1607 if (activateCellInset(bv, x, 0))
1610 return DISPATCHED_NOUPDATE;
1614 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1616 int const ocell = actcell;
1617 actcell = tabular->GetCellBelow(actcell);
1618 if (actcell == ocell) // we moved out of the inset
1619 return FINISHED_DOWN;
1624 if (old_locking_inset) {
1625 old_locking_inset->getCursorPos(bv, x, y);
1626 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1628 if (activateCellInset(bv, x, 0))
1631 return DISPATCHED_NOUPDATE;
1635 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1637 if (isRightToLeft(bv)) {
1638 if (tabular->IsFirstCellInRow(actcell)) {
1639 int row = tabular->row_of_cell(actcell);
1640 if (row == tabular->rows() - 1)
1642 actcell = tabular->GetLastCellInRow(row);
1643 actcell = tabular->GetCellBelow(actcell);
1650 if (tabular->IsLastCell(actcell))
1655 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1656 isRightToLeftPar(bv->buffer()->params);
1657 activateCellInset(bv, 0, 0, 0, !rtl);
1664 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1666 if (isRightToLeft(bv)) {
1667 if (tabular->IsLastCellInRow(actcell)) {
1668 int row = tabular->row_of_cell(actcell);
1671 actcell = tabular->GetFirstCellInRow(row);
1672 actcell = tabular->GetCellAbove(actcell);
1674 if (tabular->IsLastCell(actcell))
1679 if (!actcell) // first cell
1684 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1685 isRightToLeftPar(bv->buffer()->params);
1686 activateCellInset(bv, 0, 0, 0, !rtl);
1693 bool InsetTabular::deletable() const
1699 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1703 setSelection(0, tabular->GetNumberOfCells() - 1);
1705 if (hasSelection()) {
1706 setUndo(bv, Undo::EDIT,
1707 bv->text->cursor.par(),
1708 bv->text->cursor.par()->next());
1709 bool frozen = undo_frozen;
1712 // apply the fontchange on the whole selection
1717 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1718 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1719 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1720 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1725 updateLocal(bv, INIT, true);
1727 if (the_locking_inset)
1728 the_locking_inset->setFont(bv, font, tall);
1732 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1734 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1737 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1738 string const tmp = tabularFeature[i].feature;
1740 if (tmp == what.substr(0, tmp.length())) {
1741 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1742 //tabularFeatures[i].feature.length())) {
1743 action = tabularFeature[i].action;
1747 if (action == LyXTabular::LAST_ACTION)
1751 frontStrip(what.substr(tabularFeature[i].feature.length()));
1752 tabularFeatures(bv, action, val);
1756 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1757 string const & special, bool & flag)
1759 if (special == "dl_above") {
1762 } else if (special == "dl_below") {
1763 ltt.bottomDL = flag;
1765 } else if (special == "empty") {
1775 void InsetTabular::tabularFeatures(BufferView * bv,
1776 LyXTabular::Feature feature,
1777 string const & value)
1783 bool setLines = false;
1784 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1785 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1788 case LyXTabular::M_ALIGN_LEFT:
1789 case LyXTabular::ALIGN_LEFT:
1790 setAlign = LYX_ALIGN_LEFT;
1792 case LyXTabular::M_ALIGN_RIGHT:
1793 case LyXTabular::ALIGN_RIGHT:
1794 setAlign = LYX_ALIGN_RIGHT;
1796 case LyXTabular::M_ALIGN_CENTER:
1797 case LyXTabular::ALIGN_CENTER:
1798 setAlign = LYX_ALIGN_CENTER;
1800 case LyXTabular::M_VALIGN_TOP:
1801 case LyXTabular::VALIGN_TOP:
1802 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1804 case LyXTabular::M_VALIGN_BOTTOM:
1805 case LyXTabular::VALIGN_BOTTOM:
1806 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1808 case LyXTabular::M_VALIGN_CENTER:
1809 case LyXTabular::VALIGN_CENTER:
1810 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1815 if (hasSelection()) {
1816 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1818 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1819 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1821 setUndo(bv, Undo::FINISH,
1822 bv->text->cursor.par(),
1823 bv->text->cursor.par()->next());
1825 int row = tabular->row_of_cell(actcell);
1826 int column = tabular->column_of_cell(actcell);
1828 LyXTabular::ltType ltt;
1831 case LyXTabular::SET_PWIDTH:
1833 LyXLength const vallen(value);
1834 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1836 bool const update = (tmplen != vallen);
1837 tabular->SetColumnPWidth(actcell, vallen);
1840 for (int i = 0; i < tabular->rows(); ++i) {
1841 cell = tabular->GetCellNumber(i,column);
1842 tabular->GetCellInset(cell)->resizeLyXText(bv);
1844 updateLocal(bv, INIT, true);
1848 case LyXTabular::SET_MPWIDTH:
1850 LyXLength const vallen(value);
1851 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1853 bool const update = (tmplen != vallen);
1854 tabular->SetMColumnPWidth(actcell, vallen);
1856 for (int i = 0; i < tabular->rows(); ++i) {
1857 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1860 updateLocal(bv, INIT, true);
1864 case LyXTabular::SET_SPECIAL_COLUMN:
1865 case LyXTabular::SET_SPECIAL_MULTI:
1866 tabular->SetAlignSpecial(actcell,value,feature);
1867 updateLocal(bv, FULL, true);
1869 case LyXTabular::APPEND_ROW:
1870 // append the row into the tabular
1871 unlockInsetInInset(bv, the_locking_inset);
1872 tabular->AppendRow(actcell);
1873 updateLocal(bv, INIT, true);
1875 case LyXTabular::APPEND_COLUMN:
1876 // append the column into the tabular
1877 unlockInsetInInset(bv, the_locking_inset);
1878 tabular->AppendColumn(actcell);
1879 actcell = tabular->GetCellNumber(row, column);
1880 updateLocal(bv, INIT, true);
1882 case LyXTabular::DELETE_ROW:
1883 unlockInsetInInset(bv, the_locking_inset);
1884 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1885 tabular->DeleteRow(sel_row_start);
1887 if (sel_row_start >= tabular->rows())
1889 actcell = tabular->GetCellNumber(sel_row_start, column);
1891 updateLocal(bv, INIT, true);
1893 case LyXTabular::DELETE_COLUMN:
1894 unlockInsetInInset(bv, the_locking_inset);
1895 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1896 tabular->DeleteColumn(sel_col_start);
1898 if (sel_col_start >= tabular->columns())
1900 actcell = tabular->GetCellNumber(row, sel_col_start);
1902 updateLocal(bv, INIT, true);
1904 case LyXTabular::M_TOGGLE_LINE_TOP:
1906 case LyXTabular::TOGGLE_LINE_TOP:
1908 bool lineSet = !tabular->TopLine(actcell, flag);
1909 for (int i = sel_row_start; i <= sel_row_end; ++i)
1910 for (int j = sel_col_start; j <= sel_col_end; ++j)
1911 tabular->SetTopLine(
1912 tabular->GetCellNumber(i, j),
1914 updateLocal(bv, INIT, true);
1918 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1920 case LyXTabular::TOGGLE_LINE_BOTTOM:
1922 bool lineSet = !tabular->BottomLine(actcell, flag);
1923 for (int i = sel_row_start; i <= sel_row_end; ++i)
1924 for (int j = sel_col_start; j <= sel_col_end; ++j)
1925 tabular->SetBottomLine(
1926 tabular->GetCellNumber(i, j),
1929 updateLocal(bv, INIT, true);
1933 case LyXTabular::M_TOGGLE_LINE_LEFT:
1935 case LyXTabular::TOGGLE_LINE_LEFT:
1937 bool lineSet = !tabular->LeftLine(actcell, flag);
1938 for (int i = sel_row_start; i <= sel_row_end; ++i)
1939 for (int j = sel_col_start; j <= sel_col_end; ++j)
1940 tabular->SetLeftLine(
1941 tabular->GetCellNumber(i,j),
1944 updateLocal(bv, INIT, true);
1948 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1950 case LyXTabular::TOGGLE_LINE_RIGHT:
1952 bool lineSet = !tabular->RightLine(actcell, flag);
1953 for (int i = sel_row_start; i <= sel_row_end; ++i)
1954 for (int j = sel_col_start; j <= sel_col_end; ++j)
1955 tabular->SetRightLine(
1956 tabular->GetCellNumber(i,j),
1959 updateLocal(bv, INIT, true);
1963 case LyXTabular::M_ALIGN_LEFT:
1964 case LyXTabular::M_ALIGN_RIGHT:
1965 case LyXTabular::M_ALIGN_CENTER:
1967 case LyXTabular::ALIGN_LEFT:
1968 case LyXTabular::ALIGN_RIGHT:
1969 case LyXTabular::ALIGN_CENTER:
1970 for (int i = sel_row_start; i <= sel_row_end; ++i)
1971 for (int j = sel_col_start; j <= sel_col_end; ++j)
1972 tabular->SetAlignment(
1973 tabular->GetCellNumber(i, j),
1976 updateLocal(bv, INIT, true);
1978 case LyXTabular::M_VALIGN_TOP:
1979 case LyXTabular::M_VALIGN_BOTTOM:
1980 case LyXTabular::M_VALIGN_CENTER:
1982 case LyXTabular::VALIGN_TOP:
1983 case LyXTabular::VALIGN_BOTTOM:
1984 case LyXTabular::VALIGN_CENTER:
1985 for (int i = sel_row_start; i <= sel_row_end; ++i)
1986 for (int j = sel_col_start; j <= sel_col_end; ++j)
1987 tabular->SetVAlignment(
1988 tabular->GetCellNumber(i, j),
1990 updateLocal(bv, INIT, true);
1992 case LyXTabular::MULTICOLUMN:
1994 if (sel_row_start != sel_row_end) {
1995 Alert::alert(_("Impossible Operation!"),
1996 _("Multicolumns can only be horizontally."),
2000 // just multicol for one Single Cell
2001 if (!hasSelection()) {
2002 // check wether we are completly in a multicol
2003 if (tabular->IsMultiColumn(actcell)) {
2004 tabular->UnsetMultiColumn(actcell);
2005 updateLocal(bv, INIT, true);
2007 tabular->SetMultiColumn(actcell, 1);
2008 updateLocal(bv, CELL, true);
2012 // we have a selection so this means we just add all this
2013 // cells to form a multicolumn cell
2017 if (sel_cell_start > sel_cell_end) {
2018 s_start = sel_cell_end;
2019 s_end = sel_cell_start;
2021 s_start = sel_cell_start;
2022 s_end = sel_cell_end;
2024 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
2027 updateLocal(bv, INIT, true);
2030 case LyXTabular::SET_ALL_LINES:
2032 case LyXTabular::UNSET_ALL_LINES:
2033 for (int i = sel_row_start; i <= sel_row_end; ++i)
2034 for (int j = sel_col_start; j <= sel_col_end; ++j)
2035 tabular->SetAllLines(
2036 tabular->GetCellNumber(i,j), setLines);
2037 updateLocal(bv, INIT, true);
2039 case LyXTabular::SET_LONGTABULAR:
2040 tabular->SetLongTabular(true);
2041 updateLocal(bv, INIT, true); // because this toggles displayed
2043 case LyXTabular::UNSET_LONGTABULAR:
2044 tabular->SetLongTabular(false);
2045 updateLocal(bv, INIT, true); // because this toggles displayed
2047 case LyXTabular::SET_ROTATE_TABULAR:
2048 tabular->SetRotateTabular(true);
2050 case LyXTabular::UNSET_ROTATE_TABULAR:
2051 tabular->SetRotateTabular(false);
2053 case LyXTabular::SET_ROTATE_CELL:
2054 for (int i = sel_row_start; i <= sel_row_end; ++i)
2055 for (int j = sel_col_start; j<=sel_col_end; ++j)
2056 tabular->SetRotateCell(
2057 tabular->GetCellNumber(i, j),
2060 case LyXTabular::UNSET_ROTATE_CELL:
2061 for (int i = sel_row_start; i <= sel_row_end; ++i)
2062 for (int j = sel_col_start; j <= sel_col_end; ++j)
2063 tabular->SetRotateCell(
2064 tabular->GetCellNumber(i, j), false);
2066 case LyXTabular::SET_USEBOX:
2068 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2069 if (val == tabular->GetUsebox(actcell))
2070 val = LyXTabular::BOX_NONE;
2071 for (int i = sel_row_start; i <= sel_row_end; ++i)
2072 for (int j = sel_col_start; j <= sel_col_end; ++j)
2074 tabular->GetCellNumber(i, j), val);
2077 case LyXTabular::UNSET_LTFIRSTHEAD:
2079 case LyXTabular::SET_LTFIRSTHEAD:
2080 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2081 checkLongtableSpecial(ltt, value, flag);
2082 tabular->SetLTHead(row, flag, ltt, true);
2084 case LyXTabular::UNSET_LTHEAD:
2086 case LyXTabular::SET_LTHEAD:
2087 (void)tabular->GetRowOfLTHead(row, ltt);
2088 checkLongtableSpecial(ltt, value, flag);
2089 tabular->SetLTHead(row, flag, ltt, false);
2091 case LyXTabular::UNSET_LTFOOT:
2093 case LyXTabular::SET_LTFOOT:
2094 (void)tabular->GetRowOfLTFoot(row, ltt);
2095 checkLongtableSpecial(ltt, value, flag);
2096 tabular->SetLTFoot(row, flag, ltt, false);
2098 case LyXTabular::UNSET_LTLASTFOOT:
2100 case LyXTabular::SET_LTLASTFOOT:
2101 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2102 checkLongtableSpecial(ltt, value, flag);
2103 tabular->SetLTFoot(row, flag, ltt, true);
2105 case LyXTabular::SET_LTNEWPAGE:
2107 bool what = !tabular->GetLTNewPage(row);
2108 tabular->SetLTNewPage(row, what);
2111 // dummy stuff just to avoid warnings
2112 case LyXTabular::LAST_ACTION:
2118 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2121 UpdatableInset * inset =
2122 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2123 LyXFont font(LyXFont::ALL_SANE);
2125 x = inset->x() + inset->width(bv, font);
2126 y = inset->descent(bv, font);
2128 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2129 //inset_y = cursor.y();
2130 inset->edit(bv, x, y, button);
2131 if (!the_locking_inset)
2133 updateLocal(bv, CELL, false);
2134 return (the_locking_inset != 0);
2138 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2141 inset_x = cursor_.x()
2142 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2143 inset_y = cursor_.y();
2144 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2148 bool InsetTabular::insetHit(BufferView *, int x, int) const
2151 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2155 // This returns paperWidth() if the cell-width is unlimited or the width
2156 // in pixels if we have a pwidth for this cell.
2157 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2159 LyXLength const len = tabular->GetPWidth(cell);
2163 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2167 int InsetTabular::getMaxWidth(BufferView * bv,
2168 UpdatableInset const * inset) const
2170 int cell = tabular->GetCellFromInset(inset, actcell);
2173 lyxerr << "Own inset not found, shouldn't really happen!"
2178 int w = getMaxWidthOfCell(bv, cell);
2180 // because the inset then subtracts it's top_x and owner->x()
2181 w += (inset->x() - top_x);
2188 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2190 resizeLyXText(bv, recursive);
2194 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2197 for(int i = 0; i < tabular->rows(); ++i) {
2198 for(int j = 0; j < tabular->columns(); ++j) {
2199 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2207 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2208 bool const recursive) const
2210 if (the_locking_inset)
2211 return the_locking_inset->getLyXText(bv, recursive);
2213 // if we're locked lock the actual insettext and return it's LyXText!!!
2215 UpdatableInset * inset =
2216 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2217 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2218 return the_locking_inset->getLyXText(bv, recursive);
2221 return Inset::getLyXText(bv, recursive);
2225 bool InsetTabular::showInsetDialog(BufferView * bv) const
2227 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2228 bv->owner()->getDialogs()
2229 ->showTabular(const_cast<InsetTabular *>(this));
2234 void InsetTabular::openLayoutDialog(BufferView * bv) const
2236 if (the_locking_inset) {
2237 InsetTabular * i = static_cast<InsetTabular *>
2238 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2240 i->openLayoutDialog(bv);
2244 bv->owner()->getDialogs()->showTabular(
2245 const_cast<InsetTabular *>(this));
2250 // function returns an object as defined in func_status.h:
2251 // states OK, Unknown, Disabled, On, Off.
2253 FuncStatus InsetTabular::getStatus(string const & what) const
2255 int action = LyXTabular::LAST_ACTION;
2259 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2260 string const tmp = tabularFeature[i].feature;
2261 if (tmp == what.substr(0, tmp.length())) {
2262 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2263 // tabularFeatures[i].feature.length())) {
2264 action = tabularFeature[i].action;
2268 if (action == LyXTabular::LAST_ACTION) {
2270 return status.unknown(true);
2273 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2278 LyXTabular::ltType dummyltt;
2281 if (hasSelection()) {
2282 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2284 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2288 case LyXTabular::SET_PWIDTH:
2289 case LyXTabular::SET_MPWIDTH:
2290 case LyXTabular::SET_SPECIAL_COLUMN:
2291 case LyXTabular::SET_SPECIAL_MULTI:
2292 return status.disabled(true);
2294 case LyXTabular::APPEND_ROW:
2295 case LyXTabular::APPEND_COLUMN:
2296 case LyXTabular::DELETE_ROW:
2297 case LyXTabular::DELETE_COLUMN:
2298 case LyXTabular::SET_ALL_LINES:
2299 case LyXTabular::UNSET_ALL_LINES:
2300 return status.clear();
2302 case LyXTabular::MULTICOLUMN:
2303 status.setOnOff(tabular->IsMultiColumn(actcell));
2305 case LyXTabular::M_TOGGLE_LINE_TOP:
2307 case LyXTabular::TOGGLE_LINE_TOP:
2308 status.setOnOff(tabular->TopLine(actcell, flag));
2310 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2312 case LyXTabular::TOGGLE_LINE_BOTTOM:
2313 status.setOnOff(tabular->BottomLine(actcell, flag));
2315 case LyXTabular::M_TOGGLE_LINE_LEFT:
2317 case LyXTabular::TOGGLE_LINE_LEFT:
2318 status.setOnOff(tabular->LeftLine(actcell, flag));
2320 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2322 case LyXTabular::TOGGLE_LINE_RIGHT:
2323 status.setOnOff(tabular->RightLine(actcell, flag));
2325 case LyXTabular::M_ALIGN_LEFT:
2327 case LyXTabular::ALIGN_LEFT:
2328 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2330 case LyXTabular::M_ALIGN_RIGHT:
2332 case LyXTabular::ALIGN_RIGHT:
2333 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2335 case LyXTabular::M_ALIGN_CENTER:
2337 case LyXTabular::ALIGN_CENTER:
2338 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2340 case LyXTabular::M_VALIGN_TOP:
2342 case LyXTabular::VALIGN_TOP:
2343 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2345 case LyXTabular::M_VALIGN_BOTTOM:
2347 case LyXTabular::VALIGN_BOTTOM:
2348 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2350 case LyXTabular::M_VALIGN_CENTER:
2352 case LyXTabular::VALIGN_CENTER:
2353 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2355 case LyXTabular::SET_LONGTABULAR:
2356 status.setOnOff(tabular->IsLongTabular());
2358 case LyXTabular::UNSET_LONGTABULAR:
2359 status.setOnOff(!tabular->IsLongTabular());
2361 case LyXTabular::SET_ROTATE_TABULAR:
2362 status.setOnOff(tabular->GetRotateTabular());
2364 case LyXTabular::UNSET_ROTATE_TABULAR:
2365 status.setOnOff(!tabular->GetRotateTabular());
2367 case LyXTabular::SET_ROTATE_CELL:
2368 status.setOnOff(tabular->GetRotateCell(actcell));
2370 case LyXTabular::UNSET_ROTATE_CELL:
2371 status.setOnOff(!tabular->GetRotateCell(actcell));
2373 case LyXTabular::SET_USEBOX:
2374 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2376 case LyXTabular::SET_LTFIRSTHEAD:
2377 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2379 case LyXTabular::SET_LTHEAD:
2380 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2382 case LyXTabular::SET_LTFOOT:
2383 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2385 case LyXTabular::SET_LTLASTFOOT:
2386 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2388 case LyXTabular::SET_LTNEWPAGE:
2389 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2393 status.disabled(true);
2400 vector<string> const InsetTabular::getLabelList() const
2402 return tabular->getLabelList();
2406 bool InsetTabular::copySelection(BufferView * bv)
2408 if (!hasSelection())
2411 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2412 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2413 if (sel_col_start > sel_col_end) {
2414 sel_col_start = sel_col_end;
2415 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2417 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2419 int const columns = sel_col_end - sel_col_start + 1;
2421 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2422 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2423 if (sel_row_start > sel_row_end) {
2424 swap(sel_row_start, sel_row_end);
2426 int const rows = sel_row_end - sel_row_start + 1;
2428 delete paste_tabular;
2429 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2430 for (int i = 0; i < sel_row_start; ++i)
2431 paste_tabular->DeleteRow(0);
2432 while (paste_tabular->rows() > rows)
2433 paste_tabular->DeleteRow(rows);
2434 paste_tabular->SetTopLine(0, true, true);
2435 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2437 for (int i = 0; i < sel_col_start; ++i)
2438 paste_tabular->DeleteColumn(0);
2439 while (paste_tabular->columns() > columns)
2440 paste_tabular->DeleteColumn(columns);
2441 paste_tabular->SetLeftLine(0, true, true);
2442 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2446 paste_tabular->ascii(bv->buffer(), sstr,
2447 (int)parOwner()->params().depth(), true, '\t');
2448 bv->stuffClipboard(sstr.str().c_str());
2453 bool InsetTabular::pasteSelection(BufferView * bv)
2458 for (int r1 = 0, r2 = actrow;
2459 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2461 for(int c1 = 0, c2 = actcol;
2462 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2464 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2465 tabular->IsPartOfMultiColumn(r2,c2))
2467 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2471 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2475 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2476 int const n2 = tabular->GetCellNumber(r2, c2);
2477 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2478 tabular->GetCellInset(n2)->setOwner(this);
2479 tabular->GetCellInset(n2)->deleteLyXText(bv);
2486 bool InsetTabular::cutSelection()
2488 if (!hasSelection())
2491 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2492 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2493 if (sel_col_start > sel_col_end) {
2494 sel_col_start = sel_col_end;
2495 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2497 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2499 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2500 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2501 if (sel_row_start > sel_row_end) {
2502 swap(sel_row_start, sel_row_end);
2504 if (sel_cell_start > sel_cell_end) {
2505 swap(sel_cell_start, sel_cell_end);
2507 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2508 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2509 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2516 bool InsetTabular::isRightToLeft(BufferView * bv)
2518 return bv->getParentLanguage(this)->RightToLeft();
2522 bool InsetTabular::nodraw() const
2524 if (!UpdatableInset::nodraw() && the_locking_inset)
2525 return the_locking_inset->nodraw();
2526 return UpdatableInset::nodraw();
2530 int InsetTabular::scroll(bool recursive) const
2532 int sx = UpdatableInset::scroll(false);
2534 if (recursive && the_locking_inset)
2535 sx += the_locking_inset->scroll(recursive);
2541 bool InsetTabular::doClearArea() const
2543 return !locked || (need_update & (FULL|INIT));
2547 void InsetTabular::getSelection(int & srow, int & erow,
2548 int & scol, int & ecol) const
2550 int const start = hasSelection() ? sel_cell_start : actcell;
2551 int const end = hasSelection() ? sel_cell_end : actcell;
2553 srow = tabular->row_of_cell(start);
2554 erow = tabular->row_of_cell(end);
2559 scol = tabular->column_of_cell(start);
2560 ecol = tabular->column_of_cell(end);
2564 ecol = tabular->right_column_of_cell(end);
2569 Paragraph * InsetTabular::getParFromID(int id) const
2572 for(int i = 0; i < tabular->rows(); ++i) {
2573 for(int j = 0; j < tabular->columns(); ++j) {
2574 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2582 Paragraph * InsetTabular::firstParagraph() const
2584 if (the_locking_inset)
2585 return the_locking_inset->firstParagraph();
2590 Paragraph * InsetTabular::getFirstParagraph(int i) const
2592 return (i < tabular->GetNumberOfCells())
2593 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2598 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2600 if (the_locking_inset)
2601 return the_locking_inset->cursor(bv);
2602 return Inset::cursor(bv);
2606 Inset * InsetTabular::getInsetFromID(int id_arg) const
2609 return const_cast<InsetTabular *>(this);
2612 for(int i = 0; i < tabular->rows(); ++i) {
2613 for(int j = 0; j < tabular->columns(); ++j) {
2614 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2623 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2626 if (the_locking_inset) {
2627 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2632 if (tabular->IsLastCell(actcell)) {
2633 bv->unlockInset(const_cast<InsetTabular *>(this));
2639 // otherwise we have to lock the next inset and ask for it's selecttion
2640 UpdatableInset * inset =
2641 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2642 inset->edit(bv, 0, 0, 0);
2643 string const str(selectNextWordInt(bv, value));
2651 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2653 // when entering this function the inset should be ALWAYS locked!
2654 lyx::Assert(the_locking_inset);
2656 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2660 if (tabular->IsLastCell(actcell)) {
2661 bv->unlockInset(const_cast<InsetTabular *>(this));
2665 // otherwise we have to lock the next inset and ask for it's selecttion
2666 UpdatableInset * inset =
2667 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2669 return selectNextWordInt(bv, value);
2673 void InsetTabular::selectSelectedWord(BufferView * bv)
2675 if (the_locking_inset) {
2676 the_locking_inset->selectSelectedWord(bv);
2683 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2685 if (the_locking_inset) {
2686 the_locking_inset->toggleSelection(bv, kill_selection);
2691 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2695 if (the_locking_inset) {
2696 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2698 updateLocal(bv, CELL, false);
2701 if (tabular->IsLastCell(actcell)) {
2703 bv->unlockInset(const_cast<InsetTabular *>(this));
2708 // otherwise we have to lock the next inset and search there
2709 UpdatableInset * inset =
2710 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2712 bool const ret = searchForward(bv, str, cs, mw);
2714 updateLocal(bv, CELL, false);
2719 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2723 if (the_locking_inset) {
2724 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2726 updateLocal(bv, CELL, false);
2729 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);
2740 bool const ret = searchBackward(bv, str, cs, mw);
2742 updateLocal(bv, CELL, false);
2747 bool InsetTabular::insetAllowed(Inset::Code code) const
2749 if (the_locking_inset)
2750 return the_locking_inset->insetAllowed(code);
2755 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2757 const int cell = tabular->GetCellFromInset(in, actcell);
2760 return tabular->GetPWidth(cell).zero();
2762 // well we didn't obviously find it so maybe our owner knows more
2764 return owner()->forceDefaultParagraphs(in);
2765 // if we're here there is really something strange going on!!!