3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "insettabular.h"
14 #include "insettext.h"
17 #include "BufferView.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
28 #include "lyxlength.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "metricsinfo.h"
36 #include "frontends/Alert.h"
37 #include "frontends/Dialogs.h"
38 #include "frontends/font_metrics.h"
39 #include "frontends/LyXView.h"
40 #include "frontends/Painter.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
126 bool operator()(TabularFeature & tf)
128 return tf.action == feature_;
131 LyXTabular::Feature feature_;
137 string const featureAsString(LyXTabular::Feature feature)
139 TabularFeature * it = tabularFeature;
140 TabularFeature * end = it +
141 sizeof(tabularFeature) / sizeof(TabularFeature);
142 it = std::find_if(it, end, FindFeature(feature));
143 return (it == end) ? string() : it->feature;
147 bool InsetTabular::hasPasteBuffer() const
149 return (paste_tabular != 0);
153 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
160 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
177 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
178 : UpdatableInset(tab), buffer(&buf)
180 tabular.reset(new LyXTabular(buf.params,
181 this, *(tab.tabular)));
182 the_locking_inset = 0;
183 old_locking_inset = 0;
186 actrow = actcell = 0;
196 InsetTabular::~InsetTabular()
198 InsetTabularMailer mailer(*this);
203 Inset * InsetTabular::clone(Buffer const & buf) const
205 return new InsetTabular(*this, buf);
209 BufferView * InsetTabular::view() const
211 return buffer->getUser();
215 void InsetTabular::write(Buffer const * buf, ostream & os) const
217 os << " Tabular" << endl;
218 tabular->Write(buf, os);
222 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
224 bool const old_format = (lex.getString() == "\\LyXTable");
226 tabular.reset(new LyXTabular(buf, this, lex));
234 string token = lex.getString();
235 while (lex.isOK() && (token != "\\end_inset")) {
237 token = lex.getString();
239 if (token != "\\end_inset") {
240 lex.printError("Missing \\end_inset at this point. "
246 void InsetTabular::metrics(MetricsInfo &,
247 Dimension & dim) const
249 dim.asc = tabular->GetAscentOfRow(0);
250 dim.des = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
251 dim.wid = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
255 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
262 BufferView * bv = pi.base.bv;
268 UpdatableInset::draw(pi, x, y);
276 x += ADD_TO_TABULAR_WIDTH;
280 first_visible_cell = -1;
281 for (i = 0; i < tabular->rows(); ++i) {
283 cell = tabular->GetCellNumber(i, 0);
284 if (!((y + tabular->GetDescentOfRow(i)) > 0) &&
285 (y - tabular->GetAscentOfRow(i)) < pi.pain.paperHeight())
287 y += tabular->GetDescentOfRow(i) +
288 tabular->GetAscentOfRow(i + 1) +
289 tabular->GetAdditionalHeight(i + 1);
292 for (j = 0; j < tabular->columns(); ++j) {
293 if (nx > bv->workWidth())
295 if (tabular->IsPartOfMultiColumn(i, j))
297 cx = nx + tabular->GetBeginningOfTextInCell(cell);
298 if (first_visible_cell < 0)
299 first_visible_cell = cell;
300 if (hasSelection()) {
301 drawCellSelection(pi.pain, nx, y, i, j, cell);
304 tabular->GetCellInset(cell)->draw(pi, cx, y);
305 drawCellLines(pi.pain, nx, y, i, cell);
306 nx += tabular->GetWidthOfColumn(cell);
310 // avoiding drawing the rest of a long table is
311 // a pretty big speedup
312 if (y > bv->workHeight())
315 y += tabular->GetDescentOfRow(i) +
316 tabular->GetAscentOfRow(i + 1) +
317 tabular->GetAdditionalHeight(i + 1);
324 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
325 int row, int cell) const
327 int x2 = x + tabular->GetWidthOfColumn(cell);
330 if (!tabular->topAlreadyDrawn(cell)) {
331 on_off = !tabular->TopLine(cell);
332 pain.line(x, y - tabular->GetAscentOfRow(row),
333 x2, y - tabular->GetAscentOfRow(row),
334 on_off ? LColor::tabularonoffline : LColor::tabularline,
335 on_off ? Painter::line_onoffdash : Painter::line_solid);
337 on_off = !tabular->BottomLine(cell);
338 pain.line(x, y + tabular->GetDescentOfRow(row),
339 x2, y + tabular->GetDescentOfRow(row),
340 on_off ? LColor::tabularonoffline : LColor::tabularline,
341 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 if (!tabular->leftAlreadyDrawn(cell)) {
343 on_off = !tabular->LeftLine(cell);
344 pain.line(x, y - tabular->GetAscentOfRow(row),
345 x, y + tabular->GetDescentOfRow(row),
346 on_off ? LColor::tabularonoffline : LColor::tabularline,
347 on_off ? Painter::line_onoffdash : Painter::line_solid);
349 on_off = !tabular->RightLine(cell);
350 pain.line(x2 - tabular->GetAdditionalWidth(cell),
351 y - tabular->GetAscentOfRow(row),
352 x2 - tabular->GetAdditionalWidth(cell),
353 y + tabular->GetDescentOfRow(row),
354 on_off ? LColor::tabularonoffline : LColor::tabularline,
355 on_off ? Painter::line_onoffdash : Painter::line_solid);
359 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
360 int row, int column, int cell) const
362 lyx::Assert(hasSelection());
363 int cs = tabular->column_of_cell(sel_cell_start);
364 int ce = tabular->column_of_cell(sel_cell_end);
367 cs = tabular->column_of_cell(sel_cell_end);
369 ce = tabular->right_column_of_cell(sel_cell_end);
372 int rs = tabular->row_of_cell(sel_cell_start);
373 int re = tabular->row_of_cell(sel_cell_end);
377 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
378 int w = tabular->GetWidthOfColumn(cell);
379 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
380 pain.fillRectangle(x, y - tabular->GetAscentOfRow(row) + 1,
381 w, h, LColor::selection);
386 void InsetTabular::update(BufferView * bv, bool reinit)
392 owner()->update(bv, true);
399 if (calculate_dimensions_of_cells(bv, true))
402 owner()->update(bv, true);
406 if (the_locking_inset)
407 the_locking_inset->update(bv, reinit);
408 if (need_update < FULL &&
409 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
414 switch (need_update) {
418 if (calculate_dimensions_of_cells(bv, false)) {
433 string const InsetTabular::editMessage() const
435 return _("Opened table");
439 void InsetTabular::insetUnlock(BufferView * bv)
441 if (the_locking_inset) {
442 the_locking_inset->insetUnlock(bv);
443 updateLocal(bv, CELL);
444 the_locking_inset = 0;
449 if (scroll(false) || hasSelection()) {
454 updateLocal(bv, FULL);
459 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
462 calculate_dimensions_of_cells(bv, true);
464 if (!locked && what == CELL)
466 if (need_update < what) // only set this if it has greater update
469 if (need_update != NONE) {
470 bv->updateInset(const_cast<InsetTabular *>(this));
477 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
479 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
484 if (inset == tabular->GetCellInset(actcell)) {
485 lyxerr[Debug::INSETTEXT] << "OK" << endl;
486 the_locking_inset = tabular->GetCellInset(actcell);
489 } else if (!the_locking_inset) {
490 int const n = tabular->GetNumberOfCells();
491 int const id = inset->id();
492 for (int i = 0; i < n; ++i) {
493 InsetText * in = tabular->GetCellInset(i);
496 the_locking_inset = in;
501 if (in->getInsetFromID(id)) {
503 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
504 return the_locking_inset->lockInsetInInset(bv, inset);
507 } else if (the_locking_inset && (the_locking_inset == inset)) {
508 lyxerr[Debug::INSETTEXT] << "OK" << endl;
510 } else if (the_locking_inset) {
511 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
512 return the_locking_inset->lockInsetInInset(bv, inset);
514 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
519 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
522 if (!the_locking_inset)
524 if (the_locking_inset == inset) {
525 the_locking_inset->insetUnlock(bv);
527 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
533 updateLocal(bv, CELL);
534 // this has to be here otherwise we don't redraw the cell!
535 the_locking_inset = 0;
538 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
539 if (inset->lyxCode() == TABULAR_CODE &&
540 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
541 InsetTabularMailer mailer(*this);
542 mailer.updateDialog(bv);
551 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
553 Inset * tl_inset = inset;
554 // look if this inset is really inside myself!
555 while(tl_inset->owner() && tl_inset->owner() != this)
556 tl_inset = tl_inset->owner();
557 // if we enter here it's not ower inset
558 if (!tl_inset->owner())
560 // we only have to do this if this is a subinset of our cells
561 if (tl_inset != inset) {
562 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
565 updateLocal(bv, CELL);
570 int InsetTabular::insetInInsetY() const
572 if (!the_locking_inset)
574 return inset_y + the_locking_inset->insetInInsetY();
578 UpdatableInset * InsetTabular::getLockingInset() const
580 return the_locking_inset ? the_locking_inset->getLockingInset() :
581 const_cast<InsetTabular *>(this);
585 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
589 if (the_locking_inset)
590 return the_locking_inset->getFirstLockingInsetOfType(c);
595 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
597 if (the_locking_inset)
598 return the_locking_inset->insertInset(bv, inset);
603 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
605 if (hasSelection() && cmd.button() == mouse_button::button3)
608 if (hasSelection()) {
610 updateLocal(cmd.view(), SELECTION);
613 int const ocell = actcell;
614 int const orow = actrow;
615 BufferView * bv = cmd.view();
619 the_locking_inset = 0;
623 setPos(bv, cmd.x, cmd.y);
625 updateLocal(bv, NONE);
628 if (cmd.button() == mouse_button::button3) {
629 if ((ocell != actcell) && the_locking_inset) {
630 the_locking_inset->insetUnlock(bv);
631 updateLocal(bv, CELL);
632 the_locking_inset = 0;
638 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
640 if ((ocell == actcell) && the_locking_inset && inset_hit) {
642 FuncRequest cmd1 = cmd;
645 the_locking_inset->localDispatch(cmd1);
649 if (the_locking_inset) {
650 the_locking_inset->insetUnlock(bv);
651 updateLocal(bv, CELL);
652 the_locking_inset = 0;
655 if (cmd.button() == mouse_button::button2) {
656 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
660 if (inset_hit && bv->theLockingInset()) {
661 if (!bv->lockInset(static_cast<UpdatableInset*>
662 (tabular->GetCellInset(actcell))))
664 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
667 FuncRequest cmd1 = cmd;
670 the_locking_inset->localDispatch(cmd1);
676 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
679 if (the_locking_inset) {
680 FuncRequest cmd1 = cmd;
683 ret = the_locking_inset->localDispatch(cmd1);
685 if (cmd.button() == mouse_button::button3 && !ret) {
686 InsetTabularMailer(*this).showDialog(cmd.view());
693 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
695 if (the_locking_inset) {
696 FuncRequest cmd1 = cmd;
699 the_locking_inset->localDispatch(cmd1);
703 BufferView * bv = cmd.view();
704 int const old_cell = actcell;
706 setPos(bv, cmd.x, cmd.y);
707 if (!hasSelection()) {
708 setSelection(actcell, actcell);
709 updateLocal(bv, SELECTION);
710 } else if (old_cell != actcell) {
711 setSelection(sel_cell_start, actcell);
712 updateLocal(bv, SELECTION);
717 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
719 // We need to save the value of the_locking_inset as the call to
720 // the_locking_inset->localDispatch might unlock it.
721 old_locking_inset = the_locking_inset;
722 RESULT result = UpdatableInset::localDispatch(cmd);
723 BufferView * bv = cmd.view();
725 if (cmd.action == LFUN_INSET_EDIT) {
727 if (!bv->lockInset(this)) {
728 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
734 the_locking_inset = 0;
738 if (cmd.argument.size()) {
739 if (cmd.argument == "left") {
740 if (isRightToLeft(bv))
741 actcell = tabular->GetLastCellInRow(0);
745 if (isRightToLeft(bv))
746 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
748 actcell = tabular->GetNumberOfCells() - 1;
756 setPos(bv, cmd.x, cmd.y);
759 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
760 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
766 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
771 if (cmd.action < 0 && cmd.argument.empty())
774 bool hs = hasSelection();
777 // this one have priority over the locked InsetText, if we're not already
778 // inside another tabular then that one get's priority!
779 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
780 switch (cmd.action) {
781 case LFUN_MOUSE_PRESS:
785 case LFUN_MOUSE_MOTION:
786 lfunMouseMotion(cmd);
789 case LFUN_MOUSE_RELEASE:
790 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
792 case LFUN_CELL_BACKWARD:
793 case LFUN_CELL_FORWARD:
794 unlockInsetInInset(bv, the_locking_inset);
795 if (cmd.action == LFUN_CELL_FORWARD)
796 moveNextCell(bv, old_locking_inset != 0);
798 movePrevCell(bv, old_locking_inset != 0);
801 updateLocal(bv, SELECTION);
802 if (!the_locking_inset) {
803 return DISPATCHED_NOUPDATE;
806 // this to avoid compiler warnings.
812 kb_action action = cmd.action;
813 string arg = cmd.argument;
814 if (the_locking_inset) {
815 result = the_locking_inset->localDispatch(cmd);
816 if (result == DISPATCHED_NOUPDATE) {
819 if (sc != scroll()) { // inset has been scrolled
820 updateLocal(bv, FULL);
823 } else if (result == DISPATCHED) {
824 updateLocal(bv, CELL);
826 } else if (result == FINISHED_UP) {
828 // Make sure to reset status message after
829 // exiting, e.g. math inset
830 bv->owner()->clearMessage();
831 } else if (result == FINISHED_DOWN) {
833 bv->owner()->clearMessage();
834 } else if (result == FINISHED_RIGHT) {
836 bv->owner()->clearMessage();
837 } else if (result == FINISHED) {
838 bv->owner()->clearMessage();
844 // --- Cursor Movements ----------------------------------
845 case LFUN_RIGHTSEL: {
846 int const start = hasSelection() ? sel_cell_start : actcell;
847 if (tabular->IsLastCellInRow(actcell)) {
848 setSelection(start, actcell);
853 // if we are starting a selection, only select
854 // the current cell at the beginning
855 if (hasSelection()) {
856 moveRight(bv, false);
859 setSelection(start, end);
860 updateLocal(bv, SELECTION);
864 result = moveRight(bv);
867 updateLocal(bv, SELECTION);
870 int const start = hasSelection() ? sel_cell_start : actcell;
871 if (tabular->IsFirstCellInRow(actcell)) {
872 setSelection(start, actcell);
877 // if we are starting a selection, only select
878 // the current cell at the beginning
879 if (hasSelection()) {
883 setSelection(start, end);
884 updateLocal(bv, SELECTION);
888 result = moveLeft(bv);
891 updateLocal(bv, SELECTION);
894 int const start = hasSelection() ? sel_cell_start : actcell;
895 int const ocell = actcell;
896 // if we are starting a selection, only select
897 // the current cell at the beginning
898 if (hasSelection()) {
900 if ((ocell == sel_cell_end) ||
901 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
902 setSelection(start, tabular->GetCellBelow(sel_cell_end));
904 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
906 setSelection(start, start);
908 updateLocal(bv, SELECTION);
912 result = moveDown(bv, old_locking_inset != 0);
915 updateLocal(bv, SELECTION);
919 int const start = hasSelection() ? sel_cell_start : actcell;
920 int const ocell = actcell;
921 // if we are starting a selection, only select
922 // the current cell at the beginning
923 if (hasSelection()) {
925 if ((ocell == sel_cell_end) ||
926 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
927 setSelection(start, tabular->GetCellAbove(sel_cell_end));
929 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
931 setSelection(start, start);
933 updateLocal(bv, SELECTION);
937 result = moveUp(bv, old_locking_inset != 0);
940 updateLocal(bv, SELECTION);
943 UpdateCodes code = CURSOR;
949 unlockInsetInInset(bv, the_locking_inset);
950 if (bv->text->top_y() + bv->painter().paperHeight() <
951 (top_baseline + tabular->GetHeightOfTabular()))
953 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
955 actcell = tabular->GetCellBelow(first_visible_cell) + column;
957 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
960 updateLocal(bv, code);
964 UpdateCodes code = CURSOR;
970 unlockInsetInInset(bv, the_locking_inset);
971 if (top_baseline < 0) {
972 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
974 if (top_baseline > 0)
977 actcell = tabular->GetCellBelow(first_visible_cell) + column;
982 updateLocal(bv, code);
985 // none of these make sense for insettabular,
986 // but we must catch them to prevent any
987 // selection from being confused
991 case LFUN_WORDLEFTSEL:
993 case LFUN_WORDRIGHTSEL:
995 case LFUN_DOWN_PARAGRAPH:
996 case LFUN_DOWN_PARAGRAPHSEL:
997 case LFUN_UP_PARAGRAPH:
998 case LFUN_UP_PARAGRAPHSEL:
1004 case LFUN_BEGINNINGBUF:
1005 case LFUN_BEGINNINGBUFSEL:
1007 case LFUN_ENDBUFSEL:
1009 case LFUN_LAYOUT_TABULAR: {
1010 InsetTabularMailer mailer(*this);
1011 mailer.showDialog(bv);
1014 case LFUN_INSET_DIALOG_UPDATE: {
1015 InsetTabularMailer mailer(*this);
1016 mailer.updateDialog(bv);
1019 case LFUN_TABULAR_FEATURE:
1020 if (!tabularFeatures(bv, arg))
1021 result = UNDISPATCHED;
1023 // insert file functions
1024 case LFUN_FILE_INSERT_ASCII_PARA:
1025 case LFUN_FILE_INSERT_ASCII:
1027 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1030 if (insertAsciiString(bv, tmpstr, false))
1031 updateLocal(bv, INIT);
1033 result = UNDISPATCHED;
1036 // cut and paste functions
1038 if (!copySelection(bv))
1042 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1043 cutSelection(bv->buffer()->params);
1044 updateLocal(bv, INIT);
1047 if (!hasSelection())
1052 case LFUN_PASTESELECTION:
1054 string const clip(bv->getClipboard());
1058 if (clip.find('\t') != string::npos) {
1062 string::size_type len = clip.length();
1063 string::size_type p = 0;
1066 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1074 maxCols = max(cols, maxCols);
1080 maxCols = max(cols, maxCols);
1081 delete paste_tabular;
1082 paste_tabular = new LyXTabular(bv->buffer()->params,
1083 this, rows, maxCols);
1084 string::size_type op = 0;
1086 int cells = paste_tabular->GetNumberOfCells();
1088 while ((cell < cells) && (p < len) &&
1089 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1094 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1099 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1100 while (cols++ < maxCols)
1108 // check for the last cell if there is no trailing '\n'
1109 if ((cell < cells) && (op < len))
1110 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1113 if (!insertAsciiString(bv, clip, true))
1116 // so that the clipboard is used and it goes on
1118 // and executes LFUN_PASTESELECTION in insettext!
1119 delete paste_tabular;
1124 if (hasPasteBuffer()) {
1125 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1127 updateLocal(bv, INIT);
1130 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1132 // handle font changing stuff on selection before we lock the inset
1133 // in the default part!
1134 result = UNDISPATCHED;
1145 case LFUN_UNDERLINE:
1146 case LFUN_FONT_SIZE:
1147 if (bv->dispatch(FuncRequest(bv, action, arg)))
1148 result = DISPATCHED;
1154 // we try to activate the actual inset and put this event down to
1155 // the insets dispatch function.
1156 if ((result == DISPATCHED) || the_locking_inset)
1159 if (activateCellInset(bv)) {
1160 // reset need_update setted in above function!
1162 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1163 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1164 unlockInsetInInset(bv, the_locking_inset);
1166 // we need to update if this was requested before
1167 updateLocal(bv, NONE);
1168 return UNDISPATCHED;
1171 // so the below CELL is not set because this is higher
1172 // priority and we get a full redraw
1173 need_update = SELECTION;
1176 updateLocal(bv, CELL);
1181 if (result < FINISHED) {
1182 if (!the_locking_inset) {
1183 if (bv->fitCursor())
1184 updateLocal(bv, FULL);
1187 bv->unlockInset(this);
1192 int InsetTabular::latex(Buffer const * buf, ostream & os,
1193 LatexRunParams const & runparams) const
1195 return tabular->latex(buf, os, runparams);
1199 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1202 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1204 return tabular->ascii(buf, os, 0, false,0);
1208 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1211 int const ret = tabular->ascii(buf,os,
1212 (int)parOwner()->params().depth(),
1219 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1224 // if the table is inside a float it doesn't need the informaltable
1225 // wrapper. Search for it.
1226 for(master = owner();
1227 master && master->lyxCode() != Inset::FLOAT_CODE;
1228 master = master->owner());
1231 os << "<informaltable>";
1236 ret+= tabular->docbook(buf, os, mixcont);
1238 os << "</informaltable>";
1247 void InsetTabular::validate(LaTeXFeatures & features) const
1249 tabular->Validate(features);
1253 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1259 bool changed = false;
1261 // FIXME: since InsetText ignores this anyway, it doesn't
1262 // matter what we pass it. Ugly
1265 // if we have a locking_inset we should have to check only this cell for
1266 // change so I'll try this to have a boost, but who knows ;)
1267 if ((need_update != INIT) &&
1268 (the_locking_inset == tabular->GetCellInset(actcell))) {
1269 for(int i = 0; i < tabular->columns(); ++i) {
1270 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1272 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1275 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1276 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1277 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1280 for (int i = 0; i < tabular->rows(); ++i) {
1283 for (int j = 0; j < tabular->columns(); ++j) {
1284 if (tabular->IsPartOfMultiColumn(i,j))
1287 inset = tabular->GetCellInset(cell);
1288 if (!reinit && !tabular->GetPWidth(cell).zero())
1289 inset->update(bv, false);
1290 maxAsc = max(maxAsc, inset->ascent(bv, font));
1291 maxDesc = max(maxDesc, inset->descent(bv, font));
1292 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1294 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1295 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1303 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1305 if (the_locking_inset) {
1306 the_locking_inset->getCursor(bv, x, y);
1311 y = cursor_.y() + InsetTabular::y();
1314 int desc = tabular->GetDescentOfRow(actrow);
1316 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1318 y += ADD_TO_HEIGHT * 2;
1319 y += TEXT_TO_INSET_OFFSET;
1323 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1325 if (the_locking_inset) {
1326 the_locking_inset->getCursorPos(bv, x, y);
1329 x = cursor_.x() - top_x;
1334 void InsetTabular::fitInsetCursor(BufferView * bv) const
1336 if (the_locking_inset) {
1337 int old_top_y = bv->text->top_y();
1338 the_locking_inset->fitInsetCursor(bv);
1339 if (old_top_y != bv->text->top_y())
1345 int const asc = font_metrics::maxAscent(font);
1346 int const desc = font_metrics::maxDescent(font);
1349 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1354 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1358 actcell = actrow = actcol = 0;
1359 int ly = tabular->GetDescentOfRow(actrow);
1361 // first search the right row
1362 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1363 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1364 tabular->GetAscentOfRow(actrow + 1) +
1365 tabular->GetAdditionalHeight(actrow + 1));
1367 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1369 actcell = tabular->GetCellNumber(actrow, actcol);
1371 // now search the right column
1372 int lx = tabular->GetWidthOfColumn(actcell) -
1373 tabular->GetAdditionalWidth(actcell);
1374 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1375 lx += tabular->GetWidthOfColumn(actcell + 1)
1376 + tabular->GetAdditionalWidth(actcell);
1378 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1383 int InsetTabular::getCellXPos(int cell) const
1387 for (; !tabular->IsFirstCellInRow(c); --c)
1389 int lx = tabular->GetWidthOfColumn(cell);
1390 for (; c < cell; ++c) {
1391 lx += tabular->GetWidthOfColumn(c);
1393 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1397 void InsetTabular::resetPos(BufferView * bv) const
1399 #ifdef WITH_WARNINGS
1400 #warning This should be fixed in the right manner (20011128 Jug)
1402 // fast hack to fix infinite repaintings!
1403 if (in_reset_pos > 0)
1407 actcol = tabular->column_of_cell(actcell);
1410 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1411 if (tabular->IsLastCellInRow(cell)) {
1412 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1413 tabular->GetAscentOfRow(actrow + 1) +
1414 tabular->GetAdditionalHeight(actrow + 1));
1418 if (!locked || nodraw()) {
1419 if (the_locking_inset)
1420 inset_y = cursor_.y();
1423 // we need this only from here on!!!
1425 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1426 int new_x = getCellXPos(actcell);
1427 int old_x = cursor_.x();
1430 // cursor.x(getCellXPos(actcell) + offset);
1431 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1432 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1435 updateLocal(bv, FULL);
1436 } else if (the_locking_inset &&
1437 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1439 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1440 if (xx > (bv->workWidth()-20)) {
1441 scroll(bv, -(xx - bv->workWidth() + 60));
1442 updateLocal(bv, FULL);
1443 } else if (xx < 20) {
1449 updateLocal(bv, FULL);
1451 } else if ((cursor_.x() - offset) > 20 &&
1452 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1453 > (bv->workWidth() - 20)) {
1454 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1455 updateLocal(bv, FULL);
1456 } else if ((cursor_.x() - offset) < 20) {
1457 scroll(bv, 20 - cursor_.x() + offset);
1458 updateLocal(bv, FULL);
1459 } else if (scroll() && top_x > 20 &&
1460 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1461 scroll(bv, old_x - cursor_.x());
1462 updateLocal(bv, FULL);
1464 if (the_locking_inset) {
1465 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1466 inset_y = cursor_.y();
1468 if ((!the_locking_inset ||
1469 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1470 actcell != oldcell) {
1471 InsetTabular * inset = const_cast<InsetTabular *>(this);
1472 InsetTabularMailer mailer(*inset);
1473 mailer.updateDialog(bv);
1480 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1482 if (lock && !old_locking_inset) {
1483 if (activateCellInset(bv))
1486 bool moved = isRightToLeft(bv)
1487 ? movePrevCell(bv) : moveNextCell(bv);
1489 return FINISHED_RIGHT;
1490 if (lock && activateCellInset(bv))
1494 return DISPATCHED_NOUPDATE;
1498 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1500 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1503 if (lock) { // behind the inset
1504 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1508 return DISPATCHED_NOUPDATE;
1512 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1514 int const ocell = actcell;
1515 actcell = tabular->GetCellAbove(actcell);
1516 if (actcell == ocell) // we moved out of the inset
1522 if (old_locking_inset) {
1523 old_locking_inset->getCursorPos(bv, x, y);
1524 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1526 if (activateCellInset(bv, x, 0))
1529 return DISPATCHED_NOUPDATE;
1533 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1535 int const ocell = actcell;
1536 actcell = tabular->GetCellBelow(actcell);
1537 if (actcell == ocell) // we moved out of the inset
1538 return FINISHED_DOWN;
1543 if (old_locking_inset) {
1544 old_locking_inset->getCursorPos(bv, x, y);
1545 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1547 if (activateCellInset(bv, x, 0))
1550 return DISPATCHED_NOUPDATE;
1554 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1556 if (isRightToLeft(bv)) {
1557 if (tabular->IsFirstCellInRow(actcell)) {
1558 int row = tabular->row_of_cell(actcell);
1559 if (row == tabular->rows() - 1)
1561 actcell = tabular->GetLastCellInRow(row);
1562 actcell = tabular->GetCellBelow(actcell);
1569 if (tabular->IsLastCell(actcell))
1574 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1575 isRightToLeftPar(bv->buffer()->params);
1576 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1583 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1585 if (isRightToLeft(bv)) {
1586 if (tabular->IsLastCellInRow(actcell)) {
1587 int row = tabular->row_of_cell(actcell);
1590 actcell = tabular->GetFirstCellInRow(row);
1591 actcell = tabular->GetCellAbove(actcell);
1593 if (tabular->IsLastCell(actcell))
1598 if (!actcell) // first cell
1603 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1604 isRightToLeftPar(bv->buffer()->params);
1605 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1612 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1616 setSelection(0, tabular->GetNumberOfCells() - 1);
1618 if (hasSelection()) {
1619 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1620 bool const frozen = undo_frozen;
1623 // apply the fontchange on the whole selection
1628 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1629 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1630 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1631 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1638 updateLocal(bv, INIT);
1640 if (the_locking_inset)
1641 the_locking_inset->setFont(bv, font, tall);
1645 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1647 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1650 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1651 string const tmp = tabularFeature[i].feature;
1653 if (tmp == what.substr(0, tmp.length())) {
1654 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1655 //tabularFeatures[i].feature.length())) {
1656 action = tabularFeature[i].action;
1660 if (action == LyXTabular::LAST_ACTION)
1664 ltrim(what.substr(tabularFeature[i].feature.length()));
1665 tabularFeatures(bv, action, val);
1671 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1672 string const & special, bool & flag)
1674 if (special == "dl_above") {
1677 } else if (special == "dl_below") {
1678 ltt.bottomDL = flag;
1680 } else if (special == "empty") {
1692 void InsetTabular::tabularFeatures(BufferView * bv,
1693 LyXTabular::Feature feature,
1694 string const & value)
1700 bool setLines = false;
1701 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1702 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1705 case LyXTabular::M_ALIGN_LEFT:
1706 case LyXTabular::ALIGN_LEFT:
1707 setAlign = LYX_ALIGN_LEFT;
1709 case LyXTabular::M_ALIGN_RIGHT:
1710 case LyXTabular::ALIGN_RIGHT:
1711 setAlign = LYX_ALIGN_RIGHT;
1713 case LyXTabular::M_ALIGN_CENTER:
1714 case LyXTabular::ALIGN_CENTER:
1715 setAlign = LYX_ALIGN_CENTER;
1717 case LyXTabular::ALIGN_BLOCK:
1718 setAlign = LYX_ALIGN_BLOCK;
1720 case LyXTabular::M_VALIGN_TOP:
1721 case LyXTabular::VALIGN_TOP:
1722 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1724 case LyXTabular::M_VALIGN_BOTTOM:
1725 case LyXTabular::VALIGN_BOTTOM:
1726 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1728 case LyXTabular::M_VALIGN_CENTER:
1729 case LyXTabular::VALIGN_CENTER:
1730 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1735 if (hasSelection()) {
1736 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1738 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1739 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1741 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1743 int row = tabular->row_of_cell(actcell);
1744 int column = tabular->column_of_cell(actcell);
1746 LyXTabular::ltType ltt;
1749 case LyXTabular::SET_PWIDTH:
1751 LyXLength const vallen(value);
1752 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1754 bool const update = (tmplen != vallen);
1755 tabular->SetColumnPWidth(actcell, vallen);
1757 // We need this otherwise we won't resize
1758 // the insettext of the active cell (if any)
1759 // until later (see InsetText::do_resize)
1760 unlockInsetInInset(bv, the_locking_inset);
1763 for (int i = 0; i < tabular->rows(); ++i) {
1764 cell = tabular->GetCellNumber(i,column);
1765 tabular->GetCellInset(cell)->resizeLyXText(bv);
1767 updateLocal(bv, INIT);
1771 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1772 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1773 else if (!vallen.zero()
1774 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1775 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1778 case LyXTabular::SET_MPWIDTH:
1780 LyXLength const vallen(value);
1781 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1783 bool const update = (tmplen != vallen);
1784 tabular->SetMColumnPWidth(actcell, vallen);
1786 // We need this otherwise we won't resize
1787 // the insettext of the active cell (if any)
1788 // until later (see InsetText::do_resize)
1789 unlockInsetInInset(bv, the_locking_inset);
1791 for (int i = 0; i < tabular->rows(); ++i) {
1792 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1795 updateLocal(bv, INIT);
1799 case LyXTabular::SET_SPECIAL_COLUMN:
1800 case LyXTabular::SET_SPECIAL_MULTI:
1801 tabular->SetAlignSpecial(actcell,value,feature);
1802 updateLocal(bv, FULL);
1804 case LyXTabular::APPEND_ROW:
1805 // append the row into the tabular
1806 unlockInsetInInset(bv, the_locking_inset);
1807 tabular->AppendRow(bv->buffer()->params, actcell);
1808 updateLocal(bv, INIT);
1810 case LyXTabular::APPEND_COLUMN:
1811 // append the column into the tabular
1812 unlockInsetInInset(bv, the_locking_inset);
1813 tabular->AppendColumn(bv->buffer()->params, actcell);
1814 actcell = tabular->GetCellNumber(row, column);
1815 updateLocal(bv, INIT);
1817 case LyXTabular::DELETE_ROW:
1818 unlockInsetInInset(bv, the_locking_inset);
1819 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1820 tabular->DeleteRow(sel_row_start);
1822 if (sel_row_start >= tabular->rows())
1824 actcell = tabular->GetCellNumber(sel_row_start, column);
1826 updateLocal(bv, INIT);
1828 case LyXTabular::DELETE_COLUMN:
1829 unlockInsetInInset(bv, the_locking_inset);
1830 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1831 tabular->DeleteColumn(sel_col_start);
1833 if (sel_col_start >= tabular->columns())
1835 actcell = tabular->GetCellNumber(row, sel_col_start);
1837 updateLocal(bv, INIT);
1839 case LyXTabular::M_TOGGLE_LINE_TOP:
1841 case LyXTabular::TOGGLE_LINE_TOP:
1843 bool lineSet = !tabular->TopLine(actcell, flag);
1844 for (int i = sel_row_start; i <= sel_row_end; ++i)
1845 for (int j = sel_col_start; j <= sel_col_end; ++j)
1846 tabular->SetTopLine(
1847 tabular->GetCellNumber(i, j),
1849 updateLocal(bv, INIT);
1853 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1855 case LyXTabular::TOGGLE_LINE_BOTTOM:
1857 bool lineSet = !tabular->BottomLine(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->SetBottomLine(
1861 tabular->GetCellNumber(i, j),
1864 updateLocal(bv, INIT);
1868 case LyXTabular::M_TOGGLE_LINE_LEFT:
1870 case LyXTabular::TOGGLE_LINE_LEFT:
1872 bool lineSet = !tabular->LeftLine(actcell, flag);
1873 for (int i = sel_row_start; i <= sel_row_end; ++i)
1874 for (int j = sel_col_start; j <= sel_col_end; ++j)
1875 tabular->SetLeftLine(
1876 tabular->GetCellNumber(i,j),
1879 updateLocal(bv, INIT);
1883 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1885 case LyXTabular::TOGGLE_LINE_RIGHT:
1887 bool lineSet = !tabular->RightLine(actcell, flag);
1888 for (int i = sel_row_start; i <= sel_row_end; ++i)
1889 for (int j = sel_col_start; j <= sel_col_end; ++j)
1890 tabular->SetRightLine(
1891 tabular->GetCellNumber(i,j),
1894 updateLocal(bv, INIT);
1898 case LyXTabular::M_ALIGN_LEFT:
1899 case LyXTabular::M_ALIGN_RIGHT:
1900 case LyXTabular::M_ALIGN_CENTER:
1902 case LyXTabular::ALIGN_LEFT:
1903 case LyXTabular::ALIGN_RIGHT:
1904 case LyXTabular::ALIGN_CENTER:
1905 case LyXTabular::ALIGN_BLOCK:
1906 for (int i = sel_row_start; i <= sel_row_end; ++i)
1907 for (int j = sel_col_start; j <= sel_col_end; ++j)
1908 tabular->SetAlignment(
1909 tabular->GetCellNumber(i, j),
1912 updateLocal(bv, INIT);
1914 case LyXTabular::M_VALIGN_TOP:
1915 case LyXTabular::M_VALIGN_BOTTOM:
1916 case LyXTabular::M_VALIGN_CENTER:
1918 case LyXTabular::VALIGN_TOP:
1919 case LyXTabular::VALIGN_BOTTOM:
1920 case LyXTabular::VALIGN_CENTER:
1921 for (int i = sel_row_start; i <= sel_row_end; ++i)
1922 for (int j = sel_col_start; j <= sel_col_end; ++j)
1923 tabular->SetVAlignment(
1924 tabular->GetCellNumber(i, j),
1926 updateLocal(bv, INIT);
1928 case LyXTabular::MULTICOLUMN:
1930 if (sel_row_start != sel_row_end) {
1931 #ifdef WITH_WARNINGS
1932 #warning Need I say it ? This is horrible.
1934 Alert::error(_("Error setting multicolumn"),
1935 _("You cannot set multicolumn vertically."));
1938 // just multicol for one Single Cell
1939 if (!hasSelection()) {
1940 // check wether we are completly in a multicol
1941 if (tabular->IsMultiColumn(actcell)) {
1942 tabular->UnsetMultiColumn(actcell);
1943 updateLocal(bv, INIT);
1945 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1946 updateLocal(bv, CELL);
1950 // we have a selection so this means we just add all this
1951 // cells to form a multicolumn cell
1955 if (sel_cell_start > sel_cell_end) {
1956 s_start = sel_cell_end;
1957 s_end = sel_cell_start;
1959 s_start = sel_cell_start;
1960 s_end = sel_cell_end;
1962 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1965 updateLocal(bv, INIT);
1968 case LyXTabular::SET_ALL_LINES:
1970 case LyXTabular::UNSET_ALL_LINES:
1971 for (int i = sel_row_start; i <= sel_row_end; ++i)
1972 for (int j = sel_col_start; j <= sel_col_end; ++j)
1973 tabular->SetAllLines(
1974 tabular->GetCellNumber(i,j), setLines);
1975 updateLocal(bv, INIT);
1977 case LyXTabular::SET_LONGTABULAR:
1978 tabular->SetLongTabular(true);
1979 updateLocal(bv, INIT); // because this toggles displayed
1981 case LyXTabular::UNSET_LONGTABULAR:
1982 tabular->SetLongTabular(false);
1983 updateLocal(bv, INIT); // because this toggles displayed
1985 case LyXTabular::SET_ROTATE_TABULAR:
1986 tabular->SetRotateTabular(true);
1988 case LyXTabular::UNSET_ROTATE_TABULAR:
1989 tabular->SetRotateTabular(false);
1991 case LyXTabular::SET_ROTATE_CELL:
1992 for (int i = sel_row_start; i <= sel_row_end; ++i)
1993 for (int j = sel_col_start; j<=sel_col_end; ++j)
1994 tabular->SetRotateCell(
1995 tabular->GetCellNumber(i, j),
1998 case LyXTabular::UNSET_ROTATE_CELL:
1999 for (int i = sel_row_start; i <= sel_row_end; ++i)
2000 for (int j = sel_col_start; j <= sel_col_end; ++j)
2001 tabular->SetRotateCell(
2002 tabular->GetCellNumber(i, j), false);
2004 case LyXTabular::SET_USEBOX:
2006 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2007 if (val == tabular->GetUsebox(actcell))
2008 val = LyXTabular::BOX_NONE;
2009 for (int i = sel_row_start; i <= sel_row_end; ++i)
2010 for (int j = sel_col_start; j <= sel_col_end; ++j)
2012 tabular->GetCellNumber(i, j), val);
2015 case LyXTabular::UNSET_LTFIRSTHEAD:
2017 case LyXTabular::SET_LTFIRSTHEAD:
2018 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2019 checkLongtableSpecial(ltt, value, flag);
2020 tabular->SetLTHead(row, flag, ltt, true);
2022 case LyXTabular::UNSET_LTHEAD:
2024 case LyXTabular::SET_LTHEAD:
2025 (void)tabular->GetRowOfLTHead(row, ltt);
2026 checkLongtableSpecial(ltt, value, flag);
2027 tabular->SetLTHead(row, flag, ltt, false);
2029 case LyXTabular::UNSET_LTFOOT:
2031 case LyXTabular::SET_LTFOOT:
2032 (void)tabular->GetRowOfLTFoot(row, ltt);
2033 checkLongtableSpecial(ltt, value, flag);
2034 tabular->SetLTFoot(row, flag, ltt, false);
2036 case LyXTabular::UNSET_LTLASTFOOT:
2038 case LyXTabular::SET_LTLASTFOOT:
2039 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2040 checkLongtableSpecial(ltt, value, flag);
2041 tabular->SetLTFoot(row, flag, ltt, true);
2043 case LyXTabular::SET_LTNEWPAGE:
2045 bool what = !tabular->GetLTNewPage(row);
2046 tabular->SetLTNewPage(row, what);
2049 // dummy stuff just to avoid warnings
2050 case LyXTabular::LAST_ACTION:
2054 InsetTabularMailer mailer(*this);
2055 mailer.updateDialog(bv);
2059 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2062 UpdatableInset * inset =
2063 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2064 LyXFont font(LyXFont::ALL_SANE);
2066 x = inset->x() + inset->width(bv, font);
2067 y = inset->descent(bv, font);
2069 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2070 //inset_y = cursor.y();
2071 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2072 if (!the_locking_inset)
2074 updateLocal(bv, CELL);
2075 return (the_locking_inset != 0);
2079 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2080 mouse_button::state button)
2082 inset_x = cursor_.x()
2083 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2084 inset_y = cursor_.y();
2085 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2089 bool InsetTabular::insetHit(BufferView *, int x, int) const
2092 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2096 // This returns paperWidth() if the cell-width is unlimited or the width
2097 // in pixels if we have a pwidth for this cell.
2098 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2100 LyXLength const len = tabular->GetPWidth(cell);
2104 return len.inPixels(latexTextWidth(bv));
2108 int InsetTabular::getMaxWidth(BufferView * bv,
2109 UpdatableInset const * inset) const
2111 int cell = tabular->GetCellFromInset(inset, actcell);
2114 lyxerr << "Own inset not found, shouldn't really happen!"
2119 int w = getMaxWidthOfCell(bv, cell);
2121 // because the inset then subtracts it's top_x and owner->x()
2122 w += (inset->x() - top_x);
2129 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2131 resizeLyXText(bv, recursive);
2135 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2138 for(int i = 0; i < tabular->rows(); ++i) {
2139 for(int j = 0; j < tabular->columns(); ++j) {
2140 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2148 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2149 bool const recursive) const
2151 if (the_locking_inset)
2152 return the_locking_inset->getLyXText(bv, recursive);
2154 // if we're locked lock the actual insettext and return it's LyXText!!!
2156 UpdatableInset * inset =
2157 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2158 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2159 return the_locking_inset->getLyXText(bv, recursive);
2162 return Inset::getLyXText(bv, recursive);
2166 bool InsetTabular::showInsetDialog(BufferView * bv) const
2168 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2169 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2170 InsetTabularMailer mailer(*tmp);
2171 mailer.showDialog(bv);
2177 void InsetTabular::openLayoutDialog(BufferView * bv) const
2179 if (the_locking_inset) {
2180 InsetTabular * i = static_cast<InsetTabular *>
2181 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2183 i->openLayoutDialog(bv);
2187 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2188 InsetTabularMailer mailer(*tmp);
2189 mailer.showDialog(bv);
2194 // function returns an object as defined in func_status.h:
2195 // states OK, Unknown, Disabled, On, Off.
2197 FuncStatus InsetTabular::getStatus(string const & what) const
2199 int action = LyXTabular::LAST_ACTION;
2203 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2204 string const tmp = tabularFeature[i].feature;
2205 if (tmp == what.substr(0, tmp.length())) {
2206 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2207 // tabularFeatures[i].feature.length())) {
2208 action = tabularFeature[i].action;
2212 if (action == LyXTabular::LAST_ACTION) {
2214 return status.unknown(true);
2217 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2222 LyXTabular::ltType dummyltt;
2225 if (hasSelection()) {
2226 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2228 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2232 case LyXTabular::SET_PWIDTH:
2233 case LyXTabular::SET_MPWIDTH:
2234 case LyXTabular::SET_SPECIAL_COLUMN:
2235 case LyXTabular::SET_SPECIAL_MULTI:
2236 case LyXTabular::APPEND_ROW:
2237 case LyXTabular::APPEND_COLUMN:
2238 case LyXTabular::DELETE_ROW:
2239 case LyXTabular::DELETE_COLUMN:
2240 case LyXTabular::SET_ALL_LINES:
2241 case LyXTabular::UNSET_ALL_LINES:
2242 return status.clear();
2244 case LyXTabular::MULTICOLUMN:
2245 status.setOnOff(tabular->IsMultiColumn(actcell));
2247 case LyXTabular::M_TOGGLE_LINE_TOP:
2249 case LyXTabular::TOGGLE_LINE_TOP:
2250 status.setOnOff(tabular->TopLine(actcell, flag));
2252 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2254 case LyXTabular::TOGGLE_LINE_BOTTOM:
2255 status.setOnOff(tabular->BottomLine(actcell, flag));
2257 case LyXTabular::M_TOGGLE_LINE_LEFT:
2259 case LyXTabular::TOGGLE_LINE_LEFT:
2260 status.setOnOff(tabular->LeftLine(actcell, flag));
2262 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2264 case LyXTabular::TOGGLE_LINE_RIGHT:
2265 status.setOnOff(tabular->RightLine(actcell, flag));
2267 case LyXTabular::M_ALIGN_LEFT:
2269 case LyXTabular::ALIGN_LEFT:
2270 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2272 case LyXTabular::M_ALIGN_RIGHT:
2274 case LyXTabular::ALIGN_RIGHT:
2275 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2277 case LyXTabular::M_ALIGN_CENTER:
2279 case LyXTabular::ALIGN_CENTER:
2280 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2282 case LyXTabular::ALIGN_BLOCK:
2283 status.disabled(tabular->GetPWidth(actcell).zero());
2284 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2286 case LyXTabular::M_VALIGN_TOP:
2288 case LyXTabular::VALIGN_TOP:
2289 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2291 case LyXTabular::M_VALIGN_BOTTOM:
2293 case LyXTabular::VALIGN_BOTTOM:
2294 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2296 case LyXTabular::M_VALIGN_CENTER:
2298 case LyXTabular::VALIGN_CENTER:
2299 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2301 case LyXTabular::SET_LONGTABULAR:
2302 status.setOnOff(tabular->IsLongTabular());
2304 case LyXTabular::UNSET_LONGTABULAR:
2305 status.setOnOff(!tabular->IsLongTabular());
2307 case LyXTabular::SET_ROTATE_TABULAR:
2308 status.setOnOff(tabular->GetRotateTabular());
2310 case LyXTabular::UNSET_ROTATE_TABULAR:
2311 status.setOnOff(!tabular->GetRotateTabular());
2313 case LyXTabular::SET_ROTATE_CELL:
2314 status.setOnOff(tabular->GetRotateCell(actcell));
2316 case LyXTabular::UNSET_ROTATE_CELL:
2317 status.setOnOff(!tabular->GetRotateCell(actcell));
2319 case LyXTabular::SET_USEBOX:
2320 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2322 case LyXTabular::SET_LTFIRSTHEAD:
2323 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2325 case LyXTabular::SET_LTHEAD:
2326 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2328 case LyXTabular::SET_LTFOOT:
2329 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2331 case LyXTabular::SET_LTLASTFOOT:
2332 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2334 case LyXTabular::SET_LTNEWPAGE:
2335 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2339 status.disabled(true);
2346 vector<string> const InsetTabular::getLabelList() const
2348 return tabular->getLabelList();
2352 bool InsetTabular::copySelection(BufferView * bv)
2354 if (!hasSelection())
2357 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2358 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2359 if (sel_col_start > sel_col_end) {
2360 sel_col_start = sel_col_end;
2361 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2363 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2365 int const columns = sel_col_end - sel_col_start + 1;
2367 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2368 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2369 if (sel_row_start > sel_row_end) {
2370 swap(sel_row_start, sel_row_end);
2372 int const rows = sel_row_end - sel_row_start + 1;
2374 delete paste_tabular;
2375 paste_tabular = new LyXTabular(bv->buffer()->params,
2376 this, *tabular); // rows, columns);
2377 for (int i = 0; i < sel_row_start; ++i)
2378 paste_tabular->DeleteRow(0);
2379 while (paste_tabular->rows() > rows)
2380 paste_tabular->DeleteRow(rows);
2381 paste_tabular->SetTopLine(0, true, true);
2382 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2384 for (int i = 0; i < sel_col_start; ++i)
2385 paste_tabular->DeleteColumn(0);
2386 while (paste_tabular->columns() > columns)
2387 paste_tabular->DeleteColumn(columns);
2388 paste_tabular->SetLeftLine(0, true, true);
2389 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2393 paste_tabular->ascii(bv->buffer(), sstr,
2394 (int)parOwner()->params().depth(), true, '\t');
2395 bv->stuffClipboard(STRCONV(sstr.str()));
2400 bool InsetTabular::pasteSelection(BufferView * bv)
2405 for (int r1 = 0, r2 = actrow;
2406 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2408 for(int c1 = 0, c2 = actcol;
2409 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2411 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2412 tabular->IsPartOfMultiColumn(r2,c2))
2414 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2418 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2422 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2423 int const n2 = tabular->GetCellNumber(r2, c2);
2424 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2425 tabular->GetCellInset(n2)->setOwner(this);
2426 tabular->GetCellInset(n2)->deleteLyXText(bv);
2427 tabular->GetCellInset(n2)->markNew();
2434 bool InsetTabular::cutSelection(BufferParams const & bp)
2436 if (!hasSelection())
2439 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2440 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2441 if (sel_col_start > sel_col_end) {
2442 sel_col_start = sel_col_end;
2443 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2445 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2447 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2448 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2449 if (sel_row_start > sel_row_end) {
2450 swap(sel_row_start, sel_row_end);
2452 if (sel_cell_start > sel_cell_end) {
2453 swap(sel_cell_start, sel_cell_end);
2455 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2456 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2457 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2464 bool InsetTabular::isRightToLeft(BufferView * bv)
2466 return bv->getParentLanguage(this)->RightToLeft();
2470 bool InsetTabular::nodraw() const
2472 if (!UpdatableInset::nodraw() && the_locking_inset)
2473 return the_locking_inset->nodraw();
2474 return UpdatableInset::nodraw();
2478 int InsetTabular::scroll(bool recursive) const
2480 int sx = UpdatableInset::scroll(false);
2482 if (recursive && the_locking_inset)
2483 sx += the_locking_inset->scroll(recursive);
2489 void InsetTabular::getSelection(int & srow, int & erow,
2490 int & scol, int & ecol) const
2492 int const start = hasSelection() ? sel_cell_start : actcell;
2493 int const end = hasSelection() ? sel_cell_end : actcell;
2495 srow = tabular->row_of_cell(start);
2496 erow = tabular->row_of_cell(end);
2501 scol = tabular->column_of_cell(start);
2502 ecol = tabular->column_of_cell(end);
2506 ecol = tabular->right_column_of_cell(end);
2511 ParagraphList * InsetTabular::getParagraphs(int i) const
2513 return (i < tabular->GetNumberOfCells())
2514 ? tabular->GetCellInset(i)->getParagraphs(0)
2519 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2521 if (the_locking_inset)
2522 return the_locking_inset->cursor(bv);
2523 return Inset::cursor(bv);
2527 Inset * InsetTabular::getInsetFromID(int id_arg) const
2530 return const_cast<InsetTabular *>(this);
2533 for(int i = 0; i < tabular->rows(); ++i) {
2534 for(int j = 0; j < tabular->columns(); ++j) {
2535 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2544 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2547 if (the_locking_inset) {
2548 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2549 if (!word.word().empty()) {
2553 if (tabular->IsLastCell(actcell)) {
2554 bv->unlockInset(const_cast<InsetTabular *>(this));
2556 return WordLangTuple();
2560 // otherwise we have to lock the next inset and ask for it's selecttion
2561 UpdatableInset * inset =
2562 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2563 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2564 WordLangTuple word(selectNextWordInt(bv, value));
2566 if (!word.word().empty())
2572 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2574 // when entering this function the inset should be ALWAYS locked!
2575 lyx::Assert(the_locking_inset);
2577 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2578 if (!word.word().empty())
2581 if (tabular->IsLastCell(actcell)) {
2582 bv->unlockInset(const_cast<InsetTabular *>(this));
2583 return WordLangTuple();
2586 // otherwise we have to lock the next inset and ask for it's selecttion
2587 UpdatableInset * inset =
2588 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2589 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2590 return selectNextWordInt(bv, value);
2594 void InsetTabular::selectSelectedWord(BufferView * bv)
2596 if (the_locking_inset) {
2597 the_locking_inset->selectSelectedWord(bv);
2604 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2606 if (the_locking_inset) {
2607 the_locking_inset->toggleSelection(bv, kill_selection);
2612 void InsetTabular::markErased()
2616 while (!tabular->IsLastCell(cell)) {
2618 InsetText * inset = tabular->GetCellInset(cell);
2619 inset->markErased();
2624 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2626 if (the_locking_inset) {
2627 if (the_locking_inset->nextChange(bv, length)) {
2628 updateLocal(bv, CELL);
2631 if (tabular->IsLastCell(actcell))
2635 InsetText * inset = tabular->GetCellInset(actcell);
2636 if (inset->nextChange(bv, length)) {
2637 updateLocal(bv, FULL);
2640 while (!tabular->IsLastCell(actcell)) {
2642 inset = tabular->GetCellInset(actcell);
2643 if (inset->nextChange(bv, length)) {
2644 updateLocal(bv, FULL);
2652 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2656 if (the_locking_inset) {
2657 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2658 updateLocal(bv, CELL);
2661 if (tabular->IsLastCell(actcell))
2665 InsetText * inset = tabular->GetCellInset(cell);
2666 if (inset->searchForward(bv, str, cs, mw)) {
2667 updateLocal(bv, FULL);
2670 while (!tabular->IsLastCell(cell)) {
2672 inset = tabular->GetCellInset(cell);
2673 if (inset->searchForward(bv, str, cs, mw)) {
2674 updateLocal(bv, FULL);
2682 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2685 int cell = tabular->GetNumberOfCells();
2686 if (the_locking_inset) {
2687 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2688 updateLocal(bv, CELL);
2696 InsetText * inset = tabular->GetCellInset(cell);
2697 if (inset->searchBackward(bv, str, cs, mw)) {
2698 updateLocal(bv, CELL);
2706 bool InsetTabular::insetAllowed(Inset::Code code) const
2708 if (the_locking_inset)
2709 return the_locking_inset->insetAllowed(code);
2710 // we return true here because if the inset is not locked someone
2711 // wants to insert something in one of our insettexts and we generally
2717 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2719 const int cell = tabular->GetCellFromInset(in, actcell);
2722 return tabular->GetPWidth(cell).zero();
2724 // well we didn't obviously find it so maybe our owner knows more
2726 return owner()->forceDefaultParagraphs(in);
2727 // if we're here there is really something strange going on!!!
2731 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2734 if (buf.length() <= 0)
2740 string::size_type len = buf.length();
2741 string::size_type p = 0;
2744 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2753 maxCols = max(cols, maxCols);
2759 maxCols = max(cols, maxCols);
2760 LyXTabular * loctab;
2765 delete paste_tabular;
2766 paste_tabular = new LyXTabular(bv->buffer()->params,
2767 this, rows, maxCols);
2768 loctab = paste_tabular;
2771 loctab = tabular.get();
2777 string::size_type op = 0;
2778 int cells = loctab->GetNumberOfCells();
2781 rows = loctab->rows();
2782 int const columns = loctab->columns();
2784 while ((cell < cells) && (p < len) && (row < rows) &&
2785 (p = buf.find_first_of("\t\n", p)) != string::npos)
2791 // we can only set this if we are not too far right
2792 if (cols < columns) {
2793 InsetText * ti = loctab->GetCellInset(cell);
2794 LyXFont const font = ti->getLyXText(bv)->
2795 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2796 ti->setText(buf.substr(op, p - op), font);
2802 // we can only set this if we are not too far right
2803 if (cols < columns) {
2804 InsetText * ti = loctab->GetCellInset(cell);
2805 LyXFont const font = ti->getLyXText(bv)->
2806 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2807 ti->setText(buf.substr(op, p - op), font);
2812 cell = loctab->GetCellNumber(row, cols);
2818 // check for the last cell if there is no trailing '\n'
2819 if ((cell < cells) && (op < len)) {
2820 InsetText * ti = loctab->GetCellInset(cell);
2821 LyXFont const font = ti->getLyXText(bv)->
2822 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2823 ti->setText(buf.substr(op, len - op), font);
2830 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2832 int const rows = tabular->rows();
2833 int const columns = tabular->columns();
2834 for (int i = 0; i < rows; ++i) {
2835 for (int j = 0; j < columns; ++j) {
2836 tabular->GetCellInset(i,j)->addPreview(loader);
2842 string const InsetTabularMailer:: name_("tabular");
2844 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2849 string const InsetTabularMailer::inset2string() const
2851 return params2string(inset_);
2855 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2857 istringstream data(STRCONV(in));
2859 lex.setStream(data);
2861 #warning CHECK verify that this is a sane value to return.
2867 string const token = lex.getString();
2875 string const token = lex.getString();
2876 if (token != "\\active_cell")
2879 cell = lex.getInteger();
2882 // This is part of the inset proper that is usually swallowed
2883 // by Buffer::readInset
2886 string const token = lex.getString();
2887 if (token != "Tabular")
2894 BufferView * const bv = inset.view();
2895 Buffer const * const buffer = bv ? bv->buffer() : 0;
2897 inset.read(buffer, lex);
2899 // We can't set the active cell, but we can tell the frontend
2905 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2907 BufferView * const bv = inset.view();
2908 Buffer const * const buffer = bv ? bv->buffer() : 0;
2913 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2914 inset.write(buffer, data);
2915 data << "\\end_inset\n";
2916 return STRCONV(data.str());