1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
19 #pragma implementation
22 #include "insettabular.h"
25 #include "commandtags.h"
27 #include "LaTeXFeatures.h"
31 #include "lyx_gui_misc.h"
33 #include "insets/insettext.h"
34 #include "frontends/Dialogs.h"
50 const int ADD_TO_HEIGHT = 2;
51 const int ADD_TO_TABULAR_WIDTH = 2;
53 LyXTabular * paste_tabular = 0;
56 struct tabular_features {
57 LyXTabular::Feature action;
61 //tabular_features * tabularFeatures = 0;
63 tabular_features tabularFeatures[] =
65 { LyXTabular::APPEND_ROW, "append-row" },
66 { LyXTabular::APPEND_COLUMN, "append-column" },
67 { LyXTabular::DELETE_ROW, "delete-row" },
68 { LyXTabular::DELETE_COLUMN, "delete-column" },
69 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
70 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
71 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
72 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
73 { LyXTabular::ALIGN_LEFT, "align-left" },
74 { LyXTabular::ALIGN_RIGHT, "align-right" },
75 { LyXTabular::ALIGN_CENTER, "align-center" },
76 { LyXTabular::VALIGN_TOP, "valign-top" },
77 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
78 { LyXTabular::VALIGN_CENTER, "valign-center" },
79 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
80 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
81 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
82 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
83 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
84 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
85 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
86 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
87 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
88 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
89 { LyXTabular::MULTICOLUMN, "multicolumn" },
90 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
91 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
92 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
93 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
94 { LyXTabular::SET_PWIDTH, "set-pwidth" },
95 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
96 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
97 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
98 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
99 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
100 { LyXTabular::SET_USEBOX, "set-usebox" },
101 { LyXTabular::SET_LTHEAD, "set-lthead" },
102 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
103 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
104 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
105 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
106 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
107 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
108 { LyXTabular::LAST_ACTION, "" }
114 bool InsetTabular::hasPasteBuffer() const
116 return (paste_tabular != 0);
120 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
127 tabular.reset(new LyXTabular(this, rows,columns));
128 // for now make it always display as display() inset
130 the_locking_inset = 0;
131 locked = no_selection = false;
133 actrow = actcell = 0;
139 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
142 tabular.reset(new LyXTabular(this, *(tab.tabular)));
143 the_locking_inset = 0;
144 locked = no_selection = false;
146 actrow = actcell = 0;
147 sel_cell_start = sel_cell_end = 0;
152 InsetTabular::~InsetTabular()
159 Inset * InsetTabular::Clone(Buffer const & buf) const
161 InsetTabular * t = new InsetTabular(*this, buf);
163 //t->tabular = tabular->Clone(t);
164 t->tabular.reset(tabular->Clone(t));
169 void InsetTabular::Write(Buffer const * buf, ostream & os) const
171 os << " Tabular" << endl;
172 tabular->Write(buf, os);
176 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
178 bool const old_format = (lex.GetString() == "\\LyXTable");
182 //tabular = new LyXTabular(buf, this, lex);
183 tabular.reset(new LyXTabular(buf, this, lex));
191 string token = lex.GetString();
192 while (lex.IsOK() && (token != "\\end_inset")) {
194 token = lex.GetString();
196 if (token != "\\end_inset") {
197 lex.printError("Missing \\end_inset at this point. "
203 int InsetTabular::ascent(BufferView *, LyXFont const &) const
205 return tabular->GetAscentOfRow(0);
209 int InsetTabular::descent(BufferView *, LyXFont const &) const
211 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
215 int InsetTabular::width(BufferView *, LyXFont const &) const
217 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
221 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
222 float & x, bool cleared) const
226 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
229 // lyxerr << "InsetTabular::draw(" << need_update << ")\n";
231 Painter & pain = bv->painter();
237 UpdatableInset::draw(bv, font, baseline, x, cleared);
240 x += static_cast<float>(scroll());
242 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
243 (top_x != int(x)) || (top_baseline != baseline))) {
244 int h = ascent(bv, font) + descent(bv, font);
245 int const tx = display() || !owner() ? 0 : top_x;
246 int w = tx ? width(bv, font) : pain.paperWidth();
247 int ty = baseline - ascent(bv, font);
251 if ((ty + h) > pain.paperHeight())
252 h = pain.paperHeight();
253 if ((top_x + w) > pain.paperWidth())
254 w = pain.paperWidth();
255 pain.fillRectangle(tx, ty, w, h);
260 top_baseline = baseline;
261 x += ADD_TO_TABULAR_WIDTH;
265 first_visible_cell = -1;
266 for (i = 0; i < tabular->rows(); ++i) {
268 cell = tabular->GetCellNumber(i, 0);
269 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
270 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
272 baseline += tabular->GetDescentOfRow(i) +
273 tabular->GetAscentOfRow(i + 1) +
274 tabular->GetAdditionalHeight(i + 1);
277 for (j = 0; j < tabular->columns(); ++j) {
278 if (nx > bv->workWidth())
280 if (tabular->IsPartOfMultiColumn(i, j))
282 cx = nx + tabular->GetBeginningOfTextInCell(cell);
283 if (first_visible_cell < 0)
284 first_visible_cell = cell;
286 DrawCellSelection(pain, nx, baseline, i, j, cell);
287 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
289 DrawCellLines(pain, nx, baseline, i, cell);
290 nx += tabular->GetWidthOfColumn(cell);
293 baseline += tabular->GetDescentOfRow(i) +
294 tabular->GetAscentOfRow(i + 1) +
295 tabular->GetAdditionalHeight(i + 1);
297 } else if (need_update == CELL) {
300 if (the_locking_inset &&
301 tabular->GetCellInset(actcell) != the_locking_inset)
303 Inset * inset = tabular->GetCellInset(cell);
305 inset != the_locking_inset && i < tabular->rows();
308 inset != the_locking_inset
309 && j < tabular->columns();
311 if (tabular->IsPartOfMultiColumn(i, j))
313 nx += tabular->GetWidthOfColumn(cell);
315 inset = tabular->GetCellInset(cell);
317 if (tabular->row_of_cell(cell) > i) {
319 baseline += tabular->GetDescentOfRow(i) +
320 tabular->GetAscentOfRow(i + 1) +
321 tabular->GetAdditionalHeight(i + 1);
325 // copute baseline for actual row
326 for (i = 0; i < actrow; ++i) {
327 baseline += tabular->GetDescentOfRow(i) +
328 tabular->GetAscentOfRow(i + 1) +
329 tabular->GetAdditionalHeight(i + 1);
331 // now compute the right x position
332 cell = tabular->GetCellNumber(actrow, 0);
333 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
334 if (tabular->IsPartOfMultiColumn(actrow, j))
336 nx += tabular->GetWidthOfColumn(cell);
340 i = tabular->row_of_cell(cell);
341 if (the_locking_inset != tabular->GetCellInset(cell)) {
342 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
345 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
347 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
348 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
349 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
351 // clear only if we didn't have a change
352 if (need_update == CELL) {
353 // clear before the inset
356 baseline - tabular->GetAscentOfRow(i) + 1,
358 tabular->GetAscentOfRow(i) +
359 tabular->GetDescentOfRow(i) - 1);
360 // clear behind the inset
362 int(cx + the_locking_inset->width(bv,font) + 1),
363 baseline - tabular->GetAscentOfRow(i) + 1,
364 tabular->GetWidthOfColumn(cell) -
365 tabular->GetBeginningOfTextInCell(cell) -
366 the_locking_inset->width(bv,font) -
367 tabular->GetAdditionalWidth(cell) - 1,
368 tabular->GetAscentOfRow(i) +
369 tabular->GetDescentOfRow(i) - 1);
372 x -= ADD_TO_TABULAR_WIDTH;
373 x += width(bv, font);
374 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
381 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
382 int row, int cell) const
384 int x2 = x + tabular->GetWidthOfColumn(cell);
387 if (!tabular->TopAlreadyDrawed(cell)) {
388 on_off = !tabular->TopLine(cell);
389 pain.line(x, baseline - tabular->GetAscentOfRow(row),
390 x2, baseline - tabular->GetAscentOfRow(row),
391 on_off ? LColor::tabularonoffline : LColor::tabularline,
392 on_off ? Painter::line_onoffdash : Painter::line_solid);
394 on_off = !tabular->BottomLine(cell);
395 pain.line(x,baseline + tabular->GetDescentOfRow(row),
396 x2, baseline + tabular->GetDescentOfRow(row),
397 on_off ? LColor::tabularonoffline : LColor::tabularline,
398 on_off ? Painter::line_onoffdash : Painter::line_solid);
399 if (!tabular->LeftAlreadyDrawed(cell)) {
400 on_off = !tabular->LeftLine(cell);
401 pain.line(x, baseline - tabular->GetAscentOfRow(row),
402 x, baseline + tabular->GetDescentOfRow(row),
403 on_off ? LColor::tabularonoffline : LColor::tabularline,
404 on_off ? Painter::line_onoffdash : Painter::line_solid);
406 on_off = !tabular->RightLine(cell);
407 pain.line(x2 - tabular->GetAdditionalWidth(cell),
408 baseline - tabular->GetAscentOfRow(row),
409 x2 - tabular->GetAdditionalWidth(cell),
410 baseline + tabular->GetDescentOfRow(row),
411 on_off ? LColor::tabularonoffline : LColor::tabularline,
412 on_off ? Painter::line_onoffdash : Painter::line_solid);
416 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
417 int row, int column, int cell) const
419 int cs = tabular->column_of_cell(sel_cell_start);
420 int ce = tabular->column_of_cell(sel_cell_end);
423 cs = tabular->column_of_cell(sel_cell_end);
425 ce = tabular->right_column_of_cell(sel_cell_end);
428 int rs = tabular->row_of_cell(sel_cell_start);
429 int re = tabular->row_of_cell(sel_cell_end);
430 if (rs > re) swap(rs, re);
432 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
433 int w = tabular->GetWidthOfColumn(cell);
434 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
435 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
436 w, h, LColor::selection);
441 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
445 calculate_dimensions_of_cells(bv, font, true);
447 owner()->update(bv, font, true);
450 if (the_locking_inset)
451 the_locking_inset->update(bv, font, reinit);
453 switch (need_update) {
457 if (calculate_dimensions_of_cells(bv, font, false))
469 string const InsetTabular::EditMessage() const
471 return _("Opened Tabular Inset");
475 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
477 UpdatableInset::Edit(bv, x, y, button);
479 if (!bv->lockInset(this)) {
480 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
484 the_locking_inset = 0;
488 sel_cell_start = sel_cell_end = actcell;
489 bv->text->FinishUndo();
490 if (InsetHit(bv, x, y) && (button != 3)) {
491 ActivateCellInsetAbs(bv, x, y, button);
493 // UpdateLocal(bv, NONE, false);
494 // bv->getOwner()->getPopups().updateFormTabular();
498 void InsetTabular::InsetUnlock(BufferView * bv)
500 if (the_locking_inset) {
501 the_locking_inset->InsetUnlock(bv);
502 the_locking_inset = 0;
505 no_selection = false;
508 if (scroll(false) || hasSelection()) {
509 sel_cell_start = sel_cell_end = 0;
513 UpdateLocal(bv, FULL, false);
518 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
519 bool mark_dirty) const
521 if (need_update < what) // only set this if it has greater update
523 if ((what == INIT) && hasSelection())
526 if (need_update != NONE) {
527 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
528 if (locked) // && (what != NONE))
534 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
536 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
541 if (inset == tabular->GetCellInset(actcell)) {
542 lyxerr[Debug::INSETS] << "OK" << endl;
543 the_locking_inset = tabular->GetCellInset(actcell);
545 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
546 inset_y = cursor.y();
548 } else if (the_locking_inset && (the_locking_inset == inset)) {
549 lyxerr[Debug::INSETS] << "OK" << endl;
551 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
552 inset_y = cursor.y();
553 } else if (the_locking_inset) {
554 lyxerr[Debug::INSETS] << "MAYBE" << endl;
555 return the_locking_inset->LockInsetInInset(bv, inset);
557 lyxerr[Debug::INSETS] << "NOT OK" << endl;
562 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
565 if (!the_locking_inset)
567 if (the_locking_inset == inset) {
568 the_locking_inset->InsetUnlock(bv);
569 the_locking_inset = 0;
573 UpdateLocal(bv, CELL, false);
574 ShowInsetCursor(bv, false);
577 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
578 if (inset->LyxCode() == TABULAR_CODE &&
579 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) {
580 bv->owner()->getDialogs()->updateTabular(this);
589 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
591 if (!the_locking_inset)
593 if (the_locking_inset != inset) {
594 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
597 UpdateLocal(bv, CELL, false);
602 unsigned int InsetTabular::InsetInInsetY()
604 if (!the_locking_inset)
607 return inset_y + the_locking_inset->InsetInInsetY();
611 UpdatableInset * InsetTabular::GetLockingInset()
613 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
617 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
621 if (the_locking_inset)
622 return the_locking_inset->GetFirstLockingInsetOfType(c);
627 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
629 if (the_locking_inset)
630 return the_locking_inset->InsertInset(bv, inset);
635 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
637 if (hasSelection() && (button == 3))
640 if (hasSelection()) {
642 UpdateLocal(bv, SELECTION, false);
645 no_selection = false;
647 int const ocell = actcell;
648 int const orow = actrow;
653 UpdateLocal(bv, NONE, false);
654 sel_cell_start = sel_cell_end = actcell;
656 if ((ocell != actcell) && the_locking_inset) {
657 the_locking_inset->InsetUnlock(bv);
658 the_locking_inset = 0;
664 bool const inset_hit = InsetHit(bv, x, y);
666 if ((ocell == actcell) && the_locking_inset && inset_hit) {
668 the_locking_inset->InsetButtonPress(bv,
669 x - inset_x, y - inset_y,
672 } else if (the_locking_inset) {
673 the_locking_inset->InsetUnlock(bv);
675 the_locking_inset = 0;
677 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
680 if (inset_hit && bv->theLockingInset()) {
681 if (ActivateCellInsetAbs(bv, x, y, button))
682 the_locking_inset->InsetButtonPress(bv,
692 void InsetTabular::InsetButtonRelease(BufferView * bv,
693 int x, int y, int button)
696 if (the_locking_inset) {
698 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
699 i->InsetButtonRelease(bv, x, y, button);
703 bv->owner()->getDialogs()->showTabular(this);
706 if (the_locking_inset) {
707 the_locking_inset->InsetButtonRelease(bv,
708 x - inset_x, y - inset_y,
712 no_selection = false;
716 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
718 if (the_locking_inset) {
719 the_locking_inset->InsetMotionNotify(bv,
727 int const old_cell = actcell;
730 sel_cell_end = actcell;
731 if (sel_cell_end != old_cell)
732 UpdateLocal(bv, SELECTION, false);
735 no_selection = false;
739 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
741 if (the_locking_inset) {
742 the_locking_inset->InsetKeyPress(xke);
748 UpdatableInset::RESULT
749 InsetTabular::LocalDispatch(BufferView * bv,
753 // We need to save the value of the_locking_inset as the call to
754 // the_locking_inset->LocalDispatch might unlock it.
755 old_locking_inset = the_locking_inset;
756 no_selection = false;
757 UpdatableInset::RESULT result =
758 UpdatableInset::LocalDispatch(bv, action, arg);
759 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
764 if ((action < 0) && arg.empty())
767 bool hs = hasSelection();
770 // this one have priority over the locked InsetText!
776 if (the_locking_inset) {
777 UnlockInsetInInset(bv, the_locking_inset);
778 the_locking_inset = 0;
780 if (action == LFUN_TAB)
781 moveNextCell(bv, old_locking_inset != 0);
783 movePrevCell(bv, old_locking_inset != 0);
784 sel_cell_start = sel_cell_end = actcell;
786 UpdateLocal(bv, SELECTION, false);
787 if (!the_locking_inset) {
789 return DISPATCHED_NOUPDATE;
793 // this to avoid compiler warnings.
798 if (the_locking_inset) {
799 result=the_locking_inset->LocalDispatch(bv, action, arg);
800 if (result == DISPATCHED_NOUPDATE) {
803 if (sc != scroll()) { // inset has been scrolled
804 the_locking_inset->ToggleInsetCursor(bv);
805 UpdateLocal(bv, FULL, false);
806 the_locking_inset->ToggleInsetCursor(bv);
809 } else if (result == DISPATCHED) {
810 the_locking_inset->ToggleInsetCursor(bv);
811 UpdateLocal(bv, CELL, false);
812 the_locking_inset->ToggleInsetCursor(bv);
814 } else if (result == FINISHED) {
821 // --- Cursor Movements ----------------------------------
823 if (tabular->IsLastCellInRow(actcell))
825 moveRight(bv, false);
826 sel_cell_end = actcell;
827 UpdateLocal(bv, SELECTION, false);
830 result = moveRight(bv);
831 sel_cell_start = sel_cell_end = actcell;
833 UpdateLocal(bv, SELECTION, false);
836 if (tabular->IsFirstCellInRow(actcell))
839 sel_cell_end = actcell;
840 UpdateLocal(bv, SELECTION, false);
843 result = moveLeft(bv);
844 sel_cell_start = sel_cell_end = actcell;
846 UpdateLocal(bv, SELECTION, false);
850 int const ocell = actcell;
852 if ((ocell == sel_cell_end) ||
853 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
854 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
856 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
857 UpdateLocal(bv, SELECTION, false);
861 result = moveDown(bv, old_locking_inset != 0);
862 sel_cell_start = sel_cell_end = actcell;
864 UpdateLocal(bv, SELECTION, false);
868 int const ocell = actcell;
870 if ((ocell == sel_cell_end) ||
871 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
872 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
874 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
875 UpdateLocal(bv, SELECTION, false);
879 result = moveUp(bv, old_locking_inset != 0);
880 sel_cell_start = sel_cell_end = actcell;
882 UpdateLocal(bv, SELECTION, false);
886 if (the_locking_inset) {
887 UnlockInsetInInset(bv, the_locking_inset);
888 the_locking_inset = 0;
890 if (bv->text->first + bv->painter().paperHeight() <
891 (top_baseline + tabular->GetHeightOfTabular()))
893 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
894 UpdateLocal(bv, FULL, false);
895 actcell = tabular->GetCellBelow(first_visible_cell) + column;
897 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
900 UpdateLocal(bv, CURSOR, false);
905 if (the_locking_inset) {
906 UnlockInsetInInset(bv, the_locking_inset);
907 the_locking_inset = 0;
909 if (top_baseline < 0) {
910 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
911 UpdateLocal(bv, FULL, false);
912 if (top_baseline > 0)
915 actcell = tabular->GetCellBelow(first_visible_cell) + column;
920 UpdateLocal(bv, CURSOR, false);
931 case LFUN_LAYOUT_TABULAR:
933 bv->owner()->getDialogs()->showTabular(this);
936 case LFUN_TABULAR_FEATURE:
937 if (!TabularFeatures(bv, arg))
938 result = UNDISPATCHED;
941 if (!copySelection(bv))
943 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
944 bv->text->cursor.par()->previous(),
945 bv->text->cursor.par()->next());
947 UpdateLocal(bv, INIT, true);
952 bv->text->FinishUndo();
955 case LFUN_PASTESELECTION:
957 string clip(bv->workarea()->getClipboard());
961 if (clip.find('\t') != string::npos) {
965 unsigned int len = clip.length();
966 string::size_type p = 0;
969 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
977 maxCols = max(cols, maxCols);
983 maxCols = max(cols, maxCols);
984 delete paste_tabular;
985 paste_tabular = new LyXTabular(this, rows, maxCols);
986 string::size_type op = 0;
988 int cells = paste_tabular->GetNumberOfCells();
990 while((cell < cells) && (p < len) &&
991 (p = clip.find_first_of("\t\n", p)) != string::npos) {
996 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1001 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1002 while(cols++ < maxCols)
1010 // check for the last cell if there is no trailing '\n'
1011 if ((cell < cells) && (op < len))
1012 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
1014 // so that the clipboard is used and it goes on
1016 // and executes LFUN_PASTESELECTION in insettext!
1017 delete paste_tabular;
1022 if (hasPasteBuffer()) {
1023 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1024 bv->text->cursor.par()->previous(),
1025 bv->text->cursor.par()->next());
1027 UpdateLocal(bv, INIT, true);
1030 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1032 // we try to activate the actual inset and put this event down to
1033 // the insets dispatch function.
1034 result = UNDISPATCHED;
1035 if (the_locking_inset)
1038 if (ActivateCellInset(bv)) {
1039 result = the_locking_inset->LocalDispatch(bv, action, arg);
1040 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1041 UnlockInsetInInset(bv, the_locking_inset);
1043 the_locking_inset = 0;
1044 return UNDISPATCHED;
1047 // the_locking_inset->ToggleInsetCursor(bv);
1048 UpdateLocal(bv, CELL, false);
1049 // the_locking_inset->ToggleInsetCursor(bv);
1054 if (result!=FINISHED) {
1055 if (!the_locking_inset) {
1056 ShowInsetCursor(bv);
1059 bv->unlockInset(this);
1064 int InsetTabular::Latex(Buffer const * buf, ostream & os,
1065 bool fragile, bool fp) const
1067 return tabular->Latex(buf, os, fragile, fp);
1071 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
1073 // This should be changed to a real ascii export
1074 return tabular->Ascii(buf, os);
1078 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1084 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1086 return tabular->DocBook(buf,os);
1090 void InsetTabular::Validate(LaTeXFeatures & features) const
1092 tabular->Validate(features);
1096 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1097 LyXFont const & font,
1104 bool changed = false;
1106 // if we have a locking_inset we should have to check only this cell for
1107 // change so I'll try this to have a boost, but who knows ;)
1108 if ((need_update != INIT) &&
1109 (the_locking_inset == tabular->GetCellInset(actcell))) {
1110 for(int i = 0; i < tabular->columns(); ++i) {
1111 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1113 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1116 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1117 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1118 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1121 for (int i = 0; i < tabular->rows(); ++i) {
1124 for (int j= 0; j < tabular->columns(); ++j) {
1125 if (tabular->IsPartOfMultiColumn(i,j))
1128 inset = tabular->GetCellInset(cell);
1130 inset->update(bv, font, false);
1131 maxAsc = max(maxAsc, inset->ascent(bv, font));
1132 maxDesc = max(maxDesc, inset->descent(bv, font));
1133 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1135 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1136 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1142 void InsetTabular::GetCursorPos(BufferView *,
1143 int & x, int & y) const
1145 x = cursor.x() - top_x;
1150 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1152 if (the_locking_inset) {
1153 the_locking_inset->ToggleInsetCursor(bv);
1157 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1159 int const asc = lyxfont::maxAscent(font);
1160 int const desc = lyxfont::maxDescent(font);
1162 if (isCursorVisible())
1163 bv->hideLockedInsetCursor();
1165 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1166 toggleCursorVisible();
1170 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1172 if (!isCursorVisible()) {
1173 LyXFont font; // = GetFont(par, cursor.pos);
1175 int const asc = lyxfont::maxAscent(font);
1176 int const desc = lyxfont::maxDescent(font);
1177 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1179 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1180 setCursorVisible(true);
1185 void InsetTabular::HideInsetCursor(BufferView * bv)
1187 if (isCursorVisible()) {
1188 bv->hideLockedInsetCursor();
1189 setCursorVisible(false);
1191 // if (cursor_visible)
1192 // ToggleInsetCursor(bv);
1196 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1200 actcell = actrow = actcol = 0;
1201 int ly = tabular->GetDescentOfRow(actrow);
1203 // first search the right row
1204 while((ly < y) && (actrow < tabular->rows())) {
1205 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1206 tabular->GetAscentOfRow(actrow + 1) +
1207 tabular->GetAdditionalHeight(actrow + 1));
1209 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1211 actcell = tabular->GetCellNumber(actrow, actcol);
1213 // now search the right column
1214 int lx = tabular->GetWidthOfColumn(actcell) -
1215 tabular->GetAdditionalWidth(actcell);
1217 #ifdef WITH_WARNINGS
1218 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1220 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1221 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1222 tabular->GetAdditionalWidth(actcell - 1));
1224 // Jürgen, you should check that this is correct. (Lgb)
1225 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1226 lx += tabular->GetWidthOfColumn(actcell + 1)
1227 + tabular->GetAdditionalWidth(actcell);
1231 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1236 int InsetTabular::getCellXPos(int cell) const
1240 for (; !tabular->IsFirstCellInRow(c); --c)
1242 int lx = tabular->GetWidthOfColumn(cell);
1243 for (; c < cell; ++c) {
1244 lx += tabular->GetWidthOfColumn(c);
1246 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1250 void InsetTabular::resetPos(BufferView * bv) const
1254 actcol = tabular->column_of_cell(actcell);
1259 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1260 if (tabular->IsLastCellInRow(cell)) {
1261 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1262 tabular->GetAscentOfRow(actrow + 1) +
1263 tabular->GetAdditionalHeight(actrow + 1));
1267 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1268 int new_x = getCellXPos(actcell);
1269 int old_x = cursor.x();
1272 // cursor.x(getCellXPos(actcell) + offset);
1273 if (scroll(false) && (tabular->GetWidthOfTabular() < bv->workWidth()-20)) {
1275 UpdateLocal(bv, FULL, false);
1276 } else if (the_locking_inset &&
1277 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20)) {
1278 int xx = cursor.x() - offset + bv->text->GetRealCursorX(bv);
1279 if (xx > (bv->workWidth()-20))
1280 scroll(bv, -(xx - bv->workWidth() + 60));
1288 UpdateLocal(bv, FULL, false);
1289 } else if ((cursor.x() - offset) > 20 &&
1290 (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
1291 > (bv->workWidth() - 20)) {
1292 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1293 UpdateLocal(bv, FULL, false);
1294 } else if ((cursor.x() - offset) < 20) {
1295 scroll(bv, 20 - cursor.x() + offset);
1296 UpdateLocal(bv, FULL, false);
1297 } else if (scroll(false) && top_x > 20 &&
1298 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1299 scroll(bv, old_x - cursor.x());
1300 UpdateLocal(bv, FULL, false);
1302 if ((!the_locking_inset ||
1303 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1304 actcell != oldcell) {
1305 InsetTabular * inset = const_cast<InsetTabular *>(this);
1306 bv->owner()->getDialogs()->updateTabular(inset);
1312 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1314 if (lock && !old_locking_inset) {
1315 if (ActivateCellInset(bv))
1318 bool moved = isRightToLeft(bv)
1319 ? movePrevCell(bv) : moveNextCell(bv);
1322 if (lock && ActivateCellInset(bv))
1326 return DISPATCHED_NOUPDATE;
1330 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1332 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1335 if (lock) { // behind the inset
1336 if (ActivateCellInset(bv, 0, 0, 0, true))
1340 return DISPATCHED_NOUPDATE;
1344 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1346 int const ocell = actcell;
1347 actcell = tabular->GetCellAbove(actcell);
1348 if (actcell == ocell) // we moved out of the inset
1354 if (old_locking_inset) {
1355 old_locking_inset->GetCursorPos(bv, x, y);
1356 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1358 if (ActivateCellInset(bv, x, 0))
1361 return DISPATCHED_NOUPDATE;
1365 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1367 int const ocell = actcell;
1368 actcell = tabular->GetCellBelow(actcell);
1369 if (actcell == ocell) // we moved out of the inset
1375 if (old_locking_inset) {
1376 old_locking_inset->GetCursorPos(bv, x, y);
1377 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1379 if (ActivateCellInset(bv, x, 0))
1382 return DISPATCHED_NOUPDATE;
1386 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1388 if (isRightToLeft(bv)) {
1389 if (tabular->IsFirstCellInRow(actcell)) {
1390 int row = tabular->row_of_cell(actcell);
1391 if (row == tabular->rows() - 1)
1393 actcell = tabular->GetLastCellInRow(row);
1394 actcell = tabular->GetCellBelow(actcell);
1401 if (tabular->IsLastCell(actcell))
1406 bool rtl = tabular->GetCellInset(actcell)->par->
1407 isRightToLeftPar(bv->buffer()->params);
1408 ActivateCellInset(bv, 0, 0, 0, !rtl);
1415 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1417 if (isRightToLeft(bv)) {
1418 if (tabular->IsLastCellInRow(actcell)) {
1419 int row = tabular->row_of_cell(actcell);
1422 actcell = tabular->GetFirstCellInRow(row);
1423 actcell = tabular->GetCellAbove(actcell);
1425 if (tabular->IsLastCell(actcell))
1430 if (!actcell) // first cell
1435 bool rtl = tabular->GetCellInset(actcell)->par->
1436 isRightToLeftPar(bv->buffer()->params);
1437 ActivateCellInset(bv, 0, 0, 0, !rtl);
1444 bool InsetTabular::Delete()
1450 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1452 if (the_locking_inset)
1453 the_locking_inset->SetFont(bv, font, tall);
1457 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1459 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1462 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1463 string const tmp = tabularFeatures[i].feature;
1465 if (tmp == what.substr(0, tmp.length())) {
1466 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1467 //tabularFeatures[i].feature.length())) {
1468 action = tabularFeatures[i].action;
1472 if (action == LyXTabular::LAST_ACTION)
1476 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1477 TabularFeatures(bv, action, val);
1482 void InsetTabular::TabularFeatures(BufferView * bv,
1483 LyXTabular::Feature feature,
1484 string const & value)
1492 bool setLines = false;
1493 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1494 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1499 case LyXTabular::M_ALIGN_LEFT:
1500 case LyXTabular::ALIGN_LEFT:
1501 setAlign=LYX_ALIGN_LEFT;
1503 case LyXTabular::M_ALIGN_RIGHT:
1504 case LyXTabular::ALIGN_RIGHT:
1505 setAlign=LYX_ALIGN_RIGHT;
1507 case LyXTabular::M_ALIGN_CENTER:
1508 case LyXTabular::ALIGN_CENTER:
1509 setAlign=LYX_ALIGN_CENTER;
1511 case LyXTabular::M_VALIGN_TOP:
1512 case LyXTabular::VALIGN_TOP:
1513 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1515 case LyXTabular::M_VALIGN_BOTTOM:
1516 case LyXTabular::VALIGN_BOTTOM:
1517 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1519 case LyXTabular::M_VALIGN_CENTER:
1520 case LyXTabular::VALIGN_CENTER:
1521 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1526 if (hasSelection()) {
1527 sel_col_start = tabular->column_of_cell(sel_cell_start);
1528 sel_col_end = tabular->column_of_cell(sel_cell_end);
1529 if (sel_col_start > sel_col_end) {
1530 sel_col_end = sel_col_start;
1531 sel_col_start = tabular->column_of_cell(sel_cell_end);
1533 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1536 sel_row_start = tabular->row_of_cell(sel_cell_start);
1537 sel_row_end = tabular->row_of_cell(sel_cell_end);
1538 if (sel_row_start > sel_row_end) {
1539 //int tmp = sel_row_start;
1540 //sel_row_start = sel_row_end;
1541 //sel_row_end = tmp;
1542 swap(sel_row_start, sel_row_end);
1545 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1546 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1548 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1549 bv->text->cursor.par()->previous(),
1550 bv->text->cursor.par()->next());
1552 int row = tabular->row_of_cell(actcell);
1553 int column = tabular->column_of_cell(actcell);
1557 case LyXTabular::SET_PWIDTH:
1559 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1560 tabular->SetColumnPWidth(actcell,value);
1562 for (int i = 0; i < tabular->rows(); ++i) {
1563 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1566 UpdateLocal(bv, INIT, true);
1570 case LyXTabular::SET_MPWIDTH:
1572 bool const update = (tabular->GetPWidth(actcell) != value);
1573 tabular->SetMColumnPWidth(actcell,value);
1575 for (int i = 0; i < tabular->rows(); ++i) {
1576 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1579 UpdateLocal(bv, INIT, true);
1583 case LyXTabular::SET_SPECIAL_COLUMN:
1584 case LyXTabular::SET_SPECIAL_MULTI:
1585 tabular->SetAlignSpecial(actcell,value,feature);
1587 case LyXTabular::APPEND_ROW:
1588 // append the row into the tabular
1589 UnlockInsetInInset(bv, the_locking_inset);
1590 tabular->AppendRow(actcell);
1591 UpdateLocal(bv, INIT, true);
1593 case LyXTabular::APPEND_COLUMN:
1594 // append the column into the tabular
1595 UnlockInsetInInset(bv, the_locking_inset);
1596 tabular->AppendColumn(actcell);
1597 actcell = tabular->GetCellNumber(row, column);
1598 UpdateLocal(bv, INIT, true);
1600 case LyXTabular::DELETE_ROW:
1601 UnlockInsetInInset(bv, the_locking_inset);
1602 tabular->DeleteRow(tabular->row_of_cell(actcell));
1603 if ((row+1) > tabular->rows())
1605 actcell = tabular->GetCellNumber(row, column);
1607 UpdateLocal(bv, INIT, true);
1609 case LyXTabular::DELETE_COLUMN:
1610 UnlockInsetInInset(bv, the_locking_inset);
1611 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1612 if ((column+1) > tabular->columns())
1614 actcell = tabular->GetCellNumber(row, column);
1616 UpdateLocal(bv, INIT, true);
1618 case LyXTabular::M_TOGGLE_LINE_TOP:
1620 case LyXTabular::TOGGLE_LINE_TOP:
1622 bool lineSet = !tabular->TopLine(actcell, flag);
1623 for (int i = sel_row_start; i <= sel_row_end; ++i)
1624 for (int j = sel_col_start; j <= sel_col_end; ++j)
1625 tabular->SetTopLine(
1626 tabular->GetCellNumber(i, j),
1628 UpdateLocal(bv, INIT, true);
1632 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1634 case LyXTabular::TOGGLE_LINE_BOTTOM:
1636 bool lineSet = !tabular->BottomLine(actcell, flag);
1637 for (int i = sel_row_start; i <= sel_row_end; ++i)
1638 for (int j = sel_col_start; j <= sel_col_end; ++j)
1639 tabular->SetBottomLine(
1640 tabular->GetCellNumber(i, j),
1643 UpdateLocal(bv, INIT, true);
1647 case LyXTabular::M_TOGGLE_LINE_LEFT:
1649 case LyXTabular::TOGGLE_LINE_LEFT:
1651 bool lineSet = !tabular->LeftLine(actcell, flag);
1652 for (int i = sel_row_start; i <= sel_row_end; ++i)
1653 for (int j = sel_col_start; j <= sel_col_end; ++j)
1654 tabular->SetLeftLine(
1655 tabular->GetCellNumber(i,j),
1658 UpdateLocal(bv, INIT, true);
1662 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1664 case LyXTabular::TOGGLE_LINE_RIGHT:
1666 bool lineSet = !tabular->RightLine(actcell, flag);
1667 for (int i = sel_row_start; i <= sel_row_end; ++i)
1668 for (int j = sel_col_start; j <= sel_col_end; ++j)
1669 tabular->SetRightLine(
1670 tabular->GetCellNumber(i,j),
1673 UpdateLocal(bv, INIT, true);
1677 case LyXTabular::M_ALIGN_LEFT:
1678 case LyXTabular::M_ALIGN_RIGHT:
1679 case LyXTabular::M_ALIGN_CENTER:
1681 case LyXTabular::ALIGN_LEFT:
1682 case LyXTabular::ALIGN_RIGHT:
1683 case LyXTabular::ALIGN_CENTER:
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->SetAlignment(
1687 tabular->GetCellNumber(i, j),
1690 UpdateLocal(bv, INIT, true);
1692 case LyXTabular::M_VALIGN_TOP:
1693 case LyXTabular::M_VALIGN_BOTTOM:
1694 case LyXTabular::M_VALIGN_CENTER:
1696 case LyXTabular::VALIGN_TOP:
1697 case LyXTabular::VALIGN_BOTTOM:
1698 case LyXTabular::VALIGN_CENTER:
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->SetVAlignment(
1702 tabular->GetCellNumber(i, j),
1704 UpdateLocal(bv, INIT, true);
1706 case LyXTabular::MULTICOLUMN:
1708 if (sel_row_start != sel_row_end) {
1709 WriteAlert(_("Impossible Operation!"),
1710 _("Multicolumns can only be horizontally."),
1714 // just multicol for one Single Cell
1715 if (!hasSelection()) {
1716 // check wether we are completly in a multicol
1717 if (tabular->IsMultiColumn(actcell)) {
1718 tabular->UnsetMultiColumn(actcell);
1719 UpdateLocal(bv, INIT, true);
1721 tabular->SetMultiColumn(actcell, 1);
1722 UpdateLocal(bv, CELL, true);
1726 // we have a selection so this means we just add all this
1727 // cells to form a multicolumn cell
1731 if (sel_cell_start > sel_cell_end) {
1732 s_start = sel_cell_end;
1733 s_end = sel_cell_start;
1735 s_start = sel_cell_start;
1736 s_end = sel_cell_end;
1738 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1740 sel_cell_end = sel_cell_start;
1741 UpdateLocal(bv, INIT, true);
1744 case LyXTabular::SET_ALL_LINES:
1746 case LyXTabular::UNSET_ALL_LINES:
1747 for (int i = sel_row_start; i <= sel_row_end; ++i)
1748 for (int j = sel_col_start; j <= sel_col_end; ++j)
1749 tabular->SetAllLines(
1750 tabular->GetCellNumber(i,j), setLines);
1751 UpdateLocal(bv, INIT, true);
1753 case LyXTabular::SET_LONGTABULAR:
1754 tabular->SetLongTabular(true);
1755 UpdateLocal(bv, INIT, true); // because this toggles displayed
1757 case LyXTabular::UNSET_LONGTABULAR:
1758 tabular->SetLongTabular(false);
1759 UpdateLocal(bv, INIT, true); // because this toggles displayed
1761 case LyXTabular::SET_ROTATE_TABULAR:
1762 tabular->SetRotateTabular(true);
1764 case LyXTabular::UNSET_ROTATE_TABULAR:
1765 tabular->SetRotateTabular(false);
1767 case LyXTabular::SET_ROTATE_CELL:
1768 for (int i = sel_row_start; i <= sel_row_end; ++i)
1769 for (int j = sel_col_start; j<=sel_col_end; ++j)
1770 tabular->SetRotateCell(
1771 tabular->GetCellNumber(i, j),
1774 case LyXTabular::UNSET_ROTATE_CELL:
1775 for (int i = sel_row_start; i <= sel_row_end; ++i)
1776 for (int j = sel_col_start; j <= sel_col_end; ++j)
1777 tabular->SetRotateCell(
1778 tabular->GetCellNumber(i, j), false);
1780 case LyXTabular::SET_USEBOX:
1782 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1783 if (val == tabular->GetUsebox(actcell))
1784 val = LyXTabular::BOX_NONE;
1785 for (int i = sel_row_start; i <= sel_row_end; ++i)
1786 for (int j = sel_col_start; j <= sel_col_end; ++j)
1788 tabular->GetCellNumber(i, j), val);
1791 case LyXTabular::SET_LTFIRSTHEAD:
1792 tabular->SetLTHead(actcell, true);
1794 case LyXTabular::SET_LTHEAD:
1795 tabular->SetLTHead(actcell, false);
1797 case LyXTabular::SET_LTFOOT:
1798 tabular->SetLTFoot(actcell, false);
1800 case LyXTabular::SET_LTLASTFOOT:
1801 tabular->SetLTFoot(actcell, true);
1803 case LyXTabular::SET_LTNEWPAGE:
1805 bool what = !tabular->GetLTNewPage(actcell);
1806 tabular->SetLTNewPage(actcell, what);
1809 // dummy stuff just to avoid warnings
1810 case LyXTabular::LAST_ACTION:
1816 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1819 UpdatableInset * inset =
1820 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1821 LyXFont font(LyXFont::ALL_SANE);
1823 x = inset->x() + inset->width(bv, font);
1824 y = inset->descent(bv, font);
1826 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1827 //inset_y = cursor.y();
1828 inset->Edit(bv, x, y, button);
1829 if (!the_locking_inset)
1831 UpdateLocal(bv, CELL, false);
1832 return (the_locking_inset != 0);
1836 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1839 inset_x = cursor.x()
1840 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1841 inset_y = cursor.y();
1842 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1846 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1849 > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
1853 // This returns paperWidth() if the cell-width is unlimited or the width
1854 // in pixels if we have a pwidth for this cell.
1855 int InsetTabular::GetMaxWidthOfCell(BufferView * bv, int cell) const
1857 string const s = tabular->GetPWidth(cell);
1861 return VSpace(s).inPixels(bv);
1865 int InsetTabular::getMaxWidth(BufferView * bv,
1866 UpdatableInset const * inset) const
1868 int const n = tabular->GetNumberOfCells();
1870 for (; cell < n; ++cell) {
1871 if (tabular->GetCellInset(cell) == inset)
1876 int w = GetMaxWidthOfCell(bv, cell);
1878 // because the inset then subtracts it's top_x and owner->x()
1879 w += (inset->x() - top_x);
1884 void InsetTabular::resizeLyXText(BufferView *) const
1890 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1891 bool const recursive) const
1893 if (the_locking_inset)
1894 return the_locking_inset->getLyXText(bv, recursive);
1895 return Inset::getLyXText(bv, recursive);
1899 bool InsetTabular::ShowInsetDialog(BufferView * bv) const
1901 if (!the_locking_inset || !the_locking_inset->ShowInsetDialog(bv))
1902 bv->owner()->getDialogs()
1903 ->showTabular(const_cast<InsetTabular *>(this));
1908 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1910 if (the_locking_inset) {
1911 InsetTabular * i = static_cast<InsetTabular *>
1912 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1914 i->OpenLayoutDialog(bv);
1918 bv->owner()->getDialogs()->showTabular(
1919 const_cast<InsetTabular *>(this));
1923 // functions returns:
1927 // 3 ... toggled off
1929 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1931 int action = LyXTabular::LAST_ACTION;
1932 LyXFunc::func_status status = LyXFunc::OK;
1935 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1936 string const tmp = tabularFeatures[i].feature;
1937 if (tmp == what.substr(0, tmp.length())) {
1938 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1939 // tabularFeatures[i].feature.length())) {
1940 action = tabularFeatures[i].action;
1944 if (action == LyXTabular::LAST_ACTION)
1945 return LyXFunc::Unknown;
1947 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1954 if (hasSelection()) {
1955 sel_row_start = tabular->row_of_cell(sel_cell_start);
1956 sel_row_end = tabular->row_of_cell(sel_cell_end);
1957 if (sel_row_start > sel_row_end) {
1958 //int tmp = sel_row_start;
1959 //sel_row_start = sel_row_end;
1960 //sel_row_end = tmp;
1961 swap(sel_row_start, sel_row_end);
1964 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1968 case LyXTabular::SET_PWIDTH:
1969 case LyXTabular::SET_MPWIDTH:
1970 case LyXTabular::SET_SPECIAL_COLUMN:
1971 case LyXTabular::SET_SPECIAL_MULTI:
1972 status |= LyXFunc::Disabled;
1975 case LyXTabular::APPEND_ROW:
1976 case LyXTabular::APPEND_COLUMN:
1977 case LyXTabular::DELETE_ROW:
1978 case LyXTabular::DELETE_COLUMN:
1979 case LyXTabular::SET_ALL_LINES:
1980 case LyXTabular::UNSET_ALL_LINES:
1981 status |= LyXFunc::OK;
1984 case LyXTabular::MULTICOLUMN:
1985 if (tabular->IsMultiColumn(actcell))
1986 status |= LyXFunc::ToggleOn;
1988 status |= LyXFunc::ToggleOff;
1990 case LyXTabular::M_TOGGLE_LINE_TOP:
1992 case LyXTabular::TOGGLE_LINE_TOP:
1993 if (tabular->TopLine(actcell, flag))
1994 status |= LyXFunc::ToggleOn;
1996 status |= LyXFunc::ToggleOff;
1998 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2000 case LyXTabular::TOGGLE_LINE_BOTTOM:
2001 if (tabular->BottomLine(actcell, flag))
2002 status |= LyXFunc::ToggleOn;
2004 status |= LyXFunc::ToggleOff;
2006 case LyXTabular::M_TOGGLE_LINE_LEFT:
2008 case LyXTabular::TOGGLE_LINE_LEFT:
2009 if (tabular->LeftLine(actcell, flag))
2010 status |= LyXFunc::ToggleOn;
2012 status |= LyXFunc::ToggleOff;
2014 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2016 case LyXTabular::TOGGLE_LINE_RIGHT:
2017 if (tabular->RightLine(actcell, flag))
2018 status |= LyXFunc::ToggleOn;
2020 status |= LyXFunc::ToggleOff;
2022 case LyXTabular::M_ALIGN_LEFT:
2024 case LyXTabular::ALIGN_LEFT:
2025 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2026 status |= LyXFunc::ToggleOn;
2028 status |= LyXFunc::ToggleOff;
2030 case LyXTabular::M_ALIGN_RIGHT:
2032 case LyXTabular::ALIGN_RIGHT:
2033 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2034 status |= LyXFunc::ToggleOn;
2036 status |= LyXFunc::ToggleOff;
2038 case LyXTabular::M_ALIGN_CENTER:
2040 case LyXTabular::ALIGN_CENTER:
2041 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2042 status |= LyXFunc::ToggleOn;
2044 status |= LyXFunc::ToggleOff;
2046 case LyXTabular::M_VALIGN_TOP:
2048 case LyXTabular::VALIGN_TOP:
2049 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2050 status |= LyXFunc::ToggleOn;
2052 status |= LyXFunc::ToggleOff;
2054 case LyXTabular::M_VALIGN_BOTTOM:
2056 case LyXTabular::VALIGN_BOTTOM:
2057 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2058 status |= LyXFunc::ToggleOn;
2060 status |= LyXFunc::ToggleOff;
2062 case LyXTabular::M_VALIGN_CENTER:
2064 case LyXTabular::VALIGN_CENTER:
2065 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2066 status |= LyXFunc::ToggleOn;
2068 status |= LyXFunc::ToggleOff;
2070 case LyXTabular::SET_LONGTABULAR:
2071 if (tabular->IsLongTabular())
2072 status |= LyXFunc::ToggleOn;
2074 status |= LyXFunc::ToggleOff;
2076 case LyXTabular::UNSET_LONGTABULAR:
2077 if (!tabular->IsLongTabular())
2078 status |= LyXFunc::ToggleOn;
2080 status |= LyXFunc::ToggleOff;
2082 case LyXTabular::SET_ROTATE_TABULAR:
2083 if (tabular->GetRotateTabular())
2084 status |= LyXFunc::ToggleOn;
2086 status |= LyXFunc::ToggleOff;
2088 case LyXTabular::UNSET_ROTATE_TABULAR:
2089 if (!tabular->GetRotateTabular())
2090 status |= LyXFunc::ToggleOn;
2092 status |= LyXFunc::ToggleOff;
2094 case LyXTabular::SET_ROTATE_CELL:
2095 if (tabular->GetRotateCell(actcell))
2096 status |= LyXFunc::ToggleOn;
2098 status |= LyXFunc::ToggleOff;
2100 case LyXTabular::UNSET_ROTATE_CELL:
2101 if (!tabular->GetRotateCell(actcell))
2102 status |= LyXFunc::ToggleOn;
2104 status |= LyXFunc::ToggleOff;
2106 case LyXTabular::SET_USEBOX:
2107 if (strToInt(argument) == tabular->GetUsebox(actcell))
2108 status |= LyXFunc::ToggleOn;
2110 status |= LyXFunc::ToggleOff;
2112 case LyXTabular::SET_LTFIRSTHEAD:
2113 if (tabular->GetRowOfLTHead(actcell, dummy))
2114 status |= LyXFunc::ToggleOn;
2116 status |= LyXFunc::ToggleOff;
2118 case LyXTabular::SET_LTHEAD:
2119 if (tabular->GetRowOfLTHead(actcell, dummy))
2120 status |= LyXFunc::ToggleOn;
2122 status |= LyXFunc::ToggleOff;
2124 case LyXTabular::SET_LTFOOT:
2125 if (tabular->GetRowOfLTFoot(actcell, dummy))
2126 status |= LyXFunc::ToggleOn;
2128 status |= LyXFunc::ToggleOff;
2130 case LyXTabular::SET_LTLASTFOOT:
2131 if (tabular->GetRowOfLTFoot(actcell, dummy))
2132 status |= LyXFunc::ToggleOn;
2134 status |= LyXFunc::ToggleOff;
2136 case LyXTabular::SET_LTNEWPAGE:
2137 if (tabular->GetLTNewPage(actcell))
2138 status |= LyXFunc::ToggleOn;
2140 status |= LyXFunc::ToggleOff;
2143 status = LyXFunc::Disabled;
2150 std::vector<string> const InsetTabular::getLabelList() const
2152 return tabular->getLabelList();
2156 bool InsetTabular::copySelection(BufferView * bv)
2158 if (!hasSelection())
2160 //delete paste_tabular;
2162 //int sel_col_start;
2164 //int sel_row_start;
2167 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2168 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2169 if (sel_col_start > sel_col_end) {
2170 sel_col_start = sel_col_end;
2171 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2173 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2175 int const columns = sel_col_end - sel_col_start + 1;
2177 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2178 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2179 if (sel_row_start > sel_row_end) {
2180 //int tmp tmp = sel_row_start;
2181 //sel_row_start = sel_row_end;
2182 //sel_row_end = tmp;
2183 swap(sel_row_start, sel_row_end);
2185 int const rows = sel_row_end - sel_row_start + 1;
2187 delete paste_tabular;
2188 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2190 for (int i = 0; i < sel_row_start; ++i)
2191 paste_tabular->DeleteRow(0);
2192 while(paste_tabular->rows() > rows)
2193 paste_tabular->DeleteRow(rows);
2194 paste_tabular->SetTopLine(0, true, true);
2195 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2197 for (int i = 0; i < sel_col_start; ++i)
2198 paste_tabular->DeleteColumn(0);
2199 while (paste_tabular->columns() > columns)
2200 paste_tabular->DeleteColumn(columns);
2201 paste_tabular->SetLeftLine(0, true, true);
2202 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2206 paste_tabular->Ascii(bv->buffer(), sstr);
2207 bv->stuffClipboard(sstr.str().c_str());
2212 bool InsetTabular::pasteSelection(BufferView * bv)
2217 for (int r1 = 0, r2 = actrow;
2218 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2220 for(int c1 = 0, c2 = actcol;
2221 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2223 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2224 tabular->IsPartOfMultiColumn(r2,c2))
2226 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2230 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2234 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2235 int const n2 = tabular->GetCellNumber(r2, c2);
2236 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2237 tabular->GetCellInset(n2)->setOwner(this);
2238 tabular->GetCellInset(n2)->deleteLyXText(bv);
2245 bool InsetTabular::cutSelection()
2247 if (!hasSelection())
2250 //int sel_col_start;
2252 //int sel_row_start;
2255 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2256 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2257 if (sel_col_start > sel_col_end) {
2258 sel_col_start = sel_col_end;
2259 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2261 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2263 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2264 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2265 if (sel_row_start > sel_row_end) {
2266 //int tmp = sel_row_start;
2267 //sel_row_start = sel_row_end;
2268 //sel_row_end = tmp;
2269 swap(sel_row_start, sel_row_end);
2271 if (sel_cell_start > sel_cell_end) {
2272 //int tmp = sel_cell_start;
2273 //sel_cell_start = sel_cell_end;
2274 //sel_cell_end = tmp;
2275 swap(sel_cell_start, sel_cell_end);
2277 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2278 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2279 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2286 bool InsetTabular::isRightToLeft(BufferView *bv )
2288 return bv->getParentLanguage(this)->RightToLeft();
2291 bool InsetTabular::nodraw() const
2293 if (the_locking_inset)
2294 return the_locking_inset->nodraw();
2295 return UpdatableInset::nodraw();
2298 int InsetTabular::scroll(bool recursive) const
2300 int sx = UpdatableInset::scroll(false);
2302 if (recursive && the_locking_inset)
2303 sx += the_locking_inset->scroll(recursive);
2308 bool InsetTabular::doClearArea() const
2310 return !locked || (need_update & (FULL|INIT));