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;
177 InsetTabular::InsetTabular(InsetTabular const & tab)
178 : UpdatableInset(tab),
179 tabular(tab.buffer_->params, this, tab.tabular),
182 the_locking_inset = 0;
183 old_locking_inset = 0;
186 actrow = actcell = 0;
196 InsetTabular::~InsetTabular()
198 InsetTabularMailer mailer(*this);
203 InsetBase * InsetTabular::clone() const
205 return new InsetTabular(*this);
209 Buffer const * InsetTabular::buffer() const
215 BufferView * InsetTabular::view() const
222 void InsetTabular::buffer(Buffer * b)
228 void InsetTabular::write(Buffer const * buf, ostream & os) const
230 os << " Tabular" << endl;
231 tabular.write(buf, os);
235 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
237 bool const old_format = (lex.getString() == "\\LyXTable");
239 tabular.read(buf, lex);
247 string token = lex.getString();
248 while (lex.isOK() && (token != "\\end_inset")) {
250 token = lex.getString();
252 if (token != "\\end_inset") {
253 lex.printError("Missing \\end_inset at this point. "
259 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
262 calculate_dimensions_of_cells(mi.base.bv, true);
263 //lyxerr << "InsetTabular::metrics, bv: " << mi.base.bv << endl;
264 for (int i = 0; i < tabular.getNumberOfCells(); ++i) {
265 tabular.cellinfo_of_cell(i)->inset.text_.bv_owner = mi.base.bv;
266 tabular.cellinfo_of_cell(i)->inset.reinitLyXText();
270 dim.asc = tabular.getAscentOfRow(0);
271 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
272 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
276 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
283 BufferView * bv = pi.base.bv;
289 UpdatableInset::draw(pi, x, y);
297 x += ADD_TO_TABULAR_WIDTH;
301 first_visible_cell = -1;
302 for (i = 0; i < tabular.rows(); ++i) {
304 cell = tabular.getCellNumber(i, 0);
305 if (!((y + tabular.getDescentOfRow(i)) > 0) &&
306 (y - tabular.getAscentOfRow(i)) < pi.pain.paperHeight())
308 y += tabular.getDescentOfRow(i) +
309 tabular.getAscentOfRow(i + 1) +
310 tabular.getAdditionalHeight(i + 1);
313 for (j = 0; j < tabular.columns(); ++j) {
314 if (nx > bv->workWidth())
316 if (tabular.isPartOfMultiColumn(i, j))
318 cx = nx + tabular.getBeginningOfTextInCell(cell);
319 if (first_visible_cell < 0)
320 first_visible_cell = cell;
321 if (hasSelection()) {
322 drawCellSelection(pi.pain, nx, y, i, j, cell);
325 tabular.getCellInset(cell)->draw(pi, cx, y);
326 drawCellLines(pi.pain, nx, y, i, cell);
327 nx += tabular.getWidthOfColumn(cell);
331 // Would be nice, but for some completely unfathomable reason,
332 // on a col resize to a new fixed width, even though the insettexts
333 // are resized, the cell isn't, but drawing all cells in a tall table
334 // has the desired effect somehow. Complete dark magic.
336 // avoiding drawing the rest of a long table is
337 // a pretty big speedup
338 if (y > bv->workHeight())
342 y += tabular.getDescentOfRow(i) +
343 tabular.getAscentOfRow(i + 1) +
344 tabular.getAdditionalHeight(i + 1);
351 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
352 int row, int cell) const
354 int x2 = x + tabular.getWidthOfColumn(cell);
357 if (!tabular.topAlreadyDrawn(cell)) {
358 on_off = !tabular.topLine(cell);
359 pain.line(x, y - tabular.getAscentOfRow(row),
360 x2, y - tabular.getAscentOfRow(row),
361 on_off ? LColor::tabularonoffline : LColor::tabularline,
362 on_off ? Painter::line_onoffdash : Painter::line_solid);
364 on_off = !tabular.bottomLine(cell);
365 pain.line(x, y + tabular.getDescentOfRow(row),
366 x2, y + tabular.getDescentOfRow(row),
367 on_off ? LColor::tabularonoffline : LColor::tabularline,
368 on_off ? Painter::line_onoffdash : Painter::line_solid);
369 if (!tabular.leftAlreadyDrawn(cell)) {
370 on_off = !tabular.leftLine(cell);
371 pain.line(x, y - tabular.getAscentOfRow(row),
372 x, y + tabular.getDescentOfRow(row),
373 on_off ? LColor::tabularonoffline : LColor::tabularline,
374 on_off ? Painter::line_onoffdash : Painter::line_solid);
376 on_off = !tabular.rightLine(cell);
377 pain.line(x2 - tabular.getAdditionalWidth(cell),
378 y - tabular.getAscentOfRow(row),
379 x2 - tabular.getAdditionalWidth(cell),
380 y + tabular.getDescentOfRow(row),
381 on_off ? LColor::tabularonoffline : LColor::tabularline,
382 on_off ? Painter::line_onoffdash : Painter::line_solid);
386 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
387 int row, int column, int cell) const
389 Assert(hasSelection());
390 int cs = tabular.column_of_cell(sel_cell_start);
391 int ce = tabular.column_of_cell(sel_cell_end);
394 cs = tabular.column_of_cell(sel_cell_end);
396 ce = tabular.right_column_of_cell(sel_cell_end);
399 int rs = tabular.row_of_cell(sel_cell_start);
400 int re = tabular.row_of_cell(sel_cell_end);
404 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
405 int w = tabular.getWidthOfColumn(cell);
406 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
407 pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
408 w, h, LColor::selection);
413 void InsetTabular::update(BufferView * bv, bool reinit)
418 string const InsetTabular::editMessage() const
420 return _("Opened table");
424 void InsetTabular::insetUnlock(BufferView * bv)
426 if (the_locking_inset) {
427 the_locking_inset->insetUnlock(bv);
428 updateLocal(bv, CELL);
429 the_locking_inset = 0;
434 if (scroll(false) || hasSelection()) {
439 updateLocal(bv, FULL);
444 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
447 calculate_dimensions_of_cells(bv, true);
449 if (!locked && what == CELL)
451 if (need_update < what) // only set this if it has greater update
454 if (need_update != NONE) {
455 bv->updateInset(const_cast<InsetTabular *>(this));
462 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
464 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
469 if (inset == tabular.getCellInset(actcell)) {
470 lyxerr[Debug::INSETTEXT] << "OK" << endl;
471 the_locking_inset = tabular.getCellInset(actcell);
474 } else if (!the_locking_inset) {
475 int const n = tabular.getNumberOfCells();
476 int const id = inset->id();
477 for (int i = 0; i < n; ++i) {
478 InsetText * in = tabular.getCellInset(i);
481 the_locking_inset = in;
486 if (in->getInsetFromID(id)) {
488 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
489 return the_locking_inset->lockInsetInInset(bv, inset);
492 } else if (the_locking_inset && (the_locking_inset == inset)) {
493 lyxerr[Debug::INSETTEXT] << "OK" << endl;
495 } else if (the_locking_inset) {
496 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
497 return the_locking_inset->lockInsetInInset(bv, inset);
499 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
504 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
507 if (!the_locking_inset)
509 if (the_locking_inset == inset) {
510 the_locking_inset->insetUnlock(bv);
512 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
518 updateLocal(bv, CELL);
519 // this has to be here otherwise we don't redraw the cell!
520 the_locking_inset = 0;
523 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
524 if (inset->lyxCode() == TABULAR_CODE &&
525 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
526 InsetTabularMailer mailer(*this);
527 mailer.updateDialog(bv);
536 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
538 Inset * tl_inset = inset;
539 // look if this inset is really inside myself!
540 while(tl_inset->owner() && tl_inset->owner() != this)
541 tl_inset = tl_inset->owner();
542 // if we enter here it's not ower inset
543 if (!tl_inset->owner())
545 // we only have to do this if this is a subinset of our cells
546 if (tl_inset != inset) {
547 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
550 updateLocal(bv, CELL);
555 int InsetTabular::insetInInsetY() const
557 if (!the_locking_inset)
559 return inset_y + the_locking_inset->insetInInsetY();
563 UpdatableInset * InsetTabular::getLockingInset() const
565 return the_locking_inset ? the_locking_inset->getLockingInset() :
566 const_cast<InsetTabular *>(this);
570 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
574 if (the_locking_inset)
575 return the_locking_inset->getFirstLockingInsetOfType(c);
580 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
582 if (the_locking_inset)
583 return the_locking_inset->insertInset(bv, inset);
588 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
590 if (hasSelection() && cmd.button() == mouse_button::button3)
593 if (hasSelection()) {
595 updateLocal(cmd.view(), FULL);
598 int const ocell = actcell;
599 int const orow = actrow;
600 BufferView * bv = cmd.view();
604 the_locking_inset = 0;
608 setPos(bv, cmd.x, cmd.y);
610 updateLocal(bv, NONE);
613 if (cmd.button() == mouse_button::button3) {
614 if ((ocell != actcell) && the_locking_inset) {
615 the_locking_inset->insetUnlock(bv);
616 updateLocal(bv, CELL);
617 the_locking_inset = 0;
623 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
625 if ((ocell == actcell) && the_locking_inset && inset_hit) {
627 FuncRequest cmd1 = cmd;
630 the_locking_inset->localDispatch(cmd1);
634 if (the_locking_inset) {
635 the_locking_inset->insetUnlock(bv);
636 updateLocal(bv, CELL);
637 the_locking_inset = 0;
640 if (cmd.button() == mouse_button::button2) {
641 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
645 if (inset_hit && bv->theLockingInset()) {
646 if (!bv->lockInset(static_cast<UpdatableInset*>
647 (tabular.getCellInset(actcell))))
649 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
652 FuncRequest cmd1 = cmd;
655 the_locking_inset->localDispatch(cmd1);
661 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
664 if (the_locking_inset) {
665 FuncRequest cmd1 = cmd;
668 ret = the_locking_inset->localDispatch(cmd1);
670 if (cmd.button() == mouse_button::button3 && !ret) {
671 InsetTabularMailer(*this).showDialog(cmd.view());
678 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
680 if (the_locking_inset) {
681 FuncRequest cmd1 = cmd;
684 the_locking_inset->localDispatch(cmd1);
688 BufferView * bv = cmd.view();
689 int const old_cell = actcell;
691 setPos(bv, cmd.x, cmd.y);
692 if (!hasSelection()) {
693 setSelection(actcell, actcell);
694 updateLocal(bv, FULL);
695 } else if (old_cell != actcell) {
696 setSelection(sel_cell_start, actcell);
697 updateLocal(bv, FULL);
702 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
704 // We need to save the value of the_locking_inset as the call to
705 // the_locking_inset->localDispatch might unlock it.
706 old_locking_inset = the_locking_inset;
707 RESULT result = UpdatableInset::localDispatch(cmd);
708 BufferView * bv = cmd.view();
710 if (cmd.action == LFUN_INSET_EDIT) {
712 if (!bv->lockInset(this)) {
713 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
719 the_locking_inset = 0;
723 if (cmd.argument.size()) {
724 if (cmd.argument == "left") {
725 if (isRightToLeft(bv))
726 actcell = tabular.getLastCellInRow(0);
730 if (isRightToLeft(bv))
731 actcell = tabular.getFirstCellInRow(tabular.rows()-1);
733 actcell = tabular.getNumberOfCells() - 1;
741 setPos(bv, cmd.x, cmd.y);
744 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
745 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
751 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
756 if (cmd.action < 0 && cmd.argument.empty())
759 bool hs = hasSelection();
762 // this one have priority over the locked InsetText, if we're not already
763 // inside another tabular then that one get's priority!
764 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
765 switch (cmd.action) {
766 case LFUN_MOUSE_PRESS:
770 case LFUN_MOUSE_MOTION:
771 lfunMouseMotion(cmd);
774 case LFUN_MOUSE_RELEASE:
775 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
777 case LFUN_CELL_BACKWARD:
778 case LFUN_CELL_FORWARD:
779 unlockInsetInInset(bv, the_locking_inset);
780 if (cmd.action == LFUN_CELL_FORWARD)
781 moveNextCell(bv, old_locking_inset != 0);
783 movePrevCell(bv, old_locking_inset != 0);
786 updateLocal(bv, FULL);
787 if (!the_locking_inset) {
788 return DISPATCHED_NOUPDATE;
791 // this to avoid compiler warnings.
797 kb_action action = cmd.action;
798 string arg = cmd.argument;
799 if (the_locking_inset) {
800 result = the_locking_inset->localDispatch(cmd);
801 if (result == DISPATCHED_NOUPDATE) {
804 if (sc != scroll()) { // inset has been scrolled
805 updateLocal(bv, FULL);
808 } else if (result == DISPATCHED) {
809 updateLocal(bv, CELL);
811 } else if (result == FINISHED_UP) {
813 // Make sure to reset status message after
814 // exiting, e.g. math inset
815 bv->owner()->clearMessage();
816 } else if (result == FINISHED_DOWN) {
818 bv->owner()->clearMessage();
819 } else if (result == FINISHED_RIGHT) {
821 bv->owner()->clearMessage();
822 } else if (result == FINISHED) {
823 bv->owner()->clearMessage();
829 // --- Cursor Movements ----------------------------------
830 case LFUN_RIGHTSEL: {
831 int const start = hasSelection() ? sel_cell_start : actcell;
832 if (tabular.isLastCellInRow(actcell)) {
833 setSelection(start, actcell);
838 // if we are starting a selection, only select
839 // the current cell at the beginning
840 if (hasSelection()) {
841 moveRight(bv, false);
844 setSelection(start, end);
845 updateLocal(bv, FULL);
849 result = moveRight(bv);
852 updateLocal(bv, FULL);
855 int const start = hasSelection() ? sel_cell_start : actcell;
856 if (tabular.isFirstCellInRow(actcell)) {
857 setSelection(start, actcell);
862 // if we are starting a selection, only select
863 // the current cell at the beginning
864 if (hasSelection()) {
868 setSelection(start, end);
869 updateLocal(bv, FULL);
873 result = moveLeft(bv);
876 updateLocal(bv, FULL);
879 int const start = hasSelection() ? sel_cell_start : actcell;
880 int const ocell = actcell;
881 // if we are starting a selection, only select
882 // the current cell at the beginning
883 if (hasSelection()) {
885 if ((ocell == sel_cell_end) ||
886 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
887 setSelection(start, tabular.getCellBelow(sel_cell_end));
889 setSelection(start, tabular.getLastCellBelow(sel_cell_end));
891 setSelection(start, start);
893 updateLocal(bv, FULL);
897 result = moveDown(bv, old_locking_inset != 0);
900 updateLocal(bv, FULL);
904 int const start = hasSelection() ? sel_cell_start : actcell;
905 int const ocell = actcell;
906 // if we are starting a selection, only select
907 // the current cell at the beginning
908 if (hasSelection()) {
910 if ((ocell == sel_cell_end) ||
911 (tabular.column_of_cell(ocell)>tabular.column_of_cell(actcell)))
912 setSelection(start, tabular.getCellAbove(sel_cell_end));
914 setSelection(start, tabular.getLastCellAbove(sel_cell_end));
916 setSelection(start, start);
918 updateLocal(bv, FULL);
922 result = moveUp(bv, old_locking_inset != 0);
925 updateLocal(bv, FULL);
928 UpdateCodes code = CURSOR;
934 unlockInsetInInset(bv, the_locking_inset);
935 if (bv->text->top_y() + bv->painter().paperHeight() <
936 (top_baseline + tabular.getHeightOfTabular()))
938 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
940 actcell = tabular.getCellBelow(first_visible_cell) + column;
942 actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
945 updateLocal(bv, code);
949 UpdateCodes code = CURSOR;
955 unlockInsetInInset(bv, the_locking_inset);
956 if (top_baseline < 0) {
957 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
959 if (top_baseline > 0)
962 actcell = tabular.getCellBelow(first_visible_cell) + column;
967 updateLocal(bv, code);
970 // none of these make sense for insettabular,
971 // but we must catch them to prevent any
972 // selection from being confused
976 case LFUN_WORDLEFTSEL:
978 case LFUN_WORDRIGHTSEL:
980 case LFUN_DOWN_PARAGRAPH:
981 case LFUN_DOWN_PARAGRAPHSEL:
982 case LFUN_UP_PARAGRAPH:
983 case LFUN_UP_PARAGRAPHSEL:
989 case LFUN_BEGINNINGBUF:
990 case LFUN_BEGINNINGBUFSEL:
994 case LFUN_LAYOUT_TABULAR: {
995 InsetTabularMailer mailer(*this);
996 mailer.showDialog(bv);
999 case LFUN_INSET_DIALOG_UPDATE: {
1000 InsetTabularMailer mailer(*this);
1001 mailer.updateDialog(bv);
1004 case LFUN_TABULAR_FEATURE:
1005 if (!tabularFeatures(bv, arg))
1006 result = UNDISPATCHED;
1008 // insert file functions
1009 case LFUN_FILE_INSERT_ASCII_PARA:
1010 case LFUN_FILE_INSERT_ASCII:
1012 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1015 if (insertAsciiString(bv, tmpstr, false))
1016 updateLocal(bv, INIT);
1018 result = UNDISPATCHED;
1021 // cut and paste functions
1023 if (!copySelection(bv))
1027 setUndo(bv, Undo::DELETE);
1028 cutSelection(bv->buffer()->params);
1029 updateLocal(bv, INIT);
1032 if (!hasSelection())
1037 case LFUN_PASTESELECTION:
1039 string const clip(bv->getClipboard());
1043 if (clip.find('\t') != string::npos) {
1047 string::size_type len = clip.length();
1048 string::size_type p = 0;
1051 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1059 maxCols = max(cols, maxCols);
1065 maxCols = max(cols, maxCols);
1066 delete paste_tabular;
1067 paste_tabular = new LyXTabular(bv->buffer()->params,
1068 this, rows, maxCols);
1069 string::size_type op = 0;
1071 int cells = paste_tabular->getNumberOfCells();
1073 while ((cell < cells) && (p < len) &&
1074 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1079 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1084 paste_tabular->getCellInset(cell)->setText(clip.substr(op, p-op));
1085 while (cols++ < maxCols)
1093 // check for the last cell if there is no trailing '\n'
1094 if ((cell < cells) && (op < len))
1095 paste_tabular->getCellInset(cell)->setText(clip.substr(op, len-op));
1098 if (!insertAsciiString(bv, clip, true))
1101 // so that the clipboard is used and it goes on
1103 // and executes LFUN_PASTESELECTION in insettext!
1104 delete paste_tabular;
1109 if (hasPasteBuffer()) {
1110 setUndo(bv, Undo::INSERT);
1112 updateLocal(bv, INIT);
1115 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1117 // handle font changing stuff on selection before we lock the inset
1118 // in the default part!
1119 result = UNDISPATCHED;
1130 case LFUN_UNDERLINE:
1131 case LFUN_FONT_SIZE:
1132 if (bv->dispatch(FuncRequest(bv, action, arg)))
1133 result = DISPATCHED;
1139 // we try to activate the actual inset and put this event down to
1140 // the insets dispatch function.
1141 if ((result == DISPATCHED) || the_locking_inset)
1144 if (activateCellInset(bv)) {
1145 // reset need_update setted in above function!
1147 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1148 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1149 unlockInsetInInset(bv, the_locking_inset);
1151 // we need to update if this was requested before
1152 updateLocal(bv, NONE);
1153 return UNDISPATCHED;
1156 // so the below CELL is not set because this is higher
1157 // priority and we get a full redraw
1161 updateLocal(bv, CELL);
1166 if (result < FINISHED) {
1167 if (!the_locking_inset) {
1168 if (bv->fitCursor())
1169 updateLocal(bv, FULL);
1172 bv->unlockInset(this);
1177 int InsetTabular::latex(Buffer const * buf, ostream & os,
1178 LatexRunParams const & runparams) const
1180 return tabular.latex(buf, os, runparams);
1184 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1187 return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
1189 return tabular.ascii(buf, os, 0, false,0);
1193 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1196 int const ret = tabular.ascii(buf,os,
1197 (int)parOwner()->params().depth(),
1204 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1209 // if the table is inside a float it doesn't need the informaltable
1210 // wrapper. Search for it.
1211 for(master = owner();
1212 master && master->lyxCode() != Inset::FLOAT_CODE;
1213 master = master->owner());
1216 os << "<informaltable>";
1221 ret+= tabular.docbook(buf, os, mixcont);
1223 os << "</informaltable>";
1232 void InsetTabular::validate(LaTeXFeatures & features) const
1234 tabular.validate(features);
1238 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1244 bool changed = false;
1246 // FIXME: since InsetText ignores this anyway, it doesn't
1247 // matter what we pass it. Ugly
1250 // if we have a locking_inset we should have to check only this cell for
1251 // change so I'll try this to have a boost, but who knows ;)
1252 if ((need_update != INIT) &&
1253 (the_locking_inset == tabular.getCellInset(actcell))) {
1254 for(int i = 0; i < tabular.columns(); ++i) {
1255 maxAsc = max(tabular.getCellInset(actrow, i)->ascent(bv, font),
1257 maxDesc = max(tabular.getCellInset(actrow, i)->descent(bv, font),
1260 changed = tabular.setWidthOfCell(actcell, the_locking_inset->width(bv, font));
1261 changed = tabular.setAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1262 changed = tabular.setDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1265 for (int i = 0; i < tabular.rows(); ++i) {
1268 for (int j = 0; j < tabular.columns(); ++j) {
1269 if (tabular.isPartOfMultiColumn(i,j))
1272 inset = tabular.getCellInset(cell);
1273 if (!reinit && !tabular.getPWidth(cell).zero())
1274 inset->update(bv, false);
1275 maxAsc = max(maxAsc, inset->ascent(bv, font));
1276 maxDesc = max(maxDesc, inset->descent(bv, font));
1277 changed = tabular.setWidthOfCell(cell, inset->width(bv, font)) || changed;
1279 changed = tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1280 changed = tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1288 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1290 if (the_locking_inset) {
1291 the_locking_inset->getCursor(bv, x, y);
1296 y = cursor_.y() + InsetTabular::y();
1299 int desc = tabular.getDescentOfRow(actrow);
1301 int ascdesc = tabular.getAscentOfRow(actrow) + desc;
1303 y += ADD_TO_HEIGHT * 2;
1304 y += TEXT_TO_INSET_OFFSET;
1308 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1310 if (the_locking_inset) {
1311 the_locking_inset->getCursorPos(bv, x, y);
1314 x = cursor_.x() - top_x;
1319 void InsetTabular::fitInsetCursor(BufferView * bv) const
1321 if (the_locking_inset) {
1322 int old_top_y = bv->text->top_y();
1323 the_locking_inset->fitInsetCursor(bv);
1324 if (old_top_y != bv->text->top_y())
1330 int const asc = font_metrics::maxAscent(font);
1331 int const desc = font_metrics::maxDescent(font);
1334 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1339 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1343 actcell = actrow = actcol = 0;
1344 int ly = tabular.getDescentOfRow(actrow);
1346 // first search the right row
1347 while ((ly < y) && ((actrow+1) < tabular.rows())) {
1348 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1349 tabular.getAscentOfRow(actrow + 1) +
1350 tabular.getAdditionalHeight(actrow + 1));
1352 ly = cursor_.y() + tabular.getDescentOfRow(actrow);
1354 actcell = tabular.getCellNumber(actrow, actcol);
1356 // now search the right column
1357 int lx = tabular.getWidthOfColumn(actcell) -
1358 tabular.getAdditionalWidth(actcell);
1359 for (; !tabular.isLastCellInRow(actcell) && lx < x; ++actcell) {
1360 lx += tabular.getWidthOfColumn(actcell + 1)
1361 + tabular.getAdditionalWidth(actcell);
1363 cursor_.x(lx - tabular.getWidthOfColumn(actcell) + top_x + 2);
1368 int InsetTabular::getCellXPos(int cell) const
1372 for (; !tabular.isFirstCellInRow(c); --c)
1374 int lx = tabular.getWidthOfColumn(cell);
1375 for (; c < cell; ++c) {
1376 lx += tabular.getWidthOfColumn(c);
1378 return (lx - tabular.getWidthOfColumn(cell) + top_x);
1382 void InsetTabular::resetPos(BufferView * bv) const
1384 #ifdef WITH_WARNINGS
1385 #warning This should be fixed in the right manner (20011128 Jug)
1387 // fast hack to fix infinite repaintings!
1388 if (in_reset_pos > 0)
1392 actcol = tabular.column_of_cell(actcell);
1395 for (; (cell < actcell) && !tabular.isLastRow(cell); ++cell) {
1396 if (tabular.isLastCellInRow(cell)) {
1397 cursor_.y(cursor_.y() + tabular.getDescentOfRow(actrow) +
1398 tabular.getAscentOfRow(actrow + 1) +
1399 tabular.getAdditionalHeight(actrow + 1));
1403 if (!locked || nodraw()) {
1404 if (the_locking_inset)
1405 inset_y = cursor_.y();
1408 // we need this only from here on!!!
1410 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1411 int new_x = getCellXPos(actcell);
1412 int old_x = cursor_.x();
1415 // cursor.x(getCellXPos(actcell) + offset);
1416 if ((actcol < tabular.columns() - 1) && scroll(false) &&
1417 (tabular.getWidthOfTabular() < bv->workWidth()-20))
1420 updateLocal(bv, FULL);
1421 } else if (the_locking_inset &&
1422 (tabular.getWidthOfColumn(actcell) > bv->workWidth()-20))
1424 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1425 if (xx > (bv->workWidth()-20)) {
1426 scroll(bv, -(xx - bv->workWidth() + 60));
1427 updateLocal(bv, FULL);
1428 } else if (xx < 20) {
1434 updateLocal(bv, FULL);
1436 } else if ((cursor_.x() - offset) > 20 &&
1437 (cursor_.x() - offset + tabular.getWidthOfColumn(actcell))
1438 > (bv->workWidth() - 20)) {
1439 scroll(bv, -tabular.getWidthOfColumn(actcell) - 20);
1440 updateLocal(bv, FULL);
1441 } else if ((cursor_.x() - offset) < 20) {
1442 scroll(bv, 20 - cursor_.x() + offset);
1443 updateLocal(bv, FULL);
1444 } else if (scroll() && top_x > 20 &&
1445 (top_x + tabular.getWidthOfTabular()) > (bv->workWidth() - 20)) {
1446 scroll(bv, old_x - cursor_.x());
1447 updateLocal(bv, FULL);
1449 if (the_locking_inset) {
1450 inset_x = cursor_.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
1451 inset_y = cursor_.y();
1453 if ((!the_locking_inset ||
1454 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1455 actcell != oldcell) {
1456 InsetTabular * inset = const_cast<InsetTabular *>(this);
1457 InsetTabularMailer mailer(*inset);
1458 mailer.updateDialog(bv);
1465 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1467 if (lock && !old_locking_inset) {
1468 if (activateCellInset(bv))
1471 bool moved = isRightToLeft(bv)
1472 ? movePrevCell(bv) : moveNextCell(bv);
1474 return FINISHED_RIGHT;
1475 if (lock && activateCellInset(bv))
1479 return DISPATCHED_NOUPDATE;
1483 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1485 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1488 if (lock) { // behind the inset
1489 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1493 return DISPATCHED_NOUPDATE;
1497 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1499 int const ocell = actcell;
1500 actcell = tabular.getCellAbove(actcell);
1501 if (actcell == ocell) // we moved out of the inset
1507 if (old_locking_inset) {
1508 old_locking_inset->getCursorPos(bv, x, y);
1509 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1511 if (activateCellInset(bv, x, 0))
1514 return DISPATCHED_NOUPDATE;
1518 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1520 int const ocell = actcell;
1521 actcell = tabular.getCellBelow(actcell);
1522 if (actcell == ocell) // we moved out of the inset
1523 return FINISHED_DOWN;
1528 if (old_locking_inset) {
1529 old_locking_inset->getCursorPos(bv, x, y);
1530 x -= cursor_.x() + tabular.getBeginningOfTextInCell(actcell);
1532 if (activateCellInset(bv, x, 0))
1535 return DISPATCHED_NOUPDATE;
1539 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1541 if (isRightToLeft(bv)) {
1542 if (tabular.isFirstCellInRow(actcell)) {
1543 int row = tabular.row_of_cell(actcell);
1544 if (row == tabular.rows() - 1)
1546 actcell = tabular.getLastCellInRow(row);
1547 actcell = tabular.getCellBelow(actcell);
1554 if (tabular.isLastCell(actcell))
1559 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1560 isRightToLeftPar(bv->buffer()->params);
1561 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1568 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1570 if (isRightToLeft(bv)) {
1571 if (tabular.isLastCellInRow(actcell)) {
1572 int row = tabular.row_of_cell(actcell);
1575 actcell = tabular.getFirstCellInRow(row);
1576 actcell = tabular.getCellAbove(actcell);
1578 if (tabular.isLastCell(actcell))
1583 if (!actcell) // first cell
1588 bool rtl = tabular.getCellInset(actcell)->paragraphs.begin()->
1589 isRightToLeftPar(bv->buffer()->params);
1590 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1597 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1601 setSelection(0, tabular.getNumberOfCells() - 1);
1603 if (hasSelection()) {
1604 setUndo(bv, Undo::EDIT);
1605 bool const frozen = undo_frozen;
1608 // apply the fontchange on the whole selection
1613 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1614 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1615 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1616 tabular.getCellInset(i, j)->setFont(bv, font, tall, true);
1623 updateLocal(bv, INIT);
1625 if (the_locking_inset)
1626 the_locking_inset->setFont(bv, font, tall);
1630 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1632 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1635 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1636 string const tmp = tabularFeature[i].feature;
1638 if (tmp == what.substr(0, tmp.length())) {
1639 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1640 //tabularFeatures[i].feature.length())) {
1641 action = tabularFeature[i].action;
1645 if (action == LyXTabular::LAST_ACTION)
1649 ltrim(what.substr(tabularFeature[i].feature.length()));
1650 tabularFeatures(bv, action, val);
1656 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1657 string const & special, bool & flag)
1659 if (special == "dl_above") {
1662 } else if (special == "dl_below") {
1663 ltt.bottomDL = flag;
1665 } else if (special == "empty") {
1677 void InsetTabular::tabularFeatures(BufferView * bv,
1678 LyXTabular::Feature feature,
1679 string const & value)
1685 bool setLines = false;
1686 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1687 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1690 case LyXTabular::M_ALIGN_LEFT:
1691 case LyXTabular::ALIGN_LEFT:
1692 setAlign = LYX_ALIGN_LEFT;
1694 case LyXTabular::M_ALIGN_RIGHT:
1695 case LyXTabular::ALIGN_RIGHT:
1696 setAlign = LYX_ALIGN_RIGHT;
1698 case LyXTabular::M_ALIGN_CENTER:
1699 case LyXTabular::ALIGN_CENTER:
1700 setAlign = LYX_ALIGN_CENTER;
1702 case LyXTabular::ALIGN_BLOCK:
1703 setAlign = LYX_ALIGN_BLOCK;
1705 case LyXTabular::M_VALIGN_TOP:
1706 case LyXTabular::VALIGN_TOP:
1707 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1709 case LyXTabular::M_VALIGN_BOTTOM:
1710 case LyXTabular::VALIGN_BOTTOM:
1711 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1713 case LyXTabular::M_VALIGN_CENTER:
1714 case LyXTabular::VALIGN_CENTER:
1715 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1720 if (hasSelection()) {
1721 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1723 sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
1724 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
1726 setUndo(bv, Undo::FINISH);
1728 int row = tabular.row_of_cell(actcell);
1729 int column = tabular.column_of_cell(actcell);
1731 LyXTabular::ltType ltt;
1734 case LyXTabular::SET_PWIDTH:
1736 LyXLength const vallen(value);
1737 LyXLength const & tmplen = tabular.getColumnPWidth(actcell);
1739 bool const update = (tmplen != vallen);
1740 tabular.setColumnPWidth(actcell, vallen);
1742 // We need this otherwise we won't resize
1743 // the insettext of the active cell (if any)
1744 // until later (see InsetText::do_resize)
1745 unlockInsetInInset(bv, the_locking_inset);
1748 for (int i = 0; i < tabular.rows(); ++i) {
1749 cell = tabular.getCellNumber(i,column);
1750 tabular.getCellInset(cell)->resizeLyXText(bv);
1752 updateLocal(bv, INIT);
1756 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1757 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1758 else if (!vallen.zero()
1759 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1760 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1763 case LyXTabular::SET_MPWIDTH:
1765 LyXLength const vallen(value);
1766 LyXLength const & tmplen = tabular.getPWidth(actcell);
1768 bool const update = (tmplen != vallen);
1769 tabular.setMColumnPWidth(actcell, vallen);
1771 // We need this otherwise we won't resize
1772 // the insettext of the active cell (if any)
1773 // until later (see InsetText::do_resize)
1774 unlockInsetInInset(bv, the_locking_inset);
1776 for (int i = 0; i < tabular.rows(); ++i) {
1777 tabular.getCellInset(tabular.getCellNumber(i, column))->
1780 updateLocal(bv, INIT);
1784 case LyXTabular::SET_SPECIAL_COLUMN:
1785 case LyXTabular::SET_SPECIAL_MULTI:
1786 tabular.setAlignSpecial(actcell,value,feature);
1787 updateLocal(bv, FULL);
1789 case LyXTabular::APPEND_ROW:
1790 // append the row into the tabular
1791 unlockInsetInInset(bv, the_locking_inset);
1792 tabular.appendRow(bv->buffer()->params, actcell);
1793 updateLocal(bv, INIT);
1795 case LyXTabular::APPEND_COLUMN:
1796 // append the column into the tabular
1797 unlockInsetInInset(bv, the_locking_inset);
1798 tabular.appendColumn(bv->buffer()->params, actcell);
1799 actcell = tabular.getCellNumber(row, column);
1800 updateLocal(bv, INIT);
1802 case LyXTabular::DELETE_ROW:
1803 unlockInsetInInset(bv, the_locking_inset);
1804 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1805 tabular.deleteRow(sel_row_start);
1807 if (sel_row_start >= tabular.rows())
1809 actcell = tabular.getCellNumber(sel_row_start, column);
1811 updateLocal(bv, INIT);
1813 case LyXTabular::DELETE_COLUMN:
1814 unlockInsetInInset(bv, the_locking_inset);
1815 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1816 tabular.deleteColumn(sel_col_start);
1818 if (sel_col_start >= tabular.columns())
1820 actcell = tabular.getCellNumber(row, sel_col_start);
1822 updateLocal(bv, INIT);
1824 case LyXTabular::M_TOGGLE_LINE_TOP:
1826 case LyXTabular::TOGGLE_LINE_TOP:
1828 bool lineSet = !tabular.topLine(actcell, flag);
1829 for (int i = sel_row_start; i <= sel_row_end; ++i)
1830 for (int j = sel_col_start; j <= sel_col_end; ++j)
1832 tabular.getCellNumber(i, j),
1834 updateLocal(bv, INIT);
1838 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1840 case LyXTabular::TOGGLE_LINE_BOTTOM:
1842 bool lineSet = !tabular.bottomLine(actcell, flag);
1843 for (int i = sel_row_start; i <= sel_row_end; ++i)
1844 for (int j = sel_col_start; j <= sel_col_end; ++j)
1845 tabular.setBottomLine(
1846 tabular.getCellNumber(i, j),
1849 updateLocal(bv, INIT);
1853 case LyXTabular::M_TOGGLE_LINE_LEFT:
1855 case LyXTabular::TOGGLE_LINE_LEFT:
1857 bool lineSet = !tabular.leftLine(actcell, flag);
1858 for (int i = sel_row_start; i <= sel_row_end; ++i)
1859 for (int j = sel_col_start; j <= sel_col_end; ++j)
1860 tabular.setLeftLine(
1861 tabular.getCellNumber(i,j),
1864 updateLocal(bv, INIT);
1868 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1870 case LyXTabular::TOGGLE_LINE_RIGHT:
1872 bool lineSet = !tabular.rightLine(actcell, flag);
1873 for (int i = sel_row_start; i <= sel_row_end; ++i)
1874 for (int j = sel_col_start; j <= sel_col_end; ++j)
1875 tabular.setRightLine(
1876 tabular.getCellNumber(i,j),
1879 updateLocal(bv, INIT);
1883 case LyXTabular::M_ALIGN_LEFT:
1884 case LyXTabular::M_ALIGN_RIGHT:
1885 case LyXTabular::M_ALIGN_CENTER:
1887 case LyXTabular::ALIGN_LEFT:
1888 case LyXTabular::ALIGN_RIGHT:
1889 case LyXTabular::ALIGN_CENTER:
1890 case LyXTabular::ALIGN_BLOCK:
1891 for (int i = sel_row_start; i <= sel_row_end; ++i)
1892 for (int j = sel_col_start; j <= sel_col_end; ++j)
1893 tabular.setAlignment(
1894 tabular.getCellNumber(i, j),
1897 updateLocal(bv, INIT);
1899 case LyXTabular::M_VALIGN_TOP:
1900 case LyXTabular::M_VALIGN_BOTTOM:
1901 case LyXTabular::M_VALIGN_CENTER:
1903 case LyXTabular::VALIGN_TOP:
1904 case LyXTabular::VALIGN_BOTTOM:
1905 case LyXTabular::VALIGN_CENTER:
1906 for (int i = sel_row_start; i <= sel_row_end; ++i)
1907 for (int j = sel_col_start; j <= sel_col_end; ++j)
1908 tabular.setVAlignment(
1909 tabular.getCellNumber(i, j),
1911 updateLocal(bv, INIT);
1913 case LyXTabular::MULTICOLUMN:
1915 if (sel_row_start != sel_row_end) {
1916 #ifdef WITH_WARNINGS
1917 #warning Need I say it ? This is horrible.
1919 Alert::error(_("Error setting multicolumn"),
1920 _("You cannot set multicolumn vertically."));
1923 // just multicol for one Single Cell
1924 if (!hasSelection()) {
1925 // check wether we are completly in a multicol
1926 if (tabular.isMultiColumn(actcell)) {
1927 tabular.unsetMultiColumn(actcell);
1928 updateLocal(bv, INIT);
1930 tabular.setMultiColumn(bv->buffer(), actcell, 1);
1931 updateLocal(bv, CELL);
1935 // we have a selection so this means we just add all this
1936 // cells to form a multicolumn cell
1940 if (sel_cell_start > sel_cell_end) {
1941 s_start = sel_cell_end;
1942 s_end = sel_cell_start;
1944 s_start = sel_cell_start;
1945 s_end = sel_cell_end;
1947 tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1950 updateLocal(bv, INIT);
1953 case LyXTabular::SET_ALL_LINES:
1955 case LyXTabular::UNSET_ALL_LINES:
1956 for (int i = sel_row_start; i <= sel_row_end; ++i)
1957 for (int j = sel_col_start; j <= sel_col_end; ++j)
1958 tabular.setAllLines(
1959 tabular.getCellNumber(i,j), setLines);
1960 updateLocal(bv, INIT);
1962 case LyXTabular::SET_LONGTABULAR:
1963 tabular.setLongTabular(true);
1964 updateLocal(bv, INIT); // because this toggles displayed
1966 case LyXTabular::UNSET_LONGTABULAR:
1967 tabular.setLongTabular(false);
1968 updateLocal(bv, INIT); // because this toggles displayed
1970 case LyXTabular::SET_ROTATE_TABULAR:
1971 tabular.setRotateTabular(true);
1973 case LyXTabular::UNSET_ROTATE_TABULAR:
1974 tabular.setRotateTabular(false);
1976 case LyXTabular::SET_ROTATE_CELL:
1977 for (int i = sel_row_start; i <= sel_row_end; ++i)
1978 for (int j = sel_col_start; j<=sel_col_end; ++j)
1979 tabular.setRotateCell(
1980 tabular.getCellNumber(i, j),
1983 case LyXTabular::UNSET_ROTATE_CELL:
1984 for (int i = sel_row_start; i <= sel_row_end; ++i)
1985 for (int j = sel_col_start; j <= sel_col_end; ++j)
1986 tabular.setRotateCell(
1987 tabular.getCellNumber(i, j), false);
1989 case LyXTabular::SET_USEBOX:
1991 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1992 if (val == tabular.getUsebox(actcell))
1993 val = LyXTabular::BOX_NONE;
1994 for (int i = sel_row_start; i <= sel_row_end; ++i)
1995 for (int j = sel_col_start; j <= sel_col_end; ++j)
1997 tabular.getCellNumber(i, j), val);
2000 case LyXTabular::UNSET_LTFIRSTHEAD:
2002 case LyXTabular::SET_LTFIRSTHEAD:
2003 (void)tabular.getRowOfLTFirstHead(row, ltt);
2004 checkLongtableSpecial(ltt, value, flag);
2005 tabular.setLTHead(row, flag, ltt, true);
2007 case LyXTabular::UNSET_LTHEAD:
2009 case LyXTabular::SET_LTHEAD:
2010 (void)tabular.getRowOfLTHead(row, ltt);
2011 checkLongtableSpecial(ltt, value, flag);
2012 tabular.setLTHead(row, flag, ltt, false);
2014 case LyXTabular::UNSET_LTFOOT:
2016 case LyXTabular::SET_LTFOOT:
2017 (void)tabular.getRowOfLTFoot(row, ltt);
2018 checkLongtableSpecial(ltt, value, flag);
2019 tabular.setLTFoot(row, flag, ltt, false);
2021 case LyXTabular::UNSET_LTLASTFOOT:
2023 case LyXTabular::SET_LTLASTFOOT:
2024 (void)tabular.getRowOfLTLastFoot(row, ltt);
2025 checkLongtableSpecial(ltt, value, flag);
2026 tabular.setLTFoot(row, flag, ltt, true);
2028 case LyXTabular::SET_LTNEWPAGE:
2030 bool what = !tabular.getLTNewPage(row);
2031 tabular.setLTNewPage(row, what);
2034 // dummy stuff just to avoid warnings
2035 case LyXTabular::LAST_ACTION:
2039 InsetTabularMailer mailer(*this);
2040 mailer.updateDialog(bv);
2044 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2047 UpdatableInset * inset =
2048 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2049 LyXFont font(LyXFont::ALL_SANE);
2051 x = inset->x() + inset->width(bv, font);
2052 y = inset->descent(bv, font);
2054 //inset_x = cursor.x() - top_x + tabular.getBeginningOfTextInCell(actcell);
2055 //inset_y = cursor.y();
2056 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2057 if (!the_locking_inset)
2059 updateLocal(bv, CELL);
2060 return (the_locking_inset != 0);
2064 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2065 mouse_button::state button)
2067 inset_x = cursor_.x()
2068 - top_x + tabular.getBeginningOfTextInCell(actcell);
2069 inset_y = cursor_.y();
2070 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2074 bool InsetTabular::insetHit(BufferView *, int x, int) const
2077 > (cursor_.x() + tabular.getBeginningOfTextInCell(actcell));
2081 // This returns paperWidth() if the cell-width is unlimited or the width
2082 // in pixels if we have a pwidth for this cell.
2083 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2085 LyXLength const len = tabular.getPWidth(cell);
2089 return len.inPixels(latexTextWidth(bv));
2093 int InsetTabular::getMaxWidth(BufferView * bv,
2094 UpdatableInset const * inset) const
2096 int cell = tabular.getCellFromInset(inset, actcell);
2099 lyxerr << "Own inset not found, shouldn't really happen!"
2104 int w = getMaxWidthOfCell(bv, cell);
2106 // because the inset then subtracts it's top_x and owner->x()
2107 w += (inset->x() - top_x);
2114 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2116 resizeLyXText(bv, recursive);
2120 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2123 for(int i = 0; i < tabular.rows(); ++i) {
2124 for(int j = 0; j < tabular.columns(); ++j) {
2125 tabular.getCellInset(i, j)->resizeLyXText(bv, true);
2133 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2134 bool const recursive) const
2136 if (the_locking_inset)
2137 return the_locking_inset->getLyXText(bv, recursive);
2139 // if we're locked lock the actual insettext and return it's LyXText!!!
2141 UpdatableInset * inset =
2142 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2143 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2144 return the_locking_inset->getLyXText(bv, recursive);
2147 return Inset::getLyXText(bv, recursive);
2151 bool InsetTabular::showInsetDialog(BufferView * bv) const
2153 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2154 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2155 InsetTabularMailer mailer(*tmp);
2156 mailer.showDialog(bv);
2162 void InsetTabular::openLayoutDialog(BufferView * bv) const
2164 if (the_locking_inset) {
2165 InsetTabular * i = static_cast<InsetTabular *>
2166 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2168 i->openLayoutDialog(bv);
2172 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2173 InsetTabularMailer mailer(*tmp);
2174 mailer.showDialog(bv);
2179 // function returns an object as defined in func_status.h:
2180 // states OK, Unknown, Disabled, On, Off.
2182 FuncStatus InsetTabular::getStatus(string const & what) const
2184 int action = LyXTabular::LAST_ACTION;
2188 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2189 string const tmp = tabularFeature[i].feature;
2190 if (tmp == what.substr(0, tmp.length())) {
2191 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2192 // tabularFeatures[i].feature.length())) {
2193 action = tabularFeature[i].action;
2197 if (action == LyXTabular::LAST_ACTION) {
2199 return status.unknown(true);
2202 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2207 LyXTabular::ltType dummyltt;
2210 if (hasSelection()) {
2211 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2213 sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
2217 case LyXTabular::SET_PWIDTH:
2218 case LyXTabular::SET_MPWIDTH:
2219 case LyXTabular::SET_SPECIAL_COLUMN:
2220 case LyXTabular::SET_SPECIAL_MULTI:
2221 case LyXTabular::APPEND_ROW:
2222 case LyXTabular::APPEND_COLUMN:
2223 case LyXTabular::DELETE_ROW:
2224 case LyXTabular::DELETE_COLUMN:
2225 case LyXTabular::SET_ALL_LINES:
2226 case LyXTabular::UNSET_ALL_LINES:
2227 return status.clear();
2229 case LyXTabular::MULTICOLUMN:
2230 status.setOnOff(tabular.isMultiColumn(actcell));
2232 case LyXTabular::M_TOGGLE_LINE_TOP:
2234 case LyXTabular::TOGGLE_LINE_TOP:
2235 status.setOnOff(tabular.topLine(actcell, flag));
2237 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2239 case LyXTabular::TOGGLE_LINE_BOTTOM:
2240 status.setOnOff(tabular.bottomLine(actcell, flag));
2242 case LyXTabular::M_TOGGLE_LINE_LEFT:
2244 case LyXTabular::TOGGLE_LINE_LEFT:
2245 status.setOnOff(tabular.leftLine(actcell, flag));
2247 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2249 case LyXTabular::TOGGLE_LINE_RIGHT:
2250 status.setOnOff(tabular.rightLine(actcell, flag));
2252 case LyXTabular::M_ALIGN_LEFT:
2254 case LyXTabular::ALIGN_LEFT:
2255 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2257 case LyXTabular::M_ALIGN_RIGHT:
2259 case LyXTabular::ALIGN_RIGHT:
2260 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2262 case LyXTabular::M_ALIGN_CENTER:
2264 case LyXTabular::ALIGN_CENTER:
2265 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2267 case LyXTabular::ALIGN_BLOCK:
2268 status.disabled(tabular.getPWidth(actcell).zero());
2269 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2271 case LyXTabular::M_VALIGN_TOP:
2273 case LyXTabular::VALIGN_TOP:
2274 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2276 case LyXTabular::M_VALIGN_BOTTOM:
2278 case LyXTabular::VALIGN_BOTTOM:
2279 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2281 case LyXTabular::M_VALIGN_CENTER:
2283 case LyXTabular::VALIGN_CENTER:
2284 status.setOnOff(tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2286 case LyXTabular::SET_LONGTABULAR:
2287 status.setOnOff(tabular.isLongTabular());
2289 case LyXTabular::UNSET_LONGTABULAR:
2290 status.setOnOff(!tabular.isLongTabular());
2292 case LyXTabular::SET_ROTATE_TABULAR:
2293 status.setOnOff(tabular.getRotateTabular());
2295 case LyXTabular::UNSET_ROTATE_TABULAR:
2296 status.setOnOff(!tabular.getRotateTabular());
2298 case LyXTabular::SET_ROTATE_CELL:
2299 status.setOnOff(tabular.getRotateCell(actcell));
2301 case LyXTabular::UNSET_ROTATE_CELL:
2302 status.setOnOff(!tabular.getRotateCell(actcell));
2304 case LyXTabular::SET_USEBOX:
2305 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
2307 case LyXTabular::SET_LTFIRSTHEAD:
2308 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2310 case LyXTabular::SET_LTHEAD:
2311 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
2313 case LyXTabular::SET_LTFOOT:
2314 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2316 case LyXTabular::SET_LTLASTFOOT:
2317 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
2319 case LyXTabular::SET_LTNEWPAGE:
2320 status.setOnOff(tabular.getLTNewPage(sel_row_start));
2324 status.disabled(true);
2331 void InsetTabular::getLabelList(std::vector<string> & list) const
2333 tabular.getLabelList(list);
2337 bool InsetTabular::copySelection(BufferView * bv)
2339 if (!hasSelection())
2342 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2343 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2344 if (sel_col_start > sel_col_end) {
2345 sel_col_start = sel_col_end;
2346 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2348 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2350 int const columns = sel_col_end - sel_col_start + 1;
2352 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2353 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2354 if (sel_row_start > sel_row_end) {
2355 swap(sel_row_start, sel_row_end);
2357 int const rows = sel_row_end - sel_row_start + 1;
2359 delete paste_tabular;
2360 paste_tabular = new LyXTabular(bv->buffer()->params,
2361 this, tabular); // rows, columns);
2362 for (int i = 0; i < sel_row_start; ++i)
2363 paste_tabular->deleteRow(0);
2364 while (paste_tabular->rows() > rows)
2365 paste_tabular->deleteRow(rows);
2366 paste_tabular->setTopLine(0, true, true);
2367 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
2369 for (int i = 0; i < sel_col_start; ++i)
2370 paste_tabular->deleteColumn(0);
2371 while (paste_tabular->columns() > columns)
2372 paste_tabular->deleteColumn(columns);
2373 paste_tabular->setLeftLine(0, true, true);
2374 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
2378 paste_tabular->ascii(bv->buffer(), sstr,
2379 (int)parOwner()->params().depth(), true, '\t');
2380 bv->stuffClipboard(STRCONV(sstr.str()));
2385 bool InsetTabular::pasteSelection(BufferView * bv)
2390 for (int r1 = 0, r2 = actrow;
2391 (r1 < paste_tabular->rows()) && (r2 < tabular.rows());
2393 for(int c1 = 0, c2 = actcol;
2394 (c1 < paste_tabular->columns()) && (c2 < tabular.columns());
2396 if (paste_tabular->isPartOfMultiColumn(r1,c1) &&
2397 tabular.isPartOfMultiColumn(r2,c2))
2399 if (paste_tabular->isPartOfMultiColumn(r1,c1)) {
2403 if (tabular.isPartOfMultiColumn(r2,c2)) {
2407 int const n1 = paste_tabular->getCellNumber(r1, c1);
2408 int const n2 = tabular.getCellNumber(r2, c2);
2409 *(tabular.getCellInset(n2)) = *(paste_tabular->getCellInset(n1));
2410 tabular.getCellInset(n2)->setOwner(this);
2411 tabular.getCellInset(n2)->deleteLyXText(bv);
2412 tabular.getCellInset(n2)->markNew();
2419 bool InsetTabular::cutSelection(BufferParams const & bp)
2421 if (!hasSelection())
2424 int sel_col_start = tabular.column_of_cell(sel_cell_start);
2425 int sel_col_end = tabular.column_of_cell(sel_cell_end);
2426 if (sel_col_start > sel_col_end) {
2427 sel_col_start = sel_col_end;
2428 sel_col_end = tabular.right_column_of_cell(sel_cell_start);
2430 sel_col_end = tabular.right_column_of_cell(sel_cell_end);
2432 int sel_row_start = tabular.row_of_cell(sel_cell_start);
2433 int sel_row_end = tabular.row_of_cell(sel_cell_end);
2434 if (sel_row_start > sel_row_end) {
2435 swap(sel_row_start, sel_row_end);
2437 if (sel_cell_start > sel_cell_end) {
2438 swap(sel_cell_start, sel_cell_end);
2440 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2441 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2442 tabular.getCellInset(tabular.getCellNumber(i, j))->clear(bp.tracking_changes);
2449 bool InsetTabular::isRightToLeft(BufferView * bv)
2451 return bv->getParentLanguage(this)->RightToLeft();
2455 bool InsetTabular::nodraw() const
2457 if (!UpdatableInset::nodraw() && the_locking_inset)
2458 return the_locking_inset->nodraw();
2459 return UpdatableInset::nodraw();
2463 int InsetTabular::scroll(bool recursive) const
2465 int sx = UpdatableInset::scroll(false);
2467 if (recursive && the_locking_inset)
2468 sx += the_locking_inset->scroll(recursive);
2474 void InsetTabular::getSelection(int & srow, int & erow,
2475 int & scol, int & ecol) const
2477 int const start = hasSelection() ? sel_cell_start : actcell;
2478 int const end = hasSelection() ? sel_cell_end : actcell;
2480 srow = tabular.row_of_cell(start);
2481 erow = tabular.row_of_cell(end);
2486 scol = tabular.column_of_cell(start);
2487 ecol = tabular.column_of_cell(end);
2491 ecol = tabular.right_column_of_cell(end);
2496 ParagraphList * InsetTabular::getParagraphs(int i) const
2498 return (i < tabular.getNumberOfCells())
2499 ? tabular.getCellInset(i)->getParagraphs(0)
2504 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2506 if (the_locking_inset)
2507 return the_locking_inset->cursor(bv);
2508 return Inset::cursor(bv);
2512 Inset * InsetTabular::getInsetFromID(int id_arg) const
2515 return const_cast<InsetTabular *>(this);
2518 for(int i = 0; i < tabular.rows(); ++i) {
2519 for(int j = 0; j < tabular.columns(); ++j) {
2520 if ((result = tabular.getCellInset(i, j)->getInsetFromID(id_arg)))
2529 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2532 if (the_locking_inset) {
2533 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2534 if (!word.word().empty()) {
2538 if (tabular.isLastCell(actcell)) {
2539 bv->unlockInset(const_cast<InsetTabular *>(this));
2541 return WordLangTuple();
2545 // otherwise we have to lock the next inset and ask for it's selecttion
2546 UpdatableInset * inset =
2547 static_cast<UpdatableInset*>(tabular.getCellInset(actcell));
2548 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2549 WordLangTuple word(selectNextWordInt(bv, value));
2551 if (!word.word().empty())
2557 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2559 // when entering this function the inset should be ALWAYS locked!
2560 Assert(the_locking_inset);
2562 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2563 if (!word.word().empty())
2566 if (tabular.isLastCell(actcell)) {
2567 bv->unlockInset(const_cast<InsetTabular *>(this));
2568 return WordLangTuple();
2571 // otherwise we have to lock the next inset and ask for it's selecttion
2572 UpdatableInset * inset =
2573 static_cast<UpdatableInset*>(tabular.getCellInset(++actcell));
2574 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2575 return selectNextWordInt(bv, value);
2579 void InsetTabular::selectSelectedWord(BufferView * bv)
2581 if (the_locking_inset) {
2582 the_locking_inset->selectSelectedWord(bv);
2589 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2591 if (the_locking_inset) {
2592 the_locking_inset->toggleSelection(bv, kill_selection);
2597 void InsetTabular::markErased()
2601 while (cell < tabular.getNumberOfCells()) {
2602 InsetText * inset = tabular.getCellInset(cell);
2603 inset->markErased();
2609 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2611 if (the_locking_inset) {
2612 if (the_locking_inset->nextChange(bv, length)) {
2613 updateLocal(bv, CELL);
2616 if (tabular.isLastCell(actcell))
2620 InsetText * inset = tabular.getCellInset(actcell);
2621 if (inset->nextChange(bv, length)) {
2622 updateLocal(bv, FULL);
2625 while (!tabular.isLastCell(actcell)) {
2627 inset = tabular.getCellInset(actcell);
2628 if (inset->nextChange(bv, length)) {
2629 updateLocal(bv, FULL);
2637 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2641 if (the_locking_inset) {
2642 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2643 updateLocal(bv, CELL);
2646 if (tabular.isLastCell(actcell))
2650 InsetText * inset = tabular.getCellInset(cell);
2651 if (inset->searchForward(bv, str, cs, mw)) {
2652 updateLocal(bv, FULL);
2655 while (!tabular.isLastCell(cell)) {
2657 inset = tabular.getCellInset(cell);
2658 if (inset->searchForward(bv, str, cs, mw)) {
2659 updateLocal(bv, FULL);
2667 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2670 int cell = tabular.getNumberOfCells();
2671 if (the_locking_inset) {
2672 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2673 updateLocal(bv, CELL);
2681 InsetText * inset = tabular.getCellInset(cell);
2682 if (inset->searchBackward(bv, str, cs, mw)) {
2683 updateLocal(bv, CELL);
2691 bool InsetTabular::insetAllowed(Inset::Code code) const
2693 if (the_locking_inset)
2694 return the_locking_inset->insetAllowed(code);
2695 // we return true here because if the inset is not locked someone
2696 // wants to insert something in one of our insettexts and we generally
2702 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2704 const int cell = tabular.getCellFromInset(in, actcell);
2707 return tabular.getPWidth(cell).zero();
2709 // well we didn't obviously find it so maybe our owner knows more
2711 return owner()->forceDefaultParagraphs(in);
2712 // if we're here there is really something strange going on!!!
2716 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2719 if (buf.length() <= 0)
2725 string::size_type len = buf.length();
2726 string::size_type p = 0;
2729 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2738 maxCols = max(cols, maxCols);
2744 maxCols = max(cols, maxCols);
2745 LyXTabular * loctab;
2750 delete paste_tabular;
2751 paste_tabular = new LyXTabular(bv->buffer()->params,
2752 this, rows, maxCols);
2753 loctab = paste_tabular;
2762 string::size_type op = 0;
2763 int cells = loctab->getNumberOfCells();
2766 rows = loctab->rows();
2767 int const columns = loctab->columns();
2769 while ((cell < cells) && (p < len) && (row < rows) &&
2770 (p = buf.find_first_of("\t\n", p)) != string::npos)
2776 // we can only set this if we are not too far right
2777 if (cols < columns) {
2778 InsetText * ti = loctab->getCellInset(cell);
2779 LyXFont const font = ti->getLyXText(bv)->
2780 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2781 ti->setText(buf.substr(op, p - op), font);
2787 // we can only set this if we are not too far right
2788 if (cols < columns) {
2789 InsetText * ti = loctab->getCellInset(cell);
2790 LyXFont const font = ti->getLyXText(bv)->
2791 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2792 ti->setText(buf.substr(op, p - op), font);
2797 cell = loctab->getCellNumber(row, cols);
2803 // check for the last cell if there is no trailing '\n'
2804 if ((cell < cells) && (op < len)) {
2805 InsetText * ti = loctab->getCellInset(cell);
2806 LyXFont const font = ti->getLyXText(bv)->
2807 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2808 ti->setText(buf.substr(op, len - op), font);
2815 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2817 int const rows = tabular.rows();
2818 int const columns = tabular.columns();
2819 for (int i = 0; i < rows; ++i) {
2820 for (int j = 0; j < columns; ++j) {
2821 tabular.getCellInset(i,j)->addPreview(loader);
2827 string const InsetTabularMailer:: name_("tabular");
2829 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2834 string const InsetTabularMailer::inset2string() const
2836 return params2string(inset_);
2840 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2842 istringstream data(STRCONV(in));
2844 lex.setStream(data);
2846 #warning CHECK verify that this is a sane value to return.
2852 string const token = lex.getString();
2860 string const token = lex.getString();
2861 if (token != "\\active_cell")
2864 cell = lex.getInteger();
2867 // This is part of the inset proper that is usually swallowed
2868 // by Buffer::readInset
2871 string const token = lex.getString();
2872 if (token != "Tabular")
2879 Buffer const * const buffer = inset.buffer();
2881 inset.read(buffer, lex);
2883 // We can't set the active cell, but we can tell the frontend
2889 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2891 Buffer const * const buffer = inset.buffer();
2896 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2897 inset.write(buffer, data);
2898 data << "\\end_inset\n";
2899 return STRCONV(data.str());