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 UpdateLocal(bv, CELL, false);
532 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
533 if (inset->LyxCode() == TABULAR_CODE &&
534 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
536 dialogs_ = bv->owner()->getDialogs();
537 dialogs_->updateTabular(this);
546 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
548 if (!the_locking_inset)
550 if (the_locking_inset != inset)
551 return the_locking_inset->UpdateInsetInInset(bv, inset);
552 UpdateLocal(bv, CELL, false);
557 unsigned int InsetTabular::InsetInInsetY()
559 if (!the_locking_inset)
562 return (inset_y + the_locking_inset->InsetInInsetY());
566 UpdatableInset * InsetTabular::GetLockingInset()
568 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
572 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
576 if (the_locking_inset)
577 return the_locking_inset->GetFirstLockingInsetOfType(c);
582 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
584 if (the_locking_inset)
585 return the_locking_inset->InsertInset(bv, inset);
590 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
592 if (hasSelection()) {
593 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
594 UpdateLocal(bv, SELECTION, false);
596 no_selection = false;
598 int const ocell = actcell;
599 int const orow = actrow;
604 UpdateLocal(bv, NONE, false);
605 sel_pos_start = sel_pos_end = cursor.pos();
606 sel_cell_start = sel_cell_end = actcell;
608 bool const inset_hit = InsetHit(bv, x, y);
610 if ((ocell == actcell) && the_locking_inset && inset_hit) {
611 cursor.pos(0); // always before the inset!
613 the_locking_inset->InsetButtonPress(bv,
614 x - inset_x, y - inset_y, button);
616 } else if (the_locking_inset) {
617 the_locking_inset->InsetUnlock(bv);
619 the_locking_inset = 0;
620 if (inset_hit && bv->the_locking_inset) {
621 if (ActivateCellInset(bv, x, y, button))
622 the_locking_inset->InsetButtonPress(bv, x - inset_x,
623 y - inset_y, button);
630 void InsetTabular::InsetButtonRelease(BufferView * bv,
631 int x, int y, int button)
634 if (the_locking_inset) {
636 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
637 i->InsetButtonRelease(bv, x, y, button);
641 dialogs_ = bv->owner()->getDialogs();
642 dialogs_->showTabular(this);
645 if (the_locking_inset) {
646 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
649 no_selection = false;
653 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
655 if (the_locking_inset) {
656 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
657 y - inset_y, button);
662 int const old_pos = sel_pos_end;
663 int const old_cell = actcell;
666 sel_pos_end = cursor.pos();
667 sel_cell_end = actcell;
668 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
669 UpdateLocal(bv, SELECTION, false);
672 no_selection = false;
676 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
678 if (the_locking_inset) {
679 the_locking_inset->InsetKeyPress(xke);
685 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
688 UpdatableInset::RESULT
691 no_selection = false;
692 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
693 || (result == DISPATCHED_NOUPDATE)) {
699 if ((action < 0) && arg.empty())
702 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
703 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
705 if (the_locking_inset) {
706 result=the_locking_inset->LocalDispatch(bv, action, arg);
707 if (result == DISPATCHED_NOUPDATE)
709 else if (result == DISPATCHED) {
710 the_locking_inset->ToggleInsetCursor(bv);
711 UpdateLocal(bv, CELL, false);
712 the_locking_inset->ToggleInsetCursor(bv);
714 } else if (result == FINISHED) {
715 if ((action == LFUN_RIGHT) || (action == -1)) {
716 cursor.pos(inset_pos + 1);
719 sel_pos_start = sel_pos_end = cursor.pos();
720 sel_cell_start = sel_cell_end = actcell;
727 bool hs = hasSelection();
731 // Normal chars not handled here
734 // --- Cursor Movements ---------------------------------------------
736 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
738 moveRight(bv, false);
739 sel_pos_end = cursor.pos();
740 if (!cellstart(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;
747 UpdateLocal(bv, SELECTION, false);
750 result = moveRight(bv);
751 sel_pos_start = sel_pos_end = cursor.pos();
752 sel_cell_start = sel_cell_end = actcell;
754 UpdateLocal(bv, SELECTION, false);
757 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
760 sel_pos_end = cursor.pos();
761 if (cellstart(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;
768 UpdateLocal(bv, SELECTION, false);
771 result = moveLeft(bv);
772 sel_pos_start = sel_pos_end = cursor.pos();
773 sel_cell_start = sel_cell_end = actcell;
775 UpdateLocal(bv, SELECTION, false);
779 int const ocell = actcell;
781 sel_pos_end = cursor.pos();
782 if ((ocell == sel_cell_end) ||
783 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
784 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
786 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
787 UpdateLocal(bv, SELECTION, false);
791 result = moveDown(bv);
792 sel_pos_start = sel_pos_end = cursor.pos();
793 sel_cell_start = sel_cell_end = actcell;
795 UpdateLocal(bv, SELECTION, false);
799 int const ocell = actcell;
801 sel_pos_end = cursor.pos();
802 if ((ocell == sel_cell_end) ||
803 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
804 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
806 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
807 UpdateLocal(bv, SELECTION, false);
812 sel_pos_start = sel_pos_end = cursor.pos();
813 sel_cell_start = sel_cell_end = actcell;
815 UpdateLocal(bv, SELECTION, false);
827 if (the_locking_inset) {
828 UnlockInsetInInset(bv, the_locking_inset);
829 the_locking_inset = 0;
831 if (action == LFUN_TAB)
835 sel_pos_start = sel_pos_end = cursor.pos();
836 sel_cell_start = sel_cell_end = actcell;
838 UpdateLocal(bv, SELECTION, false);
840 case LFUN_LAYOUT_TABULAR:
842 dialogs_ = bv->owner()->getDialogs();
843 dialogs_->showTabular(this);
846 case LFUN_TABULAR_FEATURE:
847 if (!TabularFeatures(bv, arg))
848 result = UNDISPATCHED;
851 if (!copySelection())
853 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
855 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
856 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
858 bv->text->cursor.par()->previous,
859 bv->text->cursor.par()->next
863 UpdateLocal(bv, INIT, true);
868 bv->text->FinishUndo();
872 if (!hasPasteBuffer())
874 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
876 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
877 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
879 bv->text->cursor.par()->previous,
880 bv->text->cursor.par()->next
884 UpdateLocal(bv, INIT, true);
887 result = UNDISPATCHED;
890 if (result!=FINISHED) {
891 if (!the_locking_inset) {
893 if (ocell != actcell)
894 bview->getOwner()->getPopups().updateFormTabular();
899 bv->unlockInset(this);
904 int InsetTabular::Latex(Buffer const * buf, ostream & os,
905 bool fragile, bool fp) const
907 return tabular->Latex(buf, os, fragile, fp);
911 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
913 // This should be changed to a real ascii export
914 return tabular->Latex(buf, os, false, false);
918 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
924 int InsetTabular::DocBook(Buffer const *, ostream &) const
930 void InsetTabular::Validate(LaTeXFeatures & features) const
932 tabular->Validate(features);
936 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
937 LyXFont const & font,
943 bool changed = false;
945 for(int i = 0; i < tabular->rows(); ++i) {
946 maxAsc = maxDesc = 0;
947 for(int j= 0; j < tabular->columns(); ++j) {
948 if (tabular->IsPartOfMultiColumn(i,j))
951 inset = tabular->GetCellInset(cell);
953 inset->update(bv, font, false);
954 maxAsc = max(maxAsc, inset->ascent(bv, font));
955 maxDesc = max(maxDesc, inset->descent(bv, font));
956 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
958 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
959 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
965 void InsetTabular::GetCursorPos(BufferView *,
966 int & x, int & y) const
968 x = cursor.x() - top_x;
973 void InsetTabular::ToggleInsetCursor(BufferView * bv)
975 if (the_locking_inset) {
976 the_locking_inset->ToggleInsetCursor(bv);
980 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
982 int const asc = lyxfont::maxAscent(font);
983 int const desc = lyxfont::maxDescent(font);
986 bv->hideLockedInsetCursor();
988 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
989 cursor_visible = !cursor_visible;
993 void InsetTabular::ShowInsetCursor(BufferView * bv)
995 if (!cursor_visible) {
996 LyXFont font; // = GetFont(par, cursor.pos);
998 int const asc = lyxfont::maxAscent(font);
999 int const desc = lyxfont::maxDescent(font);
1000 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1001 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1002 cursor_visible = true;
1007 void InsetTabular::HideInsetCursor(BufferView * bv)
1009 if (cursor_visible) {
1010 bv->hideLockedInsetCursor();
1011 cursor_visible = false;
1013 // if (cursor_visible)
1014 // ToggleInsetCursor(bv);
1018 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1023 actcell = actrow = actcol = 0;
1024 int ly = tabular->GetDescentOfRow(actrow);
1026 // first search the right row
1027 while((ly < y) && (actrow < tabular->rows())) {
1028 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1029 tabular->GetAscentOfRow(actrow + 1) +
1030 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1033 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1035 actcell = tabular->GetCellNumber(actrow, actcol);
1037 // now search the right column
1038 int lx = tabular->GetWidthOfColumn(actcell) -
1039 tabular->GetAdditionalWidth(actcell);
1040 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1041 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1042 tabular->GetAdditionalWidth(actcell - 1));
1045 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1046 cursor.x(lx + top_x - 2);
1049 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1055 int InsetTabular::getCellXPos(int cell) const
1059 for(; !tabular->IsFirstCellInRow(c); --c)
1061 int lx = tabular->GetWidthOfColumn(cell);
1062 for(; (c < cell); ++c) {
1063 lx += tabular->GetWidthOfColumn(c);
1065 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1069 void InsetTabular::resetPos(BufferView * bv) const
1073 actcol = tabular->column_of_cell(actcell);
1078 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1079 if (tabular->IsLastCellInRow(cell)) {
1080 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1081 tabular->GetAscentOfRow(actrow + 1) +
1082 tabular->GetAdditionalHeight(cell + 1));
1086 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1087 cursor.x(getCellXPos(actcell) + offset);
1088 if (((cursor.x() - offset) > 20) &&
1089 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1090 (bv->workWidth()-20)))
1092 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1093 UpdateLocal(bv, FULL, false);
1094 } else if ((cursor.x() - offset) < 20) {
1095 scroll(bv, 20 - cursor.x() + offset);
1096 UpdateLocal(bv, FULL, false);
1097 } else if (!cellstart(cursor.pos())) {
1098 LyXFont font(LyXFont::ALL_SANE);
1099 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1100 tabular->GetBeginningOfTextInCell(actcell));
1102 if ((!the_locking_inset ||
1103 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1104 (actcell != oldcell)) {
1105 dialogs_ = bv->owner()->getDialogs();
1106 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1112 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1114 if (!cellstart(cursor.pos())) {
1115 if (tabular->IsLastCell(actcell))
1118 cursor.pos((cursor.pos() + 1) % 2);
1120 if (ActivateCellInset(bv))
1122 } else { // before the inset
1123 cursor.pos((cursor.pos() + 1) % 2);
1126 return DISPATCHED_NOUPDATE;
1130 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1132 if (!cursor.pos()) {
1137 cursor.pos((cursor.pos() - 1) % 2);
1138 if (!cellstart(cursor.pos())) {
1140 } else if (lock) { // behind the inset
1141 if (ActivateCellInset(bv, 0, 0, 0, true))
1145 return DISPATCHED_NOUPDATE;
1149 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1151 int const ocell = actcell;
1152 actcell = tabular->GetCellAbove(actcell);
1153 if (actcell == ocell) // we moved out of the inset
1156 return DISPATCHED_NOUPDATE;
1160 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1162 int const ocell = actcell;
1163 actcell = tabular->GetCellBelow(actcell);
1164 if (actcell == ocell) // we moved out of the inset
1167 return DISPATCHED_NOUPDATE;
1171 bool InsetTabular::moveNextCell(BufferView * bv)
1173 if (tabular->IsLastCell(actcell))
1176 cursor.pos((cursor.pos() + 1) % 2);
1177 if (!cellstart(cursor.pos()))
1178 cursor.pos((cursor.pos() + 1) % 2);
1184 bool InsetTabular::movePrevCell(BufferView * bv)
1186 if (!actcell) // first cell
1189 cursor.pos((cursor.pos() - 1) % 2);
1190 if (cellstart(cursor.pos()))
1191 cursor.pos((cursor.pos() - 1) % 2);
1197 bool InsetTabular::Delete()
1203 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1205 if (the_locking_inset)
1206 the_locking_inset->SetFont(bv, font, tall);
1210 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1212 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1215 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1216 string const tmp = tabularFeatures[i].feature;
1218 if (tmp == what.substr(0, tmp.length())) {
1219 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1220 //tabularFeatures[i].feature.length())) {
1221 action = tabularFeatures[i].action;
1225 if (action == LyXTabular::LAST_ACTION)
1229 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1230 TabularFeatures(bv, action, val);
1235 void InsetTabular::TabularFeatures(BufferView * bv,
1236 LyXTabular::Feature feature,
1237 string const & value)
1246 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1247 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1252 case LyXTabular::M_ALIGN_LEFT:
1253 case LyXTabular::ALIGN_LEFT:
1254 setAlign=LYX_ALIGN_LEFT;
1256 case LyXTabular::M_ALIGN_RIGHT:
1257 case LyXTabular::ALIGN_RIGHT:
1258 setAlign=LYX_ALIGN_RIGHT;
1260 case LyXTabular::M_ALIGN_CENTER:
1261 case LyXTabular::ALIGN_CENTER:
1262 setAlign=LYX_ALIGN_CENTER;
1264 case LyXTabular::M_VALIGN_TOP:
1265 case LyXTabular::VALIGN_TOP:
1266 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1268 case LyXTabular::M_VALIGN_BOTTOM:
1269 case LyXTabular::VALIGN_BOTTOM:
1270 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1272 case LyXTabular::M_VALIGN_CENTER:
1273 case LyXTabular::VALIGN_CENTER:
1274 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1279 if (hasSelection()) {
1280 sel_col_start = tabular->column_of_cell(sel_cell_start);
1281 sel_col_end = tabular->column_of_cell(sel_cell_end);
1282 if (sel_col_start > sel_col_end) {
1283 sel_col_end = sel_col_start;
1284 sel_col_start = tabular->column_of_cell(sel_cell_end);
1286 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1289 sel_row_start = tabular->row_of_cell(sel_cell_start);
1290 sel_row_end = tabular->row_of_cell(sel_cell_end);
1291 if (sel_row_start > sel_row_end) {
1292 //int tmp = sel_row_start;
1293 //sel_row_start = sel_row_end;
1294 //sel_row_end = tmp;
1295 swap(sel_row_start, sel_row_end);
1298 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1299 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1301 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1303 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1304 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1306 bv->text->cursor.par()->previous,
1307 bv->text->cursor.par()->next
1311 int row = tabular->row_of_cell(actcell);
1312 int column = tabular->column_of_cell(actcell);
1316 case LyXTabular::SET_PWIDTH:
1318 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1319 tabular->SetColumnPWidth(actcell,value);
1321 for (int i=0; i < tabular->rows(); ++i) {
1322 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1325 UpdateLocal(bv, INIT, true);
1329 case LyXTabular::SET_MPWIDTH:
1331 bool const update = (tabular->GetPWidth(actcell) != value);
1332 tabular->SetMColumnPWidth(actcell,value);
1334 for (int i=0; i < tabular->rows(); ++i) {
1335 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1338 UpdateLocal(bv, INIT, true);
1342 case LyXTabular::SET_SPECIAL_COLUMN:
1343 case LyXTabular::SET_SPECIAL_MULTI:
1344 tabular->SetAlignSpecial(actcell,value,feature);
1346 case LyXTabular::APPEND_ROW:
1347 // append the row into the tabular
1348 UnlockInsetInInset(bv, the_locking_inset);
1349 tabular->AppendRow(actcell);
1350 UpdateLocal(bv, INIT, true);
1352 case LyXTabular::APPEND_COLUMN:
1353 // append the column into the tabular
1354 tabular->AppendColumn(actcell);
1355 actcell = tabular->GetCellNumber(row, column);
1356 UpdateLocal(bv, INIT, true);
1358 case LyXTabular::DELETE_ROW:
1359 tabular->DeleteRow(tabular->row_of_cell(actcell));
1360 if ((row+1) > tabular->rows())
1362 actcell = tabular->GetCellNumber(row, column);
1363 UpdateLocal(bv, INIT, true);
1365 case LyXTabular::DELETE_COLUMN:
1366 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1367 if ((column+1) > tabular->columns())
1369 actcell = tabular->GetCellNumber(row, column);
1370 UpdateLocal(bv, INIT, true);
1372 case LyXTabular::M_TOGGLE_LINE_TOP:
1374 case LyXTabular::TOGGLE_LINE_TOP:
1375 lineSet = !tabular->TopLine(actcell, flag);
1376 for(i=sel_row_start; i<=sel_row_end; ++i)
1377 for(j=sel_col_start; j<=sel_col_end; ++j)
1378 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1379 UpdateLocal(bv, INIT, true);
1382 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1384 case LyXTabular::TOGGLE_LINE_BOTTOM:
1385 lineSet = !tabular->BottomLine(actcell, flag);
1386 for(i=sel_row_start; i<=sel_row_end; ++i)
1387 for(j=sel_col_start; j<=sel_col_end; ++j)
1388 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1390 UpdateLocal(bv, INIT, true);
1393 case LyXTabular::M_TOGGLE_LINE_LEFT:
1395 case LyXTabular::TOGGLE_LINE_LEFT:
1396 lineSet = !tabular->LeftLine(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->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1401 UpdateLocal(bv, INIT, true);
1404 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1406 case LyXTabular::TOGGLE_LINE_RIGHT:
1407 lineSet = !tabular->RightLine(actcell, flag);
1408 for(i=sel_row_start; i<=sel_row_end; ++i)
1409 for(j=sel_col_start; j<=sel_col_end; ++j)
1410 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1412 UpdateLocal(bv, INIT, true);
1414 case LyXTabular::M_ALIGN_LEFT:
1415 case LyXTabular::M_ALIGN_RIGHT:
1416 case LyXTabular::M_ALIGN_CENTER:
1418 case LyXTabular::ALIGN_LEFT:
1419 case LyXTabular::ALIGN_RIGHT:
1420 case LyXTabular::ALIGN_CENTER:
1421 for(i = sel_row_start; i <= sel_row_end; ++i)
1422 for(j = sel_col_start; j <= sel_col_end; ++j)
1423 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1426 UpdateLocal(bv, INIT, true);
1428 UpdateLocal(bv, CELL, true);
1430 case LyXTabular::M_VALIGN_TOP:
1431 case LyXTabular::M_VALIGN_BOTTOM:
1432 case LyXTabular::M_VALIGN_CENTER:
1434 case LyXTabular::VALIGN_TOP:
1435 case LyXTabular::VALIGN_BOTTOM:
1436 case LyXTabular::VALIGN_CENTER:
1437 for(i = sel_row_start; i <= sel_row_end; ++i)
1438 for(j = sel_col_start; j <= sel_col_end; ++j)
1439 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1442 UpdateLocal(bv, INIT, true);
1444 UpdateLocal(bv, CELL, true);
1446 case LyXTabular::MULTICOLUMN:
1448 if (sel_row_start != sel_row_end) {
1449 WriteAlert(_("Impossible Operation!"),
1450 _("Multicolumns can only be horizontally."),
1454 // just multicol for one Single Cell
1455 if (!hasSelection()) {
1456 // check wether we are completly in a multicol
1457 if (tabular->IsMultiColumn(actcell)) {
1458 tabular->UnsetMultiColumn(actcell);
1459 UpdateLocal(bv, INIT, true);
1461 tabular->SetMultiColumn(actcell, 1);
1462 UpdateLocal(bv, CELL, true);
1466 // we have a selection so this means we just add all this
1467 // cells to form a multicolumn cell
1471 if (sel_cell_start > sel_cell_end) {
1472 s_start = sel_cell_end;
1473 s_end = sel_cell_start;
1475 s_start = sel_cell_start;
1476 s_end = sel_cell_end;
1478 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1481 sel_cell_end = sel_cell_start;
1482 sel_pos_end = sel_pos_start;
1483 UpdateLocal(bv, INIT, true);
1486 case LyXTabular::SET_ALL_LINES:
1488 case LyXTabular::UNSET_ALL_LINES:
1489 for(i=sel_row_start; i<=sel_row_end; ++i)
1490 for(j=sel_col_start; j<=sel_col_end; ++j)
1491 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1492 UpdateLocal(bv, INIT, true);
1494 case LyXTabular::SET_LONGTABULAR:
1495 tabular->SetLongTabular(true);
1496 UpdateLocal(bv, INIT, true); // because this toggles displayed
1498 case LyXTabular::UNSET_LONGTABULAR:
1499 tabular->SetLongTabular(false);
1500 UpdateLocal(bv, INIT, true); // because this toggles displayed
1502 case LyXTabular::SET_ROTATE_TABULAR:
1503 tabular->SetRotateTabular(true);
1505 case LyXTabular::UNSET_ROTATE_TABULAR:
1506 tabular->SetRotateTabular(false);
1508 case LyXTabular::SET_ROTATE_CELL:
1509 for(i=sel_row_start; i<=sel_row_end; ++i)
1510 for(j=sel_col_start; j<=sel_col_end; ++j)
1511 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1513 case LyXTabular::UNSET_ROTATE_CELL:
1514 for(i = sel_row_start; i <= sel_row_end; ++i)
1515 for(j = sel_col_start; j <= sel_col_end; ++j)
1516 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1518 case LyXTabular::SET_USEBOX:
1520 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1521 if (val == tabular->GetUsebox(actcell))
1522 val = LyXTabular::BOX_NONE;
1523 for(i = sel_row_start; i <= sel_row_end; ++i)
1524 for(j = sel_col_start; j <= sel_col_end; ++j)
1525 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1528 case LyXTabular::SET_LTFIRSTHEAD:
1529 tabular->SetLTHead(actcell, true);
1531 case LyXTabular::SET_LTHEAD:
1532 tabular->SetLTHead(actcell, false);
1534 case LyXTabular::SET_LTFOOT:
1535 tabular->SetLTFoot(actcell, false);
1537 case LyXTabular::SET_LTLASTFOOT:
1538 tabular->SetLTFoot(actcell, true);
1540 case LyXTabular::SET_LTNEWPAGE:
1541 what = !tabular->GetLTNewPage(actcell);
1542 tabular->SetLTNewPage(actcell, what);
1544 // dummy stuff just to avoid warnings
1545 case LyXTabular::LAST_ACTION:
1551 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1554 // the cursor.pos has to be before the inset so if it isn't now just
1555 // reset the curor pos first!
1556 if (!cellstart(cursor.pos())) {
1560 UpdatableInset * inset =
1561 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1562 LyXFont font(LyXFont::ALL_SANE);
1564 x = inset->x() + inset->width(bv, font);
1565 y = inset->descent(bv, font);
1567 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1568 inset_y = cursor.y();
1569 inset->Edit(bv, x - inset_x, y - inset_y, button);
1570 if (!the_locking_inset)
1572 UpdateLocal(bv, CELL, false);
1573 return (the_locking_inset != 0);
1577 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1579 InsetText * inset = tabular->GetCellInset(actcell);
1582 if (!cellstart(cursor.pos())) {
1583 return (((x + top_x) < cursor.x()) &&
1584 ((x + top_x) > (cursor.x() - inset->width(bv,
1585 LyXFont(LyXFont::ALL_SANE)))));
1587 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1588 return ((x1 > x2) &&
1589 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1594 // This returns paperWidth() if the cell-width is unlimited or the width
1595 // in pixels if we have a pwidth for this cell.
1596 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1598 string const s = tabular->GetPWidth(cell);
1602 return VSpace(s).inPixels(0, 0);
1606 int InsetTabular::getMaxWidth(Painter & pain,
1607 UpdatableInset const * inset) const
1609 int const n = tabular->GetNumberOfCells();
1611 for(; cell < n; ++cell) {
1612 if (tabular->GetCellInset(cell) == inset)
1617 int w = GetMaxWidthOfCell(pain, cell);
1619 // because the inset then subtracts it's top_x and owner->x()
1620 w += (inset->x() - top_x);
1625 void InsetTabular::resizeLyXText(BufferView *) const
1631 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1633 if (the_locking_inset)
1634 return the_locking_inset->getLyXText(bv);
1635 return Inset::getLyXText(bv);
1639 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1641 if (the_locking_inset) {
1642 InsetTabular * i = static_cast<InsetTabular *>
1643 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1645 i->OpenLayoutDialog(bv);
1649 dialogs_ = bv->owner()->getDialogs();
1650 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1654 // functions returns:
1658 // 3 ... toggled off
1660 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1662 int action = LyXTabular::LAST_ACTION;
1663 LyXFunc::func_status status = LyXFunc::OK;
1666 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1667 string const tmp = tabularFeatures[i].feature;
1668 if (tmp == what.substr(0, tmp.length())) {
1669 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1670 // tabularFeatures[i].feature.length())) {
1671 action = tabularFeatures[i].action;
1675 if (action == LyXTabular::LAST_ACTION)
1676 return LyXFunc::Unknown;
1678 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1680 int sel_row_start, sel_row_end;
1684 if (hasSelection()) {
1685 sel_row_start = tabular->row_of_cell(sel_cell_start);
1686 sel_row_end = tabular->row_of_cell(sel_cell_end);
1687 if (sel_row_start > sel_row_end) {
1688 //int tmp = sel_row_start;
1689 //sel_row_start = sel_row_end;
1690 //sel_row_end = tmp;
1691 swap(sel_row_start, sel_row_end);
1694 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1698 case LyXTabular::SET_PWIDTH:
1699 case LyXTabular::SET_MPWIDTH:
1700 case LyXTabular::SET_SPECIAL_COLUMN:
1701 case LyXTabular::SET_SPECIAL_MULTI:
1702 status |= LyXFunc::Disabled;
1705 case LyXTabular::APPEND_ROW:
1706 case LyXTabular::APPEND_COLUMN:
1707 case LyXTabular::DELETE_ROW:
1708 case LyXTabular::DELETE_COLUMN:
1709 case LyXTabular::SET_ALL_LINES:
1710 case LyXTabular::UNSET_ALL_LINES:
1711 status |= LyXFunc::OK;
1714 case LyXTabular::MULTICOLUMN:
1715 if (tabular->IsMultiColumn(actcell))
1716 status |= LyXFunc::ToggleOn;
1718 status |= LyXFunc::ToggleOff;
1720 case LyXTabular::M_TOGGLE_LINE_TOP:
1722 case LyXTabular::TOGGLE_LINE_TOP:
1723 if (tabular->TopLine(actcell, flag))
1724 status |= LyXFunc::ToggleOn;
1726 status |= LyXFunc::ToggleOff;
1728 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1730 case LyXTabular::TOGGLE_LINE_BOTTOM:
1731 if (tabular->BottomLine(actcell, flag))
1732 status |= LyXFunc::ToggleOn;
1734 status |= LyXFunc::ToggleOff;
1736 case LyXTabular::M_TOGGLE_LINE_LEFT:
1738 case LyXTabular::TOGGLE_LINE_LEFT:
1739 if (tabular->LeftLine(actcell, flag))
1740 status |= LyXFunc::ToggleOn;
1742 status |= LyXFunc::ToggleOff;
1744 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1746 case LyXTabular::TOGGLE_LINE_RIGHT:
1747 if (tabular->RightLine(actcell, flag))
1748 status |= LyXFunc::ToggleOn;
1750 status |= LyXFunc::ToggleOff;
1752 case LyXTabular::M_ALIGN_LEFT:
1754 case LyXTabular::ALIGN_LEFT:
1755 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1756 status |= LyXFunc::ToggleOn;
1758 status |= LyXFunc::ToggleOff;
1760 case LyXTabular::M_ALIGN_RIGHT:
1762 case LyXTabular::ALIGN_RIGHT:
1763 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1764 status |= LyXFunc::ToggleOn;
1766 status |= LyXFunc::ToggleOff;
1768 case LyXTabular::M_ALIGN_CENTER:
1770 case LyXTabular::ALIGN_CENTER:
1771 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1772 status |= LyXFunc::ToggleOn;
1774 status |= LyXFunc::ToggleOff;
1776 case LyXTabular::M_VALIGN_TOP:
1778 case LyXTabular::VALIGN_TOP:
1779 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1780 status |= LyXFunc::ToggleOn;
1782 status |= LyXFunc::ToggleOff;
1784 case LyXTabular::M_VALIGN_BOTTOM:
1786 case LyXTabular::VALIGN_BOTTOM:
1787 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1788 status |= LyXFunc::ToggleOn;
1790 status |= LyXFunc::ToggleOff;
1792 case LyXTabular::M_VALIGN_CENTER:
1794 case LyXTabular::VALIGN_CENTER:
1795 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1796 status |= LyXFunc::ToggleOn;
1798 status |= LyXFunc::ToggleOff;
1800 case LyXTabular::SET_LONGTABULAR:
1801 if (tabular->IsLongTabular())
1802 status |= LyXFunc::ToggleOn;
1804 status |= LyXFunc::ToggleOff;
1806 case LyXTabular::UNSET_LONGTABULAR:
1807 if (!tabular->IsLongTabular())
1808 status |= LyXFunc::ToggleOn;
1810 status |= LyXFunc::ToggleOff;
1812 case LyXTabular::SET_ROTATE_TABULAR:
1813 if (tabular->GetRotateTabular())
1814 status |= LyXFunc::ToggleOn;
1816 status |= LyXFunc::ToggleOff;
1818 case LyXTabular::UNSET_ROTATE_TABULAR:
1819 if (!tabular->GetRotateTabular())
1820 status |= LyXFunc::ToggleOn;
1822 status |= LyXFunc::ToggleOff;
1824 case LyXTabular::SET_ROTATE_CELL:
1825 if (tabular->GetRotateCell(actcell))
1826 status |= LyXFunc::ToggleOn;
1828 status |= LyXFunc::ToggleOff;
1830 case LyXTabular::UNSET_ROTATE_CELL:
1831 if (!tabular->GetRotateCell(actcell))
1832 status |= LyXFunc::ToggleOn;
1834 status |= LyXFunc::ToggleOff;
1836 case LyXTabular::SET_USEBOX:
1837 if (strToInt(argument) == tabular->GetUsebox(actcell))
1838 status |= LyXFunc::ToggleOn;
1840 status |= LyXFunc::ToggleOff;
1842 case LyXTabular::SET_LTFIRSTHEAD:
1843 if (tabular->GetRowOfLTHead(actcell, dummy))
1844 status |= LyXFunc::ToggleOn;
1846 status |= LyXFunc::ToggleOff;
1848 case LyXTabular::SET_LTHEAD:
1849 if (tabular->GetRowOfLTHead(actcell, dummy))
1850 status |= LyXFunc::ToggleOn;
1852 status |= LyXFunc::ToggleOff;
1854 case LyXTabular::SET_LTFOOT:
1855 if (tabular->GetRowOfLTFoot(actcell, dummy))
1856 status |= LyXFunc::ToggleOn;
1858 status |= LyXFunc::ToggleOff;
1860 case LyXTabular::SET_LTLASTFOOT:
1861 if (tabular->GetRowOfLTFoot(actcell, dummy))
1862 status |= LyXFunc::ToggleOn;
1864 status |= LyXFunc::ToggleOff;
1866 case LyXTabular::SET_LTNEWPAGE:
1867 if (tabular->GetLTNewPage(actcell))
1868 status |= LyXFunc::ToggleOn;
1870 status |= LyXFunc::ToggleOff;
1873 status = LyXFunc::Disabled;
1880 bool InsetTabular::copySelection()
1882 if (!hasSelection())
1884 delete paste_tabular;
1886 int sel_col_start, sel_col_end;
1887 int sel_row_start, sel_row_end;
1889 sel_col_start = tabular->column_of_cell(sel_cell_start);
1890 sel_col_end = tabular->column_of_cell(sel_cell_end);
1891 if (sel_col_start > sel_col_end) {
1892 sel_col_start = sel_col_end;
1893 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1895 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1897 int columns = sel_col_end - sel_col_start + 1;
1899 sel_row_start = tabular->row_of_cell(sel_cell_start);
1900 sel_row_end = tabular->row_of_cell(sel_cell_end);
1901 if (sel_row_start > sel_row_end) {
1902 //int tmp tmp = sel_row_start;
1903 //sel_row_start = sel_row_end;
1904 //sel_row_end = tmp;
1905 swap(sel_row_start, sel_row_end);
1907 int rows = sel_row_end - sel_row_start + 1;
1909 paste_tabular = new LyXTabular(this, rows, columns);
1911 if (sel_cell_start > sel_cell_end) {
1912 //int tmp = sel_cell_start;
1913 //sel_cell_start = sel_cell_end;
1914 //sel_cell_end = tmp;
1915 swap(sel_cell_start, sel_cell_end);
1917 for(int i = sel_cell_start, j = 0; i <= sel_cell_end; ++i, ++j) {
1918 while(paste_tabular->row_of_cell(j) <
1919 (tabular->row_of_cell(i)-sel_row_start)) {
1922 while(paste_tabular->row_of_cell(j) >
1923 (tabular->row_of_cell(i)-sel_row_start)) {
1926 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1932 bool InsetTabular::pasteSelection(BufferView * bv)
1936 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1937 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1939 if (tabular->GetNumberOfCells() <= i)
1941 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1943 if (paste_tabular->GetNumberOfCells() <= j)
1945 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1946 tabular->GetCellInset(i)->setOwner(this);
1947 tabular->GetCellInset(i)->deleteLyXText(bv);
1953 bool InsetTabular::cutSelection()
1955 if (!hasSelection())
1958 int sel_col_start, sel_col_end;
1959 int sel_row_start, sel_row_end;
1961 sel_col_start = tabular->column_of_cell(sel_cell_start);
1962 sel_col_end = tabular->column_of_cell(sel_cell_end);
1963 if (sel_col_start > sel_col_end) {
1964 sel_col_start = sel_col_end;
1965 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1967 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1969 sel_row_start = tabular->row_of_cell(sel_cell_start);
1970 sel_row_end = tabular->row_of_cell(sel_cell_end);
1971 if (sel_row_start > sel_row_end) {
1972 //int tmp = sel_row_start;
1973 //sel_row_start = sel_row_end;
1974 //sel_row_end = tmp;
1975 swap(sel_row_start, sel_row_end);
1977 if (sel_cell_start > sel_cell_end) {
1978 //int tmp = sel_cell_start;
1979 //sel_cell_start = sel_cell_end;
1980 //sel_cell_end = tmp;
1981 swap(sel_cell_start, sel_cell_end);
1983 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1984 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1985 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();