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;
143 actrow = actcell = 0;
147 in_reset_pos = false;
151 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
153 : UpdatableInset(tab, same_id), buffer(&buf)
155 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
156 the_locking_inset = 0;
159 actrow = actcell = 0;
163 in_reset_pos = false;
167 InsetTabular::~InsetTabular()
173 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
175 return new InsetTabular(*this, buf, same_id);
179 void InsetTabular::write(Buffer const * buf, ostream & os) const
181 os << " Tabular" << endl;
182 tabular->Write(buf, os);
186 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
188 bool const old_format = (lex.getString() == "\\LyXTable");
190 tabular.reset(new LyXTabular(buf, this, lex));
198 string token = lex.getString();
199 while (lex.isOK() && (token != "\\end_inset")) {
201 token = lex.getString();
203 if (token != "\\end_inset") {
204 lex.printError("Missing \\end_inset at this point. "
210 int InsetTabular::ascent(BufferView *, LyXFont const &) const
212 return tabular->GetAscentOfRow(0);
216 int InsetTabular::descent(BufferView *, LyXFont const &) const
218 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
222 int InsetTabular::width(BufferView *, LyXFont const &) const
224 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
228 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
229 float & x, bool cleared) const
237 if (need_update == INIT) {
238 if (calculate_dimensions_of_cells(bv, font, true))
239 bv->text->status = LyXText::CHANGED_IN_DRAW;
244 Painter & pain = bv->painter();
250 UpdatableInset::draw(bv, font, baseline, x, cleared);
253 x += static_cast<float>(scroll());
255 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
256 (top_x != int(x)) || (top_baseline != baseline)))
258 int h = ascent(bv, font) + descent(bv, font);
259 int const tx = display() || !owner() ? 0 : top_x;
260 int w = tx ? width(bv, font) : pain.paperWidth();
261 int ty = baseline - ascent(bv, font);
265 if ((ty + h) > pain.paperHeight())
266 h = pain.paperHeight();
267 if ((top_x + w) > pain.paperWidth())
268 w = pain.paperWidth();
269 pain.fillRectangle(tx, ty, w, h, backgroundColor());
275 top_baseline = baseline;
276 x += ADD_TO_TABULAR_WIDTH;
280 first_visible_cell = -1;
281 for (i = 0; i < tabular->rows(); ++i) {
283 cell = tabular->GetCellNumber(i, 0);
284 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
285 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
287 baseline += tabular->GetDescentOfRow(i) +
288 tabular->GetAscentOfRow(i + 1) +
289 tabular->GetAdditionalHeight(i + 1);
292 for (j = 0; j < tabular->columns(); ++j) {
293 if (nx > bv->workWidth())
295 if (tabular->IsPartOfMultiColumn(i, j))
297 cx = nx + tabular->GetBeginningOfTextInCell(cell);
298 if (first_visible_cell < 0)
299 first_visible_cell = cell;
300 if (hasSelection()) {
301 drawCellSelection(pain, nx, baseline, i, j, cell);
304 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
305 drawCellLines(pain, nx, baseline, i, cell);
306 nx += tabular->GetWidthOfColumn(cell);
309 baseline += tabular->GetDescentOfRow(i) +
310 tabular->GetAscentOfRow(i + 1) +
311 tabular->GetAdditionalHeight(i + 1);
313 } else if (need_update == CELL) {
316 if (the_locking_inset &&
317 tabular->GetCellInset(actcell) != the_locking_inset)
319 Inset * inset = tabular->GetCellInset(cell);
321 inset != the_locking_inset && i < tabular->rows();
325 inset != the_locking_inset && j < tabular->columns();
328 if (tabular->IsPartOfMultiColumn(i, j))
330 nx += tabular->GetWidthOfColumn(cell);
332 inset = tabular->GetCellInset(cell);
334 if (tabular->row_of_cell(cell) > i) {
336 baseline += tabular->GetDescentOfRow(i) +
337 tabular->GetAscentOfRow(i + 1) +
338 tabular->GetAdditionalHeight(i + 1);
342 // compute baseline for actual row
343 for (i = 0; i < actrow; ++i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
348 // now compute the right x position
349 cell = tabular->GetCellNumber(actrow, 0);
350 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
351 if (tabular->IsPartOfMultiColumn(actrow, j))
353 nx += tabular->GetWidthOfColumn(cell);
357 i = tabular->row_of_cell(cell);
358 if (the_locking_inset != tabular->GetCellInset(cell)) {
359 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
362 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
364 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
366 // Here we use rectangular backgroundColor patches to clean up
367 // within a cell around the cell's red inset box. As follows:
370 // | | | | The rectangles are A, B and C
371 // | A |------------| B | below, origin top left (tx, ty),
372 // | | inset box | | dimensions w(idth), h(eight).
373 // +---+------------+---+ x grows rightward, y downward
375 // +--------------------+
377 // clear only if we didn't have a change
378 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
379 // clear before the inset
382 ty = baseline - tabular->GetAscentOfRow(i) + 1;
383 w = int(cx - nx - 1);
384 h = tabular->GetAscentOfRow(i) +
385 tabular->GetDescentOfRow(i) - 1;
386 pain.fillRectangle(tx, ty, w, h, backgroundColor());
387 // clear behind the inset
388 tx = int(cx + the_locking_inset->width(bv,font) + 1);
389 ty = baseline - tabular->GetAscentOfRow(i) + 1;
390 w = tabular->GetWidthOfColumn(cell) -
391 tabular->GetBeginningOfTextInCell(cell) -
392 the_locking_inset->width(bv,font) -
393 tabular->GetAdditionalWidth(cell) - 1;
394 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
395 pain.fillRectangle(tx, ty, w, h, backgroundColor());
396 // clear below the inset
398 ty = baseline + the_locking_inset->descent(bv, font) + 1;
399 w = tabular->GetWidthOfColumn(cell) -
400 tabular->GetAdditionalWidth(cell) - 1;
401 h = tabular->GetDescentOfRow(i) -
402 the_locking_inset->descent(bv, font) - 1;
403 pain.fillRectangle(tx, ty, w, h, backgroundColor());
406 x -= ADD_TO_TABULAR_WIDTH;
407 x += width(bv, font);
408 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
410 for(Inset * inset = owner(); inset; ++i)
411 inset = inset->owner();
412 if (calculate_dimensions_of_cells(bv, font, false))
420 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
421 int row, int cell) const
423 int x2 = x + tabular->GetWidthOfColumn(cell);
426 if (!tabular->TopAlreadyDrawed(cell)) {
427 on_off = !tabular->TopLine(cell);
428 pain.line(x, baseline - tabular->GetAscentOfRow(row),
429 x2, baseline - tabular->GetAscentOfRow(row),
430 on_off ? LColor::tabularonoffline : LColor::tabularline,
431 on_off ? Painter::line_onoffdash : Painter::line_solid);
433 on_off = !tabular->BottomLine(cell);
434 pain.line(x,baseline + tabular->GetDescentOfRow(row),
435 x2, baseline + tabular->GetDescentOfRow(row),
436 on_off ? LColor::tabularonoffline : LColor::tabularline,
437 on_off ? Painter::line_onoffdash : Painter::line_solid);
438 if (!tabular->LeftAlreadyDrawed(cell)) {
439 on_off = !tabular->LeftLine(cell);
440 pain.line(x, baseline - tabular->GetAscentOfRow(row),
441 x, baseline + tabular->GetDescentOfRow(row),
442 on_off ? LColor::tabularonoffline : LColor::tabularline,
443 on_off ? Painter::line_onoffdash : Painter::line_solid);
445 on_off = !tabular->RightLine(cell);
446 pain.line(x2 - tabular->GetAdditionalWidth(cell),
447 baseline - tabular->GetAscentOfRow(row),
448 x2 - tabular->GetAdditionalWidth(cell),
449 baseline + tabular->GetDescentOfRow(row),
450 on_off ? LColor::tabularonoffline : LColor::tabularline,
451 on_off ? Painter::line_onoffdash : Painter::line_solid);
455 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
456 int row, int column, int cell) const
458 lyx::Assert(hasSelection());
459 int cs = tabular->column_of_cell(sel_cell_start);
460 int ce = tabular->column_of_cell(sel_cell_end);
463 cs = tabular->column_of_cell(sel_cell_end);
465 ce = tabular->right_column_of_cell(sel_cell_end);
468 int rs = tabular->row_of_cell(sel_cell_start);
469 int re = tabular->row_of_cell(sel_cell_end);
473 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
474 int w = tabular->GetWidthOfColumn(cell);
475 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
476 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
477 w, h, LColor::selection);
482 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
488 owner()->update(bv, font, true);
495 if (calculate_dimensions_of_cells(bv, font, true))
498 owner()->update(bv, font, true);
502 if (the_locking_inset)
503 the_locking_inset->update(bv, font, reinit);
504 if (need_update < FULL &&
505 bv->text->status() == LyXText::NEED_MORE_REFRESH)
510 switch (need_update) {
514 if (calculate_dimensions_of_cells(bv, font, false))
527 string const InsetTabular::editMessage() const
529 return _("Opened Tabular Inset");
533 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
535 UpdatableInset::edit(bv, x, y, button);
537 if (!bv->lockInset(this)) {
538 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
542 the_locking_inset = 0;
548 if (insetHit(bv, x, y) && (button != 3)) {
549 activateCellInsetAbs(bv, x, y, button);
554 void InsetTabular::edit(BufferView * bv, bool front)
556 UpdatableInset::edit(bv, front);
558 if (!bv->lockInset(this)) {
559 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
563 the_locking_inset = 0;
569 actcell = tabular->GetNumberOfCells() - 1;
576 void InsetTabular::insetUnlock(BufferView * bv)
578 if (the_locking_inset) {
579 the_locking_inset->insetUnlock(bv);
580 the_locking_inset = 0;
585 if (scroll(false) || hasSelection()) {
590 updateLocal(bv, FULL, false);
595 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
596 bool mark_dirty) const
600 calculate_dimensions_of_cells(bv, font, true);
602 if (need_update < what) // only set this if it has greater update
604 if ((what == INIT) && hasSelection()) {
608 if (need_update != NONE) {
609 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
610 if (locked) // && (what != NONE))
616 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
618 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
623 if (inset == tabular->GetCellInset(actcell)) {
624 lyxerr[Debug::INSETTEXT] << "OK" << endl;
625 the_locking_inset = tabular->GetCellInset(actcell);
628 } else if (!the_locking_inset) {
629 int const n = tabular->GetNumberOfCells();
630 int const id = inset->id();
631 for (int i = 0; i < n; ++i) {
632 InsetText * in = tabular->GetCellInset(i);
635 the_locking_inset = in;
640 if (in->getInsetFromID(id)) {
642 the_locking_inset = in;
645 return the_locking_inset->lockInsetInInset(bv, inset);
648 } else if (the_locking_inset && (the_locking_inset == inset)) {
649 lyxerr[Debug::INSETTEXT] << "OK" << endl;
651 } else if (the_locking_inset) {
652 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
653 return the_locking_inset->lockInsetInInset(bv, inset);
655 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
660 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
663 if (!the_locking_inset)
665 if (the_locking_inset == inset) {
666 the_locking_inset->insetUnlock(bv);
667 the_locking_inset = 0;
669 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
675 updateLocal(bv, CELL, false);
676 showInsetCursor(bv, false);
679 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
680 if (inset->lyxCode() == TABULAR_CODE &&
681 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
682 bv->owner()->getDialogs()->updateTabular(this);
691 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
693 if (!the_locking_inset)
695 if (the_locking_inset != inset) {
696 if (!the_locking_inset->updateInsetInInset(bv, inset))
699 updateLocal(bv, CELL, false);
704 unsigned int InsetTabular::insetInInsetY()
706 if (!the_locking_inset)
708 return inset_y + the_locking_inset->insetInInsetY();
712 UpdatableInset * InsetTabular::getLockingInset() const
714 return the_locking_inset ? the_locking_inset->getLockingInset() :
715 const_cast<InsetTabular *>(this);
719 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
723 if (the_locking_inset)
724 return the_locking_inset->getFirstLockingInsetOfType(c);
729 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
731 if (the_locking_inset)
732 return the_locking_inset->insertInset(bv, inset);
737 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
739 if (hasSelection() && (button == 3))
742 if (hasSelection()) {
744 updateLocal(bv, SELECTION, false);
747 int const ocell = actcell;
748 int const orow = actrow;
753 updateLocal(bv, NONE, false);
757 if ((ocell != actcell) && the_locking_inset) {
758 the_locking_inset->insetUnlock(bv);
759 the_locking_inset = 0;
766 bool const inset_hit = insetHit(bv, x, y);
768 if ((ocell == actcell) && the_locking_inset && inset_hit) {
770 the_locking_inset->insetButtonPress(bv,
771 x - inset_x, y - inset_y,
774 } else if (the_locking_inset) {
775 the_locking_inset->insetUnlock(bv);
777 the_locking_inset = 0;
779 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
782 if (inset_hit && bv->theLockingInset()) {
783 if (activateCellInsetAbs(bv, x, y, button))
784 the_locking_inset->insetButtonPress(bv,
794 bool InsetTabular::insetButtonRelease(BufferView * bv,
795 int x, int y, int button)
798 if (the_locking_inset)
799 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
800 y - inset_y, button);
801 if (button == 3 && !ret) {
802 bv->owner()->getDialogs()->showTabular(this);
809 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
811 if (the_locking_inset) {
812 the_locking_inset->insetMotionNotify(bv,
820 // int const old_cell = actcell;
823 if (!hasSelection()) {
824 setSelection(actcell, actcell);
826 setSelection(sel_cell_start, actcell);
828 updateLocal(bv, SELECTION, false);
833 void InsetTabular::insetKeyPress(XKeyEvent * xke)
835 if (the_locking_inset) {
836 the_locking_inset->insetKeyPress(xke);
842 UpdatableInset::RESULT
843 InsetTabular::localDispatch(BufferView * bv, kb_action action,
846 // We need to save the value of the_locking_inset as the call to
847 // the_locking_inset->LocalDispatch might unlock it.
848 old_locking_inset = the_locking_inset;
849 UpdatableInset::RESULT result =
850 UpdatableInset::localDispatch(bv, action, arg);
851 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
856 if ((action < 0) && arg.empty())
859 bool hs = hasSelection();
862 // this one have priority over the locked InsetText, if we're not already
863 // inside another tabular then that one get's priority!
864 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
869 unlockInsetInInset(bv, the_locking_inset);
870 if (action == LFUN_TAB)
871 moveNextCell(bv, old_locking_inset != 0);
873 movePrevCell(bv, old_locking_inset != 0);
876 updateLocal(bv, SELECTION, false);
877 if (!the_locking_inset) {
879 return DISPATCHED_NOUPDATE;
882 // this to avoid compiler warnings.
888 if (the_locking_inset) {
889 result = the_locking_inset->localDispatch(bv, action, arg);
890 if (result == DISPATCHED_NOUPDATE) {
893 if (sc != scroll()) { // inset has been scrolled
894 the_locking_inset->toggleInsetCursor(bv);
895 updateLocal(bv, FULL, false);
896 the_locking_inset->toggleInsetCursor(bv);
899 } else if (result == DISPATCHED) {
900 the_locking_inset->toggleInsetCursor(bv);
901 updateLocal(bv, CELL, false);
902 the_locking_inset->toggleInsetCursor(bv);
904 } else if (result == FINISHED_UP) {
906 } else if (result == FINISHED_DOWN) {
908 } else if (result == FINISHED_RIGHT) {
916 // --- Cursor Movements ----------------------------------
917 case LFUN_RIGHTSEL: {
918 int const start = hasSelection() ? sel_cell_start : actcell;
919 if (tabular->IsLastCellInRow(actcell)) {
920 setSelection(start, actcell);
925 // if we are starting a selection, only select
926 // the current cell at the beginning
927 if (hasSelection()) {
928 moveRight(bv, false);
931 setSelection(start, end);
932 updateLocal(bv, SELECTION, false);
936 result = moveRight(bv);
939 updateLocal(bv, SELECTION, false);
942 int const start = hasSelection() ? sel_cell_start : actcell;
943 if (tabular->IsFirstCellInRow(actcell)) {
944 setSelection(start, actcell);
949 // if we are starting a selection, only select
950 // the current cell at the beginning
951 if (hasSelection()) {
955 setSelection(start, end);
956 updateLocal(bv, SELECTION, false);
960 result = moveLeft(bv);
963 updateLocal(bv, SELECTION, false);
966 int const start = hasSelection() ? sel_cell_start : actcell;
967 int const ocell = actcell;
968 // if we are starting a selection, only select
969 // the current cell at the beginning
970 if (hasSelection()) {
972 if ((ocell == sel_cell_end) ||
973 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
974 setSelection(start, tabular->GetCellBelow(sel_cell_end));
976 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
978 setSelection(start, start);
980 updateLocal(bv, SELECTION, false);
984 result = moveDown(bv, old_locking_inset != 0);
987 updateLocal(bv, SELECTION, false);
991 int const start = hasSelection() ? sel_cell_start : actcell;
992 int const ocell = actcell;
993 // if we are starting a selection, only select
994 // the current cell at the beginning
995 if (hasSelection()) {
997 if ((ocell == sel_cell_end) ||
998 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
999 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1001 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1003 setSelection(start, start);
1005 updateLocal(bv, SELECTION, false);
1009 result = moveUp(bv, old_locking_inset != 0);
1012 updateLocal(bv, SELECTION, false);
1015 int column = actcol;
1016 unlockInsetInInset(bv, the_locking_inset);
1017 if (bv->text->first + bv->painter().paperHeight() <
1018 (top_baseline + tabular->GetHeightOfTabular()))
1020 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1021 updateLocal(bv, FULL, false);
1022 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1024 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1027 updateLocal(bv, CURSOR, false);
1031 int column = actcol;
1032 unlockInsetInInset(bv, the_locking_inset);
1033 if (top_baseline < 0) {
1034 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1035 updateLocal(bv, FULL, false);
1036 if (top_baseline > 0)
1039 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1044 updateLocal(bv, CURSOR, false);
1047 // none of these make sense for insettabular,
1048 // but we must catch them to prevent any
1049 // selection from being confused
1053 case LFUN_WORDLEFTSEL:
1054 case LFUN_WORDRIGHT:
1055 case LFUN_WORDRIGHTSEL:
1056 case LFUN_DOWN_PARAGRAPH:
1057 case LFUN_DOWN_PARAGRAPHSEL:
1058 case LFUN_UP_PARAGRAPH:
1059 case LFUN_UP_PARAGRAPHSEL:
1060 case LFUN_BACKSPACE:
1067 case LFUN_LAYOUT_TABULAR:
1068 bv->owner()->getDialogs()->showTabular(this);
1070 case LFUN_TABULAR_FEATURE:
1071 if (!tabularFeatures(bv, arg))
1072 result = UNDISPATCHED;
1075 if (!copySelection(bv))
1077 setUndo(bv, Undo::DELETE,
1078 bv->text->cursor.par(),
1079 bv->text->cursor.par()->next());
1081 updateLocal(bv, INIT, true);
1084 if (!hasSelection())
1089 case LFUN_PASTESELECTION:
1091 string const clip(bv->getClipboard());
1095 if (clip.find('\t') != string::npos) {
1099 string::size_type len = clip.length();
1100 string::size_type p = 0;
1103 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1111 maxCols = max(cols, maxCols);
1117 maxCols = max(cols, maxCols);
1118 delete paste_tabular;
1119 paste_tabular = new LyXTabular(this, rows, maxCols);
1120 string::size_type op = 0;
1122 int cells = paste_tabular->GetNumberOfCells();
1124 while ((cell < cells) && (p < len) &&
1125 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1130 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1135 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1136 while (cols++ < maxCols)
1144 // check for the last cell if there is no trailing '\n'
1145 if ((cell < cells) && (op < len))
1146 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1148 // so that the clipboard is used and it goes on
1150 // and executes LFUN_PASTESELECTION in insettext!
1151 delete paste_tabular;
1156 if (hasPasteBuffer()) {
1157 setUndo(bv, Undo::INSERT,
1158 bv->text->cursor.par(),
1159 bv->text->cursor.par()->next());
1161 updateLocal(bv, INIT, true);
1164 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1166 // we try to activate the actual inset and put this event down to
1167 // the insets dispatch function.
1168 result = UNDISPATCHED;
1169 if (the_locking_inset)
1172 if (activateCellInset(bv)) {
1173 // reset need_update setted in above function!
1175 result = the_locking_inset->localDispatch(bv, action, arg);
1176 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1177 unlockInsetInInset(bv, the_locking_inset);
1179 // we need to update if this was requested before
1180 updateLocal(bv, NONE, false);
1181 return UNDISPATCHED;
1186 updateLocal(bv, CELL, false);
1191 if (result < FINISHED) {
1192 if (!the_locking_inset) {
1193 showInsetCursor(bv);
1196 bv->unlockInset(this);
1201 int InsetTabular::latex(Buffer const * buf, ostream & os,
1202 bool fragile, bool fp) const
1204 return tabular->latex(buf, os, fragile, fp);
1208 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1211 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1213 return tabular->ascii(buf, os, 0, false,0);
1217 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1219 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1223 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1228 // if the table is inside a float it doesn't need the informaltable
1229 // wrapper. Search for it.
1230 for(master = owner();
1231 master && master->lyxCode() != Inset::FLOAT_CODE;
1232 master = master->owner());
1235 os << "<informaltable>\n";
1238 ret+= tabular->docBook(buf,os);
1240 os << "</informaltable>\n";
1247 void InsetTabular::validate(LaTeXFeatures & features) const
1249 tabular->Validate(features);
1253 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1254 LyXFont const & font,
1261 bool changed = false;
1263 // if we have a locking_inset we should have to check only this cell for
1264 // change so I'll try this to have a boost, but who knows ;)
1265 if ((need_update != INIT) &&
1266 (the_locking_inset == tabular->GetCellInset(actcell))) {
1267 for(int i = 0; i < tabular->columns(); ++i) {
1268 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1270 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1273 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1274 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1275 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1278 for (int i = 0; i < tabular->rows(); ++i) {
1281 for (int j = 0; j < tabular->columns(); ++j) {
1282 if (tabular->IsPartOfMultiColumn(i,j))
1285 inset = tabular->GetCellInset(cell);
1286 if (!reinit && !tabular->GetPWidth(cell).zero())
1287 inset->update(bv, font, false);
1288 maxAsc = max(maxAsc, inset->ascent(bv, font));
1289 maxDesc = max(maxDesc, inset->descent(bv, font));
1290 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1292 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1293 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1301 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1303 if (the_locking_inset) {
1304 the_locking_inset->getCursorPos(bv, x, y);
1307 x = cursor_.x() - top_x;
1312 void InsetTabular::toggleInsetCursor(BufferView * bv)
1315 if (isCursorVisible())
1316 bv->hideLockedInsetCursor();
1319 if (the_locking_inset) {
1320 the_locking_inset->toggleInsetCursor(bv);
1324 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1326 int const asc = lyxfont::maxAscent(font);
1327 int const desc = lyxfont::maxDescent(font);
1329 if (isCursorVisible())
1330 bv->hideLockedInsetCursor();
1332 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1333 toggleCursorVisible();
1337 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1341 if (!isCursorVisible()) {
1342 LyXFont font; // = GetFont(par, cursor.pos);
1344 int const asc = lyxfont::maxAscent(font);
1345 int const desc = lyxfont::maxDescent(font);
1346 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1348 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1349 setCursorVisible(true);
1354 void InsetTabular::hideInsetCursor(BufferView * bv)
1356 if (isCursorVisible()) {
1357 bv->hideLockedInsetCursor();
1358 setCursorVisible(false);
1363 void InsetTabular::fitInsetCursor(BufferView * bv) const
1365 if (the_locking_inset) {
1366 the_locking_inset->fitInsetCursor(bv);
1371 int const asc = lyxfont::maxAscent(font);
1372 int const desc = lyxfont::maxDescent(font);
1373 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1377 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1381 actcell = actrow = actcol = 0;
1382 int ly = tabular->GetDescentOfRow(actrow);
1384 // first search the right row
1385 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1386 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1387 tabular->GetAscentOfRow(actrow + 1) +
1388 tabular->GetAdditionalHeight(actrow + 1));
1390 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1392 actcell = tabular->GetCellNumber(actrow, actcol);
1394 // now search the right column
1395 int lx = tabular->GetWidthOfColumn(actcell) -
1396 tabular->GetAdditionalWidth(actcell);
1397 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1398 lx += tabular->GetWidthOfColumn(actcell + 1)
1399 + tabular->GetAdditionalWidth(actcell);
1401 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1406 int InsetTabular::getCellXPos(int cell) const
1410 for (; !tabular->IsFirstCellInRow(c); --c)
1412 int lx = tabular->GetWidthOfColumn(cell);
1413 for (; c < cell; ++c) {
1414 lx += tabular->GetWidthOfColumn(c);
1416 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1420 void InsetTabular::resetPos(BufferView * bv) const
1422 #warning This should be fixed in the right manner (20011128 Jug)
1423 // fast hack to fix infinite repaintings!
1428 actcol = tabular->column_of_cell(actcell);
1431 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1432 if (tabular->IsLastCellInRow(cell)) {
1433 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1434 tabular->GetAscentOfRow(actrow + 1) +
1435 tabular->GetAdditionalHeight(actrow + 1));
1439 if (!locked || nodraw()) {
1440 if (the_locking_inset)
1441 inset_y = cursor_.y();
1444 // we need this only from here on!!!
1445 in_reset_pos = true;
1446 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1447 int new_x = getCellXPos(actcell);
1448 int old_x = cursor_.x();
1451 // cursor.x(getCellXPos(actcell) + offset);
1452 if ((actcol < tabular->columns()-1) && scroll(false) &&
1453 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1456 updateLocal(bv, FULL, false);
1457 } else if (the_locking_inset &&
1458 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1460 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1461 if (xx > (bv->workWidth()-20)) {
1462 scroll(bv, -(xx - bv->workWidth() + 60));
1463 updateLocal(bv, FULL, false);
1464 } else if (xx < 20) {
1470 updateLocal(bv, FULL, false);
1472 } else if ((cursor_.x() - offset) > 20 &&
1473 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1474 > (bv->workWidth() - 20)) {
1475 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1476 updateLocal(bv, FULL, false);
1477 } else if ((cursor_.x() - offset) < 20) {
1478 scroll(bv, 20 - cursor_.x() + offset);
1479 updateLocal(bv, FULL, false);
1480 } else if (scroll(false) && top_x > 20 &&
1481 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1482 scroll(bv, old_x - cursor_.x());
1483 updateLocal(bv, FULL, false);
1485 if (the_locking_inset) {
1486 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1487 inset_y = cursor_.y();
1489 if ((!the_locking_inset ||
1490 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1491 actcell != oldcell) {
1492 InsetTabular * inset = const_cast<InsetTabular *>(this);
1493 bv->owner()->getDialogs()->updateTabular(inset);
1496 in_reset_pos = false;
1500 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1502 if (lock && !old_locking_inset) {
1503 if (activateCellInset(bv))
1506 bool moved = isRightToLeft(bv)
1507 ? movePrevCell(bv) : moveNextCell(bv);
1509 return FINISHED_RIGHT;
1510 if (lock && activateCellInset(bv))
1514 return DISPATCHED_NOUPDATE;
1518 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1520 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1523 if (lock) { // behind the inset
1524 if (activateCellInset(bv, 0, 0, 0, true))
1528 return DISPATCHED_NOUPDATE;
1532 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1534 int const ocell = actcell;
1535 actcell = tabular->GetCellAbove(actcell);
1536 if (actcell == ocell) // we moved out of the inset
1542 if (old_locking_inset) {
1543 old_locking_inset->getCursorPos(bv, x, y);
1544 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1546 if (activateCellInset(bv, x, 0))
1549 return DISPATCHED_NOUPDATE;
1553 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1555 int const ocell = actcell;
1556 actcell = tabular->GetCellBelow(actcell);
1557 if (actcell == ocell) // we moved out of the inset
1558 return FINISHED_DOWN;
1563 if (old_locking_inset) {
1564 old_locking_inset->getCursorPos(bv, x, y);
1565 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1567 if (activateCellInset(bv, x, 0))
1570 return DISPATCHED_NOUPDATE;
1574 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1576 if (isRightToLeft(bv)) {
1577 if (tabular->IsFirstCellInRow(actcell)) {
1578 int row = tabular->row_of_cell(actcell);
1579 if (row == tabular->rows() - 1)
1581 actcell = tabular->GetLastCellInRow(row);
1582 actcell = tabular->GetCellBelow(actcell);
1589 if (tabular->IsLastCell(actcell))
1594 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1595 isRightToLeftPar(bv->buffer()->params);
1596 activateCellInset(bv, 0, 0, 0, !rtl);
1603 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1605 if (isRightToLeft(bv)) {
1606 if (tabular->IsLastCellInRow(actcell)) {
1607 int row = tabular->row_of_cell(actcell);
1610 actcell = tabular->GetFirstCellInRow(row);
1611 actcell = tabular->GetCellAbove(actcell);
1613 if (tabular->IsLastCell(actcell))
1618 if (!actcell) // first cell
1623 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1624 isRightToLeftPar(bv->buffer()->params);
1625 activateCellInset(bv, 0, 0, 0, !rtl);
1632 bool InsetTabular::deletable() const
1638 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1642 setSelection(0, tabular->GetNumberOfCells() - 1);
1644 if (hasSelection()) {
1645 setUndo(bv, Undo::EDIT,
1646 bv->text->cursor.par(),
1647 bv->text->cursor.par()->next());
1648 bool frozen = undo_frozen;
1651 // apply the fontchange on the whole selection
1656 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1657 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1658 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1659 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1664 updateLocal(bv, INIT, true);
1666 if (the_locking_inset)
1667 the_locking_inset->setFont(bv, font, tall);
1671 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1673 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1676 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1677 string const tmp = tabularFeature[i].feature;
1679 if (tmp == what.substr(0, tmp.length())) {
1680 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1681 //tabularFeatures[i].feature.length())) {
1682 action = tabularFeature[i].action;
1686 if (action == LyXTabular::LAST_ACTION)
1690 frontStrip(what.substr(tabularFeature[i].feature.length()));
1691 tabularFeatures(bv, action, val);
1695 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1696 string const & special, bool & flag)
1698 if (special == "dl_above") {
1701 } else if (special == "dl_below") {
1702 ltt.bottomDL = flag;
1704 } else if (special == "empty") {
1714 void InsetTabular::tabularFeatures(BufferView * bv,
1715 LyXTabular::Feature feature,
1716 string const & value)
1722 bool setLines = false;
1723 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1724 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1727 case LyXTabular::M_ALIGN_LEFT:
1728 case LyXTabular::ALIGN_LEFT:
1729 setAlign = LYX_ALIGN_LEFT;
1731 case LyXTabular::M_ALIGN_RIGHT:
1732 case LyXTabular::ALIGN_RIGHT:
1733 setAlign = LYX_ALIGN_RIGHT;
1735 case LyXTabular::M_ALIGN_CENTER:
1736 case LyXTabular::ALIGN_CENTER:
1737 setAlign = LYX_ALIGN_CENTER;
1739 case LyXTabular::M_VALIGN_TOP:
1740 case LyXTabular::VALIGN_TOP:
1741 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1743 case LyXTabular::M_VALIGN_BOTTOM:
1744 case LyXTabular::VALIGN_BOTTOM:
1745 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1747 case LyXTabular::M_VALIGN_CENTER:
1748 case LyXTabular::VALIGN_CENTER:
1749 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1754 if (hasSelection()) {
1755 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1757 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1758 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1760 setUndo(bv, Undo::FINISH,
1761 bv->text->cursor.par(),
1762 bv->text->cursor.par()->next());
1764 int row = tabular->row_of_cell(actcell);
1765 int column = tabular->column_of_cell(actcell);
1767 LyXTabular::ltType ltt;
1770 case LyXTabular::SET_PWIDTH:
1772 LyXLength const vallen(value);
1773 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1775 bool const update = (tmplen != vallen);
1776 tabular->SetColumnPWidth(actcell, vallen);
1779 for (int i = 0; i < tabular->rows(); ++i) {
1780 cell = tabular->GetCellNumber(i,column);
1781 tabular->GetCellInset(cell)->resizeLyXText(bv);
1783 updateLocal(bv, INIT, true);
1787 case LyXTabular::SET_MPWIDTH:
1789 LyXLength const vallen(value);
1790 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1792 bool const update = (tmplen != vallen);
1793 tabular->SetMColumnPWidth(actcell, vallen);
1795 for (int i = 0; i < tabular->rows(); ++i) {
1796 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1799 updateLocal(bv, INIT, true);
1803 case LyXTabular::SET_SPECIAL_COLUMN:
1804 case LyXTabular::SET_SPECIAL_MULTI:
1805 tabular->SetAlignSpecial(actcell,value,feature);
1806 updateLocal(bv, FULL, true);
1808 case LyXTabular::APPEND_ROW:
1809 // append the row into the tabular
1810 unlockInsetInInset(bv, the_locking_inset);
1811 tabular->AppendRow(actcell);
1812 updateLocal(bv, INIT, true);
1814 case LyXTabular::APPEND_COLUMN:
1815 // append the column into the tabular
1816 unlockInsetInInset(bv, the_locking_inset);
1817 tabular->AppendColumn(actcell);
1818 actcell = tabular->GetCellNumber(row, column);
1819 updateLocal(bv, INIT, true);
1821 case LyXTabular::DELETE_ROW:
1822 unlockInsetInInset(bv, the_locking_inset);
1823 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1824 tabular->DeleteRow(sel_row_start);
1826 if (sel_row_start >= tabular->rows())
1828 actcell = tabular->GetCellNumber(sel_row_start, column);
1830 updateLocal(bv, INIT, true);
1832 case LyXTabular::DELETE_COLUMN:
1833 unlockInsetInInset(bv, the_locking_inset);
1834 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1835 tabular->DeleteColumn(sel_col_start);
1837 if (sel_col_start >= tabular->columns())
1839 actcell = tabular->GetCellNumber(row, sel_col_start);
1841 updateLocal(bv, INIT, true);
1843 case LyXTabular::M_TOGGLE_LINE_TOP:
1845 case LyXTabular::TOGGLE_LINE_TOP:
1847 bool lineSet = !tabular->TopLine(actcell, flag);
1848 for (int i = sel_row_start; i <= sel_row_end; ++i)
1849 for (int j = sel_col_start; j <= sel_col_end; ++j)
1850 tabular->SetTopLine(
1851 tabular->GetCellNumber(i, j),
1853 updateLocal(bv, INIT, true);
1857 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1859 case LyXTabular::TOGGLE_LINE_BOTTOM:
1861 bool lineSet = !tabular->BottomLine(actcell, flag);
1862 for (int i = sel_row_start; i <= sel_row_end; ++i)
1863 for (int j = sel_col_start; j <= sel_col_end; ++j)
1864 tabular->SetBottomLine(
1865 tabular->GetCellNumber(i, j),
1868 updateLocal(bv, INIT, true);
1872 case LyXTabular::M_TOGGLE_LINE_LEFT:
1874 case LyXTabular::TOGGLE_LINE_LEFT:
1876 bool lineSet = !tabular->LeftLine(actcell, flag);
1877 for (int i = sel_row_start; i <= sel_row_end; ++i)
1878 for (int j = sel_col_start; j <= sel_col_end; ++j)
1879 tabular->SetLeftLine(
1880 tabular->GetCellNumber(i,j),
1883 updateLocal(bv, INIT, true);
1887 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1889 case LyXTabular::TOGGLE_LINE_RIGHT:
1891 bool lineSet = !tabular->RightLine(actcell, flag);
1892 for (int i = sel_row_start; i <= sel_row_end; ++i)
1893 for (int j = sel_col_start; j <= sel_col_end; ++j)
1894 tabular->SetRightLine(
1895 tabular->GetCellNumber(i,j),
1898 updateLocal(bv, INIT, true);
1902 case LyXTabular::M_ALIGN_LEFT:
1903 case LyXTabular::M_ALIGN_RIGHT:
1904 case LyXTabular::M_ALIGN_CENTER:
1906 case LyXTabular::ALIGN_LEFT:
1907 case LyXTabular::ALIGN_RIGHT:
1908 case LyXTabular::ALIGN_CENTER:
1909 for (int i = sel_row_start; i <= sel_row_end; ++i)
1910 for (int j = sel_col_start; j <= sel_col_end; ++j)
1911 tabular->SetAlignment(
1912 tabular->GetCellNumber(i, j),
1915 updateLocal(bv, INIT, true);
1917 case LyXTabular::M_VALIGN_TOP:
1918 case LyXTabular::M_VALIGN_BOTTOM:
1919 case LyXTabular::M_VALIGN_CENTER:
1921 case LyXTabular::VALIGN_TOP:
1922 case LyXTabular::VALIGN_BOTTOM:
1923 case LyXTabular::VALIGN_CENTER:
1924 for (int i = sel_row_start; i <= sel_row_end; ++i)
1925 for (int j = sel_col_start; j <= sel_col_end; ++j)
1926 tabular->SetVAlignment(
1927 tabular->GetCellNumber(i, j),
1929 updateLocal(bv, INIT, true);
1931 case LyXTabular::MULTICOLUMN:
1933 if (sel_row_start != sel_row_end) {
1934 Alert::alert(_("Impossible Operation!"),
1935 _("Multicolumns can only be horizontally."),
1939 // just multicol for one Single Cell
1940 if (!hasSelection()) {
1941 // check wether we are completly in a multicol
1942 if (tabular->IsMultiColumn(actcell)) {
1943 tabular->UnsetMultiColumn(actcell);
1944 updateLocal(bv, INIT, true);
1946 tabular->SetMultiColumn(actcell, 1);
1947 updateLocal(bv, CELL, true);
1951 // we have a selection so this means we just add all this
1952 // cells to form a multicolumn cell
1956 if (sel_cell_start > sel_cell_end) {
1957 s_start = sel_cell_end;
1958 s_end = sel_cell_start;
1960 s_start = sel_cell_start;
1961 s_end = sel_cell_end;
1963 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1966 updateLocal(bv, INIT, true);
1969 case LyXTabular::SET_ALL_LINES:
1971 case LyXTabular::UNSET_ALL_LINES:
1972 for (int i = sel_row_start; i <= sel_row_end; ++i)
1973 for (int j = sel_col_start; j <= sel_col_end; ++j)
1974 tabular->SetAllLines(
1975 tabular->GetCellNumber(i,j), setLines);
1976 updateLocal(bv, INIT, true);
1978 case LyXTabular::SET_LONGTABULAR:
1979 tabular->SetLongTabular(true);
1980 updateLocal(bv, INIT, true); // because this toggles displayed
1982 case LyXTabular::UNSET_LONGTABULAR:
1983 tabular->SetLongTabular(false);
1984 updateLocal(bv, INIT, true); // because this toggles displayed
1986 case LyXTabular::SET_ROTATE_TABULAR:
1987 tabular->SetRotateTabular(true);
1989 case LyXTabular::UNSET_ROTATE_TABULAR:
1990 tabular->SetRotateTabular(false);
1992 case LyXTabular::SET_ROTATE_CELL:
1993 for (int i = sel_row_start; i <= sel_row_end; ++i)
1994 for (int j = sel_col_start; j<=sel_col_end; ++j)
1995 tabular->SetRotateCell(
1996 tabular->GetCellNumber(i, j),
1999 case LyXTabular::UNSET_ROTATE_CELL:
2000 for (int i = sel_row_start; i <= sel_row_end; ++i)
2001 for (int j = sel_col_start; j <= sel_col_end; ++j)
2002 tabular->SetRotateCell(
2003 tabular->GetCellNumber(i, j), false);
2005 case LyXTabular::SET_USEBOX:
2007 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2008 if (val == tabular->GetUsebox(actcell))
2009 val = LyXTabular::BOX_NONE;
2010 for (int i = sel_row_start; i <= sel_row_end; ++i)
2011 for (int j = sel_col_start; j <= sel_col_end; ++j)
2013 tabular->GetCellNumber(i, j), val);
2016 case LyXTabular::UNSET_LTFIRSTHEAD:
2018 case LyXTabular::SET_LTFIRSTHEAD:
2019 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2020 checkLongtableSpecial(ltt, value, flag);
2021 tabular->SetLTHead(row, flag, ltt, true);
2023 case LyXTabular::UNSET_LTHEAD:
2025 case LyXTabular::SET_LTHEAD:
2026 (void)tabular->GetRowOfLTHead(row, ltt);
2027 checkLongtableSpecial(ltt, value, flag);
2028 tabular->SetLTHead(row, flag, ltt, false);
2030 case LyXTabular::UNSET_LTFOOT:
2032 case LyXTabular::SET_LTFOOT:
2033 (void)tabular->GetRowOfLTFoot(row, ltt);
2034 checkLongtableSpecial(ltt, value, flag);
2035 tabular->SetLTFoot(row, flag, ltt, false);
2037 case LyXTabular::UNSET_LTLASTFOOT:
2039 case LyXTabular::SET_LTLASTFOOT:
2040 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2041 checkLongtableSpecial(ltt, value, flag);
2042 tabular->SetLTFoot(row, flag, ltt, true);
2044 case LyXTabular::SET_LTNEWPAGE:
2046 bool what = !tabular->GetLTNewPage(row);
2047 tabular->SetLTNewPage(row, what);
2050 // dummy stuff just to avoid warnings
2051 case LyXTabular::LAST_ACTION:
2057 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2060 UpdatableInset * inset =
2061 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2062 LyXFont font(LyXFont::ALL_SANE);
2064 x = inset->x() + inset->width(bv, font);
2065 y = inset->descent(bv, font);
2067 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2068 //inset_y = cursor.y();
2069 inset->edit(bv, x, y, button);
2070 if (!the_locking_inset)
2072 updateLocal(bv, CELL, false);
2073 return (the_locking_inset != 0);
2077 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2080 inset_x = cursor_.x()
2081 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2082 inset_y = cursor_.y();
2083 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2087 bool InsetTabular::insetHit(BufferView *, int x, int) const
2090 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2094 // This returns paperWidth() if the cell-width is unlimited or the width
2095 // in pixels if we have a pwidth for this cell.
2096 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2098 LyXLength const len = tabular->GetPWidth(cell);
2102 #ifdef WITH_WARNINGS
2103 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2105 return VSpace(len).inPixels(bv);
2109 int InsetTabular::getMaxWidth(BufferView * bv,
2110 UpdatableInset const * inset) const
2112 int cell = tabular->cur_cell;
2113 if (tabular->GetCellInset(cell) != inset) {
2115 if (tabular->GetCellInset(cell) != inset) {
2117 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2122 int const n = tabular->GetNumberOfCells();
2125 for (cell = 0; cell < n; ++cell) {
2126 if (tabular->GetCellInset(cell) == inset)
2132 lyxerr << "Own inset not found, shouldn't really happen!\n";
2136 int w = getMaxWidthOfCell(bv, cell);
2138 // because the inset then subtracts it's top_x and owner->x()
2139 w += (inset->x() - top_x);
2146 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2148 resizeLyXText(bv, recursive);
2152 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2155 for(int i = 0; i < tabular->rows(); ++i) {
2156 for(int j = 0; j < tabular->columns(); ++j) {
2157 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2165 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2166 bool const recursive) const
2168 if (the_locking_inset)
2169 return the_locking_inset->getLyXText(bv, recursive);
2171 // if we're locked lock the actual insettext and return it's LyXText!!!
2173 UpdatableInset * inset =
2174 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2175 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2176 return the_locking_inset->getLyXText(bv, recursive);
2179 return Inset::getLyXText(bv, recursive);
2183 bool InsetTabular::showInsetDialog(BufferView * bv) const
2185 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2186 bv->owner()->getDialogs()
2187 ->showTabular(const_cast<InsetTabular *>(this));
2192 void InsetTabular::openLayoutDialog(BufferView * bv) const
2194 if (the_locking_inset) {
2195 InsetTabular * i = static_cast<InsetTabular *>
2196 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2198 i->openLayoutDialog(bv);
2202 bv->owner()->getDialogs()->showTabular(
2203 const_cast<InsetTabular *>(this));
2208 // function returns an object as defined in func_status.h:
2209 // states OK, Unknown, Disabled, On, Off.
2211 FuncStatus InsetTabular::getStatus(string const & what) const
2213 int action = LyXTabular::LAST_ACTION;
2217 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2218 string const tmp = tabularFeature[i].feature;
2219 if (tmp == what.substr(0, tmp.length())) {
2220 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2221 // tabularFeatures[i].feature.length())) {
2222 action = tabularFeature[i].action;
2226 if (action == LyXTabular::LAST_ACTION) {
2228 return status.unknown(true);
2231 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2236 LyXTabular::ltType dummyltt;
2239 if (hasSelection()) {
2240 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2242 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2246 case LyXTabular::SET_PWIDTH:
2247 case LyXTabular::SET_MPWIDTH:
2248 case LyXTabular::SET_SPECIAL_COLUMN:
2249 case LyXTabular::SET_SPECIAL_MULTI:
2250 return status.disabled(true);
2252 case LyXTabular::APPEND_ROW:
2253 case LyXTabular::APPEND_COLUMN:
2254 case LyXTabular::DELETE_ROW:
2255 case LyXTabular::DELETE_COLUMN:
2256 case LyXTabular::SET_ALL_LINES:
2257 case LyXTabular::UNSET_ALL_LINES:
2258 return status.clear();
2260 case LyXTabular::MULTICOLUMN:
2261 status.setOnOff(tabular->IsMultiColumn(actcell));
2263 case LyXTabular::M_TOGGLE_LINE_TOP:
2265 case LyXTabular::TOGGLE_LINE_TOP:
2266 status.setOnOff(tabular->TopLine(actcell, flag));
2268 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2270 case LyXTabular::TOGGLE_LINE_BOTTOM:
2271 status.setOnOff(tabular->BottomLine(actcell, flag));
2273 case LyXTabular::M_TOGGLE_LINE_LEFT:
2275 case LyXTabular::TOGGLE_LINE_LEFT:
2276 status.setOnOff(tabular->LeftLine(actcell, flag));
2278 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2280 case LyXTabular::TOGGLE_LINE_RIGHT:
2281 status.setOnOff(tabular->RightLine(actcell, flag));
2283 case LyXTabular::M_ALIGN_LEFT:
2285 case LyXTabular::ALIGN_LEFT:
2286 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2288 case LyXTabular::M_ALIGN_RIGHT:
2290 case LyXTabular::ALIGN_RIGHT:
2291 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2293 case LyXTabular::M_ALIGN_CENTER:
2295 case LyXTabular::ALIGN_CENTER:
2296 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2298 case LyXTabular::M_VALIGN_TOP:
2300 case LyXTabular::VALIGN_TOP:
2301 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2303 case LyXTabular::M_VALIGN_BOTTOM:
2305 case LyXTabular::VALIGN_BOTTOM:
2306 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2308 case LyXTabular::M_VALIGN_CENTER:
2310 case LyXTabular::VALIGN_CENTER:
2311 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2313 case LyXTabular::SET_LONGTABULAR:
2314 status.setOnOff(tabular->IsLongTabular());
2316 case LyXTabular::UNSET_LONGTABULAR:
2317 status.setOnOff(!tabular->IsLongTabular());
2319 case LyXTabular::SET_ROTATE_TABULAR:
2320 status.setOnOff(tabular->GetRotateTabular());
2322 case LyXTabular::UNSET_ROTATE_TABULAR:
2323 status.setOnOff(!tabular->GetRotateTabular());
2325 case LyXTabular::SET_ROTATE_CELL:
2326 status.setOnOff(tabular->GetRotateCell(actcell));
2328 case LyXTabular::UNSET_ROTATE_CELL:
2329 status.setOnOff(!tabular->GetRotateCell(actcell));
2331 case LyXTabular::SET_USEBOX:
2332 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2334 case LyXTabular::SET_LTFIRSTHEAD:
2335 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2337 case LyXTabular::SET_LTHEAD:
2338 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2340 case LyXTabular::SET_LTFOOT:
2341 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2343 case LyXTabular::SET_LTLASTFOOT:
2344 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2346 case LyXTabular::SET_LTNEWPAGE:
2347 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2351 status.disabled(true);
2358 std::vector<string> const InsetTabular::getLabelList() const
2360 return tabular->getLabelList();
2364 bool InsetTabular::copySelection(BufferView * bv)
2366 if (!hasSelection())
2369 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2370 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2371 if (sel_col_start > sel_col_end) {
2372 sel_col_start = sel_col_end;
2373 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2375 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2377 int const columns = sel_col_end - sel_col_start + 1;
2379 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2380 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2381 if (sel_row_start > sel_row_end) {
2382 swap(sel_row_start, sel_row_end);
2384 int const rows = sel_row_end - sel_row_start + 1;
2386 delete paste_tabular;
2387 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2388 for (int i = 0; i < sel_row_start; ++i)
2389 paste_tabular->DeleteRow(0);
2390 while (paste_tabular->rows() > rows)
2391 paste_tabular->DeleteRow(rows);
2392 paste_tabular->SetTopLine(0, true, true);
2393 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2395 for (int i = 0; i < sel_col_start; ++i)
2396 paste_tabular->DeleteColumn(0);
2397 while (paste_tabular->columns() > columns)
2398 paste_tabular->DeleteColumn(columns);
2399 paste_tabular->SetLeftLine(0, true, true);
2400 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2404 paste_tabular->ascii(bv->buffer(), sstr,
2405 (int)parOwner()->params().depth(), true, '\t');
2406 bv->stuffClipboard(sstr.str().c_str());
2411 bool InsetTabular::pasteSelection(BufferView * bv)
2416 for (int r1 = 0, r2 = actrow;
2417 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2419 for(int c1 = 0, c2 = actcol;
2420 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2422 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2423 tabular->IsPartOfMultiColumn(r2,c2))
2425 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2429 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2433 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2434 int const n2 = tabular->GetCellNumber(r2, c2);
2435 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2436 tabular->GetCellInset(n2)->setOwner(this);
2437 tabular->GetCellInset(n2)->deleteLyXText(bv);
2444 bool InsetTabular::cutSelection()
2446 if (!hasSelection())
2449 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2450 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2451 if (sel_col_start > sel_col_end) {
2452 sel_col_start = sel_col_end;
2453 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2455 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2457 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2458 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2459 if (sel_row_start > sel_row_end) {
2460 swap(sel_row_start, sel_row_end);
2462 if (sel_cell_start > sel_cell_end) {
2463 swap(sel_cell_start, sel_cell_end);
2465 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2466 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2467 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2474 bool InsetTabular::isRightToLeft(BufferView *bv )
2476 return bv->getParentLanguage(this)->RightToLeft();
2480 bool InsetTabular::nodraw() const
2482 if (!UpdatableInset::nodraw() && the_locking_inset)
2483 return the_locking_inset->nodraw();
2484 return UpdatableInset::nodraw();
2488 int InsetTabular::scroll(bool recursive) const
2490 int sx = UpdatableInset::scroll(false);
2492 if (recursive && the_locking_inset)
2493 sx += the_locking_inset->scroll(recursive);
2499 bool InsetTabular::doClearArea() const
2501 return !locked || (need_update & (FULL|INIT));
2505 void InsetTabular::getSelection(int & srow, int & erow,
2506 int & scol, int & ecol) const
2508 int const start = hasSelection() ? sel_cell_start : actcell;
2509 int const end = hasSelection() ? sel_cell_end : actcell;
2511 srow = tabular->row_of_cell(start);
2512 erow = tabular->row_of_cell(end);
2517 scol = tabular->column_of_cell(start);
2518 ecol = tabular->column_of_cell(end);
2522 ecol = tabular->right_column_of_cell(end);
2527 Paragraph * InsetTabular::getParFromID(int id) const
2530 for(int i = 0; i < tabular->rows(); ++i) {
2531 for(int j = 0; j < tabular->columns(); ++j) {
2532 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2540 Paragraph * InsetTabular::firstParagraph() const
2542 if (the_locking_inset)
2543 return the_locking_inset->firstParagraph();
2548 Paragraph * InsetTabular::getFirstParagraph(int i) const
2550 return (i < tabular->GetNumberOfCells())
2551 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2556 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2558 if (the_locking_inset)
2559 return the_locking_inset->cursor(bv);
2560 return Inset::cursor(bv);
2564 Inset * InsetTabular::getInsetFromID(int id_arg) const
2567 return const_cast<InsetTabular *>(this);
2570 for(int i = 0; i < tabular->rows(); ++i) {
2571 for(int j = 0; j < tabular->columns(); ++j) {
2572 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2581 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2584 if (the_locking_inset) {
2585 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2590 if (tabular->IsLastCell(actcell)) {
2591 bv->unlockInset(const_cast<InsetTabular *>(this));
2597 // otherwise we have to lock the next inset and ask for it's selecttion
2598 UpdatableInset * inset =
2599 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2600 inset->edit(bv, 0, 0, 0);
2601 string const str(selectNextWordInt(bv, value));
2609 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2611 // when entering this function the inset should be ALWAYS locked!
2612 lyx::Assert(the_locking_inset);
2614 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2618 if (tabular->IsLastCell(actcell)) {
2619 bv->unlockInset(const_cast<InsetTabular *>(this));
2623 // otherwise we have to lock the next inset and ask for it's selecttion
2624 UpdatableInset * inset =
2625 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2627 return selectNextWordInt(bv, value);
2631 void InsetTabular::selectSelectedWord(BufferView * bv)
2633 if (the_locking_inset) {
2634 the_locking_inset->selectSelectedWord(bv);
2641 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2643 if (the_locking_inset) {
2644 the_locking_inset->toggleSelection(bv, kill_selection);
2649 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2650 bool const & cs, bool const & mw)
2653 if (the_locking_inset) {
2654 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2656 updateLocal(bv, CELL, false);
2659 if (tabular->IsLastCell(actcell)) {
2661 bv->unlockInset(const_cast<InsetTabular *>(this));
2666 // otherwise we have to lock the next inset and search there
2667 UpdatableInset * inset =
2668 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2670 bool const ret = searchForward(bv, str, cs, mw);
2672 updateLocal(bv, CELL, false);
2677 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2678 bool const & cs, bool const & mw)
2681 if (the_locking_inset) {
2682 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2684 updateLocal(bv, CELL, false);
2687 if (!actcell) { // we are already in the first cell
2689 bv->unlockInset(const_cast<InsetTabular *>(this));
2694 // otherwise we have to lock the next inset and search there
2695 UpdatableInset * inset =
2696 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2697 inset->edit(bv, false);
2698 bool const ret = searchBackward(bv, str, cs, mw);
2700 updateLocal(bv, CELL, false);
2705 bool InsetTabular::insetAllowed(Inset::Code code) const
2707 if (the_locking_inset)
2708 return the_locking_inset->insetAllowed(code);
2713 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2715 int const n = tabular->GetNumberOfCells();
2716 static int last = 0;
2718 // maybe some speedup
2719 if ((last < n) && tabular->GetCellInset(last) == in) {
2720 if (tabular->GetPWidth(last+1).zero())
2724 if ((++last < n) && tabular->GetCellInset(last) == in) {
2725 if (tabular->GetPWidth(last).zero())
2730 for(int i=0; i < n; ++i) {
2731 if (tabular->GetCellInset(i) == in) {
2733 if (tabular->GetPWidth(i).zero())
2739 // well we didn't obviously find it so maybe our owner knows more
2741 return owner()->forceDefaultParagraphs(in);
2742 // if we're here there is really something strange going on!!!