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"
52 using namespace lyx::support;
62 namespace grfx = 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)),
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
177 InsetTabular::InsetTabular(InsetTabular const & tab)
178 : UpdatableInset(tab),
179 tabular(tab.buffer_->params, this, tab.tabular),
182 the_locking_inset = 0;
183 old_locking_inset = 0;
186 actrow = actcell = 0;
196 InsetTabular::~InsetTabular()
198 InsetTabularMailer mailer(*this);
203 InsetBase * InsetTabular::clone() const
205 return new InsetTabular(*this);
209 Buffer const * InsetTabular::buffer() const
215 BufferView * InsetTabular::view() const
222 void InsetTabular::buffer(Buffer * b)
228 void InsetTabular::write(Buffer const * buf, ostream & os) const
230 os << " Tabular" << endl;
231 tabular.write(buf, os);
235 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
237 bool const old_format = (lex.getString() == "\\LyXTable");
239 tabular.read(buf, lex);
247 string token = lex.getString();
248 while (lex.isOK() && (token != "\\end_inset")) {
250 token = lex.getString();
252 if (token != "\\end_inset") {
253 lex.printError("Missing \\end_inset at this point. "
259 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
262 //lyxerr << "InsetTabular::metrics, bv: " << mi.base.bv << endl;
263 for (int i = 0; i < tabular.getNumberOfCells(); ++i) {
264 tabular.cellinfo_of_cell(i)->inset.text_.bv_owner = mi.base.bv;
265 tabular.cellinfo_of_cell(i)->inset.reinitLyXText();
269 dim.asc = tabular.getAscentOfRow(0);
270 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
271 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
275 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
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 void InsetTabular::update(BufferView * bv, bool reinit)
418 owner()->update(bv, true);
425 if (calculate_dimensions_of_cells(bv, true))
428 owner()->update(bv, true);
432 if (the_locking_inset)
433 the_locking_inset->update(bv, reinit);
434 if (need_update < FULL &&
435 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
440 switch (need_update) {
444 if (calculate_dimensions_of_cells(bv, false)) {
459 string const InsetTabular::editMessage() const
461 return _("Opened table");
465 void InsetTabular::insetUnlock(BufferView * bv)
467 if (the_locking_inset) {
468 the_locking_inset->insetUnlock(bv);
469 updateLocal(bv, CELL);
470 the_locking_inset = 0;
475 if (scroll(false) || hasSelection()) {
480 updateLocal(bv, FULL);
485 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
488 calculate_dimensions_of_cells(bv, true);
490 if (!locked && what == CELL)
492 if (need_update < what) // only set this if it has greater update
495 if (need_update != NONE) {
496 bv->updateInset(const_cast<InsetTabular *>(this));
503 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
505 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
510 if (inset == tabular.getCellInset(actcell)) {
511 lyxerr[Debug::INSETTEXT] << "OK" << endl;
512 the_locking_inset = tabular.getCellInset(actcell);
515 } else if (!the_locking_inset) {
516 int const n = tabular.getNumberOfCells();
517 int const id = inset->id();
518 for (int i = 0; i < n; ++i) {
519 InsetText * in = tabular.getCellInset(i);
522 the_locking_inset = in;
527 if (in->getInsetFromID(id)) {
529 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
530 return the_locking_inset->lockInsetInInset(bv, inset);
533 } else if (the_locking_inset && (the_locking_inset == inset)) {
534 lyxerr[Debug::INSETTEXT] << "OK" << endl;
536 } else if (the_locking_inset) {
537 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
538 return the_locking_inset->lockInsetInInset(bv, inset);
540 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
545 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
548 if (!the_locking_inset)
550 if (the_locking_inset == inset) {
551 the_locking_inset->insetUnlock(bv);
553 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
559 updateLocal(bv, CELL);
560 // this has to be here otherwise we don't redraw the cell!
561 the_locking_inset = 0;
564 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
565 if (inset->lyxCode() == TABULAR_CODE &&
566 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
567 InsetTabularMailer mailer(*this);
568 mailer.updateDialog(bv);
577 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
579 Inset * tl_inset = inset;
580 // look if this inset is really inside myself!
581 while(tl_inset->owner() && tl_inset->owner() != this)
582 tl_inset = tl_inset->owner();
583 // if we enter here it's not ower inset
584 if (!tl_inset->owner())
586 // we only have to do this if this is a subinset of our cells
587 if (tl_inset != inset) {
588 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
591 updateLocal(bv, CELL);
596 int InsetTabular::insetInInsetY() const
598 if (!the_locking_inset)
600 return inset_y + the_locking_inset->insetInInsetY();
604 UpdatableInset * InsetTabular::getLockingInset() const
606 return the_locking_inset ? the_locking_inset->getLockingInset() :
607 const_cast<InsetTabular *>(this);
611 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
615 if (the_locking_inset)
616 return the_locking_inset->getFirstLockingInsetOfType(c);
621 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
623 if (the_locking_inset)
624 return the_locking_inset->insertInset(bv, inset);
629 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
631 if (hasSelection() && cmd.button() == mouse_button::button3)
634 if (hasSelection()) {
636 updateLocal(cmd.view(), SELECTION);
639 int const ocell = actcell;
640 int const orow = actrow;
641 BufferView * bv = cmd.view();
645 the_locking_inset = 0;
649 setPos(bv, cmd.x, cmd.y);
651 updateLocal(bv, NONE);
654 if (cmd.button() == mouse_button::button3) {
655 if ((ocell != actcell) && the_locking_inset) {
656 the_locking_inset->insetUnlock(bv);
657 updateLocal(bv, CELL);
658 the_locking_inset = 0;
664 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
666 if ((ocell == actcell) && the_locking_inset && inset_hit) {
668 FuncRequest cmd1 = cmd;
671 the_locking_inset->localDispatch(cmd1);
675 if (the_locking_inset) {
676 the_locking_inset->insetUnlock(bv);
677 updateLocal(bv, CELL);
678 the_locking_inset = 0;
681 if (cmd.button() == mouse_button::button2) {
682 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
686 if (inset_hit && bv->theLockingInset()) {
687 if (!bv->lockInset(static_cast<UpdatableInset*>
688 (tabular.getCellInset(actcell))))
690 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
693 FuncRequest cmd1 = cmd;
696 the_locking_inset->localDispatch(cmd1);
702 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
705 if (the_locking_inset) {
706 FuncRequest cmd1 = cmd;
709 ret = the_locking_inset->localDispatch(cmd1);
711 if (cmd.button() == mouse_button::button3 && !ret) {
712 InsetTabularMailer(*this).showDialog(cmd.view());
719 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
721 if (the_locking_inset) {
722 FuncRequest cmd1 = cmd;
725 the_locking_inset->localDispatch(cmd1);
729 BufferView * bv = cmd.view();
730 int const old_cell = actcell;
732 setPos(bv, cmd.x, cmd.y);
733 if (!hasSelection()) {
734 setSelection(actcell, actcell);
735 updateLocal(bv, SELECTION);
736 } else if (old_cell != actcell) {
737 setSelection(sel_cell_start, actcell);
738 updateLocal(bv, SELECTION);
743 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
745 // We need to save the value of the_locking_inset as the call to
746 // the_locking_inset->localDispatch might unlock it.
747 old_locking_inset = the_locking_inset;
748 RESULT result = UpdatableInset::localDispatch(cmd);
749 BufferView * bv = cmd.view();
751 if (cmd.action == LFUN_INSET_EDIT) {
753 if (!bv->lockInset(this)) {
754 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
760 the_locking_inset = 0;
764 if (cmd.argument.size()) {
765 if (cmd.argument == "left") {
766 if (isRightToLeft(bv))
767 actcell = tabular.getLastCellInRow(0);
771 if (isRightToLeft(bv))
772 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
774 actcell = tabular.getNumberOfCells() - 1;
782 setPos(bv, cmd.x, cmd.y);
785 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
786 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
792 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
797 if (cmd.action < 0 && cmd.argument.empty())
800 bool hs = hasSelection();
803 // this one have priority over the locked InsetText, if we're not already
804 // inside another tabular then that one get's priority!
805 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
806 switch (cmd.action) {
807 case LFUN_MOUSE_PRESS:
811 case LFUN_MOUSE_MOTION:
812 lfunMouseMotion(cmd);
815 case LFUN_MOUSE_RELEASE:
816 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
818 case LFUN_CELL_BACKWARD:
819 case LFUN_CELL_FORWARD:
820 unlockInsetInInset(bv, the_locking_inset);
821 if (cmd.action == LFUN_CELL_FORWARD)
822 moveNextCell(bv, old_locking_inset != 0);
824 movePrevCell(bv, old_locking_inset != 0);
827 updateLocal(bv, SELECTION);
828 if (!the_locking_inset) {
829 return DISPATCHED_NOUPDATE;
832 // this to avoid compiler warnings.
838 kb_action action = cmd.action;
839 string arg = cmd.argument;
840 if (the_locking_inset) {
841 result = the_locking_inset->localDispatch(cmd);
842 if (result == DISPATCHED_NOUPDATE) {
845 if (sc != scroll()) { // inset has been scrolled
846 updateLocal(bv, FULL);
849 } else if (result == DISPATCHED) {
850 updateLocal(bv, CELL);
852 } else if (result == FINISHED_UP) {
854 // Make sure to reset status message after
855 // exiting, e.g. math inset
856 bv->owner()->clearMessage();
857 } else if (result == FINISHED_DOWN) {
859 bv->owner()->clearMessage();
860 } else if (result == FINISHED_RIGHT) {
862 bv->owner()->clearMessage();
863 } else if (result == FINISHED) {
864 bv->owner()->clearMessage();
870 // --- Cursor Movements ----------------------------------
871 case LFUN_RIGHTSEL: {
872 int const start = hasSelection() ? sel_cell_start : actcell;
873 if (tabular.isLastCellInRow(actcell)) {
874 setSelection(start, actcell);
879 // if we are starting a selection, only select
880 // the current cell at the beginning
881 if (hasSelection()) {
882 moveRight(bv, false);
885 setSelection(start, end);
886 updateLocal(bv, SELECTION);
890 result = moveRight(bv);
893 updateLocal(bv, SELECTION);
896 int const start = hasSelection() ? sel_cell_start : actcell;
897 if (tabular.isFirstCellInRow(actcell)) {
898 setSelection(start, actcell);
903 // if we are starting a selection, only select
904 // the current cell at the beginning
905 if (hasSelection()) {
909 setSelection(start, end);
910 updateLocal(bv, SELECTION);
914 result = moveLeft(bv);
917 updateLocal(bv, SELECTION);
920 int const start = hasSelection() ? sel_cell_start : actcell;
921 int const ocell = actcell;
922 // if we are starting a selection, only select
923 // the current cell at the beginning
924 if (hasSelection()) {
926 if ((ocell == sel_cell_end) ||
927 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
928 setSelection(start, tabular.getCellBelow(sel_cell_end));
930 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
932 setSelection(start, start);
934 updateLocal(bv, SELECTION);
938 result = moveDown(bv, old_locking_inset != 0);
941 updateLocal(bv, SELECTION);
945 int const start = hasSelection() ? sel_cell_start : actcell;
946 int const ocell = actcell;
947 // if we are starting a selection, only select
948 // the current cell at the beginning
949 if (hasSelection()) {
951 if ((ocell == sel_cell_end) ||
952 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
953 setSelection(start, tabular.getCellAbove(sel_cell_end));
955 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
957 setSelection(start, start);
959 updateLocal(bv, SELECTION);
963 result = moveUp(bv, old_locking_inset != 0);
966 updateLocal(bv, SELECTION);
969 UpdateCodes code = CURSOR;
975 unlockInsetInInset(bv, the_locking_inset);
976 if (bv->text->top_y() + bv->painter().paperHeight() <
977 (top_baseline + tabular.getHeightOfTabular()))
979 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
981 actcell = tabular.getCellBelow(first_visible_cell) + column;
983 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
986 updateLocal(bv, code);
990 UpdateCodes code = CURSOR;
996 unlockInsetInInset(bv, the_locking_inset);
997 if (top_baseline < 0) {
998 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
1000 if (top_baseline > 0)
1003 actcell = tabular.getCellBelow(first_visible_cell) + column;
1008 updateLocal(bv, code);
1011 // none of these make sense for insettabular,
1012 // but we must catch them to prevent any
1013 // selection from being confused
1017 case LFUN_WORDLEFTSEL:
1018 case LFUN_WORDRIGHT:
1019 case LFUN_WORDRIGHTSEL:
1021 case LFUN_DOWN_PARAGRAPH:
1022 case LFUN_DOWN_PARAGRAPHSEL:
1023 case LFUN_UP_PARAGRAPH:
1024 case LFUN_UP_PARAGRAPHSEL:
1025 case LFUN_BACKSPACE:
1030 case LFUN_BEGINNINGBUF:
1031 case LFUN_BEGINNINGBUFSEL:
1033 case LFUN_ENDBUFSEL:
1035 case LFUN_LAYOUT_TABULAR: {
1036 InsetTabularMailer mailer(*this);
1037 mailer.showDialog(bv);
1040 case LFUN_INSET_DIALOG_UPDATE: {
1041 InsetTabularMailer mailer(*this);
1042 mailer.updateDialog(bv);
1045 case LFUN_TABULAR_FEATURE:
1046 if (!tabularFeatures(bv, arg))
1047 result = UNDISPATCHED;
1049 // insert file functions
1050 case LFUN_FILE_INSERT_ASCII_PARA:
1051 case LFUN_FILE_INSERT_ASCII:
1053 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1056 if (insertAsciiString(bv, tmpstr, false))
1057 updateLocal(bv, INIT);
1059 result = UNDISPATCHED;
1062 // cut and paste functions
1064 if (!copySelection(bv))
1068 setUndo(bv, Undo::DELETE);
1069 cutSelection(bv->buffer()->params);
1070 updateLocal(bv, INIT);
1073 if (!hasSelection())
1078 case LFUN_PASTESELECTION:
1080 string const clip(bv->getClipboard());
1084 if (clip.find('\t') != string::npos) {
1088 string::size_type len = clip.length();
1089 string::size_type p = 0;
1092 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1100 maxCols = max(cols, maxCols);
1106 maxCols = max(cols, maxCols);
1107 delete paste_tabular;
1108 paste_tabular = new LyXTabular(bv->buffer()->params,
1109 this, rows, maxCols);
1110 string::size_type op = 0;
1112 int cells = paste_tabular->getNumberOfCells();
1114 while ((cell < cells) && (p < len) &&
1115 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1120 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1125 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1126 while (cols++ < maxCols)
1134 // check for the last cell if there is no trailing '\n'
1135 if ((cell < cells) && (op < len))
1136 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1139 if (!insertAsciiString(bv, clip, true))
1142 // so that the clipboard is used and it goes on
1144 // and executes LFUN_PASTESELECTION in insettext!
1145 delete paste_tabular;
1150 if (hasPasteBuffer()) {
1151 setUndo(bv, Undo::INSERT);
1153 updateLocal(bv, INIT);
1156 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1158 // handle font changing stuff on selection before we lock the inset
1159 // in the default part!
1160 result = UNDISPATCHED;
1171 case LFUN_UNDERLINE:
1172 case LFUN_FONT_SIZE:
1173 if (bv->dispatch(FuncRequest(bv, action, arg)))
1174 result = DISPATCHED;
1180 // we try to activate the actual inset and put this event down to
1181 // the insets dispatch function.
1182 if ((result == DISPATCHED) || the_locking_inset)
1185 if (activateCellInset(bv)) {
1186 // reset need_update setted in above function!
1188 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1189 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1190 unlockInsetInInset(bv, the_locking_inset);
1192 // we need to update if this was requested before
1193 updateLocal(bv, NONE);
1194 return UNDISPATCHED;
1197 // so the below CELL is not set because this is higher
1198 // priority and we get a full redraw
1199 need_update = SELECTION;
1202 updateLocal(bv, CELL);
1207 if (result < FINISHED) {
1208 if (!the_locking_inset) {
1209 if (bv->fitCursor())
1210 updateLocal(bv, FULL);
1213 bv->unlockInset(this);
1218 int InsetTabular::latex(Buffer const * buf, ostream & os,
1219 LatexRunParams const & runparams) const
1221 return tabular.latex(buf, os, runparams);
1225 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1228 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1230 return tabular.ascii(buf, os, 0, false,0);
1234 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1237 int const ret = tabular.ascii(buf,os,
1238 (int)parOwner()->params().depth(),
1245 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1250 // if the table is inside a float it doesn't need the informaltable
1251 // wrapper. Search for it.
1252 for(master = owner();
1253 master && master->lyxCode() != Inset::FLOAT_CODE;
1254 master = master->owner());
1257 os << "<informaltable>";
1262 ret+= tabular.docbook(buf, os, mixcont);
1264 os << "</informaltable>";
1273 void InsetTabular::validate(LaTeXFeatures & features) const
1275 tabular.validate(features);
1279 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1285 bool changed = false;
1287 // FIXME: since InsetText ignores this anyway, it doesn't
1288 // matter what we pass it. Ugly
1291 // if we have a locking_inset we should have to check only this cell for
1292 // change so I'll try this to have a boost, but who knows ;)
1293 if ((need_update != INIT) &&
1294 (the_locking_inset == tabular.getCellInset(actcell))) {
1295 for(int i = 0; i < tabular.columns(); ++i) {
1296 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1298 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1301 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1302 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1303 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1306 for (int i = 0; i < tabular.rows(); ++i) {
1309 for (int j = 0; j < tabular.columns(); ++j) {
1310 if (tabular.isPartOfMultiColumn(i,j))
1313 inset = tabular.getCellInset(cell);
1314 if (!reinit && !tabular.getPWidth(cell).zero())
1315 inset->update(bv, false);
1316 maxAsc = max(maxAsc, inset->ascent(bv, font));
1317 maxDesc = max(maxDesc, inset->descent(bv, font));
1318 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1320 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1321 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1329 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1331 if (the_locking_inset) {
1332 the_locking_inset->getCursor(bv, x, y);
1337 y = cursor_.y() + InsetTabular::y();
1340 int desc = tabular.getDescentOfRow(actrow);
1342 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1344 y += ADD_TO_HEIGHT * 2;
1345 y += TEXT_TO_INSET_OFFSET;
1349 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1351 if (the_locking_inset) {
1352 the_locking_inset->getCursorPos(bv, x, y);
1355 x = cursor_.x() - top_x;
1360 void InsetTabular::fitInsetCursor(BufferView * bv) const
1362 if (the_locking_inset) {
1363 int old_top_y = bv->text->top_y();
1364 the_locking_inset->fitInsetCursor(bv);
1365 if (old_top_y != bv->text->top_y())
1371 int const asc = font_metrics::maxAscent(font);
1372 int const desc = font_metrics::maxDescent(font);
1375 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1380 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1384 actcell = actrow = actcol = 0;
1385 int ly = tabular.getDescentOfRow(actrow);
1387 // first search the right row
1388 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1389 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1390 tabular.getAscentOfRow(actrow + 1) +
1391 tabular.getAdditionalHeight(actrow + 1));
1393 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1395 actcell = tabular.getCellNumber(actrow, actcol);
1397 // now search the right column
1398 int lx = tabular.getWidthOfColumn(actcell) -
1399 tabular.getAdditionalWidth(actcell);
1400 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1401 lx += tabular.getWidthOfColumn(actcell + 1)
1402 + tabular.getAdditionalWidth(actcell);
1404 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1409 int InsetTabular::getCellXPos(int cell) const
1413 for (; !tabular.isFirstCellInRow(c); --c)
1415 int lx = tabular.getWidthOfColumn(cell);
1416 for (; c < cell; ++c) {
1417 lx += tabular.getWidthOfColumn(c);
1419 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1423 void InsetTabular::resetPos(BufferView * bv) const
1425 #ifdef WITH_WARNINGS
1426 #warning This should be fixed in the right manner (20011128 Jug)
1428 // fast hack to fix infinite repaintings!
1429 if (in_reset_pos > 0)
1433 actcol = tabular.column_of_cell(actcell);
1436 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1437 if (tabular.isLastCellInRow(cell)) {
1438 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1439 tabular.getAscentOfRow(actrow + 1) +
1440 tabular.getAdditionalHeight(actrow + 1));
1444 if (!locked || nodraw()) {
1445 if (the_locking_inset)
1446 inset_y = cursor_.y();
1449 // we need this only from here on!!!
1451 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1452 int new_x = getCellXPos(actcell);
1453 int old_x = cursor_.x();
1456 // cursor.x(getCellXPos(actcell) + offset);
1457 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1458 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1461 updateLocal(bv, FULL);
1462 } else if (the_locking_inset &&
1463 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1465 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1466 if (xx > (bv->workWidth()-20)) {
1467 scroll(bv, -(xx - bv->workWidth() + 60));
1468 updateLocal(bv, FULL);
1469 } else if (xx < 20) {
1475 updateLocal(bv, FULL);
1477 } else if ((cursor_.x() - offset) > 20 &&
1478 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1479 > (bv->workWidth() - 20)) {
1480 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1481 updateLocal(bv, FULL);
1482 } else if ((cursor_.x() - offset) < 20) {
1483 scroll(bv, 20 - cursor_.x() + offset);
1484 updateLocal(bv, FULL);
1485 } else if (scroll() && top_x > 20 &&
1486 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1487 scroll(bv, old_x - cursor_.x());
1488 updateLocal(bv, FULL);
1490 if (the_locking_inset) {
1491 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1492 inset_y = cursor_.y();
1494 if ((!the_locking_inset ||
1495 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1496 actcell != oldcell) {
1497 InsetTabular * inset = const_cast<InsetTabular *>(this);
1498 InsetTabularMailer mailer(*inset);
1499 mailer.updateDialog(bv);
1506 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1508 if (lock && !old_locking_inset) {
1509 if (activateCellInset(bv))
1512 bool moved = isRightToLeft(bv)
1513 ? movePrevCell(bv) : moveNextCell(bv);
1515 return FINISHED_RIGHT;
1516 if (lock && activateCellInset(bv))
1520 return DISPATCHED_NOUPDATE;
1524 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1526 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1529 if (lock) { // behind the inset
1530 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1534 return DISPATCHED_NOUPDATE;
1538 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1540 int const ocell = actcell;
1541 actcell = tabular.getCellAbove(actcell);
1542 if (actcell == ocell) // we moved out of the inset
1548 if (old_locking_inset) {
1549 old_locking_inset->getCursorPos(bv, x, y);
1550 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1552 if (activateCellInset(bv, x, 0))
1555 return DISPATCHED_NOUPDATE;
1559 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1561 int const ocell = actcell;
1562 actcell = tabular.getCellBelow(actcell);
1563 if (actcell == ocell) // we moved out of the inset
1564 return FINISHED_DOWN;
1569 if (old_locking_inset) {
1570 old_locking_inset->getCursorPos(bv, x, y);
1571 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1573 if (activateCellInset(bv, x, 0))
1576 return DISPATCHED_NOUPDATE;
1580 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1582 if (isRightToLeft(bv)) {
1583 if (tabular.isFirstCellInRow(actcell)) {
1584 int row = tabular.row_of_cell(actcell);
1585 if (row == tabular.rows() - 1)
1587 actcell = tabular.getLastCellInRow(row);
1588 actcell = tabular.getCellBelow(actcell);
1595 if (tabular.isLastCell(actcell))
1600 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1601 isRightToLeftPar(bv->buffer()->params);
1602 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1609 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1611 if (isRightToLeft(bv)) {
1612 if (tabular.isLastCellInRow(actcell)) {
1613 int row = tabular.row_of_cell(actcell);
1616 actcell = tabular.getFirstCellInRow(row);
1617 actcell = tabular.getCellAbove(actcell);
1619 if (tabular.isLastCell(actcell))
1624 if (!actcell) // first cell
1629 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1630 isRightToLeftPar(bv->buffer()->params);
1631 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1638 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1642 setSelection(0, tabular.getNumberOfCells() - 1);
1644 if (hasSelection()) {
1645 setUndo(bv, Undo::EDIT);
1646 bool const frozen = undo_frozen;
1649 // apply the fontchange on the whole selection
1654 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1655 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1656 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1657 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1664 updateLocal(bv, INIT);
1666 if (the_locking_inset)
1667 the_locking_inset->setFont(bv, font, tall);
1671 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1673 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1676 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1677 string const tmp = tabularFeature[i].feature;
1679 if (tmp == what.substr(0, tmp.length())) {
1680 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1681 //tabularFeatures[i].feature.length())) {
1682 action = tabularFeature[i].action;
1686 if (action == LyXTabular::LAST_ACTION)
1690 ltrim(what.substr(tabularFeature[i].feature.length()));
1691 tabularFeatures(bv, action, val);
1697 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1698 string const & special, bool & flag)
1700 if (special == "dl_above") {
1703 } else if (special == "dl_below") {
1704 ltt.bottomDL = flag;
1706 } else if (special == "empty") {
1718 void InsetTabular::tabularFeatures(BufferView * bv,
1719 LyXTabular::Feature feature,
1720 string const & value)
1726 bool setLines = false;
1727 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1728 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1731 case LyXTabular::M_ALIGN_LEFT:
1732 case LyXTabular::ALIGN_LEFT:
1733 setAlign = LYX_ALIGN_LEFT;
1735 case LyXTabular::M_ALIGN_RIGHT:
1736 case LyXTabular::ALIGN_RIGHT:
1737 setAlign = LYX_ALIGN_RIGHT;
1739 case LyXTabular::M_ALIGN_CENTER:
1740 case LyXTabular::ALIGN_CENTER:
1741 setAlign = LYX_ALIGN_CENTER;
1743 case LyXTabular::ALIGN_BLOCK:
1744 setAlign = LYX_ALIGN_BLOCK;
1746 case LyXTabular::M_VALIGN_TOP:
1747 case LyXTabular::VALIGN_TOP:
1748 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1750 case LyXTabular::M_VALIGN_BOTTOM:
1751 case LyXTabular::VALIGN_BOTTOM:
1752 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1754 case LyXTabular::M_VALIGN_CENTER:
1755 case LyXTabular::VALIGN_CENTER:
1756 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1761 if (hasSelection()) {
1762 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1764 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1765 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1767 setUndo(bv, Undo::FINISH);
1769 int row = tabular.row_of_cell(actcell);
1770 int column = tabular.column_of_cell(actcell);
1772 LyXTabular::ltType ltt;
1775 case LyXTabular::SET_PWIDTH:
1777 LyXLength const vallen(value);
1778 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1780 bool const update = (tmplen != vallen);
1781 tabular.setColumnPWidth(actcell, vallen);
1783 // We need this otherwise we won't resize
1784 // the insettext of the active cell (if any)
1785 // until later (see InsetText::do_resize)
1786 unlockInsetInInset(bv, the_locking_inset);
1789 for (int i = 0; i < tabular.rows(); ++i) {
1790 cell = tabular.getCellNumber(i,column);
1791 tabular.getCellInset(cell)->resizeLyXText(bv);
1793 updateLocal(bv, INIT);
1797 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1798 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1799 else if (!vallen.zero()
1800 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1801 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1804 case LyXTabular::SET_MPWIDTH:
1806 LyXLength const vallen(value);
1807 LyXLength const & tmplen = tabular.getPWidth(actcell);
1809 bool const update = (tmplen != vallen);
1810 tabular.setMColumnPWidth(actcell, vallen);
1812 // We need this otherwise we won't resize
1813 // the insettext of the active cell (if any)
1814 // until later (see InsetText::do_resize)
1815 unlockInsetInInset(bv, the_locking_inset);
1817 for (int i = 0; i < tabular.rows(); ++i) {
1818 tabular.getCellInset(tabular.getCellNumber(i, column))->
1821 updateLocal(bv, INIT);
1825 case LyXTabular::SET_SPECIAL_COLUMN:
1826 case LyXTabular::SET_SPECIAL_MULTI:
1827 tabular.setAlignSpecial(actcell,value,feature);
1828 updateLocal(bv, FULL);
1830 case LyXTabular::APPEND_ROW:
1831 // append the row into the tabular
1832 unlockInsetInInset(bv, the_locking_inset);
1833 tabular.appendRow(bv->buffer()->params, actcell);
1834 updateLocal(bv, INIT);
1836 case LyXTabular::APPEND_COLUMN:
1837 // append the column into the tabular
1838 unlockInsetInInset(bv, the_locking_inset);
1839 tabular.appendColumn(bv->buffer()->params, actcell);
1840 actcell = tabular.getCellNumber(row, column);
1841 updateLocal(bv, INIT);
1843 case LyXTabular::DELETE_ROW:
1844 unlockInsetInInset(bv, the_locking_inset);
1845 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1846 tabular.deleteRow(sel_row_start);
1848 if (sel_row_start >= tabular.rows())
1850 actcell = tabular.getCellNumber(sel_row_start, column);
1852 updateLocal(bv, INIT);
1854 case LyXTabular::DELETE_COLUMN:
1855 unlockInsetInInset(bv, the_locking_inset);
1856 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1857 tabular.deleteColumn(sel_col_start);
1859 if (sel_col_start >= tabular.columns())
1861 actcell = tabular.getCellNumber(row, sel_col_start);
1863 updateLocal(bv, INIT);
1865 case LyXTabular::M_TOGGLE_LINE_TOP:
1867 case LyXTabular::TOGGLE_LINE_TOP:
1869 bool lineSet = !tabular.topLine(actcell, flag);
1870 for (int i = sel_row_start; i <= sel_row_end; ++i)
1871 for (int j = sel_col_start; j <= sel_col_end; ++j)
1873 tabular.getCellNumber(i, j),
1875 updateLocal(bv, INIT);
1879 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1881 case LyXTabular::TOGGLE_LINE_BOTTOM:
1883 bool lineSet = !tabular.bottomLine(actcell, flag);
1884 for (int i = sel_row_start; i <= sel_row_end; ++i)
1885 for (int j = sel_col_start; j <= sel_col_end; ++j)
1886 tabular.setBottomLine(
1887 tabular.getCellNumber(i, j),
1890 updateLocal(bv, INIT);
1894 case LyXTabular::M_TOGGLE_LINE_LEFT:
1896 case LyXTabular::TOGGLE_LINE_LEFT:
1898 bool lineSet = !tabular.leftLine(actcell, flag);
1899 for (int i = sel_row_start; i <= sel_row_end; ++i)
1900 for (int j = sel_col_start; j <= sel_col_end; ++j)
1901 tabular.setLeftLine(
1902 tabular.getCellNumber(i,j),
1905 updateLocal(bv, INIT);
1909 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1911 case LyXTabular::TOGGLE_LINE_RIGHT:
1913 bool lineSet = !tabular.rightLine(actcell, flag);
1914 for (int i = sel_row_start; i <= sel_row_end; ++i)
1915 for (int j = sel_col_start; j <= sel_col_end; ++j)
1916 tabular.setRightLine(
1917 tabular.getCellNumber(i,j),
1920 updateLocal(bv, INIT);
1924 case LyXTabular::M_ALIGN_LEFT:
1925 case LyXTabular::M_ALIGN_RIGHT:
1926 case LyXTabular::M_ALIGN_CENTER:
1928 case LyXTabular::ALIGN_LEFT:
1929 case LyXTabular::ALIGN_RIGHT:
1930 case LyXTabular::ALIGN_CENTER:
1931 case LyXTabular::ALIGN_BLOCK:
1932 for (int i = sel_row_start; i <= sel_row_end; ++i)
1933 for (int j = sel_col_start; j <= sel_col_end; ++j)
1934 tabular.setAlignment(
1935 tabular.getCellNumber(i, j),
1938 updateLocal(bv, INIT);
1940 case LyXTabular::M_VALIGN_TOP:
1941 case LyXTabular::M_VALIGN_BOTTOM:
1942 case LyXTabular::M_VALIGN_CENTER:
1944 case LyXTabular::VALIGN_TOP:
1945 case LyXTabular::VALIGN_BOTTOM:
1946 case LyXTabular::VALIGN_CENTER:
1947 for (int i = sel_row_start; i <= sel_row_end; ++i)
1948 for (int j = sel_col_start; j <= sel_col_end; ++j)
1949 tabular.setVAlignment(
1950 tabular.getCellNumber(i, j),
1952 updateLocal(bv, INIT);
1954 case LyXTabular::MULTICOLUMN:
1956 if (sel_row_start != sel_row_end) {
1957 #ifdef WITH_WARNINGS
1958 #warning Need I say it ? This is horrible.
1960 Alert::error(_("Error setting multicolumn"),
1961 _("You cannot set multicolumn vertically."));
1964 // just multicol for one Single Cell
1965 if (!hasSelection()) {
1966 // check wether we are completly in a multicol
1967 if (tabular.isMultiColumn(actcell)) {
1968 tabular.unsetMultiColumn(actcell);
1969 updateLocal(bv, INIT);
1971 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1972 updateLocal(bv, CELL);
1976 // we have a selection so this means we just add all this
1977 // cells to form a multicolumn cell
1981 if (sel_cell_start > sel_cell_end) {
1982 s_start = sel_cell_end;
1983 s_end = sel_cell_start;
1985 s_start = sel_cell_start;
1986 s_end = sel_cell_end;
1988 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1991 updateLocal(bv, INIT);
1994 case LyXTabular::SET_ALL_LINES:
1996 case LyXTabular::UNSET_ALL_LINES:
1997 for (int i = sel_row_start; i <= sel_row_end; ++i)
1998 for (int j = sel_col_start; j <= sel_col_end; ++j)
1999 tabular.setAllLines(
2000 tabular.getCellNumber(i,j), setLines);
2001 updateLocal(bv, INIT);
2003 case LyXTabular::SET_LONGTABULAR:
2004 tabular.setLongTabular(true);
2005 updateLocal(bv, INIT); // because this toggles displayed
2007 case LyXTabular::UNSET_LONGTABULAR:
2008 tabular.setLongTabular(false);
2009 updateLocal(bv, INIT); // because this toggles displayed
2011 case LyXTabular::SET_ROTATE_TABULAR:
2012 tabular.setRotateTabular(true);
2014 case LyXTabular::UNSET_ROTATE_TABULAR:
2015 tabular.setRotateTabular(false);
2017 case LyXTabular::SET_ROTATE_CELL:
2018 for (int i = sel_row_start; i <= sel_row_end; ++i)
2019 for (int j = sel_col_start; j<=sel_col_end; ++j)
2020 tabular.setRotateCell(
2021 tabular.getCellNumber(i, j),
2024 case LyXTabular::UNSET_ROTATE_CELL:
2025 for (int i = sel_row_start; i <= sel_row_end; ++i)
2026 for (int j = sel_col_start; j <= sel_col_end; ++j)
2027 tabular.setRotateCell(
2028 tabular.getCellNumber(i, j), false);
2030 case LyXTabular::SET_USEBOX:
2032 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2033 if (val == tabular.getUsebox(actcell))
2034 val = LyXTabular::BOX_NONE;
2035 for (int i = sel_row_start; i <= sel_row_end; ++i)
2036 for (int j = sel_col_start; j <= sel_col_end; ++j)
2038 tabular.getCellNumber(i, j), val);
2041 case LyXTabular::UNSET_LTFIRSTHEAD:
2043 case LyXTabular::SET_LTFIRSTHEAD:
2044 (void)tabular.getRowOfLTFirstHead(row, ltt);
2045 checkLongtableSpecial(ltt, value, flag);
2046 tabular.setLTHead(row, flag, ltt, true);
2048 case LyXTabular::UNSET_LTHEAD:
2050 case LyXTabular::SET_LTHEAD:
2051 (void)tabular.getRowOfLTHead(row, ltt);
2052 checkLongtableSpecial(ltt, value, flag);
2053 tabular.setLTHead(row, flag, ltt, false);
2055 case LyXTabular::UNSET_LTFOOT:
2057 case LyXTabular::SET_LTFOOT:
2058 (void)tabular.getRowOfLTFoot(row, ltt);
2059 checkLongtableSpecial(ltt, value, flag);
2060 tabular.setLTFoot(row, flag, ltt, false);
2062 case LyXTabular::UNSET_LTLASTFOOT:
2064 case LyXTabular::SET_LTLASTFOOT:
2065 (void)tabular.getRowOfLTLastFoot(row, ltt);
2066 checkLongtableSpecial(ltt, value, flag);
2067 tabular.setLTFoot(row, flag, ltt, true);
2069 case LyXTabular::SET_LTNEWPAGE:
2071 bool what = !tabular.getLTNewPage(row);
2072 tabular.setLTNewPage(row, what);
2075 // dummy stuff just to avoid warnings
2076 case LyXTabular::LAST_ACTION:
2080 InsetTabularMailer mailer(*this);
2081 mailer.updateDialog(bv);
2085 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2088 UpdatableInset * inset =
2089 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2090 LyXFont font(LyXFont::ALL_SANE);
2092 x = inset->x() + inset->width(bv, font);
2093 y = inset->descent(bv, font);
2095 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2096 //inset_y = cursor.y();
2097 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2098 if (!the_locking_inset)
2100 updateLocal(bv, CELL);
2101 return (the_locking_inset != 0);
2105 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2106 mouse_button::state button)
2108 inset_x = cursor_.x()
2109 - top_x + tabular.getBeginningOfTextInCell(actcell);
2110 inset_y = cursor_.y();
2111 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2115 bool InsetTabular::insetHit(BufferView *, int x, int) const
2118 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2122 // This returns paperWidth() if the cell-width is unlimited or the width
2123 // in pixels if we have a pwidth for this cell.
2124 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2126 LyXLength const len = tabular.getPWidth(cell);
2130 return len.inPixels(latexTextWidth(bv));
2134 int InsetTabular::getMaxWidth(BufferView * bv,
2135 UpdatableInset const * inset) const
2137 int cell = tabular.getCellFromInset(inset, actcell);
2140 lyxerr << "Own inset not found, shouldn't really happen!"
2145 int w = getMaxWidthOfCell(bv, cell);
2147 // because the inset then subtracts it's top_x and owner->x()
2148 w += (inset->x() - top_x);
2155 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2157 resizeLyXText(bv, recursive);
2161 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2164 for(int i = 0; i < tabular.rows(); ++i) {
2165 for(int j = 0; j < tabular.columns(); ++j) {
2166 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2174 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2175 bool const recursive) const
2177 if (the_locking_inset)
2178 return the_locking_inset->getLyXText(bv, recursive);
2180 // if we're locked lock the actual insettext and return it's LyXText!!!
2182 UpdatableInset * inset =
2183 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2184 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2185 return the_locking_inset->getLyXText(bv, recursive);
2188 return Inset::getLyXText(bv, recursive);
2192 bool InsetTabular::showInsetDialog(BufferView * bv) const
2194 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2195 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2196 InsetTabularMailer mailer(*tmp);
2197 mailer.showDialog(bv);
2203 void InsetTabular::openLayoutDialog(BufferView * bv) const
2205 if (the_locking_inset) {
2206 InsetTabular * i = static_cast<InsetTabular *>
2207 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2209 i->openLayoutDialog(bv);
2213 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2214 InsetTabularMailer mailer(*tmp);
2215 mailer.showDialog(bv);
2220 // function returns an object as defined in func_status.h:
2221 // states OK, Unknown, Disabled, On, Off.
2223 FuncStatus InsetTabular::getStatus(string const & what) const
2225 int action = LyXTabular::LAST_ACTION;
2229 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2230 string const tmp = tabularFeature[i].feature;
2231 if (tmp == what.substr(0, tmp.length())) {
2232 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2233 // tabularFeatures[i].feature.length())) {
2234 action = tabularFeature[i].action;
2238 if (action == LyXTabular::LAST_ACTION) {
2240 return status.unknown(true);
2243 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2248 LyXTabular::ltType dummyltt;
2251 if (hasSelection()) {
2252 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2254 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2258 case LyXTabular::SET_PWIDTH:
2259 case LyXTabular::SET_MPWIDTH:
2260 case LyXTabular::SET_SPECIAL_COLUMN:
2261 case LyXTabular::SET_SPECIAL_MULTI:
2262 case LyXTabular::APPEND_ROW:
2263 case LyXTabular::APPEND_COLUMN:
2264 case LyXTabular::DELETE_ROW:
2265 case LyXTabular::DELETE_COLUMN:
2266 case LyXTabular::SET_ALL_LINES:
2267 case LyXTabular::UNSET_ALL_LINES:
2268 return status.clear();
2270 case LyXTabular::MULTICOLUMN:
2271 status.setOnOff(tabular.isMultiColumn(actcell));
2273 case LyXTabular::M_TOGGLE_LINE_TOP:
2275 case LyXTabular::TOGGLE_LINE_TOP:
2276 status.setOnOff(tabular.topLine(actcell, flag));
2278 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2280 case LyXTabular::TOGGLE_LINE_BOTTOM:
2281 status.setOnOff(tabular.bottomLine(actcell, flag));
2283 case LyXTabular::M_TOGGLE_LINE_LEFT:
2285 case LyXTabular::TOGGLE_LINE_LEFT:
2286 status.setOnOff(tabular.leftLine(actcell, flag));
2288 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2290 case LyXTabular::TOGGLE_LINE_RIGHT:
2291 status.setOnOff(tabular.rightLine(actcell, flag));
2293 case LyXTabular::M_ALIGN_LEFT:
2295 case LyXTabular::ALIGN_LEFT:
2296 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2298 case LyXTabular::M_ALIGN_RIGHT:
2300 case LyXTabular::ALIGN_RIGHT:
2301 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2303 case LyXTabular::M_ALIGN_CENTER:
2305 case LyXTabular::ALIGN_CENTER:
2306 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2308 case LyXTabular::ALIGN_BLOCK:
2309 status.disabled(tabular.getPWidth(actcell).zero());
2310 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2312 case LyXTabular::M_VALIGN_TOP:
2314 case LyXTabular::VALIGN_TOP:
2315 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2317 case LyXTabular::M_VALIGN_BOTTOM:
2319 case LyXTabular::VALIGN_BOTTOM:
2320 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2322 case LyXTabular::M_VALIGN_CENTER:
2324 case LyXTabular::VALIGN_CENTER:
2325 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2327 case LyXTabular::SET_LONGTABULAR:
2328 status.setOnOff(tabular.isLongTabular());
2330 case LyXTabular::UNSET_LONGTABULAR:
2331 status.setOnOff(!tabular.isLongTabular());
2333 case LyXTabular::SET_ROTATE_TABULAR:
2334 status.setOnOff(tabular.getRotateTabular());
2336 case LyXTabular::UNSET_ROTATE_TABULAR:
2337 status.setOnOff(!tabular.getRotateTabular());
2339 case LyXTabular::SET_ROTATE_CELL:
2340 status.setOnOff(tabular.getRotateCell(actcell));
2342 case LyXTabular::UNSET_ROTATE_CELL:
2343 status.setOnOff(!tabular.getRotateCell(actcell));
2345 case LyXTabular::SET_USEBOX:
2346 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2348 case LyXTabular::SET_LTFIRSTHEAD:
2349 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2351 case LyXTabular::SET_LTHEAD:
2352 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2354 case LyXTabular::SET_LTFOOT:
2355 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2357 case LyXTabular::SET_LTLASTFOOT:
2358 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2360 case LyXTabular::SET_LTNEWPAGE:
2361 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2365 status.disabled(true);
2372 void InsetTabular::getLabelList(std::vector<string> & list) const
2374 tabular.getLabelList(list);
2378 bool InsetTabular::copySelection(BufferView * bv)
2380 if (!hasSelection())
2383 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2384 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2385 if (sel_col_start > sel_col_end) {
2386 sel_col_start = sel_col_end;
2387 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2389 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2391 int const columns = sel_col_end - sel_col_start + 1;
2393 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2394 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2395 if (sel_row_start > sel_row_end) {
2396 swap(sel_row_start, sel_row_end);
2398 int const rows = sel_row_end - sel_row_start + 1;
2400 delete paste_tabular;
2401 paste_tabular = new LyXTabular(bv->buffer()->params,
2402 this, tabular); // rows, columns);
2403 for (int i = 0; i < sel_row_start; ++i)
2404 paste_tabular->deleteRow(0);
2405 while (paste_tabular->rows() > rows)
2406 paste_tabular->deleteRow(rows);
2407 paste_tabular->setTopLine(0, true, true);
2408 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2410 for (int i = 0; i < sel_col_start; ++i)
2411 paste_tabular->deleteColumn(0);
2412 while (paste_tabular->columns() > columns)
2413 paste_tabular->deleteColumn(columns);
2414 paste_tabular->setLeftLine(0, true, true);
2415 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2419 paste_tabular->ascii(bv->buffer(), sstr,
2420 (int)parOwner()->params().depth(), true, '\t');
2421 bv->stuffClipboard(STRCONV(sstr.str()));
2426 bool InsetTabular::pasteSelection(BufferView * bv)
2431 for (int r1 = 0, r2 = actrow;
2432 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2434 for(int c1 = 0, c2 = actcol;
2435 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2437 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2438 tabular.isPartOfMultiColumn(r2,c2))
2440 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2444 if (tabular.isPartOfMultiColumn(r2,c2)) {
2448 int const n1 = paste_tabular->getCellNumber(r1, c1);
2449 int const n2 = tabular.getCellNumber(r2, c2);
2450 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2451 tabular.getCellInset(n2)->setOwner(this);
2452 tabular.getCellInset(n2)->deleteLyXText(bv);
2453 tabular.getCellInset(n2)->markNew();
2460 bool InsetTabular::cutSelection(BufferParams const & bp)
2462 if (!hasSelection())
2465 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2466 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2467 if (sel_col_start > sel_col_end) {
2468 sel_col_start = sel_col_end;
2469 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2471 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2473 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2474 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2475 if (sel_row_start > sel_row_end) {
2476 swap(sel_row_start, sel_row_end);
2478 if (sel_cell_start > sel_cell_end) {
2479 swap(sel_cell_start, sel_cell_end);
2481 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2482 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2483 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2490 bool InsetTabular::isRightToLeft(BufferView * bv)
2492 return bv->getParentLanguage(this)->RightToLeft();
2496 bool InsetTabular::nodraw() const
2498 if (!UpdatableInset::nodraw() && the_locking_inset)
2499 return the_locking_inset->nodraw();
2500 return UpdatableInset::nodraw();
2504 int InsetTabular::scroll(bool recursive) const
2506 int sx = UpdatableInset::scroll(false);
2508 if (recursive && the_locking_inset)
2509 sx += the_locking_inset->scroll(recursive);
2515 void InsetTabular::getSelection(int & srow, int & erow,
2516 int & scol, int & ecol) const
2518 int const start = hasSelection() ? sel_cell_start : actcell;
2519 int const end = hasSelection() ? sel_cell_end : actcell;
2521 srow = tabular.row_of_cell(start);
2522 erow = tabular.row_of_cell(end);
2527 scol = tabular.column_of_cell(start);
2528 ecol = tabular.column_of_cell(end);
2532 ecol = tabular.right_column_of_cell(end);
2537 ParagraphList * InsetTabular::getParagraphs(int i) const
2539 return (i < tabular.getNumberOfCells())
2540 ? tabular.getCellInset(i)->getParagraphs(0)
2545 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2547 if (the_locking_inset)
2548 return the_locking_inset->cursor(bv);
2549 return Inset::cursor(bv);
2553 Inset * InsetTabular::getInsetFromID(int id_arg) const
2556 return const_cast<InsetTabular *>(this);
2559 for(int i = 0; i < tabular.rows(); ++i) {
2560 for(int j = 0; j < tabular.columns(); ++j) {
2561 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2570 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2573 if (the_locking_inset) {
2574 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2575 if (!word.word().empty()) {
2579 if (tabular.isLastCell(actcell)) {
2580 bv->unlockInset(const_cast<InsetTabular *>(this));
2582 return WordLangTuple();
2586 // otherwise we have to lock the next inset and ask for it's selecttion
2587 UpdatableInset * inset =
2588 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2589 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2590 WordLangTuple word(selectNextWordInt(bv, value));
2592 if (!word.word().empty())
2598 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2600 // when entering this function the inset should be ALWAYS locked!
2601 Assert(the_locking_inset);
2603 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2604 if (!word.word().empty())
2607 if (tabular.isLastCell(actcell)) {
2608 bv->unlockInset(const_cast<InsetTabular *>(this));
2609 return WordLangTuple();
2612 // otherwise we have to lock the next inset and ask for it's selecttion
2613 UpdatableInset * inset =
2614 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2615 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2616 return selectNextWordInt(bv, value);
2620 void InsetTabular::selectSelectedWord(BufferView * bv)
2622 if (the_locking_inset) {
2623 the_locking_inset->selectSelectedWord(bv);
2630 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2632 if (the_locking_inset) {
2633 the_locking_inset->toggleSelection(bv, kill_selection);
2638 void InsetTabular::markErased()
2642 while (cell < tabular.getNumberOfCells()) {
2643 InsetText * inset = tabular.getCellInset(cell);
2644 inset->markErased();
2650 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2652 if (the_locking_inset) {
2653 if (the_locking_inset->nextChange(bv, length)) {
2654 updateLocal(bv, CELL);
2657 if (tabular.isLastCell(actcell))
2661 InsetText * inset = tabular.getCellInset(actcell);
2662 if (inset->nextChange(bv, length)) {
2663 updateLocal(bv, FULL);
2666 while (!tabular.isLastCell(actcell)) {
2668 inset = tabular.getCellInset(actcell);
2669 if (inset->nextChange(bv, length)) {
2670 updateLocal(bv, FULL);
2678 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2682 if (the_locking_inset) {
2683 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2684 updateLocal(bv, CELL);
2687 if (tabular.isLastCell(actcell))
2691 InsetText * inset = tabular.getCellInset(cell);
2692 if (inset->searchForward(bv, str, cs, mw)) {
2693 updateLocal(bv, FULL);
2696 while (!tabular.isLastCell(cell)) {
2698 inset = tabular.getCellInset(cell);
2699 if (inset->searchForward(bv, str, cs, mw)) {
2700 updateLocal(bv, FULL);
2708 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2711 int cell = tabular.getNumberOfCells();
2712 if (the_locking_inset) {
2713 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2714 updateLocal(bv, CELL);
2722 InsetText * inset = tabular.getCellInset(cell);
2723 if (inset->searchBackward(bv, str, cs, mw)) {
2724 updateLocal(bv, CELL);
2732 bool InsetTabular::insetAllowed(Inset::Code code) const
2734 if (the_locking_inset)
2735 return the_locking_inset->insetAllowed(code);
2736 // we return true here because if the inset is not locked someone
2737 // wants to insert something in one of our insettexts and we generally
2743 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2745 const int cell = tabular.getCellFromInset(in, actcell);
2748 return tabular.getPWidth(cell).zero();
2750 // well we didn't obviously find it so maybe our owner knows more
2752 return owner()->forceDefaultParagraphs(in);
2753 // if we're here there is really something strange going on!!!
2757 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2760 if (buf.length() <= 0)
2766 string::size_type len = buf.length();
2767 string::size_type p = 0;
2770 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2779 maxCols = max(cols, maxCols);
2785 maxCols = max(cols, maxCols);
2786 LyXTabular * loctab;
2791 delete paste_tabular;
2792 paste_tabular = new LyXTabular(bv->buffer()->params,
2793 this, rows, maxCols);
2794 loctab = paste_tabular;
2803 string::size_type op = 0;
2804 int cells = loctab->getNumberOfCells();
2807 rows = loctab->rows();
2808 int const columns = loctab->columns();
2810 while ((cell < cells) && (p < len) && (row < rows) &&
2811 (p = buf.find_first_of("\t\n", p)) != string::npos)
2817 // we can only set this if we are not too far right
2818 if (cols < columns) {
2819 InsetText * ti = loctab->getCellInset(cell);
2820 LyXFont const font = ti->getLyXText(bv)->
2821 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2822 ti->setText(buf.substr(op, p - op), font);
2828 // we can only set this if we are not too far right
2829 if (cols < columns) {
2830 InsetText * ti = loctab->getCellInset(cell);
2831 LyXFont const font = ti->getLyXText(bv)->
2832 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2833 ti->setText(buf.substr(op, p - op), font);
2838 cell = loctab->getCellNumber(row, cols);
2844 // check for the last cell if there is no trailing '\n'
2845 if ((cell < cells) && (op < len)) {
2846 InsetText * ti = loctab->getCellInset(cell);
2847 LyXFont const font = ti->getLyXText(bv)->
2848 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2849 ti->setText(buf.substr(op, len - op), font);
2856 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2858 int const rows = tabular.rows();
2859 int const columns = tabular.columns();
2860 for (int i = 0; i < rows; ++i) {
2861 for (int j = 0; j < columns; ++j) {
2862 tabular.getCellInset(i,j)->addPreview(loader);
2868 string const InsetTabularMailer:: name_("tabular");
2870 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2875 string const InsetTabularMailer::inset2string() const
2877 return params2string(inset_);
2881 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2883 istringstream data(STRCONV(in));
2885 lex.setStream(data);
2887 #warning CHECK verify that this is a sane value to return.
2893 string const token = lex.getString();
2901 string const token = lex.getString();
2902 if (token != "\\active_cell")
2905 cell = lex.getInteger();
2908 // This is part of the inset proper that is usually swallowed
2909 // by Buffer::readInset
2912 string const token = lex.getString();
2913 if (token != "Tabular")
2920 Buffer const * const buffer = inset.buffer();
2922 inset.read(buffer, lex);
2924 // We can't set the active cell, but we can tell the frontend
2930 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2932 Buffer const * const buffer = inset.buffer();
2937 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2938 inset.write(buffer, data);
2939 data << "\\end_inset\n";
2940 return STRCONV(data.str());