1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
19 #pragma implementation
22 #include "insettabular.h"
25 #include "commandtags.h"
27 #include "LaTeXFeatures.h"
31 #include "lyx_gui_misc.h"
34 #include "insets/insettext.h"
35 #include "frontends/Dialogs.h"
40 const int ADD_TO_HEIGHT = 2;
41 const int ADD_TO_TABULAR_WIDTH = 2;
43 static LyXTabular * paste_tabular = 0;
44 bool InsetTabular::hasPasteBuffer() const
46 return (paste_tabular != 0);
57 struct tabular_features {
58 LyXTabular::Feature action;
62 //static tabular_features * tabularFeatures = 0;
64 static tabular_features tabularFeatures[] =
66 { LyXTabular::APPEND_ROW, "append-row" },
67 { LyXTabular::APPEND_COLUMN, "append-column" },
68 { LyXTabular::DELETE_ROW, "delete-row" },
69 { LyXTabular::DELETE_COLUMN, "delete-column" },
70 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
71 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
72 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
73 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
74 { LyXTabular::ALIGN_LEFT, "align-left" },
75 { LyXTabular::ALIGN_RIGHT, "align-right" },
76 { LyXTabular::ALIGN_CENTER, "align-center" },
77 { LyXTabular::VALIGN_TOP, "valign-top" },
78 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
79 { LyXTabular::VALIGN_CENTER, "valign-center" },
80 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
81 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
82 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
83 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
84 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
85 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
86 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
87 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
88 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
89 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
90 { LyXTabular::MULTICOLUMN, "multicolumn" },
91 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
92 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
93 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
94 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
95 { LyXTabular::SET_PWIDTH, "set-pwidth" },
96 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
97 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
98 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
99 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
100 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
101 { LyXTabular::SET_USEBOX, "set-usebox" },
102 { LyXTabular::SET_LTHEAD, "set-lthead" },
103 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
104 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
105 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
106 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
107 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
108 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
109 { LyXTabular::LAST_ACTION, "" }
112 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
119 tabular = new LyXTabular(this, rows,columns);
120 // for now make it always display as display() inset
122 the_locking_inset = 0;
123 locked = no_selection = cursor_visible = false;
126 actrow = actcell = 0;
133 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
136 tabular = new LyXTabular(this, *(tab.tabular));
137 the_locking_inset = 0;
138 locked = no_selection = cursor_visible = false;
141 actrow = actcell = 0;
142 sel_cell_start = sel_cell_end = 0;
148 InsetTabular::~InsetTabular()
155 Inset * InsetTabular::Clone(Buffer const & buf) const
157 InsetTabular * t = new InsetTabular(*this, buf);
159 t->tabular = tabular->Clone(t);
164 void InsetTabular::Write(Buffer const * buf, ostream & os) const
166 os << " Tabular" << endl;
167 tabular->Write(buf, os);
171 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
173 bool old_format = (lex.GetString() == "\\LyXTable");
178 tabular = new LyXTabular(buf, this, lex);
186 token = lex.GetString();
187 while (lex.IsOK() && (token != "\\end_inset")) {
189 token = lex.GetString();
191 if (token != "\\end_inset") {
192 lex.printError("Missing \\end_inset at this point. "
198 int InsetTabular::ascent(BufferView *, LyXFont const &) const
200 return tabular->GetAscentOfRow(0);
204 int InsetTabular::descent(BufferView *, LyXFont const &) const
206 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
210 int InsetTabular::width(BufferView *, LyXFont const &) const
212 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
216 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
217 float & x, bool cleared) const
222 Painter & pain = bv->painter();
227 UpdatableInset::draw(bv, font, baseline, x, cleared);
228 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
229 (top_x != int(x)) || (top_baseline != baseline))) {
230 int h = ascent(bv, font) + descent(bv, font);
231 int tx = display() || !owner() ? 0 : top_x;
232 int w = tx ? width(bv, font) : pain.paperWidth();
233 int ty = baseline - ascent(bv, font);
237 if ((ty + h) > pain.paperHeight())
238 h = pain.paperHeight();
239 if ((top_x + w) > pain.paperWidth())
240 w = pain.paperWidth();
241 pain.fillRectangle(tx, ty, w, h);
246 top_baseline = baseline;
247 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
250 x += ADD_TO_TABULAR_WIDTH;
254 for (i = 0; i < tabular->rows(); ++i) {
256 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
257 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
258 for (j = 0; j < tabular->columns(); ++j) {
259 if (tabular->IsPartOfMultiColumn(i, j))
261 cx = nx + tabular->GetBeginningOfTextInCell(cell);
264 DrawCellSelection(pain, nx, baseline, i, j, cell);
265 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
267 DrawCellLines(pain, nx, baseline, i, cell);
269 nx += tabular->GetWidthOfColumn(cell);
272 baseline += tabular->GetDescentOfRow(i) +
273 tabular->GetAscentOfRow(i + 1) +
274 tabular->GetAdditionalHeight(cell);
276 } else if (need_update == CELL) {
279 if (the_locking_inset) {
280 Inset * inset = tabular->GetCellInset(cell);
281 for (i = 0; (inset != the_locking_inset) && (i < tabular->rows());
284 for (j = 0; (inset != the_locking_inset) && (j < tabular->columns()); ++j)
286 if (tabular->IsPartOfMultiColumn(i, j))
288 nx += tabular->GetWidthOfColumn(cell);
290 inset = tabular->GetCellInset(cell);
292 if (tabular->row_of_cell(cell) > i) {
294 baseline += tabular->GetDescentOfRow(i) +
295 tabular->GetAscentOfRow(i + 1) +
296 tabular->GetAdditionalHeight(cell);
300 for (i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
301 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
302 if (tabular->IsPartOfMultiColumn(i, j))
304 nx += tabular->GetWidthOfColumn(cell);
307 if (tabular->row_of_cell(cell) > i) {
309 baseline += tabular->GetDescentOfRow(i) +
310 tabular->GetAscentOfRow(i + 1) +
311 tabular->GetAdditionalHeight(cell);
315 i = tabular->row_of_cell(cell);
316 if (the_locking_inset != tabular->GetCellInset(cell)) {
317 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
322 cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
323 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
324 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
326 // clear only if we didn't have a change
327 if (need_update == CELL) {
328 // clear before the inset
331 baseline - tabular->GetAscentOfRow(i) + 1,
333 tabular->GetAscentOfRow(i) +
334 tabular->GetDescentOfRow(i) - 1);
335 // clear behind the inset
337 int(cx + the_locking_inset->width(bv,font) + 1),
338 baseline - tabular->GetAscentOfRow(i) + 1,
339 tabular->GetWidthOfColumn(cell) -
340 tabular->GetBeginningOfTextInCell(cell) -
341 the_locking_inset->width(bv,font) -
342 tabular->GetAdditionalWidth(cell) - 1,
343 tabular->GetAscentOfRow(i) +
344 tabular->GetDescentOfRow(i) - 1);
347 x -= ADD_TO_TABULAR_WIDTH;
348 x += width(bv, font);
349 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
356 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
357 int row, int cell) const
359 int x2 = x + tabular->GetWidthOfColumn(cell);
362 if (!tabular->TopAlreadyDrawed(cell)) {
363 on_off = !tabular->TopLine(cell);
364 pain.line(x, baseline - tabular->GetAscentOfRow(row),
365 x2, baseline - tabular->GetAscentOfRow(row),
366 on_off ? LColor::tabularonoffline : LColor::tabularline,
367 on_off ? Painter::line_onoffdash : Painter::line_solid);
369 on_off = !tabular->BottomLine(cell);
370 pain.line(x,baseline + tabular->GetDescentOfRow(row),
371 x2, baseline + tabular->GetDescentOfRow(row),
372 on_off ? LColor::tabularonoffline : LColor::tabularline,
373 on_off ? Painter::line_onoffdash : Painter::line_solid);
374 if (!tabular->LeftAlreadyDrawed(cell)) {
375 on_off = !tabular->LeftLine(cell);
376 pain.line(x, baseline - tabular->GetAscentOfRow(row),
377 x, baseline + tabular->GetDescentOfRow(row),
378 on_off ? LColor::tabularonoffline : LColor::tabularline,
379 on_off ? Painter::line_onoffdash : Painter::line_solid);
381 on_off = !tabular->RightLine(cell);
382 pain.line(x2 - tabular->GetAdditionalWidth(cell),
383 baseline - tabular->GetAscentOfRow(row),
384 x2 - tabular->GetAdditionalWidth(cell),
385 baseline + tabular->GetDescentOfRow(row),
386 on_off ? LColor::tabularonoffline : LColor::tabularline,
387 on_off ? Painter::line_onoffdash : Painter::line_solid);
391 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
392 int row, int column, int cell) const
394 int cs = tabular->column_of_cell(sel_cell_start);
395 int ce = tabular->column_of_cell(sel_cell_end);
398 cs = tabular->column_of_cell(sel_cell_end);
400 ce = tabular->right_column_of_cell(sel_cell_end);
403 int rs = tabular->row_of_cell(sel_cell_start);
404 int re = tabular->row_of_cell(sel_cell_end);
405 if (rs > re) swap(rs, re);
407 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
408 int w = tabular->GetWidthOfColumn(cell);
409 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
410 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
411 w, h, LColor::selection);
416 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
420 calculate_dimensions_of_cells(bv, font, true);
422 owner()->update(bv, font, true);
425 if (the_locking_inset) {
426 the_locking_inset->update(bv, font, reinit);
428 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
429 // inset_y = cursor.y();
431 switch (need_update) {
435 if (calculate_dimensions_of_cells(bv, font, false))
447 string const InsetTabular::EditMessage() const
449 return _("Opened Tabular Inset");
453 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
455 UpdatableInset::Edit(bv, x, y, button);
457 if (!bv->lockInset(this)) {
458 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
462 the_locking_inset = 0;
466 sel_cell_start = sel_cell_end = actcell;
467 bv->text->FinishUndo();
468 if (InsetHit(bv, x, y) && (button != 3)) {
469 ActivateCellInsetAbs(bv, x, y, button);
471 // UpdateLocal(bv, NONE, false);
472 // bv->getOwner()->getPopups().updateFormTabular();
476 void InsetTabular::InsetUnlock(BufferView * bv)
478 if (the_locking_inset) {
479 the_locking_inset->InsetUnlock(bv);
480 the_locking_inset = 0;
483 no_selection = false;
486 if (scroll() || hasSelection()) {
490 sel_cell_start = sel_cell_end = 0;
492 UpdateLocal(bv, FULL, false);
497 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
498 bool mark_dirty) const
500 if (need_update < what) // only set this if it has greater update
502 if ((what == INIT) && hasSelection())
505 if (need_update != NONE) {
506 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
507 if (locked) // && (what != NONE))
513 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
515 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
519 if (inset == tabular->GetCellInset(actcell)) {
520 lyxerr[Debug::INSETS] << "OK" << endl;
521 the_locking_inset = tabular->GetCellInset(actcell);
523 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
524 inset_y = cursor.y();
526 } else if (the_locking_inset && (the_locking_inset == inset)) {
527 lyxerr[Debug::INSETS] << "OK" << endl;
529 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
530 inset_y = cursor.y();
531 } else if (the_locking_inset) {
532 lyxerr[Debug::INSETS] << "MAYBE" << endl;
533 return the_locking_inset->LockInsetInInset(bv, inset);
535 lyxerr[Debug::INSETS] << "NOT OK" << endl;
540 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
543 if (!the_locking_inset)
545 if (the_locking_inset == inset) {
546 the_locking_inset->InsetUnlock(bv);
547 the_locking_inset = 0;
548 UpdateLocal(bv, CELL, false);
549 ShowInsetCursor(bv, false);
552 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
553 if (inset->LyxCode() == TABULAR_CODE &&
554 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
556 bv->owner()->getDialogs()->updateTabular(this);
565 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
567 if (!the_locking_inset)
569 if (the_locking_inset != inset) {
570 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
573 UpdateLocal(bv, CELL, false);
578 unsigned int InsetTabular::InsetInInsetY()
580 if (!the_locking_inset)
583 return (inset_y + the_locking_inset->InsetInInsetY());
587 UpdatableInset * InsetTabular::GetLockingInset()
589 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
593 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
597 if (the_locking_inset)
598 return the_locking_inset->GetFirstLockingInsetOfType(c);
603 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
605 if (the_locking_inset)
606 return the_locking_inset->InsertInset(bv, inset);
611 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
613 if (hasSelection() && (button == 3))
616 if (hasSelection()) {
618 UpdateLocal(bv, SELECTION, false);
621 no_selection = false;
623 int const ocell = actcell;
624 int const orow = actrow;
629 UpdateLocal(bv, NONE, false);
630 sel_cell_start = sel_cell_end = actcell;
632 if ((ocell != actcell) && the_locking_inset) {
633 the_locking_inset->InsetUnlock(bv);
634 the_locking_inset = 0;
640 bool const inset_hit = InsetHit(bv, x, y);
642 if ((ocell == actcell) && the_locking_inset && inset_hit) {
644 the_locking_inset->InsetButtonPress(bv,
645 x - inset_x, y - inset_y, button);
647 } else if (the_locking_inset) {
648 the_locking_inset->InsetUnlock(bv);
650 the_locking_inset = 0;
652 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
655 if (inset_hit && bv->theLockingInset()) {
656 if (ActivateCellInsetAbs(bv, x, y, button))
657 the_locking_inset->InsetButtonPress(bv, x - inset_x,
658 y - inset_y, button);
665 void InsetTabular::InsetButtonRelease(BufferView * bv,
666 int x, int y, int button)
669 if (the_locking_inset) {
671 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
672 i->InsetButtonRelease(bv, x, y, button);
676 bv->owner()->getDialogs()->showTabular(this);
679 if (the_locking_inset) {
680 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
683 no_selection = false;
687 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
689 if (the_locking_inset) {
690 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
691 y - inset_y, button);
696 int const old_cell = actcell;
699 sel_cell_end = actcell;
700 if (sel_cell_end != old_cell)
701 UpdateLocal(bv, SELECTION, false);
704 no_selection = false;
708 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
710 if (the_locking_inset) {
711 the_locking_inset->InsetKeyPress(xke);
717 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
720 // We need to save the value of the_locking_inset as the call to
721 // the_locking_inset->LocalDispatch might unlock it.
722 old_locking_inset = the_locking_inset;
723 no_selection = false;
724 UpdatableInset::RESULT result =
725 UpdatableInset::LocalDispatch(bv, action, arg);
726 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
731 if ((action < 0) && arg.empty())
734 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
735 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
737 if (the_locking_inset) {
738 result=the_locking_inset->LocalDispatch(bv, action, arg);
739 if (result == DISPATCHED_NOUPDATE)
741 else if (result == DISPATCHED) {
742 the_locking_inset->ToggleInsetCursor(bv);
743 UpdateLocal(bv, CELL, false);
744 the_locking_inset->ToggleInsetCursor(bv);
746 } else if (result == FINISHED) {
750 bool hs = hasSelection();
754 // --- Cursor Movements ---------------------------------------------
756 if (tabular->IsLastCellInRow(actcell))
758 moveRight(bv, false);
759 sel_cell_end = actcell;
760 UpdateLocal(bv, SELECTION, false);
763 result = moveRight(bv);
764 sel_cell_start = sel_cell_end = actcell;
766 UpdateLocal(bv, SELECTION, false);
769 if (tabular->IsFirstCellInRow(actcell))
772 sel_cell_end = actcell;
773 UpdateLocal(bv, SELECTION, false);
776 result = moveLeft(bv);
777 sel_cell_start = sel_cell_end = actcell;
779 UpdateLocal(bv, SELECTION, false);
783 int const ocell = actcell;
785 if ((ocell == sel_cell_end) ||
786 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
787 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
789 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
790 UpdateLocal(bv, SELECTION, false);
794 result = moveDown(bv, old_locking_inset != 0);
795 sel_cell_start = sel_cell_end = actcell;
797 UpdateLocal(bv, SELECTION, false);
801 int const ocell = actcell;
803 if ((ocell == sel_cell_end) ||
804 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
805 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
807 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
808 UpdateLocal(bv, SELECTION, false);
812 result = moveUp(bv, old_locking_inset != 0);
813 sel_cell_start = sel_cell_end = actcell;
815 UpdateLocal(bv, SELECTION, false);
828 if (the_locking_inset) {
829 UnlockInsetInInset(bv, the_locking_inset);
830 the_locking_inset = 0;
832 if (action == LFUN_TAB)
833 moveNextCell(bv, old_locking_inset != 0);
835 movePrevCell(bv, old_locking_inset != 0);
836 sel_cell_start = sel_cell_end = actcell;
838 UpdateLocal(bv, SELECTION, false);
841 case LFUN_LAYOUT_TABULAR:
843 bv->owner()->getDialogs()->showTabular(this);
846 case LFUN_TABULAR_FEATURE:
847 if (!TabularFeatures(bv, arg))
848 result = UNDISPATCHED;
851 if (!copySelection(bv))
853 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
855 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
856 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
858 bv->text->cursor.par()->previous,
859 bv->text->cursor.par()->next
863 UpdateLocal(bv, INIT, true);
868 bv->text->FinishUndo();
871 case LFUN_PASTESELECTION:
873 string clip(bv->workarea()->getClipboard());
877 if (clip.find('\t') != string::npos) {
881 unsigned int len = clip.length();
882 string::size_type p = 0;
885 ((p = clip.find_first_of("\t\n", p)) != string::npos))
894 maxCols = max(cols, maxCols);
900 maxCols = max(cols, maxCols);
901 delete paste_tabular;
902 paste_tabular = new LyXTabular(this, rows, maxCols);
903 string::size_type op = 0;
905 int cells = paste_tabular->GetNumberOfCells();
907 while((cell < cells) && (p < len) &&
908 (p = clip.find_first_of("\t\n", p)) != string::npos)
914 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
919 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
920 while(cols++ < maxCols)
928 // check for the last cell if there is no trailing '\n'
929 if ((cell < cells) && (op < len))
930 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
932 // so that the clipboard is used and it goes on to default
933 // and executes LFUN_PASTESELECTION in insettext!
934 delete paste_tabular;
939 if (hasPasteBuffer()) {
940 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
942 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
943 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
945 bv->text->cursor.par()->previous,
946 bv->text->cursor.par()->next
950 UpdateLocal(bv, INIT, true);
953 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
955 // we try to activate the actual inset and put this event down to
956 // the insets dispatch function.
957 result = UNDISPATCHED;
958 if (the_locking_inset)
961 if (ActivateCellInset(bv)) {
962 result=the_locking_inset->LocalDispatch(bv, action, arg);
963 if ((result == UNDISPATCHED) || (result == FINISHED)) {
964 UnlockInsetInInset(bv, the_locking_inset);
966 the_locking_inset = 0;
970 the_locking_inset->ToggleInsetCursor(bv);
971 UpdateLocal(bv, CELL, false);
972 the_locking_inset->ToggleInsetCursor(bv);
977 if (result!=FINISHED) {
978 if (!the_locking_inset) {
982 bv->unlockInset(this);
987 int InsetTabular::Latex(Buffer const * buf, ostream & os,
988 bool fragile, bool fp) const
990 return tabular->Latex(buf, os, fragile, fp);
994 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
996 // This should be changed to a real ascii export
997 return tabular->Ascii(buf, os);
1001 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1007 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1009 return tabular->DocBook(buf,os);
1013 void InsetTabular::Validate(LaTeXFeatures & features) const
1015 tabular->Validate(features);
1019 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1020 LyXFont const & font,
1027 bool changed = false;
1029 // if we have a locking_inset we should have to check only this cell for
1030 // change so I'll try this to have a boost, but who knows ;)
1031 if ((need_update != INIT) &&
1032 (the_locking_inset == tabular->GetCellInset(actcell))) {
1033 for(int i = 0; i < tabular->columns(); ++i) {
1034 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1036 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1039 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1040 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1041 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1044 for (int i = 0; i < tabular->rows(); ++i) {
1047 for (int j= 0; j < tabular->columns(); ++j) {
1048 if (tabular->IsPartOfMultiColumn(i,j))
1051 inset = tabular->GetCellInset(cell);
1053 inset->update(bv, font, false);
1054 maxAsc = max(maxAsc, inset->ascent(bv, font));
1055 maxDesc = max(maxDesc, inset->descent(bv, font));
1056 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1058 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1059 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1065 void InsetTabular::GetCursorPos(BufferView *,
1066 int & x, int & y) const
1068 x = cursor.x() - top_x;
1073 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1075 if (the_locking_inset) {
1076 the_locking_inset->ToggleInsetCursor(bv);
1080 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1082 int const asc = lyxfont::maxAscent(font);
1083 int const desc = lyxfont::maxDescent(font);
1086 bv->hideLockedInsetCursor();
1088 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1089 cursor_visible = !cursor_visible;
1093 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1095 if (!cursor_visible) {
1096 LyXFont font; // = GetFont(par, cursor.pos);
1098 int const asc = lyxfont::maxAscent(font);
1099 int const desc = lyxfont::maxDescent(font);
1100 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1102 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1103 cursor_visible = true;
1108 void InsetTabular::HideInsetCursor(BufferView * bv)
1110 if (cursor_visible) {
1111 bv->hideLockedInsetCursor();
1112 cursor_visible = false;
1114 // if (cursor_visible)
1115 // ToggleInsetCursor(bv);
1119 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1123 actcell = actrow = actcol = 0;
1124 int ly = tabular->GetDescentOfRow(actrow);
1126 // first search the right row
1127 while((ly < y) && (actrow < tabular->rows())) {
1128 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1129 tabular->GetAscentOfRow(actrow + 1) +
1130 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1133 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1135 actcell = tabular->GetCellNumber(actrow, actcol);
1137 // now search the right column
1138 int lx = tabular->GetWidthOfColumn(actcell) -
1139 tabular->GetAdditionalWidth(actcell);
1141 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1142 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1143 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1144 tabular->GetAdditionalWidth(actcell - 1));
1146 // Jürgen, you should check that this is correct. (Lgb)
1147 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1148 lx += tabular->GetWidthOfColumn(actcell + 1)
1149 + tabular->GetAdditionalWidth(actcell);
1153 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1158 int InsetTabular::getCellXPos(int cell) const
1162 for (; !tabular->IsFirstCellInRow(c); --c)
1164 int lx = tabular->GetWidthOfColumn(cell);
1165 for (; c < cell; ++c) {
1166 lx += tabular->GetWidthOfColumn(c);
1168 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1172 void InsetTabular::resetPos(BufferView * bv) const
1176 actcol = tabular->column_of_cell(actcell);
1181 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1182 if (tabular->IsLastCellInRow(cell)) {
1183 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1184 tabular->GetAscentOfRow(actrow + 1) +
1185 tabular->GetAdditionalHeight(cell + 1));
1189 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1190 int new_x = getCellXPos(actcell);
1191 int old_x = cursor.x();
1194 // cursor.x(getCellXPos(actcell) + offset);
1195 if (((cursor.x() - offset) > 20) &&
1196 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1197 (bv->workWidth()-20)))
1199 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1200 UpdateLocal(bv, FULL, false);
1201 } else if ((cursor.x() - offset) < 20) {
1202 scroll(bv, 20 - cursor.x() + offset);
1203 UpdateLocal(bv, FULL, false);
1204 } else if (scroll() && (top_x > 20) &&
1205 ((top_x+tabular->GetWidthOfTabular()) > (bv->workWidth()-20))) {
1206 scroll(bv, old_x - cursor.x());
1208 if ((!the_locking_inset ||
1209 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1210 (actcell != oldcell)) {
1211 InsetTabular * inset = const_cast<InsetTabular *>(this);
1212 bv->owner()->getDialogs()->updateTabular(inset);
1218 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1220 if (lock && !old_locking_inset) {
1221 if (ActivateCellInset(bv))
1224 bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv);
1227 if (lock && ActivateCellInset(bv))
1231 return DISPATCHED_NOUPDATE;
1235 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1237 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1240 if (lock) { // behind the inset
1241 if (ActivateCellInset(bv, 0, 0, 0, true))
1245 return DISPATCHED_NOUPDATE;
1249 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1251 int const ocell = actcell;
1252 actcell = tabular->GetCellAbove(actcell);
1253 if (actcell == ocell) // we moved out of the inset
1259 if (old_locking_inset) {
1260 old_locking_inset->GetCursorPos(bv, x, y);
1261 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1263 if (ActivateCellInset(bv, x, 0))
1266 return DISPATCHED_NOUPDATE;
1270 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1272 int const ocell = actcell;
1273 actcell = tabular->GetCellBelow(actcell);
1274 if (actcell == ocell) // we moved out of the inset
1280 if (old_locking_inset) {
1281 old_locking_inset->GetCursorPos(bv, x, y);
1282 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1284 if (ActivateCellInset(bv, x, 0))
1287 return DISPATCHED_NOUPDATE;
1291 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1293 if (isRightToLeft(bv)) {
1294 if (tabular->IsFirstCellInRow(actcell)) {
1295 int row = tabular->row_of_cell(actcell);
1296 if (row == tabular->rows() - 1)
1298 actcell = tabular->GetLastCellInRow(row);
1299 actcell = tabular->GetCellBelow(actcell);
1306 if (tabular->IsLastCell(actcell))
1311 bool rtl = tabular->GetCellInset(actcell)->par->
1312 isRightToLeftPar(bv->buffer()->params);
1313 ActivateCellInset(bv, 0, 0, 0, !rtl);
1320 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1322 if (isRightToLeft(bv)) {
1323 if (tabular->IsLastCellInRow(actcell)) {
1324 int row = tabular->row_of_cell(actcell);
1327 actcell = tabular->GetFirstCellInRow(row);
1328 actcell = tabular->GetCellAbove(actcell);
1330 if (tabular->IsLastCell(actcell))
1335 if (!actcell) // first cell
1340 bool rtl = tabular->GetCellInset(actcell)->par->
1341 isRightToLeftPar(bv->buffer()->params);
1342 ActivateCellInset(bv, 0, 0, 0, !rtl);
1349 bool InsetTabular::Delete()
1355 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1357 if (the_locking_inset)
1358 the_locking_inset->SetFont(bv, font, tall);
1362 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1364 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1367 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1368 string const tmp = tabularFeatures[i].feature;
1370 if (tmp == what.substr(0, tmp.length())) {
1371 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1372 //tabularFeatures[i].feature.length())) {
1373 action = tabularFeatures[i].action;
1377 if (action == LyXTabular::LAST_ACTION)
1381 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1382 TabularFeatures(bv, action, val);
1387 void InsetTabular::TabularFeatures(BufferView * bv,
1388 LyXTabular::Feature feature,
1389 string const & value)
1398 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1399 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1404 case LyXTabular::M_ALIGN_LEFT:
1405 case LyXTabular::ALIGN_LEFT:
1406 setAlign=LYX_ALIGN_LEFT;
1408 case LyXTabular::M_ALIGN_RIGHT:
1409 case LyXTabular::ALIGN_RIGHT:
1410 setAlign=LYX_ALIGN_RIGHT;
1412 case LyXTabular::M_ALIGN_CENTER:
1413 case LyXTabular::ALIGN_CENTER:
1414 setAlign=LYX_ALIGN_CENTER;
1416 case LyXTabular::M_VALIGN_TOP:
1417 case LyXTabular::VALIGN_TOP:
1418 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1420 case LyXTabular::M_VALIGN_BOTTOM:
1421 case LyXTabular::VALIGN_BOTTOM:
1422 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1424 case LyXTabular::M_VALIGN_CENTER:
1425 case LyXTabular::VALIGN_CENTER:
1426 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1431 if (hasSelection()) {
1432 sel_col_start = tabular->column_of_cell(sel_cell_start);
1433 sel_col_end = tabular->column_of_cell(sel_cell_end);
1434 if (sel_col_start > sel_col_end) {
1435 sel_col_end = sel_col_start;
1436 sel_col_start = tabular->column_of_cell(sel_cell_end);
1438 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1441 sel_row_start = tabular->row_of_cell(sel_cell_start);
1442 sel_row_end = tabular->row_of_cell(sel_cell_end);
1443 if (sel_row_start > sel_row_end) {
1444 //int tmp = sel_row_start;
1445 //sel_row_start = sel_row_end;
1446 //sel_row_end = tmp;
1447 swap(sel_row_start, sel_row_end);
1450 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1451 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1453 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1455 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1456 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1458 bv->text->cursor.par()->previous,
1459 bv->text->cursor.par()->next
1463 int row = tabular->row_of_cell(actcell);
1464 int column = tabular->column_of_cell(actcell);
1468 case LyXTabular::SET_PWIDTH:
1470 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1471 tabular->SetColumnPWidth(actcell,value);
1473 for (int i=0; i < tabular->rows(); ++i) {
1474 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1477 UpdateLocal(bv, INIT, true);
1481 case LyXTabular::SET_MPWIDTH:
1483 bool const update = (tabular->GetPWidth(actcell) != value);
1484 tabular->SetMColumnPWidth(actcell,value);
1486 for (int i=0; i < tabular->rows(); ++i) {
1487 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1490 UpdateLocal(bv, INIT, true);
1494 case LyXTabular::SET_SPECIAL_COLUMN:
1495 case LyXTabular::SET_SPECIAL_MULTI:
1496 tabular->SetAlignSpecial(actcell,value,feature);
1498 case LyXTabular::APPEND_ROW:
1499 // append the row into the tabular
1500 UnlockInsetInInset(bv, the_locking_inset);
1501 tabular->AppendRow(actcell);
1502 UpdateLocal(bv, INIT, true);
1504 case LyXTabular::APPEND_COLUMN:
1505 // append the column into the tabular
1506 UnlockInsetInInset(bv, the_locking_inset);
1507 tabular->AppendColumn(actcell);
1508 actcell = tabular->GetCellNumber(row, column);
1509 UpdateLocal(bv, INIT, true);
1511 case LyXTabular::DELETE_ROW:
1512 UnlockInsetInInset(bv, the_locking_inset);
1513 tabular->DeleteRow(tabular->row_of_cell(actcell));
1514 if ((row+1) > tabular->rows())
1516 actcell = tabular->GetCellNumber(row, column);
1518 UpdateLocal(bv, INIT, true);
1520 case LyXTabular::DELETE_COLUMN:
1521 UnlockInsetInInset(bv, the_locking_inset);
1522 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1523 if ((column+1) > tabular->columns())
1525 actcell = tabular->GetCellNumber(row, column);
1527 UpdateLocal(bv, INIT, true);
1529 case LyXTabular::M_TOGGLE_LINE_TOP:
1531 case LyXTabular::TOGGLE_LINE_TOP:
1532 lineSet = !tabular->TopLine(actcell, flag);
1533 for (i=sel_row_start; i<=sel_row_end; ++i)
1534 for (j=sel_col_start; j<=sel_col_end; ++j)
1535 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1536 UpdateLocal(bv, INIT, true);
1539 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1541 case LyXTabular::TOGGLE_LINE_BOTTOM:
1542 lineSet = !tabular->BottomLine(actcell, flag);
1543 for (i=sel_row_start; i<=sel_row_end; ++i)
1544 for (j=sel_col_start; j<=sel_col_end; ++j)
1545 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1547 UpdateLocal(bv, INIT, true);
1550 case LyXTabular::M_TOGGLE_LINE_LEFT:
1552 case LyXTabular::TOGGLE_LINE_LEFT:
1553 lineSet = !tabular->LeftLine(actcell, flag);
1554 for (i=sel_row_start; i<=sel_row_end; ++i)
1555 for (j=sel_col_start; j<=sel_col_end; ++j)
1556 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1558 UpdateLocal(bv, INIT, true);
1561 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1563 case LyXTabular::TOGGLE_LINE_RIGHT:
1564 lineSet = !tabular->RightLine(actcell, flag);
1565 for (i=sel_row_start; i<=sel_row_end; ++i)
1566 for (j=sel_col_start; j<=sel_col_end; ++j)
1567 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1569 UpdateLocal(bv, INIT, true);
1571 case LyXTabular::M_ALIGN_LEFT:
1572 case LyXTabular::M_ALIGN_RIGHT:
1573 case LyXTabular::M_ALIGN_CENTER:
1575 case LyXTabular::ALIGN_LEFT:
1576 case LyXTabular::ALIGN_RIGHT:
1577 case LyXTabular::ALIGN_CENTER:
1578 for (i = sel_row_start; i <= sel_row_end; ++i)
1579 for (j = sel_col_start; j <= sel_col_end; ++j)
1580 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1582 UpdateLocal(bv, INIT, true);
1584 case LyXTabular::M_VALIGN_TOP:
1585 case LyXTabular::M_VALIGN_BOTTOM:
1586 case LyXTabular::M_VALIGN_CENTER:
1588 case LyXTabular::VALIGN_TOP:
1589 case LyXTabular::VALIGN_BOTTOM:
1590 case LyXTabular::VALIGN_CENTER:
1591 for (i = sel_row_start; i <= sel_row_end; ++i)
1592 for (j = sel_col_start; j <= sel_col_end; ++j)
1593 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1595 UpdateLocal(bv, INIT, true);
1597 case LyXTabular::MULTICOLUMN:
1599 if (sel_row_start != sel_row_end) {
1600 WriteAlert(_("Impossible Operation!"),
1601 _("Multicolumns can only be horizontally."),
1605 // just multicol for one Single Cell
1606 if (!hasSelection()) {
1607 // check wether we are completly in a multicol
1608 if (tabular->IsMultiColumn(actcell)) {
1609 tabular->UnsetMultiColumn(actcell);
1610 UpdateLocal(bv, INIT, true);
1612 tabular->SetMultiColumn(actcell, 1);
1613 UpdateLocal(bv, CELL, true);
1617 // we have a selection so this means we just add all this
1618 // cells to form a multicolumn cell
1622 if (sel_cell_start > sel_cell_end) {
1623 s_start = sel_cell_end;
1624 s_end = sel_cell_start;
1626 s_start = sel_cell_start;
1627 s_end = sel_cell_end;
1629 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1631 sel_cell_end = sel_cell_start;
1632 UpdateLocal(bv, INIT, true);
1635 case LyXTabular::SET_ALL_LINES:
1637 case LyXTabular::UNSET_ALL_LINES:
1638 for (i=sel_row_start; i<=sel_row_end; ++i)
1639 for (j=sel_col_start; j<=sel_col_end; ++j)
1640 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1641 UpdateLocal(bv, INIT, true);
1643 case LyXTabular::SET_LONGTABULAR:
1644 tabular->SetLongTabular(true);
1645 UpdateLocal(bv, INIT, true); // because this toggles displayed
1647 case LyXTabular::UNSET_LONGTABULAR:
1648 tabular->SetLongTabular(false);
1649 UpdateLocal(bv, INIT, true); // because this toggles displayed
1651 case LyXTabular::SET_ROTATE_TABULAR:
1652 tabular->SetRotateTabular(true);
1654 case LyXTabular::UNSET_ROTATE_TABULAR:
1655 tabular->SetRotateTabular(false);
1657 case LyXTabular::SET_ROTATE_CELL:
1658 for (i=sel_row_start; i<=sel_row_end; ++i)
1659 for (j=sel_col_start; j<=sel_col_end; ++j)
1660 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1662 case LyXTabular::UNSET_ROTATE_CELL:
1663 for (i = sel_row_start; i <= sel_row_end; ++i)
1664 for (j = sel_col_start; j <= sel_col_end; ++j)
1665 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1667 case LyXTabular::SET_USEBOX:
1669 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1670 if (val == tabular->GetUsebox(actcell))
1671 val = LyXTabular::BOX_NONE;
1672 for (i = sel_row_start; i <= sel_row_end; ++i)
1673 for (j = sel_col_start; j <= sel_col_end; ++j)
1674 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1677 case LyXTabular::SET_LTFIRSTHEAD:
1678 tabular->SetLTHead(actcell, true);
1680 case LyXTabular::SET_LTHEAD:
1681 tabular->SetLTHead(actcell, false);
1683 case LyXTabular::SET_LTFOOT:
1684 tabular->SetLTFoot(actcell, false);
1686 case LyXTabular::SET_LTLASTFOOT:
1687 tabular->SetLTFoot(actcell, true);
1689 case LyXTabular::SET_LTNEWPAGE:
1690 what = !tabular->GetLTNewPage(actcell);
1691 tabular->SetLTNewPage(actcell, what);
1693 // dummy stuff just to avoid warnings
1694 case LyXTabular::LAST_ACTION:
1700 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1703 UpdatableInset * inset =
1704 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1705 LyXFont font(LyXFont::ALL_SANE);
1707 x = inset->x() + inset->width(bv, font);
1708 y = inset->descent(bv, font);
1710 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1711 //inset_y = cursor.y();
1712 inset->Edit(bv, x, y, button);
1713 if (!the_locking_inset)
1715 UpdateLocal(bv, CELL, false);
1716 return (the_locking_inset != 0);
1720 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1723 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1724 inset_y = cursor.y();
1725 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1729 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1731 return x + top_x > cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1735 // This returns paperWidth() if the cell-width is unlimited or the width
1736 // in pixels if we have a pwidth for this cell.
1737 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1739 string const s = tabular->GetPWidth(cell);
1743 return VSpace(s).inPixels(0, 0);
1747 int InsetTabular::getMaxWidth(Painter & pain,
1748 UpdatableInset const * inset) const
1750 int const n = tabular->GetNumberOfCells();
1752 for (; cell < n; ++cell) {
1753 if (tabular->GetCellInset(cell) == inset)
1758 int w = GetMaxWidthOfCell(pain, cell);
1760 // because the inset then subtracts it's top_x and owner->x()
1761 w += (inset->x() - top_x);
1766 void InsetTabular::resizeLyXText(BufferView *) const
1772 LyXText * InsetTabular::getLyXText(BufferView const * bv) const
1774 if (the_locking_inset)
1775 return the_locking_inset->getLyXText(bv);
1776 return Inset::getLyXText(bv);
1780 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1782 if (the_locking_inset) {
1783 InsetTabular * i = static_cast<InsetTabular *>
1784 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1786 i->OpenLayoutDialog(bv);
1790 bv->owner()->getDialogs()->showTabular(const_cast<InsetTabular *>(this));
1794 // functions returns:
1798 // 3 ... toggled off
1800 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1802 int action = LyXTabular::LAST_ACTION;
1803 LyXFunc::func_status status = LyXFunc::OK;
1806 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1807 string const tmp = tabularFeatures[i].feature;
1808 if (tmp == what.substr(0, tmp.length())) {
1809 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1810 // tabularFeatures[i].feature.length())) {
1811 action = tabularFeatures[i].action;
1815 if (action == LyXTabular::LAST_ACTION)
1816 return LyXFunc::Unknown;
1818 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1825 if (hasSelection()) {
1826 sel_row_start = tabular->row_of_cell(sel_cell_start);
1827 sel_row_end = tabular->row_of_cell(sel_cell_end);
1828 if (sel_row_start > sel_row_end) {
1829 //int tmp = sel_row_start;
1830 //sel_row_start = sel_row_end;
1831 //sel_row_end = tmp;
1832 swap(sel_row_start, sel_row_end);
1835 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1839 case LyXTabular::SET_PWIDTH:
1840 case LyXTabular::SET_MPWIDTH:
1841 case LyXTabular::SET_SPECIAL_COLUMN:
1842 case LyXTabular::SET_SPECIAL_MULTI:
1843 status |= LyXFunc::Disabled;
1846 case LyXTabular::APPEND_ROW:
1847 case LyXTabular::APPEND_COLUMN:
1848 case LyXTabular::DELETE_ROW:
1849 case LyXTabular::DELETE_COLUMN:
1850 case LyXTabular::SET_ALL_LINES:
1851 case LyXTabular::UNSET_ALL_LINES:
1852 status |= LyXFunc::OK;
1855 case LyXTabular::MULTICOLUMN:
1856 if (tabular->IsMultiColumn(actcell))
1857 status |= LyXFunc::ToggleOn;
1859 status |= LyXFunc::ToggleOff;
1861 case LyXTabular::M_TOGGLE_LINE_TOP:
1863 case LyXTabular::TOGGLE_LINE_TOP:
1864 if (tabular->TopLine(actcell, flag))
1865 status |= LyXFunc::ToggleOn;
1867 status |= LyXFunc::ToggleOff;
1869 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1871 case LyXTabular::TOGGLE_LINE_BOTTOM:
1872 if (tabular->BottomLine(actcell, flag))
1873 status |= LyXFunc::ToggleOn;
1875 status |= LyXFunc::ToggleOff;
1877 case LyXTabular::M_TOGGLE_LINE_LEFT:
1879 case LyXTabular::TOGGLE_LINE_LEFT:
1880 if (tabular->LeftLine(actcell, flag))
1881 status |= LyXFunc::ToggleOn;
1883 status |= LyXFunc::ToggleOff;
1885 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1887 case LyXTabular::TOGGLE_LINE_RIGHT:
1888 if (tabular->RightLine(actcell, flag))
1889 status |= LyXFunc::ToggleOn;
1891 status |= LyXFunc::ToggleOff;
1893 case LyXTabular::M_ALIGN_LEFT:
1895 case LyXTabular::ALIGN_LEFT:
1896 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1897 status |= LyXFunc::ToggleOn;
1899 status |= LyXFunc::ToggleOff;
1901 case LyXTabular::M_ALIGN_RIGHT:
1903 case LyXTabular::ALIGN_RIGHT:
1904 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1905 status |= LyXFunc::ToggleOn;
1907 status |= LyXFunc::ToggleOff;
1909 case LyXTabular::M_ALIGN_CENTER:
1911 case LyXTabular::ALIGN_CENTER:
1912 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1913 status |= LyXFunc::ToggleOn;
1915 status |= LyXFunc::ToggleOff;
1917 case LyXTabular::M_VALIGN_TOP:
1919 case LyXTabular::VALIGN_TOP:
1920 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1921 status |= LyXFunc::ToggleOn;
1923 status |= LyXFunc::ToggleOff;
1925 case LyXTabular::M_VALIGN_BOTTOM:
1927 case LyXTabular::VALIGN_BOTTOM:
1928 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1929 status |= LyXFunc::ToggleOn;
1931 status |= LyXFunc::ToggleOff;
1933 case LyXTabular::M_VALIGN_CENTER:
1935 case LyXTabular::VALIGN_CENTER:
1936 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1937 status |= LyXFunc::ToggleOn;
1939 status |= LyXFunc::ToggleOff;
1941 case LyXTabular::SET_LONGTABULAR:
1942 if (tabular->IsLongTabular())
1943 status |= LyXFunc::ToggleOn;
1945 status |= LyXFunc::ToggleOff;
1947 case LyXTabular::UNSET_LONGTABULAR:
1948 if (!tabular->IsLongTabular())
1949 status |= LyXFunc::ToggleOn;
1951 status |= LyXFunc::ToggleOff;
1953 case LyXTabular::SET_ROTATE_TABULAR:
1954 if (tabular->GetRotateTabular())
1955 status |= LyXFunc::ToggleOn;
1957 status |= LyXFunc::ToggleOff;
1959 case LyXTabular::UNSET_ROTATE_TABULAR:
1960 if (!tabular->GetRotateTabular())
1961 status |= LyXFunc::ToggleOn;
1963 status |= LyXFunc::ToggleOff;
1965 case LyXTabular::SET_ROTATE_CELL:
1966 if (tabular->GetRotateCell(actcell))
1967 status |= LyXFunc::ToggleOn;
1969 status |= LyXFunc::ToggleOff;
1971 case LyXTabular::UNSET_ROTATE_CELL:
1972 if (!tabular->GetRotateCell(actcell))
1973 status |= LyXFunc::ToggleOn;
1975 status |= LyXFunc::ToggleOff;
1977 case LyXTabular::SET_USEBOX:
1978 if (strToInt(argument) == tabular->GetUsebox(actcell))
1979 status |= LyXFunc::ToggleOn;
1981 status |= LyXFunc::ToggleOff;
1983 case LyXTabular::SET_LTFIRSTHEAD:
1984 if (tabular->GetRowOfLTHead(actcell, dummy))
1985 status |= LyXFunc::ToggleOn;
1987 status |= LyXFunc::ToggleOff;
1989 case LyXTabular::SET_LTHEAD:
1990 if (tabular->GetRowOfLTHead(actcell, dummy))
1991 status |= LyXFunc::ToggleOn;
1993 status |= LyXFunc::ToggleOff;
1995 case LyXTabular::SET_LTFOOT:
1996 if (tabular->GetRowOfLTFoot(actcell, dummy))
1997 status |= LyXFunc::ToggleOn;
1999 status |= LyXFunc::ToggleOff;
2001 case LyXTabular::SET_LTLASTFOOT:
2002 if (tabular->GetRowOfLTFoot(actcell, dummy))
2003 status |= LyXFunc::ToggleOn;
2005 status |= LyXFunc::ToggleOff;
2007 case LyXTabular::SET_LTNEWPAGE:
2008 if (tabular->GetLTNewPage(actcell))
2009 status |= LyXFunc::ToggleOn;
2011 status |= LyXFunc::ToggleOff;
2014 status = LyXFunc::Disabled;
2021 bool InsetTabular::copySelection(BufferView * bv)
2023 if (!hasSelection())
2025 delete paste_tabular;
2032 sel_col_start = tabular->column_of_cell(sel_cell_start);
2033 sel_col_end = tabular->column_of_cell(sel_cell_end);
2034 if (sel_col_start > sel_col_end) {
2035 sel_col_start = sel_col_end;
2036 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2038 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2040 int columns = sel_col_end - sel_col_start + 1;
2042 sel_row_start = tabular->row_of_cell(sel_cell_start);
2043 sel_row_end = tabular->row_of_cell(sel_cell_end);
2044 if (sel_row_start > sel_row_end) {
2045 //int tmp tmp = sel_row_start;
2046 //sel_row_start = sel_row_end;
2047 //sel_row_end = tmp;
2048 swap(sel_row_start, sel_row_end);
2050 int rows = sel_row_end - sel_row_start + 1;
2052 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2054 for (i=0; i < sel_row_start; ++i)
2055 paste_tabular->DeleteRow(0);
2056 while(paste_tabular->rows() > rows)
2057 paste_tabular->DeleteRow(rows);
2058 paste_tabular->SetTopLine(0, true, true);
2059 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2061 for (i=0; i < sel_col_start; ++i)
2062 paste_tabular->DeleteColumn(0);
2063 while(paste_tabular->columns() > columns)
2064 paste_tabular->DeleteColumn(columns);
2065 paste_tabular->SetLeftLine(0, true, true);
2066 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
2069 paste_tabular->Ascii(bv->buffer(), sstr);
2070 bv->stuffClipboard(sstr.str().c_str());
2075 bool InsetTabular::pasteSelection(BufferView * bv)
2080 for (int r1 = 0, r2 = actrow;
2081 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2084 for(int c1 = 0, c2 = actcol;
2085 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2088 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2089 tabular->IsPartOfMultiColumn(r2,c2))
2091 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2095 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2099 int n1 = paste_tabular->GetCellNumber(r1, c1);
2100 int n2 = tabular->GetCellNumber(r2, c2);
2101 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2102 tabular->GetCellInset(n2)->setOwner(this);
2103 tabular->GetCellInset(n2)->deleteLyXText(bv);
2110 bool InsetTabular::cutSelection()
2112 if (!hasSelection())
2120 sel_col_start = tabular->column_of_cell(sel_cell_start);
2121 sel_col_end = tabular->column_of_cell(sel_cell_end);
2122 if (sel_col_start > sel_col_end) {
2123 sel_col_start = sel_col_end;
2124 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2126 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2128 sel_row_start = tabular->row_of_cell(sel_cell_start);
2129 sel_row_end = tabular->row_of_cell(sel_cell_end);
2130 if (sel_row_start > sel_row_end) {
2131 //int tmp = sel_row_start;
2132 //sel_row_start = sel_row_end;
2133 //sel_row_end = tmp;
2134 swap(sel_row_start, sel_row_end);
2136 if (sel_cell_start > sel_cell_end) {
2137 //int tmp = sel_cell_start;
2138 //sel_cell_start = sel_cell_end;
2139 //sel_cell_end = tmp;
2140 swap(sel_cell_start, sel_cell_end);
2142 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2143 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2144 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2150 bool InsetTabular::isRightToLeft(BufferView *bv )
2152 return bv->getParentLanguage(this)->RightToLeft();