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"
52 using namespace lyx::support;
64 int const ADD_TO_HEIGHT = 2;
65 int const ADD_TO_TABULAR_WIDTH = 2;
68 LyXTabular * paste_tabular = 0;
71 struct TabularFeature {
72 LyXTabular::Feature action;
77 TabularFeature tabularFeature[] =
79 { LyXTabular::APPEND_ROW, "append-row" },
80 { LyXTabular::APPEND_COLUMN, "append-column" },
81 { LyXTabular::DELETE_ROW, "delete-row" },
82 { LyXTabular::DELETE_COLUMN, "delete-column" },
83 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
84 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
85 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
86 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
87 { LyXTabular::ALIGN_LEFT, "align-left" },
88 { LyXTabular::ALIGN_RIGHT, "align-right" },
89 { LyXTabular::ALIGN_CENTER, "align-center" },
90 { LyXTabular::ALIGN_BLOCK, "align-block" },
91 { LyXTabular::VALIGN_TOP, "valign-top" },
92 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
93 { LyXTabular::VALIGN_CENTER, "valign-center" },
94 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
95 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
96 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
97 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
98 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
99 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
100 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
101 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
102 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
103 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
104 { LyXTabular::MULTICOLUMN, "multicolumn" },
105 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
106 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
107 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
108 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
109 { LyXTabular::SET_PWIDTH, "set-pwidth" },
110 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
111 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
112 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
113 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
114 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
115 { LyXTabular::SET_USEBOX, "set-usebox" },
116 { LyXTabular::SET_LTHEAD, "set-lthead" },
117 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
118 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
119 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
120 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
121 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
122 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
123 { LyXTabular::LAST_ACTION, "" }
127 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
128 bool operator()(TabularFeature & tf)
130 return tf.action == feature_;
133 LyXTabular::Feature feature_;
139 string const featureAsString(LyXTabular::Feature feature)
141 TabularFeature * it = tabularFeature;
142 TabularFeature * end = it +
143 sizeof(tabularFeature) / sizeof(TabularFeature);
144 it = std::find_if(it, end, FindFeature(feature));
145 return (it == end) ? string() : it->feature;
149 bool InsetTabular::hasPasteBuffer() const
151 return (paste_tabular != 0);
155 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
156 : tabular(buf.params, this, max(rows, 1), max(columns, 1)),
159 // for now make it always display as display() inset
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
175 InsetTabular::InsetTabular(InsetTabular const & tab)
176 : UpdatableInset(tab),
177 tabular(tab.buffer_->params, this, tab.tabular),
180 the_locking_inset = 0;
181 old_locking_inset = 0;
184 actrow = actcell = 0;
194 InsetTabular::~InsetTabular()
196 InsetTabularMailer mailer(*this);
201 InsetBase * InsetTabular::clone() const
203 return new InsetTabular(*this);
207 BufferView * InsetTabular::view() const
209 return buffer_->getUser();
213 void InsetTabular::buffer(Buffer * b)
219 void InsetTabular::write(Buffer const * buf, ostream & os) const
221 os << " Tabular" << endl;
222 tabular.write(buf, os);
226 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
228 bool const old_format = (lex.getString() == "\\LyXTable");
230 tabular.read(buf, lex);
238 string token = lex.getString();
239 while (lex.isOK() && (token != "\\end_inset")) {
241 token = lex.getString();
243 if (token != "\\end_inset") {
244 lex.printError("Missing \\end_inset at this point. "
250 void InsetTabular::metrics(MetricsInfo &,
251 Dimension & dim) const
253 dim.asc = tabular.getAscentOfRow(0);
254 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
255 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
259 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
266 BufferView * bv = pi.base.bv;
272 UpdatableInset::draw(pi, x, y);
280 x += ADD_TO_TABULAR_WIDTH;
284 first_visible_cell = -1;
285 for (i = 0; i < tabular.rows(); ++i) {
287 cell = tabular.getCellNumber(i, 0);
288 if (!((y + tabular.getDescentOfRow(i)) > 0) &&
289 (y - tabular.getAscentOfRow(i)) < pi.pain.paperHeight())
291 y += tabular.getDescentOfRow(i) +
292 tabular.getAscentOfRow(i + 1) +
293 tabular.getAdditionalHeight(i + 1);
296 for (j = 0; j < tabular.columns(); ++j) {
297 if (nx > bv->workWidth())
299 if (tabular.isPartOfMultiColumn(i, j))
301 cx = nx + tabular.getBeginningOfTextInCell(cell);
302 if (first_visible_cell < 0)
303 first_visible_cell = cell;
304 if (hasSelection()) {
305 drawCellSelection(pi.pain, nx, y, i, j, cell);
308 tabular.getCellInset(cell)->draw(pi, cx, y);
309 drawCellLines(pi.pain, nx, y, i, cell);
310 nx += tabular.getWidthOfColumn(cell);
314 // Would be nice, but for some completely unfathomable reason,
315 // on a col resize to a new fixed width, even though the insettexts
316 // are resized, the cell isn't, but drawing all cells in a tall table
317 // has the desired effect somehow. Complete dark magic.
319 // avoiding drawing the rest of a long table is
320 // a pretty big speedup
321 if (y > bv->workHeight())
325 y += tabular.getDescentOfRow(i) +
326 tabular.getAscentOfRow(i + 1) +
327 tabular.getAdditionalHeight(i + 1);
334 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
335 int row, int cell) const
337 int x2 = x + tabular.getWidthOfColumn(cell);
340 if (!tabular.topAlreadyDrawn(cell)) {
341 on_off = !tabular.topLine(cell);
342 pain.line(x, y - tabular.getAscentOfRow(row),
343 x2, y - tabular.getAscentOfRow(row),
344 on_off ? LColor::tabularonoffline : LColor::tabularline,
345 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 on_off = !tabular.bottomLine(cell);
348 pain.line(x, y + tabular.getDescentOfRow(row),
349 x2, y + tabular.getDescentOfRow(row),
350 on_off ? LColor::tabularonoffline : LColor::tabularline,
351 on_off ? Painter::line_onoffdash : Painter::line_solid);
352 if (!tabular.leftAlreadyDrawn(cell)) {
353 on_off = !tabular.leftLine(cell);
354 pain.line(x, y - tabular.getAscentOfRow(row),
355 x, y + tabular.getDescentOfRow(row),
356 on_off ? LColor::tabularonoffline : LColor::tabularline,
357 on_off ? Painter::line_onoffdash : Painter::line_solid);
359 on_off = !tabular.rightLine(cell);
360 pain.line(x2 - tabular.getAdditionalWidth(cell),
361 y - tabular.getAscentOfRow(row),
362 x2 - tabular.getAdditionalWidth(cell),
363 y + tabular.getDescentOfRow(row),
364 on_off ? LColor::tabularonoffline : LColor::tabularline,
365 on_off ? Painter::line_onoffdash : Painter::line_solid);
369 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
370 int row, int column, int cell) const
372 Assert(hasSelection());
373 int cs = tabular.column_of_cell(sel_cell_start);
374 int ce = tabular.column_of_cell(sel_cell_end);
377 cs = tabular.column_of_cell(sel_cell_end);
379 ce = tabular.right_column_of_cell(sel_cell_end);
382 int rs = tabular.row_of_cell(sel_cell_start);
383 int re = tabular.row_of_cell(sel_cell_end);
387 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
388 int w = tabular.getWidthOfColumn(cell);
389 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
390 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
391 w, h, LColor::selection);
396 void InsetTabular::update(BufferView * bv, bool reinit)
402 owner()->update(bv, true);
409 if (calculate_dimensions_of_cells(bv, true))
412 owner()->update(bv, true);
416 if (the_locking_inset)
417 the_locking_inset->update(bv, reinit);
418 if (need_update < FULL &&
419 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
424 switch (need_update) {
428 if (calculate_dimensions_of_cells(bv, false)) {
443 string const InsetTabular::editMessage() const
445 return _("Opened table");
449 void InsetTabular::insetUnlock(BufferView * bv)
451 if (the_locking_inset) {
452 the_locking_inset->insetUnlock(bv);
453 updateLocal(bv, CELL);
454 the_locking_inset = 0;
459 if (scroll(false) || hasSelection()) {
464 updateLocal(bv, FULL);
469 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
472 calculate_dimensions_of_cells(bv, true);
474 if (!locked && what == CELL)
476 if (need_update < what) // only set this if it has greater update
479 if (need_update != NONE) {
480 bv->updateInset(const_cast<InsetTabular *>(this));
487 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
489 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
494 if (inset == tabular.getCellInset(actcell)) {
495 lyxerr[Debug::INSETTEXT] << "OK" << endl;
496 the_locking_inset = tabular.getCellInset(actcell);
499 } else if (!the_locking_inset) {
500 int const n = tabular.getNumberOfCells();
501 int const id = inset->id();
502 for (int i = 0; i < n; ++i) {
503 InsetText * in = tabular.getCellInset(i);
506 the_locking_inset = in;
511 if (in->getInsetFromID(id)) {
513 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
514 return the_locking_inset->lockInsetInInset(bv, inset);
517 } else if (the_locking_inset && (the_locking_inset == inset)) {
518 lyxerr[Debug::INSETTEXT] << "OK" << endl;
520 } else if (the_locking_inset) {
521 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
522 return the_locking_inset->lockInsetInInset(bv, inset);
524 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
529 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
532 if (!the_locking_inset)
534 if (the_locking_inset == inset) {
535 the_locking_inset->insetUnlock(bv);
537 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
543 updateLocal(bv, CELL);
544 // this has to be here otherwise we don't redraw the cell!
545 the_locking_inset = 0;
548 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
549 if (inset->lyxCode() == TABULAR_CODE &&
550 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
551 InsetTabularMailer mailer(*this);
552 mailer.updateDialog(bv);
561 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
563 Inset * tl_inset = inset;
564 // look if this inset is really inside myself!
565 while(tl_inset->owner() && tl_inset->owner() != this)
566 tl_inset = tl_inset->owner();
567 // if we enter here it's not ower inset
568 if (!tl_inset->owner())
570 // we only have to do this if this is a subinset of our cells
571 if (tl_inset != inset) {
572 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
575 updateLocal(bv, CELL);
580 int InsetTabular::insetInInsetY() const
582 if (!the_locking_inset)
584 return inset_y + the_locking_inset->insetInInsetY();
588 UpdatableInset * InsetTabular::getLockingInset() const
590 return the_locking_inset ? the_locking_inset->getLockingInset() :
591 const_cast<InsetTabular *>(this);
595 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
599 if (the_locking_inset)
600 return the_locking_inset->getFirstLockingInsetOfType(c);
605 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
607 if (the_locking_inset)
608 return the_locking_inset->insertInset(bv, inset);
613 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
615 if (hasSelection() && cmd.button() == mouse_button::button3)
618 if (hasSelection()) {
620 updateLocal(cmd.view(), SELECTION);
623 int const ocell = actcell;
624 int const orow = actrow;
625 BufferView * bv = cmd.view();
629 the_locking_inset = 0;
633 setPos(bv, cmd.x, cmd.y);
635 updateLocal(bv, NONE);
638 if (cmd.button() == mouse_button::button3) {
639 if ((ocell != actcell) && the_locking_inset) {
640 the_locking_inset->insetUnlock(bv);
641 updateLocal(bv, CELL);
642 the_locking_inset = 0;
648 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
650 if ((ocell == actcell) && the_locking_inset && inset_hit) {
652 FuncRequest cmd1 = cmd;
655 the_locking_inset->localDispatch(cmd1);
659 if (the_locking_inset) {
660 the_locking_inset->insetUnlock(bv);
661 updateLocal(bv, CELL);
662 the_locking_inset = 0;
665 if (cmd.button() == mouse_button::button2) {
666 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
670 if (inset_hit && bv->theLockingInset()) {
671 if (!bv->lockInset(static_cast<UpdatableInset*>
672 (tabular.getCellInset(actcell))))
674 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
677 FuncRequest cmd1 = cmd;
680 the_locking_inset->localDispatch(cmd1);
686 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
689 if (the_locking_inset) {
690 FuncRequest cmd1 = cmd;
693 ret = the_locking_inset->localDispatch(cmd1);
695 if (cmd.button() == mouse_button::button3 && !ret) {
696 InsetTabularMailer(*this).showDialog(cmd.view());
703 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
705 if (the_locking_inset) {
706 FuncRequest cmd1 = cmd;
709 the_locking_inset->localDispatch(cmd1);
713 BufferView * bv = cmd.view();
714 int const old_cell = actcell;
716 setPos(bv, cmd.x, cmd.y);
717 if (!hasSelection()) {
718 setSelection(actcell, actcell);
719 updateLocal(bv, SELECTION);
720 } else if (old_cell != actcell) {
721 setSelection(sel_cell_start, actcell);
722 updateLocal(bv, SELECTION);
727 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
729 // We need to save the value of the_locking_inset as the call to
730 // the_locking_inset->localDispatch might unlock it.
731 old_locking_inset = the_locking_inset;
732 RESULT result = UpdatableInset::localDispatch(cmd);
733 BufferView * bv = cmd.view();
735 if (cmd.action == LFUN_INSET_EDIT) {
737 if (!bv->lockInset(this)) {
738 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
744 the_locking_inset = 0;
748 if (cmd.argument.size()) {
749 if (cmd.argument == "left") {
750 if (isRightToLeft(bv))
751 actcell = tabular.getLastCellInRow(0);
755 if (isRightToLeft(bv))
756 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
758 actcell = tabular.getNumberOfCells() - 1;
766 setPos(bv, cmd.x, cmd.y);
769 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
770 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
776 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
781 if (cmd.action < 0 && cmd.argument.empty())
784 bool hs = hasSelection();
787 // this one have priority over the locked InsetText, if we're not already
788 // inside another tabular then that one get's priority!
789 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
790 switch (cmd.action) {
791 case LFUN_MOUSE_PRESS:
795 case LFUN_MOUSE_MOTION:
796 lfunMouseMotion(cmd);
799 case LFUN_MOUSE_RELEASE:
800 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
802 case LFUN_CELL_BACKWARD:
803 case LFUN_CELL_FORWARD:
804 unlockInsetInInset(bv, the_locking_inset);
805 if (cmd.action == LFUN_CELL_FORWARD)
806 moveNextCell(bv, old_locking_inset != 0);
808 movePrevCell(bv, old_locking_inset != 0);
811 updateLocal(bv, SELECTION);
812 if (!the_locking_inset) {
813 return DISPATCHED_NOUPDATE;
816 // this to avoid compiler warnings.
822 kb_action action = cmd.action;
823 string arg = cmd.argument;
824 if (the_locking_inset) {
825 result = the_locking_inset->localDispatch(cmd);
826 if (result == DISPATCHED_NOUPDATE) {
829 if (sc != scroll()) { // inset has been scrolled
830 updateLocal(bv, FULL);
833 } else if (result == DISPATCHED) {
834 updateLocal(bv, CELL);
836 } else if (result == FINISHED_UP) {
838 // Make sure to reset status message after
839 // exiting, e.g. math inset
840 bv->owner()->clearMessage();
841 } else if (result == FINISHED_DOWN) {
843 bv->owner()->clearMessage();
844 } else if (result == FINISHED_RIGHT) {
846 bv->owner()->clearMessage();
847 } else if (result == FINISHED) {
848 bv->owner()->clearMessage();
854 // --- Cursor Movements ----------------------------------
855 case LFUN_RIGHTSEL: {
856 int const start = hasSelection() ? sel_cell_start : actcell;
857 if (tabular.isLastCellInRow(actcell)) {
858 setSelection(start, actcell);
863 // if we are starting a selection, only select
864 // the current cell at the beginning
865 if (hasSelection()) {
866 moveRight(bv, false);
869 setSelection(start, end);
870 updateLocal(bv, SELECTION);
874 result = moveRight(bv);
877 updateLocal(bv, SELECTION);
880 int const start = hasSelection() ? sel_cell_start : actcell;
881 if (tabular.isFirstCellInRow(actcell)) {
882 setSelection(start, actcell);
887 // if we are starting a selection, only select
888 // the current cell at the beginning
889 if (hasSelection()) {
893 setSelection(start, end);
894 updateLocal(bv, SELECTION);
898 result = moveLeft(bv);
901 updateLocal(bv, SELECTION);
904 int const start = hasSelection() ? sel_cell_start : actcell;
905 int const ocell = actcell;
906 // if we are starting a selection, only select
907 // the current cell at the beginning
908 if (hasSelection()) {
910 if ((ocell == sel_cell_end) ||
911 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
912 setSelection(start, tabular.getCellBelow(sel_cell_end));
914 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
916 setSelection(start, start);
918 updateLocal(bv, SELECTION);
922 result = moveDown(bv, old_locking_inset != 0);
925 updateLocal(bv, SELECTION);
929 int const start = hasSelection() ? sel_cell_start : actcell;
930 int const ocell = actcell;
931 // if we are starting a selection, only select
932 // the current cell at the beginning
933 if (hasSelection()) {
935 if ((ocell == sel_cell_end) ||
936 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
937 setSelection(start, tabular.getCellAbove(sel_cell_end));
939 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
941 setSelection(start, start);
943 updateLocal(bv, SELECTION);
947 result = moveUp(bv, old_locking_inset != 0);
950 updateLocal(bv, SELECTION);
953 UpdateCodes code = CURSOR;
959 unlockInsetInInset(bv, the_locking_inset);
960 if (bv->text->top_y() + bv->painter().paperHeight() <
961 (top_baseline + tabular.getHeightOfTabular()))
963 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
965 actcell = tabular.getCellBelow(first_visible_cell) + column;
967 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
970 updateLocal(bv, code);
974 UpdateCodes code = CURSOR;
980 unlockInsetInInset(bv, the_locking_inset);
981 if (top_baseline < 0) {
982 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
984 if (top_baseline > 0)
987 actcell = tabular.getCellBelow(first_visible_cell) + column;
992 updateLocal(bv, code);
995 // none of these make sense for insettabular,
996 // but we must catch them to prevent any
997 // selection from being confused
1001 case LFUN_WORDLEFTSEL:
1002 case LFUN_WORDRIGHT:
1003 case LFUN_WORDRIGHTSEL:
1005 case LFUN_DOWN_PARAGRAPH:
1006 case LFUN_DOWN_PARAGRAPHSEL:
1007 case LFUN_UP_PARAGRAPH:
1008 case LFUN_UP_PARAGRAPHSEL:
1009 case LFUN_BACKSPACE:
1014 case LFUN_BEGINNINGBUF:
1015 case LFUN_BEGINNINGBUFSEL:
1017 case LFUN_ENDBUFSEL:
1019 case LFUN_LAYOUT_TABULAR: {
1020 InsetTabularMailer mailer(*this);
1021 mailer.showDialog(bv);
1024 case LFUN_INSET_DIALOG_UPDATE: {
1025 InsetTabularMailer mailer(*this);
1026 mailer.updateDialog(bv);
1029 case LFUN_TABULAR_FEATURE:
1030 if (!tabularFeatures(bv, arg))
1031 result = UNDISPATCHED;
1033 // insert file functions
1034 case LFUN_FILE_INSERT_ASCII_PARA:
1035 case LFUN_FILE_INSERT_ASCII:
1037 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1040 if (insertAsciiString(bv, tmpstr, false))
1041 updateLocal(bv, INIT);
1043 result = UNDISPATCHED;
1046 // cut and paste functions
1048 if (!copySelection(bv))
1052 setUndo(bv, Undo::DELETE);
1053 cutSelection(bv->buffer()->params);
1054 updateLocal(bv, INIT);
1057 if (!hasSelection())
1062 case LFUN_PASTESELECTION:
1064 string const clip(bv->getClipboard());
1068 if (clip.find('\t') != string::npos) {
1072 string::size_type len = clip.length();
1073 string::size_type p = 0;
1076 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1084 maxCols = max(cols, maxCols);
1090 maxCols = max(cols, maxCols);
1091 delete paste_tabular;
1092 paste_tabular = new LyXTabular(bv->buffer()->params,
1093 this, rows, maxCols);
1094 string::size_type op = 0;
1096 int cells = paste_tabular->getNumberOfCells();
1098 while ((cell < cells) && (p < len) &&
1099 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1104 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1109 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1110 while (cols++ < maxCols)
1118 // check for the last cell if there is no trailing '\n'
1119 if ((cell < cells) && (op < len))
1120 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1123 if (!insertAsciiString(bv, clip, true))
1126 // so that the clipboard is used and it goes on
1128 // and executes LFUN_PASTESELECTION in insettext!
1129 delete paste_tabular;
1134 if (hasPasteBuffer()) {
1135 setUndo(bv, Undo::INSERT);
1137 updateLocal(bv, INIT);
1140 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1142 // handle font changing stuff on selection before we lock the inset
1143 // in the default part!
1144 result = UNDISPATCHED;
1155 case LFUN_UNDERLINE:
1156 case LFUN_FONT_SIZE:
1157 if (bv->dispatch(FuncRequest(bv, action, arg)))
1158 result = DISPATCHED;
1164 // we try to activate the actual inset and put this event down to
1165 // the insets dispatch function.
1166 if ((result == DISPATCHED) || the_locking_inset)
1169 if (activateCellInset(bv)) {
1170 // reset need_update setted in above function!
1172 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1173 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1174 unlockInsetInInset(bv, the_locking_inset);
1176 // we need to update if this was requested before
1177 updateLocal(bv, NONE);
1178 return UNDISPATCHED;
1181 // so the below CELL is not set because this is higher
1182 // priority and we get a full redraw
1183 need_update = SELECTION;
1186 updateLocal(bv, CELL);
1191 if (result < FINISHED) {
1192 if (!the_locking_inset) {
1193 if (bv->fitCursor())
1194 updateLocal(bv, FULL);
1197 bv->unlockInset(this);
1202 int InsetTabular::latex(Buffer const * buf, ostream & os,
1203 LatexRunParams const & runparams) const
1205 return tabular.latex(buf, os, runparams);
1209 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1212 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1214 return tabular.ascii(buf, os, 0, false,0);
1218 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1221 int const ret = tabular.ascii(buf,os,
1222 (int)parOwner()->params().depth(),
1229 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1234 // if the table is inside a float it doesn't need the informaltable
1235 // wrapper. Search for it.
1236 for(master = owner();
1237 master && master->lyxCode() != Inset::FLOAT_CODE;
1238 master = master->owner());
1241 os << "<informaltable>";
1246 ret+= tabular.docbook(buf, os, mixcont);
1248 os << "</informaltable>";
1257 void InsetTabular::validate(LaTeXFeatures & features) const
1259 tabular.validate(features);
1263 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1269 bool changed = false;
1271 // FIXME: since InsetText ignores this anyway, it doesn't
1272 // matter what we pass it. Ugly
1275 // if we have a locking_inset we should have to check only this cell for
1276 // change so I'll try this to have a boost, but who knows ;)
1277 if ((need_update != INIT) &&
1278 (the_locking_inset == tabular.getCellInset(actcell))) {
1279 for(int i = 0; i < tabular.columns(); ++i) {
1280 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1282 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1285 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1286 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1287 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1290 for (int i = 0; i < tabular.rows(); ++i) {
1293 for (int j = 0; j < tabular.columns(); ++j) {
1294 if (tabular.isPartOfMultiColumn(i,j))
1297 inset = tabular.getCellInset(cell);
1298 if (!reinit && !tabular.getPWidth(cell).zero())
1299 inset->update(bv, false);
1300 maxAsc = max(maxAsc, inset->ascent(bv, font));
1301 maxDesc = max(maxDesc, inset->descent(bv, font));
1302 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1304 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1305 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1313 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1315 if (the_locking_inset) {
1316 the_locking_inset->getCursor(bv, x, y);
1321 y = cursor_.y() + InsetTabular::y();
1324 int desc = tabular.getDescentOfRow(actrow);
1326 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1328 y += ADD_TO_HEIGHT * 2;
1329 y += TEXT_TO_INSET_OFFSET;
1333 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1335 if (the_locking_inset) {
1336 the_locking_inset->getCursorPos(bv, x, y);
1339 x = cursor_.x() - top_x;
1344 void InsetTabular::fitInsetCursor(BufferView * bv) const
1346 if (the_locking_inset) {
1347 int old_top_y = bv->text->top_y();
1348 the_locking_inset->fitInsetCursor(bv);
1349 if (old_top_y != bv->text->top_y())
1355 int const asc = font_metrics::maxAscent(font);
1356 int const desc = font_metrics::maxDescent(font);
1359 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1364 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1368 actcell = actrow = actcol = 0;
1369 int ly = tabular.getDescentOfRow(actrow);
1371 // first search the right row
1372 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1373 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1374 tabular.getAscentOfRow(actrow + 1) +
1375 tabular.getAdditionalHeight(actrow + 1));
1377 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1379 actcell = tabular.getCellNumber(actrow, actcol);
1381 // now search the right column
1382 int lx = tabular.getWidthOfColumn(actcell) -
1383 tabular.getAdditionalWidth(actcell);
1384 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1385 lx += tabular.getWidthOfColumn(actcell + 1)
1386 + tabular.getAdditionalWidth(actcell);
1388 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1393 int InsetTabular::getCellXPos(int cell) const
1397 for (; !tabular.isFirstCellInRow(c); --c)
1399 int lx = tabular.getWidthOfColumn(cell);
1400 for (; c < cell; ++c) {
1401 lx += tabular.getWidthOfColumn(c);
1403 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1407 void InsetTabular::resetPos(BufferView * bv) const
1409 #ifdef WITH_WARNINGS
1410 #warning This should be fixed in the right manner (20011128 Jug)
1412 // fast hack to fix infinite repaintings!
1413 if (in_reset_pos > 0)
1417 actcol = tabular.column_of_cell(actcell);
1420 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1421 if (tabular.isLastCellInRow(cell)) {
1422 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1423 tabular.getAscentOfRow(actrow + 1) +
1424 tabular.getAdditionalHeight(actrow + 1));
1428 if (!locked || nodraw()) {
1429 if (the_locking_inset)
1430 inset_y = cursor_.y();
1433 // we need this only from here on!!!
1435 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1436 int new_x = getCellXPos(actcell);
1437 int old_x = cursor_.x();
1440 // cursor.x(getCellXPos(actcell) + offset);
1441 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1442 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1445 updateLocal(bv, FULL);
1446 } else if (the_locking_inset &&
1447 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1449 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1450 if (xx > (bv->workWidth()-20)) {
1451 scroll(bv, -(xx - bv->workWidth() + 60));
1452 updateLocal(bv, FULL);
1453 } else if (xx < 20) {
1459 updateLocal(bv, FULL);
1461 } else if ((cursor_.x() - offset) > 20 &&
1462 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1463 > (bv->workWidth() - 20)) {
1464 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1465 updateLocal(bv, FULL);
1466 } else if ((cursor_.x() - offset) < 20) {
1467 scroll(bv, 20 - cursor_.x() + offset);
1468 updateLocal(bv, FULL);
1469 } else if (scroll() && top_x > 20 &&
1470 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1471 scroll(bv, old_x - cursor_.x());
1472 updateLocal(bv, FULL);
1474 if (the_locking_inset) {
1475 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1476 inset_y = cursor_.y();
1478 if ((!the_locking_inset ||
1479 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1480 actcell != oldcell) {
1481 InsetTabular * inset = const_cast<InsetTabular *>(this);
1482 InsetTabularMailer mailer(*inset);
1483 mailer.updateDialog(bv);
1490 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1492 if (lock && !old_locking_inset) {
1493 if (activateCellInset(bv))
1496 bool moved = isRightToLeft(bv)
1497 ? movePrevCell(bv) : moveNextCell(bv);
1499 return FINISHED_RIGHT;
1500 if (lock && activateCellInset(bv))
1504 return DISPATCHED_NOUPDATE;
1508 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1510 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1513 if (lock) { // behind the inset
1514 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1518 return DISPATCHED_NOUPDATE;
1522 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1524 int const ocell = actcell;
1525 actcell = tabular.getCellAbove(actcell);
1526 if (actcell == ocell) // we moved out of the inset
1532 if (old_locking_inset) {
1533 old_locking_inset->getCursorPos(bv, x, y);
1534 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1536 if (activateCellInset(bv, x, 0))
1539 return DISPATCHED_NOUPDATE;
1543 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1545 int const ocell = actcell;
1546 actcell = tabular.getCellBelow(actcell);
1547 if (actcell == ocell) // we moved out of the inset
1548 return FINISHED_DOWN;
1553 if (old_locking_inset) {
1554 old_locking_inset->getCursorPos(bv, x, y);
1555 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1557 if (activateCellInset(bv, x, 0))
1560 return DISPATCHED_NOUPDATE;
1564 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1566 if (isRightToLeft(bv)) {
1567 if (tabular.isFirstCellInRow(actcell)) {
1568 int row = tabular.row_of_cell(actcell);
1569 if (row == tabular.rows() - 1)
1571 actcell = tabular.getLastCellInRow(row);
1572 actcell = tabular.getCellBelow(actcell);
1579 if (tabular.isLastCell(actcell))
1584 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1585 isRightToLeftPar(bv->buffer()->params);
1586 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1593 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1595 if (isRightToLeft(bv)) {
1596 if (tabular.isLastCellInRow(actcell)) {
1597 int row = tabular.row_of_cell(actcell);
1600 actcell = tabular.getFirstCellInRow(row);
1601 actcell = tabular.getCellAbove(actcell);
1603 if (tabular.isLastCell(actcell))
1608 if (!actcell) // first cell
1613 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1614 isRightToLeftPar(bv->buffer()->params);
1615 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1622 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1626 setSelection(0, tabular.getNumberOfCells() - 1);
1628 if (hasSelection()) {
1629 setUndo(bv, Undo::EDIT);
1630 bool const frozen = undo_frozen;
1633 // apply the fontchange on the whole selection
1638 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1639 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1640 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1641 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1648 updateLocal(bv, INIT);
1650 if (the_locking_inset)
1651 the_locking_inset->setFont(bv, font, tall);
1655 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1657 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1660 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1661 string const tmp = tabularFeature[i].feature;
1663 if (tmp == what.substr(0, tmp.length())) {
1664 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1665 //tabularFeatures[i].feature.length())) {
1666 action = tabularFeature[i].action;
1670 if (action == LyXTabular::LAST_ACTION)
1674 ltrim(what.substr(tabularFeature[i].feature.length()));
1675 tabularFeatures(bv, action, val);
1681 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1682 string const & special, bool & flag)
1684 if (special == "dl_above") {
1687 } else if (special == "dl_below") {
1688 ltt.bottomDL = flag;
1690 } else if (special == "empty") {
1702 void InsetTabular::tabularFeatures(BufferView * bv,
1703 LyXTabular::Feature feature,
1704 string const & value)
1710 bool setLines = false;
1711 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1712 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1715 case LyXTabular::M_ALIGN_LEFT:
1716 case LyXTabular::ALIGN_LEFT:
1717 setAlign = LYX_ALIGN_LEFT;
1719 case LyXTabular::M_ALIGN_RIGHT:
1720 case LyXTabular::ALIGN_RIGHT:
1721 setAlign = LYX_ALIGN_RIGHT;
1723 case LyXTabular::M_ALIGN_CENTER:
1724 case LyXTabular::ALIGN_CENTER:
1725 setAlign = LYX_ALIGN_CENTER;
1727 case LyXTabular::ALIGN_BLOCK:
1728 setAlign = LYX_ALIGN_BLOCK;
1730 case LyXTabular::M_VALIGN_TOP:
1731 case LyXTabular::VALIGN_TOP:
1732 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1734 case LyXTabular::M_VALIGN_BOTTOM:
1735 case LyXTabular::VALIGN_BOTTOM:
1736 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1738 case LyXTabular::M_VALIGN_CENTER:
1739 case LyXTabular::VALIGN_CENTER:
1740 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1745 if (hasSelection()) {
1746 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1748 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1749 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1751 setUndo(bv, Undo::FINISH);
1753 int row = tabular.row_of_cell(actcell);
1754 int column = tabular.column_of_cell(actcell);
1756 LyXTabular::ltType ltt;
1759 case LyXTabular::SET_PWIDTH:
1761 LyXLength const vallen(value);
1762 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1764 bool const update = (tmplen != vallen);
1765 tabular.setColumnPWidth(actcell, vallen);
1767 // We need this otherwise we won't resize
1768 // the insettext of the active cell (if any)
1769 // until later (see InsetText::do_resize)
1770 unlockInsetInInset(bv, the_locking_inset);
1773 for (int i = 0; i < tabular.rows(); ++i) {
1774 cell = tabular.getCellNumber(i,column);
1775 tabular.getCellInset(cell)->resizeLyXText(bv);
1777 updateLocal(bv, INIT);
1781 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1782 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1783 else if (!vallen.zero()
1784 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1785 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1788 case LyXTabular::SET_MPWIDTH:
1790 LyXLength const vallen(value);
1791 LyXLength const & tmplen = tabular.getPWidth(actcell);
1793 bool const update = (tmplen != vallen);
1794 tabular.setMColumnPWidth(actcell, vallen);
1796 // We need this otherwise we won't resize
1797 // the insettext of the active cell (if any)
1798 // until later (see InsetText::do_resize)
1799 unlockInsetInInset(bv, the_locking_inset);
1801 for (int i = 0; i < tabular.rows(); ++i) {
1802 tabular.getCellInset(tabular.getCellNumber(i, column))->
1805 updateLocal(bv, INIT);
1809 case LyXTabular::SET_SPECIAL_COLUMN:
1810 case LyXTabular::SET_SPECIAL_MULTI:
1811 tabular.setAlignSpecial(actcell,value,feature);
1812 updateLocal(bv, FULL);
1814 case LyXTabular::APPEND_ROW:
1815 // append the row into the tabular
1816 unlockInsetInInset(bv, the_locking_inset);
1817 tabular.appendRow(bv->buffer()->params, actcell);
1818 updateLocal(bv, INIT);
1820 case LyXTabular::APPEND_COLUMN:
1821 // append the column into the tabular
1822 unlockInsetInInset(bv, the_locking_inset);
1823 tabular.appendColumn(bv->buffer()->params, actcell);
1824 actcell = tabular.getCellNumber(row, column);
1825 updateLocal(bv, INIT);
1827 case LyXTabular::DELETE_ROW:
1828 unlockInsetInInset(bv, the_locking_inset);
1829 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1830 tabular.deleteRow(sel_row_start);
1832 if (sel_row_start >= tabular.rows())
1834 actcell = tabular.getCellNumber(sel_row_start, column);
1836 updateLocal(bv, INIT);
1838 case LyXTabular::DELETE_COLUMN:
1839 unlockInsetInInset(bv, the_locking_inset);
1840 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1841 tabular.deleteColumn(sel_col_start);
1843 if (sel_col_start >= tabular.columns())
1845 actcell = tabular.getCellNumber(row, sel_col_start);
1847 updateLocal(bv, INIT);
1849 case LyXTabular::M_TOGGLE_LINE_TOP:
1851 case LyXTabular::TOGGLE_LINE_TOP:
1853 bool lineSet = !tabular.topLine(actcell, flag);
1854 for (int i = sel_row_start; i <= sel_row_end; ++i)
1855 for (int j = sel_col_start; j <= sel_col_end; ++j)
1857 tabular.getCellNumber(i, j),
1859 updateLocal(bv, INIT);
1863 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1865 case LyXTabular::TOGGLE_LINE_BOTTOM:
1867 bool lineSet = !tabular.bottomLine(actcell, flag);
1868 for (int i = sel_row_start; i <= sel_row_end; ++i)
1869 for (int j = sel_col_start; j <= sel_col_end; ++j)
1870 tabular.setBottomLine(
1871 tabular.getCellNumber(i, j),
1874 updateLocal(bv, INIT);
1878 case LyXTabular::M_TOGGLE_LINE_LEFT:
1880 case LyXTabular::TOGGLE_LINE_LEFT:
1882 bool lineSet = !tabular.leftLine(actcell, flag);
1883 for (int i = sel_row_start; i <= sel_row_end; ++i)
1884 for (int j = sel_col_start; j <= sel_col_end; ++j)
1885 tabular.setLeftLine(
1886 tabular.getCellNumber(i,j),
1889 updateLocal(bv, INIT);
1893 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1895 case LyXTabular::TOGGLE_LINE_RIGHT:
1897 bool lineSet = !tabular.rightLine(actcell, flag);
1898 for (int i = sel_row_start; i <= sel_row_end; ++i)
1899 for (int j = sel_col_start; j <= sel_col_end; ++j)
1900 tabular.setRightLine(
1901 tabular.getCellNumber(i,j),
1904 updateLocal(bv, INIT);
1908 case LyXTabular::M_ALIGN_LEFT:
1909 case LyXTabular::M_ALIGN_RIGHT:
1910 case LyXTabular::M_ALIGN_CENTER:
1912 case LyXTabular::ALIGN_LEFT:
1913 case LyXTabular::ALIGN_RIGHT:
1914 case LyXTabular::ALIGN_CENTER:
1915 case LyXTabular::ALIGN_BLOCK:
1916 for (int i = sel_row_start; i <= sel_row_end; ++i)
1917 for (int j = sel_col_start; j <= sel_col_end; ++j)
1918 tabular.setAlignment(
1919 tabular.getCellNumber(i, j),
1922 updateLocal(bv, INIT);
1924 case LyXTabular::M_VALIGN_TOP:
1925 case LyXTabular::M_VALIGN_BOTTOM:
1926 case LyXTabular::M_VALIGN_CENTER:
1928 case LyXTabular::VALIGN_TOP:
1929 case LyXTabular::VALIGN_BOTTOM:
1930 case LyXTabular::VALIGN_CENTER:
1931 for (int i = sel_row_start; i <= sel_row_end; ++i)
1932 for (int j = sel_col_start; j <= sel_col_end; ++j)
1933 tabular.setVAlignment(
1934 tabular.getCellNumber(i, j),
1936 updateLocal(bv, INIT);
1938 case LyXTabular::MULTICOLUMN:
1940 if (sel_row_start != sel_row_end) {
1941 #ifdef WITH_WARNINGS
1942 #warning Need I say it ? This is horrible.
1944 Alert::error(_("Error setting multicolumn"),
1945 _("You cannot set multicolumn vertically."));
1948 // just multicol for one Single Cell
1949 if (!hasSelection()) {
1950 // check wether we are completly in a multicol
1951 if (tabular.isMultiColumn(actcell)) {
1952 tabular.unsetMultiColumn(actcell);
1953 updateLocal(bv, INIT);
1955 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1956 updateLocal(bv, CELL);
1960 // we have a selection so this means we just add all this
1961 // cells to form a multicolumn cell
1965 if (sel_cell_start > sel_cell_end) {
1966 s_start = sel_cell_end;
1967 s_end = sel_cell_start;
1969 s_start = sel_cell_start;
1970 s_end = sel_cell_end;
1972 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1975 updateLocal(bv, INIT);
1978 case LyXTabular::SET_ALL_LINES:
1980 case LyXTabular::UNSET_ALL_LINES:
1981 for (int i = sel_row_start; i <= sel_row_end; ++i)
1982 for (int j = sel_col_start; j <= sel_col_end; ++j)
1983 tabular.setAllLines(
1984 tabular.getCellNumber(i,j), setLines);
1985 updateLocal(bv, INIT);
1987 case LyXTabular::SET_LONGTABULAR:
1988 tabular.setLongTabular(true);
1989 updateLocal(bv, INIT); // because this toggles displayed
1991 case LyXTabular::UNSET_LONGTABULAR:
1992 tabular.setLongTabular(false);
1993 updateLocal(bv, INIT); // because this toggles displayed
1995 case LyXTabular::SET_ROTATE_TABULAR:
1996 tabular.setRotateTabular(true);
1998 case LyXTabular::UNSET_ROTATE_TABULAR:
1999 tabular.setRotateTabular(false);
2001 case LyXTabular::SET_ROTATE_CELL:
2002 for (int i = sel_row_start; i <= sel_row_end; ++i)
2003 for (int j = sel_col_start; j<=sel_col_end; ++j)
2004 tabular.setRotateCell(
2005 tabular.getCellNumber(i, j),
2008 case LyXTabular::UNSET_ROTATE_CELL:
2009 for (int i = sel_row_start; i <= sel_row_end; ++i)
2010 for (int j = sel_col_start; j <= sel_col_end; ++j)
2011 tabular.setRotateCell(
2012 tabular.getCellNumber(i, j), false);
2014 case LyXTabular::SET_USEBOX:
2016 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2017 if (val == tabular.getUsebox(actcell))
2018 val = LyXTabular::BOX_NONE;
2019 for (int i = sel_row_start; i <= sel_row_end; ++i)
2020 for (int j = sel_col_start; j <= sel_col_end; ++j)
2022 tabular.getCellNumber(i, j), val);
2025 case LyXTabular::UNSET_LTFIRSTHEAD:
2027 case LyXTabular::SET_LTFIRSTHEAD:
2028 (void)tabular.getRowOfLTFirstHead(row, ltt);
2029 checkLongtableSpecial(ltt, value, flag);
2030 tabular.setLTHead(row, flag, ltt, true);
2032 case LyXTabular::UNSET_LTHEAD:
2034 case LyXTabular::SET_LTHEAD:
2035 (void)tabular.getRowOfLTHead(row, ltt);
2036 checkLongtableSpecial(ltt, value, flag);
2037 tabular.setLTHead(row, flag, ltt, false);
2039 case LyXTabular::UNSET_LTFOOT:
2041 case LyXTabular::SET_LTFOOT:
2042 (void)tabular.getRowOfLTFoot(row, ltt);
2043 checkLongtableSpecial(ltt, value, flag);
2044 tabular.setLTFoot(row, flag, ltt, false);
2046 case LyXTabular::UNSET_LTLASTFOOT:
2048 case LyXTabular::SET_LTLASTFOOT:
2049 (void)tabular.getRowOfLTLastFoot(row, ltt);
2050 checkLongtableSpecial(ltt, value, flag);
2051 tabular.setLTFoot(row, flag, ltt, true);
2053 case LyXTabular::SET_LTNEWPAGE:
2055 bool what = !tabular.getLTNewPage(row);
2056 tabular.setLTNewPage(row, what);
2059 // dummy stuff just to avoid warnings
2060 case LyXTabular::LAST_ACTION:
2064 InsetTabularMailer mailer(*this);
2065 mailer.updateDialog(bv);
2069 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2072 UpdatableInset * inset =
2073 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2074 LyXFont font(LyXFont::ALL_SANE);
2076 x = inset->x() + inset->width(bv, font);
2077 y = inset->descent(bv, font);
2079 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2080 //inset_y = cursor.y();
2081 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2082 if (!the_locking_inset)
2084 updateLocal(bv, CELL);
2085 return (the_locking_inset != 0);
2089 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2090 mouse_button::state button)
2092 inset_x = cursor_.x()
2093 - top_x + tabular.getBeginningOfTextInCell(actcell);
2094 inset_y = cursor_.y();
2095 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2099 bool InsetTabular::insetHit(BufferView *, int x, int) const
2102 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2106 // This returns paperWidth() if the cell-width is unlimited or the width
2107 // in pixels if we have a pwidth for this cell.
2108 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2110 LyXLength const len = tabular.getPWidth(cell);
2114 return len.inPixels(latexTextWidth(bv));
2118 int InsetTabular::getMaxWidth(BufferView * bv,
2119 UpdatableInset const * inset) const
2121 int cell = tabular.getCellFromInset(inset, actcell);
2124 lyxerr << "Own inset not found, shouldn't really happen!"
2129 int w = getMaxWidthOfCell(bv, cell);
2131 // because the inset then subtracts it's top_x and owner->x()
2132 w += (inset->x() - top_x);
2139 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2141 resizeLyXText(bv, recursive);
2145 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2148 for(int i = 0; i < tabular.rows(); ++i) {
2149 for(int j = 0; j < tabular.columns(); ++j) {
2150 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2158 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2159 bool const recursive) const
2161 if (the_locking_inset)
2162 return the_locking_inset->getLyXText(bv, recursive);
2164 // if we're locked lock the actual insettext and return it's LyXText!!!
2166 UpdatableInset * inset =
2167 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2168 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2169 return the_locking_inset->getLyXText(bv, recursive);
2172 return Inset::getLyXText(bv, recursive);
2176 bool InsetTabular::showInsetDialog(BufferView * bv) const
2178 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2179 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2180 InsetTabularMailer mailer(*tmp);
2181 mailer.showDialog(bv);
2187 void InsetTabular::openLayoutDialog(BufferView * bv) const
2189 if (the_locking_inset) {
2190 InsetTabular * i = static_cast<InsetTabular *>
2191 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2193 i->openLayoutDialog(bv);
2197 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2198 InsetTabularMailer mailer(*tmp);
2199 mailer.showDialog(bv);
2204 // function returns an object as defined in func_status.h:
2205 // states OK, Unknown, Disabled, On, Off.
2207 FuncStatus InsetTabular::getStatus(string const & what) const
2209 int action = LyXTabular::LAST_ACTION;
2213 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2214 string const tmp = tabularFeature[i].feature;
2215 if (tmp == what.substr(0, tmp.length())) {
2216 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2217 // tabularFeatures[i].feature.length())) {
2218 action = tabularFeature[i].action;
2222 if (action == LyXTabular::LAST_ACTION) {
2224 return status.unknown(true);
2227 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2232 LyXTabular::ltType dummyltt;
2235 if (hasSelection()) {
2236 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2238 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2242 case LyXTabular::SET_PWIDTH:
2243 case LyXTabular::SET_MPWIDTH:
2244 case LyXTabular::SET_SPECIAL_COLUMN:
2245 case LyXTabular::SET_SPECIAL_MULTI:
2246 case LyXTabular::APPEND_ROW:
2247 case LyXTabular::APPEND_COLUMN:
2248 case LyXTabular::DELETE_ROW:
2249 case LyXTabular::DELETE_COLUMN:
2250 case LyXTabular::SET_ALL_LINES:
2251 case LyXTabular::UNSET_ALL_LINES:
2252 return status.clear();
2254 case LyXTabular::MULTICOLUMN:
2255 status.setOnOff(tabular.isMultiColumn(actcell));
2257 case LyXTabular::M_TOGGLE_LINE_TOP:
2259 case LyXTabular::TOGGLE_LINE_TOP:
2260 status.setOnOff(tabular.topLine(actcell, flag));
2262 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2264 case LyXTabular::TOGGLE_LINE_BOTTOM:
2265 status.setOnOff(tabular.bottomLine(actcell, flag));
2267 case LyXTabular::M_TOGGLE_LINE_LEFT:
2269 case LyXTabular::TOGGLE_LINE_LEFT:
2270 status.setOnOff(tabular.leftLine(actcell, flag));
2272 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2274 case LyXTabular::TOGGLE_LINE_RIGHT:
2275 status.setOnOff(tabular.rightLine(actcell, flag));
2277 case LyXTabular::M_ALIGN_LEFT:
2279 case LyXTabular::ALIGN_LEFT:
2280 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2282 case LyXTabular::M_ALIGN_RIGHT:
2284 case LyXTabular::ALIGN_RIGHT:
2285 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2287 case LyXTabular::M_ALIGN_CENTER:
2289 case LyXTabular::ALIGN_CENTER:
2290 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2292 case LyXTabular::ALIGN_BLOCK:
2293 status.disabled(tabular.getPWidth(actcell).zero());
2294 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2296 case LyXTabular::M_VALIGN_TOP:
2298 case LyXTabular::VALIGN_TOP:
2299 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2301 case LyXTabular::M_VALIGN_BOTTOM:
2303 case LyXTabular::VALIGN_BOTTOM:
2304 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2306 case LyXTabular::M_VALIGN_CENTER:
2308 case LyXTabular::VALIGN_CENTER:
2309 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2311 case LyXTabular::SET_LONGTABULAR:
2312 status.setOnOff(tabular.isLongTabular());
2314 case LyXTabular::UNSET_LONGTABULAR:
2315 status.setOnOff(!tabular.isLongTabular());
2317 case LyXTabular::SET_ROTATE_TABULAR:
2318 status.setOnOff(tabular.getRotateTabular());
2320 case LyXTabular::UNSET_ROTATE_TABULAR:
2321 status.setOnOff(!tabular.getRotateTabular());
2323 case LyXTabular::SET_ROTATE_CELL:
2324 status.setOnOff(tabular.getRotateCell(actcell));
2326 case LyXTabular::UNSET_ROTATE_CELL:
2327 status.setOnOff(!tabular.getRotateCell(actcell));
2329 case LyXTabular::SET_USEBOX:
2330 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2332 case LyXTabular::SET_LTFIRSTHEAD:
2333 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2335 case LyXTabular::SET_LTHEAD:
2336 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2338 case LyXTabular::SET_LTFOOT:
2339 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2341 case LyXTabular::SET_LTLASTFOOT:
2342 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2344 case LyXTabular::SET_LTNEWPAGE:
2345 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2349 status.disabled(true);
2356 void InsetTabular::getLabelList(std::vector<string> & list) const
2358 tabular.getLabelList(list);
2362 bool InsetTabular::copySelection(BufferView * bv)
2364 if (!hasSelection())
2367 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2368 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2369 if (sel_col_start > sel_col_end) {
2370 sel_col_start = sel_col_end;
2371 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2373 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2375 int const columns = sel_col_end - sel_col_start + 1;
2377 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2378 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2379 if (sel_row_start > sel_row_end) {
2380 swap(sel_row_start, sel_row_end);
2382 int const rows = sel_row_end - sel_row_start + 1;
2384 delete paste_tabular;
2385 paste_tabular = new LyXTabular(bv->buffer()->params,
2386 this, tabular); // rows, columns);
2387 for (int i = 0; i < sel_row_start; ++i)
2388 paste_tabular->deleteRow(0);
2389 while (paste_tabular->rows() > rows)
2390 paste_tabular->deleteRow(rows);
2391 paste_tabular->setTopLine(0, true, true);
2392 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2394 for (int i = 0; i < sel_col_start; ++i)
2395 paste_tabular->deleteColumn(0);
2396 while (paste_tabular->columns() > columns)
2397 paste_tabular->deleteColumn(columns);
2398 paste_tabular->setLeftLine(0, true, true);
2399 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2403 paste_tabular->ascii(bv->buffer(), sstr,
2404 (int)parOwner()->params().depth(), true, '\t');
2405 bv->stuffClipboard(STRCONV(sstr.str()));
2410 bool InsetTabular::pasteSelection(BufferView * bv)
2415 for (int r1 = 0, r2 = actrow;
2416 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2418 for(int c1 = 0, c2 = actcol;
2419 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2421 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2422 tabular.isPartOfMultiColumn(r2,c2))
2424 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2428 if (tabular.isPartOfMultiColumn(r2,c2)) {
2432 int const n1 = paste_tabular->getCellNumber(r1, c1);
2433 int const n2 = tabular.getCellNumber(r2, c2);
2434 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2435 tabular.getCellInset(n2)->setOwner(this);
2436 tabular.getCellInset(n2)->deleteLyXText(bv);
2437 tabular.getCellInset(n2)->markNew();
2444 bool InsetTabular::cutSelection(BufferParams const & bp)
2446 if (!hasSelection())
2449 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2450 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2451 if (sel_col_start > sel_col_end) {
2452 sel_col_start = sel_col_end;
2453 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2455 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2457 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2458 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2459 if (sel_row_start > sel_row_end) {
2460 swap(sel_row_start, sel_row_end);
2462 if (sel_cell_start > sel_cell_end) {
2463 swap(sel_cell_start, sel_cell_end);
2465 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2466 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2467 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2474 bool InsetTabular::isRightToLeft(BufferView * bv)
2476 return bv->getParentLanguage(this)->RightToLeft();
2480 bool InsetTabular::nodraw() const
2482 if (!UpdatableInset::nodraw() && the_locking_inset)
2483 return the_locking_inset->nodraw();
2484 return UpdatableInset::nodraw();
2488 int InsetTabular::scroll(bool recursive) const
2490 int sx = UpdatableInset::scroll(false);
2492 if (recursive && the_locking_inset)
2493 sx += the_locking_inset->scroll(recursive);
2499 void InsetTabular::getSelection(int & srow, int & erow,
2500 int & scol, int & ecol) const
2502 int const start = hasSelection() ? sel_cell_start : actcell;
2503 int const end = hasSelection() ? sel_cell_end : actcell;
2505 srow = tabular.row_of_cell(start);
2506 erow = tabular.row_of_cell(end);
2511 scol = tabular.column_of_cell(start);
2512 ecol = tabular.column_of_cell(end);
2516 ecol = tabular.right_column_of_cell(end);
2521 ParagraphList * InsetTabular::getParagraphs(int i) const
2523 return (i < tabular.getNumberOfCells())
2524 ? tabular.getCellInset(i)->getParagraphs(0)
2529 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2531 if (the_locking_inset)
2532 return the_locking_inset->cursor(bv);
2533 return Inset::cursor(bv);
2537 Inset * InsetTabular::getInsetFromID(int id_arg) const
2540 return const_cast<InsetTabular *>(this);
2543 for(int i = 0; i < tabular.rows(); ++i) {
2544 for(int j = 0; j < tabular.columns(); ++j) {
2545 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2554 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2557 if (the_locking_inset) {
2558 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2559 if (!word.word().empty()) {
2563 if (tabular.isLastCell(actcell)) {
2564 bv->unlockInset(const_cast<InsetTabular *>(this));
2566 return WordLangTuple();
2570 // otherwise we have to lock the next inset and ask for it's selecttion
2571 UpdatableInset * inset =
2572 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2573 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2574 WordLangTuple word(selectNextWordInt(bv, value));
2576 if (!word.word().empty())
2582 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2584 // when entering this function the inset should be ALWAYS locked!
2585 Assert(the_locking_inset);
2587 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2588 if (!word.word().empty())
2591 if (tabular.isLastCell(actcell)) {
2592 bv->unlockInset(const_cast<InsetTabular *>(this));
2593 return WordLangTuple();
2596 // otherwise we have to lock the next inset and ask for it's selecttion
2597 UpdatableInset * inset =
2598 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2599 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2600 return selectNextWordInt(bv, value);
2604 void InsetTabular::selectSelectedWord(BufferView * bv)
2606 if (the_locking_inset) {
2607 the_locking_inset->selectSelectedWord(bv);
2614 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2616 if (the_locking_inset) {
2617 the_locking_inset->toggleSelection(bv, kill_selection);
2622 void InsetTabular::markErased()
2626 while (cell < tabular.getNumberOfCells()) {
2627 InsetText * inset = tabular.getCellInset(cell);
2628 inset->markErased();
2634 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2636 if (the_locking_inset) {
2637 if (the_locking_inset->nextChange(bv, length)) {
2638 updateLocal(bv, CELL);
2641 if (tabular.isLastCell(actcell))
2645 InsetText * inset = tabular.getCellInset(actcell);
2646 if (inset->nextChange(bv, length)) {
2647 updateLocal(bv, FULL);
2650 while (!tabular.isLastCell(actcell)) {
2652 inset = tabular.getCellInset(actcell);
2653 if (inset->nextChange(bv, length)) {
2654 updateLocal(bv, FULL);
2662 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2666 if (the_locking_inset) {
2667 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2668 updateLocal(bv, CELL);
2671 if (tabular.isLastCell(actcell))
2675 InsetText * inset = tabular.getCellInset(cell);
2676 if (inset->searchForward(bv, str, cs, mw)) {
2677 updateLocal(bv, FULL);
2680 while (!tabular.isLastCell(cell)) {
2682 inset = tabular.getCellInset(cell);
2683 if (inset->searchForward(bv, str, cs, mw)) {
2684 updateLocal(bv, FULL);
2692 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2695 int cell = tabular.getNumberOfCells();
2696 if (the_locking_inset) {
2697 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2698 updateLocal(bv, CELL);
2706 InsetText * inset = tabular.getCellInset(cell);
2707 if (inset->searchBackward(bv, str, cs, mw)) {
2708 updateLocal(bv, CELL);
2716 bool InsetTabular::insetAllowed(Inset::Code code) const
2718 if (the_locking_inset)
2719 return the_locking_inset->insetAllowed(code);
2720 // we return true here because if the inset is not locked someone
2721 // wants to insert something in one of our insettexts and we generally
2727 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2729 const int cell = tabular.getCellFromInset(in, actcell);
2732 return tabular.getPWidth(cell).zero();
2734 // well we didn't obviously find it so maybe our owner knows more
2736 return owner()->forceDefaultParagraphs(in);
2737 // if we're here there is really something strange going on!!!
2741 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2744 if (buf.length() <= 0)
2750 string::size_type len = buf.length();
2751 string::size_type p = 0;
2754 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2763 maxCols = max(cols, maxCols);
2769 maxCols = max(cols, maxCols);
2770 LyXTabular * loctab;
2775 delete paste_tabular;
2776 paste_tabular = new LyXTabular(bv->buffer()->params,
2777 this, rows, maxCols);
2778 loctab = paste_tabular;
2787 string::size_type op = 0;
2788 int cells = loctab->getNumberOfCells();
2791 rows = loctab->rows();
2792 int const columns = loctab->columns();
2794 while ((cell < cells) && (p < len) && (row < rows) &&
2795 (p = buf.find_first_of("\t\n", p)) != string::npos)
2801 // we can only set this if we are not too far right
2802 if (cols < columns) {
2803 InsetText * ti = loctab->getCellInset(cell);
2804 LyXFont const font = ti->getLyXText(bv)->
2805 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2806 ti->setText(buf.substr(op, p - op), font);
2812 // we can only set this if we are not too far right
2813 if (cols < columns) {
2814 InsetText * ti = loctab->getCellInset(cell);
2815 LyXFont const font = ti->getLyXText(bv)->
2816 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2817 ti->setText(buf.substr(op, p - op), font);
2822 cell = loctab->getCellNumber(row, cols);
2828 // check for the last cell if there is no trailing '\n'
2829 if ((cell < cells) && (op < len)) {
2830 InsetText * ti = loctab->getCellInset(cell);
2831 LyXFont const font = ti->getLyXText(bv)->
2832 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2833 ti->setText(buf.substr(op, len - op), font);
2840 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2842 int const rows = tabular.rows();
2843 int const columns = tabular.columns();
2844 for (int i = 0; i < rows; ++i) {
2845 for (int j = 0; j < columns; ++j) {
2846 tabular.getCellInset(i,j)->addPreview(loader);
2852 string const InsetTabularMailer:: name_("tabular");
2854 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2859 string const InsetTabularMailer::inset2string() const
2861 return params2string(inset_);
2865 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2867 istringstream data(STRCONV(in));
2869 lex.setStream(data);
2871 #warning CHECK verify that this is a sane value to return.
2877 string const token = lex.getString();
2885 string const token = lex.getString();
2886 if (token != "\\active_cell")
2889 cell = lex.getInteger();
2892 // This is part of the inset proper that is usually swallowed
2893 // by Buffer::readInset
2896 string const token = lex.getString();
2897 if (token != "Tabular")
2904 // FIXME: even current_view would be better than this.
2905 BufferView * const bv = inset.view();
2906 Buffer const * const buffer = bv ? bv->buffer() : 0;
2908 inset.read(buffer, lex);
2910 // We can't set the active cell, but we can tell the frontend
2916 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2918 // FIXME: even current_view would be better than this.
2919 BufferView * const bv = inset.view();
2920 Buffer const * const buffer = bv ? bv->buffer() : 0;
2925 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2926 inset.write(buffer, data);
2927 data << "\\end_inset\n";
2928 return STRCONV(data.str());