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"
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"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
126 bool operator()(TabularFeature & tf)
128 return tf.action == feature_;
131 LyXTabular::Feature feature_;
137 string const featureAsString(LyXTabular::Feature feature)
139 TabularFeature * it = tabularFeature;
140 TabularFeature * end = it +
141 sizeof(tabularFeature) / sizeof(TabularFeature);
142 it = std::find_if(it, end, FindFeature(feature));
143 return (it == end) ? string() : it->feature;
147 bool InsetTabular::hasPasteBuffer() const
149 return (paste_tabular != 0);
153 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
160 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
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, Buffer const & buf)
178 : UpdatableInset(tab), buffer(&buf)
180 tabular.reset(new LyXTabular(buf.params,
181 this, *(tab.tabular)));
182 the_locking_inset = 0;
183 old_locking_inset = 0;
186 actrow = actcell = 0;
196 // InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
198 // : UpdatableInset(tab, same_id), buffer(&buf)
200 // tabular.reset(new LyXTabular(buf.params,
201 // this, *(tab.tabular), same_id));
202 // the_locking_inset = 0;
203 // old_locking_inset = 0;
206 // actrow = actcell = 0;
208 // need_update = INIT;
209 // in_update = false;
216 InsetTabular::~InsetTabular()
218 InsetTabularMailer mailer(*this);
223 Inset * InsetTabular::clone(Buffer const & buf) const
225 return new InsetTabular(*this, buf);
229 // Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
231 // return new InsetTabular(*this, buf, same_id);
235 BufferView * InsetTabular::view() const
237 return buffer->getUser();
241 void InsetTabular::write(Buffer const * buf, ostream & os) const
243 os << " Tabular" << endl;
244 tabular->Write(buf, os);
248 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
250 bool const old_format = (lex.getString() == "\\LyXTable");
252 tabular.reset(new LyXTabular(buf, this, lex));
260 string token = lex.getString();
261 while (lex.isOK() && (token != "\\end_inset")) {
263 token = lex.getString();
265 if (token != "\\end_inset") {
266 lex.printError("Missing \\end_inset at this point. "
272 void InsetTabular::dimension(BufferView *, LyXFont const &,
273 Dimension & dim) const
275 dim.a = tabular->GetAscentOfRow(0);
276 dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
277 dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
281 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
289 Painter & pain = bv->painter();
295 UpdatableInset::draw(bv, font, baseline, x);
298 x += static_cast<float>(scroll());
302 top_baseline = baseline;
303 x += ADD_TO_TABULAR_WIDTH;
307 first_visible_cell = -1;
308 for (i = 0; i < tabular->rows(); ++i) {
310 cell = tabular->GetCellNumber(i, 0);
311 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
312 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
314 baseline += tabular->GetDescentOfRow(i) +
315 tabular->GetAscentOfRow(i + 1) +
316 tabular->GetAdditionalHeight(i + 1);
319 for (j = 0; j < tabular->columns(); ++j) {
320 if (nx > bv->workWidth())
322 if (tabular->IsPartOfMultiColumn(i, j))
324 cx = nx + tabular->GetBeginningOfTextInCell(cell);
325 if (first_visible_cell < 0)
326 first_visible_cell = cell;
327 if (hasSelection()) {
328 drawCellSelection(pain, nx, baseline, i, j, cell);
331 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
332 drawCellLines(pain, nx, baseline, i, cell);
333 nx += tabular->GetWidthOfColumn(cell);
336 baseline += tabular->GetDescentOfRow(i) +
337 tabular->GetAscentOfRow(i + 1) +
338 tabular->GetAdditionalHeight(i + 1);
341 x -= ADD_TO_TABULAR_WIDTH;
342 x += width(bv, font);
347 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
348 int row, int cell) const
350 int x2 = x + tabular->GetWidthOfColumn(cell);
353 if (!tabular->topAlreadyDrawn(cell)) {
354 on_off = !tabular->TopLine(cell);
355 pain.line(x, baseline - tabular->GetAscentOfRow(row),
356 x2, baseline - tabular->GetAscentOfRow(row),
357 on_off ? LColor::tabularonoffline : LColor::tabularline,
358 on_off ? Painter::line_onoffdash : Painter::line_solid);
360 on_off = !tabular->BottomLine(cell);
361 pain.line(x, baseline + tabular->GetDescentOfRow(row),
362 x2, baseline + tabular->GetDescentOfRow(row),
363 on_off ? LColor::tabularonoffline : LColor::tabularline,
364 on_off ? Painter::line_onoffdash : Painter::line_solid);
365 if (!tabular->leftAlreadyDrawn(cell)) {
366 on_off = !tabular->LeftLine(cell);
367 pain.line(x, baseline - tabular->GetAscentOfRow(row),
368 x, baseline + tabular->GetDescentOfRow(row),
369 on_off ? LColor::tabularonoffline : LColor::tabularline,
370 on_off ? Painter::line_onoffdash : Painter::line_solid);
372 on_off = !tabular->RightLine(cell);
373 pain.line(x2 - tabular->GetAdditionalWidth(cell),
374 baseline - tabular->GetAscentOfRow(row),
375 x2 - tabular->GetAdditionalWidth(cell),
376 baseline + tabular->GetDescentOfRow(row),
377 on_off ? LColor::tabularonoffline : LColor::tabularline,
378 on_off ? Painter::line_onoffdash : Painter::line_solid);
382 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
383 int row, int column, int cell) const
385 lyx::Assert(hasSelection());
386 int cs = tabular->column_of_cell(sel_cell_start);
387 int ce = tabular->column_of_cell(sel_cell_end);
390 cs = tabular->column_of_cell(sel_cell_end);
392 ce = tabular->right_column_of_cell(sel_cell_end);
395 int rs = tabular->row_of_cell(sel_cell_start);
396 int re = tabular->row_of_cell(sel_cell_end);
400 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
401 int w = tabular->GetWidthOfColumn(cell);
402 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
403 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
404 w, h, LColor::selection);
409 void InsetTabular::update(BufferView * bv, bool reinit)
415 owner()->update(bv, true);
422 if (calculate_dimensions_of_cells(bv, true))
425 owner()->update(bv, true);
429 if (the_locking_inset)
430 the_locking_inset->update(bv, reinit);
431 if (need_update < FULL &&
432 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
437 switch (need_update) {
441 if (calculate_dimensions_of_cells(bv, false)) {
456 string const InsetTabular::editMessage() const
458 return _("Opened table");
462 void InsetTabular::insetUnlock(BufferView * bv)
464 if (the_locking_inset) {
465 the_locking_inset->insetUnlock(bv);
466 updateLocal(bv, CELL);
467 the_locking_inset = 0;
472 if (scroll(false) || hasSelection()) {
477 updateLocal(bv, FULL);
482 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
485 calculate_dimensions_of_cells(bv, true);
487 if (!locked && what == CELL)
489 if (need_update < what) // only set this if it has greater update
492 if (need_update != NONE) {
493 bv->updateInset(const_cast<InsetTabular *>(this));
500 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
502 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
507 if (inset == tabular->GetCellInset(actcell)) {
508 lyxerr[Debug::INSETTEXT] << "OK" << endl;
509 the_locking_inset = tabular->GetCellInset(actcell);
512 } else if (!the_locking_inset) {
513 int const n = tabular->GetNumberOfCells();
514 int const id = inset->id();
515 for (int i = 0; i < n; ++i) {
516 InsetText * in = tabular->GetCellInset(i);
519 the_locking_inset = in;
524 if (in->getInsetFromID(id)) {
526 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
527 return the_locking_inset->lockInsetInInset(bv, inset);
530 } else if (the_locking_inset && (the_locking_inset == inset)) {
531 lyxerr[Debug::INSETTEXT] << "OK" << endl;
533 } else if (the_locking_inset) {
534 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
535 return the_locking_inset->lockInsetInInset(bv, inset);
537 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
542 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
545 if (!the_locking_inset)
547 if (the_locking_inset == inset) {
548 the_locking_inset->insetUnlock(bv);
550 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
556 updateLocal(bv, CELL);
557 // this has to be here otherwise we don't redraw the cell!
558 the_locking_inset = 0;
561 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
562 if (inset->lyxCode() == TABULAR_CODE &&
563 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
564 InsetTabularMailer mailer(*this);
565 mailer.updateDialog(bv);
574 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
576 Inset * tl_inset = inset;
577 // look if this inset is really inside myself!
578 while(tl_inset->owner() && tl_inset->owner() != this)
579 tl_inset = tl_inset->owner();
580 // if we enter here it's not ower inset
581 if (!tl_inset->owner())
583 // we only have to do this if this is a subinset of our cells
584 if (tl_inset != inset) {
585 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
588 updateLocal(bv, CELL);
593 int InsetTabular::insetInInsetY() const
595 if (!the_locking_inset)
597 return inset_y + the_locking_inset->insetInInsetY();
601 UpdatableInset * InsetTabular::getLockingInset() const
603 return the_locking_inset ? the_locking_inset->getLockingInset() :
604 const_cast<InsetTabular *>(this);
608 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
612 if (the_locking_inset)
613 return the_locking_inset->getFirstLockingInsetOfType(c);
618 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
620 if (the_locking_inset)
621 return the_locking_inset->insertInset(bv, inset);
626 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
628 if (hasSelection() && cmd.button() == mouse_button::button3)
631 if (hasSelection()) {
633 updateLocal(cmd.view(), SELECTION);
636 int const ocell = actcell;
637 int const orow = actrow;
638 BufferView * bv = cmd.view();
642 the_locking_inset = 0;
646 setPos(bv, cmd.x, cmd.y);
648 updateLocal(bv, NONE);
651 if (cmd.button() == mouse_button::button3) {
652 if ((ocell != actcell) && the_locking_inset) {
653 the_locking_inset->insetUnlock(bv);
654 updateLocal(bv, CELL);
655 the_locking_inset = 0;
661 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
663 if ((ocell == actcell) && the_locking_inset && inset_hit) {
665 FuncRequest cmd1 = cmd;
668 the_locking_inset->localDispatch(cmd1);
672 if (the_locking_inset) {
673 the_locking_inset->insetUnlock(bv);
674 updateLocal(bv, CELL);
675 the_locking_inset = 0;
678 if (cmd.button() == mouse_button::button2) {
679 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
683 if (inset_hit && bv->theLockingInset()) {
684 if (!bv->lockInset(static_cast<UpdatableInset*>
685 (tabular->GetCellInset(actcell))))
687 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
690 FuncRequest cmd1 = cmd;
693 the_locking_inset->localDispatch(cmd1);
699 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
702 if (the_locking_inset) {
703 FuncRequest cmd1 = cmd;
706 ret = the_locking_inset->localDispatch(cmd1);
708 if (cmd.button() == mouse_button::button3 && !ret) {
709 InsetTabularMailer(*this).showDialog(cmd.view());
716 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
718 if (the_locking_inset) {
719 FuncRequest cmd1 = cmd;
722 the_locking_inset->localDispatch(cmd1);
726 BufferView * bv = cmd.view();
727 int const old_cell = actcell;
729 setPos(bv, cmd.x, cmd.y);
730 if (!hasSelection()) {
731 setSelection(actcell, actcell);
732 updateLocal(bv, SELECTION);
733 } else if (old_cell != actcell) {
734 setSelection(sel_cell_start, actcell);
735 updateLocal(bv, SELECTION);
740 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
742 // We need to save the value of the_locking_inset as the call to
743 // the_locking_inset->localDispatch might unlock it.
744 old_locking_inset = the_locking_inset;
745 RESULT result = UpdatableInset::localDispatch(cmd);
746 BufferView * bv = cmd.view();
748 if (cmd.action == LFUN_INSET_EDIT) {
750 if (!bv->lockInset(this)) {
751 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
757 the_locking_inset = 0;
761 if (cmd.argument.size()) {
762 if (cmd.argument == "left") {
763 if (isRightToLeft(bv))
764 actcell = tabular->GetLastCellInRow(0);
768 if (isRightToLeft(bv))
769 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
771 actcell = tabular->GetNumberOfCells() - 1;
779 setPos(bv, cmd.x, cmd.y);
782 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
783 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
789 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
794 if (cmd.action < 0 && cmd.argument.empty())
797 bool hs = hasSelection();
800 // this one have priority over the locked InsetText, if we're not already
801 // inside another tabular then that one get's priority!
802 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
803 switch (cmd.action) {
804 case LFUN_MOUSE_PRESS:
808 case LFUN_MOUSE_MOTION:
809 lfunMouseMotion(cmd);
812 case LFUN_MOUSE_RELEASE:
813 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
815 case LFUN_CELL_BACKWARD:
816 case LFUN_CELL_FORWARD:
817 unlockInsetInInset(bv, the_locking_inset);
818 if (cmd.action == LFUN_CELL_FORWARD)
819 moveNextCell(bv, old_locking_inset != 0);
821 movePrevCell(bv, old_locking_inset != 0);
824 updateLocal(bv, SELECTION);
825 if (!the_locking_inset) {
826 return DISPATCHED_NOUPDATE;
829 // this to avoid compiler warnings.
835 kb_action action = cmd.action;
836 string arg = cmd.argument;
837 if (the_locking_inset) {
838 result = the_locking_inset->localDispatch(cmd);
839 if (result == DISPATCHED_NOUPDATE) {
842 if (sc != scroll()) { // inset has been scrolled
843 updateLocal(bv, FULL);
846 } else if (result == DISPATCHED) {
847 updateLocal(bv, CELL);
849 } else if (result == FINISHED_UP) {
851 // Make sure to reset status message after
852 // exiting, e.g. math inset
853 bv->owner()->clearMessage();
854 } else if (result == FINISHED_DOWN) {
856 bv->owner()->clearMessage();
857 } else if (result == FINISHED_RIGHT) {
859 bv->owner()->clearMessage();
860 } else if (result == FINISHED) {
861 bv->owner()->clearMessage();
867 // --- Cursor Movements ----------------------------------
868 case LFUN_RIGHTSEL: {
869 int const start = hasSelection() ? sel_cell_start : actcell;
870 if (tabular->IsLastCellInRow(actcell)) {
871 setSelection(start, actcell);
876 // if we are starting a selection, only select
877 // the current cell at the beginning
878 if (hasSelection()) {
879 moveRight(bv, false);
882 setSelection(start, end);
883 updateLocal(bv, SELECTION);
887 result = moveRight(bv);
890 updateLocal(bv, SELECTION);
893 int const start = hasSelection() ? sel_cell_start : actcell;
894 if (tabular->IsFirstCellInRow(actcell)) {
895 setSelection(start, actcell);
900 // if we are starting a selection, only select
901 // the current cell at the beginning
902 if (hasSelection()) {
906 setSelection(start, end);
907 updateLocal(bv, SELECTION);
911 result = moveLeft(bv);
914 updateLocal(bv, SELECTION);
917 int const start = hasSelection() ? sel_cell_start : actcell;
918 int const ocell = actcell;
919 // if we are starting a selection, only select
920 // the current cell at the beginning
921 if (hasSelection()) {
923 if ((ocell == sel_cell_end) ||
924 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
925 setSelection(start, tabular->GetCellBelow(sel_cell_end));
927 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
929 setSelection(start, start);
931 updateLocal(bv, SELECTION);
935 result = moveDown(bv, old_locking_inset != 0);
938 updateLocal(bv, SELECTION);
942 int const start = hasSelection() ? sel_cell_start : actcell;
943 int const ocell = actcell;
944 // if we are starting a selection, only select
945 // the current cell at the beginning
946 if (hasSelection()) {
948 if ((ocell == sel_cell_end) ||
949 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
950 setSelection(start, tabular->GetCellAbove(sel_cell_end));
952 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
954 setSelection(start, start);
956 updateLocal(bv, SELECTION);
960 result = moveUp(bv, old_locking_inset != 0);
963 updateLocal(bv, SELECTION);
966 UpdateCodes code = CURSOR;
972 unlockInsetInInset(bv, the_locking_inset);
973 if (bv->text->top_y() + bv->painter().paperHeight() <
974 (top_baseline + tabular->GetHeightOfTabular()))
976 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
978 actcell = tabular->GetCellBelow(first_visible_cell) + column;
980 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
983 updateLocal(bv, code);
987 UpdateCodes code = CURSOR;
993 unlockInsetInInset(bv, the_locking_inset);
994 if (top_baseline < 0) {
995 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
997 if (top_baseline > 0)
1000 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1005 updateLocal(bv, code);
1008 // none of these make sense for insettabular,
1009 // but we must catch them to prevent any
1010 // selection from being confused
1014 case LFUN_WORDLEFTSEL:
1015 case LFUN_WORDRIGHT:
1016 case LFUN_WORDRIGHTSEL:
1018 case LFUN_DOWN_PARAGRAPH:
1019 case LFUN_DOWN_PARAGRAPHSEL:
1020 case LFUN_UP_PARAGRAPH:
1021 case LFUN_UP_PARAGRAPHSEL:
1022 case LFUN_BACKSPACE:
1027 case LFUN_BEGINNINGBUF:
1028 case LFUN_BEGINNINGBUFSEL:
1030 case LFUN_ENDBUFSEL:
1032 case LFUN_LAYOUT_TABULAR: {
1033 InsetTabularMailer mailer(*this);
1034 mailer.showDialog(bv);
1037 case LFUN_INSET_DIALOG_UPDATE: {
1038 InsetTabularMailer mailer(*this);
1039 mailer.updateDialog(bv);
1042 case LFUN_TABULAR_FEATURE:
1043 if (!tabularFeatures(bv, arg))
1044 result = UNDISPATCHED;
1046 // insert file functions
1047 case LFUN_FILE_INSERT_ASCII_PARA:
1048 case LFUN_FILE_INSERT_ASCII:
1050 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1053 if (insertAsciiString(bv, tmpstr, false))
1054 updateLocal(bv, INIT);
1056 result = UNDISPATCHED;
1059 // cut and paste functions
1061 if (!copySelection(bv))
1065 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1066 cutSelection(bv->buffer()->params);
1067 updateLocal(bv, INIT);
1070 if (!hasSelection())
1075 case LFUN_PASTESELECTION:
1077 string const clip(bv->getClipboard());
1081 if (clip.find('\t') != string::npos) {
1085 string::size_type len = clip.length();
1086 string::size_type p = 0;
1089 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1097 maxCols = max(cols, maxCols);
1103 maxCols = max(cols, maxCols);
1104 delete paste_tabular;
1105 paste_tabular = new LyXTabular(bv->buffer()->params,
1106 this, rows, maxCols);
1107 string::size_type op = 0;
1109 int cells = paste_tabular->GetNumberOfCells();
1111 while ((cell < cells) && (p < len) &&
1112 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1117 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1122 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1123 while (cols++ < maxCols)
1131 // check for the last cell if there is no trailing '\n'
1132 if ((cell < cells) && (op < len))
1133 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1136 if (!insertAsciiString(bv, clip, true))
1139 // so that the clipboard is used and it goes on
1141 // and executes LFUN_PASTESELECTION in insettext!
1142 delete paste_tabular;
1147 if (hasPasteBuffer()) {
1148 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1150 updateLocal(bv, INIT);
1153 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1155 // handle font changing stuff on selection before we lock the inset
1156 // in the default part!
1157 result = UNDISPATCHED;
1168 case LFUN_UNDERLINE:
1169 case LFUN_FONT_SIZE:
1170 if (bv->dispatch(FuncRequest(bv, action, arg)))
1171 result = DISPATCHED;
1177 // we try to activate the actual inset and put this event down to
1178 // the insets dispatch function.
1179 if ((result == DISPATCHED) || the_locking_inset)
1182 if (activateCellInset(bv)) {
1183 // reset need_update setted in above function!
1185 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1186 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1187 unlockInsetInInset(bv, the_locking_inset);
1189 // we need to update if this was requested before
1190 updateLocal(bv, NONE);
1191 return UNDISPATCHED;
1194 // so the below CELL is not set because this is higher
1195 // priority and we get a full redraw
1196 need_update = SELECTION;
1199 updateLocal(bv, CELL);
1204 if (result < FINISHED) {
1205 if (!the_locking_inset) {
1206 if (bv->fitCursor())
1207 updateLocal(bv, FULL);
1210 bv->unlockInset(this);
1215 int InsetTabular::latex(Buffer const * buf, ostream & os,
1216 LatexRunParams const & runparams) const
1218 return tabular->latex(buf, os, runparams);
1222 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1225 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1227 return tabular->ascii(buf, os, 0, false,0);
1231 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1234 int const ret = tabular->ascii(buf,os,
1235 (int)parOwner()->params().depth(),
1242 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1247 // if the table is inside a float it doesn't need the informaltable
1248 // wrapper. Search for it.
1249 for(master = owner();
1250 master && master->lyxCode() != Inset::FLOAT_CODE;
1251 master = master->owner());
1254 os << "<informaltable>";
1259 ret+= tabular->docbook(buf, os, mixcont);
1261 os << "</informaltable>";
1270 void InsetTabular::validate(LaTeXFeatures & features) const
1272 tabular->Validate(features);
1276 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1282 bool changed = false;
1284 // FIXME: since InsetText ignores this anyway, it doesn't
1285 // matter what we pass it. Ugly
1288 // if we have a locking_inset we should have to check only this cell for
1289 // change so I'll try this to have a boost, but who knows ;)
1290 if ((need_update != INIT) &&
1291 (the_locking_inset == tabular->GetCellInset(actcell))) {
1292 for(int i = 0; i < tabular->columns(); ++i) {
1293 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1295 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1298 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1299 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1300 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1303 for (int i = 0; i < tabular->rows(); ++i) {
1306 for (int j = 0; j < tabular->columns(); ++j) {
1307 if (tabular->IsPartOfMultiColumn(i,j))
1310 inset = tabular->GetCellInset(cell);
1311 if (!reinit && !tabular->GetPWidth(cell).zero())
1312 inset->update(bv, false);
1313 maxAsc = max(maxAsc, inset->ascent(bv, font));
1314 maxDesc = max(maxDesc, inset->descent(bv, font));
1315 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1317 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1318 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1326 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1328 if (the_locking_inset) {
1329 the_locking_inset->getCursor(bv, x, y);
1334 y = cursor_.y() + InsetTabular::y();
1337 int desc = tabular->GetDescentOfRow(actrow);
1339 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1341 y += ADD_TO_HEIGHT * 2;
1342 y += TEXT_TO_INSET_OFFSET;
1346 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1348 if (the_locking_inset) {
1349 the_locking_inset->getCursorPos(bv, x, y);
1352 x = cursor_.x() - top_x;
1357 void InsetTabular::fitInsetCursor(BufferView * bv) const
1359 if (the_locking_inset) {
1360 int old_top_y = bv->text->top_y();
1361 the_locking_inset->fitInsetCursor(bv);
1362 if (old_top_y != bv->text->top_y())
1368 int const asc = font_metrics::maxAscent(font);
1369 int const desc = font_metrics::maxDescent(font);
1372 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1377 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1381 actcell = actrow = actcol = 0;
1382 int ly = tabular->GetDescentOfRow(actrow);
1384 // first search the right row
1385 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1386 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1387 tabular->GetAscentOfRow(actrow + 1) +
1388 tabular->GetAdditionalHeight(actrow + 1));
1390 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1392 actcell = tabular->GetCellNumber(actrow, actcol);
1394 // now search the right column
1395 int lx = tabular->GetWidthOfColumn(actcell) -
1396 tabular->GetAdditionalWidth(actcell);
1397 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1398 lx += tabular->GetWidthOfColumn(actcell + 1)
1399 + tabular->GetAdditionalWidth(actcell);
1401 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1406 int InsetTabular::getCellXPos(int cell) const
1410 for (; !tabular->IsFirstCellInRow(c); --c)
1412 int lx = tabular->GetWidthOfColumn(cell);
1413 for (; c < cell; ++c) {
1414 lx += tabular->GetWidthOfColumn(c);
1416 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1420 void InsetTabular::resetPos(BufferView * bv) const
1422 #ifdef WITH_WARNINGS
1423 #warning This should be fixed in the right manner (20011128 Jug)
1425 // fast hack to fix infinite repaintings!
1426 if (in_reset_pos > 0)
1430 actcol = tabular->column_of_cell(actcell);
1433 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1434 if (tabular->IsLastCellInRow(cell)) {
1435 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1436 tabular->GetAscentOfRow(actrow + 1) +
1437 tabular->GetAdditionalHeight(actrow + 1));
1441 if (!locked || nodraw()) {
1442 if (the_locking_inset)
1443 inset_y = cursor_.y();
1446 // we need this only from here on!!!
1448 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1449 int new_x = getCellXPos(actcell);
1450 int old_x = cursor_.x();
1453 // cursor.x(getCellXPos(actcell) + offset);
1454 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1455 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1458 updateLocal(bv, FULL);
1459 } else if (the_locking_inset &&
1460 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1462 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1463 if (xx > (bv->workWidth()-20)) {
1464 scroll(bv, -(xx - bv->workWidth() + 60));
1465 updateLocal(bv, FULL);
1466 } else if (xx < 20) {
1472 updateLocal(bv, FULL);
1474 } else if ((cursor_.x() - offset) > 20 &&
1475 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1476 > (bv->workWidth() - 20)) {
1477 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1478 updateLocal(bv, FULL);
1479 } else if ((cursor_.x() - offset) < 20) {
1480 scroll(bv, 20 - cursor_.x() + offset);
1481 updateLocal(bv, FULL);
1482 } else if (scroll() && top_x > 20 &&
1483 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1484 scroll(bv, old_x - cursor_.x());
1485 updateLocal(bv, FULL);
1487 if (the_locking_inset) {
1488 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1489 inset_y = cursor_.y();
1491 if ((!the_locking_inset ||
1492 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1493 actcell != oldcell) {
1494 InsetTabular * inset = const_cast<InsetTabular *>(this);
1495 InsetTabularMailer mailer(*inset);
1496 mailer.updateDialog(bv);
1503 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1505 if (lock && !old_locking_inset) {
1506 if (activateCellInset(bv))
1509 bool moved = isRightToLeft(bv)
1510 ? movePrevCell(bv) : moveNextCell(bv);
1512 return FINISHED_RIGHT;
1513 if (lock && activateCellInset(bv))
1517 return DISPATCHED_NOUPDATE;
1521 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1523 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1526 if (lock) { // behind the inset
1527 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1531 return DISPATCHED_NOUPDATE;
1535 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1537 int const ocell = actcell;
1538 actcell = tabular->GetCellAbove(actcell);
1539 if (actcell == ocell) // we moved out of the inset
1545 if (old_locking_inset) {
1546 old_locking_inset->getCursorPos(bv, x, y);
1547 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1549 if (activateCellInset(bv, x, 0))
1552 return DISPATCHED_NOUPDATE;
1556 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1558 int const ocell = actcell;
1559 actcell = tabular->GetCellBelow(actcell);
1560 if (actcell == ocell) // we moved out of the inset
1561 return FINISHED_DOWN;
1566 if (old_locking_inset) {
1567 old_locking_inset->getCursorPos(bv, x, y);
1568 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1570 if (activateCellInset(bv, x, 0))
1573 return DISPATCHED_NOUPDATE;
1577 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1579 if (isRightToLeft(bv)) {
1580 if (tabular->IsFirstCellInRow(actcell)) {
1581 int row = tabular->row_of_cell(actcell);
1582 if (row == tabular->rows() - 1)
1584 actcell = tabular->GetLastCellInRow(row);
1585 actcell = tabular->GetCellBelow(actcell);
1592 if (tabular->IsLastCell(actcell))
1597 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1598 isRightToLeftPar(bv->buffer()->params);
1599 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1606 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1608 if (isRightToLeft(bv)) {
1609 if (tabular->IsLastCellInRow(actcell)) {
1610 int row = tabular->row_of_cell(actcell);
1613 actcell = tabular->GetFirstCellInRow(row);
1614 actcell = tabular->GetCellAbove(actcell);
1616 if (tabular->IsLastCell(actcell))
1621 if (!actcell) // first cell
1626 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1627 isRightToLeftPar(bv->buffer()->params);
1628 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1635 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1639 setSelection(0, tabular->GetNumberOfCells() - 1);
1641 if (hasSelection()) {
1642 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1643 bool const frozen = undo_frozen;
1646 // apply the fontchange on the whole selection
1651 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1652 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1653 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1654 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1661 updateLocal(bv, INIT);
1663 if (the_locking_inset)
1664 the_locking_inset->setFont(bv, font, tall);
1668 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1670 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1673 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1674 string const tmp = tabularFeature[i].feature;
1676 if (tmp == what.substr(0, tmp.length())) {
1677 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1678 //tabularFeatures[i].feature.length())) {
1679 action = tabularFeature[i].action;
1683 if (action == LyXTabular::LAST_ACTION)
1687 ltrim(what.substr(tabularFeature[i].feature.length()));
1688 tabularFeatures(bv, action, val);
1694 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1695 string const & special, bool & flag)
1697 if (special == "dl_above") {
1700 } else if (special == "dl_below") {
1701 ltt.bottomDL = flag;
1703 } else if (special == "empty") {
1715 void InsetTabular::tabularFeatures(BufferView * bv,
1716 LyXTabular::Feature feature,
1717 string const & value)
1723 bool setLines = false;
1724 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1725 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1728 case LyXTabular::M_ALIGN_LEFT:
1729 case LyXTabular::ALIGN_LEFT:
1730 setAlign = LYX_ALIGN_LEFT;
1732 case LyXTabular::M_ALIGN_RIGHT:
1733 case LyXTabular::ALIGN_RIGHT:
1734 setAlign = LYX_ALIGN_RIGHT;
1736 case LyXTabular::M_ALIGN_CENTER:
1737 case LyXTabular::ALIGN_CENTER:
1738 setAlign = LYX_ALIGN_CENTER;
1740 case LyXTabular::ALIGN_BLOCK:
1741 setAlign = LYX_ALIGN_BLOCK;
1743 case LyXTabular::M_VALIGN_TOP:
1744 case LyXTabular::VALIGN_TOP:
1745 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1747 case LyXTabular::M_VALIGN_BOTTOM:
1748 case LyXTabular::VALIGN_BOTTOM:
1749 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1751 case LyXTabular::M_VALIGN_CENTER:
1752 case LyXTabular::VALIGN_CENTER:
1753 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1758 if (hasSelection()) {
1759 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1761 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1762 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1764 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1766 int row = tabular->row_of_cell(actcell);
1767 int column = tabular->column_of_cell(actcell);
1769 LyXTabular::ltType ltt;
1772 case LyXTabular::SET_PWIDTH:
1774 LyXLength const vallen(value);
1775 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1777 bool const update = (tmplen != vallen);
1778 tabular->SetColumnPWidth(actcell, vallen);
1781 for (int i = 0; i < tabular->rows(); ++i) {
1782 cell = tabular->GetCellNumber(i,column);
1783 tabular->GetCellInset(cell)->resizeLyXText(bv);
1785 updateLocal(bv, INIT);
1789 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1790 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1791 else if (!vallen.zero()
1792 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1793 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1796 case LyXTabular::SET_MPWIDTH:
1798 LyXLength const vallen(value);
1799 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1801 bool const update = (tmplen != vallen);
1802 tabular->SetMColumnPWidth(actcell, vallen);
1804 for (int i = 0; i < tabular->rows(); ++i) {
1805 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1808 updateLocal(bv, INIT);
1812 case LyXTabular::SET_SPECIAL_COLUMN:
1813 case LyXTabular::SET_SPECIAL_MULTI:
1814 tabular->SetAlignSpecial(actcell,value,feature);
1815 updateLocal(bv, FULL);
1817 case LyXTabular::APPEND_ROW:
1818 // append the row into the tabular
1819 unlockInsetInInset(bv, the_locking_inset);
1820 tabular->AppendRow(bv->buffer()->params, actcell);
1821 updateLocal(bv, INIT);
1823 case LyXTabular::APPEND_COLUMN:
1824 // append the column into the tabular
1825 unlockInsetInInset(bv, the_locking_inset);
1826 tabular->AppendColumn(bv->buffer()->params, actcell);
1827 actcell = tabular->GetCellNumber(row, column);
1828 updateLocal(bv, INIT);
1830 case LyXTabular::DELETE_ROW:
1831 unlockInsetInInset(bv, the_locking_inset);
1832 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1833 tabular->DeleteRow(sel_row_start);
1835 if (sel_row_start >= tabular->rows())
1837 actcell = tabular->GetCellNumber(sel_row_start, column);
1839 updateLocal(bv, INIT);
1841 case LyXTabular::DELETE_COLUMN:
1842 unlockInsetInInset(bv, the_locking_inset);
1843 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1844 tabular->DeleteColumn(sel_col_start);
1846 if (sel_col_start >= tabular->columns())
1848 actcell = tabular->GetCellNumber(row, sel_col_start);
1850 updateLocal(bv, INIT);
1852 case LyXTabular::M_TOGGLE_LINE_TOP:
1854 case LyXTabular::TOGGLE_LINE_TOP:
1856 bool lineSet = !tabular->TopLine(actcell, flag);
1857 for (int i = sel_row_start; i <= sel_row_end; ++i)
1858 for (int j = sel_col_start; j <= sel_col_end; ++j)
1859 tabular->SetTopLine(
1860 tabular->GetCellNumber(i, j),
1862 updateLocal(bv, INIT);
1866 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1868 case LyXTabular::TOGGLE_LINE_BOTTOM:
1870 bool lineSet = !tabular->BottomLine(actcell, flag);
1871 for (int i = sel_row_start; i <= sel_row_end; ++i)
1872 for (int j = sel_col_start; j <= sel_col_end; ++j)
1873 tabular->SetBottomLine(
1874 tabular->GetCellNumber(i, j),
1877 updateLocal(bv, INIT);
1881 case LyXTabular::M_TOGGLE_LINE_LEFT:
1883 case LyXTabular::TOGGLE_LINE_LEFT:
1885 bool lineSet = !tabular->LeftLine(actcell, flag);
1886 for (int i = sel_row_start; i <= sel_row_end; ++i)
1887 for (int j = sel_col_start; j <= sel_col_end; ++j)
1888 tabular->SetLeftLine(
1889 tabular->GetCellNumber(i,j),
1892 updateLocal(bv, INIT);
1896 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1898 case LyXTabular::TOGGLE_LINE_RIGHT:
1900 bool lineSet = !tabular->RightLine(actcell, flag);
1901 for (int i = sel_row_start; i <= sel_row_end; ++i)
1902 for (int j = sel_col_start; j <= sel_col_end; ++j)
1903 tabular->SetRightLine(
1904 tabular->GetCellNumber(i,j),
1907 updateLocal(bv, INIT);
1911 case LyXTabular::M_ALIGN_LEFT:
1912 case LyXTabular::M_ALIGN_RIGHT:
1913 case LyXTabular::M_ALIGN_CENTER:
1915 case LyXTabular::ALIGN_LEFT:
1916 case LyXTabular::ALIGN_RIGHT:
1917 case LyXTabular::ALIGN_CENTER:
1918 case LyXTabular::ALIGN_BLOCK:
1919 for (int i = sel_row_start; i <= sel_row_end; ++i)
1920 for (int j = sel_col_start; j <= sel_col_end; ++j)
1921 tabular->SetAlignment(
1922 tabular->GetCellNumber(i, j),
1925 updateLocal(bv, INIT);
1927 case LyXTabular::M_VALIGN_TOP:
1928 case LyXTabular::M_VALIGN_BOTTOM:
1929 case LyXTabular::M_VALIGN_CENTER:
1931 case LyXTabular::VALIGN_TOP:
1932 case LyXTabular::VALIGN_BOTTOM:
1933 case LyXTabular::VALIGN_CENTER:
1934 for (int i = sel_row_start; i <= sel_row_end; ++i)
1935 for (int j = sel_col_start; j <= sel_col_end; ++j)
1936 tabular->SetVAlignment(
1937 tabular->GetCellNumber(i, j),
1939 updateLocal(bv, INIT);
1941 case LyXTabular::MULTICOLUMN:
1943 if (sel_row_start != sel_row_end) {
1944 #ifdef WITH_WARNINGS
1945 #warning Need I say it ? This is horrible.
1947 Alert::error(_("Error setting multicolumn"),
1948 _("You cannot set multicolumn vertically."));
1951 // just multicol for one Single Cell
1952 if (!hasSelection()) {
1953 // check wether we are completly in a multicol
1954 if (tabular->IsMultiColumn(actcell)) {
1955 tabular->UnsetMultiColumn(actcell);
1956 updateLocal(bv, INIT);
1958 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1959 updateLocal(bv, CELL);
1963 // we have a selection so this means we just add all this
1964 // cells to form a multicolumn cell
1968 if (sel_cell_start > sel_cell_end) {
1969 s_start = sel_cell_end;
1970 s_end = sel_cell_start;
1972 s_start = sel_cell_start;
1973 s_end = sel_cell_end;
1975 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1978 updateLocal(bv, INIT);
1981 case LyXTabular::SET_ALL_LINES:
1983 case LyXTabular::UNSET_ALL_LINES:
1984 for (int i = sel_row_start; i <= sel_row_end; ++i)
1985 for (int j = sel_col_start; j <= sel_col_end; ++j)
1986 tabular->SetAllLines(
1987 tabular->GetCellNumber(i,j), setLines);
1988 updateLocal(bv, INIT);
1990 case LyXTabular::SET_LONGTABULAR:
1991 tabular->SetLongTabular(true);
1992 updateLocal(bv, INIT); // because this toggles displayed
1994 case LyXTabular::UNSET_LONGTABULAR:
1995 tabular->SetLongTabular(false);
1996 updateLocal(bv, INIT); // because this toggles displayed
1998 case LyXTabular::SET_ROTATE_TABULAR:
1999 tabular->SetRotateTabular(true);
2001 case LyXTabular::UNSET_ROTATE_TABULAR:
2002 tabular->SetRotateTabular(false);
2004 case LyXTabular::SET_ROTATE_CELL:
2005 for (int i = sel_row_start; i <= sel_row_end; ++i)
2006 for (int j = sel_col_start; j<=sel_col_end; ++j)
2007 tabular->SetRotateCell(
2008 tabular->GetCellNumber(i, j),
2011 case LyXTabular::UNSET_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), false);
2017 case LyXTabular::SET_USEBOX:
2019 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2020 if (val == tabular->GetUsebox(actcell))
2021 val = LyXTabular::BOX_NONE;
2022 for (int i = sel_row_start; i <= sel_row_end; ++i)
2023 for (int j = sel_col_start; j <= sel_col_end; ++j)
2025 tabular->GetCellNumber(i, j), val);
2028 case LyXTabular::UNSET_LTFIRSTHEAD:
2030 case LyXTabular::SET_LTFIRSTHEAD:
2031 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2032 checkLongtableSpecial(ltt, value, flag);
2033 tabular->SetLTHead(row, flag, ltt, true);
2035 case LyXTabular::UNSET_LTHEAD:
2037 case LyXTabular::SET_LTHEAD:
2038 (void)tabular->GetRowOfLTHead(row, ltt);
2039 checkLongtableSpecial(ltt, value, flag);
2040 tabular->SetLTHead(row, flag, ltt, false);
2042 case LyXTabular::UNSET_LTFOOT:
2044 case LyXTabular::SET_LTFOOT:
2045 (void)tabular->GetRowOfLTFoot(row, ltt);
2046 checkLongtableSpecial(ltt, value, flag);
2047 tabular->SetLTFoot(row, flag, ltt, false);
2049 case LyXTabular::UNSET_LTLASTFOOT:
2051 case LyXTabular::SET_LTLASTFOOT:
2052 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2053 checkLongtableSpecial(ltt, value, flag);
2054 tabular->SetLTFoot(row, flag, ltt, true);
2056 case LyXTabular::SET_LTNEWPAGE:
2058 bool what = !tabular->GetLTNewPage(row);
2059 tabular->SetLTNewPage(row, what);
2062 // dummy stuff just to avoid warnings
2063 case LyXTabular::LAST_ACTION:
2067 InsetTabularMailer mailer(*this);
2068 mailer.updateDialog(bv);
2072 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2075 UpdatableInset * inset =
2076 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2077 LyXFont font(LyXFont::ALL_SANE);
2079 x = inset->x() + inset->width(bv, font);
2080 y = inset->descent(bv, font);
2082 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2083 //inset_y = cursor.y();
2084 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2085 if (!the_locking_inset)
2087 updateLocal(bv, CELL);
2088 return (the_locking_inset != 0);
2092 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2093 mouse_button::state button)
2095 inset_x = cursor_.x()
2096 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2097 inset_y = cursor_.y();
2098 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2102 bool InsetTabular::insetHit(BufferView *, int x, int) const
2105 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2109 // This returns paperWidth() if the cell-width is unlimited or the width
2110 // in pixels if we have a pwidth for this cell.
2111 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2113 LyXLength const len = tabular->GetPWidth(cell);
2117 return len.inPixels(latexTextWidth(bv));
2121 int InsetTabular::getMaxWidth(BufferView * bv,
2122 UpdatableInset const * inset) const
2124 int cell = tabular->GetCellFromInset(inset, actcell);
2127 lyxerr << "Own inset not found, shouldn't really happen!"
2132 int w = getMaxWidthOfCell(bv, cell);
2134 // because the inset then subtracts it's top_x and owner->x()
2135 w += (inset->x() - top_x);
2142 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2144 resizeLyXText(bv, recursive);
2148 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2151 for(int i = 0; i < tabular->rows(); ++i) {
2152 for(int j = 0; j < tabular->columns(); ++j) {
2153 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2161 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2162 bool const recursive) const
2164 if (the_locking_inset)
2165 return the_locking_inset->getLyXText(bv, recursive);
2167 // if we're locked lock the actual insettext and return it's LyXText!!!
2169 UpdatableInset * inset =
2170 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2171 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2172 return the_locking_inset->getLyXText(bv, recursive);
2175 return Inset::getLyXText(bv, recursive);
2179 bool InsetTabular::showInsetDialog(BufferView * bv) const
2181 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2182 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2183 InsetTabularMailer mailer(*tmp);
2184 mailer.showDialog(bv);
2190 void InsetTabular::openLayoutDialog(BufferView * bv) const
2192 if (the_locking_inset) {
2193 InsetTabular * i = static_cast<InsetTabular *>
2194 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2196 i->openLayoutDialog(bv);
2200 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2201 InsetTabularMailer mailer(*tmp);
2202 mailer.showDialog(bv);
2207 // function returns an object as defined in func_status.h:
2208 // states OK, Unknown, Disabled, On, Off.
2210 FuncStatus InsetTabular::getStatus(string const & what) const
2212 int action = LyXTabular::LAST_ACTION;
2216 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2217 string const tmp = tabularFeature[i].feature;
2218 if (tmp == what.substr(0, tmp.length())) {
2219 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2220 // tabularFeatures[i].feature.length())) {
2221 action = tabularFeature[i].action;
2225 if (action == LyXTabular::LAST_ACTION) {
2227 return status.unknown(true);
2230 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2235 LyXTabular::ltType dummyltt;
2238 if (hasSelection()) {
2239 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2241 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2245 case LyXTabular::SET_PWIDTH:
2246 case LyXTabular::SET_MPWIDTH:
2247 case LyXTabular::SET_SPECIAL_COLUMN:
2248 case LyXTabular::SET_SPECIAL_MULTI:
2249 case LyXTabular::APPEND_ROW:
2250 case LyXTabular::APPEND_COLUMN:
2251 case LyXTabular::DELETE_ROW:
2252 case LyXTabular::DELETE_COLUMN:
2253 case LyXTabular::SET_ALL_LINES:
2254 case LyXTabular::UNSET_ALL_LINES:
2255 return status.clear();
2257 case LyXTabular::MULTICOLUMN:
2258 status.setOnOff(tabular->IsMultiColumn(actcell));
2260 case LyXTabular::M_TOGGLE_LINE_TOP:
2262 case LyXTabular::TOGGLE_LINE_TOP:
2263 status.setOnOff(tabular->TopLine(actcell, flag));
2265 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2267 case LyXTabular::TOGGLE_LINE_BOTTOM:
2268 status.setOnOff(tabular->BottomLine(actcell, flag));
2270 case LyXTabular::M_TOGGLE_LINE_LEFT:
2272 case LyXTabular::TOGGLE_LINE_LEFT:
2273 status.setOnOff(tabular->LeftLine(actcell, flag));
2275 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2277 case LyXTabular::TOGGLE_LINE_RIGHT:
2278 status.setOnOff(tabular->RightLine(actcell, flag));
2280 case LyXTabular::M_ALIGN_LEFT:
2282 case LyXTabular::ALIGN_LEFT:
2283 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2285 case LyXTabular::M_ALIGN_RIGHT:
2287 case LyXTabular::ALIGN_RIGHT:
2288 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2290 case LyXTabular::M_ALIGN_CENTER:
2292 case LyXTabular::ALIGN_CENTER:
2293 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2295 case LyXTabular::ALIGN_BLOCK:
2296 status.disabled(tabular->GetPWidth(actcell).zero());
2297 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2299 case LyXTabular::M_VALIGN_TOP:
2301 case LyXTabular::VALIGN_TOP:
2302 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2304 case LyXTabular::M_VALIGN_BOTTOM:
2306 case LyXTabular::VALIGN_BOTTOM:
2307 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2309 case LyXTabular::M_VALIGN_CENTER:
2311 case LyXTabular::VALIGN_CENTER:
2312 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2314 case LyXTabular::SET_LONGTABULAR:
2315 status.setOnOff(tabular->IsLongTabular());
2317 case LyXTabular::UNSET_LONGTABULAR:
2318 status.setOnOff(!tabular->IsLongTabular());
2320 case LyXTabular::SET_ROTATE_TABULAR:
2321 status.setOnOff(tabular->GetRotateTabular());
2323 case LyXTabular::UNSET_ROTATE_TABULAR:
2324 status.setOnOff(!tabular->GetRotateTabular());
2326 case LyXTabular::SET_ROTATE_CELL:
2327 status.setOnOff(tabular->GetRotateCell(actcell));
2329 case LyXTabular::UNSET_ROTATE_CELL:
2330 status.setOnOff(!tabular->GetRotateCell(actcell));
2332 case LyXTabular::SET_USEBOX:
2333 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2335 case LyXTabular::SET_LTFIRSTHEAD:
2336 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2338 case LyXTabular::SET_LTHEAD:
2339 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2341 case LyXTabular::SET_LTFOOT:
2342 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2344 case LyXTabular::SET_LTLASTFOOT:
2345 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2347 case LyXTabular::SET_LTNEWPAGE:
2348 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2352 status.disabled(true);
2359 vector<string> const InsetTabular::getLabelList() const
2361 return tabular->getLabelList();
2365 bool InsetTabular::copySelection(BufferView * bv)
2367 if (!hasSelection())
2370 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2371 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2372 if (sel_col_start > sel_col_end) {
2373 sel_col_start = sel_col_end;
2374 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2376 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2378 int const columns = sel_col_end - sel_col_start + 1;
2380 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2381 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2382 if (sel_row_start > sel_row_end) {
2383 swap(sel_row_start, sel_row_end);
2385 int const rows = sel_row_end - sel_row_start + 1;
2387 delete paste_tabular;
2388 paste_tabular = new LyXTabular(bv->buffer()->params,
2389 this, *tabular); // rows, columns);
2390 for (int i = 0; i < sel_row_start; ++i)
2391 paste_tabular->DeleteRow(0);
2392 while (paste_tabular->rows() > rows)
2393 paste_tabular->DeleteRow(rows);
2394 paste_tabular->SetTopLine(0, true, true);
2395 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2397 for (int i = 0; i < sel_col_start; ++i)
2398 paste_tabular->DeleteColumn(0);
2399 while (paste_tabular->columns() > columns)
2400 paste_tabular->DeleteColumn(columns);
2401 paste_tabular->SetLeftLine(0, true, true);
2402 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2406 paste_tabular->ascii(bv->buffer(), sstr,
2407 (int)parOwner()->params().depth(), true, '\t');
2408 bv->stuffClipboard(STRCONV(sstr.str()));
2413 bool InsetTabular::pasteSelection(BufferView * bv)
2418 for (int r1 = 0, r2 = actrow;
2419 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2421 for(int c1 = 0, c2 = actcol;
2422 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2424 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2425 tabular->IsPartOfMultiColumn(r2,c2))
2427 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2431 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2435 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2436 int const n2 = tabular->GetCellNumber(r2, c2);
2437 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2438 tabular->GetCellInset(n2)->setOwner(this);
2439 tabular->GetCellInset(n2)->deleteLyXText(bv);
2440 tabular->GetCellInset(n2)->markNew();
2447 bool InsetTabular::cutSelection(BufferParams const & bp)
2449 if (!hasSelection())
2452 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2453 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2454 if (sel_col_start > sel_col_end) {
2455 sel_col_start = sel_col_end;
2456 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2458 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2460 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2461 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2462 if (sel_row_start > sel_row_end) {
2463 swap(sel_row_start, sel_row_end);
2465 if (sel_cell_start > sel_cell_end) {
2466 swap(sel_cell_start, sel_cell_end);
2468 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2469 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2470 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2477 bool InsetTabular::isRightToLeft(BufferView * bv)
2479 return bv->getParentLanguage(this)->RightToLeft();
2483 bool InsetTabular::nodraw() const
2485 if (!UpdatableInset::nodraw() && the_locking_inset)
2486 return the_locking_inset->nodraw();
2487 return UpdatableInset::nodraw();
2491 int InsetTabular::scroll(bool recursive) const
2493 int sx = UpdatableInset::scroll(false);
2495 if (recursive && the_locking_inset)
2496 sx += the_locking_inset->scroll(recursive);
2502 void InsetTabular::getSelection(int & srow, int & erow,
2503 int & scol, int & ecol) const
2505 int const start = hasSelection() ? sel_cell_start : actcell;
2506 int const end = hasSelection() ? sel_cell_end : actcell;
2508 srow = tabular->row_of_cell(start);
2509 erow = tabular->row_of_cell(end);
2514 scol = tabular->column_of_cell(start);
2515 ecol = tabular->column_of_cell(end);
2519 ecol = tabular->right_column_of_cell(end);
2524 ParagraphList * InsetTabular::getParagraphs(int i) const
2526 return (i < tabular->GetNumberOfCells())
2527 ? tabular->GetCellInset(i)->getParagraphs(0)
2532 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2534 if (the_locking_inset)
2535 return the_locking_inset->cursor(bv);
2536 return Inset::cursor(bv);
2540 Inset * InsetTabular::getInsetFromID(int id_arg) const
2543 return const_cast<InsetTabular *>(this);
2546 for(int i = 0; i < tabular->rows(); ++i) {
2547 for(int j = 0; j < tabular->columns(); ++j) {
2548 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2557 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2560 if (the_locking_inset) {
2561 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2562 if (!word.word().empty()) {
2566 if (tabular->IsLastCell(actcell)) {
2567 bv->unlockInset(const_cast<InsetTabular *>(this));
2569 return WordLangTuple();
2573 // otherwise we have to lock the next inset and ask for it's selecttion
2574 UpdatableInset * inset =
2575 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2576 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2577 WordLangTuple word(selectNextWordInt(bv, value));
2579 if (!word.word().empty())
2585 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2587 // when entering this function the inset should be ALWAYS locked!
2588 lyx::Assert(the_locking_inset);
2590 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2591 if (!word.word().empty())
2594 if (tabular->IsLastCell(actcell)) {
2595 bv->unlockInset(const_cast<InsetTabular *>(this));
2596 return WordLangTuple();
2599 // otherwise we have to lock the next inset and ask for it's selecttion
2600 UpdatableInset * inset =
2601 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2602 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2603 return selectNextWordInt(bv, value);
2607 void InsetTabular::selectSelectedWord(BufferView * bv)
2609 if (the_locking_inset) {
2610 the_locking_inset->selectSelectedWord(bv);
2617 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2619 if (the_locking_inset) {
2620 the_locking_inset->toggleSelection(bv, kill_selection);
2625 void InsetTabular::markErased()
2629 while (!tabular->IsLastCell(cell)) {
2631 InsetText * inset = tabular->GetCellInset(cell);
2632 inset->markErased();
2637 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2639 if (the_locking_inset) {
2640 if (the_locking_inset->nextChange(bv, length)) {
2641 updateLocal(bv, CELL);
2644 if (tabular->IsLastCell(actcell))
2648 InsetText * inset = tabular->GetCellInset(actcell);
2649 if (inset->nextChange(bv, length)) {
2650 updateLocal(bv, FULL);
2653 while (!tabular->IsLastCell(actcell)) {
2655 inset = tabular->GetCellInset(actcell);
2656 if (inset->nextChange(bv, length)) {
2657 updateLocal(bv, FULL);
2665 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2669 if (the_locking_inset) {
2670 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2671 updateLocal(bv, CELL);
2674 if (tabular->IsLastCell(actcell))
2678 InsetText * inset = tabular->GetCellInset(cell);
2679 if (inset->searchForward(bv, str, cs, mw)) {
2680 updateLocal(bv, FULL);
2683 while (!tabular->IsLastCell(cell)) {
2685 inset = tabular->GetCellInset(cell);
2686 if (inset->searchForward(bv, str, cs, mw)) {
2687 updateLocal(bv, FULL);
2695 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2698 int cell = tabular->GetNumberOfCells();
2699 if (the_locking_inset) {
2700 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2701 updateLocal(bv, CELL);
2709 InsetText * inset = tabular->GetCellInset(cell);
2710 if (inset->searchBackward(bv, str, cs, mw)) {
2711 updateLocal(bv, CELL);
2719 bool InsetTabular::insetAllowed(Inset::Code code) const
2721 if (the_locking_inset)
2722 return the_locking_inset->insetAllowed(code);
2723 // we return true here because if the inset is not locked someone
2724 // wants to insert something in one of our insettexts and we generally
2730 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2732 const int cell = tabular->GetCellFromInset(in, actcell);
2735 return tabular->GetPWidth(cell).zero();
2737 // well we didn't obviously find it so maybe our owner knows more
2739 return owner()->forceDefaultParagraphs(in);
2740 // if we're here there is really something strange going on!!!
2744 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2747 if (buf.length() <= 0)
2753 string::size_type len = buf.length();
2754 string::size_type p = 0;
2757 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2766 maxCols = max(cols, maxCols);
2772 maxCols = max(cols, maxCols);
2773 LyXTabular * loctab;
2778 delete paste_tabular;
2779 paste_tabular = new LyXTabular(bv->buffer()->params,
2780 this, rows, maxCols);
2781 loctab = paste_tabular;
2784 loctab = tabular.get();
2790 string::size_type op = 0;
2791 int cells = loctab->GetNumberOfCells();
2794 rows = loctab->rows();
2795 int const columns = loctab->columns();
2797 while ((cell < cells) && (p < len) && (row < rows) &&
2798 (p = buf.find_first_of("\t\n", p)) != string::npos)
2804 // we can only set this if we are not too far right
2805 if (cols < columns) {
2806 InsetText * ti = loctab->GetCellInset(cell);
2807 LyXFont const font = ti->getLyXText(bv)->
2808 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2809 ti->setText(buf.substr(op, p - op), font);
2815 // we can only set this if we are not too far right
2816 if (cols < columns) {
2817 InsetText * ti = loctab->GetCellInset(cell);
2818 LyXFont const font = ti->getLyXText(bv)->
2819 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2820 ti->setText(buf.substr(op, p - op), font);
2825 cell = loctab->GetCellNumber(row, cols);
2831 // check for the last cell if there is no trailing '\n'
2832 if ((cell < cells) && (op < len)) {
2833 InsetText * ti = loctab->GetCellInset(cell);
2834 LyXFont const font = ti->getLyXText(bv)->
2835 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2836 ti->setText(buf.substr(op, len - op), font);
2843 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2845 int const rows = tabular->rows();
2846 int const columns = tabular->columns();
2847 for (int i = 0; i < rows; ++i) {
2848 for (int j = 0; j < columns; ++j) {
2849 tabular->GetCellInset(i,j)->addPreview(loader);
2855 string const InsetTabularMailer:: name_("tabular");
2857 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2862 string const InsetTabularMailer::inset2string() const
2864 return params2string(inset_);
2868 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2870 istringstream data(STRCONV(in));
2872 lex.setStream(data);
2874 #warning CHECK verify that this is a sane value to return.
2880 string const token = lex.getString();
2888 string const token = lex.getString();
2889 if (token != "\\active_cell")
2892 cell = lex.getInteger();
2895 // This is part of the inset proper that is usually swallowed
2896 // by Buffer::readInset
2899 string const token = lex.getString();
2900 if (token != "Tabular")
2907 BufferView * const bv = inset.view();
2908 Buffer const * const buffer = bv ? bv->buffer() : 0;
2910 inset.read(buffer, lex);
2912 // We can't set the active cell, but we can tell the frontend
2918 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2920 BufferView * const bv = inset.view();
2921 Buffer const * const buffer = bv ? bv->buffer() : 0;
2926 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2927 inset.write(buffer, data);
2928 data << "\\end_inset\n";
2929 return STRCONV(data.str());