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, unsigned int 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 != 3)) {
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, int button)
771 if (hasSelection() && (button == 3))
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;
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, int button)
839 if (the_locking_inset)
840 ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
841 y - inset_y, button);
842 if (button == 3 && !ret) {
843 bv->owner()->getDialogs()->showTabular(this);
850 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int 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 void InsetTabular::insetKeyPress(XKeyEvent * xke)
876 if (the_locking_inset) {
877 the_locking_inset->insetKeyPress(xke);
883 UpdatableInset::RESULT
884 InsetTabular::localDispatch(BufferView * bv, kb_action action,
887 // We need to save the value of the_locking_inset as the call to
888 // the_locking_inset->LocalDispatch might unlock it.
889 old_locking_inset = the_locking_inset;
890 UpdatableInset::RESULT result =
891 UpdatableInset::localDispatch(bv, action, arg);
892 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
897 if ((action < 0) && arg.empty())
900 bool hs = hasSelection();
903 // this one have priority over the locked InsetText, if we're not already
904 // inside another tabular then that one get's priority!
905 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
910 unlockInsetInInset(bv, the_locking_inset);
911 if (action == LFUN_TAB)
912 moveNextCell(bv, old_locking_inset != 0);
914 movePrevCell(bv, old_locking_inset != 0);
917 updateLocal(bv, SELECTION, false);
918 if (!the_locking_inset) {
920 return DISPATCHED_NOUPDATE;
923 // this to avoid compiler warnings.
929 if (the_locking_inset) {
930 result = the_locking_inset->localDispatch(bv, action, arg);
931 if (result == DISPATCHED_NOUPDATE) {
934 if (sc != scroll()) { // inset has been scrolled
935 the_locking_inset->toggleInsetCursor(bv);
936 updateLocal(bv, FULL, false);
937 the_locking_inset->toggleInsetCursor(bv);
940 } else if (result == DISPATCHED) {
941 the_locking_inset->toggleInsetCursor(bv);
942 updateLocal(bv, CELL, false);
943 the_locking_inset->toggleInsetCursor(bv);
945 } else if (result == FINISHED_UP) {
947 } else if (result == FINISHED_DOWN) {
949 } else if (result == FINISHED_RIGHT) {
957 // --- Cursor Movements ----------------------------------
958 case LFUN_RIGHTSEL: {
959 int const start = hasSelection() ? sel_cell_start : actcell;
960 if (tabular->IsLastCellInRow(actcell)) {
961 setSelection(start, actcell);
966 // if we are starting a selection, only select
967 // the current cell at the beginning
968 if (hasSelection()) {
969 moveRight(bv, false);
972 setSelection(start, end);
973 updateLocal(bv, SELECTION, false);
977 result = moveRight(bv);
980 updateLocal(bv, SELECTION, false);
983 int const start = hasSelection() ? sel_cell_start : actcell;
984 if (tabular->IsFirstCellInRow(actcell)) {
985 setSelection(start, actcell);
990 // if we are starting a selection, only select
991 // the current cell at the beginning
992 if (hasSelection()) {
996 setSelection(start, end);
997 updateLocal(bv, SELECTION, false);
1001 result = moveLeft(bv);
1004 updateLocal(bv, SELECTION, false);
1006 case LFUN_DOWNSEL: {
1007 int const start = hasSelection() ? sel_cell_start : actcell;
1008 int const ocell = actcell;
1009 // if we are starting a selection, only select
1010 // the current cell at the beginning
1011 if (hasSelection()) {
1012 moveDown(bv, false);
1013 if ((ocell == sel_cell_end) ||
1014 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1015 setSelection(start, tabular->GetCellBelow(sel_cell_end));
1017 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
1019 setSelection(start, start);
1021 updateLocal(bv, SELECTION, false);
1025 result = moveDown(bv, old_locking_inset != 0);
1028 updateLocal(bv, SELECTION, false);
1032 int const start = hasSelection() ? sel_cell_start : actcell;
1033 int const ocell = actcell;
1034 // if we are starting a selection, only select
1035 // the current cell at the beginning
1036 if (hasSelection()) {
1038 if ((ocell == sel_cell_end) ||
1039 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
1040 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1042 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1044 setSelection(start, start);
1046 updateLocal(bv, SELECTION, false);
1050 result = moveUp(bv, old_locking_inset != 0);
1053 updateLocal(bv, SELECTION, false);
1056 UpdateCodes code = CURSOR;
1061 int column = actcol;
1062 unlockInsetInInset(bv, the_locking_inset);
1063 if (bv->text->first_y + bv->painter().paperHeight() <
1064 (top_baseline + tabular->GetHeightOfTabular()))
1066 bv->scrollCB(bv->text->first_y + bv->painter().paperHeight());
1068 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1070 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1073 updateLocal(bv, code, false);
1077 UpdateCodes code = CURSOR;
1082 int column = actcol;
1083 unlockInsetInInset(bv, the_locking_inset);
1084 if (top_baseline < 0) {
1085 bv->scrollCB(bv->text->first_y - bv->painter().paperHeight());
1087 if (top_baseline > 0)
1090 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1095 updateLocal(bv, code, false);
1098 // none of these make sense for insettabular,
1099 // but we must catch them to prevent any
1100 // selection from being confused
1104 case LFUN_WORDLEFTSEL:
1105 case LFUN_WORDRIGHT:
1106 case LFUN_WORDRIGHTSEL:
1107 case LFUN_DOWN_PARAGRAPH:
1108 case LFUN_DOWN_PARAGRAPHSEL:
1109 case LFUN_UP_PARAGRAPH:
1110 case LFUN_UP_PARAGRAPHSEL:
1111 case LFUN_BACKSPACE:
1117 case LFUN_BEGINNINGBUF:
1118 case LFUN_BEGINNINGBUFSEL:
1120 case LFUN_ENDBUFSEL:
1122 case LFUN_LAYOUT_TABULAR:
1123 bv->owner()->getDialogs()->showTabular(this);
1125 case LFUN_TABULAR_FEATURE:
1126 if (!tabularFeatures(bv, arg))
1127 result = UNDISPATCHED;
1129 // insert file functions
1130 case LFUN_FILE_INSERT_ASCII_PARA:
1131 case LFUN_FILE_INSERT_ASCII:
1133 string tmpstr = getContentsOfAsciiFile(bv, arg, false);
1136 if (insertAsciiString(bv, tmpstr, false))
1137 updateLocal(bv, INIT, true);
1139 result = UNDISPATCHED;
1142 // cut and paste functions
1144 if (!copySelection(bv))
1146 setUndo(bv, Undo::DELETE,
1147 bv->text->cursor.par(),
1148 bv->text->cursor.par()->next());
1150 updateLocal(bv, INIT, true);
1153 if (!hasSelection())
1158 case LFUN_PASTESELECTION:
1160 string const clip(bv->getClipboard());
1164 if (clip.find('\t') != string::npos) {
1168 string::size_type len = clip.length();
1169 string::size_type p = 0;
1172 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1180 maxCols = max(cols, maxCols);
1186 maxCols = max(cols, maxCols);
1187 delete paste_tabular;
1188 paste_tabular = new LyXTabular(bv->buffer()->params,
1189 this, rows, maxCols);
1190 string::size_type op = 0;
1192 int cells = paste_tabular->GetNumberOfCells();
1194 while ((cell < cells) && (p < len) &&
1195 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1200 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1205 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1206 while (cols++ < maxCols)
1214 // check for the last cell if there is no trailing '\n'
1215 if ((cell < cells) && (op < len))
1216 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1219 if (!insertAsciiString(bv, clip, true))
1222 // so that the clipboard is used and it goes on
1224 // and executes LFUN_PASTESELECTION in insettext!
1225 delete paste_tabular;
1230 if (hasPasteBuffer()) {
1231 setUndo(bv, Undo::INSERT,
1232 bv->text->cursor.par(),
1233 bv->text->cursor.par()->next());
1235 updateLocal(bv, INIT, true);
1238 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1240 // handle font changing stuff on selection before we lock the inset
1241 // in the default part!
1242 result = UNDISPATCHED;
1253 case LFUN_UNDERLINE:
1254 case LFUN_FONT_SIZE:
1255 if (bv->Dispatch(action, arg))
1256 result = DISPATCHED;
1262 // we try to activate the actual inset and put this event down to
1263 // the insets dispatch function.
1264 if ((result == DISPATCHED) || the_locking_inset)
1267 if (activateCellInset(bv)) {
1268 // reset need_update setted in above function!
1270 result = the_locking_inset->localDispatch(bv, action, arg);
1271 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1272 unlockInsetInInset(bv, the_locking_inset);
1274 // we need to update if this was requested before
1275 updateLocal(bv, NONE, false);
1276 return UNDISPATCHED;
1279 // so the below CELL is not set because this is higher
1280 // priority and we get a full redraw
1281 need_update = SELECTION;
1284 updateLocal(bv, CELL, false);
1289 if (result < FINISHED) {
1290 if (!the_locking_inset) {
1291 if (bv->fitCursor())
1292 updateLocal(bv, FULL, false);
1294 showInsetCursor(bv);
1297 bv->unlockInset(this);
1302 int InsetTabular::latex(Buffer const * buf, ostream & os,
1303 bool fragile, bool fp) const
1305 return tabular->latex(buf, os, fragile, fp);
1309 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1312 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1314 return tabular->ascii(buf, os, 0, false,0);
1318 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1321 int const ret = tabular->ascii(buf,os,
1322 (int)parOwner()->params().depth(),
1329 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1334 // if the table is inside a float it doesn't need the informaltable
1335 // wrapper. Search for it.
1336 for(master = owner();
1337 master && master->lyxCode() != Inset::FLOAT_CODE;
1338 master = master->owner());
1341 os << "<informaltable>\n";
1344 ret+= tabular->docBook(buf,os);
1346 os << "</informaltable>\n";
1353 void InsetTabular::validate(LaTeXFeatures & features) const
1355 tabular->Validate(features);
1359 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1360 LyXFont const & font,
1367 bool changed = false;
1369 // if we have a locking_inset we should have to check only this cell for
1370 // change so I'll try this to have a boost, but who knows ;)
1371 if ((need_update != INIT) &&
1372 (the_locking_inset == tabular->GetCellInset(actcell))) {
1373 for(int i = 0; i < tabular->columns(); ++i) {
1374 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1376 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1379 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1380 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1381 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1384 for (int i = 0; i < tabular->rows(); ++i) {
1387 for (int j = 0; j < tabular->columns(); ++j) {
1388 if (tabular->IsPartOfMultiColumn(i,j))
1391 inset = tabular->GetCellInset(cell);
1392 if (!reinit && !tabular->GetPWidth(cell).zero())
1393 inset->update(bv, font, false);
1394 maxAsc = max(maxAsc, inset->ascent(bv, font));
1395 maxDesc = max(maxDesc, inset->descent(bv, font));
1396 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1398 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1399 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1407 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1409 if (the_locking_inset) {
1410 the_locking_inset->getCursorPos(bv, x, y);
1413 x = cursor_.x() - top_x;
1418 void InsetTabular::toggleInsetCursor(BufferView * bv)
1421 if (isCursorVisible())
1422 bv->hideLockedInsetCursor();
1425 if (the_locking_inset) {
1426 the_locking_inset->toggleInsetCursor(bv);
1430 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1432 int const asc = font_metrics::maxAscent(font);
1433 int const desc = font_metrics::maxDescent(font);
1435 if (isCursorVisible())
1436 bv->hideLockedInsetCursor();
1438 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1439 toggleCursorVisible();
1443 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1447 if (!isCursorVisible()) {
1448 LyXFont font; // = GetFont(par, cursor.pos);
1450 int const asc = font_metrics::maxAscent(font);
1451 int const desc = font_metrics::maxDescent(font);
1452 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1454 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1455 setCursorVisible(true);
1460 void InsetTabular::hideInsetCursor(BufferView * bv)
1462 if (isCursorVisible()) {
1463 bv->hideLockedInsetCursor();
1464 setCursorVisible(false);
1469 void InsetTabular::fitInsetCursor(BufferView * bv) const
1471 if (the_locking_inset) {
1472 int old_first_y = bv->text->first_y;
1473 the_locking_inset->fitInsetCursor(bv);
1474 if (old_first_y != bv->text->first_y)
1480 int const asc = font_metrics::maxAscent(font);
1481 int const desc = font_metrics::maxDescent(font);
1484 if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
1489 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1493 actcell = actrow = actcol = 0;
1494 int ly = tabular->GetDescentOfRow(actrow);
1496 // first search the right row
1497 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1498 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1499 tabular->GetAscentOfRow(actrow + 1) +
1500 tabular->GetAdditionalHeight(actrow + 1));
1502 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1504 actcell = tabular->GetCellNumber(actrow, actcol);
1506 // now search the right column
1507 int lx = tabular->GetWidthOfColumn(actcell) -
1508 tabular->GetAdditionalWidth(actcell);
1509 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1510 lx += tabular->GetWidthOfColumn(actcell + 1)
1511 + tabular->GetAdditionalWidth(actcell);
1513 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1518 int InsetTabular::getCellXPos(int cell) const
1522 for (; !tabular->IsFirstCellInRow(c); --c)
1524 int lx = tabular->GetWidthOfColumn(cell);
1525 for (; c < cell; ++c) {
1526 lx += tabular->GetWidthOfColumn(c);
1528 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1532 void InsetTabular::resetPos(BufferView * bv) const
1534 #ifdef WITH_WARNINGS
1535 #warning This should be fixed in the right manner (20011128 Jug)
1537 // fast hack to fix infinite repaintings!
1542 actcol = tabular->column_of_cell(actcell);
1545 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1546 if (tabular->IsLastCellInRow(cell)) {
1547 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1548 tabular->GetAscentOfRow(actrow + 1) +
1549 tabular->GetAdditionalHeight(actrow + 1));
1553 if (!locked || nodraw()) {
1554 if (the_locking_inset)
1555 inset_y = cursor_.y();
1558 // we need this only from here on!!!
1559 in_reset_pos = true;
1560 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1561 int new_x = getCellXPos(actcell);
1562 int old_x = cursor_.x();
1565 // cursor.x(getCellXPos(actcell) + offset);
1566 if ((actcol < tabular->columns()-1) && scroll(false) &&
1567 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1570 updateLocal(bv, FULL, false);
1571 } else if (the_locking_inset &&
1572 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1574 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1575 if (xx > (bv->workWidth()-20)) {
1576 scroll(bv, -(xx - bv->workWidth() + 60));
1577 updateLocal(bv, FULL, false);
1578 } else if (xx < 20) {
1584 updateLocal(bv, FULL, false);
1586 } else if ((cursor_.x() - offset) > 20 &&
1587 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1588 > (bv->workWidth() - 20)) {
1589 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1590 updateLocal(bv, FULL, false);
1591 } else if ((cursor_.x() - offset) < 20) {
1592 scroll(bv, 20 - cursor_.x() + offset);
1593 updateLocal(bv, FULL, false);
1594 } else if (scroll(false) && top_x > 20 &&
1595 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1596 scroll(bv, old_x - cursor_.x());
1597 updateLocal(bv, FULL, false);
1599 if (the_locking_inset) {
1600 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1601 inset_y = cursor_.y();
1603 if ((!the_locking_inset ||
1604 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1605 actcell != oldcell) {
1606 InsetTabular * inset = const_cast<InsetTabular *>(this);
1607 bv->owner()->getDialogs()->updateTabular(inset);
1610 in_reset_pos = false;
1614 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1616 if (lock && !old_locking_inset) {
1617 if (activateCellInset(bv))
1620 bool moved = isRightToLeft(bv)
1621 ? movePrevCell(bv) : moveNextCell(bv);
1623 return FINISHED_RIGHT;
1624 if (lock && activateCellInset(bv))
1628 return DISPATCHED_NOUPDATE;
1632 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1634 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1637 if (lock) { // behind the inset
1638 if (activateCellInset(bv, 0, 0, 0, true))
1642 return DISPATCHED_NOUPDATE;
1646 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1648 int const ocell = actcell;
1649 actcell = tabular->GetCellAbove(actcell);
1650 if (actcell == ocell) // we moved out of the inset
1656 if (old_locking_inset) {
1657 old_locking_inset->getCursorPos(bv, x, y);
1658 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1660 if (activateCellInset(bv, x, 0))
1663 return DISPATCHED_NOUPDATE;
1667 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1669 int const ocell = actcell;
1670 actcell = tabular->GetCellBelow(actcell);
1671 if (actcell == ocell) // we moved out of the inset
1672 return FINISHED_DOWN;
1677 if (old_locking_inset) {
1678 old_locking_inset->getCursorPos(bv, x, y);
1679 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1681 if (activateCellInset(bv, x, 0))
1684 return DISPATCHED_NOUPDATE;
1688 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1690 if (isRightToLeft(bv)) {
1691 if (tabular->IsFirstCellInRow(actcell)) {
1692 int row = tabular->row_of_cell(actcell);
1693 if (row == tabular->rows() - 1)
1695 actcell = tabular->GetLastCellInRow(row);
1696 actcell = tabular->GetCellBelow(actcell);
1703 if (tabular->IsLastCell(actcell))
1708 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1709 isRightToLeftPar(bv->buffer()->params);
1710 activateCellInset(bv, 0, 0, 0, !rtl);
1717 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1719 if (isRightToLeft(bv)) {
1720 if (tabular->IsLastCellInRow(actcell)) {
1721 int row = tabular->row_of_cell(actcell);
1724 actcell = tabular->GetFirstCellInRow(row);
1725 actcell = tabular->GetCellAbove(actcell);
1727 if (tabular->IsLastCell(actcell))
1732 if (!actcell) // first cell
1737 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1738 isRightToLeftPar(bv->buffer()->params);
1739 activateCellInset(bv, 0, 0, 0, !rtl);
1746 bool InsetTabular::deletable() const
1752 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1756 setSelection(0, tabular->GetNumberOfCells() - 1);
1758 if (hasSelection()) {
1759 setUndo(bv, Undo::EDIT,
1760 bv->text->cursor.par(),
1761 bv->text->cursor.par()->next());
1762 bool frozen = undo_frozen;
1765 // apply the fontchange on the whole selection
1770 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1771 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1772 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1773 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1780 updateLocal(bv, INIT, true);
1782 if (the_locking_inset)
1783 the_locking_inset->setFont(bv, font, tall);
1787 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1789 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1792 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1793 string const tmp = tabularFeature[i].feature;
1795 if (tmp == what.substr(0, tmp.length())) {
1796 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1797 //tabularFeatures[i].feature.length())) {
1798 action = tabularFeature[i].action;
1802 if (action == LyXTabular::LAST_ACTION)
1806 frontStrip(what.substr(tabularFeature[i].feature.length()));
1807 tabularFeatures(bv, action, val);
1811 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1812 string const & special, bool & flag)
1814 if (special == "dl_above") {
1817 } else if (special == "dl_below") {
1818 ltt.bottomDL = flag;
1820 } else if (special == "empty") {
1830 void InsetTabular::tabularFeatures(BufferView * bv,
1831 LyXTabular::Feature feature,
1832 string const & value)
1838 bool setLines = false;
1839 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1840 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1843 case LyXTabular::M_ALIGN_LEFT:
1844 case LyXTabular::ALIGN_LEFT:
1845 setAlign = LYX_ALIGN_LEFT;
1847 case LyXTabular::M_ALIGN_RIGHT:
1848 case LyXTabular::ALIGN_RIGHT:
1849 setAlign = LYX_ALIGN_RIGHT;
1851 case LyXTabular::M_ALIGN_CENTER:
1852 case LyXTabular::ALIGN_CENTER:
1853 setAlign = LYX_ALIGN_CENTER;
1855 case LyXTabular::M_VALIGN_TOP:
1856 case LyXTabular::VALIGN_TOP:
1857 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1859 case LyXTabular::M_VALIGN_BOTTOM:
1860 case LyXTabular::VALIGN_BOTTOM:
1861 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1863 case LyXTabular::M_VALIGN_CENTER:
1864 case LyXTabular::VALIGN_CENTER:
1865 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1870 if (hasSelection()) {
1871 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1873 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1874 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1876 setUndo(bv, Undo::FINISH,
1877 bv->text->cursor.par(),
1878 bv->text->cursor.par()->next());
1880 int row = tabular->row_of_cell(actcell);
1881 int column = tabular->column_of_cell(actcell);
1883 LyXTabular::ltType ltt;
1886 case LyXTabular::SET_PWIDTH:
1888 LyXLength const vallen(value);
1889 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1891 bool const update = (tmplen != vallen);
1892 tabular->SetColumnPWidth(actcell, vallen);
1895 for (int i = 0; i < tabular->rows(); ++i) {
1896 cell = tabular->GetCellNumber(i,column);
1897 tabular->GetCellInset(cell)->resizeLyXText(bv);
1899 updateLocal(bv, INIT, true);
1903 case LyXTabular::SET_MPWIDTH:
1905 LyXLength const vallen(value);
1906 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1908 bool const update = (tmplen != vallen);
1909 tabular->SetMColumnPWidth(actcell, vallen);
1911 for (int i = 0; i < tabular->rows(); ++i) {
1912 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1915 updateLocal(bv, INIT, true);
1919 case LyXTabular::SET_SPECIAL_COLUMN:
1920 case LyXTabular::SET_SPECIAL_MULTI:
1921 tabular->SetAlignSpecial(actcell,value,feature);
1922 updateLocal(bv, FULL, true);
1924 case LyXTabular::APPEND_ROW:
1925 // append the row into the tabular
1926 unlockInsetInInset(bv, the_locking_inset);
1927 tabular->AppendRow(bv->buffer()->params, actcell);
1928 updateLocal(bv, INIT, true);
1930 case LyXTabular::APPEND_COLUMN:
1931 // append the column into the tabular
1932 unlockInsetInInset(bv, the_locking_inset);
1933 tabular->AppendColumn(bv->buffer()->params, actcell);
1934 actcell = tabular->GetCellNumber(row, column);
1935 updateLocal(bv, INIT, true);
1937 case LyXTabular::DELETE_ROW:
1938 unlockInsetInInset(bv, the_locking_inset);
1939 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1940 tabular->DeleteRow(sel_row_start);
1942 if (sel_row_start >= tabular->rows())
1944 actcell = tabular->GetCellNumber(sel_row_start, column);
1946 updateLocal(bv, INIT, true);
1948 case LyXTabular::DELETE_COLUMN:
1949 unlockInsetInInset(bv, the_locking_inset);
1950 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1951 tabular->DeleteColumn(sel_col_start);
1953 if (sel_col_start >= tabular->columns())
1955 actcell = tabular->GetCellNumber(row, sel_col_start);
1957 updateLocal(bv, INIT, true);
1959 case LyXTabular::M_TOGGLE_LINE_TOP:
1961 case LyXTabular::TOGGLE_LINE_TOP:
1963 bool lineSet = !tabular->TopLine(actcell, flag);
1964 for (int i = sel_row_start; i <= sel_row_end; ++i)
1965 for (int j = sel_col_start; j <= sel_col_end; ++j)
1966 tabular->SetTopLine(
1967 tabular->GetCellNumber(i, j),
1969 updateLocal(bv, INIT, true);
1973 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1975 case LyXTabular::TOGGLE_LINE_BOTTOM:
1977 bool lineSet = !tabular->BottomLine(actcell, flag);
1978 for (int i = sel_row_start; i <= sel_row_end; ++i)
1979 for (int j = sel_col_start; j <= sel_col_end; ++j)
1980 tabular->SetBottomLine(
1981 tabular->GetCellNumber(i, j),
1984 updateLocal(bv, INIT, true);
1988 case LyXTabular::M_TOGGLE_LINE_LEFT:
1990 case LyXTabular::TOGGLE_LINE_LEFT:
1992 bool lineSet = !tabular->LeftLine(actcell, flag);
1993 for (int i = sel_row_start; i <= sel_row_end; ++i)
1994 for (int j = sel_col_start; j <= sel_col_end; ++j)
1995 tabular->SetLeftLine(
1996 tabular->GetCellNumber(i,j),
1999 updateLocal(bv, INIT, true);
2003 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2005 case LyXTabular::TOGGLE_LINE_RIGHT:
2007 bool lineSet = !tabular->RightLine(actcell, flag);
2008 for (int i = sel_row_start; i <= sel_row_end; ++i)
2009 for (int j = sel_col_start; j <= sel_col_end; ++j)
2010 tabular->SetRightLine(
2011 tabular->GetCellNumber(i,j),
2014 updateLocal(bv, INIT, true);
2018 case LyXTabular::M_ALIGN_LEFT:
2019 case LyXTabular::M_ALIGN_RIGHT:
2020 case LyXTabular::M_ALIGN_CENTER:
2022 case LyXTabular::ALIGN_LEFT:
2023 case LyXTabular::ALIGN_RIGHT:
2024 case LyXTabular::ALIGN_CENTER:
2025 for (int i = sel_row_start; i <= sel_row_end; ++i)
2026 for (int j = sel_col_start; j <= sel_col_end; ++j)
2027 tabular->SetAlignment(
2028 tabular->GetCellNumber(i, j),
2031 updateLocal(bv, INIT, true);
2033 case LyXTabular::M_VALIGN_TOP:
2034 case LyXTabular::M_VALIGN_BOTTOM:
2035 case LyXTabular::M_VALIGN_CENTER:
2037 case LyXTabular::VALIGN_TOP:
2038 case LyXTabular::VALIGN_BOTTOM:
2039 case LyXTabular::VALIGN_CENTER:
2040 for (int i = sel_row_start; i <= sel_row_end; ++i)
2041 for (int j = sel_col_start; j <= sel_col_end; ++j)
2042 tabular->SetVAlignment(
2043 tabular->GetCellNumber(i, j),
2045 updateLocal(bv, INIT, true);
2047 case LyXTabular::MULTICOLUMN:
2049 if (sel_row_start != sel_row_end) {
2050 Alert::alert(_("Impossible Operation!"),
2051 _("Multicolumns can only be horizontally."),
2055 // just multicol for one Single Cell
2056 if (!hasSelection()) {
2057 // check wether we are completly in a multicol
2058 if (tabular->IsMultiColumn(actcell)) {
2059 tabular->UnsetMultiColumn(actcell);
2060 updateLocal(bv, INIT, true);
2062 tabular->SetMultiColumn(bv->buffer(), actcell, 1);
2063 updateLocal(bv, CELL, true);
2067 // we have a selection so this means we just add all this
2068 // cells to form a multicolumn cell
2072 if (sel_cell_start > sel_cell_end) {
2073 s_start = sel_cell_end;
2074 s_end = sel_cell_start;
2076 s_start = sel_cell_start;
2077 s_end = sel_cell_end;
2079 tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
2082 updateLocal(bv, INIT, true);
2085 case LyXTabular::SET_ALL_LINES:
2087 case LyXTabular::UNSET_ALL_LINES:
2088 for (int i = sel_row_start; i <= sel_row_end; ++i)
2089 for (int j = sel_col_start; j <= sel_col_end; ++j)
2090 tabular->SetAllLines(
2091 tabular->GetCellNumber(i,j), setLines);
2092 updateLocal(bv, INIT, true);
2094 case LyXTabular::SET_LONGTABULAR:
2095 tabular->SetLongTabular(true);
2096 updateLocal(bv, INIT, true); // because this toggles displayed
2098 case LyXTabular::UNSET_LONGTABULAR:
2099 tabular->SetLongTabular(false);
2100 updateLocal(bv, INIT, true); // because this toggles displayed
2102 case LyXTabular::SET_ROTATE_TABULAR:
2103 tabular->SetRotateTabular(true);
2105 case LyXTabular::UNSET_ROTATE_TABULAR:
2106 tabular->SetRotateTabular(false);
2108 case LyXTabular::SET_ROTATE_CELL:
2109 for (int i = sel_row_start; i <= sel_row_end; ++i)
2110 for (int j = sel_col_start; j<=sel_col_end; ++j)
2111 tabular->SetRotateCell(
2112 tabular->GetCellNumber(i, j),
2115 case LyXTabular::UNSET_ROTATE_CELL:
2116 for (int i = sel_row_start; i <= sel_row_end; ++i)
2117 for (int j = sel_col_start; j <= sel_col_end; ++j)
2118 tabular->SetRotateCell(
2119 tabular->GetCellNumber(i, j), false);
2121 case LyXTabular::SET_USEBOX:
2123 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2124 if (val == tabular->GetUsebox(actcell))
2125 val = LyXTabular::BOX_NONE;
2126 for (int i = sel_row_start; i <= sel_row_end; ++i)
2127 for (int j = sel_col_start; j <= sel_col_end; ++j)
2129 tabular->GetCellNumber(i, j), val);
2132 case LyXTabular::UNSET_LTFIRSTHEAD:
2134 case LyXTabular::SET_LTFIRSTHEAD:
2135 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2136 checkLongtableSpecial(ltt, value, flag);
2137 tabular->SetLTHead(row, flag, ltt, true);
2139 case LyXTabular::UNSET_LTHEAD:
2141 case LyXTabular::SET_LTHEAD:
2142 (void)tabular->GetRowOfLTHead(row, ltt);
2143 checkLongtableSpecial(ltt, value, flag);
2144 tabular->SetLTHead(row, flag, ltt, false);
2146 case LyXTabular::UNSET_LTFOOT:
2148 case LyXTabular::SET_LTFOOT:
2149 (void)tabular->GetRowOfLTFoot(row, ltt);
2150 checkLongtableSpecial(ltt, value, flag);
2151 tabular->SetLTFoot(row, flag, ltt, false);
2153 case LyXTabular::UNSET_LTLASTFOOT:
2155 case LyXTabular::SET_LTLASTFOOT:
2156 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2157 checkLongtableSpecial(ltt, value, flag);
2158 tabular->SetLTFoot(row, flag, ltt, true);
2160 case LyXTabular::SET_LTNEWPAGE:
2162 bool what = !tabular->GetLTNewPage(row);
2163 tabular->SetLTNewPage(row, what);
2166 // dummy stuff just to avoid warnings
2167 case LyXTabular::LAST_ACTION:
2173 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2176 UpdatableInset * inset =
2177 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2178 LyXFont font(LyXFont::ALL_SANE);
2180 x = inset->x() + inset->width(bv, font);
2181 y = inset->descent(bv, font);
2183 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2184 //inset_y = cursor.y();
2185 inset->edit(bv, x, y, button);
2186 if (!the_locking_inset)
2188 updateLocal(bv, CELL, false);
2189 return (the_locking_inset != 0);
2193 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2196 inset_x = cursor_.x()
2197 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2198 inset_y = cursor_.y();
2199 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2203 bool InsetTabular::insetHit(BufferView *, int x, int) const
2206 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2210 // This returns paperWidth() if the cell-width is unlimited or the width
2211 // in pixels if we have a pwidth for this cell.
2212 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2214 LyXLength const len = tabular->GetPWidth(cell);
2218 return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
2222 int InsetTabular::getMaxWidth(BufferView * bv,
2223 UpdatableInset const * inset) const
2225 int cell = tabular->GetCellFromInset(inset, actcell);
2228 lyxerr << "Own inset not found, shouldn't really happen!"
2233 int w = getMaxWidthOfCell(bv, cell);
2235 // because the inset then subtracts it's top_x and owner->x()
2236 w += (inset->x() - top_x);
2243 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2245 resizeLyXText(bv, recursive);
2249 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2252 for(int i = 0; i < tabular->rows(); ++i) {
2253 for(int j = 0; j < tabular->columns(); ++j) {
2254 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2262 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2263 bool const recursive) const
2265 if (the_locking_inset)
2266 return the_locking_inset->getLyXText(bv, recursive);
2268 // if we're locked lock the actual insettext and return it's LyXText!!!
2270 UpdatableInset * inset =
2271 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2272 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2273 return the_locking_inset->getLyXText(bv, recursive);
2276 return Inset::getLyXText(bv, recursive);
2280 bool InsetTabular::showInsetDialog(BufferView * bv) const
2282 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2283 bv->owner()->getDialogs()
2284 ->showTabular(const_cast<InsetTabular *>(this));
2289 void InsetTabular::openLayoutDialog(BufferView * bv) const
2291 if (the_locking_inset) {
2292 InsetTabular * i = static_cast<InsetTabular *>
2293 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2295 i->openLayoutDialog(bv);
2299 bv->owner()->getDialogs()->showTabular(
2300 const_cast<InsetTabular *>(this));
2305 // function returns an object as defined in func_status.h:
2306 // states OK, Unknown, Disabled, On, Off.
2308 FuncStatus InsetTabular::getStatus(string const & what) const
2310 int action = LyXTabular::LAST_ACTION;
2314 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2315 string const tmp = tabularFeature[i].feature;
2316 if (tmp == what.substr(0, tmp.length())) {
2317 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2318 // tabularFeatures[i].feature.length())) {
2319 action = tabularFeature[i].action;
2323 if (action == LyXTabular::LAST_ACTION) {
2325 return status.unknown(true);
2328 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2333 LyXTabular::ltType dummyltt;
2336 if (hasSelection()) {
2337 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2339 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2343 case LyXTabular::SET_PWIDTH:
2344 case LyXTabular::SET_MPWIDTH:
2345 case LyXTabular::SET_SPECIAL_COLUMN:
2346 case LyXTabular::SET_SPECIAL_MULTI:
2347 return status.disabled(true);
2349 case LyXTabular::APPEND_ROW:
2350 case LyXTabular::APPEND_COLUMN:
2351 case LyXTabular::DELETE_ROW:
2352 case LyXTabular::DELETE_COLUMN:
2353 case LyXTabular::SET_ALL_LINES:
2354 case LyXTabular::UNSET_ALL_LINES:
2355 return status.clear();
2357 case LyXTabular::MULTICOLUMN:
2358 status.setOnOff(tabular->IsMultiColumn(actcell));
2360 case LyXTabular::M_TOGGLE_LINE_TOP:
2362 case LyXTabular::TOGGLE_LINE_TOP:
2363 status.setOnOff(tabular->TopLine(actcell, flag));
2365 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2367 case LyXTabular::TOGGLE_LINE_BOTTOM:
2368 status.setOnOff(tabular->BottomLine(actcell, flag));
2370 case LyXTabular::M_TOGGLE_LINE_LEFT:
2372 case LyXTabular::TOGGLE_LINE_LEFT:
2373 status.setOnOff(tabular->LeftLine(actcell, flag));
2375 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2377 case LyXTabular::TOGGLE_LINE_RIGHT:
2378 status.setOnOff(tabular->RightLine(actcell, flag));
2380 case LyXTabular::M_ALIGN_LEFT:
2382 case LyXTabular::ALIGN_LEFT:
2383 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT);
2385 case LyXTabular::M_ALIGN_RIGHT:
2387 case LyXTabular::ALIGN_RIGHT:
2388 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
2390 case LyXTabular::M_ALIGN_CENTER:
2392 case LyXTabular::ALIGN_CENTER:
2393 status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
2395 case LyXTabular::M_VALIGN_TOP:
2397 case LyXTabular::VALIGN_TOP:
2398 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
2400 case LyXTabular::M_VALIGN_BOTTOM:
2402 case LyXTabular::VALIGN_BOTTOM:
2403 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
2405 case LyXTabular::M_VALIGN_CENTER:
2407 case LyXTabular::VALIGN_CENTER:
2408 status.setOnOff(tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER);
2410 case LyXTabular::SET_LONGTABULAR:
2411 status.setOnOff(tabular->IsLongTabular());
2413 case LyXTabular::UNSET_LONGTABULAR:
2414 status.setOnOff(!tabular->IsLongTabular());
2416 case LyXTabular::SET_ROTATE_TABULAR:
2417 status.setOnOff(tabular->GetRotateTabular());
2419 case LyXTabular::UNSET_ROTATE_TABULAR:
2420 status.setOnOff(!tabular->GetRotateTabular());
2422 case LyXTabular::SET_ROTATE_CELL:
2423 status.setOnOff(tabular->GetRotateCell(actcell));
2425 case LyXTabular::UNSET_ROTATE_CELL:
2426 status.setOnOff(!tabular->GetRotateCell(actcell));
2428 case LyXTabular::SET_USEBOX:
2429 status.setOnOff(strToInt(argument) == tabular->GetUsebox(actcell));
2431 case LyXTabular::SET_LTFIRSTHEAD:
2432 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2434 case LyXTabular::SET_LTHEAD:
2435 status.setOnOff(tabular->GetRowOfLTHead(sel_row_start, dummyltt));
2437 case LyXTabular::SET_LTFOOT:
2438 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2440 case LyXTabular::SET_LTLASTFOOT:
2441 status.setOnOff(tabular->GetRowOfLTFoot(sel_row_start, dummyltt));
2443 case LyXTabular::SET_LTNEWPAGE:
2444 status.setOnOff(tabular->GetLTNewPage(sel_row_start));
2448 status.disabled(true);
2455 vector<string> const InsetTabular::getLabelList() const
2457 return tabular->getLabelList();
2461 bool InsetTabular::copySelection(BufferView * bv)
2463 if (!hasSelection())
2466 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2467 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2468 if (sel_col_start > sel_col_end) {
2469 sel_col_start = sel_col_end;
2470 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2472 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2474 int const columns = sel_col_end - sel_col_start + 1;
2476 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2477 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2478 if (sel_row_start > sel_row_end) {
2479 swap(sel_row_start, sel_row_end);
2481 int const rows = sel_row_end - sel_row_start + 1;
2483 delete paste_tabular;
2484 paste_tabular = new LyXTabular(bv->buffer()->params,
2485 this, *tabular); // rows, columns);
2486 for (int i = 0; i < sel_row_start; ++i)
2487 paste_tabular->DeleteRow(0);
2488 while (paste_tabular->rows() > rows)
2489 paste_tabular->DeleteRow(rows);
2490 paste_tabular->SetTopLine(0, true, true);
2491 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2493 for (int i = 0; i < sel_col_start; ++i)
2494 paste_tabular->DeleteColumn(0);
2495 while (paste_tabular->columns() > columns)
2496 paste_tabular->DeleteColumn(columns);
2497 paste_tabular->SetLeftLine(0, true, true);
2498 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2502 paste_tabular->ascii(bv->buffer(), sstr,
2503 (int)parOwner()->params().depth(), true, '\t');
2504 bv->stuffClipboard(sstr.str().c_str());
2509 bool InsetTabular::pasteSelection(BufferView * bv)
2514 for (int r1 = 0, r2 = actrow;
2515 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2517 for(int c1 = 0, c2 = actcol;
2518 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2520 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2521 tabular->IsPartOfMultiColumn(r2,c2))
2523 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2527 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2531 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2532 int const n2 = tabular->GetCellNumber(r2, c2);
2533 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2534 tabular->GetCellInset(n2)->setOwner(this);
2535 tabular->GetCellInset(n2)->deleteLyXText(bv);
2542 bool InsetTabular::cutSelection()
2544 if (!hasSelection())
2547 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2548 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2549 if (sel_col_start > sel_col_end) {
2550 sel_col_start = sel_col_end;
2551 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2553 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2555 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2556 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2557 if (sel_row_start > sel_row_end) {
2558 swap(sel_row_start, sel_row_end);
2560 if (sel_cell_start > sel_cell_end) {
2561 swap(sel_cell_start, sel_cell_end);
2563 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2564 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2565 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2572 bool InsetTabular::isRightToLeft(BufferView * bv)
2574 return bv->getParentLanguage(this)->RightToLeft();
2578 bool InsetTabular::nodraw() const
2580 if (!UpdatableInset::nodraw() && the_locking_inset)
2581 return the_locking_inset->nodraw();
2582 return UpdatableInset::nodraw();
2586 int InsetTabular::scroll(bool recursive) const
2588 int sx = UpdatableInset::scroll(false);
2590 if (recursive && the_locking_inset)
2591 sx += the_locking_inset->scroll(recursive);
2597 bool InsetTabular::doClearArea() const
2599 return !locked || (need_update & (FULL|INIT));
2603 void InsetTabular::getSelection(int & srow, int & erow,
2604 int & scol, int & ecol) const
2606 int const start = hasSelection() ? sel_cell_start : actcell;
2607 int const end = hasSelection() ? sel_cell_end : actcell;
2609 srow = tabular->row_of_cell(start);
2610 erow = tabular->row_of_cell(end);
2615 scol = tabular->column_of_cell(start);
2616 ecol = tabular->column_of_cell(end);
2620 ecol = tabular->right_column_of_cell(end);
2625 Paragraph * InsetTabular::getParFromID(int id) const
2628 for(int i = 0; i < tabular->rows(); ++i) {
2629 for(int j = 0; j < tabular->columns(); ++j) {
2630 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2638 Paragraph * InsetTabular::firstParagraph() const
2640 if (the_locking_inset)
2641 return the_locking_inset->firstParagraph();
2646 Paragraph * InsetTabular::getFirstParagraph(int i) const
2648 return (i < tabular->GetNumberOfCells())
2649 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2654 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2656 if (the_locking_inset)
2657 return the_locking_inset->cursor(bv);
2658 return Inset::cursor(bv);
2662 Inset * InsetTabular::getInsetFromID(int id_arg) const
2665 return const_cast<InsetTabular *>(this);
2668 for(int i = 0; i < tabular->rows(); ++i) {
2669 for(int j = 0; j < tabular->columns(); ++j) {
2670 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2679 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2682 if (the_locking_inset) {
2683 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2688 if (tabular->IsLastCell(actcell)) {
2689 bv->unlockInset(const_cast<InsetTabular *>(this));
2695 // otherwise we have to lock the next inset and ask for it's selecttion
2696 UpdatableInset * inset =
2697 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2698 inset->edit(bv, 0, 0, 0);
2699 string const str(selectNextWordInt(bv, value));
2707 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2709 // when entering this function the inset should be ALWAYS locked!
2710 lyx::Assert(the_locking_inset);
2712 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2716 if (tabular->IsLastCell(actcell)) {
2717 bv->unlockInset(const_cast<InsetTabular *>(this));
2721 // otherwise we have to lock the next inset and ask for it's selecttion
2722 UpdatableInset * inset =
2723 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2725 return selectNextWordInt(bv, value);
2729 void InsetTabular::selectSelectedWord(BufferView * bv)
2731 if (the_locking_inset) {
2732 the_locking_inset->selectSelectedWord(bv);
2739 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2741 if (the_locking_inset) {
2742 the_locking_inset->toggleSelection(bv, kill_selection);
2747 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2751 if (the_locking_inset) {
2752 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2754 updateLocal(bv, CELL, false);
2757 if (tabular->IsLastCell(actcell)) {
2759 bv->unlockInset(const_cast<InsetTabular *>(this));
2764 // otherwise we have to lock the next inset and search there
2765 UpdatableInset * inset =
2766 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2768 bool const ret = searchForward(bv, str, cs, mw);
2770 updateLocal(bv, CELL, false);
2775 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2779 if (the_locking_inset) {
2780 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2782 updateLocal(bv, CELL, false);
2785 if (!actcell) { // we are already in the first cell
2787 bv->unlockInset(const_cast<InsetTabular *>(this));
2792 // otherwise we have to lock the next inset and search there
2793 UpdatableInset * inset =
2794 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2795 inset->edit(bv, false);
2796 bool const ret = searchBackward(bv, str, cs, mw);
2798 updateLocal(bv, CELL, false);
2803 bool InsetTabular::insetAllowed(Inset::Code code) const
2805 if (the_locking_inset)
2806 return the_locking_inset->insetAllowed(code);
2807 // we return true here because if the inset is not locked someone
2808 // wants to insert something in one of our insettexts and we generally
2814 bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
2816 const int cell = tabular->GetCellFromInset(in, actcell);
2819 return tabular->GetPWidth(cell).zero();
2821 // well we didn't obviously find it so maybe our owner knows more
2823 return owner()->forceDefaultParagraphs(in);
2824 // if we're here there is really something strange going on!!!
2828 bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
2831 if (buf.length() <= 0)
2837 string::size_type len = buf.length();
2838 string::size_type p = 0;
2841 ((p = buf.find_first_of("\t\n", p)) != string::npos))
2850 maxCols = max(cols, maxCols);
2856 maxCols = max(cols, maxCols);
2857 LyXTabular * loctab;
2862 delete paste_tabular;
2863 paste_tabular = new LyXTabular(bv->buffer()->params,
2864 this, rows, maxCols);
2865 loctab = paste_tabular;
2868 loctab = tabular.get();
2873 string::size_type op = 0;
2874 int cells = loctab->GetNumberOfCells();
2877 rows = loctab->rows();
2878 int const columns = loctab->columns();
2879 while ((cell < cells) && (p < len) && (row < rows) &&
2880 (p = buf.find_first_of("\t\n", p)) != string::npos)
2886 // we can only set this if we are not too far right
2887 if (cols < columns) {
2888 InsetText * ti = loctab->GetCellInset(cell);
2889 LyXFont const font = ti->getLyXText(bv)->
2890 getFont(bv->buffer(), ti->paragraph(), 0);
2891 ti->setText(buf.substr(op, p-op), font);
2897 // we can only set this if we are not too far right
2898 if (cols < columns) {
2899 InsetText * ti = loctab->GetCellInset(cell);
2900 LyXFont const font = ti->getLyXText(bv)->
2901 getFont(bv->buffer(), ti->paragraph(), 0);
2902 ti->setText(buf.substr(op, p-op), font);
2907 cell = loctab->GetCellNumber(row, cols);
2913 // check for the last cell if there is no trailing '\n'
2914 if ((cell < cells) && (op < len)) {
2915 InsetText * ti = loctab->GetCellInset(cell);
2916 LyXFont const font = ti->getLyXText(bv)->
2917 getFont(bv->buffer(), ti->paragraph(), 0);
2918 ti->setText(buf.substr(op, len-op), font);