1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
17 #include "insettabular.h"
20 #include "commandtags.h"
23 #include "LaTeXFeatures.h"
27 #include "lyx_gui_misc.h"
29 #include "insets/insettext.h"
34 #include "BufferView.h"
35 #include "undo_funcs.h"
36 #include "lyxlength.h"
37 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/Alert.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::VALIGN_TOP, "valign-top" },
89 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
90 { LyXTabular::VALIGN_CENTER, "valign-center" },
91 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
92 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
93 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
94 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
95 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
96 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
97 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
98 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
99 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
100 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
101 { LyXTabular::MULTICOLUMN, "multicolumn" },
102 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
103 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
104 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
105 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
106 { LyXTabular::SET_PWIDTH, "set-pwidth" },
107 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
108 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
109 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
110 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
111 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
112 { LyXTabular::SET_USEBOX, "set-usebox" },
113 { LyXTabular::SET_LTHEAD, "set-lthead" },
114 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
115 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
116 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
117 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
118 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
119 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
120 { LyXTabular::LAST_ACTION, "" }
126 bool InsetTabular::hasPasteBuffer() const
128 return (paste_tabular != 0);
132 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
139 tabular.reset(new LyXTabular(this, rows, columns));
140 // for now make it always display as display() inset
142 the_locking_inset = 0;
143 old_locking_inset = 0;
146 actrow = actcell = 0;
150 in_reset_pos = false;
156 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
158 : UpdatableInset(tab, same_id), buffer(&buf)
160 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
169 in_reset_pos = false;
175 InsetTabular::~InsetTabular()
181 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
183 return new InsetTabular(*this, buf, same_id);
187 void InsetTabular::write(Buffer const * buf, ostream & os) const
189 os << " Tabular" << endl;
190 tabular->Write(buf, os);
194 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
196 bool const old_format = (lex.getString() == "\\LyXTable");
198 tabular.reset(new LyXTabular(buf, this, lex));
206 string token = lex.getString();
207 while (lex.isOK() && (token != "\\end_inset")) {
209 token = lex.getString();
211 if (token != "\\end_inset") {
212 lex.printError("Missing \\end_inset at this point. "
218 int InsetTabular::ascent(BufferView *, LyXFont const &) const
220 return tabular->GetAscentOfRow(0);
224 int InsetTabular::descent(BufferView *, LyXFont const &) const
226 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
230 int InsetTabular::width(BufferView *, LyXFont const &) const
232 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
236 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
237 float & x, bool cleared) const
245 if (need_update == INIT) {
246 if (calculate_dimensions_of_cells(bv, font, true))
247 bv->text->status = LyXText::CHANGED_IN_DRAW;
252 Painter & pain = bv->painter();
258 UpdatableInset::draw(bv, font, baseline, x, cleared);
261 x += static_cast<float>(scroll());
263 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
264 (top_x != int(x)) || (top_baseline != baseline)))
266 int h = ascent(bv, font) + descent(bv, font);
267 int const tx = display() || !owner() ? 0 : top_x;
268 int w = tx ? width(bv, font) : pain.paperWidth();
269 int ty = baseline - ascent(bv, font);
273 if ((ty + h) > pain.paperHeight())
274 h = pain.paperHeight();
275 if ((top_x + w) > pain.paperWidth())
276 w = pain.paperWidth();
277 pain.fillRectangle(tx, ty, w, h, backgroundColor());
283 top_baseline = baseline;
284 x += ADD_TO_TABULAR_WIDTH;
288 first_visible_cell = -1;
289 for (i = 0; i < tabular->rows(); ++i) {
291 cell = tabular->GetCellNumber(i, 0);
292 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
293 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
295 baseline += tabular->GetDescentOfRow(i) +
296 tabular->GetAscentOfRow(i + 1) +
297 tabular->GetAdditionalHeight(i + 1);
300 for (j = 0; j < tabular->columns(); ++j) {
301 if (nx > bv->workWidth())
303 if (tabular->IsPartOfMultiColumn(i, j))
305 cx = nx + tabular->GetBeginningOfTextInCell(cell);
306 if (first_visible_cell < 0)
307 first_visible_cell = cell;
308 if (hasSelection()) {
309 drawCellSelection(pain, nx, baseline, i, j, cell);
312 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
313 drawCellLines(pain, nx, baseline, i, cell);
314 nx += tabular->GetWidthOfColumn(cell);
317 baseline += tabular->GetDescentOfRow(i) +
318 tabular->GetAscentOfRow(i + 1) +
319 tabular->GetAdditionalHeight(i + 1);
321 } else if (need_update == CELL) {
324 if (the_locking_inset &&
325 tabular->GetCellInset(actcell) != the_locking_inset)
327 Inset * inset = tabular->GetCellInset(cell);
329 inset != the_locking_inset && i < tabular->rows();
333 inset != the_locking_inset && j < tabular->columns();
336 if (tabular->IsPartOfMultiColumn(i, j))
338 nx += tabular->GetWidthOfColumn(cell);
340 inset = tabular->GetCellInset(cell);
342 if (tabular->row_of_cell(cell) > i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
350 // compute baseline for actual row
351 for (i = 0; i < actrow; ++i) {
352 baseline += tabular->GetDescentOfRow(i) +
353 tabular->GetAscentOfRow(i + 1) +
354 tabular->GetAdditionalHeight(i + 1);
356 // now compute the right x position
357 cell = tabular->GetCellNumber(actrow, 0);
358 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
359 if (tabular->IsPartOfMultiColumn(actrow, j))
361 nx += tabular->GetWidthOfColumn(cell);
365 i = tabular->row_of_cell(cell);
366 if (the_locking_inset != tabular->GetCellInset(cell)) {
367 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
370 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
372 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
374 // Here we use rectangular backgroundColor patches to clean up
375 // within a cell around the cell's red inset box. As follows:
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 int column = actcol;
1035 unlockInsetInInset(bv, the_locking_inset);
1036 if (bv->text->first + bv->painter().paperHeight() <
1037 (top_baseline + tabular->GetHeightOfTabular()))
1039 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1040 updateLocal(bv, FULL, false);
1041 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1043 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1046 updateLocal(bv, CURSOR, false);
1050 int column = actcol;
1051 unlockInsetInInset(bv, the_locking_inset);
1052 if (top_baseline < 0) {
1053 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1054 updateLocal(bv, FULL, false);
1055 if (top_baseline > 0)
1058 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1063 updateLocal(bv, CURSOR, false);
1066 // none of these make sense for insettabular,
1067 // but we must catch them to prevent any
1068 // selection from being confused
1072 case LFUN_WORDLEFTSEL:
1073 case LFUN_WORDRIGHT:
1074 case LFUN_WORDRIGHTSEL:
1075 case LFUN_DOWN_PARAGRAPH:
1076 case LFUN_DOWN_PARAGRAPHSEL:
1077 case LFUN_UP_PARAGRAPH:
1078 case LFUN_UP_PARAGRAPHSEL:
1079 case LFUN_BACKSPACE:
1085 case LFUN_BEGINNINGBUF:
1086 case LFUN_BEGINNINGBUFSEL:
1088 case LFUN_ENDBUFSEL:
1090 case LFUN_LAYOUT_TABULAR:
1091 bv->owner()->getDialogs()->showTabular(this);
1093 case LFUN_TABULAR_FEATURE:
1094 if (!tabularFeatures(bv, arg))
1095 result = UNDISPATCHED;
1098 if (!copySelection(bv))
1100 setUndo(bv, Undo::DELETE,
1101 bv->text->cursor.par(),
1102 bv->text->cursor.par()->next());
1104 updateLocal(bv, INIT, true);
1107 if (!hasSelection())
1112 case LFUN_PASTESELECTION:
1114 string const clip(bv->getClipboard());
1118 if (clip.find('\t') != string::npos) {
1122 string::size_type len = clip.length();
1123 string::size_type p = 0;
1126 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1134 maxCols = max(cols, maxCols);
1140 maxCols = max(cols, maxCols);
1141 delete paste_tabular;
1142 paste_tabular = new LyXTabular(this, rows, maxCols);
1143 string::size_type op = 0;
1145 int cells = paste_tabular->GetNumberOfCells();
1147 while ((cell < cells) && (p < len) &&
1148 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1153 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1158 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1159 while (cols++ < maxCols)
1167 // check for the last cell if there is no trailing '\n'
1168 if ((cell < cells) && (op < len))
1169 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1171 // so that the clipboard is used and it goes on
1173 // and executes LFUN_PASTESELECTION in insettext!
1174 delete paste_tabular;
1179 if (hasPasteBuffer()) {
1180 setUndo(bv, Undo::INSERT,
1181 bv->text->cursor.par(),
1182 bv->text->cursor.par()->next());
1184 updateLocal(bv, INIT, true);
1187 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1189 // we try to activate the actual inset and put this event down to
1190 // the insets dispatch function.
1191 result = UNDISPATCHED;
1192 if (the_locking_inset)
1195 if (activateCellInset(bv)) {
1196 // reset need_update setted in above function!
1198 result = the_locking_inset->localDispatch(bv, action, arg);
1199 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1200 unlockInsetInInset(bv, the_locking_inset);
1202 // we need to update if this was requested before
1203 updateLocal(bv, NONE, false);
1204 return UNDISPATCHED;
1209 updateLocal(bv, CELL, false);
1214 if (result < FINISHED) {
1215 if (!the_locking_inset) {
1216 showInsetCursor(bv);
1219 bv->unlockInset(this);
1224 int InsetTabular::latex(Buffer const * buf, ostream & os,
1225 bool fragile, bool fp) const
1227 return tabular->latex(buf, os, fragile, fp);
1231 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1234 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1236 return tabular->ascii(buf, os, 0, false,0);
1240 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1243 int const ret = tabular->ascii(buf,os,
1244 (int)parOwner()->params().depth(),
1251 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1256 // if the table is inside a float it doesn't need the informaltable
1257 // wrapper. Search for it.
1258 for(master = owner();
1259 master && master->lyxCode() != Inset::FLOAT_CODE;
1260 master = master->owner());
1263 os << "<informaltable>\n";
1266 ret+= tabular->docBook(buf,os);
1268 os << "</informaltable>\n";
1275 void InsetTabular::validate(LaTeXFeatures & features) const
1277 tabular->Validate(features);
1281 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1282 LyXFont const & font,
1289 bool changed = false;
1291 // if we have a locking_inset we should have to check only this cell for
1292 // change so I'll try this to have a boost, but who knows ;)
1293 if ((need_update != INIT) &&
1294 (the_locking_inset == tabular->GetCellInset(actcell))) {
1295 for(int i = 0; i < tabular->columns(); ++i) {
1296 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1298 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1301 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1302 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1303 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1306 for (int i = 0; i < tabular->rows(); ++i) {
1309 for (int j = 0; j < tabular->columns(); ++j) {
1310 if (tabular->IsPartOfMultiColumn(i,j))
1313 inset = tabular->GetCellInset(cell);
1314 if (!reinit && !tabular->GetPWidth(cell).zero())
1315 inset->update(bv, font, false);
1316 maxAsc = max(maxAsc, inset->ascent(bv, font));
1317 maxDesc = max(maxDesc, inset->descent(bv, font));
1318 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1320 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1321 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1329 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1331 if (the_locking_inset) {
1332 the_locking_inset->getCursorPos(bv, x, y);
1335 x = cursor_.x() - top_x;
1340 void InsetTabular::toggleInsetCursor(BufferView * bv)
1343 if (isCursorVisible())
1344 bv->hideLockedInsetCursor();
1347 if (the_locking_inset) {
1348 the_locking_inset->toggleInsetCursor(bv);
1352 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1354 int const asc = lyxfont::maxAscent(font);
1355 int const desc = lyxfont::maxDescent(font);
1357 if (isCursorVisible())
1358 bv->hideLockedInsetCursor();
1360 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1361 toggleCursorVisible();
1365 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1369 if (!isCursorVisible()) {
1370 LyXFont font; // = GetFont(par, cursor.pos);
1372 int const asc = lyxfont::maxAscent(font);
1373 int const desc = lyxfont::maxDescent(font);
1374 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1376 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1377 setCursorVisible(true);
1382 void InsetTabular::hideInsetCursor(BufferView * bv)
1384 if (isCursorVisible()) {
1385 bv->hideLockedInsetCursor();
1386 setCursorVisible(false);
1391 void InsetTabular::fitInsetCursor(BufferView * bv) const
1393 if (the_locking_inset) {
1394 the_locking_inset->fitInsetCursor(bv);
1399 int const asc = lyxfont::maxAscent(font);
1400 int const desc = lyxfont::maxDescent(font);
1401 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1405 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1409 actcell = actrow = actcol = 0;
1410 int ly = tabular->GetDescentOfRow(actrow);
1412 // first search the right row
1413 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1414 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1415 tabular->GetAscentOfRow(actrow + 1) +
1416 tabular->GetAdditionalHeight(actrow + 1));
1418 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1420 actcell = tabular->GetCellNumber(actrow, actcol);
1422 // now search the right column
1423 int lx = tabular->GetWidthOfColumn(actcell) -
1424 tabular->GetAdditionalWidth(actcell);
1425 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1426 lx += tabular->GetWidthOfColumn(actcell + 1)
1427 + tabular->GetAdditionalWidth(actcell);
1429 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1434 int InsetTabular::getCellXPos(int cell) const
1438 for (; !tabular->IsFirstCellInRow(c); --c)
1440 int lx = tabular->GetWidthOfColumn(cell);
1441 for (; c < cell; ++c) {
1442 lx += tabular->GetWidthOfColumn(c);
1444 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1448 void InsetTabular::resetPos(BufferView * bv) const
1450 #warning This should be fixed in the right manner (20011128 Jug)
1451 // fast hack to fix infinite repaintings!
1456 actcol = tabular->column_of_cell(actcell);
1459 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1460 if (tabular->IsLastCellInRow(cell)) {
1461 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1462 tabular->GetAscentOfRow(actrow + 1) +
1463 tabular->GetAdditionalHeight(actrow + 1));
1467 if (!locked || nodraw()) {
1468 if (the_locking_inset)
1469 inset_y = cursor_.y();
1472 // we need this only from here on!!!
1473 in_reset_pos = true;
1474 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1475 int new_x = getCellXPos(actcell);
1476 int old_x = cursor_.x();
1479 // cursor.x(getCellXPos(actcell) + offset);
1480 if ((actcol < tabular->columns()-1) && scroll(false) &&
1481 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1484 updateLocal(bv, FULL, false);
1485 } else if (the_locking_inset &&
1486 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1488 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1489 if (xx > (bv->workWidth()-20)) {
1490 scroll(bv, -(xx - bv->workWidth() + 60));
1491 updateLocal(bv, FULL, false);
1492 } else if (xx < 20) {
1498 updateLocal(bv, FULL, false);
1500 } else if ((cursor_.x() - offset) > 20 &&
1501 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1502 > (bv->workWidth() - 20)) {
1503 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1504 updateLocal(bv, FULL, false);
1505 } else if ((cursor_.x() - offset) < 20) {
1506 scroll(bv, 20 - cursor_.x() + offset);
1507 updateLocal(bv, FULL, false);
1508 } else if (scroll(false) && top_x > 20 &&
1509 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1510 scroll(bv, old_x - cursor_.x());
1511 updateLocal(bv, FULL, false);
1513 if (the_locking_inset) {
1514 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1515 inset_y = cursor_.y();
1517 if ((!the_locking_inset ||
1518 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1519 actcell != oldcell) {
1520 InsetTabular * inset = const_cast<InsetTabular *>(this);
1521 bv->owner()->getDialogs()->updateTabular(inset);
1524 in_reset_pos = false;
1528 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1530 if (lock && !old_locking_inset) {
1531 if (activateCellInset(bv))
1534 bool moved = isRightToLeft(bv)
1535 ? movePrevCell(bv) : moveNextCell(bv);
1537 return FINISHED_RIGHT;
1538 if (lock && activateCellInset(bv))
1542 return DISPATCHED_NOUPDATE;
1546 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1548 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1551 if (lock) { // behind the inset
1552 if (activateCellInset(bv, 0, 0, 0, true))
1556 return DISPATCHED_NOUPDATE;
1560 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1562 int const ocell = actcell;
1563 actcell = tabular->GetCellAbove(actcell);
1564 if (actcell == ocell) // we moved out of the inset
1570 if (old_locking_inset) {
1571 old_locking_inset->getCursorPos(bv, x, y);
1572 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1574 if (activateCellInset(bv, x, 0))
1577 return DISPATCHED_NOUPDATE;
1581 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1583 int const ocell = actcell;
1584 actcell = tabular->GetCellBelow(actcell);
1585 if (actcell == ocell) // we moved out of the inset
1586 return FINISHED_DOWN;
1591 if (old_locking_inset) {
1592 old_locking_inset->getCursorPos(bv, x, y);
1593 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1595 if (activateCellInset(bv, x, 0))
1598 return DISPATCHED_NOUPDATE;
1602 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1604 if (isRightToLeft(bv)) {
1605 if (tabular->IsFirstCellInRow(actcell)) {
1606 int row = tabular->row_of_cell(actcell);
1607 if (row == tabular->rows() - 1)
1609 actcell = tabular->GetLastCellInRow(row);
1610 actcell = tabular->GetCellBelow(actcell);
1617 if (tabular->IsLastCell(actcell))
1622 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1623 isRightToLeftPar(bv->buffer()->params);
1624 activateCellInset(bv, 0, 0, 0, !rtl);
1631 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1633 if (isRightToLeft(bv)) {
1634 if (tabular->IsLastCellInRow(actcell)) {
1635 int row = tabular->row_of_cell(actcell);
1638 actcell = tabular->GetFirstCellInRow(row);
1639 actcell = tabular->GetCellAbove(actcell);
1641 if (tabular->IsLastCell(actcell))
1646 if (!actcell) // first cell
1651 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1652 isRightToLeftPar(bv->buffer()->params);
1653 activateCellInset(bv, 0, 0, 0, !rtl);
1660 bool InsetTabular::deletable() const
1666 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1670 setSelection(0, tabular->GetNumberOfCells() - 1);
1672 if (hasSelection()) {
1673 setUndo(bv, Undo::EDIT,
1674 bv->text->cursor.par(),
1675 bv->text->cursor.par()->next());
1676 bool frozen = undo_frozen;
1679 // apply the fontchange on the whole selection
1684 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1685 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1686 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1687 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1692 updateLocal(bv, INIT, true);
1694 if (the_locking_inset)
1695 the_locking_inset->setFont(bv, font, tall);
1699 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1701 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1704 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1705 string const tmp = tabularFeature[i].feature;
1707 if (tmp == what.substr(0, tmp.length())) {
1708 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1709 //tabularFeatures[i].feature.length())) {
1710 action = tabularFeature[i].action;
1714 if (action == LyXTabular::LAST_ACTION)
1718 frontStrip(what.substr(tabularFeature[i].feature.length()));
1719 tabularFeatures(bv, action, val);
1723 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1724 string const & special, bool & flag)
1726 if (special == "dl_above") {
1729 } else if (special == "dl_below") {
1730 ltt.bottomDL = flag;
1732 } else if (special == "empty") {
1742 void InsetTabular::tabularFeatures(BufferView * bv,
1743 LyXTabular::Feature feature,
1744 string const & value)
1750 bool setLines = false;
1751 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1752 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1755 case LyXTabular::M_ALIGN_LEFT:
1756 case LyXTabular::ALIGN_LEFT:
1757 setAlign = LYX_ALIGN_LEFT;
1759 case LyXTabular::M_ALIGN_RIGHT:
1760 case LyXTabular::ALIGN_RIGHT:
1761 setAlign = LYX_ALIGN_RIGHT;
1763 case LyXTabular::M_ALIGN_CENTER:
1764 case LyXTabular::ALIGN_CENTER:
1765 setAlign = LYX_ALIGN_CENTER;
1767 case LyXTabular::M_VALIGN_TOP:
1768 case LyXTabular::VALIGN_TOP:
1769 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1771 case LyXTabular::M_VALIGN_BOTTOM:
1772 case LyXTabular::VALIGN_BOTTOM:
1773 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1775 case LyXTabular::M_VALIGN_CENTER:
1776 case LyXTabular::VALIGN_CENTER:
1777 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1782 if (hasSelection()) {
1783 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1785 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1786 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1788 setUndo(bv, Undo::FINISH,
1789 bv->text->cursor.par(),
1790 bv->text->cursor.par()->next());
1792 int row = tabular->row_of_cell(actcell);
1793 int column = tabular->column_of_cell(actcell);
1795 LyXTabular::ltType ltt;
1798 case LyXTabular::SET_PWIDTH:
1800 LyXLength const vallen(value);
1801 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1803 bool const update = (tmplen != vallen);
1804 tabular->SetColumnPWidth(actcell, vallen);
1807 for (int i = 0; i < tabular->rows(); ++i) {
1808 cell = tabular->GetCellNumber(i,column);
1809 tabular->GetCellInset(cell)->resizeLyXText(bv);
1811 updateLocal(bv, INIT, true);
1815 case LyXTabular::SET_MPWIDTH:
1817 LyXLength const vallen(value);
1818 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1820 bool const update = (tmplen != vallen);
1821 tabular->SetMColumnPWidth(actcell, vallen);
1823 for (int i = 0; i < tabular->rows(); ++i) {
1824 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1827 updateLocal(bv, INIT, true);
1831 case LyXTabular::SET_SPECIAL_COLUMN:
1832 case LyXTabular::SET_SPECIAL_MULTI:
1833 tabular->SetAlignSpecial(actcell,value,feature);
1834 updateLocal(bv, FULL, true);
1836 case LyXTabular::APPEND_ROW:
1837 // append the row into the tabular
1838 unlockInsetInInset(bv, the_locking_inset);
1839 tabular->AppendRow(actcell);
1840 updateLocal(bv, INIT, true);
1842 case LyXTabular::APPEND_COLUMN:
1843 // append the column into the tabular
1844 unlockInsetInInset(bv, the_locking_inset);
1845 tabular->AppendColumn(actcell);
1846 actcell = tabular->GetCellNumber(row, column);
1847 updateLocal(bv, INIT, true);
1849 case LyXTabular::DELETE_ROW:
1850 unlockInsetInInset(bv, the_locking_inset);
1851 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1852 tabular->DeleteRow(sel_row_start);
1854 if (sel_row_start >= tabular->rows())
1856 actcell = tabular->GetCellNumber(sel_row_start, column);
1858 updateLocal(bv, INIT, true);
1860 case LyXTabular::DELETE_COLUMN:
1861 unlockInsetInInset(bv, the_locking_inset);
1862 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1863 tabular->DeleteColumn(sel_col_start);
1865 if (sel_col_start >= tabular->columns())
1867 actcell = tabular->GetCellNumber(row, sel_col_start);
1869 updateLocal(bv, INIT, true);
1871 case LyXTabular::M_TOGGLE_LINE_TOP:
1873 case LyXTabular::TOGGLE_LINE_TOP:
1875 bool lineSet = !tabular->TopLine(actcell, flag);
1876 for (int i = sel_row_start; i <= sel_row_end; ++i)
1877 for (int j = sel_col_start; j <= sel_col_end; ++j)
1878 tabular->SetTopLine(
1879 tabular->GetCellNumber(i, j),
1881 updateLocal(bv, INIT, true);
1885 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1887 case LyXTabular::TOGGLE_LINE_BOTTOM:
1889 bool lineSet = !tabular->BottomLine(actcell, flag);
1890 for (int i = sel_row_start; i <= sel_row_end; ++i)
1891 for (int j = sel_col_start; j <= sel_col_end; ++j)
1892 tabular->SetBottomLine(
1893 tabular->GetCellNumber(i, j),
1896 updateLocal(bv, INIT, true);
1900 case LyXTabular::M_TOGGLE_LINE_LEFT:
1902 case LyXTabular::TOGGLE_LINE_LEFT:
1904 bool lineSet = !tabular->LeftLine(actcell, flag);
1905 for (int i = sel_row_start; i <= sel_row_end; ++i)
1906 for (int j = sel_col_start; j <= sel_col_end; ++j)
1907 tabular->SetLeftLine(
1908 tabular->GetCellNumber(i,j),
1911 updateLocal(bv, INIT, true);
1915 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1917 case LyXTabular::TOGGLE_LINE_RIGHT:
1919 bool lineSet = !tabular->RightLine(actcell, flag);
1920 for (int i = sel_row_start; i <= sel_row_end; ++i)
1921 for (int j = sel_col_start; j <= sel_col_end; ++j)
1922 tabular->SetRightLine(
1923 tabular->GetCellNumber(i,j),
1926 updateLocal(bv, INIT, true);
1930 case LyXTabular::M_ALIGN_LEFT:
1931 case LyXTabular::M_ALIGN_RIGHT:
1932 case LyXTabular::M_ALIGN_CENTER:
1934 case LyXTabular::ALIGN_LEFT:
1935 case LyXTabular::ALIGN_RIGHT:
1936 case LyXTabular::ALIGN_CENTER:
1937 for (int i = sel_row_start; i <= sel_row_end; ++i)
1938 for (int j = sel_col_start; j <= sel_col_end; ++j)
1939 tabular->SetAlignment(
1940 tabular->GetCellNumber(i, j),
1943 updateLocal(bv, INIT, true);
1945 case LyXTabular::M_VALIGN_TOP:
1946 case LyXTabular::M_VALIGN_BOTTOM:
1947 case LyXTabular::M_VALIGN_CENTER:
1949 case LyXTabular::VALIGN_TOP:
1950 case LyXTabular::VALIGN_BOTTOM:
1951 case LyXTabular::VALIGN_CENTER:
1952 for (int i = sel_row_start; i <= sel_row_end; ++i)
1953 for (int j = sel_col_start; j <= sel_col_end; ++j)
1954 tabular->SetVAlignment(
1955 tabular->GetCellNumber(i, j),
1957 updateLocal(bv, INIT, true);
1959 case LyXTabular::MULTICOLUMN:
1961 if (sel_row_start != sel_row_end) {
1962 Alert::alert(_("Impossible Operation!"),
1963 _("Multicolumns can only be horizontally."),
1967 // just multicol for one Single Cell
1968 if (!hasSelection()) {
1969 // check wether we are completly in a multicol
1970 if (tabular->IsMultiColumn(actcell)) {
1971 tabular->UnsetMultiColumn(actcell);
1972 updateLocal(bv, INIT, true);
1974 tabular->SetMultiColumn(actcell, 1);
1975 updateLocal(bv, CELL, true);
1979 // we have a selection so this means we just add all this
1980 // cells to form a multicolumn cell
1984 if (sel_cell_start > sel_cell_end) {
1985 s_start = sel_cell_end;
1986 s_end = sel_cell_start;
1988 s_start = sel_cell_start;
1989 s_end = sel_cell_end;
1991 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1994 updateLocal(bv, INIT, true);
1997 case LyXTabular::SET_ALL_LINES:
1999 case LyXTabular::UNSET_ALL_LINES:
2000 for (int i = sel_row_start; i <= sel_row_end; ++i)
2001 for (int j = sel_col_start; j <= sel_col_end; ++j)
2002 tabular->SetAllLines(
2003 tabular->GetCellNumber(i,j), setLines);
2004 updateLocal(bv, INIT, true);
2006 case LyXTabular::SET_LONGTABULAR:
2007 tabular->SetLongTabular(true);
2008 updateLocal(bv, INIT, true); // because this toggles displayed
2010 case LyXTabular::UNSET_LONGTABULAR:
2011 tabular->SetLongTabular(false);
2012 updateLocal(bv, INIT, true); // because this toggles displayed
2014 case LyXTabular::SET_ROTATE_TABULAR:
2015 tabular->SetRotateTabular(true);
2017 case LyXTabular::UNSET_ROTATE_TABULAR:
2018 tabular->SetRotateTabular(false);
2020 case LyXTabular::SET_ROTATE_CELL:
2021 for (int i = sel_row_start; i <= sel_row_end; ++i)
2022 for (int j = sel_col_start; j<=sel_col_end; ++j)
2023 tabular->SetRotateCell(
2024 tabular->GetCellNumber(i, j),
2027 case LyXTabular::UNSET_ROTATE_CELL:
2028 for (int i = sel_row_start; i <= sel_row_end; ++i)
2029 for (int j = sel_col_start; j <= sel_col_end; ++j)
2030 tabular->SetRotateCell(
2031 tabular->GetCellNumber(i, j), false);
2033 case LyXTabular::SET_USEBOX:
2035 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2036 if (val == tabular->GetUsebox(actcell))
2037 val = LyXTabular::BOX_NONE;
2038 for (int i = sel_row_start; i <= sel_row_end; ++i)
2039 for (int j = sel_col_start; j <= sel_col_end; ++j)
2041 tabular->GetCellNumber(i, j), val);
2044 case LyXTabular::UNSET_LTFIRSTHEAD:
2046 case LyXTabular::SET_LTFIRSTHEAD:
2047 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2048 checkLongtableSpecial(ltt, value, flag);
2049 tabular->SetLTHead(row, flag, ltt, true);
2051 case LyXTabular::UNSET_LTHEAD:
2053 case LyXTabular::SET_LTHEAD:
2054 (void)tabular->GetRowOfLTHead(row, ltt);
2055 checkLongtableSpecial(ltt, value, flag);
2056 tabular->SetLTHead(row, flag, ltt, false);
2058 case LyXTabular::UNSET_LTFOOT:
2060 case LyXTabular::SET_LTFOOT:
2061 (void)tabular->GetRowOfLTFoot(row, ltt);
2062 checkLongtableSpecial(ltt, value, flag);
2063 tabular->SetLTFoot(row, flag, ltt, false);
2065 case LyXTabular::UNSET_LTLASTFOOT:
2067 case LyXTabular::SET_LTLASTFOOT:
2068 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2069 checkLongtableSpecial(ltt, value, flag);
2070 tabular->SetLTFoot(row, flag, ltt, true);
2072 case LyXTabular::SET_LTNEWPAGE:
2074 bool what = !tabular->GetLTNewPage(row);
2075 tabular->SetLTNewPage(row, what);
2078 // dummy stuff just to avoid warnings
2079 case LyXTabular::LAST_ACTION:
2085 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2088 UpdatableInset * inset =
2089 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2090 LyXFont font(LyXFont::ALL_SANE);
2092 x = inset->x() + inset->width(bv, font);
2093 y = inset->descent(bv, font);
2095 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2096 //inset_y = cursor.y();
2097 inset->edit(bv, x, y, button);
2098 if (!the_locking_inset)
2100 updateLocal(bv, CELL, false);
2101 return (the_locking_inset != 0);
2105 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2108 inset_x = cursor_.x()
2109 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2110 inset_y = cursor_.y();
2111 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2115 bool InsetTabular::insetHit(BufferView *, int x, int) const
2118 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2122 // This returns paperWidth() if the cell-width is unlimited or the width
2123 // in pixels if we have a pwidth for this cell.
2124 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2126 LyXLength const len = tabular->GetPWidth(cell);
2130 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2134 int InsetTabular::getMaxWidth(BufferView * bv,
2135 UpdatableInset const * inset) const
2137 int cell = tabular->GetCellFromInset(inset, actcell);
2140 lyxerr << "Own inset not found, shouldn't really happen!"
2145 int w = getMaxWidthOfCell(bv, cell);
2147 // because the inset then subtracts it's top_x and owner->x()
2148 w += (inset->x() - top_x);
2155 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2157 resizeLyXText(bv, recursive);
2161 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2164 for(int i = 0; i < tabular->rows(); ++i) {
2165 for(int j = 0; j < tabular->columns(); ++j) {
2166 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2174 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2175 bool const recursive) const
2177 if (the_locking_inset)
2178 return the_locking_inset->getLyXText(bv, recursive);
2180 // if we're locked lock the actual insettext and return it's LyXText!!!
2182 UpdatableInset * inset =
2183 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2184 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2185 return the_locking_inset->getLyXText(bv, recursive);
2188 return Inset::getLyXText(bv, recursive);
2192 bool InsetTabular::showInsetDialog(BufferView * bv) const
2194 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2195 bv->owner()->getDialogs()
2196 ->showTabular(const_cast<InsetTabular *>(this));
2201 void InsetTabular::openLayoutDialog(BufferView * bv) const
2203 if (the_locking_inset) {
2204 InsetTabular * i = static_cast<InsetTabular *>
2205 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2207 i->openLayoutDialog(bv);
2211 bv->owner()->getDialogs()->showTabular(
2212 const_cast<InsetTabular *>(this));
2217 // function returns an object as defined in func_status.h:
2218 // states OK, Unknown, Disabled, On, Off.
2220 FuncStatus InsetTabular::getStatus(string const & what) const
2222 int action = LyXTabular::LAST_ACTION;
2226 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2227 string const tmp = tabularFeature[i].feature;
2228 if (tmp == what.substr(0, tmp.length())) {
2229 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2230 // tabularFeatures[i].feature.length())) {
2231 action = tabularFeature[i].action;
2235 if (action == LyXTabular::LAST_ACTION) {
2237 return status.unknown(true);
2240 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2245 LyXTabular::ltType dummyltt;
2248 if (hasSelection()) {
2249 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2251 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2255 case LyXTabular::SET_PWIDTH:
2256 case LyXTabular::SET_MPWIDTH:
2257 case LyXTabular::SET_SPECIAL_COLUMN:
2258 case LyXTabular::SET_SPECIAL_MULTI:
2259 return status.disabled(true);
2261 case LyXTabular::APPEND_ROW:
2262 case LyXTabular::APPEND_COLUMN:
2263 case LyXTabular::DELETE_ROW:
2264 case LyXTabular::DELETE_COLUMN:
2265 case LyXTabular::SET_ALL_LINES:
2266 case LyXTabular::UNSET_ALL_LINES:
2267 return status.clear();
2269 case LyXTabular::MULTICOLUMN:
2270 status.setOnOff(tabular->IsMultiColumn(actcell));
2272 case LyXTabular::M_TOGGLE_LINE_TOP:
2274 case LyXTabular::TOGGLE_LINE_TOP:
2275 status.setOnOff(tabular->TopLine(actcell, flag));
2277 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2279 case LyXTabular::TOGGLE_LINE_BOTTOM:
2280 status.setOnOff(tabular->BottomLine(actcell, flag));
2282 case LyXTabular::M_TOGGLE_LINE_LEFT:
2284 case LyXTabular::TOGGLE_LINE_LEFT:
2285 status.setOnOff(tabular->LeftLine(actcell, flag));
2287 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2289 case LyXTabular::TOGGLE_LINE_RIGHT:
2290 status.setOnOff(tabular->RightLine(actcell, flag));
2292 case LyXTabular::M_ALIGN_LEFT:
2294 case LyXTabular::ALIGN_LEFT:
2295 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2297 case LyXTabular::M_ALIGN_RIGHT:
2299 case LyXTabular::ALIGN_RIGHT:
2300 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2302 case LyXTabular::M_ALIGN_CENTER:
2304 case LyXTabular::ALIGN_CENTER:
2305 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2307 case LyXTabular::M_VALIGN_TOP:
2309 case LyXTabular::VALIGN_TOP:
2310 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2312 case LyXTabular::M_VALIGN_BOTTOM:
2314 case LyXTabular::VALIGN_BOTTOM:
2315 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2317 case LyXTabular::M_VALIGN_CENTER:
2319 case LyXTabular::VALIGN_CENTER:
2320 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2322 case LyXTabular::SET_LONGTABULAR:
2323 status.setOnOff(tabular->IsLongTabular());
2325 case LyXTabular::UNSET_LONGTABULAR:
2326 status.setOnOff(!tabular->IsLongTabular());
2328 case LyXTabular::SET_ROTATE_TABULAR:
2329 status.setOnOff(tabular->GetRotateTabular());
2331 case LyXTabular::UNSET_ROTATE_TABULAR:
2332 status.setOnOff(!tabular->GetRotateTabular());
2334 case LyXTabular::SET_ROTATE_CELL:
2335 status.setOnOff(tabular->GetRotateCell(actcell));
2337 case LyXTabular::UNSET_ROTATE_CELL:
2338 status.setOnOff(!tabular->GetRotateCell(actcell));
2340 case LyXTabular::SET_USEBOX:
2341 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2343 case LyXTabular::SET_LTFIRSTHEAD:
2344 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2346 case LyXTabular::SET_LTHEAD:
2347 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2349 case LyXTabular::SET_LTFOOT:
2350 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2352 case LyXTabular::SET_LTLASTFOOT:
2353 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2355 case LyXTabular::SET_LTNEWPAGE:
2356 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2360 status.disabled(true);
2367 vector<string> const InsetTabular::getLabelList() const
2369 return tabular->getLabelList();
2373 bool InsetTabular::copySelection(BufferView * bv)
2375 if (!hasSelection())
2378 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2379 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2380 if (sel_col_start > sel_col_end) {
2381 sel_col_start = sel_col_end;
2382 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2384 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2386 int const columns = sel_col_end - sel_col_start + 1;
2388 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2389 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2390 if (sel_row_start > sel_row_end) {
2391 swap(sel_row_start, sel_row_end);
2393 int const rows = sel_row_end - sel_row_start + 1;
2395 delete paste_tabular;
2396 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2397 for (int i = 0; i < sel_row_start; ++i)
2398 paste_tabular->DeleteRow(0);
2399 while (paste_tabular->rows() > rows)
2400 paste_tabular->DeleteRow(rows);
2401 paste_tabular->SetTopLine(0, true, true);
2402 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2404 for (int i = 0; i < sel_col_start; ++i)
2405 paste_tabular->DeleteColumn(0);
2406 while (paste_tabular->columns() > columns)
2407 paste_tabular->DeleteColumn(columns);
2408 paste_tabular->SetLeftLine(0, true, true);
2409 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2413 paste_tabular->ascii(bv->buffer(), sstr,
2414 (int)parOwner()->params().depth(), true, '\t');
2415 bv->stuffClipboard(sstr.str().c_str());
2420 bool InsetTabular::pasteSelection(BufferView * bv)
2425 for (int r1 = 0, r2 = actrow;
2426 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2428 for(int c1 = 0, c2 = actcol;
2429 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2431 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2432 tabular->IsPartOfMultiColumn(r2,c2))
2434 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2438 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2442 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2443 int const n2 = tabular->GetCellNumber(r2, c2);
2444 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2445 tabular->GetCellInset(n2)->setOwner(this);
2446 tabular->GetCellInset(n2)->deleteLyXText(bv);
2453 bool InsetTabular::cutSelection()
2455 if (!hasSelection())
2458 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2459 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2460 if (sel_col_start > sel_col_end) {
2461 sel_col_start = sel_col_end;
2462 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2464 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2466 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2467 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2468 if (sel_row_start > sel_row_end) {
2469 swap(sel_row_start, sel_row_end);
2471 if (sel_cell_start > sel_cell_end) {
2472 swap(sel_cell_start, sel_cell_end);
2474 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2475 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2476 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2483 bool InsetTabular::isRightToLeft(BufferView * bv)
2485 return bv->getParentLanguage(this)->RightToLeft();
2489 bool InsetTabular::nodraw() const
2491 if (!UpdatableInset::nodraw() && the_locking_inset)
2492 return the_locking_inset->nodraw();
2493 return UpdatableInset::nodraw();
2497 int InsetTabular::scroll(bool recursive) const
2499 int sx = UpdatableInset::scroll(false);
2501 if (recursive && the_locking_inset)
2502 sx += the_locking_inset->scroll(recursive);
2508 bool InsetTabular::doClearArea() const
2510 return !locked || (need_update & (FULL|INIT));
2514 void InsetTabular::getSelection(int & srow, int & erow,
2515 int & scol, int & ecol) const
2517 int const start = hasSelection() ? sel_cell_start : actcell;
2518 int const end = hasSelection() ? sel_cell_end : actcell;
2520 srow = tabular->row_of_cell(start);
2521 erow = tabular->row_of_cell(end);
2526 scol = tabular->column_of_cell(start);
2527 ecol = tabular->column_of_cell(end);
2531 ecol = tabular->right_column_of_cell(end);
2536 Paragraph * InsetTabular::getParFromID(int id) const
2539 for(int i = 0; i < tabular->rows(); ++i) {
2540 for(int j = 0; j < tabular->columns(); ++j) {
2541 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2549 Paragraph * InsetTabular::firstParagraph() const
2551 if (the_locking_inset)
2552 return the_locking_inset->firstParagraph();
2557 Paragraph * InsetTabular::getFirstParagraph(int i) const
2559 return (i < tabular->GetNumberOfCells())
2560 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2565 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2567 if (the_locking_inset)
2568 return the_locking_inset->cursor(bv);
2569 return Inset::cursor(bv);
2573 Inset * InsetTabular::getInsetFromID(int id_arg) const
2576 return const_cast<InsetTabular *>(this);
2579 for(int i = 0; i < tabular->rows(); ++i) {
2580 for(int j = 0; j < tabular->columns(); ++j) {
2581 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2590 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2593 if (the_locking_inset) {
2594 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2599 if (tabular->IsLastCell(actcell)) {
2600 bv->unlockInset(const_cast<InsetTabular *>(this));
2606 // otherwise we have to lock the next inset and ask for it's selecttion
2607 UpdatableInset * inset =
2608 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2609 inset->edit(bv, 0, 0, 0);
2610 string const str(selectNextWordInt(bv, value));
2618 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2620 // when entering this function the inset should be ALWAYS locked!
2621 lyx::Assert(the_locking_inset);
2623 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2627 if (tabular->IsLastCell(actcell)) {
2628 bv->unlockInset(const_cast<InsetTabular *>(this));
2632 // otherwise we have to lock the next inset and ask for it's selecttion
2633 UpdatableInset * inset =
2634 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2636 return selectNextWordInt(bv, value);
2640 void InsetTabular::selectSelectedWord(BufferView * bv)
2642 if (the_locking_inset) {
2643 the_locking_inset->selectSelectedWord(bv);
2650 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2652 if (the_locking_inset) {
2653 the_locking_inset->toggleSelection(bv, kill_selection);
2658 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2662 if (the_locking_inset) {
2663 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2665 updateLocal(bv, CELL, false);
2668 if (tabular->IsLastCell(actcell)) {
2670 bv->unlockInset(const_cast<InsetTabular *>(this));
2675 // otherwise we have to lock the next inset and search there
2676 UpdatableInset * inset =
2677 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2679 bool const ret = searchForward(bv, str, cs, mw);
2681 updateLocal(bv, CELL, false);
2686 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2690 if (the_locking_inset) {
2691 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2693 updateLocal(bv, CELL, false);
2696 if (!actcell) { // we are already in the first cell
2698 bv->unlockInset(const_cast<InsetTabular *>(this));
2703 // otherwise we have to lock the next inset and search there
2704 UpdatableInset * inset =
2705 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2706 inset->edit(bv, false);
2707 bool const ret = searchBackward(bv, str, cs, mw);
2709 updateLocal(bv, CELL, false);
2714 bool InsetTabular::insetAllowed(Inset::Code code) const
2716 if (the_locking_inset)
2717 return the_locking_inset->insetAllowed(code);
2722 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2724 const int cell = tabular->GetCellFromInset(in, actcell);
2727 return tabular->GetPWidth(cell).zero();
2729 // well we didn't obviously find it so maybe our owner knows more
2731 return owner()->forceDefaultParagraphs(in);
2732 // if we're here there is really something strange going on!!!