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->first_y + bv->painter().paperHeight() <
1084 (top_baseline + tabular->GetHeightOfTabular()))
1086 bv->scrollDocView(bv->text->first_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->first_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_first_y = bv->text->first_y;
1499 the_locking_inset->fitInsetCursor(bv);
1500 if (old_first_y != bv->text->first_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 bool InsetTabular::deletable() const
1778 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1782 setSelection(0, tabular->GetNumberOfCells() - 1);
1784 if (hasSelection()) {
1785 setUndo(bv, Undo::EDIT,
1786 bv->text->cursor.par(),
1787 bv->text->cursor.par()->next());
1788 bool const frozen = undo_frozen;
1791 // apply the fontchange on the whole selection
1796 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1797 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1798 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1799 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1806 updateLocal(bv, INIT, true);
1808 if (the_locking_inset)
1809 the_locking_inset->setFont(bv, font, tall);
1813 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1815 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1818 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1819 string const tmp = tabularFeature[i].feature;
1821 if (tmp == what.substr(0, tmp.length())) {
1822 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1823 //tabularFeatures[i].feature.length())) {
1824 action = tabularFeature[i].action;
1828 if (action == LyXTabular::LAST_ACTION)
1832 ltrim(what.substr(tabularFeature[i].feature.length()));
1833 tabularFeatures(bv, action, val);
1839 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1840 string const & special, bool & flag)
1842 if (special == "dl_above") {
1845 } else if (special == "dl_below") {
1846 ltt.bottomDL = flag;
1848 } else if (special == "empty") {
1860 void InsetTabular::tabularFeatures(BufferView * bv,
1861 LyXTabular::Feature feature,
1862 string const & value)
1868 bool setLines = false;
1869 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1870 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1873 case LyXTabular::M_ALIGN_LEFT:
1874 case LyXTabular::ALIGN_LEFT:
1875 setAlign = LYX_ALIGN_LEFT;
1877 case LyXTabular::M_ALIGN_RIGHT:
1878 case LyXTabular::ALIGN_RIGHT:
1879 setAlign = LYX_ALIGN_RIGHT;
1881 case LyXTabular::M_ALIGN_CENTER:
1882 case LyXTabular::ALIGN_CENTER:
1883 setAlign = LYX_ALIGN_CENTER;
1885 case LyXTabular::ALIGN_BLOCK:
1886 setAlign = LYX_ALIGN_BLOCK;
1888 case LyXTabular::M_VALIGN_TOP:
1889 case LyXTabular::VALIGN_TOP:
1890 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1892 case LyXTabular::M_VALIGN_BOTTOM:
1893 case LyXTabular::VALIGN_BOTTOM:
1894 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1896 case LyXTabular::M_VALIGN_CENTER:
1897 case LyXTabular::VALIGN_CENTER:
1898 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1903 if (hasSelection()) {
1904 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1906 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1907 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1909 setUndo(bv, Undo::FINISH,
1910 bv->text->cursor.par(),
1911 bv->text->cursor.par()->next());
1913 int row = tabular->row_of_cell(actcell);
1914 int column = tabular->column_of_cell(actcell);
1916 LyXTabular::ltType ltt;
1919 case LyXTabular::SET_PWIDTH:
1921 LyXLength const vallen(value);
1922 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1924 bool const update = (tmplen != vallen);
1925 tabular->SetColumnPWidth(actcell, vallen);
1928 for (int i = 0; i < tabular->rows(); ++i) {
1929 cell = tabular->GetCellNumber(i,column);
1930 tabular->GetCellInset(cell)->resizeLyXText(bv);
1932 updateLocal(bv, INIT, true);
1936 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1937 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1938 else if (!vallen.zero()
1939 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1940 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1943 case LyXTabular::SET_MPWIDTH:
1945 LyXLength const vallen(value);
1946 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1948 bool const update = (tmplen != vallen);
1949 tabular->SetMColumnPWidth(actcell, vallen);
1951 for (int i = 0; i < tabular->rows(); ++i) {
1952 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1955 updateLocal(bv, INIT, true);
1959 case LyXTabular::SET_SPECIAL_COLUMN:
1960 case LyXTabular::SET_SPECIAL_MULTI:
1961 tabular->SetAlignSpecial(actcell,value,feature);
1962 updateLocal(bv, FULL, true);
1964 case LyXTabular::APPEND_ROW:
1965 // append the row into the tabular
1966 unlockInsetInInset(bv, the_locking_inset);
1967 tabular->AppendRow(bv->buffer()->params, actcell);
1968 updateLocal(bv, INIT, true);
1970 case LyXTabular::APPEND_COLUMN:
1971 // append the column into the tabular
1972 unlockInsetInInset(bv, the_locking_inset);
1973 tabular->AppendColumn(bv->buffer()->params, actcell);
1974 actcell = tabular->GetCellNumber(row, column);
1975 updateLocal(bv, INIT, true);
1977 case LyXTabular::DELETE_ROW:
1978 unlockInsetInInset(bv, the_locking_inset);
1979 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1980 tabular->DeleteRow(sel_row_start);
1982 if (sel_row_start >= tabular->rows())
1984 actcell = tabular->GetCellNumber(sel_row_start, column);
1986 updateLocal(bv, INIT, true);
1988 case LyXTabular::DELETE_COLUMN:
1989 unlockInsetInInset(bv, the_locking_inset);
1990 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1991 tabular->DeleteColumn(sel_col_start);
1993 if (sel_col_start >= tabular->columns())
1995 actcell = tabular->GetCellNumber(row, sel_col_start);
1997 updateLocal(bv, INIT, true);
1999 case LyXTabular::M_TOGGLE_LINE_TOP:
2001 case LyXTabular::TOGGLE_LINE_TOP:
2003 bool lineSet = !tabular->TopLine(actcell, flag);
2004 for (int i = sel_row_start; i <= sel_row_end; ++i)
2005 for (int j = sel_col_start; j <= sel_col_end; ++j)
2006 tabular->SetTopLine(
2007 tabular->GetCellNumber(i, j),
2009 updateLocal(bv, INIT, true);
2013 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2015 case LyXTabular::TOGGLE_LINE_BOTTOM:
2017 bool lineSet = !tabular->BottomLine(actcell, flag);
2018 for (int i = sel_row_start; i <= sel_row_end; ++i)
2019 for (int j = sel_col_start; j <= sel_col_end; ++j)
2020 tabular->SetBottomLine(
2021 tabular->GetCellNumber(i, j),
2024 updateLocal(bv, INIT, true);
2028 case LyXTabular::M_TOGGLE_LINE_LEFT:
2030 case LyXTabular::TOGGLE_LINE_LEFT:
2032 bool lineSet = !tabular->LeftLine(actcell, flag);
2033 for (int i = sel_row_start; i <= sel_row_end; ++i)
2034 for (int j = sel_col_start; j <= sel_col_end; ++j)
2035 tabular->SetLeftLine(
2036 tabular->GetCellNumber(i,j),
2039 updateLocal(bv, INIT, true);
2043 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2045 case LyXTabular::TOGGLE_LINE_RIGHT:
2047 bool lineSet = !tabular->RightLine(actcell, flag);
2048 for (int i = sel_row_start; i <= sel_row_end; ++i)
2049 for (int j = sel_col_start; j <= sel_col_end; ++j)
2050 tabular->SetRightLine(
2051 tabular->GetCellNumber(i,j),
2054 updateLocal(bv, INIT, true);
2058 case LyXTabular::M_ALIGN_LEFT:
2059 case LyXTabular::M_ALIGN_RIGHT:
2060 case LyXTabular::M_ALIGN_CENTER:
2062 case LyXTabular::ALIGN_LEFT:
2063 case LyXTabular::ALIGN_RIGHT:
2064 case LyXTabular::ALIGN_CENTER:
2065 case LyXTabular::ALIGN_BLOCK:
2066 for (int i = sel_row_start; i <= sel_row_end; ++i)
2067 for (int j = sel_col_start; j <= sel_col_end; ++j)
2068 tabular->SetAlignment(
2069 tabular->GetCellNumber(i, j),
2072 updateLocal(bv, INIT, true);
2074 case LyXTabular::M_VALIGN_TOP:
2075 case LyXTabular::M_VALIGN_BOTTOM:
2076 case LyXTabular::M_VALIGN_CENTER:
2078 case LyXTabular::VALIGN_TOP:
2079 case LyXTabular::VALIGN_BOTTOM:
2080 case LyXTabular::VALIGN_CENTER:
2081 for (int i = sel_row_start; i <= sel_row_end; ++i)
2082 for (int j = sel_col_start; j <= sel_col_end; ++j)
2083 tabular->SetVAlignment(
2084 tabular->GetCellNumber(i, j),
2086 updateLocal(bv, INIT, true);
2088 case LyXTabular::MULTICOLUMN:
2090 if (sel_row_start != sel_row_end) {
2091 Alert::alert(_("Impossible operation!"),
2092 _("Multicolumns can only be horizontally."),
2096 // just multicol for one Single Cell
2097 if (!hasSelection()) {
2098 // check wether we are completly in a multicol
2099 if (tabular->IsMultiColumn(actcell)) {
2100 tabular->UnsetMultiColumn(actcell);
2101 updateLocal(bv, INIT, true);
2103 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2104 updateLocal(bv, CELL, true);
2108 // we have a selection so this means we just add all this
2109 // cells to form a multicolumn cell
2113 if (sel_cell_start > sel_cell_end) {
2114 s_start = sel_cell_end;
2115 s_end = sel_cell_start;
2117 s_start = sel_cell_start;
2118 s_end = sel_cell_end;
2120 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2123 updateLocal(bv, INIT, true);
2126 case LyXTabular::SET_ALL_LINES:
2128 case LyXTabular::UNSET_ALL_LINES:
2129 for (int i = sel_row_start; i <= sel_row_end; ++i)
2130 for (int j = sel_col_start; j <= sel_col_end; ++j)
2131 tabular->SetAllLines(
2132 tabular->GetCellNumber(i,j), setLines);
2133 updateLocal(bv, INIT, true);
2135 case LyXTabular::SET_LONGTABULAR:
2136 tabular->SetLongTabular(true);
2137 updateLocal(bv, INIT, true); // because this toggles displayed
2139 case LyXTabular::UNSET_LONGTABULAR:
2140 tabular->SetLongTabular(false);
2141 updateLocal(bv, INIT, true); // because this toggles displayed
2143 case LyXTabular::SET_ROTATE_TABULAR:
2144 tabular->SetRotateTabular(true);
2146 case LyXTabular::UNSET_ROTATE_TABULAR:
2147 tabular->SetRotateTabular(false);
2149 case LyXTabular::SET_ROTATE_CELL:
2150 for (int i = sel_row_start; i <= sel_row_end; ++i)
2151 for (int j = sel_col_start; j<=sel_col_end; ++j)
2152 tabular->SetRotateCell(
2153 tabular->GetCellNumber(i, j),
2156 case LyXTabular::UNSET_ROTATE_CELL:
2157 for (int i = sel_row_start; i <= sel_row_end; ++i)
2158 for (int j = sel_col_start; j <= sel_col_end; ++j)
2159 tabular->SetRotateCell(
2160 tabular->GetCellNumber(i, j), false);
2162 case LyXTabular::SET_USEBOX:
2164 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2165 if (val == tabular->GetUsebox(actcell))
2166 val = LyXTabular::BOX_NONE;
2167 for (int i = sel_row_start; i <= sel_row_end; ++i)
2168 for (int j = sel_col_start; j <= sel_col_end; ++j)
2170 tabular->GetCellNumber(i, j), val);
2173 case LyXTabular::UNSET_LTFIRSTHEAD:
2175 case LyXTabular::SET_LTFIRSTHEAD:
2176 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2177 checkLongtableSpecial(ltt, value, flag);
2178 tabular->SetLTHead(row, flag, ltt, true);
2180 case LyXTabular::UNSET_LTHEAD:
2182 case LyXTabular::SET_LTHEAD:
2183 (void)tabular->GetRowOfLTHead(row, ltt);
2184 checkLongtableSpecial(ltt, value, flag);
2185 tabular->SetLTHead(row, flag, ltt, false);
2187 case LyXTabular::UNSET_LTFOOT:
2189 case LyXTabular::SET_LTFOOT:
2190 (void)tabular->GetRowOfLTFoot(row, ltt);
2191 checkLongtableSpecial(ltt, value, flag);
2192 tabular->SetLTFoot(row, flag, ltt, false);
2194 case LyXTabular::UNSET_LTLASTFOOT:
2196 case LyXTabular::SET_LTLASTFOOT:
2197 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2198 checkLongtableSpecial(ltt, value, flag);
2199 tabular->SetLTFoot(row, flag, ltt, true);
2201 case LyXTabular::SET_LTNEWPAGE:
2203 bool what = !tabular->GetLTNewPage(row);
2204 tabular->SetLTNewPage(row, what);
2207 // dummy stuff just to avoid warnings
2208 case LyXTabular::LAST_ACTION:
2214 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2217 UpdatableInset * inset =
2218 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2219 LyXFont font(LyXFont::ALL_SANE);
2221 x = inset->x() + inset->width(bv, font);
2222 y = inset->descent(bv, font);
2224 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2225 //inset_y = cursor.y();
2226 inset->edit(bv, x, y, button);
2227 if (!the_locking_inset)
2229 updateLocal(bv, CELL, false);
2230 return (the_locking_inset != 0);
2234 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2235 mouse_button::state button)
2237 inset_x = cursor_.x()
2238 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2239 inset_y = cursor_.y();
2240 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2244 bool InsetTabular::insetHit(BufferView *, int x, int) const
2247 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2251 // This returns paperWidth() if the cell-width is unlimited or the width
2252 // in pixels if we have a pwidth for this cell.
2253 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2255 LyXLength const len = tabular->GetPWidth(cell);
2259 return len.inPixels(latexTextWidth(bv));
2263 int InsetTabular::getMaxWidth(BufferView * bv,
2264 UpdatableInset const * inset) const
2266 int cell = tabular->GetCellFromInset(inset, actcell);
2269 lyxerr << "Own inset not found, shouldn't really happen!"
2274 int w = getMaxWidthOfCell(bv, cell);
2276 // because the inset then subtracts it's top_x and owner->x()
2277 w += (inset->x() - top_x);
2284 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2286 resizeLyXText(bv, recursive);
2290 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2293 for(int i = 0; i < tabular->rows(); ++i) {
2294 for(int j = 0; j < tabular->columns(); ++j) {
2295 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2303 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2304 bool const recursive) const
2306 if (the_locking_inset)
2307 return the_locking_inset->getLyXText(bv, recursive);
2309 // if we're locked lock the actual insettext and return it's LyXText!!!
2311 UpdatableInset * inset =
2312 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2313 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2314 return the_locking_inset->getLyXText(bv, recursive);
2317 return Inset::getLyXText(bv, recursive);
2321 bool InsetTabular::showInsetDialog(BufferView * bv) const
2323 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2324 bv->owner()->getDialogs().
2325 showTabular(const_cast<InsetTabular *>(this));
2330 void InsetTabular::openLayoutDialog(BufferView * bv) const
2332 if (the_locking_inset) {
2333 InsetTabular * i = static_cast<InsetTabular *>
2334 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2336 i->openLayoutDialog(bv);
2340 bv->owner()->getDialogs().showTabular(
2341 const_cast<InsetTabular *>(this));
2346 // function returns an object as defined in func_status.h:
2347 // states OK, Unknown, Disabled, On, Off.
2349 FuncStatus InsetTabular::getStatus(string const & what) const
2351 int action = LyXTabular::LAST_ACTION;
2355 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2356 string const tmp = tabularFeature[i].feature;
2357 if (tmp == what.substr(0, tmp.length())) {
2358 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2359 // tabularFeatures[i].feature.length())) {
2360 action = tabularFeature[i].action;
2364 if (action == LyXTabular::LAST_ACTION) {
2366 return status.unknown(true);
2369 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2374 LyXTabular::ltType dummyltt;
2377 if (hasSelection()) {
2378 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2380 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2384 case LyXTabular::SET_PWIDTH:
2385 case LyXTabular::SET_MPWIDTH:
2386 case LyXTabular::SET_SPECIAL_COLUMN:
2387 case LyXTabular::SET_SPECIAL_MULTI:
2388 return status.disabled(true);
2390 case LyXTabular::APPEND_ROW:
2391 case LyXTabular::APPEND_COLUMN:
2392 case LyXTabular::DELETE_ROW:
2393 case LyXTabular::DELETE_COLUMN:
2394 case LyXTabular::SET_ALL_LINES:
2395 case LyXTabular::UNSET_ALL_LINES:
2396 return status.clear();
2398 case LyXTabular::MULTICOLUMN:
2399 status.setOnOff(tabular->IsMultiColumn(actcell));
2401 case LyXTabular::M_TOGGLE_LINE_TOP:
2403 case LyXTabular::TOGGLE_LINE_TOP:
2404 status.setOnOff(tabular->TopLine(actcell, flag));
2406 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2408 case LyXTabular::TOGGLE_LINE_BOTTOM:
2409 status.setOnOff(tabular->BottomLine(actcell, flag));
2411 case LyXTabular::M_TOGGLE_LINE_LEFT:
2413 case LyXTabular::TOGGLE_LINE_LEFT:
2414 status.setOnOff(tabular->LeftLine(actcell, flag));
2416 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2418 case LyXTabular::TOGGLE_LINE_RIGHT:
2419 status.setOnOff(tabular->RightLine(actcell, flag));
2421 case LyXTabular::M_ALIGN_LEFT:
2423 case LyXTabular::ALIGN_LEFT:
2424 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2426 case LyXTabular::M_ALIGN_RIGHT:
2428 case LyXTabular::ALIGN_RIGHT:
2429 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2431 case LyXTabular::M_ALIGN_CENTER:
2433 case LyXTabular::ALIGN_CENTER:
2434 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2436 case LyXTabular::ALIGN_BLOCK:
2437 status.disabled(tabular->GetPWidth(actcell).zero());
2438 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2440 case LyXTabular::M_VALIGN_TOP:
2442 case LyXTabular::VALIGN_TOP:
2443 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2445 case LyXTabular::M_VALIGN_BOTTOM:
2447 case LyXTabular::VALIGN_BOTTOM:
2448 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2450 case LyXTabular::M_VALIGN_CENTER:
2452 case LyXTabular::VALIGN_CENTER:
2453 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2455 case LyXTabular::SET_LONGTABULAR:
2456 status.setOnOff(tabular->IsLongTabular());
2458 case LyXTabular::UNSET_LONGTABULAR:
2459 status.setOnOff(!tabular->IsLongTabular());
2461 case LyXTabular::SET_ROTATE_TABULAR:
2462 status.setOnOff(tabular->GetRotateTabular());
2464 case LyXTabular::UNSET_ROTATE_TABULAR:
2465 status.setOnOff(!tabular->GetRotateTabular());
2467 case LyXTabular::SET_ROTATE_CELL:
2468 status.setOnOff(tabular->GetRotateCell(actcell));
2470 case LyXTabular::UNSET_ROTATE_CELL:
2471 status.setOnOff(!tabular->GetRotateCell(actcell));
2473 case LyXTabular::SET_USEBOX:
2474 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2476 case LyXTabular::SET_LTFIRSTHEAD:
2477 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2479 case LyXTabular::SET_LTHEAD:
2480 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2482 case LyXTabular::SET_LTFOOT:
2483 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2485 case LyXTabular::SET_LTLASTFOOT:
2486 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2488 case LyXTabular::SET_LTNEWPAGE:
2489 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2493 status.disabled(true);
2500 vector<string> const InsetTabular::getLabelList() const
2502 return tabular->getLabelList();
2506 bool InsetTabular::copySelection(BufferView * bv)
2508 if (!hasSelection())
2511 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2512 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2513 if (sel_col_start > sel_col_end) {
2514 sel_col_start = sel_col_end;
2515 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2517 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2519 int const columns = sel_col_end - sel_col_start + 1;
2521 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2522 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2523 if (sel_row_start > sel_row_end) {
2524 swap(sel_row_start, sel_row_end);
2526 int const rows = sel_row_end - sel_row_start + 1;
2528 delete paste_tabular;
2529 paste_tabular = new LyXTabular(bv->buffer()->params,
2530 this, *tabular); // rows, columns);
2531 for (int i = 0; i < sel_row_start; ++i)
2532 paste_tabular->DeleteRow(0);
2533 while (paste_tabular->rows() > rows)
2534 paste_tabular->DeleteRow(rows);
2535 paste_tabular->SetTopLine(0, true, true);
2536 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2538 for (int i = 0; i < sel_col_start; ++i)
2539 paste_tabular->DeleteColumn(0);
2540 while (paste_tabular->columns() > columns)
2541 paste_tabular->DeleteColumn(columns);
2542 paste_tabular->SetLeftLine(0, true, true);
2543 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2547 paste_tabular->ascii(bv->buffer(), sstr,
2548 (int)parOwner()->params().depth(), true, '\t');
2549 bv->stuffClipboard(STRCONV(sstr.str()));
2554 bool InsetTabular::pasteSelection(BufferView * bv)
2559 for (int r1 = 0, r2 = actrow;
2560 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2562 for(int c1 = 0, c2 = actcol;
2563 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2565 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2566 tabular->IsPartOfMultiColumn(r2,c2))
2568 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2572 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2576 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2577 int const n2 = tabular->GetCellNumber(r2, c2);
2578 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2579 tabular->GetCellInset(n2)->setOwner(this);
2580 tabular->GetCellInset(n2)->deleteLyXText(bv);
2581 tabular->GetCellInset(n2)->markNew();
2588 bool InsetTabular::cutSelection(BufferParams const & bp)
2590 if (!hasSelection())
2593 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2594 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2595 if (sel_col_start > sel_col_end) {
2596 sel_col_start = sel_col_end;
2597 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2599 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2601 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2602 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2603 if (sel_row_start > sel_row_end) {
2604 swap(sel_row_start, sel_row_end);
2606 if (sel_cell_start > sel_cell_end) {
2607 swap(sel_cell_start, sel_cell_end);
2609 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2610 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2611 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2618 bool InsetTabular::isRightToLeft(BufferView * bv)
2620 return bv->getParentLanguage(this)->RightToLeft();
2624 bool InsetTabular::nodraw() const
2626 if (!UpdatableInset::nodraw() && the_locking_inset)
2627 return the_locking_inset->nodraw();
2628 return UpdatableInset::nodraw();
2632 int InsetTabular::scroll(bool recursive) const
2634 int sx = UpdatableInset::scroll(false);
2636 if (recursive && the_locking_inset)
2637 sx += the_locking_inset->scroll(recursive);
2643 bool InsetTabular::doClearArea() const
2645 return !locked || (need_update & (FULL|INIT));
2649 void InsetTabular::getSelection(int & srow, int & erow,
2650 int & scol, int & ecol) const
2652 int const start = hasSelection() ? sel_cell_start : actcell;
2653 int const end = hasSelection() ? sel_cell_end : actcell;
2655 srow = tabular->row_of_cell(start);
2656 erow = tabular->row_of_cell(end);
2661 scol = tabular->column_of_cell(start);
2662 ecol = tabular->column_of_cell(end);
2666 ecol = tabular->right_column_of_cell(end);
2671 Paragraph * InsetTabular::firstParagraph() const
2673 if (the_locking_inset)
2674 return the_locking_inset->firstParagraph();
2679 Paragraph * InsetTabular::getFirstParagraph(int i) const
2681 return (i < tabular->GetNumberOfCells())
2682 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2687 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2689 if (the_locking_inset)
2690 return the_locking_inset->cursor(bv);
2691 return Inset::cursor(bv);
2695 Inset * InsetTabular::getInsetFromID(int id_arg) const
2698 return const_cast<InsetTabular *>(this);
2701 for(int i = 0; i < tabular->rows(); ++i) {
2702 for(int j = 0; j < tabular->columns(); ++j) {
2703 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2712 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2715 if (the_locking_inset) {
2716 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2717 if (!word.word().empty()) {
2721 if (tabular->IsLastCell(actcell)) {
2722 bv->unlockInset(const_cast<InsetTabular *>(this));
2724 return WordLangTuple();
2728 // otherwise we have to lock the next inset and ask for it's selecttion
2729 UpdatableInset * inset =
2730 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2731 inset->edit(bv, 0, 0, mouse_button::none);
2732 WordLangTuple word(selectNextWordInt(bv, value));
2734 if (!word.word().empty())
2740 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2742 // when entering this function the inset should be ALWAYS locked!
2743 lyx::Assert(the_locking_inset);
2745 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2746 if (!word.word().empty())
2749 if (tabular->IsLastCell(actcell)) {
2750 bv->unlockInset(const_cast<InsetTabular *>(this));
2751 return WordLangTuple();
2754 // otherwise we have to lock the next inset and ask for it's selecttion
2755 UpdatableInset * inset =
2756 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2758 return selectNextWordInt(bv, value);
2762 void InsetTabular::selectSelectedWord(BufferView * bv)
2764 if (the_locking_inset) {
2765 the_locking_inset->selectSelectedWord(bv);
2772 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2774 if (the_locking_inset) {
2775 the_locking_inset->toggleSelection(bv, kill_selection);
2780 void InsetTabular::markErased()
2784 while (!tabular->IsLastCell(cell)) {
2786 InsetText * inset = tabular->GetCellInset(cell);
2787 inset->markErased();
2792 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2794 if (the_locking_inset) {
2795 if (the_locking_inset->nextChange(bv, length)) {
2796 updateLocal(bv, CELL, false);
2799 if (tabular->IsLastCell(actcell))
2803 InsetText * inset = tabular->GetCellInset(actcell);
2804 if (inset->nextChange(bv, length)) {
2805 updateLocal(bv, FULL, false);
2808 while (!tabular->IsLastCell(actcell)) {
2810 inset = tabular->GetCellInset(actcell);
2811 if (inset->nextChange(bv, length)) {
2812 updateLocal(bv, FULL, false);
2820 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2823 if (the_locking_inset) {
2824 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2825 updateLocal(bv, CELL, false);
2828 if (tabular->IsLastCell(actcell))
2832 InsetText * inset = tabular->GetCellInset(actcell);
2833 if (inset->searchForward(bv, str, cs, mw)) {
2834 updateLocal(bv, FULL, false);
2837 while (!tabular->IsLastCell(actcell)) {
2839 inset = tabular->GetCellInset(actcell);
2840 if (inset->searchForward(bv, str, cs, mw)) {
2841 updateLocal(bv, FULL, false);
2849 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2852 if (the_locking_inset) {
2853 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2854 updateLocal(bv, CELL, false);
2859 actcell = tabular->GetNumberOfCells();
2863 InsetText * inset = tabular->GetCellInset(actcell);
2864 if (inset->searchBackward(bv, str, cs, mw)) {
2865 updateLocal(bv, CELL, false);
2873 bool InsetTabular::insetAllowed(Inset::Code code) const
2875 if (the_locking_inset)
2876 return the_locking_inset->insetAllowed(code);
2877 // we return true here because if the inset is not locked someone
2878 // wants to insert something in one of our insettexts and we generally
2884 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2886 const int cell = tabular->GetCellFromInset(in, actcell);
2889 return tabular->GetPWidth(cell).zero();
2891 // well we didn't obviously find it so maybe our owner knows more
2893 return owner()->forceDefaultParagraphs(in);
2894 // if we're here there is really something strange going on!!!
2898 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2901 if (buf.length() <= 0)
2907 string::size_type len = buf.length();
2908 string::size_type p = 0;
2911 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2920 maxCols = max(cols, maxCols);
2926 maxCols = max(cols, maxCols);
2927 LyXTabular * loctab;
2932 delete paste_tabular;
2933 paste_tabular = new LyXTabular(bv->buffer()->params,
2934 this, rows, maxCols);
2935 loctab = paste_tabular;
2938 loctab = tabular.get();
2944 string::size_type op = 0;
2945 int cells = loctab->GetNumberOfCells();
2948 rows = loctab->rows();
2949 int const columns = loctab->columns();
2951 while ((cell < cells) && (p < len) && (row < rows) &&
2952 (p = buf.find_first_of("\t\n", p)) != string::npos)
2958 // we can only set this if we are not too far right
2959 if (cols < columns) {
2960 InsetText * ti = loctab->GetCellInset(cell);
2961 LyXFont const font = ti->getLyXText(bv)->
2962 getFont(bv->buffer(), ti->paragraph(), 0);
2963 ti->setText(buf.substr(op, p-op), font);
2969 // we can only set this if we are not too far right
2970 if (cols < columns) {
2971 InsetText * ti = loctab->GetCellInset(cell);
2972 LyXFont const font = ti->getLyXText(bv)->
2973 getFont(bv->buffer(), ti->paragraph(), 0);
2974 ti->setText(buf.substr(op, p-op), font);
2979 cell = loctab->GetCellNumber(row, cols);
2985 // check for the last cell if there is no trailing '\n'
2986 if ((cell < cells) && (op < len)) {
2987 InsetText * ti = loctab->GetCellInset(cell);
2988 LyXFont const font = ti->getLyXText(bv)->
2989 getFont(bv->buffer(), ti->paragraph(), 0);
2990 ti->setText(buf.substr(op, len-op), font);
2997 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2999 int const rows = tabular->rows();
3000 int const columns = tabular->columns();
3001 for (int i = 0; i < rows; ++i) {
3002 for (int j = 0; j < columns; ++j) {
3003 tabular->GetCellInset(i,j)->addPreview(loader);