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;
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;
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;
589 if (isRightToLeft(bv))
590 actcell = tabular->GetLastCellInRow(0);
594 if (isRightToLeft(bv))
595 actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
597 actcell = tabular->GetNumberOfCells() - 1;
605 void InsetTabular::insetUnlock(BufferView * bv)
607 if (the_locking_inset) {
608 the_locking_inset->insetUnlock(bv);
609 updateLocal(bv, CELL, false);
610 the_locking_inset = 0;
616 if (scroll(false) || hasSelection()) {
621 updateLocal(bv, FULL, false);
626 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
627 bool mark_dirty) const
631 calculate_dimensions_of_cells(bv, font, true);
633 if (!locked && what == CELL)
635 if (need_update < what) // only set this if it has greater update
638 if (need_update != NONE) {
639 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
646 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
648 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
653 if (inset == tabular->GetCellInset(actcell)) {
654 lyxerr[Debug::INSETTEXT] << "OK" << endl;
655 the_locking_inset = tabular->GetCellInset(actcell);
658 } else if (!the_locking_inset) {
659 int const n = tabular->GetNumberOfCells();
660 int const id = inset->id();
661 for (int i = 0; i < n; ++i) {
662 InsetText * in = tabular->GetCellInset(i);
665 the_locking_inset = in;
670 if (in->getInsetFromID(id)) {
673 return the_locking_inset->lockInsetInInset(bv, inset);
676 } else if (the_locking_inset && (the_locking_inset == inset)) {
677 lyxerr[Debug::INSETTEXT] << "OK" << endl;
679 } else if (the_locking_inset) {
680 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
681 return the_locking_inset->lockInsetInInset(bv, inset);
683 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
688 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
691 if (!the_locking_inset)
693 if (the_locking_inset == inset) {
694 the_locking_inset->insetUnlock(bv);
696 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
702 updateLocal(bv, CELL, false);
703 // this has to be here otherwise we don't redraw the cell!
704 the_locking_inset = 0;
705 // showInsetCursor(bv, false);
708 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
709 if (inset->lyxCode() == TABULAR_CODE &&
710 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
711 bv->owner()->getDialogs()->updateTabular(this);
720 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
722 Inset * tl_inset = inset;
723 // look if this inset is really inside myself!
724 while(tl_inset->owner() && tl_inset->owner() != this)
725 tl_inset = tl_inset->owner();
726 // if we enter here it's not ower inset
727 if (!tl_inset->owner())
729 // we only have to do this if this is a subinset of our cells
730 if (tl_inset != inset) {
731 if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
734 updateLocal(bv, CELL, false);
739 int InsetTabular::insetInInsetY() const
741 if (!the_locking_inset)
743 return inset_y + the_locking_inset->insetInInsetY();
747 UpdatableInset * InsetTabular::getLockingInset() const
749 return the_locking_inset ? the_locking_inset->getLockingInset() :
750 const_cast<InsetTabular *>(this);
754 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
758 if (the_locking_inset)
759 return the_locking_inset->getFirstLockingInsetOfType(c);
764 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
766 if (the_locking_inset)
767 return the_locking_inset->insertInset(bv, inset);
772 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button::state button)
774 if (hasSelection() && (button == mouse_button::button3))
777 if (hasSelection()) {
779 updateLocal(bv, SELECTION, false);
782 int const ocell = actcell;
783 int const orow = actrow;
788 the_locking_inset = 0;
794 updateLocal(bv, NONE, false);
798 if ((ocell != actcell) && the_locking_inset) {
799 the_locking_inset->insetUnlock(bv);
800 updateLocal(bv, CELL, false);
801 the_locking_inset = 0;
808 bool const inset_hit = insetHit(bv, x, y);
810 if ((ocell == actcell) && the_locking_inset && inset_hit) {
812 the_locking_inset->insetButtonPress(bv,
813 x - inset_x, y - inset_y,
816 } else if (the_locking_inset) {
817 the_locking_inset->insetUnlock(bv);
818 updateLocal(bv, CELL, false);
819 the_locking_inset = 0;
821 if (button == mouse_button::button2) {
822 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
825 if (inset_hit && bv->theLockingInset()) {
826 if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
827 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
830 the_locking_inset->insetButtonPress(
831 bv, x - inset_x, y - inset_y, button);
838 bool InsetTabular::insetButtonRelease(BufferView * bv,
839 int x, int y, mouse_button::state button)
842 if (the_locking_inset)
843 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
844 y - inset_y, button);
845 if (button == mouse_button::button3 && !ret) {
846 bv->owner()->getDialogs()->showTabular(this);
853 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state button)
855 if (the_locking_inset) {
856 the_locking_inset->insetMotionNotify(bv,
864 // int const old_cell = actcell;
867 if (!hasSelection()) {
868 setSelection(actcell, actcell);
870 setSelection(sel_cell_start, actcell);
872 updateLocal(bv, SELECTION, false);
877 UpdatableInset::RESULT
878 InsetTabular::localDispatch(BufferView * bv, kb_action action,
881 // We need to save the value of the_locking_inset as the call to
882 // the_locking_inset->LocalDispatch might unlock it.
883 old_locking_inset = the_locking_inset;
884 UpdatableInset::RESULT result =
885 UpdatableInset::localDispatch(bv, action, arg);
886 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
891 if ((action < 0) && arg.empty())
894 bool hs = hasSelection();
897 // this one have priority over the locked InsetText, if we're not already
898 // inside another tabular then that one get's priority!
899 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
904 unlockInsetInInset(bv, the_locking_inset);
905 if (action == LFUN_TAB)
906 moveNextCell(bv, old_locking_inset != 0);
908 movePrevCell(bv, old_locking_inset != 0);
911 updateLocal(bv, SELECTION, false);
912 if (!the_locking_inset) {
914 return DISPATCHED_NOUPDATE;
917 // this to avoid compiler warnings.
923 if (the_locking_inset) {
924 result = the_locking_inset->localDispatch(bv, action, arg);
925 if (result == DISPATCHED_NOUPDATE) {
928 if (sc != scroll()) { // inset has been scrolled
929 the_locking_inset->toggleInsetCursor(bv);
930 updateLocal(bv, FULL, false);
931 the_locking_inset->toggleInsetCursor(bv);
934 } else if (result == DISPATCHED) {
935 the_locking_inset->toggleInsetCursor(bv);
936 updateLocal(bv, CELL, false);
937 the_locking_inset->toggleInsetCursor(bv);
939 } else if (result == FINISHED_UP) {
941 } else if (result == FINISHED_DOWN) {
943 } else if (result == FINISHED_RIGHT) {
951 // --- Cursor Movements ----------------------------------
952 case LFUN_RIGHTSEL: {
953 int const start = hasSelection() ? sel_cell_start : actcell;
954 if (tabular->IsLastCellInRow(actcell)) {
955 setSelection(start, actcell);
960 // if we are starting a selection, only select
961 // the current cell at the beginning
962 if (hasSelection()) {
963 moveRight(bv, false);
966 setSelection(start, end);
967 updateLocal(bv, SELECTION, false);
971 result = moveRight(bv);
974 updateLocal(bv, SELECTION, false);
977 int const start = hasSelection() ? sel_cell_start : actcell;
978 if (tabular->IsFirstCellInRow(actcell)) {
979 setSelection(start, actcell);
984 // if we are starting a selection, only select
985 // the current cell at the beginning
986 if (hasSelection()) {
990 setSelection(start, end);
991 updateLocal(bv, SELECTION, false);
995 result = moveLeft(bv);
998 updateLocal(bv, SELECTION, false);
1000 case LFUN_DOWNSEL: {
1001 int const start = hasSelection() ? sel_cell_start : actcell;
1002 int const ocell = actcell;
1003 // if we are starting a selection, only select
1004 // the current cell at the beginning
1005 if (hasSelection()) {
1006 moveDown(bv, false);
1007 if ((ocell == sel_cell_end) ||
1008 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1009 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1011 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1013 setSelection(start, start);
1015 updateLocal(bv, SELECTION, false);
1019 result = moveDown(bv, old_locking_inset != 0);
1022 updateLocal(bv, SELECTION, false);
1026 int const start = hasSelection() ? sel_cell_start : actcell;
1027 int const ocell = actcell;
1028 // if we are starting a selection, only select
1029 // the current cell at the beginning
1030 if (hasSelection()) {
1032 if ((ocell == sel_cell_end) ||
1033 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1034 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1036 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1038 setSelection(start, start);
1040 updateLocal(bv, SELECTION, false);
1044 result = moveUp(bv, old_locking_inset != 0);
1047 updateLocal(bv, SELECTION, false);
1050 UpdateCodes code = CURSOR;
1055 int column = actcol;
1056 unlockInsetInInset(bv, the_locking_inset);
1057 if (bv->text->first_y + bv->painter().paperHeight() <
1058 (top_baseline + tabular->GetHeightOfTabular()))
1060 bv->scrollDocView(bv->text->first_y + bv->painter().paperHeight());
1062 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1064 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1067 updateLocal(bv, code, false);
1071 UpdateCodes code = CURSOR;
1076 int column = actcol;
1077 unlockInsetInInset(bv, the_locking_inset);
1078 if (top_baseline < 0) {
1079 bv->scrollDocView(bv->text->first_y - bv->painter().paperHeight());
1081 if (top_baseline > 0)
1084 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1089 updateLocal(bv, code, false);
1092 // none of these make sense for insettabular,
1093 // but we must catch them to prevent any
1094 // selection from being confused
1098 case LFUN_WORDLEFTSEL:
1099 case LFUN_WORDRIGHT:
1100 case LFUN_WORDRIGHTSEL:
1101 case LFUN_DOWN_PARAGRAPH:
1102 case LFUN_DOWN_PARAGRAPHSEL:
1103 case LFUN_UP_PARAGRAPH:
1104 case LFUN_UP_PARAGRAPHSEL:
1105 case LFUN_BACKSPACE:
1111 case LFUN_BEGINNINGBUF:
1112 case LFUN_BEGINNINGBUFSEL:
1114 case LFUN_ENDBUFSEL:
1116 case LFUN_LAYOUT_TABULAR:
1117 bv->owner()->getDialogs()->showTabular(this);
1119 case LFUN_TABULAR_FEATURE:
1120 if (!tabularFeatures(bv, arg))
1121 result = UNDISPATCHED;
1123 // insert file functions
1124 case LFUN_FILE_INSERT_ASCII_PARA:
1125 case LFUN_FILE_INSERT_ASCII:
1127 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1130 if (insertAsciiString(bv, tmpstr, false))
1131 updateLocal(bv, INIT, true);
1133 result = UNDISPATCHED;
1136 // cut and paste functions
1138 if (!copySelection(bv))
1140 setUndo(bv, Undo::DELETE,
1141 bv->text->cursor.par(),
1142 bv->text->cursor.par()->next());
1144 updateLocal(bv, INIT, true);
1147 if (!hasSelection())
1152 case LFUN_PASTESELECTION:
1154 string const clip(bv->getClipboard());
1158 if (clip.find('\t') != string::npos) {
1162 string::size_type len = clip.length();
1163 string::size_type p = 0;
1166 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1174 maxCols = max(cols, maxCols);
1180 maxCols = max(cols, maxCols);
1181 delete paste_tabular;
1182 paste_tabular = new LyXTabular(bv->buffer()->params,
1183 this, rows, maxCols);
1184 string::size_type op = 0;
1186 int cells = paste_tabular->GetNumberOfCells();
1188 while ((cell < cells) && (p < len) &&
1189 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1194 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1199 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1200 while (cols++ < maxCols)
1208 // check for the last cell if there is no trailing '\n'
1209 if ((cell < cells) && (op < len))
1210 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1213 if (!insertAsciiString(bv, clip, true))
1216 // so that the clipboard is used and it goes on
1218 // and executes LFUN_PASTESELECTION in insettext!
1219 delete paste_tabular;
1224 if (hasPasteBuffer()) {
1225 setUndo(bv, Undo::INSERT,
1226 bv->text->cursor.par(),
1227 bv->text->cursor.par()->next());
1229 updateLocal(bv, INIT, true);
1232 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1234 // handle font changing stuff on selection before we lock the inset
1235 // in the default part!
1236 result = UNDISPATCHED;
1247 case LFUN_UNDERLINE:
1248 case LFUN_FONT_SIZE:
1249 if (bv->Dispatch(action, arg))
1250 result = DISPATCHED;
1256 // we try to activate the actual inset and put this event down to
1257 // the insets dispatch function.
1258 if ((result == DISPATCHED) || the_locking_inset)
1261 if (activateCellInset(bv)) {
1262 // reset need_update setted in above function!
1264 result = the_locking_inset->localDispatch(bv, action, arg);
1265 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1266 unlockInsetInInset(bv, the_locking_inset);
1268 // we need to update if this was requested before
1269 updateLocal(bv, NONE, false);
1270 return UNDISPATCHED;
1273 // so the below CELL is not set because this is higher
1274 // priority and we get a full redraw
1275 need_update = SELECTION;
1278 updateLocal(bv, CELL, false);
1283 if (result < FINISHED) {
1284 if (!the_locking_inset) {
1285 if (bv->fitCursor())
1286 updateLocal(bv, FULL, false);
1288 showInsetCursor(bv);
1291 bv->unlockInset(this);
1296 int InsetTabular::latex(Buffer const * buf, ostream & os,
1297 bool fragile, bool fp) const
1299 return tabular->latex(buf, os, fragile, fp);
1303 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1306 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1308 return tabular->ascii(buf, os, 0, false,0);
1312 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1315 int const ret = tabular->ascii(buf,os,
1316 (int)parOwner()->params().depth(),
1323 int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1328 // if the table is inside a float it doesn't need the informaltable
1329 // wrapper. Search for it.
1330 for(master = owner();
1331 master && master->lyxCode() != Inset::FLOAT_CODE;
1332 master = master->owner());
1335 os << "<informaltable>";
1340 ret+= tabular->docbook(buf, os, mixcont);
1342 os << "</informaltable>";
1351 void InsetTabular::validate(LaTeXFeatures & features) const
1353 tabular->Validate(features);
1357 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1358 LyXFont const & font,
1365 bool changed = false;
1367 // if we have a locking_inset we should have to check only this cell for
1368 // change so I'll try this to have a boost, but who knows ;)
1369 if ((need_update != INIT) &&
1370 (the_locking_inset == tabular->GetCellInset(actcell))) {
1371 for(int i = 0; i < tabular->columns(); ++i) {
1372 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1374 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1377 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1378 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1379 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1382 for (int i = 0; i < tabular->rows(); ++i) {
1385 for (int j = 0; j < tabular->columns(); ++j) {
1386 if (tabular->IsPartOfMultiColumn(i,j))
1389 inset = tabular->GetCellInset(cell);
1390 if (!reinit && !tabular->GetPWidth(cell).zero())
1391 inset->update(bv, font, false);
1392 maxAsc = max(maxAsc, inset->ascent(bv, font));
1393 maxDesc = max(maxDesc, inset->descent(bv, font));
1394 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1396 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1397 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1405 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1407 if (the_locking_inset) {
1408 the_locking_inset->getCursorPos(bv, x, y);
1411 x = cursor_.x() - top_x;
1416 void InsetTabular::toggleInsetCursor(BufferView * bv)
1419 if (isCursorVisible())
1420 bv->hideLockedInsetCursor();
1423 if (the_locking_inset) {
1424 the_locking_inset->toggleInsetCursor(bv);
1428 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1430 int const asc = font_metrics::maxAscent(font);
1431 int const desc = font_metrics::maxDescent(font);
1433 if (isCursorVisible())
1434 bv->hideLockedInsetCursor();
1436 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1437 toggleCursorVisible();
1441 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1445 if (!isCursorVisible()) {
1446 LyXFont font; // = GetFont(par, cursor.pos);
1448 int const asc = font_metrics::maxAscent(font);
1449 int const desc = font_metrics::maxDescent(font);
1450 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1452 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1453 setCursorVisible(true);
1458 void InsetTabular::hideInsetCursor(BufferView * bv)
1460 if (isCursorVisible()) {
1461 bv->hideLockedInsetCursor();
1462 setCursorVisible(false);
1467 void InsetTabular::fitInsetCursor(BufferView * bv) const
1469 if (the_locking_inset) {
1470 int old_first_y = bv->text->first_y;
1471 the_locking_inset->fitInsetCursor(bv);
1472 if (old_first_y != bv->text->first_y)
1478 int const asc = font_metrics::maxAscent(font);
1479 int const desc = font_metrics::maxDescent(font);
1482 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1487 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1491 actcell = actrow = actcol = 0;
1492 int ly = tabular->GetDescentOfRow(actrow);
1494 // first search the right row
1495 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1496 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1497 tabular->GetAscentOfRow(actrow + 1) +
1498 tabular->GetAdditionalHeight(actrow + 1));
1500 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1502 actcell = tabular->GetCellNumber(actrow, actcol);
1504 // now search the right column
1505 int lx = tabular->GetWidthOfColumn(actcell) -
1506 tabular->GetAdditionalWidth(actcell);
1507 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1508 lx += tabular->GetWidthOfColumn(actcell + 1)
1509 + tabular->GetAdditionalWidth(actcell);
1511 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1516 int InsetTabular::getCellXPos(int cell) const
1520 for (; !tabular->IsFirstCellInRow(c); --c)
1522 int lx = tabular->GetWidthOfColumn(cell);
1523 for (; c < cell; ++c) {
1524 lx += tabular->GetWidthOfColumn(c);
1526 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1530 void InsetTabular::resetPos(BufferView * bv) const
1532 #ifdef WITH_WARNINGS
1533 #warning This should be fixed in the right manner (20011128 Jug)
1535 // fast hack to fix infinite repaintings!
1536 if (in_reset_pos > 10)
1540 actcol = tabular->column_of_cell(actcell);
1543 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1544 if (tabular->IsLastCellInRow(cell)) {
1545 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1546 tabular->GetAscentOfRow(actrow + 1) +
1547 tabular->GetAdditionalHeight(actrow + 1));
1551 if (!locked || nodraw()) {
1552 if (the_locking_inset)
1553 inset_y = cursor_.y();
1556 // we need this only from here on!!!
1558 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1559 int new_x = getCellXPos(actcell);
1560 int old_x = cursor_.x();
1563 // cursor.x(getCellXPos(actcell) + offset);
1564 if ((actcol < tabular->columns()-1) && scroll(false) &&
1565 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1568 updateLocal(bv, FULL, false);
1569 } else if (the_locking_inset &&
1570 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1572 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1573 if (xx > (bv->workWidth()-20)) {
1574 scroll(bv, -(xx - bv->workWidth() + 60));
1575 updateLocal(bv, FULL, false);
1576 } else if (xx < 20) {
1582 updateLocal(bv, FULL, false);
1584 } else if ((cursor_.x() - offset) > 20 &&
1585 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1586 > (bv->workWidth() - 20)) {
1587 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1588 updateLocal(bv, FULL, false);
1589 } else if ((cursor_.x() - offset) < 20) {
1590 scroll(bv, 20 - cursor_.x() + offset);
1591 updateLocal(bv, FULL, false);
1592 } else if (scroll(false) && top_x > 20 &&
1593 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1594 scroll(bv, old_x - cursor_.x());
1595 updateLocal(bv, FULL, false);
1597 if (the_locking_inset) {
1598 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1599 inset_y = cursor_.y();
1601 if ((!the_locking_inset ||
1602 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1603 actcell != oldcell) {
1604 InsetTabular * inset = const_cast<InsetTabular *>(this);
1605 bv->owner()->getDialogs()->updateTabular(inset);
1612 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1614 if (lock && !old_locking_inset) {
1615 if (activateCellInset(bv))
1618 bool moved = isRightToLeft(bv)
1619 ? movePrevCell(bv) : moveNextCell(bv);
1621 return FINISHED_RIGHT;
1622 if (lock && activateCellInset(bv))
1626 return DISPATCHED_NOUPDATE;
1630 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1632 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1635 if (lock) { // behind the inset
1636 if (activateCellInset(bv, 0, 0, mouse_button::none, true))
1640 return DISPATCHED_NOUPDATE;
1644 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1646 int const ocell = actcell;
1647 actcell = tabular->GetCellAbove(actcell);
1648 if (actcell == ocell) // we moved out of the inset
1654 if (old_locking_inset) {
1655 old_locking_inset->getCursorPos(bv, x, y);
1656 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1658 if (activateCellInset(bv, x, 0))
1661 return DISPATCHED_NOUPDATE;
1665 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1667 int const ocell = actcell;
1668 actcell = tabular->GetCellBelow(actcell);
1669 if (actcell == ocell) // we moved out of the inset
1670 return FINISHED_DOWN;
1675 if (old_locking_inset) {
1676 old_locking_inset->getCursorPos(bv, x, y);
1677 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1679 if (activateCellInset(bv, x, 0))
1682 return DISPATCHED_NOUPDATE;
1686 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1688 if (isRightToLeft(bv)) {
1689 if (tabular->IsFirstCellInRow(actcell)) {
1690 int row = tabular->row_of_cell(actcell);
1691 if (row == tabular->rows() - 1)
1693 actcell = tabular->GetLastCellInRow(row);
1694 actcell = tabular->GetCellBelow(actcell);
1701 if (tabular->IsLastCell(actcell))
1706 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1707 isRightToLeftPar(bv->buffer()->params);
1708 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1715 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1717 if (isRightToLeft(bv)) {
1718 if (tabular->IsLastCellInRow(actcell)) {
1719 int row = tabular->row_of_cell(actcell);
1722 actcell = tabular->GetFirstCellInRow(row);
1723 actcell = tabular->GetCellAbove(actcell);
1725 if (tabular->IsLastCell(actcell))
1730 if (!actcell) // first cell
1735 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1736 isRightToLeftPar(bv->buffer()->params);
1737 activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
1744 bool InsetTabular::deletable() const
1750 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1754 setSelection(0, tabular->GetNumberOfCells() - 1);
1756 if (hasSelection()) {
1757 setUndo(bv, Undo::EDIT,
1758 bv->text->cursor.par(),
1759 bv->text->cursor.par()->next());
1760 bool const frozen = undo_frozen;
1763 // apply the fontchange on the whole selection
1768 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1769 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1770 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1771 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1778 updateLocal(bv, INIT, true);
1780 if (the_locking_inset)
1781 the_locking_inset->setFont(bv, font, tall);
1785 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1787 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1790 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1791 string const tmp = tabularFeature[i].feature;
1793 if (tmp == what.substr(0, tmp.length())) {
1794 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1795 //tabularFeatures[i].feature.length())) {
1796 action = tabularFeature[i].action;
1800 if (action == LyXTabular::LAST_ACTION)
1804 frontStrip(what.substr(tabularFeature[i].feature.length()));
1805 tabularFeatures(bv, action, val);
1809 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1810 string const & special, bool & flag)
1812 if (special == "dl_above") {
1815 } else if (special == "dl_below") {
1816 ltt.bottomDL = flag;
1818 } else if (special == "empty") {
1828 void InsetTabular::tabularFeatures(BufferView * bv,
1829 LyXTabular::Feature feature,
1830 string const & value)
1836 bool setLines = false;
1837 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1838 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1841 case LyXTabular::M_ALIGN_LEFT:
1842 case LyXTabular::ALIGN_LEFT:
1843 setAlign = LYX_ALIGN_LEFT;
1845 case LyXTabular::M_ALIGN_RIGHT:
1846 case LyXTabular::ALIGN_RIGHT:
1847 setAlign = LYX_ALIGN_RIGHT;
1849 case LyXTabular::M_ALIGN_CENTER:
1850 case LyXTabular::ALIGN_CENTER:
1851 setAlign = LYX_ALIGN_CENTER;
1853 case LyXTabular::M_VALIGN_TOP:
1854 case LyXTabular::VALIGN_TOP:
1855 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1857 case LyXTabular::M_VALIGN_BOTTOM:
1858 case LyXTabular::VALIGN_BOTTOM:
1859 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1861 case LyXTabular::M_VALIGN_CENTER:
1862 case LyXTabular::VALIGN_CENTER:
1863 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1868 if (hasSelection()) {
1869 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1871 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1872 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1874 setUndo(bv, Undo::FINISH,
1875 bv->text->cursor.par(),
1876 bv->text->cursor.par()->next());
1878 int row = tabular->row_of_cell(actcell);
1879 int column = tabular->column_of_cell(actcell);
1881 LyXTabular::ltType ltt;
1884 case LyXTabular::SET_PWIDTH:
1886 LyXLength const vallen(value);
1887 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1889 bool const update = (tmplen != vallen);
1890 tabular->SetColumnPWidth(actcell, vallen);
1893 for (int i = 0; i < tabular->rows(); ++i) {
1894 cell = tabular->GetCellNumber(i,column);
1895 tabular->GetCellInset(cell)->resizeLyXText(bv);
1897 updateLocal(bv, INIT, true);
1901 case LyXTabular::SET_MPWIDTH:
1903 LyXLength const vallen(value);
1904 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1906 bool const update = (tmplen != vallen);
1907 tabular->SetMColumnPWidth(actcell, vallen);
1909 for (int i = 0; i < tabular->rows(); ++i) {
1910 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1913 updateLocal(bv, INIT, true);
1917 case LyXTabular::SET_SPECIAL_COLUMN:
1918 case LyXTabular::SET_SPECIAL_MULTI:
1919 tabular->SetAlignSpecial(actcell,value,feature);
1920 updateLocal(bv, FULL, true);
1922 case LyXTabular::APPEND_ROW:
1923 // append the row into the tabular
1924 unlockInsetInInset(bv, the_locking_inset);
1925 tabular->AppendRow(bv->buffer()->params, actcell);
1926 updateLocal(bv, INIT, true);
1928 case LyXTabular::APPEND_COLUMN:
1929 // append the column into the tabular
1930 unlockInsetInInset(bv, the_locking_inset);
1931 tabular->AppendColumn(bv->buffer()->params, actcell);
1932 actcell = tabular->GetCellNumber(row, column);
1933 updateLocal(bv, INIT, true);
1935 case LyXTabular::DELETE_ROW:
1936 unlockInsetInInset(bv, the_locking_inset);
1937 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1938 tabular->DeleteRow(sel_row_start);
1940 if (sel_row_start >= tabular->rows())
1942 actcell = tabular->GetCellNumber(sel_row_start, column);
1944 updateLocal(bv, INIT, true);
1946 case LyXTabular::DELETE_COLUMN:
1947 unlockInsetInInset(bv, the_locking_inset);
1948 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1949 tabular->DeleteColumn(sel_col_start);
1951 if (sel_col_start >= tabular->columns())
1953 actcell = tabular->GetCellNumber(row, sel_col_start);
1955 updateLocal(bv, INIT, true);
1957 case LyXTabular::M_TOGGLE_LINE_TOP:
1959 case LyXTabular::TOGGLE_LINE_TOP:
1961 bool lineSet = !tabular->TopLine(actcell, flag);
1962 for (int i = sel_row_start; i <= sel_row_end; ++i)
1963 for (int j = sel_col_start; j <= sel_col_end; ++j)
1964 tabular->SetTopLine(
1965 tabular->GetCellNumber(i, j),
1967 updateLocal(bv, INIT, true);
1971 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1973 case LyXTabular::TOGGLE_LINE_BOTTOM:
1975 bool lineSet = !tabular->BottomLine(actcell, flag);
1976 for (int i = sel_row_start; i <= sel_row_end; ++i)
1977 for (int j = sel_col_start; j <= sel_col_end; ++j)
1978 tabular->SetBottomLine(
1979 tabular->GetCellNumber(i, j),
1982 updateLocal(bv, INIT, true);
1986 case LyXTabular::M_TOGGLE_LINE_LEFT:
1988 case LyXTabular::TOGGLE_LINE_LEFT:
1990 bool lineSet = !tabular->LeftLine(actcell, flag);
1991 for (int i = sel_row_start; i <= sel_row_end; ++i)
1992 for (int j = sel_col_start; j <= sel_col_end; ++j)
1993 tabular->SetLeftLine(
1994 tabular->GetCellNumber(i,j),
1997 updateLocal(bv, INIT, true);
2001 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2003 case LyXTabular::TOGGLE_LINE_RIGHT:
2005 bool lineSet = !tabular->RightLine(actcell, flag);
2006 for (int i = sel_row_start; i <= sel_row_end; ++i)
2007 for (int j = sel_col_start; j <= sel_col_end; ++j)
2008 tabular->SetRightLine(
2009 tabular->GetCellNumber(i,j),
2012 updateLocal(bv, INIT, true);
2016 case LyXTabular::M_ALIGN_LEFT:
2017 case LyXTabular::M_ALIGN_RIGHT:
2018 case LyXTabular::M_ALIGN_CENTER:
2020 case LyXTabular::ALIGN_LEFT:
2021 case LyXTabular::ALIGN_RIGHT:
2022 case LyXTabular::ALIGN_CENTER:
2023 for (int i = sel_row_start; i <= sel_row_end; ++i)
2024 for (int j = sel_col_start; j <= sel_col_end; ++j)
2025 tabular->SetAlignment(
2026 tabular->GetCellNumber(i, j),
2029 updateLocal(bv, INIT, true);
2031 case LyXTabular::M_VALIGN_TOP:
2032 case LyXTabular::M_VALIGN_BOTTOM:
2033 case LyXTabular::M_VALIGN_CENTER:
2035 case LyXTabular::VALIGN_TOP:
2036 case LyXTabular::VALIGN_BOTTOM:
2037 case LyXTabular::VALIGN_CENTER:
2038 for (int i = sel_row_start; i <= sel_row_end; ++i)
2039 for (int j = sel_col_start; j <= sel_col_end; ++j)
2040 tabular->SetVAlignment(
2041 tabular->GetCellNumber(i, j),
2043 updateLocal(bv, INIT, true);
2045 case LyXTabular::MULTICOLUMN:
2047 if (sel_row_start != sel_row_end) {
2048 Alert::alert(_("Impossible Operation!"),
2049 _("Multicolumns can only be horizontally."),
2053 // just multicol for one Single Cell
2054 if (!hasSelection()) {
2055 // check wether we are completly in a multicol
2056 if (tabular->IsMultiColumn(actcell)) {
2057 tabular->UnsetMultiColumn(actcell);
2058 updateLocal(bv, INIT, true);
2060 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2061 updateLocal(bv, CELL, true);
2065 // we have a selection so this means we just add all this
2066 // cells to form a multicolumn cell
2070 if (sel_cell_start > sel_cell_end) {
2071 s_start = sel_cell_end;
2072 s_end = sel_cell_start;
2074 s_start = sel_cell_start;
2075 s_end = sel_cell_end;
2077 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2080 updateLocal(bv, INIT, true);
2083 case LyXTabular::SET_ALL_LINES:
2085 case LyXTabular::UNSET_ALL_LINES:
2086 for (int i = sel_row_start; i <= sel_row_end; ++i)
2087 for (int j = sel_col_start; j <= sel_col_end; ++j)
2088 tabular->SetAllLines(
2089 tabular->GetCellNumber(i,j), setLines);
2090 updateLocal(bv, INIT, true);
2092 case LyXTabular::SET_LONGTABULAR:
2093 tabular->SetLongTabular(true);
2094 updateLocal(bv, INIT, true); // because this toggles displayed
2096 case LyXTabular::UNSET_LONGTABULAR:
2097 tabular->SetLongTabular(false);
2098 updateLocal(bv, INIT, true); // because this toggles displayed
2100 case LyXTabular::SET_ROTATE_TABULAR:
2101 tabular->SetRotateTabular(true);
2103 case LyXTabular::UNSET_ROTATE_TABULAR:
2104 tabular->SetRotateTabular(false);
2106 case LyXTabular::SET_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),
2113 case LyXTabular::UNSET_ROTATE_CELL:
2114 for (int i = sel_row_start; i <= sel_row_end; ++i)
2115 for (int j = sel_col_start; j <= sel_col_end; ++j)
2116 tabular->SetRotateCell(
2117 tabular->GetCellNumber(i, j), false);
2119 case LyXTabular::SET_USEBOX:
2121 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2122 if (val == tabular->GetUsebox(actcell))
2123 val = LyXTabular::BOX_NONE;
2124 for (int i = sel_row_start; i <= sel_row_end; ++i)
2125 for (int j = sel_col_start; j <= sel_col_end; ++j)
2127 tabular->GetCellNumber(i, j), val);
2130 case LyXTabular::UNSET_LTFIRSTHEAD:
2132 case LyXTabular::SET_LTFIRSTHEAD:
2133 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2134 checkLongtableSpecial(ltt, value, flag);
2135 tabular->SetLTHead(row, flag, ltt, true);
2137 case LyXTabular::UNSET_LTHEAD:
2139 case LyXTabular::SET_LTHEAD:
2140 (void)tabular->GetRowOfLTHead(row, ltt);
2141 checkLongtableSpecial(ltt, value, flag);
2142 tabular->SetLTHead(row, flag, ltt, false);
2144 case LyXTabular::UNSET_LTFOOT:
2146 case LyXTabular::SET_LTFOOT:
2147 (void)tabular->GetRowOfLTFoot(row, ltt);
2148 checkLongtableSpecial(ltt, value, flag);
2149 tabular->SetLTFoot(row, flag, ltt, false);
2151 case LyXTabular::UNSET_LTLASTFOOT:
2153 case LyXTabular::SET_LTLASTFOOT:
2154 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2155 checkLongtableSpecial(ltt, value, flag);
2156 tabular->SetLTFoot(row, flag, ltt, true);
2158 case LyXTabular::SET_LTNEWPAGE:
2160 bool what = !tabular->GetLTNewPage(row);
2161 tabular->SetLTNewPage(row, what);
2164 // dummy stuff just to avoid warnings
2165 case LyXTabular::LAST_ACTION:
2171 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
2174 UpdatableInset * inset =
2175 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2176 LyXFont font(LyXFont::ALL_SANE);
2178 x = inset->x() + inset->width(bv, font);
2179 y = inset->descent(bv, font);
2181 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2182 //inset_y = cursor.y();
2183 inset->edit(bv, x, y, button);
2184 if (!the_locking_inset)
2186 updateLocal(bv, CELL, false);
2187 return (the_locking_inset != 0);
2191 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2192 mouse_button::state button)
2194 inset_x = cursor_.x()
2195 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2196 inset_y = cursor_.y();
2197 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2201 bool InsetTabular::insetHit(BufferView *, int x, int) const
2204 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2208 // This returns paperWidth() if the cell-width is unlimited or the width
2209 // in pixels if we have a pwidth for this cell.
2210 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2212 LyXLength const len = tabular->GetPWidth(cell);
2216 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2220 int InsetTabular::getMaxWidth(BufferView * bv,
2221 UpdatableInset const * inset) const
2223 int cell = tabular->GetCellFromInset(inset, actcell);
2226 lyxerr << "Own inset not found, shouldn't really happen!"
2231 int w = getMaxWidthOfCell(bv, cell);
2233 // because the inset then subtracts it's top_x and owner->x()
2234 w += (inset->x() - top_x);
2241 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2243 resizeLyXText(bv, recursive);
2247 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2250 for(int i = 0; i < tabular->rows(); ++i) {
2251 for(int j = 0; j < tabular->columns(); ++j) {
2252 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2260 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2261 bool const recursive) const
2263 if (the_locking_inset)
2264 return the_locking_inset->getLyXText(bv, recursive);
2266 // if we're locked lock the actual insettext and return it's LyXText!!!
2268 UpdatableInset * inset =
2269 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2270 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2271 return the_locking_inset->getLyXText(bv, recursive);
2274 return Inset::getLyXText(bv, recursive);
2278 bool InsetTabular::showInsetDialog(BufferView * bv) const
2280 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2281 bv->owner()->getDialogs()
2282 ->showTabular(const_cast<InsetTabular *>(this));
2287 void InsetTabular::openLayoutDialog(BufferView * bv) const
2289 if (the_locking_inset) {
2290 InsetTabular * i = static_cast<InsetTabular *>
2291 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2293 i->openLayoutDialog(bv);
2297 bv->owner()->getDialogs()->showTabular(
2298 const_cast<InsetTabular *>(this));
2303 // function returns an object as defined in func_status.h:
2304 // states OK, Unknown, Disabled, On, Off.
2306 FuncStatus InsetTabular::getStatus(string const & what) const
2308 int action = LyXTabular::LAST_ACTION;
2312 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2313 string const tmp = tabularFeature[i].feature;
2314 if (tmp == what.substr(0, tmp.length())) {
2315 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2316 // tabularFeatures[i].feature.length())) {
2317 action = tabularFeature[i].action;
2321 if (action == LyXTabular::LAST_ACTION) {
2323 return status.unknown(true);
2326 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2331 LyXTabular::ltType dummyltt;
2334 if (hasSelection()) {
2335 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2337 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2341 case LyXTabular::SET_PWIDTH:
2342 case LyXTabular::SET_MPWIDTH:
2343 case LyXTabular::SET_SPECIAL_COLUMN:
2344 case LyXTabular::SET_SPECIAL_MULTI:
2345 return status.disabled(true);
2347 case LyXTabular::APPEND_ROW:
2348 case LyXTabular::APPEND_COLUMN:
2349 case LyXTabular::DELETE_ROW:
2350 case LyXTabular::DELETE_COLUMN:
2351 case LyXTabular::SET_ALL_LINES:
2352 case LyXTabular::UNSET_ALL_LINES:
2353 return status.clear();
2355 case LyXTabular::MULTICOLUMN:
2356 status.setOnOff(tabular->IsMultiColumn(actcell));
2358 case LyXTabular::M_TOGGLE_LINE_TOP:
2360 case LyXTabular::TOGGLE_LINE_TOP:
2361 status.setOnOff(tabular->TopLine(actcell, flag));
2363 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2365 case LyXTabular::TOGGLE_LINE_BOTTOM:
2366 status.setOnOff(tabular->BottomLine(actcell, flag));
2368 case LyXTabular::M_TOGGLE_LINE_LEFT:
2370 case LyXTabular::TOGGLE_LINE_LEFT:
2371 status.setOnOff(tabular->LeftLine(actcell, flag));
2373 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2375 case LyXTabular::TOGGLE_LINE_RIGHT:
2376 status.setOnOff(tabular->RightLine(actcell, flag));
2378 case LyXTabular::M_ALIGN_LEFT:
2380 case LyXTabular::ALIGN_LEFT:
2381 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2383 case LyXTabular::M_ALIGN_RIGHT:
2385 case LyXTabular::ALIGN_RIGHT:
2386 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2388 case LyXTabular::M_ALIGN_CENTER:
2390 case LyXTabular::ALIGN_CENTER:
2391 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2393 case LyXTabular::M_VALIGN_TOP:
2395 case LyXTabular::VALIGN_TOP:
2396 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2398 case LyXTabular::M_VALIGN_BOTTOM:
2400 case LyXTabular::VALIGN_BOTTOM:
2401 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2403 case LyXTabular::M_VALIGN_CENTER:
2405 case LyXTabular::VALIGN_CENTER:
2406 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2408 case LyXTabular::SET_LONGTABULAR:
2409 status.setOnOff(tabular->IsLongTabular());
2411 case LyXTabular::UNSET_LONGTABULAR:
2412 status.setOnOff(!tabular->IsLongTabular());
2414 case LyXTabular::SET_ROTATE_TABULAR:
2415 status.setOnOff(tabular->GetRotateTabular());
2417 case LyXTabular::UNSET_ROTATE_TABULAR:
2418 status.setOnOff(!tabular->GetRotateTabular());
2420 case LyXTabular::SET_ROTATE_CELL:
2421 status.setOnOff(tabular->GetRotateCell(actcell));
2423 case LyXTabular::UNSET_ROTATE_CELL:
2424 status.setOnOff(!tabular->GetRotateCell(actcell));
2426 case LyXTabular::SET_USEBOX:
2427 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2429 case LyXTabular::SET_LTFIRSTHEAD:
2430 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2432 case LyXTabular::SET_LTHEAD:
2433 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2435 case LyXTabular::SET_LTFOOT:
2436 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2438 case LyXTabular::SET_LTLASTFOOT:
2439 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2441 case LyXTabular::SET_LTNEWPAGE:
2442 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2446 status.disabled(true);
2453 vector<string> const InsetTabular::getLabelList() const
2455 return tabular->getLabelList();
2459 bool InsetTabular::copySelection(BufferView * bv)
2461 if (!hasSelection())
2464 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2465 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2466 if (sel_col_start > sel_col_end) {
2467 sel_col_start = sel_col_end;
2468 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2470 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2472 int const columns = sel_col_end - sel_col_start + 1;
2474 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2475 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2476 if (sel_row_start > sel_row_end) {
2477 swap(sel_row_start, sel_row_end);
2479 int const rows = sel_row_end - sel_row_start + 1;
2481 delete paste_tabular;
2482 paste_tabular = new LyXTabular(bv->buffer()->params,
2483 this, *tabular); // rows, columns);
2484 for (int i = 0; i < sel_row_start; ++i)
2485 paste_tabular->DeleteRow(0);
2486 while (paste_tabular->rows() > rows)
2487 paste_tabular->DeleteRow(rows);
2488 paste_tabular->SetTopLine(0, true, true);
2489 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2491 for (int i = 0; i < sel_col_start; ++i)
2492 paste_tabular->DeleteColumn(0);
2493 while (paste_tabular->columns() > columns)
2494 paste_tabular->DeleteColumn(columns);
2495 paste_tabular->SetLeftLine(0, true, true);
2496 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2500 paste_tabular->ascii(bv->buffer(), sstr,
2501 (int)parOwner()->params().depth(), true, '\t');
2502 bv->stuffClipboard(sstr.str().c_str());
2507 bool InsetTabular::pasteSelection(BufferView * bv)
2512 for (int r1 = 0, r2 = actrow;
2513 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2515 for(int c1 = 0, c2 = actcol;
2516 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2518 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2519 tabular->IsPartOfMultiColumn(r2,c2))
2521 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2525 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2529 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2530 int const n2 = tabular->GetCellNumber(r2, c2);
2531 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2532 tabular->GetCellInset(n2)->setOwner(this);
2533 tabular->GetCellInset(n2)->deleteLyXText(bv);
2540 bool InsetTabular::cutSelection()
2542 if (!hasSelection())
2545 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2546 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2547 if (sel_col_start > sel_col_end) {
2548 sel_col_start = sel_col_end;
2549 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2551 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2553 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2554 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2555 if (sel_row_start > sel_row_end) {
2556 swap(sel_row_start, sel_row_end);
2558 if (sel_cell_start > sel_cell_end) {
2559 swap(sel_cell_start, sel_cell_end);
2561 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2562 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2563 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2570 bool InsetTabular::isRightToLeft(BufferView * bv)
2572 return bv->getParentLanguage(this)->RightToLeft();
2576 bool InsetTabular::nodraw() const
2578 if (!UpdatableInset::nodraw() && the_locking_inset)
2579 return the_locking_inset->nodraw();
2580 return UpdatableInset::nodraw();
2584 int InsetTabular::scroll(bool recursive) const
2586 int sx = UpdatableInset::scroll(false);
2588 if (recursive && the_locking_inset)
2589 sx += the_locking_inset->scroll(recursive);
2595 bool InsetTabular::doClearArea() const
2597 return !locked || (need_update & (FULL|INIT));
2601 void InsetTabular::getSelection(int & srow, int & erow,
2602 int & scol, int & ecol) const
2604 int const start = hasSelection() ? sel_cell_start : actcell;
2605 int const end = hasSelection() ? sel_cell_end : actcell;
2607 srow = tabular->row_of_cell(start);
2608 erow = tabular->row_of_cell(end);
2613 scol = tabular->column_of_cell(start);
2614 ecol = tabular->column_of_cell(end);
2618 ecol = tabular->right_column_of_cell(end);
2623 Paragraph * InsetTabular::getParFromID(int id) const
2626 for(int i = 0; i < tabular->rows(); ++i) {
2627 for(int j = 0; j < tabular->columns(); ++j) {
2628 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2636 Paragraph * InsetTabular::firstParagraph() const
2638 if (the_locking_inset)
2639 return the_locking_inset->firstParagraph();
2644 Paragraph * InsetTabular::getFirstParagraph(int i) const
2646 return (i < tabular->GetNumberOfCells())
2647 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2652 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2654 if (the_locking_inset)
2655 return the_locking_inset->cursor(bv);
2656 return Inset::cursor(bv);
2660 Inset * InsetTabular::getInsetFromID(int id_arg) const
2663 return const_cast<InsetTabular *>(this);
2666 for(int i = 0; i < tabular->rows(); ++i) {
2667 for(int j = 0; j < tabular->columns(); ++j) {
2668 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2677 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2680 if (the_locking_inset) {
2681 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2686 if (tabular->IsLastCell(actcell)) {
2687 bv->unlockInset(const_cast<InsetTabular *>(this));
2693 // otherwise we have to lock the next inset and ask for it's selecttion
2694 UpdatableInset * inset =
2695 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2696 inset->edit(bv, 0, 0, mouse_button::none);
2697 string const str(selectNextWordInt(bv, value));
2705 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2707 // when entering this function the inset should be ALWAYS locked!
2708 lyx::Assert(the_locking_inset);
2710 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2714 if (tabular->IsLastCell(actcell)) {
2715 bv->unlockInset(const_cast<InsetTabular *>(this));
2719 // otherwise we have to lock the next inset and ask for it's selecttion
2720 UpdatableInset * inset =
2721 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2723 return selectNextWordInt(bv, value);
2727 void InsetTabular::selectSelectedWord(BufferView * bv)
2729 if (the_locking_inset) {
2730 the_locking_inset->selectSelectedWord(bv);
2737 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2739 if (the_locking_inset) {
2740 the_locking_inset->toggleSelection(bv, kill_selection);
2745 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2748 if (the_locking_inset) {
2749 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2750 updateLocal(bv, CELL, false);
2755 InsetText * inset = tabular->GetCellInset(actcell);
2756 if (inset->searchForward(bv, str, cs, mw)) {
2757 updateLocal(bv, FULL, false);
2761 } while (!tabular->IsLastCell(actcell));
2766 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2769 if (the_locking_inset) {
2770 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2771 updateLocal(bv, CELL, false);
2776 actcell = tabular->GetNumberOfCells();
2780 InsetText * inset = tabular->GetCellInset(actcell);
2781 if (inset->searchBackward(bv, str, cs, mw)) {
2782 updateLocal(bv, CELL, false);
2790 bool InsetTabular::insetAllowed(Inset::Code code) const
2792 if (the_locking_inset)
2793 return the_locking_inset->insetAllowed(code);
2794 // we return true here because if the inset is not locked someone
2795 // wants to insert something in one of our insettexts and we generally
2801 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2803 const int cell = tabular->GetCellFromInset(in, actcell);
2806 return tabular->GetPWidth(cell).zero();
2808 // well we didn't obviously find it so maybe our owner knows more
2810 return owner()->forceDefaultParagraphs(in);
2811 // if we're here there is really something strange going on!!!
2815 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2818 if (buf.length() <= 0)
2824 string::size_type len = buf.length();
2825 string::size_type p = 0;
2828 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2837 maxCols = max(cols, maxCols);
2843 maxCols = max(cols, maxCols);
2844 LyXTabular * loctab;
2849 delete paste_tabular;
2850 paste_tabular = new LyXTabular(bv->buffer()->params,
2851 this, rows, maxCols);
2852 loctab = paste_tabular;
2855 loctab = tabular.get();
2860 string::size_type op = 0;
2861 int cells = loctab->GetNumberOfCells();
2864 rows = loctab->rows();
2865 int const columns = loctab->columns();
2866 while ((cell < cells) && (p < len) && (row < rows) &&
2867 (p = buf.find_first_of("\t\n", p)) != string::npos)
2873 // we can only set this if we are not too far right
2874 if (cols < columns) {
2875 InsetText * ti = loctab->GetCellInset(cell);
2876 LyXFont const font = ti->getLyXText(bv)->
2877 getFont(bv->buffer(), ti->paragraph(), 0);
2878 ti->setText(buf.substr(op, p-op), font);
2884 // we can only set this if we are not too far right
2885 if (cols < columns) {
2886 InsetText * ti = loctab->GetCellInset(cell);
2887 LyXFont const font = ti->getLyXText(bv)->
2888 getFont(bv->buffer(), ti->paragraph(), 0);
2889 ti->setText(buf.substr(op, p-op), font);
2894 cell = loctab->GetCellNumber(row, cols);
2900 // check for the last cell if there is no trailing '\n'
2901 if ((cell < cells) && (op < len)) {
2902 InsetText * ti = loctab->GetCellInset(cell);
2903 LyXFont const font = ti->getLyXText(bv)->
2904 getFont(bv->buffer(), ti->paragraph(), 0);
2905 ti->setText(buf.substr(op, len-op), font);