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" << endl;
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 << endl;
278 BufferView * bv = pi.base.bv;
281 UpdatableInset::draw(pi, x, y);
289 x += ADD_TO_TABULAR_WIDTH;
292 first_visible_cell = -1;
293 for (int i = 0; i < tabular.rows(); ++i) {
295 cell = tabular.getCellNumber(i, 0);
296 if (y + tabular.getDescentOfRow(i) <= 0 &&
297 y - tabular.getAscentOfRow(i) < pi.pain.paperHeight())
299 y += tabular.getDescentOfRow(i) +
300 tabular.getAscentOfRow(i + 1) +
301 tabular.getAdditionalHeight(i + 1);
304 for (int j = 0; j < tabular.columns(); ++j) {
305 if (nx > bv->workWidth())
307 if (tabular.isPartOfMultiColumn(i, j))
309 int cx = nx + tabular.getBeginningOfTextInCell(cell);
310 if (first_visible_cell < 0)
311 first_visible_cell = cell;
312 if (hasSelection()) {
313 drawCellSelection(pi.pain, nx, y, i, j, cell);
316 tabular.getCellInset(cell).draw(pi, cx, y);
317 drawCellLines(pi.pain, nx, y, i, cell);
318 nx += tabular.getWidthOfColumn(cell);
322 // Would be nice, but for some completely unfathomable reason,
323 // on a col resize to a new fixed width, even though the insettexts
324 // are resized, the cell isn't, but drawing all cells in a tall table
325 // has the desired effect somehow. Complete dark magic.
327 // avoiding drawing the rest of a long table is
328 // a pretty big speedup
329 if (y > bv->workHeight())
333 y += tabular.getDescentOfRow(i) +
334 tabular.getAscentOfRow(i + 1) +
335 tabular.getAdditionalHeight(i + 1);
342 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
343 int row, int cell) const
345 int x2 = x + tabular.getWidthOfColumn(cell);
348 if (!tabular.topAlreadyDrawn(cell)) {
349 on_off = !tabular.topLine(cell);
350 pain.line(x, y - tabular.getAscentOfRow(row),
351 x2, y - tabular.getAscentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
355 on_off = !tabular.bottomLine(cell);
356 pain.line(x, y + tabular.getDescentOfRow(row),
357 x2, y + tabular.getDescentOfRow(row),
358 on_off ? LColor::tabularonoffline : LColor::tabularline,
359 on_off ? Painter::line_onoffdash : Painter::line_solid);
360 if (!tabular.leftAlreadyDrawn(cell)) {
361 on_off = !tabular.leftLine(cell);
362 pain.line(x, y - tabular.getAscentOfRow(row),
363 x, y + tabular.getDescentOfRow(row),
364 on_off ? LColor::tabularonoffline : LColor::tabularline,
365 on_off ? Painter::line_onoffdash : Painter::line_solid);
367 on_off = !tabular.rightLine(cell);
368 pain.line(x2 - tabular.getAdditionalWidth(cell),
369 y - tabular.getAscentOfRow(row),
370 x2 - tabular.getAdditionalWidth(cell),
371 y + tabular.getDescentOfRow(row),
372 on_off ? LColor::tabularonoffline : LColor::tabularline,
373 on_off ? Painter::line_onoffdash : Painter::line_solid);
377 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
378 int row, int column, int cell) const
380 Assert(hasSelection());
381 int cs = tabular.column_of_cell(sel_cell_start);
382 int ce = tabular.column_of_cell(sel_cell_end);
385 cs = tabular.column_of_cell(sel_cell_end);
387 ce = tabular.right_column_of_cell(sel_cell_end);
390 int rs = tabular.row_of_cell(sel_cell_start);
391 int re = tabular.row_of_cell(sel_cell_end);
395 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
396 int w = tabular.getWidthOfColumn(cell);
397 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
398 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
399 w, h, LColor::selection);
404 string const InsetTabular::editMessage() const
406 return _("Opened table");
410 void InsetTabular::insetUnlock(BufferView * bv)
412 if (the_locking_inset) {
413 the_locking_inset->insetUnlock(bv);
414 updateLocal(bv, CELL);
415 the_locking_inset = 0;
420 if (scroll(false) || hasSelection()) {
425 updateLocal(bv, FULL);
430 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
432 lyxerr << "InsetTabular::updateLocal: " << what << endl;
433 if (!locked && what == CELL)
435 if (need_update < what) // only set this if it has greater update
438 if (need_update != NONE) {
439 bv->updateInset(const_cast<InsetTabular *>(this));
446 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
448 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
453 if (inset == &tabular.getCellInset(actcell)) {
454 lyxerr[Debug::INSETTEXT] << "OK" << endl;
455 the_locking_inset = &tabular.getCellInset(actcell);
458 } else if (!the_locking_inset) {
459 int const n = tabular.getNumberOfCells();
460 int const id = inset->id();
461 for (int i = 0; i < n; ++i) {
462 InsetText * in = &tabular.getCellInset(i);
465 the_locking_inset = in;
470 if (in->getInsetFromID(id)) {
472 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
473 return the_locking_inset->lockInsetInInset(bv, inset);
476 } else if (the_locking_inset && (the_locking_inset == inset)) {
477 lyxerr[Debug::INSETTEXT] << "OK" << endl;
479 } else if (the_locking_inset) {
480 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
481 return the_locking_inset->lockInsetInInset(bv, inset);
483 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
488 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
491 if (!the_locking_inset)
493 if (the_locking_inset == inset) {
494 the_locking_inset->insetUnlock(bv);
496 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
502 updateLocal(bv, CELL);
503 // this has to be here otherwise we don't redraw the cell!
504 the_locking_inset = 0;
507 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
508 if (inset->lyxCode() == TABULAR_CODE &&
509 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
510 InsetTabularMailer(*this).updateDialog(bv);
519 bool InsetTabular::updateInsetInInset(BufferView * bv, InsetOld * inset)
521 InsetOld * tl_inset = inset;
522 // look if this inset is really inside myself!
523 while (tl_inset->owner() && tl_inset->owner() != this)
524 tl_inset = tl_inset->owner();
525 // if we enter here it's not ower inset
526 if (!tl_inset->owner())
528 // we only have to do this if this is a subinset of our cells
529 if (tl_inset != inset) {
530 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
533 updateLocal(bv, CELL);
538 int InsetTabular::insetInInsetY() const
540 if (!the_locking_inset)
542 return inset_y + the_locking_inset->insetInInsetY();
546 UpdatableInset * InsetTabular::getLockingInset() const
548 return the_locking_inset ? the_locking_inset->getLockingInset() :
549 const_cast<InsetTabular *>(this);
553 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(InsetOld::Code c)
557 if (the_locking_inset)
558 return the_locking_inset->getFirstLockingInsetOfType(c);
563 bool InsetTabular::insertInset(BufferView * bv, InsetOld * inset)
565 if (the_locking_inset)
566 return the_locking_inset->insertInset(bv, inset);
571 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
573 if (hasSelection() && cmd.button() == mouse_button::button3)
576 if (hasSelection()) {
578 updateLocal(cmd.view(), FULL);
581 int const ocell = actcell;
582 int const orow = actrow;
583 BufferView * bv = cmd.view();
587 the_locking_inset = 0;
591 setPos(bv, cmd.x, cmd.y);
593 updateLocal(bv, NONE);
596 if (cmd.button() == mouse_button::button3) {
597 if ((ocell != actcell) && the_locking_inset) {
598 the_locking_inset->insetUnlock(bv);
599 updateLocal(bv, CELL);
600 the_locking_inset = 0;
606 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
608 if ((ocell == actcell) && the_locking_inset && inset_hit) {
610 FuncRequest cmd1 = cmd;
613 the_locking_inset->localDispatch(cmd1);
617 if (the_locking_inset) {
618 the_locking_inset->insetUnlock(bv);
619 updateLocal(bv, CELL);
620 the_locking_inset = 0;
623 if (cmd.button() == mouse_button::button2) {
624 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
628 if (inset_hit && bv->theLockingInset()) {
629 if (!bv->lockInset(&tabular.getCellInset(actcell))) {
630 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
633 FuncRequest cmd1 = cmd;
636 the_locking_inset->localDispatch(cmd1);
642 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
645 if (the_locking_inset) {
646 FuncRequest cmd1 = cmd;
649 ret = the_locking_inset->localDispatch(cmd1);
651 if (cmd.button() == mouse_button::button3 && !ret) {
652 InsetTabularMailer(*this).showDialog(cmd.view());
659 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
661 if (the_locking_inset) {
662 FuncRequest cmd1 = cmd;
665 the_locking_inset->localDispatch(cmd1);
669 BufferView * bv = cmd.view();
670 int const old_cell = actcell;
672 setPos(bv, cmd.x, cmd.y);
673 if (!hasSelection()) {
674 setSelection(actcell, actcell);
675 updateLocal(bv, FULL);
676 } else if (old_cell != actcell) {
677 setSelection(sel_cell_start, actcell);
678 updateLocal(bv, FULL);
683 InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
685 // We need to save the value of the_locking_inset as the call to
686 // the_locking_inset->localDispatch might unlock it.
687 old_locking_inset = the_locking_inset;
688 RESULT result = UpdatableInset::localDispatch(cmd);
689 BufferView * bv = cmd.view();
691 if (cmd.action == LFUN_INSET_EDIT) {
693 if (!bv->lockInset(this)) {
694 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
700 the_locking_inset = 0;
704 if (cmd.argument.size()) {
705 if (cmd.argument == "left") {
706 if (isRightToLeft(bv))
707 actcell = tabular.getLastCellInRow(0);
711 if (isRightToLeft(bv))
712 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
714 actcell = tabular.getNumberOfCells() - 1;
722 setPos(bv, cmd.x, cmd.y);
725 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
726 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
732 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
737 if (cmd.action < 0 && cmd.argument.empty())
740 bool hs = hasSelection();
743 // this one have priority over the locked InsetText, if we're not already
744 // inside another tabular then that one get's priority!
745 if (getFirstLockingInsetOfType(InsetOld::TABULAR_CODE) == this) {
746 switch (cmd.action) {
747 case LFUN_MOUSE_PRESS:
751 case LFUN_MOUSE_MOTION:
752 lfunMouseMotion(cmd);
755 case LFUN_MOUSE_RELEASE:
756 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
758 case LFUN_CELL_BACKWARD:
759 case LFUN_CELL_FORWARD:
760 unlockInsetInInset(bv, the_locking_inset);
761 if (cmd.action == LFUN_CELL_FORWARD)
762 moveNextCell(bv, old_locking_inset != 0);
764 movePrevCell(bv, old_locking_inset != 0);
767 updateLocal(bv, FULL);
768 if (!the_locking_inset) {
769 return DISPATCHED_NOUPDATE;
772 // this to avoid compiler warnings.
778 kb_action action = cmd.action;
779 string arg = cmd.argument;
780 if (the_locking_inset) {
781 result = the_locking_inset->localDispatch(cmd);
782 if (result == DISPATCHED_NOUPDATE) {
785 if (sc != scroll()) { // inset has been scrolled
786 updateLocal(bv, FULL);
789 } else if (result == DISPATCHED) {
790 updateLocal(bv, CELL);
792 } else if (result == FINISHED_UP) {
794 // Make sure to reset status message after
795 // exiting, e.g. math inset
796 bv->owner()->clearMessage();
797 } else if (result == FINISHED_DOWN) {
799 bv->owner()->clearMessage();
800 } else if (result == FINISHED_RIGHT) {
802 bv->owner()->clearMessage();
803 } else if (result == FINISHED) {
804 bv->owner()->clearMessage();
810 // --- Cursor Movements ----------------------------------
811 case LFUN_RIGHTSEL: {
812 int const start = hasSelection() ? sel_cell_start : actcell;
813 if (tabular.isLastCellInRow(actcell)) {
814 setSelection(start, actcell);
819 // if we are starting a selection, only select
820 // the current cell at the beginning
821 if (hasSelection()) {
822 moveRight(bv, false);
825 setSelection(start, end);
826 updateLocal(bv, FULL);
830 result = moveRight(bv);
833 updateLocal(bv, FULL);
836 int const start = hasSelection() ? sel_cell_start : actcell;
837 if (tabular.isFirstCellInRow(actcell)) {
838 setSelection(start, actcell);
843 // if we are starting a selection, only select
844 // the current cell at the beginning
845 if (hasSelection()) {
849 setSelection(start, end);
850 updateLocal(bv, FULL);
854 result = moveLeft(bv);
857 updateLocal(bv, FULL);
860 int const start = hasSelection() ? sel_cell_start : actcell;
861 int const ocell = actcell;
862 // if we are starting a selection, only select
863 // the current cell at the beginning
864 if (hasSelection()) {
866 if ((ocell == sel_cell_end) ||
867 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
868 setSelection(start, tabular.getCellBelow(sel_cell_end));
870 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
872 setSelection(start, start);
874 updateLocal(bv, FULL);
878 result = moveDown(bv, old_locking_inset != 0);
881 updateLocal(bv, FULL);
885 int const start = hasSelection() ? sel_cell_start : actcell;
886 int const ocell = actcell;
887 // if we are starting a selection, only select
888 // the current cell at the beginning
889 if (hasSelection()) {
891 if ((ocell == sel_cell_end) ||
892 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
893 setSelection(start, tabular.getCellAbove(sel_cell_end));
895 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
897 setSelection(start, start);
899 updateLocal(bv, FULL);
903 result = moveUp(bv, old_locking_inset != 0);
906 updateLocal(bv, FULL);
909 UpdateCodes code = CURSOR;
915 unlockInsetInInset(bv, the_locking_inset);
916 if (bv->text->top_y() + bv->painter().paperHeight() <
917 (top_baseline + tabular.getHeightOfTabular()))
919 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
921 actcell = tabular.getCellBelow(first_visible_cell) + column;
923 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
926 updateLocal(bv, code);
930 UpdateCodes code = CURSOR;
936 unlockInsetInInset(bv, the_locking_inset);
937 if (top_baseline < 0) {
938 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
940 if (top_baseline > 0)
943 actcell = tabular.getCellBelow(first_visible_cell) + column;
948 updateLocal(bv, code);
951 // none of these make sense for insettabular,
952 // but we must catch them to prevent any
953 // selection from being confused
957 case LFUN_WORDLEFTSEL:
959 case LFUN_WORDRIGHTSEL:
961 case LFUN_DOWN_PARAGRAPH:
962 case LFUN_DOWN_PARAGRAPHSEL:
963 case LFUN_UP_PARAGRAPH:
964 case LFUN_UP_PARAGRAPHSEL:
970 case LFUN_BEGINNINGBUF:
971 case LFUN_BEGINNINGBUFSEL:
975 case LFUN_LAYOUT_TABULAR: {
976 InsetTabularMailer(*this).showDialog(bv);
979 case LFUN_INSET_DIALOG_UPDATE: {
980 InsetTabularMailer(*this).updateDialog(bv);
983 case LFUN_TABULAR_FEATURE:
984 if (!tabularFeatures(bv, arg))
985 result = UNDISPATCHED;
987 // insert file functions
988 case LFUN_FILE_INSERT_ASCII_PARA:
989 case LFUN_FILE_INSERT_ASCII:
991 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
994 if (insertAsciiString(bv, tmpstr, false))
995 updateLocal(bv, INIT);
997 result = UNDISPATCHED;
1000 // cut and paste functions
1002 if (!copySelection(bv))
1006 recordUndo(bv, Undo::DELETE);
1007 cutSelection(bv->buffer()->params);
1008 updateLocal(bv, INIT);
1011 if (!hasSelection())
1016 case LFUN_PASTESELECTION:
1018 string const clip(bv->getClipboard());
1022 if (clip.find('\t') != string::npos) {
1026 string::size_type len = clip.length();
1027 string::size_type p = 0;
1030 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1038 maxCols = max(cols, maxCols);
1044 maxCols = max(cols, maxCols);
1045 delete paste_tabular;
1046 paste_tabular = new LyXTabular(bv->buffer()->params,
1047 this, rows, maxCols);
1048 string::size_type op = 0;
1050 int cells = paste_tabular->getNumberOfCells();
1052 while ((cell < cells) && (p < len) &&
1053 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1058 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1063 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1064 while (cols++ < maxCols)
1072 // check for the last cell if there is no trailing '\n'
1073 if ((cell < cells) && (op < len))
1074 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1077 if (!insertAsciiString(bv, clip, true))
1080 // so that the clipboard is used and it goes on
1082 // and executes LFUN_PASTESELECTION in insettext!
1083 delete paste_tabular;
1088 if (hasPasteBuffer()) {
1089 recordUndo(bv, Undo::INSERT);
1091 updateLocal(bv, INIT);
1094 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1096 // handle font changing stuff on selection before we lock the inset
1097 // in the default part!
1098 result = UNDISPATCHED;
1109 case LFUN_UNDERLINE:
1110 case LFUN_FONT_SIZE:
1111 if (bv->dispatch(FuncRequest(bv, action, arg)))
1112 result = DISPATCHED;
1118 // we try to activate the actual inset and put this event down to
1119 // the insets dispatch function.
1120 if (result == DISPATCHED || the_locking_inset)
1122 if (activateCellInset(bv)) {
1123 // reset need_update setted in above function!
1125 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1126 if (result == UNDISPATCHED || result >= FINISHED) {
1127 unlockInsetInInset(bv, the_locking_inset);
1128 // we need to update if this was requested before
1129 updateLocal(bv, NONE);
1130 return UNDISPATCHED;
1133 // so the below CELL is not set because this is higher
1134 // priority and we get a full redraw
1137 updateLocal(bv, CELL);
1142 if (result < FINISHED) {
1143 if (!the_locking_inset && bv->fitCursor())
1144 updateLocal(bv, FULL);
1146 bv->unlockInset(this);
1151 int InsetTabular::latex(Buffer const * buf, ostream & os,
1152 LatexRunParams const & runparams) const
1154 return tabular.latex(buf, os, runparams);
1158 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1161 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1163 return tabular.ascii(buf, os, 0, false, 0);
1167 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1169 return tabular.linuxdoc(buf,os);
1173 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1178 // if the table is inside a float it doesn't need the informaltable
1179 // wrapper. Search for it.
1180 for (master = owner();
1181 master && master->lyxCode() != InsetOld::FLOAT_CODE;
1182 master = master->owner());
1185 os << "<informaltable>";
1190 ret += tabular.docbook(buf, os, mixcont);
1192 os << "</informaltable>";
1201 void InsetTabular::validate(LaTeXFeatures & features) const
1203 tabular.validate(features);
1207 void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const
1210 // if we have a locking_inset we should have to check only this cell for
1211 // change so I'll try this to have a boost, but who knows ;) (Jug?)
1212 // This is _really_ important (André)
1213 if (need_update != INIT &&
1214 the_locking_inset == &tabular.getCellInset(actcell)) {
1217 for (int j = 0; j < tabular.columns(); ++j) {
1221 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1222 tabular.getCellInset(actrow, j).metrics(m, dim);
1223 maxAsc = max(dim.asc, maxAsc);
1224 maxDesc = max(dim.des, maxDesc);
1226 tabular.setWidthOfCell(actcell, the_locking_inset->width());
1227 tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT);
1228 tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT);
1234 for (int i = 0; i < tabular.rows(); ++i) {
1237 for (int j = 0; j < tabular.columns(); ++j) {
1238 if (tabular.isPartOfMultiColumn(i, j))
1244 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
1245 tabular.getCellInset(cell).metrics(m, dim);
1246 maxAsc = max(maxAsc, dim.asc);
1247 maxDesc = max(maxDesc, dim.des);
1248 tabular.setWidthOfCell(cell, dim.wid);
1250 tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
1251 tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
1256 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1258 if (the_locking_inset) {
1259 the_locking_inset->getCursor(bv, x, y);
1264 y = cursory_ + InsetTabular::y();
1267 int desc = tabular.getDescentOfRow(actrow);
1269 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1271 y += ADD_TO_HEIGHT * 2;
1272 y += TEXT_TO_INSET_OFFSET;
1276 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1278 if (the_locking_inset) {
1279 the_locking_inset->getCursorPos(bv, x, y);
1282 x = cursorx_ - top_x;
1287 void InsetTabular::fitInsetCursor(BufferView * bv) const
1289 if (the_locking_inset) {
1290 int old_top_y = bv->text->top_y();
1291 the_locking_inset->fitInsetCursor(bv);
1292 if (old_top_y != bv->text->top_y())
1298 int const asc = font_metrics::maxAscent(font);
1299 int const desc = font_metrics::maxDescent(font);
1302 if (bv->fitLockedInsetCursor(cursorx_, cursory_, asc, desc))
1307 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1310 actcell = actrow = actcol = 0;
1311 int ly = tabular.getDescentOfRow(actrow);
1313 // first search the right row
1314 while (ly < y && actrow + 1 < tabular.rows()) {
1315 cursory_ += tabular.getDescentOfRow(actrow) +
1316 tabular.getAscentOfRow(actrow + 1) +
1317 tabular.getAdditionalHeight(actrow + 1);
1319 ly = cursory_ + tabular.getDescentOfRow(actrow);
1321 actcell = tabular.getCellNumber(actrow, actcol);
1323 // now search the right column
1324 int lx = tabular.getWidthOfColumn(actcell) -
1325 tabular.getAdditionalWidth(actcell);
1326 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1327 lx += tabular.getWidthOfColumn(actcell + 1)
1328 + tabular.getAdditionalWidth(actcell);
1330 cursorx_ = lx - tabular.getWidthOfColumn(actcell) + top_x + 2;
1335 int InsetTabular::getCellXPos(int cell) const
1339 for (; !tabular.isFirstCellInRow(c); --c)
1341 int lx = tabular.getWidthOfColumn(cell);
1342 for (; c < cell; ++c)
1343 lx += tabular.getWidthOfColumn(c);
1345 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1349 void InsetTabular::resetPos(BufferView * bv) const
1351 #ifdef WITH_WARNINGS
1352 #warning This should be fixed in the right manner (20011128 Jug)
1354 // fast hack to fix infinite repaintings!
1355 if (in_reset_pos > 0)
1359 actcol = tabular.column_of_cell(actcell);
1362 for (; cell < actcell && !tabular.isLastRow(cell); ++cell) {
1363 if (tabular.isLastCellInRow(cell)) {
1364 cursory_ += tabular.getDescentOfRow(actrow) +
1365 tabular.getAscentOfRow(actrow + 1) +
1366 tabular.getAdditionalHeight(actrow + 1);
1371 if (the_locking_inset)
1375 // we need this only from here on!!!
1377 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1378 int new_x = getCellXPos(actcell);
1379 int old_x = cursorx_;
1382 // cursor.x(getCellXPos(actcell) + offset);
1383 if (actcol < tabular.columns() - 1 && scroll(false) &&
1384 tabular.getWidthOfTabular() < bv->workWidth()-20)
1387 updateLocal(bv, FULL);
1388 } else if (the_locking_inset &&
1389 tabular.getWidthOfColumn(actcell) > bv->workWidth() - 20)
1391 int xx = cursorx_ - offset + bv->text->getRealCursorX();
1392 if (xx > bv->workWidth()-20) {
1393 scroll(bv, -(xx - bv->workWidth() + 60));
1394 updateLocal(bv, FULL);
1395 } else if (xx < 20) {
1401 updateLocal(bv, FULL);
1403 } else if (cursorx_ - offset > 20 &&
1404 cursorx_ - offset + tabular.getWidthOfColumn(actcell)
1405 > bv->workWidth() - 20) {
1406 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1407 updateLocal(bv, FULL);
1408 } else if (cursorx_ - offset < 20) {
1409 scroll(bv, 20 - cursorx_ + offset);
1410 updateLocal(bv, FULL);
1411 } else if (scroll() && top_x > 20 &&
1412 (top_x + tabular.getWidthOfTabular()) > bv->workWidth() - 20) {
1413 scroll(bv, old_x - cursorx_);
1414 updateLocal(bv, FULL);
1416 if (the_locking_inset) {
1417 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
1420 if ((!the_locking_inset ||
1421 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1422 actcell != oldcell) {
1423 InsetTabularMailer(*this).updateDialog(bv);
1430 InsetOld::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1432 if (lock && !old_locking_inset) {
1433 if (activateCellInset(bv))
1436 bool moved = isRightToLeft(bv)
1437 ? movePrevCell(bv) : moveNextCell(bv);
1439 return FINISHED_RIGHT;
1440 if (lock && activateCellInset(bv))
1444 return DISPATCHED_NOUPDATE;
1448 InsetOld::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1450 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1453 if (lock) { // behind the inset
1454 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1458 return DISPATCHED_NOUPDATE;
1462 InsetOld::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1464 int const ocell = actcell;
1465 actcell = tabular.getCellAbove(actcell);
1466 if (actcell == ocell) // we moved out of the inset
1472 if (old_locking_inset) {
1473 old_locking_inset->getCursorPos(bv, x, y);
1474 x -= cursorx_ + tabular.getBeginningOfTextInCell(actcell);
1476 if (activateCellInset(bv, x, 0))
1479 return DISPATCHED_NOUPDATE;
1483 InsetOld::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1485 int const ocell = actcell;
1486 actcell = tabular.getCellBelow(actcell);
1487 if (actcell == ocell) // we moved out of the inset
1488 return FINISHED_DOWN;
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 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1506 if (isRightToLeft(bv)) {
1507 if (tabular.isFirstCellInRow(actcell)) {
1508 int row = tabular.row_of_cell(actcell);
1509 if (row == tabular.rows() - 1)
1511 actcell = tabular.getLastCellInRow(row);
1512 actcell = tabular.getCellBelow(actcell);
1519 if (tabular.isLastCell(actcell))
1524 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1525 isRightToLeftPar(bv->buffer()->params);
1526 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1533 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1535 if (isRightToLeft(bv)) {
1536 if (tabular.isLastCellInRow(actcell)) {
1537 int row = tabular.row_of_cell(actcell);
1540 actcell = tabular.getFirstCellInRow(row);
1541 actcell = tabular.getCellAbove(actcell);
1543 if (tabular.isLastCell(actcell))
1548 if (!actcell) // first cell
1553 bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
1554 isRightToLeftPar(bv->buffer()->params);
1555 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1562 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1566 setSelection(0, tabular.getNumberOfCells() - 1);
1568 if (hasSelection()) {
1569 recordUndo(bv, Undo::ATOMIC);
1570 bool const frozen = undo_frozen;
1573 // apply the fontchange on the whole selection
1578 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1579 for(int i = sel_row_start; i <= sel_row_end; ++i)
1580 for(int j = sel_col_start; j <= sel_col_end; ++j)
1581 tabular.getCellInset(i, j).setFont(bv, font, tall, true);
1587 updateLocal(bv, INIT);
1589 if (the_locking_inset)
1590 the_locking_inset->setFont(bv, font, tall);
1594 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1596 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1599 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1600 string const tmp = tabularFeature[i].feature;
1602 if (tmp == what.substr(0, tmp.length())) {
1603 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1604 //tabularFeatures[i].feature.length())) {
1605 action = tabularFeature[i].action;
1609 if (action == LyXTabular::LAST_ACTION)
1613 ltrim(what.substr(tabularFeature[i].feature.length()));
1614 tabularFeatures(bv, action, val);
1620 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1621 string const & special, bool & flag)
1623 if (special == "dl_above") {
1626 } else if (special == "dl_below") {
1627 ltt.bottomDL = flag;
1629 } else if (special == "empty") {
1641 void InsetTabular::tabularFeatures(BufferView * bv,
1642 LyXTabular::Feature feature,
1643 string const & value)
1649 bool setLines = false;
1650 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1651 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1655 case LyXTabular::M_ALIGN_LEFT:
1656 case LyXTabular::ALIGN_LEFT:
1657 setAlign = LYX_ALIGN_LEFT;
1660 case LyXTabular::M_ALIGN_RIGHT:
1661 case LyXTabular::ALIGN_RIGHT:
1662 setAlign = LYX_ALIGN_RIGHT;
1665 case LyXTabular::M_ALIGN_CENTER:
1666 case LyXTabular::ALIGN_CENTER:
1667 setAlign = LYX_ALIGN_CENTER;
1670 case LyXTabular::ALIGN_BLOCK:
1671 setAlign = LYX_ALIGN_BLOCK;
1674 case LyXTabular::M_VALIGN_TOP:
1675 case LyXTabular::VALIGN_TOP:
1676 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1679 case LyXTabular::M_VALIGN_BOTTOM:
1680 case LyXTabular::VALIGN_BOTTOM:
1681 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1684 case LyXTabular::M_VALIGN_CENTER:
1685 case LyXTabular::VALIGN_CENTER:
1686 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1693 if (hasSelection()) {
1694 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1696 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1697 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1699 recordUndo(bv, Undo::ATOMIC);
1701 int row = tabular.row_of_cell(actcell);
1702 int column = tabular.column_of_cell(actcell);
1704 LyXTabular::ltType ltt;
1708 case LyXTabular::SET_PWIDTH:
1710 LyXLength const vallen(value);
1711 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1713 bool const update = (tmplen != vallen);
1714 tabular.setColumnPWidth(actcell, vallen);
1716 // We need this otherwise we won't resize
1717 // the insettext of the active cell (if any)
1718 // until later (see InsetText::do_resize)
1719 unlockInsetInInset(bv, the_locking_inset);
1721 for (int i = 0; i < tabular.rows(); ++i)
1722 tabular.getCellInset(i, column).resizeLyXText(bv);
1723 updateLocal(bv, INIT);
1727 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1728 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1729 else if (!vallen.zero()
1730 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1731 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1735 case LyXTabular::SET_MPWIDTH:
1737 LyXLength const vallen(value);
1738 LyXLength const & tmplen = tabular.getPWidth(actcell);
1740 bool const update = (tmplen != vallen);
1741 tabular.setMColumnPWidth(actcell, vallen);
1743 // We need this otherwise we won't resize
1744 // the insettext of the active cell (if any)
1745 // until later (see InsetText::do_resize)
1746 unlockInsetInInset(bv, the_locking_inset);
1748 for (int i = 0; i < tabular.rows(); ++i)
1749 tabular.getCellInset(i, column).resizeLyXText(bv);
1751 updateLocal(bv, INIT);
1755 case LyXTabular::SET_SPECIAL_COLUMN:
1756 case LyXTabular::SET_SPECIAL_MULTI:
1757 tabular.setAlignSpecial(actcell,value,feature);
1758 updateLocal(bv, FULL);
1760 case LyXTabular::APPEND_ROW:
1761 // append the row into the tabular
1762 unlockInsetInInset(bv, the_locking_inset);
1763 tabular.appendRow(bv->buffer()->params, actcell);
1764 updateLocal(bv, INIT);
1766 case LyXTabular::APPEND_COLUMN:
1767 // append the column into the tabular
1768 unlockInsetInInset(bv, the_locking_inset);
1769 tabular.appendColumn(bv->buffer()->params, actcell);
1770 actcell = tabular.getCellNumber(row, column);
1771 updateLocal(bv, INIT);
1773 case LyXTabular::DELETE_ROW:
1774 unlockInsetInInset(bv, the_locking_inset);
1775 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1776 tabular.deleteRow(sel_row_start);
1778 if (sel_row_start >= tabular.rows())
1780 actcell = tabular.getCellNumber(sel_row_start, column);
1782 updateLocal(bv, INIT);
1784 case LyXTabular::DELETE_COLUMN:
1785 unlockInsetInInset(bv, the_locking_inset);
1786 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1787 tabular.deleteColumn(sel_col_start);
1789 if (sel_col_start >= tabular.columns())
1791 actcell = tabular.getCellNumber(row, sel_col_start);
1793 updateLocal(bv, INIT);
1795 case LyXTabular::M_TOGGLE_LINE_TOP:
1797 case LyXTabular::TOGGLE_LINE_TOP:
1799 bool lineSet = !tabular.topLine(actcell, flag);
1800 for (int i = sel_row_start; i <= sel_row_end; ++i)
1801 for (int j = sel_col_start; j <= sel_col_end; ++j)
1803 tabular.getCellNumber(i, j),
1805 updateLocal(bv, INIT);
1809 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1811 case LyXTabular::TOGGLE_LINE_BOTTOM:
1813 bool lineSet = !tabular.bottomLine(actcell, flag);
1814 for (int i = sel_row_start; i <= sel_row_end; ++i)
1815 for (int j = sel_col_start; j <= sel_col_end; ++j)
1816 tabular.setBottomLine(
1817 tabular.getCellNumber(i, j),
1820 updateLocal(bv, INIT);
1824 case LyXTabular::M_TOGGLE_LINE_LEFT:
1826 case LyXTabular::TOGGLE_LINE_LEFT:
1828 bool lineSet = !tabular.leftLine(actcell, flag);
1829 for (int i = sel_row_start; i <= sel_row_end; ++i)
1830 for (int j = sel_col_start; j <= sel_col_end; ++j)
1831 tabular.setLeftLine(
1832 tabular.getCellNumber(i,j),
1835 updateLocal(bv, INIT);
1839 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1841 case LyXTabular::TOGGLE_LINE_RIGHT:
1843 bool lineSet = !tabular.rightLine(actcell, flag);
1844 for (int i = sel_row_start; i <= sel_row_end; ++i)
1845 for (int j = sel_col_start; j <= sel_col_end; ++j)
1846 tabular.setRightLine(
1847 tabular.getCellNumber(i,j),
1850 updateLocal(bv, INIT);
1854 case LyXTabular::M_ALIGN_LEFT:
1855 case LyXTabular::M_ALIGN_RIGHT:
1856 case LyXTabular::M_ALIGN_CENTER:
1858 case LyXTabular::ALIGN_LEFT:
1859 case LyXTabular::ALIGN_RIGHT:
1860 case LyXTabular::ALIGN_CENTER:
1861 case LyXTabular::ALIGN_BLOCK:
1862 for (int i = sel_row_start; i <= sel_row_end; ++i)
1863 for (int j = sel_col_start; j <= sel_col_end; ++j)
1864 tabular.setAlignment(
1865 tabular.getCellNumber(i, j),
1868 updateLocal(bv, INIT);
1871 case LyXTabular::M_VALIGN_TOP:
1872 case LyXTabular::M_VALIGN_BOTTOM:
1873 case LyXTabular::M_VALIGN_CENTER:
1875 case LyXTabular::VALIGN_TOP:
1876 case LyXTabular::VALIGN_BOTTOM:
1877 case LyXTabular::VALIGN_CENTER:
1878 for (int i = sel_row_start; i <= sel_row_end; ++i)
1879 for (int j = sel_col_start; j <= sel_col_end; ++j)
1880 tabular.setVAlignment(
1881 tabular.getCellNumber(i, j),
1883 updateLocal(bv, INIT);
1886 case LyXTabular::MULTICOLUMN: {
1887 if (sel_row_start != sel_row_end) {
1888 #ifdef WITH_WARNINGS
1889 #warning Need I say it ? This is horrible.
1891 Alert::error(_("Error setting multicolumn"),
1892 _("You cannot set multicolumn vertically."));
1895 // just multicol for one Single Cell
1896 if (!hasSelection()) {
1897 // check wether we are completly in a multicol
1898 if (tabular.isMultiColumn(actcell)) {
1899 tabular.unsetMultiColumn(actcell);
1900 updateLocal(bv, INIT);
1902 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1903 updateLocal(bv, CELL);
1907 // we have a selection so this means we just add all this
1908 // cells to form a multicolumn cell
1912 if (sel_cell_start > sel_cell_end) {
1913 s_start = sel_cell_end;
1914 s_end = sel_cell_start;
1916 s_start = sel_cell_start;
1917 s_end = sel_cell_end;
1919 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1922 updateLocal(bv, INIT);
1926 case LyXTabular::SET_ALL_LINES:
1928 case LyXTabular::UNSET_ALL_LINES:
1929 for (int i = sel_row_start; i <= sel_row_end; ++i)
1930 for (int j = sel_col_start; j <= sel_col_end; ++j)
1931 tabular.setAllLines(
1932 tabular.getCellNumber(i,j), setLines);
1933 updateLocal(bv, INIT);
1936 case LyXTabular::SET_LONGTABULAR:
1937 tabular.setLongTabular(true);
1938 updateLocal(bv, INIT); // because this toggles displayed
1941 case LyXTabular::UNSET_LONGTABULAR:
1942 tabular.setLongTabular(false);
1943 updateLocal(bv, INIT); // because this toggles displayed
1946 case LyXTabular::SET_ROTATE_TABULAR:
1947 tabular.setRotateTabular(true);
1950 case LyXTabular::UNSET_ROTATE_TABULAR:
1951 tabular.setRotateTabular(false);
1954 case LyXTabular::SET_ROTATE_CELL:
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j<=sel_col_end; ++j)
1957 tabular.setRotateCell(
1958 tabular.getCellNumber(i, j),
1962 case LyXTabular::UNSET_ROTATE_CELL:
1963 for (int i = sel_row_start; i <= sel_row_end; ++i)
1964 for (int j = sel_col_start; j <= sel_col_end; ++j)
1965 tabular.setRotateCell(
1966 tabular.getCellNumber(i, j), false);
1969 case LyXTabular::SET_USEBOX: {
1970 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1971 if (val == tabular.getUsebox(actcell))
1972 val = LyXTabular::BOX_NONE;
1973 for (int i = sel_row_start; i <= sel_row_end; ++i)
1974 for (int j = sel_col_start; j <= sel_col_end; ++j)
1975 tabular.setUsebox(tabular.getCellNumber(i, j), val);
1979 case LyXTabular::UNSET_LTFIRSTHEAD:
1981 case LyXTabular::SET_LTFIRSTHEAD:
1982 tabular.getRowOfLTFirstHead(row, ltt);
1983 checkLongtableSpecial(ltt, value, flag);
1984 tabular.setLTHead(row, flag, ltt, true);
1987 case LyXTabular::UNSET_LTHEAD:
1989 case LyXTabular::SET_LTHEAD:
1990 tabular.getRowOfLTHead(row, ltt);
1991 checkLongtableSpecial(ltt, value, flag);
1992 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);
2003 case LyXTabular::UNSET_LTLASTFOOT:
2005 case LyXTabular::SET_LTLASTFOOT:
2006 tabular.getRowOfLTLastFoot(row, ltt);
2007 checkLongtableSpecial(ltt, value, flag);
2008 tabular.setLTFoot(row, flag, ltt, true);
2011 case LyXTabular::SET_LTNEWPAGE: {
2012 bool what = !tabular.getLTNewPage(row);
2013 tabular.setLTNewPage(row, what);
2017 // dummy stuff just to avoid warnings
2018 case LyXTabular::LAST_ACTION:
2022 InsetTabularMailer(*this).updateDialog(bv);
2026 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y,
2027 mouse_button::state button, bool behind)
2029 UpdatableInset & inset = tabular.getCellInset(actcell);
2032 x = inset.x() + inset.width();
2033 y = inset.descent();
2035 //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2036 //inset_y = cursory_;
2037 inset.localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2038 if (!the_locking_inset)
2040 updateLocal(bv, CELL);
2041 return (the_locking_inset != 0);
2045 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2046 mouse_button::state button)
2048 inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell);
2050 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2054 bool InsetTabular::insetHit(BufferView *, int x, int) const
2056 return x + top_x > cursorx_ + tabular.getBeginningOfTextInCell(actcell);
2060 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2062 resizeLyXText(bv, recursive);
2066 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2069 for (int i = 0; i < tabular.rows(); ++i)
2070 for (int j = 0; j < tabular.columns(); ++j)
2071 tabular.getCellInset(i, j).resizeLyXText(bv, true);
2076 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2077 bool const recursive) const
2079 if (the_locking_inset)
2080 return the_locking_inset->getLyXText(bv, recursive);
2081 return InsetOld::getLyXText(bv, recursive);
2085 bool InsetTabular::showInsetDialog(BufferView * bv) const
2087 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2088 InsetTabularMailer(*this).showDialog(bv);
2093 void InsetTabular::openLayoutDialog(BufferView * bv) const
2095 if (the_locking_inset) {
2096 InsetTabular * inset = static_cast<InsetTabular *>
2097 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2099 inset->openLayoutDialog(bv);
2103 InsetTabularMailer(*this).showDialog(bv);
2108 // function returns an object as defined in func_status.h:
2109 // states OK, Unknown, Disabled, On, Off.
2111 FuncStatus InsetTabular::getStatus(string const & what) const
2113 int action = LyXTabular::LAST_ACTION;
2117 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2118 string const tmp = tabularFeature[i].feature;
2119 if (tmp == what.substr(0, tmp.length())) {
2120 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2121 // tabularFeatures[i].feature.length())) {
2122 action = tabularFeature[i].action;
2126 if (action == LyXTabular::LAST_ACTION) {
2128 return status.unknown(true);
2131 string const argument
2132 = ltrim(what.substr(tabularFeature[i].feature.length()));
2137 LyXTabular::ltType dummyltt;
2141 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2143 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2146 case LyXTabular::SET_PWIDTH:
2147 case LyXTabular::SET_MPWIDTH:
2148 case LyXTabular::SET_SPECIAL_COLUMN:
2149 case LyXTabular::SET_SPECIAL_MULTI:
2150 case LyXTabular::APPEND_ROW:
2151 case LyXTabular::APPEND_COLUMN:
2152 case LyXTabular::DELETE_ROW:
2153 case LyXTabular::DELETE_COLUMN:
2154 case LyXTabular::SET_ALL_LINES:
2155 case LyXTabular::UNSET_ALL_LINES:
2156 return status.clear();
2158 case LyXTabular::MULTICOLUMN:
2159 status.setOnOff(tabular.isMultiColumn(actcell));
2162 case LyXTabular::M_TOGGLE_LINE_TOP:
2164 case LyXTabular::TOGGLE_LINE_TOP:
2165 status.setOnOff(tabular.topLine(actcell, flag));
2168 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2170 case LyXTabular::TOGGLE_LINE_BOTTOM:
2171 status.setOnOff(tabular.bottomLine(actcell, flag));
2174 case LyXTabular::M_TOGGLE_LINE_LEFT:
2176 case LyXTabular::TOGGLE_LINE_LEFT:
2177 status.setOnOff(tabular.leftLine(actcell, flag));
2180 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2182 case LyXTabular::TOGGLE_LINE_RIGHT:
2183 status.setOnOff(tabular.rightLine(actcell, flag));
2186 case LyXTabular::M_ALIGN_LEFT:
2188 case LyXTabular::ALIGN_LEFT:
2189 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2192 case LyXTabular::M_ALIGN_RIGHT:
2194 case LyXTabular::ALIGN_RIGHT:
2195 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2198 case LyXTabular::M_ALIGN_CENTER:
2200 case LyXTabular::ALIGN_CENTER:
2201 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2204 case LyXTabular::ALIGN_BLOCK:
2205 status.disabled(tabular.getPWidth(actcell).zero());
2206 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2209 case LyXTabular::M_VALIGN_TOP:
2211 case LyXTabular::VALIGN_TOP:
2212 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2215 case LyXTabular::M_VALIGN_BOTTOM:
2217 case LyXTabular::VALIGN_BOTTOM:
2218 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2221 case LyXTabular::M_VALIGN_CENTER:
2223 case LyXTabular::VALIGN_CENTER:
2224 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2227 case LyXTabular::SET_LONGTABULAR:
2228 status.setOnOff(tabular.isLongTabular());
2231 case LyXTabular::UNSET_LONGTABULAR:
2232 status.setOnOff(!tabular.isLongTabular());
2235 case LyXTabular::SET_ROTATE_TABULAR:
2236 status.setOnOff(tabular.getRotateTabular());
2239 case LyXTabular::UNSET_ROTATE_TABULAR:
2240 status.setOnOff(!tabular.getRotateTabular());
2243 case LyXTabular::SET_ROTATE_CELL:
2244 status.setOnOff(tabular.getRotateCell(actcell));
2247 case LyXTabular::UNSET_ROTATE_CELL:
2248 status.setOnOff(!tabular.getRotateCell(actcell));
2251 case LyXTabular::SET_USEBOX:
2252 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2255 case LyXTabular::SET_LTFIRSTHEAD:
2256 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2259 case LyXTabular::SET_LTHEAD:
2260 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2263 case LyXTabular::SET_LTFOOT:
2264 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2267 case LyXTabular::SET_LTLASTFOOT:
2268 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2271 case LyXTabular::SET_LTNEWPAGE:
2272 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2277 status.disabled(true);
2284 void InsetTabular::getLabelList(std::vector<string> & list) const
2286 tabular.getLabelList(list);
2290 bool InsetTabular::copySelection(BufferView * bv)
2292 if (!hasSelection())
2295 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2296 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2297 if (sel_col_start > sel_col_end) {
2298 sel_col_start = sel_col_end;
2299 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2301 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2304 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2305 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2306 if (sel_row_start > sel_row_end)
2307 swap(sel_row_start, sel_row_end);
2309 delete paste_tabular;
2310 paste_tabular = new LyXTabular(bv->buffer()->params, this, tabular);
2312 for (int i = 0; i < sel_row_start; ++i)
2313 paste_tabular->deleteRow(0);
2315 int const rows = sel_row_end - sel_row_start + 1;
2316 while (paste_tabular->rows() > rows)
2317 paste_tabular->deleteRow(rows);
2319 paste_tabular->setTopLine(0, true, true);
2320 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2323 for (int i = 0; i < sel_col_start; ++i)
2324 paste_tabular->deleteColumn(0);
2326 int const columns = sel_col_end - sel_col_start + 1;
2327 while (paste_tabular->columns() > columns)
2328 paste_tabular->deleteColumn(columns);
2330 paste_tabular->setLeftLine(0, true, true);
2331 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2335 paste_tabular->ascii(bv->buffer(), os,
2336 (int)parOwner()->params().depth(), true, '\t');
2337 bv->stuffClipboard(STRCONV(os.str()));
2342 bool InsetTabular::pasteSelection(BufferView * bv)
2347 for (int r1 = 0, r2 = actrow;
2348 r1 < paste_tabular->rows() && r2 < tabular.rows();
2350 for (int c1 = 0, c2 = actcol;
2351 c1 < paste_tabular->columns() && c2 < tabular.columns();
2353 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
2354 tabular.isPartOfMultiColumn(r2, c2))
2356 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
2360 if (tabular.isPartOfMultiColumn(r2, c2)) {
2364 InsetText & inset = tabular.getCellInset(r2, c2);
2365 inset = paste_tabular->getCellInset(r1, c1);
2366 inset.setOwner(this);
2367 inset.deleteLyXText(bv);
2375 bool InsetTabular::cutSelection(BufferParams const & bp)
2377 if (!hasSelection())
2380 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2381 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2382 if (sel_col_start > sel_col_end) {
2383 sel_col_start = sel_col_end;
2384 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2386 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2389 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2390 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2392 if (sel_row_start > sel_row_end)
2393 swap(sel_row_start, sel_row_end);
2395 if (sel_cell_start > sel_cell_end)
2396 swap(sel_cell_start, sel_cell_end);
2398 for (int i = sel_row_start; i <= sel_row_end; ++i)
2399 for (int j = sel_col_start; j <= sel_col_end; ++j)
2400 tabular.getCellInset(tabular.getCellNumber(i, j)).clear(bp.tracking_changes);
2405 bool InsetTabular::isRightToLeft(BufferView * bv)
2407 return bv->getParentLanguage(this)->RightToLeft();
2411 int InsetTabular::scroll(bool recursive) const
2413 int sx = UpdatableInset::scroll(false);
2415 if (recursive && the_locking_inset)
2416 sx += the_locking_inset->scroll(recursive);
2422 void InsetTabular::getSelection(int & srow, int & erow,
2423 int & scol, int & ecol) const
2425 int const start = hasSelection() ? sel_cell_start : actcell;
2426 int const end = hasSelection() ? sel_cell_end : actcell;
2428 srow = tabular.row_of_cell(start);
2429 erow = tabular.row_of_cell(end);
2433 scol = tabular.column_of_cell(start);
2434 ecol = tabular.column_of_cell(end);
2438 ecol = tabular.right_column_of_cell(end);
2442 ParagraphList * InsetTabular::getParagraphs(int i) const
2444 return (i < tabular.getNumberOfCells())
2445 ? tabular.getCellInset(i).getParagraphs(0)
2450 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2452 if (the_locking_inset)
2453 return the_locking_inset->cursor(bv);
2454 return InsetOld::cursor(bv);
2458 InsetOld * InsetTabular::getInsetFromID(int id_arg) const
2461 return const_cast<InsetTabular *>(this);
2463 for (int i = 0; i < tabular.rows(); ++i) {
2464 for (int j = 0; j < tabular.columns(); ++j) {
2465 InsetOld * inset = tabular.getCellInset(i, j).getInsetFromID(id_arg);
2475 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2477 if (the_locking_inset) {
2478 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2479 if (!word.word().empty())
2481 if (tabular.isLastCell(actcell)) {
2482 bv->unlockInset(const_cast<InsetTabular *>(this));
2483 return WordLangTuple();
2487 // otherwise we have to lock the next inset and ask for it's selecttion
2488 tabular.getCellInset(actcell)
2489 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2490 WordLangTuple word(selectNextWordInt(bv, value));
2491 if (!word.word().empty())
2497 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2499 // when entering this function the inset should be ALWAYS locked!
2500 Assert(the_locking_inset);
2502 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2503 if (!word.word().empty())
2506 if (tabular.isLastCell(actcell)) {
2507 bv->unlockInset(const_cast<InsetTabular *>(this));
2508 return WordLangTuple();
2511 // otherwise we have to lock the next inset and ask for it's selecttion
2513 tabular.getCellInset(actcell)
2514 .localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2515 return selectNextWordInt(bv, value);
2519 void InsetTabular::selectSelectedWord(BufferView * bv)
2521 if (the_locking_inset)
2522 the_locking_inset->selectSelectedWord(bv);
2526 void InsetTabular::markErased()
2528 for (int cell = 0; cell < tabular.getNumberOfCells(); ++cell)
2529 tabular.getCellInset(cell).markErased();
2533 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2535 if (the_locking_inset) {
2536 if (the_locking_inset->nextChange(bv, length)) {
2537 updateLocal(bv, CELL);
2540 if (tabular.isLastCell(actcell))
2544 InsetText & inset = tabular.getCellInset(actcell);
2545 if (inset.nextChange(bv, length)) {
2546 updateLocal(bv, FULL);
2549 while (!tabular.isLastCell(actcell)) {
2551 InsetText & inset = tabular.getCellInset(actcell);
2552 if (inset.nextChange(bv, length)) {
2553 updateLocal(bv, FULL);
2561 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2565 if (the_locking_inset) {
2566 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2567 updateLocal(bv, CELL);
2570 if (tabular.isLastCell(actcell))
2574 InsetText & inset = tabular.getCellInset(cell);
2575 if (inset.searchForward(bv, str, cs, mw)) {
2576 updateLocal(bv, FULL);
2579 while (!tabular.isLastCell(cell)) {
2581 InsetText & inset = tabular.getCellInset(cell);
2582 if (inset.searchForward(bv, str, cs, mw)) {
2583 updateLocal(bv, FULL);
2591 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2594 int cell = tabular.getNumberOfCells();
2595 if (the_locking_inset) {
2596 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2597 updateLocal(bv, CELL);
2605 InsetText & inset = tabular.getCellInset(cell);
2606 if (inset.searchBackward(bv, str, cs, mw)) {
2607 updateLocal(bv, CELL);
2615 bool InsetTabular::insetAllowed(InsetOld::Code code) const
2617 if (the_locking_inset)
2618 return the_locking_inset->insetAllowed(code);
2619 // we return true here because if the inset is not locked someone
2620 // wants to insert something in one of our insettexts and we generally
2626 bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
2628 const int cell = tabular.getCellFromInset(in, actcell);
2631 return tabular.getPWidth(cell).zero();
2633 // well we didn't obviously find it so maybe our owner knows more
2635 return owner()->forceDefaultParagraphs(in);
2637 lyxerr << "If we're here there is really something strange going on!"
2643 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2646 if (buf.length() <= 0)
2652 string::size_type len = buf.length();
2653 string::size_type p = 0;
2655 while (p < len && (p = buf.find_first_of("\t\n", p)) != string::npos) {
2663 maxCols = max(cols, maxCols);
2669 maxCols = max(cols, maxCols);
2670 LyXTabular * loctab;
2675 delete paste_tabular;
2676 paste_tabular = new LyXTabular(bv->buffer()->params,
2677 this, rows, maxCols);
2678 loctab = paste_tabular;
2687 string::size_type op = 0;
2688 int cells = loctab->getNumberOfCells();
2691 rows = loctab->rows();
2692 int const columns = loctab->columns();
2694 while (cell < cells && p < len && row < rows &&
2695 (p = buf.find_first_of("\t\n", p)) != string::npos)
2701 // we can only set this if we are not too far right
2702 if (cols < columns) {
2703 InsetText & inset = loctab->getCellInset(cell);
2704 LyXFont const font = inset.getLyXText(bv)->
2705 getFont(inset.paragraphs.begin(), 0);
2706 inset.setText(buf.substr(op, p - op), font);
2712 // we can only set this if we are not too far right
2713 if (cols < columns) {
2714 InsetText & inset = tabular.getCellInset(cell);
2715 LyXFont const font = inset.getLyXText(bv)->
2716 getFont(inset.paragraphs.begin(), 0);
2717 inset.setText(buf.substr(op, p - op), font);
2722 cell = loctab->getCellNumber(row, cols);
2728 // check for the last cell if there is no trailing '\n'
2729 if (cell < cells && op < len) {
2730 InsetText & inset = loctab->getCellInset(cell);
2731 LyXFont const font = inset.getLyXText(bv)->
2732 getFont(inset.paragraphs.begin(), 0);
2733 inset.setText(buf.substr(op, len - op), font);
2740 void InsetTabular::addPreview(PreviewLoader & loader) const
2742 int const rows = tabular.rows();
2743 int const columns = tabular.columns();
2744 for (int i = 0; i < rows; ++i)
2745 for (int j = 0; j < columns; ++j)
2746 tabular.getCellInset(i, j).addPreview(loader);
2750 string const InsetTabularMailer::name_("tabular");
2752 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
2753 : inset_(const_cast<InsetTabular &>(inset))
2757 string const InsetTabularMailer::inset2string(Buffer const &) const
2759 return params2string(inset_);
2763 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2765 istringstream data(STRCONV(in));
2767 lex.setStream(data);
2769 #warning CHECK verify that this is a sane value to return.
2775 string const token = lex.getString();
2783 string const token = lex.getString();
2784 if (token != "\\active_cell")
2787 cell = lex.getInteger();
2790 // This is part of the inset proper that is usually swallowed
2791 // by Buffer::readInset
2794 string const token = lex.getString();
2795 if (token != "Tabular")
2802 Buffer const * const buffer = inset.buffer();
2804 inset.read(buffer, lex);
2806 // We can't set the active cell, but we can tell the frontend
2812 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2814 Buffer const * const buffer = inset.buffer();
2819 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2820 inset.write(buffer, data);
2821 data << "\\end_inset\n";
2822 return STRCONV(data.str());