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()
637 return the_locking_inset ? the_locking_inset->getLockingInset() : this;
641 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
645 if (the_locking_inset)
646 return the_locking_inset->getFirstLockingInsetOfType(c);
651 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
653 if (the_locking_inset)
654 return the_locking_inset->insertInset(bv, inset);
659 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
661 if (hasSelection() && (button == 3))
664 if (hasSelection()) {
666 updateLocal(bv, SELECTION, false);
669 no_selection = false;
671 int const ocell = actcell;
672 int const orow = actrow;
677 updateLocal(bv, NONE, false);
678 sel_cell_start = sel_cell_end = actcell;
680 if ((ocell != actcell) && the_locking_inset) {
681 the_locking_inset->insetUnlock(bv);
682 the_locking_inset = 0;
688 bool const inset_hit = insetHit(bv, x, y);
690 if ((ocell == actcell) && the_locking_inset && inset_hit) {
692 the_locking_inset->insetButtonPress(bv,
693 x - inset_x, y - inset_y,
696 } else if (the_locking_inset) {
697 the_locking_inset->insetUnlock(bv);
699 the_locking_inset = 0;
701 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
704 if (inset_hit && bv->theLockingInset()) {
705 if (activateCellInsetAbs(bv, x, y, button))
706 the_locking_inset->insetButtonPress(bv,
716 void InsetTabular::insetButtonRelease(BufferView * bv,
717 int x, int y, int button)
720 if (the_locking_inset) {
722 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
723 i->insetButtonRelease(bv, x, y, button);
727 bv->owner()->getDialogs()->showTabular(this);
730 if (the_locking_inset) {
731 the_locking_inset->insetButtonRelease(bv,
732 x - inset_x, y - inset_y,
736 no_selection = false;
740 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
742 if (the_locking_inset) {
743 the_locking_inset->insetMotionNotify(bv,
751 int const old_cell = actcell;
754 sel_cell_end = actcell;
755 if (sel_cell_end != old_cell)
756 updateLocal(bv, SELECTION, false);
759 no_selection = false;
763 void InsetTabular::insetKeyPress(XKeyEvent * xke)
765 if (the_locking_inset) {
766 the_locking_inset->insetKeyPress(xke);
772 UpdatableInset::RESULT
773 InsetTabular::localDispatch(BufferView * bv,
777 // We need to save the value of the_locking_inset as the call to
778 // the_locking_inset->LocalDispatch might unlock it.
779 old_locking_inset = the_locking_inset;
780 no_selection = false;
781 UpdatableInset::RESULT result =
782 UpdatableInset::localDispatch(bv, action, arg);
783 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
788 if ((action < 0) && arg.empty())
791 bool hs = hasSelection();
794 // this one have priority over the locked InsetText!
799 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) != this)
802 if (the_locking_inset) {
803 unlockInsetInInset(bv, the_locking_inset);
804 the_locking_inset = 0;
806 if (action == LFUN_TAB)
807 moveNextCell(bv, old_locking_inset != 0);
809 movePrevCell(bv, old_locking_inset != 0);
810 sel_cell_start = sel_cell_end = actcell;
812 updateLocal(bv, SELECTION, false);
813 if (!the_locking_inset) {
815 return DISPATCHED_NOUPDATE;
819 // this to avoid compiler warnings.
824 if (the_locking_inset) {
825 result = the_locking_inset->localDispatch(bv, action, arg);
826 if (result == DISPATCHED_NOUPDATE) {
829 if (sc != scroll()) { // inset has been scrolled
830 the_locking_inset->toggleInsetCursor(bv);
831 updateLocal(bv, FULL, false);
832 the_locking_inset->toggleInsetCursor(bv);
835 } else if (result == DISPATCHED) {
836 the_locking_inset->toggleInsetCursor(bv);
837 updateLocal(bv, CELL, false);
838 the_locking_inset->toggleInsetCursor(bv);
840 } else if (result == FINISHED) {
847 // --- Cursor Movements ----------------------------------
849 if (tabular->IsLastCellInRow(actcell))
851 moveRight(bv, false);
852 sel_cell_end = actcell;
853 updateLocal(bv, SELECTION, false);
856 result = moveRight(bv);
857 sel_cell_start = sel_cell_end = actcell;
859 updateLocal(bv, SELECTION, false);
862 if (tabular->IsFirstCellInRow(actcell))
865 sel_cell_end = actcell;
866 updateLocal(bv, SELECTION, false);
869 result = moveLeft(bv);
870 sel_cell_start = sel_cell_end = actcell;
872 updateLocal(bv, SELECTION, false);
876 int const ocell = actcell;
878 if ((ocell == sel_cell_end) ||
879 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
880 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
882 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
883 updateLocal(bv, SELECTION, false);
887 result = moveDown(bv, old_locking_inset != 0);
888 sel_cell_start = sel_cell_end = actcell;
890 updateLocal(bv, SELECTION, false);
894 int const ocell = actcell;
896 if ((ocell == sel_cell_end) ||
897 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
898 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
900 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
901 updateLocal(bv, SELECTION, false);
905 result = moveUp(bv, old_locking_inset != 0);
906 sel_cell_start = sel_cell_end = actcell;
908 updateLocal(bv, SELECTION, false);
912 if (the_locking_inset) {
913 unlockInsetInInset(bv, the_locking_inset);
914 the_locking_inset = 0;
916 if (bv->text->first + bv->painter().paperHeight() <
917 (top_baseline + tabular->GetHeightOfTabular()))
919 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
920 updateLocal(bv, FULL, false);
921 actcell = tabular->GetCellBelow(first_visible_cell) + column;
923 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
926 updateLocal(bv, CURSOR, false);
931 if (the_locking_inset) {
932 unlockInsetInInset(bv, the_locking_inset);
933 the_locking_inset = 0;
935 if (top_baseline < 0) {
936 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
937 updateLocal(bv, FULL, false);
938 if (top_baseline > 0)
941 actcell = tabular->GetCellBelow(first_visible_cell) + column;
946 updateLocal(bv, CURSOR, false);
957 case LFUN_LAYOUT_TABULAR:
959 bv->owner()->getDialogs()->showTabular(this);
962 case LFUN_TABULAR_FEATURE:
963 if (!tabularFeatures(bv, arg))
964 result = UNDISPATCHED;
967 if (!copySelection(bv))
969 setUndo(bv, Undo::DELETE,
970 bv->text->cursor.par(),
971 bv->text->cursor.par()->next());
973 updateLocal(bv, INIT, true);
981 case LFUN_PASTESELECTION:
983 string const clip(bv->getClipboard());
987 if (clip.find('\t') != string::npos) {
991 unsigned int len = clip.length();
992 string::size_type p = 0;
995 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1003 maxCols = max(cols, maxCols);
1009 maxCols = max(cols, maxCols);
1010 delete paste_tabular;
1011 paste_tabular = new LyXTabular(this, rows, maxCols);
1012 string::size_type op = 0;
1014 int cells = paste_tabular->GetNumberOfCells();
1016 while((cell < cells) && (p < len) &&
1017 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1022 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1027 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1028 while(cols++ < maxCols)
1036 // check for the last cell if there is no trailing '\n'
1037 if ((cell < cells) && (op < len))
1038 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1040 // so that the clipboard is used and it goes on
1042 // and executes LFUN_PASTESELECTION in insettext!
1043 delete paste_tabular;
1048 if (hasPasteBuffer()) {
1049 setUndo(bv, Undo::INSERT,
1050 bv->text->cursor.par(),
1051 bv->text->cursor.par()->next());
1053 updateLocal(bv, INIT, true);
1056 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1058 // we try to activate the actual inset and put this event down to
1059 // the insets dispatch function.
1060 result = UNDISPATCHED;
1061 if (the_locking_inset)
1064 if (activateCellInset(bv)) {
1065 // reset need_update setted in above function!
1067 result = the_locking_inset->localDispatch(bv, action, arg);
1068 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1069 unlockInsetInInset(bv, the_locking_inset);
1071 the_locking_inset = 0;
1072 // we need to update if this was requested before
1073 updateLocal(bv, NONE, false);
1074 return UNDISPATCHED;
1077 // the_locking_inset->ToggleInsetCursor(bv);
1078 updateLocal(bv, CELL, false);
1079 // the_locking_inset->ToggleInsetCursor(bv);
1084 if (result!=FINISHED) {
1085 if (!the_locking_inset) {
1086 showInsetCursor(bv);
1089 bv->unlockInset(this);
1094 int InsetTabular::latex(Buffer const * buf, ostream & os,
1095 bool fragile, bool fp) const
1097 return tabular->Latex(buf, os, fragile, fp);
1101 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1103 // This should be changed to a real ascii export
1104 return tabular->Ascii(buf, os);
1108 int InsetTabular::linuxdoc(Buffer const *, ostream &) const
1114 int InsetTabular::docBook(Buffer const * buf, ostream & os) const
1116 return tabular->DocBook(buf,os);
1120 void InsetTabular::validate(LaTeXFeatures & features) const
1122 tabular->Validate(features);
1126 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1127 LyXFont const & font,
1134 bool changed = false;
1136 // if we have a locking_inset we should have to check only this cell for
1137 // change so I'll try this to have a boost, but who knows ;)
1138 if ((need_update != INIT) &&
1139 (the_locking_inset == tabular->GetCellInset(actcell))) {
1140 for(int i = 0; i < tabular->columns(); ++i) {
1141 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1143 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1146 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1147 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1148 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1154 for (int i = 0; i < tabular->rows(); ++i) {
1157 for (int j = 0; j < tabular->columns(); ++j) {
1158 if (tabular->IsPartOfMultiColumn(i,j))
1161 inset = tabular->GetCellInset(cell);
1163 inset->update(bv, font, false);
1164 maxAsc = max(maxAsc, inset->ascent(bv, font));
1165 maxDesc = max(maxDesc, inset->descent(bv, font));
1166 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1168 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1169 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1175 void InsetTabular::getCursorPos(BufferView *,
1176 int & x, int & y) const
1178 x = cursor_.x() - top_x;
1183 void InsetTabular::toggleInsetCursor(BufferView * bv)
1185 if (the_locking_inset) {
1186 the_locking_inset->toggleInsetCursor(bv);
1190 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1192 int const asc = lyxfont::maxAscent(font);
1193 int const desc = lyxfont::maxDescent(font);
1195 if (isCursorVisible())
1196 bv->hideLockedInsetCursor();
1198 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1199 toggleCursorVisible();
1203 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1205 if (!isCursorVisible()) {
1206 LyXFont font; // = GetFont(par, cursor.pos);
1208 int const asc = lyxfont::maxAscent(font);
1209 int const desc = lyxfont::maxDescent(font);
1210 bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1212 bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
1213 setCursorVisible(true);
1218 void InsetTabular::hideInsetCursor(BufferView * bv)
1220 if (isCursorVisible()) {
1221 bv->hideLockedInsetCursor();
1222 setCursorVisible(false);
1224 // if (cursor_visible)
1225 // ToggleInsetCursor(bv);
1229 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1233 actcell = actrow = actcol = 0;
1234 int ly = tabular->GetDescentOfRow(actrow);
1236 // first search the right row
1237 while((ly < y) && (actrow < tabular->rows())) {
1238 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1239 tabular->GetAscentOfRow(actrow + 1) +
1240 tabular->GetAdditionalHeight(actrow + 1));
1242 ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
1244 actcell = tabular->GetCellNumber(actrow, actcol);
1246 // now search the right column
1247 int lx = tabular->GetWidthOfColumn(actcell) -
1248 tabular->GetAdditionalWidth(actcell);
1250 #ifdef WITH_WARNINGS
1251 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1253 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1254 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1255 tabular->GetAdditionalWidth(actcell - 1));
1257 // Jürgen, you should check that this is correct. (Lgb)
1258 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1259 lx += tabular->GetWidthOfColumn(actcell + 1)
1260 + tabular->GetAdditionalWidth(actcell);
1264 cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1269 int InsetTabular::getCellXPos(int cell) const
1273 for (; !tabular->IsFirstCellInRow(c); --c)
1275 int lx = tabular->GetWidthOfColumn(cell);
1276 for (; c < cell; ++c) {
1277 lx += tabular->GetWidthOfColumn(c);
1279 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1283 void InsetTabular::resetPos(BufferView * bv) const
1287 actcol = tabular->column_of_cell(actcell);
1292 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1293 if (tabular->IsLastCellInRow(cell)) {
1294 cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
1295 tabular->GetAscentOfRow(actrow + 1) +
1296 tabular->GetAdditionalHeight(actrow + 1));
1300 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1301 int new_x = getCellXPos(actcell);
1302 int old_x = cursor_.x();
1305 // cursor.x(getCellXPos(actcell) + offset);
1306 if ((actcol < tabular->columns()-1) && scroll(false) &&
1307 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1310 updateLocal(bv, FULL, false);
1311 } else if (the_locking_inset &&
1312 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1314 int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
1315 if (xx > (bv->workWidth()-20)) {
1316 scroll(bv, -(xx - bv->workWidth() + 60));
1317 updateLocal(bv, FULL, false);
1318 } else if (xx < 20) {
1324 updateLocal(bv, FULL, false);
1326 } else if ((cursor_.x() - offset) > 20 &&
1327 (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
1328 > (bv->workWidth() - 20)) {
1329 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1330 updateLocal(bv, FULL, false);
1331 } else if ((cursor_.x() - offset) < 20) {
1332 scroll(bv, 20 - cursor_.x() + offset);
1333 updateLocal(bv, FULL, false);
1334 } else if (scroll(false) && top_x > 20 &&
1335 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1336 scroll(bv, old_x - cursor_.x());
1337 updateLocal(bv, FULL, false);
1339 if ((!the_locking_inset ||
1340 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1341 actcell != oldcell) {
1342 InsetTabular * inset = const_cast<InsetTabular *>(this);
1343 bv->owner()->getDialogs()->updateTabular(inset);
1349 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1351 if (lock && !old_locking_inset) {
1352 if (activateCellInset(bv))
1355 bool moved = isRightToLeft(bv)
1356 ? movePrevCell(bv) : moveNextCell(bv);
1359 if (lock && activateCellInset(bv))
1363 return DISPATCHED_NOUPDATE;
1367 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1369 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1372 if (lock) { // behind the inset
1373 if (activateCellInset(bv, 0, 0, 0, true))
1377 return DISPATCHED_NOUPDATE;
1381 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1383 int const ocell = actcell;
1384 actcell = tabular->GetCellAbove(actcell);
1385 if (actcell == ocell) // we moved out of the inset
1391 if (old_locking_inset) {
1392 old_locking_inset->getCursorPos(bv, x, y);
1393 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1395 if (activateCellInset(bv, x, 0))
1398 return DISPATCHED_NOUPDATE;
1402 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1404 int const ocell = actcell;
1405 actcell = tabular->GetCellBelow(actcell);
1406 if (actcell == ocell) // we moved out of the inset
1412 if (old_locking_inset) {
1413 old_locking_inset->getCursorPos(bv, x, y);
1414 x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
1416 if (activateCellInset(bv, x, 0))
1419 return DISPATCHED_NOUPDATE;
1423 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1425 if (isRightToLeft(bv)) {
1426 if (tabular->IsFirstCellInRow(actcell)) {
1427 int row = tabular->row_of_cell(actcell);
1428 if (row == tabular->rows() - 1)
1430 actcell = tabular->GetLastCellInRow(row);
1431 actcell = tabular->GetCellBelow(actcell);
1438 if (tabular->IsLastCell(actcell))
1443 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1444 isRightToLeftPar(bv->buffer()->params);
1445 activateCellInset(bv, 0, 0, 0, !rtl);
1452 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1454 if (isRightToLeft(bv)) {
1455 if (tabular->IsLastCellInRow(actcell)) {
1456 int row = tabular->row_of_cell(actcell);
1459 actcell = tabular->GetFirstCellInRow(row);
1460 actcell = tabular->GetCellAbove(actcell);
1462 if (tabular->IsLastCell(actcell))
1467 if (!actcell) // first cell
1472 bool rtl = tabular->GetCellInset(actcell)->paragraph()->
1473 isRightToLeftPar(bv->buffer()->params);
1474 activateCellInset(bv, 0, 0, 0, !rtl);
1481 bool InsetTabular::Delete()
1483 #warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
1484 #warning I guess this could be 'deletable'! (Jug)
1489 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1494 sel_cell_end = tabular->GetNumberOfCells() - 1;
1496 if (hasSelection()) {
1498 setUndo(bv, Undo::EDIT,
1499 bv->text->cursor.par(),
1500 bv->text->cursor.par()->next());
1501 frozen = undo_frozen;
1504 // apply the fontchange on the whole selection
1509 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1510 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1511 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1512 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1517 updateLocal(bv, INIT, true);
1519 if (the_locking_inset)
1520 the_locking_inset->setFont(bv, font, tall);
1524 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1526 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1529 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1530 string const tmp = tabularFeature[i].feature;
1532 if (tmp == what.substr(0, tmp.length())) {
1533 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1534 //tabularFeatures[i].feature.length())) {
1535 action = tabularFeature[i].action;
1539 if (action == LyXTabular::LAST_ACTION)
1543 frontStrip(what.substr(tabularFeature[i].feature.length()));
1544 tabularFeatures(bv, action, val);
1549 void InsetTabular::tabularFeatures(BufferView * bv,
1550 LyXTabular::Feature feature,
1551 string const & value)
1557 bool setLines = false;
1558 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1559 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1562 case LyXTabular::M_ALIGN_LEFT:
1563 case LyXTabular::ALIGN_LEFT:
1564 setAlign=LYX_ALIGN_LEFT;
1566 case LyXTabular::M_ALIGN_RIGHT:
1567 case LyXTabular::ALIGN_RIGHT:
1568 setAlign=LYX_ALIGN_RIGHT;
1570 case LyXTabular::M_ALIGN_CENTER:
1571 case LyXTabular::ALIGN_CENTER:
1572 setAlign=LYX_ALIGN_CENTER;
1574 case LyXTabular::M_VALIGN_TOP:
1575 case LyXTabular::VALIGN_TOP:
1576 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1578 case LyXTabular::M_VALIGN_BOTTOM:
1579 case LyXTabular::VALIGN_BOTTOM:
1580 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1582 case LyXTabular::M_VALIGN_CENTER:
1583 case LyXTabular::VALIGN_CENTER:
1584 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1589 if (hasSelection()) {
1590 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1592 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1593 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1595 setUndo(bv, Undo::FINISH,
1596 bv->text->cursor.par(),
1597 bv->text->cursor.par()->next());
1599 int row = tabular->row_of_cell(actcell);
1600 int column = tabular->column_of_cell(actcell);
1604 case LyXTabular::SET_PWIDTH:
1606 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1607 tabular->SetColumnPWidth(actcell,value);
1609 for (int i = 0; i < tabular->rows(); ++i) {
1610 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1613 updateLocal(bv, INIT, true);
1617 case LyXTabular::SET_MPWIDTH:
1619 bool const update = (tabular->GetPWidth(actcell) != value);
1620 tabular->SetMColumnPWidth(actcell,value);
1622 for (int i = 0; i < tabular->rows(); ++i) {
1623 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1626 updateLocal(bv, INIT, true);
1630 case LyXTabular::SET_SPECIAL_COLUMN:
1631 case LyXTabular::SET_SPECIAL_MULTI:
1632 tabular->SetAlignSpecial(actcell,value,feature);
1634 case LyXTabular::APPEND_ROW:
1635 // append the row into the tabular
1636 unlockInsetInInset(bv, the_locking_inset);
1637 tabular->AppendRow(actcell);
1638 updateLocal(bv, INIT, true);
1640 case LyXTabular::APPEND_COLUMN:
1641 // append the column into the tabular
1642 unlockInsetInInset(bv, the_locking_inset);
1643 tabular->AppendColumn(actcell);
1644 actcell = tabular->GetCellNumber(row, column);
1645 updateLocal(bv, INIT, true);
1647 case LyXTabular::DELETE_ROW:
1648 unlockInsetInInset(bv, the_locking_inset);
1649 tabular->DeleteRow(tabular->row_of_cell(actcell));
1650 if ((row+1) > tabular->rows())
1652 actcell = tabular->GetCellNumber(row, column);
1654 updateLocal(bv, INIT, true);
1656 case LyXTabular::DELETE_COLUMN:
1657 unlockInsetInInset(bv, the_locking_inset);
1658 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1659 if ((column+1) > tabular->columns())
1661 actcell = tabular->GetCellNumber(row, column);
1663 updateLocal(bv, INIT, true);
1665 case LyXTabular::M_TOGGLE_LINE_TOP:
1667 case LyXTabular::TOGGLE_LINE_TOP:
1669 bool lineSet = !tabular->TopLine(actcell, flag);
1670 for (int i = sel_row_start; i <= sel_row_end; ++i)
1671 for (int j = sel_col_start; j <= sel_col_end; ++j)
1672 tabular->SetTopLine(
1673 tabular->GetCellNumber(i, j),
1675 updateLocal(bv, INIT, true);
1679 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1681 case LyXTabular::TOGGLE_LINE_BOTTOM:
1683 bool lineSet = !tabular->BottomLine(actcell, flag);
1684 for (int i = sel_row_start; i <= sel_row_end; ++i)
1685 for (int j = sel_col_start; j <= sel_col_end; ++j)
1686 tabular->SetBottomLine(
1687 tabular->GetCellNumber(i, j),
1690 updateLocal(bv, INIT, true);
1694 case LyXTabular::M_TOGGLE_LINE_LEFT:
1696 case LyXTabular::TOGGLE_LINE_LEFT:
1698 bool lineSet = !tabular->LeftLine(actcell, flag);
1699 for (int i = sel_row_start; i <= sel_row_end; ++i)
1700 for (int j = sel_col_start; j <= sel_col_end; ++j)
1701 tabular->SetLeftLine(
1702 tabular->GetCellNumber(i,j),
1705 updateLocal(bv, INIT, true);
1709 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1711 case LyXTabular::TOGGLE_LINE_RIGHT:
1713 bool lineSet = !tabular->RightLine(actcell, flag);
1714 for (int i = sel_row_start; i <= sel_row_end; ++i)
1715 for (int j = sel_col_start; j <= sel_col_end; ++j)
1716 tabular->SetRightLine(
1717 tabular->GetCellNumber(i,j),
1720 updateLocal(bv, INIT, true);
1724 case LyXTabular::M_ALIGN_LEFT:
1725 case LyXTabular::M_ALIGN_RIGHT:
1726 case LyXTabular::M_ALIGN_CENTER:
1728 case LyXTabular::ALIGN_LEFT:
1729 case LyXTabular::ALIGN_RIGHT:
1730 case LyXTabular::ALIGN_CENTER:
1731 for (int i = sel_row_start; i <= sel_row_end; ++i)
1732 for (int j = sel_col_start; j <= sel_col_end; ++j)
1733 tabular->SetAlignment(
1734 tabular->GetCellNumber(i, j),
1737 updateLocal(bv, INIT, true);
1739 case LyXTabular::M_VALIGN_TOP:
1740 case LyXTabular::M_VALIGN_BOTTOM:
1741 case LyXTabular::M_VALIGN_CENTER:
1743 case LyXTabular::VALIGN_TOP:
1744 case LyXTabular::VALIGN_BOTTOM:
1745 case LyXTabular::VALIGN_CENTER:
1746 for (int i = sel_row_start; i <= sel_row_end; ++i)
1747 for (int j = sel_col_start; j <= sel_col_end; ++j)
1748 tabular->SetVAlignment(
1749 tabular->GetCellNumber(i, j),
1751 updateLocal(bv, INIT, true);
1753 case LyXTabular::MULTICOLUMN:
1755 if (sel_row_start != sel_row_end) {
1756 WriteAlert(_("Impossible Operation!"),
1757 _("Multicolumns can only be horizontally."),
1761 // just multicol for one Single Cell
1762 if (!hasSelection()) {
1763 // check wether we are completly in a multicol
1764 if (tabular->IsMultiColumn(actcell)) {
1765 tabular->UnsetMultiColumn(actcell);
1766 updateLocal(bv, INIT, true);
1768 tabular->SetMultiColumn(actcell, 1);
1769 updateLocal(bv, CELL, true);
1773 // we have a selection so this means we just add all this
1774 // cells to form a multicolumn cell
1778 if (sel_cell_start > sel_cell_end) {
1779 s_start = sel_cell_end;
1780 s_end = sel_cell_start;
1782 s_start = sel_cell_start;
1783 s_end = sel_cell_end;
1785 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1787 sel_cell_end = sel_cell_start;
1788 updateLocal(bv, INIT, true);
1791 case LyXTabular::SET_ALL_LINES:
1793 case LyXTabular::UNSET_ALL_LINES:
1794 for (int i = sel_row_start; i <= sel_row_end; ++i)
1795 for (int j = sel_col_start; j <= sel_col_end; ++j)
1796 tabular->SetAllLines(
1797 tabular->GetCellNumber(i,j), setLines);
1798 updateLocal(bv, INIT, true);
1800 case LyXTabular::SET_LONGTABULAR:
1801 tabular->SetLongTabular(true);
1802 updateLocal(bv, INIT, true); // because this toggles displayed
1804 case LyXTabular::UNSET_LONGTABULAR:
1805 tabular->SetLongTabular(false);
1806 updateLocal(bv, INIT, true); // because this toggles displayed
1808 case LyXTabular::SET_ROTATE_TABULAR:
1809 tabular->SetRotateTabular(true);
1811 case LyXTabular::UNSET_ROTATE_TABULAR:
1812 tabular->SetRotateTabular(false);
1814 case LyXTabular::SET_ROTATE_CELL:
1815 for (int i = sel_row_start; i <= sel_row_end; ++i)
1816 for (int j = sel_col_start; j<=sel_col_end; ++j)
1817 tabular->SetRotateCell(
1818 tabular->GetCellNumber(i, j),
1821 case LyXTabular::UNSET_ROTATE_CELL:
1822 for (int i = sel_row_start; i <= sel_row_end; ++i)
1823 for (int j = sel_col_start; j <= sel_col_end; ++j)
1824 tabular->SetRotateCell(
1825 tabular->GetCellNumber(i, j), false);
1827 case LyXTabular::SET_USEBOX:
1829 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1830 if (val == tabular->GetUsebox(actcell))
1831 val = LyXTabular::BOX_NONE;
1832 for (int i = sel_row_start; i <= sel_row_end; ++i)
1833 for (int j = sel_col_start; j <= sel_col_end; ++j)
1835 tabular->GetCellNumber(i, j), val);
1838 case LyXTabular::SET_LTFIRSTHEAD:
1839 tabular->SetLTHead(actcell, true);
1841 case LyXTabular::SET_LTHEAD:
1842 tabular->SetLTHead(actcell, false);
1844 case LyXTabular::SET_LTFOOT:
1845 tabular->SetLTFoot(actcell, false);
1847 case LyXTabular::SET_LTLASTFOOT:
1848 tabular->SetLTFoot(actcell, true);
1850 case LyXTabular::SET_LTNEWPAGE:
1852 bool what = !tabular->GetLTNewPage(actcell);
1853 tabular->SetLTNewPage(actcell, what);
1856 // dummy stuff just to avoid warnings
1857 case LyXTabular::LAST_ACTION:
1863 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1866 UpdatableInset * inset =
1867 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1868 LyXFont font(LyXFont::ALL_SANE);
1870 x = inset->x() + inset->width(bv, font);
1871 y = inset->descent(bv, font);
1873 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1874 //inset_y = cursor.y();
1875 inset->edit(bv, x, y, button);
1876 if (!the_locking_inset)
1878 updateLocal(bv, CELL, false);
1879 return (the_locking_inset != 0);
1883 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1886 inset_x = cursor_.x()
1887 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1888 inset_y = cursor_.y();
1889 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1893 bool InsetTabular::insetHit(BufferView *, int x, int) const
1896 > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
1900 // This returns paperWidth() if the cell-width is unlimited or the width
1901 // in pixels if we have a pwidth for this cell.
1902 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
1904 string const s = tabular->GetPWidth(cell);
1908 return VSpace(s).inPixels(bv);
1912 int InsetTabular::getMaxWidth(BufferView * bv,
1913 UpdatableInset const * inset) const
1915 int cell = tabular->cur_cell;
1916 if (tabular->GetCellInset(cell) != inset) {
1918 if (tabular->GetCellInset(cell) != inset) {
1920 lyxerr << "Actcell not equal to actual cell!\n";
1925 int const n = tabular->GetNumberOfCells();
1928 for (cell = 0; cell < n; ++cell) {
1929 if (tabular->GetCellInset(cell) == inset)
1935 lyxerr << "Own inset not found, shouldn't really happen!\n";
1939 int w = getMaxWidthOfCell(bv, cell);
1941 // because the inset then subtracts it's top_x and owner->x()
1942 w += (inset->x() - top_x);
1949 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
1951 resizeLyXText(bv, recursive);
1955 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
1958 for(int i = 0; i < tabular->rows(); ++i) {
1959 for(int j = 0; j < tabular->columns(); ++j) {
1960 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
1968 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1969 bool const recursive) const
1971 if (the_locking_inset)
1972 return the_locking_inset->getLyXText(bv, recursive);
1973 return Inset::getLyXText(bv, recursive);
1977 bool InsetTabular::showInsetDialog(BufferView * bv) const
1979 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
1980 bv->owner()->getDialogs()
1981 ->showTabular(const_cast<InsetTabular *>(this));
1986 void InsetTabular::openLayoutDialog(BufferView * bv) const
1988 if (the_locking_inset) {
1989 InsetTabular * i = static_cast<InsetTabular *>
1990 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
1992 i->openLayoutDialog(bv);
1996 bv->owner()->getDialogs()->showTabular(
1997 const_cast<InsetTabular *>(this));
2001 // functions returns:
2005 // 3 ... toggled off
2007 func_status::value_type InsetTabular::getStatus(string const & what) const
2009 int action = LyXTabular::LAST_ACTION;
2010 func_status::value_type status = func_status::OK;
2013 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2014 string const tmp = tabularFeature[i].feature;
2015 if (tmp == what.substr(0, tmp.length())) {
2016 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2017 // tabularFeatures[i].feature.length())) {
2018 action = tabularFeature[i].action;
2022 if (action == LyXTabular::LAST_ACTION)
2023 return func_status::Unknown;
2025 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2032 if (hasSelection()) {
2033 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2035 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2039 case LyXTabular::SET_PWIDTH:
2040 case LyXTabular::SET_MPWIDTH:
2041 case LyXTabular::SET_SPECIAL_COLUMN:
2042 case LyXTabular::SET_SPECIAL_MULTI:
2043 status |= func_status::Disabled;
2046 case LyXTabular::APPEND_ROW:
2047 case LyXTabular::APPEND_COLUMN:
2048 case LyXTabular::DELETE_ROW:
2049 case LyXTabular::DELETE_COLUMN:
2050 case LyXTabular::SET_ALL_LINES:
2051 case LyXTabular::UNSET_ALL_LINES:
2052 status |= func_status::OK;
2055 case LyXTabular::MULTICOLUMN:
2056 if (tabular->IsMultiColumn(actcell))
2057 status |= func_status::ToggleOn;
2059 status |= func_status::ToggleOff;
2061 case LyXTabular::M_TOGGLE_LINE_TOP:
2063 case LyXTabular::TOGGLE_LINE_TOP:
2064 if (tabular->TopLine(actcell, flag))
2065 status |= func_status::ToggleOn;
2067 status |= func_status::ToggleOff;
2069 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2071 case LyXTabular::TOGGLE_LINE_BOTTOM:
2072 if (tabular->BottomLine(actcell, flag))
2073 status |= func_status::ToggleOn;
2075 status |= func_status::ToggleOff;
2077 case LyXTabular::M_TOGGLE_LINE_LEFT:
2079 case LyXTabular::TOGGLE_LINE_LEFT:
2080 if (tabular->LeftLine(actcell, flag))
2081 status |= func_status::ToggleOn;
2083 status |= func_status::ToggleOff;
2085 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2087 case LyXTabular::TOGGLE_LINE_RIGHT:
2088 if (tabular->RightLine(actcell, flag))
2089 status |= func_status::ToggleOn;
2091 status |= func_status::ToggleOff;
2093 case LyXTabular::M_ALIGN_LEFT:
2095 case LyXTabular::ALIGN_LEFT:
2096 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2097 status |= func_status::ToggleOn;
2099 status |= func_status::ToggleOff;
2101 case LyXTabular::M_ALIGN_RIGHT:
2103 case LyXTabular::ALIGN_RIGHT:
2104 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2105 status |= func_status::ToggleOn;
2107 status |= func_status::ToggleOff;
2109 case LyXTabular::M_ALIGN_CENTER:
2111 case LyXTabular::ALIGN_CENTER:
2112 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2113 status |= func_status::ToggleOn;
2115 status |= func_status::ToggleOff;
2117 case LyXTabular::M_VALIGN_TOP:
2119 case LyXTabular::VALIGN_TOP:
2120 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2121 status |= func_status::ToggleOn;
2123 status |= func_status::ToggleOff;
2125 case LyXTabular::M_VALIGN_BOTTOM:
2127 case LyXTabular::VALIGN_BOTTOM:
2128 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2129 status |= func_status::ToggleOn;
2131 status |= func_status::ToggleOff;
2133 case LyXTabular::M_VALIGN_CENTER:
2135 case LyXTabular::VALIGN_CENTER:
2136 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2137 status |= func_status::ToggleOn;
2139 status |= func_status::ToggleOff;
2141 case LyXTabular::SET_LONGTABULAR:
2142 if (tabular->IsLongTabular())
2143 status |= func_status::ToggleOn;
2145 status |= func_status::ToggleOff;
2147 case LyXTabular::UNSET_LONGTABULAR:
2148 if (!tabular->IsLongTabular())
2149 status |= func_status::ToggleOn;
2151 status |= func_status::ToggleOff;
2153 case LyXTabular::SET_ROTATE_TABULAR:
2154 if (tabular->GetRotateTabular())
2155 status |= func_status::ToggleOn;
2157 status |= func_status::ToggleOff;
2159 case LyXTabular::UNSET_ROTATE_TABULAR:
2160 if (!tabular->GetRotateTabular())
2161 status |= func_status::ToggleOn;
2163 status |= func_status::ToggleOff;
2165 case LyXTabular::SET_ROTATE_CELL:
2166 if (tabular->GetRotateCell(actcell))
2167 status |= func_status::ToggleOn;
2169 status |= func_status::ToggleOff;
2171 case LyXTabular::UNSET_ROTATE_CELL:
2172 if (!tabular->GetRotateCell(actcell))
2173 status |= func_status::ToggleOn;
2175 status |= func_status::ToggleOff;
2177 case LyXTabular::SET_USEBOX:
2178 if (strToInt(argument) == tabular->GetUsebox(actcell))
2179 status |= func_status::ToggleOn;
2181 status |= func_status::ToggleOff;
2183 case LyXTabular::SET_LTFIRSTHEAD:
2184 if (tabular->GetRowOfLTHead(actcell, dummy))
2185 status |= func_status::ToggleOn;
2187 status |= func_status::ToggleOff;
2189 case LyXTabular::SET_LTHEAD:
2190 if (tabular->GetRowOfLTHead(actcell, dummy))
2191 status |= func_status::ToggleOn;
2193 status |= func_status::ToggleOff;
2195 case LyXTabular::SET_LTFOOT:
2196 if (tabular->GetRowOfLTFoot(actcell, dummy))
2197 status |= func_status::ToggleOn;
2199 status |= func_status::ToggleOff;
2201 case LyXTabular::SET_LTLASTFOOT:
2202 if (tabular->GetRowOfLTFoot(actcell, dummy))
2203 status |= func_status::ToggleOn;
2205 status |= func_status::ToggleOff;
2207 case LyXTabular::SET_LTNEWPAGE:
2208 if (tabular->GetLTNewPage(actcell))
2209 status |= func_status::ToggleOn;
2211 status |= func_status::ToggleOff;
2214 status = func_status::Disabled;
2221 std::vector<string> const InsetTabular::getLabelList() const
2223 return tabular->getLabelList();
2227 bool InsetTabular::copySelection(BufferView * bv)
2229 if (!hasSelection())
2232 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2233 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2234 if (sel_col_start > sel_col_end) {
2235 sel_col_start = sel_col_end;
2236 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2238 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2240 int const columns = sel_col_end - sel_col_start + 1;
2242 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2243 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2244 if (sel_row_start > sel_row_end) {
2245 swap(sel_row_start, sel_row_end);
2247 int const rows = sel_row_end - sel_row_start + 1;
2249 delete paste_tabular;
2250 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2251 for (int i = 0; i < sel_row_start; ++i)
2252 paste_tabular->DeleteRow(0);
2253 while(paste_tabular->rows() > rows)
2254 paste_tabular->DeleteRow(rows);
2255 paste_tabular->SetTopLine(0, true, true);
2256 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2258 for (int i = 0; i < sel_col_start; ++i)
2259 paste_tabular->DeleteColumn(0);
2260 while (paste_tabular->columns() > columns)
2261 paste_tabular->DeleteColumn(columns);
2262 paste_tabular->SetLeftLine(0, true, true);
2263 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2267 paste_tabular->Ascii(bv->buffer(), sstr);
2268 bv->stuffClipboard(sstr.str().c_str());
2273 bool InsetTabular::pasteSelection(BufferView * bv)
2278 for (int r1 = 0, r2 = actrow;
2279 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2281 for(int c1 = 0, c2 = actcol;
2282 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2284 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2285 tabular->IsPartOfMultiColumn(r2,c2))
2287 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2291 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2295 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2296 int const n2 = tabular->GetCellNumber(r2, c2);
2297 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2298 tabular->GetCellInset(n2)->setOwner(this);
2299 tabular->GetCellInset(n2)->deleteLyXText(bv);
2306 bool InsetTabular::cutSelection()
2308 if (!hasSelection())
2311 //int sel_col_start;
2313 //int sel_row_start;
2316 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2317 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2318 if (sel_col_start > sel_col_end) {
2319 sel_col_start = sel_col_end;
2320 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2322 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2324 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2325 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2326 if (sel_row_start > sel_row_end) {
2327 //int tmp = sel_row_start;
2328 //sel_row_start = sel_row_end;
2329 //sel_row_end = tmp;
2330 swap(sel_row_start, sel_row_end);
2332 if (sel_cell_start > sel_cell_end) {
2333 //int tmp = sel_cell_start;
2334 //sel_cell_start = sel_cell_end;
2335 //sel_cell_end = tmp;
2336 swap(sel_cell_start, sel_cell_end);
2338 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2339 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2340 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2347 bool InsetTabular::isRightToLeft(BufferView *bv )
2349 return bv->getParentLanguage(this)->RightToLeft();
2353 bool InsetTabular::nodraw() const
2355 if (!UpdatableInset::nodraw() && the_locking_inset)
2356 return the_locking_inset->nodraw();
2357 return UpdatableInset::nodraw();
2361 int InsetTabular::scroll(bool recursive) const
2363 int sx = UpdatableInset::scroll(false);
2365 if (recursive && the_locking_inset)
2366 sx += the_locking_inset->scroll(recursive);
2372 bool InsetTabular::doClearArea() const
2374 return !locked || (need_update & (FULL|INIT));
2378 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2380 srow = tabular->row_of_cell(sel_cell_start);
2381 erow = tabular->row_of_cell(sel_cell_end);
2385 scol = tabular->column_of_cell(sel_cell_start);
2386 ecol = tabular->column_of_cell(sel_cell_end);
2390 ecol = tabular->right_column_of_cell(sel_cell_end);
2393 Paragraph * InsetTabular::getParFromID(int id) const
2396 for(int i=0; i < tabular->rows(); ++i) {
2397 for(int j=0; j < tabular->columns(); ++j) {
2398 if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
2405 Paragraph * InsetTabular::firstParagraph() const
2407 if (the_locking_inset)
2408 return the_locking_inset->firstParagraph();
2412 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
2414 if (the_locking_inset)
2415 return the_locking_inset->cursor(bv);
2416 return Inset::cursor(bv);
2420 Inset * InsetTabular::getInsetFromID(int id_arg) const
2423 return const_cast<InsetTabular *>(this);
2426 for(int i=0; i < tabular->rows(); ++i) {
2427 for(int j=0; j < tabular->columns(); ++j) {
2428 if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))