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
13 #include "insettabular.h"
14 #include "insettext.h"
17 #include "BufferView.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
28 #include "lyxlength.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "metricsinfo.h"
36 #include "frontends/Alert.h"
37 #include "frontends/Dialogs.h"
38 #include "frontends/font_metrics.h"
39 #include "frontends/LyXView.h"
40 #include "frontends/Painter.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
51 using namespace lyx::support;
52 using namespace lyx::graphics;
66 int const ADD_TO_HEIGHT = 2;
67 int const ADD_TO_TABULAR_WIDTH = 2;
70 LyXTabular * paste_tabular = 0;
73 struct TabularFeature {
74 LyXTabular::Feature action;
79 TabularFeature tabularFeature[] =
81 { LyXTabular::APPEND_ROW, "append-row" },
82 { LyXTabular::APPEND_COLUMN, "append-column" },
83 { LyXTabular::DELETE_ROW, "delete-row" },
84 { LyXTabular::DELETE_COLUMN, "delete-column" },
85 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
86 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
87 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
88 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
89 { LyXTabular::ALIGN_LEFT, "align-left" },
90 { LyXTabular::ALIGN_RIGHT, "align-right" },
91 { LyXTabular::ALIGN_CENTER, "align-center" },
92 { LyXTabular::ALIGN_BLOCK, "align-block" },
93 { LyXTabular::VALIGN_TOP, "valign-top" },
94 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
95 { LyXTabular::VALIGN_CENTER, "valign-center" },
96 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
97 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
98 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
99 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
100 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
101 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
102 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
103 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
104 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
105 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
106 { LyXTabular::MULTICOLUMN, "multicolumn" },
107 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
108 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
109 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
110 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
111 { LyXTabular::SET_PWIDTH, "set-pwidth" },
112 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
113 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
114 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
115 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
116 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
117 { LyXTabular::SET_USEBOX, "set-usebox" },
118 { LyXTabular::SET_LTHEAD, "set-lthead" },
119 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
120 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
121 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
122 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
123 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
124 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
125 { LyXTabular::LAST_ACTION, "" }
129 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
130 bool operator()(TabularFeature & tf)
132 return tf.action == feature_;
135 LyXTabular::Feature feature_;
141 string const featureAsString(LyXTabular::Feature feature)
143 TabularFeature * it = tabularFeature;
144 TabularFeature * end = it +
145 sizeof(tabularFeature) / sizeof(TabularFeature);
146 it = std::find_if(it, end, FindFeature(feature));
147 return (it == end) ? string() : it->feature;
151 bool InsetTabular::hasPasteBuffer() const
153 return (paste_tabular != 0);
157 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 : tabular(buf.params, this, max(rows, 1), max(columns, 1)),
159 buffer_(&buf), cursorx_(0), cursory_(0)
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
176 InsetTabular::InsetTabular(InsetTabular const & tab)
177 : UpdatableInset(tab),
178 tabular(tab.buffer_->params, this, tab.tabular),
179 buffer_(tab.buffer_), cursorx_(0), cursory_(0)
181 the_locking_inset = 0;
182 old_locking_inset = 0;
185 actrow = actcell = 0;
194 InsetTabular::~InsetTabular()
196 InsetTabularMailer(*this).hideDialog();
200 auto_ptr<InsetBase> InsetTabular::clone() const
202 return auto_ptr<InsetBase>(new InsetTabular(*this));
206 Buffer const * InsetTabular::buffer() const
212 BufferView * InsetTabular::view() const
219 void InsetTabular::buffer(Buffer * b)
225 void InsetTabular::write(Buffer const * buf, ostream & os) const
227 os << " Tabular" << endl;
228 tabular.write(buf, os);
232 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
234 bool const old_format = (lex.getString() == "\\LyXTable");
236 tabular.read(buf, lex);
244 string token = lex.getString();
245 while (lex.isOK() && (token != "\\end_inset")) {
247 token = lex.getString();
249 if (token != "\\end_inset") {
250 lex.printError("Missing \\end_inset at this point. "
256 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
258 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
259 // mi.base.textwidth << "\n";
261 lyxerr << "InsetTabular::metrics: need bv\n";
265 calculate_dimensions_of_cells(mi);
267 dim.asc = tabular.getAscentOfRow(0);
268 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
269 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
274 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
276 //lyxerr << "InsetTabular::draw: " << x << " " << y << "\n";
282 BufferView * bv = pi.base.bv;
288 UpdatableInset::draw(pi, x, y);
296 x += ADD_TO_TABULAR_WIDTH;
300 first_visible_cell = -1;
301 for (i = 0; i < tabular.rows(); ++i) {
303 cell = tabular.getCellNumber(i, 0);
304 if (!((y + tabular.getDescentOfRow(i)) > 0) &&
305 (y - tabular.getAscentOfRow(i)) < pi.pain.paperHeight())
307 y += tabular.getDescentOfRow(i) +
308 tabular.getAscentOfRow(i + 1) +
309 tabular.getAdditionalHeight(i + 1);
312 for (j = 0; j < tabular.columns(); ++j) {
313 if (nx > bv->workWidth())
315 if (tabular.isPartOfMultiColumn(i, j))
317 cx = nx + tabular.getBeginningOfTextInCell(cell);
318 if (first_visible_cell < 0)
319 first_visible_cell = cell;
320 if (hasSelection()) {
321 drawCellSelection(pi.pain, nx, y, i, j, cell);
324 tabular.getCellInset(cell).draw(pi, cx, y);
325 drawCellLines(pi.pain, nx, y, i, cell);
326 nx += tabular.getWidthOfColumn(cell);
330 // Would be nice, but for some completely unfathomable reason,
331 // on a col resize to a new fixed width, even though the insettexts
332 // are resized, the cell isn't, but drawing all cells in a tall table
333 // has the desired effect somehow. Complete dark magic.
335 // avoiding drawing the rest of a long table is
336 // a pretty big speedup
337 if (y > bv->workHeight())
341 y += tabular.getDescentOfRow(i) +
342 tabular.getAscentOfRow(i + 1) +
343 tabular.getAdditionalHeight(i + 1);
350 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
351 int row, int cell) const
353 int x2 = x + tabular.getWidthOfColumn(cell);
356 if (!tabular.topAlreadyDrawn(cell)) {
357 on_off = !tabular.topLine(cell);
358 pain.line(x, y - tabular.getAscentOfRow(row),
359 x2, y - tabular.getAscentOfRow(row),
360 on_off ? LColor::tabularonoffline : LColor::tabularline,
361 on_off ? Painter::line_onoffdash : Painter::line_solid);
363 on_off = !tabular.bottomLine(cell);
364 pain.line(x, y + tabular.getDescentOfRow(row),
365 x2, y + tabular.getDescentOfRow(row),
366 on_off ? LColor::tabularonoffline : LColor::tabularline,
367 on_off ? Painter::line_onoffdash : Painter::line_solid);
368 if (!tabular.leftAlreadyDrawn(cell)) {
369 on_off = !tabular.leftLine(cell);
370 pain.line(x, y - tabular.getAscentOfRow(row),
371 x, y + tabular.getDescentOfRow(row),
372 on_off ? LColor::tabularonoffline : LColor::tabularline,
373 on_off ? Painter::line_onoffdash : Painter::line_solid);
375 on_off = !tabular.rightLine(cell);
376 pain.line(x2 - tabular.getAdditionalWidth(cell),
377 y - tabular.getAscentOfRow(row),
378 x2 - tabular.getAdditionalWidth(cell),
379 y + tabular.getDescentOfRow(row),
380 on_off ? LColor::tabularonoffline : LColor::tabularline,
381 on_off ? Painter::line_onoffdash : Painter::line_solid);
385 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
386 int row, int column, int cell) const
388 Assert(hasSelection());
389 int cs = tabular.column_of_cell(sel_cell_start);
390 int ce = tabular.column_of_cell(sel_cell_end);
393 cs = tabular.column_of_cell(sel_cell_end);
395 ce = tabular.right_column_of_cell(sel_cell_end);
398 int rs = tabular.row_of_cell(sel_cell_start);
399 int re = tabular.row_of_cell(sel_cell_end);
403 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
404 int w = tabular.getWidthOfColumn(cell);
405 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
406 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
407 w, h, LColor::selection);
412 string const InsetTabular::editMessage() const
414 return _("Opened table");
418 void InsetTabular::insetUnlock(BufferView * bv)
420 if (the_locking_inset) {
421 the_locking_inset->insetUnlock(bv);
422 updateLocal(bv, CELL);
423 the_locking_inset = 0;
428 if (scroll(false) || hasSelection()) {
433 updateLocal(bv, FULL);
438 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
440 lyxerr << "InsetTabular::updateLocal: " << what << "\n";
441 if (!locked && what == CELL)
443 if (need_update < what) // only set this if it has greater update
446 if (need_update != NONE) {
447 bv->updateInset(const_cast<InsetTabular *>(this));
454 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
456 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
461 if (inset == &tabular.getCellInset(actcell)) {
462 lyxerr[Debug::INSETTEXT] << "OK" << endl;
463 the_locking_inset = &tabular.getCellInset(actcell);
466 } else if (!the_locking_inset) {
467 int const n = tabular.getNumberOfCells();
468 int const id = inset->id();
469 for (int i = 0; i < n; ++i) {
470 InsetText * in = &tabular.getCellInset(i);
473 the_locking_inset = in;
478 if (in->getInsetFromID(id)) {
480 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
481 return the_locking_inset->lockInsetInInset(bv, inset);
484 } else if (the_locking_inset && (the_locking_inset == inset)) {
485 lyxerr[Debug::INSETTEXT] << "OK" << endl;
487 } else if (the_locking_inset) {
488 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
489 return the_locking_inset->lockInsetInInset(bv, inset);
491 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
496 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
499 if (!the_locking_inset)
501 if (the_locking_inset == inset) {
502 the_locking_inset->insetUnlock(bv);
504 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
510 updateLocal(bv, CELL);
511 // this has to be here otherwise we don't redraw the cell!
512 the_locking_inset = 0;
515 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
516 if (inset->lyxCode() == TABULAR_CODE &&
517 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
518 InsetTabularMailer(*this).updateDialog(bv);
527 bool InsetTabular::updateInsetInInset(BufferView * bv, InsetOld * inset)
529 InsetOld * tl_inset = inset;
530 // look if this inset is really inside myself!
531 while(tl_inset->owner() && tl_inset->owner() != this)
532 tl_inset = tl_inset->owner();
533 // if we enter here it's not ower inset
534 if (!tl_inset->owner())
536 // we only have to do this if this is a subinset of our cells
537 if (tl_inset != inset) {
538 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
541 updateLocal(bv, CELL);
546 int InsetTabular::insetInInsetY() const
548 if (!the_locking_inset)
550 return inset_y + the_locking_inset->insetInInsetY();
554 UpdatableInset * InsetTabular::getLockingInset() const
556 return the_locking_inset ? the_locking_inset->getLockingInset() :
557 const_cast<InsetTabular *>(this);
561 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(InsetOld::Code c)
565 if (the_locking_inset)
566 return the_locking_inset->getFirstLockingInsetOfType(c);
571 bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset)
573 if (the_locking_inset)
574 return the_locking_inset->insertInset(bv, inset);
579 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
581 if (hasSelection() && cmd.button() == mouse_button::button3)
584 if (hasSelection()) {
586 updateLocal(cmd.view(), FULL);
589 int const ocell = actcell;
590 int const orow = actrow;
591 BufferView * bv = cmd.view();
595 the_locking_inset = 0;
599 setPos(bv, cmd.x, cmd.y);
601 updateLocal(bv, NONE);
604 if (cmd.button() == mouse_button::button3) {
605 if ((ocell != actcell) && the_locking_inset) {
606 the_locking_inset->insetUnlock(bv);
607 updateLocal(bv, CELL);
608 the_locking_inset = 0;
614 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
616 if ((ocell == actcell) && the_locking_inset && inset_hit) {
618 FuncRequest cmd1 = cmd;
621 the_locking_inset->localDispatch(cmd1);
625 if (the_locking_inset) {
626 the_locking_inset->insetUnlock(bv);
627 updateLocal(bv, CELL);
628 the_locking_inset = 0;
631 if (cmd.button() == mouse_button::button2) {
632 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
636 if (inset_hit && bv->theLockingInset()) {
637 if (!bv->lockInset(&tabular.getCellInset(actcell))) {
638 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
641 FuncRequest cmd1 = cmd;
644 the_locking_inset->localDispatch(cmd1);
650 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
653 if (the_locking_inset) {
654 FuncRequest cmd1 = cmd;
657 ret = the_locking_inset->localDispatch(cmd1);
659 if (cmd.button() == mouse_button::button3 && !ret) {
660 InsetTabularMailer(*this).showDialog(cmd.view());
667 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
669 if (the_locking_inset) {
670 FuncRequest cmd1 = cmd;
673 the_locking_inset->localDispatch(cmd1);
677 BufferView * bv = cmd.view();
678 int const old_cell = actcell;
680 setPos(bv, cmd.x, cmd.y);
681 if (!hasSelection()) {
682 setSelection(actcell, actcell);
683 updateLocal(bv, FULL);
684 } else if (old_cell != actcell) {
685 setSelection(sel_cell_start, actcell);
686 updateLocal(bv, FULL);
691 InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
693 // We need to save the value of the_locking_inset as the call to
694 // the_locking_inset->localDispatch might unlock it.
695 old_locking_inset = the_locking_inset;
696 RESULT result = UpdatableInset::localDispatch(cmd);
697 BufferView * bv = cmd.view();
699 if (cmd.action == LFUN_INSET_EDIT) {
701 if (!bv->lockInset(this)) {
702 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
708 the_locking_inset = 0;
712 if (cmd.argument.size()) {
713 if (cmd.argument == "left") {
714 if (isRightToLeft(bv))
715 actcell = tabular.getLastCellInRow(0);
719 if (isRightToLeft(bv))
720 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
722 actcell = tabular.getNumberOfCells() - 1;
730 setPos(bv, cmd.x, cmd.y);
733 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
734 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
740 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
745 if (cmd.action < 0 && cmd.argument.empty())
748 bool hs = hasSelection();
751 // this one have priority over the locked InsetText, if we're not already
752 // inside another tabular then that one get's priority!
753 if (getFirstLockingInsetOfType(InsetOld::TABULAR_CODE) == this) {
754 switch (cmd.action) {
755 case LFUN_MOUSE_PRESS:
759 case LFUN_MOUSE_MOTION:
760 lfunMouseMotion(cmd);
763 case LFUN_MOUSE_RELEASE:
764 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
766 case LFUN_CELL_BACKWARD:
767 case LFUN_CELL_FORWARD:
768 unlockInsetInInset(bv, the_locking_inset);
769 if (cmd.action == LFUN_CELL_FORWARD)
770 moveNextCell(bv, old_locking_inset != 0);
772 movePrevCell(bv, old_locking_inset != 0);
775 updateLocal(bv, FULL);
776 if (!the_locking_inset) {
777 return DISPATCHED_NOUPDATE;
780 // this to avoid compiler warnings.
786 kb_action action = cmd.action;
787 string arg = cmd.argument;
788 if (the_locking_inset) {
789 result = the_locking_inset->localDispatch(cmd);
790 if (result == DISPATCHED_NOUPDATE) {
793 if (sc != scroll()) { // inset has been scrolled
794 updateLocal(bv, FULL);
797 } else if (result == DISPATCHED) {
798 updateLocal(bv, CELL);
800 } else if (result == FINISHED_UP) {
802 // Make sure to reset status message after
803 // exiting, e.g. math inset
804 bv->owner()->clearMessage();
805 } else if (result == FINISHED_DOWN) {
807 bv->owner()->clearMessage();
808 } else if (result == FINISHED_RIGHT) {
810 bv->owner()->clearMessage();
811 } else if (result == FINISHED) {
812 bv->owner()->clearMessage();
818 // --- Cursor Movements ----------------------------------
819 case LFUN_RIGHTSEL: {
820 int const start = hasSelection() ? sel_cell_start : actcell;
821 if (tabular.isLastCellInRow(actcell)) {
822 setSelection(start, actcell);
827 // if we are starting a selection, only select
828 // the current cell at the beginning
829 if (hasSelection()) {
830 moveRight(bv, false);
833 setSelection(start, end);
834 updateLocal(bv, FULL);
838 result = moveRight(bv);
841 updateLocal(bv, FULL);
844 int const start = hasSelection() ? sel_cell_start : actcell;
845 if (tabular.isFirstCellInRow(actcell)) {
846 setSelection(start, actcell);
851 // if we are starting a selection, only select
852 // the current cell at the beginning
853 if (hasSelection()) {
857 setSelection(start, end);
858 updateLocal(bv, FULL);
862 result = moveLeft(bv);
865 updateLocal(bv, FULL);
868 int const start = hasSelection() ? sel_cell_start : actcell;
869 int const ocell = actcell;
870 // if we are starting a selection, only select
871 // the current cell at the beginning
872 if (hasSelection()) {
874 if ((ocell == sel_cell_end) ||
875 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
876 setSelection(start, tabular.getCellBelow(sel_cell_end));
878 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
880 setSelection(start, start);
882 updateLocal(bv, FULL);
886 result = moveDown(bv, old_locking_inset != 0);
889 updateLocal(bv, FULL);
893 int const start = hasSelection() ? sel_cell_start : actcell;
894 int const ocell = actcell;
895 // if we are starting a selection, only select
896 // the current cell at the beginning
897 if (hasSelection()) {
899 if ((ocell == sel_cell_end) ||
900 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
901 setSelection(start, tabular.getCellAbove(sel_cell_end));
903 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
905 setSelection(start, start);
907 updateLocal(bv, FULL);
911 result = moveUp(bv, old_locking_inset != 0);
914 updateLocal(bv, FULL);
917 UpdateCodes code = CURSOR;
923 unlockInsetInInset(bv, the_locking_inset);
924 if (bv->text->top_y() + bv->painter().paperHeight() <
925 (top_baseline + tabular.getHeightOfTabular()))
927 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
929 actcell = tabular.getCellBelow(first_visible_cell) + column;
931 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
934 updateLocal(bv, code);
938 UpdateCodes code = CURSOR;
944 unlockInsetInInset(bv, the_locking_inset);
945 if (top_baseline < 0) {
946 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
948 if (top_baseline > 0)
951 actcell = tabular.getCellBelow(first_visible_cell) + column;
956 updateLocal(bv, code);
959 // none of these make sense for insettabular,
960 // but we must catch them to prevent any
961 // selection from being confused
965 case LFUN_WORDLEFTSEL:
967 case LFUN_WORDRIGHTSEL:
969 case LFUN_DOWN_PARAGRAPH:
970 case LFUN_DOWN_PARAGRAPHSEL:
971 case LFUN_UP_PARAGRAPH:
972 case LFUN_UP_PARAGRAPHSEL:
978 case LFUN_BEGINNINGBUF:
979 case LFUN_BEGINNINGBUFSEL:
983 case LFUN_LAYOUT_TABULAR: {
984 InsetTabularMailer(*this).showDialog(bv);
987 case LFUN_INSET_DIALOG_UPDATE: {
988 InsetTabularMailer(*this).updateDialog(bv);
991 case LFUN_TABULAR_FEATURE:
992 if (!tabularFeatures(bv, arg))
993 result = UNDISPATCHED;
995 // insert file functions
996 case LFUN_FILE_INSERT_ASCII_PARA:
997 case LFUN_FILE_INSERT_ASCII:
999 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1002 if (insertAsciiString(bv, tmpstr, false))
1003 updateLocal(bv, INIT);
1005 result = UNDISPATCHED;
1008 // cut and paste functions
1010 if (!copySelection(bv))
1014 recordUndo(bv, Undo::DELETE);
1015 cutSelection(bv->buffer()->params);
1016 updateLocal(bv, INIT);
1019 if (!hasSelection())
1024 case LFUN_PASTESELECTION:
1026 string const clip(bv->getClipboard());
1030 if (clip.find('\t') != string::npos) {
1034 string::size_type len = clip.length();
1035 string::size_type p = 0;
1038 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1046 maxCols = max(cols, maxCols);
1052 maxCols = max(cols, maxCols);
1053 delete paste_tabular;
1054 paste_tabular = new LyXTabular(bv->buffer()->params,
1055 this, rows, maxCols);
1056 string::size_type op = 0;
1058 int cells = paste_tabular->getNumberOfCells();
1060 while ((cell < cells) && (p < len) &&
1061 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1066 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1071 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1072 while (cols++ < maxCols)
1080 // check for the last cell if there is no trailing '\n'
1081 if ((cell < cells) && (op < len))
1082 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1085 if (!insertAsciiString(bv, clip, true))
1088 // so that the clipboard is used and it goes on
1090 // and executes LFUN_PASTESELECTION in insettext!
1091 delete paste_tabular;
1096 if (hasPasteBuffer()) {
1097 recordUndo(bv, Undo::INSERT);
1099 updateLocal(bv, INIT);
1102 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1104 // handle font changing stuff on selection before we lock the inset
1105 // in the default part!
1106 result = UNDISPATCHED;
1117 case LFUN_UNDERLINE:
1118 case LFUN_FONT_SIZE:
1119 if (bv->dispatch(FuncRequest(bv, action, arg)))
1120 result = DISPATCHED;
1126 // we try to activate the actual inset and put this event down to
1127 // the insets dispatch function.
1128 if ((result == DISPATCHED) || the_locking_inset)
1131 if (activateCellInset(bv)) {
1132 // reset need_update setted in above function!
1134 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1135 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1136 unlockInsetInInset(bv, the_locking_inset);
1138 // we need to update if this was requested before
1139 updateLocal(bv, NONE);
1140 return UNDISPATCHED;
1143 // so the below CELL is not set because this is higher
1144 // priority and we get a full redraw
1148 updateLocal(bv, CELL);
1153 if (result < FINISHED) {
1154 if (!the_locking_inset) {
1155 if (bv->fitCursor())
1156 updateLocal(bv, FULL);
1159 bv->unlockInset(this);
1164 int InsetTabular::latex(Buffer const * buf, ostream & os,
1165 LatexRunParams const & runparams) const
1167 return tabular.latex(buf, os, runparams);
1171 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1174 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1176 return tabular.ascii(buf, os, 0, false,0);
1180 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1182 return tabular.linuxdoc(buf,os);
1186 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1191 // if the table is inside a float it doesn't need the informaltable
1192 // wrapper. Search for it.
1193 for(master = owner();
1194 master && master->lyxCode() != InsetOld::FLOAT_CODE;
1195 master = master->owner());
1198 os << "<informaltable>";
1203 ret+= tabular.docbook(buf, os, mixcont);
1205 os << "</informaltable>";
1214 void InsetTabular::validate(LaTeXFeatures & features) const
1216 tabular.validate(features);
1220 void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const
1223 // if we have a locking_inset we should have to check only this cell for
1224 // change so I'll try this to have a boost, but who knows ;) (Jug?)
1225 // This is _really_ important (André)
1226 if (need_update != INIT &&
1227 the_locking_inset == &tabular.getCellInset(actcell)) {
1230 for (int j = 0; j < tabular.columns(); ++j) {
1234 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1235 tabular.getCellInset(actrow, j).metrics(m, dim);
1236 maxAsc = max(dim.asc, maxAsc);
1237 maxDesc = max(dim.des, maxDesc);
1239 tabular.setWidthOfCell(actcell, the_locking_inset->width());
1240 tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT);
1241 tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT);
1247 bool changed = false;
1248 for (int i = 0; i < tabular.rows(); ++i) {
1251 for (int j = 0; j < tabular.columns(); ++j) {
1252 if (tabular.isPartOfMultiColumn(i, j))
1258 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1259 tabular.getCellInset(cell).metrics(m, dim);
1260 maxAsc = max(maxAsc, dim.asc);
1261 maxDesc = max(maxDesc, dim.des);
1262 changed = tabular.setWidthOfCell(cell, dim.wid) || changed;
1264 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1265 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1268 // tabular.reinit();
1272 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1274 if (the_locking_inset) {
1275 the_locking_inset->getCursor(bv, x, y);
1280 y = cursory_ + InsetTabular::y();
1283 int desc = tabular.getDescentOfRow(actrow);
1285 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1287 y += ADD_TO_HEIGHT * 2;
1288 y += TEXT_TO_INSET_OFFSET;
1292 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1294 if (the_locking_inset) {
1295 the_locking_inset->getCursorPos(bv, x, y);
1298 x = cursorx_ - top_x;
1303 void InsetTabular::fitInsetCursor(BufferView * bv) const
1305 if (the_locking_inset) {
1306 int old_top_y = bv->text->top_y();
1307 the_locking_inset->fitInsetCursor(bv);
1308 if (old_top_y != bv->text->top_y())
1314 int const asc = font_metrics::maxAscent(font);
1315 int const desc = font_metrics::maxDescent(font);
1318 if (bv->fitLockedInsetCursor(cursorx_, cursory_, asc, desc))
1323 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1326 actcell = actrow = actcol = 0;
1327 int ly = tabular.getDescentOfRow(actrow);
1329 // first search the right row
1330 while (ly < y && actrow + 1 < tabular.rows()) {
1331 cursory_ += tabular.getDescentOfRow(actrow) +
1332 tabular.getAscentOfRow(actrow + 1) +
1333 tabular.getAdditionalHeight(actrow + 1);
1335 ly = cursory_ + tabular.getDescentOfRow(actrow);
1337 actcell = tabular.getCellNumber(actrow, actcol);
1339 // now search the right column
1340 int lx = tabular.getWidthOfColumn(actcell) -
1341 tabular.getAdditionalWidth(actcell);
1342 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1343 lx += tabular.getWidthOfColumn(actcell + 1)
1344 + tabular.getAdditionalWidth(actcell);
1346 cursorx_ = lx - tabular.getWidthOfColumn(actcell) + top_x + 2;
1351 int InsetTabular::getCellXPos(int cell) const
1355 for (; !tabular.isFirstCellInRow(c); --c)
1357 int lx = tabular.getWidthOfColumn(cell);
1358 for (; c < cell; ++c) {
1359 lx += tabular.getWidthOfColumn(c);
1361 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1365 void InsetTabular::resetPos(BufferView * bv) const
1367 #ifdef WITH_WARNINGS
1368 #warning This should be fixed in the right manner (20011128 Jug)
1370 // fast hack to fix infinite repaintings!
1371 if (in_reset_pos > 0)
1375 actcol = tabular.column_of_cell(actcell);
1378 for (; cell < actcell && !tabular.isLastRow(cell); ++cell) {
1379 if (tabular.isLastCellInRow(cell)) {
1380 cursory_ += tabular.getDescentOfRow(actrow) +
1381 tabular.getAscentOfRow(actrow + 1) +
1382 tabular.getAdditionalHeight(actrow + 1);
1386 if (!locked || nodraw()) {
1387 if (the_locking_inset)
1391 // we need this only from here on!!!
1393 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1394 int new_x = getCellXPos(actcell);
1395 int old_x = cursorx_;
1398 // cursor.x(getCellXPos(actcell) + offset);
1399 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1400 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1403 updateLocal(bv, FULL);
1404 } else if (the_locking_inset &&
1405 tabular.getWidthOfColumn(actcell) > bv->workWidth() - 20)
1407 int xx = cursorx_ - offset + bv->text->getRealCursorX();
1408 if (xx > (bv->workWidth()-20)) {
1409 scroll(bv, -(xx - bv->workWidth() + 60));
1410 updateLocal(bv, FULL);
1411 } else if (xx < 20) {
1417 updateLocal(bv, FULL);
1419 } else if ((cursorx_ - offset) > 20 &&
1420 (cursorx_ - offset + tabular.getWidthOfColumn(actcell))
1421 > (bv->workWidth() - 20)) {
1422 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1423 updateLocal(bv, FULL);
1424 } else if ((cursorx_ - offset) < 20) {
1425 scroll(bv, 20 - cursorx_ + offset);
1426 updateLocal(bv, FULL);
1427 } else if (scroll() && top_x > 20 &&
1428 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1429 scroll(bv, old_x - cursorx_);
1430 updateLocal(bv, FULL);
1432 if (the_locking_inset) {
1433 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
1436 if ((!the_locking_inset ||
1437 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1438 actcell != oldcell) {
1439 InsetTabularMailer(*this).updateDialog(bv);
1446 InsetOld::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1448 if (lock && !old_locking_inset) {
1449 if (activateCellInset(bv))
1452 bool moved = isRightToLeft(bv)
1453 ? movePrevCell(bv) : moveNextCell(bv);
1455 return FINISHED_RIGHT;
1456 if (lock && activateCellInset(bv))
1460 return DISPATCHED_NOUPDATE;
1464 InsetOld::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1466 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1469 if (lock) { // behind the inset
1470 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1474 return DISPATCHED_NOUPDATE;
1478 InsetOld::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1480 int const ocell = actcell;
1481 actcell = tabular.getCellAbove(actcell);
1482 if (actcell == ocell) // we moved out of the inset
1488 if (old_locking_inset) {
1489 old_locking_inset->getCursorPos(bv, x, y);
1490 x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell);
1492 if (activateCellInset(bv, x, 0))
1495 return DISPATCHED_NOUPDATE;
1499 InsetOld::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1501 int const ocell = actcell;
1502 actcell = tabular.getCellBelow(actcell);
1503 if (actcell == ocell) // we moved out of the inset
1504 return FINISHED_DOWN;
1509 if (old_locking_inset) {
1510 old_locking_inset->getCursorPos(bv, x, y);
1511 x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell);
1513 if (activateCellInset(bv, x, 0))
1516 return DISPATCHED_NOUPDATE;
1520 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1522 if (isRightToLeft(bv)) {
1523 if (tabular.isFirstCellInRow(actcell)) {
1524 int row = tabular.row_of_cell(actcell);
1525 if (row == tabular.rows() - 1)
1527 actcell = tabular.getLastCellInRow(row);
1528 actcell = tabular.getCellBelow(actcell);
1535 if (tabular.isLastCell(actcell))
1540 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1541 isRightToLeftPar(bv->buffer()->params);
1542 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1549 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1551 if (isRightToLeft(bv)) {
1552 if (tabular.isLastCellInRow(actcell)) {
1553 int row = tabular.row_of_cell(actcell);
1556 actcell = tabular.getFirstCellInRow(row);
1557 actcell = tabular.getCellAbove(actcell);
1559 if (tabular.isLastCell(actcell))
1564 if (!actcell) // first cell
1569 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1570 isRightToLeftPar(bv->buffer()->params);
1571 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1578 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1582 setSelection(0, tabular.getNumberOfCells() - 1);
1584 if (hasSelection()) {
1585 recordUndo(bv, Undo::ATOMIC);
1586 bool const frozen = undo_frozen;
1589 // apply the fontchange on the whole selection
1594 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1595 for(int i = sel_row_start; i <= sel_row_end; ++i)
1596 for(int j = sel_col_start; j <= sel_col_end; ++j)
1597 tabular.getCellInset(i, j).setFont(bv, font, tall, true);
1603 updateLocal(bv, INIT);
1605 if (the_locking_inset)
1606 the_locking_inset->setFont(bv, font, tall);
1610 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1612 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1615 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1616 string const tmp = tabularFeature[i].feature;
1618 if (tmp == what.substr(0, tmp.length())) {
1619 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1620 //tabularFeatures[i].feature.length())) {
1621 action = tabularFeature[i].action;
1625 if (action == LyXTabular::LAST_ACTION)
1629 ltrim(what.substr(tabularFeature[i].feature.length()));
1630 tabularFeatures(bv, action, val);
1636 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1637 string const & special, bool & flag)
1639 if (special == "dl_above") {
1642 } else if (special == "dl_below") {
1643 ltt.bottomDL = flag;
1645 } else if (special == "empty") {
1657 void InsetTabular::tabularFeatures(BufferView * bv,
1658 LyXTabular::Feature feature,
1659 string const & value)
1665 bool setLines = false;
1666 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1667 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1670 case LyXTabular::M_ALIGN_LEFT:
1671 case LyXTabular::ALIGN_LEFT:
1672 setAlign = LYX_ALIGN_LEFT;
1674 case LyXTabular::M_ALIGN_RIGHT:
1675 case LyXTabular::ALIGN_RIGHT:
1676 setAlign = LYX_ALIGN_RIGHT;
1678 case LyXTabular::M_ALIGN_CENTER:
1679 case LyXTabular::ALIGN_CENTER:
1680 setAlign = LYX_ALIGN_CENTER;
1682 case LyXTabular::ALIGN_BLOCK:
1683 setAlign = LYX_ALIGN_BLOCK;
1685 case LyXTabular::M_VALIGN_TOP:
1686 case LyXTabular::VALIGN_TOP:
1687 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1689 case LyXTabular::M_VALIGN_BOTTOM:
1690 case LyXTabular::VALIGN_BOTTOM:
1691 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1693 case LyXTabular::M_VALIGN_CENTER:
1694 case LyXTabular::VALIGN_CENTER:
1695 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1700 if (hasSelection()) {
1701 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1703 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1704 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1706 recordUndo(bv, Undo::ATOMIC);
1708 int row = tabular.row_of_cell(actcell);
1709 int column = tabular.column_of_cell(actcell);
1711 LyXTabular::ltType ltt;
1714 case LyXTabular::SET_PWIDTH:
1716 LyXLength const vallen(value);
1717 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1719 bool const update = (tmplen != vallen);
1720 tabular.setColumnPWidth(actcell, vallen);
1722 // We need this otherwise we won't resize
1723 // the insettext of the active cell (if any)
1724 // until later (see InsetText::do_resize)
1725 unlockInsetInInset(bv, the_locking_inset);
1727 for (int i = 0; i < tabular.rows(); ++i)
1728 tabular.getCellInset(i, column).resizeLyXText(bv);
1729 updateLocal(bv, INIT);
1733 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1734 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1735 else if (!vallen.zero()
1736 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1737 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1740 case LyXTabular::SET_MPWIDTH:
1742 LyXLength const vallen(value);
1743 LyXLength const & tmplen = tabular.getPWidth(actcell);
1745 bool const update = (tmplen != vallen);
1746 tabular.setMColumnPWidth(actcell, vallen);
1748 // We need this otherwise we won't resize
1749 // the insettext of the active cell (if any)
1750 // until later (see InsetText::do_resize)
1751 unlockInsetInInset(bv, the_locking_inset);
1753 for (int i = 0; i < tabular.rows(); ++i)
1754 tabular.getCellInset(i, column).resizeLyXText(bv);
1756 updateLocal(bv, INIT);
1760 case LyXTabular::SET_SPECIAL_COLUMN:
1761 case LyXTabular::SET_SPECIAL_MULTI:
1762 tabular.setAlignSpecial(actcell,value,feature);
1763 updateLocal(bv, FULL);
1765 case LyXTabular::APPEND_ROW:
1766 // append the row into the tabular
1767 unlockInsetInInset(bv, the_locking_inset);
1768 tabular.appendRow(bv->buffer()->params, actcell);
1769 updateLocal(bv, INIT);
1771 case LyXTabular::APPEND_COLUMN:
1772 // append the column into the tabular
1773 unlockInsetInInset(bv, the_locking_inset);
1774 tabular.appendColumn(bv->buffer()->params, actcell);
1775 actcell = tabular.getCellNumber(row, column);
1776 updateLocal(bv, INIT);
1778 case LyXTabular::DELETE_ROW:
1779 unlockInsetInInset(bv, the_locking_inset);
1780 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1781 tabular.deleteRow(sel_row_start);
1783 if (sel_row_start >= tabular.rows())
1785 actcell = tabular.getCellNumber(sel_row_start, column);
1787 updateLocal(bv, INIT);
1789 case LyXTabular::DELETE_COLUMN:
1790 unlockInsetInInset(bv, the_locking_inset);
1791 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1792 tabular.deleteColumn(sel_col_start);
1794 if (sel_col_start >= tabular.columns())
1796 actcell = tabular.getCellNumber(row, sel_col_start);
1798 updateLocal(bv, INIT);
1800 case LyXTabular::M_TOGGLE_LINE_TOP:
1802 case LyXTabular::TOGGLE_LINE_TOP:
1804 bool lineSet = !tabular.topLine(actcell, flag);
1805 for (int i = sel_row_start; i <= sel_row_end; ++i)
1806 for (int j = sel_col_start; j <= sel_col_end; ++j)
1808 tabular.getCellNumber(i, j),
1810 updateLocal(bv, INIT);
1814 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1816 case LyXTabular::TOGGLE_LINE_BOTTOM:
1818 bool lineSet = !tabular.bottomLine(actcell, flag);
1819 for (int i = sel_row_start; i <= sel_row_end; ++i)
1820 for (int j = sel_col_start; j <= sel_col_end; ++j)
1821 tabular.setBottomLine(
1822 tabular.getCellNumber(i, j),
1825 updateLocal(bv, INIT);
1829 case LyXTabular::M_TOGGLE_LINE_LEFT:
1831 case LyXTabular::TOGGLE_LINE_LEFT:
1833 bool lineSet = !tabular.leftLine(actcell, flag);
1834 for (int i = sel_row_start; i <= sel_row_end; ++i)
1835 for (int j = sel_col_start; j <= sel_col_end; ++j)
1836 tabular.setLeftLine(
1837 tabular.getCellNumber(i,j),
1840 updateLocal(bv, INIT);
1844 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1846 case LyXTabular::TOGGLE_LINE_RIGHT:
1848 bool lineSet = !tabular.rightLine(actcell, flag);
1849 for (int i = sel_row_start; i <= sel_row_end; ++i)
1850 for (int j = sel_col_start; j <= sel_col_end; ++j)
1851 tabular.setRightLine(
1852 tabular.getCellNumber(i,j),
1855 updateLocal(bv, INIT);
1859 case LyXTabular::M_ALIGN_LEFT:
1860 case LyXTabular::M_ALIGN_RIGHT:
1861 case LyXTabular::M_ALIGN_CENTER:
1863 case LyXTabular::ALIGN_LEFT:
1864 case LyXTabular::ALIGN_RIGHT:
1865 case LyXTabular::ALIGN_CENTER:
1866 case LyXTabular::ALIGN_BLOCK:
1867 for (int i = sel_row_start; i <= sel_row_end; ++i)
1868 for (int j = sel_col_start; j <= sel_col_end; ++j)
1869 tabular.setAlignment(
1870 tabular.getCellNumber(i, j),
1873 updateLocal(bv, INIT);
1875 case LyXTabular::M_VALIGN_TOP:
1876 case LyXTabular::M_VALIGN_BOTTOM:
1877 case LyXTabular::M_VALIGN_CENTER:
1879 case LyXTabular::VALIGN_TOP:
1880 case LyXTabular::VALIGN_BOTTOM:
1881 case LyXTabular::VALIGN_CENTER:
1882 for (int i = sel_row_start; i <= sel_row_end; ++i)
1883 for (int j = sel_col_start; j <= sel_col_end; ++j)
1884 tabular.setVAlignment(
1885 tabular.getCellNumber(i, j),
1887 updateLocal(bv, INIT);
1889 case LyXTabular::MULTICOLUMN:
1891 if (sel_row_start != sel_row_end) {
1892 #ifdef WITH_WARNINGS
1893 #warning Need I say it ? This is horrible.
1895 Alert::error(_("Error setting multicolumn"),
1896 _("You cannot set multicolumn vertically."));
1899 // just multicol for one Single Cell
1900 if (!hasSelection()) {
1901 // check wether we are completly in a multicol
1902 if (tabular.isMultiColumn(actcell)) {
1903 tabular.unsetMultiColumn(actcell);
1904 updateLocal(bv, INIT);
1906 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1907 updateLocal(bv, CELL);
1911 // we have a selection so this means we just add all this
1912 // cells to form a multicolumn cell
1916 if (sel_cell_start > sel_cell_end) {
1917 s_start = sel_cell_end;
1918 s_end = sel_cell_start;
1920 s_start = sel_cell_start;
1921 s_end = sel_cell_end;
1923 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1926 updateLocal(bv, INIT);
1929 case LyXTabular::SET_ALL_LINES:
1931 case LyXTabular::UNSET_ALL_LINES:
1932 for (int i = sel_row_start; i <= sel_row_end; ++i)
1933 for (int j = sel_col_start; j <= sel_col_end; ++j)
1934 tabular.setAllLines(
1935 tabular.getCellNumber(i,j), setLines);
1936 updateLocal(bv, INIT);
1938 case LyXTabular::SET_LONGTABULAR:
1939 tabular.setLongTabular(true);
1940 updateLocal(bv, INIT); // because this toggles displayed
1942 case LyXTabular::UNSET_LONGTABULAR:
1943 tabular.setLongTabular(false);
1944 updateLocal(bv, INIT); // because this toggles displayed
1946 case LyXTabular::SET_ROTATE_TABULAR:
1947 tabular.setRotateTabular(true);
1949 case LyXTabular::UNSET_ROTATE_TABULAR:
1950 tabular.setRotateTabular(false);
1952 case LyXTabular::SET_ROTATE_CELL:
1953 for (int i = sel_row_start; i <= sel_row_end; ++i)
1954 for (int j = sel_col_start; j<=sel_col_end; ++j)
1955 tabular.setRotateCell(
1956 tabular.getCellNumber(i, j),
1959 case LyXTabular::UNSET_ROTATE_CELL:
1960 for (int i = sel_row_start; i <= sel_row_end; ++i)
1961 for (int j = sel_col_start; j <= sel_col_end; ++j)
1962 tabular.setRotateCell(
1963 tabular.getCellNumber(i, j), false);
1965 case LyXTabular::SET_USEBOX:
1967 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1968 if (val == tabular.getUsebox(actcell))
1969 val = LyXTabular::BOX_NONE;
1970 for (int i = sel_row_start; i <= sel_row_end; ++i)
1971 for (int j = sel_col_start; j <= sel_col_end; ++j)
1973 tabular.getCellNumber(i, j), val);
1976 case LyXTabular::UNSET_LTFIRSTHEAD:
1978 case LyXTabular::SET_LTFIRSTHEAD:
1979 tabular.getRowOfLTFirstHead(row, ltt);
1980 checkLongtableSpecial(ltt, value, flag);
1981 tabular.setLTHead(row, flag, ltt, true);
1983 case LyXTabular::UNSET_LTHEAD:
1985 case LyXTabular::SET_LTHEAD:
1986 tabular.getRowOfLTHead(row, ltt);
1987 checkLongtableSpecial(ltt, value, flag);
1988 tabular.setLTHead(row, flag, ltt, false);
1990 case LyXTabular::UNSET_LTFOOT:
1992 case LyXTabular::SET_LTFOOT:
1993 tabular.getRowOfLTFoot(row, ltt);
1994 checkLongtableSpecial(ltt, value, flag);
1995 tabular.setLTFoot(row, flag, ltt, false);
1997 case LyXTabular::UNSET_LTLASTFOOT:
1999 case LyXTabular::SET_LTLASTFOOT:
2000 tabular.getRowOfLTLastFoot(row, ltt);
2001 checkLongtableSpecial(ltt, value, flag);
2002 tabular.setLTFoot(row, flag, ltt, true);
2004 case LyXTabular::SET_LTNEWPAGE:
2006 bool what = !tabular.getLTNewPage(row);
2007 tabular.setLTNewPage(row, what);
2010 // dummy stuff just to avoid warnings
2011 case LyXTabular::LAST_ACTION:
2015 InsetTabularMailer(*this).updateDialog(bv);
2019 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y,
2020 mouse_button::state button, bool behind)
2022 UpdatableInset & inset = tabular.getCellInset(actcell);
2025 x = inset.x() + inset.width();
2026 y = inset.descent();
2028 //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2029 //inset_y = cursory_;
2030 inset.localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2031 if (!the_locking_inset)
2033 updateLocal(bv, CELL);
2034 return (the_locking_inset != 0);
2038 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2039 mouse_button::state button)
2041 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2043 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2047 bool InsetTabular::insetHit(BufferView *, int x, int) const
2050 > cursorx_ + tabular.getBeginningOfTextInCell(actcell);
2054 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2056 resizeLyXText(bv, recursive);
2060 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2063 for(int i = 0; i < tabular.rows(); ++i)
2064 for(int j = 0; j < tabular.columns(); ++j)
2065 tabular.getCellInset(i, j).resizeLyXText(bv, true);
2070 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2071 bool const recursive) const
2073 if (the_locking_inset)
2074 return the_locking_inset->getLyXText(bv, recursive);
2075 return InsetOld::getLyXText(bv, recursive);
2079 bool InsetTabular::showInsetDialog(BufferView * bv) const
2081 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2082 InsetTabularMailer(*this).showDialog(bv);
2087 void InsetTabular::openLayoutDialog(BufferView * bv) const
2089 if (the_locking_inset) {
2090 InsetTabular * inset = static_cast<InsetTabular *>
2091 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2093 inset->openLayoutDialog(bv);
2097 InsetTabularMailer(*this).showDialog(bv);
2102 // function returns an object as defined in func_status.h:
2103 // states OK, Unknown, Disabled, On, Off.
2105 FuncStatus InsetTabular::getStatus(string const & what) const
2107 int action = LyXTabular::LAST_ACTION;
2111 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2112 string const tmp = tabularFeature[i].feature;
2113 if (tmp == what.substr(0, tmp.length())) {
2114 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2115 // tabularFeatures[i].feature.length())) {
2116 action = tabularFeature[i].action;
2120 if (action == LyXTabular::LAST_ACTION) {
2122 return status.unknown(true);
2125 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2130 LyXTabular::ltType dummyltt;
2133 if (hasSelection()) {
2134 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2136 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2140 case LyXTabular::SET_PWIDTH:
2141 case LyXTabular::SET_MPWIDTH:
2142 case LyXTabular::SET_SPECIAL_COLUMN:
2143 case LyXTabular::SET_SPECIAL_MULTI:
2144 case LyXTabular::APPEND_ROW:
2145 case LyXTabular::APPEND_COLUMN:
2146 case LyXTabular::DELETE_ROW:
2147 case LyXTabular::DELETE_COLUMN:
2148 case LyXTabular::SET_ALL_LINES:
2149 case LyXTabular::UNSET_ALL_LINES:
2150 return status.clear();
2152 case LyXTabular::MULTICOLUMN:
2153 status.setOnOff(tabular.isMultiColumn(actcell));
2155 case LyXTabular::M_TOGGLE_LINE_TOP:
2157 case LyXTabular::TOGGLE_LINE_TOP:
2158 status.setOnOff(tabular.topLine(actcell, flag));
2160 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2162 case LyXTabular::TOGGLE_LINE_BOTTOM:
2163 status.setOnOff(tabular.bottomLine(actcell, flag));
2165 case LyXTabular::M_TOGGLE_LINE_LEFT:
2167 case LyXTabular::TOGGLE_LINE_LEFT:
2168 status.setOnOff(tabular.leftLine(actcell, flag));
2170 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2172 case LyXTabular::TOGGLE_LINE_RIGHT:
2173 status.setOnOff(tabular.rightLine(actcell, flag));
2175 case LyXTabular::M_ALIGN_LEFT:
2177 case LyXTabular::ALIGN_LEFT:
2178 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2180 case LyXTabular::M_ALIGN_RIGHT:
2182 case LyXTabular::ALIGN_RIGHT:
2183 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2185 case LyXTabular::M_ALIGN_CENTER:
2187 case LyXTabular::ALIGN_CENTER:
2188 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2190 case LyXTabular::ALIGN_BLOCK:
2191 status.disabled(tabular.getPWidth(actcell).zero());
2192 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2194 case LyXTabular::M_VALIGN_TOP:
2196 case LyXTabular::VALIGN_TOP:
2197 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2199 case LyXTabular::M_VALIGN_BOTTOM:
2201 case LyXTabular::VALIGN_BOTTOM:
2202 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2204 case LyXTabular::M_VALIGN_CENTER:
2206 case LyXTabular::VALIGN_CENTER:
2207 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2209 case LyXTabular::SET_LONGTABULAR:
2210 status.setOnOff(tabular.isLongTabular());
2212 case LyXTabular::UNSET_LONGTABULAR:
2213 status.setOnOff(!tabular.isLongTabular());
2215 case LyXTabular::SET_ROTATE_TABULAR:
2216 status.setOnOff(tabular.getRotateTabular());
2218 case LyXTabular::UNSET_ROTATE_TABULAR:
2219 status.setOnOff(!tabular.getRotateTabular());
2221 case LyXTabular::SET_ROTATE_CELL:
2222 status.setOnOff(tabular.getRotateCell(actcell));
2224 case LyXTabular::UNSET_ROTATE_CELL:
2225 status.setOnOff(!tabular.getRotateCell(actcell));
2227 case LyXTabular::SET_USEBOX:
2228 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2230 case LyXTabular::SET_LTFIRSTHEAD:
2231 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2233 case LyXTabular::SET_LTHEAD:
2234 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2236 case LyXTabular::SET_LTFOOT:
2237 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2239 case LyXTabular::SET_LTLASTFOOT:
2240 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2242 case LyXTabular::SET_LTNEWPAGE:
2243 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2247 status.disabled(true);
2254 void InsetTabular::getLabelList(std::vector<string> & list) const
2256 tabular.getLabelList(list);
2260 bool InsetTabular::copySelection(BufferView * bv)
2262 if (!hasSelection())
2265 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2266 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2267 if (sel_col_start > sel_col_end) {
2268 sel_col_start = sel_col_end;
2269 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2271 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2273 int const columns = sel_col_end - sel_col_start + 1;
2275 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2276 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2277 if (sel_row_start > sel_row_end) {
2278 swap(sel_row_start, sel_row_end);
2280 int const rows = sel_row_end - sel_row_start + 1;
2282 delete paste_tabular;
2283 paste_tabular = new LyXTabular(bv->buffer()->params,
2284 this, tabular); // rows, columns);
2285 for (int i = 0; i < sel_row_start; ++i)
2286 paste_tabular->deleteRow(0);
2287 while (paste_tabular->rows() > rows)
2288 paste_tabular->deleteRow(rows);
2289 paste_tabular->setTopLine(0, true, true);
2290 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2292 for (int i = 0; i < sel_col_start; ++i)
2293 paste_tabular->deleteColumn(0);
2294 while (paste_tabular->columns() > columns)
2295 paste_tabular->deleteColumn(columns);
2296 paste_tabular->setLeftLine(0, true, true);
2297 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2301 paste_tabular->ascii(bv->buffer(), sstr,
2302 (int)parOwner()->params().depth(), true, '\t');
2303 bv->stuffClipboard(STRCONV(sstr.str()));
2308 bool InsetTabular::pasteSelection(BufferView * bv)
2313 for (int r1 = 0, r2 = actrow;
2314 r1 < paste_tabular->rows() && r2 < tabular.rows();
2316 for (int c1 = 0, c2 = actcol;
2317 c1 < paste_tabular->columns() && c2 < tabular.columns();
2319 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
2320 tabular.isPartOfMultiColumn(r2, c2))
2322 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
2326 if (tabular.isPartOfMultiColumn(r2, c2)) {
2330 InsetText & inset = tabular.getCellInset(r2, c2);
2331 inset = paste_tabular->getCellInset(r1, c1);
2332 inset.setOwner(this);
2333 inset.deleteLyXText(bv);
2341 bool InsetTabular::cutSelection(BufferParams const & bp)
2343 if (!hasSelection())
2346 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2347 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2348 if (sel_col_start > sel_col_end) {
2349 sel_col_start = sel_col_end;
2350 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2352 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2354 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2355 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2356 if (sel_row_start > sel_row_end) {
2357 swap(sel_row_start, sel_row_end);
2359 if (sel_cell_start > sel_cell_end) {
2360 swap(sel_cell_start, sel_cell_end);
2362 for (int i = sel_row_start; i <= sel_row_end; ++i)
2363 for (int j = sel_col_start; j <= sel_col_end; ++j)
2364 tabular.getCellInset(tabular.getCellNumber(i, j)).clear(bp.tracking_changes);
2369 bool InsetTabular::isRightToLeft(BufferView * bv)
2371 return bv->getParentLanguage(this)->RightToLeft();
2375 bool InsetTabular::nodraw() const
2377 if (!UpdatableInset::nodraw() && the_locking_inset)
2378 return the_locking_inset->nodraw();
2379 return UpdatableInset::nodraw();
2383 int InsetTabular::scroll(bool recursive) const
2385 int sx = UpdatableInset::scroll(false);
2387 if (recursive && the_locking_inset)
2388 sx += the_locking_inset->scroll(recursive);
2394 void InsetTabular::getSelection(int & srow, int & erow,
2395 int & scol, int & ecol) const
2397 int const start = hasSelection() ? sel_cell_start : actcell;
2398 int const end = hasSelection() ? sel_cell_end : actcell;
2400 srow = tabular.row_of_cell(start);
2401 erow = tabular.row_of_cell(end);
2406 scol = tabular.column_of_cell(start);
2407 ecol = tabular.column_of_cell(end);
2411 ecol = tabular.right_column_of_cell(end);
2416 ParagraphList * InsetTabular::getParagraphs(int i) const
2418 return (i < tabular.getNumberOfCells())
2419 ? tabular.getCellInset(i).getParagraphs(0)
2424 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2426 if (the_locking_inset)
2427 return the_locking_inset->cursor(bv);
2428 return InsetOld::cursor(bv);
2432 InsetOld * InsetTabular::getInsetFromID(int id_arg) const
2435 return const_cast<InsetTabular *>(this);
2437 for (int i = 0; i < tabular.rows(); ++i) {
2438 for (int j = 0; j < tabular.columns(); ++j) {
2439 InsetOld * inset = tabular.getCellInset(i, j).getInsetFromID(id_arg);
2449 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2452 if (the_locking_inset) {
2453 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2454 if (!word.word().empty()) {
2458 if (tabular.isLastCell(actcell)) {
2459 bv->unlockInset(const_cast<InsetTabular *>(this));
2461 return WordLangTuple();
2465 // otherwise we have to lock the next inset and ask for it's selecttion
2466 tabular.getCellInset(actcell)
2467 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2468 WordLangTuple word(selectNextWordInt(bv, value));
2470 if (!word.word().empty())
2476 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2478 // when entering this function the inset should be ALWAYS locked!
2479 Assert(the_locking_inset);
2481 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2482 if (!word.word().empty())
2485 if (tabular.isLastCell(actcell)) {
2486 bv->unlockInset(const_cast<InsetTabular *>(this));
2487 return WordLangTuple();
2490 // otherwise we have to lock the next inset and ask for it's selecttion
2492 tabular.getCellInset(actcell)
2493 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2494 return selectNextWordInt(bv, value);
2498 void InsetTabular::selectSelectedWord(BufferView * bv)
2500 if (the_locking_inset)
2501 the_locking_inset->selectSelectedWord(bv);
2505 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2507 if (the_locking_inset)
2508 the_locking_inset->toggleSelection(bv, kill_selection);
2512 void InsetTabular::markErased()
2514 for (int cell = 0; cell < tabular.getNumberOfCells(); ++cell)
2515 tabular.getCellInset(cell).markErased();
2519 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2521 if (the_locking_inset) {
2522 if (the_locking_inset->nextChange(bv, length)) {
2523 updateLocal(bv, CELL);
2526 if (tabular.isLastCell(actcell))
2530 InsetText & inset = tabular.getCellInset(actcell);
2531 if (inset.nextChange(bv, length)) {
2532 updateLocal(bv, FULL);
2535 while (!tabular.isLastCell(actcell)) {
2537 InsetText & inset = tabular.getCellInset(actcell);
2538 if (inset.nextChange(bv, length)) {
2539 updateLocal(bv, FULL);
2547 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2551 if (the_locking_inset) {
2552 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2553 updateLocal(bv, CELL);
2556 if (tabular.isLastCell(actcell))
2560 InsetText & inset = tabular.getCellInset(cell);
2561 if (inset.searchForward(bv, str, cs, mw)) {
2562 updateLocal(bv, FULL);
2565 while (!tabular.isLastCell(cell)) {
2567 InsetText & inset = tabular.getCellInset(cell);
2568 if (inset.searchForward(bv, str, cs, mw)) {
2569 updateLocal(bv, FULL);
2577 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2580 int cell = tabular.getNumberOfCells();
2581 if (the_locking_inset) {
2582 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2583 updateLocal(bv, CELL);
2591 InsetText & inset = tabular.getCellInset(cell);
2592 if (inset.searchBackward(bv, str, cs, mw)) {
2593 updateLocal(bv, CELL);
2601 bool InsetTabular::insetAllowed(InsetOld::Code code) const
2603 if (the_locking_inset)
2604 return the_locking_inset->insetAllowed(code);
2605 // we return true here because if the inset is not locked someone
2606 // wants to insert something in one of our insettexts and we generally
2612 bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
2614 const int cell = tabular.getCellFromInset(in, actcell);
2617 return tabular.getPWidth(cell).zero();
2619 // well we didn't obviously find it so maybe our owner knows more
2621 return owner()->forceDefaultParagraphs(in);
2622 // if we're here there is really something strange going on!!!
2627 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2630 if (buf.length() <= 0)
2636 string::size_type len = buf.length();
2637 string::size_type p = 0;
2640 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2649 maxCols = max(cols, maxCols);
2655 maxCols = max(cols, maxCols);
2656 LyXTabular * loctab;
2661 delete paste_tabular;
2662 paste_tabular = new LyXTabular(bv->buffer()->params,
2663 this, rows, maxCols);
2664 loctab = paste_tabular;
2673 string::size_type op = 0;
2674 int cells = loctab->getNumberOfCells();
2677 rows = loctab->rows();
2678 int const columns = loctab->columns();
2680 while (cell < cells && p < len && row < rows &&
2681 (p = buf.find_first_of("\t\n", p)) != string::npos)
2687 // we can only set this if we are not too far right
2688 if (cols < columns) {
2689 InsetText & inset = loctab->getCellInset(cell);
2690 LyXFont const font = inset.getLyXText(bv)->
2691 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2692 inset.setText(buf.substr(op, p - op), font);
2698 // we can only set this if we are not too far right
2699 if (cols < columns) {
2700 InsetText & inset = tabular.getCellInset(cell);
2701 LyXFont const font = inset.getLyXText(bv)->
2702 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2703 inset.setText(buf.substr(op, p - op), font);
2708 cell = loctab->getCellNumber(row, cols);
2714 // check for the last cell if there is no trailing '\n'
2715 if (cell < cells && op < len) {
2716 InsetText & inset = loctab->getCellInset(cell);
2717 LyXFont const font = inset.getLyXText(bv)->
2718 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2719 inset.setText(buf.substr(op, len - op), font);
2726 void InsetTabular::addPreview(PreviewLoader & loader) const
2728 int const rows = tabular.rows();
2729 int const columns = tabular.columns();
2730 for (int i = 0; i < rows; ++i)
2731 for (int j = 0; j < columns; ++j)
2732 tabular.getCellInset(i, j).addPreview(loader);
2736 string const InsetTabularMailer::name_("tabular");
2738 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
2739 : inset_(const_cast<InsetTabular &>(inset))
2743 string const InsetTabularMailer::inset2string(Buffer const &) const
2745 return params2string(inset_);
2749 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2751 istringstream data(STRCONV(in));
2753 lex.setStream(data);
2755 #warning CHECK verify that this is a sane value to return.
2761 string const token = lex.getString();
2769 string const token = lex.getString();
2770 if (token != "\\active_cell")
2773 cell = lex.getInteger();
2776 // This is part of the inset proper that is usually swallowed
2777 // by Buffer::readInset
2780 string const token = lex.getString();
2781 if (token != "Tabular")
2788 Buffer const * const buffer = inset.buffer();
2790 inset.read(buffer, lex);
2792 // We can't set the active cell, but we can tell the frontend
2798 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2800 Buffer const * const buffer = inset.buffer();
2805 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2806 inset.write(buffer, data);
2807 data << "\\end_inset\n";
2808 return STRCONV(data.str());