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"
28 #include "insets/insettext.h"
33 #include "BufferView.h"
34 #include "undo_funcs.h"
35 #include "lyxlength.h"
36 #include "ParagraphParameters.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/Alert.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
61 int const ADD_TO_HEIGHT = 2;
62 int const ADD_TO_TABULAR_WIDTH = 2;
65 LyXTabular * paste_tabular = 0;
68 struct TabularFeature {
69 LyXTabular::Feature action;
74 TabularFeature tabularFeature[] =
76 { LyXTabular::APPEND_ROW, "append-row" },
77 { LyXTabular::APPEND_COLUMN, "append-column" },
78 { LyXTabular::DELETE_ROW, "delete-row" },
79 { LyXTabular::DELETE_COLUMN, "delete-column" },
80 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
81 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
82 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
83 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
84 { LyXTabular::ALIGN_LEFT, "align-left" },
85 { LyXTabular::ALIGN_RIGHT, "align-right" },
86 { LyXTabular::ALIGN_CENTER, "align-center" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
125 bool InsetTabular::hasPasteBuffer() const
127 return (paste_tabular != 0);
131 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
138 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
139 // for now make it always display as display() inset
141 the_locking_inset = 0;
142 old_locking_inset = 0;
145 actrow = actcell = 0;
149 in_reset_pos = false;
155 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
157 : UpdatableInset(tab, same_id), buffer(&buf)
159 tabular.reset(new LyXTabular(buf.params,
160 this, *(tab.tabular), same_id));
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
169 in_reset_pos = false;
175 InsetTabular::~InsetTabular()
181 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
183 return new InsetTabular(*this, buf, same_id);
187 void InsetTabular::write(Buffer const * buf, ostream & os) const
189 os << " Tabular" << endl;
190 tabular->Write(buf, os);
194 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
196 bool const old_format = (lex.getString() == "\\LyXTable");
198 tabular.reset(new LyXTabular(buf, this, lex));
206 string token = lex.getString();
207 while (lex.isOK() && (token != "\\end_inset")) {
209 token = lex.getString();
211 if (token != "\\end_inset") {
212 lex.printError("Missing \\end_inset at this point. "
218 int InsetTabular::ascent(BufferView *, LyXFont const &) const
220 return tabular->GetAscentOfRow(0);
224 int InsetTabular::descent(BufferView *, LyXFont const &) const
226 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
230 int InsetTabular::width(BufferView *, LyXFont const &) const
232 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
236 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
237 float & x, bool cleared) const
245 if (need_update == INIT) {
246 if (calculate_dimensions_of_cells(bv, font, true))
247 bv->text->status = LyXText::CHANGED_IN_DRAW;
252 Painter & pain = bv->painter();
258 UpdatableInset::draw(bv, font, baseline, x, cleared);
261 x += static_cast<float>(scroll());
263 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
264 (top_x != int(x)) || (top_baseline != baseline)))
266 int h = ascent(bv, font) + descent(bv, font);
267 int const tx = display() || !owner() ? 0 : top_x;
268 int w = tx ? width(bv, font) : pain.paperWidth();
269 int ty = baseline - ascent(bv, font);
273 if ((ty + h) > pain.paperHeight())
274 h = pain.paperHeight();
275 if ((top_x + w) > pain.paperWidth())
276 w = pain.paperWidth();
277 pain.fillRectangle(tx, ty, w, h, backgroundColor());
283 top_baseline = baseline;
284 x += ADD_TO_TABULAR_WIDTH;
288 first_visible_cell = -1;
289 for (i = 0; i < tabular->rows(); ++i) {
291 cell = tabular->GetCellNumber(i, 0);
292 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
293 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
295 baseline += tabular->GetDescentOfRow(i) +
296 tabular->GetAscentOfRow(i + 1) +
297 tabular->GetAdditionalHeight(i + 1);
300 for (j = 0; j < tabular->columns(); ++j) {
301 if (nx > bv->workWidth())
303 if (tabular->IsPartOfMultiColumn(i, j))
305 cx = nx + tabular->GetBeginningOfTextInCell(cell);
306 if (first_visible_cell < 0)
307 first_visible_cell = cell;
308 if (hasSelection()) {
309 drawCellSelection(pain, nx, baseline, i, j, cell);
312 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
313 drawCellLines(pain, nx, baseline, i, cell);
314 nx += tabular->GetWidthOfColumn(cell);
317 baseline += tabular->GetDescentOfRow(i) +
318 tabular->GetAscentOfRow(i + 1) +
319 tabular->GetAdditionalHeight(i + 1);
321 } else if (need_update == CELL) {
324 if (the_locking_inset &&
325 tabular->GetCellInset(actcell) != the_locking_inset)
327 Inset * inset = tabular->GetCellInset(cell);
329 inset != the_locking_inset && i < tabular->rows();
333 inset != the_locking_inset && j < tabular->columns();
336 if (tabular->IsPartOfMultiColumn(i, j))
338 nx += tabular->GetWidthOfColumn(cell);
340 inset = tabular->GetCellInset(cell);
342 if (tabular->row_of_cell(cell) > i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
350 // compute baseline for actual row
351 for (i = 0; i < actrow; ++i) {
352 baseline += tabular->GetDescentOfRow(i) +
353 tabular->GetAscentOfRow(i + 1) +
354 tabular->GetAdditionalHeight(i + 1);
356 // now compute the right x position
357 cell = tabular->GetCellNumber(actrow, 0);
358 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
359 if (tabular->IsPartOfMultiColumn(actrow, j))
361 nx += tabular->GetWidthOfColumn(cell);
365 i = tabular->row_of_cell(cell);
366 if (the_locking_inset != tabular->GetCellInset(cell)) {
367 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
370 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
372 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
374 // Here we use rectangular backgroundColor patches to clean up
375 // within a cell around the cell's red inset box. As follows:
377 // +--------------------+
378 // | C | The rectangles are A, B and C
379 // | A |------------| B | below, origin top left (tx, ty),
380 // | | inset box | | dimensions w(idth), h(eight).
381 // +---+------------+---+ x grows rightward, y downward
383 // +--------------------+
386 // clear only if we didn't have a change
387 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
389 // clear before the inset
392 ty = baseline - tabular->GetAscentOfRow(i) + 1;
393 w = int(cx - nx - 1);
394 h = tabular->GetAscentOfRow(i) +
395 tabular->GetDescentOfRow(i) - 1;
396 pain.fillRectangle(tx, ty, w, h, backgroundColor());
397 // clear behind the inset
398 tx = int(cx + the_locking_inset->width(bv,font) + 1);
399 ty = baseline - tabular->GetAscentOfRow(i) + 1;
400 w = tabular->GetWidthOfColumn(cell) -
401 tabular->GetBeginningOfTextInCell(cell) -
402 the_locking_inset->width(bv,font) -
403 tabular->GetAdditionalWidth(cell) - 1;
404 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
405 pain.fillRectangle(tx, ty, w, h, backgroundColor());
406 // clear below the inset
408 ty = baseline + the_locking_inset->descent(bv, font) + 1;
409 w = tabular->GetWidthOfColumn(cell) -
410 tabular->GetAdditionalWidth(cell) - 1;
411 h = tabular->GetDescentOfRow(i) -
412 the_locking_inset->descent(bv, font) - 1;
413 pain.fillRectangle(tx, ty, w, h, backgroundColor());
414 // clear above the inset
416 ty = baseline - tabular->GetAscentOfRow(i) + 1;
417 w = tabular->GetWidthOfColumn(cell) -
418 tabular->GetAdditionalWidth(cell) - 1;
419 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
420 pain.fillRectangle(tx, ty, w, h, backgroundColor());
425 x -= ADD_TO_TABULAR_WIDTH;
426 x += width(bv, font);
427 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
429 for(Inset * inset = owner(); inset; ++i)
430 inset = inset->owner();
431 if (calculate_dimensions_of_cells(bv, font, false))
439 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
440 int row, int cell) const
442 int x2 = x + tabular->GetWidthOfColumn(cell);
445 if (!tabular->TopAlreadyDrawed(cell)) {
446 on_off = !tabular->TopLine(cell);
447 pain.line(x, baseline - tabular->GetAscentOfRow(row),
448 x2, baseline - tabular->GetAscentOfRow(row),
449 on_off ? LColor::tabularonoffline : LColor::tabularline,
450 on_off ? Painter::line_onoffdash : Painter::line_solid);
452 on_off = !tabular->BottomLine(cell);
453 pain.line(x,baseline + tabular->GetDescentOfRow(row),
454 x2, baseline + tabular->GetDescentOfRow(row),
455 on_off ? LColor::tabularonoffline : LColor::tabularline,
456 on_off ? Painter::line_onoffdash : Painter::line_solid);
457 if (!tabular->LeftAlreadyDrawed(cell)) {
458 on_off = !tabular->LeftLine(cell);
459 pain.line(x, baseline - tabular->GetAscentOfRow(row),
460 x, baseline + tabular->GetDescentOfRow(row),
461 on_off ? LColor::tabularonoffline : LColor::tabularline,
462 on_off ? Painter::line_onoffdash : Painter::line_solid);
464 on_off = !tabular->RightLine(cell);
465 pain.line(x2 - tabular->GetAdditionalWidth(cell),
466 baseline - tabular->GetAscentOfRow(row),
467 x2 - tabular->GetAdditionalWidth(cell),
468 baseline + tabular->GetDescentOfRow(row),
469 on_off ? LColor::tabularonoffline : LColor::tabularline,
470 on_off ? Painter::line_onoffdash : Painter::line_solid);
474 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
475 int row, int column, int cell) const
477 lyx::Assert(hasSelection());
478 int cs = tabular->column_of_cell(sel_cell_start);
479 int ce = tabular->column_of_cell(sel_cell_end);
482 cs = tabular->column_of_cell(sel_cell_end);
484 ce = tabular->right_column_of_cell(sel_cell_end);
487 int rs = tabular->row_of_cell(sel_cell_start);
488 int re = tabular->row_of_cell(sel_cell_end);
492 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
493 int w = tabular->GetWidthOfColumn(cell);
494 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
495 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
496 w, h, LColor::selection);
501 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
507 owner()->update(bv, font, true);
514 if (calculate_dimensions_of_cells(bv, font, true))
517 owner()->update(bv, font, true);
521 if (the_locking_inset)
522 the_locking_inset->update(bv, font, reinit);
523 if (need_update < FULL &&
524 bv->text->status() == LyXText::NEED_MORE_REFRESH)
529 switch (need_update) {
533 if (calculate_dimensions_of_cells(bv, font, false))
546 string const InsetTabular::editMessage() const
548 return _("Opened Tabular Inset");
552 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
554 UpdatableInset::edit(bv, x, y, button);
556 if (!bv->lockInset(this)) {
557 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
561 the_locking_inset = 0;
567 if (insetHit(bv, x, y) && (button != 3)) {
568 activateCellInsetAbs(bv, x, y, button);
573 void InsetTabular::edit(BufferView * bv, bool front)
575 UpdatableInset::edit(bv, front);
577 if (!bv->lockInset(this)) {
578 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
582 the_locking_inset = 0;
588 actcell = tabular->GetNumberOfCells() - 1;
595 void InsetTabular::insetUnlock(BufferView * bv)
597 if (the_locking_inset) {
598 the_locking_inset->insetUnlock(bv);
599 the_locking_inset = 0;
604 if (scroll(false) || hasSelection()) {
609 updateLocal(bv, FULL, false);
614 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
615 bool mark_dirty) const
619 calculate_dimensions_of_cells(bv, font, true);
621 if (need_update < what) // only set this if it has greater update
623 #if 0 // maybe this should not be done!
624 if ((what == INIT) && hasSelection()) {
629 if (need_update != NONE) {
630 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
631 if (locked) // && (what != NONE))
637 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
639 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
644 if (inset == tabular->GetCellInset(actcell)) {
645 lyxerr[Debug::INSETTEXT] << "OK" << endl;
646 the_locking_inset = tabular->GetCellInset(actcell);
649 } else if (!the_locking_inset) {
650 int const n = tabular->GetNumberOfCells();
651 int const id = inset->id();
652 for (int i = 0; i < n; ++i) {
653 InsetText * in = tabular->GetCellInset(i);
656 the_locking_inset = in;
661 if (in->getInsetFromID(id)) {
664 return the_locking_inset->lockInsetInInset(bv, inset);
667 } else if (the_locking_inset && (the_locking_inset == inset)) {
668 lyxerr[Debug::INSETTEXT] << "OK" << endl;
670 } else if (the_locking_inset) {
671 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
672 return the_locking_inset->lockInsetInInset(bv, inset);
674 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
679 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
682 if (!the_locking_inset)
684 if (the_locking_inset == inset) {
685 the_locking_inset->insetUnlock(bv);
686 the_locking_inset = 0;
688 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
694 updateLocal(bv, CELL, false);
695 showInsetCursor(bv, false);
698 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
699 if (inset->lyxCode() == TABULAR_CODE &&
700 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
701 bv->owner()->getDialogs()->updateTabular(this);
710 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
712 if (!the_locking_inset)
714 if (the_locking_inset != inset) {
715 if (!the_locking_inset->updateInsetInInset(bv, inset))
718 updateLocal(bv, CELL, false);
723 unsigned int InsetTabular::insetInInsetY()
725 if (!the_locking_inset)
727 return inset_y + the_locking_inset->insetInInsetY();
731 UpdatableInset * InsetTabular::getLockingInset() const
733 return the_locking_inset ? the_locking_inset->getLockingInset() :
734 const_cast<InsetTabular *>(this);
738 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
742 if (the_locking_inset)
743 return the_locking_inset->getFirstLockingInsetOfType(c);
748 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
750 if (the_locking_inset)
751 return the_locking_inset->insertInset(bv, inset);
756 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
758 if (hasSelection() && (button == 3))
761 if (hasSelection()) {
763 updateLocal(bv, SELECTION, false);
766 int const ocell = actcell;
767 int const orow = actrow;
772 updateLocal(bv, NONE, false);
776 if ((ocell != actcell) && the_locking_inset) {
777 the_locking_inset->insetUnlock(bv);
778 the_locking_inset = 0;
785 bool const inset_hit = insetHit(bv, x, y);
787 if ((ocell == actcell) && the_locking_inset && inset_hit) {
789 the_locking_inset->insetButtonPress(bv,
790 x - inset_x, y - inset_y,
793 } else if (the_locking_inset) {
794 the_locking_inset->insetUnlock(bv);
796 the_locking_inset = 0;
798 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
801 if (inset_hit && bv->theLockingInset()) {
802 if (activateCellInsetAbs(bv, x, y, button))
803 the_locking_inset->insetButtonPress(bv,
813 bool InsetTabular::insetButtonRelease(BufferView * bv,
814 int x, int y, int button)
817 if (the_locking_inset)
818 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
819 y - inset_y, button);
820 if (button == 3 && !ret) {
821 bv->owner()->getDialogs()->showTabular(this);
828 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
830 if (the_locking_inset) {
831 the_locking_inset->insetMotionNotify(bv,
839 // int const old_cell = actcell;
842 if (!hasSelection()) {
843 setSelection(actcell, actcell);
845 setSelection(sel_cell_start, actcell);
847 updateLocal(bv, SELECTION, false);
852 void InsetTabular::insetKeyPress(XKeyEvent * xke)
854 if (the_locking_inset) {
855 the_locking_inset->insetKeyPress(xke);
861 UpdatableInset::RESULT
862 InsetTabular::localDispatch(BufferView * bv, kb_action action,
865 // We need to save the value of the_locking_inset as the call to
866 // the_locking_inset->LocalDispatch might unlock it.
867 old_locking_inset = the_locking_inset;
868 UpdatableInset::RESULT result =
869 UpdatableInset::localDispatch(bv, action, arg);
870 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
875 if ((action < 0) && arg.empty())
878 bool hs = hasSelection();
881 // this one have priority over the locked InsetText, if we're not already
882 // inside another tabular then that one get's priority!
883 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
888 unlockInsetInInset(bv, the_locking_inset);
889 if (action == LFUN_TAB)
890 moveNextCell(bv, old_locking_inset != 0);
892 movePrevCell(bv, old_locking_inset != 0);
895 updateLocal(bv, SELECTION, false);
896 if (!the_locking_inset) {
898 return DISPATCHED_NOUPDATE;
901 // this to avoid compiler warnings.
907 if (the_locking_inset) {
908 result = the_locking_inset->localDispatch(bv, action, arg);
909 if (result == DISPATCHED_NOUPDATE) {
912 if (sc != scroll()) { // inset has been scrolled
913 the_locking_inset->toggleInsetCursor(bv);
914 updateLocal(bv, FULL, false);
915 the_locking_inset->toggleInsetCursor(bv);
918 } else if (result == DISPATCHED) {
919 the_locking_inset->toggleInsetCursor(bv);
920 updateLocal(bv, CELL, false);
921 the_locking_inset->toggleInsetCursor(bv);
923 } else if (result == FINISHED_UP) {
925 } else if (result == FINISHED_DOWN) {
927 } else if (result == FINISHED_RIGHT) {
935 // --- Cursor Movements ----------------------------------
936 case LFUN_RIGHTSEL: {
937 int const start = hasSelection() ? sel_cell_start : actcell;
938 if (tabular->IsLastCellInRow(actcell)) {
939 setSelection(start, actcell);
944 // if we are starting a selection, only select
945 // the current cell at the beginning
946 if (hasSelection()) {
947 moveRight(bv, false);
950 setSelection(start, end);
951 updateLocal(bv, SELECTION, false);
955 result = moveRight(bv);
958 updateLocal(bv, SELECTION, false);
961 int const start = hasSelection() ? sel_cell_start : actcell;
962 if (tabular->IsFirstCellInRow(actcell)) {
963 setSelection(start, actcell);
968 // if we are starting a selection, only select
969 // the current cell at the beginning
970 if (hasSelection()) {
974 setSelection(start, end);
975 updateLocal(bv, SELECTION, false);
979 result = moveLeft(bv);
982 updateLocal(bv, SELECTION, false);
985 int const start = hasSelection() ? sel_cell_start : actcell;
986 int const ocell = actcell;
987 // if we are starting a selection, only select
988 // the current cell at the beginning
989 if (hasSelection()) {
991 if ((ocell == sel_cell_end) ||
992 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
993 setSelection(start, tabular->GetCellBelow(sel_cell_end));
995 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
997 setSelection(start, start);
999 updateLocal(bv, SELECTION, false);
1003 result = moveDown(bv, old_locking_inset != 0);
1006 updateLocal(bv, SELECTION, false);
1010 int const start = hasSelection() ? sel_cell_start : actcell;
1011 int const ocell = actcell;
1012 // if we are starting a selection, only select
1013 // the current cell at the beginning
1014 if (hasSelection()) {
1016 if ((ocell == sel_cell_end) ||
1017 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1018 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1020 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1022 setSelection(start, start);
1024 updateLocal(bv, SELECTION, false);
1028 result = moveUp(bv, old_locking_inset != 0);
1031 updateLocal(bv, SELECTION, false);
1034 UpdateCodes code = CURSOR;
1039 int column = actcol;
1040 unlockInsetInInset(bv, the_locking_inset);
1041 if (bv->text->first_y + bv->painter().paperHeight() <
1042 (top_baseline + tabular->GetHeightOfTabular()))
1044 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1046 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1048 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1051 updateLocal(bv, code, false);
1055 UpdateCodes code = CURSOR;
1060 int column = actcol;
1061 unlockInsetInInset(bv, the_locking_inset);
1062 if (top_baseline < 0) {
1063 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1065 if (top_baseline > 0)
1068 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1073 updateLocal(bv, code, false);
1076 // none of these make sense for insettabular,
1077 // but we must catch them to prevent any
1078 // selection from being confused
1082 case LFUN_WORDLEFTSEL:
1083 case LFUN_WORDRIGHT:
1084 case LFUN_WORDRIGHTSEL:
1085 case LFUN_DOWN_PARAGRAPH:
1086 case LFUN_DOWN_PARAGRAPHSEL:
1087 case LFUN_UP_PARAGRAPH:
1088 case LFUN_UP_PARAGRAPHSEL:
1089 case LFUN_BACKSPACE:
1095 case LFUN_BEGINNINGBUF:
1096 case LFUN_BEGINNINGBUFSEL:
1098 case LFUN_ENDBUFSEL:
1100 case LFUN_LAYOUT_TABULAR:
1101 bv->owner()->getDialogs()->showTabular(this);
1103 case LFUN_TABULAR_FEATURE:
1104 if (!tabularFeatures(bv, arg))
1105 result = UNDISPATCHED;
1108 if (!copySelection(bv))
1110 setUndo(bv, Undo::DELETE,
1111 bv->text->cursor.par(),
1112 bv->text->cursor.par()->next());
1114 updateLocal(bv, INIT, true);
1117 if (!hasSelection())
1122 case LFUN_PASTESELECTION:
1124 string const clip(bv->getClipboard());
1128 if (clip.find('\t') != string::npos) {
1132 string::size_type len = clip.length();
1133 string::size_type p = 0;
1136 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1144 maxCols = max(cols, maxCols);
1150 maxCols = max(cols, maxCols);
1151 delete paste_tabular;
1152 paste_tabular = new LyXTabular(bv->buffer()->params,
1153 this, rows, maxCols);
1154 string::size_type op = 0;
1156 int cells = paste_tabular->GetNumberOfCells();
1158 while ((cell < cells) && (p < len) &&
1159 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1164 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1169 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1170 while (cols++ < maxCols)
1178 // check for the last cell if there is no trailing '\n'
1179 if ((cell < cells) && (op < len))
1180 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1182 // so that the clipboard is used and it goes on
1184 // and executes LFUN_PASTESELECTION in insettext!
1185 delete paste_tabular;
1190 if (hasPasteBuffer()) {
1191 setUndo(bv, Undo::INSERT,
1192 bv->text->cursor.par(),
1193 bv->text->cursor.par()->next());
1195 updateLocal(bv, INIT, true);
1198 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1200 // handle font changing stuff on selection before we lock the inset
1201 // in the default part!
1202 result = UNDISPATCHED;
1213 case LFUN_UNDERLINE:
1214 case LFUN_FONT_SIZE:
1215 if (bv->Dispatch(action, arg))
1216 result = DISPATCHED;
1222 // we try to activate the actual inset and put this event down to
1223 // the insets dispatch function.
1224 if ((result == DISPATCHED) || the_locking_inset)
1227 if (activateCellInset(bv)) {
1228 // reset need_update setted in above function!
1230 result = the_locking_inset->localDispatch(bv, action, arg);
1231 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1232 unlockInsetInInset(bv, the_locking_inset);
1234 // we need to update if this was requested before
1235 updateLocal(bv, NONE, false);
1236 return UNDISPATCHED;
1239 // so the below CELL is not set because this is higher
1240 // priority and we get a full redraw
1241 need_update = SELECTION;
1244 updateLocal(bv, CELL, false);
1249 if (result < FINISHED) {
1250 if (!the_locking_inset) {
1251 showInsetCursor(bv);
1254 bv->unlockInset(this);
1259 int InsetTabular::latex(Buffer const * buf, ostream & os,
1260 bool fragile, bool fp) const
1262 return tabular->latex(buf, os, fragile, fp);
1266 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1269 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1271 return tabular->ascii(buf, os, 0, false,0);
1275 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1278 int const ret = tabular->ascii(buf,os,
1279 (int)parOwner()->params().depth(),
1286 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1291 // if the table is inside a float it doesn't need the informaltable
1292 // wrapper. Search for it.
1293 for(master = owner();
1294 master && master->lyxCode() != Inset::FLOAT_CODE;
1295 master = master->owner());
1298 os << "<informaltable>\n";
1301 ret+= tabular->docBook(buf,os);
1303 os << "</informaltable>\n";
1310 void InsetTabular::validate(LaTeXFeatures & features) const
1312 tabular->Validate(features);
1316 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1317 LyXFont const & font,
1324 bool changed = false;
1326 // if we have a locking_inset we should have to check only this cell for
1327 // change so I'll try this to have a boost, but who knows ;)
1328 if ((need_update != INIT) &&
1329 (the_locking_inset == tabular->GetCellInset(actcell))) {
1330 for(int i = 0; i < tabular->columns(); ++i) {
1331 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1333 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1336 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1337 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1338 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1341 for (int i = 0; i < tabular->rows(); ++i) {
1344 for (int j = 0; j < tabular->columns(); ++j) {
1345 if (tabular->IsPartOfMultiColumn(i,j))
1348 inset = tabular->GetCellInset(cell);
1349 if (!reinit && !tabular->GetPWidth(cell).zero())
1350 inset->update(bv, font, false);
1351 maxAsc = max(maxAsc, inset->ascent(bv, font));
1352 maxDesc = max(maxDesc, inset->descent(bv, font));
1353 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1355 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1356 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1364 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1366 if (the_locking_inset) {
1367 the_locking_inset->getCursorPos(bv, x, y);
1370 x = cursor_.x() - top_x;
1375 void InsetTabular::toggleInsetCursor(BufferView * bv)
1378 if (isCursorVisible())
1379 bv->hideLockedInsetCursor();
1382 if (the_locking_inset) {
1383 the_locking_inset->toggleInsetCursor(bv);
1387 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1389 int const asc = lyxfont::maxAscent(font);
1390 int const desc = lyxfont::maxDescent(font);
1392 if (isCursorVisible())
1393 bv->hideLockedInsetCursor();
1395 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1396 toggleCursorVisible();
1400 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1404 if (!isCursorVisible()) {
1405 LyXFont font; // = GetFont(par, cursor.pos);
1407 int const asc = lyxfont::maxAscent(font);
1408 int const desc = lyxfont::maxDescent(font);
1409 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1411 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1412 setCursorVisible(true);
1417 void InsetTabular::hideInsetCursor(BufferView * bv)
1419 if (isCursorVisible()) {
1420 bv->hideLockedInsetCursor();
1421 setCursorVisible(false);
1426 void InsetTabular::fitInsetCursor(BufferView * bv) const
1428 if (the_locking_inset) {
1429 the_locking_inset->fitInsetCursor(bv);
1434 int const asc = lyxfont::maxAscent(font);
1435 int const desc = lyxfont::maxDescent(font);
1436 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1440 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1444 actcell = actrow = actcol = 0;
1445 int ly = tabular->GetDescentOfRow(actrow);
1447 // first search the right row
1448 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1449 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1450 tabular->GetAscentOfRow(actrow + 1) +
1451 tabular->GetAdditionalHeight(actrow + 1));
1453 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1455 actcell = tabular->GetCellNumber(actrow, actcol);
1457 // now search the right column
1458 int lx = tabular->GetWidthOfColumn(actcell) -
1459 tabular->GetAdditionalWidth(actcell);
1460 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1461 lx += tabular->GetWidthOfColumn(actcell + 1)
1462 + tabular->GetAdditionalWidth(actcell);
1464 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1469 int InsetTabular::getCellXPos(int cell) const
1473 for (; !tabular->IsFirstCellInRow(c); --c)
1475 int lx = tabular->GetWidthOfColumn(cell);
1476 for (; c < cell; ++c) {
1477 lx += tabular->GetWidthOfColumn(c);
1479 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1483 void InsetTabular::resetPos(BufferView * bv) const
1485 #warning This should be fixed in the right manner (20011128 Jug)
1486 // fast hack to fix infinite repaintings!
1491 actcol = tabular->column_of_cell(actcell);
1494 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1495 if (tabular->IsLastCellInRow(cell)) {
1496 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1497 tabular->GetAscentOfRow(actrow + 1) +
1498 tabular->GetAdditionalHeight(actrow + 1));
1502 if (!locked || nodraw()) {
1503 if (the_locking_inset)
1504 inset_y = cursor_.y();
1507 // we need this only from here on!!!
1508 in_reset_pos = true;
1509 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1510 int new_x = getCellXPos(actcell);
1511 int old_x = cursor_.x();
1514 // cursor.x(getCellXPos(actcell) + offset);
1515 if ((actcol < tabular->columns()-1) && scroll(false) &&
1516 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1519 updateLocal(bv, FULL, false);
1520 } else if (the_locking_inset &&
1521 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1523 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1524 if (xx > (bv->workWidth()-20)) {
1525 scroll(bv, -(xx - bv->workWidth() + 60));
1526 updateLocal(bv, FULL, false);
1527 } else if (xx < 20) {
1533 updateLocal(bv, FULL, false);
1535 } else if ((cursor_.x() - offset) > 20 &&
1536 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1537 > (bv->workWidth() - 20)) {
1538 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1539 updateLocal(bv, FULL, false);
1540 } else if ((cursor_.x() - offset) < 20) {
1541 scroll(bv, 20 - cursor_.x() + offset);
1542 updateLocal(bv, FULL, false);
1543 } else if (scroll(false) && top_x > 20 &&
1544 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1545 scroll(bv, old_x - cursor_.x());
1546 updateLocal(bv, FULL, false);
1548 if (the_locking_inset) {
1549 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1550 inset_y = cursor_.y();
1552 if ((!the_locking_inset ||
1553 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1554 actcell != oldcell) {
1555 InsetTabular * inset = const_cast<InsetTabular *>(this);
1556 bv->owner()->getDialogs()->updateTabular(inset);
1559 in_reset_pos = false;
1563 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1565 if (lock && !old_locking_inset) {
1566 if (activateCellInset(bv))
1569 bool moved = isRightToLeft(bv)
1570 ? movePrevCell(bv) : moveNextCell(bv);
1572 return FINISHED_RIGHT;
1573 if (lock && activateCellInset(bv))
1577 return DISPATCHED_NOUPDATE;
1581 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1583 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1586 if (lock) { // behind the inset
1587 if (activateCellInset(bv, 0, 0, 0, true))
1591 return DISPATCHED_NOUPDATE;
1595 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1597 int const ocell = actcell;
1598 actcell = tabular->GetCellAbove(actcell);
1599 if (actcell == ocell) // we moved out of the inset
1605 if (old_locking_inset) {
1606 old_locking_inset->getCursorPos(bv, x, y);
1607 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1609 if (activateCellInset(bv, x, 0))
1612 return DISPATCHED_NOUPDATE;
1616 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1618 int const ocell = actcell;
1619 actcell = tabular->GetCellBelow(actcell);
1620 if (actcell == ocell) // we moved out of the inset
1621 return FINISHED_DOWN;
1626 if (old_locking_inset) {
1627 old_locking_inset->getCursorPos(bv, x, y);
1628 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1630 if (activateCellInset(bv, x, 0))
1633 return DISPATCHED_NOUPDATE;
1637 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1639 if (isRightToLeft(bv)) {
1640 if (tabular->IsFirstCellInRow(actcell)) {
1641 int row = tabular->row_of_cell(actcell);
1642 if (row == tabular->rows() - 1)
1644 actcell = tabular->GetLastCellInRow(row);
1645 actcell = tabular->GetCellBelow(actcell);
1652 if (tabular->IsLastCell(actcell))
1657 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1658 isRightToLeftPar(bv->buffer()->params);
1659 activateCellInset(bv, 0, 0, 0, !rtl);
1666 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1668 if (isRightToLeft(bv)) {
1669 if (tabular->IsLastCellInRow(actcell)) {
1670 int row = tabular->row_of_cell(actcell);
1673 actcell = tabular->GetFirstCellInRow(row);
1674 actcell = tabular->GetCellAbove(actcell);
1676 if (tabular->IsLastCell(actcell))
1681 if (!actcell) // first cell
1686 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1687 isRightToLeftPar(bv->buffer()->params);
1688 activateCellInset(bv, 0, 0, 0, !rtl);
1695 bool InsetTabular::deletable() const
1701 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1705 setSelection(0, tabular->GetNumberOfCells() - 1);
1707 if (hasSelection()) {
1708 setUndo(bv, Undo::EDIT,
1709 bv->text->cursor.par(),
1710 bv->text->cursor.par()->next());
1711 bool frozen = undo_frozen;
1714 // apply the fontchange on the whole selection
1719 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1720 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1721 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1722 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1727 updateLocal(bv, INIT, true);
1729 if (the_locking_inset)
1730 the_locking_inset->setFont(bv, font, tall);
1734 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1736 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1739 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1740 string const tmp = tabularFeature[i].feature;
1742 if (tmp == what.substr(0, tmp.length())) {
1743 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1744 //tabularFeatures[i].feature.length())) {
1745 action = tabularFeature[i].action;
1749 if (action == LyXTabular::LAST_ACTION)
1753 frontStrip(what.substr(tabularFeature[i].feature.length()));
1754 tabularFeatures(bv, action, val);
1758 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1759 string const & special, bool & flag)
1761 if (special == "dl_above") {
1764 } else if (special == "dl_below") {
1765 ltt.bottomDL = flag;
1767 } else if (special == "empty") {
1777 void InsetTabular::tabularFeatures(BufferView * bv,
1778 LyXTabular::Feature feature,
1779 string const & value)
1785 bool setLines = false;
1786 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1787 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1790 case LyXTabular::M_ALIGN_LEFT:
1791 case LyXTabular::ALIGN_LEFT:
1792 setAlign = LYX_ALIGN_LEFT;
1794 case LyXTabular::M_ALIGN_RIGHT:
1795 case LyXTabular::ALIGN_RIGHT:
1796 setAlign = LYX_ALIGN_RIGHT;
1798 case LyXTabular::M_ALIGN_CENTER:
1799 case LyXTabular::ALIGN_CENTER:
1800 setAlign = LYX_ALIGN_CENTER;
1802 case LyXTabular::M_VALIGN_TOP:
1803 case LyXTabular::VALIGN_TOP:
1804 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1806 case LyXTabular::M_VALIGN_BOTTOM:
1807 case LyXTabular::VALIGN_BOTTOM:
1808 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1810 case LyXTabular::M_VALIGN_CENTER:
1811 case LyXTabular::VALIGN_CENTER:
1812 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1817 if (hasSelection()) {
1818 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1820 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1821 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1823 setUndo(bv, Undo::FINISH,
1824 bv->text->cursor.par(),
1825 bv->text->cursor.par()->next());
1827 int row = tabular->row_of_cell(actcell);
1828 int column = tabular->column_of_cell(actcell);
1830 LyXTabular::ltType ltt;
1833 case LyXTabular::SET_PWIDTH:
1835 LyXLength const vallen(value);
1836 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1838 bool const update = (tmplen != vallen);
1839 tabular->SetColumnPWidth(actcell, vallen);
1842 for (int i = 0; i < tabular->rows(); ++i) {
1843 cell = tabular->GetCellNumber(i,column);
1844 tabular->GetCellInset(cell)->resizeLyXText(bv);
1846 updateLocal(bv, INIT, true);
1850 case LyXTabular::SET_MPWIDTH:
1852 LyXLength const vallen(value);
1853 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1855 bool const update = (tmplen != vallen);
1856 tabular->SetMColumnPWidth(actcell, vallen);
1858 for (int i = 0; i < tabular->rows(); ++i) {
1859 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1862 updateLocal(bv, INIT, true);
1866 case LyXTabular::SET_SPECIAL_COLUMN:
1867 case LyXTabular::SET_SPECIAL_MULTI:
1868 tabular->SetAlignSpecial(actcell,value,feature);
1869 updateLocal(bv, FULL, true);
1871 case LyXTabular::APPEND_ROW:
1872 // append the row into the tabular
1873 unlockInsetInInset(bv, the_locking_inset);
1874 tabular->AppendRow(bv->buffer()->params, actcell);
1875 updateLocal(bv, INIT, true);
1877 case LyXTabular::APPEND_COLUMN:
1878 // append the column into the tabular
1879 unlockInsetInInset(bv, the_locking_inset);
1880 tabular->AppendColumn(bv->buffer()->params, actcell);
1881 actcell = tabular->GetCellNumber(row, column);
1882 updateLocal(bv, INIT, true);
1884 case LyXTabular::DELETE_ROW:
1885 unlockInsetInInset(bv, the_locking_inset);
1886 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1887 tabular->DeleteRow(sel_row_start);
1889 if (sel_row_start >= tabular->rows())
1891 actcell = tabular->GetCellNumber(sel_row_start, column);
1893 updateLocal(bv, INIT, true);
1895 case LyXTabular::DELETE_COLUMN:
1896 unlockInsetInInset(bv, the_locking_inset);
1897 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1898 tabular->DeleteColumn(sel_col_start);
1900 if (sel_col_start >= tabular->columns())
1902 actcell = tabular->GetCellNumber(row, sel_col_start);
1904 updateLocal(bv, INIT, true);
1906 case LyXTabular::M_TOGGLE_LINE_TOP:
1908 case LyXTabular::TOGGLE_LINE_TOP:
1910 bool lineSet = !tabular->TopLine(actcell, flag);
1911 for (int i = sel_row_start; i <= sel_row_end; ++i)
1912 for (int j = sel_col_start; j <= sel_col_end; ++j)
1913 tabular->SetTopLine(
1914 tabular->GetCellNumber(i, j),
1916 updateLocal(bv, INIT, true);
1920 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1922 case LyXTabular::TOGGLE_LINE_BOTTOM:
1924 bool lineSet = !tabular->BottomLine(actcell, flag);
1925 for (int i = sel_row_start; i <= sel_row_end; ++i)
1926 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular->SetBottomLine(
1928 tabular->GetCellNumber(i, j),
1931 updateLocal(bv, INIT, true);
1935 case LyXTabular::M_TOGGLE_LINE_LEFT:
1937 case LyXTabular::TOGGLE_LINE_LEFT:
1939 bool lineSet = !tabular->LeftLine(actcell, flag);
1940 for (int i = sel_row_start; i <= sel_row_end; ++i)
1941 for (int j = sel_col_start; j <= sel_col_end; ++j)
1942 tabular->SetLeftLine(
1943 tabular->GetCellNumber(i,j),
1946 updateLocal(bv, INIT, true);
1950 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1952 case LyXTabular::TOGGLE_LINE_RIGHT:
1954 bool lineSet = !tabular->RightLine(actcell, flag);
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j <= sel_col_end; ++j)
1957 tabular->SetRightLine(
1958 tabular->GetCellNumber(i,j),
1961 updateLocal(bv, INIT, true);
1965 case LyXTabular::M_ALIGN_LEFT:
1966 case LyXTabular::M_ALIGN_RIGHT:
1967 case LyXTabular::M_ALIGN_CENTER:
1969 case LyXTabular::ALIGN_LEFT:
1970 case LyXTabular::ALIGN_RIGHT:
1971 case LyXTabular::ALIGN_CENTER:
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->SetAlignment(
1975 tabular->GetCellNumber(i, j),
1978 updateLocal(bv, INIT, true);
1980 case LyXTabular::M_VALIGN_TOP:
1981 case LyXTabular::M_VALIGN_BOTTOM:
1982 case LyXTabular::M_VALIGN_CENTER:
1984 case LyXTabular::VALIGN_TOP:
1985 case LyXTabular::VALIGN_BOTTOM:
1986 case LyXTabular::VALIGN_CENTER:
1987 for (int i = sel_row_start; i <= sel_row_end; ++i)
1988 for (int j = sel_col_start; j <= sel_col_end; ++j)
1989 tabular->SetVAlignment(
1990 tabular->GetCellNumber(i, j),
1992 updateLocal(bv, INIT, true);
1994 case LyXTabular::MULTICOLUMN:
1996 if (sel_row_start != sel_row_end) {
1997 Alert::alert(_("Impossible Operation!"),
1998 _("Multicolumns can only be horizontally."),
2002 // just multicol for one Single Cell
2003 if (!hasSelection()) {
2004 // check wether we are completly in a multicol
2005 if (tabular->IsMultiColumn(actcell)) {
2006 tabular->UnsetMultiColumn(actcell);
2007 updateLocal(bv, INIT, true);
2009 tabular->SetMultiColumn(actcell, 1);
2010 updateLocal(bv, CELL, true);
2014 // we have a selection so this means we just add all this
2015 // cells to form a multicolumn cell
2019 if (sel_cell_start > sel_cell_end) {
2020 s_start = sel_cell_end;
2021 s_end = sel_cell_start;
2023 s_start = sel_cell_start;
2024 s_end = sel_cell_end;
2026 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
2029 updateLocal(bv, INIT, true);
2032 case LyXTabular::SET_ALL_LINES:
2034 case LyXTabular::UNSET_ALL_LINES:
2035 for (int i = sel_row_start; i <= sel_row_end; ++i)
2036 for (int j = sel_col_start; j <= sel_col_end; ++j)
2037 tabular->SetAllLines(
2038 tabular->GetCellNumber(i,j), setLines);
2039 updateLocal(bv, INIT, true);
2041 case LyXTabular::SET_LONGTABULAR:
2042 tabular->SetLongTabular(true);
2043 updateLocal(bv, INIT, true); // because this toggles displayed
2045 case LyXTabular::UNSET_LONGTABULAR:
2046 tabular->SetLongTabular(false);
2047 updateLocal(bv, INIT, true); // because this toggles displayed
2049 case LyXTabular::SET_ROTATE_TABULAR:
2050 tabular->SetRotateTabular(true);
2052 case LyXTabular::UNSET_ROTATE_TABULAR:
2053 tabular->SetRotateTabular(false);
2055 case LyXTabular::SET_ROTATE_CELL:
2056 for (int i = sel_row_start; i <= sel_row_end; ++i)
2057 for (int j = sel_col_start; j<=sel_col_end; ++j)
2058 tabular->SetRotateCell(
2059 tabular->GetCellNumber(i, j),
2062 case LyXTabular::UNSET_ROTATE_CELL:
2063 for (int i = sel_row_start; i <= sel_row_end; ++i)
2064 for (int j = sel_col_start; j <= sel_col_end; ++j)
2065 tabular->SetRotateCell(
2066 tabular->GetCellNumber(i, j), false);
2068 case LyXTabular::SET_USEBOX:
2070 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2071 if (val == tabular->GetUsebox(actcell))
2072 val = LyXTabular::BOX_NONE;
2073 for (int i = sel_row_start; i <= sel_row_end; ++i)
2074 for (int j = sel_col_start; j <= sel_col_end; ++j)
2076 tabular->GetCellNumber(i, j), val);
2079 case LyXTabular::UNSET_LTFIRSTHEAD:
2081 case LyXTabular::SET_LTFIRSTHEAD:
2082 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2083 checkLongtableSpecial(ltt, value, flag);
2084 tabular->SetLTHead(row, flag, ltt, true);
2086 case LyXTabular::UNSET_LTHEAD:
2088 case LyXTabular::SET_LTHEAD:
2089 (void)tabular->GetRowOfLTHead(row, ltt);
2090 checkLongtableSpecial(ltt, value, flag);
2091 tabular->SetLTHead(row, flag, ltt, false);
2093 case LyXTabular::UNSET_LTFOOT:
2095 case LyXTabular::SET_LTFOOT:
2096 (void)tabular->GetRowOfLTFoot(row, ltt);
2097 checkLongtableSpecial(ltt, value, flag);
2098 tabular->SetLTFoot(row, flag, ltt, false);
2100 case LyXTabular::UNSET_LTLASTFOOT:
2102 case LyXTabular::SET_LTLASTFOOT:
2103 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2104 checkLongtableSpecial(ltt, value, flag);
2105 tabular->SetLTFoot(row, flag, ltt, true);
2107 case LyXTabular::SET_LTNEWPAGE:
2109 bool what = !tabular->GetLTNewPage(row);
2110 tabular->SetLTNewPage(row, what);
2113 // dummy stuff just to avoid warnings
2114 case LyXTabular::LAST_ACTION:
2120 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2123 UpdatableInset * inset =
2124 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2125 LyXFont font(LyXFont::ALL_SANE);
2127 x = inset->x() + inset->width(bv, font);
2128 y = inset->descent(bv, font);
2130 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2131 //inset_y = cursor.y();
2132 inset->edit(bv, x, y, button);
2133 if (!the_locking_inset)
2135 updateLocal(bv, CELL, false);
2136 return (the_locking_inset != 0);
2140 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2143 inset_x = cursor_.x()
2144 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2145 inset_y = cursor_.y();
2146 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2150 bool InsetTabular::insetHit(BufferView *, int x, int) const
2153 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2157 // This returns paperWidth() if the cell-width is unlimited or the width
2158 // in pixels if we have a pwidth for this cell.
2159 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2161 LyXLength const len = tabular->GetPWidth(cell);
2165 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2169 int InsetTabular::getMaxWidth(BufferView * bv,
2170 UpdatableInset const * inset) const
2172 int cell = tabular->GetCellFromInset(inset, actcell);
2175 lyxerr << "Own inset not found, shouldn't really happen!"
2180 int w = getMaxWidthOfCell(bv, cell);
2182 // because the inset then subtracts it's top_x and owner->x()
2183 w += (inset->x() - top_x);
2190 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2192 resizeLyXText(bv, recursive);
2196 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2199 for(int i = 0; i < tabular->rows(); ++i) {
2200 for(int j = 0; j < tabular->columns(); ++j) {
2201 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2209 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2210 bool const recursive) const
2212 if (the_locking_inset)
2213 return the_locking_inset->getLyXText(bv, recursive);
2215 // if we're locked lock the actual insettext and return it's LyXText!!!
2217 UpdatableInset * inset =
2218 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2219 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2220 return the_locking_inset->getLyXText(bv, recursive);
2223 return Inset::getLyXText(bv, recursive);
2227 bool InsetTabular::showInsetDialog(BufferView * bv) const
2229 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2230 bv->owner()->getDialogs()
2231 ->showTabular(const_cast<InsetTabular *>(this));
2236 void InsetTabular::openLayoutDialog(BufferView * bv) const
2238 if (the_locking_inset) {
2239 InsetTabular * i = static_cast<InsetTabular *>
2240 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2242 i->openLayoutDialog(bv);
2246 bv->owner()->getDialogs()->showTabular(
2247 const_cast<InsetTabular *>(this));
2252 // function returns an object as defined in func_status.h:
2253 // states OK, Unknown, Disabled, On, Off.
2255 FuncStatus InsetTabular::getStatus(string const & what) const
2257 int action = LyXTabular::LAST_ACTION;
2261 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2262 string const tmp = tabularFeature[i].feature;
2263 if (tmp == what.substr(0, tmp.length())) {
2264 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2265 // tabularFeatures[i].feature.length())) {
2266 action = tabularFeature[i].action;
2270 if (action == LyXTabular::LAST_ACTION) {
2272 return status.unknown(true);
2275 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2280 LyXTabular::ltType dummyltt;
2283 if (hasSelection()) {
2284 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2286 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2290 case LyXTabular::SET_PWIDTH:
2291 case LyXTabular::SET_MPWIDTH:
2292 case LyXTabular::SET_SPECIAL_COLUMN:
2293 case LyXTabular::SET_SPECIAL_MULTI:
2294 return status.disabled(true);
2296 case LyXTabular::APPEND_ROW:
2297 case LyXTabular::APPEND_COLUMN:
2298 case LyXTabular::DELETE_ROW:
2299 case LyXTabular::DELETE_COLUMN:
2300 case LyXTabular::SET_ALL_LINES:
2301 case LyXTabular::UNSET_ALL_LINES:
2302 return status.clear();
2304 case LyXTabular::MULTICOLUMN:
2305 status.setOnOff(tabular->IsMultiColumn(actcell));
2307 case LyXTabular::M_TOGGLE_LINE_TOP:
2309 case LyXTabular::TOGGLE_LINE_TOP:
2310 status.setOnOff(tabular->TopLine(actcell, flag));
2312 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2314 case LyXTabular::TOGGLE_LINE_BOTTOM:
2315 status.setOnOff(tabular->BottomLine(actcell, flag));
2317 case LyXTabular::M_TOGGLE_LINE_LEFT:
2319 case LyXTabular::TOGGLE_LINE_LEFT:
2320 status.setOnOff(tabular->LeftLine(actcell, flag));
2322 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2324 case LyXTabular::TOGGLE_LINE_RIGHT:
2325 status.setOnOff(tabular->RightLine(actcell, flag));
2327 case LyXTabular::M_ALIGN_LEFT:
2329 case LyXTabular::ALIGN_LEFT:
2330 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2332 case LyXTabular::M_ALIGN_RIGHT:
2334 case LyXTabular::ALIGN_RIGHT:
2335 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2337 case LyXTabular::M_ALIGN_CENTER:
2339 case LyXTabular::ALIGN_CENTER:
2340 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2342 case LyXTabular::M_VALIGN_TOP:
2344 case LyXTabular::VALIGN_TOP:
2345 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2347 case LyXTabular::M_VALIGN_BOTTOM:
2349 case LyXTabular::VALIGN_BOTTOM:
2350 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2352 case LyXTabular::M_VALIGN_CENTER:
2354 case LyXTabular::VALIGN_CENTER:
2355 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2357 case LyXTabular::SET_LONGTABULAR:
2358 status.setOnOff(tabular->IsLongTabular());
2360 case LyXTabular::UNSET_LONGTABULAR:
2361 status.setOnOff(!tabular->IsLongTabular());
2363 case LyXTabular::SET_ROTATE_TABULAR:
2364 status.setOnOff(tabular->GetRotateTabular());
2366 case LyXTabular::UNSET_ROTATE_TABULAR:
2367 status.setOnOff(!tabular->GetRotateTabular());
2369 case LyXTabular::SET_ROTATE_CELL:
2370 status.setOnOff(tabular->GetRotateCell(actcell));
2372 case LyXTabular::UNSET_ROTATE_CELL:
2373 status.setOnOff(!tabular->GetRotateCell(actcell));
2375 case LyXTabular::SET_USEBOX:
2376 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2378 case LyXTabular::SET_LTFIRSTHEAD:
2379 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2381 case LyXTabular::SET_LTHEAD:
2382 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2384 case LyXTabular::SET_LTFOOT:
2385 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2387 case LyXTabular::SET_LTLASTFOOT:
2388 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2390 case LyXTabular::SET_LTNEWPAGE:
2391 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2395 status.disabled(true);
2402 vector<string> const InsetTabular::getLabelList() const
2404 return tabular->getLabelList();
2408 bool InsetTabular::copySelection(BufferView * bv)
2410 if (!hasSelection())
2413 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2414 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2415 if (sel_col_start > sel_col_end) {
2416 sel_col_start = sel_col_end;
2417 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2419 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2421 int const columns = sel_col_end - sel_col_start + 1;
2423 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2424 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2425 if (sel_row_start > sel_row_end) {
2426 swap(sel_row_start, sel_row_end);
2428 int const rows = sel_row_end - sel_row_start + 1;
2430 delete paste_tabular;
2431 paste_tabular = new LyXTabular(bv->buffer()->params,
2432 this, *tabular); // rows, columns);
2433 for (int i = 0; i < sel_row_start; ++i)
2434 paste_tabular->DeleteRow(0);
2435 while (paste_tabular->rows() > rows)
2436 paste_tabular->DeleteRow(rows);
2437 paste_tabular->SetTopLine(0, true, true);
2438 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2440 for (int i = 0; i < sel_col_start; ++i)
2441 paste_tabular->DeleteColumn(0);
2442 while (paste_tabular->columns() > columns)
2443 paste_tabular->DeleteColumn(columns);
2444 paste_tabular->SetLeftLine(0, true, true);
2445 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2449 paste_tabular->ascii(bv->buffer(), sstr,
2450 (int)parOwner()->params().depth(), true, '\t');
2451 bv->stuffClipboard(sstr.str().c_str());
2456 bool InsetTabular::pasteSelection(BufferView * bv)
2461 for (int r1 = 0, r2 = actrow;
2462 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2464 for(int c1 = 0, c2 = actcol;
2465 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2467 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2468 tabular->IsPartOfMultiColumn(r2,c2))
2470 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2474 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2478 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2479 int const n2 = tabular->GetCellNumber(r2, c2);
2480 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2481 tabular->GetCellInset(n2)->setOwner(this);
2482 tabular->GetCellInset(n2)->deleteLyXText(bv);
2489 bool InsetTabular::cutSelection()
2491 if (!hasSelection())
2494 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2495 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2496 if (sel_col_start > sel_col_end) {
2497 sel_col_start = sel_col_end;
2498 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2500 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2502 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2503 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2504 if (sel_row_start > sel_row_end) {
2505 swap(sel_row_start, sel_row_end);
2507 if (sel_cell_start > sel_cell_end) {
2508 swap(sel_cell_start, sel_cell_end);
2510 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2511 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2512 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2519 bool InsetTabular::isRightToLeft(BufferView * bv)
2521 return bv->getParentLanguage(this)->RightToLeft();
2525 bool InsetTabular::nodraw() const
2527 if (!UpdatableInset::nodraw() && the_locking_inset)
2528 return the_locking_inset->nodraw();
2529 return UpdatableInset::nodraw();
2533 int InsetTabular::scroll(bool recursive) const
2535 int sx = UpdatableInset::scroll(false);
2537 if (recursive && the_locking_inset)
2538 sx += the_locking_inset->scroll(recursive);
2544 bool InsetTabular::doClearArea() const
2546 return !locked || (need_update & (FULL|INIT));
2550 void InsetTabular::getSelection(int & srow, int & erow,
2551 int & scol, int & ecol) const
2553 int const start = hasSelection() ? sel_cell_start : actcell;
2554 int const end = hasSelection() ? sel_cell_end : actcell;
2556 srow = tabular->row_of_cell(start);
2557 erow = tabular->row_of_cell(end);
2562 scol = tabular->column_of_cell(start);
2563 ecol = tabular->column_of_cell(end);
2567 ecol = tabular->right_column_of_cell(end);
2572 Paragraph * InsetTabular::getParFromID(int id) const
2575 for(int i = 0; i < tabular->rows(); ++i) {
2576 for(int j = 0; j < tabular->columns(); ++j) {
2577 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2585 Paragraph * InsetTabular::firstParagraph() const
2587 if (the_locking_inset)
2588 return the_locking_inset->firstParagraph();
2593 Paragraph * InsetTabular::getFirstParagraph(int i) const
2595 return (i < tabular->GetNumberOfCells())
2596 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2601 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2603 if (the_locking_inset)
2604 return the_locking_inset->cursor(bv);
2605 return Inset::cursor(bv);
2609 Inset * InsetTabular::getInsetFromID(int id_arg) const
2612 return const_cast<InsetTabular *>(this);
2615 for(int i = 0; i < tabular->rows(); ++i) {
2616 for(int j = 0; j < tabular->columns(); ++j) {
2617 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2626 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2629 if (the_locking_inset) {
2630 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2635 if (tabular->IsLastCell(actcell)) {
2636 bv->unlockInset(const_cast<InsetTabular *>(this));
2642 // otherwise we have to lock the next inset and ask for it's selecttion
2643 UpdatableInset * inset =
2644 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2645 inset->edit(bv, 0, 0, 0);
2646 string const str(selectNextWordInt(bv, value));
2654 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2656 // when entering this function the inset should be ALWAYS locked!
2657 lyx::Assert(the_locking_inset);
2659 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2663 if (tabular->IsLastCell(actcell)) {
2664 bv->unlockInset(const_cast<InsetTabular *>(this));
2668 // otherwise we have to lock the next inset and ask for it's selecttion
2669 UpdatableInset * inset =
2670 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2672 return selectNextWordInt(bv, value);
2676 void InsetTabular::selectSelectedWord(BufferView * bv)
2678 if (the_locking_inset) {
2679 the_locking_inset->selectSelectedWord(bv);
2686 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2688 if (the_locking_inset) {
2689 the_locking_inset->toggleSelection(bv, kill_selection);
2694 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2698 if (the_locking_inset) {
2699 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2701 updateLocal(bv, CELL, false);
2704 if (tabular->IsLastCell(actcell)) {
2706 bv->unlockInset(const_cast<InsetTabular *>(this));
2711 // otherwise we have to lock the next inset and search there
2712 UpdatableInset * inset =
2713 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2715 bool const ret = searchForward(bv, str, cs, mw);
2717 updateLocal(bv, CELL, false);
2722 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2726 if (the_locking_inset) {
2727 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2729 updateLocal(bv, CELL, false);
2732 if (!actcell) { // we are already in the first cell
2734 bv->unlockInset(const_cast<InsetTabular *>(this));
2739 // otherwise we have to lock the next inset and search there
2740 UpdatableInset * inset =
2741 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2742 inset->edit(bv, false);
2743 bool const ret = searchBackward(bv, str, cs, mw);
2745 updateLocal(bv, CELL, false);
2750 bool InsetTabular::insetAllowed(Inset::Code code) const
2752 if (the_locking_inset)
2753 return the_locking_inset->insetAllowed(code);
2758 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2760 const int cell = tabular->GetCellFromInset(in, actcell);
2763 return tabular->GetPWidth(cell).zero();
2765 // well we didn't obviously find it so maybe our owner knows more
2767 return owner()->forceDefaultParagraphs(in);
2768 // if we're here there is really something strange going on!!!