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;
583 the_locking_inset = 0;
589 actcell = tabular->GetNumberOfCells() - 1;
596 void InsetTabular::insetUnlock(BufferView * bv)
598 if (the_locking_inset) {
599 the_locking_inset->insetUnlock(bv);
600 the_locking_inset = 0;
605 if (scroll(false) || hasSelection()) {
610 updateLocal(bv, FULL, false);
615 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
616 bool mark_dirty) const
620 calculate_dimensions_of_cells(bv, font, true);
622 if (!locked && what == CELL)
624 if (need_update < what) // only set this if it has greater update
626 #if 0 // maybe this should not be done!
627 if ((what == INIT) && hasSelection()) {
632 if (need_update != NONE) {
633 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
634 if (locked) // && (what != NONE))
640 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
642 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
647 if (inset == tabular->GetCellInset(actcell)) {
648 lyxerr[Debug::INSETTEXT] << "OK" << endl;
649 the_locking_inset = tabular->GetCellInset(actcell);
652 } else if (!the_locking_inset) {
653 int const n = tabular->GetNumberOfCells();
654 int const id = inset->id();
655 for (int i = 0; i < n; ++i) {
656 InsetText * in = tabular->GetCellInset(i);
659 the_locking_inset = in;
664 if (in->getInsetFromID(id)) {
667 return the_locking_inset->lockInsetInInset(bv, inset);
670 } else if (the_locking_inset && (the_locking_inset == inset)) {
671 lyxerr[Debug::INSETTEXT] << "OK" << endl;
673 } else if (the_locking_inset) {
674 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
675 return the_locking_inset->lockInsetInInset(bv, inset);
677 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
682 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
685 if (!the_locking_inset)
687 if (the_locking_inset == inset) {
688 the_locking_inset->insetUnlock(bv);
689 the_locking_inset = 0;
691 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
697 updateLocal(bv, CELL, false);
698 // showInsetCursor(bv, false);
701 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
702 if (inset->lyxCode() == TABULAR_CODE &&
703 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
704 bv->owner()->getDialogs()->updateTabular(this);
713 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
715 Inset * tl_inset = inset;
716 // look if this inset is really inside myself!
717 while(tl_inset->owner() && tl_inset->owner() != this)
718 tl_inset = tl_inset->owner();
719 // if we enter here it's not ower inset
720 if (!tl_inset->owner())
722 // we only have to do this if this is a subinset of our cells
723 if (tl_inset != inset) {
724 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
727 updateLocal(bv, CELL, false);
732 unsigned int InsetTabular::insetInInsetY()
734 if (!the_locking_inset)
736 return inset_y + the_locking_inset->insetInInsetY();
740 UpdatableInset * InsetTabular::getLockingInset() const
742 return the_locking_inset ? the_locking_inset->getLockingInset() :
743 const_cast<InsetTabular *>(this);
747 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
751 if (the_locking_inset)
752 return the_locking_inset->getFirstLockingInsetOfType(c);
757 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
759 if (the_locking_inset)
760 return the_locking_inset->insertInset(bv, inset);
765 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
767 if (hasSelection() && (button == 3))
770 if (hasSelection()) {
772 updateLocal(bv, SELECTION, false);
775 int const ocell = actcell;
776 int const orow = actrow;
781 updateLocal(bv, NONE, false);
785 if ((ocell != actcell) && the_locking_inset) {
786 the_locking_inset->insetUnlock(bv);
787 the_locking_inset = 0;
794 bool const inset_hit = insetHit(bv, x, y);
796 if ((ocell == actcell) && the_locking_inset && inset_hit) {
798 the_locking_inset->insetButtonPress(bv,
799 x - inset_x, y - inset_y,
802 } else if (the_locking_inset) {
803 the_locking_inset->insetUnlock(bv);
805 the_locking_inset = 0;
807 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
810 if (inset_hit && bv->theLockingInset()) {
811 // only activate the Inset so that no internal inset is hit
812 // by this call. It should be only hit by the insetButtonPress call.
813 if (activateCellInsetAbs(bv, 0, 0, 0))
814 the_locking_inset->insetButtonPress(bv,
824 bool InsetTabular::insetButtonRelease(BufferView * bv,
825 int x, int y, int button)
828 if (the_locking_inset)
829 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
830 y - inset_y, button);
831 if (button == 3 && !ret) {
832 bv->owner()->getDialogs()->showTabular(this);
839 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
841 if (the_locking_inset) {
842 the_locking_inset->insetMotionNotify(bv,
850 // int const old_cell = actcell;
853 if (!hasSelection()) {
854 setSelection(actcell, actcell);
856 setSelection(sel_cell_start, actcell);
858 updateLocal(bv, SELECTION, false);
863 void InsetTabular::insetKeyPress(XKeyEvent * xke)
865 if (the_locking_inset) {
866 the_locking_inset->insetKeyPress(xke);
872 UpdatableInset::RESULT
873 InsetTabular::localDispatch(BufferView * bv, kb_action action,
876 // We need to save the value of the_locking_inset as the call to
877 // the_locking_inset->LocalDispatch might unlock it.
878 old_locking_inset = the_locking_inset;
879 UpdatableInset::RESULT result =
880 UpdatableInset::localDispatch(bv, action, arg);
881 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
886 if ((action < 0) && arg.empty())
889 bool hs = hasSelection();
892 // this one have priority over the locked InsetText, if we're not already
893 // inside another tabular then that one get's priority!
894 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
899 unlockInsetInInset(bv, the_locking_inset);
900 if (action == LFUN_TAB)
901 moveNextCell(bv, old_locking_inset != 0);
903 movePrevCell(bv, old_locking_inset != 0);
906 updateLocal(bv, SELECTION, false);
907 if (!the_locking_inset) {
909 return DISPATCHED_NOUPDATE;
912 // this to avoid compiler warnings.
918 if (the_locking_inset) {
919 result = the_locking_inset->localDispatch(bv, action, arg);
920 if (result == DISPATCHED_NOUPDATE) {
923 if (sc != scroll()) { // inset has been scrolled
924 the_locking_inset->toggleInsetCursor(bv);
925 updateLocal(bv, FULL, false);
926 the_locking_inset->toggleInsetCursor(bv);
929 } else if (result == DISPATCHED) {
930 the_locking_inset->toggleInsetCursor(bv);
931 updateLocal(bv, CELL, false);
932 the_locking_inset->toggleInsetCursor(bv);
934 } else if (result == FINISHED_UP) {
936 } else if (result == FINISHED_DOWN) {
938 } else if (result == FINISHED_RIGHT) {
946 // --- Cursor Movements ----------------------------------
947 case LFUN_RIGHTSEL: {
948 int const start = hasSelection() ? sel_cell_start : actcell;
949 if (tabular->IsLastCellInRow(actcell)) {
950 setSelection(start, actcell);
955 // if we are starting a selection, only select
956 // the current cell at the beginning
957 if (hasSelection()) {
958 moveRight(bv, false);
961 setSelection(start, end);
962 updateLocal(bv, SELECTION, false);
966 result = moveRight(bv);
969 updateLocal(bv, SELECTION, false);
972 int const start = hasSelection() ? sel_cell_start : actcell;
973 if (tabular->IsFirstCellInRow(actcell)) {
974 setSelection(start, actcell);
979 // if we are starting a selection, only select
980 // the current cell at the beginning
981 if (hasSelection()) {
985 setSelection(start, end);
986 updateLocal(bv, SELECTION, false);
990 result = moveLeft(bv);
993 updateLocal(bv, SELECTION, false);
996 int const start = hasSelection() ? sel_cell_start : actcell;
997 int const ocell = actcell;
998 // if we are starting a selection, only select
999 // the current cell at the beginning
1000 if (hasSelection()) {
1001 moveDown(bv, false);
1002 if ((ocell == sel_cell_end) ||
1003 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1004 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1006 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1008 setSelection(start, start);
1010 updateLocal(bv, SELECTION, false);
1014 result = moveDown(bv, old_locking_inset != 0);
1017 updateLocal(bv, SELECTION, false);
1021 int const start = hasSelection() ? sel_cell_start : actcell;
1022 int const ocell = actcell;
1023 // if we are starting a selection, only select
1024 // the current cell at the beginning
1025 if (hasSelection()) {
1027 if ((ocell == sel_cell_end) ||
1028 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1029 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1031 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1033 setSelection(start, start);
1035 updateLocal(bv, SELECTION, false);
1039 result = moveUp(bv, old_locking_inset != 0);
1042 updateLocal(bv, SELECTION, false);
1045 UpdateCodes code = CURSOR;
1050 int column = actcol;
1051 unlockInsetInInset(bv, the_locking_inset);
1052 if (bv->text->first_y + bv->painter().paperHeight() <
1053 (top_baseline + tabular->GetHeightOfTabular()))
1055 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1057 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1059 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1062 updateLocal(bv, code, false);
1066 UpdateCodes code = CURSOR;
1071 int column = actcol;
1072 unlockInsetInInset(bv, the_locking_inset);
1073 if (top_baseline < 0) {
1074 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1076 if (top_baseline > 0)
1079 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1084 updateLocal(bv, code, false);
1087 // none of these make sense for insettabular,
1088 // but we must catch them to prevent any
1089 // selection from being confused
1093 case LFUN_WORDLEFTSEL:
1094 case LFUN_WORDRIGHT:
1095 case LFUN_WORDRIGHTSEL:
1096 case LFUN_DOWN_PARAGRAPH:
1097 case LFUN_DOWN_PARAGRAPHSEL:
1098 case LFUN_UP_PARAGRAPH:
1099 case LFUN_UP_PARAGRAPHSEL:
1100 case LFUN_BACKSPACE:
1106 case LFUN_BEGINNINGBUF:
1107 case LFUN_BEGINNINGBUFSEL:
1109 case LFUN_ENDBUFSEL:
1111 case LFUN_LAYOUT_TABULAR:
1112 bv->owner()->getDialogs()->showTabular(this);
1114 case LFUN_TABULAR_FEATURE:
1115 if (!tabularFeatures(bv, arg))
1116 result = UNDISPATCHED;
1118 // insert file functions
1119 case LFUN_FILE_INSERT_ASCII_PARA:
1120 case LFUN_FILE_INSERT_ASCII:
1122 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1125 if (insertAsciiString(bv, tmpstr, false))
1126 updateLocal(bv, INIT, true);
1128 result = UNDISPATCHED;
1131 // cut and paste functions
1133 if (!copySelection(bv))
1135 setUndo(bv, Undo::DELETE,
1136 bv->text->cursor.par(),
1137 bv->text->cursor.par()->next());
1139 updateLocal(bv, INIT, true);
1142 if (!hasSelection())
1147 case LFUN_PASTESELECTION:
1149 string const clip(bv->getClipboard());
1153 if (clip.find('\t') != string::npos) {
1157 string::size_type len = clip.length();
1158 string::size_type p = 0;
1161 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1169 maxCols = max(cols, maxCols);
1175 maxCols = max(cols, maxCols);
1176 delete paste_tabular;
1177 paste_tabular = new LyXTabular(bv->buffer()->params,
1178 this, rows, maxCols);
1179 string::size_type op = 0;
1181 int cells = paste_tabular->GetNumberOfCells();
1183 while ((cell < cells) && (p < len) &&
1184 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1189 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1194 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1195 while (cols++ < maxCols)
1203 // check for the last cell if there is no trailing '\n'
1204 if ((cell < cells) && (op < len))
1205 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1208 if (!insertAsciiString(bv, clip, true))
1211 // so that the clipboard is used and it goes on
1213 // and executes LFUN_PASTESELECTION in insettext!
1214 delete paste_tabular;
1219 if (hasPasteBuffer()) {
1220 setUndo(bv, Undo::INSERT,
1221 bv->text->cursor.par(),
1222 bv->text->cursor.par()->next());
1224 updateLocal(bv, INIT, true);
1227 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1229 // handle font changing stuff on selection before we lock the inset
1230 // in the default part!
1231 result = UNDISPATCHED;
1242 case LFUN_UNDERLINE:
1243 case LFUN_FONT_SIZE:
1244 if (bv->Dispatch(action, arg))
1245 result = DISPATCHED;
1251 // we try to activate the actual inset and put this event down to
1252 // the insets dispatch function.
1253 if ((result == DISPATCHED) || the_locking_inset)
1256 if (activateCellInset(bv)) {
1257 // reset need_update setted in above function!
1259 result = the_locking_inset->localDispatch(bv, action, arg);
1260 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1261 unlockInsetInInset(bv, the_locking_inset);
1263 // we need to update if this was requested before
1264 updateLocal(bv, NONE, false);
1265 return UNDISPATCHED;
1268 // so the below CELL is not set because this is higher
1269 // priority and we get a full redraw
1270 need_update = SELECTION;
1273 updateLocal(bv, CELL, false);
1278 if (result < FINISHED) {
1279 if (!the_locking_inset) {
1280 if (bv->fitCursor())
1281 updateLocal(bv, FULL, false);
1283 showInsetCursor(bv);
1286 bv->unlockInset(this);
1291 int InsetTabular::latex(Buffer const * buf, ostream & os,
1292 bool fragile, bool fp) const
1294 return tabular->latex(buf, os, fragile, fp);
1298 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1301 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1303 return tabular->ascii(buf, os, 0, false,0);
1307 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1310 int const ret = tabular->ascii(buf,os,
1311 (int)parOwner()->params().depth(),
1318 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1323 // if the table is inside a float it doesn't need the informaltable
1324 // wrapper. Search for it.
1325 for(master = owner();
1326 master && master->lyxCode() != Inset::FLOAT_CODE;
1327 master = master->owner());
1330 os << "<informaltable>\n";
1333 ret+= tabular->docBook(buf,os);
1335 os << "</informaltable>\n";
1342 void InsetTabular::validate(LaTeXFeatures & features) const
1344 tabular->Validate(features);
1348 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1349 LyXFont const & font,
1356 bool changed = false;
1358 // if we have a locking_inset we should have to check only this cell for
1359 // change so I'll try this to have a boost, but who knows ;)
1360 if ((need_update != INIT) &&
1361 (the_locking_inset == tabular->GetCellInset(actcell))) {
1362 for(int i = 0; i < tabular->columns(); ++i) {
1363 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1365 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1368 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1369 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1370 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1373 for (int i = 0; i < tabular->rows(); ++i) {
1376 for (int j = 0; j < tabular->columns(); ++j) {
1377 if (tabular->IsPartOfMultiColumn(i,j))
1380 inset = tabular->GetCellInset(cell);
1381 if (!reinit && !tabular->GetPWidth(cell).zero())
1382 inset->update(bv, font, false);
1383 maxAsc = max(maxAsc, inset->ascent(bv, font));
1384 maxDesc = max(maxDesc, inset->descent(bv, font));
1385 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1387 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1388 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1396 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1398 if (the_locking_inset) {
1399 the_locking_inset->getCursorPos(bv, x, y);
1402 x = cursor_.x() - top_x;
1407 void InsetTabular::toggleInsetCursor(BufferView * bv)
1410 if (isCursorVisible())
1411 bv->hideLockedInsetCursor();
1414 if (the_locking_inset) {
1415 the_locking_inset->toggleInsetCursor(bv);
1419 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1421 int const asc = lyxfont::maxAscent(font);
1422 int const desc = lyxfont::maxDescent(font);
1424 if (isCursorVisible())
1425 bv->hideLockedInsetCursor();
1427 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1428 toggleCursorVisible();
1432 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1436 if (!isCursorVisible()) {
1437 LyXFont font; // = GetFont(par, cursor.pos);
1439 int const asc = lyxfont::maxAscent(font);
1440 int const desc = lyxfont::maxDescent(font);
1441 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1443 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1444 setCursorVisible(true);
1449 void InsetTabular::hideInsetCursor(BufferView * bv)
1451 if (isCursorVisible()) {
1452 bv->hideLockedInsetCursor();
1453 setCursorVisible(false);
1458 void InsetTabular::fitInsetCursor(BufferView * bv) const
1460 if (the_locking_inset) {
1461 int old_first_y = bv->text->first_y;
1462 the_locking_inset->fitInsetCursor(bv);
1463 if (old_first_y != bv->text->first_y)
1469 int const asc = lyxfont::maxAscent(font);
1470 int const desc = lyxfont::maxDescent(font);
1471 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1476 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1480 actcell = actrow = actcol = 0;
1481 int ly = tabular->GetDescentOfRow(actrow);
1483 // first search the right row
1484 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1485 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1486 tabular->GetAscentOfRow(actrow + 1) +
1487 tabular->GetAdditionalHeight(actrow + 1));
1489 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1491 actcell = tabular->GetCellNumber(actrow, actcol);
1493 // now search the right column
1494 int lx = tabular->GetWidthOfColumn(actcell) -
1495 tabular->GetAdditionalWidth(actcell);
1496 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1497 lx += tabular->GetWidthOfColumn(actcell + 1)
1498 + tabular->GetAdditionalWidth(actcell);
1500 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1505 int InsetTabular::getCellXPos(int cell) const
1509 for (; !tabular->IsFirstCellInRow(c); --c)
1511 int lx = tabular->GetWidthOfColumn(cell);
1512 for (; c < cell; ++c) {
1513 lx += tabular->GetWidthOfColumn(c);
1515 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1519 void InsetTabular::resetPos(BufferView * bv) const
1521 #ifdef WITH_WARNINGS
1522 #warning This should be fixed in the right manner (20011128 Jug)
1524 // fast hack to fix infinite repaintings!
1529 actcol = tabular->column_of_cell(actcell);
1532 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1533 if (tabular->IsLastCellInRow(cell)) {
1534 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1535 tabular->GetAscentOfRow(actrow + 1) +
1536 tabular->GetAdditionalHeight(actrow + 1));
1540 if (!locked || nodraw()) {
1541 if (the_locking_inset)
1542 inset_y = cursor_.y();
1545 // we need this only from here on!!!
1546 in_reset_pos = true;
1547 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1548 int new_x = getCellXPos(actcell);
1549 int old_x = cursor_.x();
1552 // cursor.x(getCellXPos(actcell) + offset);
1553 if ((actcol < tabular->columns()-1) && scroll(false) &&
1554 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1557 updateLocal(bv, FULL, false);
1558 } else if (the_locking_inset &&
1559 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1561 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1562 if (xx > (bv->workWidth()-20)) {
1563 scroll(bv, -(xx - bv->workWidth() + 60));
1564 updateLocal(bv, FULL, false);
1565 } else if (xx < 20) {
1571 updateLocal(bv, FULL, false);
1573 } else if ((cursor_.x() - offset) > 20 &&
1574 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1575 > (bv->workWidth() - 20)) {
1576 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1577 updateLocal(bv, FULL, false);
1578 } else if ((cursor_.x() - offset) < 20) {
1579 scroll(bv, 20 - cursor_.x() + offset);
1580 updateLocal(bv, FULL, false);
1581 } else if (scroll(false) && top_x > 20 &&
1582 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1583 scroll(bv, old_x - cursor_.x());
1584 updateLocal(bv, FULL, false);
1586 if (the_locking_inset) {
1587 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1588 inset_y = cursor_.y();
1590 if ((!the_locking_inset ||
1591 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1592 actcell != oldcell) {
1593 InsetTabular * inset = const_cast<InsetTabular *>(this);
1594 bv->owner()->getDialogs()->updateTabular(inset);
1597 in_reset_pos = false;
1601 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1603 if (lock && !old_locking_inset) {
1604 if (activateCellInset(bv))
1607 bool moved = isRightToLeft(bv)
1608 ? movePrevCell(bv) : moveNextCell(bv);
1610 return FINISHED_RIGHT;
1611 if (lock && activateCellInset(bv))
1615 return DISPATCHED_NOUPDATE;
1619 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1621 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1624 if (lock) { // behind the inset
1625 if (activateCellInset(bv, 0, 0, 0, true))
1629 return DISPATCHED_NOUPDATE;
1633 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1635 int const ocell = actcell;
1636 actcell = tabular->GetCellAbove(actcell);
1637 if (actcell == ocell) // we moved out of the inset
1643 if (old_locking_inset) {
1644 old_locking_inset->getCursorPos(bv, x, y);
1645 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1647 if (activateCellInset(bv, x, 0))
1650 return DISPATCHED_NOUPDATE;
1654 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1656 int const ocell = actcell;
1657 actcell = tabular->GetCellBelow(actcell);
1658 if (actcell == ocell) // we moved out of the inset
1659 return FINISHED_DOWN;
1664 if (old_locking_inset) {
1665 old_locking_inset->getCursorPos(bv, x, y);
1666 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1668 if (activateCellInset(bv, x, 0))
1671 return DISPATCHED_NOUPDATE;
1675 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1677 if (isRightToLeft(bv)) {
1678 if (tabular->IsFirstCellInRow(actcell)) {
1679 int row = tabular->row_of_cell(actcell);
1680 if (row == tabular->rows() - 1)
1682 actcell = tabular->GetLastCellInRow(row);
1683 actcell = tabular->GetCellBelow(actcell);
1690 if (tabular->IsLastCell(actcell))
1695 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1696 isRightToLeftPar(bv->buffer()->params);
1697 activateCellInset(bv, 0, 0, 0, !rtl);
1704 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1706 if (isRightToLeft(bv)) {
1707 if (tabular->IsLastCellInRow(actcell)) {
1708 int row = tabular->row_of_cell(actcell);
1711 actcell = tabular->GetFirstCellInRow(row);
1712 actcell = tabular->GetCellAbove(actcell);
1714 if (tabular->IsLastCell(actcell))
1719 if (!actcell) // first cell
1724 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1725 isRightToLeftPar(bv->buffer()->params);
1726 activateCellInset(bv, 0, 0, 0, !rtl);
1733 bool InsetTabular::deletable() const
1739 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1743 setSelection(0, tabular->GetNumberOfCells() - 1);
1745 if (hasSelection()) {
1746 setUndo(bv, Undo::EDIT,
1747 bv->text->cursor.par(),
1748 bv->text->cursor.par()->next());
1749 bool frozen = undo_frozen;
1752 // apply the fontchange on the whole selection
1757 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1758 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1759 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1760 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1765 updateLocal(bv, INIT, true);
1767 if (the_locking_inset)
1768 the_locking_inset->setFont(bv, font, tall);
1772 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1774 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1777 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1778 string const tmp = tabularFeature[i].feature;
1780 if (tmp == what.substr(0, tmp.length())) {
1781 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1782 //tabularFeatures[i].feature.length())) {
1783 action = tabularFeature[i].action;
1787 if (action == LyXTabular::LAST_ACTION)
1791 frontStrip(what.substr(tabularFeature[i].feature.length()));
1792 tabularFeatures(bv, action, val);
1796 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1797 string const & special, bool & flag)
1799 if (special == "dl_above") {
1802 } else if (special == "dl_below") {
1803 ltt.bottomDL = flag;
1805 } else if (special == "empty") {
1815 void InsetTabular::tabularFeatures(BufferView * bv,
1816 LyXTabular::Feature feature,
1817 string const & value)
1823 bool setLines = false;
1824 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1825 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1828 case LyXTabular::M_ALIGN_LEFT:
1829 case LyXTabular::ALIGN_LEFT:
1830 setAlign = LYX_ALIGN_LEFT;
1832 case LyXTabular::M_ALIGN_RIGHT:
1833 case LyXTabular::ALIGN_RIGHT:
1834 setAlign = LYX_ALIGN_RIGHT;
1836 case LyXTabular::M_ALIGN_CENTER:
1837 case LyXTabular::ALIGN_CENTER:
1838 setAlign = LYX_ALIGN_CENTER;
1840 case LyXTabular::M_VALIGN_TOP:
1841 case LyXTabular::VALIGN_TOP:
1842 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1844 case LyXTabular::M_VALIGN_BOTTOM:
1845 case LyXTabular::VALIGN_BOTTOM:
1846 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1848 case LyXTabular::M_VALIGN_CENTER:
1849 case LyXTabular::VALIGN_CENTER:
1850 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1855 if (hasSelection()) {
1856 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1858 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1859 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1861 setUndo(bv, Undo::FINISH,
1862 bv->text->cursor.par(),
1863 bv->text->cursor.par()->next());
1865 int row = tabular->row_of_cell(actcell);
1866 int column = tabular->column_of_cell(actcell);
1868 LyXTabular::ltType ltt;
1871 case LyXTabular::SET_PWIDTH:
1873 LyXLength const vallen(value);
1874 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1876 bool const update = (tmplen != vallen);
1877 tabular->SetColumnPWidth(actcell, vallen);
1880 for (int i = 0; i < tabular->rows(); ++i) {
1881 cell = tabular->GetCellNumber(i,column);
1882 tabular->GetCellInset(cell)->resizeLyXText(bv);
1884 updateLocal(bv, INIT, true);
1888 case LyXTabular::SET_MPWIDTH:
1890 LyXLength const vallen(value);
1891 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1893 bool const update = (tmplen != vallen);
1894 tabular->SetMColumnPWidth(actcell, vallen);
1896 for (int i = 0; i < tabular->rows(); ++i) {
1897 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1900 updateLocal(bv, INIT, true);
1904 case LyXTabular::SET_SPECIAL_COLUMN:
1905 case LyXTabular::SET_SPECIAL_MULTI:
1906 tabular->SetAlignSpecial(actcell,value,feature);
1907 updateLocal(bv, FULL, true);
1909 case LyXTabular::APPEND_ROW:
1910 // append the row into the tabular
1911 unlockInsetInInset(bv, the_locking_inset);
1912 tabular->AppendRow(bv->buffer()->params, actcell);
1913 updateLocal(bv, INIT, true);
1915 case LyXTabular::APPEND_COLUMN:
1916 // append the column into the tabular
1917 unlockInsetInInset(bv, the_locking_inset);
1918 tabular->AppendColumn(bv->buffer()->params, actcell);
1919 actcell = tabular->GetCellNumber(row, column);
1920 updateLocal(bv, INIT, true);
1922 case LyXTabular::DELETE_ROW:
1923 unlockInsetInInset(bv, the_locking_inset);
1924 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1925 tabular->DeleteRow(sel_row_start);
1927 if (sel_row_start >= tabular->rows())
1929 actcell = tabular->GetCellNumber(sel_row_start, column);
1931 updateLocal(bv, INIT, true);
1933 case LyXTabular::DELETE_COLUMN:
1934 unlockInsetInInset(bv, the_locking_inset);
1935 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1936 tabular->DeleteColumn(sel_col_start);
1938 if (sel_col_start >= tabular->columns())
1940 actcell = tabular->GetCellNumber(row, sel_col_start);
1942 updateLocal(bv, INIT, true);
1944 case LyXTabular::M_TOGGLE_LINE_TOP:
1946 case LyXTabular::TOGGLE_LINE_TOP:
1948 bool lineSet = !tabular->TopLine(actcell, flag);
1949 for (int i = sel_row_start; i <= sel_row_end; ++i)
1950 for (int j = sel_col_start; j <= sel_col_end; ++j)
1951 tabular->SetTopLine(
1952 tabular->GetCellNumber(i, j),
1954 updateLocal(bv, INIT, true);
1958 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1960 case LyXTabular::TOGGLE_LINE_BOTTOM:
1962 bool lineSet = !tabular->BottomLine(actcell, flag);
1963 for (int i = sel_row_start; i <= sel_row_end; ++i)
1964 for (int j = sel_col_start; j <= sel_col_end; ++j)
1965 tabular->SetBottomLine(
1966 tabular->GetCellNumber(i, j),
1969 updateLocal(bv, INIT, true);
1973 case LyXTabular::M_TOGGLE_LINE_LEFT:
1975 case LyXTabular::TOGGLE_LINE_LEFT:
1977 bool lineSet = !tabular->LeftLine(actcell, flag);
1978 for (int i = sel_row_start; i <= sel_row_end; ++i)
1979 for (int j = sel_col_start; j <= sel_col_end; ++j)
1980 tabular->SetLeftLine(
1981 tabular->GetCellNumber(i,j),
1984 updateLocal(bv, INIT, true);
1988 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1990 case LyXTabular::TOGGLE_LINE_RIGHT:
1992 bool lineSet = !tabular->RightLine(actcell, flag);
1993 for (int i = sel_row_start; i <= sel_row_end; ++i)
1994 for (int j = sel_col_start; j <= sel_col_end; ++j)
1995 tabular->SetRightLine(
1996 tabular->GetCellNumber(i,j),
1999 updateLocal(bv, INIT, true);
2003 case LyXTabular::M_ALIGN_LEFT:
2004 case LyXTabular::M_ALIGN_RIGHT:
2005 case LyXTabular::M_ALIGN_CENTER:
2007 case LyXTabular::ALIGN_LEFT:
2008 case LyXTabular::ALIGN_RIGHT:
2009 case LyXTabular::ALIGN_CENTER:
2010 for (int i = sel_row_start; i <= sel_row_end; ++i)
2011 for (int j = sel_col_start; j <= sel_col_end; ++j)
2012 tabular->SetAlignment(
2013 tabular->GetCellNumber(i, j),
2016 updateLocal(bv, INIT, true);
2018 case LyXTabular::M_VALIGN_TOP:
2019 case LyXTabular::M_VALIGN_BOTTOM:
2020 case LyXTabular::M_VALIGN_CENTER:
2022 case LyXTabular::VALIGN_TOP:
2023 case LyXTabular::VALIGN_BOTTOM:
2024 case LyXTabular::VALIGN_CENTER:
2025 for (int i = sel_row_start; i <= sel_row_end; ++i)
2026 for (int j = sel_col_start; j <= sel_col_end; ++j)
2027 tabular->SetVAlignment(
2028 tabular->GetCellNumber(i, j),
2030 updateLocal(bv, INIT, true);
2032 case LyXTabular::MULTICOLUMN:
2034 if (sel_row_start != sel_row_end) {
2035 Alert::alert(_("Impossible Operation!"),
2036 _("Multicolumns can only be horizontally."),
2040 // just multicol for one Single Cell
2041 if (!hasSelection()) {
2042 // check wether we are completly in a multicol
2043 if (tabular->IsMultiColumn(actcell)) {
2044 tabular->UnsetMultiColumn(actcell);
2045 updateLocal(bv, INIT, true);
2047 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2048 updateLocal(bv, CELL, true);
2052 // we have a selection so this means we just add all this
2053 // cells to form a multicolumn cell
2057 if (sel_cell_start > sel_cell_end) {
2058 s_start = sel_cell_end;
2059 s_end = sel_cell_start;
2061 s_start = sel_cell_start;
2062 s_end = sel_cell_end;
2064 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2067 updateLocal(bv, INIT, true);
2070 case LyXTabular::SET_ALL_LINES:
2072 case LyXTabular::UNSET_ALL_LINES:
2073 for (int i = sel_row_start; i <= sel_row_end; ++i)
2074 for (int j = sel_col_start; j <= sel_col_end; ++j)
2075 tabular->SetAllLines(
2076 tabular->GetCellNumber(i,j), setLines);
2077 updateLocal(bv, INIT, true);
2079 case LyXTabular::SET_LONGTABULAR:
2080 tabular->SetLongTabular(true);
2081 updateLocal(bv, INIT, true); // because this toggles displayed
2083 case LyXTabular::UNSET_LONGTABULAR:
2084 tabular->SetLongTabular(false);
2085 updateLocal(bv, INIT, true); // because this toggles displayed
2087 case LyXTabular::SET_ROTATE_TABULAR:
2088 tabular->SetRotateTabular(true);
2090 case LyXTabular::UNSET_ROTATE_TABULAR:
2091 tabular->SetRotateTabular(false);
2093 case LyXTabular::SET_ROTATE_CELL:
2094 for (int i = sel_row_start; i <= sel_row_end; ++i)
2095 for (int j = sel_col_start; j<=sel_col_end; ++j)
2096 tabular->SetRotateCell(
2097 tabular->GetCellNumber(i, j),
2100 case LyXTabular::UNSET_ROTATE_CELL:
2101 for (int i = sel_row_start; i <= sel_row_end; ++i)
2102 for (int j = sel_col_start; j <= sel_col_end; ++j)
2103 tabular->SetRotateCell(
2104 tabular->GetCellNumber(i, j), false);
2106 case LyXTabular::SET_USEBOX:
2108 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2109 if (val == tabular->GetUsebox(actcell))
2110 val = LyXTabular::BOX_NONE;
2111 for (int i = sel_row_start; i <= sel_row_end; ++i)
2112 for (int j = sel_col_start; j <= sel_col_end; ++j)
2114 tabular->GetCellNumber(i, j), val);
2117 case LyXTabular::UNSET_LTFIRSTHEAD:
2119 case LyXTabular::SET_LTFIRSTHEAD:
2120 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2121 checkLongtableSpecial(ltt, value, flag);
2122 tabular->SetLTHead(row, flag, ltt, true);
2124 case LyXTabular::UNSET_LTHEAD:
2126 case LyXTabular::SET_LTHEAD:
2127 (void)tabular->GetRowOfLTHead(row, ltt);
2128 checkLongtableSpecial(ltt, value, flag);
2129 tabular->SetLTHead(row, flag, ltt, false);
2131 case LyXTabular::UNSET_LTFOOT:
2133 case LyXTabular::SET_LTFOOT:
2134 (void)tabular->GetRowOfLTFoot(row, ltt);
2135 checkLongtableSpecial(ltt, value, flag);
2136 tabular->SetLTFoot(row, flag, ltt, false);
2138 case LyXTabular::UNSET_LTLASTFOOT:
2140 case LyXTabular::SET_LTLASTFOOT:
2141 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2142 checkLongtableSpecial(ltt, value, flag);
2143 tabular->SetLTFoot(row, flag, ltt, true);
2145 case LyXTabular::SET_LTNEWPAGE:
2147 bool what = !tabular->GetLTNewPage(row);
2148 tabular->SetLTNewPage(row, what);
2151 // dummy stuff just to avoid warnings
2152 case LyXTabular::LAST_ACTION:
2158 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2161 UpdatableInset * inset =
2162 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2163 LyXFont font(LyXFont::ALL_SANE);
2165 x = inset->x() + inset->width(bv, font);
2166 y = inset->descent(bv, font);
2168 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2169 //inset_y = cursor.y();
2170 inset->edit(bv, x, y, button);
2171 if (!the_locking_inset)
2173 updateLocal(bv, CELL, false);
2174 return (the_locking_inset != 0);
2178 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2181 inset_x = cursor_.x()
2182 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2183 inset_y = cursor_.y();
2184 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2188 bool InsetTabular::insetHit(BufferView *, int x, int) const
2191 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2195 // This returns paperWidth() if the cell-width is unlimited or the width
2196 // in pixels if we have a pwidth for this cell.
2197 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2199 LyXLength const len = tabular->GetPWidth(cell);
2203 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2207 int InsetTabular::getMaxWidth(BufferView * bv,
2208 UpdatableInset const * inset) const
2210 int cell = tabular->GetCellFromInset(inset, actcell);
2213 lyxerr << "Own inset not found, shouldn't really happen!"
2218 int w = getMaxWidthOfCell(bv, cell);
2220 // because the inset then subtracts it's top_x and owner->x()
2221 w += (inset->x() - top_x);
2228 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2230 resizeLyXText(bv, recursive);
2234 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2237 for(int i = 0; i < tabular->rows(); ++i) {
2238 for(int j = 0; j < tabular->columns(); ++j) {
2239 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2247 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2248 bool const recursive) const
2250 if (the_locking_inset)
2251 return the_locking_inset->getLyXText(bv, recursive);
2253 // if we're locked lock the actual insettext and return it's LyXText!!!
2255 UpdatableInset * inset =
2256 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2257 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2258 return the_locking_inset->getLyXText(bv, recursive);
2261 return Inset::getLyXText(bv, recursive);
2265 bool InsetTabular::showInsetDialog(BufferView * bv) const
2267 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2268 bv->owner()->getDialogs()
2269 ->showTabular(const_cast<InsetTabular *>(this));
2274 void InsetTabular::openLayoutDialog(BufferView * bv) const
2276 if (the_locking_inset) {
2277 InsetTabular * i = static_cast<InsetTabular *>
2278 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2280 i->openLayoutDialog(bv);
2284 bv->owner()->getDialogs()->showTabular(
2285 const_cast<InsetTabular *>(this));
2290 // function returns an object as defined in func_status.h:
2291 // states OK, Unknown, Disabled, On, Off.
2293 FuncStatus InsetTabular::getStatus(string const & what) const
2295 int action = LyXTabular::LAST_ACTION;
2299 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2300 string const tmp = tabularFeature[i].feature;
2301 if (tmp == what.substr(0, tmp.length())) {
2302 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2303 // tabularFeatures[i].feature.length())) {
2304 action = tabularFeature[i].action;
2308 if (action == LyXTabular::LAST_ACTION) {
2310 return status.unknown(true);
2313 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2318 LyXTabular::ltType dummyltt;
2321 if (hasSelection()) {
2322 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2324 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2328 case LyXTabular::SET_PWIDTH:
2329 case LyXTabular::SET_MPWIDTH:
2330 case LyXTabular::SET_SPECIAL_COLUMN:
2331 case LyXTabular::SET_SPECIAL_MULTI:
2332 return status.disabled(true);
2334 case LyXTabular::APPEND_ROW:
2335 case LyXTabular::APPEND_COLUMN:
2336 case LyXTabular::DELETE_ROW:
2337 case LyXTabular::DELETE_COLUMN:
2338 case LyXTabular::SET_ALL_LINES:
2339 case LyXTabular::UNSET_ALL_LINES:
2340 return status.clear();
2342 case LyXTabular::MULTICOLUMN:
2343 status.setOnOff(tabular->IsMultiColumn(actcell));
2345 case LyXTabular::M_TOGGLE_LINE_TOP:
2347 case LyXTabular::TOGGLE_LINE_TOP:
2348 status.setOnOff(tabular->TopLine(actcell, flag));
2350 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2352 case LyXTabular::TOGGLE_LINE_BOTTOM:
2353 status.setOnOff(tabular->BottomLine(actcell, flag));
2355 case LyXTabular::M_TOGGLE_LINE_LEFT:
2357 case LyXTabular::TOGGLE_LINE_LEFT:
2358 status.setOnOff(tabular->LeftLine(actcell, flag));
2360 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2362 case LyXTabular::TOGGLE_LINE_RIGHT:
2363 status.setOnOff(tabular->RightLine(actcell, flag));
2365 case LyXTabular::M_ALIGN_LEFT:
2367 case LyXTabular::ALIGN_LEFT:
2368 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2370 case LyXTabular::M_ALIGN_RIGHT:
2372 case LyXTabular::ALIGN_RIGHT:
2373 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2375 case LyXTabular::M_ALIGN_CENTER:
2377 case LyXTabular::ALIGN_CENTER:
2378 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2380 case LyXTabular::M_VALIGN_TOP:
2382 case LyXTabular::VALIGN_TOP:
2383 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2385 case LyXTabular::M_VALIGN_BOTTOM:
2387 case LyXTabular::VALIGN_BOTTOM:
2388 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2390 case LyXTabular::M_VALIGN_CENTER:
2392 case LyXTabular::VALIGN_CENTER:
2393 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2395 case LyXTabular::SET_LONGTABULAR:
2396 status.setOnOff(tabular->IsLongTabular());
2398 case LyXTabular::UNSET_LONGTABULAR:
2399 status.setOnOff(!tabular->IsLongTabular());
2401 case LyXTabular::SET_ROTATE_TABULAR:
2402 status.setOnOff(tabular->GetRotateTabular());
2404 case LyXTabular::UNSET_ROTATE_TABULAR:
2405 status.setOnOff(!tabular->GetRotateTabular());
2407 case LyXTabular::SET_ROTATE_CELL:
2408 status.setOnOff(tabular->GetRotateCell(actcell));
2410 case LyXTabular::UNSET_ROTATE_CELL:
2411 status.setOnOff(!tabular->GetRotateCell(actcell));
2413 case LyXTabular::SET_USEBOX:
2414 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2416 case LyXTabular::SET_LTFIRSTHEAD:
2417 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2419 case LyXTabular::SET_LTHEAD:
2420 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2422 case LyXTabular::SET_LTFOOT:
2423 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2425 case LyXTabular::SET_LTLASTFOOT:
2426 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2428 case LyXTabular::SET_LTNEWPAGE:
2429 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2433 status.disabled(true);
2440 vector<string> const InsetTabular::getLabelList() const
2442 return tabular->getLabelList();
2446 bool InsetTabular::copySelection(BufferView * bv)
2448 if (!hasSelection())
2451 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2452 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2453 if (sel_col_start > sel_col_end) {
2454 sel_col_start = sel_col_end;
2455 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2457 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2459 int const columns = sel_col_end - sel_col_start + 1;
2461 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2462 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2463 if (sel_row_start > sel_row_end) {
2464 swap(sel_row_start, sel_row_end);
2466 int const rows = sel_row_end - sel_row_start + 1;
2468 delete paste_tabular;
2469 paste_tabular = new LyXTabular(bv->buffer()->params,
2470 this, *tabular); // rows, columns);
2471 for (int i = 0; i < sel_row_start; ++i)
2472 paste_tabular->DeleteRow(0);
2473 while (paste_tabular->rows() > rows)
2474 paste_tabular->DeleteRow(rows);
2475 paste_tabular->SetTopLine(0, true, true);
2476 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2478 for (int i = 0; i < sel_col_start; ++i)
2479 paste_tabular->DeleteColumn(0);
2480 while (paste_tabular->columns() > columns)
2481 paste_tabular->DeleteColumn(columns);
2482 paste_tabular->SetLeftLine(0, true, true);
2483 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2487 paste_tabular->ascii(bv->buffer(), sstr,
2488 (int)parOwner()->params().depth(), true, '\t');
2489 bv->stuffClipboard(sstr.str().c_str());
2494 bool InsetTabular::pasteSelection(BufferView * bv)
2499 for (int r1 = 0, r2 = actrow;
2500 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2502 for(int c1 = 0, c2 = actcol;
2503 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2505 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2506 tabular->IsPartOfMultiColumn(r2,c2))
2508 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2512 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2516 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2517 int const n2 = tabular->GetCellNumber(r2, c2);
2518 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2519 tabular->GetCellInset(n2)->setOwner(this);
2520 tabular->GetCellInset(n2)->deleteLyXText(bv);
2527 bool InsetTabular::cutSelection()
2529 if (!hasSelection())
2532 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2533 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2534 if (sel_col_start > sel_col_end) {
2535 sel_col_start = sel_col_end;
2536 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2538 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2540 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2541 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2542 if (sel_row_start > sel_row_end) {
2543 swap(sel_row_start, sel_row_end);
2545 if (sel_cell_start > sel_cell_end) {
2546 swap(sel_cell_start, sel_cell_end);
2548 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2549 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2550 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2557 bool InsetTabular::isRightToLeft(BufferView * bv)
2559 return bv->getParentLanguage(this)->RightToLeft();
2563 bool InsetTabular::nodraw() const
2565 if (!UpdatableInset::nodraw() && the_locking_inset)
2566 return the_locking_inset->nodraw();
2567 return UpdatableInset::nodraw();
2571 int InsetTabular::scroll(bool recursive) const
2573 int sx = UpdatableInset::scroll(false);
2575 if (recursive && the_locking_inset)
2576 sx += the_locking_inset->scroll(recursive);
2582 bool InsetTabular::doClearArea() const
2584 return !locked || (need_update & (FULL|INIT));
2588 void InsetTabular::getSelection(int & srow, int & erow,
2589 int & scol, int & ecol) const
2591 int const start = hasSelection() ? sel_cell_start : actcell;
2592 int const end = hasSelection() ? sel_cell_end : actcell;
2594 srow = tabular->row_of_cell(start);
2595 erow = tabular->row_of_cell(end);
2600 scol = tabular->column_of_cell(start);
2601 ecol = tabular->column_of_cell(end);
2605 ecol = tabular->right_column_of_cell(end);
2610 Paragraph * InsetTabular::getParFromID(int id) const
2613 for(int i = 0; i < tabular->rows(); ++i) {
2614 for(int j = 0; j < tabular->columns(); ++j) {
2615 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2623 Paragraph * InsetTabular::firstParagraph() const
2625 if (the_locking_inset)
2626 return the_locking_inset->firstParagraph();
2631 Paragraph * InsetTabular::getFirstParagraph(int i) const
2633 return (i < tabular->GetNumberOfCells())
2634 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2639 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2641 if (the_locking_inset)
2642 return the_locking_inset->cursor(bv);
2643 return Inset::cursor(bv);
2647 Inset * InsetTabular::getInsetFromID(int id_arg) const
2650 return const_cast<InsetTabular *>(this);
2653 for(int i = 0; i < tabular->rows(); ++i) {
2654 for(int j = 0; j < tabular->columns(); ++j) {
2655 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2664 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2667 if (the_locking_inset) {
2668 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2673 if (tabular->IsLastCell(actcell)) {
2674 bv->unlockInset(const_cast<InsetTabular *>(this));
2680 // otherwise we have to lock the next inset and ask for it's selecttion
2681 UpdatableInset * inset =
2682 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2683 inset->edit(bv, 0, 0, 0);
2684 string const str(selectNextWordInt(bv, value));
2692 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2694 // when entering this function the inset should be ALWAYS locked!
2695 lyx::Assert(the_locking_inset);
2697 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2701 if (tabular->IsLastCell(actcell)) {
2702 bv->unlockInset(const_cast<InsetTabular *>(this));
2706 // otherwise we have to lock the next inset and ask for it's selecttion
2707 UpdatableInset * inset =
2708 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2710 return selectNextWordInt(bv, value);
2714 void InsetTabular::selectSelectedWord(BufferView * bv)
2716 if (the_locking_inset) {
2717 the_locking_inset->selectSelectedWord(bv);
2724 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2726 if (the_locking_inset) {
2727 the_locking_inset->toggleSelection(bv, kill_selection);
2732 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2736 if (the_locking_inset) {
2737 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2739 updateLocal(bv, CELL, false);
2742 if (tabular->IsLastCell(actcell)) {
2744 bv->unlockInset(const_cast<InsetTabular *>(this));
2749 // otherwise we have to lock the next inset and search there
2750 UpdatableInset * inset =
2751 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2753 bool const ret = searchForward(bv, str, cs, mw);
2755 updateLocal(bv, CELL, false);
2760 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2764 if (the_locking_inset) {
2765 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2767 updateLocal(bv, CELL, false);
2770 if (!actcell) { // we are already in the first cell
2772 bv->unlockInset(const_cast<InsetTabular *>(this));
2777 // otherwise we have to lock the next inset and search there
2778 UpdatableInset * inset =
2779 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2780 inset->edit(bv, false);
2781 bool const ret = searchBackward(bv, str, cs, mw);
2783 updateLocal(bv, CELL, false);
2788 bool InsetTabular::insetAllowed(Inset::Code code) const
2790 if (the_locking_inset)
2791 return the_locking_inset->insetAllowed(code);
2792 // we return true here because if the inset is not locked someone
2793 // wants to insert something in one of our insettexts and we generally
2799 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2801 const int cell = tabular->GetCellFromInset(in, actcell);
2804 return tabular->GetPWidth(cell).zero();
2806 // well we didn't obviously find it so maybe our owner knows more
2808 return owner()->forceDefaultParagraphs(in);
2809 // if we're here there is really something strange going on!!!
2813 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2816 if (buf.length() <= 0)
2822 string::size_type len = buf.length();
2823 string::size_type p = 0;
2826 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2835 maxCols = max(cols, maxCols);
2841 maxCols = max(cols, maxCols);
2842 LyXTabular * loctab;
2847 delete paste_tabular;
2848 paste_tabular = new LyXTabular(bv->buffer()->params,
2849 this, rows, maxCols);
2850 loctab = paste_tabular;
2853 loctab = tabular.get();
2858 string::size_type op = 0;
2859 int cells = loctab->GetNumberOfCells();
2862 rows = loctab->rows();
2863 int const columns = loctab->columns();
2864 while ((cell < cells) && (p < len) && (row < rows) &&
2865 (p = buf.find_first_of("\t\n", p)) != string::npos)
2871 // we can only set this if we are not too far right
2872 if (cols < columns) {
2873 InsetText * ti = loctab->GetCellInset(cell);
2874 LyXFont const font = ti->getLyXText(bv)->
2875 getFont(bv->buffer(), ti->paragraph(), 0);
2876 ti->setText(buf.substr(op, p-op), font);
2882 // we can only set this if we are not too far right
2883 if (cols < columns) {
2884 InsetText * ti = loctab->GetCellInset(cell);
2885 LyXFont const font = ti->getLyXText(bv)->
2886 getFont(bv->buffer(), ti->paragraph(), 0);
2887 ti->setText(buf.substr(op, p-op), font);
2892 cell = loctab->GetCellNumber(row, cols);
2898 // check for the last cell if there is no trailing '\n'
2899 if ((cell < cells) && (op < len)) {
2900 InsetText * ti = loctab->GetCellInset(cell);
2901 LyXFont const font = ti->getLyXText(bv)->
2902 getFont(bv->buffer(), ti->paragraph(), 0);
2903 ti->setText(buf.substr(op, len-op), font);