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) {
1248 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1250 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1253 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1254 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1255 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1258 for (int i = 0; i < tabular.rows(); ++i) {
1261 for (int j = 0; j < tabular.columns(); ++j) {
1262 if (tabular.isPartOfMultiColumn(i,j))
1265 inset = tabular.getCellInset(cell);
1266 maxAsc = max(maxAsc, inset->ascent(bv, font));
1267 maxDesc = max(maxDesc, inset->descent(bv, font));
1268 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1270 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1271 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1279 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1281 if (the_locking_inset) {
1282 the_locking_inset->getCursor(bv, x, y);
1287 y = cursor_.y() + InsetTabular::y();
1290 int desc = tabular.getDescentOfRow(actrow);
1292 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1294 y += ADD_TO_HEIGHT * 2;
1295 y += TEXT_TO_INSET_OFFSET;
1299 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1301 if (the_locking_inset) {
1302 the_locking_inset->getCursorPos(bv, x, y);
1305 x = cursor_.x() - top_x;
1310 void InsetTabular::fitInsetCursor(BufferView * bv) const
1312 if (the_locking_inset) {
1313 int old_top_y = bv->text->top_y();
1314 the_locking_inset->fitInsetCursor(bv);
1315 if (old_top_y != bv->text->top_y())
1321 int const asc = font_metrics::maxAscent(font);
1322 int const desc = font_metrics::maxDescent(font);
1325 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1330 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1334 actcell = actrow = actcol = 0;
1335 int ly = tabular.getDescentOfRow(actrow);
1337 // first search the right row
1338 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1339 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1340 tabular.getAscentOfRow(actrow + 1) +
1341 tabular.getAdditionalHeight(actrow + 1));
1343 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1345 actcell = tabular.getCellNumber(actrow, actcol);
1347 // now search the right column
1348 int lx = tabular.getWidthOfColumn(actcell) -
1349 tabular.getAdditionalWidth(actcell);
1350 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1351 lx += tabular.getWidthOfColumn(actcell + 1)
1352 + tabular.getAdditionalWidth(actcell);
1354 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1359 int InsetTabular::getCellXPos(int cell) const
1363 for (; !tabular.isFirstCellInRow(c); --c)
1365 int lx = tabular.getWidthOfColumn(cell);
1366 for (; c < cell; ++c) {
1367 lx += tabular.getWidthOfColumn(c);
1369 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1373 void InsetTabular::resetPos(BufferView * bv) const
1375 #ifdef WITH_WARNINGS
1376 #warning This should be fixed in the right manner (20011128 Jug)
1378 // fast hack to fix infinite repaintings!
1379 if (in_reset_pos > 0)
1383 actcol = tabular.column_of_cell(actcell);
1386 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1387 if (tabular.isLastCellInRow(cell)) {
1388 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1389 tabular.getAscentOfRow(actrow + 1) +
1390 tabular.getAdditionalHeight(actrow + 1));
1394 if (!locked || nodraw()) {
1395 if (the_locking_inset)
1396 inset_y = cursor_.y();
1399 // we need this only from here on!!!
1401 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1402 int new_x = getCellXPos(actcell);
1403 int old_x = cursor_.x();
1406 // cursor.x(getCellXPos(actcell) + offset);
1407 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1408 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1411 updateLocal(bv, FULL);
1412 } else if (the_locking_inset &&
1413 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1415 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1416 if (xx > (bv->workWidth()-20)) {
1417 scroll(bv, -(xx - bv->workWidth() + 60));
1418 updateLocal(bv, FULL);
1419 } else if (xx < 20) {
1425 updateLocal(bv, FULL);
1427 } else if ((cursor_.x() - offset) > 20 &&
1428 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1429 > (bv->workWidth() - 20)) {
1430 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1431 updateLocal(bv, FULL);
1432 } else if ((cursor_.x() - offset) < 20) {
1433 scroll(bv, 20 - cursor_.x() + offset);
1434 updateLocal(bv, FULL);
1435 } else if (scroll() && top_x > 20 &&
1436 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1437 scroll(bv, old_x - cursor_.x());
1438 updateLocal(bv, FULL);
1440 if (the_locking_inset) {
1441 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1442 inset_y = cursor_.y();
1444 if ((!the_locking_inset ||
1445 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1446 actcell != oldcell) {
1447 InsetTabular * inset = const_cast<InsetTabular *>(this);
1448 InsetTabularMailer mailer(*inset);
1449 mailer.updateDialog(bv);
1456 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1458 if (lock && !old_locking_inset) {
1459 if (activateCellInset(bv))
1462 bool moved = isRightToLeft(bv)
1463 ? movePrevCell(bv) : moveNextCell(bv);
1465 return FINISHED_RIGHT;
1466 if (lock && activateCellInset(bv))
1470 return DISPATCHED_NOUPDATE;
1474 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1476 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1479 if (lock) { // behind the inset
1480 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1484 return DISPATCHED_NOUPDATE;
1488 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1490 int const ocell = actcell;
1491 actcell = tabular.getCellAbove(actcell);
1492 if (actcell == ocell) // we moved out of the inset
1498 if (old_locking_inset) {
1499 old_locking_inset->getCursorPos(bv, x, y);
1500 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1502 if (activateCellInset(bv, x, 0))
1505 return DISPATCHED_NOUPDATE;
1509 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1511 int const ocell = actcell;
1512 actcell = tabular.getCellBelow(actcell);
1513 if (actcell == ocell) // we moved out of the inset
1514 return FINISHED_DOWN;
1519 if (old_locking_inset) {
1520 old_locking_inset->getCursorPos(bv, x, y);
1521 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1523 if (activateCellInset(bv, x, 0))
1526 return DISPATCHED_NOUPDATE;
1530 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1532 if (isRightToLeft(bv)) {
1533 if (tabular.isFirstCellInRow(actcell)) {
1534 int row = tabular.row_of_cell(actcell);
1535 if (row == tabular.rows() - 1)
1537 actcell = tabular.getLastCellInRow(row);
1538 actcell = tabular.getCellBelow(actcell);
1545 if (tabular.isLastCell(actcell))
1550 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1551 isRightToLeftPar(bv->buffer()->params);
1552 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1559 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1561 if (isRightToLeft(bv)) {
1562 if (tabular.isLastCellInRow(actcell)) {
1563 int row = tabular.row_of_cell(actcell);
1566 actcell = tabular.getFirstCellInRow(row);
1567 actcell = tabular.getCellAbove(actcell);
1569 if (tabular.isLastCell(actcell))
1574 if (!actcell) // first cell
1579 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1580 isRightToLeftPar(bv->buffer()->params);
1581 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1588 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1592 setSelection(0, tabular.getNumberOfCells() - 1);
1594 if (hasSelection()) {
1595 setUndo(bv, Undo::EDIT);
1596 bool const frozen = undo_frozen;
1599 // apply the fontchange on the whole selection
1604 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1605 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1606 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1607 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1614 updateLocal(bv, INIT);
1616 if (the_locking_inset)
1617 the_locking_inset->setFont(bv, font, tall);
1621 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1623 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1626 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1627 string const tmp = tabularFeature[i].feature;
1629 if (tmp == what.substr(0, tmp.length())) {
1630 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1631 //tabularFeatures[i].feature.length())) {
1632 action = tabularFeature[i].action;
1636 if (action == LyXTabular::LAST_ACTION)
1640 ltrim(what.substr(tabularFeature[i].feature.length()));
1641 tabularFeatures(bv, action, val);
1647 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1648 string const & special, bool & flag)
1650 if (special == "dl_above") {
1653 } else if (special == "dl_below") {
1654 ltt.bottomDL = flag;
1656 } else if (special == "empty") {
1668 void InsetTabular::tabularFeatures(BufferView * bv,
1669 LyXTabular::Feature feature,
1670 string const & value)
1676 bool setLines = false;
1677 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1678 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1681 case LyXTabular::M_ALIGN_LEFT:
1682 case LyXTabular::ALIGN_LEFT:
1683 setAlign = LYX_ALIGN_LEFT;
1685 case LyXTabular::M_ALIGN_RIGHT:
1686 case LyXTabular::ALIGN_RIGHT:
1687 setAlign = LYX_ALIGN_RIGHT;
1689 case LyXTabular::M_ALIGN_CENTER:
1690 case LyXTabular::ALIGN_CENTER:
1691 setAlign = LYX_ALIGN_CENTER;
1693 case LyXTabular::ALIGN_BLOCK:
1694 setAlign = LYX_ALIGN_BLOCK;
1696 case LyXTabular::M_VALIGN_TOP:
1697 case LyXTabular::VALIGN_TOP:
1698 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1700 case LyXTabular::M_VALIGN_BOTTOM:
1701 case LyXTabular::VALIGN_BOTTOM:
1702 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1704 case LyXTabular::M_VALIGN_CENTER:
1705 case LyXTabular::VALIGN_CENTER:
1706 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1711 if (hasSelection()) {
1712 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1714 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1715 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1717 setUndo(bv, Undo::FINISH);
1719 int row = tabular.row_of_cell(actcell);
1720 int column = tabular.column_of_cell(actcell);
1722 LyXTabular::ltType ltt;
1725 case LyXTabular::SET_PWIDTH:
1727 LyXLength const vallen(value);
1728 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1730 bool const update = (tmplen != vallen);
1731 tabular.setColumnPWidth(actcell, vallen);
1733 // We need this otherwise we won't resize
1734 // the insettext of the active cell (if any)
1735 // until later (see InsetText::do_resize)
1736 unlockInsetInInset(bv, the_locking_inset);
1739 for (int i = 0; i < tabular.rows(); ++i) {
1740 cell = tabular.getCellNumber(i,column);
1741 tabular.getCellInset(cell)->resizeLyXText(bv);
1743 updateLocal(bv, INIT);
1747 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1748 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1749 else if (!vallen.zero()
1750 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1751 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1754 case LyXTabular::SET_MPWIDTH:
1756 LyXLength const vallen(value);
1757 LyXLength const & tmplen = tabular.getPWidth(actcell);
1759 bool const update = (tmplen != vallen);
1760 tabular.setMColumnPWidth(actcell, vallen);
1762 // We need this otherwise we won't resize
1763 // the insettext of the active cell (if any)
1764 // until later (see InsetText::do_resize)
1765 unlockInsetInInset(bv, the_locking_inset);
1767 for (int i = 0; i < tabular.rows(); ++i) {
1768 tabular.getCellInset(tabular.getCellNumber(i, column))->
1771 updateLocal(bv, INIT);
1775 case LyXTabular::SET_SPECIAL_COLUMN:
1776 case LyXTabular::SET_SPECIAL_MULTI:
1777 tabular.setAlignSpecial(actcell,value,feature);
1778 updateLocal(bv, FULL);
1780 case LyXTabular::APPEND_ROW:
1781 // append the row into the tabular
1782 unlockInsetInInset(bv, the_locking_inset);
1783 tabular.appendRow(bv->buffer()->params, actcell);
1784 updateLocal(bv, INIT);
1786 case LyXTabular::APPEND_COLUMN:
1787 // append the column into the tabular
1788 unlockInsetInInset(bv, the_locking_inset);
1789 tabular.appendColumn(bv->buffer()->params, actcell);
1790 actcell = tabular.getCellNumber(row, column);
1791 updateLocal(bv, INIT);
1793 case LyXTabular::DELETE_ROW:
1794 unlockInsetInInset(bv, the_locking_inset);
1795 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1796 tabular.deleteRow(sel_row_start);
1798 if (sel_row_start >= tabular.rows())
1800 actcell = tabular.getCellNumber(sel_row_start, column);
1802 updateLocal(bv, INIT);
1804 case LyXTabular::DELETE_COLUMN:
1805 unlockInsetInInset(bv, the_locking_inset);
1806 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1807 tabular.deleteColumn(sel_col_start);
1809 if (sel_col_start >= tabular.columns())
1811 actcell = tabular.getCellNumber(row, sel_col_start);
1813 updateLocal(bv, INIT);
1815 case LyXTabular::M_TOGGLE_LINE_TOP:
1817 case LyXTabular::TOGGLE_LINE_TOP:
1819 bool lineSet = !tabular.topLine(actcell, flag);
1820 for (int i = sel_row_start; i <= sel_row_end; ++i)
1821 for (int j = sel_col_start; j <= sel_col_end; ++j)
1823 tabular.getCellNumber(i, j),
1825 updateLocal(bv, INIT);
1829 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1831 case LyXTabular::TOGGLE_LINE_BOTTOM:
1833 bool lineSet = !tabular.bottomLine(actcell, flag);
1834 for (int i = sel_row_start; i <= sel_row_end; ++i)
1835 for (int j = sel_col_start; j <= sel_col_end; ++j)
1836 tabular.setBottomLine(
1837 tabular.getCellNumber(i, j),
1840 updateLocal(bv, INIT);
1844 case LyXTabular::M_TOGGLE_LINE_LEFT:
1846 case LyXTabular::TOGGLE_LINE_LEFT:
1848 bool lineSet = !tabular.leftLine(actcell, flag);
1849 for (int i = sel_row_start; i <= sel_row_end; ++i)
1850 for (int j = sel_col_start; j <= sel_col_end; ++j)
1851 tabular.setLeftLine(
1852 tabular.getCellNumber(i,j),
1855 updateLocal(bv, INIT);
1859 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1861 case LyXTabular::TOGGLE_LINE_RIGHT:
1863 bool lineSet = !tabular.rightLine(actcell, flag);
1864 for (int i = sel_row_start; i <= sel_row_end; ++i)
1865 for (int j = sel_col_start; j <= sel_col_end; ++j)
1866 tabular.setRightLine(
1867 tabular.getCellNumber(i,j),
1870 updateLocal(bv, INIT);
1874 case LyXTabular::M_ALIGN_LEFT:
1875 case LyXTabular::M_ALIGN_RIGHT:
1876 case LyXTabular::M_ALIGN_CENTER:
1878 case LyXTabular::ALIGN_LEFT:
1879 case LyXTabular::ALIGN_RIGHT:
1880 case LyXTabular::ALIGN_CENTER:
1881 case LyXTabular::ALIGN_BLOCK:
1882 for (int i = sel_row_start; i <= sel_row_end; ++i)
1883 for (int j = sel_col_start; j <= sel_col_end; ++j)
1884 tabular.setAlignment(
1885 tabular.getCellNumber(i, j),
1888 updateLocal(bv, INIT);
1890 case LyXTabular::M_VALIGN_TOP:
1891 case LyXTabular::M_VALIGN_BOTTOM:
1892 case LyXTabular::M_VALIGN_CENTER:
1894 case LyXTabular::VALIGN_TOP:
1895 case LyXTabular::VALIGN_BOTTOM:
1896 case LyXTabular::VALIGN_CENTER:
1897 for (int i = sel_row_start; i <= sel_row_end; ++i)
1898 for (int j = sel_col_start; j <= sel_col_end; ++j)
1899 tabular.setVAlignment(
1900 tabular.getCellNumber(i, j),
1902 updateLocal(bv, INIT);
1904 case LyXTabular::MULTICOLUMN:
1906 if (sel_row_start != sel_row_end) {
1907 #ifdef WITH_WARNINGS
1908 #warning Need I say it ? This is horrible.
1910 Alert::error(_("Error setting multicolumn"),
1911 _("You cannot set multicolumn vertically."));
1914 // just multicol for one Single Cell
1915 if (!hasSelection()) {
1916 // check wether we are completly in a multicol
1917 if (tabular.isMultiColumn(actcell)) {
1918 tabular.unsetMultiColumn(actcell);
1919 updateLocal(bv, INIT);
1921 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1922 updateLocal(bv, CELL);
1926 // we have a selection so this means we just add all this
1927 // cells to form a multicolumn cell
1931 if (sel_cell_start > sel_cell_end) {
1932 s_start = sel_cell_end;
1933 s_end = sel_cell_start;
1935 s_start = sel_cell_start;
1936 s_end = sel_cell_end;
1938 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1941 updateLocal(bv, INIT);
1944 case LyXTabular::SET_ALL_LINES:
1946 case LyXTabular::UNSET_ALL_LINES:
1947 for (int i = sel_row_start; i <= sel_row_end; ++i)
1948 for (int j = sel_col_start; j <= sel_col_end; ++j)
1949 tabular.setAllLines(
1950 tabular.getCellNumber(i,j), setLines);
1951 updateLocal(bv, INIT);
1953 case LyXTabular::SET_LONGTABULAR:
1954 tabular.setLongTabular(true);
1955 updateLocal(bv, INIT); // because this toggles displayed
1957 case LyXTabular::UNSET_LONGTABULAR:
1958 tabular.setLongTabular(false);
1959 updateLocal(bv, INIT); // because this toggles displayed
1961 case LyXTabular::SET_ROTATE_TABULAR:
1962 tabular.setRotateTabular(true);
1964 case LyXTabular::UNSET_ROTATE_TABULAR:
1965 tabular.setRotateTabular(false);
1967 case LyXTabular::SET_ROTATE_CELL:
1968 for (int i = sel_row_start; i <= sel_row_end; ++i)
1969 for (int j = sel_col_start; j<=sel_col_end; ++j)
1970 tabular.setRotateCell(
1971 tabular.getCellNumber(i, j),
1974 case LyXTabular::UNSET_ROTATE_CELL:
1975 for (int i = sel_row_start; i <= sel_row_end; ++i)
1976 for (int j = sel_col_start; j <= sel_col_end; ++j)
1977 tabular.setRotateCell(
1978 tabular.getCellNumber(i, j), false);
1980 case LyXTabular::SET_USEBOX:
1982 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1983 if (val == tabular.getUsebox(actcell))
1984 val = LyXTabular::BOX_NONE;
1985 for (int i = sel_row_start; i <= sel_row_end; ++i)
1986 for (int j = sel_col_start; j <= sel_col_end; ++j)
1988 tabular.getCellNumber(i, j), val);
1991 case LyXTabular::UNSET_LTFIRSTHEAD:
1993 case LyXTabular::SET_LTFIRSTHEAD:
1994 (void)tabular.getRowOfLTFirstHead(row, ltt);
1995 checkLongtableSpecial(ltt, value, flag);
1996 tabular.setLTHead(row, flag, ltt, true);
1998 case LyXTabular::UNSET_LTHEAD:
2000 case LyXTabular::SET_LTHEAD:
2001 (void)tabular.getRowOfLTHead(row, ltt);
2002 checkLongtableSpecial(ltt, value, flag);
2003 tabular.setLTHead(row, flag, ltt, false);
2005 case LyXTabular::UNSET_LTFOOT:
2007 case LyXTabular::SET_LTFOOT:
2008 (void)tabular.getRowOfLTFoot(row, ltt);
2009 checkLongtableSpecial(ltt, value, flag);
2010 tabular.setLTFoot(row, flag, ltt, false);
2012 case LyXTabular::UNSET_LTLASTFOOT:
2014 case LyXTabular::SET_LTLASTFOOT:
2015 (void)tabular.getRowOfLTLastFoot(row, ltt);
2016 checkLongtableSpecial(ltt, value, flag);
2017 tabular.setLTFoot(row, flag, ltt, true);
2019 case LyXTabular::SET_LTNEWPAGE:
2021 bool what = !tabular.getLTNewPage(row);
2022 tabular.setLTNewPage(row, what);
2025 // dummy stuff just to avoid warnings
2026 case LyXTabular::LAST_ACTION:
2030 InsetTabularMailer mailer(*this);
2031 mailer.updateDialog(bv);
2035 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2038 UpdatableInset * inset =
2039 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2040 LyXFont font(LyXFont::ALL_SANE);
2042 x = inset->x() + inset->width(bv, font);
2043 y = inset->descent(bv, font);
2045 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2046 //inset_y = cursor.y();
2047 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2048 if (!the_locking_inset)
2050 updateLocal(bv, CELL);
2051 return (the_locking_inset != 0);
2055 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2056 mouse_button::state button)
2058 inset_x = cursor_.x()
2059 - top_x + tabular.getBeginningOfTextInCell(actcell);
2060 inset_y = cursor_.y();
2061 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2065 bool InsetTabular::insetHit(BufferView *, int x, int) const
2068 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2072 // This returns paperWidth() if the cell-width is unlimited or the width
2073 // in pixels if we have a pwidth for this cell.
2074 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2076 LyXLength const len = tabular.getPWidth(cell);
2080 return len.inPixels(latexTextWidth(bv));
2084 int InsetTabular::getMaxWidth(BufferView * bv,
2085 UpdatableInset const * inset) const
2087 int cell = tabular.getCellFromInset(inset, actcell);
2090 lyxerr << "Own inset not found, shouldn't really happen!"
2095 int w = getMaxWidthOfCell(bv, cell);
2097 // because the inset then subtracts it's top_x and owner->x()
2098 w += (inset->x() - top_x);
2105 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2107 resizeLyXText(bv, recursive);
2111 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2114 for(int i = 0; i < tabular.rows(); ++i) {
2115 for(int j = 0; j < tabular.columns(); ++j) {
2116 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2124 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2125 bool const recursive) const
2127 if (the_locking_inset)
2128 return the_locking_inset->getLyXText(bv, recursive);
2130 // if we're locked lock the actual insettext and return it's LyXText!!!
2132 UpdatableInset * inset =
2133 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2134 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2135 return the_locking_inset->getLyXText(bv, recursive);
2138 return Inset::getLyXText(bv, recursive);
2142 bool InsetTabular::showInsetDialog(BufferView * bv) const
2144 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2145 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2146 InsetTabularMailer mailer(*tmp);
2147 mailer.showDialog(bv);
2153 void InsetTabular::openLayoutDialog(BufferView * bv) const
2155 if (the_locking_inset) {
2156 InsetTabular * i = static_cast<InsetTabular *>
2157 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2159 i->openLayoutDialog(bv);
2163 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2164 InsetTabularMailer mailer(*tmp);
2165 mailer.showDialog(bv);
2170 // function returns an object as defined in func_status.h:
2171 // states OK, Unknown, Disabled, On, Off.
2173 FuncStatus InsetTabular::getStatus(string const & what) const
2175 int action = LyXTabular::LAST_ACTION;
2179 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2180 string const tmp = tabularFeature[i].feature;
2181 if (tmp == what.substr(0, tmp.length())) {
2182 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2183 // tabularFeatures[i].feature.length())) {
2184 action = tabularFeature[i].action;
2188 if (action == LyXTabular::LAST_ACTION) {
2190 return status.unknown(true);
2193 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2198 LyXTabular::ltType dummyltt;
2201 if (hasSelection()) {
2202 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2204 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2208 case LyXTabular::SET_PWIDTH:
2209 case LyXTabular::SET_MPWIDTH:
2210 case LyXTabular::SET_SPECIAL_COLUMN:
2211 case LyXTabular::SET_SPECIAL_MULTI:
2212 case LyXTabular::APPEND_ROW:
2213 case LyXTabular::APPEND_COLUMN:
2214 case LyXTabular::DELETE_ROW:
2215 case LyXTabular::DELETE_COLUMN:
2216 case LyXTabular::SET_ALL_LINES:
2217 case LyXTabular::UNSET_ALL_LINES:
2218 return status.clear();
2220 case LyXTabular::MULTICOLUMN:
2221 status.setOnOff(tabular.isMultiColumn(actcell));
2223 case LyXTabular::M_TOGGLE_LINE_TOP:
2225 case LyXTabular::TOGGLE_LINE_TOP:
2226 status.setOnOff(tabular.topLine(actcell, flag));
2228 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2230 case LyXTabular::TOGGLE_LINE_BOTTOM:
2231 status.setOnOff(tabular.bottomLine(actcell, flag));
2233 case LyXTabular::M_TOGGLE_LINE_LEFT:
2235 case LyXTabular::TOGGLE_LINE_LEFT:
2236 status.setOnOff(tabular.leftLine(actcell, flag));
2238 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2240 case LyXTabular::TOGGLE_LINE_RIGHT:
2241 status.setOnOff(tabular.rightLine(actcell, flag));
2243 case LyXTabular::M_ALIGN_LEFT:
2245 case LyXTabular::ALIGN_LEFT:
2246 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2248 case LyXTabular::M_ALIGN_RIGHT:
2250 case LyXTabular::ALIGN_RIGHT:
2251 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2253 case LyXTabular::M_ALIGN_CENTER:
2255 case LyXTabular::ALIGN_CENTER:
2256 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2258 case LyXTabular::ALIGN_BLOCK:
2259 status.disabled(tabular.getPWidth(actcell).zero());
2260 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2262 case LyXTabular::M_VALIGN_TOP:
2264 case LyXTabular::VALIGN_TOP:
2265 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2267 case LyXTabular::M_VALIGN_BOTTOM:
2269 case LyXTabular::VALIGN_BOTTOM:
2270 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2272 case LyXTabular::M_VALIGN_CENTER:
2274 case LyXTabular::VALIGN_CENTER:
2275 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2277 case LyXTabular::SET_LONGTABULAR:
2278 status.setOnOff(tabular.isLongTabular());
2280 case LyXTabular::UNSET_LONGTABULAR:
2281 status.setOnOff(!tabular.isLongTabular());
2283 case LyXTabular::SET_ROTATE_TABULAR:
2284 status.setOnOff(tabular.getRotateTabular());
2286 case LyXTabular::UNSET_ROTATE_TABULAR:
2287 status.setOnOff(!tabular.getRotateTabular());
2289 case LyXTabular::SET_ROTATE_CELL:
2290 status.setOnOff(tabular.getRotateCell(actcell));
2292 case LyXTabular::UNSET_ROTATE_CELL:
2293 status.setOnOff(!tabular.getRotateCell(actcell));
2295 case LyXTabular::SET_USEBOX:
2296 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2298 case LyXTabular::SET_LTFIRSTHEAD:
2299 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2301 case LyXTabular::SET_LTHEAD:
2302 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2304 case LyXTabular::SET_LTFOOT:
2305 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2307 case LyXTabular::SET_LTLASTFOOT:
2308 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2310 case LyXTabular::SET_LTNEWPAGE:
2311 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2315 status.disabled(true);
2322 void InsetTabular::getLabelList(std::vector<string> & list) const
2324 tabular.getLabelList(list);
2328 bool InsetTabular::copySelection(BufferView * bv)
2330 if (!hasSelection())
2333 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2334 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2335 if (sel_col_start > sel_col_end) {
2336 sel_col_start = sel_col_end;
2337 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2339 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2341 int const columns = sel_col_end - sel_col_start + 1;
2343 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2344 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2345 if (sel_row_start > sel_row_end) {
2346 swap(sel_row_start, sel_row_end);
2348 int const rows = sel_row_end - sel_row_start + 1;
2350 delete paste_tabular;
2351 paste_tabular = new LyXTabular(bv->buffer()->params,
2352 this, tabular); // rows, columns);
2353 for (int i = 0; i < sel_row_start; ++i)
2354 paste_tabular->deleteRow(0);
2355 while (paste_tabular->rows() > rows)
2356 paste_tabular->deleteRow(rows);
2357 paste_tabular->setTopLine(0, true, true);
2358 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2360 for (int i = 0; i < sel_col_start; ++i)
2361 paste_tabular->deleteColumn(0);
2362 while (paste_tabular->columns() > columns)
2363 paste_tabular->deleteColumn(columns);
2364 paste_tabular->setLeftLine(0, true, true);
2365 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2369 paste_tabular->ascii(bv->buffer(), sstr,
2370 (int)parOwner()->params().depth(), true, '\t');
2371 bv->stuffClipboard(STRCONV(sstr.str()));
2376 bool InsetTabular::pasteSelection(BufferView * bv)
2381 for (int r1 = 0, r2 = actrow;
2382 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2384 for(int c1 = 0, c2 = actcol;
2385 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2387 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2388 tabular.isPartOfMultiColumn(r2,c2))
2390 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2394 if (tabular.isPartOfMultiColumn(r2,c2)) {
2398 int const n1 = paste_tabular->getCellNumber(r1, c1);
2399 int const n2 = tabular.getCellNumber(r2, c2);
2400 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2401 tabular.getCellInset(n2)->setOwner(this);
2402 tabular.getCellInset(n2)->deleteLyXText(bv);
2403 tabular.getCellInset(n2)->markNew();
2410 bool InsetTabular::cutSelection(BufferParams const & bp)
2412 if (!hasSelection())
2415 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2416 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2417 if (sel_col_start > sel_col_end) {
2418 sel_col_start = sel_col_end;
2419 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2421 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2423 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2424 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2425 if (sel_row_start > sel_row_end) {
2426 swap(sel_row_start, sel_row_end);
2428 if (sel_cell_start > sel_cell_end) {
2429 swap(sel_cell_start, sel_cell_end);
2431 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2432 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2433 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2440 bool InsetTabular::isRightToLeft(BufferView * bv)
2442 return bv->getParentLanguage(this)->RightToLeft();
2446 bool InsetTabular::nodraw() const
2448 if (!UpdatableInset::nodraw() && the_locking_inset)
2449 return the_locking_inset->nodraw();
2450 return UpdatableInset::nodraw();
2454 int InsetTabular::scroll(bool recursive) const
2456 int sx = UpdatableInset::scroll(false);
2458 if (recursive && the_locking_inset)
2459 sx += the_locking_inset->scroll(recursive);
2465 void InsetTabular::getSelection(int & srow, int & erow,
2466 int & scol, int & ecol) const
2468 int const start = hasSelection() ? sel_cell_start : actcell;
2469 int const end = hasSelection() ? sel_cell_end : actcell;
2471 srow = tabular.row_of_cell(start);
2472 erow = tabular.row_of_cell(end);
2477 scol = tabular.column_of_cell(start);
2478 ecol = tabular.column_of_cell(end);
2482 ecol = tabular.right_column_of_cell(end);
2487 ParagraphList * InsetTabular::getParagraphs(int i) const
2489 return (i < tabular.getNumberOfCells())
2490 ? tabular.getCellInset(i)->getParagraphs(0)
2495 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2497 if (the_locking_inset)
2498 return the_locking_inset->cursor(bv);
2499 return Inset::cursor(bv);
2503 Inset * InsetTabular::getInsetFromID(int id_arg) const
2506 return const_cast<InsetTabular *>(this);
2509 for(int i = 0; i < tabular.rows(); ++i) {
2510 for(int j = 0; j < tabular.columns(); ++j) {
2511 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2520 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2523 if (the_locking_inset) {
2524 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2525 if (!word.word().empty()) {
2529 if (tabular.isLastCell(actcell)) {
2530 bv->unlockInset(const_cast<InsetTabular *>(this));
2532 return WordLangTuple();
2536 // otherwise we have to lock the next inset and ask for it's selecttion
2537 UpdatableInset * inset =
2538 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2539 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2540 WordLangTuple word(selectNextWordInt(bv, value));
2542 if (!word.word().empty())
2548 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2550 // when entering this function the inset should be ALWAYS locked!
2551 Assert(the_locking_inset);
2553 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2554 if (!word.word().empty())
2557 if (tabular.isLastCell(actcell)) {
2558 bv->unlockInset(const_cast<InsetTabular *>(this));
2559 return WordLangTuple();
2562 // otherwise we have to lock the next inset and ask for it's selecttion
2563 UpdatableInset * inset =
2564 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2565 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2566 return selectNextWordInt(bv, value);
2570 void InsetTabular::selectSelectedWord(BufferView * bv)
2572 if (the_locking_inset) {
2573 the_locking_inset->selectSelectedWord(bv);
2580 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2582 if (the_locking_inset) {
2583 the_locking_inset->toggleSelection(bv, kill_selection);
2588 void InsetTabular::markErased()
2592 while (cell < tabular.getNumberOfCells()) {
2593 InsetText * inset = tabular.getCellInset(cell);
2594 inset->markErased();
2600 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2602 if (the_locking_inset) {
2603 if (the_locking_inset->nextChange(bv, length)) {
2604 updateLocal(bv, CELL);
2607 if (tabular.isLastCell(actcell))
2611 InsetText * inset = tabular.getCellInset(actcell);
2612 if (inset->nextChange(bv, length)) {
2613 updateLocal(bv, FULL);
2616 while (!tabular.isLastCell(actcell)) {
2618 inset = tabular.getCellInset(actcell);
2619 if (inset->nextChange(bv, length)) {
2620 updateLocal(bv, FULL);
2628 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2632 if (the_locking_inset) {
2633 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2634 updateLocal(bv, CELL);
2637 if (tabular.isLastCell(actcell))
2641 InsetText * inset = tabular.getCellInset(cell);
2642 if (inset->searchForward(bv, str, cs, mw)) {
2643 updateLocal(bv, FULL);
2646 while (!tabular.isLastCell(cell)) {
2648 inset = tabular.getCellInset(cell);
2649 if (inset->searchForward(bv, str, cs, mw)) {
2650 updateLocal(bv, FULL);
2658 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2661 int cell = tabular.getNumberOfCells();
2662 if (the_locking_inset) {
2663 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2664 updateLocal(bv, CELL);
2672 InsetText * inset = tabular.getCellInset(cell);
2673 if (inset->searchBackward(bv, str, cs, mw)) {
2674 updateLocal(bv, CELL);
2682 bool InsetTabular::insetAllowed(Inset::Code code) const
2684 if (the_locking_inset)
2685 return the_locking_inset->insetAllowed(code);
2686 // we return true here because if the inset is not locked someone
2687 // wants to insert something in one of our insettexts and we generally
2693 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2695 const int cell = tabular.getCellFromInset(in, actcell);
2698 return tabular.getPWidth(cell).zero();
2700 // well we didn't obviously find it so maybe our owner knows more
2702 return owner()->forceDefaultParagraphs(in);
2703 // if we're here there is really something strange going on!!!
2707 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2710 if (buf.length() <= 0)
2716 string::size_type len = buf.length();
2717 string::size_type p = 0;
2720 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2729 maxCols = max(cols, maxCols);
2735 maxCols = max(cols, maxCols);
2736 LyXTabular * loctab;
2741 delete paste_tabular;
2742 paste_tabular = new LyXTabular(bv->buffer()->params,
2743 this, rows, maxCols);
2744 loctab = paste_tabular;
2753 string::size_type op = 0;
2754 int cells = loctab->getNumberOfCells();
2757 rows = loctab->rows();
2758 int const columns = loctab->columns();
2760 while ((cell < cells) && (p < len) && (row < rows) &&
2761 (p = buf.find_first_of("\t\n", p)) != string::npos)
2767 // we can only set this if we are not too far right
2768 if (cols < columns) {
2769 InsetText * ti = loctab->getCellInset(cell);
2770 LyXFont const font = ti->getLyXText(bv)->
2771 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2772 ti->setText(buf.substr(op, p - op), font);
2778 // we can only set this if we are not too far right
2779 if (cols < columns) {
2780 InsetText * ti = loctab->getCellInset(cell);
2781 LyXFont const font = ti->getLyXText(bv)->
2782 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2783 ti->setText(buf.substr(op, p - op), font);
2788 cell = loctab->getCellNumber(row, cols);
2794 // check for the last cell if there is no trailing '\n'
2795 if ((cell < cells) && (op < len)) {
2796 InsetText * ti = loctab->getCellInset(cell);
2797 LyXFont const font = ti->getLyXText(bv)->
2798 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2799 ti->setText(buf.substr(op, len - op), font);
2806 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2808 int const rows = tabular.rows();
2809 int const columns = tabular.columns();
2810 for (int i = 0; i < rows; ++i) {
2811 for (int j = 0; j < columns; ++j) {
2812 tabular.getCellInset(i,j)->addPreview(loader);
2818 string const InsetTabularMailer:: name_("tabular");
2820 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2825 string const InsetTabularMailer::inset2string() const
2827 return params2string(inset_);
2831 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2833 istringstream data(STRCONV(in));
2835 lex.setStream(data);
2837 #warning CHECK verify that this is a sane value to return.
2843 string const token = lex.getString();
2851 string const token = lex.getString();
2852 if (token != "\\active_cell")
2855 cell = lex.getInteger();
2858 // This is part of the inset proper that is usually swallowed
2859 // by Buffer::readInset
2862 string const token = lex.getString();
2863 if (token != "Tabular")
2870 Buffer const * const buffer = inset.buffer();
2872 inset.read(buffer, lex);
2874 // We can't set the active cell, but we can tell the frontend
2880 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2882 Buffer const * const buffer = inset.buffer();
2887 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2888 inset.write(buffer, data);
2889 data << "\\end_inset\n";
2890 return STRCONV(data.str());