1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
37 #include "frontends/Alert.h"
42 #include "BufferView.h"
43 #include "undo_funcs.h"
44 #include "support/LAssert.h"
45 #include "support/lstrings.h"
56 const int ADD_TO_HEIGHT = 2;
57 const int ADD_TO_TABULAR_WIDTH = 2;
59 LyXTabular * paste_tabular = 0;
62 struct TabularFeature {
63 LyXTabular::Feature action;
67 //tabular_features * tabularFeatures = 0;
69 TabularFeature tabularFeature[] =
71 { LyXTabular::APPEND_ROW, "append-row" },
72 { LyXTabular::APPEND_COLUMN, "append-column" },
73 { LyXTabular::DELETE_ROW, "delete-row" },
74 { LyXTabular::DELETE_COLUMN, "delete-column" },
75 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
76 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
77 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
78 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
79 { LyXTabular::ALIGN_LEFT, "align-left" },
80 { LyXTabular::ALIGN_RIGHT, "align-right" },
81 { LyXTabular::ALIGN_CENTER, "align-center" },
82 { LyXTabular::VALIGN_TOP, "valign-top" },
83 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
84 { LyXTabular::VALIGN_CENTER, "valign-center" },
85 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
86 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
87 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
88 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
89 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
90 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
91 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
92 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
93 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
94 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
95 { LyXTabular::MULTICOLUMN, "multicolumn" },
96 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
97 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
98 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
99 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
100 { LyXTabular::SET_PWIDTH, "set-pwidth" },
101 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
102 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
103 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
104 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
105 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
106 { LyXTabular::SET_USEBOX, "set-usebox" },
107 { LyXTabular::SET_LTHEAD, "set-lthead" },
108 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
109 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
110 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
111 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
112 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
113 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
114 { LyXTabular::LAST_ACTION, "" }
120 bool InsetTabular::hasPasteBuffer() const
122 return (paste_tabular != 0);
126 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
133 tabular.reset(new LyXTabular(this, rows, columns));
134 // for now make it always display as display() inset
136 the_locking_inset = 0;
139 actrow = actcell = 0;
143 in_reset_pos = false;
147 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
149 : UpdatableInset(tab, same_id), buffer(&buf)
151 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
152 the_locking_inset = 0;
155 actrow = actcell = 0;
159 in_reset_pos = false;
163 InsetTabular::~InsetTabular()
169 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
171 return new InsetTabular(*this, buf, same_id);
175 void InsetTabular::write(Buffer const * buf, ostream & os) const
177 os << " Tabular" << endl;
178 tabular->Write(buf, os);
182 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
184 bool const old_format = (lex.getString() == "\\LyXTable");
188 //tabular = new LyXTabular(buf, this, lex);
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);
463 if (rs > re) swap(rs, re);
465 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
466 int w = tabular->GetWidthOfColumn(cell);
467 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
468 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
469 w, h, LColor::selection);
474 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
480 owner()->update(bv, font, true);
487 if (calculate_dimensions_of_cells(bv, font, true))
490 owner()->update(bv, font, true);
494 if (the_locking_inset)
495 the_locking_inset->update(bv, font, reinit);
496 if (need_update < FULL &&
497 bv->text->status() == LyXText::NEED_MORE_REFRESH)
502 switch (need_update) {
506 if (calculate_dimensions_of_cells(bv, font, false))
519 string const InsetTabular::editMessage() const
521 return _("Opened Tabular Inset");
525 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
527 UpdatableInset::edit(bv, x, y, button);
529 if (!bv->lockInset(this)) {
530 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
534 the_locking_inset = 0;
540 if (insetHit(bv, x, y) && (button != 3)) {
541 activateCellInsetAbs(bv, x, y, button);
546 void InsetTabular::edit(BufferView * bv, bool front)
548 UpdatableInset::edit(bv, front);
550 if (!bv->lockInset(this)) {
551 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
555 the_locking_inset = 0;
561 actcell = tabular->GetNumberOfCells() - 1;
568 void InsetTabular::insetUnlock(BufferView * bv)
570 if (the_locking_inset) {
571 the_locking_inset->insetUnlock(bv);
572 the_locking_inset = 0;
577 if (scroll(false) || hasSelection()) {
582 updateLocal(bv, FULL, false);
587 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
588 bool mark_dirty) const
592 calculate_dimensions_of_cells(bv, font, true);
594 if (need_update < what) // only set this if it has greater update
596 if ((what == INIT) && hasSelection()) {
600 if (need_update != NONE) {
601 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
602 if (locked) // && (what != NONE))
608 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
610 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
615 if (inset == tabular->GetCellInset(actcell)) {
616 lyxerr[Debug::INSETTEXT] << "OK" << endl;
617 the_locking_inset = tabular->GetCellInset(actcell);
620 } else if (!the_locking_inset) {
621 int const n = tabular->GetNumberOfCells();
622 int const id = inset->id();
623 for (int i = 0; i < n; ++i) {
624 InsetText * in = tabular->GetCellInset(i);
627 the_locking_inset = in;
632 if (in->getInsetFromID(id)) {
634 the_locking_inset = in;
637 return the_locking_inset->lockInsetInInset(bv, inset);
640 } else if (the_locking_inset && (the_locking_inset == inset)) {
641 lyxerr[Debug::INSETTEXT] << "OK" << endl;
643 } else if (the_locking_inset) {
644 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
645 return the_locking_inset->lockInsetInInset(bv, inset);
647 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
652 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
655 if (!the_locking_inset)
657 if (the_locking_inset == inset) {
658 the_locking_inset->insetUnlock(bv);
659 the_locking_inset = 0;
661 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
667 updateLocal(bv, CELL, false);
668 showInsetCursor(bv, false);
671 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
672 if (inset->lyxCode() == TABULAR_CODE &&
673 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
674 bv->owner()->getDialogs()->updateTabular(this);
683 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
685 if (!the_locking_inset)
687 if (the_locking_inset != inset) {
688 if (!the_locking_inset->updateInsetInInset(bv, inset))
691 updateLocal(bv, CELL, false);
696 unsigned int InsetTabular::insetInInsetY()
698 if (!the_locking_inset)
701 return inset_y + the_locking_inset->insetInInsetY();
705 UpdatableInset * InsetTabular::getLockingInset() const
707 return the_locking_inset ? the_locking_inset->getLockingInset() :
708 const_cast<InsetTabular *>(this);
712 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
716 if (the_locking_inset)
717 return the_locking_inset->getFirstLockingInsetOfType(c);
722 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
724 if (the_locking_inset)
725 return the_locking_inset->insertInset(bv, inset);
730 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
732 if (hasSelection() && (button == 3))
735 if (hasSelection()) {
737 updateLocal(bv, SELECTION, false);
740 int const ocell = actcell;
741 int const orow = actrow;
746 updateLocal(bv, NONE, false);
750 if ((ocell != actcell) && the_locking_inset) {
751 the_locking_inset->insetUnlock(bv);
752 the_locking_inset = 0;
759 bool const inset_hit = insetHit(bv, x, y);
761 if ((ocell == actcell) && the_locking_inset && inset_hit) {
763 the_locking_inset->insetButtonPress(bv,
764 x - inset_x, y - inset_y,
767 } else if (the_locking_inset) {
768 the_locking_inset->insetUnlock(bv);
770 the_locking_inset = 0;
772 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
775 if (inset_hit && bv->theLockingInset()) {
776 if (activateCellInsetAbs(bv, x, y, button))
777 the_locking_inset->insetButtonPress(bv,
787 bool InsetTabular::insetButtonRelease(BufferView * bv,
788 int x, int y, int button)
791 if (the_locking_inset)
792 ret = the_locking_inset->insetButtonRelease(bv, x, y, button);
793 if (button == 3 && !ret) {
794 bv->owner()->getDialogs()->showTabular(this);
801 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
803 if (the_locking_inset) {
804 the_locking_inset->insetMotionNotify(bv,
812 // int const old_cell = actcell;
815 if (!hasSelection()) {
816 setSelection(actcell, actcell);
818 setSelection(sel_cell_start, actcell);
820 updateLocal(bv, SELECTION, false);
825 void InsetTabular::insetKeyPress(XKeyEvent * xke)
827 if (the_locking_inset) {
828 the_locking_inset->insetKeyPress(xke);
834 UpdatableInset::RESULT
835 InsetTabular::localDispatch(BufferView * bv, kb_action action,
838 // We need to save the value of the_locking_inset as the call to
839 // the_locking_inset->LocalDispatch might unlock it.
840 old_locking_inset = the_locking_inset;
841 UpdatableInset::RESULT result =
842 UpdatableInset::localDispatch(bv, action, arg);
843 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
848 if ((action < 0) && arg.empty())
851 bool hs = hasSelection();
854 // this one have priority over the locked InsetText, if we're not already
855 // inside another tabular then that one get's priority!
856 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
861 unlockInsetInInset(bv, the_locking_inset);
862 if (action == LFUN_TAB)
863 moveNextCell(bv, old_locking_inset != 0);
865 movePrevCell(bv, old_locking_inset != 0);
868 updateLocal(bv, SELECTION, false);
869 if (!the_locking_inset) {
871 return DISPATCHED_NOUPDATE;
874 // this to avoid compiler warnings.
880 if (the_locking_inset) {
881 result = the_locking_inset->localDispatch(bv, action, arg);
882 if (result == DISPATCHED_NOUPDATE) {
885 if (sc != scroll()) { // inset has been scrolled
886 the_locking_inset->toggleInsetCursor(bv);
887 updateLocal(bv, FULL, false);
888 the_locking_inset->toggleInsetCursor(bv);
891 } else if (result == DISPATCHED) {
892 the_locking_inset->toggleInsetCursor(bv);
893 updateLocal(bv, CELL, false);
894 the_locking_inset->toggleInsetCursor(bv);
896 } else if (result == FINISHED_UP) {
898 } else if (result == FINISHED_DOWN) {
900 } else if (result == FINISHED_RIGHT) {
908 // --- Cursor Movements ----------------------------------
909 case LFUN_RIGHTSEL: {
910 int const start = hasSelection() ? sel_cell_start : actcell;
911 if (tabular->IsLastCellInRow(actcell)) {
912 setSelection(start, actcell);
917 // if we are starting a selection, only select
918 // the current cell at the beginning
919 if (hasSelection()) {
920 moveRight(bv, false);
923 setSelection(start, end);
924 updateLocal(bv, SELECTION, false);
928 result = moveRight(bv);
931 updateLocal(bv, SELECTION, false);
934 int const start = hasSelection() ? sel_cell_start : actcell;
935 if (tabular->IsFirstCellInRow(actcell)) {
936 setSelection(start, actcell);
941 // if we are starting a selection, only select
942 // the current cell at the beginning
943 if (hasSelection()) {
947 setSelection(start, end);
948 updateLocal(bv, SELECTION, false);
952 result = moveLeft(bv);
955 updateLocal(bv, SELECTION, false);
958 int const start = hasSelection() ? sel_cell_start : actcell;
959 int const ocell = actcell;
960 // if we are starting a selection, only select
961 // the current cell at the beginning
962 if (hasSelection()) {
965 if ((ocell == sel_cell_end) ||
966 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
967 setSelection(start, tabular->GetCellBelow(sel_cell_end));
969 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
970 updateLocal(bv, SELECTION, false);
974 result = moveDown(bv, old_locking_inset != 0);
977 updateLocal(bv, SELECTION, false);
981 int const start = hasSelection() ? sel_cell_start : actcell;
982 int const ocell = actcell;
983 // if we are starting a selection, only select
984 // the current cell at the beginning
985 if (hasSelection()) {
988 if ((ocell == sel_cell_end) ||
989 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
990 setSelection(start, tabular->GetCellAbove(sel_cell_end));
992 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
993 updateLocal(bv, SELECTION, false);
997 result = moveUp(bv, old_locking_inset != 0);
1000 updateLocal(bv, SELECTION, false);
1003 int column = actcol;
1004 unlockInsetInInset(bv, the_locking_inset);
1005 if (bv->text->first + bv->painter().paperHeight() <
1006 (top_baseline + tabular->GetHeightOfTabular()))
1008 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1009 updateLocal(bv, FULL, false);
1010 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1012 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1015 updateLocal(bv, CURSOR, false);
1019 int column = actcol;
1020 unlockInsetInInset(bv, the_locking_inset);
1021 if (top_baseline < 0) {
1022 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1023 updateLocal(bv, FULL, false);
1024 if (top_baseline > 0)
1027 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1032 updateLocal(bv, CURSOR, false);
1035 // none of these make sense for insettabular,
1036 // but we must catch them to prevent any
1037 // selection from being confused
1041 case LFUN_WORDLEFTSEL:
1042 case LFUN_WORDRIGHT:
1043 case LFUN_WORDRIGHTSEL:
1044 case LFUN_DOWN_PARAGRAPH:
1045 case LFUN_DOWN_PARAGRAPHSEL:
1046 case LFUN_UP_PARAGRAPH:
1047 case LFUN_UP_PARAGRAPHSEL:
1048 case LFUN_BACKSPACE:
1055 case LFUN_LAYOUT_TABULAR:
1057 bv->owner()->getDialogs()->showTabular(this);
1060 case LFUN_TABULAR_FEATURE:
1061 if (!tabularFeatures(bv, arg))
1062 result = UNDISPATCHED;
1065 if (!copySelection(bv))
1067 setUndo(bv, Undo::DELETE,
1068 bv->text->cursor.par(),
1069 bv->text->cursor.par()->next());
1071 updateLocal(bv, INIT, true);
1074 if (!hasSelection())
1079 case LFUN_PASTESELECTION:
1081 string const clip(bv->getClipboard());
1085 if (clip.find('\t') != string::npos) {
1089 string::size_type len = clip.length();
1090 string::size_type p = 0;
1093 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1101 maxCols = max(cols, maxCols);
1107 maxCols = max(cols, maxCols);
1108 delete paste_tabular;
1109 paste_tabular = new LyXTabular(this, rows, maxCols);
1110 string::size_type op = 0;
1112 int cells = paste_tabular->GetNumberOfCells();
1114 while ((cell < cells) && (p < len) &&
1115 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1120 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1125 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1126 while (cols++ < maxCols)
1134 // check for the last cell if there is no trailing '\n'
1135 if ((cell < cells) && (op < len))
1136 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1138 // so that the clipboard is used and it goes on
1140 // and executes LFUN_PASTESELECTION in insettext!
1141 delete paste_tabular;
1146 if (hasPasteBuffer()) {
1147 setUndo(bv, Undo::INSERT,
1148 bv->text->cursor.par(),
1149 bv->text->cursor.par()->next());
1151 updateLocal(bv, INIT, true);
1154 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1156 // we try to activate the actual inset and put this event down to
1157 // the insets dispatch function.
1158 result = UNDISPATCHED;
1159 if (the_locking_inset)
1162 if (activateCellInset(bv)) {
1163 // reset need_update setted in above function!
1165 result = the_locking_inset->localDispatch(bv, action, arg);
1166 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1167 unlockInsetInInset(bv, the_locking_inset);
1169 // we need to update if this was requested before
1170 updateLocal(bv, NONE, false);
1171 return UNDISPATCHED;
1176 updateLocal(bv, CELL, false);
1181 if (result < FINISHED) {
1182 if (!the_locking_inset) {
1183 showInsetCursor(bv);
1186 bv->unlockInset(this);
1191 int InsetTabular::latex(Buffer const * buf, ostream & os,
1192 bool fragile, bool fp) const
1194 return tabular->Latex(buf, os, fragile, fp);
1198 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1200 // This should be changed to a real ascii export
1201 return tabular->Ascii(buf, os);
1205 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1207 return tabular->Ascii(buf,os);
1211 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1216 // if the table is inside a float it doesn't need the informaltable
1217 // wrapper. Search for it.
1218 for(master = owner();
1219 master && master->lyxCode() != Inset::FLOAT_CODE;
1220 master = master->owner());
1223 os << "<informaltable>\n";
1226 ret+= tabular->DocBook(buf,os);
1228 os << "</informaltable>\n";
1235 void InsetTabular::validate(LaTeXFeatures & features) const
1237 tabular->Validate(features);
1241 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1242 LyXFont const & font,
1249 bool changed = false;
1251 // if we have a locking_inset we should have to check only this cell for
1252 // change so I'll try this to have a boost, but who knows ;)
1253 if ((need_update != INIT) &&
1254 (the_locking_inset == tabular->GetCellInset(actcell))) {
1255 for(int i = 0; i < tabular->columns(); ++i) {
1256 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1258 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1261 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1262 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1263 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1266 for (int i = 0; i < tabular->rows(); ++i) {
1269 for (int j = 0; j < tabular->columns(); ++j) {
1270 if (tabular->IsPartOfMultiColumn(i,j))
1273 inset = tabular->GetCellInset(cell);
1274 if (!reinit && !tabular->GetPWidth(cell).zero())
1275 inset->update(bv, font, false);
1276 maxAsc = max(maxAsc, inset->ascent(bv, font));
1277 maxDesc = max(maxDesc, inset->descent(bv, font));
1278 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1280 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1281 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1289 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1291 if (the_locking_inset) {
1292 the_locking_inset->getCursorPos(bv, x, y);
1295 x = cursor_.x() - top_x;
1300 void InsetTabular::toggleInsetCursor(BufferView * bv)
1302 if (the_locking_inset) {
1303 the_locking_inset->toggleInsetCursor(bv);
1307 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1309 int const asc = lyxfont::maxAscent(font);
1310 int const desc = lyxfont::maxDescent(font);
1312 if (isCursorVisible())
1313 bv->hideLockedInsetCursor();
1315 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1316 toggleCursorVisible();
1320 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1322 if (!isCursorVisible()) {
1323 LyXFont font; // = GetFont(par, cursor.pos);
1325 int const asc = lyxfont::maxAscent(font);
1326 int const desc = lyxfont::maxDescent(font);
1327 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1329 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1330 setCursorVisible(true);
1335 void InsetTabular::hideInsetCursor(BufferView * bv)
1337 if (isCursorVisible()) {
1338 bv->hideLockedInsetCursor();
1339 setCursorVisible(false);
1344 void InsetTabular::fitInsetCursor(BufferView * bv) const
1346 if (the_locking_inset) {
1347 the_locking_inset->fitInsetCursor(bv);
1352 int const asc = lyxfont::maxAscent(font);
1353 int const desc = lyxfont::maxDescent(font);
1354 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1358 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1362 actcell = actrow = actcol = 0;
1363 int ly = tabular->GetDescentOfRow(actrow);
1365 // first search the right row
1366 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1367 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1368 tabular->GetAscentOfRow(actrow + 1) +
1369 tabular->GetAdditionalHeight(actrow + 1));
1371 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1373 actcell = tabular->GetCellNumber(actrow, actcol);
1375 // now search the right column
1376 int lx = tabular->GetWidthOfColumn(actcell) -
1377 tabular->GetAdditionalWidth(actcell);
1378 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1379 lx += tabular->GetWidthOfColumn(actcell + 1)
1380 + tabular->GetAdditionalWidth(actcell);
1382 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1387 int InsetTabular::getCellXPos(int cell) const
1391 for (; !tabular->IsFirstCellInRow(c); --c)
1393 int lx = tabular->GetWidthOfColumn(cell);
1394 for (; c < cell; ++c) {
1395 lx += tabular->GetWidthOfColumn(c);
1397 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1401 void InsetTabular::resetPos(BufferView * bv) const
1403 if (!locked || nodraw())
1405 #warning This should be fixed in the right manner (20011128 Jug)
1406 // fast hack to fix infinite repaintings!
1409 in_reset_pos = true;
1411 actcol = tabular->column_of_cell(actcell);
1416 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1417 if (tabular->IsLastCellInRow(cell)) {
1418 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1419 tabular->GetAscentOfRow(actrow + 1) +
1420 tabular->GetAdditionalHeight(actrow + 1));
1424 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1425 int new_x = getCellXPos(actcell);
1426 int old_x = cursor_.x();
1429 // cursor.x(getCellXPos(actcell) + offset);
1430 if ((actcol < tabular->columns()-1) && scroll(false) &&
1431 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1434 updateLocal(bv, FULL, false);
1435 } else if (the_locking_inset &&
1436 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1438 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1439 if (xx > (bv->workWidth()-20)) {
1440 scroll(bv, -(xx - bv->workWidth() + 60));
1441 updateLocal(bv, FULL, false);
1442 } else if (xx < 20) {
1448 updateLocal(bv, FULL, false);
1450 } else if ((cursor_.x() - offset) > 20 &&
1451 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1452 > (bv->workWidth() - 20)) {
1453 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1454 updateLocal(bv, FULL, false);
1455 } else if ((cursor_.x() - offset) < 20) {
1456 scroll(bv, 20 - cursor_.x() + offset);
1457 updateLocal(bv, FULL, false);
1458 } else if (scroll(false) && top_x > 20 &&
1459 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1460 scroll(bv, old_x - cursor_.x());
1461 updateLocal(bv, FULL, false);
1463 if (the_locking_inset) {
1464 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1465 inset_y = cursor_.y();
1467 if ((!the_locking_inset ||
1468 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1469 actcell != oldcell) {
1470 InsetTabular * inset = const_cast<InsetTabular *>(this);
1471 bv->owner()->getDialogs()->updateTabular(inset);
1474 in_reset_pos = false;
1478 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1480 if (lock && !old_locking_inset) {
1481 if (activateCellInset(bv))
1484 bool moved = isRightToLeft(bv)
1485 ? movePrevCell(bv) : moveNextCell(bv);
1487 return FINISHED_RIGHT;
1488 if (lock && activateCellInset(bv))
1492 return DISPATCHED_NOUPDATE;
1496 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1498 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1501 if (lock) { // behind the inset
1502 if (activateCellInset(bv, 0, 0, 0, true))
1506 return DISPATCHED_NOUPDATE;
1510 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1512 int const ocell = actcell;
1513 actcell = tabular->GetCellAbove(actcell);
1514 if (actcell == ocell) // we moved out of the inset
1520 if (old_locking_inset) {
1521 old_locking_inset->getCursorPos(bv, x, y);
1522 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1524 if (activateCellInset(bv, x, 0))
1527 return DISPATCHED_NOUPDATE;
1531 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1533 int const ocell = actcell;
1534 actcell = tabular->GetCellBelow(actcell);
1535 if (actcell == ocell) // we moved out of the inset
1536 return FINISHED_DOWN;
1541 if (old_locking_inset) {
1542 old_locking_inset->getCursorPos(bv, x, y);
1543 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1545 if (activateCellInset(bv, x, 0))
1548 return DISPATCHED_NOUPDATE;
1552 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1554 if (isRightToLeft(bv)) {
1555 if (tabular->IsFirstCellInRow(actcell)) {
1556 int row = tabular->row_of_cell(actcell);
1557 if (row == tabular->rows() - 1)
1559 actcell = tabular->GetLastCellInRow(row);
1560 actcell = tabular->GetCellBelow(actcell);
1567 if (tabular->IsLastCell(actcell))
1572 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1573 isRightToLeftPar(bv->buffer()->params);
1574 activateCellInset(bv, 0, 0, 0, !rtl);
1581 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1583 if (isRightToLeft(bv)) {
1584 if (tabular->IsLastCellInRow(actcell)) {
1585 int row = tabular->row_of_cell(actcell);
1588 actcell = tabular->GetFirstCellInRow(row);
1589 actcell = tabular->GetCellAbove(actcell);
1591 if (tabular->IsLastCell(actcell))
1596 if (!actcell) // first cell
1601 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1602 isRightToLeftPar(bv->buffer()->params);
1603 activateCellInset(bv, 0, 0, 0, !rtl);
1610 bool InsetTabular::deletable() const
1616 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1620 setSelection(0, tabular->GetNumberOfCells() - 1);
1622 if (hasSelection()) {
1623 setUndo(bv, Undo::EDIT,
1624 bv->text->cursor.par(),
1625 bv->text->cursor.par()->next());
1626 bool frozen = undo_frozen;
1629 // apply the fontchange on the whole selection
1634 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1635 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1636 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1637 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1642 updateLocal(bv, INIT, true);
1644 if (the_locking_inset)
1645 the_locking_inset->setFont(bv, font, tall);
1649 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1651 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1654 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1655 string const tmp = tabularFeature[i].feature;
1657 if (tmp == what.substr(0, tmp.length())) {
1658 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1659 //tabularFeatures[i].feature.length())) {
1660 action = tabularFeature[i].action;
1664 if (action == LyXTabular::LAST_ACTION)
1668 frontStrip(what.substr(tabularFeature[i].feature.length()));
1669 tabularFeatures(bv, action, val);
1674 void InsetTabular::tabularFeatures(BufferView * bv,
1675 LyXTabular::Feature feature,
1676 string const & value)
1682 bool setLines = false;
1683 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1684 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1687 case LyXTabular::M_ALIGN_LEFT:
1688 case LyXTabular::ALIGN_LEFT:
1689 setAlign = LYX_ALIGN_LEFT;
1691 case LyXTabular::M_ALIGN_RIGHT:
1692 case LyXTabular::ALIGN_RIGHT:
1693 setAlign = LYX_ALIGN_RIGHT;
1695 case LyXTabular::M_ALIGN_CENTER:
1696 case LyXTabular::ALIGN_CENTER:
1697 setAlign = LYX_ALIGN_CENTER;
1699 case LyXTabular::M_VALIGN_TOP:
1700 case LyXTabular::VALIGN_TOP:
1701 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1703 case LyXTabular::M_VALIGN_BOTTOM:
1704 case LyXTabular::VALIGN_BOTTOM:
1705 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1707 case LyXTabular::M_VALIGN_CENTER:
1708 case LyXTabular::VALIGN_CENTER:
1709 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1714 if (hasSelection()) {
1715 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1717 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1718 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1720 setUndo(bv, Undo::FINISH,
1721 bv->text->cursor.par(),
1722 bv->text->cursor.par()->next());
1724 LyXTabular::ltType ltt;
1725 int row = ltt.row = tabular->row_of_cell(actcell);
1726 int column = tabular->column_of_cell(actcell);
1730 case LyXTabular::SET_PWIDTH:
1732 LyXLength const vallen = LyXLength(value);
1733 bool const update = (tabular->GetColumnPWidth(actcell) != vallen);
1734 tabular->SetColumnPWidth(actcell,vallen);
1736 for (int i = 0; i < tabular->rows(); ++i) {
1737 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1740 updateLocal(bv, INIT, true);
1744 case LyXTabular::SET_MPWIDTH:
1746 LyXLength const vallen = LyXLength(value);
1747 bool const update = (tabular->GetPWidth(actcell) != vallen);
1748 tabular->SetMColumnPWidth(actcell,vallen);
1750 for (int i = 0; i < tabular->rows(); ++i) {
1751 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1754 updateLocal(bv, INIT, true);
1758 case LyXTabular::SET_SPECIAL_COLUMN:
1759 case LyXTabular::SET_SPECIAL_MULTI:
1760 tabular->SetAlignSpecial(actcell,value,feature);
1761 updateLocal(bv, FULL, true);
1763 case LyXTabular::APPEND_ROW:
1764 // append the row into the tabular
1765 unlockInsetInInset(bv, the_locking_inset);
1766 tabular->AppendRow(actcell);
1767 updateLocal(bv, INIT, true);
1769 case LyXTabular::APPEND_COLUMN:
1770 // append the column into the tabular
1771 unlockInsetInInset(bv, the_locking_inset);
1772 tabular->AppendColumn(actcell);
1773 actcell = tabular->GetCellNumber(row, column);
1774 updateLocal(bv, INIT, true);
1776 case LyXTabular::DELETE_ROW:
1777 unlockInsetInInset(bv, the_locking_inset);
1778 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1779 tabular->DeleteRow(sel_row_start);
1781 if (sel_row_start >= tabular->rows())
1783 actcell = tabular->GetCellNumber(sel_row_start, column);
1785 updateLocal(bv, INIT, true);
1787 case LyXTabular::DELETE_COLUMN:
1788 unlockInsetInInset(bv, the_locking_inset);
1789 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1790 tabular->DeleteColumn(sel_col_start);
1792 if (sel_col_start >= tabular->columns())
1794 actcell = tabular->GetCellNumber(row, sel_col_start);
1796 updateLocal(bv, INIT, true);
1798 case LyXTabular::M_TOGGLE_LINE_TOP:
1800 case LyXTabular::TOGGLE_LINE_TOP:
1802 bool lineSet = !tabular->TopLine(actcell, flag);
1803 for (int i = sel_row_start; i <= sel_row_end; ++i)
1804 for (int j = sel_col_start; j <= sel_col_end; ++j)
1805 tabular->SetTopLine(
1806 tabular->GetCellNumber(i, j),
1808 updateLocal(bv, INIT, true);
1812 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1814 case LyXTabular::TOGGLE_LINE_BOTTOM:
1816 bool lineSet = !tabular->BottomLine(actcell, flag);
1817 for (int i = sel_row_start; i <= sel_row_end; ++i)
1818 for (int j = sel_col_start; j <= sel_col_end; ++j)
1819 tabular->SetBottomLine(
1820 tabular->GetCellNumber(i, j),
1823 updateLocal(bv, INIT, true);
1827 case LyXTabular::M_TOGGLE_LINE_LEFT:
1829 case LyXTabular::TOGGLE_LINE_LEFT:
1831 bool lineSet = !tabular->LeftLine(actcell, flag);
1832 for (int i = sel_row_start; i <= sel_row_end; ++i)
1833 for (int j = sel_col_start; j <= sel_col_end; ++j)
1834 tabular->SetLeftLine(
1835 tabular->GetCellNumber(i,j),
1838 updateLocal(bv, INIT, true);
1842 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1844 case LyXTabular::TOGGLE_LINE_RIGHT:
1846 bool lineSet = !tabular->RightLine(actcell, flag);
1847 for (int i = sel_row_start; i <= sel_row_end; ++i)
1848 for (int j = sel_col_start; j <= sel_col_end; ++j)
1849 tabular->SetRightLine(
1850 tabular->GetCellNumber(i,j),
1853 updateLocal(bv, INIT, true);
1857 case LyXTabular::M_ALIGN_LEFT:
1858 case LyXTabular::M_ALIGN_RIGHT:
1859 case LyXTabular::M_ALIGN_CENTER:
1861 case LyXTabular::ALIGN_LEFT:
1862 case LyXTabular::ALIGN_RIGHT:
1863 case LyXTabular::ALIGN_CENTER:
1864 for (int i = sel_row_start; i <= sel_row_end; ++i)
1865 for (int j = sel_col_start; j <= sel_col_end; ++j)
1866 tabular->SetAlignment(
1867 tabular->GetCellNumber(i, j),
1870 updateLocal(bv, INIT, true);
1872 case LyXTabular::M_VALIGN_TOP:
1873 case LyXTabular::M_VALIGN_BOTTOM:
1874 case LyXTabular::M_VALIGN_CENTER:
1876 case LyXTabular::VALIGN_TOP:
1877 case LyXTabular::VALIGN_BOTTOM:
1878 case LyXTabular::VALIGN_CENTER:
1879 for (int i = sel_row_start; i <= sel_row_end; ++i)
1880 for (int j = sel_col_start; j <= sel_col_end; ++j)
1881 tabular->SetVAlignment(
1882 tabular->GetCellNumber(i, j),
1884 updateLocal(bv, INIT, true);
1886 case LyXTabular::MULTICOLUMN:
1888 if (sel_row_start != sel_row_end) {
1889 Alert::alert(_("Impossible Operation!"),
1890 _("Multicolumns can only be horizontally."),
1894 // just multicol for one Single Cell
1895 if (!hasSelection()) {
1896 // check wether we are completly in a multicol
1897 if (tabular->IsMultiColumn(actcell)) {
1898 tabular->UnsetMultiColumn(actcell);
1899 updateLocal(bv, INIT, true);
1901 tabular->SetMultiColumn(actcell, 1);
1902 updateLocal(bv, CELL, true);
1906 // we have a selection so this means we just add all this
1907 // cells to form a multicolumn cell
1911 if (sel_cell_start > sel_cell_end) {
1912 s_start = sel_cell_end;
1913 s_end = sel_cell_start;
1915 s_start = sel_cell_start;
1916 s_end = sel_cell_end;
1918 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1921 updateLocal(bv, INIT, true);
1924 case LyXTabular::SET_ALL_LINES:
1926 case LyXTabular::UNSET_ALL_LINES:
1927 for (int i = sel_row_start; i <= sel_row_end; ++i)
1928 for (int j = sel_col_start; j <= sel_col_end; ++j)
1929 tabular->SetAllLines(
1930 tabular->GetCellNumber(i,j), setLines);
1931 updateLocal(bv, INIT, true);
1933 case LyXTabular::SET_LONGTABULAR:
1934 tabular->SetLongTabular(true);
1935 updateLocal(bv, INIT, true); // because this toggles displayed
1937 case LyXTabular::UNSET_LONGTABULAR:
1938 tabular->SetLongTabular(false);
1939 updateLocal(bv, INIT, true); // because this toggles displayed
1941 case LyXTabular::SET_ROTATE_TABULAR:
1942 tabular->SetRotateTabular(true);
1944 case LyXTabular::UNSET_ROTATE_TABULAR:
1945 tabular->SetRotateTabular(false);
1947 case LyXTabular::SET_ROTATE_CELL:
1948 for (int i = sel_row_start; i <= sel_row_end; ++i)
1949 for (int j = sel_col_start; j<=sel_col_end; ++j)
1950 tabular->SetRotateCell(
1951 tabular->GetCellNumber(i, j),
1954 case LyXTabular::UNSET_ROTATE_CELL:
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j <= sel_col_end; ++j)
1957 tabular->SetRotateCell(
1958 tabular->GetCellNumber(i, j), false);
1960 case LyXTabular::SET_USEBOX:
1962 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1963 if (val == tabular->GetUsebox(actcell))
1964 val = LyXTabular::BOX_NONE;
1965 for (int i = sel_row_start; i <= sel_row_end; ++i)
1966 for (int j = sel_col_start; j <= sel_col_end; ++j)
1968 tabular->GetCellNumber(i, j), val);
1971 case LyXTabular::UNSET_LTFIRSTHEAD:
1973 case LyXTabular::SET_LTFIRSTHEAD:
1974 tabular->SetLTHead(ltt, true);
1976 case LyXTabular::UNSET_LTHEAD:
1978 case LyXTabular::SET_LTHEAD:
1979 tabular->SetLTHead(ltt, false);
1981 case LyXTabular::UNSET_LTFOOT:
1983 case LyXTabular::SET_LTFOOT:
1984 tabular->SetLTFoot(ltt, false);
1986 case LyXTabular::UNSET_LTLASTFOOT:
1988 case LyXTabular::SET_LTLASTFOOT:
1989 tabular->SetLTFoot(ltt, true);
1991 case LyXTabular::SET_LTNEWPAGE:
1993 bool what = !tabular->GetLTNewPage(actcell);
1994 tabular->SetLTNewPage(actcell, what);
1997 // dummy stuff just to avoid warnings
1998 case LyXTabular::LAST_ACTION:
2004 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2007 UpdatableInset * inset =
2008 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2009 LyXFont font(LyXFont::ALL_SANE);
2011 x = inset->x() + inset->width(bv, font);
2012 y = inset->descent(bv, font);
2014 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2015 //inset_y = cursor.y();
2016 inset->edit(bv, x, y, button);
2017 if (!the_locking_inset)
2019 updateLocal(bv, CELL, false);
2020 return (the_locking_inset != 0);
2024 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2027 inset_x = cursor_.x()
2028 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2029 inset_y = cursor_.y();
2030 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2034 bool InsetTabular::insetHit(BufferView *, int x, int) const
2037 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2041 // This returns paperWidth() if the cell-width is unlimited or the width
2042 // in pixels if we have a pwidth for this cell.
2043 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2045 LyXLength const len = tabular->GetPWidth(cell);
2049 #ifdef WITH_WARNINGS
2050 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2052 return VSpace(len).inPixels(bv);
2056 int InsetTabular::getMaxWidth(BufferView * bv,
2057 UpdatableInset const * inset) const
2059 int cell = tabular->cur_cell;
2060 if (tabular->GetCellInset(cell) != inset) {
2062 if (tabular->GetCellInset(cell) != inset) {
2064 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2069 int const n = tabular->GetNumberOfCells();
2072 for (cell = 0; cell < n; ++cell) {
2073 if (tabular->GetCellInset(cell) == inset)
2079 lyxerr << "Own inset not found, shouldn't really happen!\n";
2083 int w = getMaxWidthOfCell(bv, cell);
2085 // because the inset then subtracts it's top_x and owner->x()
2086 w += (inset->x() - top_x);
2093 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2095 resizeLyXText(bv, recursive);
2099 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2102 for(int i = 0; i < tabular->rows(); ++i) {
2103 for(int j = 0; j < tabular->columns(); ++j) {
2104 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2112 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2113 bool const recursive) const
2115 if (the_locking_inset)
2116 return the_locking_inset->getLyXText(bv, recursive);
2118 // if we're locked lock the actual insettext and return it's LyXText!!!
2120 UpdatableInset * inset =
2121 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2122 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2123 return the_locking_inset->getLyXText(bv, recursive);
2126 return Inset::getLyXText(bv, recursive);
2130 bool InsetTabular::showInsetDialog(BufferView * bv) const
2132 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2133 bv->owner()->getDialogs()
2134 ->showTabular(const_cast<InsetTabular *>(this));
2139 void InsetTabular::openLayoutDialog(BufferView * bv) const
2141 if (the_locking_inset) {
2142 InsetTabular * i = static_cast<InsetTabular *>
2143 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2145 i->openLayoutDialog(bv);
2149 bv->owner()->getDialogs()->showTabular(
2150 const_cast<InsetTabular *>(this));
2155 // functions returns:
2159 // 3 ... toggled off
2161 func_status::value_type InsetTabular::getStatus(string const & what) const
2163 int action = LyXTabular::LAST_ACTION;
2164 func_status::value_type status = func_status::OK;
2167 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2168 string const tmp = tabularFeature[i].feature;
2169 if (tmp == what.substr(0, tmp.length())) {
2170 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2171 // tabularFeatures[i].feature.length())) {
2172 action = tabularFeature[i].action;
2176 if (action == LyXTabular::LAST_ACTION)
2177 return func_status::Unknown;
2179 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2184 LyXTabular::ltType dummyltt;
2187 if (hasSelection()) {
2188 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2190 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2194 case LyXTabular::SET_PWIDTH:
2195 case LyXTabular::SET_MPWIDTH:
2196 case LyXTabular::SET_SPECIAL_COLUMN:
2197 case LyXTabular::SET_SPECIAL_MULTI:
2198 status |= func_status::Disabled;
2201 case LyXTabular::APPEND_ROW:
2202 case LyXTabular::APPEND_COLUMN:
2203 case LyXTabular::DELETE_ROW:
2204 case LyXTabular::DELETE_COLUMN:
2205 case LyXTabular::SET_ALL_LINES:
2206 case LyXTabular::UNSET_ALL_LINES:
2207 status |= func_status::OK;
2210 case LyXTabular::MULTICOLUMN:
2211 if (tabular->IsMultiColumn(actcell))
2212 status |= func_status::ToggleOn;
2214 status |= func_status::ToggleOff;
2216 case LyXTabular::M_TOGGLE_LINE_TOP:
2218 case LyXTabular::TOGGLE_LINE_TOP:
2219 if (tabular->TopLine(actcell, flag))
2220 status |= func_status::ToggleOn;
2222 status |= func_status::ToggleOff;
2224 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2226 case LyXTabular::TOGGLE_LINE_BOTTOM:
2227 if (tabular->BottomLine(actcell, flag))
2228 status |= func_status::ToggleOn;
2230 status |= func_status::ToggleOff;
2232 case LyXTabular::M_TOGGLE_LINE_LEFT:
2234 case LyXTabular::TOGGLE_LINE_LEFT:
2235 if (tabular->LeftLine(actcell, flag))
2236 status |= func_status::ToggleOn;
2238 status |= func_status::ToggleOff;
2240 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2242 case LyXTabular::TOGGLE_LINE_RIGHT:
2243 if (tabular->RightLine(actcell, flag))
2244 status |= func_status::ToggleOn;
2246 status |= func_status::ToggleOff;
2248 case LyXTabular::M_ALIGN_LEFT:
2250 case LyXTabular::ALIGN_LEFT:
2251 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2252 status |= func_status::ToggleOn;
2254 status |= func_status::ToggleOff;
2256 case LyXTabular::M_ALIGN_RIGHT:
2258 case LyXTabular::ALIGN_RIGHT:
2259 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2260 status |= func_status::ToggleOn;
2262 status |= func_status::ToggleOff;
2264 case LyXTabular::M_ALIGN_CENTER:
2266 case LyXTabular::ALIGN_CENTER:
2267 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2268 status |= func_status::ToggleOn;
2270 status |= func_status::ToggleOff;
2272 case LyXTabular::M_VALIGN_TOP:
2274 case LyXTabular::VALIGN_TOP:
2275 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2276 status |= func_status::ToggleOn;
2278 status |= func_status::ToggleOff;
2280 case LyXTabular::M_VALIGN_BOTTOM:
2282 case LyXTabular::VALIGN_BOTTOM:
2283 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2284 status |= func_status::ToggleOn;
2286 status |= func_status::ToggleOff;
2288 case LyXTabular::M_VALIGN_CENTER:
2290 case LyXTabular::VALIGN_CENTER:
2291 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2292 status |= func_status::ToggleOn;
2294 status |= func_status::ToggleOff;
2296 case LyXTabular::SET_LONGTABULAR:
2297 if (tabular->IsLongTabular())
2298 status |= func_status::ToggleOn;
2300 status |= func_status::ToggleOff;
2302 case LyXTabular::UNSET_LONGTABULAR:
2303 if (!tabular->IsLongTabular())
2304 status |= func_status::ToggleOn;
2306 status |= func_status::ToggleOff;
2308 case LyXTabular::SET_ROTATE_TABULAR:
2309 if (tabular->GetRotateTabular())
2310 status |= func_status::ToggleOn;
2312 status |= func_status::ToggleOff;
2314 case LyXTabular::UNSET_ROTATE_TABULAR:
2315 if (!tabular->GetRotateTabular())
2316 status |= func_status::ToggleOn;
2318 status |= func_status::ToggleOff;
2320 case LyXTabular::SET_ROTATE_CELL:
2321 if (tabular->GetRotateCell(actcell))
2322 status |= func_status::ToggleOn;
2324 status |= func_status::ToggleOff;
2326 case LyXTabular::UNSET_ROTATE_CELL:
2327 if (!tabular->GetRotateCell(actcell))
2328 status |= func_status::ToggleOn;
2330 status |= func_status::ToggleOff;
2332 case LyXTabular::SET_USEBOX:
2333 if (strToInt(argument) == tabular->GetUsebox(actcell))
2334 status |= func_status::ToggleOn;
2336 status |= func_status::ToggleOff;
2338 case LyXTabular::SET_LTFIRSTHEAD:
2339 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2340 status |= func_status::ToggleOn;
2342 status |= func_status::ToggleOff;
2344 case LyXTabular::SET_LTHEAD:
2345 if (tabular->GetRowOfLTHead(actcell, dummyltt))
2346 status |= func_status::ToggleOn;
2348 status |= func_status::ToggleOff;
2350 case LyXTabular::SET_LTFOOT:
2351 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2352 status |= func_status::ToggleOn;
2354 status |= func_status::ToggleOff;
2356 case LyXTabular::SET_LTLASTFOOT:
2357 if (tabular->GetRowOfLTFoot(actcell, dummyltt))
2358 status |= func_status::ToggleOn;
2360 status |= func_status::ToggleOff;
2362 case LyXTabular::SET_LTNEWPAGE:
2363 if (tabular->GetLTNewPage(actcell))
2364 status |= func_status::ToggleOn;
2366 status |= func_status::ToggleOff;
2369 status = func_status::Disabled;
2376 std::vector<string> const InsetTabular::getLabelList() const
2378 return tabular->getLabelList();
2382 bool InsetTabular::copySelection(BufferView * bv)
2384 if (!hasSelection())
2387 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2388 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2389 if (sel_col_start > sel_col_end) {
2390 sel_col_start = sel_col_end;
2391 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2393 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2395 int const columns = sel_col_end - sel_col_start + 1;
2397 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2398 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2399 if (sel_row_start > sel_row_end) {
2400 swap(sel_row_start, sel_row_end);
2402 int const rows = sel_row_end - sel_row_start + 1;
2404 delete paste_tabular;
2405 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2406 for (int i = 0; i < sel_row_start; ++i)
2407 paste_tabular->DeleteRow(0);
2408 while (paste_tabular->rows() > rows)
2409 paste_tabular->DeleteRow(rows);
2410 paste_tabular->SetTopLine(0, true, true);
2411 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2413 for (int i = 0; i < sel_col_start; ++i)
2414 paste_tabular->DeleteColumn(0);
2415 while (paste_tabular->columns() > columns)
2416 paste_tabular->DeleteColumn(columns);
2417 paste_tabular->SetLeftLine(0, true, true);
2418 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2422 paste_tabular->Ascii(bv->buffer(), sstr);
2423 bv->stuffClipboard(sstr.str().c_str());
2428 bool InsetTabular::pasteSelection(BufferView * bv)
2433 for (int r1 = 0, r2 = actrow;
2434 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2436 for(int c1 = 0, c2 = actcol;
2437 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2439 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2440 tabular->IsPartOfMultiColumn(r2,c2))
2442 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2446 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2450 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2451 int const n2 = tabular->GetCellNumber(r2, c2);
2452 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2453 tabular->GetCellInset(n2)->setOwner(this);
2454 tabular->GetCellInset(n2)->deleteLyXText(bv);
2461 bool InsetTabular::cutSelection()
2463 if (!hasSelection())
2466 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2467 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2468 if (sel_col_start > sel_col_end) {
2469 sel_col_start = sel_col_end;
2470 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2472 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2474 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2475 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2476 if (sel_row_start > sel_row_end) {
2477 swap(sel_row_start, sel_row_end);
2479 if (sel_cell_start > sel_cell_end) {
2480 swap(sel_cell_start, sel_cell_end);
2482 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2483 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2484 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2491 bool InsetTabular::isRightToLeft(BufferView *bv )
2493 return bv->getParentLanguage(this)->RightToLeft();
2497 bool InsetTabular::nodraw() const
2499 if (!UpdatableInset::nodraw() && the_locking_inset)
2500 return the_locking_inset->nodraw();
2501 return UpdatableInset::nodraw();
2505 int InsetTabular::scroll(bool recursive) const
2507 int sx = UpdatableInset::scroll(false);
2509 if (recursive && the_locking_inset)
2510 sx += the_locking_inset->scroll(recursive);
2516 bool InsetTabular::doClearArea() const
2518 return !locked || (need_update & (FULL|INIT));
2522 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2524 int const start = hasSelection() ? sel_cell_start : actcell;
2525 int const end = hasSelection() ? sel_cell_end : actcell;
2527 srow = tabular->row_of_cell(start);
2528 erow = tabular->row_of_cell(end);
2533 scol = tabular->column_of_cell(start);
2534 ecol = tabular->column_of_cell(end);
2538 ecol = tabular->right_column_of_cell(end);
2543 Paragraph * InsetTabular::getParFromID(int id) const
2546 for(int i = 0; i < tabular->rows(); ++i) {
2547 for(int j = 0; j < tabular->columns(); ++j) {
2548 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2556 Paragraph * InsetTabular::firstParagraph() const
2558 if (the_locking_inset)
2559 return the_locking_inset->firstParagraph();
2564 Paragraph * InsetTabular::getFirstParagraph(int i) const
2566 return (i < tabular->GetNumberOfCells())
2567 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2572 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2574 if (the_locking_inset)
2575 return the_locking_inset->cursor(bv);
2576 return Inset::cursor(bv);
2580 Inset * InsetTabular::getInsetFromID(int id_arg) const
2583 return const_cast<InsetTabular *>(this);
2586 for(int i=0; i < tabular->rows(); ++i) {
2587 for(int j=0; j < tabular->columns(); ++j) {
2588 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2596 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2598 if (the_locking_inset) {
2599 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2602 if (tabular->IsLastCell(actcell)) {
2603 bv->unlockInset(const_cast<InsetTabular *>(this));
2609 // otherwise we have to lock the next inset and ask for it's selecttion
2610 UpdatableInset * inset =
2611 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2612 inset->edit(bv, 0, 0, 0);
2613 string const str(selectNextWordInt(bv, value));
2621 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2623 // when entering this function the inset should be ALWAYS locked!
2624 lyx::Assert(the_locking_inset);
2626 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2630 if (tabular->IsLastCell(actcell)) {
2631 bv->unlockInset(const_cast<InsetTabular *>(this));
2635 // otherwise we have to lock the next inset and ask for it's selecttion
2636 UpdatableInset * inset =
2637 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2639 return selectNextWordInt(bv, value);
2643 void InsetTabular::selectSelectedWord(BufferView * bv)
2645 if (the_locking_inset) {
2646 the_locking_inset->selectSelectedWord(bv);
2653 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2655 if (the_locking_inset) {
2656 the_locking_inset->toggleSelection(bv, kill_selection);
2661 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2662 bool const & cs, bool const & mw)
2664 if (the_locking_inset) {
2665 if (the_locking_inset->searchForward(bv, str, cs, mw))
2667 if (tabular->IsLastCell(actcell)) {
2668 bv->unlockInset(const_cast<InsetTabular *>(this));
2673 // otherwise we have to lock the next inset and search there
2674 UpdatableInset * inset =
2675 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2678 bool const res = searchForward(bv, str, cs, mw);
2679 updateLocal(bv, NONE, false);
2680 bv->updateInset(const_cast<InsetTabular *>(this), false);
2683 return searchForward(bv, str, cs, mw);
2688 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2689 bool const & cs, bool const & mw)
2691 if (the_locking_inset) {
2692 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2694 if (!actcell) { // we are already in the first cell
2695 bv->unlockInset(const_cast<InsetTabular *>(this));
2700 // otherwise we have to lock the next inset and search there
2701 UpdatableInset * inset =
2702 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2703 inset->edit(bv, false);
2705 bool const res = searchBackward(bv, str, cs, mw);
2706 bv->updateInset(const_cast<InsetTabular *>(this), false);
2709 return searchBackward(bv, str, cs, mw);
2714 bool InsetTabular::insetAllowed(Inset::Code code) const
2716 if (the_locking_inset)
2717 return the_locking_inset->insetAllowed(code);