1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
17 #include "insettabular.h"
20 #include "commandtags.h"
23 #include "LaTeXFeatures.h"
27 #include "lyx_gui_misc.h"
29 #include "insets/insettext.h"
34 #include "BufferView.h"
35 #include "undo_funcs.h"
36 #include "lyxlength.h"
37 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/Alert.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::VALIGN_TOP, "valign-top" },
89 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
90 { LyXTabular::VALIGN_CENTER, "valign-center" },
91 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
92 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
93 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
94 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
95 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
96 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
97 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
98 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
99 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
100 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
101 { LyXTabular::MULTICOLUMN, "multicolumn" },
102 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
103 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
104 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
105 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
106 { LyXTabular::SET_PWIDTH, "set-pwidth" },
107 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
108 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
109 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
110 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
111 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
112 { LyXTabular::SET_USEBOX, "set-usebox" },
113 { LyXTabular::SET_LTHEAD, "set-lthead" },
114 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
115 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
116 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
117 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
118 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
119 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
120 { LyXTabular::LAST_ACTION, "" }
126 bool InsetTabular::hasPasteBuffer() const
128 return (paste_tabular != 0);
132 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
139 tabular.reset(new LyXTabular(this, rows, columns));
140 // for now make it always display as display() inset
142 the_locking_inset = 0;
143 old_locking_inset = 0;
146 actrow = actcell = 0;
150 in_reset_pos = false;
156 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
158 : UpdatableInset(tab, same_id), buffer(&buf)
160 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
169 in_reset_pos = false;
175 InsetTabular::~InsetTabular()
181 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
183 return new InsetTabular(*this, buf, same_id);
187 void InsetTabular::write(Buffer const * buf, ostream & os) const
189 os << " Tabular" << endl;
190 tabular->Write(buf, os);
194 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
196 bool const old_format = (lex.getString() == "\\LyXTable");
198 tabular.reset(new LyXTabular(buf, this, lex));
206 string token = lex.getString();
207 while (lex.isOK() && (token != "\\end_inset")) {
209 token = lex.getString();
211 if (token != "\\end_inset") {
212 lex.printError("Missing \\end_inset at this point. "
218 int InsetTabular::ascent(BufferView *, LyXFont const &) const
220 return tabular->GetAscentOfRow(0);
224 int InsetTabular::descent(BufferView *, LyXFont const &) const
226 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
230 int InsetTabular::width(BufferView *, LyXFont const &) const
232 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
236 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
237 float & x, bool cleared) const
245 if (need_update == INIT) {
246 if (calculate_dimensions_of_cells(bv, font, true))
247 bv->text->status = LyXText::CHANGED_IN_DRAW;
252 Painter & pain = bv->painter();
258 UpdatableInset::draw(bv, font, baseline, x, cleared);
261 x += static_cast<float>(scroll());
263 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
264 (top_x != int(x)) || (top_baseline != baseline)))
266 int h = ascent(bv, font) + descent(bv, font);
267 int const tx = display() || !owner() ? 0 : top_x;
268 int w = tx ? width(bv, font) : pain.paperWidth();
269 int ty = baseline - ascent(bv, font);
273 if ((ty + h) > pain.paperHeight())
274 h = pain.paperHeight();
275 if ((top_x + w) > pain.paperWidth())
276 w = pain.paperWidth();
277 pain.fillRectangle(tx, ty, w, h, backgroundColor());
283 top_baseline = baseline;
284 x += ADD_TO_TABULAR_WIDTH;
288 first_visible_cell = -1;
289 for (i = 0; i < tabular->rows(); ++i) {
291 cell = tabular->GetCellNumber(i, 0);
292 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
293 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
295 baseline += tabular->GetDescentOfRow(i) +
296 tabular->GetAscentOfRow(i + 1) +
297 tabular->GetAdditionalHeight(i + 1);
300 for (j = 0; j < tabular->columns(); ++j) {
301 if (nx > bv->workWidth())
303 if (tabular->IsPartOfMultiColumn(i, j))
305 cx = nx + tabular->GetBeginningOfTextInCell(cell);
306 if (first_visible_cell < 0)
307 first_visible_cell = cell;
308 if (hasSelection()) {
309 drawCellSelection(pain, nx, baseline, i, j, cell);
312 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
313 drawCellLines(pain, nx, baseline, i, cell);
314 nx += tabular->GetWidthOfColumn(cell);
317 baseline += tabular->GetDescentOfRow(i) +
318 tabular->GetAscentOfRow(i + 1) +
319 tabular->GetAdditionalHeight(i + 1);
321 } else if (need_update == CELL) {
324 if (the_locking_inset &&
325 tabular->GetCellInset(actcell) != the_locking_inset)
327 Inset * inset = tabular->GetCellInset(cell);
329 inset != the_locking_inset && i < tabular->rows();
333 inset != the_locking_inset && j < tabular->columns();
336 if (tabular->IsPartOfMultiColumn(i, j))
338 nx += tabular->GetWidthOfColumn(cell);
340 inset = tabular->GetCellInset(cell);
342 if (tabular->row_of_cell(cell) > i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
350 // compute baseline for actual row
351 for (i = 0; i < actrow; ++i) {
352 baseline += tabular->GetDescentOfRow(i) +
353 tabular->GetAscentOfRow(i + 1) +
354 tabular->GetAdditionalHeight(i + 1);
356 // now compute the right x position
357 cell = tabular->GetCellNumber(actrow, 0);
358 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
359 if (tabular->IsPartOfMultiColumn(actrow, j))
361 nx += tabular->GetWidthOfColumn(cell);
365 i = tabular->row_of_cell(cell);
366 if (the_locking_inset != tabular->GetCellInset(cell)) {
367 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
370 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
372 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
374 // Here we use rectangular backgroundColor patches to clean up
375 // within a cell around the cell's red inset box. As follows:
378 // | | | | The rectangles are A, B and C
379 // | A |------------| B | below, origin top left (tx, ty),
380 // | | inset box | | dimensions w(idth), h(eight).
381 // +---+------------+---+ x grows rightward, y downward
383 // +--------------------+
385 // clear only if we didn't have a change
386 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
387 // clear before the inset
390 ty = baseline - tabular->GetAscentOfRow(i) + 1;
391 w = int(cx - nx - 1);
392 h = tabular->GetAscentOfRow(i) +
393 tabular->GetDescentOfRow(i) - 1;
394 pain.fillRectangle(tx, ty, w, h, backgroundColor());
395 // clear behind the inset
396 tx = int(cx + the_locking_inset->width(bv,font) + 1);
397 ty = baseline - tabular->GetAscentOfRow(i) + 1;
398 w = tabular->GetWidthOfColumn(cell) -
399 tabular->GetBeginningOfTextInCell(cell) -
400 the_locking_inset->width(bv,font) -
401 tabular->GetAdditionalWidth(cell) - 1;
402 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
403 pain.fillRectangle(tx, ty, w, h, backgroundColor());
404 // clear below the inset
406 ty = baseline + the_locking_inset->descent(bv, font) + 1;
407 w = tabular->GetWidthOfColumn(cell) -
408 tabular->GetAdditionalWidth(cell) - 1;
409 h = tabular->GetDescentOfRow(i) -
410 the_locking_inset->descent(bv, font) - 1;
411 pain.fillRectangle(tx, ty, w, h, backgroundColor());
414 x -= ADD_TO_TABULAR_WIDTH;
415 x += width(bv, font);
416 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
418 for(Inset * inset = owner(); inset; ++i)
419 inset = inset->owner();
420 if (calculate_dimensions_of_cells(bv, font, false))
428 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
429 int row, int cell) const
431 int x2 = x + tabular->GetWidthOfColumn(cell);
434 if (!tabular->TopAlreadyDrawed(cell)) {
435 on_off = !tabular->TopLine(cell);
436 pain.line(x, baseline - tabular->GetAscentOfRow(row),
437 x2, baseline - tabular->GetAscentOfRow(row),
438 on_off ? LColor::tabularonoffline : LColor::tabularline,
439 on_off ? Painter::line_onoffdash : Painter::line_solid);
441 on_off = !tabular->BottomLine(cell);
442 pain.line(x,baseline + tabular->GetDescentOfRow(row),
443 x2, baseline + tabular->GetDescentOfRow(row),
444 on_off ? LColor::tabularonoffline : LColor::tabularline,
445 on_off ? Painter::line_onoffdash : Painter::line_solid);
446 if (!tabular->LeftAlreadyDrawed(cell)) {
447 on_off = !tabular->LeftLine(cell);
448 pain.line(x, baseline - tabular->GetAscentOfRow(row),
449 x, baseline + tabular->GetDescentOfRow(row),
450 on_off ? LColor::tabularonoffline : LColor::tabularline,
451 on_off ? Painter::line_onoffdash : Painter::line_solid);
453 on_off = !tabular->RightLine(cell);
454 pain.line(x2 - tabular->GetAdditionalWidth(cell),
455 baseline - tabular->GetAscentOfRow(row),
456 x2 - tabular->GetAdditionalWidth(cell),
457 baseline + tabular->GetDescentOfRow(row),
458 on_off ? LColor::tabularonoffline : LColor::tabularline,
459 on_off ? Painter::line_onoffdash : Painter::line_solid);
463 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
464 int row, int column, int cell) const
466 lyx::Assert(hasSelection());
467 int cs = tabular->column_of_cell(sel_cell_start);
468 int ce = tabular->column_of_cell(sel_cell_end);
471 cs = tabular->column_of_cell(sel_cell_end);
473 ce = tabular->right_column_of_cell(sel_cell_end);
476 int rs = tabular->row_of_cell(sel_cell_start);
477 int re = tabular->row_of_cell(sel_cell_end);
481 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
482 int w = tabular->GetWidthOfColumn(cell);
483 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
484 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
485 w, h, LColor::selection);
490 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
496 owner()->update(bv, font, true);
503 if (calculate_dimensions_of_cells(bv, font, true))
506 owner()->update(bv, font, true);
510 if (the_locking_inset)
511 the_locking_inset->update(bv, font, reinit);
512 if (need_update < FULL &&
513 bv->text->status() == LyXText::NEED_MORE_REFRESH)
518 switch (need_update) {
522 if (calculate_dimensions_of_cells(bv, font, false))
535 string const InsetTabular::editMessage() const
537 return _("Opened Tabular Inset");
541 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
543 UpdatableInset::edit(bv, x, y, button);
545 if (!bv->lockInset(this)) {
546 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
550 the_locking_inset = 0;
556 if (insetHit(bv, x, y) && (button != 3)) {
557 activateCellInsetAbs(bv, x, y, button);
562 void InsetTabular::edit(BufferView * bv, bool front)
564 UpdatableInset::edit(bv, front);
566 if (!bv->lockInset(this)) {
567 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
571 the_locking_inset = 0;
577 actcell = tabular->GetNumberOfCells() - 1;
584 void InsetTabular::insetUnlock(BufferView * bv)
586 if (the_locking_inset) {
587 the_locking_inset->insetUnlock(bv);
588 the_locking_inset = 0;
593 if (scroll(false) || hasSelection()) {
598 updateLocal(bv, FULL, false);
603 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
604 bool mark_dirty) const
608 calculate_dimensions_of_cells(bv, font, true);
610 if (need_update < what) // only set this if it has greater update
612 if ((what == INIT) && hasSelection()) {
616 if (need_update != NONE) {
617 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
618 if (locked) // && (what != NONE))
624 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
626 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
631 if (inset == tabular->GetCellInset(actcell)) {
632 lyxerr[Debug::INSETTEXT] << "OK" << endl;
633 the_locking_inset = tabular->GetCellInset(actcell);
636 } else if (!the_locking_inset) {
637 int const n = tabular->GetNumberOfCells();
638 int const id = inset->id();
639 for (int i = 0; i < n; ++i) {
640 InsetText * in = tabular->GetCellInset(i);
643 the_locking_inset = in;
648 if (in->getInsetFromID(id)) {
651 // the_locking_inset = in;
654 return the_locking_inset->lockInsetInInset(bv, inset);
657 } else if (the_locking_inset && (the_locking_inset == inset)) {
658 lyxerr[Debug::INSETTEXT] << "OK" << endl;
660 } else if (the_locking_inset) {
661 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
662 return the_locking_inset->lockInsetInInset(bv, inset);
664 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
669 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
672 if (!the_locking_inset)
674 if (the_locking_inset == inset) {
675 the_locking_inset->insetUnlock(bv);
676 the_locking_inset = 0;
678 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
684 updateLocal(bv, CELL, false);
685 showInsetCursor(bv, false);
688 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
689 if (inset->lyxCode() == TABULAR_CODE &&
690 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
691 bv->owner()->getDialogs()->updateTabular(this);
700 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
702 if (!the_locking_inset)
704 if (the_locking_inset != inset) {
705 if (!the_locking_inset->updateInsetInInset(bv, inset))
708 updateLocal(bv, CELL, false);
713 unsigned int InsetTabular::insetInInsetY()
715 if (!the_locking_inset)
717 return inset_y + the_locking_inset->insetInInsetY();
721 UpdatableInset * InsetTabular::getLockingInset() const
723 return the_locking_inset ? the_locking_inset->getLockingInset() :
724 const_cast<InsetTabular *>(this);
728 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
732 if (the_locking_inset)
733 return the_locking_inset->getFirstLockingInsetOfType(c);
738 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
740 if (the_locking_inset)
741 return the_locking_inset->insertInset(bv, inset);
746 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
748 if (hasSelection() && (button == 3))
751 if (hasSelection()) {
753 updateLocal(bv, SELECTION, false);
756 int const ocell = actcell;
757 int const orow = actrow;
762 updateLocal(bv, NONE, false);
766 if ((ocell != actcell) && the_locking_inset) {
767 the_locking_inset->insetUnlock(bv);
768 the_locking_inset = 0;
775 bool const inset_hit = insetHit(bv, x, y);
777 if ((ocell == actcell) && the_locking_inset && inset_hit) {
779 the_locking_inset->insetButtonPress(bv,
780 x - inset_x, y - inset_y,
783 } else if (the_locking_inset) {
784 the_locking_inset->insetUnlock(bv);
786 the_locking_inset = 0;
788 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
791 if (inset_hit && bv->theLockingInset()) {
792 if (activateCellInsetAbs(bv, x, y, button))
793 the_locking_inset->insetButtonPress(bv,
803 bool InsetTabular::insetButtonRelease(BufferView * bv,
804 int x, int y, int button)
807 if (the_locking_inset)
808 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
809 y - inset_y, button);
810 if (button == 3 && !ret) {
811 bv->owner()->getDialogs()->showTabular(this);
818 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
820 if (the_locking_inset) {
821 the_locking_inset->insetMotionNotify(bv,
829 // int const old_cell = actcell;
832 if (!hasSelection()) {
833 setSelection(actcell, actcell);
835 setSelection(sel_cell_start, actcell);
837 updateLocal(bv, SELECTION, false);
842 void InsetTabular::insetKeyPress(XKeyEvent * xke)
844 if (the_locking_inset) {
845 the_locking_inset->insetKeyPress(xke);
851 UpdatableInset::RESULT
852 InsetTabular::localDispatch(BufferView * bv, kb_action action,
855 // We need to save the value of the_locking_inset as the call to
856 // the_locking_inset->LocalDispatch might unlock it.
857 old_locking_inset = the_locking_inset;
858 UpdatableInset::RESULT result =
859 UpdatableInset::localDispatch(bv, action, arg);
860 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
865 if ((action < 0) && arg.empty())
868 bool hs = hasSelection();
871 // this one have priority over the locked InsetText, if we're not already
872 // inside another tabular then that one get's priority!
873 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
878 unlockInsetInInset(bv, the_locking_inset);
879 if (action == LFUN_TAB)
880 moveNextCell(bv, old_locking_inset != 0);
882 movePrevCell(bv, old_locking_inset != 0);
885 updateLocal(bv, SELECTION, false);
886 if (!the_locking_inset) {
888 return DISPATCHED_NOUPDATE;
891 // this to avoid compiler warnings.
897 if (the_locking_inset) {
898 result = the_locking_inset->localDispatch(bv, action, arg);
899 if (result == DISPATCHED_NOUPDATE) {
902 if (sc != scroll()) { // inset has been scrolled
903 the_locking_inset->toggleInsetCursor(bv);
904 updateLocal(bv, FULL, false);
905 the_locking_inset->toggleInsetCursor(bv);
908 } else if (result == DISPATCHED) {
909 the_locking_inset->toggleInsetCursor(bv);
910 updateLocal(bv, CELL, false);
911 the_locking_inset->toggleInsetCursor(bv);
913 } else if (result == FINISHED_UP) {
915 } else if (result == FINISHED_DOWN) {
917 } else if (result == FINISHED_RIGHT) {
925 // --- Cursor Movements ----------------------------------
926 case LFUN_RIGHTSEL: {
927 int const start = hasSelection() ? sel_cell_start : actcell;
928 if (tabular->IsLastCellInRow(actcell)) {
929 setSelection(start, actcell);
934 // if we are starting a selection, only select
935 // the current cell at the beginning
936 if (hasSelection()) {
937 moveRight(bv, false);
940 setSelection(start, end);
941 updateLocal(bv, SELECTION, false);
945 result = moveRight(bv);
948 updateLocal(bv, SELECTION, false);
951 int const start = hasSelection() ? sel_cell_start : actcell;
952 if (tabular->IsFirstCellInRow(actcell)) {
953 setSelection(start, actcell);
958 // if we are starting a selection, only select
959 // the current cell at the beginning
960 if (hasSelection()) {
964 setSelection(start, end);
965 updateLocal(bv, SELECTION, false);
969 result = moveLeft(bv);
972 updateLocal(bv, SELECTION, false);
975 int const start = hasSelection() ? sel_cell_start : actcell;
976 int const ocell = actcell;
977 // if we are starting a selection, only select
978 // the current cell at the beginning
979 if (hasSelection()) {
981 if ((ocell == sel_cell_end) ||
982 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
983 setSelection(start, tabular->GetCellBelow(sel_cell_end));
985 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
987 setSelection(start, start);
989 updateLocal(bv, SELECTION, false);
993 result = moveDown(bv, old_locking_inset != 0);
996 updateLocal(bv, SELECTION, false);
1000 int const start = hasSelection() ? sel_cell_start : actcell;
1001 int const ocell = actcell;
1002 // if we are starting a selection, only select
1003 // the current cell at the beginning
1004 if (hasSelection()) {
1006 if ((ocell == sel_cell_end) ||
1007 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1008 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1010 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1012 setSelection(start, start);
1014 updateLocal(bv, SELECTION, false);
1018 result = moveUp(bv, old_locking_inset != 0);
1021 updateLocal(bv, SELECTION, false);
1024 int column = actcol;
1025 unlockInsetInInset(bv, the_locking_inset);
1026 if (bv->text->first + bv->painter().paperHeight() <
1027 (top_baseline + tabular->GetHeightOfTabular()))
1029 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1030 updateLocal(bv, FULL, false);
1031 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1033 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1036 updateLocal(bv, CURSOR, false);
1040 int column = actcol;
1041 unlockInsetInInset(bv, the_locking_inset);
1042 if (top_baseline < 0) {
1043 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1044 updateLocal(bv, FULL, false);
1045 if (top_baseline > 0)
1048 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1053 updateLocal(bv, CURSOR, false);
1056 // none of these make sense for insettabular,
1057 // but we must catch them to prevent any
1058 // selection from being confused
1062 case LFUN_WORDLEFTSEL:
1063 case LFUN_WORDRIGHT:
1064 case LFUN_WORDRIGHTSEL:
1065 case LFUN_DOWN_PARAGRAPH:
1066 case LFUN_DOWN_PARAGRAPHSEL:
1067 case LFUN_UP_PARAGRAPH:
1068 case LFUN_UP_PARAGRAPHSEL:
1069 case LFUN_BACKSPACE:
1075 case LFUN_BEGINNINGBUF:
1076 case LFUN_BEGINNINGBUFSEL:
1078 case LFUN_ENDBUFSEL:
1080 case LFUN_LAYOUT_TABULAR:
1081 bv->owner()->getDialogs()->showTabular(this);
1083 case LFUN_TABULAR_FEATURE:
1084 if (!tabularFeatures(bv, arg))
1085 result = UNDISPATCHED;
1088 if (!copySelection(bv))
1090 setUndo(bv, Undo::DELETE,
1091 bv->text->cursor.par(),
1092 bv->text->cursor.par()->next());
1094 updateLocal(bv, INIT, true);
1097 if (!hasSelection())
1102 case LFUN_PASTESELECTION:
1104 string const clip(bv->getClipboard());
1108 if (clip.find('\t') != string::npos) {
1112 string::size_type len = clip.length();
1113 string::size_type p = 0;
1116 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1124 maxCols = max(cols, maxCols);
1130 maxCols = max(cols, maxCols);
1131 delete paste_tabular;
1132 paste_tabular = new LyXTabular(this, rows, maxCols);
1133 string::size_type op = 0;
1135 int cells = paste_tabular->GetNumberOfCells();
1137 while ((cell < cells) && (p < len) &&
1138 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1143 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1148 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1149 while (cols++ < maxCols)
1157 // check for the last cell if there is no trailing '\n'
1158 if ((cell < cells) && (op < len))
1159 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1161 // so that the clipboard is used and it goes on
1163 // and executes LFUN_PASTESELECTION in insettext!
1164 delete paste_tabular;
1169 if (hasPasteBuffer()) {
1170 setUndo(bv, Undo::INSERT,
1171 bv->text->cursor.par(),
1172 bv->text->cursor.par()->next());
1174 updateLocal(bv, INIT, true);
1177 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1179 // we try to activate the actual inset and put this event down to
1180 // the insets dispatch function.
1181 result = UNDISPATCHED;
1182 if (the_locking_inset)
1185 if (activateCellInset(bv)) {
1186 // reset need_update setted in above function!
1188 result = the_locking_inset->localDispatch(bv, action, arg);
1189 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1190 unlockInsetInInset(bv, the_locking_inset);
1192 // we need to update if this was requested before
1193 updateLocal(bv, NONE, false);
1194 return UNDISPATCHED;
1199 updateLocal(bv, CELL, false);
1204 if (result < FINISHED) {
1205 if (!the_locking_inset) {
1206 showInsetCursor(bv);
1209 bv->unlockInset(this);
1214 int InsetTabular::latex(Buffer const * buf, ostream & os,
1215 bool fragile, bool fp) const
1217 return tabular->latex(buf, os, fragile, fp);
1221 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1224 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1226 return tabular->ascii(buf, os, 0, false,0);
1230 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1233 int const ret = tabular->ascii(buf,os,
1234 (int)parOwner()->params().depth(),
1241 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1246 // if the table is inside a float it doesn't need the informaltable
1247 // wrapper. Search for it.
1248 for(master = owner();
1249 master && master->lyxCode() != Inset::FLOAT_CODE;
1250 master = master->owner());
1253 os << "<informaltable>\n";
1256 ret+= tabular->docBook(buf,os);
1258 os << "</informaltable>\n";
1265 void InsetTabular::validate(LaTeXFeatures & features) const
1267 tabular->Validate(features);
1271 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1272 LyXFont const & font,
1279 bool changed = false;
1281 // if we have a locking_inset we should have to check only this cell for
1282 // change so I'll try this to have a boost, but who knows ;)
1283 if ((need_update != INIT) &&
1284 (the_locking_inset == tabular->GetCellInset(actcell))) {
1285 for(int i = 0; i < tabular->columns(); ++i) {
1286 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1288 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1291 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1292 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1293 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1296 for (int i = 0; i < tabular->rows(); ++i) {
1299 for (int j = 0; j < tabular->columns(); ++j) {
1300 if (tabular->IsPartOfMultiColumn(i,j))
1303 inset = tabular->GetCellInset(cell);
1304 if (!reinit && !tabular->GetPWidth(cell).zero())
1305 inset->update(bv, font, false);
1306 maxAsc = max(maxAsc, inset->ascent(bv, font));
1307 maxDesc = max(maxDesc, inset->descent(bv, font));
1308 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1310 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1311 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1319 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1321 if (the_locking_inset) {
1322 the_locking_inset->getCursorPos(bv, x, y);
1325 x = cursor_.x() - top_x;
1330 void InsetTabular::toggleInsetCursor(BufferView * bv)
1333 if (isCursorVisible())
1334 bv->hideLockedInsetCursor();
1337 if (the_locking_inset) {
1338 the_locking_inset->toggleInsetCursor(bv);
1342 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1344 int const asc = lyxfont::maxAscent(font);
1345 int const desc = lyxfont::maxDescent(font);
1347 if (isCursorVisible())
1348 bv->hideLockedInsetCursor();
1350 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1351 toggleCursorVisible();
1355 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1359 if (!isCursorVisible()) {
1360 LyXFont font; // = GetFont(par, cursor.pos);
1362 int const asc = lyxfont::maxAscent(font);
1363 int const desc = lyxfont::maxDescent(font);
1364 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1366 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1367 setCursorVisible(true);
1372 void InsetTabular::hideInsetCursor(BufferView * bv)
1374 if (isCursorVisible()) {
1375 bv->hideLockedInsetCursor();
1376 setCursorVisible(false);
1381 void InsetTabular::fitInsetCursor(BufferView * bv) const
1383 if (the_locking_inset) {
1384 the_locking_inset->fitInsetCursor(bv);
1389 int const asc = lyxfont::maxAscent(font);
1390 int const desc = lyxfont::maxDescent(font);
1391 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1395 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1399 actcell = actrow = actcol = 0;
1400 int ly = tabular->GetDescentOfRow(actrow);
1402 // first search the right row
1403 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1404 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1405 tabular->GetAscentOfRow(actrow + 1) +
1406 tabular->GetAdditionalHeight(actrow + 1));
1408 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1410 actcell = tabular->GetCellNumber(actrow, actcol);
1412 // now search the right column
1413 int lx = tabular->GetWidthOfColumn(actcell) -
1414 tabular->GetAdditionalWidth(actcell);
1415 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1416 lx += tabular->GetWidthOfColumn(actcell + 1)
1417 + tabular->GetAdditionalWidth(actcell);
1419 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1424 int InsetTabular::getCellXPos(int cell) const
1428 for (; !tabular->IsFirstCellInRow(c); --c)
1430 int lx = tabular->GetWidthOfColumn(cell);
1431 for (; c < cell; ++c) {
1432 lx += tabular->GetWidthOfColumn(c);
1434 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1438 void InsetTabular::resetPos(BufferView * bv) const
1440 #warning This should be fixed in the right manner (20011128 Jug)
1441 // fast hack to fix infinite repaintings!
1446 actcol = tabular->column_of_cell(actcell);
1449 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1450 if (tabular->IsLastCellInRow(cell)) {
1451 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1452 tabular->GetAscentOfRow(actrow + 1) +
1453 tabular->GetAdditionalHeight(actrow + 1));
1457 if (!locked || nodraw()) {
1458 if (the_locking_inset)
1459 inset_y = cursor_.y();
1462 // we need this only from here on!!!
1463 in_reset_pos = true;
1464 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1465 int new_x = getCellXPos(actcell);
1466 int old_x = cursor_.x();
1469 // cursor.x(getCellXPos(actcell) + offset);
1470 if ((actcol < tabular->columns()-1) && scroll(false) &&
1471 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1474 updateLocal(bv, FULL, false);
1475 } else if (the_locking_inset &&
1476 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1478 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1479 if (xx > (bv->workWidth()-20)) {
1480 scroll(bv, -(xx - bv->workWidth() + 60));
1481 updateLocal(bv, FULL, false);
1482 } else if (xx < 20) {
1488 updateLocal(bv, FULL, false);
1490 } else if ((cursor_.x() - offset) > 20 &&
1491 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1492 > (bv->workWidth() - 20)) {
1493 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1494 updateLocal(bv, FULL, false);
1495 } else if ((cursor_.x() - offset) < 20) {
1496 scroll(bv, 20 - cursor_.x() + offset);
1497 updateLocal(bv, FULL, false);
1498 } else if (scroll(false) && top_x > 20 &&
1499 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1500 scroll(bv, old_x - cursor_.x());
1501 updateLocal(bv, FULL, false);
1503 if (the_locking_inset) {
1504 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1505 inset_y = cursor_.y();
1507 if ((!the_locking_inset ||
1508 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1509 actcell != oldcell) {
1510 InsetTabular * inset = const_cast<InsetTabular *>(this);
1511 bv->owner()->getDialogs()->updateTabular(inset);
1514 in_reset_pos = false;
1518 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1520 if (lock && !old_locking_inset) {
1521 if (activateCellInset(bv))
1524 bool moved = isRightToLeft(bv)
1525 ? movePrevCell(bv) : moveNextCell(bv);
1527 return FINISHED_RIGHT;
1528 if (lock && activateCellInset(bv))
1532 return DISPATCHED_NOUPDATE;
1536 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1538 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1541 if (lock) { // behind the inset
1542 if (activateCellInset(bv, 0, 0, 0, true))
1546 return DISPATCHED_NOUPDATE;
1550 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1552 int const ocell = actcell;
1553 actcell = tabular->GetCellAbove(actcell);
1554 if (actcell == ocell) // we moved out of the inset
1560 if (old_locking_inset) {
1561 old_locking_inset->getCursorPos(bv, x, y);
1562 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1564 if (activateCellInset(bv, x, 0))
1567 return DISPATCHED_NOUPDATE;
1571 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1573 int const ocell = actcell;
1574 actcell = tabular->GetCellBelow(actcell);
1575 if (actcell == ocell) // we moved out of the inset
1576 return FINISHED_DOWN;
1581 if (old_locking_inset) {
1582 old_locking_inset->getCursorPos(bv, x, y);
1583 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1585 if (activateCellInset(bv, x, 0))
1588 return DISPATCHED_NOUPDATE;
1592 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1594 if (isRightToLeft(bv)) {
1595 if (tabular->IsFirstCellInRow(actcell)) {
1596 int row = tabular->row_of_cell(actcell);
1597 if (row == tabular->rows() - 1)
1599 actcell = tabular->GetLastCellInRow(row);
1600 actcell = tabular->GetCellBelow(actcell);
1607 if (tabular->IsLastCell(actcell))
1612 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1613 isRightToLeftPar(bv->buffer()->params);
1614 activateCellInset(bv, 0, 0, 0, !rtl);
1621 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1623 if (isRightToLeft(bv)) {
1624 if (tabular->IsLastCellInRow(actcell)) {
1625 int row = tabular->row_of_cell(actcell);
1628 actcell = tabular->GetFirstCellInRow(row);
1629 actcell = tabular->GetCellAbove(actcell);
1631 if (tabular->IsLastCell(actcell))
1636 if (!actcell) // first cell
1641 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1642 isRightToLeftPar(bv->buffer()->params);
1643 activateCellInset(bv, 0, 0, 0, !rtl);
1650 bool InsetTabular::deletable() const
1656 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1660 setSelection(0, tabular->GetNumberOfCells() - 1);
1662 if (hasSelection()) {
1663 setUndo(bv, Undo::EDIT,
1664 bv->text->cursor.par(),
1665 bv->text->cursor.par()->next());
1666 bool frozen = undo_frozen;
1669 // apply the fontchange on the whole selection
1674 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1675 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1676 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1677 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1682 updateLocal(bv, INIT, true);
1684 if (the_locking_inset)
1685 the_locking_inset->setFont(bv, font, tall);
1689 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1691 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1694 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1695 string const tmp = tabularFeature[i].feature;
1697 if (tmp == what.substr(0, tmp.length())) {
1698 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1699 //tabularFeatures[i].feature.length())) {
1700 action = tabularFeature[i].action;
1704 if (action == LyXTabular::LAST_ACTION)
1708 frontStrip(what.substr(tabularFeature[i].feature.length()));
1709 tabularFeatures(bv, action, val);
1713 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1714 string const & special, bool & flag)
1716 if (special == "dl_above") {
1719 } else if (special == "dl_below") {
1720 ltt.bottomDL = flag;
1722 } else if (special == "empty") {
1732 void InsetTabular::tabularFeatures(BufferView * bv,
1733 LyXTabular::Feature feature,
1734 string const & value)
1740 bool setLines = false;
1741 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1742 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1745 case LyXTabular::M_ALIGN_LEFT:
1746 case LyXTabular::ALIGN_LEFT:
1747 setAlign = LYX_ALIGN_LEFT;
1749 case LyXTabular::M_ALIGN_RIGHT:
1750 case LyXTabular::ALIGN_RIGHT:
1751 setAlign = LYX_ALIGN_RIGHT;
1753 case LyXTabular::M_ALIGN_CENTER:
1754 case LyXTabular::ALIGN_CENTER:
1755 setAlign = LYX_ALIGN_CENTER;
1757 case LyXTabular::M_VALIGN_TOP:
1758 case LyXTabular::VALIGN_TOP:
1759 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1761 case LyXTabular::M_VALIGN_BOTTOM:
1762 case LyXTabular::VALIGN_BOTTOM:
1763 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1765 case LyXTabular::M_VALIGN_CENTER:
1766 case LyXTabular::VALIGN_CENTER:
1767 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1772 if (hasSelection()) {
1773 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1775 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1776 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1778 setUndo(bv, Undo::FINISH,
1779 bv->text->cursor.par(),
1780 bv->text->cursor.par()->next());
1782 int row = tabular->row_of_cell(actcell);
1783 int column = tabular->column_of_cell(actcell);
1785 LyXTabular::ltType ltt;
1788 case LyXTabular::SET_PWIDTH:
1790 LyXLength const vallen(value);
1791 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1793 bool const update = (tmplen != vallen);
1794 tabular->SetColumnPWidth(actcell, vallen);
1797 for (int i = 0; i < tabular->rows(); ++i) {
1798 cell = tabular->GetCellNumber(i,column);
1799 tabular->GetCellInset(cell)->resizeLyXText(bv);
1801 updateLocal(bv, INIT, true);
1805 case LyXTabular::SET_MPWIDTH:
1807 LyXLength const vallen(value);
1808 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1810 bool const update = (tmplen != vallen);
1811 tabular->SetMColumnPWidth(actcell, vallen);
1813 for (int i = 0; i < tabular->rows(); ++i) {
1814 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1817 updateLocal(bv, INIT, true);
1821 case LyXTabular::SET_SPECIAL_COLUMN:
1822 case LyXTabular::SET_SPECIAL_MULTI:
1823 tabular->SetAlignSpecial(actcell,value,feature);
1824 updateLocal(bv, FULL, true);
1826 case LyXTabular::APPEND_ROW:
1827 // append the row into the tabular
1828 unlockInsetInInset(bv, the_locking_inset);
1829 tabular->AppendRow(actcell);
1830 updateLocal(bv, INIT, true);
1832 case LyXTabular::APPEND_COLUMN:
1833 // append the column into the tabular
1834 unlockInsetInInset(bv, the_locking_inset);
1835 tabular->AppendColumn(actcell);
1836 actcell = tabular->GetCellNumber(row, column);
1837 updateLocal(bv, INIT, true);
1839 case LyXTabular::DELETE_ROW:
1840 unlockInsetInInset(bv, the_locking_inset);
1841 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1842 tabular->DeleteRow(sel_row_start);
1844 if (sel_row_start >= tabular->rows())
1846 actcell = tabular->GetCellNumber(sel_row_start, column);
1848 updateLocal(bv, INIT, true);
1850 case LyXTabular::DELETE_COLUMN:
1851 unlockInsetInInset(bv, the_locking_inset);
1852 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1853 tabular->DeleteColumn(sel_col_start);
1855 if (sel_col_start >= tabular->columns())
1857 actcell = tabular->GetCellNumber(row, sel_col_start);
1859 updateLocal(bv, INIT, true);
1861 case LyXTabular::M_TOGGLE_LINE_TOP:
1863 case LyXTabular::TOGGLE_LINE_TOP:
1865 bool lineSet = !tabular->TopLine(actcell, flag);
1866 for (int i = sel_row_start; i <= sel_row_end; ++i)
1867 for (int j = sel_col_start; j <= sel_col_end; ++j)
1868 tabular->SetTopLine(
1869 tabular->GetCellNumber(i, j),
1871 updateLocal(bv, INIT, true);
1875 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1877 case LyXTabular::TOGGLE_LINE_BOTTOM:
1879 bool lineSet = !tabular->BottomLine(actcell, flag);
1880 for (int i = sel_row_start; i <= sel_row_end; ++i)
1881 for (int j = sel_col_start; j <= sel_col_end; ++j)
1882 tabular->SetBottomLine(
1883 tabular->GetCellNumber(i, j),
1886 updateLocal(bv, INIT, true);
1890 case LyXTabular::M_TOGGLE_LINE_LEFT:
1892 case LyXTabular::TOGGLE_LINE_LEFT:
1894 bool lineSet = !tabular->LeftLine(actcell, flag);
1895 for (int i = sel_row_start; i <= sel_row_end; ++i)
1896 for (int j = sel_col_start; j <= sel_col_end; ++j)
1897 tabular->SetLeftLine(
1898 tabular->GetCellNumber(i,j),
1901 updateLocal(bv, INIT, true);
1905 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1907 case LyXTabular::TOGGLE_LINE_RIGHT:
1909 bool lineSet = !tabular->RightLine(actcell, flag);
1910 for (int i = sel_row_start; i <= sel_row_end; ++i)
1911 for (int j = sel_col_start; j <= sel_col_end; ++j)
1912 tabular->SetRightLine(
1913 tabular->GetCellNumber(i,j),
1916 updateLocal(bv, INIT, true);
1920 case LyXTabular::M_ALIGN_LEFT:
1921 case LyXTabular::M_ALIGN_RIGHT:
1922 case LyXTabular::M_ALIGN_CENTER:
1924 case LyXTabular::ALIGN_LEFT:
1925 case LyXTabular::ALIGN_RIGHT:
1926 case LyXTabular::ALIGN_CENTER:
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->SetAlignment(
1930 tabular->GetCellNumber(i, j),
1933 updateLocal(bv, INIT, true);
1935 case LyXTabular::M_VALIGN_TOP:
1936 case LyXTabular::M_VALIGN_BOTTOM:
1937 case LyXTabular::M_VALIGN_CENTER:
1939 case LyXTabular::VALIGN_TOP:
1940 case LyXTabular::VALIGN_BOTTOM:
1941 case LyXTabular::VALIGN_CENTER:
1942 for (int i = sel_row_start; i <= sel_row_end; ++i)
1943 for (int j = sel_col_start; j <= sel_col_end; ++j)
1944 tabular->SetVAlignment(
1945 tabular->GetCellNumber(i, j),
1947 updateLocal(bv, INIT, true);
1949 case LyXTabular::MULTICOLUMN:
1951 if (sel_row_start != sel_row_end) {
1952 Alert::alert(_("Impossible Operation!"),
1953 _("Multicolumns can only be horizontally."),
1957 // just multicol for one Single Cell
1958 if (!hasSelection()) {
1959 // check wether we are completly in a multicol
1960 if (tabular->IsMultiColumn(actcell)) {
1961 tabular->UnsetMultiColumn(actcell);
1962 updateLocal(bv, INIT, true);
1964 tabular->SetMultiColumn(actcell, 1);
1965 updateLocal(bv, CELL, true);
1969 // we have a selection so this means we just add all this
1970 // cells to form a multicolumn cell
1974 if (sel_cell_start > sel_cell_end) {
1975 s_start = sel_cell_end;
1976 s_end = sel_cell_start;
1978 s_start = sel_cell_start;
1979 s_end = sel_cell_end;
1981 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1984 updateLocal(bv, INIT, true);
1987 case LyXTabular::SET_ALL_LINES:
1989 case LyXTabular::UNSET_ALL_LINES:
1990 for (int i = sel_row_start; i <= sel_row_end; ++i)
1991 for (int j = sel_col_start; j <= sel_col_end; ++j)
1992 tabular->SetAllLines(
1993 tabular->GetCellNumber(i,j), setLines);
1994 updateLocal(bv, INIT, true);
1996 case LyXTabular::SET_LONGTABULAR:
1997 tabular->SetLongTabular(true);
1998 updateLocal(bv, INIT, true); // because this toggles displayed
2000 case LyXTabular::UNSET_LONGTABULAR:
2001 tabular->SetLongTabular(false);
2002 updateLocal(bv, INIT, true); // because this toggles displayed
2004 case LyXTabular::SET_ROTATE_TABULAR:
2005 tabular->SetRotateTabular(true);
2007 case LyXTabular::UNSET_ROTATE_TABULAR:
2008 tabular->SetRotateTabular(false);
2010 case LyXTabular::SET_ROTATE_CELL:
2011 for (int i = sel_row_start; i <= sel_row_end; ++i)
2012 for (int j = sel_col_start; j<=sel_col_end; ++j)
2013 tabular->SetRotateCell(
2014 tabular->GetCellNumber(i, j),
2017 case LyXTabular::UNSET_ROTATE_CELL:
2018 for (int i = sel_row_start; i <= sel_row_end; ++i)
2019 for (int j = sel_col_start; j <= sel_col_end; ++j)
2020 tabular->SetRotateCell(
2021 tabular->GetCellNumber(i, j), false);
2023 case LyXTabular::SET_USEBOX:
2025 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2026 if (val == tabular->GetUsebox(actcell))
2027 val = LyXTabular::BOX_NONE;
2028 for (int i = sel_row_start; i <= sel_row_end; ++i)
2029 for (int j = sel_col_start; j <= sel_col_end; ++j)
2031 tabular->GetCellNumber(i, j), val);
2034 case LyXTabular::UNSET_LTFIRSTHEAD:
2036 case LyXTabular::SET_LTFIRSTHEAD:
2037 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2038 checkLongtableSpecial(ltt, value, flag);
2039 tabular->SetLTHead(row, flag, ltt, true);
2041 case LyXTabular::UNSET_LTHEAD:
2043 case LyXTabular::SET_LTHEAD:
2044 (void)tabular->GetRowOfLTHead(row, ltt);
2045 checkLongtableSpecial(ltt, value, flag);
2046 tabular->SetLTHead(row, flag, ltt, false);
2048 case LyXTabular::UNSET_LTFOOT:
2050 case LyXTabular::SET_LTFOOT:
2051 (void)tabular->GetRowOfLTFoot(row, ltt);
2052 checkLongtableSpecial(ltt, value, flag);
2053 tabular->SetLTFoot(row, flag, ltt, false);
2055 case LyXTabular::UNSET_LTLASTFOOT:
2057 case LyXTabular::SET_LTLASTFOOT:
2058 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2059 checkLongtableSpecial(ltt, value, flag);
2060 tabular->SetLTFoot(row, flag, ltt, true);
2062 case LyXTabular::SET_LTNEWPAGE:
2064 bool what = !tabular->GetLTNewPage(row);
2065 tabular->SetLTNewPage(row, what);
2068 // dummy stuff just to avoid warnings
2069 case LyXTabular::LAST_ACTION:
2075 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2078 UpdatableInset * inset =
2079 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2080 LyXFont font(LyXFont::ALL_SANE);
2082 x = inset->x() + inset->width(bv, font);
2083 y = inset->descent(bv, font);
2085 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2086 //inset_y = cursor.y();
2087 inset->edit(bv, x, y, button);
2088 if (!the_locking_inset)
2090 updateLocal(bv, CELL, false);
2091 return (the_locking_inset != 0);
2095 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2098 inset_x = cursor_.x()
2099 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2100 inset_y = cursor_.y();
2101 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2105 bool InsetTabular::insetHit(BufferView *, int x, int) const
2108 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2112 // This returns paperWidth() if the cell-width is unlimited or the width
2113 // in pixels if we have a pwidth for this cell.
2114 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2116 LyXLength const len = tabular->GetPWidth(cell);
2120 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2124 int InsetTabular::getMaxWidth(BufferView * bv,
2125 UpdatableInset const * inset) const
2127 int cell = tabular->GetCellFromInset(inset, actcell);
2130 lyxerr << "Own inset not found, shouldn't really happen!"
2135 int w = getMaxWidthOfCell(bv, cell);
2137 // because the inset then subtracts it's top_x and owner->x()
2138 w += (inset->x() - top_x);
2145 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2147 resizeLyXText(bv, recursive);
2151 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2154 for(int i = 0; i < tabular->rows(); ++i) {
2155 for(int j = 0; j < tabular->columns(); ++j) {
2156 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2164 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2165 bool const recursive) const
2167 if (the_locking_inset)
2168 return the_locking_inset->getLyXText(bv, recursive);
2170 // if we're locked lock the actual insettext and return it's LyXText!!!
2172 UpdatableInset * inset =
2173 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2174 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2175 return the_locking_inset->getLyXText(bv, recursive);
2178 return Inset::getLyXText(bv, recursive);
2182 bool InsetTabular::showInsetDialog(BufferView * bv) const
2184 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2185 bv->owner()->getDialogs()
2186 ->showTabular(const_cast<InsetTabular *>(this));
2191 void InsetTabular::openLayoutDialog(BufferView * bv) const
2193 if (the_locking_inset) {
2194 InsetTabular * i = static_cast<InsetTabular *>
2195 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2197 i->openLayoutDialog(bv);
2201 bv->owner()->getDialogs()->showTabular(
2202 const_cast<InsetTabular *>(this));
2207 // function returns an object as defined in func_status.h:
2208 // states OK, Unknown, Disabled, On, Off.
2210 FuncStatus InsetTabular::getStatus(string const & what) const
2212 int action = LyXTabular::LAST_ACTION;
2216 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2217 string const tmp = tabularFeature[i].feature;
2218 if (tmp == what.substr(0, tmp.length())) {
2219 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2220 // tabularFeatures[i].feature.length())) {
2221 action = tabularFeature[i].action;
2225 if (action == LyXTabular::LAST_ACTION) {
2227 return status.unknown(true);
2230 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2235 LyXTabular::ltType dummyltt;
2238 if (hasSelection()) {
2239 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2241 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2245 case LyXTabular::SET_PWIDTH:
2246 case LyXTabular::SET_MPWIDTH:
2247 case LyXTabular::SET_SPECIAL_COLUMN:
2248 case LyXTabular::SET_SPECIAL_MULTI:
2249 return status.disabled(true);
2251 case LyXTabular::APPEND_ROW:
2252 case LyXTabular::APPEND_COLUMN:
2253 case LyXTabular::DELETE_ROW:
2254 case LyXTabular::DELETE_COLUMN:
2255 case LyXTabular::SET_ALL_LINES:
2256 case LyXTabular::UNSET_ALL_LINES:
2257 return status.clear();
2259 case LyXTabular::MULTICOLUMN:
2260 status.setOnOff(tabular->IsMultiColumn(actcell));
2262 case LyXTabular::M_TOGGLE_LINE_TOP:
2264 case LyXTabular::TOGGLE_LINE_TOP:
2265 status.setOnOff(tabular->TopLine(actcell, flag));
2267 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2269 case LyXTabular::TOGGLE_LINE_BOTTOM:
2270 status.setOnOff(tabular->BottomLine(actcell, flag));
2272 case LyXTabular::M_TOGGLE_LINE_LEFT:
2274 case LyXTabular::TOGGLE_LINE_LEFT:
2275 status.setOnOff(tabular->LeftLine(actcell, flag));
2277 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2279 case LyXTabular::TOGGLE_LINE_RIGHT:
2280 status.setOnOff(tabular->RightLine(actcell, flag));
2282 case LyXTabular::M_ALIGN_LEFT:
2284 case LyXTabular::ALIGN_LEFT:
2285 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2287 case LyXTabular::M_ALIGN_RIGHT:
2289 case LyXTabular::ALIGN_RIGHT:
2290 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2292 case LyXTabular::M_ALIGN_CENTER:
2294 case LyXTabular::ALIGN_CENTER:
2295 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2297 case LyXTabular::M_VALIGN_TOP:
2299 case LyXTabular::VALIGN_TOP:
2300 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2302 case LyXTabular::M_VALIGN_BOTTOM:
2304 case LyXTabular::VALIGN_BOTTOM:
2305 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2307 case LyXTabular::M_VALIGN_CENTER:
2309 case LyXTabular::VALIGN_CENTER:
2310 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2312 case LyXTabular::SET_LONGTABULAR:
2313 status.setOnOff(tabular->IsLongTabular());
2315 case LyXTabular::UNSET_LONGTABULAR:
2316 status.setOnOff(!tabular->IsLongTabular());
2318 case LyXTabular::SET_ROTATE_TABULAR:
2319 status.setOnOff(tabular->GetRotateTabular());
2321 case LyXTabular::UNSET_ROTATE_TABULAR:
2322 status.setOnOff(!tabular->GetRotateTabular());
2324 case LyXTabular::SET_ROTATE_CELL:
2325 status.setOnOff(tabular->GetRotateCell(actcell));
2327 case LyXTabular::UNSET_ROTATE_CELL:
2328 status.setOnOff(!tabular->GetRotateCell(actcell));
2330 case LyXTabular::SET_USEBOX:
2331 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2333 case LyXTabular::SET_LTFIRSTHEAD:
2334 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2336 case LyXTabular::SET_LTHEAD:
2337 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2339 case LyXTabular::SET_LTFOOT:
2340 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2342 case LyXTabular::SET_LTLASTFOOT:
2343 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2345 case LyXTabular::SET_LTNEWPAGE:
2346 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2350 status.disabled(true);
2357 vector<string> const InsetTabular::getLabelList() const
2359 return tabular->getLabelList();
2363 bool InsetTabular::copySelection(BufferView * bv)
2365 if (!hasSelection())
2368 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2369 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2370 if (sel_col_start > sel_col_end) {
2371 sel_col_start = sel_col_end;
2372 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2374 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2376 int const columns = sel_col_end - sel_col_start + 1;
2378 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2379 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2380 if (sel_row_start > sel_row_end) {
2381 swap(sel_row_start, sel_row_end);
2383 int const rows = sel_row_end - sel_row_start + 1;
2385 delete paste_tabular;
2386 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2387 for (int i = 0; i < sel_row_start; ++i)
2388 paste_tabular->DeleteRow(0);
2389 while (paste_tabular->rows() > rows)
2390 paste_tabular->DeleteRow(rows);
2391 paste_tabular->SetTopLine(0, true, true);
2392 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2394 for (int i = 0; i < sel_col_start; ++i)
2395 paste_tabular->DeleteColumn(0);
2396 while (paste_tabular->columns() > columns)
2397 paste_tabular->DeleteColumn(columns);
2398 paste_tabular->SetLeftLine(0, true, true);
2399 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2403 paste_tabular->ascii(bv->buffer(), sstr,
2404 (int)parOwner()->params().depth(), true, '\t');
2405 bv->stuffClipboard(sstr.str().c_str());
2410 bool InsetTabular::pasteSelection(BufferView * bv)
2415 for (int r1 = 0, r2 = actrow;
2416 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2418 for(int c1 = 0, c2 = actcol;
2419 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2421 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2422 tabular->IsPartOfMultiColumn(r2,c2))
2424 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2428 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2432 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2433 int const n2 = tabular->GetCellNumber(r2, c2);
2434 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2435 tabular->GetCellInset(n2)->setOwner(this);
2436 tabular->GetCellInset(n2)->deleteLyXText(bv);
2443 bool InsetTabular::cutSelection()
2445 if (!hasSelection())
2448 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2449 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2450 if (sel_col_start > sel_col_end) {
2451 sel_col_start = sel_col_end;
2452 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2454 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2456 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2457 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2458 if (sel_row_start > sel_row_end) {
2459 swap(sel_row_start, sel_row_end);
2461 if (sel_cell_start > sel_cell_end) {
2462 swap(sel_cell_start, sel_cell_end);
2464 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2465 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2466 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2473 bool InsetTabular::isRightToLeft(BufferView * bv)
2475 return bv->getParentLanguage(this)->RightToLeft();
2479 bool InsetTabular::nodraw() const
2481 if (!UpdatableInset::nodraw() && the_locking_inset)
2482 return the_locking_inset->nodraw();
2483 return UpdatableInset::nodraw();
2487 int InsetTabular::scroll(bool recursive) const
2489 int sx = UpdatableInset::scroll(false);
2491 if (recursive && the_locking_inset)
2492 sx += the_locking_inset->scroll(recursive);
2498 bool InsetTabular::doClearArea() const
2500 return !locked || (need_update & (FULL|INIT));
2504 void InsetTabular::getSelection(int & srow, int & erow,
2505 int & scol, int & ecol) const
2507 int const start = hasSelection() ? sel_cell_start : actcell;
2508 int const end = hasSelection() ? sel_cell_end : actcell;
2510 srow = tabular->row_of_cell(start);
2511 erow = tabular->row_of_cell(end);
2516 scol = tabular->column_of_cell(start);
2517 ecol = tabular->column_of_cell(end);
2521 ecol = tabular->right_column_of_cell(end);
2526 Paragraph * InsetTabular::getParFromID(int id) const
2529 for(int i = 0; i < tabular->rows(); ++i) {
2530 for(int j = 0; j < tabular->columns(); ++j) {
2531 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2539 Paragraph * InsetTabular::firstParagraph() const
2541 if (the_locking_inset)
2542 return the_locking_inset->firstParagraph();
2547 Paragraph * InsetTabular::getFirstParagraph(int i) const
2549 return (i < tabular->GetNumberOfCells())
2550 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2555 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2557 if (the_locking_inset)
2558 return the_locking_inset->cursor(bv);
2559 return Inset::cursor(bv);
2563 Inset * InsetTabular::getInsetFromID(int id_arg) const
2566 return const_cast<InsetTabular *>(this);
2569 for(int i = 0; i < tabular->rows(); ++i) {
2570 for(int j = 0; j < tabular->columns(); ++j) {
2571 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2580 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2583 if (the_locking_inset) {
2584 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2589 if (tabular->IsLastCell(actcell)) {
2590 bv->unlockInset(const_cast<InsetTabular *>(this));
2596 // otherwise we have to lock the next inset and ask for it's selecttion
2597 UpdatableInset * inset =
2598 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2599 inset->edit(bv, 0, 0, 0);
2600 string const str(selectNextWordInt(bv, value));
2608 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2610 // when entering this function the inset should be ALWAYS locked!
2611 lyx::Assert(the_locking_inset);
2613 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2617 if (tabular->IsLastCell(actcell)) {
2618 bv->unlockInset(const_cast<InsetTabular *>(this));
2622 // otherwise we have to lock the next inset and ask for it's selecttion
2623 UpdatableInset * inset =
2624 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2626 return selectNextWordInt(bv, value);
2630 void InsetTabular::selectSelectedWord(BufferView * bv)
2632 if (the_locking_inset) {
2633 the_locking_inset->selectSelectedWord(bv);
2640 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2642 if (the_locking_inset) {
2643 the_locking_inset->toggleSelection(bv, kill_selection);
2648 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2652 if (the_locking_inset) {
2653 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2655 updateLocal(bv, CELL, false);
2658 if (tabular->IsLastCell(actcell)) {
2660 bv->unlockInset(const_cast<InsetTabular *>(this));
2665 // otherwise we have to lock the next inset and search there
2666 UpdatableInset * inset =
2667 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2669 bool const ret = searchForward(bv, str, cs, mw);
2671 updateLocal(bv, CELL, false);
2676 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2680 if (the_locking_inset) {
2681 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2683 updateLocal(bv, CELL, false);
2686 if (!actcell) { // we are already in the first cell
2688 bv->unlockInset(const_cast<InsetTabular *>(this));
2693 // otherwise we have to lock the next inset and search there
2694 UpdatableInset * inset =
2695 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2696 inset->edit(bv, false);
2697 bool const ret = searchBackward(bv, str, cs, mw);
2699 updateLocal(bv, CELL, false);
2704 bool InsetTabular::insetAllowed(Inset::Code code) const
2706 if (the_locking_inset)
2707 return the_locking_inset->insetAllowed(code);
2712 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2714 const int cell = tabular->GetCellFromInset(in, actcell);
2717 return tabular->GetPWidth(cell).zero();
2719 // well we didn't obviously find it so maybe our owner knows more
2721 return owner()->forceDefaultParagraphs(in);
2722 // if we're here there is really something strange going on!!!