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);
1673 void InsetTabular::tabularFeatures(BufferView * bv,
1674 LyXTabular::Feature feature,
1675 string const & value)
1681 bool setLines = false;
1682 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1683 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1686 case LyXTabular::M_ALIGN_LEFT:
1687 case LyXTabular::ALIGN_LEFT:
1688 setAlign = LYX_ALIGN_LEFT;
1690 case LyXTabular::M_ALIGN_RIGHT:
1691 case LyXTabular::ALIGN_RIGHT:
1692 setAlign = LYX_ALIGN_RIGHT;
1694 case LyXTabular::M_ALIGN_CENTER:
1695 case LyXTabular::ALIGN_CENTER:
1696 setAlign = LYX_ALIGN_CENTER;
1698 case LyXTabular::M_VALIGN_TOP:
1699 case LyXTabular::VALIGN_TOP:
1700 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1702 case LyXTabular::M_VALIGN_BOTTOM:
1703 case LyXTabular::VALIGN_BOTTOM:
1704 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1706 case LyXTabular::M_VALIGN_CENTER:
1707 case LyXTabular::VALIGN_CENTER:
1708 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1713 if (hasSelection()) {
1714 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1716 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1717 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1719 setUndo(bv, Undo::FINISH,
1720 bv->text->cursor.par(),
1721 bv->text->cursor.par()->next());
1723 LyXTabular::ltType ltt;
1724 int row = ltt.row = tabular->row_of_cell(actcell);
1725 int column = tabular->column_of_cell(actcell);
1729 case LyXTabular::SET_PWIDTH:
1731 LyXLength const vallen(value);
1732 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1734 bool const update = (tmplen != vallen);
1735 tabular->SetColumnPWidth(actcell, vallen);
1737 for (int i = 0; i < tabular->rows(); ++i) {
1738 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1741 updateLocal(bv, INIT, true);
1745 case LyXTabular::SET_MPWIDTH:
1747 LyXLength const vallen(value);
1748 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1750 bool const update = (tmplen != vallen);
1751 tabular->SetMColumnPWidth(actcell, vallen);
1753 for (int i = 0; i < tabular->rows(); ++i) {
1754 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1757 updateLocal(bv, INIT, true);
1761 case LyXTabular::SET_SPECIAL_COLUMN:
1762 case LyXTabular::SET_SPECIAL_MULTI:
1763 tabular->SetAlignSpecial(actcell,value,feature);
1764 updateLocal(bv, FULL, true);
1766 case LyXTabular::APPEND_ROW:
1767 // append the row into the tabular
1768 unlockInsetInInset(bv, the_locking_inset);
1769 tabular->AppendRow(actcell);
1770 updateLocal(bv, INIT, true);
1772 case LyXTabular::APPEND_COLUMN:
1773 // append the column into the tabular
1774 unlockInsetInInset(bv, the_locking_inset);
1775 tabular->AppendColumn(actcell);
1776 actcell = tabular->GetCellNumber(row, column);
1777 updateLocal(bv, INIT, true);
1779 case LyXTabular::DELETE_ROW:
1780 unlockInsetInInset(bv, the_locking_inset);
1781 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1782 tabular->DeleteRow(sel_row_start);
1784 if (sel_row_start >= tabular->rows())
1786 actcell = tabular->GetCellNumber(sel_row_start, column);
1788 updateLocal(bv, INIT, true);
1790 case LyXTabular::DELETE_COLUMN:
1791 unlockInsetInInset(bv, the_locking_inset);
1792 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1793 tabular->DeleteColumn(sel_col_start);
1795 if (sel_col_start >= tabular->columns())
1797 actcell = tabular->GetCellNumber(row, sel_col_start);
1799 updateLocal(bv, INIT, true);
1801 case LyXTabular::M_TOGGLE_LINE_TOP:
1803 case LyXTabular::TOGGLE_LINE_TOP:
1805 bool lineSet = !tabular->TopLine(actcell, flag);
1806 for (int i = sel_row_start; i <= sel_row_end; ++i)
1807 for (int j = sel_col_start; j <= sel_col_end; ++j)
1808 tabular->SetTopLine(
1809 tabular->GetCellNumber(i, j),
1811 updateLocal(bv, INIT, true);
1815 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1817 case LyXTabular::TOGGLE_LINE_BOTTOM:
1819 bool lineSet = !tabular->BottomLine(actcell, flag);
1820 for (int i = sel_row_start; i <= sel_row_end; ++i)
1821 for (int j = sel_col_start; j <= sel_col_end; ++j)
1822 tabular->SetBottomLine(
1823 tabular->GetCellNumber(i, j),
1826 updateLocal(bv, INIT, true);
1830 case LyXTabular::M_TOGGLE_LINE_LEFT:
1832 case LyXTabular::TOGGLE_LINE_LEFT:
1834 bool lineSet = !tabular->LeftLine(actcell, flag);
1835 for (int i = sel_row_start; i <= sel_row_end; ++i)
1836 for (int j = sel_col_start; j <= sel_col_end; ++j)
1837 tabular->SetLeftLine(
1838 tabular->GetCellNumber(i,j),
1841 updateLocal(bv, INIT, true);
1845 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1847 case LyXTabular::TOGGLE_LINE_RIGHT:
1849 bool lineSet = !tabular->RightLine(actcell, flag);
1850 for (int i = sel_row_start; i <= sel_row_end; ++i)
1851 for (int j = sel_col_start; j <= sel_col_end; ++j)
1852 tabular->SetRightLine(
1853 tabular->GetCellNumber(i,j),
1856 updateLocal(bv, INIT, true);
1860 case LyXTabular::M_ALIGN_LEFT:
1861 case LyXTabular::M_ALIGN_RIGHT:
1862 case LyXTabular::M_ALIGN_CENTER:
1864 case LyXTabular::ALIGN_LEFT:
1865 case LyXTabular::ALIGN_RIGHT:
1866 case LyXTabular::ALIGN_CENTER:
1867 for (int i = sel_row_start; i <= sel_row_end; ++i)
1868 for (int j = sel_col_start; j <= sel_col_end; ++j)
1869 tabular->SetAlignment(
1870 tabular->GetCellNumber(i, j),
1873 updateLocal(bv, INIT, true);
1875 case LyXTabular::M_VALIGN_TOP:
1876 case LyXTabular::M_VALIGN_BOTTOM:
1877 case LyXTabular::M_VALIGN_CENTER:
1879 case LyXTabular::VALIGN_TOP:
1880 case LyXTabular::VALIGN_BOTTOM:
1881 case LyXTabular::VALIGN_CENTER:
1882 for (int i = sel_row_start; i <= sel_row_end; ++i)
1883 for (int j = sel_col_start; j <= sel_col_end; ++j)
1884 tabular->SetVAlignment(
1885 tabular->GetCellNumber(i, j),
1887 updateLocal(bv, INIT, true);
1889 case LyXTabular::MULTICOLUMN:
1891 if (sel_row_start != sel_row_end) {
1892 Alert::alert(_("Impossible Operation!"),
1893 _("Multicolumns can only be horizontally."),
1897 // just multicol for one Single Cell
1898 if (!hasSelection()) {
1899 // check wether we are completly in a multicol
1900 if (tabular->IsMultiColumn(actcell)) {
1901 tabular->UnsetMultiColumn(actcell);
1902 updateLocal(bv, INIT, true);
1904 tabular->SetMultiColumn(actcell, 1);
1905 updateLocal(bv, CELL, true);
1909 // we have a selection so this means we just add all this
1910 // cells to form a multicolumn cell
1914 if (sel_cell_start > sel_cell_end) {
1915 s_start = sel_cell_end;
1916 s_end = sel_cell_start;
1918 s_start = sel_cell_start;
1919 s_end = sel_cell_end;
1921 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1924 updateLocal(bv, INIT, true);
1927 case LyXTabular::SET_ALL_LINES:
1929 case LyXTabular::UNSET_ALL_LINES:
1930 for (int i = sel_row_start; i <= sel_row_end; ++i)
1931 for (int j = sel_col_start; j <= sel_col_end; ++j)
1932 tabular->SetAllLines(
1933 tabular->GetCellNumber(i,j), setLines);
1934 updateLocal(bv, INIT, true);
1936 case LyXTabular::SET_LONGTABULAR:
1937 tabular->SetLongTabular(true);
1938 updateLocal(bv, INIT, true); // because this toggles displayed
1940 case LyXTabular::UNSET_LONGTABULAR:
1941 tabular->SetLongTabular(false);
1942 updateLocal(bv, INIT, true); // because this toggles displayed
1944 case LyXTabular::SET_ROTATE_TABULAR:
1945 tabular->SetRotateTabular(true);
1947 case LyXTabular::UNSET_ROTATE_TABULAR:
1948 tabular->SetRotateTabular(false);
1950 case LyXTabular::SET_ROTATE_CELL:
1951 for (int i = sel_row_start; i <= sel_row_end; ++i)
1952 for (int j = sel_col_start; j<=sel_col_end; ++j)
1953 tabular->SetRotateCell(
1954 tabular->GetCellNumber(i, j),
1957 case LyXTabular::UNSET_ROTATE_CELL:
1958 for (int i = sel_row_start; i <= sel_row_end; ++i)
1959 for (int j = sel_col_start; j <= sel_col_end; ++j)
1960 tabular->SetRotateCell(
1961 tabular->GetCellNumber(i, j), false);
1963 case LyXTabular::SET_USEBOX:
1965 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1966 if (val == tabular->GetUsebox(actcell))
1967 val = LyXTabular::BOX_NONE;
1968 for (int i = sel_row_start; i <= sel_row_end; ++i)
1969 for (int j = sel_col_start; j <= sel_col_end; ++j)
1971 tabular->GetCellNumber(i, j), val);
1974 case LyXTabular::UNSET_LTFIRSTHEAD:
1976 case LyXTabular::SET_LTFIRSTHEAD:
1977 tabular->SetLTHead(ltt, true);
1979 case LyXTabular::UNSET_LTHEAD:
1981 case LyXTabular::SET_LTHEAD:
1982 tabular->SetLTHead(ltt, false);
1984 case LyXTabular::UNSET_LTFOOT:
1986 case LyXTabular::SET_LTFOOT:
1987 tabular->SetLTFoot(ltt, false);
1989 case LyXTabular::UNSET_LTLASTFOOT:
1991 case LyXTabular::SET_LTLASTFOOT:
1992 tabular->SetLTFoot(ltt, true);
1994 case LyXTabular::SET_LTNEWPAGE:
1996 bool what = !tabular->GetLTNewPage(actcell);
1997 tabular->SetLTNewPage(actcell, what);
2000 // dummy stuff just to avoid warnings
2001 case LyXTabular::LAST_ACTION:
2007 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2010 UpdatableInset * inset =
2011 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2012 LyXFont font(LyXFont::ALL_SANE);
2014 x = inset->x() + inset->width(bv, font);
2015 y = inset->descent(bv, font);
2017 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2018 //inset_y = cursor.y();
2019 inset->edit(bv, x, y, button);
2020 if (!the_locking_inset)
2022 updateLocal(bv, CELL, false);
2023 return (the_locking_inset != 0);
2027 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2030 inset_x = cursor_.x()
2031 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2032 inset_y = cursor_.y();
2033 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2037 bool InsetTabular::insetHit(BufferView *, int x, int) const
2040 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2044 // This returns paperWidth() if the cell-width is unlimited or the width
2045 // in pixels if we have a pwidth for this cell.
2046 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2048 LyXLength const len = tabular->GetPWidth(cell);
2052 #ifdef WITH_WARNINGS
2053 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2055 return VSpace(len).inPixels(bv);
2059 int InsetTabular::getMaxWidth(BufferView * bv,
2060 UpdatableInset const * inset) const
2062 int cell = tabular->cur_cell;
2063 if (tabular->GetCellInset(cell) != inset) {
2065 if (tabular->GetCellInset(cell) != inset) {
2067 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2072 int const n = tabular->GetNumberOfCells();
2075 for (cell = 0; cell < n; ++cell) {
2076 if (tabular->GetCellInset(cell) == inset)
2082 lyxerr << "Own inset not found, shouldn't really happen!\n";
2086 int w = getMaxWidthOfCell(bv, cell);
2088 // because the inset then subtracts it's top_x and owner->x()
2089 w += (inset->x() - top_x);
2096 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2098 resizeLyXText(bv, recursive);
2102 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2105 for(int i = 0; i < tabular->rows(); ++i) {
2106 for(int j = 0; j < tabular->columns(); ++j) {
2107 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2115 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2116 bool const recursive) const
2118 if (the_locking_inset)
2119 return the_locking_inset->getLyXText(bv, recursive);
2121 // if we're locked lock the actual insettext and return it's LyXText!!!
2123 UpdatableInset * inset =
2124 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2125 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2126 return the_locking_inset->getLyXText(bv, recursive);
2129 return Inset::getLyXText(bv, recursive);
2133 bool InsetTabular::showInsetDialog(BufferView * bv) const
2135 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2136 bv->owner()->getDialogs()
2137 ->showTabular(const_cast<InsetTabular *>(this));
2142 void InsetTabular::openLayoutDialog(BufferView * bv) const
2144 if (the_locking_inset) {
2145 InsetTabular * i = static_cast<InsetTabular *>
2146 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2148 i->openLayoutDialog(bv);
2152 bv->owner()->getDialogs()->showTabular(
2153 const_cast<InsetTabular *>(this));
2158 // functions returns:
2162 // 3 ... toggled off
2164 func_status::value_type InsetTabular::getStatus(string const & what) const
2166 int action = LyXTabular::LAST_ACTION;
2167 func_status::value_type status = func_status::OK;
2170 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2171 string const tmp = tabularFeature[i].feature;
2172 if (tmp == what.substr(0, tmp.length())) {
2173 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2174 // tabularFeatures[i].feature.length())) {
2175 action = tabularFeature[i].action;
2179 if (action == LyXTabular::LAST_ACTION)
2180 return func_status::Unknown;
2182 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2187 LyXTabular::ltType dummyltt;
2190 if (hasSelection()) {
2191 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2193 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2197 case LyXTabular::SET_PWIDTH:
2198 case LyXTabular::SET_MPWIDTH:
2199 case LyXTabular::SET_SPECIAL_COLUMN:
2200 case LyXTabular::SET_SPECIAL_MULTI:
2201 status |= func_status::Disabled;
2204 case LyXTabular::APPEND_ROW:
2205 case LyXTabular::APPEND_COLUMN:
2206 case LyXTabular::DELETE_ROW:
2207 case LyXTabular::DELETE_COLUMN:
2208 case LyXTabular::SET_ALL_LINES:
2209 case LyXTabular::UNSET_ALL_LINES:
2210 status |= func_status::OK;
2213 case LyXTabular::MULTICOLUMN:
2214 if (tabular->IsMultiColumn(actcell))
2215 status |= func_status::ToggleOn;
2217 status |= func_status::ToggleOff;
2219 case LyXTabular::M_TOGGLE_LINE_TOP:
2221 case LyXTabular::TOGGLE_LINE_TOP:
2222 if (tabular->TopLine(actcell, flag))
2223 status |= func_status::ToggleOn;
2225 status |= func_status::ToggleOff;
2227 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2229 case LyXTabular::TOGGLE_LINE_BOTTOM:
2230 if (tabular->BottomLine(actcell, flag))
2231 status |= func_status::ToggleOn;
2233 status |= func_status::ToggleOff;
2235 case LyXTabular::M_TOGGLE_LINE_LEFT:
2237 case LyXTabular::TOGGLE_LINE_LEFT:
2238 if (tabular->LeftLine(actcell, flag))
2239 status |= func_status::ToggleOn;
2241 status |= func_status::ToggleOff;
2243 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2245 case LyXTabular::TOGGLE_LINE_RIGHT:
2246 if (tabular->RightLine(actcell, flag))
2247 status |= func_status::ToggleOn;
2249 status |= func_status::ToggleOff;
2251 case LyXTabular::M_ALIGN_LEFT:
2253 case LyXTabular::ALIGN_LEFT:
2254 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2255 status |= func_status::ToggleOn;
2257 status |= func_status::ToggleOff;
2259 case LyXTabular::M_ALIGN_RIGHT:
2261 case LyXTabular::ALIGN_RIGHT:
2262 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2263 status |= func_status::ToggleOn;
2265 status |= func_status::ToggleOff;
2267 case LyXTabular::M_ALIGN_CENTER:
2269 case LyXTabular::ALIGN_CENTER:
2270 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2271 status |= func_status::ToggleOn;
2273 status |= func_status::ToggleOff;
2275 case LyXTabular::M_VALIGN_TOP:
2277 case LyXTabular::VALIGN_TOP:
2278 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2279 status |= func_status::ToggleOn;
2281 status |= func_status::ToggleOff;
2283 case LyXTabular::M_VALIGN_BOTTOM:
2285 case LyXTabular::VALIGN_BOTTOM:
2286 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2287 status |= func_status::ToggleOn;
2289 status |= func_status::ToggleOff;
2291 case LyXTabular::M_VALIGN_CENTER:
2293 case LyXTabular::VALIGN_CENTER:
2294 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2295 status |= func_status::ToggleOn;
2297 status |= func_status::ToggleOff;
2299 case LyXTabular::SET_LONGTABULAR:
2300 if (tabular->IsLongTabular())
2301 status |= func_status::ToggleOn;
2303 status |= func_status::ToggleOff;
2305 case LyXTabular::UNSET_LONGTABULAR:
2306 if (!tabular->IsLongTabular())
2307 status |= func_status::ToggleOn;
2309 status |= func_status::ToggleOff;
2311 case LyXTabular::SET_ROTATE_TABULAR:
2312 if (tabular->GetRotateTabular())
2313 status |= func_status::ToggleOn;
2315 status |= func_status::ToggleOff;
2317 case LyXTabular::UNSET_ROTATE_TABULAR:
2318 if (!tabular->GetRotateTabular())
2319 status |= func_status::ToggleOn;
2321 status |= func_status::ToggleOff;
2323 case LyXTabular::SET_ROTATE_CELL:
2324 if (tabular->GetRotateCell(actcell))
2325 status |= func_status::ToggleOn;
2327 status |= func_status::ToggleOff;
2329 case LyXTabular::UNSET_ROTATE_CELL:
2330 if (!tabular->GetRotateCell(actcell))
2331 status |= func_status::ToggleOn;
2333 status |= func_status::ToggleOff;
2335 case LyXTabular::SET_USEBOX:
2336 if (strToInt(argument) == tabular->GetUsebox(actcell))
2337 status |= func_status::ToggleOn;
2339 status |= func_status::ToggleOff;
2341 case LyXTabular::SET_LTFIRSTHEAD:
2342 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2343 status |= func_status::ToggleOn;
2345 status |= func_status::ToggleOff;
2347 case LyXTabular::SET_LTHEAD:
2348 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2349 status |= func_status::ToggleOn;
2351 status |= func_status::ToggleOff;
2353 case LyXTabular::SET_LTFOOT:
2354 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2355 status |= func_status::ToggleOn;
2357 status |= func_status::ToggleOff;
2359 case LyXTabular::SET_LTLASTFOOT:
2360 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2361 status |= func_status::ToggleOn;
2363 status |= func_status::ToggleOff;
2365 case LyXTabular::SET_LTNEWPAGE:
2366 if (tabular->GetLTNewPage(actcell))
2367 status |= func_status::ToggleOn;
2369 status |= func_status::ToggleOff;
2372 status = func_status::Disabled;
2379 std::vector<string> const InsetTabular::getLabelList() const
2381 return tabular->getLabelList();
2385 bool InsetTabular::copySelection(BufferView * bv)
2387 if (!hasSelection())
2390 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2391 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2392 if (sel_col_start > sel_col_end) {
2393 sel_col_start = sel_col_end;
2394 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2396 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2398 int const columns = sel_col_end - sel_col_start + 1;
2400 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2401 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2402 if (sel_row_start > sel_row_end) {
2403 swap(sel_row_start, sel_row_end);
2405 int const rows = sel_row_end - sel_row_start + 1;
2407 delete paste_tabular;
2408 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2409 for (int i = 0; i < sel_row_start; ++i)
2410 paste_tabular->DeleteRow(0);
2411 while (paste_tabular->rows() > rows)
2412 paste_tabular->DeleteRow(rows);
2413 paste_tabular->SetTopLine(0, true, true);
2414 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2416 for (int i = 0; i < sel_col_start; ++i)
2417 paste_tabular->DeleteColumn(0);
2418 while (paste_tabular->columns() > columns)
2419 paste_tabular->DeleteColumn(columns);
2420 paste_tabular->SetLeftLine(0, true, true);
2421 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2425 paste_tabular->Ascii(bv->buffer(), sstr);
2426 bv->stuffClipboard(sstr.str().c_str());
2431 bool InsetTabular::pasteSelection(BufferView * bv)
2436 for (int r1 = 0, r2 = actrow;
2437 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2439 for(int c1 = 0, c2 = actcol;
2440 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2442 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2443 tabular->IsPartOfMultiColumn(r2,c2))
2445 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2449 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2453 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2454 int const n2 = tabular->GetCellNumber(r2, c2);
2455 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2456 tabular->GetCellInset(n2)->setOwner(this);
2457 tabular->GetCellInset(n2)->deleteLyXText(bv);
2464 bool InsetTabular::cutSelection()
2466 if (!hasSelection())
2469 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2470 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2471 if (sel_col_start > sel_col_end) {
2472 sel_col_start = sel_col_end;
2473 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2475 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2477 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2478 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2479 if (sel_row_start > sel_row_end) {
2480 swap(sel_row_start, sel_row_end);
2482 if (sel_cell_start > sel_cell_end) {
2483 swap(sel_cell_start, sel_cell_end);
2485 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2486 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2487 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2494 bool InsetTabular::isRightToLeft(BufferView *bv )
2496 return bv->getParentLanguage(this)->RightToLeft();
2500 bool InsetTabular::nodraw() const
2502 if (!UpdatableInset::nodraw() && the_locking_inset)
2503 return the_locking_inset->nodraw();
2504 return UpdatableInset::nodraw();
2508 int InsetTabular::scroll(bool recursive) const
2510 int sx = UpdatableInset::scroll(false);
2512 if (recursive && the_locking_inset)
2513 sx += the_locking_inset->scroll(recursive);
2519 bool InsetTabular::doClearArea() const
2521 return !locked || (need_update & (FULL|INIT));
2525 void InsetTabular::getSelection(int & srow, int & erow,
2526 int & scol, int & ecol) const
2528 int const start = hasSelection() ? sel_cell_start : actcell;
2529 int const end = hasSelection() ? sel_cell_end : actcell;
2531 srow = tabular->row_of_cell(start);
2532 erow = tabular->row_of_cell(end);
2537 scol = tabular->column_of_cell(start);
2538 ecol = tabular->column_of_cell(end);
2542 ecol = tabular->right_column_of_cell(end);
2547 Paragraph * InsetTabular::getParFromID(int id) const
2550 for(int i = 0; i < tabular->rows(); ++i) {
2551 for(int j = 0; j < tabular->columns(); ++j) {
2552 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2560 Paragraph * InsetTabular::firstParagraph() const
2562 if (the_locking_inset)
2563 return the_locking_inset->firstParagraph();
2568 Paragraph * InsetTabular::getFirstParagraph(int i) const
2570 return (i < tabular->GetNumberOfCells())
2571 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2576 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2578 if (the_locking_inset)
2579 return the_locking_inset->cursor(bv);
2580 return Inset::cursor(bv);
2584 Inset * InsetTabular::getInsetFromID(int id_arg) const
2587 return const_cast<InsetTabular *>(this);
2590 for(int i = 0; i < tabular->rows(); ++i) {
2591 for(int j = 0; j < tabular->columns(); ++j) {
2592 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2601 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2603 if (the_locking_inset) {
2604 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2607 if (tabular->IsLastCell(actcell)) {
2608 bv->unlockInset(const_cast<InsetTabular *>(this));
2614 // otherwise we have to lock the next inset and ask for it's selecttion
2615 UpdatableInset * inset =
2616 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2617 inset->edit(bv, 0, 0, 0);
2618 string const str(selectNextWordInt(bv, value));
2626 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2628 // when entering this function the inset should be ALWAYS locked!
2629 lyx::Assert(the_locking_inset);
2631 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2635 if (tabular->IsLastCell(actcell)) {
2636 bv->unlockInset(const_cast<InsetTabular *>(this));
2640 // otherwise we have to lock the next inset and ask for it's selecttion
2641 UpdatableInset * inset =
2642 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2644 return selectNextWordInt(bv, value);
2648 void InsetTabular::selectSelectedWord(BufferView * bv)
2650 if (the_locking_inset) {
2651 the_locking_inset->selectSelectedWord(bv);
2658 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2660 if (the_locking_inset) {
2661 the_locking_inset->toggleSelection(bv, kill_selection);
2666 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2667 bool const & cs, bool const & mw)
2669 if (the_locking_inset) {
2670 if (the_locking_inset->searchForward(bv, str, cs, mw))
2672 if (tabular->IsLastCell(actcell)) {
2673 bv->unlockInset(const_cast<InsetTabular *>(this));
2678 // otherwise we have to lock the next inset and search there
2679 UpdatableInset * inset =
2680 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2683 bool const res = searchForward(bv, str, cs, mw);
2684 updateLocal(bv, NONE, false);
2685 bv->updateInset(const_cast<InsetTabular *>(this), false);
2688 return searchForward(bv, str, cs, mw);
2693 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2694 bool const & cs, bool const & mw)
2696 if (the_locking_inset) {
2697 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2699 if (!actcell) { // we are already in the first cell
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));
2708 inset->edit(bv, false);
2710 bool const res = searchBackward(bv, str, cs, mw);
2711 bv->updateInset(const_cast<InsetTabular *>(this), false);
2714 return searchBackward(bv, str, cs, mw);
2719 bool InsetTabular::insetAllowed(Inset::Code code) const
2721 if (the_locking_inset)
2722 return the_locking_inset->insetAllowed(code);