1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
17 #include "insettabular.h"
21 #include "commandtags.h"
24 #include "LaTeXFeatures.h"
29 #include "insets/insettext.h"
33 #include "BufferView.h"
34 #include "undo_funcs.h"
35 #include "lyxlength.h"
36 #include "ParagraphParameters.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/Alert.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
61 int const ADD_TO_HEIGHT = 2;
62 int const ADD_TO_TABULAR_WIDTH = 2;
65 LyXTabular * paste_tabular = 0;
68 struct TabularFeature {
69 LyXTabular::Feature action;
74 TabularFeature tabularFeature[] =
76 { LyXTabular::APPEND_ROW, "append-row" },
77 { LyXTabular::APPEND_COLUMN, "append-column" },
78 { LyXTabular::DELETE_ROW, "delete-row" },
79 { LyXTabular::DELETE_COLUMN, "delete-column" },
80 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
81 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
82 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
83 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
84 { LyXTabular::ALIGN_LEFT, "align-left" },
85 { LyXTabular::ALIGN_RIGHT, "align-right" },
86 { LyXTabular::ALIGN_CENTER, "align-center" },
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, "" }
125 bool InsetTabular::hasPasteBuffer() const
127 return (paste_tabular != 0);
131 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
138 tabular.reset(new LyXTabular(buf.params, this, rows, columns));
139 // for now make it always display as display() inset
141 the_locking_inset = 0;
142 old_locking_inset = 0;
145 actrow = actcell = 0;
149 in_reset_pos = false;
155 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
157 : UpdatableInset(tab, same_id), buffer(&buf)
159 tabular.reset(new LyXTabular(buf.params,
160 this, *(tab.tabular), same_id));
161 the_locking_inset = 0;
162 old_locking_inset = 0;
165 actrow = actcell = 0;
169 in_reset_pos = false;
175 InsetTabular::~InsetTabular()
181 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
183 return new InsetTabular(*this, buf, same_id);
187 void InsetTabular::write(Buffer const * buf, ostream & os) const
189 os << " Tabular" << endl;
190 tabular->Write(buf, os);
194 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
196 bool const old_format = (lex.getString() == "\\LyXTable");
198 tabular.reset(new LyXTabular(buf, this, lex));
206 string token = lex.getString();
207 while (lex.isOK() && (token != "\\end_inset")) {
209 token = lex.getString();
211 if (token != "\\end_inset") {
212 lex.printError("Missing \\end_inset at this point. "
218 int InsetTabular::ascent(BufferView *, LyXFont const &) const
220 return tabular->GetAscentOfRow(0);
224 int InsetTabular::descent(BufferView *, LyXFont const &) const
226 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
230 int InsetTabular::width(BufferView *, LyXFont const &) const
232 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
236 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
237 float & x, bool cleared) const
245 if (need_update == INIT) {
246 if (calculate_dimensions_of_cells(bv, font, true))
247 bv->text->status = LyXText::CHANGED_IN_DRAW;
252 Painter & pain = bv->painter();
258 UpdatableInset::draw(bv, font, baseline, x, cleared);
261 x += static_cast<float>(scroll());
263 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
264 (top_x != int(x)) || (top_baseline != baseline)))
266 int h = ascent(bv, font) + descent(bv, font);
267 int const tx = display() || !owner() ? 0 : top_x;
268 int w = tx ? width(bv, font) : pain.paperWidth();
269 int ty = baseline - ascent(bv, font);
273 if ((ty + h) > pain.paperHeight())
274 h = pain.paperHeight();
275 if ((top_x + w) > pain.paperWidth())
276 w = pain.paperWidth();
277 pain.fillRectangle(tx, ty, w, h, backgroundColor());
283 top_baseline = baseline;
284 x += ADD_TO_TABULAR_WIDTH;
288 first_visible_cell = -1;
289 for (i = 0; i < tabular->rows(); ++i) {
291 cell = tabular->GetCellNumber(i, 0);
292 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
293 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
295 baseline += tabular->GetDescentOfRow(i) +
296 tabular->GetAscentOfRow(i + 1) +
297 tabular->GetAdditionalHeight(i + 1);
300 for (j = 0; j < tabular->columns(); ++j) {
301 if (nx > bv->workWidth())
303 if (tabular->IsPartOfMultiColumn(i, j))
305 cx = nx + tabular->GetBeginningOfTextInCell(cell);
306 if (first_visible_cell < 0)
307 first_visible_cell = cell;
308 if (hasSelection()) {
309 drawCellSelection(pain, nx, baseline, i, j, cell);
312 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
313 drawCellLines(pain, nx, baseline, i, cell);
314 nx += tabular->GetWidthOfColumn(cell);
317 baseline += tabular->GetDescentOfRow(i) +
318 tabular->GetAscentOfRow(i + 1) +
319 tabular->GetAdditionalHeight(i + 1);
321 } else if (need_update == CELL) {
324 if (the_locking_inset &&
325 tabular->GetCellInset(actcell) != the_locking_inset)
327 Inset * inset = tabular->GetCellInset(cell);
329 inset != the_locking_inset && i < tabular->rows();
333 inset != the_locking_inset && j < tabular->columns();
336 if (tabular->IsPartOfMultiColumn(i, j))
338 nx += tabular->GetWidthOfColumn(cell);
340 inset = tabular->GetCellInset(cell);
342 if (tabular->row_of_cell(cell) > i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
350 // compute baseline for actual row
351 for (i = 0; i < actrow; ++i) {
352 baseline += tabular->GetDescentOfRow(i) +
353 tabular->GetAscentOfRow(i + 1) +
354 tabular->GetAdditionalHeight(i + 1);
356 // now compute the right x position
357 cell = tabular->GetCellNumber(actrow, 0);
358 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
359 if (tabular->IsPartOfMultiColumn(actrow, j))
361 nx += tabular->GetWidthOfColumn(cell);
365 i = tabular->row_of_cell(cell);
366 if (the_locking_inset != tabular->GetCellInset(cell)) {
367 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
370 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
372 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
374 // Here we use rectangular backgroundColor patches to clean up
375 // within a cell around the cell's red inset box. As follows:
377 // +--------------------+
378 // | C | The rectangles are A, B and C
379 // | A |------------| B | below, origin top left (tx, ty),
380 // | | inset box | | dimensions w(idth), h(eight).
381 // +---+------------+---+ x grows rightward, y downward
383 // +--------------------+
386 // clear only if we didn't have a change
387 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
389 // clear before the inset
392 ty = baseline - tabular->GetAscentOfRow(i) + 1;
393 w = int(cx - nx - 1);
394 h = tabular->GetAscentOfRow(i) +
395 tabular->GetDescentOfRow(i) - 1;
396 pain.fillRectangle(tx, ty, w, h, backgroundColor());
397 // clear behind the inset
398 tx = int(cx + the_locking_inset->width(bv,font) + 1);
399 ty = baseline - tabular->GetAscentOfRow(i) + 1;
400 w = tabular->GetWidthOfColumn(cell) -
401 tabular->GetBeginningOfTextInCell(cell) -
402 the_locking_inset->width(bv,font) -
403 tabular->GetAdditionalWidth(cell) - 1;
404 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
405 pain.fillRectangle(tx, ty, w, h, backgroundColor());
406 // clear below the inset
408 ty = baseline + the_locking_inset->descent(bv, font) + 1;
409 w = tabular->GetWidthOfColumn(cell) -
410 tabular->GetAdditionalWidth(cell) - 1;
411 h = tabular->GetDescentOfRow(i) -
412 the_locking_inset->descent(bv, font) - 1;
413 pain.fillRectangle(tx, ty, w, h, backgroundColor());
414 // clear above the inset
416 ty = baseline - tabular->GetAscentOfRow(i) + 1;
417 w = tabular->GetWidthOfColumn(cell) -
418 tabular->GetAdditionalWidth(cell) - 1;
419 h = tabular->GetAscentOfRow(i) - the_locking_inset->ascent(bv, font);
420 pain.fillRectangle(tx, ty, w, h, backgroundColor());
425 x -= ADD_TO_TABULAR_WIDTH;
426 x += width(bv, font);
427 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
429 for(Inset * inset = owner(); inset; ++i)
430 inset = inset->owner();
431 if (calculate_dimensions_of_cells(bv, font, false))
439 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
440 int row, int cell) const
442 int x2 = x + tabular->GetWidthOfColumn(cell);
445 if (!tabular->TopAlreadyDrawed(cell)) {
446 on_off = !tabular->TopLine(cell);
447 pain.line(x, baseline - tabular->GetAscentOfRow(row),
448 x2, baseline - tabular->GetAscentOfRow(row),
449 on_off ? LColor::tabularonoffline : LColor::tabularline,
450 on_off ? Painter::line_onoffdash : Painter::line_solid);
452 on_off = !tabular->BottomLine(cell);
453 pain.line(x,baseline + tabular->GetDescentOfRow(row),
454 x2, baseline + tabular->GetDescentOfRow(row),
455 on_off ? LColor::tabularonoffline : LColor::tabularline,
456 on_off ? Painter::line_onoffdash : Painter::line_solid);
457 if (!tabular->LeftAlreadyDrawed(cell)) {
458 on_off = !tabular->LeftLine(cell);
459 pain.line(x, baseline - tabular->GetAscentOfRow(row),
460 x, baseline + tabular->GetDescentOfRow(row),
461 on_off ? LColor::tabularonoffline : LColor::tabularline,
462 on_off ? Painter::line_onoffdash : Painter::line_solid);
464 on_off = !tabular->RightLine(cell);
465 pain.line(x2 - tabular->GetAdditionalWidth(cell),
466 baseline - tabular->GetAscentOfRow(row),
467 x2 - tabular->GetAdditionalWidth(cell),
468 baseline + tabular->GetDescentOfRow(row),
469 on_off ? LColor::tabularonoffline : LColor::tabularline,
470 on_off ? Painter::line_onoffdash : Painter::line_solid);
474 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
475 int row, int column, int cell) const
477 lyx::Assert(hasSelection());
478 int cs = tabular->column_of_cell(sel_cell_start);
479 int ce = tabular->column_of_cell(sel_cell_end);
482 cs = tabular->column_of_cell(sel_cell_end);
484 ce = tabular->right_column_of_cell(sel_cell_end);
487 int rs = tabular->row_of_cell(sel_cell_start);
488 int re = tabular->row_of_cell(sel_cell_end);
492 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
493 int w = tabular->GetWidthOfColumn(cell);
494 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
495 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
496 w, h, LColor::selection);
501 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
507 owner()->update(bv, font, true);
514 if (calculate_dimensions_of_cells(bv, font, true))
517 owner()->update(bv, font, true);
521 if (the_locking_inset)
522 the_locking_inset->update(bv, font, reinit);
523 if (need_update < FULL &&
524 bv->text->status() == LyXText::NEED_MORE_REFRESH)
529 switch (need_update) {
533 if (calculate_dimensions_of_cells(bv, font, false))
546 string const InsetTabular::editMessage() const
548 return _("Opened Tabular Inset");
552 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
554 UpdatableInset::edit(bv, x, y, button);
556 if (!bv->lockInset(this)) {
557 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
561 the_locking_inset = 0;
567 if (insetHit(bv, x, y) && (button != 3)) {
568 activateCellInsetAbs(bv, x, y, button);
573 void InsetTabular::edit(BufferView * bv, bool front)
575 UpdatableInset::edit(bv, front);
577 if (!bv->lockInset(this)) {
578 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
582 the_locking_inset = 0;
588 actcell = tabular->GetNumberOfCells() - 1;
595 void InsetTabular::insetUnlock(BufferView * bv)
597 if (the_locking_inset) {
598 the_locking_inset->insetUnlock(bv);
599 the_locking_inset = 0;
604 if (scroll(false) || hasSelection()) {
609 updateLocal(bv, FULL, false);
614 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
615 bool mark_dirty) const
619 calculate_dimensions_of_cells(bv, font, true);
621 if (!locked && what == CELL)
623 if (need_update < what) // only set this if it has greater update
625 #if 0 // maybe this should not be done!
626 if ((what == INIT) && hasSelection()) {
631 if (need_update != NONE) {
632 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
633 if (locked) // && (what != NONE))
639 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
641 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
646 if (inset == tabular->GetCellInset(actcell)) {
647 lyxerr[Debug::INSETTEXT] << "OK" << endl;
648 the_locking_inset = tabular->GetCellInset(actcell);
651 } else if (!the_locking_inset) {
652 int const n = tabular->GetNumberOfCells();
653 int const id = inset->id();
654 for (int i = 0; i < n; ++i) {
655 InsetText * in = tabular->GetCellInset(i);
658 the_locking_inset = in;
663 if (in->getInsetFromID(id)) {
666 return the_locking_inset->lockInsetInInset(bv, inset);
669 } else if (the_locking_inset && (the_locking_inset == inset)) {
670 lyxerr[Debug::INSETTEXT] << "OK" << endl;
672 } else if (the_locking_inset) {
673 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
674 return the_locking_inset->lockInsetInInset(bv, inset);
676 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
681 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
684 if (!the_locking_inset)
686 if (the_locking_inset == inset) {
687 the_locking_inset->insetUnlock(bv);
688 the_locking_inset = 0;
690 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
696 updateLocal(bv, CELL, false);
697 // showInsetCursor(bv, false);
700 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
701 if (inset->lyxCode() == TABULAR_CODE &&
702 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
703 bv->owner()->getDialogs()->updateTabular(this);
712 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
714 Inset * tl_inset = inset;
715 // look if this inset is really inside myself!
716 while(tl_inset->owner() && tl_inset->owner() != this)
717 tl_inset = tl_inset->owner();
718 // if we enter here it's not ower inset
719 if (!tl_inset->owner())
721 // we only have to do this if this is a subinset of our cells
722 if (tl_inset != inset) {
723 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
726 updateLocal(bv, CELL, false);
731 unsigned int InsetTabular::insetInInsetY()
733 if (!the_locking_inset)
735 return inset_y + the_locking_inset->insetInInsetY();
739 UpdatableInset * InsetTabular::getLockingInset() const
741 return the_locking_inset ? the_locking_inset->getLockingInset() :
742 const_cast<InsetTabular *>(this);
746 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
750 if (the_locking_inset)
751 return the_locking_inset->getFirstLockingInsetOfType(c);
756 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
758 if (the_locking_inset)
759 return the_locking_inset->insertInset(bv, inset);
764 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
766 if (hasSelection() && (button == 3))
769 if (hasSelection()) {
771 updateLocal(bv, SELECTION, false);
774 int const ocell = actcell;
775 int const orow = actrow;
780 updateLocal(bv, NONE, false);
784 if ((ocell != actcell) && the_locking_inset) {
785 the_locking_inset->insetUnlock(bv);
786 the_locking_inset = 0;
793 bool const inset_hit = insetHit(bv, x, y);
795 if ((ocell == actcell) && the_locking_inset && inset_hit) {
797 the_locking_inset->insetButtonPress(bv,
798 x - inset_x, y - inset_y,
801 } else if (the_locking_inset) {
802 the_locking_inset->insetUnlock(bv);
804 the_locking_inset = 0;
806 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
809 if (inset_hit && bv->theLockingInset()) {
810 // only activate the Inset so that no internal inset is hit
811 // by this call. It should be only hit by the insetButtonPress call.
812 if (activateCellInsetAbs(bv, 0, 0, 0))
813 the_locking_inset->insetButtonPress(bv,
823 bool InsetTabular::insetButtonRelease(BufferView * bv,
824 int x, int y, int button)
827 if (the_locking_inset)
828 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
829 y - inset_y, button);
830 if (button == 3 && !ret) {
831 bv->owner()->getDialogs()->showTabular(this);
838 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
840 if (the_locking_inset) {
841 the_locking_inset->insetMotionNotify(bv,
849 // int const old_cell = actcell;
852 if (!hasSelection()) {
853 setSelection(actcell, actcell);
855 setSelection(sel_cell_start, actcell);
857 updateLocal(bv, SELECTION, false);
862 void InsetTabular::insetKeyPress(XKeyEvent * xke)
864 if (the_locking_inset) {
865 the_locking_inset->insetKeyPress(xke);
871 UpdatableInset::RESULT
872 InsetTabular::localDispatch(BufferView * bv, kb_action action,
875 // We need to save the value of the_locking_inset as the call to
876 // the_locking_inset->LocalDispatch might unlock it.
877 old_locking_inset = the_locking_inset;
878 UpdatableInset::RESULT result =
879 UpdatableInset::localDispatch(bv, action, arg);
880 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
885 if ((action < 0) && arg.empty())
888 bool hs = hasSelection();
891 // this one have priority over the locked InsetText, if we're not already
892 // inside another tabular then that one get's priority!
893 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
898 unlockInsetInInset(bv, the_locking_inset);
899 if (action == LFUN_TAB)
900 moveNextCell(bv, old_locking_inset != 0);
902 movePrevCell(bv, old_locking_inset != 0);
905 updateLocal(bv, SELECTION, false);
906 if (!the_locking_inset) {
908 return DISPATCHED_NOUPDATE;
911 // this to avoid compiler warnings.
917 if (the_locking_inset) {
918 result = the_locking_inset->localDispatch(bv, action, arg);
919 if (result == DISPATCHED_NOUPDATE) {
922 if (sc != scroll()) { // inset has been scrolled
923 the_locking_inset->toggleInsetCursor(bv);
924 updateLocal(bv, FULL, false);
925 the_locking_inset->toggleInsetCursor(bv);
928 } else if (result == DISPATCHED) {
929 the_locking_inset->toggleInsetCursor(bv);
930 updateLocal(bv, CELL, false);
931 the_locking_inset->toggleInsetCursor(bv);
933 } else if (result == FINISHED_UP) {
935 } else if (result == FINISHED_DOWN) {
937 } else if (result == FINISHED_RIGHT) {
945 // --- Cursor Movements ----------------------------------
946 case LFUN_RIGHTSEL: {
947 int const start = hasSelection() ? sel_cell_start : actcell;
948 if (tabular->IsLastCellInRow(actcell)) {
949 setSelection(start, actcell);
954 // if we are starting a selection, only select
955 // the current cell at the beginning
956 if (hasSelection()) {
957 moveRight(bv, false);
960 setSelection(start, end);
961 updateLocal(bv, SELECTION, false);
965 result = moveRight(bv);
968 updateLocal(bv, SELECTION, false);
971 int const start = hasSelection() ? sel_cell_start : actcell;
972 if (tabular->IsFirstCellInRow(actcell)) {
973 setSelection(start, actcell);
978 // if we are starting a selection, only select
979 // the current cell at the beginning
980 if (hasSelection()) {
984 setSelection(start, end);
985 updateLocal(bv, SELECTION, false);
989 result = moveLeft(bv);
992 updateLocal(bv, SELECTION, false);
995 int const start = hasSelection() ? sel_cell_start : actcell;
996 int const ocell = actcell;
997 // if we are starting a selection, only select
998 // the current cell at the beginning
999 if (hasSelection()) {
1000 moveDown(bv, false);
1001 if ((ocell == sel_cell_end) ||
1002 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1003 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1005 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1007 setSelection(start, start);
1009 updateLocal(bv, SELECTION, false);
1013 result = moveDown(bv, old_locking_inset != 0);
1016 updateLocal(bv, SELECTION, false);
1020 int const start = hasSelection() ? sel_cell_start : actcell;
1021 int const ocell = actcell;
1022 // if we are starting a selection, only select
1023 // the current cell at the beginning
1024 if (hasSelection()) {
1026 if ((ocell == sel_cell_end) ||
1027 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1028 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1030 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1032 setSelection(start, start);
1034 updateLocal(bv, SELECTION, false);
1038 result = moveUp(bv, old_locking_inset != 0);
1041 updateLocal(bv, SELECTION, false);
1044 UpdateCodes code = CURSOR;
1049 int column = actcol;
1050 unlockInsetInInset(bv, the_locking_inset);
1051 if (bv->text->first_y + bv->painter().paperHeight() <
1052 (top_baseline + tabular->GetHeightOfTabular()))
1054 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1056 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1058 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1061 updateLocal(bv, code, false);
1065 UpdateCodes code = CURSOR;
1070 int column = actcol;
1071 unlockInsetInInset(bv, the_locking_inset);
1072 if (top_baseline < 0) {
1073 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1075 if (top_baseline > 0)
1078 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1083 updateLocal(bv, code, false);
1086 // none of these make sense for insettabular,
1087 // but we must catch them to prevent any
1088 // selection from being confused
1092 case LFUN_WORDLEFTSEL:
1093 case LFUN_WORDRIGHT:
1094 case LFUN_WORDRIGHTSEL:
1095 case LFUN_DOWN_PARAGRAPH:
1096 case LFUN_DOWN_PARAGRAPHSEL:
1097 case LFUN_UP_PARAGRAPH:
1098 case LFUN_UP_PARAGRAPHSEL:
1099 case LFUN_BACKSPACE:
1105 case LFUN_BEGINNINGBUF:
1106 case LFUN_BEGINNINGBUFSEL:
1108 case LFUN_ENDBUFSEL:
1110 case LFUN_LAYOUT_TABULAR:
1111 bv->owner()->getDialogs()->showTabular(this);
1113 case LFUN_TABULAR_FEATURE:
1114 if (!tabularFeatures(bv, arg))
1115 result = UNDISPATCHED;
1117 // insert file functions
1118 case LFUN_FILE_INSERT_ASCII_PARA:
1119 case LFUN_FILE_INSERT_ASCII:
1121 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1124 if (insertAsciiString(bv, tmpstr, false))
1125 updateLocal(bv, INIT, true);
1127 result = UNDISPATCHED;
1130 // cut and paste functions
1132 if (!copySelection(bv))
1134 setUndo(bv, Undo::DELETE,
1135 bv->text->cursor.par(),
1136 bv->text->cursor.par()->next());
1138 updateLocal(bv, INIT, true);
1141 if (!hasSelection())
1146 case LFUN_PASTESELECTION:
1148 string const clip(bv->getClipboard());
1152 if (clip.find('\t') != string::npos) {
1156 string::size_type len = clip.length();
1157 string::size_type p = 0;
1160 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1168 maxCols = max(cols, maxCols);
1174 maxCols = max(cols, maxCols);
1175 delete paste_tabular;
1176 paste_tabular = new LyXTabular(bv->buffer()->params,
1177 this, rows, maxCols);
1178 string::size_type op = 0;
1180 int cells = paste_tabular->GetNumberOfCells();
1182 while ((cell < cells) && (p < len) &&
1183 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1188 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1193 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1194 while (cols++ < maxCols)
1202 // check for the last cell if there is no trailing '\n'
1203 if ((cell < cells) && (op < len))
1204 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1207 if (!insertAsciiString(bv, clip, true))
1210 // so that the clipboard is used and it goes on
1212 // and executes LFUN_PASTESELECTION in insettext!
1213 delete paste_tabular;
1218 if (hasPasteBuffer()) {
1219 setUndo(bv, Undo::INSERT,
1220 bv->text->cursor.par(),
1221 bv->text->cursor.par()->next());
1223 updateLocal(bv, INIT, true);
1226 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1228 // handle font changing stuff on selection before we lock the inset
1229 // in the default part!
1230 result = UNDISPATCHED;
1241 case LFUN_UNDERLINE:
1242 case LFUN_FONT_SIZE:
1243 if (bv->Dispatch(action, arg))
1244 result = DISPATCHED;
1250 // we try to activate the actual inset and put this event down to
1251 // the insets dispatch function.
1252 if ((result == DISPATCHED) || the_locking_inset)
1255 if (activateCellInset(bv)) {
1256 // reset need_update setted in above function!
1258 result = the_locking_inset->localDispatch(bv, action, arg);
1259 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1260 unlockInsetInInset(bv, the_locking_inset);
1262 // we need to update if this was requested before
1263 updateLocal(bv, NONE, false);
1264 return UNDISPATCHED;
1267 // so the below CELL is not set because this is higher
1268 // priority and we get a full redraw
1269 need_update = SELECTION;
1272 updateLocal(bv, CELL, false);
1277 if (result < FINISHED) {
1278 if (!the_locking_inset) {
1279 // showInsetCursor(bv);
1282 bv->unlockInset(this);
1287 int InsetTabular::latex(Buffer const * buf, ostream & os,
1288 bool fragile, bool fp) const
1290 return tabular->latex(buf, os, fragile, fp);
1294 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1297 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1299 return tabular->ascii(buf, os, 0, false,0);
1303 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1306 int const ret = tabular->ascii(buf,os,
1307 (int)parOwner()->params().depth(),
1314 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1319 // if the table is inside a float it doesn't need the informaltable
1320 // wrapper. Search for it.
1321 for(master = owner();
1322 master && master->lyxCode() != Inset::FLOAT_CODE;
1323 master = master->owner());
1326 os << "<informaltable>\n";
1329 ret+= tabular->docBook(buf,os);
1331 os << "</informaltable>\n";
1338 void InsetTabular::validate(LaTeXFeatures & features) const
1340 tabular->Validate(features);
1344 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1345 LyXFont const & font,
1352 bool changed = false;
1354 // if we have a locking_inset we should have to check only this cell for
1355 // change so I'll try this to have a boost, but who knows ;)
1356 if ((need_update != INIT) &&
1357 (the_locking_inset == tabular->GetCellInset(actcell))) {
1358 for(int i = 0; i < tabular->columns(); ++i) {
1359 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1361 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1364 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1365 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1366 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1369 for (int i = 0; i < tabular->rows(); ++i) {
1372 for (int j = 0; j < tabular->columns(); ++j) {
1373 if (tabular->IsPartOfMultiColumn(i,j))
1376 inset = tabular->GetCellInset(cell);
1377 if (!reinit && !tabular->GetPWidth(cell).zero())
1378 inset->update(bv, font, false);
1379 maxAsc = max(maxAsc, inset->ascent(bv, font));
1380 maxDesc = max(maxDesc, inset->descent(bv, font));
1381 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1383 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1384 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1392 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1394 if (the_locking_inset) {
1395 the_locking_inset->getCursorPos(bv, x, y);
1398 x = cursor_.x() - top_x;
1403 void InsetTabular::toggleInsetCursor(BufferView * bv)
1406 if (isCursorVisible())
1407 bv->hideLockedInsetCursor();
1410 if (the_locking_inset) {
1411 the_locking_inset->toggleInsetCursor(bv);
1415 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1417 int const asc = lyxfont::maxAscent(font);
1418 int const desc = lyxfont::maxDescent(font);
1420 if (isCursorVisible())
1421 bv->hideLockedInsetCursor();
1423 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1424 toggleCursorVisible();
1428 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1432 if (!isCursorVisible()) {
1433 LyXFont font; // = GetFont(par, cursor.pos);
1435 int const asc = lyxfont::maxAscent(font);
1436 int const desc = lyxfont::maxDescent(font);
1437 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1439 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1440 setCursorVisible(true);
1445 void InsetTabular::hideInsetCursor(BufferView * bv)
1447 if (isCursorVisible()) {
1448 bv->hideLockedInsetCursor();
1449 setCursorVisible(false);
1454 void InsetTabular::fitInsetCursor(BufferView * bv) const
1456 if (the_locking_inset) {
1457 the_locking_inset->fitInsetCursor(bv);
1462 int const asc = lyxfont::maxAscent(font);
1463 int const desc = lyxfont::maxDescent(font);
1464 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1468 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1472 actcell = actrow = actcol = 0;
1473 int ly = tabular->GetDescentOfRow(actrow);
1475 // first search the right row
1476 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1477 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1478 tabular->GetAscentOfRow(actrow + 1) +
1479 tabular->GetAdditionalHeight(actrow + 1));
1481 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1483 actcell = tabular->GetCellNumber(actrow, actcol);
1485 // now search the right column
1486 int lx = tabular->GetWidthOfColumn(actcell) -
1487 tabular->GetAdditionalWidth(actcell);
1488 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1489 lx += tabular->GetWidthOfColumn(actcell + 1)
1490 + tabular->GetAdditionalWidth(actcell);
1492 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1497 int InsetTabular::getCellXPos(int cell) const
1501 for (; !tabular->IsFirstCellInRow(c); --c)
1503 int lx = tabular->GetWidthOfColumn(cell);
1504 for (; c < cell; ++c) {
1505 lx += tabular->GetWidthOfColumn(c);
1507 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1511 void InsetTabular::resetPos(BufferView * bv) const
1513 #ifdef WITH_WARNINGS
1514 #warning This should be fixed in the right manner (20011128 Jug)
1516 // fast hack to fix infinite repaintings!
1521 actcol = tabular->column_of_cell(actcell);
1524 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1525 if (tabular->IsLastCellInRow(cell)) {
1526 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1527 tabular->GetAscentOfRow(actrow + 1) +
1528 tabular->GetAdditionalHeight(actrow + 1));
1532 if (!locked || nodraw()) {
1533 if (the_locking_inset)
1534 inset_y = cursor_.y();
1537 // we need this only from here on!!!
1538 in_reset_pos = true;
1539 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1540 int new_x = getCellXPos(actcell);
1541 int old_x = cursor_.x();
1544 // cursor.x(getCellXPos(actcell) + offset);
1545 if ((actcol < tabular->columns()-1) && scroll(false) &&
1546 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1549 updateLocal(bv, FULL, false);
1550 } else if (the_locking_inset &&
1551 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1553 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1554 if (xx > (bv->workWidth()-20)) {
1555 scroll(bv, -(xx - bv->workWidth() + 60));
1556 updateLocal(bv, FULL, false);
1557 } else if (xx < 20) {
1563 updateLocal(bv, FULL, false);
1565 } else if ((cursor_.x() - offset) > 20 &&
1566 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1567 > (bv->workWidth() - 20)) {
1568 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1569 updateLocal(bv, FULL, false);
1570 } else if ((cursor_.x() - offset) < 20) {
1571 scroll(bv, 20 - cursor_.x() + offset);
1572 updateLocal(bv, FULL, false);
1573 } else if (scroll(false) && top_x > 20 &&
1574 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1575 scroll(bv, old_x - cursor_.x());
1576 updateLocal(bv, FULL, false);
1578 if (the_locking_inset) {
1579 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1580 inset_y = cursor_.y();
1582 if ((!the_locking_inset ||
1583 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1584 actcell != oldcell) {
1585 InsetTabular * inset = const_cast<InsetTabular *>(this);
1586 bv->owner()->getDialogs()->updateTabular(inset);
1589 in_reset_pos = false;
1593 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1595 if (lock && !old_locking_inset) {
1596 if (activateCellInset(bv))
1599 bool moved = isRightToLeft(bv)
1600 ? movePrevCell(bv) : moveNextCell(bv);
1602 return FINISHED_RIGHT;
1603 if (lock && activateCellInset(bv))
1607 return DISPATCHED_NOUPDATE;
1611 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1613 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1616 if (lock) { // behind the inset
1617 if (activateCellInset(bv, 0, 0, 0, true))
1621 return DISPATCHED_NOUPDATE;
1625 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1627 int const ocell = actcell;
1628 actcell = tabular->GetCellAbove(actcell);
1629 if (actcell == ocell) // we moved out of the inset
1635 if (old_locking_inset) {
1636 old_locking_inset->getCursorPos(bv, x, y);
1637 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1639 if (activateCellInset(bv, x, 0))
1642 return DISPATCHED_NOUPDATE;
1646 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1648 int const ocell = actcell;
1649 actcell = tabular->GetCellBelow(actcell);
1650 if (actcell == ocell) // we moved out of the inset
1651 return FINISHED_DOWN;
1656 if (old_locking_inset) {
1657 old_locking_inset->getCursorPos(bv, x, y);
1658 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1660 if (activateCellInset(bv, x, 0))
1663 return DISPATCHED_NOUPDATE;
1667 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1669 if (isRightToLeft(bv)) {
1670 if (tabular->IsFirstCellInRow(actcell)) {
1671 int row = tabular->row_of_cell(actcell);
1672 if (row == tabular->rows() - 1)
1674 actcell = tabular->GetLastCellInRow(row);
1675 actcell = tabular->GetCellBelow(actcell);
1682 if (tabular->IsLastCell(actcell))
1687 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1688 isRightToLeftPar(bv->buffer()->params);
1689 activateCellInset(bv, 0, 0, 0, !rtl);
1696 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1698 if (isRightToLeft(bv)) {
1699 if (tabular->IsLastCellInRow(actcell)) {
1700 int row = tabular->row_of_cell(actcell);
1703 actcell = tabular->GetFirstCellInRow(row);
1704 actcell = tabular->GetCellAbove(actcell);
1706 if (tabular->IsLastCell(actcell))
1711 if (!actcell) // first cell
1716 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1717 isRightToLeftPar(bv->buffer()->params);
1718 activateCellInset(bv, 0, 0, 0, !rtl);
1725 bool InsetTabular::deletable() const
1731 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1735 setSelection(0, tabular->GetNumberOfCells() - 1);
1737 if (hasSelection()) {
1738 setUndo(bv, Undo::EDIT,
1739 bv->text->cursor.par(),
1740 bv->text->cursor.par()->next());
1741 bool frozen = undo_frozen;
1744 // apply the fontchange on the whole selection
1749 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1750 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1751 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1752 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1757 updateLocal(bv, INIT, true);
1759 if (the_locking_inset)
1760 the_locking_inset->setFont(bv, font, tall);
1764 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1766 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1769 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1770 string const tmp = tabularFeature[i].feature;
1772 if (tmp == what.substr(0, tmp.length())) {
1773 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1774 //tabularFeatures[i].feature.length())) {
1775 action = tabularFeature[i].action;
1779 if (action == LyXTabular::LAST_ACTION)
1783 frontStrip(what.substr(tabularFeature[i].feature.length()));
1784 tabularFeatures(bv, action, val);
1788 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1789 string const & special, bool & flag)
1791 if (special == "dl_above") {
1794 } else if (special == "dl_below") {
1795 ltt.bottomDL = flag;
1797 } else if (special == "empty") {
1807 void InsetTabular::tabularFeatures(BufferView * bv,
1808 LyXTabular::Feature feature,
1809 string const & value)
1815 bool setLines = false;
1816 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1817 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1820 case LyXTabular::M_ALIGN_LEFT:
1821 case LyXTabular::ALIGN_LEFT:
1822 setAlign = LYX_ALIGN_LEFT;
1824 case LyXTabular::M_ALIGN_RIGHT:
1825 case LyXTabular::ALIGN_RIGHT:
1826 setAlign = LYX_ALIGN_RIGHT;
1828 case LyXTabular::M_ALIGN_CENTER:
1829 case LyXTabular::ALIGN_CENTER:
1830 setAlign = LYX_ALIGN_CENTER;
1832 case LyXTabular::M_VALIGN_TOP:
1833 case LyXTabular::VALIGN_TOP:
1834 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1836 case LyXTabular::M_VALIGN_BOTTOM:
1837 case LyXTabular::VALIGN_BOTTOM:
1838 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1840 case LyXTabular::M_VALIGN_CENTER:
1841 case LyXTabular::VALIGN_CENTER:
1842 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1847 if (hasSelection()) {
1848 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1850 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1851 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1853 setUndo(bv, Undo::FINISH,
1854 bv->text->cursor.par(),
1855 bv->text->cursor.par()->next());
1857 int row = tabular->row_of_cell(actcell);
1858 int column = tabular->column_of_cell(actcell);
1860 LyXTabular::ltType ltt;
1863 case LyXTabular::SET_PWIDTH:
1865 LyXLength const vallen(value);
1866 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1868 bool const update = (tmplen != vallen);
1869 tabular->SetColumnPWidth(actcell, vallen);
1872 for (int i = 0; i < tabular->rows(); ++i) {
1873 cell = tabular->GetCellNumber(i,column);
1874 tabular->GetCellInset(cell)->resizeLyXText(bv);
1876 updateLocal(bv, INIT, true);
1880 case LyXTabular::SET_MPWIDTH:
1882 LyXLength const vallen(value);
1883 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1885 bool const update = (tmplen != vallen);
1886 tabular->SetMColumnPWidth(actcell, vallen);
1888 for (int i = 0; i < tabular->rows(); ++i) {
1889 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1892 updateLocal(bv, INIT, true);
1896 case LyXTabular::SET_SPECIAL_COLUMN:
1897 case LyXTabular::SET_SPECIAL_MULTI:
1898 tabular->SetAlignSpecial(actcell,value,feature);
1899 updateLocal(bv, FULL, true);
1901 case LyXTabular::APPEND_ROW:
1902 // append the row into the tabular
1903 unlockInsetInInset(bv, the_locking_inset);
1904 tabular->AppendRow(bv->buffer()->params, actcell);
1905 updateLocal(bv, INIT, true);
1907 case LyXTabular::APPEND_COLUMN:
1908 // append the column into the tabular
1909 unlockInsetInInset(bv, the_locking_inset);
1910 tabular->AppendColumn(bv->buffer()->params, actcell);
1911 actcell = tabular->GetCellNumber(row, column);
1912 updateLocal(bv, INIT, true);
1914 case LyXTabular::DELETE_ROW:
1915 unlockInsetInInset(bv, the_locking_inset);
1916 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1917 tabular->DeleteRow(sel_row_start);
1919 if (sel_row_start >= tabular->rows())
1921 actcell = tabular->GetCellNumber(sel_row_start, column);
1923 updateLocal(bv, INIT, true);
1925 case LyXTabular::DELETE_COLUMN:
1926 unlockInsetInInset(bv, the_locking_inset);
1927 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1928 tabular->DeleteColumn(sel_col_start);
1930 if (sel_col_start >= tabular->columns())
1932 actcell = tabular->GetCellNumber(row, sel_col_start);
1934 updateLocal(bv, INIT, true);
1936 case LyXTabular::M_TOGGLE_LINE_TOP:
1938 case LyXTabular::TOGGLE_LINE_TOP:
1940 bool lineSet = !tabular->TopLine(actcell, flag);
1941 for (int i = sel_row_start; i <= sel_row_end; ++i)
1942 for (int j = sel_col_start; j <= sel_col_end; ++j)
1943 tabular->SetTopLine(
1944 tabular->GetCellNumber(i, j),
1946 updateLocal(bv, INIT, true);
1950 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1952 case LyXTabular::TOGGLE_LINE_BOTTOM:
1954 bool lineSet = !tabular->BottomLine(actcell, flag);
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j <= sel_col_end; ++j)
1957 tabular->SetBottomLine(
1958 tabular->GetCellNumber(i, j),
1961 updateLocal(bv, INIT, true);
1965 case LyXTabular::M_TOGGLE_LINE_LEFT:
1967 case LyXTabular::TOGGLE_LINE_LEFT:
1969 bool lineSet = !tabular->LeftLine(actcell, flag);
1970 for (int i = sel_row_start; i <= sel_row_end; ++i)
1971 for (int j = sel_col_start; j <= sel_col_end; ++j)
1972 tabular->SetLeftLine(
1973 tabular->GetCellNumber(i,j),
1976 updateLocal(bv, INIT, true);
1980 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1982 case LyXTabular::TOGGLE_LINE_RIGHT:
1984 bool lineSet = !tabular->RightLine(actcell, flag);
1985 for (int i = sel_row_start; i <= sel_row_end; ++i)
1986 for (int j = sel_col_start; j <= sel_col_end; ++j)
1987 tabular->SetRightLine(
1988 tabular->GetCellNumber(i,j),
1991 updateLocal(bv, INIT, true);
1995 case LyXTabular::M_ALIGN_LEFT:
1996 case LyXTabular::M_ALIGN_RIGHT:
1997 case LyXTabular::M_ALIGN_CENTER:
1999 case LyXTabular::ALIGN_LEFT:
2000 case LyXTabular::ALIGN_RIGHT:
2001 case LyXTabular::ALIGN_CENTER:
2002 for (int i = sel_row_start; i <= sel_row_end; ++i)
2003 for (int j = sel_col_start; j <= sel_col_end; ++j)
2004 tabular->SetAlignment(
2005 tabular->GetCellNumber(i, j),
2008 updateLocal(bv, INIT, true);
2010 case LyXTabular::M_VALIGN_TOP:
2011 case LyXTabular::M_VALIGN_BOTTOM:
2012 case LyXTabular::M_VALIGN_CENTER:
2014 case LyXTabular::VALIGN_TOP:
2015 case LyXTabular::VALIGN_BOTTOM:
2016 case LyXTabular::VALIGN_CENTER:
2017 for (int i = sel_row_start; i <= sel_row_end; ++i)
2018 for (int j = sel_col_start; j <= sel_col_end; ++j)
2019 tabular->SetVAlignment(
2020 tabular->GetCellNumber(i, j),
2022 updateLocal(bv, INIT, true);
2024 case LyXTabular::MULTICOLUMN:
2026 if (sel_row_start != sel_row_end) {
2027 Alert::alert(_("Impossible Operation!"),
2028 _("Multicolumns can only be horizontally."),
2032 // just multicol for one Single Cell
2033 if (!hasSelection()) {
2034 // check wether we are completly in a multicol
2035 if (tabular->IsMultiColumn(actcell)) {
2036 tabular->UnsetMultiColumn(actcell);
2037 updateLocal(bv, INIT, true);
2039 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2040 updateLocal(bv, CELL, true);
2044 // we have a selection so this means we just add all this
2045 // cells to form a multicolumn cell
2049 if (sel_cell_start > sel_cell_end) {
2050 s_start = sel_cell_end;
2051 s_end = sel_cell_start;
2053 s_start = sel_cell_start;
2054 s_end = sel_cell_end;
2056 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2059 updateLocal(bv, INIT, true);
2062 case LyXTabular::SET_ALL_LINES:
2064 case LyXTabular::UNSET_ALL_LINES:
2065 for (int i = sel_row_start; i <= sel_row_end; ++i)
2066 for (int j = sel_col_start; j <= sel_col_end; ++j)
2067 tabular->SetAllLines(
2068 tabular->GetCellNumber(i,j), setLines);
2069 updateLocal(bv, INIT, true);
2071 case LyXTabular::SET_LONGTABULAR:
2072 tabular->SetLongTabular(true);
2073 updateLocal(bv, INIT, true); // because this toggles displayed
2075 case LyXTabular::UNSET_LONGTABULAR:
2076 tabular->SetLongTabular(false);
2077 updateLocal(bv, INIT, true); // because this toggles displayed
2079 case LyXTabular::SET_ROTATE_TABULAR:
2080 tabular->SetRotateTabular(true);
2082 case LyXTabular::UNSET_ROTATE_TABULAR:
2083 tabular->SetRotateTabular(false);
2085 case LyXTabular::SET_ROTATE_CELL:
2086 for (int i = sel_row_start; i <= sel_row_end; ++i)
2087 for (int j = sel_col_start; j<=sel_col_end; ++j)
2088 tabular->SetRotateCell(
2089 tabular->GetCellNumber(i, j),
2092 case LyXTabular::UNSET_ROTATE_CELL:
2093 for (int i = sel_row_start; i <= sel_row_end; ++i)
2094 for (int j = sel_col_start; j <= sel_col_end; ++j)
2095 tabular->SetRotateCell(
2096 tabular->GetCellNumber(i, j), false);
2098 case LyXTabular::SET_USEBOX:
2100 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2101 if (val == tabular->GetUsebox(actcell))
2102 val = LyXTabular::BOX_NONE;
2103 for (int i = sel_row_start; i <= sel_row_end; ++i)
2104 for (int j = sel_col_start; j <= sel_col_end; ++j)
2106 tabular->GetCellNumber(i, j), val);
2109 case LyXTabular::UNSET_LTFIRSTHEAD:
2111 case LyXTabular::SET_LTFIRSTHEAD:
2112 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2113 checkLongtableSpecial(ltt, value, flag);
2114 tabular->SetLTHead(row, flag, ltt, true);
2116 case LyXTabular::UNSET_LTHEAD:
2118 case LyXTabular::SET_LTHEAD:
2119 (void)tabular->GetRowOfLTHead(row, ltt);
2120 checkLongtableSpecial(ltt, value, flag);
2121 tabular->SetLTHead(row, flag, ltt, false);
2123 case LyXTabular::UNSET_LTFOOT:
2125 case LyXTabular::SET_LTFOOT:
2126 (void)tabular->GetRowOfLTFoot(row, ltt);
2127 checkLongtableSpecial(ltt, value, flag);
2128 tabular->SetLTFoot(row, flag, ltt, false);
2130 case LyXTabular::UNSET_LTLASTFOOT:
2132 case LyXTabular::SET_LTLASTFOOT:
2133 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2134 checkLongtableSpecial(ltt, value, flag);
2135 tabular->SetLTFoot(row, flag, ltt, true);
2137 case LyXTabular::SET_LTNEWPAGE:
2139 bool what = !tabular->GetLTNewPage(row);
2140 tabular->SetLTNewPage(row, what);
2143 // dummy stuff just to avoid warnings
2144 case LyXTabular::LAST_ACTION:
2150 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2153 UpdatableInset * inset =
2154 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2155 LyXFont font(LyXFont::ALL_SANE);
2157 x = inset->x() + inset->width(bv, font);
2158 y = inset->descent(bv, font);
2160 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2161 //inset_y = cursor.y();
2162 inset->edit(bv, x, y, button);
2163 if (!the_locking_inset)
2165 updateLocal(bv, CELL, false);
2166 return (the_locking_inset != 0);
2170 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2173 inset_x = cursor_.x()
2174 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2175 inset_y = cursor_.y();
2176 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2180 bool InsetTabular::insetHit(BufferView *, int x, int) const
2183 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2187 // This returns paperWidth() if the cell-width is unlimited or the width
2188 // in pixels if we have a pwidth for this cell.
2189 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2191 LyXLength const len = tabular->GetPWidth(cell);
2195 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2199 int InsetTabular::getMaxWidth(BufferView * bv,
2200 UpdatableInset const * inset) const
2202 int cell = tabular->GetCellFromInset(inset, actcell);
2205 lyxerr << "Own inset not found, shouldn't really happen!"
2210 int w = getMaxWidthOfCell(bv, cell);
2212 // because the inset then subtracts it's top_x and owner->x()
2213 w += (inset->x() - top_x);
2220 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2222 resizeLyXText(bv, recursive);
2226 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2229 for(int i = 0; i < tabular->rows(); ++i) {
2230 for(int j = 0; j < tabular->columns(); ++j) {
2231 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2239 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2240 bool const recursive) const
2242 if (the_locking_inset)
2243 return the_locking_inset->getLyXText(bv, recursive);
2245 // if we're locked lock the actual insettext and return it's LyXText!!!
2247 UpdatableInset * inset =
2248 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2249 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2250 return the_locking_inset->getLyXText(bv, recursive);
2253 return Inset::getLyXText(bv, recursive);
2257 bool InsetTabular::showInsetDialog(BufferView * bv) const
2259 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2260 bv->owner()->getDialogs()
2261 ->showTabular(const_cast<InsetTabular *>(this));
2266 void InsetTabular::openLayoutDialog(BufferView * bv) const
2268 if (the_locking_inset) {
2269 InsetTabular * i = static_cast<InsetTabular *>
2270 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2272 i->openLayoutDialog(bv);
2276 bv->owner()->getDialogs()->showTabular(
2277 const_cast<InsetTabular *>(this));
2282 // function returns an object as defined in func_status.h:
2283 // states OK, Unknown, Disabled, On, Off.
2285 FuncStatus InsetTabular::getStatus(string const & what) const
2287 int action = LyXTabular::LAST_ACTION;
2291 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2292 string const tmp = tabularFeature[i].feature;
2293 if (tmp == what.substr(0, tmp.length())) {
2294 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2295 // tabularFeatures[i].feature.length())) {
2296 action = tabularFeature[i].action;
2300 if (action == LyXTabular::LAST_ACTION) {
2302 return status.unknown(true);
2305 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2310 LyXTabular::ltType dummyltt;
2313 if (hasSelection()) {
2314 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2316 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2320 case LyXTabular::SET_PWIDTH:
2321 case LyXTabular::SET_MPWIDTH:
2322 case LyXTabular::SET_SPECIAL_COLUMN:
2323 case LyXTabular::SET_SPECIAL_MULTI:
2324 return status.disabled(true);
2326 case LyXTabular::APPEND_ROW:
2327 case LyXTabular::APPEND_COLUMN:
2328 case LyXTabular::DELETE_ROW:
2329 case LyXTabular::DELETE_COLUMN:
2330 case LyXTabular::SET_ALL_LINES:
2331 case LyXTabular::UNSET_ALL_LINES:
2332 return status.clear();
2334 case LyXTabular::MULTICOLUMN:
2335 status.setOnOff(tabular->IsMultiColumn(actcell));
2337 case LyXTabular::M_TOGGLE_LINE_TOP:
2339 case LyXTabular::TOGGLE_LINE_TOP:
2340 status.setOnOff(tabular->TopLine(actcell, flag));
2342 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2344 case LyXTabular::TOGGLE_LINE_BOTTOM:
2345 status.setOnOff(tabular->BottomLine(actcell, flag));
2347 case LyXTabular::M_TOGGLE_LINE_LEFT:
2349 case LyXTabular::TOGGLE_LINE_LEFT:
2350 status.setOnOff(tabular->LeftLine(actcell, flag));
2352 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2354 case LyXTabular::TOGGLE_LINE_RIGHT:
2355 status.setOnOff(tabular->RightLine(actcell, flag));
2357 case LyXTabular::M_ALIGN_LEFT:
2359 case LyXTabular::ALIGN_LEFT:
2360 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2362 case LyXTabular::M_ALIGN_RIGHT:
2364 case LyXTabular::ALIGN_RIGHT:
2365 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2367 case LyXTabular::M_ALIGN_CENTER:
2369 case LyXTabular::ALIGN_CENTER:
2370 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2372 case LyXTabular::M_VALIGN_TOP:
2374 case LyXTabular::VALIGN_TOP:
2375 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2377 case LyXTabular::M_VALIGN_BOTTOM:
2379 case LyXTabular::VALIGN_BOTTOM:
2380 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2382 case LyXTabular::M_VALIGN_CENTER:
2384 case LyXTabular::VALIGN_CENTER:
2385 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2387 case LyXTabular::SET_LONGTABULAR:
2388 status.setOnOff(tabular->IsLongTabular());
2390 case LyXTabular::UNSET_LONGTABULAR:
2391 status.setOnOff(!tabular->IsLongTabular());
2393 case LyXTabular::SET_ROTATE_TABULAR:
2394 status.setOnOff(tabular->GetRotateTabular());
2396 case LyXTabular::UNSET_ROTATE_TABULAR:
2397 status.setOnOff(!tabular->GetRotateTabular());
2399 case LyXTabular::SET_ROTATE_CELL:
2400 status.setOnOff(tabular->GetRotateCell(actcell));
2402 case LyXTabular::UNSET_ROTATE_CELL:
2403 status.setOnOff(!tabular->GetRotateCell(actcell));
2405 case LyXTabular::SET_USEBOX:
2406 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2408 case LyXTabular::SET_LTFIRSTHEAD:
2409 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2411 case LyXTabular::SET_LTHEAD:
2412 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2414 case LyXTabular::SET_LTFOOT:
2415 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2417 case LyXTabular::SET_LTLASTFOOT:
2418 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2420 case LyXTabular::SET_LTNEWPAGE:
2421 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2425 status.disabled(true);
2432 vector<string> const InsetTabular::getLabelList() const
2434 return tabular->getLabelList();
2438 bool InsetTabular::copySelection(BufferView * bv)
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 const columns = sel_col_end - sel_col_start + 1;
2453 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2454 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2455 if (sel_row_start > sel_row_end) {
2456 swap(sel_row_start, sel_row_end);
2458 int const rows = sel_row_end - sel_row_start + 1;
2460 delete paste_tabular;
2461 paste_tabular = new LyXTabular(bv->buffer()->params,
2462 this, *tabular); // rows, columns);
2463 for (int i = 0; i < sel_row_start; ++i)
2464 paste_tabular->DeleteRow(0);
2465 while (paste_tabular->rows() > rows)
2466 paste_tabular->DeleteRow(rows);
2467 paste_tabular->SetTopLine(0, true, true);
2468 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2470 for (int i = 0; i < sel_col_start; ++i)
2471 paste_tabular->DeleteColumn(0);
2472 while (paste_tabular->columns() > columns)
2473 paste_tabular->DeleteColumn(columns);
2474 paste_tabular->SetLeftLine(0, true, true);
2475 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2479 paste_tabular->ascii(bv->buffer(), sstr,
2480 (int)parOwner()->params().depth(), true, '\t');
2481 bv->stuffClipboard(sstr.str().c_str());
2486 bool InsetTabular::pasteSelection(BufferView * bv)
2491 for (int r1 = 0, r2 = actrow;
2492 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2494 for(int c1 = 0, c2 = actcol;
2495 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2497 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2498 tabular->IsPartOfMultiColumn(r2,c2))
2500 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2504 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2508 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2509 int const n2 = tabular->GetCellNumber(r2, c2);
2510 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2511 tabular->GetCellInset(n2)->setOwner(this);
2512 tabular->GetCellInset(n2)->deleteLyXText(bv);
2519 bool InsetTabular::cutSelection()
2521 if (!hasSelection())
2524 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2525 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2526 if (sel_col_start > sel_col_end) {
2527 sel_col_start = sel_col_end;
2528 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2530 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2532 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2533 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2534 if (sel_row_start > sel_row_end) {
2535 swap(sel_row_start, sel_row_end);
2537 if (sel_cell_start > sel_cell_end) {
2538 swap(sel_cell_start, sel_cell_end);
2540 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2541 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2542 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2549 bool InsetTabular::isRightToLeft(BufferView * bv)
2551 return bv->getParentLanguage(this)->RightToLeft();
2555 bool InsetTabular::nodraw() const
2557 if (!UpdatableInset::nodraw() && the_locking_inset)
2558 return the_locking_inset->nodraw();
2559 return UpdatableInset::nodraw();
2563 int InsetTabular::scroll(bool recursive) const
2565 int sx = UpdatableInset::scroll(false);
2567 if (recursive && the_locking_inset)
2568 sx += the_locking_inset->scroll(recursive);
2574 bool InsetTabular::doClearArea() const
2576 return !locked || (need_update & (FULL|INIT));
2580 void InsetTabular::getSelection(int & srow, int & erow,
2581 int & scol, int & ecol) const
2583 int const start = hasSelection() ? sel_cell_start : actcell;
2584 int const end = hasSelection() ? sel_cell_end : actcell;
2586 srow = tabular->row_of_cell(start);
2587 erow = tabular->row_of_cell(end);
2592 scol = tabular->column_of_cell(start);
2593 ecol = tabular->column_of_cell(end);
2597 ecol = tabular->right_column_of_cell(end);
2602 Paragraph * InsetTabular::getParFromID(int id) const
2605 for(int i = 0; i < tabular->rows(); ++i) {
2606 for(int j = 0; j < tabular->columns(); ++j) {
2607 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2615 Paragraph * InsetTabular::firstParagraph() const
2617 if (the_locking_inset)
2618 return the_locking_inset->firstParagraph();
2623 Paragraph * InsetTabular::getFirstParagraph(int i) const
2625 return (i < tabular->GetNumberOfCells())
2626 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2631 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2633 if (the_locking_inset)
2634 return the_locking_inset->cursor(bv);
2635 return Inset::cursor(bv);
2639 Inset * InsetTabular::getInsetFromID(int id_arg) const
2642 return const_cast<InsetTabular *>(this);
2645 for(int i = 0; i < tabular->rows(); ++i) {
2646 for(int j = 0; j < tabular->columns(); ++j) {
2647 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2656 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2659 if (the_locking_inset) {
2660 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2665 if (tabular->IsLastCell(actcell)) {
2666 bv->unlockInset(const_cast<InsetTabular *>(this));
2672 // otherwise we have to lock the next inset and ask for it's selecttion
2673 UpdatableInset * inset =
2674 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2675 inset->edit(bv, 0, 0, 0);
2676 string const str(selectNextWordInt(bv, value));
2684 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2686 // when entering this function the inset should be ALWAYS locked!
2687 lyx::Assert(the_locking_inset);
2689 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2693 if (tabular->IsLastCell(actcell)) {
2694 bv->unlockInset(const_cast<InsetTabular *>(this));
2698 // otherwise we have to lock the next inset and ask for it's selecttion
2699 UpdatableInset * inset =
2700 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2702 return selectNextWordInt(bv, value);
2706 void InsetTabular::selectSelectedWord(BufferView * bv)
2708 if (the_locking_inset) {
2709 the_locking_inset->selectSelectedWord(bv);
2716 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2718 if (the_locking_inset) {
2719 the_locking_inset->toggleSelection(bv, kill_selection);
2724 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2728 if (the_locking_inset) {
2729 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2731 updateLocal(bv, CELL, false);
2734 if (tabular->IsLastCell(actcell)) {
2736 bv->unlockInset(const_cast<InsetTabular *>(this));
2741 // otherwise we have to lock the next inset and search there
2742 UpdatableInset * inset =
2743 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2745 bool const ret = searchForward(bv, str, cs, mw);
2747 updateLocal(bv, CELL, false);
2752 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2756 if (the_locking_inset) {
2757 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2759 updateLocal(bv, CELL, false);
2762 if (!actcell) { // we are already in the first cell
2764 bv->unlockInset(const_cast<InsetTabular *>(this));
2769 // otherwise we have to lock the next inset and search there
2770 UpdatableInset * inset =
2771 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2772 inset->edit(bv, false);
2773 bool const ret = searchBackward(bv, str, cs, mw);
2775 updateLocal(bv, CELL, false);
2780 bool InsetTabular::insetAllowed(Inset::Code code) const
2782 if (the_locking_inset)
2783 return the_locking_inset->insetAllowed(code);
2788 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2790 const int cell = tabular->GetCellFromInset(in, actcell);
2793 return tabular->GetPWidth(cell).zero();
2795 // well we didn't obviously find it so maybe our owner knows more
2797 return owner()->forceDefaultParagraphs(in);
2798 // if we're here there is really something strange going on!!!
2802 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2805 if (buf.find('\t') == string::npos)
2811 string::size_type len = buf.length();
2812 string::size_type p = 0;
2815 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2824 maxCols = max(cols, maxCols);
2830 maxCols = max(cols, maxCols);
2831 LyXTabular * loctab;
2836 delete paste_tabular;
2837 paste_tabular = new LyXTabular(bv->buffer()->params,
2838 this, rows, maxCols);
2839 loctab = paste_tabular;
2842 loctab = tabular.get();
2847 string::size_type op = 0;
2848 int cells = loctab->GetNumberOfCells();
2851 rows = loctab->rows();
2852 int const columns = loctab->columns();
2853 while ((cell < cells) && (p < len) && (row < rows) &&
2854 (p = buf.find_first_of("\t\n", p)) != string::npos)
2860 // we can only set this if we are not too far right
2861 if (cols < columns) {
2862 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2868 // we can only set this if we are not too far right
2870 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2874 cell = loctab->GetCellNumber(row, cols);
2880 // check for the last cell if there is no trailing '\n'
2881 if ((cell < cells) && (op < len))
2882 loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));