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 && bv->text->needRefresh())
437 switch (need_update) {
441 if (calculate_dimensions_of_cells(bv, false)) {
453 string const InsetTabular::editMessage() const
455 return _("Opened table");
459 void InsetTabular::insetUnlock(BufferView * bv)
461 if (the_locking_inset) {
462 the_locking_inset->insetUnlock(bv);
463 updateLocal(bv, CELL);
464 the_locking_inset = 0;
469 if (scroll(false) || hasSelection()) {
474 updateLocal(bv, FULL);
479 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
482 calculate_dimensions_of_cells(bv, true);
484 if (!locked && what == CELL)
486 if (need_update < what) // only set this if it has greater update
489 if (need_update != NONE) {
490 bv->updateInset(const_cast<InsetTabular *>(this));
497 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
499 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
504 if (inset == tabular.getCellInset(actcell)) {
505 lyxerr[Debug::INSETTEXT] << "OK" << endl;
506 the_locking_inset = tabular.getCellInset(actcell);
509 } else if (!the_locking_inset) {
510 int const n = tabular.getNumberOfCells();
511 int const id = inset->id();
512 for (int i = 0; i < n; ++i) {
513 InsetText * in = tabular.getCellInset(i);
516 the_locking_inset = in;
521 if (in->getInsetFromID(id)) {
523 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
524 return the_locking_inset->lockInsetInInset(bv, inset);
527 } else if (the_locking_inset && (the_locking_inset == inset)) {
528 lyxerr[Debug::INSETTEXT] << "OK" << endl;
530 } else if (the_locking_inset) {
531 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
532 return the_locking_inset->lockInsetInInset(bv, inset);
534 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
539 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
542 if (!the_locking_inset)
544 if (the_locking_inset == inset) {
545 the_locking_inset->insetUnlock(bv);
547 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
553 updateLocal(bv, CELL);
554 // this has to be here otherwise we don't redraw the cell!
555 the_locking_inset = 0;
558 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
559 if (inset->lyxCode() == TABULAR_CODE &&
560 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
561 InsetTabularMailer mailer(*this);
562 mailer.updateDialog(bv);
571 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
573 Inset * tl_inset = inset;
574 // look if this inset is really inside myself!
575 while(tl_inset->owner() && tl_inset->owner() != this)
576 tl_inset = tl_inset->owner();
577 // if we enter here it's not ower inset
578 if (!tl_inset->owner())
580 // we only have to do this if this is a subinset of our cells
581 if (tl_inset != inset) {
582 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
585 updateLocal(bv, CELL);
590 int InsetTabular::insetInInsetY() const
592 if (!the_locking_inset)
594 return inset_y + the_locking_inset->insetInInsetY();
598 UpdatableInset * InsetTabular::getLockingInset() const
600 return the_locking_inset ? the_locking_inset->getLockingInset() :
601 const_cast<InsetTabular *>(this);
605 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
609 if (the_locking_inset)
610 return the_locking_inset->getFirstLockingInsetOfType(c);
615 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
617 if (the_locking_inset)
618 return the_locking_inset->insertInset(bv, inset);
623 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
625 if (hasSelection() && cmd.button() == mouse_button::button3)
628 if (hasSelection()) {
630 updateLocal(cmd.view(), FULL);
633 int const ocell = actcell;
634 int const orow = actrow;
635 BufferView * bv = cmd.view();
639 the_locking_inset = 0;
643 setPos(bv, cmd.x, cmd.y);
645 updateLocal(bv, NONE);
648 if (cmd.button() == mouse_button::button3) {
649 if ((ocell != actcell) && the_locking_inset) {
650 the_locking_inset->insetUnlock(bv);
651 updateLocal(bv, CELL);
652 the_locking_inset = 0;
658 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
660 if ((ocell == actcell) && the_locking_inset && inset_hit) {
662 FuncRequest cmd1 = cmd;
665 the_locking_inset->localDispatch(cmd1);
669 if (the_locking_inset) {
670 the_locking_inset->insetUnlock(bv);
671 updateLocal(bv, CELL);
672 the_locking_inset = 0;
675 if (cmd.button() == mouse_button::button2) {
676 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
680 if (inset_hit && bv->theLockingInset()) {
681 if (!bv->lockInset(static_cast<UpdatableInset*>
682 (tabular.getCellInset(actcell))))
684 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
687 FuncRequest cmd1 = cmd;
690 the_locking_inset->localDispatch(cmd1);
696 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
699 if (the_locking_inset) {
700 FuncRequest cmd1 = cmd;
703 ret = the_locking_inset->localDispatch(cmd1);
705 if (cmd.button() == mouse_button::button3 && !ret) {
706 InsetTabularMailer(*this).showDialog(cmd.view());
713 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
715 if (the_locking_inset) {
716 FuncRequest cmd1 = cmd;
719 the_locking_inset->localDispatch(cmd1);
723 BufferView * bv = cmd.view();
724 int const old_cell = actcell;
726 setPos(bv, cmd.x, cmd.y);
727 if (!hasSelection()) {
728 setSelection(actcell, actcell);
729 updateLocal(bv, FULL);
730 } else if (old_cell != actcell) {
731 setSelection(sel_cell_start, actcell);
732 updateLocal(bv, FULL);
737 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
739 // We need to save the value of the_locking_inset as the call to
740 // the_locking_inset->localDispatch might unlock it.
741 old_locking_inset = the_locking_inset;
742 RESULT result = UpdatableInset::localDispatch(cmd);
743 BufferView * bv = cmd.view();
745 if (cmd.action == LFUN_INSET_EDIT) {
747 if (!bv->lockInset(this)) {
748 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
754 the_locking_inset = 0;
758 if (cmd.argument.size()) {
759 if (cmd.argument == "left") {
760 if (isRightToLeft(bv))
761 actcell = tabular.getLastCellInRow(0);
765 if (isRightToLeft(bv))
766 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
768 actcell = tabular.getNumberOfCells() - 1;
776 setPos(bv, cmd.x, cmd.y);
779 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
780 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
786 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
791 if (cmd.action < 0 && cmd.argument.empty())
794 bool hs = hasSelection();
797 // this one have priority over the locked InsetText, if we're not already
798 // inside another tabular then that one get's priority!
799 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
800 switch (cmd.action) {
801 case LFUN_MOUSE_PRESS:
805 case LFUN_MOUSE_MOTION:
806 lfunMouseMotion(cmd);
809 case LFUN_MOUSE_RELEASE:
810 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
812 case LFUN_CELL_BACKWARD:
813 case LFUN_CELL_FORWARD:
814 unlockInsetInInset(bv, the_locking_inset);
815 if (cmd.action == LFUN_CELL_FORWARD)
816 moveNextCell(bv, old_locking_inset != 0);
818 movePrevCell(bv, old_locking_inset != 0);
821 updateLocal(bv, FULL);
822 if (!the_locking_inset) {
823 return DISPATCHED_NOUPDATE;
826 // this to avoid compiler warnings.
832 kb_action action = cmd.action;
833 string arg = cmd.argument;
834 if (the_locking_inset) {
835 result = the_locking_inset->localDispatch(cmd);
836 if (result == DISPATCHED_NOUPDATE) {
839 if (sc != scroll()) { // inset has been scrolled
840 updateLocal(bv, FULL);
843 } else if (result == DISPATCHED) {
844 updateLocal(bv, CELL);
846 } else if (result == FINISHED_UP) {
848 // Make sure to reset status message after
849 // exiting, e.g. math inset
850 bv->owner()->clearMessage();
851 } else if (result == FINISHED_DOWN) {
853 bv->owner()->clearMessage();
854 } else if (result == FINISHED_RIGHT) {
856 bv->owner()->clearMessage();
857 } else if (result == FINISHED) {
858 bv->owner()->clearMessage();
864 // --- Cursor Movements ----------------------------------
865 case LFUN_RIGHTSEL: {
866 int const start = hasSelection() ? sel_cell_start : actcell;
867 if (tabular.isLastCellInRow(actcell)) {
868 setSelection(start, actcell);
873 // if we are starting a selection, only select
874 // the current cell at the beginning
875 if (hasSelection()) {
876 moveRight(bv, false);
879 setSelection(start, end);
880 updateLocal(bv, FULL);
884 result = moveRight(bv);
887 updateLocal(bv, FULL);
890 int const start = hasSelection() ? sel_cell_start : actcell;
891 if (tabular.isFirstCellInRow(actcell)) {
892 setSelection(start, actcell);
897 // if we are starting a selection, only select
898 // the current cell at the beginning
899 if (hasSelection()) {
903 setSelection(start, end);
904 updateLocal(bv, FULL);
908 result = moveLeft(bv);
911 updateLocal(bv, FULL);
914 int const start = hasSelection() ? sel_cell_start : actcell;
915 int const ocell = actcell;
916 // if we are starting a selection, only select
917 // the current cell at the beginning
918 if (hasSelection()) {
920 if ((ocell == sel_cell_end) ||
921 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
922 setSelection(start, tabular.getCellBelow(sel_cell_end));
924 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
926 setSelection(start, start);
928 updateLocal(bv, FULL);
932 result = moveDown(bv, old_locking_inset != 0);
935 updateLocal(bv, FULL);
939 int const start = hasSelection() ? sel_cell_start : actcell;
940 int const ocell = actcell;
941 // if we are starting a selection, only select
942 // the current cell at the beginning
943 if (hasSelection()) {
945 if ((ocell == sel_cell_end) ||
946 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
947 setSelection(start, tabular.getCellAbove(sel_cell_end));
949 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
951 setSelection(start, start);
953 updateLocal(bv, FULL);
957 result = moveUp(bv, old_locking_inset != 0);
960 updateLocal(bv, FULL);
963 UpdateCodes code = CURSOR;
969 unlockInsetInInset(bv, the_locking_inset);
970 if (bv->text->top_y() + bv->painter().paperHeight() <
971 (top_baseline + tabular.getHeightOfTabular()))
973 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
975 actcell = tabular.getCellBelow(first_visible_cell) + column;
977 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
980 updateLocal(bv, code);
984 UpdateCodes code = CURSOR;
990 unlockInsetInInset(bv, the_locking_inset);
991 if (top_baseline < 0) {
992 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
994 if (top_baseline > 0)
997 actcell = tabular.getCellBelow(first_visible_cell) + column;
1002 updateLocal(bv, code);
1005 // none of these make sense for insettabular,
1006 // but we must catch them to prevent any
1007 // selection from being confused
1011 case LFUN_WORDLEFTSEL:
1012 case LFUN_WORDRIGHT:
1013 case LFUN_WORDRIGHTSEL:
1015 case LFUN_DOWN_PARAGRAPH:
1016 case LFUN_DOWN_PARAGRAPHSEL:
1017 case LFUN_UP_PARAGRAPH:
1018 case LFUN_UP_PARAGRAPHSEL:
1019 case LFUN_BACKSPACE:
1024 case LFUN_BEGINNINGBUF:
1025 case LFUN_BEGINNINGBUFSEL:
1027 case LFUN_ENDBUFSEL:
1029 case LFUN_LAYOUT_TABULAR: {
1030 InsetTabularMailer mailer(*this);
1031 mailer.showDialog(bv);
1034 case LFUN_INSET_DIALOG_UPDATE: {
1035 InsetTabularMailer mailer(*this);
1036 mailer.updateDialog(bv);
1039 case LFUN_TABULAR_FEATURE:
1040 if (!tabularFeatures(bv, arg))
1041 result = UNDISPATCHED;
1043 // insert file functions
1044 case LFUN_FILE_INSERT_ASCII_PARA:
1045 case LFUN_FILE_INSERT_ASCII:
1047 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1050 if (insertAsciiString(bv, tmpstr, false))
1051 updateLocal(bv, INIT);
1053 result = UNDISPATCHED;
1056 // cut and paste functions
1058 if (!copySelection(bv))
1062 setUndo(bv, Undo::DELETE);
1063 cutSelection(bv->buffer()->params);
1064 updateLocal(bv, INIT);
1067 if (!hasSelection())
1072 case LFUN_PASTESELECTION:
1074 string const clip(bv->getClipboard());
1078 if (clip.find('\t') != string::npos) {
1082 string::size_type len = clip.length();
1083 string::size_type p = 0;
1086 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1094 maxCols = max(cols, maxCols);
1100 maxCols = max(cols, maxCols);
1101 delete paste_tabular;
1102 paste_tabular = new LyXTabular(bv->buffer()->params,
1103 this, rows, maxCols);
1104 string::size_type op = 0;
1106 int cells = paste_tabular->getNumberOfCells();
1108 while ((cell < cells) && (p < len) &&
1109 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1114 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1119 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1120 while (cols++ < maxCols)
1128 // check for the last cell if there is no trailing '\n'
1129 if ((cell < cells) && (op < len))
1130 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1133 if (!insertAsciiString(bv, clip, true))
1136 // so that the clipboard is used and it goes on
1138 // and executes LFUN_PASTESELECTION in insettext!
1139 delete paste_tabular;
1144 if (hasPasteBuffer()) {
1145 setUndo(bv, Undo::INSERT);
1147 updateLocal(bv, INIT);
1150 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1152 // handle font changing stuff on selection before we lock the inset
1153 // in the default part!
1154 result = UNDISPATCHED;
1165 case LFUN_UNDERLINE:
1166 case LFUN_FONT_SIZE:
1167 if (bv->dispatch(FuncRequest(bv, action, arg)))
1168 result = DISPATCHED;
1174 // we try to activate the actual inset and put this event down to
1175 // the insets dispatch function.
1176 if ((result == DISPATCHED) || the_locking_inset)
1179 if (activateCellInset(bv)) {
1180 // reset need_update setted in above function!
1182 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1183 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1184 unlockInsetInInset(bv, the_locking_inset);
1186 // we need to update if this was requested before
1187 updateLocal(bv, NONE);
1188 return UNDISPATCHED;
1191 // so the below CELL is not set because this is higher
1192 // priority and we get a full redraw
1196 updateLocal(bv, CELL);
1201 if (result < FINISHED) {
1202 if (!the_locking_inset) {
1203 if (bv->fitCursor())
1204 updateLocal(bv, FULL);
1207 bv->unlockInset(this);
1212 int InsetTabular::latex(Buffer const * buf, ostream & os,
1213 LatexRunParams const & runparams) const
1215 return tabular.latex(buf, os, runparams);
1219 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1222 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1224 return tabular.ascii(buf, os, 0, false,0);
1228 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1231 int const ret = tabular.ascii(buf,os,
1232 (int)parOwner()->params().depth(),
1239 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1244 // if the table is inside a float it doesn't need the informaltable
1245 // wrapper. Search for it.
1246 for(master = owner();
1247 master && master->lyxCode() != Inset::FLOAT_CODE;
1248 master = master->owner());
1251 os << "<informaltable>";
1256 ret+= tabular.docbook(buf, os, mixcont);
1258 os << "</informaltable>";
1267 void InsetTabular::validate(LaTeXFeatures & features) const
1269 tabular.validate(features);
1273 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1279 bool changed = false;
1281 // FIXME: since InsetText ignores this anyway, it doesn't
1282 // matter what we pass it. Ugly
1285 // if we have a locking_inset we should have to check only this cell for
1286 // change so I'll try this to have a boost, but who knows ;)
1287 if ((need_update != INIT) &&
1288 (the_locking_inset == tabular.getCellInset(actcell))) {
1289 for(int i = 0; i < tabular.columns(); ++i) {
1290 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1292 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1295 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1296 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1297 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1300 for (int i = 0; i < tabular.rows(); ++i) {
1303 for (int j = 0; j < tabular.columns(); ++j) {
1304 if (tabular.isPartOfMultiColumn(i,j))
1307 inset = tabular.getCellInset(cell);
1308 if (!reinit && !tabular.getPWidth(cell).zero())
1309 inset->update(bv, false);
1310 maxAsc = max(maxAsc, inset->ascent(bv, font));
1311 maxDesc = max(maxDesc, inset->descent(bv, font));
1312 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1314 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1315 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1323 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1325 if (the_locking_inset) {
1326 the_locking_inset->getCursor(bv, x, y);
1331 y = cursor_.y() + InsetTabular::y();
1334 int desc = tabular.getDescentOfRow(actrow);
1336 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1338 y += ADD_TO_HEIGHT * 2;
1339 y += TEXT_TO_INSET_OFFSET;
1343 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1345 if (the_locking_inset) {
1346 the_locking_inset->getCursorPos(bv, x, y);
1349 x = cursor_.x() - top_x;
1354 void InsetTabular::fitInsetCursor(BufferView * bv) const
1356 if (the_locking_inset) {
1357 int old_top_y = bv->text->top_y();
1358 the_locking_inset->fitInsetCursor(bv);
1359 if (old_top_y != bv->text->top_y())
1365 int const asc = font_metrics::maxAscent(font);
1366 int const desc = font_metrics::maxDescent(font);
1369 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1374 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1378 actcell = actrow = actcol = 0;
1379 int ly = tabular.getDescentOfRow(actrow);
1381 // first search the right row
1382 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1383 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1384 tabular.getAscentOfRow(actrow + 1) +
1385 tabular.getAdditionalHeight(actrow + 1));
1387 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1389 actcell = tabular.getCellNumber(actrow, actcol);
1391 // now search the right column
1392 int lx = tabular.getWidthOfColumn(actcell) -
1393 tabular.getAdditionalWidth(actcell);
1394 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1395 lx += tabular.getWidthOfColumn(actcell + 1)
1396 + tabular.getAdditionalWidth(actcell);
1398 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1403 int InsetTabular::getCellXPos(int cell) const
1407 for (; !tabular.isFirstCellInRow(c); --c)
1409 int lx = tabular.getWidthOfColumn(cell);
1410 for (; c < cell; ++c) {
1411 lx += tabular.getWidthOfColumn(c);
1413 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1417 void InsetTabular::resetPos(BufferView * bv) const
1419 #ifdef WITH_WARNINGS
1420 #warning This should be fixed in the right manner (20011128 Jug)
1422 // fast hack to fix infinite repaintings!
1423 if (in_reset_pos > 0)
1427 actcol = tabular.column_of_cell(actcell);
1430 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1431 if (tabular.isLastCellInRow(cell)) {
1432 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1433 tabular.getAscentOfRow(actrow + 1) +
1434 tabular.getAdditionalHeight(actrow + 1));
1438 if (!locked || nodraw()) {
1439 if (the_locking_inset)
1440 inset_y = cursor_.y();
1443 // we need this only from here on!!!
1445 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1446 int new_x = getCellXPos(actcell);
1447 int old_x = cursor_.x();
1450 // cursor.x(getCellXPos(actcell) + offset);
1451 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1452 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1455 updateLocal(bv, FULL);
1456 } else if (the_locking_inset &&
1457 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1459 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1460 if (xx > (bv->workWidth()-20)) {
1461 scroll(bv, -(xx - bv->workWidth() + 60));
1462 updateLocal(bv, FULL);
1463 } else if (xx < 20) {
1469 updateLocal(bv, FULL);
1471 } else if ((cursor_.x() - offset) > 20 &&
1472 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1473 > (bv->workWidth() - 20)) {
1474 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1475 updateLocal(bv, FULL);
1476 } else if ((cursor_.x() - offset) < 20) {
1477 scroll(bv, 20 - cursor_.x() + offset);
1478 updateLocal(bv, FULL);
1479 } else if (scroll() && top_x > 20 &&
1480 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1481 scroll(bv, old_x - cursor_.x());
1482 updateLocal(bv, FULL);
1484 if (the_locking_inset) {
1485 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1486 inset_y = cursor_.y();
1488 if ((!the_locking_inset ||
1489 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1490 actcell != oldcell) {
1491 InsetTabular * inset = const_cast<InsetTabular *>(this);
1492 InsetTabularMailer mailer(*inset);
1493 mailer.updateDialog(bv);
1500 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1502 if (lock && !old_locking_inset) {
1503 if (activateCellInset(bv))
1506 bool moved = isRightToLeft(bv)
1507 ? movePrevCell(bv) : moveNextCell(bv);
1509 return FINISHED_RIGHT;
1510 if (lock && activateCellInset(bv))
1514 return DISPATCHED_NOUPDATE;
1518 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1520 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1523 if (lock) { // behind the inset
1524 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1528 return DISPATCHED_NOUPDATE;
1532 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1534 int const ocell = actcell;
1535 actcell = tabular.getCellAbove(actcell);
1536 if (actcell == ocell) // we moved out of the inset
1542 if (old_locking_inset) {
1543 old_locking_inset->getCursorPos(bv, x, y);
1544 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1546 if (activateCellInset(bv, x, 0))
1549 return DISPATCHED_NOUPDATE;
1553 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1555 int const ocell = actcell;
1556 actcell = tabular.getCellBelow(actcell);
1557 if (actcell == ocell) // we moved out of the inset
1558 return FINISHED_DOWN;
1563 if (old_locking_inset) {
1564 old_locking_inset->getCursorPos(bv, x, y);
1565 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1567 if (activateCellInset(bv, x, 0))
1570 return DISPATCHED_NOUPDATE;
1574 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1576 if (isRightToLeft(bv)) {
1577 if (tabular.isFirstCellInRow(actcell)) {
1578 int row = tabular.row_of_cell(actcell);
1579 if (row == tabular.rows() - 1)
1581 actcell = tabular.getLastCellInRow(row);
1582 actcell = tabular.getCellBelow(actcell);
1589 if (tabular.isLastCell(actcell))
1594 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1595 isRightToLeftPar(bv->buffer()->params);
1596 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1603 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1605 if (isRightToLeft(bv)) {
1606 if (tabular.isLastCellInRow(actcell)) {
1607 int row = tabular.row_of_cell(actcell);
1610 actcell = tabular.getFirstCellInRow(row);
1611 actcell = tabular.getCellAbove(actcell);
1613 if (tabular.isLastCell(actcell))
1618 if (!actcell) // first cell
1623 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1624 isRightToLeftPar(bv->buffer()->params);
1625 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1632 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1636 setSelection(0, tabular.getNumberOfCells() - 1);
1638 if (hasSelection()) {
1639 setUndo(bv, Undo::EDIT);
1640 bool const frozen = undo_frozen;
1643 // apply the fontchange on the whole selection
1648 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1649 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1650 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1651 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1658 updateLocal(bv, INIT);
1660 if (the_locking_inset)
1661 the_locking_inset->setFont(bv, font, tall);
1665 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1667 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1670 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1671 string const tmp = tabularFeature[i].feature;
1673 if (tmp == what.substr(0, tmp.length())) {
1674 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1675 //tabularFeatures[i].feature.length())) {
1676 action = tabularFeature[i].action;
1680 if (action == LyXTabular::LAST_ACTION)
1684 ltrim(what.substr(tabularFeature[i].feature.length()));
1685 tabularFeatures(bv, action, val);
1691 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1692 string const & special, bool & flag)
1694 if (special == "dl_above") {
1697 } else if (special == "dl_below") {
1698 ltt.bottomDL = flag;
1700 } else if (special == "empty") {
1712 void InsetTabular::tabularFeatures(BufferView * bv,
1713 LyXTabular::Feature feature,
1714 string const & value)
1720 bool setLines = false;
1721 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1722 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1725 case LyXTabular::M_ALIGN_LEFT:
1726 case LyXTabular::ALIGN_LEFT:
1727 setAlign = LYX_ALIGN_LEFT;
1729 case LyXTabular::M_ALIGN_RIGHT:
1730 case LyXTabular::ALIGN_RIGHT:
1731 setAlign = LYX_ALIGN_RIGHT;
1733 case LyXTabular::M_ALIGN_CENTER:
1734 case LyXTabular::ALIGN_CENTER:
1735 setAlign = LYX_ALIGN_CENTER;
1737 case LyXTabular::ALIGN_BLOCK:
1738 setAlign = LYX_ALIGN_BLOCK;
1740 case LyXTabular::M_VALIGN_TOP:
1741 case LyXTabular::VALIGN_TOP:
1742 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1744 case LyXTabular::M_VALIGN_BOTTOM:
1745 case LyXTabular::VALIGN_BOTTOM:
1746 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1748 case LyXTabular::M_VALIGN_CENTER:
1749 case LyXTabular::VALIGN_CENTER:
1750 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1755 if (hasSelection()) {
1756 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1758 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1759 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1761 setUndo(bv, Undo::FINISH);
1763 int row = tabular.row_of_cell(actcell);
1764 int column = tabular.column_of_cell(actcell);
1766 LyXTabular::ltType ltt;
1769 case LyXTabular::SET_PWIDTH:
1771 LyXLength const vallen(value);
1772 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1774 bool const update = (tmplen != vallen);
1775 tabular.setColumnPWidth(actcell, vallen);
1777 // We need this otherwise we won't resize
1778 // the insettext of the active cell (if any)
1779 // until later (see InsetText::do_resize)
1780 unlockInsetInInset(bv, the_locking_inset);
1783 for (int i = 0; i < tabular.rows(); ++i) {
1784 cell = tabular.getCellNumber(i,column);
1785 tabular.getCellInset(cell)->resizeLyXText(bv);
1787 updateLocal(bv, INIT);
1791 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1792 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1793 else if (!vallen.zero()
1794 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1795 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1798 case LyXTabular::SET_MPWIDTH:
1800 LyXLength const vallen(value);
1801 LyXLength const & tmplen = tabular.getPWidth(actcell);
1803 bool const update = (tmplen != vallen);
1804 tabular.setMColumnPWidth(actcell, vallen);
1806 // We need this otherwise we won't resize
1807 // the insettext of the active cell (if any)
1808 // until later (see InsetText::do_resize)
1809 unlockInsetInInset(bv, the_locking_inset);
1811 for (int i = 0; i < tabular.rows(); ++i) {
1812 tabular.getCellInset(tabular.getCellNumber(i, column))->
1815 updateLocal(bv, INIT);
1819 case LyXTabular::SET_SPECIAL_COLUMN:
1820 case LyXTabular::SET_SPECIAL_MULTI:
1821 tabular.setAlignSpecial(actcell,value,feature);
1822 updateLocal(bv, FULL);
1824 case LyXTabular::APPEND_ROW:
1825 // append the row into the tabular
1826 unlockInsetInInset(bv, the_locking_inset);
1827 tabular.appendRow(bv->buffer()->params, actcell);
1828 updateLocal(bv, INIT);
1830 case LyXTabular::APPEND_COLUMN:
1831 // append the column into the tabular
1832 unlockInsetInInset(bv, the_locking_inset);
1833 tabular.appendColumn(bv->buffer()->params, actcell);
1834 actcell = tabular.getCellNumber(row, column);
1835 updateLocal(bv, INIT);
1837 case LyXTabular::DELETE_ROW:
1838 unlockInsetInInset(bv, the_locking_inset);
1839 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1840 tabular.deleteRow(sel_row_start);
1842 if (sel_row_start >= tabular.rows())
1844 actcell = tabular.getCellNumber(sel_row_start, column);
1846 updateLocal(bv, INIT);
1848 case LyXTabular::DELETE_COLUMN:
1849 unlockInsetInInset(bv, the_locking_inset);
1850 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1851 tabular.deleteColumn(sel_col_start);
1853 if (sel_col_start >= tabular.columns())
1855 actcell = tabular.getCellNumber(row, sel_col_start);
1857 updateLocal(bv, INIT);
1859 case LyXTabular::M_TOGGLE_LINE_TOP:
1861 case LyXTabular::TOGGLE_LINE_TOP:
1863 bool lineSet = !tabular.topLine(actcell, flag);
1864 for (int i = sel_row_start; i <= sel_row_end; ++i)
1865 for (int j = sel_col_start; j <= sel_col_end; ++j)
1867 tabular.getCellNumber(i, j),
1869 updateLocal(bv, INIT);
1873 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1875 case LyXTabular::TOGGLE_LINE_BOTTOM:
1877 bool lineSet = !tabular.bottomLine(actcell, flag);
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.setBottomLine(
1881 tabular.getCellNumber(i, j),
1884 updateLocal(bv, INIT);
1888 case LyXTabular::M_TOGGLE_LINE_LEFT:
1890 case LyXTabular::TOGGLE_LINE_LEFT:
1892 bool lineSet = !tabular.leftLine(actcell, flag);
1893 for (int i = sel_row_start; i <= sel_row_end; ++i)
1894 for (int j = sel_col_start; j <= sel_col_end; ++j)
1895 tabular.setLeftLine(
1896 tabular.getCellNumber(i,j),
1899 updateLocal(bv, INIT);
1903 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1905 case LyXTabular::TOGGLE_LINE_RIGHT:
1907 bool lineSet = !tabular.rightLine(actcell, flag);
1908 for (int i = sel_row_start; i <= sel_row_end; ++i)
1909 for (int j = sel_col_start; j <= sel_col_end; ++j)
1910 tabular.setRightLine(
1911 tabular.getCellNumber(i,j),
1914 updateLocal(bv, INIT);
1918 case LyXTabular::M_ALIGN_LEFT:
1919 case LyXTabular::M_ALIGN_RIGHT:
1920 case LyXTabular::M_ALIGN_CENTER:
1922 case LyXTabular::ALIGN_LEFT:
1923 case LyXTabular::ALIGN_RIGHT:
1924 case LyXTabular::ALIGN_CENTER:
1925 case LyXTabular::ALIGN_BLOCK:
1926 for (int i = sel_row_start; i <= sel_row_end; ++i)
1927 for (int j = sel_col_start; j <= sel_col_end; ++j)
1928 tabular.setAlignment(
1929 tabular.getCellNumber(i, j),
1932 updateLocal(bv, INIT);
1934 case LyXTabular::M_VALIGN_TOP:
1935 case LyXTabular::M_VALIGN_BOTTOM:
1936 case LyXTabular::M_VALIGN_CENTER:
1938 case LyXTabular::VALIGN_TOP:
1939 case LyXTabular::VALIGN_BOTTOM:
1940 case LyXTabular::VALIGN_CENTER:
1941 for (int i = sel_row_start; i <= sel_row_end; ++i)
1942 for (int j = sel_col_start; j <= sel_col_end; ++j)
1943 tabular.setVAlignment(
1944 tabular.getCellNumber(i, j),
1946 updateLocal(bv, INIT);
1948 case LyXTabular::MULTICOLUMN:
1950 if (sel_row_start != sel_row_end) {
1951 #ifdef WITH_WARNINGS
1952 #warning Need I say it ? This is horrible.
1954 Alert::error(_("Error setting multicolumn"),
1955 _("You cannot set multicolumn vertically."));
1958 // just multicol for one Single Cell
1959 if (!hasSelection()) {
1960 // check wether we are completly in a multicol
1961 if (tabular.isMultiColumn(actcell)) {
1962 tabular.unsetMultiColumn(actcell);
1963 updateLocal(bv, INIT);
1965 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1966 updateLocal(bv, CELL);
1970 // we have a selection so this means we just add all this
1971 // cells to form a multicolumn cell
1975 if (sel_cell_start > sel_cell_end) {
1976 s_start = sel_cell_end;
1977 s_end = sel_cell_start;
1979 s_start = sel_cell_start;
1980 s_end = sel_cell_end;
1982 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1985 updateLocal(bv, INIT);
1988 case LyXTabular::SET_ALL_LINES:
1990 case LyXTabular::UNSET_ALL_LINES:
1991 for (int i = sel_row_start; i <= sel_row_end; ++i)
1992 for (int j = sel_col_start; j <= sel_col_end; ++j)
1993 tabular.setAllLines(
1994 tabular.getCellNumber(i,j), setLines);
1995 updateLocal(bv, INIT);
1997 case LyXTabular::SET_LONGTABULAR:
1998 tabular.setLongTabular(true);
1999 updateLocal(bv, INIT); // because this toggles displayed
2001 case LyXTabular::UNSET_LONGTABULAR:
2002 tabular.setLongTabular(false);
2003 updateLocal(bv, INIT); // because this toggles displayed
2005 case LyXTabular::SET_ROTATE_TABULAR:
2006 tabular.setRotateTabular(true);
2008 case LyXTabular::UNSET_ROTATE_TABULAR:
2009 tabular.setRotateTabular(false);
2011 case LyXTabular::SET_ROTATE_CELL:
2012 for (int i = sel_row_start; i <= sel_row_end; ++i)
2013 for (int j = sel_col_start; j<=sel_col_end; ++j)
2014 tabular.setRotateCell(
2015 tabular.getCellNumber(i, j),
2018 case LyXTabular::UNSET_ROTATE_CELL:
2019 for (int i = sel_row_start; i <= sel_row_end; ++i)
2020 for (int j = sel_col_start; j <= sel_col_end; ++j)
2021 tabular.setRotateCell(
2022 tabular.getCellNumber(i, j), false);
2024 case LyXTabular::SET_USEBOX:
2026 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2027 if (val == tabular.getUsebox(actcell))
2028 val = LyXTabular::BOX_NONE;
2029 for (int i = sel_row_start; i <= sel_row_end; ++i)
2030 for (int j = sel_col_start; j <= sel_col_end; ++j)
2032 tabular.getCellNumber(i, j), val);
2035 case LyXTabular::UNSET_LTFIRSTHEAD:
2037 case LyXTabular::SET_LTFIRSTHEAD:
2038 (void)tabular.getRowOfLTFirstHead(row, ltt);
2039 checkLongtableSpecial(ltt, value, flag);
2040 tabular.setLTHead(row, flag, ltt, true);
2042 case LyXTabular::UNSET_LTHEAD:
2044 case LyXTabular::SET_LTHEAD:
2045 (void)tabular.getRowOfLTHead(row, ltt);
2046 checkLongtableSpecial(ltt, value, flag);
2047 tabular.setLTHead(row, flag, ltt, false);
2049 case LyXTabular::UNSET_LTFOOT:
2051 case LyXTabular::SET_LTFOOT:
2052 (void)tabular.getRowOfLTFoot(row, ltt);
2053 checkLongtableSpecial(ltt, value, flag);
2054 tabular.setLTFoot(row, flag, ltt, false);
2056 case LyXTabular::UNSET_LTLASTFOOT:
2058 case LyXTabular::SET_LTLASTFOOT:
2059 (void)tabular.getRowOfLTLastFoot(row, ltt);
2060 checkLongtableSpecial(ltt, value, flag);
2061 tabular.setLTFoot(row, flag, ltt, true);
2063 case LyXTabular::SET_LTNEWPAGE:
2065 bool what = !tabular.getLTNewPage(row);
2066 tabular.setLTNewPage(row, what);
2069 // dummy stuff just to avoid warnings
2070 case LyXTabular::LAST_ACTION:
2074 InsetTabularMailer mailer(*this);
2075 mailer.updateDialog(bv);
2079 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2082 UpdatableInset * inset =
2083 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2084 LyXFont font(LyXFont::ALL_SANE);
2086 x = inset->x() + inset->width(bv, font);
2087 y = inset->descent(bv, font);
2089 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2090 //inset_y = cursor.y();
2091 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2092 if (!the_locking_inset)
2094 updateLocal(bv, CELL);
2095 return (the_locking_inset != 0);
2099 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2100 mouse_button::state button)
2102 inset_x = cursor_.x()
2103 - top_x + tabular.getBeginningOfTextInCell(actcell);
2104 inset_y = cursor_.y();
2105 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2109 bool InsetTabular::insetHit(BufferView *, int x, int) const
2112 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2116 // This returns paperWidth() if the cell-width is unlimited or the width
2117 // in pixels if we have a pwidth for this cell.
2118 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2120 LyXLength const len = tabular.getPWidth(cell);
2124 return len.inPixels(latexTextWidth(bv));
2128 int InsetTabular::getMaxWidth(BufferView * bv,
2129 UpdatableInset const * inset) const
2131 int cell = tabular.getCellFromInset(inset, actcell);
2134 lyxerr << "Own inset not found, shouldn't really happen!"
2139 int w = getMaxWidthOfCell(bv, cell);
2141 // because the inset then subtracts it's top_x and owner->x()
2142 w += (inset->x() - top_x);
2149 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2151 resizeLyXText(bv, recursive);
2155 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2158 for(int i = 0; i < tabular.rows(); ++i) {
2159 for(int j = 0; j < tabular.columns(); ++j) {
2160 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2168 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2169 bool const recursive) const
2171 if (the_locking_inset)
2172 return the_locking_inset->getLyXText(bv, recursive);
2174 // if we're locked lock the actual insettext and return it's LyXText!!!
2176 UpdatableInset * inset =
2177 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2178 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2179 return the_locking_inset->getLyXText(bv, recursive);
2182 return Inset::getLyXText(bv, recursive);
2186 bool InsetTabular::showInsetDialog(BufferView * bv) const
2188 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2189 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2190 InsetTabularMailer mailer(*tmp);
2191 mailer.showDialog(bv);
2197 void InsetTabular::openLayoutDialog(BufferView * bv) const
2199 if (the_locking_inset) {
2200 InsetTabular * i = static_cast<InsetTabular *>
2201 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2203 i->openLayoutDialog(bv);
2207 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2208 InsetTabularMailer mailer(*tmp);
2209 mailer.showDialog(bv);
2214 // function returns an object as defined in func_status.h:
2215 // states OK, Unknown, Disabled, On, Off.
2217 FuncStatus InsetTabular::getStatus(string const & what) const
2219 int action = LyXTabular::LAST_ACTION;
2223 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2224 string const tmp = tabularFeature[i].feature;
2225 if (tmp == what.substr(0, tmp.length())) {
2226 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2227 // tabularFeatures[i].feature.length())) {
2228 action = tabularFeature[i].action;
2232 if (action == LyXTabular::LAST_ACTION) {
2234 return status.unknown(true);
2237 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2242 LyXTabular::ltType dummyltt;
2245 if (hasSelection()) {
2246 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2248 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2252 case LyXTabular::SET_PWIDTH:
2253 case LyXTabular::SET_MPWIDTH:
2254 case LyXTabular::SET_SPECIAL_COLUMN:
2255 case LyXTabular::SET_SPECIAL_MULTI:
2256 case LyXTabular::APPEND_ROW:
2257 case LyXTabular::APPEND_COLUMN:
2258 case LyXTabular::DELETE_ROW:
2259 case LyXTabular::DELETE_COLUMN:
2260 case LyXTabular::SET_ALL_LINES:
2261 case LyXTabular::UNSET_ALL_LINES:
2262 return status.clear();
2264 case LyXTabular::MULTICOLUMN:
2265 status.setOnOff(tabular.isMultiColumn(actcell));
2267 case LyXTabular::M_TOGGLE_LINE_TOP:
2269 case LyXTabular::TOGGLE_LINE_TOP:
2270 status.setOnOff(tabular.topLine(actcell, flag));
2272 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2274 case LyXTabular::TOGGLE_LINE_BOTTOM:
2275 status.setOnOff(tabular.bottomLine(actcell, flag));
2277 case LyXTabular::M_TOGGLE_LINE_LEFT:
2279 case LyXTabular::TOGGLE_LINE_LEFT:
2280 status.setOnOff(tabular.leftLine(actcell, flag));
2282 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2284 case LyXTabular::TOGGLE_LINE_RIGHT:
2285 status.setOnOff(tabular.rightLine(actcell, flag));
2287 case LyXTabular::M_ALIGN_LEFT:
2289 case LyXTabular::ALIGN_LEFT:
2290 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2292 case LyXTabular::M_ALIGN_RIGHT:
2294 case LyXTabular::ALIGN_RIGHT:
2295 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2297 case LyXTabular::M_ALIGN_CENTER:
2299 case LyXTabular::ALIGN_CENTER:
2300 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2302 case LyXTabular::ALIGN_BLOCK:
2303 status.disabled(tabular.getPWidth(actcell).zero());
2304 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2306 case LyXTabular::M_VALIGN_TOP:
2308 case LyXTabular::VALIGN_TOP:
2309 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2311 case LyXTabular::M_VALIGN_BOTTOM:
2313 case LyXTabular::VALIGN_BOTTOM:
2314 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2316 case LyXTabular::M_VALIGN_CENTER:
2318 case LyXTabular::VALIGN_CENTER:
2319 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2321 case LyXTabular::SET_LONGTABULAR:
2322 status.setOnOff(tabular.isLongTabular());
2324 case LyXTabular::UNSET_LONGTABULAR:
2325 status.setOnOff(!tabular.isLongTabular());
2327 case LyXTabular::SET_ROTATE_TABULAR:
2328 status.setOnOff(tabular.getRotateTabular());
2330 case LyXTabular::UNSET_ROTATE_TABULAR:
2331 status.setOnOff(!tabular.getRotateTabular());
2333 case LyXTabular::SET_ROTATE_CELL:
2334 status.setOnOff(tabular.getRotateCell(actcell));
2336 case LyXTabular::UNSET_ROTATE_CELL:
2337 status.setOnOff(!tabular.getRotateCell(actcell));
2339 case LyXTabular::SET_USEBOX:
2340 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2342 case LyXTabular::SET_LTFIRSTHEAD:
2343 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2345 case LyXTabular::SET_LTHEAD:
2346 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2348 case LyXTabular::SET_LTFOOT:
2349 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2351 case LyXTabular::SET_LTLASTFOOT:
2352 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2354 case LyXTabular::SET_LTNEWPAGE:
2355 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2359 status.disabled(true);
2366 void InsetTabular::getLabelList(std::vector<string> & list) const
2368 tabular.getLabelList(list);
2372 bool InsetTabular::copySelection(BufferView * bv)
2374 if (!hasSelection())
2377 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2378 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2379 if (sel_col_start > sel_col_end) {
2380 sel_col_start = sel_col_end;
2381 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2383 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2385 int const columns = sel_col_end - sel_col_start + 1;
2387 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2388 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2389 if (sel_row_start > sel_row_end) {
2390 swap(sel_row_start, sel_row_end);
2392 int const rows = sel_row_end - sel_row_start + 1;
2394 delete paste_tabular;
2395 paste_tabular = new LyXTabular(bv->buffer()->params,
2396 this, tabular); // rows, columns);
2397 for (int i = 0; i < sel_row_start; ++i)
2398 paste_tabular->deleteRow(0);
2399 while (paste_tabular->rows() > rows)
2400 paste_tabular->deleteRow(rows);
2401 paste_tabular->setTopLine(0, true, true);
2402 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2404 for (int i = 0; i < sel_col_start; ++i)
2405 paste_tabular->deleteColumn(0);
2406 while (paste_tabular->columns() > columns)
2407 paste_tabular->deleteColumn(columns);
2408 paste_tabular->setLeftLine(0, true, true);
2409 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2413 paste_tabular->ascii(bv->buffer(), sstr,
2414 (int)parOwner()->params().depth(), true, '\t');
2415 bv->stuffClipboard(STRCONV(sstr.str()));
2420 bool InsetTabular::pasteSelection(BufferView * bv)
2425 for (int r1 = 0, r2 = actrow;
2426 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2428 for(int c1 = 0, c2 = actcol;
2429 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2431 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2432 tabular.isPartOfMultiColumn(r2,c2))
2434 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2438 if (tabular.isPartOfMultiColumn(r2,c2)) {
2442 int const n1 = paste_tabular->getCellNumber(r1, c1);
2443 int const n2 = tabular.getCellNumber(r2, c2);
2444 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2445 tabular.getCellInset(n2)->setOwner(this);
2446 tabular.getCellInset(n2)->deleteLyXText(bv);
2447 tabular.getCellInset(n2)->markNew();
2454 bool InsetTabular::cutSelection(BufferParams const & bp)
2456 if (!hasSelection())
2459 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2460 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2461 if (sel_col_start > sel_col_end) {
2462 sel_col_start = sel_col_end;
2463 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2465 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2467 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2468 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2469 if (sel_row_start > sel_row_end) {
2470 swap(sel_row_start, sel_row_end);
2472 if (sel_cell_start > sel_cell_end) {
2473 swap(sel_cell_start, sel_cell_end);
2475 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2476 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2477 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2484 bool InsetTabular::isRightToLeft(BufferView * bv)
2486 return bv->getParentLanguage(this)->RightToLeft();
2490 bool InsetTabular::nodraw() const
2492 if (!UpdatableInset::nodraw() && the_locking_inset)
2493 return the_locking_inset->nodraw();
2494 return UpdatableInset::nodraw();
2498 int InsetTabular::scroll(bool recursive) const
2500 int sx = UpdatableInset::scroll(false);
2502 if (recursive && the_locking_inset)
2503 sx += the_locking_inset->scroll(recursive);
2509 void InsetTabular::getSelection(int & srow, int & erow,
2510 int & scol, int & ecol) const
2512 int const start = hasSelection() ? sel_cell_start : actcell;
2513 int const end = hasSelection() ? sel_cell_end : actcell;
2515 srow = tabular.row_of_cell(start);
2516 erow = tabular.row_of_cell(end);
2521 scol = tabular.column_of_cell(start);
2522 ecol = tabular.column_of_cell(end);
2526 ecol = tabular.right_column_of_cell(end);
2531 ParagraphList * InsetTabular::getParagraphs(int i) const
2533 return (i < tabular.getNumberOfCells())
2534 ? tabular.getCellInset(i)->getParagraphs(0)
2539 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2541 if (the_locking_inset)
2542 return the_locking_inset->cursor(bv);
2543 return Inset::cursor(bv);
2547 Inset * InsetTabular::getInsetFromID(int id_arg) const
2550 return const_cast<InsetTabular *>(this);
2553 for(int i = 0; i < tabular.rows(); ++i) {
2554 for(int j = 0; j < tabular.columns(); ++j) {
2555 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2564 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2567 if (the_locking_inset) {
2568 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2569 if (!word.word().empty()) {
2573 if (tabular.isLastCell(actcell)) {
2574 bv->unlockInset(const_cast<InsetTabular *>(this));
2576 return WordLangTuple();
2580 // otherwise we have to lock the next inset and ask for it's selecttion
2581 UpdatableInset * inset =
2582 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2583 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2584 WordLangTuple word(selectNextWordInt(bv, value));
2586 if (!word.word().empty())
2592 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2594 // when entering this function the inset should be ALWAYS locked!
2595 Assert(the_locking_inset);
2597 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2598 if (!word.word().empty())
2601 if (tabular.isLastCell(actcell)) {
2602 bv->unlockInset(const_cast<InsetTabular *>(this));
2603 return WordLangTuple();
2606 // otherwise we have to lock the next inset and ask for it's selecttion
2607 UpdatableInset * inset =
2608 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2609 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2610 return selectNextWordInt(bv, value);
2614 void InsetTabular::selectSelectedWord(BufferView * bv)
2616 if (the_locking_inset) {
2617 the_locking_inset->selectSelectedWord(bv);
2624 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2626 if (the_locking_inset) {
2627 the_locking_inset->toggleSelection(bv, kill_selection);
2632 void InsetTabular::markErased()
2636 while (cell < tabular.getNumberOfCells()) {
2637 InsetText * inset = tabular.getCellInset(cell);
2638 inset->markErased();
2644 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2646 if (the_locking_inset) {
2647 if (the_locking_inset->nextChange(bv, length)) {
2648 updateLocal(bv, CELL);
2651 if (tabular.isLastCell(actcell))
2655 InsetText * inset = tabular.getCellInset(actcell);
2656 if (inset->nextChange(bv, length)) {
2657 updateLocal(bv, FULL);
2660 while (!tabular.isLastCell(actcell)) {
2662 inset = tabular.getCellInset(actcell);
2663 if (inset->nextChange(bv, length)) {
2664 updateLocal(bv, FULL);
2672 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2676 if (the_locking_inset) {
2677 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2678 updateLocal(bv, CELL);
2681 if (tabular.isLastCell(actcell))
2685 InsetText * inset = tabular.getCellInset(cell);
2686 if (inset->searchForward(bv, str, cs, mw)) {
2687 updateLocal(bv, FULL);
2690 while (!tabular.isLastCell(cell)) {
2692 inset = tabular.getCellInset(cell);
2693 if (inset->searchForward(bv, str, cs, mw)) {
2694 updateLocal(bv, FULL);
2702 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2705 int cell = tabular.getNumberOfCells();
2706 if (the_locking_inset) {
2707 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2708 updateLocal(bv, CELL);
2716 InsetText * inset = tabular.getCellInset(cell);
2717 if (inset->searchBackward(bv, str, cs, mw)) {
2718 updateLocal(bv, CELL);
2726 bool InsetTabular::insetAllowed(Inset::Code code) const
2728 if (the_locking_inset)
2729 return the_locking_inset->insetAllowed(code);
2730 // we return true here because if the inset is not locked someone
2731 // wants to insert something in one of our insettexts and we generally
2737 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2739 const int cell = tabular.getCellFromInset(in, actcell);
2742 return tabular.getPWidth(cell).zero();
2744 // well we didn't obviously find it so maybe our owner knows more
2746 return owner()->forceDefaultParagraphs(in);
2747 // if we're here there is really something strange going on!!!
2751 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2754 if (buf.length() <= 0)
2760 string::size_type len = buf.length();
2761 string::size_type p = 0;
2764 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2773 maxCols = max(cols, maxCols);
2779 maxCols = max(cols, maxCols);
2780 LyXTabular * loctab;
2785 delete paste_tabular;
2786 paste_tabular = new LyXTabular(bv->buffer()->params,
2787 this, rows, maxCols);
2788 loctab = paste_tabular;
2797 string::size_type op = 0;
2798 int cells = loctab->getNumberOfCells();
2801 rows = loctab->rows();
2802 int const columns = loctab->columns();
2804 while ((cell < cells) && (p < len) && (row < rows) &&
2805 (p = buf.find_first_of("\t\n", p)) != string::npos)
2811 // we can only set this if we are not too far right
2812 if (cols < columns) {
2813 InsetText * ti = loctab->getCellInset(cell);
2814 LyXFont const font = ti->getLyXText(bv)->
2815 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2816 ti->setText(buf.substr(op, p - op), font);
2822 // we can only set this if we are not too far right
2823 if (cols < columns) {
2824 InsetText * ti = loctab->getCellInset(cell);
2825 LyXFont const font = ti->getLyXText(bv)->
2826 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2827 ti->setText(buf.substr(op, p - op), font);
2832 cell = loctab->getCellNumber(row, cols);
2838 // check for the last cell if there is no trailing '\n'
2839 if ((cell < cells) && (op < len)) {
2840 InsetText * ti = loctab->getCellInset(cell);
2841 LyXFont const font = ti->getLyXText(bv)->
2842 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2843 ti->setText(buf.substr(op, len - op), font);
2850 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2852 int const rows = tabular.rows();
2853 int const columns = tabular.columns();
2854 for (int i = 0; i < rows; ++i) {
2855 for (int j = 0; j < columns; ++j) {
2856 tabular.getCellInset(i,j)->addPreview(loader);
2862 string const InsetTabularMailer:: name_("tabular");
2864 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2869 string const InsetTabularMailer::inset2string() const
2871 return params2string(inset_);
2875 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2877 istringstream data(STRCONV(in));
2879 lex.setStream(data);
2881 #warning CHECK verify that this is a sane value to return.
2887 string const token = lex.getString();
2895 string const token = lex.getString();
2896 if (token != "\\active_cell")
2899 cell = lex.getInteger();
2902 // This is part of the inset proper that is usually swallowed
2903 // by Buffer::readInset
2906 string const token = lex.getString();
2907 if (token != "Tabular")
2914 Buffer const * const buffer = inset.buffer();
2916 inset.read(buffer, lex);
2918 // We can't set the active cell, but we can tell the frontend
2924 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2926 Buffer const * const buffer = inset.buffer();
2931 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2932 inset.write(buffer, data);
2933 data << "\\end_inset\n";
2934 return STRCONV(data.str());