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 "funcrequest.h"
23 #include "LaTeXFeatures.h"
26 #include "lyxlength.h"
29 #include "ParagraphParameters.h"
30 #include "undo_funcs.h"
31 #include "WordLangTuple.h"
34 #include "frontends/Alert.h"
35 #include "frontends/Dialogs.h"
36 #include "frontends/font_metrics.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/Painter.h"
40 #include "support/LAssert.h"
41 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::ALIGN_BLOCK, "align-block" },
87 { LyXTabular::VALIGN_TOP, "valign-top" },
88 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
89 { LyXTabular::VALIGN_CENTER, "valign-center" },
90 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
91 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
92 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
93 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
94 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
95 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
96 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
97 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
98 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
99 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
100 { LyXTabular::MULTICOLUMN, "multicolumn" },
101 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
102 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
103 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
104 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
105 { LyXTabular::SET_PWIDTH, "set-pwidth" },
106 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
107 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
108 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
109 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
110 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
111 { LyXTabular::SET_USEBOX, "set-usebox" },
112 { LyXTabular::SET_LTHEAD, "set-lthead" },
113 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
114 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
115 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
116 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
117 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
118 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
119 { LyXTabular::LAST_ACTION, "" }
123 FindFeature(LyXTabular::Feature feature) : feature_(feature) {}
124 bool operator()(TabularFeature & tf)
126 return tf.action == feature_;
129 LyXTabular::Feature feature_;
135 string const featureAsString(LyXTabular::Feature feature)
137 TabularFeature * it = tabularFeature;
138 TabularFeature * end = it +
139 sizeof(tabularFeature) / sizeof(TabularFeature);
140 it = std::find_if(it, end, FindFeature(feature));
141 return (it == end) ? string() : it->feature;
145 bool InsetTabular::hasPasteBuffer() const
147 return (paste_tabular != 0);
151 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
159 // for now make it always display as display() inset
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
175 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
177 : UpdatableInset(tab, same_id), buffer(&buf)
179 tabular.reset(new LyXTabular(buf.params,
180 this, *(tab.tabular), same_id));
181 the_locking_inset = 0;
182 old_locking_inset = 0;
185 actrow = actcell = 0;
195 InsetTabular::~InsetTabular()
197 InsetTabularMailer mailer(*this);
202 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
204 return new InsetTabular(*this, buf, same_id);
208 BufferView * InsetTabular::view() const
210 return buffer->getUser();
214 void InsetTabular::write(Buffer const * buf, ostream & os) const
216 os << " Tabular" << endl;
217 tabular->Write(buf, os);
221 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
223 bool const old_format = (lex.getString() == "\\LyXTable");
225 tabular.reset(new LyXTabular(buf, this, lex));
233 string token = lex.getString();
234 while (lex.isOK() && (token != "\\end_inset")) {
236 token = lex.getString();
238 if (token != "\\end_inset") {
239 lex.printError("Missing \\end_inset at this point. "
245 int InsetTabular::ascent(BufferView *, LyXFont const &) const
247 return tabular->GetAscentOfRow(0);
251 int InsetTabular::descent(BufferView *, LyXFont const &) const
253 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
257 int InsetTabular::width(BufferView *, LyXFont const &) const
259 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
263 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
271 Painter & pain = bv->painter();
277 UpdatableInset::draw(bv, font, baseline, x);
280 x += static_cast<float>(scroll());
284 top_baseline = baseline;
285 x += ADD_TO_TABULAR_WIDTH;
289 first_visible_cell = -1;
290 for (i = 0; i < tabular->rows(); ++i) {
292 cell = tabular->GetCellNumber(i, 0);
293 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
294 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
296 baseline += tabular->GetDescentOfRow(i) +
297 tabular->GetAscentOfRow(i + 1) +
298 tabular->GetAdditionalHeight(i + 1);
301 for (j = 0; j < tabular->columns(); ++j) {
302 if (nx > bv->workWidth())
304 if (tabular->IsPartOfMultiColumn(i, j))
306 cx = nx + tabular->GetBeginningOfTextInCell(cell);
307 if (first_visible_cell < 0)
308 first_visible_cell = cell;
309 if (hasSelection()) {
310 drawCellSelection(pain, nx, baseline, i, j, cell);
313 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
314 drawCellLines(pain, nx, baseline, i, cell);
315 nx += tabular->GetWidthOfColumn(cell);
318 baseline += tabular->GetDescentOfRow(i) +
319 tabular->GetAscentOfRow(i + 1) +
320 tabular->GetAdditionalHeight(i + 1);
323 x -= ADD_TO_TABULAR_WIDTH;
324 x += width(bv, font);
329 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
330 int row, int cell) const
332 int x2 = x + tabular->GetWidthOfColumn(cell);
335 if (!tabular->topAlreadyDrawn(cell)) {
336 on_off = !tabular->TopLine(cell);
337 pain.line(x, baseline - tabular->GetAscentOfRow(row),
338 x2, baseline - tabular->GetAscentOfRow(row),
339 on_off ? LColor::tabularonoffline : LColor::tabularline,
340 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 on_off = !tabular->BottomLine(cell);
343 pain.line(x, baseline + tabular->GetDescentOfRow(row),
344 x2, baseline + tabular->GetDescentOfRow(row),
345 on_off ? LColor::tabularonoffline : LColor::tabularline,
346 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 if (!tabular->leftAlreadyDrawn(cell)) {
348 on_off = !tabular->LeftLine(cell);
349 pain.line(x, baseline - tabular->GetAscentOfRow(row),
350 x, baseline + tabular->GetDescentOfRow(row),
351 on_off ? LColor::tabularonoffline : LColor::tabularline,
352 on_off ? Painter::line_onoffdash : Painter::line_solid);
354 on_off = !tabular->RightLine(cell);
355 pain.line(x2 - tabular->GetAdditionalWidth(cell),
356 baseline - tabular->GetAscentOfRow(row),
357 x2 - tabular->GetAdditionalWidth(cell),
358 baseline + tabular->GetDescentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
364 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
365 int row, int column, int cell) const
367 lyx::Assert(hasSelection());
368 int cs = tabular->column_of_cell(sel_cell_start);
369 int ce = tabular->column_of_cell(sel_cell_end);
372 cs = tabular->column_of_cell(sel_cell_end);
374 ce = tabular->right_column_of_cell(sel_cell_end);
377 int rs = tabular->row_of_cell(sel_cell_start);
378 int re = tabular->row_of_cell(sel_cell_end);
382 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
383 int w = tabular->GetWidthOfColumn(cell);
384 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
385 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
386 w, h, LColor::selection);
391 void InsetTabular::update(BufferView * bv, bool reinit)
397 owner()->update(bv, true);
404 if (calculate_dimensions_of_cells(bv, true))
407 owner()->update(bv, true);
411 if (the_locking_inset)
412 the_locking_inset->update(bv, reinit);
413 if (need_update < FULL &&
414 bv->text->refreshStatus() == LyXText::REFRESH_AREA)
419 switch (need_update) {
423 if (calculate_dimensions_of_cells(bv, false)) {
438 string const InsetTabular::editMessage() const
440 return _("Opened table");
444 void InsetTabular::insetUnlock(BufferView * bv)
446 if (the_locking_inset) {
447 the_locking_inset->insetUnlock(bv);
448 updateLocal(bv, CELL);
449 the_locking_inset = 0;
454 if (scroll(false) || hasSelection()) {
459 updateLocal(bv, FULL);
464 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
467 calculate_dimensions_of_cells(bv, true);
469 if (!locked && what == CELL)
471 if (need_update < what) // only set this if it has greater update
474 if (need_update != NONE) {
475 bv->updateInset(const_cast<InsetTabular *>(this));
482 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
484 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
489 if (inset == tabular->GetCellInset(actcell)) {
490 lyxerr[Debug::INSETTEXT] << "OK" << endl;
491 the_locking_inset = tabular->GetCellInset(actcell);
494 } else if (!the_locking_inset) {
495 int const n = tabular->GetNumberOfCells();
496 int const id = inset->id();
497 for (int i = 0; i < n; ++i) {
498 InsetText * in = tabular->GetCellInset(i);
501 the_locking_inset = in;
506 if (in->getInsetFromID(id)) {
508 in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
509 return the_locking_inset->lockInsetInInset(bv, inset);
512 } else if (the_locking_inset && (the_locking_inset == inset)) {
513 lyxerr[Debug::INSETTEXT] << "OK" << endl;
515 } else if (the_locking_inset) {
516 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
517 return the_locking_inset->lockInsetInInset(bv, inset);
519 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
524 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
527 if (!the_locking_inset)
529 if (the_locking_inset == inset) {
530 the_locking_inset->insetUnlock(bv);
532 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
538 updateLocal(bv, CELL);
539 // this has to be here otherwise we don't redraw the cell!
540 the_locking_inset = 0;
543 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
544 if (inset->lyxCode() == TABULAR_CODE &&
545 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
546 InsetTabularMailer mailer(*this);
547 mailer.updateDialog(bv);
556 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
558 Inset * tl_inset = inset;
559 // look if this inset is really inside myself!
560 while(tl_inset->owner() && tl_inset->owner() != this)
561 tl_inset = tl_inset->owner();
562 // if we enter here it's not ower inset
563 if (!tl_inset->owner())
565 // we only have to do this if this is a subinset of our cells
566 if (tl_inset != inset) {
567 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
570 updateLocal(bv, CELL);
575 int InsetTabular::insetInInsetY() const
577 if (!the_locking_inset)
579 return inset_y + the_locking_inset->insetInInsetY();
583 UpdatableInset * InsetTabular::getLockingInset() const
585 return the_locking_inset ? the_locking_inset->getLockingInset() :
586 const_cast<InsetTabular *>(this);
590 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
594 if (the_locking_inset)
595 return the_locking_inset->getFirstLockingInsetOfType(c);
600 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
602 if (the_locking_inset)
603 return the_locking_inset->insertInset(bv, inset);
608 void InsetTabular::lfunMousePress(FuncRequest const & cmd)
610 if (hasSelection() && cmd.button() == mouse_button::button3)
613 if (hasSelection()) {
615 updateLocal(cmd.view(), SELECTION);
618 int const ocell = actcell;
619 int const orow = actrow;
620 BufferView * bv = cmd.view();
624 the_locking_inset = 0;
628 setPos(bv, cmd.x, cmd.y);
630 updateLocal(bv, NONE);
633 if (cmd.button() == mouse_button::button3) {
634 if ((ocell != actcell) && the_locking_inset) {
635 the_locking_inset->insetUnlock(bv);
636 updateLocal(bv, CELL);
637 the_locking_inset = 0;
643 bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
645 if ((ocell == actcell) && the_locking_inset && inset_hit) {
647 FuncRequest cmd1 = cmd;
650 the_locking_inset->localDispatch(cmd1);
654 if (the_locking_inset) {
655 the_locking_inset->insetUnlock(bv);
656 updateLocal(bv, CELL);
657 the_locking_inset = 0;
660 if (cmd.button() == mouse_button::button2) {
661 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
665 if (inset_hit && bv->theLockingInset()) {
666 if (!bv->lockInset(static_cast<UpdatableInset*>
667 (tabular->GetCellInset(actcell))))
669 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
672 FuncRequest cmd1 = cmd;
675 the_locking_inset->localDispatch(cmd1);
681 bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
684 if (the_locking_inset) {
685 FuncRequest cmd1 = cmd;
688 ret = the_locking_inset->localDispatch(cmd1);
690 if (cmd.button() == mouse_button::button3 && !ret) {
691 InsetTabularMailer mailer(*this);
692 mailer.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,
1049 bv->text->cursor.par(),
1050 boost::next(bv->text->cursor.par()));
1051 cutSelection(bv->buffer()->params);
1052 updateLocal(bv, INIT);
1055 if (!hasSelection())
1060 case LFUN_PASTESELECTION:
1062 string const clip(bv->getClipboard());
1066 if (clip.find('\t') != string::npos) {
1070 string::size_type len = clip.length();
1071 string::size_type p = 0;
1074 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1082 maxCols = max(cols, maxCols);
1088 maxCols = max(cols, maxCols);
1089 delete paste_tabular;
1090 paste_tabular = new LyXTabular(bv->buffer()->params,
1091 this, rows, maxCols);
1092 string::size_type op = 0;
1094 int cells = paste_tabular->GetNumberOfCells();
1096 while ((cell < cells) && (p < len) &&
1097 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1102 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1107 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1108 while (cols++ < maxCols)
1116 // check for the last cell if there is no trailing '\n'
1117 if ((cell < cells) && (op < len))
1118 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1121 if (!insertAsciiString(bv, clip, true))
1124 // so that the clipboard is used and it goes on
1126 // and executes LFUN_PASTESELECTION in insettext!
1127 delete paste_tabular;
1132 if (hasPasteBuffer()) {
1133 setUndo(bv, Undo::INSERT,
1134 bv->text->cursor.par(),
1135 boost::next(bv->text->cursor.par()));
1137 updateLocal(bv, INIT);
1140 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1142 // handle font changing stuff on selection before we lock the inset
1143 // in the default part!
1144 result = UNDISPATCHED;
1155 case LFUN_UNDERLINE:
1156 case LFUN_FONT_SIZE:
1157 if (bv->dispatch(FuncRequest(bv, action, arg)))
1158 result = DISPATCHED;
1164 // we try to activate the actual inset and put this event down to
1165 // the insets dispatch function.
1166 if ((result == DISPATCHED) || the_locking_inset)
1169 if (activateCellInset(bv)) {
1170 // reset need_update setted in above function!
1172 result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
1173 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1174 unlockInsetInInset(bv, the_locking_inset);
1176 // we need to update if this was requested before
1177 updateLocal(bv, NONE);
1178 return UNDISPATCHED;
1181 // so the below CELL is not set because this is higher
1182 // priority and we get a full redraw
1183 need_update = SELECTION;
1186 updateLocal(bv, CELL);
1191 if (result < FINISHED) {
1192 if (!the_locking_inset) {
1193 if (bv->fitCursor())
1194 updateLocal(bv, FULL);
1197 bv->unlockInset(this);
1202 int InsetTabular::latex(Buffer const * buf, ostream & os,
1203 bool fragile, bool fp) const
1205 return tabular->latex(buf, os, fragile, fp);
1209 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1212 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1214 return tabular->ascii(buf, os, 0, false,0);
1218 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1221 int const ret = tabular->ascii(buf,os,
1222 (int)parOwner()->params().depth(),
1229 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1234 // if the table is inside a float it doesn't need the informaltable
1235 // wrapper. Search for it.
1236 for(master = owner();
1237 master && master->lyxCode() != Inset::FLOAT_CODE;
1238 master = master->owner());
1241 os << "<informaltable>";
1246 ret+= tabular->docbook(buf, os, mixcont);
1248 os << "</informaltable>";
1257 void InsetTabular::validate(LaTeXFeatures & features) const
1259 tabular->Validate(features);
1263 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
1269 bool changed = false;
1271 // FIXME: since InsetText ignores this anyway, it doesn't
1272 // matter what we pass it. Ugly
1275 // if we have a locking_inset we should have to check only this cell for
1276 // change so I'll try this to have a boost, but who knows ;)
1277 if ((need_update != INIT) &&
1278 (the_locking_inset == tabular->GetCellInset(actcell))) {
1279 for(int i = 0; i < tabular->columns(); ++i) {
1280 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1282 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1285 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1286 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1287 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1290 for (int i = 0; i < tabular->rows(); ++i) {
1293 for (int j = 0; j < tabular->columns(); ++j) {
1294 if (tabular->IsPartOfMultiColumn(i,j))
1297 inset = tabular->GetCellInset(cell);
1298 if (!reinit && !tabular->GetPWidth(cell).zero())
1299 inset->update(bv, false);
1300 maxAsc = max(maxAsc, inset->ascent(bv, font));
1301 maxDesc = max(maxDesc, inset->descent(bv, font));
1302 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1304 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1305 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1313 void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
1315 if (the_locking_inset) {
1316 the_locking_inset->getCursor(bv, x, y);
1321 y = cursor_.y() + InsetTabular::y();
1324 int desc = tabular->GetDescentOfRow(actrow);
1326 int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
1328 y += ADD_TO_HEIGHT * 2;
1329 y += TEXT_TO_INSET_OFFSET;
1333 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1335 if (the_locking_inset) {
1336 the_locking_inset->getCursorPos(bv, x, y);
1339 x = cursor_.x() - top_x;
1344 void InsetTabular::fitInsetCursor(BufferView * bv) const
1346 if (the_locking_inset) {
1347 int old_top_y = bv->text->top_y();
1348 the_locking_inset->fitInsetCursor(bv);
1349 if (old_top_y != bv->text->top_y())
1355 int const asc = font_metrics::maxAscent(font);
1356 int const desc = font_metrics::maxDescent(font);
1359 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1364 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1368 actcell = actrow = actcol = 0;
1369 int ly = tabular->GetDescentOfRow(actrow);
1371 // first search the right row
1372 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1373 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1374 tabular->GetAscentOfRow(actrow + 1) +
1375 tabular->GetAdditionalHeight(actrow + 1));
1377 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1379 actcell = tabular->GetCellNumber(actrow, actcol);
1381 // now search the right column
1382 int lx = tabular->GetWidthOfColumn(actcell) -
1383 tabular->GetAdditionalWidth(actcell);
1384 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1385 lx += tabular->GetWidthOfColumn(actcell + 1)
1386 + tabular->GetAdditionalWidth(actcell);
1388 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1393 int InsetTabular::getCellXPos(int cell) const
1397 for (; !tabular->IsFirstCellInRow(c); --c)
1399 int lx = tabular->GetWidthOfColumn(cell);
1400 for (; c < cell; ++c) {
1401 lx += tabular->GetWidthOfColumn(c);
1403 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1407 void InsetTabular::resetPos(BufferView * bv) const
1409 #ifdef WITH_WARNINGS
1410 #warning This should be fixed in the right manner (20011128 Jug)
1412 // fast hack to fix infinite repaintings!
1413 if (in_reset_pos > 0)
1417 actcol = tabular->column_of_cell(actcell);
1420 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1421 if (tabular->IsLastCellInRow(cell)) {
1422 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1423 tabular->GetAscentOfRow(actrow + 1) +
1424 tabular->GetAdditionalHeight(actrow + 1));
1428 if (!locked || nodraw()) {
1429 if (the_locking_inset)
1430 inset_y = cursor_.y();
1433 // we need this only from here on!!!
1435 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1436 int new_x = getCellXPos(actcell);
1437 int old_x = cursor_.x();
1440 // cursor.x(getCellXPos(actcell) + offset);
1441 if ((actcol < tabular->columns() - 1) && scroll(false) &&
1442 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1445 updateLocal(bv, FULL);
1446 } else if (the_locking_inset &&
1447 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1449 int xx = cursor_.x() - offset + bv->text->getRealCursorX();
1450 if (xx > (bv->workWidth()-20)) {
1451 scroll(bv, -(xx - bv->workWidth() + 60));
1452 updateLocal(bv, FULL);
1453 } else if (xx < 20) {
1459 updateLocal(bv, FULL);
1461 } else if ((cursor_.x() - offset) > 20 &&
1462 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1463 > (bv->workWidth() - 20)) {
1464 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1465 updateLocal(bv, FULL);
1466 } else if ((cursor_.x() - offset) < 20) {
1467 scroll(bv, 20 - cursor_.x() + offset);
1468 updateLocal(bv, FULL);
1469 } else if (scroll() && top_x > 20 &&
1470 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1471 scroll(bv, old_x - cursor_.x());
1472 updateLocal(bv, FULL);
1474 if (the_locking_inset) {
1475 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1476 inset_y = cursor_.y();
1478 if ((!the_locking_inset ||
1479 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1480 actcell != oldcell) {
1481 InsetTabular * inset = const_cast<InsetTabular *>(this);
1482 InsetTabularMailer mailer(*inset);
1483 mailer.updateDialog(bv);
1490 Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1492 if (lock && !old_locking_inset) {
1493 if (activateCellInset(bv))
1496 bool moved = isRightToLeft(bv)
1497 ? movePrevCell(bv) : moveNextCell(bv);
1499 return FINISHED_RIGHT;
1500 if (lock && activateCellInset(bv))
1504 return DISPATCHED_NOUPDATE;
1508 Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1510 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1513 if (lock) { // behind the inset
1514 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1518 return DISPATCHED_NOUPDATE;
1522 Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1524 int const ocell = actcell;
1525 actcell = tabular->GetCellAbove(actcell);
1526 if (actcell == ocell) // we moved out of the inset
1532 if (old_locking_inset) {
1533 old_locking_inset->getCursorPos(bv, x, y);
1534 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1536 if (activateCellInset(bv, x, 0))
1539 return DISPATCHED_NOUPDATE;
1543 Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1545 int const ocell = actcell;
1546 actcell = tabular->GetCellBelow(actcell);
1547 if (actcell == ocell) // we moved out of the inset
1548 return FINISHED_DOWN;
1553 if (old_locking_inset) {
1554 old_locking_inset->getCursorPos(bv, x, y);
1555 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1557 if (activateCellInset(bv, x, 0))
1560 return DISPATCHED_NOUPDATE;
1564 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1566 if (isRightToLeft(bv)) {
1567 if (tabular->IsFirstCellInRow(actcell)) {
1568 int row = tabular->row_of_cell(actcell);
1569 if (row == tabular->rows() - 1)
1571 actcell = tabular->GetLastCellInRow(row);
1572 actcell = tabular->GetCellBelow(actcell);
1579 if (tabular->IsLastCell(actcell))
1584 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1585 isRightToLeftPar(bv->buffer()->params);
1586 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1593 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1595 if (isRightToLeft(bv)) {
1596 if (tabular->IsLastCellInRow(actcell)) {
1597 int row = tabular->row_of_cell(actcell);
1600 actcell = tabular->GetFirstCellInRow(row);
1601 actcell = tabular->GetCellAbove(actcell);
1603 if (tabular->IsLastCell(actcell))
1608 if (!actcell) // first cell
1613 bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
1614 isRightToLeftPar(bv->buffer()->params);
1615 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1622 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1626 setSelection(0, tabular->GetNumberOfCells() - 1);
1628 if (hasSelection()) {
1629 setUndo(bv, Undo::EDIT,
1630 bv->text->cursor.par(),
1631 boost::next(bv->text->cursor.par()));
1632 bool const frozen = undo_frozen;
1635 // apply the fontchange on the whole selection
1640 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1641 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1642 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1643 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1650 updateLocal(bv, INIT);
1652 if (the_locking_inset)
1653 the_locking_inset->setFont(bv, font, tall);
1657 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1659 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1662 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1663 string const tmp = tabularFeature[i].feature;
1665 if (tmp == what.substr(0, tmp.length())) {
1666 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1667 //tabularFeatures[i].feature.length())) {
1668 action = tabularFeature[i].action;
1672 if (action == LyXTabular::LAST_ACTION)
1676 ltrim(what.substr(tabularFeature[i].feature.length()));
1677 tabularFeatures(bv, action, val);
1683 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1684 string const & special, bool & flag)
1686 if (special == "dl_above") {
1689 } else if (special == "dl_below") {
1690 ltt.bottomDL = flag;
1692 } else if (special == "empty") {
1704 void InsetTabular::tabularFeatures(BufferView * bv,
1705 LyXTabular::Feature feature,
1706 string const & value)
1712 bool setLines = false;
1713 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1714 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1717 case LyXTabular::M_ALIGN_LEFT:
1718 case LyXTabular::ALIGN_LEFT:
1719 setAlign = LYX_ALIGN_LEFT;
1721 case LyXTabular::M_ALIGN_RIGHT:
1722 case LyXTabular::ALIGN_RIGHT:
1723 setAlign = LYX_ALIGN_RIGHT;
1725 case LyXTabular::M_ALIGN_CENTER:
1726 case LyXTabular::ALIGN_CENTER:
1727 setAlign = LYX_ALIGN_CENTER;
1729 case LyXTabular::ALIGN_BLOCK:
1730 setAlign = LYX_ALIGN_BLOCK;
1732 case LyXTabular::M_VALIGN_TOP:
1733 case LyXTabular::VALIGN_TOP:
1734 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1736 case LyXTabular::M_VALIGN_BOTTOM:
1737 case LyXTabular::VALIGN_BOTTOM:
1738 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1740 case LyXTabular::M_VALIGN_CENTER:
1741 case LyXTabular::VALIGN_CENTER:
1742 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1747 if (hasSelection()) {
1748 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1750 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1751 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1753 setUndo(bv, Undo::FINISH,
1754 bv->text->cursor.par(),
1755 boost::next(bv->text->cursor.par()));
1757 int row = tabular->row_of_cell(actcell);
1758 int column = tabular->column_of_cell(actcell);
1760 LyXTabular::ltType ltt;
1763 case LyXTabular::SET_PWIDTH:
1765 LyXLength const vallen(value);
1766 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1768 bool const update = (tmplen != vallen);
1769 tabular->SetColumnPWidth(actcell, vallen);
1772 for (int i = 0; i < tabular->rows(); ++i) {
1773 cell = tabular->GetCellNumber(i,column);
1774 tabular->GetCellInset(cell)->resizeLyXText(bv);
1776 updateLocal(bv, INIT);
1780 && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1781 tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
1782 else if (!vallen.zero()
1783 && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1784 tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
1787 case LyXTabular::SET_MPWIDTH:
1789 LyXLength const vallen(value);
1790 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1792 bool const update = (tmplen != vallen);
1793 tabular->SetMColumnPWidth(actcell, vallen);
1795 for (int i = 0; i < tabular->rows(); ++i) {
1796 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1799 updateLocal(bv, INIT);
1803 case LyXTabular::SET_SPECIAL_COLUMN:
1804 case LyXTabular::SET_SPECIAL_MULTI:
1805 tabular->SetAlignSpecial(actcell,value,feature);
1806 updateLocal(bv, FULL);
1808 case LyXTabular::APPEND_ROW:
1809 // append the row into the tabular
1810 unlockInsetInInset(bv, the_locking_inset);
1811 tabular->AppendRow(bv->buffer()->params, actcell);
1812 updateLocal(bv, INIT);
1814 case LyXTabular::APPEND_COLUMN:
1815 // append the column into the tabular
1816 unlockInsetInInset(bv, the_locking_inset);
1817 tabular->AppendColumn(bv->buffer()->params, actcell);
1818 actcell = tabular->GetCellNumber(row, column);
1819 updateLocal(bv, INIT);
1821 case LyXTabular::DELETE_ROW:
1822 unlockInsetInInset(bv, the_locking_inset);
1823 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1824 tabular->DeleteRow(sel_row_start);
1826 if (sel_row_start >= tabular->rows())
1828 actcell = tabular->GetCellNumber(sel_row_start, column);
1830 updateLocal(bv, INIT);
1832 case LyXTabular::DELETE_COLUMN:
1833 unlockInsetInInset(bv, the_locking_inset);
1834 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1835 tabular->DeleteColumn(sel_col_start);
1837 if (sel_col_start >= tabular->columns())
1839 actcell = tabular->GetCellNumber(row, sel_col_start);
1841 updateLocal(bv, INIT);
1843 case LyXTabular::M_TOGGLE_LINE_TOP:
1845 case LyXTabular::TOGGLE_LINE_TOP:
1847 bool lineSet = !tabular->TopLine(actcell, flag);
1848 for (int i = sel_row_start; i <= sel_row_end; ++i)
1849 for (int j = sel_col_start; j <= sel_col_end; ++j)
1850 tabular->SetTopLine(
1851 tabular->GetCellNumber(i, j),
1853 updateLocal(bv, INIT);
1857 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1859 case LyXTabular::TOGGLE_LINE_BOTTOM:
1861 bool lineSet = !tabular->BottomLine(actcell, flag);
1862 for (int i = sel_row_start; i <= sel_row_end; ++i)
1863 for (int j = sel_col_start; j <= sel_col_end; ++j)
1864 tabular->SetBottomLine(
1865 tabular->GetCellNumber(i, j),
1868 updateLocal(bv, INIT);
1872 case LyXTabular::M_TOGGLE_LINE_LEFT:
1874 case LyXTabular::TOGGLE_LINE_LEFT:
1876 bool lineSet = !tabular->LeftLine(actcell, flag);
1877 for (int i = sel_row_start; i <= sel_row_end; ++i)
1878 for (int j = sel_col_start; j <= sel_col_end; ++j)
1879 tabular->SetLeftLine(
1880 tabular->GetCellNumber(i,j),
1883 updateLocal(bv, INIT);
1887 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1889 case LyXTabular::TOGGLE_LINE_RIGHT:
1891 bool lineSet = !tabular->RightLine(actcell, flag);
1892 for (int i = sel_row_start; i <= sel_row_end; ++i)
1893 for (int j = sel_col_start; j <= sel_col_end; ++j)
1894 tabular->SetRightLine(
1895 tabular->GetCellNumber(i,j),
1898 updateLocal(bv, INIT);
1902 case LyXTabular::M_ALIGN_LEFT:
1903 case LyXTabular::M_ALIGN_RIGHT:
1904 case LyXTabular::M_ALIGN_CENTER:
1906 case LyXTabular::ALIGN_LEFT:
1907 case LyXTabular::ALIGN_RIGHT:
1908 case LyXTabular::ALIGN_CENTER:
1909 case LyXTabular::ALIGN_BLOCK:
1910 for (int i = sel_row_start; i <= sel_row_end; ++i)
1911 for (int j = sel_col_start; j <= sel_col_end; ++j)
1912 tabular->SetAlignment(
1913 tabular->GetCellNumber(i, j),
1916 updateLocal(bv, INIT);
1918 case LyXTabular::M_VALIGN_TOP:
1919 case LyXTabular::M_VALIGN_BOTTOM:
1920 case LyXTabular::M_VALIGN_CENTER:
1922 case LyXTabular::VALIGN_TOP:
1923 case LyXTabular::VALIGN_BOTTOM:
1924 case LyXTabular::VALIGN_CENTER:
1925 for (int i = sel_row_start; i <= sel_row_end; ++i)
1926 for (int j = sel_col_start; j <= sel_col_end; ++j)
1927 tabular->SetVAlignment(
1928 tabular->GetCellNumber(i, j),
1930 updateLocal(bv, INIT);
1932 case LyXTabular::MULTICOLUMN:
1934 if (sel_row_start != sel_row_end) {
1935 #ifdef WITH_WARNINGS
1936 #warning Need I say it ? This is horrible.
1938 Alert::error(_("Error setting multicolumn"),
1939 _("You cannot set multicolumn vertically."));
1942 // just multicol for one Single Cell
1943 if (!hasSelection()) {
1944 // check wether we are completly in a multicol
1945 if (tabular->IsMultiColumn(actcell)) {
1946 tabular->UnsetMultiColumn(actcell);
1947 updateLocal(bv, INIT);
1949 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
1950 updateLocal(bv, CELL);
1954 // we have a selection so this means we just add all this
1955 // cells to form a multicolumn cell
1959 if (sel_cell_start > sel_cell_end) {
1960 s_start = sel_cell_end;
1961 s_end = sel_cell_start;
1963 s_start = sel_cell_start;
1964 s_end = sel_cell_end;
1966 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
1969 updateLocal(bv, INIT);
1972 case LyXTabular::SET_ALL_LINES:
1974 case LyXTabular::UNSET_ALL_LINES:
1975 for (int i = sel_row_start; i <= sel_row_end; ++i)
1976 for (int j = sel_col_start; j <= sel_col_end; ++j)
1977 tabular->SetAllLines(
1978 tabular->GetCellNumber(i,j), setLines);
1979 updateLocal(bv, INIT);
1981 case LyXTabular::SET_LONGTABULAR:
1982 tabular->SetLongTabular(true);
1983 updateLocal(bv, INIT); // because this toggles displayed
1985 case LyXTabular::UNSET_LONGTABULAR:
1986 tabular->SetLongTabular(false);
1987 updateLocal(bv, INIT); // because this toggles displayed
1989 case LyXTabular::SET_ROTATE_TABULAR:
1990 tabular->SetRotateTabular(true);
1992 case LyXTabular::UNSET_ROTATE_TABULAR:
1993 tabular->SetRotateTabular(false);
1995 case LyXTabular::SET_ROTATE_CELL:
1996 for (int i = sel_row_start; i <= sel_row_end; ++i)
1997 for (int j = sel_col_start; j<=sel_col_end; ++j)
1998 tabular->SetRotateCell(
1999 tabular->GetCellNumber(i, j),
2002 case LyXTabular::UNSET_ROTATE_CELL:
2003 for (int i = sel_row_start; i <= sel_row_end; ++i)
2004 for (int j = sel_col_start; j <= sel_col_end; ++j)
2005 tabular->SetRotateCell(
2006 tabular->GetCellNumber(i, j), false);
2008 case LyXTabular::SET_USEBOX:
2010 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2011 if (val == tabular->GetUsebox(actcell))
2012 val = LyXTabular::BOX_NONE;
2013 for (int i = sel_row_start; i <= sel_row_end; ++i)
2014 for (int j = sel_col_start; j <= sel_col_end; ++j)
2016 tabular->GetCellNumber(i, j), val);
2019 case LyXTabular::UNSET_LTFIRSTHEAD:
2021 case LyXTabular::SET_LTFIRSTHEAD:
2022 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2023 checkLongtableSpecial(ltt, value, flag);
2024 tabular->SetLTHead(row, flag, ltt, true);
2026 case LyXTabular::UNSET_LTHEAD:
2028 case LyXTabular::SET_LTHEAD:
2029 (void)tabular->GetRowOfLTHead(row, ltt);
2030 checkLongtableSpecial(ltt, value, flag);
2031 tabular->SetLTHead(row, flag, ltt, false);
2033 case LyXTabular::UNSET_LTFOOT:
2035 case LyXTabular::SET_LTFOOT:
2036 (void)tabular->GetRowOfLTFoot(row, ltt);
2037 checkLongtableSpecial(ltt, value, flag);
2038 tabular->SetLTFoot(row, flag, ltt, false);
2040 case LyXTabular::UNSET_LTLASTFOOT:
2042 case LyXTabular::SET_LTLASTFOOT:
2043 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2044 checkLongtableSpecial(ltt, value, flag);
2045 tabular->SetLTFoot(row, flag, ltt, true);
2047 case LyXTabular::SET_LTNEWPAGE:
2049 bool what = !tabular->GetLTNewPage(row);
2050 tabular->SetLTNewPage(row, what);
2053 // dummy stuff just to avoid warnings
2054 case LyXTabular::LAST_ACTION:
2058 InsetTabularMailer mailer(*this);
2059 mailer.updateDialog(bv);
2063 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2066 UpdatableInset * inset =
2067 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2068 LyXFont font(LyXFont::ALL_SANE);
2070 x = inset->x() + inset->width(bv, font);
2071 y = inset->descent(bv, font);
2073 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2074 //inset_y = cursor.y();
2075 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
2076 if (!the_locking_inset)
2078 updateLocal(bv, CELL);
2079 return (the_locking_inset != 0);
2083 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2084 mouse_button::state button)
2086 inset_x = cursor_.x()
2087 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2088 inset_y = cursor_.y();
2089 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2093 bool InsetTabular::insetHit(BufferView *, int x, int) const
2096 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2100 // This returns paperWidth() if the cell-width is unlimited or the width
2101 // in pixels if we have a pwidth for this cell.
2102 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2104 LyXLength const len = tabular->GetPWidth(cell);
2108 return len.inPixels(latexTextWidth(bv));
2112 int InsetTabular::getMaxWidth(BufferView * bv,
2113 UpdatableInset const * inset) const
2115 int cell = tabular->GetCellFromInset(inset, actcell);
2118 lyxerr << "Own inset not found, shouldn't really happen!"
2123 int w = getMaxWidthOfCell(bv, cell);
2125 // because the inset then subtracts it's top_x and owner->x()
2126 w += (inset->x() - top_x);
2133 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2135 resizeLyXText(bv, recursive);
2139 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2142 for(int i = 0; i < tabular->rows(); ++i) {
2143 for(int j = 0; j < tabular->columns(); ++j) {
2144 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2152 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2153 bool const recursive) const
2155 if (the_locking_inset)
2156 return the_locking_inset->getLyXText(bv, recursive);
2158 // if we're locked lock the actual insettext and return it's LyXText!!!
2160 UpdatableInset * inset =
2161 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2162 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2163 return the_locking_inset->getLyXText(bv, recursive);
2166 return Inset::getLyXText(bv, recursive);
2170 bool InsetTabular::showInsetDialog(BufferView * bv) const
2172 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv)) {
2173 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2174 InsetTabularMailer mailer(*tmp);
2175 mailer.showDialog(bv);
2181 void InsetTabular::openLayoutDialog(BufferView * bv) const
2183 if (the_locking_inset) {
2184 InsetTabular * i = static_cast<InsetTabular *>
2185 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2187 i->openLayoutDialog(bv);
2191 InsetTabular * tmp = const_cast<InsetTabular *>(this);
2192 InsetTabularMailer mailer(*tmp);
2193 mailer.showDialog(bv);
2198 // function returns an object as defined in func_status.h:
2199 // states OK, Unknown, Disabled, On, Off.
2201 FuncStatus InsetTabular::getStatus(string const & what) const
2203 int action = LyXTabular::LAST_ACTION;
2207 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2208 string const tmp = tabularFeature[i].feature;
2209 if (tmp == what.substr(0, tmp.length())) {
2210 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2211 // tabularFeatures[i].feature.length())) {
2212 action = tabularFeature[i].action;
2216 if (action == LyXTabular::LAST_ACTION) {
2218 return status.unknown(true);
2221 string const argument = ltrim(what.substr(tabularFeature[i].feature.length()));
2226 LyXTabular::ltType dummyltt;
2229 if (hasSelection()) {
2230 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2232 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2236 case LyXTabular::SET_PWIDTH:
2237 case LyXTabular::SET_MPWIDTH:
2238 case LyXTabular::SET_SPECIAL_COLUMN:
2239 case LyXTabular::SET_SPECIAL_MULTI:
2240 case LyXTabular::APPEND_ROW:
2241 case LyXTabular::APPEND_COLUMN:
2242 case LyXTabular::DELETE_ROW:
2243 case LyXTabular::DELETE_COLUMN:
2244 case LyXTabular::SET_ALL_LINES:
2245 case LyXTabular::UNSET_ALL_LINES:
2246 return status.clear();
2248 case LyXTabular::MULTICOLUMN:
2249 status.setOnOff(tabular->IsMultiColumn(actcell));
2251 case LyXTabular::M_TOGGLE_LINE_TOP:
2253 case LyXTabular::TOGGLE_LINE_TOP:
2254 status.setOnOff(tabular->TopLine(actcell, flag));
2256 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2258 case LyXTabular::TOGGLE_LINE_BOTTOM:
2259 status.setOnOff(tabular->BottomLine(actcell, flag));
2261 case LyXTabular::M_TOGGLE_LINE_LEFT:
2263 case LyXTabular::TOGGLE_LINE_LEFT:
2264 status.setOnOff(tabular->LeftLine(actcell, flag));
2266 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2268 case LyXTabular::TOGGLE_LINE_RIGHT:
2269 status.setOnOff(tabular->RightLine(actcell, flag));
2271 case LyXTabular::M_ALIGN_LEFT:
2273 case LyXTabular::ALIGN_LEFT:
2274 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2276 case LyXTabular::M_ALIGN_RIGHT:
2278 case LyXTabular::ALIGN_RIGHT:
2279 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2281 case LyXTabular::M_ALIGN_CENTER:
2283 case LyXTabular::ALIGN_CENTER:
2284 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2286 case LyXTabular::ALIGN_BLOCK:
2287 status.disabled(tabular->GetPWidth(actcell).zero());
2288 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
2290 case LyXTabular::M_VALIGN_TOP:
2292 case LyXTabular::VALIGN_TOP:
2293 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2295 case LyXTabular::M_VALIGN_BOTTOM:
2297 case LyXTabular::VALIGN_BOTTOM:
2298 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2300 case LyXTabular::M_VALIGN_CENTER:
2302 case LyXTabular::VALIGN_CENTER:
2303 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2305 case LyXTabular::SET_LONGTABULAR:
2306 status.setOnOff(tabular->IsLongTabular());
2308 case LyXTabular::UNSET_LONGTABULAR:
2309 status.setOnOff(!tabular->IsLongTabular());
2311 case LyXTabular::SET_ROTATE_TABULAR:
2312 status.setOnOff(tabular->GetRotateTabular());
2314 case LyXTabular::UNSET_ROTATE_TABULAR:
2315 status.setOnOff(!tabular->GetRotateTabular());
2317 case LyXTabular::SET_ROTATE_CELL:
2318 status.setOnOff(tabular->GetRotateCell(actcell));
2320 case LyXTabular::UNSET_ROTATE_CELL:
2321 status.setOnOff(!tabular->GetRotateCell(actcell));
2323 case LyXTabular::SET_USEBOX:
2324 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2326 case LyXTabular::SET_LTFIRSTHEAD:
2327 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2329 case LyXTabular::SET_LTHEAD:
2330 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2332 case LyXTabular::SET_LTFOOT:
2333 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2335 case LyXTabular::SET_LTLASTFOOT:
2336 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2338 case LyXTabular::SET_LTNEWPAGE:
2339 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2343 status.disabled(true);
2350 vector<string> const InsetTabular::getLabelList() const
2352 return tabular->getLabelList();
2356 bool InsetTabular::copySelection(BufferView * bv)
2358 if (!hasSelection())
2361 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2362 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2363 if (sel_col_start > sel_col_end) {
2364 sel_col_start = sel_col_end;
2365 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2367 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2369 int const columns = sel_col_end - sel_col_start + 1;
2371 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2372 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2373 if (sel_row_start > sel_row_end) {
2374 swap(sel_row_start, sel_row_end);
2376 int const rows = sel_row_end - sel_row_start + 1;
2378 delete paste_tabular;
2379 paste_tabular = new LyXTabular(bv->buffer()->params,
2380 this, *tabular); // rows, columns);
2381 for (int i = 0; i < sel_row_start; ++i)
2382 paste_tabular->DeleteRow(0);
2383 while (paste_tabular->rows() > rows)
2384 paste_tabular->DeleteRow(rows);
2385 paste_tabular->SetTopLine(0, true, true);
2386 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2388 for (int i = 0; i < sel_col_start; ++i)
2389 paste_tabular->DeleteColumn(0);
2390 while (paste_tabular->columns() > columns)
2391 paste_tabular->DeleteColumn(columns);
2392 paste_tabular->SetLeftLine(0, true, true);
2393 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2397 paste_tabular->ascii(bv->buffer(), sstr,
2398 (int)parOwner()->params().depth(), true, '\t');
2399 bv->stuffClipboard(STRCONV(sstr.str()));
2404 bool InsetTabular::pasteSelection(BufferView * bv)
2409 for (int r1 = 0, r2 = actrow;
2410 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2412 for(int c1 = 0, c2 = actcol;
2413 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2415 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2416 tabular->IsPartOfMultiColumn(r2,c2))
2418 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2422 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2426 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2427 int const n2 = tabular->GetCellNumber(r2, c2);
2428 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2429 tabular->GetCellInset(n2)->setOwner(this);
2430 tabular->GetCellInset(n2)->deleteLyXText(bv);
2431 tabular->GetCellInset(n2)->markNew();
2438 bool InsetTabular::cutSelection(BufferParams const & bp)
2440 if (!hasSelection())
2443 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2444 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2445 if (sel_col_start > sel_col_end) {
2446 sel_col_start = sel_col_end;
2447 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2449 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2451 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2452 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2453 if (sel_row_start > sel_row_end) {
2454 swap(sel_row_start, sel_row_end);
2456 if (sel_cell_start > sel_cell_end) {
2457 swap(sel_cell_start, sel_cell_end);
2459 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2460 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2461 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear(bp.tracking_changes);
2468 bool InsetTabular::isRightToLeft(BufferView * bv)
2470 return bv->getParentLanguage(this)->RightToLeft();
2474 bool InsetTabular::nodraw() const
2476 if (!UpdatableInset::nodraw() && the_locking_inset)
2477 return the_locking_inset->nodraw();
2478 return UpdatableInset::nodraw();
2482 int InsetTabular::scroll(bool recursive) const
2484 int sx = UpdatableInset::scroll(false);
2486 if (recursive && the_locking_inset)
2487 sx += the_locking_inset->scroll(recursive);
2493 void InsetTabular::getSelection(int & srow, int & erow,
2494 int & scol, int & ecol) const
2496 int const start = hasSelection() ? sel_cell_start : actcell;
2497 int const end = hasSelection() ? sel_cell_end : actcell;
2499 srow = tabular->row_of_cell(start);
2500 erow = tabular->row_of_cell(end);
2505 scol = tabular->column_of_cell(start);
2506 ecol = tabular->column_of_cell(end);
2510 ecol = tabular->right_column_of_cell(end);
2515 ParagraphList * InsetTabular::getParagraphs(int i) const
2517 return (i < tabular->GetNumberOfCells())
2518 ? tabular->GetCellInset(i)->getParagraphs(0)
2523 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2525 if (the_locking_inset)
2526 return the_locking_inset->cursor(bv);
2527 return Inset::cursor(bv);
2531 Inset * InsetTabular::getInsetFromID(int id_arg) const
2534 return const_cast<InsetTabular *>(this);
2537 for(int i = 0; i < tabular->rows(); ++i) {
2538 for(int j = 0; j < tabular->columns(); ++j) {
2539 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2548 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2551 if (the_locking_inset) {
2552 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2553 if (!word.word().empty()) {
2557 if (tabular->IsLastCell(actcell)) {
2558 bv->unlockInset(const_cast<InsetTabular *>(this));
2560 return WordLangTuple();
2564 // otherwise we have to lock the next inset and ask for it's selecttion
2565 UpdatableInset * inset =
2566 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2567 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2568 WordLangTuple word(selectNextWordInt(bv, value));
2570 if (!word.word().empty())
2576 WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2578 // when entering this function the inset should be ALWAYS locked!
2579 lyx::Assert(the_locking_inset);
2581 WordLangTuple word(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2582 if (!word.word().empty())
2585 if (tabular->IsLastCell(actcell)) {
2586 bv->unlockInset(const_cast<InsetTabular *>(this));
2587 return WordLangTuple();
2590 // otherwise we have to lock the next inset and ask for it's selecttion
2591 UpdatableInset * inset =
2592 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2593 inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
2594 return selectNextWordInt(bv, value);
2598 void InsetTabular::selectSelectedWord(BufferView * bv)
2600 if (the_locking_inset) {
2601 the_locking_inset->selectSelectedWord(bv);
2608 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2610 if (the_locking_inset) {
2611 the_locking_inset->toggleSelection(bv, kill_selection);
2616 void InsetTabular::markErased()
2620 while (!tabular->IsLastCell(cell)) {
2622 InsetText * inset = tabular->GetCellInset(cell);
2623 inset->markErased();
2628 bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
2630 if (the_locking_inset) {
2631 if (the_locking_inset->nextChange(bv, length)) {
2632 updateLocal(bv, CELL);
2635 if (tabular->IsLastCell(actcell))
2639 InsetText * inset = tabular->GetCellInset(actcell);
2640 if (inset->nextChange(bv, length)) {
2641 updateLocal(bv, FULL);
2644 while (!tabular->IsLastCell(actcell)) {
2646 inset = tabular->GetCellInset(actcell);
2647 if (inset->nextChange(bv, length)) {
2648 updateLocal(bv, FULL);
2656 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2660 if (the_locking_inset) {
2661 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2662 updateLocal(bv, CELL);
2665 if (tabular->IsLastCell(actcell))
2669 InsetText * inset = tabular->GetCellInset(cell);
2670 if (inset->searchForward(bv, str, cs, mw)) {
2671 updateLocal(bv, FULL);
2674 while (!tabular->IsLastCell(cell)) {
2676 inset = tabular->GetCellInset(cell);
2677 if (inset->searchForward(bv, str, cs, mw)) {
2678 updateLocal(bv, FULL);
2686 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2689 int cell = tabular->GetNumberOfCells();
2690 if (the_locking_inset) {
2691 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2692 updateLocal(bv, CELL);
2700 InsetText * inset = tabular->GetCellInset(cell);
2701 if (inset->searchBackward(bv, str, cs, mw)) {
2702 updateLocal(bv, CELL);
2710 bool InsetTabular::insetAllowed(Inset::Code code) const
2712 if (the_locking_inset)
2713 return the_locking_inset->insetAllowed(code);
2714 // we return true here because if the inset is not locked someone
2715 // wants to insert something in one of our insettexts and we generally
2721 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2723 const int cell = tabular->GetCellFromInset(in, actcell);
2726 return tabular->GetPWidth(cell).zero();
2728 // well we didn't obviously find it so maybe our owner knows more
2730 return owner()->forceDefaultParagraphs(in);
2731 // if we're here there is really something strange going on!!!
2735 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2738 if (buf.length() <= 0)
2744 string::size_type len = buf.length();
2745 string::size_type p = 0;
2748 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2757 maxCols = max(cols, maxCols);
2763 maxCols = max(cols, maxCols);
2764 LyXTabular * loctab;
2769 delete paste_tabular;
2770 paste_tabular = new LyXTabular(bv->buffer()->params,
2771 this, rows, maxCols);
2772 loctab = paste_tabular;
2775 loctab = tabular.get();
2781 string::size_type op = 0;
2782 int cells = loctab->GetNumberOfCells();
2785 rows = loctab->rows();
2786 int const columns = loctab->columns();
2788 while ((cell < cells) && (p < len) && (row < rows) &&
2789 (p = buf.find_first_of("\t\n", p)) != string::npos)
2795 // we can only set this if we are not too far right
2796 if (cols < columns) {
2797 InsetText * ti = loctab->GetCellInset(cell);
2798 LyXFont const font = ti->getLyXText(bv)->
2799 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2800 ti->setText(buf.substr(op, p - op), font);
2806 // we can only set this if we are not too far right
2807 if (cols < columns) {
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, p - op), font);
2816 cell = loctab->GetCellNumber(row, cols);
2822 // check for the last cell if there is no trailing '\n'
2823 if ((cell < cells) && (op < len)) {
2824 InsetText * ti = loctab->GetCellInset(cell);
2825 LyXFont const font = ti->getLyXText(bv)->
2826 getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
2827 ti->setText(buf.substr(op, len - op), font);
2834 void InsetTabular::addPreview(grfx::PreviewLoader & loader) const
2836 int const rows = tabular->rows();
2837 int const columns = tabular->columns();
2838 for (int i = 0; i < rows; ++i) {
2839 for (int j = 0; j < columns; ++j) {
2840 tabular->GetCellInset(i,j)->addPreview(loader);
2846 string const InsetTabularMailer:: name_("tabular");
2848 InsetTabularMailer::InsetTabularMailer(InsetTabular & inset)
2853 string const InsetTabularMailer::inset2string() const
2855 return params2string(inset_);
2859 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
2861 istringstream data(STRCONV(in));
2863 lex.setStream(data);
2865 #warning CHECK verify that this is a sane value to return.
2871 string const token = lex.getString();
2879 string const token = lex.getString();
2880 if (token != "\\active_cell")
2883 cell = lex.getInteger();
2886 // This is part of the inset proper that is usually swallowed
2887 // by Buffer::readInset
2890 string const token = lex.getString();
2891 if (token != "Tabular")
2898 BufferView * const bv = inset.view();
2899 Buffer const * const buffer = bv ? bv->buffer() : 0;
2901 inset.read(buffer, lex);
2903 // We can't set the active cell, but we can tell the frontend
2909 string const InsetTabularMailer::params2string(InsetTabular const & inset)
2911 BufferView * const bv = inset.view();
2912 Buffer const * const buffer = bv ? bv->buffer() : 0;
2917 data << name_ << " \\active_cell " << inset.getActCell() << '\n';
2918 inset.write(buffer, data);
2919 data << "\\end_inset\n";
2920 return STRCONV(data.str());