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;
62 namespace grfx = lyx::graphics;
66 int const ADD_TO_HEIGHT = 2;
67 int const ADD_TO_TABULAR_WIDTH = 2;
70 LyXTabular * paste_tabular = 0;
73 struct TabularFeature {
74 LyXTabular::Feature action;
79 TabularFeature tabularFeature[] =
81 { LyXTabular::APPEND_ROW, "append-row" },
82 { LyXTabular::APPEND_COLUMN, "append-column" },
83 { LyXTabular::DELETE_ROW, "delete-row" },
84 { LyXTabular::DELETE_COLUMN, "delete-column" },
85 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
86 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
87 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
88 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
89 { LyXTabular::ALIGN_LEFT, "align-left" },
90 { LyXTabular::ALIGN_RIGHT, "align-right" },
91 { LyXTabular::ALIGN_CENTER, "align-center" },
92 { LyXTabular::ALIGN_BLOCK, "align-block" },
93 { LyXTabular::VALIGN_TOP, "valign-top" },
94 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
95 { LyXTabular::VALIGN_CENTER, "valign-center" },
96 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
97 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
98 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
99 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
100 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
101 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
102 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
103 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
104 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
105 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
106 { LyXTabular::MULTICOLUMN, "multicolumn" },
107 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
108 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
109 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
110 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
111 { LyXTabular::SET_PWIDTH, "set-pwidth" },
112 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
113 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
114 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
115 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
116 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
117 { LyXTabular::SET_USEBOX, "set-usebox" },
118 { LyXTabular::SET_LTHEAD, "set-lthead" },
119 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
120 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
121 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
122 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
123 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
124 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
125 { LyXTabular::LAST_ACTION, "" }
129 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
130 bool operator()(TabularFeature & tf)
132 return tf.action == feature_;
135 LyXTabular::Feature feature_;
141 string const featureAsString(LyXTabular::Feature feature)
143 TabularFeature * it = tabularFeature;
144 TabularFeature * end = it +
145 sizeof(tabularFeature) / sizeof(TabularFeature);
146 it = std::find_if(it, end, FindFeature(feature));
147 return (it == end) ? string() : it->feature;
151 bool InsetTabular::hasPasteBuffer() const
153 return (paste_tabular != 0);
157 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 : tabular(buf.params, this, max(rows, 1), max(columns, 1)),
161 // for now make it always display as display() inset
163 the_locking_inset = 0;
164 old_locking_inset = 0;
167 actrow = actcell = 0;
176 InsetTabular::InsetTabular(InsetTabular const & tab)
177 : UpdatableInset(tab),
178 tabular(tab.buffer_->params, this, tab.tabular),
181 the_locking_inset = 0;
182 old_locking_inset = 0;
185 actrow = actcell = 0;
194 InsetTabular::~InsetTabular()
196 InsetTabularMailer mailer(*this);
201 InsetBase * InsetTabular::clone() const
203 return new InsetTabular(*this);
207 Buffer const * InsetTabular::buffer() const
213 BufferView * InsetTabular::view() const
220 void InsetTabular::buffer(Buffer * b)
226 void InsetTabular::write(Buffer const * buf, ostream & os) const
228 os << " Tabular" << endl;
229 tabular.write(buf, os);
233 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
235 bool const old_format = (lex.getString() == "\\LyXTable");
237 tabular.read(buf, lex);
245 string token = lex.getString();
246 while (lex.isOK() && (token != "\\end_inset")) {
248 token = lex.getString();
250 if (token != "\\end_inset") {
251 lex.printError("Missing \\end_inset at this point. "
257 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
260 calculate_dimensions_of_cells(mi.base.bv, true);
261 //lyxerr << "InsetTabular::metrics, bv: " << mi.base.bv << endl;
262 for (int i = 0; i < tabular.getNumberOfCells(); ++i) {
263 tabular.cellinfo_of_cell(i)->inset.text_.bv_owner = mi.base.bv;
264 tabular.cellinfo_of_cell(i)->inset.reinitLyXText();
268 dim.asc = tabular.getAscentOfRow(0);
269 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
270 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
274 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
281 BufferView * bv = pi.base.bv;
287 UpdatableInset::draw(pi, x, y);
295 x += ADD_TO_TABULAR_WIDTH;
299 first_visible_cell = -1;
300 for (i = 0; i < tabular.rows(); ++i) {
302 cell = tabular.getCellNumber(i, 0);
303 if (!((y + tabular.getDescentOfRow(i)) > 0) &&
304 (y - tabular.getAscentOfRow(i)) < pi.pain.paperHeight())
306 y += tabular.getDescentOfRow(i) +
307 tabular.getAscentOfRow(i + 1) +
308 tabular.getAdditionalHeight(i + 1);
311 for (j = 0; j < tabular.columns(); ++j) {
312 if (nx > bv->workWidth())
314 if (tabular.isPartOfMultiColumn(i, j))
316 cx = nx + tabular.getBeginningOfTextInCell(cell);
317 if (first_visible_cell < 0)
318 first_visible_cell = cell;
319 if (hasSelection()) {
320 drawCellSelection(pi.pain, nx, y, i, j, cell);
323 tabular.getCellInset(cell)->draw(pi, cx, y);
324 drawCellLines(pi.pain, nx, y, i, cell);
325 nx += tabular.getWidthOfColumn(cell);
329 // Would be nice, but for some completely unfathomable reason,
330 // on a col resize to a new fixed width, even though the insettexts
331 // are resized, the cell isn't, but drawing all cells in a tall table
332 // has the desired effect somehow. Complete dark magic.
334 // avoiding drawing the rest of a long table is
335 // a pretty big speedup
336 if (y > bv->workHeight())
340 y += tabular.getDescentOfRow(i) +
341 tabular.getAscentOfRow(i + 1) +
342 tabular.getAdditionalHeight(i + 1);
349 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
350 int row, int cell) const
352 int x2 = x + tabular.getWidthOfColumn(cell);
355 if (!tabular.topAlreadyDrawn(cell)) {
356 on_off = !tabular.topLine(cell);
357 pain.line(x, y - tabular.getAscentOfRow(row),
358 x2, y - tabular.getAscentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
362 on_off = !tabular.bottomLine(cell);
363 pain.line(x, y + tabular.getDescentOfRow(row),
364 x2, y + tabular.getDescentOfRow(row),
365 on_off ? LColor::tabularonoffline : LColor::tabularline,
366 on_off ? Painter::line_onoffdash : Painter::line_solid);
367 if (!tabular.leftAlreadyDrawn(cell)) {
368 on_off = !tabular.leftLine(cell);
369 pain.line(x, y - tabular.getAscentOfRow(row),
370 x, y + tabular.getDescentOfRow(row),
371 on_off ? LColor::tabularonoffline : LColor::tabularline,
372 on_off ? Painter::line_onoffdash : Painter::line_solid);
374 on_off = !tabular.rightLine(cell);
375 pain.line(x2 - tabular.getAdditionalWidth(cell),
376 y - tabular.getAscentOfRow(row),
377 x2 - tabular.getAdditionalWidth(cell),
378 y + tabular.getDescentOfRow(row),
379 on_off ? LColor::tabularonoffline : LColor::tabularline,
380 on_off ? Painter::line_onoffdash : Painter::line_solid);
384 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
385 int row, int column, int cell) const
387 Assert(hasSelection());
388 int cs = tabular.column_of_cell(sel_cell_start);
389 int ce = tabular.column_of_cell(sel_cell_end);
392 cs = tabular.column_of_cell(sel_cell_end);
394 ce = tabular.right_column_of_cell(sel_cell_end);
397 int rs = tabular.row_of_cell(sel_cell_start);
398 int re = tabular.row_of_cell(sel_cell_end);
402 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
403 int w = tabular.getWidthOfColumn(cell);
404 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
405 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
406 w, h, LColor::selection);
411 string const InsetTabular::editMessage() const
413 return _("Opened table");
417 void InsetTabular::insetUnlock(BufferView * bv)
419 if (the_locking_inset) {
420 the_locking_inset->insetUnlock(bv);
421 updateLocal(bv, CELL);
422 the_locking_inset = 0;
427 if (scroll(false) || hasSelection()) {
432 updateLocal(bv, FULL);
437 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
440 calculate_dimensions_of_cells(bv, true);
442 if (!locked && what == CELL)
444 if (need_update < what) // only set this if it has greater update
447 if (need_update != NONE) {
448 bv->updateInset(const_cast<InsetTabular *>(this));
455 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
457 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
462 if (inset == tabular.getCellInset(actcell)) {
463 lyxerr[Debug::INSETTEXT] << "OK" << endl;
464 the_locking_inset = tabular.getCellInset(actcell);
467 } else if (!the_locking_inset) {
468 int const n = tabular.getNumberOfCells();
469 int const id = inset->id();
470 for (int i = 0; i < n; ++i) {
471 InsetText * in = tabular.getCellInset(i);
474 the_locking_inset = in;
479 if (in->getInsetFromID(id)) {
481 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
482 return the_locking_inset->lockInsetInInset(bv, inset);
485 } else if (the_locking_inset && (the_locking_inset == inset)) {
486 lyxerr[Debug::INSETTEXT] << "OK" << endl;
488 } else if (the_locking_inset) {
489 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
490 return the_locking_inset->lockInsetInInset(bv, inset);
492 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
497 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
500 if (!the_locking_inset)
502 if (the_locking_inset == inset) {
503 the_locking_inset->insetUnlock(bv);
505 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
511 updateLocal(bv, CELL);
512 // this has to be here otherwise we don't redraw the cell!
513 the_locking_inset = 0;
516 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
517 if (inset->lyxCode() == TABULAR_CODE &&
518 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
519 InsetTabularMailer mailer(*this);
520 mailer.updateDialog(bv);
529 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
531 Inset * tl_inset = inset;
532 // look if this inset is really inside myself!
533 while(tl_inset->owner() && tl_inset->owner() != this)
534 tl_inset = tl_inset->owner();
535 // if we enter here it's not ower inset
536 if (!tl_inset->owner())
538 // we only have to do this if this is a subinset of our cells
539 if (tl_inset != inset) {
540 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
543 updateLocal(bv, CELL);
548 int InsetTabular::insetInInsetY() const
550 if (!the_locking_inset)
552 return inset_y + the_locking_inset->insetInInsetY();
556 UpdatableInset * InsetTabular::getLockingInset() const
558 return the_locking_inset ? the_locking_inset->getLockingInset() :
559 const_cast<InsetTabular *>(this);
563 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
567 if (the_locking_inset)
568 return the_locking_inset->getFirstLockingInsetOfType(c);
573 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
575 if (the_locking_inset)
576 return the_locking_inset->insertInset(bv, inset);
581 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
583 if (hasSelection() && cmd.button() == mouse_button::button3)
586 if (hasSelection()) {
588 updateLocal(cmd.view(), FULL);
591 int const ocell = actcell;
592 int const orow = actrow;
593 BufferView * bv = cmd.view();
597 the_locking_inset = 0;
601 setPos(bv, cmd.x, cmd.y);
603 updateLocal(bv, NONE);
606 if (cmd.button() == mouse_button::button3) {
607 if ((ocell != actcell) && the_locking_inset) {
608 the_locking_inset->insetUnlock(bv);
609 updateLocal(bv, CELL);
610 the_locking_inset = 0;
616 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
618 if ((ocell == actcell) && the_locking_inset && inset_hit) {
620 FuncRequest cmd1 = cmd;
623 the_locking_inset->localDispatch(cmd1);
627 if (the_locking_inset) {
628 the_locking_inset->insetUnlock(bv);
629 updateLocal(bv, CELL);
630 the_locking_inset = 0;
633 if (cmd.button() == mouse_button::button2) {
634 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
638 if (inset_hit && bv->theLockingInset()) {
639 if (!bv->lockInset(static_cast<UpdatableInset*>
640 (tabular.getCellInset(actcell))))
642 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
645 FuncRequest cmd1 = cmd;
648 the_locking_inset->localDispatch(cmd1);
654 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
657 if (the_locking_inset) {
658 FuncRequest cmd1 = cmd;
661 ret = the_locking_inset->localDispatch(cmd1);
663 if (cmd.button() == mouse_button::button3 && !ret) {
664 InsetTabularMailer(*this).showDialog(cmd.view());
671 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
673 if (the_locking_inset) {
674 FuncRequest cmd1 = cmd;
677 the_locking_inset->localDispatch(cmd1);
681 BufferView * bv = cmd.view();
682 int const old_cell = actcell;
684 setPos(bv, cmd.x, cmd.y);
685 if (!hasSelection()) {
686 setSelection(actcell, actcell);
687 updateLocal(bv, FULL);
688 } else if (old_cell != actcell) {
689 setSelection(sel_cell_start, actcell);
690 updateLocal(bv, FULL);
695 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
697 // We need to save the value of the_locking_inset as the call to
698 // the_locking_inset->localDispatch might unlock it.
699 old_locking_inset = the_locking_inset;
700 RESULT result = UpdatableInset::localDispatch(cmd);
701 BufferView * bv = cmd.view();
703 if (cmd.action == LFUN_INSET_EDIT) {
705 if (!bv->lockInset(this)) {
706 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
712 the_locking_inset = 0;
716 if (cmd.argument.size()) {
717 if (cmd.argument == "left") {
718 if (isRightToLeft(bv))
719 actcell = tabular.getLastCellInRow(0);
723 if (isRightToLeft(bv))
724 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
726 actcell = tabular.getNumberOfCells() - 1;
734 setPos(bv, cmd.x, cmd.y);
737 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
738 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
744 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
749 if (cmd.action < 0 && cmd.argument.empty())
752 bool hs = hasSelection();
755 // this one have priority over the locked InsetText, if we're not already
756 // inside another tabular then that one get's priority!
757 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
758 switch (cmd.action) {
759 case LFUN_MOUSE_PRESS:
763 case LFUN_MOUSE_MOTION:
764 lfunMouseMotion(cmd);
767 case LFUN_MOUSE_RELEASE:
768 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
770 case LFUN_CELL_BACKWARD:
771 case LFUN_CELL_FORWARD:
772 unlockInsetInInset(bv, the_locking_inset);
773 if (cmd.action == LFUN_CELL_FORWARD)
774 moveNextCell(bv, old_locking_inset != 0);
776 movePrevCell(bv, old_locking_inset != 0);
779 updateLocal(bv, FULL);
780 if (!the_locking_inset) {
781 return DISPATCHED_NOUPDATE;
784 // this to avoid compiler warnings.
790 kb_action action = cmd.action;
791 string arg = cmd.argument;
792 if (the_locking_inset) {
793 result = the_locking_inset->localDispatch(cmd);
794 if (result == DISPATCHED_NOUPDATE) {
797 if (sc != scroll()) { // inset has been scrolled
798 updateLocal(bv, FULL);
801 } else if (result == DISPATCHED) {
802 updateLocal(bv, CELL);
804 } else if (result == FINISHED_UP) {
806 // Make sure to reset status message after
807 // exiting, e.g. math inset
808 bv->owner()->clearMessage();
809 } else if (result == FINISHED_DOWN) {
811 bv->owner()->clearMessage();
812 } else if (result == FINISHED_RIGHT) {
814 bv->owner()->clearMessage();
815 } else if (result == FINISHED) {
816 bv->owner()->clearMessage();
822 // --- Cursor Movements ----------------------------------
823 case LFUN_RIGHTSEL: {
824 int const start = hasSelection() ? sel_cell_start : actcell;
825 if (tabular.isLastCellInRow(actcell)) {
826 setSelection(start, actcell);
831 // if we are starting a selection, only select
832 // the current cell at the beginning
833 if (hasSelection()) {
834 moveRight(bv, false);
837 setSelection(start, end);
838 updateLocal(bv, FULL);
842 result = moveRight(bv);
845 updateLocal(bv, FULL);
848 int const start = hasSelection() ? sel_cell_start : actcell;
849 if (tabular.isFirstCellInRow(actcell)) {
850 setSelection(start, actcell);
855 // if we are starting a selection, only select
856 // the current cell at the beginning
857 if (hasSelection()) {
861 setSelection(start, end);
862 updateLocal(bv, FULL);
866 result = moveLeft(bv);
869 updateLocal(bv, FULL);
872 int const start = hasSelection() ? sel_cell_start : actcell;
873 int const ocell = actcell;
874 // if we are starting a selection, only select
875 // the current cell at the beginning
876 if (hasSelection()) {
878 if ((ocell == sel_cell_end) ||
879 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
880 setSelection(start, tabular.getCellBelow(sel_cell_end));
882 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
884 setSelection(start, start);
886 updateLocal(bv, FULL);
890 result = moveDown(bv, old_locking_inset != 0);
893 updateLocal(bv, FULL);
897 int const start = hasSelection() ? sel_cell_start : actcell;
898 int const ocell = actcell;
899 // if we are starting a selection, only select
900 // the current cell at the beginning
901 if (hasSelection()) {
903 if ((ocell == sel_cell_end) ||
904 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
905 setSelection(start, tabular.getCellAbove(sel_cell_end));
907 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
909 setSelection(start, start);
911 updateLocal(bv, FULL);
915 result = moveUp(bv, old_locking_inset != 0);
918 updateLocal(bv, FULL);
921 UpdateCodes code = CURSOR;
927 unlockInsetInInset(bv, the_locking_inset);
928 if (bv->text->top_y() + bv->painter().paperHeight() <
929 (top_baseline + tabular.getHeightOfTabular()))
931 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
933 actcell = tabular.getCellBelow(first_visible_cell) + column;
935 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
938 updateLocal(bv, code);
942 UpdateCodes code = CURSOR;
948 unlockInsetInInset(bv, the_locking_inset);
949 if (top_baseline < 0) {
950 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
952 if (top_baseline > 0)
955 actcell = tabular.getCellBelow(first_visible_cell) + column;
960 updateLocal(bv, code);
963 // none of these make sense for insettabular,
964 // but we must catch them to prevent any
965 // selection from being confused
969 case LFUN_WORDLEFTSEL:
971 case LFUN_WORDRIGHTSEL:
973 case LFUN_DOWN_PARAGRAPH:
974 case LFUN_DOWN_PARAGRAPHSEL:
975 case LFUN_UP_PARAGRAPH:
976 case LFUN_UP_PARAGRAPHSEL:
982 case LFUN_BEGINNINGBUF:
983 case LFUN_BEGINNINGBUFSEL:
987 case LFUN_LAYOUT_TABULAR: {
988 InsetTabularMailer mailer(*this);
989 mailer.showDialog(bv);
992 case LFUN_INSET_DIALOG_UPDATE: {
993 InsetTabularMailer mailer(*this);
994 mailer.updateDialog(bv);
997 case LFUN_TABULAR_FEATURE:
998 if (!tabularFeatures(bv, arg))
999 result = UNDISPATCHED;
1001 // insert file functions
1002 case LFUN_FILE_INSERT_ASCII_PARA:
1003 case LFUN_FILE_INSERT_ASCII:
1005 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1008 if (insertAsciiString(bv, tmpstr, false))
1009 updateLocal(bv, INIT);
1011 result = UNDISPATCHED;
1014 // cut and paste functions
1016 if (!copySelection(bv))
1020 setUndo(bv, Undo::DELETE);
1021 cutSelection(bv->buffer()->params);
1022 updateLocal(bv, INIT);
1025 if (!hasSelection())
1030 case LFUN_PASTESELECTION:
1032 string const clip(bv->getClipboard());
1036 if (clip.find('\t') != string::npos) {
1040 string::size_type len = clip.length();
1041 string::size_type p = 0;
1044 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1052 maxCols = max(cols, maxCols);
1058 maxCols = max(cols, maxCols);
1059 delete paste_tabular;
1060 paste_tabular = new LyXTabular(bv->buffer()->params,
1061 this, rows, maxCols);
1062 string::size_type op = 0;
1064 int cells = paste_tabular->getNumberOfCells();
1066 while ((cell < cells) && (p < len) &&
1067 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1072 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1077 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1078 while (cols++ < maxCols)
1086 // check for the last cell if there is no trailing '\n'
1087 if ((cell < cells) && (op < len))
1088 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1091 if (!insertAsciiString(bv, clip, true))
1094 // so that the clipboard is used and it goes on
1096 // and executes LFUN_PASTESELECTION in insettext!
1097 delete paste_tabular;
1102 if (hasPasteBuffer()) {
1103 setUndo(bv, Undo::INSERT);
1105 updateLocal(bv, INIT);
1108 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1110 // handle font changing stuff on selection before we lock the inset
1111 // in the default part!
1112 result = UNDISPATCHED;
1123 case LFUN_UNDERLINE:
1124 case LFUN_FONT_SIZE:
1125 if (bv->dispatch(FuncRequest(bv, action, arg)))
1126 result = DISPATCHED;
1132 // we try to activate the actual inset and put this event down to
1133 // the insets dispatch function.
1134 if ((result == DISPATCHED) || the_locking_inset)
1137 if (activateCellInset(bv)) {
1138 // reset need_update setted in above function!
1140 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1141 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1142 unlockInsetInInset(bv, the_locking_inset);
1144 // we need to update if this was requested before
1145 updateLocal(bv, NONE);
1146 return UNDISPATCHED;
1149 // so the below CELL is not set because this is higher
1150 // priority and we get a full redraw
1154 updateLocal(bv, CELL);
1159 if (result < FINISHED) {
1160 if (!the_locking_inset) {
1161 if (bv->fitCursor())
1162 updateLocal(bv, FULL);
1165 bv->unlockInset(this);
1170 int InsetTabular::latex(Buffer const * buf, ostream & os,
1171 LatexRunParams const & runparams) const
1173 return tabular.latex(buf, os, runparams);
1177 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1180 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1182 return tabular.ascii(buf, os, 0, false,0);
1186 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1189 int const ret = tabular.ascii(buf,os,
1190 (int)parOwner()->params().depth(),
1197 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1202 // if the table is inside a float it doesn't need the informaltable
1203 // wrapper. Search for it.
1204 for(master = owner();
1205 master && master->lyxCode() != Inset::FLOAT_CODE;
1206 master = master->owner());
1209 os << "<informaltable>";
1214 ret+= tabular.docbook(buf, os, mixcont);
1216 os << "</informaltable>";
1225 void InsetTabular::validate(LaTeXFeatures & features) const
1227 tabular.validate(features);
1231 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1237 bool changed = false;
1239 // FIXME: since InsetText ignores this anyway, it doesn't
1240 // matter what we pass it. Ugly
1243 // if we have a locking_inset we should have to check only this cell for
1244 // change so I'll try this to have a boost, but who knows ;)
1245 if ((need_update != INIT) &&
1246 (the_locking_inset == tabular.getCellInset(actcell))) {
1247 for(int i = 0; i < tabular.columns(); ++i) {
1249 MetricsInfo mi(bv, font);
1250 tabular.getCellInset(actrow, i)->metrics(mi, dim);
1251 maxAsc = max(dim.asc, maxAsc);
1252 maxDesc = max(dim.des, maxDesc);
1254 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1255 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1256 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1259 for (int i = 0; i < tabular.rows(); ++i) {
1262 for (int j = 0; j < tabular.columns(); ++j) {
1263 if (tabular.isPartOfMultiColumn(i,j))
1267 MetricsInfo mi(bv, font);
1268 tabular.getCellInset(cell)->metrics(mi, dim);
1269 maxAsc = max(maxAsc, dim.asc);
1270 maxDesc = max(maxDesc, dim.des);
1271 changed = tabular.setWidthOfCell(cell, dim.wid) || changed;
1273 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1274 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1282 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1284 if (the_locking_inset) {
1285 the_locking_inset->getCursor(bv, x, y);
1290 y = cursor_.y() + InsetTabular::y();
1293 int desc = tabular.getDescentOfRow(actrow);
1295 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1297 y += ADD_TO_HEIGHT * 2;
1298 y += TEXT_TO_INSET_OFFSET;
1302 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1304 if (the_locking_inset) {
1305 the_locking_inset->getCursorPos(bv, x, y);
1308 x = cursor_.x() - top_x;
1313 void InsetTabular::fitInsetCursor(BufferView * bv) const
1315 if (the_locking_inset) {
1316 int old_top_y = bv->text->top_y();
1317 the_locking_inset->fitInsetCursor(bv);
1318 if (old_top_y != bv->text->top_y())
1324 int const asc = font_metrics::maxAscent(font);
1325 int const desc = font_metrics::maxDescent(font);
1328 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1333 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1337 actcell = actrow = actcol = 0;
1338 int ly = tabular.getDescentOfRow(actrow);
1340 // first search the right row
1341 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1342 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1343 tabular.getAscentOfRow(actrow + 1) +
1344 tabular.getAdditionalHeight(actrow + 1));
1346 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1348 actcell = tabular.getCellNumber(actrow, actcol);
1350 // now search the right column
1351 int lx = tabular.getWidthOfColumn(actcell) -
1352 tabular.getAdditionalWidth(actcell);
1353 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1354 lx += tabular.getWidthOfColumn(actcell + 1)
1355 + tabular.getAdditionalWidth(actcell);
1357 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1362 int InsetTabular::getCellXPos(int cell) const
1366 for (; !tabular.isFirstCellInRow(c); --c)
1368 int lx = tabular.getWidthOfColumn(cell);
1369 for (; c < cell; ++c) {
1370 lx += tabular.getWidthOfColumn(c);
1372 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1376 void InsetTabular::resetPos(BufferView * bv) const
1378 #ifdef WITH_WARNINGS
1379 #warning This should be fixed in the right manner (20011128 Jug)
1381 // fast hack to fix infinite repaintings!
1382 if (in_reset_pos > 0)
1386 actcol = tabular.column_of_cell(actcell);
1389 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1390 if (tabular.isLastCellInRow(cell)) {
1391 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1392 tabular.getAscentOfRow(actrow + 1) +
1393 tabular.getAdditionalHeight(actrow + 1));
1397 if (!locked || nodraw()) {
1398 if (the_locking_inset)
1399 inset_y = cursor_.y();
1402 // we need this only from here on!!!
1404 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1405 int new_x = getCellXPos(actcell);
1406 int old_x = cursor_.x();
1409 // cursor.x(getCellXPos(actcell) + offset);
1410 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1411 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1414 updateLocal(bv, FULL);
1415 } else if (the_locking_inset &&
1416 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1418 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1419 if (xx > (bv->workWidth()-20)) {
1420 scroll(bv, -(xx - bv->workWidth() + 60));
1421 updateLocal(bv, FULL);
1422 } else if (xx < 20) {
1428 updateLocal(bv, FULL);
1430 } else if ((cursor_.x() - offset) > 20 &&
1431 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1432 > (bv->workWidth() - 20)) {
1433 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1434 updateLocal(bv, FULL);
1435 } else if ((cursor_.x() - offset) < 20) {
1436 scroll(bv, 20 - cursor_.x() + offset);
1437 updateLocal(bv, FULL);
1438 } else if (scroll() && top_x > 20 &&
1439 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1440 scroll(bv, old_x - cursor_.x());
1441 updateLocal(bv, FULL);
1443 if (the_locking_inset) {
1444 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1445 inset_y = cursor_.y();
1447 if ((!the_locking_inset ||
1448 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1449 actcell != oldcell) {
1450 InsetTabular * inset = const_cast<InsetTabular *>(this);
1451 InsetTabularMailer mailer(*inset);
1452 mailer.updateDialog(bv);
1459 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1461 if (lock && !old_locking_inset) {
1462 if (activateCellInset(bv))
1465 bool moved = isRightToLeft(bv)
1466 ? movePrevCell(bv) : moveNextCell(bv);
1468 return FINISHED_RIGHT;
1469 if (lock && activateCellInset(bv))
1473 return DISPATCHED_NOUPDATE;
1477 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1479 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1482 if (lock) { // behind the inset
1483 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1487 return DISPATCHED_NOUPDATE;
1491 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1493 int const ocell = actcell;
1494 actcell = tabular.getCellAbove(actcell);
1495 if (actcell == ocell) // we moved out of the inset
1501 if (old_locking_inset) {
1502 old_locking_inset->getCursorPos(bv, x, y);
1503 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1505 if (activateCellInset(bv, x, 0))
1508 return DISPATCHED_NOUPDATE;
1512 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1514 int const ocell = actcell;
1515 actcell = tabular.getCellBelow(actcell);
1516 if (actcell == ocell) // we moved out of the inset
1517 return FINISHED_DOWN;
1522 if (old_locking_inset) {
1523 old_locking_inset->getCursorPos(bv, x, y);
1524 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1526 if (activateCellInset(bv, x, 0))
1529 return DISPATCHED_NOUPDATE;
1533 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1535 if (isRightToLeft(bv)) {
1536 if (tabular.isFirstCellInRow(actcell)) {
1537 int row = tabular.row_of_cell(actcell);
1538 if (row == tabular.rows() - 1)
1540 actcell = tabular.getLastCellInRow(row);
1541 actcell = tabular.getCellBelow(actcell);
1548 if (tabular.isLastCell(actcell))
1553 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1554 isRightToLeftPar(bv->buffer()->params);
1555 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1562 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1564 if (isRightToLeft(bv)) {
1565 if (tabular.isLastCellInRow(actcell)) {
1566 int row = tabular.row_of_cell(actcell);
1569 actcell = tabular.getFirstCellInRow(row);
1570 actcell = tabular.getCellAbove(actcell);
1572 if (tabular.isLastCell(actcell))
1577 if (!actcell) // first cell
1582 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1583 isRightToLeftPar(bv->buffer()->params);
1584 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1591 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1595 setSelection(0, tabular.getNumberOfCells() - 1);
1597 if (hasSelection()) {
1598 setUndo(bv, Undo::EDIT);
1599 bool const frozen = undo_frozen;
1602 // apply the fontchange on the whole selection
1607 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1608 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1609 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1610 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1617 updateLocal(bv, INIT);
1619 if (the_locking_inset)
1620 the_locking_inset->setFont(bv, font, tall);
1624 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1626 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1629 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1630 string const tmp = tabularFeature[i].feature;
1632 if (tmp == what.substr(0, tmp.length())) {
1633 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1634 //tabularFeatures[i].feature.length())) {
1635 action = tabularFeature[i].action;
1639 if (action == LyXTabular::LAST_ACTION)
1643 ltrim(what.substr(tabularFeature[i].feature.length()));
1644 tabularFeatures(bv, action, val);
1650 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1651 string const & special, bool & flag)
1653 if (special == "dl_above") {
1656 } else if (special == "dl_below") {
1657 ltt.bottomDL = flag;
1659 } else if (special == "empty") {
1671 void InsetTabular::tabularFeatures(BufferView * bv,
1672 LyXTabular::Feature feature,
1673 string const & value)
1679 bool setLines = false;
1680 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1681 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1684 case LyXTabular::M_ALIGN_LEFT:
1685 case LyXTabular::ALIGN_LEFT:
1686 setAlign = LYX_ALIGN_LEFT;
1688 case LyXTabular::M_ALIGN_RIGHT:
1689 case LyXTabular::ALIGN_RIGHT:
1690 setAlign = LYX_ALIGN_RIGHT;
1692 case LyXTabular::M_ALIGN_CENTER:
1693 case LyXTabular::ALIGN_CENTER:
1694 setAlign = LYX_ALIGN_CENTER;
1696 case LyXTabular::ALIGN_BLOCK:
1697 setAlign = LYX_ALIGN_BLOCK;
1699 case LyXTabular::M_VALIGN_TOP:
1700 case LyXTabular::VALIGN_TOP:
1701 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1703 case LyXTabular::M_VALIGN_BOTTOM:
1704 case LyXTabular::VALIGN_BOTTOM:
1705 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1707 case LyXTabular::M_VALIGN_CENTER:
1708 case LyXTabular::VALIGN_CENTER:
1709 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1714 if (hasSelection()) {
1715 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1717 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1718 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1720 setUndo(bv, Undo::FINISH);
1722 int row = tabular.row_of_cell(actcell);
1723 int column = tabular.column_of_cell(actcell);
1725 LyXTabular::ltType ltt;
1728 case LyXTabular::SET_PWIDTH:
1730 LyXLength const vallen(value);
1731 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1733 bool const update = (tmplen != vallen);
1734 tabular.setColumnPWidth(actcell, vallen);
1736 // We need this otherwise we won't resize
1737 // the insettext of the active cell (if any)
1738 // until later (see InsetText::do_resize)
1739 unlockInsetInInset(bv, the_locking_inset);
1742 for (int i = 0; i < tabular.rows(); ++i) {
1743 cell = tabular.getCellNumber(i,column);
1744 tabular.getCellInset(cell)->resizeLyXText(bv);
1746 updateLocal(bv, INIT);
1750 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1751 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1752 else if (!vallen.zero()
1753 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1754 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1757 case LyXTabular::SET_MPWIDTH:
1759 LyXLength const vallen(value);
1760 LyXLength const & tmplen = tabular.getPWidth(actcell);
1762 bool const update = (tmplen != vallen);
1763 tabular.setMColumnPWidth(actcell, vallen);
1765 // We need this otherwise we won't resize
1766 // the insettext of the active cell (if any)
1767 // until later (see InsetText::do_resize)
1768 unlockInsetInInset(bv, the_locking_inset);
1770 for (int i = 0; i < tabular.rows(); ++i) {
1771 tabular.getCellInset(tabular.getCellNumber(i, column))->
1774 updateLocal(bv, INIT);
1778 case LyXTabular::SET_SPECIAL_COLUMN:
1779 case LyXTabular::SET_SPECIAL_MULTI:
1780 tabular.setAlignSpecial(actcell,value,feature);
1781 updateLocal(bv, FULL);
1783 case LyXTabular::APPEND_ROW:
1784 // append the row into the tabular
1785 unlockInsetInInset(bv, the_locking_inset);
1786 tabular.appendRow(bv->buffer()->params, actcell);
1787 updateLocal(bv, INIT);
1789 case LyXTabular::APPEND_COLUMN:
1790 // append the column into the tabular
1791 unlockInsetInInset(bv, the_locking_inset);
1792 tabular.appendColumn(bv->buffer()->params, actcell);
1793 actcell = tabular.getCellNumber(row, column);
1794 updateLocal(bv, INIT);
1796 case LyXTabular::DELETE_ROW:
1797 unlockInsetInInset(bv, the_locking_inset);
1798 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1799 tabular.deleteRow(sel_row_start);
1801 if (sel_row_start >= tabular.rows())
1803 actcell = tabular.getCellNumber(sel_row_start, column);
1805 updateLocal(bv, INIT);
1807 case LyXTabular::DELETE_COLUMN:
1808 unlockInsetInInset(bv, the_locking_inset);
1809 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1810 tabular.deleteColumn(sel_col_start);
1812 if (sel_col_start >= tabular.columns())
1814 actcell = tabular.getCellNumber(row, sel_col_start);
1816 updateLocal(bv, INIT);
1818 case LyXTabular::M_TOGGLE_LINE_TOP:
1820 case LyXTabular::TOGGLE_LINE_TOP:
1822 bool lineSet = !tabular.topLine(actcell, flag);
1823 for (int i = sel_row_start; i <= sel_row_end; ++i)
1824 for (int j = sel_col_start; j <= sel_col_end; ++j)
1826 tabular.getCellNumber(i, j),
1828 updateLocal(bv, INIT);
1832 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1834 case LyXTabular::TOGGLE_LINE_BOTTOM:
1836 bool lineSet = !tabular.bottomLine(actcell, flag);
1837 for (int i = sel_row_start; i <= sel_row_end; ++i)
1838 for (int j = sel_col_start; j <= sel_col_end; ++j)
1839 tabular.setBottomLine(
1840 tabular.getCellNumber(i, j),
1843 updateLocal(bv, INIT);
1847 case LyXTabular::M_TOGGLE_LINE_LEFT:
1849 case LyXTabular::TOGGLE_LINE_LEFT:
1851 bool lineSet = !tabular.leftLine(actcell, flag);
1852 for (int i = sel_row_start; i <= sel_row_end; ++i)
1853 for (int j = sel_col_start; j <= sel_col_end; ++j)
1854 tabular.setLeftLine(
1855 tabular.getCellNumber(i,j),
1858 updateLocal(bv, INIT);
1862 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1864 case LyXTabular::TOGGLE_LINE_RIGHT:
1866 bool lineSet = !tabular.rightLine(actcell, flag);
1867 for (int i = sel_row_start; i <= sel_row_end; ++i)
1868 for (int j = sel_col_start; j <= sel_col_end; ++j)
1869 tabular.setRightLine(
1870 tabular.getCellNumber(i,j),
1873 updateLocal(bv, INIT);
1877 case LyXTabular::M_ALIGN_LEFT:
1878 case LyXTabular::M_ALIGN_RIGHT:
1879 case LyXTabular::M_ALIGN_CENTER:
1881 case LyXTabular::ALIGN_LEFT:
1882 case LyXTabular::ALIGN_RIGHT:
1883 case LyXTabular::ALIGN_CENTER:
1884 case LyXTabular::ALIGN_BLOCK:
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.setAlignment(
1888 tabular.getCellNumber(i, j),
1891 updateLocal(bv, INIT);
1893 case LyXTabular::M_VALIGN_TOP:
1894 case LyXTabular::M_VALIGN_BOTTOM:
1895 case LyXTabular::M_VALIGN_CENTER:
1897 case LyXTabular::VALIGN_TOP:
1898 case LyXTabular::VALIGN_BOTTOM:
1899 case LyXTabular::VALIGN_CENTER:
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.setVAlignment(
1903 tabular.getCellNumber(i, j),
1905 updateLocal(bv, INIT);
1907 case LyXTabular::MULTICOLUMN:
1909 if (sel_row_start != sel_row_end) {
1910 #ifdef WITH_WARNINGS
1911 #warning Need I say it ? This is horrible.
1913 Alert::error(_("Error setting multicolumn"),
1914 _("You cannot set multicolumn vertically."));
1917 // just multicol for one Single Cell
1918 if (!hasSelection()) {
1919 // check wether we are completly in a multicol
1920 if (tabular.isMultiColumn(actcell)) {
1921 tabular.unsetMultiColumn(actcell);
1922 updateLocal(bv, INIT);
1924 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1925 updateLocal(bv, CELL);
1929 // we have a selection so this means we just add all this
1930 // cells to form a multicolumn cell
1934 if (sel_cell_start > sel_cell_end) {
1935 s_start = sel_cell_end;
1936 s_end = sel_cell_start;
1938 s_start = sel_cell_start;
1939 s_end = sel_cell_end;
1941 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1944 updateLocal(bv, INIT);
1947 case LyXTabular::SET_ALL_LINES:
1949 case LyXTabular::UNSET_ALL_LINES:
1950 for (int i = sel_row_start; i <= sel_row_end; ++i)
1951 for (int j = sel_col_start; j <= sel_col_end; ++j)
1952 tabular.setAllLines(
1953 tabular.getCellNumber(i,j), setLines);
1954 updateLocal(bv, INIT);
1956 case LyXTabular::SET_LONGTABULAR:
1957 tabular.setLongTabular(true);
1958 updateLocal(bv, INIT); // because this toggles displayed
1960 case LyXTabular::UNSET_LONGTABULAR:
1961 tabular.setLongTabular(false);
1962 updateLocal(bv, INIT); // because this toggles displayed
1964 case LyXTabular::SET_ROTATE_TABULAR:
1965 tabular.setRotateTabular(true);
1967 case LyXTabular::UNSET_ROTATE_TABULAR:
1968 tabular.setRotateTabular(false);
1970 case LyXTabular::SET_ROTATE_CELL:
1971 for (int i = sel_row_start; i <= sel_row_end; ++i)
1972 for (int j = sel_col_start; j<=sel_col_end; ++j)
1973 tabular.setRotateCell(
1974 tabular.getCellNumber(i, j),
1977 case LyXTabular::UNSET_ROTATE_CELL:
1978 for (int i = sel_row_start; i <= sel_row_end; ++i)
1979 for (int j = sel_col_start; j <= sel_col_end; ++j)
1980 tabular.setRotateCell(
1981 tabular.getCellNumber(i, j), false);
1983 case LyXTabular::SET_USEBOX:
1985 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1986 if (val == tabular.getUsebox(actcell))
1987 val = LyXTabular::BOX_NONE;
1988 for (int i = sel_row_start; i <= sel_row_end; ++i)
1989 for (int j = sel_col_start; j <= sel_col_end; ++j)
1991 tabular.getCellNumber(i, j), val);
1994 case LyXTabular::UNSET_LTFIRSTHEAD:
1996 case LyXTabular::SET_LTFIRSTHEAD:
1997 (void)tabular.getRowOfLTFirstHead(row, ltt);
1998 checkLongtableSpecial(ltt, value, flag);
1999 tabular.setLTHead(row, flag, ltt, true);
2001 case LyXTabular::UNSET_LTHEAD:
2003 case LyXTabular::SET_LTHEAD:
2004 (void)tabular.getRowOfLTHead(row, ltt);
2005 checkLongtableSpecial(ltt, value, flag);
2006 tabular.setLTHead(row, flag, ltt, false);
2008 case LyXTabular::UNSET_LTFOOT:
2010 case LyXTabular::SET_LTFOOT:
2011 (void)tabular.getRowOfLTFoot(row, ltt);
2012 checkLongtableSpecial(ltt, value, flag);
2013 tabular.setLTFoot(row, flag, ltt, false);
2015 case LyXTabular::UNSET_LTLASTFOOT:
2017 case LyXTabular::SET_LTLASTFOOT:
2018 (void)tabular.getRowOfLTLastFoot(row, ltt);
2019 checkLongtableSpecial(ltt, value, flag);
2020 tabular.setLTFoot(row, flag, ltt, true);
2022 case LyXTabular::SET_LTNEWPAGE:
2024 bool what = !tabular.getLTNewPage(row);
2025 tabular.setLTNewPage(row, what);
2028 // dummy stuff just to avoid warnings
2029 case LyXTabular::LAST_ACTION:
2033 InsetTabularMailer mailer(*this);
2034 mailer.updateDialog(bv);
2038 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2041 UpdatableInset * inset =
2042 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2043 LyXFont font(LyXFont::ALL_SANE);
2045 x = inset->x() + inset->width(bv, font);
2046 y = inset->descent(bv, font);
2048 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2049 //inset_y = cursor.y();
2050 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2051 if (!the_locking_inset)
2053 updateLocal(bv, CELL);
2054 return (the_locking_inset != 0);
2058 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2059 mouse_button::state button)
2061 inset_x = cursor_.x()
2062 - top_x + tabular.getBeginningOfTextInCell(actcell);
2063 inset_y = cursor_.y();
2064 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2068 bool InsetTabular::insetHit(BufferView *, int x, int) const
2071 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2075 // This returns paperWidth() if the cell-width is unlimited or the width
2076 // in pixels if we have a pwidth for this cell.
2077 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2079 LyXLength const len = tabular.getPWidth(cell);
2083 return len.inPixels(latexTextWidth(bv));
2087 int InsetTabular::getMaxWidth(BufferView * bv,
2088 UpdatableInset const * inset) const
2090 int cell = tabular.getCellFromInset(inset, actcell);
2093 lyxerr << "Own inset not found, shouldn't really happen!"
2098 int w = getMaxWidthOfCell(bv, cell);
2100 // because the inset then subtracts it's top_x and owner->x()
2101 w += (inset->x() - top_x);
2108 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2110 resizeLyXText(bv, recursive);
2114 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2117 for(int i = 0; i < tabular.rows(); ++i) {
2118 for(int j = 0; j < tabular.columns(); ++j) {
2119 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2127 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2128 bool const recursive) const
2130 if (the_locking_inset)
2131 return the_locking_inset->getLyXText(bv, recursive);
2133 // if we're locked lock the actual insettext and return it's LyXText!!!
2135 UpdatableInset * inset =
2136 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2137 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2138 return the_locking_inset->getLyXText(bv, recursive);
2141 return Inset::getLyXText(bv, recursive);
2145 bool InsetTabular::showInsetDialog(BufferView * bv) const
2147 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2148 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2149 InsetTabularMailer mailer(*tmp);
2150 mailer.showDialog(bv);
2156 void InsetTabular::openLayoutDialog(BufferView * bv) const
2158 if (the_locking_inset) {
2159 InsetTabular * i = static_cast<InsetTabular *>
2160 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2162 i->openLayoutDialog(bv);
2166 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2167 InsetTabularMailer mailer(*tmp);
2168 mailer.showDialog(bv);
2173 // function returns an object as defined in func_status.h:
2174 // states OK, Unknown, Disabled, On, Off.
2176 FuncStatus InsetTabular::getStatus(string const & what) const
2178 int action = LyXTabular::LAST_ACTION;
2182 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2183 string const tmp = tabularFeature[i].feature;
2184 if (tmp == what.substr(0, tmp.length())) {
2185 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2186 // tabularFeatures[i].feature.length())) {
2187 action = tabularFeature[i].action;
2191 if (action == LyXTabular::LAST_ACTION) {
2193 return status.unknown(true);
2196 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2201 LyXTabular::ltType dummyltt;
2204 if (hasSelection()) {
2205 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2207 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2211 case LyXTabular::SET_PWIDTH:
2212 case LyXTabular::SET_MPWIDTH:
2213 case LyXTabular::SET_SPECIAL_COLUMN:
2214 case LyXTabular::SET_SPECIAL_MULTI:
2215 case LyXTabular::APPEND_ROW:
2216 case LyXTabular::APPEND_COLUMN:
2217 case LyXTabular::DELETE_ROW:
2218 case LyXTabular::DELETE_COLUMN:
2219 case LyXTabular::SET_ALL_LINES:
2220 case LyXTabular::UNSET_ALL_LINES:
2221 return status.clear();
2223 case LyXTabular::MULTICOLUMN:
2224 status.setOnOff(tabular.isMultiColumn(actcell));
2226 case LyXTabular::M_TOGGLE_LINE_TOP:
2228 case LyXTabular::TOGGLE_LINE_TOP:
2229 status.setOnOff(tabular.topLine(actcell, flag));
2231 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2233 case LyXTabular::TOGGLE_LINE_BOTTOM:
2234 status.setOnOff(tabular.bottomLine(actcell, flag));
2236 case LyXTabular::M_TOGGLE_LINE_LEFT:
2238 case LyXTabular::TOGGLE_LINE_LEFT:
2239 status.setOnOff(tabular.leftLine(actcell, flag));
2241 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2243 case LyXTabular::TOGGLE_LINE_RIGHT:
2244 status.setOnOff(tabular.rightLine(actcell, flag));
2246 case LyXTabular::M_ALIGN_LEFT:
2248 case LyXTabular::ALIGN_LEFT:
2249 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2251 case LyXTabular::M_ALIGN_RIGHT:
2253 case LyXTabular::ALIGN_RIGHT:
2254 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2256 case LyXTabular::M_ALIGN_CENTER:
2258 case LyXTabular::ALIGN_CENTER:
2259 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2261 case LyXTabular::ALIGN_BLOCK:
2262 status.disabled(tabular.getPWidth(actcell).zero());
2263 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2265 case LyXTabular::M_VALIGN_TOP:
2267 case LyXTabular::VALIGN_TOP:
2268 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2270 case LyXTabular::M_VALIGN_BOTTOM:
2272 case LyXTabular::VALIGN_BOTTOM:
2273 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2275 case LyXTabular::M_VALIGN_CENTER:
2277 case LyXTabular::VALIGN_CENTER:
2278 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2280 case LyXTabular::SET_LONGTABULAR:
2281 status.setOnOff(tabular.isLongTabular());
2283 case LyXTabular::UNSET_LONGTABULAR:
2284 status.setOnOff(!tabular.isLongTabular());
2286 case LyXTabular::SET_ROTATE_TABULAR:
2287 status.setOnOff(tabular.getRotateTabular());
2289 case LyXTabular::UNSET_ROTATE_TABULAR:
2290 status.setOnOff(!tabular.getRotateTabular());
2292 case LyXTabular::SET_ROTATE_CELL:
2293 status.setOnOff(tabular.getRotateCell(actcell));
2295 case LyXTabular::UNSET_ROTATE_CELL:
2296 status.setOnOff(!tabular.getRotateCell(actcell));
2298 case LyXTabular::SET_USEBOX:
2299 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2301 case LyXTabular::SET_LTFIRSTHEAD:
2302 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2304 case LyXTabular::SET_LTHEAD:
2305 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2307 case LyXTabular::SET_LTFOOT:
2308 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2310 case LyXTabular::SET_LTLASTFOOT:
2311 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2313 case LyXTabular::SET_LTNEWPAGE:
2314 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2318 status.disabled(true);
2325 void InsetTabular::getLabelList(std::vector<string> & list) const
2327 tabular.getLabelList(list);
2331 bool InsetTabular::copySelection(BufferView * bv)
2333 if (!hasSelection())
2336 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2337 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2338 if (sel_col_start > sel_col_end) {
2339 sel_col_start = sel_col_end;
2340 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2342 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2344 int const columns = sel_col_end - sel_col_start + 1;
2346 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2347 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2348 if (sel_row_start > sel_row_end) {
2349 swap(sel_row_start, sel_row_end);
2351 int const rows = sel_row_end - sel_row_start + 1;
2353 delete paste_tabular;
2354 paste_tabular = new LyXTabular(bv->buffer()->params,
2355 this, tabular); // rows, columns);
2356 for (int i = 0; i < sel_row_start; ++i)
2357 paste_tabular->deleteRow(0);
2358 while (paste_tabular->rows() > rows)
2359 paste_tabular->deleteRow(rows);
2360 paste_tabular->setTopLine(0, true, true);
2361 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2363 for (int i = 0; i < sel_col_start; ++i)
2364 paste_tabular->deleteColumn(0);
2365 while (paste_tabular->columns() > columns)
2366 paste_tabular->deleteColumn(columns);
2367 paste_tabular->setLeftLine(0, true, true);
2368 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2372 paste_tabular->ascii(bv->buffer(), sstr,
2373 (int)parOwner()->params().depth(), true, '\t');
2374 bv->stuffClipboard(STRCONV(sstr.str()));
2379 bool InsetTabular::pasteSelection(BufferView * bv)
2384 for (int r1 = 0, r2 = actrow;
2385 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2387 for(int c1 = 0, c2 = actcol;
2388 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2390 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2391 tabular.isPartOfMultiColumn(r2,c2))
2393 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2397 if (tabular.isPartOfMultiColumn(r2,c2)) {
2401 int const n1 = paste_tabular->getCellNumber(r1, c1);
2402 int const n2 = tabular.getCellNumber(r2, c2);
2403 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2404 tabular.getCellInset(n2)->setOwner(this);
2405 tabular.getCellInset(n2)->deleteLyXText(bv);
2406 tabular.getCellInset(n2)->markNew();
2413 bool InsetTabular::cutSelection(BufferParams const & bp)
2415 if (!hasSelection())
2418 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2419 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2420 if (sel_col_start > sel_col_end) {
2421 sel_col_start = sel_col_end;
2422 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2424 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2426 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2427 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2428 if (sel_row_start > sel_row_end) {
2429 swap(sel_row_start, sel_row_end);
2431 if (sel_cell_start > sel_cell_end) {
2432 swap(sel_cell_start, sel_cell_end);
2434 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2435 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2436 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2443 bool InsetTabular::isRightToLeft(BufferView * bv)
2445 return bv->getParentLanguage(this)->RightToLeft();
2449 bool InsetTabular::nodraw() const
2451 if (!UpdatableInset::nodraw() && the_locking_inset)
2452 return the_locking_inset->nodraw();
2453 return UpdatableInset::nodraw();
2457 int InsetTabular::scroll(bool recursive) const
2459 int sx = UpdatableInset::scroll(false);
2461 if (recursive && the_locking_inset)
2462 sx += the_locking_inset->scroll(recursive);
2468 void InsetTabular::getSelection(int & srow, int & erow,
2469 int & scol, int & ecol) const
2471 int const start = hasSelection() ? sel_cell_start : actcell;
2472 int const end = hasSelection() ? sel_cell_end : actcell;
2474 srow = tabular.row_of_cell(start);
2475 erow = tabular.row_of_cell(end);
2480 scol = tabular.column_of_cell(start);
2481 ecol = tabular.column_of_cell(end);
2485 ecol = tabular.right_column_of_cell(end);
2490 ParagraphList * InsetTabular::getParagraphs(int i) const
2492 return (i < tabular.getNumberOfCells())
2493 ? tabular.getCellInset(i)->getParagraphs(0)
2498 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2500 if (the_locking_inset)
2501 return the_locking_inset->cursor(bv);
2502 return Inset::cursor(bv);
2506 Inset * InsetTabular::getInsetFromID(int id_arg) const
2509 return const_cast<InsetTabular *>(this);
2512 for(int i = 0; i < tabular.rows(); ++i) {
2513 for(int j = 0; j < tabular.columns(); ++j) {
2514 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2523 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2526 if (the_locking_inset) {
2527 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2528 if (!word.word().empty()) {
2532 if (tabular.isLastCell(actcell)) {
2533 bv->unlockInset(const_cast<InsetTabular *>(this));
2535 return WordLangTuple();
2539 // otherwise we have to lock the next inset and ask for it's selecttion
2540 UpdatableInset * inset =
2541 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2542 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2543 WordLangTuple word(selectNextWordInt(bv, value));
2545 if (!word.word().empty())
2551 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2553 // when entering this function the inset should be ALWAYS locked!
2554 Assert(the_locking_inset);
2556 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2557 if (!word.word().empty())
2560 if (tabular.isLastCell(actcell)) {
2561 bv->unlockInset(const_cast<InsetTabular *>(this));
2562 return WordLangTuple();
2565 // otherwise we have to lock the next inset and ask for it's selecttion
2566 UpdatableInset * inset =
2567 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2568 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2569 return selectNextWordInt(bv, value);
2573 void InsetTabular::selectSelectedWord(BufferView * bv)
2575 if (the_locking_inset) {
2576 the_locking_inset->selectSelectedWord(bv);
2583 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2585 if (the_locking_inset) {
2586 the_locking_inset->toggleSelection(bv, kill_selection);
2591 void InsetTabular::markErased()
2595 while (cell < tabular.getNumberOfCells()) {
2596 InsetText * inset = tabular.getCellInset(cell);
2597 inset->markErased();
2603 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2605 if (the_locking_inset) {
2606 if (the_locking_inset->nextChange(bv, length)) {
2607 updateLocal(bv, CELL);
2610 if (tabular.isLastCell(actcell))
2614 InsetText * inset = tabular.getCellInset(actcell);
2615 if (inset->nextChange(bv, length)) {
2616 updateLocal(bv, FULL);
2619 while (!tabular.isLastCell(actcell)) {
2621 inset = tabular.getCellInset(actcell);
2622 if (inset->nextChange(bv, length)) {
2623 updateLocal(bv, FULL);
2631 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2635 if (the_locking_inset) {
2636 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2637 updateLocal(bv, CELL);
2640 if (tabular.isLastCell(actcell))
2644 InsetText * inset = tabular.getCellInset(cell);
2645 if (inset->searchForward(bv, str, cs, mw)) {
2646 updateLocal(bv, FULL);
2649 while (!tabular.isLastCell(cell)) {
2651 inset = tabular.getCellInset(cell);
2652 if (inset->searchForward(bv, str, cs, mw)) {
2653 updateLocal(bv, FULL);
2661 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2664 int cell = tabular.getNumberOfCells();
2665 if (the_locking_inset) {
2666 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2667 updateLocal(bv, CELL);
2675 InsetText * inset = tabular.getCellInset(cell);
2676 if (inset->searchBackward(bv, str, cs, mw)) {
2677 updateLocal(bv, CELL);
2685 bool InsetTabular::insetAllowed(Inset::Code code) const
2687 if (the_locking_inset)
2688 return the_locking_inset->insetAllowed(code);
2689 // we return true here because if the inset is not locked someone
2690 // wants to insert something in one of our insettexts and we generally
2696 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2698 const int cell = tabular.getCellFromInset(in, actcell);
2701 return tabular.getPWidth(cell).zero();
2703 // well we didn't obviously find it so maybe our owner knows more
2705 return owner()->forceDefaultParagraphs(in);
2706 // if we're here there is really something strange going on!!!
2710 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2713 if (buf.length() <= 0)
2719 string::size_type len = buf.length();
2720 string::size_type p = 0;
2723 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2732 maxCols = max(cols, maxCols);
2738 maxCols = max(cols, maxCols);
2739 LyXTabular * loctab;
2744 delete paste_tabular;
2745 paste_tabular = new LyXTabular(bv->buffer()->params,
2746 this, rows, maxCols);
2747 loctab = paste_tabular;
2756 string::size_type op = 0;
2757 int cells = loctab->getNumberOfCells();
2760 rows = loctab->rows();
2761 int const columns = loctab->columns();
2763 while ((cell < cells) && (p < len) && (row < rows) &&
2764 (p = buf.find_first_of("\t\n", p)) != string::npos)
2770 // we can only set this if we are not too far right
2771 if (cols < columns) {
2772 InsetText * ti = loctab->getCellInset(cell);
2773 LyXFont const font = ti->getLyXText(bv)->
2774 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2775 ti->setText(buf.substr(op, p - op), font);
2781 // we can only set this if we are not too far right
2782 if (cols < columns) {
2783 InsetText * ti = loctab->getCellInset(cell);
2784 LyXFont const font = ti->getLyXText(bv)->
2785 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2786 ti->setText(buf.substr(op, p - op), font);
2791 cell = loctab->getCellNumber(row, cols);
2797 // check for the last cell if there is no trailing '\n'
2798 if ((cell < cells) && (op < len)) {
2799 InsetText * ti = loctab->getCellInset(cell);
2800 LyXFont const font = ti->getLyXText(bv)->
2801 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2802 ti->setText(buf.substr(op, len - op), font);
2809 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2811 int const rows = tabular.rows();
2812 int const columns = tabular.columns();
2813 for (int i = 0; i < rows; ++i) {
2814 for (int j = 0; j < columns; ++j) {
2815 tabular.getCellInset(i,j)->addPreview(loader);
2821 string const InsetTabularMailer:: name_("tabular");
2823 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2828 string const InsetTabularMailer::inset2string() const
2830 return params2string(inset_);
2834 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2836 istringstream data(STRCONV(in));
2838 lex.setStream(data);
2840 #warning CHECK verify that this is a sane value to return.
2846 string const token = lex.getString();
2854 string const token = lex.getString();
2855 if (token != "\\active_cell")
2858 cell = lex.getInteger();
2861 // This is part of the inset proper that is usually swallowed
2862 // by Buffer::readInset
2865 string const token = lex.getString();
2866 if (token != "Tabular")
2873 Buffer const * const buffer = inset.buffer();
2875 inset.read(buffer, lex);
2877 // We can't set the active cell, but we can tell the frontend
2883 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2885 Buffer const * const buffer = inset.buffer();
2890 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2891 inset.write(buffer, data);
2892 data << "\\end_inset\n";
2893 return STRCONV(data.str());