1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
41 #include "BufferView.h"
42 #include "undo_funcs.h"
53 const int ADD_TO_HEIGHT = 2;
54 const int ADD_TO_TABULAR_WIDTH = 2;
56 LyXTabular * paste_tabular = 0;
59 struct TabularFeature {
60 LyXTabular::Feature action;
64 //tabular_features * tabularFeatures = 0;
66 TabularFeature tabularFeature[] =
68 { LyXTabular::APPEND_ROW, "append-row" },
69 { LyXTabular::APPEND_COLUMN, "append-column" },
70 { LyXTabular::DELETE_ROW, "delete-row" },
71 { LyXTabular::DELETE_COLUMN, "delete-column" },
72 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
73 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
74 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
75 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
76 { LyXTabular::ALIGN_LEFT, "align-left" },
77 { LyXTabular::ALIGN_RIGHT, "align-right" },
78 { LyXTabular::ALIGN_CENTER, "align-center" },
79 { LyXTabular::VALIGN_TOP, "valign-top" },
80 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
81 { LyXTabular::VALIGN_CENTER, "valign-center" },
82 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
83 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
84 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
85 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
86 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
87 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
88 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
89 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
90 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
91 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
92 { LyXTabular::MULTICOLUMN, "multicolumn" },
93 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
94 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
95 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
96 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
97 { LyXTabular::SET_PWIDTH, "set-pwidth" },
98 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
99 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
100 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
101 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
102 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
103 { LyXTabular::SET_USEBOX, "set-usebox" },
104 { LyXTabular::SET_LTHEAD, "set-lthead" },
105 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
106 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
107 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
108 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
109 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
110 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
111 { LyXTabular::LAST_ACTION, "" }
117 bool InsetTabular::hasPasteBuffer() const
119 return (paste_tabular != 0);
123 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
130 tabular.reset(new LyXTabular(this, rows, columns));
131 // for now make it always display as display() inset
133 the_locking_inset = 0;
134 locked = no_selection = false;
136 actrow = actcell = 0;
142 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
146 tabular.reset(new LyXTabular(this, *(tab.tabular)));
147 the_locking_inset = 0;
148 locked = no_selection = false;
150 actrow = actcell = 0;
151 sel_cell_start = sel_cell_end = 0;
158 InsetTabular::~InsetTabular()
164 Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
166 return new InsetTabular(*this, buf, same_id);
170 void InsetTabular::write(Buffer const * buf, ostream & os) const
172 os << " Tabular" << endl;
173 tabular->Write(buf, os);
177 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
179 bool const old_format = (lex.GetString() == "\\LyXTable");
183 //tabular = new LyXTabular(buf, this, lex);
184 tabular.reset(new LyXTabular(buf, this, lex));
192 string token = lex.GetString();
193 while (lex.IsOK() && (token != "\\end_inset")) {
195 token = lex.GetString();
197 if (token != "\\end_inset") {
198 lex.printError("Missing \\end_inset at this point. "
204 int InsetTabular::ascent(BufferView *, LyXFont const &) const
206 return tabular->GetAscentOfRow(0);
210 int InsetTabular::descent(BufferView *, LyXFont const &) const
212 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
216 int InsetTabular::width(BufferView *, LyXFont const &) const
218 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
222 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
223 float & x, bool cleared) const
231 if (need_update == INIT) {
232 if (calculate_dimensions_of_cells(bv, font, true))
233 bv->text->status = LyXText::CHANGED_IN_DRAW;
238 Painter & pain = bv->painter();
244 UpdatableInset::draw(bv, font, baseline, x, cleared);
247 x += static_cast<float>(scroll());
249 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
250 (top_x != int(x)) || (top_baseline != baseline))) {
251 int h = ascent(bv, font) + descent(bv, font);
252 int const tx = display() || !owner() ? 0 : top_x;
253 int w = tx ? width(bv, font) : pain.paperWidth();
254 int ty = baseline - ascent(bv, font);
258 if ((ty + h) > pain.paperHeight())
259 h = pain.paperHeight();
260 if ((top_x + w) > pain.paperWidth())
261 w = pain.paperWidth();
262 pain.fillRectangle(tx, ty, w, h);
267 top_baseline = baseline;
268 x += ADD_TO_TABULAR_WIDTH;
272 first_visible_cell = -1;
273 for (i = 0; i < tabular->rows(); ++i) {
275 cell = tabular->GetCellNumber(i, 0);
276 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
277 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
279 baseline += tabular->GetDescentOfRow(i) +
280 tabular->GetAscentOfRow(i + 1) +
281 tabular->GetAdditionalHeight(i + 1);
284 for (j = 0; j < tabular->columns(); ++j) {
285 if (nx > bv->workWidth())
287 if (tabular->IsPartOfMultiColumn(i, j))
289 cx = nx + tabular->GetBeginningOfTextInCell(cell);
290 if (first_visible_cell < 0)
291 first_visible_cell = cell;
293 drawCellSelection(pain, nx, baseline, i, j, cell);
295 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
297 drawCellLines(pain, nx, baseline, i, cell);
298 nx += tabular->GetWidthOfColumn(cell);
301 baseline += tabular->GetDescentOfRow(i) +
302 tabular->GetAscentOfRow(i + 1) +
303 tabular->GetAdditionalHeight(i + 1);
305 } else if (need_update == CELL) {
308 if (the_locking_inset &&
309 tabular->GetCellInset(actcell) != the_locking_inset)
311 Inset * inset = tabular->GetCellInset(cell);
313 inset != the_locking_inset && i < tabular->rows();
316 inset != the_locking_inset
317 && j < tabular->columns();
319 if (tabular->IsPartOfMultiColumn(i, j))
321 nx += tabular->GetWidthOfColumn(cell);
323 inset = tabular->GetCellInset(cell);
325 if (tabular->row_of_cell(cell) > i) {
327 baseline += tabular->GetDescentOfRow(i) +
328 tabular->GetAscentOfRow(i + 1) +
329 tabular->GetAdditionalHeight(i + 1);
333 // compute baseline for actual row
334 for (i = 0; i < actrow; ++i) {
335 baseline += tabular->GetDescentOfRow(i) +
336 tabular->GetAscentOfRow(i + 1) +
337 tabular->GetAdditionalHeight(i + 1);
339 // now compute the right x position
340 cell = tabular->GetCellNumber(actrow, 0);
341 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
342 if (tabular->IsPartOfMultiColumn(actrow, j))
344 nx += tabular->GetWidthOfColumn(cell);
348 i = tabular->row_of_cell(cell);
349 if (the_locking_inset != tabular->GetCellInset(cell)) {
350 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
353 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
355 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
356 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
358 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) {
386 for(Inset * inset=owner(); inset; ++i)
387 inset = inset->owner();
388 if (calculate_dimensions_of_cells(bv, font, false))
396 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
397 int row, int cell) const
399 int x2 = x + tabular->GetWidthOfColumn(cell);
402 if (!tabular->TopAlreadyDrawed(cell)) {
403 on_off = !tabular->TopLine(cell);
404 pain.line(x, baseline - tabular->GetAscentOfRow(row),
405 x2, baseline - tabular->GetAscentOfRow(row),
406 on_off ? LColor::tabularonoffline : LColor::tabularline,
407 on_off ? Painter::line_onoffdash : Painter::line_solid);
409 on_off = !tabular->BottomLine(cell);
410 pain.line(x,baseline + tabular->GetDescentOfRow(row),
411 x2, baseline + tabular->GetDescentOfRow(row),
412 on_off ? LColor::tabularonoffline : LColor::tabularline,
413 on_off ? Painter::line_onoffdash : Painter::line_solid);
414 if (!tabular->LeftAlreadyDrawed(cell)) {
415 on_off = !tabular->LeftLine(cell);
416 pain.line(x, baseline - tabular->GetAscentOfRow(row),
417 x, baseline + tabular->GetDescentOfRow(row),
418 on_off ? LColor::tabularonoffline : LColor::tabularline,
419 on_off ? Painter::line_onoffdash : Painter::line_solid);
421 on_off = !tabular->RightLine(cell);
422 pain.line(x2 - tabular->GetAdditionalWidth(cell),
423 baseline - tabular->GetAscentOfRow(row),
424 x2 - tabular->GetAdditionalWidth(cell),
425 baseline + tabular->GetDescentOfRow(row),
426 on_off ? LColor::tabularonoffline : LColor::tabularline,
427 on_off ? Painter::line_onoffdash : Painter::line_solid);
431 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
432 int row, int column, int cell) const
434 int cs = tabular->column_of_cell(sel_cell_start);
435 int ce = tabular->column_of_cell(sel_cell_end);
438 cs = tabular->column_of_cell(sel_cell_end);
440 ce = tabular->right_column_of_cell(sel_cell_end);
443 int rs = tabular->row_of_cell(sel_cell_start);
444 int re = tabular->row_of_cell(sel_cell_end);
445 if (rs > re) swap(rs, re);
447 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
448 int w = tabular->GetWidthOfColumn(cell);
449 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
450 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
451 w, h, LColor::selection);
456 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
460 calculate_dimensions_of_cells(bv, font, true);
462 owner()->update(bv, font, true);
465 if (the_locking_inset)
466 the_locking_inset->update(bv, font, reinit);
467 if (need_update < FULL &&
468 bv->text->status() == LyXText::NEED_MORE_REFRESH)
473 switch (need_update) {
477 if (calculate_dimensions_of_cells(bv, font, false))
489 string const InsetTabular::editMessage() const
491 return _("Opened Tabular Inset");
495 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
497 UpdatableInset::edit(bv, x, y, button);
499 if (!bv->lockInset(this)) {
500 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
504 the_locking_inset = 0;
508 sel_cell_start = sel_cell_end = actcell;
510 if (insetHit(bv, x, y) && (button != 3)) {
511 activateCellInsetAbs(bv, x, y, button);
513 // UpdateLocal(bv, NONE, false);
514 // bv->getOwner()->getPopups().updateFormTabular();
518 void InsetTabular::insetUnlock(BufferView * bv)
520 if (the_locking_inset) {
521 the_locking_inset->insetUnlock(bv);
522 the_locking_inset = 0;
525 no_selection = false;
528 if (scroll(false) || hasSelection()) {
529 sel_cell_start = sel_cell_end = 0;
533 updateLocal(bv, FULL, false);
538 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
539 bool mark_dirty) const
541 if (need_update < what) // only set this if it has greater update
543 if ((what == INIT) && hasSelection())
546 if (need_update != NONE) {
547 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
548 if (locked) // && (what != NONE))
554 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
556 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
561 if (inset == tabular->GetCellInset(actcell)) {
562 lyxerr[Debug::INSETS] << "OK" << endl;
563 the_locking_inset = tabular->GetCellInset(actcell);
565 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
566 inset_y = cursor_.y();
568 } else if (the_locking_inset && (the_locking_inset == inset)) {
569 lyxerr[Debug::INSETS] << "OK" << endl;
571 inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
572 inset_y = cursor_.y();
573 } else if (the_locking_inset) {
574 lyxerr[Debug::INSETS] << "MAYBE" << endl;
575 return the_locking_inset->lockInsetInInset(bv, inset);
577 lyxerr[Debug::INSETS] << "NOT OK" << endl;
582 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
585 if (!the_locking_inset)
587 if (the_locking_inset == inset) {
588 the_locking_inset->insetUnlock(bv);
589 the_locking_inset = 0;
591 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
597 updateLocal(bv, CELL, false);
598 showInsetCursor(bv, false);
601 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
602 if (inset->lyxCode() == TABULAR_CODE &&
603 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
604 bv->owner()->getDialogs()->updateTabular(this);
613 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
615 if (!the_locking_inset)
617 if (the_locking_inset != inset) {
618 if (!the_locking_inset->updateInsetInInset(bv, inset))
621 updateLocal(bv, CELL, false);
626 unsigned int InsetTabular::insetInInsetY()
628 if (!the_locking_inset)
631 return inset_y + the_locking_inset->insetInInsetY();
635 UpdatableInset * InsetTabular::getLockingInset() const
637 return the_locking_inset ? the_locking_inset->getLockingInset() :
638 const_cast<InsetTabular *>(this);
642 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
646 if (the_locking_inset)
647 return the_locking_inset->getFirstLockingInsetOfType(c);
652 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
654 if (the_locking_inset)
655 return the_locking_inset->insertInset(bv, inset);
660 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
662 if (hasSelection() && (button == 3))
665 if (hasSelection()) {
667 updateLocal(bv, SELECTION, false);
670 no_selection = false;
672 int const ocell = actcell;
673 int const orow = actrow;
678 updateLocal(bv, NONE, false);
679 sel_cell_start = sel_cell_end = actcell;
681 if ((ocell != actcell) && the_locking_inset) {
682 the_locking_inset->insetUnlock(bv);
683 the_locking_inset = 0;
689 bool const inset_hit = insetHit(bv, x, y);
691 if ((ocell == actcell) && the_locking_inset && inset_hit) {
693 the_locking_inset->insetButtonPress(bv,
694 x - inset_x, y - inset_y,
697 } else if (the_locking_inset) {
698 the_locking_inset->insetUnlock(bv);
700 the_locking_inset = 0;
702 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
705 if (inset_hit && bv->theLockingInset()) {
706 if (activateCellInsetAbs(bv, x, y, button))
707 the_locking_inset->insetButtonPress(bv,
717 void InsetTabular::insetButtonRelease(BufferView * bv,
718 int x, int y, int button)
721 if (the_locking_inset) {
723 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
724 i->insetButtonRelease(bv, x, y, button);
728 bv->owner()->getDialogs()->showTabular(this);
731 if (the_locking_inset) {
732 the_locking_inset->insetButtonRelease(bv,
733 x - inset_x, y - inset_y,
737 no_selection = false;
741 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
743 if (the_locking_inset) {
744 the_locking_inset->insetMotionNotify(bv,
752 int const old_cell = actcell;
755 sel_cell_end = actcell;
756 if (sel_cell_end != old_cell)
757 updateLocal(bv, SELECTION, false);
760 no_selection = false;
764 void InsetTabular::insetKeyPress(XKeyEvent * xke)
766 if (the_locking_inset) {
767 the_locking_inset->insetKeyPress(xke);
773 UpdatableInset::RESULT
774 InsetTabular::localDispatch(BufferView * bv,
778 // We need to save the value of the_locking_inset as the call to
779 // the_locking_inset->LocalDispatch might unlock it.
780 old_locking_inset = the_locking_inset;
781 no_selection = false;
782 UpdatableInset::RESULT result =
783 UpdatableInset::localDispatch(bv, action, arg);
784 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
789 if ((action < 0) && arg.empty())
792 bool hs = hasSelection();
795 // this one have priority over the locked InsetText!
800 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) != this)
803 if (the_locking_inset) {
804 unlockInsetInInset(bv, the_locking_inset);
805 the_locking_inset = 0;
807 if (action == LFUN_TAB)
808 moveNextCell(bv, old_locking_inset != 0);
810 movePrevCell(bv, old_locking_inset != 0);
811 sel_cell_start = sel_cell_end = actcell;
813 updateLocal(bv, SELECTION, false);
814 if (!the_locking_inset) {
816 return DISPATCHED_NOUPDATE;
820 // this to avoid compiler warnings.
825 if (the_locking_inset) {
826 result = the_locking_inset->localDispatch(bv, action, arg);
827 if (result == DISPATCHED_NOUPDATE) {
830 if (sc != scroll()) { // inset has been scrolled
831 the_locking_inset->toggleInsetCursor(bv);
832 updateLocal(bv, FULL, false);
833 the_locking_inset->toggleInsetCursor(bv);
836 } else if (result == DISPATCHED) {
837 the_locking_inset->toggleInsetCursor(bv);
838 updateLocal(bv, CELL, false);
839 the_locking_inset->toggleInsetCursor(bv);
841 } else if (result == FINISHED) {
848 // --- Cursor Movements ----------------------------------
850 if (tabular->IsLastCellInRow(actcell))
852 moveRight(bv, false);
853 sel_cell_end = actcell;
854 updateLocal(bv, SELECTION, false);
857 result = moveRight(bv);
858 sel_cell_start = sel_cell_end = actcell;
860 updateLocal(bv, SELECTION, false);
863 if (tabular->IsFirstCellInRow(actcell))
866 sel_cell_end = actcell;
867 updateLocal(bv, SELECTION, false);
870 result = moveLeft(bv);
871 sel_cell_start = sel_cell_end = actcell;
873 updateLocal(bv, SELECTION, false);
877 int const ocell = actcell;
879 if ((ocell == sel_cell_end) ||
880 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
881 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
883 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
884 updateLocal(bv, SELECTION, false);
888 result = moveDown(bv, old_locking_inset != 0);
889 sel_cell_start = sel_cell_end = actcell;
891 updateLocal(bv, SELECTION, false);
895 int const ocell = actcell;
897 if ((ocell == sel_cell_end) ||
898 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
899 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
901 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
902 updateLocal(bv, SELECTION, false);
906 result = moveUp(bv, old_locking_inset != 0);
907 sel_cell_start = sel_cell_end = actcell;
909 updateLocal(bv, SELECTION, false);
913 if (the_locking_inset) {
914 unlockInsetInInset(bv, the_locking_inset);
915 the_locking_inset = 0;
917 if (bv->text->first + bv->painter().paperHeight() <
918 (top_baseline + tabular->GetHeightOfTabular()))
920 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
921 updateLocal(bv, FULL, false);
922 actcell = tabular->GetCellBelow(first_visible_cell) + column;
924 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
927 updateLocal(bv, CURSOR, false);
932 if (the_locking_inset) {
933 unlockInsetInInset(bv, the_locking_inset);
934 the_locking_inset = 0;
936 if (top_baseline < 0) {
937 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
938 updateLocal(bv, FULL, false);
939 if (top_baseline > 0)
942 actcell = tabular->GetCellBelow(first_visible_cell) + column;
947 updateLocal(bv, CURSOR, false);
958 case LFUN_LAYOUT_TABULAR:
960 bv->owner()->getDialogs()->showTabular(this);
963 case LFUN_TABULAR_FEATURE:
964 if (!tabularFeatures(bv, arg))
965 result = UNDISPATCHED;
968 if (!copySelection(bv))
970 setUndo(bv, Undo::DELETE,
971 bv->text->cursor.par(),
972 bv->text->cursor.par()->next());
974 updateLocal(bv, INIT, true);
982 case LFUN_PASTESELECTION:
984 string const clip(bv->getClipboard());
988 if (clip.find('\t') != string::npos) {
992 unsigned int len = clip.length();
993 string::size_type p = 0;
996 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1004 maxCols = max(cols, maxCols);
1010 maxCols = max(cols, maxCols);
1011 delete paste_tabular;
1012 paste_tabular = new LyXTabular(this, rows, maxCols);
1013 string::size_type op = 0;
1015 int cells = paste_tabular->GetNumberOfCells();
1017 while((cell < cells) && (p < len) &&
1018 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1023 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1028 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1029 while(cols++ < maxCols)
1037 // check for the last cell if there is no trailing '\n'
1038 if ((cell < cells) && (op < len))
1039 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1041 // so that the clipboard is used and it goes on
1043 // and executes LFUN_PASTESELECTION in insettext!
1044 delete paste_tabular;
1049 if (hasPasteBuffer()) {
1050 setUndo(bv, Undo::INSERT,
1051 bv->text->cursor.par(),
1052 bv->text->cursor.par()->next());
1054 updateLocal(bv, INIT, true);
1057 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1059 // we try to activate the actual inset and put this event down to
1060 // the insets dispatch function.
1061 result = UNDISPATCHED;
1062 if (the_locking_inset)
1065 if (activateCellInset(bv)) {
1066 // reset need_update setted in above function!
1068 result = the_locking_inset->localDispatch(bv, action, arg);
1069 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1070 unlockInsetInInset(bv, the_locking_inset);
1072 the_locking_inset = 0;
1073 // we need to update if this was requested before
1074 updateLocal(bv, NONE, false);
1075 return UNDISPATCHED;
1078 // the_locking_inset->ToggleInsetCursor(bv);
1079 updateLocal(bv, CELL, false);
1080 // the_locking_inset->ToggleInsetCursor(bv);
1085 if (result!=FINISHED) {
1086 if (!the_locking_inset) {
1087 showInsetCursor(bv);
1090 bv->unlockInset(this);
1095 int InsetTabular::latex(Buffer const * buf, ostream & os,
1096 bool fragile, bool fp) const
1098 return tabular->Latex(buf, os, fragile, fp);
1102 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1104 // This should be changed to a real ascii export
1105 return tabular->Ascii(buf, os);
1109 int InsetTabular::linuxdoc(Buffer const *, ostream &) const
1115 int InsetTabular::docBook(Buffer const * buf, ostream & os) const
1117 return tabular->DocBook(buf,os);
1121 void InsetTabular::validate(LaTeXFeatures & features) const
1123 tabular->Validate(features);
1127 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1128 LyXFont const & font,
1135 bool changed = false;
1137 // if we have a locking_inset we should have to check only this cell for
1138 // change so I'll try this to have a boost, but who knows ;)
1139 if ((need_update != INIT) &&
1140 (the_locking_inset == tabular->GetCellInset(actcell))) {
1141 for(int i = 0; i < tabular->columns(); ++i) {
1142 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1144 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1147 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1148 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1149 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1155 for (int i = 0; i < tabular->rows(); ++i) {
1158 for (int j = 0; j < tabular->columns(); ++j) {
1159 if (tabular->IsPartOfMultiColumn(i,j))
1162 inset = tabular->GetCellInset(cell);
1164 inset->update(bv, font, false);
1165 maxAsc = max(maxAsc, inset->ascent(bv, font));
1166 maxDesc = max(maxDesc, inset->descent(bv, font));
1167 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1169 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1170 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1176 void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
1178 if (the_locking_inset) {
1179 the_locking_inset->getCursorPos(bv, x, y);
1182 x = cursor_.x() - top_x;
1187 void InsetTabular::toggleInsetCursor(BufferView * bv)
1189 if (the_locking_inset) {
1190 the_locking_inset->toggleInsetCursor(bv);
1194 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1196 int const asc = lyxfont::maxAscent(font);
1197 int const desc = lyxfont::maxDescent(font);
1199 if (isCursorVisible())
1200 bv->hideLockedInsetCursor();
1202 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1203 toggleCursorVisible();
1207 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1209 if (!isCursorVisible()) {
1210 LyXFont font; // = GetFont(par, cursor.pos);
1212 int const asc = lyxfont::maxAscent(font);
1213 int const desc = lyxfont::maxDescent(font);
1214 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1216 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1217 setCursorVisible(true);
1222 void InsetTabular::hideInsetCursor(BufferView * bv)
1224 if (isCursorVisible()) {
1225 bv->hideLockedInsetCursor();
1226 setCursorVisible(false);
1228 // if (cursor_visible)
1229 // ToggleInsetCursor(bv);
1233 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1237 actcell = actrow = actcol = 0;
1238 int ly = tabular->GetDescentOfRow(actrow);
1240 // first search the right row
1241 while((ly < y) && (actrow < tabular->rows())) {
1242 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1243 tabular->GetAscentOfRow(actrow + 1) +
1244 tabular->GetAdditionalHeight(actrow + 1));
1246 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1248 actcell = tabular->GetCellNumber(actrow, actcol);
1250 // now search the right column
1251 int lx = tabular->GetWidthOfColumn(actcell) -
1252 tabular->GetAdditionalWidth(actcell);
1254 #ifdef WITH_WARNINGS
1255 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1257 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1258 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1259 tabular->GetAdditionalWidth(actcell - 1));
1261 // Jürgen, you should check that this is correct. (Lgb)
1262 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1263 lx += tabular->GetWidthOfColumn(actcell + 1)
1264 + tabular->GetAdditionalWidth(actcell);
1268 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1273 int InsetTabular::getCellXPos(int cell) const
1277 for (; !tabular->IsFirstCellInRow(c); --c)
1279 int lx = tabular->GetWidthOfColumn(cell);
1280 for (; c < cell; ++c) {
1281 lx += tabular->GetWidthOfColumn(c);
1283 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1287 void InsetTabular::resetPos(BufferView * bv) const
1291 actcol = tabular->column_of_cell(actcell);
1296 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1297 if (tabular->IsLastCellInRow(cell)) {
1298 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1299 tabular->GetAscentOfRow(actrow + 1) +
1300 tabular->GetAdditionalHeight(actrow + 1));
1304 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1305 int new_x = getCellXPos(actcell);
1306 int old_x = cursor_.x();
1309 // cursor.x(getCellXPos(actcell) + offset);
1310 if ((actcol < tabular->columns()-1) && scroll(false) &&
1311 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1314 updateLocal(bv, FULL, false);
1315 } else if (the_locking_inset &&
1316 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1318 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1319 if (xx > (bv->workWidth()-20)) {
1320 scroll(bv, -(xx - bv->workWidth() + 60));
1321 updateLocal(bv, FULL, false);
1322 } else if (xx < 20) {
1328 updateLocal(bv, FULL, false);
1330 } else if ((cursor_.x() - offset) > 20 &&
1331 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1332 > (bv->workWidth() - 20)) {
1333 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1334 updateLocal(bv, FULL, false);
1335 } else if ((cursor_.x() - offset) < 20) {
1336 scroll(bv, 20 - cursor_.x() + offset);
1337 updateLocal(bv, FULL, false);
1338 } else if (scroll(false) && top_x > 20 &&
1339 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1340 scroll(bv, old_x - cursor_.x());
1341 updateLocal(bv, FULL, false);
1343 if ((!the_locking_inset ||
1344 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1345 actcell != oldcell) {
1346 InsetTabular * inset = const_cast<InsetTabular *>(this);
1347 bv->owner()->getDialogs()->updateTabular(inset);
1353 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1355 if (lock && !old_locking_inset) {
1356 if (activateCellInset(bv))
1359 bool moved = isRightToLeft(bv)
1360 ? movePrevCell(bv) : moveNextCell(bv);
1363 if (lock && activateCellInset(bv))
1367 return DISPATCHED_NOUPDATE;
1371 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1373 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1376 if (lock) { // behind the inset
1377 if (activateCellInset(bv, 0, 0, 0, true))
1381 return DISPATCHED_NOUPDATE;
1385 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1387 int const ocell = actcell;
1388 actcell = tabular->GetCellAbove(actcell);
1389 if (actcell == ocell) // we moved out of the inset
1395 if (old_locking_inset) {
1396 old_locking_inset->getCursorPos(bv, x, y);
1397 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1399 if (activateCellInset(bv, x, 0))
1402 return DISPATCHED_NOUPDATE;
1406 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1408 int const ocell = actcell;
1409 actcell = tabular->GetCellBelow(actcell);
1410 if (actcell == ocell) // we moved out of the inset
1416 if (old_locking_inset) {
1417 old_locking_inset->getCursorPos(bv, x, y);
1418 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1420 if (activateCellInset(bv, x, 0))
1423 return DISPATCHED_NOUPDATE;
1427 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1429 if (isRightToLeft(bv)) {
1430 if (tabular->IsFirstCellInRow(actcell)) {
1431 int row = tabular->row_of_cell(actcell);
1432 if (row == tabular->rows() - 1)
1434 actcell = tabular->GetLastCellInRow(row);
1435 actcell = tabular->GetCellBelow(actcell);
1442 if (tabular->IsLastCell(actcell))
1447 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1448 isRightToLeftPar(bv->buffer()->params);
1449 activateCellInset(bv, 0, 0, 0, !rtl);
1456 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1458 if (isRightToLeft(bv)) {
1459 if (tabular->IsLastCellInRow(actcell)) {
1460 int row = tabular->row_of_cell(actcell);
1463 actcell = tabular->GetFirstCellInRow(row);
1464 actcell = tabular->GetCellAbove(actcell);
1466 if (tabular->IsLastCell(actcell))
1471 if (!actcell) // first cell
1476 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1477 isRightToLeftPar(bv->buffer()->params);
1478 activateCellInset(bv, 0, 0, 0, !rtl);
1485 bool InsetTabular::Delete()
1487 #warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
1488 #warning I guess this could be 'deletable'! (Jug)
1493 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1498 sel_cell_end = tabular->GetNumberOfCells() - 1;
1500 if (hasSelection()) {
1501 setUndo(bv, Undo::EDIT,
1502 bv->text->cursor.par(),
1503 bv->text->cursor.par()->next());
1504 bool frozen = undo_frozen;
1507 // apply the fontchange on the whole selection
1512 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1513 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1514 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1515 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1520 updateLocal(bv, INIT, true);
1522 if (the_locking_inset)
1523 the_locking_inset->setFont(bv, font, tall);
1527 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1529 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1532 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1533 string const tmp = tabularFeature[i].feature;
1535 if (tmp == what.substr(0, tmp.length())) {
1536 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1537 //tabularFeatures[i].feature.length())) {
1538 action = tabularFeature[i].action;
1542 if (action == LyXTabular::LAST_ACTION)
1546 frontStrip(what.substr(tabularFeature[i].feature.length()));
1547 tabularFeatures(bv, action, val);
1552 void InsetTabular::tabularFeatures(BufferView * bv,
1553 LyXTabular::Feature feature,
1554 string const & value)
1560 bool setLines = false;
1561 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1562 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1565 case LyXTabular::M_ALIGN_LEFT:
1566 case LyXTabular::ALIGN_LEFT:
1567 setAlign=LYX_ALIGN_LEFT;
1569 case LyXTabular::M_ALIGN_RIGHT:
1570 case LyXTabular::ALIGN_RIGHT:
1571 setAlign=LYX_ALIGN_RIGHT;
1573 case LyXTabular::M_ALIGN_CENTER:
1574 case LyXTabular::ALIGN_CENTER:
1575 setAlign=LYX_ALIGN_CENTER;
1577 case LyXTabular::M_VALIGN_TOP:
1578 case LyXTabular::VALIGN_TOP:
1579 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1581 case LyXTabular::M_VALIGN_BOTTOM:
1582 case LyXTabular::VALIGN_BOTTOM:
1583 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1585 case LyXTabular::M_VALIGN_CENTER:
1586 case LyXTabular::VALIGN_CENTER:
1587 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1592 if (hasSelection()) {
1593 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1595 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1596 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1598 setUndo(bv, Undo::FINISH,
1599 bv->text->cursor.par(),
1600 bv->text->cursor.par()->next());
1602 int row = tabular->row_of_cell(actcell);
1603 int column = tabular->column_of_cell(actcell);
1607 case LyXTabular::SET_PWIDTH:
1609 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1610 tabular->SetColumnPWidth(actcell,value);
1612 for (int i = 0; i < tabular->rows(); ++i) {
1613 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1616 updateLocal(bv, INIT, true);
1620 case LyXTabular::SET_MPWIDTH:
1622 bool const update = (tabular->GetPWidth(actcell) != value);
1623 tabular->SetMColumnPWidth(actcell,value);
1625 for (int i = 0; i < tabular->rows(); ++i) {
1626 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1629 updateLocal(bv, INIT, true);
1633 case LyXTabular::SET_SPECIAL_COLUMN:
1634 case LyXTabular::SET_SPECIAL_MULTI:
1635 tabular->SetAlignSpecial(actcell,value,feature);
1637 case LyXTabular::APPEND_ROW:
1638 // append the row into the tabular
1639 unlockInsetInInset(bv, the_locking_inset);
1640 tabular->AppendRow(actcell);
1641 updateLocal(bv, INIT, true);
1643 case LyXTabular::APPEND_COLUMN:
1644 // append the column into the tabular
1645 unlockInsetInInset(bv, the_locking_inset);
1646 tabular->AppendColumn(actcell);
1647 actcell = tabular->GetCellNumber(row, column);
1648 updateLocal(bv, INIT, true);
1650 case LyXTabular::DELETE_ROW:
1651 unlockInsetInInset(bv, the_locking_inset);
1652 tabular->DeleteRow(tabular->row_of_cell(actcell));
1653 if ((row+1) > tabular->rows())
1655 actcell = tabular->GetCellNumber(row, column);
1657 updateLocal(bv, INIT, true);
1659 case LyXTabular::DELETE_COLUMN:
1660 unlockInsetInInset(bv, the_locking_inset);
1661 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1662 if ((column+1) > tabular->columns())
1664 actcell = tabular->GetCellNumber(row, column);
1666 updateLocal(bv, INIT, true);
1668 case LyXTabular::M_TOGGLE_LINE_TOP:
1670 case LyXTabular::TOGGLE_LINE_TOP:
1672 bool lineSet = !tabular->TopLine(actcell, flag);
1673 for (int i = sel_row_start; i <= sel_row_end; ++i)
1674 for (int j = sel_col_start; j <= sel_col_end; ++j)
1675 tabular->SetTopLine(
1676 tabular->GetCellNumber(i, j),
1678 updateLocal(bv, INIT, true);
1682 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1684 case LyXTabular::TOGGLE_LINE_BOTTOM:
1686 bool lineSet = !tabular->BottomLine(actcell, flag);
1687 for (int i = sel_row_start; i <= sel_row_end; ++i)
1688 for (int j = sel_col_start; j <= sel_col_end; ++j)
1689 tabular->SetBottomLine(
1690 tabular->GetCellNumber(i, j),
1693 updateLocal(bv, INIT, true);
1697 case LyXTabular::M_TOGGLE_LINE_LEFT:
1699 case LyXTabular::TOGGLE_LINE_LEFT:
1701 bool lineSet = !tabular->LeftLine(actcell, flag);
1702 for (int i = sel_row_start; i <= sel_row_end; ++i)
1703 for (int j = sel_col_start; j <= sel_col_end; ++j)
1704 tabular->SetLeftLine(
1705 tabular->GetCellNumber(i,j),
1708 updateLocal(bv, INIT, true);
1712 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1714 case LyXTabular::TOGGLE_LINE_RIGHT:
1716 bool lineSet = !tabular->RightLine(actcell, flag);
1717 for (int i = sel_row_start; i <= sel_row_end; ++i)
1718 for (int j = sel_col_start; j <= sel_col_end; ++j)
1719 tabular->SetRightLine(
1720 tabular->GetCellNumber(i,j),
1723 updateLocal(bv, INIT, true);
1727 case LyXTabular::M_ALIGN_LEFT:
1728 case LyXTabular::M_ALIGN_RIGHT:
1729 case LyXTabular::M_ALIGN_CENTER:
1731 case LyXTabular::ALIGN_LEFT:
1732 case LyXTabular::ALIGN_RIGHT:
1733 case LyXTabular::ALIGN_CENTER:
1734 for (int i = sel_row_start; i <= sel_row_end; ++i)
1735 for (int j = sel_col_start; j <= sel_col_end; ++j)
1736 tabular->SetAlignment(
1737 tabular->GetCellNumber(i, j),
1740 updateLocal(bv, INIT, true);
1742 case LyXTabular::M_VALIGN_TOP:
1743 case LyXTabular::M_VALIGN_BOTTOM:
1744 case LyXTabular::M_VALIGN_CENTER:
1746 case LyXTabular::VALIGN_TOP:
1747 case LyXTabular::VALIGN_BOTTOM:
1748 case LyXTabular::VALIGN_CENTER:
1749 for (int i = sel_row_start; i <= sel_row_end; ++i)
1750 for (int j = sel_col_start; j <= sel_col_end; ++j)
1751 tabular->SetVAlignment(
1752 tabular->GetCellNumber(i, j),
1754 updateLocal(bv, INIT, true);
1756 case LyXTabular::MULTICOLUMN:
1758 if (sel_row_start != sel_row_end) {
1759 WriteAlert(_("Impossible Operation!"),
1760 _("Multicolumns can only be horizontally."),
1764 // just multicol for one Single Cell
1765 if (!hasSelection()) {
1766 // check wether we are completly in a multicol
1767 if (tabular->IsMultiColumn(actcell)) {
1768 tabular->UnsetMultiColumn(actcell);
1769 updateLocal(bv, INIT, true);
1771 tabular->SetMultiColumn(actcell, 1);
1772 updateLocal(bv, CELL, true);
1776 // we have a selection so this means we just add all this
1777 // cells to form a multicolumn cell
1781 if (sel_cell_start > sel_cell_end) {
1782 s_start = sel_cell_end;
1783 s_end = sel_cell_start;
1785 s_start = sel_cell_start;
1786 s_end = sel_cell_end;
1788 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1790 sel_cell_end = sel_cell_start;
1791 updateLocal(bv, INIT, true);
1794 case LyXTabular::SET_ALL_LINES:
1796 case LyXTabular::UNSET_ALL_LINES:
1797 for (int i = sel_row_start; i <= sel_row_end; ++i)
1798 for (int j = sel_col_start; j <= sel_col_end; ++j)
1799 tabular->SetAllLines(
1800 tabular->GetCellNumber(i,j), setLines);
1801 updateLocal(bv, INIT, true);
1803 case LyXTabular::SET_LONGTABULAR:
1804 tabular->SetLongTabular(true);
1805 updateLocal(bv, INIT, true); // because this toggles displayed
1807 case LyXTabular::UNSET_LONGTABULAR:
1808 tabular->SetLongTabular(false);
1809 updateLocal(bv, INIT, true); // because this toggles displayed
1811 case LyXTabular::SET_ROTATE_TABULAR:
1812 tabular->SetRotateTabular(true);
1814 case LyXTabular::UNSET_ROTATE_TABULAR:
1815 tabular->SetRotateTabular(false);
1817 case LyXTabular::SET_ROTATE_CELL:
1818 for (int i = sel_row_start; i <= sel_row_end; ++i)
1819 for (int j = sel_col_start; j<=sel_col_end; ++j)
1820 tabular->SetRotateCell(
1821 tabular->GetCellNumber(i, j),
1824 case LyXTabular::UNSET_ROTATE_CELL:
1825 for (int i = sel_row_start; i <= sel_row_end; ++i)
1826 for (int j = sel_col_start; j <= sel_col_end; ++j)
1827 tabular->SetRotateCell(
1828 tabular->GetCellNumber(i, j), false);
1830 case LyXTabular::SET_USEBOX:
1832 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1833 if (val == tabular->GetUsebox(actcell))
1834 val = LyXTabular::BOX_NONE;
1835 for (int i = sel_row_start; i <= sel_row_end; ++i)
1836 for (int j = sel_col_start; j <= sel_col_end; ++j)
1838 tabular->GetCellNumber(i, j), val);
1841 case LyXTabular::SET_LTFIRSTHEAD:
1842 tabular->SetLTHead(actcell, true);
1844 case LyXTabular::SET_LTHEAD:
1845 tabular->SetLTHead(actcell, false);
1847 case LyXTabular::SET_LTFOOT:
1848 tabular->SetLTFoot(actcell, false);
1850 case LyXTabular::SET_LTLASTFOOT:
1851 tabular->SetLTFoot(actcell, true);
1853 case LyXTabular::SET_LTNEWPAGE:
1855 bool what = !tabular->GetLTNewPage(actcell);
1856 tabular->SetLTNewPage(actcell, what);
1859 // dummy stuff just to avoid warnings
1860 case LyXTabular::LAST_ACTION:
1866 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1869 UpdatableInset * inset =
1870 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1871 LyXFont font(LyXFont::ALL_SANE);
1873 x = inset->x() + inset->width(bv, font);
1874 y = inset->descent(bv, font);
1876 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1877 //inset_y = cursor.y();
1878 inset->edit(bv, x, y, button);
1879 if (!the_locking_inset)
1881 updateLocal(bv, CELL, false);
1882 return (the_locking_inset != 0);
1886 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1889 inset_x = cursor_.x()
1890 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1891 inset_y = cursor_.y();
1892 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1896 bool InsetTabular::insetHit(BufferView *, int x, int) const
1899 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
1903 // This returns paperWidth() if the cell-width is unlimited or the width
1904 // in pixels if we have a pwidth for this cell.
1905 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
1907 string const s = tabular->GetPWidth(cell);
1911 return VSpace(s).inPixels(bv);
1915 int InsetTabular::getMaxWidth(BufferView * bv,
1916 UpdatableInset const * inset) const
1918 int cell = tabular->cur_cell;
1919 if (tabular->GetCellInset(cell) != inset) {
1921 if (tabular->GetCellInset(cell) != inset) {
1923 lyxerr << "Actcell not equal to actual cell!\n";
1928 int const n = tabular->GetNumberOfCells();
1931 for (cell = 0; cell < n; ++cell) {
1932 if (tabular->GetCellInset(cell) == inset)
1938 lyxerr << "Own inset not found, shouldn't really happen!\n";
1942 int w = getMaxWidthOfCell(bv, cell);
1944 // because the inset then subtracts it's top_x and owner->x()
1945 w += (inset->x() - top_x);
1952 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
1954 resizeLyXText(bv, recursive);
1958 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
1961 for(int i = 0; i < tabular->rows(); ++i) {
1962 for(int j = 0; j < tabular->columns(); ++j) {
1963 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
1971 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1972 bool const recursive) const
1974 if (the_locking_inset)
1975 return the_locking_inset->getLyXText(bv, recursive);
1976 return Inset::getLyXText(bv, recursive);
1980 bool InsetTabular::showInsetDialog(BufferView * bv) const
1982 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
1983 bv->owner()->getDialogs()
1984 ->showTabular(const_cast<InsetTabular *>(this));
1989 void InsetTabular::openLayoutDialog(BufferView * bv) const
1991 if (the_locking_inset) {
1992 InsetTabular * i = static_cast<InsetTabular *>
1993 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
1995 i->openLayoutDialog(bv);
1999 bv->owner()->getDialogs()->showTabular(
2000 const_cast<InsetTabular *>(this));
2004 // functions returns:
2008 // 3 ... toggled off
2010 func_status::value_type InsetTabular::getStatus(string const & what) const
2012 int action = LyXTabular::LAST_ACTION;
2013 func_status::value_type status = func_status::OK;
2016 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2017 string const tmp = tabularFeature[i].feature;
2018 if (tmp == what.substr(0, tmp.length())) {
2019 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2020 // tabularFeatures[i].feature.length())) {
2021 action = tabularFeature[i].action;
2025 if (action == LyXTabular::LAST_ACTION)
2026 return func_status::Unknown;
2028 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2035 if (hasSelection()) {
2036 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2038 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2042 case LyXTabular::SET_PWIDTH:
2043 case LyXTabular::SET_MPWIDTH:
2044 case LyXTabular::SET_SPECIAL_COLUMN:
2045 case LyXTabular::SET_SPECIAL_MULTI:
2046 status |= func_status::Disabled;
2049 case LyXTabular::APPEND_ROW:
2050 case LyXTabular::APPEND_COLUMN:
2051 case LyXTabular::DELETE_ROW:
2052 case LyXTabular::DELETE_COLUMN:
2053 case LyXTabular::SET_ALL_LINES:
2054 case LyXTabular::UNSET_ALL_LINES:
2055 status |= func_status::OK;
2058 case LyXTabular::MULTICOLUMN:
2059 if (tabular->IsMultiColumn(actcell))
2060 status |= func_status::ToggleOn;
2062 status |= func_status::ToggleOff;
2064 case LyXTabular::M_TOGGLE_LINE_TOP:
2066 case LyXTabular::TOGGLE_LINE_TOP:
2067 if (tabular->TopLine(actcell, flag))
2068 status |= func_status::ToggleOn;
2070 status |= func_status::ToggleOff;
2072 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2074 case LyXTabular::TOGGLE_LINE_BOTTOM:
2075 if (tabular->BottomLine(actcell, flag))
2076 status |= func_status::ToggleOn;
2078 status |= func_status::ToggleOff;
2080 case LyXTabular::M_TOGGLE_LINE_LEFT:
2082 case LyXTabular::TOGGLE_LINE_LEFT:
2083 if (tabular->LeftLine(actcell, flag))
2084 status |= func_status::ToggleOn;
2086 status |= func_status::ToggleOff;
2088 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2090 case LyXTabular::TOGGLE_LINE_RIGHT:
2091 if (tabular->RightLine(actcell, flag))
2092 status |= func_status::ToggleOn;
2094 status |= func_status::ToggleOff;
2096 case LyXTabular::M_ALIGN_LEFT:
2098 case LyXTabular::ALIGN_LEFT:
2099 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2100 status |= func_status::ToggleOn;
2102 status |= func_status::ToggleOff;
2104 case LyXTabular::M_ALIGN_RIGHT:
2106 case LyXTabular::ALIGN_RIGHT:
2107 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2108 status |= func_status::ToggleOn;
2110 status |= func_status::ToggleOff;
2112 case LyXTabular::M_ALIGN_CENTER:
2114 case LyXTabular::ALIGN_CENTER:
2115 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2116 status |= func_status::ToggleOn;
2118 status |= func_status::ToggleOff;
2120 case LyXTabular::M_VALIGN_TOP:
2122 case LyXTabular::VALIGN_TOP:
2123 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2124 status |= func_status::ToggleOn;
2126 status |= func_status::ToggleOff;
2128 case LyXTabular::M_VALIGN_BOTTOM:
2130 case LyXTabular::VALIGN_BOTTOM:
2131 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2132 status |= func_status::ToggleOn;
2134 status |= func_status::ToggleOff;
2136 case LyXTabular::M_VALIGN_CENTER:
2138 case LyXTabular::VALIGN_CENTER:
2139 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2140 status |= func_status::ToggleOn;
2142 status |= func_status::ToggleOff;
2144 case LyXTabular::SET_LONGTABULAR:
2145 if (tabular->IsLongTabular())
2146 status |= func_status::ToggleOn;
2148 status |= func_status::ToggleOff;
2150 case LyXTabular::UNSET_LONGTABULAR:
2151 if (!tabular->IsLongTabular())
2152 status |= func_status::ToggleOn;
2154 status |= func_status::ToggleOff;
2156 case LyXTabular::SET_ROTATE_TABULAR:
2157 if (tabular->GetRotateTabular())
2158 status |= func_status::ToggleOn;
2160 status |= func_status::ToggleOff;
2162 case LyXTabular::UNSET_ROTATE_TABULAR:
2163 if (!tabular->GetRotateTabular())
2164 status |= func_status::ToggleOn;
2166 status |= func_status::ToggleOff;
2168 case LyXTabular::SET_ROTATE_CELL:
2169 if (tabular->GetRotateCell(actcell))
2170 status |= func_status::ToggleOn;
2172 status |= func_status::ToggleOff;
2174 case LyXTabular::UNSET_ROTATE_CELL:
2175 if (!tabular->GetRotateCell(actcell))
2176 status |= func_status::ToggleOn;
2178 status |= func_status::ToggleOff;
2180 case LyXTabular::SET_USEBOX:
2181 if (strToInt(argument) == tabular->GetUsebox(actcell))
2182 status |= func_status::ToggleOn;
2184 status |= func_status::ToggleOff;
2186 case LyXTabular::SET_LTFIRSTHEAD:
2187 if (tabular->GetRowOfLTHead(actcell, dummy))
2188 status |= func_status::ToggleOn;
2190 status |= func_status::ToggleOff;
2192 case LyXTabular::SET_LTHEAD:
2193 if (tabular->GetRowOfLTHead(actcell, dummy))
2194 status |= func_status::ToggleOn;
2196 status |= func_status::ToggleOff;
2198 case LyXTabular::SET_LTFOOT:
2199 if (tabular->GetRowOfLTFoot(actcell, dummy))
2200 status |= func_status::ToggleOn;
2202 status |= func_status::ToggleOff;
2204 case LyXTabular::SET_LTLASTFOOT:
2205 if (tabular->GetRowOfLTFoot(actcell, dummy))
2206 status |= func_status::ToggleOn;
2208 status |= func_status::ToggleOff;
2210 case LyXTabular::SET_LTNEWPAGE:
2211 if (tabular->GetLTNewPage(actcell))
2212 status |= func_status::ToggleOn;
2214 status |= func_status::ToggleOff;
2217 status = func_status::Disabled;
2224 std::vector<string> const InsetTabular::getLabelList() const
2226 return tabular->getLabelList();
2230 bool InsetTabular::copySelection(BufferView * bv)
2232 if (!hasSelection())
2235 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2236 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2237 if (sel_col_start > sel_col_end) {
2238 sel_col_start = sel_col_end;
2239 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2241 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2243 int const columns = sel_col_end - sel_col_start + 1;
2245 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2246 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2247 if (sel_row_start > sel_row_end) {
2248 swap(sel_row_start, sel_row_end);
2250 int const rows = sel_row_end - sel_row_start + 1;
2252 delete paste_tabular;
2253 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2254 for (int i = 0; i < sel_row_start; ++i)
2255 paste_tabular->DeleteRow(0);
2256 while(paste_tabular->rows() > rows)
2257 paste_tabular->DeleteRow(rows);
2258 paste_tabular->SetTopLine(0, true, true);
2259 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2261 for (int i = 0; i < sel_col_start; ++i)
2262 paste_tabular->DeleteColumn(0);
2263 while (paste_tabular->columns() > columns)
2264 paste_tabular->DeleteColumn(columns);
2265 paste_tabular->SetLeftLine(0, true, true);
2266 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2270 paste_tabular->Ascii(bv->buffer(), sstr);
2271 bv->stuffClipboard(sstr.str().c_str());
2276 bool InsetTabular::pasteSelection(BufferView * bv)
2281 for (int r1 = 0, r2 = actrow;
2282 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2284 for(int c1 = 0, c2 = actcol;
2285 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2287 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2288 tabular->IsPartOfMultiColumn(r2,c2))
2290 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2294 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2298 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2299 int const n2 = tabular->GetCellNumber(r2, c2);
2300 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2301 tabular->GetCellInset(n2)->setOwner(this);
2302 tabular->GetCellInset(n2)->deleteLyXText(bv);
2309 bool InsetTabular::cutSelection()
2311 if (!hasSelection())
2314 //int sel_col_start;
2316 //int sel_row_start;
2319 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2320 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2321 if (sel_col_start > sel_col_end) {
2322 sel_col_start = sel_col_end;
2323 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2325 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2327 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2328 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2329 if (sel_row_start > sel_row_end) {
2330 //int tmp = sel_row_start;
2331 //sel_row_start = sel_row_end;
2332 //sel_row_end = tmp;
2333 swap(sel_row_start, sel_row_end);
2335 if (sel_cell_start > sel_cell_end) {
2336 //int tmp = sel_cell_start;
2337 //sel_cell_start = sel_cell_end;
2338 //sel_cell_end = tmp;
2339 swap(sel_cell_start, sel_cell_end);
2341 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2342 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2343 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2350 bool InsetTabular::isRightToLeft(BufferView *bv )
2352 return bv->getParentLanguage(this)->RightToLeft();
2356 bool InsetTabular::nodraw() const
2358 if (!UpdatableInset::nodraw() && the_locking_inset)
2359 return the_locking_inset->nodraw();
2360 return UpdatableInset::nodraw();
2364 int InsetTabular::scroll(bool recursive) const
2366 int sx = UpdatableInset::scroll(false);
2368 if (recursive && the_locking_inset)
2369 sx += the_locking_inset->scroll(recursive);
2375 bool InsetTabular::doClearArea() const
2377 return !locked || (need_update & (FULL|INIT));
2381 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2383 srow = tabular->row_of_cell(sel_cell_start);
2384 erow = tabular->row_of_cell(sel_cell_end);
2388 scol = tabular->column_of_cell(sel_cell_start);
2389 ecol = tabular->column_of_cell(sel_cell_end);
2393 ecol = tabular->right_column_of_cell(sel_cell_end);
2396 Paragraph * InsetTabular::getParFromID(int id) const
2399 for(int i = 0; i < tabular->rows(); ++i) {
2400 for(int j = 0; j < tabular->columns(); ++j) {
2401 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2408 Paragraph * InsetTabular::firstParagraph() const
2410 if (the_locking_inset)
2411 return the_locking_inset->firstParagraph();
2415 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2417 if (the_locking_inset)
2418 return the_locking_inset->cursor(bv);
2419 return Inset::cursor(bv);
2423 Inset * InsetTabular::getInsetFromID(int id_arg) const
2426 return const_cast<InsetTabular *>(this);
2429 for(int i=0; i < tabular->rows(); ++i) {
2430 for(int j=0; j < tabular->columns(); ++j) {
2431 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
2439 string InsetTabular::selectNextWord(BufferView * bv, float & value) const
2441 if (the_locking_inset) {
2443 str = the_locking_inset->selectNextWord(bv, value);
2447 if (tabular->IsLastCell(actcell)) {
2448 bv->unlockInset(const_cast<InsetTabular *>(this));
2452 // otherwise we have to lock the next inset and ask for it's selecttion
2453 UpdatableInset * inset =
2454 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2455 inset->edit(bv, 0, 0, 0);
2456 string str = selectNextWordInt(bv, value);
2462 string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
2464 if (the_locking_inset) {
2466 str = the_locking_inset->selectNextWord(bv, value);
2470 if (tabular->IsLastCell(actcell)) {
2471 bv->unlockInset(const_cast<InsetTabular *>(this));
2475 // otherwise we have to lock the next inset and ask for it's selecttion
2476 UpdatableInset * inset =
2477 static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
2478 inset->edit(bv, 0, 0, 0);
2479 return selectNextWordInt(bv, value);
2483 void InsetTabular::selectSelectedWord(BufferView * bv)
2485 if (the_locking_inset) {
2486 the_locking_inset->selectSelectedWord(bv);
2492 void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
2494 if (the_locking_inset) {
2495 the_locking_inset->toggleSelection(bv, kill_selection);