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"
21 #include "commandtags.h"
24 #include "LaTeXFeatures.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(buf.params, 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(buf.params,
161 this, *(tab.tabular), same_id));
162 the_locking_inset = 0;
163 old_locking_inset = 0;
166 actrow = actcell = 0;
170 in_reset_pos = false;
176 InsetTabular::~InsetTabular()
182 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
184 return new InsetTabular(*this, buf, same_id);
188 void InsetTabular::write(Buffer const * buf, ostream & os) const
190 os << " Tabular" << endl;
191 tabular->Write(buf, os);
195 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
197 bool const old_format = (lex.getString() == "\\LyXTable");
199 tabular.reset(new LyXTabular(buf, this, lex));
207 string token = lex.getString();
208 while (lex.isOK() && (token != "\\end_inset")) {
210 token = lex.getString();
212 if (token != "\\end_inset") {
213 lex.printError("Missing \\end_inset at this point. "
219 int InsetTabular::ascent(BufferView *, LyXFont const &) const
221 return tabular->GetAscentOfRow(0);
225 int InsetTabular::descent(BufferView *, LyXFont const &) const
227 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
231 int InsetTabular::width(BufferView *, LyXFont const &) const
233 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
237 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
238 float & x, bool cleared) const
246 if (need_update == INIT) {
247 if (calculate_dimensions_of_cells(bv, font, true))
248 bv->text->status = LyXText::CHANGED_IN_DRAW;
253 Painter & pain = bv->painter();
259 UpdatableInset::draw(bv, font, baseline, x, cleared);
262 x += static_cast<float>(scroll());
264 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
265 (top_x != int(x)) || (top_baseline != baseline)))
267 int h = ascent(bv, font) + descent(bv, font);
268 int const tx = display() || !owner() ? 0 : top_x;
269 int w = tx ? width(bv, font) : pain.paperWidth();
270 int ty = baseline - ascent(bv, font);
274 if ((ty + h) > pain.paperHeight())
275 h = pain.paperHeight();
276 if ((top_x + w) > pain.paperWidth())
277 w = pain.paperWidth();
278 pain.fillRectangle(tx, ty, w, h, backgroundColor());
284 top_baseline = baseline;
285 x += ADD_TO_TABULAR_WIDTH;
289 first_visible_cell = -1;
290 for (i = 0; i < tabular->rows(); ++i) {
292 cell = tabular->GetCellNumber(i, 0);
293 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
294 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
296 baseline += tabular->GetDescentOfRow(i) +
297 tabular->GetAscentOfRow(i + 1) +
298 tabular->GetAdditionalHeight(i + 1);
301 for (j = 0; j < tabular->columns(); ++j) {
302 if (nx > bv->workWidth())
304 if (tabular->IsPartOfMultiColumn(i, j))
306 cx = nx + tabular->GetBeginningOfTextInCell(cell);
307 if (first_visible_cell < 0)
308 first_visible_cell = cell;
309 if (hasSelection()) {
310 drawCellSelection(pain, nx, baseline, i, j, cell);
313 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
314 drawCellLines(pain, nx, baseline, i, cell);
315 nx += tabular->GetWidthOfColumn(cell);
318 baseline += tabular->GetDescentOfRow(i) +
319 tabular->GetAscentOfRow(i + 1) +
320 tabular->GetAdditionalHeight(i + 1);
322 } else if (need_update == CELL) {
325 if (the_locking_inset &&
326 tabular->GetCellInset(actcell) != the_locking_inset)
328 Inset * inset = tabular->GetCellInset(cell);
330 inset != the_locking_inset && i < tabular->rows();
334 inset != the_locking_inset && j < tabular->columns();
337 if (tabular->IsPartOfMultiColumn(i, j))
339 nx += tabular->GetWidthOfColumn(cell);
341 inset = tabular->GetCellInset(cell);
343 if (tabular->row_of_cell(cell) > i) {
345 baseline += tabular->GetDescentOfRow(i) +
346 tabular->GetAscentOfRow(i + 1) +
347 tabular->GetAdditionalHeight(i + 1);
351 // compute baseline for actual row
352 for (i = 0; i < actrow; ++i) {
353 baseline += tabular->GetDescentOfRow(i) +
354 tabular->GetAscentOfRow(i + 1) +
355 tabular->GetAdditionalHeight(i + 1);
357 // now compute the right x position
358 cell = tabular->GetCellNumber(actrow, 0);
359 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
360 if (tabular->IsPartOfMultiColumn(actrow, j))
362 nx += tabular->GetWidthOfColumn(cell);
366 i = tabular->row_of_cell(cell);
367 if (the_locking_inset != tabular->GetCellInset(cell)) {
368 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
371 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
373 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
375 // Here we use rectangular backgroundColor patches to clean up
376 // within a cell around the cell's red inset box. As follows:
378 // +--------------------+
379 // | C | The rectangles are A, B and C
380 // | A |------------| B | below, origin top left (tx, ty),
381 // | | inset box | | dimensions w(idth), h(eight).
382 // +---+------------+---+ x grows rightward, y downward
384 // +--------------------+
387 // clear only if we didn't have a change
388 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
390 // clear before the inset
393 ty = baseline - tabular->GetAscentOfRow(i) + 1;
394 w = int(cx - nx - 1);
395 h = tabular->GetAscentOfRow(i) +
396 tabular->GetDescentOfRow(i) - 1;
397 pain.fillRectangle(tx, ty, w, h, backgroundColor());
398 // clear behind the inset
399 tx = int(cx + the_locking_inset->width(bv,font) + 1);
400 ty = baseline - tabular->GetAscentOfRow(i) + 1;
401 w = tabular->GetWidthOfColumn(cell) -
402 tabular->GetBeginningOfTextInCell(cell) -
403 the_locking_inset->width(bv,font) -
404 tabular->GetAdditionalWidth(cell) - 1;
405 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
406 pain.fillRectangle(tx, ty, w, h, backgroundColor());
407 // clear below the inset
409 ty = baseline + the_locking_inset->descent(bv, font) + 1;
410 w = tabular->GetWidthOfColumn(cell) -
411 tabular->GetAdditionalWidth(cell) - 1;
412 h = tabular->GetDescentOfRow(i) -
413 the_locking_inset->descent(bv, font) - 1;
414 pain.fillRectangle(tx, ty, w, h, backgroundColor());
415 // clear above the inset
417 ty = baseline - tabular->GetAscentOfRow(i) + 1;
418 w = tabular->GetWidthOfColumn(cell) -
419 tabular->GetAdditionalWidth(cell) - 1;
420 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
421 pain.fillRectangle(tx, ty, w, h, backgroundColor());
426 x -= ADD_TO_TABULAR_WIDTH;
427 x += width(bv, font);
428 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
430 for(Inset * inset = owner(); inset; ++i)
431 inset = inset->owner();
432 if (calculate_dimensions_of_cells(bv, font, false))
440 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
441 int row, int cell) const
443 int x2 = x + tabular->GetWidthOfColumn(cell);
446 if (!tabular->TopAlreadyDrawed(cell)) {
447 on_off = !tabular->TopLine(cell);
448 pain.line(x, baseline - tabular->GetAscentOfRow(row),
449 x2, baseline - tabular->GetAscentOfRow(row),
450 on_off ? LColor::tabularonoffline : LColor::tabularline,
451 on_off ? Painter::line_onoffdash : Painter::line_solid);
453 on_off = !tabular->BottomLine(cell);
454 pain.line(x,baseline + tabular->GetDescentOfRow(row),
455 x2, baseline + tabular->GetDescentOfRow(row),
456 on_off ? LColor::tabularonoffline : LColor::tabularline,
457 on_off ? Painter::line_onoffdash : Painter::line_solid);
458 if (!tabular->LeftAlreadyDrawed(cell)) {
459 on_off = !tabular->LeftLine(cell);
460 pain.line(x, baseline - tabular->GetAscentOfRow(row),
461 x, baseline + tabular->GetDescentOfRow(row),
462 on_off ? LColor::tabularonoffline : LColor::tabularline,
463 on_off ? Painter::line_onoffdash : Painter::line_solid);
465 on_off = !tabular->RightLine(cell);
466 pain.line(x2 - tabular->GetAdditionalWidth(cell),
467 baseline - tabular->GetAscentOfRow(row),
468 x2 - tabular->GetAdditionalWidth(cell),
469 baseline + tabular->GetDescentOfRow(row),
470 on_off ? LColor::tabularonoffline : LColor::tabularline,
471 on_off ? Painter::line_onoffdash : Painter::line_solid);
475 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
476 int row, int column, int cell) const
478 lyx::Assert(hasSelection());
479 int cs = tabular->column_of_cell(sel_cell_start);
480 int ce = tabular->column_of_cell(sel_cell_end);
483 cs = tabular->column_of_cell(sel_cell_end);
485 ce = tabular->right_column_of_cell(sel_cell_end);
488 int rs = tabular->row_of_cell(sel_cell_start);
489 int re = tabular->row_of_cell(sel_cell_end);
493 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
494 int w = tabular->GetWidthOfColumn(cell);
495 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
496 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
497 w, h, LColor::selection);
502 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
508 owner()->update(bv, font, true);
515 if (calculate_dimensions_of_cells(bv, font, true))
518 owner()->update(bv, font, true);
522 if (the_locking_inset)
523 the_locking_inset->update(bv, font, reinit);
524 if (need_update < FULL &&
525 bv->text->status() == LyXText::NEED_MORE_REFRESH)
530 switch (need_update) {
534 if (calculate_dimensions_of_cells(bv, font, false))
547 string const InsetTabular::editMessage() const
549 return _("Opened Tabular Inset");
553 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
555 UpdatableInset::edit(bv, x, y, button);
557 if (!bv->lockInset(this)) {
558 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
562 the_locking_inset = 0;
568 if (insetHit(bv, x, y) && (button != 3)) {
569 activateCellInsetAbs(bv, x, y, button);
574 void InsetTabular::edit(BufferView * bv, bool front)
576 UpdatableInset::edit(bv, front);
578 if (!bv->lockInset(this)) {
579 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
583 the_locking_inset = 0;
589 actcell = tabular->GetNumberOfCells() - 1;
596 void InsetTabular::insetUnlock(BufferView * bv)
598 if (the_locking_inset) {
599 the_locking_inset->insetUnlock(bv);
600 the_locking_inset = 0;
605 if (scroll(false) || hasSelection()) {
610 updateLocal(bv, FULL, false);
615 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
616 bool mark_dirty) const
620 calculate_dimensions_of_cells(bv, font, true);
622 if (need_update < what) // only set this if it has greater update
624 #if 0 // maybe this should not be done!
625 if ((what == INIT) && hasSelection()) {
630 if (need_update != NONE) {
631 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
632 if (locked) // && (what != NONE))
638 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
640 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
645 if (inset == tabular->GetCellInset(actcell)) {
646 lyxerr[Debug::INSETTEXT] << "OK" << endl;
647 the_locking_inset = tabular->GetCellInset(actcell);
650 } else if (!the_locking_inset) {
651 int const n = tabular->GetNumberOfCells();
652 int const id = inset->id();
653 for (int i = 0; i < n; ++i) {
654 InsetText * in = tabular->GetCellInset(i);
657 the_locking_inset = in;
662 if (in->getInsetFromID(id)) {
665 return the_locking_inset->lockInsetInInset(bv, inset);
668 } else if (the_locking_inset && (the_locking_inset == inset)) {
669 lyxerr[Debug::INSETTEXT] << "OK" << endl;
671 } else if (the_locking_inset) {
672 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
673 return the_locking_inset->lockInsetInInset(bv, inset);
675 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
680 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
683 if (!the_locking_inset)
685 if (the_locking_inset == inset) {
686 the_locking_inset->insetUnlock(bv);
687 the_locking_inset = 0;
689 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
695 updateLocal(bv, CELL, false);
696 showInsetCursor(bv, false);
699 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
700 if (inset->lyxCode() == TABULAR_CODE &&
701 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
702 bv->owner()->getDialogs()->updateTabular(this);
711 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
713 if (!the_locking_inset)
715 if (the_locking_inset != inset) {
716 if (!the_locking_inset->updateInsetInInset(bv, inset))
719 updateLocal(bv, CELL, false);
724 unsigned int InsetTabular::insetInInsetY()
726 if (!the_locking_inset)
728 return inset_y + the_locking_inset->insetInInsetY();
732 UpdatableInset * InsetTabular::getLockingInset() const
734 return the_locking_inset ? the_locking_inset->getLockingInset() :
735 const_cast<InsetTabular *>(this);
739 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
743 if (the_locking_inset)
744 return the_locking_inset->getFirstLockingInsetOfType(c);
749 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
751 if (the_locking_inset)
752 return the_locking_inset->insertInset(bv, inset);
757 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
759 if (hasSelection() && (button == 3))
762 if (hasSelection()) {
764 updateLocal(bv, SELECTION, false);
767 int const ocell = actcell;
768 int const orow = actrow;
773 updateLocal(bv, NONE, false);
777 if ((ocell != actcell) && the_locking_inset) {
778 the_locking_inset->insetUnlock(bv);
779 the_locking_inset = 0;
786 bool const inset_hit = insetHit(bv, x, y);
788 if ((ocell == actcell) && the_locking_inset && inset_hit) {
790 the_locking_inset->insetButtonPress(bv,
791 x - inset_x, y - inset_y,
794 } else if (the_locking_inset) {
795 the_locking_inset->insetUnlock(bv);
797 the_locking_inset = 0;
799 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
802 if (inset_hit && bv->theLockingInset()) {
803 if (activateCellInsetAbs(bv, x, y, button))
804 the_locking_inset->insetButtonPress(bv,
814 bool InsetTabular::insetButtonRelease(BufferView * bv,
815 int x, int y, int button)
818 if (the_locking_inset)
819 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
820 y - inset_y, button);
821 if (button == 3 && !ret) {
822 bv->owner()->getDialogs()->showTabular(this);
829 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
831 if (the_locking_inset) {
832 the_locking_inset->insetMotionNotify(bv,
840 // int const old_cell = actcell;
843 if (!hasSelection()) {
844 setSelection(actcell, actcell);
846 setSelection(sel_cell_start, actcell);
848 updateLocal(bv, SELECTION, false);
853 void InsetTabular::insetKeyPress(XKeyEvent * xke)
855 if (the_locking_inset) {
856 the_locking_inset->insetKeyPress(xke);
862 UpdatableInset::RESULT
863 InsetTabular::localDispatch(BufferView * bv, kb_action action,
866 // We need to save the value of the_locking_inset as the call to
867 // the_locking_inset->LocalDispatch might unlock it.
868 old_locking_inset = the_locking_inset;
869 UpdatableInset::RESULT result =
870 UpdatableInset::localDispatch(bv, action, arg);
871 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
876 if ((action < 0) && arg.empty())
879 bool hs = hasSelection();
882 // this one have priority over the locked InsetText, if we're not already
883 // inside another tabular then that one get's priority!
884 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
889 unlockInsetInInset(bv, the_locking_inset);
890 if (action == LFUN_TAB)
891 moveNextCell(bv, old_locking_inset != 0);
893 movePrevCell(bv, old_locking_inset != 0);
896 updateLocal(bv, SELECTION, false);
897 if (!the_locking_inset) {
899 return DISPATCHED_NOUPDATE;
902 // this to avoid compiler warnings.
908 if (the_locking_inset) {
909 result = the_locking_inset->localDispatch(bv, action, arg);
910 if (result == DISPATCHED_NOUPDATE) {
913 if (sc != scroll()) { // inset has been scrolled
914 the_locking_inset->toggleInsetCursor(bv);
915 updateLocal(bv, FULL, false);
916 the_locking_inset->toggleInsetCursor(bv);
919 } else if (result == DISPATCHED) {
920 the_locking_inset->toggleInsetCursor(bv);
921 updateLocal(bv, CELL, false);
922 the_locking_inset->toggleInsetCursor(bv);
924 } else if (result == FINISHED_UP) {
926 } else if (result == FINISHED_DOWN) {
928 } else if (result == FINISHED_RIGHT) {
936 // --- Cursor Movements ----------------------------------
937 case LFUN_RIGHTSEL: {
938 int const start = hasSelection() ? sel_cell_start : actcell;
939 if (tabular->IsLastCellInRow(actcell)) {
940 setSelection(start, actcell);
945 // if we are starting a selection, only select
946 // the current cell at the beginning
947 if (hasSelection()) {
948 moveRight(bv, false);
951 setSelection(start, end);
952 updateLocal(bv, SELECTION, false);
956 result = moveRight(bv);
959 updateLocal(bv, SELECTION, false);
962 int const start = hasSelection() ? sel_cell_start : actcell;
963 if (tabular->IsFirstCellInRow(actcell)) {
964 setSelection(start, actcell);
969 // if we are starting a selection, only select
970 // the current cell at the beginning
971 if (hasSelection()) {
975 setSelection(start, end);
976 updateLocal(bv, SELECTION, false);
980 result = moveLeft(bv);
983 updateLocal(bv, SELECTION, false);
986 int const start = hasSelection() ? sel_cell_start : actcell;
987 int const ocell = actcell;
988 // if we are starting a selection, only select
989 // the current cell at the beginning
990 if (hasSelection()) {
992 if ((ocell == sel_cell_end) ||
993 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
994 setSelection(start, tabular->GetCellBelow(sel_cell_end));
996 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
998 setSelection(start, start);
1000 updateLocal(bv, SELECTION, false);
1004 result = moveDown(bv, old_locking_inset != 0);
1007 updateLocal(bv, SELECTION, false);
1011 int const start = hasSelection() ? sel_cell_start : actcell;
1012 int const ocell = actcell;
1013 // if we are starting a selection, only select
1014 // the current cell at the beginning
1015 if (hasSelection()) {
1017 if ((ocell == sel_cell_end) ||
1018 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1019 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1021 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1023 setSelection(start, start);
1025 updateLocal(bv, SELECTION, false);
1029 result = moveUp(bv, old_locking_inset != 0);
1032 updateLocal(bv, SELECTION, false);
1035 UpdateCodes code = CURSOR;
1040 int column = actcol;
1041 unlockInsetInInset(bv, the_locking_inset);
1042 if (bv->text->first_y + bv->painter().paperHeight() <
1043 (top_baseline + tabular->GetHeightOfTabular()))
1045 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1047 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1049 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1052 updateLocal(bv, code, false);
1056 UpdateCodes code = CURSOR;
1061 int column = actcol;
1062 unlockInsetInInset(bv, the_locking_inset);
1063 if (top_baseline < 0) {
1064 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1066 if (top_baseline > 0)
1069 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1074 updateLocal(bv, code, false);
1077 // none of these make sense for insettabular,
1078 // but we must catch them to prevent any
1079 // selection from being confused
1083 case LFUN_WORDLEFTSEL:
1084 case LFUN_WORDRIGHT:
1085 case LFUN_WORDRIGHTSEL:
1086 case LFUN_DOWN_PARAGRAPH:
1087 case LFUN_DOWN_PARAGRAPHSEL:
1088 case LFUN_UP_PARAGRAPH:
1089 case LFUN_UP_PARAGRAPHSEL:
1090 case LFUN_BACKSPACE:
1096 case LFUN_BEGINNINGBUF:
1097 case LFUN_BEGINNINGBUFSEL:
1099 case LFUN_ENDBUFSEL:
1101 case LFUN_LAYOUT_TABULAR:
1102 bv->owner()->getDialogs()->showTabular(this);
1104 case LFUN_TABULAR_FEATURE:
1105 if (!tabularFeatures(bv, arg))
1106 result = UNDISPATCHED;
1108 // insert file functions
1109 case LFUN_FILE_INSERT_ASCII_PARA:
1110 case LFUN_FILE_INSERT_ASCII:
1112 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1115 if (insertAsciiString(bv, tmpstr, false))
1116 updateLocal(bv, INIT, true);
1118 result = UNDISPATCHED;
1121 // cut and paste functions
1123 if (!copySelection(bv))
1125 setUndo(bv, Undo::DELETE,
1126 bv->text->cursor.par(),
1127 bv->text->cursor.par()->next());
1129 updateLocal(bv, INIT, true);
1132 if (!hasSelection())
1137 case LFUN_PASTESELECTION:
1139 string const clip(bv->getClipboard());
1143 if (clip.find('\t') != string::npos) {
1147 string::size_type len = clip.length();
1148 string::size_type p = 0;
1151 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1159 maxCols = max(cols, maxCols);
1165 maxCols = max(cols, maxCols);
1166 delete paste_tabular;
1167 paste_tabular = new LyXTabular(bv->buffer()->params,
1168 this, rows, maxCols);
1169 string::size_type op = 0;
1171 int cells = paste_tabular->GetNumberOfCells();
1173 while ((cell < cells) && (p < len) &&
1174 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1179 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1184 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1185 while (cols++ < maxCols)
1193 // check for the last cell if there is no trailing '\n'
1194 if ((cell < cells) && (op < len))
1195 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1198 if (!insertAsciiString(bv, clip, true))
1201 // so that the clipboard is used and it goes on
1203 // and executes LFUN_PASTESELECTION in insettext!
1204 delete paste_tabular;
1209 if (hasPasteBuffer()) {
1210 setUndo(bv, Undo::INSERT,
1211 bv->text->cursor.par(),
1212 bv->text->cursor.par()->next());
1214 updateLocal(bv, INIT, true);
1217 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1219 // handle font changing stuff on selection before we lock the inset
1220 // in the default part!
1221 result = UNDISPATCHED;
1232 case LFUN_UNDERLINE:
1233 case LFUN_FONT_SIZE:
1234 if (bv->Dispatch(action, arg))
1235 result = DISPATCHED;
1241 // we try to activate the actual inset and put this event down to
1242 // the insets dispatch function.
1243 if ((result == DISPATCHED) || the_locking_inset)
1246 if (activateCellInset(bv)) {
1247 // reset need_update setted in above function!
1249 result = the_locking_inset->localDispatch(bv, action, arg);
1250 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1251 unlockInsetInInset(bv, the_locking_inset);
1253 // we need to update if this was requested before
1254 updateLocal(bv, NONE, false);
1255 return UNDISPATCHED;
1258 // so the below CELL is not set because this is higher
1259 // priority and we get a full redraw
1260 need_update = SELECTION;
1263 updateLocal(bv, CELL, false);
1268 if (result < FINISHED) {
1269 if (!the_locking_inset) {
1270 showInsetCursor(bv);
1273 bv->unlockInset(this);
1278 int InsetTabular::latex(Buffer const * buf, ostream & os,
1279 bool fragile, bool fp) const
1281 return tabular->latex(buf, os, fragile, fp);
1285 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1288 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1290 return tabular->ascii(buf, os, 0, false,0);
1294 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1297 int const ret = tabular->ascii(buf,os,
1298 (int)parOwner()->params().depth(),
1305 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1310 // if the table is inside a float it doesn't need the informaltable
1311 // wrapper. Search for it.
1312 for(master = owner();
1313 master && master->lyxCode() != Inset::FLOAT_CODE;
1314 master = master->owner());
1317 os << "<informaltable>\n";
1320 ret+= tabular->docBook(buf,os);
1322 os << "</informaltable>\n";
1329 void InsetTabular::validate(LaTeXFeatures & features) const
1331 tabular->Validate(features);
1335 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1336 LyXFont const & font,
1343 bool changed = false;
1345 // if we have a locking_inset we should have to check only this cell for
1346 // change so I'll try this to have a boost, but who knows ;)
1347 if ((need_update != INIT) &&
1348 (the_locking_inset == tabular->GetCellInset(actcell))) {
1349 for(int i = 0; i < tabular->columns(); ++i) {
1350 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1352 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1355 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1356 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1357 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1360 for (int i = 0; i < tabular->rows(); ++i) {
1363 for (int j = 0; j < tabular->columns(); ++j) {
1364 if (tabular->IsPartOfMultiColumn(i,j))
1367 inset = tabular->GetCellInset(cell);
1368 if (!reinit && !tabular->GetPWidth(cell).zero())
1369 inset->update(bv, font, false);
1370 maxAsc = max(maxAsc, inset->ascent(bv, font));
1371 maxDesc = max(maxDesc, inset->descent(bv, font));
1372 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1374 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1375 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1383 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1385 if (the_locking_inset) {
1386 the_locking_inset->getCursorPos(bv, x, y);
1389 x = cursor_.x() - top_x;
1394 void InsetTabular::toggleInsetCursor(BufferView * bv)
1397 if (isCursorVisible())
1398 bv->hideLockedInsetCursor();
1401 if (the_locking_inset) {
1402 the_locking_inset->toggleInsetCursor(bv);
1406 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1408 int const asc = lyxfont::maxAscent(font);
1409 int const desc = lyxfont::maxDescent(font);
1411 if (isCursorVisible())
1412 bv->hideLockedInsetCursor();
1414 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1415 toggleCursorVisible();
1419 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1423 if (!isCursorVisible()) {
1424 LyXFont font; // = GetFont(par, cursor.pos);
1426 int const asc = lyxfont::maxAscent(font);
1427 int const desc = lyxfont::maxDescent(font);
1428 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1430 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1431 setCursorVisible(true);
1436 void InsetTabular::hideInsetCursor(BufferView * bv)
1438 if (isCursorVisible()) {
1439 bv->hideLockedInsetCursor();
1440 setCursorVisible(false);
1445 void InsetTabular::fitInsetCursor(BufferView * bv) const
1447 if (the_locking_inset) {
1448 the_locking_inset->fitInsetCursor(bv);
1453 int const asc = lyxfont::maxAscent(font);
1454 int const desc = lyxfont::maxDescent(font);
1455 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1459 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1463 actcell = actrow = actcol = 0;
1464 int ly = tabular->GetDescentOfRow(actrow);
1466 // first search the right row
1467 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1468 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1469 tabular->GetAscentOfRow(actrow + 1) +
1470 tabular->GetAdditionalHeight(actrow + 1));
1472 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1474 actcell = tabular->GetCellNumber(actrow, actcol);
1476 // now search the right column
1477 int lx = tabular->GetWidthOfColumn(actcell) -
1478 tabular->GetAdditionalWidth(actcell);
1479 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1480 lx += tabular->GetWidthOfColumn(actcell + 1)
1481 + tabular->GetAdditionalWidth(actcell);
1483 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1488 int InsetTabular::getCellXPos(int cell) const
1492 for (; !tabular->IsFirstCellInRow(c); --c)
1494 int lx = tabular->GetWidthOfColumn(cell);
1495 for (; c < cell; ++c) {
1496 lx += tabular->GetWidthOfColumn(c);
1498 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1502 void InsetTabular::resetPos(BufferView * bv) const
1504 #warning This should be fixed in the right manner (20011128 Jug)
1505 // fast hack to fix infinite repaintings!
1510 actcol = tabular->column_of_cell(actcell);
1513 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1514 if (tabular->IsLastCellInRow(cell)) {
1515 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1516 tabular->GetAscentOfRow(actrow + 1) +
1517 tabular->GetAdditionalHeight(actrow + 1));
1521 if (!locked || nodraw()) {
1522 if (the_locking_inset)
1523 inset_y = cursor_.y();
1526 // we need this only from here on!!!
1527 in_reset_pos = true;
1528 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1529 int new_x = getCellXPos(actcell);
1530 int old_x = cursor_.x();
1533 // cursor.x(getCellXPos(actcell) + offset);
1534 if ((actcol < tabular->columns()-1) && scroll(false) &&
1535 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1538 updateLocal(bv, FULL, false);
1539 } else if (the_locking_inset &&
1540 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1542 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1543 if (xx > (bv->workWidth()-20)) {
1544 scroll(bv, -(xx - bv->workWidth() + 60));
1545 updateLocal(bv, FULL, false);
1546 } else if (xx < 20) {
1552 updateLocal(bv, FULL, false);
1554 } else if ((cursor_.x() - offset) > 20 &&
1555 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1556 > (bv->workWidth() - 20)) {
1557 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1558 updateLocal(bv, FULL, false);
1559 } else if ((cursor_.x() - offset) < 20) {
1560 scroll(bv, 20 - cursor_.x() + offset);
1561 updateLocal(bv, FULL, false);
1562 } else if (scroll(false) && top_x > 20 &&
1563 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1564 scroll(bv, old_x - cursor_.x());
1565 updateLocal(bv, FULL, false);
1567 if (the_locking_inset) {
1568 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1569 inset_y = cursor_.y();
1571 if ((!the_locking_inset ||
1572 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1573 actcell != oldcell) {
1574 InsetTabular * inset = const_cast<InsetTabular *>(this);
1575 bv->owner()->getDialogs()->updateTabular(inset);
1578 in_reset_pos = false;
1582 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1584 if (lock && !old_locking_inset) {
1585 if (activateCellInset(bv))
1588 bool moved = isRightToLeft(bv)
1589 ? movePrevCell(bv) : moveNextCell(bv);
1591 return FINISHED_RIGHT;
1592 if (lock && activateCellInset(bv))
1596 return DISPATCHED_NOUPDATE;
1600 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1602 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1605 if (lock) { // behind the inset
1606 if (activateCellInset(bv, 0, 0, 0, true))
1610 return DISPATCHED_NOUPDATE;
1614 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1616 int const ocell = actcell;
1617 actcell = tabular->GetCellAbove(actcell);
1618 if (actcell == ocell) // we moved out of the inset
1624 if (old_locking_inset) {
1625 old_locking_inset->getCursorPos(bv, x, y);
1626 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1628 if (activateCellInset(bv, x, 0))
1631 return DISPATCHED_NOUPDATE;
1635 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1637 int const ocell = actcell;
1638 actcell = tabular->GetCellBelow(actcell);
1639 if (actcell == ocell) // we moved out of the inset
1640 return FINISHED_DOWN;
1645 if (old_locking_inset) {
1646 old_locking_inset->getCursorPos(bv, x, y);
1647 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1649 if (activateCellInset(bv, x, 0))
1652 return DISPATCHED_NOUPDATE;
1656 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1658 if (isRightToLeft(bv)) {
1659 if (tabular->IsFirstCellInRow(actcell)) {
1660 int row = tabular->row_of_cell(actcell);
1661 if (row == tabular->rows() - 1)
1663 actcell = tabular->GetLastCellInRow(row);
1664 actcell = tabular->GetCellBelow(actcell);
1671 if (tabular->IsLastCell(actcell))
1676 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1677 isRightToLeftPar(bv->buffer()->params);
1678 activateCellInset(bv, 0, 0, 0, !rtl);
1685 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1687 if (isRightToLeft(bv)) {
1688 if (tabular->IsLastCellInRow(actcell)) {
1689 int row = tabular->row_of_cell(actcell);
1692 actcell = tabular->GetFirstCellInRow(row);
1693 actcell = tabular->GetCellAbove(actcell);
1695 if (tabular->IsLastCell(actcell))
1700 if (!actcell) // first cell
1705 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1706 isRightToLeftPar(bv->buffer()->params);
1707 activateCellInset(bv, 0, 0, 0, !rtl);
1714 bool InsetTabular::deletable() const
1720 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1724 setSelection(0, tabular->GetNumberOfCells() - 1);
1726 if (hasSelection()) {
1727 setUndo(bv, Undo::EDIT,
1728 bv->text->cursor.par(),
1729 bv->text->cursor.par()->next());
1730 bool frozen = undo_frozen;
1733 // apply the fontchange on the whole selection
1738 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1739 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1740 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1741 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1746 updateLocal(bv, INIT, true);
1748 if (the_locking_inset)
1749 the_locking_inset->setFont(bv, font, tall);
1753 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1755 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1758 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1759 string const tmp = tabularFeature[i].feature;
1761 if (tmp == what.substr(0, tmp.length())) {
1762 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1763 //tabularFeatures[i].feature.length())) {
1764 action = tabularFeature[i].action;
1768 if (action == LyXTabular::LAST_ACTION)
1772 frontStrip(what.substr(tabularFeature[i].feature.length()));
1773 tabularFeatures(bv, action, val);
1777 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1778 string const & special, bool & flag)
1780 if (special == "dl_above") {
1783 } else if (special == "dl_below") {
1784 ltt.bottomDL = flag;
1786 } else if (special == "empty") {
1796 void InsetTabular::tabularFeatures(BufferView * bv,
1797 LyXTabular::Feature feature,
1798 string const & value)
1804 bool setLines = false;
1805 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1806 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1809 case LyXTabular::M_ALIGN_LEFT:
1810 case LyXTabular::ALIGN_LEFT:
1811 setAlign = LYX_ALIGN_LEFT;
1813 case LyXTabular::M_ALIGN_RIGHT:
1814 case LyXTabular::ALIGN_RIGHT:
1815 setAlign = LYX_ALIGN_RIGHT;
1817 case LyXTabular::M_ALIGN_CENTER:
1818 case LyXTabular::ALIGN_CENTER:
1819 setAlign = LYX_ALIGN_CENTER;
1821 case LyXTabular::M_VALIGN_TOP:
1822 case LyXTabular::VALIGN_TOP:
1823 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1825 case LyXTabular::M_VALIGN_BOTTOM:
1826 case LyXTabular::VALIGN_BOTTOM:
1827 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1829 case LyXTabular::M_VALIGN_CENTER:
1830 case LyXTabular::VALIGN_CENTER:
1831 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1836 if (hasSelection()) {
1837 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1839 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1840 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1842 setUndo(bv, Undo::FINISH,
1843 bv->text->cursor.par(),
1844 bv->text->cursor.par()->next());
1846 int row = tabular->row_of_cell(actcell);
1847 int column = tabular->column_of_cell(actcell);
1849 LyXTabular::ltType ltt;
1852 case LyXTabular::SET_PWIDTH:
1854 LyXLength const vallen(value);
1855 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1857 bool const update = (tmplen != vallen);
1858 tabular->SetColumnPWidth(actcell, vallen);
1861 for (int i = 0; i < tabular->rows(); ++i) {
1862 cell = tabular->GetCellNumber(i,column);
1863 tabular->GetCellInset(cell)->resizeLyXText(bv);
1865 updateLocal(bv, INIT, true);
1869 case LyXTabular::SET_MPWIDTH:
1871 LyXLength const vallen(value);
1872 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1874 bool const update = (tmplen != vallen);
1875 tabular->SetMColumnPWidth(actcell, vallen);
1877 for (int i = 0; i < tabular->rows(); ++i) {
1878 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1881 updateLocal(bv, INIT, true);
1885 case LyXTabular::SET_SPECIAL_COLUMN:
1886 case LyXTabular::SET_SPECIAL_MULTI:
1887 tabular->SetAlignSpecial(actcell,value,feature);
1888 updateLocal(bv, FULL, true);
1890 case LyXTabular::APPEND_ROW:
1891 // append the row into the tabular
1892 unlockInsetInInset(bv, the_locking_inset);
1893 tabular->AppendRow(bv->buffer()->params, actcell);
1894 updateLocal(bv, INIT, true);
1896 case LyXTabular::APPEND_COLUMN:
1897 // append the column into the tabular
1898 unlockInsetInInset(bv, the_locking_inset);
1899 tabular->AppendColumn(bv->buffer()->params, actcell);
1900 actcell = tabular->GetCellNumber(row, column);
1901 updateLocal(bv, INIT, true);
1903 case LyXTabular::DELETE_ROW:
1904 unlockInsetInInset(bv, the_locking_inset);
1905 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1906 tabular->DeleteRow(sel_row_start);
1908 if (sel_row_start >= tabular->rows())
1910 actcell = tabular->GetCellNumber(sel_row_start, column);
1912 updateLocal(bv, INIT, true);
1914 case LyXTabular::DELETE_COLUMN:
1915 unlockInsetInInset(bv, the_locking_inset);
1916 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1917 tabular->DeleteColumn(sel_col_start);
1919 if (sel_col_start >= tabular->columns())
1921 actcell = tabular->GetCellNumber(row, sel_col_start);
1923 updateLocal(bv, INIT, true);
1925 case LyXTabular::M_TOGGLE_LINE_TOP:
1927 case LyXTabular::TOGGLE_LINE_TOP:
1929 bool lineSet = !tabular->TopLine(actcell, flag);
1930 for (int i = sel_row_start; i <= sel_row_end; ++i)
1931 for (int j = sel_col_start; j <= sel_col_end; ++j)
1932 tabular->SetTopLine(
1933 tabular->GetCellNumber(i, j),
1935 updateLocal(bv, INIT, true);
1939 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1941 case LyXTabular::TOGGLE_LINE_BOTTOM:
1943 bool lineSet = !tabular->BottomLine(actcell, flag);
1944 for (int i = sel_row_start; i <= sel_row_end; ++i)
1945 for (int j = sel_col_start; j <= sel_col_end; ++j)
1946 tabular->SetBottomLine(
1947 tabular->GetCellNumber(i, j),
1950 updateLocal(bv, INIT, true);
1954 case LyXTabular::M_TOGGLE_LINE_LEFT:
1956 case LyXTabular::TOGGLE_LINE_LEFT:
1958 bool lineSet = !tabular->LeftLine(actcell, flag);
1959 for (int i = sel_row_start; i <= sel_row_end; ++i)
1960 for (int j = sel_col_start; j <= sel_col_end; ++j)
1961 tabular->SetLeftLine(
1962 tabular->GetCellNumber(i,j),
1965 updateLocal(bv, INIT, true);
1969 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1971 case LyXTabular::TOGGLE_LINE_RIGHT:
1973 bool lineSet = !tabular->RightLine(actcell, flag);
1974 for (int i = sel_row_start; i <= sel_row_end; ++i)
1975 for (int j = sel_col_start; j <= sel_col_end; ++j)
1976 tabular->SetRightLine(
1977 tabular->GetCellNumber(i,j),
1980 updateLocal(bv, INIT, true);
1984 case LyXTabular::M_ALIGN_LEFT:
1985 case LyXTabular::M_ALIGN_RIGHT:
1986 case LyXTabular::M_ALIGN_CENTER:
1988 case LyXTabular::ALIGN_LEFT:
1989 case LyXTabular::ALIGN_RIGHT:
1990 case LyXTabular::ALIGN_CENTER:
1991 for (int i = sel_row_start; i <= sel_row_end; ++i)
1992 for (int j = sel_col_start; j <= sel_col_end; ++j)
1993 tabular->SetAlignment(
1994 tabular->GetCellNumber(i, j),
1997 updateLocal(bv, INIT, true);
1999 case LyXTabular::M_VALIGN_TOP:
2000 case LyXTabular::M_VALIGN_BOTTOM:
2001 case LyXTabular::M_VALIGN_CENTER:
2003 case LyXTabular::VALIGN_TOP:
2004 case LyXTabular::VALIGN_BOTTOM:
2005 case LyXTabular::VALIGN_CENTER:
2006 for (int i = sel_row_start; i <= sel_row_end; ++i)
2007 for (int j = sel_col_start; j <= sel_col_end; ++j)
2008 tabular->SetVAlignment(
2009 tabular->GetCellNumber(i, j),
2011 updateLocal(bv, INIT, true);
2013 case LyXTabular::MULTICOLUMN:
2015 if (sel_row_start != sel_row_end) {
2016 Alert::alert(_("Impossible Operation!"),
2017 _("Multicolumns can only be horizontally."),
2021 // just multicol for one Single Cell
2022 if (!hasSelection()) {
2023 // check wether we are completly in a multicol
2024 if (tabular->IsMultiColumn(actcell)) {
2025 tabular->UnsetMultiColumn(actcell);
2026 updateLocal(bv, INIT, true);
2028 tabular->SetMultiColumn(actcell, 1);
2029 updateLocal(bv, CELL, true);
2033 // we have a selection so this means we just add all this
2034 // cells to form a multicolumn cell
2038 if (sel_cell_start > sel_cell_end) {
2039 s_start = sel_cell_end;
2040 s_end = sel_cell_start;
2042 s_start = sel_cell_start;
2043 s_end = sel_cell_end;
2045 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
2048 updateLocal(bv, INIT, true);
2051 case LyXTabular::SET_ALL_LINES:
2053 case LyXTabular::UNSET_ALL_LINES:
2054 for (int i = sel_row_start; i <= sel_row_end; ++i)
2055 for (int j = sel_col_start; j <= sel_col_end; ++j)
2056 tabular->SetAllLines(
2057 tabular->GetCellNumber(i,j), setLines);
2058 updateLocal(bv, INIT, true);
2060 case LyXTabular::SET_LONGTABULAR:
2061 tabular->SetLongTabular(true);
2062 updateLocal(bv, INIT, true); // because this toggles displayed
2064 case LyXTabular::UNSET_LONGTABULAR:
2065 tabular->SetLongTabular(false);
2066 updateLocal(bv, INIT, true); // because this toggles displayed
2068 case LyXTabular::SET_ROTATE_TABULAR:
2069 tabular->SetRotateTabular(true);
2071 case LyXTabular::UNSET_ROTATE_TABULAR:
2072 tabular->SetRotateTabular(false);
2074 case LyXTabular::SET_ROTATE_CELL:
2075 for (int i = sel_row_start; i <= sel_row_end; ++i)
2076 for (int j = sel_col_start; j<=sel_col_end; ++j)
2077 tabular->SetRotateCell(
2078 tabular->GetCellNumber(i, j),
2081 case LyXTabular::UNSET_ROTATE_CELL:
2082 for (int i = sel_row_start; i <= sel_row_end; ++i)
2083 for (int j = sel_col_start; j <= sel_col_end; ++j)
2084 tabular->SetRotateCell(
2085 tabular->GetCellNumber(i, j), false);
2087 case LyXTabular::SET_USEBOX:
2089 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2090 if (val == tabular->GetUsebox(actcell))
2091 val = LyXTabular::BOX_NONE;
2092 for (int i = sel_row_start; i <= sel_row_end; ++i)
2093 for (int j = sel_col_start; j <= sel_col_end; ++j)
2095 tabular->GetCellNumber(i, j), val);
2098 case LyXTabular::UNSET_LTFIRSTHEAD:
2100 case LyXTabular::SET_LTFIRSTHEAD:
2101 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2102 checkLongtableSpecial(ltt, value, flag);
2103 tabular->SetLTHead(row, flag, ltt, true);
2105 case LyXTabular::UNSET_LTHEAD:
2107 case LyXTabular::SET_LTHEAD:
2108 (void)tabular->GetRowOfLTHead(row, ltt);
2109 checkLongtableSpecial(ltt, value, flag);
2110 tabular->SetLTHead(row, flag, ltt, false);
2112 case LyXTabular::UNSET_LTFOOT:
2114 case LyXTabular::SET_LTFOOT:
2115 (void)tabular->GetRowOfLTFoot(row, ltt);
2116 checkLongtableSpecial(ltt, value, flag);
2117 tabular->SetLTFoot(row, flag, ltt, false);
2119 case LyXTabular::UNSET_LTLASTFOOT:
2121 case LyXTabular::SET_LTLASTFOOT:
2122 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2123 checkLongtableSpecial(ltt, value, flag);
2124 tabular->SetLTFoot(row, flag, ltt, true);
2126 case LyXTabular::SET_LTNEWPAGE:
2128 bool what = !tabular->GetLTNewPage(row);
2129 tabular->SetLTNewPage(row, what);
2132 // dummy stuff just to avoid warnings
2133 case LyXTabular::LAST_ACTION:
2139 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2142 UpdatableInset * inset =
2143 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2144 LyXFont font(LyXFont::ALL_SANE);
2146 x = inset->x() + inset->width(bv, font);
2147 y = inset->descent(bv, font);
2149 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2150 //inset_y = cursor.y();
2151 inset->edit(bv, x, y, button);
2152 if (!the_locking_inset)
2154 updateLocal(bv, CELL, false);
2155 return (the_locking_inset != 0);
2159 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2162 inset_x = cursor_.x()
2163 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2164 inset_y = cursor_.y();
2165 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2169 bool InsetTabular::insetHit(BufferView *, int x, int) const
2172 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2176 // This returns paperWidth() if the cell-width is unlimited or the width
2177 // in pixels if we have a pwidth for this cell.
2178 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2180 LyXLength const len = tabular->GetPWidth(cell);
2184 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2188 int InsetTabular::getMaxWidth(BufferView * bv,
2189 UpdatableInset const * inset) const
2191 int cell = tabular->GetCellFromInset(inset, actcell);
2194 lyxerr << "Own inset not found, shouldn't really happen!"
2199 int w = getMaxWidthOfCell(bv, cell);
2201 // because the inset then subtracts it's top_x and owner->x()
2202 w += (inset->x() - top_x);
2209 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2211 resizeLyXText(bv, recursive);
2215 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2218 for(int i = 0; i < tabular->rows(); ++i) {
2219 for(int j = 0; j < tabular->columns(); ++j) {
2220 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2228 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2229 bool const recursive) const
2231 if (the_locking_inset)
2232 return the_locking_inset->getLyXText(bv, recursive);
2234 // if we're locked lock the actual insettext and return it's LyXText!!!
2236 UpdatableInset * inset =
2237 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2238 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2239 return the_locking_inset->getLyXText(bv, recursive);
2242 return Inset::getLyXText(bv, recursive);
2246 bool InsetTabular::showInsetDialog(BufferView * bv) const
2248 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2249 bv->owner()->getDialogs()
2250 ->showTabular(const_cast<InsetTabular *>(this));
2255 void InsetTabular::openLayoutDialog(BufferView * bv) const
2257 if (the_locking_inset) {
2258 InsetTabular * i = static_cast<InsetTabular *>
2259 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2261 i->openLayoutDialog(bv);
2265 bv->owner()->getDialogs()->showTabular(
2266 const_cast<InsetTabular *>(this));
2271 // function returns an object as defined in func_status.h:
2272 // states OK, Unknown, Disabled, On, Off.
2274 FuncStatus InsetTabular::getStatus(string const & what) const
2276 int action = LyXTabular::LAST_ACTION;
2280 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2281 string const tmp = tabularFeature[i].feature;
2282 if (tmp == what.substr(0, tmp.length())) {
2283 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2284 // tabularFeatures[i].feature.length())) {
2285 action = tabularFeature[i].action;
2289 if (action == LyXTabular::LAST_ACTION) {
2291 return status.unknown(true);
2294 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2299 LyXTabular::ltType dummyltt;
2302 if (hasSelection()) {
2303 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2305 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2309 case LyXTabular::SET_PWIDTH:
2310 case LyXTabular::SET_MPWIDTH:
2311 case LyXTabular::SET_SPECIAL_COLUMN:
2312 case LyXTabular::SET_SPECIAL_MULTI:
2313 return status.disabled(true);
2315 case LyXTabular::APPEND_ROW:
2316 case LyXTabular::APPEND_COLUMN:
2317 case LyXTabular::DELETE_ROW:
2318 case LyXTabular::DELETE_COLUMN:
2319 case LyXTabular::SET_ALL_LINES:
2320 case LyXTabular::UNSET_ALL_LINES:
2321 return status.clear();
2323 case LyXTabular::MULTICOLUMN:
2324 status.setOnOff(tabular->IsMultiColumn(actcell));
2326 case LyXTabular::M_TOGGLE_LINE_TOP:
2328 case LyXTabular::TOGGLE_LINE_TOP:
2329 status.setOnOff(tabular->TopLine(actcell, flag));
2331 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2333 case LyXTabular::TOGGLE_LINE_BOTTOM:
2334 status.setOnOff(tabular->BottomLine(actcell, flag));
2336 case LyXTabular::M_TOGGLE_LINE_LEFT:
2338 case LyXTabular::TOGGLE_LINE_LEFT:
2339 status.setOnOff(tabular->LeftLine(actcell, flag));
2341 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2343 case LyXTabular::TOGGLE_LINE_RIGHT:
2344 status.setOnOff(tabular->RightLine(actcell, flag));
2346 case LyXTabular::M_ALIGN_LEFT:
2348 case LyXTabular::ALIGN_LEFT:
2349 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2351 case LyXTabular::M_ALIGN_RIGHT:
2353 case LyXTabular::ALIGN_RIGHT:
2354 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2356 case LyXTabular::M_ALIGN_CENTER:
2358 case LyXTabular::ALIGN_CENTER:
2359 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2361 case LyXTabular::M_VALIGN_TOP:
2363 case LyXTabular::VALIGN_TOP:
2364 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2366 case LyXTabular::M_VALIGN_BOTTOM:
2368 case LyXTabular::VALIGN_BOTTOM:
2369 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2371 case LyXTabular::M_VALIGN_CENTER:
2373 case LyXTabular::VALIGN_CENTER:
2374 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2376 case LyXTabular::SET_LONGTABULAR:
2377 status.setOnOff(tabular->IsLongTabular());
2379 case LyXTabular::UNSET_LONGTABULAR:
2380 status.setOnOff(!tabular->IsLongTabular());
2382 case LyXTabular::SET_ROTATE_TABULAR:
2383 status.setOnOff(tabular->GetRotateTabular());
2385 case LyXTabular::UNSET_ROTATE_TABULAR:
2386 status.setOnOff(!tabular->GetRotateTabular());
2388 case LyXTabular::SET_ROTATE_CELL:
2389 status.setOnOff(tabular->GetRotateCell(actcell));
2391 case LyXTabular::UNSET_ROTATE_CELL:
2392 status.setOnOff(!tabular->GetRotateCell(actcell));
2394 case LyXTabular::SET_USEBOX:
2395 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2397 case LyXTabular::SET_LTFIRSTHEAD:
2398 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2400 case LyXTabular::SET_LTHEAD:
2401 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2403 case LyXTabular::SET_LTFOOT:
2404 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2406 case LyXTabular::SET_LTLASTFOOT:
2407 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2409 case LyXTabular::SET_LTNEWPAGE:
2410 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2414 status.disabled(true);
2421 vector<string> const InsetTabular::getLabelList() const
2423 return tabular->getLabelList();
2427 bool InsetTabular::copySelection(BufferView * bv)
2429 if (!hasSelection())
2432 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2433 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2434 if (sel_col_start > sel_col_end) {
2435 sel_col_start = sel_col_end;
2436 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2438 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2440 int const columns = sel_col_end - sel_col_start + 1;
2442 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2443 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2444 if (sel_row_start > sel_row_end) {
2445 swap(sel_row_start, sel_row_end);
2447 int const rows = sel_row_end - sel_row_start + 1;
2449 delete paste_tabular;
2450 paste_tabular = new LyXTabular(bv->buffer()->params,
2451 this, *tabular); // rows, columns);
2452 for (int i = 0; i < sel_row_start; ++i)
2453 paste_tabular->DeleteRow(0);
2454 while (paste_tabular->rows() > rows)
2455 paste_tabular->DeleteRow(rows);
2456 paste_tabular->SetTopLine(0, true, true);
2457 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2459 for (int i = 0; i < sel_col_start; ++i)
2460 paste_tabular->DeleteColumn(0);
2461 while (paste_tabular->columns() > columns)
2462 paste_tabular->DeleteColumn(columns);
2463 paste_tabular->SetLeftLine(0, true, true);
2464 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2468 paste_tabular->ascii(bv->buffer(), sstr,
2469 (int)parOwner()->params().depth(), true, '\t');
2470 bv->stuffClipboard(sstr.str().c_str());
2475 bool InsetTabular::pasteSelection(BufferView * bv)
2480 for (int r1 = 0, r2 = actrow;
2481 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2483 for(int c1 = 0, c2 = actcol;
2484 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2486 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2487 tabular->IsPartOfMultiColumn(r2,c2))
2489 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2493 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2497 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2498 int const n2 = tabular->GetCellNumber(r2, c2);
2499 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2500 tabular->GetCellInset(n2)->setOwner(this);
2501 tabular->GetCellInset(n2)->deleteLyXText(bv);
2508 bool InsetTabular::cutSelection()
2510 if (!hasSelection())
2513 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2514 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2515 if (sel_col_start > sel_col_end) {
2516 sel_col_start = sel_col_end;
2517 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2519 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2521 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2522 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2523 if (sel_row_start > sel_row_end) {
2524 swap(sel_row_start, sel_row_end);
2526 if (sel_cell_start > sel_cell_end) {
2527 swap(sel_cell_start, sel_cell_end);
2529 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2530 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2531 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2538 bool InsetTabular::isRightToLeft(BufferView * bv)
2540 return bv->getParentLanguage(this)->RightToLeft();
2544 bool InsetTabular::nodraw() const
2546 if (!UpdatableInset::nodraw() && the_locking_inset)
2547 return the_locking_inset->nodraw();
2548 return UpdatableInset::nodraw();
2552 int InsetTabular::scroll(bool recursive) const
2554 int sx = UpdatableInset::scroll(false);
2556 if (recursive && the_locking_inset)
2557 sx += the_locking_inset->scroll(recursive);
2563 bool InsetTabular::doClearArea() const
2565 return !locked || (need_update & (FULL|INIT));
2569 void InsetTabular::getSelection(int & srow, int & erow,
2570 int & scol, int & ecol) const
2572 int const start = hasSelection() ? sel_cell_start : actcell;
2573 int const end = hasSelection() ? sel_cell_end : actcell;
2575 srow = tabular->row_of_cell(start);
2576 erow = tabular->row_of_cell(end);
2581 scol = tabular->column_of_cell(start);
2582 ecol = tabular->column_of_cell(end);
2586 ecol = tabular->right_column_of_cell(end);
2591 Paragraph * InsetTabular::getParFromID(int id) const
2594 for(int i = 0; i < tabular->rows(); ++i) {
2595 for(int j = 0; j < tabular->columns(); ++j) {
2596 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2604 Paragraph * InsetTabular::firstParagraph() const
2606 if (the_locking_inset)
2607 return the_locking_inset->firstParagraph();
2612 Paragraph * InsetTabular::getFirstParagraph(int i) const
2614 return (i < tabular->GetNumberOfCells())
2615 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2620 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2622 if (the_locking_inset)
2623 return the_locking_inset->cursor(bv);
2624 return Inset::cursor(bv);
2628 Inset * InsetTabular::getInsetFromID(int id_arg) const
2631 return const_cast<InsetTabular *>(this);
2634 for(int i = 0; i < tabular->rows(); ++i) {
2635 for(int j = 0; j < tabular->columns(); ++j) {
2636 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2645 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2648 if (the_locking_inset) {
2649 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2654 if (tabular->IsLastCell(actcell)) {
2655 bv->unlockInset(const_cast<InsetTabular *>(this));
2661 // otherwise we have to lock the next inset and ask for it's selecttion
2662 UpdatableInset * inset =
2663 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2664 inset->edit(bv, 0, 0, 0);
2665 string const str(selectNextWordInt(bv, value));
2673 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2675 // when entering this function the inset should be ALWAYS locked!
2676 lyx::Assert(the_locking_inset);
2678 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2682 if (tabular->IsLastCell(actcell)) {
2683 bv->unlockInset(const_cast<InsetTabular *>(this));
2687 // otherwise we have to lock the next inset and ask for it's selecttion
2688 UpdatableInset * inset =
2689 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2691 return selectNextWordInt(bv, value);
2695 void InsetTabular::selectSelectedWord(BufferView * bv)
2697 if (the_locking_inset) {
2698 the_locking_inset->selectSelectedWord(bv);
2705 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2707 if (the_locking_inset) {
2708 the_locking_inset->toggleSelection(bv, kill_selection);
2713 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2717 if (the_locking_inset) {
2718 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2720 updateLocal(bv, CELL, false);
2723 if (tabular->IsLastCell(actcell)) {
2725 bv->unlockInset(const_cast<InsetTabular *>(this));
2730 // otherwise we have to lock the next inset and search there
2731 UpdatableInset * inset =
2732 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2734 bool const ret = searchForward(bv, str, cs, mw);
2736 updateLocal(bv, CELL, false);
2741 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2745 if (the_locking_inset) {
2746 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2748 updateLocal(bv, CELL, false);
2751 if (!actcell) { // we are already in the first cell
2753 bv->unlockInset(const_cast<InsetTabular *>(this));
2758 // otherwise we have to lock the next inset and search there
2759 UpdatableInset * inset =
2760 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2761 inset->edit(bv, false);
2762 bool const ret = searchBackward(bv, str, cs, mw);
2764 updateLocal(bv, CELL, false);
2769 bool InsetTabular::insetAllowed(Inset::Code code) const
2771 if (the_locking_inset)
2772 return the_locking_inset->insetAllowed(code);
2777 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2779 const int cell = tabular->GetCellFromInset(in, actcell);
2782 return tabular->GetPWidth(cell).zero();
2784 // well we didn't obviously find it so maybe our owner knows more
2786 return owner()->forceDefaultParagraphs(in);
2787 // if we're here there is really something strange going on!!!
2791 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2794 if (buf.find('\t') == string::npos)
2800 string::size_type len = buf.length();
2801 string::size_type p = 0;
2804 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2813 maxCols = max(cols, maxCols);
2819 maxCols = max(cols, maxCols);
2820 LyXTabular * loctab;
2825 delete paste_tabular;
2826 paste_tabular = new LyXTabular(bv->buffer()->params,
2827 this, rows, maxCols);
2828 loctab = paste_tabular;
2831 loctab = tabular.get();
2836 string::size_type op = 0;
2837 int cells = loctab->GetNumberOfCells();
2840 rows = loctab->rows();
2841 int const columns = loctab->columns();
2842 while ((cell < cells) && (p < len) && (row < rows) &&
2843 (p = buf.find_first_of("\t\n", p)) != string::npos)
2849 // we can only set this if we are not too far right
2850 if (cols < columns) {
2851 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2857 // we can only set this if we are not too far right
2859 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2863 cell = loctab->GetCellNumber(row, cols);
2869 // check for the last cell if there is no trailing '\n'
2870 if ((cell < cells) && (op < len))
2871 loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));