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"
52 const int ADD_TO_HEIGHT = 2;
53 const int ADD_TO_TABULAR_WIDTH = 2;
55 LyXTabular * paste_tabular = 0;
58 struct tabular_features {
59 LyXTabular::Feature action;
63 //tabular_features * tabularFeatures = 0;
65 tabular_features tabularFeatures[] =
67 { LyXTabular::APPEND_ROW, "append-row" },
68 { LyXTabular::APPEND_COLUMN, "append-column" },
69 { LyXTabular::DELETE_ROW, "delete-row" },
70 { LyXTabular::DELETE_COLUMN, "delete-column" },
71 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
72 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
73 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
74 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
75 { LyXTabular::ALIGN_LEFT, "align-left" },
76 { LyXTabular::ALIGN_RIGHT, "align-right" },
77 { LyXTabular::ALIGN_CENTER, "align-center" },
78 { LyXTabular::VALIGN_TOP, "valign-top" },
79 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
80 { LyXTabular::VALIGN_CENTER, "valign-center" },
81 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
82 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
83 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
84 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
85 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
86 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
87 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
88 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
89 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
90 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
91 { LyXTabular::MULTICOLUMN, "multicolumn" },
92 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
93 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
94 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
95 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
96 { LyXTabular::SET_PWIDTH, "set-pwidth" },
97 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
98 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
99 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
100 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
101 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
102 { LyXTabular::SET_USEBOX, "set-usebox" },
103 { LyXTabular::SET_LTHEAD, "set-lthead" },
104 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
105 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
106 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
107 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
108 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
109 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
110 { LyXTabular::LAST_ACTION, "" }
116 bool InsetTabular::hasPasteBuffer() const
118 return (paste_tabular != 0);
122 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
129 //tabular = new LyXTabular(this, rows,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 cursor_visible = false;
139 actrow = actcell = 0;
145 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
148 //tabular = new LyXTabular(this, *(tab.tabular));
149 tabular.reset(new LyXTabular(this, *(tab.tabular)));
150 the_locking_inset = 0;
151 locked = no_selection = false;
153 cursor_visible = false;
156 actrow = actcell = 0;
157 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
236 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
239 // lyxerr << "InsetTabular::draw(" << need_update << ")\n";
241 Painter & pain = bv->painter();
247 UpdatableInset::draw(bv, font, baseline, x, cleared);
250 x += (float)scroll();
252 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
253 (top_x != int(x)) || (top_baseline != baseline))) {
254 int h = ascent(bv, font) + descent(bv, font);
255 int const tx = display() || !owner() ? 0 : top_x;
256 int w = tx ? width(bv, font) : pain.paperWidth();
257 int ty = baseline - ascent(bv, font);
261 if ((ty + h) > pain.paperHeight())
262 h = pain.paperHeight();
263 if ((top_x + w) > pain.paperWidth())
264 w = pain.paperWidth();
265 pain.fillRectangle(tx, ty, w, h);
270 top_baseline = baseline;
271 x += ADD_TO_TABULAR_WIDTH;
275 first_visible_cell = -1;
276 for (i = 0; i < tabular->rows(); ++i) {
278 cell = tabular->GetCellNumber(i, 0);
279 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
280 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
282 baseline += tabular->GetDescentOfRow(i) +
283 tabular->GetAscentOfRow(i + 1) +
284 tabular->GetAdditionalHeight(i + 1);
287 for (j = 0; j < tabular->columns(); ++j) {
288 if (nx > bv->workWidth())
290 if (tabular->IsPartOfMultiColumn(i, j))
292 cx = nx + tabular->GetBeginningOfTextInCell(cell);
293 if (first_visible_cell < 0)
294 first_visible_cell = cell;
296 DrawCellSelection(pain, nx, baseline, i, j, cell);
297 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
299 DrawCellLines(pain, nx, baseline, i, cell);
300 nx += tabular->GetWidthOfColumn(cell);
303 baseline += tabular->GetDescentOfRow(i) +
304 tabular->GetAscentOfRow(i + 1) +
305 tabular->GetAdditionalHeight(i + 1);
307 } else if (need_update == CELL) {
310 if (the_locking_inset &&
311 tabular->GetCellInset(actcell) != the_locking_inset)
313 Inset * inset = tabular->GetCellInset(cell);
315 inset != the_locking_inset && i < tabular->rows();
318 inset != the_locking_inset
319 && j < tabular->columns();
321 if (tabular->IsPartOfMultiColumn(i, j))
323 nx += tabular->GetWidthOfColumn(cell);
325 inset = tabular->GetCellInset(cell);
327 if (tabular->row_of_cell(cell) > i) {
329 baseline += tabular->GetDescentOfRow(i) +
330 tabular->GetAscentOfRow(i + 1) +
331 tabular->GetAdditionalHeight(i + 1);
335 // copute baseline for actual row
336 for (i = 0; i < actrow; ++i) {
337 baseline += tabular->GetDescentOfRow(i) +
338 tabular->GetAscentOfRow(i + 1) +
339 tabular->GetAdditionalHeight(i + 1);
341 // now compute the right x position
342 cell = tabular->GetCellNumber(actrow, 0);
343 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
344 if (tabular->IsPartOfMultiColumn(actrow, j))
346 nx += tabular->GetWidthOfColumn(cell);
350 i = tabular->row_of_cell(cell);
351 if (the_locking_inset != tabular->GetCellInset(cell)) {
352 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
355 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
357 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
358 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
359 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
361 // clear only if we didn't have a change
362 if (need_update == CELL) {
363 // clear before the inset
366 baseline - tabular->GetAscentOfRow(i) + 1,
368 tabular->GetAscentOfRow(i) +
369 tabular->GetDescentOfRow(i) - 1);
370 // clear behind the inset
372 int(cx + the_locking_inset->width(bv,font) + 1),
373 baseline - tabular->GetAscentOfRow(i) + 1,
374 tabular->GetWidthOfColumn(cell) -
375 tabular->GetBeginningOfTextInCell(cell) -
376 the_locking_inset->width(bv,font) -
377 tabular->GetAdditionalWidth(cell) - 1,
378 tabular->GetAscentOfRow(i) +
379 tabular->GetDescentOfRow(i) - 1);
382 x -= ADD_TO_TABULAR_WIDTH;
383 x += width(bv, font);
384 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
391 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
392 int row, int cell) const
394 int x2 = x + tabular->GetWidthOfColumn(cell);
397 if (!tabular->TopAlreadyDrawed(cell)) {
398 on_off = !tabular->TopLine(cell);
399 pain.line(x, baseline - tabular->GetAscentOfRow(row),
400 x2, baseline - tabular->GetAscentOfRow(row),
401 on_off ? LColor::tabularonoffline : LColor::tabularline,
402 on_off ? Painter::line_onoffdash : Painter::line_solid);
404 on_off = !tabular->BottomLine(cell);
405 pain.line(x,baseline + tabular->GetDescentOfRow(row),
406 x2, baseline + tabular->GetDescentOfRow(row),
407 on_off ? LColor::tabularonoffline : LColor::tabularline,
408 on_off ? Painter::line_onoffdash : Painter::line_solid);
409 if (!tabular->LeftAlreadyDrawed(cell)) {
410 on_off = !tabular->LeftLine(cell);
411 pain.line(x, baseline - tabular->GetAscentOfRow(row),
412 x, baseline + tabular->GetDescentOfRow(row),
413 on_off ? LColor::tabularonoffline : LColor::tabularline,
414 on_off ? Painter::line_onoffdash : Painter::line_solid);
416 on_off = !tabular->RightLine(cell);
417 pain.line(x2 - tabular->GetAdditionalWidth(cell),
418 baseline - tabular->GetAscentOfRow(row),
419 x2 - tabular->GetAdditionalWidth(cell),
420 baseline + tabular->GetDescentOfRow(row),
421 on_off ? LColor::tabularonoffline : LColor::tabularline,
422 on_off ? Painter::line_onoffdash : Painter::line_solid);
426 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
427 int row, int column, int cell) const
429 int cs = tabular->column_of_cell(sel_cell_start);
430 int ce = tabular->column_of_cell(sel_cell_end);
433 cs = tabular->column_of_cell(sel_cell_end);
435 ce = tabular->right_column_of_cell(sel_cell_end);
438 int rs = tabular->row_of_cell(sel_cell_start);
439 int re = tabular->row_of_cell(sel_cell_end);
440 if (rs > re) swap(rs, re);
442 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
443 int w = tabular->GetWidthOfColumn(cell);
444 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
445 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
446 w, h, LColor::selection);
451 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
455 calculate_dimensions_of_cells(bv, font, true);
457 owner()->update(bv, font, true);
460 if (the_locking_inset)
461 the_locking_inset->update(bv, font, reinit);
463 switch (need_update) {
467 if (calculate_dimensions_of_cells(bv, font, false))
479 string const InsetTabular::EditMessage() const
481 return _("Opened Tabular Inset");
485 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
487 UpdatableInset::Edit(bv, x, y, button);
489 if (!bv->lockInset(this)) {
490 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
494 the_locking_inset = 0;
498 sel_cell_start = sel_cell_end = actcell;
499 bv->text->FinishUndo();
500 if (InsetHit(bv, x, y) && (button != 3)) {
501 ActivateCellInsetAbs(bv, x, y, button);
503 // UpdateLocal(bv, NONE, false);
504 // bv->getOwner()->getPopups().updateFormTabular();
508 void InsetTabular::InsetUnlock(BufferView * bv)
510 if (the_locking_inset) {
511 the_locking_inset->InsetUnlock(bv);
512 the_locking_inset = 0;
515 no_selection = false;
518 if (scroll(false) || hasSelection()) {
519 sel_cell_start = sel_cell_end = 0;
523 UpdateLocal(bv, FULL, false);
528 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
529 bool mark_dirty) const
531 if (need_update < what) // only set this if it has greater update
533 if ((what == INIT) && hasSelection())
536 if (need_update != NONE) {
537 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
538 if (locked) // && (what != NONE))
544 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
546 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
551 if (inset == tabular->GetCellInset(actcell)) {
552 lyxerr[Debug::INSETS] << "OK" << endl;
553 the_locking_inset = tabular->GetCellInset(actcell);
555 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
556 inset_y = cursor.y();
558 } else if (the_locking_inset && (the_locking_inset == inset)) {
559 lyxerr[Debug::INSETS] << "OK" << endl;
561 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
562 inset_y = cursor.y();
563 } else if (the_locking_inset) {
564 lyxerr[Debug::INSETS] << "MAYBE" << endl;
565 return the_locking_inset->LockInsetInInset(bv, inset);
567 lyxerr[Debug::INSETS] << "NOT OK" << endl;
572 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
575 if (!the_locking_inset)
577 if (the_locking_inset == inset) {
578 the_locking_inset->InsetUnlock(bv);
579 the_locking_inset = 0;
583 UpdateLocal(bv, CELL, false);
584 ShowInsetCursor(bv, false);
587 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
588 if (inset->LyxCode() == TABULAR_CODE &&
589 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) {
590 bv->owner()->getDialogs()->updateTabular(this);
599 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
601 if (!the_locking_inset)
603 if (the_locking_inset != inset) {
604 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
607 UpdateLocal(bv, CELL, false);
612 unsigned int InsetTabular::InsetInInsetY()
614 if (!the_locking_inset)
617 return inset_y + the_locking_inset->InsetInInsetY();
621 UpdatableInset * InsetTabular::GetLockingInset()
623 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
627 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
631 if (the_locking_inset)
632 return the_locking_inset->GetFirstLockingInsetOfType(c);
637 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
639 if (the_locking_inset)
640 return the_locking_inset->InsertInset(bv, inset);
645 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
647 if (hasSelection() && (button == 3))
650 if (hasSelection()) {
652 UpdateLocal(bv, SELECTION, false);
655 no_selection = false;
657 int const ocell = actcell;
658 int const orow = actrow;
663 UpdateLocal(bv, NONE, false);
664 sel_cell_start = sel_cell_end = actcell;
666 if ((ocell != actcell) && the_locking_inset) {
667 the_locking_inset->InsetUnlock(bv);
668 the_locking_inset = 0;
674 bool const inset_hit = InsetHit(bv, x, y);
676 if ((ocell == actcell) && the_locking_inset && inset_hit) {
678 the_locking_inset->InsetButtonPress(bv,
679 x - inset_x, y - inset_y,
682 } else if (the_locking_inset) {
683 the_locking_inset->InsetUnlock(bv);
685 the_locking_inset = 0;
687 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
690 if (inset_hit && bv->theLockingInset()) {
691 if (ActivateCellInsetAbs(bv, x, y, button))
692 the_locking_inset->InsetButtonPress(bv,
702 void InsetTabular::InsetButtonRelease(BufferView * bv,
703 int x, int y, int button)
706 if (the_locking_inset) {
708 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
709 i->InsetButtonRelease(bv, x, y, button);
713 bv->owner()->getDialogs()->showTabular(this);
716 if (the_locking_inset) {
717 the_locking_inset->InsetButtonRelease(bv,
718 x - inset_x, y - inset_y,
722 no_selection = false;
726 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
728 if (the_locking_inset) {
729 the_locking_inset->InsetMotionNotify(bv,
737 int const old_cell = actcell;
740 sel_cell_end = actcell;
741 if (sel_cell_end != old_cell)
742 UpdateLocal(bv, SELECTION, false);
745 no_selection = false;
749 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
751 if (the_locking_inset) {
752 the_locking_inset->InsetKeyPress(xke);
758 UpdatableInset::RESULT
759 InsetTabular::LocalDispatch(BufferView * bv,
763 // We need to save the value of the_locking_inset as the call to
764 // the_locking_inset->LocalDispatch might unlock it.
765 old_locking_inset = the_locking_inset;
766 no_selection = false;
767 UpdatableInset::RESULT result =
768 UpdatableInset::LocalDispatch(bv, action, arg);
769 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
774 if ((action < 0) && arg.empty())
777 bool hs = hasSelection();
780 // this one have priority over the locked InsetText!
786 if (the_locking_inset) {
787 UnlockInsetInInset(bv, the_locking_inset);
788 the_locking_inset = 0;
790 if (action == LFUN_TAB)
791 moveNextCell(bv, old_locking_inset != 0);
793 movePrevCell(bv, old_locking_inset != 0);
794 sel_cell_start = sel_cell_end = actcell;
796 UpdateLocal(bv, SELECTION, false);
797 if (!the_locking_inset) {
799 return DISPATCHED_NOUPDATE;
803 // this to avoid compiler warnings.
808 if (the_locking_inset) {
809 result=the_locking_inset->LocalDispatch(bv, action, arg);
810 if (result == DISPATCHED_NOUPDATE) {
813 if (sc != scroll()) { // inset has been scrolled
814 the_locking_inset->ToggleInsetCursor(bv);
815 UpdateLocal(bv, FULL, false);
816 the_locking_inset->ToggleInsetCursor(bv);
819 } else if (result == DISPATCHED) {
820 the_locking_inset->ToggleInsetCursor(bv);
821 UpdateLocal(bv, CELL, false);
822 the_locking_inset->ToggleInsetCursor(bv);
824 } else if (result == FINISHED) {
831 // --- Cursor Movements ----------------------------------
833 if (tabular->IsLastCellInRow(actcell))
835 moveRight(bv, false);
836 sel_cell_end = actcell;
837 UpdateLocal(bv, SELECTION, false);
840 result = moveRight(bv);
841 sel_cell_start = sel_cell_end = actcell;
843 UpdateLocal(bv, SELECTION, false);
846 if (tabular->IsFirstCellInRow(actcell))
849 sel_cell_end = actcell;
850 UpdateLocal(bv, SELECTION, false);
853 result = moveLeft(bv);
854 sel_cell_start = sel_cell_end = actcell;
856 UpdateLocal(bv, SELECTION, false);
860 int const ocell = actcell;
862 if ((ocell == sel_cell_end) ||
863 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
864 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
866 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
867 UpdateLocal(bv, SELECTION, false);
871 result = moveDown(bv, old_locking_inset != 0);
872 sel_cell_start = sel_cell_end = actcell;
874 UpdateLocal(bv, SELECTION, false);
878 int const ocell = actcell;
880 if ((ocell == sel_cell_end) ||
881 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
882 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
884 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
885 UpdateLocal(bv, SELECTION, false);
889 result = moveUp(bv, old_locking_inset != 0);
890 sel_cell_start = sel_cell_end = actcell;
892 UpdateLocal(bv, SELECTION, false);
896 if (the_locking_inset) {
897 UnlockInsetInInset(bv, the_locking_inset);
898 the_locking_inset = 0;
900 if (bv->text->first + bv->painter().paperHeight() <
901 (top_baseline + tabular->GetHeightOfTabular()))
903 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
904 UpdateLocal(bv, FULL, false);
905 actcell = tabular->GetCellBelow(first_visible_cell) + column;
907 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
910 UpdateLocal(bv, CURSOR, false);
915 if (the_locking_inset) {
916 UnlockInsetInInset(bv, the_locking_inset);
917 the_locking_inset = 0;
919 if (top_baseline < 0) {
920 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
921 UpdateLocal(bv, FULL, false);
922 if (top_baseline > 0)
925 actcell = tabular->GetCellBelow(first_visible_cell) + column;
930 UpdateLocal(bv, CURSOR, false);
941 case LFUN_LAYOUT_TABULAR:
943 bv->owner()->getDialogs()->showTabular(this);
946 case LFUN_TABULAR_FEATURE:
947 if (!TabularFeatures(bv, arg))
948 result = UNDISPATCHED;
951 if (!copySelection(bv))
953 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
955 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
956 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
958 bv->text->cursor.par()->previous(),
959 bv->text->cursor.par()->next()
963 UpdateLocal(bv, INIT, true);
968 bv->text->FinishUndo();
971 case LFUN_PASTESELECTION:
973 string clip(bv->workarea()->getClipboard());
977 if (clip.find('\t') != string::npos) {
981 unsigned int len = clip.length();
982 string::size_type p = 0;
985 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
993 maxCols = max(cols, maxCols);
999 maxCols = max(cols, maxCols);
1000 delete paste_tabular;
1001 paste_tabular = new LyXTabular(this, rows, maxCols);
1002 string::size_type op = 0;
1004 int cells = paste_tabular->GetNumberOfCells();
1006 while((cell < cells) && (p < len) &&
1007 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1012 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1017 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1018 while(cols++ < maxCols)
1026 // check for the last cell if there is no trailing '\n'
1027 if ((cell < cells) && (op < len))
1028 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
1030 // so that the clipboard is used and it goes on
1032 // and executes LFUN_PASTESELECTION in insettext!
1033 delete paste_tabular;
1038 if (hasPasteBuffer()) {
1039 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1041 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
1042 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
1044 bv->text->cursor.par()->previous(),
1045 bv->text->cursor.par()->next()
1049 UpdateLocal(bv, INIT, true);
1052 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1054 // we try to activate the actual inset and put this event down to
1055 // the insets dispatch function.
1056 result = UNDISPATCHED;
1057 if (the_locking_inset)
1060 if (ActivateCellInset(bv)) {
1061 result = the_locking_inset->LocalDispatch(bv, action, arg);
1062 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1063 UnlockInsetInInset(bv, the_locking_inset);
1065 the_locking_inset = 0;
1066 return UNDISPATCHED;
1069 // the_locking_inset->ToggleInsetCursor(bv);
1070 UpdateLocal(bv, CELL, false);
1071 // the_locking_inset->ToggleInsetCursor(bv);
1076 if (result!=FINISHED) {
1077 if (!the_locking_inset) {
1078 ShowInsetCursor(bv);
1081 bv->unlockInset(this);
1086 int InsetTabular::Latex(Buffer const * buf, ostream & os,
1087 bool fragile, bool fp) const
1089 return tabular->Latex(buf, os, fragile, fp);
1093 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
1095 // This should be changed to a real ascii export
1096 return tabular->Ascii(buf, os);
1100 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1106 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1108 return tabular->DocBook(buf,os);
1112 void InsetTabular::Validate(LaTeXFeatures & features) const
1114 tabular->Validate(features);
1118 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1119 LyXFont const & font,
1126 bool changed = false;
1128 // if we have a locking_inset we should have to check only this cell for
1129 // change so I'll try this to have a boost, but who knows ;)
1130 if ((need_update != INIT) &&
1131 (the_locking_inset == tabular->GetCellInset(actcell))) {
1132 for(int i = 0; i < tabular->columns(); ++i) {
1133 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1135 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1138 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1139 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1140 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1143 for (int i = 0; i < tabular->rows(); ++i) {
1146 for (int j= 0; j < tabular->columns(); ++j) {
1147 if (tabular->IsPartOfMultiColumn(i,j))
1150 inset = tabular->GetCellInset(cell);
1152 inset->update(bv, font, false);
1153 maxAsc = max(maxAsc, inset->ascent(bv, font));
1154 maxDesc = max(maxDesc, inset->descent(bv, font));
1155 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1157 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1158 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1164 void InsetTabular::GetCursorPos(BufferView *,
1165 int & x, int & y) const
1167 x = cursor.x() - top_x;
1172 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1174 if (the_locking_inset) {
1175 the_locking_inset->ToggleInsetCursor(bv);
1179 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1181 int const asc = lyxfont::maxAscent(font);
1182 int const desc = lyxfont::maxDescent(font);
1184 if (isCursorVisible())
1185 bv->hideLockedInsetCursor();
1187 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1188 toggleCursorVisible();
1192 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1194 if (!isCursorVisible()) {
1195 LyXFont font; // = GetFont(par, cursor.pos);
1197 int const asc = lyxfont::maxAscent(font);
1198 int const desc = lyxfont::maxDescent(font);
1199 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1201 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1202 setCursorVisible(true);
1207 void InsetTabular::HideInsetCursor(BufferView * bv)
1209 if (isCursorVisible()) {
1210 bv->hideLockedInsetCursor();
1211 setCursorVisible(false);
1213 // if (cursor_visible)
1214 // ToggleInsetCursor(bv);
1218 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1222 actcell = actrow = actcol = 0;
1223 int ly = tabular->GetDescentOfRow(actrow);
1225 // first search the right row
1226 while((ly < y) && (actrow < tabular->rows())) {
1227 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1228 tabular->GetAscentOfRow(actrow + 1) +
1229 tabular->GetAdditionalHeight(actrow + 1));
1231 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1233 actcell = tabular->GetCellNumber(actrow, actcol);
1235 // now search the right column
1236 int lx = tabular->GetWidthOfColumn(actcell) -
1237 tabular->GetAdditionalWidth(actcell);
1239 #ifdef WITH_WARNINGS
1240 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1242 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1243 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1244 tabular->GetAdditionalWidth(actcell - 1));
1246 // Jürgen, you should check that this is correct. (Lgb)
1247 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1248 lx += tabular->GetWidthOfColumn(actcell + 1)
1249 + tabular->GetAdditionalWidth(actcell);
1253 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1258 int InsetTabular::getCellXPos(int cell) const
1262 for (; !tabular->IsFirstCellInRow(c); --c)
1264 int lx = tabular->GetWidthOfColumn(cell);
1265 for (; c < cell; ++c) {
1266 lx += tabular->GetWidthOfColumn(c);
1268 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1272 void InsetTabular::resetPos(BufferView * bv) const
1276 actcol = tabular->column_of_cell(actcell);
1281 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1282 if (tabular->IsLastCellInRow(cell)) {
1283 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1284 tabular->GetAscentOfRow(actrow + 1) +
1285 tabular->GetAdditionalHeight(actrow + 1));
1289 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1290 int new_x = getCellXPos(actcell);
1291 int old_x = cursor.x();
1294 // cursor.x(getCellXPos(actcell) + offset);
1295 if (scroll(false) && (tabular->GetWidthOfTabular() < bv->workWidth()-20)) {
1297 UpdateLocal(bv, FULL, false);
1298 } else if (the_locking_inset &&
1299 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20)) {
1300 int xx = cursor.x() - offset + bv->text->GetRealCursorX(bv);
1301 if (xx > (bv->workWidth()-20))
1302 scroll(bv, -(xx - bv->workWidth() + 60));
1310 UpdateLocal(bv, FULL, false);
1311 } else if ((cursor.x() - offset) > 20 &&
1312 (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
1313 > (bv->workWidth() - 20)) {
1314 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1315 UpdateLocal(bv, FULL, false);
1316 } else if ((cursor.x() - offset) < 20) {
1317 scroll(bv, 20 - cursor.x() + offset);
1318 UpdateLocal(bv, FULL, false);
1319 } else if (scroll(false) && top_x > 20 &&
1320 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1321 scroll(bv, old_x - cursor.x());
1322 UpdateLocal(bv, FULL, false);
1324 if ((!the_locking_inset ||
1325 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1326 actcell != oldcell) {
1327 InsetTabular * inset = const_cast<InsetTabular *>(this);
1328 bv->owner()->getDialogs()->updateTabular(inset);
1334 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1336 if (lock && !old_locking_inset) {
1337 if (ActivateCellInset(bv))
1340 bool moved = isRightToLeft(bv)
1341 ? movePrevCell(bv) : moveNextCell(bv);
1344 if (lock && ActivateCellInset(bv))
1348 return DISPATCHED_NOUPDATE;
1352 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1354 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1357 if (lock) { // behind the inset
1358 if (ActivateCellInset(bv, 0, 0, 0, true))
1362 return DISPATCHED_NOUPDATE;
1366 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1368 int const ocell = actcell;
1369 actcell = tabular->GetCellAbove(actcell);
1370 if (actcell == ocell) // we moved out of the inset
1376 if (old_locking_inset) {
1377 old_locking_inset->GetCursorPos(bv, x, y);
1378 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1380 if (ActivateCellInset(bv, x, 0))
1383 return DISPATCHED_NOUPDATE;
1387 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1389 int const ocell = actcell;
1390 actcell = tabular->GetCellBelow(actcell);
1391 if (actcell == ocell) // we moved out of the inset
1397 if (old_locking_inset) {
1398 old_locking_inset->GetCursorPos(bv, x, y);
1399 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1401 if (ActivateCellInset(bv, x, 0))
1404 return DISPATCHED_NOUPDATE;
1408 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1410 if (isRightToLeft(bv)) {
1411 if (tabular->IsFirstCellInRow(actcell)) {
1412 int row = tabular->row_of_cell(actcell);
1413 if (row == tabular->rows() - 1)
1415 actcell = tabular->GetLastCellInRow(row);
1416 actcell = tabular->GetCellBelow(actcell);
1423 if (tabular->IsLastCell(actcell))
1428 bool rtl = tabular->GetCellInset(actcell)->par->
1429 isRightToLeftPar(bv->buffer()->params);
1430 ActivateCellInset(bv, 0, 0, 0, !rtl);
1437 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1439 if (isRightToLeft(bv)) {
1440 if (tabular->IsLastCellInRow(actcell)) {
1441 int row = tabular->row_of_cell(actcell);
1444 actcell = tabular->GetFirstCellInRow(row);
1445 actcell = tabular->GetCellAbove(actcell);
1447 if (tabular->IsLastCell(actcell))
1452 if (!actcell) // first cell
1457 bool rtl = tabular->GetCellInset(actcell)->par->
1458 isRightToLeftPar(bv->buffer()->params);
1459 ActivateCellInset(bv, 0, 0, 0, !rtl);
1466 bool InsetTabular::Delete()
1472 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1474 if (the_locking_inset)
1475 the_locking_inset->SetFont(bv, font, tall);
1479 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1481 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1484 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1485 string const tmp = tabularFeatures[i].feature;
1487 if (tmp == what.substr(0, tmp.length())) {
1488 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1489 //tabularFeatures[i].feature.length())) {
1490 action = tabularFeatures[i].action;
1494 if (action == LyXTabular::LAST_ACTION)
1498 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1499 TabularFeatures(bv, action, val);
1504 void InsetTabular::TabularFeatures(BufferView * bv,
1505 LyXTabular::Feature feature,
1506 string const & value)
1514 bool setLines = false;
1515 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1516 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1521 case LyXTabular::M_ALIGN_LEFT:
1522 case LyXTabular::ALIGN_LEFT:
1523 setAlign=LYX_ALIGN_LEFT;
1525 case LyXTabular::M_ALIGN_RIGHT:
1526 case LyXTabular::ALIGN_RIGHT:
1527 setAlign=LYX_ALIGN_RIGHT;
1529 case LyXTabular::M_ALIGN_CENTER:
1530 case LyXTabular::ALIGN_CENTER:
1531 setAlign=LYX_ALIGN_CENTER;
1533 case LyXTabular::M_VALIGN_TOP:
1534 case LyXTabular::VALIGN_TOP:
1535 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1537 case LyXTabular::M_VALIGN_BOTTOM:
1538 case LyXTabular::VALIGN_BOTTOM:
1539 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1541 case LyXTabular::M_VALIGN_CENTER:
1542 case LyXTabular::VALIGN_CENTER:
1543 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1548 if (hasSelection()) {
1549 sel_col_start = tabular->column_of_cell(sel_cell_start);
1550 sel_col_end = tabular->column_of_cell(sel_cell_end);
1551 if (sel_col_start > sel_col_end) {
1552 sel_col_end = sel_col_start;
1553 sel_col_start = tabular->column_of_cell(sel_cell_end);
1555 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1558 sel_row_start = tabular->row_of_cell(sel_cell_start);
1559 sel_row_end = tabular->row_of_cell(sel_cell_end);
1560 if (sel_row_start > sel_row_end) {
1561 //int tmp = sel_row_start;
1562 //sel_row_start = sel_row_end;
1563 //sel_row_end = tmp;
1564 swap(sel_row_start, sel_row_end);
1567 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1568 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1570 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1572 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
1573 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
1575 bv->text->cursor.par()->previous(),
1576 bv->text->cursor.par()->next()
1580 int row = tabular->row_of_cell(actcell);
1581 int column = tabular->column_of_cell(actcell);
1585 case LyXTabular::SET_PWIDTH:
1587 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1588 tabular->SetColumnPWidth(actcell,value);
1590 for (int i = 0; i < tabular->rows(); ++i) {
1591 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1594 UpdateLocal(bv, INIT, true);
1598 case LyXTabular::SET_MPWIDTH:
1600 bool const update = (tabular->GetPWidth(actcell) != value);
1601 tabular->SetMColumnPWidth(actcell,value);
1603 for (int i = 0; i < tabular->rows(); ++i) {
1604 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1607 UpdateLocal(bv, INIT, true);
1611 case LyXTabular::SET_SPECIAL_COLUMN:
1612 case LyXTabular::SET_SPECIAL_MULTI:
1613 tabular->SetAlignSpecial(actcell,value,feature);
1615 case LyXTabular::APPEND_ROW:
1616 // append the row into the tabular
1617 UnlockInsetInInset(bv, the_locking_inset);
1618 tabular->AppendRow(actcell);
1619 UpdateLocal(bv, INIT, true);
1621 case LyXTabular::APPEND_COLUMN:
1622 // append the column into the tabular
1623 UnlockInsetInInset(bv, the_locking_inset);
1624 tabular->AppendColumn(actcell);
1625 actcell = tabular->GetCellNumber(row, column);
1626 UpdateLocal(bv, INIT, true);
1628 case LyXTabular::DELETE_ROW:
1629 UnlockInsetInInset(bv, the_locking_inset);
1630 tabular->DeleteRow(tabular->row_of_cell(actcell));
1631 if ((row+1) > tabular->rows())
1633 actcell = tabular->GetCellNumber(row, column);
1635 UpdateLocal(bv, INIT, true);
1637 case LyXTabular::DELETE_COLUMN:
1638 UnlockInsetInInset(bv, the_locking_inset);
1639 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1640 if ((column+1) > tabular->columns())
1642 actcell = tabular->GetCellNumber(row, column);
1644 UpdateLocal(bv, INIT, true);
1646 case LyXTabular::M_TOGGLE_LINE_TOP:
1648 case LyXTabular::TOGGLE_LINE_TOP:
1650 bool lineSet = !tabular->TopLine(actcell, flag);
1651 for (int i = sel_row_start; i <= sel_row_end; ++i)
1652 for (int j = sel_col_start; j <= sel_col_end; ++j)
1653 tabular->SetTopLine(
1654 tabular->GetCellNumber(i, j),
1656 UpdateLocal(bv, INIT, true);
1660 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1662 case LyXTabular::TOGGLE_LINE_BOTTOM:
1664 bool lineSet = !tabular->BottomLine(actcell, flag);
1665 for (int i = sel_row_start; i <= sel_row_end; ++i)
1666 for (int j = sel_col_start; j <= sel_col_end; ++j)
1667 tabular->SetBottomLine(
1668 tabular->GetCellNumber(i, j),
1671 UpdateLocal(bv, INIT, true);
1675 case LyXTabular::M_TOGGLE_LINE_LEFT:
1677 case LyXTabular::TOGGLE_LINE_LEFT:
1679 bool lineSet = !tabular->LeftLine(actcell, flag);
1680 for (int i = sel_row_start; i <= sel_row_end; ++i)
1681 for (int j = sel_col_start; j <= sel_col_end; ++j)
1682 tabular->SetLeftLine(
1683 tabular->GetCellNumber(i,j),
1686 UpdateLocal(bv, INIT, true);
1690 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1692 case LyXTabular::TOGGLE_LINE_RIGHT:
1694 bool lineSet = !tabular->RightLine(actcell, flag);
1695 for (int i = sel_row_start; i <= sel_row_end; ++i)
1696 for (int j = sel_col_start; j <= sel_col_end; ++j)
1697 tabular->SetRightLine(
1698 tabular->GetCellNumber(i,j),
1701 UpdateLocal(bv, INIT, true);
1705 case LyXTabular::M_ALIGN_LEFT:
1706 case LyXTabular::M_ALIGN_RIGHT:
1707 case LyXTabular::M_ALIGN_CENTER:
1709 case LyXTabular::ALIGN_LEFT:
1710 case LyXTabular::ALIGN_RIGHT:
1711 case LyXTabular::ALIGN_CENTER:
1712 for (int i = sel_row_start; i <= sel_row_end; ++i)
1713 for (int j = sel_col_start; j <= sel_col_end; ++j)
1714 tabular->SetAlignment(
1715 tabular->GetCellNumber(i, j),
1718 UpdateLocal(bv, INIT, true);
1720 case LyXTabular::M_VALIGN_TOP:
1721 case LyXTabular::M_VALIGN_BOTTOM:
1722 case LyXTabular::M_VALIGN_CENTER:
1724 case LyXTabular::VALIGN_TOP:
1725 case LyXTabular::VALIGN_BOTTOM:
1726 case LyXTabular::VALIGN_CENTER:
1727 for (int i = sel_row_start; i <= sel_row_end; ++i)
1728 for (int j = sel_col_start; j <= sel_col_end; ++j)
1729 tabular->SetVAlignment(
1730 tabular->GetCellNumber(i, j),
1732 UpdateLocal(bv, INIT, true);
1734 case LyXTabular::MULTICOLUMN:
1736 if (sel_row_start != sel_row_end) {
1737 WriteAlert(_("Impossible Operation!"),
1738 _("Multicolumns can only be horizontally."),
1742 // just multicol for one Single Cell
1743 if (!hasSelection()) {
1744 // check wether we are completly in a multicol
1745 if (tabular->IsMultiColumn(actcell)) {
1746 tabular->UnsetMultiColumn(actcell);
1747 UpdateLocal(bv, INIT, true);
1749 tabular->SetMultiColumn(actcell, 1);
1750 UpdateLocal(bv, CELL, true);
1754 // we have a selection so this means we just add all this
1755 // cells to form a multicolumn cell
1759 if (sel_cell_start > sel_cell_end) {
1760 s_start = sel_cell_end;
1761 s_end = sel_cell_start;
1763 s_start = sel_cell_start;
1764 s_end = sel_cell_end;
1766 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1768 sel_cell_end = sel_cell_start;
1769 UpdateLocal(bv, INIT, true);
1772 case LyXTabular::SET_ALL_LINES:
1774 case LyXTabular::UNSET_ALL_LINES:
1775 for (int i = sel_row_start; i <= sel_row_end; ++i)
1776 for (int j = sel_col_start; j <= sel_col_end; ++j)
1777 tabular->SetAllLines(
1778 tabular->GetCellNumber(i,j), setLines);
1779 UpdateLocal(bv, INIT, true);
1781 case LyXTabular::SET_LONGTABULAR:
1782 tabular->SetLongTabular(true);
1783 UpdateLocal(bv, INIT, true); // because this toggles displayed
1785 case LyXTabular::UNSET_LONGTABULAR:
1786 tabular->SetLongTabular(false);
1787 UpdateLocal(bv, INIT, true); // because this toggles displayed
1789 case LyXTabular::SET_ROTATE_TABULAR:
1790 tabular->SetRotateTabular(true);
1792 case LyXTabular::UNSET_ROTATE_TABULAR:
1793 tabular->SetRotateTabular(false);
1795 case LyXTabular::SET_ROTATE_CELL:
1796 for (int i = sel_row_start; i <= sel_row_end; ++i)
1797 for (int j = sel_col_start; j<=sel_col_end; ++j)
1798 tabular->SetRotateCell(
1799 tabular->GetCellNumber(i, j),
1802 case LyXTabular::UNSET_ROTATE_CELL:
1803 for (int i = sel_row_start; i <= sel_row_end; ++i)
1804 for (int j = sel_col_start; j <= sel_col_end; ++j)
1805 tabular->SetRotateCell(
1806 tabular->GetCellNumber(i, j), false);
1808 case LyXTabular::SET_USEBOX:
1810 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1811 if (val == tabular->GetUsebox(actcell))
1812 val = LyXTabular::BOX_NONE;
1813 for (int i = sel_row_start; i <= sel_row_end; ++i)
1814 for (int j = sel_col_start; j <= sel_col_end; ++j)
1816 tabular->GetCellNumber(i, j), val);
1819 case LyXTabular::SET_LTFIRSTHEAD:
1820 tabular->SetLTHead(actcell, true);
1822 case LyXTabular::SET_LTHEAD:
1823 tabular->SetLTHead(actcell, false);
1825 case LyXTabular::SET_LTFOOT:
1826 tabular->SetLTFoot(actcell, false);
1828 case LyXTabular::SET_LTLASTFOOT:
1829 tabular->SetLTFoot(actcell, true);
1831 case LyXTabular::SET_LTNEWPAGE:
1833 bool what = !tabular->GetLTNewPage(actcell);
1834 tabular->SetLTNewPage(actcell, what);
1837 // dummy stuff just to avoid warnings
1838 case LyXTabular::LAST_ACTION:
1844 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1847 UpdatableInset * inset =
1848 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1849 LyXFont font(LyXFont::ALL_SANE);
1851 x = inset->x() + inset->width(bv, font);
1852 y = inset->descent(bv, font);
1854 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1855 //inset_y = cursor.y();
1856 inset->Edit(bv, x, y, button);
1857 if (!the_locking_inset)
1859 UpdateLocal(bv, CELL, false);
1860 return (the_locking_inset != 0);
1864 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1867 inset_x = cursor.x()
1868 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1869 inset_y = cursor.y();
1870 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1874 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1877 > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
1881 // This returns paperWidth() if the cell-width is unlimited or the width
1882 // in pixels if we have a pwidth for this cell.
1883 int InsetTabular::GetMaxWidthOfCell(BufferView * bv, int cell) const
1885 string const s = tabular->GetPWidth(cell);
1889 return VSpace(s).inPixels(bv);
1893 int InsetTabular::getMaxWidth(BufferView * bv,
1894 UpdatableInset const * inset) const
1896 int const n = tabular->GetNumberOfCells();
1898 for (; cell < n; ++cell) {
1899 if (tabular->GetCellInset(cell) == inset)
1904 int w = GetMaxWidthOfCell(bv, cell);
1906 // because the inset then subtracts it's top_x and owner->x()
1907 w += (inset->x() - top_x);
1912 void InsetTabular::resizeLyXText(BufferView *) const
1918 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1919 bool const recursive) const
1921 if (the_locking_inset)
1922 return the_locking_inset->getLyXText(bv, recursive);
1923 return Inset::getLyXText(bv, recursive);
1927 bool InsetTabular::ShowInsetDialog(BufferView * bv) const
1929 if (!the_locking_inset || !the_locking_inset->ShowInsetDialog(bv))
1930 bv->owner()->getDialogs()
1931 ->showTabular(const_cast<InsetTabular *>(this));
1936 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1938 if (the_locking_inset) {
1939 InsetTabular * i = static_cast<InsetTabular *>
1940 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1942 i->OpenLayoutDialog(bv);
1946 bv->owner()->getDialogs()->showTabular(
1947 const_cast<InsetTabular *>(this));
1951 // functions returns:
1955 // 3 ... toggled off
1957 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1959 int action = LyXTabular::LAST_ACTION;
1960 LyXFunc::func_status status = LyXFunc::OK;
1963 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1964 string const tmp = tabularFeatures[i].feature;
1965 if (tmp == what.substr(0, tmp.length())) {
1966 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1967 // tabularFeatures[i].feature.length())) {
1968 action = tabularFeatures[i].action;
1972 if (action == LyXTabular::LAST_ACTION)
1973 return LyXFunc::Unknown;
1975 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1982 if (hasSelection()) {
1983 sel_row_start = tabular->row_of_cell(sel_cell_start);
1984 sel_row_end = tabular->row_of_cell(sel_cell_end);
1985 if (sel_row_start > sel_row_end) {
1986 //int tmp = sel_row_start;
1987 //sel_row_start = sel_row_end;
1988 //sel_row_end = tmp;
1989 swap(sel_row_start, sel_row_end);
1992 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1996 case LyXTabular::SET_PWIDTH:
1997 case LyXTabular::SET_MPWIDTH:
1998 case LyXTabular::SET_SPECIAL_COLUMN:
1999 case LyXTabular::SET_SPECIAL_MULTI:
2000 status |= LyXFunc::Disabled;
2003 case LyXTabular::APPEND_ROW:
2004 case LyXTabular::APPEND_COLUMN:
2005 case LyXTabular::DELETE_ROW:
2006 case LyXTabular::DELETE_COLUMN:
2007 case LyXTabular::SET_ALL_LINES:
2008 case LyXTabular::UNSET_ALL_LINES:
2009 status |= LyXFunc::OK;
2012 case LyXTabular::MULTICOLUMN:
2013 if (tabular->IsMultiColumn(actcell))
2014 status |= LyXFunc::ToggleOn;
2016 status |= LyXFunc::ToggleOff;
2018 case LyXTabular::M_TOGGLE_LINE_TOP:
2020 case LyXTabular::TOGGLE_LINE_TOP:
2021 if (tabular->TopLine(actcell, flag))
2022 status |= LyXFunc::ToggleOn;
2024 status |= LyXFunc::ToggleOff;
2026 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2028 case LyXTabular::TOGGLE_LINE_BOTTOM:
2029 if (tabular->BottomLine(actcell, flag))
2030 status |= LyXFunc::ToggleOn;
2032 status |= LyXFunc::ToggleOff;
2034 case LyXTabular::M_TOGGLE_LINE_LEFT:
2036 case LyXTabular::TOGGLE_LINE_LEFT:
2037 if (tabular->LeftLine(actcell, flag))
2038 status |= LyXFunc::ToggleOn;
2040 status |= LyXFunc::ToggleOff;
2042 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2044 case LyXTabular::TOGGLE_LINE_RIGHT:
2045 if (tabular->RightLine(actcell, flag))
2046 status |= LyXFunc::ToggleOn;
2048 status |= LyXFunc::ToggleOff;
2050 case LyXTabular::M_ALIGN_LEFT:
2052 case LyXTabular::ALIGN_LEFT:
2053 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2054 status |= LyXFunc::ToggleOn;
2056 status |= LyXFunc::ToggleOff;
2058 case LyXTabular::M_ALIGN_RIGHT:
2060 case LyXTabular::ALIGN_RIGHT:
2061 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2062 status |= LyXFunc::ToggleOn;
2064 status |= LyXFunc::ToggleOff;
2066 case LyXTabular::M_ALIGN_CENTER:
2068 case LyXTabular::ALIGN_CENTER:
2069 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2070 status |= LyXFunc::ToggleOn;
2072 status |= LyXFunc::ToggleOff;
2074 case LyXTabular::M_VALIGN_TOP:
2076 case LyXTabular::VALIGN_TOP:
2077 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2078 status |= LyXFunc::ToggleOn;
2080 status |= LyXFunc::ToggleOff;
2082 case LyXTabular::M_VALIGN_BOTTOM:
2084 case LyXTabular::VALIGN_BOTTOM:
2085 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2086 status |= LyXFunc::ToggleOn;
2088 status |= LyXFunc::ToggleOff;
2090 case LyXTabular::M_VALIGN_CENTER:
2092 case LyXTabular::VALIGN_CENTER:
2093 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2094 status |= LyXFunc::ToggleOn;
2096 status |= LyXFunc::ToggleOff;
2098 case LyXTabular::SET_LONGTABULAR:
2099 if (tabular->IsLongTabular())
2100 status |= LyXFunc::ToggleOn;
2102 status |= LyXFunc::ToggleOff;
2104 case LyXTabular::UNSET_LONGTABULAR:
2105 if (!tabular->IsLongTabular())
2106 status |= LyXFunc::ToggleOn;
2108 status |= LyXFunc::ToggleOff;
2110 case LyXTabular::SET_ROTATE_TABULAR:
2111 if (tabular->GetRotateTabular())
2112 status |= LyXFunc::ToggleOn;
2114 status |= LyXFunc::ToggleOff;
2116 case LyXTabular::UNSET_ROTATE_TABULAR:
2117 if (!tabular->GetRotateTabular())
2118 status |= LyXFunc::ToggleOn;
2120 status |= LyXFunc::ToggleOff;
2122 case LyXTabular::SET_ROTATE_CELL:
2123 if (tabular->GetRotateCell(actcell))
2124 status |= LyXFunc::ToggleOn;
2126 status |= LyXFunc::ToggleOff;
2128 case LyXTabular::UNSET_ROTATE_CELL:
2129 if (!tabular->GetRotateCell(actcell))
2130 status |= LyXFunc::ToggleOn;
2132 status |= LyXFunc::ToggleOff;
2134 case LyXTabular::SET_USEBOX:
2135 if (strToInt(argument) == tabular->GetUsebox(actcell))
2136 status |= LyXFunc::ToggleOn;
2138 status |= LyXFunc::ToggleOff;
2140 case LyXTabular::SET_LTFIRSTHEAD:
2141 if (tabular->GetRowOfLTHead(actcell, dummy))
2142 status |= LyXFunc::ToggleOn;
2144 status |= LyXFunc::ToggleOff;
2146 case LyXTabular::SET_LTHEAD:
2147 if (tabular->GetRowOfLTHead(actcell, dummy))
2148 status |= LyXFunc::ToggleOn;
2150 status |= LyXFunc::ToggleOff;
2152 case LyXTabular::SET_LTFOOT:
2153 if (tabular->GetRowOfLTFoot(actcell, dummy))
2154 status |= LyXFunc::ToggleOn;
2156 status |= LyXFunc::ToggleOff;
2158 case LyXTabular::SET_LTLASTFOOT:
2159 if (tabular->GetRowOfLTFoot(actcell, dummy))
2160 status |= LyXFunc::ToggleOn;
2162 status |= LyXFunc::ToggleOff;
2164 case LyXTabular::SET_LTNEWPAGE:
2165 if (tabular->GetLTNewPage(actcell))
2166 status |= LyXFunc::ToggleOn;
2168 status |= LyXFunc::ToggleOff;
2171 status = LyXFunc::Disabled;
2178 std::vector<string> const InsetTabular::getLabelList() const
2180 return tabular->getLabelList();
2184 bool InsetTabular::copySelection(BufferView * bv)
2186 if (!hasSelection())
2188 //delete paste_tabular;
2190 //int sel_col_start;
2192 //int sel_row_start;
2195 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2196 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2197 if (sel_col_start > sel_col_end) {
2198 sel_col_start = sel_col_end;
2199 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2201 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2203 int const columns = sel_col_end - sel_col_start + 1;
2205 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2206 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2207 if (sel_row_start > sel_row_end) {
2208 //int tmp tmp = sel_row_start;
2209 //sel_row_start = sel_row_end;
2210 //sel_row_end = tmp;
2211 swap(sel_row_start, sel_row_end);
2213 int const rows = sel_row_end - sel_row_start + 1;
2215 delete paste_tabular;
2216 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2218 for (int i = 0; i < sel_row_start; ++i)
2219 paste_tabular->DeleteRow(0);
2220 while(paste_tabular->rows() > rows)
2221 paste_tabular->DeleteRow(rows);
2222 paste_tabular->SetTopLine(0, true, true);
2223 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2225 for (int i = 0; i < sel_col_start; ++i)
2226 paste_tabular->DeleteColumn(0);
2227 while (paste_tabular->columns() > columns)
2228 paste_tabular->DeleteColumn(columns);
2229 paste_tabular->SetLeftLine(0, true, true);
2230 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2234 paste_tabular->Ascii(bv->buffer(), sstr);
2235 bv->stuffClipboard(sstr.str().c_str());
2240 bool InsetTabular::pasteSelection(BufferView * bv)
2245 for (int r1 = 0, r2 = actrow;
2246 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2248 for(int c1 = 0, c2 = actcol;
2249 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2251 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2252 tabular->IsPartOfMultiColumn(r2,c2))
2254 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2258 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2262 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2263 int const n2 = tabular->GetCellNumber(r2, c2);
2264 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2265 tabular->GetCellInset(n2)->setOwner(this);
2266 tabular->GetCellInset(n2)->deleteLyXText(bv);
2273 bool InsetTabular::cutSelection()
2275 if (!hasSelection())
2278 //int sel_col_start;
2280 //int sel_row_start;
2283 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2284 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2285 if (sel_col_start > sel_col_end) {
2286 sel_col_start = sel_col_end;
2287 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2289 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2291 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2292 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2293 if (sel_row_start > sel_row_end) {
2294 //int tmp = sel_row_start;
2295 //sel_row_start = sel_row_end;
2296 //sel_row_end = tmp;
2297 swap(sel_row_start, sel_row_end);
2299 if (sel_cell_start > sel_cell_end) {
2300 //int tmp = sel_cell_start;
2301 //sel_cell_start = sel_cell_end;
2302 //sel_cell_end = tmp;
2303 swap(sel_cell_start, sel_cell_end);
2305 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2306 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2307 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2314 bool InsetTabular::isRightToLeft(BufferView *bv )
2316 return bv->getParentLanguage(this)->RightToLeft();
2319 bool InsetTabular::nodraw() const
2321 if (the_locking_inset)
2322 return the_locking_inset->nodraw();
2323 return UpdatableInset::nodraw();
2326 int InsetTabular::scroll(bool recursive) const
2328 int sx = UpdatableInset::scroll(false);
2330 if (recursive && the_locking_inset)
2331 sx += the_locking_inset->scroll(recursive);
2336 bool InsetTabular::doClearArea() const
2338 return !locked || (need_update & (FULL|INIT));