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"
39 const int ADD_TO_HEIGHT = 2;
40 const int ADD_TO_TABULAR_WIDTH = 2;
42 static LyXTabular * paste_tabular = 0;
43 bool InsetTabular::hasPasteBuffer() const
45 return (paste_tabular != 0);
55 struct tabular_features {
56 LyXTabular::Feature action;
60 //static tabular_features * tabularFeatures = 0;
62 static tabular_features tabularFeatures[] =
64 { LyXTabular::APPEND_ROW, "append-row" },
65 { LyXTabular::APPEND_COLUMN, "append-column" },
66 { LyXTabular::DELETE_ROW, "delete-row" },
67 { LyXTabular::DELETE_COLUMN, "delete-column" },
68 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
69 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
70 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
71 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
72 { LyXTabular::ALIGN_LEFT, "align-left" },
73 { LyXTabular::ALIGN_RIGHT, "align-right" },
74 { LyXTabular::ALIGN_CENTER, "align-center" },
75 { LyXTabular::VALIGN_TOP, "valign-top" },
76 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
77 { LyXTabular::VALIGN_CENTER, "valign-center" },
78 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
79 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
80 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
81 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
82 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
83 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
84 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
85 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
86 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
87 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
88 { LyXTabular::MULTICOLUMN, "multicolumn" },
89 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
90 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
91 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
92 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
93 { LyXTabular::SET_PWIDTH, "set-pwidth" },
94 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
95 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
96 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
97 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
98 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
99 { LyXTabular::SET_USEBOX, "set-usebox" },
100 { LyXTabular::SET_LTHEAD, "set-lthead" },
101 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
102 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
103 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
104 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
105 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
106 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
107 { LyXTabular::LAST_ACTION, "" }
112 bool cellstart(LyXParagraph::size_type p)
114 return ((p % 2) == 0);
118 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
125 tabular = new LyXTabular(this, rows,columns);
126 // for now make it always display as display() inset
128 the_locking_inset = 0;
129 locked = no_selection = cursor_visible = false;
134 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
139 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
142 tabular = new LyXTabular(this, *(tab.tabular));
143 the_locking_inset = 0;
144 locked = no_selection = cursor_visible = false;
149 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
154 InsetTabular::~InsetTabular()
161 Inset * InsetTabular::Clone(Buffer const & buf) const
163 InsetTabular * t = new InsetTabular(*this, buf);
165 t->tabular = tabular->Clone(t);
170 void InsetTabular::Write(Buffer const * buf, ostream & os) const
172 os << " Tabular" << endl;
173 tabular->Write(buf, os);
177 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
179 bool old_format = (lex.GetString() == "\\LyXTable");
184 tabular = new LyXTabular(buf, this, lex);
192 token = lex.GetString();
193 while (lex.IsOK() && (token != "\\end_inset")) {
195 token = lex.GetString();
197 if (token != "\\end_inset") {
198 lex.printError("Missing \\end_inset at this point. "
204 int InsetTabular::ascent(BufferView *, LyXFont const &) const
206 return tabular->GetAscentOfRow(0);
210 int InsetTabular::descent(BufferView *, LyXFont const &) const
212 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
216 int InsetTabular::width(BufferView *, LyXFont const &) const
218 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
222 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
223 float & x, bool cleared) const
225 Painter & pain = bv->painter();
230 UpdatableInset::draw(bv, font, baseline, x, cleared);
231 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
232 (top_x != int(x)) || (top_baseline != baseline))) {
233 int h = ascent(bv, font) + descent(bv, font);
234 int tx = display() || !owner() ? 0 : top_x;
235 int w = tx ? width(bv, font) : pain.paperWidth();
236 int ty = baseline - ascent(bv, font);
240 if ((ty + h) > pain.paperHeight())
241 h = pain.paperHeight();
242 if ((top_x + w) > pain.paperWidth())
243 w = pain.paperWidth();
244 pain.fillRectangle(tx, ty, w, h);
249 top_baseline = baseline;
250 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
253 x += ADD_TO_TABULAR_WIDTH;
255 for(i = 0; i < tabular->rows(); ++i) {
257 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
258 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
259 for(j = 0; j < tabular->columns(); ++j) {
260 if (tabular->IsPartOfMultiColumn(i, j))
262 cx = nx + tabular->GetBeginningOfTextInCell(cell);
265 DrawCellSelection(pain, nx, baseline, i, j, cell);
266 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
268 DrawCellLines(pain, nx, baseline, i, cell);
270 nx += tabular->GetWidthOfColumn(cell);
273 baseline += tabular->GetDescentOfRow(i) +
274 tabular->GetAscentOfRow(i + 1) +
275 tabular->GetAdditionalHeight(cell);
277 } else if (need_update == CELL) {
279 for(i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
280 for(j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
281 if (tabular->IsPartOfMultiColumn(i, j))
283 nx += tabular->GetWidthOfColumn(cell);
286 if (tabular->row_of_cell(cell) > i) {
288 baseline += tabular->GetDescentOfRow(i) +
289 tabular->GetAscentOfRow(i + 1) +
290 tabular->GetAdditionalHeight(cell);
293 if (the_locking_inset == tabular->GetCellInset(cell)) {
294 LyXText::text_status st = bv->text->status;
296 cx = nx + tabular->GetBeginningOfTextInCell(cell);
297 bv->text->status = st;
298 if (need_update == CELL) {
299 // clear before the inset
302 baseline - tabular->GetAscentOfRow(i) + 1,
304 tabular->GetAscentOfRow(i) +
305 tabular->GetDescentOfRow(i) - 1);
306 // clear behind the inset
308 int(cx + the_locking_inset->width(bv,font) + 1),
309 baseline - tabular->GetAscentOfRow(i) + 1,
310 tabular->GetWidthOfColumn(cell) -
311 tabular->GetBeginningOfTextInCell(cell) -
312 the_locking_inset->width(bv,font) - 1,
313 tabular->GetAscentOfRow(i) +
314 tabular->GetDescentOfRow(i) - 1);
316 tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
317 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
320 x -= ADD_TO_TABULAR_WIDTH;
321 x += width(bv, font);
322 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
329 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
330 int row, int cell) const
332 int x2 = x + tabular->GetWidthOfColumn(cell);
335 if (!tabular->TopAlreadyDrawed(cell)) {
336 on_off = !tabular->TopLine(cell);
337 pain.line(x, baseline - tabular->GetAscentOfRow(row),
338 x2, baseline - tabular->GetAscentOfRow(row),
339 on_off ? LColor::tabularonoffline : LColor::tabularline,
340 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 on_off = !tabular->BottomLine(cell);
343 pain.line(x,baseline + tabular->GetDescentOfRow(row),
344 x2, baseline + tabular->GetDescentOfRow(row),
345 on_off ? LColor::tabularonoffline : LColor::tabularline,
346 on_off ? Painter::line_onoffdash : Painter::line_solid);
347 if (!tabular->LeftAlreadyDrawed(cell)) {
348 on_off = !tabular->LeftLine(cell);
349 pain.line(x, baseline - tabular->GetAscentOfRow(row),
350 x, baseline + tabular->GetDescentOfRow(row),
351 on_off ? LColor::tabularonoffline : LColor::tabularline,
352 on_off ? Painter::line_onoffdash : Painter::line_solid);
354 on_off = !tabular->RightLine(cell);
355 pain.line(x2 - tabular->GetAdditionalWidth(cell),
356 baseline - tabular->GetAscentOfRow(row),
357 x2 - tabular->GetAdditionalWidth(cell),
358 baseline + tabular->GetDescentOfRow(row),
359 on_off ? LColor::tabularonoffline : LColor::tabularline,
360 on_off ? Painter::line_onoffdash : Painter::line_solid);
364 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
365 int row, int column, int cell) const
367 int cs = tabular->column_of_cell(sel_cell_start);
368 int ce = tabular->column_of_cell(sel_cell_end);
371 cs = tabular->column_of_cell(sel_cell_end);
373 ce = tabular->right_column_of_cell(sel_cell_end);
376 int rs = tabular->row_of_cell(sel_cell_start);
377 int re = tabular->row_of_cell(sel_cell_end);
378 if (rs > re) swap(rs, re);
380 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
381 int w = tabular->GetWidthOfColumn(cell);
382 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
383 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
384 w, h, LColor::selection);
389 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
393 calculate_dimensions_of_cells(bv, font, true);
395 owner()->update(bv, font, true);
398 if (the_locking_inset) {
399 the_locking_inset->update(bv, font, reinit);
401 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
402 // inset_y = cursor.y();
404 switch(need_update) {
408 if (calculate_dimensions_of_cells(bv, font, false))
420 string const InsetTabular::EditMessage() const
422 return _("Opened Tabular Inset");
426 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
428 UpdatableInset::Edit(bv, x, y, button);
430 if (!bv->lockInset(this)) {
431 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
435 the_locking_inset = 0;
440 sel_pos_start = sel_pos_end = cursor.pos();
441 sel_cell_start = sel_cell_end = actcell;
442 bv->text->FinishUndo();
443 if (InsetHit(bv, x, y)) {
444 ActivateCellInset(bv, x, y, button);
446 UpdateLocal(bv, NONE, false);
447 // bv->getOwner()->getPopups().updateFormTabular();
451 void InsetTabular::InsetUnlock(BufferView * bv)
453 if (the_locking_inset) {
454 the_locking_inset->InsetUnlock(bv);
455 the_locking_inset = 0;
458 no_selection = false;
461 if (scroll() || hasSelection()) {
465 sel_pos_start = sel_pos_end = 0;
466 sel_cell_start = sel_cell_end = 0;
468 UpdateLocal(bv, FULL, false);
473 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
474 bool mark_dirty) const
478 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
479 if (locked && (what != NONE))
484 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
486 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
490 if (inset == tabular->GetCellInset(actcell)) {
491 lyxerr[Debug::INSETS] << "OK" << endl;
492 the_locking_inset = tabular->GetCellInset(actcell);
494 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
495 inset_y = cursor.y();
496 inset_pos = cursor.pos();
498 } else if (the_locking_inset && (the_locking_inset == inset)) {
499 if (cursor.pos() == inset_pos) {
500 lyxerr[Debug::INSETS] << "OK" << endl;
502 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
503 inset_y = cursor.y();
505 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
507 } else if (the_locking_inset) {
508 lyxerr[Debug::INSETS] << "MAYBE" << endl;
509 return the_locking_inset->LockInsetInInset(bv, inset);
511 lyxerr[Debug::INSETS] << "NOT OK" << endl;
516 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
519 if (!the_locking_inset)
521 if (the_locking_inset == inset) {
522 the_locking_inset->InsetUnlock(bv);
523 the_locking_inset = 0;
525 moveRight(bv, false);
526 ShowInsetCursor(bv, false);
527 UpdateLocal(bv, CELL, false);
530 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
531 if (inset->LyxCode() == TABULAR_CODE &&
532 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
534 bv->owner()->getDialogs()->updateTabular(this);
543 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
545 if (!the_locking_inset)
547 if (the_locking_inset != inset)
548 return the_locking_inset->UpdateInsetInInset(bv, inset);
549 UpdateLocal(bv, CELL, false);
554 unsigned int InsetTabular::InsetInInsetY()
556 if (!the_locking_inset)
559 return (inset_y + the_locking_inset->InsetInInsetY());
563 UpdatableInset * InsetTabular::GetLockingInset()
565 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
569 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
573 if (the_locking_inset)
574 return the_locking_inset->GetFirstLockingInsetOfType(c);
579 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
581 if (the_locking_inset)
582 return the_locking_inset->InsertInset(bv, inset);
587 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
589 if (hasSelection()) {
590 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
591 UpdateLocal(bv, SELECTION, false);
593 no_selection = false;
595 int const ocell = actcell;
596 int const orow = actrow;
601 UpdateLocal(bv, NONE, false);
602 sel_pos_start = sel_pos_end = cursor.pos();
603 sel_cell_start = sel_cell_end = actcell;
605 bool const inset_hit = InsetHit(bv, x, y);
607 if ((ocell == actcell) && the_locking_inset && inset_hit) {
608 cursor.pos(0); // always before the inset!
610 the_locking_inset->InsetButtonPress(bv,
611 x - inset_x, y - inset_y, button);
613 } else if (the_locking_inset) {
614 the_locking_inset->InsetUnlock(bv);
616 the_locking_inset = 0;
617 if (inset_hit && bv->theLockingInset()) {
618 if (ActivateCellInset(bv, x, y, button))
619 the_locking_inset->InsetButtonPress(bv, x - inset_x,
620 y - inset_y, button);
627 void InsetTabular::InsetButtonRelease(BufferView * bv,
628 int x, int y, int button)
631 if (the_locking_inset) {
633 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
634 i->InsetButtonRelease(bv, x, y, button);
638 bv->owner()->getDialogs()->showTabular(this);
641 if (the_locking_inset) {
642 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
645 no_selection = false;
649 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
651 if (the_locking_inset) {
652 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
653 y - inset_y, button);
658 LyXParagraph::size_type const old_pos = sel_pos_end;
659 int const old_cell = actcell;
662 sel_pos_end = cursor.pos();
663 sel_cell_end = actcell;
664 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
665 UpdateLocal(bv, SELECTION, false);
668 no_selection = false;
672 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
674 if (the_locking_inset) {
675 the_locking_inset->InsetKeyPress(xke);
681 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
684 UpdatableInset::RESULT
687 no_selection = false;
688 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
689 || (result == DISPATCHED_NOUPDATE)) {
695 if ((action < 0) && arg.empty())
698 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
699 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
701 if (the_locking_inset) {
702 result=the_locking_inset->LocalDispatch(bv, action, arg);
703 if (result == DISPATCHED_NOUPDATE)
705 else if (result == DISPATCHED) {
706 the_locking_inset->ToggleInsetCursor(bv);
707 UpdateLocal(bv, CELL, false);
708 the_locking_inset->ToggleInsetCursor(bv);
710 } else if (result == FINISHED) {
711 if ((action == LFUN_RIGHT) || (action == -1)) {
712 cursor.pos(inset_pos + 1);
715 sel_pos_start = sel_pos_end = cursor.pos();
716 sel_cell_start = sel_cell_end = actcell;
724 bool hs = hasSelection();
728 // --- Cursor Movements ---------------------------------------------
730 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
732 moveRight(bv, false);
734 if (!cellstart(cursor.pos())) {
735 sel_pos_end = cursor.pos();
736 if (tabular->right_column_of_cell(sel_cell_start) >
737 tabular->right_column_of_cell(actcell))
738 sel_cell_end = actcell+1;
740 sel_cell_end = actcell;
743 sel_pos_end = cursor.pos();
744 sel_cell_end = actcell;
746 UpdateLocal(bv, SELECTION, false);
749 result = moveRight(bv);
750 sel_pos_start = sel_pos_end = cursor.pos();
751 sel_cell_start = sel_cell_end = actcell;
753 UpdateLocal(bv, SELECTION, false);
756 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
760 if (cellstart(cursor.pos())) {
761 sel_pos_end = cursor.pos();
762 if (tabular->column_of_cell(sel_cell_start) >=
763 tabular->column_of_cell(actcell))
764 sel_cell_end = actcell;
766 sel_cell_end = actcell-1;
769 sel_pos_end = cursor.pos();
770 sel_cell_end = actcell;
772 UpdateLocal(bv, SELECTION, false);
775 result = moveLeft(bv);
776 sel_pos_start = sel_pos_end = cursor.pos();
777 sel_cell_start = sel_cell_end = actcell;
779 UpdateLocal(bv, SELECTION, false);
783 int const ocell = actcell;
785 sel_pos_end = cursor.pos();
786 if ((ocell == sel_cell_end) ||
787 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
788 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
790 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
791 UpdateLocal(bv, SELECTION, false);
795 result = moveDown(bv);
796 sel_pos_start = sel_pos_end = cursor.pos();
797 sel_cell_start = sel_cell_end = actcell;
799 UpdateLocal(bv, SELECTION, false);
803 int const ocell = actcell;
805 sel_pos_end = cursor.pos();
806 if ((ocell == sel_cell_end) ||
807 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
808 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
810 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
811 UpdateLocal(bv, SELECTION, false);
816 sel_pos_start = sel_pos_end = cursor.pos();
817 sel_cell_start = sel_cell_end = actcell;
819 UpdateLocal(bv, SELECTION, false);
831 if (the_locking_inset) {
832 UnlockInsetInInset(bv, the_locking_inset);
833 the_locking_inset = 0;
835 if (action == LFUN_TAB)
839 sel_pos_start = sel_pos_end = cursor.pos();
840 sel_cell_start = sel_cell_end = actcell;
842 UpdateLocal(bv, SELECTION, false);
844 case LFUN_LAYOUT_TABULAR:
846 bv->owner()->getDialogs()->showTabular(this);
849 case LFUN_TABULAR_FEATURE:
850 if (!TabularFeatures(bv, arg))
851 result = UNDISPATCHED;
854 if (!copySelection(bv))
856 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
858 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
859 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
861 bv->text->cursor.par()->previous,
862 bv->text->cursor.par()->next
866 UpdateLocal(bv, INIT, true);
871 bv->text->FinishUndo();
875 if (!hasPasteBuffer())
877 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
879 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
880 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
882 bv->text->cursor.par()->previous,
883 bv->text->cursor.par()->next
887 UpdateLocal(bv, INIT, true);
890 // we try to activate the actual inset and put this event down to
891 // the insets dispatch function.
892 result = UNDISPATCHED;
893 if (the_locking_inset)
895 if (ActivateCellInset(bv, 0, 0, 0, !cellstart(cursor.pos()))) {
896 result=the_locking_inset->LocalDispatch(bv, action, arg);
897 if (result == DISPATCHED_NOUPDATE)
899 else if (result == DISPATCHED) {
900 the_locking_inset->ToggleInsetCursor(bv);
901 UpdateLocal(bv, CELL, false);
902 the_locking_inset->ToggleInsetCursor(bv);
905 result = UNDISPATCHED;
910 if (result!=FINISHED) {
911 if (!the_locking_inset) {
915 bv->unlockInset(this);
920 int InsetTabular::Latex(Buffer const * buf, ostream & os,
921 bool fragile, bool fp) const
923 return tabular->Latex(buf, os, fragile, fp);
927 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
929 // This should be changed to a real ascii export
930 return tabular->Ascii(buf, os);
934 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
940 int InsetTabular::DocBook(Buffer const *, ostream &) const
946 void InsetTabular::Validate(LaTeXFeatures & features) const
948 tabular->Validate(features);
952 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
953 LyXFont const & font,
959 bool changed = false;
961 for(int i = 0; i < tabular->rows(); ++i) {
962 maxAsc = maxDesc = 0;
963 for(int j= 0; j < tabular->columns(); ++j) {
964 if (tabular->IsPartOfMultiColumn(i,j))
967 inset = tabular->GetCellInset(cell);
969 inset->update(bv, font, false);
970 maxAsc = max(maxAsc, inset->ascent(bv, font));
971 maxDesc = max(maxDesc, inset->descent(bv, font));
972 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
974 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
975 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
981 void InsetTabular::GetCursorPos(BufferView *,
982 int & x, int & y) const
984 x = cursor.x() - top_x;
989 void InsetTabular::ToggleInsetCursor(BufferView * bv)
991 if (the_locking_inset) {
992 the_locking_inset->ToggleInsetCursor(bv);
996 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
998 int const asc = lyxfont::maxAscent(font);
999 int const desc = lyxfont::maxDescent(font);
1002 bv->hideLockedInsetCursor();
1004 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1005 cursor_visible = !cursor_visible;
1009 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1011 if (!cursor_visible) {
1012 LyXFont font; // = GetFont(par, cursor.pos);
1014 int const asc = lyxfont::maxAscent(font);
1015 int const desc = lyxfont::maxDescent(font);
1016 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1018 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1019 cursor_visible = true;
1024 void InsetTabular::HideInsetCursor(BufferView * bv)
1026 if (cursor_visible) {
1027 bv->hideLockedInsetCursor();
1028 cursor_visible = false;
1030 // if (cursor_visible)
1031 // ToggleInsetCursor(bv);
1035 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1040 actcell = actrow = actcol = 0;
1041 int ly = tabular->GetDescentOfRow(actrow);
1043 // first search the right row
1044 while((ly < y) && (actrow < tabular->rows())) {
1045 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1046 tabular->GetAscentOfRow(actrow + 1) +
1047 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1050 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1052 actcell = tabular->GetCellNumber(actrow, actcol);
1054 // now search the right column
1055 int lx = tabular->GetWidthOfColumn(actcell) -
1056 tabular->GetAdditionalWidth(actcell);
1057 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1059 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1060 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1061 tabular->GetAdditionalWidth(actcell - 1));
1063 // Jürgen, you should check that this is correct. (Lgb)
1064 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1065 lx += tabular->GetWidthOfColumn(actcell + 1)
1066 + tabular->GetAdditionalWidth(actcell);
1072 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1073 cursor.x(lx + top_x - 2);
1076 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1082 int InsetTabular::getCellXPos(int cell) const
1086 for(; !tabular->IsFirstCellInRow(c); --c)
1088 int lx = tabular->GetWidthOfColumn(cell);
1089 for(; c < cell; ++c) {
1090 lx += tabular->GetWidthOfColumn(c);
1092 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1096 void InsetTabular::resetPos(BufferView * bv) const
1100 actcol = tabular->column_of_cell(actcell);
1105 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1106 if (tabular->IsLastCellInRow(cell)) {
1107 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1108 tabular->GetAscentOfRow(actrow + 1) +
1109 tabular->GetAdditionalHeight(cell + 1));
1113 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1114 cursor.x(getCellXPos(actcell) + offset);
1115 if (((cursor.x() - offset) > 20) &&
1116 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1117 (bv->workWidth()-20)))
1119 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1120 UpdateLocal(bv, FULL, false);
1121 } else if ((cursor.x() - offset) < 20) {
1122 scroll(bv, 20 - cursor.x() + offset);
1123 UpdateLocal(bv, FULL, false);
1124 } else if (!cellstart(cursor.pos())) {
1125 LyXFont font(LyXFont::ALL_SANE);
1126 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1127 tabular->GetBeginningOfTextInCell(actcell));
1129 if ((!the_locking_inset ||
1130 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1131 (actcell != oldcell)) {
1132 InsetTabular * inset = const_cast<InsetTabular *>(this);
1133 bv->owner()->getDialogs()->updateTabular(inset);
1139 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1141 if (!cellstart(cursor.pos())) {
1142 if (tabular->IsLastCell(actcell))
1147 if (ActivateCellInset(bv))
1149 } else { // before the inset
1153 return DISPATCHED_NOUPDATE;
1157 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1159 if (cellstart(cursor.pos()) && !actcell)
1161 if (cellstart(cursor.pos())) {
1164 } else if (lock) { // behind the inset
1166 if (ActivateCellInset(bv, 0, 0, 0, true))
1172 return DISPATCHED_NOUPDATE;
1176 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1178 int const ocell = actcell;
1179 actcell = tabular->GetCellAbove(actcell);
1180 if (actcell == ocell) // we moved out of the inset
1183 return DISPATCHED_NOUPDATE;
1187 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1189 int const ocell = actcell;
1190 actcell = tabular->GetCellBelow(actcell);
1191 if (actcell == ocell) // we moved out of the inset
1194 return DISPATCHED_NOUPDATE;
1198 bool InsetTabular::moveNextCell(BufferView * bv)
1200 if (tabular->IsLastCell(actcell))
1208 bool InsetTabular::movePrevCell(BufferView * bv)
1210 if (!actcell) // first cell
1218 bool InsetTabular::Delete()
1224 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1226 if (the_locking_inset)
1227 the_locking_inset->SetFont(bv, font, tall);
1231 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1233 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1236 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1237 string const tmp = tabularFeatures[i].feature;
1239 if (tmp == what.substr(0, tmp.length())) {
1240 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1241 //tabularFeatures[i].feature.length())) {
1242 action = tabularFeatures[i].action;
1246 if (action == LyXTabular::LAST_ACTION)
1250 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1251 TabularFeatures(bv, action, val);
1256 void InsetTabular::TabularFeatures(BufferView * bv,
1257 LyXTabular::Feature feature,
1258 string const & value)
1267 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1268 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1273 case LyXTabular::M_ALIGN_LEFT:
1274 case LyXTabular::ALIGN_LEFT:
1275 setAlign=LYX_ALIGN_LEFT;
1277 case LyXTabular::M_ALIGN_RIGHT:
1278 case LyXTabular::ALIGN_RIGHT:
1279 setAlign=LYX_ALIGN_RIGHT;
1281 case LyXTabular::M_ALIGN_CENTER:
1282 case LyXTabular::ALIGN_CENTER:
1283 setAlign=LYX_ALIGN_CENTER;
1285 case LyXTabular::M_VALIGN_TOP:
1286 case LyXTabular::VALIGN_TOP:
1287 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1289 case LyXTabular::M_VALIGN_BOTTOM:
1290 case LyXTabular::VALIGN_BOTTOM:
1291 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1293 case LyXTabular::M_VALIGN_CENTER:
1294 case LyXTabular::VALIGN_CENTER:
1295 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1300 if (hasSelection()) {
1301 sel_col_start = tabular->column_of_cell(sel_cell_start);
1302 sel_col_end = tabular->column_of_cell(sel_cell_end);
1303 if (sel_col_start > sel_col_end) {
1304 sel_col_end = sel_col_start;
1305 sel_col_start = tabular->column_of_cell(sel_cell_end);
1307 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1310 sel_row_start = tabular->row_of_cell(sel_cell_start);
1311 sel_row_end = tabular->row_of_cell(sel_cell_end);
1312 if (sel_row_start > sel_row_end) {
1313 //int tmp = sel_row_start;
1314 //sel_row_start = sel_row_end;
1315 //sel_row_end = tmp;
1316 swap(sel_row_start, sel_row_end);
1319 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1320 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1322 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1324 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1325 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1327 bv->text->cursor.par()->previous,
1328 bv->text->cursor.par()->next
1332 int row = tabular->row_of_cell(actcell);
1333 int column = tabular->column_of_cell(actcell);
1337 case LyXTabular::SET_PWIDTH:
1339 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1340 tabular->SetColumnPWidth(actcell,value);
1342 for (int i=0; i < tabular->rows(); ++i) {
1343 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1346 UpdateLocal(bv, INIT, true);
1350 case LyXTabular::SET_MPWIDTH:
1352 bool const update = (tabular->GetPWidth(actcell) != value);
1353 tabular->SetMColumnPWidth(actcell,value);
1355 for (int i=0; i < tabular->rows(); ++i) {
1356 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1359 UpdateLocal(bv, INIT, true);
1363 case LyXTabular::SET_SPECIAL_COLUMN:
1364 case LyXTabular::SET_SPECIAL_MULTI:
1365 tabular->SetAlignSpecial(actcell,value,feature);
1367 case LyXTabular::APPEND_ROW:
1368 // append the row into the tabular
1369 UnlockInsetInInset(bv, the_locking_inset);
1370 tabular->AppendRow(actcell);
1371 UpdateLocal(bv, INIT, true);
1373 case LyXTabular::APPEND_COLUMN:
1374 // append the column into the tabular
1375 tabular->AppendColumn(actcell);
1376 actcell = tabular->GetCellNumber(row, column);
1377 UpdateLocal(bv, INIT, true);
1379 case LyXTabular::DELETE_ROW:
1380 tabular->DeleteRow(tabular->row_of_cell(actcell));
1381 if ((row+1) > tabular->rows())
1383 actcell = tabular->GetCellNumber(row, column);
1384 UpdateLocal(bv, INIT, true);
1386 case LyXTabular::DELETE_COLUMN:
1387 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1388 if ((column+1) > tabular->columns())
1390 actcell = tabular->GetCellNumber(row, column);
1391 UpdateLocal(bv, INIT, true);
1393 case LyXTabular::M_TOGGLE_LINE_TOP:
1395 case LyXTabular::TOGGLE_LINE_TOP:
1396 lineSet = !tabular->TopLine(actcell, flag);
1397 for(i=sel_row_start; i<=sel_row_end; ++i)
1398 for(j=sel_col_start; j<=sel_col_end; ++j)
1399 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1400 UpdateLocal(bv, INIT, true);
1403 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1405 case LyXTabular::TOGGLE_LINE_BOTTOM:
1406 lineSet = !tabular->BottomLine(actcell, flag);
1407 for(i=sel_row_start; i<=sel_row_end; ++i)
1408 for(j=sel_col_start; j<=sel_col_end; ++j)
1409 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1411 UpdateLocal(bv, INIT, true);
1414 case LyXTabular::M_TOGGLE_LINE_LEFT:
1416 case LyXTabular::TOGGLE_LINE_LEFT:
1417 lineSet = !tabular->LeftLine(actcell, flag);
1418 for(i=sel_row_start; i<=sel_row_end; ++i)
1419 for(j=sel_col_start; j<=sel_col_end; ++j)
1420 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1422 UpdateLocal(bv, INIT, true);
1425 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1427 case LyXTabular::TOGGLE_LINE_RIGHT:
1428 lineSet = !tabular->RightLine(actcell, flag);
1429 for(i=sel_row_start; i<=sel_row_end; ++i)
1430 for(j=sel_col_start; j<=sel_col_end; ++j)
1431 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1433 UpdateLocal(bv, INIT, true);
1435 case LyXTabular::M_ALIGN_LEFT:
1436 case LyXTabular::M_ALIGN_RIGHT:
1437 case LyXTabular::M_ALIGN_CENTER:
1439 case LyXTabular::ALIGN_LEFT:
1440 case LyXTabular::ALIGN_RIGHT:
1441 case LyXTabular::ALIGN_CENTER:
1442 for(i = sel_row_start; i <= sel_row_end; ++i)
1443 for(j = sel_col_start; j <= sel_col_end; ++j)
1444 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1447 UpdateLocal(bv, INIT, true);
1449 UpdateLocal(bv, CELL, true);
1451 case LyXTabular::M_VALIGN_TOP:
1452 case LyXTabular::M_VALIGN_BOTTOM:
1453 case LyXTabular::M_VALIGN_CENTER:
1455 case LyXTabular::VALIGN_TOP:
1456 case LyXTabular::VALIGN_BOTTOM:
1457 case LyXTabular::VALIGN_CENTER:
1458 for(i = sel_row_start; i <= sel_row_end; ++i)
1459 for(j = sel_col_start; j <= sel_col_end; ++j)
1460 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1463 UpdateLocal(bv, INIT, true);
1465 UpdateLocal(bv, CELL, true);
1467 case LyXTabular::MULTICOLUMN:
1469 if (sel_row_start != sel_row_end) {
1470 WriteAlert(_("Impossible Operation!"),
1471 _("Multicolumns can only be horizontally."),
1475 // just multicol for one Single Cell
1476 if (!hasSelection()) {
1477 // check wether we are completly in a multicol
1478 if (tabular->IsMultiColumn(actcell)) {
1479 tabular->UnsetMultiColumn(actcell);
1480 UpdateLocal(bv, INIT, true);
1482 tabular->SetMultiColumn(actcell, 1);
1483 UpdateLocal(bv, CELL, true);
1487 // we have a selection so this means we just add all this
1488 // cells to form a multicolumn cell
1492 if (sel_cell_start > sel_cell_end) {
1493 s_start = sel_cell_end;
1494 s_end = sel_cell_start;
1496 s_start = sel_cell_start;
1497 s_end = sel_cell_end;
1499 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1502 sel_cell_end = sel_cell_start;
1503 sel_pos_end = sel_pos_start;
1504 UpdateLocal(bv, INIT, true);
1507 case LyXTabular::SET_ALL_LINES:
1509 case LyXTabular::UNSET_ALL_LINES:
1510 for(i=sel_row_start; i<=sel_row_end; ++i)
1511 for(j=sel_col_start; j<=sel_col_end; ++j)
1512 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1513 UpdateLocal(bv, INIT, true);
1515 case LyXTabular::SET_LONGTABULAR:
1516 tabular->SetLongTabular(true);
1517 UpdateLocal(bv, INIT, true); // because this toggles displayed
1519 case LyXTabular::UNSET_LONGTABULAR:
1520 tabular->SetLongTabular(false);
1521 UpdateLocal(bv, INIT, true); // because this toggles displayed
1523 case LyXTabular::SET_ROTATE_TABULAR:
1524 tabular->SetRotateTabular(true);
1526 case LyXTabular::UNSET_ROTATE_TABULAR:
1527 tabular->SetRotateTabular(false);
1529 case LyXTabular::SET_ROTATE_CELL:
1530 for(i=sel_row_start; i<=sel_row_end; ++i)
1531 for(j=sel_col_start; j<=sel_col_end; ++j)
1532 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1534 case LyXTabular::UNSET_ROTATE_CELL:
1535 for(i = sel_row_start; i <= sel_row_end; ++i)
1536 for(j = sel_col_start; j <= sel_col_end; ++j)
1537 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1539 case LyXTabular::SET_USEBOX:
1541 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1542 if (val == tabular->GetUsebox(actcell))
1543 val = LyXTabular::BOX_NONE;
1544 for(i = sel_row_start; i <= sel_row_end; ++i)
1545 for(j = sel_col_start; j <= sel_col_end; ++j)
1546 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1549 case LyXTabular::SET_LTFIRSTHEAD:
1550 tabular->SetLTHead(actcell, true);
1552 case LyXTabular::SET_LTHEAD:
1553 tabular->SetLTHead(actcell, false);
1555 case LyXTabular::SET_LTFOOT:
1556 tabular->SetLTFoot(actcell, false);
1558 case LyXTabular::SET_LTLASTFOOT:
1559 tabular->SetLTFoot(actcell, true);
1561 case LyXTabular::SET_LTNEWPAGE:
1562 what = !tabular->GetLTNewPage(actcell);
1563 tabular->SetLTNewPage(actcell, what);
1565 // dummy stuff just to avoid warnings
1566 case LyXTabular::LAST_ACTION:
1572 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1575 // the cursor.pos has to be before the inset so if it isn't now just
1576 // reset the curor pos first!
1577 if (!cellstart(cursor.pos())) {
1581 UpdatableInset * inset =
1582 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1583 LyXFont font(LyXFont::ALL_SANE);
1585 x = inset->x() + inset->width(bv, font);
1586 y = inset->descent(bv, font);
1588 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1589 inset_y = cursor.y();
1590 inset->Edit(bv, x, y - inset_y, button);
1591 if (!the_locking_inset)
1593 UpdateLocal(bv, CELL, false);
1594 return (the_locking_inset != 0);
1598 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1600 InsetText * inset = tabular->GetCellInset(actcell);
1603 if (!cellstart(cursor.pos())) {
1604 return (((x + top_x) < cursor.x()) &&
1605 ((x + top_x) > (cursor.x() - inset->width(bv,
1606 LyXFont(LyXFont::ALL_SANE)))));
1608 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1609 return ((x1 > x2) &&
1610 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1615 // This returns paperWidth() if the cell-width is unlimited or the width
1616 // in pixels if we have a pwidth for this cell.
1617 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1619 string const s = tabular->GetPWidth(cell);
1623 return VSpace(s).inPixels(0, 0);
1627 int InsetTabular::getMaxWidth(Painter & pain,
1628 UpdatableInset const * inset) const
1630 int const n = tabular->GetNumberOfCells();
1632 for(; cell < n; ++cell) {
1633 if (tabular->GetCellInset(cell) == inset)
1638 int w = GetMaxWidthOfCell(pain, cell);
1640 // because the inset then subtracts it's top_x and owner->x()
1641 w += (inset->x() - top_x);
1646 void InsetTabular::resizeLyXText(BufferView *) const
1652 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1654 if (the_locking_inset)
1655 return the_locking_inset->getLyXText(bv);
1656 return Inset::getLyXText(bv);
1660 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1662 if (the_locking_inset) {
1663 InsetTabular * i = static_cast<InsetTabular *>
1664 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1666 i->OpenLayoutDialog(bv);
1670 bv->owner()->getDialogs()->showTabular(const_cast<InsetTabular *>(this));
1674 // functions returns:
1678 // 3 ... toggled off
1680 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1682 int action = LyXTabular::LAST_ACTION;
1683 LyXFunc::func_status status = LyXFunc::OK;
1686 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1687 string const tmp = tabularFeatures[i].feature;
1688 if (tmp == what.substr(0, tmp.length())) {
1689 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1690 // tabularFeatures[i].feature.length())) {
1691 action = tabularFeatures[i].action;
1695 if (action == LyXTabular::LAST_ACTION)
1696 return LyXFunc::Unknown;
1698 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1700 int sel_row_start, sel_row_end;
1704 if (hasSelection()) {
1705 sel_row_start = tabular->row_of_cell(sel_cell_start);
1706 sel_row_end = tabular->row_of_cell(sel_cell_end);
1707 if (sel_row_start > sel_row_end) {
1708 //int tmp = sel_row_start;
1709 //sel_row_start = sel_row_end;
1710 //sel_row_end = tmp;
1711 swap(sel_row_start, sel_row_end);
1714 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1718 case LyXTabular::SET_PWIDTH:
1719 case LyXTabular::SET_MPWIDTH:
1720 case LyXTabular::SET_SPECIAL_COLUMN:
1721 case LyXTabular::SET_SPECIAL_MULTI:
1722 status |= LyXFunc::Disabled;
1725 case LyXTabular::APPEND_ROW:
1726 case LyXTabular::APPEND_COLUMN:
1727 case LyXTabular::DELETE_ROW:
1728 case LyXTabular::DELETE_COLUMN:
1729 case LyXTabular::SET_ALL_LINES:
1730 case LyXTabular::UNSET_ALL_LINES:
1731 status |= LyXFunc::OK;
1734 case LyXTabular::MULTICOLUMN:
1735 if (tabular->IsMultiColumn(actcell))
1736 status |= LyXFunc::ToggleOn;
1738 status |= LyXFunc::ToggleOff;
1740 case LyXTabular::M_TOGGLE_LINE_TOP:
1742 case LyXTabular::TOGGLE_LINE_TOP:
1743 if (tabular->TopLine(actcell, flag))
1744 status |= LyXFunc::ToggleOn;
1746 status |= LyXFunc::ToggleOff;
1748 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1750 case LyXTabular::TOGGLE_LINE_BOTTOM:
1751 if (tabular->BottomLine(actcell, flag))
1752 status |= LyXFunc::ToggleOn;
1754 status |= LyXFunc::ToggleOff;
1756 case LyXTabular::M_TOGGLE_LINE_LEFT:
1758 case LyXTabular::TOGGLE_LINE_LEFT:
1759 if (tabular->LeftLine(actcell, flag))
1760 status |= LyXFunc::ToggleOn;
1762 status |= LyXFunc::ToggleOff;
1764 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1766 case LyXTabular::TOGGLE_LINE_RIGHT:
1767 if (tabular->RightLine(actcell, flag))
1768 status |= LyXFunc::ToggleOn;
1770 status |= LyXFunc::ToggleOff;
1772 case LyXTabular::M_ALIGN_LEFT:
1774 case LyXTabular::ALIGN_LEFT:
1775 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1776 status |= LyXFunc::ToggleOn;
1778 status |= LyXFunc::ToggleOff;
1780 case LyXTabular::M_ALIGN_RIGHT:
1782 case LyXTabular::ALIGN_RIGHT:
1783 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1784 status |= LyXFunc::ToggleOn;
1786 status |= LyXFunc::ToggleOff;
1788 case LyXTabular::M_ALIGN_CENTER:
1790 case LyXTabular::ALIGN_CENTER:
1791 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1792 status |= LyXFunc::ToggleOn;
1794 status |= LyXFunc::ToggleOff;
1796 case LyXTabular::M_VALIGN_TOP:
1798 case LyXTabular::VALIGN_TOP:
1799 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1800 status |= LyXFunc::ToggleOn;
1802 status |= LyXFunc::ToggleOff;
1804 case LyXTabular::M_VALIGN_BOTTOM:
1806 case LyXTabular::VALIGN_BOTTOM:
1807 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1808 status |= LyXFunc::ToggleOn;
1810 status |= LyXFunc::ToggleOff;
1812 case LyXTabular::M_VALIGN_CENTER:
1814 case LyXTabular::VALIGN_CENTER:
1815 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1816 status |= LyXFunc::ToggleOn;
1818 status |= LyXFunc::ToggleOff;
1820 case LyXTabular::SET_LONGTABULAR:
1821 if (tabular->IsLongTabular())
1822 status |= LyXFunc::ToggleOn;
1824 status |= LyXFunc::ToggleOff;
1826 case LyXTabular::UNSET_LONGTABULAR:
1827 if (!tabular->IsLongTabular())
1828 status |= LyXFunc::ToggleOn;
1830 status |= LyXFunc::ToggleOff;
1832 case LyXTabular::SET_ROTATE_TABULAR:
1833 if (tabular->GetRotateTabular())
1834 status |= LyXFunc::ToggleOn;
1836 status |= LyXFunc::ToggleOff;
1838 case LyXTabular::UNSET_ROTATE_TABULAR:
1839 if (!tabular->GetRotateTabular())
1840 status |= LyXFunc::ToggleOn;
1842 status |= LyXFunc::ToggleOff;
1844 case LyXTabular::SET_ROTATE_CELL:
1845 if (tabular->GetRotateCell(actcell))
1846 status |= LyXFunc::ToggleOn;
1848 status |= LyXFunc::ToggleOff;
1850 case LyXTabular::UNSET_ROTATE_CELL:
1851 if (!tabular->GetRotateCell(actcell))
1852 status |= LyXFunc::ToggleOn;
1854 status |= LyXFunc::ToggleOff;
1856 case LyXTabular::SET_USEBOX:
1857 if (strToInt(argument) == tabular->GetUsebox(actcell))
1858 status |= LyXFunc::ToggleOn;
1860 status |= LyXFunc::ToggleOff;
1862 case LyXTabular::SET_LTFIRSTHEAD:
1863 if (tabular->GetRowOfLTHead(actcell, dummy))
1864 status |= LyXFunc::ToggleOn;
1866 status |= LyXFunc::ToggleOff;
1868 case LyXTabular::SET_LTHEAD:
1869 if (tabular->GetRowOfLTHead(actcell, dummy))
1870 status |= LyXFunc::ToggleOn;
1872 status |= LyXFunc::ToggleOff;
1874 case LyXTabular::SET_LTFOOT:
1875 if (tabular->GetRowOfLTFoot(actcell, dummy))
1876 status |= LyXFunc::ToggleOn;
1878 status |= LyXFunc::ToggleOff;
1880 case LyXTabular::SET_LTLASTFOOT:
1881 if (tabular->GetRowOfLTFoot(actcell, dummy))
1882 status |= LyXFunc::ToggleOn;
1884 status |= LyXFunc::ToggleOff;
1886 case LyXTabular::SET_LTNEWPAGE:
1887 if (tabular->GetLTNewPage(actcell))
1888 status |= LyXFunc::ToggleOn;
1890 status |= LyXFunc::ToggleOff;
1893 status = LyXFunc::Disabled;
1900 bool InsetTabular::copySelection(BufferView * bv)
1902 if (!hasSelection())
1904 delete paste_tabular;
1906 int sel_col_start, sel_col_end;
1907 int sel_row_start, sel_row_end;
1909 sel_col_start = tabular->column_of_cell(sel_cell_start);
1910 sel_col_end = tabular->column_of_cell(sel_cell_end);
1911 if (sel_col_start > sel_col_end) {
1912 sel_col_start = sel_col_end;
1913 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1915 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1917 int columns = sel_col_end - sel_col_start + 1;
1919 sel_row_start = tabular->row_of_cell(sel_cell_start);
1920 sel_row_end = tabular->row_of_cell(sel_cell_end);
1921 if (sel_row_start > sel_row_end) {
1922 //int tmp tmp = sel_row_start;
1923 //sel_row_start = sel_row_end;
1924 //sel_row_end = tmp;
1925 swap(sel_row_start, sel_row_end);
1927 int rows = sel_row_end - sel_row_start + 1;
1929 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
1931 for(i=0; i < sel_row_start; ++i)
1932 paste_tabular->DeleteRow(0);
1933 while(paste_tabular->rows() > rows)
1934 paste_tabular->DeleteRow(rows);
1935 paste_tabular->SetTopLine(0, true, true);
1936 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
1938 for(i=0; i < sel_col_start; ++i)
1939 paste_tabular->DeleteColumn(0);
1940 while(paste_tabular->columns() > columns)
1941 paste_tabular->DeleteColumn(columns);
1942 paste_tabular->SetLeftLine(0, true, true);
1943 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
1946 paste_tabular->Ascii(bv->buffer(), sstr);
1947 bv->stuffClipboard(sstr.str());
1952 bool InsetTabular::pasteSelection(BufferView * bv)
1956 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1957 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1959 if (tabular->GetNumberOfCells() <= i)
1961 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1963 if (paste_tabular->GetNumberOfCells() <= j)
1965 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1966 tabular->GetCellInset(i)->setOwner(this);
1967 tabular->GetCellInset(i)->deleteLyXText(bv);
1973 bool InsetTabular::cutSelection()
1975 if (!hasSelection())
1978 int sel_col_start, sel_col_end;
1979 int sel_row_start, sel_row_end;
1981 sel_col_start = tabular->column_of_cell(sel_cell_start);
1982 sel_col_end = tabular->column_of_cell(sel_cell_end);
1983 if (sel_col_start > sel_col_end) {
1984 sel_col_start = sel_col_end;
1985 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1987 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1989 sel_row_start = tabular->row_of_cell(sel_cell_start);
1990 sel_row_end = tabular->row_of_cell(sel_cell_end);
1991 if (sel_row_start > sel_row_end) {
1992 //int tmp = sel_row_start;
1993 //sel_row_start = sel_row_end;
1994 //sel_row_end = tmp;
1995 swap(sel_row_start, sel_row_end);
1997 if (sel_cell_start > sel_cell_end) {
1998 //int tmp = sel_cell_start;
1999 //sel_cell_start = sel_cell_end;
2000 //sel_cell_end = tmp;
2001 swap(sel_cell_start, sel_cell_end);
2003 for(int i = sel_row_start; i <= sel_row_end; ++i) {
2004 for(int j = sel_col_start; j <= sel_col_end; ++j) {
2005 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();