1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
19 #pragma implementation
22 #include "insettabular.h"
25 #include "commandtags.h"
27 #include "LaTeXFeatures.h"
31 #include "lyx_gui_misc.h"
34 #include "insets/insettext.h"
35 #include "frontends/Dialogs.h"
50 const int ADD_TO_HEIGHT = 2;
51 const int ADD_TO_TABULAR_WIDTH = 2;
53 LyXTabular * paste_tabular = 0;
56 struct tabular_features {
57 LyXTabular::Feature action;
61 //tabular_features * tabularFeatures = 0;
63 tabular_features tabularFeatures[] =
65 { LyXTabular::APPEND_ROW, "append-row" },
66 { LyXTabular::APPEND_COLUMN, "append-column" },
67 { LyXTabular::DELETE_ROW, "delete-row" },
68 { LyXTabular::DELETE_COLUMN, "delete-column" },
69 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
70 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
71 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
72 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
73 { LyXTabular::ALIGN_LEFT, "align-left" },
74 { LyXTabular::ALIGN_RIGHT, "align-right" },
75 { LyXTabular::ALIGN_CENTER, "align-center" },
76 { LyXTabular::VALIGN_TOP, "valign-top" },
77 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
78 { LyXTabular::VALIGN_CENTER, "valign-center" },
79 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
80 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
81 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
82 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
83 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
84 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
85 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
86 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
87 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
88 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
89 { LyXTabular::MULTICOLUMN, "multicolumn" },
90 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
91 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
92 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
93 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
94 { LyXTabular::SET_PWIDTH, "set-pwidth" },
95 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
96 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
97 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
98 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
99 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
100 { LyXTabular::SET_USEBOX, "set-usebox" },
101 { LyXTabular::SET_LTHEAD, "set-lthead" },
102 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
103 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
104 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
105 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
106 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
107 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
108 { LyXTabular::LAST_ACTION, "" }
114 bool InsetTabular::hasPasteBuffer() const
116 return (paste_tabular != 0);
120 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
127 //tabular = new LyXTabular(this, rows,columns);
128 tabular.reset(new LyXTabular(this, rows,columns));
129 // for now make it always display as display() inset
131 the_locking_inset = 0;
132 locked = no_selection = false;
134 cursor_visible = false;
137 actrow = actcell = 0;
144 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
147 //tabular = new LyXTabular(this, *(tab.tabular));
148 tabular.reset(new LyXTabular(this, *(tab.tabular)));
149 the_locking_inset = 0;
150 locked = no_selection = false;
152 cursor_visible = false;
155 actrow = actcell = 0;
156 sel_cell_start = sel_cell_end = 0;
162 InsetTabular::~InsetTabular()
169 Inset * InsetTabular::Clone(Buffer const & buf) const
171 InsetTabular * t = new InsetTabular(*this, buf);
173 //t->tabular = tabular->Clone(t);
174 t->tabular.reset(tabular->Clone(t));
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");
192 //tabular = new LyXTabular(buf, this, lex);
193 tabular.reset(new LyXTabular(buf, this, lex));
201 string token = lex.GetString();
202 while (lex.IsOK() && (token != "\\end_inset")) {
204 token = lex.GetString();
206 if (token != "\\end_inset") {
207 lex.printError("Missing \\end_inset at this point. "
213 int InsetTabular::ascent(BufferView *, LyXFont const &) const
215 return tabular->GetAscentOfRow(0);
219 int InsetTabular::descent(BufferView *, LyXFont const &) const
221 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
225 int InsetTabular::width(BufferView *, LyXFont const &) const
227 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
231 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
232 float & x, bool cleared) const
237 Painter & pain = bv->painter();
242 UpdatableInset::draw(bv, font, baseline, x, cleared);
243 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
244 (top_x != int(x)) || (top_baseline != baseline))) {
245 int h = ascent(bv, font) + descent(bv, font);
246 int const tx = display() || !owner() ? 0 : top_x;
247 int w = tx ? width(bv, font) : pain.paperWidth();
248 int ty = baseline - ascent(bv, font);
252 if ((ty + h) > pain.paperHeight())
253 h = pain.paperHeight();
254 if ((top_x + w) > pain.paperWidth())
255 w = pain.paperWidth();
256 pain.fillRectangle(tx, ty, w, h);
261 top_baseline = baseline;
262 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
265 x += ADD_TO_TABULAR_WIDTH;
269 first_visible_cell = -1;
270 for (i = 0; i < tabular->rows(); ++i) {
272 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
273 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
274 for (j = 0; j < tabular->columns(); ++j) {
275 if (tabular->IsPartOfMultiColumn(i, j))
277 cx = nx + tabular->GetBeginningOfTextInCell(cell);
279 if (first_visible_cell < 0)
280 first_visible_cell = cell;
282 DrawCellSelection(pain, nx, baseline, i, j, cell);
283 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
285 DrawCellLines(pain, nx, baseline, i, cell);
287 nx += tabular->GetWidthOfColumn(cell);
290 baseline += tabular->GetDescentOfRow(i) +
291 tabular->GetAscentOfRow(i + 1) +
292 tabular->GetAdditionalHeight(cell);
294 } else if (need_update == CELL) {
297 if (the_locking_inset) {
298 Inset * inset = tabular->GetCellInset(cell);
300 inset != the_locking_inset && i < tabular->rows();
303 inset != the_locking_inset
304 && j < tabular->columns();
306 if (tabular->IsPartOfMultiColumn(i, j))
308 nx += tabular->GetWidthOfColumn(cell);
310 inset = tabular->GetCellInset(cell);
312 if (tabular->row_of_cell(cell) > i) {
314 baseline += tabular->GetDescentOfRow(i) +
315 tabular->GetAscentOfRow(i + 1) +
316 tabular->GetAdditionalHeight(cell);
321 cell < actcell && i < tabular->rows(); ++i) {
322 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
323 if (tabular->IsPartOfMultiColumn(i, j))
325 nx += tabular->GetWidthOfColumn(cell);
328 if (tabular->row_of_cell(cell) > i) {
330 baseline += tabular->GetDescentOfRow(i) +
331 tabular->GetAscentOfRow(i + 1) +
332 tabular->GetAdditionalHeight(cell);
336 i = tabular->row_of_cell(cell);
337 if (the_locking_inset != tabular->GetCellInset(cell)) {
338 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
341 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
343 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
344 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
345 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
347 // clear only if we didn't have a change
348 if (need_update == CELL) {
349 // clear before the inset
352 baseline - tabular->GetAscentOfRow(i) + 1,
354 tabular->GetAscentOfRow(i) +
355 tabular->GetDescentOfRow(i) - 1);
356 // clear behind the inset
358 int(cx + the_locking_inset->width(bv,font) + 1),
359 baseline - tabular->GetAscentOfRow(i) + 1,
360 tabular->GetWidthOfColumn(cell) -
361 tabular->GetBeginningOfTextInCell(cell) -
362 the_locking_inset->width(bv,font) -
363 tabular->GetAdditionalWidth(cell) - 1,
364 tabular->GetAscentOfRow(i) +
365 tabular->GetDescentOfRow(i) - 1);
368 x -= ADD_TO_TABULAR_WIDTH;
369 x += width(bv, font);
370 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
377 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
378 int row, int cell) const
380 int x2 = x + tabular->GetWidthOfColumn(cell);
383 if (!tabular->TopAlreadyDrawed(cell)) {
384 on_off = !tabular->TopLine(cell);
385 pain.line(x, baseline - tabular->GetAscentOfRow(row),
386 x2, baseline - tabular->GetAscentOfRow(row),
387 on_off ? LColor::tabularonoffline : LColor::tabularline,
388 on_off ? Painter::line_onoffdash : Painter::line_solid);
390 on_off = !tabular->BottomLine(cell);
391 pain.line(x,baseline + tabular->GetDescentOfRow(row),
392 x2, baseline + tabular->GetDescentOfRow(row),
393 on_off ? LColor::tabularonoffline : LColor::tabularline,
394 on_off ? Painter::line_onoffdash : Painter::line_solid);
395 if (!tabular->LeftAlreadyDrawed(cell)) {
396 on_off = !tabular->LeftLine(cell);
397 pain.line(x, baseline - tabular->GetAscentOfRow(row),
398 x, baseline + tabular->GetDescentOfRow(row),
399 on_off ? LColor::tabularonoffline : LColor::tabularline,
400 on_off ? Painter::line_onoffdash : Painter::line_solid);
402 on_off = !tabular->RightLine(cell);
403 pain.line(x2 - tabular->GetAdditionalWidth(cell),
404 baseline - tabular->GetAscentOfRow(row),
405 x2 - tabular->GetAdditionalWidth(cell),
406 baseline + tabular->GetDescentOfRow(row),
407 on_off ? LColor::tabularonoffline : LColor::tabularline,
408 on_off ? Painter::line_onoffdash : Painter::line_solid);
412 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
413 int row, int column, int cell) const
415 int cs = tabular->column_of_cell(sel_cell_start);
416 int ce = tabular->column_of_cell(sel_cell_end);
419 cs = tabular->column_of_cell(sel_cell_end);
421 ce = tabular->right_column_of_cell(sel_cell_end);
424 int rs = tabular->row_of_cell(sel_cell_start);
425 int re = tabular->row_of_cell(sel_cell_end);
426 if (rs > re) swap(rs, re);
428 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
429 int w = tabular->GetWidthOfColumn(cell);
430 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
431 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
432 w, h, LColor::selection);
437 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
441 calculate_dimensions_of_cells(bv, font, true);
443 owner()->update(bv, font, true);
446 if (the_locking_inset) {
447 the_locking_inset->update(bv, font, reinit);
449 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
450 // inset_y = cursor.y();
452 switch (need_update) {
456 if (calculate_dimensions_of_cells(bv, font, false))
468 string const InsetTabular::EditMessage() const
470 return _("Opened Tabular Inset");
474 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
476 UpdatableInset::Edit(bv, x, y, button);
478 if (!bv->lockInset(this)) {
479 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
483 the_locking_inset = 0;
487 sel_cell_start = sel_cell_end = actcell;
488 bv->text->FinishUndo();
489 if (InsetHit(bv, x, y) && (button != 3)) {
490 ActivateCellInsetAbs(bv, x, y, button);
492 // UpdateLocal(bv, NONE, false);
493 // bv->getOwner()->getPopups().updateFormTabular();
497 void InsetTabular::InsetUnlock(BufferView * bv)
499 if (the_locking_inset) {
500 the_locking_inset->InsetUnlock(bv);
501 the_locking_inset = 0;
504 no_selection = false;
507 if (scroll() || hasSelection()) {
508 sel_cell_start = sel_cell_end = 0;
512 UpdateLocal(bv, FULL, false);
517 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
518 bool mark_dirty) const
520 if (need_update < what) // only set this if it has greater update
522 if ((what == INIT) && hasSelection())
525 if (need_update != NONE) {
526 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
527 if (locked) // && (what != NONE))
533 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
535 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
540 if (inset == tabular->GetCellInset(actcell)) {
541 lyxerr[Debug::INSETS] << "OK" << endl;
542 the_locking_inset = tabular->GetCellInset(actcell);
544 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
545 inset_y = cursor.y();
547 } else if (the_locking_inset && (the_locking_inset == inset)) {
548 lyxerr[Debug::INSETS] << "OK" << endl;
550 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
551 inset_y = cursor.y();
552 } else if (the_locking_inset) {
553 lyxerr[Debug::INSETS] << "MAYBE" << endl;
554 return the_locking_inset->LockInsetInInset(bv, inset);
556 lyxerr[Debug::INSETS] << "NOT OK" << endl;
561 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
564 if (!the_locking_inset)
566 if (the_locking_inset == inset) {
567 the_locking_inset->InsetUnlock(bv);
568 the_locking_inset = 0;
569 UpdateLocal(bv, CELL, false);
570 ShowInsetCursor(bv, false);
573 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
574 if (inset->LyxCode() == TABULAR_CODE &&
575 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) {
576 bv->owner()->getDialogs()->updateTabular(this);
585 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
587 if (!the_locking_inset)
589 if (the_locking_inset != inset) {
590 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
593 UpdateLocal(bv, CELL, false);
598 unsigned int InsetTabular::InsetInInsetY()
600 if (!the_locking_inset)
603 return inset_y + the_locking_inset->InsetInInsetY();
607 UpdatableInset * InsetTabular::GetLockingInset()
609 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
613 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
617 if (the_locking_inset)
618 return the_locking_inset->GetFirstLockingInsetOfType(c);
623 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
625 if (the_locking_inset)
626 return the_locking_inset->InsertInset(bv, inset);
631 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
633 if (hasSelection() && (button == 3))
636 if (hasSelection()) {
638 UpdateLocal(bv, SELECTION, false);
641 no_selection = false;
643 int const ocell = actcell;
644 int const orow = actrow;
649 UpdateLocal(bv, NONE, false);
650 sel_cell_start = sel_cell_end = actcell;
652 if ((ocell != actcell) && the_locking_inset) {
653 the_locking_inset->InsetUnlock(bv);
654 the_locking_inset = 0;
660 bool const inset_hit = InsetHit(bv, x, y);
662 if ((ocell == actcell) && the_locking_inset && inset_hit) {
664 the_locking_inset->InsetButtonPress(bv,
665 x - inset_x, y - inset_y,
668 } else if (the_locking_inset) {
669 the_locking_inset->InsetUnlock(bv);
671 the_locking_inset = 0;
673 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
676 if (inset_hit && bv->theLockingInset()) {
677 if (ActivateCellInsetAbs(bv, x, y, button))
678 the_locking_inset->InsetButtonPress(bv,
688 void InsetTabular::InsetButtonRelease(BufferView * bv,
689 int x, int y, int button)
692 if (the_locking_inset) {
694 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
695 i->InsetButtonRelease(bv, x, y, button);
699 bv->owner()->getDialogs()->showTabular(this);
702 if (the_locking_inset) {
703 the_locking_inset->InsetButtonRelease(bv,
704 x - inset_x, y - inset_y,
708 no_selection = false;
712 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
714 if (the_locking_inset) {
715 the_locking_inset->InsetMotionNotify(bv,
723 int const old_cell = actcell;
726 sel_cell_end = actcell;
727 if (sel_cell_end != old_cell)
728 UpdateLocal(bv, SELECTION, false);
731 no_selection = false;
735 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
737 if (the_locking_inset) {
738 the_locking_inset->InsetKeyPress(xke);
744 UpdatableInset::RESULT
745 InsetTabular::LocalDispatch(BufferView * bv,
749 // We need to save the value of the_locking_inset as the call to
750 // the_locking_inset->LocalDispatch might unlock it.
751 old_locking_inset = the_locking_inset;
752 no_selection = false;
753 UpdatableInset::RESULT result =
754 UpdatableInset::LocalDispatch(bv, action, arg);
755 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
760 if ((action < 0) && arg.empty())
763 bool hs = hasSelection();
766 // this one have priority over the locked InsetText!
772 if (the_locking_inset) {
773 UnlockInsetInInset(bv, the_locking_inset);
774 the_locking_inset = 0;
776 if (action == LFUN_TAB)
777 moveNextCell(bv, old_locking_inset != 0);
779 movePrevCell(bv, old_locking_inset != 0);
780 sel_cell_start = sel_cell_end = actcell;
782 UpdateLocal(bv, SELECTION, false);
786 // this to avoid compiler warnings.
791 if (the_locking_inset) {
792 result=the_locking_inset->LocalDispatch(bv, action, arg);
793 if (result == DISPATCHED_NOUPDATE) {
796 if (sc != scroll()) { // inset has been scrolled
797 the_locking_inset->ToggleInsetCursor(bv);
798 UpdateLocal(bv, FULL, false);
799 the_locking_inset->ToggleInsetCursor(bv);
802 } else if (result == DISPATCHED) {
803 the_locking_inset->ToggleInsetCursor(bv);
804 UpdateLocal(bv, CELL, false);
805 the_locking_inset->ToggleInsetCursor(bv);
807 } else if (result == FINISHED) {
814 // --- Cursor Movements ----------------------------------
816 if (tabular->IsLastCellInRow(actcell))
818 moveRight(bv, false);
819 sel_cell_end = actcell;
820 UpdateLocal(bv, SELECTION, false);
823 result = moveRight(bv);
824 sel_cell_start = sel_cell_end = actcell;
826 UpdateLocal(bv, SELECTION, false);
829 if (tabular->IsFirstCellInRow(actcell))
832 sel_cell_end = actcell;
833 UpdateLocal(bv, SELECTION, false);
836 result = moveLeft(bv);
837 sel_cell_start = sel_cell_end = actcell;
839 UpdateLocal(bv, SELECTION, false);
843 int const ocell = actcell;
845 if ((ocell == sel_cell_end) ||
846 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
847 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
849 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
850 UpdateLocal(bv, SELECTION, false);
854 result = moveDown(bv, old_locking_inset != 0);
855 sel_cell_start = sel_cell_end = actcell;
857 UpdateLocal(bv, SELECTION, false);
861 int const ocell = actcell;
863 if ((ocell == sel_cell_end) ||
864 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
865 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
867 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
868 UpdateLocal(bv, SELECTION, false);
872 result = moveUp(bv, old_locking_inset != 0);
873 sel_cell_start = sel_cell_end = actcell;
875 UpdateLocal(bv, SELECTION, false);
879 if (the_locking_inset) {
880 UnlockInsetInInset(bv, the_locking_inset);
881 the_locking_inset = 0;
883 if (bv->text->first + bv->painter().paperHeight() <
884 (top_baseline + tabular->GetHeightOfTabular()))
886 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
887 UpdateLocal(bv, FULL, false);
888 actcell = tabular->GetCellBelow(first_visible_cell) + column;
890 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
893 UpdateLocal(bv, CURSOR, false);
898 if (the_locking_inset) {
899 UnlockInsetInInset(bv, the_locking_inset);
900 the_locking_inset = 0;
902 if (top_baseline < 0) {
903 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
904 UpdateLocal(bv, FULL, false);
905 if (top_baseline > 0)
908 actcell = tabular->GetCellBelow(first_visible_cell) + column;
913 UpdateLocal(bv, CURSOR, false);
924 case LFUN_LAYOUT_TABULAR:
926 bv->owner()->getDialogs()->showTabular(this);
929 case LFUN_TABULAR_FEATURE:
930 if (!TabularFeatures(bv, arg))
931 result = UNDISPATCHED;
934 if (!copySelection(bv))
936 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
938 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
939 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
941 bv->text->cursor.par()->previous(),
942 bv->text->cursor.par()->next()
946 UpdateLocal(bv, INIT, true);
951 bv->text->FinishUndo();
954 case LFUN_PASTESELECTION:
956 string clip(bv->workarea()->getClipboard());
960 if (clip.find('\t') != string::npos) {
964 unsigned int len = clip.length();
965 string::size_type p = 0;
968 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
976 maxCols = max(cols, maxCols);
982 maxCols = max(cols, maxCols);
983 delete paste_tabular;
984 paste_tabular = new LyXTabular(this, rows, maxCols);
985 string::size_type op = 0;
987 int cells = paste_tabular->GetNumberOfCells();
989 while((cell < cells) && (p < len) &&
990 (p = clip.find_first_of("\t\n", p)) != string::npos) {
995 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1000 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1001 while(cols++ < maxCols)
1009 // check for the last cell if there is no trailing '\n'
1010 if ((cell < cells) && (op < len))
1011 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
1013 // so that the clipboard is used and it goes on
1015 // and executes LFUN_PASTESELECTION in insettext!
1016 delete paste_tabular;
1021 if (hasPasteBuffer()) {
1022 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1024 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
1025 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
1027 bv->text->cursor.par()->previous(),
1028 bv->text->cursor.par()->next()
1032 UpdateLocal(bv, INIT, true);
1035 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1037 // we try to activate the actual inset and put this event down to
1038 // the insets dispatch function.
1039 result = UNDISPATCHED;
1040 if (the_locking_inset)
1043 if (ActivateCellInset(bv)) {
1044 result = the_locking_inset->LocalDispatch(bv, action, arg);
1045 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1046 UnlockInsetInInset(bv, the_locking_inset);
1048 the_locking_inset = 0;
1049 return UNDISPATCHED;
1052 the_locking_inset->ToggleInsetCursor(bv);
1053 UpdateLocal(bv, CELL, false);
1054 the_locking_inset->ToggleInsetCursor(bv);
1059 if (result!=FINISHED) {
1060 if (!the_locking_inset) {
1061 ShowInsetCursor(bv);
1064 bv->unlockInset(this);
1069 int InsetTabular::Latex(Buffer const * buf, ostream & os,
1070 bool fragile, bool fp) const
1072 return tabular->Latex(buf, os, fragile, fp);
1076 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
1078 // This should be changed to a real ascii export
1079 return tabular->Ascii(buf, os);
1083 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1089 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1091 return tabular->DocBook(buf,os);
1095 void InsetTabular::Validate(LaTeXFeatures & features) const
1097 tabular->Validate(features);
1101 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1102 LyXFont const & font,
1109 bool changed = false;
1111 // if we have a locking_inset we should have to check only this cell for
1112 // change so I'll try this to have a boost, but who knows ;)
1113 if ((need_update != INIT) &&
1114 (the_locking_inset == tabular->GetCellInset(actcell))) {
1115 for(int i = 0; i < tabular->columns(); ++i) {
1116 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1118 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1121 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1122 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1123 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1126 for (int i = 0; i < tabular->rows(); ++i) {
1129 for (int j= 0; j < tabular->columns(); ++j) {
1130 if (tabular->IsPartOfMultiColumn(i,j))
1133 inset = tabular->GetCellInset(cell);
1135 inset->update(bv, font, false);
1136 maxAsc = max(maxAsc, inset->ascent(bv, font));
1137 maxDesc = max(maxDesc, inset->descent(bv, font));
1138 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1140 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1141 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1147 void InsetTabular::GetCursorPos(BufferView *,
1148 int & x, int & y) const
1150 x = cursor.x() - top_x;
1155 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1157 if (the_locking_inset) {
1158 the_locking_inset->ToggleInsetCursor(bv);
1162 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1164 int const asc = lyxfont::maxAscent(font);
1165 int const desc = lyxfont::maxDescent(font);
1167 if (isCursorVisible())
1168 bv->hideLockedInsetCursor();
1170 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1171 toggleCursorVisible();
1175 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1177 if (!isCursorVisible()) {
1178 LyXFont font; // = GetFont(par, cursor.pos);
1180 int const asc = lyxfont::maxAscent(font);
1181 int const desc = lyxfont::maxDescent(font);
1182 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1184 bv->showLockedInsetCursor(cursor.x(), cursor.y(),
1186 setCursorVisible(true);
1191 void InsetTabular::HideInsetCursor(BufferView * bv)
1193 if (isCursorVisible()) {
1194 bv->hideLockedInsetCursor();
1195 setCursorVisible(false);
1197 // if (cursor_visible)
1198 // ToggleInsetCursor(bv);
1202 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1206 actcell = actrow = actcol = 0;
1207 int ly = tabular->GetDescentOfRow(actrow);
1209 // first search the right row
1210 while((ly < y) && (actrow < tabular->rows())) {
1212 + tabular->GetDescentOfRow(actrow)
1213 + tabular->GetAscentOfRow(actrow + 1)
1215 GetAdditionalHeight(tabular->
1216 GetCellNumber(actrow + 1,
1219 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1221 actcell = tabular->GetCellNumber(actrow, actcol);
1223 // now search the right column
1224 int lx = tabular->GetWidthOfColumn(actcell) -
1225 tabular->GetAdditionalWidth(actcell);
1227 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1228 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1229 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1230 tabular->GetAdditionalWidth(actcell - 1));
1232 // Jürgen, you should check that this is correct. (Lgb)
1233 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1234 lx += tabular->GetWidthOfColumn(actcell + 1)
1235 + tabular->GetAdditionalWidth(actcell);
1239 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1244 int InsetTabular::getCellXPos(int cell) const
1248 for (; !tabular->IsFirstCellInRow(c); --c)
1250 int lx = tabular->GetWidthOfColumn(cell);
1251 for (; c < cell; ++c) {
1252 lx += tabular->GetWidthOfColumn(c);
1254 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1258 void InsetTabular::resetPos(BufferView * bv) const
1262 actcol = tabular->column_of_cell(actcell);
1267 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1268 if (tabular->IsLastCellInRow(cell)) {
1270 + tabular->GetDescentOfRow(actrow)
1271 + tabular->GetAscentOfRow(actrow + 1)
1272 + tabular->GetAdditionalHeight(cell + 1));
1276 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1277 int new_x = getCellXPos(actcell);
1278 int old_x = cursor.x();
1281 // cursor.x(getCellXPos(actcell) + offset);
1282 if (scroll() && (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1284 else if (the_locking_inset &&
1285 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20)) {
1286 int xx = cursor.x() - offset + bv->text->GetRealCursorX(bv);
1287 if (xx > (bv->workWidth()-20))
1288 scroll(bv, -(xx - bv->workWidth() + 60));
1296 } else if ((cursor.x() - offset) > 20 &&
1297 (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
1298 > (bv->workWidth() - 20)) {
1299 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1300 UpdateLocal(bv, FULL, false);
1301 } else if ((cursor.x() - offset) < 20) {
1302 scroll(bv, 20 - cursor.x() + offset);
1303 UpdateLocal(bv, FULL, false);
1304 } else if (scroll() && top_x > 20 &&
1305 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1306 scroll(bv, old_x - cursor.x());
1308 if ((!the_locking_inset ||
1309 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1310 actcell != oldcell) {
1311 InsetTabular * inset = const_cast<InsetTabular *>(this);
1312 bv->owner()->getDialogs()->updateTabular(inset);
1318 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1320 if (lock && !old_locking_inset) {
1321 if (ActivateCellInset(bv))
1324 bool moved = isRightToLeft(bv)
1325 ? movePrevCell(bv) : moveNextCell(bv);
1328 if (lock && ActivateCellInset(bv))
1332 return DISPATCHED_NOUPDATE;
1336 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1338 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1341 if (lock) { // behind the inset
1342 if (ActivateCellInset(bv, 0, 0, 0, true))
1346 return DISPATCHED_NOUPDATE;
1350 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1352 int const ocell = actcell;
1353 actcell = tabular->GetCellAbove(actcell);
1354 if (actcell == ocell) // we moved out of the inset
1360 if (old_locking_inset) {
1361 old_locking_inset->GetCursorPos(bv, x, y);
1362 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1364 if (ActivateCellInset(bv, x, 0))
1367 return DISPATCHED_NOUPDATE;
1371 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1373 int const ocell = actcell;
1374 actcell = tabular->GetCellBelow(actcell);
1375 if (actcell == ocell) // we moved out of the inset
1381 if (old_locking_inset) {
1382 old_locking_inset->GetCursorPos(bv, x, y);
1383 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1385 if (ActivateCellInset(bv, x, 0))
1388 return DISPATCHED_NOUPDATE;
1392 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1394 if (isRightToLeft(bv)) {
1395 if (tabular->IsFirstCellInRow(actcell)) {
1396 int row = tabular->row_of_cell(actcell);
1397 if (row == tabular->rows() - 1)
1399 actcell = tabular->GetLastCellInRow(row);
1400 actcell = tabular->GetCellBelow(actcell);
1407 if (tabular->IsLastCell(actcell))
1412 bool rtl = tabular->GetCellInset(actcell)->par->
1413 isRightToLeftPar(bv->buffer()->params);
1414 ActivateCellInset(bv, 0, 0, 0, !rtl);
1421 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1423 if (isRightToLeft(bv)) {
1424 if (tabular->IsLastCellInRow(actcell)) {
1425 int row = tabular->row_of_cell(actcell);
1428 actcell = tabular->GetFirstCellInRow(row);
1429 actcell = tabular->GetCellAbove(actcell);
1431 if (tabular->IsLastCell(actcell))
1436 if (!actcell) // first cell
1441 bool rtl = tabular->GetCellInset(actcell)->par->
1442 isRightToLeftPar(bv->buffer()->params);
1443 ActivateCellInset(bv, 0, 0, 0, !rtl);
1450 bool InsetTabular::Delete()
1456 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1458 if (the_locking_inset)
1459 the_locking_inset->SetFont(bv, font, tall);
1463 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1465 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1468 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1469 string const tmp = tabularFeatures[i].feature;
1471 if (tmp == what.substr(0, tmp.length())) {
1472 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1473 //tabularFeatures[i].feature.length())) {
1474 action = tabularFeatures[i].action;
1478 if (action == LyXTabular::LAST_ACTION)
1482 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1483 TabularFeatures(bv, action, val);
1488 void InsetTabular::TabularFeatures(BufferView * bv,
1489 LyXTabular::Feature feature,
1490 string const & value)
1498 bool setLines = false;
1499 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1500 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1505 case LyXTabular::M_ALIGN_LEFT:
1506 case LyXTabular::ALIGN_LEFT:
1507 setAlign=LYX_ALIGN_LEFT;
1509 case LyXTabular::M_ALIGN_RIGHT:
1510 case LyXTabular::ALIGN_RIGHT:
1511 setAlign=LYX_ALIGN_RIGHT;
1513 case LyXTabular::M_ALIGN_CENTER:
1514 case LyXTabular::ALIGN_CENTER:
1515 setAlign=LYX_ALIGN_CENTER;
1517 case LyXTabular::M_VALIGN_TOP:
1518 case LyXTabular::VALIGN_TOP:
1519 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1521 case LyXTabular::M_VALIGN_BOTTOM:
1522 case LyXTabular::VALIGN_BOTTOM:
1523 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1525 case LyXTabular::M_VALIGN_CENTER:
1526 case LyXTabular::VALIGN_CENTER:
1527 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1532 if (hasSelection()) {
1533 sel_col_start = tabular->column_of_cell(sel_cell_start);
1534 sel_col_end = tabular->column_of_cell(sel_cell_end);
1535 if (sel_col_start > sel_col_end) {
1536 sel_col_end = sel_col_start;
1537 sel_col_start = tabular->column_of_cell(sel_cell_end);
1539 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1542 sel_row_start = tabular->row_of_cell(sel_cell_start);
1543 sel_row_end = tabular->row_of_cell(sel_cell_end);
1544 if (sel_row_start > sel_row_end) {
1545 //int tmp = sel_row_start;
1546 //sel_row_start = sel_row_end;
1547 //sel_row_end = tmp;
1548 swap(sel_row_start, sel_row_end);
1551 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1552 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1554 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1556 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
1557 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
1559 bv->text->cursor.par()->previous(),
1560 bv->text->cursor.par()->next()
1564 int row = tabular->row_of_cell(actcell);
1565 int column = tabular->column_of_cell(actcell);
1569 case LyXTabular::SET_PWIDTH:
1571 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1572 tabular->SetColumnPWidth(actcell,value);
1574 for (int i = 0; i < tabular->rows(); ++i) {
1575 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1578 UpdateLocal(bv, INIT, true);
1582 case LyXTabular::SET_MPWIDTH:
1584 bool const update = (tabular->GetPWidth(actcell) != value);
1585 tabular->SetMColumnPWidth(actcell,value);
1587 for (int i = 0; i < tabular->rows(); ++i) {
1588 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1591 UpdateLocal(bv, INIT, true);
1595 case LyXTabular::SET_SPECIAL_COLUMN:
1596 case LyXTabular::SET_SPECIAL_MULTI:
1597 tabular->SetAlignSpecial(actcell,value,feature);
1599 case LyXTabular::APPEND_ROW:
1600 // append the row into the tabular
1601 UnlockInsetInInset(bv, the_locking_inset);
1602 tabular->AppendRow(actcell);
1603 UpdateLocal(bv, INIT, true);
1605 case LyXTabular::APPEND_COLUMN:
1606 // append the column into the tabular
1607 UnlockInsetInInset(bv, the_locking_inset);
1608 tabular->AppendColumn(actcell);
1609 actcell = tabular->GetCellNumber(row, column);
1610 UpdateLocal(bv, INIT, true);
1612 case LyXTabular::DELETE_ROW:
1613 UnlockInsetInInset(bv, the_locking_inset);
1614 tabular->DeleteRow(tabular->row_of_cell(actcell));
1615 if ((row+1) > tabular->rows())
1617 actcell = tabular->GetCellNumber(row, column);
1619 UpdateLocal(bv, INIT, true);
1621 case LyXTabular::DELETE_COLUMN:
1622 UnlockInsetInInset(bv, the_locking_inset);
1623 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1624 if ((column+1) > tabular->columns())
1626 actcell = tabular->GetCellNumber(row, column);
1628 UpdateLocal(bv, INIT, true);
1630 case LyXTabular::M_TOGGLE_LINE_TOP:
1632 case LyXTabular::TOGGLE_LINE_TOP:
1634 bool lineSet = !tabular->TopLine(actcell, flag);
1635 for (int i = sel_row_start; i <= sel_row_end; ++i)
1636 for (int j = sel_col_start; j <= sel_col_end; ++j)
1637 tabular->SetTopLine(
1638 tabular->GetCellNumber(i, j),
1640 UpdateLocal(bv, INIT, true);
1644 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1646 case LyXTabular::TOGGLE_LINE_BOTTOM:
1648 bool lineSet = !tabular->BottomLine(actcell, flag);
1649 for (int i = sel_row_start; i <= sel_row_end; ++i)
1650 for (int j = sel_col_start; j <= sel_col_end; ++j)
1651 tabular->SetBottomLine(
1652 tabular->GetCellNumber(i, j),
1655 UpdateLocal(bv, INIT, true);
1659 case LyXTabular::M_TOGGLE_LINE_LEFT:
1661 case LyXTabular::TOGGLE_LINE_LEFT:
1663 bool lineSet = !tabular->LeftLine(actcell, flag);
1664 for (int i = sel_row_start; i <= sel_row_end; ++i)
1665 for (int j = sel_col_start; j <= sel_col_end; ++j)
1666 tabular->SetLeftLine(
1667 tabular->GetCellNumber(i,j),
1670 UpdateLocal(bv, INIT, true);
1674 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1676 case LyXTabular::TOGGLE_LINE_RIGHT:
1678 bool lineSet = !tabular->RightLine(actcell, flag);
1679 for (int i = sel_row_start; i <= sel_row_end; ++i)
1680 for (int j = sel_col_start; j <= sel_col_end; ++j)
1681 tabular->SetRightLine(
1682 tabular->GetCellNumber(i,j),
1685 UpdateLocal(bv, INIT, true);
1689 case LyXTabular::M_ALIGN_LEFT:
1690 case LyXTabular::M_ALIGN_RIGHT:
1691 case LyXTabular::M_ALIGN_CENTER:
1693 case LyXTabular::ALIGN_LEFT:
1694 case LyXTabular::ALIGN_RIGHT:
1695 case LyXTabular::ALIGN_CENTER:
1696 for (int i = sel_row_start; i <= sel_row_end; ++i)
1697 for (int j = sel_col_start; j <= sel_col_end; ++j)
1698 tabular->SetAlignment(
1699 tabular->GetCellNumber(i, j),
1702 UpdateLocal(bv, INIT, true);
1704 case LyXTabular::M_VALIGN_TOP:
1705 case LyXTabular::M_VALIGN_BOTTOM:
1706 case LyXTabular::M_VALIGN_CENTER:
1708 case LyXTabular::VALIGN_TOP:
1709 case LyXTabular::VALIGN_BOTTOM:
1710 case LyXTabular::VALIGN_CENTER:
1711 for (int i = sel_row_start; i <= sel_row_end; ++i)
1712 for (int j = sel_col_start; j <= sel_col_end; ++j)
1713 tabular->SetVAlignment(
1714 tabular->GetCellNumber(i, j),
1716 UpdateLocal(bv, INIT, true);
1718 case LyXTabular::MULTICOLUMN:
1720 if (sel_row_start != sel_row_end) {
1721 WriteAlert(_("Impossible Operation!"),
1722 _("Multicolumns can only be horizontally."),
1726 // just multicol for one Single Cell
1727 if (!hasSelection()) {
1728 // check wether we are completly in a multicol
1729 if (tabular->IsMultiColumn(actcell)) {
1730 tabular->UnsetMultiColumn(actcell);
1731 UpdateLocal(bv, INIT, true);
1733 tabular->SetMultiColumn(actcell, 1);
1734 UpdateLocal(bv, CELL, true);
1738 // we have a selection so this means we just add all this
1739 // cells to form a multicolumn cell
1743 if (sel_cell_start > sel_cell_end) {
1744 s_start = sel_cell_end;
1745 s_end = sel_cell_start;
1747 s_start = sel_cell_start;
1748 s_end = sel_cell_end;
1750 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1752 sel_cell_end = sel_cell_start;
1753 UpdateLocal(bv, INIT, true);
1756 case LyXTabular::SET_ALL_LINES:
1758 case LyXTabular::UNSET_ALL_LINES:
1759 for (int i = sel_row_start; i <= sel_row_end; ++i)
1760 for (int j = sel_col_start; j <= sel_col_end; ++j)
1761 tabular->SetAllLines(
1762 tabular->GetCellNumber(i,j), setLines);
1763 UpdateLocal(bv, INIT, true);
1765 case LyXTabular::SET_LONGTABULAR:
1766 tabular->SetLongTabular(true);
1767 UpdateLocal(bv, INIT, true); // because this toggles displayed
1769 case LyXTabular::UNSET_LONGTABULAR:
1770 tabular->SetLongTabular(false);
1771 UpdateLocal(bv, INIT, true); // because this toggles displayed
1773 case LyXTabular::SET_ROTATE_TABULAR:
1774 tabular->SetRotateTabular(true);
1776 case LyXTabular::UNSET_ROTATE_TABULAR:
1777 tabular->SetRotateTabular(false);
1779 case LyXTabular::SET_ROTATE_CELL:
1780 for (int i = sel_row_start; i <= sel_row_end; ++i)
1781 for (int j = sel_col_start; j<=sel_col_end; ++j)
1782 tabular->SetRotateCell(
1783 tabular->GetCellNumber(i, j),
1786 case LyXTabular::UNSET_ROTATE_CELL:
1787 for (int i = sel_row_start; i <= sel_row_end; ++i)
1788 for (int j = sel_col_start; j <= sel_col_end; ++j)
1789 tabular->SetRotateCell(
1790 tabular->GetCellNumber(i, j), false);
1792 case LyXTabular::SET_USEBOX:
1794 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1795 if (val == tabular->GetUsebox(actcell))
1796 val = LyXTabular::BOX_NONE;
1797 for (int i = sel_row_start; i <= sel_row_end; ++i)
1798 for (int j = sel_col_start; j <= sel_col_end; ++j)
1800 tabular->GetCellNumber(i, j), val);
1803 case LyXTabular::SET_LTFIRSTHEAD:
1804 tabular->SetLTHead(actcell, true);
1806 case LyXTabular::SET_LTHEAD:
1807 tabular->SetLTHead(actcell, false);
1809 case LyXTabular::SET_LTFOOT:
1810 tabular->SetLTFoot(actcell, false);
1812 case LyXTabular::SET_LTLASTFOOT:
1813 tabular->SetLTFoot(actcell, true);
1815 case LyXTabular::SET_LTNEWPAGE:
1817 bool what = !tabular->GetLTNewPage(actcell);
1818 tabular->SetLTNewPage(actcell, what);
1821 // dummy stuff just to avoid warnings
1822 case LyXTabular::LAST_ACTION:
1828 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1831 UpdatableInset * inset =
1832 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1833 LyXFont font(LyXFont::ALL_SANE);
1835 x = inset->x() + inset->width(bv, font);
1836 y = inset->descent(bv, font);
1838 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1839 //inset_y = cursor.y();
1840 inset->Edit(bv, x, y, button);
1841 if (!the_locking_inset)
1843 UpdateLocal(bv, CELL, false);
1844 return (the_locking_inset != 0);
1848 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1851 inset_x = cursor.x()
1852 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1853 inset_y = cursor.y();
1854 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1858 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1861 > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
1865 // This returns paperWidth() if the cell-width is unlimited or the width
1866 // in pixels if we have a pwidth for this cell.
1867 int InsetTabular::GetMaxWidthOfCell(BufferView * bv, int cell) const
1869 string const s = tabular->GetPWidth(cell);
1873 return VSpace(s).inPixels(bv);
1877 int InsetTabular::getMaxWidth(BufferView * bv,
1878 UpdatableInset const * inset) const
1880 int const n = tabular->GetNumberOfCells();
1882 for (; cell < n; ++cell) {
1883 if (tabular->GetCellInset(cell) == inset)
1888 int w = GetMaxWidthOfCell(bv, cell);
1890 // because the inset then subtracts it's top_x and owner->x()
1891 w += (inset->x() - top_x);
1896 void InsetTabular::resizeLyXText(BufferView *) const
1902 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1903 bool const recursive) const
1905 if (the_locking_inset)
1906 return the_locking_inset->getLyXText(bv, recursive);
1907 return Inset::getLyXText(bv, recursive);
1911 bool InsetTabular::ShowInsetDialog(BufferView * bv) const
1913 if (!the_locking_inset || !the_locking_inset->ShowInsetDialog(bv))
1914 bv->owner()->getDialogs()
1915 ->showTabular(const_cast<InsetTabular *>(this));
1920 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1922 if (the_locking_inset) {
1923 InsetTabular * i = static_cast<InsetTabular *>
1924 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1926 i->OpenLayoutDialog(bv);
1930 bv->owner()->getDialogs()->showTabular(
1931 const_cast<InsetTabular *>(this));
1935 // functions returns:
1939 // 3 ... toggled off
1941 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1943 int action = LyXTabular::LAST_ACTION;
1944 LyXFunc::func_status status = LyXFunc::OK;
1947 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1948 string const tmp = tabularFeatures[i].feature;
1949 if (tmp == what.substr(0, tmp.length())) {
1950 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1951 // tabularFeatures[i].feature.length())) {
1952 action = tabularFeatures[i].action;
1956 if (action == LyXTabular::LAST_ACTION)
1957 return LyXFunc::Unknown;
1959 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1966 if (hasSelection()) {
1967 sel_row_start = tabular->row_of_cell(sel_cell_start);
1968 sel_row_end = tabular->row_of_cell(sel_cell_end);
1969 if (sel_row_start > sel_row_end) {
1970 //int tmp = sel_row_start;
1971 //sel_row_start = sel_row_end;
1972 //sel_row_end = tmp;
1973 swap(sel_row_start, sel_row_end);
1976 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1980 case LyXTabular::SET_PWIDTH:
1981 case LyXTabular::SET_MPWIDTH:
1982 case LyXTabular::SET_SPECIAL_COLUMN:
1983 case LyXTabular::SET_SPECIAL_MULTI:
1984 status |= LyXFunc::Disabled;
1987 case LyXTabular::APPEND_ROW:
1988 case LyXTabular::APPEND_COLUMN:
1989 case LyXTabular::DELETE_ROW:
1990 case LyXTabular::DELETE_COLUMN:
1991 case LyXTabular::SET_ALL_LINES:
1992 case LyXTabular::UNSET_ALL_LINES:
1993 status |= LyXFunc::OK;
1996 case LyXTabular::MULTICOLUMN:
1997 if (tabular->IsMultiColumn(actcell))
1998 status |= LyXFunc::ToggleOn;
2000 status |= LyXFunc::ToggleOff;
2002 case LyXTabular::M_TOGGLE_LINE_TOP:
2004 case LyXTabular::TOGGLE_LINE_TOP:
2005 if (tabular->TopLine(actcell, flag))
2006 status |= LyXFunc::ToggleOn;
2008 status |= LyXFunc::ToggleOff;
2010 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2012 case LyXTabular::TOGGLE_LINE_BOTTOM:
2013 if (tabular->BottomLine(actcell, flag))
2014 status |= LyXFunc::ToggleOn;
2016 status |= LyXFunc::ToggleOff;
2018 case LyXTabular::M_TOGGLE_LINE_LEFT:
2020 case LyXTabular::TOGGLE_LINE_LEFT:
2021 if (tabular->LeftLine(actcell, flag))
2022 status |= LyXFunc::ToggleOn;
2024 status |= LyXFunc::ToggleOff;
2026 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2028 case LyXTabular::TOGGLE_LINE_RIGHT:
2029 if (tabular->RightLine(actcell, flag))
2030 status |= LyXFunc::ToggleOn;
2032 status |= LyXFunc::ToggleOff;
2034 case LyXTabular::M_ALIGN_LEFT:
2036 case LyXTabular::ALIGN_LEFT:
2037 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2038 status |= LyXFunc::ToggleOn;
2040 status |= LyXFunc::ToggleOff;
2042 case LyXTabular::M_ALIGN_RIGHT:
2044 case LyXTabular::ALIGN_RIGHT:
2045 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2046 status |= LyXFunc::ToggleOn;
2048 status |= LyXFunc::ToggleOff;
2050 case LyXTabular::M_ALIGN_CENTER:
2052 case LyXTabular::ALIGN_CENTER:
2053 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2054 status |= LyXFunc::ToggleOn;
2056 status |= LyXFunc::ToggleOff;
2058 case LyXTabular::M_VALIGN_TOP:
2060 case LyXTabular::VALIGN_TOP:
2061 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2062 status |= LyXFunc::ToggleOn;
2064 status |= LyXFunc::ToggleOff;
2066 case LyXTabular::M_VALIGN_BOTTOM:
2068 case LyXTabular::VALIGN_BOTTOM:
2069 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2070 status |= LyXFunc::ToggleOn;
2072 status |= LyXFunc::ToggleOff;
2074 case LyXTabular::M_VALIGN_CENTER:
2076 case LyXTabular::VALIGN_CENTER:
2077 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2078 status |= LyXFunc::ToggleOn;
2080 status |= LyXFunc::ToggleOff;
2082 case LyXTabular::SET_LONGTABULAR:
2083 if (tabular->IsLongTabular())
2084 status |= LyXFunc::ToggleOn;
2086 status |= LyXFunc::ToggleOff;
2088 case LyXTabular::UNSET_LONGTABULAR:
2089 if (!tabular->IsLongTabular())
2090 status |= LyXFunc::ToggleOn;
2092 status |= LyXFunc::ToggleOff;
2094 case LyXTabular::SET_ROTATE_TABULAR:
2095 if (tabular->GetRotateTabular())
2096 status |= LyXFunc::ToggleOn;
2098 status |= LyXFunc::ToggleOff;
2100 case LyXTabular::UNSET_ROTATE_TABULAR:
2101 if (!tabular->GetRotateTabular())
2102 status |= LyXFunc::ToggleOn;
2104 status |= LyXFunc::ToggleOff;
2106 case LyXTabular::SET_ROTATE_CELL:
2107 if (tabular->GetRotateCell(actcell))
2108 status |= LyXFunc::ToggleOn;
2110 status |= LyXFunc::ToggleOff;
2112 case LyXTabular::UNSET_ROTATE_CELL:
2113 if (!tabular->GetRotateCell(actcell))
2114 status |= LyXFunc::ToggleOn;
2116 status |= LyXFunc::ToggleOff;
2118 case LyXTabular::SET_USEBOX:
2119 if (strToInt(argument) == tabular->GetUsebox(actcell))
2120 status |= LyXFunc::ToggleOn;
2122 status |= LyXFunc::ToggleOff;
2124 case LyXTabular::SET_LTFIRSTHEAD:
2125 if (tabular->GetRowOfLTHead(actcell, dummy))
2126 status |= LyXFunc::ToggleOn;
2128 status |= LyXFunc::ToggleOff;
2130 case LyXTabular::SET_LTHEAD:
2131 if (tabular->GetRowOfLTHead(actcell, dummy))
2132 status |= LyXFunc::ToggleOn;
2134 status |= LyXFunc::ToggleOff;
2136 case LyXTabular::SET_LTFOOT:
2137 if (tabular->GetRowOfLTFoot(actcell, dummy))
2138 status |= LyXFunc::ToggleOn;
2140 status |= LyXFunc::ToggleOff;
2142 case LyXTabular::SET_LTLASTFOOT:
2143 if (tabular->GetRowOfLTFoot(actcell, dummy))
2144 status |= LyXFunc::ToggleOn;
2146 status |= LyXFunc::ToggleOff;
2148 case LyXTabular::SET_LTNEWPAGE:
2149 if (tabular->GetLTNewPage(actcell))
2150 status |= LyXFunc::ToggleOn;
2152 status |= LyXFunc::ToggleOff;
2155 status = LyXFunc::Disabled;
2162 bool InsetTabular::copySelection(BufferView * bv)
2164 if (!hasSelection())
2166 //delete paste_tabular;
2168 //int sel_col_start;
2170 //int sel_row_start;
2173 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2174 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2175 if (sel_col_start > sel_col_end) {
2176 sel_col_start = sel_col_end;
2177 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2179 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2181 int const columns = sel_col_end - sel_col_start + 1;
2183 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2184 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2185 if (sel_row_start > sel_row_end) {
2186 //int tmp tmp = sel_row_start;
2187 //sel_row_start = sel_row_end;
2188 //sel_row_end = tmp;
2189 swap(sel_row_start, sel_row_end);
2191 int const rows = sel_row_end - sel_row_start + 1;
2193 delete paste_tabular;
2194 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2196 for (int i = 0; i < sel_row_start; ++i)
2197 paste_tabular->DeleteRow(0);
2198 while(paste_tabular->rows() > rows)
2199 paste_tabular->DeleteRow(rows);
2200 paste_tabular->SetTopLine(0, true, true);
2201 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2203 for (int i = 0; i < sel_col_start; ++i)
2204 paste_tabular->DeleteColumn(0);
2205 while (paste_tabular->columns() > columns)
2206 paste_tabular->DeleteColumn(columns);
2207 paste_tabular->SetLeftLine(0, true, true);
2208 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2212 paste_tabular->Ascii(bv->buffer(), sstr);
2213 bv->stuffClipboard(sstr.str().c_str());
2218 bool InsetTabular::pasteSelection(BufferView * bv)
2223 for (int r1 = 0, r2 = actrow;
2224 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2226 for(int c1 = 0, c2 = actcol;
2227 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2229 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2230 tabular->IsPartOfMultiColumn(r2,c2))
2232 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2236 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2240 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2241 int const n2 = tabular->GetCellNumber(r2, c2);
2242 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2243 tabular->GetCellInset(n2)->setOwner(this);
2244 tabular->GetCellInset(n2)->deleteLyXText(bv);
2251 bool InsetTabular::cutSelection()
2253 if (!hasSelection())
2256 //int sel_col_start;
2258 //int sel_row_start;
2261 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2262 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2263 if (sel_col_start > sel_col_end) {
2264 sel_col_start = sel_col_end;
2265 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2267 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2269 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2270 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2271 if (sel_row_start > sel_row_end) {
2272 //int tmp = sel_row_start;
2273 //sel_row_start = sel_row_end;
2274 //sel_row_end = tmp;
2275 swap(sel_row_start, sel_row_end);
2277 if (sel_cell_start > sel_cell_end) {
2278 //int tmp = sel_cell_start;
2279 //sel_cell_start = sel_cell_end;
2280 //sel_cell_end = tmp;
2281 swap(sel_cell_start, sel_cell_end);
2283 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2284 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2285 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2292 bool InsetTabular::isRightToLeft(BufferView *bv )
2294 return bv->getParentLanguage(this)->RightToLeft();