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"
38 #include "frontends/Dialogs.h"
39 #include "frontends/Alert.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
59 int const ADD_TO_HEIGHT = 2;
60 int const ADD_TO_TABULAR_WIDTH = 2;
63 LyXTabular * paste_tabular = 0;
66 struct TabularFeature {
67 LyXTabular::Feature action;
72 TabularFeature tabularFeature[] =
74 { LyXTabular::APPEND_ROW, "append-row" },
75 { LyXTabular::APPEND_COLUMN, "append-column" },
76 { LyXTabular::DELETE_ROW, "delete-row" },
77 { LyXTabular::DELETE_COLUMN, "delete-column" },
78 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
79 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
80 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
81 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
82 { LyXTabular::ALIGN_LEFT, "align-left" },
83 { LyXTabular::ALIGN_RIGHT, "align-right" },
84 { LyXTabular::ALIGN_CENTER, "align-center" },
85 { LyXTabular::VALIGN_TOP, "valign-top" },
86 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
87 { LyXTabular::VALIGN_CENTER, "valign-center" },
88 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
89 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
90 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
91 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
92 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
93 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
94 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
95 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
96 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
97 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
98 { LyXTabular::MULTICOLUMN, "multicolumn" },
99 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
100 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
101 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
102 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
103 { LyXTabular::SET_PWIDTH, "set-pwidth" },
104 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
105 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
106 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
107 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
108 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
109 { LyXTabular::SET_USEBOX, "set-usebox" },
110 { LyXTabular::SET_LTHEAD, "set-lthead" },
111 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
112 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
113 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
114 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
115 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
116 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
117 { LyXTabular::LAST_ACTION, "" }
123 bool InsetTabular::hasPasteBuffer() const
125 return (paste_tabular != 0);
129 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
136 tabular.reset(new LyXTabular(this, rows, columns));
137 // for now make it always display as display() inset
139 the_locking_inset = 0;
142 actrow = actcell = 0;
146 in_reset_pos = false;
150 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
152 : UpdatableInset(tab, same_id), buffer(&buf)
154 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
155 the_locking_inset = 0;
158 actrow = actcell = 0;
162 in_reset_pos = false;
166 InsetTabular::~InsetTabular()
172 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
174 return new InsetTabular(*this, buf, same_id);
178 void InsetTabular::write(Buffer const * buf, ostream & os) const
180 os << " Tabular" << endl;
181 tabular->Write(buf, os);
185 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
187 bool const old_format = (lex.getString() == "\\LyXTable");
189 tabular.reset(new LyXTabular(buf, this, lex));
197 string token = lex.getString();
198 while (lex.isOK() && (token != "\\end_inset")) {
200 token = lex.getString();
202 if (token != "\\end_inset") {
203 lex.printError("Missing \\end_inset at this point. "
209 int InsetTabular::ascent(BufferView *, LyXFont const &) const
211 return tabular->GetAscentOfRow(0);
215 int InsetTabular::descent(BufferView *, LyXFont const &) const
217 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
221 int InsetTabular::width(BufferView *, LyXFont const &) const
223 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
227 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
228 float & x, bool cleared) const
236 if (need_update == INIT) {
237 if (calculate_dimensions_of_cells(bv, font, true))
238 bv->text->status = LyXText::CHANGED_IN_DRAW;
243 Painter & pain = bv->painter();
249 UpdatableInset::draw(bv, font, baseline, x, cleared);
252 x += static_cast<float>(scroll());
254 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
255 (top_x != int(x)) || (top_baseline != baseline)))
257 int h = ascent(bv, font) + descent(bv, font);
258 int const tx = display() || !owner() ? 0 : top_x;
259 int w = tx ? width(bv, font) : pain.paperWidth();
260 int ty = baseline - ascent(bv, font);
264 if ((ty + h) > pain.paperHeight())
265 h = pain.paperHeight();
266 if ((top_x + w) > pain.paperWidth())
267 w = pain.paperWidth();
268 pain.fillRectangle(tx, ty, w, h, backgroundColor());
274 top_baseline = baseline;
275 x += ADD_TO_TABULAR_WIDTH;
279 first_visible_cell = -1;
280 for (i = 0; i < tabular->rows(); ++i) {
282 cell = tabular->GetCellNumber(i, 0);
283 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
284 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
286 baseline += tabular->GetDescentOfRow(i) +
287 tabular->GetAscentOfRow(i + 1) +
288 tabular->GetAdditionalHeight(i + 1);
291 for (j = 0; j < tabular->columns(); ++j) {
292 if (nx > bv->workWidth())
294 if (tabular->IsPartOfMultiColumn(i, j))
296 cx = nx + tabular->GetBeginningOfTextInCell(cell);
297 if (first_visible_cell < 0)
298 first_visible_cell = cell;
299 if (hasSelection()) {
300 drawCellSelection(pain, nx, baseline, i, j, cell);
303 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
304 drawCellLines(pain, nx, baseline, i, cell);
305 nx += tabular->GetWidthOfColumn(cell);
308 baseline += tabular->GetDescentOfRow(i) +
309 tabular->GetAscentOfRow(i + 1) +
310 tabular->GetAdditionalHeight(i + 1);
312 } else if (need_update == CELL) {
315 if (the_locking_inset &&
316 tabular->GetCellInset(actcell) != the_locking_inset)
318 Inset * inset = tabular->GetCellInset(cell);
320 inset != the_locking_inset && i < tabular->rows();
324 inset != the_locking_inset && j < tabular->columns();
327 if (tabular->IsPartOfMultiColumn(i, j))
329 nx += tabular->GetWidthOfColumn(cell);
331 inset = tabular->GetCellInset(cell);
333 if (tabular->row_of_cell(cell) > i) {
335 baseline += tabular->GetDescentOfRow(i) +
336 tabular->GetAscentOfRow(i + 1) +
337 tabular->GetAdditionalHeight(i + 1);
341 // compute baseline for actual row
342 for (i = 0; i < actrow; ++i) {
343 baseline += tabular->GetDescentOfRow(i) +
344 tabular->GetAscentOfRow(i + 1) +
345 tabular->GetAdditionalHeight(i + 1);
347 // now compute the right x position
348 cell = tabular->GetCellNumber(actrow, 0);
349 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
350 if (tabular->IsPartOfMultiColumn(actrow, j))
352 nx += tabular->GetWidthOfColumn(cell);
356 i = tabular->row_of_cell(cell);
357 if (the_locking_inset != tabular->GetCellInset(cell)) {
358 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
361 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
363 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
364 // clear only if we didn't have a change
365 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
366 // clear before the inset
369 baseline - tabular->GetAscentOfRow(i) + 1,
371 tabular->GetAscentOfRow(i) +
372 tabular->GetDescentOfRow(i) - 1,
374 // clear behind the inset
376 int(cx + the_locking_inset->width(bv,font) + 1),
377 baseline - tabular->GetAscentOfRow(i) + 1,
378 tabular->GetWidthOfColumn(cell) -
379 tabular->GetBeginningOfTextInCell(cell) -
380 the_locking_inset->width(bv,font) -
381 tabular->GetAdditionalWidth(cell) - 1,
382 tabular->GetAscentOfRow(i) +
383 tabular->GetDescentOfRow(i) - 1,
385 // clear below the inset
388 baseline + the_locking_inset->descent(bv, font) + 1,
389 tabular->GetWidthOfColumn(cell) -
390 tabular->GetAdditionalWidth(cell) - 1,
391 tabular->GetAscentOfRow(i) +
392 tabular->GetDescentOfRow(i) -
393 the_locking_inset->ascent(bv, font) -
394 the_locking_inset->descent(bv, font) -
395 TEXT_TO_INSET_OFFSET - 1,
399 x -= ADD_TO_TABULAR_WIDTH;
400 x += width(bv, font);
401 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
403 for(Inset * inset = owner(); inset; ++i)
404 inset = inset->owner();
405 if (calculate_dimensions_of_cells(bv, font, false))
413 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
414 int row, int cell) const
416 int x2 = x + tabular->GetWidthOfColumn(cell);
419 if (!tabular->TopAlreadyDrawed(cell)) {
420 on_off = !tabular->TopLine(cell);
421 pain.line(x, baseline - tabular->GetAscentOfRow(row),
422 x2, baseline - tabular->GetAscentOfRow(row),
423 on_off ? LColor::tabularonoffline : LColor::tabularline,
424 on_off ? Painter::line_onoffdash : Painter::line_solid);
426 on_off = !tabular->BottomLine(cell);
427 pain.line(x,baseline + tabular->GetDescentOfRow(row),
428 x2, baseline + tabular->GetDescentOfRow(row),
429 on_off ? LColor::tabularonoffline : LColor::tabularline,
430 on_off ? Painter::line_onoffdash : Painter::line_solid);
431 if (!tabular->LeftAlreadyDrawed(cell)) {
432 on_off = !tabular->LeftLine(cell);
433 pain.line(x, baseline - tabular->GetAscentOfRow(row),
434 x, baseline + tabular->GetDescentOfRow(row),
435 on_off ? LColor::tabularonoffline : LColor::tabularline,
436 on_off ? Painter::line_onoffdash : Painter::line_solid);
438 on_off = !tabular->RightLine(cell);
439 pain.line(x2 - tabular->GetAdditionalWidth(cell),
440 baseline - tabular->GetAscentOfRow(row),
441 x2 - tabular->GetAdditionalWidth(cell),
442 baseline + tabular->GetDescentOfRow(row),
443 on_off ? LColor::tabularonoffline : LColor::tabularline,
444 on_off ? Painter::line_onoffdash : Painter::line_solid);
448 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
449 int row, int column, int cell) const
451 lyx::Assert(hasSelection());
452 int cs = tabular->column_of_cell(sel_cell_start);
453 int ce = tabular->column_of_cell(sel_cell_end);
456 cs = tabular->column_of_cell(sel_cell_end);
458 ce = tabular->right_column_of_cell(sel_cell_end);
461 int rs = tabular->row_of_cell(sel_cell_start);
462 int re = tabular->row_of_cell(sel_cell_end);
466 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
467 int w = tabular->GetWidthOfColumn(cell);
468 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
469 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
470 w, h, LColor::selection);
475 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
481 owner()->update(bv, font, true);
488 if (calculate_dimensions_of_cells(bv, font, true))
491 owner()->update(bv, font, true);
495 if (the_locking_inset)
496 the_locking_inset->update(bv, font, reinit);
497 if (need_update < FULL &&
498 bv->text->status() == LyXText::NEED_MORE_REFRESH)
503 switch (need_update) {
507 if (calculate_dimensions_of_cells(bv, font, false))
520 string const InsetTabular::editMessage() const
522 return _("Opened Tabular Inset");
526 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
528 UpdatableInset::edit(bv, x, y, button);
530 if (!bv->lockInset(this)) {
531 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
535 the_locking_inset = 0;
541 if (insetHit(bv, x, y) && (button != 3)) {
542 activateCellInsetAbs(bv, x, y, button);
547 void InsetTabular::edit(BufferView * bv, bool front)
549 UpdatableInset::edit(bv, front);
551 if (!bv->lockInset(this)) {
552 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
556 the_locking_inset = 0;
562 actcell = tabular->GetNumberOfCells() - 1;
569 void InsetTabular::insetUnlock(BufferView * bv)
571 if (the_locking_inset) {
572 the_locking_inset->insetUnlock(bv);
573 the_locking_inset = 0;
578 if (scroll(false) || hasSelection()) {
583 updateLocal(bv, FULL, false);
588 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
589 bool mark_dirty) const
593 calculate_dimensions_of_cells(bv, font, true);
595 if (need_update < what) // only set this if it has greater update
597 if ((what == INIT) && hasSelection()) {
601 if (need_update != NONE) {
602 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
603 if (locked) // && (what != NONE))
609 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
611 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
616 if (inset == tabular->GetCellInset(actcell)) {
617 lyxerr[Debug::INSETTEXT] << "OK" << endl;
618 the_locking_inset = tabular->GetCellInset(actcell);
621 } else if (!the_locking_inset) {
622 int const n = tabular->GetNumberOfCells();
623 int const id = inset->id();
624 for (int i = 0; i < n; ++i) {
625 InsetText * in = tabular->GetCellInset(i);
628 the_locking_inset = in;
633 if (in->getInsetFromID(id)) {
635 the_locking_inset = in;
638 return the_locking_inset->lockInsetInInset(bv, inset);
641 } else if (the_locking_inset && (the_locking_inset == inset)) {
642 lyxerr[Debug::INSETTEXT] << "OK" << endl;
644 } else if (the_locking_inset) {
645 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
646 return the_locking_inset->lockInsetInInset(bv, inset);
648 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
653 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
656 if (!the_locking_inset)
658 if (the_locking_inset == inset) {
659 the_locking_inset->insetUnlock(bv);
660 the_locking_inset = 0;
662 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
668 updateLocal(bv, CELL, false);
669 showInsetCursor(bv, false);
672 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
673 if (inset->lyxCode() == TABULAR_CODE &&
674 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
675 bv->owner()->getDialogs()->updateTabular(this);
684 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
686 if (!the_locking_inset)
688 if (the_locking_inset != inset) {
689 if (!the_locking_inset->updateInsetInInset(bv, inset))
692 updateLocal(bv, CELL, false);
697 unsigned int InsetTabular::insetInInsetY()
699 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()) {
966 if ((ocell == sel_cell_end) ||
967 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
968 setSelection(start, tabular->GetCellBelow(sel_cell_end));
970 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
971 updateLocal(bv, SELECTION, false);
975 result = moveDown(bv, old_locking_inset != 0);
978 updateLocal(bv, SELECTION, false);
982 int const start = hasSelection() ? sel_cell_start : actcell;
983 int const ocell = actcell;
984 // if we are starting a selection, only select
985 // the current cell at the beginning
986 if (hasSelection()) {
989 if ((ocell == sel_cell_end) ||
990 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
991 setSelection(start, tabular->GetCellAbove(sel_cell_end));
993 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
994 updateLocal(bv, SELECTION, false);
998 result = moveUp(bv, old_locking_inset != 0);
1001 updateLocal(bv, SELECTION, false);
1004 int column = actcol;
1005 unlockInsetInInset(bv, the_locking_inset);
1006 if (bv->text->first + bv->painter().paperHeight() <
1007 (top_baseline + tabular->GetHeightOfTabular()))
1009 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1010 updateLocal(bv, FULL, false);
1011 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1013 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1016 updateLocal(bv, CURSOR, false);
1020 int column = actcol;
1021 unlockInsetInInset(bv, the_locking_inset);
1022 if (top_baseline < 0) {
1023 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1024 updateLocal(bv, FULL, false);
1025 if (top_baseline > 0)
1028 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1033 updateLocal(bv, CURSOR, false);
1036 // none of these make sense for insettabular,
1037 // but we must catch them to prevent any
1038 // selection from being confused
1042 case LFUN_WORDLEFTSEL:
1043 case LFUN_WORDRIGHT:
1044 case LFUN_WORDRIGHTSEL:
1045 case LFUN_DOWN_PARAGRAPH:
1046 case LFUN_DOWN_PARAGRAPHSEL:
1047 case LFUN_UP_PARAGRAPH:
1048 case LFUN_UP_PARAGRAPHSEL:
1049 case LFUN_BACKSPACE:
1056 case LFUN_LAYOUT_TABULAR:
1057 bv->owner()->getDialogs()->showTabular(this);
1059 case LFUN_TABULAR_FEATURE:
1060 if (!tabularFeatures(bv, arg))
1061 result = UNDISPATCHED;
1064 if (!copySelection(bv))
1066 setUndo(bv, Undo::DELETE,
1067 bv->text->cursor.par(),
1068 bv->text->cursor.par()->next());
1070 updateLocal(bv, INIT, true);
1073 if (!hasSelection())
1078 case LFUN_PASTESELECTION:
1080 string const clip(bv->getClipboard());
1084 if (clip.find('\t') != string::npos) {
1088 string::size_type len = clip.length();
1089 string::size_type p = 0;
1092 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1100 maxCols = max(cols, maxCols);
1106 maxCols = max(cols, maxCols);
1107 delete paste_tabular;
1108 paste_tabular = new LyXTabular(this, rows, maxCols);
1109 string::size_type op = 0;
1111 int cells = paste_tabular->GetNumberOfCells();
1113 while ((cell < cells) && (p < len) &&
1114 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1119 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1124 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1125 while (cols++ < maxCols)
1133 // check for the last cell if there is no trailing '\n'
1134 if ((cell < cells) && (op < len))
1135 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1137 // so that the clipboard is used and it goes on
1139 // and executes LFUN_PASTESELECTION in insettext!
1140 delete paste_tabular;
1145 if (hasPasteBuffer()) {
1146 setUndo(bv, Undo::INSERT,
1147 bv->text->cursor.par(),
1148 bv->text->cursor.par()->next());
1150 updateLocal(bv, INIT, true);
1153 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1155 // we try to activate the actual inset and put this event down to
1156 // the insets dispatch function.
1157 result = UNDISPATCHED;
1158 if (the_locking_inset)
1161 if (activateCellInset(bv)) {
1162 // reset need_update setted in above function!
1164 result = the_locking_inset->localDispatch(bv, action, arg);
1165 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1166 unlockInsetInInset(bv, the_locking_inset);
1168 // we need to update if this was requested before
1169 updateLocal(bv, NONE, false);
1170 return UNDISPATCHED;
1175 updateLocal(bv, CELL, false);
1180 if (result < FINISHED) {
1181 if (!the_locking_inset) {
1182 showInsetCursor(bv);
1185 bv->unlockInset(this);
1190 int InsetTabular::latex(Buffer const * buf, ostream & os,
1191 bool fragile, bool fp) const
1193 return tabular->Latex(buf, os, fragile, fp);
1197 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1199 // This should be changed to a real ascii export
1200 return tabular->Ascii(buf, os);
1204 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1206 return tabular->Ascii(buf,os);
1210 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1215 // if the table is inside a float it doesn't need the informaltable
1216 // wrapper. Search for it.
1217 for(master = owner();
1218 master && master->lyxCode() != Inset::FLOAT_CODE;
1219 master = master->owner());
1222 os << "<informaltable>\n";
1225 ret+= tabular->DocBook(buf,os);
1227 os << "</informaltable>\n";
1234 void InsetTabular::validate(LaTeXFeatures & features) const
1236 tabular->Validate(features);
1240 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1241 LyXFont const & font,
1248 bool changed = false;
1250 // if we have a locking_inset we should have to check only this cell for
1251 // change so I'll try this to have a boost, but who knows ;)
1252 if ((need_update != INIT) &&
1253 (the_locking_inset == tabular->GetCellInset(actcell))) {
1254 for(int i = 0; i < tabular->columns(); ++i) {
1255 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1257 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1260 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1261 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1262 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1265 for (int i = 0; i < tabular->rows(); ++i) {
1268 for (int j = 0; j < tabular->columns(); ++j) {
1269 if (tabular->IsPartOfMultiColumn(i,j))
1272 inset = tabular->GetCellInset(cell);
1273 if (!reinit && !tabular->GetPWidth(cell).zero())
1274 inset->update(bv, font, false);
1275 maxAsc = max(maxAsc, inset->ascent(bv, font));
1276 maxDesc = max(maxDesc, inset->descent(bv, font));
1277 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1279 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1280 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1288 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1290 if (the_locking_inset) {
1291 the_locking_inset->getCursorPos(bv, x, y);
1294 x = cursor_.x() - top_x;
1299 void InsetTabular::toggleInsetCursor(BufferView * bv)
1301 if (the_locking_inset) {
1302 the_locking_inset->toggleInsetCursor(bv);
1306 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1308 int const asc = lyxfont::maxAscent(font);
1309 int const desc = lyxfont::maxDescent(font);
1311 if (isCursorVisible())
1312 bv->hideLockedInsetCursor();
1314 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1315 toggleCursorVisible();
1319 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1321 if (!isCursorVisible()) {
1322 LyXFont font; // = GetFont(par, cursor.pos);
1324 int const asc = lyxfont::maxAscent(font);
1325 int const desc = lyxfont::maxDescent(font);
1326 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1328 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1329 setCursorVisible(true);
1334 void InsetTabular::hideInsetCursor(BufferView * bv)
1336 if (isCursorVisible()) {
1337 bv->hideLockedInsetCursor();
1338 setCursorVisible(false);
1343 void InsetTabular::fitInsetCursor(BufferView * bv) const
1345 if (the_locking_inset) {
1346 the_locking_inset->fitInsetCursor(bv);
1351 int const asc = lyxfont::maxAscent(font);
1352 int const desc = lyxfont::maxDescent(font);
1353 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1357 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1361 actcell = actrow = actcol = 0;
1362 int ly = tabular->GetDescentOfRow(actrow);
1364 // first search the right row
1365 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1366 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1367 tabular->GetAscentOfRow(actrow + 1) +
1368 tabular->GetAdditionalHeight(actrow + 1));
1370 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1372 actcell = tabular->GetCellNumber(actrow, actcol);
1374 // now search the right column
1375 int lx = tabular->GetWidthOfColumn(actcell) -
1376 tabular->GetAdditionalWidth(actcell);
1377 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1378 lx += tabular->GetWidthOfColumn(actcell + 1)
1379 + tabular->GetAdditionalWidth(actcell);
1381 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1386 int InsetTabular::getCellXPos(int cell) const
1390 for (; !tabular->IsFirstCellInRow(c); --c)
1392 int lx = tabular->GetWidthOfColumn(cell);
1393 for (; c < cell; ++c) {
1394 lx += tabular->GetWidthOfColumn(c);
1396 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1400 void InsetTabular::resetPos(BufferView * bv) const
1402 if (!locked || nodraw())
1404 #warning This should be fixed in the right manner (20011128 Jug)
1405 // fast hack to fix infinite repaintings!
1408 in_reset_pos = true;
1410 actcol = tabular->column_of_cell(actcell);
1415 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1416 if (tabular->IsLastCellInRow(cell)) {
1417 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1418 tabular->GetAscentOfRow(actrow + 1) +
1419 tabular->GetAdditionalHeight(actrow + 1));
1423 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1424 int new_x = getCellXPos(actcell);
1425 int old_x = cursor_.x();
1428 // cursor.x(getCellXPos(actcell) + offset);
1429 if ((actcol < tabular->columns()-1) && scroll(false) &&
1430 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1433 updateLocal(bv, FULL, false);
1434 } else if (the_locking_inset &&
1435 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1437 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1438 if (xx > (bv->workWidth()-20)) {
1439 scroll(bv, -(xx - bv->workWidth() + 60));
1440 updateLocal(bv, FULL, false);
1441 } else if (xx < 20) {
1447 updateLocal(bv, FULL, false);
1449 } else if ((cursor_.x() - offset) > 20 &&
1450 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1451 > (bv->workWidth() - 20)) {
1452 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1453 updateLocal(bv, FULL, false);
1454 } else if ((cursor_.x() - offset) < 20) {
1455 scroll(bv, 20 - cursor_.x() + offset);
1456 updateLocal(bv, FULL, false);
1457 } else if (scroll(false) && top_x > 20 &&
1458 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1459 scroll(bv, old_x - cursor_.x());
1460 updateLocal(bv, FULL, false);
1462 if (the_locking_inset) {
1463 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1464 inset_y = cursor_.y();
1466 if ((!the_locking_inset ||
1467 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1468 actcell != oldcell) {
1469 InsetTabular * inset = const_cast<InsetTabular *>(this);
1470 bv->owner()->getDialogs()->updateTabular(inset);
1473 in_reset_pos = false;
1477 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1479 if (lock && !old_locking_inset) {
1480 if (activateCellInset(bv))
1483 bool moved = isRightToLeft(bv)
1484 ? movePrevCell(bv) : moveNextCell(bv);
1486 return FINISHED_RIGHT;
1487 if (lock && activateCellInset(bv))
1491 return DISPATCHED_NOUPDATE;
1495 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1497 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1500 if (lock) { // behind the inset
1501 if (activateCellInset(bv, 0, 0, 0, true))
1505 return DISPATCHED_NOUPDATE;
1509 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1511 int const ocell = actcell;
1512 actcell = tabular->GetCellAbove(actcell);
1513 if (actcell == ocell) // we moved out of the inset
1519 if (old_locking_inset) {
1520 old_locking_inset->getCursorPos(bv, x, y);
1521 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1523 if (activateCellInset(bv, x, 0))
1526 return DISPATCHED_NOUPDATE;
1530 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1532 int const ocell = actcell;
1533 actcell = tabular->GetCellBelow(actcell);
1534 if (actcell == ocell) // we moved out of the inset
1535 return FINISHED_DOWN;
1540 if (old_locking_inset) {
1541 old_locking_inset->getCursorPos(bv, x, y);
1542 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1544 if (activateCellInset(bv, x, 0))
1547 return DISPATCHED_NOUPDATE;
1551 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1553 if (isRightToLeft(bv)) {
1554 if (tabular->IsFirstCellInRow(actcell)) {
1555 int row = tabular->row_of_cell(actcell);
1556 if (row == tabular->rows() - 1)
1558 actcell = tabular->GetLastCellInRow(row);
1559 actcell = tabular->GetCellBelow(actcell);
1566 if (tabular->IsLastCell(actcell))
1571 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1572 isRightToLeftPar(bv->buffer()->params);
1573 activateCellInset(bv, 0, 0, 0, !rtl);
1580 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1582 if (isRightToLeft(bv)) {
1583 if (tabular->IsLastCellInRow(actcell)) {
1584 int row = tabular->row_of_cell(actcell);
1587 actcell = tabular->GetFirstCellInRow(row);
1588 actcell = tabular->GetCellAbove(actcell);
1590 if (tabular->IsLastCell(actcell))
1595 if (!actcell) // first cell
1600 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1601 isRightToLeftPar(bv->buffer()->params);
1602 activateCellInset(bv, 0, 0, 0, !rtl);
1609 bool InsetTabular::deletable() const
1615 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1619 setSelection(0, tabular->GetNumberOfCells() - 1);
1621 if (hasSelection()) {
1622 setUndo(bv, Undo::EDIT,
1623 bv->text->cursor.par(),
1624 bv->text->cursor.par()->next());
1625 bool frozen = undo_frozen;
1628 // apply the fontchange on the whole selection
1633 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1634 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1635 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1636 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1641 updateLocal(bv, INIT, true);
1643 if (the_locking_inset)
1644 the_locking_inset->setFont(bv, font, tall);
1648 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1650 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1653 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1654 string const tmp = tabularFeature[i].feature;
1656 if (tmp == what.substr(0, tmp.length())) {
1657 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1658 //tabularFeatures[i].feature.length())) {
1659 action = tabularFeature[i].action;
1663 if (action == LyXTabular::LAST_ACTION)
1667 frontStrip(what.substr(tabularFeature[i].feature.length()));
1668 tabularFeatures(bv, action, val);
1672 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1673 string const & special, bool & flag)
1675 if (special == "dl_above") {
1678 } else if (special == "dl_below") {
1679 ltt.bottomDL = flag;
1681 } else if (special == "empty") {
1691 void InsetTabular::tabularFeatures(BufferView * bv,
1692 LyXTabular::Feature feature,
1693 string const & value)
1699 bool setLines = false;
1700 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1701 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1704 case LyXTabular::M_ALIGN_LEFT:
1705 case LyXTabular::ALIGN_LEFT:
1706 setAlign = LYX_ALIGN_LEFT;
1708 case LyXTabular::M_ALIGN_RIGHT:
1709 case LyXTabular::ALIGN_RIGHT:
1710 setAlign = LYX_ALIGN_RIGHT;
1712 case LyXTabular::M_ALIGN_CENTER:
1713 case LyXTabular::ALIGN_CENTER:
1714 setAlign = LYX_ALIGN_CENTER;
1716 case LyXTabular::M_VALIGN_TOP:
1717 case LyXTabular::VALIGN_TOP:
1718 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1720 case LyXTabular::M_VALIGN_BOTTOM:
1721 case LyXTabular::VALIGN_BOTTOM:
1722 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1724 case LyXTabular::M_VALIGN_CENTER:
1725 case LyXTabular::VALIGN_CENTER:
1726 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1731 if (hasSelection()) {
1732 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1734 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1735 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1737 setUndo(bv, Undo::FINISH,
1738 bv->text->cursor.par(),
1739 bv->text->cursor.par()->next());
1741 int row = tabular->row_of_cell(actcell);
1742 int column = tabular->column_of_cell(actcell);
1744 LyXTabular::ltType ltt;
1747 case LyXTabular::SET_PWIDTH:
1749 LyXLength const vallen(value);
1750 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1752 bool const update = (tmplen != vallen);
1753 tabular->SetColumnPWidth(actcell, vallen);
1756 for (int i = 0; i < tabular->rows(); ++i) {
1757 cell = tabular->GetCellNumber(i,column);
1758 tabular->GetCellInset(cell)->resizeLyXText(bv);
1760 updateLocal(bv, INIT, true);
1764 case LyXTabular::SET_MPWIDTH:
1766 LyXLength const vallen(value);
1767 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1769 bool const update = (tmplen != vallen);
1770 tabular->SetMColumnPWidth(actcell, vallen);
1772 for (int i = 0; i < tabular->rows(); ++i) {
1773 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1776 updateLocal(bv, INIT, true);
1780 case LyXTabular::SET_SPECIAL_COLUMN:
1781 case LyXTabular::SET_SPECIAL_MULTI:
1782 tabular->SetAlignSpecial(actcell,value,feature);
1783 updateLocal(bv, FULL, true);
1785 case LyXTabular::APPEND_ROW:
1786 // append the row into the tabular
1787 unlockInsetInInset(bv, the_locking_inset);
1788 tabular->AppendRow(actcell);
1789 updateLocal(bv, INIT, true);
1791 case LyXTabular::APPEND_COLUMN:
1792 // append the column into the tabular
1793 unlockInsetInInset(bv, the_locking_inset);
1794 tabular->AppendColumn(actcell);
1795 actcell = tabular->GetCellNumber(row, column);
1796 updateLocal(bv, INIT, true);
1798 case LyXTabular::DELETE_ROW:
1799 unlockInsetInInset(bv, the_locking_inset);
1800 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1801 tabular->DeleteRow(sel_row_start);
1803 if (sel_row_start >= tabular->rows())
1805 actcell = tabular->GetCellNumber(sel_row_start, column);
1807 updateLocal(bv, INIT, true);
1809 case LyXTabular::DELETE_COLUMN:
1810 unlockInsetInInset(bv, the_locking_inset);
1811 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1812 tabular->DeleteColumn(sel_col_start);
1814 if (sel_col_start >= tabular->columns())
1816 actcell = tabular->GetCellNumber(row, sel_col_start);
1818 updateLocal(bv, INIT, true);
1820 case LyXTabular::M_TOGGLE_LINE_TOP:
1822 case LyXTabular::TOGGLE_LINE_TOP:
1824 bool lineSet = !tabular->TopLine(actcell, flag);
1825 for (int i = sel_row_start; i <= sel_row_end; ++i)
1826 for (int j = sel_col_start; j <= sel_col_end; ++j)
1827 tabular->SetTopLine(
1828 tabular->GetCellNumber(i, j),
1830 updateLocal(bv, INIT, true);
1834 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1836 case LyXTabular::TOGGLE_LINE_BOTTOM:
1838 bool lineSet = !tabular->BottomLine(actcell, flag);
1839 for (int i = sel_row_start; i <= sel_row_end; ++i)
1840 for (int j = sel_col_start; j <= sel_col_end; ++j)
1841 tabular->SetBottomLine(
1842 tabular->GetCellNumber(i, j),
1845 updateLocal(bv, INIT, true);
1849 case LyXTabular::M_TOGGLE_LINE_LEFT:
1851 case LyXTabular::TOGGLE_LINE_LEFT:
1853 bool lineSet = !tabular->LeftLine(actcell, flag);
1854 for (int i = sel_row_start; i <= sel_row_end; ++i)
1855 for (int j = sel_col_start; j <= sel_col_end; ++j)
1856 tabular->SetLeftLine(
1857 tabular->GetCellNumber(i,j),
1860 updateLocal(bv, INIT, true);
1864 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1866 case LyXTabular::TOGGLE_LINE_RIGHT:
1868 bool lineSet = !tabular->RightLine(actcell, flag);
1869 for (int i = sel_row_start; i <= sel_row_end; ++i)
1870 for (int j = sel_col_start; j <= sel_col_end; ++j)
1871 tabular->SetRightLine(
1872 tabular->GetCellNumber(i,j),
1875 updateLocal(bv, INIT, true);
1879 case LyXTabular::M_ALIGN_LEFT:
1880 case LyXTabular::M_ALIGN_RIGHT:
1881 case LyXTabular::M_ALIGN_CENTER:
1883 case LyXTabular::ALIGN_LEFT:
1884 case LyXTabular::ALIGN_RIGHT:
1885 case LyXTabular::ALIGN_CENTER:
1886 for (int i = sel_row_start; i <= sel_row_end; ++i)
1887 for (int j = sel_col_start; j <= sel_col_end; ++j)
1888 tabular->SetAlignment(
1889 tabular->GetCellNumber(i, j),
1892 updateLocal(bv, INIT, true);
1894 case LyXTabular::M_VALIGN_TOP:
1895 case LyXTabular::M_VALIGN_BOTTOM:
1896 case LyXTabular::M_VALIGN_CENTER:
1898 case LyXTabular::VALIGN_TOP:
1899 case LyXTabular::VALIGN_BOTTOM:
1900 case LyXTabular::VALIGN_CENTER:
1901 for (int i = sel_row_start; i <= sel_row_end; ++i)
1902 for (int j = sel_col_start; j <= sel_col_end; ++j)
1903 tabular->SetVAlignment(
1904 tabular->GetCellNumber(i, j),
1906 updateLocal(bv, INIT, true);
1908 case LyXTabular::MULTICOLUMN:
1910 if (sel_row_start != sel_row_end) {
1911 Alert::alert(_("Impossible Operation!"),
1912 _("Multicolumns can only be horizontally."),
1916 // just multicol for one Single Cell
1917 if (!hasSelection()) {
1918 // check wether we are completly in a multicol
1919 if (tabular->IsMultiColumn(actcell)) {
1920 tabular->UnsetMultiColumn(actcell);
1921 updateLocal(bv, INIT, true);
1923 tabular->SetMultiColumn(actcell, 1);
1924 updateLocal(bv, CELL, true);
1928 // we have a selection so this means we just add all this
1929 // cells to form a multicolumn cell
1933 if (sel_cell_start > sel_cell_end) {
1934 s_start = sel_cell_end;
1935 s_end = sel_cell_start;
1937 s_start = sel_cell_start;
1938 s_end = sel_cell_end;
1940 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1943 updateLocal(bv, INIT, true);
1946 case LyXTabular::SET_ALL_LINES:
1948 case LyXTabular::UNSET_ALL_LINES:
1949 for (int i = sel_row_start; i <= sel_row_end; ++i)
1950 for (int j = sel_col_start; j <= sel_col_end; ++j)
1951 tabular->SetAllLines(
1952 tabular->GetCellNumber(i,j), setLines);
1953 updateLocal(bv, INIT, true);
1955 case LyXTabular::SET_LONGTABULAR:
1956 tabular->SetLongTabular(true);
1957 updateLocal(bv, INIT, true); // because this toggles displayed
1959 case LyXTabular::UNSET_LONGTABULAR:
1960 tabular->SetLongTabular(false);
1961 updateLocal(bv, INIT, true); // because this toggles displayed
1963 case LyXTabular::SET_ROTATE_TABULAR:
1964 tabular->SetRotateTabular(true);
1966 case LyXTabular::UNSET_ROTATE_TABULAR:
1967 tabular->SetRotateTabular(false);
1969 case LyXTabular::SET_ROTATE_CELL:
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->SetRotateCell(
1973 tabular->GetCellNumber(i, j),
1976 case LyXTabular::UNSET_ROTATE_CELL:
1977 for (int i = sel_row_start; i <= sel_row_end; ++i)
1978 for (int j = sel_col_start; j <= sel_col_end; ++j)
1979 tabular->SetRotateCell(
1980 tabular->GetCellNumber(i, j), false);
1982 case LyXTabular::SET_USEBOX:
1984 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1985 if (val == tabular->GetUsebox(actcell))
1986 val = LyXTabular::BOX_NONE;
1987 for (int i = sel_row_start; i <= sel_row_end; ++i)
1988 for (int j = sel_col_start; j <= sel_col_end; ++j)
1990 tabular->GetCellNumber(i, j), val);
1993 case LyXTabular::UNSET_LTFIRSTHEAD:
1995 case LyXTabular::SET_LTFIRSTHEAD:
1996 (void)tabular->GetRowOfLTFirstHead(row, ltt);
1997 checkLongtableSpecial(ltt, value, flag);
1998 tabular->SetLTHead(row, flag, ltt, true);
2000 case LyXTabular::UNSET_LTHEAD:
2002 case LyXTabular::SET_LTHEAD:
2003 (void)tabular->GetRowOfLTHead(row, ltt);
2004 checkLongtableSpecial(ltt, value, flag);
2005 tabular->SetLTHead(row, flag, ltt, false);
2007 case LyXTabular::UNSET_LTFOOT:
2009 case LyXTabular::SET_LTFOOT:
2010 (void)tabular->GetRowOfLTFoot(row, ltt);
2011 checkLongtableSpecial(ltt, value, flag);
2012 tabular->SetLTFoot(row, flag, ltt, false);
2014 case LyXTabular::UNSET_LTLASTFOOT:
2016 case LyXTabular::SET_LTLASTFOOT:
2017 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2018 checkLongtableSpecial(ltt, value, flag);
2019 tabular->SetLTFoot(row, flag, ltt, true);
2021 case LyXTabular::SET_LTNEWPAGE:
2023 bool what = !tabular->GetLTNewPage(row);
2024 tabular->SetLTNewPage(row, what);
2027 // dummy stuff just to avoid warnings
2028 case LyXTabular::LAST_ACTION:
2034 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2037 UpdatableInset * inset =
2038 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2039 LyXFont font(LyXFont::ALL_SANE);
2041 x = inset->x() + inset->width(bv, font);
2042 y = inset->descent(bv, font);
2044 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2045 //inset_y = cursor.y();
2046 inset->edit(bv, x, y, button);
2047 if (!the_locking_inset)
2049 updateLocal(bv, CELL, false);
2050 return (the_locking_inset != 0);
2054 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2057 inset_x = cursor_.x()
2058 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2059 inset_y = cursor_.y();
2060 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2064 bool InsetTabular::insetHit(BufferView *, int x, int) const
2067 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2071 // This returns paperWidth() if the cell-width is unlimited or the width
2072 // in pixels if we have a pwidth for this cell.
2073 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2075 LyXLength const len = tabular->GetPWidth(cell);
2079 #ifdef WITH_WARNINGS
2080 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2082 return VSpace(len).inPixels(bv);
2086 int InsetTabular::getMaxWidth(BufferView * bv,
2087 UpdatableInset const * inset) const
2089 int cell = tabular->cur_cell;
2090 if (tabular->GetCellInset(cell) != inset) {
2092 if (tabular->GetCellInset(cell) != inset) {
2094 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2099 int const n = tabular->GetNumberOfCells();
2102 for (cell = 0; cell < n; ++cell) {
2103 if (tabular->GetCellInset(cell) == inset)
2109 lyxerr << "Own inset not found, shouldn't really happen!\n";
2113 int w = getMaxWidthOfCell(bv, cell);
2115 // because the inset then subtracts it's top_x and owner->x()
2116 w += (inset->x() - top_x);
2123 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2125 resizeLyXText(bv, recursive);
2129 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2132 for(int i = 0; i < tabular->rows(); ++i) {
2133 for(int j = 0; j < tabular->columns(); ++j) {
2134 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2142 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2143 bool const recursive) const
2145 if (the_locking_inset)
2146 return the_locking_inset->getLyXText(bv, recursive);
2148 // if we're locked lock the actual insettext and return it's LyXText!!!
2150 UpdatableInset * inset =
2151 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2152 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2153 return the_locking_inset->getLyXText(bv, recursive);
2156 return Inset::getLyXText(bv, recursive);
2160 bool InsetTabular::showInsetDialog(BufferView * bv) const
2162 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2163 bv->owner()->getDialogs()
2164 ->showTabular(const_cast<InsetTabular *>(this));
2169 void InsetTabular::openLayoutDialog(BufferView * bv) const
2171 if (the_locking_inset) {
2172 InsetTabular * i = static_cast<InsetTabular *>
2173 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2175 i->openLayoutDialog(bv);
2179 bv->owner()->getDialogs()->showTabular(
2180 const_cast<InsetTabular *>(this));
2185 // functions returns:
2189 // 3 ... toggled off
2191 func_status::value_type InsetTabular::getStatus(string const & what) const
2193 int action = LyXTabular::LAST_ACTION;
2194 func_status::value_type status = func_status::OK;
2197 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2198 string const tmp = tabularFeature[i].feature;
2199 if (tmp == what.substr(0, tmp.length())) {
2200 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2201 // tabularFeatures[i].feature.length())) {
2202 action = tabularFeature[i].action;
2206 if (action == LyXTabular::LAST_ACTION)
2207 return func_status::Unknown;
2209 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2214 LyXTabular::ltType dummyltt;
2217 if (hasSelection()) {
2218 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2220 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2224 case LyXTabular::SET_PWIDTH:
2225 case LyXTabular::SET_MPWIDTH:
2226 case LyXTabular::SET_SPECIAL_COLUMN:
2227 case LyXTabular::SET_SPECIAL_MULTI:
2228 status |= func_status::Disabled;
2231 case LyXTabular::APPEND_ROW:
2232 case LyXTabular::APPEND_COLUMN:
2233 case LyXTabular::DELETE_ROW:
2234 case LyXTabular::DELETE_COLUMN:
2235 case LyXTabular::SET_ALL_LINES:
2236 case LyXTabular::UNSET_ALL_LINES:
2237 status |= func_status::OK;
2240 case LyXTabular::MULTICOLUMN:
2241 if (tabular->IsMultiColumn(actcell))
2242 status |= func_status::ToggleOn;
2244 status |= func_status::ToggleOff;
2246 case LyXTabular::M_TOGGLE_LINE_TOP:
2248 case LyXTabular::TOGGLE_LINE_TOP:
2249 if (tabular->TopLine(actcell, flag))
2250 status |= func_status::ToggleOn;
2252 status |= func_status::ToggleOff;
2254 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2256 case LyXTabular::TOGGLE_LINE_BOTTOM:
2257 if (tabular->BottomLine(actcell, flag))
2258 status |= func_status::ToggleOn;
2260 status |= func_status::ToggleOff;
2262 case LyXTabular::M_TOGGLE_LINE_LEFT:
2264 case LyXTabular::TOGGLE_LINE_LEFT:
2265 if (tabular->LeftLine(actcell, flag))
2266 status |= func_status::ToggleOn;
2268 status |= func_status::ToggleOff;
2270 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2272 case LyXTabular::TOGGLE_LINE_RIGHT:
2273 if (tabular->RightLine(actcell, flag))
2274 status |= func_status::ToggleOn;
2276 status |= func_status::ToggleOff;
2278 case LyXTabular::M_ALIGN_LEFT:
2280 case LyXTabular::ALIGN_LEFT:
2281 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2282 status |= func_status::ToggleOn;
2284 status |= func_status::ToggleOff;
2286 case LyXTabular::M_ALIGN_RIGHT:
2288 case LyXTabular::ALIGN_RIGHT:
2289 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2290 status |= func_status::ToggleOn;
2292 status |= func_status::ToggleOff;
2294 case LyXTabular::M_ALIGN_CENTER:
2296 case LyXTabular::ALIGN_CENTER:
2297 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2298 status |= func_status::ToggleOn;
2300 status |= func_status::ToggleOff;
2302 case LyXTabular::M_VALIGN_TOP:
2304 case LyXTabular::VALIGN_TOP:
2305 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2306 status |= func_status::ToggleOn;
2308 status |= func_status::ToggleOff;
2310 case LyXTabular::M_VALIGN_BOTTOM:
2312 case LyXTabular::VALIGN_BOTTOM:
2313 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2314 status |= func_status::ToggleOn;
2316 status |= func_status::ToggleOff;
2318 case LyXTabular::M_VALIGN_CENTER:
2320 case LyXTabular::VALIGN_CENTER:
2321 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2322 status |= func_status::ToggleOn;
2324 status |= func_status::ToggleOff;
2326 case LyXTabular::SET_LONGTABULAR:
2327 if (tabular->IsLongTabular())
2328 status |= func_status::ToggleOn;
2330 status |= func_status::ToggleOff;
2332 case LyXTabular::UNSET_LONGTABULAR:
2333 if (!tabular->IsLongTabular())
2334 status |= func_status::ToggleOn;
2336 status |= func_status::ToggleOff;
2338 case LyXTabular::SET_ROTATE_TABULAR:
2339 if (tabular->GetRotateTabular())
2340 status |= func_status::ToggleOn;
2342 status |= func_status::ToggleOff;
2344 case LyXTabular::UNSET_ROTATE_TABULAR:
2345 if (!tabular->GetRotateTabular())
2346 status |= func_status::ToggleOn;
2348 status |= func_status::ToggleOff;
2350 case LyXTabular::SET_ROTATE_CELL:
2351 if (tabular->GetRotateCell(actcell))
2352 status |= func_status::ToggleOn;
2354 status |= func_status::ToggleOff;
2356 case LyXTabular::UNSET_ROTATE_CELL:
2357 if (!tabular->GetRotateCell(actcell))
2358 status |= func_status::ToggleOn;
2360 status |= func_status::ToggleOff;
2362 case LyXTabular::SET_USEBOX:
2363 if (strToInt(argument) == tabular->GetUsebox(actcell))
2364 status |= func_status::ToggleOn;
2366 status |= func_status::ToggleOff;
2368 case LyXTabular::SET_LTFIRSTHEAD:
2369 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2370 status |= func_status::ToggleOn;
2372 status |= func_status::ToggleOff;
2374 case LyXTabular::SET_LTHEAD:
2375 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2376 status |= func_status::ToggleOn;
2378 status |= func_status::ToggleOff;
2380 case LyXTabular::SET_LTFOOT:
2381 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2382 status |= func_status::ToggleOn;
2384 status |= func_status::ToggleOff;
2386 case LyXTabular::SET_LTLASTFOOT:
2387 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2388 status |= func_status::ToggleOn;
2390 status |= func_status::ToggleOff;
2392 case LyXTabular::SET_LTNEWPAGE:
2393 if (tabular->GetLTNewPage(sel_row_start))
2394 status |= func_status::ToggleOn;
2396 status |= func_status::ToggleOff;
2399 status = func_status::Disabled;
2406 std::vector<string> const InsetTabular::getLabelList() const
2408 return tabular->getLabelList();
2412 bool InsetTabular::copySelection(BufferView * bv)
2414 if (!hasSelection())
2417 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2418 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2419 if (sel_col_start > sel_col_end) {
2420 sel_col_start = sel_col_end;
2421 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2423 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2425 int const columns = sel_col_end - sel_col_start + 1;
2427 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2428 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2429 if (sel_row_start > sel_row_end) {
2430 swap(sel_row_start, sel_row_end);
2432 int const rows = sel_row_end - sel_row_start + 1;
2434 delete paste_tabular;
2435 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2436 for (int i = 0; i < sel_row_start; ++i)
2437 paste_tabular->DeleteRow(0);
2438 while (paste_tabular->rows() > rows)
2439 paste_tabular->DeleteRow(rows);
2440 paste_tabular->SetTopLine(0, true, true);
2441 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2443 for (int i = 0; i < sel_col_start; ++i)
2444 paste_tabular->DeleteColumn(0);
2445 while (paste_tabular->columns() > columns)
2446 paste_tabular->DeleteColumn(columns);
2447 paste_tabular->SetLeftLine(0, true, true);
2448 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2452 paste_tabular->Ascii(bv->buffer(), sstr);
2453 bv->stuffClipboard(sstr.str().c_str());
2458 bool InsetTabular::pasteSelection(BufferView * bv)
2463 for (int r1 = 0, r2 = actrow;
2464 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2466 for(int c1 = 0, c2 = actcol;
2467 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2469 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2470 tabular->IsPartOfMultiColumn(r2,c2))
2472 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2476 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2480 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2481 int const n2 = tabular->GetCellNumber(r2, c2);
2482 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2483 tabular->GetCellInset(n2)->setOwner(this);
2484 tabular->GetCellInset(n2)->deleteLyXText(bv);
2491 bool InsetTabular::cutSelection()
2493 if (!hasSelection())
2496 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2497 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2498 if (sel_col_start > sel_col_end) {
2499 sel_col_start = sel_col_end;
2500 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2502 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2504 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2505 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2506 if (sel_row_start > sel_row_end) {
2507 swap(sel_row_start, sel_row_end);
2509 if (sel_cell_start > sel_cell_end) {
2510 swap(sel_cell_start, sel_cell_end);
2512 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2513 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2514 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2521 bool InsetTabular::isRightToLeft(BufferView *bv )
2523 return bv->getParentLanguage(this)->RightToLeft();
2527 bool InsetTabular::nodraw() const
2529 if (!UpdatableInset::nodraw() && the_locking_inset)
2530 return the_locking_inset->nodraw();
2531 return UpdatableInset::nodraw();
2535 int InsetTabular::scroll(bool recursive) const
2537 int sx = UpdatableInset::scroll(false);
2539 if (recursive && the_locking_inset)
2540 sx += the_locking_inset->scroll(recursive);
2546 bool InsetTabular::doClearArea() const
2548 return !locked || (need_update & (FULL|INIT));
2552 void InsetTabular::getSelection(int & srow, int & erow,
2553 int & scol, int & ecol) const
2555 int const start = hasSelection() ? sel_cell_start : actcell;
2556 int const end = hasSelection() ? sel_cell_end : actcell;
2558 srow = tabular->row_of_cell(start);
2559 erow = tabular->row_of_cell(end);
2564 scol = tabular->column_of_cell(start);
2565 ecol = tabular->column_of_cell(end);
2569 ecol = tabular->right_column_of_cell(end);
2574 Paragraph * InsetTabular::getParFromID(int id) const
2577 for(int i = 0; i < tabular->rows(); ++i) {
2578 for(int j = 0; j < tabular->columns(); ++j) {
2579 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2587 Paragraph * InsetTabular::firstParagraph() const
2589 if (the_locking_inset)
2590 return the_locking_inset->firstParagraph();
2595 Paragraph * InsetTabular::getFirstParagraph(int i) const
2597 return (i < tabular->GetNumberOfCells())
2598 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2603 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2605 if (the_locking_inset)
2606 return the_locking_inset->cursor(bv);
2607 return Inset::cursor(bv);
2611 Inset * InsetTabular::getInsetFromID(int id_arg) const
2614 return const_cast<InsetTabular *>(this);
2617 for(int i = 0; i < tabular->rows(); ++i) {
2618 for(int j = 0; j < tabular->columns(); ++j) {
2619 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2628 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2630 if (the_locking_inset) {
2631 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2634 if (tabular->IsLastCell(actcell)) {
2635 bv->unlockInset(const_cast<InsetTabular *>(this));
2641 // otherwise we have to lock the next inset and ask for it's selecttion
2642 UpdatableInset * inset =
2643 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2644 inset->edit(bv, 0, 0, 0);
2645 string const str(selectNextWordInt(bv, value));
2653 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2655 // when entering this function the inset should be ALWAYS locked!
2656 lyx::Assert(the_locking_inset);
2658 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2662 if (tabular->IsLastCell(actcell)) {
2663 bv->unlockInset(const_cast<InsetTabular *>(this));
2667 // otherwise we have to lock the next inset and ask for it's selecttion
2668 UpdatableInset * inset =
2669 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2671 return selectNextWordInt(bv, value);
2675 void InsetTabular::selectSelectedWord(BufferView * bv)
2677 if (the_locking_inset) {
2678 the_locking_inset->selectSelectedWord(bv);
2685 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2687 if (the_locking_inset) {
2688 the_locking_inset->toggleSelection(bv, kill_selection);
2693 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2694 bool const & cs, bool const & mw)
2696 if (the_locking_inset) {
2697 if (the_locking_inset->searchForward(bv, str, cs, mw))
2699 if (tabular->IsLastCell(actcell)) {
2700 bv->unlockInset(const_cast<InsetTabular *>(this));
2705 // otherwise we have to lock the next inset and search there
2706 UpdatableInset * inset =
2707 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2710 bool const res = searchForward(bv, str, cs, mw);
2711 updateLocal(bv, NONE, false);
2712 bv->updateInset(const_cast<InsetTabular *>(this), false);
2715 return searchForward(bv, str, cs, mw);
2720 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2721 bool const & cs, bool const & mw)
2723 if (the_locking_inset) {
2724 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2726 if (!actcell) { // we are already in the first cell
2727 bv->unlockInset(const_cast<InsetTabular *>(this));
2732 // otherwise we have to lock the next inset and search there
2733 UpdatableInset * inset =
2734 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2735 inset->edit(bv, false);
2737 bool const res = searchBackward(bv, str, cs, mw);
2738 bv->updateInset(const_cast<InsetTabular *>(this), false);
2741 return searchBackward(bv, str, cs, mw);
2746 bool InsetTabular::insetAllowed(Inset::Code code) const
2748 if (the_locking_inset)
2749 return the_locking_inset->insetAllowed(code);