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"
25 #include "frontends/Painter.h"
26 #include "frontends/font_metrics.h"
28 #include "frontends/LyXView.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)-1;
495 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
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)) {
548 string const InsetTabular::editMessage() const
550 return _("Opened Tabular Inset");
554 void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
556 UpdatableInset::edit(bv, x, y, button);
558 if (!bv->lockInset(this)) {
559 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
563 the_locking_inset = 0;
569 if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
570 activateCellInsetAbs(bv, x, y, button);
575 void InsetTabular::edit(BufferView * bv, bool front)
577 UpdatableInset::edit(bv, front);
579 if (!bv->lockInset(this)) {
580 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
585 the_locking_inset = 0;
591 actcell = tabular->GetNumberOfCells() - 1;
598 void InsetTabular::insetUnlock(BufferView * bv)
600 if (the_locking_inset) {
601 the_locking_inset->insetUnlock(bv);
602 updateLocal(bv, CELL, false);
603 the_locking_inset = 0;
608 if (scroll(false) || hasSelection()) {
613 updateLocal(bv, FULL, false);
618 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
619 bool mark_dirty) const
623 calculate_dimensions_of_cells(bv, font, true);
625 if (!locked && what == CELL)
627 if (need_update < what) // only set this if it has greater update
629 #if 0 // maybe this should not be done!
630 if ((what == INIT) && hasSelection()) {
635 if (need_update != NONE) {
636 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
637 if (locked) // && (what != NONE))
643 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
645 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
650 if (inset == tabular->GetCellInset(actcell)) {
651 lyxerr[Debug::INSETTEXT] << "OK" << endl;
652 the_locking_inset = tabular->GetCellInset(actcell);
655 } else if (!the_locking_inset) {
656 int const n = tabular->GetNumberOfCells();
657 int const id = inset->id();
658 for (int i = 0; i < n; ++i) {
659 InsetText * in = tabular->GetCellInset(i);
662 the_locking_inset = in;
667 if (in->getInsetFromID(id)) {
670 return the_locking_inset->lockInsetInInset(bv, inset);
673 } else if (the_locking_inset && (the_locking_inset == inset)) {
674 lyxerr[Debug::INSETTEXT] << "OK" << endl;
676 } else if (the_locking_inset) {
677 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
678 return the_locking_inset->lockInsetInInset(bv, inset);
680 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
685 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
688 if (!the_locking_inset)
690 if (the_locking_inset == inset) {
691 the_locking_inset->insetUnlock(bv);
693 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
699 updateLocal(bv, CELL, false);
700 // this has to be here otherwise we don't redraw the cell!
701 the_locking_inset = 0;
702 // showInsetCursor(bv, false);
705 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
706 if (inset->lyxCode() == TABULAR_CODE &&
707 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
708 bv->owner()->getDialogs()->updateTabular(this);
717 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
719 Inset * tl_inset = inset;
720 // look if this inset is really inside myself!
721 while(tl_inset->owner() && tl_inset->owner() != this)
722 tl_inset = tl_inset->owner();
723 // if we enter here it's not ower inset
724 if (!tl_inset->owner())
726 // we only have to do this if this is a subinset of our cells
727 if (tl_inset != inset) {
728 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
731 updateLocal(bv, CELL, false);
736 int InsetTabular::insetInInsetY() const
738 if (!the_locking_inset)
740 return inset_y + the_locking_inset->insetInInsetY();
744 UpdatableInset * InsetTabular::getLockingInset() const
746 return the_locking_inset ? the_locking_inset->getLockingInset() :
747 const_cast<InsetTabular *>(this);
751 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
755 if (the_locking_inset)
756 return the_locking_inset->getFirstLockingInsetOfType(c);
761 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
763 if (the_locking_inset)
764 return the_locking_inset->insertInset(bv, inset);
769 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button::state button)
771 if (hasSelection() && (button == mouse_button::button3))
774 if (hasSelection()) {
776 updateLocal(bv, SELECTION, false);
779 int const ocell = actcell;
780 int const orow = actrow;
785 the_locking_inset = 0;
791 updateLocal(bv, NONE, false);
795 if ((ocell != actcell) && the_locking_inset) {
796 the_locking_inset->insetUnlock(bv);
797 updateLocal(bv, CELL, false);
798 the_locking_inset = 0;
805 bool const inset_hit = insetHit(bv, x, y);
807 if ((ocell == actcell) && the_locking_inset && inset_hit) {
809 the_locking_inset->insetButtonPress(bv,
810 x - inset_x, y - inset_y,
813 } else if (the_locking_inset) {
814 the_locking_inset->insetUnlock(bv);
815 updateLocal(bv, CELL, false);
816 the_locking_inset = 0;
818 if (button == mouse_button::button2) {
819 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
822 if (inset_hit && bv->theLockingInset()) {
823 if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
824 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
827 the_locking_inset->insetButtonPress(
828 bv, x - inset_x, y - inset_y, button);
835 bool InsetTabular::insetButtonRelease(BufferView * bv,
836 int x, int y, mouse_button::state button)
839 if (the_locking_inset)
840 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
841 y - inset_y, button);
842 if (button == mouse_button::button3 && !ret) {
843 bv->owner()->getDialogs()->showTabular(this);
850 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state button)
852 if (the_locking_inset) {
853 the_locking_inset->insetMotionNotify(bv,
861 // int const old_cell = actcell;
864 if (!hasSelection()) {
865 setSelection(actcell, actcell);
867 setSelection(sel_cell_start, actcell);
869 updateLocal(bv, SELECTION, false);
874 UpdatableInset::RESULT
875 InsetTabular::localDispatch(BufferView * bv, kb_action action,
878 // We need to save the value of the_locking_inset as the call to
879 // the_locking_inset->LocalDispatch might unlock it.
880 old_locking_inset = the_locking_inset;
881 UpdatableInset::RESULT result =
882 UpdatableInset::localDispatch(bv, action, arg);
883 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
888 if ((action < 0) && arg.empty())
891 bool hs = hasSelection();
894 // this one have priority over the locked InsetText, if we're not already
895 // inside another tabular then that one get's priority!
896 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
901 unlockInsetInInset(bv, the_locking_inset);
902 if (action == LFUN_TAB)
903 moveNextCell(bv, old_locking_inset != 0);
905 movePrevCell(bv, old_locking_inset != 0);
908 updateLocal(bv, SELECTION, false);
909 if (!the_locking_inset) {
911 return DISPATCHED_NOUPDATE;
914 // this to avoid compiler warnings.
920 if (the_locking_inset) {
921 result = the_locking_inset->localDispatch(bv, action, arg);
922 if (result == DISPATCHED_NOUPDATE) {
925 if (sc != scroll()) { // inset has been scrolled
926 the_locking_inset->toggleInsetCursor(bv);
927 updateLocal(bv, FULL, false);
928 the_locking_inset->toggleInsetCursor(bv);
931 } else if (result == DISPATCHED) {
932 the_locking_inset->toggleInsetCursor(bv);
933 updateLocal(bv, CELL, false);
934 the_locking_inset->toggleInsetCursor(bv);
936 } else if (result == FINISHED_UP) {
938 } else if (result == FINISHED_DOWN) {
940 } else if (result == FINISHED_RIGHT) {
948 // --- Cursor Movements ----------------------------------
949 case LFUN_RIGHTSEL: {
950 int const start = hasSelection() ? sel_cell_start : actcell;
951 if (tabular->IsLastCellInRow(actcell)) {
952 setSelection(start, actcell);
957 // if we are starting a selection, only select
958 // the current cell at the beginning
959 if (hasSelection()) {
960 moveRight(bv, false);
963 setSelection(start, end);
964 updateLocal(bv, SELECTION, false);
968 result = moveRight(bv);
971 updateLocal(bv, SELECTION, false);
974 int const start = hasSelection() ? sel_cell_start : actcell;
975 if (tabular->IsFirstCellInRow(actcell)) {
976 setSelection(start, actcell);
981 // if we are starting a selection, only select
982 // the current cell at the beginning
983 if (hasSelection()) {
987 setSelection(start, end);
988 updateLocal(bv, SELECTION, false);
992 result = moveLeft(bv);
995 updateLocal(bv, SELECTION, false);
998 int const start = hasSelection() ? sel_cell_start : actcell;
999 int const ocell = actcell;
1000 // if we are starting a selection, only select
1001 // the current cell at the beginning
1002 if (hasSelection()) {
1003 moveDown(bv, false);
1004 if ((ocell == sel_cell_end) ||
1005 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1006 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1008 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1010 setSelection(start, start);
1012 updateLocal(bv, SELECTION, false);
1016 result = moveDown(bv, old_locking_inset != 0);
1019 updateLocal(bv, SELECTION, false);
1023 int const start = hasSelection() ? sel_cell_start : actcell;
1024 int const ocell = actcell;
1025 // if we are starting a selection, only select
1026 // the current cell at the beginning
1027 if (hasSelection()) {
1029 if ((ocell == sel_cell_end) ||
1030 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1031 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1033 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1035 setSelection(start, start);
1037 updateLocal(bv, SELECTION, false);
1041 result = moveUp(bv, old_locking_inset != 0);
1044 updateLocal(bv, SELECTION, false);
1047 UpdateCodes code = CURSOR;
1052 int column = actcol;
1053 unlockInsetInInset(bv, the_locking_inset);
1054 if (bv->text->first_y + bv->painter().paperHeight() <
1055 (top_baseline + tabular->GetHeightOfTabular()))
1057 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1059 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1061 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1064 updateLocal(bv, code, false);
1068 UpdateCodes code = CURSOR;
1073 int column = actcol;
1074 unlockInsetInInset(bv, the_locking_inset);
1075 if (top_baseline < 0) {
1076 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1078 if (top_baseline > 0)
1081 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1086 updateLocal(bv, code, false);
1089 // none of these make sense for insettabular,
1090 // but we must catch them to prevent any
1091 // selection from being confused
1095 case LFUN_WORDLEFTSEL:
1096 case LFUN_WORDRIGHT:
1097 case LFUN_WORDRIGHTSEL:
1098 case LFUN_DOWN_PARAGRAPH:
1099 case LFUN_DOWN_PARAGRAPHSEL:
1100 case LFUN_UP_PARAGRAPH:
1101 case LFUN_UP_PARAGRAPHSEL:
1102 case LFUN_BACKSPACE:
1108 case LFUN_BEGINNINGBUF:
1109 case LFUN_BEGINNINGBUFSEL:
1111 case LFUN_ENDBUFSEL:
1113 case LFUN_LAYOUT_TABULAR:
1114 bv->owner()->getDialogs()->showTabular(this);
1116 case LFUN_TABULAR_FEATURE:
1117 if (!tabularFeatures(bv, arg))
1118 result = UNDISPATCHED;
1120 // insert file functions
1121 case LFUN_FILE_INSERT_ASCII_PARA:
1122 case LFUN_FILE_INSERT_ASCII:
1124 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1127 if (insertAsciiString(bv, tmpstr, false))
1128 updateLocal(bv, INIT, true);
1130 result = UNDISPATCHED;
1133 // cut and paste functions
1135 if (!copySelection(bv))
1137 setUndo(bv, Undo::DELETE,
1138 bv->text->cursor.par(),
1139 bv->text->cursor.par()->next());
1141 updateLocal(bv, INIT, true);
1144 if (!hasSelection())
1149 case LFUN_PASTESELECTION:
1151 string const clip(bv->getClipboard());
1155 if (clip.find('\t') != string::npos) {
1159 string::size_type len = clip.length();
1160 string::size_type p = 0;
1163 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1171 maxCols = max(cols, maxCols);
1177 maxCols = max(cols, maxCols);
1178 delete paste_tabular;
1179 paste_tabular = new LyXTabular(bv->buffer()->params,
1180 this, rows, maxCols);
1181 string::size_type op = 0;
1183 int cells = paste_tabular->GetNumberOfCells();
1185 while ((cell < cells) && (p < len) &&
1186 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1191 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1196 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1197 while (cols++ < maxCols)
1205 // check for the last cell if there is no trailing '\n'
1206 if ((cell < cells) && (op < len))
1207 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1210 if (!insertAsciiString(bv, clip, true))
1213 // so that the clipboard is used and it goes on
1215 // and executes LFUN_PASTESELECTION in insettext!
1216 delete paste_tabular;
1221 if (hasPasteBuffer()) {
1222 setUndo(bv, Undo::INSERT,
1223 bv->text->cursor.par(),
1224 bv->text->cursor.par()->next());
1226 updateLocal(bv, INIT, true);
1229 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1231 // handle font changing stuff on selection before we lock the inset
1232 // in the default part!
1233 result = UNDISPATCHED;
1244 case LFUN_UNDERLINE:
1245 case LFUN_FONT_SIZE:
1246 if (bv->Dispatch(action, arg))
1247 result = DISPATCHED;
1253 // we try to activate the actual inset and put this event down to
1254 // the insets dispatch function.
1255 if ((result == DISPATCHED) || the_locking_inset)
1258 if (activateCellInset(bv)) {
1259 // reset need_update setted in above function!
1261 result = the_locking_inset->localDispatch(bv, action, arg);
1262 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1263 unlockInsetInInset(bv, the_locking_inset);
1265 // we need to update if this was requested before
1266 updateLocal(bv, NONE, false);
1267 return UNDISPATCHED;
1270 // so the below CELL is not set because this is higher
1271 // priority and we get a full redraw
1272 need_update = SELECTION;
1275 updateLocal(bv, CELL, false);
1280 if (result < FINISHED) {
1281 if (!the_locking_inset) {
1282 if (bv->fitCursor())
1283 updateLocal(bv, FULL, false);
1285 showInsetCursor(bv);
1288 bv->unlockInset(this);
1293 int InsetTabular::latex(Buffer const * buf, ostream & os,
1294 bool fragile, bool fp) const
1296 return tabular->latex(buf, os, fragile, fp);
1300 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1303 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1305 return tabular->ascii(buf, os, 0, false,0);
1309 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1312 int const ret = tabular->ascii(buf,os,
1313 (int)parOwner()->params().depth(),
1320 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1325 // if the table is inside a float it doesn't need the informaltable
1326 // wrapper. Search for it.
1327 for(master = owner();
1328 master && master->lyxCode() != Inset::FLOAT_CODE;
1329 master = master->owner());
1332 os << "<informaltable>\n";
1335 ret+= tabular->docBook(buf,os);
1337 os << "</informaltable>\n";
1344 void InsetTabular::validate(LaTeXFeatures & features) const
1346 tabular->Validate(features);
1350 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1351 LyXFont const & font,
1358 bool changed = false;
1360 // if we have a locking_inset we should have to check only this cell for
1361 // change so I'll try this to have a boost, but who knows ;)
1362 if ((need_update != INIT) &&
1363 (the_locking_inset == tabular->GetCellInset(actcell))) {
1364 for(int i = 0; i < tabular->columns(); ++i) {
1365 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1367 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1370 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1371 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1372 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1375 for (int i = 0; i < tabular->rows(); ++i) {
1378 for (int j = 0; j < tabular->columns(); ++j) {
1379 if (tabular->IsPartOfMultiColumn(i,j))
1382 inset = tabular->GetCellInset(cell);
1383 if (!reinit && !tabular->GetPWidth(cell).zero())
1384 inset->update(bv, font, false);
1385 maxAsc = max(maxAsc, inset->ascent(bv, font));
1386 maxDesc = max(maxDesc, inset->descent(bv, font));
1387 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1389 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1390 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1398 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1400 if (the_locking_inset) {
1401 the_locking_inset->getCursorPos(bv, x, y);
1404 x = cursor_.x() - top_x;
1409 void InsetTabular::toggleInsetCursor(BufferView * bv)
1412 if (isCursorVisible())
1413 bv->hideLockedInsetCursor();
1416 if (the_locking_inset) {
1417 the_locking_inset->toggleInsetCursor(bv);
1421 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1423 int const asc = font_metrics::maxAscent(font);
1424 int const desc = font_metrics::maxDescent(font);
1426 if (isCursorVisible())
1427 bv->hideLockedInsetCursor();
1429 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1430 toggleCursorVisible();
1434 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1438 if (!isCursorVisible()) {
1439 LyXFont font; // = GetFont(par, cursor.pos);
1441 int const asc = font_metrics::maxAscent(font);
1442 int const desc = font_metrics::maxDescent(font);
1443 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1445 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1446 setCursorVisible(true);
1451 void InsetTabular::hideInsetCursor(BufferView * bv)
1453 if (isCursorVisible()) {
1454 bv->hideLockedInsetCursor();
1455 setCursorVisible(false);
1460 void InsetTabular::fitInsetCursor(BufferView * bv) const
1462 if (the_locking_inset) {
1463 int old_first_y = bv->text->first_y;
1464 the_locking_inset->fitInsetCursor(bv);
1465 if (old_first_y != bv->text->first_y)
1471 int const asc = font_metrics::maxAscent(font);
1472 int const desc = font_metrics::maxDescent(font);
1475 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1480 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1484 actcell = actrow = actcol = 0;
1485 int ly = tabular->GetDescentOfRow(actrow);
1487 // first search the right row
1488 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1489 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1490 tabular->GetAscentOfRow(actrow + 1) +
1491 tabular->GetAdditionalHeight(actrow + 1));
1493 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1495 actcell = tabular->GetCellNumber(actrow, actcol);
1497 // now search the right column
1498 int lx = tabular->GetWidthOfColumn(actcell) -
1499 tabular->GetAdditionalWidth(actcell);
1500 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1501 lx += tabular->GetWidthOfColumn(actcell + 1)
1502 + tabular->GetAdditionalWidth(actcell);
1504 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1509 int InsetTabular::getCellXPos(int cell) const
1513 for (; !tabular->IsFirstCellInRow(c); --c)
1515 int lx = tabular->GetWidthOfColumn(cell);
1516 for (; c < cell; ++c) {
1517 lx += tabular->GetWidthOfColumn(c);
1519 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1523 void InsetTabular::resetPos(BufferView * bv) const
1525 #ifdef WITH_WARNINGS
1526 #warning This should be fixed in the right manner (20011128 Jug)
1528 // fast hack to fix infinite repaintings!
1533 actcol = tabular->column_of_cell(actcell);
1536 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1537 if (tabular->IsLastCellInRow(cell)) {
1538 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1539 tabular->GetAscentOfRow(actrow + 1) +
1540 tabular->GetAdditionalHeight(actrow + 1));
1544 if (!locked || nodraw()) {
1545 if (the_locking_inset)
1546 inset_y = cursor_.y();
1549 // we need this only from here on!!!
1550 in_reset_pos = true;
1551 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1552 int new_x = getCellXPos(actcell);
1553 int old_x = cursor_.x();
1556 // cursor.x(getCellXPos(actcell) + offset);
1557 if ((actcol < tabular->columns()-1) && scroll(false) &&
1558 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1561 updateLocal(bv, FULL, false);
1562 } else if (the_locking_inset &&
1563 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1565 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1566 if (xx > (bv->workWidth()-20)) {
1567 scroll(bv, -(xx - bv->workWidth() + 60));
1568 updateLocal(bv, FULL, false);
1569 } else if (xx < 20) {
1575 updateLocal(bv, FULL, false);
1577 } else if ((cursor_.x() - offset) > 20 &&
1578 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1579 > (bv->workWidth() - 20)) {
1580 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1581 updateLocal(bv, FULL, false);
1582 } else if ((cursor_.x() - offset) < 20) {
1583 scroll(bv, 20 - cursor_.x() + offset);
1584 updateLocal(bv, FULL, false);
1585 } else if (scroll(false) && top_x > 20 &&
1586 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1587 scroll(bv, old_x - cursor_.x());
1588 updateLocal(bv, FULL, false);
1590 if (the_locking_inset) {
1591 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1592 inset_y = cursor_.y();
1594 if ((!the_locking_inset ||
1595 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1596 actcell != oldcell) {
1597 InsetTabular * inset = const_cast<InsetTabular *>(this);
1598 bv->owner()->getDialogs()->updateTabular(inset);
1601 in_reset_pos = false;
1605 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1607 if (lock && !old_locking_inset) {
1608 if (activateCellInset(bv))
1611 bool moved = isRightToLeft(bv)
1612 ? movePrevCell(bv) : moveNextCell(bv);
1614 return FINISHED_RIGHT;
1615 if (lock && activateCellInset(bv))
1619 return DISPATCHED_NOUPDATE;
1623 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1625 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1628 if (lock) { // behind the inset
1629 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1633 return DISPATCHED_NOUPDATE;
1637 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1639 int const ocell = actcell;
1640 actcell = tabular->GetCellAbove(actcell);
1641 if (actcell == ocell) // we moved out of the inset
1647 if (old_locking_inset) {
1648 old_locking_inset->getCursorPos(bv, x, y);
1649 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1651 if (activateCellInset(bv, x, 0))
1654 return DISPATCHED_NOUPDATE;
1658 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1660 int const ocell = actcell;
1661 actcell = tabular->GetCellBelow(actcell);
1662 if (actcell == ocell) // we moved out of the inset
1663 return FINISHED_DOWN;
1668 if (old_locking_inset) {
1669 old_locking_inset->getCursorPos(bv, x, y);
1670 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1672 if (activateCellInset(bv, x, 0))
1675 return DISPATCHED_NOUPDATE;
1679 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1681 if (isRightToLeft(bv)) {
1682 if (tabular->IsFirstCellInRow(actcell)) {
1683 int row = tabular->row_of_cell(actcell);
1684 if (row == tabular->rows() - 1)
1686 actcell = tabular->GetLastCellInRow(row);
1687 actcell = tabular->GetCellBelow(actcell);
1694 if (tabular->IsLastCell(actcell))
1699 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1700 isRightToLeftPar(bv->buffer()->params);
1701 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1708 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1710 if (isRightToLeft(bv)) {
1711 if (tabular->IsLastCellInRow(actcell)) {
1712 int row = tabular->row_of_cell(actcell);
1715 actcell = tabular->GetFirstCellInRow(row);
1716 actcell = tabular->GetCellAbove(actcell);
1718 if (tabular->IsLastCell(actcell))
1723 if (!actcell) // first cell
1728 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1729 isRightToLeftPar(bv->buffer()->params);
1730 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1737 bool InsetTabular::deletable() const
1743 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1747 setSelection(0, tabular->GetNumberOfCells() - 1);
1749 if (hasSelection()) {
1750 setUndo(bv, Undo::EDIT,
1751 bv->text->cursor.par(),
1752 bv->text->cursor.par()->next());
1753 bool frozen = undo_frozen;
1756 // apply the fontchange on the whole selection
1761 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1762 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1763 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1764 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1771 updateLocal(bv, INIT, true);
1773 if (the_locking_inset)
1774 the_locking_inset->setFont(bv, font, tall);
1778 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1780 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1783 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1784 string const tmp = tabularFeature[i].feature;
1786 if (tmp == what.substr(0, tmp.length())) {
1787 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1788 //tabularFeatures[i].feature.length())) {
1789 action = tabularFeature[i].action;
1793 if (action == LyXTabular::LAST_ACTION)
1797 frontStrip(what.substr(tabularFeature[i].feature.length()));
1798 tabularFeatures(bv, action, val);
1802 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1803 string const & special, bool & flag)
1805 if (special == "dl_above") {
1808 } else if (special == "dl_below") {
1809 ltt.bottomDL = flag;
1811 } else if (special == "empty") {
1821 void InsetTabular::tabularFeatures(BufferView * bv,
1822 LyXTabular::Feature feature,
1823 string const & value)
1829 bool setLines = false;
1830 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1831 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1834 case LyXTabular::M_ALIGN_LEFT:
1835 case LyXTabular::ALIGN_LEFT:
1836 setAlign = LYX_ALIGN_LEFT;
1838 case LyXTabular::M_ALIGN_RIGHT:
1839 case LyXTabular::ALIGN_RIGHT:
1840 setAlign = LYX_ALIGN_RIGHT;
1842 case LyXTabular::M_ALIGN_CENTER:
1843 case LyXTabular::ALIGN_CENTER:
1844 setAlign = LYX_ALIGN_CENTER;
1846 case LyXTabular::M_VALIGN_TOP:
1847 case LyXTabular::VALIGN_TOP:
1848 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1850 case LyXTabular::M_VALIGN_BOTTOM:
1851 case LyXTabular::VALIGN_BOTTOM:
1852 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1854 case LyXTabular::M_VALIGN_CENTER:
1855 case LyXTabular::VALIGN_CENTER:
1856 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1861 if (hasSelection()) {
1862 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1864 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1865 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1867 setUndo(bv, Undo::FINISH,
1868 bv->text->cursor.par(),
1869 bv->text->cursor.par()->next());
1871 int row = tabular->row_of_cell(actcell);
1872 int column = tabular->column_of_cell(actcell);
1874 LyXTabular::ltType ltt;
1877 case LyXTabular::SET_PWIDTH:
1879 LyXLength const vallen(value);
1880 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1882 bool const update = (tmplen != vallen);
1883 tabular->SetColumnPWidth(actcell, vallen);
1886 for (int i = 0; i < tabular->rows(); ++i) {
1887 cell = tabular->GetCellNumber(i,column);
1888 tabular->GetCellInset(cell)->resizeLyXText(bv);
1890 updateLocal(bv, INIT, true);
1894 case LyXTabular::SET_MPWIDTH:
1896 LyXLength const vallen(value);
1897 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1899 bool const update = (tmplen != vallen);
1900 tabular->SetMColumnPWidth(actcell, vallen);
1902 for (int i = 0; i < tabular->rows(); ++i) {
1903 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1906 updateLocal(bv, INIT, true);
1910 case LyXTabular::SET_SPECIAL_COLUMN:
1911 case LyXTabular::SET_SPECIAL_MULTI:
1912 tabular->SetAlignSpecial(actcell,value,feature);
1913 updateLocal(bv, FULL, true);
1915 case LyXTabular::APPEND_ROW:
1916 // append the row into the tabular
1917 unlockInsetInInset(bv, the_locking_inset);
1918 tabular->AppendRow(bv->buffer()->params, actcell);
1919 updateLocal(bv, INIT, true);
1921 case LyXTabular::APPEND_COLUMN:
1922 // append the column into the tabular
1923 unlockInsetInInset(bv, the_locking_inset);
1924 tabular->AppendColumn(bv->buffer()->params, actcell);
1925 actcell = tabular->GetCellNumber(row, column);
1926 updateLocal(bv, INIT, true);
1928 case LyXTabular::DELETE_ROW:
1929 unlockInsetInInset(bv, the_locking_inset);
1930 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1931 tabular->DeleteRow(sel_row_start);
1933 if (sel_row_start >= tabular->rows())
1935 actcell = tabular->GetCellNumber(sel_row_start, column);
1937 updateLocal(bv, INIT, true);
1939 case LyXTabular::DELETE_COLUMN:
1940 unlockInsetInInset(bv, the_locking_inset);
1941 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1942 tabular->DeleteColumn(sel_col_start);
1944 if (sel_col_start >= tabular->columns())
1946 actcell = tabular->GetCellNumber(row, sel_col_start);
1948 updateLocal(bv, INIT, true);
1950 case LyXTabular::M_TOGGLE_LINE_TOP:
1952 case LyXTabular::TOGGLE_LINE_TOP:
1954 bool lineSet = !tabular->TopLine(actcell, flag);
1955 for (int i = sel_row_start; i <= sel_row_end; ++i)
1956 for (int j = sel_col_start; j <= sel_col_end; ++j)
1957 tabular->SetTopLine(
1958 tabular->GetCellNumber(i, j),
1960 updateLocal(bv, INIT, true);
1964 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1966 case LyXTabular::TOGGLE_LINE_BOTTOM:
1968 bool lineSet = !tabular->BottomLine(actcell, flag);
1969 for (int i = sel_row_start; i <= sel_row_end; ++i)
1970 for (int j = sel_col_start; j <= sel_col_end; ++j)
1971 tabular->SetBottomLine(
1972 tabular->GetCellNumber(i, j),
1975 updateLocal(bv, INIT, true);
1979 case LyXTabular::M_TOGGLE_LINE_LEFT:
1981 case LyXTabular::TOGGLE_LINE_LEFT:
1983 bool lineSet = !tabular->LeftLine(actcell, flag);
1984 for (int i = sel_row_start; i <= sel_row_end; ++i)
1985 for (int j = sel_col_start; j <= sel_col_end; ++j)
1986 tabular->SetLeftLine(
1987 tabular->GetCellNumber(i,j),
1990 updateLocal(bv, INIT, true);
1994 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1996 case LyXTabular::TOGGLE_LINE_RIGHT:
1998 bool lineSet = !tabular->RightLine(actcell, flag);
1999 for (int i = sel_row_start; i <= sel_row_end; ++i)
2000 for (int j = sel_col_start; j <= sel_col_end; ++j)
2001 tabular->SetRightLine(
2002 tabular->GetCellNumber(i,j),
2005 updateLocal(bv, INIT, true);
2009 case LyXTabular::M_ALIGN_LEFT:
2010 case LyXTabular::M_ALIGN_RIGHT:
2011 case LyXTabular::M_ALIGN_CENTER:
2013 case LyXTabular::ALIGN_LEFT:
2014 case LyXTabular::ALIGN_RIGHT:
2015 case LyXTabular::ALIGN_CENTER:
2016 for (int i = sel_row_start; i <= sel_row_end; ++i)
2017 for (int j = sel_col_start; j <= sel_col_end; ++j)
2018 tabular->SetAlignment(
2019 tabular->GetCellNumber(i, j),
2022 updateLocal(bv, INIT, true);
2024 case LyXTabular::M_VALIGN_TOP:
2025 case LyXTabular::M_VALIGN_BOTTOM:
2026 case LyXTabular::M_VALIGN_CENTER:
2028 case LyXTabular::VALIGN_TOP:
2029 case LyXTabular::VALIGN_BOTTOM:
2030 case LyXTabular::VALIGN_CENTER:
2031 for (int i = sel_row_start; i <= sel_row_end; ++i)
2032 for (int j = sel_col_start; j <= sel_col_end; ++j)
2033 tabular->SetVAlignment(
2034 tabular->GetCellNumber(i, j),
2036 updateLocal(bv, INIT, true);
2038 case LyXTabular::MULTICOLUMN:
2040 if (sel_row_start != sel_row_end) {
2041 Alert::alert(_("Impossible Operation!"),
2042 _("Multicolumns can only be horizontally."),
2046 // just multicol for one Single Cell
2047 if (!hasSelection()) {
2048 // check wether we are completly in a multicol
2049 if (tabular->IsMultiColumn(actcell)) {
2050 tabular->UnsetMultiColumn(actcell);
2051 updateLocal(bv, INIT, true);
2053 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2054 updateLocal(bv, CELL, true);
2058 // we have a selection so this means we just add all this
2059 // cells to form a multicolumn cell
2063 if (sel_cell_start > sel_cell_end) {
2064 s_start = sel_cell_end;
2065 s_end = sel_cell_start;
2067 s_start = sel_cell_start;
2068 s_end = sel_cell_end;
2070 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2073 updateLocal(bv, INIT, true);
2076 case LyXTabular::SET_ALL_LINES:
2078 case LyXTabular::UNSET_ALL_LINES:
2079 for (int i = sel_row_start; i <= sel_row_end; ++i)
2080 for (int j = sel_col_start; j <= sel_col_end; ++j)
2081 tabular->SetAllLines(
2082 tabular->GetCellNumber(i,j), setLines);
2083 updateLocal(bv, INIT, true);
2085 case LyXTabular::SET_LONGTABULAR:
2086 tabular->SetLongTabular(true);
2087 updateLocal(bv, INIT, true); // because this toggles displayed
2089 case LyXTabular::UNSET_LONGTABULAR:
2090 tabular->SetLongTabular(false);
2091 updateLocal(bv, INIT, true); // because this toggles displayed
2093 case LyXTabular::SET_ROTATE_TABULAR:
2094 tabular->SetRotateTabular(true);
2096 case LyXTabular::UNSET_ROTATE_TABULAR:
2097 tabular->SetRotateTabular(false);
2099 case LyXTabular::SET_ROTATE_CELL:
2100 for (int i = sel_row_start; i <= sel_row_end; ++i)
2101 for (int j = sel_col_start; j<=sel_col_end; ++j)
2102 tabular->SetRotateCell(
2103 tabular->GetCellNumber(i, j),
2106 case LyXTabular::UNSET_ROTATE_CELL:
2107 for (int i = sel_row_start; i <= sel_row_end; ++i)
2108 for (int j = sel_col_start; j <= sel_col_end; ++j)
2109 tabular->SetRotateCell(
2110 tabular->GetCellNumber(i, j), false);
2112 case LyXTabular::SET_USEBOX:
2114 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2115 if (val == tabular->GetUsebox(actcell))
2116 val = LyXTabular::BOX_NONE;
2117 for (int i = sel_row_start; i <= sel_row_end; ++i)
2118 for (int j = sel_col_start; j <= sel_col_end; ++j)
2120 tabular->GetCellNumber(i, j), val);
2123 case LyXTabular::UNSET_LTFIRSTHEAD:
2125 case LyXTabular::SET_LTFIRSTHEAD:
2126 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2127 checkLongtableSpecial(ltt, value, flag);
2128 tabular->SetLTHead(row, flag, ltt, true);
2130 case LyXTabular::UNSET_LTHEAD:
2132 case LyXTabular::SET_LTHEAD:
2133 (void)tabular->GetRowOfLTHead(row, ltt);
2134 checkLongtableSpecial(ltt, value, flag);
2135 tabular->SetLTHead(row, flag, ltt, false);
2137 case LyXTabular::UNSET_LTFOOT:
2139 case LyXTabular::SET_LTFOOT:
2140 (void)tabular->GetRowOfLTFoot(row, ltt);
2141 checkLongtableSpecial(ltt, value, flag);
2142 tabular->SetLTFoot(row, flag, ltt, false);
2144 case LyXTabular::UNSET_LTLASTFOOT:
2146 case LyXTabular::SET_LTLASTFOOT:
2147 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2148 checkLongtableSpecial(ltt, value, flag);
2149 tabular->SetLTFoot(row, flag, ltt, true);
2151 case LyXTabular::SET_LTNEWPAGE:
2153 bool what = !tabular->GetLTNewPage(row);
2154 tabular->SetLTNewPage(row, what);
2157 // dummy stuff just to avoid warnings
2158 case LyXTabular::LAST_ACTION:
2164 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2167 UpdatableInset * inset =
2168 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2169 LyXFont font(LyXFont::ALL_SANE);
2171 x = inset->x() + inset->width(bv, font);
2172 y = inset->descent(bv, font);
2174 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2175 //inset_y = cursor.y();
2176 inset->edit(bv, x, y, button);
2177 if (!the_locking_inset)
2179 updateLocal(bv, CELL, false);
2180 return (the_locking_inset != 0);
2184 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2185 mouse_button::state button)
2187 inset_x = cursor_.x()
2188 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2189 inset_y = cursor_.y();
2190 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2194 bool InsetTabular::insetHit(BufferView *, int x, int) const
2197 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2201 // This returns paperWidth() if the cell-width is unlimited or the width
2202 // in pixels if we have a pwidth for this cell.
2203 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2205 LyXLength const len = tabular->GetPWidth(cell);
2209 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2213 int InsetTabular::getMaxWidth(BufferView * bv,
2214 UpdatableInset const * inset) const
2216 int cell = tabular->GetCellFromInset(inset, actcell);
2219 lyxerr << "Own inset not found, shouldn't really happen!"
2224 int w = getMaxWidthOfCell(bv, cell);
2226 // because the inset then subtracts it's top_x and owner->x()
2227 w += (inset->x() - top_x);
2234 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2236 resizeLyXText(bv, recursive);
2240 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2243 for(int i = 0; i < tabular->rows(); ++i) {
2244 for(int j = 0; j < tabular->columns(); ++j) {
2245 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2253 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2254 bool const recursive) const
2256 if (the_locking_inset)
2257 return the_locking_inset->getLyXText(bv, recursive);
2259 // if we're locked lock the actual insettext and return it's LyXText!!!
2261 UpdatableInset * inset =
2262 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2263 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2264 return the_locking_inset->getLyXText(bv, recursive);
2267 return Inset::getLyXText(bv, recursive);
2271 bool InsetTabular::showInsetDialog(BufferView * bv) const
2273 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2274 bv->owner()->getDialogs()
2275 ->showTabular(const_cast<InsetTabular *>(this));
2280 void InsetTabular::openLayoutDialog(BufferView * bv) const
2282 if (the_locking_inset) {
2283 InsetTabular * i = static_cast<InsetTabular *>
2284 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2286 i->openLayoutDialog(bv);
2290 bv->owner()->getDialogs()->showTabular(
2291 const_cast<InsetTabular *>(this));
2296 // function returns an object as defined in func_status.h:
2297 // states OK, Unknown, Disabled, On, Off.
2299 FuncStatus InsetTabular::getStatus(string const & what) const
2301 int action = LyXTabular::LAST_ACTION;
2305 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2306 string const tmp = tabularFeature[i].feature;
2307 if (tmp == what.substr(0, tmp.length())) {
2308 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2309 // tabularFeatures[i].feature.length())) {
2310 action = tabularFeature[i].action;
2314 if (action == LyXTabular::LAST_ACTION) {
2316 return status.unknown(true);
2319 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2324 LyXTabular::ltType dummyltt;
2327 if (hasSelection()) {
2328 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2330 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2334 case LyXTabular::SET_PWIDTH:
2335 case LyXTabular::SET_MPWIDTH:
2336 case LyXTabular::SET_SPECIAL_COLUMN:
2337 case LyXTabular::SET_SPECIAL_MULTI:
2338 return status.disabled(true);
2340 case LyXTabular::APPEND_ROW:
2341 case LyXTabular::APPEND_COLUMN:
2342 case LyXTabular::DELETE_ROW:
2343 case LyXTabular::DELETE_COLUMN:
2344 case LyXTabular::SET_ALL_LINES:
2345 case LyXTabular::UNSET_ALL_LINES:
2346 return status.clear();
2348 case LyXTabular::MULTICOLUMN:
2349 status.setOnOff(tabular->IsMultiColumn(actcell));
2351 case LyXTabular::M_TOGGLE_LINE_TOP:
2353 case LyXTabular::TOGGLE_LINE_TOP:
2354 status.setOnOff(tabular->TopLine(actcell, flag));
2356 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2358 case LyXTabular::TOGGLE_LINE_BOTTOM:
2359 status.setOnOff(tabular->BottomLine(actcell, flag));
2361 case LyXTabular::M_TOGGLE_LINE_LEFT:
2363 case LyXTabular::TOGGLE_LINE_LEFT:
2364 status.setOnOff(tabular->LeftLine(actcell, flag));
2366 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2368 case LyXTabular::TOGGLE_LINE_RIGHT:
2369 status.setOnOff(tabular->RightLine(actcell, flag));
2371 case LyXTabular::M_ALIGN_LEFT:
2373 case LyXTabular::ALIGN_LEFT:
2374 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2376 case LyXTabular::M_ALIGN_RIGHT:
2378 case LyXTabular::ALIGN_RIGHT:
2379 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2381 case LyXTabular::M_ALIGN_CENTER:
2383 case LyXTabular::ALIGN_CENTER:
2384 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2386 case LyXTabular::M_VALIGN_TOP:
2388 case LyXTabular::VALIGN_TOP:
2389 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2391 case LyXTabular::M_VALIGN_BOTTOM:
2393 case LyXTabular::VALIGN_BOTTOM:
2394 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2396 case LyXTabular::M_VALIGN_CENTER:
2398 case LyXTabular::VALIGN_CENTER:
2399 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2401 case LyXTabular::SET_LONGTABULAR:
2402 status.setOnOff(tabular->IsLongTabular());
2404 case LyXTabular::UNSET_LONGTABULAR:
2405 status.setOnOff(!tabular->IsLongTabular());
2407 case LyXTabular::SET_ROTATE_TABULAR:
2408 status.setOnOff(tabular->GetRotateTabular());
2410 case LyXTabular::UNSET_ROTATE_TABULAR:
2411 status.setOnOff(!tabular->GetRotateTabular());
2413 case LyXTabular::SET_ROTATE_CELL:
2414 status.setOnOff(tabular->GetRotateCell(actcell));
2416 case LyXTabular::UNSET_ROTATE_CELL:
2417 status.setOnOff(!tabular->GetRotateCell(actcell));
2419 case LyXTabular::SET_USEBOX:
2420 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2422 case LyXTabular::SET_LTFIRSTHEAD:
2423 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2425 case LyXTabular::SET_LTHEAD:
2426 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2428 case LyXTabular::SET_LTFOOT:
2429 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2431 case LyXTabular::SET_LTLASTFOOT:
2432 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2434 case LyXTabular::SET_LTNEWPAGE:
2435 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2439 status.disabled(true);
2446 vector<string> const InsetTabular::getLabelList() const
2448 return tabular->getLabelList();
2452 bool InsetTabular::copySelection(BufferView * bv)
2454 if (!hasSelection())
2457 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2458 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2459 if (sel_col_start > sel_col_end) {
2460 sel_col_start = sel_col_end;
2461 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2463 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2465 int const columns = sel_col_end - sel_col_start + 1;
2467 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2468 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2469 if (sel_row_start > sel_row_end) {
2470 swap(sel_row_start, sel_row_end);
2472 int const rows = sel_row_end - sel_row_start + 1;
2474 delete paste_tabular;
2475 paste_tabular = new LyXTabular(bv->buffer()->params,
2476 this, *tabular); // rows, columns);
2477 for (int i = 0; i < sel_row_start; ++i)
2478 paste_tabular->DeleteRow(0);
2479 while (paste_tabular->rows() > rows)
2480 paste_tabular->DeleteRow(rows);
2481 paste_tabular->SetTopLine(0, true, true);
2482 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2484 for (int i = 0; i < sel_col_start; ++i)
2485 paste_tabular->DeleteColumn(0);
2486 while (paste_tabular->columns() > columns)
2487 paste_tabular->DeleteColumn(columns);
2488 paste_tabular->SetLeftLine(0, true, true);
2489 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2493 paste_tabular->ascii(bv->buffer(), sstr,
2494 (int)parOwner()->params().depth(), true, '\t');
2495 bv->stuffClipboard(sstr.str().c_str());
2500 bool InsetTabular::pasteSelection(BufferView * bv)
2505 for (int r1 = 0, r2 = actrow;
2506 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2508 for(int c1 = 0, c2 = actcol;
2509 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2511 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2512 tabular->IsPartOfMultiColumn(r2,c2))
2514 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2518 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2522 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2523 int const n2 = tabular->GetCellNumber(r2, c2);
2524 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2525 tabular->GetCellInset(n2)->setOwner(this);
2526 tabular->GetCellInset(n2)->deleteLyXText(bv);
2533 bool InsetTabular::cutSelection()
2535 if (!hasSelection())
2538 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2539 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2540 if (sel_col_start > sel_col_end) {
2541 sel_col_start = sel_col_end;
2542 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2544 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2546 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2547 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2548 if (sel_row_start > sel_row_end) {
2549 swap(sel_row_start, sel_row_end);
2551 if (sel_cell_start > sel_cell_end) {
2552 swap(sel_cell_start, sel_cell_end);
2554 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2555 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2556 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2563 bool InsetTabular::isRightToLeft(BufferView * bv)
2565 return bv->getParentLanguage(this)->RightToLeft();
2569 bool InsetTabular::nodraw() const
2571 if (!UpdatableInset::nodraw() && the_locking_inset)
2572 return the_locking_inset->nodraw();
2573 return UpdatableInset::nodraw();
2577 int InsetTabular::scroll(bool recursive) const
2579 int sx = UpdatableInset::scroll(false);
2581 if (recursive && the_locking_inset)
2582 sx += the_locking_inset->scroll(recursive);
2588 bool InsetTabular::doClearArea() const
2590 return !locked || (need_update & (FULL|INIT));
2594 void InsetTabular::getSelection(int & srow, int & erow,
2595 int & scol, int & ecol) const
2597 int const start = hasSelection() ? sel_cell_start : actcell;
2598 int const end = hasSelection() ? sel_cell_end : actcell;
2600 srow = tabular->row_of_cell(start);
2601 erow = tabular->row_of_cell(end);
2606 scol = tabular->column_of_cell(start);
2607 ecol = tabular->column_of_cell(end);
2611 ecol = tabular->right_column_of_cell(end);
2616 Paragraph * InsetTabular::getParFromID(int id) const
2619 for(int i = 0; i < tabular->rows(); ++i) {
2620 for(int j = 0; j < tabular->columns(); ++j) {
2621 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2629 Paragraph * InsetTabular::firstParagraph() const
2631 if (the_locking_inset)
2632 return the_locking_inset->firstParagraph();
2637 Paragraph * InsetTabular::getFirstParagraph(int i) const
2639 return (i < tabular->GetNumberOfCells())
2640 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2645 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2647 if (the_locking_inset)
2648 return the_locking_inset->cursor(bv);
2649 return Inset::cursor(bv);
2653 Inset * InsetTabular::getInsetFromID(int id_arg) const
2656 return const_cast<InsetTabular *>(this);
2659 for(int i = 0; i < tabular->rows(); ++i) {
2660 for(int j = 0; j < tabular->columns(); ++j) {
2661 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2670 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2673 if (the_locking_inset) {
2674 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2679 if (tabular->IsLastCell(actcell)) {
2680 bv->unlockInset(const_cast<InsetTabular *>(this));
2686 // otherwise we have to lock the next inset and ask for it's selecttion
2687 UpdatableInset * inset =
2688 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2689 inset->edit(bv, 0, 0, mouse_button::none);
2690 string const str(selectNextWordInt(bv, value));
2698 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2700 // when entering this function the inset should be ALWAYS locked!
2701 lyx::Assert(the_locking_inset);
2703 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2707 if (tabular->IsLastCell(actcell)) {
2708 bv->unlockInset(const_cast<InsetTabular *>(this));
2712 // otherwise we have to lock the next inset and ask for it's selecttion
2713 UpdatableInset * inset =
2714 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2716 return selectNextWordInt(bv, value);
2720 void InsetTabular::selectSelectedWord(BufferView * bv)
2722 if (the_locking_inset) {
2723 the_locking_inset->selectSelectedWord(bv);
2730 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2732 if (the_locking_inset) {
2733 the_locking_inset->toggleSelection(bv, kill_selection);
2738 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2742 if (the_locking_inset) {
2743 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2745 updateLocal(bv, CELL, false);
2748 if (tabular->IsLastCell(actcell)) {
2750 bv->unlockInset(const_cast<InsetTabular *>(this));
2755 // otherwise we have to lock the next inset and search there
2756 UpdatableInset * inset =
2757 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2759 bool const ret = searchForward(bv, str, cs, mw);
2761 updateLocal(bv, CELL, false);
2766 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2770 if (the_locking_inset) {
2771 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2773 updateLocal(bv, CELL, false);
2776 if (!actcell) { // we are already in the first cell
2778 bv->unlockInset(const_cast<InsetTabular *>(this));
2783 // otherwise we have to lock the next inset and search there
2784 UpdatableInset * inset =
2785 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2786 inset->edit(bv, false);
2787 bool const ret = searchBackward(bv, str, cs, mw);
2789 updateLocal(bv, CELL, false);
2794 bool InsetTabular::insetAllowed(Inset::Code code) const
2796 if (the_locking_inset)
2797 return the_locking_inset->insetAllowed(code);
2798 // we return true here because if the inset is not locked someone
2799 // wants to insert something in one of our insettexts and we generally
2805 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2807 const int cell = tabular->GetCellFromInset(in, actcell);
2810 return tabular->GetPWidth(cell).zero();
2812 // well we didn't obviously find it so maybe our owner knows more
2814 return owner()->forceDefaultParagraphs(in);
2815 // if we're here there is really something strange going on!!!
2819 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2822 if (buf.length() <= 0)
2828 string::size_type len = buf.length();
2829 string::size_type p = 0;
2832 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2841 maxCols = max(cols, maxCols);
2847 maxCols = max(cols, maxCols);
2848 LyXTabular * loctab;
2853 delete paste_tabular;
2854 paste_tabular = new LyXTabular(bv->buffer()->params,
2855 this, rows, maxCols);
2856 loctab = paste_tabular;
2859 loctab = tabular.get();
2864 string::size_type op = 0;
2865 int cells = loctab->GetNumberOfCells();
2868 rows = loctab->rows();
2869 int const columns = loctab->columns();
2870 while ((cell < cells) && (p < len) && (row < rows) &&
2871 (p = buf.find_first_of("\t\n", p)) != string::npos)
2877 // we can only set this if we are not too far right
2878 if (cols < columns) {
2879 InsetText * ti = loctab->GetCellInset(cell);
2880 LyXFont const font = ti->getLyXText(bv)->
2881 getFont(bv->buffer(), ti->paragraph(), 0);
2882 ti->setText(buf.substr(op, p-op), font);
2888 // we can only set this if we are not too far right
2889 if (cols < columns) {
2890 InsetText * ti = loctab->GetCellInset(cell);
2891 LyXFont const font = ti->getLyXText(bv)->
2892 getFont(bv->buffer(), ti->paragraph(), 0);
2893 ti->setText(buf.substr(op, p-op), font);
2898 cell = loctab->GetCellNumber(row, cols);
2904 // check for the last cell if there is no trailing '\n'
2905 if ((cell < cells) && (op < len)) {
2906 InsetText * ti = loctab->GetCellInset(cell);
2907 LyXFont const font = ti->getLyXText(bv)->
2908 getFont(bv->buffer(), ti->paragraph(), 0);
2909 ti->setText(buf.substr(op, len-op), font);