1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
41 #include "BufferView.h"
42 #include "undo_funcs.h"
43 #include "support/LAssert.h"
44 #include "support/lstrings.h"
55 const int ADD_TO_HEIGHT = 2;
56 const int ADD_TO_TABULAR_WIDTH = 2;
58 LyXTabular * paste_tabular = 0;
61 struct TabularFeature {
62 LyXTabular::Feature action;
66 //tabular_features * tabularFeatures = 0;
68 TabularFeature tabularFeature[] =
70 { LyXTabular::APPEND_ROW, "append-row" },
71 { LyXTabular::APPEND_COLUMN, "append-column" },
72 { LyXTabular::DELETE_ROW, "delete-row" },
73 { LyXTabular::DELETE_COLUMN, "delete-column" },
74 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
75 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
76 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
77 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
78 { LyXTabular::ALIGN_LEFT, "align-left" },
79 { LyXTabular::ALIGN_RIGHT, "align-right" },
80 { LyXTabular::ALIGN_CENTER, "align-center" },
81 { LyXTabular::VALIGN_TOP, "valign-top" },
82 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
83 { LyXTabular::VALIGN_CENTER, "valign-center" },
84 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
85 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
86 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
87 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
88 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
89 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
90 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
91 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
92 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
93 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
94 { LyXTabular::MULTICOLUMN, "multicolumn" },
95 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
96 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
97 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
98 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
99 { LyXTabular::SET_PWIDTH, "set-pwidth" },
100 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
101 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
102 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
103 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
104 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
105 { LyXTabular::SET_USEBOX, "set-usebox" },
106 { LyXTabular::SET_LTHEAD, "set-lthead" },
107 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
108 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
109 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
110 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
111 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
112 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
113 { LyXTabular::LAST_ACTION, "" }
119 bool InsetTabular::hasPasteBuffer() const
121 return (paste_tabular != 0);
125 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
132 tabular.reset(new LyXTabular(this, rows, columns));
133 // for now make it always display as display() inset
135 the_locking_inset = 0;
136 locked = no_selection = false;
138 actrow = actcell = 0;
145 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
147 : UpdatableInset(tab, same_id), buffer(&buf)
149 tabular.reset(new LyXTabular(this, *(tab.tabular)));
150 the_locking_inset = 0;
151 locked = no_selection = false;
153 actrow = actcell = 0;
154 sel_cell_start = sel_cell_end = 0;
160 InsetTabular::~InsetTabular()
166 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
168 return new InsetTabular(*this, buf, same_id);
172 void InsetTabular::write(Buffer const * buf, ostream & os) const
174 os << " Tabular" << endl;
175 tabular->Write(buf, os);
179 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
181 bool const old_format = (lex.getString() == "\\LyXTable");
185 //tabular = new LyXTabular(buf, this, lex);
186 tabular.reset(new LyXTabular(buf, this, lex));
194 string token = lex.getString();
195 while (lex.isOK() && (token != "\\end_inset")) {
197 token = lex.getString();
199 if (token != "\\end_inset") {
200 lex.printError("Missing \\end_inset at this point. "
206 int InsetTabular::ascent(BufferView *, LyXFont const &) const
208 return tabular->GetAscentOfRow(0);
212 int InsetTabular::descent(BufferView *, LyXFont const &) const
214 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
218 int InsetTabular::width(BufferView *, LyXFont const &) const
220 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
224 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
225 float & x, bool cleared) const
233 if (need_update == INIT) {
234 if (calculate_dimensions_of_cells(bv, font, true))
235 bv->text->status = LyXText::CHANGED_IN_DRAW;
240 Painter & pain = bv->painter();
246 UpdatableInset::draw(bv, font, baseline, x, cleared);
249 x += static_cast<float>(scroll());
251 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
252 (top_x != int(x)) || (top_baseline != baseline)))
254 int h = ascent(bv, font) + descent(bv, font);
255 int const tx = display() || !owner() ? 0 : top_x;
256 int w = tx ? width(bv, font) : pain.paperWidth();
257 int ty = baseline - ascent(bv, font);
261 if ((ty + h) > pain.paperHeight())
262 h = pain.paperHeight();
263 if ((top_x + w) > pain.paperWidth())
264 w = pain.paperWidth();
265 pain.fillRectangle(tx, ty, w, h, backgroundColor());
271 top_baseline = baseline;
272 x += ADD_TO_TABULAR_WIDTH;
276 first_visible_cell = -1;
277 for (i = 0; i < tabular->rows(); ++i) {
279 cell = tabular->GetCellNumber(i, 0);
280 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
281 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
283 baseline += tabular->GetDescentOfRow(i) +
284 tabular->GetAscentOfRow(i + 1) +
285 tabular->GetAdditionalHeight(i + 1);
288 for (j = 0; j < tabular->columns(); ++j) {
289 if (nx > bv->workWidth())
291 if (tabular->IsPartOfMultiColumn(i, j))
293 cx = nx + tabular->GetBeginningOfTextInCell(cell);
294 if (first_visible_cell < 0)
295 first_visible_cell = cell;
297 drawCellSelection(pain, nx, baseline, i, j, cell);
299 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
301 drawCellLines(pain, nx, baseline, i, cell);
302 nx += tabular->GetWidthOfColumn(cell);
305 baseline += tabular->GetDescentOfRow(i) +
306 tabular->GetAscentOfRow(i + 1) +
307 tabular->GetAdditionalHeight(i + 1);
309 } else if (need_update == CELL) {
312 if (the_locking_inset &&
313 tabular->GetCellInset(actcell) != the_locking_inset)
315 Inset * inset = tabular->GetCellInset(cell);
317 inset != the_locking_inset && i < tabular->rows();
321 inset != the_locking_inset && j < tabular->columns();
324 if (tabular->IsPartOfMultiColumn(i, j))
326 nx += tabular->GetWidthOfColumn(cell);
328 inset = tabular->GetCellInset(cell);
330 if (tabular->row_of_cell(cell) > i) {
332 baseline += tabular->GetDescentOfRow(i) +
333 tabular->GetAscentOfRow(i + 1) +
334 tabular->GetAdditionalHeight(i + 1);
338 // compute baseline for actual row
339 for (i = 0; i < actrow; ++i) {
340 baseline += tabular->GetDescentOfRow(i) +
341 tabular->GetAscentOfRow(i + 1) +
342 tabular->GetAdditionalHeight(i + 1);
344 // now compute the right x position
345 cell = tabular->GetCellNumber(actrow, 0);
346 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
347 if (tabular->IsPartOfMultiColumn(actrow, j))
349 nx += tabular->GetWidthOfColumn(cell);
353 i = tabular->row_of_cell(cell);
354 if (the_locking_inset != tabular->GetCellInset(cell)) {
355 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
358 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
360 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
361 // clear only if we didn't have a change
362 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
363 // clear before the inset
366 baseline - tabular->GetAscentOfRow(i) + 1,
368 tabular->GetAscentOfRow(i) +
369 tabular->GetDescentOfRow(i) - 1,
371 // clear behind the inset
373 int(cx + the_locking_inset->width(bv,font) + 1),
374 baseline - tabular->GetAscentOfRow(i) + 1,
375 tabular->GetWidthOfColumn(cell) -
376 tabular->GetBeginningOfTextInCell(cell) -
377 the_locking_inset->width(bv,font) -
378 tabular->GetAdditionalWidth(cell) - 1,
379 tabular->GetAscentOfRow(i) +
380 tabular->GetDescentOfRow(i) - 1,
382 // clear below the inset
385 baseline + the_locking_inset->descent(bv, font) + 1,
386 tabular->GetWidthOfColumn(cell) -
387 tabular->GetAdditionalWidth(cell) - 1,
388 tabular->GetAscentOfRow(i) +
389 tabular->GetDescentOfRow(i) -
390 the_locking_inset->ascent(bv, font) -
391 the_locking_inset->descent(bv, font) -
392 TEXT_TO_INSET_OFFSET - 1,
396 x -= ADD_TO_TABULAR_WIDTH;
397 x += width(bv, font);
398 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
400 for(Inset * inset=owner(); inset; ++i)
401 inset = inset->owner();
402 if (calculate_dimensions_of_cells(bv, font, false))
410 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
411 int row, int cell) const
413 int x2 = x + tabular->GetWidthOfColumn(cell);
416 if (!tabular->TopAlreadyDrawed(cell)) {
417 on_off = !tabular->TopLine(cell);
418 pain.line(x, baseline - tabular->GetAscentOfRow(row),
419 x2, baseline - tabular->GetAscentOfRow(row),
420 on_off ? LColor::tabularonoffline : LColor::tabularline,
421 on_off ? Painter::line_onoffdash : Painter::line_solid);
423 on_off = !tabular->BottomLine(cell);
424 pain.line(x,baseline + tabular->GetDescentOfRow(row),
425 x2, baseline + tabular->GetDescentOfRow(row),
426 on_off ? LColor::tabularonoffline : LColor::tabularline,
427 on_off ? Painter::line_onoffdash : Painter::line_solid);
428 if (!tabular->LeftAlreadyDrawed(cell)) {
429 on_off = !tabular->LeftLine(cell);
430 pain.line(x, baseline - tabular->GetAscentOfRow(row),
431 x, baseline + tabular->GetDescentOfRow(row),
432 on_off ? LColor::tabularonoffline : LColor::tabularline,
433 on_off ? Painter::line_onoffdash : Painter::line_solid);
435 on_off = !tabular->RightLine(cell);
436 pain.line(x2 - tabular->GetAdditionalWidth(cell),
437 baseline - tabular->GetAscentOfRow(row),
438 x2 - tabular->GetAdditionalWidth(cell),
439 baseline + tabular->GetDescentOfRow(row),
440 on_off ? LColor::tabularonoffline : LColor::tabularline,
441 on_off ? Painter::line_onoffdash : Painter::line_solid);
445 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
446 int row, int column, int cell) const
448 int cs = tabular->column_of_cell(sel_cell_start);
449 int ce = tabular->column_of_cell(sel_cell_end);
452 cs = tabular->column_of_cell(sel_cell_end);
454 ce = tabular->right_column_of_cell(sel_cell_end);
457 int rs = tabular->row_of_cell(sel_cell_start);
458 int re = tabular->row_of_cell(sel_cell_end);
459 if (rs > re) swap(rs, re);
461 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
462 int w = tabular->GetWidthOfColumn(cell);
463 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
464 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
465 w, h, LColor::selection);
470 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
476 owner()->update(bv, font, true);
483 if (calculate_dimensions_of_cells(bv, font, true))
486 owner()->update(bv, font, true);
490 if (the_locking_inset)
491 the_locking_inset->update(bv, font, reinit);
492 if (need_update < FULL &&
493 bv->text->status() == LyXText::NEED_MORE_REFRESH)
498 switch (need_update) {
502 if (calculate_dimensions_of_cells(bv, font, false))
515 string const InsetTabular::editMessage() const
517 return _("Opened Tabular Inset");
521 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
523 UpdatableInset::edit(bv, x, y, button);
525 if (!bv->lockInset(this)) {
526 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
530 the_locking_inset = 0;
534 sel_cell_start = sel_cell_end = actcell;
536 if (insetHit(bv, x, y) && (button != 3)) {
537 activateCellInsetAbs(bv, x, y, button);
542 void InsetTabular::edit(BufferView * bv, bool front)
544 UpdatableInset::edit(bv, front);
546 if (!bv->lockInset(this)) {
547 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
551 the_locking_inset = 0;
557 actcell = tabular->GetNumberOfCells() - 1;
558 sel_cell_start = sel_cell_end = actcell;
564 void InsetTabular::insetUnlock(BufferView * bv)
566 if (the_locking_inset) {
567 the_locking_inset->insetUnlock(bv);
568 the_locking_inset = 0;
571 no_selection = false;
574 if (scroll(false) || hasSelection()) {
575 sel_cell_start = sel_cell_end = 0;
579 updateLocal(bv, FULL, false);
584 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
585 bool mark_dirty) const
587 if (need_update < what) // only set this if it has greater update
589 if ((what == INIT) && hasSelection())
592 if (need_update != NONE) {
593 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
594 if (locked) // && (what != NONE))
600 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
602 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
607 if (inset == tabular->GetCellInset(actcell)) {
608 lyxerr[Debug::INSETS] << "OK" << endl;
609 the_locking_inset = tabular->GetCellInset(actcell);
612 } else if (the_locking_inset && (the_locking_inset == inset)) {
613 lyxerr[Debug::INSETS] << "OK" << endl;
615 } else if (the_locking_inset) {
616 lyxerr[Debug::INSETS] << "MAYBE" << endl;
617 return the_locking_inset->lockInsetInInset(bv, inset);
619 lyxerr[Debug::INSETS] << "NOT OK" << endl;
624 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
627 if (!the_locking_inset)
629 if (the_locking_inset == inset) {
630 the_locking_inset->insetUnlock(bv);
631 the_locking_inset = 0;
633 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
639 updateLocal(bv, CELL, false);
640 showInsetCursor(bv, false);
643 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
644 if (inset->lyxCode() == TABULAR_CODE &&
645 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
646 bv->owner()->getDialogs()->updateTabular(this);
655 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
657 if (!the_locking_inset)
659 if (the_locking_inset != inset) {
660 if (!the_locking_inset->updateInsetInInset(bv, inset))
663 updateLocal(bv, CELL, false);
668 unsigned int InsetTabular::insetInInsetY()
670 if (!the_locking_inset)
673 return inset_y + the_locking_inset->insetInInsetY();
677 UpdatableInset * InsetTabular::getLockingInset() const
679 return the_locking_inset ? the_locking_inset->getLockingInset() :
680 const_cast<InsetTabular *>(this);
684 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
688 if (the_locking_inset)
689 return the_locking_inset->getFirstLockingInsetOfType(c);
694 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
696 if (the_locking_inset)
697 return the_locking_inset->insertInset(bv, inset);
702 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
704 if (hasSelection() && (button == 3))
707 if (hasSelection()) {
709 updateLocal(bv, SELECTION, false);
712 no_selection = false;
714 int const ocell = actcell;
715 int const orow = actrow;
720 updateLocal(bv, NONE, false);
721 sel_cell_start = sel_cell_end = actcell;
723 if ((ocell != actcell) && the_locking_inset) {
724 the_locking_inset->insetUnlock(bv);
725 the_locking_inset = 0;
731 bool const inset_hit = insetHit(bv, x, y);
733 if ((ocell == actcell) && the_locking_inset && inset_hit) {
735 the_locking_inset->insetButtonPress(bv,
736 x - inset_x, y - inset_y,
739 } else if (the_locking_inset) {
740 the_locking_inset->insetUnlock(bv);
742 the_locking_inset = 0;
744 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
747 if (inset_hit && bv->theLockingInset()) {
748 if (activateCellInsetAbs(bv, x, y, button))
749 the_locking_inset->insetButtonPress(bv,
759 void InsetTabular::insetButtonRelease(BufferView * bv,
760 int x, int y, int button)
763 if (the_locking_inset) {
765 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
766 i->insetButtonRelease(bv, x, y, button);
770 bv->owner()->getDialogs()->showTabular(this);
773 if (the_locking_inset) {
774 the_locking_inset->insetButtonRelease(bv,
775 x - inset_x, y - inset_y,
779 no_selection = false;
783 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
785 if (the_locking_inset) {
786 the_locking_inset->insetMotionNotify(bv,
794 int const old_cell = actcell;
797 sel_cell_end = actcell;
798 if (sel_cell_end != old_cell)
799 updateLocal(bv, SELECTION, false);
802 no_selection = false;
806 void InsetTabular::insetKeyPress(XKeyEvent * xke)
808 if (the_locking_inset) {
809 the_locking_inset->insetKeyPress(xke);
815 UpdatableInset::RESULT
816 InsetTabular::localDispatch(BufferView * bv, kb_action action,
819 // We need to save the value of the_locking_inset as the call to
820 // the_locking_inset->LocalDispatch might unlock it.
821 old_locking_inset = the_locking_inset;
822 no_selection = false;
823 UpdatableInset::RESULT result =
824 UpdatableInset::localDispatch(bv, action, arg);
825 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
830 if ((action < 0) && arg.empty())
833 bool hs = hasSelection();
836 // this one have priority over the locked InsetText, if we're not already
837 // inside another tabular then that one get's priority!
838 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
843 if (the_locking_inset) {
844 unlockInsetInInset(bv, the_locking_inset);
845 the_locking_inset = 0;
847 if (action == LFUN_TAB)
848 moveNextCell(bv, old_locking_inset != 0);
850 movePrevCell(bv, old_locking_inset != 0);
851 sel_cell_start = sel_cell_end = actcell;
853 updateLocal(bv, SELECTION, false);
854 if (!the_locking_inset) {
856 return DISPATCHED_NOUPDATE;
859 // this to avoid compiler warnings.
865 if (the_locking_inset) {
866 result = the_locking_inset->localDispatch(bv, action, arg);
867 if (result == DISPATCHED_NOUPDATE) {
870 if (sc != scroll()) { // inset has been scrolled
871 the_locking_inset->toggleInsetCursor(bv);
872 updateLocal(bv, FULL, false);
873 the_locking_inset->toggleInsetCursor(bv);
876 } else if (result == DISPATCHED) {
877 the_locking_inset->toggleInsetCursor(bv);
878 updateLocal(bv, CELL, false);
879 the_locking_inset->toggleInsetCursor(bv);
881 } else if (result == FINISHED_UP) {
883 } else if (result == FINISHED_DOWN) {
885 } else if (result == FINISHED_RIGHT) {
893 // --- Cursor Movements ----------------------------------
895 if (tabular->IsLastCellInRow(actcell))
897 moveRight(bv, false);
898 sel_cell_end = actcell;
899 updateLocal(bv, SELECTION, false);
902 result = moveRight(bv);
903 sel_cell_start = sel_cell_end = actcell;
905 updateLocal(bv, SELECTION, false);
908 if (tabular->IsFirstCellInRow(actcell))
911 sel_cell_end = actcell;
912 updateLocal(bv, SELECTION, false);
915 result = moveLeft(bv);
916 sel_cell_start = sel_cell_end = actcell;
918 updateLocal(bv, SELECTION, false);
922 int const ocell = actcell;
924 if ((ocell == sel_cell_end) ||
925 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
926 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
928 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
929 updateLocal(bv, SELECTION, false);
933 result = moveDown(bv, old_locking_inset != 0);
934 sel_cell_start = sel_cell_end = actcell;
936 updateLocal(bv, SELECTION, false);
940 int const ocell = actcell;
942 if ((ocell == sel_cell_end) ||
943 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
944 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
946 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
947 updateLocal(bv, SELECTION, false);
951 result = moveUp(bv, old_locking_inset != 0);
952 sel_cell_start = sel_cell_end = actcell;
954 updateLocal(bv, SELECTION, false);
958 if (the_locking_inset) {
959 unlockInsetInInset(bv, the_locking_inset);
960 the_locking_inset = 0;
962 if (bv->text->first + bv->painter().paperHeight() <
963 (top_baseline + tabular->GetHeightOfTabular()))
965 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
966 updateLocal(bv, FULL, false);
967 actcell = tabular->GetCellBelow(first_visible_cell) + column;
969 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
972 updateLocal(bv, CURSOR, false);
977 if (the_locking_inset) {
978 unlockInsetInInset(bv, the_locking_inset);
979 the_locking_inset = 0;
981 if (top_baseline < 0) {
982 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
983 updateLocal(bv, FULL, false);
984 if (top_baseline > 0)
987 actcell = tabular->GetCellBelow(first_visible_cell) + column;
992 updateLocal(bv, CURSOR, false);
1003 case LFUN_LAYOUT_TABULAR:
1005 bv->owner()->getDialogs()->showTabular(this);
1008 case LFUN_TABULAR_FEATURE:
1009 if (!tabularFeatures(bv, arg))
1010 result = UNDISPATCHED;
1013 if (!copySelection(bv))
1015 setUndo(bv, Undo::DELETE,
1016 bv->text->cursor.par(),
1017 bv->text->cursor.par()->next());
1019 updateLocal(bv, INIT, true);
1022 if (!hasSelection())
1027 case LFUN_PASTESELECTION:
1029 string const clip(bv->getClipboard());
1033 if (clip.find('\t') != string::npos) {
1037 string::size_type len = clip.length();
1038 string::size_type p = 0;
1041 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1049 maxCols = max(cols, maxCols);
1055 maxCols = max(cols, maxCols);
1056 delete paste_tabular;
1057 paste_tabular = new LyXTabular(this, rows, maxCols);
1058 string::size_type op = 0;
1060 int cells = paste_tabular->GetNumberOfCells();
1062 while((cell < cells) && (p < len) &&
1063 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1068 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1073 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1074 while(cols++ < maxCols)
1082 // check for the last cell if there is no trailing '\n'
1083 if ((cell < cells) && (op < len))
1084 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1086 // so that the clipboard is used and it goes on
1088 // and executes LFUN_PASTESELECTION in insettext!
1089 delete paste_tabular;
1094 if (hasPasteBuffer()) {
1095 setUndo(bv, Undo::INSERT,
1096 bv->text->cursor.par(),
1097 bv->text->cursor.par()->next());
1099 updateLocal(bv, INIT, true);
1102 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1104 // we try to activate the actual inset and put this event down to
1105 // the insets dispatch function.
1106 result = UNDISPATCHED;
1107 if (the_locking_inset)
1110 if (activateCellInset(bv)) {
1111 // reset need_update setted in above function!
1113 result = the_locking_inset->localDispatch(bv, action, arg);
1114 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1115 unlockInsetInInset(bv, the_locking_inset);
1117 the_locking_inset = 0;
1118 // we need to update if this was requested before
1119 updateLocal(bv, NONE, false);
1120 return UNDISPATCHED;
1125 updateLocal(bv, CELL, false);
1130 if (result < FINISHED) {
1131 if (!the_locking_inset) {
1132 showInsetCursor(bv);
1135 bv->unlockInset(this);
1140 int InsetTabular::latex(Buffer const * buf, ostream & os,
1141 bool fragile, bool fp) const
1143 return tabular->Latex(buf, os, fragile, fp);
1147 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1149 // This should be changed to a real ascii export
1150 return tabular->Ascii(buf, os);
1154 int InsetTabular::linuxdoc(Buffer const *, ostream &) const
1160 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1162 return tabular->DocBook(buf,os);
1166 void InsetTabular::validate(LaTeXFeatures & features) const
1168 tabular->Validate(features);
1172 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1173 LyXFont const & font,
1180 bool changed = false;
1182 // if we have a locking_inset we should have to check only this cell for
1183 // change so I'll try this to have a boost, but who knows ;)
1184 if ((need_update != INIT) &&
1185 (the_locking_inset == tabular->GetCellInset(actcell))) {
1186 for(int i = 0; i < tabular->columns(); ++i) {
1187 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1189 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1192 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1193 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1194 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1197 for (int i = 0; i < tabular->rows(); ++i) {
1200 for (int j = 0; j < tabular->columns(); ++j) {
1201 if (tabular->IsPartOfMultiColumn(i,j))
1204 inset = tabular->GetCellInset(cell);
1205 if (!reinit && !tabular->GetPWidth(cell).empty())
1206 inset->update(bv, font, false);
1207 maxAsc = max(maxAsc, inset->ascent(bv, font));
1208 maxDesc = max(maxDesc, inset->descent(bv, font));
1209 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1211 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1212 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1218 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1220 if (the_locking_inset) {
1221 the_locking_inset->getCursorPos(bv, x, y);
1224 x = cursor_.x() - top_x;
1229 void InsetTabular::toggleInsetCursor(BufferView * bv)
1231 if (the_locking_inset) {
1232 the_locking_inset->toggleInsetCursor(bv);
1236 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1238 int const asc = lyxfont::maxAscent(font);
1239 int const desc = lyxfont::maxDescent(font);
1241 if (isCursorVisible())
1242 bv->hideLockedInsetCursor();
1244 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1245 toggleCursorVisible();
1249 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1251 if (!isCursorVisible()) {
1252 LyXFont font; // = GetFont(par, cursor.pos);
1254 int const asc = lyxfont::maxAscent(font);
1255 int const desc = lyxfont::maxDescent(font);
1256 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1258 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1259 setCursorVisible(true);
1264 void InsetTabular::hideInsetCursor(BufferView * bv)
1266 if (isCursorVisible()) {
1267 bv->hideLockedInsetCursor();
1268 setCursorVisible(false);
1273 void InsetTabular::fitInsetCursor(BufferView * bv) const
1275 if (the_locking_inset) {
1276 the_locking_inset->fitInsetCursor(bv);
1281 int const asc = lyxfont::maxAscent(font);
1282 int const desc = lyxfont::maxDescent(font);
1283 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1287 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1291 actcell = actrow = actcol = 0;
1292 int ly = tabular->GetDescentOfRow(actrow);
1294 // first search the right row
1295 while((ly < y) && ((actrow+1) < tabular->rows())) {
1296 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1297 tabular->GetAscentOfRow(actrow + 1) +
1298 tabular->GetAdditionalHeight(actrow + 1));
1300 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1302 actcell = tabular->GetCellNumber(actrow, actcol);
1304 // now search the right column
1305 int lx = tabular->GetWidthOfColumn(actcell) -
1306 tabular->GetAdditionalWidth(actcell);
1307 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1308 lx += tabular->GetWidthOfColumn(actcell + 1)
1309 + tabular->GetAdditionalWidth(actcell);
1311 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1316 int InsetTabular::getCellXPos(int cell) const
1320 for (; !tabular->IsFirstCellInRow(c); --c)
1322 int lx = tabular->GetWidthOfColumn(cell);
1323 for (; c < cell; ++c) {
1324 lx += tabular->GetWidthOfColumn(c);
1326 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1330 void InsetTabular::resetPos(BufferView * bv) const
1332 if (!locked || nodraw())
1334 actcol = tabular->column_of_cell(actcell);
1339 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1340 if (tabular->IsLastCellInRow(cell)) {
1341 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1342 tabular->GetAscentOfRow(actrow + 1) +
1343 tabular->GetAdditionalHeight(actrow + 1));
1347 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1348 int new_x = getCellXPos(actcell);
1349 int old_x = cursor_.x();
1352 // cursor.x(getCellXPos(actcell) + offset);
1353 if ((actcol < tabular->columns()-1) && scroll(false) &&
1354 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1357 updateLocal(bv, FULL, false);
1358 } else if (the_locking_inset &&
1359 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1361 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1362 if (xx > (bv->workWidth()-20)) {
1363 scroll(bv, -(xx - bv->workWidth() + 60));
1364 updateLocal(bv, FULL, false);
1365 } else if (xx < 20) {
1371 updateLocal(bv, FULL, false);
1373 } else if ((cursor_.x() - offset) > 20 &&
1374 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1375 > (bv->workWidth() - 20)) {
1376 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1377 updateLocal(bv, FULL, false);
1378 } else if ((cursor_.x() - offset) < 20) {
1379 scroll(bv, 20 - cursor_.x() + offset);
1380 updateLocal(bv, FULL, false);
1381 } else if (scroll(false) && top_x > 20 &&
1382 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1383 scroll(bv, old_x - cursor_.x());
1384 updateLocal(bv, FULL, false);
1386 if (the_locking_inset) {
1387 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1388 inset_y = cursor_.y();
1390 if ((!the_locking_inset ||
1391 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1392 actcell != oldcell) {
1393 InsetTabular * inset = const_cast<InsetTabular *>(this);
1394 bv->owner()->getDialogs()->updateTabular(inset);
1400 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1402 if (lock && !old_locking_inset) {
1403 if (activateCellInset(bv))
1406 bool moved = isRightToLeft(bv)
1407 ? movePrevCell(bv) : moveNextCell(bv);
1409 return FINISHED_RIGHT;
1410 if (lock && activateCellInset(bv))
1414 return DISPATCHED_NOUPDATE;
1418 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1420 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1423 if (lock) { // behind the inset
1424 if (activateCellInset(bv, 0, 0, 0, true))
1428 return DISPATCHED_NOUPDATE;
1432 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1434 int const ocell = actcell;
1435 actcell = tabular->GetCellAbove(actcell);
1436 if (actcell == ocell) // we moved out of the inset
1442 if (old_locking_inset) {
1443 old_locking_inset->getCursorPos(bv, x, y);
1444 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1446 if (activateCellInset(bv, x, 0))
1449 return DISPATCHED_NOUPDATE;
1453 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1455 int const ocell = actcell;
1456 actcell = tabular->GetCellBelow(actcell);
1457 if (actcell == ocell) // we moved out of the inset
1458 return FINISHED_DOWN;
1463 if (old_locking_inset) {
1464 old_locking_inset->getCursorPos(bv, x, y);
1465 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1467 if (activateCellInset(bv, x, 0))
1470 return DISPATCHED_NOUPDATE;
1474 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1476 if (isRightToLeft(bv)) {
1477 if (tabular->IsFirstCellInRow(actcell)) {
1478 int row = tabular->row_of_cell(actcell);
1479 if (row == tabular->rows() - 1)
1481 actcell = tabular->GetLastCellInRow(row);
1482 actcell = tabular->GetCellBelow(actcell);
1489 if (tabular->IsLastCell(actcell))
1494 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1495 isRightToLeftPar(bv->buffer()->params);
1496 activateCellInset(bv, 0, 0, 0, !rtl);
1503 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1505 if (isRightToLeft(bv)) {
1506 if (tabular->IsLastCellInRow(actcell)) {
1507 int row = tabular->row_of_cell(actcell);
1510 actcell = tabular->GetFirstCellInRow(row);
1511 actcell = tabular->GetCellAbove(actcell);
1513 if (tabular->IsLastCell(actcell))
1518 if (!actcell) // first cell
1523 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1524 isRightToLeftPar(bv->buffer()->params);
1525 activateCellInset(bv, 0, 0, 0, !rtl);
1532 bool InsetTabular::deletable() const
1538 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1543 sel_cell_end = tabular->GetNumberOfCells() - 1;
1545 if (hasSelection()) {
1546 setUndo(bv, Undo::EDIT,
1547 bv->text->cursor.par(),
1548 bv->text->cursor.par()->next());
1549 bool frozen = undo_frozen;
1552 // apply the fontchange on the whole selection
1557 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1558 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1559 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1560 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1565 updateLocal(bv, INIT, true);
1567 if (the_locking_inset)
1568 the_locking_inset->setFont(bv, font, tall);
1572 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1574 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1577 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1578 string const tmp = tabularFeature[i].feature;
1580 if (tmp == what.substr(0, tmp.length())) {
1581 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1582 //tabularFeatures[i].feature.length())) {
1583 action = tabularFeature[i].action;
1587 if (action == LyXTabular::LAST_ACTION)
1591 frontStrip(what.substr(tabularFeature[i].feature.length()));
1592 tabularFeatures(bv, action, val);
1597 void InsetTabular::tabularFeatures(BufferView * bv,
1598 LyXTabular::Feature feature,
1599 string const & value)
1605 bool setLines = false;
1606 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1607 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1610 case LyXTabular::M_ALIGN_LEFT:
1611 case LyXTabular::ALIGN_LEFT:
1612 setAlign=LYX_ALIGN_LEFT;
1614 case LyXTabular::M_ALIGN_RIGHT:
1615 case LyXTabular::ALIGN_RIGHT:
1616 setAlign=LYX_ALIGN_RIGHT;
1618 case LyXTabular::M_ALIGN_CENTER:
1619 case LyXTabular::ALIGN_CENTER:
1620 setAlign=LYX_ALIGN_CENTER;
1622 case LyXTabular::M_VALIGN_TOP:
1623 case LyXTabular::VALIGN_TOP:
1624 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1626 case LyXTabular::M_VALIGN_BOTTOM:
1627 case LyXTabular::VALIGN_BOTTOM:
1628 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1630 case LyXTabular::M_VALIGN_CENTER:
1631 case LyXTabular::VALIGN_CENTER:
1632 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1637 if (hasSelection()) {
1638 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1640 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1641 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1643 setUndo(bv, Undo::FINISH,
1644 bv->text->cursor.par(),
1645 bv->text->cursor.par()->next());
1647 int row = tabular->row_of_cell(actcell);
1648 int column = tabular->column_of_cell(actcell);
1652 case LyXTabular::SET_PWIDTH:
1654 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1655 tabular->SetColumnPWidth(actcell,value);
1657 for (int i = 0; i < tabular->rows(); ++i) {
1658 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1661 updateLocal(bv, INIT, true);
1665 case LyXTabular::SET_MPWIDTH:
1667 bool const update = (tabular->GetPWidth(actcell) != value);
1668 tabular->SetMColumnPWidth(actcell,value);
1670 for (int i = 0; i < tabular->rows(); ++i) {
1671 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1674 updateLocal(bv, INIT, true);
1678 case LyXTabular::SET_SPECIAL_COLUMN:
1679 case LyXTabular::SET_SPECIAL_MULTI:
1680 tabular->SetAlignSpecial(actcell,value,feature);
1681 updateLocal(bv, FULL, true);
1683 case LyXTabular::APPEND_ROW:
1684 // append the row into the tabular
1685 unlockInsetInInset(bv, the_locking_inset);
1686 tabular->AppendRow(actcell);
1687 updateLocal(bv, INIT, true);
1689 case LyXTabular::APPEND_COLUMN:
1690 // append the column into the tabular
1691 unlockInsetInInset(bv, the_locking_inset);
1692 tabular->AppendColumn(actcell);
1693 actcell = tabular->GetCellNumber(row, column);
1694 updateLocal(bv, INIT, true);
1696 case LyXTabular::DELETE_ROW:
1697 unlockInsetInInset(bv, the_locking_inset);
1698 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1699 tabular->DeleteRow(sel_row_start);
1701 if (sel_row_start >= tabular->rows())
1703 actcell = tabular->GetCellNumber(sel_row_start, column);
1705 updateLocal(bv, INIT, true);
1707 case LyXTabular::DELETE_COLUMN:
1708 unlockInsetInInset(bv, the_locking_inset);
1709 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1710 tabular->DeleteColumn(sel_col_start);
1712 if (sel_col_start >= tabular->columns())
1714 actcell = tabular->GetCellNumber(row, sel_col_start);
1716 updateLocal(bv, INIT, true);
1718 case LyXTabular::M_TOGGLE_LINE_TOP:
1720 case LyXTabular::TOGGLE_LINE_TOP:
1722 bool lineSet = !tabular->TopLine(actcell, flag);
1723 for (int i = sel_row_start; i <= sel_row_end; ++i)
1724 for (int j = sel_col_start; j <= sel_col_end; ++j)
1725 tabular->SetTopLine(
1726 tabular->GetCellNumber(i, j),
1728 updateLocal(bv, INIT, true);
1732 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1734 case LyXTabular::TOGGLE_LINE_BOTTOM:
1736 bool lineSet = !tabular->BottomLine(actcell, flag);
1737 for (int i = sel_row_start; i <= sel_row_end; ++i)
1738 for (int j = sel_col_start; j <= sel_col_end; ++j)
1739 tabular->SetBottomLine(
1740 tabular->GetCellNumber(i, j),
1743 updateLocal(bv, INIT, true);
1747 case LyXTabular::M_TOGGLE_LINE_LEFT:
1749 case LyXTabular::TOGGLE_LINE_LEFT:
1751 bool lineSet = !tabular->LeftLine(actcell, flag);
1752 for (int i = sel_row_start; i <= sel_row_end; ++i)
1753 for (int j = sel_col_start; j <= sel_col_end; ++j)
1754 tabular->SetLeftLine(
1755 tabular->GetCellNumber(i,j),
1758 updateLocal(bv, INIT, true);
1762 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1764 case LyXTabular::TOGGLE_LINE_RIGHT:
1766 bool lineSet = !tabular->RightLine(actcell, flag);
1767 for (int i = sel_row_start; i <= sel_row_end; ++i)
1768 for (int j = sel_col_start; j <= sel_col_end; ++j)
1769 tabular->SetRightLine(
1770 tabular->GetCellNumber(i,j),
1773 updateLocal(bv, INIT, true);
1777 case LyXTabular::M_ALIGN_LEFT:
1778 case LyXTabular::M_ALIGN_RIGHT:
1779 case LyXTabular::M_ALIGN_CENTER:
1781 case LyXTabular::ALIGN_LEFT:
1782 case LyXTabular::ALIGN_RIGHT:
1783 case LyXTabular::ALIGN_CENTER:
1784 for (int i = sel_row_start; i <= sel_row_end; ++i)
1785 for (int j = sel_col_start; j <= sel_col_end; ++j)
1786 tabular->SetAlignment(
1787 tabular->GetCellNumber(i, j),
1790 updateLocal(bv, INIT, true);
1792 case LyXTabular::M_VALIGN_TOP:
1793 case LyXTabular::M_VALIGN_BOTTOM:
1794 case LyXTabular::M_VALIGN_CENTER:
1796 case LyXTabular::VALIGN_TOP:
1797 case LyXTabular::VALIGN_BOTTOM:
1798 case LyXTabular::VALIGN_CENTER:
1799 for (int i = sel_row_start; i <= sel_row_end; ++i)
1800 for (int j = sel_col_start; j <= sel_col_end; ++j)
1801 tabular->SetVAlignment(
1802 tabular->GetCellNumber(i, j),
1804 updateLocal(bv, INIT, true);
1806 case LyXTabular::MULTICOLUMN:
1808 if (sel_row_start != sel_row_end) {
1809 WriteAlert(_("Impossible Operation!"),
1810 _("Multicolumns can only be horizontally."),
1814 // just multicol for one Single Cell
1815 if (!hasSelection()) {
1816 // check wether we are completly in a multicol
1817 if (tabular->IsMultiColumn(actcell)) {
1818 tabular->UnsetMultiColumn(actcell);
1819 updateLocal(bv, INIT, true);
1821 tabular->SetMultiColumn(actcell, 1);
1822 updateLocal(bv, CELL, true);
1826 // we have a selection so this means we just add all this
1827 // cells to form a multicolumn cell
1831 if (sel_cell_start > sel_cell_end) {
1832 s_start = sel_cell_end;
1833 s_end = sel_cell_start;
1835 s_start = sel_cell_start;
1836 s_end = sel_cell_end;
1838 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1840 sel_cell_end = sel_cell_start;
1841 updateLocal(bv, INIT, true);
1844 case LyXTabular::SET_ALL_LINES:
1846 case LyXTabular::UNSET_ALL_LINES:
1847 for (int i = sel_row_start; i <= sel_row_end; ++i)
1848 for (int j = sel_col_start; j <= sel_col_end; ++j)
1849 tabular->SetAllLines(
1850 tabular->GetCellNumber(i,j), setLines);
1851 updateLocal(bv, INIT, true);
1853 case LyXTabular::SET_LONGTABULAR:
1854 tabular->SetLongTabular(true);
1855 updateLocal(bv, INIT, true); // because this toggles displayed
1857 case LyXTabular::UNSET_LONGTABULAR:
1858 tabular->SetLongTabular(false);
1859 updateLocal(bv, INIT, true); // because this toggles displayed
1861 case LyXTabular::SET_ROTATE_TABULAR:
1862 tabular->SetRotateTabular(true);
1864 case LyXTabular::UNSET_ROTATE_TABULAR:
1865 tabular->SetRotateTabular(false);
1867 case LyXTabular::SET_ROTATE_CELL:
1868 for (int i = sel_row_start; i <= sel_row_end; ++i)
1869 for (int j = sel_col_start; j<=sel_col_end; ++j)
1870 tabular->SetRotateCell(
1871 tabular->GetCellNumber(i, j),
1874 case LyXTabular::UNSET_ROTATE_CELL:
1875 for (int i = sel_row_start; i <= sel_row_end; ++i)
1876 for (int j = sel_col_start; j <= sel_col_end; ++j)
1877 tabular->SetRotateCell(
1878 tabular->GetCellNumber(i, j), false);
1880 case LyXTabular::SET_USEBOX:
1882 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1883 if (val == tabular->GetUsebox(actcell))
1884 val = LyXTabular::BOX_NONE;
1885 for (int i = sel_row_start; i <= sel_row_end; ++i)
1886 for (int j = sel_col_start; j <= sel_col_end; ++j)
1888 tabular->GetCellNumber(i, j), val);
1891 case LyXTabular::SET_LTFIRSTHEAD:
1892 tabular->SetLTHead(actcell, true);
1894 case LyXTabular::SET_LTHEAD:
1895 tabular->SetLTHead(actcell, false);
1897 case LyXTabular::SET_LTFOOT:
1898 tabular->SetLTFoot(actcell, false);
1900 case LyXTabular::SET_LTLASTFOOT:
1901 tabular->SetLTFoot(actcell, true);
1903 case LyXTabular::SET_LTNEWPAGE:
1905 bool what = !tabular->GetLTNewPage(actcell);
1906 tabular->SetLTNewPage(actcell, what);
1909 // dummy stuff just to avoid warnings
1910 case LyXTabular::LAST_ACTION:
1916 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1919 UpdatableInset * inset =
1920 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1921 LyXFont font(LyXFont::ALL_SANE);
1923 x = inset->x() + inset->width(bv, font);
1924 y = inset->descent(bv, font);
1926 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1927 //inset_y = cursor.y();
1928 inset->edit(bv, x, y, button);
1929 if (!the_locking_inset)
1931 updateLocal(bv, CELL, false);
1932 return (the_locking_inset != 0);
1936 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1939 inset_x = cursor_.x()
1940 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1941 inset_y = cursor_.y();
1942 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1946 bool InsetTabular::insetHit(BufferView *, int x, int) const
1949 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
1953 // This returns paperWidth() if the cell-width is unlimited or the width
1954 // in pixels if we have a pwidth for this cell.
1955 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
1957 string const s = tabular->GetPWidth(cell);
1961 return VSpace(s).inPixels(bv);
1965 int InsetTabular::getMaxWidth(BufferView * bv,
1966 UpdatableInset const * inset) const
1968 int cell = tabular->cur_cell;
1969 if (tabular->GetCellInset(cell) != inset) {
1971 if (tabular->GetCellInset(cell) != inset) {
1973 lyxerr << "Actcell not equal to actual cell!\n";
1978 int const n = tabular->GetNumberOfCells();
1981 for (cell = 0; cell < n; ++cell) {
1982 if (tabular->GetCellInset(cell) == inset)
1988 lyxerr << "Own inset not found, shouldn't really happen!\n";
1992 int w = getMaxWidthOfCell(bv, cell);
1994 // because the inset then subtracts it's top_x and owner->x()
1995 w += (inset->x() - top_x);
2002 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2004 resizeLyXText(bv, recursive);
2008 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2011 for(int i = 0; i < tabular->rows(); ++i) {
2012 for(int j = 0; j < tabular->columns(); ++j) {
2013 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2021 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2022 bool const recursive) const
2024 if (the_locking_inset)
2025 return the_locking_inset->getLyXText(bv, recursive);
2027 // if we're locked lock the actual insettext and return it's LyXText!!!
2029 UpdatableInset * inset =
2030 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2031 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2032 return the_locking_inset->getLyXText(bv, recursive);
2035 return Inset::getLyXText(bv, recursive);
2039 bool InsetTabular::showInsetDialog(BufferView * bv) const
2041 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2042 bv->owner()->getDialogs()
2043 ->showTabular(const_cast<InsetTabular *>(this));
2048 void InsetTabular::openLayoutDialog(BufferView * bv) const
2050 if (the_locking_inset) {
2051 InsetTabular * i = static_cast<InsetTabular *>
2052 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2054 i->openLayoutDialog(bv);
2058 bv->owner()->getDialogs()->showTabular(
2059 const_cast<InsetTabular *>(this));
2064 // functions returns:
2068 // 3 ... toggled off
2070 func_status::value_type InsetTabular::getStatus(string const & what) const
2072 int action = LyXTabular::LAST_ACTION;
2073 func_status::value_type status = func_status::OK;
2076 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2077 string const tmp = tabularFeature[i].feature;
2078 if (tmp == what.substr(0, tmp.length())) {
2079 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2080 // tabularFeatures[i].feature.length())) {
2081 action = tabularFeature[i].action;
2085 if (action == LyXTabular::LAST_ACTION)
2086 return func_status::Unknown;
2088 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2095 if (hasSelection()) {
2096 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2098 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2102 case LyXTabular::SET_PWIDTH:
2103 case LyXTabular::SET_MPWIDTH:
2104 case LyXTabular::SET_SPECIAL_COLUMN:
2105 case LyXTabular::SET_SPECIAL_MULTI:
2106 status |= func_status::Disabled;
2109 case LyXTabular::APPEND_ROW:
2110 case LyXTabular::APPEND_COLUMN:
2111 case LyXTabular::DELETE_ROW:
2112 case LyXTabular::DELETE_COLUMN:
2113 case LyXTabular::SET_ALL_LINES:
2114 case LyXTabular::UNSET_ALL_LINES:
2115 status |= func_status::OK;
2118 case LyXTabular::MULTICOLUMN:
2119 if (tabular->IsMultiColumn(actcell))
2120 status |= func_status::ToggleOn;
2122 status |= func_status::ToggleOff;
2124 case LyXTabular::M_TOGGLE_LINE_TOP:
2126 case LyXTabular::TOGGLE_LINE_TOP:
2127 if (tabular->TopLine(actcell, flag))
2128 status |= func_status::ToggleOn;
2130 status |= func_status::ToggleOff;
2132 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2134 case LyXTabular::TOGGLE_LINE_BOTTOM:
2135 if (tabular->BottomLine(actcell, flag))
2136 status |= func_status::ToggleOn;
2138 status |= func_status::ToggleOff;
2140 case LyXTabular::M_TOGGLE_LINE_LEFT:
2142 case LyXTabular::TOGGLE_LINE_LEFT:
2143 if (tabular->LeftLine(actcell, flag))
2144 status |= func_status::ToggleOn;
2146 status |= func_status::ToggleOff;
2148 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2150 case LyXTabular::TOGGLE_LINE_RIGHT:
2151 if (tabular->RightLine(actcell, flag))
2152 status |= func_status::ToggleOn;
2154 status |= func_status::ToggleOff;
2156 case LyXTabular::M_ALIGN_LEFT:
2158 case LyXTabular::ALIGN_LEFT:
2159 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2160 status |= func_status::ToggleOn;
2162 status |= func_status::ToggleOff;
2164 case LyXTabular::M_ALIGN_RIGHT:
2166 case LyXTabular::ALIGN_RIGHT:
2167 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2168 status |= func_status::ToggleOn;
2170 status |= func_status::ToggleOff;
2172 case LyXTabular::M_ALIGN_CENTER:
2174 case LyXTabular::ALIGN_CENTER:
2175 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2176 status |= func_status::ToggleOn;
2178 status |= func_status::ToggleOff;
2180 case LyXTabular::M_VALIGN_TOP:
2182 case LyXTabular::VALIGN_TOP:
2183 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2184 status |= func_status::ToggleOn;
2186 status |= func_status::ToggleOff;
2188 case LyXTabular::M_VALIGN_BOTTOM:
2190 case LyXTabular::VALIGN_BOTTOM:
2191 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2192 status |= func_status::ToggleOn;
2194 status |= func_status::ToggleOff;
2196 case LyXTabular::M_VALIGN_CENTER:
2198 case LyXTabular::VALIGN_CENTER:
2199 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2200 status |= func_status::ToggleOn;
2202 status |= func_status::ToggleOff;
2204 case LyXTabular::SET_LONGTABULAR:
2205 if (tabular->IsLongTabular())
2206 status |= func_status::ToggleOn;
2208 status |= func_status::ToggleOff;
2210 case LyXTabular::UNSET_LONGTABULAR:
2211 if (!tabular->IsLongTabular())
2212 status |= func_status::ToggleOn;
2214 status |= func_status::ToggleOff;
2216 case LyXTabular::SET_ROTATE_TABULAR:
2217 if (tabular->GetRotateTabular())
2218 status |= func_status::ToggleOn;
2220 status |= func_status::ToggleOff;
2222 case LyXTabular::UNSET_ROTATE_TABULAR:
2223 if (!tabular->GetRotateTabular())
2224 status |= func_status::ToggleOn;
2226 status |= func_status::ToggleOff;
2228 case LyXTabular::SET_ROTATE_CELL:
2229 if (tabular->GetRotateCell(actcell))
2230 status |= func_status::ToggleOn;
2232 status |= func_status::ToggleOff;
2234 case LyXTabular::UNSET_ROTATE_CELL:
2235 if (!tabular->GetRotateCell(actcell))
2236 status |= func_status::ToggleOn;
2238 status |= func_status::ToggleOff;
2240 case LyXTabular::SET_USEBOX:
2241 if (strToInt(argument) == tabular->GetUsebox(actcell))
2242 status |= func_status::ToggleOn;
2244 status |= func_status::ToggleOff;
2246 case LyXTabular::SET_LTFIRSTHEAD:
2247 if (tabular->GetRowOfLTHead(actcell, dummy))
2248 status |= func_status::ToggleOn;
2250 status |= func_status::ToggleOff;
2252 case LyXTabular::SET_LTHEAD:
2253 if (tabular->GetRowOfLTHead(actcell, dummy))
2254 status |= func_status::ToggleOn;
2256 status |= func_status::ToggleOff;
2258 case LyXTabular::SET_LTFOOT:
2259 if (tabular->GetRowOfLTFoot(actcell, dummy))
2260 status |= func_status::ToggleOn;
2262 status |= func_status::ToggleOff;
2264 case LyXTabular::SET_LTLASTFOOT:
2265 if (tabular->GetRowOfLTFoot(actcell, dummy))
2266 status |= func_status::ToggleOn;
2268 status |= func_status::ToggleOff;
2270 case LyXTabular::SET_LTNEWPAGE:
2271 if (tabular->GetLTNewPage(actcell))
2272 status |= func_status::ToggleOn;
2274 status |= func_status::ToggleOff;
2277 status = func_status::Disabled;
2284 std::vector<string> const InsetTabular::getLabelList() const
2286 return tabular->getLabelList();
2290 bool InsetTabular::copySelection(BufferView * bv)
2292 if (!hasSelection())
2295 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2296 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2297 if (sel_col_start > sel_col_end) {
2298 sel_col_start = sel_col_end;
2299 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2301 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2303 int const columns = sel_col_end - sel_col_start + 1;
2305 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2306 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2307 if (sel_row_start > sel_row_end) {
2308 swap(sel_row_start, sel_row_end);
2310 int const rows = sel_row_end - sel_row_start + 1;
2312 delete paste_tabular;
2313 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2314 for (int i = 0; i < sel_row_start; ++i)
2315 paste_tabular->DeleteRow(0);
2316 while(paste_tabular->rows() > rows)
2317 paste_tabular->DeleteRow(rows);
2318 paste_tabular->SetTopLine(0, true, true);
2319 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2321 for (int i = 0; i < sel_col_start; ++i)
2322 paste_tabular->DeleteColumn(0);
2323 while (paste_tabular->columns() > columns)
2324 paste_tabular->DeleteColumn(columns);
2325 paste_tabular->SetLeftLine(0, true, true);
2326 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2330 paste_tabular->Ascii(bv->buffer(), sstr);
2331 bv->stuffClipboard(sstr.str().c_str());
2336 bool InsetTabular::pasteSelection(BufferView * bv)
2341 for (int r1 = 0, r2 = actrow;
2342 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2344 for(int c1 = 0, c2 = actcol;
2345 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2347 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2348 tabular->IsPartOfMultiColumn(r2,c2))
2350 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2354 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2358 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2359 int const n2 = tabular->GetCellNumber(r2, c2);
2360 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2361 tabular->GetCellInset(n2)->setOwner(this);
2362 tabular->GetCellInset(n2)->deleteLyXText(bv);
2369 bool InsetTabular::cutSelection()
2371 if (!hasSelection())
2374 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2375 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2376 if (sel_col_start > sel_col_end) {
2377 sel_col_start = sel_col_end;
2378 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2380 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2382 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2383 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2384 if (sel_row_start > sel_row_end) {
2385 swap(sel_row_start, sel_row_end);
2387 if (sel_cell_start > sel_cell_end) {
2388 swap(sel_cell_start, sel_cell_end);
2390 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2391 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2392 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2399 bool InsetTabular::isRightToLeft(BufferView *bv )
2401 return bv->getParentLanguage(this)->RightToLeft();
2405 bool InsetTabular::nodraw() const
2407 if (!UpdatableInset::nodraw() && the_locking_inset)
2408 return the_locking_inset->nodraw();
2409 return UpdatableInset::nodraw();
2413 int InsetTabular::scroll(bool recursive) const
2415 int sx = UpdatableInset::scroll(false);
2417 if (recursive && the_locking_inset)
2418 sx += the_locking_inset->scroll(recursive);
2424 bool InsetTabular::doClearArea() const
2426 return !locked || (need_update & (FULL|INIT));
2430 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2432 srow = tabular->row_of_cell(sel_cell_start);
2433 erow = tabular->row_of_cell(sel_cell_end);
2437 scol = tabular->column_of_cell(sel_cell_start);
2438 ecol = tabular->column_of_cell(sel_cell_end);
2442 ecol = tabular->right_column_of_cell(sel_cell_end);
2446 Paragraph * InsetTabular::getParFromID(int id) const
2449 for(int i = 0; i < tabular->rows(); ++i) {
2450 for(int j = 0; j < tabular->columns(); ++j) {
2451 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2459 Paragraph * InsetTabular::firstParagraph() const
2461 if (the_locking_inset)
2462 return the_locking_inset->firstParagraph();
2467 Paragraph * InsetTabular::getFirstParagraph(int i) const
2469 return (i < tabular->GetNumberOfCells())
2470 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2475 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2477 if (the_locking_inset)
2478 return the_locking_inset->cursor(bv);
2479 return Inset::cursor(bv);
2483 Inset * InsetTabular::getInsetFromID(int id_arg) const
2486 return const_cast<InsetTabular *>(this);
2489 for(int i=0; i < tabular->rows(); ++i) {
2490 for(int j=0; j < tabular->columns(); ++j) {
2491 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2499 string const InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2501 if (the_locking_inset) {
2502 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2505 if (tabular->IsLastCell(actcell)) {
2506 bv->unlockInset(const_cast<InsetTabular *>(this));
2512 // otherwise we have to lock the next inset and ask for it's selecttion
2513 UpdatableInset * inset =
2514 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2515 inset->edit(bv, 0, 0, 0);
2516 string const str(selectNextWordInt(bv, value));
2524 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2526 // when entering this function the inset should be ALWAYS locked!
2527 lyx::Assert(the_locking_inset);
2529 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2533 if (tabular->IsLastCell(actcell)) {
2534 bv->unlockInset(const_cast<InsetTabular *>(this));
2538 // otherwise we have to lock the next inset and ask for it's selecttion
2539 UpdatableInset * inset =
2540 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2542 return selectNextWordInt(bv, value);
2546 void InsetTabular::selectSelectedWord(BufferView * bv)
2548 if (the_locking_inset) {
2549 the_locking_inset->selectSelectedWord(bv);
2556 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2558 if (the_locking_inset) {
2559 the_locking_inset->toggleSelection(bv, kill_selection);
2564 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2565 bool const & cs, bool const & mw)
2567 if (the_locking_inset) {
2568 if (the_locking_inset->searchForward(bv, str, cs, mw))
2570 if (tabular->IsLastCell(actcell)) {
2571 bv->unlockInset(const_cast<InsetTabular *>(this));
2576 // otherwise we have to lock the next inset and search there
2577 UpdatableInset * inset =
2578 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2581 bool const res = searchForward(bv, str, cs, mw);
2582 updateLocal(bv, NONE, false);
2583 bv->updateInset(const_cast<InsetTabular *>(this), false);
2586 return searchForward(bv, str, cs, mw);
2591 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2592 bool const & cs, bool const & mw)
2594 if (the_locking_inset) {
2595 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2597 if (!actcell) { // we are already in the first cell
2598 bv->unlockInset(const_cast<InsetTabular *>(this));
2603 // otherwise we have to lock the next inset and search there
2604 UpdatableInset * inset =
2605 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2606 inset->edit(bv, false);
2608 bool const res = searchBackward(bv, str, cs, mw);
2609 bv->updateInset(const_cast<InsetTabular *>(this), false);
2612 return searchBackward(bv, str, cs, mw);
2617 bool InsetTabular::insetAllowed(Inset::Code code) const
2619 if (the_locking_inset)
2620 return the_locking_inset->insetAllowed(code);