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 {
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::DELETE_TABULAR, "delete-tabular" },
89 { LyXTabular::MULTICOLUMN, "multicolumn" },
90 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
91 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
92 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
93 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
94 { LyXTabular::SET_PWIDTH, "set-pwidth" },
95 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
96 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
97 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
98 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
99 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
100 { LyXTabular::SET_USEBOX, "set-usebox" },
101 { LyXTabular::SET_LTHEAD, "set-lthead" },
102 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
103 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
104 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
105 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
106 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
107 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
108 { LyXTabular::LAST_ACTION, "" }
113 bool cellstart(LyXParagraph::size_type p)
115 return ((p % 2) == 0);
119 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
126 tabular = new LyXTabular(this, rows,columns);
127 // for now make it always display as display() inset
129 the_locking_inset = 0;
130 locked = no_selection = cursor_visible = false;
135 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
141 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
144 tabular = new LyXTabular(this, *(tab.tabular));
145 the_locking_inset = 0;
146 locked = no_selection = cursor_visible = false;
151 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
157 InsetTabular::~InsetTabular()
161 dialogs_->hideTabular(this);
165 Inset * InsetTabular::Clone() const
167 InsetTabular * t = new InsetTabular(*this, buffer);
169 t->tabular = tabular->Clone(t);
174 void InsetTabular::Write(Buffer const * buf, ostream & os) const
176 os << " Tabular" << endl;
177 tabular->Write(buf, os);
181 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
183 bool old_format = (lex.GetString() == "\\LyXTable");
188 tabular = new LyXTabular(buf, this, lex);
196 token = lex.GetString();
197 while (lex.IsOK() && (token != "\\end_inset")) {
199 token = lex.GetString();
201 if (token != "\\end_inset") {
202 lex.printError("Missing \\end_inset at this point. "
208 int InsetTabular::ascent(BufferView *, LyXFont const &) const
210 return tabular->GetAscentOfRow(0);
214 int InsetTabular::descent(BufferView *, LyXFont const &) const
216 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
220 int InsetTabular::width(BufferView *, LyXFont const &) const
222 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
226 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
227 float & x, bool cleared) const
229 Painter & pain = bv->painter();
234 UpdatableInset::draw(bv, font, baseline, x, cleared);
235 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
236 (top_x != int(x)) || (top_baseline != baseline))) {
237 int h = ascent(bv, font) + descent(bv, font);
238 int tx = display() || !owner() ? 0 : top_x;
239 int w = tx ? width(bv, font) : pain.paperWidth();
240 int ty = baseline - ascent(bv, font);
244 if ((ty + h) > pain.paperHeight())
245 h = pain.paperHeight();
246 if ((top_x + w) > pain.paperWidth())
247 w = pain.paperWidth();
248 pain.fillRectangle(tx, ty, w, h);
253 top_baseline = baseline;
254 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
257 x += ADD_TO_TABULAR_WIDTH;
258 if (cleared || (need_update == FULL) || (need_update == CELL)) {
259 for(i = 0; i < tabular->rows(); ++i) {
261 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
262 (baseline - tabular->GetAscentOfRow(i)) < pain.paperHeight();
263 for(j = 0; j < tabular->columns(); ++j) {
264 if (tabular->IsPartOfMultiColumn(i, j))
266 cx = nx + tabular->GetBeginningOfTextInCell(cell);
268 DrawCellSelection(pain, nx, baseline, i, j, cell);
269 if (dodraw && !cleared && locked && the_locking_inset) {
270 if (the_locking_inset == tabular->GetCellInset(cell)) {
271 LyXText::text_status st = bv->text->status;
273 bv->text->status = st;
274 if (need_update == CELL) {
275 // clear before the inset
278 baseline - tabular->GetAscentOfRow(i) + 1,
280 tabular->GetAscentOfRow(i) +
281 tabular->GetDescentOfRow(i) - 1);
282 // clear behind the inset
284 int(cx + the_locking_inset->width(bv,font) + 1),
285 baseline - tabular->GetAscentOfRow(i) + 1,
286 tabular->GetWidthOfColumn(cell) -
287 tabular->GetBeginningOfTextInCell(cell) -
288 the_locking_inset->width(bv,font) - 1,
289 tabular->GetAscentOfRow(i) +
290 tabular->GetDescentOfRow(i) - 1);
292 tabular->GetCellInset(cell)->draw(
293 bv, font, baseline, cx, false);
294 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
297 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
299 DrawCellLines(pain, nx, baseline, i, cell);
301 nx += tabular->GetWidthOfColumn(cell);
304 baseline += tabular->GetDescentOfRow(i) +
305 tabular->GetAscentOfRow(i + 1) +
306 tabular->GetAdditionalHeight(cell + 1);
309 x -= ADD_TO_TABULAR_WIDTH;
310 x += width(bv, font);
311 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
318 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
319 int row, int cell) const
321 int x2 = x + tabular->GetWidthOfColumn(cell);
324 if (!tabular->TopAlreadyDrawed(cell)) {
325 on_off = !tabular->TopLine(cell);
326 pain.line(x, baseline - tabular->GetAscentOfRow(row),
327 x2, baseline - tabular->GetAscentOfRow(row),
328 on_off ? LColor::tabularonoffline : LColor::tabularline,
329 on_off ? Painter::line_onoffdash : Painter::line_solid);
331 on_off = !tabular->BottomLine(cell);
332 pain.line(x,baseline + tabular->GetDescentOfRow(row),
333 x2, baseline + tabular->GetDescentOfRow(row),
334 on_off ? LColor::tabularonoffline : LColor::tabularline,
335 on_off ? Painter::line_onoffdash : Painter::line_solid);
336 if (!tabular->LeftAlreadyDrawed(cell)) {
337 on_off = !tabular->LeftLine(cell);
338 pain.line(x, baseline - tabular->GetAscentOfRow(row),
339 x, baseline + tabular->GetDescentOfRow(row),
340 on_off ? LColor::tabularonoffline : LColor::tabularline,
341 on_off ? Painter::line_onoffdash : Painter::line_solid);
343 on_off = !tabular->RightLine(cell);
344 pain.line(x2 - tabular->GetAdditionalWidth(cell),
345 baseline - tabular->GetAscentOfRow(row),
346 x2 - tabular->GetAdditionalWidth(cell),
347 baseline + tabular->GetDescentOfRow(row),
348 on_off ? LColor::tabularonoffline : LColor::tabularline,
349 on_off ? Painter::line_onoffdash : Painter::line_solid);
353 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
354 int row, int column, int cell) const
356 int cs = tabular->column_of_cell(sel_cell_start);
357 int ce = tabular->column_of_cell(sel_cell_end);
360 cs = tabular->column_of_cell(sel_cell_end);
362 ce = tabular->right_column_of_cell(sel_cell_end);
365 int rs = tabular->row_of_cell(sel_cell_start);
366 int re = tabular->row_of_cell(sel_cell_end);
367 if (rs > re) swap(rs, re);
369 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
370 int w = tabular->GetWidthOfColumn(cell);
371 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
372 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
373 w, h, LColor::selection);
378 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
382 calculate_dimensions_of_cells(bv, font, true);
384 owner()->update(bv, font, true);
387 if (the_locking_inset)
388 the_locking_inset->update(bv, font, reinit);
389 switch(need_update) {
393 if (calculate_dimensions_of_cells(bv, font, false))
405 string const InsetTabular::EditMessage() const
407 return _("Opened Tabular Inset");
411 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
413 UpdatableInset::Edit(bv, x, y, button);
415 if (!bv->lockInset(this)) {
416 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
420 the_locking_inset = 0;
421 inset_pos = inset_x = inset_y = 0;
423 sel_pos_start = sel_pos_end = cursor.pos();
424 sel_cell_start = sel_cell_end = actcell;
425 bv->text->FinishUndo();
426 if (InsetHit(bv, x, y)) {
427 ActivateCellInset(bv, x, y, button);
429 UpdateLocal(bv, NONE, false);
430 // bv->getOwner()->getPopups().updateFormTabular();
434 void InsetTabular::InsetUnlock(BufferView * bv)
436 if (the_locking_inset) {
437 the_locking_inset->InsetUnlock(bv);
438 the_locking_inset = 0;
441 no_selection = false;
444 if (scroll() || hasSelection()) {
448 sel_pos_start = sel_pos_end = 0;
449 sel_cell_start = sel_cell_end = 0;
451 UpdateLocal(bv, FULL, false);
456 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
457 bool mark_dirty) const
461 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
462 if (locked && (what != NONE))
467 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
469 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
473 if (inset == tabular->GetCellInset(actcell)) {
474 lyxerr[Debug::INSETS] << "OK" << endl;
475 the_locking_inset = tabular->GetCellInset(actcell);
477 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
478 inset_y = cursor.y();
479 inset_pos = cursor.pos();
481 } else if (the_locking_inset && (the_locking_inset == inset)) {
482 if (cursor.pos() == inset_pos) {
483 lyxerr[Debug::INSETS] << "OK" << endl;
485 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
486 inset_y = cursor.y();
488 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
490 } else if (the_locking_inset) {
491 lyxerr[Debug::INSETS] << "MAYBE" << endl;
492 return the_locking_inset->LockInsetInInset(bv, inset);
494 lyxerr[Debug::INSETS] << "NOT OK" << endl;
499 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
502 if (!the_locking_inset)
504 if (the_locking_inset == inset) {
505 the_locking_inset->InsetUnlock(bv);
506 the_locking_inset = 0;
508 moveRight(bv, false);
509 UpdateLocal(bv, CELL, false);
512 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
513 if (inset->LyxCode() == TABULAR_CODE &&
514 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
516 dialogs_ = bv->owner()->getDialogs();
517 dialogs_->updateTabular(this);
526 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
528 if (!the_locking_inset)
530 if (the_locking_inset != inset)
531 return the_locking_inset->UpdateInsetInInset(bv, inset);
532 UpdateLocal(bv, CELL, false);
537 int InsetTabular::InsetInInsetY()
539 if (!the_locking_inset)
542 return (inset_y + the_locking_inset->InsetInInsetY());
546 UpdatableInset * InsetTabular::GetLockingInset()
548 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
552 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
556 if (the_locking_inset)
557 return the_locking_inset->GetFirstLockingInsetOfType(c);
562 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
564 if (the_locking_inset)
565 return the_locking_inset->InsertInset(bv, inset);
570 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
572 if (hasSelection()) {
573 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
574 UpdateLocal(bv, SELECTION, false);
576 no_selection = false;
578 int const ocell = actcell;
579 int const orow = actrow;
584 UpdateLocal(bv, NONE, false);
585 sel_pos_start = sel_pos_end = cursor.pos();
586 sel_cell_start = sel_cell_end = actcell;
588 bool const inset_hit = InsetHit(bv, x, y);
590 if ((ocell == actcell) && the_locking_inset && inset_hit) {
591 the_locking_inset->InsetButtonPress(bv,
592 x - inset_x, y - inset_y, button);
594 } else if (the_locking_inset) {
595 the_locking_inset->InsetUnlock(bv);
597 the_locking_inset = 0;
598 if (inset_hit && bv->the_locking_inset) {
599 if (ActivateCellInset(bv, x, y, button))
600 the_locking_inset->InsetButtonPress(bv, x - inset_x,
601 y - inset_y, button);
608 void InsetTabular::InsetButtonRelease(BufferView * bv,
609 int x, int y, int button)
612 if (the_locking_inset) {
614 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
615 i->InsetButtonRelease(bv, x, y, button);
619 dialogs_ = bv->owner()->getDialogs();
620 dialogs_->showTabular(this);
623 if (the_locking_inset) {
624 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
627 no_selection = false;
631 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
633 if (the_locking_inset) {
634 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
635 y - inset_y, button);
640 int const old_pos = sel_pos_end;
641 int const old_cell = actcell;
644 sel_pos_end = cursor.pos();
645 sel_cell_end = actcell;
646 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
647 UpdateLocal(bv, SELECTION, false);
650 no_selection = false;
654 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
656 if (the_locking_inset) {
657 the_locking_inset->InsetKeyPress(xke);
663 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
666 UpdatableInset::RESULT
669 no_selection = false;
670 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
671 || (result == DISPATCHED_NOUPDATE)) {
677 if ((action < 0) && arg.empty())
680 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
681 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
683 if (the_locking_inset) {
684 result=the_locking_inset->LocalDispatch(bv, action, arg);
685 if (result == DISPATCHED_NOUPDATE)
687 else if (result == DISPATCHED) {
688 the_locking_inset->ToggleInsetCursor(bv);
689 UpdateLocal(bv, CELL, false);
690 the_locking_inset->ToggleInsetCursor(bv);
692 } else if (result == FINISHED) {
693 if ((action == LFUN_RIGHT) || (action == -1)) {
694 cursor.pos(inset_pos + 1);
697 sel_pos_start = sel_pos_end = cursor.pos();
698 sel_cell_start = sel_cell_end = actcell;
705 bool hs = hasSelection();
709 // Normal chars not handled here
712 // --- Cursor Movements ---------------------------------------------
714 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
716 moveRight(bv, false);
717 sel_pos_end = cursor.pos();
718 if (!cellstart(cursor.pos())) {
719 if (tabular->right_column_of_cell(sel_cell_start) >
720 tabular->right_column_of_cell(actcell))
721 sel_cell_end = actcell+1;
723 sel_cell_end = actcell;
725 UpdateLocal(bv, SELECTION, false);
728 result = moveRight(bv);
729 sel_pos_start = sel_pos_end = cursor.pos();
730 sel_cell_start = sel_cell_end = actcell;
732 UpdateLocal(bv, SELECTION, false);
735 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
738 sel_pos_end = cursor.pos();
739 if (cellstart(cursor.pos())) {
740 if (tabular->column_of_cell(sel_cell_start) >=
741 tabular->column_of_cell(actcell))
742 sel_cell_end = actcell;
744 sel_cell_end = actcell-1;
746 UpdateLocal(bv, SELECTION, false);
749 result = moveLeft(bv);
750 sel_pos_start = sel_pos_end = cursor.pos();
751 sel_cell_start = sel_cell_end = actcell;
753 UpdateLocal(bv, SELECTION, false);
757 int const ocell = actcell;
759 sel_pos_end = cursor.pos();
760 if ((ocell == sel_cell_end) ||
761 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
762 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
764 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
765 UpdateLocal(bv, SELECTION, false);
769 result = moveDown(bv);
770 sel_pos_start = sel_pos_end = cursor.pos();
771 sel_cell_start = sel_cell_end = actcell;
773 UpdateLocal(bv, SELECTION, false);
777 int const ocell = actcell;
779 sel_pos_end = cursor.pos();
780 if ((ocell == sel_cell_end) ||
781 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
782 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
784 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
785 UpdateLocal(bv, SELECTION, false);
790 sel_pos_start = sel_pos_end = cursor.pos();
791 sel_cell_start = sel_cell_end = actcell;
793 UpdateLocal(bv, SELECTION, false);
805 if (the_locking_inset) {
806 UnlockInsetInInset(bv, the_locking_inset);
807 the_locking_inset = 0;
809 if (action == LFUN_TAB)
813 sel_pos_start = sel_pos_end = cursor.pos();
814 sel_cell_start = sel_cell_end = actcell;
816 UpdateLocal(bv, SELECTION, false);
819 case LFUN_LAYOUT_TABLE:
821 dialogs_ = bv->owner()->getDialogs();
822 dialogs_->showTabular(this);
826 #warning Jürgen, have a look. Is this correct? (Lgb)
827 case LFUN_LAYOUT_TABULAR:
829 dialogs_ = bv->owner()->getDialogs();
830 dialogs_->showTabular(this);
834 case LFUN_TABULAR_FEATURE:
835 if (!TabularFeatures(bv, arg))
836 result = UNDISPATCHED;
839 if (!copySelection())
841 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
843 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
844 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
846 bv->text->cursor.par()->previous,
847 bv->text->cursor.par()->next
851 UpdateLocal(bv, INIT, true);
856 bv->text->FinishUndo();
860 if (!hasPasteBuffer())
862 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
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);
875 result = UNDISPATCHED;
878 if (result!=FINISHED) {
879 if (!the_locking_inset) {
881 if (ocell != actcell)
882 bview->getOwner()->getPopups().updateFormTabular();
887 bv->unlockInset(this);
892 int InsetTabular::Latex(Buffer const * buf, ostream & os,
893 bool fragile, bool fp) const
895 return tabular->Latex(buf, os, fragile, fp);
899 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
901 // This should be changed to a real ascii export
902 return tabular->Latex(buf, os, false, false);
906 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
912 int InsetTabular::DocBook(Buffer const *, ostream &) const
918 void InsetTabular::Validate(LaTeXFeatures & features) const
920 tabular->Validate(features);
924 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
925 LyXFont const & font,
931 bool changed = false;
933 for(int i = 0; i < tabular->rows(); ++i) {
934 maxAsc = maxDesc = 0;
935 for(int j= 0; j < tabular->columns(); ++j) {
936 if (tabular->IsPartOfMultiColumn(i,j))
939 inset = tabular->GetCellInset(cell);
941 inset->update(bv, font, false);
942 maxAsc = max(maxAsc, inset->ascent(bv, font));
943 maxDesc = max(maxDesc, inset->descent(bv, font));
944 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
946 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
947 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
953 void InsetTabular::GetCursorPos(BufferView *, int & x, int & y) const
955 x = cursor.x() - top_x;
960 void InsetTabular::ToggleInsetCursor(BufferView * bv)
962 if (the_locking_inset) {
963 the_locking_inset->ToggleInsetCursor(bv);
967 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
969 int const asc = lyxfont::maxAscent(font);
970 int const desc = lyxfont::maxDescent(font);
973 bv->hideLockedInsetCursor();
975 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
976 cursor_visible = !cursor_visible;
980 void InsetTabular::ShowInsetCursor(BufferView * bv)
982 if (!cursor_visible) {
983 LyXFont font; // = GetFont(par, cursor.pos);
985 int const asc = lyxfont::maxAscent(font);
986 int const desc = lyxfont::maxDescent(font);
987 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
988 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
989 cursor_visible = true;
994 void InsetTabular::HideInsetCursor(BufferView * bv)
996 if (cursor_visible) {
997 bv->hideLockedInsetCursor();
998 cursor_visible = false;
1000 // if (cursor_visible)
1001 // ToggleInsetCursor(bv);
1005 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1010 actcell = actrow = actcol = 0;
1011 int ly = tabular->GetDescentOfRow(actrow);
1013 // first search the right row
1014 while((ly < y) && (actrow < tabular->rows())) {
1015 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1016 tabular->GetAscentOfRow(actrow+1) +
1017 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1020 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1022 actcell = tabular->GetCellNumber(actrow, actcol);
1024 // now search the right column
1025 int lx = tabular->GetWidthOfColumn(actcell) -
1026 tabular->GetAdditionalWidth(actcell);
1027 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1028 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1029 tabular->GetAdditionalWidth(actcell - 1));
1032 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1033 cursor.x(lx + top_x - 2);
1036 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1042 int InsetTabular::getCellXPos(int cell) const
1046 for(; !tabular->IsFirstCellInRow(c); --c)
1048 int lx = tabular->GetWidthOfColumn(cell);
1049 for(; (c < cell); ++c) {
1050 lx += tabular->GetWidthOfColumn(c);
1052 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1056 void InsetTabular::resetPos(BufferView * bv) const
1060 actcol = tabular->column_of_cell(actcell);
1065 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1066 if (tabular->IsLastCellInRow(cell)) {
1067 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1068 tabular->GetAscentOfRow(actrow + 1) +
1069 tabular->GetAdditionalHeight(cell + 1));
1073 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1074 cursor.x(getCellXPos(actcell) + offset);
1075 if (((cursor.x() - offset) > 20) &&
1076 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1077 (bv->workWidth()-20)))
1079 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1080 UpdateLocal(bv, FULL, false);
1081 } else if ((cursor.x() - offset) < 20) {
1082 scroll(bv, 20 - cursor.x() + offset);
1083 UpdateLocal(bv, FULL, false);
1084 } else if (!cellstart(cursor.pos())) {
1085 LyXFont font(LyXFont::ALL_SANE);
1086 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1087 tabular->GetBeginningOfTextInCell(actcell));
1089 if ((!the_locking_inset ||
1090 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1091 (actcell != oldcell)) {
1092 dialogs_ = bv->owner()->getDialogs();
1093 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1099 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1101 if (!cellstart(cursor.pos())) {
1102 if (tabular->IsLastCell(actcell))
1105 cursor.pos((cursor.pos() + 1) % 2);
1107 if (ActivateCellInset(bv))
1109 } else { // before the inset
1110 cursor.pos((cursor.pos() + 1) % 2);
1113 return DISPATCHED_NOUPDATE;
1117 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1119 if (!cursor.pos()) {
1124 cursor.pos((cursor.pos() - 1) % 2);
1125 if (!cellstart(cursor.pos())) {
1127 } else if (lock) { // behind the inset
1128 if (ActivateCellInset(bv, 0, 0, 0, true))
1132 return DISPATCHED_NOUPDATE;
1136 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1138 int const ocell = actcell;
1139 actcell = tabular->GetCellAbove(actcell);
1140 if (actcell == ocell) // we moved out of the inset
1143 return DISPATCHED_NOUPDATE;
1147 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1149 int const ocell = actcell;
1150 actcell = tabular->GetCellBelow(actcell);
1151 if (actcell == ocell) // we moved out of the inset
1154 return DISPATCHED_NOUPDATE;
1158 bool InsetTabular::moveNextCell(BufferView * bv)
1160 if (tabular->IsLastCell(actcell))
1163 cursor.pos((cursor.pos() + 1) % 2);
1164 if (!cellstart(cursor.pos()))
1165 cursor.pos((cursor.pos() + 1) % 2);
1171 bool InsetTabular::movePrevCell(BufferView * bv)
1173 if (!actcell) // first cell
1176 cursor.pos((cursor.pos() - 1) % 2);
1177 if (cellstart(cursor.pos()))
1178 cursor.pos((cursor.pos() - 1) % 2);
1184 bool InsetTabular::Delete()
1190 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1192 if (the_locking_inset)
1193 the_locking_inset->SetFont(bv, font, tall);
1197 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1199 int action = LyXTabular::LAST_ACTION;
1202 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1203 string const tmp = tabularFeatures[i].feature;
1205 if (tmp == what.substr(0, tmp.length())) {
1206 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1207 //tabularFeatures[i].feature.length())) {
1208 action = tabularFeatures[i].action;
1212 if (action == LyXTabular::LAST_ACTION)
1216 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1217 TabularFeatures(bv, action, val);
1222 void InsetTabular::TabularFeatures(BufferView * bv, int feature,
1223 string const & value)
1232 setAlign = LYX_ALIGN_LEFT,
1237 case LyXTabular::M_ALIGN_LEFT:
1238 case LyXTabular::ALIGN_LEFT:
1239 setAlign=LYX_ALIGN_LEFT;
1241 case LyXTabular::M_ALIGN_RIGHT:
1242 case LyXTabular::ALIGN_RIGHT:
1243 setAlign=LYX_ALIGN_RIGHT;
1245 case LyXTabular::M_ALIGN_CENTER:
1246 case LyXTabular::ALIGN_CENTER:
1247 setAlign=LYX_ALIGN_CENTER;
1249 case LyXTabular::M_VALIGN_TOP:
1250 case LyXTabular::VALIGN_TOP:
1251 setAlign=LyXTabular::LYX_VALIGN_TOP;
1253 case LyXTabular::M_VALIGN_BOTTOM:
1254 case LyXTabular::VALIGN_BOTTOM:
1255 setAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1257 case LyXTabular::M_VALIGN_CENTER:
1258 case LyXTabular::VALIGN_CENTER:
1259 setAlign=LyXTabular::LYX_VALIGN_CENTER;
1264 if (hasSelection()) {
1265 sel_col_start = tabular->column_of_cell(sel_cell_start);
1266 sel_col_end = tabular->column_of_cell(sel_cell_end);
1267 if (sel_col_start > sel_col_end) {
1268 sel_col_end = sel_col_start;
1269 sel_col_start = tabular->column_of_cell(sel_cell_end);
1271 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1274 sel_row_start = tabular->row_of_cell(sel_cell_start);
1275 sel_row_end = tabular->row_of_cell(sel_cell_end);
1276 if (sel_row_start > sel_row_end) {
1277 //int tmp = sel_row_start;
1278 //sel_row_start = sel_row_end;
1279 //sel_row_end = tmp;
1280 swap(sel_row_start, sel_row_end);
1283 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1284 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1286 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1288 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1289 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1291 bv->text->cursor.par()->previous,
1292 bv->text->cursor.par()->next
1296 int row = tabular->row_of_cell(actcell);
1297 int column = tabular->column_of_cell(actcell);
1301 case LyXTabular::SET_PWIDTH:
1303 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1304 tabular->SetColumnPWidth(actcell,value);
1306 for (int i=0; i < tabular->rows(); ++i) {
1307 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1310 UpdateLocal(bv, INIT, true);
1314 case LyXTabular::SET_MPWIDTH:
1316 bool const update = (tabular->GetPWidth(actcell) != value);
1317 tabular->SetMColumnPWidth(actcell,value);
1319 for (int i=0; i < tabular->rows(); ++i) {
1320 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1323 UpdateLocal(bv, INIT, true);
1327 case LyXTabular::SET_SPECIAL_COLUMN:
1328 case LyXTabular::SET_SPECIAL_MULTI:
1329 tabular->SetAlignSpecial(actcell,value,feature);
1331 case LyXTabular::APPEND_ROW:
1332 // append the row into the tabular
1333 UnlockInsetInInset(bv, the_locking_inset);
1334 tabular->AppendRow(actcell);
1335 UpdateLocal(bv, INIT, true);
1337 case LyXTabular::APPEND_COLUMN:
1338 // append the column into the tabular
1339 tabular->AppendColumn(actcell);
1340 actcell = tabular->GetCellNumber(row, column);
1341 UpdateLocal(bv, INIT, true);
1343 case LyXTabular::DELETE_ROW:
1344 tabular->DeleteRow(tabular->row_of_cell(actcell));
1345 if ((row+1) > tabular->rows())
1347 actcell = tabular->GetCellNumber(row, column);
1348 UpdateLocal(bv, INIT, true);
1350 case LyXTabular::DELETE_COLUMN:
1351 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1352 if ((column+1) > tabular->columns())
1354 actcell = tabular->GetCellNumber(row, column);
1355 UpdateLocal(bv, INIT, true);
1357 case LyXTabular::M_TOGGLE_LINE_TOP:
1359 case LyXTabular::TOGGLE_LINE_TOP:
1360 lineSet = !tabular->TopLine(actcell, flag);
1361 for(i=sel_row_start; i<=sel_row_end; ++i)
1362 for(j=sel_col_start; j<=sel_col_end; ++j)
1363 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1364 UpdateLocal(bv, INIT, true);
1367 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1369 case LyXTabular::TOGGLE_LINE_BOTTOM:
1370 lineSet = !tabular->BottomLine(actcell, flag);
1371 for(i=sel_row_start; i<=sel_row_end; ++i)
1372 for(j=sel_col_start; j<=sel_col_end; ++j)
1373 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1375 UpdateLocal(bv, INIT, true);
1378 case LyXTabular::M_TOGGLE_LINE_LEFT:
1380 case LyXTabular::TOGGLE_LINE_LEFT:
1381 lineSet = !tabular->LeftLine(actcell, flag);
1382 for(i=sel_row_start; i<=sel_row_end; ++i)
1383 for(j=sel_col_start; j<=sel_col_end; ++j)
1384 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1386 UpdateLocal(bv, INIT, true);
1389 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1391 case LyXTabular::TOGGLE_LINE_RIGHT:
1392 lineSet = !tabular->RightLine(actcell, flag);
1393 for(i=sel_row_start; i<=sel_row_end; ++i)
1394 for(j=sel_col_start; j<=sel_col_end; ++j)
1395 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1397 UpdateLocal(bv, INIT, true);
1399 case LyXTabular::M_ALIGN_LEFT:
1400 case LyXTabular::M_ALIGN_RIGHT:
1401 case LyXTabular::M_ALIGN_CENTER:
1403 case LyXTabular::ALIGN_LEFT:
1404 case LyXTabular::ALIGN_RIGHT:
1405 case LyXTabular::ALIGN_CENTER:
1406 for(i=sel_row_start; i<=sel_row_end; ++i)
1407 for(j=sel_col_start; j<=sel_col_end; ++j)
1408 tabular->SetAlignment(tabular->GetCellNumber(i,j),setAlign,
1411 UpdateLocal(bv, INIT, true);
1413 UpdateLocal(bv, CELL, true);
1415 case LyXTabular::M_VALIGN_TOP:
1416 case LyXTabular::M_VALIGN_BOTTOM:
1417 case LyXTabular::M_VALIGN_CENTER:
1419 case LyXTabular::VALIGN_TOP:
1420 case LyXTabular::VALIGN_BOTTOM:
1421 case LyXTabular::VALIGN_CENTER:
1422 for(i=sel_row_start; i<=sel_row_end; ++i)
1423 for(j=sel_col_start; j<=sel_col_end; ++j)
1424 tabular->SetVAlignment(tabular->GetCellNumber(i,j), setAlign,
1427 UpdateLocal(bv, INIT, true);
1429 UpdateLocal(bv, CELL, true);
1431 case LyXTabular::MULTICOLUMN:
1433 if (sel_row_start != sel_row_end) {
1434 WriteAlert(_("Impossible Operation!"),
1435 _("Multicolumns can only be horizontally."),
1439 // just multicol for one Single Cell
1440 if (!hasSelection()) {
1441 // check wether we are completly in a multicol
1442 if (tabular->IsMultiColumn(actcell)) {
1443 tabular->UnsetMultiColumn(actcell);
1444 UpdateLocal(bv, INIT, true);
1446 tabular->SetMultiColumn(actcell, 1);
1447 UpdateLocal(bv, CELL, true);
1451 // we have a selection so this means we just add all this
1452 // cells to form a multicolumn cell
1456 if (sel_cell_start > sel_cell_end) {
1457 s_start = sel_cell_end;
1458 s_end = sel_cell_start;
1460 s_start = sel_cell_start;
1461 s_end = sel_cell_end;
1463 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1466 sel_cell_end = sel_cell_start;
1467 sel_pos_end = sel_pos_start;
1468 UpdateLocal(bv, INIT, true);
1471 case LyXTabular::SET_ALL_LINES:
1473 case LyXTabular::UNSET_ALL_LINES:
1474 for(i=sel_row_start; i<=sel_row_end; ++i)
1475 for(j=sel_col_start; j<=sel_col_end; ++j)
1476 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1477 UpdateLocal(bv, INIT, true);
1479 case LyXTabular::SET_LONGTABULAR:
1480 tabular->SetLongTabular(true);
1481 UpdateLocal(bv, INIT, true); // because this toggles displayed
1483 case LyXTabular::UNSET_LONGTABULAR:
1484 tabular->SetLongTabular(false);
1485 UpdateLocal(bv, INIT, true); // because this toggles displayed
1487 case LyXTabular::SET_ROTATE_TABULAR:
1488 tabular->SetRotateTabular(true);
1490 case LyXTabular::UNSET_ROTATE_TABULAR:
1491 tabular->SetRotateTabular(false);
1493 case LyXTabular::SET_ROTATE_CELL:
1494 for(i=sel_row_start; i<=sel_row_end; ++i)
1495 for(j=sel_col_start; j<=sel_col_end; ++j)
1496 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1498 case LyXTabular::UNSET_ROTATE_CELL:
1499 for(i = sel_row_start; i <= sel_row_end; ++i)
1500 for(j = sel_col_start; j <= sel_col_end; ++j)
1501 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1503 case LyXTabular::SET_USEBOX:
1505 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1506 if (val == tabular->GetUsebox(actcell))
1507 val = LyXTabular::BOX_NONE;
1508 for(i = sel_row_start; i <= sel_row_end; ++i)
1509 for(j = sel_col_start; j <= sel_col_end; ++j)
1510 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1513 case LyXTabular::SET_LTFIRSTHEAD:
1514 tabular->SetLTHead(actcell, true);
1516 case LyXTabular::SET_LTHEAD:
1517 tabular->SetLTHead(actcell, false);
1519 case LyXTabular::SET_LTFOOT:
1520 tabular->SetLTFoot(actcell, false);
1522 case LyXTabular::SET_LTLASTFOOT:
1523 tabular->SetLTFoot(actcell, true);
1525 case LyXTabular::SET_LTNEWPAGE:
1526 what = !tabular->GetLTNewPage(actcell);
1527 tabular->SetLTNewPage(actcell, what);
1533 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1536 // the cursor.pos has to be before the inset so if it isn't now just
1537 // reset the curor pos first!
1538 if (!cellstart(cursor.pos())) {
1539 cursor.pos((cursor.pos() - 1) % 2);
1542 UpdatableInset * inset =
1543 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1544 LyXFont font(LyXFont::ALL_SANE);
1546 x = inset->x() + inset->width(bv, font);
1547 y = inset->descent(bv, font);
1549 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1550 inset_y = cursor.y();
1551 inset->Edit(bv, x - inset_x, y - inset_y, button);
1552 if (!the_locking_inset)
1554 UpdateLocal(bv, CELL, false);
1555 return (the_locking_inset != 0);
1559 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1561 InsetText * inset = tabular->GetCellInset(actcell);
1564 if (!cellstart(cursor.pos())) {
1565 return (((x + top_x) < cursor.x()) &&
1566 ((x + top_x) > (cursor.x() - inset->width(bv,
1567 LyXFont(LyXFont::ALL_SANE)))));
1569 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1570 return ((x1 > x2) &&
1571 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1576 // This returns paperWidth() if the cell-width is unlimited or the width
1577 // in pixels if we have a pwidth for this cell.
1578 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1580 string const s = tabular->GetPWidth(cell);
1584 return VSpace(s).inPixels(0, 0);
1588 int InsetTabular::getMaxWidth(Painter & pain,
1589 UpdatableInset const * inset) const
1591 int const n = tabular->GetNumberOfCells();
1593 for(; cell < n; ++cell) {
1594 if (tabular->GetCellInset(cell) == inset)
1599 int w = GetMaxWidthOfCell(pain, cell);
1601 // because the inset then subtracts it's top_x and owner->x()
1602 w += (inset->x() - top_x);
1607 void InsetTabular::resizeLyXText(BufferView *) const
1613 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1615 if (the_locking_inset)
1616 return the_locking_inset->getLyXText(bv);
1617 return Inset::getLyXText(bv);
1621 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1623 if (the_locking_inset) {
1624 InsetTabular * i = static_cast<InsetTabular *>
1625 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1627 i->OpenLayoutDialog(bv);
1631 dialogs_ = bv->owner()->getDialogs();
1632 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1636 // functions returns:
1640 // 3 ... toggled off
1642 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1644 int action = LyXTabular::LAST_ACTION;
1645 LyXFunc::func_status status = LyXFunc::OK;
1648 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1649 string const tmp = tabularFeatures[i].feature;
1650 if (tmp == what.substr(0, tmp.length())) {
1651 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1652 // tabularFeatures[i].feature.length())) {
1653 action = tabularFeatures[i].action;
1657 if (action == LyXTabular::LAST_ACTION)
1658 return LyXFunc::Unknown;
1660 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1662 int sel_row_start, sel_row_end;
1666 if (hasSelection()) {
1667 sel_row_start = tabular->row_of_cell(sel_cell_start);
1668 sel_row_end = tabular->row_of_cell(sel_cell_end);
1669 if (sel_row_start > sel_row_end) {
1670 //int tmp = sel_row_start;
1671 //sel_row_start = sel_row_end;
1672 //sel_row_end = tmp;
1673 swap(sel_row_start, sel_row_end);
1676 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1680 case LyXTabular::SET_PWIDTH:
1681 case LyXTabular::SET_MPWIDTH:
1682 case LyXTabular::SET_SPECIAL_COLUMN:
1683 case LyXTabular::SET_SPECIAL_MULTI:
1684 status |= LyXFunc::Disabled;
1687 case LyXTabular::APPEND_ROW:
1688 case LyXTabular::APPEND_COLUMN:
1689 case LyXTabular::DELETE_ROW:
1690 case LyXTabular::DELETE_COLUMN:
1691 case LyXTabular::SET_ALL_LINES:
1692 case LyXTabular::UNSET_ALL_LINES:
1693 status |= LyXFunc::OK;
1696 case LyXTabular::MULTICOLUMN:
1697 if (tabular->IsMultiColumn(actcell))
1698 status |= LyXFunc::ToggleOn;
1700 status |= LyXFunc::ToggleOff;
1702 case LyXTabular::M_TOGGLE_LINE_TOP:
1704 case LyXTabular::TOGGLE_LINE_TOP:
1705 if (tabular->TopLine(actcell, flag))
1706 status |= LyXFunc::ToggleOn;
1708 status |= LyXFunc::ToggleOff;
1710 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1712 case LyXTabular::TOGGLE_LINE_BOTTOM:
1713 if (tabular->BottomLine(actcell, flag))
1714 status |= LyXFunc::ToggleOn;
1716 status |= LyXFunc::ToggleOff;
1718 case LyXTabular::M_TOGGLE_LINE_LEFT:
1720 case LyXTabular::TOGGLE_LINE_LEFT:
1721 if (tabular->LeftLine(actcell, flag))
1722 status |= LyXFunc::ToggleOn;
1724 status |= LyXFunc::ToggleOff;
1726 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1728 case LyXTabular::TOGGLE_LINE_RIGHT:
1729 if (tabular->RightLine(actcell, flag))
1730 status |= LyXFunc::ToggleOn;
1732 status |= LyXFunc::ToggleOff;
1734 case LyXTabular::M_ALIGN_LEFT:
1736 case LyXTabular::ALIGN_LEFT:
1737 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1738 status |= LyXFunc::ToggleOn;
1740 status |= LyXFunc::ToggleOff;
1742 case LyXTabular::M_ALIGN_RIGHT:
1744 case LyXTabular::ALIGN_RIGHT:
1745 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1746 status |= LyXFunc::ToggleOn;
1748 status |= LyXFunc::ToggleOff;
1750 case LyXTabular::M_ALIGN_CENTER:
1752 case LyXTabular::ALIGN_CENTER:
1753 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1754 status |= LyXFunc::ToggleOn;
1756 status |= LyXFunc::ToggleOff;
1758 case LyXTabular::M_VALIGN_TOP:
1760 case LyXTabular::VALIGN_TOP:
1761 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1762 status |= LyXFunc::ToggleOn;
1764 status |= LyXFunc::ToggleOff;
1766 case LyXTabular::M_VALIGN_BOTTOM:
1768 case LyXTabular::VALIGN_BOTTOM:
1769 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1770 status |= LyXFunc::ToggleOn;
1772 status |= LyXFunc::ToggleOff;
1774 case LyXTabular::M_VALIGN_CENTER:
1776 case LyXTabular::VALIGN_CENTER:
1777 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1778 status |= LyXFunc::ToggleOn;
1780 status |= LyXFunc::ToggleOff;
1782 case LyXTabular::SET_LONGTABULAR:
1783 if (tabular->IsLongTabular())
1784 status |= LyXFunc::ToggleOn;
1786 status |= LyXFunc::ToggleOff;
1788 case LyXTabular::UNSET_LONGTABULAR:
1789 if (!tabular->IsLongTabular())
1790 status |= LyXFunc::ToggleOn;
1792 status |= LyXFunc::ToggleOff;
1794 case LyXTabular::SET_ROTATE_TABULAR:
1795 if (tabular->GetRotateTabular())
1796 status |= LyXFunc::ToggleOn;
1798 status |= LyXFunc::ToggleOff;
1800 case LyXTabular::UNSET_ROTATE_TABULAR:
1801 if (!tabular->GetRotateTabular())
1802 status |= LyXFunc::ToggleOn;
1804 status |= LyXFunc::ToggleOff;
1806 case LyXTabular::SET_ROTATE_CELL:
1807 if (tabular->GetRotateCell(actcell))
1808 status |= LyXFunc::ToggleOn;
1810 status |= LyXFunc::ToggleOff;
1812 case LyXTabular::UNSET_ROTATE_CELL:
1813 if (!tabular->GetRotateCell(actcell))
1814 status |= LyXFunc::ToggleOn;
1816 status |= LyXFunc::ToggleOff;
1818 case LyXTabular::SET_USEBOX:
1819 if (strToInt(argument) == tabular->GetUsebox(actcell))
1820 status |= LyXFunc::ToggleOn;
1822 status |= LyXFunc::ToggleOff;
1824 case LyXTabular::SET_LTFIRSTHEAD:
1825 if (tabular->GetRowOfLTHead(actcell, dummy))
1826 status |= LyXFunc::ToggleOn;
1828 status |= LyXFunc::ToggleOff;
1830 case LyXTabular::SET_LTHEAD:
1831 if (tabular->GetRowOfLTHead(actcell, dummy))
1832 status |= LyXFunc::ToggleOn;
1834 status |= LyXFunc::ToggleOff;
1836 case LyXTabular::SET_LTFOOT:
1837 if (tabular->GetRowOfLTFoot(actcell, dummy))
1838 status |= LyXFunc::ToggleOn;
1840 status |= LyXFunc::ToggleOff;
1842 case LyXTabular::SET_LTLASTFOOT:
1843 if (tabular->GetRowOfLTFoot(actcell, dummy))
1844 status |= LyXFunc::ToggleOn;
1846 status |= LyXFunc::ToggleOff;
1848 case LyXTabular::SET_LTNEWPAGE:
1849 if (tabular->GetLTNewPage(actcell))
1850 status |= LyXFunc::ToggleOn;
1852 status |= LyXFunc::ToggleOff;
1855 status = LyXFunc::Disabled;
1862 bool InsetTabular::copySelection()
1864 if (!hasSelection())
1866 delete paste_tabular;
1868 int sel_col_start, sel_col_end;
1869 int sel_row_start, sel_row_end;
1871 sel_col_start = tabular->column_of_cell(sel_cell_start);
1872 sel_col_end = tabular->column_of_cell(sel_cell_end);
1873 if (sel_col_start > sel_col_end) {
1874 sel_col_start = sel_col_end;
1875 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1877 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1879 int columns = sel_col_end - sel_col_start + 1;
1881 sel_row_start = tabular->row_of_cell(sel_cell_start);
1882 sel_row_end = tabular->row_of_cell(sel_cell_end);
1883 if (sel_row_start > sel_row_end) {
1884 //int tmp tmp = sel_row_start;
1885 //sel_row_start = sel_row_end;
1886 //sel_row_end = tmp;
1887 swap(sel_row_start, sel_row_end);
1889 int rows = sel_row_end - sel_row_start + 1;
1891 paste_tabular = new LyXTabular(this, rows, columns);
1893 if (sel_cell_start > sel_cell_end) {
1894 //int tmp = sel_cell_start;
1895 //sel_cell_start = sel_cell_end;
1896 //sel_cell_end = tmp;
1897 swap(sel_cell_start, sel_cell_end);
1899 for(int i = sel_cell_start, j = 0; i <= sel_cell_end; ++i, ++j) {
1900 while(paste_tabular->row_of_cell(j) <
1901 (tabular->row_of_cell(i)-sel_row_start)) {
1904 while(paste_tabular->row_of_cell(j) >
1905 (tabular->row_of_cell(i)-sel_row_start)) {
1908 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1914 bool InsetTabular::pasteSelection(BufferView * bv)
1918 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1919 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1921 if (tabular->GetNumberOfCells() <= i)
1923 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1925 if (paste_tabular->GetNumberOfCells() <= j)
1927 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1928 tabular->GetCellInset(i)->setOwner(this);
1929 tabular->GetCellInset(i)->deleteLyXText(bv);
1935 bool InsetTabular::cutSelection()
1937 if (!hasSelection())
1940 int sel_col_start, sel_col_end;
1941 int sel_row_start, sel_row_end;
1943 sel_col_start = tabular->column_of_cell(sel_cell_start);
1944 sel_col_end = tabular->column_of_cell(sel_cell_end);
1945 if (sel_col_start > sel_col_end) {
1946 sel_col_start = sel_col_end;
1947 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1949 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1951 sel_row_start = tabular->row_of_cell(sel_cell_start);
1952 sel_row_end = tabular->row_of_cell(sel_cell_end);
1953 if (sel_row_start > sel_row_end) {
1954 //int tmp = sel_row_start;
1955 //sel_row_start = sel_row_end;
1956 //sel_row_end = tmp;
1957 swap(sel_row_start, sel_row_end);
1959 if (sel_cell_start > sel_cell_end) {
1960 //int tmp = sel_cell_start;
1961 //sel_cell_start = sel_cell_end;
1962 //sel_cell_end = tmp;
1963 swap(sel_cell_start, sel_cell_end);
1965 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1966 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1967 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();