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
14 #include "insettabular.h"
15 #include "insettext.h"
18 #include "BufferView.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
27 #include "lyxlength.h"
30 #include "ParagraphParameters.h"
31 #include "undo_funcs.h"
32 #include "WordLangTuple.h"
34 #include "frontends/Alert.h"
35 #include "frontends/Dialogs.h"
36 #include "frontends/font_metrics.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/Painter.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::ALIGN_BLOCK, "align-block" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
123 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
124 bool operator()(TabularFeature & tf)
126 return tf.action == feature_;
129 LyXTabular::Feature feature_;
135 string const featureAsString(LyXTabular::Feature feature)
137 TabularFeature * it = tabularFeature;
138 TabularFeature * end = it +
139 sizeof(tabularFeature) / sizeof(TabularFeature);
140 it = std::find_if(it, end, FindFeature(feature));
141 return (it == end) ? string() : it->feature;
145 bool InsetTabular::hasPasteBuffer() const
147 return (paste_tabular != 0);
151 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
159 // for now make it always display as display() inset
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
175 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
177 : UpdatableInset(tab, same_id), buffer(&buf)
179 tabular.reset(new LyXTabular(buf.params,
180 this, *(tab.tabular), same_id));
181 the_locking_inset = 0;
182 old_locking_inset = 0;
185 actrow = actcell = 0;
195 InsetTabular::~InsetTabular()
197 InsetTabularMailer mailer(*this);
202 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
204 return new InsetTabular(*this, buf, same_id);
208 BufferView * InsetTabular::view() const
210 return buffer->getUser();
214 void InsetTabular::write(Buffer const * buf, ostream & os) const
216 os << " Tabular" << endl;
217 tabular->Write(buf, os);
221 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
223 bool const old_format = (lex.getString() == "\\LyXTable");
225 tabular.reset(new LyXTabular(buf, this, lex));
233 string token = lex.getString();
234 while (lex.isOK() && (token != "\\end_inset")) {
236 token = lex.getString();
238 if (token != "\\end_inset") {
239 lex.printError("Missing \\end_inset at this point. "
245 int InsetTabular::ascent(BufferView *, LyXFont const &) const
247 return tabular->GetAscentOfRow(0);
251 int InsetTabular::descent(BufferView *, LyXFont const &) const
253 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
257 int InsetTabular::width(BufferView *, LyXFont const &) const
259 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
263 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
271 Painter & pain = bv->painter();
277 UpdatableInset::draw(bv, font, baseline, x);
280 x += static_cast<float>(scroll());
284 top_baseline = baseline;
285 x += ADD_TO_TABULAR_WIDTH;
289 first_visible_cell = -1;
290 for (i = 0; i < tabular->rows(); ++i) {
292 cell = tabular->GetCellNumber(i, 0);
293 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
294 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
296 baseline += tabular->GetDescentOfRow(i) +
297 tabular->GetAscentOfRow(i + 1) +
298 tabular->GetAdditionalHeight(i + 1);
301 for (j = 0; j < tabular->columns(); ++j) {
302 if (nx > bv->workWidth())
304 if (tabular->IsPartOfMultiColumn(i, j))
306 cx = nx + tabular->GetBeginningOfTextInCell(cell);
307 if (first_visible_cell < 0)
308 first_visible_cell = cell;
309 if (hasSelection()) {
310 drawCellSelection(pain, nx, baseline, i, j, cell);
313 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
314 drawCellLines(pain, nx, baseline, i, cell);
315 nx += tabular->GetWidthOfColumn(cell);
318 baseline += tabular->GetDescentOfRow(i) +
319 tabular->GetAscentOfRow(i + 1) +
320 tabular->GetAdditionalHeight(i + 1);
323 x -= ADD_TO_TABULAR_WIDTH;
324 x += width(bv, font);
329 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
330 int row, int cell) const
332 int x2 = x + tabular->GetWidthOfColumn(cell);
335 if (!tabular->topAlreadyDrawn(cell)) {
336 on_off = !tabular->TopLine(cell);
337 pain.line(x, baseline - tabular->GetAscentOfRow(row),
338 x2, baseline - tabular->GetAscentOfRow(row),
339 on_off ? LColor::tabularonoffline : LColor::tabularline,
340 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 on_off = !tabular->BottomLine(cell);
343 pain.line(x, baseline + tabular->GetDescentOfRow(row),
344 x2, baseline + tabular->GetDescentOfRow(row),
345 on_off ? LColor::tabularonoffline : LColor::tabularline,
346 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 if (!tabular->leftAlreadyDrawn(cell)) {
348 on_off = !tabular->LeftLine(cell);
349 pain.line(x, baseline - tabular->GetAscentOfRow(row),
350 x, baseline + tabular->GetDescentOfRow(row),
351 on_off ? LColor::tabularonoffline : LColor::tabularline,
352 on_off ? Painter::line_onoffdash : Painter::line_solid);
354 on_off = !tabular->RightLine(cell);
355 pain.line(x2 - tabular->GetAdditionalWidth(cell),
356 baseline - tabular->GetAscentOfRow(row),
357 x2 - tabular->GetAdditionalWidth(cell),
358 baseline + tabular->GetDescentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
364 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
365 int row, int column, int cell) const
367 lyx::Assert(hasSelection());
368 int cs = tabular->column_of_cell(sel_cell_start);
369 int ce = tabular->column_of_cell(sel_cell_end);
372 cs = tabular->column_of_cell(sel_cell_end);
374 ce = tabular->right_column_of_cell(sel_cell_end);
377 int rs = tabular->row_of_cell(sel_cell_start);
378 int re = tabular->row_of_cell(sel_cell_end);
382 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
383 int w = tabular->GetWidthOfColumn(cell);
384 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
385 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
386 w, h, LColor::selection);
391 void InsetTabular::update(BufferView * bv, bool reinit)
397 owner()->update(bv, true);
404 if (calculate_dimensions_of_cells(bv, true))
407 owner()->update(bv, true);
411 if (the_locking_inset)
412 the_locking_inset->update(bv, reinit);
413 if (need_update < FULL &&
414 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
419 switch (need_update) {
423 if (calculate_dimensions_of_cells(bv, false)) {
438 string const InsetTabular::editMessage() const
440 return _("Opened Tabular Inset");
444 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
446 UpdatableInset::edit(bv, x, y, button);
448 if (!bv->lockInset(this)) {
449 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
453 the_locking_inset = 0;
459 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
460 activateCellInsetAbs(bv, x, y, button);
465 void InsetTabular::edit(BufferView * bv, bool front)
467 UpdatableInset::edit(bv, front);
469 if (!bv->lockInset(this)) {
470 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
475 the_locking_inset = 0;
479 if (isRightToLeft(bv))
480 actcell = tabular->GetLastCellInRow(0);
484 if (isRightToLeft(bv))
485 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
487 actcell = tabular->GetNumberOfCells() - 1;
495 void InsetTabular::insetUnlock(BufferView * bv)
497 if (the_locking_inset) {
498 the_locking_inset->insetUnlock(bv);
499 updateLocal(bv, CELL);
500 the_locking_inset = 0;
506 if (scroll(false) || hasSelection()) {
511 updateLocal(bv, FULL);
516 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
519 calculate_dimensions_of_cells(bv, true);
521 if (!locked && what == CELL)
523 if (need_update < what) // only set this if it has greater update
526 if (need_update != NONE) {
527 bv->updateInset(const_cast<InsetTabular *>(this));
534 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
536 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
541 if (inset == tabular->GetCellInset(actcell)) {
542 lyxerr[Debug::INSETTEXT] << "OK" << endl;
543 the_locking_inset = tabular->GetCellInset(actcell);
546 } else if (!the_locking_inset) {
547 int const n = tabular->GetNumberOfCells();
548 int const id = inset->id();
549 for (int i = 0; i < n; ++i) {
550 InsetText * in = tabular->GetCellInset(i);
553 the_locking_inset = in;
558 if (in->getInsetFromID(id)) {
561 return the_locking_inset->lockInsetInInset(bv, inset);
564 } else if (the_locking_inset && (the_locking_inset == inset)) {
565 lyxerr[Debug::INSETTEXT] << "OK" << endl;
567 } else if (the_locking_inset) {
568 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
569 return the_locking_inset->lockInsetInInset(bv, inset);
571 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
576 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
579 if (!the_locking_inset)
581 if (the_locking_inset == inset) {
582 the_locking_inset->insetUnlock(bv);
584 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
590 updateLocal(bv, CELL);
591 // this has to be here otherwise we don't redraw the cell!
592 the_locking_inset = 0;
593 // showInsetCursor(bv, false);
596 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
597 if (inset->lyxCode() == TABULAR_CODE &&
598 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
599 InsetTabularMailer mailer(*this);
600 mailer.updateDialog(bv);
609 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
611 Inset * tl_inset = inset;
612 // look if this inset is really inside myself!
613 while(tl_inset->owner() && tl_inset->owner() != this)
614 tl_inset = tl_inset->owner();
615 // if we enter here it's not ower inset
616 if (!tl_inset->owner())
618 // we only have to do this if this is a subinset of our cells
619 if (tl_inset != inset) {
620 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
623 updateLocal(bv, CELL);
628 int InsetTabular::insetInInsetY() const
630 if (!the_locking_inset)
632 return inset_y + the_locking_inset->insetInInsetY();
636 UpdatableInset * InsetTabular::getLockingInset() const
638 return the_locking_inset ? the_locking_inset->getLockingInset() :
639 const_cast<InsetTabular *>(this);
643 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
647 if (the_locking_inset)
648 return the_locking_inset->getFirstLockingInsetOfType(c);
653 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
655 if (the_locking_inset)
656 return the_locking_inset->insertInset(bv, inset);
661 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
663 if (hasSelection() && cmd.button() == mouse_button::button3)
666 if (hasSelection()) {
668 updateLocal(cmd.view(), SELECTION);
671 int const ocell = actcell;
672 int const orow = actrow;
673 BufferView * bv = cmd.view();
678 the_locking_inset = 0;
682 setPos(bv, cmd.x, cmd.y);
684 updateLocal(bv, NONE);
687 if (cmd.button() == mouse_button::button3) {
688 if ((ocell != actcell) && the_locking_inset) {
689 the_locking_inset->insetUnlock(bv);
690 updateLocal(bv, CELL);
691 the_locking_inset = 0;
698 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
700 if ((ocell == actcell) && the_locking_inset && inset_hit) {
702 FuncRequest cmd1 = cmd;
705 the_locking_inset->localDispatch(cmd1);
709 if (the_locking_inset) {
710 the_locking_inset->insetUnlock(bv);
711 updateLocal(bv, CELL);
712 the_locking_inset = 0;
715 if (cmd.button() == mouse_button::button2) {
716 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
720 if (inset_hit && bv->theLockingInset()) {
721 if (!bv->lockInset(static_cast<UpdatableInset*>
722 (tabular->GetCellInset(actcell))))
724 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
727 FuncRequest cmd1 = cmd;
730 the_locking_inset->localDispatch(cmd1);
737 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
740 if (the_locking_inset) {
741 FuncRequest cmd1 = cmd;
744 ret = the_locking_inset->localDispatch(cmd1);
746 if (cmd.button() == mouse_button::button3 && !ret) {
747 InsetTabularMailer mailer(*this);
748 mailer.showDialog(cmd.view());
755 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
757 if (the_locking_inset) {
758 FuncRequest cmd1 = cmd;
761 the_locking_inset->localDispatch(cmd1);
765 BufferView * bv = cmd.view();
767 int const old_cell = actcell;
769 setPos(bv, cmd.x, cmd.y);
770 if (!hasSelection()) {
771 setSelection(actcell, actcell);
772 updateLocal(bv, SELECTION);
773 } else if (old_cell != actcell) {
774 setSelection(sel_cell_start, actcell);
775 updateLocal(bv, SELECTION);
781 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
783 // We need to save the value of the_locking_inset as the call to
784 // the_locking_inset->localDispatch might unlock it.
785 old_locking_inset = the_locking_inset;
786 RESULT result = UpdatableInset::localDispatch(cmd);
788 BufferView * bv = cmd.view();
789 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
794 if (cmd.action < 0 && cmd.argument.empty())
797 bool hs = hasSelection();
800 // this one have priority over the locked InsetText, if we're not already
801 // inside another tabular then that one get's priority!
802 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
803 switch (cmd.action) {
804 case LFUN_MOUSE_PRESS:
808 case LFUN_MOUSE_MOTION:
809 lfunMouseMotion(cmd);
812 case LFUN_MOUSE_RELEASE:
813 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
818 unlockInsetInInset(bv, the_locking_inset);
819 if (cmd.action == LFUN_TAB)
820 moveNextCell(bv, old_locking_inset != 0);
822 movePrevCell(bv, old_locking_inset != 0);
825 updateLocal(bv, SELECTION);
826 if (!the_locking_inset) {
828 return DISPATCHED_NOUPDATE;
831 // this to avoid compiler warnings.
837 kb_action action = cmd.action;
838 string arg = cmd.argument;
839 if (the_locking_inset) {
840 result = the_locking_inset->localDispatch(cmd);
841 if (result == DISPATCHED_NOUPDATE) {
844 if (sc != scroll()) { // inset has been scrolled
845 the_locking_inset->toggleInsetCursor(bv);
846 updateLocal(bv, FULL);
847 the_locking_inset->toggleInsetCursor(bv);
850 } else if (result == DISPATCHED) {
851 the_locking_inset->toggleInsetCursor(bv);
852 updateLocal(bv, CELL);
853 the_locking_inset->toggleInsetCursor(bv);
855 } else if (result == FINISHED_UP) {
857 } else if (result == FINISHED_DOWN) {
859 } else if (result == FINISHED_RIGHT) {
867 // --- Cursor Movements ----------------------------------
868 case LFUN_RIGHTSEL: {
869 int const start = hasSelection() ? sel_cell_start : actcell;
870 if (tabular->IsLastCellInRow(actcell)) {
871 setSelection(start, actcell);
876 // if we are starting a selection, only select
877 // the current cell at the beginning
878 if (hasSelection()) {
879 moveRight(bv, false);
882 setSelection(start, end);
883 updateLocal(bv, SELECTION);
887 result = moveRight(bv);
890 updateLocal(bv, SELECTION);
893 int const start = hasSelection() ? sel_cell_start : actcell;
894 if (tabular->IsFirstCellInRow(actcell)) {
895 setSelection(start, actcell);
900 // if we are starting a selection, only select
901 // the current cell at the beginning
902 if (hasSelection()) {
906 setSelection(start, end);
907 updateLocal(bv, SELECTION);
911 result = moveLeft(bv);
914 updateLocal(bv, SELECTION);
917 int const start = hasSelection() ? sel_cell_start : actcell;
918 int const ocell = actcell;
919 // if we are starting a selection, only select
920 // the current cell at the beginning
921 if (hasSelection()) {
923 if ((ocell == sel_cell_end) ||
924 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
925 setSelection(start, tabular->GetCellBelow(sel_cell_end));
927 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
929 setSelection(start, start);
931 updateLocal(bv, SELECTION);
935 result = moveDown(bv, old_locking_inset != 0);
938 updateLocal(bv, SELECTION);
942 int const start = hasSelection() ? sel_cell_start : actcell;
943 int const ocell = actcell;
944 // if we are starting a selection, only select
945 // the current cell at the beginning
946 if (hasSelection()) {
948 if ((ocell == sel_cell_end) ||
949 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
950 setSelection(start, tabular->GetCellAbove(sel_cell_end));
952 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
954 setSelection(start, start);
956 updateLocal(bv, SELECTION);
960 result = moveUp(bv, old_locking_inset != 0);
963 updateLocal(bv, SELECTION);
966 UpdateCodes code = CURSOR;
972 unlockInsetInInset(bv, the_locking_inset);
973 if (bv->text->top_y() + bv->painter().paperHeight() <
974 (top_baseline + tabular->GetHeightOfTabular()))
976 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
978 actcell = tabular->GetCellBelow(first_visible_cell) + column;
980 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
983 updateLocal(bv, code);
987 UpdateCodes code = CURSOR;
993 unlockInsetInInset(bv, the_locking_inset);
994 if (top_baseline < 0) {
995 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
997 if (top_baseline > 0)
1000 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1005 updateLocal(bv, code);
1008 // none of these make sense for insettabular,
1009 // but we must catch them to prevent any
1010 // selection from being confused
1014 case LFUN_WORDLEFTSEL:
1015 case LFUN_WORDRIGHT:
1016 case LFUN_WORDRIGHTSEL:
1018 case LFUN_DOWN_PARAGRAPH:
1019 case LFUN_DOWN_PARAGRAPHSEL:
1020 case LFUN_UP_PARAGRAPH:
1021 case LFUN_UP_PARAGRAPHSEL:
1022 case LFUN_BACKSPACE:
1027 case LFUN_BEGINNINGBUF:
1028 case LFUN_BEGINNINGBUFSEL:
1030 case LFUN_ENDBUFSEL:
1032 case LFUN_LAYOUT_TABULAR: {
1033 InsetTabularMailer mailer(*this);
1034 mailer.showDialog(bv);
1037 case LFUN_INSET_DIALOG_UPDATE: {
1038 InsetTabularMailer mailer(*this);
1039 mailer.updateDialog(bv);
1042 case LFUN_TABULAR_FEATURE:
1043 if (!tabularFeatures(bv, arg))
1044 result = UNDISPATCHED;
1046 // insert file functions
1047 case LFUN_FILE_INSERT_ASCII_PARA:
1048 case LFUN_FILE_INSERT_ASCII:
1050 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1053 if (insertAsciiString(bv, tmpstr, false))
1054 updateLocal(bv, INIT);
1056 result = UNDISPATCHED;
1059 // cut and paste functions
1061 if (!copySelection(bv))
1065 setUndo(bv, Undo::DELETE,
1066 bv->text->cursor.par(),
1067 bv->text->cursor.par()->next());
1068 cutSelection(bv->buffer()->params);
1069 updateLocal(bv, INIT);
1072 if (!hasSelection())
1077 case LFUN_PASTESELECTION:
1079 string const clip(bv->getClipboard());
1083 if (clip.find('\t') != string::npos) {
1087 string::size_type len = clip.length();
1088 string::size_type p = 0;
1091 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1099 maxCols = max(cols, maxCols);
1105 maxCols = max(cols, maxCols);
1106 delete paste_tabular;
1107 paste_tabular = new LyXTabular(bv->buffer()->params,
1108 this, rows, maxCols);
1109 string::size_type op = 0;
1111 int cells = paste_tabular->GetNumberOfCells();
1113 while ((cell < cells) && (p < len) &&
1114 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1119 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1124 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1125 while (cols++ < maxCols)
1133 // check for the last cell if there is no trailing '\n'
1134 if ((cell < cells) && (op < len))
1135 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1138 if (!insertAsciiString(bv, clip, true))
1141 // so that the clipboard is used and it goes on
1143 // and executes LFUN_PASTESELECTION in insettext!
1144 delete paste_tabular;
1149 if (hasPasteBuffer()) {
1150 setUndo(bv, Undo::INSERT,
1151 bv->text->cursor.par(),
1152 bv->text->cursor.par()->next());
1154 updateLocal(bv, INIT);
1157 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1159 // handle font changing stuff on selection before we lock the inset
1160 // in the default part!
1161 result = UNDISPATCHED;
1172 case LFUN_UNDERLINE:
1173 case LFUN_FONT_SIZE:
1174 if (bv->dispatch(FuncRequest(bv, action, arg)))
1175 result = DISPATCHED;
1181 // we try to activate the actual inset and put this event down to
1182 // the insets dispatch function.
1183 if ((result == DISPATCHED) || the_locking_inset)
1186 if (activateCellInset(bv)) {
1187 // reset need_update setted in above function!
1189 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1190 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1191 unlockInsetInInset(bv, the_locking_inset);
1193 // we need to update if this was requested before
1194 updateLocal(bv, NONE);
1195 return UNDISPATCHED;
1198 // so the below CELL is not set because this is higher
1199 // priority and we get a full redraw
1200 need_update = SELECTION;
1203 updateLocal(bv, CELL);
1208 if (result < FINISHED) {
1209 if (!the_locking_inset) {
1210 if (bv->fitCursor())
1211 updateLocal(bv, FULL);
1213 showInsetCursor(bv);
1216 bv->unlockInset(this);
1221 int InsetTabular::latex(Buffer const * buf, ostream & os,
1222 bool fragile, bool fp) const
1224 return tabular->latex(buf, os, fragile, fp);
1228 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1231 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1233 return tabular->ascii(buf, os, 0, false,0);
1237 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1240 int const ret = tabular->ascii(buf,os,
1241 (int)parOwner()->params().depth(),
1248 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1253 // if the table is inside a float it doesn't need the informaltable
1254 // wrapper. Search for it.
1255 for(master = owner();
1256 master && master->lyxCode() != Inset::FLOAT_CODE;
1257 master = master->owner());
1260 os << "<informaltable>";
1265 ret+= tabular->docbook(buf, os, mixcont);
1267 os << "</informaltable>";
1276 void InsetTabular::validate(LaTeXFeatures & features) const
1278 tabular->Validate(features);
1282 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1288 bool changed = false;
1290 // FIXME: since InsetText ignores this anyway, it doesn't
1291 // matter what we pass it. Ugly
1294 // if we have a locking_inset we should have to check only this cell for
1295 // change so I'll try this to have a boost, but who knows ;)
1296 if ((need_update != INIT) &&
1297 (the_locking_inset == tabular->GetCellInset(actcell))) {
1298 for(int i = 0; i < tabular->columns(); ++i) {
1299 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1301 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1304 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1305 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1306 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1309 for (int i = 0; i < tabular->rows(); ++i) {
1312 for (int j = 0; j < tabular->columns(); ++j) {
1313 if (tabular->IsPartOfMultiColumn(i,j))
1316 inset = tabular->GetCellInset(cell);
1317 if (!reinit && !tabular->GetPWidth(cell).zero())
1318 inset->update(bv, false);
1319 maxAsc = max(maxAsc, inset->ascent(bv, font));
1320 maxDesc = max(maxDesc, inset->descent(bv, font));
1321 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1323 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1324 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1332 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1334 if (the_locking_inset) {
1335 the_locking_inset->getCursorPos(bv, x, y);
1338 x = cursor_.x() - top_x;
1343 void InsetTabular::toggleInsetCursor(BufferView * bv)
1346 if (isCursorVisible())
1347 bv->hideLockedInsetCursor();
1350 if (the_locking_inset) {
1351 the_locking_inset->toggleInsetCursor(bv);
1355 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1357 int const asc = font_metrics::maxAscent(font);
1358 int const desc = font_metrics::maxDescent(font);
1360 if (isCursorVisible())
1361 bv->hideLockedInsetCursor();
1363 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1364 toggleCursorVisible();
1368 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1372 if (!isCursorVisible()) {
1373 LyXFont font; // = GetFont(par, cursor.pos);
1375 int const asc = font_metrics::maxAscent(font);
1376 int const desc = font_metrics::maxDescent(font);
1377 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1379 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1380 setCursorVisible(true);
1385 void InsetTabular::hideInsetCursor(BufferView * bv)
1387 if (isCursorVisible()) {
1388 bv->hideLockedInsetCursor();
1389 setCursorVisible(false);
1394 void InsetTabular::fitInsetCursor(BufferView * bv) const
1396 if (the_locking_inset) {
1397 int old_top_y = bv->text->top_y();
1398 the_locking_inset->fitInsetCursor(bv);
1399 if (old_top_y != bv->text->top_y())
1405 int const asc = font_metrics::maxAscent(font);
1406 int const desc = font_metrics::maxDescent(font);
1409 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1414 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1418 actcell = actrow = actcol = 0;
1419 int ly = tabular->GetDescentOfRow(actrow);
1421 // first search the right row
1422 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1423 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1424 tabular->GetAscentOfRow(actrow + 1) +
1425 tabular->GetAdditionalHeight(actrow + 1));
1427 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1429 actcell = tabular->GetCellNumber(actrow, actcol);
1431 // now search the right column
1432 int lx = tabular->GetWidthOfColumn(actcell) -
1433 tabular->GetAdditionalWidth(actcell);
1434 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1435 lx += tabular->GetWidthOfColumn(actcell + 1)
1436 + tabular->GetAdditionalWidth(actcell);
1438 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1443 int InsetTabular::getCellXPos(int cell) const
1447 for (; !tabular->IsFirstCellInRow(c); --c)
1449 int lx = tabular->GetWidthOfColumn(cell);
1450 for (; c < cell; ++c) {
1451 lx += tabular->GetWidthOfColumn(c);
1453 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1457 void InsetTabular::resetPos(BufferView * bv) const
1459 #ifdef WITH_WARNINGS
1460 #warning This should be fixed in the right manner (20011128 Jug)
1462 // fast hack to fix infinite repaintings!
1463 if (in_reset_pos > 0)
1467 actcol = tabular->column_of_cell(actcell);
1470 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1471 if (tabular->IsLastCellInRow(cell)) {
1472 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1473 tabular->GetAscentOfRow(actrow + 1) +
1474 tabular->GetAdditionalHeight(actrow + 1));
1478 if (!locked || nodraw()) {
1479 if (the_locking_inset)
1480 inset_y = cursor_.y();
1483 // we need this only from here on!!!
1485 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1486 int new_x = getCellXPos(actcell);
1487 int old_x = cursor_.x();
1490 // cursor.x(getCellXPos(actcell) + offset);
1491 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1492 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1495 updateLocal(bv, FULL);
1496 } else if (the_locking_inset &&
1497 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1499 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1500 if (xx > (bv->workWidth()-20)) {
1501 scroll(bv, -(xx - bv->workWidth() + 60));
1502 updateLocal(bv, FULL);
1503 } else if (xx < 20) {
1509 updateLocal(bv, FULL);
1511 } else if ((cursor_.x() - offset) > 20 &&
1512 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1513 > (bv->workWidth() - 20)) {
1514 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1515 updateLocal(bv, FULL);
1516 } else if ((cursor_.x() - offset) < 20) {
1517 scroll(bv, 20 - cursor_.x() + offset);
1518 updateLocal(bv, FULL);
1519 } else if (scroll() && top_x > 20 &&
1520 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1521 scroll(bv, old_x - cursor_.x());
1522 updateLocal(bv, FULL);
1524 if (the_locking_inset) {
1525 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1526 inset_y = cursor_.y();
1528 if ((!the_locking_inset ||
1529 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1530 actcell != oldcell) {
1531 InsetTabular * inset = const_cast<InsetTabular *>(this);
1532 InsetTabularMailer mailer(*inset);
1533 mailer.updateDialog(bv);
1540 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1542 if (lock && !old_locking_inset) {
1543 if (activateCellInset(bv))
1546 bool moved = isRightToLeft(bv)
1547 ? movePrevCell(bv) : moveNextCell(bv);
1549 return FINISHED_RIGHT;
1550 if (lock && activateCellInset(bv))
1554 return DISPATCHED_NOUPDATE;
1558 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1560 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1563 if (lock) { // behind the inset
1564 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1568 return DISPATCHED_NOUPDATE;
1572 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1574 int const ocell = actcell;
1575 actcell = tabular->GetCellAbove(actcell);
1576 if (actcell == ocell) // we moved out of the inset
1582 if (old_locking_inset) {
1583 old_locking_inset->getCursorPos(bv, x, y);
1584 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1586 if (activateCellInset(bv, x, 0))
1589 return DISPATCHED_NOUPDATE;
1593 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1595 int const ocell = actcell;
1596 actcell = tabular->GetCellBelow(actcell);
1597 if (actcell == ocell) // we moved out of the inset
1598 return FINISHED_DOWN;
1603 if (old_locking_inset) {
1604 old_locking_inset->getCursorPos(bv, x, y);
1605 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1607 if (activateCellInset(bv, x, 0))
1610 return DISPATCHED_NOUPDATE;
1614 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1616 if (isRightToLeft(bv)) {
1617 if (tabular->IsFirstCellInRow(actcell)) {
1618 int row = tabular->row_of_cell(actcell);
1619 if (row == tabular->rows() - 1)
1621 actcell = tabular->GetLastCellInRow(row);
1622 actcell = tabular->GetCellBelow(actcell);
1629 if (tabular->IsLastCell(actcell))
1634 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1635 isRightToLeftPar(bv->buffer()->params);
1636 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1643 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1645 if (isRightToLeft(bv)) {
1646 if (tabular->IsLastCellInRow(actcell)) {
1647 int row = tabular->row_of_cell(actcell);
1650 actcell = tabular->GetFirstCellInRow(row);
1651 actcell = tabular->GetCellAbove(actcell);
1653 if (tabular->IsLastCell(actcell))
1658 if (!actcell) // first cell
1663 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1664 isRightToLeftPar(bv->buffer()->params);
1665 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1672 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1676 setSelection(0, tabular->GetNumberOfCells() - 1);
1678 if (hasSelection()) {
1679 setUndo(bv, Undo::EDIT,
1680 bv->text->cursor.par(),
1681 bv->text->cursor.par()->next());
1682 bool const frozen = undo_frozen;
1685 // apply the fontchange on the whole selection
1690 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1691 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1692 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1693 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1700 updateLocal(bv, INIT);
1702 if (the_locking_inset)
1703 the_locking_inset->setFont(bv, font, tall);
1707 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1709 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1712 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1713 string const tmp = tabularFeature[i].feature;
1715 if (tmp == what.substr(0, tmp.length())) {
1716 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1717 //tabularFeatures[i].feature.length())) {
1718 action = tabularFeature[i].action;
1722 if (action == LyXTabular::LAST_ACTION)
1726 ltrim(what.substr(tabularFeature[i].feature.length()));
1727 tabularFeatures(bv, action, val);
1733 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1734 string const & special, bool & flag)
1736 if (special == "dl_above") {
1739 } else if (special == "dl_below") {
1740 ltt.bottomDL = flag;
1742 } else if (special == "empty") {
1754 void InsetTabular::tabularFeatures(BufferView * bv,
1755 LyXTabular::Feature feature,
1756 string const & value)
1762 bool setLines = false;
1763 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1764 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1767 case LyXTabular::M_ALIGN_LEFT:
1768 case LyXTabular::ALIGN_LEFT:
1769 setAlign = LYX_ALIGN_LEFT;
1771 case LyXTabular::M_ALIGN_RIGHT:
1772 case LyXTabular::ALIGN_RIGHT:
1773 setAlign = LYX_ALIGN_RIGHT;
1775 case LyXTabular::M_ALIGN_CENTER:
1776 case LyXTabular::ALIGN_CENTER:
1777 setAlign = LYX_ALIGN_CENTER;
1779 case LyXTabular::ALIGN_BLOCK:
1780 setAlign = LYX_ALIGN_BLOCK;
1782 case LyXTabular::M_VALIGN_TOP:
1783 case LyXTabular::VALIGN_TOP:
1784 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1786 case LyXTabular::M_VALIGN_BOTTOM:
1787 case LyXTabular::VALIGN_BOTTOM:
1788 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1790 case LyXTabular::M_VALIGN_CENTER:
1791 case LyXTabular::VALIGN_CENTER:
1792 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1797 if (hasSelection()) {
1798 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1800 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1801 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1803 setUndo(bv, Undo::FINISH,
1804 bv->text->cursor.par(),
1805 bv->text->cursor.par()->next());
1807 int row = tabular->row_of_cell(actcell);
1808 int column = tabular->column_of_cell(actcell);
1810 LyXTabular::ltType ltt;
1813 case LyXTabular::SET_PWIDTH:
1815 LyXLength const vallen(value);
1816 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1818 bool const update = (tmplen != vallen);
1819 tabular->SetColumnPWidth(actcell, vallen);
1822 for (int i = 0; i < tabular->rows(); ++i) {
1823 cell = tabular->GetCellNumber(i,column);
1824 tabular->GetCellInset(cell)->resizeLyXText(bv);
1826 updateLocal(bv, INIT);
1830 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1831 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1832 else if (!vallen.zero()
1833 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1834 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1837 case LyXTabular::SET_MPWIDTH:
1839 LyXLength const vallen(value);
1840 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1842 bool const update = (tmplen != vallen);
1843 tabular->SetMColumnPWidth(actcell, vallen);
1845 for (int i = 0; i < tabular->rows(); ++i) {
1846 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1849 updateLocal(bv, INIT);
1853 case LyXTabular::SET_SPECIAL_COLUMN:
1854 case LyXTabular::SET_SPECIAL_MULTI:
1855 tabular->SetAlignSpecial(actcell,value,feature);
1856 updateLocal(bv, FULL);
1858 case LyXTabular::APPEND_ROW:
1859 // append the row into the tabular
1860 unlockInsetInInset(bv, the_locking_inset);
1861 tabular->AppendRow(bv->buffer()->params, actcell);
1862 updateLocal(bv, INIT);
1864 case LyXTabular::APPEND_COLUMN:
1865 // append the column into the tabular
1866 unlockInsetInInset(bv, the_locking_inset);
1867 tabular->AppendColumn(bv->buffer()->params, actcell);
1868 actcell = tabular->GetCellNumber(row, column);
1869 updateLocal(bv, INIT);
1871 case LyXTabular::DELETE_ROW:
1872 unlockInsetInInset(bv, the_locking_inset);
1873 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1874 tabular->DeleteRow(sel_row_start);
1876 if (sel_row_start >= tabular->rows())
1878 actcell = tabular->GetCellNumber(sel_row_start, column);
1880 updateLocal(bv, INIT);
1882 case LyXTabular::DELETE_COLUMN:
1883 unlockInsetInInset(bv, the_locking_inset);
1884 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1885 tabular->DeleteColumn(sel_col_start);
1887 if (sel_col_start >= tabular->columns())
1889 actcell = tabular->GetCellNumber(row, sel_col_start);
1891 updateLocal(bv, INIT);
1893 case LyXTabular::M_TOGGLE_LINE_TOP:
1895 case LyXTabular::TOGGLE_LINE_TOP:
1897 bool lineSet = !tabular->TopLine(actcell, flag);
1898 for (int i = sel_row_start; i <= sel_row_end; ++i)
1899 for (int j = sel_col_start; j <= sel_col_end; ++j)
1900 tabular->SetTopLine(
1901 tabular->GetCellNumber(i, j),
1903 updateLocal(bv, INIT);
1907 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1909 case LyXTabular::TOGGLE_LINE_BOTTOM:
1911 bool lineSet = !tabular->BottomLine(actcell, flag);
1912 for (int i = sel_row_start; i <= sel_row_end; ++i)
1913 for (int j = sel_col_start; j <= sel_col_end; ++j)
1914 tabular->SetBottomLine(
1915 tabular->GetCellNumber(i, j),
1918 updateLocal(bv, INIT);
1922 case LyXTabular::M_TOGGLE_LINE_LEFT:
1924 case LyXTabular::TOGGLE_LINE_LEFT:
1926 bool lineSet = !tabular->LeftLine(actcell, flag);
1927 for (int i = sel_row_start; i <= sel_row_end; ++i)
1928 for (int j = sel_col_start; j <= sel_col_end; ++j)
1929 tabular->SetLeftLine(
1930 tabular->GetCellNumber(i,j),
1933 updateLocal(bv, INIT);
1937 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1939 case LyXTabular::TOGGLE_LINE_RIGHT:
1941 bool lineSet = !tabular->RightLine(actcell, flag);
1942 for (int i = sel_row_start; i <= sel_row_end; ++i)
1943 for (int j = sel_col_start; j <= sel_col_end; ++j)
1944 tabular->SetRightLine(
1945 tabular->GetCellNumber(i,j),
1948 updateLocal(bv, INIT);
1952 case LyXTabular::M_ALIGN_LEFT:
1953 case LyXTabular::M_ALIGN_RIGHT:
1954 case LyXTabular::M_ALIGN_CENTER:
1956 case LyXTabular::ALIGN_LEFT:
1957 case LyXTabular::ALIGN_RIGHT:
1958 case LyXTabular::ALIGN_CENTER:
1959 case LyXTabular::ALIGN_BLOCK:
1960 for (int i = sel_row_start; i <= sel_row_end; ++i)
1961 for (int j = sel_col_start; j <= sel_col_end; ++j)
1962 tabular->SetAlignment(
1963 tabular->GetCellNumber(i, j),
1966 updateLocal(bv, INIT);
1968 case LyXTabular::M_VALIGN_TOP:
1969 case LyXTabular::M_VALIGN_BOTTOM:
1970 case LyXTabular::M_VALIGN_CENTER:
1972 case LyXTabular::VALIGN_TOP:
1973 case LyXTabular::VALIGN_BOTTOM:
1974 case LyXTabular::VALIGN_CENTER:
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->SetVAlignment(
1978 tabular->GetCellNumber(i, j),
1980 updateLocal(bv, INIT);
1982 case LyXTabular::MULTICOLUMN:
1984 if (sel_row_start != sel_row_end) {
1985 #ifdef WITH_WARNINGS
1986 #warning Need I say it ? This is horrible.
1988 Alert::error(_("Error setting multicolumn"),
1989 _("You cannot set multicolumn vertically."));
1992 // just multicol for one Single Cell
1993 if (!hasSelection()) {
1994 // check wether we are completly in a multicol
1995 if (tabular->IsMultiColumn(actcell)) {
1996 tabular->UnsetMultiColumn(actcell);
1997 updateLocal(bv, INIT);
1999 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2000 updateLocal(bv, CELL);
2004 // we have a selection so this means we just add all this
2005 // cells to form a multicolumn cell
2009 if (sel_cell_start > sel_cell_end) {
2010 s_start = sel_cell_end;
2011 s_end = sel_cell_start;
2013 s_start = sel_cell_start;
2014 s_end = sel_cell_end;
2016 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2019 updateLocal(bv, INIT);
2022 case LyXTabular::SET_ALL_LINES:
2024 case LyXTabular::UNSET_ALL_LINES:
2025 for (int i = sel_row_start; i <= sel_row_end; ++i)
2026 for (int j = sel_col_start; j <= sel_col_end; ++j)
2027 tabular->SetAllLines(
2028 tabular->GetCellNumber(i,j), setLines);
2029 updateLocal(bv, INIT);
2031 case LyXTabular::SET_LONGTABULAR:
2032 tabular->SetLongTabular(true);
2033 updateLocal(bv, INIT); // because this toggles displayed
2035 case LyXTabular::UNSET_LONGTABULAR:
2036 tabular->SetLongTabular(false);
2037 updateLocal(bv, INIT); // because this toggles displayed
2039 case LyXTabular::SET_ROTATE_TABULAR:
2040 tabular->SetRotateTabular(true);
2042 case LyXTabular::UNSET_ROTATE_TABULAR:
2043 tabular->SetRotateTabular(false);
2045 case LyXTabular::SET_ROTATE_CELL:
2046 for (int i = sel_row_start; i <= sel_row_end; ++i)
2047 for (int j = sel_col_start; j<=sel_col_end; ++j)
2048 tabular->SetRotateCell(
2049 tabular->GetCellNumber(i, j),
2052 case LyXTabular::UNSET_ROTATE_CELL:
2053 for (int i = sel_row_start; i <= sel_row_end; ++i)
2054 for (int j = sel_col_start; j <= sel_col_end; ++j)
2055 tabular->SetRotateCell(
2056 tabular->GetCellNumber(i, j), false);
2058 case LyXTabular::SET_USEBOX:
2060 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2061 if (val == tabular->GetUsebox(actcell))
2062 val = LyXTabular::BOX_NONE;
2063 for (int i = sel_row_start; i <= sel_row_end; ++i)
2064 for (int j = sel_col_start; j <= sel_col_end; ++j)
2066 tabular->GetCellNumber(i, j), val);
2069 case LyXTabular::UNSET_LTFIRSTHEAD:
2071 case LyXTabular::SET_LTFIRSTHEAD:
2072 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2073 checkLongtableSpecial(ltt, value, flag);
2074 tabular->SetLTHead(row, flag, ltt, true);
2076 case LyXTabular::UNSET_LTHEAD:
2078 case LyXTabular::SET_LTHEAD:
2079 (void)tabular->GetRowOfLTHead(row, ltt);
2080 checkLongtableSpecial(ltt, value, flag);
2081 tabular->SetLTHead(row, flag, ltt, false);
2083 case LyXTabular::UNSET_LTFOOT:
2085 case LyXTabular::SET_LTFOOT:
2086 (void)tabular->GetRowOfLTFoot(row, ltt);
2087 checkLongtableSpecial(ltt, value, flag);
2088 tabular->SetLTFoot(row, flag, ltt, false);
2090 case LyXTabular::UNSET_LTLASTFOOT:
2092 case LyXTabular::SET_LTLASTFOOT:
2093 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2094 checkLongtableSpecial(ltt, value, flag);
2095 tabular->SetLTFoot(row, flag, ltt, true);
2097 case LyXTabular::SET_LTNEWPAGE:
2099 bool what = !tabular->GetLTNewPage(row);
2100 tabular->SetLTNewPage(row, what);
2103 // dummy stuff just to avoid warnings
2104 case LyXTabular::LAST_ACTION:
2110 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2113 UpdatableInset * inset =
2114 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2115 LyXFont font(LyXFont::ALL_SANE);
2117 x = inset->x() + inset->width(bv, font);
2118 y = inset->descent(bv, font);
2120 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2121 //inset_y = cursor.y();
2122 inset->edit(bv, x, y, button);
2123 if (!the_locking_inset)
2125 updateLocal(bv, CELL);
2126 return (the_locking_inset != 0);
2130 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2131 mouse_button::state button)
2133 inset_x = cursor_.x()
2134 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2135 inset_y = cursor_.y();
2136 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2140 bool InsetTabular::insetHit(BufferView *, int x, int) const
2143 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2147 // This returns paperWidth() if the cell-width is unlimited or the width
2148 // in pixels if we have a pwidth for this cell.
2149 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2151 LyXLength const len = tabular->GetPWidth(cell);
2155 return len.inPixels(latexTextWidth(bv));
2159 int InsetTabular::getMaxWidth(BufferView * bv,
2160 UpdatableInset const * inset) const
2162 int cell = tabular->GetCellFromInset(inset, actcell);
2165 lyxerr << "Own inset not found, shouldn't really happen!"
2170 int w = getMaxWidthOfCell(bv, cell);
2172 // because the inset then subtracts it's top_x and owner->x()
2173 w += (inset->x() - top_x);
2180 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2182 resizeLyXText(bv, recursive);
2186 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2189 for(int i = 0; i < tabular->rows(); ++i) {
2190 for(int j = 0; j < tabular->columns(); ++j) {
2191 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2199 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2200 bool const recursive) const
2202 if (the_locking_inset)
2203 return the_locking_inset->getLyXText(bv, recursive);
2205 // if we're locked lock the actual insettext and return it's LyXText!!!
2207 UpdatableInset * inset =
2208 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2209 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2210 return the_locking_inset->getLyXText(bv, recursive);
2213 return Inset::getLyXText(bv, recursive);
2217 bool InsetTabular::showInsetDialog(BufferView * bv) const
2219 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2220 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2221 InsetTabularMailer mailer(*tmp);
2222 mailer.showDialog(bv);
2228 void InsetTabular::openLayoutDialog(BufferView * bv) const
2230 if (the_locking_inset) {
2231 InsetTabular * i = static_cast<InsetTabular *>
2232 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2234 i->openLayoutDialog(bv);
2238 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2239 InsetTabularMailer mailer(*tmp);
2240 mailer.showDialog(bv);
2245 // function returns an object as defined in func_status.h:
2246 // states OK, Unknown, Disabled, On, Off.
2248 FuncStatus InsetTabular::getStatus(string const & what) const
2250 int action = LyXTabular::LAST_ACTION;
2254 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2255 string const tmp = tabularFeature[i].feature;
2256 if (tmp == what.substr(0, tmp.length())) {
2257 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2258 // tabularFeatures[i].feature.length())) {
2259 action = tabularFeature[i].action;
2263 if (action == LyXTabular::LAST_ACTION) {
2265 return status.unknown(true);
2268 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2273 LyXTabular::ltType dummyltt;
2276 if (hasSelection()) {
2277 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2279 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2283 case LyXTabular::SET_PWIDTH:
2284 case LyXTabular::SET_MPWIDTH:
2285 case LyXTabular::SET_SPECIAL_COLUMN:
2286 case LyXTabular::SET_SPECIAL_MULTI:
2287 return status.disabled(true);
2289 case LyXTabular::APPEND_ROW:
2290 case LyXTabular::APPEND_COLUMN:
2291 case LyXTabular::DELETE_ROW:
2292 case LyXTabular::DELETE_COLUMN:
2293 case LyXTabular::SET_ALL_LINES:
2294 case LyXTabular::UNSET_ALL_LINES:
2295 return status.clear();
2297 case LyXTabular::MULTICOLUMN:
2298 status.setOnOff(tabular->IsMultiColumn(actcell));
2300 case LyXTabular::M_TOGGLE_LINE_TOP:
2302 case LyXTabular::TOGGLE_LINE_TOP:
2303 status.setOnOff(tabular->TopLine(actcell, flag));
2305 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2307 case LyXTabular::TOGGLE_LINE_BOTTOM:
2308 status.setOnOff(tabular->BottomLine(actcell, flag));
2310 case LyXTabular::M_TOGGLE_LINE_LEFT:
2312 case LyXTabular::TOGGLE_LINE_LEFT:
2313 status.setOnOff(tabular->LeftLine(actcell, flag));
2315 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2317 case LyXTabular::TOGGLE_LINE_RIGHT:
2318 status.setOnOff(tabular->RightLine(actcell, flag));
2320 case LyXTabular::M_ALIGN_LEFT:
2322 case LyXTabular::ALIGN_LEFT:
2323 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2325 case LyXTabular::M_ALIGN_RIGHT:
2327 case LyXTabular::ALIGN_RIGHT:
2328 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2330 case LyXTabular::M_ALIGN_CENTER:
2332 case LyXTabular::ALIGN_CENTER:
2333 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2335 case LyXTabular::ALIGN_BLOCK:
2336 status.disabled(tabular->GetPWidth(actcell).zero());
2337 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2339 case LyXTabular::M_VALIGN_TOP:
2341 case LyXTabular::VALIGN_TOP:
2342 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2344 case LyXTabular::M_VALIGN_BOTTOM:
2346 case LyXTabular::VALIGN_BOTTOM:
2347 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2349 case LyXTabular::M_VALIGN_CENTER:
2351 case LyXTabular::VALIGN_CENTER:
2352 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2354 case LyXTabular::SET_LONGTABULAR:
2355 status.setOnOff(tabular->IsLongTabular());
2357 case LyXTabular::UNSET_LONGTABULAR:
2358 status.setOnOff(!tabular->IsLongTabular());
2360 case LyXTabular::SET_ROTATE_TABULAR:
2361 status.setOnOff(tabular->GetRotateTabular());
2363 case LyXTabular::UNSET_ROTATE_TABULAR:
2364 status.setOnOff(!tabular->GetRotateTabular());
2366 case LyXTabular::SET_ROTATE_CELL:
2367 status.setOnOff(tabular->GetRotateCell(actcell));
2369 case LyXTabular::UNSET_ROTATE_CELL:
2370 status.setOnOff(!tabular->GetRotateCell(actcell));
2372 case LyXTabular::SET_USEBOX:
2373 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2375 case LyXTabular::SET_LTFIRSTHEAD:
2376 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2378 case LyXTabular::SET_LTHEAD:
2379 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2381 case LyXTabular::SET_LTFOOT:
2382 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2384 case LyXTabular::SET_LTLASTFOOT:
2385 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2387 case LyXTabular::SET_LTNEWPAGE:
2388 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2392 status.disabled(true);
2399 vector<string> const InsetTabular::getLabelList() const
2401 return tabular->getLabelList();
2405 bool InsetTabular::copySelection(BufferView * bv)
2407 if (!hasSelection())
2410 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2411 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2412 if (sel_col_start > sel_col_end) {
2413 sel_col_start = sel_col_end;
2414 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2416 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2418 int const columns = sel_col_end - sel_col_start + 1;
2420 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2421 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2422 if (sel_row_start > sel_row_end) {
2423 swap(sel_row_start, sel_row_end);
2425 int const rows = sel_row_end - sel_row_start + 1;
2427 delete paste_tabular;
2428 paste_tabular = new LyXTabular(bv->buffer()->params,
2429 this, *tabular); // rows, columns);
2430 for (int i = 0; i < sel_row_start; ++i)
2431 paste_tabular->DeleteRow(0);
2432 while (paste_tabular->rows() > rows)
2433 paste_tabular->DeleteRow(rows);
2434 paste_tabular->SetTopLine(0, true, true);
2435 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2437 for (int i = 0; i < sel_col_start; ++i)
2438 paste_tabular->DeleteColumn(0);
2439 while (paste_tabular->columns() > columns)
2440 paste_tabular->DeleteColumn(columns);
2441 paste_tabular->SetLeftLine(0, true, true);
2442 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2446 paste_tabular->ascii(bv->buffer(), sstr,
2447 (int)parOwner()->params().depth(), true, '\t');
2448 bv->stuffClipboard(STRCONV(sstr.str()));
2453 bool InsetTabular::pasteSelection(BufferView * bv)
2458 for (int r1 = 0, r2 = actrow;
2459 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2461 for(int c1 = 0, c2 = actcol;
2462 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2464 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2465 tabular->IsPartOfMultiColumn(r2,c2))
2467 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2471 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2475 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2476 int const n2 = tabular->GetCellNumber(r2, c2);
2477 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2478 tabular->GetCellInset(n2)->setOwner(this);
2479 tabular->GetCellInset(n2)->deleteLyXText(bv);
2480 tabular->GetCellInset(n2)->markNew();
2487 bool InsetTabular::cutSelection(BufferParams const & bp)
2489 if (!hasSelection())
2492 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2493 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2494 if (sel_col_start > sel_col_end) {
2495 sel_col_start = sel_col_end;
2496 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2498 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2500 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2501 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2502 if (sel_row_start > sel_row_end) {
2503 swap(sel_row_start, sel_row_end);
2505 if (sel_cell_start > sel_cell_end) {
2506 swap(sel_cell_start, sel_cell_end);
2508 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2509 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2510 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2517 bool InsetTabular::isRightToLeft(BufferView * bv)
2519 return bv->getParentLanguage(this)->RightToLeft();
2523 bool InsetTabular::nodraw() const
2525 if (!UpdatableInset::nodraw() && the_locking_inset)
2526 return the_locking_inset->nodraw();
2527 return UpdatableInset::nodraw();
2531 int InsetTabular::scroll(bool recursive) const
2533 int sx = UpdatableInset::scroll(false);
2535 if (recursive && the_locking_inset)
2536 sx += the_locking_inset->scroll(recursive);
2542 void InsetTabular::getSelection(int & srow, int & erow,
2543 int & scol, int & ecol) const
2545 int const start = hasSelection() ? sel_cell_start : actcell;
2546 int const end = hasSelection() ? sel_cell_end : actcell;
2548 srow = tabular->row_of_cell(start);
2549 erow = tabular->row_of_cell(end);
2554 scol = tabular->column_of_cell(start);
2555 ecol = tabular->column_of_cell(end);
2559 ecol = tabular->right_column_of_cell(end);
2564 Paragraph * InsetTabular::firstParagraph() const
2566 if (the_locking_inset)
2567 return the_locking_inset->firstParagraph();
2572 Paragraph * InsetTabular::getFirstParagraph(int i) const
2574 return (i < tabular->GetNumberOfCells())
2575 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2580 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2582 if (the_locking_inset)
2583 return the_locking_inset->cursor(bv);
2584 return Inset::cursor(bv);
2588 Inset * InsetTabular::getInsetFromID(int id_arg) const
2591 return const_cast<InsetTabular *>(this);
2594 for(int i = 0; i < tabular->rows(); ++i) {
2595 for(int j = 0; j < tabular->columns(); ++j) {
2596 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2605 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2608 if (the_locking_inset) {
2609 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2610 if (!word.word().empty()) {
2614 if (tabular->IsLastCell(actcell)) {
2615 bv->unlockInset(const_cast<InsetTabular *>(this));
2617 return WordLangTuple();
2621 // otherwise we have to lock the next inset and ask for it's selecttion
2622 UpdatableInset * inset =
2623 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2624 inset->edit(bv, 0, 0, mouse_button::none);
2625 WordLangTuple word(selectNextWordInt(bv, value));
2627 if (!word.word().empty())
2633 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2635 // when entering this function the inset should be ALWAYS locked!
2636 lyx::Assert(the_locking_inset);
2638 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2639 if (!word.word().empty())
2642 if (tabular->IsLastCell(actcell)) {
2643 bv->unlockInset(const_cast<InsetTabular *>(this));
2644 return WordLangTuple();
2647 // otherwise we have to lock the next inset and ask for it's selecttion
2648 UpdatableInset * inset =
2649 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2651 return selectNextWordInt(bv, value);
2655 void InsetTabular::selectSelectedWord(BufferView * bv)
2657 if (the_locking_inset) {
2658 the_locking_inset->selectSelectedWord(bv);
2665 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2667 if (the_locking_inset) {
2668 the_locking_inset->toggleSelection(bv, kill_selection);
2673 void InsetTabular::markErased()
2677 while (!tabular->IsLastCell(cell)) {
2679 InsetText * inset = tabular->GetCellInset(cell);
2680 inset->markErased();
2685 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2687 if (the_locking_inset) {
2688 if (the_locking_inset->nextChange(bv, length)) {
2689 updateLocal(bv, CELL);
2692 if (tabular->IsLastCell(actcell))
2696 InsetText * inset = tabular->GetCellInset(actcell);
2697 if (inset->nextChange(bv, length)) {
2698 updateLocal(bv, FULL);
2701 while (!tabular->IsLastCell(actcell)) {
2703 inset = tabular->GetCellInset(actcell);
2704 if (inset->nextChange(bv, length)) {
2705 updateLocal(bv, FULL);
2713 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2716 if (the_locking_inset) {
2717 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2718 updateLocal(bv, CELL);
2721 if (tabular->IsLastCell(actcell))
2725 InsetText * inset = tabular->GetCellInset(actcell);
2726 if (inset->searchForward(bv, str, cs, mw)) {
2727 updateLocal(bv, FULL);
2730 while (!tabular->IsLastCell(actcell)) {
2732 inset = tabular->GetCellInset(actcell);
2733 if (inset->searchForward(bv, str, cs, mw)) {
2734 updateLocal(bv, FULL);
2742 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2745 if (the_locking_inset) {
2746 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2747 updateLocal(bv, CELL);
2752 actcell = tabular->GetNumberOfCells();
2756 InsetText * inset = tabular->GetCellInset(actcell);
2757 if (inset->searchBackward(bv, str, cs, mw)) {
2758 updateLocal(bv, CELL);
2766 bool InsetTabular::insetAllowed(Inset::Code code) const
2768 if (the_locking_inset)
2769 return the_locking_inset->insetAllowed(code);
2770 // we return true here because if the inset is not locked someone
2771 // wants to insert something in one of our insettexts and we generally
2777 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2779 const int cell = tabular->GetCellFromInset(in, actcell);
2782 return tabular->GetPWidth(cell).zero();
2784 // well we didn't obviously find it so maybe our owner knows more
2786 return owner()->forceDefaultParagraphs(in);
2787 // if we're here there is really something strange going on!!!
2791 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2794 if (buf.length() <= 0)
2800 string::size_type len = buf.length();
2801 string::size_type p = 0;
2804 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2813 maxCols = max(cols, maxCols);
2819 maxCols = max(cols, maxCols);
2820 LyXTabular * loctab;
2825 delete paste_tabular;
2826 paste_tabular = new LyXTabular(bv->buffer()->params,
2827 this, rows, maxCols);
2828 loctab = paste_tabular;
2831 loctab = tabular.get();
2837 string::size_type op = 0;
2838 int cells = loctab->GetNumberOfCells();
2841 rows = loctab->rows();
2842 int const columns = loctab->columns();
2844 while ((cell < cells) && (p < len) && (row < rows) &&
2845 (p = buf.find_first_of("\t\n", p)) != string::npos)
2851 // we can only set this if we are not too far right
2852 if (cols < columns) {
2853 InsetText * ti = loctab->GetCellInset(cell);
2854 LyXFont const font = ti->getLyXText(bv)->
2855 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2856 ti->setText(buf.substr(op, p - op), font);
2862 // we can only set this if we are not too far right
2863 if (cols < columns) {
2864 InsetText * ti = loctab->GetCellInset(cell);
2865 LyXFont const font = ti->getLyXText(bv)->
2866 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2867 ti->setText(buf.substr(op, p - op), font);
2872 cell = loctab->GetCellNumber(row, cols);
2878 // check for the last cell if there is no trailing '\n'
2879 if ((cell < cells) && (op < len)) {
2880 InsetText * ti = loctab->GetCellInset(cell);
2881 LyXFont const font = ti->getLyXText(bv)->
2882 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2883 ti->setText(buf.substr(op, len - op), font);
2890 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2892 int const rows = tabular->rows();
2893 int const columns = tabular->columns();
2894 for (int i = 0; i < rows; ++i) {
2895 for (int j = 0; j < columns; ++j) {
2896 tabular->GetCellInset(i,j)->addPreview(loader);
2902 string const InsetTabularMailer:: name_("tabular");
2904 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2909 string const InsetTabularMailer::inset2string() const
2911 return params2string(inset_);
2915 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2917 istringstream data(in);
2919 lex.setStream(data);
2923 string const token = lex.getString();
2931 string const token = lex.getString();
2932 if (token != "\\active_cell")
2935 cell = lex.getInteger();
2938 // This is part of the inset proper that is usually swallowed
2939 // by Buffer::readInset
2942 string const token = lex.getString();
2943 if (token != "Tabular")
2950 BufferView * const bv = inset.view();
2951 Buffer const * const buffer = bv ? bv->buffer() : 0;
2953 inset.read(buffer, lex);
2955 // We can't set the active cell, but we can tell the frontend
2962 InsetTabularMailer::params2string(InsetTabular const & inset)
2964 BufferView * const bv = inset.view();
2965 Buffer const * const buffer = bv ? bv->buffer() : 0;
2970 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2971 inset.write(buffer, data);
2972 data << "\\end_inset\n";