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 (need_update < what) // only set this if it has greater update
623 #if 0 // maybe this should not be done!
624 if ((what == INIT) && hasSelection()) {
629 if (need_update != NONE) {
630 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
631 if (locked) // && (what != NONE))
637 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
639 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
644 if (inset == tabular->GetCellInset(actcell)) {
645 lyxerr[Debug::INSETTEXT] << "OK" << endl;
646 the_locking_inset = tabular->GetCellInset(actcell);
649 } else if (!the_locking_inset) {
650 int const n = tabular->GetNumberOfCells();
651 int const id = inset->id();
652 for (int i = 0; i < n; ++i) {
653 InsetText * in = tabular->GetCellInset(i);
656 the_locking_inset = in;
661 if (in->getInsetFromID(id)) {
664 return the_locking_inset->lockInsetInInset(bv, inset);
667 } else if (the_locking_inset && (the_locking_inset == inset)) {
668 lyxerr[Debug::INSETTEXT] << "OK" << endl;
670 } else if (the_locking_inset) {
671 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
672 return the_locking_inset->lockInsetInInset(bv, inset);
674 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
679 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
682 if (!the_locking_inset)
684 if (the_locking_inset == inset) {
685 the_locking_inset->insetUnlock(bv);
686 the_locking_inset = 0;
688 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
694 updateLocal(bv, CELL, false);
695 showInsetCursor(bv, false);
698 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
699 if (inset->lyxCode() == TABULAR_CODE &&
700 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
701 bv->owner()->getDialogs()->updateTabular(this);
710 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
712 if (!the_locking_inset)
714 if (the_locking_inset != inset) {
715 if (!the_locking_inset->updateInsetInInset(bv, inset))
718 updateLocal(bv, CELL, false);
723 unsigned int InsetTabular::insetInInsetY()
725 if (!the_locking_inset)
727 return inset_y + the_locking_inset->insetInInsetY();
731 UpdatableInset * InsetTabular::getLockingInset() const
733 return the_locking_inset ? the_locking_inset->getLockingInset() :
734 const_cast<InsetTabular *>(this);
738 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
742 if (the_locking_inset)
743 return the_locking_inset->getFirstLockingInsetOfType(c);
748 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
750 if (the_locking_inset)
751 return the_locking_inset->insertInset(bv, inset);
756 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
758 if (hasSelection() && (button == 3))
761 if (hasSelection()) {
763 updateLocal(bv, SELECTION, false);
766 int const ocell = actcell;
767 int const orow = actrow;
772 updateLocal(bv, NONE, false);
776 if ((ocell != actcell) && the_locking_inset) {
777 the_locking_inset->insetUnlock(bv);
778 the_locking_inset = 0;
785 bool const inset_hit = insetHit(bv, x, y);
787 if ((ocell == actcell) && the_locking_inset && inset_hit) {
789 the_locking_inset->insetButtonPress(bv,
790 x - inset_x, y - inset_y,
793 } else if (the_locking_inset) {
794 the_locking_inset->insetUnlock(bv);
796 the_locking_inset = 0;
798 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
801 if (inset_hit && bv->theLockingInset()) {
802 // only activate the Inset so that no internal inset is hit
803 // by this call. It should be only hit by the insetButtonPress call.
804 if (activateCellInsetAbs(bv, 0, 0, 0))
805 the_locking_inset->insetButtonPress(bv,
815 bool InsetTabular::insetButtonRelease(BufferView * bv,
816 int x, int y, int button)
819 if (the_locking_inset)
820 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
821 y - inset_y, button);
822 if (button == 3 && !ret) {
823 bv->owner()->getDialogs()->showTabular(this);
830 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
832 if (the_locking_inset) {
833 the_locking_inset->insetMotionNotify(bv,
841 // int const old_cell = actcell;
844 if (!hasSelection()) {
845 setSelection(actcell, actcell);
847 setSelection(sel_cell_start, actcell);
849 updateLocal(bv, SELECTION, false);
854 void InsetTabular::insetKeyPress(XKeyEvent * xke)
856 if (the_locking_inset) {
857 the_locking_inset->insetKeyPress(xke);
863 UpdatableInset::RESULT
864 InsetTabular::localDispatch(BufferView * bv, kb_action action,
867 // We need to save the value of the_locking_inset as the call to
868 // the_locking_inset->LocalDispatch might unlock it.
869 old_locking_inset = the_locking_inset;
870 UpdatableInset::RESULT result =
871 UpdatableInset::localDispatch(bv, action, arg);
872 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
877 if ((action < 0) && arg.empty())
880 bool hs = hasSelection();
883 // this one have priority over the locked InsetText, if we're not already
884 // inside another tabular then that one get's priority!
885 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
890 unlockInsetInInset(bv, the_locking_inset);
891 if (action == LFUN_TAB)
892 moveNextCell(bv, old_locking_inset != 0);
894 movePrevCell(bv, old_locking_inset != 0);
897 updateLocal(bv, SELECTION, false);
898 if (!the_locking_inset) {
900 return DISPATCHED_NOUPDATE;
903 // this to avoid compiler warnings.
909 if (the_locking_inset) {
910 result = the_locking_inset->localDispatch(bv, action, arg);
911 if (result == DISPATCHED_NOUPDATE) {
914 if (sc != scroll()) { // inset has been scrolled
915 the_locking_inset->toggleInsetCursor(bv);
916 updateLocal(bv, FULL, false);
917 the_locking_inset->toggleInsetCursor(bv);
920 } else if (result == DISPATCHED) {
921 the_locking_inset->toggleInsetCursor(bv);
922 updateLocal(bv, CELL, false);
923 the_locking_inset->toggleInsetCursor(bv);
925 } else if (result == FINISHED_UP) {
927 } else if (result == FINISHED_DOWN) {
929 } else if (result == FINISHED_RIGHT) {
937 // --- Cursor Movements ----------------------------------
938 case LFUN_RIGHTSEL: {
939 int const start = hasSelection() ? sel_cell_start : actcell;
940 if (tabular->IsLastCellInRow(actcell)) {
941 setSelection(start, actcell);
946 // if we are starting a selection, only select
947 // the current cell at the beginning
948 if (hasSelection()) {
949 moveRight(bv, false);
952 setSelection(start, end);
953 updateLocal(bv, SELECTION, false);
957 result = moveRight(bv);
960 updateLocal(bv, SELECTION, false);
963 int const start = hasSelection() ? sel_cell_start : actcell;
964 if (tabular->IsFirstCellInRow(actcell)) {
965 setSelection(start, actcell);
970 // if we are starting a selection, only select
971 // the current cell at the beginning
972 if (hasSelection()) {
976 setSelection(start, end);
977 updateLocal(bv, SELECTION, false);
981 result = moveLeft(bv);
984 updateLocal(bv, SELECTION, false);
987 int const start = hasSelection() ? sel_cell_start : actcell;
988 int const ocell = actcell;
989 // if we are starting a selection, only select
990 // the current cell at the beginning
991 if (hasSelection()) {
993 if ((ocell == sel_cell_end) ||
994 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
995 setSelection(start, tabular->GetCellBelow(sel_cell_end));
997 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
999 setSelection(start, start);
1001 updateLocal(bv, SELECTION, false);
1005 result = moveDown(bv, old_locking_inset != 0);
1008 updateLocal(bv, SELECTION, false);
1012 int const start = hasSelection() ? sel_cell_start : actcell;
1013 int const ocell = actcell;
1014 // if we are starting a selection, only select
1015 // the current cell at the beginning
1016 if (hasSelection()) {
1018 if ((ocell == sel_cell_end) ||
1019 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1020 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1022 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1024 setSelection(start, start);
1026 updateLocal(bv, SELECTION, false);
1030 result = moveUp(bv, old_locking_inset != 0);
1033 updateLocal(bv, SELECTION, false);
1036 UpdateCodes code = CURSOR;
1041 int column = actcol;
1042 unlockInsetInInset(bv, the_locking_inset);
1043 if (bv->text->first_y + bv->painter().paperHeight() <
1044 (top_baseline + tabular->GetHeightOfTabular()))
1046 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1048 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1050 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1053 updateLocal(bv, code, false);
1057 UpdateCodes code = CURSOR;
1062 int column = actcol;
1063 unlockInsetInInset(bv, the_locking_inset);
1064 if (top_baseline < 0) {
1065 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1067 if (top_baseline > 0)
1070 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1075 updateLocal(bv, code, false);
1078 // none of these make sense for insettabular,
1079 // but we must catch them to prevent any
1080 // selection from being confused
1084 case LFUN_WORDLEFTSEL:
1085 case LFUN_WORDRIGHT:
1086 case LFUN_WORDRIGHTSEL:
1087 case LFUN_DOWN_PARAGRAPH:
1088 case LFUN_DOWN_PARAGRAPHSEL:
1089 case LFUN_UP_PARAGRAPH:
1090 case LFUN_UP_PARAGRAPHSEL:
1091 case LFUN_BACKSPACE:
1097 case LFUN_BEGINNINGBUF:
1098 case LFUN_BEGINNINGBUFSEL:
1100 case LFUN_ENDBUFSEL:
1102 case LFUN_LAYOUT_TABULAR:
1103 bv->owner()->getDialogs()->showTabular(this);
1105 case LFUN_TABULAR_FEATURE:
1106 if (!tabularFeatures(bv, arg))
1107 result = UNDISPATCHED;
1109 // insert file functions
1110 case LFUN_FILE_INSERT_ASCII_PARA:
1111 case LFUN_FILE_INSERT_ASCII:
1113 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1116 if (insertAsciiString(bv, tmpstr, false))
1117 updateLocal(bv, INIT, true);
1119 result = UNDISPATCHED;
1122 // cut and paste functions
1124 if (!copySelection(bv))
1126 setUndo(bv, Undo::DELETE,
1127 bv->text->cursor.par(),
1128 bv->text->cursor.par()->next());
1130 updateLocal(bv, INIT, true);
1133 if (!hasSelection())
1138 case LFUN_PASTESELECTION:
1140 string const clip(bv->getClipboard());
1144 if (clip.find('\t') != string::npos) {
1148 string::size_type len = clip.length();
1149 string::size_type p = 0;
1152 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1160 maxCols = max(cols, maxCols);
1166 maxCols = max(cols, maxCols);
1167 delete paste_tabular;
1168 paste_tabular = new LyXTabular(bv->buffer()->params,
1169 this, rows, maxCols);
1170 string::size_type op = 0;
1172 int cells = paste_tabular->GetNumberOfCells();
1174 while ((cell < cells) && (p < len) &&
1175 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1180 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1185 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1186 while (cols++ < maxCols)
1194 // check for the last cell if there is no trailing '\n'
1195 if ((cell < cells) && (op < len))
1196 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1199 if (!insertAsciiString(bv, clip, true))
1202 // so that the clipboard is used and it goes on
1204 // and executes LFUN_PASTESELECTION in insettext!
1205 delete paste_tabular;
1210 if (hasPasteBuffer()) {
1211 setUndo(bv, Undo::INSERT,
1212 bv->text->cursor.par(),
1213 bv->text->cursor.par()->next());
1215 updateLocal(bv, INIT, true);
1218 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1220 // handle font changing stuff on selection before we lock the inset
1221 // in the default part!
1222 result = UNDISPATCHED;
1233 case LFUN_UNDERLINE:
1234 case LFUN_FONT_SIZE:
1235 if (bv->Dispatch(action, arg))
1236 result = DISPATCHED;
1242 // we try to activate the actual inset and put this event down to
1243 // the insets dispatch function.
1244 if ((result == DISPATCHED) || the_locking_inset)
1247 if (activateCellInset(bv)) {
1248 // reset need_update setted in above function!
1250 result = the_locking_inset->localDispatch(bv, action, arg);
1251 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1252 unlockInsetInInset(bv, the_locking_inset);
1254 // we need to update if this was requested before
1255 updateLocal(bv, NONE, false);
1256 return UNDISPATCHED;
1259 // so the below CELL is not set because this is higher
1260 // priority and we get a full redraw
1261 need_update = SELECTION;
1264 updateLocal(bv, CELL, false);
1269 if (result < FINISHED) {
1270 if (!the_locking_inset) {
1271 showInsetCursor(bv);
1274 bv->unlockInset(this);
1279 int InsetTabular::latex(Buffer const * buf, ostream & os,
1280 bool fragile, bool fp) const
1282 return tabular->latex(buf, os, fragile, fp);
1286 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1289 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1291 return tabular->ascii(buf, os, 0, false,0);
1295 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1298 int const ret = tabular->ascii(buf,os,
1299 (int)parOwner()->params().depth(),
1306 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1311 // if the table is inside a float it doesn't need the informaltable
1312 // wrapper. Search for it.
1313 for(master = owner();
1314 master && master->lyxCode() != Inset::FLOAT_CODE;
1315 master = master->owner());
1318 os << "<informaltable>\n";
1321 ret+= tabular->docBook(buf,os);
1323 os << "</informaltable>\n";
1330 void InsetTabular::validate(LaTeXFeatures & features) const
1332 tabular->Validate(features);
1336 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1337 LyXFont const & font,
1344 bool changed = false;
1346 // if we have a locking_inset we should have to check only this cell for
1347 // change so I'll try this to have a boost, but who knows ;)
1348 if ((need_update != INIT) &&
1349 (the_locking_inset == tabular->GetCellInset(actcell))) {
1350 for(int i = 0; i < tabular->columns(); ++i) {
1351 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1353 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1356 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1357 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1358 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1361 for (int i = 0; i < tabular->rows(); ++i) {
1364 for (int j = 0; j < tabular->columns(); ++j) {
1365 if (tabular->IsPartOfMultiColumn(i,j))
1368 inset = tabular->GetCellInset(cell);
1369 if (!reinit && !tabular->GetPWidth(cell).zero())
1370 inset->update(bv, font, false);
1371 maxAsc = max(maxAsc, inset->ascent(bv, font));
1372 maxDesc = max(maxDesc, inset->descent(bv, font));
1373 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1375 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1376 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1384 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1386 if (the_locking_inset) {
1387 the_locking_inset->getCursorPos(bv, x, y);
1390 x = cursor_.x() - top_x;
1395 void InsetTabular::toggleInsetCursor(BufferView * bv)
1398 if (isCursorVisible())
1399 bv->hideLockedInsetCursor();
1402 if (the_locking_inset) {
1403 the_locking_inset->toggleInsetCursor(bv);
1407 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1409 int const asc = lyxfont::maxAscent(font);
1410 int const desc = lyxfont::maxDescent(font);
1412 if (isCursorVisible())
1413 bv->hideLockedInsetCursor();
1415 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1416 toggleCursorVisible();
1420 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1424 if (!isCursorVisible()) {
1425 LyXFont font; // = GetFont(par, cursor.pos);
1427 int const asc = lyxfont::maxAscent(font);
1428 int const desc = lyxfont::maxDescent(font);
1429 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1431 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1432 setCursorVisible(true);
1437 void InsetTabular::hideInsetCursor(BufferView * bv)
1439 if (isCursorVisible()) {
1440 bv->hideLockedInsetCursor();
1441 setCursorVisible(false);
1446 void InsetTabular::fitInsetCursor(BufferView * bv) const
1448 if (the_locking_inset) {
1449 the_locking_inset->fitInsetCursor(bv);
1454 int const asc = lyxfont::maxAscent(font);
1455 int const desc = lyxfont::maxDescent(font);
1456 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1460 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1464 actcell = actrow = actcol = 0;
1465 int ly = tabular->GetDescentOfRow(actrow);
1467 // first search the right row
1468 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1469 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1470 tabular->GetAscentOfRow(actrow + 1) +
1471 tabular->GetAdditionalHeight(actrow + 1));
1473 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1475 actcell = tabular->GetCellNumber(actrow, actcol);
1477 // now search the right column
1478 int lx = tabular->GetWidthOfColumn(actcell) -
1479 tabular->GetAdditionalWidth(actcell);
1480 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1481 lx += tabular->GetWidthOfColumn(actcell + 1)
1482 + tabular->GetAdditionalWidth(actcell);
1484 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1489 int InsetTabular::getCellXPos(int cell) const
1493 for (; !tabular->IsFirstCellInRow(c); --c)
1495 int lx = tabular->GetWidthOfColumn(cell);
1496 for (; c < cell; ++c) {
1497 lx += tabular->GetWidthOfColumn(c);
1499 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1503 void InsetTabular::resetPos(BufferView * bv) const
1505 #warning This should be fixed in the right manner (20011128 Jug)
1506 // fast hack to fix infinite repaintings!
1511 actcol = tabular->column_of_cell(actcell);
1514 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1515 if (tabular->IsLastCellInRow(cell)) {
1516 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1517 tabular->GetAscentOfRow(actrow + 1) +
1518 tabular->GetAdditionalHeight(actrow + 1));
1522 if (!locked || nodraw()) {
1523 if (the_locking_inset)
1524 inset_y = cursor_.y();
1527 // we need this only from here on!!!
1528 in_reset_pos = true;
1529 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1530 int new_x = getCellXPos(actcell);
1531 int old_x = cursor_.x();
1534 // cursor.x(getCellXPos(actcell) + offset);
1535 if ((actcol < tabular->columns()-1) && scroll(false) &&
1536 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1539 updateLocal(bv, FULL, false);
1540 } else if (the_locking_inset &&
1541 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1543 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1544 if (xx > (bv->workWidth()-20)) {
1545 scroll(bv, -(xx - bv->workWidth() + 60));
1546 updateLocal(bv, FULL, false);
1547 } else if (xx < 20) {
1553 updateLocal(bv, FULL, false);
1555 } else if ((cursor_.x() - offset) > 20 &&
1556 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1557 > (bv->workWidth() - 20)) {
1558 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1559 updateLocal(bv, FULL, false);
1560 } else if ((cursor_.x() - offset) < 20) {
1561 scroll(bv, 20 - cursor_.x() + offset);
1562 updateLocal(bv, FULL, false);
1563 } else if (scroll(false) && top_x > 20 &&
1564 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1565 scroll(bv, old_x - cursor_.x());
1566 updateLocal(bv, FULL, false);
1568 if (the_locking_inset) {
1569 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1570 inset_y = cursor_.y();
1572 if ((!the_locking_inset ||
1573 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1574 actcell != oldcell) {
1575 InsetTabular * inset = const_cast<InsetTabular *>(this);
1576 bv->owner()->getDialogs()->updateTabular(inset);
1579 in_reset_pos = false;
1583 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1585 if (lock && !old_locking_inset) {
1586 if (activateCellInset(bv))
1589 bool moved = isRightToLeft(bv)
1590 ? movePrevCell(bv) : moveNextCell(bv);
1592 return FINISHED_RIGHT;
1593 if (lock && activateCellInset(bv))
1597 return DISPATCHED_NOUPDATE;
1601 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1603 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1606 if (lock) { // behind the inset
1607 if (activateCellInset(bv, 0, 0, 0, true))
1611 return DISPATCHED_NOUPDATE;
1615 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1617 int const ocell = actcell;
1618 actcell = tabular->GetCellAbove(actcell);
1619 if (actcell == ocell) // we moved out of the inset
1625 if (old_locking_inset) {
1626 old_locking_inset->getCursorPos(bv, x, y);
1627 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1629 if (activateCellInset(bv, x, 0))
1632 return DISPATCHED_NOUPDATE;
1636 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1638 int const ocell = actcell;
1639 actcell = tabular->GetCellBelow(actcell);
1640 if (actcell == ocell) // we moved out of the inset
1641 return FINISHED_DOWN;
1646 if (old_locking_inset) {
1647 old_locking_inset->getCursorPos(bv, x, y);
1648 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1650 if (activateCellInset(bv, x, 0))
1653 return DISPATCHED_NOUPDATE;
1657 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1659 if (isRightToLeft(bv)) {
1660 if (tabular->IsFirstCellInRow(actcell)) {
1661 int row = tabular->row_of_cell(actcell);
1662 if (row == tabular->rows() - 1)
1664 actcell = tabular->GetLastCellInRow(row);
1665 actcell = tabular->GetCellBelow(actcell);
1672 if (tabular->IsLastCell(actcell))
1677 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1678 isRightToLeftPar(bv->buffer()->params);
1679 activateCellInset(bv, 0, 0, 0, !rtl);
1686 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1688 if (isRightToLeft(bv)) {
1689 if (tabular->IsLastCellInRow(actcell)) {
1690 int row = tabular->row_of_cell(actcell);
1693 actcell = tabular->GetFirstCellInRow(row);
1694 actcell = tabular->GetCellAbove(actcell);
1696 if (tabular->IsLastCell(actcell))
1701 if (!actcell) // first cell
1706 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1707 isRightToLeftPar(bv->buffer()->params);
1708 activateCellInset(bv, 0, 0, 0, !rtl);
1715 bool InsetTabular::deletable() const
1721 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1725 setSelection(0, tabular->GetNumberOfCells() - 1);
1727 if (hasSelection()) {
1728 setUndo(bv, Undo::EDIT,
1729 bv->text->cursor.par(),
1730 bv->text->cursor.par()->next());
1731 bool frozen = undo_frozen;
1734 // apply the fontchange on the whole selection
1739 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1740 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1741 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1742 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1747 updateLocal(bv, INIT, true);
1749 if (the_locking_inset)
1750 the_locking_inset->setFont(bv, font, tall);
1754 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1756 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1759 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1760 string const tmp = tabularFeature[i].feature;
1762 if (tmp == what.substr(0, tmp.length())) {
1763 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1764 //tabularFeatures[i].feature.length())) {
1765 action = tabularFeature[i].action;
1769 if (action == LyXTabular::LAST_ACTION)
1773 frontStrip(what.substr(tabularFeature[i].feature.length()));
1774 tabularFeatures(bv, action, val);
1778 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1779 string const & special, bool & flag)
1781 if (special == "dl_above") {
1784 } else if (special == "dl_below") {
1785 ltt.bottomDL = flag;
1787 } else if (special == "empty") {
1797 void InsetTabular::tabularFeatures(BufferView * bv,
1798 LyXTabular::Feature feature,
1799 string const & value)
1805 bool setLines = false;
1806 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1807 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1810 case LyXTabular::M_ALIGN_LEFT:
1811 case LyXTabular::ALIGN_LEFT:
1812 setAlign = LYX_ALIGN_LEFT;
1814 case LyXTabular::M_ALIGN_RIGHT:
1815 case LyXTabular::ALIGN_RIGHT:
1816 setAlign = LYX_ALIGN_RIGHT;
1818 case LyXTabular::M_ALIGN_CENTER:
1819 case LyXTabular::ALIGN_CENTER:
1820 setAlign = LYX_ALIGN_CENTER;
1822 case LyXTabular::M_VALIGN_TOP:
1823 case LyXTabular::VALIGN_TOP:
1824 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1826 case LyXTabular::M_VALIGN_BOTTOM:
1827 case LyXTabular::VALIGN_BOTTOM:
1828 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1830 case LyXTabular::M_VALIGN_CENTER:
1831 case LyXTabular::VALIGN_CENTER:
1832 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1837 if (hasSelection()) {
1838 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1840 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1841 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1843 setUndo(bv, Undo::FINISH,
1844 bv->text->cursor.par(),
1845 bv->text->cursor.par()->next());
1847 int row = tabular->row_of_cell(actcell);
1848 int column = tabular->column_of_cell(actcell);
1850 LyXTabular::ltType ltt;
1853 case LyXTabular::SET_PWIDTH:
1855 LyXLength const vallen(value);
1856 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1858 bool const update = (tmplen != vallen);
1859 tabular->SetColumnPWidth(actcell, vallen);
1862 for (int i = 0; i < tabular->rows(); ++i) {
1863 cell = tabular->GetCellNumber(i,column);
1864 tabular->GetCellInset(cell)->resizeLyXText(bv);
1866 updateLocal(bv, INIT, true);
1870 case LyXTabular::SET_MPWIDTH:
1872 LyXLength const vallen(value);
1873 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1875 bool const update = (tmplen != vallen);
1876 tabular->SetMColumnPWidth(actcell, vallen);
1878 for (int i = 0; i < tabular->rows(); ++i) {
1879 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1882 updateLocal(bv, INIT, true);
1886 case LyXTabular::SET_SPECIAL_COLUMN:
1887 case LyXTabular::SET_SPECIAL_MULTI:
1888 tabular->SetAlignSpecial(actcell,value,feature);
1889 updateLocal(bv, FULL, true);
1891 case LyXTabular::APPEND_ROW:
1892 // append the row into the tabular
1893 unlockInsetInInset(bv, the_locking_inset);
1894 tabular->AppendRow(bv->buffer()->params, actcell);
1895 updateLocal(bv, INIT, true);
1897 case LyXTabular::APPEND_COLUMN:
1898 // append the column into the tabular
1899 unlockInsetInInset(bv, the_locking_inset);
1900 tabular->AppendColumn(bv->buffer()->params, actcell);
1901 actcell = tabular->GetCellNumber(row, column);
1902 updateLocal(bv, INIT, true);
1904 case LyXTabular::DELETE_ROW:
1905 unlockInsetInInset(bv, the_locking_inset);
1906 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1907 tabular->DeleteRow(sel_row_start);
1909 if (sel_row_start >= tabular->rows())
1911 actcell = tabular->GetCellNumber(sel_row_start, column);
1913 updateLocal(bv, INIT, true);
1915 case LyXTabular::DELETE_COLUMN:
1916 unlockInsetInInset(bv, the_locking_inset);
1917 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1918 tabular->DeleteColumn(sel_col_start);
1920 if (sel_col_start >= tabular->columns())
1922 actcell = tabular->GetCellNumber(row, sel_col_start);
1924 updateLocal(bv, INIT, true);
1926 case LyXTabular::M_TOGGLE_LINE_TOP:
1928 case LyXTabular::TOGGLE_LINE_TOP:
1930 bool lineSet = !tabular->TopLine(actcell, flag);
1931 for (int i = sel_row_start; i <= sel_row_end; ++i)
1932 for (int j = sel_col_start; j <= sel_col_end; ++j)
1933 tabular->SetTopLine(
1934 tabular->GetCellNumber(i, j),
1936 updateLocal(bv, INIT, true);
1940 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1942 case LyXTabular::TOGGLE_LINE_BOTTOM:
1944 bool lineSet = !tabular->BottomLine(actcell, flag);
1945 for (int i = sel_row_start; i <= sel_row_end; ++i)
1946 for (int j = sel_col_start; j <= sel_col_end; ++j)
1947 tabular->SetBottomLine(
1948 tabular->GetCellNumber(i, j),
1951 updateLocal(bv, INIT, true);
1955 case LyXTabular::M_TOGGLE_LINE_LEFT:
1957 case LyXTabular::TOGGLE_LINE_LEFT:
1959 bool lineSet = !tabular->LeftLine(actcell, flag);
1960 for (int i = sel_row_start; i <= sel_row_end; ++i)
1961 for (int j = sel_col_start; j <= sel_col_end; ++j)
1962 tabular->SetLeftLine(
1963 tabular->GetCellNumber(i,j),
1966 updateLocal(bv, INIT, true);
1970 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1972 case LyXTabular::TOGGLE_LINE_RIGHT:
1974 bool lineSet = !tabular->RightLine(actcell, flag);
1975 for (int i = sel_row_start; i <= sel_row_end; ++i)
1976 for (int j = sel_col_start; j <= sel_col_end; ++j)
1977 tabular->SetRightLine(
1978 tabular->GetCellNumber(i,j),
1981 updateLocal(bv, INIT, true);
1985 case LyXTabular::M_ALIGN_LEFT:
1986 case LyXTabular::M_ALIGN_RIGHT:
1987 case LyXTabular::M_ALIGN_CENTER:
1989 case LyXTabular::ALIGN_LEFT:
1990 case LyXTabular::ALIGN_RIGHT:
1991 case LyXTabular::ALIGN_CENTER:
1992 for (int i = sel_row_start; i <= sel_row_end; ++i)
1993 for (int j = sel_col_start; j <= sel_col_end; ++j)
1994 tabular->SetAlignment(
1995 tabular->GetCellNumber(i, j),
1998 updateLocal(bv, INIT, true);
2000 case LyXTabular::M_VALIGN_TOP:
2001 case LyXTabular::M_VALIGN_BOTTOM:
2002 case LyXTabular::M_VALIGN_CENTER:
2004 case LyXTabular::VALIGN_TOP:
2005 case LyXTabular::VALIGN_BOTTOM:
2006 case LyXTabular::VALIGN_CENTER:
2007 for (int i = sel_row_start; i <= sel_row_end; ++i)
2008 for (int j = sel_col_start; j <= sel_col_end; ++j)
2009 tabular->SetVAlignment(
2010 tabular->GetCellNumber(i, j),
2012 updateLocal(bv, INIT, true);
2014 case LyXTabular::MULTICOLUMN:
2016 if (sel_row_start != sel_row_end) {
2017 Alert::alert(_("Impossible Operation!"),
2018 _("Multicolumns can only be horizontally."),
2022 // just multicol for one Single Cell
2023 if (!hasSelection()) {
2024 // check wether we are completly in a multicol
2025 if (tabular->IsMultiColumn(actcell)) {
2026 tabular->UnsetMultiColumn(actcell);
2027 updateLocal(bv, INIT, true);
2029 tabular->SetMultiColumn(actcell, 1);
2030 updateLocal(bv, CELL, true);
2034 // we have a selection so this means we just add all this
2035 // cells to form a multicolumn cell
2039 if (sel_cell_start > sel_cell_end) {
2040 s_start = sel_cell_end;
2041 s_end = sel_cell_start;
2043 s_start = sel_cell_start;
2044 s_end = sel_cell_end;
2046 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
2049 updateLocal(bv, INIT, true);
2052 case LyXTabular::SET_ALL_LINES:
2054 case LyXTabular::UNSET_ALL_LINES:
2055 for (int i = sel_row_start; i <= sel_row_end; ++i)
2056 for (int j = sel_col_start; j <= sel_col_end; ++j)
2057 tabular->SetAllLines(
2058 tabular->GetCellNumber(i,j), setLines);
2059 updateLocal(bv, INIT, true);
2061 case LyXTabular::SET_LONGTABULAR:
2062 tabular->SetLongTabular(true);
2063 updateLocal(bv, INIT, true); // because this toggles displayed
2065 case LyXTabular::UNSET_LONGTABULAR:
2066 tabular->SetLongTabular(false);
2067 updateLocal(bv, INIT, true); // because this toggles displayed
2069 case LyXTabular::SET_ROTATE_TABULAR:
2070 tabular->SetRotateTabular(true);
2072 case LyXTabular::UNSET_ROTATE_TABULAR:
2073 tabular->SetRotateTabular(false);
2075 case LyXTabular::SET_ROTATE_CELL:
2076 for (int i = sel_row_start; i <= sel_row_end; ++i)
2077 for (int j = sel_col_start; j<=sel_col_end; ++j)
2078 tabular->SetRotateCell(
2079 tabular->GetCellNumber(i, j),
2082 case LyXTabular::UNSET_ROTATE_CELL:
2083 for (int i = sel_row_start; i <= sel_row_end; ++i)
2084 for (int j = sel_col_start; j <= sel_col_end; ++j)
2085 tabular->SetRotateCell(
2086 tabular->GetCellNumber(i, j), false);
2088 case LyXTabular::SET_USEBOX:
2090 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2091 if (val == tabular->GetUsebox(actcell))
2092 val = LyXTabular::BOX_NONE;
2093 for (int i = sel_row_start; i <= sel_row_end; ++i)
2094 for (int j = sel_col_start; j <= sel_col_end; ++j)
2096 tabular->GetCellNumber(i, j), val);
2099 case LyXTabular::UNSET_LTFIRSTHEAD:
2101 case LyXTabular::SET_LTFIRSTHEAD:
2102 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2103 checkLongtableSpecial(ltt, value, flag);
2104 tabular->SetLTHead(row, flag, ltt, true);
2106 case LyXTabular::UNSET_LTHEAD:
2108 case LyXTabular::SET_LTHEAD:
2109 (void)tabular->GetRowOfLTHead(row, ltt);
2110 checkLongtableSpecial(ltt, value, flag);
2111 tabular->SetLTHead(row, flag, ltt, false);
2113 case LyXTabular::UNSET_LTFOOT:
2115 case LyXTabular::SET_LTFOOT:
2116 (void)tabular->GetRowOfLTFoot(row, ltt);
2117 checkLongtableSpecial(ltt, value, flag);
2118 tabular->SetLTFoot(row, flag, ltt, false);
2120 case LyXTabular::UNSET_LTLASTFOOT:
2122 case LyXTabular::SET_LTLASTFOOT:
2123 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2124 checkLongtableSpecial(ltt, value, flag);
2125 tabular->SetLTFoot(row, flag, ltt, true);
2127 case LyXTabular::SET_LTNEWPAGE:
2129 bool what = !tabular->GetLTNewPage(row);
2130 tabular->SetLTNewPage(row, what);
2133 // dummy stuff just to avoid warnings
2134 case LyXTabular::LAST_ACTION:
2140 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2143 UpdatableInset * inset =
2144 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2145 LyXFont font(LyXFont::ALL_SANE);
2147 x = inset->x() + inset->width(bv, font);
2148 y = inset->descent(bv, font);
2150 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2151 //inset_y = cursor.y();
2152 inset->edit(bv, x, y, button);
2153 if (!the_locking_inset)
2155 updateLocal(bv, CELL, false);
2156 return (the_locking_inset != 0);
2160 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2163 inset_x = cursor_.x()
2164 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2165 inset_y = cursor_.y();
2166 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2170 bool InsetTabular::insetHit(BufferView *, int x, int) const
2173 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2177 // This returns paperWidth() if the cell-width is unlimited or the width
2178 // in pixels if we have a pwidth for this cell.
2179 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2181 LyXLength const len = tabular->GetPWidth(cell);
2185 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2189 int InsetTabular::getMaxWidth(BufferView * bv,
2190 UpdatableInset const * inset) const
2192 int cell = tabular->GetCellFromInset(inset, actcell);
2195 lyxerr << "Own inset not found, shouldn't really happen!"
2200 int w = getMaxWidthOfCell(bv, cell);
2202 // because the inset then subtracts it's top_x and owner->x()
2203 w += (inset->x() - top_x);
2210 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2212 resizeLyXText(bv, recursive);
2216 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2219 for(int i = 0; i < tabular->rows(); ++i) {
2220 for(int j = 0; j < tabular->columns(); ++j) {
2221 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2229 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2230 bool const recursive) const
2232 if (the_locking_inset)
2233 return the_locking_inset->getLyXText(bv, recursive);
2235 // if we're locked lock the actual insettext and return it's LyXText!!!
2237 UpdatableInset * inset =
2238 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2239 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2240 return the_locking_inset->getLyXText(bv, recursive);
2243 return Inset::getLyXText(bv, recursive);
2247 bool InsetTabular::showInsetDialog(BufferView * bv) const
2249 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2250 bv->owner()->getDialogs()
2251 ->showTabular(const_cast<InsetTabular *>(this));
2256 void InsetTabular::openLayoutDialog(BufferView * bv) const
2258 if (the_locking_inset) {
2259 InsetTabular * i = static_cast<InsetTabular *>
2260 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2262 i->openLayoutDialog(bv);
2266 bv->owner()->getDialogs()->showTabular(
2267 const_cast<InsetTabular *>(this));
2272 // function returns an object as defined in func_status.h:
2273 // states OK, Unknown, Disabled, On, Off.
2275 FuncStatus InsetTabular::getStatus(string const & what) const
2277 int action = LyXTabular::LAST_ACTION;
2281 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2282 string const tmp = tabularFeature[i].feature;
2283 if (tmp == what.substr(0, tmp.length())) {
2284 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2285 // tabularFeatures[i].feature.length())) {
2286 action = tabularFeature[i].action;
2290 if (action == LyXTabular::LAST_ACTION) {
2292 return status.unknown(true);
2295 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2300 LyXTabular::ltType dummyltt;
2303 if (hasSelection()) {
2304 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2306 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2310 case LyXTabular::SET_PWIDTH:
2311 case LyXTabular::SET_MPWIDTH:
2312 case LyXTabular::SET_SPECIAL_COLUMN:
2313 case LyXTabular::SET_SPECIAL_MULTI:
2314 return status.disabled(true);
2316 case LyXTabular::APPEND_ROW:
2317 case LyXTabular::APPEND_COLUMN:
2318 case LyXTabular::DELETE_ROW:
2319 case LyXTabular::DELETE_COLUMN:
2320 case LyXTabular::SET_ALL_LINES:
2321 case LyXTabular::UNSET_ALL_LINES:
2322 return status.clear();
2324 case LyXTabular::MULTICOLUMN:
2325 status.setOnOff(tabular->IsMultiColumn(actcell));
2327 case LyXTabular::M_TOGGLE_LINE_TOP:
2329 case LyXTabular::TOGGLE_LINE_TOP:
2330 status.setOnOff(tabular->TopLine(actcell, flag));
2332 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2334 case LyXTabular::TOGGLE_LINE_BOTTOM:
2335 status.setOnOff(tabular->BottomLine(actcell, flag));
2337 case LyXTabular::M_TOGGLE_LINE_LEFT:
2339 case LyXTabular::TOGGLE_LINE_LEFT:
2340 status.setOnOff(tabular->LeftLine(actcell, flag));
2342 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2344 case LyXTabular::TOGGLE_LINE_RIGHT:
2345 status.setOnOff(tabular->RightLine(actcell, flag));
2347 case LyXTabular::M_ALIGN_LEFT:
2349 case LyXTabular::ALIGN_LEFT:
2350 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2352 case LyXTabular::M_ALIGN_RIGHT:
2354 case LyXTabular::ALIGN_RIGHT:
2355 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2357 case LyXTabular::M_ALIGN_CENTER:
2359 case LyXTabular::ALIGN_CENTER:
2360 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2362 case LyXTabular::M_VALIGN_TOP:
2364 case LyXTabular::VALIGN_TOP:
2365 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2367 case LyXTabular::M_VALIGN_BOTTOM:
2369 case LyXTabular::VALIGN_BOTTOM:
2370 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2372 case LyXTabular::M_VALIGN_CENTER:
2374 case LyXTabular::VALIGN_CENTER:
2375 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2377 case LyXTabular::SET_LONGTABULAR:
2378 status.setOnOff(tabular->IsLongTabular());
2380 case LyXTabular::UNSET_LONGTABULAR:
2381 status.setOnOff(!tabular->IsLongTabular());
2383 case LyXTabular::SET_ROTATE_TABULAR:
2384 status.setOnOff(tabular->GetRotateTabular());
2386 case LyXTabular::UNSET_ROTATE_TABULAR:
2387 status.setOnOff(!tabular->GetRotateTabular());
2389 case LyXTabular::SET_ROTATE_CELL:
2390 status.setOnOff(tabular->GetRotateCell(actcell));
2392 case LyXTabular::UNSET_ROTATE_CELL:
2393 status.setOnOff(!tabular->GetRotateCell(actcell));
2395 case LyXTabular::SET_USEBOX:
2396 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2398 case LyXTabular::SET_LTFIRSTHEAD:
2399 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2401 case LyXTabular::SET_LTHEAD:
2402 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2404 case LyXTabular::SET_LTFOOT:
2405 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2407 case LyXTabular::SET_LTLASTFOOT:
2408 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2410 case LyXTabular::SET_LTNEWPAGE:
2411 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2415 status.disabled(true);
2422 vector<string> const InsetTabular::getLabelList() const
2424 return tabular->getLabelList();
2428 bool InsetTabular::copySelection(BufferView * bv)
2430 if (!hasSelection())
2433 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2434 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2435 if (sel_col_start > sel_col_end) {
2436 sel_col_start = sel_col_end;
2437 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2439 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2441 int const columns = sel_col_end - sel_col_start + 1;
2443 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2444 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2445 if (sel_row_start > sel_row_end) {
2446 swap(sel_row_start, sel_row_end);
2448 int const rows = sel_row_end - sel_row_start + 1;
2450 delete paste_tabular;
2451 paste_tabular = new LyXTabular(bv->buffer()->params,
2452 this, *tabular); // rows, columns);
2453 for (int i = 0; i < sel_row_start; ++i)
2454 paste_tabular->DeleteRow(0);
2455 while (paste_tabular->rows() > rows)
2456 paste_tabular->DeleteRow(rows);
2457 paste_tabular->SetTopLine(0, true, true);
2458 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2460 for (int i = 0; i < sel_col_start; ++i)
2461 paste_tabular->DeleteColumn(0);
2462 while (paste_tabular->columns() > columns)
2463 paste_tabular->DeleteColumn(columns);
2464 paste_tabular->SetLeftLine(0, true, true);
2465 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2469 paste_tabular->ascii(bv->buffer(), sstr,
2470 (int)parOwner()->params().depth(), true, '\t');
2471 bv->stuffClipboard(sstr.str().c_str());
2476 bool InsetTabular::pasteSelection(BufferView * bv)
2481 for (int r1 = 0, r2 = actrow;
2482 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2484 for(int c1 = 0, c2 = actcol;
2485 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2487 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2488 tabular->IsPartOfMultiColumn(r2,c2))
2490 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2494 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2498 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2499 int const n2 = tabular->GetCellNumber(r2, c2);
2500 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2501 tabular->GetCellInset(n2)->setOwner(this);
2502 tabular->GetCellInset(n2)->deleteLyXText(bv);
2509 bool InsetTabular::cutSelection()
2511 if (!hasSelection())
2514 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2515 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2516 if (sel_col_start > sel_col_end) {
2517 sel_col_start = sel_col_end;
2518 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2520 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2522 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2523 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2524 if (sel_row_start > sel_row_end) {
2525 swap(sel_row_start, sel_row_end);
2527 if (sel_cell_start > sel_cell_end) {
2528 swap(sel_cell_start, sel_cell_end);
2530 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2531 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2532 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2539 bool InsetTabular::isRightToLeft(BufferView * bv)
2541 return bv->getParentLanguage(this)->RightToLeft();
2545 bool InsetTabular::nodraw() const
2547 if (!UpdatableInset::nodraw() && the_locking_inset)
2548 return the_locking_inset->nodraw();
2549 return UpdatableInset::nodraw();
2553 int InsetTabular::scroll(bool recursive) const
2555 int sx = UpdatableInset::scroll(false);
2557 if (recursive && the_locking_inset)
2558 sx += the_locking_inset->scroll(recursive);
2564 bool InsetTabular::doClearArea() const
2566 return !locked || (need_update & (FULL|INIT));
2570 void InsetTabular::getSelection(int & srow, int & erow,
2571 int & scol, int & ecol) const
2573 int const start = hasSelection() ? sel_cell_start : actcell;
2574 int const end = hasSelection() ? sel_cell_end : actcell;
2576 srow = tabular->row_of_cell(start);
2577 erow = tabular->row_of_cell(end);
2582 scol = tabular->column_of_cell(start);
2583 ecol = tabular->column_of_cell(end);
2587 ecol = tabular->right_column_of_cell(end);
2592 Paragraph * InsetTabular::getParFromID(int id) const
2595 for(int i = 0; i < tabular->rows(); ++i) {
2596 for(int j = 0; j < tabular->columns(); ++j) {
2597 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2605 Paragraph * InsetTabular::firstParagraph() const
2607 if (the_locking_inset)
2608 return the_locking_inset->firstParagraph();
2613 Paragraph * InsetTabular::getFirstParagraph(int i) const
2615 return (i < tabular->GetNumberOfCells())
2616 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2621 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2623 if (the_locking_inset)
2624 return the_locking_inset->cursor(bv);
2625 return Inset::cursor(bv);
2629 Inset * InsetTabular::getInsetFromID(int id_arg) const
2632 return const_cast<InsetTabular *>(this);
2635 for(int i = 0; i < tabular->rows(); ++i) {
2636 for(int j = 0; j < tabular->columns(); ++j) {
2637 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2646 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2649 if (the_locking_inset) {
2650 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2655 if (tabular->IsLastCell(actcell)) {
2656 bv->unlockInset(const_cast<InsetTabular *>(this));
2662 // otherwise we have to lock the next inset and ask for it's selecttion
2663 UpdatableInset * inset =
2664 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2665 inset->edit(bv, 0, 0, 0);
2666 string const str(selectNextWordInt(bv, value));
2674 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2676 // when entering this function the inset should be ALWAYS locked!
2677 lyx::Assert(the_locking_inset);
2679 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2683 if (tabular->IsLastCell(actcell)) {
2684 bv->unlockInset(const_cast<InsetTabular *>(this));
2688 // otherwise we have to lock the next inset and ask for it's selecttion
2689 UpdatableInset * inset =
2690 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2692 return selectNextWordInt(bv, value);
2696 void InsetTabular::selectSelectedWord(BufferView * bv)
2698 if (the_locking_inset) {
2699 the_locking_inset->selectSelectedWord(bv);
2706 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2708 if (the_locking_inset) {
2709 the_locking_inset->toggleSelection(bv, kill_selection);
2714 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2718 if (the_locking_inset) {
2719 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2721 updateLocal(bv, CELL, false);
2724 if (tabular->IsLastCell(actcell)) {
2726 bv->unlockInset(const_cast<InsetTabular *>(this));
2731 // otherwise we have to lock the next inset and search there
2732 UpdatableInset * inset =
2733 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2735 bool const ret = searchForward(bv, str, cs, mw);
2737 updateLocal(bv, CELL, false);
2742 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2746 if (the_locking_inset) {
2747 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2749 updateLocal(bv, CELL, false);
2752 if (!actcell) { // we are already in the first cell
2754 bv->unlockInset(const_cast<InsetTabular *>(this));
2759 // otherwise we have to lock the next inset and search there
2760 UpdatableInset * inset =
2761 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2762 inset->edit(bv, false);
2763 bool const ret = searchBackward(bv, str, cs, mw);
2765 updateLocal(bv, CELL, false);
2770 bool InsetTabular::insetAllowed(Inset::Code code) const
2772 if (the_locking_inset)
2773 return the_locking_inset->insetAllowed(code);
2778 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2780 const int cell = tabular->GetCellFromInset(in, actcell);
2783 return tabular->GetPWidth(cell).zero();
2785 // well we didn't obviously find it so maybe our owner knows more
2787 return owner()->forceDefaultParagraphs(in);
2788 // if we're here there is really something strange going on!!!
2792 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2795 if (buf.find('\t') == string::npos)
2801 string::size_type len = buf.length();
2802 string::size_type p = 0;
2805 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2814 maxCols = max(cols, maxCols);
2820 maxCols = max(cols, maxCols);
2821 LyXTabular * loctab;
2826 delete paste_tabular;
2827 paste_tabular = new LyXTabular(bv->buffer()->params,
2828 this, rows, maxCols);
2829 loctab = paste_tabular;
2832 loctab = tabular.get();
2837 string::size_type op = 0;
2838 int cells = loctab->GetNumberOfCells();
2841 rows = loctab->rows();
2842 int const columns = loctab->columns();
2843 while ((cell < cells) && (p < len) && (row < rows) &&
2844 (p = buf.find_first_of("\t\n", p)) != string::npos)
2850 // we can only set this if we are not too far right
2851 if (cols < columns) {
2852 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2858 // we can only set this if we are not too far right
2860 loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
2864 cell = loctab->GetCellNumber(row, cols);
2870 // check for the last cell if there is no trailing '\n'
2871 if ((cell < cells) && (op < len))
2872 loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));