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,
179 : UpdatableInset(tab, same_id), buffer(&buf)
181 tabular.reset(new LyXTabular(buf.params,
182 this, *(tab.tabular), same_id));
183 the_locking_inset = 0;
184 old_locking_inset = 0;
187 actrow = actcell = 0;
197 InsetTabular::~InsetTabular()
199 InsetTabularMailer mailer(*this);
204 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
206 return new InsetTabular(*this, buf, same_id);
210 BufferView * InsetTabular::view() const
212 return buffer->getUser();
216 void InsetTabular::write(Buffer const * buf, ostream & os) const
218 os << " Tabular" << endl;
219 tabular->Write(buf, os);
223 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
225 bool const old_format = (lex.getString() == "\\LyXTable");
227 tabular.reset(new LyXTabular(buf, this, lex));
235 string token = lex.getString();
236 while (lex.isOK() && (token != "\\end_inset")) {
238 token = lex.getString();
240 if (token != "\\end_inset") {
241 lex.printError("Missing \\end_inset at this point. "
247 void InsetTabular::dimension(BufferView *, LyXFont const &,
248 Dimension & dim) const
250 dim.a = tabular->GetAscentOfRow(0);
251 dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
252 dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
256 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
264 Painter & pain = bv->painter();
270 UpdatableInset::draw(bv, font, baseline, x);
273 x += static_cast<float>(scroll());
277 top_baseline = baseline;
278 x += ADD_TO_TABULAR_WIDTH;
282 first_visible_cell = -1;
283 for (i = 0; i < tabular->rows(); ++i) {
285 cell = tabular->GetCellNumber(i, 0);
286 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
287 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
289 baseline += tabular->GetDescentOfRow(i) +
290 tabular->GetAscentOfRow(i + 1) +
291 tabular->GetAdditionalHeight(i + 1);
294 for (j = 0; j < tabular->columns(); ++j) {
295 if (nx > bv->workWidth())
297 if (tabular->IsPartOfMultiColumn(i, j))
299 cx = nx + tabular->GetBeginningOfTextInCell(cell);
300 if (first_visible_cell < 0)
301 first_visible_cell = cell;
302 if (hasSelection()) {
303 drawCellSelection(pain, nx, baseline, i, j, cell);
306 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
307 drawCellLines(pain, nx, baseline, i, cell);
308 nx += tabular->GetWidthOfColumn(cell);
311 baseline += tabular->GetDescentOfRow(i) +
312 tabular->GetAscentOfRow(i + 1) +
313 tabular->GetAdditionalHeight(i + 1);
316 x -= ADD_TO_TABULAR_WIDTH;
317 x += width(bv, font);
322 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
323 int row, int cell) const
325 int x2 = x + tabular->GetWidthOfColumn(cell);
328 if (!tabular->topAlreadyDrawn(cell)) {
329 on_off = !tabular->TopLine(cell);
330 pain.line(x, baseline - tabular->GetAscentOfRow(row),
331 x2, baseline - tabular->GetAscentOfRow(row),
332 on_off ? LColor::tabularonoffline : LColor::tabularline,
333 on_off ? Painter::line_onoffdash : Painter::line_solid);
335 on_off = !tabular->BottomLine(cell);
336 pain.line(x, baseline + tabular->GetDescentOfRow(row),
337 x2, baseline + tabular->GetDescentOfRow(row),
338 on_off ? LColor::tabularonoffline : LColor::tabularline,
339 on_off ? Painter::line_onoffdash : Painter::line_solid);
340 if (!tabular->leftAlreadyDrawn(cell)) {
341 on_off = !tabular->LeftLine(cell);
342 pain.line(x, baseline - tabular->GetAscentOfRow(row),
343 x, baseline + tabular->GetDescentOfRow(row),
344 on_off ? LColor::tabularonoffline : LColor::tabularline,
345 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 on_off = !tabular->RightLine(cell);
348 pain.line(x2 - tabular->GetAdditionalWidth(cell),
349 baseline - tabular->GetAscentOfRow(row),
350 x2 - tabular->GetAdditionalWidth(cell),
351 baseline + tabular->GetDescentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
357 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
358 int row, int column, int cell) const
360 lyx::Assert(hasSelection());
361 int cs = tabular->column_of_cell(sel_cell_start);
362 int ce = tabular->column_of_cell(sel_cell_end);
365 cs = tabular->column_of_cell(sel_cell_end);
367 ce = tabular->right_column_of_cell(sel_cell_end);
370 int rs = tabular->row_of_cell(sel_cell_start);
371 int re = tabular->row_of_cell(sel_cell_end);
375 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
376 int w = tabular->GetWidthOfColumn(cell);
377 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
378 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
379 w, h, LColor::selection);
384 void InsetTabular::update(BufferView * bv, bool reinit)
390 owner()->update(bv, true);
397 if (calculate_dimensions_of_cells(bv, true))
400 owner()->update(bv, true);
404 if (the_locking_inset)
405 the_locking_inset->update(bv, reinit);
406 if (need_update < FULL &&
407 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
412 switch (need_update) {
416 if (calculate_dimensions_of_cells(bv, false)) {
431 string const InsetTabular::editMessage() const
433 return _("Opened table");
437 void InsetTabular::insetUnlock(BufferView * bv)
439 if (the_locking_inset) {
440 the_locking_inset->insetUnlock(bv);
441 updateLocal(bv, CELL);
442 the_locking_inset = 0;
447 if (scroll(false) || hasSelection()) {
452 updateLocal(bv, FULL);
457 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
460 calculate_dimensions_of_cells(bv, true);
462 if (!locked && what == CELL)
464 if (need_update < what) // only set this if it has greater update
467 if (need_update != NONE) {
468 bv->updateInset(const_cast<InsetTabular *>(this));
475 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
477 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
482 if (inset == tabular->GetCellInset(actcell)) {
483 lyxerr[Debug::INSETTEXT] << "OK" << endl;
484 the_locking_inset = tabular->GetCellInset(actcell);
487 } else if (!the_locking_inset) {
488 int const n = tabular->GetNumberOfCells();
489 int const id = inset->id();
490 for (int i = 0; i < n; ++i) {
491 InsetText * in = tabular->GetCellInset(i);
494 the_locking_inset = in;
499 if (in->getInsetFromID(id)) {
501 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
502 return the_locking_inset->lockInsetInInset(bv, inset);
505 } else if (the_locking_inset && (the_locking_inset == inset)) {
506 lyxerr[Debug::INSETTEXT] << "OK" << endl;
508 } else if (the_locking_inset) {
509 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
510 return the_locking_inset->lockInsetInInset(bv, inset);
512 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
517 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
520 if (!the_locking_inset)
522 if (the_locking_inset == inset) {
523 the_locking_inset->insetUnlock(bv);
525 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
531 updateLocal(bv, CELL);
532 // this has to be here otherwise we don't redraw the cell!
533 the_locking_inset = 0;
536 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
537 if (inset->lyxCode() == TABULAR_CODE &&
538 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
539 InsetTabularMailer mailer(*this);
540 mailer.updateDialog(bv);
549 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
551 Inset * tl_inset = inset;
552 // look if this inset is really inside myself!
553 while(tl_inset->owner() && tl_inset->owner() != this)
554 tl_inset = tl_inset->owner();
555 // if we enter here it's not ower inset
556 if (!tl_inset->owner())
558 // we only have to do this if this is a subinset of our cells
559 if (tl_inset != inset) {
560 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
563 updateLocal(bv, CELL);
568 int InsetTabular::insetInInsetY() const
570 if (!the_locking_inset)
572 return inset_y + the_locking_inset->insetInInsetY();
576 UpdatableInset * InsetTabular::getLockingInset() const
578 return the_locking_inset ? the_locking_inset->getLockingInset() :
579 const_cast<InsetTabular *>(this);
583 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
587 if (the_locking_inset)
588 return the_locking_inset->getFirstLockingInsetOfType(c);
593 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
595 if (the_locking_inset)
596 return the_locking_inset->insertInset(bv, inset);
601 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
603 if (hasSelection() && cmd.button() == mouse_button::button3)
606 if (hasSelection()) {
608 updateLocal(cmd.view(), SELECTION);
611 int const ocell = actcell;
612 int const orow = actrow;
613 BufferView * bv = cmd.view();
617 the_locking_inset = 0;
621 setPos(bv, cmd.x, cmd.y);
623 updateLocal(bv, NONE);
626 if (cmd.button() == mouse_button::button3) {
627 if ((ocell != actcell) && the_locking_inset) {
628 the_locking_inset->insetUnlock(bv);
629 updateLocal(bv, CELL);
630 the_locking_inset = 0;
636 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
638 if ((ocell == actcell) && the_locking_inset && inset_hit) {
640 FuncRequest cmd1 = cmd;
643 the_locking_inset->localDispatch(cmd1);
647 if (the_locking_inset) {
648 the_locking_inset->insetUnlock(bv);
649 updateLocal(bv, CELL);
650 the_locking_inset = 0;
653 if (cmd.button() == mouse_button::button2) {
654 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
658 if (inset_hit && bv->theLockingInset()) {
659 if (!bv->lockInset(static_cast<UpdatableInset*>
660 (tabular->GetCellInset(actcell))))
662 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
665 FuncRequest cmd1 = cmd;
668 the_locking_inset->localDispatch(cmd1);
674 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
677 if (the_locking_inset) {
678 FuncRequest cmd1 = cmd;
681 ret = the_locking_inset->localDispatch(cmd1);
683 if (cmd.button() == mouse_button::button3 && !ret) {
684 InsetTabularMailer mailer(*this);
685 mailer.showDialog(cmd.view());
692 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
694 if (the_locking_inset) {
695 FuncRequest cmd1 = cmd;
698 the_locking_inset->localDispatch(cmd1);
702 BufferView * bv = cmd.view();
703 int const old_cell = actcell;
705 setPos(bv, cmd.x, cmd.y);
706 if (!hasSelection()) {
707 setSelection(actcell, actcell);
708 updateLocal(bv, SELECTION);
709 } else if (old_cell != actcell) {
710 setSelection(sel_cell_start, actcell);
711 updateLocal(bv, SELECTION);
716 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
718 // We need to save the value of the_locking_inset as the call to
719 // the_locking_inset->localDispatch might unlock it.
720 old_locking_inset = the_locking_inset;
721 RESULT result = UpdatableInset::localDispatch(cmd);
722 BufferView * bv = cmd.view();
724 if (cmd.action == LFUN_INSET_EDIT) {
726 if (!bv->lockInset(this)) {
727 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
733 the_locking_inset = 0;
737 if (cmd.argument.size()) {
738 if (cmd.argument == "left") {
739 if (isRightToLeft(bv))
740 actcell = tabular->GetLastCellInRow(0);
744 if (isRightToLeft(bv))
745 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
747 actcell = tabular->GetNumberOfCells() - 1;
755 setPos(bv, cmd.x, cmd.y);
758 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
759 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
765 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
770 if (cmd.action < 0 && cmd.argument.empty())
773 bool hs = hasSelection();
776 // this one have priority over the locked InsetText, if we're not already
777 // inside another tabular then that one get's priority!
778 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
779 switch (cmd.action) {
780 case LFUN_MOUSE_PRESS:
784 case LFUN_MOUSE_MOTION:
785 lfunMouseMotion(cmd);
788 case LFUN_MOUSE_RELEASE:
789 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
791 case LFUN_CELL_BACKWARD:
792 case LFUN_CELL_FORWARD:
793 unlockInsetInInset(bv, the_locking_inset);
794 if (cmd.action == LFUN_CELL_FORWARD)
795 moveNextCell(bv, old_locking_inset != 0);
797 movePrevCell(bv, old_locking_inset != 0);
800 updateLocal(bv, SELECTION);
801 if (!the_locking_inset) {
802 return DISPATCHED_NOUPDATE;
805 // this to avoid compiler warnings.
811 kb_action action = cmd.action;
812 string arg = cmd.argument;
813 if (the_locking_inset) {
814 result = the_locking_inset->localDispatch(cmd);
815 if (result == DISPATCHED_NOUPDATE) {
818 if (sc != scroll()) { // inset has been scrolled
819 updateLocal(bv, FULL);
822 } else if (result == DISPATCHED) {
823 updateLocal(bv, CELL);
825 } else if (result == FINISHED_UP) {
827 // Make sure to reset status message after
828 // exiting, e.g. math inset
829 bv->owner()->clearMessage();
830 } else if (result == FINISHED_DOWN) {
832 bv->owner()->clearMessage();
833 } else if (result == FINISHED_RIGHT) {
835 bv->owner()->clearMessage();
836 } else if (result == FINISHED) {
837 bv->owner()->clearMessage();
843 // --- Cursor Movements ----------------------------------
844 case LFUN_RIGHTSEL: {
845 int const start = hasSelection() ? sel_cell_start : actcell;
846 if (tabular->IsLastCellInRow(actcell)) {
847 setSelection(start, actcell);
852 // if we are starting a selection, only select
853 // the current cell at the beginning
854 if (hasSelection()) {
855 moveRight(bv, false);
858 setSelection(start, end);
859 updateLocal(bv, SELECTION);
863 result = moveRight(bv);
866 updateLocal(bv, SELECTION);
869 int const start = hasSelection() ? sel_cell_start : actcell;
870 if (tabular->IsFirstCellInRow(actcell)) {
871 setSelection(start, actcell);
876 // if we are starting a selection, only select
877 // the current cell at the beginning
878 if (hasSelection()) {
882 setSelection(start, end);
883 updateLocal(bv, SELECTION);
887 result = moveLeft(bv);
890 updateLocal(bv, SELECTION);
893 int const start = hasSelection() ? sel_cell_start : actcell;
894 int const ocell = actcell;
895 // if we are starting a selection, only select
896 // the current cell at the beginning
897 if (hasSelection()) {
899 if ((ocell == sel_cell_end) ||
900 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
901 setSelection(start, tabular->GetCellBelow(sel_cell_end));
903 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
905 setSelection(start, start);
907 updateLocal(bv, SELECTION);
911 result = moveDown(bv, old_locking_inset != 0);
914 updateLocal(bv, SELECTION);
918 int const start = hasSelection() ? sel_cell_start : actcell;
919 int const ocell = actcell;
920 // if we are starting a selection, only select
921 // the current cell at the beginning
922 if (hasSelection()) {
924 if ((ocell == sel_cell_end) ||
925 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
926 setSelection(start, tabular->GetCellAbove(sel_cell_end));
928 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
930 setSelection(start, start);
932 updateLocal(bv, SELECTION);
936 result = moveUp(bv, old_locking_inset != 0);
939 updateLocal(bv, SELECTION);
942 UpdateCodes code = CURSOR;
948 unlockInsetInInset(bv, the_locking_inset);
949 if (bv->text->top_y() + bv->painter().paperHeight() <
950 (top_baseline + tabular->GetHeightOfTabular()))
952 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
954 actcell = tabular->GetCellBelow(first_visible_cell) + column;
956 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
959 updateLocal(bv, code);
963 UpdateCodes code = CURSOR;
969 unlockInsetInInset(bv, the_locking_inset);
970 if (top_baseline < 0) {
971 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
973 if (top_baseline > 0)
976 actcell = tabular->GetCellBelow(first_visible_cell) + column;
981 updateLocal(bv, code);
984 // none of these make sense for insettabular,
985 // but we must catch them to prevent any
986 // selection from being confused
990 case LFUN_WORDLEFTSEL:
992 case LFUN_WORDRIGHTSEL:
994 case LFUN_DOWN_PARAGRAPH:
995 case LFUN_DOWN_PARAGRAPHSEL:
996 case LFUN_UP_PARAGRAPH:
997 case LFUN_UP_PARAGRAPHSEL:
1003 case LFUN_BEGINNINGBUF:
1004 case LFUN_BEGINNINGBUFSEL:
1006 case LFUN_ENDBUFSEL:
1008 case LFUN_LAYOUT_TABULAR: {
1009 InsetTabularMailer mailer(*this);
1010 mailer.showDialog(bv);
1013 case LFUN_INSET_DIALOG_UPDATE: {
1014 InsetTabularMailer mailer(*this);
1015 mailer.updateDialog(bv);
1018 case LFUN_TABULAR_FEATURE:
1019 if (!tabularFeatures(bv, arg))
1020 result = UNDISPATCHED;
1022 // insert file functions
1023 case LFUN_FILE_INSERT_ASCII_PARA:
1024 case LFUN_FILE_INSERT_ASCII:
1026 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1029 if (insertAsciiString(bv, tmpstr, false))
1030 updateLocal(bv, INIT);
1032 result = UNDISPATCHED;
1035 // cut and paste functions
1037 if (!copySelection(bv))
1041 setUndo(bv, Undo::DELETE,
1042 bv->text->cursor.par(),
1043 boost::next(bv->text->cursor.par()));
1044 cutSelection(bv->buffer()->params);
1045 updateLocal(bv, INIT);
1048 if (!hasSelection())
1053 case LFUN_PASTESELECTION:
1055 string const clip(bv->getClipboard());
1059 if (clip.find('\t') != string::npos) {
1063 string::size_type len = clip.length();
1064 string::size_type p = 0;
1067 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1075 maxCols = max(cols, maxCols);
1081 maxCols = max(cols, maxCols);
1082 delete paste_tabular;
1083 paste_tabular = new LyXTabular(bv->buffer()->params,
1084 this, rows, maxCols);
1085 string::size_type op = 0;
1087 int cells = paste_tabular->GetNumberOfCells();
1089 while ((cell < cells) && (p < len) &&
1090 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1095 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1100 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1101 while (cols++ < maxCols)
1109 // check for the last cell if there is no trailing '\n'
1110 if ((cell < cells) && (op < len))
1111 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1114 if (!insertAsciiString(bv, clip, true))
1117 // so that the clipboard is used and it goes on
1119 // and executes LFUN_PASTESELECTION in insettext!
1120 delete paste_tabular;
1125 if (hasPasteBuffer()) {
1126 setUndo(bv, Undo::INSERT,
1127 bv->text->cursor.par(),
1128 boost::next(bv->text->cursor.par()));
1130 updateLocal(bv, INIT);
1133 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1135 // handle font changing stuff on selection before we lock the inset
1136 // in the default part!
1137 result = UNDISPATCHED;
1148 case LFUN_UNDERLINE:
1149 case LFUN_FONT_SIZE:
1150 if (bv->dispatch(FuncRequest(bv, action, arg)))
1151 result = DISPATCHED;
1157 // we try to activate the actual inset and put this event down to
1158 // the insets dispatch function.
1159 if ((result == DISPATCHED) || the_locking_inset)
1162 if (activateCellInset(bv)) {
1163 // reset need_update setted in above function!
1165 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1166 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1167 unlockInsetInInset(bv, the_locking_inset);
1169 // we need to update if this was requested before
1170 updateLocal(bv, NONE);
1171 return UNDISPATCHED;
1174 // so the below CELL is not set because this is higher
1175 // priority and we get a full redraw
1176 need_update = SELECTION;
1179 updateLocal(bv, CELL);
1184 if (result < FINISHED) {
1185 if (!the_locking_inset) {
1186 if (bv->fitCursor())
1187 updateLocal(bv, FULL);
1190 bv->unlockInset(this);
1195 int InsetTabular::latex(Buffer const * buf, ostream & os,
1196 bool fragile, bool fp) const
1198 return tabular->latex(buf, os, fragile, fp);
1202 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1205 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1207 return tabular->ascii(buf, os, 0, false,0);
1211 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1214 int const ret = tabular->ascii(buf,os,
1215 (int)parOwner()->params().depth(),
1222 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1227 // if the table is inside a float it doesn't need the informaltable
1228 // wrapper. Search for it.
1229 for(master = owner();
1230 master && master->lyxCode() != Inset::FLOAT_CODE;
1231 master = master->owner());
1234 os << "<informaltable>";
1239 ret+= tabular->docbook(buf, os, mixcont);
1241 os << "</informaltable>";
1250 void InsetTabular::validate(LaTeXFeatures & features) const
1252 tabular->Validate(features);
1256 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1262 bool changed = false;
1264 // FIXME: since InsetText ignores this anyway, it doesn't
1265 // matter what we pass it. Ugly
1268 // if we have a locking_inset we should have to check only this cell for
1269 // change so I'll try this to have a boost, but who knows ;)
1270 if ((need_update != INIT) &&
1271 (the_locking_inset == tabular->GetCellInset(actcell))) {
1272 for(int i = 0; i < tabular->columns(); ++i) {
1273 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1275 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1278 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1279 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1280 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1283 for (int i = 0; i < tabular->rows(); ++i) {
1286 for (int j = 0; j < tabular->columns(); ++j) {
1287 if (tabular->IsPartOfMultiColumn(i,j))
1290 inset = tabular->GetCellInset(cell);
1291 if (!reinit && !tabular->GetPWidth(cell).zero())
1292 inset->update(bv, false);
1293 maxAsc = max(maxAsc, inset->ascent(bv, font));
1294 maxDesc = max(maxDesc, inset->descent(bv, font));
1295 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1297 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1298 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1306 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1308 if (the_locking_inset) {
1309 the_locking_inset->getCursor(bv, x, y);
1314 y = cursor_.y() + InsetTabular::y();
1317 int desc = tabular->GetDescentOfRow(actrow);
1319 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1321 y += ADD_TO_HEIGHT * 2;
1322 y += TEXT_TO_INSET_OFFSET;
1326 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1328 if (the_locking_inset) {
1329 the_locking_inset->getCursorPos(bv, x, y);
1332 x = cursor_.x() - top_x;
1337 void InsetTabular::fitInsetCursor(BufferView * bv) const
1339 if (the_locking_inset) {
1340 int old_top_y = bv->text->top_y();
1341 the_locking_inset->fitInsetCursor(bv);
1342 if (old_top_y != bv->text->top_y())
1348 int const asc = font_metrics::maxAscent(font);
1349 int const desc = font_metrics::maxDescent(font);
1352 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1357 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1361 actcell = actrow = actcol = 0;
1362 int ly = tabular->GetDescentOfRow(actrow);
1364 // first search the right row
1365 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1366 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1367 tabular->GetAscentOfRow(actrow + 1) +
1368 tabular->GetAdditionalHeight(actrow + 1));
1370 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1372 actcell = tabular->GetCellNumber(actrow, actcol);
1374 // now search the right column
1375 int lx = tabular->GetWidthOfColumn(actcell) -
1376 tabular->GetAdditionalWidth(actcell);
1377 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1378 lx += tabular->GetWidthOfColumn(actcell + 1)
1379 + tabular->GetAdditionalWidth(actcell);
1381 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1386 int InsetTabular::getCellXPos(int cell) const
1390 for (; !tabular->IsFirstCellInRow(c); --c)
1392 int lx = tabular->GetWidthOfColumn(cell);
1393 for (; c < cell; ++c) {
1394 lx += tabular->GetWidthOfColumn(c);
1396 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1400 void InsetTabular::resetPos(BufferView * bv) const
1402 #ifdef WITH_WARNINGS
1403 #warning This should be fixed in the right manner (20011128 Jug)
1405 // fast hack to fix infinite repaintings!
1406 if (in_reset_pos > 0)
1410 actcol = tabular->column_of_cell(actcell);
1413 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1414 if (tabular->IsLastCellInRow(cell)) {
1415 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1416 tabular->GetAscentOfRow(actrow + 1) +
1417 tabular->GetAdditionalHeight(actrow + 1));
1421 if (!locked || nodraw()) {
1422 if (the_locking_inset)
1423 inset_y = cursor_.y();
1426 // we need this only from here on!!!
1428 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1429 int new_x = getCellXPos(actcell);
1430 int old_x = cursor_.x();
1433 // cursor.x(getCellXPos(actcell) + offset);
1434 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1435 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1438 updateLocal(bv, FULL);
1439 } else if (the_locking_inset &&
1440 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1442 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1443 if (xx > (bv->workWidth()-20)) {
1444 scroll(bv, -(xx - bv->workWidth() + 60));
1445 updateLocal(bv, FULL);
1446 } else if (xx < 20) {
1452 updateLocal(bv, FULL);
1454 } else if ((cursor_.x() - offset) > 20 &&
1455 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1456 > (bv->workWidth() - 20)) {
1457 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1458 updateLocal(bv, FULL);
1459 } else if ((cursor_.x() - offset) < 20) {
1460 scroll(bv, 20 - cursor_.x() + offset);
1461 updateLocal(bv, FULL);
1462 } else if (scroll() && top_x > 20 &&
1463 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1464 scroll(bv, old_x - cursor_.x());
1465 updateLocal(bv, FULL);
1467 if (the_locking_inset) {
1468 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1469 inset_y = cursor_.y();
1471 if ((!the_locking_inset ||
1472 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1473 actcell != oldcell) {
1474 InsetTabular * inset = const_cast<InsetTabular *>(this);
1475 InsetTabularMailer mailer(*inset);
1476 mailer.updateDialog(bv);
1483 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1485 if (lock && !old_locking_inset) {
1486 if (activateCellInset(bv))
1489 bool moved = isRightToLeft(bv)
1490 ? movePrevCell(bv) : moveNextCell(bv);
1492 return FINISHED_RIGHT;
1493 if (lock && activateCellInset(bv))
1497 return DISPATCHED_NOUPDATE;
1501 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1503 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1506 if (lock) { // behind the inset
1507 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1511 return DISPATCHED_NOUPDATE;
1515 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1517 int const ocell = actcell;
1518 actcell = tabular->GetCellAbove(actcell);
1519 if (actcell == ocell) // we moved out of the inset
1525 if (old_locking_inset) {
1526 old_locking_inset->getCursorPos(bv, x, y);
1527 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1529 if (activateCellInset(bv, x, 0))
1532 return DISPATCHED_NOUPDATE;
1536 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1538 int const ocell = actcell;
1539 actcell = tabular->GetCellBelow(actcell);
1540 if (actcell == ocell) // we moved out of the inset
1541 return FINISHED_DOWN;
1546 if (old_locking_inset) {
1547 old_locking_inset->getCursorPos(bv, x, y);
1548 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1550 if (activateCellInset(bv, x, 0))
1553 return DISPATCHED_NOUPDATE;
1557 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1559 if (isRightToLeft(bv)) {
1560 if (tabular->IsFirstCellInRow(actcell)) {
1561 int row = tabular->row_of_cell(actcell);
1562 if (row == tabular->rows() - 1)
1564 actcell = tabular->GetLastCellInRow(row);
1565 actcell = tabular->GetCellBelow(actcell);
1572 if (tabular->IsLastCell(actcell))
1577 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1578 isRightToLeftPar(bv->buffer()->params);
1579 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1586 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1588 if (isRightToLeft(bv)) {
1589 if (tabular->IsLastCellInRow(actcell)) {
1590 int row = tabular->row_of_cell(actcell);
1593 actcell = tabular->GetFirstCellInRow(row);
1594 actcell = tabular->GetCellAbove(actcell);
1596 if (tabular->IsLastCell(actcell))
1601 if (!actcell) // first cell
1606 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1607 isRightToLeftPar(bv->buffer()->params);
1608 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1615 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1619 setSelection(0, tabular->GetNumberOfCells() - 1);
1621 if (hasSelection()) {
1622 setUndo(bv, Undo::EDIT,
1623 bv->text->cursor.par(),
1624 boost::next(bv->text->cursor.par()));
1625 bool const frozen = undo_frozen;
1628 // apply the fontchange on the whole selection
1633 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1634 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1635 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1636 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1643 updateLocal(bv, INIT);
1645 if (the_locking_inset)
1646 the_locking_inset->setFont(bv, font, tall);
1650 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1652 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1655 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1656 string const tmp = tabularFeature[i].feature;
1658 if (tmp == what.substr(0, tmp.length())) {
1659 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1660 //tabularFeatures[i].feature.length())) {
1661 action = tabularFeature[i].action;
1665 if (action == LyXTabular::LAST_ACTION)
1669 ltrim(what.substr(tabularFeature[i].feature.length()));
1670 tabularFeatures(bv, action, val);
1676 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1677 string const & special, bool & flag)
1679 if (special == "dl_above") {
1682 } else if (special == "dl_below") {
1683 ltt.bottomDL = flag;
1685 } else if (special == "empty") {
1697 void InsetTabular::tabularFeatures(BufferView * bv,
1698 LyXTabular::Feature feature,
1699 string const & value)
1705 bool setLines = false;
1706 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1707 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1710 case LyXTabular::M_ALIGN_LEFT:
1711 case LyXTabular::ALIGN_LEFT:
1712 setAlign = LYX_ALIGN_LEFT;
1714 case LyXTabular::M_ALIGN_RIGHT:
1715 case LyXTabular::ALIGN_RIGHT:
1716 setAlign = LYX_ALIGN_RIGHT;
1718 case LyXTabular::M_ALIGN_CENTER:
1719 case LyXTabular::ALIGN_CENTER:
1720 setAlign = LYX_ALIGN_CENTER;
1722 case LyXTabular::ALIGN_BLOCK:
1723 setAlign = LYX_ALIGN_BLOCK;
1725 case LyXTabular::M_VALIGN_TOP:
1726 case LyXTabular::VALIGN_TOP:
1727 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1729 case LyXTabular::M_VALIGN_BOTTOM:
1730 case LyXTabular::VALIGN_BOTTOM:
1731 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1733 case LyXTabular::M_VALIGN_CENTER:
1734 case LyXTabular::VALIGN_CENTER:
1735 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1740 if (hasSelection()) {
1741 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1743 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1744 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1746 setUndo(bv, Undo::FINISH,
1747 bv->text->cursor.par(),
1748 boost::next(bv->text->cursor.par()));
1750 int row = tabular->row_of_cell(actcell);
1751 int column = tabular->column_of_cell(actcell);
1753 LyXTabular::ltType ltt;
1756 case LyXTabular::SET_PWIDTH:
1758 LyXLength const vallen(value);
1759 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1761 bool const update = (tmplen != vallen);
1762 tabular->SetColumnPWidth(actcell, vallen);
1765 for (int i = 0; i < tabular->rows(); ++i) {
1766 cell = tabular->GetCellNumber(i,column);
1767 tabular->GetCellInset(cell)->resizeLyXText(bv);
1769 updateLocal(bv, INIT);
1773 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1774 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1775 else if (!vallen.zero()
1776 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1777 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1780 case LyXTabular::SET_MPWIDTH:
1782 LyXLength const vallen(value);
1783 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1785 bool const update = (tmplen != vallen);
1786 tabular->SetMColumnPWidth(actcell, vallen);
1788 for (int i = 0; i < tabular->rows(); ++i) {
1789 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1792 updateLocal(bv, INIT);
1796 case LyXTabular::SET_SPECIAL_COLUMN:
1797 case LyXTabular::SET_SPECIAL_MULTI:
1798 tabular->SetAlignSpecial(actcell,value,feature);
1799 updateLocal(bv, FULL);
1801 case LyXTabular::APPEND_ROW:
1802 // append the row into the tabular
1803 unlockInsetInInset(bv, the_locking_inset);
1804 tabular->AppendRow(bv->buffer()->params, actcell);
1805 updateLocal(bv, INIT);
1807 case LyXTabular::APPEND_COLUMN:
1808 // append the column into the tabular
1809 unlockInsetInInset(bv, the_locking_inset);
1810 tabular->AppendColumn(bv->buffer()->params, actcell);
1811 actcell = tabular->GetCellNumber(row, column);
1812 updateLocal(bv, INIT);
1814 case LyXTabular::DELETE_ROW:
1815 unlockInsetInInset(bv, the_locking_inset);
1816 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1817 tabular->DeleteRow(sel_row_start);
1819 if (sel_row_start >= tabular->rows())
1821 actcell = tabular->GetCellNumber(sel_row_start, column);
1823 updateLocal(bv, INIT);
1825 case LyXTabular::DELETE_COLUMN:
1826 unlockInsetInInset(bv, the_locking_inset);
1827 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1828 tabular->DeleteColumn(sel_col_start);
1830 if (sel_col_start >= tabular->columns())
1832 actcell = tabular->GetCellNumber(row, sel_col_start);
1834 updateLocal(bv, INIT);
1836 case LyXTabular::M_TOGGLE_LINE_TOP:
1838 case LyXTabular::TOGGLE_LINE_TOP:
1840 bool lineSet = !tabular->TopLine(actcell, flag);
1841 for (int i = sel_row_start; i <= sel_row_end; ++i)
1842 for (int j = sel_col_start; j <= sel_col_end; ++j)
1843 tabular->SetTopLine(
1844 tabular->GetCellNumber(i, j),
1846 updateLocal(bv, INIT);
1850 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1852 case LyXTabular::TOGGLE_LINE_BOTTOM:
1854 bool lineSet = !tabular->BottomLine(actcell, flag);
1855 for (int i = sel_row_start; i <= sel_row_end; ++i)
1856 for (int j = sel_col_start; j <= sel_col_end; ++j)
1857 tabular->SetBottomLine(
1858 tabular->GetCellNumber(i, j),
1861 updateLocal(bv, INIT);
1865 case LyXTabular::M_TOGGLE_LINE_LEFT:
1867 case LyXTabular::TOGGLE_LINE_LEFT:
1869 bool lineSet = !tabular->LeftLine(actcell, flag);
1870 for (int i = sel_row_start; i <= sel_row_end; ++i)
1871 for (int j = sel_col_start; j <= sel_col_end; ++j)
1872 tabular->SetLeftLine(
1873 tabular->GetCellNumber(i,j),
1876 updateLocal(bv, INIT);
1880 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1882 case LyXTabular::TOGGLE_LINE_RIGHT:
1884 bool lineSet = !tabular->RightLine(actcell, flag);
1885 for (int i = sel_row_start; i <= sel_row_end; ++i)
1886 for (int j = sel_col_start; j <= sel_col_end; ++j)
1887 tabular->SetRightLine(
1888 tabular->GetCellNumber(i,j),
1891 updateLocal(bv, INIT);
1895 case LyXTabular::M_ALIGN_LEFT:
1896 case LyXTabular::M_ALIGN_RIGHT:
1897 case LyXTabular::M_ALIGN_CENTER:
1899 case LyXTabular::ALIGN_LEFT:
1900 case LyXTabular::ALIGN_RIGHT:
1901 case LyXTabular::ALIGN_CENTER:
1902 case LyXTabular::ALIGN_BLOCK:
1903 for (int i = sel_row_start; i <= sel_row_end; ++i)
1904 for (int j = sel_col_start; j <= sel_col_end; ++j)
1905 tabular->SetAlignment(
1906 tabular->GetCellNumber(i, j),
1909 updateLocal(bv, INIT);
1911 case LyXTabular::M_VALIGN_TOP:
1912 case LyXTabular::M_VALIGN_BOTTOM:
1913 case LyXTabular::M_VALIGN_CENTER:
1915 case LyXTabular::VALIGN_TOP:
1916 case LyXTabular::VALIGN_BOTTOM:
1917 case LyXTabular::VALIGN_CENTER:
1918 for (int i = sel_row_start; i <= sel_row_end; ++i)
1919 for (int j = sel_col_start; j <= sel_col_end; ++j)
1920 tabular->SetVAlignment(
1921 tabular->GetCellNumber(i, j),
1923 updateLocal(bv, INIT);
1925 case LyXTabular::MULTICOLUMN:
1927 if (sel_row_start != sel_row_end) {
1928 #ifdef WITH_WARNINGS
1929 #warning Need I say it ? This is horrible.
1931 Alert::error(_("Error setting multicolumn"),
1932 _("You cannot set multicolumn vertically."));
1935 // just multicol for one Single Cell
1936 if (!hasSelection()) {
1937 // check wether we are completly in a multicol
1938 if (tabular->IsMultiColumn(actcell)) {
1939 tabular->UnsetMultiColumn(actcell);
1940 updateLocal(bv, INIT);
1942 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1943 updateLocal(bv, CELL);
1947 // we have a selection so this means we just add all this
1948 // cells to form a multicolumn cell
1952 if (sel_cell_start > sel_cell_end) {
1953 s_start = sel_cell_end;
1954 s_end = sel_cell_start;
1956 s_start = sel_cell_start;
1957 s_end = sel_cell_end;
1959 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1962 updateLocal(bv, INIT);
1965 case LyXTabular::SET_ALL_LINES:
1967 case LyXTabular::UNSET_ALL_LINES:
1968 for (int i = sel_row_start; i <= sel_row_end; ++i)
1969 for (int j = sel_col_start; j <= sel_col_end; ++j)
1970 tabular->SetAllLines(
1971 tabular->GetCellNumber(i,j), setLines);
1972 updateLocal(bv, INIT);
1974 case LyXTabular::SET_LONGTABULAR:
1975 tabular->SetLongTabular(true);
1976 updateLocal(bv, INIT); // because this toggles displayed
1978 case LyXTabular::UNSET_LONGTABULAR:
1979 tabular->SetLongTabular(false);
1980 updateLocal(bv, INIT); // because this toggles displayed
1982 case LyXTabular::SET_ROTATE_TABULAR:
1983 tabular->SetRotateTabular(true);
1985 case LyXTabular::UNSET_ROTATE_TABULAR:
1986 tabular->SetRotateTabular(false);
1988 case LyXTabular::SET_ROTATE_CELL:
1989 for (int i = sel_row_start; i <= sel_row_end; ++i)
1990 for (int j = sel_col_start; j<=sel_col_end; ++j)
1991 tabular->SetRotateCell(
1992 tabular->GetCellNumber(i, j),
1995 case LyXTabular::UNSET_ROTATE_CELL:
1996 for (int i = sel_row_start; i <= sel_row_end; ++i)
1997 for (int j = sel_col_start; j <= sel_col_end; ++j)
1998 tabular->SetRotateCell(
1999 tabular->GetCellNumber(i, j), false);
2001 case LyXTabular::SET_USEBOX:
2003 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2004 if (val == tabular->GetUsebox(actcell))
2005 val = LyXTabular::BOX_NONE;
2006 for (int i = sel_row_start; i <= sel_row_end; ++i)
2007 for (int j = sel_col_start; j <= sel_col_end; ++j)
2009 tabular->GetCellNumber(i, j), val);
2012 case LyXTabular::UNSET_LTFIRSTHEAD:
2014 case LyXTabular::SET_LTFIRSTHEAD:
2015 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2016 checkLongtableSpecial(ltt, value, flag);
2017 tabular->SetLTHead(row, flag, ltt, true);
2019 case LyXTabular::UNSET_LTHEAD:
2021 case LyXTabular::SET_LTHEAD:
2022 (void)tabular->GetRowOfLTHead(row, ltt);
2023 checkLongtableSpecial(ltt, value, flag);
2024 tabular->SetLTHead(row, flag, ltt, false);
2026 case LyXTabular::UNSET_LTFOOT:
2028 case LyXTabular::SET_LTFOOT:
2029 (void)tabular->GetRowOfLTFoot(row, ltt);
2030 checkLongtableSpecial(ltt, value, flag);
2031 tabular->SetLTFoot(row, flag, ltt, false);
2033 case LyXTabular::UNSET_LTLASTFOOT:
2035 case LyXTabular::SET_LTLASTFOOT:
2036 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2037 checkLongtableSpecial(ltt, value, flag);
2038 tabular->SetLTFoot(row, flag, ltt, true);
2040 case LyXTabular::SET_LTNEWPAGE:
2042 bool what = !tabular->GetLTNewPage(row);
2043 tabular->SetLTNewPage(row, what);
2046 // dummy stuff just to avoid warnings
2047 case LyXTabular::LAST_ACTION:
2051 InsetTabularMailer mailer(*this);
2052 mailer.updateDialog(bv);
2056 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2059 UpdatableInset * inset =
2060 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2061 LyXFont font(LyXFont::ALL_SANE);
2063 x = inset->x() + inset->width(bv, font);
2064 y = inset->descent(bv, font);
2066 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2067 //inset_y = cursor.y();
2068 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2069 if (!the_locking_inset)
2071 updateLocal(bv, CELL);
2072 return (the_locking_inset != 0);
2076 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2077 mouse_button::state button)
2079 inset_x = cursor_.x()
2080 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2081 inset_y = cursor_.y();
2082 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2086 bool InsetTabular::insetHit(BufferView *, int x, int) const
2089 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2093 // This returns paperWidth() if the cell-width is unlimited or the width
2094 // in pixels if we have a pwidth for this cell.
2095 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2097 LyXLength const len = tabular->GetPWidth(cell);
2101 return len.inPixels(latexTextWidth(bv));
2105 int InsetTabular::getMaxWidth(BufferView * bv,
2106 UpdatableInset const * inset) const
2108 int cell = tabular->GetCellFromInset(inset, actcell);
2111 lyxerr << "Own inset not found, shouldn't really happen!"
2116 int w = getMaxWidthOfCell(bv, cell);
2118 // because the inset then subtracts it's top_x and owner->x()
2119 w += (inset->x() - top_x);
2126 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2128 resizeLyXText(bv, recursive);
2132 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2135 for(int i = 0; i < tabular->rows(); ++i) {
2136 for(int j = 0; j < tabular->columns(); ++j) {
2137 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2145 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2146 bool const recursive) const
2148 if (the_locking_inset)
2149 return the_locking_inset->getLyXText(bv, recursive);
2151 // if we're locked lock the actual insettext and return it's LyXText!!!
2153 UpdatableInset * inset =
2154 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2155 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2156 return the_locking_inset->getLyXText(bv, recursive);
2159 return Inset::getLyXText(bv, recursive);
2163 bool InsetTabular::showInsetDialog(BufferView * bv) const
2165 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2166 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2167 InsetTabularMailer mailer(*tmp);
2168 mailer.showDialog(bv);
2174 void InsetTabular::openLayoutDialog(BufferView * bv) const
2176 if (the_locking_inset) {
2177 InsetTabular * i = static_cast<InsetTabular *>
2178 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2180 i->openLayoutDialog(bv);
2184 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2185 InsetTabularMailer mailer(*tmp);
2186 mailer.showDialog(bv);
2191 // function returns an object as defined in func_status.h:
2192 // states OK, Unknown, Disabled, On, Off.
2194 FuncStatus InsetTabular::getStatus(string const & what) const
2196 int action = LyXTabular::LAST_ACTION;
2200 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2201 string const tmp = tabularFeature[i].feature;
2202 if (tmp == what.substr(0, tmp.length())) {
2203 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2204 // tabularFeatures[i].feature.length())) {
2205 action = tabularFeature[i].action;
2209 if (action == LyXTabular::LAST_ACTION) {
2211 return status.unknown(true);
2214 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2219 LyXTabular::ltType dummyltt;
2222 if (hasSelection()) {
2223 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2225 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2229 case LyXTabular::SET_PWIDTH:
2230 case LyXTabular::SET_MPWIDTH:
2231 case LyXTabular::SET_SPECIAL_COLUMN:
2232 case LyXTabular::SET_SPECIAL_MULTI:
2233 case LyXTabular::APPEND_ROW:
2234 case LyXTabular::APPEND_COLUMN:
2235 case LyXTabular::DELETE_ROW:
2236 case LyXTabular::DELETE_COLUMN:
2237 case LyXTabular::SET_ALL_LINES:
2238 case LyXTabular::UNSET_ALL_LINES:
2239 return status.clear();
2241 case LyXTabular::MULTICOLUMN:
2242 status.setOnOff(tabular->IsMultiColumn(actcell));
2244 case LyXTabular::M_TOGGLE_LINE_TOP:
2246 case LyXTabular::TOGGLE_LINE_TOP:
2247 status.setOnOff(tabular->TopLine(actcell, flag));
2249 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2251 case LyXTabular::TOGGLE_LINE_BOTTOM:
2252 status.setOnOff(tabular->BottomLine(actcell, flag));
2254 case LyXTabular::M_TOGGLE_LINE_LEFT:
2256 case LyXTabular::TOGGLE_LINE_LEFT:
2257 status.setOnOff(tabular->LeftLine(actcell, flag));
2259 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2261 case LyXTabular::TOGGLE_LINE_RIGHT:
2262 status.setOnOff(tabular->RightLine(actcell, flag));
2264 case LyXTabular::M_ALIGN_LEFT:
2266 case LyXTabular::ALIGN_LEFT:
2267 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2269 case LyXTabular::M_ALIGN_RIGHT:
2271 case LyXTabular::ALIGN_RIGHT:
2272 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2274 case LyXTabular::M_ALIGN_CENTER:
2276 case LyXTabular::ALIGN_CENTER:
2277 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2279 case LyXTabular::ALIGN_BLOCK:
2280 status.disabled(tabular->GetPWidth(actcell).zero());
2281 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2283 case LyXTabular::M_VALIGN_TOP:
2285 case LyXTabular::VALIGN_TOP:
2286 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2288 case LyXTabular::M_VALIGN_BOTTOM:
2290 case LyXTabular::VALIGN_BOTTOM:
2291 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2293 case LyXTabular::M_VALIGN_CENTER:
2295 case LyXTabular::VALIGN_CENTER:
2296 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2298 case LyXTabular::SET_LONGTABULAR:
2299 status.setOnOff(tabular->IsLongTabular());
2301 case LyXTabular::UNSET_LONGTABULAR:
2302 status.setOnOff(!tabular->IsLongTabular());
2304 case LyXTabular::SET_ROTATE_TABULAR:
2305 status.setOnOff(tabular->GetRotateTabular());
2307 case LyXTabular::UNSET_ROTATE_TABULAR:
2308 status.setOnOff(!tabular->GetRotateTabular());
2310 case LyXTabular::SET_ROTATE_CELL:
2311 status.setOnOff(tabular->GetRotateCell(actcell));
2313 case LyXTabular::UNSET_ROTATE_CELL:
2314 status.setOnOff(!tabular->GetRotateCell(actcell));
2316 case LyXTabular::SET_USEBOX:
2317 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2319 case LyXTabular::SET_LTFIRSTHEAD:
2320 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2322 case LyXTabular::SET_LTHEAD:
2323 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2325 case LyXTabular::SET_LTFOOT:
2326 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2328 case LyXTabular::SET_LTLASTFOOT:
2329 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2331 case LyXTabular::SET_LTNEWPAGE:
2332 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2336 status.disabled(true);
2343 vector<string> const InsetTabular::getLabelList() const
2345 return tabular->getLabelList();
2349 bool InsetTabular::copySelection(BufferView * bv)
2351 if (!hasSelection())
2354 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2355 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2356 if (sel_col_start > sel_col_end) {
2357 sel_col_start = sel_col_end;
2358 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2360 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2362 int const columns = sel_col_end - sel_col_start + 1;
2364 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2365 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2366 if (sel_row_start > sel_row_end) {
2367 swap(sel_row_start, sel_row_end);
2369 int const rows = sel_row_end - sel_row_start + 1;
2371 delete paste_tabular;
2372 paste_tabular = new LyXTabular(bv->buffer()->params,
2373 this, *tabular); // rows, columns);
2374 for (int i = 0; i < sel_row_start; ++i)
2375 paste_tabular->DeleteRow(0);
2376 while (paste_tabular->rows() > rows)
2377 paste_tabular->DeleteRow(rows);
2378 paste_tabular->SetTopLine(0, true, true);
2379 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2381 for (int i = 0; i < sel_col_start; ++i)
2382 paste_tabular->DeleteColumn(0);
2383 while (paste_tabular->columns() > columns)
2384 paste_tabular->DeleteColumn(columns);
2385 paste_tabular->SetLeftLine(0, true, true);
2386 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2390 paste_tabular->ascii(bv->buffer(), sstr,
2391 (int)parOwner()->params().depth(), true, '\t');
2392 bv->stuffClipboard(STRCONV(sstr.str()));
2397 bool InsetTabular::pasteSelection(BufferView * bv)
2402 for (int r1 = 0, r2 = actrow;
2403 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2405 for(int c1 = 0, c2 = actcol;
2406 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2408 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2409 tabular->IsPartOfMultiColumn(r2,c2))
2411 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2415 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2419 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2420 int const n2 = tabular->GetCellNumber(r2, c2);
2421 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2422 tabular->GetCellInset(n2)->setOwner(this);
2423 tabular->GetCellInset(n2)->deleteLyXText(bv);
2424 tabular->GetCellInset(n2)->markNew();
2431 bool InsetTabular::cutSelection(BufferParams const & bp)
2433 if (!hasSelection())
2436 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2437 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2438 if (sel_col_start > sel_col_end) {
2439 sel_col_start = sel_col_end;
2440 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2442 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2444 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2445 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2446 if (sel_row_start > sel_row_end) {
2447 swap(sel_row_start, sel_row_end);
2449 if (sel_cell_start > sel_cell_end) {
2450 swap(sel_cell_start, sel_cell_end);
2452 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2453 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2454 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2461 bool InsetTabular::isRightToLeft(BufferView * bv)
2463 return bv->getParentLanguage(this)->RightToLeft();
2467 bool InsetTabular::nodraw() const
2469 if (!UpdatableInset::nodraw() && the_locking_inset)
2470 return the_locking_inset->nodraw();
2471 return UpdatableInset::nodraw();
2475 int InsetTabular::scroll(bool recursive) const
2477 int sx = UpdatableInset::scroll(false);
2479 if (recursive && the_locking_inset)
2480 sx += the_locking_inset->scroll(recursive);
2486 void InsetTabular::getSelection(int & srow, int & erow,
2487 int & scol, int & ecol) const
2489 int const start = hasSelection() ? sel_cell_start : actcell;
2490 int const end = hasSelection() ? sel_cell_end : actcell;
2492 srow = tabular->row_of_cell(start);
2493 erow = tabular->row_of_cell(end);
2498 scol = tabular->column_of_cell(start);
2499 ecol = tabular->column_of_cell(end);
2503 ecol = tabular->right_column_of_cell(end);
2508 ParagraphList * InsetTabular::getParagraphs(int i) const
2510 return (i < tabular->GetNumberOfCells())
2511 ? tabular->GetCellInset(i)->getParagraphs(0)
2516 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2518 if (the_locking_inset)
2519 return the_locking_inset->cursor(bv);
2520 return Inset::cursor(bv);
2524 Inset * InsetTabular::getInsetFromID(int id_arg) const
2527 return const_cast<InsetTabular *>(this);
2530 for(int i = 0; i < tabular->rows(); ++i) {
2531 for(int j = 0; j < tabular->columns(); ++j) {
2532 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2541 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2544 if (the_locking_inset) {
2545 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2546 if (!word.word().empty()) {
2550 if (tabular->IsLastCell(actcell)) {
2551 bv->unlockInset(const_cast<InsetTabular *>(this));
2553 return WordLangTuple();
2557 // otherwise we have to lock the next inset and ask for it's selecttion
2558 UpdatableInset * inset =
2559 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2560 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2561 WordLangTuple word(selectNextWordInt(bv, value));
2563 if (!word.word().empty())
2569 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2571 // when entering this function the inset should be ALWAYS locked!
2572 lyx::Assert(the_locking_inset);
2574 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2575 if (!word.word().empty())
2578 if (tabular->IsLastCell(actcell)) {
2579 bv->unlockInset(const_cast<InsetTabular *>(this));
2580 return WordLangTuple();
2583 // otherwise we have to lock the next inset and ask for it's selecttion
2584 UpdatableInset * inset =
2585 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2586 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2587 return selectNextWordInt(bv, value);
2591 void InsetTabular::selectSelectedWord(BufferView * bv)
2593 if (the_locking_inset) {
2594 the_locking_inset->selectSelectedWord(bv);
2601 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2603 if (the_locking_inset) {
2604 the_locking_inset->toggleSelection(bv, kill_selection);
2609 void InsetTabular::markErased()
2613 while (!tabular->IsLastCell(cell)) {
2615 InsetText * inset = tabular->GetCellInset(cell);
2616 inset->markErased();
2621 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2623 if (the_locking_inset) {
2624 if (the_locking_inset->nextChange(bv, length)) {
2625 updateLocal(bv, CELL);
2628 if (tabular->IsLastCell(actcell))
2632 InsetText * inset = tabular->GetCellInset(actcell);
2633 if (inset->nextChange(bv, length)) {
2634 updateLocal(bv, FULL);
2637 while (!tabular->IsLastCell(actcell)) {
2639 inset = tabular->GetCellInset(actcell);
2640 if (inset->nextChange(bv, length)) {
2641 updateLocal(bv, FULL);
2649 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2653 if (the_locking_inset) {
2654 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2655 updateLocal(bv, CELL);
2658 if (tabular->IsLastCell(actcell))
2662 InsetText * inset = tabular->GetCellInset(cell);
2663 if (inset->searchForward(bv, str, cs, mw)) {
2664 updateLocal(bv, FULL);
2667 while (!tabular->IsLastCell(cell)) {
2669 inset = tabular->GetCellInset(cell);
2670 if (inset->searchForward(bv, str, cs, mw)) {
2671 updateLocal(bv, FULL);
2679 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2682 int cell = tabular->GetNumberOfCells();
2683 if (the_locking_inset) {
2684 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2685 updateLocal(bv, CELL);
2693 InsetText * inset = tabular->GetCellInset(cell);
2694 if (inset->searchBackward(bv, str, cs, mw)) {
2695 updateLocal(bv, CELL);
2703 bool InsetTabular::insetAllowed(Inset::Code code) const
2705 if (the_locking_inset)
2706 return the_locking_inset->insetAllowed(code);
2707 // we return true here because if the inset is not locked someone
2708 // wants to insert something in one of our insettexts and we generally
2714 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2716 const int cell = tabular->GetCellFromInset(in, actcell);
2719 return tabular->GetPWidth(cell).zero();
2721 // well we didn't obviously find it so maybe our owner knows more
2723 return owner()->forceDefaultParagraphs(in);
2724 // if we're here there is really something strange going on!!!
2728 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2731 if (buf.length() <= 0)
2737 string::size_type len = buf.length();
2738 string::size_type p = 0;
2741 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2750 maxCols = max(cols, maxCols);
2756 maxCols = max(cols, maxCols);
2757 LyXTabular * loctab;
2762 delete paste_tabular;
2763 paste_tabular = new LyXTabular(bv->buffer()->params,
2764 this, rows, maxCols);
2765 loctab = paste_tabular;
2768 loctab = tabular.get();
2774 string::size_type op = 0;
2775 int cells = loctab->GetNumberOfCells();
2778 rows = loctab->rows();
2779 int const columns = loctab->columns();
2781 while ((cell < cells) && (p < len) && (row < rows) &&
2782 (p = buf.find_first_of("\t\n", p)) != string::npos)
2788 // we can only set this if we are not too far right
2789 if (cols < columns) {
2790 InsetText * ti = loctab->GetCellInset(cell);
2791 LyXFont const font = ti->getLyXText(bv)->
2792 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2793 ti->setText(buf.substr(op, p - op), font);
2799 // we can only set this if we are not too far right
2800 if (cols < columns) {
2801 InsetText * ti = loctab->GetCellInset(cell);
2802 LyXFont const font = ti->getLyXText(bv)->
2803 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2804 ti->setText(buf.substr(op, p - op), font);
2809 cell = loctab->GetCellNumber(row, cols);
2815 // check for the last cell if there is no trailing '\n'
2816 if ((cell < cells) && (op < len)) {
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, len - op), font);
2827 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2829 int const rows = tabular->rows();
2830 int const columns = tabular->columns();
2831 for (int i = 0; i < rows; ++i) {
2832 for (int j = 0; j < columns; ++j) {
2833 tabular->GetCellInset(i,j)->addPreview(loader);
2839 string const InsetTabularMailer:: name_("tabular");
2841 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2846 string const InsetTabularMailer::inset2string() const
2848 return params2string(inset_);
2852 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2854 istringstream data(STRCONV(in));
2856 lex.setStream(data);
2858 #warning CHECK verify that this is a sane value to return.
2864 string const token = lex.getString();
2872 string const token = lex.getString();
2873 if (token != "\\active_cell")
2876 cell = lex.getInteger();
2879 // This is part of the inset proper that is usually swallowed
2880 // by Buffer::readInset
2883 string const token = lex.getString();
2884 if (token != "Tabular")
2891 BufferView * const bv = inset.view();
2892 Buffer const * const buffer = bv ? bv->buffer() : 0;
2894 inset.read(buffer, lex);
2896 // We can't set the active cell, but we can tell the frontend
2902 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2904 BufferView * const bv = inset.view();
2905 Buffer const * const buffer = bv ? bv->buffer() : 0;
2910 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2911 inset.write(buffer, data);
2912 data << "\\end_inset\n";
2913 return STRCONV(data.str());