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)) {
648 the_locking_inset = in;
651 return the_locking_inset->lockInsetInInset(bv, inset);
654 } else if (the_locking_inset && (the_locking_inset == inset)) {
655 lyxerr[Debug::INSETTEXT] << "OK" << endl;
657 } else if (the_locking_inset) {
658 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
659 return the_locking_inset->lockInsetInInset(bv, inset);
661 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
666 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
669 if (!the_locking_inset)
671 if (the_locking_inset == inset) {
672 the_locking_inset->insetUnlock(bv);
673 the_locking_inset = 0;
675 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
681 updateLocal(bv, CELL, false);
682 showInsetCursor(bv, false);
685 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
686 if (inset->lyxCode() == TABULAR_CODE &&
687 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
688 bv->owner()->getDialogs()->updateTabular(this);
697 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
699 if (!the_locking_inset)
701 if (the_locking_inset != inset) {
702 if (!the_locking_inset->updateInsetInInset(bv, inset))
705 updateLocal(bv, CELL, false);
710 unsigned int InsetTabular::insetInInsetY()
712 if (!the_locking_inset)
714 return inset_y + the_locking_inset->insetInInsetY();
718 UpdatableInset * InsetTabular::getLockingInset() const
720 return the_locking_inset ? the_locking_inset->getLockingInset() :
721 const_cast<InsetTabular *>(this);
725 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
729 if (the_locking_inset)
730 return the_locking_inset->getFirstLockingInsetOfType(c);
735 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
737 if (the_locking_inset)
738 return the_locking_inset->insertInset(bv, inset);
743 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
745 if (hasSelection() && (button == 3))
748 if (hasSelection()) {
750 updateLocal(bv, SELECTION, false);
753 int const ocell = actcell;
754 int const orow = actrow;
759 updateLocal(bv, NONE, false);
763 if ((ocell != actcell) && the_locking_inset) {
764 the_locking_inset->insetUnlock(bv);
765 the_locking_inset = 0;
772 bool const inset_hit = insetHit(bv, x, y);
774 if ((ocell == actcell) && the_locking_inset && inset_hit) {
776 the_locking_inset->insetButtonPress(bv,
777 x - inset_x, y - inset_y,
780 } else if (the_locking_inset) {
781 the_locking_inset->insetUnlock(bv);
783 the_locking_inset = 0;
785 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
788 if (inset_hit && bv->theLockingInset()) {
789 if (activateCellInsetAbs(bv, x, y, button))
790 the_locking_inset->insetButtonPress(bv,
800 bool InsetTabular::insetButtonRelease(BufferView * bv,
801 int x, int y, int button)
804 if (the_locking_inset)
805 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
806 y - inset_y, button);
807 if (button == 3 && !ret) {
808 bv->owner()->getDialogs()->showTabular(this);
815 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
817 if (the_locking_inset) {
818 the_locking_inset->insetMotionNotify(bv,
826 // int const old_cell = actcell;
829 if (!hasSelection()) {
830 setSelection(actcell, actcell);
832 setSelection(sel_cell_start, actcell);
834 updateLocal(bv, SELECTION, false);
839 void InsetTabular::insetKeyPress(XKeyEvent * xke)
841 if (the_locking_inset) {
842 the_locking_inset->insetKeyPress(xke);
848 UpdatableInset::RESULT
849 InsetTabular::localDispatch(BufferView * bv, kb_action action,
852 // We need to save the value of the_locking_inset as the call to
853 // the_locking_inset->LocalDispatch might unlock it.
854 old_locking_inset = the_locking_inset;
855 UpdatableInset::RESULT result =
856 UpdatableInset::localDispatch(bv, action, arg);
857 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
862 if ((action < 0) && arg.empty())
865 bool hs = hasSelection();
868 // this one have priority over the locked InsetText, if we're not already
869 // inside another tabular then that one get's priority!
870 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
875 unlockInsetInInset(bv, the_locking_inset);
876 if (action == LFUN_TAB)
877 moveNextCell(bv, old_locking_inset != 0);
879 movePrevCell(bv, old_locking_inset != 0);
882 updateLocal(bv, SELECTION, false);
883 if (!the_locking_inset) {
885 return DISPATCHED_NOUPDATE;
888 // this to avoid compiler warnings.
894 if (the_locking_inset) {
895 result = the_locking_inset->localDispatch(bv, action, arg);
896 if (result == DISPATCHED_NOUPDATE) {
899 if (sc != scroll()) { // inset has been scrolled
900 the_locking_inset->toggleInsetCursor(bv);
901 updateLocal(bv, FULL, false);
902 the_locking_inset->toggleInsetCursor(bv);
905 } else if (result == DISPATCHED) {
906 the_locking_inset->toggleInsetCursor(bv);
907 updateLocal(bv, CELL, false);
908 the_locking_inset->toggleInsetCursor(bv);
910 } else if (result == FINISHED_UP) {
912 } else if (result == FINISHED_DOWN) {
914 } else if (result == FINISHED_RIGHT) {
922 // --- Cursor Movements ----------------------------------
923 case LFUN_RIGHTSEL: {
924 int const start = hasSelection() ? sel_cell_start : actcell;
925 if (tabular->IsLastCellInRow(actcell)) {
926 setSelection(start, actcell);
931 // if we are starting a selection, only select
932 // the current cell at the beginning
933 if (hasSelection()) {
934 moveRight(bv, false);
937 setSelection(start, end);
938 updateLocal(bv, SELECTION, false);
942 result = moveRight(bv);
945 updateLocal(bv, SELECTION, false);
948 int const start = hasSelection() ? sel_cell_start : actcell;
949 if (tabular->IsFirstCellInRow(actcell)) {
950 setSelection(start, actcell);
955 // if we are starting a selection, only select
956 // the current cell at the beginning
957 if (hasSelection()) {
961 setSelection(start, end);
962 updateLocal(bv, SELECTION, false);
966 result = moveLeft(bv);
969 updateLocal(bv, SELECTION, false);
972 int const start = hasSelection() ? sel_cell_start : actcell;
973 int const ocell = actcell;
974 // if we are starting a selection, only select
975 // the current cell at the beginning
976 if (hasSelection()) {
978 if ((ocell == sel_cell_end) ||
979 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
980 setSelection(start, tabular->GetCellBelow(sel_cell_end));
982 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
984 setSelection(start, start);
986 updateLocal(bv, SELECTION, false);
990 result = moveDown(bv, old_locking_inset != 0);
993 updateLocal(bv, SELECTION, false);
997 int const start = hasSelection() ? sel_cell_start : actcell;
998 int const ocell = actcell;
999 // if we are starting a selection, only select
1000 // the current cell at the beginning
1001 if (hasSelection()) {
1003 if ((ocell == sel_cell_end) ||
1004 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1005 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1007 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1009 setSelection(start, start);
1011 updateLocal(bv, SELECTION, false);
1015 result = moveUp(bv, old_locking_inset != 0);
1018 updateLocal(bv, SELECTION, false);
1021 int column = actcol;
1022 unlockInsetInInset(bv, the_locking_inset);
1023 if (bv->text->first + bv->painter().paperHeight() <
1024 (top_baseline + tabular->GetHeightOfTabular()))
1026 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1027 updateLocal(bv, FULL, false);
1028 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1030 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1033 updateLocal(bv, CURSOR, false);
1037 int column = actcol;
1038 unlockInsetInInset(bv, the_locking_inset);
1039 if (top_baseline < 0) {
1040 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1041 updateLocal(bv, FULL, false);
1042 if (top_baseline > 0)
1045 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1050 updateLocal(bv, CURSOR, false);
1053 // none of these make sense for insettabular,
1054 // but we must catch them to prevent any
1055 // selection from being confused
1059 case LFUN_WORDLEFTSEL:
1060 case LFUN_WORDRIGHT:
1061 case LFUN_WORDRIGHTSEL:
1062 case LFUN_DOWN_PARAGRAPH:
1063 case LFUN_DOWN_PARAGRAPHSEL:
1064 case LFUN_UP_PARAGRAPH:
1065 case LFUN_UP_PARAGRAPHSEL:
1066 case LFUN_BACKSPACE:
1072 case LFUN_BEGINNINGBUF:
1073 case LFUN_BEGINNINGBUFSEL:
1075 case LFUN_ENDBUFSEL:
1077 case LFUN_LAYOUT_TABULAR:
1078 bv->owner()->getDialogs()->showTabular(this);
1080 case LFUN_TABULAR_FEATURE:
1081 if (!tabularFeatures(bv, arg))
1082 result = UNDISPATCHED;
1085 if (!copySelection(bv))
1087 setUndo(bv, Undo::DELETE,
1088 bv->text->cursor.par(),
1089 bv->text->cursor.par()->next());
1091 updateLocal(bv, INIT, true);
1094 if (!hasSelection())
1099 case LFUN_PASTESELECTION:
1101 string const clip(bv->getClipboard());
1105 if (clip.find('\t') != string::npos) {
1109 string::size_type len = clip.length();
1110 string::size_type p = 0;
1113 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1121 maxCols = max(cols, maxCols);
1127 maxCols = max(cols, maxCols);
1128 delete paste_tabular;
1129 paste_tabular = new LyXTabular(this, rows, maxCols);
1130 string::size_type op = 0;
1132 int cells = paste_tabular->GetNumberOfCells();
1134 while ((cell < cells) && (p < len) &&
1135 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1140 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1145 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1146 while (cols++ < maxCols)
1154 // check for the last cell if there is no trailing '\n'
1155 if ((cell < cells) && (op < len))
1156 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1158 // so that the clipboard is used and it goes on
1160 // and executes LFUN_PASTESELECTION in insettext!
1161 delete paste_tabular;
1166 if (hasPasteBuffer()) {
1167 setUndo(bv, Undo::INSERT,
1168 bv->text->cursor.par(),
1169 bv->text->cursor.par()->next());
1171 updateLocal(bv, INIT, true);
1174 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1176 // we try to activate the actual inset and put this event down to
1177 // the insets dispatch function.
1178 result = UNDISPATCHED;
1179 if (the_locking_inset)
1182 if (activateCellInset(bv)) {
1183 // reset need_update setted in above function!
1185 result = the_locking_inset->localDispatch(bv, action, arg);
1186 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1187 unlockInsetInInset(bv, the_locking_inset);
1189 // we need to update if this was requested before
1190 updateLocal(bv, NONE, false);
1191 return UNDISPATCHED;
1196 updateLocal(bv, CELL, false);
1201 if (result < FINISHED) {
1202 if (!the_locking_inset) {
1203 showInsetCursor(bv);
1206 bv->unlockInset(this);
1211 int InsetTabular::latex(Buffer const * buf, ostream & os,
1212 bool fragile, bool fp) const
1214 return tabular->latex(buf, os, fragile, fp);
1218 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1221 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1223 return tabular->ascii(buf, os, 0, false,0);
1227 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1229 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1233 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1238 // if the table is inside a float it doesn't need the informaltable
1239 // wrapper. Search for it.
1240 for(master = owner();
1241 master && master->lyxCode() != Inset::FLOAT_CODE;
1242 master = master->owner());
1245 os << "<informaltable>\n";
1248 ret+= tabular->docBook(buf,os);
1250 os << "</informaltable>\n";
1257 void InsetTabular::validate(LaTeXFeatures & features) const
1259 tabular->Validate(features);
1263 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1264 LyXFont const & font,
1271 bool changed = false;
1273 // if we have a locking_inset we should have to check only this cell for
1274 // change so I'll try this to have a boost, but who knows ;)
1275 if ((need_update != INIT) &&
1276 (the_locking_inset == tabular->GetCellInset(actcell))) {
1277 for(int i = 0; i < tabular->columns(); ++i) {
1278 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1280 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1283 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1284 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1285 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1288 for (int i = 0; i < tabular->rows(); ++i) {
1291 for (int j = 0; j < tabular->columns(); ++j) {
1292 if (tabular->IsPartOfMultiColumn(i,j))
1295 inset = tabular->GetCellInset(cell);
1296 if (!reinit && !tabular->GetPWidth(cell).zero())
1297 inset->update(bv, font, false);
1298 maxAsc = max(maxAsc, inset->ascent(bv, font));
1299 maxDesc = max(maxDesc, inset->descent(bv, font));
1300 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1302 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1303 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1311 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1313 if (the_locking_inset) {
1314 the_locking_inset->getCursorPos(bv, x, y);
1317 x = cursor_.x() - top_x;
1322 void InsetTabular::toggleInsetCursor(BufferView * bv)
1325 if (isCursorVisible())
1326 bv->hideLockedInsetCursor();
1329 if (the_locking_inset) {
1330 the_locking_inset->toggleInsetCursor(bv);
1334 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1336 int const asc = lyxfont::maxAscent(font);
1337 int const desc = lyxfont::maxDescent(font);
1339 if (isCursorVisible())
1340 bv->hideLockedInsetCursor();
1342 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1343 toggleCursorVisible();
1347 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1351 if (!isCursorVisible()) {
1352 LyXFont font; // = GetFont(par, cursor.pos);
1354 int const asc = lyxfont::maxAscent(font);
1355 int const desc = lyxfont::maxDescent(font);
1356 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1358 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1359 setCursorVisible(true);
1364 void InsetTabular::hideInsetCursor(BufferView * bv)
1366 if (isCursorVisible()) {
1367 bv->hideLockedInsetCursor();
1368 setCursorVisible(false);
1373 void InsetTabular::fitInsetCursor(BufferView * bv) const
1375 if (the_locking_inset) {
1376 the_locking_inset->fitInsetCursor(bv);
1381 int const asc = lyxfont::maxAscent(font);
1382 int const desc = lyxfont::maxDescent(font);
1383 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1387 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1391 actcell = actrow = actcol = 0;
1392 int ly = tabular->GetDescentOfRow(actrow);
1394 // first search the right row
1395 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1396 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1397 tabular->GetAscentOfRow(actrow + 1) +
1398 tabular->GetAdditionalHeight(actrow + 1));
1400 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1402 actcell = tabular->GetCellNumber(actrow, actcol);
1404 // now search the right column
1405 int lx = tabular->GetWidthOfColumn(actcell) -
1406 tabular->GetAdditionalWidth(actcell);
1407 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1408 lx += tabular->GetWidthOfColumn(actcell + 1)
1409 + tabular->GetAdditionalWidth(actcell);
1411 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1416 int InsetTabular::getCellXPos(int cell) const
1420 for (; !tabular->IsFirstCellInRow(c); --c)
1422 int lx = tabular->GetWidthOfColumn(cell);
1423 for (; c < cell; ++c) {
1424 lx += tabular->GetWidthOfColumn(c);
1426 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1430 void InsetTabular::resetPos(BufferView * bv) const
1432 #warning This should be fixed in the right manner (20011128 Jug)
1433 // fast hack to fix infinite repaintings!
1438 actcol = tabular->column_of_cell(actcell);
1441 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1442 if (tabular->IsLastCellInRow(cell)) {
1443 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1444 tabular->GetAscentOfRow(actrow + 1) +
1445 tabular->GetAdditionalHeight(actrow + 1));
1449 if (!locked || nodraw()) {
1450 if (the_locking_inset)
1451 inset_y = cursor_.y();
1454 // we need this only from here on!!!
1455 in_reset_pos = true;
1456 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1457 int new_x = getCellXPos(actcell);
1458 int old_x = cursor_.x();
1461 // cursor.x(getCellXPos(actcell) + offset);
1462 if ((actcol < tabular->columns()-1) && scroll(false) &&
1463 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1466 updateLocal(bv, FULL, false);
1467 } else if (the_locking_inset &&
1468 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1470 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1471 if (xx > (bv->workWidth()-20)) {
1472 scroll(bv, -(xx - bv->workWidth() + 60));
1473 updateLocal(bv, FULL, false);
1474 } else if (xx < 20) {
1480 updateLocal(bv, FULL, false);
1482 } else if ((cursor_.x() - offset) > 20 &&
1483 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1484 > (bv->workWidth() - 20)) {
1485 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1486 updateLocal(bv, FULL, false);
1487 } else if ((cursor_.x() - offset) < 20) {
1488 scroll(bv, 20 - cursor_.x() + offset);
1489 updateLocal(bv, FULL, false);
1490 } else if (scroll(false) && top_x > 20 &&
1491 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1492 scroll(bv, old_x - cursor_.x());
1493 updateLocal(bv, FULL, false);
1495 if (the_locking_inset) {
1496 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1497 inset_y = cursor_.y();
1499 if ((!the_locking_inset ||
1500 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1501 actcell != oldcell) {
1502 InsetTabular * inset = const_cast<InsetTabular *>(this);
1503 bv->owner()->getDialogs()->updateTabular(inset);
1506 in_reset_pos = false;
1510 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1512 if (lock && !old_locking_inset) {
1513 if (activateCellInset(bv))
1516 bool moved = isRightToLeft(bv)
1517 ? movePrevCell(bv) : moveNextCell(bv);
1519 return FINISHED_RIGHT;
1520 if (lock && activateCellInset(bv))
1524 return DISPATCHED_NOUPDATE;
1528 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1530 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1533 if (lock) { // behind the inset
1534 if (activateCellInset(bv, 0, 0, 0, true))
1538 return DISPATCHED_NOUPDATE;
1542 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1544 int const ocell = actcell;
1545 actcell = tabular->GetCellAbove(actcell);
1546 if (actcell == ocell) // we moved out of the inset
1552 if (old_locking_inset) {
1553 old_locking_inset->getCursorPos(bv, x, y);
1554 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1556 if (activateCellInset(bv, x, 0))
1559 return DISPATCHED_NOUPDATE;
1563 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1565 int const ocell = actcell;
1566 actcell = tabular->GetCellBelow(actcell);
1567 if (actcell == ocell) // we moved out of the inset
1568 return FINISHED_DOWN;
1573 if (old_locking_inset) {
1574 old_locking_inset->getCursorPos(bv, x, y);
1575 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1577 if (activateCellInset(bv, x, 0))
1580 return DISPATCHED_NOUPDATE;
1584 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1586 if (isRightToLeft(bv)) {
1587 if (tabular->IsFirstCellInRow(actcell)) {
1588 int row = tabular->row_of_cell(actcell);
1589 if (row == tabular->rows() - 1)
1591 actcell = tabular->GetLastCellInRow(row);
1592 actcell = tabular->GetCellBelow(actcell);
1599 if (tabular->IsLastCell(actcell))
1604 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1605 isRightToLeftPar(bv->buffer()->params);
1606 activateCellInset(bv, 0, 0, 0, !rtl);
1613 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1615 if (isRightToLeft(bv)) {
1616 if (tabular->IsLastCellInRow(actcell)) {
1617 int row = tabular->row_of_cell(actcell);
1620 actcell = tabular->GetFirstCellInRow(row);
1621 actcell = tabular->GetCellAbove(actcell);
1623 if (tabular->IsLastCell(actcell))
1628 if (!actcell) // first cell
1633 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1634 isRightToLeftPar(bv->buffer()->params);
1635 activateCellInset(bv, 0, 0, 0, !rtl);
1642 bool InsetTabular::deletable() const
1648 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1652 setSelection(0, tabular->GetNumberOfCells() - 1);
1654 if (hasSelection()) {
1655 setUndo(bv, Undo::EDIT,
1656 bv->text->cursor.par(),
1657 bv->text->cursor.par()->next());
1658 bool frozen = undo_frozen;
1661 // apply the fontchange on the whole selection
1666 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1667 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1668 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1669 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1674 updateLocal(bv, INIT, true);
1676 if (the_locking_inset)
1677 the_locking_inset->setFont(bv, font, tall);
1681 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1683 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1686 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1687 string const tmp = tabularFeature[i].feature;
1689 if (tmp == what.substr(0, tmp.length())) {
1690 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1691 //tabularFeatures[i].feature.length())) {
1692 action = tabularFeature[i].action;
1696 if (action == LyXTabular::LAST_ACTION)
1700 frontStrip(what.substr(tabularFeature[i].feature.length()));
1701 tabularFeatures(bv, action, val);
1705 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1706 string const & special, bool & flag)
1708 if (special == "dl_above") {
1711 } else if (special == "dl_below") {
1712 ltt.bottomDL = flag;
1714 } else if (special == "empty") {
1724 void InsetTabular::tabularFeatures(BufferView * bv,
1725 LyXTabular::Feature feature,
1726 string const & value)
1732 bool setLines = false;
1733 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1734 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1737 case LyXTabular::M_ALIGN_LEFT:
1738 case LyXTabular::ALIGN_LEFT:
1739 setAlign = LYX_ALIGN_LEFT;
1741 case LyXTabular::M_ALIGN_RIGHT:
1742 case LyXTabular::ALIGN_RIGHT:
1743 setAlign = LYX_ALIGN_RIGHT;
1745 case LyXTabular::M_ALIGN_CENTER:
1746 case LyXTabular::ALIGN_CENTER:
1747 setAlign = LYX_ALIGN_CENTER;
1749 case LyXTabular::M_VALIGN_TOP:
1750 case LyXTabular::VALIGN_TOP:
1751 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1753 case LyXTabular::M_VALIGN_BOTTOM:
1754 case LyXTabular::VALIGN_BOTTOM:
1755 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1757 case LyXTabular::M_VALIGN_CENTER:
1758 case LyXTabular::VALIGN_CENTER:
1759 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1764 if (hasSelection()) {
1765 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1767 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1768 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1770 setUndo(bv, Undo::FINISH,
1771 bv->text->cursor.par(),
1772 bv->text->cursor.par()->next());
1774 int row = tabular->row_of_cell(actcell);
1775 int column = tabular->column_of_cell(actcell);
1777 LyXTabular::ltType ltt;
1780 case LyXTabular::SET_PWIDTH:
1782 LyXLength const vallen(value);
1783 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1785 bool const update = (tmplen != vallen);
1786 tabular->SetColumnPWidth(actcell, vallen);
1789 for (int i = 0; i < tabular->rows(); ++i) {
1790 cell = tabular->GetCellNumber(i,column);
1791 tabular->GetCellInset(cell)->resizeLyXText(bv);
1793 updateLocal(bv, INIT, true);
1797 case LyXTabular::SET_MPWIDTH:
1799 LyXLength const vallen(value);
1800 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1802 bool const update = (tmplen != vallen);
1803 tabular->SetMColumnPWidth(actcell, vallen);
1805 for (int i = 0; i < tabular->rows(); ++i) {
1806 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1809 updateLocal(bv, INIT, true);
1813 case LyXTabular::SET_SPECIAL_COLUMN:
1814 case LyXTabular::SET_SPECIAL_MULTI:
1815 tabular->SetAlignSpecial(actcell,value,feature);
1816 updateLocal(bv, FULL, true);
1818 case LyXTabular::APPEND_ROW:
1819 // append the row into the tabular
1820 unlockInsetInInset(bv, the_locking_inset);
1821 tabular->AppendRow(actcell);
1822 updateLocal(bv, INIT, true);
1824 case LyXTabular::APPEND_COLUMN:
1825 // append the column into the tabular
1826 unlockInsetInInset(bv, the_locking_inset);
1827 tabular->AppendColumn(actcell);
1828 actcell = tabular->GetCellNumber(row, column);
1829 updateLocal(bv, INIT, true);
1831 case LyXTabular::DELETE_ROW:
1832 unlockInsetInInset(bv, the_locking_inset);
1833 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1834 tabular->DeleteRow(sel_row_start);
1836 if (sel_row_start >= tabular->rows())
1838 actcell = tabular->GetCellNumber(sel_row_start, column);
1840 updateLocal(bv, INIT, true);
1842 case LyXTabular::DELETE_COLUMN:
1843 unlockInsetInInset(bv, the_locking_inset);
1844 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1845 tabular->DeleteColumn(sel_col_start);
1847 if (sel_col_start >= tabular->columns())
1849 actcell = tabular->GetCellNumber(row, sel_col_start);
1851 updateLocal(bv, INIT, true);
1853 case LyXTabular::M_TOGGLE_LINE_TOP:
1855 case LyXTabular::TOGGLE_LINE_TOP:
1857 bool lineSet = !tabular->TopLine(actcell, flag);
1858 for (int i = sel_row_start; i <= sel_row_end; ++i)
1859 for (int j = sel_col_start; j <= sel_col_end; ++j)
1860 tabular->SetTopLine(
1861 tabular->GetCellNumber(i, j),
1863 updateLocal(bv, INIT, true);
1867 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1869 case LyXTabular::TOGGLE_LINE_BOTTOM:
1871 bool lineSet = !tabular->BottomLine(actcell, flag);
1872 for (int i = sel_row_start; i <= sel_row_end; ++i)
1873 for (int j = sel_col_start; j <= sel_col_end; ++j)
1874 tabular->SetBottomLine(
1875 tabular->GetCellNumber(i, j),
1878 updateLocal(bv, INIT, true);
1882 case LyXTabular::M_TOGGLE_LINE_LEFT:
1884 case LyXTabular::TOGGLE_LINE_LEFT:
1886 bool lineSet = !tabular->LeftLine(actcell, flag);
1887 for (int i = sel_row_start; i <= sel_row_end; ++i)
1888 for (int j = sel_col_start; j <= sel_col_end; ++j)
1889 tabular->SetLeftLine(
1890 tabular->GetCellNumber(i,j),
1893 updateLocal(bv, INIT, true);
1897 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1899 case LyXTabular::TOGGLE_LINE_RIGHT:
1901 bool lineSet = !tabular->RightLine(actcell, flag);
1902 for (int i = sel_row_start; i <= sel_row_end; ++i)
1903 for (int j = sel_col_start; j <= sel_col_end; ++j)
1904 tabular->SetRightLine(
1905 tabular->GetCellNumber(i,j),
1908 updateLocal(bv, INIT, true);
1912 case LyXTabular::M_ALIGN_LEFT:
1913 case LyXTabular::M_ALIGN_RIGHT:
1914 case LyXTabular::M_ALIGN_CENTER:
1916 case LyXTabular::ALIGN_LEFT:
1917 case LyXTabular::ALIGN_RIGHT:
1918 case LyXTabular::ALIGN_CENTER:
1919 for (int i = sel_row_start; i <= sel_row_end; ++i)
1920 for (int j = sel_col_start; j <= sel_col_end; ++j)
1921 tabular->SetAlignment(
1922 tabular->GetCellNumber(i, j),
1925 updateLocal(bv, INIT, true);
1927 case LyXTabular::M_VALIGN_TOP:
1928 case LyXTabular::M_VALIGN_BOTTOM:
1929 case LyXTabular::M_VALIGN_CENTER:
1931 case LyXTabular::VALIGN_TOP:
1932 case LyXTabular::VALIGN_BOTTOM:
1933 case LyXTabular::VALIGN_CENTER:
1934 for (int i = sel_row_start; i <= sel_row_end; ++i)
1935 for (int j = sel_col_start; j <= sel_col_end; ++j)
1936 tabular->SetVAlignment(
1937 tabular->GetCellNumber(i, j),
1939 updateLocal(bv, INIT, true);
1941 case LyXTabular::MULTICOLUMN:
1943 if (sel_row_start != sel_row_end) {
1944 Alert::alert(_("Impossible Operation!"),
1945 _("Multicolumns can only be horizontally."),
1949 // just multicol for one Single Cell
1950 if (!hasSelection()) {
1951 // check wether we are completly in a multicol
1952 if (tabular->IsMultiColumn(actcell)) {
1953 tabular->UnsetMultiColumn(actcell);
1954 updateLocal(bv, INIT, true);
1956 tabular->SetMultiColumn(actcell, 1);
1957 updateLocal(bv, CELL, true);
1961 // we have a selection so this means we just add all this
1962 // cells to form a multicolumn cell
1966 if (sel_cell_start > sel_cell_end) {
1967 s_start = sel_cell_end;
1968 s_end = sel_cell_start;
1970 s_start = sel_cell_start;
1971 s_end = sel_cell_end;
1973 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1976 updateLocal(bv, INIT, true);
1979 case LyXTabular::SET_ALL_LINES:
1981 case LyXTabular::UNSET_ALL_LINES:
1982 for (int i = sel_row_start; i <= sel_row_end; ++i)
1983 for (int j = sel_col_start; j <= sel_col_end; ++j)
1984 tabular->SetAllLines(
1985 tabular->GetCellNumber(i,j), setLines);
1986 updateLocal(bv, INIT, true);
1988 case LyXTabular::SET_LONGTABULAR:
1989 tabular->SetLongTabular(true);
1990 updateLocal(bv, INIT, true); // because this toggles displayed
1992 case LyXTabular::UNSET_LONGTABULAR:
1993 tabular->SetLongTabular(false);
1994 updateLocal(bv, INIT, true); // because this toggles displayed
1996 case LyXTabular::SET_ROTATE_TABULAR:
1997 tabular->SetRotateTabular(true);
1999 case LyXTabular::UNSET_ROTATE_TABULAR:
2000 tabular->SetRotateTabular(false);
2002 case LyXTabular::SET_ROTATE_CELL:
2003 for (int i = sel_row_start; i <= sel_row_end; ++i)
2004 for (int j = sel_col_start; j<=sel_col_end; ++j)
2005 tabular->SetRotateCell(
2006 tabular->GetCellNumber(i, j),
2009 case LyXTabular::UNSET_ROTATE_CELL:
2010 for (int i = sel_row_start; i <= sel_row_end; ++i)
2011 for (int j = sel_col_start; j <= sel_col_end; ++j)
2012 tabular->SetRotateCell(
2013 tabular->GetCellNumber(i, j), false);
2015 case LyXTabular::SET_USEBOX:
2017 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2018 if (val == tabular->GetUsebox(actcell))
2019 val = LyXTabular::BOX_NONE;
2020 for (int i = sel_row_start; i <= sel_row_end; ++i)
2021 for (int j = sel_col_start; j <= sel_col_end; ++j)
2023 tabular->GetCellNumber(i, j), val);
2026 case LyXTabular::UNSET_LTFIRSTHEAD:
2028 case LyXTabular::SET_LTFIRSTHEAD:
2029 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2030 checkLongtableSpecial(ltt, value, flag);
2031 tabular->SetLTHead(row, flag, ltt, true);
2033 case LyXTabular::UNSET_LTHEAD:
2035 case LyXTabular::SET_LTHEAD:
2036 (void)tabular->GetRowOfLTHead(row, ltt);
2037 checkLongtableSpecial(ltt, value, flag);
2038 tabular->SetLTHead(row, flag, ltt, false);
2040 case LyXTabular::UNSET_LTFOOT:
2042 case LyXTabular::SET_LTFOOT:
2043 (void)tabular->GetRowOfLTFoot(row, ltt);
2044 checkLongtableSpecial(ltt, value, flag);
2045 tabular->SetLTFoot(row, flag, ltt, false);
2047 case LyXTabular::UNSET_LTLASTFOOT:
2049 case LyXTabular::SET_LTLASTFOOT:
2050 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2051 checkLongtableSpecial(ltt, value, flag);
2052 tabular->SetLTFoot(row, flag, ltt, true);
2054 case LyXTabular::SET_LTNEWPAGE:
2056 bool what = !tabular->GetLTNewPage(row);
2057 tabular->SetLTNewPage(row, what);
2060 // dummy stuff just to avoid warnings
2061 case LyXTabular::LAST_ACTION:
2067 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2070 UpdatableInset * inset =
2071 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2072 LyXFont font(LyXFont::ALL_SANE);
2074 x = inset->x() + inset->width(bv, font);
2075 y = inset->descent(bv, font);
2077 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2078 //inset_y = cursor.y();
2079 inset->edit(bv, x, y, button);
2080 if (!the_locking_inset)
2082 updateLocal(bv, CELL, false);
2083 return (the_locking_inset != 0);
2087 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2090 inset_x = cursor_.x()
2091 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2092 inset_y = cursor_.y();
2093 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2097 bool InsetTabular::insetHit(BufferView *, int x, int) const
2100 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2104 // This returns paperWidth() if the cell-width is unlimited or the width
2105 // in pixels if we have a pwidth for this cell.
2106 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2108 LyXLength const len = tabular->GetPWidth(cell);
2112 #ifdef WITH_WARNINGS
2113 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2115 return VSpace(len).inPixels(bv);
2119 int InsetTabular::getMaxWidth(BufferView * bv,
2120 UpdatableInset const * inset) const
2122 int cell = tabular->cur_cell;
2123 if (tabular->GetCellInset(cell) != inset) {
2125 if (tabular->GetCellInset(cell) != inset) {
2127 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2132 int const n = tabular->GetNumberOfCells();
2135 for (cell = 0; cell < n; ++cell) {
2136 if (tabular->GetCellInset(cell) == inset)
2142 lyxerr << "Own inset not found, shouldn't really happen!\n";
2146 int w = getMaxWidthOfCell(bv, cell);
2148 // because the inset then subtracts it's top_x and owner->x()
2149 w += (inset->x() - top_x);
2156 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2158 resizeLyXText(bv, recursive);
2162 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2165 for(int i = 0; i < tabular->rows(); ++i) {
2166 for(int j = 0; j < tabular->columns(); ++j) {
2167 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2175 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2176 bool const recursive) const
2178 if (the_locking_inset)
2179 return the_locking_inset->getLyXText(bv, recursive);
2181 // if we're locked lock the actual insettext and return it's LyXText!!!
2183 UpdatableInset * inset =
2184 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2185 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2186 return the_locking_inset->getLyXText(bv, recursive);
2189 return Inset::getLyXText(bv, recursive);
2193 bool InsetTabular::showInsetDialog(BufferView * bv) const
2195 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2196 bv->owner()->getDialogs()
2197 ->showTabular(const_cast<InsetTabular *>(this));
2202 void InsetTabular::openLayoutDialog(BufferView * bv) const
2204 if (the_locking_inset) {
2205 InsetTabular * i = static_cast<InsetTabular *>
2206 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2208 i->openLayoutDialog(bv);
2212 bv->owner()->getDialogs()->showTabular(
2213 const_cast<InsetTabular *>(this));
2218 // function returns an object as defined in func_status.h:
2219 // states OK, Unknown, Disabled, On, Off.
2221 FuncStatus InsetTabular::getStatus(string const & what) const
2223 int action = LyXTabular::LAST_ACTION;
2227 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2228 string const tmp = tabularFeature[i].feature;
2229 if (tmp == what.substr(0, tmp.length())) {
2230 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2231 // tabularFeatures[i].feature.length())) {
2232 action = tabularFeature[i].action;
2236 if (action == LyXTabular::LAST_ACTION) {
2238 return status.unknown(true);
2241 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2246 LyXTabular::ltType dummyltt;
2249 if (hasSelection()) {
2250 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2252 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2256 case LyXTabular::SET_PWIDTH:
2257 case LyXTabular::SET_MPWIDTH:
2258 case LyXTabular::SET_SPECIAL_COLUMN:
2259 case LyXTabular::SET_SPECIAL_MULTI:
2260 return status.disabled(true);
2262 case LyXTabular::APPEND_ROW:
2263 case LyXTabular::APPEND_COLUMN:
2264 case LyXTabular::DELETE_ROW:
2265 case LyXTabular::DELETE_COLUMN:
2266 case LyXTabular::SET_ALL_LINES:
2267 case LyXTabular::UNSET_ALL_LINES:
2268 return status.clear();
2270 case LyXTabular::MULTICOLUMN:
2271 status.setOnOff(tabular->IsMultiColumn(actcell));
2273 case LyXTabular::M_TOGGLE_LINE_TOP:
2275 case LyXTabular::TOGGLE_LINE_TOP:
2276 status.setOnOff(tabular->TopLine(actcell, flag));
2278 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2280 case LyXTabular::TOGGLE_LINE_BOTTOM:
2281 status.setOnOff(tabular->BottomLine(actcell, flag));
2283 case LyXTabular::M_TOGGLE_LINE_LEFT:
2285 case LyXTabular::TOGGLE_LINE_LEFT:
2286 status.setOnOff(tabular->LeftLine(actcell, flag));
2288 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2290 case LyXTabular::TOGGLE_LINE_RIGHT:
2291 status.setOnOff(tabular->RightLine(actcell, flag));
2293 case LyXTabular::M_ALIGN_LEFT:
2295 case LyXTabular::ALIGN_LEFT:
2296 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2298 case LyXTabular::M_ALIGN_RIGHT:
2300 case LyXTabular::ALIGN_RIGHT:
2301 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2303 case LyXTabular::M_ALIGN_CENTER:
2305 case LyXTabular::ALIGN_CENTER:
2306 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2308 case LyXTabular::M_VALIGN_TOP:
2310 case LyXTabular::VALIGN_TOP:
2311 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2313 case LyXTabular::M_VALIGN_BOTTOM:
2315 case LyXTabular::VALIGN_BOTTOM:
2316 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2318 case LyXTabular::M_VALIGN_CENTER:
2320 case LyXTabular::VALIGN_CENTER:
2321 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2323 case LyXTabular::SET_LONGTABULAR:
2324 status.setOnOff(tabular->IsLongTabular());
2326 case LyXTabular::UNSET_LONGTABULAR:
2327 status.setOnOff(!tabular->IsLongTabular());
2329 case LyXTabular::SET_ROTATE_TABULAR:
2330 status.setOnOff(tabular->GetRotateTabular());
2332 case LyXTabular::UNSET_ROTATE_TABULAR:
2333 status.setOnOff(!tabular->GetRotateTabular());
2335 case LyXTabular::SET_ROTATE_CELL:
2336 status.setOnOff(tabular->GetRotateCell(actcell));
2338 case LyXTabular::UNSET_ROTATE_CELL:
2339 status.setOnOff(!tabular->GetRotateCell(actcell));
2341 case LyXTabular::SET_USEBOX:
2342 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2344 case LyXTabular::SET_LTFIRSTHEAD:
2345 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2347 case LyXTabular::SET_LTHEAD:
2348 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2350 case LyXTabular::SET_LTFOOT:
2351 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2353 case LyXTabular::SET_LTLASTFOOT:
2354 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2356 case LyXTabular::SET_LTNEWPAGE:
2357 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2361 status.disabled(true);
2368 std::vector<string> const InsetTabular::getLabelList() const
2370 return tabular->getLabelList();
2374 bool InsetTabular::copySelection(BufferView * bv)
2376 if (!hasSelection())
2379 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2380 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2381 if (sel_col_start > sel_col_end) {
2382 sel_col_start = sel_col_end;
2383 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2385 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2387 int const columns = sel_col_end - sel_col_start + 1;
2389 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2390 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2391 if (sel_row_start > sel_row_end) {
2392 swap(sel_row_start, sel_row_end);
2394 int const rows = sel_row_end - sel_row_start + 1;
2396 delete paste_tabular;
2397 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2398 for (int i = 0; i < sel_row_start; ++i)
2399 paste_tabular->DeleteRow(0);
2400 while (paste_tabular->rows() > rows)
2401 paste_tabular->DeleteRow(rows);
2402 paste_tabular->SetTopLine(0, true, true);
2403 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2405 for (int i = 0; i < sel_col_start; ++i)
2406 paste_tabular->DeleteColumn(0);
2407 while (paste_tabular->columns() > columns)
2408 paste_tabular->DeleteColumn(columns);
2409 paste_tabular->SetLeftLine(0, true, true);
2410 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2414 paste_tabular->ascii(bv->buffer(), sstr,
2415 (int)parOwner()->params().depth(), true, '\t');
2416 bv->stuffClipboard(sstr.str().c_str());
2421 bool InsetTabular::pasteSelection(BufferView * bv)
2426 for (int r1 = 0, r2 = actrow;
2427 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2429 for(int c1 = 0, c2 = actcol;
2430 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2432 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2433 tabular->IsPartOfMultiColumn(r2,c2))
2435 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2439 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2443 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2444 int const n2 = tabular->GetCellNumber(r2, c2);
2445 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2446 tabular->GetCellInset(n2)->setOwner(this);
2447 tabular->GetCellInset(n2)->deleteLyXText(bv);
2454 bool InsetTabular::cutSelection()
2456 if (!hasSelection())
2459 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2460 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2461 if (sel_col_start > sel_col_end) {
2462 sel_col_start = sel_col_end;
2463 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2465 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2467 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2468 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2469 if (sel_row_start > sel_row_end) {
2470 swap(sel_row_start, sel_row_end);
2472 if (sel_cell_start > sel_cell_end) {
2473 swap(sel_cell_start, sel_cell_end);
2475 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2476 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2477 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2484 bool InsetTabular::isRightToLeft(BufferView *bv )
2486 return bv->getParentLanguage(this)->RightToLeft();
2490 bool InsetTabular::nodraw() const
2492 if (!UpdatableInset::nodraw() && the_locking_inset)
2493 return the_locking_inset->nodraw();
2494 return UpdatableInset::nodraw();
2498 int InsetTabular::scroll(bool recursive) const
2500 int sx = UpdatableInset::scroll(false);
2502 if (recursive && the_locking_inset)
2503 sx += the_locking_inset->scroll(recursive);
2509 bool InsetTabular::doClearArea() const
2511 return !locked || (need_update & (FULL|INIT));
2515 void InsetTabular::getSelection(int & srow, int & erow,
2516 int & scol, int & ecol) const
2518 int const start = hasSelection() ? sel_cell_start : actcell;
2519 int const end = hasSelection() ? sel_cell_end : actcell;
2521 srow = tabular->row_of_cell(start);
2522 erow = tabular->row_of_cell(end);
2527 scol = tabular->column_of_cell(start);
2528 ecol = tabular->column_of_cell(end);
2532 ecol = tabular->right_column_of_cell(end);
2537 Paragraph * InsetTabular::getParFromID(int id) const
2540 for(int i = 0; i < tabular->rows(); ++i) {
2541 for(int j = 0; j < tabular->columns(); ++j) {
2542 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2550 Paragraph * InsetTabular::firstParagraph() const
2552 if (the_locking_inset)
2553 return the_locking_inset->firstParagraph();
2558 Paragraph * InsetTabular::getFirstParagraph(int i) const
2560 return (i < tabular->GetNumberOfCells())
2561 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2566 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2568 if (the_locking_inset)
2569 return the_locking_inset->cursor(bv);
2570 return Inset::cursor(bv);
2574 Inset * InsetTabular::getInsetFromID(int id_arg) const
2577 return const_cast<InsetTabular *>(this);
2580 for(int i = 0; i < tabular->rows(); ++i) {
2581 for(int j = 0; j < tabular->columns(); ++j) {
2582 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2591 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2594 if (the_locking_inset) {
2595 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2600 if (tabular->IsLastCell(actcell)) {
2601 bv->unlockInset(const_cast<InsetTabular *>(this));
2607 // otherwise we have to lock the next inset and ask for it's selecttion
2608 UpdatableInset * inset =
2609 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2610 inset->edit(bv, 0, 0, 0);
2611 string const str(selectNextWordInt(bv, value));
2619 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2621 // when entering this function the inset should be ALWAYS locked!
2622 lyx::Assert(the_locking_inset);
2624 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2628 if (tabular->IsLastCell(actcell)) {
2629 bv->unlockInset(const_cast<InsetTabular *>(this));
2633 // otherwise we have to lock the next inset and ask for it's selecttion
2634 UpdatableInset * inset =
2635 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2637 return selectNextWordInt(bv, value);
2641 void InsetTabular::selectSelectedWord(BufferView * bv)
2643 if (the_locking_inset) {
2644 the_locking_inset->selectSelectedWord(bv);
2651 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2653 if (the_locking_inset) {
2654 the_locking_inset->toggleSelection(bv, kill_selection);
2659 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2663 if (the_locking_inset) {
2664 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2666 updateLocal(bv, CELL, false);
2669 if (tabular->IsLastCell(actcell)) {
2671 bv->unlockInset(const_cast<InsetTabular *>(this));
2676 // otherwise we have to lock the next inset and search there
2677 UpdatableInset * inset =
2678 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2680 bool const ret = searchForward(bv, str, cs, mw);
2682 updateLocal(bv, CELL, false);
2687 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2691 if (the_locking_inset) {
2692 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2694 updateLocal(bv, CELL, false);
2697 if (!actcell) { // we are already in the first cell
2699 bv->unlockInset(const_cast<InsetTabular *>(this));
2704 // otherwise we have to lock the next inset and search there
2705 UpdatableInset * inset =
2706 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2707 inset->edit(bv, false);
2708 bool const ret = searchBackward(bv, str, cs, mw);
2710 updateLocal(bv, CELL, false);
2715 bool InsetTabular::insetAllowed(Inset::Code code) const
2717 if (the_locking_inset)
2718 return the_locking_inset->insetAllowed(code);
2723 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2725 int const n = tabular->GetNumberOfCells();
2726 static int last = 0;
2728 // maybe some speedup
2729 if ((last < n) && tabular->GetCellInset(last) == in) {
2730 if (tabular->GetPWidth(last+1).zero())
2734 if ((++last < n) && tabular->GetCellInset(last) == in) {
2735 if (tabular->GetPWidth(last).zero())
2740 for(int i=0; i < n; ++i) {
2741 if (tabular->GetCellInset(i) == in) {
2743 if (tabular->GetPWidth(i).zero())
2749 // well we didn't obviously find it so maybe our owner knows more
2751 return owner()->forceDefaultParagraphs(in);
2752 // if we're here there is really something strange going on!!!