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 #include "insettabular.h"
15 #include "insettext.h"
18 #include "BufferView.h"
19 #include "commandtags.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
27 #include "lyxlength.h"
30 #include "ParagraphParameters.h"
31 #include "undo_funcs.h"
32 #include "WordLangTuple.h"
34 #include "frontends/Alert.h"
35 #include "frontends/Dialogs.h"
36 #include "frontends/font_metrics.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/Painter.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::ALIGN_BLOCK, "align-block" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
125 bool InsetTabular::hasPasteBuffer() const
127 return (paste_tabular != 0);
131 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
138 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
139 // for now make it always display as display() inset
141 the_locking_inset = 0;
142 old_locking_inset = 0;
145 actrow = actcell = 0;
155 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
157 : UpdatableInset(tab, same_id), buffer(&buf)
159 tabular.reset(new LyXTabular(buf.params,
160 this, *(tab.tabular), same_id));
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
175 InsetTabular::~InsetTabular()
181 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
183 return new InsetTabular(*this, buf, same_id);
187 void InsetTabular::write(Buffer const * buf, ostream & os) const
189 os << " Tabular" << endl;
190 tabular->Write(buf, os);
194 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
196 bool const old_format = (lex.getString() == "\\LyXTable");
198 tabular.reset(new LyXTabular(buf, this, lex));
206 string token = lex.getString();
207 while (lex.isOK() && (token != "\\end_inset")) {
209 token = lex.getString();
211 if (token != "\\end_inset") {
212 lex.printError("Missing \\end_inset at this point. "
218 int InsetTabular::ascent(BufferView *, LyXFont const &) const
220 return tabular->GetAscentOfRow(0);
224 int InsetTabular::descent(BufferView *, LyXFont const &) const
226 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
230 int InsetTabular::width(BufferView *, LyXFont const &) const
232 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
236 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
237 float & x, bool cleared) const
245 if (need_update == INIT) {
246 if (calculate_dimensions_of_cells(bv, font, true))
247 bv->text->status = LyXText::CHANGED_IN_DRAW;
252 Painter & pain = bv->painter();
258 UpdatableInset::draw(bv, font, baseline, x, cleared);
261 x += static_cast<float>(scroll());
263 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
264 (top_x != int(x)) || (top_baseline != baseline)))
266 int h = ascent(bv, font) + descent(bv, font);
267 int const tx = display() || !owner() ? 0 : top_x;
268 int w = tx ? width(bv, font) : pain.paperWidth();
269 int ty = baseline - ascent(bv, font);
273 if ((ty + h) > pain.paperHeight())
274 h = pain.paperHeight();
275 if ((top_x + w) > pain.paperWidth())
276 w = pain.paperWidth();
277 pain.fillRectangle(tx, ty, w, h, backgroundColor());
283 top_baseline = baseline;
284 x += ADD_TO_TABULAR_WIDTH;
288 first_visible_cell = -1;
289 for (i = 0; i < tabular->rows(); ++i) {
291 cell = tabular->GetCellNumber(i, 0);
292 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
293 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
295 baseline += tabular->GetDescentOfRow(i) +
296 tabular->GetAscentOfRow(i + 1) +
297 tabular->GetAdditionalHeight(i + 1);
300 for (j = 0; j < tabular->columns(); ++j) {
301 if (nx > bv->workWidth())
303 if (tabular->IsPartOfMultiColumn(i, j))
305 cx = nx + tabular->GetBeginningOfTextInCell(cell);
306 if (first_visible_cell < 0)
307 first_visible_cell = cell;
308 if (hasSelection()) {
309 drawCellSelection(pain, nx, baseline, i, j, cell);
312 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
313 drawCellLines(pain, nx, baseline, i, cell);
314 nx += tabular->GetWidthOfColumn(cell);
317 baseline += tabular->GetDescentOfRow(i) +
318 tabular->GetAscentOfRow(i + 1) +
319 tabular->GetAdditionalHeight(i + 1);
321 } else if (need_update == CELL) {
324 if (the_locking_inset &&
325 tabular->GetCellInset(actcell) != the_locking_inset)
327 Inset * inset = tabular->GetCellInset(cell);
329 inset != the_locking_inset && i < tabular->rows();
333 inset != the_locking_inset && j < tabular->columns();
336 if (tabular->IsPartOfMultiColumn(i, j))
338 nx += tabular->GetWidthOfColumn(cell);
340 inset = tabular->GetCellInset(cell);
342 if (tabular->row_of_cell(cell) > i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
350 // compute baseline for actual row
351 for (i = 0; i < actrow; ++i) {
352 baseline += tabular->GetDescentOfRow(i) +
353 tabular->GetAscentOfRow(i + 1) +
354 tabular->GetAdditionalHeight(i + 1);
356 // now compute the right x position
357 cell = tabular->GetCellNumber(actrow, 0);
358 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
359 if (tabular->IsPartOfMultiColumn(actrow, j))
361 nx += tabular->GetWidthOfColumn(cell);
365 i = tabular->row_of_cell(cell);
366 if (the_locking_inset != tabular->GetCellInset(cell)) {
367 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
370 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
372 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
374 // Here we use rectangular backgroundColor patches to clean up
375 // within a cell around the cell's red inset box. As follows:
377 // +--------------------+
378 // | C | The rectangles are A, B and C
379 // | A |------------| B | below, origin top left (tx, ty),
380 // | | inset box | | dimensions w(idth), h(eight).
381 // +---+------------+---+ x grows rightward, y downward
383 // +--------------------+
386 // clear only if we didn't have a change
387 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
389 // clear before the inset
392 ty = baseline - tabular->GetAscentOfRow(i) + 1;
393 w = int(cx - nx - 1);
394 h = tabular->GetAscentOfRow(i) +
395 tabular->GetDescentOfRow(i) - 1;
396 pain.fillRectangle(tx, ty, w, h, backgroundColor());
397 // clear behind the inset
398 tx = int(cx + the_locking_inset->width(bv,font) + 1);
399 ty = baseline - tabular->GetAscentOfRow(i) + 1;
400 w = tabular->GetWidthOfColumn(cell) -
401 tabular->GetBeginningOfTextInCell(cell) -
402 the_locking_inset->width(bv,font) -
403 tabular->GetAdditionalWidth(cell) - 1;
404 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
405 pain.fillRectangle(tx, ty, w, h, backgroundColor());
406 // clear below the inset
408 ty = baseline + the_locking_inset->descent(bv, font) + 1;
409 w = tabular->GetWidthOfColumn(cell) -
410 tabular->GetAdditionalWidth(cell) - 1;
411 h = tabular->GetDescentOfRow(i) -
412 the_locking_inset->descent(bv, font) - 1;
413 pain.fillRectangle(tx, ty, w, h, backgroundColor());
414 // clear above the inset
416 ty = baseline - tabular->GetAscentOfRow(i) + 1;
417 w = tabular->GetWidthOfColumn(cell) -
418 tabular->GetAdditionalWidth(cell) - 1;
419 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
420 pain.fillRectangle(tx, ty, w, h, backgroundColor());
425 x -= ADD_TO_TABULAR_WIDTH;
426 x += width(bv, font);
427 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
429 for(Inset * inset = owner(); inset; ++i)
430 inset = inset->owner();
431 if (calculate_dimensions_of_cells(bv, font, false))
439 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
440 int row, int cell) const
442 int x2 = x + tabular->GetWidthOfColumn(cell);
445 if (!tabular->topAlreadyDrawn(cell)) {
446 on_off = !tabular->TopLine(cell);
447 pain.line(x, baseline - tabular->GetAscentOfRow(row),
448 x2, baseline - tabular->GetAscentOfRow(row),
449 on_off ? LColor::tabularonoffline : LColor::tabularline,
450 on_off ? Painter::line_onoffdash : Painter::line_solid);
452 on_off = !tabular->BottomLine(cell);
453 pain.line(x, baseline + tabular->GetDescentOfRow(row),
454 x2, baseline + tabular->GetDescentOfRow(row),
455 on_off ? LColor::tabularonoffline : LColor::tabularline,
456 on_off ? Painter::line_onoffdash : Painter::line_solid);
457 if (!tabular->leftAlreadyDrawn(cell)) {
458 on_off = !tabular->LeftLine(cell);
459 pain.line(x, baseline - tabular->GetAscentOfRow(row),
460 x, baseline + tabular->GetDescentOfRow(row),
461 on_off ? LColor::tabularonoffline : LColor::tabularline,
462 on_off ? Painter::line_onoffdash : Painter::line_solid);
464 on_off = !tabular->RightLine(cell);
465 pain.line(x2 - tabular->GetAdditionalWidth(cell),
466 baseline - tabular->GetAscentOfRow(row),
467 x2 - tabular->GetAdditionalWidth(cell),
468 baseline + tabular->GetDescentOfRow(row),
469 on_off ? LColor::tabularonoffline : LColor::tabularline,
470 on_off ? Painter::line_onoffdash : Painter::line_solid);
474 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
475 int row, int column, int cell) const
477 lyx::Assert(hasSelection());
478 int cs = tabular->column_of_cell(sel_cell_start);
479 int ce = tabular->column_of_cell(sel_cell_end);
482 cs = tabular->column_of_cell(sel_cell_end);
484 ce = tabular->right_column_of_cell(sel_cell_end);
487 int rs = tabular->row_of_cell(sel_cell_start);
488 int re = tabular->row_of_cell(sel_cell_end);
492 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
493 int w = tabular->GetWidthOfColumn(cell);
494 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
495 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
496 w, h, LColor::selection);
501 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
507 owner()->update(bv, font, true);
514 if (calculate_dimensions_of_cells(bv, font, true))
517 owner()->update(bv, font, true);
521 if (the_locking_inset)
522 the_locking_inset->update(bv, font, reinit);
523 if (need_update < FULL &&
524 bv->text->status() == LyXText::NEED_MORE_REFRESH)
529 switch (need_update) {
533 if (calculate_dimensions_of_cells(bv, font, false)) {
548 string const InsetTabular::editMessage() const
550 return _("Opened Tabular Inset");
554 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
556 UpdatableInset::edit(bv, x, y, button);
558 if (!bv->lockInset(this)) {
559 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
563 the_locking_inset = 0;
569 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
570 activateCellInsetAbs(bv, x, y, button);
575 void InsetTabular::edit(BufferView * bv, bool front)
577 UpdatableInset::edit(bv, front);
579 if (!bv->lockInset(this)) {
580 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
585 the_locking_inset = 0;
589 if (isRightToLeft(bv))
590 actcell = tabular->GetLastCellInRow(0);
594 if (isRightToLeft(bv))
595 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
597 actcell = tabular->GetNumberOfCells() - 1;
605 void InsetTabular::insetUnlock(BufferView * bv)
607 if (the_locking_inset) {
608 the_locking_inset->insetUnlock(bv);
609 updateLocal(bv, CELL, false);
610 the_locking_inset = 0;
616 if (scroll(false) || hasSelection()) {
621 updateLocal(bv, FULL, false);
626 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
627 bool mark_dirty) const
631 calculate_dimensions_of_cells(bv, font, true);
633 if (!locked && what == CELL)
635 if (need_update < what) // only set this if it has greater update
638 if (need_update != NONE) {
639 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
646 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
648 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
653 if (inset == tabular->GetCellInset(actcell)) {
654 lyxerr[Debug::INSETTEXT] << "OK" << endl;
655 the_locking_inset = tabular->GetCellInset(actcell);
658 } else if (!the_locking_inset) {
659 int const n = tabular->GetNumberOfCells();
660 int const id = inset->id();
661 for (int i = 0; i < n; ++i) {
662 InsetText * in = tabular->GetCellInset(i);
665 the_locking_inset = in;
670 if (in->getInsetFromID(id)) {
673 return the_locking_inset->lockInsetInInset(bv, inset);
676 } else if (the_locking_inset && (the_locking_inset == inset)) {
677 lyxerr[Debug::INSETTEXT] << "OK" << endl;
679 } else if (the_locking_inset) {
680 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
681 return the_locking_inset->lockInsetInInset(bv, inset);
683 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
688 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
691 if (!the_locking_inset)
693 if (the_locking_inset == inset) {
694 the_locking_inset->insetUnlock(bv);
696 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
702 updateLocal(bv, CELL, false);
703 // this has to be here otherwise we don't redraw the cell!
704 the_locking_inset = 0;
705 // showInsetCursor(bv, false);
708 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
709 if (inset->lyxCode() == TABULAR_CODE &&
710 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
711 bv->owner()->getDialogs().updateTabular(this);
720 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
722 Inset * tl_inset = inset;
723 // look if this inset is really inside myself!
724 while(tl_inset->owner() && tl_inset->owner() != this)
725 tl_inset = tl_inset->owner();
726 // if we enter here it's not ower inset
727 if (!tl_inset->owner())
729 // we only have to do this if this is a subinset of our cells
730 if (tl_inset != inset) {
731 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
734 updateLocal(bv, CELL, false);
739 int InsetTabular::insetInInsetY() const
741 if (!the_locking_inset)
743 return inset_y + the_locking_inset->insetInInsetY();
747 UpdatableInset * InsetTabular::getLockingInset() const
749 return the_locking_inset ? the_locking_inset->getLockingInset() :
750 const_cast<InsetTabular *>(this);
754 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
758 if (the_locking_inset)
759 return the_locking_inset->getFirstLockingInsetOfType(c);
764 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
766 if (the_locking_inset)
767 return the_locking_inset->insertInset(bv, inset);
772 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
774 if (hasSelection() && cmd.button() == mouse_button::button3)
777 if (hasSelection()) {
779 updateLocal(cmd.view(), SELECTION, false);
782 int const ocell = actcell;
783 int const orow = actrow;
784 BufferView * bv = cmd.view();
789 the_locking_inset = 0;
793 setPos(bv, cmd.x, cmd.y);
795 updateLocal(bv, NONE, false);
798 if (cmd.button() == mouse_button::button3) {
799 if ((ocell != actcell) && the_locking_inset) {
800 the_locking_inset->insetUnlock(bv);
801 updateLocal(bv, CELL, false);
802 the_locking_inset = 0;
809 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
811 if ((ocell == actcell) && the_locking_inset && inset_hit) {
813 FuncRequest cmd1 = cmd;
816 the_locking_inset->localDispatch(cmd1);
820 if (the_locking_inset) {
821 the_locking_inset->insetUnlock(bv);
822 updateLocal(bv, CELL, false);
823 the_locking_inset = 0;
826 if (cmd.button() == mouse_button::button2) {
827 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
831 if (inset_hit && bv->theLockingInset()) {
832 if (!bv->lockInset(static_cast<UpdatableInset*>
833 (tabular->GetCellInset(actcell))))
835 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
838 FuncRequest cmd1 = cmd;
841 the_locking_inset->localDispatch(cmd1);
848 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
851 if (the_locking_inset) {
852 FuncRequest cmd1 = cmd;
855 ret = the_locking_inset->localDispatch(cmd1);
857 if (cmd.button() == mouse_button::button3 && !ret) {
858 cmd.view()->owner()->getDialogs().showTabular(this);
865 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
867 if (the_locking_inset) {
868 FuncRequest cmd1 = cmd;
871 the_locking_inset->localDispatch(cmd1);
875 BufferView * bv = cmd.view();
877 int const old_cell = actcell;
879 setPos(bv, cmd.x, cmd.y);
880 if (!hasSelection()) {
881 setSelection(actcell, actcell);
882 updateLocal(bv, SELECTION, false);
883 } else if (old_cell != actcell) {
884 setSelection(sel_cell_start, actcell);
885 updateLocal(bv, SELECTION, false);
891 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
893 // We need to save the value of the_locking_inset as the call to
894 // the_locking_inset->localDispatch might unlock it.
895 old_locking_inset = the_locking_inset;
896 RESULT result = UpdatableInset::localDispatch(cmd);
898 BufferView * bv = cmd.view();
899 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
904 if (cmd.action < 0 && cmd.argument.empty())
907 bool hs = hasSelection();
910 // this one have priority over the locked InsetText, if we're not already
911 // inside another tabular then that one get's priority!
912 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
913 switch (cmd.action) {
914 case LFUN_MOUSE_PRESS:
918 case LFUN_MOUSE_MOTION:
919 lfunMouseMotion(cmd);
922 case LFUN_MOUSE_RELEASE:
923 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
928 unlockInsetInInset(bv, the_locking_inset);
929 if (cmd.action == LFUN_TAB)
930 moveNextCell(bv, old_locking_inset != 0);
932 movePrevCell(bv, old_locking_inset != 0);
935 updateLocal(bv, SELECTION, false);
936 if (!the_locking_inset) {
938 return DISPATCHED_NOUPDATE;
941 // this to avoid compiler warnings.
947 kb_action action = cmd.action;
948 string arg = cmd.argument;
949 if (the_locking_inset) {
950 result = the_locking_inset->localDispatch(cmd);
951 if (result == DISPATCHED_NOUPDATE) {
954 if (sc != scroll()) { // inset has been scrolled
955 the_locking_inset->toggleInsetCursor(bv);
956 updateLocal(bv, FULL, false);
957 the_locking_inset->toggleInsetCursor(bv);
960 } else if (result == DISPATCHED) {
961 the_locking_inset->toggleInsetCursor(bv);
962 updateLocal(bv, CELL, false);
963 the_locking_inset->toggleInsetCursor(bv);
965 } else if (result == FINISHED_UP) {
967 } else if (result == FINISHED_DOWN) {
969 } else if (result == FINISHED_RIGHT) {
977 // --- Cursor Movements ----------------------------------
978 case LFUN_RIGHTSEL: {
979 int const start = hasSelection() ? sel_cell_start : actcell;
980 if (tabular->IsLastCellInRow(actcell)) {
981 setSelection(start, actcell);
986 // if we are starting a selection, only select
987 // the current cell at the beginning
988 if (hasSelection()) {
989 moveRight(bv, false);
992 setSelection(start, end);
993 updateLocal(bv, SELECTION, false);
997 result = moveRight(bv);
1000 updateLocal(bv, SELECTION, false);
1002 case LFUN_LEFTSEL: {
1003 int const start = hasSelection() ? sel_cell_start : actcell;
1004 if (tabular->IsFirstCellInRow(actcell)) {
1005 setSelection(start, actcell);
1010 // if we are starting a selection, only select
1011 // the current cell at the beginning
1012 if (hasSelection()) {
1013 moveLeft(bv, false);
1016 setSelection(start, end);
1017 updateLocal(bv, SELECTION, false);
1021 result = moveLeft(bv);
1024 updateLocal(bv, SELECTION, false);
1026 case LFUN_DOWNSEL: {
1027 int const start = hasSelection() ? sel_cell_start : actcell;
1028 int const ocell = actcell;
1029 // if we are starting a selection, only select
1030 // the current cell at the beginning
1031 if (hasSelection()) {
1032 moveDown(bv, false);
1033 if ((ocell == sel_cell_end) ||
1034 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1035 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1037 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1039 setSelection(start, start);
1041 updateLocal(bv, SELECTION, false);
1045 result = moveDown(bv, old_locking_inset != 0);
1048 updateLocal(bv, SELECTION, false);
1052 int const start = hasSelection() ? sel_cell_start : actcell;
1053 int const ocell = actcell;
1054 // if we are starting a selection, only select
1055 // the current cell at the beginning
1056 if (hasSelection()) {
1058 if ((ocell == sel_cell_end) ||
1059 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1060 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1062 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1064 setSelection(start, start);
1066 updateLocal(bv, SELECTION, false);
1070 result = moveUp(bv, old_locking_inset != 0);
1073 updateLocal(bv, SELECTION, false);
1076 UpdateCodes code = CURSOR;
1081 int column = actcol;
1082 unlockInsetInInset(bv, the_locking_inset);
1083 if (bv->text->top_y() + bv->painter().paperHeight() <
1084 (top_baseline + tabular->GetHeightOfTabular()))
1086 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
1088 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1090 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1093 updateLocal(bv, code, false);
1097 UpdateCodes code = CURSOR;
1102 int column = actcol;
1103 unlockInsetInInset(bv, the_locking_inset);
1104 if (top_baseline < 0) {
1105 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
1107 if (top_baseline > 0)
1110 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1115 updateLocal(bv, code, false);
1118 // none of these make sense for insettabular,
1119 // but we must catch them to prevent any
1120 // selection from being confused
1124 case LFUN_WORDLEFTSEL:
1125 case LFUN_WORDRIGHT:
1126 case LFUN_WORDRIGHTSEL:
1128 case LFUN_DOWN_PARAGRAPH:
1129 case LFUN_DOWN_PARAGRAPHSEL:
1130 case LFUN_UP_PARAGRAPH:
1131 case LFUN_UP_PARAGRAPHSEL:
1132 case LFUN_BACKSPACE:
1137 case LFUN_BEGINNINGBUF:
1138 case LFUN_BEGINNINGBUFSEL:
1140 case LFUN_ENDBUFSEL:
1142 case LFUN_LAYOUT_TABULAR:
1143 bv->owner()->getDialogs().showTabular(this);
1145 case LFUN_TABULAR_FEATURE:
1146 if (!tabularFeatures(bv, arg))
1147 result = UNDISPATCHED;
1149 // insert file functions
1150 case LFUN_FILE_INSERT_ASCII_PARA:
1151 case LFUN_FILE_INSERT_ASCII:
1153 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1156 if (insertAsciiString(bv, tmpstr, false))
1157 updateLocal(bv, INIT, true);
1159 result = UNDISPATCHED;
1162 // cut and paste functions
1164 if (!copySelection(bv))
1168 setUndo(bv, Undo::DELETE,
1169 bv->text->cursor.par(),
1170 bv->text->cursor.par()->next());
1171 cutSelection(bv->buffer()->params);
1172 updateLocal(bv, INIT, true);
1175 if (!hasSelection())
1180 case LFUN_PASTESELECTION:
1182 string const clip(bv->getClipboard());
1186 if (clip.find('\t') != string::npos) {
1190 string::size_type len = clip.length();
1191 string::size_type p = 0;
1194 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1202 maxCols = max(cols, maxCols);
1208 maxCols = max(cols, maxCols);
1209 delete paste_tabular;
1210 paste_tabular = new LyXTabular(bv->buffer()->params,
1211 this, rows, maxCols);
1212 string::size_type op = 0;
1214 int cells = paste_tabular->GetNumberOfCells();
1216 while ((cell < cells) && (p < len) &&
1217 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1222 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1227 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1228 while (cols++ < maxCols)
1236 // check for the last cell if there is no trailing '\n'
1237 if ((cell < cells) && (op < len))
1238 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1241 if (!insertAsciiString(bv, clip, true))
1244 // so that the clipboard is used and it goes on
1246 // and executes LFUN_PASTESELECTION in insettext!
1247 delete paste_tabular;
1252 if (hasPasteBuffer()) {
1253 setUndo(bv, Undo::INSERT,
1254 bv->text->cursor.par(),
1255 bv->text->cursor.par()->next());
1257 updateLocal(bv, INIT, true);
1260 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1262 // handle font changing stuff on selection before we lock the inset
1263 // in the default part!
1264 result = UNDISPATCHED;
1275 case LFUN_UNDERLINE:
1276 case LFUN_FONT_SIZE:
1277 if (bv->dispatch(FuncRequest(bv, action, arg)))
1278 result = DISPATCHED;
1284 // we try to activate the actual inset and put this event down to
1285 // the insets dispatch function.
1286 if ((result == DISPATCHED) || the_locking_inset)
1289 if (activateCellInset(bv)) {
1290 // reset need_update setted in above function!
1292 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1293 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1294 unlockInsetInInset(bv, the_locking_inset);
1296 // we need to update if this was requested before
1297 updateLocal(bv, NONE, false);
1298 return UNDISPATCHED;
1301 // so the below CELL is not set because this is higher
1302 // priority and we get a full redraw
1303 need_update = SELECTION;
1306 updateLocal(bv, CELL, false);
1311 if (result < FINISHED) {
1312 if (!the_locking_inset) {
1313 if (bv->fitCursor())
1314 updateLocal(bv, FULL, false);
1316 showInsetCursor(bv);
1319 bv->unlockInset(this);
1324 int InsetTabular::latex(Buffer const * buf, ostream & os,
1325 bool fragile, bool fp) const
1327 return tabular->latex(buf, os, fragile, fp);
1331 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1334 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1336 return tabular->ascii(buf, os, 0, false,0);
1340 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1343 int const ret = tabular->ascii(buf,os,
1344 (int)parOwner()->params().depth(),
1351 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1356 // if the table is inside a float it doesn't need the informaltable
1357 // wrapper. Search for it.
1358 for(master = owner();
1359 master && master->lyxCode() != Inset::FLOAT_CODE;
1360 master = master->owner());
1363 os << "<informaltable>";
1368 ret+= tabular->docbook(buf, os, mixcont);
1370 os << "</informaltable>";
1379 void InsetTabular::validate(LaTeXFeatures & features) const
1381 tabular->Validate(features);
1385 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1386 LyXFont const & font,
1393 bool changed = false;
1395 // if we have a locking_inset we should have to check only this cell for
1396 // change so I'll try this to have a boost, but who knows ;)
1397 if ((need_update != INIT) &&
1398 (the_locking_inset == tabular->GetCellInset(actcell))) {
1399 for(int i = 0; i < tabular->columns(); ++i) {
1400 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1402 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1405 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1406 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1407 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1410 for (int i = 0; i < tabular->rows(); ++i) {
1413 for (int j = 0; j < tabular->columns(); ++j) {
1414 if (tabular->IsPartOfMultiColumn(i,j))
1417 inset = tabular->GetCellInset(cell);
1418 if (!reinit && !tabular->GetPWidth(cell).zero())
1419 inset->update(bv, font, false);
1420 maxAsc = max(maxAsc, inset->ascent(bv, font));
1421 maxDesc = max(maxDesc, inset->descent(bv, font));
1422 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1424 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1425 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1433 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1435 if (the_locking_inset) {
1436 the_locking_inset->getCursorPos(bv, x, y);
1439 x = cursor_.x() - top_x;
1444 void InsetTabular::toggleInsetCursor(BufferView * bv)
1447 if (isCursorVisible())
1448 bv->hideLockedInsetCursor();
1451 if (the_locking_inset) {
1452 the_locking_inset->toggleInsetCursor(bv);
1456 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1458 int const asc = font_metrics::maxAscent(font);
1459 int const desc = font_metrics::maxDescent(font);
1461 if (isCursorVisible())
1462 bv->hideLockedInsetCursor();
1464 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1465 toggleCursorVisible();
1469 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1473 if (!isCursorVisible()) {
1474 LyXFont font; // = GetFont(par, cursor.pos);
1476 int const asc = font_metrics::maxAscent(font);
1477 int const desc = font_metrics::maxDescent(font);
1478 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1480 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1481 setCursorVisible(true);
1486 void InsetTabular::hideInsetCursor(BufferView * bv)
1488 if (isCursorVisible()) {
1489 bv->hideLockedInsetCursor();
1490 setCursorVisible(false);
1495 void InsetTabular::fitInsetCursor(BufferView * bv) const
1497 if (the_locking_inset) {
1498 int old_top_y = bv->text->top_y();
1499 the_locking_inset->fitInsetCursor(bv);
1500 if (old_top_y != bv->text->top_y())
1506 int const asc = font_metrics::maxAscent(font);
1507 int const desc = font_metrics::maxDescent(font);
1510 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1515 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1519 actcell = actrow = actcol = 0;
1520 int ly = tabular->GetDescentOfRow(actrow);
1522 // first search the right row
1523 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1524 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1525 tabular->GetAscentOfRow(actrow + 1) +
1526 tabular->GetAdditionalHeight(actrow + 1));
1528 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1530 actcell = tabular->GetCellNumber(actrow, actcol);
1532 // now search the right column
1533 int lx = tabular->GetWidthOfColumn(actcell) -
1534 tabular->GetAdditionalWidth(actcell);
1535 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1536 lx += tabular->GetWidthOfColumn(actcell + 1)
1537 + tabular->GetAdditionalWidth(actcell);
1539 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1544 int InsetTabular::getCellXPos(int cell) const
1548 for (; !tabular->IsFirstCellInRow(c); --c)
1550 int lx = tabular->GetWidthOfColumn(cell);
1551 for (; c < cell; ++c) {
1552 lx += tabular->GetWidthOfColumn(c);
1554 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1558 void InsetTabular::resetPos(BufferView * bv) const
1560 #ifdef WITH_WARNINGS
1561 #warning This should be fixed in the right manner (20011128 Jug)
1563 // fast hack to fix infinite repaintings!
1564 if (in_reset_pos > 0)
1568 actcol = tabular->column_of_cell(actcell);
1571 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1572 if (tabular->IsLastCellInRow(cell)) {
1573 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1574 tabular->GetAscentOfRow(actrow + 1) +
1575 tabular->GetAdditionalHeight(actrow + 1));
1579 if (!locked || nodraw()) {
1580 if (the_locking_inset)
1581 inset_y = cursor_.y();
1584 // we need this only from here on!!!
1586 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1587 int new_x = getCellXPos(actcell);
1588 int old_x = cursor_.x();
1591 // cursor.x(getCellXPos(actcell) + offset);
1592 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1593 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1596 updateLocal(bv, FULL, false);
1597 } else if (the_locking_inset &&
1598 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1600 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1601 if (xx > (bv->workWidth()-20)) {
1602 scroll(bv, -(xx - bv->workWidth() + 60));
1603 updateLocal(bv, FULL, false);
1604 } else if (xx < 20) {
1610 updateLocal(bv, FULL, false);
1612 } else if ((cursor_.x() - offset) > 20 &&
1613 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1614 > (bv->workWidth() - 20)) {
1615 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1616 updateLocal(bv, FULL, false);
1617 } else if ((cursor_.x() - offset) < 20) {
1618 scroll(bv, 20 - cursor_.x() + offset);
1619 updateLocal(bv, FULL, false);
1620 } else if (scroll() && top_x > 20 &&
1621 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1622 scroll(bv, old_x - cursor_.x());
1623 updateLocal(bv, FULL, false);
1625 if (the_locking_inset) {
1626 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1627 inset_y = cursor_.y();
1629 if ((!the_locking_inset ||
1630 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1631 actcell != oldcell) {
1632 InsetTabular * inset = const_cast<InsetTabular *>(this);
1633 bv->owner()->getDialogs().updateTabular(inset);
1640 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1642 if (lock && !old_locking_inset) {
1643 if (activateCellInset(bv))
1646 bool moved = isRightToLeft(bv)
1647 ? movePrevCell(bv) : moveNextCell(bv);
1649 return FINISHED_RIGHT;
1650 if (lock && activateCellInset(bv))
1654 return DISPATCHED_NOUPDATE;
1658 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1660 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1663 if (lock) { // behind the inset
1664 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1668 return DISPATCHED_NOUPDATE;
1672 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1674 int const ocell = actcell;
1675 actcell = tabular->GetCellAbove(actcell);
1676 if (actcell == ocell) // we moved out of the inset
1682 if (old_locking_inset) {
1683 old_locking_inset->getCursorPos(bv, x, y);
1684 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1686 if (activateCellInset(bv, x, 0))
1689 return DISPATCHED_NOUPDATE;
1693 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1695 int const ocell = actcell;
1696 actcell = tabular->GetCellBelow(actcell);
1697 if (actcell == ocell) // we moved out of the inset
1698 return FINISHED_DOWN;
1703 if (old_locking_inset) {
1704 old_locking_inset->getCursorPos(bv, x, y);
1705 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1707 if (activateCellInset(bv, x, 0))
1710 return DISPATCHED_NOUPDATE;
1714 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1716 if (isRightToLeft(bv)) {
1717 if (tabular->IsFirstCellInRow(actcell)) {
1718 int row = tabular->row_of_cell(actcell);
1719 if (row == tabular->rows() - 1)
1721 actcell = tabular->GetLastCellInRow(row);
1722 actcell = tabular->GetCellBelow(actcell);
1729 if (tabular->IsLastCell(actcell))
1734 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1735 isRightToLeftPar(bv->buffer()->params);
1736 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1743 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1745 if (isRightToLeft(bv)) {
1746 if (tabular->IsLastCellInRow(actcell)) {
1747 int row = tabular->row_of_cell(actcell);
1750 actcell = tabular->GetFirstCellInRow(row);
1751 actcell = tabular->GetCellAbove(actcell);
1753 if (tabular->IsLastCell(actcell))
1758 if (!actcell) // first cell
1763 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1764 isRightToLeftPar(bv->buffer()->params);
1765 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1772 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1776 setSelection(0, tabular->GetNumberOfCells() - 1);
1778 if (hasSelection()) {
1779 setUndo(bv, Undo::EDIT,
1780 bv->text->cursor.par(),
1781 bv->text->cursor.par()->next());
1782 bool const frozen = undo_frozen;
1785 // apply the fontchange on the whole selection
1790 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1791 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1792 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1793 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1800 updateLocal(bv, INIT, true);
1802 if (the_locking_inset)
1803 the_locking_inset->setFont(bv, font, tall);
1807 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1809 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1812 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1813 string const tmp = tabularFeature[i].feature;
1815 if (tmp == what.substr(0, tmp.length())) {
1816 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1817 //tabularFeatures[i].feature.length())) {
1818 action = tabularFeature[i].action;
1822 if (action == LyXTabular::LAST_ACTION)
1826 ltrim(what.substr(tabularFeature[i].feature.length()));
1827 tabularFeatures(bv, action, val);
1833 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1834 string const & special, bool & flag)
1836 if (special == "dl_above") {
1839 } else if (special == "dl_below") {
1840 ltt.bottomDL = flag;
1842 } else if (special == "empty") {
1854 void InsetTabular::tabularFeatures(BufferView * bv,
1855 LyXTabular::Feature feature,
1856 string const & value)
1862 bool setLines = false;
1863 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1864 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1867 case LyXTabular::M_ALIGN_LEFT:
1868 case LyXTabular::ALIGN_LEFT:
1869 setAlign = LYX_ALIGN_LEFT;
1871 case LyXTabular::M_ALIGN_RIGHT:
1872 case LyXTabular::ALIGN_RIGHT:
1873 setAlign = LYX_ALIGN_RIGHT;
1875 case LyXTabular::M_ALIGN_CENTER:
1876 case LyXTabular::ALIGN_CENTER:
1877 setAlign = LYX_ALIGN_CENTER;
1879 case LyXTabular::ALIGN_BLOCK:
1880 setAlign = LYX_ALIGN_BLOCK;
1882 case LyXTabular::M_VALIGN_TOP:
1883 case LyXTabular::VALIGN_TOP:
1884 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1886 case LyXTabular::M_VALIGN_BOTTOM:
1887 case LyXTabular::VALIGN_BOTTOM:
1888 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1890 case LyXTabular::M_VALIGN_CENTER:
1891 case LyXTabular::VALIGN_CENTER:
1892 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1897 if (hasSelection()) {
1898 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1900 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1901 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1903 setUndo(bv, Undo::FINISH,
1904 bv->text->cursor.par(),
1905 bv->text->cursor.par()->next());
1907 int row = tabular->row_of_cell(actcell);
1908 int column = tabular->column_of_cell(actcell);
1910 LyXTabular::ltType ltt;
1913 case LyXTabular::SET_PWIDTH:
1915 LyXLength const vallen(value);
1916 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1918 bool const update = (tmplen != vallen);
1919 tabular->SetColumnPWidth(actcell, vallen);
1922 for (int i = 0; i < tabular->rows(); ++i) {
1923 cell = tabular->GetCellNumber(i,column);
1924 tabular->GetCellInset(cell)->resizeLyXText(bv);
1926 updateLocal(bv, INIT, true);
1930 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1931 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1932 else if (!vallen.zero()
1933 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1934 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1937 case LyXTabular::SET_MPWIDTH:
1939 LyXLength const vallen(value);
1940 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1942 bool const update = (tmplen != vallen);
1943 tabular->SetMColumnPWidth(actcell, vallen);
1945 for (int i = 0; i < tabular->rows(); ++i) {
1946 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1949 updateLocal(bv, INIT, true);
1953 case LyXTabular::SET_SPECIAL_COLUMN:
1954 case LyXTabular::SET_SPECIAL_MULTI:
1955 tabular->SetAlignSpecial(actcell,value,feature);
1956 updateLocal(bv, FULL, true);
1958 case LyXTabular::APPEND_ROW:
1959 // append the row into the tabular
1960 unlockInsetInInset(bv, the_locking_inset);
1961 tabular->AppendRow(bv->buffer()->params, actcell);
1962 updateLocal(bv, INIT, true);
1964 case LyXTabular::APPEND_COLUMN:
1965 // append the column into the tabular
1966 unlockInsetInInset(bv, the_locking_inset);
1967 tabular->AppendColumn(bv->buffer()->params, actcell);
1968 actcell = tabular->GetCellNumber(row, column);
1969 updateLocal(bv, INIT, true);
1971 case LyXTabular::DELETE_ROW:
1972 unlockInsetInInset(bv, the_locking_inset);
1973 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1974 tabular->DeleteRow(sel_row_start);
1976 if (sel_row_start >= tabular->rows())
1978 actcell = tabular->GetCellNumber(sel_row_start, column);
1980 updateLocal(bv, INIT, true);
1982 case LyXTabular::DELETE_COLUMN:
1983 unlockInsetInInset(bv, the_locking_inset);
1984 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1985 tabular->DeleteColumn(sel_col_start);
1987 if (sel_col_start >= tabular->columns())
1989 actcell = tabular->GetCellNumber(row, sel_col_start);
1991 updateLocal(bv, INIT, true);
1993 case LyXTabular::M_TOGGLE_LINE_TOP:
1995 case LyXTabular::TOGGLE_LINE_TOP:
1997 bool lineSet = !tabular->TopLine(actcell, flag);
1998 for (int i = sel_row_start; i <= sel_row_end; ++i)
1999 for (int j = sel_col_start; j <= sel_col_end; ++j)
2000 tabular->SetTopLine(
2001 tabular->GetCellNumber(i, j),
2003 updateLocal(bv, INIT, true);
2007 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2009 case LyXTabular::TOGGLE_LINE_BOTTOM:
2011 bool lineSet = !tabular->BottomLine(actcell, flag);
2012 for (int i = sel_row_start; i <= sel_row_end; ++i)
2013 for (int j = sel_col_start; j <= sel_col_end; ++j)
2014 tabular->SetBottomLine(
2015 tabular->GetCellNumber(i, j),
2018 updateLocal(bv, INIT, true);
2022 case LyXTabular::M_TOGGLE_LINE_LEFT:
2024 case LyXTabular::TOGGLE_LINE_LEFT:
2026 bool lineSet = !tabular->LeftLine(actcell, flag);
2027 for (int i = sel_row_start; i <= sel_row_end; ++i)
2028 for (int j = sel_col_start; j <= sel_col_end; ++j)
2029 tabular->SetLeftLine(
2030 tabular->GetCellNumber(i,j),
2033 updateLocal(bv, INIT, true);
2037 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2039 case LyXTabular::TOGGLE_LINE_RIGHT:
2041 bool lineSet = !tabular->RightLine(actcell, flag);
2042 for (int i = sel_row_start; i <= sel_row_end; ++i)
2043 for (int j = sel_col_start; j <= sel_col_end; ++j)
2044 tabular->SetRightLine(
2045 tabular->GetCellNumber(i,j),
2048 updateLocal(bv, INIT, true);
2052 case LyXTabular::M_ALIGN_LEFT:
2053 case LyXTabular::M_ALIGN_RIGHT:
2054 case LyXTabular::M_ALIGN_CENTER:
2056 case LyXTabular::ALIGN_LEFT:
2057 case LyXTabular::ALIGN_RIGHT:
2058 case LyXTabular::ALIGN_CENTER:
2059 case LyXTabular::ALIGN_BLOCK:
2060 for (int i = sel_row_start; i <= sel_row_end; ++i)
2061 for (int j = sel_col_start; j <= sel_col_end; ++j)
2062 tabular->SetAlignment(
2063 tabular->GetCellNumber(i, j),
2066 updateLocal(bv, INIT, true);
2068 case LyXTabular::M_VALIGN_TOP:
2069 case LyXTabular::M_VALIGN_BOTTOM:
2070 case LyXTabular::M_VALIGN_CENTER:
2072 case LyXTabular::VALIGN_TOP:
2073 case LyXTabular::VALIGN_BOTTOM:
2074 case LyXTabular::VALIGN_CENTER:
2075 for (int i = sel_row_start; i <= sel_row_end; ++i)
2076 for (int j = sel_col_start; j <= sel_col_end; ++j)
2077 tabular->SetVAlignment(
2078 tabular->GetCellNumber(i, j),
2080 updateLocal(bv, INIT, true);
2082 case LyXTabular::MULTICOLUMN:
2084 if (sel_row_start != sel_row_end) {
2085 Alert::alert(_("Impossible operation!"),
2086 _("Multicolumns can only be horizontally."),
2090 // just multicol for one Single Cell
2091 if (!hasSelection()) {
2092 // check wether we are completly in a multicol
2093 if (tabular->IsMultiColumn(actcell)) {
2094 tabular->UnsetMultiColumn(actcell);
2095 updateLocal(bv, INIT, true);
2097 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2098 updateLocal(bv, CELL, true);
2102 // we have a selection so this means we just add all this
2103 // cells to form a multicolumn cell
2107 if (sel_cell_start > sel_cell_end) {
2108 s_start = sel_cell_end;
2109 s_end = sel_cell_start;
2111 s_start = sel_cell_start;
2112 s_end = sel_cell_end;
2114 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2117 updateLocal(bv, INIT, true);
2120 case LyXTabular::SET_ALL_LINES:
2122 case LyXTabular::UNSET_ALL_LINES:
2123 for (int i = sel_row_start; i <= sel_row_end; ++i)
2124 for (int j = sel_col_start; j <= sel_col_end; ++j)
2125 tabular->SetAllLines(
2126 tabular->GetCellNumber(i,j), setLines);
2127 updateLocal(bv, INIT, true);
2129 case LyXTabular::SET_LONGTABULAR:
2130 tabular->SetLongTabular(true);
2131 updateLocal(bv, INIT, true); // because this toggles displayed
2133 case LyXTabular::UNSET_LONGTABULAR:
2134 tabular->SetLongTabular(false);
2135 updateLocal(bv, INIT, true); // because this toggles displayed
2137 case LyXTabular::SET_ROTATE_TABULAR:
2138 tabular->SetRotateTabular(true);
2140 case LyXTabular::UNSET_ROTATE_TABULAR:
2141 tabular->SetRotateTabular(false);
2143 case LyXTabular::SET_ROTATE_CELL:
2144 for (int i = sel_row_start; i <= sel_row_end; ++i)
2145 for (int j = sel_col_start; j<=sel_col_end; ++j)
2146 tabular->SetRotateCell(
2147 tabular->GetCellNumber(i, j),
2150 case LyXTabular::UNSET_ROTATE_CELL:
2151 for (int i = sel_row_start; i <= sel_row_end; ++i)
2152 for (int j = sel_col_start; j <= sel_col_end; ++j)
2153 tabular->SetRotateCell(
2154 tabular->GetCellNumber(i, j), false);
2156 case LyXTabular::SET_USEBOX:
2158 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2159 if (val == tabular->GetUsebox(actcell))
2160 val = LyXTabular::BOX_NONE;
2161 for (int i = sel_row_start; i <= sel_row_end; ++i)
2162 for (int j = sel_col_start; j <= sel_col_end; ++j)
2164 tabular->GetCellNumber(i, j), val);
2167 case LyXTabular::UNSET_LTFIRSTHEAD:
2169 case LyXTabular::SET_LTFIRSTHEAD:
2170 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2171 checkLongtableSpecial(ltt, value, flag);
2172 tabular->SetLTHead(row, flag, ltt, true);
2174 case LyXTabular::UNSET_LTHEAD:
2176 case LyXTabular::SET_LTHEAD:
2177 (void)tabular->GetRowOfLTHead(row, ltt);
2178 checkLongtableSpecial(ltt, value, flag);
2179 tabular->SetLTHead(row, flag, ltt, false);
2181 case LyXTabular::UNSET_LTFOOT:
2183 case LyXTabular::SET_LTFOOT:
2184 (void)tabular->GetRowOfLTFoot(row, ltt);
2185 checkLongtableSpecial(ltt, value, flag);
2186 tabular->SetLTFoot(row, flag, ltt, false);
2188 case LyXTabular::UNSET_LTLASTFOOT:
2190 case LyXTabular::SET_LTLASTFOOT:
2191 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2192 checkLongtableSpecial(ltt, value, flag);
2193 tabular->SetLTFoot(row, flag, ltt, true);
2195 case LyXTabular::SET_LTNEWPAGE:
2197 bool what = !tabular->GetLTNewPage(row);
2198 tabular->SetLTNewPage(row, what);
2201 // dummy stuff just to avoid warnings
2202 case LyXTabular::LAST_ACTION:
2208 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2211 UpdatableInset * inset =
2212 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2213 LyXFont font(LyXFont::ALL_SANE);
2215 x = inset->x() + inset->width(bv, font);
2216 y = inset->descent(bv, font);
2218 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2219 //inset_y = cursor.y();
2220 inset->edit(bv, x, y, button);
2221 if (!the_locking_inset)
2223 updateLocal(bv, CELL, false);
2224 return (the_locking_inset != 0);
2228 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2229 mouse_button::state button)
2231 inset_x = cursor_.x()
2232 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2233 inset_y = cursor_.y();
2234 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2238 bool InsetTabular::insetHit(BufferView *, int x, int) const
2241 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2245 // This returns paperWidth() if the cell-width is unlimited or the width
2246 // in pixels if we have a pwidth for this cell.
2247 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2249 LyXLength const len = tabular->GetPWidth(cell);
2253 return len.inPixels(latexTextWidth(bv));
2257 int InsetTabular::getMaxWidth(BufferView * bv,
2258 UpdatableInset const * inset) const
2260 int cell = tabular->GetCellFromInset(inset, actcell);
2263 lyxerr << "Own inset not found, shouldn't really happen!"
2268 int w = getMaxWidthOfCell(bv, cell);
2270 // because the inset then subtracts it's top_x and owner->x()
2271 w += (inset->x() - top_x);
2278 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2280 resizeLyXText(bv, recursive);
2284 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2287 for(int i = 0; i < tabular->rows(); ++i) {
2288 for(int j = 0; j < tabular->columns(); ++j) {
2289 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2297 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2298 bool const recursive) const
2300 if (the_locking_inset)
2301 return the_locking_inset->getLyXText(bv, recursive);
2303 // if we're locked lock the actual insettext and return it's LyXText!!!
2305 UpdatableInset * inset =
2306 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2307 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2308 return the_locking_inset->getLyXText(bv, recursive);
2311 return Inset::getLyXText(bv, recursive);
2315 bool InsetTabular::showInsetDialog(BufferView * bv) const
2317 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2318 bv->owner()->getDialogs().
2319 showTabular(const_cast<InsetTabular *>(this));
2324 void InsetTabular::openLayoutDialog(BufferView * bv) const
2326 if (the_locking_inset) {
2327 InsetTabular * i = static_cast<InsetTabular *>
2328 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2330 i->openLayoutDialog(bv);
2334 bv->owner()->getDialogs().showTabular(
2335 const_cast<InsetTabular *>(this));
2340 // function returns an object as defined in func_status.h:
2341 // states OK, Unknown, Disabled, On, Off.
2343 FuncStatus InsetTabular::getStatus(string const & what) const
2345 int action = LyXTabular::LAST_ACTION;
2349 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2350 string const tmp = tabularFeature[i].feature;
2351 if (tmp == what.substr(0, tmp.length())) {
2352 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2353 // tabularFeatures[i].feature.length())) {
2354 action = tabularFeature[i].action;
2358 if (action == LyXTabular::LAST_ACTION) {
2360 return status.unknown(true);
2363 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2368 LyXTabular::ltType dummyltt;
2371 if (hasSelection()) {
2372 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2374 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2378 case LyXTabular::SET_PWIDTH:
2379 case LyXTabular::SET_MPWIDTH:
2380 case LyXTabular::SET_SPECIAL_COLUMN:
2381 case LyXTabular::SET_SPECIAL_MULTI:
2382 return status.disabled(true);
2384 case LyXTabular::APPEND_ROW:
2385 case LyXTabular::APPEND_COLUMN:
2386 case LyXTabular::DELETE_ROW:
2387 case LyXTabular::DELETE_COLUMN:
2388 case LyXTabular::SET_ALL_LINES:
2389 case LyXTabular::UNSET_ALL_LINES:
2390 return status.clear();
2392 case LyXTabular::MULTICOLUMN:
2393 status.setOnOff(tabular->IsMultiColumn(actcell));
2395 case LyXTabular::M_TOGGLE_LINE_TOP:
2397 case LyXTabular::TOGGLE_LINE_TOP:
2398 status.setOnOff(tabular->TopLine(actcell, flag));
2400 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2402 case LyXTabular::TOGGLE_LINE_BOTTOM:
2403 status.setOnOff(tabular->BottomLine(actcell, flag));
2405 case LyXTabular::M_TOGGLE_LINE_LEFT:
2407 case LyXTabular::TOGGLE_LINE_LEFT:
2408 status.setOnOff(tabular->LeftLine(actcell, flag));
2410 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2412 case LyXTabular::TOGGLE_LINE_RIGHT:
2413 status.setOnOff(tabular->RightLine(actcell, flag));
2415 case LyXTabular::M_ALIGN_LEFT:
2417 case LyXTabular::ALIGN_LEFT:
2418 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2420 case LyXTabular::M_ALIGN_RIGHT:
2422 case LyXTabular::ALIGN_RIGHT:
2423 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2425 case LyXTabular::M_ALIGN_CENTER:
2427 case LyXTabular::ALIGN_CENTER:
2428 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2430 case LyXTabular::ALIGN_BLOCK:
2431 status.disabled(tabular->GetPWidth(actcell).zero());
2432 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2434 case LyXTabular::M_VALIGN_TOP:
2436 case LyXTabular::VALIGN_TOP:
2437 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2439 case LyXTabular::M_VALIGN_BOTTOM:
2441 case LyXTabular::VALIGN_BOTTOM:
2442 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2444 case LyXTabular::M_VALIGN_CENTER:
2446 case LyXTabular::VALIGN_CENTER:
2447 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2449 case LyXTabular::SET_LONGTABULAR:
2450 status.setOnOff(tabular->IsLongTabular());
2452 case LyXTabular::UNSET_LONGTABULAR:
2453 status.setOnOff(!tabular->IsLongTabular());
2455 case LyXTabular::SET_ROTATE_TABULAR:
2456 status.setOnOff(tabular->GetRotateTabular());
2458 case LyXTabular::UNSET_ROTATE_TABULAR:
2459 status.setOnOff(!tabular->GetRotateTabular());
2461 case LyXTabular::SET_ROTATE_CELL:
2462 status.setOnOff(tabular->GetRotateCell(actcell));
2464 case LyXTabular::UNSET_ROTATE_CELL:
2465 status.setOnOff(!tabular->GetRotateCell(actcell));
2467 case LyXTabular::SET_USEBOX:
2468 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2470 case LyXTabular::SET_LTFIRSTHEAD:
2471 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2473 case LyXTabular::SET_LTHEAD:
2474 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2476 case LyXTabular::SET_LTFOOT:
2477 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2479 case LyXTabular::SET_LTLASTFOOT:
2480 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2482 case LyXTabular::SET_LTNEWPAGE:
2483 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2487 status.disabled(true);
2494 vector<string> const InsetTabular::getLabelList() const
2496 return tabular->getLabelList();
2500 bool InsetTabular::copySelection(BufferView * bv)
2502 if (!hasSelection())
2505 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2506 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2507 if (sel_col_start > sel_col_end) {
2508 sel_col_start = sel_col_end;
2509 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2511 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2513 int const columns = sel_col_end - sel_col_start + 1;
2515 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2516 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2517 if (sel_row_start > sel_row_end) {
2518 swap(sel_row_start, sel_row_end);
2520 int const rows = sel_row_end - sel_row_start + 1;
2522 delete paste_tabular;
2523 paste_tabular = new LyXTabular(bv->buffer()->params,
2524 this, *tabular); // rows, columns);
2525 for (int i = 0; i < sel_row_start; ++i)
2526 paste_tabular->DeleteRow(0);
2527 while (paste_tabular->rows() > rows)
2528 paste_tabular->DeleteRow(rows);
2529 paste_tabular->SetTopLine(0, true, true);
2530 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2532 for (int i = 0; i < sel_col_start; ++i)
2533 paste_tabular->DeleteColumn(0);
2534 while (paste_tabular->columns() > columns)
2535 paste_tabular->DeleteColumn(columns);
2536 paste_tabular->SetLeftLine(0, true, true);
2537 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2541 paste_tabular->ascii(bv->buffer(), sstr,
2542 (int)parOwner()->params().depth(), true, '\t');
2543 bv->stuffClipboard(STRCONV(sstr.str()));
2548 bool InsetTabular::pasteSelection(BufferView * bv)
2553 for (int r1 = 0, r2 = actrow;
2554 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2556 for(int c1 = 0, c2 = actcol;
2557 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2559 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2560 tabular->IsPartOfMultiColumn(r2,c2))
2562 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2566 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2570 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2571 int const n2 = tabular->GetCellNumber(r2, c2);
2572 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2573 tabular->GetCellInset(n2)->setOwner(this);
2574 tabular->GetCellInset(n2)->deleteLyXText(bv);
2575 tabular->GetCellInset(n2)->markNew();
2582 bool InsetTabular::cutSelection(BufferParams const & bp)
2584 if (!hasSelection())
2587 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2588 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2589 if (sel_col_start > sel_col_end) {
2590 sel_col_start = sel_col_end;
2591 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2593 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2595 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2596 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2597 if (sel_row_start > sel_row_end) {
2598 swap(sel_row_start, sel_row_end);
2600 if (sel_cell_start > sel_cell_end) {
2601 swap(sel_cell_start, sel_cell_end);
2603 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2604 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2605 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2612 bool InsetTabular::isRightToLeft(BufferView * bv)
2614 return bv->getParentLanguage(this)->RightToLeft();
2618 bool InsetTabular::nodraw() const
2620 if (!UpdatableInset::nodraw() && the_locking_inset)
2621 return the_locking_inset->nodraw();
2622 return UpdatableInset::nodraw();
2626 int InsetTabular::scroll(bool recursive) const
2628 int sx = UpdatableInset::scroll(false);
2630 if (recursive && the_locking_inset)
2631 sx += the_locking_inset->scroll(recursive);
2637 bool InsetTabular::doClearArea() const
2639 return !locked || (need_update & (FULL|INIT));
2643 void InsetTabular::getSelection(int & srow, int & erow,
2644 int & scol, int & ecol) const
2646 int const start = hasSelection() ? sel_cell_start : actcell;
2647 int const end = hasSelection() ? sel_cell_end : actcell;
2649 srow = tabular->row_of_cell(start);
2650 erow = tabular->row_of_cell(end);
2655 scol = tabular->column_of_cell(start);
2656 ecol = tabular->column_of_cell(end);
2660 ecol = tabular->right_column_of_cell(end);
2665 Paragraph * InsetTabular::firstParagraph() const
2667 if (the_locking_inset)
2668 return the_locking_inset->firstParagraph();
2673 Paragraph * InsetTabular::getFirstParagraph(int i) const
2675 return (i < tabular->GetNumberOfCells())
2676 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2681 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2683 if (the_locking_inset)
2684 return the_locking_inset->cursor(bv);
2685 return Inset::cursor(bv);
2689 Inset * InsetTabular::getInsetFromID(int id_arg) const
2692 return const_cast<InsetTabular *>(this);
2695 for(int i = 0; i < tabular->rows(); ++i) {
2696 for(int j = 0; j < tabular->columns(); ++j) {
2697 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2706 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2709 if (the_locking_inset) {
2710 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2711 if (!word.word().empty()) {
2715 if (tabular->IsLastCell(actcell)) {
2716 bv->unlockInset(const_cast<InsetTabular *>(this));
2718 return WordLangTuple();
2722 // otherwise we have to lock the next inset and ask for it's selecttion
2723 UpdatableInset * inset =
2724 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2725 inset->edit(bv, 0, 0, mouse_button::none);
2726 WordLangTuple word(selectNextWordInt(bv, value));
2728 if (!word.word().empty())
2734 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2736 // when entering this function the inset should be ALWAYS locked!
2737 lyx::Assert(the_locking_inset);
2739 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2740 if (!word.word().empty())
2743 if (tabular->IsLastCell(actcell)) {
2744 bv->unlockInset(const_cast<InsetTabular *>(this));
2745 return WordLangTuple();
2748 // otherwise we have to lock the next inset and ask for it's selecttion
2749 UpdatableInset * inset =
2750 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2752 return selectNextWordInt(bv, value);
2756 void InsetTabular::selectSelectedWord(BufferView * bv)
2758 if (the_locking_inset) {
2759 the_locking_inset->selectSelectedWord(bv);
2766 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2768 if (the_locking_inset) {
2769 the_locking_inset->toggleSelection(bv, kill_selection);
2774 void InsetTabular::markErased()
2778 while (!tabular->IsLastCell(cell)) {
2780 InsetText * inset = tabular->GetCellInset(cell);
2781 inset->markErased();
2786 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2788 if (the_locking_inset) {
2789 if (the_locking_inset->nextChange(bv, length)) {
2790 updateLocal(bv, CELL, false);
2793 if (tabular->IsLastCell(actcell))
2797 InsetText * inset = tabular->GetCellInset(actcell);
2798 if (inset->nextChange(bv, length)) {
2799 updateLocal(bv, FULL, false);
2802 while (!tabular->IsLastCell(actcell)) {
2804 inset = tabular->GetCellInset(actcell);
2805 if (inset->nextChange(bv, length)) {
2806 updateLocal(bv, FULL, false);
2814 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2817 if (the_locking_inset) {
2818 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2819 updateLocal(bv, CELL, false);
2822 if (tabular->IsLastCell(actcell))
2826 InsetText * inset = tabular->GetCellInset(actcell);
2827 if (inset->searchForward(bv, str, cs, mw)) {
2828 updateLocal(bv, FULL, false);
2831 while (!tabular->IsLastCell(actcell)) {
2833 inset = tabular->GetCellInset(actcell);
2834 if (inset->searchForward(bv, str, cs, mw)) {
2835 updateLocal(bv, FULL, false);
2843 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2846 if (the_locking_inset) {
2847 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2848 updateLocal(bv, CELL, false);
2853 actcell = tabular->GetNumberOfCells();
2857 InsetText * inset = tabular->GetCellInset(actcell);
2858 if (inset->searchBackward(bv, str, cs, mw)) {
2859 updateLocal(bv, CELL, false);
2867 bool InsetTabular::insetAllowed(Inset::Code code) const
2869 if (the_locking_inset)
2870 return the_locking_inset->insetAllowed(code);
2871 // we return true here because if the inset is not locked someone
2872 // wants to insert something in one of our insettexts and we generally
2878 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2880 const int cell = tabular->GetCellFromInset(in, actcell);
2883 return tabular->GetPWidth(cell).zero();
2885 // well we didn't obviously find it so maybe our owner knows more
2887 return owner()->forceDefaultParagraphs(in);
2888 // if we're here there is really something strange going on!!!
2892 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2895 if (buf.length() <= 0)
2901 string::size_type len = buf.length();
2902 string::size_type p = 0;
2905 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2914 maxCols = max(cols, maxCols);
2920 maxCols = max(cols, maxCols);
2921 LyXTabular * loctab;
2926 delete paste_tabular;
2927 paste_tabular = new LyXTabular(bv->buffer()->params,
2928 this, rows, maxCols);
2929 loctab = paste_tabular;
2932 loctab = tabular.get();
2938 string::size_type op = 0;
2939 int cells = loctab->GetNumberOfCells();
2942 rows = loctab->rows();
2943 int const columns = loctab->columns();
2945 while ((cell < cells) && (p < len) && (row < rows) &&
2946 (p = buf.find_first_of("\t\n", p)) != string::npos)
2952 // we can only set this if we are not too far right
2953 if (cols < columns) {
2954 InsetText * ti = loctab->GetCellInset(cell);
2955 LyXFont const font = ti->getLyXText(bv)->
2956 getFont(bv->buffer(), ti->paragraph(), 0);
2957 ti->setText(buf.substr(op, p-op), font);
2963 // we can only set this if we are not too far right
2964 if (cols < columns) {
2965 InsetText * ti = loctab->GetCellInset(cell);
2966 LyXFont const font = ti->getLyXText(bv)->
2967 getFont(bv->buffer(), ti->paragraph(), 0);
2968 ti->setText(buf.substr(op, p-op), font);
2973 cell = loctab->GetCellNumber(row, cols);
2979 // check for the last cell if there is no trailing '\n'
2980 if ((cell < cells) && (op < len)) {
2981 InsetText * ti = loctab->GetCellInset(cell);
2982 LyXFont const font = ti->getLyXText(bv)->
2983 getFont(bv->buffer(), ti->paragraph(), 0);
2984 ti->setText(buf.substr(op, len-op), font);
2991 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2993 int const rows = tabular->rows();
2994 int const columns = tabular->columns();
2995 for (int i = 0; i < rows; ++i) {
2996 for (int j = 0; j < columns; ++j) {
2997 tabular->GetCellInset(i,j)->addPreview(loader);