3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "insettabular.h"
14 #include "insettext.h"
17 #include "BufferView.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
28 #include "lyxlength.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
36 #include "frontends/Alert.h"
37 #include "frontends/Dialogs.h"
38 #include "frontends/font_metrics.h"
39 #include "frontends/LyXView.h"
40 #include "frontends/Painter.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
126 bool operator()(TabularFeature & tf)
128 return tf.action == feature_;
131 LyXTabular::Feature feature_;
137 string const featureAsString(LyXTabular::Feature feature)
139 TabularFeature * it = tabularFeature;
140 TabularFeature * end = it +
141 sizeof(tabularFeature) / sizeof(TabularFeature);
142 it = std::find_if(it, end, FindFeature(feature));
143 return (it == end) ? string() : it->feature;
147 bool InsetTabular::hasPasteBuffer() const
149 return (paste_tabular != 0);
153 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
160 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
177 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
178 : UpdatableInset(tab), buffer(&buf)
180 tabular.reset(new LyXTabular(buf.params,
181 this, *(tab.tabular)));
182 the_locking_inset = 0;
183 old_locking_inset = 0;
186 actrow = actcell = 0;
196 // InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
198 // : UpdatableInset(tab, same_id), buffer(&buf)
200 // tabular.reset(new LyXTabular(buf.params,
201 // this, *(tab.tabular), same_id));
202 // the_locking_inset = 0;
203 // old_locking_inset = 0;
206 // actrow = actcell = 0;
208 // need_update = INIT;
209 // in_update = false;
216 InsetTabular::~InsetTabular()
218 InsetTabularMailer mailer(*this);
223 Inset * InsetTabular::clone(Buffer const & buf) const
225 return new InsetTabular(*this, buf);
229 // Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
231 // return new InsetTabular(*this, buf, same_id);
235 BufferView * InsetTabular::view() const
237 return buffer->getUser();
241 void InsetTabular::write(Buffer const * buf, ostream & os) const
243 os << " Tabular" << endl;
244 tabular->Write(buf, os);
248 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
250 bool const old_format = (lex.getString() == "\\LyXTable");
252 tabular.reset(new LyXTabular(buf, this, lex));
260 string token = lex.getString();
261 while (lex.isOK() && (token != "\\end_inset")) {
263 token = lex.getString();
265 if (token != "\\end_inset") {
266 lex.printError("Missing \\end_inset at this point. "
272 void InsetTabular::dimension(BufferView *, LyXFont const &,
273 Dimension & dim) const
275 dim.a = tabular->GetAscentOfRow(0);
276 dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
277 dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
281 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
289 Painter & pain = bv->painter();
295 UpdatableInset::draw(bv, font, baseline, x);
298 x += static_cast<float>(scroll());
302 top_baseline = baseline;
303 x += ADD_TO_TABULAR_WIDTH;
307 first_visible_cell = -1;
308 for (i = 0; i < tabular->rows(); ++i) {
310 cell = tabular->GetCellNumber(i, 0);
311 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
312 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
314 baseline += tabular->GetDescentOfRow(i) +
315 tabular->GetAscentOfRow(i + 1) +
316 tabular->GetAdditionalHeight(i + 1);
319 for (j = 0; j < tabular->columns(); ++j) {
320 if (nx > bv->workWidth())
322 if (tabular->IsPartOfMultiColumn(i, j))
324 cx = nx + tabular->GetBeginningOfTextInCell(cell);
325 if (first_visible_cell < 0)
326 first_visible_cell = cell;
327 if (hasSelection()) {
328 drawCellSelection(pain, nx, baseline, i, j, cell);
331 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
332 drawCellLines(pain, nx, baseline, i, cell);
333 nx += tabular->GetWidthOfColumn(cell);
337 // avoiding drawing the rest of a long table is
338 // a pretty big speedup
339 if (baseline > bv->workHeight())
342 baseline += tabular->GetDescentOfRow(i) +
343 tabular->GetAscentOfRow(i + 1) +
344 tabular->GetAdditionalHeight(i + 1);
347 x -= ADD_TO_TABULAR_WIDTH;
348 x += width(bv, font);
353 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
354 int row, int cell) const
356 int x2 = x + tabular->GetWidthOfColumn(cell);
359 if (!tabular->topAlreadyDrawn(cell)) {
360 on_off = !tabular->TopLine(cell);
361 pain.line(x, baseline - tabular->GetAscentOfRow(row),
362 x2, baseline - tabular->GetAscentOfRow(row),
363 on_off ? LColor::tabularonoffline : LColor::tabularline,
364 on_off ? Painter::line_onoffdash : Painter::line_solid);
366 on_off = !tabular->BottomLine(cell);
367 pain.line(x, baseline + tabular->GetDescentOfRow(row),
368 x2, baseline + tabular->GetDescentOfRow(row),
369 on_off ? LColor::tabularonoffline : LColor::tabularline,
370 on_off ? Painter::line_onoffdash : Painter::line_solid);
371 if (!tabular->leftAlreadyDrawn(cell)) {
372 on_off = !tabular->LeftLine(cell);
373 pain.line(x, baseline - tabular->GetAscentOfRow(row),
374 x, baseline + tabular->GetDescentOfRow(row),
375 on_off ? LColor::tabularonoffline : LColor::tabularline,
376 on_off ? Painter::line_onoffdash : Painter::line_solid);
378 on_off = !tabular->RightLine(cell);
379 pain.line(x2 - tabular->GetAdditionalWidth(cell),
380 baseline - tabular->GetAscentOfRow(row),
381 x2 - tabular->GetAdditionalWidth(cell),
382 baseline + tabular->GetDescentOfRow(row),
383 on_off ? LColor::tabularonoffline : LColor::tabularline,
384 on_off ? Painter::line_onoffdash : Painter::line_solid);
388 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
389 int row, int column, int cell) const
391 lyx::Assert(hasSelection());
392 int cs = tabular->column_of_cell(sel_cell_start);
393 int ce = tabular->column_of_cell(sel_cell_end);
396 cs = tabular->column_of_cell(sel_cell_end);
398 ce = tabular->right_column_of_cell(sel_cell_end);
401 int rs = tabular->row_of_cell(sel_cell_start);
402 int re = tabular->row_of_cell(sel_cell_end);
406 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
407 int w = tabular->GetWidthOfColumn(cell);
408 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
409 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
410 w, h, LColor::selection);
415 void InsetTabular::update(BufferView * bv, bool reinit)
421 owner()->update(bv, true);
428 if (calculate_dimensions_of_cells(bv, true))
431 owner()->update(bv, true);
435 if (the_locking_inset)
436 the_locking_inset->update(bv, reinit);
437 if (need_update < FULL &&
438 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
443 switch (need_update) {
447 if (calculate_dimensions_of_cells(bv, false)) {
462 string const InsetTabular::editMessage() const
464 return _("Opened table");
468 void InsetTabular::insetUnlock(BufferView * bv)
470 if (the_locking_inset) {
471 the_locking_inset->insetUnlock(bv);
472 updateLocal(bv, CELL);
473 the_locking_inset = 0;
478 if (scroll(false) || hasSelection()) {
483 updateLocal(bv, FULL);
488 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
491 calculate_dimensions_of_cells(bv, true);
493 if (!locked && what == CELL)
495 if (need_update < what) // only set this if it has greater update
498 if (need_update != NONE) {
499 bv->updateInset(const_cast<InsetTabular *>(this));
506 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
508 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
513 if (inset == tabular->GetCellInset(actcell)) {
514 lyxerr[Debug::INSETTEXT] << "OK" << endl;
515 the_locking_inset = tabular->GetCellInset(actcell);
518 } else if (!the_locking_inset) {
519 int const n = tabular->GetNumberOfCells();
520 int const id = inset->id();
521 for (int i = 0; i < n; ++i) {
522 InsetText * in = tabular->GetCellInset(i);
525 the_locking_inset = in;
530 if (in->getInsetFromID(id)) {
532 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
533 return the_locking_inset->lockInsetInInset(bv, inset);
536 } else if (the_locking_inset && (the_locking_inset == inset)) {
537 lyxerr[Debug::INSETTEXT] << "OK" << endl;
539 } else if (the_locking_inset) {
540 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
541 return the_locking_inset->lockInsetInInset(bv, inset);
543 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
548 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
551 if (!the_locking_inset)
553 if (the_locking_inset == inset) {
554 the_locking_inset->insetUnlock(bv);
556 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
562 updateLocal(bv, CELL);
563 // this has to be here otherwise we don't redraw the cell!
564 the_locking_inset = 0;
567 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
568 if (inset->lyxCode() == TABULAR_CODE &&
569 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
570 InsetTabularMailer mailer(*this);
571 mailer.updateDialog(bv);
580 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
582 Inset * tl_inset = inset;
583 // look if this inset is really inside myself!
584 while(tl_inset->owner() && tl_inset->owner() != this)
585 tl_inset = tl_inset->owner();
586 // if we enter here it's not ower inset
587 if (!tl_inset->owner())
589 // we only have to do this if this is a subinset of our cells
590 if (tl_inset != inset) {
591 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
594 updateLocal(bv, CELL);
599 int InsetTabular::insetInInsetY() const
601 if (!the_locking_inset)
603 return inset_y + the_locking_inset->insetInInsetY();
607 UpdatableInset * InsetTabular::getLockingInset() const
609 return the_locking_inset ? the_locking_inset->getLockingInset() :
610 const_cast<InsetTabular *>(this);
614 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
618 if (the_locking_inset)
619 return the_locking_inset->getFirstLockingInsetOfType(c);
624 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
626 if (the_locking_inset)
627 return the_locking_inset->insertInset(bv, inset);
632 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
634 if (hasSelection() && cmd.button() == mouse_button::button3)
637 if (hasSelection()) {
639 updateLocal(cmd.view(), SELECTION);
642 int const ocell = actcell;
643 int const orow = actrow;
644 BufferView * bv = cmd.view();
648 the_locking_inset = 0;
652 setPos(bv, cmd.x, cmd.y);
654 updateLocal(bv, NONE);
657 if (cmd.button() == mouse_button::button3) {
658 if ((ocell != actcell) && the_locking_inset) {
659 the_locking_inset->insetUnlock(bv);
660 updateLocal(bv, CELL);
661 the_locking_inset = 0;
667 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
669 if ((ocell == actcell) && the_locking_inset && inset_hit) {
671 FuncRequest cmd1 = cmd;
674 the_locking_inset->localDispatch(cmd1);
678 if (the_locking_inset) {
679 the_locking_inset->insetUnlock(bv);
680 updateLocal(bv, CELL);
681 the_locking_inset = 0;
684 if (cmd.button() == mouse_button::button2) {
685 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
689 if (inset_hit && bv->theLockingInset()) {
690 if (!bv->lockInset(static_cast<UpdatableInset*>
691 (tabular->GetCellInset(actcell))))
693 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
696 FuncRequest cmd1 = cmd;
699 the_locking_inset->localDispatch(cmd1);
705 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
708 if (the_locking_inset) {
709 FuncRequest cmd1 = cmd;
712 ret = the_locking_inset->localDispatch(cmd1);
714 if (cmd.button() == mouse_button::button3 && !ret) {
715 InsetTabularMailer(*this).showDialog(cmd.view());
722 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
724 if (the_locking_inset) {
725 FuncRequest cmd1 = cmd;
728 the_locking_inset->localDispatch(cmd1);
732 BufferView * bv = cmd.view();
733 int const old_cell = actcell;
735 setPos(bv, cmd.x, cmd.y);
736 if (!hasSelection()) {
737 setSelection(actcell, actcell);
738 updateLocal(bv, SELECTION);
739 } else if (old_cell != actcell) {
740 setSelection(sel_cell_start, actcell);
741 updateLocal(bv, SELECTION);
746 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
748 // We need to save the value of the_locking_inset as the call to
749 // the_locking_inset->localDispatch might unlock it.
750 old_locking_inset = the_locking_inset;
751 RESULT result = UpdatableInset::localDispatch(cmd);
752 BufferView * bv = cmd.view();
754 if (cmd.action == LFUN_INSET_EDIT) {
756 if (!bv->lockInset(this)) {
757 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
763 the_locking_inset = 0;
767 if (cmd.argument.size()) {
768 if (cmd.argument == "left") {
769 if (isRightToLeft(bv))
770 actcell = tabular->GetLastCellInRow(0);
774 if (isRightToLeft(bv))
775 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
777 actcell = tabular->GetNumberOfCells() - 1;
785 setPos(bv, cmd.x, cmd.y);
788 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
789 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
795 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
800 if (cmd.action < 0 && cmd.argument.empty())
803 bool hs = hasSelection();
806 // this one have priority over the locked InsetText, if we're not already
807 // inside another tabular then that one get's priority!
808 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
809 switch (cmd.action) {
810 case LFUN_MOUSE_PRESS:
814 case LFUN_MOUSE_MOTION:
815 lfunMouseMotion(cmd);
818 case LFUN_MOUSE_RELEASE:
819 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
821 case LFUN_CELL_BACKWARD:
822 case LFUN_CELL_FORWARD:
823 unlockInsetInInset(bv, the_locking_inset);
824 if (cmd.action == LFUN_CELL_FORWARD)
825 moveNextCell(bv, old_locking_inset != 0);
827 movePrevCell(bv, old_locking_inset != 0);
830 updateLocal(bv, SELECTION);
831 if (!the_locking_inset) {
832 return DISPATCHED_NOUPDATE;
835 // this to avoid compiler warnings.
841 kb_action action = cmd.action;
842 string arg = cmd.argument;
843 if (the_locking_inset) {
844 result = the_locking_inset->localDispatch(cmd);
845 if (result == DISPATCHED_NOUPDATE) {
848 if (sc != scroll()) { // inset has been scrolled
849 updateLocal(bv, FULL);
852 } else if (result == DISPATCHED) {
853 updateLocal(bv, CELL);
855 } else if (result == FINISHED_UP) {
857 // Make sure to reset status message after
858 // exiting, e.g. math inset
859 bv->owner()->clearMessage();
860 } else if (result == FINISHED_DOWN) {
862 bv->owner()->clearMessage();
863 } else if (result == FINISHED_RIGHT) {
865 bv->owner()->clearMessage();
866 } else if (result == FINISHED) {
867 bv->owner()->clearMessage();
873 // --- Cursor Movements ----------------------------------
874 case LFUN_RIGHTSEL: {
875 int const start = hasSelection() ? sel_cell_start : actcell;
876 if (tabular->IsLastCellInRow(actcell)) {
877 setSelection(start, actcell);
882 // if we are starting a selection, only select
883 // the current cell at the beginning
884 if (hasSelection()) {
885 moveRight(bv, false);
888 setSelection(start, end);
889 updateLocal(bv, SELECTION);
893 result = moveRight(bv);
896 updateLocal(bv, SELECTION);
899 int const start = hasSelection() ? sel_cell_start : actcell;
900 if (tabular->IsFirstCellInRow(actcell)) {
901 setSelection(start, actcell);
906 // if we are starting a selection, only select
907 // the current cell at the beginning
908 if (hasSelection()) {
912 setSelection(start, end);
913 updateLocal(bv, SELECTION);
917 result = moveLeft(bv);
920 updateLocal(bv, SELECTION);
923 int const start = hasSelection() ? sel_cell_start : actcell;
924 int const ocell = actcell;
925 // if we are starting a selection, only select
926 // the current cell at the beginning
927 if (hasSelection()) {
929 if ((ocell == sel_cell_end) ||
930 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
931 setSelection(start, tabular->GetCellBelow(sel_cell_end));
933 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
935 setSelection(start, start);
937 updateLocal(bv, SELECTION);
941 result = moveDown(bv, old_locking_inset != 0);
944 updateLocal(bv, SELECTION);
948 int const start = hasSelection() ? sel_cell_start : actcell;
949 int const ocell = actcell;
950 // if we are starting a selection, only select
951 // the current cell at the beginning
952 if (hasSelection()) {
954 if ((ocell == sel_cell_end) ||
955 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
956 setSelection(start, tabular->GetCellAbove(sel_cell_end));
958 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
960 setSelection(start, start);
962 updateLocal(bv, SELECTION);
966 result = moveUp(bv, old_locking_inset != 0);
969 updateLocal(bv, SELECTION);
972 UpdateCodes code = CURSOR;
978 unlockInsetInInset(bv, the_locking_inset);
979 if (bv->text->top_y() + bv->painter().paperHeight() <
980 (top_baseline + tabular->GetHeightOfTabular()))
982 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
984 actcell = tabular->GetCellBelow(first_visible_cell) + column;
986 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
989 updateLocal(bv, code);
993 UpdateCodes code = CURSOR;
999 unlockInsetInInset(bv, the_locking_inset);
1000 if (top_baseline < 0) {
1001 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
1003 if (top_baseline > 0)
1006 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1011 updateLocal(bv, code);
1014 // none of these make sense for insettabular,
1015 // but we must catch them to prevent any
1016 // selection from being confused
1020 case LFUN_WORDLEFTSEL:
1021 case LFUN_WORDRIGHT:
1022 case LFUN_WORDRIGHTSEL:
1024 case LFUN_DOWN_PARAGRAPH:
1025 case LFUN_DOWN_PARAGRAPHSEL:
1026 case LFUN_UP_PARAGRAPH:
1027 case LFUN_UP_PARAGRAPHSEL:
1028 case LFUN_BACKSPACE:
1033 case LFUN_BEGINNINGBUF:
1034 case LFUN_BEGINNINGBUFSEL:
1036 case LFUN_ENDBUFSEL:
1038 case LFUN_LAYOUT_TABULAR: {
1039 InsetTabularMailer mailer(*this);
1040 mailer.showDialog(bv);
1043 case LFUN_INSET_DIALOG_UPDATE: {
1044 InsetTabularMailer mailer(*this);
1045 mailer.updateDialog(bv);
1048 case LFUN_TABULAR_FEATURE:
1049 if (!tabularFeatures(bv, arg))
1050 result = UNDISPATCHED;
1052 // insert file functions
1053 case LFUN_FILE_INSERT_ASCII_PARA:
1054 case LFUN_FILE_INSERT_ASCII:
1056 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1059 if (insertAsciiString(bv, tmpstr, false))
1060 updateLocal(bv, INIT);
1062 result = UNDISPATCHED;
1065 // cut and paste functions
1067 if (!copySelection(bv))
1071 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1072 cutSelection(bv->buffer()->params);
1073 updateLocal(bv, INIT);
1076 if (!hasSelection())
1081 case LFUN_PASTESELECTION:
1083 string const clip(bv->getClipboard());
1087 if (clip.find('\t') != string::npos) {
1091 string::size_type len = clip.length();
1092 string::size_type p = 0;
1095 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1103 maxCols = max(cols, maxCols);
1109 maxCols = max(cols, maxCols);
1110 delete paste_tabular;
1111 paste_tabular = new LyXTabular(bv->buffer()->params,
1112 this, rows, maxCols);
1113 string::size_type op = 0;
1115 int cells = paste_tabular->GetNumberOfCells();
1117 while ((cell < cells) && (p < len) &&
1118 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1123 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1128 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1129 while (cols++ < maxCols)
1137 // check for the last cell if there is no trailing '\n'
1138 if ((cell < cells) && (op < len))
1139 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1142 if (!insertAsciiString(bv, clip, true))
1145 // so that the clipboard is used and it goes on
1147 // and executes LFUN_PASTESELECTION in insettext!
1148 delete paste_tabular;
1153 if (hasPasteBuffer()) {
1154 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1156 updateLocal(bv, INIT);
1159 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1161 // handle font changing stuff on selection before we lock the inset
1162 // in the default part!
1163 result = UNDISPATCHED;
1174 case LFUN_UNDERLINE:
1175 case LFUN_FONT_SIZE:
1176 if (bv->dispatch(FuncRequest(bv, action, arg)))
1177 result = DISPATCHED;
1183 // we try to activate the actual inset and put this event down to
1184 // the insets dispatch function.
1185 if ((result == DISPATCHED) || the_locking_inset)
1188 if (activateCellInset(bv)) {
1189 // reset need_update setted in above function!
1191 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1192 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1193 unlockInsetInInset(bv, the_locking_inset);
1195 // we need to update if this was requested before
1196 updateLocal(bv, NONE);
1197 return UNDISPATCHED;
1200 // so the below CELL is not set because this is higher
1201 // priority and we get a full redraw
1202 need_update = SELECTION;
1205 updateLocal(bv, CELL);
1210 if (result < FINISHED) {
1211 if (!the_locking_inset) {
1212 if (bv->fitCursor())
1213 updateLocal(bv, FULL);
1216 bv->unlockInset(this);
1221 int InsetTabular::latex(Buffer const * buf, ostream & os,
1222 LatexRunParams const & runparams) const
1224 return tabular->latex(buf, os, runparams);
1228 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1231 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1233 return tabular->ascii(buf, os, 0, false,0);
1237 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1240 int const ret = tabular->ascii(buf,os,
1241 (int)parOwner()->params().depth(),
1248 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1253 // if the table is inside a float it doesn't need the informaltable
1254 // wrapper. Search for it.
1255 for(master = owner();
1256 master && master->lyxCode() != Inset::FLOAT_CODE;
1257 master = master->owner());
1260 os << "<informaltable>";
1265 ret+= tabular->docbook(buf, os, mixcont);
1267 os << "</informaltable>";
1276 void InsetTabular::validate(LaTeXFeatures & features) const
1278 tabular->Validate(features);
1282 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1288 bool changed = false;
1290 // FIXME: since InsetText ignores this anyway, it doesn't
1291 // matter what we pass it. Ugly
1294 // if we have a locking_inset we should have to check only this cell for
1295 // change so I'll try this to have a boost, but who knows ;)
1296 if ((need_update != INIT) &&
1297 (the_locking_inset == tabular->GetCellInset(actcell))) {
1298 for(int i = 0; i < tabular->columns(); ++i) {
1299 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1301 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1304 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1305 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1306 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1309 for (int i = 0; i < tabular->rows(); ++i) {
1312 for (int j = 0; j < tabular->columns(); ++j) {
1313 if (tabular->IsPartOfMultiColumn(i,j))
1316 inset = tabular->GetCellInset(cell);
1317 if (!reinit && !tabular->GetPWidth(cell).zero())
1318 inset->update(bv, false);
1319 maxAsc = max(maxAsc, inset->ascent(bv, font));
1320 maxDesc = max(maxDesc, inset->descent(bv, font));
1321 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1323 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1324 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1332 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1334 if (the_locking_inset) {
1335 the_locking_inset->getCursor(bv, x, y);
1340 y = cursor_.y() + InsetTabular::y();
1343 int desc = tabular->GetDescentOfRow(actrow);
1345 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1347 y += ADD_TO_HEIGHT * 2;
1348 y += TEXT_TO_INSET_OFFSET;
1352 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1354 if (the_locking_inset) {
1355 the_locking_inset->getCursorPos(bv, x, y);
1358 x = cursor_.x() - top_x;
1363 void InsetTabular::fitInsetCursor(BufferView * bv) const
1365 if (the_locking_inset) {
1366 int old_top_y = bv->text->top_y();
1367 the_locking_inset->fitInsetCursor(bv);
1368 if (old_top_y != bv->text->top_y())
1374 int const asc = font_metrics::maxAscent(font);
1375 int const desc = font_metrics::maxDescent(font);
1378 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1383 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1387 actcell = actrow = actcol = 0;
1388 int ly = tabular->GetDescentOfRow(actrow);
1390 // first search the right row
1391 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1392 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1393 tabular->GetAscentOfRow(actrow + 1) +
1394 tabular->GetAdditionalHeight(actrow + 1));
1396 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1398 actcell = tabular->GetCellNumber(actrow, actcol);
1400 // now search the right column
1401 int lx = tabular->GetWidthOfColumn(actcell) -
1402 tabular->GetAdditionalWidth(actcell);
1403 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1404 lx += tabular->GetWidthOfColumn(actcell + 1)
1405 + tabular->GetAdditionalWidth(actcell);
1407 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1412 int InsetTabular::getCellXPos(int cell) const
1416 for (; !tabular->IsFirstCellInRow(c); --c)
1418 int lx = tabular->GetWidthOfColumn(cell);
1419 for (; c < cell; ++c) {
1420 lx += tabular->GetWidthOfColumn(c);
1422 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1426 void InsetTabular::resetPos(BufferView * bv) const
1428 #ifdef WITH_WARNINGS
1429 #warning This should be fixed in the right manner (20011128 Jug)
1431 // fast hack to fix infinite repaintings!
1432 if (in_reset_pos > 0)
1436 actcol = tabular->column_of_cell(actcell);
1439 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1440 if (tabular->IsLastCellInRow(cell)) {
1441 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1442 tabular->GetAscentOfRow(actrow + 1) +
1443 tabular->GetAdditionalHeight(actrow + 1));
1447 if (!locked || nodraw()) {
1448 if (the_locking_inset)
1449 inset_y = cursor_.y();
1452 // we need this only from here on!!!
1454 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1455 int new_x = getCellXPos(actcell);
1456 int old_x = cursor_.x();
1459 // cursor.x(getCellXPos(actcell) + offset);
1460 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1461 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1464 updateLocal(bv, FULL);
1465 } else if (the_locking_inset &&
1466 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1468 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1469 if (xx > (bv->workWidth()-20)) {
1470 scroll(bv, -(xx - bv->workWidth() + 60));
1471 updateLocal(bv, FULL);
1472 } else if (xx < 20) {
1478 updateLocal(bv, FULL);
1480 } else if ((cursor_.x() - offset) > 20 &&
1481 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1482 > (bv->workWidth() - 20)) {
1483 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1484 updateLocal(bv, FULL);
1485 } else if ((cursor_.x() - offset) < 20) {
1486 scroll(bv, 20 - cursor_.x() + offset);
1487 updateLocal(bv, FULL);
1488 } else if (scroll() && top_x > 20 &&
1489 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1490 scroll(bv, old_x - cursor_.x());
1491 updateLocal(bv, FULL);
1493 if (the_locking_inset) {
1494 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1495 inset_y = cursor_.y();
1497 if ((!the_locking_inset ||
1498 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1499 actcell != oldcell) {
1500 InsetTabular * inset = const_cast<InsetTabular *>(this);
1501 InsetTabularMailer mailer(*inset);
1502 mailer.updateDialog(bv);
1509 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1511 if (lock && !old_locking_inset) {
1512 if (activateCellInset(bv))
1515 bool moved = isRightToLeft(bv)
1516 ? movePrevCell(bv) : moveNextCell(bv);
1518 return FINISHED_RIGHT;
1519 if (lock && activateCellInset(bv))
1523 return DISPATCHED_NOUPDATE;
1527 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1529 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1532 if (lock) { // behind the inset
1533 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1537 return DISPATCHED_NOUPDATE;
1541 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1543 int const ocell = actcell;
1544 actcell = tabular->GetCellAbove(actcell);
1545 if (actcell == ocell) // we moved out of the inset
1551 if (old_locking_inset) {
1552 old_locking_inset->getCursorPos(bv, x, y);
1553 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1555 if (activateCellInset(bv, x, 0))
1558 return DISPATCHED_NOUPDATE;
1562 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1564 int const ocell = actcell;
1565 actcell = tabular->GetCellBelow(actcell);
1566 if (actcell == ocell) // we moved out of the inset
1567 return FINISHED_DOWN;
1572 if (old_locking_inset) {
1573 old_locking_inset->getCursorPos(bv, x, y);
1574 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1576 if (activateCellInset(bv, x, 0))
1579 return DISPATCHED_NOUPDATE;
1583 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1585 if (isRightToLeft(bv)) {
1586 if (tabular->IsFirstCellInRow(actcell)) {
1587 int row = tabular->row_of_cell(actcell);
1588 if (row == tabular->rows() - 1)
1590 actcell = tabular->GetLastCellInRow(row);
1591 actcell = tabular->GetCellBelow(actcell);
1598 if (tabular->IsLastCell(actcell))
1603 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1604 isRightToLeftPar(bv->buffer()->params);
1605 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1612 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1614 if (isRightToLeft(bv)) {
1615 if (tabular->IsLastCellInRow(actcell)) {
1616 int row = tabular->row_of_cell(actcell);
1619 actcell = tabular->GetFirstCellInRow(row);
1620 actcell = tabular->GetCellAbove(actcell);
1622 if (tabular->IsLastCell(actcell))
1627 if (!actcell) // first cell
1632 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1633 isRightToLeftPar(bv->buffer()->params);
1634 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1641 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1645 setSelection(0, tabular->GetNumberOfCells() - 1);
1647 if (hasSelection()) {
1648 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1649 bool const frozen = undo_frozen;
1652 // apply the fontchange on the whole selection
1657 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1658 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1659 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1660 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1667 updateLocal(bv, INIT);
1669 if (the_locking_inset)
1670 the_locking_inset->setFont(bv, font, tall);
1674 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1676 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1679 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1680 string const tmp = tabularFeature[i].feature;
1682 if (tmp == what.substr(0, tmp.length())) {
1683 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1684 //tabularFeatures[i].feature.length())) {
1685 action = tabularFeature[i].action;
1689 if (action == LyXTabular::LAST_ACTION)
1693 ltrim(what.substr(tabularFeature[i].feature.length()));
1694 tabularFeatures(bv, action, val);
1700 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1701 string const & special, bool & flag)
1703 if (special == "dl_above") {
1706 } else if (special == "dl_below") {
1707 ltt.bottomDL = flag;
1709 } else if (special == "empty") {
1721 void InsetTabular::tabularFeatures(BufferView * bv,
1722 LyXTabular::Feature feature,
1723 string const & value)
1729 bool setLines = false;
1730 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1731 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1734 case LyXTabular::M_ALIGN_LEFT:
1735 case LyXTabular::ALIGN_LEFT:
1736 setAlign = LYX_ALIGN_LEFT;
1738 case LyXTabular::M_ALIGN_RIGHT:
1739 case LyXTabular::ALIGN_RIGHT:
1740 setAlign = LYX_ALIGN_RIGHT;
1742 case LyXTabular::M_ALIGN_CENTER:
1743 case LyXTabular::ALIGN_CENTER:
1744 setAlign = LYX_ALIGN_CENTER;
1746 case LyXTabular::ALIGN_BLOCK:
1747 setAlign = LYX_ALIGN_BLOCK;
1749 case LyXTabular::M_VALIGN_TOP:
1750 case LyXTabular::VALIGN_TOP:
1751 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1753 case LyXTabular::M_VALIGN_BOTTOM:
1754 case LyXTabular::VALIGN_BOTTOM:
1755 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1757 case LyXTabular::M_VALIGN_CENTER:
1758 case LyXTabular::VALIGN_CENTER:
1759 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1764 if (hasSelection()) {
1765 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1767 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1768 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1770 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1772 int row = tabular->row_of_cell(actcell);
1773 int column = tabular->column_of_cell(actcell);
1775 LyXTabular::ltType ltt;
1778 case LyXTabular::SET_PWIDTH:
1780 LyXLength const vallen(value);
1781 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1783 bool const update = (tmplen != vallen);
1784 tabular->SetColumnPWidth(actcell, vallen);
1787 for (int i = 0; i < tabular->rows(); ++i) {
1788 cell = tabular->GetCellNumber(i,column);
1789 tabular->GetCellInset(cell)->resizeLyXText(bv);
1791 updateLocal(bv, INIT);
1795 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1796 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1797 else if (!vallen.zero()
1798 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1799 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1802 case LyXTabular::SET_MPWIDTH:
1804 LyXLength const vallen(value);
1805 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1807 bool const update = (tmplen != vallen);
1808 tabular->SetMColumnPWidth(actcell, vallen);
1810 for (int i = 0; i < tabular->rows(); ++i) {
1811 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1814 updateLocal(bv, INIT);
1818 case LyXTabular::SET_SPECIAL_COLUMN:
1819 case LyXTabular::SET_SPECIAL_MULTI:
1820 tabular->SetAlignSpecial(actcell,value,feature);
1821 updateLocal(bv, FULL);
1823 case LyXTabular::APPEND_ROW:
1824 // append the row into the tabular
1825 unlockInsetInInset(bv, the_locking_inset);
1826 tabular->AppendRow(bv->buffer()->params, actcell);
1827 updateLocal(bv, INIT);
1829 case LyXTabular::APPEND_COLUMN:
1830 // append the column into the tabular
1831 unlockInsetInInset(bv, the_locking_inset);
1832 tabular->AppendColumn(bv->buffer()->params, actcell);
1833 actcell = tabular->GetCellNumber(row, column);
1834 updateLocal(bv, INIT);
1836 case LyXTabular::DELETE_ROW:
1837 unlockInsetInInset(bv, the_locking_inset);
1838 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1839 tabular->DeleteRow(sel_row_start);
1841 if (sel_row_start >= tabular->rows())
1843 actcell = tabular->GetCellNumber(sel_row_start, column);
1845 updateLocal(bv, INIT);
1847 case LyXTabular::DELETE_COLUMN:
1848 unlockInsetInInset(bv, the_locking_inset);
1849 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1850 tabular->DeleteColumn(sel_col_start);
1852 if (sel_col_start >= tabular->columns())
1854 actcell = tabular->GetCellNumber(row, sel_col_start);
1856 updateLocal(bv, INIT);
1858 case LyXTabular::M_TOGGLE_LINE_TOP:
1860 case LyXTabular::TOGGLE_LINE_TOP:
1862 bool lineSet = !tabular->TopLine(actcell, flag);
1863 for (int i = sel_row_start; i <= sel_row_end; ++i)
1864 for (int j = sel_col_start; j <= sel_col_end; ++j)
1865 tabular->SetTopLine(
1866 tabular->GetCellNumber(i, j),
1868 updateLocal(bv, INIT);
1872 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1874 case LyXTabular::TOGGLE_LINE_BOTTOM:
1876 bool lineSet = !tabular->BottomLine(actcell, flag);
1877 for (int i = sel_row_start; i <= sel_row_end; ++i)
1878 for (int j = sel_col_start; j <= sel_col_end; ++j)
1879 tabular->SetBottomLine(
1880 tabular->GetCellNumber(i, j),
1883 updateLocal(bv, INIT);
1887 case LyXTabular::M_TOGGLE_LINE_LEFT:
1889 case LyXTabular::TOGGLE_LINE_LEFT:
1891 bool lineSet = !tabular->LeftLine(actcell, flag);
1892 for (int i = sel_row_start; i <= sel_row_end; ++i)
1893 for (int j = sel_col_start; j <= sel_col_end; ++j)
1894 tabular->SetLeftLine(
1895 tabular->GetCellNumber(i,j),
1898 updateLocal(bv, INIT);
1902 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1904 case LyXTabular::TOGGLE_LINE_RIGHT:
1906 bool lineSet = !tabular->RightLine(actcell, flag);
1907 for (int i = sel_row_start; i <= sel_row_end; ++i)
1908 for (int j = sel_col_start; j <= sel_col_end; ++j)
1909 tabular->SetRightLine(
1910 tabular->GetCellNumber(i,j),
1913 updateLocal(bv, INIT);
1917 case LyXTabular::M_ALIGN_LEFT:
1918 case LyXTabular::M_ALIGN_RIGHT:
1919 case LyXTabular::M_ALIGN_CENTER:
1921 case LyXTabular::ALIGN_LEFT:
1922 case LyXTabular::ALIGN_RIGHT:
1923 case LyXTabular::ALIGN_CENTER:
1924 case LyXTabular::ALIGN_BLOCK:
1925 for (int i = sel_row_start; i <= sel_row_end; ++i)
1926 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular->SetAlignment(
1928 tabular->GetCellNumber(i, j),
1931 updateLocal(bv, INIT);
1933 case LyXTabular::M_VALIGN_TOP:
1934 case LyXTabular::M_VALIGN_BOTTOM:
1935 case LyXTabular::M_VALIGN_CENTER:
1937 case LyXTabular::VALIGN_TOP:
1938 case LyXTabular::VALIGN_BOTTOM:
1939 case LyXTabular::VALIGN_CENTER:
1940 for (int i = sel_row_start; i <= sel_row_end; ++i)
1941 for (int j = sel_col_start; j <= sel_col_end; ++j)
1942 tabular->SetVAlignment(
1943 tabular->GetCellNumber(i, j),
1945 updateLocal(bv, INIT);
1947 case LyXTabular::MULTICOLUMN:
1949 if (sel_row_start != sel_row_end) {
1950 #ifdef WITH_WARNINGS
1951 #warning Need I say it ? This is horrible.
1953 Alert::error(_("Error setting multicolumn"),
1954 _("You cannot set multicolumn vertically."));
1957 // just multicol for one Single Cell
1958 if (!hasSelection()) {
1959 // check wether we are completly in a multicol
1960 if (tabular->IsMultiColumn(actcell)) {
1961 tabular->UnsetMultiColumn(actcell);
1962 updateLocal(bv, INIT);
1964 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1965 updateLocal(bv, CELL);
1969 // we have a selection so this means we just add all this
1970 // cells to form a multicolumn cell
1974 if (sel_cell_start > sel_cell_end) {
1975 s_start = sel_cell_end;
1976 s_end = sel_cell_start;
1978 s_start = sel_cell_start;
1979 s_end = sel_cell_end;
1981 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1984 updateLocal(bv, INIT);
1987 case LyXTabular::SET_ALL_LINES:
1989 case LyXTabular::UNSET_ALL_LINES:
1990 for (int i = sel_row_start; i <= sel_row_end; ++i)
1991 for (int j = sel_col_start; j <= sel_col_end; ++j)
1992 tabular->SetAllLines(
1993 tabular->GetCellNumber(i,j), setLines);
1994 updateLocal(bv, INIT);
1996 case LyXTabular::SET_LONGTABULAR:
1997 tabular->SetLongTabular(true);
1998 updateLocal(bv, INIT); // because this toggles displayed
2000 case LyXTabular::UNSET_LONGTABULAR:
2001 tabular->SetLongTabular(false);
2002 updateLocal(bv, INIT); // because this toggles displayed
2004 case LyXTabular::SET_ROTATE_TABULAR:
2005 tabular->SetRotateTabular(true);
2007 case LyXTabular::UNSET_ROTATE_TABULAR:
2008 tabular->SetRotateTabular(false);
2010 case LyXTabular::SET_ROTATE_CELL:
2011 for (int i = sel_row_start; i <= sel_row_end; ++i)
2012 for (int j = sel_col_start; j<=sel_col_end; ++j)
2013 tabular->SetRotateCell(
2014 tabular->GetCellNumber(i, j),
2017 case LyXTabular::UNSET_ROTATE_CELL:
2018 for (int i = sel_row_start; i <= sel_row_end; ++i)
2019 for (int j = sel_col_start; j <= sel_col_end; ++j)
2020 tabular->SetRotateCell(
2021 tabular->GetCellNumber(i, j), false);
2023 case LyXTabular::SET_USEBOX:
2025 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2026 if (val == tabular->GetUsebox(actcell))
2027 val = LyXTabular::BOX_NONE;
2028 for (int i = sel_row_start; i <= sel_row_end; ++i)
2029 for (int j = sel_col_start; j <= sel_col_end; ++j)
2031 tabular->GetCellNumber(i, j), val);
2034 case LyXTabular::UNSET_LTFIRSTHEAD:
2036 case LyXTabular::SET_LTFIRSTHEAD:
2037 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2038 checkLongtableSpecial(ltt, value, flag);
2039 tabular->SetLTHead(row, flag, ltt, true);
2041 case LyXTabular::UNSET_LTHEAD:
2043 case LyXTabular::SET_LTHEAD:
2044 (void)tabular->GetRowOfLTHead(row, ltt);
2045 checkLongtableSpecial(ltt, value, flag);
2046 tabular->SetLTHead(row, flag, ltt, false);
2048 case LyXTabular::UNSET_LTFOOT:
2050 case LyXTabular::SET_LTFOOT:
2051 (void)tabular->GetRowOfLTFoot(row, ltt);
2052 checkLongtableSpecial(ltt, value, flag);
2053 tabular->SetLTFoot(row, flag, ltt, false);
2055 case LyXTabular::UNSET_LTLASTFOOT:
2057 case LyXTabular::SET_LTLASTFOOT:
2058 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2059 checkLongtableSpecial(ltt, value, flag);
2060 tabular->SetLTFoot(row, flag, ltt, true);
2062 case LyXTabular::SET_LTNEWPAGE:
2064 bool what = !tabular->GetLTNewPage(row);
2065 tabular->SetLTNewPage(row, what);
2068 // dummy stuff just to avoid warnings
2069 case LyXTabular::LAST_ACTION:
2073 InsetTabularMailer mailer(*this);
2074 mailer.updateDialog(bv);
2078 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2081 UpdatableInset * inset =
2082 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2083 LyXFont font(LyXFont::ALL_SANE);
2085 x = inset->x() + inset->width(bv, font);
2086 y = inset->descent(bv, font);
2088 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2089 //inset_y = cursor.y();
2090 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2091 if (!the_locking_inset)
2093 updateLocal(bv, CELL);
2094 return (the_locking_inset != 0);
2098 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2099 mouse_button::state button)
2101 inset_x = cursor_.x()
2102 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2103 inset_y = cursor_.y();
2104 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2108 bool InsetTabular::insetHit(BufferView *, int x, int) const
2111 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2115 // This returns paperWidth() if the cell-width is unlimited or the width
2116 // in pixels if we have a pwidth for this cell.
2117 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2119 LyXLength const len = tabular->GetPWidth(cell);
2123 return len.inPixels(latexTextWidth(bv));
2127 int InsetTabular::getMaxWidth(BufferView * bv,
2128 UpdatableInset const * inset) const
2130 int cell = tabular->GetCellFromInset(inset, actcell);
2133 lyxerr << "Own inset not found, shouldn't really happen!"
2138 int w = getMaxWidthOfCell(bv, cell);
2140 // because the inset then subtracts it's top_x and owner->x()
2141 w += (inset->x() - top_x);
2148 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2150 resizeLyXText(bv, recursive);
2154 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2157 for(int i = 0; i < tabular->rows(); ++i) {
2158 for(int j = 0; j < tabular->columns(); ++j) {
2159 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2167 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2168 bool const recursive) const
2170 if (the_locking_inset)
2171 return the_locking_inset->getLyXText(bv, recursive);
2173 // if we're locked lock the actual insettext and return it's LyXText!!!
2175 UpdatableInset * inset =
2176 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2177 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2178 return the_locking_inset->getLyXText(bv, recursive);
2181 return Inset::getLyXText(bv, recursive);
2185 bool InsetTabular::showInsetDialog(BufferView * bv) const
2187 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2188 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2189 InsetTabularMailer mailer(*tmp);
2190 mailer.showDialog(bv);
2196 void InsetTabular::openLayoutDialog(BufferView * bv) const
2198 if (the_locking_inset) {
2199 InsetTabular * i = static_cast<InsetTabular *>
2200 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2202 i->openLayoutDialog(bv);
2206 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2207 InsetTabularMailer mailer(*tmp);
2208 mailer.showDialog(bv);
2213 // function returns an object as defined in func_status.h:
2214 // states OK, Unknown, Disabled, On, Off.
2216 FuncStatus InsetTabular::getStatus(string const & what) const
2218 int action = LyXTabular::LAST_ACTION;
2222 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2223 string const tmp = tabularFeature[i].feature;
2224 if (tmp == what.substr(0, tmp.length())) {
2225 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2226 // tabularFeatures[i].feature.length())) {
2227 action = tabularFeature[i].action;
2231 if (action == LyXTabular::LAST_ACTION) {
2233 return status.unknown(true);
2236 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2241 LyXTabular::ltType dummyltt;
2244 if (hasSelection()) {
2245 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2247 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2251 case LyXTabular::SET_PWIDTH:
2252 case LyXTabular::SET_MPWIDTH:
2253 case LyXTabular::SET_SPECIAL_COLUMN:
2254 case LyXTabular::SET_SPECIAL_MULTI:
2255 case LyXTabular::APPEND_ROW:
2256 case LyXTabular::APPEND_COLUMN:
2257 case LyXTabular::DELETE_ROW:
2258 case LyXTabular::DELETE_COLUMN:
2259 case LyXTabular::SET_ALL_LINES:
2260 case LyXTabular::UNSET_ALL_LINES:
2261 return status.clear();
2263 case LyXTabular::MULTICOLUMN:
2264 status.setOnOff(tabular->IsMultiColumn(actcell));
2266 case LyXTabular::M_TOGGLE_LINE_TOP:
2268 case LyXTabular::TOGGLE_LINE_TOP:
2269 status.setOnOff(tabular->TopLine(actcell, flag));
2271 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2273 case LyXTabular::TOGGLE_LINE_BOTTOM:
2274 status.setOnOff(tabular->BottomLine(actcell, flag));
2276 case LyXTabular::M_TOGGLE_LINE_LEFT:
2278 case LyXTabular::TOGGLE_LINE_LEFT:
2279 status.setOnOff(tabular->LeftLine(actcell, flag));
2281 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2283 case LyXTabular::TOGGLE_LINE_RIGHT:
2284 status.setOnOff(tabular->RightLine(actcell, flag));
2286 case LyXTabular::M_ALIGN_LEFT:
2288 case LyXTabular::ALIGN_LEFT:
2289 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2291 case LyXTabular::M_ALIGN_RIGHT:
2293 case LyXTabular::ALIGN_RIGHT:
2294 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2296 case LyXTabular::M_ALIGN_CENTER:
2298 case LyXTabular::ALIGN_CENTER:
2299 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2301 case LyXTabular::ALIGN_BLOCK:
2302 status.disabled(tabular->GetPWidth(actcell).zero());
2303 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2305 case LyXTabular::M_VALIGN_TOP:
2307 case LyXTabular::VALIGN_TOP:
2308 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2310 case LyXTabular::M_VALIGN_BOTTOM:
2312 case LyXTabular::VALIGN_BOTTOM:
2313 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2315 case LyXTabular::M_VALIGN_CENTER:
2317 case LyXTabular::VALIGN_CENTER:
2318 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2320 case LyXTabular::SET_LONGTABULAR:
2321 status.setOnOff(tabular->IsLongTabular());
2323 case LyXTabular::UNSET_LONGTABULAR:
2324 status.setOnOff(!tabular->IsLongTabular());
2326 case LyXTabular::SET_ROTATE_TABULAR:
2327 status.setOnOff(tabular->GetRotateTabular());
2329 case LyXTabular::UNSET_ROTATE_TABULAR:
2330 status.setOnOff(!tabular->GetRotateTabular());
2332 case LyXTabular::SET_ROTATE_CELL:
2333 status.setOnOff(tabular->GetRotateCell(actcell));
2335 case LyXTabular::UNSET_ROTATE_CELL:
2336 status.setOnOff(!tabular->GetRotateCell(actcell));
2338 case LyXTabular::SET_USEBOX:
2339 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2341 case LyXTabular::SET_LTFIRSTHEAD:
2342 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2344 case LyXTabular::SET_LTHEAD:
2345 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2347 case LyXTabular::SET_LTFOOT:
2348 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2350 case LyXTabular::SET_LTLASTFOOT:
2351 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2353 case LyXTabular::SET_LTNEWPAGE:
2354 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2358 status.disabled(true);
2365 vector<string> const InsetTabular::getLabelList() const
2367 return tabular->getLabelList();
2371 bool InsetTabular::copySelection(BufferView * bv)
2373 if (!hasSelection())
2376 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2377 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2378 if (sel_col_start > sel_col_end) {
2379 sel_col_start = sel_col_end;
2380 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2382 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2384 int const columns = sel_col_end - sel_col_start + 1;
2386 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2387 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2388 if (sel_row_start > sel_row_end) {
2389 swap(sel_row_start, sel_row_end);
2391 int const rows = sel_row_end - sel_row_start + 1;
2393 delete paste_tabular;
2394 paste_tabular = new LyXTabular(bv->buffer()->params,
2395 this, *tabular); // rows, columns);
2396 for (int i = 0; i < sel_row_start; ++i)
2397 paste_tabular->DeleteRow(0);
2398 while (paste_tabular->rows() > rows)
2399 paste_tabular->DeleteRow(rows);
2400 paste_tabular->SetTopLine(0, true, true);
2401 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2403 for (int i = 0; i < sel_col_start; ++i)
2404 paste_tabular->DeleteColumn(0);
2405 while (paste_tabular->columns() > columns)
2406 paste_tabular->DeleteColumn(columns);
2407 paste_tabular->SetLeftLine(0, true, true);
2408 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2412 paste_tabular->ascii(bv->buffer(), sstr,
2413 (int)parOwner()->params().depth(), true, '\t');
2414 bv->stuffClipboard(STRCONV(sstr.str()));
2419 bool InsetTabular::pasteSelection(BufferView * bv)
2424 for (int r1 = 0, r2 = actrow;
2425 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2427 for(int c1 = 0, c2 = actcol;
2428 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2430 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2431 tabular->IsPartOfMultiColumn(r2,c2))
2433 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2437 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2441 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2442 int const n2 = tabular->GetCellNumber(r2, c2);
2443 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2444 tabular->GetCellInset(n2)->setOwner(this);
2445 tabular->GetCellInset(n2)->deleteLyXText(bv);
2446 tabular->GetCellInset(n2)->markNew();
2453 bool InsetTabular::cutSelection(BufferParams const & bp)
2455 if (!hasSelection())
2458 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2459 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2460 if (sel_col_start > sel_col_end) {
2461 sel_col_start = sel_col_end;
2462 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2464 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2466 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2467 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2468 if (sel_row_start > sel_row_end) {
2469 swap(sel_row_start, sel_row_end);
2471 if (sel_cell_start > sel_cell_end) {
2472 swap(sel_cell_start, sel_cell_end);
2474 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2475 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2476 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2483 bool InsetTabular::isRightToLeft(BufferView * bv)
2485 return bv->getParentLanguage(this)->RightToLeft();
2489 bool InsetTabular::nodraw() const
2491 if (!UpdatableInset::nodraw() && the_locking_inset)
2492 return the_locking_inset->nodraw();
2493 return UpdatableInset::nodraw();
2497 int InsetTabular::scroll(bool recursive) const
2499 int sx = UpdatableInset::scroll(false);
2501 if (recursive && the_locking_inset)
2502 sx += the_locking_inset->scroll(recursive);
2508 void InsetTabular::getSelection(int & srow, int & erow,
2509 int & scol, int & ecol) const
2511 int const start = hasSelection() ? sel_cell_start : actcell;
2512 int const end = hasSelection() ? sel_cell_end : actcell;
2514 srow = tabular->row_of_cell(start);
2515 erow = tabular->row_of_cell(end);
2520 scol = tabular->column_of_cell(start);
2521 ecol = tabular->column_of_cell(end);
2525 ecol = tabular->right_column_of_cell(end);
2530 ParagraphList * InsetTabular::getParagraphs(int i) const
2532 return (i < tabular->GetNumberOfCells())
2533 ? tabular->GetCellInset(i)->getParagraphs(0)
2538 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2540 if (the_locking_inset)
2541 return the_locking_inset->cursor(bv);
2542 return Inset::cursor(bv);
2546 Inset * InsetTabular::getInsetFromID(int id_arg) const
2549 return const_cast<InsetTabular *>(this);
2552 for(int i = 0; i < tabular->rows(); ++i) {
2553 for(int j = 0; j < tabular->columns(); ++j) {
2554 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2563 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2566 if (the_locking_inset) {
2567 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2568 if (!word.word().empty()) {
2572 if (tabular->IsLastCell(actcell)) {
2573 bv->unlockInset(const_cast<InsetTabular *>(this));
2575 return WordLangTuple();
2579 // otherwise we have to lock the next inset and ask for it's selecttion
2580 UpdatableInset * inset =
2581 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2582 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2583 WordLangTuple word(selectNextWordInt(bv, value));
2585 if (!word.word().empty())
2591 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2593 // when entering this function the inset should be ALWAYS locked!
2594 lyx::Assert(the_locking_inset);
2596 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2597 if (!word.word().empty())
2600 if (tabular->IsLastCell(actcell)) {
2601 bv->unlockInset(const_cast<InsetTabular *>(this));
2602 return WordLangTuple();
2605 // otherwise we have to lock the next inset and ask for it's selecttion
2606 UpdatableInset * inset =
2607 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2608 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2609 return selectNextWordInt(bv, value);
2613 void InsetTabular::selectSelectedWord(BufferView * bv)
2615 if (the_locking_inset) {
2616 the_locking_inset->selectSelectedWord(bv);
2623 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2625 if (the_locking_inset) {
2626 the_locking_inset->toggleSelection(bv, kill_selection);
2631 void InsetTabular::markErased()
2635 while (!tabular->IsLastCell(cell)) {
2637 InsetText * inset = tabular->GetCellInset(cell);
2638 inset->markErased();
2643 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2645 if (the_locking_inset) {
2646 if (the_locking_inset->nextChange(bv, length)) {
2647 updateLocal(bv, CELL);
2650 if (tabular->IsLastCell(actcell))
2654 InsetText * inset = tabular->GetCellInset(actcell);
2655 if (inset->nextChange(bv, length)) {
2656 updateLocal(bv, FULL);
2659 while (!tabular->IsLastCell(actcell)) {
2661 inset = tabular->GetCellInset(actcell);
2662 if (inset->nextChange(bv, length)) {
2663 updateLocal(bv, FULL);
2671 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2675 if (the_locking_inset) {
2676 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2677 updateLocal(bv, CELL);
2680 if (tabular->IsLastCell(actcell))
2684 InsetText * inset = tabular->GetCellInset(cell);
2685 if (inset->searchForward(bv, str, cs, mw)) {
2686 updateLocal(bv, FULL);
2689 while (!tabular->IsLastCell(cell)) {
2691 inset = tabular->GetCellInset(cell);
2692 if (inset->searchForward(bv, str, cs, mw)) {
2693 updateLocal(bv, FULL);
2701 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2704 int cell = tabular->GetNumberOfCells();
2705 if (the_locking_inset) {
2706 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2707 updateLocal(bv, CELL);
2715 InsetText * inset = tabular->GetCellInset(cell);
2716 if (inset->searchBackward(bv, str, cs, mw)) {
2717 updateLocal(bv, CELL);
2725 bool InsetTabular::insetAllowed(Inset::Code code) const
2727 if (the_locking_inset)
2728 return the_locking_inset->insetAllowed(code);
2729 // we return true here because if the inset is not locked someone
2730 // wants to insert something in one of our insettexts and we generally
2736 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2738 const int cell = tabular->GetCellFromInset(in, actcell);
2741 return tabular->GetPWidth(cell).zero();
2743 // well we didn't obviously find it so maybe our owner knows more
2745 return owner()->forceDefaultParagraphs(in);
2746 // if we're here there is really something strange going on!!!
2750 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2753 if (buf.length() <= 0)
2759 string::size_type len = buf.length();
2760 string::size_type p = 0;
2763 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2772 maxCols = max(cols, maxCols);
2778 maxCols = max(cols, maxCols);
2779 LyXTabular * loctab;
2784 delete paste_tabular;
2785 paste_tabular = new LyXTabular(bv->buffer()->params,
2786 this, rows, maxCols);
2787 loctab = paste_tabular;
2790 loctab = tabular.get();
2796 string::size_type op = 0;
2797 int cells = loctab->GetNumberOfCells();
2800 rows = loctab->rows();
2801 int const columns = loctab->columns();
2803 while ((cell < cells) && (p < len) && (row < rows) &&
2804 (p = buf.find_first_of("\t\n", p)) != string::npos)
2810 // we can only set this if we are not too far right
2811 if (cols < columns) {
2812 InsetText * ti = loctab->GetCellInset(cell);
2813 LyXFont const font = ti->getLyXText(bv)->
2814 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2815 ti->setText(buf.substr(op, p - op), font);
2821 // we can only set this if we are not too far right
2822 if (cols < columns) {
2823 InsetText * ti = loctab->GetCellInset(cell);
2824 LyXFont const font = ti->getLyXText(bv)->
2825 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2826 ti->setText(buf.substr(op, p - op), font);
2831 cell = loctab->GetCellNumber(row, cols);
2837 // check for the last cell if there is no trailing '\n'
2838 if ((cell < cells) && (op < len)) {
2839 InsetText * ti = loctab->GetCellInset(cell);
2840 LyXFont const font = ti->getLyXText(bv)->
2841 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2842 ti->setText(buf.substr(op, len - op), font);
2849 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2851 int const rows = tabular->rows();
2852 int const columns = tabular->columns();
2853 for (int i = 0; i < rows; ++i) {
2854 for (int j = 0; j < columns; ++j) {
2855 tabular->GetCellInset(i,j)->addPreview(loader);
2861 string const InsetTabularMailer:: name_("tabular");
2863 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2868 string const InsetTabularMailer::inset2string() const
2870 return params2string(inset_);
2874 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2876 istringstream data(STRCONV(in));
2878 lex.setStream(data);
2880 #warning CHECK verify that this is a sane value to return.
2886 string const token = lex.getString();
2894 string const token = lex.getString();
2895 if (token != "\\active_cell")
2898 cell = lex.getInteger();
2901 // This is part of the inset proper that is usually swallowed
2902 // by Buffer::readInset
2905 string const token = lex.getString();
2906 if (token != "Tabular")
2913 BufferView * const bv = inset.view();
2914 Buffer const * const buffer = bv ? bv->buffer() : 0;
2916 inset.read(buffer, lex);
2918 // We can't set the active cell, but we can tell the frontend
2924 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2926 BufferView * const bv = inset.view();
2927 Buffer const * const buffer = bv ? bv->buffer() : 0;
2932 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2933 inset.write(buffer, data);
2934 data << "\\end_inset\n";
2935 return STRCONV(data.str());