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()
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::dimension(BufferView *, LyXFont const &,
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(BufferView * bv, LyXFont const & font, int baseline,
263 Painter & pain = bv->painter();
269 UpdatableInset::draw(bv, font, baseline, x);
272 x += static_cast<float>(scroll());
276 top_baseline = baseline;
277 x += ADD_TO_TABULAR_WIDTH;
281 first_visible_cell = -1;
282 for (i = 0; i < tabular->rows(); ++i) {
284 cell = tabular->GetCellNumber(i, 0);
285 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
286 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
288 baseline += tabular->GetDescentOfRow(i) +
289 tabular->GetAscentOfRow(i + 1) +
290 tabular->GetAdditionalHeight(i + 1);
293 for (j = 0; j < tabular->columns(); ++j) {
294 if (nx > bv->workWidth())
296 if (tabular->IsPartOfMultiColumn(i, j))
298 cx = nx + tabular->GetBeginningOfTextInCell(cell);
299 if (first_visible_cell < 0)
300 first_visible_cell = cell;
301 if (hasSelection()) {
302 drawCellSelection(pain, nx, baseline, i, j, cell);
305 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
306 drawCellLines(pain, nx, baseline, i, cell);
307 nx += tabular->GetWidthOfColumn(cell);
311 // avoiding drawing the rest of a long table is
312 // a pretty big speedup
313 if (baseline > bv->workHeight())
316 baseline += tabular->GetDescentOfRow(i) +
317 tabular->GetAscentOfRow(i + 1) +
318 tabular->GetAdditionalHeight(i + 1);
321 x -= ADD_TO_TABULAR_WIDTH;
322 x += width(bv, font);
327 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
328 int row, int cell) const
330 int x2 = x + tabular->GetWidthOfColumn(cell);
333 if (!tabular->topAlreadyDrawn(cell)) {
334 on_off = !tabular->TopLine(cell);
335 pain.line(x, baseline - tabular->GetAscentOfRow(row),
336 x2, baseline - tabular->GetAscentOfRow(row),
337 on_off ? LColor::tabularonoffline : LColor::tabularline,
338 on_off ? Painter::line_onoffdash : Painter::line_solid);
340 on_off = !tabular->BottomLine(cell);
341 pain.line(x, baseline + tabular->GetDescentOfRow(row),
342 x2, baseline + tabular->GetDescentOfRow(row),
343 on_off ? LColor::tabularonoffline : LColor::tabularline,
344 on_off ? Painter::line_onoffdash : Painter::line_solid);
345 if (!tabular->leftAlreadyDrawn(cell)) {
346 on_off = !tabular->LeftLine(cell);
347 pain.line(x, baseline - tabular->GetAscentOfRow(row),
348 x, baseline + tabular->GetDescentOfRow(row),
349 on_off ? LColor::tabularonoffline : LColor::tabularline,
350 on_off ? Painter::line_onoffdash : Painter::line_solid);
352 on_off = !tabular->RightLine(cell);
353 pain.line(x2 - tabular->GetAdditionalWidth(cell),
354 baseline - tabular->GetAscentOfRow(row),
355 x2 - tabular->GetAdditionalWidth(cell),
356 baseline + tabular->GetDescentOfRow(row),
357 on_off ? LColor::tabularonoffline : LColor::tabularline,
358 on_off ? Painter::line_onoffdash : Painter::line_solid);
362 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
363 int row, int column, int cell) const
365 lyx::Assert(hasSelection());
366 int cs = tabular->column_of_cell(sel_cell_start);
367 int ce = tabular->column_of_cell(sel_cell_end);
370 cs = tabular->column_of_cell(sel_cell_end);
372 ce = tabular->right_column_of_cell(sel_cell_end);
375 int rs = tabular->row_of_cell(sel_cell_start);
376 int re = tabular->row_of_cell(sel_cell_end);
380 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
381 int w = tabular->GetWidthOfColumn(cell);
382 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
383 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
384 w, h, LColor::selection);
389 void InsetTabular::update(BufferView * bv, bool reinit)
395 owner()->update(bv, true);
402 if (calculate_dimensions_of_cells(bv, true))
405 owner()->update(bv, true);
409 if (the_locking_inset)
410 the_locking_inset->update(bv, reinit);
411 if (need_update < FULL &&
412 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
417 switch (need_update) {
421 if (calculate_dimensions_of_cells(bv, false)) {
436 string const InsetTabular::editMessage() const
438 return _("Opened table");
442 void InsetTabular::insetUnlock(BufferView * bv)
444 if (the_locking_inset) {
445 the_locking_inset->insetUnlock(bv);
446 updateLocal(bv, CELL);
447 the_locking_inset = 0;
452 if (scroll(false) || hasSelection()) {
457 updateLocal(bv, FULL);
462 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
465 calculate_dimensions_of_cells(bv, true);
467 if (!locked && what == CELL)
469 if (need_update < what) // only set this if it has greater update
472 if (need_update != NONE) {
473 bv->updateInset(const_cast<InsetTabular *>(this));
480 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
482 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
487 if (inset == tabular->GetCellInset(actcell)) {
488 lyxerr[Debug::INSETTEXT] << "OK" << endl;
489 the_locking_inset = tabular->GetCellInset(actcell);
492 } else if (!the_locking_inset) {
493 int const n = tabular->GetNumberOfCells();
494 int const id = inset->id();
495 for (int i = 0; i < n; ++i) {
496 InsetText * in = tabular->GetCellInset(i);
499 the_locking_inset = in;
504 if (in->getInsetFromID(id)) {
506 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
507 return the_locking_inset->lockInsetInInset(bv, inset);
510 } else if (the_locking_inset && (the_locking_inset == inset)) {
511 lyxerr[Debug::INSETTEXT] << "OK" << endl;
513 } else if (the_locking_inset) {
514 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
515 return the_locking_inset->lockInsetInInset(bv, inset);
517 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
522 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
525 if (!the_locking_inset)
527 if (the_locking_inset == inset) {
528 the_locking_inset->insetUnlock(bv);
530 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
536 updateLocal(bv, CELL);
537 // this has to be here otherwise we don't redraw the cell!
538 the_locking_inset = 0;
541 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
542 if (inset->lyxCode() == TABULAR_CODE &&
543 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
544 InsetTabularMailer mailer(*this);
545 mailer.updateDialog(bv);
554 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
556 Inset * tl_inset = inset;
557 // look if this inset is really inside myself!
558 while(tl_inset->owner() && tl_inset->owner() != this)
559 tl_inset = tl_inset->owner();
560 // if we enter here it's not ower inset
561 if (!tl_inset->owner())
563 // we only have to do this if this is a subinset of our cells
564 if (tl_inset != inset) {
565 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
568 updateLocal(bv, CELL);
573 int InsetTabular::insetInInsetY() const
575 if (!the_locking_inset)
577 return inset_y + the_locking_inset->insetInInsetY();
581 UpdatableInset * InsetTabular::getLockingInset() const
583 return the_locking_inset ? the_locking_inset->getLockingInset() :
584 const_cast<InsetTabular *>(this);
588 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
592 if (the_locking_inset)
593 return the_locking_inset->getFirstLockingInsetOfType(c);
598 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
600 if (the_locking_inset)
601 return the_locking_inset->insertInset(bv, inset);
606 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
608 if (hasSelection() && cmd.button() == mouse_button::button3)
611 if (hasSelection()) {
613 updateLocal(cmd.view(), SELECTION);
616 int const ocell = actcell;
617 int const orow = actrow;
618 BufferView * bv = cmd.view();
622 the_locking_inset = 0;
626 setPos(bv, cmd.x, cmd.y);
628 updateLocal(bv, NONE);
631 if (cmd.button() == mouse_button::button3) {
632 if ((ocell != actcell) && the_locking_inset) {
633 the_locking_inset->insetUnlock(bv);
634 updateLocal(bv, CELL);
635 the_locking_inset = 0;
641 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
643 if ((ocell == actcell) && the_locking_inset && inset_hit) {
645 FuncRequest cmd1 = cmd;
648 the_locking_inset->localDispatch(cmd1);
652 if (the_locking_inset) {
653 the_locking_inset->insetUnlock(bv);
654 updateLocal(bv, CELL);
655 the_locking_inset = 0;
658 if (cmd.button() == mouse_button::button2) {
659 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
663 if (inset_hit && bv->theLockingInset()) {
664 if (!bv->lockInset(static_cast<UpdatableInset*>
665 (tabular->GetCellInset(actcell))))
667 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
670 FuncRequest cmd1 = cmd;
673 the_locking_inset->localDispatch(cmd1);
679 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
682 if (the_locking_inset) {
683 FuncRequest cmd1 = cmd;
686 ret = the_locking_inset->localDispatch(cmd1);
688 if (cmd.button() == mouse_button::button3 && !ret) {
689 InsetTabularMailer(*this).showDialog(cmd.view());
696 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
698 if (the_locking_inset) {
699 FuncRequest cmd1 = cmd;
702 the_locking_inset->localDispatch(cmd1);
706 BufferView * bv = cmd.view();
707 int const old_cell = actcell;
709 setPos(bv, cmd.x, cmd.y);
710 if (!hasSelection()) {
711 setSelection(actcell, actcell);
712 updateLocal(bv, SELECTION);
713 } else if (old_cell != actcell) {
714 setSelection(sel_cell_start, actcell);
715 updateLocal(bv, SELECTION);
720 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
722 // We need to save the value of the_locking_inset as the call to
723 // the_locking_inset->localDispatch might unlock it.
724 old_locking_inset = the_locking_inset;
725 RESULT result = UpdatableInset::localDispatch(cmd);
726 BufferView * bv = cmd.view();
728 if (cmd.action == LFUN_INSET_EDIT) {
730 if (!bv->lockInset(this)) {
731 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
737 the_locking_inset = 0;
741 if (cmd.argument.size()) {
742 if (cmd.argument == "left") {
743 if (isRightToLeft(bv))
744 actcell = tabular->GetLastCellInRow(0);
748 if (isRightToLeft(bv))
749 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
751 actcell = tabular->GetNumberOfCells() - 1;
759 setPos(bv, cmd.x, cmd.y);
762 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
763 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
769 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
774 if (cmd.action < 0 && cmd.argument.empty())
777 bool hs = hasSelection();
780 // this one have priority over the locked InsetText, if we're not already
781 // inside another tabular then that one get's priority!
782 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
783 switch (cmd.action) {
784 case LFUN_MOUSE_PRESS:
788 case LFUN_MOUSE_MOTION:
789 lfunMouseMotion(cmd);
792 case LFUN_MOUSE_RELEASE:
793 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
795 case LFUN_CELL_BACKWARD:
796 case LFUN_CELL_FORWARD:
797 unlockInsetInInset(bv, the_locking_inset);
798 if (cmd.action == LFUN_CELL_FORWARD)
799 moveNextCell(bv, old_locking_inset != 0);
801 movePrevCell(bv, old_locking_inset != 0);
804 updateLocal(bv, SELECTION);
805 if (!the_locking_inset) {
806 return DISPATCHED_NOUPDATE;
809 // this to avoid compiler warnings.
815 kb_action action = cmd.action;
816 string arg = cmd.argument;
817 if (the_locking_inset) {
818 result = the_locking_inset->localDispatch(cmd);
819 if (result == DISPATCHED_NOUPDATE) {
822 if (sc != scroll()) { // inset has been scrolled
823 updateLocal(bv, FULL);
826 } else if (result == DISPATCHED) {
827 updateLocal(bv, CELL);
829 } else if (result == FINISHED_UP) {
831 // Make sure to reset status message after
832 // exiting, e.g. math inset
833 bv->owner()->clearMessage();
834 } else if (result == FINISHED_DOWN) {
836 bv->owner()->clearMessage();
837 } else if (result == FINISHED_RIGHT) {
839 bv->owner()->clearMessage();
840 } else if (result == FINISHED) {
841 bv->owner()->clearMessage();
847 // --- Cursor Movements ----------------------------------
848 case LFUN_RIGHTSEL: {
849 int const start = hasSelection() ? sel_cell_start : actcell;
850 if (tabular->IsLastCellInRow(actcell)) {
851 setSelection(start, actcell);
856 // if we are starting a selection, only select
857 // the current cell at the beginning
858 if (hasSelection()) {
859 moveRight(bv, false);
862 setSelection(start, end);
863 updateLocal(bv, SELECTION);
867 result = moveRight(bv);
870 updateLocal(bv, SELECTION);
873 int const start = hasSelection() ? sel_cell_start : actcell;
874 if (tabular->IsFirstCellInRow(actcell)) {
875 setSelection(start, actcell);
880 // if we are starting a selection, only select
881 // the current cell at the beginning
882 if (hasSelection()) {
886 setSelection(start, end);
887 updateLocal(bv, SELECTION);
891 result = moveLeft(bv);
894 updateLocal(bv, SELECTION);
897 int const start = hasSelection() ? sel_cell_start : actcell;
898 int const ocell = actcell;
899 // if we are starting a selection, only select
900 // the current cell at the beginning
901 if (hasSelection()) {
903 if ((ocell == sel_cell_end) ||
904 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
905 setSelection(start, tabular->GetCellBelow(sel_cell_end));
907 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
909 setSelection(start, start);
911 updateLocal(bv, SELECTION);
915 result = moveDown(bv, old_locking_inset != 0);
918 updateLocal(bv, SELECTION);
922 int const start = hasSelection() ? sel_cell_start : actcell;
923 int const ocell = actcell;
924 // if we are starting a selection, only select
925 // the current cell at the beginning
926 if (hasSelection()) {
928 if ((ocell == sel_cell_end) ||
929 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
930 setSelection(start, tabular->GetCellAbove(sel_cell_end));
932 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
934 setSelection(start, start);
936 updateLocal(bv, SELECTION);
940 result = moveUp(bv, old_locking_inset != 0);
943 updateLocal(bv, SELECTION);
946 UpdateCodes code = CURSOR;
952 unlockInsetInInset(bv, the_locking_inset);
953 if (bv->text->top_y() + bv->painter().paperHeight() <
954 (top_baseline + tabular->GetHeightOfTabular()))
956 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
958 actcell = tabular->GetCellBelow(first_visible_cell) + column;
960 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
963 updateLocal(bv, code);
967 UpdateCodes code = CURSOR;
973 unlockInsetInInset(bv, the_locking_inset);
974 if (top_baseline < 0) {
975 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
977 if (top_baseline > 0)
980 actcell = tabular->GetCellBelow(first_visible_cell) + column;
985 updateLocal(bv, code);
988 // none of these make sense for insettabular,
989 // but we must catch them to prevent any
990 // selection from being confused
994 case LFUN_WORDLEFTSEL:
996 case LFUN_WORDRIGHTSEL:
998 case LFUN_DOWN_PARAGRAPH:
999 case LFUN_DOWN_PARAGRAPHSEL:
1000 case LFUN_UP_PARAGRAPH:
1001 case LFUN_UP_PARAGRAPHSEL:
1002 case LFUN_BACKSPACE:
1007 case LFUN_BEGINNINGBUF:
1008 case LFUN_BEGINNINGBUFSEL:
1010 case LFUN_ENDBUFSEL:
1012 case LFUN_LAYOUT_TABULAR: {
1013 InsetTabularMailer mailer(*this);
1014 mailer.showDialog(bv);
1017 case LFUN_INSET_DIALOG_UPDATE: {
1018 InsetTabularMailer mailer(*this);
1019 mailer.updateDialog(bv);
1022 case LFUN_TABULAR_FEATURE:
1023 if (!tabularFeatures(bv, arg))
1024 result = UNDISPATCHED;
1026 // insert file functions
1027 case LFUN_FILE_INSERT_ASCII_PARA:
1028 case LFUN_FILE_INSERT_ASCII:
1030 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1033 if (insertAsciiString(bv, tmpstr, false))
1034 updateLocal(bv, INIT);
1036 result = UNDISPATCHED;
1039 // cut and paste functions
1041 if (!copySelection(bv))
1045 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1046 cutSelection(bv->buffer()->params);
1047 updateLocal(bv, INIT);
1050 if (!hasSelection())
1055 case LFUN_PASTESELECTION:
1057 string const clip(bv->getClipboard());
1061 if (clip.find('\t') != string::npos) {
1065 string::size_type len = clip.length();
1066 string::size_type p = 0;
1069 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1077 maxCols = max(cols, maxCols);
1083 maxCols = max(cols, maxCols);
1084 delete paste_tabular;
1085 paste_tabular = new LyXTabular(bv->buffer()->params,
1086 this, rows, maxCols);
1087 string::size_type op = 0;
1089 int cells = paste_tabular->GetNumberOfCells();
1091 while ((cell < cells) && (p < len) &&
1092 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1097 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1102 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1103 while (cols++ < maxCols)
1111 // check for the last cell if there is no trailing '\n'
1112 if ((cell < cells) && (op < len))
1113 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1116 if (!insertAsciiString(bv, clip, true))
1119 // so that the clipboard is used and it goes on
1121 // and executes LFUN_PASTESELECTION in insettext!
1122 delete paste_tabular;
1127 if (hasPasteBuffer()) {
1128 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1130 updateLocal(bv, INIT);
1133 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1135 // handle font changing stuff on selection before we lock the inset
1136 // in the default part!
1137 result = UNDISPATCHED;
1148 case LFUN_UNDERLINE:
1149 case LFUN_FONT_SIZE:
1150 if (bv->dispatch(FuncRequest(bv, action, arg)))
1151 result = DISPATCHED;
1157 // we try to activate the actual inset and put this event down to
1158 // the insets dispatch function.
1159 if ((result == DISPATCHED) || the_locking_inset)
1162 if (activateCellInset(bv)) {
1163 // reset need_update setted in above function!
1165 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1166 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1167 unlockInsetInInset(bv, the_locking_inset);
1169 // we need to update if this was requested before
1170 updateLocal(bv, NONE);
1171 return UNDISPATCHED;
1174 // so the below CELL is not set because this is higher
1175 // priority and we get a full redraw
1176 need_update = SELECTION;
1179 updateLocal(bv, CELL);
1184 if (result < FINISHED) {
1185 if (!the_locking_inset) {
1186 if (bv->fitCursor())
1187 updateLocal(bv, FULL);
1190 bv->unlockInset(this);
1195 int InsetTabular::latex(Buffer const * buf, ostream & os,
1196 LatexRunParams const & runparams) const
1198 return tabular->latex(buf, os, runparams);
1202 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1205 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1207 return tabular->ascii(buf, os, 0, false,0);
1211 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1214 int const ret = tabular->ascii(buf,os,
1215 (int)parOwner()->params().depth(),
1222 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1227 // if the table is inside a float it doesn't need the informaltable
1228 // wrapper. Search for it.
1229 for(master = owner();
1230 master && master->lyxCode() != Inset::FLOAT_CODE;
1231 master = master->owner());
1234 os << "<informaltable>";
1239 ret+= tabular->docbook(buf, os, mixcont);
1241 os << "</informaltable>";
1250 void InsetTabular::validate(LaTeXFeatures & features) const
1252 tabular->Validate(features);
1256 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1262 bool changed = false;
1264 // FIXME: since InsetText ignores this anyway, it doesn't
1265 // matter what we pass it. Ugly
1268 // if we have a locking_inset we should have to check only this cell for
1269 // change so I'll try this to have a boost, but who knows ;)
1270 if ((need_update != INIT) &&
1271 (the_locking_inset == tabular->GetCellInset(actcell))) {
1272 for(int i = 0; i < tabular->columns(); ++i) {
1273 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1275 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1278 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1279 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1280 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1283 for (int i = 0; i < tabular->rows(); ++i) {
1286 for (int j = 0; j < tabular->columns(); ++j) {
1287 if (tabular->IsPartOfMultiColumn(i,j))
1290 inset = tabular->GetCellInset(cell);
1291 if (!reinit && !tabular->GetPWidth(cell).zero())
1292 inset->update(bv, false);
1293 maxAsc = max(maxAsc, inset->ascent(bv, font));
1294 maxDesc = max(maxDesc, inset->descent(bv, font));
1295 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1297 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1298 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1306 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1308 if (the_locking_inset) {
1309 the_locking_inset->getCursor(bv, x, y);
1314 y = cursor_.y() + InsetTabular::y();
1317 int desc = tabular->GetDescentOfRow(actrow);
1319 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1321 y += ADD_TO_HEIGHT * 2;
1322 y += TEXT_TO_INSET_OFFSET;
1326 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1328 if (the_locking_inset) {
1329 the_locking_inset->getCursorPos(bv, x, y);
1332 x = cursor_.x() - top_x;
1337 void InsetTabular::fitInsetCursor(BufferView * bv) const
1339 if (the_locking_inset) {
1340 int old_top_y = bv->text->top_y();
1341 the_locking_inset->fitInsetCursor(bv);
1342 if (old_top_y != bv->text->top_y())
1348 int const asc = font_metrics::maxAscent(font);
1349 int const desc = font_metrics::maxDescent(font);
1352 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1357 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1361 actcell = actrow = actcol = 0;
1362 int ly = tabular->GetDescentOfRow(actrow);
1364 // first search the right row
1365 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1366 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1367 tabular->GetAscentOfRow(actrow + 1) +
1368 tabular->GetAdditionalHeight(actrow + 1));
1370 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1372 actcell = tabular->GetCellNumber(actrow, actcol);
1374 // now search the right column
1375 int lx = tabular->GetWidthOfColumn(actcell) -
1376 tabular->GetAdditionalWidth(actcell);
1377 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1378 lx += tabular->GetWidthOfColumn(actcell + 1)
1379 + tabular->GetAdditionalWidth(actcell);
1381 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1386 int InsetTabular::getCellXPos(int cell) const
1390 for (; !tabular->IsFirstCellInRow(c); --c)
1392 int lx = tabular->GetWidthOfColumn(cell);
1393 for (; c < cell; ++c) {
1394 lx += tabular->GetWidthOfColumn(c);
1396 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1400 void InsetTabular::resetPos(BufferView * bv) const
1402 #ifdef WITH_WARNINGS
1403 #warning This should be fixed in the right manner (20011128 Jug)
1405 // fast hack to fix infinite repaintings!
1406 if (in_reset_pos > 0)
1410 actcol = tabular->column_of_cell(actcell);
1413 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1414 if (tabular->IsLastCellInRow(cell)) {
1415 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1416 tabular->GetAscentOfRow(actrow + 1) +
1417 tabular->GetAdditionalHeight(actrow + 1));
1421 if (!locked || nodraw()) {
1422 if (the_locking_inset)
1423 inset_y = cursor_.y();
1426 // we need this only from here on!!!
1428 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1429 int new_x = getCellXPos(actcell);
1430 int old_x = cursor_.x();
1433 // cursor.x(getCellXPos(actcell) + offset);
1434 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1435 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1438 updateLocal(bv, FULL);
1439 } else if (the_locking_inset &&
1440 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1442 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1443 if (xx > (bv->workWidth()-20)) {
1444 scroll(bv, -(xx - bv->workWidth() + 60));
1445 updateLocal(bv, FULL);
1446 } else if (xx < 20) {
1452 updateLocal(bv, FULL);
1454 } else if ((cursor_.x() - offset) > 20 &&
1455 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1456 > (bv->workWidth() - 20)) {
1457 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1458 updateLocal(bv, FULL);
1459 } else if ((cursor_.x() - offset) < 20) {
1460 scroll(bv, 20 - cursor_.x() + offset);
1461 updateLocal(bv, FULL);
1462 } else if (scroll() && top_x > 20 &&
1463 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1464 scroll(bv, old_x - cursor_.x());
1465 updateLocal(bv, FULL);
1467 if (the_locking_inset) {
1468 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1469 inset_y = cursor_.y();
1471 if ((!the_locking_inset ||
1472 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1473 actcell != oldcell) {
1474 InsetTabular * inset = const_cast<InsetTabular *>(this);
1475 InsetTabularMailer mailer(*inset);
1476 mailer.updateDialog(bv);
1483 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1485 if (lock && !old_locking_inset) {
1486 if (activateCellInset(bv))
1489 bool moved = isRightToLeft(bv)
1490 ? movePrevCell(bv) : moveNextCell(bv);
1492 return FINISHED_RIGHT;
1493 if (lock && activateCellInset(bv))
1497 return DISPATCHED_NOUPDATE;
1501 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1503 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1506 if (lock) { // behind the inset
1507 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1511 return DISPATCHED_NOUPDATE;
1515 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1517 int const ocell = actcell;
1518 actcell = tabular->GetCellAbove(actcell);
1519 if (actcell == ocell) // we moved out of the inset
1525 if (old_locking_inset) {
1526 old_locking_inset->getCursorPos(bv, x, y);
1527 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1529 if (activateCellInset(bv, x, 0))
1532 return DISPATCHED_NOUPDATE;
1536 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1538 int const ocell = actcell;
1539 actcell = tabular->GetCellBelow(actcell);
1540 if (actcell == ocell) // we moved out of the inset
1541 return FINISHED_DOWN;
1546 if (old_locking_inset) {
1547 old_locking_inset->getCursorPos(bv, x, y);
1548 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1550 if (activateCellInset(bv, x, 0))
1553 return DISPATCHED_NOUPDATE;
1557 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1559 if (isRightToLeft(bv)) {
1560 if (tabular->IsFirstCellInRow(actcell)) {
1561 int row = tabular->row_of_cell(actcell);
1562 if (row == tabular->rows() - 1)
1564 actcell = tabular->GetLastCellInRow(row);
1565 actcell = tabular->GetCellBelow(actcell);
1572 if (tabular->IsLastCell(actcell))
1577 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1578 isRightToLeftPar(bv->buffer()->params);
1579 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1586 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1588 if (isRightToLeft(bv)) {
1589 if (tabular->IsLastCellInRow(actcell)) {
1590 int row = tabular->row_of_cell(actcell);
1593 actcell = tabular->GetFirstCellInRow(row);
1594 actcell = tabular->GetCellAbove(actcell);
1596 if (tabular->IsLastCell(actcell))
1601 if (!actcell) // first cell
1606 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1607 isRightToLeftPar(bv->buffer()->params);
1608 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1615 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1619 setSelection(0, tabular->GetNumberOfCells() - 1);
1621 if (hasSelection()) {
1622 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1623 bool const frozen = undo_frozen;
1626 // apply the fontchange on the whole selection
1631 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1632 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1633 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1634 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1641 updateLocal(bv, INIT);
1643 if (the_locking_inset)
1644 the_locking_inset->setFont(bv, font, tall);
1648 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1650 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1653 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1654 string const tmp = tabularFeature[i].feature;
1656 if (tmp == what.substr(0, tmp.length())) {
1657 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1658 //tabularFeatures[i].feature.length())) {
1659 action = tabularFeature[i].action;
1663 if (action == LyXTabular::LAST_ACTION)
1667 ltrim(what.substr(tabularFeature[i].feature.length()));
1668 tabularFeatures(bv, action, val);
1674 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1675 string const & special, bool & flag)
1677 if (special == "dl_above") {
1680 } else if (special == "dl_below") {
1681 ltt.bottomDL = flag;
1683 } else if (special == "empty") {
1695 void InsetTabular::tabularFeatures(BufferView * bv,
1696 LyXTabular::Feature feature,
1697 string const & value)
1703 bool setLines = false;
1704 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1705 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1708 case LyXTabular::M_ALIGN_LEFT:
1709 case LyXTabular::ALIGN_LEFT:
1710 setAlign = LYX_ALIGN_LEFT;
1712 case LyXTabular::M_ALIGN_RIGHT:
1713 case LyXTabular::ALIGN_RIGHT:
1714 setAlign = LYX_ALIGN_RIGHT;
1716 case LyXTabular::M_ALIGN_CENTER:
1717 case LyXTabular::ALIGN_CENTER:
1718 setAlign = LYX_ALIGN_CENTER;
1720 case LyXTabular::ALIGN_BLOCK:
1721 setAlign = LYX_ALIGN_BLOCK;
1723 case LyXTabular::M_VALIGN_TOP:
1724 case LyXTabular::VALIGN_TOP:
1725 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1727 case LyXTabular::M_VALIGN_BOTTOM:
1728 case LyXTabular::VALIGN_BOTTOM:
1729 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1731 case LyXTabular::M_VALIGN_CENTER:
1732 case LyXTabular::VALIGN_CENTER:
1733 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1738 if (hasSelection()) {
1739 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1741 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1742 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1744 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1746 int row = tabular->row_of_cell(actcell);
1747 int column = tabular->column_of_cell(actcell);
1749 LyXTabular::ltType ltt;
1752 case LyXTabular::SET_PWIDTH:
1754 LyXLength const vallen(value);
1755 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1757 bool const update = (tmplen != vallen);
1758 tabular->SetColumnPWidth(actcell, vallen);
1761 for (int i = 0; i < tabular->rows(); ++i) {
1762 cell = tabular->GetCellNumber(i,column);
1763 tabular->GetCellInset(cell)->resizeLyXText(bv);
1765 updateLocal(bv, INIT);
1769 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1770 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1771 else if (!vallen.zero()
1772 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1773 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1776 case LyXTabular::SET_MPWIDTH:
1778 LyXLength const vallen(value);
1779 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1781 bool const update = (tmplen != vallen);
1782 tabular->SetMColumnPWidth(actcell, vallen);
1784 for (int i = 0; i < tabular->rows(); ++i) {
1785 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1788 updateLocal(bv, INIT);
1792 case LyXTabular::SET_SPECIAL_COLUMN:
1793 case LyXTabular::SET_SPECIAL_MULTI:
1794 tabular->SetAlignSpecial(actcell,value,feature);
1795 updateLocal(bv, FULL);
1797 case LyXTabular::APPEND_ROW:
1798 // append the row into the tabular
1799 unlockInsetInInset(bv, the_locking_inset);
1800 tabular->AppendRow(bv->buffer()->params, actcell);
1801 updateLocal(bv, INIT);
1803 case LyXTabular::APPEND_COLUMN:
1804 // append the column into the tabular
1805 unlockInsetInInset(bv, the_locking_inset);
1806 tabular->AppendColumn(bv->buffer()->params, actcell);
1807 actcell = tabular->GetCellNumber(row, column);
1808 updateLocal(bv, INIT);
1810 case LyXTabular::DELETE_ROW:
1811 unlockInsetInInset(bv, the_locking_inset);
1812 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1813 tabular->DeleteRow(sel_row_start);
1815 if (sel_row_start >= tabular->rows())
1817 actcell = tabular->GetCellNumber(sel_row_start, column);
1819 updateLocal(bv, INIT);
1821 case LyXTabular::DELETE_COLUMN:
1822 unlockInsetInInset(bv, the_locking_inset);
1823 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1824 tabular->DeleteColumn(sel_col_start);
1826 if (sel_col_start >= tabular->columns())
1828 actcell = tabular->GetCellNumber(row, sel_col_start);
1830 updateLocal(bv, INIT);
1832 case LyXTabular::M_TOGGLE_LINE_TOP:
1834 case LyXTabular::TOGGLE_LINE_TOP:
1836 bool lineSet = !tabular->TopLine(actcell, flag);
1837 for (int i = sel_row_start; i <= sel_row_end; ++i)
1838 for (int j = sel_col_start; j <= sel_col_end; ++j)
1839 tabular->SetTopLine(
1840 tabular->GetCellNumber(i, j),
1842 updateLocal(bv, INIT);
1846 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1848 case LyXTabular::TOGGLE_LINE_BOTTOM:
1850 bool lineSet = !tabular->BottomLine(actcell, flag);
1851 for (int i = sel_row_start; i <= sel_row_end; ++i)
1852 for (int j = sel_col_start; j <= sel_col_end; ++j)
1853 tabular->SetBottomLine(
1854 tabular->GetCellNumber(i, j),
1857 updateLocal(bv, INIT);
1861 case LyXTabular::M_TOGGLE_LINE_LEFT:
1863 case LyXTabular::TOGGLE_LINE_LEFT:
1865 bool lineSet = !tabular->LeftLine(actcell, flag);
1866 for (int i = sel_row_start; i <= sel_row_end; ++i)
1867 for (int j = sel_col_start; j <= sel_col_end; ++j)
1868 tabular->SetLeftLine(
1869 tabular->GetCellNumber(i,j),
1872 updateLocal(bv, INIT);
1876 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1878 case LyXTabular::TOGGLE_LINE_RIGHT:
1880 bool lineSet = !tabular->RightLine(actcell, flag);
1881 for (int i = sel_row_start; i <= sel_row_end; ++i)
1882 for (int j = sel_col_start; j <= sel_col_end; ++j)
1883 tabular->SetRightLine(
1884 tabular->GetCellNumber(i,j),
1887 updateLocal(bv, INIT);
1891 case LyXTabular::M_ALIGN_LEFT:
1892 case LyXTabular::M_ALIGN_RIGHT:
1893 case LyXTabular::M_ALIGN_CENTER:
1895 case LyXTabular::ALIGN_LEFT:
1896 case LyXTabular::ALIGN_RIGHT:
1897 case LyXTabular::ALIGN_CENTER:
1898 case LyXTabular::ALIGN_BLOCK:
1899 for (int i = sel_row_start; i <= sel_row_end; ++i)
1900 for (int j = sel_col_start; j <= sel_col_end; ++j)
1901 tabular->SetAlignment(
1902 tabular->GetCellNumber(i, j),
1905 updateLocal(bv, INIT);
1907 case LyXTabular::M_VALIGN_TOP:
1908 case LyXTabular::M_VALIGN_BOTTOM:
1909 case LyXTabular::M_VALIGN_CENTER:
1911 case LyXTabular::VALIGN_TOP:
1912 case LyXTabular::VALIGN_BOTTOM:
1913 case LyXTabular::VALIGN_CENTER:
1914 for (int i = sel_row_start; i <= sel_row_end; ++i)
1915 for (int j = sel_col_start; j <= sel_col_end; ++j)
1916 tabular->SetVAlignment(
1917 tabular->GetCellNumber(i, j),
1919 updateLocal(bv, INIT);
1921 case LyXTabular::MULTICOLUMN:
1923 if (sel_row_start != sel_row_end) {
1924 #ifdef WITH_WARNINGS
1925 #warning Need I say it ? This is horrible.
1927 Alert::error(_("Error setting multicolumn"),
1928 _("You cannot set multicolumn vertically."));
1931 // just multicol for one Single Cell
1932 if (!hasSelection()) {
1933 // check wether we are completly in a multicol
1934 if (tabular->IsMultiColumn(actcell)) {
1935 tabular->UnsetMultiColumn(actcell);
1936 updateLocal(bv, INIT);
1938 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1939 updateLocal(bv, CELL);
1943 // we have a selection so this means we just add all this
1944 // cells to form a multicolumn cell
1948 if (sel_cell_start > sel_cell_end) {
1949 s_start = sel_cell_end;
1950 s_end = sel_cell_start;
1952 s_start = sel_cell_start;
1953 s_end = sel_cell_end;
1955 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1958 updateLocal(bv, INIT);
1961 case LyXTabular::SET_ALL_LINES:
1963 case LyXTabular::UNSET_ALL_LINES:
1964 for (int i = sel_row_start; i <= sel_row_end; ++i)
1965 for (int j = sel_col_start; j <= sel_col_end; ++j)
1966 tabular->SetAllLines(
1967 tabular->GetCellNumber(i,j), setLines);
1968 updateLocal(bv, INIT);
1970 case LyXTabular::SET_LONGTABULAR:
1971 tabular->SetLongTabular(true);
1972 updateLocal(bv, INIT); // because this toggles displayed
1974 case LyXTabular::UNSET_LONGTABULAR:
1975 tabular->SetLongTabular(false);
1976 updateLocal(bv, INIT); // because this toggles displayed
1978 case LyXTabular::SET_ROTATE_TABULAR:
1979 tabular->SetRotateTabular(true);
1981 case LyXTabular::UNSET_ROTATE_TABULAR:
1982 tabular->SetRotateTabular(false);
1984 case LyXTabular::SET_ROTATE_CELL:
1985 for (int i = sel_row_start; i <= sel_row_end; ++i)
1986 for (int j = sel_col_start; j<=sel_col_end; ++j)
1987 tabular->SetRotateCell(
1988 tabular->GetCellNumber(i, j),
1991 case LyXTabular::UNSET_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), false);
1997 case LyXTabular::SET_USEBOX:
1999 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2000 if (val == tabular->GetUsebox(actcell))
2001 val = LyXTabular::BOX_NONE;
2002 for (int i = sel_row_start; i <= sel_row_end; ++i)
2003 for (int j = sel_col_start; j <= sel_col_end; ++j)
2005 tabular->GetCellNumber(i, j), val);
2008 case LyXTabular::UNSET_LTFIRSTHEAD:
2010 case LyXTabular::SET_LTFIRSTHEAD:
2011 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2012 checkLongtableSpecial(ltt, value, flag);
2013 tabular->SetLTHead(row, flag, ltt, true);
2015 case LyXTabular::UNSET_LTHEAD:
2017 case LyXTabular::SET_LTHEAD:
2018 (void)tabular->GetRowOfLTHead(row, ltt);
2019 checkLongtableSpecial(ltt, value, flag);
2020 tabular->SetLTHead(row, flag, ltt, false);
2022 case LyXTabular::UNSET_LTFOOT:
2024 case LyXTabular::SET_LTFOOT:
2025 (void)tabular->GetRowOfLTFoot(row, ltt);
2026 checkLongtableSpecial(ltt, value, flag);
2027 tabular->SetLTFoot(row, flag, ltt, false);
2029 case LyXTabular::UNSET_LTLASTFOOT:
2031 case LyXTabular::SET_LTLASTFOOT:
2032 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2033 checkLongtableSpecial(ltt, value, flag);
2034 tabular->SetLTFoot(row, flag, ltt, true);
2036 case LyXTabular::SET_LTNEWPAGE:
2038 bool what = !tabular->GetLTNewPage(row);
2039 tabular->SetLTNewPage(row, what);
2042 // dummy stuff just to avoid warnings
2043 case LyXTabular::LAST_ACTION:
2047 InsetTabularMailer mailer(*this);
2048 mailer.updateDialog(bv);
2052 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2055 UpdatableInset * inset =
2056 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2057 LyXFont font(LyXFont::ALL_SANE);
2059 x = inset->x() + inset->width(bv, font);
2060 y = inset->descent(bv, font);
2062 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2063 //inset_y = cursor.y();
2064 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2065 if (!the_locking_inset)
2067 updateLocal(bv, CELL);
2068 return (the_locking_inset != 0);
2072 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2073 mouse_button::state button)
2075 inset_x = cursor_.x()
2076 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2077 inset_y = cursor_.y();
2078 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2082 bool InsetTabular::insetHit(BufferView *, int x, int) const
2085 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2089 // This returns paperWidth() if the cell-width is unlimited or the width
2090 // in pixels if we have a pwidth for this cell.
2091 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2093 LyXLength const len = tabular->GetPWidth(cell);
2097 return len.inPixels(latexTextWidth(bv));
2101 int InsetTabular::getMaxWidth(BufferView * bv,
2102 UpdatableInset const * inset) const
2104 int cell = tabular->GetCellFromInset(inset, actcell);
2107 lyxerr << "Own inset not found, shouldn't really happen!"
2112 int w = getMaxWidthOfCell(bv, cell);
2114 // because the inset then subtracts it's top_x and owner->x()
2115 w += (inset->x() - top_x);
2122 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2124 resizeLyXText(bv, recursive);
2128 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2131 for(int i = 0; i < tabular->rows(); ++i) {
2132 for(int j = 0; j < tabular->columns(); ++j) {
2133 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2141 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2142 bool const recursive) const
2144 if (the_locking_inset)
2145 return the_locking_inset->getLyXText(bv, recursive);
2147 // if we're locked lock the actual insettext and return it's LyXText!!!
2149 UpdatableInset * inset =
2150 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2151 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2152 return the_locking_inset->getLyXText(bv, recursive);
2155 return Inset::getLyXText(bv, recursive);
2159 bool InsetTabular::showInsetDialog(BufferView * bv) const
2161 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2162 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2163 InsetTabularMailer mailer(*tmp);
2164 mailer.showDialog(bv);
2170 void InsetTabular::openLayoutDialog(BufferView * bv) const
2172 if (the_locking_inset) {
2173 InsetTabular * i = static_cast<InsetTabular *>
2174 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2176 i->openLayoutDialog(bv);
2180 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2181 InsetTabularMailer mailer(*tmp);
2182 mailer.showDialog(bv);
2187 // function returns an object as defined in func_status.h:
2188 // states OK, Unknown, Disabled, On, Off.
2190 FuncStatus InsetTabular::getStatus(string const & what) const
2192 int action = LyXTabular::LAST_ACTION;
2196 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2197 string const tmp = tabularFeature[i].feature;
2198 if (tmp == what.substr(0, tmp.length())) {
2199 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2200 // tabularFeatures[i].feature.length())) {
2201 action = tabularFeature[i].action;
2205 if (action == LyXTabular::LAST_ACTION) {
2207 return status.unknown(true);
2210 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2215 LyXTabular::ltType dummyltt;
2218 if (hasSelection()) {
2219 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2221 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2225 case LyXTabular::SET_PWIDTH:
2226 case LyXTabular::SET_MPWIDTH:
2227 case LyXTabular::SET_SPECIAL_COLUMN:
2228 case LyXTabular::SET_SPECIAL_MULTI:
2229 case LyXTabular::APPEND_ROW:
2230 case LyXTabular::APPEND_COLUMN:
2231 case LyXTabular::DELETE_ROW:
2232 case LyXTabular::DELETE_COLUMN:
2233 case LyXTabular::SET_ALL_LINES:
2234 case LyXTabular::UNSET_ALL_LINES:
2235 return status.clear();
2237 case LyXTabular::MULTICOLUMN:
2238 status.setOnOff(tabular->IsMultiColumn(actcell));
2240 case LyXTabular::M_TOGGLE_LINE_TOP:
2242 case LyXTabular::TOGGLE_LINE_TOP:
2243 status.setOnOff(tabular->TopLine(actcell, flag));
2245 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2247 case LyXTabular::TOGGLE_LINE_BOTTOM:
2248 status.setOnOff(tabular->BottomLine(actcell, flag));
2250 case LyXTabular::M_TOGGLE_LINE_LEFT:
2252 case LyXTabular::TOGGLE_LINE_LEFT:
2253 status.setOnOff(tabular->LeftLine(actcell, flag));
2255 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2257 case LyXTabular::TOGGLE_LINE_RIGHT:
2258 status.setOnOff(tabular->RightLine(actcell, flag));
2260 case LyXTabular::M_ALIGN_LEFT:
2262 case LyXTabular::ALIGN_LEFT:
2263 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2265 case LyXTabular::M_ALIGN_RIGHT:
2267 case LyXTabular::ALIGN_RIGHT:
2268 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2270 case LyXTabular::M_ALIGN_CENTER:
2272 case LyXTabular::ALIGN_CENTER:
2273 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2275 case LyXTabular::ALIGN_BLOCK:
2276 status.disabled(tabular->GetPWidth(actcell).zero());
2277 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2279 case LyXTabular::M_VALIGN_TOP:
2281 case LyXTabular::VALIGN_TOP:
2282 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2284 case LyXTabular::M_VALIGN_BOTTOM:
2286 case LyXTabular::VALIGN_BOTTOM:
2287 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2289 case LyXTabular::M_VALIGN_CENTER:
2291 case LyXTabular::VALIGN_CENTER:
2292 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2294 case LyXTabular::SET_LONGTABULAR:
2295 status.setOnOff(tabular->IsLongTabular());
2297 case LyXTabular::UNSET_LONGTABULAR:
2298 status.setOnOff(!tabular->IsLongTabular());
2300 case LyXTabular::SET_ROTATE_TABULAR:
2301 status.setOnOff(tabular->GetRotateTabular());
2303 case LyXTabular::UNSET_ROTATE_TABULAR:
2304 status.setOnOff(!tabular->GetRotateTabular());
2306 case LyXTabular::SET_ROTATE_CELL:
2307 status.setOnOff(tabular->GetRotateCell(actcell));
2309 case LyXTabular::UNSET_ROTATE_CELL:
2310 status.setOnOff(!tabular->GetRotateCell(actcell));
2312 case LyXTabular::SET_USEBOX:
2313 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2315 case LyXTabular::SET_LTFIRSTHEAD:
2316 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2318 case LyXTabular::SET_LTHEAD:
2319 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2321 case LyXTabular::SET_LTFOOT:
2322 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2324 case LyXTabular::SET_LTLASTFOOT:
2325 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2327 case LyXTabular::SET_LTNEWPAGE:
2328 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2332 status.disabled(true);
2339 vector<string> const InsetTabular::getLabelList() const
2341 return tabular->getLabelList();
2345 bool InsetTabular::copySelection(BufferView * bv)
2347 if (!hasSelection())
2350 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2351 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2352 if (sel_col_start > sel_col_end) {
2353 sel_col_start = sel_col_end;
2354 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2356 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2358 int const columns = sel_col_end - sel_col_start + 1;
2360 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2361 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2362 if (sel_row_start > sel_row_end) {
2363 swap(sel_row_start, sel_row_end);
2365 int const rows = sel_row_end - sel_row_start + 1;
2367 delete paste_tabular;
2368 paste_tabular = new LyXTabular(bv->buffer()->params,
2369 this, *tabular); // rows, columns);
2370 for (int i = 0; i < sel_row_start; ++i)
2371 paste_tabular->DeleteRow(0);
2372 while (paste_tabular->rows() > rows)
2373 paste_tabular->DeleteRow(rows);
2374 paste_tabular->SetTopLine(0, true, true);
2375 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2377 for (int i = 0; i < sel_col_start; ++i)
2378 paste_tabular->DeleteColumn(0);
2379 while (paste_tabular->columns() > columns)
2380 paste_tabular->DeleteColumn(columns);
2381 paste_tabular->SetLeftLine(0, true, true);
2382 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2386 paste_tabular->ascii(bv->buffer(), sstr,
2387 (int)parOwner()->params().depth(), true, '\t');
2388 bv->stuffClipboard(STRCONV(sstr.str()));
2393 bool InsetTabular::pasteSelection(BufferView * bv)
2398 for (int r1 = 0, r2 = actrow;
2399 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2401 for(int c1 = 0, c2 = actcol;
2402 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2404 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2405 tabular->IsPartOfMultiColumn(r2,c2))
2407 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2411 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2415 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2416 int const n2 = tabular->GetCellNumber(r2, c2);
2417 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2418 tabular->GetCellInset(n2)->setOwner(this);
2419 tabular->GetCellInset(n2)->deleteLyXText(bv);
2420 tabular->GetCellInset(n2)->markNew();
2427 bool InsetTabular::cutSelection(BufferParams const & bp)
2429 if (!hasSelection())
2432 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2433 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2434 if (sel_col_start > sel_col_end) {
2435 sel_col_start = sel_col_end;
2436 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2438 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2440 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2441 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2442 if (sel_row_start > sel_row_end) {
2443 swap(sel_row_start, sel_row_end);
2445 if (sel_cell_start > sel_cell_end) {
2446 swap(sel_cell_start, sel_cell_end);
2448 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2449 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2450 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2457 bool InsetTabular::isRightToLeft(BufferView * bv)
2459 return bv->getParentLanguage(this)->RightToLeft();
2463 bool InsetTabular::nodraw() const
2465 if (!UpdatableInset::nodraw() && the_locking_inset)
2466 return the_locking_inset->nodraw();
2467 return UpdatableInset::nodraw();
2471 int InsetTabular::scroll(bool recursive) const
2473 int sx = UpdatableInset::scroll(false);
2475 if (recursive && the_locking_inset)
2476 sx += the_locking_inset->scroll(recursive);
2482 void InsetTabular::getSelection(int & srow, int & erow,
2483 int & scol, int & ecol) const
2485 int const start = hasSelection() ? sel_cell_start : actcell;
2486 int const end = hasSelection() ? sel_cell_end : actcell;
2488 srow = tabular->row_of_cell(start);
2489 erow = tabular->row_of_cell(end);
2494 scol = tabular->column_of_cell(start);
2495 ecol = tabular->column_of_cell(end);
2499 ecol = tabular->right_column_of_cell(end);
2504 ParagraphList * InsetTabular::getParagraphs(int i) const
2506 return (i < tabular->GetNumberOfCells())
2507 ? tabular->GetCellInset(i)->getParagraphs(0)
2512 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2514 if (the_locking_inset)
2515 return the_locking_inset->cursor(bv);
2516 return Inset::cursor(bv);
2520 Inset * InsetTabular::getInsetFromID(int id_arg) const
2523 return const_cast<InsetTabular *>(this);
2526 for(int i = 0; i < tabular->rows(); ++i) {
2527 for(int j = 0; j < tabular->columns(); ++j) {
2528 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2537 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2540 if (the_locking_inset) {
2541 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2542 if (!word.word().empty()) {
2546 if (tabular->IsLastCell(actcell)) {
2547 bv->unlockInset(const_cast<InsetTabular *>(this));
2549 return WordLangTuple();
2553 // otherwise we have to lock the next inset and ask for it's selecttion
2554 UpdatableInset * inset =
2555 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2556 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2557 WordLangTuple word(selectNextWordInt(bv, value));
2559 if (!word.word().empty())
2565 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2567 // when entering this function the inset should be ALWAYS locked!
2568 lyx::Assert(the_locking_inset);
2570 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2571 if (!word.word().empty())
2574 if (tabular->IsLastCell(actcell)) {
2575 bv->unlockInset(const_cast<InsetTabular *>(this));
2576 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 return selectNextWordInt(bv, value);
2587 void InsetTabular::selectSelectedWord(BufferView * bv)
2589 if (the_locking_inset) {
2590 the_locking_inset->selectSelectedWord(bv);
2597 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2599 if (the_locking_inset) {
2600 the_locking_inset->toggleSelection(bv, kill_selection);
2605 void InsetTabular::markErased()
2609 while (!tabular->IsLastCell(cell)) {
2611 InsetText * inset = tabular->GetCellInset(cell);
2612 inset->markErased();
2617 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2619 if (the_locking_inset) {
2620 if (the_locking_inset->nextChange(bv, length)) {
2621 updateLocal(bv, CELL);
2624 if (tabular->IsLastCell(actcell))
2628 InsetText * inset = tabular->GetCellInset(actcell);
2629 if (inset->nextChange(bv, length)) {
2630 updateLocal(bv, FULL);
2633 while (!tabular->IsLastCell(actcell)) {
2635 inset = tabular->GetCellInset(actcell);
2636 if (inset->nextChange(bv, length)) {
2637 updateLocal(bv, FULL);
2645 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2649 if (the_locking_inset) {
2650 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2651 updateLocal(bv, CELL);
2654 if (tabular->IsLastCell(actcell))
2658 InsetText * inset = tabular->GetCellInset(cell);
2659 if (inset->searchForward(bv, str, cs, mw)) {
2660 updateLocal(bv, FULL);
2663 while (!tabular->IsLastCell(cell)) {
2665 inset = tabular->GetCellInset(cell);
2666 if (inset->searchForward(bv, str, cs, mw)) {
2667 updateLocal(bv, FULL);
2675 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2678 int cell = tabular->GetNumberOfCells();
2679 if (the_locking_inset) {
2680 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2681 updateLocal(bv, CELL);
2689 InsetText * inset = tabular->GetCellInset(cell);
2690 if (inset->searchBackward(bv, str, cs, mw)) {
2691 updateLocal(bv, CELL);
2699 bool InsetTabular::insetAllowed(Inset::Code code) const
2701 if (the_locking_inset)
2702 return the_locking_inset->insetAllowed(code);
2703 // we return true here because if the inset is not locked someone
2704 // wants to insert something in one of our insettexts and we generally
2710 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2712 const int cell = tabular->GetCellFromInset(in, actcell);
2715 return tabular->GetPWidth(cell).zero();
2717 // well we didn't obviously find it so maybe our owner knows more
2719 return owner()->forceDefaultParagraphs(in);
2720 // if we're here there is really something strange going on!!!
2724 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2727 if (buf.length() <= 0)
2733 string::size_type len = buf.length();
2734 string::size_type p = 0;
2737 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2746 maxCols = max(cols, maxCols);
2752 maxCols = max(cols, maxCols);
2753 LyXTabular * loctab;
2758 delete paste_tabular;
2759 paste_tabular = new LyXTabular(bv->buffer()->params,
2760 this, rows, maxCols);
2761 loctab = paste_tabular;
2764 loctab = tabular.get();
2770 string::size_type op = 0;
2771 int cells = loctab->GetNumberOfCells();
2774 rows = loctab->rows();
2775 int const columns = loctab->columns();
2777 while ((cell < cells) && (p < len) && (row < rows) &&
2778 (p = buf.find_first_of("\t\n", p)) != string::npos)
2784 // we can only set this if we are not too far right
2785 if (cols < columns) {
2786 InsetText * ti = loctab->GetCellInset(cell);
2787 LyXFont const font = ti->getLyXText(bv)->
2788 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2789 ti->setText(buf.substr(op, p - op), font);
2795 // we can only set this if we are not too far right
2796 if (cols < columns) {
2797 InsetText * ti = loctab->GetCellInset(cell);
2798 LyXFont const font = ti->getLyXText(bv)->
2799 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2800 ti->setText(buf.substr(op, p - op), font);
2805 cell = loctab->GetCellNumber(row, cols);
2811 // check for the last cell if there is no trailing '\n'
2812 if ((cell < cells) && (op < len)) {
2813 InsetText * ti = loctab->GetCellInset(cell);
2814 LyXFont const font = ti->getLyXText(bv)->
2815 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2816 ti->setText(buf.substr(op, len - op), font);
2823 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2825 int const rows = tabular->rows();
2826 int const columns = tabular->columns();
2827 for (int i = 0; i < rows; ++i) {
2828 for (int j = 0; j < columns; ++j) {
2829 tabular->GetCellInset(i,j)->addPreview(loader);
2835 string const InsetTabularMailer:: name_("tabular");
2837 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2842 string const InsetTabularMailer::inset2string() const
2844 return params2string(inset_);
2848 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2850 istringstream data(STRCONV(in));
2852 lex.setStream(data);
2854 #warning CHECK verify that this is a sane value to return.
2860 string const token = lex.getString();
2868 string const token = lex.getString();
2869 if (token != "\\active_cell")
2872 cell = lex.getInteger();
2875 // This is part of the inset proper that is usually swallowed
2876 // by Buffer::readInset
2879 string const token = lex.getString();
2880 if (token != "Tabular")
2887 BufferView * const bv = inset.view();
2888 Buffer const * const buffer = bv ? bv->buffer() : 0;
2890 inset.read(buffer, lex);
2892 // We can't set the active cell, but we can tell the frontend
2898 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2900 BufferView * const bv = inset.view();
2901 Buffer const * const buffer = bv ? bv->buffer() : 0;
2906 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2907 inset.write(buffer, data);
2908 data << "\\end_inset\n";
2909 return STRCONV(data.str());