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, Inset * inset)
529 Inset * 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(Inset::Code c)
565 if (the_locking_inset)
566 return the_locking_inset->getFirstLockingInsetOfType(c);
571 bool InsetTabular::insertInset(BufferView * bv, Inset * 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 Inset::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(Inset::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 setUndo(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 setUndo(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
1183 int const ret = tabular.ascii(buf,os,
1184 (int)parOwner()->params().depth(),
1191 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1196 // if the table is inside a float it doesn't need the informaltable
1197 // wrapper. Search for it.
1198 for(master = owner();
1199 master && master->lyxCode() != Inset::FLOAT_CODE;
1200 master = master->owner());
1203 os << "<informaltable>";
1208 ret+= tabular.docbook(buf, os, mixcont);
1210 os << "</informaltable>";
1219 void InsetTabular::validate(LaTeXFeatures & features) const
1221 tabular.validate(features);
1225 void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const
1228 // if we have a locking_inset we should have to check only this cell for
1229 // change so I'll try this to have a boost, but who knows ;) (Jug?)
1230 // This is _really_ important (André)
1231 if (need_update != INIT &&
1232 the_locking_inset == &tabular.getCellInset(actcell)) {
1235 for (int j = 0; j < tabular.columns(); ++j) {
1239 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1240 tabular.getCellInset(actrow, j).metrics(m, dim);
1241 maxAsc = max(dim.asc, maxAsc);
1242 maxDesc = max(dim.des, maxDesc);
1244 tabular.setWidthOfCell(actcell, the_locking_inset->width());
1245 tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT);
1246 tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT);
1252 bool changed = false;
1253 for (int i = 0; i < tabular.rows(); ++i) {
1256 for (int j = 0; j < tabular.columns(); ++j) {
1257 if (tabular.isPartOfMultiColumn(i, j))
1263 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1264 tabular.getCellInset(cell).metrics(m, dim);
1265 maxAsc = max(maxAsc, dim.asc);
1266 maxDesc = max(maxDesc, dim.des);
1267 changed = tabular.setWidthOfCell(cell, dim.wid) || changed;
1269 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1270 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1273 // tabular.reinit();
1277 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1279 if (the_locking_inset) {
1280 the_locking_inset->getCursor(bv, x, y);
1285 y = cursory_ + InsetTabular::y();
1288 int desc = tabular.getDescentOfRow(actrow);
1290 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1292 y += ADD_TO_HEIGHT * 2;
1293 y += TEXT_TO_INSET_OFFSET;
1297 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1299 if (the_locking_inset) {
1300 the_locking_inset->getCursorPos(bv, x, y);
1303 x = cursorx_ - top_x;
1308 void InsetTabular::fitInsetCursor(BufferView * bv) const
1310 if (the_locking_inset) {
1311 int old_top_y = bv->text->top_y();
1312 the_locking_inset->fitInsetCursor(bv);
1313 if (old_top_y != bv->text->top_y())
1319 int const asc = font_metrics::maxAscent(font);
1320 int const desc = font_metrics::maxDescent(font);
1323 if (bv->fitLockedInsetCursor(cursorx_, cursory_, asc, desc))
1328 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1331 actcell = actrow = actcol = 0;
1332 int ly = tabular.getDescentOfRow(actrow);
1334 // first search the right row
1335 while (ly < y && actrow + 1 < tabular.rows()) {
1336 cursory_ += tabular.getDescentOfRow(actrow) +
1337 tabular.getAscentOfRow(actrow + 1) +
1338 tabular.getAdditionalHeight(actrow + 1);
1340 ly = cursory_ + tabular.getDescentOfRow(actrow);
1342 actcell = tabular.getCellNumber(actrow, actcol);
1344 // now search the right column
1345 int lx = tabular.getWidthOfColumn(actcell) -
1346 tabular.getAdditionalWidth(actcell);
1347 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1348 lx += tabular.getWidthOfColumn(actcell + 1)
1349 + tabular.getAdditionalWidth(actcell);
1351 cursorx_ = lx - tabular.getWidthOfColumn(actcell) + top_x + 2;
1356 int InsetTabular::getCellXPos(int cell) const
1360 for (; !tabular.isFirstCellInRow(c); --c)
1362 int lx = tabular.getWidthOfColumn(cell);
1363 for (; c < cell; ++c) {
1364 lx += tabular.getWidthOfColumn(c);
1366 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1370 void InsetTabular::resetPos(BufferView * bv) const
1372 #ifdef WITH_WARNINGS
1373 #warning This should be fixed in the right manner (20011128 Jug)
1375 // fast hack to fix infinite repaintings!
1376 if (in_reset_pos > 0)
1380 actcol = tabular.column_of_cell(actcell);
1383 for (; cell < actcell && !tabular.isLastRow(cell); ++cell) {
1384 if (tabular.isLastCellInRow(cell)) {
1385 cursory_ += tabular.getDescentOfRow(actrow) +
1386 tabular.getAscentOfRow(actrow + 1) +
1387 tabular.getAdditionalHeight(actrow + 1);
1391 if (!locked || nodraw()) {
1392 if (the_locking_inset)
1396 // we need this only from here on!!!
1398 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1399 int new_x = getCellXPos(actcell);
1400 int old_x = cursorx_;
1403 // cursor.x(getCellXPos(actcell) + offset);
1404 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1405 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1408 updateLocal(bv, FULL);
1409 } else if (the_locking_inset &&
1410 tabular.getWidthOfColumn(actcell) > bv->workWidth() - 20)
1412 int xx = cursorx_ - offset + bv->text->getRealCursorX();
1413 if (xx > (bv->workWidth()-20)) {
1414 scroll(bv, -(xx - bv->workWidth() + 60));
1415 updateLocal(bv, FULL);
1416 } else if (xx < 20) {
1422 updateLocal(bv, FULL);
1424 } else if ((cursorx_ - offset) > 20 &&
1425 (cursorx_ - offset + tabular.getWidthOfColumn(actcell))
1426 > (bv->workWidth() - 20)) {
1427 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1428 updateLocal(bv, FULL);
1429 } else if ((cursorx_ - offset) < 20) {
1430 scroll(bv, 20 - cursorx_ + offset);
1431 updateLocal(bv, FULL);
1432 } else if (scroll() && top_x > 20 &&
1433 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1434 scroll(bv, old_x - cursorx_);
1435 updateLocal(bv, FULL);
1437 if (the_locking_inset) {
1438 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
1441 if ((!the_locking_inset ||
1442 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1443 actcell != oldcell) {
1444 InsetTabularMailer(*this).updateDialog(bv);
1451 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1453 if (lock && !old_locking_inset) {
1454 if (activateCellInset(bv))
1457 bool moved = isRightToLeft(bv)
1458 ? movePrevCell(bv) : moveNextCell(bv);
1460 return FINISHED_RIGHT;
1461 if (lock && activateCellInset(bv))
1465 return DISPATCHED_NOUPDATE;
1469 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1471 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1474 if (lock) { // behind the inset
1475 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1479 return DISPATCHED_NOUPDATE;
1483 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1485 int const ocell = actcell;
1486 actcell = tabular.getCellAbove(actcell);
1487 if (actcell == ocell) // we moved out of the inset
1493 if (old_locking_inset) {
1494 old_locking_inset->getCursorPos(bv, x, y);
1495 x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell);
1497 if (activateCellInset(bv, x, 0))
1500 return DISPATCHED_NOUPDATE;
1504 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1506 int const ocell = actcell;
1507 actcell = tabular.getCellBelow(actcell);
1508 if (actcell == ocell) // we moved out of the inset
1509 return FINISHED_DOWN;
1514 if (old_locking_inset) {
1515 old_locking_inset->getCursorPos(bv, x, y);
1516 x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell);
1518 if (activateCellInset(bv, x, 0))
1521 return DISPATCHED_NOUPDATE;
1525 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1527 if (isRightToLeft(bv)) {
1528 if (tabular.isFirstCellInRow(actcell)) {
1529 int row = tabular.row_of_cell(actcell);
1530 if (row == tabular.rows() - 1)
1532 actcell = tabular.getLastCellInRow(row);
1533 actcell = tabular.getCellBelow(actcell);
1540 if (tabular.isLastCell(actcell))
1545 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1546 isRightToLeftPar(bv->buffer()->params);
1547 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1554 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1556 if (isRightToLeft(bv)) {
1557 if (tabular.isLastCellInRow(actcell)) {
1558 int row = tabular.row_of_cell(actcell);
1561 actcell = tabular.getFirstCellInRow(row);
1562 actcell = tabular.getCellAbove(actcell);
1564 if (tabular.isLastCell(actcell))
1569 if (!actcell) // first cell
1574 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1575 isRightToLeftPar(bv->buffer()->params);
1576 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1583 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1587 setSelection(0, tabular.getNumberOfCells() - 1);
1589 if (hasSelection()) {
1590 setUndo(bv, Undo::EDIT);
1591 bool const frozen = undo_frozen;
1594 // apply the fontchange on the whole selection
1599 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1600 for(int i = sel_row_start; i <= sel_row_end; ++i)
1601 for(int j = sel_col_start; j <= sel_col_end; ++j)
1602 tabular.getCellInset(i, j).setFont(bv, font, tall, true);
1608 updateLocal(bv, INIT);
1610 if (the_locking_inset)
1611 the_locking_inset->setFont(bv, font, tall);
1615 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1617 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1620 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1621 string const tmp = tabularFeature[i].feature;
1623 if (tmp == what.substr(0, tmp.length())) {
1624 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1625 //tabularFeatures[i].feature.length())) {
1626 action = tabularFeature[i].action;
1630 if (action == LyXTabular::LAST_ACTION)
1634 ltrim(what.substr(tabularFeature[i].feature.length()));
1635 tabularFeatures(bv, action, val);
1641 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1642 string const & special, bool & flag)
1644 if (special == "dl_above") {
1647 } else if (special == "dl_below") {
1648 ltt.bottomDL = flag;
1650 } else if (special == "empty") {
1662 void InsetTabular::tabularFeatures(BufferView * bv,
1663 LyXTabular::Feature feature,
1664 string const & value)
1670 bool setLines = false;
1671 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1672 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1675 case LyXTabular::M_ALIGN_LEFT:
1676 case LyXTabular::ALIGN_LEFT:
1677 setAlign = LYX_ALIGN_LEFT;
1679 case LyXTabular::M_ALIGN_RIGHT:
1680 case LyXTabular::ALIGN_RIGHT:
1681 setAlign = LYX_ALIGN_RIGHT;
1683 case LyXTabular::M_ALIGN_CENTER:
1684 case LyXTabular::ALIGN_CENTER:
1685 setAlign = LYX_ALIGN_CENTER;
1687 case LyXTabular::ALIGN_BLOCK:
1688 setAlign = LYX_ALIGN_BLOCK;
1690 case LyXTabular::M_VALIGN_TOP:
1691 case LyXTabular::VALIGN_TOP:
1692 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1694 case LyXTabular::M_VALIGN_BOTTOM:
1695 case LyXTabular::VALIGN_BOTTOM:
1696 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1698 case LyXTabular::M_VALIGN_CENTER:
1699 case LyXTabular::VALIGN_CENTER:
1700 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1705 if (hasSelection()) {
1706 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1708 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1709 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1711 setUndo(bv, Undo::FINISH);
1713 int row = tabular.row_of_cell(actcell);
1714 int column = tabular.column_of_cell(actcell);
1716 LyXTabular::ltType ltt;
1719 case LyXTabular::SET_PWIDTH:
1721 LyXLength const vallen(value);
1722 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1724 bool const update = (tmplen != vallen);
1725 tabular.setColumnPWidth(actcell, vallen);
1727 // We need this otherwise we won't resize
1728 // the insettext of the active cell (if any)
1729 // until later (see InsetText::do_resize)
1730 unlockInsetInInset(bv, the_locking_inset);
1732 for (int i = 0; i < tabular.rows(); ++i)
1733 tabular.getCellInset(i, column).resizeLyXText(bv);
1734 updateLocal(bv, INIT);
1738 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1739 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1740 else if (!vallen.zero()
1741 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1742 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1745 case LyXTabular::SET_MPWIDTH:
1747 LyXLength const vallen(value);
1748 LyXLength const & tmplen = tabular.getPWidth(actcell);
1750 bool const update = (tmplen != vallen);
1751 tabular.setMColumnPWidth(actcell, vallen);
1753 // We need this otherwise we won't resize
1754 // the insettext of the active cell (if any)
1755 // until later (see InsetText::do_resize)
1756 unlockInsetInInset(bv, the_locking_inset);
1758 for (int i = 0; i < tabular.rows(); ++i)
1759 tabular.getCellInset(i, column).resizeLyXText(bv);
1761 updateLocal(bv, INIT);
1765 case LyXTabular::SET_SPECIAL_COLUMN:
1766 case LyXTabular::SET_SPECIAL_MULTI:
1767 tabular.setAlignSpecial(actcell,value,feature);
1768 updateLocal(bv, FULL);
1770 case LyXTabular::APPEND_ROW:
1771 // append the row into the tabular
1772 unlockInsetInInset(bv, the_locking_inset);
1773 tabular.appendRow(bv->buffer()->params, actcell);
1774 updateLocal(bv, INIT);
1776 case LyXTabular::APPEND_COLUMN:
1777 // append the column into the tabular
1778 unlockInsetInInset(bv, the_locking_inset);
1779 tabular.appendColumn(bv->buffer()->params, actcell);
1780 actcell = tabular.getCellNumber(row, column);
1781 updateLocal(bv, INIT);
1783 case LyXTabular::DELETE_ROW:
1784 unlockInsetInInset(bv, the_locking_inset);
1785 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1786 tabular.deleteRow(sel_row_start);
1788 if (sel_row_start >= tabular.rows())
1790 actcell = tabular.getCellNumber(sel_row_start, column);
1792 updateLocal(bv, INIT);
1794 case LyXTabular::DELETE_COLUMN:
1795 unlockInsetInInset(bv, the_locking_inset);
1796 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1797 tabular.deleteColumn(sel_col_start);
1799 if (sel_col_start >= tabular.columns())
1801 actcell = tabular.getCellNumber(row, sel_col_start);
1803 updateLocal(bv, INIT);
1805 case LyXTabular::M_TOGGLE_LINE_TOP:
1807 case LyXTabular::TOGGLE_LINE_TOP:
1809 bool lineSet = !tabular.topLine(actcell, flag);
1810 for (int i = sel_row_start; i <= sel_row_end; ++i)
1811 for (int j = sel_col_start; j <= sel_col_end; ++j)
1813 tabular.getCellNumber(i, j),
1815 updateLocal(bv, INIT);
1819 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1821 case LyXTabular::TOGGLE_LINE_BOTTOM:
1823 bool lineSet = !tabular.bottomLine(actcell, flag);
1824 for (int i = sel_row_start; i <= sel_row_end; ++i)
1825 for (int j = sel_col_start; j <= sel_col_end; ++j)
1826 tabular.setBottomLine(
1827 tabular.getCellNumber(i, j),
1830 updateLocal(bv, INIT);
1834 case LyXTabular::M_TOGGLE_LINE_LEFT:
1836 case LyXTabular::TOGGLE_LINE_LEFT:
1838 bool lineSet = !tabular.leftLine(actcell, flag);
1839 for (int i = sel_row_start; i <= sel_row_end; ++i)
1840 for (int j = sel_col_start; j <= sel_col_end; ++j)
1841 tabular.setLeftLine(
1842 tabular.getCellNumber(i,j),
1845 updateLocal(bv, INIT);
1849 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1851 case LyXTabular::TOGGLE_LINE_RIGHT:
1853 bool lineSet = !tabular.rightLine(actcell, flag);
1854 for (int i = sel_row_start; i <= sel_row_end; ++i)
1855 for (int j = sel_col_start; j <= sel_col_end; ++j)
1856 tabular.setRightLine(
1857 tabular.getCellNumber(i,j),
1860 updateLocal(bv, INIT);
1864 case LyXTabular::M_ALIGN_LEFT:
1865 case LyXTabular::M_ALIGN_RIGHT:
1866 case LyXTabular::M_ALIGN_CENTER:
1868 case LyXTabular::ALIGN_LEFT:
1869 case LyXTabular::ALIGN_RIGHT:
1870 case LyXTabular::ALIGN_CENTER:
1871 case LyXTabular::ALIGN_BLOCK:
1872 for (int i = sel_row_start; i <= sel_row_end; ++i)
1873 for (int j = sel_col_start; j <= sel_col_end; ++j)
1874 tabular.setAlignment(
1875 tabular.getCellNumber(i, j),
1878 updateLocal(bv, INIT);
1880 case LyXTabular::M_VALIGN_TOP:
1881 case LyXTabular::M_VALIGN_BOTTOM:
1882 case LyXTabular::M_VALIGN_CENTER:
1884 case LyXTabular::VALIGN_TOP:
1885 case LyXTabular::VALIGN_BOTTOM:
1886 case LyXTabular::VALIGN_CENTER:
1887 for (int i = sel_row_start; i <= sel_row_end; ++i)
1888 for (int j = sel_col_start; j <= sel_col_end; ++j)
1889 tabular.setVAlignment(
1890 tabular.getCellNumber(i, j),
1892 updateLocal(bv, INIT);
1894 case LyXTabular::MULTICOLUMN:
1896 if (sel_row_start != sel_row_end) {
1897 #ifdef WITH_WARNINGS
1898 #warning Need I say it ? This is horrible.
1900 Alert::error(_("Error setting multicolumn"),
1901 _("You cannot set multicolumn vertically."));
1904 // just multicol for one Single Cell
1905 if (!hasSelection()) {
1906 // check wether we are completly in a multicol
1907 if (tabular.isMultiColumn(actcell)) {
1908 tabular.unsetMultiColumn(actcell);
1909 updateLocal(bv, INIT);
1911 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1912 updateLocal(bv, CELL);
1916 // we have a selection so this means we just add all this
1917 // cells to form a multicolumn cell
1921 if (sel_cell_start > sel_cell_end) {
1922 s_start = sel_cell_end;
1923 s_end = sel_cell_start;
1925 s_start = sel_cell_start;
1926 s_end = sel_cell_end;
1928 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1931 updateLocal(bv, INIT);
1934 case LyXTabular::SET_ALL_LINES:
1936 case LyXTabular::UNSET_ALL_LINES:
1937 for (int i = sel_row_start; i <= sel_row_end; ++i)
1938 for (int j = sel_col_start; j <= sel_col_end; ++j)
1939 tabular.setAllLines(
1940 tabular.getCellNumber(i,j), setLines);
1941 updateLocal(bv, INIT);
1943 case LyXTabular::SET_LONGTABULAR:
1944 tabular.setLongTabular(true);
1945 updateLocal(bv, INIT); // because this toggles displayed
1947 case LyXTabular::UNSET_LONGTABULAR:
1948 tabular.setLongTabular(false);
1949 updateLocal(bv, INIT); // because this toggles displayed
1951 case LyXTabular::SET_ROTATE_TABULAR:
1952 tabular.setRotateTabular(true);
1954 case LyXTabular::UNSET_ROTATE_TABULAR:
1955 tabular.setRotateTabular(false);
1957 case LyXTabular::SET_ROTATE_CELL:
1958 for (int i = sel_row_start; i <= sel_row_end; ++i)
1959 for (int j = sel_col_start; j<=sel_col_end; ++j)
1960 tabular.setRotateCell(
1961 tabular.getCellNumber(i, j),
1964 case LyXTabular::UNSET_ROTATE_CELL:
1965 for (int i = sel_row_start; i <= sel_row_end; ++i)
1966 for (int j = sel_col_start; j <= sel_col_end; ++j)
1967 tabular.setRotateCell(
1968 tabular.getCellNumber(i, j), false);
1970 case LyXTabular::SET_USEBOX:
1972 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1973 if (val == tabular.getUsebox(actcell))
1974 val = LyXTabular::BOX_NONE;
1975 for (int i = sel_row_start; i <= sel_row_end; ++i)
1976 for (int j = sel_col_start; j <= sel_col_end; ++j)
1978 tabular.getCellNumber(i, j), val);
1981 case LyXTabular::UNSET_LTFIRSTHEAD:
1983 case LyXTabular::SET_LTFIRSTHEAD:
1984 tabular.getRowOfLTFirstHead(row, ltt);
1985 checkLongtableSpecial(ltt, value, flag);
1986 tabular.setLTHead(row, flag, ltt, true);
1988 case LyXTabular::UNSET_LTHEAD:
1990 case LyXTabular::SET_LTHEAD:
1991 tabular.getRowOfLTHead(row, ltt);
1992 checkLongtableSpecial(ltt, value, flag);
1993 tabular.setLTHead(row, flag, ltt, false);
1995 case LyXTabular::UNSET_LTFOOT:
1997 case LyXTabular::SET_LTFOOT:
1998 tabular.getRowOfLTFoot(row, ltt);
1999 checkLongtableSpecial(ltt, value, flag);
2000 tabular.setLTFoot(row, flag, ltt, false);
2002 case LyXTabular::UNSET_LTLASTFOOT:
2004 case LyXTabular::SET_LTLASTFOOT:
2005 tabular.getRowOfLTLastFoot(row, ltt);
2006 checkLongtableSpecial(ltt, value, flag);
2007 tabular.setLTFoot(row, flag, ltt, true);
2009 case LyXTabular::SET_LTNEWPAGE:
2011 bool what = !tabular.getLTNewPage(row);
2012 tabular.setLTNewPage(row, what);
2015 // dummy stuff just to avoid warnings
2016 case LyXTabular::LAST_ACTION:
2020 InsetTabularMailer(*this).updateDialog(bv);
2024 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y,
2025 mouse_button::state button, bool behind)
2027 UpdatableInset & inset = tabular.getCellInset(actcell);
2030 x = inset.x() + inset.width();
2031 y = inset.descent();
2033 //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2034 //inset_y = cursory_;
2035 inset.localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2036 if (!the_locking_inset)
2038 updateLocal(bv, CELL);
2039 return (the_locking_inset != 0);
2043 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2044 mouse_button::state button)
2046 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2048 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2052 bool InsetTabular::insetHit(BufferView *, int x, int) const
2055 > cursorx_ + tabular.getBeginningOfTextInCell(actcell);
2059 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2061 resizeLyXText(bv, recursive);
2065 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2068 for(int i = 0; i < tabular.rows(); ++i)
2069 for(int j = 0; j < tabular.columns(); ++j)
2070 tabular.getCellInset(i, j).resizeLyXText(bv, true);
2075 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2076 bool const recursive) const
2078 if (the_locking_inset)
2079 return the_locking_inset->getLyXText(bv, recursive);
2080 return Inset::getLyXText(bv, recursive);
2084 bool InsetTabular::showInsetDialog(BufferView * bv) const
2086 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2087 InsetTabularMailer(*this).showDialog(bv);
2092 void InsetTabular::openLayoutDialog(BufferView * bv) const
2094 if (the_locking_inset) {
2095 InsetTabular * inset = static_cast<InsetTabular *>
2096 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2098 inset->openLayoutDialog(bv);
2102 InsetTabularMailer(*this).showDialog(bv);
2107 // function returns an object as defined in func_status.h:
2108 // states OK, Unknown, Disabled, On, Off.
2110 FuncStatus InsetTabular::getStatus(string const & what) const
2112 int action = LyXTabular::LAST_ACTION;
2116 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2117 string const tmp = tabularFeature[i].feature;
2118 if (tmp == what.substr(0, tmp.length())) {
2119 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2120 // tabularFeatures[i].feature.length())) {
2121 action = tabularFeature[i].action;
2125 if (action == LyXTabular::LAST_ACTION) {
2127 return status.unknown(true);
2130 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2135 LyXTabular::ltType dummyltt;
2138 if (hasSelection()) {
2139 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2141 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2145 case LyXTabular::SET_PWIDTH:
2146 case LyXTabular::SET_MPWIDTH:
2147 case LyXTabular::SET_SPECIAL_COLUMN:
2148 case LyXTabular::SET_SPECIAL_MULTI:
2149 case LyXTabular::APPEND_ROW:
2150 case LyXTabular::APPEND_COLUMN:
2151 case LyXTabular::DELETE_ROW:
2152 case LyXTabular::DELETE_COLUMN:
2153 case LyXTabular::SET_ALL_LINES:
2154 case LyXTabular::UNSET_ALL_LINES:
2155 return status.clear();
2157 case LyXTabular::MULTICOLUMN:
2158 status.setOnOff(tabular.isMultiColumn(actcell));
2160 case LyXTabular::M_TOGGLE_LINE_TOP:
2162 case LyXTabular::TOGGLE_LINE_TOP:
2163 status.setOnOff(tabular.topLine(actcell, flag));
2165 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2167 case LyXTabular::TOGGLE_LINE_BOTTOM:
2168 status.setOnOff(tabular.bottomLine(actcell, flag));
2170 case LyXTabular::M_TOGGLE_LINE_LEFT:
2172 case LyXTabular::TOGGLE_LINE_LEFT:
2173 status.setOnOff(tabular.leftLine(actcell, flag));
2175 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2177 case LyXTabular::TOGGLE_LINE_RIGHT:
2178 status.setOnOff(tabular.rightLine(actcell, flag));
2180 case LyXTabular::M_ALIGN_LEFT:
2182 case LyXTabular::ALIGN_LEFT:
2183 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2185 case LyXTabular::M_ALIGN_RIGHT:
2187 case LyXTabular::ALIGN_RIGHT:
2188 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2190 case LyXTabular::M_ALIGN_CENTER:
2192 case LyXTabular::ALIGN_CENTER:
2193 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2195 case LyXTabular::ALIGN_BLOCK:
2196 status.disabled(tabular.getPWidth(actcell).zero());
2197 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2199 case LyXTabular::M_VALIGN_TOP:
2201 case LyXTabular::VALIGN_TOP:
2202 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2204 case LyXTabular::M_VALIGN_BOTTOM:
2206 case LyXTabular::VALIGN_BOTTOM:
2207 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2209 case LyXTabular::M_VALIGN_CENTER:
2211 case LyXTabular::VALIGN_CENTER:
2212 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2214 case LyXTabular::SET_LONGTABULAR:
2215 status.setOnOff(tabular.isLongTabular());
2217 case LyXTabular::UNSET_LONGTABULAR:
2218 status.setOnOff(!tabular.isLongTabular());
2220 case LyXTabular::SET_ROTATE_TABULAR:
2221 status.setOnOff(tabular.getRotateTabular());
2223 case LyXTabular::UNSET_ROTATE_TABULAR:
2224 status.setOnOff(!tabular.getRotateTabular());
2226 case LyXTabular::SET_ROTATE_CELL:
2227 status.setOnOff(tabular.getRotateCell(actcell));
2229 case LyXTabular::UNSET_ROTATE_CELL:
2230 status.setOnOff(!tabular.getRotateCell(actcell));
2232 case LyXTabular::SET_USEBOX:
2233 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2235 case LyXTabular::SET_LTFIRSTHEAD:
2236 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2238 case LyXTabular::SET_LTHEAD:
2239 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2241 case LyXTabular::SET_LTFOOT:
2242 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2244 case LyXTabular::SET_LTLASTFOOT:
2245 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2247 case LyXTabular::SET_LTNEWPAGE:
2248 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2252 status.disabled(true);
2259 void InsetTabular::getLabelList(std::vector<string> & list) const
2261 tabular.getLabelList(list);
2265 bool InsetTabular::copySelection(BufferView * bv)
2267 if (!hasSelection())
2270 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2271 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2272 if (sel_col_start > sel_col_end) {
2273 sel_col_start = sel_col_end;
2274 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2276 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2278 int const columns = sel_col_end - sel_col_start + 1;
2280 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2281 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2282 if (sel_row_start > sel_row_end) {
2283 swap(sel_row_start, sel_row_end);
2285 int const rows = sel_row_end - sel_row_start + 1;
2287 delete paste_tabular;
2288 paste_tabular = new LyXTabular(bv->buffer()->params,
2289 this, tabular); // rows, columns);
2290 for (int i = 0; i < sel_row_start; ++i)
2291 paste_tabular->deleteRow(0);
2292 while (paste_tabular->rows() > rows)
2293 paste_tabular->deleteRow(rows);
2294 paste_tabular->setTopLine(0, true, true);
2295 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2297 for (int i = 0; i < sel_col_start; ++i)
2298 paste_tabular->deleteColumn(0);
2299 while (paste_tabular->columns() > columns)
2300 paste_tabular->deleteColumn(columns);
2301 paste_tabular->setLeftLine(0, true, true);
2302 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2306 paste_tabular->ascii(bv->buffer(), sstr,
2307 (int)parOwner()->params().depth(), true, '\t');
2308 bv->stuffClipboard(STRCONV(sstr.str()));
2313 bool InsetTabular::pasteSelection(BufferView * bv)
2318 for (int r1 = 0, r2 = actrow;
2319 r1 < paste_tabular->rows() && r2 < tabular.rows();
2321 for (int c1 = 0, c2 = actcol;
2322 c1 < paste_tabular->columns() && c2 < tabular.columns();
2324 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
2325 tabular.isPartOfMultiColumn(r2, c2))
2327 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
2331 if (tabular.isPartOfMultiColumn(r2, c2)) {
2335 InsetText & inset = tabular.getCellInset(r2, c2);
2336 inset = paste_tabular->getCellInset(r1, c1);
2337 inset.setOwner(this);
2338 inset.deleteLyXText(bv);
2346 bool InsetTabular::cutSelection(BufferParams const & bp)
2348 if (!hasSelection())
2351 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2352 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2353 if (sel_col_start > sel_col_end) {
2354 sel_col_start = sel_col_end;
2355 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2357 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2359 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2360 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2361 if (sel_row_start > sel_row_end) {
2362 swap(sel_row_start, sel_row_end);
2364 if (sel_cell_start > sel_cell_end) {
2365 swap(sel_cell_start, sel_cell_end);
2367 for (int i = sel_row_start; i <= sel_row_end; ++i)
2368 for (int j = sel_col_start; j <= sel_col_end; ++j)
2369 tabular.getCellInset(tabular.getCellNumber(i, j)).clear(bp.tracking_changes);
2374 bool InsetTabular::isRightToLeft(BufferView * bv)
2376 return bv->getParentLanguage(this)->RightToLeft();
2380 bool InsetTabular::nodraw() const
2382 if (!UpdatableInset::nodraw() && the_locking_inset)
2383 return the_locking_inset->nodraw();
2384 return UpdatableInset::nodraw();
2388 int InsetTabular::scroll(bool recursive) const
2390 int sx = UpdatableInset::scroll(false);
2392 if (recursive && the_locking_inset)
2393 sx += the_locking_inset->scroll(recursive);
2399 void InsetTabular::getSelection(int & srow, int & erow,
2400 int & scol, int & ecol) const
2402 int const start = hasSelection() ? sel_cell_start : actcell;
2403 int const end = hasSelection() ? sel_cell_end : actcell;
2405 srow = tabular.row_of_cell(start);
2406 erow = tabular.row_of_cell(end);
2411 scol = tabular.column_of_cell(start);
2412 ecol = tabular.column_of_cell(end);
2416 ecol = tabular.right_column_of_cell(end);
2421 ParagraphList * InsetTabular::getParagraphs(int i) const
2423 return (i < tabular.getNumberOfCells())
2424 ? tabular.getCellInset(i).getParagraphs(0)
2429 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2431 if (the_locking_inset)
2432 return the_locking_inset->cursor(bv);
2433 return Inset::cursor(bv);
2437 Inset * InsetTabular::getInsetFromID(int id_arg) const
2440 return const_cast<InsetTabular *>(this);
2442 for (int i = 0; i < tabular.rows(); ++i) {
2443 for (int j = 0; j < tabular.columns(); ++j) {
2444 Inset * inset = tabular.getCellInset(i, j).getInsetFromID(id_arg);
2454 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2457 if (the_locking_inset) {
2458 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2459 if (!word.word().empty()) {
2463 if (tabular.isLastCell(actcell)) {
2464 bv->unlockInset(const_cast<InsetTabular *>(this));
2466 return WordLangTuple();
2470 // otherwise we have to lock the next inset and ask for it's selecttion
2471 tabular.getCellInset(actcell)
2472 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2473 WordLangTuple word(selectNextWordInt(bv, value));
2475 if (!word.word().empty())
2481 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2483 // when entering this function the inset should be ALWAYS locked!
2484 Assert(the_locking_inset);
2486 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2487 if (!word.word().empty())
2490 if (tabular.isLastCell(actcell)) {
2491 bv->unlockInset(const_cast<InsetTabular *>(this));
2492 return WordLangTuple();
2495 // otherwise we have to lock the next inset and ask for it's selecttion
2497 tabular.getCellInset(actcell)
2498 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2499 return selectNextWordInt(bv, value);
2503 void InsetTabular::selectSelectedWord(BufferView * bv)
2505 if (the_locking_inset)
2506 the_locking_inset->selectSelectedWord(bv);
2510 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2512 if (the_locking_inset)
2513 the_locking_inset->toggleSelection(bv, kill_selection);
2517 void InsetTabular::markErased()
2519 for (int cell = 0; cell < tabular.getNumberOfCells(); ++cell)
2520 tabular.getCellInset(cell).markErased();
2524 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2526 if (the_locking_inset) {
2527 if (the_locking_inset->nextChange(bv, length)) {
2528 updateLocal(bv, CELL);
2531 if (tabular.isLastCell(actcell))
2535 InsetText & inset = tabular.getCellInset(actcell);
2536 if (inset.nextChange(bv, length)) {
2537 updateLocal(bv, FULL);
2540 while (!tabular.isLastCell(actcell)) {
2542 InsetText & inset = tabular.getCellInset(actcell);
2543 if (inset.nextChange(bv, length)) {
2544 updateLocal(bv, FULL);
2552 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2556 if (the_locking_inset) {
2557 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2558 updateLocal(bv, CELL);
2561 if (tabular.isLastCell(actcell))
2565 InsetText & inset = tabular.getCellInset(cell);
2566 if (inset.searchForward(bv, str, cs, mw)) {
2567 updateLocal(bv, FULL);
2570 while (!tabular.isLastCell(cell)) {
2572 InsetText & inset = tabular.getCellInset(cell);
2573 if (inset.searchForward(bv, str, cs, mw)) {
2574 updateLocal(bv, FULL);
2582 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2585 int cell = tabular.getNumberOfCells();
2586 if (the_locking_inset) {
2587 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2588 updateLocal(bv, CELL);
2596 InsetText & inset = tabular.getCellInset(cell);
2597 if (inset.searchBackward(bv, str, cs, mw)) {
2598 updateLocal(bv, CELL);
2606 bool InsetTabular::insetAllowed(Inset::Code code) const
2608 if (the_locking_inset)
2609 return the_locking_inset->insetAllowed(code);
2610 // we return true here because if the inset is not locked someone
2611 // wants to insert something in one of our insettexts and we generally
2617 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2619 const int cell = tabular.getCellFromInset(in, actcell);
2622 return tabular.getPWidth(cell).zero();
2624 // well we didn't obviously find it so maybe our owner knows more
2626 return owner()->forceDefaultParagraphs(in);
2627 // if we're here there is really something strange going on!!!
2632 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2635 if (buf.length() <= 0)
2641 string::size_type len = buf.length();
2642 string::size_type p = 0;
2645 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2654 maxCols = max(cols, maxCols);
2660 maxCols = max(cols, maxCols);
2661 LyXTabular * loctab;
2666 delete paste_tabular;
2667 paste_tabular = new LyXTabular(bv->buffer()->params,
2668 this, rows, maxCols);
2669 loctab = paste_tabular;
2678 string::size_type op = 0;
2679 int cells = loctab->getNumberOfCells();
2682 rows = loctab->rows();
2683 int const columns = loctab->columns();
2685 while (cell < cells && p < len && row < rows &&
2686 (p = buf.find_first_of("\t\n", p)) != string::npos)
2692 // we can only set this if we are not too far right
2693 if (cols < columns) {
2694 InsetText & inset = loctab->getCellInset(cell);
2695 LyXFont const font = inset.getLyXText(bv)->
2696 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2697 inset.setText(buf.substr(op, p - op), font);
2703 // we can only set this if we are not too far right
2704 if (cols < columns) {
2705 InsetText & inset = tabular.getCellInset(cell);
2706 LyXFont const font = inset.getLyXText(bv)->
2707 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2708 inset.setText(buf.substr(op, p - op), font);
2713 cell = loctab->getCellNumber(row, cols);
2719 // check for the last cell if there is no trailing '\n'
2720 if (cell < cells && op < len) {
2721 InsetText & inset = loctab->getCellInset(cell);
2722 LyXFont const font = inset.getLyXText(bv)->
2723 getFont(bv->buffer(), inset.paragraphs.begin(), 0);
2724 inset.setText(buf.substr(op, len - op), font);
2731 void InsetTabular::addPreview(PreviewLoader & loader) const
2733 int const rows = tabular.rows();
2734 int const columns = tabular.columns();
2735 for (int i = 0; i < rows; ++i)
2736 for (int j = 0; j < columns; ++j)
2737 tabular.getCellInset(i, j).addPreview(loader);
2741 string const InsetTabularMailer::name_("tabular");
2743 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
2744 : inset_(const_cast<InsetTabular &>(inset))
2748 string const InsetTabularMailer::inset2string(Buffer const &) const
2750 return params2string(inset_);
2754 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2756 istringstream data(STRCONV(in));
2758 lex.setStream(data);
2760 #warning CHECK verify that this is a sane value to return.
2766 string const token = lex.getString();
2774 string const token = lex.getString();
2775 if (token != "\\active_cell")
2778 cell = lex.getInteger();
2781 // This is part of the inset proper that is usually swallowed
2782 // by Buffer::readInset
2785 string const token = lex.getString();
2786 if (token != "Tabular")
2793 Buffer const * const buffer = inset.buffer();
2795 inset.read(buffer, lex);
2797 // We can't set the active cell, but we can tell the frontend
2803 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2805 Buffer const * const buffer = inset.buffer();
2810 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2811 inset.write(buffer, data);
2812 data << "\\end_inset\n";
2813 return STRCONV(data.str());