3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "insettabular.h"
14 #include "insettext.h"
17 #include "BufferView.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
28 #include "lyxlength.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "metricsinfo.h"
36 #include "frontends/Alert.h"
37 #include "frontends/Dialogs.h"
38 #include "frontends/font_metrics.h"
39 #include "frontends/LyXView.h"
40 #include "frontends/Painter.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
126 bool operator()(TabularFeature & tf)
128 return tf.action == feature_;
131 LyXTabular::Feature feature_;
137 string const featureAsString(LyXTabular::Feature feature)
139 TabularFeature * it = tabularFeature;
140 TabularFeature * end = it +
141 sizeof(tabularFeature) / sizeof(TabularFeature);
142 it = std::find_if(it, end, FindFeature(feature));
143 return (it == end) ? string() : it->feature;
147 bool InsetTabular::hasPasteBuffer() const
149 return (paste_tabular != 0);
153 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
160 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
177 InsetTabular::InsetTabular(InsetTabular const & tab)
178 : UpdatableInset(tab), buffer_(tab.buffer_)
180 tabular.reset(new LyXTabular(buffer_->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() const
205 return new InsetTabular(*this);
209 BufferView * InsetTabular::view() const
211 return buffer_->getUser();
215 void InsetTabular::buffer(Buffer * b)
221 void InsetTabular::write(Buffer const * buf, ostream & os) const
223 os << " Tabular" << endl;
224 tabular->write(buf, os);
228 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
230 bool const old_format = (lex.getString() == "\\LyXTable");
232 tabular.reset(new LyXTabular(buf, this, lex));
240 string token = lex.getString();
241 while (lex.isOK() && (token != "\\end_inset")) {
243 token = lex.getString();
245 if (token != "\\end_inset") {
246 lex.printError("Missing \\end_inset at this point. "
252 void InsetTabular::metrics(MetricsInfo &,
253 Dimension & dim) const
255 dim.asc = tabular->getAscentOfRow(0);
256 dim.des = tabular->getHeightOfTabular() - tabular->getAscentOfRow(0) + 1;
257 dim.wid = tabular->getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
261 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
268 BufferView * bv = pi.base.bv;
274 UpdatableInset::draw(pi, x, y);
282 x += ADD_TO_TABULAR_WIDTH;
286 first_visible_cell = -1;
287 for (i = 0; i < tabular->rows(); ++i) {
289 cell = tabular->getCellNumber(i, 0);
290 if (!((y + tabular->getDescentOfRow(i)) > 0) &&
291 (y - tabular->getAscentOfRow(i)) < pi.pain.paperHeight())
293 y += tabular->getDescentOfRow(i) +
294 tabular->getAscentOfRow(i + 1) +
295 tabular->getAdditionalHeight(i + 1);
298 for (j = 0; j < tabular->columns(); ++j) {
299 if (nx > bv->workWidth())
301 if (tabular->isPartOfMultiColumn(i, j))
303 cx = nx + tabular->getBeginningOfTextInCell(cell);
304 if (first_visible_cell < 0)
305 first_visible_cell = cell;
306 if (hasSelection()) {
307 drawCellSelection(pi.pain, nx, y, i, j, cell);
310 tabular->getCellInset(cell)->draw(pi, cx, y);
311 drawCellLines(pi.pain, nx, y, i, cell);
312 nx += tabular->getWidthOfColumn(cell);
316 // Would be nice, but for some completely unfathomable reason,
317 // on a col resize to a new fixed width, even though the insettexts
318 // are resized, the cell isn't, but drawing all cells in a tall table
319 // has the desired effect somehow. Complete dark magic.
321 // avoiding drawing the rest of a long table is
322 // a pretty big speedup
323 if (y > bv->workHeight())
327 y += tabular->getDescentOfRow(i) +
328 tabular->getAscentOfRow(i + 1) +
329 tabular->getAdditionalHeight(i + 1);
336 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
337 int row, int cell) const
339 int x2 = x + tabular->getWidthOfColumn(cell);
342 if (!tabular->topAlreadyDrawn(cell)) {
343 on_off = !tabular->topLine(cell);
344 pain.line(x, y - tabular->getAscentOfRow(row),
345 x2, y - tabular->getAscentOfRow(row),
346 on_off ? LColor::tabularonoffline : LColor::tabularline,
347 on_off ? Painter::line_onoffdash : Painter::line_solid);
349 on_off = !tabular->bottomLine(cell);
350 pain.line(x, y + tabular->getDescentOfRow(row),
351 x2, y + tabular->getDescentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
354 if (!tabular->leftAlreadyDrawn(cell)) {
355 on_off = !tabular->leftLine(cell);
356 pain.line(x, y - tabular->getAscentOfRow(row),
357 x, y + tabular->getDescentOfRow(row),
358 on_off ? LColor::tabularonoffline : LColor::tabularline,
359 on_off ? Painter::line_onoffdash : Painter::line_solid);
361 on_off = !tabular->rightLine(cell);
362 pain.line(x2 - tabular->getAdditionalWidth(cell),
363 y - tabular->getAscentOfRow(row),
364 x2 - tabular->getAdditionalWidth(cell),
365 y + tabular->getDescentOfRow(row),
366 on_off ? LColor::tabularonoffline : LColor::tabularline,
367 on_off ? Painter::line_onoffdash : Painter::line_solid);
371 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
372 int row, int column, int cell) const
374 lyx::Assert(hasSelection());
375 int cs = tabular->column_of_cell(sel_cell_start);
376 int ce = tabular->column_of_cell(sel_cell_end);
379 cs = tabular->column_of_cell(sel_cell_end);
381 ce = tabular->right_column_of_cell(sel_cell_end);
384 int rs = tabular->row_of_cell(sel_cell_start);
385 int re = tabular->row_of_cell(sel_cell_end);
389 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
390 int w = tabular->getWidthOfColumn(cell);
391 int h = tabular->getAscentOfRow(row) + tabular->getDescentOfRow(row)-1;
392 pain.fillRectangle(x, y - tabular->getAscentOfRow(row) + 1,
393 w, h, LColor::selection);
398 void InsetTabular::update(BufferView * bv, bool reinit)
404 owner()->update(bv, true);
411 if (calculate_dimensions_of_cells(bv, true))
414 owner()->update(bv, true);
418 if (the_locking_inset)
419 the_locking_inset->update(bv, reinit);
420 if (need_update < FULL &&
421 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
426 switch (need_update) {
430 if (calculate_dimensions_of_cells(bv, false)) {
445 string const InsetTabular::editMessage() const
447 return _("Opened table");
451 void InsetTabular::insetUnlock(BufferView * bv)
453 if (the_locking_inset) {
454 the_locking_inset->insetUnlock(bv);
455 updateLocal(bv, CELL);
456 the_locking_inset = 0;
461 if (scroll(false) || hasSelection()) {
466 updateLocal(bv, FULL);
471 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
474 calculate_dimensions_of_cells(bv, true);
476 if (!locked && what == CELL)
478 if (need_update < what) // only set this if it has greater update
481 if (need_update != NONE) {
482 bv->updateInset(const_cast<InsetTabular *>(this));
489 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
491 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
496 if (inset == tabular->getCellInset(actcell)) {
497 lyxerr[Debug::INSETTEXT] << "OK" << endl;
498 the_locking_inset = tabular->getCellInset(actcell);
501 } else if (!the_locking_inset) {
502 int const n = tabular->getNumberOfCells();
503 int const id = inset->id();
504 for (int i = 0; i < n; ++i) {
505 InsetText * in = tabular->getCellInset(i);
508 the_locking_inset = in;
513 if (in->getInsetFromID(id)) {
515 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
516 return the_locking_inset->lockInsetInInset(bv, inset);
519 } else if (the_locking_inset && (the_locking_inset == inset)) {
520 lyxerr[Debug::INSETTEXT] << "OK" << endl;
522 } else if (the_locking_inset) {
523 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
524 return the_locking_inset->lockInsetInInset(bv, inset);
526 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
531 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
534 if (!the_locking_inset)
536 if (the_locking_inset == inset) {
537 the_locking_inset->insetUnlock(bv);
539 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
545 updateLocal(bv, CELL);
546 // this has to be here otherwise we don't redraw the cell!
547 the_locking_inset = 0;
550 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
551 if (inset->lyxCode() == TABULAR_CODE &&
552 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
553 InsetTabularMailer mailer(*this);
554 mailer.updateDialog(bv);
563 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
565 Inset * tl_inset = inset;
566 // look if this inset is really inside myself!
567 while(tl_inset->owner() && tl_inset->owner() != this)
568 tl_inset = tl_inset->owner();
569 // if we enter here it's not ower inset
570 if (!tl_inset->owner())
572 // we only have to do this if this is a subinset of our cells
573 if (tl_inset != inset) {
574 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
577 updateLocal(bv, CELL);
582 int InsetTabular::insetInInsetY() const
584 if (!the_locking_inset)
586 return inset_y + the_locking_inset->insetInInsetY();
590 UpdatableInset * InsetTabular::getLockingInset() const
592 return the_locking_inset ? the_locking_inset->getLockingInset() :
593 const_cast<InsetTabular *>(this);
597 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
601 if (the_locking_inset)
602 return the_locking_inset->getFirstLockingInsetOfType(c);
607 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
609 if (the_locking_inset)
610 return the_locking_inset->insertInset(bv, inset);
615 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
617 if (hasSelection() && cmd.button() == mouse_button::button3)
620 if (hasSelection()) {
622 updateLocal(cmd.view(), SELECTION);
625 int const ocell = actcell;
626 int const orow = actrow;
627 BufferView * bv = cmd.view();
631 the_locking_inset = 0;
635 setPos(bv, cmd.x, cmd.y);
637 updateLocal(bv, NONE);
640 if (cmd.button() == mouse_button::button3) {
641 if ((ocell != actcell) && the_locking_inset) {
642 the_locking_inset->insetUnlock(bv);
643 updateLocal(bv, CELL);
644 the_locking_inset = 0;
650 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
652 if ((ocell == actcell) && the_locking_inset && inset_hit) {
654 FuncRequest cmd1 = cmd;
657 the_locking_inset->localDispatch(cmd1);
661 if (the_locking_inset) {
662 the_locking_inset->insetUnlock(bv);
663 updateLocal(bv, CELL);
664 the_locking_inset = 0;
667 if (cmd.button() == mouse_button::button2) {
668 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
672 if (inset_hit && bv->theLockingInset()) {
673 if (!bv->lockInset(static_cast<UpdatableInset*>
674 (tabular->getCellInset(actcell))))
676 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
679 FuncRequest cmd1 = cmd;
682 the_locking_inset->localDispatch(cmd1);
688 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
691 if (the_locking_inset) {
692 FuncRequest cmd1 = cmd;
695 ret = the_locking_inset->localDispatch(cmd1);
697 if (cmd.button() == mouse_button::button3 && !ret) {
698 InsetTabularMailer(*this).showDialog(cmd.view());
705 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
707 if (the_locking_inset) {
708 FuncRequest cmd1 = cmd;
711 the_locking_inset->localDispatch(cmd1);
715 BufferView * bv = cmd.view();
716 int const old_cell = actcell;
718 setPos(bv, cmd.x, cmd.y);
719 if (!hasSelection()) {
720 setSelection(actcell, actcell);
721 updateLocal(bv, SELECTION);
722 } else if (old_cell != actcell) {
723 setSelection(sel_cell_start, actcell);
724 updateLocal(bv, SELECTION);
729 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
731 // We need to save the value of the_locking_inset as the call to
732 // the_locking_inset->localDispatch might unlock it.
733 old_locking_inset = the_locking_inset;
734 RESULT result = UpdatableInset::localDispatch(cmd);
735 BufferView * bv = cmd.view();
737 if (cmd.action == LFUN_INSET_EDIT) {
739 if (!bv->lockInset(this)) {
740 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
746 the_locking_inset = 0;
750 if (cmd.argument.size()) {
751 if (cmd.argument == "left") {
752 if (isRightToLeft(bv))
753 actcell = tabular->getLastCellInRow(0);
757 if (isRightToLeft(bv))
758 actcell = tabular->getFirstCellInRow(tabular->rows()-1);
760 actcell = tabular->getNumberOfCells() - 1;
768 setPos(bv, cmd.x, cmd.y);
771 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
772 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
778 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
783 if (cmd.action < 0 && cmd.argument.empty())
786 bool hs = hasSelection();
789 // this one have priority over the locked InsetText, if we're not already
790 // inside another tabular then that one get's priority!
791 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
792 switch (cmd.action) {
793 case LFUN_MOUSE_PRESS:
797 case LFUN_MOUSE_MOTION:
798 lfunMouseMotion(cmd);
801 case LFUN_MOUSE_RELEASE:
802 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
804 case LFUN_CELL_BACKWARD:
805 case LFUN_CELL_FORWARD:
806 unlockInsetInInset(bv, the_locking_inset);
807 if (cmd.action == LFUN_CELL_FORWARD)
808 moveNextCell(bv, old_locking_inset != 0);
810 movePrevCell(bv, old_locking_inset != 0);
813 updateLocal(bv, SELECTION);
814 if (!the_locking_inset) {
815 return DISPATCHED_NOUPDATE;
818 // this to avoid compiler warnings.
824 kb_action action = cmd.action;
825 string arg = cmd.argument;
826 if (the_locking_inset) {
827 result = the_locking_inset->localDispatch(cmd);
828 if (result == DISPATCHED_NOUPDATE) {
831 if (sc != scroll()) { // inset has been scrolled
832 updateLocal(bv, FULL);
835 } else if (result == DISPATCHED) {
836 updateLocal(bv, CELL);
838 } else if (result == FINISHED_UP) {
840 // Make sure to reset status message after
841 // exiting, e.g. math inset
842 bv->owner()->clearMessage();
843 } else if (result == FINISHED_DOWN) {
845 bv->owner()->clearMessage();
846 } else if (result == FINISHED_RIGHT) {
848 bv->owner()->clearMessage();
849 } else if (result == FINISHED) {
850 bv->owner()->clearMessage();
856 // --- Cursor Movements ----------------------------------
857 case LFUN_RIGHTSEL: {
858 int const start = hasSelection() ? sel_cell_start : actcell;
859 if (tabular->isLastCellInRow(actcell)) {
860 setSelection(start, actcell);
865 // if we are starting a selection, only select
866 // the current cell at the beginning
867 if (hasSelection()) {
868 moveRight(bv, false);
871 setSelection(start, end);
872 updateLocal(bv, SELECTION);
876 result = moveRight(bv);
879 updateLocal(bv, SELECTION);
882 int const start = hasSelection() ? sel_cell_start : actcell;
883 if (tabular->isFirstCellInRow(actcell)) {
884 setSelection(start, actcell);
889 // if we are starting a selection, only select
890 // the current cell at the beginning
891 if (hasSelection()) {
895 setSelection(start, end);
896 updateLocal(bv, SELECTION);
900 result = moveLeft(bv);
903 updateLocal(bv, SELECTION);
906 int const start = hasSelection() ? sel_cell_start : actcell;
907 int const ocell = actcell;
908 // if we are starting a selection, only select
909 // the current cell at the beginning
910 if (hasSelection()) {
912 if ((ocell == sel_cell_end) ||
913 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
914 setSelection(start, tabular->getCellBelow(sel_cell_end));
916 setSelection(start, tabular->getLastCellBelow(sel_cell_end));
918 setSelection(start, start);
920 updateLocal(bv, SELECTION);
924 result = moveDown(bv, old_locking_inset != 0);
927 updateLocal(bv, SELECTION);
931 int const start = hasSelection() ? sel_cell_start : actcell;
932 int const ocell = actcell;
933 // if we are starting a selection, only select
934 // the current cell at the beginning
935 if (hasSelection()) {
937 if ((ocell == sel_cell_end) ||
938 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
939 setSelection(start, tabular->getCellAbove(sel_cell_end));
941 setSelection(start, tabular->getLastCellAbove(sel_cell_end));
943 setSelection(start, start);
945 updateLocal(bv, SELECTION);
949 result = moveUp(bv, old_locking_inset != 0);
952 updateLocal(bv, SELECTION);
955 UpdateCodes code = CURSOR;
961 unlockInsetInInset(bv, the_locking_inset);
962 if (bv->text->top_y() + bv->painter().paperHeight() <
963 (top_baseline + tabular->getHeightOfTabular()))
965 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
967 actcell = tabular->getCellBelow(first_visible_cell) + column;
969 actcell = tabular->getFirstCellInRow(tabular->rows() - 1) + column;
972 updateLocal(bv, code);
976 UpdateCodes code = CURSOR;
982 unlockInsetInInset(bv, the_locking_inset);
983 if (top_baseline < 0) {
984 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
986 if (top_baseline > 0)
989 actcell = tabular->getCellBelow(first_visible_cell) + column;
994 updateLocal(bv, code);
997 // none of these make sense for insettabular,
998 // but we must catch them to prevent any
999 // selection from being confused
1003 case LFUN_WORDLEFTSEL:
1004 case LFUN_WORDRIGHT:
1005 case LFUN_WORDRIGHTSEL:
1007 case LFUN_DOWN_PARAGRAPH:
1008 case LFUN_DOWN_PARAGRAPHSEL:
1009 case LFUN_UP_PARAGRAPH:
1010 case LFUN_UP_PARAGRAPHSEL:
1011 case LFUN_BACKSPACE:
1016 case LFUN_BEGINNINGBUF:
1017 case LFUN_BEGINNINGBUFSEL:
1019 case LFUN_ENDBUFSEL:
1021 case LFUN_LAYOUT_TABULAR: {
1022 InsetTabularMailer mailer(*this);
1023 mailer.showDialog(bv);
1026 case LFUN_INSET_DIALOG_UPDATE: {
1027 InsetTabularMailer mailer(*this);
1028 mailer.updateDialog(bv);
1031 case LFUN_TABULAR_FEATURE:
1032 if (!tabularFeatures(bv, arg))
1033 result = UNDISPATCHED;
1035 // insert file functions
1036 case LFUN_FILE_INSERT_ASCII_PARA:
1037 case LFUN_FILE_INSERT_ASCII:
1039 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1042 if (insertAsciiString(bv, tmpstr, false))
1043 updateLocal(bv, INIT);
1045 result = UNDISPATCHED;
1048 // cut and paste functions
1050 if (!copySelection(bv))
1054 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1055 cutSelection(bv->buffer()->params);
1056 updateLocal(bv, INIT);
1059 if (!hasSelection())
1064 case LFUN_PASTESELECTION:
1066 string const clip(bv->getClipboard());
1070 if (clip.find('\t') != string::npos) {
1074 string::size_type len = clip.length();
1075 string::size_type p = 0;
1078 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1086 maxCols = max(cols, maxCols);
1092 maxCols = max(cols, maxCols);
1093 delete paste_tabular;
1094 paste_tabular = new LyXTabular(bv->buffer()->params,
1095 this, rows, maxCols);
1096 string::size_type op = 0;
1098 int cells = paste_tabular->getNumberOfCells();
1100 while ((cell < cells) && (p < len) &&
1101 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1106 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1111 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1112 while (cols++ < maxCols)
1120 // check for the last cell if there is no trailing '\n'
1121 if ((cell < cells) && (op < len))
1122 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1125 if (!insertAsciiString(bv, clip, true))
1128 // so that the clipboard is used and it goes on
1130 // and executes LFUN_PASTESELECTION in insettext!
1131 delete paste_tabular;
1136 if (hasPasteBuffer()) {
1137 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1139 updateLocal(bv, INIT);
1142 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1144 // handle font changing stuff on selection before we lock the inset
1145 // in the default part!
1146 result = UNDISPATCHED;
1157 case LFUN_UNDERLINE:
1158 case LFUN_FONT_SIZE:
1159 if (bv->dispatch(FuncRequest(bv, action, arg)))
1160 result = DISPATCHED;
1166 // we try to activate the actual inset and put this event down to
1167 // the insets dispatch function.
1168 if ((result == DISPATCHED) || the_locking_inset)
1171 if (activateCellInset(bv)) {
1172 // reset need_update setted in above function!
1174 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1175 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1176 unlockInsetInInset(bv, the_locking_inset);
1178 // we need to update if this was requested before
1179 updateLocal(bv, NONE);
1180 return UNDISPATCHED;
1183 // so the below CELL is not set because this is higher
1184 // priority and we get a full redraw
1185 need_update = SELECTION;
1188 updateLocal(bv, CELL);
1193 if (result < FINISHED) {
1194 if (!the_locking_inset) {
1195 if (bv->fitCursor())
1196 updateLocal(bv, FULL);
1199 bv->unlockInset(this);
1204 int InsetTabular::latex(Buffer const * buf, ostream & os,
1205 LatexRunParams const & runparams) const
1207 return tabular->latex(buf, os, runparams);
1211 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1214 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1216 return tabular->ascii(buf, os, 0, false,0);
1220 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1223 int const ret = tabular->ascii(buf,os,
1224 (int)parOwner()->params().depth(),
1231 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1236 // if the table is inside a float it doesn't need the informaltable
1237 // wrapper. Search for it.
1238 for(master = owner();
1239 master && master->lyxCode() != Inset::FLOAT_CODE;
1240 master = master->owner());
1243 os << "<informaltable>";
1248 ret+= tabular->docbook(buf, os, mixcont);
1250 os << "</informaltable>";
1259 void InsetTabular::validate(LaTeXFeatures & features) const
1261 tabular->validate(features);
1265 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1271 bool changed = false;
1273 // FIXME: since InsetText ignores this anyway, it doesn't
1274 // matter what we pass it. Ugly
1277 // if we have a locking_inset we should have to check only this cell for
1278 // change so I'll try this to have a boost, but who knows ;)
1279 if ((need_update != INIT) &&
1280 (the_locking_inset == tabular->getCellInset(actcell))) {
1281 for(int i = 0; i < tabular->columns(); ++i) {
1282 maxAsc = max(tabular->getCellInset(actrow, i)->ascent(bv, font),
1284 maxDesc = max(tabular->getCellInset(actrow, i)->descent(bv, font),
1287 changed = tabular->setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1288 changed = tabular->setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1289 changed = tabular->setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1292 for (int i = 0; i < tabular->rows(); ++i) {
1295 for (int j = 0; j < tabular->columns(); ++j) {
1296 if (tabular->isPartOfMultiColumn(i,j))
1299 inset = tabular->getCellInset(cell);
1300 if (!reinit && !tabular->getPWidth(cell).zero())
1301 inset->update(bv, false);
1302 maxAsc = max(maxAsc, inset->ascent(bv, font));
1303 maxDesc = max(maxDesc, inset->descent(bv, font));
1304 changed = tabular->setWidthOfCell(cell, inset->width(bv, font)) || changed;
1306 changed = tabular->setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1307 changed = tabular->setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1315 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1317 if (the_locking_inset) {
1318 the_locking_inset->getCursor(bv, x, y);
1323 y = cursor_.y() + InsetTabular::y();
1326 int desc = tabular->getDescentOfRow(actrow);
1328 int ascdesc = tabular->getAscentOfRow(actrow) + desc;
1330 y += ADD_TO_HEIGHT * 2;
1331 y += TEXT_TO_INSET_OFFSET;
1335 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1337 if (the_locking_inset) {
1338 the_locking_inset->getCursorPos(bv, x, y);
1341 x = cursor_.x() - top_x;
1346 void InsetTabular::fitInsetCursor(BufferView * bv) const
1348 if (the_locking_inset) {
1349 int old_top_y = bv->text->top_y();
1350 the_locking_inset->fitInsetCursor(bv);
1351 if (old_top_y != bv->text->top_y())
1357 int const asc = font_metrics::maxAscent(font);
1358 int const desc = font_metrics::maxDescent(font);
1361 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1366 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1370 actcell = actrow = actcol = 0;
1371 int ly = tabular->getDescentOfRow(actrow);
1373 // first search the right row
1374 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1375 cursor_.y(cursor_.y() + tabular->getDescentOfRow(actrow) +
1376 tabular->getAscentOfRow(actrow + 1) +
1377 tabular->getAdditionalHeight(actrow + 1));
1379 ly = cursor_.y() + tabular->getDescentOfRow(actrow);
1381 actcell = tabular->getCellNumber(actrow, actcol);
1383 // now search the right column
1384 int lx = tabular->getWidthOfColumn(actcell) -
1385 tabular->getAdditionalWidth(actcell);
1386 for (; !tabular->isLastCellInRow(actcell) && lx < x; ++actcell) {
1387 lx += tabular->getWidthOfColumn(actcell + 1)
1388 + tabular->getAdditionalWidth(actcell);
1390 cursor_.x(lx - tabular->getWidthOfColumn(actcell) + top_x + 2);
1395 int InsetTabular::getCellXPos(int cell) const
1399 for (; !tabular->isFirstCellInRow(c); --c)
1401 int lx = tabular->getWidthOfColumn(cell);
1402 for (; c < cell; ++c) {
1403 lx += tabular->getWidthOfColumn(c);
1405 return (lx - tabular->getWidthOfColumn(cell) + top_x);
1409 void InsetTabular::resetPos(BufferView * bv) const
1411 #ifdef WITH_WARNINGS
1412 #warning This should be fixed in the right manner (20011128 Jug)
1414 // fast hack to fix infinite repaintings!
1415 if (in_reset_pos > 0)
1419 actcol = tabular->column_of_cell(actcell);
1422 for (; (cell < actcell) && !tabular->isLastRow(cell); ++cell) {
1423 if (tabular->isLastCellInRow(cell)) {
1424 cursor_.y(cursor_.y() + tabular->getDescentOfRow(actrow) +
1425 tabular->getAscentOfRow(actrow + 1) +
1426 tabular->getAdditionalHeight(actrow + 1));
1430 if (!locked || nodraw()) {
1431 if (the_locking_inset)
1432 inset_y = cursor_.y();
1435 // we need this only from here on!!!
1437 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1438 int new_x = getCellXPos(actcell);
1439 int old_x = cursor_.x();
1442 // cursor.x(getCellXPos(actcell) + offset);
1443 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1444 (tabular->getWidthOfTabular() < bv->workWidth()-20))
1447 updateLocal(bv, FULL);
1448 } else if (the_locking_inset &&
1449 (tabular->getWidthOfColumn(actcell) > bv->workWidth()-20))
1451 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1452 if (xx > (bv->workWidth()-20)) {
1453 scroll(bv, -(xx - bv->workWidth() + 60));
1454 updateLocal(bv, FULL);
1455 } else if (xx < 20) {
1461 updateLocal(bv, FULL);
1463 } else if ((cursor_.x() - offset) > 20 &&
1464 (cursor_.x() - offset + tabular->getWidthOfColumn(actcell))
1465 > (bv->workWidth() - 20)) {
1466 scroll(bv, -tabular->getWidthOfColumn(actcell) - 20);
1467 updateLocal(bv, FULL);
1468 } else if ((cursor_.x() - offset) < 20) {
1469 scroll(bv, 20 - cursor_.x() + offset);
1470 updateLocal(bv, FULL);
1471 } else if (scroll() && top_x > 20 &&
1472 (top_x + tabular->getWidthOfTabular()) > (bv->workWidth() - 20)) {
1473 scroll(bv, old_x - cursor_.x());
1474 updateLocal(bv, FULL);
1476 if (the_locking_inset) {
1477 inset_x = cursor_.x() - top_x + tabular->getBeginningOfTextInCell(actcell);
1478 inset_y = cursor_.y();
1480 if ((!the_locking_inset ||
1481 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1482 actcell != oldcell) {
1483 InsetTabular * inset = const_cast<InsetTabular *>(this);
1484 InsetTabularMailer mailer(*inset);
1485 mailer.updateDialog(bv);
1492 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1494 if (lock && !old_locking_inset) {
1495 if (activateCellInset(bv))
1498 bool moved = isRightToLeft(bv)
1499 ? movePrevCell(bv) : moveNextCell(bv);
1501 return FINISHED_RIGHT;
1502 if (lock && activateCellInset(bv))
1506 return DISPATCHED_NOUPDATE;
1510 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1512 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1515 if (lock) { // behind the inset
1516 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1520 return DISPATCHED_NOUPDATE;
1524 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1526 int const ocell = actcell;
1527 actcell = tabular->getCellAbove(actcell);
1528 if (actcell == ocell) // we moved out of the inset
1534 if (old_locking_inset) {
1535 old_locking_inset->getCursorPos(bv, x, y);
1536 x -= cursor_.x() + tabular->getBeginningOfTextInCell(actcell);
1538 if (activateCellInset(bv, x, 0))
1541 return DISPATCHED_NOUPDATE;
1545 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1547 int const ocell = actcell;
1548 actcell = tabular->getCellBelow(actcell);
1549 if (actcell == ocell) // we moved out of the inset
1550 return FINISHED_DOWN;
1555 if (old_locking_inset) {
1556 old_locking_inset->getCursorPos(bv, x, y);
1557 x -= cursor_.x() + tabular->getBeginningOfTextInCell(actcell);
1559 if (activateCellInset(bv, x, 0))
1562 return DISPATCHED_NOUPDATE;
1566 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1568 if (isRightToLeft(bv)) {
1569 if (tabular->isFirstCellInRow(actcell)) {
1570 int row = tabular->row_of_cell(actcell);
1571 if (row == tabular->rows() - 1)
1573 actcell = tabular->getLastCellInRow(row);
1574 actcell = tabular->getCellBelow(actcell);
1581 if (tabular->isLastCell(actcell))
1586 bool rtl = tabular->getCellInset(actcell)->paragraphs.begin()->
1587 isRightToLeftPar(bv->buffer()->params);
1588 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1595 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1597 if (isRightToLeft(bv)) {
1598 if (tabular->isLastCellInRow(actcell)) {
1599 int row = tabular->row_of_cell(actcell);
1602 actcell = tabular->getFirstCellInRow(row);
1603 actcell = tabular->getCellAbove(actcell);
1605 if (tabular->isLastCell(actcell))
1610 if (!actcell) // first cell
1615 bool rtl = tabular->getCellInset(actcell)->paragraphs.begin()->
1616 isRightToLeftPar(bv->buffer()->params);
1617 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1624 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1628 setSelection(0, tabular->getNumberOfCells() - 1);
1630 if (hasSelection()) {
1631 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1632 bool const frozen = undo_frozen;
1635 // apply the fontchange on the whole selection
1640 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1641 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1642 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1643 tabular->getCellInset(i, j)->setFont(bv, font, tall, true);
1650 updateLocal(bv, INIT);
1652 if (the_locking_inset)
1653 the_locking_inset->setFont(bv, font, tall);
1657 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1659 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1662 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1663 string const tmp = tabularFeature[i].feature;
1665 if (tmp == what.substr(0, tmp.length())) {
1666 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1667 //tabularFeatures[i].feature.length())) {
1668 action = tabularFeature[i].action;
1672 if (action == LyXTabular::LAST_ACTION)
1676 ltrim(what.substr(tabularFeature[i].feature.length()));
1677 tabularFeatures(bv, action, val);
1683 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1684 string const & special, bool & flag)
1686 if (special == "dl_above") {
1689 } else if (special == "dl_below") {
1690 ltt.bottomDL = flag;
1692 } else if (special == "empty") {
1704 void InsetTabular::tabularFeatures(BufferView * bv,
1705 LyXTabular::Feature feature,
1706 string const & value)
1712 bool setLines = false;
1713 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1714 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1717 case LyXTabular::M_ALIGN_LEFT:
1718 case LyXTabular::ALIGN_LEFT:
1719 setAlign = LYX_ALIGN_LEFT;
1721 case LyXTabular::M_ALIGN_RIGHT:
1722 case LyXTabular::ALIGN_RIGHT:
1723 setAlign = LYX_ALIGN_RIGHT;
1725 case LyXTabular::M_ALIGN_CENTER:
1726 case LyXTabular::ALIGN_CENTER:
1727 setAlign = LYX_ALIGN_CENTER;
1729 case LyXTabular::ALIGN_BLOCK:
1730 setAlign = LYX_ALIGN_BLOCK;
1732 case LyXTabular::M_VALIGN_TOP:
1733 case LyXTabular::VALIGN_TOP:
1734 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1736 case LyXTabular::M_VALIGN_BOTTOM:
1737 case LyXTabular::VALIGN_BOTTOM:
1738 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1740 case LyXTabular::M_VALIGN_CENTER:
1741 case LyXTabular::VALIGN_CENTER:
1742 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1747 if (hasSelection()) {
1748 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1750 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1751 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1753 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1755 int row = tabular->row_of_cell(actcell);
1756 int column = tabular->column_of_cell(actcell);
1758 LyXTabular::ltType ltt;
1761 case LyXTabular::SET_PWIDTH:
1763 LyXLength const vallen(value);
1764 LyXLength const & tmplen = tabular->getColumnPWidth(actcell);
1766 bool const update = (tmplen != vallen);
1767 tabular->setColumnPWidth(actcell, vallen);
1769 // We need this otherwise we won't resize
1770 // the insettext of the active cell (if any)
1771 // until later (see InsetText::do_resize)
1772 unlockInsetInInset(bv, the_locking_inset);
1775 for (int i = 0; i < tabular->rows(); ++i) {
1776 cell = tabular->getCellNumber(i,column);
1777 tabular->getCellInset(cell)->resizeLyXText(bv);
1779 updateLocal(bv, INIT);
1783 && tabular->getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1784 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1785 else if (!vallen.zero()
1786 && tabular->getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1787 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1790 case LyXTabular::SET_MPWIDTH:
1792 LyXLength const vallen(value);
1793 LyXLength const & tmplen = tabular->getPWidth(actcell);
1795 bool const update = (tmplen != vallen);
1796 tabular->setMColumnPWidth(actcell, vallen);
1798 // We need this otherwise we won't resize
1799 // the insettext of the active cell (if any)
1800 // until later (see InsetText::do_resize)
1801 unlockInsetInInset(bv, the_locking_inset);
1803 for (int i = 0; i < tabular->rows(); ++i) {
1804 tabular->getCellInset(tabular->getCellNumber(i, column))->
1807 updateLocal(bv, INIT);
1811 case LyXTabular::SET_SPECIAL_COLUMN:
1812 case LyXTabular::SET_SPECIAL_MULTI:
1813 tabular->setAlignSpecial(actcell,value,feature);
1814 updateLocal(bv, FULL);
1816 case LyXTabular::APPEND_ROW:
1817 // append the row into the tabular
1818 unlockInsetInInset(bv, the_locking_inset);
1819 tabular->appendRow(bv->buffer()->params, actcell);
1820 updateLocal(bv, INIT);
1822 case LyXTabular::APPEND_COLUMN:
1823 // append the column into the tabular
1824 unlockInsetInInset(bv, the_locking_inset);
1825 tabular->appendColumn(bv->buffer()->params, actcell);
1826 actcell = tabular->getCellNumber(row, column);
1827 updateLocal(bv, INIT);
1829 case LyXTabular::DELETE_ROW:
1830 unlockInsetInInset(bv, the_locking_inset);
1831 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1832 tabular->deleteRow(sel_row_start);
1834 if (sel_row_start >= tabular->rows())
1836 actcell = tabular->getCellNumber(sel_row_start, column);
1838 updateLocal(bv, INIT);
1840 case LyXTabular::DELETE_COLUMN:
1841 unlockInsetInInset(bv, the_locking_inset);
1842 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1843 tabular->deleteColumn(sel_col_start);
1845 if (sel_col_start >= tabular->columns())
1847 actcell = tabular->getCellNumber(row, sel_col_start);
1849 updateLocal(bv, INIT);
1851 case LyXTabular::M_TOGGLE_LINE_TOP:
1853 case LyXTabular::TOGGLE_LINE_TOP:
1855 bool lineSet = !tabular->topLine(actcell, flag);
1856 for (int i = sel_row_start; i <= sel_row_end; ++i)
1857 for (int j = sel_col_start; j <= sel_col_end; ++j)
1858 tabular->setTopLine(
1859 tabular->getCellNumber(i, j),
1861 updateLocal(bv, INIT);
1865 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1867 case LyXTabular::TOGGLE_LINE_BOTTOM:
1869 bool lineSet = !tabular->bottomLine(actcell, flag);
1870 for (int i = sel_row_start; i <= sel_row_end; ++i)
1871 for (int j = sel_col_start; j <= sel_col_end; ++j)
1872 tabular->setBottomLine(
1873 tabular->getCellNumber(i, j),
1876 updateLocal(bv, INIT);
1880 case LyXTabular::M_TOGGLE_LINE_LEFT:
1882 case LyXTabular::TOGGLE_LINE_LEFT:
1884 bool lineSet = !tabular->leftLine(actcell, flag);
1885 for (int i = sel_row_start; i <= sel_row_end; ++i)
1886 for (int j = sel_col_start; j <= sel_col_end; ++j)
1887 tabular->setLeftLine(
1888 tabular->getCellNumber(i,j),
1891 updateLocal(bv, INIT);
1895 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1897 case LyXTabular::TOGGLE_LINE_RIGHT:
1899 bool lineSet = !tabular->rightLine(actcell, flag);
1900 for (int i = sel_row_start; i <= sel_row_end; ++i)
1901 for (int j = sel_col_start; j <= sel_col_end; ++j)
1902 tabular->setRightLine(
1903 tabular->getCellNumber(i,j),
1906 updateLocal(bv, INIT);
1910 case LyXTabular::M_ALIGN_LEFT:
1911 case LyXTabular::M_ALIGN_RIGHT:
1912 case LyXTabular::M_ALIGN_CENTER:
1914 case LyXTabular::ALIGN_LEFT:
1915 case LyXTabular::ALIGN_RIGHT:
1916 case LyXTabular::ALIGN_CENTER:
1917 case LyXTabular::ALIGN_BLOCK:
1918 for (int i = sel_row_start; i <= sel_row_end; ++i)
1919 for (int j = sel_col_start; j <= sel_col_end; ++j)
1920 tabular->setAlignment(
1921 tabular->getCellNumber(i, j),
1924 updateLocal(bv, INIT);
1926 case LyXTabular::M_VALIGN_TOP:
1927 case LyXTabular::M_VALIGN_BOTTOM:
1928 case LyXTabular::M_VALIGN_CENTER:
1930 case LyXTabular::VALIGN_TOP:
1931 case LyXTabular::VALIGN_BOTTOM:
1932 case LyXTabular::VALIGN_CENTER:
1933 for (int i = sel_row_start; i <= sel_row_end; ++i)
1934 for (int j = sel_col_start; j <= sel_col_end; ++j)
1935 tabular->setVAlignment(
1936 tabular->getCellNumber(i, j),
1938 updateLocal(bv, INIT);
1940 case LyXTabular::MULTICOLUMN:
1942 if (sel_row_start != sel_row_end) {
1943 #ifdef WITH_WARNINGS
1944 #warning Need I say it ? This is horrible.
1946 Alert::error(_("Error setting multicolumn"),
1947 _("You cannot set multicolumn vertically."));
1950 // just multicol for one Single Cell
1951 if (!hasSelection()) {
1952 // check wether we are completly in a multicol
1953 if (tabular->isMultiColumn(actcell)) {
1954 tabular->unsetMultiColumn(actcell);
1955 updateLocal(bv, INIT);
1957 tabular->setMultiColumn(bv->buffer(), actcell, 1);
1958 updateLocal(bv, CELL);
1962 // we have a selection so this means we just add all this
1963 // cells to form a multicolumn cell
1967 if (sel_cell_start > sel_cell_end) {
1968 s_start = sel_cell_end;
1969 s_end = sel_cell_start;
1971 s_start = sel_cell_start;
1972 s_end = sel_cell_end;
1974 tabular->setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1977 updateLocal(bv, INIT);
1980 case LyXTabular::SET_ALL_LINES:
1982 case LyXTabular::UNSET_ALL_LINES:
1983 for (int i = sel_row_start; i <= sel_row_end; ++i)
1984 for (int j = sel_col_start; j <= sel_col_end; ++j)
1985 tabular->setAllLines(
1986 tabular->getCellNumber(i,j), setLines);
1987 updateLocal(bv, INIT);
1989 case LyXTabular::SET_LONGTABULAR:
1990 tabular->setLongTabular(true);
1991 updateLocal(bv, INIT); // because this toggles displayed
1993 case LyXTabular::UNSET_LONGTABULAR:
1994 tabular->setLongTabular(false);
1995 updateLocal(bv, INIT); // because this toggles displayed
1997 case LyXTabular::SET_ROTATE_TABULAR:
1998 tabular->setRotateTabular(true);
2000 case LyXTabular::UNSET_ROTATE_TABULAR:
2001 tabular->setRotateTabular(false);
2003 case LyXTabular::SET_ROTATE_CELL:
2004 for (int i = sel_row_start; i <= sel_row_end; ++i)
2005 for (int j = sel_col_start; j<=sel_col_end; ++j)
2006 tabular->setRotateCell(
2007 tabular->getCellNumber(i, j),
2010 case LyXTabular::UNSET_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), false);
2016 case LyXTabular::SET_USEBOX:
2018 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2019 if (val == tabular->getUsebox(actcell))
2020 val = LyXTabular::BOX_NONE;
2021 for (int i = sel_row_start; i <= sel_row_end; ++i)
2022 for (int j = sel_col_start; j <= sel_col_end; ++j)
2024 tabular->getCellNumber(i, j), val);
2027 case LyXTabular::UNSET_LTFIRSTHEAD:
2029 case LyXTabular::SET_LTFIRSTHEAD:
2030 (void)tabular->getRowOfLTFirstHead(row, ltt);
2031 checkLongtableSpecial(ltt, value, flag);
2032 tabular->setLTHead(row, flag, ltt, true);
2034 case LyXTabular::UNSET_LTHEAD:
2036 case LyXTabular::SET_LTHEAD:
2037 (void)tabular->getRowOfLTHead(row, ltt);
2038 checkLongtableSpecial(ltt, value, flag);
2039 tabular->setLTHead(row, flag, ltt, false);
2041 case LyXTabular::UNSET_LTFOOT:
2043 case LyXTabular::SET_LTFOOT:
2044 (void)tabular->getRowOfLTFoot(row, ltt);
2045 checkLongtableSpecial(ltt, value, flag);
2046 tabular->setLTFoot(row, flag, ltt, false);
2048 case LyXTabular::UNSET_LTLASTFOOT:
2050 case LyXTabular::SET_LTLASTFOOT:
2051 (void)tabular->getRowOfLTLastFoot(row, ltt);
2052 checkLongtableSpecial(ltt, value, flag);
2053 tabular->setLTFoot(row, flag, ltt, true);
2055 case LyXTabular::SET_LTNEWPAGE:
2057 bool what = !tabular->getLTNewPage(row);
2058 tabular->setLTNewPage(row, what);
2061 // dummy stuff just to avoid warnings
2062 case LyXTabular::LAST_ACTION:
2066 InsetTabularMailer mailer(*this);
2067 mailer.updateDialog(bv);
2071 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2074 UpdatableInset * inset =
2075 static_cast<UpdatableInset*>(tabular->getCellInset(actcell));
2076 LyXFont font(LyXFont::ALL_SANE);
2078 x = inset->x() + inset->width(bv, font);
2079 y = inset->descent(bv, font);
2081 //inset_x = cursor.x() - top_x + tabular->getBeginningOfTextInCell(actcell);
2082 //inset_y = cursor.y();
2083 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2084 if (!the_locking_inset)
2086 updateLocal(bv, CELL);
2087 return (the_locking_inset != 0);
2091 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2092 mouse_button::state button)
2094 inset_x = cursor_.x()
2095 - top_x + tabular->getBeginningOfTextInCell(actcell);
2096 inset_y = cursor_.y();
2097 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2101 bool InsetTabular::insetHit(BufferView *, int x, int) const
2104 > (cursor_.x() + tabular->getBeginningOfTextInCell(actcell));
2108 // This returns paperWidth() if the cell-width is unlimited or the width
2109 // in pixels if we have a pwidth for this cell.
2110 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2112 LyXLength const len = tabular->getPWidth(cell);
2116 return len.inPixels(latexTextWidth(bv));
2120 int InsetTabular::getMaxWidth(BufferView * bv,
2121 UpdatableInset const * inset) const
2123 int cell = tabular->getCellFromInset(inset, actcell);
2126 lyxerr << "Own inset not found, shouldn't really happen!"
2131 int w = getMaxWidthOfCell(bv, cell);
2133 // because the inset then subtracts it's top_x and owner->x()
2134 w += (inset->x() - top_x);
2141 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2143 resizeLyXText(bv, recursive);
2147 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2150 for(int i = 0; i < tabular->rows(); ++i) {
2151 for(int j = 0; j < tabular->columns(); ++j) {
2152 tabular->getCellInset(i, j)->resizeLyXText(bv, true);
2160 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2161 bool const recursive) const
2163 if (the_locking_inset)
2164 return the_locking_inset->getLyXText(bv, recursive);
2166 // if we're locked lock the actual insettext and return it's LyXText!!!
2168 UpdatableInset * inset =
2169 static_cast<UpdatableInset*>(tabular->getCellInset(actcell));
2170 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2171 return the_locking_inset->getLyXText(bv, recursive);
2174 return Inset::getLyXText(bv, recursive);
2178 bool InsetTabular::showInsetDialog(BufferView * bv) const
2180 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2181 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2182 InsetTabularMailer mailer(*tmp);
2183 mailer.showDialog(bv);
2189 void InsetTabular::openLayoutDialog(BufferView * bv) const
2191 if (the_locking_inset) {
2192 InsetTabular * i = static_cast<InsetTabular *>
2193 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2195 i->openLayoutDialog(bv);
2199 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2200 InsetTabularMailer mailer(*tmp);
2201 mailer.showDialog(bv);
2206 // function returns an object as defined in func_status.h:
2207 // states OK, Unknown, Disabled, On, Off.
2209 FuncStatus InsetTabular::getStatus(string const & what) const
2211 int action = LyXTabular::LAST_ACTION;
2215 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2216 string const tmp = tabularFeature[i].feature;
2217 if (tmp == what.substr(0, tmp.length())) {
2218 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2219 // tabularFeatures[i].feature.length())) {
2220 action = tabularFeature[i].action;
2224 if (action == LyXTabular::LAST_ACTION) {
2226 return status.unknown(true);
2229 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2234 LyXTabular::ltType dummyltt;
2237 if (hasSelection()) {
2238 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2240 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2244 case LyXTabular::SET_PWIDTH:
2245 case LyXTabular::SET_MPWIDTH:
2246 case LyXTabular::SET_SPECIAL_COLUMN:
2247 case LyXTabular::SET_SPECIAL_MULTI:
2248 case LyXTabular::APPEND_ROW:
2249 case LyXTabular::APPEND_COLUMN:
2250 case LyXTabular::DELETE_ROW:
2251 case LyXTabular::DELETE_COLUMN:
2252 case LyXTabular::SET_ALL_LINES:
2253 case LyXTabular::UNSET_ALL_LINES:
2254 return status.clear();
2256 case LyXTabular::MULTICOLUMN:
2257 status.setOnOff(tabular->isMultiColumn(actcell));
2259 case LyXTabular::M_TOGGLE_LINE_TOP:
2261 case LyXTabular::TOGGLE_LINE_TOP:
2262 status.setOnOff(tabular->topLine(actcell, flag));
2264 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2266 case LyXTabular::TOGGLE_LINE_BOTTOM:
2267 status.setOnOff(tabular->bottomLine(actcell, flag));
2269 case LyXTabular::M_TOGGLE_LINE_LEFT:
2271 case LyXTabular::TOGGLE_LINE_LEFT:
2272 status.setOnOff(tabular->leftLine(actcell, flag));
2274 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2276 case LyXTabular::TOGGLE_LINE_RIGHT:
2277 status.setOnOff(tabular->rightLine(actcell, flag));
2279 case LyXTabular::M_ALIGN_LEFT:
2281 case LyXTabular::ALIGN_LEFT:
2282 status.setOnOff(tabular->getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2284 case LyXTabular::M_ALIGN_RIGHT:
2286 case LyXTabular::ALIGN_RIGHT:
2287 status.setOnOff(tabular->getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2289 case LyXTabular::M_ALIGN_CENTER:
2291 case LyXTabular::ALIGN_CENTER:
2292 status.setOnOff(tabular->getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2294 case LyXTabular::ALIGN_BLOCK:
2295 status.disabled(tabular->getPWidth(actcell).zero());
2296 status.setOnOff(tabular->getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2298 case LyXTabular::M_VALIGN_TOP:
2300 case LyXTabular::VALIGN_TOP:
2301 status.setOnOff(tabular->getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2303 case LyXTabular::M_VALIGN_BOTTOM:
2305 case LyXTabular::VALIGN_BOTTOM:
2306 status.setOnOff(tabular->getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2308 case LyXTabular::M_VALIGN_CENTER:
2310 case LyXTabular::VALIGN_CENTER:
2311 status.setOnOff(tabular->getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2313 case LyXTabular::SET_LONGTABULAR:
2314 status.setOnOff(tabular->isLongTabular());
2316 case LyXTabular::UNSET_LONGTABULAR:
2317 status.setOnOff(!tabular->isLongTabular());
2319 case LyXTabular::SET_ROTATE_TABULAR:
2320 status.setOnOff(tabular->getRotateTabular());
2322 case LyXTabular::UNSET_ROTATE_TABULAR:
2323 status.setOnOff(!tabular->getRotateTabular());
2325 case LyXTabular::SET_ROTATE_CELL:
2326 status.setOnOff(tabular->getRotateCell(actcell));
2328 case LyXTabular::UNSET_ROTATE_CELL:
2329 status.setOnOff(!tabular->getRotateCell(actcell));
2331 case LyXTabular::SET_USEBOX:
2332 status.setOnOff(strToInt(argument) == tabular->getUsebox(actcell));
2334 case LyXTabular::SET_LTFIRSTHEAD:
2335 status.setOnOff(tabular->getRowOfLTHead(sel_row_start, dummyltt));
2337 case LyXTabular::SET_LTHEAD:
2338 status.setOnOff(tabular->getRowOfLTHead(sel_row_start, dummyltt));
2340 case LyXTabular::SET_LTFOOT:
2341 status.setOnOff(tabular->getRowOfLTFoot(sel_row_start, dummyltt));
2343 case LyXTabular::SET_LTLASTFOOT:
2344 status.setOnOff(tabular->getRowOfLTFoot(sel_row_start, dummyltt));
2346 case LyXTabular::SET_LTNEWPAGE:
2347 status.setOnOff(tabular->getLTNewPage(sel_row_start));
2351 status.disabled(true);
2358 vector<string> const InsetTabular::getLabelList() const
2360 return tabular->getLabelList();
2364 bool InsetTabular::copySelection(BufferView * bv)
2366 if (!hasSelection())
2369 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2370 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2371 if (sel_col_start > sel_col_end) {
2372 sel_col_start = sel_col_end;
2373 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2375 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2377 int const columns = sel_col_end - sel_col_start + 1;
2379 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2380 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2381 if (sel_row_start > sel_row_end) {
2382 swap(sel_row_start, sel_row_end);
2384 int const rows = sel_row_end - sel_row_start + 1;
2386 delete paste_tabular;
2387 paste_tabular = new LyXTabular(bv->buffer()->params,
2388 this, *tabular); // rows, columns);
2389 for (int i = 0; i < sel_row_start; ++i)
2390 paste_tabular->deleteRow(0);
2391 while (paste_tabular->rows() > rows)
2392 paste_tabular->deleteRow(rows);
2393 paste_tabular->setTopLine(0, true, true);
2394 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2396 for (int i = 0; i < sel_col_start; ++i)
2397 paste_tabular->deleteColumn(0);
2398 while (paste_tabular->columns() > columns)
2399 paste_tabular->deleteColumn(columns);
2400 paste_tabular->setLeftLine(0, true, true);
2401 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2405 paste_tabular->ascii(bv->buffer(), sstr,
2406 (int)parOwner()->params().depth(), true, '\t');
2407 bv->stuffClipboard(STRCONV(sstr.str()));
2412 bool InsetTabular::pasteSelection(BufferView * bv)
2417 for (int r1 = 0, r2 = actrow;
2418 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2420 for(int c1 = 0, c2 = actcol;
2421 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2423 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2424 tabular->isPartOfMultiColumn(r2,c2))
2426 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2430 if (tabular->isPartOfMultiColumn(r2,c2)) {
2434 int const n1 = paste_tabular->getCellNumber(r1, c1);
2435 int const n2 = tabular->getCellNumber(r2, c2);
2436 *(tabular->getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2437 tabular->getCellInset(n2)->setOwner(this);
2438 tabular->getCellInset(n2)->deleteLyXText(bv);
2439 tabular->getCellInset(n2)->markNew();
2446 bool InsetTabular::cutSelection(BufferParams const & bp)
2448 if (!hasSelection())
2451 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2452 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2453 if (sel_col_start > sel_col_end) {
2454 sel_col_start = sel_col_end;
2455 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2457 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2459 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2460 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2461 if (sel_row_start > sel_row_end) {
2462 swap(sel_row_start, sel_row_end);
2464 if (sel_cell_start > sel_cell_end) {
2465 swap(sel_cell_start, sel_cell_end);
2467 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2468 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2469 tabular->getCellInset(tabular->getCellNumber(i, j))->clear(bp.tracking_changes);
2476 bool InsetTabular::isRightToLeft(BufferView * bv)
2478 return bv->getParentLanguage(this)->RightToLeft();
2482 bool InsetTabular::nodraw() const
2484 if (!UpdatableInset::nodraw() && the_locking_inset)
2485 return the_locking_inset->nodraw();
2486 return UpdatableInset::nodraw();
2490 int InsetTabular::scroll(bool recursive) const
2492 int sx = UpdatableInset::scroll(false);
2494 if (recursive && the_locking_inset)
2495 sx += the_locking_inset->scroll(recursive);
2501 void InsetTabular::getSelection(int & srow, int & erow,
2502 int & scol, int & ecol) const
2504 int const start = hasSelection() ? sel_cell_start : actcell;
2505 int const end = hasSelection() ? sel_cell_end : actcell;
2507 srow = tabular->row_of_cell(start);
2508 erow = tabular->row_of_cell(end);
2513 scol = tabular->column_of_cell(start);
2514 ecol = tabular->column_of_cell(end);
2518 ecol = tabular->right_column_of_cell(end);
2523 ParagraphList * InsetTabular::getParagraphs(int i) const
2525 return (i < tabular->getNumberOfCells())
2526 ? tabular->getCellInset(i)->getParagraphs(0)
2531 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2533 if (the_locking_inset)
2534 return the_locking_inset->cursor(bv);
2535 return Inset::cursor(bv);
2539 Inset * InsetTabular::getInsetFromID(int id_arg) const
2542 return const_cast<InsetTabular *>(this);
2545 for(int i = 0; i < tabular->rows(); ++i) {
2546 for(int j = 0; j < tabular->columns(); ++j) {
2547 if ((result = tabular->getCellInset(i, j)->getInsetFromID(id_arg)))
2556 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2559 if (the_locking_inset) {
2560 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2561 if (!word.word().empty()) {
2565 if (tabular->isLastCell(actcell)) {
2566 bv->unlockInset(const_cast<InsetTabular *>(this));
2568 return WordLangTuple();
2572 // otherwise we have to lock the next inset and ask for it's selecttion
2573 UpdatableInset * inset =
2574 static_cast<UpdatableInset*>(tabular->getCellInset(actcell));
2575 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2576 WordLangTuple word(selectNextWordInt(bv, value));
2578 if (!word.word().empty())
2584 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2586 // when entering this function the inset should be ALWAYS locked!
2587 lyx::Assert(the_locking_inset);
2589 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2590 if (!word.word().empty())
2593 if (tabular->isLastCell(actcell)) {
2594 bv->unlockInset(const_cast<InsetTabular *>(this));
2595 return WordLangTuple();
2598 // otherwise we have to lock the next inset and ask for it's selecttion
2599 UpdatableInset * inset =
2600 static_cast<UpdatableInset*>(tabular->getCellInset(++actcell));
2601 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2602 return selectNextWordInt(bv, value);
2606 void InsetTabular::selectSelectedWord(BufferView * bv)
2608 if (the_locking_inset) {
2609 the_locking_inset->selectSelectedWord(bv);
2616 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2618 if (the_locking_inset) {
2619 the_locking_inset->toggleSelection(bv, kill_selection);
2624 void InsetTabular::markErased()
2628 while (cell < tabular->getNumberOfCells()) {
2629 InsetText * inset = tabular->getCellInset(cell);
2630 inset->markErased();
2636 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2638 if (the_locking_inset) {
2639 if (the_locking_inset->nextChange(bv, length)) {
2640 updateLocal(bv, CELL);
2643 if (tabular->isLastCell(actcell))
2647 InsetText * inset = tabular->getCellInset(actcell);
2648 if (inset->nextChange(bv, length)) {
2649 updateLocal(bv, FULL);
2652 while (!tabular->isLastCell(actcell)) {
2654 inset = tabular->getCellInset(actcell);
2655 if (inset->nextChange(bv, length)) {
2656 updateLocal(bv, FULL);
2664 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2668 if (the_locking_inset) {
2669 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2670 updateLocal(bv, CELL);
2673 if (tabular->isLastCell(actcell))
2677 InsetText * inset = tabular->getCellInset(cell);
2678 if (inset->searchForward(bv, str, cs, mw)) {
2679 updateLocal(bv, FULL);
2682 while (!tabular->isLastCell(cell)) {
2684 inset = tabular->getCellInset(cell);
2685 if (inset->searchForward(bv, str, cs, mw)) {
2686 updateLocal(bv, FULL);
2694 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2697 int cell = tabular->getNumberOfCells();
2698 if (the_locking_inset) {
2699 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2700 updateLocal(bv, CELL);
2708 InsetText * inset = tabular->getCellInset(cell);
2709 if (inset->searchBackward(bv, str, cs, mw)) {
2710 updateLocal(bv, CELL);
2718 bool InsetTabular::insetAllowed(Inset::Code code) const
2720 if (the_locking_inset)
2721 return the_locking_inset->insetAllowed(code);
2722 // we return true here because if the inset is not locked someone
2723 // wants to insert something in one of our insettexts and we generally
2729 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2731 const int cell = tabular->getCellFromInset(in, actcell);
2734 return tabular->getPWidth(cell).zero();
2736 // well we didn't obviously find it so maybe our owner knows more
2738 return owner()->forceDefaultParagraphs(in);
2739 // if we're here there is really something strange going on!!!
2743 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2746 if (buf.length() <= 0)
2752 string::size_type len = buf.length();
2753 string::size_type p = 0;
2756 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2765 maxCols = max(cols, maxCols);
2771 maxCols = max(cols, maxCols);
2772 LyXTabular * loctab;
2777 delete paste_tabular;
2778 paste_tabular = new LyXTabular(bv->buffer()->params,
2779 this, rows, maxCols);
2780 loctab = paste_tabular;
2783 loctab = tabular.get();
2789 string::size_type op = 0;
2790 int cells = loctab->getNumberOfCells();
2793 rows = loctab->rows();
2794 int const columns = loctab->columns();
2796 while ((cell < cells) && (p < len) && (row < rows) &&
2797 (p = buf.find_first_of("\t\n", p)) != string::npos)
2803 // we can only set this if we are not too far right
2804 if (cols < columns) {
2805 InsetText * ti = loctab->getCellInset(cell);
2806 LyXFont const font = ti->getLyXText(bv)->
2807 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2808 ti->setText(buf.substr(op, p - op), font);
2814 // we can only set this if we are not too far right
2815 if (cols < columns) {
2816 InsetText * ti = loctab->getCellInset(cell);
2817 LyXFont const font = ti->getLyXText(bv)->
2818 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2819 ti->setText(buf.substr(op, p - op), font);
2824 cell = loctab->getCellNumber(row, cols);
2830 // check for the last cell if there is no trailing '\n'
2831 if ((cell < cells) && (op < len)) {
2832 InsetText * ti = loctab->getCellInset(cell);
2833 LyXFont const font = ti->getLyXText(bv)->
2834 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2835 ti->setText(buf.substr(op, len - op), font);
2842 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2844 int const rows = tabular->rows();
2845 int const columns = tabular->columns();
2846 for (int i = 0; i < rows; ++i) {
2847 for (int j = 0; j < columns; ++j) {
2848 tabular->getCellInset(i,j)->addPreview(loader);
2854 string const InsetTabularMailer:: name_("tabular");
2856 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2861 string const InsetTabularMailer::inset2string() const
2863 return params2string(inset_);
2867 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2869 istringstream data(STRCONV(in));
2871 lex.setStream(data);
2873 #warning CHECK verify that this is a sane value to return.
2879 string const token = lex.getString();
2887 string const token = lex.getString();
2888 if (token != "\\active_cell")
2891 cell = lex.getInteger();
2894 // This is part of the inset proper that is usually swallowed
2895 // by Buffer::readInset
2898 string const token = lex.getString();
2899 if (token != "Tabular")
2906 // FIXME: even current_view would be better than this.
2907 BufferView * const bv = inset.view();
2908 Buffer const * const buffer = bv ? bv->buffer() : 0;
2910 inset.read(buffer, lex);
2912 // We can't set the active cell, but we can tell the frontend
2918 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2920 // FIXME: even current_view would be better than this.
2921 BufferView * const bv = inset.view();
2922 Buffer const * const buffer = bv ? bv->buffer() : 0;
2927 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2928 inset.write(buffer, data);
2929 data << "\\end_inset\n";
2930 return STRCONV(data.str());