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"
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 LyXTabular * paste_tabular = 0;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_CENTER, "valign-center" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
126 bool operator()(TabularFeature & tf)
128 return tf.action == feature_;
131 LyXTabular::Feature feature_;
137 string const featureAsString(LyXTabular::Feature feature)
139 TabularFeature * it = tabularFeature;
140 TabularFeature * end = it +
141 sizeof(tabularFeature) / sizeof(TabularFeature);
142 it = std::find_if(it, end, FindFeature(feature));
143 return (it == end) ? string() : it->feature;
147 bool InsetTabular::hasPasteBuffer() const
149 return (paste_tabular != 0);
153 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
160 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
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), buffer_(tab.buffer_)
180 tabular.reset(new LyXTabular(buffer_->params,
181 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 Inset * InsetTabular::clone() const
205 return new InsetTabular(*this);
209 BufferView * InsetTabular::view() const
211 return buffer_->getUser();
215 void InsetTabular::buffer(Buffer * b)
221 void InsetTabular::write(Buffer const * buf, ostream & os) const
223 os << " Tabular" << endl;
224 tabular->Write(buf, os);
228 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
230 bool const old_format = (lex.getString() == "\\LyXTable");
232 tabular.reset(new LyXTabular(buf, this, lex));
240 string token = lex.getString();
241 while (lex.isOK() && (token != "\\end_inset")) {
243 token = lex.getString();
245 if (token != "\\end_inset") {
246 lex.printError("Missing \\end_inset at this point. "
252 void InsetTabular::metrics(MetricsInfo &,
253 Dimension & dim) const
255 dim.asc = tabular->GetAscentOfRow(0);
256 dim.des = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
257 dim.wid = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
261 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
268 BufferView * bv = pi.base.bv;
274 UpdatableInset::draw(pi, x, y);
282 x += ADD_TO_TABULAR_WIDTH;
286 first_visible_cell = -1;
287 for (i = 0; i < tabular->rows(); ++i) {
289 cell = tabular->GetCellNumber(i, 0);
290 if (!((y + tabular->GetDescentOfRow(i)) > 0) &&
291 (y - tabular->GetAscentOfRow(i)) < pi.pain.paperHeight())
293 y += tabular->GetDescentOfRow(i) +
294 tabular->GetAscentOfRow(i + 1) +
295 tabular->GetAdditionalHeight(i + 1);
298 for (j = 0; j < tabular->columns(); ++j) {
299 if (nx > bv->workWidth())
301 if (tabular->IsPartOfMultiColumn(i, j))
303 cx = nx + tabular->GetBeginningOfTextInCell(cell);
304 if (first_visible_cell < 0)
305 first_visible_cell = cell;
306 if (hasSelection()) {
307 drawCellSelection(pi.pain, nx, y, i, j, cell);
310 tabular->GetCellInset(cell)->draw(pi, cx, y);
311 drawCellLines(pi.pain, nx, y, i, cell);
312 nx += tabular->GetWidthOfColumn(cell);
316 // avoiding drawing the rest of a long table is
317 // a pretty big speedup
318 if (y > bv->workHeight())
321 y += tabular->GetDescentOfRow(i) +
322 tabular->GetAscentOfRow(i + 1) +
323 tabular->GetAdditionalHeight(i + 1);
330 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
331 int row, int cell) const
333 int x2 = x + tabular->GetWidthOfColumn(cell);
336 if (!tabular->topAlreadyDrawn(cell)) {
337 on_off = !tabular->TopLine(cell);
338 pain.line(x, y - tabular->GetAscentOfRow(row),
339 x2, y - tabular->GetAscentOfRow(row),
340 on_off ? LColor::tabularonoffline : LColor::tabularline,
341 on_off ? Painter::line_onoffdash : Painter::line_solid);
343 on_off = !tabular->BottomLine(cell);
344 pain.line(x, y + tabular->GetDescentOfRow(row),
345 x2, y + tabular->GetDescentOfRow(row),
346 on_off ? LColor::tabularonoffline : LColor::tabularline,
347 on_off ? Painter::line_onoffdash : Painter::line_solid);
348 if (!tabular->leftAlreadyDrawn(cell)) {
349 on_off = !tabular->LeftLine(cell);
350 pain.line(x, y - tabular->GetAscentOfRow(row),
351 x, y + tabular->GetDescentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
355 on_off = !tabular->RightLine(cell);
356 pain.line(x2 - tabular->GetAdditionalWidth(cell),
357 y - tabular->GetAscentOfRow(row),
358 x2 - tabular->GetAdditionalWidth(cell),
359 y + tabular->GetDescentOfRow(row),
360 on_off ? LColor::tabularonoffline : LColor::tabularline,
361 on_off ? Painter::line_onoffdash : Painter::line_solid);
365 void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
366 int row, int column, int cell) const
368 lyx::Assert(hasSelection());
369 int cs = tabular->column_of_cell(sel_cell_start);
370 int ce = tabular->column_of_cell(sel_cell_end);
373 cs = tabular->column_of_cell(sel_cell_end);
375 ce = tabular->right_column_of_cell(sel_cell_end);
378 int rs = tabular->row_of_cell(sel_cell_start);
379 int re = tabular->row_of_cell(sel_cell_end);
383 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
384 int w = tabular->GetWidthOfColumn(cell);
385 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
386 pain.fillRectangle(x, y - tabular->GetAscentOfRow(row) + 1,
387 w, h, LColor::selection);
392 void InsetTabular::update(BufferView * bv, bool reinit)
398 owner()->update(bv, true);
405 if (calculate_dimensions_of_cells(bv, true))
408 owner()->update(bv, true);
412 if (the_locking_inset)
413 the_locking_inset->update(bv, reinit);
414 if (need_update < FULL &&
415 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
420 switch (need_update) {
424 if (calculate_dimensions_of_cells(bv, false)) {
439 string const InsetTabular::editMessage() const
441 return _("Opened table");
445 void InsetTabular::insetUnlock(BufferView * bv)
447 if (the_locking_inset) {
448 the_locking_inset->insetUnlock(bv);
449 updateLocal(bv, CELL);
450 the_locking_inset = 0;
455 if (scroll(false) || hasSelection()) {
460 updateLocal(bv, FULL);
465 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
468 calculate_dimensions_of_cells(bv, true);
470 if (!locked && what == CELL)
472 if (need_update < what) // only set this if it has greater update
475 if (need_update != NONE) {
476 bv->updateInset(const_cast<InsetTabular *>(this));
483 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
485 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
490 if (inset == tabular->GetCellInset(actcell)) {
491 lyxerr[Debug::INSETTEXT] << "OK" << endl;
492 the_locking_inset = tabular->GetCellInset(actcell);
495 } else if (!the_locking_inset) {
496 int const n = tabular->GetNumberOfCells();
497 int const id = inset->id();
498 for (int i = 0; i < n; ++i) {
499 InsetText * in = tabular->GetCellInset(i);
502 the_locking_inset = in;
507 if (in->getInsetFromID(id)) {
509 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
510 return the_locking_inset->lockInsetInInset(bv, inset);
513 } else if (the_locking_inset && (the_locking_inset == inset)) {
514 lyxerr[Debug::INSETTEXT] << "OK" << endl;
516 } else if (the_locking_inset) {
517 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
518 return the_locking_inset->lockInsetInInset(bv, inset);
520 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
525 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
528 if (!the_locking_inset)
530 if (the_locking_inset == inset) {
531 the_locking_inset->insetUnlock(bv);
533 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
539 updateLocal(bv, CELL);
540 // this has to be here otherwise we don't redraw the cell!
541 the_locking_inset = 0;
544 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
545 if (inset->lyxCode() == TABULAR_CODE &&
546 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
547 InsetTabularMailer mailer(*this);
548 mailer.updateDialog(bv);
557 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
559 Inset * tl_inset = inset;
560 // look if this inset is really inside myself!
561 while(tl_inset->owner() && tl_inset->owner() != this)
562 tl_inset = tl_inset->owner();
563 // if we enter here it's not ower inset
564 if (!tl_inset->owner())
566 // we only have to do this if this is a subinset of our cells
567 if (tl_inset != inset) {
568 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
571 updateLocal(bv, CELL);
576 int InsetTabular::insetInInsetY() const
578 if (!the_locking_inset)
580 return inset_y + the_locking_inset->insetInInsetY();
584 UpdatableInset * InsetTabular::getLockingInset() const
586 return the_locking_inset ? the_locking_inset->getLockingInset() :
587 const_cast<InsetTabular *>(this);
591 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
595 if (the_locking_inset)
596 return the_locking_inset->getFirstLockingInsetOfType(c);
601 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
603 if (the_locking_inset)
604 return the_locking_inset->insertInset(bv, inset);
609 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
611 if (hasSelection() && cmd.button() == mouse_button::button3)
614 if (hasSelection()) {
616 updateLocal(cmd.view(), SELECTION);
619 int const ocell = actcell;
620 int const orow = actrow;
621 BufferView * bv = cmd.view();
625 the_locking_inset = 0;
629 setPos(bv, cmd.x, cmd.y);
631 updateLocal(bv, NONE);
634 if (cmd.button() == mouse_button::button3) {
635 if ((ocell != actcell) && the_locking_inset) {
636 the_locking_inset->insetUnlock(bv);
637 updateLocal(bv, CELL);
638 the_locking_inset = 0;
644 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
646 if ((ocell == actcell) && the_locking_inset && inset_hit) {
648 FuncRequest cmd1 = cmd;
651 the_locking_inset->localDispatch(cmd1);
655 if (the_locking_inset) {
656 the_locking_inset->insetUnlock(bv);
657 updateLocal(bv, CELL);
658 the_locking_inset = 0;
661 if (cmd.button() == mouse_button::button2) {
662 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
666 if (inset_hit && bv->theLockingInset()) {
667 if (!bv->lockInset(static_cast<UpdatableInset*>
668 (tabular->GetCellInset(actcell))))
670 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
673 FuncRequest cmd1 = cmd;
676 the_locking_inset->localDispatch(cmd1);
682 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
685 if (the_locking_inset) {
686 FuncRequest cmd1 = cmd;
689 ret = the_locking_inset->localDispatch(cmd1);
691 if (cmd.button() == mouse_button::button3 && !ret) {
692 InsetTabularMailer(*this).showDialog(cmd.view());
699 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
701 if (the_locking_inset) {
702 FuncRequest cmd1 = cmd;
705 the_locking_inset->localDispatch(cmd1);
709 BufferView * bv = cmd.view();
710 int const old_cell = actcell;
712 setPos(bv, cmd.x, cmd.y);
713 if (!hasSelection()) {
714 setSelection(actcell, actcell);
715 updateLocal(bv, SELECTION);
716 } else if (old_cell != actcell) {
717 setSelection(sel_cell_start, actcell);
718 updateLocal(bv, SELECTION);
723 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
725 // We need to save the value of the_locking_inset as the call to
726 // the_locking_inset->localDispatch might unlock it.
727 old_locking_inset = the_locking_inset;
728 RESULT result = UpdatableInset::localDispatch(cmd);
729 BufferView * bv = cmd.view();
731 if (cmd.action == LFUN_INSET_EDIT) {
733 if (!bv->lockInset(this)) {
734 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
740 the_locking_inset = 0;
744 if (cmd.argument.size()) {
745 if (cmd.argument == "left") {
746 if (isRightToLeft(bv))
747 actcell = tabular->GetLastCellInRow(0);
751 if (isRightToLeft(bv))
752 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
754 actcell = tabular->GetNumberOfCells() - 1;
762 setPos(bv, cmd.x, cmd.y);
765 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
766 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
772 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
777 if (cmd.action < 0 && cmd.argument.empty())
780 bool hs = hasSelection();
783 // this one have priority over the locked InsetText, if we're not already
784 // inside another tabular then that one get's priority!
785 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
786 switch (cmd.action) {
787 case LFUN_MOUSE_PRESS:
791 case LFUN_MOUSE_MOTION:
792 lfunMouseMotion(cmd);
795 case LFUN_MOUSE_RELEASE:
796 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
798 case LFUN_CELL_BACKWARD:
799 case LFUN_CELL_FORWARD:
800 unlockInsetInInset(bv, the_locking_inset);
801 if (cmd.action == LFUN_CELL_FORWARD)
802 moveNextCell(bv, old_locking_inset != 0);
804 movePrevCell(bv, old_locking_inset != 0);
807 updateLocal(bv, SELECTION);
808 if (!the_locking_inset) {
809 return DISPATCHED_NOUPDATE;
812 // this to avoid compiler warnings.
818 kb_action action = cmd.action;
819 string arg = cmd.argument;
820 if (the_locking_inset) {
821 result = the_locking_inset->localDispatch(cmd);
822 if (result == DISPATCHED_NOUPDATE) {
825 if (sc != scroll()) { // inset has been scrolled
826 updateLocal(bv, FULL);
829 } else if (result == DISPATCHED) {
830 updateLocal(bv, CELL);
832 } else if (result == FINISHED_UP) {
834 // Make sure to reset status message after
835 // exiting, e.g. math inset
836 bv->owner()->clearMessage();
837 } else if (result == FINISHED_DOWN) {
839 bv->owner()->clearMessage();
840 } else if (result == FINISHED_RIGHT) {
842 bv->owner()->clearMessage();
843 } else if (result == FINISHED) {
844 bv->owner()->clearMessage();
850 // --- Cursor Movements ----------------------------------
851 case LFUN_RIGHTSEL: {
852 int const start = hasSelection() ? sel_cell_start : actcell;
853 if (tabular->IsLastCellInRow(actcell)) {
854 setSelection(start, actcell);
859 // if we are starting a selection, only select
860 // the current cell at the beginning
861 if (hasSelection()) {
862 moveRight(bv, false);
865 setSelection(start, end);
866 updateLocal(bv, SELECTION);
870 result = moveRight(bv);
873 updateLocal(bv, SELECTION);
876 int const start = hasSelection() ? sel_cell_start : actcell;
877 if (tabular->IsFirstCellInRow(actcell)) {
878 setSelection(start, actcell);
883 // if we are starting a selection, only select
884 // the current cell at the beginning
885 if (hasSelection()) {
889 setSelection(start, end);
890 updateLocal(bv, SELECTION);
894 result = moveLeft(bv);
897 updateLocal(bv, SELECTION);
900 int const start = hasSelection() ? sel_cell_start : actcell;
901 int const ocell = actcell;
902 // if we are starting a selection, only select
903 // the current cell at the beginning
904 if (hasSelection()) {
906 if ((ocell == sel_cell_end) ||
907 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
908 setSelection(start, tabular->GetCellBelow(sel_cell_end));
910 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
912 setSelection(start, start);
914 updateLocal(bv, SELECTION);
918 result = moveDown(bv, old_locking_inset != 0);
921 updateLocal(bv, SELECTION);
925 int const start = hasSelection() ? sel_cell_start : actcell;
926 int const ocell = actcell;
927 // if we are starting a selection, only select
928 // the current cell at the beginning
929 if (hasSelection()) {
931 if ((ocell == sel_cell_end) ||
932 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
933 setSelection(start, tabular->GetCellAbove(sel_cell_end));
935 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
937 setSelection(start, start);
939 updateLocal(bv, SELECTION);
943 result = moveUp(bv, old_locking_inset != 0);
946 updateLocal(bv, SELECTION);
949 UpdateCodes code = CURSOR;
955 unlockInsetInInset(bv, the_locking_inset);
956 if (bv->text->top_y() + bv->painter().paperHeight() <
957 (top_baseline + tabular->GetHeightOfTabular()))
959 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
961 actcell = tabular->GetCellBelow(first_visible_cell) + column;
963 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
966 updateLocal(bv, code);
970 UpdateCodes code = CURSOR;
976 unlockInsetInInset(bv, the_locking_inset);
977 if (top_baseline < 0) {
978 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
980 if (top_baseline > 0)
983 actcell = tabular->GetCellBelow(first_visible_cell) + column;
988 updateLocal(bv, code);
991 // none of these make sense for insettabular,
992 // but we must catch them to prevent any
993 // selection from being confused
997 case LFUN_WORDLEFTSEL:
999 case LFUN_WORDRIGHTSEL:
1001 case LFUN_DOWN_PARAGRAPH:
1002 case LFUN_DOWN_PARAGRAPHSEL:
1003 case LFUN_UP_PARAGRAPH:
1004 case LFUN_UP_PARAGRAPHSEL:
1005 case LFUN_BACKSPACE:
1010 case LFUN_BEGINNINGBUF:
1011 case LFUN_BEGINNINGBUFSEL:
1013 case LFUN_ENDBUFSEL:
1015 case LFUN_LAYOUT_TABULAR: {
1016 InsetTabularMailer mailer(*this);
1017 mailer.showDialog(bv);
1020 case LFUN_INSET_DIALOG_UPDATE: {
1021 InsetTabularMailer mailer(*this);
1022 mailer.updateDialog(bv);
1025 case LFUN_TABULAR_FEATURE:
1026 if (!tabularFeatures(bv, arg))
1027 result = UNDISPATCHED;
1029 // insert file functions
1030 case LFUN_FILE_INSERT_ASCII_PARA:
1031 case LFUN_FILE_INSERT_ASCII:
1033 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1036 if (insertAsciiString(bv, tmpstr, false))
1037 updateLocal(bv, INIT);
1039 result = UNDISPATCHED;
1042 // cut and paste functions
1044 if (!copySelection(bv))
1048 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1049 cutSelection(bv->buffer()->params);
1050 updateLocal(bv, INIT);
1053 if (!hasSelection())
1058 case LFUN_PASTESELECTION:
1060 string const clip(bv->getClipboard());
1064 if (clip.find('\t') != string::npos) {
1068 string::size_type len = clip.length();
1069 string::size_type p = 0;
1072 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1080 maxCols = max(cols, maxCols);
1086 maxCols = max(cols, maxCols);
1087 delete paste_tabular;
1088 paste_tabular = new LyXTabular(bv->buffer()->params,
1089 this, rows, maxCols);
1090 string::size_type op = 0;
1092 int cells = paste_tabular->GetNumberOfCells();
1094 while ((cell < cells) && (p < len) &&
1095 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1100 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1105 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1106 while (cols++ < maxCols)
1114 // check for the last cell if there is no trailing '\n'
1115 if ((cell < cells) && (op < len))
1116 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1119 if (!insertAsciiString(bv, clip, true))
1122 // so that the clipboard is used and it goes on
1124 // and executes LFUN_PASTESELECTION in insettext!
1125 delete paste_tabular;
1130 if (hasPasteBuffer()) {
1131 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1133 updateLocal(bv, INIT);
1136 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1138 // handle font changing stuff on selection before we lock the inset
1139 // in the default part!
1140 result = UNDISPATCHED;
1151 case LFUN_UNDERLINE:
1152 case LFUN_FONT_SIZE:
1153 if (bv->dispatch(FuncRequest(bv, action, arg)))
1154 result = DISPATCHED;
1160 // we try to activate the actual inset and put this event down to
1161 // the insets dispatch function.
1162 if ((result == DISPATCHED) || the_locking_inset)
1165 if (activateCellInset(bv)) {
1166 // reset need_update setted in above function!
1168 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1169 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1170 unlockInsetInInset(bv, the_locking_inset);
1172 // we need to update if this was requested before
1173 updateLocal(bv, NONE);
1174 return UNDISPATCHED;
1177 // so the below CELL is not set because this is higher
1178 // priority and we get a full redraw
1179 need_update = SELECTION;
1182 updateLocal(bv, CELL);
1187 if (result < FINISHED) {
1188 if (!the_locking_inset) {
1189 if (bv->fitCursor())
1190 updateLocal(bv, FULL);
1193 bv->unlockInset(this);
1198 int InsetTabular::latex(Buffer const * buf, ostream & os,
1199 LatexRunParams const & runparams) const
1201 return tabular->latex(buf, os, runparams);
1205 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1208 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1210 return tabular->ascii(buf, os, 0, false,0);
1214 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1217 int const ret = tabular->ascii(buf,os,
1218 (int)parOwner()->params().depth(),
1225 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1230 // if the table is inside a float it doesn't need the informaltable
1231 // wrapper. Search for it.
1232 for(master = owner();
1233 master && master->lyxCode() != Inset::FLOAT_CODE;
1234 master = master->owner());
1237 os << "<informaltable>";
1242 ret+= tabular->docbook(buf, os, mixcont);
1244 os << "</informaltable>";
1253 void InsetTabular::validate(LaTeXFeatures & features) const
1255 tabular->Validate(features);
1259 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1265 bool changed = false;
1267 // FIXME: since InsetText ignores this anyway, it doesn't
1268 // matter what we pass it. Ugly
1271 // if we have a locking_inset we should have to check only this cell for
1272 // change so I'll try this to have a boost, but who knows ;)
1273 if ((need_update != INIT) &&
1274 (the_locking_inset == tabular->GetCellInset(actcell))) {
1275 for(int i = 0; i < tabular->columns(); ++i) {
1276 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1278 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1281 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1282 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1283 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1286 for (int i = 0; i < tabular->rows(); ++i) {
1289 for (int j = 0; j < tabular->columns(); ++j) {
1290 if (tabular->IsPartOfMultiColumn(i,j))
1293 inset = tabular->GetCellInset(cell);
1294 if (!reinit && !tabular->GetPWidth(cell).zero())
1295 inset->update(bv, false);
1296 maxAsc = max(maxAsc, inset->ascent(bv, font));
1297 maxDesc = max(maxDesc, inset->descent(bv, font));
1298 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1300 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1301 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1309 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1311 if (the_locking_inset) {
1312 the_locking_inset->getCursor(bv, x, y);
1317 y = cursor_.y() + InsetTabular::y();
1320 int desc = tabular->GetDescentOfRow(actrow);
1322 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1324 y += ADD_TO_HEIGHT * 2;
1325 y += TEXT_TO_INSET_OFFSET;
1329 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1331 if (the_locking_inset) {
1332 the_locking_inset->getCursorPos(bv, x, y);
1335 x = cursor_.x() - top_x;
1340 void InsetTabular::fitInsetCursor(BufferView * bv) const
1342 if (the_locking_inset) {
1343 int old_top_y = bv->text->top_y();
1344 the_locking_inset->fitInsetCursor(bv);
1345 if (old_top_y != bv->text->top_y())
1351 int const asc = font_metrics::maxAscent(font);
1352 int const desc = font_metrics::maxDescent(font);
1355 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1360 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1364 actcell = actrow = actcol = 0;
1365 int ly = tabular->GetDescentOfRow(actrow);
1367 // first search the right row
1368 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1369 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1370 tabular->GetAscentOfRow(actrow + 1) +
1371 tabular->GetAdditionalHeight(actrow + 1));
1373 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1375 actcell = tabular->GetCellNumber(actrow, actcol);
1377 // now search the right column
1378 int lx = tabular->GetWidthOfColumn(actcell) -
1379 tabular->GetAdditionalWidth(actcell);
1380 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1381 lx += tabular->GetWidthOfColumn(actcell + 1)
1382 + tabular->GetAdditionalWidth(actcell);
1384 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1389 int InsetTabular::getCellXPos(int cell) const
1393 for (; !tabular->IsFirstCellInRow(c); --c)
1395 int lx = tabular->GetWidthOfColumn(cell);
1396 for (; c < cell; ++c) {
1397 lx += tabular->GetWidthOfColumn(c);
1399 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1403 void InsetTabular::resetPos(BufferView * bv) const
1405 #ifdef WITH_WARNINGS
1406 #warning This should be fixed in the right manner (20011128 Jug)
1408 // fast hack to fix infinite repaintings!
1409 if (in_reset_pos > 0)
1413 actcol = tabular->column_of_cell(actcell);
1416 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1417 if (tabular->IsLastCellInRow(cell)) {
1418 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1419 tabular->GetAscentOfRow(actrow + 1) +
1420 tabular->GetAdditionalHeight(actrow + 1));
1424 if (!locked || nodraw()) {
1425 if (the_locking_inset)
1426 inset_y = cursor_.y();
1429 // we need this only from here on!!!
1431 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1432 int new_x = getCellXPos(actcell);
1433 int old_x = cursor_.x();
1436 // cursor.x(getCellXPos(actcell) + offset);
1437 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1438 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1441 updateLocal(bv, FULL);
1442 } else if (the_locking_inset &&
1443 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1445 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1446 if (xx > (bv->workWidth()-20)) {
1447 scroll(bv, -(xx - bv->workWidth() + 60));
1448 updateLocal(bv, FULL);
1449 } else if (xx < 20) {
1455 updateLocal(bv, FULL);
1457 } else if ((cursor_.x() - offset) > 20 &&
1458 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1459 > (bv->workWidth() - 20)) {
1460 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1461 updateLocal(bv, FULL);
1462 } else if ((cursor_.x() - offset) < 20) {
1463 scroll(bv, 20 - cursor_.x() + offset);
1464 updateLocal(bv, FULL);
1465 } else if (scroll() && top_x > 20 &&
1466 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1467 scroll(bv, old_x - cursor_.x());
1468 updateLocal(bv, FULL);
1470 if (the_locking_inset) {
1471 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1472 inset_y = cursor_.y();
1474 if ((!the_locking_inset ||
1475 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1476 actcell != oldcell) {
1477 InsetTabular * inset = const_cast<InsetTabular *>(this);
1478 InsetTabularMailer mailer(*inset);
1479 mailer.updateDialog(bv);
1486 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1488 if (lock && !old_locking_inset) {
1489 if (activateCellInset(bv))
1492 bool moved = isRightToLeft(bv)
1493 ? movePrevCell(bv) : moveNextCell(bv);
1495 return FINISHED_RIGHT;
1496 if (lock && activateCellInset(bv))
1500 return DISPATCHED_NOUPDATE;
1504 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1506 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1509 if (lock) { // behind the inset
1510 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1514 return DISPATCHED_NOUPDATE;
1518 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1520 int const ocell = actcell;
1521 actcell = tabular->GetCellAbove(actcell);
1522 if (actcell == ocell) // we moved out of the inset
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 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1541 int const ocell = actcell;
1542 actcell = tabular->GetCellBelow(actcell);
1543 if (actcell == ocell) // we moved out of the inset
1544 return FINISHED_DOWN;
1549 if (old_locking_inset) {
1550 old_locking_inset->getCursorPos(bv, x, y);
1551 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1553 if (activateCellInset(bv, x, 0))
1556 return DISPATCHED_NOUPDATE;
1560 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1562 if (isRightToLeft(bv)) {
1563 if (tabular->IsFirstCellInRow(actcell)) {
1564 int row = tabular->row_of_cell(actcell);
1565 if (row == tabular->rows() - 1)
1567 actcell = tabular->GetLastCellInRow(row);
1568 actcell = tabular->GetCellBelow(actcell);
1575 if (tabular->IsLastCell(actcell))
1580 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1581 isRightToLeftPar(bv->buffer()->params);
1582 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1589 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1591 if (isRightToLeft(bv)) {
1592 if (tabular->IsLastCellInRow(actcell)) {
1593 int row = tabular->row_of_cell(actcell);
1596 actcell = tabular->GetFirstCellInRow(row);
1597 actcell = tabular->GetCellAbove(actcell);
1599 if (tabular->IsLastCell(actcell))
1604 if (!actcell) // first cell
1609 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1610 isRightToLeftPar(bv->buffer()->params);
1611 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1618 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1622 setSelection(0, tabular->GetNumberOfCells() - 1);
1624 if (hasSelection()) {
1625 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1626 bool const frozen = undo_frozen;
1629 // apply the fontchange on the whole selection
1634 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1635 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1636 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1637 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1644 updateLocal(bv, INIT);
1646 if (the_locking_inset)
1647 the_locking_inset->setFont(bv, font, tall);
1651 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1653 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1656 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1657 string const tmp = tabularFeature[i].feature;
1659 if (tmp == what.substr(0, tmp.length())) {
1660 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1661 //tabularFeatures[i].feature.length())) {
1662 action = tabularFeature[i].action;
1666 if (action == LyXTabular::LAST_ACTION)
1670 ltrim(what.substr(tabularFeature[i].feature.length()));
1671 tabularFeatures(bv, action, val);
1677 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1678 string const & special, bool & flag)
1680 if (special == "dl_above") {
1683 } else if (special == "dl_below") {
1684 ltt.bottomDL = flag;
1686 } else if (special == "empty") {
1698 void InsetTabular::tabularFeatures(BufferView * bv,
1699 LyXTabular::Feature feature,
1700 string const & value)
1706 bool setLines = false;
1707 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1708 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1711 case LyXTabular::M_ALIGN_LEFT:
1712 case LyXTabular::ALIGN_LEFT:
1713 setAlign = LYX_ALIGN_LEFT;
1715 case LyXTabular::M_ALIGN_RIGHT:
1716 case LyXTabular::ALIGN_RIGHT:
1717 setAlign = LYX_ALIGN_RIGHT;
1719 case LyXTabular::M_ALIGN_CENTER:
1720 case LyXTabular::ALIGN_CENTER:
1721 setAlign = LYX_ALIGN_CENTER;
1723 case LyXTabular::ALIGN_BLOCK:
1724 setAlign = LYX_ALIGN_BLOCK;
1726 case LyXTabular::M_VALIGN_TOP:
1727 case LyXTabular::VALIGN_TOP:
1728 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1730 case LyXTabular::M_VALIGN_BOTTOM:
1731 case LyXTabular::VALIGN_BOTTOM:
1732 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1734 case LyXTabular::M_VALIGN_CENTER:
1735 case LyXTabular::VALIGN_CENTER:
1736 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1741 if (hasSelection()) {
1742 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1744 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1745 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1747 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1749 int row = tabular->row_of_cell(actcell);
1750 int column = tabular->column_of_cell(actcell);
1752 LyXTabular::ltType ltt;
1755 case LyXTabular::SET_PWIDTH:
1757 LyXLength const vallen(value);
1758 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1760 bool const update = (tmplen != vallen);
1761 tabular->SetColumnPWidth(actcell, vallen);
1763 // We need this otherwise we won't resize
1764 // the insettext of the active cell (if any)
1765 // until later (see InsetText::do_resize)
1766 unlockInsetInInset(bv, the_locking_inset);
1769 for (int i = 0; i < tabular->rows(); ++i) {
1770 cell = tabular->GetCellNumber(i,column);
1771 tabular->GetCellInset(cell)->resizeLyXText(bv);
1773 updateLocal(bv, INIT);
1777 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1778 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1779 else if (!vallen.zero()
1780 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1781 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1784 case LyXTabular::SET_MPWIDTH:
1786 LyXLength const vallen(value);
1787 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1789 bool const update = (tmplen != vallen);
1790 tabular->SetMColumnPWidth(actcell, vallen);
1792 // We need this otherwise we won't resize
1793 // the insettext of the active cell (if any)
1794 // until later (see InsetText::do_resize)
1795 unlockInsetInInset(bv, the_locking_inset);
1797 for (int i = 0; i < tabular->rows(); ++i) {
1798 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1801 updateLocal(bv, INIT);
1805 case LyXTabular::SET_SPECIAL_COLUMN:
1806 case LyXTabular::SET_SPECIAL_MULTI:
1807 tabular->SetAlignSpecial(actcell,value,feature);
1808 updateLocal(bv, FULL);
1810 case LyXTabular::APPEND_ROW:
1811 // append the row into the tabular
1812 unlockInsetInInset(bv, the_locking_inset);
1813 tabular->AppendRow(bv->buffer()->params, actcell);
1814 updateLocal(bv, INIT);
1816 case LyXTabular::APPEND_COLUMN:
1817 // append the column into the tabular
1818 unlockInsetInInset(bv, the_locking_inset);
1819 tabular->AppendColumn(bv->buffer()->params, actcell);
1820 actcell = tabular->GetCellNumber(row, column);
1821 updateLocal(bv, INIT);
1823 case LyXTabular::DELETE_ROW:
1824 unlockInsetInInset(bv, the_locking_inset);
1825 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1826 tabular->DeleteRow(sel_row_start);
1828 if (sel_row_start >= tabular->rows())
1830 actcell = tabular->GetCellNumber(sel_row_start, column);
1832 updateLocal(bv, INIT);
1834 case LyXTabular::DELETE_COLUMN:
1835 unlockInsetInInset(bv, the_locking_inset);
1836 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1837 tabular->DeleteColumn(sel_col_start);
1839 if (sel_col_start >= tabular->columns())
1841 actcell = tabular->GetCellNumber(row, sel_col_start);
1843 updateLocal(bv, INIT);
1845 case LyXTabular::M_TOGGLE_LINE_TOP:
1847 case LyXTabular::TOGGLE_LINE_TOP:
1849 bool lineSet = !tabular->TopLine(actcell, flag);
1850 for (int i = sel_row_start; i <= sel_row_end; ++i)
1851 for (int j = sel_col_start; j <= sel_col_end; ++j)
1852 tabular->SetTopLine(
1853 tabular->GetCellNumber(i, j),
1855 updateLocal(bv, INIT);
1859 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1861 case LyXTabular::TOGGLE_LINE_BOTTOM:
1863 bool lineSet = !tabular->BottomLine(actcell, flag);
1864 for (int i = sel_row_start; i <= sel_row_end; ++i)
1865 for (int j = sel_col_start; j <= sel_col_end; ++j)
1866 tabular->SetBottomLine(
1867 tabular->GetCellNumber(i, j),
1870 updateLocal(bv, INIT);
1874 case LyXTabular::M_TOGGLE_LINE_LEFT:
1876 case LyXTabular::TOGGLE_LINE_LEFT:
1878 bool lineSet = !tabular->LeftLine(actcell, flag);
1879 for (int i = sel_row_start; i <= sel_row_end; ++i)
1880 for (int j = sel_col_start; j <= sel_col_end; ++j)
1881 tabular->SetLeftLine(
1882 tabular->GetCellNumber(i,j),
1885 updateLocal(bv, INIT);
1889 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1891 case LyXTabular::TOGGLE_LINE_RIGHT:
1893 bool lineSet = !tabular->RightLine(actcell, flag);
1894 for (int i = sel_row_start; i <= sel_row_end; ++i)
1895 for (int j = sel_col_start; j <= sel_col_end; ++j)
1896 tabular->SetRightLine(
1897 tabular->GetCellNumber(i,j),
1900 updateLocal(bv, INIT);
1904 case LyXTabular::M_ALIGN_LEFT:
1905 case LyXTabular::M_ALIGN_RIGHT:
1906 case LyXTabular::M_ALIGN_CENTER:
1908 case LyXTabular::ALIGN_LEFT:
1909 case LyXTabular::ALIGN_RIGHT:
1910 case LyXTabular::ALIGN_CENTER:
1911 case LyXTabular::ALIGN_BLOCK:
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->SetAlignment(
1915 tabular->GetCellNumber(i, j),
1918 updateLocal(bv, INIT);
1920 case LyXTabular::M_VALIGN_TOP:
1921 case LyXTabular::M_VALIGN_BOTTOM:
1922 case LyXTabular::M_VALIGN_CENTER:
1924 case LyXTabular::VALIGN_TOP:
1925 case LyXTabular::VALIGN_BOTTOM:
1926 case LyXTabular::VALIGN_CENTER:
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->SetVAlignment(
1930 tabular->GetCellNumber(i, j),
1932 updateLocal(bv, INIT);
1934 case LyXTabular::MULTICOLUMN:
1936 if (sel_row_start != sel_row_end) {
1937 #ifdef WITH_WARNINGS
1938 #warning Need I say it ? This is horrible.
1940 Alert::error(_("Error setting multicolumn"),
1941 _("You cannot set multicolumn vertically."));
1944 // just multicol for one Single Cell
1945 if (!hasSelection()) {
1946 // check wether we are completly in a multicol
1947 if (tabular->IsMultiColumn(actcell)) {
1948 tabular->UnsetMultiColumn(actcell);
1949 updateLocal(bv, INIT);
1951 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1952 updateLocal(bv, CELL);
1956 // we have a selection so this means we just add all this
1957 // cells to form a multicolumn cell
1961 if (sel_cell_start > sel_cell_end) {
1962 s_start = sel_cell_end;
1963 s_end = sel_cell_start;
1965 s_start = sel_cell_start;
1966 s_end = sel_cell_end;
1968 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1971 updateLocal(bv, INIT);
1974 case LyXTabular::SET_ALL_LINES:
1976 case LyXTabular::UNSET_ALL_LINES:
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->SetAllLines(
1980 tabular->GetCellNumber(i,j), setLines);
1981 updateLocal(bv, INIT);
1983 case LyXTabular::SET_LONGTABULAR:
1984 tabular->SetLongTabular(true);
1985 updateLocal(bv, INIT); // because this toggles displayed
1987 case LyXTabular::UNSET_LONGTABULAR:
1988 tabular->SetLongTabular(false);
1989 updateLocal(bv, INIT); // because this toggles displayed
1991 case LyXTabular::SET_ROTATE_TABULAR:
1992 tabular->SetRotateTabular(true);
1994 case LyXTabular::UNSET_ROTATE_TABULAR:
1995 tabular->SetRotateTabular(false);
1997 case LyXTabular::SET_ROTATE_CELL:
1998 for (int i = sel_row_start; i <= sel_row_end; ++i)
1999 for (int j = sel_col_start; j<=sel_col_end; ++j)
2000 tabular->SetRotateCell(
2001 tabular->GetCellNumber(i, j),
2004 case LyXTabular::UNSET_ROTATE_CELL:
2005 for (int i = sel_row_start; i <= sel_row_end; ++i)
2006 for (int j = sel_col_start; j <= sel_col_end; ++j)
2007 tabular->SetRotateCell(
2008 tabular->GetCellNumber(i, j), false);
2010 case LyXTabular::SET_USEBOX:
2012 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2013 if (val == tabular->GetUsebox(actcell))
2014 val = LyXTabular::BOX_NONE;
2015 for (int i = sel_row_start; i <= sel_row_end; ++i)
2016 for (int j = sel_col_start; j <= sel_col_end; ++j)
2018 tabular->GetCellNumber(i, j), val);
2021 case LyXTabular::UNSET_LTFIRSTHEAD:
2023 case LyXTabular::SET_LTFIRSTHEAD:
2024 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2025 checkLongtableSpecial(ltt, value, flag);
2026 tabular->SetLTHead(row, flag, ltt, true);
2028 case LyXTabular::UNSET_LTHEAD:
2030 case LyXTabular::SET_LTHEAD:
2031 (void)tabular->GetRowOfLTHead(row, ltt);
2032 checkLongtableSpecial(ltt, value, flag);
2033 tabular->SetLTHead(row, flag, ltt, false);
2035 case LyXTabular::UNSET_LTFOOT:
2037 case LyXTabular::SET_LTFOOT:
2038 (void)tabular->GetRowOfLTFoot(row, ltt);
2039 checkLongtableSpecial(ltt, value, flag);
2040 tabular->SetLTFoot(row, flag, ltt, false);
2042 case LyXTabular::UNSET_LTLASTFOOT:
2044 case LyXTabular::SET_LTLASTFOOT:
2045 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2046 checkLongtableSpecial(ltt, value, flag);
2047 tabular->SetLTFoot(row, flag, ltt, true);
2049 case LyXTabular::SET_LTNEWPAGE:
2051 bool what = !tabular->GetLTNewPage(row);
2052 tabular->SetLTNewPage(row, what);
2055 // dummy stuff just to avoid warnings
2056 case LyXTabular::LAST_ACTION:
2060 InsetTabularMailer mailer(*this);
2061 mailer.updateDialog(bv);
2065 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2068 UpdatableInset * inset =
2069 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2070 LyXFont font(LyXFont::ALL_SANE);
2072 x = inset->x() + inset->width(bv, font);
2073 y = inset->descent(bv, font);
2075 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2076 //inset_y = cursor.y();
2077 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2078 if (!the_locking_inset)
2080 updateLocal(bv, CELL);
2081 return (the_locking_inset != 0);
2085 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2086 mouse_button::state button)
2088 inset_x = cursor_.x()
2089 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2090 inset_y = cursor_.y();
2091 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2095 bool InsetTabular::insetHit(BufferView *, int x, int) const
2098 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2102 // This returns paperWidth() if the cell-width is unlimited or the width
2103 // in pixels if we have a pwidth for this cell.
2104 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2106 LyXLength const len = tabular->GetPWidth(cell);
2110 return len.inPixels(latexTextWidth(bv));
2114 int InsetTabular::getMaxWidth(BufferView * bv,
2115 UpdatableInset const * inset) const
2117 int cell = tabular->GetCellFromInset(inset, actcell);
2120 lyxerr << "Own inset not found, shouldn't really happen!"
2125 int w = getMaxWidthOfCell(bv, cell);
2127 // because the inset then subtracts it's top_x and owner->x()
2128 w += (inset->x() - top_x);
2135 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2137 resizeLyXText(bv, recursive);
2141 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2144 for(int i = 0; i < tabular->rows(); ++i) {
2145 for(int j = 0; j < tabular->columns(); ++j) {
2146 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2154 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2155 bool const recursive) const
2157 if (the_locking_inset)
2158 return the_locking_inset->getLyXText(bv, recursive);
2160 // if we're locked lock the actual insettext and return it's LyXText!!!
2162 UpdatableInset * inset =
2163 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2164 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2165 return the_locking_inset->getLyXText(bv, recursive);
2168 return Inset::getLyXText(bv, recursive);
2172 bool InsetTabular::showInsetDialog(BufferView * bv) const
2174 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2175 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2176 InsetTabularMailer mailer(*tmp);
2177 mailer.showDialog(bv);
2183 void InsetTabular::openLayoutDialog(BufferView * bv) const
2185 if (the_locking_inset) {
2186 InsetTabular * i = static_cast<InsetTabular *>
2187 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2189 i->openLayoutDialog(bv);
2193 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2194 InsetTabularMailer mailer(*tmp);
2195 mailer.showDialog(bv);
2200 // function returns an object as defined in func_status.h:
2201 // states OK, Unknown, Disabled, On, Off.
2203 FuncStatus InsetTabular::getStatus(string const & what) const
2205 int action = LyXTabular::LAST_ACTION;
2209 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2210 string const tmp = tabularFeature[i].feature;
2211 if (tmp == what.substr(0, tmp.length())) {
2212 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2213 // tabularFeatures[i].feature.length())) {
2214 action = tabularFeature[i].action;
2218 if (action == LyXTabular::LAST_ACTION) {
2220 return status.unknown(true);
2223 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2228 LyXTabular::ltType dummyltt;
2231 if (hasSelection()) {
2232 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2234 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2238 case LyXTabular::SET_PWIDTH:
2239 case LyXTabular::SET_MPWIDTH:
2240 case LyXTabular::SET_SPECIAL_COLUMN:
2241 case LyXTabular::SET_SPECIAL_MULTI:
2242 case LyXTabular::APPEND_ROW:
2243 case LyXTabular::APPEND_COLUMN:
2244 case LyXTabular::DELETE_ROW:
2245 case LyXTabular::DELETE_COLUMN:
2246 case LyXTabular::SET_ALL_LINES:
2247 case LyXTabular::UNSET_ALL_LINES:
2248 return status.clear();
2250 case LyXTabular::MULTICOLUMN:
2251 status.setOnOff(tabular->IsMultiColumn(actcell));
2253 case LyXTabular::M_TOGGLE_LINE_TOP:
2255 case LyXTabular::TOGGLE_LINE_TOP:
2256 status.setOnOff(tabular->TopLine(actcell, flag));
2258 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2260 case LyXTabular::TOGGLE_LINE_BOTTOM:
2261 status.setOnOff(tabular->BottomLine(actcell, flag));
2263 case LyXTabular::M_TOGGLE_LINE_LEFT:
2265 case LyXTabular::TOGGLE_LINE_LEFT:
2266 status.setOnOff(tabular->LeftLine(actcell, flag));
2268 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2270 case LyXTabular::TOGGLE_LINE_RIGHT:
2271 status.setOnOff(tabular->RightLine(actcell, flag));
2273 case LyXTabular::M_ALIGN_LEFT:
2275 case LyXTabular::ALIGN_LEFT:
2276 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2278 case LyXTabular::M_ALIGN_RIGHT:
2280 case LyXTabular::ALIGN_RIGHT:
2281 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2283 case LyXTabular::M_ALIGN_CENTER:
2285 case LyXTabular::ALIGN_CENTER:
2286 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2288 case LyXTabular::ALIGN_BLOCK:
2289 status.disabled(tabular->GetPWidth(actcell).zero());
2290 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2292 case LyXTabular::M_VALIGN_TOP:
2294 case LyXTabular::VALIGN_TOP:
2295 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2297 case LyXTabular::M_VALIGN_BOTTOM:
2299 case LyXTabular::VALIGN_BOTTOM:
2300 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2302 case LyXTabular::M_VALIGN_CENTER:
2304 case LyXTabular::VALIGN_CENTER:
2305 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2307 case LyXTabular::SET_LONGTABULAR:
2308 status.setOnOff(tabular->IsLongTabular());
2310 case LyXTabular::UNSET_LONGTABULAR:
2311 status.setOnOff(!tabular->IsLongTabular());
2313 case LyXTabular::SET_ROTATE_TABULAR:
2314 status.setOnOff(tabular->GetRotateTabular());
2316 case LyXTabular::UNSET_ROTATE_TABULAR:
2317 status.setOnOff(!tabular->GetRotateTabular());
2319 case LyXTabular::SET_ROTATE_CELL:
2320 status.setOnOff(tabular->GetRotateCell(actcell));
2322 case LyXTabular::UNSET_ROTATE_CELL:
2323 status.setOnOff(!tabular->GetRotateCell(actcell));
2325 case LyXTabular::SET_USEBOX:
2326 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2328 case LyXTabular::SET_LTFIRSTHEAD:
2329 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2331 case LyXTabular::SET_LTHEAD:
2332 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2334 case LyXTabular::SET_LTFOOT:
2335 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2337 case LyXTabular::SET_LTLASTFOOT:
2338 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2340 case LyXTabular::SET_LTNEWPAGE:
2341 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2345 status.disabled(true);
2352 vector<string> const InsetTabular::getLabelList() const
2354 return tabular->getLabelList();
2358 bool InsetTabular::copySelection(BufferView * bv)
2360 if (!hasSelection())
2363 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2364 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2365 if (sel_col_start > sel_col_end) {
2366 sel_col_start = sel_col_end;
2367 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2369 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2371 int const columns = sel_col_end - sel_col_start + 1;
2373 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2374 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2375 if (sel_row_start > sel_row_end) {
2376 swap(sel_row_start, sel_row_end);
2378 int const rows = sel_row_end - sel_row_start + 1;
2380 delete paste_tabular;
2381 paste_tabular = new LyXTabular(bv->buffer()->params,
2382 this, *tabular); // rows, columns);
2383 for (int i = 0; i < sel_row_start; ++i)
2384 paste_tabular->DeleteRow(0);
2385 while (paste_tabular->rows() > rows)
2386 paste_tabular->DeleteRow(rows);
2387 paste_tabular->SetTopLine(0, true, true);
2388 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2390 for (int i = 0; i < sel_col_start; ++i)
2391 paste_tabular->DeleteColumn(0);
2392 while (paste_tabular->columns() > columns)
2393 paste_tabular->DeleteColumn(columns);
2394 paste_tabular->SetLeftLine(0, true, true);
2395 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2399 paste_tabular->ascii(bv->buffer(), sstr,
2400 (int)parOwner()->params().depth(), true, '\t');
2401 bv->stuffClipboard(STRCONV(sstr.str()));
2406 bool InsetTabular::pasteSelection(BufferView * bv)
2411 for (int r1 = 0, r2 = actrow;
2412 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2414 for(int c1 = 0, c2 = actcol;
2415 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2417 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2418 tabular->IsPartOfMultiColumn(r2,c2))
2420 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2424 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2428 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2429 int const n2 = tabular->GetCellNumber(r2, c2);
2430 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2431 tabular->GetCellInset(n2)->setOwner(this);
2432 tabular->GetCellInset(n2)->deleteLyXText(bv);
2433 tabular->GetCellInset(n2)->markNew();
2440 bool InsetTabular::cutSelection(BufferParams const & bp)
2442 if (!hasSelection())
2445 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2446 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2447 if (sel_col_start > sel_col_end) {
2448 sel_col_start = sel_col_end;
2449 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2451 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2453 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2454 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2455 if (sel_row_start > sel_row_end) {
2456 swap(sel_row_start, sel_row_end);
2458 if (sel_cell_start > sel_cell_end) {
2459 swap(sel_cell_start, sel_cell_end);
2461 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2462 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2463 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2470 bool InsetTabular::isRightToLeft(BufferView * bv)
2472 return bv->getParentLanguage(this)->RightToLeft();
2476 bool InsetTabular::nodraw() const
2478 if (!UpdatableInset::nodraw() && the_locking_inset)
2479 return the_locking_inset->nodraw();
2480 return UpdatableInset::nodraw();
2484 int InsetTabular::scroll(bool recursive) const
2486 int sx = UpdatableInset::scroll(false);
2488 if (recursive && the_locking_inset)
2489 sx += the_locking_inset->scroll(recursive);
2495 void InsetTabular::getSelection(int & srow, int & erow,
2496 int & scol, int & ecol) const
2498 int const start = hasSelection() ? sel_cell_start : actcell;
2499 int const end = hasSelection() ? sel_cell_end : actcell;
2501 srow = tabular->row_of_cell(start);
2502 erow = tabular->row_of_cell(end);
2507 scol = tabular->column_of_cell(start);
2508 ecol = tabular->column_of_cell(end);
2512 ecol = tabular->right_column_of_cell(end);
2517 ParagraphList * InsetTabular::getParagraphs(int i) const
2519 return (i < tabular->GetNumberOfCells())
2520 ? tabular->GetCellInset(i)->getParagraphs(0)
2525 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2527 if (the_locking_inset)
2528 return the_locking_inset->cursor(bv);
2529 return Inset::cursor(bv);
2533 Inset * InsetTabular::getInsetFromID(int id_arg) const
2536 return const_cast<InsetTabular *>(this);
2539 for(int i = 0; i < tabular->rows(); ++i) {
2540 for(int j = 0; j < tabular->columns(); ++j) {
2541 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2550 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2553 if (the_locking_inset) {
2554 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2555 if (!word.word().empty()) {
2559 if (tabular->IsLastCell(actcell)) {
2560 bv->unlockInset(const_cast<InsetTabular *>(this));
2562 return WordLangTuple();
2566 // otherwise we have to lock the next inset and ask for it's selecttion
2567 UpdatableInset * inset =
2568 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2569 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2570 WordLangTuple word(selectNextWordInt(bv, value));
2572 if (!word.word().empty())
2578 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2580 // when entering this function the inset should be ALWAYS locked!
2581 lyx::Assert(the_locking_inset);
2583 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2584 if (!word.word().empty())
2587 if (tabular->IsLastCell(actcell)) {
2588 bv->unlockInset(const_cast<InsetTabular *>(this));
2589 return WordLangTuple();
2592 // otherwise we have to lock the next inset and ask for it's selecttion
2593 UpdatableInset * inset =
2594 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2595 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2596 return selectNextWordInt(bv, value);
2600 void InsetTabular::selectSelectedWord(BufferView * bv)
2602 if (the_locking_inset) {
2603 the_locking_inset->selectSelectedWord(bv);
2610 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2612 if (the_locking_inset) {
2613 the_locking_inset->toggleSelection(bv, kill_selection);
2618 void InsetTabular::markErased()
2622 while (!tabular->IsLastCell(cell)) {
2624 InsetText * inset = tabular->GetCellInset(cell);
2625 inset->markErased();
2630 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2632 if (the_locking_inset) {
2633 if (the_locking_inset->nextChange(bv, length)) {
2634 updateLocal(bv, CELL);
2637 if (tabular->IsLastCell(actcell))
2641 InsetText * inset = tabular->GetCellInset(actcell);
2642 if (inset->nextChange(bv, length)) {
2643 updateLocal(bv, FULL);
2646 while (!tabular->IsLastCell(actcell)) {
2648 inset = tabular->GetCellInset(actcell);
2649 if (inset->nextChange(bv, length)) {
2650 updateLocal(bv, FULL);
2658 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2662 if (the_locking_inset) {
2663 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2664 updateLocal(bv, CELL);
2667 if (tabular->IsLastCell(actcell))
2671 InsetText * inset = tabular->GetCellInset(cell);
2672 if (inset->searchForward(bv, str, cs, mw)) {
2673 updateLocal(bv, FULL);
2676 while (!tabular->IsLastCell(cell)) {
2678 inset = tabular->GetCellInset(cell);
2679 if (inset->searchForward(bv, str, cs, mw)) {
2680 updateLocal(bv, FULL);
2688 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2691 int cell = tabular->GetNumberOfCells();
2692 if (the_locking_inset) {
2693 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2694 updateLocal(bv, CELL);
2702 InsetText * inset = tabular->GetCellInset(cell);
2703 if (inset->searchBackward(bv, str, cs, mw)) {
2704 updateLocal(bv, CELL);
2712 bool InsetTabular::insetAllowed(Inset::Code code) const
2714 if (the_locking_inset)
2715 return the_locking_inset->insetAllowed(code);
2716 // we return true here because if the inset is not locked someone
2717 // wants to insert something in one of our insettexts and we generally
2723 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2725 const int cell = tabular->GetCellFromInset(in, actcell);
2728 return tabular->GetPWidth(cell).zero();
2730 // well we didn't obviously find it so maybe our owner knows more
2732 return owner()->forceDefaultParagraphs(in);
2733 // if we're here there is really something strange going on!!!
2737 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2740 if (buf.length() <= 0)
2746 string::size_type len = buf.length();
2747 string::size_type p = 0;
2750 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2759 maxCols = max(cols, maxCols);
2765 maxCols = max(cols, maxCols);
2766 LyXTabular * loctab;
2771 delete paste_tabular;
2772 paste_tabular = new LyXTabular(bv->buffer()->params,
2773 this, rows, maxCols);
2774 loctab = paste_tabular;
2777 loctab = tabular.get();
2783 string::size_type op = 0;
2784 int cells = loctab->GetNumberOfCells();
2787 rows = loctab->rows();
2788 int const columns = loctab->columns();
2790 while ((cell < cells) && (p < len) && (row < rows) &&
2791 (p = buf.find_first_of("\t\n", p)) != string::npos)
2797 // we can only set this if we are not too far right
2798 if (cols < columns) {
2799 InsetText * ti = loctab->GetCellInset(cell);
2800 LyXFont const font = ti->getLyXText(bv)->
2801 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2802 ti->setText(buf.substr(op, p - op), font);
2808 // we can only set this if we are not too far right
2809 if (cols < columns) {
2810 InsetText * ti = loctab->GetCellInset(cell);
2811 LyXFont const font = ti->getLyXText(bv)->
2812 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2813 ti->setText(buf.substr(op, p - op), font);
2818 cell = loctab->GetCellNumber(row, cols);
2824 // check for the last cell if there is no trailing '\n'
2825 if ((cell < cells) && (op < len)) {
2826 InsetText * ti = loctab->GetCellInset(cell);
2827 LyXFont const font = ti->getLyXText(bv)->
2828 getFont(bv->buffer(), ti->paragraphs.begin(), 0);
2829 ti->setText(buf.substr(op, len - op), font);
2836 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2838 int const rows = tabular->rows();
2839 int const columns = tabular->columns();
2840 for (int i = 0; i < rows; ++i) {
2841 for (int j = 0; j < columns; ++j) {
2842 tabular->GetCellInset(i,j)->addPreview(loader);
2848 string const InsetTabularMailer:: name_("tabular");
2850 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2855 string const InsetTabularMailer::inset2string() const
2857 return params2string(inset_);
2861 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2863 istringstream data(STRCONV(in));
2865 lex.setStream(data);
2867 #warning CHECK verify that this is a sane value to return.
2873 string const token = lex.getString();
2881 string const token = lex.getString();
2882 if (token != "\\active_cell")
2885 cell = lex.getInteger();
2888 // This is part of the inset proper that is usually swallowed
2889 // by Buffer::readInset
2892 string const token = lex.getString();
2893 if (token != "Tabular")
2900 // FIXME: even current_view would be better than this.
2901 BufferView * const bv = inset.view();
2902 Buffer const * const buffer = bv ? bv->buffer() : 0;
2904 inset.read(buffer, lex);
2906 // We can't set the active cell, but we can tell the frontend
2912 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2914 // FIXME: even current_view would be better than this.
2915 BufferView * const bv = inset.view();
2916 Buffer const * const buffer = bv ? bv->buffer() : 0;
2921 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2922 inset.write(buffer, data);
2923 data << "\\end_inset\n";
2924 return STRCONV(data.str());