1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
41 #include "BufferView.h"
42 #include "undo_funcs.h"
53 const int ADD_TO_HEIGHT = 2;
54 const int ADD_TO_TABULAR_WIDTH = 2;
56 LyXTabular * paste_tabular = 0;
59 struct TabularFeature {
60 LyXTabular::Feature action;
64 //tabular_features * tabularFeatures = 0;
66 TabularFeature tabularFeature[] =
68 { LyXTabular::APPEND_ROW, "append-row" },
69 { LyXTabular::APPEND_COLUMN, "append-column" },
70 { LyXTabular::DELETE_ROW, "delete-row" },
71 { LyXTabular::DELETE_COLUMN, "delete-column" },
72 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
73 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
74 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
75 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
76 { LyXTabular::ALIGN_LEFT, "align-left" },
77 { LyXTabular::ALIGN_RIGHT, "align-right" },
78 { LyXTabular::ALIGN_CENTER, "align-center" },
79 { LyXTabular::VALIGN_TOP, "valign-top" },
80 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
81 { LyXTabular::VALIGN_CENTER, "valign-center" },
82 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
83 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
84 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
85 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
86 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
87 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
88 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
89 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
90 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
91 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
92 { LyXTabular::MULTICOLUMN, "multicolumn" },
93 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
94 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
95 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
96 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
97 { LyXTabular::SET_PWIDTH, "set-pwidth" },
98 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
99 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
100 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
101 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
102 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
103 { LyXTabular::SET_USEBOX, "set-usebox" },
104 { LyXTabular::SET_LTHEAD, "set-lthead" },
105 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
106 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
107 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
108 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
109 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
110 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
111 { LyXTabular::LAST_ACTION, "" }
117 bool InsetTabular::hasPasteBuffer() const
119 return (paste_tabular != 0);
123 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
130 tabular.reset(new LyXTabular(this, rows, columns));
131 // for now make it always display as display() inset
133 the_locking_inset = 0;
134 locked = no_selection = false;
136 actrow = actcell = 0;
142 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
144 : UpdatableInset(tab, same_id), buffer(&buf)
146 tabular.reset(new LyXTabular(this, *(tab.tabular)));
147 the_locking_inset = 0;
148 locked = no_selection = false;
150 actrow = actcell = 0;
151 sel_cell_start = sel_cell_end = 0;
156 InsetTabular::~InsetTabular()
162 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
164 return new InsetTabular(*this, buf, same_id);
168 void InsetTabular::write(Buffer const * buf, ostream & os) const
170 os << " Tabular" << endl;
171 tabular->Write(buf, os);
175 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
177 bool const old_format = (lex.GetString() == "\\LyXTable");
181 //tabular = new LyXTabular(buf, this, lex);
182 tabular.reset(new LyXTabular(buf, this, lex));
190 string token = lex.GetString();
191 while (lex.IsOK() && (token != "\\end_inset")) {
193 token = lex.GetString();
195 if (token != "\\end_inset") {
196 lex.printError("Missing \\end_inset at this point. "
202 int InsetTabular::ascent(BufferView *, LyXFont const &) const
204 return tabular->GetAscentOfRow(0);
208 int InsetTabular::descent(BufferView *, LyXFont const &) const
210 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
214 int InsetTabular::width(BufferView *, LyXFont const &) const
216 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
220 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
221 float & x, bool cleared) const
229 if (need_update == INIT) {
230 if (calculate_dimensions_of_cells(bv, font, true))
231 bv->text->status = LyXText::CHANGED_IN_DRAW;
236 Painter & pain = bv->painter();
242 UpdatableInset::draw(bv, font, baseline, x, cleared);
245 x += static_cast<float>(scroll());
247 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
248 (top_x != int(x)) || (top_baseline != baseline))) {
249 int h = ascent(bv, font) + descent(bv, font);
250 int const tx = display() || !owner() ? 0 : top_x;
251 int w = tx ? width(bv, font) : pain.paperWidth();
252 int ty = baseline - ascent(bv, font);
256 if ((ty + h) > pain.paperHeight())
257 h = pain.paperHeight();
258 if ((top_x + w) > pain.paperWidth())
259 w = pain.paperWidth();
260 pain.fillRectangle(tx, ty, w, h, backgroundColor());
265 top_baseline = baseline;
266 x += ADD_TO_TABULAR_WIDTH;
270 first_visible_cell = -1;
271 for (i = 0; i < tabular->rows(); ++i) {
273 cell = tabular->GetCellNumber(i, 0);
274 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
275 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
277 baseline += tabular->GetDescentOfRow(i) +
278 tabular->GetAscentOfRow(i + 1) +
279 tabular->GetAdditionalHeight(i + 1);
282 for (j = 0; j < tabular->columns(); ++j) {
283 if (nx > bv->workWidth())
285 if (tabular->IsPartOfMultiColumn(i, j))
287 cx = nx + tabular->GetBeginningOfTextInCell(cell);
288 if (first_visible_cell < 0)
289 first_visible_cell = cell;
291 drawCellSelection(pain, nx, baseline, i, j, cell);
293 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
295 drawCellLines(pain, nx, baseline, i, cell);
296 nx += tabular->GetWidthOfColumn(cell);
299 baseline += tabular->GetDescentOfRow(i) +
300 tabular->GetAscentOfRow(i + 1) +
301 tabular->GetAdditionalHeight(i + 1);
303 } else if (need_update == CELL) {
306 if (the_locking_inset &&
307 tabular->GetCellInset(actcell) != the_locking_inset)
309 Inset * inset = tabular->GetCellInset(cell);
311 inset != the_locking_inset && i < tabular->rows();
314 inset != the_locking_inset
315 && j < tabular->columns();
317 if (tabular->IsPartOfMultiColumn(i, j))
319 nx += tabular->GetWidthOfColumn(cell);
321 inset = tabular->GetCellInset(cell);
323 if (tabular->row_of_cell(cell) > i) {
325 baseline += tabular->GetDescentOfRow(i) +
326 tabular->GetAscentOfRow(i + 1) +
327 tabular->GetAdditionalHeight(i + 1);
331 // compute baseline for actual row
332 for (i = 0; i < actrow; ++i) {
333 baseline += tabular->GetDescentOfRow(i) +
334 tabular->GetAscentOfRow(i + 1) +
335 tabular->GetAdditionalHeight(i + 1);
337 // now compute the right x position
338 cell = tabular->GetCellNumber(actrow, 0);
339 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
340 if (tabular->IsPartOfMultiColumn(actrow, j))
342 nx += tabular->GetWidthOfColumn(cell);
346 i = tabular->row_of_cell(cell);
347 if (the_locking_inset != tabular->GetCellInset(cell)) {
348 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
351 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
353 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
354 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
356 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
359 // clear only if we didn't have a change
360 if (need_update == CELL) {
361 // clear before the inset
364 baseline - tabular->GetAscentOfRow(i) + 1,
366 tabular->GetAscentOfRow(i) +
367 tabular->GetDescentOfRow(i) - 1,
369 // clear behind the inset
371 int(cx + the_locking_inset->width(bv,font) + 1),
372 baseline - tabular->GetAscentOfRow(i) + 1,
373 tabular->GetWidthOfColumn(cell) -
374 tabular->GetBeginningOfTextInCell(cell) -
375 the_locking_inset->width(bv,font) -
376 tabular->GetAdditionalWidth(cell) - 1,
377 tabular->GetAscentOfRow(i) +
378 tabular->GetDescentOfRow(i) - 1,
382 x -= ADD_TO_TABULAR_WIDTH;
383 x += width(bv, font);
384 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
386 for(Inset * inset=owner(); inset; ++i)
387 inset = inset->owner();
388 if (calculate_dimensions_of_cells(bv, font, false))
396 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
397 int row, int cell) const
399 int x2 = x + tabular->GetWidthOfColumn(cell);
402 if (!tabular->TopAlreadyDrawed(cell)) {
403 on_off = !tabular->TopLine(cell);
404 pain.line(x, baseline - tabular->GetAscentOfRow(row),
405 x2, baseline - tabular->GetAscentOfRow(row),
406 on_off ? LColor::tabularonoffline : LColor::tabularline,
407 on_off ? Painter::line_onoffdash : Painter::line_solid);
409 on_off = !tabular->BottomLine(cell);
410 pain.line(x,baseline + tabular->GetDescentOfRow(row),
411 x2, baseline + tabular->GetDescentOfRow(row),
412 on_off ? LColor::tabularonoffline : LColor::tabularline,
413 on_off ? Painter::line_onoffdash : Painter::line_solid);
414 if (!tabular->LeftAlreadyDrawed(cell)) {
415 on_off = !tabular->LeftLine(cell);
416 pain.line(x, baseline - tabular->GetAscentOfRow(row),
417 x, baseline + tabular->GetDescentOfRow(row),
418 on_off ? LColor::tabularonoffline : LColor::tabularline,
419 on_off ? Painter::line_onoffdash : Painter::line_solid);
421 on_off = !tabular->RightLine(cell);
422 pain.line(x2 - tabular->GetAdditionalWidth(cell),
423 baseline - tabular->GetAscentOfRow(row),
424 x2 - tabular->GetAdditionalWidth(cell),
425 baseline + tabular->GetDescentOfRow(row),
426 on_off ? LColor::tabularonoffline : LColor::tabularline,
427 on_off ? Painter::line_onoffdash : Painter::line_solid);
431 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
432 int row, int column, int cell) const
434 int cs = tabular->column_of_cell(sel_cell_start);
435 int ce = tabular->column_of_cell(sel_cell_end);
438 cs = tabular->column_of_cell(sel_cell_end);
440 ce = tabular->right_column_of_cell(sel_cell_end);
443 int rs = tabular->row_of_cell(sel_cell_start);
444 int re = tabular->row_of_cell(sel_cell_end);
445 if (rs > re) swap(rs, re);
447 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
448 int w = tabular->GetWidthOfColumn(cell);
449 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
450 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
451 w, h, LColor::selection);
456 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
460 calculate_dimensions_of_cells(bv, font, true);
462 owner()->update(bv, font, true);
465 if (the_locking_inset)
466 the_locking_inset->update(bv, font, reinit);
467 if (need_update < FULL &&
468 bv->text->status() == LyXText::NEED_MORE_REFRESH)
473 switch (need_update) {
477 if (calculate_dimensions_of_cells(bv, font, false))
489 string const InsetTabular::editMessage() const
491 return _("Opened Tabular Inset");
495 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
497 UpdatableInset::edit(bv, x, y, button);
499 if (!bv->lockInset(this)) {
500 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
504 the_locking_inset = 0;
508 sel_cell_start = sel_cell_end = actcell;
510 if (insetHit(bv, x, y) && (button != 3)) {
511 activateCellInsetAbs(bv, x, y, button);
516 void InsetTabular::edit(BufferView * bv, bool front)
518 UpdatableInset::edit(bv, front);
520 if (!bv->lockInset(this)) {
521 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
525 the_locking_inset = 0;
531 actcell = tabular->GetNumberOfCells() - 1;
532 sel_cell_start = sel_cell_end = actcell;
538 void InsetTabular::insetUnlock(BufferView * bv)
540 if (the_locking_inset) {
541 the_locking_inset->insetUnlock(bv);
542 the_locking_inset = 0;
545 no_selection = false;
548 if (scroll(false) || hasSelection()) {
549 sel_cell_start = sel_cell_end = 0;
553 updateLocal(bv, FULL, false);
558 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
559 bool mark_dirty) const
561 if (need_update < what) // only set this if it has greater update
563 if ((what == INIT) && hasSelection())
566 if (need_update != NONE) {
567 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
568 if (locked) // && (what != NONE))
574 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
576 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
581 if (inset == tabular->GetCellInset(actcell)) {
582 lyxerr[Debug::INSETS] << "OK" << endl;
583 the_locking_inset = tabular->GetCellInset(actcell);
585 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
586 inset_y = cursor_.y();
588 } else if (the_locking_inset && (the_locking_inset == inset)) {
589 lyxerr[Debug::INSETS] << "OK" << endl;
591 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
592 inset_y = cursor_.y();
593 } else if (the_locking_inset) {
594 lyxerr[Debug::INSETS] << "MAYBE" << endl;
595 return the_locking_inset->lockInsetInInset(bv, inset);
597 lyxerr[Debug::INSETS] << "NOT OK" << endl;
602 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
605 if (!the_locking_inset)
607 if (the_locking_inset == inset) {
608 the_locking_inset->insetUnlock(bv);
609 the_locking_inset = 0;
611 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
617 updateLocal(bv, CELL, false);
618 showInsetCursor(bv, false);
621 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
622 if (inset->lyxCode() == TABULAR_CODE &&
623 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
624 bv->owner()->getDialogs()->updateTabular(this);
633 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
635 if (!the_locking_inset)
637 if (the_locking_inset != inset) {
638 if (!the_locking_inset->updateInsetInInset(bv, inset))
641 updateLocal(bv, CELL, false);
646 unsigned int InsetTabular::insetInInsetY()
648 if (!the_locking_inset)
651 return inset_y + the_locking_inset->insetInInsetY();
655 UpdatableInset * InsetTabular::getLockingInset() const
657 return the_locking_inset ? the_locking_inset->getLockingInset() :
658 const_cast<InsetTabular *>(this);
662 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
666 if (the_locking_inset)
667 return the_locking_inset->getFirstLockingInsetOfType(c);
672 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
674 if (the_locking_inset)
675 return the_locking_inset->insertInset(bv, inset);
680 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
682 if (hasSelection() && (button == 3))
685 if (hasSelection()) {
687 updateLocal(bv, SELECTION, false);
690 no_selection = false;
692 int const ocell = actcell;
693 int const orow = actrow;
698 updateLocal(bv, NONE, false);
699 sel_cell_start = sel_cell_end = actcell;
701 if ((ocell != actcell) && the_locking_inset) {
702 the_locking_inset->insetUnlock(bv);
703 the_locking_inset = 0;
709 bool const inset_hit = insetHit(bv, x, y);
711 if ((ocell == actcell) && the_locking_inset && inset_hit) {
713 the_locking_inset->insetButtonPress(bv,
714 x - inset_x, y - inset_y,
717 } else if (the_locking_inset) {
718 the_locking_inset->insetUnlock(bv);
720 the_locking_inset = 0;
722 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
725 if (inset_hit && bv->theLockingInset()) {
726 if (activateCellInsetAbs(bv, x, y, button))
727 the_locking_inset->insetButtonPress(bv,
737 void InsetTabular::insetButtonRelease(BufferView * bv,
738 int x, int y, int button)
741 if (the_locking_inset) {
743 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
744 i->insetButtonRelease(bv, x, y, button);
748 bv->owner()->getDialogs()->showTabular(this);
751 if (the_locking_inset) {
752 the_locking_inset->insetButtonRelease(bv,
753 x - inset_x, y - inset_y,
757 no_selection = false;
761 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
763 if (the_locking_inset) {
764 the_locking_inset->insetMotionNotify(bv,
772 int const old_cell = actcell;
775 sel_cell_end = actcell;
776 if (sel_cell_end != old_cell)
777 updateLocal(bv, SELECTION, false);
780 no_selection = false;
784 void InsetTabular::insetKeyPress(XKeyEvent * xke)
786 if (the_locking_inset) {
787 the_locking_inset->insetKeyPress(xke);
793 UpdatableInset::RESULT
794 InsetTabular::localDispatch(BufferView * bv,
798 // We need to save the value of the_locking_inset as the call to
799 // the_locking_inset->LocalDispatch might unlock it.
800 old_locking_inset = the_locking_inset;
801 no_selection = false;
802 UpdatableInset::RESULT result =
803 UpdatableInset::localDispatch(bv, action, arg);
804 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
809 if ((action < 0) && arg.empty())
812 bool hs = hasSelection();
815 // this one have priority over the locked InsetText!
820 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) != this)
823 if (the_locking_inset) {
824 unlockInsetInInset(bv, the_locking_inset);
825 the_locking_inset = 0;
827 if (action == LFUN_TAB)
828 moveNextCell(bv, old_locking_inset != 0);
830 movePrevCell(bv, old_locking_inset != 0);
831 sel_cell_start = sel_cell_end = actcell;
833 updateLocal(bv, SELECTION, false);
834 if (!the_locking_inset) {
836 return DISPATCHED_NOUPDATE;
840 // this to avoid compiler warnings.
845 if (the_locking_inset) {
846 result = the_locking_inset->localDispatch(bv, action, arg);
847 if (result == DISPATCHED_NOUPDATE) {
850 if (sc != scroll()) { // inset has been scrolled
851 the_locking_inset->toggleInsetCursor(bv);
852 updateLocal(bv, FULL, false);
853 the_locking_inset->toggleInsetCursor(bv);
856 } else if (result == DISPATCHED) {
857 the_locking_inset->toggleInsetCursor(bv);
858 updateLocal(bv, CELL, false);
859 the_locking_inset->toggleInsetCursor(bv);
861 } else if (result == FINISHED) {
868 // --- Cursor Movements ----------------------------------
870 if (tabular->IsLastCellInRow(actcell))
872 moveRight(bv, false);
873 sel_cell_end = actcell;
874 updateLocal(bv, SELECTION, false);
877 result = moveRight(bv);
878 sel_cell_start = sel_cell_end = actcell;
880 updateLocal(bv, SELECTION, false);
883 if (tabular->IsFirstCellInRow(actcell))
886 sel_cell_end = actcell;
887 updateLocal(bv, SELECTION, false);
890 result = moveLeft(bv);
891 sel_cell_start = sel_cell_end = actcell;
893 updateLocal(bv, SELECTION, false);
897 int const ocell = actcell;
899 if ((ocell == sel_cell_end) ||
900 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
901 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
903 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
904 updateLocal(bv, SELECTION, false);
908 result = moveDown(bv, old_locking_inset != 0);
909 sel_cell_start = sel_cell_end = actcell;
911 updateLocal(bv, SELECTION, false);
915 int const ocell = actcell;
917 if ((ocell == sel_cell_end) ||
918 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
919 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
921 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
922 updateLocal(bv, SELECTION, false);
926 result = moveUp(bv, old_locking_inset != 0);
927 sel_cell_start = sel_cell_end = actcell;
929 updateLocal(bv, SELECTION, false);
933 if (the_locking_inset) {
934 unlockInsetInInset(bv, the_locking_inset);
935 the_locking_inset = 0;
937 if (bv->text->first + bv->painter().paperHeight() <
938 (top_baseline + tabular->GetHeightOfTabular()))
940 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
941 updateLocal(bv, FULL, false);
942 actcell = tabular->GetCellBelow(first_visible_cell) + column;
944 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
947 updateLocal(bv, CURSOR, false);
952 if (the_locking_inset) {
953 unlockInsetInInset(bv, the_locking_inset);
954 the_locking_inset = 0;
956 if (top_baseline < 0) {
957 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
958 updateLocal(bv, FULL, false);
959 if (top_baseline > 0)
962 actcell = tabular->GetCellBelow(first_visible_cell) + column;
967 updateLocal(bv, CURSOR, false);
978 case LFUN_LAYOUT_TABULAR:
980 bv->owner()->getDialogs()->showTabular(this);
983 case LFUN_TABULAR_FEATURE:
984 if (!tabularFeatures(bv, arg))
985 result = UNDISPATCHED;
988 if (!copySelection(bv))
990 setUndo(bv, Undo::DELETE,
991 bv->text->cursor.par(),
992 bv->text->cursor.par()->next());
994 updateLocal(bv, INIT, true);
1002 case LFUN_PASTESELECTION:
1004 string const clip(bv->getClipboard());
1008 if (clip.find('\t') != string::npos) {
1012 unsigned int len = clip.length();
1013 string::size_type p = 0;
1016 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1024 maxCols = max(cols, maxCols);
1030 maxCols = max(cols, maxCols);
1031 delete paste_tabular;
1032 paste_tabular = new LyXTabular(this, rows, maxCols);
1033 string::size_type op = 0;
1035 int cells = paste_tabular->GetNumberOfCells();
1037 while((cell < cells) && (p < len) &&
1038 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1043 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1048 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1049 while(cols++ < maxCols)
1057 // check for the last cell if there is no trailing '\n'
1058 if ((cell < cells) && (op < len))
1059 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1061 // so that the clipboard is used and it goes on
1063 // and executes LFUN_PASTESELECTION in insettext!
1064 delete paste_tabular;
1069 if (hasPasteBuffer()) {
1070 setUndo(bv, Undo::INSERT,
1071 bv->text->cursor.par(),
1072 bv->text->cursor.par()->next());
1074 updateLocal(bv, INIT, true);
1077 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1079 // we try to activate the actual inset and put this event down to
1080 // the insets dispatch function.
1081 result = UNDISPATCHED;
1082 if (the_locking_inset)
1085 if (activateCellInset(bv)) {
1086 // reset need_update setted in above function!
1088 result = the_locking_inset->localDispatch(bv, action, arg);
1089 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1090 unlockInsetInInset(bv, the_locking_inset);
1092 the_locking_inset = 0;
1093 // we need to update if this was requested before
1094 updateLocal(bv, NONE, false);
1095 return UNDISPATCHED;
1098 // the_locking_inset->ToggleInsetCursor(bv);
1099 updateLocal(bv, CELL, false);
1100 // the_locking_inset->ToggleInsetCursor(bv);
1105 if (result!=FINISHED) {
1106 if (!the_locking_inset) {
1107 showInsetCursor(bv);
1110 bv->unlockInset(this);
1115 int InsetTabular::latex(Buffer const * buf, ostream & os,
1116 bool fragile, bool fp) const
1118 return tabular->Latex(buf, os, fragile, fp);
1122 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1124 // This should be changed to a real ascii export
1125 return tabular->Ascii(buf, os);
1129 int InsetTabular::linuxdoc(Buffer const *, ostream &) const
1135 int InsetTabular::docBook(Buffer const * buf, ostream & os) const
1137 return tabular->DocBook(buf,os);
1141 void InsetTabular::validate(LaTeXFeatures & features) const
1143 tabular->Validate(features);
1147 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1148 LyXFont const & font,
1155 bool changed = false;
1157 // if we have a locking_inset we should have to check only this cell for
1158 // change so I'll try this to have a boost, but who knows ;)
1159 if ((need_update != INIT) &&
1160 (the_locking_inset == tabular->GetCellInset(actcell))) {
1161 for(int i = 0; i < tabular->columns(); ++i) {
1162 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1164 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1167 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1168 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1169 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1175 for (int i = 0; i < tabular->rows(); ++i) {
1178 for (int j = 0; j < tabular->columns(); ++j) {
1179 if (tabular->IsPartOfMultiColumn(i,j))
1182 inset = tabular->GetCellInset(cell);
1184 inset->update(bv, font, false);
1185 maxAsc = max(maxAsc, inset->ascent(bv, font));
1186 maxDesc = max(maxDesc, inset->descent(bv, font));
1187 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1189 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1190 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1196 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1198 if (the_locking_inset) {
1199 the_locking_inset->getCursorPos(bv, x, y);
1202 x = cursor_.x() - top_x;
1207 void InsetTabular::toggleInsetCursor(BufferView * bv)
1209 if (the_locking_inset) {
1210 the_locking_inset->toggleInsetCursor(bv);
1214 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1216 int const asc = lyxfont::maxAscent(font);
1217 int const desc = lyxfont::maxDescent(font);
1219 if (isCursorVisible())
1220 bv->hideLockedInsetCursor();
1222 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1223 toggleCursorVisible();
1227 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1229 if (!isCursorVisible()) {
1230 LyXFont font; // = GetFont(par, cursor.pos);
1232 int const asc = lyxfont::maxAscent(font);
1233 int const desc = lyxfont::maxDescent(font);
1234 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1236 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1237 setCursorVisible(true);
1242 void InsetTabular::hideInsetCursor(BufferView * bv)
1244 if (isCursorVisible()) {
1245 bv->hideLockedInsetCursor();
1246 setCursorVisible(false);
1248 // if (cursor_visible)
1249 // ToggleInsetCursor(bv);
1253 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1257 actcell = actrow = actcol = 0;
1258 int ly = tabular->GetDescentOfRow(actrow);
1260 // first search the right row
1261 while((ly < y) && (actrow < tabular->rows())) {
1262 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1263 tabular->GetAscentOfRow(actrow + 1) +
1264 tabular->GetAdditionalHeight(actrow + 1));
1266 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1268 actcell = tabular->GetCellNumber(actrow, actcol);
1270 // now search the right column
1271 int lx = tabular->GetWidthOfColumn(actcell) -
1272 tabular->GetAdditionalWidth(actcell);
1274 #ifdef WITH_WARNINGS
1275 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1277 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1278 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1279 tabular->GetAdditionalWidth(actcell - 1));
1281 // Jürgen, you should check that this is correct. (Lgb)
1282 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1283 lx += tabular->GetWidthOfColumn(actcell + 1)
1284 + tabular->GetAdditionalWidth(actcell);
1288 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1293 int InsetTabular::getCellXPos(int cell) const
1297 for (; !tabular->IsFirstCellInRow(c); --c)
1299 int lx = tabular->GetWidthOfColumn(cell);
1300 for (; c < cell; ++c) {
1301 lx += tabular->GetWidthOfColumn(c);
1303 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1307 void InsetTabular::resetPos(BufferView * bv) const
1311 actcol = tabular->column_of_cell(actcell);
1316 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1317 if (tabular->IsLastCellInRow(cell)) {
1318 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1319 tabular->GetAscentOfRow(actrow + 1) +
1320 tabular->GetAdditionalHeight(actrow + 1));
1324 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1325 int new_x = getCellXPos(actcell);
1326 int old_x = cursor_.x();
1329 // cursor.x(getCellXPos(actcell) + offset);
1330 if ((actcol < tabular->columns()-1) && scroll(false) &&
1331 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1334 updateLocal(bv, FULL, false);
1335 } else if (the_locking_inset &&
1336 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1338 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1339 if (xx > (bv->workWidth()-20)) {
1340 scroll(bv, -(xx - bv->workWidth() + 60));
1341 updateLocal(bv, FULL, false);
1342 } else if (xx < 20) {
1348 updateLocal(bv, FULL, false);
1350 } else if ((cursor_.x() - offset) > 20 &&
1351 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1352 > (bv->workWidth() - 20)) {
1353 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1354 updateLocal(bv, FULL, false);
1355 } else if ((cursor_.x() - offset) < 20) {
1356 scroll(bv, 20 - cursor_.x() + offset);
1357 updateLocal(bv, FULL, false);
1358 } else if (scroll(false) && top_x > 20 &&
1359 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1360 scroll(bv, old_x - cursor_.x());
1361 updateLocal(bv, FULL, false);
1363 if ((!the_locking_inset ||
1364 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1365 actcell != oldcell) {
1366 InsetTabular * inset = const_cast<InsetTabular *>(this);
1367 bv->owner()->getDialogs()->updateTabular(inset);
1373 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1375 if (lock && !old_locking_inset) {
1376 if (activateCellInset(bv))
1379 bool moved = isRightToLeft(bv)
1380 ? movePrevCell(bv) : moveNextCell(bv);
1383 if (lock && activateCellInset(bv))
1387 return DISPATCHED_NOUPDATE;
1391 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1393 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1396 if (lock) { // behind the inset
1397 if (activateCellInset(bv, 0, 0, 0, true))
1401 return DISPATCHED_NOUPDATE;
1405 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1407 int const ocell = actcell;
1408 actcell = tabular->GetCellAbove(actcell);
1409 if (actcell == ocell) // we moved out of the inset
1415 if (old_locking_inset) {
1416 old_locking_inset->getCursorPos(bv, x, y);
1417 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1419 if (activateCellInset(bv, x, 0))
1422 return DISPATCHED_NOUPDATE;
1426 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1428 int const ocell = actcell;
1429 actcell = tabular->GetCellBelow(actcell);
1430 if (actcell == ocell) // we moved out of the inset
1436 if (old_locking_inset) {
1437 old_locking_inset->getCursorPos(bv, x, y);
1438 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1440 if (activateCellInset(bv, x, 0))
1443 return DISPATCHED_NOUPDATE;
1447 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1449 if (isRightToLeft(bv)) {
1450 if (tabular->IsFirstCellInRow(actcell)) {
1451 int row = tabular->row_of_cell(actcell);
1452 if (row == tabular->rows() - 1)
1454 actcell = tabular->GetLastCellInRow(row);
1455 actcell = tabular->GetCellBelow(actcell);
1462 if (tabular->IsLastCell(actcell))
1467 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1468 isRightToLeftPar(bv->buffer()->params);
1469 activateCellInset(bv, 0, 0, 0, !rtl);
1476 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1478 if (isRightToLeft(bv)) {
1479 if (tabular->IsLastCellInRow(actcell)) {
1480 int row = tabular->row_of_cell(actcell);
1483 actcell = tabular->GetFirstCellInRow(row);
1484 actcell = tabular->GetCellAbove(actcell);
1486 if (tabular->IsLastCell(actcell))
1491 if (!actcell) // first cell
1496 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1497 isRightToLeftPar(bv->buffer()->params);
1498 activateCellInset(bv, 0, 0, 0, !rtl);
1505 bool InsetTabular::Delete()
1507 #warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
1508 #warning I guess this could be 'deletable'! (Jug)
1513 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1518 sel_cell_end = tabular->GetNumberOfCells() - 1;
1520 if (hasSelection()) {
1521 setUndo(bv, Undo::EDIT,
1522 bv->text->cursor.par(),
1523 bv->text->cursor.par()->next());
1524 bool frozen = undo_frozen;
1527 // apply the fontchange on the whole selection
1532 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1533 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1534 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1535 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1540 updateLocal(bv, INIT, true);
1542 if (the_locking_inset)
1543 the_locking_inset->setFont(bv, font, tall);
1547 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1549 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1552 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1553 string const tmp = tabularFeature[i].feature;
1555 if (tmp == what.substr(0, tmp.length())) {
1556 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1557 //tabularFeatures[i].feature.length())) {
1558 action = tabularFeature[i].action;
1562 if (action == LyXTabular::LAST_ACTION)
1566 frontStrip(what.substr(tabularFeature[i].feature.length()));
1567 tabularFeatures(bv, action, val);
1572 void InsetTabular::tabularFeatures(BufferView * bv,
1573 LyXTabular::Feature feature,
1574 string const & value)
1580 bool setLines = false;
1581 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1582 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1585 case LyXTabular::M_ALIGN_LEFT:
1586 case LyXTabular::ALIGN_LEFT:
1587 setAlign=LYX_ALIGN_LEFT;
1589 case LyXTabular::M_ALIGN_RIGHT:
1590 case LyXTabular::ALIGN_RIGHT:
1591 setAlign=LYX_ALIGN_RIGHT;
1593 case LyXTabular::M_ALIGN_CENTER:
1594 case LyXTabular::ALIGN_CENTER:
1595 setAlign=LYX_ALIGN_CENTER;
1597 case LyXTabular::M_VALIGN_TOP:
1598 case LyXTabular::VALIGN_TOP:
1599 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1601 case LyXTabular::M_VALIGN_BOTTOM:
1602 case LyXTabular::VALIGN_BOTTOM:
1603 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1605 case LyXTabular::M_VALIGN_CENTER:
1606 case LyXTabular::VALIGN_CENTER:
1607 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1612 if (hasSelection()) {
1613 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1615 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1616 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1618 setUndo(bv, Undo::FINISH,
1619 bv->text->cursor.par(),
1620 bv->text->cursor.par()->next());
1622 int row = tabular->row_of_cell(actcell);
1623 int column = tabular->column_of_cell(actcell);
1627 case LyXTabular::SET_PWIDTH:
1629 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1630 tabular->SetColumnPWidth(actcell,value);
1632 for (int i = 0; i < tabular->rows(); ++i) {
1633 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1636 updateLocal(bv, INIT, true);
1640 case LyXTabular::SET_MPWIDTH:
1642 bool const update = (tabular->GetPWidth(actcell) != value);
1643 tabular->SetMColumnPWidth(actcell,value);
1645 for (int i = 0; i < tabular->rows(); ++i) {
1646 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1649 updateLocal(bv, INIT, true);
1653 case LyXTabular::SET_SPECIAL_COLUMN:
1654 case LyXTabular::SET_SPECIAL_MULTI:
1655 tabular->SetAlignSpecial(actcell,value,feature);
1657 case LyXTabular::APPEND_ROW:
1658 // append the row into the tabular
1659 unlockInsetInInset(bv, the_locking_inset);
1660 tabular->AppendRow(actcell);
1661 updateLocal(bv, INIT, true);
1663 case LyXTabular::APPEND_COLUMN:
1664 // append the column into the tabular
1665 unlockInsetInInset(bv, the_locking_inset);
1666 tabular->AppendColumn(actcell);
1667 actcell = tabular->GetCellNumber(row, column);
1668 updateLocal(bv, INIT, true);
1670 case LyXTabular::DELETE_ROW:
1671 unlockInsetInInset(bv, the_locking_inset);
1672 tabular->DeleteRow(tabular->row_of_cell(actcell));
1673 if ((row+1) > tabular->rows())
1675 actcell = tabular->GetCellNumber(row, column);
1677 updateLocal(bv, INIT, true);
1679 case LyXTabular::DELETE_COLUMN:
1680 unlockInsetInInset(bv, the_locking_inset);
1681 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1682 if ((column+1) > tabular->columns())
1684 actcell = tabular->GetCellNumber(row, column);
1686 updateLocal(bv, INIT, true);
1688 case LyXTabular::M_TOGGLE_LINE_TOP:
1690 case LyXTabular::TOGGLE_LINE_TOP:
1692 bool lineSet = !tabular->TopLine(actcell, flag);
1693 for (int i = sel_row_start; i <= sel_row_end; ++i)
1694 for (int j = sel_col_start; j <= sel_col_end; ++j)
1695 tabular->SetTopLine(
1696 tabular->GetCellNumber(i, j),
1698 updateLocal(bv, INIT, true);
1702 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1704 case LyXTabular::TOGGLE_LINE_BOTTOM:
1706 bool lineSet = !tabular->BottomLine(actcell, flag);
1707 for (int i = sel_row_start; i <= sel_row_end; ++i)
1708 for (int j = sel_col_start; j <= sel_col_end; ++j)
1709 tabular->SetBottomLine(
1710 tabular->GetCellNumber(i, j),
1713 updateLocal(bv, INIT, true);
1717 case LyXTabular::M_TOGGLE_LINE_LEFT:
1719 case LyXTabular::TOGGLE_LINE_LEFT:
1721 bool lineSet = !tabular->LeftLine(actcell, flag);
1722 for (int i = sel_row_start; i <= sel_row_end; ++i)
1723 for (int j = sel_col_start; j <= sel_col_end; ++j)
1724 tabular->SetLeftLine(
1725 tabular->GetCellNumber(i,j),
1728 updateLocal(bv, INIT, true);
1732 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1734 case LyXTabular::TOGGLE_LINE_RIGHT:
1736 bool lineSet = !tabular->RightLine(actcell, flag);
1737 for (int i = sel_row_start; i <= sel_row_end; ++i)
1738 for (int j = sel_col_start; j <= sel_col_end; ++j)
1739 tabular->SetRightLine(
1740 tabular->GetCellNumber(i,j),
1743 updateLocal(bv, INIT, true);
1747 case LyXTabular::M_ALIGN_LEFT:
1748 case LyXTabular::M_ALIGN_RIGHT:
1749 case LyXTabular::M_ALIGN_CENTER:
1751 case LyXTabular::ALIGN_LEFT:
1752 case LyXTabular::ALIGN_RIGHT:
1753 case LyXTabular::ALIGN_CENTER:
1754 for (int i = sel_row_start; i <= sel_row_end; ++i)
1755 for (int j = sel_col_start; j <= sel_col_end; ++j)
1756 tabular->SetAlignment(
1757 tabular->GetCellNumber(i, j),
1760 updateLocal(bv, INIT, true);
1762 case LyXTabular::M_VALIGN_TOP:
1763 case LyXTabular::M_VALIGN_BOTTOM:
1764 case LyXTabular::M_VALIGN_CENTER:
1766 case LyXTabular::VALIGN_TOP:
1767 case LyXTabular::VALIGN_BOTTOM:
1768 case LyXTabular::VALIGN_CENTER:
1769 for (int i = sel_row_start; i <= sel_row_end; ++i)
1770 for (int j = sel_col_start; j <= sel_col_end; ++j)
1771 tabular->SetVAlignment(
1772 tabular->GetCellNumber(i, j),
1774 updateLocal(bv, INIT, true);
1776 case LyXTabular::MULTICOLUMN:
1778 if (sel_row_start != sel_row_end) {
1779 WriteAlert(_("Impossible Operation!"),
1780 _("Multicolumns can only be horizontally."),
1784 // just multicol for one Single Cell
1785 if (!hasSelection()) {
1786 // check wether we are completly in a multicol
1787 if (tabular->IsMultiColumn(actcell)) {
1788 tabular->UnsetMultiColumn(actcell);
1789 updateLocal(bv, INIT, true);
1791 tabular->SetMultiColumn(actcell, 1);
1792 updateLocal(bv, CELL, true);
1796 // we have a selection so this means we just add all this
1797 // cells to form a multicolumn cell
1801 if (sel_cell_start > sel_cell_end) {
1802 s_start = sel_cell_end;
1803 s_end = sel_cell_start;
1805 s_start = sel_cell_start;
1806 s_end = sel_cell_end;
1808 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1810 sel_cell_end = sel_cell_start;
1811 updateLocal(bv, INIT, true);
1814 case LyXTabular::SET_ALL_LINES:
1816 case LyXTabular::UNSET_ALL_LINES:
1817 for (int i = sel_row_start; i <= sel_row_end; ++i)
1818 for (int j = sel_col_start; j <= sel_col_end; ++j)
1819 tabular->SetAllLines(
1820 tabular->GetCellNumber(i,j), setLines);
1821 updateLocal(bv, INIT, true);
1823 case LyXTabular::SET_LONGTABULAR:
1824 tabular->SetLongTabular(true);
1825 updateLocal(bv, INIT, true); // because this toggles displayed
1827 case LyXTabular::UNSET_LONGTABULAR:
1828 tabular->SetLongTabular(false);
1829 updateLocal(bv, INIT, true); // because this toggles displayed
1831 case LyXTabular::SET_ROTATE_TABULAR:
1832 tabular->SetRotateTabular(true);
1834 case LyXTabular::UNSET_ROTATE_TABULAR:
1835 tabular->SetRotateTabular(false);
1837 case LyXTabular::SET_ROTATE_CELL:
1838 for (int i = sel_row_start; i <= sel_row_end; ++i)
1839 for (int j = sel_col_start; j<=sel_col_end; ++j)
1840 tabular->SetRotateCell(
1841 tabular->GetCellNumber(i, j),
1844 case LyXTabular::UNSET_ROTATE_CELL:
1845 for (int i = sel_row_start; i <= sel_row_end; ++i)
1846 for (int j = sel_col_start; j <= sel_col_end; ++j)
1847 tabular->SetRotateCell(
1848 tabular->GetCellNumber(i, j), false);
1850 case LyXTabular::SET_USEBOX:
1852 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1853 if (val == tabular->GetUsebox(actcell))
1854 val = LyXTabular::BOX_NONE;
1855 for (int i = sel_row_start; i <= sel_row_end; ++i)
1856 for (int j = sel_col_start; j <= sel_col_end; ++j)
1858 tabular->GetCellNumber(i, j), val);
1861 case LyXTabular::SET_LTFIRSTHEAD:
1862 tabular->SetLTHead(actcell, true);
1864 case LyXTabular::SET_LTHEAD:
1865 tabular->SetLTHead(actcell, false);
1867 case LyXTabular::SET_LTFOOT:
1868 tabular->SetLTFoot(actcell, false);
1870 case LyXTabular::SET_LTLASTFOOT:
1871 tabular->SetLTFoot(actcell, true);
1873 case LyXTabular::SET_LTNEWPAGE:
1875 bool what = !tabular->GetLTNewPage(actcell);
1876 tabular->SetLTNewPage(actcell, what);
1879 // dummy stuff just to avoid warnings
1880 case LyXTabular::LAST_ACTION:
1886 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1889 UpdatableInset * inset =
1890 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1891 LyXFont font(LyXFont::ALL_SANE);
1893 x = inset->x() + inset->width(bv, font);
1894 y = inset->descent(bv, font);
1896 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1897 //inset_y = cursor.y();
1898 inset->edit(bv, x, y, button);
1899 if (!the_locking_inset)
1901 updateLocal(bv, CELL, false);
1902 return (the_locking_inset != 0);
1906 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1909 inset_x = cursor_.x()
1910 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1911 inset_y = cursor_.y();
1912 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1916 bool InsetTabular::insetHit(BufferView *, int x, int) const
1919 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
1923 // This returns paperWidth() if the cell-width is unlimited or the width
1924 // in pixels if we have a pwidth for this cell.
1925 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
1927 string const s = tabular->GetPWidth(cell);
1931 return VSpace(s).inPixels(bv);
1935 int InsetTabular::getMaxWidth(BufferView * bv,
1936 UpdatableInset const * inset) const
1938 int cell = tabular->cur_cell;
1939 if (tabular->GetCellInset(cell) != inset) {
1941 if (tabular->GetCellInset(cell) != inset) {
1943 lyxerr << "Actcell not equal to actual cell!\n";
1948 int const n = tabular->GetNumberOfCells();
1951 for (cell = 0; cell < n; ++cell) {
1952 if (tabular->GetCellInset(cell) == inset)
1958 lyxerr << "Own inset not found, shouldn't really happen!\n";
1962 int w = getMaxWidthOfCell(bv, cell);
1964 // because the inset then subtracts it's top_x and owner->x()
1965 w += (inset->x() - top_x);
1972 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
1974 resizeLyXText(bv, recursive);
1978 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
1981 for(int i = 0; i < tabular->rows(); ++i) {
1982 for(int j = 0; j < tabular->columns(); ++j) {
1983 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
1991 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1992 bool const recursive) const
1994 if (the_locking_inset)
1995 return the_locking_inset->getLyXText(bv, recursive);
1997 // if we're locked lock the actual insettext and return it's LyXText!!!
1999 UpdatableInset * inset =
2000 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2001 inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
2002 return the_locking_inset->getLyXText(bv, recursive);
2005 return Inset::getLyXText(bv, recursive);
2009 bool InsetTabular::showInsetDialog(BufferView * bv) const
2011 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
2012 bv->owner()->getDialogs()
2013 ->showTabular(const_cast<InsetTabular *>(this));
2018 void InsetTabular::openLayoutDialog(BufferView * bv) const
2020 if (the_locking_inset) {
2021 InsetTabular * i = static_cast<InsetTabular *>
2022 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
2024 i->openLayoutDialog(bv);
2028 bv->owner()->getDialogs()->showTabular(
2029 const_cast<InsetTabular *>(this));
2033 // functions returns:
2037 // 3 ... toggled off
2039 func_status::value_type InsetTabular::getStatus(string const & what) const
2041 int action = LyXTabular::LAST_ACTION;
2042 func_status::value_type status = func_status::OK;
2045 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2046 string const tmp = tabularFeature[i].feature;
2047 if (tmp == what.substr(0, tmp.length())) {
2048 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2049 // tabularFeatures[i].feature.length())) {
2050 action = tabularFeature[i].action;
2054 if (action == LyXTabular::LAST_ACTION)
2055 return func_status::Unknown;
2057 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2064 if (hasSelection()) {
2065 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2067 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2071 case LyXTabular::SET_PWIDTH:
2072 case LyXTabular::SET_MPWIDTH:
2073 case LyXTabular::SET_SPECIAL_COLUMN:
2074 case LyXTabular::SET_SPECIAL_MULTI:
2075 status |= func_status::Disabled;
2078 case LyXTabular::APPEND_ROW:
2079 case LyXTabular::APPEND_COLUMN:
2080 case LyXTabular::DELETE_ROW:
2081 case LyXTabular::DELETE_COLUMN:
2082 case LyXTabular::SET_ALL_LINES:
2083 case LyXTabular::UNSET_ALL_LINES:
2084 status |= func_status::OK;
2087 case LyXTabular::MULTICOLUMN:
2088 if (tabular->IsMultiColumn(actcell))
2089 status |= func_status::ToggleOn;
2091 status |= func_status::ToggleOff;
2093 case LyXTabular::M_TOGGLE_LINE_TOP:
2095 case LyXTabular::TOGGLE_LINE_TOP:
2096 if (tabular->TopLine(actcell, flag))
2097 status |= func_status::ToggleOn;
2099 status |= func_status::ToggleOff;
2101 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2103 case LyXTabular::TOGGLE_LINE_BOTTOM:
2104 if (tabular->BottomLine(actcell, flag))
2105 status |= func_status::ToggleOn;
2107 status |= func_status::ToggleOff;
2109 case LyXTabular::M_TOGGLE_LINE_LEFT:
2111 case LyXTabular::TOGGLE_LINE_LEFT:
2112 if (tabular->LeftLine(actcell, flag))
2113 status |= func_status::ToggleOn;
2115 status |= func_status::ToggleOff;
2117 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2119 case LyXTabular::TOGGLE_LINE_RIGHT:
2120 if (tabular->RightLine(actcell, flag))
2121 status |= func_status::ToggleOn;
2123 status |= func_status::ToggleOff;
2125 case LyXTabular::M_ALIGN_LEFT:
2127 case LyXTabular::ALIGN_LEFT:
2128 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2129 status |= func_status::ToggleOn;
2131 status |= func_status::ToggleOff;
2133 case LyXTabular::M_ALIGN_RIGHT:
2135 case LyXTabular::ALIGN_RIGHT:
2136 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2137 status |= func_status::ToggleOn;
2139 status |= func_status::ToggleOff;
2141 case LyXTabular::M_ALIGN_CENTER:
2143 case LyXTabular::ALIGN_CENTER:
2144 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2145 status |= func_status::ToggleOn;
2147 status |= func_status::ToggleOff;
2149 case LyXTabular::M_VALIGN_TOP:
2151 case LyXTabular::VALIGN_TOP:
2152 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2153 status |= func_status::ToggleOn;
2155 status |= func_status::ToggleOff;
2157 case LyXTabular::M_VALIGN_BOTTOM:
2159 case LyXTabular::VALIGN_BOTTOM:
2160 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2161 status |= func_status::ToggleOn;
2163 status |= func_status::ToggleOff;
2165 case LyXTabular::M_VALIGN_CENTER:
2167 case LyXTabular::VALIGN_CENTER:
2168 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2169 status |= func_status::ToggleOn;
2171 status |= func_status::ToggleOff;
2173 case LyXTabular::SET_LONGTABULAR:
2174 if (tabular->IsLongTabular())
2175 status |= func_status::ToggleOn;
2177 status |= func_status::ToggleOff;
2179 case LyXTabular::UNSET_LONGTABULAR:
2180 if (!tabular->IsLongTabular())
2181 status |= func_status::ToggleOn;
2183 status |= func_status::ToggleOff;
2185 case LyXTabular::SET_ROTATE_TABULAR:
2186 if (tabular->GetRotateTabular())
2187 status |= func_status::ToggleOn;
2189 status |= func_status::ToggleOff;
2191 case LyXTabular::UNSET_ROTATE_TABULAR:
2192 if (!tabular->GetRotateTabular())
2193 status |= func_status::ToggleOn;
2195 status |= func_status::ToggleOff;
2197 case LyXTabular::SET_ROTATE_CELL:
2198 if (tabular->GetRotateCell(actcell))
2199 status |= func_status::ToggleOn;
2201 status |= func_status::ToggleOff;
2203 case LyXTabular::UNSET_ROTATE_CELL:
2204 if (!tabular->GetRotateCell(actcell))
2205 status |= func_status::ToggleOn;
2207 status |= func_status::ToggleOff;
2209 case LyXTabular::SET_USEBOX:
2210 if (strToInt(argument) == tabular->GetUsebox(actcell))
2211 status |= func_status::ToggleOn;
2213 status |= func_status::ToggleOff;
2215 case LyXTabular::SET_LTFIRSTHEAD:
2216 if (tabular->GetRowOfLTHead(actcell, dummy))
2217 status |= func_status::ToggleOn;
2219 status |= func_status::ToggleOff;
2221 case LyXTabular::SET_LTHEAD:
2222 if (tabular->GetRowOfLTHead(actcell, dummy))
2223 status |= func_status::ToggleOn;
2225 status |= func_status::ToggleOff;
2227 case LyXTabular::SET_LTFOOT:
2228 if (tabular->GetRowOfLTFoot(actcell, dummy))
2229 status |= func_status::ToggleOn;
2231 status |= func_status::ToggleOff;
2233 case LyXTabular::SET_LTLASTFOOT:
2234 if (tabular->GetRowOfLTFoot(actcell, dummy))
2235 status |= func_status::ToggleOn;
2237 status |= func_status::ToggleOff;
2239 case LyXTabular::SET_LTNEWPAGE:
2240 if (tabular->GetLTNewPage(actcell))
2241 status |= func_status::ToggleOn;
2243 status |= func_status::ToggleOff;
2246 status = func_status::Disabled;
2253 std::vector<string> const InsetTabular::getLabelList() const
2255 return tabular->getLabelList();
2259 bool InsetTabular::copySelection(BufferView * bv)
2261 if (!hasSelection())
2264 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2265 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2266 if (sel_col_start > sel_col_end) {
2267 sel_col_start = sel_col_end;
2268 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2270 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2272 int const columns = sel_col_end - sel_col_start + 1;
2274 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2275 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2276 if (sel_row_start > sel_row_end) {
2277 swap(sel_row_start, sel_row_end);
2279 int const rows = sel_row_end - sel_row_start + 1;
2281 delete paste_tabular;
2282 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2283 for (int i = 0; i < sel_row_start; ++i)
2284 paste_tabular->DeleteRow(0);
2285 while(paste_tabular->rows() > rows)
2286 paste_tabular->DeleteRow(rows);
2287 paste_tabular->SetTopLine(0, true, true);
2288 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2290 for (int i = 0; i < sel_col_start; ++i)
2291 paste_tabular->DeleteColumn(0);
2292 while (paste_tabular->columns() > columns)
2293 paste_tabular->DeleteColumn(columns);
2294 paste_tabular->SetLeftLine(0, true, true);
2295 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2299 paste_tabular->Ascii(bv->buffer(), sstr);
2300 bv->stuffClipboard(sstr.str().c_str());
2305 bool InsetTabular::pasteSelection(BufferView * bv)
2310 for (int r1 = 0, r2 = actrow;
2311 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2313 for(int c1 = 0, c2 = actcol;
2314 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2316 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2317 tabular->IsPartOfMultiColumn(r2,c2))
2319 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2323 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2327 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2328 int const n2 = tabular->GetCellNumber(r2, c2);
2329 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2330 tabular->GetCellInset(n2)->setOwner(this);
2331 tabular->GetCellInset(n2)->deleteLyXText(bv);
2338 bool InsetTabular::cutSelection()
2340 if (!hasSelection())
2343 //int sel_col_start;
2345 //int sel_row_start;
2348 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2349 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2350 if (sel_col_start > sel_col_end) {
2351 sel_col_start = sel_col_end;
2352 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2354 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2356 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2357 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2358 if (sel_row_start > sel_row_end) {
2359 //int tmp = sel_row_start;
2360 //sel_row_start = sel_row_end;
2361 //sel_row_end = tmp;
2362 swap(sel_row_start, sel_row_end);
2364 if (sel_cell_start > sel_cell_end) {
2365 //int tmp = sel_cell_start;
2366 //sel_cell_start = sel_cell_end;
2367 //sel_cell_end = tmp;
2368 swap(sel_cell_start, sel_cell_end);
2370 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2371 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2372 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2379 bool InsetTabular::isRightToLeft(BufferView *bv )
2381 return bv->getParentLanguage(this)->RightToLeft();
2385 bool InsetTabular::nodraw() const
2387 if (!UpdatableInset::nodraw() && the_locking_inset)
2388 return the_locking_inset->nodraw();
2389 return UpdatableInset::nodraw();
2393 int InsetTabular::scroll(bool recursive) const
2395 int sx = UpdatableInset::scroll(false);
2397 if (recursive && the_locking_inset)
2398 sx += the_locking_inset->scroll(recursive);
2404 bool InsetTabular::doClearArea() const
2406 return !locked || (need_update & (FULL|INIT));
2410 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2412 srow = tabular->row_of_cell(sel_cell_start);
2413 erow = tabular->row_of_cell(sel_cell_end);
2417 scol = tabular->column_of_cell(sel_cell_start);
2418 ecol = tabular->column_of_cell(sel_cell_end);
2422 ecol = tabular->right_column_of_cell(sel_cell_end);
2425 Paragraph * InsetTabular::getParFromID(int id) const
2428 for(int i = 0; i < tabular->rows(); ++i) {
2429 for(int j = 0; j < tabular->columns(); ++j) {
2430 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2437 Paragraph * InsetTabular::firstParagraph() const
2439 if (the_locking_inset)
2440 return the_locking_inset->firstParagraph();
2444 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2446 if (the_locking_inset)
2447 return the_locking_inset->cursor(bv);
2448 return Inset::cursor(bv);
2452 Inset * InsetTabular::getInsetFromID(int id_arg) const
2455 return const_cast<InsetTabular *>(this);
2458 for(int i=0; i < tabular->rows(); ++i) {
2459 for(int j=0; j < tabular->columns(); ++j) {
2460 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2468 string InsetTabular::selectNextWord(BufferView * bv, float & value) const
2470 if (the_locking_inset) {
2472 str = the_locking_inset->selectNextWord(bv, value);
2475 if (tabular->IsLastCell(actcell)) {
2476 bv->unlockInset(const_cast<InsetTabular *>(this));
2482 // otherwise we have to lock the next inset and ask for it's selecttion
2483 UpdatableInset * inset =
2484 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2485 inset->edit(bv, 0, 0, 0);
2486 string str = selectNextWordInt(bv, value);
2492 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2494 // when entering this function the inset should be ALWAYS locked!
2495 lyx::Assert(the_locking_inset);
2498 str = the_locking_inset->selectNextWord(bv, value);
2502 if (tabular->IsLastCell(actcell)) {
2503 bv->unlockInset(const_cast<InsetTabular *>(this));
2507 // otherwise we have to lock the next inset and ask for it's selecttion
2508 UpdatableInset * inset =
2509 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2510 inset->edit(bv, 0, 0, 0);
2511 return selectNextWordInt(bv, value);
2515 void InsetTabular::selectSelectedWord(BufferView * bv)
2517 if (the_locking_inset) {
2518 the_locking_inset->selectSelectedWord(bv);
2524 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2526 if (the_locking_inset) {
2527 the_locking_inset->toggleSelection(bv, kill_selection);
2532 bool InsetTabular::searchForward(BufferView * bv, string const & str,
2533 bool const & cs, bool const & mw)
2535 if (the_locking_inset) {
2536 if (the_locking_inset->searchForward(bv, str, cs, mw))
2538 if (tabular->IsLastCell(actcell)) {
2539 bv->unlockInset(const_cast<InsetTabular *>(this));
2545 // otherwise we have to lock the next inset and search there
2546 UpdatableInset * inset =
2547 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2549 bool res = searchForward(bv, str, cs, mw);
2550 updateLocal(bv, NONE, false);
2552 bv->updateInset(const_cast<InsetTabular *>(this), false);
2556 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
2557 bool const & cs, bool const & mw)
2559 if (the_locking_inset) {
2560 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2562 if (!actcell) { // we are already in the first cell
2563 bv->unlockInset(const_cast<InsetTabular *>(this));
2569 // otherwise we have to lock the next inset and search there
2570 UpdatableInset * inset =
2571 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
2572 inset->edit(bv, false);
2573 bool res = searchBackward(bv, str, cs, mw);
2575 bv->updateInset(const_cast<InsetTabular *>(this), false);