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"
20 #include "commandtags.h"
23 #include "LaTeXFeatures.h"
27 #include "lyx_gui_misc.h"
29 #include "insets/insettext.h"
34 #include "BufferView.h"
35 #include "undo_funcs.h"
36 #include "lyxlength.h"
37 #include "ParagraphParameters.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/Alert.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
60 int const ADD_TO_HEIGHT = 2;
61 int const ADD_TO_TABULAR_WIDTH = 2;
64 LyXTabular * paste_tabular = 0;
67 struct TabularFeature {
68 LyXTabular::Feature action;
73 TabularFeature tabularFeature[] =
75 { LyXTabular::APPEND_ROW, "append-row" },
76 { LyXTabular::APPEND_COLUMN, "append-column" },
77 { LyXTabular::DELETE_ROW, "delete-row" },
78 { LyXTabular::DELETE_COLUMN, "delete-column" },
79 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
80 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
81 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
82 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
83 { LyXTabular::ALIGN_LEFT, "align-left" },
84 { LyXTabular::ALIGN_RIGHT, "align-right" },
85 { LyXTabular::ALIGN_CENTER, "align-center" },
86 { LyXTabular::VALIGN_TOP, "valign-top" },
87 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
88 { LyXTabular::VALIGN_CENTER, "valign-center" },
89 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
90 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
91 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
92 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
93 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
94 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
95 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
96 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
97 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
98 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
99 { LyXTabular::MULTICOLUMN, "multicolumn" },
100 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
101 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
102 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
103 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
104 { LyXTabular::SET_PWIDTH, "set-pwidth" },
105 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
106 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
107 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
108 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
109 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
110 { LyXTabular::SET_USEBOX, "set-usebox" },
111 { LyXTabular::SET_LTHEAD, "set-lthead" },
112 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
113 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
114 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
115 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
116 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
117 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
118 { LyXTabular::LAST_ACTION, "" }
124 bool InsetTabular::hasPasteBuffer() const
126 return (paste_tabular != 0);
130 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
137 tabular.reset(new LyXTabular(this, rows, columns));
138 // for now make it always display as display() inset
140 the_locking_inset = 0;
143 actrow = actcell = 0;
147 in_reset_pos = false;
151 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
153 : UpdatableInset(tab, same_id), buffer(&buf)
155 tabular.reset(new LyXTabular(this, *(tab.tabular), same_id));
156 the_locking_inset = 0;
159 actrow = actcell = 0;
163 in_reset_pos = false;
167 InsetTabular::~InsetTabular()
173 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
175 return new InsetTabular(*this, buf, same_id);
179 void InsetTabular::write(Buffer const * buf, ostream & os) const
181 os << " Tabular" << endl;
182 tabular->Write(buf, os);
186 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
188 bool const old_format = (lex.getString() == "\\LyXTable");
190 tabular.reset(new LyXTabular(buf, this, lex));
198 string token = lex.getString();
199 while (lex.isOK() && (token != "\\end_inset")) {
201 token = lex.getString();
203 if (token != "\\end_inset") {
204 lex.printError("Missing \\end_inset at this point. "
210 int InsetTabular::ascent(BufferView *, LyXFont const &) const
212 return tabular->GetAscentOfRow(0);
216 int InsetTabular::descent(BufferView *, LyXFont const &) const
218 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
222 int InsetTabular::width(BufferView *, LyXFont const &) const
224 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
228 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
229 float & x, bool cleared) const
237 if (need_update == INIT) {
238 if (calculate_dimensions_of_cells(bv, font, true))
239 bv->text->status = LyXText::CHANGED_IN_DRAW;
244 Painter & pain = bv->painter();
250 UpdatableInset::draw(bv, font, baseline, x, cleared);
253 x += static_cast<float>(scroll());
255 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
256 (top_x != int(x)) || (top_baseline != baseline)))
258 int h = ascent(bv, font) + descent(bv, font);
259 int const tx = display() || !owner() ? 0 : top_x;
260 int w = tx ? width(bv, font) : pain.paperWidth();
261 int ty = baseline - ascent(bv, font);
265 if ((ty + h) > pain.paperHeight())
266 h = pain.paperHeight();
267 if ((top_x + w) > pain.paperWidth())
268 w = pain.paperWidth();
269 pain.fillRectangle(tx, ty, w, h, backgroundColor());
275 top_baseline = baseline;
276 x += ADD_TO_TABULAR_WIDTH;
280 first_visible_cell = -1;
281 for (i = 0; i < tabular->rows(); ++i) {
283 cell = tabular->GetCellNumber(i, 0);
284 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
285 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
287 baseline += tabular->GetDescentOfRow(i) +
288 tabular->GetAscentOfRow(i + 1) +
289 tabular->GetAdditionalHeight(i + 1);
292 for (j = 0; j < tabular->columns(); ++j) {
293 if (nx > bv->workWidth())
295 if (tabular->IsPartOfMultiColumn(i, j))
297 cx = nx + tabular->GetBeginningOfTextInCell(cell);
298 if (first_visible_cell < 0)
299 first_visible_cell = cell;
300 if (hasSelection()) {
301 drawCellSelection(pain, nx, baseline, i, j, cell);
304 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, cleared);
305 drawCellLines(pain, nx, baseline, i, cell);
306 nx += tabular->GetWidthOfColumn(cell);
309 baseline += tabular->GetDescentOfRow(i) +
310 tabular->GetAscentOfRow(i + 1) +
311 tabular->GetAdditionalHeight(i + 1);
313 } else if (need_update == CELL) {
316 if (the_locking_inset &&
317 tabular->GetCellInset(actcell) != the_locking_inset)
319 Inset * inset = tabular->GetCellInset(cell);
321 inset != the_locking_inset && i < tabular->rows();
325 inset != the_locking_inset && j < tabular->columns();
328 if (tabular->IsPartOfMultiColumn(i, j))
330 nx += tabular->GetWidthOfColumn(cell);
332 inset = tabular->GetCellInset(cell);
334 if (tabular->row_of_cell(cell) > i) {
336 baseline += tabular->GetDescentOfRow(i) +
337 tabular->GetAscentOfRow(i + 1) +
338 tabular->GetAdditionalHeight(i + 1);
342 // compute baseline for actual row
343 for (i = 0; i < actrow; ++i) {
344 baseline += tabular->GetDescentOfRow(i) +
345 tabular->GetAscentOfRow(i + 1) +
346 tabular->GetAdditionalHeight(i + 1);
348 // now compute the right x position
349 cell = tabular->GetCellNumber(actrow, 0);
350 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
351 if (tabular->IsPartOfMultiColumn(actrow, j))
353 nx += tabular->GetWidthOfColumn(cell);
357 i = tabular->row_of_cell(cell);
358 if (the_locking_inset != tabular->GetCellInset(cell)) {
359 lyxerr[Debug::INSETTEXT] << "ERROR this shouldn't happen\n";
362 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
364 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
366 // Here we use rectangular backgroundColor patches to clean up
367 // within a cell around the cell's red inset box. As follows:
370 // | | | | The rectangles are A, B and C
371 // | A |------------| B | below, origin top left (tx, ty),
372 // | | inset box | | dimensions w(idth), h(eight).
373 // +---+------------+---+ x grows rightward, y downward
375 // +--------------------+
377 // clear only if we didn't have a change
378 if (bv->text->status() != LyXText::CHANGED_IN_DRAW) {
379 // clear before the inset
382 ty = baseline - tabular->GetAscentOfRow(i) + 1;
383 w = int(cx - nx - 1);
384 h = tabular->GetAscentOfRow(i) +
385 tabular->GetDescentOfRow(i) - 1;
386 pain.fillRectangle(tx, ty, w, h, backgroundColor());
387 // clear behind the inset
388 tx = int(cx + the_locking_inset->width(bv,font) + 1);
389 ty = baseline - tabular->GetAscentOfRow(i) + 1;
390 w = tabular->GetWidthOfColumn(cell) -
391 tabular->GetBeginningOfTextInCell(cell) -
392 the_locking_inset->width(bv,font) -
393 tabular->GetAdditionalWidth(cell) - 1;
394 h = tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1;
395 pain.fillRectangle(tx, ty, w, h, backgroundColor());
396 // clear below the inset
398 ty = baseline + the_locking_inset->descent(bv, font) + 1;
399 w = tabular->GetWidthOfColumn(cell) -
400 tabular->GetAdditionalWidth(cell) - 1;
401 h = tabular->GetDescentOfRow(i) -
402 the_locking_inset->descent(bv, font) - 1;
403 pain.fillRectangle(tx, ty, w, h, backgroundColor());
406 x -= ADD_TO_TABULAR_WIDTH;
407 x += width(bv, font);
408 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
410 for(Inset * inset = owner(); inset; ++i)
411 inset = inset->owner();
412 if (calculate_dimensions_of_cells(bv, font, false))
420 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
421 int row, int cell) const
423 int x2 = x + tabular->GetWidthOfColumn(cell);
426 if (!tabular->TopAlreadyDrawed(cell)) {
427 on_off = !tabular->TopLine(cell);
428 pain.line(x, baseline - tabular->GetAscentOfRow(row),
429 x2, baseline - tabular->GetAscentOfRow(row),
430 on_off ? LColor::tabularonoffline : LColor::tabularline,
431 on_off ? Painter::line_onoffdash : Painter::line_solid);
433 on_off = !tabular->BottomLine(cell);
434 pain.line(x,baseline + tabular->GetDescentOfRow(row),
435 x2, baseline + tabular->GetDescentOfRow(row),
436 on_off ? LColor::tabularonoffline : LColor::tabularline,
437 on_off ? Painter::line_onoffdash : Painter::line_solid);
438 if (!tabular->LeftAlreadyDrawed(cell)) {
439 on_off = !tabular->LeftLine(cell);
440 pain.line(x, baseline - tabular->GetAscentOfRow(row),
441 x, baseline + tabular->GetDescentOfRow(row),
442 on_off ? LColor::tabularonoffline : LColor::tabularline,
443 on_off ? Painter::line_onoffdash : Painter::line_solid);
445 on_off = !tabular->RightLine(cell);
446 pain.line(x2 - tabular->GetAdditionalWidth(cell),
447 baseline - tabular->GetAscentOfRow(row),
448 x2 - tabular->GetAdditionalWidth(cell),
449 baseline + tabular->GetDescentOfRow(row),
450 on_off ? LColor::tabularonoffline : LColor::tabularline,
451 on_off ? Painter::line_onoffdash : Painter::line_solid);
455 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
456 int row, int column, int cell) const
458 lyx::Assert(hasSelection());
459 int cs = tabular->column_of_cell(sel_cell_start);
460 int ce = tabular->column_of_cell(sel_cell_end);
463 cs = tabular->column_of_cell(sel_cell_end);
465 ce = tabular->right_column_of_cell(sel_cell_end);
468 int rs = tabular->row_of_cell(sel_cell_start);
469 int re = tabular->row_of_cell(sel_cell_end);
473 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
474 int w = tabular->GetWidthOfColumn(cell);
475 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
476 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
477 w, h, LColor::selection);
482 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
488 owner()->update(bv, font, true);
495 if (calculate_dimensions_of_cells(bv, font, true))
498 owner()->update(bv, font, true);
502 if (the_locking_inset)
503 the_locking_inset->update(bv, font, reinit);
504 if (need_update < FULL &&
505 bv->text->status() == LyXText::NEED_MORE_REFRESH)
510 switch (need_update) {
514 if (calculate_dimensions_of_cells(bv, font, false))
527 string const InsetTabular::editMessage() const
529 return _("Opened Tabular Inset");
533 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
535 UpdatableInset::edit(bv, x, y, button);
537 if (!bv->lockInset(this)) {
538 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
542 the_locking_inset = 0;
548 if (insetHit(bv, x, y) && (button != 3)) {
549 activateCellInsetAbs(bv, x, y, button);
554 void InsetTabular::edit(BufferView * bv, bool front)
556 UpdatableInset::edit(bv, front);
558 if (!bv->lockInset(this)) {
559 lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
563 the_locking_inset = 0;
569 actcell = tabular->GetNumberOfCells() - 1;
576 void InsetTabular::insetUnlock(BufferView * bv)
578 if (the_locking_inset) {
579 the_locking_inset->insetUnlock(bv);
580 the_locking_inset = 0;
585 if (scroll(false) || hasSelection()) {
590 updateLocal(bv, FULL, false);
595 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
596 bool mark_dirty) const
600 calculate_dimensions_of_cells(bv, font, true);
602 if (need_update < what) // only set this if it has greater update
604 if ((what == INIT) && hasSelection()) {
608 if (need_update != NONE) {
609 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
610 if (locked) // && (what != NONE))
616 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
618 lyxerr[Debug::INSETTEXT] << "InsetTabular::LockInsetInInset("
623 if (inset == tabular->GetCellInset(actcell)) {
624 lyxerr[Debug::INSETTEXT] << "OK" << endl;
625 the_locking_inset = tabular->GetCellInset(actcell);
628 } else if (!the_locking_inset) {
629 int const n = tabular->GetNumberOfCells();
630 int const id = inset->id();
631 for (int i = 0; i < n; ++i) {
632 InsetText * in = tabular->GetCellInset(i);
635 the_locking_inset = in;
640 if (in->getInsetFromID(id)) {
642 the_locking_inset = in;
645 return the_locking_inset->lockInsetInInset(bv, inset);
648 } else if (the_locking_inset && (the_locking_inset == inset)) {
649 lyxerr[Debug::INSETTEXT] << "OK" << endl;
651 } else if (the_locking_inset) {
652 lyxerr[Debug::INSETTEXT] << "MAYBE" << endl;
653 return the_locking_inset->lockInsetInInset(bv, inset);
655 lyxerr[Debug::INSETTEXT] << "NOT OK" << endl;
660 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
663 if (!the_locking_inset)
665 if (the_locking_inset == inset) {
666 the_locking_inset->insetUnlock(bv);
667 the_locking_inset = 0;
669 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
675 updateLocal(bv, CELL, false);
676 showInsetCursor(bv, false);
679 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
680 if (inset->lyxCode() == TABULAR_CODE &&
681 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
682 bv->owner()->getDialogs()->updateTabular(this);
691 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
693 if (!the_locking_inset)
695 if (the_locking_inset != inset) {
696 if (!the_locking_inset->updateInsetInInset(bv, inset))
699 updateLocal(bv, CELL, false);
704 unsigned int InsetTabular::insetInInsetY()
706 if (!the_locking_inset)
708 return inset_y + the_locking_inset->insetInInsetY();
712 UpdatableInset * InsetTabular::getLockingInset() const
714 return the_locking_inset ? the_locking_inset->getLockingInset() :
715 const_cast<InsetTabular *>(this);
719 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
723 if (the_locking_inset)
724 return the_locking_inset->getFirstLockingInsetOfType(c);
729 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
731 if (the_locking_inset)
732 return the_locking_inset->insertInset(bv, inset);
737 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
739 if (hasSelection() && (button == 3))
742 if (hasSelection()) {
744 updateLocal(bv, SELECTION, false);
747 int const ocell = actcell;
748 int const orow = actrow;
753 updateLocal(bv, NONE, false);
757 if ((ocell != actcell) && the_locking_inset) {
758 the_locking_inset->insetUnlock(bv);
759 the_locking_inset = 0;
766 bool const inset_hit = insetHit(bv, x, y);
768 if ((ocell == actcell) && the_locking_inset && inset_hit) {
770 the_locking_inset->insetButtonPress(bv,
771 x - inset_x, y - inset_y,
774 } else if (the_locking_inset) {
775 the_locking_inset->insetUnlock(bv);
777 the_locking_inset = 0;
779 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
782 if (inset_hit && bv->theLockingInset()) {
783 if (activateCellInsetAbs(bv, x, y, button))
784 the_locking_inset->insetButtonPress(bv,
794 bool InsetTabular::insetButtonRelease(BufferView * bv,
795 int x, int y, int button)
798 if (the_locking_inset)
799 ret = the_locking_inset->insetButtonRelease(bv, x, y, button);
800 if (button == 3 && !ret) {
801 bv->owner()->getDialogs()->showTabular(this);
808 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
810 if (the_locking_inset) {
811 the_locking_inset->insetMotionNotify(bv,
819 // int const old_cell = actcell;
822 if (!hasSelection()) {
823 setSelection(actcell, actcell);
825 setSelection(sel_cell_start, actcell);
827 updateLocal(bv, SELECTION, false);
832 void InsetTabular::insetKeyPress(XKeyEvent * xke)
834 if (the_locking_inset) {
835 the_locking_inset->insetKeyPress(xke);
841 UpdatableInset::RESULT
842 InsetTabular::localDispatch(BufferView * bv, kb_action action,
845 // We need to save the value of the_locking_inset as the call to
846 // the_locking_inset->LocalDispatch might unlock it.
847 old_locking_inset = the_locking_inset;
848 UpdatableInset::RESULT result =
849 UpdatableInset::localDispatch(bv, action, arg);
850 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
855 if ((action < 0) && arg.empty())
858 bool hs = hasSelection();
861 // this one have priority over the locked InsetText, if we're not already
862 // inside another tabular then that one get's priority!
863 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
868 unlockInsetInInset(bv, the_locking_inset);
869 if (action == LFUN_TAB)
870 moveNextCell(bv, old_locking_inset != 0);
872 movePrevCell(bv, old_locking_inset != 0);
875 updateLocal(bv, SELECTION, false);
876 if (!the_locking_inset) {
878 return DISPATCHED_NOUPDATE;
881 // this to avoid compiler warnings.
887 if (the_locking_inset) {
888 result = the_locking_inset->localDispatch(bv, action, arg);
889 if (result == DISPATCHED_NOUPDATE) {
892 if (sc != scroll()) { // inset has been scrolled
893 the_locking_inset->toggleInsetCursor(bv);
894 updateLocal(bv, FULL, false);
895 the_locking_inset->toggleInsetCursor(bv);
898 } else if (result == DISPATCHED) {
899 the_locking_inset->toggleInsetCursor(bv);
900 updateLocal(bv, CELL, false);
901 the_locking_inset->toggleInsetCursor(bv);
903 } else if (result == FINISHED_UP) {
905 } else if (result == FINISHED_DOWN) {
907 } else if (result == FINISHED_RIGHT) {
915 // --- Cursor Movements ----------------------------------
916 case LFUN_RIGHTSEL: {
917 int const start = hasSelection() ? sel_cell_start : actcell;
918 if (tabular->IsLastCellInRow(actcell)) {
919 setSelection(start, actcell);
924 // if we are starting a selection, only select
925 // the current cell at the beginning
926 if (hasSelection()) {
927 moveRight(bv, false);
930 setSelection(start, end);
931 updateLocal(bv, SELECTION, false);
935 result = moveRight(bv);
938 updateLocal(bv, SELECTION, false);
941 int const start = hasSelection() ? sel_cell_start : actcell;
942 if (tabular->IsFirstCellInRow(actcell)) {
943 setSelection(start, actcell);
948 // if we are starting a selection, only select
949 // the current cell at the beginning
950 if (hasSelection()) {
954 setSelection(start, end);
955 updateLocal(bv, SELECTION, false);
959 result = moveLeft(bv);
962 updateLocal(bv, SELECTION, false);
965 int const start = hasSelection() ? sel_cell_start : actcell;
966 int const ocell = actcell;
967 // if we are starting a selection, only select
968 // the current cell at the beginning
969 if (hasSelection()) {
971 if ((ocell == sel_cell_end) ||
972 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
973 setSelection(start, tabular->GetCellBelow(sel_cell_end));
975 setSelection(start, tabular->GetLastCellBelow(sel_cell_end));
977 setSelection(start, start);
979 updateLocal(bv, SELECTION, false);
983 result = moveDown(bv, old_locking_inset != 0);
986 updateLocal(bv, SELECTION, false);
990 int const start = hasSelection() ? sel_cell_start : actcell;
991 int const ocell = actcell;
992 // if we are starting a selection, only select
993 // the current cell at the beginning
994 if (hasSelection()) {
996 if ((ocell == sel_cell_end) ||
997 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
998 setSelection(start, tabular->GetCellAbove(sel_cell_end));
1000 setSelection(start, tabular->GetLastCellAbove(sel_cell_end));
1002 setSelection(start, start);
1004 updateLocal(bv, SELECTION, false);
1008 result = moveUp(bv, old_locking_inset != 0);
1011 updateLocal(bv, SELECTION, false);
1014 int column = actcol;
1015 unlockInsetInInset(bv, the_locking_inset);
1016 if (bv->text->first + bv->painter().paperHeight() <
1017 (top_baseline + tabular->GetHeightOfTabular()))
1019 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
1020 updateLocal(bv, FULL, false);
1021 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1023 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
1026 updateLocal(bv, CURSOR, false);
1030 int column = actcol;
1031 unlockInsetInInset(bv, the_locking_inset);
1032 if (top_baseline < 0) {
1033 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
1034 updateLocal(bv, FULL, false);
1035 if (top_baseline > 0)
1038 actcell = tabular->GetCellBelow(first_visible_cell) + column;
1043 updateLocal(bv, CURSOR, false);
1046 // none of these make sense for insettabular,
1047 // but we must catch them to prevent any
1048 // selection from being confused
1052 case LFUN_WORDLEFTSEL:
1053 case LFUN_WORDRIGHT:
1054 case LFUN_WORDRIGHTSEL:
1055 case LFUN_DOWN_PARAGRAPH:
1056 case LFUN_DOWN_PARAGRAPHSEL:
1057 case LFUN_UP_PARAGRAPH:
1058 case LFUN_UP_PARAGRAPHSEL:
1059 case LFUN_BACKSPACE:
1066 case LFUN_LAYOUT_TABULAR:
1067 bv->owner()->getDialogs()->showTabular(this);
1069 case LFUN_TABULAR_FEATURE:
1070 if (!tabularFeatures(bv, arg))
1071 result = UNDISPATCHED;
1074 if (!copySelection(bv))
1076 setUndo(bv, Undo::DELETE,
1077 bv->text->cursor.par(),
1078 bv->text->cursor.par()->next());
1080 updateLocal(bv, INIT, true);
1083 if (!hasSelection())
1088 case LFUN_PASTESELECTION:
1090 string const clip(bv->getClipboard());
1094 if (clip.find('\t') != string::npos) {
1098 string::size_type len = clip.length();
1099 string::size_type p = 0;
1102 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1110 maxCols = max(cols, maxCols);
1116 maxCols = max(cols, maxCols);
1117 delete paste_tabular;
1118 paste_tabular = new LyXTabular(this, rows, maxCols);
1119 string::size_type op = 0;
1121 int cells = paste_tabular->GetNumberOfCells();
1123 while ((cell < cells) && (p < len) &&
1124 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1129 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1134 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1135 while (cols++ < maxCols)
1143 // check for the last cell if there is no trailing '\n'
1144 if ((cell < cells) && (op < len))
1145 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1147 // so that the clipboard is used and it goes on
1149 // and executes LFUN_PASTESELECTION in insettext!
1150 delete paste_tabular;
1155 if (hasPasteBuffer()) {
1156 setUndo(bv, Undo::INSERT,
1157 bv->text->cursor.par(),
1158 bv->text->cursor.par()->next());
1160 updateLocal(bv, INIT, true);
1163 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1165 // we try to activate the actual inset and put this event down to
1166 // the insets dispatch function.
1167 result = UNDISPATCHED;
1168 if (the_locking_inset)
1171 if (activateCellInset(bv)) {
1172 // reset need_update setted in above function!
1174 result = the_locking_inset->localDispatch(bv, action, arg);
1175 if ((result == UNDISPATCHED) || (result >= FINISHED)) {
1176 unlockInsetInInset(bv, the_locking_inset);
1178 // we need to update if this was requested before
1179 updateLocal(bv, NONE, false);
1180 return UNDISPATCHED;
1185 updateLocal(bv, CELL, false);
1190 if (result < FINISHED) {
1191 if (!the_locking_inset) {
1192 showInsetCursor(bv);
1195 bv->unlockInset(this);
1200 int InsetTabular::latex(Buffer const * buf, ostream & os,
1201 bool fragile, bool fp) const
1203 return tabular->latex(buf, os, fragile, fp);
1207 int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
1210 return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
1212 return tabular->ascii(buf, os, 0, false,0);
1216 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
1218 return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
1222 int InsetTabular::docbook(Buffer const * buf, ostream & os) const
1227 // if the table is inside a float it doesn't need the informaltable
1228 // wrapper. Search for it.
1229 for(master = owner();
1230 master && master->lyxCode() != Inset::FLOAT_CODE;
1231 master = master->owner());
1234 os << "<informaltable>\n";
1237 ret+= tabular->docBook(buf,os);
1239 os << "</informaltable>\n";
1246 void InsetTabular::validate(LaTeXFeatures & features) const
1248 tabular->Validate(features);
1252 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1253 LyXFont const & font,
1260 bool changed = false;
1262 // if we have a locking_inset we should have to check only this cell for
1263 // change so I'll try this to have a boost, but who knows ;)
1264 if ((need_update != INIT) &&
1265 (the_locking_inset == tabular->GetCellInset(actcell))) {
1266 for(int i = 0; i < tabular->columns(); ++i) {
1267 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1269 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1272 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1273 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1274 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1277 for (int i = 0; i < tabular->rows(); ++i) {
1280 for (int j = 0; j < tabular->columns(); ++j) {
1281 if (tabular->IsPartOfMultiColumn(i,j))
1284 inset = tabular->GetCellInset(cell);
1285 if (!reinit && !tabular->GetPWidth(cell).zero())
1286 inset->update(bv, font, false);
1287 maxAsc = max(maxAsc, inset->ascent(bv, font));
1288 maxDesc = max(maxDesc, inset->descent(bv, font));
1289 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1291 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1292 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1300 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1302 if (the_locking_inset) {
1303 the_locking_inset->getCursorPos(bv, x, y);
1306 x = cursor_.x() - top_x;
1311 void InsetTabular::toggleInsetCursor(BufferView * bv)
1314 if (isCursorVisible())
1315 bv->hideLockedInsetCursor();
1318 if (the_locking_inset) {
1319 the_locking_inset->toggleInsetCursor(bv);
1323 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1325 int const asc = lyxfont::maxAscent(font);
1326 int const desc = lyxfont::maxDescent(font);
1328 if (isCursorVisible())
1329 bv->hideLockedInsetCursor();
1331 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1332 toggleCursorVisible();
1336 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1340 if (!isCursorVisible()) {
1341 LyXFont font; // = GetFont(par, cursor.pos);
1343 int const asc = lyxfont::maxAscent(font);
1344 int const desc = lyxfont::maxDescent(font);
1345 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1347 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1348 setCursorVisible(true);
1353 void InsetTabular::hideInsetCursor(BufferView * bv)
1355 if (isCursorVisible()) {
1356 bv->hideLockedInsetCursor();
1357 setCursorVisible(false);
1362 void InsetTabular::fitInsetCursor(BufferView * bv) const
1364 if (the_locking_inset) {
1365 the_locking_inset->fitInsetCursor(bv);
1370 int const asc = lyxfont::maxAscent(font);
1371 int const desc = lyxfont::maxDescent(font);
1372 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1376 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1380 actcell = actrow = actcol = 0;
1381 int ly = tabular->GetDescentOfRow(actrow);
1383 // first search the right row
1384 while ((ly < y) && ((actrow+1) < tabular->rows())) {
1385 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1386 tabular->GetAscentOfRow(actrow + 1) +
1387 tabular->GetAdditionalHeight(actrow + 1));
1389 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1391 actcell = tabular->GetCellNumber(actrow, actcol);
1393 // now search the right column
1394 int lx = tabular->GetWidthOfColumn(actcell) -
1395 tabular->GetAdditionalWidth(actcell);
1396 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1397 lx += tabular->GetWidthOfColumn(actcell + 1)
1398 + tabular->GetAdditionalWidth(actcell);
1400 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1405 int InsetTabular::getCellXPos(int cell) const
1409 for (; !tabular->IsFirstCellInRow(c); --c)
1411 int lx = tabular->GetWidthOfColumn(cell);
1412 for (; c < cell; ++c) {
1413 lx += tabular->GetWidthOfColumn(c);
1415 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1419 void InsetTabular::resetPos(BufferView * bv) const
1421 #warning This should be fixed in the right manner (20011128 Jug)
1422 // fast hack to fix infinite repaintings!
1427 actcol = tabular->column_of_cell(actcell);
1430 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1431 if (tabular->IsLastCellInRow(cell)) {
1432 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1433 tabular->GetAscentOfRow(actrow + 1) +
1434 tabular->GetAdditionalHeight(actrow + 1));
1438 if (!locked || nodraw()) {
1439 if (the_locking_inset)
1440 inset_y = cursor_.y();
1443 // we need this only from here on!!!
1444 in_reset_pos = true;
1445 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1446 int new_x = getCellXPos(actcell);
1447 int old_x = cursor_.x();
1450 // cursor.x(getCellXPos(actcell) + offset);
1451 if ((actcol < tabular->columns()-1) && scroll(false) &&
1452 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1455 updateLocal(bv, FULL, false);
1456 } else if (the_locking_inset &&
1457 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1459 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1460 if (xx > (bv->workWidth()-20)) {
1461 scroll(bv, -(xx - bv->workWidth() + 60));
1462 updateLocal(bv, FULL, false);
1463 } else if (xx < 20) {
1469 updateLocal(bv, FULL, false);
1471 } else if ((cursor_.x() - offset) > 20 &&
1472 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1473 > (bv->workWidth() - 20)) {
1474 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1475 updateLocal(bv, FULL, false);
1476 } else if ((cursor_.x() - offset) < 20) {
1477 scroll(bv, 20 - cursor_.x() + offset);
1478 updateLocal(bv, FULL, false);
1479 } else if (scroll(false) && top_x > 20 &&
1480 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1481 scroll(bv, old_x - cursor_.x());
1482 updateLocal(bv, FULL, false);
1484 if (the_locking_inset) {
1485 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1486 inset_y = cursor_.y();
1488 if ((!the_locking_inset ||
1489 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1490 actcell != oldcell) {
1491 InsetTabular * inset = const_cast<InsetTabular *>(this);
1492 bv->owner()->getDialogs()->updateTabular(inset);
1495 in_reset_pos = false;
1499 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1501 if (lock && !old_locking_inset) {
1502 if (activateCellInset(bv))
1505 bool moved = isRightToLeft(bv)
1506 ? movePrevCell(bv) : moveNextCell(bv);
1508 return FINISHED_RIGHT;
1509 if (lock && activateCellInset(bv))
1513 return DISPATCHED_NOUPDATE;
1517 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1519 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1522 if (lock) { // behind the inset
1523 if (activateCellInset(bv, 0, 0, 0, true))
1527 return DISPATCHED_NOUPDATE;
1531 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1533 int const ocell = actcell;
1534 actcell = tabular->GetCellAbove(actcell);
1535 if (actcell == ocell) // we moved out of the inset
1541 if (old_locking_inset) {
1542 old_locking_inset->getCursorPos(bv, x, y);
1543 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1545 if (activateCellInset(bv, x, 0))
1548 return DISPATCHED_NOUPDATE;
1552 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1554 int const ocell = actcell;
1555 actcell = tabular->GetCellBelow(actcell);
1556 if (actcell == ocell) // we moved out of the inset
1557 return FINISHED_DOWN;
1562 if (old_locking_inset) {
1563 old_locking_inset->getCursorPos(bv, x, y);
1564 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1566 if (activateCellInset(bv, x, 0))
1569 return DISPATCHED_NOUPDATE;
1573 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1575 if (isRightToLeft(bv)) {
1576 if (tabular->IsFirstCellInRow(actcell)) {
1577 int row = tabular->row_of_cell(actcell);
1578 if (row == tabular->rows() - 1)
1580 actcell = tabular->GetLastCellInRow(row);
1581 actcell = tabular->GetCellBelow(actcell);
1588 if (tabular->IsLastCell(actcell))
1593 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1594 isRightToLeftPar(bv->buffer()->params);
1595 activateCellInset(bv, 0, 0, 0, !rtl);
1602 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1604 if (isRightToLeft(bv)) {
1605 if (tabular->IsLastCellInRow(actcell)) {
1606 int row = tabular->row_of_cell(actcell);
1609 actcell = tabular->GetFirstCellInRow(row);
1610 actcell = tabular->GetCellAbove(actcell);
1612 if (tabular->IsLastCell(actcell))
1617 if (!actcell) // first cell
1622 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1623 isRightToLeftPar(bv->buffer()->params);
1624 activateCellInset(bv, 0, 0, 0, !rtl);
1631 bool InsetTabular::deletable() const
1637 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1641 setSelection(0, tabular->GetNumberOfCells() - 1);
1643 if (hasSelection()) {
1644 setUndo(bv, Undo::EDIT,
1645 bv->text->cursor.par(),
1646 bv->text->cursor.par()->next());
1647 bool frozen = undo_frozen;
1650 // apply the fontchange on the whole selection
1655 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1656 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1657 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1658 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1663 updateLocal(bv, INIT, true);
1665 if (the_locking_inset)
1666 the_locking_inset->setFont(bv, font, tall);
1670 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1672 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1675 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1676 string const tmp = tabularFeature[i].feature;
1678 if (tmp == what.substr(0, tmp.length())) {
1679 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1680 //tabularFeatures[i].feature.length())) {
1681 action = tabularFeature[i].action;
1685 if (action == LyXTabular::LAST_ACTION)
1689 frontStrip(what.substr(tabularFeature[i].feature.length()));
1690 tabularFeatures(bv, action, val);
1694 static void checkLongtableSpecial(LyXTabular::ltType & ltt,
1695 string const & special, bool & flag)
1697 if (special == "dl_above") {
1700 } else if (special == "dl_below") {
1701 ltt.bottomDL = flag;
1703 } else if (special == "empty") {
1713 void InsetTabular::tabularFeatures(BufferView * bv,
1714 LyXTabular::Feature feature,
1715 string const & value)
1721 bool setLines = false;
1722 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1723 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1726 case LyXTabular::M_ALIGN_LEFT:
1727 case LyXTabular::ALIGN_LEFT:
1728 setAlign = LYX_ALIGN_LEFT;
1730 case LyXTabular::M_ALIGN_RIGHT:
1731 case LyXTabular::ALIGN_RIGHT:
1732 setAlign = LYX_ALIGN_RIGHT;
1734 case LyXTabular::M_ALIGN_CENTER:
1735 case LyXTabular::ALIGN_CENTER:
1736 setAlign = LYX_ALIGN_CENTER;
1738 case LyXTabular::M_VALIGN_TOP:
1739 case LyXTabular::VALIGN_TOP:
1740 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1742 case LyXTabular::M_VALIGN_BOTTOM:
1743 case LyXTabular::VALIGN_BOTTOM:
1744 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1746 case LyXTabular::M_VALIGN_CENTER:
1747 case LyXTabular::VALIGN_CENTER:
1748 setVAlign = LyXTabular::LYX_VALIGN_CENTER;
1753 if (hasSelection()) {
1754 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1756 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1757 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1759 setUndo(bv, Undo::FINISH,
1760 bv->text->cursor.par(),
1761 bv->text->cursor.par()->next());
1763 int row = tabular->row_of_cell(actcell);
1764 int column = tabular->column_of_cell(actcell);
1766 LyXTabular::ltType ltt;
1769 case LyXTabular::SET_PWIDTH:
1771 LyXLength const vallen(value);
1772 LyXLength const & tmplen = tabular->GetColumnPWidth(actcell);
1774 bool const update = (tmplen != vallen);
1775 tabular->SetColumnPWidth(actcell, vallen);
1778 for (int i = 0; i < tabular->rows(); ++i) {
1779 cell = tabular->GetCellNumber(i,column);
1780 tabular->GetCellInset(cell)->resizeLyXText(bv);
1782 updateLocal(bv, INIT, true);
1786 case LyXTabular::SET_MPWIDTH:
1788 LyXLength const vallen(value);
1789 LyXLength const & tmplen = tabular->GetPWidth(actcell);
1791 bool const update = (tmplen != vallen);
1792 tabular->SetMColumnPWidth(actcell, vallen);
1794 for (int i = 0; i < tabular->rows(); ++i) {
1795 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1798 updateLocal(bv, INIT, true);
1802 case LyXTabular::SET_SPECIAL_COLUMN:
1803 case LyXTabular::SET_SPECIAL_MULTI:
1804 tabular->SetAlignSpecial(actcell,value,feature);
1805 updateLocal(bv, FULL, true);
1807 case LyXTabular::APPEND_ROW:
1808 // append the row into the tabular
1809 unlockInsetInInset(bv, the_locking_inset);
1810 tabular->AppendRow(actcell);
1811 updateLocal(bv, INIT, true);
1813 case LyXTabular::APPEND_COLUMN:
1814 // append the column into the tabular
1815 unlockInsetInInset(bv, the_locking_inset);
1816 tabular->AppendColumn(actcell);
1817 actcell = tabular->GetCellNumber(row, column);
1818 updateLocal(bv, INIT, true);
1820 case LyXTabular::DELETE_ROW:
1821 unlockInsetInInset(bv, the_locking_inset);
1822 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1823 tabular->DeleteRow(sel_row_start);
1825 if (sel_row_start >= tabular->rows())
1827 actcell = tabular->GetCellNumber(sel_row_start, column);
1829 updateLocal(bv, INIT, true);
1831 case LyXTabular::DELETE_COLUMN:
1832 unlockInsetInInset(bv, the_locking_inset);
1833 for(int i = sel_col_start; i <= sel_col_end; ++i) {
1834 tabular->DeleteColumn(sel_col_start);
1836 if (sel_col_start >= tabular->columns())
1838 actcell = tabular->GetCellNumber(row, sel_col_start);
1840 updateLocal(bv, INIT, true);
1842 case LyXTabular::M_TOGGLE_LINE_TOP:
1844 case LyXTabular::TOGGLE_LINE_TOP:
1846 bool lineSet = !tabular->TopLine(actcell, flag);
1847 for (int i = sel_row_start; i <= sel_row_end; ++i)
1848 for (int j = sel_col_start; j <= sel_col_end; ++j)
1849 tabular->SetTopLine(
1850 tabular->GetCellNumber(i, j),
1852 updateLocal(bv, INIT, true);
1856 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1858 case LyXTabular::TOGGLE_LINE_BOTTOM:
1860 bool lineSet = !tabular->BottomLine(actcell, flag);
1861 for (int i = sel_row_start; i <= sel_row_end; ++i)
1862 for (int j = sel_col_start; j <= sel_col_end; ++j)
1863 tabular->SetBottomLine(
1864 tabular->GetCellNumber(i, j),
1867 updateLocal(bv, INIT, true);
1871 case LyXTabular::M_TOGGLE_LINE_LEFT:
1873 case LyXTabular::TOGGLE_LINE_LEFT:
1875 bool lineSet = !tabular->LeftLine(actcell, flag);
1876 for (int i = sel_row_start; i <= sel_row_end; ++i)
1877 for (int j = sel_col_start; j <= sel_col_end; ++j)
1878 tabular->SetLeftLine(
1879 tabular->GetCellNumber(i,j),
1882 updateLocal(bv, INIT, true);
1886 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1888 case LyXTabular::TOGGLE_LINE_RIGHT:
1890 bool lineSet = !tabular->RightLine(actcell, flag);
1891 for (int i = sel_row_start; i <= sel_row_end; ++i)
1892 for (int j = sel_col_start; j <= sel_col_end; ++j)
1893 tabular->SetRightLine(
1894 tabular->GetCellNumber(i,j),
1897 updateLocal(bv, INIT, true);
1901 case LyXTabular::M_ALIGN_LEFT:
1902 case LyXTabular::M_ALIGN_RIGHT:
1903 case LyXTabular::M_ALIGN_CENTER:
1905 case LyXTabular::ALIGN_LEFT:
1906 case LyXTabular::ALIGN_RIGHT:
1907 case LyXTabular::ALIGN_CENTER:
1908 for (int i = sel_row_start; i <= sel_row_end; ++i)
1909 for (int j = sel_col_start; j <= sel_col_end; ++j)
1910 tabular->SetAlignment(
1911 tabular->GetCellNumber(i, j),
1914 updateLocal(bv, INIT, true);
1916 case LyXTabular::M_VALIGN_TOP:
1917 case LyXTabular::M_VALIGN_BOTTOM:
1918 case LyXTabular::M_VALIGN_CENTER:
1920 case LyXTabular::VALIGN_TOP:
1921 case LyXTabular::VALIGN_BOTTOM:
1922 case LyXTabular::VALIGN_CENTER:
1923 for (int i = sel_row_start; i <= sel_row_end; ++i)
1924 for (int j = sel_col_start; j <= sel_col_end; ++j)
1925 tabular->SetVAlignment(
1926 tabular->GetCellNumber(i, j),
1928 updateLocal(bv, INIT, true);
1930 case LyXTabular::MULTICOLUMN:
1932 if (sel_row_start != sel_row_end) {
1933 Alert::alert(_("Impossible Operation!"),
1934 _("Multicolumns can only be horizontally."),
1938 // just multicol for one Single Cell
1939 if (!hasSelection()) {
1940 // check wether we are completly in a multicol
1941 if (tabular->IsMultiColumn(actcell)) {
1942 tabular->UnsetMultiColumn(actcell);
1943 updateLocal(bv, INIT, true);
1945 tabular->SetMultiColumn(actcell, 1);
1946 updateLocal(bv, CELL, true);
1950 // we have a selection so this means we just add all this
1951 // cells to form a multicolumn cell
1955 if (sel_cell_start > sel_cell_end) {
1956 s_start = sel_cell_end;
1957 s_end = sel_cell_start;
1959 s_start = sel_cell_start;
1960 s_end = sel_cell_end;
1962 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1965 updateLocal(bv, INIT, true);
1968 case LyXTabular::SET_ALL_LINES:
1970 case LyXTabular::UNSET_ALL_LINES:
1971 for (int i = sel_row_start; i <= sel_row_end; ++i)
1972 for (int j = sel_col_start; j <= sel_col_end; ++j)
1973 tabular->SetAllLines(
1974 tabular->GetCellNumber(i,j), setLines);
1975 updateLocal(bv, INIT, true);
1977 case LyXTabular::SET_LONGTABULAR:
1978 tabular->SetLongTabular(true);
1979 updateLocal(bv, INIT, true); // because this toggles displayed
1981 case LyXTabular::UNSET_LONGTABULAR:
1982 tabular->SetLongTabular(false);
1983 updateLocal(bv, INIT, true); // because this toggles displayed
1985 case LyXTabular::SET_ROTATE_TABULAR:
1986 tabular->SetRotateTabular(true);
1988 case LyXTabular::UNSET_ROTATE_TABULAR:
1989 tabular->SetRotateTabular(false);
1991 case LyXTabular::SET_ROTATE_CELL:
1992 for (int i = sel_row_start; i <= sel_row_end; ++i)
1993 for (int j = sel_col_start; j<=sel_col_end; ++j)
1994 tabular->SetRotateCell(
1995 tabular->GetCellNumber(i, j),
1998 case LyXTabular::UNSET_ROTATE_CELL:
1999 for (int i = sel_row_start; i <= sel_row_end; ++i)
2000 for (int j = sel_col_start; j <= sel_col_end; ++j)
2001 tabular->SetRotateCell(
2002 tabular->GetCellNumber(i, j), false);
2004 case LyXTabular::SET_USEBOX:
2006 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
2007 if (val == tabular->GetUsebox(actcell))
2008 val = LyXTabular::BOX_NONE;
2009 for (int i = sel_row_start; i <= sel_row_end; ++i)
2010 for (int j = sel_col_start; j <= sel_col_end; ++j)
2012 tabular->GetCellNumber(i, j), val);
2015 case LyXTabular::UNSET_LTFIRSTHEAD:
2017 case LyXTabular::SET_LTFIRSTHEAD:
2018 (void)tabular->GetRowOfLTFirstHead(row, ltt);
2019 checkLongtableSpecial(ltt, value, flag);
2020 tabular->SetLTHead(row, flag, ltt, true);
2022 case LyXTabular::UNSET_LTHEAD:
2024 case LyXTabular::SET_LTHEAD:
2025 (void)tabular->GetRowOfLTHead(row, ltt);
2026 checkLongtableSpecial(ltt, value, flag);
2027 tabular->SetLTHead(row, flag, ltt, false);
2029 case LyXTabular::UNSET_LTFOOT:
2031 case LyXTabular::SET_LTFOOT:
2032 (void)tabular->GetRowOfLTFoot(row, ltt);
2033 checkLongtableSpecial(ltt, value, flag);
2034 tabular->SetLTFoot(row, flag, ltt, false);
2036 case LyXTabular::UNSET_LTLASTFOOT:
2038 case LyXTabular::SET_LTLASTFOOT:
2039 (void)tabular->GetRowOfLTLastFoot(row, ltt);
2040 checkLongtableSpecial(ltt, value, flag);
2041 tabular->SetLTFoot(row, flag, ltt, true);
2043 case LyXTabular::SET_LTNEWPAGE:
2045 bool what = !tabular->GetLTNewPage(row);
2046 tabular->SetLTNewPage(row, what);
2049 // dummy stuff just to avoid warnings
2050 case LyXTabular::LAST_ACTION:
2056 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
2059 UpdatableInset * inset =
2060 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2061 LyXFont font(LyXFont::ALL_SANE);
2063 x = inset->x() + inset->width(bv, font);
2064 y = inset->descent(bv, font);
2066 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
2067 //inset_y = cursor.y();
2068 inset->edit(bv, x, y, button);
2069 if (!the_locking_inset)
2071 updateLocal(bv, CELL, false);
2072 return (the_locking_inset != 0);
2076 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
2079 inset_x = cursor_.x()
2080 - top_x + tabular->GetBeginningOfTextInCell(actcell);
2081 inset_y = cursor_.y();
2082 return activateCellInset(bv, x - inset_x, y - inset_y, button);
2086 bool InsetTabular::insetHit(BufferView *, int x, int) const
2089 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
2093 // This returns paperWidth() if the cell-width is unlimited or the width
2094 // in pixels if we have a pwidth for this cell.
2095 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
2097 LyXLength const len = tabular->GetPWidth(cell);
2101 #ifdef WITH_WARNINGS
2102 #warning Remove use of VSpace as soon as LyXLength::inPixels exists (JMarc)
2104 return VSpace(len).inPixels(bv);
2108 int InsetTabular::getMaxWidth(BufferView * bv,
2109 UpdatableInset const * inset) const
2111 int cell = tabular->cur_cell;
2112 if (tabular->GetCellInset(cell) != inset) {
2114 if (tabular->GetCellInset(cell) != inset) {
2116 lyxerr[Debug::INSETTEXT] << "Actcell not equal to actual cell!\n";
2121 int const n = tabular->GetNumberOfCells();
2124 for (cell = 0; cell < n; ++cell) {
2125 if (tabular->GetCellInset(cell) == inset)
2131 lyxerr << "Own inset not found, shouldn't really happen!\n";
2135 int w = getMaxWidthOfCell(bv, cell);
2137 // because the inset then subtracts it's top_x and owner->x()
2138 w += (inset->x() - top_x);
2145 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
2147 resizeLyXText(bv, recursive);
2151 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
2154 for(int i = 0; i < tabular->rows(); ++i) {
2155 for(int j = 0; j < tabular->columns(); ++j) {
2156 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
2164 LyXText * InsetTabular::getLyXText(BufferView const * bv,
2165 bool const recursive) const
2167 if (the_locking_inset)
2168 return the_locking_inset->getLyXText(bv, recursive);
2170 // if we're locked lock the actual insettext and return it's LyXText!!!
2172 UpdatableInset * inset =
2173 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2174 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2175 return the_locking_inset->getLyXText(bv, recursive);
2178 return Inset::getLyXText(bv, recursive);
2182 bool InsetTabular::showInsetDialog(BufferView * bv) const
2184 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2185 bv->owner()->getDialogs()
2186 ->showTabular(const_cast<InsetTabular *>(this));
2191 void InsetTabular::openLayoutDialog(BufferView * bv) const
2193 if (the_locking_inset) {
2194 InsetTabular * i = static_cast<InsetTabular *>
2195 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2197 i->openLayoutDialog(bv);
2201 bv->owner()->getDialogs()->showTabular(
2202 const_cast<InsetTabular *>(this));
2207 // functions returns:
2211 // 3 ... toggled off
2213 func_status::value_type InsetTabular::getStatus(string const & what) const
2215 int action = LyXTabular::LAST_ACTION;
2216 func_status::value_type status = func_status::OK;
2219 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2220 string const tmp = tabularFeature[i].feature;
2221 if (tmp == what.substr(0, tmp.length())) {
2222 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2223 // tabularFeatures[i].feature.length())) {
2224 action = tabularFeature[i].action;
2228 if (action == LyXTabular::LAST_ACTION)
2229 return func_status::Unknown;
2231 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2236 LyXTabular::ltType dummyltt;
2239 if (hasSelection()) {
2240 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2242 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2246 case LyXTabular::SET_PWIDTH:
2247 case LyXTabular::SET_MPWIDTH:
2248 case LyXTabular::SET_SPECIAL_COLUMN:
2249 case LyXTabular::SET_SPECIAL_MULTI:
2250 status |= func_status::Disabled;
2253 case LyXTabular::APPEND_ROW:
2254 case LyXTabular::APPEND_COLUMN:
2255 case LyXTabular::DELETE_ROW:
2256 case LyXTabular::DELETE_COLUMN:
2257 case LyXTabular::SET_ALL_LINES:
2258 case LyXTabular::UNSET_ALL_LINES:
2259 status |= func_status::OK;
2262 case LyXTabular::MULTICOLUMN:
2263 if (tabular->IsMultiColumn(actcell))
2264 status |= func_status::ToggleOn;
2266 status |= func_status::ToggleOff;
2268 case LyXTabular::M_TOGGLE_LINE_TOP:
2270 case LyXTabular::TOGGLE_LINE_TOP:
2271 if (tabular->TopLine(actcell, flag))
2272 status |= func_status::ToggleOn;
2274 status |= func_status::ToggleOff;
2276 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2278 case LyXTabular::TOGGLE_LINE_BOTTOM:
2279 if (tabular->BottomLine(actcell, flag))
2280 status |= func_status::ToggleOn;
2282 status |= func_status::ToggleOff;
2284 case LyXTabular::M_TOGGLE_LINE_LEFT:
2286 case LyXTabular::TOGGLE_LINE_LEFT:
2287 if (tabular->LeftLine(actcell, flag))
2288 status |= func_status::ToggleOn;
2290 status |= func_status::ToggleOff;
2292 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2294 case LyXTabular::TOGGLE_LINE_RIGHT:
2295 if (tabular->RightLine(actcell, flag))
2296 status |= func_status::ToggleOn;
2298 status |= func_status::ToggleOff;
2300 case LyXTabular::M_ALIGN_LEFT:
2302 case LyXTabular::ALIGN_LEFT:
2303 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2304 status |= func_status::ToggleOn;
2306 status |= func_status::ToggleOff;
2308 case LyXTabular::M_ALIGN_RIGHT:
2310 case LyXTabular::ALIGN_RIGHT:
2311 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2312 status |= func_status::ToggleOn;
2314 status |= func_status::ToggleOff;
2316 case LyXTabular::M_ALIGN_CENTER:
2318 case LyXTabular::ALIGN_CENTER:
2319 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2320 status |= func_status::ToggleOn;
2322 status |= func_status::ToggleOff;
2324 case LyXTabular::M_VALIGN_TOP:
2326 case LyXTabular::VALIGN_TOP:
2327 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2328 status |= func_status::ToggleOn;
2330 status |= func_status::ToggleOff;
2332 case LyXTabular::M_VALIGN_BOTTOM:
2334 case LyXTabular::VALIGN_BOTTOM:
2335 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2336 status |= func_status::ToggleOn;
2338 status |= func_status::ToggleOff;
2340 case LyXTabular::M_VALIGN_CENTER:
2342 case LyXTabular::VALIGN_CENTER:
2343 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2344 status |= func_status::ToggleOn;
2346 status |= func_status::ToggleOff;
2348 case LyXTabular::SET_LONGTABULAR:
2349 if (tabular->IsLongTabular())
2350 status |= func_status::ToggleOn;
2352 status |= func_status::ToggleOff;
2354 case LyXTabular::UNSET_LONGTABULAR:
2355 if (!tabular->IsLongTabular())
2356 status |= func_status::ToggleOn;
2358 status |= func_status::ToggleOff;
2360 case LyXTabular::SET_ROTATE_TABULAR:
2361 if (tabular->GetRotateTabular())
2362 status |= func_status::ToggleOn;
2364 status |= func_status::ToggleOff;
2366 case LyXTabular::UNSET_ROTATE_TABULAR:
2367 if (!tabular->GetRotateTabular())
2368 status |= func_status::ToggleOn;
2370 status |= func_status::ToggleOff;
2372 case LyXTabular::SET_ROTATE_CELL:
2373 if (tabular->GetRotateCell(actcell))
2374 status |= func_status::ToggleOn;
2376 status |= func_status::ToggleOff;
2378 case LyXTabular::UNSET_ROTATE_CELL:
2379 if (!tabular->GetRotateCell(actcell))
2380 status |= func_status::ToggleOn;
2382 status |= func_status::ToggleOff;
2384 case LyXTabular::SET_USEBOX:
2385 if (strToInt(argument) == tabular->GetUsebox(actcell))
2386 status |= func_status::ToggleOn;
2388 status |= func_status::ToggleOff;
2390 case LyXTabular::SET_LTFIRSTHEAD:
2391 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2392 status |= func_status::ToggleOn;
2394 status |= func_status::ToggleOff;
2396 case LyXTabular::SET_LTHEAD:
2397 if (tabular->GetRowOfLTHead(sel_row_start, dummyltt))
2398 status |= func_status::ToggleOn;
2400 status |= func_status::ToggleOff;
2402 case LyXTabular::SET_LTFOOT:
2403 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2404 status |= func_status::ToggleOn;
2406 status |= func_status::ToggleOff;
2408 case LyXTabular::SET_LTLASTFOOT:
2409 if (tabular->GetRowOfLTFoot(sel_row_start, dummyltt))
2410 status |= func_status::ToggleOn;
2412 status |= func_status::ToggleOff;
2414 case LyXTabular::SET_LTNEWPAGE:
2415 if (tabular->GetLTNewPage(sel_row_start))
2416 status |= func_status::ToggleOn;
2418 status |= func_status::ToggleOff;
2421 status = func_status::Disabled;
2428 std::vector<string> const InsetTabular::getLabelList() const
2430 return tabular->getLabelList();
2434 bool InsetTabular::copySelection(BufferView * bv)
2436 if (!hasSelection())
2439 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2440 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2441 if (sel_col_start > sel_col_end) {
2442 sel_col_start = sel_col_end;
2443 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2445 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2447 int const columns = sel_col_end - sel_col_start + 1;
2449 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2450 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2451 if (sel_row_start > sel_row_end) {
2452 swap(sel_row_start, sel_row_end);
2454 int const rows = sel_row_end - sel_row_start + 1;
2456 delete paste_tabular;
2457 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2458 for (int i = 0; i < sel_row_start; ++i)
2459 paste_tabular->DeleteRow(0);
2460 while (paste_tabular->rows() > rows)
2461 paste_tabular->DeleteRow(rows);
2462 paste_tabular->SetTopLine(0, true, true);
2463 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows - 1),
2465 for (int i = 0; i < sel_col_start; ++i)
2466 paste_tabular->DeleteColumn(0);
2467 while (paste_tabular->columns() > columns)
2468 paste_tabular->DeleteColumn(columns);
2469 paste_tabular->SetLeftLine(0, true, true);
2470 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2474 paste_tabular->ascii(bv->buffer(), sstr,
2475 (int)parOwner()->params().depth(), true, '\t');
2476 bv->stuffClipboard(sstr.str().c_str());
2481 bool InsetTabular::pasteSelection(BufferView * bv)
2486 for (int r1 = 0, r2 = actrow;
2487 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2489 for(int c1 = 0, c2 = actcol;
2490 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2492 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2493 tabular->IsPartOfMultiColumn(r2,c2))
2495 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2499 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2503 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2504 int const n2 = tabular->GetCellNumber(r2, c2);
2505 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2506 tabular->GetCellInset(n2)->setOwner(this);
2507 tabular->GetCellInset(n2)->deleteLyXText(bv);
2514 bool InsetTabular::cutSelection()
2516 if (!hasSelection())
2519 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2520 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2521 if (sel_col_start > sel_col_end) {
2522 sel_col_start = sel_col_end;
2523 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2525 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2527 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2528 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2529 if (sel_row_start > sel_row_end) {
2530 swap(sel_row_start, sel_row_end);
2532 if (sel_cell_start > sel_cell_end) {
2533 swap(sel_cell_start, sel_cell_end);
2535 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2536 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2537 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2544 bool InsetTabular::isRightToLeft(BufferView *bv )
2546 return bv->getParentLanguage(this)->RightToLeft();
2550 bool InsetTabular::nodraw() const
2552 if (!UpdatableInset::nodraw() && the_locking_inset)
2553 return the_locking_inset->nodraw();
2554 return UpdatableInset::nodraw();
2558 int InsetTabular::scroll(bool recursive) const
2560 int sx = UpdatableInset::scroll(false);
2562 if (recursive && the_locking_inset)
2563 sx += the_locking_inset->scroll(recursive);
2569 bool InsetTabular::doClearArea() const
2571 return !locked || (need_update & (FULL|INIT));
2575 void InsetTabular::getSelection(int & srow, int & erow,
2576 int & scol, int & ecol) const
2578 int const start = hasSelection() ? sel_cell_start : actcell;
2579 int const end = hasSelection() ? sel_cell_end : actcell;
2581 srow = tabular->row_of_cell(start);
2582 erow = tabular->row_of_cell(end);
2587 scol = tabular->column_of_cell(start);
2588 ecol = tabular->column_of_cell(end);
2592 ecol = tabular->right_column_of_cell(end);
2597 Paragraph * InsetTabular::getParFromID(int id) const
2600 for(int i = 0; i < tabular->rows(); ++i) {
2601 for(int j = 0; j < tabular->columns(); ++j) {
2602 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2610 Paragraph * InsetTabular::firstParagraph() const
2612 if (the_locking_inset)
2613 return the_locking_inset->firstParagraph();
2618 Paragraph * InsetTabular::getFirstParagraph(int i) const
2620 return (i < tabular->GetNumberOfCells())
2621 ? tabular->GetCellInset(i)->getFirstParagraph(0)
2626 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2628 if (the_locking_inset)
2629 return the_locking_inset->cursor(bv);
2630 return Inset::cursor(bv);
2634 Inset * InsetTabular::getInsetFromID(int id_arg) const
2637 return const_cast<InsetTabular *>(this);
2640 for(int i = 0; i < tabular->rows(); ++i) {
2641 for(int j = 0; j < tabular->columns(); ++j) {
2642 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2651 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2654 if (the_locking_inset) {
2655 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2660 if (tabular->IsLastCell(actcell)) {
2661 bv->unlockInset(const_cast<InsetTabular *>(this));
2667 // otherwise we have to lock the next inset and ask for it's selecttion
2668 UpdatableInset * inset =
2669 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2670 inset->edit(bv, 0, 0, 0);
2671 string const str(selectNextWordInt(bv, value));
2679 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2681 // when entering this function the inset should be ALWAYS locked!
2682 lyx::Assert(the_locking_inset);
2684 string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
2688 if (tabular->IsLastCell(actcell)) {
2689 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));
2697 return selectNextWordInt(bv, value);
2701 void InsetTabular::selectSelectedWord(BufferView * bv)
2703 if (the_locking_inset) {
2704 the_locking_inset->selectSelectedWord(bv);
2711 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2713 if (the_locking_inset) {
2714 the_locking_inset->toggleSelection(bv, kill_selection);
2719 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2720 bool const & cs, bool const & mw)
2723 if (the_locking_inset) {
2724 if (the_locking_inset->searchForward(bv, str, cs, mw)) {
2726 updateLocal(bv, CELL, false);
2729 if (tabular->IsLastCell(actcell)) {
2731 bv->unlockInset(const_cast<InsetTabular *>(this));
2736 // otherwise we have to lock the next inset and search there
2737 UpdatableInset * inset =
2738 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2740 bool const ret = searchForward(bv, str, cs, mw);
2742 updateLocal(bv, CELL, false);
2747 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2748 bool const & cs, bool const & mw)
2751 if (the_locking_inset) {
2752 if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
2754 updateLocal(bv, CELL, false);
2757 if (!actcell) { // we are already in the first cell
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));
2767 inset->edit(bv, false);
2768 bool const ret = searchBackward(bv, str, cs, mw);
2770 updateLocal(bv, CELL, false);
2775 bool InsetTabular::insetAllowed(Inset::Code code) const
2777 if (the_locking_inset)
2778 return the_locking_inset->insetAllowed(code);