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"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::VALIGN_TOP, "valign-top" },
87 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
88 { LyXTabular::VALIGN_CENTER, "valign-center" },
89 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
90 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
91 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
92 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
93 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
94 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
95 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
96 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
97 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
98 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
99 { LyXTabular::MULTICOLUMN, "multicolumn" },
100 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
101 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
102 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
103 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
104 { LyXTabular::SET_PWIDTH, "set-pwidth" },
105 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
106 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
107 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
108 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
109 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
110 { LyXTabular::SET_USEBOX, "set-usebox" },
111 { LyXTabular::SET_LTHEAD, "set-lthead" },
112 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
113 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
114 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
115 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
116 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
117 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
118 { LyXTabular::LAST_ACTION, "" }
124 bool InsetTabular::hasPasteBuffer() const
126 return (paste_tabular != 0);
130 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
137 tabular.reset(new LyXTabular(this, rows, columns));
138 // for now make it always display as display() inset
140 the_locking_inset = 0;
141 old_locking_inset = 0;
144 actrow = actcell = 0;
148 in_reset_pos = false;
154 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
156 : UpdatableInset(tab, same_id), buffer(&buf)
158 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
159 the_locking_inset = 0;
160 old_locking_inset = 0;
163 actrow = actcell = 0;
167 in_reset_pos = false;
173 InsetTabular::~InsetTabular()
179 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
181 return new InsetTabular(*this, buf, same_id);
185 void InsetTabular::write(Buffer const * buf, ostream & os) const
187 os << " Tabular" << endl;
188 tabular->Write(buf, os);
192 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
194 bool const old_format = (lex.getString() == "\\LyXTable");
196 tabular.reset(new LyXTabular(buf, this, lex));
204 string token = lex.getString();
205 while (lex.isOK() && (token != "\\end_inset")) {
207 token = lex.getString();
209 if (token != "\\end_inset") {
210 lex.printError("Missing \\end_inset at this point. "
216 int InsetTabular::ascent(BufferView *, LyXFont const &) const
218 return tabular->GetAscentOfRow(0);
222 int InsetTabular::descent(BufferView *, LyXFont const &) const
224 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
228 int InsetTabular::width(BufferView *, LyXFont const &) const
230 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
234 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
235 float & x, bool cleared) const
243 if (need_update == INIT) {
244 if (calculate_dimensions_of_cells(bv, font, true))
245 bv->text->status = LyXText::CHANGED_IN_DRAW;
250 Painter & pain = bv->painter();
256 UpdatableInset::draw(bv, font, baseline, x, cleared);
259 x += static_cast<float>(scroll());
261 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
262 (top_x != int(x)) || (top_baseline != baseline)))
264 int h = ascent(bv, font) + descent(bv, font);
265 int const tx = display() || !owner() ? 0 : top_x;
266 int w = tx ? width(bv, font) : pain.paperWidth();
267 int ty = baseline - ascent(bv, font);
271 if ((ty + h) > pain.paperHeight())
272 h = pain.paperHeight();
273 if ((top_x + w) > pain.paperWidth())
274 w = pain.paperWidth();
275 pain.fillRectangle(tx, ty, w, h, backgroundColor());
281 top_baseline = baseline;
282 x += ADD_TO_TABULAR_WIDTH;
286 first_visible_cell = -1;
287 for (i = 0; i < tabular->rows(); ++i) {
289 cell = tabular->GetCellNumber(i, 0);
290 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
291 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
293 baseline += tabular->GetDescentOfRow(i) +
294 tabular->GetAscentOfRow(i + 1) +
295 tabular->GetAdditionalHeight(i + 1);
298 for (j = 0; j < tabular->columns(); ++j) {
299 if (nx > bv->workWidth())
301 if (tabular->IsPartOfMultiColumn(i, j))
303 cx = nx + tabular->GetBeginningOfTextInCell(cell);
304 if (first_visible_cell < 0)
305 first_visible_cell = cell;
306 if (hasSelection()) {
307 drawCellSelection(pain, nx, baseline, i, j, cell);
310 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
311 drawCellLines(pain, nx, baseline, i, cell);
312 nx += tabular->GetWidthOfColumn(cell);
315 baseline += tabular->GetDescentOfRow(i) +
316 tabular->GetAscentOfRow(i + 1) +
317 tabular->GetAdditionalHeight(i + 1);
319 } else if (need_update == CELL) {
322 if (the_locking_inset &&
323 tabular->GetCellInset(actcell) != the_locking_inset)
325 Inset * inset = tabular->GetCellInset(cell);
327 inset != the_locking_inset && i < tabular->rows();
331 inset != the_locking_inset && j < tabular->columns();
334 if (tabular->IsPartOfMultiColumn(i, j))
336 nx += tabular->GetWidthOfColumn(cell);
338 inset = tabular->GetCellInset(cell);
340 if (tabular->row_of_cell(cell) > i) {
342 baseline += tabular->GetDescentOfRow(i) +
343 tabular->GetAscentOfRow(i + 1) +
344 tabular->GetAdditionalHeight(i + 1);
348 // compute baseline for actual row
349 for (i = 0; i < actrow; ++i) {
350 baseline += tabular->GetDescentOfRow(i) +
351 tabular->GetAscentOfRow(i + 1) +
352 tabular->GetAdditionalHeight(i + 1);
354 // now compute the right x position
355 cell = tabular->GetCellNumber(actrow, 0);
356 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
357 if (tabular->IsPartOfMultiColumn(actrow, j))
359 nx += tabular->GetWidthOfColumn(cell);
363 i = tabular->row_of_cell(cell);
364 if (the_locking_inset != tabular->GetCellInset(cell)) {
365 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
368 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
370 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
372 // Here we use rectangular backgroundColor patches to clean up
373 // within a cell around the cell's red inset box. As follows:
376 // | | | | The rectangles are A, B and C
377 // | A |------------| B | below, origin top left (tx, ty),
378 // | | inset box | | dimensions w(idth), h(eight).
379 // +---+------------+---+ x grows rightward, y downward
381 // +--------------------+
383 // clear only if we didn't have a change
384 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
385 // clear before the inset
388 ty = baseline - tabular->GetAscentOfRow(i) + 1;
389 w = int(cx - nx - 1);
390 h = tabular->GetAscentOfRow(i) +
391 tabular->GetDescentOfRow(i) - 1;
392 pain.fillRectangle(tx, ty, w, h, backgroundColor());
393 // clear behind the inset
394 tx = int(cx + the_locking_inset->width(bv,font) + 1);
395 ty = baseline - tabular->GetAscentOfRow(i) + 1;
396 w = tabular->GetWidthOfColumn(cell) -
397 tabular->GetBeginningOfTextInCell(cell) -
398 the_locking_inset->width(bv,font) -
399 tabular->GetAdditionalWidth(cell) - 1;
400 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
401 pain.fillRectangle(tx, ty, w, h, backgroundColor());
402 // clear below the inset
404 ty = baseline + the_locking_inset->descent(bv, font) + 1;
405 w = tabular->GetWidthOfColumn(cell) -
406 tabular->GetAdditionalWidth(cell) - 1;
407 h = tabular->GetDescentOfRow(i) -
408 the_locking_inset->descent(bv, font) - 1;
409 pain.fillRectangle(tx, ty, w, h, backgroundColor());
412 x -= ADD_TO_TABULAR_WIDTH;
413 x += width(bv, font);
414 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
416 for(Inset * inset = owner(); inset; ++i)
417 inset = inset->owner();
418 if (calculate_dimensions_of_cells(bv, font, false))
426 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
427 int row, int cell) const
429 int x2 = x + tabular->GetWidthOfColumn(cell);
432 if (!tabular->TopAlreadyDrawed(cell)) {
433 on_off = !tabular->TopLine(cell);
434 pain.line(x, baseline - tabular->GetAscentOfRow(row),
435 x2, baseline - tabular->GetAscentOfRow(row),
436 on_off ? LColor::tabularonoffline : LColor::tabularline,
437 on_off ? Painter::line_onoffdash : Painter::line_solid);
439 on_off = !tabular->BottomLine(cell);
440 pain.line(x,baseline + tabular->GetDescentOfRow(row),
441 x2, baseline + tabular->GetDescentOfRow(row),
442 on_off ? LColor::tabularonoffline : LColor::tabularline,
443 on_off ? Painter::line_onoffdash : Painter::line_solid);
444 if (!tabular->LeftAlreadyDrawed(cell)) {
445 on_off = !tabular->LeftLine(cell);
446 pain.line(x, baseline - tabular->GetAscentOfRow(row),
447 x, baseline + tabular->GetDescentOfRow(row),
448 on_off ? LColor::tabularonoffline : LColor::tabularline,
449 on_off ? Painter::line_onoffdash : Painter::line_solid);
451 on_off = !tabular->RightLine(cell);
452 pain.line(x2 - tabular->GetAdditionalWidth(cell),
453 baseline - tabular->GetAscentOfRow(row),
454 x2 - tabular->GetAdditionalWidth(cell),
455 baseline + tabular->GetDescentOfRow(row),
456 on_off ? LColor::tabularonoffline : LColor::tabularline,
457 on_off ? Painter::line_onoffdash : Painter::line_solid);
461 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
462 int row, int column, int cell) const
464 lyx::Assert(hasSelection());
465 int cs = tabular->column_of_cell(sel_cell_start);
466 int ce = tabular->column_of_cell(sel_cell_end);
469 cs = tabular->column_of_cell(sel_cell_end);
471 ce = tabular->right_column_of_cell(sel_cell_end);
474 int rs = tabular->row_of_cell(sel_cell_start);
475 int re = tabular->row_of_cell(sel_cell_end);
479 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
480 int w = tabular->GetWidthOfColumn(cell);
481 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
482 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
483 w, h, LColor::selection);
488 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
494 owner()->update(bv, font, true);
501 if (calculate_dimensions_of_cells(bv, font, true))
504 owner()->update(bv, font, true);
508 if (the_locking_inset)
509 the_locking_inset->update(bv, font, reinit);
510 if (need_update < FULL &&
511 bv->text->status() == LyXText::NEED_MORE_REFRESH)
516 switch (need_update) {
520 if (calculate_dimensions_of_cells(bv, font, false))
533 string const InsetTabular::editMessage() const
535 return _("Opened Tabular Inset");
539 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
541 UpdatableInset::edit(bv, x, y, button);
543 if (!bv->lockInset(this)) {
544 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
548 the_locking_inset = 0;
554 if (insetHit(bv, x, y) && (button != 3)) {
555 activateCellInsetAbs(bv, x, y, button);
560 void InsetTabular::edit(BufferView * bv, bool front)
562 UpdatableInset::edit(bv, front);
564 if (!bv->lockInset(this)) {
565 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
569 the_locking_inset = 0;
575 actcell = tabular->GetNumberOfCells() - 1;
582 void InsetTabular::insetUnlock(BufferView * bv)
584 if (the_locking_inset) {
585 the_locking_inset->insetUnlock(bv);
586 the_locking_inset = 0;
591 if (scroll(false) || hasSelection()) {
596 updateLocal(bv, FULL, false);
601 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
602 bool mark_dirty) const
606 calculate_dimensions_of_cells(bv, font, true);
608 if (need_update < what) // only set this if it has greater update
610 if ((what == INIT) && hasSelection()) {
614 if (need_update != NONE) {
615 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
616 if (locked) // && (what != NONE))
622 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
624 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
629 if (inset == tabular->GetCellInset(actcell)) {
630 lyxerr[Debug::INSETTEXT] << "OK" << endl;
631 the_locking_inset = tabular->GetCellInset(actcell);
634 } else if (!the_locking_inset) {
635 int const n = tabular->GetNumberOfCells();
636 int const id = inset->id();
637 for (int i = 0; i < n; ++i) {
638 InsetText * in = tabular->GetCellInset(i);
641 the_locking_inset = in;
646 if (in->getInsetFromID(id)) {
649 // the_locking_inset = in;
652 return the_locking_inset->lockInsetInInset(bv, inset);
655 } else if (the_locking_inset && (the_locking_inset == inset)) {
656 lyxerr[Debug::INSETTEXT] << "OK" << endl;
658 } else if (the_locking_inset) {
659 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
660 return the_locking_inset->lockInsetInInset(bv, inset);
662 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
667 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
670 if (!the_locking_inset)
672 if (the_locking_inset == inset) {
673 the_locking_inset->insetUnlock(bv);
674 the_locking_inset = 0;
676 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
682 updateLocal(bv, CELL, false);
683 showInsetCursor(bv, false);
686 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
687 if (inset->lyxCode() == TABULAR_CODE &&
688 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
689 bv->owner()->getDialogs()->updateTabular(this);
698 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
700 if (!the_locking_inset)
702 if (the_locking_inset != inset) {
703 if (!the_locking_inset->updateInsetInInset(bv, inset))
706 updateLocal(bv, CELL, false);
711 unsigned int InsetTabular::insetInInsetY()
713 if (!the_locking_inset)
715 return inset_y + the_locking_inset->insetInInsetY();
719 UpdatableInset * InsetTabular::getLockingInset() const
721 return the_locking_inset ? the_locking_inset->getLockingInset() :
722 const_cast<InsetTabular *>(this);
726 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
730 if (the_locking_inset)
731 return the_locking_inset->getFirstLockingInsetOfType(c);
736 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
738 if (the_locking_inset)
739 return the_locking_inset->insertInset(bv, inset);
744 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
746 if (hasSelection() && (button == 3))
749 if (hasSelection()) {
751 updateLocal(bv, SELECTION, false);
754 int const ocell = actcell;
755 int const orow = actrow;
760 updateLocal(bv, NONE, false);
764 if ((ocell != actcell) && the_locking_inset) {
765 the_locking_inset->insetUnlock(bv);
766 the_locking_inset = 0;
773 bool const inset_hit = insetHit(bv, x, y);
775 if ((ocell == actcell) && the_locking_inset && inset_hit) {
777 the_locking_inset->insetButtonPress(bv,
778 x - inset_x, y - inset_y,
781 } else if (the_locking_inset) {
782 the_locking_inset->insetUnlock(bv);
784 the_locking_inset = 0;
786 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
789 if (inset_hit && bv->theLockingInset()) {
790 if (activateCellInsetAbs(bv, x, y, button))
791 the_locking_inset->insetButtonPress(bv,
801 bool InsetTabular::insetButtonRelease(BufferView * bv,
802 int x, int y, int button)
805 if (the_locking_inset)
806 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
807 y - inset_y, button);
808 if (button == 3 && !ret) {
809 bv->owner()->getDialogs()->showTabular(this);
816 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
818 if (the_locking_inset) {
819 the_locking_inset->insetMotionNotify(bv,
827 // int const old_cell = actcell;
830 if (!hasSelection()) {
831 setSelection(actcell, actcell);
833 setSelection(sel_cell_start, actcell);
835 updateLocal(bv, SELECTION, false);
840 void InsetTabular::insetKeyPress(XKeyEvent * xke)
842 if (the_locking_inset) {
843 the_locking_inset->insetKeyPress(xke);
849 UpdatableInset::RESULT
850 InsetTabular::localDispatch(BufferView * bv, kb_action action,
853 // We need to save the value of the_locking_inset as the call to
854 // the_locking_inset->LocalDispatch might unlock it.
855 old_locking_inset = the_locking_inset;
856 UpdatableInset::RESULT result =
857 UpdatableInset::localDispatch(bv, action, arg);
858 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
863 if ((action < 0) && arg.empty())
866 bool hs = hasSelection();
869 // this one have priority over the locked InsetText, if we're not already
870 // inside another tabular then that one get's priority!
871 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
876 unlockInsetInInset(bv, the_locking_inset);
877 if (action == LFUN_TAB)
878 moveNextCell(bv, old_locking_inset != 0);
880 movePrevCell(bv, old_locking_inset != 0);
883 updateLocal(bv, SELECTION, false);
884 if (!the_locking_inset) {
886 return DISPATCHED_NOUPDATE;
889 // this to avoid compiler warnings.
895 if (the_locking_inset) {
896 result = the_locking_inset->localDispatch(bv, action, arg);
897 if (result == DISPATCHED_NOUPDATE) {
900 if (sc != scroll()) { // inset has been scrolled
901 the_locking_inset->toggleInsetCursor(bv);
902 updateLocal(bv, FULL, false);
903 the_locking_inset->toggleInsetCursor(bv);
906 } else if (result == DISPATCHED) {
907 the_locking_inset->toggleInsetCursor(bv);
908 updateLocal(bv, CELL, false);
909 the_locking_inset->toggleInsetCursor(bv);
911 } else if (result == FINISHED_UP) {
913 } else if (result == FINISHED_DOWN) {
915 } else if (result == FINISHED_RIGHT) {
923 // --- Cursor Movements ----------------------------------
924 case LFUN_RIGHTSEL: {
925 int const start = hasSelection() ? sel_cell_start : actcell;
926 if (tabular->IsLastCellInRow(actcell)) {
927 setSelection(start, actcell);
932 // if we are starting a selection, only select
933 // the current cell at the beginning
934 if (hasSelection()) {
935 moveRight(bv, false);
938 setSelection(start, end);
939 updateLocal(bv, SELECTION, false);
943 result = moveRight(bv);
946 updateLocal(bv, SELECTION, false);
949 int const start = hasSelection() ? sel_cell_start : actcell;
950 if (tabular->IsFirstCellInRow(actcell)) {
951 setSelection(start, actcell);
956 // if we are starting a selection, only select
957 // the current cell at the beginning
958 if (hasSelection()) {
962 setSelection(start, end);
963 updateLocal(bv, SELECTION, false);
967 result = moveLeft(bv);
970 updateLocal(bv, SELECTION, false);
973 int const start = hasSelection() ? sel_cell_start : actcell;
974 int const ocell = actcell;
975 // if we are starting a selection, only select
976 // the current cell at the beginning
977 if (hasSelection()) {
979 if ((ocell == sel_cell_end) ||
980 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
981 setSelection(start, tabular->GetCellBelow(sel_cell_end));
983 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
985 setSelection(start, start);
987 updateLocal(bv, SELECTION, false);
991 result = moveDown(bv, old_locking_inset != 0);
994 updateLocal(bv, SELECTION, false);
998 int const start = hasSelection() ? sel_cell_start : actcell;
999 int const ocell = actcell;
1000 // if we are starting a selection, only select
1001 // the current cell at the beginning
1002 if (hasSelection()) {
1004 if ((ocell == sel_cell_end) ||
1005 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1006 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1008 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1010 setSelection(start, start);
1012 updateLocal(bv, SELECTION, false);
1016 result = moveUp(bv, old_locking_inset != 0);
1019 updateLocal(bv, SELECTION, false);
1022 int column = actcol;
1023 unlockInsetInInset(bv, the_locking_inset);
1024 if (bv->text->first + bv->painter().paperHeight() <
1025 (top_baseline + tabular->GetHeightOfTabular()))
1027 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1028 updateLocal(bv, FULL, false);
1029 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1031 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1034 updateLocal(bv, CURSOR, false);
1038 int column = actcol;
1039 unlockInsetInInset(bv, the_locking_inset);
1040 if (top_baseline < 0) {
1041 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1042 updateLocal(bv, FULL, false);
1043 if (top_baseline > 0)
1046 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1051 updateLocal(bv, CURSOR, false);
1054 // none of these make sense for insettabular,
1055 // but we must catch them to prevent any
1056 // selection from being confused
1060 case LFUN_WORDLEFTSEL:
1061 case LFUN_WORDRIGHT:
1062 case LFUN_WORDRIGHTSEL:
1063 case LFUN_DOWN_PARAGRAPH:
1064 case LFUN_DOWN_PARAGRAPHSEL:
1065 case LFUN_UP_PARAGRAPH:
1066 case LFUN_UP_PARAGRAPHSEL:
1067 case LFUN_BACKSPACE:
1073 case LFUN_BEGINNINGBUF:
1074 case LFUN_BEGINNINGBUFSEL:
1076 case LFUN_ENDBUFSEL:
1078 case LFUN_LAYOUT_TABULAR:
1079 bv->owner()->getDialogs()->showTabular(this);
1081 case LFUN_TABULAR_FEATURE:
1082 if (!tabularFeatures(bv, arg))
1083 result = UNDISPATCHED;
1086 if (!copySelection(bv))
1088 setUndo(bv, Undo::DELETE,
1089 bv->text->cursor.par(),
1090 bv->text->cursor.par()->next());
1092 updateLocal(bv, INIT, true);
1095 if (!hasSelection())
1100 case LFUN_PASTESELECTION:
1102 string const clip(bv->getClipboard());
1106 if (clip.find('\t') != string::npos) {
1110 string::size_type len = clip.length();
1111 string::size_type p = 0;
1114 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1122 maxCols = max(cols, maxCols);
1128 maxCols = max(cols, maxCols);
1129 delete paste_tabular;
1130 paste_tabular = new LyXTabular(this, rows, maxCols);
1131 string::size_type op = 0;
1133 int cells = paste_tabular->GetNumberOfCells();
1135 while ((cell < cells) && (p < len) &&
1136 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1141 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1146 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1147 while (cols++ < maxCols)
1155 // check for the last cell if there is no trailing '\n'
1156 if ((cell < cells) && (op < len))
1157 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1159 // so that the clipboard is used and it goes on
1161 // and executes LFUN_PASTESELECTION in insettext!
1162 delete paste_tabular;
1167 if (hasPasteBuffer()) {
1168 setUndo(bv, Undo::INSERT,
1169 bv->text->cursor.par(),
1170 bv->text->cursor.par()->next());
1172 updateLocal(bv, INIT, true);
1175 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1177 // we try to activate the actual inset and put this event down to
1178 // the insets dispatch function.
1179 result = UNDISPATCHED;
1180 if (the_locking_inset)
1183 if (activateCellInset(bv)) {
1184 // reset need_update setted in above function!
1186 result = the_locking_inset->localDispatch(bv, action, arg);
1187 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1188 unlockInsetInInset(bv, the_locking_inset);
1190 // we need to update if this was requested before
1191 updateLocal(bv, NONE, false);
1192 return UNDISPATCHED;
1197 updateLocal(bv, CELL, false);
1202 if (result < FINISHED) {
1203 if (!the_locking_inset) {
1204 showInsetCursor(bv);
1207 bv->unlockInset(this);
1212 int InsetTabular::latex(Buffer const * buf, ostream & os,
1213 bool fragile, bool fp) const
1215 return tabular->latex(buf, os, fragile, fp);
1219 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1222 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1224 return tabular->ascii(buf, os, 0, false,0);
1228 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1231 int const ret = tabular->ascii(buf,os,
1232 (int)parOwner()->params().depth(),
1239 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1244 // if the table is inside a float it doesn't need the informaltable
1245 // wrapper. Search for it.
1246 for(master = owner();
1247 master && master->lyxCode() != Inset::FLOAT_CODE;
1248 master = master->owner());
1251 os << "<informaltable>\n";
1254 ret+= tabular->docBook(buf,os);
1256 os << "</informaltable>\n";
1263 void InsetTabular::validate(LaTeXFeatures & features) const
1265 tabular->Validate(features);
1269 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1270 LyXFont const & font,
1277 bool changed = false;
1279 // if we have a locking_inset we should have to check only this cell for
1280 // change so I'll try this to have a boost, but who knows ;)
1281 if ((need_update != INIT) &&
1282 (the_locking_inset == tabular->GetCellInset(actcell))) {
1283 for(int i = 0; i < tabular->columns(); ++i) {
1284 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1286 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1289 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1290 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1291 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1294 for (int i = 0; i < tabular->rows(); ++i) {
1297 for (int j = 0; j < tabular->columns(); ++j) {
1298 if (tabular->IsPartOfMultiColumn(i,j))
1301 inset = tabular->GetCellInset(cell);
1302 if (!reinit && !tabular->GetPWidth(cell).zero())
1303 inset->update(bv, font, false);
1304 maxAsc = max(maxAsc, inset->ascent(bv, font));
1305 maxDesc = max(maxDesc, inset->descent(bv, font));
1306 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1308 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1309 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1317 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1319 if (the_locking_inset) {
1320 the_locking_inset->getCursorPos(bv, x, y);
1323 x = cursor_.x() - top_x;
1328 void InsetTabular::toggleInsetCursor(BufferView * bv)
1331 if (isCursorVisible())
1332 bv->hideLockedInsetCursor();
1335 if (the_locking_inset) {
1336 the_locking_inset->toggleInsetCursor(bv);
1340 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1342 int const asc = lyxfont::maxAscent(font);
1343 int const desc = lyxfont::maxDescent(font);
1345 if (isCursorVisible())
1346 bv->hideLockedInsetCursor();
1348 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1349 toggleCursorVisible();
1353 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1357 if (!isCursorVisible()) {
1358 LyXFont font; // = GetFont(par, cursor.pos);
1360 int const asc = lyxfont::maxAscent(font);
1361 int const desc = lyxfont::maxDescent(font);
1362 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1364 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1365 setCursorVisible(true);
1370 void InsetTabular::hideInsetCursor(BufferView * bv)
1372 if (isCursorVisible()) {
1373 bv->hideLockedInsetCursor();
1374 setCursorVisible(false);
1379 void InsetTabular::fitInsetCursor(BufferView * bv) const
1381 if (the_locking_inset) {
1382 the_locking_inset->fitInsetCursor(bv);
1387 int const asc = lyxfont::maxAscent(font);
1388 int const desc = lyxfont::maxDescent(font);
1389 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1393 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1397 actcell = actrow = actcol = 0;
1398 int ly = tabular->GetDescentOfRow(actrow);
1400 // first search the right row
1401 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1402 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1403 tabular->GetAscentOfRow(actrow + 1) +
1404 tabular->GetAdditionalHeight(actrow + 1));
1406 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1408 actcell = tabular->GetCellNumber(actrow, actcol);
1410 // now search the right column
1411 int lx = tabular->GetWidthOfColumn(actcell) -
1412 tabular->GetAdditionalWidth(actcell);
1413 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1414 lx += tabular->GetWidthOfColumn(actcell + 1)
1415 + tabular->GetAdditionalWidth(actcell);
1417 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1422 int InsetTabular::getCellXPos(int cell) const
1426 for (; !tabular->IsFirstCellInRow(c); --c)
1428 int lx = tabular->GetWidthOfColumn(cell);
1429 for (; c < cell; ++c) {
1430 lx += tabular->GetWidthOfColumn(c);
1432 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1436 void InsetTabular::resetPos(BufferView * bv) const
1438 #warning This should be fixed in the right manner (20011128 Jug)
1439 // fast hack to fix infinite repaintings!
1444 actcol = tabular->column_of_cell(actcell);
1447 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1448 if (tabular->IsLastCellInRow(cell)) {
1449 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1450 tabular->GetAscentOfRow(actrow + 1) +
1451 tabular->GetAdditionalHeight(actrow + 1));
1455 if (!locked || nodraw()) {
1456 if (the_locking_inset)
1457 inset_y = cursor_.y();
1460 // we need this only from here on!!!
1461 in_reset_pos = true;
1462 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1463 int new_x = getCellXPos(actcell);
1464 int old_x = cursor_.x();
1467 // cursor.x(getCellXPos(actcell) + offset);
1468 if ((actcol < tabular->columns()-1) && scroll(false) &&
1469 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1472 updateLocal(bv, FULL, false);
1473 } else if (the_locking_inset &&
1474 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1476 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1477 if (xx > (bv->workWidth()-20)) {
1478 scroll(bv, -(xx - bv->workWidth() + 60));
1479 updateLocal(bv, FULL, false);
1480 } else if (xx < 20) {
1486 updateLocal(bv, FULL, false);
1488 } else if ((cursor_.x() - offset) > 20 &&
1489 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1490 > (bv->workWidth() - 20)) {
1491 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1492 updateLocal(bv, FULL, false);
1493 } else if ((cursor_.x() - offset) < 20) {
1494 scroll(bv, 20 - cursor_.x() + offset);
1495 updateLocal(bv, FULL, false);
1496 } else if (scroll(false) && top_x > 20 &&
1497 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1498 scroll(bv, old_x - cursor_.x());
1499 updateLocal(bv, FULL, false);
1501 if (the_locking_inset) {
1502 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1503 inset_y = cursor_.y();
1505 if ((!the_locking_inset ||
1506 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1507 actcell != oldcell) {
1508 InsetTabular * inset = const_cast<InsetTabular *>(this);
1509 bv->owner()->getDialogs()->updateTabular(inset);
1512 in_reset_pos = false;
1516 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1518 if (lock && !old_locking_inset) {
1519 if (activateCellInset(bv))
1522 bool moved = isRightToLeft(bv)
1523 ? movePrevCell(bv) : moveNextCell(bv);
1525 return FINISHED_RIGHT;
1526 if (lock && activateCellInset(bv))
1530 return DISPATCHED_NOUPDATE;
1534 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1536 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1539 if (lock) { // behind the inset
1540 if (activateCellInset(bv, 0, 0, 0, true))
1544 return DISPATCHED_NOUPDATE;
1548 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1550 int const ocell = actcell;
1551 actcell = tabular->GetCellAbove(actcell);
1552 if (actcell == ocell) // we moved out of the inset
1558 if (old_locking_inset) {
1559 old_locking_inset->getCursorPos(bv, x, y);
1560 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1562 if (activateCellInset(bv, x, 0))
1565 return DISPATCHED_NOUPDATE;
1569 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1571 int const ocell = actcell;
1572 actcell = tabular->GetCellBelow(actcell);
1573 if (actcell == ocell) // we moved out of the inset
1574 return FINISHED_DOWN;
1579 if (old_locking_inset) {
1580 old_locking_inset->getCursorPos(bv, x, y);
1581 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1583 if (activateCellInset(bv, x, 0))
1586 return DISPATCHED_NOUPDATE;
1590 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1592 if (isRightToLeft(bv)) {
1593 if (tabular->IsFirstCellInRow(actcell)) {
1594 int row = tabular->row_of_cell(actcell);
1595 if (row == tabular->rows() - 1)
1597 actcell = tabular->GetLastCellInRow(row);
1598 actcell = tabular->GetCellBelow(actcell);
1605 if (tabular->IsLastCell(actcell))
1610 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1611 isRightToLeftPar(bv->buffer()->params);
1612 activateCellInset(bv, 0, 0, 0, !rtl);
1619 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1621 if (isRightToLeft(bv)) {
1622 if (tabular->IsLastCellInRow(actcell)) {
1623 int row = tabular->row_of_cell(actcell);
1626 actcell = tabular->GetFirstCellInRow(row);
1627 actcell = tabular->GetCellAbove(actcell);
1629 if (tabular->IsLastCell(actcell))
1634 if (!actcell) // first cell
1639 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1640 isRightToLeftPar(bv->buffer()->params);
1641 activateCellInset(bv, 0, 0, 0, !rtl);
1648 bool InsetTabular::deletable() const
1654 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1658 setSelection(0, tabular->GetNumberOfCells() - 1);
1660 if (hasSelection()) {
1661 setUndo(bv, Undo::EDIT,
1662 bv->text->cursor.par(),
1663 bv->text->cursor.par()->next());
1664 bool frozen = undo_frozen;
1667 // apply the fontchange on the whole selection
1672 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1673 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1674 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1675 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1680 updateLocal(bv, INIT, true);
1682 if (the_locking_inset)
1683 the_locking_inset->setFont(bv, font, tall);
1687 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1689 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1692 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1693 string const tmp = tabularFeature[i].feature;
1695 if (tmp == what.substr(0, tmp.length())) {
1696 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1697 //tabularFeatures[i].feature.length())) {
1698 action = tabularFeature[i].action;
1702 if (action == LyXTabular::LAST_ACTION)
1706 frontStrip(what.substr(tabularFeature[i].feature.length()));
1707 tabularFeatures(bv, action, val);
1711 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1712 string const & special, bool & flag)
1714 if (special == "dl_above") {
1717 } else if (special == "dl_below") {
1718 ltt.bottomDL = flag;
1720 } else if (special == "empty") {
1730 void InsetTabular::tabularFeatures(BufferView * bv,
1731 LyXTabular::Feature feature,
1732 string const & value)
1738 bool setLines = false;
1739 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1740 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1743 case LyXTabular::M_ALIGN_LEFT:
1744 case LyXTabular::ALIGN_LEFT:
1745 setAlign = LYX_ALIGN_LEFT;
1747 case LyXTabular::M_ALIGN_RIGHT:
1748 case LyXTabular::ALIGN_RIGHT:
1749 setAlign = LYX_ALIGN_RIGHT;
1751 case LyXTabular::M_ALIGN_CENTER:
1752 case LyXTabular::ALIGN_CENTER:
1753 setAlign = LYX_ALIGN_CENTER;
1755 case LyXTabular::M_VALIGN_TOP:
1756 case LyXTabular::VALIGN_TOP:
1757 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1759 case LyXTabular::M_VALIGN_BOTTOM:
1760 case LyXTabular::VALIGN_BOTTOM:
1761 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1763 case LyXTabular::M_VALIGN_CENTER:
1764 case LyXTabular::VALIGN_CENTER:
1765 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1770 if (hasSelection()) {
1771 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1773 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1774 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1776 setUndo(bv, Undo::FINISH,
1777 bv->text->cursor.par(),
1778 bv->text->cursor.par()->next());
1780 int row = tabular->row_of_cell(actcell);
1781 int column = tabular->column_of_cell(actcell);
1783 LyXTabular::ltType ltt;
1786 case LyXTabular::SET_PWIDTH:
1788 LyXLength const vallen(value);
1789 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1791 bool const update = (tmplen != vallen);
1792 tabular->SetColumnPWidth(actcell, vallen);
1795 for (int i = 0; i < tabular->rows(); ++i) {
1796 cell = tabular->GetCellNumber(i,column);
1797 tabular->GetCellInset(cell)->resizeLyXText(bv);
1799 updateLocal(bv, INIT, true);
1803 case LyXTabular::SET_MPWIDTH:
1805 LyXLength const vallen(value);
1806 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1808 bool const update = (tmplen != vallen);
1809 tabular->SetMColumnPWidth(actcell, vallen);
1811 for (int i = 0; i < tabular->rows(); ++i) {
1812 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1815 updateLocal(bv, INIT, true);
1819 case LyXTabular::SET_SPECIAL_COLUMN:
1820 case LyXTabular::SET_SPECIAL_MULTI:
1821 tabular->SetAlignSpecial(actcell,value,feature);
1822 updateLocal(bv, FULL, true);
1824 case LyXTabular::APPEND_ROW:
1825 // append the row into the tabular
1826 unlockInsetInInset(bv, the_locking_inset);
1827 tabular->AppendRow(actcell);
1828 updateLocal(bv, INIT, true);
1830 case LyXTabular::APPEND_COLUMN:
1831 // append the column into the tabular
1832 unlockInsetInInset(bv, the_locking_inset);
1833 tabular->AppendColumn(actcell);
1834 actcell = tabular->GetCellNumber(row, column);
1835 updateLocal(bv, INIT, true);
1837 case LyXTabular::DELETE_ROW:
1838 unlockInsetInInset(bv, the_locking_inset);
1839 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1840 tabular->DeleteRow(sel_row_start);
1842 if (sel_row_start >= tabular->rows())
1844 actcell = tabular->GetCellNumber(sel_row_start, column);
1846 updateLocal(bv, INIT, true);
1848 case LyXTabular::DELETE_COLUMN:
1849 unlockInsetInInset(bv, the_locking_inset);
1850 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1851 tabular->DeleteColumn(sel_col_start);
1853 if (sel_col_start >= tabular->columns())
1855 actcell = tabular->GetCellNumber(row, sel_col_start);
1857 updateLocal(bv, INIT, true);
1859 case LyXTabular::M_TOGGLE_LINE_TOP:
1861 case LyXTabular::TOGGLE_LINE_TOP:
1863 bool lineSet = !tabular->TopLine(actcell, flag);
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->SetTopLine(
1867 tabular->GetCellNumber(i, j),
1869 updateLocal(bv, INIT, true);
1873 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1875 case LyXTabular::TOGGLE_LINE_BOTTOM:
1877 bool lineSet = !tabular->BottomLine(actcell, flag);
1878 for (int i = sel_row_start; i <= sel_row_end; ++i)
1879 for (int j = sel_col_start; j <= sel_col_end; ++j)
1880 tabular->SetBottomLine(
1881 tabular->GetCellNumber(i, j),
1884 updateLocal(bv, INIT, true);
1888 case LyXTabular::M_TOGGLE_LINE_LEFT:
1890 case LyXTabular::TOGGLE_LINE_LEFT:
1892 bool lineSet = !tabular->LeftLine(actcell, flag);
1893 for (int i = sel_row_start; i <= sel_row_end; ++i)
1894 for (int j = sel_col_start; j <= sel_col_end; ++j)
1895 tabular->SetLeftLine(
1896 tabular->GetCellNumber(i,j),
1899 updateLocal(bv, INIT, true);
1903 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1905 case LyXTabular::TOGGLE_LINE_RIGHT:
1907 bool lineSet = !tabular->RightLine(actcell, flag);
1908 for (int i = sel_row_start; i <= sel_row_end; ++i)
1909 for (int j = sel_col_start; j <= sel_col_end; ++j)
1910 tabular->SetRightLine(
1911 tabular->GetCellNumber(i,j),
1914 updateLocal(bv, INIT, true);
1918 case LyXTabular::M_ALIGN_LEFT:
1919 case LyXTabular::M_ALIGN_RIGHT:
1920 case LyXTabular::M_ALIGN_CENTER:
1922 case LyXTabular::ALIGN_LEFT:
1923 case LyXTabular::ALIGN_RIGHT:
1924 case LyXTabular::ALIGN_CENTER:
1925 for (int i = sel_row_start; i <= sel_row_end; ++i)
1926 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular->SetAlignment(
1928 tabular->GetCellNumber(i, j),
1931 updateLocal(bv, INIT, true);
1933 case LyXTabular::M_VALIGN_TOP:
1934 case LyXTabular::M_VALIGN_BOTTOM:
1935 case LyXTabular::M_VALIGN_CENTER:
1937 case LyXTabular::VALIGN_TOP:
1938 case LyXTabular::VALIGN_BOTTOM:
1939 case LyXTabular::VALIGN_CENTER:
1940 for (int i = sel_row_start; i <= sel_row_end; ++i)
1941 for (int j = sel_col_start; j <= sel_col_end; ++j)
1942 tabular->SetVAlignment(
1943 tabular->GetCellNumber(i, j),
1945 updateLocal(bv, INIT, true);
1947 case LyXTabular::MULTICOLUMN:
1949 if (sel_row_start != sel_row_end) {
1950 Alert::alert(_("Impossible Operation!"),
1951 _("Multicolumns can only be horizontally."),
1955 // just multicol for one Single Cell
1956 if (!hasSelection()) {
1957 // check wether we are completly in a multicol
1958 if (tabular->IsMultiColumn(actcell)) {
1959 tabular->UnsetMultiColumn(actcell);
1960 updateLocal(bv, INIT, true);
1962 tabular->SetMultiColumn(actcell, 1);
1963 updateLocal(bv, CELL, true);
1967 // we have a selection so this means we just add all this
1968 // cells to form a multicolumn cell
1972 if (sel_cell_start > sel_cell_end) {
1973 s_start = sel_cell_end;
1974 s_end = sel_cell_start;
1976 s_start = sel_cell_start;
1977 s_end = sel_cell_end;
1979 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1982 updateLocal(bv, INIT, true);
1985 case LyXTabular::SET_ALL_LINES:
1987 case LyXTabular::UNSET_ALL_LINES:
1988 for (int i = sel_row_start; i <= sel_row_end; ++i)
1989 for (int j = sel_col_start; j <= sel_col_end; ++j)
1990 tabular->SetAllLines(
1991 tabular->GetCellNumber(i,j), setLines);
1992 updateLocal(bv, INIT, true);
1994 case LyXTabular::SET_LONGTABULAR:
1995 tabular->SetLongTabular(true);
1996 updateLocal(bv, INIT, true); // because this toggles displayed
1998 case LyXTabular::UNSET_LONGTABULAR:
1999 tabular->SetLongTabular(false);
2000 updateLocal(bv, INIT, true); // because this toggles displayed
2002 case LyXTabular::SET_ROTATE_TABULAR:
2003 tabular->SetRotateTabular(true);
2005 case LyXTabular::UNSET_ROTATE_TABULAR:
2006 tabular->SetRotateTabular(false);
2008 case LyXTabular::SET_ROTATE_CELL:
2009 for (int i = sel_row_start; i <= sel_row_end; ++i)
2010 for (int j = sel_col_start; j<=sel_col_end; ++j)
2011 tabular->SetRotateCell(
2012 tabular->GetCellNumber(i, j),
2015 case LyXTabular::UNSET_ROTATE_CELL:
2016 for (int i = sel_row_start; i <= sel_row_end; ++i)
2017 for (int j = sel_col_start; j <= sel_col_end; ++j)
2018 tabular->SetRotateCell(
2019 tabular->GetCellNumber(i, j), false);
2021 case LyXTabular::SET_USEBOX:
2023 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2024 if (val == tabular->GetUsebox(actcell))
2025 val = LyXTabular::BOX_NONE;
2026 for (int i = sel_row_start; i <= sel_row_end; ++i)
2027 for (int j = sel_col_start; j <= sel_col_end; ++j)
2029 tabular->GetCellNumber(i, j), val);
2032 case LyXTabular::UNSET_LTFIRSTHEAD:
2034 case LyXTabular::SET_LTFIRSTHEAD:
2035 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2036 checkLongtableSpecial(ltt, value, flag);
2037 tabular->SetLTHead(row, flag, ltt, true);
2039 case LyXTabular::UNSET_LTHEAD:
2041 case LyXTabular::SET_LTHEAD:
2042 (void)tabular->GetRowOfLTHead(row, ltt);
2043 checkLongtableSpecial(ltt, value, flag);
2044 tabular->SetLTHead(row, flag, ltt, false);
2046 case LyXTabular::UNSET_LTFOOT:
2048 case LyXTabular::SET_LTFOOT:
2049 (void)tabular->GetRowOfLTFoot(row, ltt);
2050 checkLongtableSpecial(ltt, value, flag);
2051 tabular->SetLTFoot(row, flag, ltt, false);
2053 case LyXTabular::UNSET_LTLASTFOOT:
2055 case LyXTabular::SET_LTLASTFOOT:
2056 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2057 checkLongtableSpecial(ltt, value, flag);
2058 tabular->SetLTFoot(row, flag, ltt, true);
2060 case LyXTabular::SET_LTNEWPAGE:
2062 bool what = !tabular->GetLTNewPage(row);
2063 tabular->SetLTNewPage(row, what);
2066 // dummy stuff just to avoid warnings
2067 case LyXTabular::LAST_ACTION:
2073 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2076 UpdatableInset * inset =
2077 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2078 LyXFont font(LyXFont::ALL_SANE);
2080 x = inset->x() + inset->width(bv, font);
2081 y = inset->descent(bv, font);
2083 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2084 //inset_y = cursor.y();
2085 inset->edit(bv, x, y, button);
2086 if (!the_locking_inset)
2088 updateLocal(bv, CELL, false);
2089 return (the_locking_inset != 0);
2093 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2096 inset_x = cursor_.x()
2097 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2098 inset_y = cursor_.y();
2099 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2103 bool InsetTabular::insetHit(BufferView *, int x, int) const
2106 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2110 // This returns paperWidth() if the cell-width is unlimited or the width
2111 // in pixels if we have a pwidth for this cell.
2112 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2114 LyXLength const len = tabular->GetPWidth(cell);
2118 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2122 int InsetTabular::getMaxWidth(BufferView * bv,
2123 UpdatableInset const * inset) const
2125 int cell = tabular->GetCellFromInset(inset, actcell);
2128 lyxerr << "Own inset not found, shouldn't really happen!"
2133 int w = getMaxWidthOfCell(bv, cell);
2135 // because the inset then subtracts it's top_x and owner->x()
2136 w += (inset->x() - top_x);
2143 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2145 resizeLyXText(bv, recursive);
2149 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2152 for(int i = 0; i < tabular->rows(); ++i) {
2153 for(int j = 0; j < tabular->columns(); ++j) {
2154 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2162 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2163 bool const recursive) const
2165 if (the_locking_inset)
2166 return the_locking_inset->getLyXText(bv, recursive);
2168 // if we're locked lock the actual insettext and return it's LyXText!!!
2170 UpdatableInset * inset =
2171 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2172 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2173 return the_locking_inset->getLyXText(bv, recursive);
2176 return Inset::getLyXText(bv, recursive);
2180 bool InsetTabular::showInsetDialog(BufferView * bv) const
2182 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2183 bv->owner()->getDialogs()
2184 ->showTabular(const_cast<InsetTabular *>(this));
2189 void InsetTabular::openLayoutDialog(BufferView * bv) const
2191 if (the_locking_inset) {
2192 InsetTabular * i = static_cast<InsetTabular *>
2193 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2195 i->openLayoutDialog(bv);
2199 bv->owner()->getDialogs()->showTabular(
2200 const_cast<InsetTabular *>(this));
2205 // function returns an object as defined in func_status.h:
2206 // states OK, Unknown, Disabled, On, Off.
2208 FuncStatus InsetTabular::getStatus(string const & what) const
2210 int action = LyXTabular::LAST_ACTION;
2214 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2215 string const tmp = tabularFeature[i].feature;
2216 if (tmp == what.substr(0, tmp.length())) {
2217 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2218 // tabularFeatures[i].feature.length())) {
2219 action = tabularFeature[i].action;
2223 if (action == LyXTabular::LAST_ACTION) {
2225 return status.unknown(true);
2228 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2233 LyXTabular::ltType dummyltt;
2236 if (hasSelection()) {
2237 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2239 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2243 case LyXTabular::SET_PWIDTH:
2244 case LyXTabular::SET_MPWIDTH:
2245 case LyXTabular::SET_SPECIAL_COLUMN:
2246 case LyXTabular::SET_SPECIAL_MULTI:
2247 return status.disabled(true);
2249 case LyXTabular::APPEND_ROW:
2250 case LyXTabular::APPEND_COLUMN:
2251 case LyXTabular::DELETE_ROW:
2252 case LyXTabular::DELETE_COLUMN:
2253 case LyXTabular::SET_ALL_LINES:
2254 case LyXTabular::UNSET_ALL_LINES:
2255 return status.clear();
2257 case LyXTabular::MULTICOLUMN:
2258 status.setOnOff(tabular->IsMultiColumn(actcell));
2260 case LyXTabular::M_TOGGLE_LINE_TOP:
2262 case LyXTabular::TOGGLE_LINE_TOP:
2263 status.setOnOff(tabular->TopLine(actcell, flag));
2265 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2267 case LyXTabular::TOGGLE_LINE_BOTTOM:
2268 status.setOnOff(tabular->BottomLine(actcell, flag));
2270 case LyXTabular::M_TOGGLE_LINE_LEFT:
2272 case LyXTabular::TOGGLE_LINE_LEFT:
2273 status.setOnOff(tabular->LeftLine(actcell, flag));
2275 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2277 case LyXTabular::TOGGLE_LINE_RIGHT:
2278 status.setOnOff(tabular->RightLine(actcell, flag));
2280 case LyXTabular::M_ALIGN_LEFT:
2282 case LyXTabular::ALIGN_LEFT:
2283 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2285 case LyXTabular::M_ALIGN_RIGHT:
2287 case LyXTabular::ALIGN_RIGHT:
2288 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2290 case LyXTabular::M_ALIGN_CENTER:
2292 case LyXTabular::ALIGN_CENTER:
2293 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2295 case LyXTabular::M_VALIGN_TOP:
2297 case LyXTabular::VALIGN_TOP:
2298 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2300 case LyXTabular::M_VALIGN_BOTTOM:
2302 case LyXTabular::VALIGN_BOTTOM:
2303 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2305 case LyXTabular::M_VALIGN_CENTER:
2307 case LyXTabular::VALIGN_CENTER:
2308 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2310 case LyXTabular::SET_LONGTABULAR:
2311 status.setOnOff(tabular->IsLongTabular());
2313 case LyXTabular::UNSET_LONGTABULAR:
2314 status.setOnOff(!tabular->IsLongTabular());
2316 case LyXTabular::SET_ROTATE_TABULAR:
2317 status.setOnOff(tabular->GetRotateTabular());
2319 case LyXTabular::UNSET_ROTATE_TABULAR:
2320 status.setOnOff(!tabular->GetRotateTabular());
2322 case LyXTabular::SET_ROTATE_CELL:
2323 status.setOnOff(tabular->GetRotateCell(actcell));
2325 case LyXTabular::UNSET_ROTATE_CELL:
2326 status.setOnOff(!tabular->GetRotateCell(actcell));
2328 case LyXTabular::SET_USEBOX:
2329 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2331 case LyXTabular::SET_LTFIRSTHEAD:
2332 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2334 case LyXTabular::SET_LTHEAD:
2335 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2337 case LyXTabular::SET_LTFOOT:
2338 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2340 case LyXTabular::SET_LTLASTFOOT:
2341 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2343 case LyXTabular::SET_LTNEWPAGE:
2344 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2348 status.disabled(true);
2355 std::vector<string> const InsetTabular::getLabelList() const
2357 return tabular->getLabelList();
2361 bool InsetTabular::copySelection(BufferView * bv)
2363 if (!hasSelection())
2366 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2367 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2368 if (sel_col_start > sel_col_end) {
2369 sel_col_start = sel_col_end;
2370 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2372 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2374 int const columns = sel_col_end - sel_col_start + 1;
2376 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2377 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2378 if (sel_row_start > sel_row_end) {
2379 swap(sel_row_start, sel_row_end);
2381 int const rows = sel_row_end - sel_row_start + 1;
2383 delete paste_tabular;
2384 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2385 for (int i = 0; i < sel_row_start; ++i)
2386 paste_tabular->DeleteRow(0);
2387 while (paste_tabular->rows() > rows)
2388 paste_tabular->DeleteRow(rows);
2389 paste_tabular->SetTopLine(0, true, true);
2390 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2392 for (int i = 0; i < sel_col_start; ++i)
2393 paste_tabular->DeleteColumn(0);
2394 while (paste_tabular->columns() > columns)
2395 paste_tabular->DeleteColumn(columns);
2396 paste_tabular->SetLeftLine(0, true, true);
2397 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2401 paste_tabular->ascii(bv->buffer(), sstr,
2402 (int)parOwner()->params().depth(), true, '\t');
2403 bv->stuffClipboard(sstr.str().c_str());
2408 bool InsetTabular::pasteSelection(BufferView * bv)
2413 for (int r1 = 0, r2 = actrow;
2414 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2416 for(int c1 = 0, c2 = actcol;
2417 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2419 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2420 tabular->IsPartOfMultiColumn(r2,c2))
2422 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2426 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2430 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2431 int const n2 = tabular->GetCellNumber(r2, c2);
2432 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2433 tabular->GetCellInset(n2)->setOwner(this);
2434 tabular->GetCellInset(n2)->deleteLyXText(bv);
2441 bool InsetTabular::cutSelection()
2443 if (!hasSelection())
2446 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2447 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2448 if (sel_col_start > sel_col_end) {
2449 sel_col_start = sel_col_end;
2450 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2452 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2454 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2455 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2456 if (sel_row_start > sel_row_end) {
2457 swap(sel_row_start, sel_row_end);
2459 if (sel_cell_start > sel_cell_end) {
2460 swap(sel_cell_start, sel_cell_end);
2462 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2463 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2464 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2471 bool InsetTabular::isRightToLeft(BufferView *bv )
2473 return bv->getParentLanguage(this)->RightToLeft();
2477 bool InsetTabular::nodraw() const
2479 if (!UpdatableInset::nodraw() && the_locking_inset)
2480 return the_locking_inset->nodraw();
2481 return UpdatableInset::nodraw();
2485 int InsetTabular::scroll(bool recursive) const
2487 int sx = UpdatableInset::scroll(false);
2489 if (recursive && the_locking_inset)
2490 sx += the_locking_inset->scroll(recursive);
2496 bool InsetTabular::doClearArea() const
2498 return !locked || (need_update & (FULL|INIT));
2502 void InsetTabular::getSelection(int & srow, int & erow,
2503 int & scol, int & ecol) const
2505 int const start = hasSelection() ? sel_cell_start : actcell;
2506 int const end = hasSelection() ? sel_cell_end : actcell;
2508 srow = tabular->row_of_cell(start);
2509 erow = tabular->row_of_cell(end);
2514 scol = tabular->column_of_cell(start);
2515 ecol = tabular->column_of_cell(end);
2519 ecol = tabular->right_column_of_cell(end);
2524 Paragraph * InsetTabular::getParFromID(int id) const
2527 for(int i = 0; i < tabular->rows(); ++i) {
2528 for(int j = 0; j < tabular->columns(); ++j) {
2529 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2537 Paragraph * InsetTabular::firstParagraph() const
2539 if (the_locking_inset)
2540 return the_locking_inset->firstParagraph();
2545 Paragraph * InsetTabular::getFirstParagraph(int i) const
2547 return (i < tabular->GetNumberOfCells())
2548 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2553 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2555 if (the_locking_inset)
2556 return the_locking_inset->cursor(bv);
2557 return Inset::cursor(bv);
2561 Inset * InsetTabular::getInsetFromID(int id_arg) const
2564 return const_cast<InsetTabular *>(this);
2567 for(int i = 0; i < tabular->rows(); ++i) {
2568 for(int j = 0; j < tabular->columns(); ++j) {
2569 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2578 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2581 if (the_locking_inset) {
2582 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2587 if (tabular->IsLastCell(actcell)) {
2588 bv->unlockInset(const_cast<InsetTabular *>(this));
2594 // otherwise we have to lock the next inset and ask for it's selecttion
2595 UpdatableInset * inset =
2596 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2597 inset->edit(bv, 0, 0, 0);
2598 string const str(selectNextWordInt(bv, value));
2606 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2608 // when entering this function the inset should be ALWAYS locked!
2609 lyx::Assert(the_locking_inset);
2611 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2615 if (tabular->IsLastCell(actcell)) {
2616 bv->unlockInset(const_cast<InsetTabular *>(this));
2620 // otherwise we have to lock the next inset and ask for it's selecttion
2621 UpdatableInset * inset =
2622 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2624 return selectNextWordInt(bv, value);
2628 void InsetTabular::selectSelectedWord(BufferView * bv)
2630 if (the_locking_inset) {
2631 the_locking_inset->selectSelectedWord(bv);
2638 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2640 if (the_locking_inset) {
2641 the_locking_inset->toggleSelection(bv, kill_selection);
2646 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2650 if (the_locking_inset) {
2651 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2653 updateLocal(bv, CELL, false);
2656 if (tabular->IsLastCell(actcell)) {
2658 bv->unlockInset(const_cast<InsetTabular *>(this));
2663 // otherwise we have to lock the next inset and search there
2664 UpdatableInset * inset =
2665 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2667 bool const ret = searchForward(bv, str, cs, mw);
2669 updateLocal(bv, CELL, false);
2674 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2678 if (the_locking_inset) {
2679 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2681 updateLocal(bv, CELL, false);
2684 if (!actcell) { // we are already in the first cell
2686 bv->unlockInset(const_cast<InsetTabular *>(this));
2691 // otherwise we have to lock the next inset and search there
2692 UpdatableInset * inset =
2693 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2694 inset->edit(bv, false);
2695 bool const ret = searchBackward(bv, str, cs, mw);
2697 updateLocal(bv, CELL, false);
2702 bool InsetTabular::insetAllowed(Inset::Code code) const
2704 if (the_locking_inset)
2705 return the_locking_inset->insetAllowed(code);
2710 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2712 const int cell = tabular->GetCellFromInset(in, actcell);
2715 return tabular->GetPWidth(cell).zero();
2717 // well we didn't obviously find it so maybe our owner knows more
2719 return owner()->forceDefaultParagraphs(in);
2720 // if we're here there is really something strange going on!!!