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"
52 const int ADD_TO_HEIGHT = 2;
53 const int ADD_TO_TABULAR_WIDTH = 2;
55 LyXTabular * paste_tabular = 0;
58 struct TabularFeature {
59 LyXTabular::Feature action;
63 //tabular_features * tabularFeatures = 0;
65 TabularFeature tabularFeature[] =
67 { LyXTabular::APPEND_ROW, "append-row" },
68 { LyXTabular::APPEND_COLUMN, "append-column" },
69 { LyXTabular::DELETE_ROW, "delete-row" },
70 { LyXTabular::DELETE_COLUMN, "delete-column" },
71 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
72 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
73 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
74 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
75 { LyXTabular::ALIGN_LEFT, "align-left" },
76 { LyXTabular::ALIGN_RIGHT, "align-right" },
77 { LyXTabular::ALIGN_CENTER, "align-center" },
78 { LyXTabular::VALIGN_TOP, "valign-top" },
79 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
80 { LyXTabular::VALIGN_CENTER, "valign-center" },
81 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
82 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
83 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
84 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
85 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
86 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
87 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
88 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
89 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
90 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
91 { LyXTabular::MULTICOLUMN, "multicolumn" },
92 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
93 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
94 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
95 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
96 { LyXTabular::SET_PWIDTH, "set-pwidth" },
97 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
98 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
99 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
100 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
101 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
102 { LyXTabular::SET_USEBOX, "set-usebox" },
103 { LyXTabular::SET_LTHEAD, "set-lthead" },
104 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
105 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
106 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
107 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
108 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
109 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
110 { LyXTabular::LAST_ACTION, "" }
116 bool InsetTabular::hasPasteBuffer() const
118 return (paste_tabular != 0);
122 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
129 tabular.reset(new LyXTabular(this, rows,columns));
130 // for now make it always display as display() inset
132 the_locking_inset = 0;
133 locked = no_selection = false;
135 actrow = actcell = 0;
141 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
144 tabular.reset(new LyXTabular(this, *(tab.tabular)));
145 the_locking_inset = 0;
146 locked = no_selection = false;
148 actrow = actcell = 0;
149 sel_cell_start = sel_cell_end = 0;
154 InsetTabular::~InsetTabular()
160 Inset * InsetTabular::clone(Buffer const & buf) const
162 InsetTabular * t = new InsetTabular(*this, buf);
163 t->tabular.reset(tabular->clone(t));
168 void InsetTabular::write(Buffer const * buf, ostream & os) const
170 os << " Tabular" << endl;
171 tabular->Write(buf, os);
175 void InsetTabular::read(Buffer const * buf, LyXLex & lex)
177 bool const old_format = (lex.GetString() == "\\LyXTable");
181 //tabular = new LyXTabular(buf, this, lex);
182 tabular.reset(new LyXTabular(buf, this, lex));
190 string token = lex.GetString();
191 while (lex.IsOK() && (token != "\\end_inset")) {
193 token = lex.GetString();
195 if (token != "\\end_inset") {
196 lex.printError("Missing \\end_inset at this point. "
202 int InsetTabular::ascent(BufferView *, LyXFont const &) const
204 return tabular->GetAscentOfRow(0);
208 int InsetTabular::descent(BufferView *, LyXFont const &) const
210 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
214 int InsetTabular::width(BufferView *, LyXFont const &) const
216 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
220 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
221 float & x, bool cleared) const
229 if (need_update == INIT) {
230 if (calculate_dimensions_of_cells(bv, font, true))
231 bv->text->status = LyXText::CHANGED_IN_DRAW;
236 Painter & pain = bv->painter();
242 UpdatableInset::draw(bv, font, baseline, x, cleared);
245 x += static_cast<float>(scroll());
247 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
248 (top_x != int(x)) || (top_baseline != baseline))) {
249 int h = ascent(bv, font) + descent(bv, font);
250 int const tx = display() || !owner() ? 0 : top_x;
251 int w = tx ? width(bv, font) : pain.paperWidth();
252 int ty = baseline - ascent(bv, font);
256 if ((ty + h) > pain.paperHeight())
257 h = pain.paperHeight();
258 if ((top_x + w) > pain.paperWidth())
259 w = pain.paperWidth();
260 pain.fillRectangle(tx, ty, w, h);
265 top_baseline = baseline;
266 x += ADD_TO_TABULAR_WIDTH;
270 first_visible_cell = -1;
271 for (i = 0; i < tabular->rows(); ++i) {
273 cell = tabular->GetCellNumber(i, 0);
274 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
275 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
277 baseline += tabular->GetDescentOfRow(i) +
278 tabular->GetAscentOfRow(i + 1) +
279 tabular->GetAdditionalHeight(i + 1);
282 for (j = 0; j < tabular->columns(); ++j) {
283 if (nx > bv->workWidth())
285 if (tabular->IsPartOfMultiColumn(i, j))
287 cx = nx + tabular->GetBeginningOfTextInCell(cell);
288 if (first_visible_cell < 0)
289 first_visible_cell = cell;
291 drawCellSelection(pain, nx, baseline, i, j, cell);
293 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
295 drawCellLines(pain, nx, baseline, i, cell);
296 nx += tabular->GetWidthOfColumn(cell);
299 baseline += tabular->GetDescentOfRow(i) +
300 tabular->GetAscentOfRow(i + 1) +
301 tabular->GetAdditionalHeight(i + 1);
303 } else if (need_update == CELL) {
306 if (the_locking_inset &&
307 tabular->GetCellInset(actcell) != the_locking_inset)
309 #warning Jürgen, why is this?
310 Inset * inset = tabular->GetCellInset(cell);
312 inset != the_locking_inset && i < tabular->rows();
315 inset != the_locking_inset
316 && j < tabular->columns();
318 if (tabular->IsPartOfMultiColumn(i, j))
320 nx += tabular->GetWidthOfColumn(cell);
322 inset = tabular->GetCellInset(cell);
324 if (tabular->row_of_cell(cell) > i) {
326 baseline += tabular->GetDescentOfRow(i) +
327 tabular->GetAscentOfRow(i + 1) +
328 tabular->GetAdditionalHeight(i + 1);
332 // copute baseline for actual row
333 for (i = 0; i < actrow; ++i) {
334 baseline += tabular->GetDescentOfRow(i) +
335 tabular->GetAscentOfRow(i + 1) +
336 tabular->GetAdditionalHeight(i + 1);
338 // now compute the right x position
339 cell = tabular->GetCellNumber(actrow, 0);
340 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
341 if (tabular->IsPartOfMultiColumn(actrow, j))
343 nx += tabular->GetWidthOfColumn(cell);
347 i = tabular->row_of_cell(cell);
348 if (the_locking_inset != tabular->GetCellInset(cell)) {
349 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
352 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
354 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
355 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
357 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
360 // clear only if we didn't have a change
361 if (need_update == CELL) {
362 // clear before the inset
365 baseline - tabular->GetAscentOfRow(i) + 1,
367 tabular->GetAscentOfRow(i) +
368 tabular->GetDescentOfRow(i) - 1);
369 // clear behind the inset
371 int(cx + the_locking_inset->width(bv,font) + 1),
372 baseline - tabular->GetAscentOfRow(i) + 1,
373 tabular->GetWidthOfColumn(cell) -
374 tabular->GetBeginningOfTextInCell(cell) -
375 the_locking_inset->width(bv,font) -
376 tabular->GetAdditionalWidth(cell) - 1,
377 tabular->GetAscentOfRow(i) +
378 tabular->GetDescentOfRow(i) - 1);
381 x -= ADD_TO_TABULAR_WIDTH;
382 x += width(bv, font);
383 if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
385 for(Inset * inset=owner(); inset; ++i)
386 inset = inset->owner();
387 if (calculate_dimensions_of_cells(bv, font, false))
395 void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
396 int row, int cell) const
398 int x2 = x + tabular->GetWidthOfColumn(cell);
401 if (!tabular->TopAlreadyDrawed(cell)) {
402 on_off = !tabular->TopLine(cell);
403 pain.line(x, baseline - tabular->GetAscentOfRow(row),
404 x2, baseline - tabular->GetAscentOfRow(row),
405 on_off ? LColor::tabularonoffline : LColor::tabularline,
406 on_off ? Painter::line_onoffdash : Painter::line_solid);
408 on_off = !tabular->BottomLine(cell);
409 pain.line(x,baseline + tabular->GetDescentOfRow(row),
410 x2, baseline + tabular->GetDescentOfRow(row),
411 on_off ? LColor::tabularonoffline : LColor::tabularline,
412 on_off ? Painter::line_onoffdash : Painter::line_solid);
413 if (!tabular->LeftAlreadyDrawed(cell)) {
414 on_off = !tabular->LeftLine(cell);
415 pain.line(x, baseline - tabular->GetAscentOfRow(row),
416 x, baseline + tabular->GetDescentOfRow(row),
417 on_off ? LColor::tabularonoffline : LColor::tabularline,
418 on_off ? Painter::line_onoffdash : Painter::line_solid);
420 on_off = !tabular->RightLine(cell);
421 pain.line(x2 - tabular->GetAdditionalWidth(cell),
422 baseline - tabular->GetAscentOfRow(row),
423 x2 - tabular->GetAdditionalWidth(cell),
424 baseline + tabular->GetDescentOfRow(row),
425 on_off ? LColor::tabularonoffline : LColor::tabularline,
426 on_off ? Painter::line_onoffdash : Painter::line_solid);
430 void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
431 int row, int column, int cell) const
433 int cs = tabular->column_of_cell(sel_cell_start);
434 int ce = tabular->column_of_cell(sel_cell_end);
437 cs = tabular->column_of_cell(sel_cell_end);
439 ce = tabular->right_column_of_cell(sel_cell_end);
442 int rs = tabular->row_of_cell(sel_cell_start);
443 int re = tabular->row_of_cell(sel_cell_end);
444 if (rs > re) swap(rs, re);
446 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
447 int w = tabular->GetWidthOfColumn(cell);
448 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
449 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
450 w, h, LColor::selection);
455 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
459 calculate_dimensions_of_cells(bv, font, true);
461 owner()->update(bv, font, true);
464 if (the_locking_inset)
465 the_locking_inset->update(bv, font, reinit);
467 switch (need_update) {
471 if (calculate_dimensions_of_cells(bv, font, false))
483 string const InsetTabular::editMessage() const
485 return _("Opened Tabular Inset");
489 void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
491 UpdatableInset::edit(bv, x, y, button);
493 if (!bv->lockInset(this)) {
494 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
498 the_locking_inset = 0;
502 sel_cell_start = sel_cell_end = actcell;
503 bv->text->finishUndo();
504 if (insetHit(bv, x, y) && (button != 3)) {
505 activateCellInsetAbs(bv, x, y, button);
507 // UpdateLocal(bv, NONE, false);
508 // bv->getOwner()->getPopups().updateFormTabular();
512 void InsetTabular::insetUnlock(BufferView * bv)
514 if (the_locking_inset) {
515 the_locking_inset->insetUnlock(bv);
516 the_locking_inset = 0;
519 no_selection = false;
522 if (scroll(false) || hasSelection()) {
523 sel_cell_start = sel_cell_end = 0;
527 updateLocal(bv, FULL, false);
532 void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
533 bool mark_dirty) const
535 if (need_update < what) // only set this if it has greater update
537 if ((what == INIT) && hasSelection())
540 if (need_update != NONE) {
541 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
542 if (locked) // && (what != NONE))
548 bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
550 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
555 if (inset == tabular->GetCellInset(actcell)) {
556 lyxerr[Debug::INSETS] << "OK" << endl;
557 the_locking_inset = tabular->GetCellInset(actcell);
559 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
560 inset_y = cursor.y();
562 } else if (the_locking_inset && (the_locking_inset == inset)) {
563 lyxerr[Debug::INSETS] << "OK" << endl;
565 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
566 inset_y = cursor.y();
567 } else if (the_locking_inset) {
568 lyxerr[Debug::INSETS] << "MAYBE" << endl;
569 return the_locking_inset->lockInsetInInset(bv, inset);
571 lyxerr[Debug::INSETS] << "NOT OK" << endl;
576 bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
579 if (!the_locking_inset)
581 if (the_locking_inset == inset) {
582 the_locking_inset->insetUnlock(bv);
583 the_locking_inset = 0;
585 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
591 updateLocal(bv, CELL, false);
592 showInsetCursor(bv, false);
595 if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
596 if (inset->lyxCode() == TABULAR_CODE &&
597 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) {
598 bv->owner()->getDialogs()->updateTabular(this);
607 bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
609 if (!the_locking_inset)
611 if (the_locking_inset != inset) {
612 if (!the_locking_inset->updateInsetInInset(bv, inset))
615 updateLocal(bv, CELL, false);
620 unsigned int InsetTabular::insetInInsetY()
622 if (!the_locking_inset)
625 return inset_y + the_locking_inset->insetInInsetY();
629 UpdatableInset * InsetTabular::getLockingInset()
631 return the_locking_inset ? the_locking_inset->getLockingInset() : this;
635 UpdatableInset * InsetTabular::getFirstLockingInsetOfType(Inset::Code c)
639 if (the_locking_inset)
640 return the_locking_inset->getFirstLockingInsetOfType(c);
645 bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
647 if (the_locking_inset)
648 return the_locking_inset->insertInset(bv, inset);
653 void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
655 if (hasSelection() && (button == 3))
658 if (hasSelection()) {
660 updateLocal(bv, SELECTION, false);
663 no_selection = false;
665 int const ocell = actcell;
666 int const orow = actrow;
671 updateLocal(bv, NONE, false);
672 sel_cell_start = sel_cell_end = actcell;
674 if ((ocell != actcell) && the_locking_inset) {
675 the_locking_inset->insetUnlock(bv);
676 the_locking_inset = 0;
682 bool const inset_hit = insetHit(bv, x, y);
684 if ((ocell == actcell) && the_locking_inset && inset_hit) {
686 the_locking_inset->insetButtonPress(bv,
687 x - inset_x, y - inset_y,
690 } else if (the_locking_inset) {
691 the_locking_inset->insetUnlock(bv);
693 the_locking_inset = 0;
695 localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
698 if (inset_hit && bv->theLockingInset()) {
699 if (activateCellInsetAbs(bv, x, y, button))
700 the_locking_inset->insetButtonPress(bv,
710 void InsetTabular::insetButtonRelease(BufferView * bv,
711 int x, int y, int button)
714 if (the_locking_inset) {
716 if ((i = the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE))) {
717 i->insetButtonRelease(bv, x, y, button);
721 bv->owner()->getDialogs()->showTabular(this);
724 if (the_locking_inset) {
725 the_locking_inset->insetButtonRelease(bv,
726 x - inset_x, y - inset_y,
730 no_selection = false;
734 void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
736 if (the_locking_inset) {
737 the_locking_inset->insetMotionNotify(bv,
745 int const old_cell = actcell;
748 sel_cell_end = actcell;
749 if (sel_cell_end != old_cell)
750 updateLocal(bv, SELECTION, false);
753 no_selection = false;
757 void InsetTabular::insetKeyPress(XKeyEvent * xke)
759 if (the_locking_inset) {
760 the_locking_inset->insetKeyPress(xke);
766 UpdatableInset::RESULT
767 InsetTabular::localDispatch(BufferView * bv,
771 // We need to save the value of the_locking_inset as the call to
772 // the_locking_inset->LocalDispatch might unlock it.
773 old_locking_inset = the_locking_inset;
774 no_selection = false;
775 UpdatableInset::RESULT result =
776 UpdatableInset::localDispatch(bv, action, arg);
777 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
782 if ((action < 0) && arg.empty())
785 bool hs = hasSelection();
788 // this one have priority over the locked InsetText!
793 if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) != this)
796 if (the_locking_inset) {
797 unlockInsetInInset(bv, the_locking_inset);
798 the_locking_inset = 0;
800 if (action == LFUN_TAB)
801 moveNextCell(bv, old_locking_inset != 0);
803 movePrevCell(bv, old_locking_inset != 0);
804 sel_cell_start = sel_cell_end = actcell;
806 updateLocal(bv, SELECTION, false);
807 if (!the_locking_inset) {
809 return DISPATCHED_NOUPDATE;
813 // this to avoid compiler warnings.
818 if (the_locking_inset) {
819 result = the_locking_inset->localDispatch(bv, action, arg);
820 if (result == DISPATCHED_NOUPDATE) {
823 if (sc != scroll()) { // inset has been scrolled
824 the_locking_inset->toggleInsetCursor(bv);
825 updateLocal(bv, FULL, false);
826 the_locking_inset->toggleInsetCursor(bv);
829 } else if (result == DISPATCHED) {
830 the_locking_inset->toggleInsetCursor(bv);
831 updateLocal(bv, CELL, false);
832 the_locking_inset->toggleInsetCursor(bv);
834 } else if (result == FINISHED) {
841 // --- Cursor Movements ----------------------------------
843 if (tabular->IsLastCellInRow(actcell))
845 moveRight(bv, false);
846 sel_cell_end = actcell;
847 updateLocal(bv, SELECTION, false);
850 result = moveRight(bv);
851 sel_cell_start = sel_cell_end = actcell;
853 updateLocal(bv, SELECTION, false);
856 if (tabular->IsFirstCellInRow(actcell))
859 sel_cell_end = actcell;
860 updateLocal(bv, SELECTION, false);
863 result = moveLeft(bv);
864 sel_cell_start = sel_cell_end = actcell;
866 updateLocal(bv, SELECTION, false);
870 int const ocell = actcell;
872 if ((ocell == sel_cell_end) ||
873 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
874 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
876 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
877 updateLocal(bv, SELECTION, false);
881 result = moveDown(bv, old_locking_inset != 0);
882 sel_cell_start = sel_cell_end = actcell;
884 updateLocal(bv, SELECTION, false);
888 int const ocell = actcell;
890 if ((ocell == sel_cell_end) ||
891 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
892 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
894 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
895 updateLocal(bv, SELECTION, false);
899 result = moveUp(bv, old_locking_inset != 0);
900 sel_cell_start = sel_cell_end = actcell;
902 updateLocal(bv, SELECTION, false);
906 if (the_locking_inset) {
907 unlockInsetInInset(bv, the_locking_inset);
908 the_locking_inset = 0;
910 if (bv->text->first + bv->painter().paperHeight() <
911 (top_baseline + tabular->GetHeightOfTabular()))
913 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
914 updateLocal(bv, FULL, false);
915 actcell = tabular->GetCellBelow(first_visible_cell) + column;
917 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
920 updateLocal(bv, CURSOR, false);
925 if (the_locking_inset) {
926 unlockInsetInInset(bv, the_locking_inset);
927 the_locking_inset = 0;
929 if (top_baseline < 0) {
930 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
931 updateLocal(bv, FULL, false);
932 if (top_baseline > 0)
935 actcell = tabular->GetCellBelow(first_visible_cell) + column;
940 updateLocal(bv, CURSOR, false);
951 case LFUN_LAYOUT_TABULAR:
953 bv->owner()->getDialogs()->showTabular(this);
956 case LFUN_TABULAR_FEATURE:
957 if (!tabularFeatures(bv, arg))
958 result = UNDISPATCHED;
961 if (!copySelection(bv))
963 bv->text->setUndo(bv->buffer(), Undo::DELETE,
964 bv->text->cursor.par()->previous(),
965 bv->text->cursor.par()->next());
967 updateLocal(bv, INIT, true);
972 bv->text->finishUndo();
975 case LFUN_PASTESELECTION:
977 string const clip(bv->getClipboard());
981 if (clip.find('\t') != string::npos) {
985 unsigned int len = clip.length();
986 string::size_type p = 0;
989 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
997 maxCols = max(cols, maxCols);
1003 maxCols = max(cols, maxCols);
1004 delete paste_tabular;
1005 paste_tabular = new LyXTabular(this, rows, maxCols);
1006 string::size_type op = 0;
1008 int cells = paste_tabular->GetNumberOfCells();
1010 while((cell < cells) && (p < len) &&
1011 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1016 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1021 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, p-op));
1022 while(cols++ < maxCols)
1030 // check for the last cell if there is no trailing '\n'
1031 if ((cell < cells) && (op < len))
1032 paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
1034 // so that the clipboard is used and it goes on
1036 // and executes LFUN_PASTESELECTION in insettext!
1037 delete paste_tabular;
1042 if (hasPasteBuffer()) {
1043 bv->text->setUndo(bv->buffer(), Undo::INSERT,
1044 bv->text->cursor.par()->previous(),
1045 bv->text->cursor.par()->next());
1047 updateLocal(bv, INIT, true);
1050 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1052 // we try to activate the actual inset and put this event down to
1053 // the insets dispatch function.
1054 result = UNDISPATCHED;
1055 if (the_locking_inset)
1058 if (activateCellInset(bv)) {
1059 // reset need_update setted in above function!
1061 result = the_locking_inset->localDispatch(bv, action, arg);
1062 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1063 unlockInsetInInset(bv, the_locking_inset);
1065 the_locking_inset = 0;
1066 // we need to update if this was requested before
1067 updateLocal(bv, NONE, false);
1068 return UNDISPATCHED;
1071 // the_locking_inset->ToggleInsetCursor(bv);
1072 updateLocal(bv, CELL, false);
1073 // the_locking_inset->ToggleInsetCursor(bv);
1078 if (result!=FINISHED) {
1079 if (!the_locking_inset) {
1080 showInsetCursor(bv);
1083 bv->unlockInset(this);
1088 int InsetTabular::latex(Buffer const * buf, ostream & os,
1089 bool fragile, bool fp) const
1091 return tabular->Latex(buf, os, fragile, fp);
1095 int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
1097 // This should be changed to a real ascii export
1098 return tabular->Ascii(buf, os);
1102 int InsetTabular::linuxdoc(Buffer const *, ostream &) const
1108 int InsetTabular::docBook(Buffer const * buf, ostream & os) const
1110 return tabular->DocBook(buf,os);
1114 void InsetTabular::validate(LaTeXFeatures & features) const
1116 tabular->Validate(features);
1120 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1121 LyXFont const & font,
1128 bool changed = false;
1130 // if we have a locking_inset we should have to check only this cell for
1131 // change so I'll try this to have a boost, but who knows ;)
1132 if ((need_update != INIT) &&
1133 (the_locking_inset == tabular->GetCellInset(actcell))) {
1134 for(int i = 0; i < tabular->columns(); ++i) {
1135 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1137 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1140 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1141 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1142 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1148 for (int i = 0; i < tabular->rows(); ++i) {
1151 for (int j = 0; j < tabular->columns(); ++j) {
1152 if (tabular->IsPartOfMultiColumn(i,j))
1155 inset = tabular->GetCellInset(cell);
1157 inset->update(bv, font, false);
1158 maxAsc = max(maxAsc, inset->ascent(bv, font));
1159 maxDesc = max(maxDesc, inset->descent(bv, font));
1160 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1162 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1163 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1169 void InsetTabular::getCursorPos(BufferView *,
1170 int & x, int & y) const
1172 x = cursor.x() - top_x;
1177 void InsetTabular::toggleInsetCursor(BufferView * bv)
1179 if (the_locking_inset) {
1180 the_locking_inset->toggleInsetCursor(bv);
1184 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1186 int const asc = lyxfont::maxAscent(font);
1187 int const desc = lyxfont::maxDescent(font);
1189 if (isCursorVisible())
1190 bv->hideLockedInsetCursor();
1192 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1193 toggleCursorVisible();
1197 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
1199 if (!isCursorVisible()) {
1200 LyXFont font; // = GetFont(par, cursor.pos);
1202 int const asc = lyxfont::maxAscent(font);
1203 int const desc = lyxfont::maxDescent(font);
1204 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1206 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1207 setCursorVisible(true);
1212 void InsetTabular::hideInsetCursor(BufferView * bv)
1214 if (isCursorVisible()) {
1215 bv->hideLockedInsetCursor();
1216 setCursorVisible(false);
1218 // if (cursor_visible)
1219 // ToggleInsetCursor(bv);
1223 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1227 actcell = actrow = actcol = 0;
1228 int ly = tabular->GetDescentOfRow(actrow);
1230 // first search the right row
1231 while((ly < y) && (actrow < tabular->rows())) {
1232 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1233 tabular->GetAscentOfRow(actrow + 1) +
1234 tabular->GetAdditionalHeight(actrow + 1));
1236 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1238 actcell = tabular->GetCellNumber(actrow, actcol);
1240 // now search the right column
1241 int lx = tabular->GetWidthOfColumn(actcell) -
1242 tabular->GetAdditionalWidth(actcell);
1244 #ifdef WITH_WARNINGS
1245 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1247 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1248 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1249 tabular->GetAdditionalWidth(actcell - 1));
1251 // Jürgen, you should check that this is correct. (Lgb)
1252 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1253 lx += tabular->GetWidthOfColumn(actcell + 1)
1254 + tabular->GetAdditionalWidth(actcell);
1258 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1263 int InsetTabular::getCellXPos(int cell) const
1267 for (; !tabular->IsFirstCellInRow(c); --c)
1269 int lx = tabular->GetWidthOfColumn(cell);
1270 for (; c < cell; ++c) {
1271 lx += tabular->GetWidthOfColumn(c);
1273 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1277 void InsetTabular::resetPos(BufferView * bv) const
1281 actcol = tabular->column_of_cell(actcell);
1286 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1287 if (tabular->IsLastCellInRow(cell)) {
1288 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1289 tabular->GetAscentOfRow(actrow + 1) +
1290 tabular->GetAdditionalHeight(actrow + 1));
1294 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1295 int new_x = getCellXPos(actcell);
1296 int old_x = cursor.x();
1299 // cursor.x(getCellXPos(actcell) + offset);
1300 if ((actcol < tabular->columns()-1) && scroll(false) &&
1301 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1304 updateLocal(bv, FULL, false);
1305 } else if (the_locking_inset &&
1306 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1308 int xx = cursor.x() - offset + bv->text->getRealCursorX(bv);
1309 if (xx > (bv->workWidth()-20)) {
1310 scroll(bv, -(xx - bv->workWidth() + 60));
1311 updateLocal(bv, FULL, false);
1312 } else if (xx < 20) {
1318 updateLocal(bv, FULL, false);
1320 } else if ((cursor.x() - offset) > 20 &&
1321 (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
1322 > (bv->workWidth() - 20)) {
1323 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1324 updateLocal(bv, FULL, false);
1325 } else if ((cursor.x() - offset) < 20) {
1326 scroll(bv, 20 - cursor.x() + offset);
1327 updateLocal(bv, FULL, false);
1328 } else if (scroll(false) && top_x > 20 &&
1329 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1330 scroll(bv, old_x - cursor.x());
1331 updateLocal(bv, FULL, false);
1333 if ((!the_locking_inset ||
1334 !the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE)) &&
1335 actcell != oldcell) {
1336 InsetTabular * inset = const_cast<InsetTabular *>(this);
1337 bv->owner()->getDialogs()->updateTabular(inset);
1343 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1345 if (lock && !old_locking_inset) {
1346 if (activateCellInset(bv))
1349 bool moved = isRightToLeft(bv)
1350 ? movePrevCell(bv) : moveNextCell(bv);
1353 if (lock && activateCellInset(bv))
1357 return DISPATCHED_NOUPDATE;
1361 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1363 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1366 if (lock) { // behind the inset
1367 if (activateCellInset(bv, 0, 0, 0, true))
1371 return DISPATCHED_NOUPDATE;
1375 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1377 int const ocell = actcell;
1378 actcell = tabular->GetCellAbove(actcell);
1379 if (actcell == ocell) // we moved out of the inset
1385 if (old_locking_inset) {
1386 old_locking_inset->getCursorPos(bv, x, y);
1387 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1389 if (activateCellInset(bv, x, 0))
1392 return DISPATCHED_NOUPDATE;
1396 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1398 int const ocell = actcell;
1399 actcell = tabular->GetCellBelow(actcell);
1400 if (actcell == ocell) // we moved out of the inset
1406 if (old_locking_inset) {
1407 old_locking_inset->getCursorPos(bv, x, y);
1408 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1410 if (activateCellInset(bv, x, 0))
1413 return DISPATCHED_NOUPDATE;
1417 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1419 if (isRightToLeft(bv)) {
1420 if (tabular->IsFirstCellInRow(actcell)) {
1421 int row = tabular->row_of_cell(actcell);
1422 if (row == tabular->rows() - 1)
1424 actcell = tabular->GetLastCellInRow(row);
1425 actcell = tabular->GetCellBelow(actcell);
1432 if (tabular->IsLastCell(actcell))
1437 bool rtl = tabular->GetCellInset(actcell)->par->
1438 isRightToLeftPar(bv->buffer()->params);
1439 activateCellInset(bv, 0, 0, 0, !rtl);
1446 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1448 if (isRightToLeft(bv)) {
1449 if (tabular->IsLastCellInRow(actcell)) {
1450 int row = tabular->row_of_cell(actcell);
1453 actcell = tabular->GetFirstCellInRow(row);
1454 actcell = tabular->GetCellAbove(actcell);
1456 if (tabular->IsLastCell(actcell))
1461 if (!actcell) // first cell
1466 bool rtl = tabular->GetCellInset(actcell)->par->
1467 isRightToLeftPar(bv->buffer()->params);
1468 activateCellInset(bv, 0, 0, 0, !rtl);
1475 bool InsetTabular::Delete()
1477 #warning Is this func correctly named? Or should it be "deletable"?
1482 void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
1487 sel_cell_end = tabular->GetNumberOfCells() - 1;
1489 if (hasSelection()) {
1491 bv->text->setUndo(bv->buffer(), Undo::EDIT,
1492 bv->text->cursor.par()->previous(),
1493 bv->text->cursor.par()->next());
1494 frozen = bv->text->undo_frozen;
1496 bv->text->freezeUndo();
1497 // apply the fontchange on the whole selection
1502 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1503 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1504 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1505 tabular->GetCellInset(i, j)->setFont(bv, font, tall, true);
1509 bv->text->unFreezeUndo();
1510 updateLocal(bv, INIT, true);
1512 if (the_locking_inset)
1513 the_locking_inset->setFont(bv, font, tall);
1517 bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
1519 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1522 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1523 string const tmp = tabularFeature[i].feature;
1525 if (tmp == what.substr(0, tmp.length())) {
1526 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1527 //tabularFeatures[i].feature.length())) {
1528 action = tabularFeature[i].action;
1532 if (action == LyXTabular::LAST_ACTION)
1536 frontStrip(what.substr(tabularFeature[i].feature.length()));
1537 tabularFeatures(bv, action, val);
1542 void InsetTabular::tabularFeatures(BufferView * bv,
1543 LyXTabular::Feature feature,
1544 string const & value)
1550 bool setLines = false;
1551 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1552 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1555 case LyXTabular::M_ALIGN_LEFT:
1556 case LyXTabular::ALIGN_LEFT:
1557 setAlign=LYX_ALIGN_LEFT;
1559 case LyXTabular::M_ALIGN_RIGHT:
1560 case LyXTabular::ALIGN_RIGHT:
1561 setAlign=LYX_ALIGN_RIGHT;
1563 case LyXTabular::M_ALIGN_CENTER:
1564 case LyXTabular::ALIGN_CENTER:
1565 setAlign=LYX_ALIGN_CENTER;
1567 case LyXTabular::M_VALIGN_TOP:
1568 case LyXTabular::VALIGN_TOP:
1569 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1571 case LyXTabular::M_VALIGN_BOTTOM:
1572 case LyXTabular::VALIGN_BOTTOM:
1573 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1575 case LyXTabular::M_VALIGN_CENTER:
1576 case LyXTabular::VALIGN_CENTER:
1577 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1582 if (hasSelection()) {
1583 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1585 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1586 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1588 bv->text->setUndo(bv->buffer(), Undo::FINISH,
1589 bv->text->cursor.par()->previous(),
1590 bv->text->cursor.par()->next());
1592 int row = tabular->row_of_cell(actcell);
1593 int column = tabular->column_of_cell(actcell);
1597 case LyXTabular::SET_PWIDTH:
1599 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1600 tabular->SetColumnPWidth(actcell,value);
1602 for (int i = 0; i < tabular->rows(); ++i) {
1603 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1606 updateLocal(bv, INIT, true);
1610 case LyXTabular::SET_MPWIDTH:
1612 bool const update = (tabular->GetPWidth(actcell) != value);
1613 tabular->SetMColumnPWidth(actcell,value);
1615 for (int i = 0; i < tabular->rows(); ++i) {
1616 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1619 updateLocal(bv, INIT, true);
1623 case LyXTabular::SET_SPECIAL_COLUMN:
1624 case LyXTabular::SET_SPECIAL_MULTI:
1625 tabular->SetAlignSpecial(actcell,value,feature);
1627 case LyXTabular::APPEND_ROW:
1628 // append the row into the tabular
1629 unlockInsetInInset(bv, the_locking_inset);
1630 tabular->AppendRow(actcell);
1631 updateLocal(bv, INIT, true);
1633 case LyXTabular::APPEND_COLUMN:
1634 // append the column into the tabular
1635 unlockInsetInInset(bv, the_locking_inset);
1636 tabular->AppendColumn(actcell);
1637 actcell = tabular->GetCellNumber(row, column);
1638 updateLocal(bv, INIT, true);
1640 case LyXTabular::DELETE_ROW:
1641 unlockInsetInInset(bv, the_locking_inset);
1642 tabular->DeleteRow(tabular->row_of_cell(actcell));
1643 if ((row+1) > tabular->rows())
1645 actcell = tabular->GetCellNumber(row, column);
1647 updateLocal(bv, INIT, true);
1649 case LyXTabular::DELETE_COLUMN:
1650 unlockInsetInInset(bv, the_locking_inset);
1651 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1652 if ((column+1) > tabular->columns())
1654 actcell = tabular->GetCellNumber(row, column);
1656 updateLocal(bv, INIT, true);
1658 case LyXTabular::M_TOGGLE_LINE_TOP:
1660 case LyXTabular::TOGGLE_LINE_TOP:
1662 bool lineSet = !tabular->TopLine(actcell, flag);
1663 for (int i = sel_row_start; i <= sel_row_end; ++i)
1664 for (int j = sel_col_start; j <= sel_col_end; ++j)
1665 tabular->SetTopLine(
1666 tabular->GetCellNumber(i, j),
1668 updateLocal(bv, INIT, true);
1672 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1674 case LyXTabular::TOGGLE_LINE_BOTTOM:
1676 bool lineSet = !tabular->BottomLine(actcell, flag);
1677 for (int i = sel_row_start; i <= sel_row_end; ++i)
1678 for (int j = sel_col_start; j <= sel_col_end; ++j)
1679 tabular->SetBottomLine(
1680 tabular->GetCellNumber(i, j),
1683 updateLocal(bv, INIT, true);
1687 case LyXTabular::M_TOGGLE_LINE_LEFT:
1689 case LyXTabular::TOGGLE_LINE_LEFT:
1691 bool lineSet = !tabular->LeftLine(actcell, flag);
1692 for (int i = sel_row_start; i <= sel_row_end; ++i)
1693 for (int j = sel_col_start; j <= sel_col_end; ++j)
1694 tabular->SetLeftLine(
1695 tabular->GetCellNumber(i,j),
1698 updateLocal(bv, INIT, true);
1702 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1704 case LyXTabular::TOGGLE_LINE_RIGHT:
1706 bool lineSet = !tabular->RightLine(actcell, flag);
1707 for (int i = sel_row_start; i <= sel_row_end; ++i)
1708 for (int j = sel_col_start; j <= sel_col_end; ++j)
1709 tabular->SetRightLine(
1710 tabular->GetCellNumber(i,j),
1713 updateLocal(bv, INIT, true);
1717 case LyXTabular::M_ALIGN_LEFT:
1718 case LyXTabular::M_ALIGN_RIGHT:
1719 case LyXTabular::M_ALIGN_CENTER:
1721 case LyXTabular::ALIGN_LEFT:
1722 case LyXTabular::ALIGN_RIGHT:
1723 case LyXTabular::ALIGN_CENTER:
1724 for (int i = sel_row_start; i <= sel_row_end; ++i)
1725 for (int j = sel_col_start; j <= sel_col_end; ++j)
1726 tabular->SetAlignment(
1727 tabular->GetCellNumber(i, j),
1730 updateLocal(bv, INIT, true);
1732 case LyXTabular::M_VALIGN_TOP:
1733 case LyXTabular::M_VALIGN_BOTTOM:
1734 case LyXTabular::M_VALIGN_CENTER:
1736 case LyXTabular::VALIGN_TOP:
1737 case LyXTabular::VALIGN_BOTTOM:
1738 case LyXTabular::VALIGN_CENTER:
1739 for (int i = sel_row_start; i <= sel_row_end; ++i)
1740 for (int j = sel_col_start; j <= sel_col_end; ++j)
1741 tabular->SetVAlignment(
1742 tabular->GetCellNumber(i, j),
1744 updateLocal(bv, INIT, true);
1746 case LyXTabular::MULTICOLUMN:
1748 if (sel_row_start != sel_row_end) {
1749 WriteAlert(_("Impossible Operation!"),
1750 _("Multicolumns can only be horizontally."),
1754 // just multicol for one Single Cell
1755 if (!hasSelection()) {
1756 // check wether we are completly in a multicol
1757 if (tabular->IsMultiColumn(actcell)) {
1758 tabular->UnsetMultiColumn(actcell);
1759 updateLocal(bv, INIT, true);
1761 tabular->SetMultiColumn(actcell, 1);
1762 updateLocal(bv, CELL, true);
1766 // we have a selection so this means we just add all this
1767 // cells to form a multicolumn cell
1771 if (sel_cell_start > sel_cell_end) {
1772 s_start = sel_cell_end;
1773 s_end = sel_cell_start;
1775 s_start = sel_cell_start;
1776 s_end = sel_cell_end;
1778 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1780 sel_cell_end = sel_cell_start;
1781 updateLocal(bv, INIT, true);
1784 case LyXTabular::SET_ALL_LINES:
1786 case LyXTabular::UNSET_ALL_LINES:
1787 for (int i = sel_row_start; i <= sel_row_end; ++i)
1788 for (int j = sel_col_start; j <= sel_col_end; ++j)
1789 tabular->SetAllLines(
1790 tabular->GetCellNumber(i,j), setLines);
1791 updateLocal(bv, INIT, true);
1793 case LyXTabular::SET_LONGTABULAR:
1794 tabular->SetLongTabular(true);
1795 updateLocal(bv, INIT, true); // because this toggles displayed
1797 case LyXTabular::UNSET_LONGTABULAR:
1798 tabular->SetLongTabular(false);
1799 updateLocal(bv, INIT, true); // because this toggles displayed
1801 case LyXTabular::SET_ROTATE_TABULAR:
1802 tabular->SetRotateTabular(true);
1804 case LyXTabular::UNSET_ROTATE_TABULAR:
1805 tabular->SetRotateTabular(false);
1807 case LyXTabular::SET_ROTATE_CELL:
1808 for (int i = sel_row_start; i <= sel_row_end; ++i)
1809 for (int j = sel_col_start; j<=sel_col_end; ++j)
1810 tabular->SetRotateCell(
1811 tabular->GetCellNumber(i, j),
1814 case LyXTabular::UNSET_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), false);
1820 case LyXTabular::SET_USEBOX:
1822 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1823 if (val == tabular->GetUsebox(actcell))
1824 val = LyXTabular::BOX_NONE;
1825 for (int i = sel_row_start; i <= sel_row_end; ++i)
1826 for (int j = sel_col_start; j <= sel_col_end; ++j)
1828 tabular->GetCellNumber(i, j), val);
1831 case LyXTabular::SET_LTFIRSTHEAD:
1832 tabular->SetLTHead(actcell, true);
1834 case LyXTabular::SET_LTHEAD:
1835 tabular->SetLTHead(actcell, false);
1837 case LyXTabular::SET_LTFOOT:
1838 tabular->SetLTFoot(actcell, false);
1840 case LyXTabular::SET_LTLASTFOOT:
1841 tabular->SetLTFoot(actcell, true);
1843 case LyXTabular::SET_LTNEWPAGE:
1845 bool what = !tabular->GetLTNewPage(actcell);
1846 tabular->SetLTNewPage(actcell, what);
1849 // dummy stuff just to avoid warnings
1850 case LyXTabular::LAST_ACTION:
1856 bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
1859 UpdatableInset * inset =
1860 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1861 LyXFont font(LyXFont::ALL_SANE);
1863 x = inset->x() + inset->width(bv, font);
1864 y = inset->descent(bv, font);
1866 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1867 //inset_y = cursor.y();
1868 inset->edit(bv, x, y, button);
1869 if (!the_locking_inset)
1871 updateLocal(bv, CELL, false);
1872 return (the_locking_inset != 0);
1876 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
1879 inset_x = cursor.x()
1880 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1881 inset_y = cursor.y();
1882 return activateCellInset(bv, x - inset_x, y - inset_y, button);
1886 bool InsetTabular::insetHit(BufferView *, int x, int) const
1889 > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
1893 // This returns paperWidth() if the cell-width is unlimited or the width
1894 // in pixels if we have a pwidth for this cell.
1895 int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
1897 string const s = tabular->GetPWidth(cell);
1901 return VSpace(s).inPixels(bv);
1905 int InsetTabular::getMaxWidth(BufferView * bv,
1906 UpdatableInset const * inset) const
1908 int cell = tabular->cur_cell;
1909 if (tabular->GetCellInset(cell) != inset) {
1911 if (tabular->GetCellInset(cell) != inset) {
1912 lyxerr << "Actcell not equal to actual cell!" << std::endl;
1918 int const n = tabular->GetNumberOfCells();
1922 for (; cell < n; ++cell) {
1923 if (tabular->GetCellInset(cell) == inset)
1932 int w = getMaxWidthOfCell(bv, cell);
1934 // because the inset then subtracts it's top_x and owner->x()
1935 w += (inset->x() - top_x);
1942 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
1944 resizeLyXText(bv, recursive);
1948 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
1951 for(int i = 0; i < tabular->rows(); ++i) {
1952 for(int j = 0; j < tabular->columns(); ++j) {
1953 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
1961 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1962 bool const recursive) const
1964 if (the_locking_inset)
1965 return the_locking_inset->getLyXText(bv, recursive);
1966 return Inset::getLyXText(bv, recursive);
1970 bool InsetTabular::showInsetDialog(BufferView * bv) const
1972 if (!the_locking_inset || !the_locking_inset->showInsetDialog(bv))
1973 bv->owner()->getDialogs()
1974 ->showTabular(const_cast<InsetTabular *>(this));
1979 void InsetTabular::openLayoutDialog(BufferView * bv) const
1981 if (the_locking_inset) {
1982 InsetTabular * i = static_cast<InsetTabular *>
1983 (the_locking_inset->getFirstLockingInsetOfType(TABULAR_CODE));
1985 i->openLayoutDialog(bv);
1989 bv->owner()->getDialogs()->showTabular(
1990 const_cast<InsetTabular *>(this));
1994 // functions returns:
1998 // 3 ... toggled off
2000 func_status::value_type InsetTabular::getStatus(string const & what) const
2002 int action = LyXTabular::LAST_ACTION;
2003 func_status::value_type status = func_status::OK;
2006 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
2007 string const tmp = tabularFeature[i].feature;
2008 if (tmp == what.substr(0, tmp.length())) {
2009 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2010 // tabularFeatures[i].feature.length())) {
2011 action = tabularFeature[i].action;
2015 if (action == LyXTabular::LAST_ACTION)
2016 return func_status::Unknown;
2018 string const argument = frontStrip(what.substr(tabularFeature[i].feature.length()));
2025 if (hasSelection()) {
2026 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2028 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2032 case LyXTabular::SET_PWIDTH:
2033 case LyXTabular::SET_MPWIDTH:
2034 case LyXTabular::SET_SPECIAL_COLUMN:
2035 case LyXTabular::SET_SPECIAL_MULTI:
2036 status |= func_status::Disabled;
2039 case LyXTabular::APPEND_ROW:
2040 case LyXTabular::APPEND_COLUMN:
2041 case LyXTabular::DELETE_ROW:
2042 case LyXTabular::DELETE_COLUMN:
2043 case LyXTabular::SET_ALL_LINES:
2044 case LyXTabular::UNSET_ALL_LINES:
2045 status |= func_status::OK;
2048 case LyXTabular::MULTICOLUMN:
2049 if (tabular->IsMultiColumn(actcell))
2050 status |= func_status::ToggleOn;
2052 status |= func_status::ToggleOff;
2054 case LyXTabular::M_TOGGLE_LINE_TOP:
2056 case LyXTabular::TOGGLE_LINE_TOP:
2057 if (tabular->TopLine(actcell, flag))
2058 status |= func_status::ToggleOn;
2060 status |= func_status::ToggleOff;
2062 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2064 case LyXTabular::TOGGLE_LINE_BOTTOM:
2065 if (tabular->BottomLine(actcell, flag))
2066 status |= func_status::ToggleOn;
2068 status |= func_status::ToggleOff;
2070 case LyXTabular::M_TOGGLE_LINE_LEFT:
2072 case LyXTabular::TOGGLE_LINE_LEFT:
2073 if (tabular->LeftLine(actcell, flag))
2074 status |= func_status::ToggleOn;
2076 status |= func_status::ToggleOff;
2078 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2080 case LyXTabular::TOGGLE_LINE_RIGHT:
2081 if (tabular->RightLine(actcell, flag))
2082 status |= func_status::ToggleOn;
2084 status |= func_status::ToggleOff;
2086 case LyXTabular::M_ALIGN_LEFT:
2088 case LyXTabular::ALIGN_LEFT:
2089 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2090 status |= func_status::ToggleOn;
2092 status |= func_status::ToggleOff;
2094 case LyXTabular::M_ALIGN_RIGHT:
2096 case LyXTabular::ALIGN_RIGHT:
2097 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2098 status |= func_status::ToggleOn;
2100 status |= func_status::ToggleOff;
2102 case LyXTabular::M_ALIGN_CENTER:
2104 case LyXTabular::ALIGN_CENTER:
2105 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2106 status |= func_status::ToggleOn;
2108 status |= func_status::ToggleOff;
2110 case LyXTabular::M_VALIGN_TOP:
2112 case LyXTabular::VALIGN_TOP:
2113 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2114 status |= func_status::ToggleOn;
2116 status |= func_status::ToggleOff;
2118 case LyXTabular::M_VALIGN_BOTTOM:
2120 case LyXTabular::VALIGN_BOTTOM:
2121 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2122 status |= func_status::ToggleOn;
2124 status |= func_status::ToggleOff;
2126 case LyXTabular::M_VALIGN_CENTER:
2128 case LyXTabular::VALIGN_CENTER:
2129 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2130 status |= func_status::ToggleOn;
2132 status |= func_status::ToggleOff;
2134 case LyXTabular::SET_LONGTABULAR:
2135 if (tabular->IsLongTabular())
2136 status |= func_status::ToggleOn;
2138 status |= func_status::ToggleOff;
2140 case LyXTabular::UNSET_LONGTABULAR:
2141 if (!tabular->IsLongTabular())
2142 status |= func_status::ToggleOn;
2144 status |= func_status::ToggleOff;
2146 case LyXTabular::SET_ROTATE_TABULAR:
2147 if (tabular->GetRotateTabular())
2148 status |= func_status::ToggleOn;
2150 status |= func_status::ToggleOff;
2152 case LyXTabular::UNSET_ROTATE_TABULAR:
2153 if (!tabular->GetRotateTabular())
2154 status |= func_status::ToggleOn;
2156 status |= func_status::ToggleOff;
2158 case LyXTabular::SET_ROTATE_CELL:
2159 if (tabular->GetRotateCell(actcell))
2160 status |= func_status::ToggleOn;
2162 status |= func_status::ToggleOff;
2164 case LyXTabular::UNSET_ROTATE_CELL:
2165 if (!tabular->GetRotateCell(actcell))
2166 status |= func_status::ToggleOn;
2168 status |= func_status::ToggleOff;
2170 case LyXTabular::SET_USEBOX:
2171 if (strToInt(argument) == tabular->GetUsebox(actcell))
2172 status |= func_status::ToggleOn;
2174 status |= func_status::ToggleOff;
2176 case LyXTabular::SET_LTFIRSTHEAD:
2177 if (tabular->GetRowOfLTHead(actcell, dummy))
2178 status |= func_status::ToggleOn;
2180 status |= func_status::ToggleOff;
2182 case LyXTabular::SET_LTHEAD:
2183 if (tabular->GetRowOfLTHead(actcell, dummy))
2184 status |= func_status::ToggleOn;
2186 status |= func_status::ToggleOff;
2188 case LyXTabular::SET_LTFOOT:
2189 if (tabular->GetRowOfLTFoot(actcell, dummy))
2190 status |= func_status::ToggleOn;
2192 status |= func_status::ToggleOff;
2194 case LyXTabular::SET_LTLASTFOOT:
2195 if (tabular->GetRowOfLTFoot(actcell, dummy))
2196 status |= func_status::ToggleOn;
2198 status |= func_status::ToggleOff;
2200 case LyXTabular::SET_LTNEWPAGE:
2201 if (tabular->GetLTNewPage(actcell))
2202 status |= func_status::ToggleOn;
2204 status |= func_status::ToggleOff;
2207 status = func_status::Disabled;
2214 std::vector<string> const InsetTabular::getLabelList() const
2216 return tabular->getLabelList();
2220 bool InsetTabular::copySelection(BufferView * bv)
2222 if (!hasSelection())
2225 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2226 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2227 if (sel_col_start > sel_col_end) {
2228 sel_col_start = sel_col_end;
2229 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2231 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2233 int const columns = sel_col_end - sel_col_start + 1;
2235 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2236 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2237 if (sel_row_start > sel_row_end) {
2238 swap(sel_row_start, sel_row_end);
2240 int const rows = sel_row_end - sel_row_start + 1;
2242 delete paste_tabular;
2243 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2244 for (int i = 0; i < sel_row_start; ++i)
2245 paste_tabular->DeleteRow(0);
2246 while(paste_tabular->rows() > rows)
2247 paste_tabular->DeleteRow(rows);
2248 paste_tabular->SetTopLine(0, true, true);
2249 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2251 for (int i = 0; i < sel_col_start; ++i)
2252 paste_tabular->DeleteColumn(0);
2253 while (paste_tabular->columns() > columns)
2254 paste_tabular->DeleteColumn(columns);
2255 paste_tabular->SetLeftLine(0, true, true);
2256 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2260 paste_tabular->Ascii(bv->buffer(), sstr);
2261 bv->stuffClipboard(sstr.str().c_str());
2266 bool InsetTabular::pasteSelection(BufferView * bv)
2271 for (int r1 = 0, r2 = actrow;
2272 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2274 for(int c1 = 0, c2 = actcol;
2275 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2277 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2278 tabular->IsPartOfMultiColumn(r2,c2))
2280 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2284 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2288 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2289 int const n2 = tabular->GetCellNumber(r2, c2);
2290 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2291 tabular->GetCellInset(n2)->setOwner(this);
2292 tabular->GetCellInset(n2)->deleteLyXText(bv);
2299 bool InsetTabular::cutSelection()
2301 if (!hasSelection())
2304 //int sel_col_start;
2306 //int sel_row_start;
2309 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2310 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2311 if (sel_col_start > sel_col_end) {
2312 sel_col_start = sel_col_end;
2313 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2315 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2317 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2318 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2319 if (sel_row_start > sel_row_end) {
2320 //int tmp = sel_row_start;
2321 //sel_row_start = sel_row_end;
2322 //sel_row_end = tmp;
2323 swap(sel_row_start, sel_row_end);
2325 if (sel_cell_start > sel_cell_end) {
2326 //int tmp = sel_cell_start;
2327 //sel_cell_start = sel_cell_end;
2328 //sel_cell_end = tmp;
2329 swap(sel_cell_start, sel_cell_end);
2331 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2332 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2333 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2340 bool InsetTabular::isRightToLeft(BufferView *bv )
2342 return bv->getParentLanguage(this)->RightToLeft();
2346 bool InsetTabular::nodraw() const
2348 if (!UpdatableInset::nodraw() && the_locking_inset)
2349 return the_locking_inset->nodraw();
2350 return UpdatableInset::nodraw();
2354 int InsetTabular::scroll(bool recursive) const
2356 int sx = UpdatableInset::scroll(false);
2358 if (recursive && the_locking_inset)
2359 sx += the_locking_inset->scroll(recursive);
2365 bool InsetTabular::doClearArea() const
2367 return !locked || (need_update & (FULL|INIT));
2371 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2373 srow = tabular->row_of_cell(sel_cell_start);
2374 erow = tabular->row_of_cell(sel_cell_end);
2378 scol = tabular->column_of_cell(sel_cell_start);
2379 ecol = tabular->column_of_cell(sel_cell_end);
2383 ecol = tabular->right_column_of_cell(sel_cell_end);