1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
17 #include "insettabular.h"
18 #include "insettext.h"
21 #include "BufferView.h"
22 #include "commandtags.h"
24 #include "funcrequest.h"
27 #include "LaTeXFeatures.h"
30 #include "lyxlength.h"
33 #include "ParagraphParameters.h"
34 #include "undo_funcs.h"
35 #include "WordLangTuple.h"
37 #include "frontends/Alert.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/font_metrics.h"
40 #include "frontends/LyXView.h"
41 #include "frontends/Painter.h"
43 #include "support/LAssert.h"
44 #include "support/lstrings.h"
63 int const ADD_TO_HEIGHT = 2;
64 int const ADD_TO_TABULAR_WIDTH = 2;
67 LyXTabular * paste_tabular = 0;
70 struct TabularFeature {
71 LyXTabular::Feature action;
76 TabularFeature tabularFeature[] =
78 { LyXTabular::APPEND_ROW, "append-row" },
79 { LyXTabular::APPEND_COLUMN, "append-column" },
80 { LyXTabular::DELETE_ROW, "delete-row" },
81 { LyXTabular::DELETE_COLUMN, "delete-column" },
82 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
83 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
84 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
85 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
86 { LyXTabular::ALIGN_LEFT, "align-left" },
87 { LyXTabular::ALIGN_RIGHT, "align-right" },
88 { LyXTabular::ALIGN_CENTER, "align-center" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
127 bool InsetTabular::hasPasteBuffer() const
129 return (paste_tabular != 0);
133 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
140 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
141 // for now make it always display as display() inset
143 the_locking_inset = 0;
144 old_locking_inset = 0;
147 actrow = actcell = 0;
157 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
159 : UpdatableInset(tab, same_id), buffer(&buf)
161 tabular.reset(new LyXTabular(buf.params,
162 this, *(tab.tabular), same_id));
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
177 InsetTabular::~InsetTabular()
183 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
185 return new InsetTabular(*this, buf, same_id);
189 void InsetTabular::write(Buffer const * buf, ostream & os) const
191 os << " Tabular" << endl;
192 tabular->Write(buf, os);
196 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
198 bool const old_format = (lex.getString() == "\\LyXTable");
200 tabular.reset(new LyXTabular(buf, this, lex));
208 string token = lex.getString();
209 while (lex.isOK() && (token != "\\end_inset")) {
211 token = lex.getString();
213 if (token != "\\end_inset") {
214 lex.printError("Missing \\end_inset at this point. "
220 int InsetTabular::ascent(BufferView *, LyXFont const &) const
222 return tabular->GetAscentOfRow(0);
226 int InsetTabular::descent(BufferView *, LyXFont const &) const
228 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
232 int InsetTabular::width(BufferView *, LyXFont const &) const
234 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
238 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
239 float & x, bool cleared) const
247 if (need_update == INIT) {
248 if (calculate_dimensions_of_cells(bv, font, true))
249 bv->text->status = LyXText::CHANGED_IN_DRAW;
254 Painter & pain = bv->painter();
260 UpdatableInset::draw(bv, font, baseline, x, cleared);
263 x += static_cast<float>(scroll());
265 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
266 (top_x != int(x)) || (top_baseline != baseline)))
268 int h = ascent(bv, font) + descent(bv, font);
269 int const tx = display() || !owner() ? 0 : top_x;
270 int w = tx ? width(bv, font) : pain.paperWidth();
271 int ty = baseline - ascent(bv, font);
275 if ((ty + h) > pain.paperHeight())
276 h = pain.paperHeight();
277 if ((top_x + w) > pain.paperWidth())
278 w = pain.paperWidth();
279 pain.fillRectangle(tx, ty, w, h, backgroundColor());
285 top_baseline = baseline;
286 x += ADD_TO_TABULAR_WIDTH;
290 first_visible_cell = -1;
291 for (i = 0; i < tabular->rows(); ++i) {
293 cell = tabular->GetCellNumber(i, 0);
294 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
295 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
297 baseline += tabular->GetDescentOfRow(i) +
298 tabular->GetAscentOfRow(i + 1) +
299 tabular->GetAdditionalHeight(i + 1);
302 for (j = 0; j < tabular->columns(); ++j) {
303 if (nx > bv->workWidth())
305 if (tabular->IsPartOfMultiColumn(i, j))
307 cx = nx + tabular->GetBeginningOfTextInCell(cell);
308 if (first_visible_cell < 0)
309 first_visible_cell = cell;
310 if (hasSelection()) {
311 drawCellSelection(pain, nx, baseline, i, j, cell);
314 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
315 drawCellLines(pain, nx, baseline, i, cell);
316 nx += tabular->GetWidthOfColumn(cell);
319 baseline += tabular->GetDescentOfRow(i) +
320 tabular->GetAscentOfRow(i + 1) +
321 tabular->GetAdditionalHeight(i + 1);
323 } else if (need_update == CELL) {
326 if (the_locking_inset &&
327 tabular->GetCellInset(actcell) != the_locking_inset)
329 Inset * inset = tabular->GetCellInset(cell);
331 inset != the_locking_inset && i < tabular->rows();
335 inset != the_locking_inset && j < tabular->columns();
338 if (tabular->IsPartOfMultiColumn(i, j))
340 nx += tabular->GetWidthOfColumn(cell);
342 inset = tabular->GetCellInset(cell);
344 if (tabular->row_of_cell(cell) > i) {
346 baseline += tabular->GetDescentOfRow(i) +
347 tabular->GetAscentOfRow(i + 1) +
348 tabular->GetAdditionalHeight(i + 1);
352 // compute baseline for actual row
353 for (i = 0; i < actrow; ++i) {
354 baseline += tabular->GetDescentOfRow(i) +
355 tabular->GetAscentOfRow(i + 1) +
356 tabular->GetAdditionalHeight(i + 1);
358 // now compute the right x position
359 cell = tabular->GetCellNumber(actrow, 0);
360 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
361 if (tabular->IsPartOfMultiColumn(actrow, j))
363 nx += tabular->GetWidthOfColumn(cell);
367 i = tabular->row_of_cell(cell);
368 if (the_locking_inset != tabular->GetCellInset(cell)) {
369 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
372 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
374 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
376 // Here we use rectangular backgroundColor patches to clean up
377 // within a cell around the cell's red inset box. As follows:
379 // +--------------------+
380 // | C | The rectangles are A, B and C
381 // | A |------------| B | below, origin top left (tx, ty),
382 // | | inset box | | dimensions w(idth), h(eight).
383 // +---+------------+---+ x grows rightward, y downward
385 // +--------------------+
388 // clear only if we didn't have a change
389 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
391 // clear before the inset
394 ty = baseline - tabular->GetAscentOfRow(i) + 1;
395 w = int(cx - nx - 1);
396 h = tabular->GetAscentOfRow(i) +
397 tabular->GetDescentOfRow(i) - 1;
398 pain.fillRectangle(tx, ty, w, h, backgroundColor());
399 // clear behind the inset
400 tx = int(cx + the_locking_inset->width(bv,font) + 1);
401 ty = baseline - tabular->GetAscentOfRow(i) + 1;
402 w = tabular->GetWidthOfColumn(cell) -
403 tabular->GetBeginningOfTextInCell(cell) -
404 the_locking_inset->width(bv,font) -
405 tabular->GetAdditionalWidth(cell) - 1;
406 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
407 pain.fillRectangle(tx, ty, w, h, backgroundColor());
408 // clear below the inset
410 ty = baseline + the_locking_inset->descent(bv, font) + 1;
411 w = tabular->GetWidthOfColumn(cell) -
412 tabular->GetAdditionalWidth(cell) - 1;
413 h = tabular->GetDescentOfRow(i) -
414 the_locking_inset->descent(bv, font) - 1;
415 pain.fillRectangle(tx, ty, w, h, backgroundColor());
416 // clear above the inset
418 ty = baseline - tabular->GetAscentOfRow(i) + 1;
419 w = tabular->GetWidthOfColumn(cell) -
420 tabular->GetAdditionalWidth(cell) - 1;
421 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
422 pain.fillRectangle(tx, ty, w, h, backgroundColor());
427 x -= ADD_TO_TABULAR_WIDTH;
428 x += width(bv, font);
429 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
431 for(Inset * inset = owner(); inset; ++i)
432 inset = inset->owner();
433 if (calculate_dimensions_of_cells(bv, font, false))
441 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
442 int row, int cell) const
444 int x2 = x + tabular->GetWidthOfColumn(cell);
447 if (!tabular->TopAlreadyDrawed(cell)) {
448 on_off = !tabular->TopLine(cell);
449 pain.line(x, baseline - tabular->GetAscentOfRow(row),
450 x2, baseline - tabular->GetAscentOfRow(row),
451 on_off ? LColor::tabularonoffline : LColor::tabularline,
452 on_off ? Painter::line_onoffdash : Painter::line_solid);
454 on_off = !tabular->BottomLine(cell);
455 pain.line(x, baseline + tabular->GetDescentOfRow(row),
456 x2, baseline + tabular->GetDescentOfRow(row),
457 on_off ? LColor::tabularonoffline : LColor::tabularline,
458 on_off ? Painter::line_onoffdash : Painter::line_solid);
459 if (!tabular->LeftAlreadyDrawed(cell)) {
460 on_off = !tabular->LeftLine(cell);
461 pain.line(x, baseline - tabular->GetAscentOfRow(row),
462 x, baseline + tabular->GetDescentOfRow(row),
463 on_off ? LColor::tabularonoffline : LColor::tabularline,
464 on_off ? Painter::line_onoffdash : Painter::line_solid);
466 on_off = !tabular->RightLine(cell);
467 pain.line(x2 - tabular->GetAdditionalWidth(cell),
468 baseline - tabular->GetAscentOfRow(row),
469 x2 - tabular->GetAdditionalWidth(cell),
470 baseline + tabular->GetDescentOfRow(row),
471 on_off ? LColor::tabularonoffline : LColor::tabularline,
472 on_off ? Painter::line_onoffdash : Painter::line_solid);
476 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
477 int row, int column, int cell) const
479 lyx::Assert(hasSelection());
480 int cs = tabular->column_of_cell(sel_cell_start);
481 int ce = tabular->column_of_cell(sel_cell_end);
484 cs = tabular->column_of_cell(sel_cell_end);
486 ce = tabular->right_column_of_cell(sel_cell_end);
489 int rs = tabular->row_of_cell(sel_cell_start);
490 int re = tabular->row_of_cell(sel_cell_end);
494 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
495 int w = tabular->GetWidthOfColumn(cell);
496 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
497 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
498 w, h, LColor::selection);
503 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
509 owner()->update(bv, font, true);
516 if (calculate_dimensions_of_cells(bv, font, true))
519 owner()->update(bv, font, true);
523 if (the_locking_inset)
524 the_locking_inset->update(bv, font, reinit);
525 if (need_update < FULL &&
526 bv->text->status() == LyXText::NEED_MORE_REFRESH)
531 switch (need_update) {
535 if (calculate_dimensions_of_cells(bv, font, false)) {
550 string const InsetTabular::editMessage() const
552 return _("Opened Tabular Inset");
556 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
558 UpdatableInset::edit(bv, x, y, button);
560 if (!bv->lockInset(this)) {
561 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
565 the_locking_inset = 0;
571 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
572 activateCellInsetAbs(bv, x, y, button);
577 void InsetTabular::edit(BufferView * bv, bool front)
579 UpdatableInset::edit(bv, front);
581 if (!bv->lockInset(this)) {
582 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
587 the_locking_inset = 0;
591 if (isRightToLeft(bv))
592 actcell = tabular->GetLastCellInRow(0);
596 if (isRightToLeft(bv))
597 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
599 actcell = tabular->GetNumberOfCells() - 1;
607 void InsetTabular::insetUnlock(BufferView * bv)
609 if (the_locking_inset) {
610 the_locking_inset->insetUnlock(bv);
611 updateLocal(bv, CELL, false);
612 the_locking_inset = 0;
618 if (scroll(false) || hasSelection()) {
623 updateLocal(bv, FULL, false);
628 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
629 bool mark_dirty) const
633 calculate_dimensions_of_cells(bv, font, true);
635 if (!locked && what == CELL)
637 if (need_update < what) // only set this if it has greater update
640 if (need_update != NONE) {
641 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
648 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
650 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
655 if (inset == tabular->GetCellInset(actcell)) {
656 lyxerr[Debug::INSETTEXT] << "OK" << endl;
657 the_locking_inset = tabular->GetCellInset(actcell);
660 } else if (!the_locking_inset) {
661 int const n = tabular->GetNumberOfCells();
662 int const id = inset->id();
663 for (int i = 0; i < n; ++i) {
664 InsetText * in = tabular->GetCellInset(i);
667 the_locking_inset = in;
672 if (in->getInsetFromID(id)) {
675 return the_locking_inset->lockInsetInInset(bv, inset);
678 } else if (the_locking_inset && (the_locking_inset == inset)) {
679 lyxerr[Debug::INSETTEXT] << "OK" << endl;
681 } else if (the_locking_inset) {
682 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
683 return the_locking_inset->lockInsetInInset(bv, inset);
685 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
690 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
693 if (!the_locking_inset)
695 if (the_locking_inset == inset) {
696 the_locking_inset->insetUnlock(bv);
698 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
704 updateLocal(bv, CELL, false);
705 // this has to be here otherwise we don't redraw the cell!
706 the_locking_inset = 0;
707 // showInsetCursor(bv, false);
710 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
711 if (inset->lyxCode() == TABULAR_CODE &&
712 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
713 bv->owner()->getDialogs().updateTabular(this);
722 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
724 Inset * tl_inset = inset;
725 // look if this inset is really inside myself!
726 while(tl_inset->owner() && tl_inset->owner() != this)
727 tl_inset = tl_inset->owner();
728 // if we enter here it's not ower inset
729 if (!tl_inset->owner())
731 // we only have to do this if this is a subinset of our cells
732 if (tl_inset != inset) {
733 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
736 updateLocal(bv, CELL, false);
741 int InsetTabular::insetInInsetY() const
743 if (!the_locking_inset)
745 return inset_y + the_locking_inset->insetInInsetY();
749 UpdatableInset * InsetTabular::getLockingInset() const
751 return the_locking_inset ? the_locking_inset->getLockingInset() :
752 const_cast<InsetTabular *>(this);
756 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
760 if (the_locking_inset)
761 return the_locking_inset->getFirstLockingInsetOfType(c);
766 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
768 if (the_locking_inset)
769 return the_locking_inset->insertInset(bv, inset);
774 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
776 if (hasSelection() && cmd.button() == mouse_button::button3)
779 if (hasSelection()) {
781 updateLocal(cmd.view(), SELECTION, false);
784 int const ocell = actcell;
785 int const orow = actrow;
786 BufferView * bv = cmd.view();
791 the_locking_inset = 0;
795 setPos(bv, cmd.x, cmd.y);
797 updateLocal(bv, NONE, false);
800 if (cmd.button() == mouse_button::button3) {
801 if ((ocell != actcell) && the_locking_inset) {
802 the_locking_inset->insetUnlock(bv);
803 updateLocal(bv, CELL, false);
804 the_locking_inset = 0;
811 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
813 FuncRequest cmd1 = cmd;
817 if ((ocell == actcell) && the_locking_inset && inset_hit) {
819 the_locking_inset->localDispatch(cmd1);
823 if (the_locking_inset) {
824 the_locking_inset->insetUnlock(bv);
825 updateLocal(bv, CELL, false);
826 the_locking_inset = 0;
829 if (cmd.button() == mouse_button::button2) {
830 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
834 if (inset_hit && bv->theLockingInset()) {
835 if (!bv->lockInset(static_cast<UpdatableInset*>
836 (tabular->GetCellInset(actcell))))
838 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
841 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 lfunMouseRelease(cmd);
924 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
929 unlockInsetInInset(bv, the_locking_inset);
930 if (cmd.action == LFUN_TAB)
931 moveNextCell(bv, old_locking_inset != 0);
933 movePrevCell(bv, old_locking_inset != 0);
936 updateLocal(bv, SELECTION, false);
937 if (!the_locking_inset) {
939 return DISPATCHED_NOUPDATE;
942 // this to avoid compiler warnings.
948 kb_action action = cmd.action;
949 string arg = cmd.argument;
950 if (the_locking_inset) {
951 result = the_locking_inset->localDispatch(cmd);
952 if (result == DISPATCHED_NOUPDATE) {
955 if (sc != scroll()) { // inset has been scrolled
956 the_locking_inset->toggleInsetCursor(bv);
957 updateLocal(bv, FULL, false);
958 the_locking_inset->toggleInsetCursor(bv);
961 } else if (result == DISPATCHED) {
962 the_locking_inset->toggleInsetCursor(bv);
963 updateLocal(bv, CELL, false);
964 the_locking_inset->toggleInsetCursor(bv);
966 } else if (result == FINISHED_UP) {
968 } else if (result == FINISHED_DOWN) {
970 } else if (result == FINISHED_RIGHT) {
978 // --- Cursor Movements ----------------------------------
979 case LFUN_RIGHTSEL: {
980 int const start = hasSelection() ? sel_cell_start : actcell;
981 if (tabular->IsLastCellInRow(actcell)) {
982 setSelection(start, actcell);
987 // if we are starting a selection, only select
988 // the current cell at the beginning
989 if (hasSelection()) {
990 moveRight(bv, false);
993 setSelection(start, end);
994 updateLocal(bv, SELECTION, false);
998 result = moveRight(bv);
1001 updateLocal(bv, SELECTION, false);
1003 case LFUN_LEFTSEL: {
1004 int const start = hasSelection() ? sel_cell_start : actcell;
1005 if (tabular->IsFirstCellInRow(actcell)) {
1006 setSelection(start, actcell);
1011 // if we are starting a selection, only select
1012 // the current cell at the beginning
1013 if (hasSelection()) {
1014 moveLeft(bv, false);
1017 setSelection(start, end);
1018 updateLocal(bv, SELECTION, false);
1022 result = moveLeft(bv);
1025 updateLocal(bv, SELECTION, false);
1027 case LFUN_DOWNSEL: {
1028 int const start = hasSelection() ? sel_cell_start : actcell;
1029 int const ocell = actcell;
1030 // if we are starting a selection, only select
1031 // the current cell at the beginning
1032 if (hasSelection()) {
1033 moveDown(bv, false);
1034 if ((ocell == sel_cell_end) ||
1035 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1036 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1038 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1040 setSelection(start, start);
1042 updateLocal(bv, SELECTION, false);
1046 result = moveDown(bv, old_locking_inset != 0);
1049 updateLocal(bv, SELECTION, false);
1053 int const start = hasSelection() ? sel_cell_start : actcell;
1054 int const ocell = actcell;
1055 // if we are starting a selection, only select
1056 // the current cell at the beginning
1057 if (hasSelection()) {
1059 if ((ocell == sel_cell_end) ||
1060 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1061 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1063 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1065 setSelection(start, start);
1067 updateLocal(bv, SELECTION, false);
1071 result = moveUp(bv, old_locking_inset != 0);
1074 updateLocal(bv, SELECTION, false);
1077 UpdateCodes code = CURSOR;
1082 int column = actcol;
1083 unlockInsetInInset(bv, the_locking_inset);
1084 if (bv->text->first_y + bv->painter().paperHeight() <
1085 (top_baseline + tabular->GetHeightOfTabular()))
1087 bv->scrollDocView(bv->text->first_y + bv->painter().paperHeight());
1089 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1091 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1094 updateLocal(bv, code, false);
1098 UpdateCodes code = CURSOR;
1103 int column = actcol;
1104 unlockInsetInInset(bv, the_locking_inset);
1105 if (top_baseline < 0) {
1106 bv->scrollDocView(bv->text->first_y - bv->painter().paperHeight());
1108 if (top_baseline > 0)
1111 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1116 updateLocal(bv, code, false);
1119 // none of these make sense for insettabular,
1120 // but we must catch them to prevent any
1121 // selection from being confused
1125 case LFUN_WORDLEFTSEL:
1126 case LFUN_WORDRIGHT:
1127 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());
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 > 10)
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);
1837 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1838 string const & special, bool & flag)
1840 if (special == "dl_above") {
1843 } else if (special == "dl_below") {
1844 ltt.bottomDL = flag;
1846 } else if (special == "empty") {
1856 void InsetTabular::tabularFeatures(BufferView * bv,
1857 LyXTabular::Feature feature,
1858 string const & value)
1864 bool setLines = false;
1865 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1866 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1869 case LyXTabular::M_ALIGN_LEFT:
1870 case LyXTabular::ALIGN_LEFT:
1871 setAlign = LYX_ALIGN_LEFT;
1873 case LyXTabular::M_ALIGN_RIGHT:
1874 case LyXTabular::ALIGN_RIGHT:
1875 setAlign = LYX_ALIGN_RIGHT;
1877 case LyXTabular::M_ALIGN_CENTER:
1878 case LyXTabular::ALIGN_CENTER:
1879 setAlign = LYX_ALIGN_CENTER;
1881 case LyXTabular::M_VALIGN_TOP:
1882 case LyXTabular::VALIGN_TOP:
1883 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1885 case LyXTabular::M_VALIGN_BOTTOM:
1886 case LyXTabular::VALIGN_BOTTOM:
1887 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1889 case LyXTabular::M_VALIGN_CENTER:
1890 case LyXTabular::VALIGN_CENTER:
1891 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1896 if (hasSelection()) {
1897 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1899 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1900 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1902 setUndo(bv, Undo::FINISH,
1903 bv->text->cursor.par(),
1904 bv->text->cursor.par()->next());
1906 int row = tabular->row_of_cell(actcell);
1907 int column = tabular->column_of_cell(actcell);
1909 LyXTabular::ltType ltt;
1912 case LyXTabular::SET_PWIDTH:
1914 LyXLength const vallen(value);
1915 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1917 bool const update = (tmplen != vallen);
1918 tabular->SetColumnPWidth(actcell, vallen);
1921 for (int i = 0; i < tabular->rows(); ++i) {
1922 cell = tabular->GetCellNumber(i,column);
1923 tabular->GetCellInset(cell)->resizeLyXText(bv);
1925 updateLocal(bv, INIT, true);
1929 case LyXTabular::SET_MPWIDTH:
1931 LyXLength const vallen(value);
1932 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1934 bool const update = (tmplen != vallen);
1935 tabular->SetMColumnPWidth(actcell, vallen);
1937 for (int i = 0; i < tabular->rows(); ++i) {
1938 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1941 updateLocal(bv, INIT, true);
1945 case LyXTabular::SET_SPECIAL_COLUMN:
1946 case LyXTabular::SET_SPECIAL_MULTI:
1947 tabular->SetAlignSpecial(actcell,value,feature);
1948 updateLocal(bv, FULL, true);
1950 case LyXTabular::APPEND_ROW:
1951 // append the row into the tabular
1952 unlockInsetInInset(bv, the_locking_inset);
1953 tabular->AppendRow(bv->buffer()->params, actcell);
1954 updateLocal(bv, INIT, true);
1956 case LyXTabular::APPEND_COLUMN:
1957 // append the column into the tabular
1958 unlockInsetInInset(bv, the_locking_inset);
1959 tabular->AppendColumn(bv->buffer()->params, actcell);
1960 actcell = tabular->GetCellNumber(row, column);
1961 updateLocal(bv, INIT, true);
1963 case LyXTabular::DELETE_ROW:
1964 unlockInsetInInset(bv, the_locking_inset);
1965 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1966 tabular->DeleteRow(sel_row_start);
1968 if (sel_row_start >= tabular->rows())
1970 actcell = tabular->GetCellNumber(sel_row_start, column);
1972 updateLocal(bv, INIT, true);
1974 case LyXTabular::DELETE_COLUMN:
1975 unlockInsetInInset(bv, the_locking_inset);
1976 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1977 tabular->DeleteColumn(sel_col_start);
1979 if (sel_col_start >= tabular->columns())
1981 actcell = tabular->GetCellNumber(row, sel_col_start);
1983 updateLocal(bv, INIT, true);
1985 case LyXTabular::M_TOGGLE_LINE_TOP:
1987 case LyXTabular::TOGGLE_LINE_TOP:
1989 bool lineSet = !tabular->TopLine(actcell, flag);
1990 for (int i = sel_row_start; i <= sel_row_end; ++i)
1991 for (int j = sel_col_start; j <= sel_col_end; ++j)
1992 tabular->SetTopLine(
1993 tabular->GetCellNumber(i, j),
1995 updateLocal(bv, INIT, true);
1999 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2001 case LyXTabular::TOGGLE_LINE_BOTTOM:
2003 bool lineSet = !tabular->BottomLine(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->SetBottomLine(
2007 tabular->GetCellNumber(i, j),
2010 updateLocal(bv, INIT, true);
2014 case LyXTabular::M_TOGGLE_LINE_LEFT:
2016 case LyXTabular::TOGGLE_LINE_LEFT:
2018 bool lineSet = !tabular->LeftLine(actcell, flag);
2019 for (int i = sel_row_start; i <= sel_row_end; ++i)
2020 for (int j = sel_col_start; j <= sel_col_end; ++j)
2021 tabular->SetLeftLine(
2022 tabular->GetCellNumber(i,j),
2025 updateLocal(bv, INIT, true);
2029 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2031 case LyXTabular::TOGGLE_LINE_RIGHT:
2033 bool lineSet = !tabular->RightLine(actcell, flag);
2034 for (int i = sel_row_start; i <= sel_row_end; ++i)
2035 for (int j = sel_col_start; j <= sel_col_end; ++j)
2036 tabular->SetRightLine(
2037 tabular->GetCellNumber(i,j),
2040 updateLocal(bv, INIT, true);
2044 case LyXTabular::M_ALIGN_LEFT:
2045 case LyXTabular::M_ALIGN_RIGHT:
2046 case LyXTabular::M_ALIGN_CENTER:
2048 case LyXTabular::ALIGN_LEFT:
2049 case LyXTabular::ALIGN_RIGHT:
2050 case LyXTabular::ALIGN_CENTER:
2051 for (int i = sel_row_start; i <= sel_row_end; ++i)
2052 for (int j = sel_col_start; j <= sel_col_end; ++j)
2053 tabular->SetAlignment(
2054 tabular->GetCellNumber(i, j),
2057 updateLocal(bv, INIT, true);
2059 case LyXTabular::M_VALIGN_TOP:
2060 case LyXTabular::M_VALIGN_BOTTOM:
2061 case LyXTabular::M_VALIGN_CENTER:
2063 case LyXTabular::VALIGN_TOP:
2064 case LyXTabular::VALIGN_BOTTOM:
2065 case LyXTabular::VALIGN_CENTER:
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->SetVAlignment(
2069 tabular->GetCellNumber(i, j),
2071 updateLocal(bv, INIT, true);
2073 case LyXTabular::MULTICOLUMN:
2075 if (sel_row_start != sel_row_end) {
2076 Alert::alert(_("Impossible Operation!"),
2077 _("Multicolumns can only be horizontally."),
2081 // just multicol for one Single Cell
2082 if (!hasSelection()) {
2083 // check wether we are completly in a multicol
2084 if (tabular->IsMultiColumn(actcell)) {
2085 tabular->UnsetMultiColumn(actcell);
2086 updateLocal(bv, INIT, true);
2088 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2089 updateLocal(bv, CELL, true);
2093 // we have a selection so this means we just add all this
2094 // cells to form a multicolumn cell
2098 if (sel_cell_start > sel_cell_end) {
2099 s_start = sel_cell_end;
2100 s_end = sel_cell_start;
2102 s_start = sel_cell_start;
2103 s_end = sel_cell_end;
2105 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2108 updateLocal(bv, INIT, true);
2111 case LyXTabular::SET_ALL_LINES:
2113 case LyXTabular::UNSET_ALL_LINES:
2114 for (int i = sel_row_start; i <= sel_row_end; ++i)
2115 for (int j = sel_col_start; j <= sel_col_end; ++j)
2116 tabular->SetAllLines(
2117 tabular->GetCellNumber(i,j), setLines);
2118 updateLocal(bv, INIT, true);
2120 case LyXTabular::SET_LONGTABULAR:
2121 tabular->SetLongTabular(true);
2122 updateLocal(bv, INIT, true); // because this toggles displayed
2124 case LyXTabular::UNSET_LONGTABULAR:
2125 tabular->SetLongTabular(false);
2126 updateLocal(bv, INIT, true); // because this toggles displayed
2128 case LyXTabular::SET_ROTATE_TABULAR:
2129 tabular->SetRotateTabular(true);
2131 case LyXTabular::UNSET_ROTATE_TABULAR:
2132 tabular->SetRotateTabular(false);
2134 case LyXTabular::SET_ROTATE_CELL:
2135 for (int i = sel_row_start; i <= sel_row_end; ++i)
2136 for (int j = sel_col_start; j<=sel_col_end; ++j)
2137 tabular->SetRotateCell(
2138 tabular->GetCellNumber(i, j),
2141 case LyXTabular::UNSET_ROTATE_CELL:
2142 for (int i = sel_row_start; i <= sel_row_end; ++i)
2143 for (int j = sel_col_start; j <= sel_col_end; ++j)
2144 tabular->SetRotateCell(
2145 tabular->GetCellNumber(i, j), false);
2147 case LyXTabular::SET_USEBOX:
2149 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2150 if (val == tabular->GetUsebox(actcell))
2151 val = LyXTabular::BOX_NONE;
2152 for (int i = sel_row_start; i <= sel_row_end; ++i)
2153 for (int j = sel_col_start; j <= sel_col_end; ++j)
2155 tabular->GetCellNumber(i, j), val);
2158 case LyXTabular::UNSET_LTFIRSTHEAD:
2160 case LyXTabular::SET_LTFIRSTHEAD:
2161 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2162 checkLongtableSpecial(ltt, value, flag);
2163 tabular->SetLTHead(row, flag, ltt, true);
2165 case LyXTabular::UNSET_LTHEAD:
2167 case LyXTabular::SET_LTHEAD:
2168 (void)tabular->GetRowOfLTHead(row, ltt);
2169 checkLongtableSpecial(ltt, value, flag);
2170 tabular->SetLTHead(row, flag, ltt, false);
2172 case LyXTabular::UNSET_LTFOOT:
2174 case LyXTabular::SET_LTFOOT:
2175 (void)tabular->GetRowOfLTFoot(row, ltt);
2176 checkLongtableSpecial(ltt, value, flag);
2177 tabular->SetLTFoot(row, flag, ltt, false);
2179 case LyXTabular::UNSET_LTLASTFOOT:
2181 case LyXTabular::SET_LTLASTFOOT:
2182 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2183 checkLongtableSpecial(ltt, value, flag);
2184 tabular->SetLTFoot(row, flag, ltt, true);
2186 case LyXTabular::SET_LTNEWPAGE:
2188 bool what = !tabular->GetLTNewPage(row);
2189 tabular->SetLTNewPage(row, what);
2192 // dummy stuff just to avoid warnings
2193 case LyXTabular::LAST_ACTION:
2199 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2202 UpdatableInset * inset =
2203 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2204 LyXFont font(LyXFont::ALL_SANE);
2206 x = inset->x() + inset->width(bv, font);
2207 y = inset->descent(bv, font);
2209 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2210 //inset_y = cursor.y();
2211 inset->edit(bv, x, y, button);
2212 if (!the_locking_inset)
2214 updateLocal(bv, CELL, false);
2215 return (the_locking_inset != 0);
2219 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2220 mouse_button::state button)
2222 inset_x = cursor_.x()
2223 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2224 inset_y = cursor_.y();
2225 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2229 bool InsetTabular::insetHit(BufferView *, int x, int) const
2232 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2236 // This returns paperWidth() if the cell-width is unlimited or the width
2237 // in pixels if we have a pwidth for this cell.
2238 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2240 LyXLength const len = tabular->GetPWidth(cell);
2244 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2248 int InsetTabular::getMaxWidth(BufferView * bv,
2249 UpdatableInset const * inset) const
2251 int cell = tabular->GetCellFromInset(inset, actcell);
2254 lyxerr << "Own inset not found, shouldn't really happen!"
2259 int w = getMaxWidthOfCell(bv, cell);
2261 // because the inset then subtracts it's top_x and owner->x()
2262 w += (inset->x() - top_x);
2269 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2271 resizeLyXText(bv, recursive);
2275 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2278 for(int i = 0; i < tabular->rows(); ++i) {
2279 for(int j = 0; j < tabular->columns(); ++j) {
2280 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2288 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2289 bool const recursive) const
2291 if (the_locking_inset)
2292 return the_locking_inset->getLyXText(bv, recursive);
2294 // if we're locked lock the actual insettext and return it's LyXText!!!
2296 UpdatableInset * inset =
2297 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2298 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2299 return the_locking_inset->getLyXText(bv, recursive);
2302 return Inset::getLyXText(bv, recursive);
2306 bool InsetTabular::showInsetDialog(BufferView * bv) const
2308 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2309 bv->owner()->getDialogs().
2310 showTabular(const_cast<InsetTabular *>(this));
2315 void InsetTabular::openLayoutDialog(BufferView * bv) const
2317 if (the_locking_inset) {
2318 InsetTabular * i = static_cast<InsetTabular *>
2319 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2321 i->openLayoutDialog(bv);
2325 bv->owner()->getDialogs().showTabular(
2326 const_cast<InsetTabular *>(this));
2331 // function returns an object as defined in func_status.h:
2332 // states OK, Unknown, Disabled, On, Off.
2334 FuncStatus InsetTabular::getStatus(string const & what) const
2336 int action = LyXTabular::LAST_ACTION;
2340 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2341 string const tmp = tabularFeature[i].feature;
2342 if (tmp == what.substr(0, tmp.length())) {
2343 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2344 // tabularFeatures[i].feature.length())) {
2345 action = tabularFeature[i].action;
2349 if (action == LyXTabular::LAST_ACTION) {
2351 return status.unknown(true);
2354 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2359 LyXTabular::ltType dummyltt;
2362 if (hasSelection()) {
2363 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2365 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2369 case LyXTabular::SET_PWIDTH:
2370 case LyXTabular::SET_MPWIDTH:
2371 case LyXTabular::SET_SPECIAL_COLUMN:
2372 case LyXTabular::SET_SPECIAL_MULTI:
2373 return status.disabled(true);
2375 case LyXTabular::APPEND_ROW:
2376 case LyXTabular::APPEND_COLUMN:
2377 case LyXTabular::DELETE_ROW:
2378 case LyXTabular::DELETE_COLUMN:
2379 case LyXTabular::SET_ALL_LINES:
2380 case LyXTabular::UNSET_ALL_LINES:
2381 return status.clear();
2383 case LyXTabular::MULTICOLUMN:
2384 status.setOnOff(tabular->IsMultiColumn(actcell));
2386 case LyXTabular::M_TOGGLE_LINE_TOP:
2388 case LyXTabular::TOGGLE_LINE_TOP:
2389 status.setOnOff(tabular->TopLine(actcell, flag));
2391 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2393 case LyXTabular::TOGGLE_LINE_BOTTOM:
2394 status.setOnOff(tabular->BottomLine(actcell, flag));
2396 case LyXTabular::M_TOGGLE_LINE_LEFT:
2398 case LyXTabular::TOGGLE_LINE_LEFT:
2399 status.setOnOff(tabular->LeftLine(actcell, flag));
2401 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2403 case LyXTabular::TOGGLE_LINE_RIGHT:
2404 status.setOnOff(tabular->RightLine(actcell, flag));
2406 case LyXTabular::M_ALIGN_LEFT:
2408 case LyXTabular::ALIGN_LEFT:
2409 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2411 case LyXTabular::M_ALIGN_RIGHT:
2413 case LyXTabular::ALIGN_RIGHT:
2414 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2416 case LyXTabular::M_ALIGN_CENTER:
2418 case LyXTabular::ALIGN_CENTER:
2419 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2421 case LyXTabular::M_VALIGN_TOP:
2423 case LyXTabular::VALIGN_TOP:
2424 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2426 case LyXTabular::M_VALIGN_BOTTOM:
2428 case LyXTabular::VALIGN_BOTTOM:
2429 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2431 case LyXTabular::M_VALIGN_CENTER:
2433 case LyXTabular::VALIGN_CENTER:
2434 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2436 case LyXTabular::SET_LONGTABULAR:
2437 status.setOnOff(tabular->IsLongTabular());
2439 case LyXTabular::UNSET_LONGTABULAR:
2440 status.setOnOff(!tabular->IsLongTabular());
2442 case LyXTabular::SET_ROTATE_TABULAR:
2443 status.setOnOff(tabular->GetRotateTabular());
2445 case LyXTabular::UNSET_ROTATE_TABULAR:
2446 status.setOnOff(!tabular->GetRotateTabular());
2448 case LyXTabular::SET_ROTATE_CELL:
2449 status.setOnOff(tabular->GetRotateCell(actcell));
2451 case LyXTabular::UNSET_ROTATE_CELL:
2452 status.setOnOff(!tabular->GetRotateCell(actcell));
2454 case LyXTabular::SET_USEBOX:
2455 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2457 case LyXTabular::SET_LTFIRSTHEAD:
2458 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2460 case LyXTabular::SET_LTHEAD:
2461 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2463 case LyXTabular::SET_LTFOOT:
2464 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2466 case LyXTabular::SET_LTLASTFOOT:
2467 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2469 case LyXTabular::SET_LTNEWPAGE:
2470 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2474 status.disabled(true);
2481 vector<string> const InsetTabular::getLabelList() const
2483 return tabular->getLabelList();
2487 bool InsetTabular::copySelection(BufferView * bv)
2489 if (!hasSelection())
2492 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2493 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2494 if (sel_col_start > sel_col_end) {
2495 sel_col_start = sel_col_end;
2496 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2498 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2500 int const columns = sel_col_end - sel_col_start + 1;
2502 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2503 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2504 if (sel_row_start > sel_row_end) {
2505 swap(sel_row_start, sel_row_end);
2507 int const rows = sel_row_end - sel_row_start + 1;
2509 delete paste_tabular;
2510 paste_tabular = new LyXTabular(bv->buffer()->params,
2511 this, *tabular); // rows, columns);
2512 for (int i = 0; i < sel_row_start; ++i)
2513 paste_tabular->DeleteRow(0);
2514 while (paste_tabular->rows() > rows)
2515 paste_tabular->DeleteRow(rows);
2516 paste_tabular->SetTopLine(0, true, true);
2517 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2519 for (int i = 0; i < sel_col_start; ++i)
2520 paste_tabular->DeleteColumn(0);
2521 while (paste_tabular->columns() > columns)
2522 paste_tabular->DeleteColumn(columns);
2523 paste_tabular->SetLeftLine(0, true, true);
2524 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2528 paste_tabular->ascii(bv->buffer(), sstr,
2529 (int)parOwner()->params().depth(), true, '\t');
2530 bv->stuffClipboard(sstr.str().c_str());
2535 bool InsetTabular::pasteSelection(BufferView * bv)
2540 for (int r1 = 0, r2 = actrow;
2541 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2543 for(int c1 = 0, c2 = actcol;
2544 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2546 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2547 tabular->IsPartOfMultiColumn(r2,c2))
2549 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2553 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2557 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2558 int const n2 = tabular->GetCellNumber(r2, c2);
2559 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2560 tabular->GetCellInset(n2)->setOwner(this);
2561 tabular->GetCellInset(n2)->deleteLyXText(bv);
2568 bool InsetTabular::cutSelection()
2570 if (!hasSelection())
2573 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2574 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2575 if (sel_col_start > sel_col_end) {
2576 sel_col_start = sel_col_end;
2577 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2579 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2581 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2582 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2583 if (sel_row_start > sel_row_end) {
2584 swap(sel_row_start, sel_row_end);
2586 if (sel_cell_start > sel_cell_end) {
2587 swap(sel_cell_start, sel_cell_end);
2589 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2590 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2591 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2598 bool InsetTabular::isRightToLeft(BufferView * bv)
2600 return bv->getParentLanguage(this)->RightToLeft();
2604 bool InsetTabular::nodraw() const
2606 if (!UpdatableInset::nodraw() && the_locking_inset)
2607 return the_locking_inset->nodraw();
2608 return UpdatableInset::nodraw();
2612 int InsetTabular::scroll(bool recursive) const
2614 int sx = UpdatableInset::scroll(false);
2616 if (recursive && the_locking_inset)
2617 sx += the_locking_inset->scroll(recursive);
2623 bool InsetTabular::doClearArea() const
2625 return !locked || (need_update & (FULL|INIT));
2629 void InsetTabular::getSelection(int & srow, int & erow,
2630 int & scol, int & ecol) const
2632 int const start = hasSelection() ? sel_cell_start : actcell;
2633 int const end = hasSelection() ? sel_cell_end : actcell;
2635 srow = tabular->row_of_cell(start);
2636 erow = tabular->row_of_cell(end);
2641 scol = tabular->column_of_cell(start);
2642 ecol = tabular->column_of_cell(end);
2646 ecol = tabular->right_column_of_cell(end);
2651 Paragraph * InsetTabular::getParFromID(int id) const
2654 for(int i = 0; i < tabular->rows(); ++i) {
2655 for(int j = 0; j < tabular->columns(); ++j) {
2656 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2664 Paragraph * InsetTabular::firstParagraph() const
2666 if (the_locking_inset)
2667 return the_locking_inset->firstParagraph();
2672 Paragraph * InsetTabular::getFirstParagraph(int i) const
2674 return (i < tabular->GetNumberOfCells())
2675 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2680 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2682 if (the_locking_inset)
2683 return the_locking_inset->cursor(bv);
2684 return Inset::cursor(bv);
2688 Inset * InsetTabular::getInsetFromID(int id_arg) const
2691 return const_cast<InsetTabular *>(this);
2694 for(int i = 0; i < tabular->rows(); ++i) {
2695 for(int j = 0; j < tabular->columns(); ++j) {
2696 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2705 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2708 if (the_locking_inset) {
2709 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2710 if (!word.word().empty()) {
2714 if (tabular->IsLastCell(actcell)) {
2715 bv->unlockInset(const_cast<InsetTabular *>(this));
2717 return WordLangTuple();
2721 // otherwise we have to lock the next inset and ask for it's selecttion
2722 UpdatableInset * inset =
2723 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2724 inset->edit(bv, 0, 0, mouse_button::none);
2725 WordLangTuple word(selectNextWordInt(bv, value));
2727 if (!word.word().empty())
2733 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2735 // when entering this function the inset should be ALWAYS locked!
2736 lyx::Assert(the_locking_inset);
2738 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2739 if (!word.word().empty())
2742 if (tabular->IsLastCell(actcell)) {
2743 bv->unlockInset(const_cast<InsetTabular *>(this));
2744 return WordLangTuple();
2747 // otherwise we have to lock the next inset and ask for it's selecttion
2748 UpdatableInset * inset =
2749 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2751 return selectNextWordInt(bv, value);
2755 void InsetTabular::selectSelectedWord(BufferView * bv)
2757 if (the_locking_inset) {
2758 the_locking_inset->selectSelectedWord(bv);
2765 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2767 if (the_locking_inset) {
2768 the_locking_inset->toggleSelection(bv, kill_selection);
2773 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2776 if (the_locking_inset) {
2777 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2778 updateLocal(bv, CELL, false);
2781 if (tabular->IsLastCell(actcell))
2785 InsetText * inset = tabular->GetCellInset(actcell);
2786 if (inset->searchForward(bv, str, cs, mw)) {
2787 updateLocal(bv, FULL, false);
2790 while (!tabular->IsLastCell(actcell)) {
2792 inset = tabular->GetCellInset(actcell);
2793 if (inset->searchForward(bv, str, cs, mw)) {
2794 updateLocal(bv, FULL, false);
2802 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2805 if (the_locking_inset) {
2806 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2807 updateLocal(bv, CELL, false);
2812 actcell = tabular->GetNumberOfCells();
2816 InsetText * inset = tabular->GetCellInset(actcell);
2817 if (inset->searchBackward(bv, str, cs, mw)) {
2818 updateLocal(bv, CELL, false);
2826 bool InsetTabular::insetAllowed(Inset::Code code) const
2828 if (the_locking_inset)
2829 return the_locking_inset->insetAllowed(code);
2830 // we return true here because if the inset is not locked someone
2831 // wants to insert something in one of our insettexts and we generally
2837 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2839 const int cell = tabular->GetCellFromInset(in, actcell);
2842 return tabular->GetPWidth(cell).zero();
2844 // well we didn't obviously find it so maybe our owner knows more
2846 return owner()->forceDefaultParagraphs(in);
2847 // if we're here there is really something strange going on!!!
2851 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2854 if (buf.length() <= 0)
2860 string::size_type len = buf.length();
2861 string::size_type p = 0;
2864 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2873 maxCols = max(cols, maxCols);
2879 maxCols = max(cols, maxCols);
2880 LyXTabular * loctab;
2885 delete paste_tabular;
2886 paste_tabular = new LyXTabular(bv->buffer()->params,
2887 this, rows, maxCols);
2888 loctab = paste_tabular;
2891 loctab = tabular.get();
2896 string::size_type op = 0;
2897 int cells = loctab->GetNumberOfCells();
2900 rows = loctab->rows();
2901 int const columns = loctab->columns();
2902 while ((cell < cells) && (p < len) && (row < rows) &&
2903 (p = buf.find_first_of("\t\n", p)) != string::npos)
2909 // we can only set this if we are not too far right
2910 if (cols < columns) {
2911 InsetText * ti = loctab->GetCellInset(cell);
2912 LyXFont const font = ti->getLyXText(bv)->
2913 getFont(bv->buffer(), ti->paragraph(), 0);
2914 ti->setText(buf.substr(op, p-op), font);
2920 // we can only set this if we are not too far right
2921 if (cols < columns) {
2922 InsetText * ti = loctab->GetCellInset(cell);
2923 LyXFont const font = ti->getLyXText(bv)->
2924 getFont(bv->buffer(), ti->paragraph(), 0);
2925 ti->setText(buf.substr(op, p-op), font);
2930 cell = loctab->GetCellNumber(row, cols);
2936 // check for the last cell if there is no trailing '\n'
2937 if ((cell < cells) && (op < len)) {
2938 InsetText * ti = loctab->GetCellInset(cell);
2939 LyXFont const font = ti->getLyXText(bv)->
2940 getFont(bv->buffer(), ti->paragraph(), 0);
2941 ti->setText(buf.substr(op, len-op), font);
2948 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2950 int const rows = tabular->rows();
2951 int const columns = tabular->columns();
2952 for (int i = 0; i < rows; ++i) {
2953 for (int j = 0; j < columns; ++j) {
2954 tabular->GetCellInset(i,j)->addPreview(loader);