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 * 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;
140 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
143 tabular = new LyXTabular(this, *(tab.tabular));
144 the_locking_inset = 0;
145 locked = no_selection = cursor_visible = false;
150 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
156 InsetTabular::~InsetTabular()
160 dialogs_->hideTabular(this);
164 Inset * InsetTabular::Clone() const
166 InsetTabular * t = new InsetTabular(*this, buffer);
168 t->tabular = tabular->Clone(t);
173 void InsetTabular::Write(Buffer const * buf, ostream & os) const
175 os << " Tabular" << endl;
176 tabular->Write(buf, os);
180 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
182 bool old_format = (lex.GetString() == "\\LyXTable");
187 tabular = new LyXTabular(buf, this, lex);
195 token = lex.GetString();
196 while (lex.IsOK() && (token != "\\end_inset")) {
198 token = lex.GetString();
200 if (token != "\\end_inset") {
201 lex.printError("Missing \\end_inset at this point. "
207 int InsetTabular::ascent(BufferView *, LyXFont const &) const
209 return tabular->GetAscentOfRow(0);
213 int InsetTabular::descent(BufferView *, LyXFont const &) const
215 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
219 int InsetTabular::width(BufferView *, LyXFont const &) const
221 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
225 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
226 float & x, bool cleared) const
228 Painter & pain = bv->painter();
233 UpdatableInset::draw(bv, font, baseline, x, cleared);
234 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
235 (top_x != int(x)) || (top_baseline != baseline))) {
236 int h = ascent(bv, font) + descent(bv, font);
237 int tx = display() || !owner() ? 0 : top_x;
238 int w = tx ? width(bv, font) : pain.paperWidth();
239 int ty = baseline - ascent(bv, font);
243 if ((ty + h) > pain.paperHeight())
244 h = pain.paperHeight();
245 if ((top_x + w) > pain.paperWidth())
246 w = pain.paperWidth();
247 pain.fillRectangle(tx, ty, w, h);
252 top_baseline = baseline;
253 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
256 x += ADD_TO_TABULAR_WIDTH;
258 for(i = 0; i < tabular->rows(); ++i) {
260 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
261 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
262 for(j = 0; j < tabular->columns(); ++j) {
263 if (tabular->IsPartOfMultiColumn(i, j))
265 cx = nx + tabular->GetBeginningOfTextInCell(cell);
268 DrawCellSelection(pain, nx, baseline, i, j, cell);
269 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
271 DrawCellLines(pain, nx, baseline, i, cell);
273 nx += tabular->GetWidthOfColumn(cell);
276 baseline += tabular->GetDescentOfRow(i) +
277 tabular->GetAscentOfRow(i + 1) +
278 tabular->GetAdditionalHeight(cell);
280 } else if (need_update == CELL) {
282 for(i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
283 for(j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
284 if (tabular->IsPartOfMultiColumn(i, j))
286 nx += tabular->GetWidthOfColumn(cell);
289 if (tabular->row_of_cell(cell) > i) {
291 baseline += tabular->GetDescentOfRow(i) +
292 tabular->GetAscentOfRow(i + 1) +
293 tabular->GetAdditionalHeight(cell);
296 if (the_locking_inset == tabular->GetCellInset(cell)) {
297 LyXText::text_status st = bv->text->status;
299 cx = nx + tabular->GetBeginningOfTextInCell(cell);
300 bv->text->status = st;
301 if (need_update == CELL) {
302 // clear before the inset
305 baseline - tabular->GetAscentOfRow(i) + 1,
307 tabular->GetAscentOfRow(i) +
308 tabular->GetDescentOfRow(i) - 1);
309 // clear behind the inset
311 int(cx + the_locking_inset->width(bv,font) + 1),
312 baseline - tabular->GetAscentOfRow(i) + 1,
313 tabular->GetWidthOfColumn(cell) -
314 tabular->GetBeginningOfTextInCell(cell) -
315 the_locking_inset->width(bv,font) - 1,
316 tabular->GetAscentOfRow(i) +
317 tabular->GetDescentOfRow(i) - 1);
319 tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
320 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
323 x -= ADD_TO_TABULAR_WIDTH;
324 x += width(bv, font);
325 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
332 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
333 int row, int cell) const
335 int x2 = x + tabular->GetWidthOfColumn(cell);
338 if (!tabular->TopAlreadyDrawed(cell)) {
339 on_off = !tabular->TopLine(cell);
340 pain.line(x, baseline - tabular->GetAscentOfRow(row),
341 x2, baseline - tabular->GetAscentOfRow(row),
342 on_off ? LColor::tabularonoffline : LColor::tabularline,
343 on_off ? Painter::line_onoffdash : Painter::line_solid);
345 on_off = !tabular->BottomLine(cell);
346 pain.line(x,baseline + tabular->GetDescentOfRow(row),
347 x2, baseline + tabular->GetDescentOfRow(row),
348 on_off ? LColor::tabularonoffline : LColor::tabularline,
349 on_off ? Painter::line_onoffdash : Painter::line_solid);
350 if (!tabular->LeftAlreadyDrawed(cell)) {
351 on_off = !tabular->LeftLine(cell);
352 pain.line(x, baseline - tabular->GetAscentOfRow(row),
353 x, baseline + tabular->GetDescentOfRow(row),
354 on_off ? LColor::tabularonoffline : LColor::tabularline,
355 on_off ? Painter::line_onoffdash : Painter::line_solid);
357 on_off = !tabular->RightLine(cell);
358 pain.line(x2 - tabular->GetAdditionalWidth(cell),
359 baseline - tabular->GetAscentOfRow(row),
360 x2 - tabular->GetAdditionalWidth(cell),
361 baseline + tabular->GetDescentOfRow(row),
362 on_off ? LColor::tabularonoffline : LColor::tabularline,
363 on_off ? Painter::line_onoffdash : Painter::line_solid);
367 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
368 int row, int column, int cell) const
370 int cs = tabular->column_of_cell(sel_cell_start);
371 int ce = tabular->column_of_cell(sel_cell_end);
374 cs = tabular->column_of_cell(sel_cell_end);
376 ce = tabular->right_column_of_cell(sel_cell_end);
379 int rs = tabular->row_of_cell(sel_cell_start);
380 int re = tabular->row_of_cell(sel_cell_end);
381 if (rs > re) swap(rs, re);
383 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
384 int w = tabular->GetWidthOfColumn(cell);
385 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
386 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
387 w, h, LColor::selection);
392 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
396 calculate_dimensions_of_cells(bv, font, true);
398 owner()->update(bv, font, true);
401 if (the_locking_inset) {
402 the_locking_inset->update(bv, font, reinit);
404 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
405 // inset_y = cursor.y();
407 switch(need_update) {
411 if (calculate_dimensions_of_cells(bv, font, false))
423 string const InsetTabular::EditMessage() const
425 return _("Opened Tabular Inset");
429 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
431 UpdatableInset::Edit(bv, x, y, button);
433 if (!bv->lockInset(this)) {
434 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
438 the_locking_inset = 0;
443 sel_pos_start = sel_pos_end = cursor.pos();
444 sel_cell_start = sel_cell_end = actcell;
445 bv->text->FinishUndo();
446 if (InsetHit(bv, x, y)) {
447 ActivateCellInset(bv, x, y, button);
449 UpdateLocal(bv, NONE, false);
450 // bv->getOwner()->getPopups().updateFormTabular();
454 void InsetTabular::InsetUnlock(BufferView * bv)
456 if (the_locking_inset) {
457 the_locking_inset->InsetUnlock(bv);
458 the_locking_inset = 0;
461 no_selection = false;
464 if (scroll() || hasSelection()) {
468 sel_pos_start = sel_pos_end = 0;
469 sel_cell_start = sel_cell_end = 0;
471 UpdateLocal(bv, FULL, false);
476 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
477 bool mark_dirty) const
481 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
482 if (locked && (what != NONE))
487 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
489 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
493 if (inset == tabular->GetCellInset(actcell)) {
494 lyxerr[Debug::INSETS] << "OK" << endl;
495 the_locking_inset = tabular->GetCellInset(actcell);
497 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
498 inset_y = cursor.y();
499 inset_pos = cursor.pos();
501 } else if (the_locking_inset && (the_locking_inset == inset)) {
502 if (cursor.pos() == inset_pos) {
503 lyxerr[Debug::INSETS] << "OK" << endl;
505 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
506 inset_y = cursor.y();
508 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
510 } else if (the_locking_inset) {
511 lyxerr[Debug::INSETS] << "MAYBE" << endl;
512 return the_locking_inset->LockInsetInInset(bv, inset);
514 lyxerr[Debug::INSETS] << "NOT OK" << endl;
519 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
522 if (!the_locking_inset)
524 if (the_locking_inset == inset) {
525 the_locking_inset->InsetUnlock(bv);
526 the_locking_inset = 0;
528 moveRight(bv, false);
529 ShowInsetCursor(bv, false);
530 UpdateLocal(bv, CELL, false);
533 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
534 if (inset->LyxCode() == TABULAR_CODE &&
535 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
537 dialogs_ = bv->owner()->getDialogs();
538 dialogs_->updateTabular(this);
547 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
549 if (!the_locking_inset)
551 if (the_locking_inset != inset)
552 return the_locking_inset->UpdateInsetInInset(bv, inset);
553 UpdateLocal(bv, CELL, false);
558 unsigned int InsetTabular::InsetInInsetY()
560 if (!the_locking_inset)
563 return (inset_y + the_locking_inset->InsetInInsetY());
567 UpdatableInset * InsetTabular::GetLockingInset()
569 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
573 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
577 if (the_locking_inset)
578 return the_locking_inset->GetFirstLockingInsetOfType(c);
583 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
585 if (the_locking_inset)
586 return the_locking_inset->InsertInset(bv, inset);
591 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
593 if (hasSelection()) {
594 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
595 UpdateLocal(bv, SELECTION, false);
597 no_selection = false;
599 int const ocell = actcell;
600 int const orow = actrow;
605 UpdateLocal(bv, NONE, false);
606 sel_pos_start = sel_pos_end = cursor.pos();
607 sel_cell_start = sel_cell_end = actcell;
609 bool const inset_hit = InsetHit(bv, x, y);
611 if ((ocell == actcell) && the_locking_inset && inset_hit) {
612 cursor.pos(0); // always before the inset!
614 the_locking_inset->InsetButtonPress(bv,
615 x - inset_x, y - inset_y, button);
617 } else if (the_locking_inset) {
618 the_locking_inset->InsetUnlock(bv);
620 the_locking_inset = 0;
621 if (inset_hit && bv->theLockingInset()) {
622 if (ActivateCellInset(bv, x, y, button))
623 the_locking_inset->InsetButtonPress(bv, x - inset_x,
624 y - inset_y, button);
631 void InsetTabular::InsetButtonRelease(BufferView * bv,
632 int x, int y, int button)
635 if (the_locking_inset) {
637 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
638 i->InsetButtonRelease(bv, x, y, button);
642 dialogs_ = bv->owner()->getDialogs();
643 dialogs_->showTabular(this);
646 if (the_locking_inset) {
647 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
650 no_selection = false;
654 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
656 if (the_locking_inset) {
657 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
658 y - inset_y, button);
663 int const old_pos = sel_pos_end;
664 int const old_cell = actcell;
667 sel_pos_end = cursor.pos();
668 sel_cell_end = actcell;
669 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
670 UpdateLocal(bv, SELECTION, false);
673 no_selection = false;
677 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
679 if (the_locking_inset) {
680 the_locking_inset->InsetKeyPress(xke);
686 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
689 UpdatableInset::RESULT
692 no_selection = false;
693 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
694 || (result == DISPATCHED_NOUPDATE)) {
700 if ((action < 0) && arg.empty())
703 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
704 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
706 if (the_locking_inset) {
707 result=the_locking_inset->LocalDispatch(bv, action, arg);
708 if (result == DISPATCHED_NOUPDATE)
710 else if (result == DISPATCHED) {
711 the_locking_inset->ToggleInsetCursor(bv);
712 UpdateLocal(bv, CELL, false);
713 the_locking_inset->ToggleInsetCursor(bv);
715 } else if (result == FINISHED) {
716 if ((action == LFUN_RIGHT) || (action == -1)) {
717 cursor.pos(inset_pos + 1);
720 sel_pos_start = sel_pos_end = cursor.pos();
721 sel_cell_start = sel_cell_end = actcell;
729 bool hs = hasSelection();
733 // --- Cursor Movements ---------------------------------------------
735 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
737 moveRight(bv, false);
739 if (!cellstart(cursor.pos())) {
740 sel_pos_end = cursor.pos();
741 if (tabular->right_column_of_cell(sel_cell_start) >
742 tabular->right_column_of_cell(actcell))
743 sel_cell_end = actcell+1;
745 sel_cell_end = actcell;
748 sel_pos_end = cursor.pos();
749 sel_cell_end = actcell;
751 UpdateLocal(bv, SELECTION, false);
754 result = moveRight(bv);
755 sel_pos_start = sel_pos_end = cursor.pos();
756 sel_cell_start = sel_cell_end = actcell;
758 UpdateLocal(bv, SELECTION, false);
761 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
765 if (cellstart(cursor.pos())) {
766 sel_pos_end = cursor.pos();
767 if (tabular->column_of_cell(sel_cell_start) >=
768 tabular->column_of_cell(actcell))
769 sel_cell_end = actcell;
771 sel_cell_end = actcell-1;
774 sel_pos_end = cursor.pos();
775 sel_cell_end = actcell;
777 UpdateLocal(bv, SELECTION, false);
780 result = moveLeft(bv);
781 sel_pos_start = sel_pos_end = cursor.pos();
782 sel_cell_start = sel_cell_end = actcell;
784 UpdateLocal(bv, SELECTION, false);
788 int const ocell = actcell;
790 sel_pos_end = cursor.pos();
791 if ((ocell == sel_cell_end) ||
792 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
793 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
795 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
796 UpdateLocal(bv, SELECTION, false);
800 result = moveDown(bv);
801 sel_pos_start = sel_pos_end = cursor.pos();
802 sel_cell_start = sel_cell_end = actcell;
804 UpdateLocal(bv, SELECTION, false);
808 int const ocell = actcell;
810 sel_pos_end = cursor.pos();
811 if ((ocell == sel_cell_end) ||
812 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
813 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
815 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
816 UpdateLocal(bv, SELECTION, false);
821 sel_pos_start = sel_pos_end = cursor.pos();
822 sel_cell_start = sel_cell_end = actcell;
824 UpdateLocal(bv, SELECTION, false);
836 if (the_locking_inset) {
837 UnlockInsetInInset(bv, the_locking_inset);
838 the_locking_inset = 0;
840 if (action == LFUN_TAB)
844 sel_pos_start = sel_pos_end = cursor.pos();
845 sel_cell_start = sel_cell_end = actcell;
847 UpdateLocal(bv, SELECTION, false);
849 case LFUN_LAYOUT_TABULAR:
851 dialogs_ = bv->owner()->getDialogs();
852 dialogs_->showTabular(this);
855 case LFUN_TABULAR_FEATURE:
856 if (!TabularFeatures(bv, arg))
857 result = UNDISPATCHED;
860 if (!copySelection(bv))
862 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
864 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
865 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
867 bv->text->cursor.par()->previous,
868 bv->text->cursor.par()->next
872 UpdateLocal(bv, INIT, true);
877 bv->text->FinishUndo();
881 if (!hasPasteBuffer())
883 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
885 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
886 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
888 bv->text->cursor.par()->previous,
889 bv->text->cursor.par()->next
893 UpdateLocal(bv, INIT, true);
896 // we try to activate the actual inset and put this event down to
897 // the insets dispatch function.
898 result = UNDISPATCHED;
899 if (the_locking_inset)
901 if (ActivateCellInset(bv, 0, 0, 0, !cellstart(cursor.pos()))) {
902 result=the_locking_inset->LocalDispatch(bv, action, arg);
903 if (result == DISPATCHED_NOUPDATE)
905 else if (result == DISPATCHED) {
906 the_locking_inset->ToggleInsetCursor(bv);
907 UpdateLocal(bv, CELL, false);
908 the_locking_inset->ToggleInsetCursor(bv);
911 result = UNDISPATCHED;
916 if (result!=FINISHED) {
917 if (!the_locking_inset) {
921 bv->unlockInset(this);
926 int InsetTabular::Latex(Buffer const * buf, ostream & os,
927 bool fragile, bool fp) const
929 return tabular->Latex(buf, os, fragile, fp);
933 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
935 // This should be changed to a real ascii export
936 return tabular->Ascii(buf, os);
940 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
946 int InsetTabular::DocBook(Buffer const *, ostream &) const
952 void InsetTabular::Validate(LaTeXFeatures & features) const
954 tabular->Validate(features);
958 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
959 LyXFont const & font,
965 bool changed = false;
967 for(int i = 0; i < tabular->rows(); ++i) {
968 maxAsc = maxDesc = 0;
969 for(int j= 0; j < tabular->columns(); ++j) {
970 if (tabular->IsPartOfMultiColumn(i,j))
973 inset = tabular->GetCellInset(cell);
975 inset->update(bv, font, false);
976 maxAsc = max(maxAsc, inset->ascent(bv, font));
977 maxDesc = max(maxDesc, inset->descent(bv, font));
978 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
980 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
981 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
987 void InsetTabular::GetCursorPos(BufferView *,
988 int & x, int & y) const
990 x = cursor.x() - top_x;
995 void InsetTabular::ToggleInsetCursor(BufferView * bv)
997 if (the_locking_inset) {
998 the_locking_inset->ToggleInsetCursor(bv);
1002 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1004 int const asc = lyxfont::maxAscent(font);
1005 int const desc = lyxfont::maxDescent(font);
1008 bv->hideLockedInsetCursor();
1010 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1011 cursor_visible = !cursor_visible;
1015 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1017 if (!cursor_visible) {
1018 LyXFont font; // = GetFont(par, cursor.pos);
1020 int const asc = lyxfont::maxAscent(font);
1021 int const desc = lyxfont::maxDescent(font);
1022 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1024 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1025 cursor_visible = true;
1030 void InsetTabular::HideInsetCursor(BufferView * bv)
1032 if (cursor_visible) {
1033 bv->hideLockedInsetCursor();
1034 cursor_visible = false;
1036 // if (cursor_visible)
1037 // ToggleInsetCursor(bv);
1041 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1046 actcell = actrow = actcol = 0;
1047 int ly = tabular->GetDescentOfRow(actrow);
1049 // first search the right row
1050 while((ly < y) && (actrow < tabular->rows())) {
1051 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1052 tabular->GetAscentOfRow(actrow + 1) +
1053 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1056 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1058 actcell = tabular->GetCellNumber(actrow, actcol);
1060 // now search the right column
1061 int lx = tabular->GetWidthOfColumn(actcell) -
1062 tabular->GetAdditionalWidth(actcell);
1063 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1065 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1066 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1067 tabular->GetAdditionalWidth(actcell - 1));
1069 // Jürgen, you should check that this is correct. (Lgb)
1070 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1071 lx += tabular->GetWidthOfColumn(actcell + 1)
1072 + tabular->GetAdditionalWidth(actcell);
1078 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1079 cursor.x(lx + top_x - 2);
1082 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1088 int InsetTabular::getCellXPos(int cell) const
1092 for(; !tabular->IsFirstCellInRow(c); --c)
1094 int lx = tabular->GetWidthOfColumn(cell);
1095 for(; c < cell; ++c) {
1096 lx += tabular->GetWidthOfColumn(c);
1098 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1102 void InsetTabular::resetPos(BufferView * bv) const
1106 actcol = tabular->column_of_cell(actcell);
1111 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1112 if (tabular->IsLastCellInRow(cell)) {
1113 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1114 tabular->GetAscentOfRow(actrow + 1) +
1115 tabular->GetAdditionalHeight(cell + 1));
1119 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1120 cursor.x(getCellXPos(actcell) + offset);
1121 if (((cursor.x() - offset) > 20) &&
1122 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1123 (bv->workWidth()-20)))
1125 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1126 UpdateLocal(bv, FULL, false);
1127 } else if ((cursor.x() - offset) < 20) {
1128 scroll(bv, 20 - cursor.x() + offset);
1129 UpdateLocal(bv, FULL, false);
1130 } else if (!cellstart(cursor.pos())) {
1131 LyXFont font(LyXFont::ALL_SANE);
1132 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1133 tabular->GetBeginningOfTextInCell(actcell));
1135 if ((!the_locking_inset ||
1136 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1137 (actcell != oldcell)) {
1138 dialogs_ = bv->owner()->getDialogs();
1139 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1145 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1147 if (!cellstart(cursor.pos())) {
1148 if (tabular->IsLastCell(actcell))
1153 if (ActivateCellInset(bv))
1155 } else { // before the inset
1159 return DISPATCHED_NOUPDATE;
1163 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1165 if (cellstart(cursor.pos()) && !actcell)
1167 if (cellstart(cursor.pos())) {
1170 } else if (lock) { // behind the inset
1172 if (ActivateCellInset(bv, 0, 0, 0, true))
1178 return DISPATCHED_NOUPDATE;
1182 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1184 int const ocell = actcell;
1185 actcell = tabular->GetCellAbove(actcell);
1186 if (actcell == ocell) // we moved out of the inset
1189 return DISPATCHED_NOUPDATE;
1193 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1195 int const ocell = actcell;
1196 actcell = tabular->GetCellBelow(actcell);
1197 if (actcell == ocell) // we moved out of the inset
1200 return DISPATCHED_NOUPDATE;
1204 bool InsetTabular::moveNextCell(BufferView * bv)
1206 if (tabular->IsLastCell(actcell))
1214 bool InsetTabular::movePrevCell(BufferView * bv)
1216 if (!actcell) // first cell
1224 bool InsetTabular::Delete()
1230 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1232 if (the_locking_inset)
1233 the_locking_inset->SetFont(bv, font, tall);
1237 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1239 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1242 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1243 string const tmp = tabularFeatures[i].feature;
1245 if (tmp == what.substr(0, tmp.length())) {
1246 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1247 //tabularFeatures[i].feature.length())) {
1248 action = tabularFeatures[i].action;
1252 if (action == LyXTabular::LAST_ACTION)
1256 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1257 TabularFeatures(bv, action, val);
1262 void InsetTabular::TabularFeatures(BufferView * bv,
1263 LyXTabular::Feature feature,
1264 string const & value)
1273 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1274 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1279 case LyXTabular::M_ALIGN_LEFT:
1280 case LyXTabular::ALIGN_LEFT:
1281 setAlign=LYX_ALIGN_LEFT;
1283 case LyXTabular::M_ALIGN_RIGHT:
1284 case LyXTabular::ALIGN_RIGHT:
1285 setAlign=LYX_ALIGN_RIGHT;
1287 case LyXTabular::M_ALIGN_CENTER:
1288 case LyXTabular::ALIGN_CENTER:
1289 setAlign=LYX_ALIGN_CENTER;
1291 case LyXTabular::M_VALIGN_TOP:
1292 case LyXTabular::VALIGN_TOP:
1293 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1295 case LyXTabular::M_VALIGN_BOTTOM:
1296 case LyXTabular::VALIGN_BOTTOM:
1297 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1299 case LyXTabular::M_VALIGN_CENTER:
1300 case LyXTabular::VALIGN_CENTER:
1301 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1306 if (hasSelection()) {
1307 sel_col_start = tabular->column_of_cell(sel_cell_start);
1308 sel_col_end = tabular->column_of_cell(sel_cell_end);
1309 if (sel_col_start > sel_col_end) {
1310 sel_col_end = sel_col_start;
1311 sel_col_start = tabular->column_of_cell(sel_cell_end);
1313 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1316 sel_row_start = tabular->row_of_cell(sel_cell_start);
1317 sel_row_end = tabular->row_of_cell(sel_cell_end);
1318 if (sel_row_start > sel_row_end) {
1319 //int tmp = sel_row_start;
1320 //sel_row_start = sel_row_end;
1321 //sel_row_end = tmp;
1322 swap(sel_row_start, sel_row_end);
1325 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1326 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1328 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1330 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1331 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1333 bv->text->cursor.par()->previous,
1334 bv->text->cursor.par()->next
1338 int row = tabular->row_of_cell(actcell);
1339 int column = tabular->column_of_cell(actcell);
1343 case LyXTabular::SET_PWIDTH:
1345 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1346 tabular->SetColumnPWidth(actcell,value);
1348 for (int i=0; i < tabular->rows(); ++i) {
1349 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1352 UpdateLocal(bv, INIT, true);
1356 case LyXTabular::SET_MPWIDTH:
1358 bool const update = (tabular->GetPWidth(actcell) != value);
1359 tabular->SetMColumnPWidth(actcell,value);
1361 for (int i=0; i < tabular->rows(); ++i) {
1362 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1365 UpdateLocal(bv, INIT, true);
1369 case LyXTabular::SET_SPECIAL_COLUMN:
1370 case LyXTabular::SET_SPECIAL_MULTI:
1371 tabular->SetAlignSpecial(actcell,value,feature);
1373 case LyXTabular::APPEND_ROW:
1374 // append the row into the tabular
1375 UnlockInsetInInset(bv, the_locking_inset);
1376 tabular->AppendRow(actcell);
1377 UpdateLocal(bv, INIT, true);
1379 case LyXTabular::APPEND_COLUMN:
1380 // append the column into the tabular
1381 tabular->AppendColumn(actcell);
1382 actcell = tabular->GetCellNumber(row, column);
1383 UpdateLocal(bv, INIT, true);
1385 case LyXTabular::DELETE_ROW:
1386 tabular->DeleteRow(tabular->row_of_cell(actcell));
1387 if ((row+1) > tabular->rows())
1389 actcell = tabular->GetCellNumber(row, column);
1390 UpdateLocal(bv, INIT, true);
1392 case LyXTabular::DELETE_COLUMN:
1393 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1394 if ((column+1) > tabular->columns())
1396 actcell = tabular->GetCellNumber(row, column);
1397 UpdateLocal(bv, INIT, true);
1399 case LyXTabular::M_TOGGLE_LINE_TOP:
1401 case LyXTabular::TOGGLE_LINE_TOP:
1402 lineSet = !tabular->TopLine(actcell, flag);
1403 for(i=sel_row_start; i<=sel_row_end; ++i)
1404 for(j=sel_col_start; j<=sel_col_end; ++j)
1405 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1406 UpdateLocal(bv, INIT, true);
1409 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1411 case LyXTabular::TOGGLE_LINE_BOTTOM:
1412 lineSet = !tabular->BottomLine(actcell, flag);
1413 for(i=sel_row_start; i<=sel_row_end; ++i)
1414 for(j=sel_col_start; j<=sel_col_end; ++j)
1415 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1417 UpdateLocal(bv, INIT, true);
1420 case LyXTabular::M_TOGGLE_LINE_LEFT:
1422 case LyXTabular::TOGGLE_LINE_LEFT:
1423 lineSet = !tabular->LeftLine(actcell, flag);
1424 for(i=sel_row_start; i<=sel_row_end; ++i)
1425 for(j=sel_col_start; j<=sel_col_end; ++j)
1426 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1428 UpdateLocal(bv, INIT, true);
1431 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1433 case LyXTabular::TOGGLE_LINE_RIGHT:
1434 lineSet = !tabular->RightLine(actcell, flag);
1435 for(i=sel_row_start; i<=sel_row_end; ++i)
1436 for(j=sel_col_start; j<=sel_col_end; ++j)
1437 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1439 UpdateLocal(bv, INIT, true);
1441 case LyXTabular::M_ALIGN_LEFT:
1442 case LyXTabular::M_ALIGN_RIGHT:
1443 case LyXTabular::M_ALIGN_CENTER:
1445 case LyXTabular::ALIGN_LEFT:
1446 case LyXTabular::ALIGN_RIGHT:
1447 case LyXTabular::ALIGN_CENTER:
1448 for(i = sel_row_start; i <= sel_row_end; ++i)
1449 for(j = sel_col_start; j <= sel_col_end; ++j)
1450 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1453 UpdateLocal(bv, INIT, true);
1455 UpdateLocal(bv, CELL, true);
1457 case LyXTabular::M_VALIGN_TOP:
1458 case LyXTabular::M_VALIGN_BOTTOM:
1459 case LyXTabular::M_VALIGN_CENTER:
1461 case LyXTabular::VALIGN_TOP:
1462 case LyXTabular::VALIGN_BOTTOM:
1463 case LyXTabular::VALIGN_CENTER:
1464 for(i = sel_row_start; i <= sel_row_end; ++i)
1465 for(j = sel_col_start; j <= sel_col_end; ++j)
1466 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1469 UpdateLocal(bv, INIT, true);
1471 UpdateLocal(bv, CELL, true);
1473 case LyXTabular::MULTICOLUMN:
1475 if (sel_row_start != sel_row_end) {
1476 WriteAlert(_("Impossible Operation!"),
1477 _("Multicolumns can only be horizontally."),
1481 // just multicol for one Single Cell
1482 if (!hasSelection()) {
1483 // check wether we are completly in a multicol
1484 if (tabular->IsMultiColumn(actcell)) {
1485 tabular->UnsetMultiColumn(actcell);
1486 UpdateLocal(bv, INIT, true);
1488 tabular->SetMultiColumn(actcell, 1);
1489 UpdateLocal(bv, CELL, true);
1493 // we have a selection so this means we just add all this
1494 // cells to form a multicolumn cell
1498 if (sel_cell_start > sel_cell_end) {
1499 s_start = sel_cell_end;
1500 s_end = sel_cell_start;
1502 s_start = sel_cell_start;
1503 s_end = sel_cell_end;
1505 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1508 sel_cell_end = sel_cell_start;
1509 sel_pos_end = sel_pos_start;
1510 UpdateLocal(bv, INIT, true);
1513 case LyXTabular::SET_ALL_LINES:
1515 case LyXTabular::UNSET_ALL_LINES:
1516 for(i=sel_row_start; i<=sel_row_end; ++i)
1517 for(j=sel_col_start; j<=sel_col_end; ++j)
1518 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1519 UpdateLocal(bv, INIT, true);
1521 case LyXTabular::SET_LONGTABULAR:
1522 tabular->SetLongTabular(true);
1523 UpdateLocal(bv, INIT, true); // because this toggles displayed
1525 case LyXTabular::UNSET_LONGTABULAR:
1526 tabular->SetLongTabular(false);
1527 UpdateLocal(bv, INIT, true); // because this toggles displayed
1529 case LyXTabular::SET_ROTATE_TABULAR:
1530 tabular->SetRotateTabular(true);
1532 case LyXTabular::UNSET_ROTATE_TABULAR:
1533 tabular->SetRotateTabular(false);
1535 case LyXTabular::SET_ROTATE_CELL:
1536 for(i=sel_row_start; i<=sel_row_end; ++i)
1537 for(j=sel_col_start; j<=sel_col_end; ++j)
1538 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1540 case LyXTabular::UNSET_ROTATE_CELL:
1541 for(i = sel_row_start; i <= sel_row_end; ++i)
1542 for(j = sel_col_start; j <= sel_col_end; ++j)
1543 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1545 case LyXTabular::SET_USEBOX:
1547 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1548 if (val == tabular->GetUsebox(actcell))
1549 val = LyXTabular::BOX_NONE;
1550 for(i = sel_row_start; i <= sel_row_end; ++i)
1551 for(j = sel_col_start; j <= sel_col_end; ++j)
1552 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1555 case LyXTabular::SET_LTFIRSTHEAD:
1556 tabular->SetLTHead(actcell, true);
1558 case LyXTabular::SET_LTHEAD:
1559 tabular->SetLTHead(actcell, false);
1561 case LyXTabular::SET_LTFOOT:
1562 tabular->SetLTFoot(actcell, false);
1564 case LyXTabular::SET_LTLASTFOOT:
1565 tabular->SetLTFoot(actcell, true);
1567 case LyXTabular::SET_LTNEWPAGE:
1568 what = !tabular->GetLTNewPage(actcell);
1569 tabular->SetLTNewPage(actcell, what);
1571 // dummy stuff just to avoid warnings
1572 case LyXTabular::LAST_ACTION:
1578 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1581 // the cursor.pos has to be before the inset so if it isn't now just
1582 // reset the curor pos first!
1583 if (!cellstart(cursor.pos())) {
1587 UpdatableInset * inset =
1588 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1589 LyXFont font(LyXFont::ALL_SANE);
1591 x = inset->x() + inset->width(bv, font);
1592 y = inset->descent(bv, font);
1594 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1595 inset_y = cursor.y();
1596 inset->Edit(bv, x, y - inset_y, button);
1597 if (!the_locking_inset)
1599 UpdateLocal(bv, CELL, false);
1600 return (the_locking_inset != 0);
1604 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1606 InsetText * inset = tabular->GetCellInset(actcell);
1609 if (!cellstart(cursor.pos())) {
1610 return (((x + top_x) < cursor.x()) &&
1611 ((x + top_x) > (cursor.x() - inset->width(bv,
1612 LyXFont(LyXFont::ALL_SANE)))));
1614 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1615 return ((x1 > x2) &&
1616 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1621 // This returns paperWidth() if the cell-width is unlimited or the width
1622 // in pixels if we have a pwidth for this cell.
1623 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1625 string const s = tabular->GetPWidth(cell);
1629 return VSpace(s).inPixels(0, 0);
1633 int InsetTabular::getMaxWidth(Painter & pain,
1634 UpdatableInset const * inset) const
1636 int const n = tabular->GetNumberOfCells();
1638 for(; cell < n; ++cell) {
1639 if (tabular->GetCellInset(cell) == inset)
1644 int w = GetMaxWidthOfCell(pain, cell);
1646 // because the inset then subtracts it's top_x and owner->x()
1647 w += (inset->x() - top_x);
1652 void InsetTabular::resizeLyXText(BufferView *) const
1658 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1660 if (the_locking_inset)
1661 return the_locking_inset->getLyXText(bv);
1662 return Inset::getLyXText(bv);
1666 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1668 if (the_locking_inset) {
1669 InsetTabular * i = static_cast<InsetTabular *>
1670 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1672 i->OpenLayoutDialog(bv);
1676 dialogs_ = bv->owner()->getDialogs();
1677 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1681 // functions returns:
1685 // 3 ... toggled off
1687 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1689 int action = LyXTabular::LAST_ACTION;
1690 LyXFunc::func_status status = LyXFunc::OK;
1693 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1694 string const tmp = tabularFeatures[i].feature;
1695 if (tmp == what.substr(0, tmp.length())) {
1696 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1697 // tabularFeatures[i].feature.length())) {
1698 action = tabularFeatures[i].action;
1702 if (action == LyXTabular::LAST_ACTION)
1703 return LyXFunc::Unknown;
1705 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1707 int sel_row_start, sel_row_end;
1711 if (hasSelection()) {
1712 sel_row_start = tabular->row_of_cell(sel_cell_start);
1713 sel_row_end = tabular->row_of_cell(sel_cell_end);
1714 if (sel_row_start > sel_row_end) {
1715 //int tmp = sel_row_start;
1716 //sel_row_start = sel_row_end;
1717 //sel_row_end = tmp;
1718 swap(sel_row_start, sel_row_end);
1721 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1725 case LyXTabular::SET_PWIDTH:
1726 case LyXTabular::SET_MPWIDTH:
1727 case LyXTabular::SET_SPECIAL_COLUMN:
1728 case LyXTabular::SET_SPECIAL_MULTI:
1729 status |= LyXFunc::Disabled;
1732 case LyXTabular::APPEND_ROW:
1733 case LyXTabular::APPEND_COLUMN:
1734 case LyXTabular::DELETE_ROW:
1735 case LyXTabular::DELETE_COLUMN:
1736 case LyXTabular::SET_ALL_LINES:
1737 case LyXTabular::UNSET_ALL_LINES:
1738 status |= LyXFunc::OK;
1741 case LyXTabular::MULTICOLUMN:
1742 if (tabular->IsMultiColumn(actcell))
1743 status |= LyXFunc::ToggleOn;
1745 status |= LyXFunc::ToggleOff;
1747 case LyXTabular::M_TOGGLE_LINE_TOP:
1749 case LyXTabular::TOGGLE_LINE_TOP:
1750 if (tabular->TopLine(actcell, flag))
1751 status |= LyXFunc::ToggleOn;
1753 status |= LyXFunc::ToggleOff;
1755 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1757 case LyXTabular::TOGGLE_LINE_BOTTOM:
1758 if (tabular->BottomLine(actcell, flag))
1759 status |= LyXFunc::ToggleOn;
1761 status |= LyXFunc::ToggleOff;
1763 case LyXTabular::M_TOGGLE_LINE_LEFT:
1765 case LyXTabular::TOGGLE_LINE_LEFT:
1766 if (tabular->LeftLine(actcell, flag))
1767 status |= LyXFunc::ToggleOn;
1769 status |= LyXFunc::ToggleOff;
1771 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1773 case LyXTabular::TOGGLE_LINE_RIGHT:
1774 if (tabular->RightLine(actcell, flag))
1775 status |= LyXFunc::ToggleOn;
1777 status |= LyXFunc::ToggleOff;
1779 case LyXTabular::M_ALIGN_LEFT:
1781 case LyXTabular::ALIGN_LEFT:
1782 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1783 status |= LyXFunc::ToggleOn;
1785 status |= LyXFunc::ToggleOff;
1787 case LyXTabular::M_ALIGN_RIGHT:
1789 case LyXTabular::ALIGN_RIGHT:
1790 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1791 status |= LyXFunc::ToggleOn;
1793 status |= LyXFunc::ToggleOff;
1795 case LyXTabular::M_ALIGN_CENTER:
1797 case LyXTabular::ALIGN_CENTER:
1798 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1799 status |= LyXFunc::ToggleOn;
1801 status |= LyXFunc::ToggleOff;
1803 case LyXTabular::M_VALIGN_TOP:
1805 case LyXTabular::VALIGN_TOP:
1806 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1807 status |= LyXFunc::ToggleOn;
1809 status |= LyXFunc::ToggleOff;
1811 case LyXTabular::M_VALIGN_BOTTOM:
1813 case LyXTabular::VALIGN_BOTTOM:
1814 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1815 status |= LyXFunc::ToggleOn;
1817 status |= LyXFunc::ToggleOff;
1819 case LyXTabular::M_VALIGN_CENTER:
1821 case LyXTabular::VALIGN_CENTER:
1822 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1823 status |= LyXFunc::ToggleOn;
1825 status |= LyXFunc::ToggleOff;
1827 case LyXTabular::SET_LONGTABULAR:
1828 if (tabular->IsLongTabular())
1829 status |= LyXFunc::ToggleOn;
1831 status |= LyXFunc::ToggleOff;
1833 case LyXTabular::UNSET_LONGTABULAR:
1834 if (!tabular->IsLongTabular())
1835 status |= LyXFunc::ToggleOn;
1837 status |= LyXFunc::ToggleOff;
1839 case LyXTabular::SET_ROTATE_TABULAR:
1840 if (tabular->GetRotateTabular())
1841 status |= LyXFunc::ToggleOn;
1843 status |= LyXFunc::ToggleOff;
1845 case LyXTabular::UNSET_ROTATE_TABULAR:
1846 if (!tabular->GetRotateTabular())
1847 status |= LyXFunc::ToggleOn;
1849 status |= LyXFunc::ToggleOff;
1851 case LyXTabular::SET_ROTATE_CELL:
1852 if (tabular->GetRotateCell(actcell))
1853 status |= LyXFunc::ToggleOn;
1855 status |= LyXFunc::ToggleOff;
1857 case LyXTabular::UNSET_ROTATE_CELL:
1858 if (!tabular->GetRotateCell(actcell))
1859 status |= LyXFunc::ToggleOn;
1861 status |= LyXFunc::ToggleOff;
1863 case LyXTabular::SET_USEBOX:
1864 if (strToInt(argument) == tabular->GetUsebox(actcell))
1865 status |= LyXFunc::ToggleOn;
1867 status |= LyXFunc::ToggleOff;
1869 case LyXTabular::SET_LTFIRSTHEAD:
1870 if (tabular->GetRowOfLTHead(actcell, dummy))
1871 status |= LyXFunc::ToggleOn;
1873 status |= LyXFunc::ToggleOff;
1875 case LyXTabular::SET_LTHEAD:
1876 if (tabular->GetRowOfLTHead(actcell, dummy))
1877 status |= LyXFunc::ToggleOn;
1879 status |= LyXFunc::ToggleOff;
1881 case LyXTabular::SET_LTFOOT:
1882 if (tabular->GetRowOfLTFoot(actcell, dummy))
1883 status |= LyXFunc::ToggleOn;
1885 status |= LyXFunc::ToggleOff;
1887 case LyXTabular::SET_LTLASTFOOT:
1888 if (tabular->GetRowOfLTFoot(actcell, dummy))
1889 status |= LyXFunc::ToggleOn;
1891 status |= LyXFunc::ToggleOff;
1893 case LyXTabular::SET_LTNEWPAGE:
1894 if (tabular->GetLTNewPage(actcell))
1895 status |= LyXFunc::ToggleOn;
1897 status |= LyXFunc::ToggleOff;
1900 status = LyXFunc::Disabled;
1907 bool InsetTabular::copySelection(BufferView * bv)
1909 if (!hasSelection())
1911 delete paste_tabular;
1913 int sel_col_start, sel_col_end;
1914 int sel_row_start, sel_row_end;
1916 sel_col_start = tabular->column_of_cell(sel_cell_start);
1917 sel_col_end = tabular->column_of_cell(sel_cell_end);
1918 if (sel_col_start > sel_col_end) {
1919 sel_col_start = sel_col_end;
1920 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1922 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1924 int columns = sel_col_end - sel_col_start + 1;
1926 sel_row_start = tabular->row_of_cell(sel_cell_start);
1927 sel_row_end = tabular->row_of_cell(sel_cell_end);
1928 if (sel_row_start > sel_row_end) {
1929 //int tmp tmp = sel_row_start;
1930 //sel_row_start = sel_row_end;
1931 //sel_row_end = tmp;
1932 swap(sel_row_start, sel_row_end);
1934 int rows = sel_row_end - sel_row_start + 1;
1936 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
1938 for(i=0; i < sel_row_start; ++i)
1939 paste_tabular->DeleteRow(0);
1940 while(paste_tabular->rows() > rows)
1941 paste_tabular->DeleteRow(rows);
1942 paste_tabular->SetTopLine(0, true, true);
1943 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
1945 for(i=0; i < sel_col_start; ++i)
1946 paste_tabular->DeleteColumn(0);
1947 while(paste_tabular->columns() > columns)
1948 paste_tabular->DeleteColumn(columns);
1949 paste_tabular->SetLeftLine(0, true, true);
1950 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
1953 paste_tabular->Ascii(bv->buffer(), sstr);
1954 bv->stuffClipboard(sstr.str());
1959 bool InsetTabular::pasteSelection(BufferView * bv)
1963 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1964 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1966 if (tabular->GetNumberOfCells() <= i)
1968 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1970 if (paste_tabular->GetNumberOfCells() <= j)
1972 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1973 tabular->GetCellInset(i)->setOwner(this);
1974 tabular->GetCellInset(i)->deleteLyXText(bv);
1980 bool InsetTabular::cutSelection()
1982 if (!hasSelection())
1985 int sel_col_start, sel_col_end;
1986 int sel_row_start, sel_row_end;
1988 sel_col_start = tabular->column_of_cell(sel_cell_start);
1989 sel_col_end = tabular->column_of_cell(sel_cell_end);
1990 if (sel_col_start > sel_col_end) {
1991 sel_col_start = sel_col_end;
1992 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1994 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1996 sel_row_start = tabular->row_of_cell(sel_cell_start);
1997 sel_row_end = tabular->row_of_cell(sel_cell_end);
1998 if (sel_row_start > sel_row_end) {
1999 //int tmp = sel_row_start;
2000 //sel_row_start = sel_row_end;
2001 //sel_row_end = tmp;
2002 swap(sel_row_start, sel_row_end);
2004 if (sel_cell_start > sel_cell_end) {
2005 //int tmp = sel_cell_start;
2006 //sel_cell_start = sel_cell_end;
2007 //sel_cell_end = tmp;
2008 swap(sel_cell_start, sel_cell_end);
2010 for(int i = sel_row_start; i <= sel_row_end; ++i) {
2011 for(int j = sel_col_start; j <= sel_col_end; ++j) {
2012 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();