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 BufferView * InsetTabular::view() const
211 return buffer_->getUser();
215 void InsetTabular::buffer(Buffer * b)
221 void InsetTabular::write(Buffer const * buf, ostream & os) const
223 os << " Tabular" << endl;
224 tabular.write(buf, os);
228 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
230 bool const old_format = (lex.getString() == "\\LyXTable");
232 tabular.read(buf, lex);
240 string token = lex.getString();
241 while (lex.isOK() && (token != "\\end_inset")) {
243 token = lex.getString();
245 if (token != "\\end_inset") {
246 lex.printError("Missing \\end_inset at this point. "
252 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
255 //lyxerr << "InsetTabular::metrics, bv: " << mi.base.bv << endl;
256 for (int i = 0; i < tabular.getNumberOfCells(); ++i) {
257 tabular.cellinfo_of_cell(i)->inset.text_.bv_owner = mi.base.bv;
258 tabular.cellinfo_of_cell(i)->inset.reinitLyXText();
262 dim.asc = tabular.getAscentOfRow(0);
263 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
264 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
268 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
275 BufferView * bv = pi.base.bv;
281 UpdatableInset::draw(pi, x, y);
289 x += ADD_TO_TABULAR_WIDTH;
293 first_visible_cell = -1;
294 for (i = 0; i < tabular.rows(); ++i) {
296 cell = tabular.getCellNumber(i, 0);
297 if (!((y + tabular.getDescentOfRow(i)) > 0) &&
298 (y - tabular.getAscentOfRow(i)) < pi.pain.paperHeight())
300 y += tabular.getDescentOfRow(i) +
301 tabular.getAscentOfRow(i + 1) +
302 tabular.getAdditionalHeight(i + 1);
305 for (j = 0; j < tabular.columns(); ++j) {
306 if (nx > bv->workWidth())
308 if (tabular.isPartOfMultiColumn(i, j))
310 cx = nx + tabular.getBeginningOfTextInCell(cell);
311 if (first_visible_cell < 0)
312 first_visible_cell = cell;
313 if (hasSelection()) {
314 drawCellSelection(pi.pain, nx, y, i, j, cell);
317 tabular.getCellInset(cell)->draw(pi, cx, y);
318 drawCellLines(pi.pain, nx, y, i, cell);
319 nx += tabular.getWidthOfColumn(cell);
323 // Would be nice, but for some completely unfathomable reason,
324 // on a col resize to a new fixed width, even though the insettexts
325 // are resized, the cell isn't, but drawing all cells in a tall table
326 // has the desired effect somehow. Complete dark magic.
328 // avoiding drawing the rest of a long table is
329 // a pretty big speedup
330 if (y > bv->workHeight())
334 y += tabular.getDescentOfRow(i) +
335 tabular.getAscentOfRow(i + 1) +
336 tabular.getAdditionalHeight(i + 1);
343 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
344 int row, int cell) const
346 int x2 = x + tabular.getWidthOfColumn(cell);
349 if (!tabular.topAlreadyDrawn(cell)) {
350 on_off = !tabular.topLine(cell);
351 pain.line(x, y - tabular.getAscentOfRow(row),
352 x2, y - tabular.getAscentOfRow(row),
353 on_off ? LColor::tabularonoffline : LColor::tabularline,
354 on_off ? Painter::line_onoffdash : Painter::line_solid);
356 on_off = !tabular.bottomLine(cell);
357 pain.line(x, y + tabular.getDescentOfRow(row),
358 x2, y + tabular.getDescentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
361 if (!tabular.leftAlreadyDrawn(cell)) {
362 on_off = !tabular.leftLine(cell);
363 pain.line(x, y - tabular.getAscentOfRow(row),
364 x, y + tabular.getDescentOfRow(row),
365 on_off ? LColor::tabularonoffline : LColor::tabularline,
366 on_off ? Painter::line_onoffdash : Painter::line_solid);
368 on_off = !tabular.rightLine(cell);
369 pain.line(x2 - tabular.getAdditionalWidth(cell),
370 y - tabular.getAscentOfRow(row),
371 x2 - tabular.getAdditionalWidth(cell),
372 y + tabular.getDescentOfRow(row),
373 on_off ? LColor::tabularonoffline : LColor::tabularline,
374 on_off ? Painter::line_onoffdash : Painter::line_solid);
378 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
379 int row, int column, int cell) const
381 Assert(hasSelection());
382 int cs = tabular.column_of_cell(sel_cell_start);
383 int ce = tabular.column_of_cell(sel_cell_end);
386 cs = tabular.column_of_cell(sel_cell_end);
388 ce = tabular.right_column_of_cell(sel_cell_end);
391 int rs = tabular.row_of_cell(sel_cell_start);
392 int re = tabular.row_of_cell(sel_cell_end);
396 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
397 int w = tabular.getWidthOfColumn(cell);
398 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
399 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
400 w, h, LColor::selection);
405 void InsetTabular::update(BufferView * bv, bool reinit)
411 owner()->update(bv, true);
418 if (calculate_dimensions_of_cells(bv, true))
421 owner()->update(bv, true);
425 if (the_locking_inset)
426 the_locking_inset->update(bv, reinit);
427 if (need_update < FULL &&
428 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
433 switch (need_update) {
437 if (calculate_dimensions_of_cells(bv, false)) {
452 string const InsetTabular::editMessage() const
454 return _("Opened table");
458 void InsetTabular::insetUnlock(BufferView * bv)
460 if (the_locking_inset) {
461 the_locking_inset->insetUnlock(bv);
462 updateLocal(bv, CELL);
463 the_locking_inset = 0;
468 if (scroll(false) || hasSelection()) {
473 updateLocal(bv, FULL);
478 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
481 calculate_dimensions_of_cells(bv, true);
483 if (!locked && what == CELL)
485 if (need_update < what) // only set this if it has greater update
488 if (need_update != NONE) {
489 bv->updateInset(const_cast<InsetTabular *>(this));
496 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
498 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
503 if (inset == tabular.getCellInset(actcell)) {
504 lyxerr[Debug::INSETTEXT] << "OK" << endl;
505 the_locking_inset = tabular.getCellInset(actcell);
508 } else if (!the_locking_inset) {
509 int const n = tabular.getNumberOfCells();
510 int const id = inset->id();
511 for (int i = 0; i < n; ++i) {
512 InsetText * in = tabular.getCellInset(i);
515 the_locking_inset = in;
520 if (in->getInsetFromID(id)) {
522 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
523 return the_locking_inset->lockInsetInInset(bv, inset);
526 } else if (the_locking_inset && (the_locking_inset == inset)) {
527 lyxerr[Debug::INSETTEXT] << "OK" << endl;
529 } else if (the_locking_inset) {
530 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
531 return the_locking_inset->lockInsetInInset(bv, inset);
533 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
538 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
541 if (!the_locking_inset)
543 if (the_locking_inset == inset) {
544 the_locking_inset->insetUnlock(bv);
546 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
552 updateLocal(bv, CELL);
553 // this has to be here otherwise we don't redraw the cell!
554 the_locking_inset = 0;
557 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
558 if (inset->lyxCode() == TABULAR_CODE &&
559 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
560 InsetTabularMailer mailer(*this);
561 mailer.updateDialog(bv);
570 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
572 Inset * tl_inset = inset;
573 // look if this inset is really inside myself!
574 while(tl_inset->owner() && tl_inset->owner() != this)
575 tl_inset = tl_inset->owner();
576 // if we enter here it's not ower inset
577 if (!tl_inset->owner())
579 // we only have to do this if this is a subinset of our cells
580 if (tl_inset != inset) {
581 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
584 updateLocal(bv, CELL);
589 int InsetTabular::insetInInsetY() const
591 if (!the_locking_inset)
593 return inset_y + the_locking_inset->insetInInsetY();
597 UpdatableInset * InsetTabular::getLockingInset() const
599 return the_locking_inset ? the_locking_inset->getLockingInset() :
600 const_cast<InsetTabular *>(this);
604 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
608 if (the_locking_inset)
609 return the_locking_inset->getFirstLockingInsetOfType(c);
614 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
616 if (the_locking_inset)
617 return the_locking_inset->insertInset(bv, inset);
622 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
624 if (hasSelection() && cmd.button() == mouse_button::button3)
627 if (hasSelection()) {
629 updateLocal(cmd.view(), SELECTION);
632 int const ocell = actcell;
633 int const orow = actrow;
634 BufferView * bv = cmd.view();
638 the_locking_inset = 0;
642 setPos(bv, cmd.x, cmd.y);
644 updateLocal(bv, NONE);
647 if (cmd.button() == mouse_button::button3) {
648 if ((ocell != actcell) && the_locking_inset) {
649 the_locking_inset->insetUnlock(bv);
650 updateLocal(bv, CELL);
651 the_locking_inset = 0;
657 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
659 if ((ocell == actcell) && the_locking_inset && inset_hit) {
661 FuncRequest cmd1 = cmd;
664 the_locking_inset->localDispatch(cmd1);
668 if (the_locking_inset) {
669 the_locking_inset->insetUnlock(bv);
670 updateLocal(bv, CELL);
671 the_locking_inset = 0;
674 if (cmd.button() == mouse_button::button2) {
675 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
679 if (inset_hit && bv->theLockingInset()) {
680 if (!bv->lockInset(static_cast<UpdatableInset*>
681 (tabular.getCellInset(actcell))))
683 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
686 FuncRequest cmd1 = cmd;
689 the_locking_inset->localDispatch(cmd1);
695 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
698 if (the_locking_inset) {
699 FuncRequest cmd1 = cmd;
702 ret = the_locking_inset->localDispatch(cmd1);
704 if (cmd.button() == mouse_button::button3 && !ret) {
705 InsetTabularMailer(*this).showDialog(cmd.view());
712 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
714 if (the_locking_inset) {
715 FuncRequest cmd1 = cmd;
718 the_locking_inset->localDispatch(cmd1);
722 BufferView * bv = cmd.view();
723 int const old_cell = actcell;
725 setPos(bv, cmd.x, cmd.y);
726 if (!hasSelection()) {
727 setSelection(actcell, actcell);
728 updateLocal(bv, SELECTION);
729 } else if (old_cell != actcell) {
730 setSelection(sel_cell_start, actcell);
731 updateLocal(bv, SELECTION);
736 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
738 // We need to save the value of the_locking_inset as the call to
739 // the_locking_inset->localDispatch might unlock it.
740 old_locking_inset = the_locking_inset;
741 RESULT result = UpdatableInset::localDispatch(cmd);
742 BufferView * bv = cmd.view();
744 if (cmd.action == LFUN_INSET_EDIT) {
746 if (!bv->lockInset(this)) {
747 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
753 the_locking_inset = 0;
757 if (cmd.argument.size()) {
758 if (cmd.argument == "left") {
759 if (isRightToLeft(bv))
760 actcell = tabular.getLastCellInRow(0);
764 if (isRightToLeft(bv))
765 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
767 actcell = tabular.getNumberOfCells() - 1;
775 setPos(bv, cmd.x, cmd.y);
778 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
779 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
785 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
790 if (cmd.action < 0 && cmd.argument.empty())
793 bool hs = hasSelection();
796 // this one have priority over the locked InsetText, if we're not already
797 // inside another tabular then that one get's priority!
798 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
799 switch (cmd.action) {
800 case LFUN_MOUSE_PRESS:
804 case LFUN_MOUSE_MOTION:
805 lfunMouseMotion(cmd);
808 case LFUN_MOUSE_RELEASE:
809 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
811 case LFUN_CELL_BACKWARD:
812 case LFUN_CELL_FORWARD:
813 unlockInsetInInset(bv, the_locking_inset);
814 if (cmd.action == LFUN_CELL_FORWARD)
815 moveNextCell(bv, old_locking_inset != 0);
817 movePrevCell(bv, old_locking_inset != 0);
820 updateLocal(bv, SELECTION);
821 if (!the_locking_inset) {
822 return DISPATCHED_NOUPDATE;
825 // this to avoid compiler warnings.
831 kb_action action = cmd.action;
832 string arg = cmd.argument;
833 if (the_locking_inset) {
834 result = the_locking_inset->localDispatch(cmd);
835 if (result == DISPATCHED_NOUPDATE) {
838 if (sc != scroll()) { // inset has been scrolled
839 updateLocal(bv, FULL);
842 } else if (result == DISPATCHED) {
843 updateLocal(bv, CELL);
845 } else if (result == FINISHED_UP) {
847 // Make sure to reset status message after
848 // exiting, e.g. math inset
849 bv->owner()->clearMessage();
850 } else if (result == FINISHED_DOWN) {
852 bv->owner()->clearMessage();
853 } else if (result == FINISHED_RIGHT) {
855 bv->owner()->clearMessage();
856 } else if (result == FINISHED) {
857 bv->owner()->clearMessage();
863 // --- Cursor Movements ----------------------------------
864 case LFUN_RIGHTSEL: {
865 int const start = hasSelection() ? sel_cell_start : actcell;
866 if (tabular.isLastCellInRow(actcell)) {
867 setSelection(start, actcell);
872 // if we are starting a selection, only select
873 // the current cell at the beginning
874 if (hasSelection()) {
875 moveRight(bv, false);
878 setSelection(start, end);
879 updateLocal(bv, SELECTION);
883 result = moveRight(bv);
886 updateLocal(bv, SELECTION);
889 int const start = hasSelection() ? sel_cell_start : actcell;
890 if (tabular.isFirstCellInRow(actcell)) {
891 setSelection(start, actcell);
896 // if we are starting a selection, only select
897 // the current cell at the beginning
898 if (hasSelection()) {
902 setSelection(start, end);
903 updateLocal(bv, SELECTION);
907 result = moveLeft(bv);
910 updateLocal(bv, SELECTION);
913 int const start = hasSelection() ? sel_cell_start : actcell;
914 int const ocell = actcell;
915 // if we are starting a selection, only select
916 // the current cell at the beginning
917 if (hasSelection()) {
919 if ((ocell == sel_cell_end) ||
920 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
921 setSelection(start, tabular.getCellBelow(sel_cell_end));
923 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
925 setSelection(start, start);
927 updateLocal(bv, SELECTION);
931 result = moveDown(bv, old_locking_inset != 0);
934 updateLocal(bv, SELECTION);
938 int const start = hasSelection() ? sel_cell_start : actcell;
939 int const ocell = actcell;
940 // if we are starting a selection, only select
941 // the current cell at the beginning
942 if (hasSelection()) {
944 if ((ocell == sel_cell_end) ||
945 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
946 setSelection(start, tabular.getCellAbove(sel_cell_end));
948 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
950 setSelection(start, start);
952 updateLocal(bv, SELECTION);
956 result = moveUp(bv, old_locking_inset != 0);
959 updateLocal(bv, SELECTION);
962 UpdateCodes code = CURSOR;
968 unlockInsetInInset(bv, the_locking_inset);
969 if (bv->text->top_y() + bv->painter().paperHeight() <
970 (top_baseline + tabular.getHeightOfTabular()))
972 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
974 actcell = tabular.getCellBelow(first_visible_cell) + column;
976 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
979 updateLocal(bv, code);
983 UpdateCodes code = CURSOR;
989 unlockInsetInInset(bv, the_locking_inset);
990 if (top_baseline < 0) {
991 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
993 if (top_baseline > 0)
996 actcell = tabular.getCellBelow(first_visible_cell) + column;
1001 updateLocal(bv, code);
1004 // none of these make sense for insettabular,
1005 // but we must catch them to prevent any
1006 // selection from being confused
1010 case LFUN_WORDLEFTSEL:
1011 case LFUN_WORDRIGHT:
1012 case LFUN_WORDRIGHTSEL:
1014 case LFUN_DOWN_PARAGRAPH:
1015 case LFUN_DOWN_PARAGRAPHSEL:
1016 case LFUN_UP_PARAGRAPH:
1017 case LFUN_UP_PARAGRAPHSEL:
1018 case LFUN_BACKSPACE:
1023 case LFUN_BEGINNINGBUF:
1024 case LFUN_BEGINNINGBUFSEL:
1026 case LFUN_ENDBUFSEL:
1028 case LFUN_LAYOUT_TABULAR: {
1029 InsetTabularMailer mailer(*this);
1030 mailer.showDialog(bv);
1033 case LFUN_INSET_DIALOG_UPDATE: {
1034 InsetTabularMailer mailer(*this);
1035 mailer.updateDialog(bv);
1038 case LFUN_TABULAR_FEATURE:
1039 if (!tabularFeatures(bv, arg))
1040 result = UNDISPATCHED;
1042 // insert file functions
1043 case LFUN_FILE_INSERT_ASCII_PARA:
1044 case LFUN_FILE_INSERT_ASCII:
1046 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1049 if (insertAsciiString(bv, tmpstr, false))
1050 updateLocal(bv, INIT);
1052 result = UNDISPATCHED;
1055 // cut and paste functions
1057 if (!copySelection(bv))
1061 setUndo(bv, Undo::DELETE);
1062 cutSelection(bv->buffer()->params);
1063 updateLocal(bv, INIT);
1066 if (!hasSelection())
1071 case LFUN_PASTESELECTION:
1073 string const clip(bv->getClipboard());
1077 if (clip.find('\t') != string::npos) {
1081 string::size_type len = clip.length();
1082 string::size_type p = 0;
1085 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1093 maxCols = max(cols, maxCols);
1099 maxCols = max(cols, maxCols);
1100 delete paste_tabular;
1101 paste_tabular = new LyXTabular(bv->buffer()->params,
1102 this, rows, maxCols);
1103 string::size_type op = 0;
1105 int cells = paste_tabular->getNumberOfCells();
1107 while ((cell < cells) && (p < len) &&
1108 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1113 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1118 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1119 while (cols++ < maxCols)
1127 // check for the last cell if there is no trailing '\n'
1128 if ((cell < cells) && (op < len))
1129 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1132 if (!insertAsciiString(bv, clip, true))
1135 // so that the clipboard is used and it goes on
1137 // and executes LFUN_PASTESELECTION in insettext!
1138 delete paste_tabular;
1143 if (hasPasteBuffer()) {
1144 setUndo(bv, Undo::INSERT);
1146 updateLocal(bv, INIT);
1149 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1151 // handle font changing stuff on selection before we lock the inset
1152 // in the default part!
1153 result = UNDISPATCHED;
1164 case LFUN_UNDERLINE:
1165 case LFUN_FONT_SIZE:
1166 if (bv->dispatch(FuncRequest(bv, action, arg)))
1167 result = DISPATCHED;
1173 // we try to activate the actual inset and put this event down to
1174 // the insets dispatch function.
1175 if ((result == DISPATCHED) || the_locking_inset)
1178 if (activateCellInset(bv)) {
1179 // reset need_update setted in above function!
1181 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1182 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1183 unlockInsetInInset(bv, the_locking_inset);
1185 // we need to update if this was requested before
1186 updateLocal(bv, NONE);
1187 return UNDISPATCHED;
1190 // so the below CELL is not set because this is higher
1191 // priority and we get a full redraw
1192 need_update = SELECTION;
1195 updateLocal(bv, CELL);
1200 if (result < FINISHED) {
1201 if (!the_locking_inset) {
1202 if (bv->fitCursor())
1203 updateLocal(bv, FULL);
1206 bv->unlockInset(this);
1211 int InsetTabular::latex(Buffer const * buf, ostream & os,
1212 LatexRunParams const & runparams) const
1214 return tabular.latex(buf, os, runparams);
1218 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1221 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1223 return tabular.ascii(buf, os, 0, false,0);
1227 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1230 int const ret = tabular.ascii(buf,os,
1231 (int)parOwner()->params().depth(),
1238 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1243 // if the table is inside a float it doesn't need the informaltable
1244 // wrapper. Search for it.
1245 for(master = owner();
1246 master && master->lyxCode() != Inset::FLOAT_CODE;
1247 master = master->owner());
1250 os << "<informaltable>";
1255 ret+= tabular.docbook(buf, os, mixcont);
1257 os << "</informaltable>";
1266 void InsetTabular::validate(LaTeXFeatures & features) const
1268 tabular.validate(features);
1272 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1278 bool changed = false;
1280 // FIXME: since InsetText ignores this anyway, it doesn't
1281 // matter what we pass it. Ugly
1284 // if we have a locking_inset we should have to check only this cell for
1285 // change so I'll try this to have a boost, but who knows ;)
1286 if ((need_update != INIT) &&
1287 (the_locking_inset == tabular.getCellInset(actcell))) {
1288 for(int i = 0; i < tabular.columns(); ++i) {
1289 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1291 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1294 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1295 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1296 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1299 for (int i = 0; i < tabular.rows(); ++i) {
1302 for (int j = 0; j < tabular.columns(); ++j) {
1303 if (tabular.isPartOfMultiColumn(i,j))
1306 inset = tabular.getCellInset(cell);
1307 if (!reinit && !tabular.getPWidth(cell).zero())
1308 inset->update(bv, false);
1309 maxAsc = max(maxAsc, inset->ascent(bv, font));
1310 maxDesc = max(maxDesc, inset->descent(bv, font));
1311 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1313 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1314 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1322 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1324 if (the_locking_inset) {
1325 the_locking_inset->getCursor(bv, x, y);
1330 y = cursor_.y() + InsetTabular::y();
1333 int desc = tabular.getDescentOfRow(actrow);
1335 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1337 y += ADD_TO_HEIGHT * 2;
1338 y += TEXT_TO_INSET_OFFSET;
1342 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1344 if (the_locking_inset) {
1345 the_locking_inset->getCursorPos(bv, x, y);
1348 x = cursor_.x() - top_x;
1353 void InsetTabular::fitInsetCursor(BufferView * bv) const
1355 if (the_locking_inset) {
1356 int old_top_y = bv->text->top_y();
1357 the_locking_inset->fitInsetCursor(bv);
1358 if (old_top_y != bv->text->top_y())
1364 int const asc = font_metrics::maxAscent(font);
1365 int const desc = font_metrics::maxDescent(font);
1368 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1373 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1377 actcell = actrow = actcol = 0;
1378 int ly = tabular.getDescentOfRow(actrow);
1380 // first search the right row
1381 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1382 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1383 tabular.getAscentOfRow(actrow + 1) +
1384 tabular.getAdditionalHeight(actrow + 1));
1386 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1388 actcell = tabular.getCellNumber(actrow, actcol);
1390 // now search the right column
1391 int lx = tabular.getWidthOfColumn(actcell) -
1392 tabular.getAdditionalWidth(actcell);
1393 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1394 lx += tabular.getWidthOfColumn(actcell + 1)
1395 + tabular.getAdditionalWidth(actcell);
1397 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1402 int InsetTabular::getCellXPos(int cell) const
1406 for (; !tabular.isFirstCellInRow(c); --c)
1408 int lx = tabular.getWidthOfColumn(cell);
1409 for (; c < cell; ++c) {
1410 lx += tabular.getWidthOfColumn(c);
1412 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1416 void InsetTabular::resetPos(BufferView * bv) const
1418 #ifdef WITH_WARNINGS
1419 #warning This should be fixed in the right manner (20011128 Jug)
1421 // fast hack to fix infinite repaintings!
1422 if (in_reset_pos > 0)
1426 actcol = tabular.column_of_cell(actcell);
1429 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1430 if (tabular.isLastCellInRow(cell)) {
1431 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1432 tabular.getAscentOfRow(actrow + 1) +
1433 tabular.getAdditionalHeight(actrow + 1));
1437 if (!locked || nodraw()) {
1438 if (the_locking_inset)
1439 inset_y = cursor_.y();
1442 // we need this only from here on!!!
1444 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1445 int new_x = getCellXPos(actcell);
1446 int old_x = cursor_.x();
1449 // cursor.x(getCellXPos(actcell) + offset);
1450 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1451 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1454 updateLocal(bv, FULL);
1455 } else if (the_locking_inset &&
1456 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1458 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1459 if (xx > (bv->workWidth()-20)) {
1460 scroll(bv, -(xx - bv->workWidth() + 60));
1461 updateLocal(bv, FULL);
1462 } else if (xx < 20) {
1468 updateLocal(bv, FULL);
1470 } else if ((cursor_.x() - offset) > 20 &&
1471 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1472 > (bv->workWidth() - 20)) {
1473 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1474 updateLocal(bv, FULL);
1475 } else if ((cursor_.x() - offset) < 20) {
1476 scroll(bv, 20 - cursor_.x() + offset);
1477 updateLocal(bv, FULL);
1478 } else if (scroll() && top_x > 20 &&
1479 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1480 scroll(bv, old_x - cursor_.x());
1481 updateLocal(bv, FULL);
1483 if (the_locking_inset) {
1484 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1485 inset_y = cursor_.y();
1487 if ((!the_locking_inset ||
1488 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1489 actcell != oldcell) {
1490 InsetTabular * inset = const_cast<InsetTabular *>(this);
1491 InsetTabularMailer mailer(*inset);
1492 mailer.updateDialog(bv);
1499 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1501 if (lock && !old_locking_inset) {
1502 if (activateCellInset(bv))
1505 bool moved = isRightToLeft(bv)
1506 ? movePrevCell(bv) : moveNextCell(bv);
1508 return FINISHED_RIGHT;
1509 if (lock && activateCellInset(bv))
1513 return DISPATCHED_NOUPDATE;
1517 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1519 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1522 if (lock) { // behind the inset
1523 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1527 return DISPATCHED_NOUPDATE;
1531 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1533 int const ocell = actcell;
1534 actcell = tabular.getCellAbove(actcell);
1535 if (actcell == ocell) // we moved out of the inset
1541 if (old_locking_inset) {
1542 old_locking_inset->getCursorPos(bv, x, y);
1543 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1545 if (activateCellInset(bv, x, 0))
1548 return DISPATCHED_NOUPDATE;
1552 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1554 int const ocell = actcell;
1555 actcell = tabular.getCellBelow(actcell);
1556 if (actcell == ocell) // we moved out of the inset
1557 return FINISHED_DOWN;
1562 if (old_locking_inset) {
1563 old_locking_inset->getCursorPos(bv, x, y);
1564 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1566 if (activateCellInset(bv, x, 0))
1569 return DISPATCHED_NOUPDATE;
1573 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1575 if (isRightToLeft(bv)) {
1576 if (tabular.isFirstCellInRow(actcell)) {
1577 int row = tabular.row_of_cell(actcell);
1578 if (row == tabular.rows() - 1)
1580 actcell = tabular.getLastCellInRow(row);
1581 actcell = tabular.getCellBelow(actcell);
1588 if (tabular.isLastCell(actcell))
1593 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1594 isRightToLeftPar(bv->buffer()->params);
1595 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1602 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1604 if (isRightToLeft(bv)) {
1605 if (tabular.isLastCellInRow(actcell)) {
1606 int row = tabular.row_of_cell(actcell);
1609 actcell = tabular.getFirstCellInRow(row);
1610 actcell = tabular.getCellAbove(actcell);
1612 if (tabular.isLastCell(actcell))
1617 if (!actcell) // first cell
1622 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1623 isRightToLeftPar(bv->buffer()->params);
1624 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1631 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1635 setSelection(0, tabular.getNumberOfCells() - 1);
1637 if (hasSelection()) {
1638 setUndo(bv, Undo::EDIT);
1639 bool const frozen = undo_frozen;
1642 // apply the fontchange on the whole selection
1647 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1648 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1649 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1650 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1657 updateLocal(bv, INIT);
1659 if (the_locking_inset)
1660 the_locking_inset->setFont(bv, font, tall);
1664 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1666 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1669 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1670 string const tmp = tabularFeature[i].feature;
1672 if (tmp == what.substr(0, tmp.length())) {
1673 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1674 //tabularFeatures[i].feature.length())) {
1675 action = tabularFeature[i].action;
1679 if (action == LyXTabular::LAST_ACTION)
1683 ltrim(what.substr(tabularFeature[i].feature.length()));
1684 tabularFeatures(bv, action, val);
1690 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1691 string const & special, bool & flag)
1693 if (special == "dl_above") {
1696 } else if (special == "dl_below") {
1697 ltt.bottomDL = flag;
1699 } else if (special == "empty") {
1711 void InsetTabular::tabularFeatures(BufferView * bv,
1712 LyXTabular::Feature feature,
1713 string const & value)
1719 bool setLines = false;
1720 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1721 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1724 case LyXTabular::M_ALIGN_LEFT:
1725 case LyXTabular::ALIGN_LEFT:
1726 setAlign = LYX_ALIGN_LEFT;
1728 case LyXTabular::M_ALIGN_RIGHT:
1729 case LyXTabular::ALIGN_RIGHT:
1730 setAlign = LYX_ALIGN_RIGHT;
1732 case LyXTabular::M_ALIGN_CENTER:
1733 case LyXTabular::ALIGN_CENTER:
1734 setAlign = LYX_ALIGN_CENTER;
1736 case LyXTabular::ALIGN_BLOCK:
1737 setAlign = LYX_ALIGN_BLOCK;
1739 case LyXTabular::M_VALIGN_TOP:
1740 case LyXTabular::VALIGN_TOP:
1741 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1743 case LyXTabular::M_VALIGN_BOTTOM:
1744 case LyXTabular::VALIGN_BOTTOM:
1745 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1747 case LyXTabular::M_VALIGN_CENTER:
1748 case LyXTabular::VALIGN_CENTER:
1749 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1754 if (hasSelection()) {
1755 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1757 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1758 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1760 setUndo(bv, Undo::FINISH);
1762 int row = tabular.row_of_cell(actcell);
1763 int column = tabular.column_of_cell(actcell);
1765 LyXTabular::ltType ltt;
1768 case LyXTabular::SET_PWIDTH:
1770 LyXLength const vallen(value);
1771 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1773 bool const update = (tmplen != vallen);
1774 tabular.setColumnPWidth(actcell, vallen);
1776 // We need this otherwise we won't resize
1777 // the insettext of the active cell (if any)
1778 // until later (see InsetText::do_resize)
1779 unlockInsetInInset(bv, the_locking_inset);
1782 for (int i = 0; i < tabular.rows(); ++i) {
1783 cell = tabular.getCellNumber(i,column);
1784 tabular.getCellInset(cell)->resizeLyXText(bv);
1786 updateLocal(bv, INIT);
1790 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1791 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1792 else if (!vallen.zero()
1793 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1794 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1797 case LyXTabular::SET_MPWIDTH:
1799 LyXLength const vallen(value);
1800 LyXLength const & tmplen = tabular.getPWidth(actcell);
1802 bool const update = (tmplen != vallen);
1803 tabular.setMColumnPWidth(actcell, vallen);
1805 // We need this otherwise we won't resize
1806 // the insettext of the active cell (if any)
1807 // until later (see InsetText::do_resize)
1808 unlockInsetInInset(bv, the_locking_inset);
1810 for (int i = 0; i < tabular.rows(); ++i) {
1811 tabular.getCellInset(tabular.getCellNumber(i, column))->
1814 updateLocal(bv, INIT);
1818 case LyXTabular::SET_SPECIAL_COLUMN:
1819 case LyXTabular::SET_SPECIAL_MULTI:
1820 tabular.setAlignSpecial(actcell,value,feature);
1821 updateLocal(bv, FULL);
1823 case LyXTabular::APPEND_ROW:
1824 // append the row into the tabular
1825 unlockInsetInInset(bv, the_locking_inset);
1826 tabular.appendRow(bv->buffer()->params, actcell);
1827 updateLocal(bv, INIT);
1829 case LyXTabular::APPEND_COLUMN:
1830 // append the column into the tabular
1831 unlockInsetInInset(bv, the_locking_inset);
1832 tabular.appendColumn(bv->buffer()->params, actcell);
1833 actcell = tabular.getCellNumber(row, column);
1834 updateLocal(bv, INIT);
1836 case LyXTabular::DELETE_ROW:
1837 unlockInsetInInset(bv, the_locking_inset);
1838 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1839 tabular.deleteRow(sel_row_start);
1841 if (sel_row_start >= tabular.rows())
1843 actcell = tabular.getCellNumber(sel_row_start, column);
1845 updateLocal(bv, INIT);
1847 case LyXTabular::DELETE_COLUMN:
1848 unlockInsetInInset(bv, the_locking_inset);
1849 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1850 tabular.deleteColumn(sel_col_start);
1852 if (sel_col_start >= tabular.columns())
1854 actcell = tabular.getCellNumber(row, sel_col_start);
1856 updateLocal(bv, INIT);
1858 case LyXTabular::M_TOGGLE_LINE_TOP:
1860 case LyXTabular::TOGGLE_LINE_TOP:
1862 bool lineSet = !tabular.topLine(actcell, flag);
1863 for (int i = sel_row_start; i <= sel_row_end; ++i)
1864 for (int j = sel_col_start; j <= sel_col_end; ++j)
1866 tabular.getCellNumber(i, j),
1868 updateLocal(bv, INIT);
1872 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1874 case LyXTabular::TOGGLE_LINE_BOTTOM:
1876 bool lineSet = !tabular.bottomLine(actcell, flag);
1877 for (int i = sel_row_start; i <= sel_row_end; ++i)
1878 for (int j = sel_col_start; j <= sel_col_end; ++j)
1879 tabular.setBottomLine(
1880 tabular.getCellNumber(i, j),
1883 updateLocal(bv, INIT);
1887 case LyXTabular::M_TOGGLE_LINE_LEFT:
1889 case LyXTabular::TOGGLE_LINE_LEFT:
1891 bool lineSet = !tabular.leftLine(actcell, flag);
1892 for (int i = sel_row_start; i <= sel_row_end; ++i)
1893 for (int j = sel_col_start; j <= sel_col_end; ++j)
1894 tabular.setLeftLine(
1895 tabular.getCellNumber(i,j),
1898 updateLocal(bv, INIT);
1902 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1904 case LyXTabular::TOGGLE_LINE_RIGHT:
1906 bool lineSet = !tabular.rightLine(actcell, flag);
1907 for (int i = sel_row_start; i <= sel_row_end; ++i)
1908 for (int j = sel_col_start; j <= sel_col_end; ++j)
1909 tabular.setRightLine(
1910 tabular.getCellNumber(i,j),
1913 updateLocal(bv, INIT);
1917 case LyXTabular::M_ALIGN_LEFT:
1918 case LyXTabular::M_ALIGN_RIGHT:
1919 case LyXTabular::M_ALIGN_CENTER:
1921 case LyXTabular::ALIGN_LEFT:
1922 case LyXTabular::ALIGN_RIGHT:
1923 case LyXTabular::ALIGN_CENTER:
1924 case LyXTabular::ALIGN_BLOCK:
1925 for (int i = sel_row_start; i <= sel_row_end; ++i)
1926 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular.setAlignment(
1928 tabular.getCellNumber(i, j),
1931 updateLocal(bv, INIT);
1933 case LyXTabular::M_VALIGN_TOP:
1934 case LyXTabular::M_VALIGN_BOTTOM:
1935 case LyXTabular::M_VALIGN_CENTER:
1937 case LyXTabular::VALIGN_TOP:
1938 case LyXTabular::VALIGN_BOTTOM:
1939 case LyXTabular::VALIGN_CENTER:
1940 for (int i = sel_row_start; i <= sel_row_end; ++i)
1941 for (int j = sel_col_start; j <= sel_col_end; ++j)
1942 tabular.setVAlignment(
1943 tabular.getCellNumber(i, j),
1945 updateLocal(bv, INIT);
1947 case LyXTabular::MULTICOLUMN:
1949 if (sel_row_start != sel_row_end) {
1950 #ifdef WITH_WARNINGS
1951 #warning Need I say it ? This is horrible.
1953 Alert::error(_("Error setting multicolumn"),
1954 _("You cannot set multicolumn vertically."));
1957 // just multicol for one Single Cell
1958 if (!hasSelection()) {
1959 // check wether we are completly in a multicol
1960 if (tabular.isMultiColumn(actcell)) {
1961 tabular.unsetMultiColumn(actcell);
1962 updateLocal(bv, INIT);
1964 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1965 updateLocal(bv, CELL);
1969 // we have a selection so this means we just add all this
1970 // cells to form a multicolumn cell
1974 if (sel_cell_start > sel_cell_end) {
1975 s_start = sel_cell_end;
1976 s_end = sel_cell_start;
1978 s_start = sel_cell_start;
1979 s_end = sel_cell_end;
1981 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1984 updateLocal(bv, INIT);
1987 case LyXTabular::SET_ALL_LINES:
1989 case LyXTabular::UNSET_ALL_LINES:
1990 for (int i = sel_row_start; i <= sel_row_end; ++i)
1991 for (int j = sel_col_start; j <= sel_col_end; ++j)
1992 tabular.setAllLines(
1993 tabular.getCellNumber(i,j), setLines);
1994 updateLocal(bv, INIT);
1996 case LyXTabular::SET_LONGTABULAR:
1997 tabular.setLongTabular(true);
1998 updateLocal(bv, INIT); // because this toggles displayed
2000 case LyXTabular::UNSET_LONGTABULAR:
2001 tabular.setLongTabular(false);
2002 updateLocal(bv, INIT); // because this toggles displayed
2004 case LyXTabular::SET_ROTATE_TABULAR:
2005 tabular.setRotateTabular(true);
2007 case LyXTabular::UNSET_ROTATE_TABULAR:
2008 tabular.setRotateTabular(false);
2010 case LyXTabular::SET_ROTATE_CELL:
2011 for (int i = sel_row_start; i <= sel_row_end; ++i)
2012 for (int j = sel_col_start; j<=sel_col_end; ++j)
2013 tabular.setRotateCell(
2014 tabular.getCellNumber(i, j),
2017 case LyXTabular::UNSET_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), false);
2023 case LyXTabular::SET_USEBOX:
2025 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2026 if (val == tabular.getUsebox(actcell))
2027 val = LyXTabular::BOX_NONE;
2028 for (int i = sel_row_start; i <= sel_row_end; ++i)
2029 for (int j = sel_col_start; j <= sel_col_end; ++j)
2031 tabular.getCellNumber(i, j), val);
2034 case LyXTabular::UNSET_LTFIRSTHEAD:
2036 case LyXTabular::SET_LTFIRSTHEAD:
2037 (void)tabular.getRowOfLTFirstHead(row, ltt);
2038 checkLongtableSpecial(ltt, value, flag);
2039 tabular.setLTHead(row, flag, ltt, true);
2041 case LyXTabular::UNSET_LTHEAD:
2043 case LyXTabular::SET_LTHEAD:
2044 (void)tabular.getRowOfLTHead(row, ltt);
2045 checkLongtableSpecial(ltt, value, flag);
2046 tabular.setLTHead(row, flag, ltt, false);
2048 case LyXTabular::UNSET_LTFOOT:
2050 case LyXTabular::SET_LTFOOT:
2051 (void)tabular.getRowOfLTFoot(row, ltt);
2052 checkLongtableSpecial(ltt, value, flag);
2053 tabular.setLTFoot(row, flag, ltt, false);
2055 case LyXTabular::UNSET_LTLASTFOOT:
2057 case LyXTabular::SET_LTLASTFOOT:
2058 (void)tabular.getRowOfLTLastFoot(row, ltt);
2059 checkLongtableSpecial(ltt, value, flag);
2060 tabular.setLTFoot(row, flag, ltt, true);
2062 case LyXTabular::SET_LTNEWPAGE:
2064 bool what = !tabular.getLTNewPage(row);
2065 tabular.setLTNewPage(row, what);
2068 // dummy stuff just to avoid warnings
2069 case LyXTabular::LAST_ACTION:
2073 InsetTabularMailer mailer(*this);
2074 mailer.updateDialog(bv);
2078 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2081 UpdatableInset * inset =
2082 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2083 LyXFont font(LyXFont::ALL_SANE);
2085 x = inset->x() + inset->width(bv, font);
2086 y = inset->descent(bv, font);
2088 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2089 //inset_y = cursor.y();
2090 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2091 if (!the_locking_inset)
2093 updateLocal(bv, CELL);
2094 return (the_locking_inset != 0);
2098 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2099 mouse_button::state button)
2101 inset_x = cursor_.x()
2102 - top_x + tabular.getBeginningOfTextInCell(actcell);
2103 inset_y = cursor_.y();
2104 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2108 bool InsetTabular::insetHit(BufferView *, int x, int) const
2111 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2115 // This returns paperWidth() if the cell-width is unlimited or the width
2116 // in pixels if we have a pwidth for this cell.
2117 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2119 LyXLength const len = tabular.getPWidth(cell);
2123 return len.inPixels(latexTextWidth(bv));
2127 int InsetTabular::getMaxWidth(BufferView * bv,
2128 UpdatableInset const * inset) const
2130 int cell = tabular.getCellFromInset(inset, actcell);
2133 lyxerr << "Own inset not found, shouldn't really happen!"
2138 int w = getMaxWidthOfCell(bv, cell);
2140 // because the inset then subtracts it's top_x and owner->x()
2141 w += (inset->x() - top_x);
2148 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2150 resizeLyXText(bv, recursive);
2154 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2157 for(int i = 0; i < tabular.rows(); ++i) {
2158 for(int j = 0; j < tabular.columns(); ++j) {
2159 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2167 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2168 bool const recursive) const
2170 if (the_locking_inset)
2171 return the_locking_inset->getLyXText(bv, recursive);
2173 // if we're locked lock the actual insettext and return it's LyXText!!!
2175 UpdatableInset * inset =
2176 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2177 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2178 return the_locking_inset->getLyXText(bv, recursive);
2181 return Inset::getLyXText(bv, recursive);
2185 bool InsetTabular::showInsetDialog(BufferView * bv) const
2187 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2188 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2189 InsetTabularMailer mailer(*tmp);
2190 mailer.showDialog(bv);
2196 void InsetTabular::openLayoutDialog(BufferView * bv) const
2198 if (the_locking_inset) {
2199 InsetTabular * i = static_cast<InsetTabular *>
2200 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2202 i->openLayoutDialog(bv);
2206 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2207 InsetTabularMailer mailer(*tmp);
2208 mailer.showDialog(bv);
2213 // function returns an object as defined in func_status.h:
2214 // states OK, Unknown, Disabled, On, Off.
2216 FuncStatus InsetTabular::getStatus(string const & what) const
2218 int action = LyXTabular::LAST_ACTION;
2222 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2223 string const tmp = tabularFeature[i].feature;
2224 if (tmp == what.substr(0, tmp.length())) {
2225 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2226 // tabularFeatures[i].feature.length())) {
2227 action = tabularFeature[i].action;
2231 if (action == LyXTabular::LAST_ACTION) {
2233 return status.unknown(true);
2236 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2241 LyXTabular::ltType dummyltt;
2244 if (hasSelection()) {
2245 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2247 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2251 case LyXTabular::SET_PWIDTH:
2252 case LyXTabular::SET_MPWIDTH:
2253 case LyXTabular::SET_SPECIAL_COLUMN:
2254 case LyXTabular::SET_SPECIAL_MULTI:
2255 case LyXTabular::APPEND_ROW:
2256 case LyXTabular::APPEND_COLUMN:
2257 case LyXTabular::DELETE_ROW:
2258 case LyXTabular::DELETE_COLUMN:
2259 case LyXTabular::SET_ALL_LINES:
2260 case LyXTabular::UNSET_ALL_LINES:
2261 return status.clear();
2263 case LyXTabular::MULTICOLUMN:
2264 status.setOnOff(tabular.isMultiColumn(actcell));
2266 case LyXTabular::M_TOGGLE_LINE_TOP:
2268 case LyXTabular::TOGGLE_LINE_TOP:
2269 status.setOnOff(tabular.topLine(actcell, flag));
2271 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2273 case LyXTabular::TOGGLE_LINE_BOTTOM:
2274 status.setOnOff(tabular.bottomLine(actcell, flag));
2276 case LyXTabular::M_TOGGLE_LINE_LEFT:
2278 case LyXTabular::TOGGLE_LINE_LEFT:
2279 status.setOnOff(tabular.leftLine(actcell, flag));
2281 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2283 case LyXTabular::TOGGLE_LINE_RIGHT:
2284 status.setOnOff(tabular.rightLine(actcell, flag));
2286 case LyXTabular::M_ALIGN_LEFT:
2288 case LyXTabular::ALIGN_LEFT:
2289 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2291 case LyXTabular::M_ALIGN_RIGHT:
2293 case LyXTabular::ALIGN_RIGHT:
2294 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2296 case LyXTabular::M_ALIGN_CENTER:
2298 case LyXTabular::ALIGN_CENTER:
2299 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2301 case LyXTabular::ALIGN_BLOCK:
2302 status.disabled(tabular.getPWidth(actcell).zero());
2303 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2305 case LyXTabular::M_VALIGN_TOP:
2307 case LyXTabular::VALIGN_TOP:
2308 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2310 case LyXTabular::M_VALIGN_BOTTOM:
2312 case LyXTabular::VALIGN_BOTTOM:
2313 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2315 case LyXTabular::M_VALIGN_CENTER:
2317 case LyXTabular::VALIGN_CENTER:
2318 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2320 case LyXTabular::SET_LONGTABULAR:
2321 status.setOnOff(tabular.isLongTabular());
2323 case LyXTabular::UNSET_LONGTABULAR:
2324 status.setOnOff(!tabular.isLongTabular());
2326 case LyXTabular::SET_ROTATE_TABULAR:
2327 status.setOnOff(tabular.getRotateTabular());
2329 case LyXTabular::UNSET_ROTATE_TABULAR:
2330 status.setOnOff(!tabular.getRotateTabular());
2332 case LyXTabular::SET_ROTATE_CELL:
2333 status.setOnOff(tabular.getRotateCell(actcell));
2335 case LyXTabular::UNSET_ROTATE_CELL:
2336 status.setOnOff(!tabular.getRotateCell(actcell));
2338 case LyXTabular::SET_USEBOX:
2339 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2341 case LyXTabular::SET_LTFIRSTHEAD:
2342 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2344 case LyXTabular::SET_LTHEAD:
2345 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2347 case LyXTabular::SET_LTFOOT:
2348 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2350 case LyXTabular::SET_LTLASTFOOT:
2351 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2353 case LyXTabular::SET_LTNEWPAGE:
2354 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2358 status.disabled(true);
2365 void InsetTabular::getLabelList(std::vector<string> & list) const
2367 tabular.getLabelList(list);
2371 bool InsetTabular::copySelection(BufferView * bv)
2373 if (!hasSelection())
2376 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2377 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2378 if (sel_col_start > sel_col_end) {
2379 sel_col_start = sel_col_end;
2380 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2382 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2384 int const columns = sel_col_end - sel_col_start + 1;
2386 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2387 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2388 if (sel_row_start > sel_row_end) {
2389 swap(sel_row_start, sel_row_end);
2391 int const rows = sel_row_end - sel_row_start + 1;
2393 delete paste_tabular;
2394 paste_tabular = new LyXTabular(bv->buffer()->params,
2395 this, tabular); // rows, columns);
2396 for (int i = 0; i < sel_row_start; ++i)
2397 paste_tabular->deleteRow(0);
2398 while (paste_tabular->rows() > rows)
2399 paste_tabular->deleteRow(rows);
2400 paste_tabular->setTopLine(0, true, true);
2401 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2403 for (int i = 0; i < sel_col_start; ++i)
2404 paste_tabular->deleteColumn(0);
2405 while (paste_tabular->columns() > columns)
2406 paste_tabular->deleteColumn(columns);
2407 paste_tabular->setLeftLine(0, true, true);
2408 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2412 paste_tabular->ascii(bv->buffer(), sstr,
2413 (int)parOwner()->params().depth(), true, '\t');
2414 bv->stuffClipboard(STRCONV(sstr.str()));
2419 bool InsetTabular::pasteSelection(BufferView * bv)
2424 for (int r1 = 0, r2 = actrow;
2425 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2427 for(int c1 = 0, c2 = actcol;
2428 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2430 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2431 tabular.isPartOfMultiColumn(r2,c2))
2433 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2437 if (tabular.isPartOfMultiColumn(r2,c2)) {
2441 int const n1 = paste_tabular->getCellNumber(r1, c1);
2442 int const n2 = tabular.getCellNumber(r2, c2);
2443 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2444 tabular.getCellInset(n2)->setOwner(this);
2445 tabular.getCellInset(n2)->deleteLyXText(bv);
2446 tabular.getCellInset(n2)->markNew();
2453 bool InsetTabular::cutSelection(BufferParams const & bp)
2455 if (!hasSelection())
2458 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2459 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2460 if (sel_col_start > sel_col_end) {
2461 sel_col_start = sel_col_end;
2462 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2464 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2466 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2467 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2468 if (sel_row_start > sel_row_end) {
2469 swap(sel_row_start, sel_row_end);
2471 if (sel_cell_start > sel_cell_end) {
2472 swap(sel_cell_start, sel_cell_end);
2474 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2475 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2476 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2483 bool InsetTabular::isRightToLeft(BufferView * bv)
2485 return bv->getParentLanguage(this)->RightToLeft();
2489 bool InsetTabular::nodraw() const
2491 if (!UpdatableInset::nodraw() && the_locking_inset)
2492 return the_locking_inset->nodraw();
2493 return UpdatableInset::nodraw();
2497 int InsetTabular::scroll(bool recursive) const
2499 int sx = UpdatableInset::scroll(false);
2501 if (recursive && the_locking_inset)
2502 sx += the_locking_inset->scroll(recursive);
2508 void InsetTabular::getSelection(int & srow, int & erow,
2509 int & scol, int & ecol) const
2511 int const start = hasSelection() ? sel_cell_start : actcell;
2512 int const end = hasSelection() ? sel_cell_end : actcell;
2514 srow = tabular.row_of_cell(start);
2515 erow = tabular.row_of_cell(end);
2520 scol = tabular.column_of_cell(start);
2521 ecol = tabular.column_of_cell(end);
2525 ecol = tabular.right_column_of_cell(end);
2530 ParagraphList * InsetTabular::getParagraphs(int i) const
2532 return (i < tabular.getNumberOfCells())
2533 ? tabular.getCellInset(i)->getParagraphs(0)
2538 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2540 if (the_locking_inset)
2541 return the_locking_inset->cursor(bv);
2542 return Inset::cursor(bv);
2546 Inset * InsetTabular::getInsetFromID(int id_arg) const
2549 return const_cast<InsetTabular *>(this);
2552 for(int i = 0; i < tabular.rows(); ++i) {
2553 for(int j = 0; j < tabular.columns(); ++j) {
2554 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2563 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2566 if (the_locking_inset) {
2567 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2568 if (!word.word().empty()) {
2572 if (tabular.isLastCell(actcell)) {
2573 bv->unlockInset(const_cast<InsetTabular *>(this));
2575 return WordLangTuple();
2579 // otherwise we have to lock the next inset and ask for it's selecttion
2580 UpdatableInset * inset =
2581 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2582 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2583 WordLangTuple word(selectNextWordInt(bv, value));
2585 if (!word.word().empty())
2591 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2593 // when entering this function the inset should be ALWAYS locked!
2594 Assert(the_locking_inset);
2596 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2597 if (!word.word().empty())
2600 if (tabular.isLastCell(actcell)) {
2601 bv->unlockInset(const_cast<InsetTabular *>(this));
2602 return WordLangTuple();
2605 // otherwise we have to lock the next inset and ask for it's selecttion
2606 UpdatableInset * inset =
2607 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2608 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2609 return selectNextWordInt(bv, value);
2613 void InsetTabular::selectSelectedWord(BufferView * bv)
2615 if (the_locking_inset) {
2616 the_locking_inset->selectSelectedWord(bv);
2623 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2625 if (the_locking_inset) {
2626 the_locking_inset->toggleSelection(bv, kill_selection);
2631 void InsetTabular::markErased()
2635 while (cell < tabular.getNumberOfCells()) {
2636 InsetText * inset = tabular.getCellInset(cell);
2637 inset->markErased();
2643 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2645 if (the_locking_inset) {
2646 if (the_locking_inset->nextChange(bv, length)) {
2647 updateLocal(bv, CELL);
2650 if (tabular.isLastCell(actcell))
2654 InsetText * inset = tabular.getCellInset(actcell);
2655 if (inset->nextChange(bv, length)) {
2656 updateLocal(bv, FULL);
2659 while (!tabular.isLastCell(actcell)) {
2661 inset = tabular.getCellInset(actcell);
2662 if (inset->nextChange(bv, length)) {
2663 updateLocal(bv, FULL);
2671 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2675 if (the_locking_inset) {
2676 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2677 updateLocal(bv, CELL);
2680 if (tabular.isLastCell(actcell))
2684 InsetText * inset = tabular.getCellInset(cell);
2685 if (inset->searchForward(bv, str, cs, mw)) {
2686 updateLocal(bv, FULL);
2689 while (!tabular.isLastCell(cell)) {
2691 inset = tabular.getCellInset(cell);
2692 if (inset->searchForward(bv, str, cs, mw)) {
2693 updateLocal(bv, FULL);
2701 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2704 int cell = tabular.getNumberOfCells();
2705 if (the_locking_inset) {
2706 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2707 updateLocal(bv, CELL);
2715 InsetText * inset = tabular.getCellInset(cell);
2716 if (inset->searchBackward(bv, str, cs, mw)) {
2717 updateLocal(bv, CELL);
2725 bool InsetTabular::insetAllowed(Inset::Code code) const
2727 if (the_locking_inset)
2728 return the_locking_inset->insetAllowed(code);
2729 // we return true here because if the inset is not locked someone
2730 // wants to insert something in one of our insettexts and we generally
2736 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2738 const int cell = tabular.getCellFromInset(in, actcell);
2741 return tabular.getPWidth(cell).zero();
2743 // well we didn't obviously find it so maybe our owner knows more
2745 return owner()->forceDefaultParagraphs(in);
2746 // if we're here there is really something strange going on!!!
2750 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2753 if (buf.length() <= 0)
2759 string::size_type len = buf.length();
2760 string::size_type p = 0;
2763 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2772 maxCols = max(cols, maxCols);
2778 maxCols = max(cols, maxCols);
2779 LyXTabular * loctab;
2784 delete paste_tabular;
2785 paste_tabular = new LyXTabular(bv->buffer()->params,
2786 this, rows, maxCols);
2787 loctab = paste_tabular;
2796 string::size_type op = 0;
2797 int cells = loctab->getNumberOfCells();
2800 rows = loctab->rows();
2801 int const columns = loctab->columns();
2803 while ((cell < cells) && (p < len) && (row < rows) &&
2804 (p = buf.find_first_of("\t\n", p)) != string::npos)
2810 // we can only set this if we are not too far right
2811 if (cols < columns) {
2812 InsetText * ti = loctab->getCellInset(cell);
2813 LyXFont const font = ti->getLyXText(bv)->
2814 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2815 ti->setText(buf.substr(op, p - op), font);
2821 // we can only set this if we are not too far right
2822 if (cols < columns) {
2823 InsetText * ti = loctab->getCellInset(cell);
2824 LyXFont const font = ti->getLyXText(bv)->
2825 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2826 ti->setText(buf.substr(op, p - op), font);
2831 cell = loctab->getCellNumber(row, cols);
2837 // check for the last cell if there is no trailing '\n'
2838 if ((cell < cells) && (op < len)) {
2839 InsetText * ti = loctab->getCellInset(cell);
2840 LyXFont const font = ti->getLyXText(bv)->
2841 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2842 ti->setText(buf.substr(op, len - op), font);
2849 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2851 int const rows = tabular.rows();
2852 int const columns = tabular.columns();
2853 for (int i = 0; i < rows; ++i) {
2854 for (int j = 0; j < columns; ++j) {
2855 tabular.getCellInset(i,j)->addPreview(loader);
2861 string const InsetTabularMailer:: name_("tabular");
2863 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2868 string const InsetTabularMailer::inset2string() const
2870 return params2string(inset_);
2874 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2876 istringstream data(STRCONV(in));
2878 lex.setStream(data);
2880 #warning CHECK verify that this is a sane value to return.
2886 string const token = lex.getString();
2894 string const token = lex.getString();
2895 if (token != "\\active_cell")
2898 cell = lex.getInteger();
2901 // This is part of the inset proper that is usually swallowed
2902 // by Buffer::readInset
2905 string const token = lex.getString();
2906 if (token != "Tabular")
2913 // FIXME: even current_view would be better than this.
2914 BufferView * const bv = inset.view();
2915 Buffer const * const buffer = bv ? bv->buffer() : 0;
2917 inset.read(buffer, lex);
2919 // We can't set the active cell, but we can tell the frontend
2925 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2927 // FIXME: even current_view would be better than this.
2928 BufferView * const bv = inset.view();
2929 Buffer const * const buffer = bv ? bv->buffer() : 0;
2934 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2935 inset.write(buffer, data);
2936 data << "\\end_inset\n";
2937 return STRCONV(data.str());