3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "insettabular.h"
18 #include "insettext.h"
21 #include "BufferView.h"
22 #include "commandtags.h"
24 #include "funcrequest.h"
27 #include "LaTeXFeatures.h"
30 #include "lyxlength.h"
33 #include "ParagraphParameters.h"
34 #include "undo_funcs.h"
35 #include "WordLangTuple.h"
37 #include "frontends/Alert.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/font_metrics.h"
40 #include "frontends/LyXView.h"
41 #include "frontends/Painter.h"
43 #include "support/LAssert.h"
44 #include "support/lstrings.h"
63 int const ADD_TO_HEIGHT = 2;
64 int const ADD_TO_TABULAR_WIDTH = 2;
67 LyXTabular * paste_tabular = 0;
70 struct TabularFeature {
71 LyXTabular::Feature action;
76 TabularFeature tabularFeature[] =
78 { LyXTabular::APPEND_ROW, "append-row" },
79 { LyXTabular::APPEND_COLUMN, "append-column" },
80 { LyXTabular::DELETE_ROW, "delete-row" },
81 { LyXTabular::DELETE_COLUMN, "delete-column" },
82 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
83 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
84 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
85 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
86 { LyXTabular::ALIGN_LEFT, "align-left" },
87 { LyXTabular::ALIGN_RIGHT, "align-right" },
88 { LyXTabular::ALIGN_CENTER, "align-center" },
89 { LyXTabular::ALIGN_BLOCK, "align-block" },
90 { LyXTabular::VALIGN_TOP, "valign-top" },
91 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
92 { LyXTabular::VALIGN_CENTER, "valign-center" },
93 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
94 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
95 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
96 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
97 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
98 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
99 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
100 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
101 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
102 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
103 { LyXTabular::MULTICOLUMN, "multicolumn" },
104 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
105 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
106 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
107 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
108 { LyXTabular::SET_PWIDTH, "set-pwidth" },
109 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
110 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
111 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
112 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
113 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
114 { LyXTabular::SET_USEBOX, "set-usebox" },
115 { LyXTabular::SET_LTHEAD, "set-lthead" },
116 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
117 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
118 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
119 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
120 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
121 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
122 { LyXTabular::LAST_ACTION, "" }
128 bool InsetTabular::hasPasteBuffer() const
130 return (paste_tabular != 0);
134 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
141 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
142 // for now make it always display as display() inset
144 the_locking_inset = 0;
145 old_locking_inset = 0;
148 actrow = actcell = 0;
158 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
160 : UpdatableInset(tab, same_id), buffer(&buf)
162 tabular.reset(new LyXTabular(buf.params,
163 this, *(tab.tabular), same_id));
164 the_locking_inset = 0;
165 old_locking_inset = 0;
168 actrow = actcell = 0;
178 InsetTabular::~InsetTabular()
184 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
186 return new InsetTabular(*this, buf, same_id);
190 void InsetTabular::write(Buffer const * buf, ostream & os) const
192 os << " Tabular" << endl;
193 tabular->Write(buf, os);
197 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
199 bool const old_format = (lex.getString() == "\\LyXTable");
201 tabular.reset(new LyXTabular(buf, this, lex));
209 string token = lex.getString();
210 while (lex.isOK() && (token != "\\end_inset")) {
212 token = lex.getString();
214 if (token != "\\end_inset") {
215 lex.printError("Missing \\end_inset at this point. "
221 int InsetTabular::ascent(BufferView *, LyXFont const &) const
223 return tabular->GetAscentOfRow(0);
227 int InsetTabular::descent(BufferView *, LyXFont const &) const
229 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
233 int InsetTabular::width(BufferView *, LyXFont const &) const
235 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
239 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
240 float & x, bool cleared) const
248 if (need_update == INIT) {
249 if (calculate_dimensions_of_cells(bv, font, true))
250 bv->text->status = LyXText::CHANGED_IN_DRAW;
255 Painter & pain = bv->painter();
261 UpdatableInset::draw(bv, font, baseline, x, cleared);
264 x += static_cast<float>(scroll());
266 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
267 (top_x != int(x)) || (top_baseline != baseline)))
269 int h = ascent(bv, font) + descent(bv, font);
270 int const tx = display() || !owner() ? 0 : top_x;
271 int w = tx ? width(bv, font) : pain.paperWidth();
272 int ty = baseline - ascent(bv, font);
276 if ((ty + h) > pain.paperHeight())
277 h = pain.paperHeight();
278 if ((top_x + w) > pain.paperWidth())
279 w = pain.paperWidth();
280 pain.fillRectangle(tx, ty, w, h, backgroundColor());
286 top_baseline = baseline;
287 x += ADD_TO_TABULAR_WIDTH;
291 first_visible_cell = -1;
292 for (i = 0; i < tabular->rows(); ++i) {
294 cell = tabular->GetCellNumber(i, 0);
295 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
296 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
298 baseline += tabular->GetDescentOfRow(i) +
299 tabular->GetAscentOfRow(i + 1) +
300 tabular->GetAdditionalHeight(i + 1);
303 for (j = 0; j < tabular->columns(); ++j) {
304 if (nx > bv->workWidth())
306 if (tabular->IsPartOfMultiColumn(i, j))
308 cx = nx + tabular->GetBeginningOfTextInCell(cell);
309 if (first_visible_cell < 0)
310 first_visible_cell = cell;
311 if (hasSelection()) {
312 drawCellSelection(pain, nx, baseline, i, j, cell);
315 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
316 drawCellLines(pain, nx, baseline, i, cell);
317 nx += tabular->GetWidthOfColumn(cell);
320 baseline += tabular->GetDescentOfRow(i) +
321 tabular->GetAscentOfRow(i + 1) +
322 tabular->GetAdditionalHeight(i + 1);
324 } else if (need_update == CELL) {
327 if (the_locking_inset &&
328 tabular->GetCellInset(actcell) != the_locking_inset)
330 Inset * inset = tabular->GetCellInset(cell);
332 inset != the_locking_inset && i < tabular->rows();
336 inset != the_locking_inset && j < tabular->columns();
339 if (tabular->IsPartOfMultiColumn(i, j))
341 nx += tabular->GetWidthOfColumn(cell);
343 inset = tabular->GetCellInset(cell);
345 if (tabular->row_of_cell(cell) > i) {
347 baseline += tabular->GetDescentOfRow(i) +
348 tabular->GetAscentOfRow(i + 1) +
349 tabular->GetAdditionalHeight(i + 1);
353 // compute baseline for actual row
354 for (i = 0; i < actrow; ++i) {
355 baseline += tabular->GetDescentOfRow(i) +
356 tabular->GetAscentOfRow(i + 1) +
357 tabular->GetAdditionalHeight(i + 1);
359 // now compute the right x position
360 cell = tabular->GetCellNumber(actrow, 0);
361 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
362 if (tabular->IsPartOfMultiColumn(actrow, j))
364 nx += tabular->GetWidthOfColumn(cell);
368 i = tabular->row_of_cell(cell);
369 if (the_locking_inset != tabular->GetCellInset(cell)) {
370 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
373 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
375 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
377 // Here we use rectangular backgroundColor patches to clean up
378 // within a cell around the cell's red inset box. As follows:
380 // +--------------------+
381 // | C | The rectangles are A, B and C
382 // | A |------------| B | below, origin top left (tx, ty),
383 // | | inset box | | dimensions w(idth), h(eight).
384 // +---+------------+---+ x grows rightward, y downward
386 // +--------------------+
389 // clear only if we didn't have a change
390 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
392 // clear before the inset
395 ty = baseline - tabular->GetAscentOfRow(i) + 1;
396 w = int(cx - nx - 1);
397 h = tabular->GetAscentOfRow(i) +
398 tabular->GetDescentOfRow(i) - 1;
399 pain.fillRectangle(tx, ty, w, h, backgroundColor());
400 // clear behind the inset
401 tx = int(cx + the_locking_inset->width(bv,font) + 1);
402 ty = baseline - tabular->GetAscentOfRow(i) + 1;
403 w = tabular->GetWidthOfColumn(cell) -
404 tabular->GetBeginningOfTextInCell(cell) -
405 the_locking_inset->width(bv,font) -
406 tabular->GetAdditionalWidth(cell) - 1;
407 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
408 pain.fillRectangle(tx, ty, w, h, backgroundColor());
409 // clear below the inset
411 ty = baseline + the_locking_inset->descent(bv, font) + 1;
412 w = tabular->GetWidthOfColumn(cell) -
413 tabular->GetAdditionalWidth(cell) - 1;
414 h = tabular->GetDescentOfRow(i) -
415 the_locking_inset->descent(bv, font) - 1;
416 pain.fillRectangle(tx, ty, w, h, backgroundColor());
417 // clear above the inset
419 ty = baseline - tabular->GetAscentOfRow(i) + 1;
420 w = tabular->GetWidthOfColumn(cell) -
421 tabular->GetAdditionalWidth(cell) - 1;
422 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
423 pain.fillRectangle(tx, ty, w, h, backgroundColor());
428 x -= ADD_TO_TABULAR_WIDTH;
429 x += width(bv, font);
430 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
432 for(Inset * inset = owner(); inset; ++i)
433 inset = inset->owner();
434 if (calculate_dimensions_of_cells(bv, font, false))
442 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
443 int row, int cell) const
445 int x2 = x + tabular->GetWidthOfColumn(cell);
448 if (!tabular->TopAlreadyDrawed(cell)) {
449 on_off = !tabular->TopLine(cell);
450 pain.line(x, baseline - tabular->GetAscentOfRow(row),
451 x2, baseline - tabular->GetAscentOfRow(row),
452 on_off ? LColor::tabularonoffline : LColor::tabularline,
453 on_off ? Painter::line_onoffdash : Painter::line_solid);
455 on_off = !tabular->BottomLine(cell);
456 pain.line(x, baseline + tabular->GetDescentOfRow(row),
457 x2, baseline + tabular->GetDescentOfRow(row),
458 on_off ? LColor::tabularonoffline : LColor::tabularline,
459 on_off ? Painter::line_onoffdash : Painter::line_solid);
460 if (!tabular->LeftAlreadyDrawed(cell)) {
461 on_off = !tabular->LeftLine(cell);
462 pain.line(x, baseline - tabular->GetAscentOfRow(row),
463 x, baseline + tabular->GetDescentOfRow(row),
464 on_off ? LColor::tabularonoffline : LColor::tabularline,
465 on_off ? Painter::line_onoffdash : Painter::line_solid);
467 on_off = !tabular->RightLine(cell);
468 pain.line(x2 - tabular->GetAdditionalWidth(cell),
469 baseline - tabular->GetAscentOfRow(row),
470 x2 - tabular->GetAdditionalWidth(cell),
471 baseline + tabular->GetDescentOfRow(row),
472 on_off ? LColor::tabularonoffline : LColor::tabularline,
473 on_off ? Painter::line_onoffdash : Painter::line_solid);
477 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
478 int row, int column, int cell) const
480 lyx::Assert(hasSelection());
481 int cs = tabular->column_of_cell(sel_cell_start);
482 int ce = tabular->column_of_cell(sel_cell_end);
485 cs = tabular->column_of_cell(sel_cell_end);
487 ce = tabular->right_column_of_cell(sel_cell_end);
490 int rs = tabular->row_of_cell(sel_cell_start);
491 int re = tabular->row_of_cell(sel_cell_end);
495 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
496 int w = tabular->GetWidthOfColumn(cell);
497 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
498 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
499 w, h, LColor::selection);
504 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
510 owner()->update(bv, font, true);
517 if (calculate_dimensions_of_cells(bv, font, true))
520 owner()->update(bv, font, true);
524 if (the_locking_inset)
525 the_locking_inset->update(bv, font, reinit);
526 if (need_update < FULL &&
527 bv->text->status() == LyXText::NEED_MORE_REFRESH)
532 switch (need_update) {
536 if (calculate_dimensions_of_cells(bv, font, false)) {
551 string const InsetTabular::editMessage() const
553 return _("Opened Tabular Inset");
557 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
559 UpdatableInset::edit(bv, x, y, button);
561 if (!bv->lockInset(this)) {
562 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
566 the_locking_inset = 0;
572 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
573 activateCellInsetAbs(bv, x, y, button);
578 void InsetTabular::edit(BufferView * bv, bool front)
580 UpdatableInset::edit(bv, front);
582 if (!bv->lockInset(this)) {
583 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
588 the_locking_inset = 0;
592 if (isRightToLeft(bv))
593 actcell = tabular->GetLastCellInRow(0);
597 if (isRightToLeft(bv))
598 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
600 actcell = tabular->GetNumberOfCells() - 1;
608 void InsetTabular::insetUnlock(BufferView * bv)
610 if (the_locking_inset) {
611 the_locking_inset->insetUnlock(bv);
612 updateLocal(bv, CELL, false);
613 the_locking_inset = 0;
619 if (scroll(false) || hasSelection()) {
624 updateLocal(bv, FULL, false);
629 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
630 bool mark_dirty) const
634 calculate_dimensions_of_cells(bv, font, true);
636 if (!locked && what == CELL)
638 if (need_update < what) // only set this if it has greater update
641 if (need_update != NONE) {
642 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
649 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
651 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
656 if (inset == tabular->GetCellInset(actcell)) {
657 lyxerr[Debug::INSETTEXT] << "OK" << endl;
658 the_locking_inset = tabular->GetCellInset(actcell);
661 } else if (!the_locking_inset) {
662 int const n = tabular->GetNumberOfCells();
663 int const id = inset->id();
664 for (int i = 0; i < n; ++i) {
665 InsetText * in = tabular->GetCellInset(i);
668 the_locking_inset = in;
673 if (in->getInsetFromID(id)) {
676 return the_locking_inset->lockInsetInInset(bv, inset);
679 } else if (the_locking_inset && (the_locking_inset == inset)) {
680 lyxerr[Debug::INSETTEXT] << "OK" << endl;
682 } else if (the_locking_inset) {
683 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
684 return the_locking_inset->lockInsetInInset(bv, inset);
686 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
691 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
694 if (!the_locking_inset)
696 if (the_locking_inset == inset) {
697 the_locking_inset->insetUnlock(bv);
699 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
705 updateLocal(bv, CELL, false);
706 // this has to be here otherwise we don't redraw the cell!
707 the_locking_inset = 0;
708 // showInsetCursor(bv, false);
711 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
712 if (inset->lyxCode() == TABULAR_CODE &&
713 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
714 bv->owner()->getDialogs().updateTabular(this);
723 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
725 Inset * tl_inset = inset;
726 // look if this inset is really inside myself!
727 while(tl_inset->owner() && tl_inset->owner() != this)
728 tl_inset = tl_inset->owner();
729 // if we enter here it's not ower inset
730 if (!tl_inset->owner())
732 // we only have to do this if this is a subinset of our cells
733 if (tl_inset != inset) {
734 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
737 updateLocal(bv, CELL, false);
742 int InsetTabular::insetInInsetY() const
744 if (!the_locking_inset)
746 return inset_y + the_locking_inset->insetInInsetY();
750 UpdatableInset * InsetTabular::getLockingInset() const
752 return the_locking_inset ? the_locking_inset->getLockingInset() :
753 const_cast<InsetTabular *>(this);
757 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
761 if (the_locking_inset)
762 return the_locking_inset->getFirstLockingInsetOfType(c);
767 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
769 if (the_locking_inset)
770 return the_locking_inset->insertInset(bv, inset);
775 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
777 if (hasSelection() && cmd.button() == mouse_button::button3)
780 if (hasSelection()) {
782 updateLocal(cmd.view(), SELECTION, false);
785 int const ocell = actcell;
786 int const orow = actrow;
787 BufferView * bv = cmd.view();
792 the_locking_inset = 0;
796 setPos(bv, cmd.x, cmd.y);
798 updateLocal(bv, NONE, false);
801 if (cmd.button() == mouse_button::button3) {
802 if ((ocell != actcell) && the_locking_inset) {
803 the_locking_inset->insetUnlock(bv);
804 updateLocal(bv, CELL, false);
805 the_locking_inset = 0;
812 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
814 if ((ocell == actcell) && the_locking_inset && inset_hit) {
816 FuncRequest cmd1 = cmd;
819 the_locking_inset->localDispatch(cmd1);
823 if (the_locking_inset) {
824 the_locking_inset->insetUnlock(bv);
825 updateLocal(bv, CELL, false);
826 the_locking_inset = 0;
829 if (cmd.button() == mouse_button::button2) {
830 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
834 if (inset_hit && bv->theLockingInset()) {
835 if (!bv->lockInset(static_cast<UpdatableInset*>
836 (tabular->GetCellInset(actcell))))
838 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
841 FuncRequest cmd1 = cmd;
844 the_locking_inset->localDispatch(cmd1);
851 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
854 if (the_locking_inset) {
855 FuncRequest cmd1 = cmd;
858 ret = the_locking_inset->localDispatch(cmd1);
860 if (cmd.button() == mouse_button::button3 && !ret) {
861 cmd.view()->owner()->getDialogs().showTabular(this);
868 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
870 if (the_locking_inset) {
871 FuncRequest cmd1 = cmd;
874 the_locking_inset->localDispatch(cmd1);
878 BufferView * bv = cmd.view();
880 int const old_cell = actcell;
882 setPos(bv, cmd.x, cmd.y);
883 if (!hasSelection()) {
884 setSelection(actcell, actcell);
885 updateLocal(bv, SELECTION, false);
886 } else if (old_cell != actcell) {
887 setSelection(sel_cell_start, actcell);
888 updateLocal(bv, SELECTION, false);
894 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
896 // We need to save the value of the_locking_inset as the call to
897 // the_locking_inset->localDispatch might unlock it.
898 old_locking_inset = the_locking_inset;
899 RESULT result = UpdatableInset::localDispatch(cmd);
901 BufferView * bv = cmd.view();
902 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
907 if (cmd.action < 0 && cmd.argument.empty())
910 bool hs = hasSelection();
913 // this one have priority over the locked InsetText, if we're not already
914 // inside another tabular then that one get's priority!
915 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
916 switch (cmd.action) {
917 case LFUN_MOUSE_PRESS:
921 case LFUN_MOUSE_MOTION:
922 lfunMouseMotion(cmd);
925 case LFUN_MOUSE_RELEASE:
926 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
931 unlockInsetInInset(bv, the_locking_inset);
932 if (cmd.action == LFUN_TAB)
933 moveNextCell(bv, old_locking_inset != 0);
935 movePrevCell(bv, old_locking_inset != 0);
938 updateLocal(bv, SELECTION, false);
939 if (!the_locking_inset) {
941 return DISPATCHED_NOUPDATE;
944 // this to avoid compiler warnings.
950 kb_action action = cmd.action;
951 string arg = cmd.argument;
952 if (the_locking_inset) {
953 result = the_locking_inset->localDispatch(cmd);
954 if (result == DISPATCHED_NOUPDATE) {
957 if (sc != scroll()) { // inset has been scrolled
958 the_locking_inset->toggleInsetCursor(bv);
959 updateLocal(bv, FULL, false);
960 the_locking_inset->toggleInsetCursor(bv);
963 } else if (result == DISPATCHED) {
964 the_locking_inset->toggleInsetCursor(bv);
965 updateLocal(bv, CELL, false);
966 the_locking_inset->toggleInsetCursor(bv);
968 } else if (result == FINISHED_UP) {
970 } else if (result == FINISHED_DOWN) {
972 } else if (result == FINISHED_RIGHT) {
980 // --- Cursor Movements ----------------------------------
981 case LFUN_RIGHTSEL: {
982 int const start = hasSelection() ? sel_cell_start : actcell;
983 if (tabular->IsLastCellInRow(actcell)) {
984 setSelection(start, actcell);
989 // if we are starting a selection, only select
990 // the current cell at the beginning
991 if (hasSelection()) {
992 moveRight(bv, false);
995 setSelection(start, end);
996 updateLocal(bv, SELECTION, false);
1000 result = moveRight(bv);
1003 updateLocal(bv, SELECTION, false);
1005 case LFUN_LEFTSEL: {
1006 int const start = hasSelection() ? sel_cell_start : actcell;
1007 if (tabular->IsFirstCellInRow(actcell)) {
1008 setSelection(start, actcell);
1013 // if we are starting a selection, only select
1014 // the current cell at the beginning
1015 if (hasSelection()) {
1016 moveLeft(bv, false);
1019 setSelection(start, end);
1020 updateLocal(bv, SELECTION, false);
1024 result = moveLeft(bv);
1027 updateLocal(bv, SELECTION, false);
1029 case LFUN_DOWNSEL: {
1030 int const start = hasSelection() ? sel_cell_start : actcell;
1031 int const ocell = actcell;
1032 // if we are starting a selection, only select
1033 // the current cell at the beginning
1034 if (hasSelection()) {
1035 moveDown(bv, false);
1036 if ((ocell == sel_cell_end) ||
1037 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1038 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1040 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1042 setSelection(start, start);
1044 updateLocal(bv, SELECTION, false);
1048 result = moveDown(bv, old_locking_inset != 0);
1051 updateLocal(bv, SELECTION, false);
1055 int const start = hasSelection() ? sel_cell_start : actcell;
1056 int const ocell = actcell;
1057 // if we are starting a selection, only select
1058 // the current cell at the beginning
1059 if (hasSelection()) {
1061 if ((ocell == sel_cell_end) ||
1062 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1063 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1065 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1067 setSelection(start, start);
1069 updateLocal(bv, SELECTION, false);
1073 result = moveUp(bv, old_locking_inset != 0);
1076 updateLocal(bv, SELECTION, false);
1079 UpdateCodes code = CURSOR;
1084 int column = actcol;
1085 unlockInsetInInset(bv, the_locking_inset);
1086 if (bv->text->first_y + bv->painter().paperHeight() <
1087 (top_baseline + tabular->GetHeightOfTabular()))
1089 bv->scrollDocView(bv->text->first_y + bv->painter().paperHeight());
1091 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1093 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1096 updateLocal(bv, code, false);
1100 UpdateCodes code = CURSOR;
1105 int column = actcol;
1106 unlockInsetInInset(bv, the_locking_inset);
1107 if (top_baseline < 0) {
1108 bv->scrollDocView(bv->text->first_y - bv->painter().paperHeight());
1110 if (top_baseline > 0)
1113 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1118 updateLocal(bv, code, false);
1121 // none of these make sense for insettabular,
1122 // but we must catch them to prevent any
1123 // selection from being confused
1127 case LFUN_WORDLEFTSEL:
1128 case LFUN_WORDRIGHT:
1129 case LFUN_WORDRIGHTSEL:
1131 case LFUN_DOWN_PARAGRAPH:
1132 case LFUN_DOWN_PARAGRAPHSEL:
1133 case LFUN_UP_PARAGRAPH:
1134 case LFUN_UP_PARAGRAPHSEL:
1135 case LFUN_BACKSPACE:
1140 case LFUN_BEGINNINGBUF:
1141 case LFUN_BEGINNINGBUFSEL:
1143 case LFUN_ENDBUFSEL:
1145 case LFUN_LAYOUT_TABULAR:
1146 bv->owner()->getDialogs().showTabular(this);
1148 case LFUN_TABULAR_FEATURE:
1149 if (!tabularFeatures(bv, arg))
1150 result = UNDISPATCHED;
1152 // insert file functions
1153 case LFUN_FILE_INSERT_ASCII_PARA:
1154 case LFUN_FILE_INSERT_ASCII:
1156 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1159 if (insertAsciiString(bv, tmpstr, false))
1160 updateLocal(bv, INIT, true);
1162 result = UNDISPATCHED;
1165 // cut and paste functions
1167 if (!copySelection(bv))
1171 setUndo(bv, Undo::DELETE,
1172 bv->text->cursor.par(),
1173 bv->text->cursor.par()->next());
1174 cutSelection(bv->buffer()->params);
1175 updateLocal(bv, INIT, true);
1178 if (!hasSelection())
1183 case LFUN_PASTESELECTION:
1185 string const clip(bv->getClipboard());
1189 if (clip.find('\t') != string::npos) {
1193 string::size_type len = clip.length();
1194 string::size_type p = 0;
1197 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1205 maxCols = max(cols, maxCols);
1211 maxCols = max(cols, maxCols);
1212 delete paste_tabular;
1213 paste_tabular = new LyXTabular(bv->buffer()->params,
1214 this, rows, maxCols);
1215 string::size_type op = 0;
1217 int cells = paste_tabular->GetNumberOfCells();
1219 while ((cell < cells) && (p < len) &&
1220 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1225 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1230 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1231 while (cols++ < maxCols)
1239 // check for the last cell if there is no trailing '\n'
1240 if ((cell < cells) && (op < len))
1241 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1244 if (!insertAsciiString(bv, clip, true))
1247 // so that the clipboard is used and it goes on
1249 // and executes LFUN_PASTESELECTION in insettext!
1250 delete paste_tabular;
1255 if (hasPasteBuffer()) {
1256 setUndo(bv, Undo::INSERT,
1257 bv->text->cursor.par(),
1258 bv->text->cursor.par()->next());
1260 updateLocal(bv, INIT, true);
1263 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1265 // handle font changing stuff on selection before we lock the inset
1266 // in the default part!
1267 result = UNDISPATCHED;
1278 case LFUN_UNDERLINE:
1279 case LFUN_FONT_SIZE:
1280 if (bv->dispatch(FuncRequest(bv, action, arg)))
1281 result = DISPATCHED;
1287 // we try to activate the actual inset and put this event down to
1288 // the insets dispatch function.
1289 if ((result == DISPATCHED) || the_locking_inset)
1292 if (activateCellInset(bv)) {
1293 // reset need_update setted in above function!
1295 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1296 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1297 unlockInsetInInset(bv, the_locking_inset);
1299 // we need to update if this was requested before
1300 updateLocal(bv, NONE, false);
1301 return UNDISPATCHED;
1304 // so the below CELL is not set because this is higher
1305 // priority and we get a full redraw
1306 need_update = SELECTION;
1309 updateLocal(bv, CELL, false);
1314 if (result < FINISHED) {
1315 if (!the_locking_inset) {
1316 if (bv->fitCursor())
1317 updateLocal(bv, FULL, false);
1319 showInsetCursor(bv);
1322 bv->unlockInset(this);
1327 int InsetTabular::latex(Buffer const * buf, ostream & os,
1328 bool fragile, bool fp) const
1330 return tabular->latex(buf, os, fragile, fp);
1334 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1337 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1339 return tabular->ascii(buf, os, 0, false,0);
1343 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1346 int const ret = tabular->ascii(buf,os,
1347 (int)parOwner()->params().depth(),
1354 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1359 // if the table is inside a float it doesn't need the informaltable
1360 // wrapper. Search for it.
1361 for(master = owner();
1362 master && master->lyxCode() != Inset::FLOAT_CODE;
1363 master = master->owner());
1366 os << "<informaltable>";
1371 ret+= tabular->docbook(buf, os, mixcont);
1373 os << "</informaltable>";
1382 void InsetTabular::validate(LaTeXFeatures & features) const
1384 tabular->Validate(features);
1388 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1389 LyXFont const & font,
1396 bool changed = false;
1398 // if we have a locking_inset we should have to check only this cell for
1399 // change so I'll try this to have a boost, but who knows ;)
1400 if ((need_update != INIT) &&
1401 (the_locking_inset == tabular->GetCellInset(actcell))) {
1402 for(int i = 0; i < tabular->columns(); ++i) {
1403 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1405 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1408 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1409 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1410 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1413 for (int i = 0; i < tabular->rows(); ++i) {
1416 for (int j = 0; j < tabular->columns(); ++j) {
1417 if (tabular->IsPartOfMultiColumn(i,j))
1420 inset = tabular->GetCellInset(cell);
1421 if (!reinit && !tabular->GetPWidth(cell).zero())
1422 inset->update(bv, font, false);
1423 maxAsc = max(maxAsc, inset->ascent(bv, font));
1424 maxDesc = max(maxDesc, inset->descent(bv, font));
1425 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1427 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1428 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1436 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1438 if (the_locking_inset) {
1439 the_locking_inset->getCursorPos(bv, x, y);
1442 x = cursor_.x() - top_x;
1447 void InsetTabular::toggleInsetCursor(BufferView * bv)
1450 if (isCursorVisible())
1451 bv->hideLockedInsetCursor();
1454 if (the_locking_inset) {
1455 the_locking_inset->toggleInsetCursor(bv);
1459 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1461 int const asc = font_metrics::maxAscent(font);
1462 int const desc = font_metrics::maxDescent(font);
1464 if (isCursorVisible())
1465 bv->hideLockedInsetCursor();
1467 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1468 toggleCursorVisible();
1472 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1476 if (!isCursorVisible()) {
1477 LyXFont font; // = GetFont(par, cursor.pos);
1479 int const asc = font_metrics::maxAscent(font);
1480 int const desc = font_metrics::maxDescent(font);
1481 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1483 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1484 setCursorVisible(true);
1489 void InsetTabular::hideInsetCursor(BufferView * bv)
1491 if (isCursorVisible()) {
1492 bv->hideLockedInsetCursor();
1493 setCursorVisible(false);
1498 void InsetTabular::fitInsetCursor(BufferView * bv) const
1500 if (the_locking_inset) {
1501 int old_first_y = bv->text->first_y;
1502 the_locking_inset->fitInsetCursor(bv);
1503 if (old_first_y != bv->text->first_y)
1509 int const asc = font_metrics::maxAscent(font);
1510 int const desc = font_metrics::maxDescent(font);
1513 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1518 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1522 actcell = actrow = actcol = 0;
1523 int ly = tabular->GetDescentOfRow(actrow);
1525 // first search the right row
1526 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1527 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1528 tabular->GetAscentOfRow(actrow + 1) +
1529 tabular->GetAdditionalHeight(actrow + 1));
1531 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1533 actcell = tabular->GetCellNumber(actrow, actcol);
1535 // now search the right column
1536 int lx = tabular->GetWidthOfColumn(actcell) -
1537 tabular->GetAdditionalWidth(actcell);
1538 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1539 lx += tabular->GetWidthOfColumn(actcell + 1)
1540 + tabular->GetAdditionalWidth(actcell);
1542 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1547 int InsetTabular::getCellXPos(int cell) const
1551 for (; !tabular->IsFirstCellInRow(c); --c)
1553 int lx = tabular->GetWidthOfColumn(cell);
1554 for (; c < cell; ++c) {
1555 lx += tabular->GetWidthOfColumn(c);
1557 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1561 void InsetTabular::resetPos(BufferView * bv) const
1563 #ifdef WITH_WARNINGS
1564 #warning This should be fixed in the right manner (20011128 Jug)
1566 // fast hack to fix infinite repaintings!
1567 if (in_reset_pos > 0)
1571 actcol = tabular->column_of_cell(actcell);
1574 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1575 if (tabular->IsLastCellInRow(cell)) {
1576 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1577 tabular->GetAscentOfRow(actrow + 1) +
1578 tabular->GetAdditionalHeight(actrow + 1));
1582 if (!locked || nodraw()) {
1583 if (the_locking_inset)
1584 inset_y = cursor_.y();
1587 // we need this only from here on!!!
1589 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1590 int new_x = getCellXPos(actcell);
1591 int old_x = cursor_.x();
1594 // cursor.x(getCellXPos(actcell) + offset);
1595 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1596 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1599 updateLocal(bv, FULL, false);
1600 } else if (the_locking_inset &&
1601 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1603 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1604 if (xx > (bv->workWidth()-20)) {
1605 scroll(bv, -(xx - bv->workWidth() + 60));
1606 updateLocal(bv, FULL, false);
1607 } else if (xx < 20) {
1613 updateLocal(bv, FULL, false);
1615 } else if ((cursor_.x() - offset) > 20 &&
1616 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1617 > (bv->workWidth() - 20)) {
1618 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1619 updateLocal(bv, FULL, false);
1620 } else if ((cursor_.x() - offset) < 20) {
1621 scroll(bv, 20 - cursor_.x() + offset);
1622 updateLocal(bv, FULL, false);
1623 } else if (scroll() && top_x > 20 &&
1624 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1625 scroll(bv, old_x - cursor_.x());
1626 updateLocal(bv, FULL, false);
1628 if (the_locking_inset) {
1629 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1630 inset_y = cursor_.y();
1632 if ((!the_locking_inset ||
1633 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1634 actcell != oldcell) {
1635 InsetTabular * inset = const_cast<InsetTabular *>(this);
1636 bv->owner()->getDialogs().updateTabular(inset);
1643 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1645 if (lock && !old_locking_inset) {
1646 if (activateCellInset(bv))
1649 bool moved = isRightToLeft(bv)
1650 ? movePrevCell(bv) : moveNextCell(bv);
1652 return FINISHED_RIGHT;
1653 if (lock && activateCellInset(bv))
1657 return DISPATCHED_NOUPDATE;
1661 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1663 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1666 if (lock) { // behind the inset
1667 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1671 return DISPATCHED_NOUPDATE;
1675 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1677 int const ocell = actcell;
1678 actcell = tabular->GetCellAbove(actcell);
1679 if (actcell == ocell) // we moved out of the inset
1685 if (old_locking_inset) {
1686 old_locking_inset->getCursorPos(bv, x, y);
1687 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1689 if (activateCellInset(bv, x, 0))
1692 return DISPATCHED_NOUPDATE;
1696 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1698 int const ocell = actcell;
1699 actcell = tabular->GetCellBelow(actcell);
1700 if (actcell == ocell) // we moved out of the inset
1701 return FINISHED_DOWN;
1706 if (old_locking_inset) {
1707 old_locking_inset->getCursorPos(bv, x, y);
1708 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1710 if (activateCellInset(bv, x, 0))
1713 return DISPATCHED_NOUPDATE;
1717 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1719 if (isRightToLeft(bv)) {
1720 if (tabular->IsFirstCellInRow(actcell)) {
1721 int row = tabular->row_of_cell(actcell);
1722 if (row == tabular->rows() - 1)
1724 actcell = tabular->GetLastCellInRow(row);
1725 actcell = tabular->GetCellBelow(actcell);
1732 if (tabular->IsLastCell(actcell))
1737 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1738 isRightToLeftPar(bv->buffer()->params);
1739 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1746 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1748 if (isRightToLeft(bv)) {
1749 if (tabular->IsLastCellInRow(actcell)) {
1750 int row = tabular->row_of_cell(actcell);
1753 actcell = tabular->GetFirstCellInRow(row);
1754 actcell = tabular->GetCellAbove(actcell);
1756 if (tabular->IsLastCell(actcell))
1761 if (!actcell) // first cell
1766 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1767 isRightToLeftPar(bv->buffer()->params);
1768 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1775 bool InsetTabular::deletable() const
1781 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1785 setSelection(0, tabular->GetNumberOfCells() - 1);
1787 if (hasSelection()) {
1788 setUndo(bv, Undo::EDIT,
1789 bv->text->cursor.par(),
1790 bv->text->cursor.par()->next());
1791 bool const frozen = undo_frozen;
1794 // apply the fontchange on the whole selection
1799 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1800 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1801 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1802 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1809 updateLocal(bv, INIT, true);
1811 if (the_locking_inset)
1812 the_locking_inset->setFont(bv, font, tall);
1816 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1818 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1821 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1822 string const tmp = tabularFeature[i].feature;
1824 if (tmp == what.substr(0, tmp.length())) {
1825 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1826 //tabularFeatures[i].feature.length())) {
1827 action = tabularFeature[i].action;
1831 if (action == LyXTabular::LAST_ACTION)
1835 ltrim(what.substr(tabularFeature[i].feature.length()));
1836 tabularFeatures(bv, action, val);
1840 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1841 string const & special, bool & flag)
1843 if (special == "dl_above") {
1846 } else if (special == "dl_below") {
1847 ltt.bottomDL = flag;
1849 } else if (special == "empty") {
1859 void InsetTabular::tabularFeatures(BufferView * bv,
1860 LyXTabular::Feature feature,
1861 string const & value)
1867 bool setLines = false;
1868 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1869 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1872 case LyXTabular::M_ALIGN_LEFT:
1873 case LyXTabular::ALIGN_LEFT:
1874 setAlign = LYX_ALIGN_LEFT;
1876 case LyXTabular::M_ALIGN_RIGHT:
1877 case LyXTabular::ALIGN_RIGHT:
1878 setAlign = LYX_ALIGN_RIGHT;
1880 case LyXTabular::M_ALIGN_CENTER:
1881 case LyXTabular::ALIGN_CENTER:
1882 setAlign = LYX_ALIGN_CENTER;
1884 case LyXTabular::ALIGN_BLOCK:
1885 setAlign = LYX_ALIGN_BLOCK;
1887 case LyXTabular::M_VALIGN_TOP:
1888 case LyXTabular::VALIGN_TOP:
1889 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1891 case LyXTabular::M_VALIGN_BOTTOM:
1892 case LyXTabular::VALIGN_BOTTOM:
1893 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1895 case LyXTabular::M_VALIGN_CENTER:
1896 case LyXTabular::VALIGN_CENTER:
1897 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1902 if (hasSelection()) {
1903 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1905 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1906 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1908 setUndo(bv, Undo::FINISH,
1909 bv->text->cursor.par(),
1910 bv->text->cursor.par()->next());
1912 int row = tabular->row_of_cell(actcell);
1913 int column = tabular->column_of_cell(actcell);
1915 LyXTabular::ltType ltt;
1918 case LyXTabular::SET_PWIDTH:
1920 LyXLength const vallen(value);
1921 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1923 bool const update = (tmplen != vallen);
1924 tabular->SetColumnPWidth(actcell, vallen);
1927 for (int i = 0; i < tabular->rows(); ++i) {
1928 cell = tabular->GetCellNumber(i,column);
1929 tabular->GetCellInset(cell)->resizeLyXText(bv);
1931 updateLocal(bv, INIT, true);
1935 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1936 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1937 else if (!vallen.zero()
1938 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1939 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1942 case LyXTabular::SET_MPWIDTH:
1944 LyXLength const vallen(value);
1945 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1947 bool const update = (tmplen != vallen);
1948 tabular->SetMColumnPWidth(actcell, vallen);
1950 for (int i = 0; i < tabular->rows(); ++i) {
1951 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1954 updateLocal(bv, INIT, true);
1958 case LyXTabular::SET_SPECIAL_COLUMN:
1959 case LyXTabular::SET_SPECIAL_MULTI:
1960 tabular->SetAlignSpecial(actcell,value,feature);
1961 updateLocal(bv, FULL, true);
1963 case LyXTabular::APPEND_ROW:
1964 // append the row into the tabular
1965 unlockInsetInInset(bv, the_locking_inset);
1966 tabular->AppendRow(bv->buffer()->params, actcell);
1967 updateLocal(bv, INIT, true);
1969 case LyXTabular::APPEND_COLUMN:
1970 // append the column into the tabular
1971 unlockInsetInInset(bv, the_locking_inset);
1972 tabular->AppendColumn(bv->buffer()->params, actcell);
1973 actcell = tabular->GetCellNumber(row, column);
1974 updateLocal(bv, INIT, true);
1976 case LyXTabular::DELETE_ROW:
1977 unlockInsetInInset(bv, the_locking_inset);
1978 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1979 tabular->DeleteRow(sel_row_start);
1981 if (sel_row_start >= tabular->rows())
1983 actcell = tabular->GetCellNumber(sel_row_start, column);
1985 updateLocal(bv, INIT, true);
1987 case LyXTabular::DELETE_COLUMN:
1988 unlockInsetInInset(bv, the_locking_inset);
1989 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1990 tabular->DeleteColumn(sel_col_start);
1992 if (sel_col_start >= tabular->columns())
1994 actcell = tabular->GetCellNumber(row, sel_col_start);
1996 updateLocal(bv, INIT, true);
1998 case LyXTabular::M_TOGGLE_LINE_TOP:
2000 case LyXTabular::TOGGLE_LINE_TOP:
2002 bool lineSet = !tabular->TopLine(actcell, flag);
2003 for (int i = sel_row_start; i <= sel_row_end; ++i)
2004 for (int j = sel_col_start; j <= sel_col_end; ++j)
2005 tabular->SetTopLine(
2006 tabular->GetCellNumber(i, j),
2008 updateLocal(bv, INIT, true);
2012 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2014 case LyXTabular::TOGGLE_LINE_BOTTOM:
2016 bool lineSet = !tabular->BottomLine(actcell, flag);
2017 for (int i = sel_row_start; i <= sel_row_end; ++i)
2018 for (int j = sel_col_start; j <= sel_col_end; ++j)
2019 tabular->SetBottomLine(
2020 tabular->GetCellNumber(i, j),
2023 updateLocal(bv, INIT, true);
2027 case LyXTabular::M_TOGGLE_LINE_LEFT:
2029 case LyXTabular::TOGGLE_LINE_LEFT:
2031 bool lineSet = !tabular->LeftLine(actcell, flag);
2032 for (int i = sel_row_start; i <= sel_row_end; ++i)
2033 for (int j = sel_col_start; j <= sel_col_end; ++j)
2034 tabular->SetLeftLine(
2035 tabular->GetCellNumber(i,j),
2038 updateLocal(bv, INIT, true);
2042 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2044 case LyXTabular::TOGGLE_LINE_RIGHT:
2046 bool lineSet = !tabular->RightLine(actcell, flag);
2047 for (int i = sel_row_start; i <= sel_row_end; ++i)
2048 for (int j = sel_col_start; j <= sel_col_end; ++j)
2049 tabular->SetRightLine(
2050 tabular->GetCellNumber(i,j),
2053 updateLocal(bv, INIT, true);
2057 case LyXTabular::M_ALIGN_LEFT:
2058 case LyXTabular::M_ALIGN_RIGHT:
2059 case LyXTabular::M_ALIGN_CENTER:
2061 case LyXTabular::ALIGN_LEFT:
2062 case LyXTabular::ALIGN_RIGHT:
2063 case LyXTabular::ALIGN_CENTER:
2064 case LyXTabular::ALIGN_BLOCK:
2065 for (int i = sel_row_start; i <= sel_row_end; ++i)
2066 for (int j = sel_col_start; j <= sel_col_end; ++j)
2067 tabular->SetAlignment(
2068 tabular->GetCellNumber(i, j),
2071 updateLocal(bv, INIT, true);
2073 case LyXTabular::M_VALIGN_TOP:
2074 case LyXTabular::M_VALIGN_BOTTOM:
2075 case LyXTabular::M_VALIGN_CENTER:
2077 case LyXTabular::VALIGN_TOP:
2078 case LyXTabular::VALIGN_BOTTOM:
2079 case LyXTabular::VALIGN_CENTER:
2080 for (int i = sel_row_start; i <= sel_row_end; ++i)
2081 for (int j = sel_col_start; j <= sel_col_end; ++j)
2082 tabular->SetVAlignment(
2083 tabular->GetCellNumber(i, j),
2085 updateLocal(bv, INIT, true);
2087 case LyXTabular::MULTICOLUMN:
2089 if (sel_row_start != sel_row_end) {
2090 Alert::alert(_("Impossible operation!"),
2091 _("Multicolumns can only be horizontally."),
2095 // just multicol for one Single Cell
2096 if (!hasSelection()) {
2097 // check wether we are completly in a multicol
2098 if (tabular->IsMultiColumn(actcell)) {
2099 tabular->UnsetMultiColumn(actcell);
2100 updateLocal(bv, INIT, true);
2102 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2103 updateLocal(bv, CELL, true);
2107 // we have a selection so this means we just add all this
2108 // cells to form a multicolumn cell
2112 if (sel_cell_start > sel_cell_end) {
2113 s_start = sel_cell_end;
2114 s_end = sel_cell_start;
2116 s_start = sel_cell_start;
2117 s_end = sel_cell_end;
2119 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2122 updateLocal(bv, INIT, true);
2125 case LyXTabular::SET_ALL_LINES:
2127 case LyXTabular::UNSET_ALL_LINES:
2128 for (int i = sel_row_start; i <= sel_row_end; ++i)
2129 for (int j = sel_col_start; j <= sel_col_end; ++j)
2130 tabular->SetAllLines(
2131 tabular->GetCellNumber(i,j), setLines);
2132 updateLocal(bv, INIT, true);
2134 case LyXTabular::SET_LONGTABULAR:
2135 tabular->SetLongTabular(true);
2136 updateLocal(bv, INIT, true); // because this toggles displayed
2138 case LyXTabular::UNSET_LONGTABULAR:
2139 tabular->SetLongTabular(false);
2140 updateLocal(bv, INIT, true); // because this toggles displayed
2142 case LyXTabular::SET_ROTATE_TABULAR:
2143 tabular->SetRotateTabular(true);
2145 case LyXTabular::UNSET_ROTATE_TABULAR:
2146 tabular->SetRotateTabular(false);
2148 case LyXTabular::SET_ROTATE_CELL:
2149 for (int i = sel_row_start; i <= sel_row_end; ++i)
2150 for (int j = sel_col_start; j<=sel_col_end; ++j)
2151 tabular->SetRotateCell(
2152 tabular->GetCellNumber(i, j),
2155 case LyXTabular::UNSET_ROTATE_CELL:
2156 for (int i = sel_row_start; i <= sel_row_end; ++i)
2157 for (int j = sel_col_start; j <= sel_col_end; ++j)
2158 tabular->SetRotateCell(
2159 tabular->GetCellNumber(i, j), false);
2161 case LyXTabular::SET_USEBOX:
2163 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2164 if (val == tabular->GetUsebox(actcell))
2165 val = LyXTabular::BOX_NONE;
2166 for (int i = sel_row_start; i <= sel_row_end; ++i)
2167 for (int j = sel_col_start; j <= sel_col_end; ++j)
2169 tabular->GetCellNumber(i, j), val);
2172 case LyXTabular::UNSET_LTFIRSTHEAD:
2174 case LyXTabular::SET_LTFIRSTHEAD:
2175 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2176 checkLongtableSpecial(ltt, value, flag);
2177 tabular->SetLTHead(row, flag, ltt, true);
2179 case LyXTabular::UNSET_LTHEAD:
2181 case LyXTabular::SET_LTHEAD:
2182 (void)tabular->GetRowOfLTHead(row, ltt);
2183 checkLongtableSpecial(ltt, value, flag);
2184 tabular->SetLTHead(row, flag, ltt, false);
2186 case LyXTabular::UNSET_LTFOOT:
2188 case LyXTabular::SET_LTFOOT:
2189 (void)tabular->GetRowOfLTFoot(row, ltt);
2190 checkLongtableSpecial(ltt, value, flag);
2191 tabular->SetLTFoot(row, flag, ltt, false);
2193 case LyXTabular::UNSET_LTLASTFOOT:
2195 case LyXTabular::SET_LTLASTFOOT:
2196 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2197 checkLongtableSpecial(ltt, value, flag);
2198 tabular->SetLTFoot(row, flag, ltt, true);
2200 case LyXTabular::SET_LTNEWPAGE:
2202 bool what = !tabular->GetLTNewPage(row);
2203 tabular->SetLTNewPage(row, what);
2206 // dummy stuff just to avoid warnings
2207 case LyXTabular::LAST_ACTION:
2213 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2216 UpdatableInset * inset =
2217 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2218 LyXFont font(LyXFont::ALL_SANE);
2220 x = inset->x() + inset->width(bv, font);
2221 y = inset->descent(bv, font);
2223 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2224 //inset_y = cursor.y();
2225 inset->edit(bv, x, y, button);
2226 if (!the_locking_inset)
2228 updateLocal(bv, CELL, false);
2229 return (the_locking_inset != 0);
2233 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2234 mouse_button::state button)
2236 inset_x = cursor_.x()
2237 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2238 inset_y = cursor_.y();
2239 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2243 bool InsetTabular::insetHit(BufferView *, int x, int) const
2246 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2250 // This returns paperWidth() if the cell-width is unlimited or the width
2251 // in pixels if we have a pwidth for this cell.
2252 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2254 LyXLength const len = tabular->GetPWidth(cell);
2258 return len.inPixels(latexTextWidth(bv));
2262 int InsetTabular::getMaxWidth(BufferView * bv,
2263 UpdatableInset const * inset) const
2265 int cell = tabular->GetCellFromInset(inset, actcell);
2268 lyxerr << "Own inset not found, shouldn't really happen!"
2273 int w = getMaxWidthOfCell(bv, cell);
2275 // because the inset then subtracts it's top_x and owner->x()
2276 w += (inset->x() - top_x);
2283 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2285 resizeLyXText(bv, recursive);
2289 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2292 for(int i = 0; i < tabular->rows(); ++i) {
2293 for(int j = 0; j < tabular->columns(); ++j) {
2294 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2302 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2303 bool const recursive) const
2305 if (the_locking_inset)
2306 return the_locking_inset->getLyXText(bv, recursive);
2308 // if we're locked lock the actual insettext and return it's LyXText!!!
2310 UpdatableInset * inset =
2311 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2312 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2313 return the_locking_inset->getLyXText(bv, recursive);
2316 return Inset::getLyXText(bv, recursive);
2320 bool InsetTabular::showInsetDialog(BufferView * bv) const
2322 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2323 bv->owner()->getDialogs().
2324 showTabular(const_cast<InsetTabular *>(this));
2329 void InsetTabular::openLayoutDialog(BufferView * bv) const
2331 if (the_locking_inset) {
2332 InsetTabular * i = static_cast<InsetTabular *>
2333 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2335 i->openLayoutDialog(bv);
2339 bv->owner()->getDialogs().showTabular(
2340 const_cast<InsetTabular *>(this));
2345 // function returns an object as defined in func_status.h:
2346 // states OK, Unknown, Disabled, On, Off.
2348 FuncStatus InsetTabular::getStatus(string const & what) const
2350 int action = LyXTabular::LAST_ACTION;
2354 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2355 string const tmp = tabularFeature[i].feature;
2356 if (tmp == what.substr(0, tmp.length())) {
2357 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2358 // tabularFeatures[i].feature.length())) {
2359 action = tabularFeature[i].action;
2363 if (action == LyXTabular::LAST_ACTION) {
2365 return status.unknown(true);
2368 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2373 LyXTabular::ltType dummyltt;
2376 if (hasSelection()) {
2377 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2379 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2383 case LyXTabular::SET_PWIDTH:
2384 case LyXTabular::SET_MPWIDTH:
2385 case LyXTabular::SET_SPECIAL_COLUMN:
2386 case LyXTabular::SET_SPECIAL_MULTI:
2387 return status.disabled(true);
2389 case LyXTabular::APPEND_ROW:
2390 case LyXTabular::APPEND_COLUMN:
2391 case LyXTabular::DELETE_ROW:
2392 case LyXTabular::DELETE_COLUMN:
2393 case LyXTabular::SET_ALL_LINES:
2394 case LyXTabular::UNSET_ALL_LINES:
2395 return status.clear();
2397 case LyXTabular::MULTICOLUMN:
2398 status.setOnOff(tabular->IsMultiColumn(actcell));
2400 case LyXTabular::M_TOGGLE_LINE_TOP:
2402 case LyXTabular::TOGGLE_LINE_TOP:
2403 status.setOnOff(tabular->TopLine(actcell, flag));
2405 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2407 case LyXTabular::TOGGLE_LINE_BOTTOM:
2408 status.setOnOff(tabular->BottomLine(actcell, flag));
2410 case LyXTabular::M_TOGGLE_LINE_LEFT:
2412 case LyXTabular::TOGGLE_LINE_LEFT:
2413 status.setOnOff(tabular->LeftLine(actcell, flag));
2415 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2417 case LyXTabular::TOGGLE_LINE_RIGHT:
2418 status.setOnOff(tabular->RightLine(actcell, flag));
2420 case LyXTabular::M_ALIGN_LEFT:
2422 case LyXTabular::ALIGN_LEFT:
2423 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2425 case LyXTabular::M_ALIGN_RIGHT:
2427 case LyXTabular::ALIGN_RIGHT:
2428 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2430 case LyXTabular::M_ALIGN_CENTER:
2432 case LyXTabular::ALIGN_CENTER:
2433 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2435 case LyXTabular::ALIGN_BLOCK:
2436 status.disabled(tabular->GetPWidth(actcell).zero());
2437 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2439 case LyXTabular::M_VALIGN_TOP:
2441 case LyXTabular::VALIGN_TOP:
2442 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2444 case LyXTabular::M_VALIGN_BOTTOM:
2446 case LyXTabular::VALIGN_BOTTOM:
2447 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2449 case LyXTabular::M_VALIGN_CENTER:
2451 case LyXTabular::VALIGN_CENTER:
2452 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2454 case LyXTabular::SET_LONGTABULAR:
2455 status.setOnOff(tabular->IsLongTabular());
2457 case LyXTabular::UNSET_LONGTABULAR:
2458 status.setOnOff(!tabular->IsLongTabular());
2460 case LyXTabular::SET_ROTATE_TABULAR:
2461 status.setOnOff(tabular->GetRotateTabular());
2463 case LyXTabular::UNSET_ROTATE_TABULAR:
2464 status.setOnOff(!tabular->GetRotateTabular());
2466 case LyXTabular::SET_ROTATE_CELL:
2467 status.setOnOff(tabular->GetRotateCell(actcell));
2469 case LyXTabular::UNSET_ROTATE_CELL:
2470 status.setOnOff(!tabular->GetRotateCell(actcell));
2472 case LyXTabular::SET_USEBOX:
2473 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2475 case LyXTabular::SET_LTFIRSTHEAD:
2476 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2478 case LyXTabular::SET_LTHEAD:
2479 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2481 case LyXTabular::SET_LTFOOT:
2482 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2484 case LyXTabular::SET_LTLASTFOOT:
2485 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2487 case LyXTabular::SET_LTNEWPAGE:
2488 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2492 status.disabled(true);
2499 vector<string> const InsetTabular::getLabelList() const
2501 return tabular->getLabelList();
2505 bool InsetTabular::copySelection(BufferView * bv)
2507 if (!hasSelection())
2510 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2511 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2512 if (sel_col_start > sel_col_end) {
2513 sel_col_start = sel_col_end;
2514 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2516 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2518 int const columns = sel_col_end - sel_col_start + 1;
2520 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2521 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2522 if (sel_row_start > sel_row_end) {
2523 swap(sel_row_start, sel_row_end);
2525 int const rows = sel_row_end - sel_row_start + 1;
2527 delete paste_tabular;
2528 paste_tabular = new LyXTabular(bv->buffer()->params,
2529 this, *tabular); // rows, columns);
2530 for (int i = 0; i < sel_row_start; ++i)
2531 paste_tabular->DeleteRow(0);
2532 while (paste_tabular->rows() > rows)
2533 paste_tabular->DeleteRow(rows);
2534 paste_tabular->SetTopLine(0, true, true);
2535 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2537 for (int i = 0; i < sel_col_start; ++i)
2538 paste_tabular->DeleteColumn(0);
2539 while (paste_tabular->columns() > columns)
2540 paste_tabular->DeleteColumn(columns);
2541 paste_tabular->SetLeftLine(0, true, true);
2542 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2546 paste_tabular->ascii(bv->buffer(), sstr,
2547 (int)parOwner()->params().depth(), true, '\t');
2548 bv->stuffClipboard(STRCONV(sstr.str()));
2553 bool InsetTabular::pasteSelection(BufferView * bv)
2558 for (int r1 = 0, r2 = actrow;
2559 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2561 for(int c1 = 0, c2 = actcol;
2562 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2564 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2565 tabular->IsPartOfMultiColumn(r2,c2))
2567 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2571 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2575 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2576 int const n2 = tabular->GetCellNumber(r2, c2);
2577 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2578 tabular->GetCellInset(n2)->setOwner(this);
2579 tabular->GetCellInset(n2)->deleteLyXText(bv);
2580 tabular->GetCellInset(n2)->markNew();
2587 bool InsetTabular::cutSelection(BufferParams const & bp)
2589 if (!hasSelection())
2592 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2593 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2594 if (sel_col_start > sel_col_end) {
2595 sel_col_start = sel_col_end;
2596 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2598 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2600 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2601 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2602 if (sel_row_start > sel_row_end) {
2603 swap(sel_row_start, sel_row_end);
2605 if (sel_cell_start > sel_cell_end) {
2606 swap(sel_cell_start, sel_cell_end);
2608 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2609 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2610 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2617 bool InsetTabular::isRightToLeft(BufferView * bv)
2619 return bv->getParentLanguage(this)->RightToLeft();
2623 bool InsetTabular::nodraw() const
2625 if (!UpdatableInset::nodraw() && the_locking_inset)
2626 return the_locking_inset->nodraw();
2627 return UpdatableInset::nodraw();
2631 int InsetTabular::scroll(bool recursive) const
2633 int sx = UpdatableInset::scroll(false);
2635 if (recursive && the_locking_inset)
2636 sx += the_locking_inset->scroll(recursive);
2642 bool InsetTabular::doClearArea() const
2644 return !locked || (need_update & (FULL|INIT));
2648 void InsetTabular::getSelection(int & srow, int & erow,
2649 int & scol, int & ecol) const
2651 int const start = hasSelection() ? sel_cell_start : actcell;
2652 int const end = hasSelection() ? sel_cell_end : actcell;
2654 srow = tabular->row_of_cell(start);
2655 erow = tabular->row_of_cell(end);
2660 scol = tabular->column_of_cell(start);
2661 ecol = tabular->column_of_cell(end);
2665 ecol = tabular->right_column_of_cell(end);
2670 Paragraph * InsetTabular::getParFromID(int id) const
2673 for(int i = 0; i < tabular->rows(); ++i) {
2674 for(int j = 0; j < tabular->columns(); ++j) {
2675 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2683 Paragraph * InsetTabular::firstParagraph() const
2685 if (the_locking_inset)
2686 return the_locking_inset->firstParagraph();
2691 Paragraph * InsetTabular::getFirstParagraph(int i) const
2693 return (i < tabular->GetNumberOfCells())
2694 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2699 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2701 if (the_locking_inset)
2702 return the_locking_inset->cursor(bv);
2703 return Inset::cursor(bv);
2707 Inset * InsetTabular::getInsetFromID(int id_arg) const
2710 return const_cast<InsetTabular *>(this);
2713 for(int i = 0; i < tabular->rows(); ++i) {
2714 for(int j = 0; j < tabular->columns(); ++j) {
2715 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2724 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2727 if (the_locking_inset) {
2728 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2729 if (!word.word().empty()) {
2733 if (tabular->IsLastCell(actcell)) {
2734 bv->unlockInset(const_cast<InsetTabular *>(this));
2736 return WordLangTuple();
2740 // otherwise we have to lock the next inset and ask for it's selecttion
2741 UpdatableInset * inset =
2742 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2743 inset->edit(bv, 0, 0, mouse_button::none);
2744 WordLangTuple word(selectNextWordInt(bv, value));
2746 if (!word.word().empty())
2752 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2754 // when entering this function the inset should be ALWAYS locked!
2755 lyx::Assert(the_locking_inset);
2757 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2758 if (!word.word().empty())
2761 if (tabular->IsLastCell(actcell)) {
2762 bv->unlockInset(const_cast<InsetTabular *>(this));
2763 return WordLangTuple();
2766 // otherwise we have to lock the next inset and ask for it's selecttion
2767 UpdatableInset * inset =
2768 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2770 return selectNextWordInt(bv, value);
2774 void InsetTabular::selectSelectedWord(BufferView * bv)
2776 if (the_locking_inset) {
2777 the_locking_inset->selectSelectedWord(bv);
2784 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2786 if (the_locking_inset) {
2787 the_locking_inset->toggleSelection(bv, kill_selection);
2792 void InsetTabular::markErased()
2796 while (!tabular->IsLastCell(cell)) {
2798 InsetText * inset = tabular->GetCellInset(cell);
2799 inset->markErased();
2804 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2806 if (the_locking_inset) {
2807 if (the_locking_inset->nextChange(bv, length)) {
2808 updateLocal(bv, CELL, false);
2811 if (tabular->IsLastCell(actcell))
2815 InsetText * inset = tabular->GetCellInset(actcell);
2816 if (inset->nextChange(bv, length)) {
2817 updateLocal(bv, FULL, false);
2820 while (!tabular->IsLastCell(actcell)) {
2822 inset = tabular->GetCellInset(actcell);
2823 if (inset->nextChange(bv, length)) {
2824 updateLocal(bv, FULL, false);
2832 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2835 if (the_locking_inset) {
2836 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2837 updateLocal(bv, CELL, false);
2840 if (tabular->IsLastCell(actcell))
2844 InsetText * inset = tabular->GetCellInset(actcell);
2845 if (inset->searchForward(bv, str, cs, mw)) {
2846 updateLocal(bv, FULL, false);
2849 while (!tabular->IsLastCell(actcell)) {
2851 inset = tabular->GetCellInset(actcell);
2852 if (inset->searchForward(bv, str, cs, mw)) {
2853 updateLocal(bv, FULL, false);
2861 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2864 if (the_locking_inset) {
2865 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2866 updateLocal(bv, CELL, false);
2871 actcell = tabular->GetNumberOfCells();
2875 InsetText * inset = tabular->GetCellInset(actcell);
2876 if (inset->searchBackward(bv, str, cs, mw)) {
2877 updateLocal(bv, CELL, false);
2885 bool InsetTabular::insetAllowed(Inset::Code code) const
2887 if (the_locking_inset)
2888 return the_locking_inset->insetAllowed(code);
2889 // we return true here because if the inset is not locked someone
2890 // wants to insert something in one of our insettexts and we generally
2896 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2898 const int cell = tabular->GetCellFromInset(in, actcell);
2901 return tabular->GetPWidth(cell).zero();
2903 // well we didn't obviously find it so maybe our owner knows more
2905 return owner()->forceDefaultParagraphs(in);
2906 // if we're here there is really something strange going on!!!
2910 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2913 if (buf.length() <= 0)
2919 string::size_type len = buf.length();
2920 string::size_type p = 0;
2923 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2932 maxCols = max(cols, maxCols);
2938 maxCols = max(cols, maxCols);
2939 LyXTabular * loctab;
2944 delete paste_tabular;
2945 paste_tabular = new LyXTabular(bv->buffer()->params,
2946 this, rows, maxCols);
2947 loctab = paste_tabular;
2950 loctab = tabular.get();
2956 string::size_type op = 0;
2957 int cells = loctab->GetNumberOfCells();
2960 rows = loctab->rows();
2961 int const columns = loctab->columns();
2963 while ((cell < cells) && (p < len) && (row < rows) &&
2964 (p = buf.find_first_of("\t\n", p)) != string::npos)
2970 // we can only set this if we are not too far right
2971 if (cols < columns) {
2972 InsetText * ti = loctab->GetCellInset(cell);
2973 LyXFont const font = ti->getLyXText(bv)->
2974 getFont(bv->buffer(), ti->paragraph(), 0);
2975 ti->setText(buf.substr(op, p-op), font);
2981 // we can only set this if we are not too far right
2982 if (cols < columns) {
2983 InsetText * ti = loctab->GetCellInset(cell);
2984 LyXFont const font = ti->getLyXText(bv)->
2985 getFont(bv->buffer(), ti->paragraph(), 0);
2986 ti->setText(buf.substr(op, p-op), font);
2991 cell = loctab->GetCellNumber(row, cols);
2997 // check for the last cell if there is no trailing '\n'
2998 if ((cell < cells) && (op < len)) {
2999 InsetText * ti = loctab->GetCellInset(cell);
3000 LyXFont const font = ti->getLyXText(bv)->
3001 getFont(bv->buffer(), ti->paragraph(), 0);
3002 ti->setText(buf.substr(op, len-op), font);
3009 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
3011 int const rows = tabular->rows();
3012 int const columns = tabular->columns();
3013 for (int i = 0; i < rows; ++i) {
3014 for (int j = 0; j < columns; ++j) {
3015 tabular->GetCellInset(i,j)->addPreview(loader);