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
14 #include "insettabular.h"
15 #include "insettext.h"
18 #include "BufferView.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
27 #include "lyxlength.h"
30 #include "ParagraphParameters.h"
31 #include "undo_funcs.h"
32 #include "WordLangTuple.h"
34 #include "frontends/Alert.h"
35 #include "frontends/Dialogs.h"
36 #include "frontends/font_metrics.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/Painter.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::ALIGN_BLOCK, "align-block" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
123 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
124 bool operator()(TabularFeature & tf)
126 return tf.action == feature_;
129 LyXTabular::Feature feature_;
135 string const featureAsString(LyXTabular::Feature feature)
137 TabularFeature * it = tabularFeature;
138 TabularFeature * end = it +
139 sizeof(tabularFeature) / sizeof(TabularFeature);
140 it = std::find_if(it, end, FindFeature(feature));
141 return (it == end) ? string() : it->feature;
145 bool InsetTabular::hasPasteBuffer() const
147 return (paste_tabular != 0);
151 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
159 // for now make it always display as display() inset
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
175 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
177 : UpdatableInset(tab, same_id), buffer(&buf)
179 tabular.reset(new LyXTabular(buf.params,
180 this, *(tab.tabular), same_id));
181 the_locking_inset = 0;
182 old_locking_inset = 0;
185 actrow = actcell = 0;
195 InsetTabular::~InsetTabular()
197 InsetTabularMailer mailer(*this);
202 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
204 return new InsetTabular(*this, buf, same_id);
208 BufferView * InsetTabular::view() const
210 return buffer->getUser();
214 void InsetTabular::write(Buffer const * buf, ostream & os) const
216 os << " Tabular" << endl;
217 tabular->Write(buf, os);
221 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
223 bool const old_format = (lex.getString() == "\\LyXTable");
225 tabular.reset(new LyXTabular(buf, this, lex));
233 string token = lex.getString();
234 while (lex.isOK() && (token != "\\end_inset")) {
236 token = lex.getString();
238 if (token != "\\end_inset") {
239 lex.printError("Missing \\end_inset at this point. "
245 int InsetTabular::ascent(BufferView *, LyXFont const &) const
247 return tabular->GetAscentOfRow(0);
251 int InsetTabular::descent(BufferView *, LyXFont const &) const
253 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
257 int InsetTabular::width(BufferView *, LyXFont const &) const
259 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
263 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
271 Painter & pain = bv->painter();
277 UpdatableInset::draw(bv, font, baseline, x);
280 x += static_cast<float>(scroll());
284 top_baseline = baseline;
285 x += ADD_TO_TABULAR_WIDTH;
289 first_visible_cell = -1;
290 for (i = 0; i < tabular->rows(); ++i) {
292 cell = tabular->GetCellNumber(i, 0);
293 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
294 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
296 baseline += tabular->GetDescentOfRow(i) +
297 tabular->GetAscentOfRow(i + 1) +
298 tabular->GetAdditionalHeight(i + 1);
301 for (j = 0; j < tabular->columns(); ++j) {
302 if (nx > bv->workWidth())
304 if (tabular->IsPartOfMultiColumn(i, j))
306 cx = nx + tabular->GetBeginningOfTextInCell(cell);
307 if (first_visible_cell < 0)
308 first_visible_cell = cell;
309 if (hasSelection()) {
310 drawCellSelection(pain, nx, baseline, i, j, cell);
313 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
314 drawCellLines(pain, nx, baseline, i, cell);
315 nx += tabular->GetWidthOfColumn(cell);
318 baseline += tabular->GetDescentOfRow(i) +
319 tabular->GetAscentOfRow(i + 1) +
320 tabular->GetAdditionalHeight(i + 1);
323 x -= ADD_TO_TABULAR_WIDTH;
324 x += width(bv, font);
329 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
330 int row, int cell) const
332 int x2 = x + tabular->GetWidthOfColumn(cell);
335 if (!tabular->topAlreadyDrawn(cell)) {
336 on_off = !tabular->TopLine(cell);
337 pain.line(x, baseline - tabular->GetAscentOfRow(row),
338 x2, baseline - tabular->GetAscentOfRow(row),
339 on_off ? LColor::tabularonoffline : LColor::tabularline,
340 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 on_off = !tabular->BottomLine(cell);
343 pain.line(x, baseline + tabular->GetDescentOfRow(row),
344 x2, baseline + tabular->GetDescentOfRow(row),
345 on_off ? LColor::tabularonoffline : LColor::tabularline,
346 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 if (!tabular->leftAlreadyDrawn(cell)) {
348 on_off = !tabular->LeftLine(cell);
349 pain.line(x, baseline - tabular->GetAscentOfRow(row),
350 x, baseline + tabular->GetDescentOfRow(row),
351 on_off ? LColor::tabularonoffline : LColor::tabularline,
352 on_off ? Painter::line_onoffdash : Painter::line_solid);
354 on_off = !tabular->RightLine(cell);
355 pain.line(x2 - tabular->GetAdditionalWidth(cell),
356 baseline - tabular->GetAscentOfRow(row),
357 x2 - tabular->GetAdditionalWidth(cell),
358 baseline + tabular->GetDescentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
364 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
365 int row, int column, int cell) const
367 lyx::Assert(hasSelection());
368 int cs = tabular->column_of_cell(sel_cell_start);
369 int ce = tabular->column_of_cell(sel_cell_end);
372 cs = tabular->column_of_cell(sel_cell_end);
374 ce = tabular->right_column_of_cell(sel_cell_end);
377 int rs = tabular->row_of_cell(sel_cell_start);
378 int re = tabular->row_of_cell(sel_cell_end);
382 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
383 int w = tabular->GetWidthOfColumn(cell);
384 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
385 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
386 w, h, LColor::selection);
391 void InsetTabular::update(BufferView * bv, bool reinit)
397 owner()->update(bv, true);
404 if (calculate_dimensions_of_cells(bv, true))
407 owner()->update(bv, true);
411 if (the_locking_inset)
412 the_locking_inset->update(bv, reinit);
413 if (need_update < FULL &&
414 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
419 switch (need_update) {
423 if (calculate_dimensions_of_cells(bv, false)) {
438 string const InsetTabular::editMessage() const
440 return _("Opened table");
444 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
446 UpdatableInset::edit(bv, x, y, button);
448 if (!bv->lockInset(this)) {
449 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
453 the_locking_inset = 0;
459 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
460 activateCellInsetAbs(bv, x, y, button);
465 void InsetTabular::edit(BufferView * bv, bool front)
467 UpdatableInset::edit(bv, front);
469 if (!bv->lockInset(this)) {
470 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
475 the_locking_inset = 0;
479 if (isRightToLeft(bv))
480 actcell = tabular->GetLastCellInRow(0);
484 if (isRightToLeft(bv))
485 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
487 actcell = tabular->GetNumberOfCells() - 1;
495 void InsetTabular::insetUnlock(BufferView * bv)
497 if (the_locking_inset) {
498 the_locking_inset->insetUnlock(bv);
499 updateLocal(bv, CELL);
500 the_locking_inset = 0;
505 if (scroll(false) || hasSelection()) {
510 updateLocal(bv, FULL);
515 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
518 calculate_dimensions_of_cells(bv, true);
520 if (!locked && what == CELL)
522 if (need_update < what) // only set this if it has greater update
525 if (need_update != NONE) {
526 bv->updateInset(const_cast<InsetTabular *>(this));
533 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
535 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
540 if (inset == tabular->GetCellInset(actcell)) {
541 lyxerr[Debug::INSETTEXT] << "OK" << endl;
542 the_locking_inset = tabular->GetCellInset(actcell);
545 } else if (!the_locking_inset) {
546 int const n = tabular->GetNumberOfCells();
547 int const id = inset->id();
548 for (int i = 0; i < n; ++i) {
549 InsetText * in = tabular->GetCellInset(i);
552 the_locking_inset = in;
557 if (in->getInsetFromID(id)) {
560 return the_locking_inset->lockInsetInInset(bv, inset);
563 } else if (the_locking_inset && (the_locking_inset == inset)) {
564 lyxerr[Debug::INSETTEXT] << "OK" << endl;
566 } else if (the_locking_inset) {
567 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
568 return the_locking_inset->lockInsetInInset(bv, inset);
570 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
575 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
578 if (!the_locking_inset)
580 if (the_locking_inset == inset) {
581 the_locking_inset->insetUnlock(bv);
583 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
589 updateLocal(bv, CELL);
590 // this has to be here otherwise we don't redraw the cell!
591 the_locking_inset = 0;
594 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
595 if (inset->lyxCode() == TABULAR_CODE &&
596 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
597 InsetTabularMailer mailer(*this);
598 mailer.updateDialog(bv);
607 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
609 Inset * tl_inset = inset;
610 // look if this inset is really inside myself!
611 while(tl_inset->owner() && tl_inset->owner() != this)
612 tl_inset = tl_inset->owner();
613 // if we enter here it's not ower inset
614 if (!tl_inset->owner())
616 // we only have to do this if this is a subinset of our cells
617 if (tl_inset != inset) {
618 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
621 updateLocal(bv, CELL);
626 int InsetTabular::insetInInsetY() const
628 if (!the_locking_inset)
630 return inset_y + the_locking_inset->insetInInsetY();
634 UpdatableInset * InsetTabular::getLockingInset() const
636 return the_locking_inset ? the_locking_inset->getLockingInset() :
637 const_cast<InsetTabular *>(this);
641 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
645 if (the_locking_inset)
646 return the_locking_inset->getFirstLockingInsetOfType(c);
651 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
653 if (the_locking_inset)
654 return the_locking_inset->insertInset(bv, inset);
659 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
661 if (hasSelection() && cmd.button() == mouse_button::button3)
664 if (hasSelection()) {
666 updateLocal(cmd.view(), SELECTION);
669 int const ocell = actcell;
670 int const orow = actrow;
671 BufferView * bv = cmd.view();
675 the_locking_inset = 0;
679 setPos(bv, cmd.x, cmd.y);
681 updateLocal(bv, NONE);
684 if (cmd.button() == mouse_button::button3) {
685 if ((ocell != actcell) && the_locking_inset) {
686 the_locking_inset->insetUnlock(bv);
687 updateLocal(bv, CELL);
688 the_locking_inset = 0;
694 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
696 if ((ocell == actcell) && the_locking_inset && inset_hit) {
698 FuncRequest cmd1 = cmd;
701 the_locking_inset->localDispatch(cmd1);
705 if (the_locking_inset) {
706 the_locking_inset->insetUnlock(bv);
707 updateLocal(bv, CELL);
708 the_locking_inset = 0;
711 if (cmd.button() == mouse_button::button2) {
712 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
716 if (inset_hit && bv->theLockingInset()) {
717 if (!bv->lockInset(static_cast<UpdatableInset*>
718 (tabular->GetCellInset(actcell))))
720 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
723 FuncRequest cmd1 = cmd;
726 the_locking_inset->localDispatch(cmd1);
732 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
735 if (the_locking_inset) {
736 FuncRequest cmd1 = cmd;
739 ret = the_locking_inset->localDispatch(cmd1);
741 if (cmd.button() == mouse_button::button3 && !ret) {
742 InsetTabularMailer mailer(*this);
743 mailer.showDialog(cmd.view());
750 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
752 if (the_locking_inset) {
753 FuncRequest cmd1 = cmd;
756 the_locking_inset->localDispatch(cmd1);
760 BufferView * bv = cmd.view();
761 int const old_cell = actcell;
763 setPos(bv, cmd.x, cmd.y);
764 if (!hasSelection()) {
765 setSelection(actcell, actcell);
766 updateLocal(bv, SELECTION);
767 } else if (old_cell != actcell) {
768 setSelection(sel_cell_start, actcell);
769 updateLocal(bv, SELECTION);
774 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
776 // We need to save the value of the_locking_inset as the call to
777 // the_locking_inset->localDispatch might unlock it.
778 old_locking_inset = the_locking_inset;
779 RESULT result = UpdatableInset::localDispatch(cmd);
781 BufferView * bv = cmd.view();
782 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
787 if (cmd.action < 0 && cmd.argument.empty())
790 bool hs = hasSelection();
793 // this one have priority over the locked InsetText, if we're not already
794 // inside another tabular then that one get's priority!
795 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
796 switch (cmd.action) {
797 case LFUN_MOUSE_PRESS:
801 case LFUN_MOUSE_MOTION:
802 lfunMouseMotion(cmd);
805 case LFUN_MOUSE_RELEASE:
806 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
808 case LFUN_CELL_BACKWARD:
809 case LFUN_CELL_FORWARD:
810 unlockInsetInInset(bv, the_locking_inset);
811 if (cmd.action == LFUN_CELL_FORWARD)
812 moveNextCell(bv, old_locking_inset != 0);
814 movePrevCell(bv, old_locking_inset != 0);
817 updateLocal(bv, SELECTION);
818 if (!the_locking_inset) {
819 return DISPATCHED_NOUPDATE;
822 // this to avoid compiler warnings.
828 kb_action action = cmd.action;
829 string arg = cmd.argument;
830 if (the_locking_inset) {
831 result = the_locking_inset->localDispatch(cmd);
832 if (result == DISPATCHED_NOUPDATE) {
835 if (sc != scroll()) { // inset has been scrolled
836 updateLocal(bv, FULL);
839 } else if (result == DISPATCHED) {
840 updateLocal(bv, CELL);
842 } else if (result == FINISHED_UP) {
844 // Make sure to reset status message after
845 // exiting, e.g. math inset
846 bv->owner()->clearMessage();
847 } else if (result == FINISHED_DOWN) {
849 bv->owner()->clearMessage();
850 } else if (result == FINISHED_RIGHT) {
852 bv->owner()->clearMessage();
853 } else if (result == FINISHED) {
854 bv->owner()->clearMessage();
860 // --- Cursor Movements ----------------------------------
861 case LFUN_RIGHTSEL: {
862 int const start = hasSelection() ? sel_cell_start : actcell;
863 if (tabular->IsLastCellInRow(actcell)) {
864 setSelection(start, actcell);
869 // if we are starting a selection, only select
870 // the current cell at the beginning
871 if (hasSelection()) {
872 moveRight(bv, false);
875 setSelection(start, end);
876 updateLocal(bv, SELECTION);
880 result = moveRight(bv);
883 updateLocal(bv, SELECTION);
886 int const start = hasSelection() ? sel_cell_start : actcell;
887 if (tabular->IsFirstCellInRow(actcell)) {
888 setSelection(start, actcell);
893 // if we are starting a selection, only select
894 // the current cell at the beginning
895 if (hasSelection()) {
899 setSelection(start, end);
900 updateLocal(bv, SELECTION);
904 result = moveLeft(bv);
907 updateLocal(bv, SELECTION);
910 int const start = hasSelection() ? sel_cell_start : actcell;
911 int const ocell = actcell;
912 // if we are starting a selection, only select
913 // the current cell at the beginning
914 if (hasSelection()) {
916 if ((ocell == sel_cell_end) ||
917 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
918 setSelection(start, tabular->GetCellBelow(sel_cell_end));
920 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
922 setSelection(start, start);
924 updateLocal(bv, SELECTION);
928 result = moveDown(bv, old_locking_inset != 0);
931 updateLocal(bv, SELECTION);
935 int const start = hasSelection() ? sel_cell_start : actcell;
936 int const ocell = actcell;
937 // if we are starting a selection, only select
938 // the current cell at the beginning
939 if (hasSelection()) {
941 if ((ocell == sel_cell_end) ||
942 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
943 setSelection(start, tabular->GetCellAbove(sel_cell_end));
945 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
947 setSelection(start, start);
949 updateLocal(bv, SELECTION);
953 result = moveUp(bv, old_locking_inset != 0);
956 updateLocal(bv, SELECTION);
959 UpdateCodes code = CURSOR;
965 unlockInsetInInset(bv, the_locking_inset);
966 if (bv->text->top_y() + bv->painter().paperHeight() <
967 (top_baseline + tabular->GetHeightOfTabular()))
969 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
971 actcell = tabular->GetCellBelow(first_visible_cell) + column;
973 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
976 updateLocal(bv, code);
980 UpdateCodes code = CURSOR;
986 unlockInsetInInset(bv, the_locking_inset);
987 if (top_baseline < 0) {
988 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
990 if (top_baseline > 0)
993 actcell = tabular->GetCellBelow(first_visible_cell) + column;
998 updateLocal(bv, code);
1001 // none of these make sense for insettabular,
1002 // but we must catch them to prevent any
1003 // selection from being confused
1007 case LFUN_WORDLEFTSEL:
1008 case LFUN_WORDRIGHT:
1009 case LFUN_WORDRIGHTSEL:
1011 case LFUN_DOWN_PARAGRAPH:
1012 case LFUN_DOWN_PARAGRAPHSEL:
1013 case LFUN_UP_PARAGRAPH:
1014 case LFUN_UP_PARAGRAPHSEL:
1015 case LFUN_BACKSPACE:
1020 case LFUN_BEGINNINGBUF:
1021 case LFUN_BEGINNINGBUFSEL:
1023 case LFUN_ENDBUFSEL:
1025 case LFUN_LAYOUT_TABULAR: {
1026 InsetTabularMailer mailer(*this);
1027 mailer.showDialog(bv);
1030 case LFUN_INSET_DIALOG_UPDATE: {
1031 InsetTabularMailer mailer(*this);
1032 mailer.updateDialog(bv);
1035 case LFUN_TABULAR_FEATURE:
1036 if (!tabularFeatures(bv, arg))
1037 result = UNDISPATCHED;
1039 // insert file functions
1040 case LFUN_FILE_INSERT_ASCII_PARA:
1041 case LFUN_FILE_INSERT_ASCII:
1043 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1046 if (insertAsciiString(bv, tmpstr, false))
1047 updateLocal(bv, INIT);
1049 result = UNDISPATCHED;
1052 // cut and paste functions
1054 if (!copySelection(bv))
1058 setUndo(bv, Undo::DELETE,
1059 bv->text->cursor.par(),
1060 boost::next(bv->text->cursor.par()));
1061 cutSelection(bv->buffer()->params);
1062 updateLocal(bv, INIT);
1065 if (!hasSelection())
1070 case LFUN_PASTESELECTION:
1072 string const clip(bv->getClipboard());
1076 if (clip.find('\t') != string::npos) {
1080 string::size_type len = clip.length();
1081 string::size_type p = 0;
1084 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1092 maxCols = max(cols, maxCols);
1098 maxCols = max(cols, maxCols);
1099 delete paste_tabular;
1100 paste_tabular = new LyXTabular(bv->buffer()->params,
1101 this, rows, maxCols);
1102 string::size_type op = 0;
1104 int cells = paste_tabular->GetNumberOfCells();
1106 while ((cell < cells) && (p < len) &&
1107 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1112 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1117 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1118 while (cols++ < maxCols)
1126 // check for the last cell if there is no trailing '\n'
1127 if ((cell < cells) && (op < len))
1128 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1131 if (!insertAsciiString(bv, clip, true))
1134 // so that the clipboard is used and it goes on
1136 // and executes LFUN_PASTESELECTION in insettext!
1137 delete paste_tabular;
1142 if (hasPasteBuffer()) {
1143 setUndo(bv, Undo::INSERT,
1144 bv->text->cursor.par(),
1145 boost::next(bv->text->cursor.par()));
1147 updateLocal(bv, INIT);
1150 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1152 // handle font changing stuff on selection before we lock the inset
1153 // in the default part!
1154 result = UNDISPATCHED;
1165 case LFUN_UNDERLINE:
1166 case LFUN_FONT_SIZE:
1167 if (bv->dispatch(FuncRequest(bv, action, arg)))
1168 result = DISPATCHED;
1174 // we try to activate the actual inset and put this event down to
1175 // the insets dispatch function.
1176 if ((result == DISPATCHED) || the_locking_inset)
1179 if (activateCellInset(bv)) {
1180 // reset need_update setted in above function!
1182 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1183 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1184 unlockInsetInInset(bv, the_locking_inset);
1186 // we need to update if this was requested before
1187 updateLocal(bv, NONE);
1188 return UNDISPATCHED;
1191 // so the below CELL is not set because this is higher
1192 // priority and we get a full redraw
1193 need_update = SELECTION;
1196 updateLocal(bv, CELL);
1201 if (result < FINISHED) {
1202 if (!the_locking_inset) {
1203 if (bv->fitCursor())
1204 updateLocal(bv, FULL);
1207 bv->unlockInset(this);
1212 int InsetTabular::latex(Buffer const * buf, ostream & os,
1213 bool fragile, bool fp) const
1215 return tabular->latex(buf, os, fragile, fp);
1219 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1222 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1224 return tabular->ascii(buf, os, 0, false,0);
1228 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1231 int const ret = tabular->ascii(buf,os,
1232 (int)parOwner()->params().depth(),
1239 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1244 // if the table is inside a float it doesn't need the informaltable
1245 // wrapper. Search for it.
1246 for(master = owner();
1247 master && master->lyxCode() != Inset::FLOAT_CODE;
1248 master = master->owner());
1251 os << "<informaltable>";
1256 ret+= tabular->docbook(buf, os, mixcont);
1258 os << "</informaltable>";
1267 void InsetTabular::validate(LaTeXFeatures & features) const
1269 tabular->Validate(features);
1273 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1279 bool changed = false;
1281 // FIXME: since InsetText ignores this anyway, it doesn't
1282 // matter what we pass it. Ugly
1285 // if we have a locking_inset we should have to check only this cell for
1286 // change so I'll try this to have a boost, but who knows ;)
1287 if ((need_update != INIT) &&
1288 (the_locking_inset == tabular->GetCellInset(actcell))) {
1289 for(int i = 0; i < tabular->columns(); ++i) {
1290 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1292 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1295 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1296 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1297 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1300 for (int i = 0; i < tabular->rows(); ++i) {
1303 for (int j = 0; j < tabular->columns(); ++j) {
1304 if (tabular->IsPartOfMultiColumn(i,j))
1307 inset = tabular->GetCellInset(cell);
1308 if (!reinit && !tabular->GetPWidth(cell).zero())
1309 inset->update(bv, false);
1310 maxAsc = max(maxAsc, inset->ascent(bv, font));
1311 maxDesc = max(maxDesc, inset->descent(bv, font));
1312 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1314 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1315 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1323 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1325 if (the_locking_inset) {
1326 the_locking_inset->getCursor(bv, x, y);
1331 y = cursor_.y() + InsetTabular::y();
1334 int desc = tabular->GetDescentOfRow(actrow);
1336 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1338 y += ADD_TO_HEIGHT * 2;
1339 y += TEXT_TO_INSET_OFFSET;
1343 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1345 if (the_locking_inset) {
1346 the_locking_inset->getCursorPos(bv, x, y);
1349 x = cursor_.x() - top_x;
1354 void InsetTabular::fitInsetCursor(BufferView * bv) const
1356 if (the_locking_inset) {
1357 int old_top_y = bv->text->top_y();
1358 the_locking_inset->fitInsetCursor(bv);
1359 if (old_top_y != bv->text->top_y())
1365 int const asc = font_metrics::maxAscent(font);
1366 int const desc = font_metrics::maxDescent(font);
1369 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1374 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1378 actcell = actrow = actcol = 0;
1379 int ly = tabular->GetDescentOfRow(actrow);
1381 // first search the right row
1382 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1383 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1384 tabular->GetAscentOfRow(actrow + 1) +
1385 tabular->GetAdditionalHeight(actrow + 1));
1387 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1389 actcell = tabular->GetCellNumber(actrow, actcol);
1391 // now search the right column
1392 int lx = tabular->GetWidthOfColumn(actcell) -
1393 tabular->GetAdditionalWidth(actcell);
1394 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1395 lx += tabular->GetWidthOfColumn(actcell + 1)
1396 + tabular->GetAdditionalWidth(actcell);
1398 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1403 int InsetTabular::getCellXPos(int cell) const
1407 for (; !tabular->IsFirstCellInRow(c); --c)
1409 int lx = tabular->GetWidthOfColumn(cell);
1410 for (; c < cell; ++c) {
1411 lx += tabular->GetWidthOfColumn(c);
1413 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1417 void InsetTabular::resetPos(BufferView * bv) const
1419 #ifdef WITH_WARNINGS
1420 #warning This should be fixed in the right manner (20011128 Jug)
1422 // fast hack to fix infinite repaintings!
1423 if (in_reset_pos > 0)
1427 actcol = tabular->column_of_cell(actcell);
1430 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1431 if (tabular->IsLastCellInRow(cell)) {
1432 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1433 tabular->GetAscentOfRow(actrow + 1) +
1434 tabular->GetAdditionalHeight(actrow + 1));
1438 if (!locked || nodraw()) {
1439 if (the_locking_inset)
1440 inset_y = cursor_.y();
1443 // we need this only from here on!!!
1445 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1446 int new_x = getCellXPos(actcell);
1447 int old_x = cursor_.x();
1450 // cursor.x(getCellXPos(actcell) + offset);
1451 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1452 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1455 updateLocal(bv, FULL);
1456 } else if (the_locking_inset &&
1457 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1459 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1460 if (xx > (bv->workWidth()-20)) {
1461 scroll(bv, -(xx - bv->workWidth() + 60));
1462 updateLocal(bv, FULL);
1463 } else if (xx < 20) {
1469 updateLocal(bv, FULL);
1471 } else if ((cursor_.x() - offset) > 20 &&
1472 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1473 > (bv->workWidth() - 20)) {
1474 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1475 updateLocal(bv, FULL);
1476 } else if ((cursor_.x() - offset) < 20) {
1477 scroll(bv, 20 - cursor_.x() + offset);
1478 updateLocal(bv, FULL);
1479 } else if (scroll() && top_x > 20 &&
1480 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1481 scroll(bv, old_x - cursor_.x());
1482 updateLocal(bv, FULL);
1484 if (the_locking_inset) {
1485 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1486 inset_y = cursor_.y();
1488 if ((!the_locking_inset ||
1489 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1490 actcell != oldcell) {
1491 InsetTabular * inset = const_cast<InsetTabular *>(this);
1492 InsetTabularMailer mailer(*inset);
1493 mailer.updateDialog(bv);
1500 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1502 if (lock && !old_locking_inset) {
1503 if (activateCellInset(bv))
1506 bool moved = isRightToLeft(bv)
1507 ? movePrevCell(bv) : moveNextCell(bv);
1509 return FINISHED_RIGHT;
1510 if (lock && activateCellInset(bv))
1514 return DISPATCHED_NOUPDATE;
1518 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1520 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1523 if (lock) { // behind the inset
1524 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1528 return DISPATCHED_NOUPDATE;
1532 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1534 int const ocell = actcell;
1535 actcell = tabular->GetCellAbove(actcell);
1536 if (actcell == ocell) // we moved out of the inset
1542 if (old_locking_inset) {
1543 old_locking_inset->getCursorPos(bv, x, y);
1544 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1546 if (activateCellInset(bv, x, 0))
1549 return DISPATCHED_NOUPDATE;
1553 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1555 int const ocell = actcell;
1556 actcell = tabular->GetCellBelow(actcell);
1557 if (actcell == ocell) // we moved out of the inset
1558 return FINISHED_DOWN;
1563 if (old_locking_inset) {
1564 old_locking_inset->getCursorPos(bv, x, y);
1565 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1567 if (activateCellInset(bv, x, 0))
1570 return DISPATCHED_NOUPDATE;
1574 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1576 if (isRightToLeft(bv)) {
1577 if (tabular->IsFirstCellInRow(actcell)) {
1578 int row = tabular->row_of_cell(actcell);
1579 if (row == tabular->rows() - 1)
1581 actcell = tabular->GetLastCellInRow(row);
1582 actcell = tabular->GetCellBelow(actcell);
1589 if (tabular->IsLastCell(actcell))
1594 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1595 isRightToLeftPar(bv->buffer()->params);
1596 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1603 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1605 if (isRightToLeft(bv)) {
1606 if (tabular->IsLastCellInRow(actcell)) {
1607 int row = tabular->row_of_cell(actcell);
1610 actcell = tabular->GetFirstCellInRow(row);
1611 actcell = tabular->GetCellAbove(actcell);
1613 if (tabular->IsLastCell(actcell))
1618 if (!actcell) // first cell
1623 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1624 isRightToLeftPar(bv->buffer()->params);
1625 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1632 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1636 setSelection(0, tabular->GetNumberOfCells() - 1);
1638 if (hasSelection()) {
1639 setUndo(bv, Undo::EDIT,
1640 bv->text->cursor.par(),
1641 boost::next(bv->text->cursor.par()));
1642 bool const frozen = undo_frozen;
1645 // apply the fontchange on the whole selection
1650 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1651 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1652 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1653 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1660 updateLocal(bv, INIT);
1662 if (the_locking_inset)
1663 the_locking_inset->setFont(bv, font, tall);
1667 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1669 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1672 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1673 string const tmp = tabularFeature[i].feature;
1675 if (tmp == what.substr(0, tmp.length())) {
1676 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1677 //tabularFeatures[i].feature.length())) {
1678 action = tabularFeature[i].action;
1682 if (action == LyXTabular::LAST_ACTION)
1686 ltrim(what.substr(tabularFeature[i].feature.length()));
1687 tabularFeatures(bv, action, val);
1693 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1694 string const & special, bool & flag)
1696 if (special == "dl_above") {
1699 } else if (special == "dl_below") {
1700 ltt.bottomDL = flag;
1702 } else if (special == "empty") {
1714 void InsetTabular::tabularFeatures(BufferView * bv,
1715 LyXTabular::Feature feature,
1716 string const & value)
1722 bool setLines = false;
1723 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1724 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1727 case LyXTabular::M_ALIGN_LEFT:
1728 case LyXTabular::ALIGN_LEFT:
1729 setAlign = LYX_ALIGN_LEFT;
1731 case LyXTabular::M_ALIGN_RIGHT:
1732 case LyXTabular::ALIGN_RIGHT:
1733 setAlign = LYX_ALIGN_RIGHT;
1735 case LyXTabular::M_ALIGN_CENTER:
1736 case LyXTabular::ALIGN_CENTER:
1737 setAlign = LYX_ALIGN_CENTER;
1739 case LyXTabular::ALIGN_BLOCK:
1740 setAlign = LYX_ALIGN_BLOCK;
1742 case LyXTabular::M_VALIGN_TOP:
1743 case LyXTabular::VALIGN_TOP:
1744 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1746 case LyXTabular::M_VALIGN_BOTTOM:
1747 case LyXTabular::VALIGN_BOTTOM:
1748 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1750 case LyXTabular::M_VALIGN_CENTER:
1751 case LyXTabular::VALIGN_CENTER:
1752 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1757 if (hasSelection()) {
1758 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1760 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1761 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1763 setUndo(bv, Undo::FINISH,
1764 bv->text->cursor.par(),
1765 boost::next(bv->text->cursor.par()));
1767 int row = tabular->row_of_cell(actcell);
1768 int column = tabular->column_of_cell(actcell);
1770 LyXTabular::ltType ltt;
1773 case LyXTabular::SET_PWIDTH:
1775 LyXLength const vallen(value);
1776 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1778 bool const update = (tmplen != vallen);
1779 tabular->SetColumnPWidth(actcell, vallen);
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 for (int i = 0; i < tabular->rows(); ++i) {
1806 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1809 updateLocal(bv, INIT);
1813 case LyXTabular::SET_SPECIAL_COLUMN:
1814 case LyXTabular::SET_SPECIAL_MULTI:
1815 tabular->SetAlignSpecial(actcell,value,feature);
1816 updateLocal(bv, FULL);
1818 case LyXTabular::APPEND_ROW:
1819 // append the row into the tabular
1820 unlockInsetInInset(bv, the_locking_inset);
1821 tabular->AppendRow(bv->buffer()->params, actcell);
1822 updateLocal(bv, INIT);
1824 case LyXTabular::APPEND_COLUMN:
1825 // append the column into the tabular
1826 unlockInsetInInset(bv, the_locking_inset);
1827 tabular->AppendColumn(bv->buffer()->params, actcell);
1828 actcell = tabular->GetCellNumber(row, column);
1829 updateLocal(bv, INIT);
1831 case LyXTabular::DELETE_ROW:
1832 unlockInsetInInset(bv, the_locking_inset);
1833 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1834 tabular->DeleteRow(sel_row_start);
1836 if (sel_row_start >= tabular->rows())
1838 actcell = tabular->GetCellNumber(sel_row_start, column);
1840 updateLocal(bv, INIT);
1842 case LyXTabular::DELETE_COLUMN:
1843 unlockInsetInInset(bv, the_locking_inset);
1844 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1845 tabular->DeleteColumn(sel_col_start);
1847 if (sel_col_start >= tabular->columns())
1849 actcell = tabular->GetCellNumber(row, sel_col_start);
1851 updateLocal(bv, INIT);
1853 case LyXTabular::M_TOGGLE_LINE_TOP:
1855 case LyXTabular::TOGGLE_LINE_TOP:
1857 bool lineSet = !tabular->TopLine(actcell, flag);
1858 for (int i = sel_row_start; i <= sel_row_end; ++i)
1859 for (int j = sel_col_start; j <= sel_col_end; ++j)
1860 tabular->SetTopLine(
1861 tabular->GetCellNumber(i, j),
1863 updateLocal(bv, INIT);
1867 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1869 case LyXTabular::TOGGLE_LINE_BOTTOM:
1871 bool lineSet = !tabular->BottomLine(actcell, flag);
1872 for (int i = sel_row_start; i <= sel_row_end; ++i)
1873 for (int j = sel_col_start; j <= sel_col_end; ++j)
1874 tabular->SetBottomLine(
1875 tabular->GetCellNumber(i, j),
1878 updateLocal(bv, INIT);
1882 case LyXTabular::M_TOGGLE_LINE_LEFT:
1884 case LyXTabular::TOGGLE_LINE_LEFT:
1886 bool lineSet = !tabular->LeftLine(actcell, flag);
1887 for (int i = sel_row_start; i <= sel_row_end; ++i)
1888 for (int j = sel_col_start; j <= sel_col_end; ++j)
1889 tabular->SetLeftLine(
1890 tabular->GetCellNumber(i,j),
1893 updateLocal(bv, INIT);
1897 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1899 case LyXTabular::TOGGLE_LINE_RIGHT:
1901 bool lineSet = !tabular->RightLine(actcell, flag);
1902 for (int i = sel_row_start; i <= sel_row_end; ++i)
1903 for (int j = sel_col_start; j <= sel_col_end; ++j)
1904 tabular->SetRightLine(
1905 tabular->GetCellNumber(i,j),
1908 updateLocal(bv, INIT);
1912 case LyXTabular::M_ALIGN_LEFT:
1913 case LyXTabular::M_ALIGN_RIGHT:
1914 case LyXTabular::M_ALIGN_CENTER:
1916 case LyXTabular::ALIGN_LEFT:
1917 case LyXTabular::ALIGN_RIGHT:
1918 case LyXTabular::ALIGN_CENTER:
1919 case LyXTabular::ALIGN_BLOCK:
1920 for (int i = sel_row_start; i <= sel_row_end; ++i)
1921 for (int j = sel_col_start; j <= sel_col_end; ++j)
1922 tabular->SetAlignment(
1923 tabular->GetCellNumber(i, j),
1926 updateLocal(bv, INIT);
1928 case LyXTabular::M_VALIGN_TOP:
1929 case LyXTabular::M_VALIGN_BOTTOM:
1930 case LyXTabular::M_VALIGN_CENTER:
1932 case LyXTabular::VALIGN_TOP:
1933 case LyXTabular::VALIGN_BOTTOM:
1934 case LyXTabular::VALIGN_CENTER:
1935 for (int i = sel_row_start; i <= sel_row_end; ++i)
1936 for (int j = sel_col_start; j <= sel_col_end; ++j)
1937 tabular->SetVAlignment(
1938 tabular->GetCellNumber(i, j),
1940 updateLocal(bv, INIT);
1942 case LyXTabular::MULTICOLUMN:
1944 if (sel_row_start != sel_row_end) {
1945 #ifdef WITH_WARNINGS
1946 #warning Need I say it ? This is horrible.
1948 Alert::error(_("Error setting multicolumn"),
1949 _("You cannot set multicolumn vertically."));
1952 // just multicol for one Single Cell
1953 if (!hasSelection()) {
1954 // check wether we are completly in a multicol
1955 if (tabular->IsMultiColumn(actcell)) {
1956 tabular->UnsetMultiColumn(actcell);
1957 updateLocal(bv, INIT);
1959 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1960 updateLocal(bv, CELL);
1964 // we have a selection so this means we just add all this
1965 // cells to form a multicolumn cell
1969 if (sel_cell_start > sel_cell_end) {
1970 s_start = sel_cell_end;
1971 s_end = sel_cell_start;
1973 s_start = sel_cell_start;
1974 s_end = sel_cell_end;
1976 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1979 updateLocal(bv, INIT);
1982 case LyXTabular::SET_ALL_LINES:
1984 case LyXTabular::UNSET_ALL_LINES:
1985 for (int i = sel_row_start; i <= sel_row_end; ++i)
1986 for (int j = sel_col_start; j <= sel_col_end; ++j)
1987 tabular->SetAllLines(
1988 tabular->GetCellNumber(i,j), setLines);
1989 updateLocal(bv, INIT);
1991 case LyXTabular::SET_LONGTABULAR:
1992 tabular->SetLongTabular(true);
1993 updateLocal(bv, INIT); // because this toggles displayed
1995 case LyXTabular::UNSET_LONGTABULAR:
1996 tabular->SetLongTabular(false);
1997 updateLocal(bv, INIT); // because this toggles displayed
1999 case LyXTabular::SET_ROTATE_TABULAR:
2000 tabular->SetRotateTabular(true);
2002 case LyXTabular::UNSET_ROTATE_TABULAR:
2003 tabular->SetRotateTabular(false);
2005 case LyXTabular::SET_ROTATE_CELL:
2006 for (int i = sel_row_start; i <= sel_row_end; ++i)
2007 for (int j = sel_col_start; j<=sel_col_end; ++j)
2008 tabular->SetRotateCell(
2009 tabular->GetCellNumber(i, j),
2012 case LyXTabular::UNSET_ROTATE_CELL:
2013 for (int i = sel_row_start; i <= sel_row_end; ++i)
2014 for (int j = sel_col_start; j <= sel_col_end; ++j)
2015 tabular->SetRotateCell(
2016 tabular->GetCellNumber(i, j), false);
2018 case LyXTabular::SET_USEBOX:
2020 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2021 if (val == tabular->GetUsebox(actcell))
2022 val = LyXTabular::BOX_NONE;
2023 for (int i = sel_row_start; i <= sel_row_end; ++i)
2024 for (int j = sel_col_start; j <= sel_col_end; ++j)
2026 tabular->GetCellNumber(i, j), val);
2029 case LyXTabular::UNSET_LTFIRSTHEAD:
2031 case LyXTabular::SET_LTFIRSTHEAD:
2032 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2033 checkLongtableSpecial(ltt, value, flag);
2034 tabular->SetLTHead(row, flag, ltt, true);
2036 case LyXTabular::UNSET_LTHEAD:
2038 case LyXTabular::SET_LTHEAD:
2039 (void)tabular->GetRowOfLTHead(row, ltt);
2040 checkLongtableSpecial(ltt, value, flag);
2041 tabular->SetLTHead(row, flag, ltt, false);
2043 case LyXTabular::UNSET_LTFOOT:
2045 case LyXTabular::SET_LTFOOT:
2046 (void)tabular->GetRowOfLTFoot(row, ltt);
2047 checkLongtableSpecial(ltt, value, flag);
2048 tabular->SetLTFoot(row, flag, ltt, false);
2050 case LyXTabular::UNSET_LTLASTFOOT:
2052 case LyXTabular::SET_LTLASTFOOT:
2053 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2054 checkLongtableSpecial(ltt, value, flag);
2055 tabular->SetLTFoot(row, flag, ltt, true);
2057 case LyXTabular::SET_LTNEWPAGE:
2059 bool what = !tabular->GetLTNewPage(row);
2060 tabular->SetLTNewPage(row, what);
2063 // dummy stuff just to avoid warnings
2064 case LyXTabular::LAST_ACTION:
2068 InsetTabularMailer mailer(*this);
2069 mailer.updateDialog(bv);
2073 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2076 UpdatableInset * inset =
2077 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2078 LyXFont font(LyXFont::ALL_SANE);
2080 x = inset->x() + inset->width(bv, font);
2081 y = inset->descent(bv, font);
2083 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2084 //inset_y = cursor.y();
2085 inset->edit(bv, x, y, button);
2086 if (!the_locking_inset)
2088 updateLocal(bv, CELL);
2089 return (the_locking_inset != 0);
2093 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2094 mouse_button::state button)
2096 inset_x = cursor_.x()
2097 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2098 inset_y = cursor_.y();
2099 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2103 bool InsetTabular::insetHit(BufferView *, int x, int) const
2106 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2110 // This returns paperWidth() if the cell-width is unlimited or the width
2111 // in pixels if we have a pwidth for this cell.
2112 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2114 LyXLength const len = tabular->GetPWidth(cell);
2118 return len.inPixels(latexTextWidth(bv));
2122 int InsetTabular::getMaxWidth(BufferView * bv,
2123 UpdatableInset const * inset) const
2125 int cell = tabular->GetCellFromInset(inset, actcell);
2128 lyxerr << "Own inset not found, shouldn't really happen!"
2133 int w = getMaxWidthOfCell(bv, cell);
2135 // because the inset then subtracts it's top_x and owner->x()
2136 w += (inset->x() - top_x);
2143 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2145 resizeLyXText(bv, recursive);
2149 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2152 for(int i = 0; i < tabular->rows(); ++i) {
2153 for(int j = 0; j < tabular->columns(); ++j) {
2154 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2162 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2163 bool const recursive) const
2165 if (the_locking_inset)
2166 return the_locking_inset->getLyXText(bv, recursive);
2168 // if we're locked lock the actual insettext and return it's LyXText!!!
2170 UpdatableInset * inset =
2171 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2172 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2173 return the_locking_inset->getLyXText(bv, recursive);
2176 return Inset::getLyXText(bv, recursive);
2180 bool InsetTabular::showInsetDialog(BufferView * bv) const
2182 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2183 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2184 InsetTabularMailer mailer(*tmp);
2185 mailer.showDialog(bv);
2191 void InsetTabular::openLayoutDialog(BufferView * bv) const
2193 if (the_locking_inset) {
2194 InsetTabular * i = static_cast<InsetTabular *>
2195 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2197 i->openLayoutDialog(bv);
2201 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2202 InsetTabularMailer mailer(*tmp);
2203 mailer.showDialog(bv);
2208 // function returns an object as defined in func_status.h:
2209 // states OK, Unknown, Disabled, On, Off.
2211 FuncStatus InsetTabular::getStatus(string const & what) const
2213 int action = LyXTabular::LAST_ACTION;
2217 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2218 string const tmp = tabularFeature[i].feature;
2219 if (tmp == what.substr(0, tmp.length())) {
2220 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2221 // tabularFeatures[i].feature.length())) {
2222 action = tabularFeature[i].action;
2226 if (action == LyXTabular::LAST_ACTION) {
2228 return status.unknown(true);
2231 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2236 LyXTabular::ltType dummyltt;
2239 if (hasSelection()) {
2240 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2242 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2246 case LyXTabular::SET_PWIDTH:
2247 case LyXTabular::SET_MPWIDTH:
2248 case LyXTabular::SET_SPECIAL_COLUMN:
2249 case LyXTabular::SET_SPECIAL_MULTI:
2250 case LyXTabular::APPEND_ROW:
2251 case LyXTabular::APPEND_COLUMN:
2252 case LyXTabular::DELETE_ROW:
2253 case LyXTabular::DELETE_COLUMN:
2254 case LyXTabular::SET_ALL_LINES:
2255 case LyXTabular::UNSET_ALL_LINES:
2256 return status.clear();
2258 case LyXTabular::MULTICOLUMN:
2259 status.setOnOff(tabular->IsMultiColumn(actcell));
2261 case LyXTabular::M_TOGGLE_LINE_TOP:
2263 case LyXTabular::TOGGLE_LINE_TOP:
2264 status.setOnOff(tabular->TopLine(actcell, flag));
2266 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2268 case LyXTabular::TOGGLE_LINE_BOTTOM:
2269 status.setOnOff(tabular->BottomLine(actcell, flag));
2271 case LyXTabular::M_TOGGLE_LINE_LEFT:
2273 case LyXTabular::TOGGLE_LINE_LEFT:
2274 status.setOnOff(tabular->LeftLine(actcell, flag));
2276 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2278 case LyXTabular::TOGGLE_LINE_RIGHT:
2279 status.setOnOff(tabular->RightLine(actcell, flag));
2281 case LyXTabular::M_ALIGN_LEFT:
2283 case LyXTabular::ALIGN_LEFT:
2284 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2286 case LyXTabular::M_ALIGN_RIGHT:
2288 case LyXTabular::ALIGN_RIGHT:
2289 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2291 case LyXTabular::M_ALIGN_CENTER:
2293 case LyXTabular::ALIGN_CENTER:
2294 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2296 case LyXTabular::ALIGN_BLOCK:
2297 status.disabled(tabular->GetPWidth(actcell).zero());
2298 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2300 case LyXTabular::M_VALIGN_TOP:
2302 case LyXTabular::VALIGN_TOP:
2303 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2305 case LyXTabular::M_VALIGN_BOTTOM:
2307 case LyXTabular::VALIGN_BOTTOM:
2308 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2310 case LyXTabular::M_VALIGN_CENTER:
2312 case LyXTabular::VALIGN_CENTER:
2313 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2315 case LyXTabular::SET_LONGTABULAR:
2316 status.setOnOff(tabular->IsLongTabular());
2318 case LyXTabular::UNSET_LONGTABULAR:
2319 status.setOnOff(!tabular->IsLongTabular());
2321 case LyXTabular::SET_ROTATE_TABULAR:
2322 status.setOnOff(tabular->GetRotateTabular());
2324 case LyXTabular::UNSET_ROTATE_TABULAR:
2325 status.setOnOff(!tabular->GetRotateTabular());
2327 case LyXTabular::SET_ROTATE_CELL:
2328 status.setOnOff(tabular->GetRotateCell(actcell));
2330 case LyXTabular::UNSET_ROTATE_CELL:
2331 status.setOnOff(!tabular->GetRotateCell(actcell));
2333 case LyXTabular::SET_USEBOX:
2334 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2336 case LyXTabular::SET_LTFIRSTHEAD:
2337 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2339 case LyXTabular::SET_LTHEAD:
2340 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2342 case LyXTabular::SET_LTFOOT:
2343 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2345 case LyXTabular::SET_LTLASTFOOT:
2346 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2348 case LyXTabular::SET_LTNEWPAGE:
2349 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2353 status.disabled(true);
2360 vector<string> const InsetTabular::getLabelList() const
2362 return tabular->getLabelList();
2366 bool InsetTabular::copySelection(BufferView * bv)
2368 if (!hasSelection())
2371 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2372 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2373 if (sel_col_start > sel_col_end) {
2374 sel_col_start = sel_col_end;
2375 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2377 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2379 int const columns = sel_col_end - sel_col_start + 1;
2381 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2382 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2383 if (sel_row_start > sel_row_end) {
2384 swap(sel_row_start, sel_row_end);
2386 int const rows = sel_row_end - sel_row_start + 1;
2388 delete paste_tabular;
2389 paste_tabular = new LyXTabular(bv->buffer()->params,
2390 this, *tabular); // rows, columns);
2391 for (int i = 0; i < sel_row_start; ++i)
2392 paste_tabular->DeleteRow(0);
2393 while (paste_tabular->rows() > rows)
2394 paste_tabular->DeleteRow(rows);
2395 paste_tabular->SetTopLine(0, true, true);
2396 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2398 for (int i = 0; i < sel_col_start; ++i)
2399 paste_tabular->DeleteColumn(0);
2400 while (paste_tabular->columns() > columns)
2401 paste_tabular->DeleteColumn(columns);
2402 paste_tabular->SetLeftLine(0, true, true);
2403 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2407 paste_tabular->ascii(bv->buffer(), sstr,
2408 (int)parOwner()->params().depth(), true, '\t');
2409 bv->stuffClipboard(STRCONV(sstr.str()));
2414 bool InsetTabular::pasteSelection(BufferView * bv)
2419 for (int r1 = 0, r2 = actrow;
2420 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2422 for(int c1 = 0, c2 = actcol;
2423 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2425 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2426 tabular->IsPartOfMultiColumn(r2,c2))
2428 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2432 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2436 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2437 int const n2 = tabular->GetCellNumber(r2, c2);
2438 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2439 tabular->GetCellInset(n2)->setOwner(this);
2440 tabular->GetCellInset(n2)->deleteLyXText(bv);
2441 tabular->GetCellInset(n2)->markNew();
2448 bool InsetTabular::cutSelection(BufferParams const & bp)
2450 if (!hasSelection())
2453 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2454 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2455 if (sel_col_start > sel_col_end) {
2456 sel_col_start = sel_col_end;
2457 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2459 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2461 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2462 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2463 if (sel_row_start > sel_row_end) {
2464 swap(sel_row_start, sel_row_end);
2466 if (sel_cell_start > sel_cell_end) {
2467 swap(sel_cell_start, sel_cell_end);
2469 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2470 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2471 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2478 bool InsetTabular::isRightToLeft(BufferView * bv)
2480 return bv->getParentLanguage(this)->RightToLeft();
2484 bool InsetTabular::nodraw() const
2486 if (!UpdatableInset::nodraw() && the_locking_inset)
2487 return the_locking_inset->nodraw();
2488 return UpdatableInset::nodraw();
2492 int InsetTabular::scroll(bool recursive) const
2494 int sx = UpdatableInset::scroll(false);
2496 if (recursive && the_locking_inset)
2497 sx += the_locking_inset->scroll(recursive);
2503 void InsetTabular::getSelection(int & srow, int & erow,
2504 int & scol, int & ecol) const
2506 int const start = hasSelection() ? sel_cell_start : actcell;
2507 int const end = hasSelection() ? sel_cell_end : actcell;
2509 srow = tabular->row_of_cell(start);
2510 erow = tabular->row_of_cell(end);
2515 scol = tabular->column_of_cell(start);
2516 ecol = tabular->column_of_cell(end);
2520 ecol = tabular->right_column_of_cell(end);
2525 ParagraphList * InsetTabular::getParagraphs(int i) const
2527 return (i < tabular->GetNumberOfCells())
2528 ? tabular->GetCellInset(i)->getParagraphs(0)
2533 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2535 if (the_locking_inset)
2536 return the_locking_inset->cursor(bv);
2537 return Inset::cursor(bv);
2541 Inset * InsetTabular::getInsetFromID(int id_arg) const
2544 return const_cast<InsetTabular *>(this);
2547 for(int i = 0; i < tabular->rows(); ++i) {
2548 for(int j = 0; j < tabular->columns(); ++j) {
2549 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2558 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2561 if (the_locking_inset) {
2562 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2563 if (!word.word().empty()) {
2567 if (tabular->IsLastCell(actcell)) {
2568 bv->unlockInset(const_cast<InsetTabular *>(this));
2570 return WordLangTuple();
2574 // otherwise we have to lock the next inset and ask for it's selecttion
2575 UpdatableInset * inset =
2576 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2577 inset->edit(bv, 0, 0, mouse_button::none);
2578 WordLangTuple word(selectNextWordInt(bv, value));
2580 if (!word.word().empty())
2586 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2588 // when entering this function the inset should be ALWAYS locked!
2589 lyx::Assert(the_locking_inset);
2591 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2592 if (!word.word().empty())
2595 if (tabular->IsLastCell(actcell)) {
2596 bv->unlockInset(const_cast<InsetTabular *>(this));
2597 return WordLangTuple();
2600 // otherwise we have to lock the next inset and ask for it's selecttion
2601 UpdatableInset * inset =
2602 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2604 return selectNextWordInt(bv, value);
2608 void InsetTabular::selectSelectedWord(BufferView * bv)
2610 if (the_locking_inset) {
2611 the_locking_inset->selectSelectedWord(bv);
2618 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2620 if (the_locking_inset) {
2621 the_locking_inset->toggleSelection(bv, kill_selection);
2626 void InsetTabular::markErased()
2630 while (!tabular->IsLastCell(cell)) {
2632 InsetText * inset = tabular->GetCellInset(cell);
2633 inset->markErased();
2638 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2640 if (the_locking_inset) {
2641 if (the_locking_inset->nextChange(bv, length)) {
2642 updateLocal(bv, CELL);
2645 if (tabular->IsLastCell(actcell))
2649 InsetText * inset = tabular->GetCellInset(actcell);
2650 if (inset->nextChange(bv, length)) {
2651 updateLocal(bv, FULL);
2654 while (!tabular->IsLastCell(actcell)) {
2656 inset = tabular->GetCellInset(actcell);
2657 if (inset->nextChange(bv, length)) {
2658 updateLocal(bv, FULL);
2666 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2670 if (the_locking_inset) {
2671 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2672 updateLocal(bv, CELL);
2675 if (tabular->IsLastCell(actcell))
2679 InsetText * inset = tabular->GetCellInset(cell);
2680 if (inset->searchForward(bv, str, cs, mw)) {
2681 updateLocal(bv, FULL);
2684 while (!tabular->IsLastCell(cell)) {
2686 inset = tabular->GetCellInset(cell);
2687 if (inset->searchForward(bv, str, cs, mw)) {
2688 updateLocal(bv, FULL);
2696 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2699 int cell = tabular->GetNumberOfCells();
2700 if (the_locking_inset) {
2701 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2702 updateLocal(bv, CELL);
2710 InsetText * inset = tabular->GetCellInset(cell);
2711 if (inset->searchBackward(bv, str, cs, mw)) {
2712 updateLocal(bv, CELL);
2720 bool InsetTabular::insetAllowed(Inset::Code code) const
2722 if (the_locking_inset)
2723 return the_locking_inset->insetAllowed(code);
2724 // we return true here because if the inset is not locked someone
2725 // wants to insert something in one of our insettexts and we generally
2731 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2733 const int cell = tabular->GetCellFromInset(in, actcell);
2736 return tabular->GetPWidth(cell).zero();
2738 // well we didn't obviously find it so maybe our owner knows more
2740 return owner()->forceDefaultParagraphs(in);
2741 // if we're here there is really something strange going on!!!
2745 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2748 if (buf.length() <= 0)
2754 string::size_type len = buf.length();
2755 string::size_type p = 0;
2758 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2767 maxCols = max(cols, maxCols);
2773 maxCols = max(cols, maxCols);
2774 LyXTabular * loctab;
2779 delete paste_tabular;
2780 paste_tabular = new LyXTabular(bv->buffer()->params,
2781 this, rows, maxCols);
2782 loctab = paste_tabular;
2785 loctab = tabular.get();
2791 string::size_type op = 0;
2792 int cells = loctab->GetNumberOfCells();
2795 rows = loctab->rows();
2796 int const columns = loctab->columns();
2798 while ((cell < cells) && (p < len) && (row < rows) &&
2799 (p = buf.find_first_of("\t\n", p)) != string::npos)
2805 // we can only set this if we are not too far right
2806 if (cols < columns) {
2807 InsetText * ti = loctab->GetCellInset(cell);
2808 LyXFont const font = ti->getLyXText(bv)->
2809 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2810 ti->setText(buf.substr(op, p - op), font);
2816 // we can only set this if we are not too far right
2817 if (cols < columns) {
2818 InsetText * ti = loctab->GetCellInset(cell);
2819 LyXFont const font = ti->getLyXText(bv)->
2820 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2821 ti->setText(buf.substr(op, p - op), font);
2826 cell = loctab->GetCellNumber(row, cols);
2832 // check for the last cell if there is no trailing '\n'
2833 if ((cell < cells) && (op < len)) {
2834 InsetText * ti = loctab->GetCellInset(cell);
2835 LyXFont const font = ti->getLyXText(bv)->
2836 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2837 ti->setText(buf.substr(op, len - op), font);
2844 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2846 int const rows = tabular->rows();
2847 int const columns = tabular->columns();
2848 for (int i = 0; i < rows; ++i) {
2849 for (int j = 0; j < columns; ++j) {
2850 tabular->GetCellInset(i,j)->addPreview(loader);
2856 string const InsetTabularMailer:: name_("tabular");
2858 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2863 string const InsetTabularMailer::inset2string() const
2865 return params2string(inset_);
2869 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2871 istringstream data(in);
2873 lex.setStream(data);
2875 #warning CHECK verify that this is a sane value to return.
2881 string const token = lex.getString();
2889 string const token = lex.getString();
2890 if (token != "\\active_cell")
2893 cell = lex.getInteger();
2896 // This is part of the inset proper that is usually swallowed
2897 // by Buffer::readInset
2900 string const token = lex.getString();
2901 if (token != "Tabular")
2908 BufferView * const bv = inset.view();
2909 Buffer const * const buffer = bv ? bv->buffer() : 0;
2911 inset.read(buffer, lex);
2913 // We can't set the active cell, but we can tell the frontend
2920 InsetTabularMailer::params2string(InsetTabular const & inset)
2922 BufferView * const bv = inset.view();
2923 Buffer const * const buffer = bv ? bv->buffer() : 0;
2928 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2929 inset.write(buffer, data);
2930 data << "\\end_inset\n";