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 // only activate the Inset so that no internal inset is hit
804 // by this call. It should be only hit by the insetButtonPress call.
805 if (activateCellInsetAbs(bv, 0, 0, 0))
806 the_locking_inset->insetButtonPress(bv,
816 bool InsetTabular::insetButtonRelease(BufferView * bv,
817 int x, int y, int button)
820 if (the_locking_inset)
821 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
822 y - inset_y, button);
823 if (button == 3 && !ret) {
824 bv->owner()->getDialogs()->showTabular(this);
831 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
833 if (the_locking_inset) {
834 the_locking_inset->insetMotionNotify(bv,
842 // int const old_cell = actcell;
845 if (!hasSelection()) {
846 setSelection(actcell, actcell);
848 setSelection(sel_cell_start, actcell);
850 updateLocal(bv, SELECTION, false);
855 void InsetTabular::insetKeyPress(XKeyEvent * xke)
857 if (the_locking_inset) {
858 the_locking_inset->insetKeyPress(xke);
864 UpdatableInset::RESULT
865 InsetTabular::localDispatch(BufferView * bv, kb_action action,
868 // We need to save the value of the_locking_inset as the call to
869 // the_locking_inset->LocalDispatch might unlock it.
870 old_locking_inset = the_locking_inset;
871 UpdatableInset::RESULT result =
872 UpdatableInset::localDispatch(bv, action, arg);
873 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
878 if ((action < 0) && arg.empty())
881 bool hs = hasSelection();
884 // this one have priority over the locked InsetText, if we're not already
885 // inside another tabular then that one get's priority!
886 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
891 unlockInsetInInset(bv, the_locking_inset);
892 if (action == LFUN_TAB)
893 moveNextCell(bv, old_locking_inset != 0);
895 movePrevCell(bv, old_locking_inset != 0);
898 updateLocal(bv, SELECTION, false);
899 if (!the_locking_inset) {
901 return DISPATCHED_NOUPDATE;
904 // this to avoid compiler warnings.
910 if (the_locking_inset) {
911 result = the_locking_inset->localDispatch(bv, action, arg);
912 if (result == DISPATCHED_NOUPDATE) {
915 if (sc != scroll()) { // inset has been scrolled
916 the_locking_inset->toggleInsetCursor(bv);
917 updateLocal(bv, FULL, false);
918 the_locking_inset->toggleInsetCursor(bv);
921 } else if (result == DISPATCHED) {
922 the_locking_inset->toggleInsetCursor(bv);
923 updateLocal(bv, CELL, false);
924 the_locking_inset->toggleInsetCursor(bv);
926 } else if (result == FINISHED_UP) {
928 } else if (result == FINISHED_DOWN) {
930 } else if (result == FINISHED_RIGHT) {
938 // --- Cursor Movements ----------------------------------
939 case LFUN_RIGHTSEL: {
940 int const start = hasSelection() ? sel_cell_start : actcell;
941 if (tabular->IsLastCellInRow(actcell)) {
942 setSelection(start, actcell);
947 // if we are starting a selection, only select
948 // the current cell at the beginning
949 if (hasSelection()) {
950 moveRight(bv, false);
953 setSelection(start, end);
954 updateLocal(bv, SELECTION, false);
958 result = moveRight(bv);
961 updateLocal(bv, SELECTION, false);
964 int const start = hasSelection() ? sel_cell_start : actcell;
965 if (tabular->IsFirstCellInRow(actcell)) {
966 setSelection(start, actcell);
971 // if we are starting a selection, only select
972 // the current cell at the beginning
973 if (hasSelection()) {
977 setSelection(start, end);
978 updateLocal(bv, SELECTION, false);
982 result = moveLeft(bv);
985 updateLocal(bv, SELECTION, false);
988 int const start = hasSelection() ? sel_cell_start : actcell;
989 int const ocell = actcell;
990 // if we are starting a selection, only select
991 // the current cell at the beginning
992 if (hasSelection()) {
994 if ((ocell == sel_cell_end) ||
995 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
996 setSelection(start, tabular->GetCellBelow(sel_cell_end));
998 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1000 setSelection(start, start);
1002 updateLocal(bv, SELECTION, false);
1006 result = moveDown(bv, old_locking_inset != 0);
1009 updateLocal(bv, SELECTION, false);
1013 int const start = hasSelection() ? sel_cell_start : actcell;
1014 int const ocell = actcell;
1015 // if we are starting a selection, only select
1016 // the current cell at the beginning
1017 if (hasSelection()) {
1019 if ((ocell == sel_cell_end) ||
1020 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1021 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1023 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1025 setSelection(start, start);
1027 updateLocal(bv, SELECTION, false);
1031 result = moveUp(bv, old_locking_inset != 0);
1034 updateLocal(bv, SELECTION, false);
1037 UpdateCodes code = CURSOR;
1042 int column = actcol;
1043 unlockInsetInInset(bv, the_locking_inset);
1044 if (bv->text->first_y + bv->painter().paperHeight() <
1045 (top_baseline + tabular->GetHeightOfTabular()))
1047 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1049 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1051 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1054 updateLocal(bv, code, false);
1058 UpdateCodes code = CURSOR;
1063 int column = actcol;
1064 unlockInsetInInset(bv, the_locking_inset);
1065 if (top_baseline < 0) {
1066 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1068 if (top_baseline > 0)
1071 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1076 updateLocal(bv, code, false);
1079 // none of these make sense for insettabular,
1080 // but we must catch them to prevent any
1081 // selection from being confused
1085 case LFUN_WORDLEFTSEL:
1086 case LFUN_WORDRIGHT:
1087 case LFUN_WORDRIGHTSEL:
1088 case LFUN_DOWN_PARAGRAPH:
1089 case LFUN_DOWN_PARAGRAPHSEL:
1090 case LFUN_UP_PARAGRAPH:
1091 case LFUN_UP_PARAGRAPHSEL:
1092 case LFUN_BACKSPACE:
1098 case LFUN_BEGINNINGBUF:
1099 case LFUN_BEGINNINGBUFSEL:
1101 case LFUN_ENDBUFSEL:
1103 case LFUN_LAYOUT_TABULAR:
1104 bv->owner()->getDialogs()->showTabular(this);
1106 case LFUN_TABULAR_FEATURE:
1107 if (!tabularFeatures(bv, arg))
1108 result = UNDISPATCHED;
1110 // insert file functions
1111 case LFUN_FILE_INSERT_ASCII_PARA:
1112 case LFUN_FILE_INSERT_ASCII:
1114 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1117 if (insertAsciiString(bv, tmpstr, false))
1118 updateLocal(bv, INIT, true);
1120 result = UNDISPATCHED;
1123 // cut and paste functions
1125 if (!copySelection(bv))
1127 setUndo(bv, Undo::DELETE,
1128 bv->text->cursor.par(),
1129 bv->text->cursor.par()->next());
1131 updateLocal(bv, INIT, true);
1134 if (!hasSelection())
1139 case LFUN_PASTESELECTION:
1141 string const clip(bv->getClipboard());
1145 if (clip.find('\t') != string::npos) {
1149 string::size_type len = clip.length();
1150 string::size_type p = 0;
1153 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1161 maxCols = max(cols, maxCols);
1167 maxCols = max(cols, maxCols);
1168 delete paste_tabular;
1169 paste_tabular = new LyXTabular(bv->buffer()->params,
1170 this, rows, maxCols);
1171 string::size_type op = 0;
1173 int cells = paste_tabular->GetNumberOfCells();
1175 while ((cell < cells) && (p < len) &&
1176 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1181 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1186 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1187 while (cols++ < maxCols)
1195 // check for the last cell if there is no trailing '\n'
1196 if ((cell < cells) && (op < len))
1197 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1200 if (!insertAsciiString(bv, clip, true))
1203 // so that the clipboard is used and it goes on
1205 // and executes LFUN_PASTESELECTION in insettext!
1206 delete paste_tabular;
1211 if (hasPasteBuffer()) {
1212 setUndo(bv, Undo::INSERT,
1213 bv->text->cursor.par(),
1214 bv->text->cursor.par()->next());
1216 updateLocal(bv, INIT, true);
1219 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1221 // handle font changing stuff on selection before we lock the inset
1222 // in the default part!
1223 result = UNDISPATCHED;
1234 case LFUN_UNDERLINE:
1235 case LFUN_FONT_SIZE:
1236 if (bv->Dispatch(action, arg))
1237 result = DISPATCHED;
1243 // we try to activate the actual inset and put this event down to
1244 // the insets dispatch function.
1245 if ((result == DISPATCHED) || the_locking_inset)
1248 if (activateCellInset(bv)) {
1249 // reset need_update setted in above function!
1251 result = the_locking_inset->localDispatch(bv, action, arg);
1252 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1253 unlockInsetInInset(bv, the_locking_inset);
1255 // we need to update if this was requested before
1256 updateLocal(bv, NONE, false);
1257 return UNDISPATCHED;
1260 // so the below CELL is not set because this is higher
1261 // priority and we get a full redraw
1262 need_update = SELECTION;
1265 updateLocal(bv, CELL, false);
1270 if (result < FINISHED) {
1271 if (!the_locking_inset) {
1272 showInsetCursor(bv);
1275 bv->unlockInset(this);
1280 int InsetTabular::latex(Buffer const * buf, ostream & os,
1281 bool fragile, bool fp) const
1283 return tabular->latex(buf, os, fragile, fp);
1287 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1290 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1292 return tabular->ascii(buf, os, 0, false,0);
1296 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1299 int const ret = tabular->ascii(buf,os,
1300 (int)parOwner()->params().depth(),
1307 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1312 // if the table is inside a float it doesn't need the informaltable
1313 // wrapper. Search for it.
1314 for(master = owner();
1315 master && master->lyxCode() != Inset::FLOAT_CODE;
1316 master = master->owner());
1319 os << "<informaltable>\n";
1322 ret+= tabular->docBook(buf,os);
1324 os << "</informaltable>\n";
1331 void InsetTabular::validate(LaTeXFeatures & features) const
1333 tabular->Validate(features);
1337 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1338 LyXFont const & font,
1345 bool changed = false;
1347 // if we have a locking_inset we should have to check only this cell for
1348 // change so I'll try this to have a boost, but who knows ;)
1349 if ((need_update != INIT) &&
1350 (the_locking_inset == tabular->GetCellInset(actcell))) {
1351 for(int i = 0; i < tabular->columns(); ++i) {
1352 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1354 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1357 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1358 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1359 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1362 for (int i = 0; i < tabular->rows(); ++i) {
1365 for (int j = 0; j < tabular->columns(); ++j) {
1366 if (tabular->IsPartOfMultiColumn(i,j))
1369 inset = tabular->GetCellInset(cell);
1370 if (!reinit && !tabular->GetPWidth(cell).zero())
1371 inset->update(bv, font, false);
1372 maxAsc = max(maxAsc, inset->ascent(bv, font));
1373 maxDesc = max(maxDesc, inset->descent(bv, font));
1374 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1376 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1377 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1385 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1387 if (the_locking_inset) {
1388 the_locking_inset->getCursorPos(bv, x, y);
1391 x = cursor_.x() - top_x;
1396 void InsetTabular::toggleInsetCursor(BufferView * bv)
1399 if (isCursorVisible())
1400 bv->hideLockedInsetCursor();
1403 if (the_locking_inset) {
1404 the_locking_inset->toggleInsetCursor(bv);
1408 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1410 int const asc = lyxfont::maxAscent(font);
1411 int const desc = lyxfont::maxDescent(font);
1413 if (isCursorVisible())
1414 bv->hideLockedInsetCursor();
1416 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1417 toggleCursorVisible();
1421 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1425 if (!isCursorVisible()) {
1426 LyXFont font; // = GetFont(par, cursor.pos);
1428 int const asc = lyxfont::maxAscent(font);
1429 int const desc = lyxfont::maxDescent(font);
1430 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1432 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1433 setCursorVisible(true);
1438 void InsetTabular::hideInsetCursor(BufferView * bv)
1440 if (isCursorVisible()) {
1441 bv->hideLockedInsetCursor();
1442 setCursorVisible(false);
1447 void InsetTabular::fitInsetCursor(BufferView * bv) const
1449 if (the_locking_inset) {
1450 the_locking_inset->fitInsetCursor(bv);
1455 int const asc = lyxfont::maxAscent(font);
1456 int const desc = lyxfont::maxDescent(font);
1457 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1461 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1465 actcell = actrow = actcol = 0;
1466 int ly = tabular->GetDescentOfRow(actrow);
1468 // first search the right row
1469 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1470 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1471 tabular->GetAscentOfRow(actrow + 1) +
1472 tabular->GetAdditionalHeight(actrow + 1));
1474 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1476 actcell = tabular->GetCellNumber(actrow, actcol);
1478 // now search the right column
1479 int lx = tabular->GetWidthOfColumn(actcell) -
1480 tabular->GetAdditionalWidth(actcell);
1481 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1482 lx += tabular->GetWidthOfColumn(actcell + 1)
1483 + tabular->GetAdditionalWidth(actcell);
1485 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1490 int InsetTabular::getCellXPos(int cell) const
1494 for (; !tabular->IsFirstCellInRow(c); --c)
1496 int lx = tabular->GetWidthOfColumn(cell);
1497 for (; c < cell; ++c) {
1498 lx += tabular->GetWidthOfColumn(c);
1500 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1504 void InsetTabular::resetPos(BufferView * bv) const
1506 #warning This should be fixed in the right manner (20011128 Jug)
1507 // fast hack to fix infinite repaintings!
1512 actcol = tabular->column_of_cell(actcell);
1515 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1516 if (tabular->IsLastCellInRow(cell)) {
1517 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1518 tabular->GetAscentOfRow(actrow + 1) +
1519 tabular->GetAdditionalHeight(actrow + 1));
1523 if (!locked || nodraw()) {
1524 if (the_locking_inset)
1525 inset_y = cursor_.y();
1528 // we need this only from here on!!!
1529 in_reset_pos = true;
1530 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1531 int new_x = getCellXPos(actcell);
1532 int old_x = cursor_.x();
1535 // cursor.x(getCellXPos(actcell) + offset);
1536 if ((actcol < tabular->columns()-1) && scroll(false) &&
1537 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1540 updateLocal(bv, FULL, false);
1541 } else if (the_locking_inset &&
1542 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1544 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1545 if (xx > (bv->workWidth()-20)) {
1546 scroll(bv, -(xx - bv->workWidth() + 60));
1547 updateLocal(bv, FULL, false);
1548 } else if (xx < 20) {
1554 updateLocal(bv, FULL, false);
1556 } else if ((cursor_.x() - offset) > 20 &&
1557 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1558 > (bv->workWidth() - 20)) {
1559 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1560 updateLocal(bv, FULL, false);
1561 } else if ((cursor_.x() - offset) < 20) {
1562 scroll(bv, 20 - cursor_.x() + offset);
1563 updateLocal(bv, FULL, false);
1564 } else if (scroll(false) && top_x > 20 &&
1565 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1566 scroll(bv, old_x - cursor_.x());
1567 updateLocal(bv, FULL, false);
1569 if (the_locking_inset) {
1570 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1571 inset_y = cursor_.y();
1573 if ((!the_locking_inset ||
1574 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1575 actcell != oldcell) {
1576 InsetTabular * inset = const_cast<InsetTabular *>(this);
1577 bv->owner()->getDialogs()->updateTabular(inset);
1580 in_reset_pos = false;
1584 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1586 if (lock && !old_locking_inset) {
1587 if (activateCellInset(bv))
1590 bool moved = isRightToLeft(bv)
1591 ? movePrevCell(bv) : moveNextCell(bv);
1593 return FINISHED_RIGHT;
1594 if (lock && activateCellInset(bv))
1598 return DISPATCHED_NOUPDATE;
1602 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1604 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1607 if (lock) { // behind the inset
1608 if (activateCellInset(bv, 0, 0, 0, true))
1612 return DISPATCHED_NOUPDATE;
1616 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1618 int const ocell = actcell;
1619 actcell = tabular->GetCellAbove(actcell);
1620 if (actcell == ocell) // we moved out of the inset
1626 if (old_locking_inset) {
1627 old_locking_inset->getCursorPos(bv, x, y);
1628 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1630 if (activateCellInset(bv, x, 0))
1633 return DISPATCHED_NOUPDATE;
1637 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1639 int const ocell = actcell;
1640 actcell = tabular->GetCellBelow(actcell);
1641 if (actcell == ocell) // we moved out of the inset
1642 return FINISHED_DOWN;
1647 if (old_locking_inset) {
1648 old_locking_inset->getCursorPos(bv, x, y);
1649 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1651 if (activateCellInset(bv, x, 0))
1654 return DISPATCHED_NOUPDATE;
1658 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1660 if (isRightToLeft(bv)) {
1661 if (tabular->IsFirstCellInRow(actcell)) {
1662 int row = tabular->row_of_cell(actcell);
1663 if (row == tabular->rows() - 1)
1665 actcell = tabular->GetLastCellInRow(row);
1666 actcell = tabular->GetCellBelow(actcell);
1673 if (tabular->IsLastCell(actcell))
1678 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1679 isRightToLeftPar(bv->buffer()->params);
1680 activateCellInset(bv, 0, 0, 0, !rtl);
1687 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1689 if (isRightToLeft(bv)) {
1690 if (tabular->IsLastCellInRow(actcell)) {
1691 int row = tabular->row_of_cell(actcell);
1694 actcell = tabular->GetFirstCellInRow(row);
1695 actcell = tabular->GetCellAbove(actcell);
1697 if (tabular->IsLastCell(actcell))
1702 if (!actcell) // first cell
1707 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1708 isRightToLeftPar(bv->buffer()->params);
1709 activateCellInset(bv, 0, 0, 0, !rtl);
1716 bool InsetTabular::deletable() const
1722 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1726 setSelection(0, tabular->GetNumberOfCells() - 1);
1728 if (hasSelection()) {
1729 setUndo(bv, Undo::EDIT,
1730 bv->text->cursor.par(),
1731 bv->text->cursor.par()->next());
1732 bool frozen = undo_frozen;
1735 // apply the fontchange on the whole selection
1740 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1741 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1742 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1743 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1748 updateLocal(bv, INIT, true);
1750 if (the_locking_inset)
1751 the_locking_inset->setFont(bv, font, tall);
1755 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1757 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1760 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1761 string const tmp = tabularFeature[i].feature;
1763 if (tmp == what.substr(0, tmp.length())) {
1764 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1765 //tabularFeatures[i].feature.length())) {
1766 action = tabularFeature[i].action;
1770 if (action == LyXTabular::LAST_ACTION)
1774 frontStrip(what.substr(tabularFeature[i].feature.length()));
1775 tabularFeatures(bv, action, val);
1779 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1780 string const & special, bool & flag)
1782 if (special == "dl_above") {
1785 } else if (special == "dl_below") {
1786 ltt.bottomDL = flag;
1788 } else if (special == "empty") {
1798 void InsetTabular::tabularFeatures(BufferView * bv,
1799 LyXTabular::Feature feature,
1800 string const & value)
1806 bool setLines = false;
1807 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1808 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1811 case LyXTabular::M_ALIGN_LEFT:
1812 case LyXTabular::ALIGN_LEFT:
1813 setAlign = LYX_ALIGN_LEFT;
1815 case LyXTabular::M_ALIGN_RIGHT:
1816 case LyXTabular::ALIGN_RIGHT:
1817 setAlign = LYX_ALIGN_RIGHT;
1819 case LyXTabular::M_ALIGN_CENTER:
1820 case LyXTabular::ALIGN_CENTER:
1821 setAlign = LYX_ALIGN_CENTER;
1823 case LyXTabular::M_VALIGN_TOP:
1824 case LyXTabular::VALIGN_TOP:
1825 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1827 case LyXTabular::M_VALIGN_BOTTOM:
1828 case LyXTabular::VALIGN_BOTTOM:
1829 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1831 case LyXTabular::M_VALIGN_CENTER:
1832 case LyXTabular::VALIGN_CENTER:
1833 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1838 if (hasSelection()) {
1839 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1841 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1842 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1844 setUndo(bv, Undo::FINISH,
1845 bv->text->cursor.par(),
1846 bv->text->cursor.par()->next());
1848 int row = tabular->row_of_cell(actcell);
1849 int column = tabular->column_of_cell(actcell);
1851 LyXTabular::ltType ltt;
1854 case LyXTabular::SET_PWIDTH:
1856 LyXLength const vallen(value);
1857 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1859 bool const update = (tmplen != vallen);
1860 tabular->SetColumnPWidth(actcell, vallen);
1863 for (int i = 0; i < tabular->rows(); ++i) {
1864 cell = tabular->GetCellNumber(i,column);
1865 tabular->GetCellInset(cell)->resizeLyXText(bv);
1867 updateLocal(bv, INIT, true);
1871 case LyXTabular::SET_MPWIDTH:
1873 LyXLength const vallen(value);
1874 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1876 bool const update = (tmplen != vallen);
1877 tabular->SetMColumnPWidth(actcell, vallen);
1879 for (int i = 0; i < tabular->rows(); ++i) {
1880 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1883 updateLocal(bv, INIT, true);
1887 case LyXTabular::SET_SPECIAL_COLUMN:
1888 case LyXTabular::SET_SPECIAL_MULTI:
1889 tabular->SetAlignSpecial(actcell,value,feature);
1890 updateLocal(bv, FULL, true);
1892 case LyXTabular::APPEND_ROW:
1893 // append the row into the tabular
1894 unlockInsetInInset(bv, the_locking_inset);
1895 tabular->AppendRow(bv->buffer()->params, actcell);
1896 updateLocal(bv, INIT, true);
1898 case LyXTabular::APPEND_COLUMN:
1899 // append the column into the tabular
1900 unlockInsetInInset(bv, the_locking_inset);
1901 tabular->AppendColumn(bv->buffer()->params, actcell);
1902 actcell = tabular->GetCellNumber(row, column);
1903 updateLocal(bv, INIT, true);
1905 case LyXTabular::DELETE_ROW:
1906 unlockInsetInInset(bv, the_locking_inset);
1907 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1908 tabular->DeleteRow(sel_row_start);
1910 if (sel_row_start >= tabular->rows())
1912 actcell = tabular->GetCellNumber(sel_row_start, column);
1914 updateLocal(bv, INIT, true);
1916 case LyXTabular::DELETE_COLUMN:
1917 unlockInsetInInset(bv, the_locking_inset);
1918 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1919 tabular->DeleteColumn(sel_col_start);
1921 if (sel_col_start >= tabular->columns())
1923 actcell = tabular->GetCellNumber(row, sel_col_start);
1925 updateLocal(bv, INIT, true);
1927 case LyXTabular::M_TOGGLE_LINE_TOP:
1929 case LyXTabular::TOGGLE_LINE_TOP:
1931 bool lineSet = !tabular->TopLine(actcell, flag);
1932 for (int i = sel_row_start; i <= sel_row_end; ++i)
1933 for (int j = sel_col_start; j <= sel_col_end; ++j)
1934 tabular->SetTopLine(
1935 tabular->GetCellNumber(i, j),
1937 updateLocal(bv, INIT, true);
1941 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1943 case LyXTabular::TOGGLE_LINE_BOTTOM:
1945 bool lineSet = !tabular->BottomLine(actcell, flag);
1946 for (int i = sel_row_start; i <= sel_row_end; ++i)
1947 for (int j = sel_col_start; j <= sel_col_end; ++j)
1948 tabular->SetBottomLine(
1949 tabular->GetCellNumber(i, j),
1952 updateLocal(bv, INIT, true);
1956 case LyXTabular::M_TOGGLE_LINE_LEFT:
1958 case LyXTabular::TOGGLE_LINE_LEFT:
1960 bool lineSet = !tabular->LeftLine(actcell, flag);
1961 for (int i = sel_row_start; i <= sel_row_end; ++i)
1962 for (int j = sel_col_start; j <= sel_col_end; ++j)
1963 tabular->SetLeftLine(
1964 tabular->GetCellNumber(i,j),
1967 updateLocal(bv, INIT, true);
1971 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1973 case LyXTabular::TOGGLE_LINE_RIGHT:
1975 bool lineSet = !tabular->RightLine(actcell, flag);
1976 for (int i = sel_row_start; i <= sel_row_end; ++i)
1977 for (int j = sel_col_start; j <= sel_col_end; ++j)
1978 tabular->SetRightLine(
1979 tabular->GetCellNumber(i,j),
1982 updateLocal(bv, INIT, true);
1986 case LyXTabular::M_ALIGN_LEFT:
1987 case LyXTabular::M_ALIGN_RIGHT:
1988 case LyXTabular::M_ALIGN_CENTER:
1990 case LyXTabular::ALIGN_LEFT:
1991 case LyXTabular::ALIGN_RIGHT:
1992 case LyXTabular::ALIGN_CENTER:
1993 for (int i = sel_row_start; i <= sel_row_end; ++i)
1994 for (int j = sel_col_start; j <= sel_col_end; ++j)
1995 tabular->SetAlignment(
1996 tabular->GetCellNumber(i, j),
1999 updateLocal(bv, INIT, true);
2001 case LyXTabular::M_VALIGN_TOP:
2002 case LyXTabular::M_VALIGN_BOTTOM:
2003 case LyXTabular::M_VALIGN_CENTER:
2005 case LyXTabular::VALIGN_TOP:
2006 case LyXTabular::VALIGN_BOTTOM:
2007 case LyXTabular::VALIGN_CENTER:
2008 for (int i = sel_row_start; i <= sel_row_end; ++i)
2009 for (int j = sel_col_start; j <= sel_col_end; ++j)
2010 tabular->SetVAlignment(
2011 tabular->GetCellNumber(i, j),
2013 updateLocal(bv, INIT, true);
2015 case LyXTabular::MULTICOLUMN:
2017 if (sel_row_start != sel_row_end) {
2018 Alert::alert(_("Impossible Operation!"),
2019 _("Multicolumns can only be horizontally."),
2023 // just multicol for one Single Cell
2024 if (!hasSelection()) {
2025 // check wether we are completly in a multicol
2026 if (tabular->IsMultiColumn(actcell)) {
2027 tabular->UnsetMultiColumn(actcell);
2028 updateLocal(bv, INIT, true);
2030 tabular->SetMultiColumn(actcell, 1);
2031 updateLocal(bv, CELL, true);
2035 // we have a selection so this means we just add all this
2036 // cells to form a multicolumn cell
2040 if (sel_cell_start > sel_cell_end) {
2041 s_start = sel_cell_end;
2042 s_end = sel_cell_start;
2044 s_start = sel_cell_start;
2045 s_end = sel_cell_end;
2047 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
2050 updateLocal(bv, INIT, true);
2053 case LyXTabular::SET_ALL_LINES:
2055 case LyXTabular::UNSET_ALL_LINES:
2056 for (int i = sel_row_start; i <= sel_row_end; ++i)
2057 for (int j = sel_col_start; j <= sel_col_end; ++j)
2058 tabular->SetAllLines(
2059 tabular->GetCellNumber(i,j), setLines);
2060 updateLocal(bv, INIT, true);
2062 case LyXTabular::SET_LONGTABULAR:
2063 tabular->SetLongTabular(true);
2064 updateLocal(bv, INIT, true); // because this toggles displayed
2066 case LyXTabular::UNSET_LONGTABULAR:
2067 tabular->SetLongTabular(false);
2068 updateLocal(bv, INIT, true); // because this toggles displayed
2070 case LyXTabular::SET_ROTATE_TABULAR:
2071 tabular->SetRotateTabular(true);
2073 case LyXTabular::UNSET_ROTATE_TABULAR:
2074 tabular->SetRotateTabular(false);
2076 case LyXTabular::SET_ROTATE_CELL:
2077 for (int i = sel_row_start; i <= sel_row_end; ++i)
2078 for (int j = sel_col_start; j<=sel_col_end; ++j)
2079 tabular->SetRotateCell(
2080 tabular->GetCellNumber(i, j),
2083 case LyXTabular::UNSET_ROTATE_CELL:
2084 for (int i = sel_row_start; i <= sel_row_end; ++i)
2085 for (int j = sel_col_start; j <= sel_col_end; ++j)
2086 tabular->SetRotateCell(
2087 tabular->GetCellNumber(i, j), false);
2089 case LyXTabular::SET_USEBOX:
2091 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2092 if (val == tabular->GetUsebox(actcell))
2093 val = LyXTabular::BOX_NONE;
2094 for (int i = sel_row_start; i <= sel_row_end; ++i)
2095 for (int j = sel_col_start; j <= sel_col_end; ++j)
2097 tabular->GetCellNumber(i, j), val);
2100 case LyXTabular::UNSET_LTFIRSTHEAD:
2102 case LyXTabular::SET_LTFIRSTHEAD:
2103 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2104 checkLongtableSpecial(ltt, value, flag);
2105 tabular->SetLTHead(row, flag, ltt, true);
2107 case LyXTabular::UNSET_LTHEAD:
2109 case LyXTabular::SET_LTHEAD:
2110 (void)tabular->GetRowOfLTHead(row, ltt);
2111 checkLongtableSpecial(ltt, value, flag);
2112 tabular->SetLTHead(row, flag, ltt, false);
2114 case LyXTabular::UNSET_LTFOOT:
2116 case LyXTabular::SET_LTFOOT:
2117 (void)tabular->GetRowOfLTFoot(row, ltt);
2118 checkLongtableSpecial(ltt, value, flag);
2119 tabular->SetLTFoot(row, flag, ltt, false);
2121 case LyXTabular::UNSET_LTLASTFOOT:
2123 case LyXTabular::SET_LTLASTFOOT:
2124 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2125 checkLongtableSpecial(ltt, value, flag);
2126 tabular->SetLTFoot(row, flag, ltt, true);
2128 case LyXTabular::SET_LTNEWPAGE:
2130 bool what = !tabular->GetLTNewPage(row);
2131 tabular->SetLTNewPage(row, what);
2134 // dummy stuff just to avoid warnings
2135 case LyXTabular::LAST_ACTION:
2141 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2144 UpdatableInset * inset =
2145 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2146 LyXFont font(LyXFont::ALL_SANE);
2148 x = inset->x() + inset->width(bv, font);
2149 y = inset->descent(bv, font);
2151 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2152 //inset_y = cursor.y();
2153 inset->edit(bv, x, y, button);
2154 if (!the_locking_inset)
2156 updateLocal(bv, CELL, false);
2157 return (the_locking_inset != 0);
2161 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2164 inset_x = cursor_.x()
2165 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2166 inset_y = cursor_.y();
2167 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2171 bool InsetTabular::insetHit(BufferView *, int x, int) const
2174 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2178 // This returns paperWidth() if the cell-width is unlimited or the width
2179 // in pixels if we have a pwidth for this cell.
2180 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2182 LyXLength const len = tabular->GetPWidth(cell);
2186 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2190 int InsetTabular::getMaxWidth(BufferView * bv,
2191 UpdatableInset const * inset) const
2193 int cell = tabular->GetCellFromInset(inset, actcell);
2196 lyxerr << "Own inset not found, shouldn't really happen!"
2201 int w = getMaxWidthOfCell(bv, cell);
2203 // because the inset then subtracts it's top_x and owner->x()
2204 w += (inset->x() - top_x);
2211 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2213 resizeLyXText(bv, recursive);
2217 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2220 for(int i = 0; i < tabular->rows(); ++i) {
2221 for(int j = 0; j < tabular->columns(); ++j) {
2222 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2230 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2231 bool const recursive) const
2233 if (the_locking_inset)
2234 return the_locking_inset->getLyXText(bv, recursive);
2236 // if we're locked lock the actual insettext and return it's LyXText!!!
2238 UpdatableInset * inset =
2239 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2240 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2241 return the_locking_inset->getLyXText(bv, recursive);
2244 return Inset::getLyXText(bv, recursive);
2248 bool InsetTabular::showInsetDialog(BufferView * bv) const
2250 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2251 bv->owner()->getDialogs()
2252 ->showTabular(const_cast<InsetTabular *>(this));
2257 void InsetTabular::openLayoutDialog(BufferView * bv) const
2259 if (the_locking_inset) {
2260 InsetTabular * i = static_cast<InsetTabular *>
2261 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2263 i->openLayoutDialog(bv);
2267 bv->owner()->getDialogs()->showTabular(
2268 const_cast<InsetTabular *>(this));
2273 // function returns an object as defined in func_status.h:
2274 // states OK, Unknown, Disabled, On, Off.
2276 FuncStatus InsetTabular::getStatus(string const & what) const
2278 int action = LyXTabular::LAST_ACTION;
2282 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2283 string const tmp = tabularFeature[i].feature;
2284 if (tmp == what.substr(0, tmp.length())) {
2285 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2286 // tabularFeatures[i].feature.length())) {
2287 action = tabularFeature[i].action;
2291 if (action == LyXTabular::LAST_ACTION) {
2293 return status.unknown(true);
2296 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2301 LyXTabular::ltType dummyltt;
2304 if (hasSelection()) {
2305 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2307 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2311 case LyXTabular::SET_PWIDTH:
2312 case LyXTabular::SET_MPWIDTH:
2313 case LyXTabular::SET_SPECIAL_COLUMN:
2314 case LyXTabular::SET_SPECIAL_MULTI:
2315 return status.disabled(true);
2317 case LyXTabular::APPEND_ROW:
2318 case LyXTabular::APPEND_COLUMN:
2319 case LyXTabular::DELETE_ROW:
2320 case LyXTabular::DELETE_COLUMN:
2321 case LyXTabular::SET_ALL_LINES:
2322 case LyXTabular::UNSET_ALL_LINES:
2323 return status.clear();
2325 case LyXTabular::MULTICOLUMN:
2326 status.setOnOff(tabular->IsMultiColumn(actcell));
2328 case LyXTabular::M_TOGGLE_LINE_TOP:
2330 case LyXTabular::TOGGLE_LINE_TOP:
2331 status.setOnOff(tabular->TopLine(actcell, flag));
2333 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2335 case LyXTabular::TOGGLE_LINE_BOTTOM:
2336 status.setOnOff(tabular->BottomLine(actcell, flag));
2338 case LyXTabular::M_TOGGLE_LINE_LEFT:
2340 case LyXTabular::TOGGLE_LINE_LEFT:
2341 status.setOnOff(tabular->LeftLine(actcell, flag));
2343 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2345 case LyXTabular::TOGGLE_LINE_RIGHT:
2346 status.setOnOff(tabular->RightLine(actcell, flag));
2348 case LyXTabular::M_ALIGN_LEFT:
2350 case LyXTabular::ALIGN_LEFT:
2351 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2353 case LyXTabular::M_ALIGN_RIGHT:
2355 case LyXTabular::ALIGN_RIGHT:
2356 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2358 case LyXTabular::M_ALIGN_CENTER:
2360 case LyXTabular::ALIGN_CENTER:
2361 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2363 case LyXTabular::M_VALIGN_TOP:
2365 case LyXTabular::VALIGN_TOP:
2366 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2368 case LyXTabular::M_VALIGN_BOTTOM:
2370 case LyXTabular::VALIGN_BOTTOM:
2371 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2373 case LyXTabular::M_VALIGN_CENTER:
2375 case LyXTabular::VALIGN_CENTER:
2376 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2378 case LyXTabular::SET_LONGTABULAR:
2379 status.setOnOff(tabular->IsLongTabular());
2381 case LyXTabular::UNSET_LONGTABULAR:
2382 status.setOnOff(!tabular->IsLongTabular());
2384 case LyXTabular::SET_ROTATE_TABULAR:
2385 status.setOnOff(tabular->GetRotateTabular());
2387 case LyXTabular::UNSET_ROTATE_TABULAR:
2388 status.setOnOff(!tabular->GetRotateTabular());
2390 case LyXTabular::SET_ROTATE_CELL:
2391 status.setOnOff(tabular->GetRotateCell(actcell));
2393 case LyXTabular::UNSET_ROTATE_CELL:
2394 status.setOnOff(!tabular->GetRotateCell(actcell));
2396 case LyXTabular::SET_USEBOX:
2397 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2399 case LyXTabular::SET_LTFIRSTHEAD:
2400 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2402 case LyXTabular::SET_LTHEAD:
2403 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2405 case LyXTabular::SET_LTFOOT:
2406 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2408 case LyXTabular::SET_LTLASTFOOT:
2409 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2411 case LyXTabular::SET_LTNEWPAGE:
2412 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2416 status.disabled(true);
2423 vector<string> const InsetTabular::getLabelList() const
2425 return tabular->getLabelList();
2429 bool InsetTabular::copySelection(BufferView * bv)
2431 if (!hasSelection())
2434 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2435 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2436 if (sel_col_start > sel_col_end) {
2437 sel_col_start = sel_col_end;
2438 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2440 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2442 int const columns = sel_col_end - sel_col_start + 1;
2444 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2445 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2446 if (sel_row_start > sel_row_end) {
2447 swap(sel_row_start, sel_row_end);
2449 int const rows = sel_row_end - sel_row_start + 1;
2451 delete paste_tabular;
2452 paste_tabular = new LyXTabular(bv->buffer()->params,
2453 this, *tabular); // rows, columns);
2454 for (int i = 0; i < sel_row_start; ++i)
2455 paste_tabular->DeleteRow(0);
2456 while (paste_tabular->rows() > rows)
2457 paste_tabular->DeleteRow(rows);
2458 paste_tabular->SetTopLine(0, true, true);
2459 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2461 for (int i = 0; i < sel_col_start; ++i)
2462 paste_tabular->DeleteColumn(0);
2463 while (paste_tabular->columns() > columns)
2464 paste_tabular->DeleteColumn(columns);
2465 paste_tabular->SetLeftLine(0, true, true);
2466 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2470 paste_tabular->ascii(bv->buffer(), sstr,
2471 (int)parOwner()->params().depth(), true, '\t');
2472 bv->stuffClipboard(sstr.str().c_str());
2477 bool InsetTabular::pasteSelection(BufferView * bv)
2482 for (int r1 = 0, r2 = actrow;
2483 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2485 for(int c1 = 0, c2 = actcol;
2486 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2488 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2489 tabular->IsPartOfMultiColumn(r2,c2))
2491 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2495 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2499 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2500 int const n2 = tabular->GetCellNumber(r2, c2);
2501 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2502 tabular->GetCellInset(n2)->setOwner(this);
2503 tabular->GetCellInset(n2)->deleteLyXText(bv);
2510 bool InsetTabular::cutSelection()
2512 if (!hasSelection())
2515 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2516 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2517 if (sel_col_start > sel_col_end) {
2518 sel_col_start = sel_col_end;
2519 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2521 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2523 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2524 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2525 if (sel_row_start > sel_row_end) {
2526 swap(sel_row_start, sel_row_end);
2528 if (sel_cell_start > sel_cell_end) {
2529 swap(sel_cell_start, sel_cell_end);
2531 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2532 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2533 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2540 bool InsetTabular::isRightToLeft(BufferView * bv)
2542 return bv->getParentLanguage(this)->RightToLeft();
2546 bool InsetTabular::nodraw() const
2548 if (!UpdatableInset::nodraw() && the_locking_inset)
2549 return the_locking_inset->nodraw();
2550 return UpdatableInset::nodraw();
2554 int InsetTabular::scroll(bool recursive) const
2556 int sx = UpdatableInset::scroll(false);
2558 if (recursive && the_locking_inset)
2559 sx += the_locking_inset->scroll(recursive);
2565 bool InsetTabular::doClearArea() const
2567 return !locked || (need_update & (FULL|INIT));
2571 void InsetTabular::getSelection(int & srow, int & erow,
2572 int & scol, int & ecol) const
2574 int const start = hasSelection() ? sel_cell_start : actcell;
2575 int const end = hasSelection() ? sel_cell_end : actcell;
2577 srow = tabular->row_of_cell(start);
2578 erow = tabular->row_of_cell(end);
2583 scol = tabular->column_of_cell(start);
2584 ecol = tabular->column_of_cell(end);
2588 ecol = tabular->right_column_of_cell(end);
2593 Paragraph * InsetTabular::getParFromID(int id) const
2596 for(int i = 0; i < tabular->rows(); ++i) {
2597 for(int j = 0; j < tabular->columns(); ++j) {
2598 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2606 Paragraph * InsetTabular::firstParagraph() const
2608 if (the_locking_inset)
2609 return the_locking_inset->firstParagraph();
2614 Paragraph * InsetTabular::getFirstParagraph(int i) const
2616 return (i < tabular->GetNumberOfCells())
2617 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2622 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2624 if (the_locking_inset)
2625 return the_locking_inset->cursor(bv);
2626 return Inset::cursor(bv);
2630 Inset * InsetTabular::getInsetFromID(int id_arg) const
2633 return const_cast<InsetTabular *>(this);
2636 for(int i = 0; i < tabular->rows(); ++i) {
2637 for(int j = 0; j < tabular->columns(); ++j) {
2638 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2647 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2650 if (the_locking_inset) {
2651 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2656 if (tabular->IsLastCell(actcell)) {
2657 bv->unlockInset(const_cast<InsetTabular *>(this));
2663 // otherwise we have to lock the next inset and ask for it's selecttion
2664 UpdatableInset * inset =
2665 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2666 inset->edit(bv, 0, 0, 0);
2667 string const str(selectNextWordInt(bv, value));
2675 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2677 // when entering this function the inset should be ALWAYS locked!
2678 lyx::Assert(the_locking_inset);
2680 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2684 if (tabular->IsLastCell(actcell)) {
2685 bv->unlockInset(const_cast<InsetTabular *>(this));
2689 // otherwise we have to lock the next inset and ask for it's selecttion
2690 UpdatableInset * inset =
2691 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2693 return selectNextWordInt(bv, value);
2697 void InsetTabular::selectSelectedWord(BufferView * bv)
2699 if (the_locking_inset) {
2700 the_locking_inset->selectSelectedWord(bv);
2707 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2709 if (the_locking_inset) {
2710 the_locking_inset->toggleSelection(bv, kill_selection);
2715 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2719 if (the_locking_inset) {
2720 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2722 updateLocal(bv, CELL, false);
2725 if (tabular->IsLastCell(actcell)) {
2727 bv->unlockInset(const_cast<InsetTabular *>(this));
2732 // otherwise we have to lock the next inset and search there
2733 UpdatableInset * inset =
2734 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2736 bool const ret = searchForward(bv, str, cs, mw);
2738 updateLocal(bv, CELL, false);
2743 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2747 if (the_locking_inset) {
2748 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2750 updateLocal(bv, CELL, false);
2753 if (!actcell) { // we are already in the first cell
2755 bv->unlockInset(const_cast<InsetTabular *>(this));
2760 // otherwise we have to lock the next inset and search there
2761 UpdatableInset * inset =
2762 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2763 inset->edit(bv, false);
2764 bool const ret = searchBackward(bv, str, cs, mw);
2766 updateLocal(bv, CELL, false);
2771 bool InsetTabular::insetAllowed(Inset::Code code) const
2773 if (the_locking_inset)
2774 return the_locking_inset->insetAllowed(code);
2779 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2781 const int cell = tabular->GetCellFromInset(in, actcell);
2784 return tabular->GetPWidth(cell).zero();
2786 // well we didn't obviously find it so maybe our owner knows more
2788 return owner()->forceDefaultParagraphs(in);
2789 // if we're here there is really something strange going on!!!
2793 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2796 if (buf.find('\t') == string::npos)
2802 string::size_type len = buf.length();
2803 string::size_type p = 0;
2806 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2815 maxCols = max(cols, maxCols);
2821 maxCols = max(cols, maxCols);
2822 LyXTabular * loctab;
2827 delete paste_tabular;
2828 paste_tabular = new LyXTabular(bv->buffer()->params,
2829 this, rows, maxCols);
2830 loctab = paste_tabular;
2833 loctab = tabular.get();
2838 string::size_type op = 0;
2839 int cells = loctab->GetNumberOfCells();
2842 rows = loctab->rows();
2843 int const columns = loctab->columns();
2844 while ((cell < cells) && (p < len) && (row < rows) &&
2845 (p = buf.find_first_of("\t\n", p)) != string::npos)
2851 // we can only set this if we are not too far right
2852 if (cols < columns) {
2853 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2859 // we can only set this if we are not too far right
2861 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2865 cell = loctab->GetCellNumber(row, cols);
2871 // check for the last cell if there is no trailing '\n'
2872 if ((cell < cells) && (op < len))
2873 loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));