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"
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, Buffer const & buf,
179 : UpdatableInset(tab, same_id), buffer(&buf)
181 tabular.reset(new LyXTabular(buf.params,
182 this, *(tab.tabular), same_id));
183 the_locking_inset = 0;
184 old_locking_inset = 0;
187 actrow = actcell = 0;
197 InsetTabular::~InsetTabular()
199 InsetTabularMailer mailer(*this);
204 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
206 return new InsetTabular(*this, buf, same_id);
210 BufferView * InsetTabular::view() const
212 return buffer->getUser();
216 void InsetTabular::write(Buffer const * buf, ostream & os) const
218 os << " Tabular" << endl;
219 tabular->Write(buf, os);
223 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
225 bool const old_format = (lex.getString() == "\\LyXTable");
227 tabular.reset(new LyXTabular(buf, this, lex));
235 string token = lex.getString();
236 while (lex.isOK() && (token != "\\end_inset")) {
238 token = lex.getString();
240 if (token != "\\end_inset") {
241 lex.printError("Missing \\end_inset at this point. "
247 void InsetTabular::dimension(BufferView *, LyXFont const &,
248 Dimension & dim) const
250 dim.a = tabular->GetAscentOfRow(0);
251 dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
252 dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
256 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
264 Painter & pain = bv->painter();
270 UpdatableInset::draw(bv, font, baseline, x);
273 x += static_cast<float>(scroll());
277 top_baseline = baseline;
278 x += ADD_TO_TABULAR_WIDTH;
282 first_visible_cell = -1;
283 for (i = 0; i < tabular->rows(); ++i) {
285 cell = tabular->GetCellNumber(i, 0);
286 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
287 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
289 baseline += tabular->GetDescentOfRow(i) +
290 tabular->GetAscentOfRow(i + 1) +
291 tabular->GetAdditionalHeight(i + 1);
294 for (j = 0; j < tabular->columns(); ++j) {
295 if (nx > bv->workWidth())
297 if (tabular->IsPartOfMultiColumn(i, j))
299 cx = nx + tabular->GetBeginningOfTextInCell(cell);
300 if (first_visible_cell < 0)
301 first_visible_cell = cell;
302 if (hasSelection()) {
303 drawCellSelection(pain, nx, baseline, i, j, cell);
306 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
307 drawCellLines(pain, nx, baseline, i, cell);
308 nx += tabular->GetWidthOfColumn(cell);
311 baseline += tabular->GetDescentOfRow(i) +
312 tabular->GetAscentOfRow(i + 1) +
313 tabular->GetAdditionalHeight(i + 1);
316 x -= ADD_TO_TABULAR_WIDTH;
317 x += width(bv, font);
322 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
323 int row, int cell) const
325 int x2 = x + tabular->GetWidthOfColumn(cell);
328 if (!tabular->topAlreadyDrawn(cell)) {
329 on_off = !tabular->TopLine(cell);
330 pain.line(x, baseline - tabular->GetAscentOfRow(row),
331 x2, baseline - tabular->GetAscentOfRow(row),
332 on_off ? LColor::tabularonoffline : LColor::tabularline,
333 on_off ? Painter::line_onoffdash : Painter::line_solid);
335 on_off = !tabular->BottomLine(cell);
336 pain.line(x, baseline + tabular->GetDescentOfRow(row),
337 x2, baseline + tabular->GetDescentOfRow(row),
338 on_off ? LColor::tabularonoffline : LColor::tabularline,
339 on_off ? Painter::line_onoffdash : Painter::line_solid);
340 if (!tabular->leftAlreadyDrawn(cell)) {
341 on_off = !tabular->LeftLine(cell);
342 pain.line(x, baseline - tabular->GetAscentOfRow(row),
343 x, baseline + tabular->GetDescentOfRow(row),
344 on_off ? LColor::tabularonoffline : LColor::tabularline,
345 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 on_off = !tabular->RightLine(cell);
348 pain.line(x2 - tabular->GetAdditionalWidth(cell),
349 baseline - tabular->GetAscentOfRow(row),
350 x2 - tabular->GetAdditionalWidth(cell),
351 baseline + tabular->GetDescentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
357 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
358 int row, int column, int cell) const
360 lyx::Assert(hasSelection());
361 int cs = tabular->column_of_cell(sel_cell_start);
362 int ce = tabular->column_of_cell(sel_cell_end);
365 cs = tabular->column_of_cell(sel_cell_end);
367 ce = tabular->right_column_of_cell(sel_cell_end);
370 int rs = tabular->row_of_cell(sel_cell_start);
371 int re = tabular->row_of_cell(sel_cell_end);
375 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
376 int w = tabular->GetWidthOfColumn(cell);
377 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
378 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
379 w, h, LColor::selection);
384 void InsetTabular::update(BufferView * bv, bool reinit)
390 owner()->update(bv, true);
397 if (calculate_dimensions_of_cells(bv, true))
400 owner()->update(bv, true);
404 if (the_locking_inset)
405 the_locking_inset->update(bv, reinit);
406 if (need_update < FULL &&
407 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
412 switch (need_update) {
416 if (calculate_dimensions_of_cells(bv, false)) {
431 string const InsetTabular::editMessage() const
433 return _("Opened table");
437 void InsetTabular::insetUnlock(BufferView * bv)
439 if (the_locking_inset) {
440 the_locking_inset->insetUnlock(bv);
441 updateLocal(bv, CELL);
442 the_locking_inset = 0;
447 if (scroll(false) || hasSelection()) {
452 updateLocal(bv, FULL);
457 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
460 calculate_dimensions_of_cells(bv, true);
462 if (!locked && what == CELL)
464 if (need_update < what) // only set this if it has greater update
467 if (need_update != NONE) {
468 bv->updateInset(const_cast<InsetTabular *>(this));
475 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
477 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
482 if (inset == tabular->GetCellInset(actcell)) {
483 lyxerr[Debug::INSETTEXT] << "OK" << endl;
484 the_locking_inset = tabular->GetCellInset(actcell);
487 } else if (!the_locking_inset) {
488 int const n = tabular->GetNumberOfCells();
489 int const id = inset->id();
490 for (int i = 0; i < n; ++i) {
491 InsetText * in = tabular->GetCellInset(i);
494 the_locking_inset = in;
499 if (in->getInsetFromID(id)) {
501 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
502 return the_locking_inset->lockInsetInInset(bv, inset);
505 } else if (the_locking_inset && (the_locking_inset == inset)) {
506 lyxerr[Debug::INSETTEXT] << "OK" << endl;
508 } else if (the_locking_inset) {
509 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
510 return the_locking_inset->lockInsetInInset(bv, inset);
512 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
517 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
520 if (!the_locking_inset)
522 if (the_locking_inset == inset) {
523 the_locking_inset->insetUnlock(bv);
525 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
531 updateLocal(bv, CELL);
532 // this has to be here otherwise we don't redraw the cell!
533 the_locking_inset = 0;
536 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
537 if (inset->lyxCode() == TABULAR_CODE &&
538 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
539 InsetTabularMailer mailer(*this);
540 mailer.updateDialog(bv);
549 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
551 Inset * tl_inset = inset;
552 // look if this inset is really inside myself!
553 while(tl_inset->owner() && tl_inset->owner() != this)
554 tl_inset = tl_inset->owner();
555 // if we enter here it's not ower inset
556 if (!tl_inset->owner())
558 // we only have to do this if this is a subinset of our cells
559 if (tl_inset != inset) {
560 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
563 updateLocal(bv, CELL);
568 int InsetTabular::insetInInsetY() const
570 if (!the_locking_inset)
572 return inset_y + the_locking_inset->insetInInsetY();
576 UpdatableInset * InsetTabular::getLockingInset() const
578 return the_locking_inset ? the_locking_inset->getLockingInset() :
579 const_cast<InsetTabular *>(this);
583 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
587 if (the_locking_inset)
588 return the_locking_inset->getFirstLockingInsetOfType(c);
593 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
595 if (the_locking_inset)
596 return the_locking_inset->insertInset(bv, inset);
601 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
603 if (hasSelection() && cmd.button() == mouse_button::button3)
606 if (hasSelection()) {
608 updateLocal(cmd.view(), SELECTION);
611 int const ocell = actcell;
612 int const orow = actrow;
613 BufferView * bv = cmd.view();
617 the_locking_inset = 0;
621 setPos(bv, cmd.x, cmd.y);
623 updateLocal(bv, NONE);
626 if (cmd.button() == mouse_button::button3) {
627 if ((ocell != actcell) && the_locking_inset) {
628 the_locking_inset->insetUnlock(bv);
629 updateLocal(bv, CELL);
630 the_locking_inset = 0;
636 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
638 if ((ocell == actcell) && the_locking_inset && inset_hit) {
640 FuncRequest cmd1 = cmd;
643 the_locking_inset->localDispatch(cmd1);
647 if (the_locking_inset) {
648 the_locking_inset->insetUnlock(bv);
649 updateLocal(bv, CELL);
650 the_locking_inset = 0;
653 if (cmd.button() == mouse_button::button2) {
654 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
658 if (inset_hit && bv->theLockingInset()) {
659 if (!bv->lockInset(static_cast<UpdatableInset*>
660 (tabular->GetCellInset(actcell))))
662 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
665 FuncRequest cmd1 = cmd;
668 the_locking_inset->localDispatch(cmd1);
674 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
677 if (the_locking_inset) {
678 FuncRequest cmd1 = cmd;
681 ret = the_locking_inset->localDispatch(cmd1);
683 if (cmd.button() == mouse_button::button3 && !ret) {
684 InsetTabularMailer(*this).showDialog(cmd.view());
691 void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
693 if (the_locking_inset) {
694 FuncRequest cmd1 = cmd;
697 the_locking_inset->localDispatch(cmd1);
701 BufferView * bv = cmd.view();
702 int const old_cell = actcell;
704 setPos(bv, cmd.x, cmd.y);
705 if (!hasSelection()) {
706 setSelection(actcell, actcell);
707 updateLocal(bv, SELECTION);
708 } else if (old_cell != actcell) {
709 setSelection(sel_cell_start, actcell);
710 updateLocal(bv, SELECTION);
715 Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
717 // We need to save the value of the_locking_inset as the call to
718 // the_locking_inset->localDispatch might unlock it.
719 old_locking_inset = the_locking_inset;
720 RESULT result = UpdatableInset::localDispatch(cmd);
721 BufferView * bv = cmd.view();
723 if (cmd.action == LFUN_INSET_EDIT) {
725 if (!bv->lockInset(this)) {
726 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
732 the_locking_inset = 0;
736 if (cmd.argument.size()) {
737 if (cmd.argument == "left") {
738 if (isRightToLeft(bv))
739 actcell = tabular->GetLastCellInRow(0);
743 if (isRightToLeft(bv))
744 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
746 actcell = tabular->GetNumberOfCells() - 1;
754 setPos(bv, cmd.x, cmd.y);
757 if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
758 activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
764 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
769 if (cmd.action < 0 && cmd.argument.empty())
772 bool hs = hasSelection();
775 // this one have priority over the locked InsetText, if we're not already
776 // inside another tabular then that one get's priority!
777 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
778 switch (cmd.action) {
779 case LFUN_MOUSE_PRESS:
783 case LFUN_MOUSE_MOTION:
784 lfunMouseMotion(cmd);
787 case LFUN_MOUSE_RELEASE:
788 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
790 case LFUN_CELL_BACKWARD:
791 case LFUN_CELL_FORWARD:
792 unlockInsetInInset(bv, the_locking_inset);
793 if (cmd.action == LFUN_CELL_FORWARD)
794 moveNextCell(bv, old_locking_inset != 0);
796 movePrevCell(bv, old_locking_inset != 0);
799 updateLocal(bv, SELECTION);
800 if (!the_locking_inset) {
801 return DISPATCHED_NOUPDATE;
804 // this to avoid compiler warnings.
810 kb_action action = cmd.action;
811 string arg = cmd.argument;
812 if (the_locking_inset) {
813 result = the_locking_inset->localDispatch(cmd);
814 if (result == DISPATCHED_NOUPDATE) {
817 if (sc != scroll()) { // inset has been scrolled
818 updateLocal(bv, FULL);
821 } else if (result == DISPATCHED) {
822 updateLocal(bv, CELL);
824 } else if (result == FINISHED_UP) {
826 // Make sure to reset status message after
827 // exiting, e.g. math inset
828 bv->owner()->clearMessage();
829 } else if (result == FINISHED_DOWN) {
831 bv->owner()->clearMessage();
832 } else if (result == FINISHED_RIGHT) {
834 bv->owner()->clearMessage();
835 } else if (result == FINISHED) {
836 bv->owner()->clearMessage();
842 // --- Cursor Movements ----------------------------------
843 case LFUN_RIGHTSEL: {
844 int const start = hasSelection() ? sel_cell_start : actcell;
845 if (tabular->IsLastCellInRow(actcell)) {
846 setSelection(start, actcell);
851 // if we are starting a selection, only select
852 // the current cell at the beginning
853 if (hasSelection()) {
854 moveRight(bv, false);
857 setSelection(start, end);
858 updateLocal(bv, SELECTION);
862 result = moveRight(bv);
865 updateLocal(bv, SELECTION);
868 int const start = hasSelection() ? sel_cell_start : actcell;
869 if (tabular->IsFirstCellInRow(actcell)) {
870 setSelection(start, actcell);
875 // if we are starting a selection, only select
876 // the current cell at the beginning
877 if (hasSelection()) {
881 setSelection(start, end);
882 updateLocal(bv, SELECTION);
886 result = moveLeft(bv);
889 updateLocal(bv, SELECTION);
892 int const start = hasSelection() ? sel_cell_start : actcell;
893 int const ocell = actcell;
894 // if we are starting a selection, only select
895 // the current cell at the beginning
896 if (hasSelection()) {
898 if ((ocell == sel_cell_end) ||
899 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
900 setSelection(start, tabular->GetCellBelow(sel_cell_end));
902 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
904 setSelection(start, start);
906 updateLocal(bv, SELECTION);
910 result = moveDown(bv, old_locking_inset != 0);
913 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->GetCellAbove(sel_cell_end));
927 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
929 setSelection(start, start);
931 updateLocal(bv, SELECTION);
935 result = moveUp(bv, old_locking_inset != 0);
938 updateLocal(bv, SELECTION);
941 UpdateCodes code = CURSOR;
947 unlockInsetInInset(bv, the_locking_inset);
948 if (bv->text->top_y() + bv->painter().paperHeight() <
949 (top_baseline + tabular->GetHeightOfTabular()))
951 bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
953 actcell = tabular->GetCellBelow(first_visible_cell) + column;
955 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
958 updateLocal(bv, code);
962 UpdateCodes code = CURSOR;
968 unlockInsetInInset(bv, the_locking_inset);
969 if (top_baseline < 0) {
970 bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
972 if (top_baseline > 0)
975 actcell = tabular->GetCellBelow(first_visible_cell) + column;
980 updateLocal(bv, code);
983 // none of these make sense for insettabular,
984 // but we must catch them to prevent any
985 // selection from being confused
989 case LFUN_WORDLEFTSEL:
991 case LFUN_WORDRIGHTSEL:
993 case LFUN_DOWN_PARAGRAPH:
994 case LFUN_DOWN_PARAGRAPHSEL:
995 case LFUN_UP_PARAGRAPH:
996 case LFUN_UP_PARAGRAPHSEL:
1002 case LFUN_BEGINNINGBUF:
1003 case LFUN_BEGINNINGBUFSEL:
1005 case LFUN_ENDBUFSEL:
1007 case LFUN_LAYOUT_TABULAR: {
1008 InsetTabularMailer mailer(*this);
1009 mailer.showDialog(bv);
1012 case LFUN_INSET_DIALOG_UPDATE: {
1013 InsetTabularMailer mailer(*this);
1014 mailer.updateDialog(bv);
1017 case LFUN_TABULAR_FEATURE:
1018 if (!tabularFeatures(bv, arg))
1019 result = UNDISPATCHED;
1021 // insert file functions
1022 case LFUN_FILE_INSERT_ASCII_PARA:
1023 case LFUN_FILE_INSERT_ASCII:
1025 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1028 if (insertAsciiString(bv, tmpstr, false))
1029 updateLocal(bv, INIT);
1031 result = UNDISPATCHED;
1034 // cut and paste functions
1036 if (!copySelection(bv))
1040 setUndo(bv, Undo::DELETE, bv->text->cursor.par());
1041 cutSelection(bv->buffer()->params);
1042 updateLocal(bv, INIT);
1045 if (!hasSelection())
1050 case LFUN_PASTESELECTION:
1052 string const clip(bv->getClipboard());
1056 if (clip.find('\t') != string::npos) {
1060 string::size_type len = clip.length();
1061 string::size_type p = 0;
1064 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1072 maxCols = max(cols, maxCols);
1078 maxCols = max(cols, maxCols);
1079 delete paste_tabular;
1080 paste_tabular = new LyXTabular(bv->buffer()->params,
1081 this, rows, maxCols);
1082 string::size_type op = 0;
1084 int cells = paste_tabular->GetNumberOfCells();
1086 while ((cell < cells) && (p < len) &&
1087 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1092 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1097 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1098 while (cols++ < maxCols)
1106 // check for the last cell if there is no trailing '\n'
1107 if ((cell < cells) && (op < len))
1108 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1111 if (!insertAsciiString(bv, clip, true))
1114 // so that the clipboard is used and it goes on
1116 // and executes LFUN_PASTESELECTION in insettext!
1117 delete paste_tabular;
1122 if (hasPasteBuffer()) {
1123 setUndo(bv, Undo::INSERT, bv->text->cursor.par());
1125 updateLocal(bv, INIT);
1128 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1130 // handle font changing stuff on selection before we lock the inset
1131 // in the default part!
1132 result = UNDISPATCHED;
1143 case LFUN_UNDERLINE:
1144 case LFUN_FONT_SIZE:
1145 if (bv->dispatch(FuncRequest(bv, action, arg)))
1146 result = DISPATCHED;
1152 // we try to activate the actual inset and put this event down to
1153 // the insets dispatch function.
1154 if ((result == DISPATCHED) || the_locking_inset)
1157 if (activateCellInset(bv)) {
1158 // reset need_update setted in above function!
1160 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1161 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1162 unlockInsetInInset(bv, the_locking_inset);
1164 // we need to update if this was requested before
1165 updateLocal(bv, NONE);
1166 return UNDISPATCHED;
1169 // so the below CELL is not set because this is higher
1170 // priority and we get a full redraw
1171 need_update = SELECTION;
1174 updateLocal(bv, CELL);
1179 if (result < FINISHED) {
1180 if (!the_locking_inset) {
1181 if (bv->fitCursor())
1182 updateLocal(bv, FULL);
1185 bv->unlockInset(this);
1190 int InsetTabular::latex(Buffer const * buf, ostream & os,
1191 LatexRunParams const & runparams) const
1193 return tabular->latex(buf, os, runparams);
1197 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1200 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1202 return tabular->ascii(buf, os, 0, false,0);
1206 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1209 int const ret = tabular->ascii(buf,os,
1210 (int)parOwner()->params().depth(),
1217 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1222 // if the table is inside a float it doesn't need the informaltable
1223 // wrapper. Search for it.
1224 for(master = owner();
1225 master && master->lyxCode() != Inset::FLOAT_CODE;
1226 master = master->owner());
1229 os << "<informaltable>";
1234 ret+= tabular->docbook(buf, os, mixcont);
1236 os << "</informaltable>";
1245 void InsetTabular::validate(LaTeXFeatures & features) const
1247 tabular->Validate(features);
1251 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1257 bool changed = false;
1259 // FIXME: since InsetText ignores this anyway, it doesn't
1260 // matter what we pass it. Ugly
1263 // if we have a locking_inset we should have to check only this cell for
1264 // change so I'll try this to have a boost, but who knows ;)
1265 if ((need_update != INIT) &&
1266 (the_locking_inset == tabular->GetCellInset(actcell))) {
1267 for(int i = 0; i < tabular->columns(); ++i) {
1268 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1270 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1273 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1274 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1275 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1278 for (int i = 0; i < tabular->rows(); ++i) {
1281 for (int j = 0; j < tabular->columns(); ++j) {
1282 if (tabular->IsPartOfMultiColumn(i,j))
1285 inset = tabular->GetCellInset(cell);
1286 if (!reinit && !tabular->GetPWidth(cell).zero())
1287 inset->update(bv, false);
1288 maxAsc = max(maxAsc, inset->ascent(bv, font));
1289 maxDesc = max(maxDesc, inset->descent(bv, font));
1290 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1292 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1293 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1301 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1303 if (the_locking_inset) {
1304 the_locking_inset->getCursor(bv, x, y);
1309 y = cursor_.y() + InsetTabular::y();
1312 int desc = tabular->GetDescentOfRow(actrow);
1314 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1316 y += ADD_TO_HEIGHT * 2;
1317 y += TEXT_TO_INSET_OFFSET;
1321 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1323 if (the_locking_inset) {
1324 the_locking_inset->getCursorPos(bv, x, y);
1327 x = cursor_.x() - top_x;
1332 void InsetTabular::fitInsetCursor(BufferView * bv) const
1334 if (the_locking_inset) {
1335 int old_top_y = bv->text->top_y();
1336 the_locking_inset->fitInsetCursor(bv);
1337 if (old_top_y != bv->text->top_y())
1343 int const asc = font_metrics::maxAscent(font);
1344 int const desc = font_metrics::maxDescent(font);
1347 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1352 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1356 actcell = actrow = actcol = 0;
1357 int ly = tabular->GetDescentOfRow(actrow);
1359 // first search the right row
1360 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1361 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1362 tabular->GetAscentOfRow(actrow + 1) +
1363 tabular->GetAdditionalHeight(actrow + 1));
1365 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1367 actcell = tabular->GetCellNumber(actrow, actcol);
1369 // now search the right column
1370 int lx = tabular->GetWidthOfColumn(actcell) -
1371 tabular->GetAdditionalWidth(actcell);
1372 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1373 lx += tabular->GetWidthOfColumn(actcell + 1)
1374 + tabular->GetAdditionalWidth(actcell);
1376 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1381 int InsetTabular::getCellXPos(int cell) const
1385 for (; !tabular->IsFirstCellInRow(c); --c)
1387 int lx = tabular->GetWidthOfColumn(cell);
1388 for (; c < cell; ++c) {
1389 lx += tabular->GetWidthOfColumn(c);
1391 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1395 void InsetTabular::resetPos(BufferView * bv) const
1397 #ifdef WITH_WARNINGS
1398 #warning This should be fixed in the right manner (20011128 Jug)
1400 // fast hack to fix infinite repaintings!
1401 if (in_reset_pos > 0)
1405 actcol = tabular->column_of_cell(actcell);
1408 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1409 if (tabular->IsLastCellInRow(cell)) {
1410 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1411 tabular->GetAscentOfRow(actrow + 1) +
1412 tabular->GetAdditionalHeight(actrow + 1));
1416 if (!locked || nodraw()) {
1417 if (the_locking_inset)
1418 inset_y = cursor_.y();
1421 // we need this only from here on!!!
1423 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1424 int new_x = getCellXPos(actcell);
1425 int old_x = cursor_.x();
1428 // cursor.x(getCellXPos(actcell) + offset);
1429 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1430 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1433 updateLocal(bv, FULL);
1434 } else if (the_locking_inset &&
1435 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1437 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1438 if (xx > (bv->workWidth()-20)) {
1439 scroll(bv, -(xx - bv->workWidth() + 60));
1440 updateLocal(bv, FULL);
1441 } else if (xx < 20) {
1447 updateLocal(bv, FULL);
1449 } else if ((cursor_.x() - offset) > 20 &&
1450 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1451 > (bv->workWidth() - 20)) {
1452 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1453 updateLocal(bv, FULL);
1454 } else if ((cursor_.x() - offset) < 20) {
1455 scroll(bv, 20 - cursor_.x() + offset);
1456 updateLocal(bv, FULL);
1457 } else if (scroll() && top_x > 20 &&
1458 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1459 scroll(bv, old_x - cursor_.x());
1460 updateLocal(bv, FULL);
1462 if (the_locking_inset) {
1463 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1464 inset_y = cursor_.y();
1466 if ((!the_locking_inset ||
1467 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1468 actcell != oldcell) {
1469 InsetTabular * inset = const_cast<InsetTabular *>(this);
1470 InsetTabularMailer mailer(*inset);
1471 mailer.updateDialog(bv);
1478 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1480 if (lock && !old_locking_inset) {
1481 if (activateCellInset(bv))
1484 bool moved = isRightToLeft(bv)
1485 ? movePrevCell(bv) : moveNextCell(bv);
1487 return FINISHED_RIGHT;
1488 if (lock && activateCellInset(bv))
1492 return DISPATCHED_NOUPDATE;
1496 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1498 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1501 if (lock) { // behind the inset
1502 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1506 return DISPATCHED_NOUPDATE;
1510 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1512 int const ocell = actcell;
1513 actcell = tabular->GetCellAbove(actcell);
1514 if (actcell == ocell) // we moved out of the inset
1520 if (old_locking_inset) {
1521 old_locking_inset->getCursorPos(bv, x, y);
1522 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1524 if (activateCellInset(bv, x, 0))
1527 return DISPATCHED_NOUPDATE;
1531 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1533 int const ocell = actcell;
1534 actcell = tabular->GetCellBelow(actcell);
1535 if (actcell == ocell) // we moved out of the inset
1536 return FINISHED_DOWN;
1541 if (old_locking_inset) {
1542 old_locking_inset->getCursorPos(bv, x, y);
1543 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1545 if (activateCellInset(bv, x, 0))
1548 return DISPATCHED_NOUPDATE;
1552 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1554 if (isRightToLeft(bv)) {
1555 if (tabular->IsFirstCellInRow(actcell)) {
1556 int row = tabular->row_of_cell(actcell);
1557 if (row == tabular->rows() - 1)
1559 actcell = tabular->GetLastCellInRow(row);
1560 actcell = tabular->GetCellBelow(actcell);
1567 if (tabular->IsLastCell(actcell))
1572 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1573 isRightToLeftPar(bv->buffer()->params);
1574 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1581 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1583 if (isRightToLeft(bv)) {
1584 if (tabular->IsLastCellInRow(actcell)) {
1585 int row = tabular->row_of_cell(actcell);
1588 actcell = tabular->GetFirstCellInRow(row);
1589 actcell = tabular->GetCellAbove(actcell);
1591 if (tabular->IsLastCell(actcell))
1596 if (!actcell) // first cell
1601 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1602 isRightToLeftPar(bv->buffer()->params);
1603 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1610 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1614 setSelection(0, tabular->GetNumberOfCells() - 1);
1616 if (hasSelection()) {
1617 setUndo(bv, Undo::EDIT, bv->text->cursor.par());
1618 bool const frozen = undo_frozen;
1621 // apply the fontchange on the whole selection
1626 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1627 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1628 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1629 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1636 updateLocal(bv, INIT);
1638 if (the_locking_inset)
1639 the_locking_inset->setFont(bv, font, tall);
1643 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1645 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1648 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1649 string const tmp = tabularFeature[i].feature;
1651 if (tmp == what.substr(0, tmp.length())) {
1652 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1653 //tabularFeatures[i].feature.length())) {
1654 action = tabularFeature[i].action;
1658 if (action == LyXTabular::LAST_ACTION)
1662 ltrim(what.substr(tabularFeature[i].feature.length()));
1663 tabularFeatures(bv, action, val);
1669 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1670 string const & special, bool & flag)
1672 if (special == "dl_above") {
1675 } else if (special == "dl_below") {
1676 ltt.bottomDL = flag;
1678 } else if (special == "empty") {
1690 void InsetTabular::tabularFeatures(BufferView * bv,
1691 LyXTabular::Feature feature,
1692 string const & value)
1698 bool setLines = false;
1699 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1700 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1703 case LyXTabular::M_ALIGN_LEFT:
1704 case LyXTabular::ALIGN_LEFT:
1705 setAlign = LYX_ALIGN_LEFT;
1707 case LyXTabular::M_ALIGN_RIGHT:
1708 case LyXTabular::ALIGN_RIGHT:
1709 setAlign = LYX_ALIGN_RIGHT;
1711 case LyXTabular::M_ALIGN_CENTER:
1712 case LyXTabular::ALIGN_CENTER:
1713 setAlign = LYX_ALIGN_CENTER;
1715 case LyXTabular::ALIGN_BLOCK:
1716 setAlign = LYX_ALIGN_BLOCK;
1718 case LyXTabular::M_VALIGN_TOP:
1719 case LyXTabular::VALIGN_TOP:
1720 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1722 case LyXTabular::M_VALIGN_BOTTOM:
1723 case LyXTabular::VALIGN_BOTTOM:
1724 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1726 case LyXTabular::M_VALIGN_CENTER:
1727 case LyXTabular::VALIGN_CENTER:
1728 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1733 if (hasSelection()) {
1734 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1736 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1737 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1739 setUndo(bv, Undo::FINISH, bv->text->cursor.par());
1741 int row = tabular->row_of_cell(actcell);
1742 int column = tabular->column_of_cell(actcell);
1744 LyXTabular::ltType ltt;
1747 case LyXTabular::SET_PWIDTH:
1749 LyXLength const vallen(value);
1750 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1752 bool const update = (tmplen != vallen);
1753 tabular->SetColumnPWidth(actcell, vallen);
1756 for (int i = 0; i < tabular->rows(); ++i) {
1757 cell = tabular->GetCellNumber(i,column);
1758 tabular->GetCellInset(cell)->resizeLyXText(bv);
1760 updateLocal(bv, INIT);
1764 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1765 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1766 else if (!vallen.zero()
1767 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1768 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1771 case LyXTabular::SET_MPWIDTH:
1773 LyXLength const vallen(value);
1774 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1776 bool const update = (tmplen != vallen);
1777 tabular->SetMColumnPWidth(actcell, vallen);
1779 for (int i = 0; i < tabular->rows(); ++i) {
1780 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1783 updateLocal(bv, INIT);
1787 case LyXTabular::SET_SPECIAL_COLUMN:
1788 case LyXTabular::SET_SPECIAL_MULTI:
1789 tabular->SetAlignSpecial(actcell,value,feature);
1790 updateLocal(bv, FULL);
1792 case LyXTabular::APPEND_ROW:
1793 // append the row into the tabular
1794 unlockInsetInInset(bv, the_locking_inset);
1795 tabular->AppendRow(bv->buffer()->params, actcell);
1796 updateLocal(bv, INIT);
1798 case LyXTabular::APPEND_COLUMN:
1799 // append the column into the tabular
1800 unlockInsetInInset(bv, the_locking_inset);
1801 tabular->AppendColumn(bv->buffer()->params, actcell);
1802 actcell = tabular->GetCellNumber(row, column);
1803 updateLocal(bv, INIT);
1805 case LyXTabular::DELETE_ROW:
1806 unlockInsetInInset(bv, the_locking_inset);
1807 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1808 tabular->DeleteRow(sel_row_start);
1810 if (sel_row_start >= tabular->rows())
1812 actcell = tabular->GetCellNumber(sel_row_start, column);
1814 updateLocal(bv, INIT);
1816 case LyXTabular::DELETE_COLUMN:
1817 unlockInsetInInset(bv, the_locking_inset);
1818 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1819 tabular->DeleteColumn(sel_col_start);
1821 if (sel_col_start >= tabular->columns())
1823 actcell = tabular->GetCellNumber(row, sel_col_start);
1825 updateLocal(bv, INIT);
1827 case LyXTabular::M_TOGGLE_LINE_TOP:
1829 case LyXTabular::TOGGLE_LINE_TOP:
1831 bool lineSet = !tabular->TopLine(actcell, flag);
1832 for (int i = sel_row_start; i <= sel_row_end; ++i)
1833 for (int j = sel_col_start; j <= sel_col_end; ++j)
1834 tabular->SetTopLine(
1835 tabular->GetCellNumber(i, j),
1837 updateLocal(bv, INIT);
1841 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1843 case LyXTabular::TOGGLE_LINE_BOTTOM:
1845 bool lineSet = !tabular->BottomLine(actcell, flag);
1846 for (int i = sel_row_start; i <= sel_row_end; ++i)
1847 for (int j = sel_col_start; j <= sel_col_end; ++j)
1848 tabular->SetBottomLine(
1849 tabular->GetCellNumber(i, j),
1852 updateLocal(bv, INIT);
1856 case LyXTabular::M_TOGGLE_LINE_LEFT:
1858 case LyXTabular::TOGGLE_LINE_LEFT:
1860 bool lineSet = !tabular->LeftLine(actcell, flag);
1861 for (int i = sel_row_start; i <= sel_row_end; ++i)
1862 for (int j = sel_col_start; j <= sel_col_end; ++j)
1863 tabular->SetLeftLine(
1864 tabular->GetCellNumber(i,j),
1867 updateLocal(bv, INIT);
1871 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1873 case LyXTabular::TOGGLE_LINE_RIGHT:
1875 bool lineSet = !tabular->RightLine(actcell, flag);
1876 for (int i = sel_row_start; i <= sel_row_end; ++i)
1877 for (int j = sel_col_start; j <= sel_col_end; ++j)
1878 tabular->SetRightLine(
1879 tabular->GetCellNumber(i,j),
1882 updateLocal(bv, INIT);
1886 case LyXTabular::M_ALIGN_LEFT:
1887 case LyXTabular::M_ALIGN_RIGHT:
1888 case LyXTabular::M_ALIGN_CENTER:
1890 case LyXTabular::ALIGN_LEFT:
1891 case LyXTabular::ALIGN_RIGHT:
1892 case LyXTabular::ALIGN_CENTER:
1893 case LyXTabular::ALIGN_BLOCK:
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->SetAlignment(
1897 tabular->GetCellNumber(i, j),
1900 updateLocal(bv, INIT);
1902 case LyXTabular::M_VALIGN_TOP:
1903 case LyXTabular::M_VALIGN_BOTTOM:
1904 case LyXTabular::M_VALIGN_CENTER:
1906 case LyXTabular::VALIGN_TOP:
1907 case LyXTabular::VALIGN_BOTTOM:
1908 case LyXTabular::VALIGN_CENTER:
1909 for (int i = sel_row_start; i <= sel_row_end; ++i)
1910 for (int j = sel_col_start; j <= sel_col_end; ++j)
1911 tabular->SetVAlignment(
1912 tabular->GetCellNumber(i, j),
1914 updateLocal(bv, INIT);
1916 case LyXTabular::MULTICOLUMN:
1918 if (sel_row_start != sel_row_end) {
1919 #ifdef WITH_WARNINGS
1920 #warning Need I say it ? This is horrible.
1922 Alert::error(_("Error setting multicolumn"),
1923 _("You cannot set multicolumn vertically."));
1926 // just multicol for one Single Cell
1927 if (!hasSelection()) {
1928 // check wether we are completly in a multicol
1929 if (tabular->IsMultiColumn(actcell)) {
1930 tabular->UnsetMultiColumn(actcell);
1931 updateLocal(bv, INIT);
1933 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1934 updateLocal(bv, CELL);
1938 // we have a selection so this means we just add all this
1939 // cells to form a multicolumn cell
1943 if (sel_cell_start > sel_cell_end) {
1944 s_start = sel_cell_end;
1945 s_end = sel_cell_start;
1947 s_start = sel_cell_start;
1948 s_end = sel_cell_end;
1950 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1953 updateLocal(bv, INIT);
1956 case LyXTabular::SET_ALL_LINES:
1958 case LyXTabular::UNSET_ALL_LINES:
1959 for (int i = sel_row_start; i <= sel_row_end; ++i)
1960 for (int j = sel_col_start; j <= sel_col_end; ++j)
1961 tabular->SetAllLines(
1962 tabular->GetCellNumber(i,j), setLines);
1963 updateLocal(bv, INIT);
1965 case LyXTabular::SET_LONGTABULAR:
1966 tabular->SetLongTabular(true);
1967 updateLocal(bv, INIT); // because this toggles displayed
1969 case LyXTabular::UNSET_LONGTABULAR:
1970 tabular->SetLongTabular(false);
1971 updateLocal(bv, INIT); // because this toggles displayed
1973 case LyXTabular::SET_ROTATE_TABULAR:
1974 tabular->SetRotateTabular(true);
1976 case LyXTabular::UNSET_ROTATE_TABULAR:
1977 tabular->SetRotateTabular(false);
1979 case LyXTabular::SET_ROTATE_CELL:
1980 for (int i = sel_row_start; i <= sel_row_end; ++i)
1981 for (int j = sel_col_start; j<=sel_col_end; ++j)
1982 tabular->SetRotateCell(
1983 tabular->GetCellNumber(i, j),
1986 case LyXTabular::UNSET_ROTATE_CELL:
1987 for (int i = sel_row_start; i <= sel_row_end; ++i)
1988 for (int j = sel_col_start; j <= sel_col_end; ++j)
1989 tabular->SetRotateCell(
1990 tabular->GetCellNumber(i, j), false);
1992 case LyXTabular::SET_USEBOX:
1994 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1995 if (val == tabular->GetUsebox(actcell))
1996 val = LyXTabular::BOX_NONE;
1997 for (int i = sel_row_start; i <= sel_row_end; ++i)
1998 for (int j = sel_col_start; j <= sel_col_end; ++j)
2000 tabular->GetCellNumber(i, j), val);
2003 case LyXTabular::UNSET_LTFIRSTHEAD:
2005 case LyXTabular::SET_LTFIRSTHEAD:
2006 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2007 checkLongtableSpecial(ltt, value, flag);
2008 tabular->SetLTHead(row, flag, ltt, true);
2010 case LyXTabular::UNSET_LTHEAD:
2012 case LyXTabular::SET_LTHEAD:
2013 (void)tabular->GetRowOfLTHead(row, ltt);
2014 checkLongtableSpecial(ltt, value, flag);
2015 tabular->SetLTHead(row, flag, ltt, false);
2017 case LyXTabular::UNSET_LTFOOT:
2019 case LyXTabular::SET_LTFOOT:
2020 (void)tabular->GetRowOfLTFoot(row, ltt);
2021 checkLongtableSpecial(ltt, value, flag);
2022 tabular->SetLTFoot(row, flag, ltt, false);
2024 case LyXTabular::UNSET_LTLASTFOOT:
2026 case LyXTabular::SET_LTLASTFOOT:
2027 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2028 checkLongtableSpecial(ltt, value, flag);
2029 tabular->SetLTFoot(row, flag, ltt, true);
2031 case LyXTabular::SET_LTNEWPAGE:
2033 bool what = !tabular->GetLTNewPage(row);
2034 tabular->SetLTNewPage(row, what);
2037 // dummy stuff just to avoid warnings
2038 case LyXTabular::LAST_ACTION:
2042 InsetTabularMailer mailer(*this);
2043 mailer.updateDialog(bv);
2047 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2050 UpdatableInset * inset =
2051 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2052 LyXFont font(LyXFont::ALL_SANE);
2054 x = inset->x() + inset->width(bv, font);
2055 y = inset->descent(bv, font);
2057 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2058 //inset_y = cursor.y();
2059 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2060 if (!the_locking_inset)
2062 updateLocal(bv, CELL);
2063 return (the_locking_inset != 0);
2067 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2068 mouse_button::state button)
2070 inset_x = cursor_.x()
2071 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2072 inset_y = cursor_.y();
2073 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2077 bool InsetTabular::insetHit(BufferView *, int x, int) const
2080 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2084 // This returns paperWidth() if the cell-width is unlimited or the width
2085 // in pixels if we have a pwidth for this cell.
2086 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2088 LyXLength const len = tabular->GetPWidth(cell);
2092 return len.inPixels(latexTextWidth(bv));
2096 int InsetTabular::getMaxWidth(BufferView * bv,
2097 UpdatableInset const * inset) const
2099 int cell = tabular->GetCellFromInset(inset, actcell);
2102 lyxerr << "Own inset not found, shouldn't really happen!"
2107 int w = getMaxWidthOfCell(bv, cell);
2109 // because the inset then subtracts it's top_x and owner->x()
2110 w += (inset->x() - top_x);
2117 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2119 resizeLyXText(bv, recursive);
2123 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2126 for(int i = 0; i < tabular->rows(); ++i) {
2127 for(int j = 0; j < tabular->columns(); ++j) {
2128 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2136 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2137 bool const recursive) const
2139 if (the_locking_inset)
2140 return the_locking_inset->getLyXText(bv, recursive);
2142 // if we're locked lock the actual insettext and return it's LyXText!!!
2144 UpdatableInset * inset =
2145 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2146 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2147 return the_locking_inset->getLyXText(bv, recursive);
2150 return Inset::getLyXText(bv, recursive);
2154 bool InsetTabular::showInsetDialog(BufferView * bv) const
2156 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2157 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2158 InsetTabularMailer mailer(*tmp);
2159 mailer.showDialog(bv);
2165 void InsetTabular::openLayoutDialog(BufferView * bv) const
2167 if (the_locking_inset) {
2168 InsetTabular * i = static_cast<InsetTabular *>
2169 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2171 i->openLayoutDialog(bv);
2175 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2176 InsetTabularMailer mailer(*tmp);
2177 mailer.showDialog(bv);
2182 // function returns an object as defined in func_status.h:
2183 // states OK, Unknown, Disabled, On, Off.
2185 FuncStatus InsetTabular::getStatus(string const & what) const
2187 int action = LyXTabular::LAST_ACTION;
2191 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2192 string const tmp = tabularFeature[i].feature;
2193 if (tmp == what.substr(0, tmp.length())) {
2194 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2195 // tabularFeatures[i].feature.length())) {
2196 action = tabularFeature[i].action;
2200 if (action == LyXTabular::LAST_ACTION) {
2202 return status.unknown(true);
2205 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2210 LyXTabular::ltType dummyltt;
2213 if (hasSelection()) {
2214 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2216 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2220 case LyXTabular::SET_PWIDTH:
2221 case LyXTabular::SET_MPWIDTH:
2222 case LyXTabular::SET_SPECIAL_COLUMN:
2223 case LyXTabular::SET_SPECIAL_MULTI:
2224 case LyXTabular::APPEND_ROW:
2225 case LyXTabular::APPEND_COLUMN:
2226 case LyXTabular::DELETE_ROW:
2227 case LyXTabular::DELETE_COLUMN:
2228 case LyXTabular::SET_ALL_LINES:
2229 case LyXTabular::UNSET_ALL_LINES:
2230 return status.clear();
2232 case LyXTabular::MULTICOLUMN:
2233 status.setOnOff(tabular->IsMultiColumn(actcell));
2235 case LyXTabular::M_TOGGLE_LINE_TOP:
2237 case LyXTabular::TOGGLE_LINE_TOP:
2238 status.setOnOff(tabular->TopLine(actcell, flag));
2240 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2242 case LyXTabular::TOGGLE_LINE_BOTTOM:
2243 status.setOnOff(tabular->BottomLine(actcell, flag));
2245 case LyXTabular::M_TOGGLE_LINE_LEFT:
2247 case LyXTabular::TOGGLE_LINE_LEFT:
2248 status.setOnOff(tabular->LeftLine(actcell, flag));
2250 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2252 case LyXTabular::TOGGLE_LINE_RIGHT:
2253 status.setOnOff(tabular->RightLine(actcell, flag));
2255 case LyXTabular::M_ALIGN_LEFT:
2257 case LyXTabular::ALIGN_LEFT:
2258 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2260 case LyXTabular::M_ALIGN_RIGHT:
2262 case LyXTabular::ALIGN_RIGHT:
2263 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2265 case LyXTabular::M_ALIGN_CENTER:
2267 case LyXTabular::ALIGN_CENTER:
2268 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2270 case LyXTabular::ALIGN_BLOCK:
2271 status.disabled(tabular->GetPWidth(actcell).zero());
2272 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2274 case LyXTabular::M_VALIGN_TOP:
2276 case LyXTabular::VALIGN_TOP:
2277 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2279 case LyXTabular::M_VALIGN_BOTTOM:
2281 case LyXTabular::VALIGN_BOTTOM:
2282 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2284 case LyXTabular::M_VALIGN_CENTER:
2286 case LyXTabular::VALIGN_CENTER:
2287 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2289 case LyXTabular::SET_LONGTABULAR:
2290 status.setOnOff(tabular->IsLongTabular());
2292 case LyXTabular::UNSET_LONGTABULAR:
2293 status.setOnOff(!tabular->IsLongTabular());
2295 case LyXTabular::SET_ROTATE_TABULAR:
2296 status.setOnOff(tabular->GetRotateTabular());
2298 case LyXTabular::UNSET_ROTATE_TABULAR:
2299 status.setOnOff(!tabular->GetRotateTabular());
2301 case LyXTabular::SET_ROTATE_CELL:
2302 status.setOnOff(tabular->GetRotateCell(actcell));
2304 case LyXTabular::UNSET_ROTATE_CELL:
2305 status.setOnOff(!tabular->GetRotateCell(actcell));
2307 case LyXTabular::SET_USEBOX:
2308 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2310 case LyXTabular::SET_LTFIRSTHEAD:
2311 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2313 case LyXTabular::SET_LTHEAD:
2314 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2316 case LyXTabular::SET_LTFOOT:
2317 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2319 case LyXTabular::SET_LTLASTFOOT:
2320 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2322 case LyXTabular::SET_LTNEWPAGE:
2323 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2327 status.disabled(true);
2334 vector<string> const InsetTabular::getLabelList() const
2336 return tabular->getLabelList();
2340 bool InsetTabular::copySelection(BufferView * bv)
2342 if (!hasSelection())
2345 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2346 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2347 if (sel_col_start > sel_col_end) {
2348 sel_col_start = sel_col_end;
2349 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2351 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2353 int const columns = sel_col_end - sel_col_start + 1;
2355 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2356 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2357 if (sel_row_start > sel_row_end) {
2358 swap(sel_row_start, sel_row_end);
2360 int const rows = sel_row_end - sel_row_start + 1;
2362 delete paste_tabular;
2363 paste_tabular = new LyXTabular(bv->buffer()->params,
2364 this, *tabular); // rows, columns);
2365 for (int i = 0; i < sel_row_start; ++i)
2366 paste_tabular->DeleteRow(0);
2367 while (paste_tabular->rows() > rows)
2368 paste_tabular->DeleteRow(rows);
2369 paste_tabular->SetTopLine(0, true, true);
2370 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2372 for (int i = 0; i < sel_col_start; ++i)
2373 paste_tabular->DeleteColumn(0);
2374 while (paste_tabular->columns() > columns)
2375 paste_tabular->DeleteColumn(columns);
2376 paste_tabular->SetLeftLine(0, true, true);
2377 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2381 paste_tabular->ascii(bv->buffer(), sstr,
2382 (int)parOwner()->params().depth(), true, '\t');
2383 bv->stuffClipboard(STRCONV(sstr.str()));
2388 bool InsetTabular::pasteSelection(BufferView * bv)
2393 for (int r1 = 0, r2 = actrow;
2394 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2396 for(int c1 = 0, c2 = actcol;
2397 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2399 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2400 tabular->IsPartOfMultiColumn(r2,c2))
2402 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2406 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2410 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2411 int const n2 = tabular->GetCellNumber(r2, c2);
2412 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2413 tabular->GetCellInset(n2)->setOwner(this);
2414 tabular->GetCellInset(n2)->deleteLyXText(bv);
2415 tabular->GetCellInset(n2)->markNew();
2422 bool InsetTabular::cutSelection(BufferParams const & bp)
2424 if (!hasSelection())
2427 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2428 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2429 if (sel_col_start > sel_col_end) {
2430 sel_col_start = sel_col_end;
2431 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2433 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2435 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2436 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2437 if (sel_row_start > sel_row_end) {
2438 swap(sel_row_start, sel_row_end);
2440 if (sel_cell_start > sel_cell_end) {
2441 swap(sel_cell_start, sel_cell_end);
2443 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2444 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2445 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2452 bool InsetTabular::isRightToLeft(BufferView * bv)
2454 return bv->getParentLanguage(this)->RightToLeft();
2458 bool InsetTabular::nodraw() const
2460 if (!UpdatableInset::nodraw() && the_locking_inset)
2461 return the_locking_inset->nodraw();
2462 return UpdatableInset::nodraw();
2466 int InsetTabular::scroll(bool recursive) const
2468 int sx = UpdatableInset::scroll(false);
2470 if (recursive && the_locking_inset)
2471 sx += the_locking_inset->scroll(recursive);
2477 void InsetTabular::getSelection(int & srow, int & erow,
2478 int & scol, int & ecol) const
2480 int const start = hasSelection() ? sel_cell_start : actcell;
2481 int const end = hasSelection() ? sel_cell_end : actcell;
2483 srow = tabular->row_of_cell(start);
2484 erow = tabular->row_of_cell(end);
2489 scol = tabular->column_of_cell(start);
2490 ecol = tabular->column_of_cell(end);
2494 ecol = tabular->right_column_of_cell(end);
2499 ParagraphList * InsetTabular::getParagraphs(int i) const
2501 return (i < tabular->GetNumberOfCells())
2502 ? tabular->GetCellInset(i)->getParagraphs(0)
2507 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2509 if (the_locking_inset)
2510 return the_locking_inset->cursor(bv);
2511 return Inset::cursor(bv);
2515 Inset * InsetTabular::getInsetFromID(int id_arg) const
2518 return const_cast<InsetTabular *>(this);
2521 for(int i = 0; i < tabular->rows(); ++i) {
2522 for(int j = 0; j < tabular->columns(); ++j) {
2523 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2532 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2535 if (the_locking_inset) {
2536 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2537 if (!word.word().empty()) {
2541 if (tabular->IsLastCell(actcell)) {
2542 bv->unlockInset(const_cast<InsetTabular *>(this));
2544 return WordLangTuple();
2548 // otherwise we have to lock the next inset and ask for it's selecttion
2549 UpdatableInset * inset =
2550 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2551 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2552 WordLangTuple word(selectNextWordInt(bv, value));
2554 if (!word.word().empty())
2560 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2562 // when entering this function the inset should be ALWAYS locked!
2563 lyx::Assert(the_locking_inset);
2565 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2566 if (!word.word().empty())
2569 if (tabular->IsLastCell(actcell)) {
2570 bv->unlockInset(const_cast<InsetTabular *>(this));
2571 return WordLangTuple();
2574 // otherwise we have to lock the next inset and ask for it's selecttion
2575 UpdatableInset * inset =
2576 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2577 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2578 return selectNextWordInt(bv, value);
2582 void InsetTabular::selectSelectedWord(BufferView * bv)
2584 if (the_locking_inset) {
2585 the_locking_inset->selectSelectedWord(bv);
2592 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2594 if (the_locking_inset) {
2595 the_locking_inset->toggleSelection(bv, kill_selection);
2600 void InsetTabular::markErased()
2604 while (!tabular->IsLastCell(cell)) {
2606 InsetText * inset = tabular->GetCellInset(cell);
2607 inset->markErased();
2612 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2614 if (the_locking_inset) {
2615 if (the_locking_inset->nextChange(bv, length)) {
2616 updateLocal(bv, CELL);
2619 if (tabular->IsLastCell(actcell))
2623 InsetText * inset = tabular->GetCellInset(actcell);
2624 if (inset->nextChange(bv, length)) {
2625 updateLocal(bv, FULL);
2628 while (!tabular->IsLastCell(actcell)) {
2630 inset = tabular->GetCellInset(actcell);
2631 if (inset->nextChange(bv, length)) {
2632 updateLocal(bv, FULL);
2640 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2644 if (the_locking_inset) {
2645 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2646 updateLocal(bv, CELL);
2649 if (tabular->IsLastCell(actcell))
2653 InsetText * inset = tabular->GetCellInset(cell);
2654 if (inset->searchForward(bv, str, cs, mw)) {
2655 updateLocal(bv, FULL);
2658 while (!tabular->IsLastCell(cell)) {
2660 inset = tabular->GetCellInset(cell);
2661 if (inset->searchForward(bv, str, cs, mw)) {
2662 updateLocal(bv, FULL);
2670 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2673 int cell = tabular->GetNumberOfCells();
2674 if (the_locking_inset) {
2675 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2676 updateLocal(bv, CELL);
2684 InsetText * inset = tabular->GetCellInset(cell);
2685 if (inset->searchBackward(bv, str, cs, mw)) {
2686 updateLocal(bv, CELL);
2694 bool InsetTabular::insetAllowed(Inset::Code code) const
2696 if (the_locking_inset)
2697 return the_locking_inset->insetAllowed(code);
2698 // we return true here because if the inset is not locked someone
2699 // wants to insert something in one of our insettexts and we generally
2705 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2707 const int cell = tabular->GetCellFromInset(in, actcell);
2710 return tabular->GetPWidth(cell).zero();
2712 // well we didn't obviously find it so maybe our owner knows more
2714 return owner()->forceDefaultParagraphs(in);
2715 // if we're here there is really something strange going on!!!
2719 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2722 if (buf.length() <= 0)
2728 string::size_type len = buf.length();
2729 string::size_type p = 0;
2732 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2741 maxCols = max(cols, maxCols);
2747 maxCols = max(cols, maxCols);
2748 LyXTabular * loctab;
2753 delete paste_tabular;
2754 paste_tabular = new LyXTabular(bv->buffer()->params,
2755 this, rows, maxCols);
2756 loctab = paste_tabular;
2759 loctab = tabular.get();
2765 string::size_type op = 0;
2766 int cells = loctab->GetNumberOfCells();
2769 rows = loctab->rows();
2770 int const columns = loctab->columns();
2772 while ((cell < cells) && (p < len) && (row < rows) &&
2773 (p = buf.find_first_of("\t\n", p)) != string::npos)
2779 // we can only set this if we are not too far right
2780 if (cols < columns) {
2781 InsetText * ti = loctab->GetCellInset(cell);
2782 LyXFont const font = ti->getLyXText(bv)->
2783 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2784 ti->setText(buf.substr(op, p - op), font);
2790 // we can only set this if we are not too far right
2791 if (cols < columns) {
2792 InsetText * ti = loctab->GetCellInset(cell);
2793 LyXFont const font = ti->getLyXText(bv)->
2794 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2795 ti->setText(buf.substr(op, p - op), font);
2800 cell = loctab->GetCellNumber(row, cols);
2806 // check for the last cell if there is no trailing '\n'
2807 if ((cell < cells) && (op < len)) {
2808 InsetText * ti = loctab->GetCellInset(cell);
2809 LyXFont const font = ti->getLyXText(bv)->
2810 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2811 ti->setText(buf.substr(op, len - op), font);
2818 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2820 int const rows = tabular->rows();
2821 int const columns = tabular->columns();
2822 for (int i = 0; i < rows; ++i) {
2823 for (int j = 0; j < columns; ++j) {
2824 tabular->GetCellInset(i,j)->addPreview(loader);
2830 string const InsetTabularMailer:: name_("tabular");
2832 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2837 string const InsetTabularMailer::inset2string() const
2839 return params2string(inset_);
2843 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2845 istringstream data(STRCONV(in));
2847 lex.setStream(data);
2849 #warning CHECK verify that this is a sane value to return.
2855 string const token = lex.getString();
2863 string const token = lex.getString();
2864 if (token != "\\active_cell")
2867 cell = lex.getInteger();
2870 // This is part of the inset proper that is usually swallowed
2871 // by Buffer::readInset
2874 string const token = lex.getString();
2875 if (token != "Tabular")
2882 BufferView * const bv = inset.view();
2883 Buffer const * const buffer = bv ? bv->buffer() : 0;
2885 inset.read(buffer, lex);
2887 // We can't set the active cell, but we can tell the frontend
2893 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2895 BufferView * const bv = inset.view();
2896 Buffer const * const buffer = bv ? bv->buffer() : 0;
2901 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2902 inset.write(buffer, data);
2903 data << "\\end_inset\n";
2904 return STRCONV(data.str());